From 71f310cc624f9a8a228f6611501420e184fa8ddb Mon Sep 17 00:00:00 2001 From: Jonatan Rhodin Date: Wed, 19 Jun 2024 09:29:08 +0200 Subject: [PATCH] Show location name after adding and removing from custom list --- .../compose/communication/CustomListSuccess.kt | 2 ++ .../compose/screen/SelectLocationScreen.kt | 17 ++++++++++++++++- .../viewmodel/SelectLocationViewModel.kt | 12 ++++++++++-- .../resource/src/main/res/values/strings.xml | 1 + 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/communication/CustomListSuccess.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/communication/CustomListSuccess.kt index d83cd4c76de8..1ae0bf904fa1 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/communication/CustomListSuccess.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/communication/CustomListSuccess.kt @@ -32,5 +32,7 @@ data class Renamed(override val undo: CustomListAction.Rename) : CustomListSucce @Parcelize data class LocationsChanged( val name: CustomListName, + val locationNamesAdded: List? = null, + val locationNamesRemoved: List? = null, override val undo: CustomListAction.UpdateLocations ) : CustomListSuccess diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/SelectLocationScreen.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/SelectLocationScreen.kt index b10a41a070c6..e1627e851fe8 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/SelectLocationScreen.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/SelectLocationScreen.kt @@ -844,7 +844,22 @@ private fun CustomListSuccess.message(context: Context): String = } ?: context.getString(R.string.locations_were_changed_for, name) is Deleted -> context.getString(R.string.delete_custom_list_message, name) is Renamed -> context.getString(R.string.name_was_changed_to, name) - is LocationsChanged -> context.getString(R.string.locations_were_changed_for, name) + is LocationsChanged -> + when { + locationNamesAdded != null -> + context.getString( + R.string.location_was_added_to_list, + locationNamesAdded.first(), + name + ) + locationNamesRemoved != null -> + context.getString( + R.string.location_was_removed_from_list, + locationNamesRemoved.first(), + name + ) + else -> context.getString(R.string.locations_were_changed_for, name) + } } @Composable diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/SelectLocationViewModel.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/SelectLocationViewModel.kt index 2509fdc8765d..5b5e770788c4 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/SelectLocationViewModel.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/SelectLocationViewModel.kt @@ -138,7 +138,13 @@ class SelectLocationViewModel( customListActionUseCase(CustomListAction.UpdateLocations(customList.id, newLocations)) .fold( { _uiSideEffect.send(SelectLocationSideEffect.GenericError) }, - { _uiSideEffect.send(SelectLocationSideEffect.LocationAddedToCustomList(it)) }, + { + _uiSideEffect.send( + SelectLocationSideEffect.LocationAddedToCustomList( + it.copy(locationNamesAdded = listOf(item.name)) + ) + ) + }, ) } } @@ -155,7 +161,9 @@ class SelectLocationViewModel( { _uiSideEffect.send(SelectLocationSideEffect.GenericError) }, { _uiSideEffect.send( - SelectLocationSideEffect.LocationRemovedFromCustomList(it) + SelectLocationSideEffect.LocationRemovedFromCustomList( + it.copy(locationNamesRemoved = listOf(item.name)) + ) ) } ) diff --git a/android/lib/resource/src/main/res/values/strings.xml b/android/lib/resource/src/main/res/values/strings.xml index f7fafc72ffcb..5b6d75de6fd5 100644 --- a/android/lib/resource/src/main/res/values/strings.xml +++ b/android/lib/resource/src/main/res/values/strings.xml @@ -385,4 +385,5 @@ Delete method? Failed to set to current - API not reachable Failed to set to current - Unknown reason + %s was removed from \"%s\"