进度事件通知及更新
This commit is contained in:
parent
ae45b72717
commit
8f2786b5b9
|
|
@ -42,4 +42,11 @@ object VididinEvents {
|
||||||
const val EVENT_JUMP_2_VIDEO = 901
|
const val EVENT_JUMP_2_VIDEO = 901
|
||||||
const val EVENT_JUMP_2_SIGN= 902
|
const val EVENT_JUMP_2_SIGN= 902
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Withdraw related
|
||||||
|
const val EVENT_WITHDRAW_SUB_ITEM_PROGRESS_UPDATED = 500
|
||||||
|
const val EVENT_WITHDRAW_SELECTED_SUB_ITEM_CHANGED = 501
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -7,9 +7,10 @@ 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.eventbus.NotifyMan
|
|
||||||
import com.ama.core.architecture.util.setOnClickBatch
|
import com.ama.core.architecture.util.setOnClickBatch
|
||||||
import com.gamedog.vididin.VidiConst
|
import com.gamedog.vididin.VidiConst
|
||||||
|
import com.gamedog.vididin.VididinEvents
|
||||||
|
import com.gamedog.vididin.beans.WatchAdNotifyBean
|
||||||
import com.gamedog.vididin.manager.WithdrawItemBean
|
import com.gamedog.vididin.manager.WithdrawItemBean
|
||||||
import com.gamedog.vididin.manager.WithdrawManager
|
import com.gamedog.vididin.manager.WithdrawManager
|
||||||
import com.gamedog.vididin.router.Router
|
import com.gamedog.vididin.router.Router
|
||||||
|
|
@ -21,7 +22,6 @@ import com.vididin.real.money.game.databinding.ActivityWithdrawSubBinding as Vie
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class WithDrawSubActivity : AppViewsEmptyViewModelActivity<ViewBinding>() {
|
class WithDrawSubActivity : AppViewsEmptyViewModelActivity<ViewBinding>() {
|
||||||
private var mSelectedSubIndex: Int = 0
|
|
||||||
private lateinit var mCurItem: WithdrawItemBean
|
private lateinit var mCurItem: WithdrawItemBean
|
||||||
private var mType: Int = 0
|
private var mType: Int = 0
|
||||||
private val mAdapter: WithdrawSubAdapter by lazy { WithdrawSubAdapter() }
|
private val mAdapter: WithdrawSubAdapter by lazy { WithdrawSubAdapter() }
|
||||||
|
|
@ -51,30 +51,53 @@ class WithDrawSubActivity : AppViewsEmptyViewModelActivity<ViewBinding>() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun gotoWatchAd() {
|
private fun gotoWatchAd() {
|
||||||
val extraData = NotifyMan.NotifyData<WithdrawItemBean>(mCurItem)
|
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(extraData))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun ViewBinding.initListeners() {
|
override fun ViewBinding.initListeners() {
|
||||||
mCurItem = WithdrawManager.instance().getItem(mType)
|
registerEvents({ data->
|
||||||
mAdapter.submitList(mCurItem.subItemList)
|
when (data?.mEventType) {
|
||||||
|
VididinEvents.EVENT_AD_WATCHED_FOR_WITHDRAW_BIG -> {
|
||||||
|
handleAdWatched(data.mData as WatchAdNotifyBean<WithdrawItemBean>)
|
||||||
|
}
|
||||||
|
|
||||||
mCurItem.subItemList.forEach {
|
VididinEvents.EVENT_WITHDRAW_SUB_ITEM_PROGRESS_UPDATED -> {
|
||||||
if (it.isSelected) {
|
if ((data.mData as Int) == mCurItem.selectedSubIndex) {
|
||||||
mSelectedSubIndex = it.index
|
progressBar.setProgress(mCurItem.subItemList[mCurItem.selectedSubIndex].currentProgress)
|
||||||
return@forEach
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VididinEvents.EVENT_WITHDRAW_SELECTED_SUB_ITEM_CHANGED -> {
|
||||||
updateUI()
|
updateUI()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, VididinEvents.EVENT_AD_WATCHED_FOR_WITHDRAW_BIG,
|
||||||
|
VididinEvents.EVENT_WITHDRAW_SUB_ITEM_PROGRESS_UPDATED,
|
||||||
|
VididinEvents.EVENT_WITHDRAW_SELECTED_SUB_ITEM_CHANGED)
|
||||||
|
|
||||||
recyclerView.scrollToPosition(mSelectedSubIndex)
|
|
||||||
|
mCurItem = WithdrawManager.instance().getItem(mType)
|
||||||
|
updateUI()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun handleAdWatched(adNotifyBean: WatchAdNotifyBean<WithdrawItemBean>) {
|
||||||
|
val withdrawItemBean = adNotifyBean.extraData
|
||||||
|
if (WithdrawManager.instance().addAdEarnForSubBean(withdrawItemBean.index,
|
||||||
|
withdrawItemBean.selectedSubIndex, adNotifyBean.earnMoneyNum)) {
|
||||||
|
updateUI()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateUI() {
|
private fun updateUI() {
|
||||||
with(binding) {
|
with(binding) {
|
||||||
|
mAdapter.mSelectedSubIndex = mCurItem.selectedSubIndex
|
||||||
|
mAdapter.submitList(mCurItem.subItemList)
|
||||||
|
recyclerView.scrollToPosition(mCurItem.selectedSubIndex)
|
||||||
|
|
||||||
|
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[mSelectedSubIndex].currentProgress)
|
progressBar.setProgress(mCurItem.subItemList[mCurItem.selectedSubIndex].currentProgress)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,9 +14,11 @@ import com.vididin.real.money.game.databinding.LayoutItemWithdrawSubBinding as V
|
||||||
|
|
||||||
class WithdrawSubAdapter() : ListAdapter<WithdrawSubItem, WithdrawSubAdapter.ViewHolder>(DiffCallback()) {
|
class WithdrawSubAdapter() : ListAdapter<WithdrawSubItem, WithdrawSubAdapter.ViewHolder>(DiffCallback()) {
|
||||||
|
|
||||||
|
var mSelectedSubIndex: Int = 0
|
||||||
|
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||||
val binding = ViewBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
val binding = ViewBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||||
return ViewHolder(binding)
|
return ViewHolder(binding,)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||||
|
|
@ -29,7 +31,7 @@ class WithdrawSubAdapter() : ListAdapter<WithdrawSubItem, WithdrawSubAdapter.Vie
|
||||||
with(binding) {
|
with(binding) {
|
||||||
tvTitle.text = buildString {
|
tvTitle.text = buildString {
|
||||||
append(ResUtil.getString(R.string.cash))
|
append(ResUtil.getString(R.string.cash))
|
||||||
append(item.cashNum)
|
append(item.cashTotal)
|
||||||
}
|
}
|
||||||
tvDay.text = buildString {
|
tvDay.text = buildString {
|
||||||
append(ResUtil.getString(R.string.day))
|
append(ResUtil.getString(R.string.day))
|
||||||
|
|
@ -37,7 +39,7 @@ class WithdrawSubAdapter() : ListAdapter<WithdrawSubItem, WithdrawSubAdapter.Vie
|
||||||
append(item.index + 1)
|
append(item.index + 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item.isSelected) {
|
if (item.index == mSelectedSubIndex) {
|
||||||
root.setBackgroundResource(R.drawable.bg_withdraw_sub_selected)
|
root.setBackgroundResource(R.drawable.bg_withdraw_sub_selected)
|
||||||
root.alpha = 1F
|
root.alpha = 1F
|
||||||
ivLefttopChecked.isVisible = true
|
ivLefttopChecked.isVisible = true
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@ package com.gamedog.vididin.manager
|
||||||
|
|
||||||
import com.ama.core.architecture.util.AndroidUtil
|
import com.ama.core.architecture.util.AndroidUtil
|
||||||
import com.ama.core.architecture.util.SpUtil
|
import com.ama.core.architecture.util.SpUtil
|
||||||
|
import com.ama.core.architecture.util.eventbus.NotifyMan
|
||||||
|
import com.gamedog.vididin.VididinEvents
|
||||||
|
|
||||||
|
|
||||||
class WithdrawManager private constructor() {
|
class WithdrawManager private constructor() {
|
||||||
|
|
@ -11,7 +13,7 @@ class WithdrawManager private constructor() {
|
||||||
val itemList = SpUtil.instance().getList<WithdrawItemBean>(SpUtil.KEY_WITHDRAW_ITEM_LIST).toMutableList()
|
val itemList = SpUtil.instance().getList<WithdrawItemBean>(SpUtil.KEY_WITHDRAW_ITEM_LIST).toMutableList()
|
||||||
if (itemList.isEmpty()) {
|
if (itemList.isEmpty()) {
|
||||||
itemList.addAll(generateItemList())
|
itemList.addAll(generateItemList())
|
||||||
save2Infos(itemList)
|
saveInfos2Sp(itemList)
|
||||||
}
|
}
|
||||||
itemList
|
itemList
|
||||||
}
|
}
|
||||||
|
|
@ -46,12 +48,13 @@ class WithdrawManager private constructor() {
|
||||||
val subItemCount: Int = (totalCashInItem/EACH_SUB_ITEM_CASH_NUM).toInt()
|
val subItemCount: Int = (totalCashInItem/EACH_SUB_ITEM_CASH_NUM).toInt()
|
||||||
|
|
||||||
for (i in 0..subItemCount-1) {
|
for (i in 0..subItemCount-1) {
|
||||||
subItemList.add(WithdrawSubItem(i, EACH_SUB_ITEM_CASH_NUM, i==0, AndroidUtil.randomInt(50, 70)))
|
val initProgress = AndroidUtil.randomInt(50, 70)
|
||||||
|
subItemList.add(WithdrawSubItem(i, EACH_SUB_ITEM_CASH_NUM, initProgress, initProgress, 0F))
|
||||||
}
|
}
|
||||||
return subItemList
|
return subItemList
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun save2Infos(itemList: MutableList<WithdrawItemBean>) {
|
private fun saveInfos2Sp(itemList: MutableList<WithdrawItemBean>) {
|
||||||
SpUtil.instance().putList(SpUtil.KEY_WITHDRAW_ITEM_LIST, itemList)
|
SpUtil.instance().putList(SpUtil.KEY_WITHDRAW_ITEM_LIST, itemList)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -63,8 +66,41 @@ class WithdrawManager private constructor() {
|
||||||
return mItemList[itemIndex]
|
return mItemList[itemIndex]
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateProgress(itemIndex: Int, updatedItem: WithdrawItemBean) {
|
|
||||||
// TODO -
|
fun addAdEarnForSubBean(itemIndex: Int, selectedSubIndex: Int, earnMoneyNum: Float) : Boolean {
|
||||||
|
if (itemIndex >= 0 && itemIndex < mItemList.size) {
|
||||||
|
try {
|
||||||
|
val subBean = mItemList[itemIndex].subItemList[selectedSubIndex]
|
||||||
|
subBean.hasEarnMoneyByAd += earnMoneyNum * 5 // dollar 2 bariz
|
||||||
|
calculateSubBeanProgress(subBean) //传入 itembean 更新 selectedIndex为下一个
|
||||||
|
saveInfos2Sp(mItemList)
|
||||||
|
notifyProgressUpdated(subBean)
|
||||||
|
return true
|
||||||
|
} catch (e: Exception) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun notifyProgressUpdated(subBean: WithdrawSubItem) {
|
||||||
|
NotifyMan.instance().sendEvent(VididinEvents.EVENT_WITHDRAW_SUB_ITEM_PROGRESS_UPDATED,
|
||||||
|
NotifyMan.NotifyData(subBean.index))
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun notifySelectedSubBeanChanged(subBean: WithdrawSubItem) {
|
||||||
|
NotifyMan.instance().sendEvent(VididinEvents.EVENT_WITHDRAW_SELECTED_SUB_ITEM_CHANGED, NotifyMan.NotifyData(subBean.index))
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun calculateSubBeanProgress(subBean: WithdrawSubItem) {
|
||||||
|
val needEarnProgress = 100 - subBean.startProgress
|
||||||
|
if (subBean.hasEarnMoneyByAd >= subBean.cashTotal) {
|
||||||
|
subBean.currentProgress = 100
|
||||||
|
} else {
|
||||||
|
val newProgress = subBean.startProgress + (needEarnProgress * (subBean.hasEarnMoneyByAd / subBean.cashTotal)).toInt()
|
||||||
|
subBean.currentProgress = if (newProgress >= 100) 99 else newProgress
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -74,12 +110,14 @@ data class WithdrawItemBean(
|
||||||
val index: Int,
|
val index: Int,
|
||||||
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,
|
||||||
)
|
)
|
||||||
|
|
||||||
data class WithdrawSubItem(
|
data class WithdrawSubItem(
|
||||||
val index: Int,
|
val index: Int,
|
||||||
val cashNum: Float,
|
val cashTotal: Float,
|
||||||
var isSelected: Boolean = false,
|
val startProgress: Int = 0,
|
||||||
val currentProgress: Int = 0,
|
var currentProgress: Int = 0,
|
||||||
|
var hasEarnMoneyByAd: Float = 0F,
|
||||||
)
|
)
|
||||||
Loading…
Reference in New Issue