Loading feature/navigation/drawer/src/main/kotlin/app/k9mail/feature/navigation/drawer/NavigationDrawerModule.kt +7 −0 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ import app.k9mail.feature.navigation.drawer.domain.usecase.GetDisplayAccounts import app.k9mail.feature.navigation.drawer.domain.usecase.GetDisplayFoldersForAccount import app.k9mail.feature.navigation.drawer.domain.usecase.GetDrawerConfig import app.k9mail.feature.navigation.drawer.domain.usecase.SyncAccount import app.k9mail.feature.navigation.drawer.domain.usecase.SyncAllAccounts import app.k9mail.feature.navigation.drawer.legacy.AccountsViewModel import app.k9mail.feature.navigation.drawer.legacy.FoldersViewModel import app.k9mail.feature.navigation.drawer.ui.DrawerViewModel Loading Loading @@ -43,6 +44,12 @@ val navigationDrawerModule: Module = module { ) } single<UseCase.SyncAllAccounts> { SyncAllAccounts( messagingController = get(), ) } viewModel { AccountsViewModel( getDisplayAccounts = get(), Loading feature/navigation/drawer/src/main/kotlin/app/k9mail/feature/navigation/drawer/domain/DomainContract.kt +6 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,12 @@ internal interface DomainContract { fun interface SyncAccount { operator fun invoke(account: Account): Flow<Result<Unit>> } /** * Synchronize all accounts. */ fun interface SyncAllAccounts { operator fun invoke(): Flow<Result<Unit>> } } } feature/navigation/drawer/src/main/kotlin/app/k9mail/feature/navigation/drawer/domain/usecase/SyncAllAccounts.kt 0 → 100644 +37 −0 Original line number Diff line number Diff line package app.k9mail.feature.navigation.drawer.domain.usecase import android.content.Context import app.k9mail.feature.navigation.drawer.domain.DomainContract.UseCase import app.k9mail.legacy.account.Account import app.k9mail.legacy.message.controller.MessagingControllerMailChecker import app.k9mail.legacy.message.controller.SimpleMessagingListener import kotlin.coroutines.CoroutineContext import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.channels.awaitClose import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.callbackFlow import kotlinx.coroutines.flow.flowOn class SyncAllAccounts( private val messagingController: MessagingControllerMailChecker, private val coroutineContext: CoroutineContext = Dispatchers.IO, ) : UseCase.SyncAllAccounts { override fun invoke(): Flow<Result<Unit>> = callbackFlow { val listener = object : SimpleMessagingListener() { override fun checkMailFinished(context: Context?, account: Account?) { trySend(Result.success(Unit)) close() } } messagingController.checkMail( account = null, ignoreLastCheckedTime = true, useManualWakeLock = true, notify = true, listener = listener, ) awaitClose() }.flowOn(coroutineContext) } feature/navigation/drawer/src/test/kotlin/app/k9mail/feature/navigation/drawer/domain/usecase/SyncAllAccountsTest.kt 0 → 100644 +26 −0 Original line number Diff line number Diff line package app.k9mail.feature.navigation.drawer.domain.usecase import app.k9mail.legacy.message.controller.MessagingListener import assertk.assertions.isEqualTo import kotlin.test.Test import kotlinx.coroutines.flow.first import kotlinx.coroutines.test.runTest class SyncAllAccountsTest { @Test fun `should sync mail`() = runTest { val listenerExecutor: (MessagingListener?) -> Unit = { listener -> listener?.checkMailFinished(null, null) } val testSubject = SyncAllAccounts( messagingController = FakeMessagingControllerMailChecker( listenerExecutor = listenerExecutor, ), ) val result = testSubject().first() assertk.assertThat(result.isSuccess).isEqualTo(true) } } Loading
feature/navigation/drawer/src/main/kotlin/app/k9mail/feature/navigation/drawer/NavigationDrawerModule.kt +7 −0 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ import app.k9mail.feature.navigation.drawer.domain.usecase.GetDisplayAccounts import app.k9mail.feature.navigation.drawer.domain.usecase.GetDisplayFoldersForAccount import app.k9mail.feature.navigation.drawer.domain.usecase.GetDrawerConfig import app.k9mail.feature.navigation.drawer.domain.usecase.SyncAccount import app.k9mail.feature.navigation.drawer.domain.usecase.SyncAllAccounts import app.k9mail.feature.navigation.drawer.legacy.AccountsViewModel import app.k9mail.feature.navigation.drawer.legacy.FoldersViewModel import app.k9mail.feature.navigation.drawer.ui.DrawerViewModel Loading Loading @@ -43,6 +44,12 @@ val navigationDrawerModule: Module = module { ) } single<UseCase.SyncAllAccounts> { SyncAllAccounts( messagingController = get(), ) } viewModel { AccountsViewModel( getDisplayAccounts = get(), Loading
feature/navigation/drawer/src/main/kotlin/app/k9mail/feature/navigation/drawer/domain/DomainContract.kt +6 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,12 @@ internal interface DomainContract { fun interface SyncAccount { operator fun invoke(account: Account): Flow<Result<Unit>> } /** * Synchronize all accounts. */ fun interface SyncAllAccounts { operator fun invoke(): Flow<Result<Unit>> } } }
feature/navigation/drawer/src/main/kotlin/app/k9mail/feature/navigation/drawer/domain/usecase/SyncAllAccounts.kt 0 → 100644 +37 −0 Original line number Diff line number Diff line package app.k9mail.feature.navigation.drawer.domain.usecase import android.content.Context import app.k9mail.feature.navigation.drawer.domain.DomainContract.UseCase import app.k9mail.legacy.account.Account import app.k9mail.legacy.message.controller.MessagingControllerMailChecker import app.k9mail.legacy.message.controller.SimpleMessagingListener import kotlin.coroutines.CoroutineContext import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.channels.awaitClose import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.callbackFlow import kotlinx.coroutines.flow.flowOn class SyncAllAccounts( private val messagingController: MessagingControllerMailChecker, private val coroutineContext: CoroutineContext = Dispatchers.IO, ) : UseCase.SyncAllAccounts { override fun invoke(): Flow<Result<Unit>> = callbackFlow { val listener = object : SimpleMessagingListener() { override fun checkMailFinished(context: Context?, account: Account?) { trySend(Result.success(Unit)) close() } } messagingController.checkMail( account = null, ignoreLastCheckedTime = true, useManualWakeLock = true, notify = true, listener = listener, ) awaitClose() }.flowOn(coroutineContext) }
feature/navigation/drawer/src/test/kotlin/app/k9mail/feature/navigation/drawer/domain/usecase/SyncAllAccountsTest.kt 0 → 100644 +26 −0 Original line number Diff line number Diff line package app.k9mail.feature.navigation.drawer.domain.usecase import app.k9mail.legacy.message.controller.MessagingListener import assertk.assertions.isEqualTo import kotlin.test.Test import kotlinx.coroutines.flow.first import kotlinx.coroutines.test.runTest class SyncAllAccountsTest { @Test fun `should sync mail`() = runTest { val listenerExecutor: (MessagingListener?) -> Unit = { listener -> listener?.checkMailFinished(null, null) } val testSubject = SyncAllAccounts( messagingController = FakeMessagingControllerMailChecker( listenerExecutor = listenerExecutor, ), ) val result = testSubject().first() assertk.assertThat(result.isSuccess).isEqualTo(true) } }