修改 selectingIndex 逻辑
This commit is contained in:
parent
f889dc5072
commit
1e73375a16
|
|
@ -7,6 +7,7 @@ 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.DateUtil
|
||||
import com.ama.core.architecture.util.ResUtil
|
||||
import com.ama.core.architecture.util.setOnClickBatch
|
||||
import com.gamedog.vididin.VidiConst
|
||||
|
|
@ -25,8 +26,11 @@ import com.vididin.real.money.game.databinding.ActivityWithdrawSubBinding as Vie
|
|||
@AndroidEntryPoint
|
||||
class WithDrawSubActivity : AppViewsEmptyViewModelActivity<ViewBinding>() {
|
||||
private lateinit var mCurItem: WithdrawItemBean
|
||||
private var mSelectingIndex: Int = 0
|
||||
private var mType: Int = 0
|
||||
private val mAdapter: WithdrawSubAdapter by lazy { WithdrawSubAdapter() }
|
||||
private val mAdapter: WithdrawSubAdapter by lazy { WithdrawSubAdapter( { itemIndex ->
|
||||
handleSubItemClicked(itemIndex)
|
||||
}) }
|
||||
|
||||
|
||||
override fun inflateViewBinding(inflater: LayoutInflater) = ViewBinding.inflate(inflater)
|
||||
|
|
@ -46,7 +50,7 @@ class WithDrawSubActivity : AppViewsEmptyViewModelActivity<ViewBinding>() {
|
|||
setOnClickBatch(flAction) {
|
||||
when(this) {
|
||||
flAction -> {
|
||||
when (mCurItem.subItemList[mCurItem.selectedSubIndex].withdrawState) {
|
||||
when (mCurItem.subItemList[mSelectingIndex].withdrawState) {
|
||||
0 -> {
|
||||
gotoWatchAd()
|
||||
}
|
||||
|
|
@ -60,6 +64,14 @@ class WithDrawSubActivity : AppViewsEmptyViewModelActivity<ViewBinding>() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun handleSubItemClicked(itemIndex: Int) {
|
||||
val mMaxDayIndex = DateUtil.getDaysPassed(mCurItem.startMs)
|
||||
if (itemIndex >= 0 && itemIndex <= mMaxDayIndex) {
|
||||
mSelectingIndex = itemIndex
|
||||
updateUI()
|
||||
}
|
||||
}
|
||||
|
||||
private fun gotoWatchAd() {
|
||||
Router.WatchAd.startActivity(this, VidiConst.WATCH_AD_FOR_WITHDRAW_BIG, AndroidUtil.object2Json(mCurItem))
|
||||
}
|
||||
|
|
@ -72,7 +84,7 @@ class WithDrawSubActivity : AppViewsEmptyViewModelActivity<ViewBinding>() {
|
|||
}
|
||||
|
||||
VididinEvents.EVENT_WITHDRAW_SUB_ITEM_PROGRESS_UPDATED -> {
|
||||
if ((data.mData as Int) == mCurItem.selectedSubIndex) {
|
||||
if ((data.mData as Int) == mSelectingIndex) {
|
||||
updateProgressUI()
|
||||
}
|
||||
}
|
||||
|
|
@ -87,33 +99,34 @@ class WithDrawSubActivity : AppViewsEmptyViewModelActivity<ViewBinding>() {
|
|||
|
||||
|
||||
mCurItem = WithdrawManager.instance().getItem(mType)
|
||||
mSelectingIndex = DateUtil.getDaysPassed(mCurItem.startMs)
|
||||
updateUI()
|
||||
}
|
||||
|
||||
private fun handleAdWatched(adNotifyBean: WatchAdNotifyBean<WithdrawItemBean>) {
|
||||
val withdrawItemBean = adNotifyBean.extraData
|
||||
if (WithdrawManager.instance().addAdEarnForSubBean(withdrawItemBean.index,
|
||||
withdrawItemBean.selectedSubIndex, adNotifyBean.earnMoneyNum)) {
|
||||
mSelectingIndex, adNotifyBean.earnMoneyNum)) {
|
||||
updateUI()
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateUI() {
|
||||
with(binding) {
|
||||
mAdapter.mSelectedSubIndex = mCurItem.selectedSubIndex
|
||||
mAdapter.mSelectedSubIndex = mSelectingIndex
|
||||
mAdapter.submitList(mCurItem.subItemList)
|
||||
recyclerView.scrollToPosition(mCurItem.selectedSubIndex)
|
||||
recyclerView.scrollToPosition(mSelectingIndex)
|
||||
|
||||
tvCashTotal.text = mCurItem.totalCashNum.toString()
|
||||
progressBar.enableTouch(false)
|
||||
progressBar.setBarColor(forColor = R.color.green_ce)
|
||||
progressBar.setProgress(mCurItem.subItemList[mCurItem.selectedSubIndex].currentProgress)
|
||||
progressBar.setProgress(mCurItem.subItemList[mSelectingIndex].currentProgress)
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateProgressUI() {
|
||||
with(binding) {
|
||||
val subBean = mCurItem.subItemList[mCurItem.selectedSubIndex]
|
||||
val subBean = mCurItem.subItemList[mSelectingIndex]
|
||||
val curProgress = subBean.currentProgress
|
||||
progressBar.setProgress(curProgress)
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import com.gamedog.vididin.manager.WithdrawSubItem
|
|||
import com.vididin.real.money.game.R
|
||||
import com.vididin.real.money.game.databinding.LayoutItemWithdrawSubBinding as ViewBinding
|
||||
|
||||
class WithdrawSubAdapter() : ListAdapter<WithdrawSubItem, WithdrawSubAdapter.ViewHolder>(DiffCallback()) {
|
||||
class WithdrawSubAdapter(private val selectCallback: (index: Int)->Unit) : ListAdapter<WithdrawSubItem, WithdrawSubAdapter.ViewHolder>(DiffCallback()) {
|
||||
|
||||
var mSelectedSubIndex: Int = 0
|
||||
|
||||
|
|
@ -22,6 +22,9 @@ class WithdrawSubAdapter() : ListAdapter<WithdrawSubItem, WithdrawSubAdapter.Vie
|
|||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
holder.itemView.rootView.setOnClickListener {
|
||||
selectCallback.invoke(position)
|
||||
}
|
||||
holder.bind(getItem(position))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -127,7 +127,6 @@ data class WithdrawItemBean(
|
|||
val totalCashNum: Float,
|
||||
var totalProgress: Int = 0,
|
||||
val subItemList: List<WithdrawSubItem> = emptyList(),
|
||||
var selectedSubIndex: Int = 0,
|
||||
val startMs: Long = 0,
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/root"
|
||||
android:clickable="true"
|
||||
android:layout_width="75dp"
|
||||
android:layout_height="90dp"
|
||||
android:background="@drawable/bg_withdraw_sub_selected">
|
||||
|
|
|
|||
|
|
@ -75,20 +75,20 @@ class DateUtil private constructor() {
|
|||
/**
|
||||
* 从起始时间到现在已经过去多少天
|
||||
*/
|
||||
fun getDaysPassed(startTime: Any): Long {
|
||||
fun getDaysPassed(startTime: Any): Int {
|
||||
val startTimestamp = when (startTime) {
|
||||
is Long -> startTime
|
||||
is Date -> startTime.time
|
||||
is String -> stringToTimestamp(startTime) ?: 0L
|
||||
else -> 0L
|
||||
is String -> stringToTimestamp(startTime) ?: 0
|
||||
else -> 0
|
||||
}
|
||||
|
||||
if (startTimestamp == 0L) return 0L
|
||||
if (startTimestamp == 0L) return 0
|
||||
|
||||
val currentTime = System.currentTimeMillis()
|
||||
val diffMillis = currentTime - startTimestamp
|
||||
|
||||
return TimeUnit.MILLISECONDS.toDays(diffMillis)
|
||||
return TimeUnit.MILLISECONDS.toDays(diffMillis).toInt()
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue