|
@@ -9,50 +9,52 @@ import androidx.recyclerview.widget.LinearLayoutManager
|
|
|
import com.sambath.kunkhmer.R
|
|
|
import com.sambath.kunkhmer.adapter.EventAdapter
|
|
|
import com.sambath.kunkhmer.adapter.EventCardItem
|
|
|
-import com.sambath.kunkhmer.adapter.LivesAdapter
|
|
|
-import com.sambath.kunkhmer.adapter.LivesCardItem
|
|
|
+import com.sambath.kunkhmer.app.App
|
|
|
import kotlinx.android.synthetic.main.fragment_event.view.recyclerViewEvent
|
|
|
|
|
|
class EventFragment : Fragment() {
|
|
|
private var _root: View? = null
|
|
|
private val binding get() = _root!!
|
|
|
+ private lateinit var eventViewModel: EventViewModel
|
|
|
+ private lateinit var eventAdapter: EventAdapter
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
super.onCreate(savedInstanceState)
|
|
|
}
|
|
|
|
|
|
- override fun onCreateView(
|
|
|
- inflater: LayoutInflater,
|
|
|
- container: ViewGroup?,
|
|
|
- savedInstanceState: Bundle?
|
|
|
- ): View? {
|
|
|
+ override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
|
|
_root = inflater.inflate(R.layout.fragment_event, container, false)
|
|
|
|
|
|
+ eventViewModel = EventViewModel(App.injectApiService(), App.injectPrefHelper())
|
|
|
+ eventViewModel.getEvents()
|
|
|
+ eventViewModel.state.observe(viewLifecycleOwner, androidx.lifecycle.Observer {
|
|
|
+ render(it)
|
|
|
+ })
|
|
|
+
|
|
|
setEvent()
|
|
|
|
|
|
return binding
|
|
|
}
|
|
|
|
|
|
+ private fun render(state: EventViewModel.EventViewState) {
|
|
|
+ if (state.isProgress) {
|
|
|
+ }
|
|
|
+ if (state.isLoginSuccess) {
|
|
|
+ if(state.eventsData != null) {
|
|
|
+ eventAdapter.cardList = state.eventsData
|
|
|
+ eventAdapter.notifyDataSetChanged()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (state.error != null) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private fun setEvent() {
|
|
|
val recyclerView = binding.recyclerViewEvent
|
|
|
- val cardList = createCardList() // Create your card data list here
|
|
|
- val cardAdapter = EventAdapter(cardList)
|
|
|
+ eventAdapter = EventAdapter(mutableListOf())
|
|
|
|
|
|
recyclerView.layoutManager =
|
|
|
LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
|
|
|
- recyclerView.adapter = cardAdapter
|
|
|
- }
|
|
|
-
|
|
|
- private fun createCardList(): List<EventCardItem> {
|
|
|
- // Create and return your list of CardItems
|
|
|
- return listOf(
|
|
|
- EventCardItem("https://i.ytimg.com/vi/Lh5O00zo_pc/hq720.jpg?sqp=-oaymwEcCOgCEMoBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLCEQ100buCWUuyBKWe_96UbevbIEA",
|
|
|
- "ទស្សនាការប្រកួតសង្វៀនប្រដាល់គុនខ្មែរឯកភ្នំ", "ម៉ន សាម៉េត(ខ្មែរ) vs (ថៃ)ហ្វាម៉ែ សែងចាក់", "កម្មវិធីប្រកួតថ្ងៃអាទិត្យ ទី៣១ ខែមិនា ឆ្នាំ២០២៣"),
|
|
|
- EventCardItem("https://i.ytimg.com/vi/Lh5O00zo_pc/hq720.jpg?sqp=-oaymwEcCOgCEMoBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLCEQ100buCWUuyBKWe_96UbevbIEA",
|
|
|
- "ទស្សនាការប្រកួតសង្វៀនប្រដាល់គុនខ្មែរឯកភ្នំ", "ម៉ន សាម៉េត(ខ្មែរ) vs (ថៃ)ហ្វាម៉ែ សែងចាក់", "កម្មវិធីប្រកួតថ្ងៃអាទិត្យ ទី៣១ ខែមិនា ឆ្នាំ២០២៣"),
|
|
|
- EventCardItem("https://i.ytimg.com/vi/Lh5O00zo_pc/hq720.jpg?sqp=-oaymwEcCOgCEMoBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLCEQ100buCWUuyBKWe_96UbevbIEA",
|
|
|
- "ទស្សនាការប្រកួតសង្វៀនប្រដាល់គុនខ្មែរឯកភ្នំ", "ម៉ន សាម៉េត(ខ្មែរ) vs (ថៃ)ហ្វាម៉ែ សែងចាក់", "កម្មវិធីប្រកួតថ្ងៃអាទិត្យ ទី៣១ ខែមិនា ឆ្នាំ២០២៣"),
|
|
|
- // Add more card items as needed
|
|
|
- )
|
|
|
+ recyclerView.adapter = eventAdapter
|
|
|
}
|
|
|
}
|