Browse Source

提交人:jtm
提交内容:菜品刷新

江天明 1 year ago
parent
commit
857ac3c2bc

+ 9 - 2
BusinessCommon/src/main/java/com/develop/common/data_repo/db/ModelKit.kt

@@ -1,5 +1,7 @@
 package com.develop.common.data_repo.db
 
+import com.drake.brv.item.ItemStableId
+
 
 data class ModelsModel(var resId: Int, var modeName: String, var modesType: ModesType)
 data class NewsModel(var title: String, var des: String, var hasRead: Boolean)
@@ -20,10 +22,15 @@ data class FoodContentModel(
     var isNetRecipes: Boolean = false,
     var hasDownloaded: Boolean = false,
     var isLike: Boolean = false,
-    var foodId: String = "",
+    var foodId: String = "1",
     var recipesEdition: String? = "1.0",
     var useNum: Int = 0
-)
+):ItemStableId{
+    override fun getItemId(): Long {
+        return foodId.toLong()
+    }
+
+}
 
 data class FoodListModel(var foodList: MutableList<FoodContentModel>, var categoryName: String)
 

+ 2 - 2
BusinessCommon/src/main/java/com/develop/common/widget/FoodContentView.kt

@@ -59,8 +59,8 @@ class FoodContentView : ConstraintLayout {
     init {
         val root = View.inflate(context, R.layout.food_content_view, this)
         binding = FoodContentViewBinding.bind(root)
-//        binding.contentLayout.background_drawable = R.drawable.food_content_conner
-//        binding.likeLayout.background_drawable = R.drawable.white_circle
+        binding.contentLayout.background_drawable = R.drawable.food_content_conner
+        binding.likeLayout.background_drawable = R.drawable.white_circle
         binding.contentLayout.setOnClickListener {
             mFoodContent?.apply {
                 TopResumedAtyHolder.getCurrentActivity()?.navigateTo(Screens.Cook.COOK_DETAIL) {

+ 35 - 30
BusinessMain/src/main/java/com/develop/main/ui/RecipesFragment.kt

@@ -163,6 +163,40 @@ class RecipesFragment : CommonBVMFragment<FragmentCommeListBinding, HomeViewMode
                 addType<CommonSearchModel>(HOME_SEARCH_PROVIDER)
                 addType<CategoryModel>(HOME_CATEGORY_PROVIDER)
                 addType<FoodListModel>(HOME_FOOD_LIST_PROVIDER)
+                onCreate {
+                    if (it == HOME_FOOD_LIST_PROVIDER){
+                        foodRecycle = findView(R.id.food_recycle)
+
+                        (foodRecycle?.itemAnimator as SimpleItemAnimator).supportsChangeAnimations =
+                            false
+                        foodRecycle?.setHasFixedSize(true)
+                        foodRecycle?.isNestedScrollingEnabled = false
+                        foodRecycle?.setRecycledViewPool(recycledViewPool)
+                        foodRecycle?.grid(4)
+                        foodRecycle?.setup {
+                            setHasStableIds(true)
+                            if (isNightTheme()) {
+                                addType<FoodContentModel>(com.develop.common.R.layout.food_content_night_provider)
+                                onBind {
+                                    findView<FoodContentView>(com.develop.common.R.id.food_content_view).setFoodContent(
+                                        getModel()
+                                    )
+                                }
+                            } else {
+                                addType<FoodContentModel>(com.develop.common.R.layout.food_content_provider)
+                                onBind {
+                                    findView<FoodContentView>(com.develop.common.R.id.food_content_view).setFoodContent(
+                                        getModel()
+                                    )
+                                }
+                            }
+                        }
+                        foodRecycle?.setRecyclerListener { holder ->
+                            holder.itemView.findViewById<FoodContentView>(com.develop.common.R.id.food_content_view)
+                                .recycleImageView()
+                        }
+                    }
+                }
                 onBind {
                     when (itemViewType) {
                         HOME_TITLE_PROVIDER -> {
@@ -175,36 +209,7 @@ class RecipesFragment : CommonBVMFragment<FragmentCommeListBinding, HomeViewMode
 
                         HOME_FOOD_LIST_PROVIDER -> {
                             val models = getModel<FoodListModel>()
-                            foodRecycle = findView(R.id.food_recycle)
-                            (foodRecycle?.itemAnimator as SimpleItemAnimator).supportsChangeAnimations =
-                                false
-                            foodRecycle?.setHasFixedSize(true)
-                            foodRecycle?.isNestedScrollingEnabled = false
-                            foodRecycle?.setRecycledViewPool(recycledViewPool)
-                            foodRecycle?.grid(4)
-                            foodRecycle?.setup {
-                                if (isNightTheme()) {
-                                    addType<FoodContentModel>(com.develop.common.R.layout.food_content_night_provider)
-                                    onBind {
-                                        findView<FoodContentView>(com.develop.common.R.id.food_content_view).setFoodContent(
-                                            getModel()
-                                        )
-                                    }
-                                } else {
-                                    addType<FoodContentModel>(com.develop.common.R.layout.food_content_provider)
-                                    onBind {
-                                        findView<FoodContentView>(com.develop.common.R.id.food_content_view).setFoodContent(
-                                            getModel()
-                                        )
-                                    }
-                                }
-
-
-                            }?.models = models.foodList
-                            foodRecycle?.setRecyclerListener { holder ->
-                                holder.itemView.findViewById<FoodContentView>(com.develop.common.R.id.food_content_view)
-                                    .recycleImageView()
-                            }
+                            foodRecycle?.models = models.foodList
                         }
 
                         HOME_FUNCTION_PROVIDER -> {