From 0c8e6a2efe4d772f3b578fd97f1e5f28d50ba201 Mon Sep 17 00:00:00 2001 From: renhaoting <370797079@qq.com> Date: Tue, 6 Jan 2026 19:14:24 +0800 Subject: [PATCH] =?UTF-8?q?WithdrawItem=20=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../features/watchad/WatchAdActivity.kt | 4 +- .../features/withdraw/WithDrawSubActivity.kt | 9 +- .../features/withdraw/WithdrawSubAdapter.kt | 6 +- .../vididin/manager/WithdrawManager.kt | 107 ++++++------------ 4 files changed, 46 insertions(+), 80 deletions(-) diff --git a/app/src/main/java/com/gamedog/vididin/features/watchad/WatchAdActivity.kt b/app/src/main/java/com/gamedog/vididin/features/watchad/WatchAdActivity.kt index 45b2e0e..125f34c 100644 --- a/app/src/main/java/com/gamedog/vididin/features/watchad/WatchAdActivity.kt +++ b/app/src/main/java/com/gamedog/vididin/features/watchad/WatchAdActivity.kt @@ -15,7 +15,7 @@ import com.gamedog.vididin.VidiConst import com.gamedog.vididin.VididinEvents import com.gamedog.vididin.beans.WatchAdNotifyBean import com.gamedog.vididin.main.interfaces.OnTabStyleListener -import com.gamedog.vididin.manager.WithdrawItemBean +import com.gamedog.vididin.manager.WithdrawItem import com.remax.bill.ads.AdResult import com.remax.bill.ads.ext.AdShowExt import dagger.hilt.android.AndroidEntryPoint @@ -83,7 +83,7 @@ class WatchAdActivity : AppViewsEmptyViewModelActivity(), OnTabStyl notifyEventType = VididinEvents.EVENT_AD_WATCHED_FOR_WITHDRAW_BIG val extraData = mExtraJsonStr?.let { - AndroidUtil.json2Object(mExtraJsonStr!!) + AndroidUtil.json2Object(mExtraJsonStr!!) } notifyData.mData = WatchAdNotifyBean(mRewardedDollarNum, extraData) } 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 f1f4971..c54321c 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 @@ -6,7 +6,6 @@ import android.text.method.ScrollingMovementMethod import android.view.LayoutInflater import androidx.activity.viewModels import androidx.core.view.isVisible -import androidx.lifecycle.Lifecycle import androidx.lifecycle.lifecycleScope import androidx.recyclerview.widget.LinearLayoutManager import com.ama.core.architecture.appBase.AppViewsEmptyViewModelActivity @@ -25,7 +24,7 @@ import com.gamedog.vididin.features.withdraw.dialogs.WithdrawBindBankDialog import com.gamedog.vididin.features.withdraw.dialogs.WithdrawFailDialog import com.gamedog.vididin.features.withdraw.dialogs.WithdrawInfoConfirmDialog import com.gamedog.vididin.features.withdraw.dialogs.WithdrawSuccessDialog -import com.gamedog.vididin.manager.WithdrawItemBean +import com.gamedog.vididin.manager.WithdrawItem import com.gamedog.vididin.manager.WithdrawManager import com.gamedog.vididin.manager.WithdrawManager.Companion.INIT_OK import com.gamedog.vididin.manager.WithdrawManager.Companion.TRANSACTION_STATE_FAIL @@ -44,7 +43,7 @@ import com.viddin.videos.free.databinding.ActivityWithdrawSubBinding as ViewBind class WithDrawSubActivity : AppViewsEmptyViewModelActivity() { private val viewModel: WithdrawViewModel by viewModels() - private lateinit var mCurItem: WithdrawItemBean + private lateinit var mCurItem: WithdrawItem private var mSelectingIndex: Int = 0 private var mType: Int = 0 private val mAdapter: WithdrawSubAdapter by lazy { WithdrawSubAdapter( { itemIndex -> @@ -228,7 +227,7 @@ class WithDrawSubActivity : AppViewsEmptyViewModelActivity() { registerEvents({ data-> when (data?.mEventType) { VididinEvents.EVENT_AD_WATCHED_FOR_WITHDRAW_BIG -> { - handleAdWatched(data.mData as WatchAdNotifyBean) + handleAdWatched(data.mData as WatchAdNotifyBean) } VididinEvents.EVENT_WITHDRAW_SUB_ITEM_PROGRESS_UPDATED -> { @@ -282,7 +281,7 @@ class WithDrawSubActivity : AppViewsEmptyViewModelActivity() { } } - private fun handleAdWatched(adNotifyBean: WatchAdNotifyBean) { + private fun handleAdWatched(adNotifyBean: WatchAdNotifyBean) { val withdrawItemBean = adNotifyBean.extraData if (WithdrawManager.instance().addAdEarnForSubBean(withdrawItemBean.index, mSelectingIndex, adNotifyBean.earnMoneyNum * VidiConst.WITHDRAW_REWARD_AD_REVENUE_PERCENT)) { diff --git a/app/src/main/java/com/gamedog/vididin/features/withdraw/WithdrawSubAdapter.kt b/app/src/main/java/com/gamedog/vididin/features/withdraw/WithdrawSubAdapter.kt index d9bedd6..a8c9e6f 100644 --- a/app/src/main/java/com/gamedog/vididin/features/withdraw/WithdrawSubAdapter.kt +++ b/app/src/main/java/com/gamedog/vididin/features/withdraw/WithdrawSubAdapter.kt @@ -39,10 +39,10 @@ class WithdrawSubAdapter(private val selectCallback: (index: Int)->Unit) : ListA tvDay.text = buildString { append(ResUtil.getString(R.string.day)) append(" ") - append(item.index + 1) + append(item.dayIndex + 1) } - if (item.index == mSelectedSubIndex) { + if (item.dayIndex == mSelectedSubIndex) { root.setBackgroundResource(R.drawable.bg_withdraw_sub_selected) root.alpha = 1F ivLefttopChecked.isVisible = true @@ -57,7 +57,7 @@ class WithdrawSubAdapter(private val selectCallback: (index: Int)->Unit) : ListA class DiffCallback : DiffUtil.ItemCallback() { override fun areItemsTheSame(oldItem: WithdrawSubItem, newItem: WithdrawSubItem): Boolean { - return oldItem.index == newItem.index + return oldItem.dayIndex == newItem.dayIndex } override fun areContentsTheSame(oldItem: WithdrawSubItem, newItem: WithdrawSubItem): Boolean { 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 6c770f3..0d30fb3 100644 --- a/app/src/main/java/com/gamedog/vididin/manager/WithdrawManager.kt +++ b/app/src/main/java/com/gamedog/vididin/manager/WithdrawManager.kt @@ -11,8 +11,6 @@ import com.gamedog.statisticreporter.StatisticUtil import com.gamedog.vididin.VidiConst import com.gamedog.vididin.VididinEvents import com.gamedog.vididin.beans.RECORD_CASH_MINUS_WITHDRAW_SUCCESS -import com.gamedog.vididin.beans.RECORD_CASH_PLUS_WITHDRAW_FAIL -import com.gamedog.vididin.beans.RECORD_CASH_PLUS_WITHDRAW_ONGOING import com.gamedog.vididin.beans.RecordCash import com.gamedog.vididin.beans.req.PayInitReq import com.gamedog.vididin.beans.req.PayoutCheckReq @@ -32,15 +30,15 @@ import java.util.concurrent.locks.ReentrantLock class WithdrawManager private constructor() { - private val backgroundScope = CoroutineScope(SupervisorJob() + Dispatchers.IO) + private val mBgScope = CoroutineScope(SupervisorJob() + Dispatchers.IO) private val mRecordLocker = ReentrantLock() private val mRecordList: MutableList by lazy { SpUtil.instance().getList(SpUtil.KEY_WITHDRAW_HISTORY_LIST).toMutableList() } - private val mItemList: MutableList by lazy { - val itemList = SpUtil.instance().getList(SpUtil.KEY_WITHDRAW_ITEM_LIST).toMutableList() + private val mWithdrawItemList: MutableList by lazy { + val itemList = SpUtil.instance().getList(SpUtil.KEY_WITHDRAW_ITEM_LIST).toMutableList() if (itemList.isEmpty()) { itemList.addAll(generateItemList()) saveInfos2Sp(itemList) @@ -116,14 +114,14 @@ class WithdrawManager private constructor() { - private fun generateItemList(): MutableList { - val itemList = mutableListOf() - itemList.add(WithdrawItemBean(0, 0.1, isBigWithDraw = false)) - itemList.add(WithdrawItemBean(1, 10.0, AndroidUtil.randomInt(50, 70), generateSubItemList(10.0))) - itemList.add(WithdrawItemBean(2, 20.0, AndroidUtil.randomInt(50, 70), generateSubItemList(20.0))) - itemList.add(WithdrawItemBean(3, 50.0, AndroidUtil.randomInt(50, 70), generateSubItemList(50.0))) - itemList.add(WithdrawItemBean(4, 100.0, AndroidUtil.randomInt(50, 70), generateSubItemList(100.0))) - itemList.add(WithdrawItemBean(5, 300.0, AndroidUtil.randomInt(50, 70), generateSubItemList(300.0))) + private fun generateItemList(): MutableList { + val itemList = mutableListOf() + itemList.add(WithdrawItem(0, 0.1, isBigWithDraw = false)) + itemList.add(WithdrawItem(1, 10.0, AndroidUtil.randomInt(50, 70), generateSubItemList(10.0))) + itemList.add(WithdrawItem(2, 20.0, AndroidUtil.randomInt(50, 70), generateSubItemList(20.0))) + itemList.add(WithdrawItem(3, 50.0, AndroidUtil.randomInt(50, 70), generateSubItemList(50.0))) + itemList.add(WithdrawItem(4, 100.0, AndroidUtil.randomInt(50, 70), generateSubItemList(100.0))) + itemList.add(WithdrawItem(5, 300.0, AndroidUtil.randomInt(50, 70), generateSubItemList(300.0))) return itemList } @@ -138,16 +136,16 @@ class WithdrawManager private constructor() { return subItemList } - private fun saveInfos2Sp(itemList: MutableList) { + private fun saveInfos2Sp(itemList: MutableList) { SpUtil.instance().putList(SpUtil.KEY_WITHDRAW_ITEM_LIST, itemList) } - fun getItemList(): List { - return mItemList + fun getItemList(): List { + return mWithdrawItemList } - fun getItem(itemIndex: Int): WithdrawItemBean { - return mItemList[itemIndex] + fun getItem(itemIndex: Int): WithdrawItem { + return mWithdrawItemList[itemIndex] } @@ -176,12 +174,12 @@ class WithdrawManager private constructor() { } fun addAdEarnForSubBean(itemIndex: Int, selectedSubIndex: Int, earnMoneyNum: Double) : Boolean { - if (itemIndex >= 0 && itemIndex < mItemList.size) { + if (itemIndex >= 0 && itemIndex < mWithdrawItemList.size) { try { - val subBean = mItemList[itemIndex].subItemList[selectedSubIndex] + val subBean = mWithdrawItemList[itemIndex].subItemList[selectedSubIndex] subBean.hasEarnMoneyByAd += earnMoneyNum * 5 // dollar 2 bariz calculateSubBeanProgress(subBean) //传入 itembean 更新 selectedIndex为下一个 - saveInfos2Sp(mItemList) + saveInfos2Sp(mWithdrawItemList) notifyProgressUpdated(subBean) return true } catch (e: Exception) { @@ -194,11 +192,11 @@ class WithdrawManager private constructor() { private fun notifyProgressUpdated(subBean: WithdrawSubItem) { NotifyMan.instance().sendEvent(VididinEvents.EVENT_WITHDRAW_SUB_ITEM_PROGRESS_UPDATED, - NotifyMan.NotifyData(subBean.index)) + NotifyMan.NotifyData(subBean.dayIndex)) } private fun notifySelectedSubBeanChanged(subBean: WithdrawSubItem) { - NotifyMan.instance().sendEvent(VididinEvents.EVENT_WITHDRAW_SELECTED_SUB_ITEM_CHANGED, NotifyMan.NotifyData(subBean.index)) + NotifyMan.instance().sendEvent(VididinEvents.EVENT_WITHDRAW_SELECTED_SUB_ITEM_CHANGED, NotifyMan.NotifyData(subBean.dayIndex)) } private fun notifyItemListChanged() { @@ -222,13 +220,13 @@ class WithdrawManager private constructor() { fun updateSubBeanState(subBean: WithdrawSubItem, newState: Int) { subBean.withdrawState = newState - saveInfos2Sp(mItemList) + saveInfos2Sp(mWithdrawItemList) } - fun startItem(curItem: WithdrawItemBean) { + fun startItem(curItem: WithdrawItem) { if (curItem.startMs <= 0L) { curItem.startMs = DateUtil.getCurTimeMs() - (if (curItem.totalCashNum == 50.0) 24 * 3600000 * 4 else 0) - saveInfos2Sp(mItemList) + saveInfos2Sp(mWithdrawItemList) } } @@ -289,7 +287,7 @@ class WithdrawManager private constructor() { needReset = true } else { var allSubItemFinish = true - mItemList[itemIndex].subItemList.forEach { + mWithdrawItemList[itemIndex].subItemList.forEach { if (it.withdrawState != STATE_HAS_WITHDRAWED) { allSubItemFinish = false return@forEach @@ -305,7 +303,7 @@ class WithdrawManager private constructor() { } private fun resetItem(itemIndex: Int) { - val needResetItem = mItemList[itemIndex] + val needResetItem = mWithdrawItemList[itemIndex] needResetItem.apply { totalProgress = 0 startMs = 0L @@ -370,7 +368,9 @@ class WithdrawManager private constructor() { mRecordLocker.lock() mRecordList.forEachIndexed { index, record -> if (record.state == TRANSACTION_STATE_ONGOING) { - doTransactionCheck(record.recordNo, record.cashNum) + mBgScope.launch { + requestCheck(record.recordNo) + } } } } finally { @@ -379,13 +379,7 @@ class WithdrawManager private constructor() { } } - private fun doTransactionCheck(recordNo: String, cashNum: Double) { - backgroundScope.launch { - performNetworkRequest(recordNo) - } - } - - private suspend fun performNetworkRequest(recordNo: String) { + private suspend fun requestCheck(recordNo: String) { val requestParam = applyInitFields(PayoutCheckReq()).apply { record_no = recordNo } @@ -569,39 +563,12 @@ class WithdrawManager private constructor() { } - private fun getStartedItemRestCashNum(itemIndex: Int): Double { - if (itemIndex in 0..mItemList.size-1) { - val curItem = mItemList[itemIndex] - if (curItem.hasStarted) { - var hasWithdrawedCash = 0.0 - curItem.subItemList.forEach { subItem-> - if (subItem.withdrawState == STATE_HAS_WITHDRAWED) { - hasWithdrawedCash += subItem.cashTotal - } - } - return curItem.totalCashNum - hasWithdrawedCash - } - } - return 0.0 - } - - /*private fun getStartedItemRestCashCount(): Double { - var allStartedItemRestCashNum = 0.0 - mItemList.forEachIndexed { index, item -> - if (!(TaskManager.instance().newbieFirstWithdrawStatus().getStatusBean().hasClaimReward && index == 0)) { - allStartedItemRestCashNum += getStartedItemRestCashNum(index) - } - } - - return allStartedItemRestCashNum - }*/ - fun getItemProgress(itemIndex: Int): Double { var itemProgress = 0.0 - if (itemIndex in 0..mItemList.size-1) { - val curItem = mItemList[itemIndex] + if (itemIndex in 0..mWithdrawItemList.size-1) { + val curItem = mWithdrawItemList[itemIndex] val userCashTotal = AccountManager.getCash() if (curItem.hasStarted) { return 1.0 @@ -614,13 +581,13 @@ class WithdrawManager private constructor() { } fun setItemStarted(itemIndex: Int) { - if (itemIndex in 0..mItemList.size-1) { - val curItem = mItemList[itemIndex] + if (itemIndex in 0..mWithdrawItemList.size-1) { + val curItem = mWithdrawItemList[itemIndex] if (!curItem.hasStarted) { curItem.hasStarted = true curItem.startMs = System.currentTimeMillis() AccountManager.adjustCash(-1 * curItem.totalCashNum) - saveInfos2Sp(mItemList) + saveInfos2Sp(mWithdrawItemList) notifyItemListChanged() } } @@ -630,7 +597,7 @@ class WithdrawManager private constructor() { } -data class WithdrawItemBean( +data class WithdrawItem( val index: Int, val totalCashNum: Double, var totalProgress: Int = 0, @@ -641,7 +608,7 @@ data class WithdrawItemBean( ) data class WithdrawSubItem( - val index: Int, + val dayIndex: Int, val cashTotal: Double, val startAdProgress: Int = 0, var currentAdProgress: Int = 0,