Skip to content

Commit

Permalink
Show location name after adding and removing from custom list
Browse files Browse the repository at this point in the history
  • Loading branch information
Pururun committed Jun 19, 2024
1 parent 88c5d62 commit 71f310c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,7 @@ data class Renamed(override val undo: CustomListAction.Rename) : CustomListSucce
@Parcelize
data class LocationsChanged(
val name: CustomListName,
val locationNamesAdded: List<String>? = null,
val locationNamesRemoved: List<String>? = null,
override val undo: CustomListAction.UpdateLocations
) : CustomListSuccess
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
)
)
},
)
}
}
Expand All @@ -155,7 +161,9 @@ class SelectLocationViewModel(
{ _uiSideEffect.send(SelectLocationSideEffect.GenericError) },
{
_uiSideEffect.send(
SelectLocationSideEffect.LocationRemovedFromCustomList(it)
SelectLocationSideEffect.LocationRemovedFromCustomList(
it.copy(locationNamesRemoved = listOf(item.name))
)
)
}
)
Expand Down
1 change: 1 addition & 0 deletions android/lib/resource/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -385,4 +385,5 @@
<string name="delete_method_question">Delete method?</string>
<string name="failed_to_set_current_test_error">Failed to set to current - API not reachable</string>
<string name="failed_to_set_current_unknown_error">Failed to set to current - Unknown reason</string>
<string name="location_was_removed_from_list">%s was removed from \"%s\"</string>
</resources>

0 comments on commit 71f310c

Please sign in to comment.