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

Code before:
 *
 * Currently general settings are split between [K9] and [GeneralSettings]. The goal is to move everything over to
 * [GeneralSettings] and get rid of [K9].
 *
 * The [GeneralSettings] instance managed by this class is updated with state from [K9] when [K9.saveSettingsAsync] is
 * called.
 */
@Suppress("LongParameterList")
internal class DefaultGeneralSettingsManager(
    private val preferences: Preferences,
    private val coroutineScope: CoroutineScope,
    private val changePublisher: PreferenceChangePublisher,
    private val privacySettingsPreferenceManager: PrivacySettingsPreferenceManager,
    private val notificationPreferenceManager: NotificationPreferenceManager,
    private val displaySettingsSettingsPreferenceManager: DisplaySettingsPreferenceManager,
    private val displayCoreSettingsPreferenceManager: DisplayCoreSettingsPreferenceManager,
    private val displayInboxSettingsPreferenceManager: DisplayInboxSettingsPreferenceManager,
    private val displayVisualSettingsPreferenceManager: DisplayVisualSettingsPreferenceManager,
    private val displayMiscSettingsPreferenceManager: DisplayMiscSettingsPreferenceManager,
    private val networkSettingsPreferenceManager: NetworkSettingsPreferenceManager,
    private val debuggingSettingsPreferenceManager: DebuggingSettingsPreferenceManager,
    private val interactionSettingsPreferenceManager: InteractionSettingsPreferenceManager,
    private val debugLogConfigurator: DebugLogConfigurator,
    private val backgroundDispatcher: CoroutineDispatcher = Dispatchers.IO,
    private val platformConfigProvider: PlatformConfigProvider,
    private val preferenceChangePublisher: PreferenceChangePublisher,
) : GeneralSettingsManager {
    val mutex = Mutex()
    private val generalSettings = privacySettingsPreferenceManager.getConfigFlow()
        .map { privacy ->
            GeneralSettings(privacy = privacy, platformConfigProvider = platformConfigProvider)
        }
        .combine(privacySettingsPreferenceManager.getConfigFlow()) { generalSettings, privacySettings ->
            generalSettings.copy(
                privacy = privacySettings,
            )
        }
        .combine(notificationPreferenceManager.getConfigFlow()) { generalSettings, notificationSettings ->
            generalSettings.copy(
                notification = notificationSettings,
            )
        }
        .combine(displaySettingsSettingsPreferenceManager.getConfigFlow()) { generalSettings, displaySettings ->
            generalSettings.copy(
                display = displaySettings,
            )
        }
        .combine(displayCoreSettingsPreferenceManager.getConfigFlow()) { generalSettings, coreSettings ->
            generalSettings.copy(
                display = generalSettings.display.copy(coreSettings = coreSettings),
            )

Review comment (suggestion):
There is already a `changePublisher` above -> line 46

Code after:
 *
 * Currently general settings are split between [K9] and [GeneralSettings]. The goal is to move everything over to
 * [GeneralSettings] and get rid of [K9].
 *
 * The [GeneralSettings] instance managed by this class is updated with state from [K9] when [K9.saveSettingsAsync] is
 * called.
 */
@Suppress("LongParameterList")
internal class DefaultGeneralSettingsManager(
    private val preferences: Preferences,
    private val coroutineScope: CoroutineScope,
    private val changePublisher: PreferenceChangePublisher,
    private val privacySettingsPreferenceManager: PrivacySettingsPreferenceManager,
    private val notificationPreferenceManager: NotificationPreferenceManager,
    private val displaySettingsSettingsPreferenceManager: DisplaySettingsPreferenceManager,
    private val displayCoreSettingsPreferenceManager: DisplayCoreSettingsPreferenceManager,
    private val displayInboxSettingsPreferenceManager: DisplayInboxSettingsPreferenceManager,
    private val displayVisualSettingsPreferenceManager: DisplayVisualSettingsPreferenceManager,
    private val displayMiscSettingsPreferenceManager: DisplayMiscSettingsPreferenceManager,
    private val networkSettingsPreferenceManager: NetworkSettingsPreferenceManager,
    private val debuggingSettingsPreferenceManager: DebuggingSettingsPreferenceManager,
    private val interactionSettingsPreferenceManager: InteractionSettingsPreferenceManager,
    private val debugLogConfigurator: DebugLogConfigurator,
    private val backgroundDispatcher: CoroutineDispatcher = Dispatchers.IO,
    private val platformConfigProvider: PlatformConfigProvider,
) : GeneralSettingsManager {
    val mutex = Mutex()
    private val generalSettings = privacySettingsPreferenceManager.getConfigFlow()
        .map { privacy ->
            GeneralSettings(privacy = privacy, platformConfigProvider = platformConfigProvider)
        }
        .combine(privacySettingsPreferenceManager.getConfigFlow()) { generalSettings, privacySettings ->
            generalSettings.copy(
                privacy = privacySettings,
            )
        }
        .combine(notificationPreferenceManager.getConfigFlow()) { generalSettings, notificationSettings ->
            generalSettings.copy(
                notification = notificationSettings,
            )
        }
        .combine(displaySettingsSettingsPreferenceManager.getConfigFlow()) { generalSettings, displaySettings ->
            generalSettings.copy(
                display = displaySettings,
            )
        }
        .combine(displayCoreSettingsPreferenceManager.getConfigFlow()) { generalSettings, coreSettings ->
            generalSettings.copy(
                display = generalSettings.display.copy(coreSettings = coreSettings),
            )
        }