From e28606c7d82ae36c1beb989e139e25e4ee449958 Mon Sep 17 00:00:00 2001 From: renhaoting <370797079@qq.com> Date: Tue, 13 Jan 2026 11:37:04 +0800 Subject: [PATCH] =?UTF-8?q?=20=E9=80=82=E9=85=8D=EF=BC=9Ajoin=E6=97=B6=20?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E5=99=A8=E8=BF=94=E5=9B=9Eobj=20=E6=94=BE?= =?UTF-8?q?=E7=BD=AE=E5=88=B0=E4=BA=86=20currentList?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../vididin/features/zero/ZeroBuyActivity.kt | 16 ++++++++----- .../vididin/features/zero/ZeroBuyViewModel.kt | 23 ++++++++++++------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/com/gamedog/vididin/features/zero/ZeroBuyActivity.kt b/app/src/main/java/com/gamedog/vididin/features/zero/ZeroBuyActivity.kt index f010ea1..8008b0f 100644 --- a/app/src/main/java/com/gamedog/vididin/features/zero/ZeroBuyActivity.kt +++ b/app/src/main/java/com/gamedog/vididin/features/zero/ZeroBuyActivity.kt @@ -223,12 +223,16 @@ class ZeroBuyActivity : AppViewsEmptyViewModelActivity() { } private fun updateItemUI(joinedItem: ZeroBuyItem?) { - val currentList = mAdapter.currentList.toMutableList() - val indexToUpdate = currentList.indexOfFirst { it.id == joinedItem?.id } - if (indexToUpdate != -1) { - currentList.removeAt(indexToUpdate) - currentList.add(indexToUpdate, joinedItem) - mAdapter.submitList(currentList) + if (joinedItem == null) { + mAdapter.notifyDataSetChanged() + } else { + val currentList = mAdapter.currentList.toMutableList() + val indexToUpdate = currentList.indexOfFirst { it.id == joinedItem?.id } + if (indexToUpdate != -1) { + currentList.removeAt(indexToUpdate) + currentList.add(indexToUpdate, joinedItem) + mAdapter.submitList(currentList) + } } } diff --git a/app/src/main/java/com/gamedog/vididin/features/zero/ZeroBuyViewModel.kt b/app/src/main/java/com/gamedog/vididin/features/zero/ZeroBuyViewModel.kt index e3708e0..1ced775 100644 --- a/app/src/main/java/com/gamedog/vididin/features/zero/ZeroBuyViewModel.kt +++ b/app/src/main/java/com/gamedog/vididin/features/zero/ZeroBuyViewModel.kt @@ -20,7 +20,10 @@ import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.launch + + class ZeroBuyViewModel : ViewModel() { + private val CODE_HAS_JOINED_BEFORE: Int = 10003 private val _ZeroBuyListData = MutableStateFlow>(Result.Loading) val ZeroBuyListData: StateFlow> = _ZeroBuyListData.asStateFlow() @@ -51,18 +54,22 @@ class ZeroBuyViewModel : ViewModel() { val respObj = AndroidUtil.json2Object(result.data.string()) - respObj?.contentObj?.let { - val itemId = respObj.contentObj?.id - if ((respObj.code == 0 || respObj.code == 10003) && itemId != null && itemId > 0) { - val mutableJoinedIdList = if(joinZeroBuyItemIds == null) mutableListOf() else joinZeroBuyItemIds.toMutableList() - mutableJoinedIdList.add(itemId) - SpUtil.instance().putList(SpUtil.KEY_ZEROBUY_JOINED_ACTIVITY_IDS, mutableJoinedIdList) + respObj?.let { + if (it.code == CODE_HAS_JOINED_BEFORE || it.code == 0) { + // save + val joinedActivityList = if(joinZeroBuyItemIds == null) mutableListOf() else joinZeroBuyItemIds.toMutableList() + if (!joinedActivityList.contains(itemId)) { + joinedActivityList.add(itemId) + SpUtil.instance().putList(SpUtil.KEY_ZEROBUY_JOINED_ACTIVITY_IDS, joinedActivityList) + } - _ZeroBuyJoinResult.value = Result.Success(respObj?.contentObj) + // flow set + _ZeroBuyJoinResult.value = Result.Success(it.current_purchases[0]) + + // return return@launch } } - _ZeroBuyJoinResult.value = Result.Error(Throwable("empty response")) } is Result.Error -> {