Add setting to disable extension updated notification

it jumps to the notification setting
This commit is contained in:
Jays2Kings 2021-08-07 17:11:39 -04:00
parent a5fbd4dade
commit e24686f0cf
3 changed files with 47 additions and 2 deletions

View File

@ -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()
}
}
}

View File

@ -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)
}
}

View File

@ -291,8 +291,8 @@
<!-- Extensions -->
<string name="extensions">Extensions</string>
<string name="extension_updates">Extension Updates</string>
<string name="extension_updates_pending">Extension Updates pending</string>
<string name="extension_updates">Extension updates</string>
<string name="extension_updates_pending">Extension updates pending</string>
<string name="extension_info">Extension info</string>
<string name="filter_languages">Filter Languages</string>
<string name="obsolete">Obsolete</string>
@ -777,6 +777,7 @@
<string name="pref_global_search">Global search</string>
<string name="check_for_extension_updates">Check for extension updates</string>
<string name="auto_update_extensions">Auto-update extensions</string>
<string name="notify_extension_updated">Notify extension has been updated</string>
<string name="some_extensions_may_not_update">Some extensions may not be auto-updated if they were installed outside this app</string>
<string name="only_search_pinned_when">Only search pinned sources</string>
<string name="match_pinned_sources">Match pinned sources</string>