-
Notifications
You must be signed in to change notification settings - Fork 6
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 #759 from radixdlt/feature/ABW-2754-show-addlinkco…
…nnector-only-when-no-linkconnectors [ABW-2754] Show add link connector screen only when no link connectors available and connector status indicator
- Loading branch information
Showing
22 changed files
with
360 additions
and
130 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
app/src/main/java/com/babylon/wallet/android/LinkConnectionStatusObserver.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,66 @@ | ||
package com.babylon.wallet.android | ||
|
||
import androidx.compose.ui.graphics.Color | ||
import com.babylon.wallet.android.di.coroutines.ApplicationScope | ||
import com.babylon.wallet.android.utils.Constants | ||
import kotlinx.collections.immutable.ImmutableList | ||
import kotlinx.collections.immutable.persistentListOf | ||
import kotlinx.collections.immutable.toPersistentList | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.flow.SharingStarted | ||
import kotlinx.coroutines.flow.map | ||
import kotlinx.coroutines.flow.stateIn | ||
import rdx.works.core.preferences.PreferencesManager | ||
import rdx.works.peerdroid.data.PeerdroidConnector | ||
import rdx.works.peerdroid.domain.PeerConnectionStatus | ||
import javax.inject.Inject | ||
|
||
class LinkConnectionStatusObserver @Inject constructor( | ||
peerdroidConnector: PeerdroidConnector, | ||
preferencesManager: PreferencesManager, | ||
@ApplicationScope private val applicationScope: CoroutineScope | ||
) { | ||
|
||
val isEnabled = preferencesManager | ||
.isLinkConnectionStatusIndicatorEnabled | ||
.stateIn( | ||
scope = applicationScope, | ||
started = SharingStarted.WhileSubscribed(Constants.VM_STOP_TIMEOUT_MS), | ||
initialValue = true | ||
) | ||
|
||
val currentStatus = peerdroidConnector | ||
.peerConnectionStatus | ||
.map { mapOfPeerConnectionStatus -> | ||
LinkConnectionsStatus( | ||
peerConnectionStatus = mapOfPeerConnectionStatus.values.toPersistentList() | ||
) | ||
} | ||
.stateIn( | ||
scope = applicationScope, | ||
started = SharingStarted.WhileSubscribed(Constants.VM_STOP_TIMEOUT_MS), | ||
initialValue = LinkConnectionsStatus() | ||
) | ||
|
||
data class LinkConnectionsStatus( | ||
private val peerConnectionStatus: ImmutableList<PeerConnectionStatus> = persistentListOf() | ||
) { | ||
|
||
fun currentStatus() = peerConnectionStatus | ||
.map { state -> | ||
when (state) { | ||
PeerConnectionStatus.OPEN -> { | ||
Color.Green | ||
} | ||
|
||
PeerConnectionStatus.CLOSED -> { | ||
Color.Red | ||
} | ||
|
||
PeerConnectionStatus.CONNECTING -> { | ||
Color.Yellow | ||
} | ||
} | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.