不同类型触发机制, 从不同制定list随机选择
This commit is contained in:
parent
64ff009736
commit
efc140f512
|
|
@ -19,7 +19,7 @@ import java.util.concurrent.ConcurrentHashMap
|
|||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
object NotificationDatas {
|
||||
private var mCurRandomIndex = 0
|
||||
private val mLastRandomIndexMap: MutableMap<String, Int> = mutableMapOf()
|
||||
const val GAP_FOR_WITHDRAW_NOTIFY = 30 * 1000
|
||||
|
||||
var context: Context = BaseApp.appContext()
|
||||
|
|
@ -222,16 +222,20 @@ object NotificationDatas {
|
|||
return mConfigMap[notifiType]
|
||||
}
|
||||
|
||||
fun getRandomConfig(): NotificationConfig {
|
||||
var randomIndex = AndroidUtil.randomInt(0, mRandomConfigList.size - 1)
|
||||
if (mCurRandomIndex == randomIndex) {
|
||||
fun getRandomConfig(randomType:String, specifyList: List<Int>): NotificationConfig {
|
||||
var randomIndex = AndroidUtil.randomInt(0, specifyList.size - 1)
|
||||
val newGenIndex = specifyList[randomIndex] - 1
|
||||
val lastIndex = mLastRandomIndexMap[randomType]
|
||||
|
||||
if (lastIndex == newGenIndex) {
|
||||
randomIndex++
|
||||
if (randomIndex >= mRandomConfigList.size) {
|
||||
if (randomIndex >= specifyList.size) {
|
||||
randomIndex = 0
|
||||
}
|
||||
}
|
||||
mCurRandomIndex = randomIndex
|
||||
return mRandomConfigList[mCurRandomIndex]
|
||||
mLastRandomIndexMap.put(randomType, specifyList[randomIndex] - 1)
|
||||
|
||||
return mRandomConfigList[mLastRandomIndexMap[randomType]!!]
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -307,17 +307,6 @@ class NotificationTimingController private constructor() : LifecycleObserver {
|
|||
}*/
|
||||
|
||||
when (type) {
|
||||
NotificationCheckController.NotificationType.UNLOCK -> {
|
||||
showNotifyRandom()
|
||||
}
|
||||
|
||||
NotificationCheckController.NotificationType.BACKGROUND -> {
|
||||
showNotifyWithdraw()
|
||||
//showNotifyRandom()
|
||||
//showNotifyResident()
|
||||
}
|
||||
|
||||
|
||||
NotificationCheckController.NotificationType.KEEPALIVE -> {
|
||||
|
||||
}
|
||||
|
|
@ -331,15 +320,24 @@ class NotificationTimingController private constructor() : LifecycleObserver {
|
|||
}
|
||||
|
||||
NotificationCheckController.NotificationType.FIXTIMEPOINT -> {
|
||||
showNotifyRandom()
|
||||
showNotifyRandom(NotificationCheckController.NotificationType.FIXTIMEPOINT.string, listOf(2,3,4,6,7,8))
|
||||
}
|
||||
|
||||
NotificationCheckController.NotificationType.APPINSTALL -> {
|
||||
showNotifyRandom()
|
||||
showNotifyRandom(NotificationCheckController.NotificationType.APPINSTALL.string, listOf(3,5,7,9,11))
|
||||
}
|
||||
|
||||
NotificationCheckController.NotificationType.CHARGE -> {
|
||||
showNotifyRandom()
|
||||
showNotifyRandom(NotificationCheckController.NotificationType.CHARGE.string, listOf(1,3,5,7,9,11))
|
||||
}
|
||||
|
||||
NotificationCheckController.NotificationType.UNLOCK -> {
|
||||
showNotifyRandom(NotificationCheckController.NotificationType.UNLOCK.string, listOf(2,4,6,8,10,11))
|
||||
}
|
||||
|
||||
NotificationCheckController.NotificationType.BACKGROUND -> {
|
||||
showNotifyWithdraw()
|
||||
//showNotifyResident()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -351,7 +349,6 @@ class NotificationTimingController private constructor() : LifecycleObserver {
|
|||
|
||||
private fun showNotifyWithdraw() {
|
||||
if (System.currentTimeMillis() - NotificationRecorder.getLastWithdrawShowTime() >= GAP_FOR_WITHDRAW_NOTIFY) {
|
||||
|
||||
val hasClaimedSmallCash = SpUtil.instance().getObject<TaskStateNewBieFirstWithDraw2>(SpUtil.KEY_NEWBIE_FIRST_WITHDRAW)?.hasClaimReward
|
||||
NotificationDatas.getConfigForType(NOTI_TYPE_BG_WITHDRAW)?.let {
|
||||
it.content = String.format(it.content, if (hasClaimedSmallCash == null || !hasClaimedSmallCash) 0.1 else 50)
|
||||
|
|
@ -360,8 +357,8 @@ class NotificationTimingController private constructor() : LifecycleObserver {
|
|||
}
|
||||
}
|
||||
|
||||
private fun showNotifyRandom() {
|
||||
NotificationUtil.getInstance().showBasicNotification(NotificationDatas.getRandomConfig())
|
||||
private fun showNotifyRandom(randomType:String, randomList: List<Int>) {
|
||||
NotificationUtil.getInstance().showBasicNotification(NotificationDatas.getRandomConfig(randomType, randomList))
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue