mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-02 12:07:28 +00:00
Create extension SyncService.isOnline()
This commit is contained in:
+3
@@ -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 }
|
||||
|
||||
-8
@@ -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
|
||||
}
|
||||
|
||||
-37
@@ -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())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user