summaryrefslogtreecommitdiffhomepage
path: root/android
diff options
context:
space:
mode:
authorAlbin <albin@mullvad.net>2022-06-14 08:07:38 +0200
committerAlbin <albin@mullvad.net>2022-06-15 10:25:32 +0200
commite1140b9446e5baaaf72d642d1abdb722357becb8 (patch)
treef7615af13bc80f3ce2ea29ad57254fb6c30cc93e /android
parent8064ca4de5adc5da6b4210d0dd6ea666f4dfe2f5 (diff)
downloadmullvadvpn-e1140b9446e5baaaf72d642d1abdb722357becb8.tar.xz
mullvadvpn-e1140b9446e5baaaf72d642d1abdb722357becb8.zip
Improve revoked ui state
Diffstat (limited to 'android')
-rw-r--r--android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/DeviceRevokedScreenTest.kt6
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/DeviceRevokedScreen.kt5
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/state/DeviceRevokedUiState.kt12
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/fragments/DeviceRevokedFragment.kt3
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/DeviceRevokedViewModel.kt16
-rw-r--r--android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/DeviceRevokedViewModelTest.kt8
6 files changed, 27 insertions, 23 deletions
diff --git a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/DeviceRevokedScreenTest.kt b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/DeviceRevokedScreenTest.kt
index 1590dcc497..13d98455c5 100644
--- a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/DeviceRevokedScreenTest.kt
+++ b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/DeviceRevokedScreenTest.kt
@@ -35,7 +35,7 @@ class DeviceRevokedScreenTest {
// Arrange
every {
mockedViewModel.uiState
- } returns MutableStateFlow(DeviceRevokedUiState(isSecured = true))
+ } returns MutableStateFlow(DeviceRevokedUiState.SECURED)
// Act
composeTestRule.setContent {
@@ -55,7 +55,7 @@ class DeviceRevokedScreenTest {
// Arrange
every {
mockedViewModel.uiState
- } returns MutableStateFlow(DeviceRevokedUiState(isSecured = false))
+ } returns MutableStateFlow(DeviceRevokedUiState.UNSECURED)
// Act
composeTestRule.setContent {
@@ -75,7 +75,7 @@ class DeviceRevokedScreenTest {
// Arrange
every {
mockedViewModel.uiState
- } returns MutableStateFlow(DeviceRevokedUiState(isSecured = false))
+ } returns MutableStateFlow(DeviceRevokedUiState.UNSECURED)
composeTestRule.setContent {
AppTheme {
DeviceRevokedScreen(mockedViewModel)
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/DeviceRevokedScreen.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/DeviceRevokedScreen.kt
index a559cd0cf9..d1ae33d0e5 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/DeviceRevokedScreen.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/DeviceRevokedScreen.kt
@@ -23,6 +23,7 @@ import androidx.constraintlayout.compose.ConstraintLayout
import androidx.constraintlayout.compose.Dimension
import net.mullvad.mullvadvpn.R
import net.mullvad.mullvadvpn.compose.component.ActionButton
+import net.mullvad.mullvadvpn.compose.state.DeviceRevokedUiState
import net.mullvad.mullvadvpn.viewmodel.DeviceRevokedViewModel
@Composable
@@ -76,7 +77,7 @@ fun DeviceRevokedScreen(
modifier = Modifier.padding(top = 10.dp)
)
- if (state.isSecured) {
+ if (state == DeviceRevokedUiState.SECURED) {
Text(
text = stringResource(id = R.string.device_inactive_unblock_warning),
fontSize = 12.sp,
@@ -96,7 +97,7 @@ fun DeviceRevokedScreen(
}
) {
val buttonColor = colorResource(
- if (state.isSecured) {
+ if (state == DeviceRevokedUiState.SECURED) {
R.color.red60
} else {
R.color.blue
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/state/DeviceRevokedUiState.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/state/DeviceRevokedUiState.kt
index f8465423ed..b2223e77e4 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/state/DeviceRevokedUiState.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/state/DeviceRevokedUiState.kt
@@ -1,11 +1,7 @@
package net.mullvad.mullvadvpn.compose.state
-data class DeviceRevokedUiState(
- val isSecured: Boolean
-) {
- companion object {
- val DEFAULT = DeviceRevokedUiState(
- isSecured = false
- )
- }
+enum class DeviceRevokedUiState {
+ SECURED,
+ UNSECURED,
+ UNKNOWN
}
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/fragments/DeviceRevokedFragment.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/fragments/DeviceRevokedFragment.kt
index 69b7f31111..3b614be03c 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/fragments/DeviceRevokedFragment.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/fragments/DeviceRevokedFragment.kt
@@ -12,6 +12,7 @@ import net.mullvad.mullvadvpn.R
import net.mullvad.mullvadvpn.compose.component.AppTheme
import net.mullvad.mullvadvpn.compose.component.ScaffoldWithTopBar
import net.mullvad.mullvadvpn.compose.screen.DeviceRevokedScreen
+import net.mullvad.mullvadvpn.compose.state.DeviceRevokedUiState
import net.mullvad.mullvadvpn.ui.MainActivity
import net.mullvad.mullvadvpn.viewmodel.DeviceRevokedViewModel
import org.koin.androidx.viewmodel.ext.android.viewModel
@@ -30,7 +31,7 @@ class DeviceRevokedFragment : Fragment() {
val state = deviceRevokedViewModel.uiState.collectAsState().value
val topColor = colorResource(
- if (state.isSecured) {
+ if (state == DeviceRevokedUiState.SECURED) {
R.color.green
} else {
R.color.red
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/DeviceRevokedViewModel.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/DeviceRevokedViewModel.kt
index aca1f9f9eb..d3975fbd08 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/DeviceRevokedViewModel.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/DeviceRevokedViewModel.kt
@@ -9,7 +9,6 @@ import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import net.mullvad.mullvadvpn.compose.state.DeviceRevokedUiState
-import net.mullvad.mullvadvpn.model.TunnelState
import net.mullvad.mullvadvpn.ui.serviceconnection.ServiceConnectionContainer
import net.mullvad.mullvadvpn.ui.serviceconnection.ServiceConnectionManager
import net.mullvad.talpid.util.callbackFlowFromSubscription
@@ -24,14 +23,21 @@ class DeviceRevokedViewModel(
val uiState = serviceConnectionManager.connectionState
.map { connectionState -> connectionState.readyContainer()?.connectionProxy }
.flatMapLatest { proxy ->
- proxy?.onUiStateChange?.callbackFlowFromSubscription(this)
- ?: flowOf(TunnelState.Disconnected)
+ proxy?.onUiStateChange
+ ?.callbackFlowFromSubscription(this)
+ ?.map {
+ if (it.isSecured()) {
+ DeviceRevokedUiState.SECURED
+ } else {
+ DeviceRevokedUiState.UNSECURED
+ }
+ }
+ ?: flowOf(DeviceRevokedUiState.UNKNOWN)
}
- .map { DeviceRevokedUiState(it.isSecured()) }
.stateIn(
scope,
SharingStarted.Lazily,
- DeviceRevokedUiState.DEFAULT
+ DeviceRevokedUiState.UNKNOWN
)
fun onGoToLoginClicked() {
diff --git a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/DeviceRevokedViewModelTest.kt b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/DeviceRevokedViewModelTest.kt
index d8f4fdf119..69941a474d 100644
--- a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/DeviceRevokedViewModelTest.kt
+++ b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/DeviceRevokedViewModelTest.kt
@@ -59,7 +59,7 @@ class DeviceRevokedViewModelTest {
// Arrange, Act, Assert
viewModel.uiState.test {
serviceConnectionState.value = ServiceConnectionState.Disconnected
- assertEquals(DeviceRevokedUiState(false), awaitItem())
+ assertEquals(DeviceRevokedUiState.UNKNOWN, awaitItem())
}
}
@@ -68,7 +68,7 @@ class DeviceRevokedViewModelTest {
// Arrange, Act, Assert
viewModel.uiState.test {
serviceConnectionState.value = ServiceConnectionState.ConnectedNotReady(mockk())
- assertEquals(DeviceRevokedUiState(false), awaitItem())
+ assertEquals(DeviceRevokedUiState.UNKNOWN, awaitItem())
}
}
@@ -89,9 +89,9 @@ class DeviceRevokedViewModelTest {
// Act, Assert
viewModel.uiState.test {
- assertEquals(DeviceRevokedUiState(false), awaitItem())
+ assertEquals(DeviceRevokedUiState.UNKNOWN, awaitItem())
serviceConnectionState.value = ServiceConnectionState.ConnectedReady(mockedContainer)
- assertEquals(DeviceRevokedUiState(true), awaitItem())
+ assertEquals(DeviceRevokedUiState.SECURED, awaitItem())
}
}