diff options
Diffstat (limited to 'android/app/src/main')
10 files changed, 38 insertions, 28 deletions
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/communication/CustomListAction.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/communication/CustomListAction.kt index 0b478f5272..9ddee73e22 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/communication/CustomListAction.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/communication/CustomListAction.kt @@ -2,22 +2,26 @@ package net.mullvad.mullvadvpn.compose.communication import android.os.Parcelable import kotlinx.parcelize.Parcelize +import net.mullvad.mullvadvpn.model.CustomListName sealed interface CustomListAction : Parcelable { @Parcelize - data class Rename(val customListId: String, val name: String, val newName: String) : - CustomListAction { + data class Rename( + val customListId: String, + val name: CustomListName, + val newName: CustomListName + ) : CustomListAction { fun not() = this.copy(name = newName, newName = name) } @Parcelize data class Delete(val customListId: String) : CustomListAction { - fun not(name: String, locations: List<String>) = Create(name, locations) + fun not(name: CustomListName, locations: List<String>) = Create(name, locations) } @Parcelize - data class Create(val name: String = "", val locations: List<String> = emptyList()) : + data class Create(val name: CustomListName, val locations: List<String> = emptyList()) : CustomListAction, Parcelable { fun not(customListId: String) = Delete(customListId) } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/communication/CustomListResult.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/communication/CustomListResult.kt index 32fa077a7f..14cba09b44 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/communication/CustomListResult.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/communication/CustomListResult.kt @@ -2,6 +2,7 @@ package net.mullvad.mullvadvpn.compose.communication import android.os.Parcelable import kotlinx.parcelize.Parcelize +import net.mullvad.mullvadvpn.model.CustomListName sealed interface CustomListResult : Parcelable { val undo: CustomListAction @@ -9,26 +10,26 @@ sealed interface CustomListResult : Parcelable { @Parcelize data class Created( val id: String, - val name: String, + val name: CustomListName, val locationName: String?, override val undo: CustomListAction.Delete ) : CustomListResult @Parcelize data class Deleted(override val undo: CustomListAction.Create) : CustomListResult { - val name + val name: CustomListName get() = undo.name } @Parcelize data class Renamed(override val undo: CustomListAction.Rename) : CustomListResult { - val name: String + val name: CustomListName get() = undo.name } @Parcelize data class LocationsChanged( - val name: String, + val name: CustomListName, override val undo: CustomListAction.UpdateLocations ) : CustomListResult } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/component/CustomListNameTextField.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/component/CustomListNameTextField.kt index 675f6f8f14..b3a0ece577 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/component/CustomListNameTextField.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/component/CustomListNameTextField.kt @@ -14,6 +14,7 @@ import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.input.KeyboardType import net.mullvad.mullvadvpn.R import net.mullvad.mullvadvpn.compose.textfield.CustomTextField +import net.mullvad.mullvadvpn.model.CustomListName import net.mullvad.mullvadvpn.model.CustomListsError @Composable @@ -41,6 +42,7 @@ fun CustomListNameTextField( placeholderText = null, isValidValue = error == null, isDigitsOnlyAllowed = false, + maxCharLength = CustomListName.MAX_LENGTH, supportingText = error?.let { { diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/CustomListExtensions.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/CustomListExtensions.kt index 6fb87a6af5..ad668ed9e8 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/CustomListExtensions.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/CustomListExtensions.kt @@ -1,13 +1,14 @@ package net.mullvad.mullvadvpn.relaylist import net.mullvad.mullvadvpn.model.CustomList +import net.mullvad.mullvadvpn.model.CustomListName private fun CustomList.toRelayItemCustomList( relayCountries: List<RelayItem.Country> ): RelayItem.CustomList = RelayItem.CustomList( id = this.id, - name = this.name, + customListName = CustomListName.fromString(name), expanded = false, locations = this.locations.mapNotNull { diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayItem.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayItem.kt index 54c4a9bef4..ce4be395b6 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayItem.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayItem.kt @@ -1,5 +1,6 @@ package net.mullvad.mullvadvpn.relaylist +import net.mullvad.mullvadvpn.model.CustomListName import net.mullvad.mullvadvpn.model.GeoIpLocation import net.mullvad.mullvadvpn.model.GeographicLocationConstraint @@ -15,11 +16,12 @@ sealed interface RelayItem { val expanded: Boolean data class CustomList( - override val name: String, + val customListName: CustomListName, override val expanded: Boolean, val id: String, val locations: List<RelayItem>, ) : RelayItem { + override val name: String = customListName.value override val active get() = locations.any { location -> location.active } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/repository/CustomListsRepository.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/repository/CustomListsRepository.kt index f1a38871bd..0832f434a5 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/repository/CustomListsRepository.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/repository/CustomListsRepository.kt @@ -8,6 +8,7 @@ import net.mullvad.mullvadvpn.lib.ipc.Request import net.mullvad.mullvadvpn.lib.ipc.events import net.mullvad.mullvadvpn.model.CreateCustomListResult import net.mullvad.mullvadvpn.model.CustomList +import net.mullvad.mullvadvpn.model.CustomListName import net.mullvad.mullvadvpn.model.CustomListsError import net.mullvad.mullvadvpn.model.GeographicLocationConstraint import net.mullvad.mullvadvpn.model.UpdateCustomListResult @@ -20,8 +21,8 @@ class CustomListsRepository( private val settingsRepository: SettingsRepository, private val relayListListener: RelayListListener ) { - suspend fun createCustomList(name: String): CreateCustomListResult { - val result = messageHandler.trySendRequest(Request.CreateCustomList(name)) + suspend fun createCustomList(name: CustomListName): CreateCustomListResult { + val result = messageHandler.trySendRequest(Request.CreateCustomList(name.value)) return if (result) { messageHandler.events<Event.CreateCustomListResultEvent>().first().result @@ -52,8 +53,8 @@ class CustomListsRepository( ArrayList(locationCodes.mapNotNull { getGeographicLocationConstraintByCode(it) }) ) - suspend fun updateCustomListName(id: String, name: String): UpdateCustomListResult = - getCustomListById(id)?.let { updateCustomList(it.copy(name = name)) } + suspend fun updateCustomListName(id: String, name: CustomListName): UpdateCustomListResult = + getCustomListById(id)?.let { updateCustomList(it.copy(name = name.value)) } ?: UpdateCustomListResult.Error(CustomListsError.OtherError) private suspend fun updateCustomListLocations( diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/customlists/CustomListActionUseCase.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/customlists/CustomListActionUseCase.kt index 7b2e5a43aa..8d722325d6 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/customlists/CustomListActionUseCase.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/customlists/CustomListActionUseCase.kt @@ -5,6 +5,7 @@ import net.mullvad.mullvadvpn.compose.communication.CustomListAction import net.mullvad.mullvadvpn.compose.communication.CustomListResult import net.mullvad.mullvadvpn.model.CreateCustomListResult import net.mullvad.mullvadvpn.model.CustomList +import net.mullvad.mullvadvpn.model.CustomListName import net.mullvad.mullvadvpn.model.GeographicLocationConstraint import net.mullvad.mullvadvpn.model.UpdateCustomListResult import net.mullvad.mullvadvpn.relaylist.getRelayItemsByCodes @@ -79,9 +80,9 @@ class CustomListActionUseCase( } fun performAction(action: CustomListAction.Delete): Result<CustomListResult.Deleted> { - val customList: CustomList? = customListsRepository.getCustomListById(action.customListId) + val customList: CustomList = customListsRepository.getCustomListById(action.customListId)!! val oldLocations = customList.locations() - val name = customList?.name ?: "" + val name = CustomListName.fromString(customList.name) customListsRepository.deleteCustomList(action.customListId) return Result.success( CustomListResult.Deleted(undo = action.not(locations = oldLocations, name = name)) @@ -91,9 +92,9 @@ class CustomListActionUseCase( suspend fun performAction( action: CustomListAction.UpdateLocations ): Result<CustomListResult.LocationsChanged> { - val customList: CustomList? = customListsRepository.getCustomListById(action.customListId) + val customList = customListsRepository.getCustomListById(action.customListId)!! val oldLocations = customList.locations() - val name = customList?.name ?: "" + val name = CustomListName.fromString(customList.name) customListsRepository.updateCustomListLocationsFromCodes( action.customListId, action.locations diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/CreateCustomListDialogViewModel.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/CreateCustomListDialogViewModel.kt index 9ae5bb7a64..f58916cd66 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/CreateCustomListDialogViewModel.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/CreateCustomListDialogViewModel.kt @@ -13,6 +13,7 @@ import kotlinx.coroutines.launch import net.mullvad.mullvadvpn.compose.communication.CustomListAction import net.mullvad.mullvadvpn.compose.communication.CustomListResult import net.mullvad.mullvadvpn.compose.state.CreateCustomListUiState +import net.mullvad.mullvadvpn.model.CustomListName import net.mullvad.mullvadvpn.model.CustomListsError import net.mullvad.mullvadvpn.usecase.customlists.CustomListActionUseCase import net.mullvad.mullvadvpn.usecase.customlists.CustomListsException @@ -38,7 +39,7 @@ class CreateCustomListDialogViewModel( customListActionUseCase .performAction( CustomListAction.Create( - name, + CustomListName.fromString(name), if (locationCode.isNotEmpty()) { listOf(locationCode) } else { diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/CustomListLocationsViewModel.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/CustomListLocationsViewModel.kt index 5fa99306a3..5efba5321e 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/CustomListLocationsViewModel.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/CustomListLocationsViewModel.kt @@ -28,8 +28,6 @@ class CustomListLocationsViewModel( private val relayListUseCase: RelayListUseCase, private val customListActionUseCase: CustomListActionUseCase ) : ViewModel() { - private var customListName: String = "" - private val _uiSideEffect = MutableSharedFlow<CustomListLocationsSideEffect>(replay = 1, extraBufferCapacity = 1) val uiSideEffect: SharedFlow<CustomListLocationsSideEffect> = _uiSideEffect @@ -195,11 +193,9 @@ class CustomListLocationsViewModel( private suspend fun fetchInitialSelectedLocations() { _selectedLocations.value = - awaitCustomListById(customListId) - ?.apply { customListName = name } - ?.locations - ?.selectChildren() - .apply { _initialLocations.value = this ?: emptySet() } + awaitCustomListById(customListId)?.locations?.selectChildren().apply { + _initialLocations.value = this ?: emptySet() + } } companion object { diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/EditCustomListNameDialogViewModel.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/EditCustomListNameDialogViewModel.kt index c2625e6d56..9a8d3d2f62 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/EditCustomListNameDialogViewModel.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/EditCustomListNameDialogViewModel.kt @@ -13,6 +13,7 @@ import kotlinx.coroutines.launch import net.mullvad.mullvadvpn.compose.communication.CustomListAction import net.mullvad.mullvadvpn.compose.communication.CustomListResult import net.mullvad.mullvadvpn.compose.state.UpdateCustomListUiState +import net.mullvad.mullvadvpn.model.CustomListName import net.mullvad.mullvadvpn.model.CustomListsError import net.mullvad.mullvadvpn.usecase.customlists.CustomListActionUseCase import net.mullvad.mullvadvpn.usecase.customlists.CustomListsException @@ -44,8 +45,8 @@ class EditCustomListNameDialogViewModel( .performAction( CustomListAction.Rename( customListId = customListId, - name = initialName, - newName = name + name = CustomListName.fromString(initialName), + newName = CustomListName.fromString(name) ) ) .fold( |
