|
@@ -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
|
|
|
}
|
|
|
}
|
|
|
}
|