Fix regional UI
This commit is contained in:
parent
32ba5e0b07
commit
923404ebc5
@ -17,8 +17,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
||||
findPreference<Preference>(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
|
||||
}
|
||||
|
@ -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")))
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user