Browse Source

提交人:jtm
提交内容:添加分类数量,已下载图标黄色

江天明 1 year ago
parent
commit
f97e597b75

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

@@ -7,6 +7,7 @@ import android.util.Log
 import android.view.View
 import android.widget.RelativeLayout
 import androidx.constraintlayout.widget.ConstraintLayout
+import androidx.core.graphics.drawable.DrawableCompat
 import com.blankj.utilcode.util.ThreadUtils.runOnUiThread
 import com.bumptech.glide.Glide
 import com.bumptech.glide.load.DataSource
@@ -83,6 +84,11 @@ class FoodContentView : ConstraintLayout {
             }
         }
         //喜欢点击
+        val tintList = resources.getColorStateList(com.develop.common.R.color.color_cook_tab_tint)
+        binding.ivNet.drawable?.apply {
+            DrawableCompat.setTintList(this, tintList)
+        }
+
         binding.likeLayout.setOnClickListener {
             //收藏/取消收藏
             mFoodContent?.apply {
@@ -194,6 +200,7 @@ class FoodContentView : ConstraintLayout {
             } else {
                 ivNet.visibility = View.GONE
             }
+            ivNet.isSelected = hasDownload
             if (hasDownload) {
                 ivLike.skinSrc(R.drawable.ic_delete)
             } else {

+ 2 - 2
BusinessCommon/src/main/res/color/color_cook_tab_tint.xml

@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
 <selector xmlns:android="http://schemas.android.com/apk/res/android">
-    <item android:color="#ffffff" android:state_selected="true"/>
-    <item android:color="@color/cook_tab_unselected" android:state_selected="false"/>
+    <item android:color="#ffffff" android:state_selected="false"/>
+    <item android:color="#ffa627" android:state_selected="true"/>
 </selector>

+ 34 - 8
BusinessMain/src/main/java/com/develop/main/ui/RecipesFragment.kt

@@ -85,7 +85,13 @@ class RecipesFragment : CommonBVMFragment<FragmentCommeListBinding, HomeViewMode
                         addType<DevRecipeCategory>(R.layout.item_filter_and_sort_view)
                         onBind {
                             val model = getModel<DevRecipeCategory>()
-                            bindFilterSortView(adapter, this, model.name ?: "", true)
+                            bindFilterSortView(
+                                adapter,
+                                this,
+                                model.name ?: "",
+                                true,
+                                model.number ?: ""
+                            )
                         }
                     }
                 }?.models = categoryDataList
@@ -186,6 +192,8 @@ class RecipesFragment : CommonBVMFragment<FragmentCommeListBinding, HomeViewMode
                                 findView<HomeFilterSortSearchView>(R.id.function_view)
                             if (filterSortModel != null) {
                                 filterSortSearchView?.apply {
+                                    val size = viewModel.categorySizeList["all"]
+                                    updateFilterName(getString(com.develop.common.R.string.all) + "($size)")
                                     setVisible()
                                     if (!viewModel.isSearch) {
                                         resetView()
@@ -415,7 +423,8 @@ class RecipesFragment : CommonBVMFragment<FragmentCommeListBinding, HomeViewMode
         adapter: BindingAdapter,
         binder: BindingAdapter.BindingViewHolder,
         name: String,
-        isFilter: Boolean
+        isFilter: Boolean,
+        categoryNum: String? = ""
     ) {
         binder.apply {
             val binding = ItemFilterAndSortViewBinding.bind(itemView)
@@ -424,7 +433,13 @@ class RecipesFragment : CommonBVMFragment<FragmentCommeListBinding, HomeViewMode
             } else {
                 sortedSelectedPos
             }
-            binding.tvName.updateText(name)
+            if (isFilter) {
+                val size = viewModel.categorySizeList[categoryNum]
+                binding.tvName.updateText("$name($size)")
+            } else {
+                binding.tvName.updateText(name)
+            }
+
             if (selectionPos == absoluteAdapterPosition) {
                 binding.tvName.text_color = checkedColor
                 binding.ivCheck.background_drawable = icChecked
@@ -471,7 +486,12 @@ class RecipesFragment : CommonBVMFragment<FragmentCommeListBinding, HomeViewMode
                 //默认All
                 categoryDataList.add(
                     0, DevRecipeCategory(
-                        "", "", getString(com.develop.common.R.string.all), null, null, null
+                        "",
+                        "all",
+                        getString(com.develop.common.R.string.all),
+                        null,
+                        null,
+                        null
                     )
                 )
                 if (lastSortedPos != 0) {
@@ -539,7 +559,7 @@ class RecipesFragment : CommonBVMFragment<FragmentCommeListBinding, HomeViewMode
                 categoryDataList = it
                 categoryDataList.add(
                     0, DevRecipeCategory(
-                        "", "", getString(com.develop.common.R.string.all), null, null, null
+                        "", "all", getString(com.develop.common.R.string.all), null, null, null
                     )
                 )
                 if (currCategoryName.isNotEmpty()) {
@@ -558,7 +578,7 @@ class RecipesFragment : CommonBVMFragment<FragmentCommeListBinding, HomeViewMode
 
             //获取线上热门标签回调
             onLineHotTagsLiveData.observe(viewLifecycleOwner) {
-               // binding.rv.models = DataFactory.genOnLineHotTags(it)
+                // binding.rv.models = DataFactory.genOnLineHotTags(it)
             }
 
             //搜索回调
@@ -586,8 +606,9 @@ class RecipesFragment : CommonBVMFragment<FragmentCommeListBinding, HomeViewMode
     private fun updateCategoryName(devRecipeCategory: DevRecipeCategory) {
         loadingDialog.showDialog(childFragmentManager, "loadingDialog")
         viewModel.currCategoryName = devRecipeCategory.name ?: ""
+        val size = viewModel.categorySizeList[devRecipeCategory.number]
         filterSortSearchView?.updateFilterName(
-            viewModel.currCategoryName
+            viewModel.currCategoryName + "($size)"
         )
         if (viewModel.recipesType == RecipesType.ONLINE) {
             viewModel.categoryCode = devRecipeCategory.code
@@ -597,7 +618,12 @@ class RecipesFragment : CommonBVMFragment<FragmentCommeListBinding, HomeViewMode
             viewModel.categoryCode = devRecipeCategory.number.toString()
             isRefresh = true
             binding.page.resetNoMoreData()
-            viewModel.queryLocalRecipes(viewModel.categoryCode)
+            if (viewModel.categoryCode == "all") {
+                viewModel.queryLocalRecipes("")
+            } else {
+                viewModel.queryLocalRecipes(viewModel.categoryCode)
+            }
+
         }
     }
 

+ 13 - 4
BusinessMain/src/main/java/com/develop/main/viewmodel/HomeViewModel.kt

@@ -89,13 +89,22 @@ class HomeViewModel : BaseViewModel() {
     private var foodCount = 0
     private var recipeDao = FoodDataProvider.getDatabase().recipeDao()
     var errorCallback = MutableLiveData<String>()
+    var categorySizeList = HashMap<String, String>()
 
     /**查询本地菜谱分类*/
     fun queryRecipesCategory() {
-        FoodDataProvider.getDatabase().runInTransaction {
-            localCategoryLiveData.postValue(
-                FoodDataProvider.getDatabase().recipeDao().queryCategory().toMutableList()
-            )
+        var allSize = 0
+        scope(Dispatchers.IO) {
+            val result = FoodDataProvider.getDatabase().recipeDao().queryCategory().toMutableList()
+            categorySizeList.clear()
+            result.forEach {
+                val size = FoodDataProvider.getDatabase().recipeDao()
+                    .queryRecipesByCategory(it.number ?: "").size
+                allSize += size
+                categorySizeList[it.number ?: ""] = size.toString()
+            }
+            categorySizeList["all"] = allSize.toString()
+            localCategoryLiveData.postValue(result)
         }
     }