Repository: thunderbird/thunderbird-android
File: legacy/core/src/main/java/com/fsck/k9/preferences/DefaultDrawerConfigManager.kt (Kotlin)

Code before:
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.flow.update
import net.thunderbird.core.preference.display.inboxSettings.DisplayInboxSettingsPreferenceManager
import net.thunderbird.core.preference.display.visualSettings.DisplayVisualSettingsPreferenceManager
import net.thunderbird.core.preference.update
import net.thunderbird.feature.navigation.drawer.api.NavigationDrawerExternalContract.DrawerConfig

internal class DefaultDrawerConfigManager(
    private val preferences: Preferences,
    coroutineScope: CoroutineScope,
    private val displayInboxSettingsPreferenceManager: DisplayInboxSettingsPreferenceManager,
    private val displayVisualSettingsPreferenceManager: DisplayVisualSettingsPreferenceManager,
) : DrawerConfigManager {
    private val showAccountSelector = MutableStateFlow(K9.isShowAccountSelector)
    private val drawerConfig: StateFlow<DrawerConfig> = showAccountSelector
        .combine(displayInboxSettingsPreferenceManager.getConfigFlow()) {
                showAccSelector,
                displayInboxSettings,
            ->
            Pair(showAccSelector, displayInboxSettings)
        }
        .combine(displayVisualSettingsPreferenceManager.getConfigFlow()) {
                (showAccSelector, displayInboxSettings),
                displayVisualSettings,
            ->
            DrawerConfig(
                showAccountSelector = showAccSelector,
                showStarredCount = displayInboxSettings.isShowStarredCount,
                showUnifiedFolders = displayInboxSettings.isShowUnifiedInbox,
                expandAllFolder = displayVisualSettings.drawerExpandAllFolder,
            )
        }
        .stateIn(
            scope = coroutineScope,
            started = SharingStarted.WhileSubscribed(),
            initialValue = DrawerConfig(
                showAccountSelector = false,
                showStarredCount = false,
                showUnifiedFolders = false,
                expandAllFolder = false,
            ),
        )

    override fun save(config: DrawerConfig) {
        displayInboxSettingsPreferenceManager.update {
            it.copy(
                isShowStarredCount = config.showStarredCount,
                isShowUnifiedInbox = config.showUnifiedFolders,
            )
        }

Review comment (suggestion):
nit: better formatting for readability:
```suggestion
        .combine(
            displayVisualSettingsPreferenceManager.getConfigFlow(),
        ) { (showAccSelector, displayInboxSettings), displayVisualSettings ->
```

Code after:
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.flow.update
import net.thunderbird.core.preference.display.inboxSettings.DisplayInboxSettingsPreferenceManager
import net.thunderbird.core.preference.display.visualSettings.DisplayVisualSettingsPreferenceManager
import net.thunderbird.core.preference.update
import net.thunderbird.feature.navigation.drawer.api.NavigationDrawerExternalContract.DrawerConfig

internal class DefaultDrawerConfigManager(
    private val preferences: Preferences,
    coroutineScope: CoroutineScope,
    private val displayInboxSettingsPreferenceManager: DisplayInboxSettingsPreferenceManager,
    private val displayVisualSettingsPreferenceManager: DisplayVisualSettingsPreferenceManager,
) : DrawerConfigManager {
    private val showAccountSelector = MutableStateFlow(K9.isShowAccountSelector)
    private val drawerConfig: StateFlow<DrawerConfig> = showAccountSelector
        .combine(
            displayInboxSettingsPreferenceManager.getConfigFlow(),
        ) { showAccSelector, displayInboxSettings ->
            Pair(showAccSelector, displayInboxSettings)
        }
        .combine(
            displayVisualSettingsPreferenceManager.getConfigFlow(),
        ) { (showAccSelector, displayInboxSettings), displayVisualSettings ->
            DrawerConfig(
                showAccountSelector = showAccSelector,
                showStarredCount = displayInboxSettings.isShowStarredCount,
                showUnifiedFolders = displayInboxSettings.isShowUnifiedInbox,
                expandAllFolder = displayVisualSettings.drawerExpandAllFolder,
            )
        }
        .stateIn(
            scope = coroutineScope,
            started = SharingStarted.WhileSubscribed(),
            initialValue = DrawerConfig(
                showAccountSelector = false,
                showStarredCount = false,
                showUnifiedFolders = false,
                expandAllFolder = false,
            ),
        )

    override fun save(config: DrawerConfig) {
        displayInboxSettingsPreferenceManager.update {
            it.copy(
                isShowStarredCount = config.showStarredCount,
                isShowUnifiedInbox = config.showUnifiedFolders,
            )
        }

        val editor = preferences.createStorageEditor()