withdraw manager 以及ui赋值
This commit is contained in:
parent
f8face95c6
commit
de9f32ae5b
|
|
@ -8,7 +8,6 @@ import androidx.lifecycle.Lifecycle
|
|||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.lifecycle.repeatOnLifecycle
|
||||
import com.ama.core.architecture.appBase.AppViewsEmptyViewModelActivity
|
||||
import com.ama.core.architecture.util.AndroidUtil
|
||||
import com.ama.core.architecture.util.SpUtil
|
||||
import com.ama.core.architecture.util.setOnClickBatch
|
||||
import com.gamedog.vididin.VidiConst
|
||||
|
|
@ -101,8 +100,7 @@ class WithDrawActivity : AppViewsEmptyViewModelActivity<ViewBinding>() {
|
|||
when(this) {
|
||||
tvSacar -> {
|
||||
if (mItemViewList.get(mCurSelectedIndex).getCashNum() > 1F) {
|
||||
gotoWithdrawSubActivity()
|
||||
|
||||
gotoWithdrawSubActivity(mCurSelectedIndex)
|
||||
} else {
|
||||
val hasBindBank = AccountManager.hasValidBankInfo()
|
||||
val cashNum = mItemViewList.get(mCurSelectedIndex).getCashNum()
|
||||
|
|
@ -316,8 +314,8 @@ class WithDrawActivity : AppViewsEmptyViewModelActivity<ViewBinding>() {
|
|||
WithdrawFailDialog(this@WithDrawActivity, errorHintRes).show()
|
||||
}
|
||||
|
||||
private fun gotoWithdrawSubActivity() {
|
||||
Router.WithdrawSub.startActivity(this, 111)
|
||||
private fun gotoWithdrawSubActivity(selectedIndex: Int) {
|
||||
Router.WithdrawSub.startActivity(this, selectedIndex - 1)
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,15 @@ import android.content.Intent
|
|||
import android.view.LayoutInflater
|
||||
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.manager.WithdrawManager
|
||||
import com.gamedog.vididin.manager.WithdrawSubItem
|
||||
import com.gamedog.vididin.router.Router
|
||||
import com.vididin.real.money.game.R
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import com.vididin.real.money.game.databinding.ActivityWithdrawSubBinding as ViewBinding
|
||||
|
||||
|
|
@ -13,6 +21,8 @@ import com.vididin.real.money.game.databinding.ActivityWithdrawSubBinding as Vie
|
|||
|
||||
@AndroidEntryPoint
|
||||
class WithDrawSubActivity : AppViewsEmptyViewModelActivity<ViewBinding>() {
|
||||
private var mSelectedSubIndex: Int = 0
|
||||
private lateinit var mSubItemList: List<WithdrawSubItem>
|
||||
private var mType: Int = 0
|
||||
private val mAdapter: WithdrawSubAdapter by lazy { WithdrawSubAdapter() }
|
||||
|
||||
|
|
@ -29,15 +39,41 @@ class WithDrawSubActivity : AppViewsEmptyViewModelActivity<ViewBinding>() {
|
|||
recyclerView.layoutManager = LinearLayoutManager(this@WithDrawSubActivity, LinearLayoutManager.HORIZONTAL, false)
|
||||
recyclerView.adapter = mAdapter
|
||||
recyclerView.addItemDecoration(CommonItemDecoration.create(18, 0, false))
|
||||
|
||||
|
||||
setOnClickBatch(flAction) {
|
||||
when(this) {
|
||||
flAction -> {
|
||||
gotoWatchAd()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun gotoWatchAd() {
|
||||
val extraData = NotifyMan.NotifyData<Float>(1111111F)
|
||||
Router.WatchAd.startActivity(this, VidiConst.WATCH_AD_FOR_WITHDRAW, AndroidUtil.object2Json(extraData))
|
||||
}
|
||||
|
||||
override fun ViewBinding.initListeners() {
|
||||
val dataList = mutableListOf<WithdrawSubItem>()
|
||||
dataList.add(WithdrawSubItem(0, 1F, false))
|
||||
dataList.add(WithdrawSubItem(1, 1F, true))
|
||||
dataList.add(WithdrawSubItem(2, 1F, false))
|
||||
dataList.add(WithdrawSubItem(3, 1F, false))
|
||||
mAdapter.submitList(dataList)
|
||||
mSubItemList = WithdrawManager.instance().getSubItemList(mType)
|
||||
mAdapter.submitList(mSubItemList)
|
||||
|
||||
mSubItemList.forEach {
|
||||
if (it.isSelected) {
|
||||
mSelectedSubIndex = it.index
|
||||
return@forEach
|
||||
}
|
||||
}
|
||||
updateUI()
|
||||
}
|
||||
|
||||
private fun updateUI() {
|
||||
with(binding) {
|
||||
progressBar.enableTouch(false)
|
||||
progressBar.setBarColor(forColor = R.color.green_ce)
|
||||
progressBar.setProgress(mSubItemList[mSelectedSubIndex].currentProgress)
|
||||
}
|
||||
}
|
||||
|
||||
override fun ViewBinding.initObservers() {
|
||||
|
|
@ -54,8 +90,3 @@ class WithDrawSubActivity : AppViewsEmptyViewModelActivity<ViewBinding>() {
|
|||
}
|
||||
}
|
||||
|
||||
data class WithdrawSubItem(
|
||||
val index: Int,
|
||||
val cashNum: Float,
|
||||
var isSelected: Boolean = false,
|
||||
)
|
||||
|
|
@ -8,6 +8,7 @@ import androidx.recyclerview.widget.DiffUtil
|
|||
import androidx.recyclerview.widget.ListAdapter
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.ama.core.architecture.util.ResUtil
|
||||
import com.gamedog.vididin.manager.WithdrawSubItem
|
||||
import com.vididin.real.money.game.R
|
||||
import com.vididin.real.money.game.databinding.LayoutItemWithdrawSubBinding as ViewBinding
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,86 @@
|
|||
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,
|
||||
)
|
||||
|
|
@ -110,6 +110,7 @@
|
|||
/>
|
||||
|
||||
<com.ama.core.architecture.widget.CustomProgressBar
|
||||
android:id="@+id/progress_bar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="12dp"
|
||||
android:layout_marginHorizontal="20dp"
|
||||
|
|
|
|||
|
|
@ -99,5 +99,6 @@
|
|||
<color name="red_e0">#ffffe9e0</color>
|
||||
<color name="red_7f">#FFFF7F00</color>
|
||||
<color name="yellow_e0">#FFFEE000</color>
|
||||
<color name="green_ce">#FF29CE00</color>
|
||||
|
||||
</resources>
|
||||
|
|
@ -154,6 +154,10 @@ class AndroidUtil private constructor() {
|
|||
return ""
|
||||
}
|
||||
|
||||
fun randomInt(startNum: Int, endNum: Int): Int {
|
||||
return (startNum..endNum).random()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -36,6 +36,7 @@ class SpUtil private constructor(spFileName: String) {
|
|||
|
||||
|
||||
const val KEY_WITHDRAW_HISTORY_LIST = "KEY_WITHDRAW_HISTORY_LIST"
|
||||
const val KEY_WITHDRAW_ITEM_LIST = "KEY_WITHDRAW_ITEM_LIST"
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ class CustomProgressBar(context: Context, attrs: AttributeSet) : View(context, a
|
|||
|
||||
private var mBgColor = ResUtil.getColor(R.color.gray_d3)
|
||||
private var mForColor = ResUtil.getColor(R.color.green_09)
|
||||
private var mEnableTouch: Boolean = false
|
||||
|
||||
|
||||
|
||||
|
|
@ -53,6 +54,10 @@ class CustomProgressBar(context: Context, attrs: AttributeSet) : View(context, a
|
|||
invalidate()
|
||||
}
|
||||
|
||||
fun enableTouch(enableTouch: Boolean) {
|
||||
mEnableTouch = enableTouch
|
||||
}
|
||||
|
||||
fun setBarColor(bgColor: Int=R.color.gray_d3, forColor: Int=R.color.green_09) {
|
||||
mBgColor = ResUtil.getColor(bgColor)
|
||||
mForColor = ResUtil.getColor(forColor)
|
||||
|
|
@ -67,22 +72,25 @@ class CustomProgressBar(context: Context, attrs: AttributeSet) : View(context, a
|
|||
private var onProgressChangeListener: OnProgressChangeListener? = null
|
||||
|
||||
override fun onTouchEvent(event: MotionEvent): Boolean {
|
||||
when (event.action) {
|
||||
MotionEvent.ACTION_DOWN -> {
|
||||
parent.requestDisallowInterceptTouchEvent(true)
|
||||
updateProgressFromTouch(event.x)
|
||||
return true
|
||||
}
|
||||
MotionEvent.ACTION_MOVE -> {
|
||||
updateProgressFromTouch(event.x)
|
||||
return true
|
||||
}
|
||||
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
|
||||
parent.requestDisallowInterceptTouchEvent(false)
|
||||
updateProgressFromTouch(event.x, true)
|
||||
return true
|
||||
if (mEnableTouch) {
|
||||
when (event.action) {
|
||||
MotionEvent.ACTION_DOWN -> {
|
||||
parent.requestDisallowInterceptTouchEvent(true)
|
||||
updateProgressFromTouch(event.x)
|
||||
return true
|
||||
}
|
||||
MotionEvent.ACTION_MOVE -> {
|
||||
updateProgressFromTouch(event.x)
|
||||
return true
|
||||
}
|
||||
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
|
||||
parent.requestDisallowInterceptTouchEvent(false)
|
||||
updateProgressFromTouch(event.x, true)
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return super.onTouchEvent(event)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue