Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add info dialog for device name #5033

Merged
merged 1 commit into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import io.mockk.mockk
import io.mockk.verify
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.asSharedFlow
import net.mullvad.mullvadvpn.compose.state.AccountUiState
import net.mullvad.mullvadvpn.viewmodel.AccountUiState
import net.mullvad.mullvadvpn.viewmodel.AccountViewModel
import org.junit.Before
import org.junit.Rule
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package net.mullvad.mullvadvpn.compose.dialog

import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import net.mullvad.mullvadvpn.R

@Composable
fun DeviceNameInfoDialog(onDismiss: () -> Unit) {
InfoDialog(
message = stringResource(id = R.string.local_network_sharing_info),
additionalInfo =
buildString {
appendLine(stringResource(id = R.string.device_name_info_part1))
appendLine(stringResource(id = R.string.device_name_info_part2))
appendLine(stringResource(id = R.string.device_name_info_part3))
},
onDismiss = onDismiss
)
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package net.mullvad.mullvadvpn.compose.screen

import androidx.compose.animation.animateContentSize
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
Expand All @@ -19,6 +21,7 @@ import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import com.google.accompanist.systemuicontroller.rememberSystemUiController
Expand All @@ -35,12 +38,14 @@ import net.mullvad.mullvadvpn.compose.component.CopyableObfuscationView
import net.mullvad.mullvadvpn.compose.component.InformationView
import net.mullvad.mullvadvpn.compose.component.MissingPolicy
import net.mullvad.mullvadvpn.compose.component.drawVerticalScrollbar
import net.mullvad.mullvadvpn.compose.state.AccountUiState
import net.mullvad.mullvadvpn.compose.dialog.DeviceNameInfoDialog
import net.mullvad.mullvadvpn.constant.IS_PLAY_BUILD
import net.mullvad.mullvadvpn.lib.common.util.capitalizeFirstCharOfEachWord
import net.mullvad.mullvadvpn.lib.common.util.openAccountPageInBrowser
import net.mullvad.mullvadvpn.lib.theme.Dimens
import net.mullvad.mullvadvpn.util.toExpiryDateString
import net.mullvad.mullvadvpn.viewmodel.AccountScreenDialogState
import net.mullvad.mullvadvpn.viewmodel.AccountUiState
import net.mullvad.mullvadvpn.viewmodel.AccountViewModel

@OptIn(ExperimentalMaterial3Api::class)
Expand All @@ -52,7 +57,8 @@ private fun PreviewAccountScreen() {
AccountUiState(
deviceName = "Test Name",
accountNumber = "1234123412341234",
accountExpiry = null
accountExpiry = null,
dialogState = AccountScreenDialogState.NoDialog
),
viewActions = MutableSharedFlow<AccountViewModel.ViewAction>().asSharedFlow(),
enterTransitionEndAction = MutableSharedFlow()
Expand All @@ -64,6 +70,8 @@ private fun PreviewAccountScreen() {
fun AccountScreen(
uiState: AccountUiState,
viewActions: SharedFlow<AccountViewModel.ViewAction>,
onDeviceNameInfoClick: () -> Unit = {},
onDismissInfoClick: () -> Unit = {},
enterTransitionEndAction: SharedFlow<Unit>,
onRedeemVoucherClick: () -> Unit = {},
onManageAccountClick: () -> Unit = {},
Expand All @@ -79,6 +87,10 @@ fun AccountScreen(
LaunchedEffect(Unit) {
enterTransitionEndAction.collect { systemUiController.setStatusBarColor(backgroundColor) }
}
if (uiState.dialogState == AccountScreenDialogState.DeviceNameInfoDialog) {
DeviceNameInfoDialog(onDismissInfoClick)
}

CollapsingToolbarScaffold(
backgroundColor = MaterialTheme.colorScheme.background,
modifier = Modifier.fillMaxSize(),
Expand Down Expand Up @@ -127,10 +139,21 @@ fun AccountScreen(
modifier = Modifier.padding(start = Dimens.sideMargin, end = Dimens.sideMargin)
)

InformationView(
content = uiState.deviceName.capitalizeFirstCharOfEachWord(),
whenMissing = MissingPolicy.SHOW_SPINNER
)
Row {
InformationView(
content = uiState.deviceName?.capitalizeFirstCharOfEachWord() ?: "",
whenMissing = MissingPolicy.SHOW_SPINNER
)
Icon(
modifier =
Modifier.clickable { onDeviceNameInfoClick() }
.padding(start = Dimens.mediumPadding, end = Dimens.mediumPadding)
.align(Alignment.CenterVertically),
painter = painterResource(id = R.drawable.icon_info),
contentDescription = null,
tint = MaterialTheme.colorScheme.inverseSurface
)
}

Text(
style = MaterialTheme.typography.labelMedium,
Expand All @@ -142,9 +165,7 @@ fun AccountScreen(
top = Dimens.smallPadding
)
)

CopyableObfuscationView(content = uiState.accountNumber)

CopyableObfuscationView(content = uiState.accountNumber ?: "")
Text(
style = MaterialTheme.typography.labelMedium,
text = stringResource(id = R.string.paid_until),
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ class AccountFragment : BaseFragment(), StatusBarPainter, NavigationBarPainter {
enterTransitionEndAction = vm.enterTransitionEndAction,
onRedeemVoucherClick = { openRedeemVoucherFragment() },
onManageAccountClick = vm::onManageAccountClick,
onLogoutClick = vm::onLogoutClick
) {
activity?.onBackPressed()
}
onLogoutClick = vm::onLogoutClick,
onDeviceNameInfoClick = vm::onDeviceNameInfoClick,
onDismissInfoClick = vm::onDismissInfoClick,
onBackClick = { activity?.onBackPressedDispatcher?.onBackPressed() }
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package net.mullvad.mullvadvpn.viewmodel

import net.mullvad.mullvadvpn.model.AccountExpiry
import net.mullvad.mullvadvpn.model.DeviceState
import org.joda.time.DateTime

data class AccountUiState(
val deviceName: String?,
val accountNumber: String?,
val accountExpiry: DateTime?,
val dialogState: AccountScreenDialogState = AccountScreenDialogState.NoDialog
) {
companion object {
fun default() =
AccountUiState(
deviceName = DeviceState.Unknown.deviceName(),
accountNumber = DeviceState.Unknown.token(),
accountExpiry = AccountExpiry.Missing.date(),
dialogState = AccountScreenDialogState.NoDialog
)
}
}

sealed class AccountScreenDialogState {
data object NoDialog : AccountScreenDialogState()

data object DeviceNameInfoDialog : AccountScreenDialogState()
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package net.mullvad.mullvadvpn.viewmodel
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import net.mullvad.mullvadvpn.compose.state.AccountUiState
import net.mullvad.mullvadvpn.repository.AccountRepository
import net.mullvad.mullvadvpn.repository.DeviceRepository
import net.mullvad.mullvadvpn.ui.serviceconnection.ServiceConnectionManager
Expand All @@ -25,27 +26,24 @@ class AccountViewModel(
private val _enterTransitionEndAction = MutableSharedFlow<Unit>()
val viewActions = _viewActions.asSharedFlow()

private val dialogState =
MutableStateFlow<AccountScreenDialogState>(AccountScreenDialogState.NoDialog)

private val vmState: StateFlow<AccountUiState> =
combine(deviceRepository.deviceState, accountRepository.accountExpiryState) {
combine(deviceRepository.deviceState, accountRepository.accountExpiryState, dialogState) {
deviceState,
accountExpiry ->
accountExpiry,
dialogState ->
AccountUiState(
deviceName = deviceState.deviceName() ?: "",
accountNumber = deviceState.token() ?: "",
accountExpiry = accountExpiry.date()
deviceName = deviceState.deviceName(),
accountNumber = deviceState.token(),
accountExpiry = accountExpiry.date(),
dialogState = dialogState
)
}
.stateIn(
viewModelScope,
SharingStarted.WhileSubscribed(),
AccountUiState(deviceName = "", accountNumber = "", accountExpiry = null)
)
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), AccountUiState.default())
val uiState =
vmState.stateIn(
viewModelScope,
SharingStarted.WhileSubscribed(),
AccountUiState(deviceName = "", accountNumber = "", accountExpiry = null)
)
vmState.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), AccountUiState.default())

val enterTransitionEndAction = _enterTransitionEndAction.asSharedFlow()

Expand All @@ -63,6 +61,18 @@ class AccountViewModel(
accountRepository.logout()
}

fun onDeviceNameInfoClick() {
dialogState.update { AccountScreenDialogState.DeviceNameInfoDialog }
}

fun onDismissInfoClick() {
hideDialog()
}

private fun hideDialog() {
dialogState.update { AccountScreenDialogState.NoDialog }
}

fun onTransitionAnimationEnd() {
viewModelScope.launch { _enterTransitionEndAction.emit(Unit) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class AccountViewModelTest {
// Act, Assert
viewModel.uiState.test {
var result = awaitItem()
assertEquals("", result.deviceName)
assertEquals(null, result.deviceName)
deviceState.value = DeviceState.LoggedIn(accountAndDevice = dummyAccountAndDevice)
result = awaitItem()
assertEquals(DUMMY_DEVICE_NAME, result.accountNumber)
Expand Down
6 changes: 3 additions & 3 deletions android/lib/resource/src/main/res/values-da/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@
<string name="device_inactive_title">Enheden er inaktiv</string>
<string name="device_inactive_unblock_warning">Hvis du logger på, ophæves blokeringen af internettet på denne enhed.</string>
<string name="device_name">Enhedsnavn</string>
<string name="device_name_info_first_paragraph">Dette er det navn, der er tildelt enheden. Hver enhed, der er logget på en Mullvad-konto, får et unikt navn, der hjælper dig med at identificere den, når du administrerer dine enheder i appen eller på webstedet.</string>
<string name="device_name_info_second_paragraph">Du kan have op til 5 enheder logget ind på én Mullvad-konto.</string>
<string name="device_name_info_third_paragraph">Hvis du logger ud, fjernes enheden og enhedsnavnet. Når du logger på igen, får enheden et nyt navn.</string>
<string name="device_name_info_part1">Dette er det navn, der er tildelt enheden. Hver enhed, der er logget på en Mullvad-konto, får et unikt navn, der hjælper dig med at identificere den, når du administrerer dine enheder i appen eller på webstedet.</string>
<string name="device_name_info_part2">Du kan have op til 5 enheder logget ind på én Mullvad-konto.</string>
<string name="device_name_info_part3">Hvis du logger ud, fjernes enheden og enhedsnavnet. Når du logger på igen, får enheden et nyt navn.</string>
<string name="disconnect">Afbryd forbindelse</string>
<string name="disconnecting">Afbryder</string>
<string name="dismiss">Afvis</string>
Expand Down
6 changes: 3 additions & 3 deletions android/lib/resource/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@
<string name="device_inactive_title">Gerät ist inaktiv</string>
<string name="device_inactive_unblock_warning">Wenn Sie mit der Anmeldung fortfahren, wird die Internetsperre auf diesem Gerät aufgehoben.</string>
<string name="device_name">Gerätename</string>
<string name="device_name_info_first_paragraph">Dies ist der dem Gerät zugewiesene Name. Jedes Gerät, das in einem Mullvad-Konto angemeldet ist, erhält einen eindeutigen Namen, mit dem Sie es identifizieren können, wenn Sie Ihre Geräte in der App oder auf der Website verwalten.</string>
<string name="device_name_info_second_paragraph">Es sind pro Mullvad-Konto bis zu 5 angemeldete Geräte möglich.</string>
<string name="device_name_info_third_paragraph">Wenn Sie sich abmelden, werden das Gerät und der Gerätename entfernt. Wenn Sie sich wieder anmelden, erhält das Gerät einen neuen Namen.</string>
<string name="device_name_info_part1">Dies ist der dem Gerät zugewiesene Name. Jedes Gerät, das in einem Mullvad-Konto angemeldet ist, erhält einen eindeutigen Namen, mit dem Sie es identifizieren können, wenn Sie Ihre Geräte in der App oder auf der Website verwalten.</string>
<string name="device_name_info_part2">Es sind pro Mullvad-Konto bis zu 5 angemeldete Geräte möglich.</string>
<string name="device_name_info_part3">Wenn Sie sich abmelden, werden das Gerät und der Gerätename entfernt. Wenn Sie sich wieder anmelden, erhält das Gerät einen neuen Namen.</string>
<string name="disconnect">Verbindung trennen</string>
<string name="disconnecting">Verbindung wird getrennt</string>
<string name="dismiss">Ausblenden</string>
Expand Down
6 changes: 3 additions & 3 deletions android/lib/resource/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@
<string name="device_inactive_title">El dispositivo está inactivo</string>
<string name="device_inactive_unblock_warning">Al iniciar la sesión, se desbloqueará el acceso a Internet en este dispositivo.</string>
<string name="device_name">Nombre del dispositivo</string>
<string name="device_name_info_first_paragraph">Este es el nombre asignado al dispositivo. Cada dispositivo conectado a una cuenta de Mullvad recibe un nombre único que ayuda a identificarlo cuando gestiona sus dispositivos en la aplicación o en el sitio web.</string>
<string name="device_name_info_second_paragraph">Puede tener hasta 5 dispositivos conectados a una cuenta de Mullvad.</string>
<string name="device_name_info_third_paragraph">Si cierra sesión, se quita el dispositivo y el nombre del dispositivo. Cuando vuelve a iniciar sesión, el dispositivo recibirá un nombre nuevo.</string>
<string name="device_name_info_part1">Este es el nombre asignado al dispositivo. Cada dispositivo conectado a una cuenta de Mullvad recibe un nombre único que ayuda a identificarlo cuando gestiona sus dispositivos en la aplicación o en el sitio web.</string>
<string name="device_name_info_part2">Puede tener hasta 5 dispositivos conectados a una cuenta de Mullvad.</string>
<string name="device_name_info_part3">Si cierra sesión, se quita el dispositivo y el nombre del dispositivo. Cuando vuelve a iniciar sesión, el dispositivo recibirá un nombre nuevo.</string>
<string name="disconnect">Desconectar</string>
<string name="disconnecting">Desconectando</string>
<string name="dismiss">Descartar</string>
Expand Down
6 changes: 3 additions & 3 deletions android/lib/resource/src/main/res/values-fi/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@
<string name="device_inactive_title">Laite ei ole aktiivinen</string>
<string name="device_inactive_unblock_warning">Kirjautumiseen siirtyminen purkaa internetin käytön eston tältä laitteelta.</string>
<string name="device_name">Laitteen nimi</string>
<string name="device_name_info_first_paragraph">Tämä on laitteelle annettu nimi. Jokainen Mullvad-tilille kirjautunut laite saa yksilöllisen nimen, jonka avulla sen voi tunnistaa laitteiden hallinnassa sovelluksessa tai verkkosivustolla.</string>
<string name="device_name_info_second_paragraph">Yhdelle Mullvad-tilille voi olla kirjautuneena enintään viisi laitetta.</string>
<string name="device_name_info_third_paragraph">Jos kirjaudut ulos, laite ja laitteen nimi poistetaan. Kun kirjaudut sisään uudelleen, laitteelle annetaan uusi nimi.</string>
<string name="device_name_info_part1">Tämä on laitteelle annettu nimi. Jokainen Mullvad-tilille kirjautunut laite saa yksilöllisen nimen, jonka avulla sen voi tunnistaa laitteiden hallinnassa sovelluksessa tai verkkosivustolla.</string>
<string name="device_name_info_part2">Yhdelle Mullvad-tilille voi olla kirjautuneena enintään viisi laitetta.</string>
<string name="device_name_info_part3">Jos kirjaudut ulos, laite ja laitteen nimi poistetaan. Kun kirjaudut sisään uudelleen, laitteelle annetaan uusi nimi.</string>
<string name="disconnect">Katkaise yhteys</string>
<string name="disconnecting">Katkaistaan yhteyttä</string>
<string name="dismiss">Jätä huomiotta</string>
Expand Down
6 changes: 3 additions & 3 deletions android/lib/resource/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@
<string name="device_inactive_title">L\'appareil est inactif</string>
<string name="device_inactive_unblock_warning">Aller à la connexion débloquera la connexion Internet sur cet appareil.</string>
<string name="device_name">Nom de l\'appareil</string>
<string name="device_name_info_first_paragraph">Il s\'agit du nom attribué à l\'appareil. Chaque appareil connecté à un compte Mullvad reçoit un nom unique qui vous aide à l\'identifier lorsque vous gérez vos appareils dans l\'application ou sur le site Web.</string>
<string name="device_name_info_second_paragraph">Vous pouvez connecter jusqu\'à 5 appareils au même compte Mullvad.</string>
<string name="device_name_info_third_paragraph">Si vous vous déconnectez, l\'appareil et son nom sont supprimés. Lorsque vous vous reconnectez, l\'appareil reçoit un nouveau nom.</string>
<string name="device_name_info_part1">Il s\'agit du nom attribué à l\'appareil. Chaque appareil connecté à un compte Mullvad reçoit un nom unique qui vous aide à l\'identifier lorsque vous gérez vos appareils dans l\'application ou sur le site Web.</string>
<string name="device_name_info_part2">Vous pouvez connecter jusqu\'à 5 appareils au même compte Mullvad.</string>
<string name="device_name_info_part3">Si vous vous déconnectez, l\'appareil et son nom sont supprimés. Lorsque vous vous reconnectez, l\'appareil reçoit un nouveau nom.</string>
<string name="disconnect">Déconnexion</string>
<string name="disconnecting">Déconnexion en cours</string>
<string name="dismiss">Ignorer</string>
Expand Down
Loading
Loading