86 lines
2.7 KiB
Kotlin
86 lines
2.7 KiB
Kotlin
package com.gamedog.vididin.manager
|
|
|
|
import com.ama.core.architecture.util.AndroidUtil
|
|
import com.ama.core.architecture.util.SpUtil
|
|
|
|
|
|
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())
|
|
save2Infos(itemList)
|
|
}
|
|
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) {
|
|
subItemList.add(WithdrawSubItem(i, EACH_SUB_ITEM_CASH_NUM, i==0, AndroidUtil.randomInt(50, 70)))
|
|
}
|
|
return subItemList
|
|
}
|
|
|
|
private fun save2Infos(itemList: MutableList<WithdrawItemBean>) {
|
|
SpUtil.instance().putList(SpUtil.KEY_WITHDRAW_ITEM_LIST, itemList)
|
|
}
|
|
|
|
fun getItemList(): List<WithdrawItemBean> {
|
|
return mItemList
|
|
}
|
|
|
|
fun getSubItemList(itemIndex: Int): List<WithdrawSubItem> {
|
|
return mItemList[itemIndex].subItemList
|
|
}
|
|
|
|
|
|
fun updateProgress(itemIndex: Int, updatedItem: WithdrawItemBean) {
|
|
// TODO -
|
|
}
|
|
|
|
}
|
|
|
|
|
|
data class WithdrawItemBean(
|
|
val index: Int,
|
|
val totalCashNum: Float,
|
|
var totalProgress: Int = 0,
|
|
val subItemList: List<WithdrawSubItem> = emptyList()
|
|
)
|
|
|
|
data class WithdrawSubItem(
|
|
val index: Int,
|
|
val cashNum: Float,
|
|
var isSelected: Boolean = false,
|
|
val currentProgress: Int = 0,
|
|
) |