1
0
Fork 0

For #13938: Implement nav to notification settings for all OS versions. (#13972)

master
Mihai Adrian Carare 2020-08-20 23:10:04 +03:00 committed by GitHub
parent 61cb052156
commit ea688cce09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 8 deletions

View File

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

View File

@ -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<Preference>(
getPreferenceKey(R.string.pref_key_debug_settings)
)?.isVisible = requireContext().settings().showSecretDebugMenuThisSession
findPreference<Preference>(
getPreferenceKey(R.string.pref_key_notifications)
)?.isVisible = requireContext().settings().showNotificationsSetting
}
private fun getClickListenerForMakeDefaultBrowser(): Preference.OnPreferenceClickListener {