适配:join时 服务器返回obj 放置到了 currentList
This commit is contained in:
parent
922df7550e
commit
e28606c7d8
|
|
@ -223,6 +223,9 @@ class ZeroBuyActivity : AppViewsEmptyViewModelActivity<ViewBinding>() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateItemUI(joinedItem: ZeroBuyItem?) {
|
private fun updateItemUI(joinedItem: ZeroBuyItem?) {
|
||||||
|
if (joinedItem == null) {
|
||||||
|
mAdapter.notifyDataSetChanged()
|
||||||
|
} else {
|
||||||
val currentList = mAdapter.currentList.toMutableList()
|
val currentList = mAdapter.currentList.toMutableList()
|
||||||
val indexToUpdate = currentList.indexOfFirst { it.id == joinedItem?.id }
|
val indexToUpdate = currentList.indexOfFirst { it.id == joinedItem?.id }
|
||||||
if (indexToUpdate != -1) {
|
if (indexToUpdate != -1) {
|
||||||
|
|
@ -231,6 +234,7 @@ class ZeroBuyActivity : AppViewsEmptyViewModelActivity<ViewBinding>() {
|
||||||
mAdapter.submitList(currentList)
|
mAdapter.submitList(currentList)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,10 @@ import kotlinx.coroutines.flow.StateFlow
|
||||||
import kotlinx.coroutines.flow.asStateFlow
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ZeroBuyViewModel : ViewModel() {
|
class ZeroBuyViewModel : ViewModel() {
|
||||||
|
private val CODE_HAS_JOINED_BEFORE: Int = 10003
|
||||||
private val _ZeroBuyListData = MutableStateFlow<Result<ZeroBuyResp>>(Result.Loading)
|
private val _ZeroBuyListData = MutableStateFlow<Result<ZeroBuyResp>>(Result.Loading)
|
||||||
val ZeroBuyListData: StateFlow<Result<ZeroBuyResp>> = _ZeroBuyListData.asStateFlow()
|
val ZeroBuyListData: StateFlow<Result<ZeroBuyResp>> = _ZeroBuyListData.asStateFlow()
|
||||||
|
|
||||||
|
|
@ -51,18 +54,22 @@ class ZeroBuyViewModel : ViewModel() {
|
||||||
val respObj = AndroidUtil.json2Object<ZeroBuyResp>(result.data.string())
|
val respObj = AndroidUtil.json2Object<ZeroBuyResp>(result.data.string())
|
||||||
|
|
||||||
|
|
||||||
respObj?.contentObj?.let {
|
respObj?.let {
|
||||||
val itemId = respObj.contentObj?.id
|
if (it.code == CODE_HAS_JOINED_BEFORE || it.code == 0) {
|
||||||
if ((respObj.code == 0 || respObj.code == 10003) && itemId != null && itemId > 0) {
|
// save
|
||||||
val mutableJoinedIdList = if(joinZeroBuyItemIds == null) mutableListOf<Int>() else joinZeroBuyItemIds.toMutableList()
|
val joinedActivityList = if(joinZeroBuyItemIds == null) mutableListOf<Int>() else joinZeroBuyItemIds.toMutableList()
|
||||||
mutableJoinedIdList.add(itemId)
|
if (!joinedActivityList.contains(itemId)) {
|
||||||
SpUtil.instance().putList(SpUtil.KEY_ZEROBUY_JOINED_ACTIVITY_IDS, mutableJoinedIdList)
|
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
|
return@launch
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_ZeroBuyJoinResult.value = Result.Error(Throwable("empty response"))
|
_ZeroBuyJoinResult.value = Result.Error(Throwable("empty response"))
|
||||||
}
|
}
|
||||||
is Result.Error -> {
|
is Result.Error -> {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue