进度事件通知及更新

This commit is contained in:
renhaoting 2025-12-15 10:47:58 +08:00
parent ae45b72717
commit 8f2786b5b9
4 changed files with 96 additions and 26 deletions

View File

@ -42,4 +42,11 @@ object VididinEvents {
const val EVENT_JUMP_2_VIDEO = 901
const val EVENT_JUMP_2_SIGN= 902
// Withdraw related
const val EVENT_WITHDRAW_SUB_ITEM_PROGRESS_UPDATED = 500
const val EVENT_WITHDRAW_SELECTED_SUB_ITEM_CHANGED = 501
}

View File

@ -7,9 +7,10 @@ import androidx.recyclerview.widget.LinearLayoutManager
import com.ama.core.architecture.appBase.AppViewsEmptyViewModelActivity
import com.ama.core.architecture.util.AndroidUtil
import com.ama.core.architecture.util.CommonItemDecoration
import com.ama.core.architecture.util.eventbus.NotifyMan
import com.ama.core.architecture.util.setOnClickBatch
import com.gamedog.vididin.VidiConst
import com.gamedog.vididin.VididinEvents
import com.gamedog.vididin.beans.WatchAdNotifyBean
import com.gamedog.vididin.manager.WithdrawItemBean
import com.gamedog.vididin.manager.WithdrawManager
import com.gamedog.vididin.router.Router
@ -21,7 +22,6 @@ import com.vididin.real.money.game.databinding.ActivityWithdrawSubBinding as Vie
@AndroidEntryPoint
class WithDrawSubActivity : AppViewsEmptyViewModelActivity<ViewBinding>() {
private var mSelectedSubIndex: Int = 0
private lateinit var mCurItem: WithdrawItemBean
private var mType: Int = 0
private val mAdapter: WithdrawSubAdapter by lazy { WithdrawSubAdapter() }
@ -51,30 +51,53 @@ class WithDrawSubActivity : AppViewsEmptyViewModelActivity<ViewBinding>() {
}
private fun gotoWatchAd() {
val extraData = NotifyMan.NotifyData<WithdrawItemBean>(mCurItem)
Router.WatchAd.startActivity(this, VidiConst.WATCH_AD_FOR_WITHDRAW_BIG, AndroidUtil.object2Json(extraData))
Router.WatchAd.startActivity(this, VidiConst.WATCH_AD_FOR_WITHDRAW_BIG, AndroidUtil.object2Json(mCurItem))
}
override fun ViewBinding.initListeners() {
mCurItem = WithdrawManager.instance().getItem(mType)
mAdapter.submitList(mCurItem.subItemList)
registerEvents({ data->
when (data?.mEventType) {
VididinEvents.EVENT_AD_WATCHED_FOR_WITHDRAW_BIG -> {
handleAdWatched(data.mData as WatchAdNotifyBean<WithdrawItemBean>)
}
mCurItem.subItemList.forEach {
if (it.isSelected) {
mSelectedSubIndex = it.index
return@forEach
VididinEvents.EVENT_WITHDRAW_SUB_ITEM_PROGRESS_UPDATED -> {
if ((data.mData as Int) == mCurItem.selectedSubIndex) {
progressBar.setProgress(mCurItem.subItemList[mCurItem.selectedSubIndex].currentProgress)
}
}
VididinEvents.EVENT_WITHDRAW_SELECTED_SUB_ITEM_CHANGED -> {
updateUI()
}
}
}
updateUI()
}, VididinEvents.EVENT_AD_WATCHED_FOR_WITHDRAW_BIG,
VididinEvents.EVENT_WITHDRAW_SUB_ITEM_PROGRESS_UPDATED,
VididinEvents.EVENT_WITHDRAW_SELECTED_SUB_ITEM_CHANGED)
recyclerView.scrollToPosition(mSelectedSubIndex)
mCurItem = WithdrawManager.instance().getItem(mType)
updateUI()
}
private fun handleAdWatched(adNotifyBean: WatchAdNotifyBean<WithdrawItemBean>) {
val withdrawItemBean = adNotifyBean.extraData
if (WithdrawManager.instance().addAdEarnForSubBean(withdrawItemBean.index,
withdrawItemBean.selectedSubIndex, adNotifyBean.earnMoneyNum)) {
updateUI()
}
}
private fun updateUI() {
with(binding) {
mAdapter.mSelectedSubIndex = mCurItem.selectedSubIndex
mAdapter.submitList(mCurItem.subItemList)
recyclerView.scrollToPosition(mCurItem.selectedSubIndex)
tvCashTotal.text = mCurItem.totalCashNum.toString()
progressBar.enableTouch(false)
progressBar.setBarColor(forColor = R.color.green_ce)
progressBar.setProgress(mCurItem.subItemList[mSelectedSubIndex].currentProgress)
progressBar.setProgress(mCurItem.subItemList[mCurItem.selectedSubIndex].currentProgress)
}
}

View File

@ -14,9 +14,11 @@ import com.vididin.real.money.game.databinding.LayoutItemWithdrawSubBinding as V
class WithdrawSubAdapter() : ListAdapter<WithdrawSubItem, WithdrawSubAdapter.ViewHolder>(DiffCallback()) {
var mSelectedSubIndex: Int = 0
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val binding = ViewBinding.inflate(LayoutInflater.from(parent.context), parent, false)
return ViewHolder(binding)
return ViewHolder(binding,)
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
@ -29,7 +31,7 @@ class WithdrawSubAdapter() : ListAdapter<WithdrawSubItem, WithdrawSubAdapter.Vie
with(binding) {
tvTitle.text = buildString {
append(ResUtil.getString(R.string.cash))
append(item.cashNum)
append(item.cashTotal)
}
tvDay.text = buildString {
append(ResUtil.getString(R.string.day))
@ -37,7 +39,7 @@ class WithdrawSubAdapter() : ListAdapter<WithdrawSubItem, WithdrawSubAdapter.Vie
append(item.index + 1)
}
if (item.isSelected) {
if (item.index == mSelectedSubIndex) {
root.setBackgroundResource(R.drawable.bg_withdraw_sub_selected)
root.alpha = 1F
ivLefttopChecked.isVisible = true

View File

@ -2,6 +2,8 @@ package com.gamedog.vididin.manager
import com.ama.core.architecture.util.AndroidUtil
import com.ama.core.architecture.util.SpUtil
import com.ama.core.architecture.util.eventbus.NotifyMan
import com.gamedog.vididin.VididinEvents
class WithdrawManager private constructor() {
@ -11,7 +13,7 @@ class WithdrawManager private constructor() {
val itemList = SpUtil.instance().getList<WithdrawItemBean>(SpUtil.KEY_WITHDRAW_ITEM_LIST).toMutableList()
if (itemList.isEmpty()) {
itemList.addAll(generateItemList())
save2Infos(itemList)
saveInfos2Sp(itemList)
}
itemList
}
@ -46,12 +48,13 @@ class WithdrawManager private constructor() {
val subItemCount: Int = (totalCashInItem/EACH_SUB_ITEM_CASH_NUM).toInt()
for (i in 0..subItemCount-1) {
subItemList.add(WithdrawSubItem(i, EACH_SUB_ITEM_CASH_NUM, i==0, AndroidUtil.randomInt(50, 70)))
val initProgress = AndroidUtil.randomInt(50, 70)
subItemList.add(WithdrawSubItem(i, EACH_SUB_ITEM_CASH_NUM, initProgress, initProgress, 0F))
}
return subItemList
}
private fun save2Infos(itemList: MutableList<WithdrawItemBean>) {
private fun saveInfos2Sp(itemList: MutableList<WithdrawItemBean>) {
SpUtil.instance().putList(SpUtil.KEY_WITHDRAW_ITEM_LIST, itemList)
}
@ -63,8 +66,41 @@ class WithdrawManager private constructor() {
return mItemList[itemIndex]
}
fun updateProgress(itemIndex: Int, updatedItem: WithdrawItemBean) {
// TODO -
fun addAdEarnForSubBean(itemIndex: Int, selectedSubIndex: Int, earnMoneyNum: Float) : Boolean {
if (itemIndex >= 0 && itemIndex < mItemList.size) {
try {
val subBean = mItemList[itemIndex].subItemList[selectedSubIndex]
subBean.hasEarnMoneyByAd += earnMoneyNum * 5 // dollar 2 bariz
calculateSubBeanProgress(subBean) //传入 itembean 更新 selectedIndex为下一个
saveInfos2Sp(mItemList)
notifyProgressUpdated(subBean)
return true
} catch (e: Exception) {
e.printStackTrace()
}
}
return false
}
private fun notifyProgressUpdated(subBean: WithdrawSubItem) {
NotifyMan.instance().sendEvent(VididinEvents.EVENT_WITHDRAW_SUB_ITEM_PROGRESS_UPDATED,
NotifyMan.NotifyData(subBean.index))
}
private fun notifySelectedSubBeanChanged(subBean: WithdrawSubItem) {
NotifyMan.instance().sendEvent(VididinEvents.EVENT_WITHDRAW_SELECTED_SUB_ITEM_CHANGED, NotifyMan.NotifyData(subBean.index))
}
private fun calculateSubBeanProgress(subBean: WithdrawSubItem) {
val needEarnProgress = 100 - subBean.startProgress
if (subBean.hasEarnMoneyByAd >= subBean.cashTotal) {
subBean.currentProgress = 100
} else {
val newProgress = subBean.startProgress + (needEarnProgress * (subBean.hasEarnMoneyByAd / subBean.cashTotal)).toInt()
subBean.currentProgress = if (newProgress >= 100) 99 else newProgress
}
}
}
@ -74,12 +110,14 @@ data class WithdrawItemBean(
val index: Int,
val totalCashNum: Float,
var totalProgress: Int = 0,
val subItemList: List<WithdrawSubItem> = emptyList()
val subItemList: List<WithdrawSubItem> = emptyList(),
var selectedSubIndex: Int = 0,
)
data class WithdrawSubItem(
val index: Int,
val cashNum: Float,
var isSelected: Boolean = false,
val currentProgress: Int = 0,
val cashTotal: Float,
val startProgress: Int = 0,
var currentProgress: Int = 0,
var hasEarnMoneyByAd: Float = 0F,
)