dola 1 yıl önce
ebeveyn
işleme
024055b2cf

+ 36 - 0
app/src/main/java/com/sambath/kunkhmer/adapter/LivesAdapter.kt

@@ -0,0 +1,36 @@
+package com.sambath.kunkhmer.adapter
+
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import android.widget.ImageView
+import android.widget.TextView
+import androidx.recyclerview.widget.RecyclerView
+import com.sambath.kunkhmer.R
+
+class LivesAdapter(private val cardList: List<LivesCardItem>) :
+    RecyclerView.Adapter<LivesAdapter.ViewHolder>() {
+    class CardViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView)
+
+    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): LivesAdapter.ViewHolder {
+        val itemView = LayoutInflater.from(parent.context)
+            .inflate(R.layout.layout_event_item_card, parent, false)
+        return LivesAdapter.ViewHolder(itemView)
+    }
+
+    override fun onBindViewHolder(holder: LivesAdapter.ViewHolder, position: Int) {
+        val currentItem = cardList[position]
+
+        holder.imageView.setImageResource(currentItem.imageResource)
+        holder.subTitleTextView.text = currentItem.subTitle
+        holder.titleTextView.text = currentItem.title
+    }
+
+    override fun getItemCount() = cardList.size
+
+    class ViewHolder(ItemView: View) : RecyclerView.ViewHolder(ItemView) {
+        val imageView: ImageView = itemView.findViewById(R.id.imageView)
+        val subTitleTextView: TextView = itemView.findViewById(R.id.subTitleTextView)
+        val titleTextView: TextView = itemView.findViewById(R.id.titleTextView)
+    }
+}

+ 3 - 0
app/src/main/java/com/sambath/kunkhmer/adapter/LivesCardItem.kt

@@ -0,0 +1,3 @@
+package com.sambath.kunkhmer.adapter
+
+data class LivesCardItem(val imageResource: Int, val title: String, val subTitle: String)

+ 33 - 38
app/src/main/java/com/sambath/kunkhmer/screen/event/EventFragment.kt

@@ -5,56 +5,51 @@ import androidx.fragment.app.Fragment
 import android.view.LayoutInflater
 import android.view.View
 import android.view.ViewGroup
+import androidx.recyclerview.widget.LinearLayoutManager
 import com.sambath.kunkhmer.R
+import com.sambath.kunkhmer.adapter.LivesAdapter
+import com.sambath.kunkhmer.adapter.LivesCardItem
+import kotlinx.android.synthetic.main.fragment_event.view.recyclerViewEvent
 
-// TODO: Rename parameter arguments, choose names that match
-// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
-private const val ARG_PARAM1 = "param1"
-private const val ARG_PARAM2 = "param2"
-
-/**
- * A simple [Fragment] subclass.
- * Use the [EventFragment.newInstance] factory method to
- * create an instance of this fragment.
- */
 class EventFragment : Fragment() {
-    // TODO: Rename and change types of parameters
-    private var param1: String? = null
-    private var param2: String? = null
+    private var _root: View? = null
+    private val binding get() = _root!!
 
     override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState)
-        arguments?.let {
-            param1 = it.getString(ARG_PARAM1)
-            param2 = it.getString(ARG_PARAM2)
-        }
     }
 
     override fun onCreateView(
-        inflater: LayoutInflater, container: ViewGroup?,
+        inflater: LayoutInflater,
+        container: ViewGroup?,
         savedInstanceState: Bundle?
     ): View? {
-        // Inflate the layout for this fragment
-        return inflater.inflate(R.layout.fragment_event, container, false)
+        _root = inflater.inflate(R.layout.fragment_event, container, false)
+
+        setEvent()
+
+        return binding
+    }
+
+    private fun setEvent() {
+        val recyclerView = binding.recyclerViewEvent
+        val cardList = createCardList() // Create your card data list here
+        val cardAdapter = LivesAdapter(cardList)
+
+        recyclerView.layoutManager =
+            LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
+        recyclerView.adapter = cardAdapter
     }
 
-    companion object {
-        /**
-         * Use this factory method to create a new instance of
-         * this fragment using the provided parameters.
-         *
-         * @param param1 Parameter 1.
-         * @param param2 Parameter 2.
-         * @return A new instance of fragment EventFragment.
-         */
-        // TODO: Rename and change types and number of parameters
-        @JvmStatic
-        fun newInstance(param1: String, param2: String) =
-            EventFragment().apply {
-                arguments = Bundle().apply {
-                    putString(ARG_PARAM1, param1)
-                    putString(ARG_PARAM2, param2)
-                }
-            }
+    private fun createCardList(): List<LivesCardItem> {
+        // Create and return your list of CardItems
+        return listOf(
+            LivesCardItem(R.drawable.ic_bg_dashboard, "Title 1", "SubTitle 1"),
+            LivesCardItem(R.drawable.ic_bg_dashboard, "Title 2", "SubTitle 2"),
+            LivesCardItem(R.drawable.ic_bg_dashboard, "Title 3", "SubTitle 3"),
+            LivesCardItem(R.drawable.ic_bg_dashboard, "Title 4", "SubTitle 4"),
+            LivesCardItem(R.drawable.ic_bg_dashboard, "Title 5", "SubTitle 5"),
+            // Add more card items as needed
+        )
     }
 }

+ 32 - 36
app/src/main/java/com/sambath/kunkhmer/screen/lives/LivesFragment.kt

@@ -5,29 +5,19 @@ import androidx.fragment.app.Fragment
 import android.view.LayoutInflater
 import android.view.View
 import android.view.ViewGroup
+import androidx.recyclerview.widget.LinearLayoutManager
 import com.sambath.kunkhmer.R
+import com.sambath.kunkhmer.adapter.LivesAdapter
+import com.sambath.kunkhmer.adapter.LivesCardItem
+import kotlinx.android.synthetic.main.fragment_event.view.recyclerViewEvent
+import kotlinx.android.synthetic.main.fragment_lives.view.recyclerViewLives
 
-// TODO: Rename parameter arguments, choose names that match
-// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
-private const val ARG_PARAM1 = "param1"
-private const val ARG_PARAM2 = "param2"
-
-/**
- * A simple [Fragment] subclass.
- * Use the [LivesFragment.newInstance] factory method to
- * create an instance of this fragment.
- */
 class LivesFragment : Fragment() {
-    // TODO: Rename and change types of parameters
-    private var param1: String? = null
-    private var param2: String? = null
+    private var _root: View? = null
+    private val binding get() = _root!!
 
     override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState)
-        arguments?.let {
-            param1 = it.getString(ARG_PARAM1)
-            param2 = it.getString(ARG_PARAM2)
-        }
     }
 
     override fun onCreateView(
@@ -35,26 +25,32 @@ class LivesFragment : Fragment() {
         savedInstanceState: Bundle?
     ): View? {
         // Inflate the layout for this fragment
-        return inflater.inflate(R.layout.fragment_lives, container, false)
+        _root = inflater.inflate(R.layout.fragment_lives, container, false)
+
+        setEvent()
+
+        return binding
+    }
+
+    private fun setEvent() {
+        val recyclerView = binding.recyclerViewLives
+        val cardList = createCardList() // Create your card data list here
+        val cardAdapter = LivesAdapter(cardList)
+
+        recyclerView.layoutManager =
+            LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
+        recyclerView.adapter = cardAdapter
     }
 
-    companion object {
-        /**
-         * Use this factory method to create a new instance of
-         * this fragment using the provided parameters.
-         *
-         * @param param1 Parameter 1.
-         * @param param2 Parameter 2.
-         * @return A new instance of fragment LivesFragment.
-         */
-        // TODO: Rename and change types and number of parameters
-        @JvmStatic
-        fun newInstance(param1: String, param2: String) =
-            LivesFragment().apply {
-                arguments = Bundle().apply {
-                    putString(ARG_PARAM1, param1)
-                    putString(ARG_PARAM2, param2)
-                }
-            }
+    private fun createCardList(): List<LivesCardItem> {
+        // Create and return your list of CardItems
+        return listOf(
+            LivesCardItem(R.drawable.ic_bg_dashboard, "Title 1", "SubTitle 1"),
+            LivesCardItem(R.drawable.ic_bg_dashboard, "Title 2", "SubTitle 2"),
+            LivesCardItem(R.drawable.ic_bg_dashboard, "Title 3", "SubTitle 3"),
+            LivesCardItem(R.drawable.ic_bg_dashboard, "Title 4", "SubTitle 4"),
+            LivesCardItem(R.drawable.ic_bg_dashboard, "Title 5", "SubTitle 5"),
+            // Add more card items as needed
+        )
     }
 }

+ 5 - 4
app/src/main/res/layout/fragment_event.xml

@@ -1,14 +1,15 @@
 <?xml version="1.0" encoding="utf-8"?>
 <FrameLayout 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"
     tools:context=".screen.event.EventFragment">
 
-    <!-- TODO: Update blank fragment layout -->
-    <TextView
+    <androidx.recyclerview.widget.RecyclerView
+        android:id="@+id/recyclerViewEvent"
         android:layout_width="match_parent"
-        android:layout_height="match_parent"
-        android:text="@string/hello_blank_fragment" />
+        android:layout_height="wrap_content"
+        app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
 
 </FrameLayout>

+ 5 - 4
app/src/main/res/layout/fragment_lives.xml

@@ -3,12 +3,13 @@
     xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
     tools:context=".screen.lives.LivesFragment">
 
-    <!-- TODO: Update blank fragment layout -->
-    <TextView
+    <androidx.recyclerview.widget.RecyclerView
+        android:id="@+id/recyclerViewLives"
         android:layout_width="match_parent"
-        android:layout_height="match_parent"
-        android:text="@string/hello_blank_fragment" />
+        android:layout_height="wrap_content"
+        app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
 
 </FrameLayout>

+ 47 - 0
app/src/main/res/layout/layout_event_item_card.xml

@@ -0,0 +1,47 @@
+<androidx.cardview.widget.CardView 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="wrap_content"
+    android:layout_margin="5dp"
+    app:cardCornerRadius="5dp"
+    app:cardElevation="4dp">
+
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:orientation="vertical">
+
+        <LinearLayout
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:orientation="vertical"
+            android:paddingTop="5dp"
+            android:paddingBottom="5dp">
+
+            <TextView
+                android:id="@+id/titleTextView"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:text="Your Title"
+                android:textSize="14sp"
+                android:textStyle="bold" />
+
+            <TextView
+                android:id="@+id/subTitleTextView"
+                android:layout_width="wrap_content"
+                android:layout_height="match_parent"
+                android:gravity="center_vertical"
+                android:text="Your Date"
+                android:textSize="12sp" />
+        </LinearLayout>
+
+        <ImageView
+            android:id="@+id/imageView"
+            android:layout_width="match_parent"
+            android:layout_height="200dp"
+            android:background="@color/color_green_800"
+            android:scaleType="centerCrop" />
+
+    </LinearLayout>
+</androidx.cardview.widget.CardView>