Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 494fbe07 authored by Wolf-Martell Montwé's avatar Wolf-Martell Montwé Committed by GitHub
Browse files

Merge pull request #9271 from wmontwe/add-account-settings-profile-indicator-part-2

Add account settings profile indicator - part 2
parents a2f8462a 5e1470ed
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -33,4 +33,6 @@ dependencies {
    implementation(projects.mail.protocols.imap)

    implementation(libs.androidx.work.runtime)

    testImplementation(projects.feature.account.fake)
}
+9 −5
Original line number Diff line number Diff line
package net.thunderbird.app.common.account

import app.k9mail.feature.account.setup.AccountSetupExternalContract
import net.thunderbird.app.common.account.data.CommonAccountProfileLocalDataSource
import net.thunderbird.app.common.account.data.CommonLegacyAccountWrapperManager
import net.thunderbird.app.common.account.data.DefaultAccountProfileLocalDataSource
import net.thunderbird.app.common.account.data.DefaultLegacyAccountWrapperManager
import net.thunderbird.core.android.account.AccountDefaultsProvider
import net.thunderbird.core.android.account.LegacyAccountWrapperManager
import net.thunderbird.feature.account.core.AccountCoreExternalContract.AccountProfileLocalDataSource
import net.thunderbird.feature.account.core.featureAccountCoreModule
import net.thunderbird.feature.account.storage.legacy.featureAccountStorageLegacyModule
import org.koin.android.ext.koin.androidApplication
import org.koin.dsl.module

internal val appCommonAccountModule = module {
    includes(
        featureAccountCoreModule,
        featureAccountStorageLegacyModule,
    )

    single<LegacyAccountWrapperManager> {
        CommonLegacyAccountWrapperManager(
        DefaultLegacyAccountWrapperManager(
            accountManager = get(),
            accountDataMapper = get(),
        )
    }

    single<AccountProfileLocalDataSource> {
        CommonAccountProfileLocalDataSource(
        DefaultAccountProfileLocalDataSource(
            accountManager = get(),
            dataMapper = get(),
        )
    }

    single<AccountDefaultsProvider> {
        CommonAccountDefaultsProvider(
        DefaultAccountDefaultsProvider(
            resourceProvider = get(),
            featureFlagProvider = get(),
        )
+4 −4
Original line number Diff line number Diff line
package net.thunderbird.app.common.account

import com.fsck.k9.CoreResourceProvider
import com.fsck.k9.K9
import net.thunderbird.core.android.account.AccountDefaultsProvider
import net.thunderbird.core.android.account.AccountDefaultsProvider.Companion.DEFAULT_MAXIMUM_AUTO_DOWNLOAD_MESSAGE_SIZE
import net.thunderbird.core.android.account.AccountDefaultsProvider.Companion.DEFAULT_MESSAGE_FORMAT
@@ -17,6 +16,7 @@ import net.thunderbird.core.android.account.AccountDefaultsProvider.Companion.DE
import net.thunderbird.core.android.account.AccountDefaultsProvider.Companion.DEFAULT_SORT_TYPE
import net.thunderbird.core.android.account.AccountDefaultsProvider.Companion.DEFAULT_STRIP_SIGNATURE
import net.thunderbird.core.android.account.AccountDefaultsProvider.Companion.DEFAULT_SYNC_INTERVAL
import net.thunderbird.core.android.account.AccountDefaultsProvider.Companion.DEFAULT_VISIBLE_LIMIT
import net.thunderbird.core.android.account.AccountDefaultsProvider.Companion.NO_OPENPGP_KEY
import net.thunderbird.core.android.account.AccountDefaultsProvider.Companion.UNASSIGNED_ACCOUNT_NUMBER
import net.thunderbird.core.android.account.Expunge
@@ -26,14 +26,14 @@ import net.thunderbird.core.android.account.LegacyAccount
import net.thunderbird.core.android.account.ShowPictures
import net.thunderbird.core.featureflag.FeatureFlagProvider
import net.thunderbird.core.featureflag.toFeatureFlagKey
import net.thunderbird.core.preferences.Storage
import net.thunderbird.core.preference.storage.Storage
import net.thunderbird.feature.mail.folder.api.SpecialFolderSelection
import net.thunderbird.feature.notification.NotificationLight
import net.thunderbird.feature.notification.NotificationSettings
import net.thunderbird.feature.notification.NotificationVibration

@Suppress("MagicNumber")
internal class CommonAccountDefaultsProvider(
internal class DefaultAccountDefaultsProvider(
    private val resourceProvider: CoreResourceProvider,
    private val featureFlagProvider: FeatureFlagProvider,
) : AccountDefaultsProvider {
@@ -67,7 +67,7 @@ internal class CommonAccountDefaultsProvider(
    private fun LegacyAccount.applyLegacyDefaults() {
        automaticCheckIntervalMinutes = DEFAULT_SYNC_INTERVAL
        idleRefreshMinutes = 24
        displayCount = K9.DEFAULT_VISIBLE_LIMIT
        displayCount = DEFAULT_VISIBLE_LIMIT
        accountNumber = UNASSIGNED_ACCOUNT_NUMBER
        isNotifyNewMail = true
        folderNotifyNewMailMode = FolderMode.ALL
+12 −13
Original line number Diff line number Diff line
@@ -4,34 +4,33 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.flow.map
import net.thunderbird.core.android.account.LegacyAccountWrapperManager
import net.thunderbird.feature.account.api.AccountId
import net.thunderbird.feature.account.api.profile.AccountProfile
import net.thunderbird.feature.account.AccountId
import net.thunderbird.feature.account.core.AccountCoreExternalContract.AccountProfileLocalDataSource
import net.thunderbird.feature.account.profile.AccountProfile
import net.thunderbird.feature.account.storage.mapper.AccountProfileDataMapper

internal class CommonAccountProfileLocalDataSource(
internal class DefaultAccountProfileLocalDataSource(
    private val accountManager: LegacyAccountWrapperManager,
    private val dataMapper: AccountProfileDataMapper,
) : AccountProfileLocalDataSource {

    override fun getById(accountId: AccountId): Flow<AccountProfile?> {
        return accountManager.getById(accountId.value)
        return accountManager.getById(accountId)
            .map { account ->
                account?.let {
                    AccountProfile(
                        accountId = AccountId.from(account.uuid),
                        name = account.displayName,
                        color = account.chipColor,
                    )
                account?.let { dto ->
                    dataMapper.toDomain(dto.profile)
                }
            }
    }

    override suspend fun update(accountProfile: AccountProfile) {
        val currentAccount = accountManager.getById(accountProfile.accountId.value)
        val currentAccount = accountManager.getById(accountProfile.id)
            .firstOrNull() ?: return

        val accountProfile = dataMapper.toDto(accountProfile)

        val updatedAccount = currentAccount.copy(
            displayName = accountProfile.name,
            chipColor = accountProfile.color,
            profile = accountProfile,
        )

        accountManager.update(updatedAccount)
+13 −6
Original line number Diff line number Diff line
@@ -5,27 +5,34 @@ import kotlinx.coroutines.flow.map
import net.thunderbird.core.android.account.AccountManager
import net.thunderbird.core.android.account.LegacyAccountWrapper
import net.thunderbird.core.android.account.LegacyAccountWrapperManager
import net.thunderbird.feature.account.AccountId
import net.thunderbird.feature.account.storage.legacy.mapper.DefaultLegacyAccountWrapperDataMapper

internal class CommonLegacyAccountWrapperManager(
internal class DefaultLegacyAccountWrapperManager(
    private val accountManager: AccountManager,
    private val accountDataMapper: DefaultLegacyAccountWrapperDataMapper,
) : LegacyAccountWrapperManager {

    override fun getAll(): Flow<List<LegacyAccountWrapper>> {
        return accountManager.getAccountsFlow()
            .map { list ->
                list.map { account ->
                    LegacyAccountWrapper.from(account)
                    accountDataMapper.toDomain(account)
                }
            }
    }

    override fun getById(id: String): Flow<LegacyAccountWrapper?> {
        return accountManager.getAccountFlow(id).map { account ->
            account?.let { LegacyAccountWrapper.from(it) }
    override fun getById(id: AccountId): Flow<LegacyAccountWrapper?> {
        return accountManager.getAccountFlow(id.asRaw()).map { account ->
            account?.let {
                accountDataMapper.toDomain(it)
            }
        }
    }

    override suspend fun update(account: LegacyAccountWrapper) {
        accountManager.saveAccount(LegacyAccountWrapper.to(account))
        accountManager.saveAccount(
            accountDataMapper.toDto(account),
        )
    }
}
Loading