diff --git a/app/src/main/java/com/gamedog/vididin/features/withdraw/WithDrawSubActivity.kt b/app/src/main/java/com/gamedog/vididin/features/withdraw/WithDrawSubActivity.kt index f05a728..cc7ff1b 100644 --- a/app/src/main/java/com/gamedog/vididin/features/withdraw/WithDrawSubActivity.kt +++ b/app/src/main/java/com/gamedog/vididin/features/withdraw/WithDrawSubActivity.kt @@ -306,7 +306,7 @@ class WithDrawSubActivity : AppViewsEmptyViewModelActivity() { private fun updateProgressUI() { with(binding) { val subBean = mCurItem.subItemList[mSelectingIndex] - val curProgress = subBean.currentProgress + val curProgress = subBean.currentAdProgress progressBar.setProgress(curProgress) tvProgress.text = "$curProgress%" diff --git a/app/src/main/java/com/gamedog/vididin/manager/WithdrawManager.kt b/app/src/main/java/com/gamedog/vididin/manager/WithdrawManager.kt index e1c9a45..01aef68 100644 --- a/app/src/main/java/com/gamedog/vididin/manager/WithdrawManager.kt +++ b/app/src/main/java/com/gamedog/vididin/manager/WithdrawManager.kt @@ -175,16 +175,16 @@ class WithdrawManager private constructor() { private fun calculateSubBeanProgress(subBean: WithdrawSubItem) { - val needEarnProgress = 100 - subBean.startProgress + val needEarnProgress = 100 - subBean.startAdProgress if (subBean.hasEarnMoneyByAd >= subBean.cashTotal) { - subBean.currentProgress = 100 + subBean.currentAdProgress = 100 // update state if (subBean.withdrawState == STATE_NEED_WATCH_AD) { subBean.withdrawState = STATE_COULD_WITHDRAW } } else { - val newProgress = subBean.startProgress + (needEarnProgress * (subBean.hasEarnMoneyByAd / subBean.cashTotal)).toInt() - subBean.currentProgress = if (newProgress >= 100) 99 else newProgress + val newProgress = subBean.startAdProgress + (needEarnProgress * (subBean.hasEarnMoneyByAd / subBean.cashTotal)).toInt() + subBean.currentAdProgress = if (newProgress >= 100) 100 else newProgress } } @@ -238,6 +238,10 @@ class WithdrawManager private constructor() { needSaveSp =true record.state = newState record.failReason = failType + + if (newState == STATE_HAS_WITHDRAWED) { + checkIfItemFinishAndReset(record.itemIndex) + } } return@forEachIndexed } @@ -246,12 +250,52 @@ class WithdrawManager private constructor() { mRecordLocker.unlock() } - if (needSaveSp) { saveRecords2Sp() } } + private fun checkIfItemFinishAndReset(itemIndex: Int) { + var needReset = false + if (itemIndex == 0) { + needReset = true + } else { + var allSubItemFinish = true + mItemList[itemIndex].subItemList.forEach { + if (it.withdrawState != STATE_HAS_WITHDRAWED) { + allSubItemFinish = false + return@forEach + } + } + + needReset = allSubItemFinish + } + + if (needReset) { + resetItem(itemIndex) + } + } + + private fun resetItem(itemIndex: Int) { + val needResetItem = mItemList[itemIndex] + needResetItem.apply { + totalProgress = 0 + startMs = 0L + hasStarted = false + + subItemList.forEach { subItem -> + subItem.apply { + currentAdProgress = startAdProgress + hasEarnMoneyByAd = 0F + withdrawState = STATE_NEED_WATCH_AD + } + } + } + + notifyItemListChanged() + } + + fun getClonedRecordList(): List { try { mRecordLocker.lock() @@ -507,8 +551,8 @@ data class WithdrawItemBean( data class WithdrawSubItem( val index: Int, val cashTotal: Float, - val startProgress: Int = 0, - var currentProgress: Int = 0, + val startAdProgress: Int = 0, + var currentAdProgress: Int = 0, var hasEarnMoneyByAd: Float = 0F, var withdrawState: Int = STATE_NEED_WATCH_AD, ) \ No newline at end of file