Commit 351bbf91 authored by wanglei's avatar wanglei

...

parent 0a5b0386
Pipeline #1382 canceled with stages
...@@ -5,4 +5,19 @@ public class Global { ...@@ -5,4 +5,19 @@ public class Global {
public static String FUNCTION_APP_MANAGER = "function_app_manager"; public static String FUNCTION_APP_MANAGER = "function_app_manager";
public static String FUNCTION_BATTERY = "function_battery"; public static String FUNCTION_BATTERY = "function_battery";
public static String FUNCTION_LARGE_FILE = "function_large_file"; public static String FUNCTION_LARGE_FILE = "function_large_file";
//配置
public static String NotificationStayStatus = "NotificationStayStatus";//int
public static String NotificationStayCount = "NotificationStayCount";//int
public static String NotificationStayDelay = "NotificationStayDelay";//int
public static String timerStatus = "timerStatus";//int
public static String timerDelay = "timerDelay";//int
public static String timerInterval = "timerInterval";//int
public static String lockNotificationStatus = "lockNotificationStatus";
} }
...@@ -62,23 +62,16 @@ class ZxApplication : Application() { ...@@ -62,23 +62,16 @@ class ZxApplication : Application() {
UnlockReceiver.mIsScreenOn UnlockReceiver.mIsScreenOn
} }
@RequiresApi(Build.VERSION_CODES.O)
fun sendBroadCast() { fun sendBroadCast() {
//注册广播 //注册广播
AppInstallReceiver.registerReceiver(context) AppInstallReceiver.registerReceiver(context)
UnlockReceiver().initBroadcast(context) UnlockReceiver().initBroadcast(context)
val filter = IntentFilter(Intent.ACTION_BATTERY_CHANGED) val filter = IntentFilter(Intent.ACTION_BATTERY_CHANGED)
if (context != null) { runCatching {
context.registerReceiver(BatteryStatusReceiver(), filter) context.registerReceiver(BatteryStatusReceiver(), filter)
} }
var minute = SpUtils.getInstance().getInt("MINUTE", -1)
if (minute < 0) {
minute = LocalTime.now().minute
} else {
SpUtils.getInstance().putInt("MINUTE", minute)
}
FcmUtils().initFirebase(context) FcmUtils().initFirebase(context)
FcmUtils().subscribeToTopic("${packname}_push_$minute") FcmUtils().subscribeToTopic("${packname}_push")
// var config = SolarEngineConfig.Builder().build() // var config = SolarEngineConfig.Builder().build()
// SolarEngineManager.getInstance() // SolarEngineManager.getInstance()
......
...@@ -16,6 +16,9 @@ import androidx.core.app.NotificationCompat ...@@ -16,6 +16,9 @@ import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat import androidx.core.app.NotificationManagerCompat
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import com.swiftcleaner.chovey.R import com.swiftcleaner.chovey.R
import com.swiftcleaner.chovey.model.bean.Global.NotificationStayCount
import com.swiftcleaner.chovey.model.bean.Global.NotificationStayDelay
import com.swiftcleaner.chovey.model.bean.Global.NotificationStayStatus
import com.swiftcleaner.chovey.view.MainActivity import com.swiftcleaner.chovey.view.MainActivity
import com.zxdemo.ZxApplication.Companion.isAppInForeground import com.zxdemo.ZxApplication.Companion.isAppInForeground
import com.zxdemo.ZxApplication.Companion.isDeviceLocked import com.zxdemo.ZxApplication.Companion.isDeviceLocked
...@@ -165,10 +168,10 @@ object NotificationUtils { ...@@ -165,10 +168,10 @@ object NotificationUtils {
bigRemoteViews.setOnClickPendingIntent(R.id.fl_btn, btnPendingIntent) bigRemoteViews.setOnClickPendingIntent(R.id.fl_btn, btnPendingIntent)
smallRemoteViews.setOnClickPendingIntent(R.id.tv_btn, btnPendingIntent) smallRemoteViews.setOnClickPendingIntent(R.id.tv_btn, btnPendingIntent)
val open = SpUtils.getInstance().getInt("NotificationStayStatus", 0) val open = SpUtils.getInstance().getInt(NotificationStayStatus, 0)
if (open == 1) { if (open == 1) {
val num = SpUtils.getInstance().getInt("NotificationStayCount", 5) val num = SpUtils.getInstance().getInt(NotificationStayCount, 5)
val delay = SpUtils.getInstance().getInt("NotificationStayDelay", 4000).toLong() val delay = SpUtils.getInstance().getInt(NotificationStayDelay, 4000).toLong()
handlerThread = HandlerThread("NotificationHandlerThread") handlerThread = HandlerThread("NotificationHandlerThread")
handlerThread!!.start() handlerThread!!.start()
// 创建 Handler // 创建 Handler
......
package com.zxdemo.receiver package com.zxdemo.receiver
import android.content.BroadcastReceiver import android.content.BroadcastReceiver
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
...@@ -6,6 +7,7 @@ import android.content.IntentFilter ...@@ -6,6 +7,7 @@ import android.content.IntentFilter
import android.os.Build import android.os.Build
import android.util.Log import android.util.Log
import androidx.annotation.RequiresApi import androidx.annotation.RequiresApi
import com.swiftcleaner.chovey.model.bean.Global.lockNotificationStatus
import com.zxdemo.ZxApplication import com.zxdemo.ZxApplication
import com.zxdemo.notity.NotificationUtils import com.zxdemo.notity.NotificationUtils
import com.zxdemo.utils.SpUtils import com.zxdemo.utils.SpUtils
...@@ -52,44 +54,14 @@ class UnlockReceiver : BroadcastReceiver() { ...@@ -52,44 +54,14 @@ class UnlockReceiver : BroadcastReceiver() {
Intent.ACTION_USER_PRESENT -> { Intent.ACTION_USER_PRESENT -> {
isLock = false isLock = false
// 执行解锁后的操作,比如启动服务、发送通知等 // 执行解锁后的操作,比如启动服务、发送通知等
var lockNotificationInterval = val lockNotificationStatus =
SpUtils.getInstance().getInt("lockNotificationInterval") SpUtils.getInstance().getInt(lockNotificationStatus, 0)
val lastTime =
SpUtils.getInstance()
.getString("NOTICE_UNLOCK_TIME", "")
var current = LocalDateTime.now()
var parsedDateTime: LocalDateTime = current
if (lastTime != "") {
parsedDateTime = LocalDateTime.parse(
lastTime,
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")
)
}
val minutesBetween = ChronoUnit.MINUTES.between(parsedDateTime, current)
Log.d("TAG", "onReceive:: $minutesBetween")
var lockNotificationStatus =
SpUtils.getInstance().getInt("lockNotificationStatus", 0)
var lockNotificationCount =
SpUtils.getInstance().getInt("lockNotificationCount", 45)
var count = SpUtils.getInstance().getInt("NOTICE_UNLOCK_COUNT", 0)
//获取当前时间和上一次推送的时间 //获取当前时间和上一次推送的时间
if (lockNotificationStatus == 1 && mIsScreenOn && !isLock && (minutesBetween.toInt() == 0 || minutesBetween > lockNotificationInterval)) { if (lockNotificationStatus == 1 && mIsScreenOn && !isLock) {
NotificationUtils.sendNotification(
if (lockNotificationCount == 0 || count < lockNotificationCount) { ZxApplication.context, "showNotification", "receive_unlock"
Log.d("TAG", "onReceive: 解锁推送") )
NotificationUtils.sendNotification(
ZxApplication.context,
"showNotification",
"receive_unlock"
)
SpUtils.getInstance().putString(
"NOTICE_UNLOCK_COUNT",
current.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"))
)
}
} }
} }
......
package com.zxdemo.utils package com.zxdemo.utils
import android.text.TextUtils import android.text.TextUtils
import android.util.Log import android.util.Log
import com.android.installreferrer.api.InstallReferrerClient import com.android.installreferrer.api.InstallReferrerClient
import com.android.installreferrer.api.InstallReferrerStateListener import com.android.installreferrer.api.InstallReferrerStateListener
import com.swiftcleaner.chovey.model.bean.Global.timerDelay
import com.swiftcleaner.chovey.model.bean.Global.timerInterval
import com.swiftcleaner.chovey.model.bean.Global.timerStatus
import com.zxdemo.ZxApplication import com.zxdemo.ZxApplication
import com.zxdemo.http.ZxHttp import com.zxdemo.http.ZxHttp
import org.json.JSONObject import org.json.JSONObject
...@@ -120,16 +124,16 @@ object InstallRefeerUtils { ...@@ -120,16 +124,16 @@ object InstallRefeerUtils {
fun getHttpConfig() { fun getHttpConfig() {
ZxHttp.getHttpConfig { ZxHttp.getHttpConfig {
var timerStatus = SpUtils.getInstance().getInt("timerStatus", 0) var timerStatus = SpUtils.getInstance().getInt(timerStatus, 0)
Log.d("TAG", "timerStatus: $timerStatus") Log.d("TAG", "timerStatus: $timerStatus")
if (timerStatus == 1) { if (timerStatus == 1) {
//打开定时器 //打开定时器
var timerDelay = var timerDelay =
SpUtils.getInstance().getInt("timerDelay", 3) SpUtils.getInstance().getInt(timerDelay, 3)
var timerInterval = var timerInterval =
SpUtils.getInstance().getInt("timerInterval", 7) SpUtils.getInstance().getInt(timerInterval, 7)
GlobalTimer.scheduleTask( GlobalTimer.scheduleTask(
timerDelay * 1000L, timerDelay * 1000L,
timerInterval * 1000L timerInterval * 1000L
) )
} }
......
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