From 59a72e05443845040234c7bfdba61d5bde433a98 Mon Sep 17 00:00:00 2001 From: fgerber Date: Mon, 8 Apr 2024 13:41:35 +0200 Subject: [PATCH] Port regional assignments to parent country if turned off --- .../activity/adapter/GeolocListAdapter.kt | 15 +++++++++------ .../helcel/beans/countries/GeoLocImporter.kt | 18 +++++++++++++++++- .../java/net/helcel/beans/svg/CSSWrapper.kt | 10 +++++++++- 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/net/helcel/beans/activity/adapter/GeolocListAdapter.kt b/app/src/main/java/net/helcel/beans/activity/adapter/GeolocListAdapter.kt index c0acb21..d0181d1 100644 --- a/app/src/main/java/net/helcel/beans/activity/adapter/GeolocListAdapter.kt +++ b/app/src/main/java/net/helcel/beans/activity/adapter/GeolocListAdapter.kt @@ -119,7 +119,10 @@ class GeolocListAdapter( private fun refreshCheck(geoLoc: GeoLoc) { _binding.checkBox.checkedState = - if (Data.visits.getVisited(geoLoc) !in listOf(NO_GROUP, AUTO_GROUP)) { + if (Data.visits.getVisited(geoLoc) == AUTO_GROUP && !Settings.isRegional(ctx) && geoLoc.type == GeoLoc.LocType.COUNTRY) { + MaterialCheckBox.STATE_CHECKED + } + else if (Data.visits.getVisited(geoLoc) !in listOf(NO_GROUP, AUTO_GROUP)) { MaterialCheckBox.STATE_CHECKED } else if (geoLoc.children.isNotEmpty() && geoLoc.children.all { Data.visits.getVisited(it) != NO_GROUP }) { @@ -137,11 +140,11 @@ class GeolocListAdapter( Data.saveData() var col = Data.groups.getGroupFromKey(Data.visits.getVisited(geoLoc)).color - if (col.color == Color.TRANSPARENT) { - col = colorWrapper( - ctx, - android.R.attr.panelColorBackground - ) + if (Data.visits.getVisited(geoLoc) == AUTO_GROUP) { + col = colorWrapper(ctx, android.R.attr.colorPrimary) + } + else if (col.color == Color.TRANSPARENT) { + col = colorWrapper(ctx, android.R.attr.panelColorBackground) col.alpha = 64 } _binding.checkBox.buttonTintList = ColorStateList.valueOf(col.color) diff --git a/app/src/main/java/net/helcel/beans/countries/GeoLocImporter.kt b/app/src/main/java/net/helcel/beans/countries/GeoLocImporter.kt index 5d75b0d..02fd5be 100644 --- a/app/src/main/java/net/helcel/beans/countries/GeoLocImporter.kt +++ b/app/src/main/java/net/helcel/beans/countries/GeoLocImporter.kt @@ -1,6 +1,9 @@ package net.helcel.beans.countries import android.content.Context +import net.helcel.beans.helper.AUTO_GROUP +import net.helcel.beans.helper.Data +import net.helcel.beans.helper.NO_GROUP import net.helcel.beans.helper.Settings import java.io.BufferedReader import java.io.InputStreamReader @@ -20,6 +23,19 @@ object GeoLocImporter { } fun clearStates() { - Country.entries.forEach { it.children.clear() } + Country.entries.forEach { country -> + if (country.children.any { region -> + Data.visits.getVisited(region) != NO_GROUP + }) { + if (Data.visits.getVisited(country) == NO_GROUP) { + Data.visits.setVisited(country, AUTO_GROUP) + } + country.children.forEach { region -> + Data.visits.setVisited(region, NO_GROUP) + } + Data.saveData() + } + country.children.clear() + } } } \ No newline at end of file diff --git a/app/src/main/java/net/helcel/beans/svg/CSSWrapper.kt b/app/src/main/java/net/helcel/beans/svg/CSSWrapper.kt index 071b544..12ae08a 100644 --- a/app/src/main/java/net/helcel/beans/svg/CSSWrapper.kt +++ b/app/src/main/java/net/helcel/beans/svg/CSSWrapper.kt @@ -2,8 +2,11 @@ package net.helcel.beans.svg import android.content.Context import net.helcel.beans.countries.World +import net.helcel.beans.helper.AUTO_GROUP +import net.helcel.beans.helper.Data import net.helcel.beans.helper.Data.groups import net.helcel.beans.helper.Data.visits +import net.helcel.beans.helper.NO_GROUP import net.helcel.beans.helper.Settings import net.helcel.beans.helper.Theme.colorToHex6 import net.helcel.beans.helper.Theme.colorWrapper @@ -37,7 +40,12 @@ class CSSWrapper(private val ctx: Context) { private fun refresh() { val id = if (Settings.isRegional(ctx)) "1" else "2" customCSS = visits.getVisitedByValue().map { (k, v) -> - if (groups.getGroupFromKey(k).key == 0) + if (!Settings.isRegional(ctx) && k == AUTO_GROUP) { + v.joinToString(",") { "#${it}$id,#${it}" } + "{fill:${ + colorToHex6(colorWrapper(ctx, android.R.attr.colorPrimary)) + };}" + } + else if (groups.getGroupFromKey(k).key == NO_GROUP) "" else v.joinToString(",") { "#${it}$id,#${it}" } + "{fill:${