Pārlūkot izejas kodu

boxing template

Dola TENG 1 gadu atpakaļ
vecāks
revīzija
8fba735a16

+ 52 - 7
app/src/main/java/com/khmer9/boxingapplication/ui/boxing/BoxingFragment.kt

@@ -7,6 +7,12 @@ import android.view.ViewGroup
 import android.widget.TextView
 import androidx.fragment.app.Fragment
 import androidx.lifecycle.ViewModelProvider
+import androidx.recyclerview.widget.LinearLayoutManager
+import com.khmer9.boxingapplication.R
+import com.khmer9.boxingapplication.adapter.CardItem
+import com.khmer9.boxingapplication.adapter.NewsFeedCardAdapter
+import com.khmer9.boxingapplication.adapter.SubTopNewsCardAdapter
+import com.khmer9.boxingapplication.adapter.TopNewsCardAdapter
 import com.khmer9.boxingapplication.databinding.FragmentGalleryBinding
 
 class BoxingFragment : Fragment() {
@@ -22,16 +28,13 @@ class BoxingFragment : Fragment() {
         container: ViewGroup?,
         savedInstanceState: Bundle?
     ): View {
-        val galleryViewModel =
-            ViewModelProvider(this).get(BoxingViewModel::class.java)
-
         _binding = FragmentGalleryBinding.inflate(inflater, container, false)
         val root: View = binding.root
 
-        val textView: TextView = binding.textGallery
-        galleryViewModel.text.observe(viewLifecycleOwner) {
-            textView.text = it
-        }
+        setTopNews()
+        setSubTopNews()
+        setNewsFeed()
+
         return root
     }
 
@@ -39,4 +42,46 @@ class BoxingFragment : Fragment() {
         super.onDestroyView()
         _binding = null
     }
+
+    private fun setTopNews() {
+        val recyclerView = binding.recyclerViewTopNews
+        val cardList = createCardList() // Create your card data list here
+        val cardAdapter = TopNewsCardAdapter(cardList)
+
+        recyclerView.layoutManager =
+            LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
+        recyclerView.adapter = cardAdapter
+    }
+
+    private fun setSubTopNews() {
+        val recyclerView = binding.recyclerViewSecondTopNews
+        val cardList = createCardList() // Create your card data list here
+        val cardAdapter = TopNewsCardAdapter(cardList)
+
+        recyclerView.layoutManager =
+            LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
+        recyclerView.adapter = cardAdapter
+    }
+
+    private fun setNewsFeed() {
+        val recyclerView = binding.recyclerViewNewsFeed
+        val cardList = createCardList() // Create your card data list here
+        val cardAdapter = NewsFeedCardAdapter(cardList)
+
+        recyclerView.layoutManager =
+            LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
+        recyclerView.adapter = cardAdapter
+    }
+
+    private fun createCardList(): List<CardItem> {
+        // Create and return your list of CardItems
+        return listOf(
+            CardItem(R.drawable.ic_launcher_background, "Date 1", "Title 1"),
+            CardItem(R.drawable.ic_launcher_background, "Date 2", "Title 2"),
+            CardItem(R.drawable.ic_launcher_background, "Date 3", "Title 3"),
+            CardItem(R.drawable.ic_launcher_background, "Date 4", "Title 4"),
+            CardItem(R.drawable.ic_launcher_background, "Date 5", "Title 5"),
+            // Add more card items as needed
+        )
+    }
 }

+ 0 - 4
app/src/main/java/com/khmer9/boxingapplication/ui/home/HomeFragment.kt

@@ -17,7 +17,6 @@ import com.khmer9.boxingapplication.databinding.FragmentHomeBinding
 class HomeFragment : Fragment() {
 
     private var _binding: FragmentHomeBinding? = null
-    private lateinit var homeViewModel: HomeViewModel
 
     // This property is only valid between onCreateView and
     // onDestroyView.
@@ -28,9 +27,6 @@ class HomeFragment : Fragment() {
         container: ViewGroup?,
         savedInstanceState: Bundle?
     ): View {
-        homeViewModel =
-            ViewModelProvider(this).get(HomeViewModel::class.java)
-
         _binding = FragmentHomeBinding.inflate(inflater, container, false)
         val root: View = binding.root
         setTopNews()

+ 19 - 13
app/src/main/res/layout/fragment_gallery.xml

@@ -1,22 +1,28 @@
 <?xml version="1.0" encoding="utf-8"?>
-<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schemas.android.com/apk/res-auto"
     xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
+    android:orientation="vertical"
     tools:context=".ui.boxing.BoxingFragment">
 
-    <TextView
-        android:id="@+id/text_gallery"
+    <androidx.recyclerview.widget.RecyclerView
+        android:id="@+id/recyclerViewTopNews"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        android:layout_marginStart="8dp"
-        android:layout_marginTop="8dp"
-        android:layout_marginEnd="8dp"
-        android:textAlignment="center"
-        android:textSize="20sp"
-        app:layout_constraintBottom_toBottomOf="parent"
-        app:layout_constraintEnd_toEndOf="parent"
-        app:layout_constraintStart_toStartOf="parent"
-        app:layout_constraintTop_toTopOf="parent" />
-</androidx.constraintlayout.widget.ConstraintLayout>
+        app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
+
+    <androidx.recyclerview.widget.RecyclerView
+        android:id="@+id/recyclerViewSecondTopNews"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
+
+    <androidx.recyclerview.widget.RecyclerView
+        android:id="@+id/recyclerViewNewsFeed"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
+
+</androidx.appcompat.widget.LinearLayoutCompat>

+ 1 - 1
app/src/main/res/menu/activity_main_drawer.xml

@@ -11,7 +11,7 @@
         <item
             android:id="@+id/nav_gallery"
             android:icon="@drawable/ic_menu_gallery"
-            android:title="@string/menu_gallery" />
+            android:title="@string/menu_boxing" />
         <item
             android:id="@+id/nav_slideshow"
             android:icon="@drawable/ic_menu_slideshow"

+ 1 - 1
app/src/main/res/navigation/mobile_navigation.xml

@@ -14,7 +14,7 @@
     <fragment
         android:id="@+id/nav_gallery"
         android:name="com.khmer9.boxingapplication.ui.boxing.BoxingFragment"
-        android:label="@string/menu_gallery"
+        android:label="@string/menu_boxing"
         tools:layout="@layout/fragment_gallery" />
 
     <fragment