Skip to content

Commit 64abdf6

Browse files
committed
Rename NetworkStatus.Online/Offline to Connected/Disconnected so they're not easily mistaken with internet connectivity instead
1 parent 4218140 commit 64abdf6

File tree

6 files changed

+27
-15
lines changed

6 files changed

+27
-15
lines changed

appnav/src/main/kotlin/io/element/android/appnav/di/DefaultSyncOrchestrator.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class DefaultSyncOrchestrator @AssistedInject constructor(
9999
appForegroundStateService.isSyncingNotificationEvent,
100100
) { syncState, networkState, isInForeground, isInCall, isSyncingNotificationEvent ->
101101
val isAppActive = isInForeground || isInCall || isSyncingNotificationEvent
102-
val isNetworkAvailable = networkState == NetworkStatus.Online
102+
val isNetworkAvailable = networkState == NetworkStatus.Connected
103103

104104
Timber.tag(tag).d("isAppActive=$isAppActive, isNetworkAvailable=$isNetworkAvailable")
105105
if (syncState == SyncState.Running && !isAppActive) {

appnav/src/main/kotlin/io/element/android/appnav/loggedin/SendQueues.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class SendQueues @Inject constructor(
3232
) {
3333
/**
3434
* Launches the send queues retry mechanism in the given [coroutineScope].
35-
* Makes sure to re-enable all send queues when the network status is [NetworkStatus.Online].
35+
* Makes sure to re-enable all send queues when the network status is [NetworkStatus.Connected].
3636
*/
3737
@OptIn(FlowPreview::class)
3838
fun launchIn(coroutineScope: CoroutineScope) {

appnav/src/test/kotlin/io/element/android/appnav/DefaultSyncOrchestratorTest.kt

+7-7
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class DefaultSyncOrchestratorTest {
3939
val syncService = FakeSyncService(initialSyncState = SyncState.Idle).apply {
4040
startSyncLambda = startSyncRecorder
4141
}
42-
val networkMonitor = FakeNetworkMonitor(initialStatus = NetworkStatus.Offline)
42+
val networkMonitor = FakeNetworkMonitor(initialStatus = NetworkStatus.Disconnected)
4343
val syncOrchestrator = createSyncOrchestrator(syncService, networkMonitor)
4444

4545
// We start observing
@@ -61,7 +61,7 @@ class DefaultSyncOrchestratorTest {
6161
val syncService = FakeSyncService(initialSyncState = SyncState.Running).apply {
6262
stopSyncLambda = stopSyncRecorder
6363
}
64-
val networkMonitor = FakeNetworkMonitor(initialStatus = NetworkStatus.Online)
64+
val networkMonitor = FakeNetworkMonitor(initialStatus = NetworkStatus.Connected)
6565
val appForegroundStateService = FakeAppForegroundStateService(initialForegroundValue = true)
6666
val syncOrchestrator = createSyncOrchestrator(syncService, networkMonitor, appForegroundStateService)
6767

@@ -94,7 +94,7 @@ class DefaultSyncOrchestratorTest {
9494
startSyncLambda = startSyncRecorder
9595
stopSyncLambda = stopSyncRecorder
9696
}
97-
val networkMonitor = FakeNetworkMonitor(initialStatus = NetworkStatus.Online)
97+
val networkMonitor = FakeNetworkMonitor(initialStatus = NetworkStatus.Connected)
9898
val appForegroundStateService = FakeAppForegroundStateService(
9999
initialForegroundValue = false,
100100
initialIsSyncingNotificationEventValue = false,
@@ -141,7 +141,7 @@ class DefaultSyncOrchestratorTest {
141141
startSyncLambda = startSyncRecorder
142142
stopSyncLambda = stopSyncRecorder
143143
}
144-
val networkMonitor = FakeNetworkMonitor(initialStatus = NetworkStatus.Online)
144+
val networkMonitor = FakeNetworkMonitor(initialStatus = NetworkStatus.Connected)
145145
val appForegroundStateService = FakeAppForegroundStateService(
146146
initialForegroundValue = false,
147147
initialIsSyncingNotificationEventValue = false,
@@ -188,7 +188,7 @@ class DefaultSyncOrchestratorTest {
188188
startSyncLambda = startSyncRecorder
189189
stopSyncLambda = stopSyncRecorder
190190
}
191-
val networkMonitor = FakeNetworkMonitor(initialStatus = NetworkStatus.Online)
191+
val networkMonitor = FakeNetworkMonitor(initialStatus = NetworkStatus.Connected)
192192
val appForegroundStateService = FakeAppForegroundStateService(
193193
initialForegroundValue = true,
194194
initialIsSyncingNotificationEventValue = true,
@@ -230,7 +230,7 @@ class DefaultSyncOrchestratorTest {
230230
val syncService = FakeSyncService(initialSyncState = SyncState.Running).apply {
231231
stopSyncLambda = stopSyncRecorder
232232
}
233-
val networkMonitor = FakeNetworkMonitor(initialStatus = NetworkStatus.Online)
233+
val networkMonitor = FakeNetworkMonitor(initialStatus = NetworkStatus.Connected)
234234
val appForegroundStateService = FakeAppForegroundStateService(
235235
initialForegroundValue = true,
236236
initialIsSyncingNotificationEventValue = true,
@@ -263,7 +263,7 @@ class DefaultSyncOrchestratorTest {
263263
val syncService = FakeSyncService(initialSyncState = SyncState.Running).apply {
264264
startSyncLambda = startSyncRecorder
265265
}
266-
val networkMonitor = FakeNetworkMonitor(initialStatus = NetworkStatus.Offline)
266+
val networkMonitor = FakeNetworkMonitor(initialStatus = NetworkStatus.Disconnected)
267267
val syncOrchestrator = createSyncOrchestrator(syncService, networkMonitor)
268268

269269
// We start observing, we skip the initial sync attempt since the state is running

features/networkmonitor/api/src/main/kotlin/io/element/android/features/networkmonitor/api/NetworkStatus.kt

+14-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,19 @@
77

88
package io.element.android.features.networkmonitor.api
99

10+
/**
11+
* Network connectivity status of the device.
12+
*
13+
* **Note:** this is *network* connectivity status, not *internet* connectivity status.
14+
*/
1015
enum class NetworkStatus {
11-
Online,
12-
Offline
16+
/**
17+
* The device is connected to a network.
18+
*/
19+
Connected,
20+
21+
/**
22+
* The device is not connected to any networks.
23+
*/
24+
Disconnected
1325
}

features/networkmonitor/impl/src/main/kotlin/io/element/android/features/networkmonitor/impl/DefaultNetworkMonitor.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ class DefaultNetworkMonitor @Inject constructor(
5454

5555
override fun onLost(network: Network) {
5656
if (activeNetworksCount.decrementAndGet() == 0) {
57-
trySendBlocking(NetworkStatus.Offline)
57+
trySendBlocking(NetworkStatus.Disconnected)
5858
}
5959
}
6060

6161
override fun onAvailable(network: Network) {
6262
if (activeNetworksCount.incrementAndGet() > 0) {
63-
trySendBlocking(NetworkStatus.Online)
63+
trySendBlocking(NetworkStatus.Connected)
6464
}
6565
}
6666
}
@@ -82,6 +82,6 @@ class DefaultNetworkMonitor @Inject constructor(
8282
.stateIn(appCoroutineScope, SharingStarted.WhileSubscribed(), connectivityManager.activeNetworkStatus())
8383

8484
private fun ConnectivityManager.activeNetworkStatus(): NetworkStatus {
85-
return if (activeNetwork != null) NetworkStatus.Online else NetworkStatus.Offline
85+
return if (activeNetwork != null) NetworkStatus.Connected else NetworkStatus.Disconnected
8686
}
8787
}

features/networkmonitor/test/src/main/kotlin/io/element/android/features/networkmonitor/test/FakeNetworkMonitor.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ import io.element.android.features.networkmonitor.api.NetworkMonitor
1111
import io.element.android.features.networkmonitor.api.NetworkStatus
1212
import kotlinx.coroutines.flow.MutableStateFlow
1313

14-
class FakeNetworkMonitor(initialStatus: NetworkStatus = NetworkStatus.Online) : NetworkMonitor {
14+
class FakeNetworkMonitor(initialStatus: NetworkStatus = NetworkStatus.Connected) : NetworkMonitor {
1515
override val connectivity = MutableStateFlow(initialStatus)
1616
}

0 commit comments

Comments
 (0)