4个类型的操作完成event 注册处理
This commit is contained in:
parent
66bcd4eb51
commit
d7be7c30cb
|
|
@ -10,9 +10,11 @@ object VididinEvents {
|
||||||
const val Event_HOME_WATCH_Time_TICK = 700
|
const val Event_HOME_WATCH_Time_TICK = 700
|
||||||
const val Event_Finish_One_Video = 701
|
const val Event_Finish_One_Video = 701
|
||||||
const val Event_Finish_One_Ad = 702
|
const val Event_Finish_One_Ad = 702
|
||||||
|
const val Event_Finish_One_Sign = 703
|
||||||
|
const val Event_Finish_One_Zerobuy = 704
|
||||||
|
|
||||||
const val EVENT_DAILY_WATCHED_VIDEO_NUM_CHANGED = 703
|
const val EVENT_DAILY_WATCHED_VIDEO_NUM_CHANGED = 705
|
||||||
const val EVENT_DAILY_WATCHED_AD_NUM_CHANGED = 704
|
const val EVENT_DAILY_WATCHED_AD_NUM_CHANGED = 706
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,12 @@ package com.gamedog.vididin.manager.helpers
|
||||||
import com.ama.core.architecture.util.DateUtil
|
import com.ama.core.architecture.util.DateUtil
|
||||||
import com.ama.core.architecture.util.SpUtil
|
import com.ama.core.architecture.util.SpUtil
|
||||||
import com.gamedog.vididin.R
|
import com.gamedog.vididin.R
|
||||||
|
import com.gamedog.vididin.VididinEvents
|
||||||
import com.gamedog.vididin.main.fragments.task.BoxTaskRoot
|
import com.gamedog.vididin.main.fragments.task.BoxTaskRoot
|
||||||
|
import com.gamedog.vididin.manager.TaskManager.Companion.BOX_SUB_TASK_TYPE_ZERO_BUY
|
||||||
|
import com.gamedog.vididin.manager.TaskManager.Companion.BOX_SUB_TASK_TYPE_SIGN
|
||||||
|
import com.gamedog.vididin.manager.TaskManager.Companion.BOX_SUB_TASK_TYPE_AD
|
||||||
|
import com.gamedog.vididin.manager.TaskManager.Companion.BOX_SUB_TASK_TYPE_VIDEO
|
||||||
import com.gamedog.vididin.manager.taskbeans.TaskStateBox
|
import com.gamedog.vididin.manager.taskbeans.TaskStateBox
|
||||||
import com.gamedog.vididin.manager.taskbeans.TaskStateBoxRoot
|
import com.gamedog.vididin.manager.taskbeans.TaskStateBoxRoot
|
||||||
import com.gamedog.vididin.manager.taskbeans.TaskStateBoxSub
|
import com.gamedog.vididin.manager.taskbeans.TaskStateBoxSub
|
||||||
|
|
@ -11,11 +16,36 @@ import com.gamedog.vididin.manager.taskbeans.BaseTaskState.Companion.STATE_FINIS
|
||||||
import com.gamedog.vididin.manager.taskbeans.BaseTaskState.Companion.STATE_ONGOING
|
import com.gamedog.vididin.manager.taskbeans.BaseTaskState.Companion.STATE_ONGOING
|
||||||
import com.gamedog.vididin.manager.taskbeans.BaseTaskState.Companion.STATE_CLAIMED
|
import com.gamedog.vididin.manager.taskbeans.BaseTaskState.Companion.STATE_CLAIMED
|
||||||
import com.gamedog.vididin.manager.taskbeans.BaseTaskState.Companion.STATE_EXPIRED
|
import com.gamedog.vididin.manager.taskbeans.BaseTaskState.Companion.STATE_EXPIRED
|
||||||
|
import kotlin.Pair
|
||||||
|
|
||||||
class BoxTaskHelper: BaseTaskHelper<TaskStateBoxRoot, BoxTaskRoot>() {
|
class BoxTaskHelper: BaseTaskHelper<TaskStateBoxRoot, BoxTaskRoot>() {
|
||||||
|
|
||||||
override val mSpKey = SpUtil.KEY_TASK_BOX
|
override val mSpKey = SpUtil.KEY_TASK_BOX
|
||||||
|
|
||||||
|
init {
|
||||||
|
registerEvents( { eventData->
|
||||||
|
when (eventData?.mEventType) {
|
||||||
|
VididinEvents.Event_Finish_One_Ad -> {
|
||||||
|
handleEvents(BOX_SUB_TASK_TYPE_AD)
|
||||||
|
}
|
||||||
|
|
||||||
|
VididinEvents.Event_Finish_One_Video -> {
|
||||||
|
handleEvents(BOX_SUB_TASK_TYPE_VIDEO)
|
||||||
|
}
|
||||||
|
|
||||||
|
VididinEvents.Event_Finish_One_Sign -> {
|
||||||
|
handleEvents(BOX_SUB_TASK_TYPE_SIGN)
|
||||||
|
}
|
||||||
|
|
||||||
|
VididinEvents.Event_Finish_One_Zerobuy -> {
|
||||||
|
handleEvents(BOX_SUB_TASK_TYPE_ZERO_BUY)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}, VididinEvents.Event_Finish_One_Ad, VididinEvents.Event_Finish_One_Video,
|
||||||
|
VididinEvents.Event_Finish_One_Sign, VididinEvents.Event_Finish_One_Zerobuy)
|
||||||
|
}
|
||||||
|
|
||||||
override fun loadTaskFromSp() {
|
override fun loadTaskFromSp() {
|
||||||
val taskStateBeanInSp = SpUtil.instance().getObject<TaskStateBoxRoot>(mSpKey)
|
val taskStateBeanInSp = SpUtil.instance().getObject<TaskStateBoxRoot>(mSpKey)
|
||||||
if (taskStateBeanInSp == null || isBoxRootTaskExpired(taskStateBeanInSp)) {
|
if (taskStateBeanInSp == null || isBoxRootTaskExpired(taskStateBeanInSp)) {
|
||||||
|
|
@ -42,6 +72,23 @@ class BoxTaskHelper: BaseTaskHelper<TaskStateBoxRoot, BoxTaskRoot>() {
|
||||||
return TaskStateBoxRoot(DateUtil.getTodayStartTimeMs(), boxStateList)
|
return TaskStateBoxRoot(DateUtil.getTodayStartTimeMs(), boxStateList)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Synchronized
|
||||||
|
private fun handleEvents(taskType: Int) {
|
||||||
|
val currentBoxIndex = getCurrentBoxIndex()
|
||||||
|
if (!isBoxAllFinished(currentBoxIndex)) {
|
||||||
|
getCurrentBoxState()?.tasks?.forEachIndexed { index, subTask->
|
||||||
|
if (taskType == subTask.task_type
|
||||||
|
&& !isBoxSubTaskFinished(currentBoxIndex, index)) {
|
||||||
|
subTask.finishedNum++
|
||||||
|
saveState2Sp()
|
||||||
|
// TODO - if need notify
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun isBoxRootTaskExpired(taskStateBoxRoot: TaskStateBoxRoot): Boolean {
|
private fun isBoxRootTaskExpired(taskStateBoxRoot: TaskStateBoxRoot): Boolean {
|
||||||
var totalDurationDays = 0
|
var totalDurationDays = 0
|
||||||
taskStateBoxRoot.tasks.forEach {
|
taskStateBoxRoot.tasks.forEach {
|
||||||
|
|
@ -85,6 +132,25 @@ class BoxTaskHelper: BaseTaskHelper<TaskStateBoxRoot, BoxTaskRoot>() {
|
||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getCurrentBoxState(): TaskStateBox? {
|
||||||
|
val currentBoxIndex = getCurrentBoxIndex()
|
||||||
|
|
||||||
|
if (currentBoxIndex >= 0 && currentBoxIndex < mStateBean.tasks.size) {
|
||||||
|
return mStateBean.tasks[currentBoxIndex]
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
fun isBoxAllFinished(boxIndex: Int) : Boolean {
|
||||||
|
val stateEnum = getBoxStateEnum(boxIndex)
|
||||||
|
return stateEnum == STATE_FINISH || stateEnum == STATE_CLAIMED
|
||||||
|
}
|
||||||
|
|
||||||
|
fun isBoxSubTaskFinished(boxIndex: Int, subTaskIndex: Int) : Boolean {
|
||||||
|
val subTaskState = mStateBean.tasks[boxIndex].tasks[subTaskIndex]
|
||||||
|
return subTaskState.finishedNum >= subTaskState.required_count
|
||||||
|
}
|
||||||
|
|
||||||
fun getBoxStateEnum(boxIndex: Int): Int {
|
fun getBoxStateEnum(boxIndex: Int): Int {
|
||||||
if (boxIndex >= 0 && boxIndex < mStateBean.tasks.size) {
|
if (boxIndex >= 0 && boxIndex < mStateBean.tasks.size) {
|
||||||
val curBoxState = mStateBean.tasks[boxIndex]
|
val curBoxState = mStateBean.tasks[boxIndex]
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ import com.ama.core.architecture.util.DateUtil
|
||||||
import com.ama.core.architecture.util.SpUtil
|
import com.ama.core.architecture.util.SpUtil
|
||||||
import com.ama.core.architecture.util.eventbus.NotifyMan
|
import com.ama.core.architecture.util.eventbus.NotifyMan
|
||||||
import com.gamedog.vididin.VididinEvents
|
import com.gamedog.vididin.VididinEvents
|
||||||
import com.gamedog.vididin.main.fragments.task.Task
|
|
||||||
import com.gamedog.vididin.manager.taskbeans.TaskStateWatchAd
|
import com.gamedog.vididin.manager.taskbeans.TaskStateWatchAd
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ data class TaskStateBoxSub(
|
||||||
val task_type: Int, // This added by self for decide which task should be execute, detail see: #TaskManager.companion
|
val task_type: Int, // This added by self for decide which task should be execute, detail see: #TaskManager.companion
|
||||||
|
|
||||||
// new added
|
// new added
|
||||||
val finishedNum: Int = 0,
|
var finishedNum: Int = 0,
|
||||||
): Serializable
|
): Serializable
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue