From 3fa2c5638f4f6f848ea8fbf6e3f258a67e6b596c Mon Sep 17 00:00:00 2001 From: renhaoting <370797079@qq.com> Date: Thu, 25 Dec 2025 18:51:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=BA=BF=E7=A8=8B=E5=AE=89?= =?UTF-8?q?=E5=85=A8locker?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gamedog/vididin/manager/ZeroManager.kt | 69 +++++++++---------- 1 file changed, 32 insertions(+), 37 deletions(-) diff --git a/app/src/main/java/com/gamedog/vididin/manager/ZeroManager.kt b/app/src/main/java/com/gamedog/vididin/manager/ZeroManager.kt index e972a0c..b15fa6c 100644 --- a/app/src/main/java/com/gamedog/vididin/manager/ZeroManager.kt +++ b/app/src/main/java/com/gamedog/vididin/manager/ZeroManager.kt @@ -10,7 +10,6 @@ import com.gamedog.vididin.VidiConst import com.gamedog.vididin.VidiConst.ZEROBUY_SECRET import com.gamedog.vididin.VididinEvents import com.gamedog.vididin.beans.ZeroBuyItem -import com.gamedog.vididin.beans.ZeroBuyResp import com.gamedog.vididin.beans.ZeroBuyWithdrawResp import com.gamedog.vididin.core.login.login.AccountManager import com.gamedog.vididin.features.withdraw.dialogs.WithdrawBindBankDialog @@ -27,7 +26,7 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.launch -import kotlinx.coroutines.withContext +import java.util.concurrent.locks.ReentrantLock import kotlin.Int @@ -50,6 +49,8 @@ class ZeroManager private constructor() { SpUtil.instance().getList(SpUtil.KEY_ZEROBUY_WIN_ITEMS).toMutableList() } + private val mRecordLocker = ReentrantLock() + private fun saveWinWithdrawInfos() { SpUtil.instance().putList(SpUtil.KEY_ZEROBUY_WIN_ITEMS, mWinZeroList) notifyChangeUpdate() @@ -69,63 +70,57 @@ class ZeroManager private constructor() { if (it.contains(userId) && zeroItem.completed) { var alreadyExist = false - mWinZeroList.forEach { - if (it.purchase_id == zeroItem.id) { - alreadyExist = true - return@forEach + try { + mRecordLocker.lock() + mWinZeroList.forEach { + if (it.purchase_id == zeroItem.id) { + alreadyExist = true + return@forEach + } } - } - if (!alreadyExist) { - mWinZeroList.add(WinZeroWithdrawInfoItem(zeroItem.id, zeroItem.title, zeroItem.price)) - saveWinWithdrawInfos() + if (!alreadyExist) { + mWinZeroList.add(WinZeroWithdrawInfoItem(zeroItem.id, zeroItem.title, zeroItem.price)) + saveWinWithdrawInfos() + } + } finally { + mRecordLocker.unlock() } } } } fun getZeroWithdrawItem(zeroItem: ZeroBuyItem): WinZeroWithdrawInfoItem { - return mWinZeroList.filter { zeroItem.id == it.purchase_id }[0] + try { + mRecordLocker.lock() + return mWinZeroList.filter { zeroItem.id == it.purchase_id }[0] + } finally { + mRecordLocker.unlock() + } } fun couldStartWithdraw(zeroItem: ZeroBuyItem): Boolean { val userId = AccountManager.getAccount().userId zeroItem.winners?.let { if (it.contains(userId) && zeroItem.completed) { - mWinZeroList.forEach { - if (it.purchase_id == zeroItem.id) { - return it.withdrawState == TRANSACTION_STATE_UNSTART || it.withdrawState == TRANSACTION_STATE_FAIL + try { + mRecordLocker.lock() + mWinZeroList.forEach { + if (it.purchase_id == zeroItem.id) { + return it.withdrawState == TRANSACTION_STATE_UNSTART || it.withdrawState == TRANSACTION_STATE_FAIL + } } + addWinWithdrawItem(zeroItem) + return true + } finally { + mRecordLocker.unlock() } - addWinWithdrawItem(zeroItem) - return true } } return false } - fun startWithdrawForWinPurchase(zeroItem: ZeroBuyItem) { - if (couldStartWithdraw(zeroItem)) { - /*when (it.withdrawState) { - TRANSACTION_STATE_UNSTART -> { - - } - - TRANSACTION_STATE_ONGOING -> { - - } - - TRANSACTION_STATE_SUCCESS -> { - - } - - TRANSACTION_STATE_FAIL -> { - - } - }*/ - } - } private fun requestWithdrawZeroReward(zeroWithdrawItem: WinZeroWithdrawInfoItem) {