Fix update all crash on A11 and under

Fixes #1170
This commit is contained in:
Jays2Kings 2022-04-03 18:06:27 -04:00
parent 2c7b44fea2
commit 128cbc9687
2 changed files with 24 additions and 54 deletions

View file

@ -6,9 +6,7 @@ import android.app.NotificationManager
import android.content.Context import android.content.Context
import android.os.Build import android.os.Build
import androidx.core.app.NotificationManagerCompat import androidx.core.app.NotificationManagerCompat
import androidx.preference.PreferenceManager
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.PreferenceKeys
import eu.kanade.tachiyomi.util.system.notificationManager import eu.kanade.tachiyomi.util.system.notificationManager
/** /**
@ -179,33 +177,7 @@ object Notifications {
CHANNEL_INCOGNITO_MODE, CHANNEL_INCOGNITO_MODE,
context.getString(R.string.incognito_mode), context.getString(R.string.incognito_mode),
NotificationManager.IMPORTANCE_LOW NotificationManager.IMPORTANCE_LOW
) ),
)
context.notificationManager.createNotificationChannels(channels)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
addAutoUpdateExtensionsNotifications(true, context)
context.notificationManager.createNotificationChannel(
NotificationChannel(
CHANNEL_UPDATED,
context.getString(R.string.update_completed),
NotificationManager.IMPORTANCE_DEFAULT
).apply {
setShowBadge(false)
}
)
} else {
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
addAutoUpdateExtensionsNotifications(
prefs.getBoolean(PreferenceKeys.useShizuku, false),
context
)
}
}
fun addAutoUpdateExtensionsNotifications(canAutoUpdate: Boolean, context: Context) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return
if (canAutoUpdate) {
val newChannels = listOf(
NotificationChannel( NotificationChannel(
CHANNEL_EXT_PROGRESS, CHANNEL_EXT_PROGRESS,
context.getString(R.string.updating_extensions), context.getString(R.string.updating_extensions),
@ -221,13 +193,16 @@ object Notifications {
NotificationManager.IMPORTANCE_DEFAULT NotificationManager.IMPORTANCE_DEFAULT
).apply { ).apply {
group = GROUP_EXTENSION_UPDATES group = GROUP_EXTENSION_UPDATES
},
NotificationChannel(
CHANNEL_UPDATED,
context.getString(R.string.update_completed),
NotificationManager.IMPORTANCE_DEFAULT
).apply {
setShowBadge(false)
} }
) )
context.notificationManager.createNotificationChannels(newChannels) context.notificationManager.createNotificationChannels(channels)
} else {
context.notificationManager.deleteNotificationChannel(CHANNEL_EXT_PROGRESS)
context.notificationManager.deleteNotificationChannel(CHANNEL_EXT_UPDATED)
}
} }
fun isNotificationChannelEnabled(context: Context, channelId: String?): Boolean { fun isNotificationChannelEnabled(context: Context, channelId: String?): Boolean {

View file

@ -4,7 +4,6 @@ import android.annotation.SuppressLint
import android.app.Dialog import android.app.Dialog
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.os.PowerManager import android.os.PowerManager
import android.provider.Settings import android.provider.Settings
@ -22,7 +21,6 @@ import eu.kanade.tachiyomi.data.download.DownloadManager
import eu.kanade.tachiyomi.data.download.DownloadProvider import eu.kanade.tachiyomi.data.download.DownloadProvider
import eu.kanade.tachiyomi.data.library.LibraryUpdateService import eu.kanade.tachiyomi.data.library.LibraryUpdateService
import eu.kanade.tachiyomi.data.library.LibraryUpdateService.Target import eu.kanade.tachiyomi.data.library.LibraryUpdateService.Target
import eu.kanade.tachiyomi.data.notification.Notifications
import eu.kanade.tachiyomi.data.preference.PreferenceKeys import eu.kanade.tachiyomi.data.preference.PreferenceKeys
import eu.kanade.tachiyomi.extension.ShizukuInstaller import eu.kanade.tachiyomi.extension.ShizukuInstaller
import eu.kanade.tachiyomi.network.NetworkHelper import eu.kanade.tachiyomi.network.NetworkHelper
@ -235,9 +233,6 @@ class SettingsAdvancedController : SettingsController() {
.show() .show()
false false
} else { } else {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
Notifications.addAutoUpdateExtensionsNotifications(it, context)
}
true true
} }
} }