Commit 294472a7 authored by 周文华's avatar 周文华

【修复】1.修复循环获取通知栏事件id导致的崩溃。2.修复空数据导致的崩溃。3.修复部分机型跳转页缺失导致的崩溃。

parent 0145597a
...@@ -97,7 +97,10 @@ object NotificationUiUtil { ...@@ -97,7 +97,10 @@ object NotificationUiUtil {
val count = AppPreferences.getInstance().getString(popup_count, "20").toInt() val count = AppPreferences.getInstance().getString(popup_count, "20").toInt()
if (dayPopupCount > count) { if (dayPopupCount > count) {
LogEx.logDebug("canSendNotification", "count") LogEx.logDebug("canSendNotification", "count")
EventUtils.event("Notification_Error", "dayPopupCount=$dayPopupCount count=$count where=$where actionId=$actionId") EventUtils.event(
"Notification_Error",
"dayPopupCount=$dayPopupCount count=$count where=$where actionId=$actionId"
)
return false return false
} }
//判断是否在时间区域 //判断是否在时间区域
...@@ -106,8 +109,14 @@ object NotificationUiUtil { ...@@ -106,8 +109,14 @@ object NotificationUiUtil {
val calendar = Calendar.getInstance() val calendar = Calendar.getInstance()
val currentHour = calendar.get(Calendar.HOUR_OF_DAY) val currentHour = calendar.get(Calendar.HOUR_OF_DAY)
if (currentHour !in start until end) { if (currentHour !in start until end) {
LogEx.logDebug("canSendNotification", "start-end currentHour=$currentHour start=$start end=$end") LogEx.logDebug(
EventUtils.event("Notification_Error", "start=$start end=$end currentHour=$currentHour where=$where actionId=$actionId") "canSendNotification",
"start-end currentHour=$currentHour start=$start end=$end"
)
EventUtils.event(
"Notification_Error",
"start=$start end=$end currentHour=$currentHour where=$where actionId=$actionId"
)
return false return false
} }
...@@ -124,8 +133,14 @@ object NotificationUiUtil { ...@@ -124,8 +133,14 @@ object NotificationUiUtil {
} }
val passedTime = System.currentTimeMillis() - lastPopupTime val passedTime = System.currentTimeMillis() - lastPopupTime
if (passedTime < interval * 60 * 1000L) { if (passedTime < interval * 60 * 1000L) {
EventUtils.event("Notification_Error", "where=$where actionId=$actionId interval=$interval passedTime=$passedTime") EventUtils.event(
LogEx.logDebug("canSendNotification", "interval where=$where passedTime=$passedTime interval=$interval") "Notification_Error",
"where=$where actionId=$actionId interval=$interval passedTime=$passedTime"
)
LogEx.logDebug(
"canSendNotification",
"interval where=$where passedTime=$passedTime interval=$interval"
)
return false return false
} }
...@@ -135,7 +150,11 @@ object NotificationUiUtil { ...@@ -135,7 +150,11 @@ object NotificationUiUtil {
var hoverActionId = "" var hoverActionId = ""
@SuppressLint("RemoteViewLayout") @SuppressLint("RemoteViewLayout")
fun sendNotificationIfCan(context: Context, where: String = "", actionId: String = getNextActionId()) { fun sendNotificationIfCan(
context: Context,
where: String = "",
actionId: String = getNextActionId()
) {
if (!canSendNotification(where, actionId)) return if (!canSendNotification(where, actionId)) return
//发送通知 //发送通知
...@@ -155,8 +174,10 @@ object NotificationUiUtil { ...@@ -155,8 +174,10 @@ object NotificationUiUtil {
} }
fun setActionNotification(context: Context, actionId: String) { fun setActionNotification(context: Context, actionId: String) {
val bigRemoteViews = RemoteViews(MyApplication.context.packageName, R.layout.notification_message) val bigRemoteViews =
val smallRemoteViews = RemoteViews(MyApplication.context.packageName, R.layout.notification_message) RemoteViews(MyApplication.context.packageName, R.layout.notification_message)
val smallRemoteViews =
RemoteViews(MyApplication.context.packageName, R.layout.notification_message)
val intent = Intent(context, SplashActivity::class.java) val intent = Intent(context, SplashActivity::class.java)
intent.putExtra("actionId", actionId) intent.putExtra("actionId", actionId)
...@@ -213,19 +234,26 @@ object NotificationUiUtil { ...@@ -213,19 +234,26 @@ object NotificationUiUtil {
NOTIFICATION_ACTION_APP_PROCESS -> { NOTIFICATION_ACTION_APP_PROCESS -> {
val pair = MyApplication.context.ramPair() val pair = MyApplication.context.ramPair()
val percent =if(pair.second>0) (pair.first * 100 / pair.second).toInt() else 0 val percent = if (pair.second > 0) (pair.first * 100 / pair.second).toInt() else 0
val desc = "Memory is $percent% used" val desc = "Memory is $percent% used"
val smallRemoteViewsVar = RemoteViews(context.packageName, R.layout.notification_memory_small_1) val smallRemoteViewsVar =
RemoteViews(context.packageName, R.layout.notification_memory_small_1)
smallRemoteViewsVar.setProgressBar(R.id.progress_bar, percent, 100, false) smallRemoteViewsVar.setProgressBar(R.id.progress_bar, percent, 100, false)
smallRemoteViewsVar.setTextViewText(R.id.tv_desc, desc) smallRemoteViewsVar.setTextViewText(R.id.tv_desc, desc)
val btnRequestCode = Random.nextInt(1000) val btnRequestCode = Random.nextInt(1000)
smallRemoteViewsVar.setOnClickPendingIntent( smallRemoteViewsVar.setOnClickPendingIntent(
R.id.tv_btn, R.id.tv_btn,
PendingIntent.getActivity(context, btnRequestCode, intent, PendingIntent.FLAG_IMMUTABLE) PendingIntent.getActivity(
context,
btnRequestCode,
intent,
PendingIntent.FLAG_IMMUTABLE
)
) )
val bigRemoteViewsVar = RemoteViews(context.packageName, R.layout.notification_memory_big) val bigRemoteViewsVar =
RemoteViews(context.packageName, R.layout.notification_memory_big)
sendCustomNotification(context, intent, bigRemoteViewsVar, smallRemoteViewsVar) sendCustomNotification(context, intent, bigRemoteViewsVar, smallRemoteViewsVar)
} }
...@@ -235,10 +263,12 @@ object NotificationUiUtil { ...@@ -235,10 +263,12 @@ object NotificationUiUtil {
if (size == 0L) { if (size == 0L) {
size = Random.nextLong(1024 * 5, 1024 * 10) size = Random.nextLong(1024 * 5, 1024 * 10)
} }
val bigRemoteViewsVar = RemoteViews(context.packageName, R.layout.notification_junk_big) val bigRemoteViewsVar =
RemoteViews(context.packageName, R.layout.notification_junk_big)
bigRemoteViewsVar.setTextViewText(R.id.tv_size, size.toFormatSize()) bigRemoteViewsVar.setTextViewText(R.id.tv_size, size.toFormatSize())
val smallRemoteViewsVar = RemoteViews(context.packageName, R.layout.notification_junk_small) val smallRemoteViewsVar =
RemoteViews(context.packageName, R.layout.notification_junk_small)
smallRemoteViewsVar.setTextViewText(R.id.tv_size, size.toFormatSize()) smallRemoteViewsVar.setTextViewText(R.id.tv_size, size.toFormatSize())
sendCustomNotification(context, intent, bigRemoteViewsVar, smallRemoteViewsVar) sendCustomNotification(context, intent, bigRemoteViewsVar, smallRemoteViewsVar)
...@@ -249,11 +279,15 @@ object NotificationUiUtil { ...@@ -249,11 +279,15 @@ object NotificationUiUtil {
if (weatherBean.list.isEmpty()) return if (weatherBean.list.isEmpty()) return
val subBean = weatherBean.list[0] val subBean = weatherBean.list[0]
val smallRemoteViewsVar = RemoteViews(context.packageName, R.layout.notification_weather_small) val smallRemoteViewsVar =
RemoteViews(context.packageName, R.layout.notification_weather_small)
smallRemoteViewsVar.setTextViewText(R.id.tv_city, weatherBean.city) smallRemoteViewsVar.setTextViewText(R.id.tv_city, weatherBean.city)
val min = subBean.tempMin.toInt() val min = subBean.tempMin.toInt()
val max = subBean.tempMax.toInt() val max = subBean.tempMax.toInt()
smallRemoteViewsVar.setTextViewText(R.id.tv_wendu_now, Random.nextInt(min, max).toString()) smallRemoteViewsVar.setTextViewText(
R.id.tv_wendu_now,
Random.nextInt(min, max).toString()
)
val icon = when (WeatherUtils.getWeatherType(subBean.iconDay.toInt())) { val icon = when (WeatherUtils.getWeatherType(subBean.iconDay.toInt())) {
"Sunny day" -> R.mipmap.d_qing "Sunny day" -> R.mipmap.d_qing
"Cloudy day" -> R.mipmap.d_yin "Cloudy day" -> R.mipmap.d_yin
...@@ -267,7 +301,8 @@ object NotificationUiUtil { ...@@ -267,7 +301,8 @@ object NotificationUiUtil {
smallRemoteViewsVar.setImageViewResource(R.id.iv_weather, icon) smallRemoteViewsVar.setImageViewResource(R.id.iv_weather, icon)
smallRemoteViewsVar.setTextViewText(R.id.tv_wendu_range, "$min℃/$max℃") smallRemoteViewsVar.setTextViewText(R.id.tv_wendu_range, "$min℃/$max℃")
val bigRemoteViewsVar = RemoteViews(context.packageName, R.layout.notification_weather_big) val bigRemoteViewsVar =
RemoteViews(context.packageName, R.layout.notification_weather_big)
bigRemoteViewsVar.setImageViewResource(R.id.iv_weather_11h, icon) bigRemoteViewsVar.setImageViewResource(R.id.iv_weather_11h, icon)
bigRemoteViewsVar.setImageViewResource(R.id.iv_weather_14h, icon) bigRemoteViewsVar.setImageViewResource(R.id.iv_weather_14h, icon)
bigRemoteViewsVar.setImageViewResource(R.id.iv_weather_17h, icon) bigRemoteViewsVar.setImageViewResource(R.id.iv_weather_17h, icon)
...@@ -275,15 +310,39 @@ object NotificationUiUtil { ...@@ -275,15 +310,39 @@ object NotificationUiUtil {
bigRemoteViewsVar.setImageViewResource(R.id.iv_weather_23h, icon) bigRemoteViewsVar.setImageViewResource(R.id.iv_weather_23h, icon)
bigRemoteViewsVar.setImageViewResource(R.id.iv_weather, icon) bigRemoteViewsVar.setImageViewResource(R.id.iv_weather, icon)
bigRemoteViewsVar.setTextViewText(R.id.tv_wendu_11h, Random.nextInt(min, max).toString()) bigRemoteViewsVar.setTextViewText(
bigRemoteViewsVar.setTextViewText(R.id.tv_wendu_14h, Random.nextInt(min, max).toString()) R.id.tv_wendu_11h,
bigRemoteViewsVar.setTextViewText(R.id.tv_wendu_17h, Random.nextInt(min, max).toString()) Random.nextInt(min, max).toString()
bigRemoteViewsVar.setTextViewText(R.id.tv_wendu_20h, Random.nextInt(min, max).toString()) )
bigRemoteViewsVar.setTextViewText(R.id.tv_wendu_23h, Random.nextInt(min, max).toString()) bigRemoteViewsVar.setTextViewText(
R.id.tv_wendu_14h,
Random.nextInt(min, max).toString()
)
bigRemoteViewsVar.setTextViewText(
R.id.tv_wendu_17h,
Random.nextInt(min, max).toString()
)
bigRemoteViewsVar.setTextViewText(
R.id.tv_wendu_20h,
Random.nextInt(min, max).toString()
)
bigRemoteViewsVar.setTextViewText(
R.id.tv_wendu_23h,
Random.nextInt(min, max).toString()
)
bigRemoteViewsVar.setTextViewText(R.id.tv_wendu_now, Random.nextInt(min, max).toString()) bigRemoteViewsVar.setTextViewText(
bigRemoteViewsVar.setTextViewText(R.id.tv_day_desc, if (isDayOrNight()) subBean.textDay else subBean.textNight) R.id.tv_wendu_now,
bigRemoteViewsVar.setTextViewText(R.id.tv_weather_info, "$min℃/$max℃ ${formatATime()}") Random.nextInt(min, max).toString()
)
bigRemoteViewsVar.setTextViewText(
R.id.tv_day_desc,
if (isDayOrNight()) subBean.textDay else subBean.textNight
)
bigRemoteViewsVar.setTextViewText(
R.id.tv_weather_info,
"$min℃/$max℃ ${formatATime()}"
)
sendCustomNotification(context, intent, bigRemoteViewsVar, smallRemoteViewsVar) sendCustomNotification(context, intent, bigRemoteViewsVar, smallRemoteViewsVar)
} }
...@@ -302,7 +361,8 @@ object NotificationUiUtil { ...@@ -302,7 +361,8 @@ object NotificationUiUtil {
smallRemoteViews: RemoteViews, smallRemoteViews: RemoteViews,
) { ) {
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager val notificationManager =
context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
//创建channel //创建channel
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
...@@ -332,7 +392,8 @@ object NotificationUiUtil { ...@@ -332,7 +392,8 @@ object NotificationUiUtil {
.setContentText("notification") .setContentText("notification")
val requestCode = Random.nextInt(1000) val requestCode = Random.nextInt(1000)
val pendingIntent = PendingIntent.getActivity(context, requestCode, intent, PendingIntent.FLAG_IMMUTABLE) val pendingIntent =
PendingIntent.getActivity(context, requestCode, intent, PendingIntent.FLAG_IMMUTABLE)
builder.setContentIntent(pendingIntent) builder.setContentIntent(pendingIntent)
.setPriority(NotificationCompat.PRIORITY_MAX) .setPriority(NotificationCompat.PRIORITY_MAX)
.setAutoCancel(true) .setAutoCancel(true)
...@@ -366,16 +427,15 @@ object NotificationUiUtil { ...@@ -366,16 +427,15 @@ object NotificationUiUtil {
NOTIFICATION_ACTION_WEATHER NOTIFICATION_ACTION_WEATHER
) )
var actionIdList = arrayListOf<String>() private var nextIdIndex = -1
@Synchronized
fun getNextActionId(): String { fun getNextActionId(): String {
if (actionIdList.isEmpty()) { if (nextIdIndex in 0..looper_actionId.size - 2) {
actionIdList.addAll(looper_actionId) nextIdIndex++
} } else {
val next = actionIdList[0] nextIdIndex = 0
actionIdList.removeAt(0)
if (BuildConfig.DEBUG) {
// return NOTIFICATION_ACTION_WEATHER
} }
return next return looper_actionId[nextIdIndex]
} }
} }
\ No newline at end of file
...@@ -116,6 +116,7 @@ class ColorProgress : View { ...@@ -116,6 +116,7 @@ class ColorProgress : View {
fun animateProgress(list: List<ProgressBean>) { fun animateProgress(list: List<ProgressBean>) {
listProgressBean = list listProgressBean = list
if(list.isEmpty())return
val totalAngle = list.maxOf { it.sweepAngle } val totalAngle = list.maxOf { it.sweepAngle }
val progressAnimator = ValueAnimator.ofFloat(0f, totalAngle) val progressAnimator = ValueAnimator.ofFloat(0f, totalAngle)
progressAnimator.interpolator = LinearInterpolator() // 平滑插值器 progressAnimator.interpolator = LinearInterpolator() // 平滑插值器
......
...@@ -2,6 +2,7 @@ package com.base.pdfviewerscannerwhite.utils ...@@ -2,6 +2,7 @@ package com.base.pdfviewerscannerwhite.utils
import android.Manifest import android.Manifest
import android.app.Activity import android.app.Activity
import android.content.ActivityNotFoundException
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.pm.PackageManager import android.content.pm.PackageManager
...@@ -18,15 +19,20 @@ object PermissionUtils { ...@@ -18,15 +19,20 @@ object PermissionUtils {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
Environment.isExternalStorageManager() Environment.isExternalStorageManager()
} else { } else {
val readPermission = ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) val readPermission =
val writePermission = ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE)
val writePermission =
ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
return readPermission == PackageManager.PERMISSION_GRANTED && writePermission == PackageManager.PERMISSION_GRANTED; return readPermission == PackageManager.PERMISSION_GRANTED && writePermission == PackageManager.PERMISSION_GRANTED;
} }
} }
fun Context.checkNotificationPermission(): Boolean { fun Context.checkNotificationPermission(): Boolean {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
ActivityCompat.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS) == PackageManager.PERMISSION_GRANTED ActivityCompat.checkSelfPermission(
this,
Manifest.permission.POST_NOTIFICATIONS
) == PackageManager.PERMISSION_GRANTED
} else { } else {
return true return true
} }
...@@ -38,7 +44,10 @@ object PermissionUtils { ...@@ -38,7 +44,10 @@ object PermissionUtils {
fun Activity.userDenyNotificationPermission(): Boolean { fun Activity.userDenyNotificationPermission(): Boolean {
val shouldShowRationale = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { val shouldShowRationale = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.POST_NOTIFICATIONS) ActivityCompat.shouldShowRequestPermissionRationale(
this,
Manifest.permission.POST_NOTIFICATIONS
)
} else { } else {
true true
} }
...@@ -55,20 +64,28 @@ object PermissionUtils { ...@@ -55,20 +64,28 @@ object PermissionUtils {
jumpAction: (() -> Unit)? = null, jumpAction: (() -> Unit)? = null,
result: (flag: Boolean) -> Unit result: (flag: Boolean) -> Unit
) { ) {
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
val intent = val intent =
Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION) Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION)
intent.addCategory("android.intent.category.DEFAULT") intent.addCategory("android.intent.category.DEFAULT")
intent.data = Uri.parse("package:${packageName}") intent.data = Uri.parse("package:${packageName}")
jumpAction?.invoke() jumpAction?.invoke()
launcher.launch(intent) { launcher.launch(intent) {
result.invoke(checkStorePermission()) result.invoke(checkStorePermission())
} }
} else { } else {
launcher.launch(arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE)) { map -> launcher.launch(
result(map.values.all { it }) arrayOf(
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE
)
) { map ->
result(map.values.all { it })
}
} }
} catch (_: ActivityNotFoundException) {
} }
} }
......
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