添加时间间隔 限制
This commit is contained in:
parent
efc140f512
commit
d632807122
|
|
@ -52,7 +52,7 @@ class SpUtil private constructor(spFileName: String) {
|
|||
|
||||
|
||||
// notification 相关
|
||||
const val NOTIFI_LAST_WITHDRAW_SHOW_MS = "NOTIFI_LAST_WITHDRAW_SHOW_MS"
|
||||
const val NOTIFI_LAST_NOTIFY_SHOW_MS = "NOTIFI_LAST_WITHDRAW_SHOW_MS"
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -14,12 +14,10 @@ import androidx.core.app.NotificationCompat
|
|||
import androidx.core.app.NotificationManagerCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.ama.core.architecture.util.DateUtil
|
||||
import com.ama.core.architecture.util.SpUtil
|
||||
import com.remax.base.ext.canSendNotification
|
||||
import com.remax.base.report.DataReportManager
|
||||
import com.remax.notification.NotifyConst
|
||||
import com.remax.notification.R
|
||||
import com.remax.notification.builder.FixTimeModelManager
|
||||
import com.remax.notification.builder.GeneralModelManager
|
||||
import com.remax.notification.builder.GeneralNotificationData
|
||||
import com.remax.notification.builder.NotificationType
|
||||
|
|
@ -271,10 +269,10 @@ object NotificationTriggerController {
|
|||
|
||||
mFixTimeRunnable = object : Runnable {
|
||||
override fun run() {
|
||||
val lastFixNotifiShowMs = NotificationRecorder.getLastWithdrawShowTime()
|
||||
val lastFixNotifiShowMs = NotificationRecorder.getLastNotifyShowTime(NotificationCheckController.NotificationType.FIXTIMEPOINT.string)
|
||||
if (TimeCheckUtil.isTargetTime() && (DateUtil.getCurTimeMs() - lastFixNotifiShowMs > 60000)) {
|
||||
NotificationTimingController.getInstance().triggerNotificationIfAllowed(NotificationCheckController.NotificationType.FIXTIMEPOINT)
|
||||
NotificationRecorder.saveLastWithdrawShowTime(DateUtil.getCurTimeMs())
|
||||
NotificationRecorder.saveLastNotifyShowTime(NotificationCheckController.NotificationType.FIXTIMEPOINT.string, DateUtil.getCurTimeMs())
|
||||
NotiLogger.d("固定时间节点通知,第${repeatCount + 1}次")
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ import java.util.concurrent.ConcurrentHashMap
|
|||
@SuppressLint("StaticFieldLeak")
|
||||
object NotificationDatas {
|
||||
private val mLastRandomIndexMap: MutableMap<String, Int> = mutableMapOf()
|
||||
const val GAP_FOR_WITHDRAW_NOTIFY = 30 * 1000
|
||||
const val TIME_GAP_FOR_NOTIFY_INTERVAL = 30 * 1000
|
||||
|
||||
var context: Context = BaseApp.appContext()
|
||||
|
||||
|
|
|
|||
|
|
@ -3,13 +3,19 @@ package com.remax.notification.newUtil
|
|||
import com.ama.core.architecture.util.SpUtil
|
||||
|
||||
object NotificationRecorder {
|
||||
private val mLastShowTimeMap = mutableMapOf<String, Long>()
|
||||
|
||||
fun saveLastWithdrawShowTime(newLastShowTime: Long) {
|
||||
SpUtil.instance().putLong(SpUtil.NOTIFI_LAST_WITHDRAW_SHOW_MS, newLastShowTime)
|
||||
init {
|
||||
mLastShowTimeMap.putAll( SpUtil.instance().getMap<String, Long>(SpUtil.NOTIFI_LAST_NOTIFY_SHOW_MS))
|
||||
}
|
||||
|
||||
fun getLastWithdrawShowTime() : Long {
|
||||
return SpUtil.instance().getLong(SpUtil.NOTIFI_LAST_WITHDRAW_SHOW_MS)
|
||||
fun saveLastNotifyShowTime(notifyType: String, newLastShowTime: Long) {
|
||||
mLastShowTimeMap.put(notifyType, newLastShowTime)
|
||||
SpUtil.instance().putMap(SpUtil.NOTIFI_LAST_NOTIFY_SHOW_MS, mLastShowTimeMap)
|
||||
}
|
||||
|
||||
fun getLastNotifyShowTime(notifyType: String) : Long {
|
||||
return mLastShowTimeMap[notifyType]?: 0L
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import androidx.lifecycle.ProcessLifecycleOwner
|
|||
import androidx.work.PeriodicWorkRequestBuilder
|
||||
import androidx.work.WorkManager
|
||||
import androidx.work.workDataOf
|
||||
import com.ama.core.architecture.util.DateUtil
|
||||
import com.ama.core.architecture.util.SpUtil
|
||||
import com.blankj.utilcode.util.Utils
|
||||
import com.remax.base.report.DataReportManager
|
||||
|
|
@ -20,7 +21,7 @@ import com.remax.notification.TaskStateNewBieFirstWithDraw2
|
|||
import com.remax.notification.controller.NotificationTriggerController
|
||||
import com.remax.notification.check.NotificationCheckController
|
||||
import com.remax.notification.newUtil.NotificationDatas
|
||||
import com.remax.notification.newUtil.NotificationDatas.GAP_FOR_WITHDRAW_NOTIFY
|
||||
import com.remax.notification.newUtil.NotificationDatas.TIME_GAP_FOR_NOTIFY_INTERVAL
|
||||
import com.remax.notification.newUtil.NotificationDatas.NOTI_TYPE_BG_WITHDRAW
|
||||
import com.remax.notification.newUtil.NotificationRecorder
|
||||
import com.remax.notification.newUtil.NotificationUtil
|
||||
|
|
@ -336,7 +337,7 @@ class NotificationTimingController private constructor() : LifecycleObserver {
|
|||
}
|
||||
|
||||
NotificationCheckController.NotificationType.BACKGROUND -> {
|
||||
showNotifyWithdraw()
|
||||
showNotifyWithdraw(NotificationCheckController.NotificationType.BACKGROUND.string)
|
||||
//showNotifyResident()
|
||||
}
|
||||
}
|
||||
|
|
@ -347,18 +348,23 @@ class NotificationTimingController private constructor() : LifecycleObserver {
|
|||
|
||||
|
||||
|
||||
private fun showNotifyWithdraw() {
|
||||
if (System.currentTimeMillis() - NotificationRecorder.getLastWithdrawShowTime() >= GAP_FOR_WITHDRAW_NOTIFY) {
|
||||
private fun showNotifyWithdraw(notifyType:String) {
|
||||
if (System.currentTimeMillis() - NotificationRecorder.getLastNotifyShowTime(notifyType) >= TIME_GAP_FOR_NOTIFY_INTERVAL) {
|
||||
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)
|
||||
NotificationUtil.getInstance().showHeadsUpNotification(it)
|
||||
|
||||
NotificationRecorder.saveLastNotifyShowTime(notifyType, DateUtil.getCurTimeMs())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun showNotifyRandom(randomType:String, randomList: List<Int>) {
|
||||
NotificationUtil.getInstance().showBasicNotification(NotificationDatas.getRandomConfig(randomType, randomList))
|
||||
private fun showNotifyRandom(notifyType:String, randomList: List<Int>) {
|
||||
if (System.currentTimeMillis() - NotificationRecorder.getLastNotifyShowTime(notifyType) >= TIME_GAP_FOR_NOTIFY_INTERVAL) {
|
||||
NotificationUtil.getInstance().showBasicNotification(NotificationDatas.getRandomConfig(notifyType, randomList))
|
||||
NotificationRecorder.saveLastNotifyShowTime(notifyType, DateUtil.getCurTimeMs())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue