体现可选择

This commit is contained in:
renhaoting 2025-11-27 15:28:06 +08:00
parent 3b2b78dd95
commit 1b35da0a4e
3 changed files with 84 additions and 31 deletions

View File

@ -8,6 +8,9 @@ import com.ama.core.architecture.appBase.AppViewsActivity
import com.ama.core.architecture.util.ResUtil import com.ama.core.architecture.util.ResUtil
import com.ama.core.architecture.util.setOnClickBatch import com.ama.core.architecture.util.setOnClickBatch
import com.gamedog.vididin.R import com.gamedog.vididin.R
import com.gamedog.vididin.VididinEvents
import com.gamedog.vididin.core.login.login.AccountManager
import com.gamedog.vididin.features.withdraw.widget.WithDrawItemView
import com.gamedog.vididin.main.interfaces.OnTabStyleListener import com.gamedog.vididin.main.interfaces.OnTabStyleListener
import com.gamedog.vididin.router.Router import com.gamedog.vididin.router.Router
import dagger.hilt.android.AndroidEntryPoint import dagger.hilt.android.AndroidEntryPoint
@ -23,37 +26,46 @@ class WithDrawActivity : AppViewsActivity<ViewBinding, UiState, ViewModel>(), On
override val mViewModel: ViewModel by viewModels() override val mViewModel: ViewModel by viewModels()
override fun inflateViewBinding(inflater: LayoutInflater) = ViewBinding.inflate(inflater) override fun inflateViewBinding(inflater: LayoutInflater) = ViewBinding.inflate(inflater)
private val mItemViewList: MutableList<WithDrawItemView> = mutableListOf()
private var mCurSelectedIndex: Int = 0
override fun ViewBinding.initWindowInsets() { override fun ViewBinding.initWindowInsets() {
setImmerseRootView(contentRoot) setImmerseRootView(contentRoot)
} }
override fun ViewBinding.initViews() { override fun ViewBinding.initViews() {
with(binding) { with(binding) {
withdraw01.setNumAndAction(ResUtil.getString(R.string.cash) + " " + 0.1, { withdraw01.setNumAndAction(0, 0.1F,
{ itemIndex->
updateUIItemSelectStates(itemIndex)
})
}) withdraw10.setNumAndAction(1, 10F,
withdraw01.setSelected() { itemIndex->
updateUIItemSelectStates(itemIndex)
})
withdraw10.setNumAndAction(ResUtil.getString(R.string.cash) + " " + 10, { withdraw20.setNumAndAction(2, 20F,
{ itemIndex->
updateUIItemSelectStates(itemIndex)
})
}) withdraw50.setNumAndAction(3, 50F,
{ itemIndex->
updateUIItemSelectStates(itemIndex)
})
withdraw20.setNumAndAction(ResUtil.getString(R.string.cash) + " " + 20, { withdraw100.setNumAndAction(4, 100F,
{ itemIndex->
updateUIItemSelectStates(itemIndex)
})
}) withdraw300.setNumAndAction(5, 300F,
{ itemIndex->
withdraw50.setNumAndAction(ResUtil.getString(R.string.cash) + " " + 50, { updateUIItemSelectStates(itemIndex)
})
})
withdraw100.setNumAndAction(ResUtil.getString(R.string.cash) + " " + 100, {
})
withdraw300.setNumAndAction(ResUtil.getString(R.string.cash) + " " + 300, {
})
withdrawPix2.setIconAndText(R.mipmap.pix2, R.string.pix2, { withdrawPix2.setIconAndText(R.mipmap.pix2, R.string.pix2, {
@ -61,7 +73,7 @@ class WithDrawActivity : AppViewsActivity<ViewBinding, UiState, ViewModel>(), On
updateUIItemSelectStates(0)
setOnClickBatch(tvSacar, withdrawRecord) { setOnClickBatch(tvSacar, withdrawRecord) {
when(this) { when(this) {
tvSacar -> { tvSacar -> {
@ -74,10 +86,31 @@ class WithDrawActivity : AppViewsActivity<ViewBinding, UiState, ViewModel>(), On
} }
} }
mItemViewList.add(withdraw01)
mItemViewList.add(withdraw10)
mItemViewList.add(withdraw20)
mItemViewList.add(withdraw50)
mItemViewList.add(withdraw100)
mItemViewList.add(withdraw300)
updateUICashTotal()
}
private fun updateUIItemSelectStates(itemIndex: Int) {
mCurSelectedIndex = itemIndex
mItemViewList.forEachIndexed { index, view ->
view.setSelectedState(index == mCurSelectedIndex)
}
}
private fun updateUICashTotal() {
binding.tvCashTotal.text = AccountManager.getCash().toString()
} }
override fun ViewBinding.initListeners() { override fun ViewBinding.initListeners() {
//TODO("Not yet implemented") registerEvents({ data->
updateUICashTotal()
}, VididinEvents.Event_Account_Cash_Changed)
} }
override fun ViewBinding.initObservers() { override fun ViewBinding.initObservers() {

View File

@ -14,24 +14,33 @@ class WithDrawItemView @JvmOverloads constructor(
attrs: AttributeSet? = null, attrs: AttributeSet? = null,
defStyleAttr: Int = 0 defStyleAttr: Int = 0
) : LinearLayout(context, attrs, defStyleAttr) { ) : LinearLayout(context, attrs, defStyleAttr) {
private var mItemIndex: Int = 0
private var mIsSelected = false
private var mCashNum: Float = 0F
private var mBinding: ViewBinding private var mBinding: ViewBinding
init { init {
mBinding = ViewBinding.inflate(LayoutInflater.from(context), this, true) mBinding = ViewBinding.inflate(LayoutInflater.from(context), this, true)
mBinding.run {
}
} }
fun setNumAndAction(number: String, clickAction: ()->Unit) { /**
mBinding.tvWithdrawNum.text = number * For withdraw number in top area
*/
fun setNumAndAction(itemIndex: Int, cashNum: Float, clickAction: (Int)->Unit) {
mItemIndex = itemIndex
mCashNum = cashNum
mBinding.tvWithdrawNum.text = cashNum.toString()
mBinding.root.setOnClickListener { mBinding.root.setOnClickListener {
clickAction.invoke() clickAction.invoke(mItemIndex)
} }
} }
/**
* For bank item in bottom area
*/
fun setIconAndText(iconRes: Int, textRes: Int, clickAction: ()->Unit) { fun setIconAndText(iconRes: Int, textRes: Int, clickAction: ()->Unit) {
mBinding.tvWithdrawNum.text = ResUtil.getString(textRes) mBinding.tvWithdrawNum.text = ResUtil.getString(textRes)
mBinding.ivItemIcon.setImageResource(iconRes) mBinding.ivItemIcon.setImageResource(iconRes)
@ -40,8 +49,9 @@ class WithDrawItemView @JvmOverloads constructor(
} }
} }
fun setSelected() { fun setSelectedState(isSelected: Boolean) {
mBinding.root.setBackgroundResource(R.drawable.withdraw_item_bg_selected) mIsSelected = isSelected
mBinding.root.setBackgroundResource(if (mIsSelected) R.drawable.withdraw_item_bg_selected else R.drawable.withdraw_item_bg_unselected)
} }

View File

@ -79,7 +79,17 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textSize="21sp" android:textSize="21sp"
android:textColor="@color/yellow_46" android:textColor="@color/yellow_46"
android:text="@string/cash01" android:text="@string/cash"
android:layout_marginStart="5dp"
/>
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/tv_cash_total"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="21sp"
android:textColor="@color/yellow_46"
android:text="0"
android:layout_marginStart="5dp" android:layout_marginStart="5dp"
/> />
</LinearLayout> </LinearLayout>