Better info about relays in the Top Nav bar

pull/3/head
Vitor Pamplona 2023-01-13 21:35:12 -05:00
rodzic 5859ae2c52
commit 353046b451
2 zmienionych plików z 9 dodań i 5 usunięć

Wyświetl plik

@ -53,7 +53,8 @@ fun MainTopBar(scaffoldState: ScaffoldState, accountViewModel: AccountViewModel)
val accountUser = accountUserState?.user val accountUser = accountUserState?.user
val relayViewModel: RelayPoolViewModel = viewModel { RelayPoolViewModel() } val relayViewModel: RelayPoolViewModel = viewModel { RelayPoolViewModel() }
val relayPoolLiveData by relayViewModel.relayPoolLiveData.observeAsState() val connectedRelaysLiveData by relayViewModel.connectedRelaysLiveData.observeAsState()
val availableRelaysLiveData by relayViewModel.availableRelaysLiveData.observeAsState()
val coroutineScope = rememberCoroutineScope() val coroutineScope = rememberCoroutineScope()
@ -105,8 +106,8 @@ fun MainTopBar(scaffoldState: ScaffoldState, accountViewModel: AccountViewModel)
}, },
actions = { actions = {
Text( Text(
relayPoolLiveData ?: "--/--", "${connectedRelaysLiveData ?: "--"}/${availableRelaysLiveData ?: "--"}",
color = MaterialTheme.colors.onSurface.copy(alpha = 0.32f) color = if (connectedRelaysLiveData == 0) Color.Red else MaterialTheme.colors.onSurface.copy(alpha = 0.32f)
) )
IconButton( IconButton(

Wyświetl plik

@ -6,7 +6,10 @@ import androidx.lifecycle.ViewModel
import com.vitorpamplona.amethyst.service.relays.RelayPool import com.vitorpamplona.amethyst.service.relays.RelayPool
class RelayPoolViewModel: ViewModel() { class RelayPoolViewModel: ViewModel() {
val relayPoolLiveData: LiveData<String> = Transformations.map(RelayPool.live) { val connectedRelaysLiveData: LiveData<Int> = Transformations.map(RelayPool.live) {
it.relays.report() it.relays.connectedRelays()
}
val availableRelaysLiveData: LiveData<Int> = Transformations.map(RelayPool.live) {
it.relays.availableRelays()
} }
} }