Merge pull request #5534 from k9mail/notification_settings

Open system settings screens for notification channels directly
This commit is contained in:
cketti 2021-08-07 02:27:38 +02:00 committed by GitHub
commit 11c85745d0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 51 additions and 12 deletions

View file

@ -22,6 +22,8 @@ import com.fsck.k9.fragment.ConfirmationDialogFragment
import com.fsck.k9.fragment.ConfirmationDialogFragment.ConfirmationDialogFragmentListener
import com.fsck.k9.mailstore.FolderType
import com.fsck.k9.mailstore.RemoteFolder
import com.fsck.k9.notification.NotificationChannelManager
import com.fsck.k9.notification.NotificationChannelManager.ChannelType
import com.fsck.k9.ui.R
import com.fsck.k9.ui.endtoend.AutocryptKeyTransferActivity
import com.fsck.k9.ui.settings.onClick
@ -43,6 +45,7 @@ class AccountSettingsFragment : PreferenceFragmentCompat(), ConfirmationDialogFr
private val openPgpApiManager: OpenPgpApiManager by inject { parametersOf(this) }
private val messagingController: MessagingController by inject()
private val accountRemover: BackgroundAccountRemover by inject()
private val notificationChannelManager: NotificationChannelManager by inject()
private lateinit var dataStore: AccountSettingsDataStore
private val accountUuid: String by lazy {
@ -71,7 +74,7 @@ class AccountSettingsFragment : PreferenceFragmentCompat(), ConfirmationDialogFr
initializeAdvancedPushSettings(account)
initializeCryptoSettings(account)
initializeFolderSettings(account)
initializeNotifications()
initializeNotifications(account)
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
@ -176,10 +179,23 @@ class AccountSettingsFragment : PreferenceFragmentCompat(), ConfirmationDialogFr
}
}
private fun initializeNotifications() {
findPreference<Preference>(PREFERENCE_OPEN_NOTIFICATION_SETTINGS)?.let {
private fun initializeNotifications(account: Account) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
PRE_SDK26_NOTIFICATION_PREFERENCES.forEach { findPreference<Preference>(it).remove() }
}
findPreference<NotificationsPreference>(PREFERENCE_NOTIFICATION_SETTINGS_MESSAGES)?.let {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
PRE_SDK26_NOTIFICATION_PREFERENCES.forEach { findPreference<Preference>(it).remove() }
it.notificationChannelId = notificationChannelManager.getChannelIdFor(account, ChannelType.MESSAGES)
} else {
it.remove()
}
}
findPreference<NotificationsPreference>(PREFERENCE_NOTIFICATION_SETTINGS_MISCELLANEOUS)?.let {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
it.notificationChannelId =
notificationChannelManager.getChannelIdFor(account, ChannelType.MISCELLANEOUS)
} else {
it.remove()
}
@ -373,7 +389,8 @@ class AccountSettingsFragment : PreferenceFragmentCompat(), ConfirmationDialogFr
private const val PREFERENCE_SENT_FOLDER = "sent_folder"
private const val PREFERENCE_SPAM_FOLDER = "spam_folder"
private const val PREFERENCE_TRASH_FOLDER = "trash_folder"
private const val PREFERENCE_OPEN_NOTIFICATION_SETTINGS = "open_notification_settings"
private const val PREFERENCE_NOTIFICATION_SETTINGS_MESSAGES = "open_notification_settings_messages"
private const val PREFERENCE_NOTIFICATION_SETTINGS_MISCELLANEOUS = "open_notification_settings_miscellaneous"
private const val DELETE_POLICY_MARK_AS_READ = "MARK_AS_READ"
private val PRE_SDK26_NOTIFICATION_PREFERENCES = arrayOf(

View file

@ -3,8 +3,10 @@ package com.fsck.k9.ui.settings.account
import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.os.Build
import android.provider.Settings
import android.util.AttributeSet
import androidx.annotation.RequiresApi
import androidx.core.content.ContextCompat.startActivity
import androidx.core.content.res.TypedArrayUtils
import androidx.fragment.app.DialogFragment
@ -12,6 +14,7 @@ import androidx.preference.Preference
import com.takisoft.preferencex.PreferenceFragmentCompat
@SuppressLint("RestrictedApi")
@RequiresApi(Build.VERSION_CODES.O)
class NotificationsPreference
@JvmOverloads
constructor(
@ -24,8 +27,16 @@ constructor(
defStyleRes: Int = 0
) : Preference(context, attrs, defStyleAttr, defStyleRes) {
var notificationChannelId: String? = null
override fun onClick() {
val intent = Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS)
val intent = if (notificationChannelId == null) {
Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS)
} else {
Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS).apply {
putExtra(Settings.EXTRA_CHANNEL_ID, notificationChannelId)
}
}
intent.putExtra(Settings.EXTRA_APP_PACKAGE, this.context.packageName)
startActivity(this.context, intent, null)
}

View file

@ -521,8 +521,9 @@ Please submit bug reports, contribute new features and ask questions at
<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_mark_message_as_read_on_delete_label">Mark as read when deleted</string>
<string name="account_settings_mark_message_as_read_on_delete_summary">Mark a message as read when it is deleted</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_notification_channels_label">Notification channels</string>
<string name="account_settings_open_notification_settings_messages_summary">Configure notifications for new messages</string>
<string name="account_settings_open_notification_settings_miscellaneous_summary">Configure error and status notifications</string>
<string name="account_settings_show_pictures_label">Always show images</string>
<string name="account_settings_show_pictures_never">No</string>

View file

@ -382,11 +382,21 @@
android:summary="@string/account_settings_notify_sync_summary"
android:title="@string/account_settings_notify_sync_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" />
<PreferenceCategory
android:key="notification_channels"
android:title="@string/account_settings_notification_channels_label">
<com.fsck.k9.ui.settings.account.NotificationsPreference
android:key="open_notification_settings_messages"
android:summary="@string/account_settings_open_notification_settings_messages_summary"
android:title="@string/notification_channel_messages_title" />
<com.fsck.k9.ui.settings.account.NotificationsPreference
android:key="open_notification_settings_miscellaneous"
android:summary="@string/account_settings_open_notification_settings_miscellaneous_summary"
android:title="@string/notification_channel_miscellaneous_title" />
</PreferenceCategory>
</PreferenceScreen>
<PreferenceScreen