From 90d7d5be15dda8d4e8f8f7d76f136dcf1196fb50 Mon Sep 17 00:00:00 2001 From: Mihai Adrian Carare <48995920+mcarare@users.noreply.github.com> Date: Thu, 20 Aug 2020 23:10:04 +0300 Subject: [PATCH] [fenix] For https://github.com/mozilla-mobile/fenix/issues/13938: Implement nav to notification settings for all OS versions. (https://github.com/mozilla-mobile/fenix/pull/13972) --- .../java/org/mozilla/fenix/ext/Context.kt | 21 +++++++++++++++++++ .../fenix/settings/SettingsFragment.kt | 10 ++------- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/ext/Context.kt b/app/src/main/java/org/mozilla/fenix/ext/Context.kt index 1e3d3b7821..d106370260 100644 --- a/app/src/main/java/org/mozilla/fenix/ext/Context.kt +++ b/app/src/main/java/org/mozilla/fenix/ext/Context.kt @@ -6,6 +6,9 @@ package org.mozilla.fenix.ext import android.app.Activity import android.content.Context +import android.content.Intent +import android.os.Build +import android.provider.Settings import android.view.ContextThemeWrapper import android.view.View import android.view.ViewGroup @@ -89,3 +92,21 @@ fun Context.getStringWithArgSafe(@StringRes resId: Int, formatArg: String): Stri */ val Context.accessibilityManager: AccessibilityManager get() = getSystemService(Context.ACCESSIBILITY_SERVICE) as AccessibilityManager + +/** + * Used to navigate to system notifications settings for app + */ +fun Context.navigateToNotificationsSettings() { + val intent = Intent() + intent.let { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + it.action = Settings.ACTION_APP_NOTIFICATION_SETTINGS + it.putExtra(Settings.EXTRA_APP_PACKAGE, this.packageName) + } else { + it.action = "android.settings.APP_NOTIFICATION_SETTINGS" + it.putExtra("app_package", this.packageName) + it.putExtra("app_uid", this.applicationInfo.uid) + } + } + startActivity(intent) +} diff --git a/app/src/main/java/org/mozilla/fenix/settings/SettingsFragment.kt b/app/src/main/java/org/mozilla/fenix/settings/SettingsFragment.kt index 38dc05b83d..4c64a967d0 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/SettingsFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/SettingsFragment.kt @@ -36,6 +36,7 @@ import org.mozilla.fenix.ext.application import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.getPreferenceKey import org.mozilla.fenix.ext.metrics +import org.mozilla.fenix.ext.navigateToNotificationsSettings import org.mozilla.fenix.ext.requireComponents import org.mozilla.fenix.ext.settings import org.mozilla.fenix.ext.showToolbar @@ -271,10 +272,7 @@ class SettingsFragment : PreferenceFragmentCompat() { SettingsFragmentDirections.actionSettingsFragmentToDeleteBrowsingDataOnQuitFragment() } resources.getString(R.string.pref_key_notifications) -> { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - val intent = Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS) - startActivity(intent) - } + context?.navigateToNotificationsSettings() null } resources.getString(R.string.pref_key_customize) -> { @@ -359,10 +357,6 @@ class SettingsFragment : PreferenceFragmentCompat() { findPreference( getPreferenceKey(R.string.pref_key_debug_settings) )?.isVisible = requireContext().settings().showSecretDebugMenuThisSession - - findPreference( - getPreferenceKey(R.string.pref_key_notifications) - )?.isVisible = requireContext().settings().showNotificationsSetting } private fun getClickListenerForMakeDefaultBrowser(): Preference.OnPreferenceClickListener {