Skip to content

Commit f603622

Browse files
authored
Merge pull request #9834 from shamim-emon/fix-issue-9833
Migrate messageViewPostRemoveNavigation to PreferenceDataStore
2 parents 3f69468 + ea1ecca commit f603622

7 files changed

Lines changed: 37 additions & 24 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
package net.thunderbird.core.preference.interaction
22

33
const val INTERACTION_SETTINGS_DEFAULT_USE_VOLUME_KEYS_NAVIGATION = false
4+
val INTERACTION_SETTINGS_DEFAULT_MESSAGE_VIEW_POST_REMOVE_NAVIGATION = PostRemoveNavigation.ReturnToMessageList.name
45

56
data class InteractionSettings(
67
val useVolumeKeysForNavigation: Boolean = INTERACTION_SETTINGS_DEFAULT_USE_VOLUME_KEYS_NAVIGATION,
8+
val messageViewPostRemoveNavigation: String = INTERACTION_SETTINGS_DEFAULT_MESSAGE_VIEW_POST_REMOVE_NAVIGATION,
79
)
10+
11+
/**
12+
* The navigation actions that can be to performed after the user has deleted or moved a message from the message
13+
* view screen.
14+
*/
15+
enum class PostRemoveNavigation {
16+
ReturnToMessageList,
17+
ShowPreviousMessage,
18+
ShowNextMessage,
19+
}

core/preference/api/src/commonMain/kotlin/net/thunderbird/core/preference/interaction/InteractionSettingsPreferenceManager.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ package net.thunderbird.core.preference.interaction
33
import net.thunderbird.core.preference.PreferenceManager
44

55
const val KEY_USE_VOLUME_KEYS_FOR_NAVIGATION = "useVolumeKeysForNavigation"
6+
const val KEY_MESSAGE_VIEW_POST_DELETE_ACTION = "messageViewPostDeleteAction"
67
interface InteractionSettingsPreferenceManager : PreferenceManager<InteractionSettings>

core/preference/impl/src/commonMain/kotlin/net/thunderbird/core/preference/interaction/DefaultInteractionSettingsPreferenceManager.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,18 @@ class DefaultInteractionSettingsPreferenceManager(
4040
KEY_USE_VOLUME_KEYS_FOR_NAVIGATION,
4141
INTERACTION_SETTINGS_DEFAULT_USE_VOLUME_KEYS_NAVIGATION,
4242
),
43+
messageViewPostRemoveNavigation = storage.getStringOrDefault(
44+
KEY_MESSAGE_VIEW_POST_DELETE_ACTION,
45+
INTERACTION_SETTINGS_DEFAULT_MESSAGE_VIEW_POST_REMOVE_NAVIGATION,
46+
),
4347
)
4448

4549
private fun writeConfig(config: InteractionSettings) {
4650
logger.debug(TAG) { "writeConfig() called with: config = $config" }
4751
scope.launch(ioDispatcher) {
4852
mutex.withLock {
4953
storageEditor.putBoolean(KEY_USE_VOLUME_KEYS_FOR_NAVIGATION, config.useVolumeKeysForNavigation)
54+
storageEditor.putString(KEY_MESSAGE_VIEW_POST_DELETE_ACTION, config.messageViewPostRemoveNavigation)
5055
storageEditor.commit().also { commited ->
5156
logger.verbose(TAG) { "writeConfig: storageEditor.commit() resulted in: $commited" }
5257
}

legacy/core/src/main/java/com/fsck/k9/K9.kt

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,6 @@ object K9 : KoinComponent {
149149
@JvmStatic
150150
var contactNameColor = 0xFF1093F5.toInt()
151151

152-
var messageViewPostRemoveNavigation: PostRemoveNavigation = PostRemoveNavigation.ReturnToMessageList
153-
154152
var messageViewPostMarkAsUnreadNavigation: PostMarkAsUnreadNavigation =
155153
PostMarkAsUnreadNavigation.ReturnToMessageList
156154

@@ -243,8 +241,6 @@ object K9 : KoinComponent {
243241

244242
messageListDensity = storage.getEnum("messageListDensity", UiDensity.Default)
245243
contactNameColor = storage.getInt("registeredNameColor", 0xFF1093F5.toInt())
246-
messageViewPostRemoveNavigation =
247-
storage.getEnum("messageViewPostDeleteAction", PostRemoveNavigation.ReturnToMessageList)
248244
messageViewPostMarkAsUnreadNavigation =
249245
storage.getEnum("messageViewPostMarkAsUnreadAction", PostMarkAsUnreadNavigation.ReturnToMessageList)
250246

@@ -305,7 +301,6 @@ object K9 : KoinComponent {
305301
editor.putBoolean("showAccountSelector", isShowAccountSelector)
306302
editor.putInt("messageListPreviewLines", messageListPreviewLines)
307303
editor.putInt("registeredNameColor", contactNameColor)
308-
editor.putEnum("messageViewPostDeleteAction", messageViewPostRemoveNavigation)
309304
editor.putEnum("messageViewPostMarkAsUnreadAction", messageViewPostMarkAsUnreadNavigation)
310305

311306
editor.putBoolean("confirmDelete", isConfirmDelete)
@@ -398,16 +393,6 @@ object K9 : KoinComponent {
398393
NOTHING,
399394
}
400395

401-
/**
402-
* The navigation actions that can be to performed after the user has deleted or moved a message from the message
403-
* view screen.
404-
*/
405-
enum class PostRemoveNavigation {
406-
ReturnToMessageList,
407-
ShowPreviousMessage,
408-
ShowNextMessage,
409-
}
410-
411396
/**
412397
* The navigation actions that can be to performed after the user has marked a message as unread from the message
413398
* view screen.

legacy/core/src/main/java/com/fsck/k9/preferences/GeneralSettingsDescriptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import com.fsck.k9.FontSizes;
1515
import com.fsck.k9.K9.NotificationQuickDelete;
1616
import com.fsck.k9.K9.PostMarkAsUnreadNavigation;
17-
import com.fsck.k9.K9.PostRemoveNavigation;
1817
import com.fsck.k9.UiDensity;
1918
import com.fsck.k9.core.R;
2019
import com.fsck.k9.preferences.Settings.BooleanSetting;
@@ -42,6 +41,7 @@
4241
import net.thunderbird.core.preference.SplitViewMode;
4342
import net.thunderbird.core.preference.SubTheme;
4443
import net.thunderbird.core.preference.display.coreSettings.DisplayCoreSettingsKt;
44+
import net.thunderbird.core.preference.interaction.PostRemoveNavigation;
4545
import net.thunderbird.core.preference.network.NetworkSettingsKt;
4646
import net.thunderbird.core.preference.storage.Storage;
4747

legacy/ui/legacy/src/main/java/com/fsck/k9/activity/MessageList.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import app.k9mail.legacy.message.controller.MessageReference
3434
import com.fsck.k9.CoreResourceProvider
3535
import com.fsck.k9.K9
3636
import com.fsck.k9.K9.PostMarkAsUnreadNavigation
37-
import com.fsck.k9.K9.PostRemoveNavigation
3837
import com.fsck.k9.Preferences
3938
import com.fsck.k9.account.BackgroundAccountRemover
4039
import com.fsck.k9.activity.compose.MessageActions
@@ -65,6 +64,7 @@ import net.thunderbird.core.logging.Logger
6564
import net.thunderbird.core.logging.legacy.Log
6665
import net.thunderbird.core.preference.GeneralSettingsManager
6766
import net.thunderbird.core.preference.SplitViewMode
67+
import net.thunderbird.core.preference.interaction.PostRemoveNavigation
6868
import net.thunderbird.feature.account.storage.legacy.mapper.LegacyAccountDataMapper
6969
import net.thunderbird.feature.navigation.drawer.api.NavigationDrawer
7070
import net.thunderbird.feature.navigation.drawer.dropdown.DropDownDrawer
@@ -1292,10 +1292,10 @@ open class MessageList :
12921292
}
12931293

12941294
override fun performNavigationAfterMessageRemoval() {
1295-
when (K9.messageViewPostRemoveNavigation) {
1296-
PostRemoveNavigation.ReturnToMessageList -> returnToMessageList()
1297-
PostRemoveNavigation.ShowPreviousMessage -> showPreviousMessageOrReturn()
1298-
PostRemoveNavigation.ShowNextMessage -> showNextMessageOrReturn()
1295+
when (generalSettingsManager.getConfig().interaction.messageViewPostRemoveNavigation) {
1296+
PostRemoveNavigation.ReturnToMessageList.name -> returnToMessageList()
1297+
PostRemoveNavigation.ShowPreviousMessage.name -> showPreviousMessageOrReturn()
1298+
PostRemoveNavigation.ShowNextMessage.name -> showNextMessageOrReturn()
12991299
}
13001300
}
13011301

legacy/ui/legacy/src/main/java/com/fsck/k9/ui/settings/general/GeneralSettingsDataStore.kt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import androidx.preference.PreferenceDataStore
44
import app.k9mail.feature.telemetry.api.TelemetryManager
55
import com.fsck.k9.K9
66
import com.fsck.k9.K9.PostMarkAsUnreadNavigation
7-
import com.fsck.k9.K9.PostRemoveNavigation
87
import com.fsck.k9.UiDensity
98
import com.fsck.k9.job.K9JobManager
109
import com.fsck.k9.ui.base.AppLanguageManager
@@ -173,7 +172,7 @@ class GeneralSettingsDataStore(
173172
"swipe_action_right" -> swipeActionToString(K9.swipeRightAction)
174173
"swipe_action_left" -> swipeActionToString(K9.swipeLeftAction)
175174
"message_list_density" -> K9.messageListDensity.toString()
176-
"post_remove_navigation" -> K9.messageViewPostRemoveNavigation.name
175+
"post_remove_navigation" -> generalSettingsManager.getConfig().interaction.messageViewPostRemoveNavigation
177176
"post_mark_as_unread_navigation" -> K9.messageViewPostMarkAsUnreadNavigation.name
178177
else -> defValue
179178
}
@@ -217,7 +216,7 @@ class GeneralSettingsDataStore(
217216
"swipe_action_right" -> K9.swipeRightAction = stringToSwipeAction(value)
218217
"swipe_action_left" -> K9.swipeLeftAction = stringToSwipeAction(value)
219218
"message_list_density" -> K9.messageListDensity = UiDensity.valueOf(value)
220-
"post_remove_navigation" -> K9.messageViewPostRemoveNavigation = PostRemoveNavigation.valueOf(value)
219+
"post_remove_navigation" -> setMessageViewPostRemoveNavigation(value)
221220
"post_mark_as_unread_navigation" -> {
222221
K9.messageViewPostMarkAsUnreadNavigation = PostMarkAsUnreadNavigation.valueOf(value)
223222
}
@@ -652,6 +651,17 @@ class GeneralSettingsDataStore(
652651
}
653652
}
654653

654+
private fun setMessageViewPostRemoveNavigation(value: String) {
655+
skipSaveSettings = true
656+
generalSettingsManager.update { settings ->
657+
settings.copy(
658+
interaction = settings.interaction.copy(
659+
messageViewPostRemoveNavigation = value,
660+
),
661+
)
662+
}
663+
}
664+
655665
private fun appThemeToString(theme: AppTheme) = when (theme) {
656666
AppTheme.LIGHT -> "light"
657667
AppTheme.DARK -> "dark"

0 commit comments

Comments
 (0)