From 923404ebc5d50f86b89d9035714a4cc2e0b18f99 Mon Sep 17 00:00:00 2001 From: soraefir Date: Mon, 8 Apr 2024 00:42:35 +0200 Subject: [PATCH] Fix regional UI --- .../activity/fragment/SettingsFragment.kt | 3 +- .../helcel/beans/countries/GeoLocImporter.kt | 4 +- .../java/net/helcel/beans/svg/CSSWrapper.kt | 40 +++++++++++-------- 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/net/helcel/beans/activity/fragment/SettingsFragment.kt b/app/src/main/java/net/helcel/beans/activity/fragment/SettingsFragment.kt index 29a5b71..c334480 100644 --- a/app/src/main/java/net/helcel/beans/activity/fragment/SettingsFragment.kt +++ b/app/src/main/java/net/helcel/beans/activity/fragment/SettingsFragment.kt @@ -17,8 +17,7 @@ class SettingsFragment : PreferenceFragmentCompat() { findPreference(getString(R.string.key_regional))?.setOnPreferenceChangeListener { _, key -> when (key as String) { ctx.getString(R.string.off) -> GeoLocImporter.clearStates() - ctx.getString(R.string.on) -> GeoLocImporter.importStates(ctx) - else -> GeoLocImporter.clearStates() + ctx.getString(R.string.on) -> GeoLocImporter.importStates(ctx, true) } true } 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 b759207..5d75b0d 100644 --- a/app/src/main/java/net/helcel/beans/countries/GeoLocImporter.kt +++ b/app/src/main/java/net/helcel/beans/countries/GeoLocImporter.kt @@ -7,8 +7,8 @@ import java.io.InputStreamReader object GeoLocImporter { - fun importStates(ctx: Context) { - if (!Settings.isRegional(ctx)) { + fun importStates(ctx: Context, force: Boolean = false) { + if (!Settings.isRegional(ctx) and !force) { return } val fs = BufferedReader(InputStreamReader(ctx.assets.open("geoloc_state.txt"))) 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 3548a3f..071b544 100644 --- a/app/src/main/java/net/helcel/beans/svg/CSSWrapper.kt +++ b/app/src/main/java/net/helcel/beans/svg/CSSWrapper.kt @@ -4,47 +4,55 @@ import android.content.Context import net.helcel.beans.countries.World import net.helcel.beans.helper.Data.groups import net.helcel.beans.helper.Data.visits +import net.helcel.beans.helper.Settings import net.helcel.beans.helper.Theme.colorToHex6 import net.helcel.beans.helper.Theme.colorWrapper -class CSSWrapper(ctx: Context) { +class CSSWrapper(private val ctx: Context) { private val colorForeground: String = colorToHex6(colorWrapper(ctx, android.R.attr.panelColorBackground)) private val colorBackground: String = colorToHex6(colorWrapper(ctx, android.R.attr.colorBackground)) - private val baseCSS: String + private val continents: String = World.WWW.children.joinToString(",") { "#${it.code}2" } + private val countries: String = World.WWW.children.joinToString(",") { itt -> + itt.children.joinToString(",") { "#${it.code}2" } + } + private val regional: String = World.WWW.children.joinToString(",") { itt -> + itt.children.joinToString(",") { "#${it.code}1" } + } + private val countryOnlyCSS: String = + "svg{fill:$colorForeground;stroke:$colorBackground;stroke-width:0.1;}" + + "${regional}{display:none;}" + private val countryRegionalCSS: String = + "svg{fill:$colorForeground;stroke:$colorBackground;stroke-width:0.01;}" + + "$continents,$countries{fill:none;stroke:$colorBackground;stroke-width:0.1;}" private var customCSS: String = "" init { - val www = World.WWW.children.joinToString(",") { "#${it.code}2" } - val ccc = World.WWW.children.joinToString(",") { itt -> - itt.children.joinToString(",") { "#${it.code}2" } - } - baseCSS = "svg{fill:$colorForeground;stroke:$colorBackground;stroke-width:0.01;}" + - "$www,$ccc{stroke:$colorBackground;stroke-width:0.1;fill:none}" refresh() } - fun refresh() { + private fun refresh() { + val id = if (Settings.isRegional(ctx)) "1" else "2" customCSS = visits.getVisitedByValue().map { (k, v) -> if (groups.getGroupFromKey(k).key == 0) "" else - v.joinToString(",") { "#${it}1,#${it}" } + "{fill:${ - colorToHex6( - groups.getGroupFromKey( - k - ).color - ) + v.joinToString(",") { "#${it}$id,#${it}" } + "{fill:${ + colorToHex6(groups.getGroupFromKey(k).color) };}" }.joinToString("") } fun get(): String { refresh() - return baseCSS + customCSS + return if (Settings.isRegional(ctx)) { + countryRegionalCSS + customCSS + } else { + countryOnlyCSS + customCSS + } } } \ No newline at end of file