forked from thunderbird/thunderbird-android
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request thunderbird#8166 from wmontwe/change-drawer-sync-c…
…alls Change drawer sync calls
- Loading branch information
Showing
19 changed files
with
309 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...er/src/main/kotlin/app/k9mail/feature/navigation/drawer/domain/usecase/SyncAllAccounts.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...app/k9mail/feature/navigation/drawer/domain/usecase/FakeMessagingControllerMailChecker.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package app.k9mail.feature.navigation.drawer.domain.usecase | ||
|
||
import app.k9mail.legacy.account.Account | ||
import app.k9mail.legacy.message.controller.MessagingControllerMailChecker | ||
import app.k9mail.legacy.message.controller.MessagingListener | ||
|
||
internal class FakeMessagingControllerMailChecker( | ||
private val listenerExecutor: (MessagingListener?) -> Unit = {}, | ||
) : MessagingControllerMailChecker { | ||
override fun checkMail( | ||
account: Account?, | ||
ignoreLastCheckedTime: Boolean, | ||
useManualWakeLock: Boolean, | ||
notify: Boolean, | ||
listener: MessagingListener?, | ||
) { | ||
listenerExecutor(listener) | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...er/src/test/kotlin/app/k9mail/feature/navigation/drawer/domain/usecase/SyncAccountTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package app.k9mail.feature.navigation.drawer.domain.usecase | ||
|
||
import app.k9mail.feature.navigation.drawer.ui.FakeData | ||
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 SyncAccountTest { | ||
|
||
@Test | ||
fun `should sync mail with account`() = runTest { | ||
val listenerExecutor: (MessagingListener?) -> Unit = { listener -> | ||
listener?.checkMailFinished(null, null) | ||
} | ||
val testSubject = SyncAccount( | ||
messagingController = FakeMessagingControllerMailChecker( | ||
listenerExecutor = listenerExecutor, | ||
), | ||
) | ||
|
||
val result = testSubject(FakeData.ACCOUNT).first() | ||
|
||
assertk.assertThat(result.isSuccess).isEqualTo(true) | ||
} | ||
} |
Oops, something went wrong.