参与成功后再 扣减钻石

This commit is contained in:
renhaoting 2025-12-24 18:34:10 +08:00
parent a3b0386c9d
commit aefd72680b
4 changed files with 13 additions and 6 deletions

View File

@ -70,7 +70,7 @@ class ZeroBuyActivity : AppViewsEmptyViewModelActivity<ViewBinding>() {
with(recyclerView) {
mAdapter = ZeroItemAdapter({ itemId, diamondCost->
if (AccountManager.adjustDiamond(diamondCost)) {
if (AccountManager.getDiamond() >= diamondCost) {
requestParticipateActivity(itemId)
} else {
AndroidUtil.showToast(R.string.dont_enought_diamond)
@ -156,8 +156,14 @@ class ZeroBuyActivity : AppViewsEmptyViewModelActivity<ViewBinding>() {
viewModel.ZeroBuyJoinResult.collect { result ->
when (result) {
is Result.Loading -> { }
is Result.Success -> updateItemUI(result.data)
is Result.Error -> { }
is Result.Success -> {
result.data?.let {
AccountManager.adjustDiamond(-1 * it.cost)
}
updateItemUI(result.data)
}
is Result.Error -> { AndroidUtil.showToast(R.string.has_join_failed_zerobuy) }
}
}
}

View File

@ -32,7 +32,7 @@ class ZeroRecordAdapter() : ListAdapter<ZeroBuyItem, ZeroRecordAdapter.ViewHolde
private fun isWinItem(item: ZeroBuyItem): Boolean {
val winerIds = item.winners
return winerIds?.contains(AccountManager.getAccount()?.userId) ?: false
return winerIds?.contains(AccountManager.getAccount().userId) ?: false
}
inner class ViewHolder(private val binding: ViewBinding) : RecyclerView.ViewHolder(binding.root) {

View File

@ -74,7 +74,7 @@ object AccountManager {
@Synchronized
fun adjustCash(adjustNum: Float, recordBean: RecordCash?): Boolean {
if (adjustNum < 0L && Math.abs(adjustNum) > getGold()) {
if (adjustNum < 0L && Math.abs(adjustNum) > getCash()) {
return false
}
mAccount.cashCount += adjustNum
@ -92,7 +92,7 @@ object AccountManager {
@Synchronized
fun adjustDiamond(adjustNum: Int): Boolean {
if (adjustNum < 0L && Math.abs(adjustNum) > getGold()) {
if (adjustNum < 0L && Math.abs(adjustNum) > getDiamond()) {
return false
}
mAccount.diamondCount += adjustNum

View File

@ -120,6 +120,7 @@
<string name="record_cash_title_hint">Total sacado até o momento:</string>
<string name="participar_ed">Já participou</string>
<string name="remain_time">Reembolso em</string>
<string name="has_join_failed_zerobuy">participate this activity failed.</string>
<string name="has_joined_zerobuy">You have participated this activity.</string>
<string name="no_data_hint">There\'s no any record</string>
<string name="get">Get</string>