From c489df2aaff591ccfae248de2c0d4e01acc63194 Mon Sep 17 00:00:00 2001 From: johan12345 Date: Fri, 9 Dec 2022 21:43:43 +0100 Subject: [PATCH] Android Auto/Automotive: Fix crash when no or all prices match "my plans" --- .../vonforst/evmap/auto/ChargepriceScreen.kt | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/app/src/google/java/net/vonforst/evmap/auto/ChargepriceScreen.kt b/app/src/google/java/net/vonforst/evmap/auto/ChargepriceScreen.kt index a9cbda17..bc6892ff 100644 --- a/app/src/google/java/net/vonforst/evmap/auto/ChargepriceScreen.kt +++ b/app/src/google/java/net/vonforst/evmap/auto/ChargepriceScreen.kt @@ -95,19 +95,29 @@ class ChargepriceScreen(ctx: CarContext, val charger: ChargeLocation) : Screen(c val (myPrices, otherPrices) = prices.partition { price -> price.tariffId in myTariffs } val myPricesList = buildPricesList(myPrices) val otherPricesList = buildPricesList(otherPrices) - addSectionedList( - SectionedItemList.create( - myPricesList, - (header?.let { it + "\n" } ?: "") + - carContext.getString(R.string.chargeprice_header_my_tariffs) + if (myPricesList.items.isNotEmpty() && otherPricesList.items.isNotEmpty()) { + addSectionedList( + SectionedItemList.create( + myPricesList, + (header?.let { it + "\n" } ?: "") + + carContext.getString(R.string.chargeprice_header_my_tariffs) + ) ) - ) - addSectionedList( - SectionedItemList.create( - otherPricesList, - carContext.getString(R.string.chargeprice_header_other_tariffs) + addSectionedList( + SectionedItemList.create( + otherPricesList, + carContext.getString(R.string.chargeprice_header_other_tariffs) + ) ) - ) + } else { + val list = + if (myPricesList.items.isNotEmpty()) myPricesList else otherPricesList + if (header != null) { + addSectionedList(SectionedItemList.create(list, header)) + } else { + setSingleList(list) + } + } } else { val list = buildPricesList(prices) if (header != null && list.items.isNotEmpty()) {