diff --git a/core/preference/api/src/commonMain/kotlin/net/thunderbird/core/preference/interaction/InteractionSettings.kt b/core/preference/api/src/commonMain/kotlin/net/thunderbird/core/preference/interaction/InteractionSettings.kt index ac9831e352f..ac9097f89a7 100644 --- a/core/preference/api/src/commonMain/kotlin/net/thunderbird/core/preference/interaction/InteractionSettings.kt +++ b/core/preference/api/src/commonMain/kotlin/net/thunderbird/core/preference/interaction/InteractionSettings.kt @@ -5,6 +5,8 @@ import net.thunderbird.core.common.action.SwipeActions const val INTERACTION_SETTINGS_DEFAULT_USE_VOLUME_KEYS_NAVIGATION = false val INTERACTION_SETTINGS_DEFAULT_MESSAGE_VIEW_POST_REMOVE_NAVIGATION = PostRemoveNavigation.ReturnToMessageList.name +val INTERACTION_SETTINGS_DEFAULT_MESSAGE_VIEW_POST_MARK_AS_UNREAD_NAVIGATION = + PostMarkAsUnreadNavigation.ReturnToMessageList val INTERACTION_SETTINGS_DEFAULT_SWIPE_ACTION = SwipeActions( leftAction = SwipeAction.ToggleRead, rightAction = SwipeAction.ToggleSelection, @@ -19,6 +21,8 @@ const val INTERACTION_SETTINGS_DEFAULT_CONFIRM_MARK_ALL_READ = true data class InteractionSettings( val useVolumeKeysForNavigation: Boolean = INTERACTION_SETTINGS_DEFAULT_USE_VOLUME_KEYS_NAVIGATION, val messageViewPostRemoveNavigation: String = INTERACTION_SETTINGS_DEFAULT_MESSAGE_VIEW_POST_REMOVE_NAVIGATION, + var messageViewPostMarkAsUnreadNavigation: PostMarkAsUnreadNavigation = + INTERACTION_SETTINGS_DEFAULT_MESSAGE_VIEW_POST_MARK_AS_UNREAD_NAVIGATION, val swipeActions: SwipeActions = INTERACTION_SETTINGS_DEFAULT_SWIPE_ACTION, val isConfirmDelete: Boolean = INTERACTION_SETTINGS_DEFAULT_CONFIRM_DELETE, val isConfirmDeleteStarred: Boolean = INTERACTION_SETTINGS_DEFAULT_CONFIRM_DELETE_STARRED, @@ -37,3 +41,12 @@ enum class PostRemoveNavigation { ShowPreviousMessage, ShowNextMessage, } + +/** + * The navigation actions that can be to performed after the user has marked a + * message as unread from the message view screen. + */ +enum class PostMarkAsUnreadNavigation { + StayOnCurrentMessage, + ReturnToMessageList, +} diff --git a/core/preference/api/src/commonMain/kotlin/net/thunderbird/core/preference/interaction/InteractionSettingsPreferenceManager.kt b/core/preference/api/src/commonMain/kotlin/net/thunderbird/core/preference/interaction/InteractionSettingsPreferenceManager.kt index a264642a7b6..818df9ce425 100644 --- a/core/preference/api/src/commonMain/kotlin/net/thunderbird/core/preference/interaction/InteractionSettingsPreferenceManager.kt +++ b/core/preference/api/src/commonMain/kotlin/net/thunderbird/core/preference/interaction/InteractionSettingsPreferenceManager.kt @@ -4,6 +4,7 @@ import net.thunderbird.core.preference.PreferenceManager const val KEY_USE_VOLUME_KEYS_FOR_NAVIGATION = "useVolumeKeysForNavigation" const val KEY_MESSAGE_VIEW_POST_DELETE_ACTION = "messageViewPostDeleteAction" +const val KEY_MESSAGE_VIEW_POST_MARK_AS_UNREAD_ACTION = "messageViewPostMarkAsReadAction" const val KEY_SWIPE_ACTION_LEFT = "swipeLeftAction" const val KEY_SWIPE_ACTION_RIGHT = "swipeRightAction" const val KEY_CONFIRM_DELETE = "confirmDelete" diff --git a/core/preference/impl/src/commonMain/kotlin/net/thunderbird/core/preference/interaction/DefaultInteractionSettingsPreferenceManager.kt b/core/preference/impl/src/commonMain/kotlin/net/thunderbird/core/preference/interaction/DefaultInteractionSettingsPreferenceManager.kt index 5fee7f01e97..4688fd8a3ca 100644 --- a/core/preference/impl/src/commonMain/kotlin/net/thunderbird/core/preference/interaction/DefaultInteractionSettingsPreferenceManager.kt +++ b/core/preference/impl/src/commonMain/kotlin/net/thunderbird/core/preference/interaction/DefaultInteractionSettingsPreferenceManager.kt @@ -51,6 +51,10 @@ class DefaultInteractionSettingsPreferenceManager( KEY_MESSAGE_VIEW_POST_DELETE_ACTION, INTERACTION_SETTINGS_DEFAULT_MESSAGE_VIEW_POST_REMOVE_NAVIGATION, ), + messageViewPostMarkAsUnreadNavigation = storage.getEnumOrDefault( + KEY_MESSAGE_VIEW_POST_MARK_AS_UNREAD_ACTION, + INTERACTION_SETTINGS_DEFAULT_MESSAGE_VIEW_POST_MARK_AS_UNREAD_NAVIGATION, + ), swipeActions = SwipeActions( leftAction = storage.getEnumOrDefault( key = KEY_SWIPE_ACTION_LEFT, @@ -87,6 +91,10 @@ class DefaultInteractionSettingsPreferenceManager( mutex.withLock { storageEditor.putBoolean(KEY_USE_VOLUME_KEYS_FOR_NAVIGATION, config.useVolumeKeysForNavigation) storageEditor.putString(KEY_MESSAGE_VIEW_POST_DELETE_ACTION, config.messageViewPostRemoveNavigation) + storageEditor.putEnum( + KEY_MESSAGE_VIEW_POST_MARK_AS_UNREAD_ACTION, + config.messageViewPostMarkAsUnreadNavigation, + ) storageEditor.putEnum(KEY_SWIPE_ACTION_LEFT, config.swipeActions.leftAction) storageEditor.putEnum(KEY_SWIPE_ACTION_RIGHT, config.swipeActions.rightAction) storageEditor.putBoolean(KEY_CONFIRM_DELETE, config.isConfirmDelete) diff --git a/legacy/core/src/main/java/com/fsck/k9/K9.kt b/legacy/core/src/main/java/com/fsck/k9/K9.kt index dd202578c09..2d0bf2ee8d0 100644 --- a/legacy/core/src/main/java/com/fsck/k9/K9.kt +++ b/legacy/core/src/main/java/com/fsck/k9/K9.kt @@ -113,9 +113,6 @@ object K9 : KoinComponent { @JvmStatic val fontSizes = FontSizes() - var messageViewPostMarkAsUnreadNavigation: PostMarkAsUnreadNavigation = - PostMarkAsUnreadNavigation.ReturnToMessageList - @get:Synchronized @set:Synchronized @JvmStatic @@ -172,9 +169,6 @@ object K9 : KoinComponent { @JvmStatic @Suppress("LongMethod") fun loadPrefs(storage: Storage) { - messageViewPostMarkAsUnreadNavigation = - storage.getEnum("messageViewPostMarkAsUnreadAction", PostMarkAsUnreadNavigation.ReturnToMessageList) - sortType = storage.getEnum("sortTypeEnum", AccountDefaultsProvider.DEFAULT_SORT_TYPE) val sortAscendingSetting = storage.getBoolean("sortAscending", AccountDefaultsProvider.DEFAULT_SORT_ASCENDING) @@ -199,8 +193,6 @@ object K9 : KoinComponent { @Suppress("LongMethod") internal fun save(editor: StorageEditor) { - editor.putEnum("messageViewPostMarkAsUnreadAction", messageViewPostMarkAsUnreadNavigation) - editor.putEnum("sortTypeEnum", sortType) editor.putBoolean("sortAscending", sortAscending[sortType] ?: false) @@ -254,13 +246,4 @@ object K9 : KoinComponent { const val MAX_SEND_ATTEMPTS = 5 const val MANUAL_WAKE_LOCK_TIMEOUT = 120000 - - /** - * The navigation actions that can be to performed after the user has marked a message as unread from the message - * view screen. - */ - enum class PostMarkAsUnreadNavigation { - StayOnCurrentMessage, - ReturnToMessageList, - } } diff --git a/legacy/core/src/main/java/com/fsck/k9/preferences/GeneralSettingsDescriptions.java b/legacy/core/src/main/java/com/fsck/k9/preferences/GeneralSettingsDescriptions.java index 6de2a3f845b..e2b9bb60303 100644 --- a/legacy/core/src/main/java/com/fsck/k9/preferences/GeneralSettingsDescriptions.java +++ b/legacy/core/src/main/java/com/fsck/k9/preferences/GeneralSettingsDescriptions.java @@ -12,7 +12,6 @@ import app.k9mail.feature.telemetry.api.TelemetryManager; import app.k9mail.legacy.di.DI; import com.fsck.k9.FontSizes; -import com.fsck.k9.K9.PostMarkAsUnreadNavigation; import com.fsck.k9.core.R; import com.fsck.k9.preferences.Settings.BooleanSetting; import com.fsck.k9.preferences.Settings.ColorSetting; @@ -43,6 +42,7 @@ import net.thunderbird.core.preference.SubTheme; import net.thunderbird.core.preference.display.coreSettings.DisplayCoreSettingsKt; import net.thunderbird.core.preference.display.visualSettings.message.list.MessageListDateTimeFormat; +import net.thunderbird.core.preference.interaction.PostMarkAsUnreadNavigation; import net.thunderbird.core.preference.interaction.PostRemoveNavigation; import net.thunderbird.core.preference.network.NetworkSettingsKt; import net.thunderbird.core.preference.storage.Storage; diff --git a/legacy/ui/legacy/src/main/java/com/fsck/k9/activity/MessageHomeActivity.kt b/legacy/ui/legacy/src/main/java/com/fsck/k9/activity/MessageHomeActivity.kt index aa6d64af347..b73ac4fb4b7 100644 --- a/legacy/ui/legacy/src/main/java/com/fsck/k9/activity/MessageHomeActivity.kt +++ b/legacy/ui/legacy/src/main/java/com/fsck/k9/activity/MessageHomeActivity.kt @@ -33,8 +33,6 @@ import app.k9mail.feature.launcher.FeatureLauncherActivity import app.k9mail.feature.launcher.FeatureLauncherTarget import app.k9mail.legacy.message.controller.MessageReference import com.fsck.k9.CoreResourceProvider -import com.fsck.k9.K9 -import com.fsck.k9.K9.PostMarkAsUnreadNavigation import com.fsck.k9.Preferences import com.fsck.k9.activity.compose.MessageActions import com.fsck.k9.controller.MessagingController @@ -63,6 +61,7 @@ import net.thunderbird.core.logging.Logger import net.thunderbird.core.logging.legacy.Log import net.thunderbird.core.preference.GeneralSettingsManager import net.thunderbird.core.preference.SplitViewMode +import net.thunderbird.core.preference.interaction.PostMarkAsUnreadNavigation import net.thunderbird.core.preference.interaction.PostRemoveNavigation import net.thunderbird.feature.account.storage.legacy.mapper.LegacyAccountDataMapper import net.thunderbird.feature.funding.api.FundingManager @@ -1289,7 +1288,7 @@ open class MessageHomeActivity : } override fun performNavigationAfterMarkAsUnread() { - when (K9.messageViewPostMarkAsUnreadNavigation) { + when (generalSettingsManager.getConfig().interaction.messageViewPostMarkAsUnreadNavigation) { PostMarkAsUnreadNavigation.StayOnCurrentMessage -> Unit PostMarkAsUnreadNavigation.ReturnToMessageList -> returnToMessageList() } diff --git a/legacy/ui/legacy/src/main/java/com/fsck/k9/ui/settings/general/GeneralSettingsDataStore.kt b/legacy/ui/legacy/src/main/java/com/fsck/k9/ui/settings/general/GeneralSettingsDataStore.kt index f85704b2ee8..ab66f39b0cd 100644 --- a/legacy/ui/legacy/src/main/java/com/fsck/k9/ui/settings/general/GeneralSettingsDataStore.kt +++ b/legacy/ui/legacy/src/main/java/com/fsck/k9/ui/settings/general/GeneralSettingsDataStore.kt @@ -3,7 +3,6 @@ package com.fsck.k9.ui.settings.general import androidx.preference.PreferenceDataStore import app.k9mail.feature.telemetry.api.TelemetryManager import com.fsck.k9.K9 -import com.fsck.k9.K9.PostMarkAsUnreadNavigation import com.fsck.k9.job.K9JobManager import com.fsck.k9.ui.base.AppLanguageManager import net.thunderbird.core.common.action.SwipeAction @@ -17,6 +16,7 @@ import net.thunderbird.core.preference.SplitViewMode import net.thunderbird.core.preference.SubTheme import net.thunderbird.core.preference.display.visualSettings.message.list.MessageListDateTimeFormat import net.thunderbird.core.preference.display.visualSettings.message.list.UiDensity +import net.thunderbird.core.preference.interaction.PostMarkAsUnreadNavigation import net.thunderbird.core.preference.update @Suppress("LargeClass") @@ -173,7 +173,7 @@ class GeneralSettingsDataStore( "swipe_action_left" -> swipeActionToString(interactionSettings.swipeActions.leftAction) "message_list_density" -> messageListSettings.uiDensity.toString() "post_remove_navigation" -> interactionSettings.messageViewPostRemoveNavigation - "post_mark_as_unread_navigation" -> K9.messageViewPostMarkAsUnreadNavigation.name + "post_mark_as_unread_navigation" -> interactionSettings.messageViewPostMarkAsUnreadNavigation.name else -> defValue } } @@ -215,10 +215,7 @@ class GeneralSettingsDataStore( "swipe_action_left" -> updateSwipeAction(value) { swipeAction -> copy(leftAction = swipeAction) } "message_list_density" -> updateMessageListDensity(value) "post_remove_navigation" -> setMessageViewPostRemoveNavigation(value) - "post_mark_as_unread_navigation" -> { - K9.messageViewPostMarkAsUnreadNavigation = PostMarkAsUnreadNavigation.valueOf(value) - } - + "post_mark_as_unread_navigation" -> setMessageViewPostMarkAsUnreadNavigation(value) else -> return } @@ -747,6 +744,17 @@ class GeneralSettingsDataStore( } } + private fun setMessageViewPostMarkAsUnreadNavigation(value: String) { + skipSaveSettings = true + generalSettingsManager.update { settings -> + settings.copy( + interaction = settings.interaction.copy( + messageViewPostMarkAsUnreadNavigation = PostMarkAsUnreadNavigation.valueOf(value), + ), + ) + } + } + private fun appThemeToString(theme: AppTheme) = when (theme) { AppTheme.LIGHT -> "light" AppTheme.DARK -> "dark"