取现逻辑调整
This commit is contained in:
parent
c2bb7ec0e7
commit
38b8a8d23c
|
|
@ -128,7 +128,7 @@ class WithDrawActivity : AppViewsEmptyViewModelActivity<ViewBinding>() {
|
|||
}
|
||||
|
||||
private fun updateUICashTotal() {
|
||||
binding.tvCashTotal.text = AccountManager.getCash().toString()
|
||||
binding.tvCashTotal.text = String.format("%.2f", AccountManager.getCash())
|
||||
binding.tvAllCashHasWithdrawed.text = buildString {
|
||||
append(ResUtil.getString(R.string.cash))
|
||||
append(" ")
|
||||
|
|
@ -156,7 +156,7 @@ class WithDrawActivity : AppViewsEmptyViewModelActivity<ViewBinding>() {
|
|||
showTransactionResultDialog(record)
|
||||
}
|
||||
updateUICashTotal()
|
||||
mItemViewList[record.itemIndex].updateProgressUI()
|
||||
mItemViewList[record.itemIndex].updateProgressAndButUI()
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
|
@ -286,7 +286,7 @@ class WithDrawActivity : AppViewsEmptyViewModelActivity<ViewBinding>() {
|
|||
}
|
||||
|
||||
private fun gotoWithdrawSubActivity(selectedIndex: Int) {
|
||||
Router.WithdrawSub.startActivity(this, selectedIndex - 1)
|
||||
Router.WithdrawSub.startActivity(this, selectedIndex)
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -31,12 +31,13 @@ class WithDrawItemView @JvmOverloads constructor(
|
|||
fun setNumAndAction(itemIndex: Int, cashNum: Float, clickAction: (Int)->Unit) {
|
||||
mItemIndex = itemIndex
|
||||
mCashNum = cashNum
|
||||
mBinding.tvWithdrawNum.text = ResUtil.getString(R.string.cash) + " " + cashNum.toString()
|
||||
mBinding.tvWithdrawNum.text = ResUtil.getString(R.string.cash) + " " +
|
||||
if (cashNum.toString().endsWith(".0")) cashNum.toString().substring(0, cashNum.toString().indexOf(".0")) else cashNum.toString()
|
||||
mBinding.tvSacar.setOnClickListener {
|
||||
clickAction.invoke(mItemIndex)
|
||||
}
|
||||
|
||||
updateProgressUI()
|
||||
updateProgressAndButUI()
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -44,12 +45,17 @@ class WithDrawItemView @JvmOverloads constructor(
|
|||
return mCashNum
|
||||
}
|
||||
|
||||
fun updateProgressUI() {
|
||||
val progressIntNum: Float = WithdrawManager.instance().getHasWithdrawSuccessCashCount(mItemIndex)
|
||||
fun updateProgressAndButUI() {
|
||||
var itemProgress = WithdrawManager.instance().getItemProgress(mItemIndex) * 100
|
||||
//var itemState = WithdrawManager.instance().getItemState(mItemIndex)
|
||||
|
||||
with(mBinding) {
|
||||
progressBar.setProgress(progressIntNum.toInt())
|
||||
tvProgress.text = String.format("%.2f", progressIntNum).toString() + ResUtil.getString(R.string.percent)
|
||||
progressBar.setProgress(itemProgress.toInt())
|
||||
tvProgress.text = String.format("%.2f", itemProgress) + ResUtil.getString(R.string.percent)
|
||||
|
||||
var canClickable: Boolean = itemProgress >= 100F
|
||||
tvSacar.isClickable = canClickable
|
||||
tvSacar.alpha = if (canClickable) 1F else 0.5F
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -217,7 +217,7 @@ class TasksFragment : AppViewsFragment<ViewBinding, UiState, ViewModel>(), OnTab
|
|||
binding?.tvCashTotal?.text = buildString {
|
||||
append(ResUtil.getString(R.string.cash))
|
||||
append(" ")
|
||||
append(AccountManager.getCash())
|
||||
append(String.format("%.2f", AccountManager.getCash()))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -47,6 +47,13 @@ class WithdrawManager private constructor() {
|
|||
companion object {
|
||||
const val EACH_SUB_ITEM_CASH_NUM: Float = 1F
|
||||
|
||||
// subBean 状态
|
||||
const val ITEM_STATE_CANNOT_START: Int = 0
|
||||
const val ITEM_STATE_CAN_START: Int = 1
|
||||
const val ITEM_STATE_STARTED: Int = 2
|
||||
|
||||
|
||||
|
||||
// subBean 状态
|
||||
const val STATE_NEED_WATCH_AD: Int = 0
|
||||
const val STATE_COULD_WITHDRAW: Int = 1
|
||||
|
|
@ -83,11 +90,12 @@ class WithdrawManager private constructor() {
|
|||
|
||||
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)))
|
||||
itemList.add(WithdrawItemBean(0, 0.1F, isBigWithDraw = false))
|
||||
itemList.add(WithdrawItemBean(1, 10F, AndroidUtil.randomInt(50, 70), generateSubItemList(10F)))
|
||||
itemList.add(WithdrawItemBean(2, 20F, AndroidUtil.randomInt(50, 70), generateSubItemList(20F)))
|
||||
itemList.add(WithdrawItemBean(3, 50F, AndroidUtil.randomInt(50, 70), generateSubItemList(50F)))
|
||||
itemList.add(WithdrawItemBean(4, 100F, AndroidUtil.randomInt(50, 70), generateSubItemList(100F)))
|
||||
itemList.add(WithdrawItemBean(5, 300F, AndroidUtil.randomInt(50, 70), generateSubItemList(300F)))
|
||||
return itemList
|
||||
}
|
||||
|
||||
|
|
@ -399,6 +407,71 @@ class WithdrawManager private constructor() {
|
|||
return failTextRes
|
||||
}
|
||||
|
||||
private fun getStartedItemRestCashNum(itemIndex: Int): Float {
|
||||
if (itemIndex in 0..mItemList.size-1) {
|
||||
val curItem = mItemList[itemIndex]
|
||||
if (curItem.hasStarted) {
|
||||
var hasWithdrawedCash = 0F
|
||||
curItem.subItemList.forEach { subItem->
|
||||
if (subItem.withdrawState == STATE_HAS_WITHDRAWED) {
|
||||
hasWithdrawedCash += subItem.cashTotal
|
||||
}
|
||||
}
|
||||
return curItem.totalCashNum - hasWithdrawedCash
|
||||
}
|
||||
}
|
||||
return 0F
|
||||
}
|
||||
|
||||
private fun getStartedItemRestCashCount(): Float {
|
||||
var allStartedItemRestCashNum = 0F
|
||||
mItemList.forEachIndexed { index, item ->
|
||||
allStartedItemRestCashNum += getStartedItemRestCashNum(index)
|
||||
}
|
||||
|
||||
return allStartedItemRestCashNum
|
||||
}
|
||||
|
||||
fun getItemState(itemIndex: Int): Int {
|
||||
var returnState = ITEM_STATE_CANNOT_START
|
||||
|
||||
AccountManager.getAccount()?.let {
|
||||
if (itemIndex in 0..mItemList.size-1) {
|
||||
val curItem = mItemList[itemIndex]
|
||||
val userCashTotal = it.cashCount
|
||||
val allStartedItemRestCashNum = getStartedItemRestCashCount()
|
||||
|
||||
if (curItem.hasStarted) {
|
||||
returnState = ITEM_STATE_STARTED
|
||||
} else if ((userCashTotal - allStartedItemRestCashNum) >= curItem.totalCashNum) {
|
||||
returnState = ITEM_STATE_CAN_START
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return returnState
|
||||
}
|
||||
|
||||
fun getItemProgress(itemIndex: Int): Float {
|
||||
var itemProgress = 0F
|
||||
|
||||
AccountManager.getAccount()?.let {
|
||||
if (itemIndex in 0..mItemList.size-1) {
|
||||
val curItem = mItemList[itemIndex]
|
||||
val userCashTotal = it.cashCount
|
||||
val restAvailableCashNum = userCashTotal - getStartedItemRestCashCount()
|
||||
|
||||
if (curItem.hasStarted || restAvailableCashNum >= curItem.totalCashNum) {
|
||||
itemProgress = 1F
|
||||
} else {
|
||||
itemProgress = restAvailableCashNum / curItem.totalCashNum
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return itemProgress
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -409,6 +482,8 @@ data class WithdrawItemBean(
|
|||
var totalProgress: Int = 0,
|
||||
val subItemList: List<WithdrawSubItem> = emptyList(),
|
||||
var startMs: Long = 0L,
|
||||
var hasStarted: Boolean = false,
|
||||
var isBigWithDraw: Boolean = true
|
||||
)
|
||||
|
||||
data class WithdrawSubItem(
|
||||
|
|
|
|||
|
|
@ -101,6 +101,7 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="21sp"
|
||||
android:textStyle="bold"
|
||||
android:textColor="@color/yellow_46"
|
||||
android:text="0"
|
||||
android:layout_marginStart="5dp"
|
||||
|
|
|
|||
|
|
@ -28,8 +28,6 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_centerInParent="true"
|
||||
android:layout_toEndOf="@id/ll_left_root"
|
||||
android:layout_toStartOf="@+id/ll_right_root"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="vertical">
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue