diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/notification/Notifications.kt b/app/src/main/java/eu/kanade/tachiyomi/data/notification/Notifications.kt index a154e2a64e..4411c593e4 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/notification/Notifications.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/notification/Notifications.kt @@ -7,6 +7,7 @@ import android.content.Context import android.os.Build import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.util.system.notificationManager +import androidx.core.app.NotificationManagerCompat /** * Class to manage the basic information of all the notifications used in the app. @@ -175,4 +176,18 @@ object Notifications { context.notificationManager.createNotificationChannels(newChannels) } } + + fun isNotificationChannelEnabled(context: Context, channelId: String?): Boolean { + return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + if (!channelId.isNullOrBlank()) { + val manager = + context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager + val channel = manager.getNotificationChannel(channelId) + return channel.importance != NotificationManager.IMPORTANCE_NONE + } + false + } else { + NotificationManagerCompat.from(context).areNotificationsEnabled() + } + } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBrowseController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBrowseController.kt index a73eccf158..b4380eb369 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBrowseController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBrowseController.kt @@ -1,8 +1,14 @@ package eu.kanade.tachiyomi.ui.setting +import android.app.Activity +import android.content.Intent import android.os.Build +import android.provider.Settings import androidx.preference.PreferenceScreen +import androidx.preference.SwitchPreferenceCompat +import eu.kanade.tachiyomi.BuildConfig import eu.kanade.tachiyomi.R +import eu.kanade.tachiyomi.data.notification.Notifications import eu.kanade.tachiyomi.data.preference.PreferenceKeys import eu.kanade.tachiyomi.data.preference.asImmediateFlow import eu.kanade.tachiyomi.data.preference.getOrDefault @@ -19,6 +25,7 @@ import uy.kohesive.injekt.injectLazy class SettingsBrowseController : SettingsController() { val sourceManager: SourceManager by injectLazy() + var updatedExtNotifPref: SwitchPreferenceCompat? = null override fun setupPreferenceScreen(screen: PreferenceScreen) = screen.apply { titleRes = R.string.sources @@ -49,6 +56,23 @@ class SettingsBrowseController : SettingsController() { defaultValue = AutoUpdaterJob.ONLY_ON_UNMETERED } infoPreference(R.string.some_extensions_may_not_update) + switchPreference { + key = "notify_ext_updated" + isPersistent = false + titleRes = R.string.notify_extension_updated + isChecked = Notifications.isNotificationChannelEnabled(context, Notifications.CHANNEL_EXT_UPDATED) + updatedExtNotifPref = this + onChange { + false + } + onClick { + val intent = Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS).apply { + putExtra(Settings.EXTRA_APP_PACKAGE, BuildConfig.APPLICATION_ID) + putExtra(Settings.EXTRA_CHANNEL_ID, Notifications.CHANNEL_EXT_UPDATED) + } + startActivity(intent) + } + } } } @@ -153,4 +177,9 @@ class SettingsBrowseController : SettingsController() { infoPreference(R.string.does_not_prevent_unofficial_nsfw) } } + + override fun onActivityResumed(activity: Activity) { + super.onActivityResumed(activity) + updatedExtNotifPref?.isChecked = Notifications.isNotificationChannelEnabled(activity, Notifications.CHANNEL_EXT_UPDATED) + } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a013d71ec1..bada17e9cf 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -291,8 +291,8 @@ Extensions - Extension Updates - Extension Updates pending + Extension updates + Extension updates pending Extension info Filter Languages Obsolete @@ -777,6 +777,7 @@ Global search Check for extension updates Auto-update extensions + Notify extension has been updated Some extensions may not be auto-updated if they were installed outside this app Only search pinned sources Match pinned sources