Fix regional UI

This commit is contained in:
soraefir 2024-04-08 00:42:35 +02:00
parent 32ba5e0b07
commit 923404ebc5
Signed by: sora
GPG Key ID: A362EA0491E2EEA0
3 changed files with 27 additions and 20 deletions

View File

@ -17,8 +17,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
findPreference<Preference>(getString(R.string.key_regional))?.setOnPreferenceChangeListener { _, key -> findPreference<Preference>(getString(R.string.key_regional))?.setOnPreferenceChangeListener { _, key ->
when (key as String) { when (key as String) {
ctx.getString(R.string.off) -> GeoLocImporter.clearStates() ctx.getString(R.string.off) -> GeoLocImporter.clearStates()
ctx.getString(R.string.on) -> GeoLocImporter.importStates(ctx) ctx.getString(R.string.on) -> GeoLocImporter.importStates(ctx, true)
else -> GeoLocImporter.clearStates()
} }
true true
} }

View File

@ -7,8 +7,8 @@ import java.io.InputStreamReader
object GeoLocImporter { object GeoLocImporter {
fun importStates(ctx: Context) { fun importStates(ctx: Context, force: Boolean = false) {
if (!Settings.isRegional(ctx)) { if (!Settings.isRegional(ctx) and !force) {
return return
} }
val fs = BufferedReader(InputStreamReader(ctx.assets.open("geoloc_state.txt"))) val fs = BufferedReader(InputStreamReader(ctx.assets.open("geoloc_state.txt")))

View File

@ -4,47 +4,55 @@ import android.content.Context
import net.helcel.beans.countries.World import net.helcel.beans.countries.World
import net.helcel.beans.helper.Data.groups import net.helcel.beans.helper.Data.groups
import net.helcel.beans.helper.Data.visits 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.colorToHex6
import net.helcel.beans.helper.Theme.colorWrapper import net.helcel.beans.helper.Theme.colorWrapper
class CSSWrapper(ctx: Context) { class CSSWrapper(private val ctx: Context) {
private val colorForeground: String = private val colorForeground: String =
colorToHex6(colorWrapper(ctx, android.R.attr.panelColorBackground)) colorToHex6(colorWrapper(ctx, android.R.attr.panelColorBackground))
private val colorBackground: String = private val colorBackground: String =
colorToHex6(colorWrapper(ctx, android.R.attr.colorBackground)) 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 = "" private var customCSS: String = ""
init { 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() refresh()
} }
fun refresh() { private fun refresh() {
val id = if (Settings.isRegional(ctx)) "1" else "2"
customCSS = visits.getVisitedByValue().map { (k, v) -> customCSS = visits.getVisitedByValue().map { (k, v) ->
if (groups.getGroupFromKey(k).key == 0) if (groups.getGroupFromKey(k).key == 0)
"" ""
else else
v.joinToString(",") { "#${it}1,#${it}" } + "{fill:${ v.joinToString(",") { "#${it}$id,#${it}" } + "{fill:${
colorToHex6( colorToHex6(groups.getGroupFromKey(k).color)
groups.getGroupFromKey(
k
).color
)
};}" };}"
}.joinToString("") }.joinToString("")
} }
fun get(): String { fun get(): String {
refresh() refresh()
return baseCSS + customCSS return if (Settings.isRegional(ctx)) {
countryRegionalCSS + customCSS
} else {
countryOnlyCSS + customCSS
}
} }
} }