Browse Source

提交人:jtm
提交内容:同步竖版改动

380474035@qq.com 1 year ago
parent
commit
37f36a71ae

+ 22 - 13
BusinessStep/src/main/java/com/develop/step/ui/recipes_detail/CookDetailSourceFragment.kt

@@ -42,23 +42,32 @@ class CookDetailSourceFragment :
             }
         }
         viewModel.getRecipeLiveData().observe(viewLifecycleOwner) {
-            val sourceItems = mutableListOf<CookSourceItem>()
-            for (recipeFood in it.material) {
-                sourceItems.add(
-                    CookSourceItem(
+            viewModel.portionSizeLiveData.observe(viewLifecycleOwner) { size ->
+                val sourceItems = mutableListOf<CookSourceItem>()
+                val originalList = mutableListOf<CookSourceItem>()
+                for (recipeFood in it.material) {
+                    val sourceItem = CookSourceItem(
                         recipeFood.foodName ?: "",
                         "${recipeFood.amount} ${recipeFood.unit}"
                     )
-                )
-            }
-            val jarCount = it.portionSize.firstOrNull()?.portionSize?.toIntOrNull() ?: 1
-            val string = if (jarCount > 1) {
-                getString(com.develop.common.R.string.make_n_jars, jarCount.toString())
-            } else {
-                getString(com.develop.common.R.string.make_1_jar)
+                    if (recipeFood.recipePortionSizeNumber == size.portionSize) {
+                        sourceItems.add(sourceItem)
+                    }
+                    originalList.add(sourceItem)
+                }
+                if (sourceItems.isEmpty()) {
+                    // 防止没有任何数据显示
+                    sourceItems.addAll(originalList)
+                }
+                val jarCount = size?.portionSize?.toIntOrNull() ?: 1
+                val string = if (jarCount > 1) {
+                    getString(com.develop.common.R.string.make_n_jars, jarCount.toString())
+                } else {
+                    getString(com.develop.common.R.string.make_1_jar)
+                }
+                binding.tvStepTitle.text = string
+                binding.rvList.models = sourceItems
             }
-            binding.tvStepTitle.text = string
-            binding.rvList.models = sourceItems
         }
     }
 }