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

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

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