diff options
| author | Albin <albin@mullvad.net> | 2022-06-15 09:52:28 +0200 |
|---|---|---|
| committer | Albin <albin@mullvad.net> | 2022-06-15 10:25:32 +0200 |
| commit | 2d5c5269d814558c9ef511d90a027176fe498057 (patch) | |
| tree | abe3b960b07ec25cce4ac4df051934d51616e87a /android | |
| parent | e1140b9446e5baaaf72d642d1abdb722357becb8 (diff) | |
| download | mullvadvpn-2d5c5269d814558c9ef511d90a027176fe498057.tar.xz mullvadvpn-2d5c5269d814558c9ef511d90a027176fe498057.zip | |
Simplify device transition flow
Diffstat (limited to 'android')
3 files changed, 35 insertions, 18 deletions
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/model/Device.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/model/Device.kt index 01a8e6ee37..21341dca54 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/model/Device.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/model/Device.kt @@ -9,4 +9,28 @@ data class Device( val name: String, val pubkey: ByteArray, val ports: ArrayList<String> -) : Parcelable +) : Parcelable { + // Generated by Android Studio + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + other as Device + + if (id != other.id) return false + if (name != other.name) return false + if (!pubkey.contentEquals(other.pubkey)) return false + if (ports != other.ports) return false + + return true + } + + // Generated by Android Studio + override fun hashCode(): Int { + var result = id.hashCode() + result = 31 * result + name.hashCode() + result = 31 * result + pubkey.contentHashCode() + result = 31 * result + ports.hashCode() + return result + } +} diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/model/DeviceState.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/model/DeviceState.kt index 7745d13214..e23f0857d1 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/model/DeviceState.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/model/DeviceState.kt @@ -11,7 +11,7 @@ sealed class DeviceState : Parcelable { object Unknown : DeviceState() @Parcelize - class LoggedIn(val accountAndDevice: AccountAndDevice) : DeviceState() + data class LoggedIn(val accountAndDevice: AccountAndDevice) : DeviceState() @Parcelize object LoggedOut : DeviceState() diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/MainActivity.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/MainActivity.kt index 5e00472bc4..204635a161 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/MainActivity.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/MainActivity.kt @@ -15,11 +15,8 @@ import androidx.fragment.app.FragmentManager import androidx.lifecycle.Lifecycle import androidx.lifecycle.flowWithLifecycle import androidx.lifecycle.lifecycleScope -import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.collect import kotlinx.coroutines.flow.debounce -import kotlinx.coroutines.flow.distinctUntilChangedBy -import kotlinx.coroutines.flow.filter import kotlinx.coroutines.launch import net.mullvad.mullvadvpn.BuildConfig import net.mullvad.mullvadvpn.R @@ -161,25 +158,21 @@ open class MainActivity : FragmentActivity() { // Debounce DeviceState.Unknown to delay view transitions during reconnect. it.addDebounceForUnknownState() } - .distinctByDeviceState() - .filter { newState -> newState != currentState } .collect { newState -> - when (newState) { - is DeviceState.Initial, - is DeviceState.Unknown -> openLaunchView() - is DeviceState.LoggedOut -> openLoginView() - is DeviceState.Revoked -> openRevokedView() - is DeviceState.LoggedIn -> openConnectView() + if (newState != currentState) { + when (newState) { + is DeviceState.Initial, + is DeviceState.Unknown -> openLaunchView() + is DeviceState.LoggedOut -> openLoginView() + is DeviceState.Revoked -> openRevokedView() + is DeviceState.LoggedIn -> openConnectView() + } + currentState = newState } - currentState = newState } } } - private fun Flow<DeviceState>.distinctByDeviceState(): Flow<DeviceState> { - return this.distinctUntilChangedBy { it::class } - } - private fun DeviceState.addDebounceForUnknownState(): Long { return if (this is DeviceState.Unknown) { UNKNOWN_STATE_DEBOUNCE_DELAY_MILLISECONDS |
