Skip to content

Commit 4706236

Browse files
committed
refactor(preferences): migrate K9.messageListDensity to new preference manager
1 parent 0fd3108 commit 4706236

File tree

6 files changed

+28
-10
lines changed

6 files changed

+28
-10
lines changed

core/preference/api/src/commonMain/kotlin/net/thunderbird/core/preference/display/visualSettings/message/list/DisplayMessageListSettings.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const val MESSAGE_LIST_SETTINGS_DEFAULT_IS_CHANGE_CONTACT_NAME_COLOR = true
77
const val MESSAGE_LIST_SETTINGS_DEFAULT_IS_COLORIZE_MISSING_CONTACT_PICTURE = true
88
const val MESSAGE_LIST_SETTINGS_DEFAULT_IS_USE_BACKGROUND_AS_INDICATOR = false
99
const val MESSAGE_LIST_SETTINGS_DEFAULT_PREVIEW_LINES = 2
10+
val MESSAGE_LIST_SETTINGS_DEFAULT_UI_DENSITY = UiDensity.Default
1011

1112
data class DisplayMessageListSettings(
1213
val isShowCorrespondentNames: Boolean = MESSAGE_LIST_SETTINGS_DEFAULT_IS_SHOW_CORRESPONDENT_NAMES,
@@ -16,4 +17,5 @@ data class DisplayMessageListSettings(
1617
val isColorizeMissingContactPictures: Boolean = MESSAGE_LIST_SETTINGS_DEFAULT_IS_COLORIZE_MISSING_CONTACT_PICTURE,
1718
val isUseBackgroundAsUnreadIndicator: Boolean = MESSAGE_LIST_SETTINGS_DEFAULT_IS_USE_BACKGROUND_AS_INDICATOR,
1819
val previewLines: Int = MESSAGE_LIST_SETTINGS_DEFAULT_PREVIEW_LINES,
20+
val uiDensity: UiDensity = MESSAGE_LIST_SETTINGS_DEFAULT_UI_DENSITY,
1921
)

core/preference/impl/src/commonMain/kotlin/net/thunderbird/core/preference/display/visualSettings/message/list/DefaultMessageListPreferencesManager.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import kotlinx.coroutines.flow.update
66
import net.thunderbird.core.logging.Logger
77
import net.thunderbird.core.preference.storage.Storage
88
import net.thunderbird.core.preference.storage.StorageEditor
9+
import net.thunderbird.core.preference.storage.getEnumOrDefault
10+
import net.thunderbird.core.preference.storage.putEnum
911

1012
private const val TAG = "DefaultMessageListPreferencesManager"
1113

@@ -50,6 +52,10 @@ class DefaultMessageListPreferencesManager(
5052
KEY_MESSAGE_LIST_VIEW_PREVIEW_LINES,
5153
MESSAGE_LIST_SETTINGS_DEFAULT_PREVIEW_LINES,
5254
),
55+
uiDensity = storage.getEnumOrDefault(
56+
KEY_MESSAGE_LIST_VIEW_DENSITY,
57+
MESSAGE_LIST_SETTINGS_DEFAULT_UI_DENSITY,
58+
),
5359
)
5460

5561
private fun write(preferences: DisplayMessageListSettings) {
@@ -60,6 +66,7 @@ class DefaultMessageListPreferencesManager(
6066
storageEditor.putBoolean(KEY_SHOW_CONTACT_NAME, preferences.isShowContactName)
6167
storageEditor.putBoolean(KEY_SHOW_CORRESPONDENT_NAMES, preferences.isShowCorrespondentNames)
6268
storageEditor.putInt(KEY_MESSAGE_LIST_VIEW_PREVIEW_LINES, preferences.previewLines)
69+
storageEditor.putEnum(KEY_MESSAGE_LIST_VIEW_DENSITY, preferences.uiDensity)
6370
}
6471

6572
override fun getConfig(): DisplayMessageListSettings = preferences.value

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import net.thunderbird.core.android.account.AccountDefaultsProvider
1414
import net.thunderbird.core.android.account.SortType
1515
import net.thunderbird.core.featureflag.FeatureFlagProvider
1616
import net.thunderbird.core.featureflag.toFeatureFlagKey
17-
import net.thunderbird.core.preference.display.visualSettings.message.list.UiDensity
1817
import net.thunderbird.core.preference.storage.Storage
1918
import net.thunderbird.core.preference.storage.StorageEditor
2019
import net.thunderbird.core.preference.storage.getEnumOrDefault
@@ -121,9 +120,6 @@ object K9 : KoinComponent {
121120
@JvmStatic
122121
var lockScreenNotificationVisibility = LockScreenNotificationVisibility.MESSAGE_COUNT
123122

124-
@JvmStatic
125-
var messageListDensity: UiDensity = UiDensity.Default
126-
127123
@JvmStatic
128124
var contactNameColor = 0xFF1093F5.toInt()
129125

@@ -206,7 +202,6 @@ object K9 : KoinComponent {
206202
fun loadPrefs(storage: Storage) {
207203
isShowAccountSelector = storage.getBoolean("showAccountSelector", true)
208204

209-
messageListDensity = storage.getEnum("messageListDensity", UiDensity.Default)
210205
contactNameColor = storage.getInt("registeredNameColor", 0xFF1093F5.toInt())
211206
messageViewPostMarkAsUnreadNavigation =
212207
storage.getEnum("messageViewPostMarkAsUnreadAction", PostMarkAsUnreadNavigation.ReturnToMessageList)
@@ -247,7 +242,6 @@ object K9 : KoinComponent {
247242

248243
@Suppress("LongMethod")
249244
internal fun save(editor: StorageEditor) {
250-
editor.putEnum("messageListDensity", messageListDensity)
251245
editor.putBoolean("showAccountSelector", isShowAccountSelector)
252246
editor.putInt("registeredNameColor", contactNameColor)
253247
editor.putEnum("messageViewPostMarkAsUnreadAction", messageViewPostMarkAsUnreadNavigation)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ data class MessageListActivityConfig(
6161
contactNameColor = K9.contactNameColor,
6262
messageViewTheme = settings.display.coreSettings.messageViewTheme,
6363
messageListPreviewLines = messageListPreferences.previewLines,
64-
messageListDensity = K9.messageListDensity,
64+
messageListDensity = messageListPreferences.uiDensity,
6565
splitViewMode = settings.display.coreSettings.splitViewMode,
6666
fontSizeMessageListSubject = K9.fontSizes.messageListSubject,
6767
fontSizeMessageListSender = K9.fontSizes.messageListSender,

legacy/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/MessageListFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ class MessageListFragment :
812812
showingThreadedList = showingThreadedList,
813813
backGroundAsReadIndicator = messageListSettings.isUseBackgroundAsUnreadIndicator,
814814
showAccountIndicator = isShowAccountIndicator,
815-
density = K9.messageListDensity,
815+
density = messageListSettings.uiDensity,
816816
)
817817

818818
private fun getFolderInfoHolder(account: LegacyAccount, folderId: Long): FolderInfoHolder {

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ class GeneralSettingsDataStore(
163163
"message_compose_input_font" -> K9.fontSizes.messageComposeInput.toString()
164164
"swipe_action_right" -> swipeActionToString(interactionSettings.swipeActions.rightAction)
165165
"swipe_action_left" -> swipeActionToString(interactionSettings.swipeActions.leftAction)
166-
"message_list_density" -> K9.messageListDensity.toString()
166+
"message_list_density" -> messageListSettings.uiDensity.toString()
167167
"post_remove_navigation" -> interactionSettings.messageViewPostRemoveNavigation
168168
"post_mark_as_unread_navigation" -> K9.messageViewPostMarkAsUnreadNavigation.name
169169
else -> defValue
@@ -208,7 +208,7 @@ class GeneralSettingsDataStore(
208208
"message_compose_input_font" -> K9.fontSizes.messageComposeInput = value.toInt()
209209
"swipe_action_right" -> updateSwipeAction(value) { swipeAction -> copy(rightAction = swipeAction) }
210210
"swipe_action_left" -> updateSwipeAction(value) { swipeAction -> copy(leftAction = swipeAction) }
211-
"message_list_density" -> K9.messageListDensity = UiDensity.valueOf(value)
211+
"message_list_density" -> updateMessageListDensity(value)
212212
"post_remove_navigation" -> setMessageViewPostRemoveNavigation(value)
213213
"post_mark_as_unread_navigation" -> {
214214
K9.messageViewPostMarkAsUnreadNavigation = PostMarkAsUnreadNavigation.valueOf(value)
@@ -810,4 +810,19 @@ class GeneralSettingsDataStore(
810810
)
811811
}
812812
}
813+
814+
private fun updateMessageListDensity(value: String) {
815+
skipSaveSettings = true
816+
generalSettingsManager.update { settings ->
817+
settings.copy(
818+
display = settings.display.copy(
819+
visualSettings = settings.display.visualSettings.copy(
820+
messageListSettings = settings.display.visualSettings.messageListSettings.copy(
821+
uiDensity = UiDensity.valueOf(value),
822+
),
823+
),
824+
),
825+
)
826+
}
827+
}
813828
}

0 commit comments

Comments
 (0)