Commit db732926 authored by Your Name's avatar Your Name

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	app/src/main/res/layout/notification_common_small.xml
parents a0f24d80 351bbf91
Pipeline #1383 canceled with stages
......@@ -5,4 +5,19 @@ public class Global {
public static String FUNCTION_APP_MANAGER = "function_app_manager";
public static String FUNCTION_BATTERY = "function_battery";
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() {
UnlockReceiver.mIsScreenOn
}
@RequiresApi(Build.VERSION_CODES.O)
fun sendBroadCast() {
//注册广播
AppInstallReceiver.registerReceiver(context)
UnlockReceiver().initBroadcast(context)
val filter = IntentFilter(Intent.ACTION_BATTERY_CHANGED)
if (context != null) {
runCatching {
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().subscribeToTopic("${packname}_push_$minute")
FcmUtils().subscribeToTopic("${packname}_push")
// var config = SolarEngineConfig.Builder().build()
// SolarEngineManager.getInstance()
......
package com.zxdemo.notity
import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.PendingIntent
......@@ -15,6 +16,9 @@ import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import androidx.core.content.ContextCompat
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.zxdemo.ZxApplication.Companion.isAppInForeground
import com.zxdemo.ZxApplication.Companion.isDeviceLocked
......@@ -131,8 +135,8 @@ object NotificationUtils {
fun sendNotification(context: Context, action: String, value: String) {
var actionId = nextNotificationId
val bigRemoteViews = RemoteViews(context.packageName, R.layout.notice_expand)
val smallRemoteViews = RemoteViews(context.packageName, R.layout.notify_stay_big)
val bigRemoteViews = RemoteViews(context.packageName, R.layout.notification_common)
val smallRemoteViews = RemoteViews(context.packageName, R.layout.notification_common_small)
when (actionId) {
ID_CLEAN_JUNK -> {
}
......@@ -161,13 +165,13 @@ object NotificationUtils {
var intent = Intent(context, MainActivity::class.java)
intent.putExtra("actionId", actionId)
val btnPendingIntent = PendingIntent.getActivity(context, btnRequestCode, intent, flag)
// bigRemoteViews.setOnClickPendingIntent(R.id.btn_notice, btnPendingIntent)
// smallRemoteViews.setOnClickPendingIntent(R.id.notice_btn, btnPendingIntent)
bigRemoteViews.setOnClickPendingIntent(R.id.fl_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) {
val num = SpUtils.getInstance().getInt("NotificationStayCount", 5)
val delay = SpUtils.getInstance().getInt("NotificationStayDelay", 4000).toLong()
val num = SpUtils.getInstance().getInt(NotificationStayCount, 5)
val delay = SpUtils.getInstance().getInt(NotificationStayDelay, 4000).toLong()
handlerThread = HandlerThread("NotificationHandlerThread")
handlerThread!!.start()
// 创建 Handler
......
package com.zxdemo.receiver
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
......@@ -6,6 +7,7 @@ import android.content.IntentFilter
import android.os.Build
import android.util.Log
import androidx.annotation.RequiresApi
import com.swiftcleaner.chovey.model.bean.Global.lockNotificationStatus
import com.zxdemo.ZxApplication
import com.zxdemo.notity.NotificationUtils
import com.zxdemo.utils.SpUtils
......@@ -52,44 +54,14 @@ class UnlockReceiver : BroadcastReceiver() {
Intent.ACTION_USER_PRESENT -> {
isLock = false
// 执行解锁后的操作,比如启动服务、发送通知等
var lockNotificationInterval =
SpUtils.getInstance().getInt("lockNotificationInterval")
val lastTime =
SpUtils.getInstance()
.getString("NOTICE_UNLOCK_TIME", "")
var current = LocalDateTime.now()
val lockNotificationStatus =
SpUtils.getInstance().getInt(lockNotificationStatus, 0)
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 (lockNotificationCount == 0 || count < lockNotificationCount) {
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"))
)
}
if (lockNotificationStatus == 1 && mIsScreenOn && !isLock) {
NotificationUtils.sendNotification(
ZxApplication.context, "showNotification", "receive_unlock"
)
}
}
......
package com.zxdemo.utils
import android.text.TextUtils
import android.util.Log
import com.android.installreferrer.api.InstallReferrerClient
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.http.ZxHttp
import org.json.JSONObject
......@@ -120,16 +124,16 @@ object InstallRefeerUtils {
fun getHttpConfig() {
ZxHttp.getHttpConfig {
var timerStatus = SpUtils.getInstance().getInt("timerStatus", 0)
var timerStatus = SpUtils.getInstance().getInt(timerStatus, 0)
Log.d("TAG", "timerStatus: $timerStatus")
if (timerStatus == 1) {
//打开定时器
var timerDelay =
SpUtils.getInstance().getInt("timerDelay", 3)
SpUtils.getInstance().getInt(timerDelay, 3)
var timerInterval =
SpUtils.getInstance().getInt("timerInterval", 7)
SpUtils.getInstance().getInt(timerInterval, 7)
GlobalTimer.scheduleTask(
timerDelay * 1000L,
timerDelay * 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