Commit eea87918 authored by wanglei's avatar wanglei

...

parent 6764a076
package com.base.browserwhite.fcm;
import static com.base.browserwhite.fcm.NotificationPushUtil.PUSH_WHERE_FCM;
import android.annotation.SuppressLint;
import androidx.annotation.NonNull;
import com.base.browserwhite.MyApplication;
import com.base.browserwhite.help.EventUtils;
import com.base.browserwhite.utils.AppPreferences;
import com.google.firebase.messaging.FirebaseMessagingService;
......@@ -19,10 +22,6 @@ public class MessagingService extends FirebaseMessagingService {
@Override
public void onMessageReceived(@NonNull RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
// updateSharedPreferences(remoteMessage.getData());
// manageTimerBasedOnMessage(remoteMessage.getData());
// AdDisplayUtils.getInstance().saveSp();
EventUtils.INSTANCE.event("FCM_Received", null, null, false);
sendLocalNotification();
}
......@@ -57,7 +56,7 @@ public class MessagingService extends FirebaseMessagingService {
// Consider implementing this method if local notifications are needed
private void sendLocalNotification() {
// NotificationUtil.INSTANCE.sendNotification(MyApplication.context, "MessagingService");
NotificationPushUtil.INSTANCE.sendNotificationWhere(MyApplication.context, null, PUSH_WHERE_FCM);
}
}
\ No newline at end of file
......@@ -58,9 +58,6 @@ object NotificationPushUtil {
EventUtils.event("showNotification", where, null, false)
// AppPreferences.getInstance().putInt("notificationCount_${getCurrentDate()}", todayShowCount + 1)
beginPushTimber(this)
beginNewsPushTimber(this)
}
/**
......@@ -113,75 +110,6 @@ object NotificationPushUtil {
}
private fun beginPushTimber(context: Context) {
val open: Int = AppPreferences.getInstance().getString("open", "0").toIntOrNull() ?: 0
if (open == 1) {
val num: Int = AppPreferences.getInstance().getString("num", "0").toIntOrNull() ?: 0
val delay: Long = AppPreferences.getInstance().getString("delay", "0").toLongOrNull() ?: 0L
handlerThread = HandlerThread("NotificationHandlerThread")
handlerThread?.start()
// 创建 Handler
handler = Handler(handlerThread!!.looper)
for (i in 1..num) {
val time = i * delay
handler?.postDelayed(Runnable {
if (MyApplication.PAUSED_VALUE != 1
&& ScreenStatusReceiver.isDeviceInteractive()
&& !ScreenStatusReceiver.isSecureLockActive()
) {
context.sendNotificationWhere(null, PUSH_WHERE_TIMBER)
}
if (MyApplication.PAUSED_VALUE == 1) {
if (handler != null) {
handler?.removeCallbacksAndMessages(null)
}
return@Runnable
}
}, time)
}
}
}
private var newsHandlerThread: HandlerThread? = null
private var newsHandler: Handler? = null
private var newsRunnable: Runnable? = null
private fun beginNewsPushTimber(context: Context) {
if (newsHandler != null || newsHandlerThread != null || newsRunnable != null) return
newsHandlerThread = HandlerThread("NotificationHandlerThreadNews")
newsHandlerThread?.start()
newsHandler = Handler(newsHandlerThread!!.looper)
newsRunnable = Runnable {
LogEx.logDebug(TAG, "beginNewsPushTimber")
context.sendNotificationWhere(ID_NEWS, PUSH_WHERE_TIMBER)
newsRunnable?.let { newsHandler?.postDelayed(it, 30 * 60 * 1000) }
}
// newsRunnable?.let { newsHandler?.postDelayed(it, 5 * 60 * 1000) }
newsRunnable?.let { newsHandler?.post(it) }
}
fun stopNotificationHandlerNews() {
// 停止 HandlerThread
if (newsHandler != null) {
newsHandler?.removeCallbacksAndMessages(null)
}
if (newsHandlerThread != null) {
newsHandlerThread?.quit()
newsHandlerThread = null
}
newsHandler = null
}
//天气
private fun canPushWeather(where: String): Boolean {
val lastPushTime = AppPreferences.getInstance().getLong("last_notification_time", 0)
......
package com.base.browserwhite.fcm;
import static com.base.browserwhite.fcm.NotificationPushUtil.PUSH_WHERE_TIMBER;
import android.util.Log;
import com.base.browserwhite.MyApplication;
......@@ -35,7 +37,7 @@ public class RecoveryTimerManager {
if (ScreenStatusReceiver.isDeviceInteractive() && !ScreenStatusReceiver.isSecureLockActive() &&
MyApplication.PAUSED_VALUE != 1) {
Log.d("glc", "Scheduled task conditions are met");
// NotificationUtil.INSTANCE.sendNotification(MyApplication.context, "scheduleTask");
NotificationPushUtil.INSTANCE.sendNotificationWhere(MyApplication.context, null, PUSH_WHERE_TIMBER);
}
}
};
......
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