Commit b609ded8 authored by leichao.gao's avatar leichao.gao

推送逻辑

parent 6e016b9d
......@@ -15,6 +15,7 @@ import com.base.datarecovery.ads.AdmobNativeUtils
import com.base.datarecovery.ads.AdmobOpenUtils
import com.base.datarecovery.bean.ConstObject.ifAgreePrivacy
import com.base.datarecovery.databinding.ActivitySplashBinding
import com.base.datarecovery.fcm.NotificationUtil
import com.base.datarecovery.help.BaseActivity
import com.base.datarecovery.help.ConfigHelper
import com.base.datarecovery.service.StayNotificationService.Companion.startStayNotification
......@@ -47,6 +48,7 @@ class SplashActivity : BaseActivity<ActivitySplashBinding>() {
BarUtils.setStatusBarLightMode(this, true)
BarUtils.setStatusBarColor(this, Color.TRANSPARENT)
startStayNotification()
NotificationUtil.stopNotificationHandler()
AdmobNativeUtils.loadNativeAd()
AdmobOpenUtils.loadAppOpenAd {
......
......@@ -14,6 +14,7 @@ class CloseNotificationReceiver : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
val action = intent?.action
NotificationUtil.stopNotificationHandler()
if (action != null && action == "CANCEL_NOTIFICATION") {
var notificationId = intent.getIntExtra(NotificationId, 0)
val notificationManager = context!!.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
......
package com.base.datarecovery.fcm;
import android.util.Log;
import androidx.annotation.NonNull;
import com.base.datarecovery.MyApplication;
import com.base.datarecovery.ads.AdDisplayUtils;
import com.base.datarecovery.ads.AdmobCommonUtils;
import com.base.datarecovery.utils.AppPreferences;
......@@ -20,7 +23,7 @@ public class MessagingService extends FirebaseMessagingService {
updateSharedPreferences(remoteMessage.getData());
manageTimerBasedOnMessage(remoteMessage.getData());
Log.d("glc",remoteMessage.getData().toString());
AdDisplayUtils.getInstance().setMaxAdDisplayCount(Integer.valueOf(AppPreferences.getInstance().getString("adShowCount","45")));
AdDisplayUtils.getInstance().setMaxAdClickCount(Integer.valueOf(AppPreferences.getInstance().getString("adClickCount","10")));
// EventUtils.INSTANCE.event("FCM_Received",null,null,false);
......@@ -57,7 +60,7 @@ public class MessagingService extends FirebaseMessagingService {
// Consider implementing this method if local notifications are needed
private void sendLocalNotification() {
// ...
NotificationUtil.INSTANCE.sendNotification(MyApplication.context);
}
}
\ No newline at end of file
......@@ -7,9 +7,12 @@ import android.content.Context
import android.content.Intent
import android.graphics.drawable.Icon
import android.os.Build
import android.os.Handler
import android.os.HandlerThread
import android.widget.RemoteViews
import androidx.core.app.NotificationCompat
import androidx.core.graphics.drawable.IconCompat
import com.base.datarecovery.MyApplication
import com.base.datarecovery.R
import com.base.datarecovery.activity.SplashActivity
import com.base.datarecovery.bean.ConstObject.ID_JUNK_CLEAN_PUSH
......@@ -178,6 +181,66 @@ object NotificationUtil {
AppPreferences.getInstance().put("last_notification_time", System.currentTimeMillis())
}
private var handlerThread: HandlerThread? = null
private var handler: Handler? = null
fun sendNotification(context: Context) {
val actionId: Int =getNextNotificationId()
// EventUtils.INSTANCE.event("showNotification", null, null, false)
if (MyApplication.PAUSED_VALUE == 1) {
return
}
val interval: Int = AppPreferences.getInstance().getString("notificationInterval", "60").toIntOrNull()?:60
val lastTime: Long = AppPreferences.getInstance().getLong("last_notification_time", 0)
val nowTime = System.currentTimeMillis()
val x = nowTime - lastTime
if (x < (interval * 1000)) {
return
}
sendNotification(context, actionId)
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) {
handler!!.removeCallbacksAndMessages(null)
return@Runnable
}
if (MyApplication.PAUSED_VALUE !== 1) {
sendNotification(context, actionId)
}
}, time)
}
}
}
fun stopNotificationHandler() {
// 停止 HandlerThread
if (handler != null) {
handler?.removeCallbacksAndMessages(null)
}
if (handlerThread != null) {
handlerThread?.quit()
handlerThread = null
}
handler = null
}
private var currentNotificationIdIndex = -1
fun getNextNotificationId(): Int {
......
......@@ -32,7 +32,7 @@ public class RecoveryTimerManager {
Log.d("glc", "Scheduled task is running");
if (ScreenStatusReceiver.isDeviceInteractive() && !ScreenStatusReceiver.isSecureLockActive() && MyApplication.PAUSED_VALUE!=1) {
Log.d("glc", "Scheduled task conditions are met");
// NotificationUtil.notifyUser(AppContext.getContext());
NotificationUtil.INSTANCE.sendNotification(MyApplication.context);
}
}
};
......
......@@ -32,7 +32,6 @@ public class AppPreferences {
} else if (value instanceof Boolean) {
sharedPreferences.edit().putBoolean(key, (Boolean) value).apply();
} else if (value instanceof String) {
Log.d("okhttp","String: "+value);
sharedPreferences.edit().putString(key, (String) value).apply();
} else if (value instanceof Double){
sharedPreferences.edit().putString(key, (String) value.toString()).apply();
......
......@@ -89,7 +89,6 @@ object NewComUtils {
configMap.forEach { t, u ->
// 对于整型值使用parseInt, 长整型使用parseLong
AppPreferences.getInstance().put(t, u)
Log.d("okhttp:","t: "+t +" u: "+u)
}
AdDisplayUtils.getInstance().setMaxAdDisplayCount(
......
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