fix(activity): 修复采样与菜品列表页异常场景的数据展示

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-28 17:46:19 +08:00
co-authored by Claude Sonnet 4.6
parent 425f485b95
commit e8933fa578
3 changed files with 21 additions and 3 deletions
@@ -59,6 +59,7 @@ class SamplingListActivity : BaseActivity() {
lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
appViewModel.cookFoodListState.collect { cookFoodEntities ->
if (binding.dishRadioGroup.checkedRadioButtonId != R.id.rbSamplingCooking) return@collect
delayDismissLoading()
if (cookFoodEntities.isNullOrEmpty()) {
loadEmptyView()
@@ -89,8 +90,18 @@ class SamplingListActivity : BaseActivity() {
netViewModel.samplingListState.collect { state ->
when (state) {
is UiState.Loading -> showLoading()
is UiState.Success -> loadDishList(state.data)
is UiState.Success -> {
if (binding.dishRadioGroup.checkedRadioButtonId != R.id.rbSamplingFinished) {
delayDismissLoading()
return@collect
}
loadDishList(state.data)
}
is UiState.Error -> {
if (binding.dishRadioGroup.checkedRadioButtonId != R.id.rbSamplingFinished) {
delayDismissLoading()
return@collect
}
binding.refreshLayout.setEnableRefresh(true)
toast(state.msg)
finishRefresh()
@@ -146,8 +146,15 @@ class DishListFragment : BaseFragment<FragmentDishListBinding>() {
if (isAdded.not()) return@collect
toast(networkState.msg)
finishRefresh()
if (pageNo == 1) loadEmptyView()
activity.delayDismissLoading()
if (pageNo == 1) {
// 网络异常或接口不通时,降级使用本地数据;本地也为空才显示空视图
if (localList.isNullOrEmpty()) {
loadEmptyView()
} else {
loadAndMergeDishList(null, localList)
}
}
}
is UiState.Idle -> {}
}
@@ -55,7 +55,7 @@
android:layout_height="wrap_content">
<TextView
android:layout_width="120dp"
android:layout_width="wrap_content"
android:layout_height="80dp"
android:layout_gravity="start"
android:layout_marginStart="30dp"