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