|
@@ -12,13 +12,19 @@ import androidx.recyclerview.widget.RecyclerView
|
|
import com.sambath.kunkhmer.R
|
|
import com.sambath.kunkhmer.R
|
|
import com.sambath.kunkhmer.adapter.LivesAdapter
|
|
import com.sambath.kunkhmer.adapter.LivesAdapter
|
|
import com.sambath.kunkhmer.adapter.LivesCardItem
|
|
import com.sambath.kunkhmer.adapter.LivesCardItem
|
|
|
|
+import com.sambath.kunkhmer.adapter.ProductAdapter
|
|
|
|
+import com.sambath.kunkhmer.app.App
|
|
|
|
+import com.sambath.kunkhmer.remote.LivesInfo
|
|
|
|
+import com.sambath.kunkhmer.screen.shop.ShopViewModel
|
|
import kotlinx.android.synthetic.main.fragment_event.view.recyclerViewEvent
|
|
import kotlinx.android.synthetic.main.fragment_event.view.recyclerViewEvent
|
|
import kotlinx.android.synthetic.main.fragment_lives.view.recyclerViewLives
|
|
import kotlinx.android.synthetic.main.fragment_lives.view.recyclerViewLives
|
|
|
|
|
|
class LivesFragment : Fragment(), LivesAdapter.OnItemClickListener {
|
|
class LivesFragment : Fragment(), LivesAdapter.OnItemClickListener {
|
|
private var _root: View? = null
|
|
private var _root: View? = null
|
|
private val binding get() = _root!!
|
|
private val binding get() = _root!!
|
|
- private var cardList: List<LivesCardItem>? = null
|
|
|
|
|
|
+ private var cardList: List<LivesInfo>? = null
|
|
|
|
+ private lateinit var livesAdapter: LivesAdapter
|
|
|
|
+ private lateinit var livesViewModel: LivesViewModel
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
super.onCreate(savedInstanceState)
|
|
super.onCreate(savedInstanceState)
|
|
@@ -31,47 +37,68 @@ class LivesFragment : Fragment(), LivesAdapter.OnItemClickListener {
|
|
// Inflate the layout for this fragment
|
|
// Inflate the layout for this fragment
|
|
_root = inflater.inflate(R.layout.fragment_lives, container, false)
|
|
_root = inflater.inflate(R.layout.fragment_lives, container, false)
|
|
|
|
|
|
- setEvent()
|
|
|
|
|
|
+ livesAdapter = LivesAdapter(mutableListOf(), this)
|
|
|
|
+ livesViewModel = LivesViewModel(App.injectApiService(), App.injectPrefHelper())
|
|
|
|
+ livesViewModel.getLives()
|
|
|
|
+ livesViewModel.state.observe(viewLifecycleOwner, androidx.lifecycle.Observer {
|
|
|
|
+ render(it)
|
|
|
|
+ })
|
|
|
|
|
|
- return binding
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private fun setEvent() {
|
|
|
|
val recyclerView = binding.recyclerViewLives
|
|
val recyclerView = binding.recyclerViewLives
|
|
- cardList = createCardList() // Create your card data list here
|
|
|
|
- val cardAdapter = LivesAdapter(cardList!!, this)
|
|
|
|
-
|
|
|
|
recyclerView.layoutManager =
|
|
recyclerView.layoutManager =
|
|
LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
|
|
LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
|
|
- recyclerView.adapter = cardAdapter
|
|
|
|
|
|
+ recyclerView.adapter = livesAdapter
|
|
|
|
+
|
|
|
|
+ return binding
|
|
}
|
|
}
|
|
|
|
|
|
- private fun createCardList(): List<LivesCardItem> {
|
|
|
|
- // Create and return your list of CardItems
|
|
|
|
- return listOf(
|
|
|
|
- LivesCardItem("https://i.ytimg.com/vi/Lh5O00zo_pc/hq720.jpg?sqp=-oaymwEcCOgCEMoBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLCEQ100buCWUuyBKWe_96UbevbIEA",
|
|
|
|
- "ផ្សាយបន្តផ្ទាល់កម្មវិធីប្រដាល់ Krud គុនខ្មែរ", "ឃឹម បូរ៉ា (ខ្មែរ) Vs ពេជ្រ សម្បត្តិ"),
|
|
|
|
- LivesCardItem("https://i.ytimg.com/vi/Lh5O00zo_pc/hq720.jpg?sqp=-oaymwEcCOgCEMoBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLCEQ100buCWUuyBKWe_96UbevbIEA",
|
|
|
|
- "ផ្សាយបន្តផ្ទាល់កម្មវិធីប្រដាល់ Krud គុនខ្មែរ", "ឃឹម បូរ៉ា (ខ្មែរ) Vs ពេជ្រ សម្បត្តិ"),
|
|
|
|
- LivesCardItem("https://i.ytimg.com/vi/Lh5O00zo_pc/hq720.jpg?sqp=-oaymwEcCOgCEMoBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLCEQ100buCWUuyBKWe_96UbevbIEA",
|
|
|
|
- "ផ្សាយបន្តផ្ទាល់កម្មវិធីប្រដាល់ Krud គុនខ្មែរ", "ឃឹម បូរ៉ា (ខ្មែរ) Vs ពេជ្រ សម្បត្តិ"),
|
|
|
|
- LivesCardItem("https://i.ytimg.com/vi/Lh5O00zo_pc/hq720.jpg?sqp=-oaymwEcCOgCEMoBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLCEQ100buCWUuyBKWe_96UbevbIEA",
|
|
|
|
- "ផ្សាយបន្តផ្ទាល់កម្មវិធីប្រដាល់ Krud គុនខ្មែរ", "ឃឹម បូរ៉ា (ខ្មែរ) Vs ពេជ្រ សម្បត្តិ"),
|
|
|
|
- LivesCardItem("https://i.ytimg.com/vi/Lh5O00zo_pc/hq720.jpg?sqp=-oaymwEcCOgCEMoBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLCEQ100buCWUuyBKWe_96UbevbIEA",
|
|
|
|
- "ផ្សាយបន្តផ្ទាល់កម្មវិធីប្រដាល់ Krud គុនខ្មែរ", "ឃឹម បូរ៉ា (ខ្មែរ) Vs ពេជ្រ សម្បត្តិ"),
|
|
|
|
- // Add more card items as needed
|
|
|
|
- )
|
|
|
|
|
|
+ private fun render(state: LivesViewModel.LivesViewState) {
|
|
|
|
+ if (state.isLoginSuccess) {
|
|
|
|
+ if(state.livesData != null) {
|
|
|
|
+ livesAdapter.cardList = state.livesData
|
|
|
|
+ cardList = livesAdapter.cardList
|
|
|
|
+ livesAdapter.notifyDataSetChanged()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // Other state handling...
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// private fun setEvent() {
|
|
|
|
+// val recyclerView = binding.recyclerViewLives
|
|
|
|
+// cardList = createCardList() // Create your card data list here
|
|
|
|
+// val cardAdapter = LivesAdapter(cardList!!, this)
|
|
|
|
+//
|
|
|
|
+// recyclerView.layoutManager =
|
|
|
|
+// LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
|
|
|
|
+// recyclerView.adapter = cardAdapter
|
|
|
|
+// }
|
|
|
|
+
|
|
|
|
+// private fun createCardList(): List<LivesCardItem> {
|
|
|
|
+// // Create and return your list of CardItems
|
|
|
|
+// return listOf(
|
|
|
|
+// LivesCardItem("https://i.ytimg.com/vi/Lh5O00zo_pc/hq720.jpg?sqp=-oaymwEcCOgCEMoBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLCEQ100buCWUuyBKWe_96UbevbIEA",
|
|
|
|
+// "ផ្សាយបន្តផ្ទាល់កម្មវិធីប្រដាល់ Krud គុនខ្មែរ", "ឃឹម បូរ៉ា (ខ្មែរ) Vs ពេជ្រ សម្បត្តិ"),
|
|
|
|
+// LivesCardItem("https://i.ytimg.com/vi/Lh5O00zo_pc/hq720.jpg?sqp=-oaymwEcCOgCEMoBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLCEQ100buCWUuyBKWe_96UbevbIEA",
|
|
|
|
+// "ផ្សាយបន្តផ្ទាល់កម្មវិធីប្រដាល់ Krud គុនខ្មែរ", "ឃឹម បូរ៉ា (ខ្មែរ) Vs ពេជ្រ សម្បត្តិ"),
|
|
|
|
+// LivesCardItem("https://i.ytimg.com/vi/Lh5O00zo_pc/hq720.jpg?sqp=-oaymwEcCOgCEMoBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLCEQ100buCWUuyBKWe_96UbevbIEA",
|
|
|
|
+// "ផ្សាយបន្តផ្ទាល់កម្មវិធីប្រដាល់ Krud គុនខ្មែរ", "ឃឹម បូរ៉ា (ខ្មែរ) Vs ពេជ្រ សម្បត្តិ"),
|
|
|
|
+// LivesCardItem("https://i.ytimg.com/vi/Lh5O00zo_pc/hq720.jpg?sqp=-oaymwEcCOgCEMoBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLCEQ100buCWUuyBKWe_96UbevbIEA",
|
|
|
|
+// "ផ្សាយបន្តផ្ទាល់កម្មវិធីប្រដាល់ Krud គុនខ្មែរ", "ឃឹម បូរ៉ា (ខ្មែរ) Vs ពេជ្រ សម្បត្តិ"),
|
|
|
|
+// LivesCardItem("https://i.ytimg.com/vi/Lh5O00zo_pc/hq720.jpg?sqp=-oaymwEcCOgCEMoBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLCEQ100buCWUuyBKWe_96UbevbIEA",
|
|
|
|
+// "ផ្សាយបន្តផ្ទាល់កម្មវិធីប្រដាល់ Krud គុនខ្មែរ", "ឃឹម បូរ៉ា (ខ្មែរ) Vs ពេជ្រ សម្បត្តិ"),
|
|
|
|
+// // Add more card items as needed
|
|
|
|
+// )
|
|
|
|
+// }
|
|
|
|
+
|
|
override fun onItemClick(position: Int) {
|
|
override fun onItemClick(position: Int) {
|
|
val clickedItem = cardList!![position]
|
|
val clickedItem = cardList!![position]
|
|
val liveDetailFragment = LiveDetailFragment()
|
|
val liveDetailFragment = LiveDetailFragment()
|
|
|
|
|
|
// You can pass data to the LiveDetailFragment using arguments if needed
|
|
// You can pass data to the LiveDetailFragment using arguments if needed
|
|
val bundle = Bundle()
|
|
val bundle = Bundle()
|
|
- bundle.putString("image_url", clickedItem.imageResource)
|
|
|
|
- bundle.putString("title", clickedItem.title)
|
|
|
|
- bundle.putString("description", clickedItem.title)
|
|
|
|
|
|
+ bundle.putString("image_url", clickedItem.filename)
|
|
|
|
+ bundle.putString("title", clickedItem.name)
|
|
|
|
+ bundle.putString("description", clickedItem.desc)
|
|
liveDetailFragment.arguments = bundle
|
|
liveDetailFragment.arguments = bundle
|
|
|
|
|
|
// Replace the current fragment with the LiveDetailFragment
|
|
// Replace the current fragment with the LiveDetailFragment
|