Skip to content

Commit 4507912

Browse files
committed
Fix #410: confirm before deleting profile on Automotive
1 parent fa0826c commit 4507912

3 files changed

Lines changed: 58 additions & 23 deletions

File tree

app/src/main/java/net/vonforst/evmap/auto/FilterScreen.kt

Lines changed: 56 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ import androidx.car.app.model.CarColor
1515
import androidx.car.app.model.CarIcon
1616
import androidx.car.app.model.CarText
1717
import androidx.car.app.model.ForegroundCarColorSpan
18+
import androidx.car.app.model.Header
1819
import androidx.car.app.model.ItemList
1920
import androidx.car.app.model.ListTemplate
21+
import androidx.car.app.model.MessageTemplate
2022
import androidx.car.app.model.Pane
2123
import androidx.car.app.model.PaneTemplate
2224
import androidx.car.app.model.ParkedOnlyOnClickListener
@@ -241,20 +243,23 @@ class FilterScreen(ctx: CarContext, val session: EVMapSession) : Screen(ctx) {
241243

242244
)
243245
setOnClickListener {
244-
lifecycleScope.launch {
245-
db.filterProfileDao().delete(it)
246-
if (prefs.filterStatus == it.id) {
247-
prefs.filterStatus = FILTERS_DISABLED
246+
val confirmScreen = ConfirmDeleteScreen(carContext, it) {
247+
lifecycleScope.launch {
248+
db.filterProfileDao().delete(it)
249+
if (prefs.filterStatus == it.id) {
250+
prefs.filterStatus = FILTERS_DISABLED
251+
}
252+
CarToast.makeText(
253+
carContext,
254+
carContext.getString(
255+
R.string.deleted_item,
256+
it.name
257+
),
258+
CarToast.LENGTH_SHORT
259+
).show()
248260
}
249-
CarToast.makeText(
250-
carContext,
251-
carContext.getString(
252-
R.string.deleted_item,
253-
it.name
254-
),
255-
CarToast.LENGTH_SHORT
256-
).show()
257261
}
262+
screenManager.push(confirmScreen)
258263
}
259264
}.build())
260265
}
@@ -299,6 +304,31 @@ class FilterScreen(ctx: CarContext, val session: EVMapSession) : Screen(ctx) {
299304
}
300305
}
301306

307+
class ConfirmDeleteScreen(ctx: CarContext, val profile: FilterProfile, val deleteListener: () -> Unit): Screen(ctx) {
308+
override fun onGetTemplate(): Template {
309+
val message = carContext.getString(R.string.auto_confirm_delete_profile, profile.name)
310+
return MessageTemplate.Builder(message)
311+
.setHeader(Header.Builder()
312+
.setTitle(carContext.getString(R.string.delete))
313+
.setStartHeaderAction(Action.BACK)
314+
.build())
315+
.addAction(Action.Builder()
316+
.setTitle(carContext.getString(R.string.delete))
317+
.setBackgroundColor(CarColor.PRIMARY)
318+
.setFlags(Action.FLAG_PRIMARY)
319+
.setOnClickListener {
320+
deleteListener()
321+
screenManager.pop()
322+
}
323+
.build())
324+
.addAction(Action.Builder()
325+
.setTitle(carContext.getString(R.string.cancel))
326+
.setOnClickListener { screenManager.pop() }
327+
.build())
328+
.build()
329+
}
330+
}
331+
302332
@androidx.car.app.annotations.ExperimentalCarApi
303333
class EditFiltersScreen(ctx: CarContext) : Screen(ctx) {
304334
private val vm = FilterViewModel(carContext.applicationContext as Application)
@@ -360,18 +390,21 @@ class EditFiltersScreen(ctx: CarContext) : Screen(ctx) {
360390

361391
)
362392
setOnClickListener {
363-
lifecycleScope.launch {
364-
vm.deleteCurrentProfile()
365-
CarToast.makeText(
366-
carContext,
367-
carContext.getString(
368-
R.string.deleted_item,
369-
currentProfile.name
370-
),
371-
CarToast.LENGTH_SHORT
372-
).show()
373-
screenManager.pop()
393+
val confirmScreen = ConfirmDeleteScreen(carContext, currentProfile) {
394+
lifecycleScope.launch {
395+
vm.deleteCurrentProfile()
396+
CarToast.makeText(
397+
carContext,
398+
carContext.getString(
399+
R.string.deleted_item,
400+
currentProfile.name
401+
),
402+
CarToast.LENGTH_SHORT
403+
).show()
404+
screenManager.pop()
405+
}
374406
}
407+
screenManager.push(confirmScreen)
375408
}
376409
}.build())
377410
}

app/src/main/res/values-de/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,4 +389,5 @@
389389
<string name="chargeprice_removal_2025_dialog_title">Sorry!</string>
390390
<string name="chargeprice_removal_2025_dialog_detail">Die Kosten für den Zugriff auf Chargeprice-Daten sind stark gestiegen und können nicht mehr durch Spenden gedeckt werden. Daher kann EVMap diese Daten nicht mehr direkt anzeigen. Hier öffnet sich nun die Chargeprice-Website. Eine alternative Lösung ist in Arbeit, wird aber Zeit brauchen und anfangs nur eingeschränkt funktionieren. Danke für eure Geduld und Unterstützung!</string>
391391
<string name="auto_use_new_map_screen">Neue Kartendarstellung (beta)</string>
392+
<string name="auto_confirm_delete_profile">Filterprofil „%s“ löschen?</string>
392393
</resources>

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,4 +389,5 @@
389389
<string name="chargeprice_removal_2025_dialog_title">Sorry!</string>
390390
<string name="chargeprice_removal_2025_dialog_detail">Costs for Chargeprice data access have risen sharply and can’t be covered by donations, so EVMap can no longer show this data directly. For now, this opens the Chargeprice website. An alternative solution is being developed, but it’ll take time and may start with limited features. Thanks for your patience and support!</string>
391391
<string name="auto_use_new_map_screen">New map screen (beta)</string>
392+
<string name="auto_confirm_delete_profile">Delete filter profile “%s“?</string>
392393
</resources>

0 commit comments

Comments
 (0)