Add an item that opens system notification settings

This item is displayed only on Oreo or higher and is hidden in previous
versions of Android.
This commit is contained in:
Wiktor Kwapisiewicz 2018-11-28 15:35:30 +01:00
parent c9f3d57071
commit d9ddba4e60
3 changed files with 44 additions and 0 deletions

View file

@ -0,0 +1,37 @@
package com.fsck.k9.ui.settings.account
import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.provider.Settings
import android.support.v4.app.DialogFragment
import android.support.v4.content.ContextCompat.startActivity
import android.support.v4.content.res.TypedArrayUtils
import android.support.v7.preference.Preference
import android.util.AttributeSet
import com.takisoft.fix.support.v7.preference.PreferenceFragmentCompat
@SuppressLint("RestrictedApi")
class NotificationsPreference
@JvmOverloads
constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = TypedArrayUtils.getAttr(context, android.support.v7.preference.R.attr.preferenceStyle,
android.R.attr.preferenceStyle),
defStyleRes: Int = 0
) : Preference(context, attrs, defStyleAttr, defStyleRes) {
override fun onClick() {
val intent = Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS)
intent.putExtra(Settings.EXTRA_APP_PACKAGE, this.context.packageName)
startActivity(this.context, intent, null)
}
companion object {
init {
PreferenceFragmentCompat.registerPreferenceFragment(
NotificationsPreference::class.java, DialogFragment::class.java)
}
}
}

View file

@ -558,6 +558,8 @@ Please submit bug reports, contribute new features and ask questions at
<string name="account_settings_notification_opens_unread_summary">Searches for unread messages when Notification is opened</string>
<string name="account_settings_mark_message_as_read_on_view_label">Mark as read when opened</string>
<string name="account_settings_mark_message_as_read_on_view_summary">Mark a message as read when it is opened for viewing</string>
<string name="account_settings_notification_open_system_notifications_label">Notification settings</string>
<string name="account_settings_notification_open_system_notifications_summary">Open system notification settings</string>
<string name="account_settings_show_pictures_label">Always show images</string>
<string name="account_settings_show_pictures_never">No</string>

View file

@ -392,6 +392,11 @@
android:summary="@string/account_settings_notification_opens_unread_summary"
android:title="@string/account_settings_notification_opens_unread_label" />
<com.fsck.k9.ui.settings.account.NotificationsPreference
android:key="open_notification_settings"
android:summary="@string/account_settings_notification_open_system_notifications_summary"
android:title="@string/account_settings_notification_open_system_notifications_label" />
</PreferenceScreen>
<PreferenceScreen