android: fix import (#400)

Updates #cleanup

Signed-off-by: kari-ts <kari@tailscale.com>
pull/401/head
kari-ts 7 months ago committed by GitHub
parent 12ad295706
commit 0ff47f7ab5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -18,7 +18,6 @@ import com.tailscale.ipn.ui.util.PeerCategorizer
import com.tailscale.ipn.ui.util.PeerSet import com.tailscale.ipn.ui.util.PeerSet
import com.tailscale.ipn.ui.util.TimeUtil import com.tailscale.ipn.ui.util.TimeUtil
import com.tailscale.ipn.ui.util.set import com.tailscale.ipn.ui.util.set
import com.tailscale.ipn.App
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.combine
@ -63,18 +62,19 @@ class MainViewModel : IpnViewModel() {
combine(Notifier.state, vpnPrepared) { state, prepared -> state to prepared } combine(Notifier.state, vpnPrepared) { state, prepared -> state to prepared }
.collect { (currentState, prepared) -> .collect { (currentState, prepared) ->
stateRes.set(userStringRes(currentState, previousState, prepared)) stateRes.set(userStringRes(currentState, previousState, prepared))
val isOn = when { val isOn =
when {
currentState == State.Running || currentState == State.Starting -> true currentState == State.Running || currentState == State.Starting -> true
previousState == State.NoState && currentState == State.Starting -> true previousState == State.NoState && currentState == State.Starting -> true
else -> false else -> false
} }
_vpnToggleState.value = isOn _vpnToggleState.value = isOn
previousState = currentState previousState = currentState
} }
} }
viewModelScope.launch { viewModelScope.launch {
Notifier.netmap.collect { it -> Notifier.netmap.collect { it ->
@ -118,11 +118,11 @@ class MainViewModel : IpnViewModel() {
val isPrepared = vpnPrepared.value val isPrepared = vpnPrepared.value
when { when {
!isPrepared -> showVPNPermissionLauncherIfUnauthorized() !isPrepared -> showVPNPermissionLauncherIfUnauthorized()
state == Ipn.State.Running -> stopVPN() state == Ipn.State.Running -> stopVPN()
else -> startVPN() else -> startVPN()
} }
} }
fun searchPeers(searchTerm: String) { fun searchPeers(searchTerm: String) {
this.searchTerm.set(searchTerm) this.searchTerm.set(searchTerm)
@ -139,15 +139,15 @@ class MainViewModel : IpnViewModel() {
private fun userStringRes(currentState: State?, previousState: State?, vpnPrepared: Boolean): Int { private fun userStringRes(currentState: State?, previousState: State?, vpnPrepared: Boolean): Int {
return when { return when {
previousState == State.NoState && currentState == State.Starting -> R.string.starting previousState == State.NoState && currentState == State.Starting -> R.string.starting
currentState == State.NoState -> R.string.placeholder currentState == State.NoState -> R.string.placeholder
currentState == State.InUseOtherUser -> R.string.placeholder currentState == State.InUseOtherUser -> R.string.placeholder
currentState == State.NeedsLogin -> if (vpnPrepared) R.string.please_login else R.string.connect_to_vpn currentState == State.NeedsLogin ->
currentState == State.NeedsMachineAuth -> R.string.needs_machine_auth if (vpnPrepared) R.string.please_login else R.string.connect_to_vpn
currentState == State.Stopped -> R.string.stopped currentState == State.NeedsMachineAuth -> R.string.needs_machine_auth
currentState == State.Starting -> R.string.starting currentState == State.Stopped -> R.string.stopped
currentState == State.Running -> R.string.connected currentState == State.Starting -> R.string.starting
else -> R.string.placeholder currentState == State.Running -> R.string.connected
else -> R.string.placeholder
} }
return resId
} }
Loading…
Cancel
Save