2025-12-12 07:27:30 +00:00
|
|
|
package com.gamedog.vididin.manager
|
|
|
|
|
|
|
|
|
|
import com.ama.core.architecture.util.AndroidUtil
|
|
|
|
|
import com.ama.core.architecture.util.SpUtil
|
2025-12-15 02:47:58 +00:00
|
|
|
import com.ama.core.architecture.util.eventbus.NotifyMan
|
|
|
|
|
import com.gamedog.vididin.VididinEvents
|
2025-12-12 07:27:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class WithdrawManager private constructor() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private val mItemList: MutableList<WithdrawItemBean> by lazy {
|
|
|
|
|
val itemList = SpUtil.instance().getList<WithdrawItemBean>(SpUtil.KEY_WITHDRAW_ITEM_LIST).toMutableList()
|
|
|
|
|
if (itemList.isEmpty()) {
|
|
|
|
|
itemList.addAll(generateItemList())
|
2025-12-15 02:47:58 +00:00
|
|
|
saveInfos2Sp(itemList)
|
2025-12-12 07:27:30 +00:00
|
|
|
}
|
|
|
|
|
itemList
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
companion object {
|
|
|
|
|
const val EACH_SUB_ITEM_CASH_NUM: Float = 1F
|
|
|
|
|
|
|
|
|
|
@Volatile
|
|
|
|
|
private var instance: WithdrawManager? = null
|
|
|
|
|
fun instance(): WithdrawManager {
|
|
|
|
|
return instance ?: synchronized(this) {
|
|
|
|
|
instance ?: WithdrawManager().also {
|
|
|
|
|
instance = it
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun generateItemList(): MutableList<WithdrawItemBean> {
|
|
|
|
|
val itemList = mutableListOf<WithdrawItemBean>()
|
|
|
|
|
itemList.add(WithdrawItemBean(0, 10F, AndroidUtil.randomInt(50, 70), generateSubItemList(10F)))
|
|
|
|
|
itemList.add(WithdrawItemBean(1, 20F, AndroidUtil.randomInt(50, 70), generateSubItemList(20F)))
|
|
|
|
|
itemList.add(WithdrawItemBean(2, 50F, AndroidUtil.randomInt(50, 70), generateSubItemList(50F)))
|
|
|
|
|
itemList.add(WithdrawItemBean(3, 100F, AndroidUtil.randomInt(50, 70), generateSubItemList(100F)))
|
|
|
|
|
itemList.add(WithdrawItemBean(4, 300F, AndroidUtil.randomInt(50, 70), generateSubItemList(300F)))
|
|
|
|
|
return itemList
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun generateSubItemList(totalCashInItem: Float): List<WithdrawSubItem> {
|
|
|
|
|
val subItemList = mutableListOf<WithdrawSubItem>()
|
|
|
|
|
val subItemCount: Int = (totalCashInItem/EACH_SUB_ITEM_CASH_NUM).toInt()
|
|
|
|
|
|
|
|
|
|
for (i in 0..subItemCount-1) {
|
2025-12-15 02:47:58 +00:00
|
|
|
val initProgress = AndroidUtil.randomInt(50, 70)
|
|
|
|
|
subItemList.add(WithdrawSubItem(i, EACH_SUB_ITEM_CASH_NUM, initProgress, initProgress, 0F))
|
2025-12-12 07:27:30 +00:00
|
|
|
}
|
|
|
|
|
return subItemList
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-15 02:47:58 +00:00
|
|
|
private fun saveInfos2Sp(itemList: MutableList<WithdrawItemBean>) {
|
2025-12-12 07:27:30 +00:00
|
|
|
SpUtil.instance().putList(SpUtil.KEY_WITHDRAW_ITEM_LIST, itemList)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun getItemList(): List<WithdrawItemBean> {
|
|
|
|
|
return mItemList
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-12 09:23:21 +00:00
|
|
|
fun getItem(itemIndex: Int): WithdrawItemBean {
|
|
|
|
|
return mItemList[itemIndex]
|
2025-12-12 07:27:30 +00:00
|
|
|
}
|
|
|
|
|
|
2025-12-15 02:47:58 +00:00
|
|
|
|
|
|
|
|
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
|
|
|
|
|
}
|
2025-12-12 07:27:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data class WithdrawItemBean(
|
|
|
|
|
val index: Int,
|
|
|
|
|
val totalCashNum: Float,
|
|
|
|
|
var totalProgress: Int = 0,
|
2025-12-15 02:47:58 +00:00
|
|
|
val subItemList: List<WithdrawSubItem> = emptyList(),
|
|
|
|
|
var selectedSubIndex: Int = 0,
|
2025-12-12 07:27:30 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
data class WithdrawSubItem(
|
|
|
|
|
val index: Int,
|
2025-12-15 02:47:58 +00:00
|
|
|
val cashTotal: Float,
|
|
|
|
|
val startProgress: Int = 0,
|
|
|
|
|
var currentProgress: Int = 0,
|
|
|
|
|
var hasEarnMoneyByAd: Float = 0F,
|
2025-12-12 07:27:30 +00:00
|
|
|
)
|