数据线程安全locker
This commit is contained in:
parent
ab540875e6
commit
3fa2c5638f
|
|
@ -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<WinZeroWithdrawInfoItem>(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) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue