add preference to open notification settings if enabled

This commit is contained in:
Markus Doits 2022-12-06 21:55:00 +01:00
parent 522f05ed60
commit b63e5e8bfc
No known key found for this signature in database
GPG key ID: 4D406BBC615201D1
5 changed files with 28 additions and 1 deletions

View file

@ -413,7 +413,7 @@ class NotificationService(val context: Context) {
} }
} }
private fun toChannelId(scope: String, priority: Int): String { fun toChannelId(scope: String, priority: Int): String {
return when (priority) { return when (priority) {
1 -> scope + PRIORITY_MIN 1 -> scope + PRIORITY_MIN
2 -> scope + PRIORITY_LOW 2 -> scope + PRIORITY_LOW

View file

@ -4,8 +4,10 @@ import android.content.ContentResolver
import android.content.ClipData import android.content.ClipData
import android.content.ClipboardManager import android.content.ClipboardManager
import android.content.Context import android.content.Context
import android.content.Intent
import android.net.Uri import android.net.Uri
import android.os.Bundle import android.os.Bundle
import android.provider.Settings
import android.text.TextUtils import android.text.TextUtils
import android.widget.Toast import android.widget.Toast
import androidx.activity.result.ActivityResultLauncher import androidx.activity.result.ActivityResultLauncher
@ -82,6 +84,7 @@ class DetailSettingsActivity : AppCompatActivity() {
private lateinit var subscription: Subscription private lateinit var subscription: Subscription
private lateinit var iconSetPref: Preference private lateinit var iconSetPref: Preference
private lateinit var openChannelsPref: Preference
private lateinit var iconSetLauncher: ActivityResultLauncher<String> private lateinit var iconSetLauncher: ActivityResultLauncher<String>
private lateinit var iconRemovePref: Preference private lateinit var iconRemovePref: Preference
@ -113,6 +116,7 @@ class DetailSettingsActivity : AppCompatActivity() {
if (subscription.upAppId == null) { if (subscription.upAppId == null) {
loadInstantPref() loadInstantPref()
loadDedicatedChannelsPrefs() loadDedicatedChannelsPrefs()
loadOpenChannelsPrefs()
loadMutedUntilPref() loadMutedUntilPref()
loadMinPriorityPref() loadMinPriorityPref()
loadAutoDeletePref() loadAutoDeletePref()
@ -165,6 +169,8 @@ class DetailSettingsActivity : AppCompatActivity() {
notificationService.deleteSubscriptionNotificationChannels(subscription) notificationService.deleteSubscriptionNotificationChannels(subscription)
} }
openChannelsPref.isVisible = value
} }
override fun getBoolean(key: String?, defValue: Boolean): Boolean { override fun getBoolean(key: String?, defValue: Boolean): Boolean {
return subscription.dedicatedChannels return subscription.dedicatedChannels
@ -179,6 +185,21 @@ class DetailSettingsActivity : AppCompatActivity() {
} }
} }
private fun loadOpenChannelsPrefs() {
val prefId = context?.getString(R.string.detail_settings_notifications_open_channels_key) ?: return
openChannelsPref = findPreference(prefId) ?: return
openChannelsPref.isVisible = subscription.dedicatedChannels
openChannelsPref.preferenceDataStore = object : PreferenceDataStore() { } // Dummy store to protect from accidentally overwriting
openChannelsPref.onPreferenceClickListener = Preference.OnPreferenceClickListener { _ ->
val channelId = notificationService.toChannelId(notificationService.dedicatedNotificationScope(subscription), 3)
val settingsIntent = Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.putExtra(Settings.EXTRA_APP_PACKAGE, requireContext().applicationContext.packageName)
startActivity(settingsIntent);
true
}
}
private fun loadMutedUntilPref() { private fun loadMutedUntilPref() {
val prefId = context?.getString(R.string.detail_settings_notifications_muted_until_key) ?: return val prefId = context?.getString(R.string.detail_settings_notifications_muted_until_key) ?: return
val pref: ListPreference? = findPreference(prefId) val pref: ListPreference? = findPreference(prefId)

View file

@ -352,6 +352,7 @@
<string name="detail_settings_notifications_dedicated_channels_title">Use dedicated channels</string> <string name="detail_settings_notifications_dedicated_channels_title">Use dedicated channels</string>
<string name="detail_settings_notifications_dedicated_channels_summay_on">Use dedicated notification channels for this subscription</string> <string name="detail_settings_notifications_dedicated_channels_summay_on">Use dedicated notification channels for this subscription</string>
<string name="detail_settings_notifications_dedicated_channels_summay_off">Use default notification channels</string> <string name="detail_settings_notifications_dedicated_channels_summay_off">Use default notification channels</string>
<string name="detail_settings_notifications_open_channels_title">Configure dedicated channels</string>
<string name="detail_settings_appearance_header">Appearance</string> <string name="detail_settings_appearance_header">Appearance</string>
<string name="detail_settings_appearance_icon_set_title">Subscription icon</string> <string name="detail_settings_appearance_icon_set_title">Subscription icon</string>
<string name="detail_settings_appearance_icon_set_summary">Set an icon to be displayed in notifications</string> <string name="detail_settings_appearance_icon_set_summary">Set an icon to be displayed in notifications</string>

View file

@ -35,6 +35,7 @@
<string name="detail_settings_notifications_instant_key" translatable="false">SubscriptionInstant</string> <string name="detail_settings_notifications_instant_key" translatable="false">SubscriptionInstant</string>
<string name="detail_settings_notifications_muted_until_key" translatable="false">SubscriptionMutedUntil</string> <string name="detail_settings_notifications_muted_until_key" translatable="false">SubscriptionMutedUntil</string>
<string name="detail_settings_notifications_dedicated_channels_key" translatable="false">SubscriptionDedicatedChannels</string> <string name="detail_settings_notifications_dedicated_channels_key" translatable="false">SubscriptionDedicatedChannels</string>
<string name="detail_settings_notifications_open_channels_key" translatable="false">SubscriptionOpenChannels</string>
<string name="detail_settings_notifications_min_priority_key" translatable="false">SubscriptionMinPriority</string> <string name="detail_settings_notifications_min_priority_key" translatable="false">SubscriptionMinPriority</string>
<string name="detail_settings_notifications_auto_delete_key" translatable="false">SubscriptionAutoDelete</string> <string name="detail_settings_notifications_auto_delete_key" translatable="false">SubscriptionAutoDelete</string>
<string name="detail_settings_appearance_header_key" translatable="false">SubscriptionAppearance</string> <string name="detail_settings_appearance_header_key" translatable="false">SubscriptionAppearance</string>

View file

@ -18,6 +18,10 @@
app:key="@string/detail_settings_notifications_dedicated_channels_key" app:key="@string/detail_settings_notifications_dedicated_channels_key"
app:title="@string/detail_settings_notifications_dedicated_channels_title" app:title="@string/detail_settings_notifications_dedicated_channels_title"
app:isPreferenceVisible="false"/> app:isPreferenceVisible="false"/>
<Preference
app:key="@string/detail_settings_notifications_open_channels_key"
app:title="@string/detail_settings_notifications_open_channels_title"
app:isPreferenceVisible="false"/>
<ListPreference <ListPreference
app:key="@string/detail_settings_notifications_min_priority_key" app:key="@string/detail_settings_notifications_min_priority_key"
app:title="@string/settings_notifications_min_priority_title" app:title="@string/settings_notifications_min_priority_title"