Create extension SyncService.isOnline()
This commit is contained in:
parent
3ffafdd7e7
commit
c8f4268545
8 changed files with 18 additions and 60 deletions
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
package io.element.android.libraries.matrix.api.sync
|
||||
|
||||
import io.element.android.libraries.core.coroutine.mapState
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
|
||||
interface SyncService {
|
||||
|
|
@ -25,3 +26,5 @@ interface SyncService {
|
|||
*/
|
||||
val syncState: StateFlow<SyncState>
|
||||
}
|
||||
|
||||
fun SyncService.isOnline(): StateFlow<Boolean> = syncState.mapState { it != SyncState.Offline }
|
||||
|
|
|
|||
|
|
@ -14,11 +14,3 @@ enum class SyncState {
|
|||
Terminated,
|
||||
Offline,
|
||||
}
|
||||
|
||||
fun SyncState.isConnected() = when (this) {
|
||||
SyncState.Idle,
|
||||
SyncState.Running,
|
||||
SyncState.Error,
|
||||
SyncState.Terminated -> true
|
||||
SyncState.Offline -> false
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,37 +0,0 @@
|
|||
/*
|
||||
* Copyright 2025 New Vector Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
package io.element.android.libraries.matrix.api.sync
|
||||
|
||||
import org.junit.Test
|
||||
|
||||
class SyncStateTest {
|
||||
@Test
|
||||
fun `isConnected should return true for Idle`() {
|
||||
assert(SyncState.Idle.isConnected())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `isConnected should return true for Running`() {
|
||||
assert(SyncState.Running.isConnected())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `isConnected should return true for Error`() {
|
||||
assert(SyncState.Error.isConnected())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `isConnected should return true for Terminated`() {
|
||||
assert(SyncState.Terminated.isConnected())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `isConnected should return false for Offline`() {
|
||||
assert(!SyncState.Offline.isConnected())
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue