|
@@ -1,5 +1,6 @@
|
|
package com.sambath.kunkhmer.screen.fighter
|
|
package com.sambath.kunkhmer.screen.fighter
|
|
|
|
|
|
|
|
+import android.content.Intent
|
|
import android.os.Bundle
|
|
import android.os.Bundle
|
|
import android.view.LayoutInflater
|
|
import android.view.LayoutInflater
|
|
import android.view.View
|
|
import android.view.View
|
|
@@ -10,33 +11,54 @@ import com.google.android.material.tabs.TabLayout
|
|
import com.sambath.kunkhmer.R
|
|
import com.sambath.kunkhmer.R
|
|
import com.sambath.kunkhmer.adapter.FighterAdapter
|
|
import com.sambath.kunkhmer.adapter.FighterAdapter
|
|
import com.sambath.kunkhmer.adapter.FighterCardItem
|
|
import com.sambath.kunkhmer.adapter.FighterCardItem
|
|
|
|
+import com.sambath.kunkhmer.app.App
|
|
|
|
+import com.sambath.kunkhmer.app.MainActivity
|
|
|
|
+import com.sambath.kunkhmer.remote.MatchesData
|
|
|
|
+import com.sambath.kunkhmer.screen.login.LoginViewModel
|
|
|
|
+import com.sambath.kunkhmer.screen.login.LoginViewState
|
|
|
|
+import kotlinx.android.synthetic.main.activity_login.tv_error
|
|
import kotlinx.android.synthetic.main.fragment_fighter.view.recyclerViewFighter
|
|
import kotlinx.android.synthetic.main.fragment_fighter.view.recyclerViewFighter
|
|
import kotlinx.android.synthetic.main.fragment_fighter.view.selectedTabTextView
|
|
import kotlinx.android.synthetic.main.fragment_fighter.view.selectedTabTextView
|
|
import kotlinx.android.synthetic.main.fragment_fighter.view.tabLayout
|
|
import kotlinx.android.synthetic.main.fragment_fighter.view.tabLayout
|
|
|
|
+import java.util.Observer
|
|
|
|
|
|
class FighterFragment : Fragment() {
|
|
class FighterFragment : Fragment() {
|
|
private var _root: View? = null
|
|
private var _root: View? = null
|
|
-
|
|
|
|
private val binding get() = _root!!
|
|
private val binding get() = _root!!
|
|
|
|
|
|
// Inside your Fragment:
|
|
// Inside your Fragment:
|
|
var tabSelectionListener: TabSelectionListener? = null
|
|
var tabSelectionListener: TabSelectionListener? = null
|
|
|
|
+ private lateinit var fighterViewModel: FighterViewModel
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
super.onCreate(savedInstanceState)
|
|
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_fighter, container, false)
|
|
_root = inflater.inflate(R.layout.fragment_fighter, container, false)
|
|
|
|
|
|
- setTab()
|
|
|
|
|
|
+ fighterViewModel = FighterViewModel(App.injectApiService(), App.injectPrefHelper())
|
|
|
|
+ fighterViewModel.getMatches()
|
|
|
|
+ fighterViewModel.state.observe(viewLifecycleOwner, androidx.lifecycle.Observer {
|
|
|
|
+ render(it)
|
|
|
|
+ })
|
|
|
|
+
|
|
return binding
|
|
return binding
|
|
}
|
|
}
|
|
|
|
|
|
- private fun setTab() {
|
|
|
|
|
|
+ private fun render(state: FighterViewState) {
|
|
|
|
+ if (state.isProgress) {
|
|
|
|
+ }
|
|
|
|
+ if (state.isLoginSuccess) {
|
|
|
|
+ if(state.matchesData != null) {
|
|
|
|
+ setTab(state.matchesData)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (state.error != null) {
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private fun setTab(data: MatchesData) {
|
|
val tabTitles = listOf("Fri 18 Aug", "Yesterday", "Today", "Tomorrow", "Tue 22 Aug")
|
|
val tabTitles = listOf("Fri 18 Aug", "Yesterday", "Today", "Tomorrow", "Tue 22 Aug")
|
|
|
|
|
|
// Populate TabLayout with dynamic tabs
|
|
// Populate TabLayout with dynamic tabs
|
|
@@ -51,7 +73,7 @@ class FighterFragment : Fragment() {
|
|
tab?.let {
|
|
tab?.let {
|
|
val selectedTitle = it.text.toString()
|
|
val selectedTitle = it.text.toString()
|
|
binding.selectedTabTextView.text = "Selected Tab: $selectedTitle"
|
|
binding.selectedTabTextView.text = "Selected Tab: $selectedTitle"
|
|
- setFighters()
|
|
|
|
|
|
+ setFighters(data)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -67,10 +89,10 @@ class FighterFragment : Fragment() {
|
|
binding.tabLayout.getTabAt(2)?.select()
|
|
binding.tabLayout.getTabAt(2)?.select()
|
|
}
|
|
}
|
|
|
|
|
|
- private fun setFighters() {
|
|
|
|
|
|
+ private fun setFighters(data: MatchesData) {
|
|
val recyclerView = binding.recyclerViewFighter
|
|
val recyclerView = binding.recyclerViewFighter
|
|
- val cardList = createCardList() // Create your card data list here
|
|
|
|
- val cardAdapter = FighterAdapter(cardList)
|
|
|
|
|
|
+ //val cardList = createCardList() // Create your card data list here
|
|
|
|
+ val cardAdapter = FighterAdapter(data.obj)
|
|
|
|
|
|
recyclerView.layoutManager =
|
|
recyclerView.layoutManager =
|
|
LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
|
|
LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
|