Commit 5c104124 authored by leichao.gao's avatar leichao.gao

update timer

parent 88f0dbc2
package com.base.browserwhite.fcm;
import static com.base.browserwhite.fcm.NotificationPushUtil.PUSH_WHERE_TIMBER;
import android.Manifest;
import android.app.Notification;
import android.content.pm.PackageManager;
import android.util.Log;
import androidx.core.app.ActivityCompat;
import androidx.core.app.NotificationManagerCompat;
import com.base.browserwhite.MyApplication;
import com.base.browserwhite.service.StayNotificationService;
import java.util.Timer;
import java.util.TimerTask;
public class NotificationTimerManager {
private static NotificationTimerManager instance;
private Timer taskTimer;
private boolean isTimerActive;
private NotificationTimerManager() {
// 私有构造方法
}
public static synchronized NotificationTimerManager getInstance() {
if (instance == null) {
instance = new NotificationTimerManager();
}
return instance;
}
public void scheduleTask(long delay, long period) {
synchronized (NotificationTimerManager.class) {
ensureTimerIsStopped(); // 确保定时器未运行
taskTimer = new Timer(); // 创建新的 Timer 实例
TimerTask task = new TimerTask() {
@Override
public void run() {
Notification notification = StayNotificationService.Companion.createPermanentNotification(MyApplication.context);
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(MyApplication.context);
if (ActivityCompat.checkSelfPermission(MyApplication.context, Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) {
}else {
notificationManager.notify(100, notification);
}
}
};
taskTimer.schedule(task, delay, period); // 调度任务
isTimerActive = true; // 设置定时器状态为活跃
}
}
private void ensureTimerIsStopped() {
if (isTimerActive) {
if (taskTimer != null) {
taskTimer.cancel();
taskTimer.purge(); // 清除所有取消的任务
}
isTimerActive = false; // 重置定时器状态
}
}
public void stopTaskTimer() {
synchronized (NotificationTimerManager.class) {
ensureTimerIsStopped(); // 停止定时器
}
}
public boolean isTaskTimerActive() {
return isTimerActive;
}
}
\ No newline at end of file
......@@ -7,6 +7,7 @@ import com.android.installreferrer.api.InstallReferrerStateListener
import com.base.browserwhite.BuildConfig
import com.base.browserwhite.MyApplication
import com.base.browserwhite.ads.AdmobMaxHelper
import com.base.browserwhite.fcm.NotificationTimerManager
import com.base.browserwhite.fcm.RecoveryTimerManager
import com.base.browserwhite.fcm.ScreenStatusReceiver
import com.base.browserwhite.utils.AppPreferences
......@@ -48,7 +49,12 @@ object InstallHelps {
obj.put("instantExperienceLaunched", installInfo.toString())
EventUtils.event("install_referrer", ext = obj, isSingleEvent = true)
AppPreferences.getInstance().put("referrer", response.installReferrer)
if (listOf("gclid", "facebook", "instagram").all { !installInfo.contains(it, true) }) {
if (listOf(
"gclid",
"facebook",
"instagram"
).all { !installInfo.contains(it, true) }
) {
//自然用户
if (BuildConfig.DEBUG) {
AppPreferences.getInstance().put("install_source", "channel")
......@@ -103,6 +109,21 @@ object InstallHelps {
)
}
}
val refreshNotificationSwitch: Int =
AppPreferences.getInstance().getString("refreshNotificationSwitch", "1")
.toIntOrNull() ?: 1
val refreshNotificationInterval: Int =
AppPreferences.getInstance().getString("refreshNotificationInterval", "1")
.toIntOrNull() ?: 1
if (refreshNotificationSwitch == 1) {
if (!NotificationTimerManager.getInstance().isTaskTimerActive) {
NotificationTimerManager.getInstance().scheduleTask(
(refreshNotificationInterval * 60 * 1000).toLong(),
(refreshNotificationInterval * 60 * 1000).toLong()
)
}
}
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment