|
@@ -5,13 +5,23 @@ import androidx.fragment.app.Fragment
|
|
import android.view.LayoutInflater
|
|
import android.view.LayoutInflater
|
|
import android.view.View
|
|
import android.view.View
|
|
import android.view.ViewGroup
|
|
import android.view.ViewGroup
|
|
|
|
+import androidx.recyclerview.widget.LinearLayoutManager
|
|
import com.sambath.kunkhmer.R
|
|
import com.sambath.kunkhmer.R
|
|
|
|
+import com.sambath.kunkhmer.adapter.ProductAdapter
|
|
|
|
+import com.sambath.kunkhmer.adapter.ProductCardItem
|
|
|
|
+import com.sambath.kunkhmer.app.App
|
|
|
|
+import com.sambath.kunkhmer.screen.news.NewsViewState
|
|
|
|
+import kotlinx.android.synthetic.main.fragment_news.view.recyclerViewNews
|
|
|
|
+import kotlinx.android.synthetic.main.fragment_shop.view.recyclerViewShop
|
|
|
|
|
|
|
|
|
|
-class ShopFragment : Fragment() {
|
|
|
|
|
|
+class ShopFragment : Fragment(), ProductAdapter.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<ProductCardItem>? = null
|
|
|
|
+ private lateinit var productAdapter: ProductAdapter
|
|
|
|
+ private lateinit var shopViewModel: ShopViewModel
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
super.onCreate(savedInstanceState)
|
|
super.onCreate(savedInstanceState)
|
|
@@ -22,6 +32,34 @@ class ShopFragment : Fragment() {
|
|
savedInstanceState: Bundle?
|
|
savedInstanceState: Bundle?
|
|
): View? {
|
|
): View? {
|
|
_root = inflater.inflate(R.layout.fragment_shop, container, false)
|
|
_root = inflater.inflate(R.layout.fragment_shop, container, false)
|
|
|
|
+
|
|
|
|
+ shopViewModel = ShopViewModel(App.injectApiService(), App.injectPrefHelper())
|
|
|
|
+ productAdapter = ProductAdapter(mutableListOf(), this)
|
|
|
|
+ shopViewModel.getProducts()
|
|
|
|
+
|
|
|
|
+ binding.recyclerViewShop.apply {
|
|
|
|
+ layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
|
|
|
|
+ adapter = productAdapter
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ shopViewModel.state.observe(viewLifecycleOwner, androidx.lifecycle.Observer {
|
|
|
|
+ render(it)
|
|
|
|
+ })
|
|
|
|
+
|
|
return binding
|
|
return binding
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ private fun render(state: ShopViewModel.ProductViewState) {
|
|
|
|
+ if (state.isLoginSuccess) {
|
|
|
|
+ if(state.productData != null) {
|
|
|
|
+ productAdapter.cardList = state.productData
|
|
|
|
+ productAdapter.notifyDataSetChanged()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // Other state handling...
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ override fun onItemClick(position: Int) {
|
|
|
|
+ TODO("Not yet implemented")
|
|
|
|
+ }
|
|
}
|
|
}
|