diff --git a/app/src/main/java/io/heckel/ntfy/msg/NotificationService.kt b/app/src/main/java/io/heckel/ntfy/msg/NotificationService.kt index a64811d..828ae4a 100644 --- a/app/src/main/java/io/heckel/ntfy/msg/NotificationService.kt +++ b/app/src/main/java/io/heckel/ntfy/msg/NotificationService.kt @@ -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) { 1 -> scope + PRIORITY_MIN 2 -> scope + PRIORITY_LOW diff --git a/app/src/main/java/io/heckel/ntfy/ui/DetailSettingsActivity.kt b/app/src/main/java/io/heckel/ntfy/ui/DetailSettingsActivity.kt index bba637c..fd81d2d 100644 --- a/app/src/main/java/io/heckel/ntfy/ui/DetailSettingsActivity.kt +++ b/app/src/main/java/io/heckel/ntfy/ui/DetailSettingsActivity.kt @@ -4,8 +4,10 @@ import android.content.ContentResolver import android.content.ClipData import android.content.ClipboardManager import android.content.Context +import android.content.Intent import android.net.Uri import android.os.Bundle +import android.provider.Settings import android.text.TextUtils import android.widget.Toast import androidx.activity.result.ActivityResultLauncher @@ -82,6 +84,7 @@ class DetailSettingsActivity : AppCompatActivity() { private lateinit var subscription: Subscription private lateinit var iconSetPref: Preference + private lateinit var openChannelsPref: Preference private lateinit var iconSetLauncher: ActivityResultLauncher private lateinit var iconRemovePref: Preference @@ -113,6 +116,7 @@ class DetailSettingsActivity : AppCompatActivity() { if (subscription.upAppId == null) { loadInstantPref() loadDedicatedChannelsPrefs() + loadOpenChannelsPrefs() loadMutedUntilPref() loadMinPriorityPref() loadAutoDeletePref() @@ -165,6 +169,8 @@ class DetailSettingsActivity : AppCompatActivity() { notificationService.deleteSubscriptionNotificationChannels(subscription) } + openChannelsPref.isVisible = value + } override fun getBoolean(key: String?, defValue: Boolean): Boolean { 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() { val prefId = context?.getString(R.string.detail_settings_notifications_muted_until_key) ?: return val pref: ListPreference? = findPreference(prefId) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e14386a..17fd9ae 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -352,6 +352,7 @@ Use dedicated channels Use dedicated notification channels for this subscription Use default notification channels + Configure dedicated channels Appearance Subscription icon Set an icon to be displayed in notifications diff --git a/app/src/main/res/values/values.xml b/app/src/main/res/values/values.xml index be34678..6155bcd 100644 --- a/app/src/main/res/values/values.xml +++ b/app/src/main/res/values/values.xml @@ -35,6 +35,7 @@ SubscriptionInstant SubscriptionMutedUntil SubscriptionDedicatedChannels + SubscriptionOpenChannels SubscriptionMinPriority SubscriptionAutoDelete SubscriptionAppearance diff --git a/app/src/main/res/xml/detail_preferences.xml b/app/src/main/res/xml/detail_preferences.xml index 651a373..3176a9e 100644 --- a/app/src/main/res/xml/detail_preferences.xml +++ b/app/src/main/res/xml/detail_preferences.xml @@ -18,6 +18,10 @@ app:key="@string/detail_settings_notifications_dedicated_channels_key" app:title="@string/detail_settings_notifications_dedicated_channels_title" app:isPreferenceVisible="false"/> +