CleanUp, Opti, Svg, ...

This commit is contained in:
soraefir 2024-04-10 20:56:14 +02:00
parent 98582732cd
commit cd7c54230e
Signed by: sora
GPG Key ID: A362EA0491E2EEA0
20 changed files with 4453 additions and 14286 deletions

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 6.4 MiB

After

Width:  |  Height:  |  Size: 6.4 MiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 6.4 MiB

After

Width:  |  Height:  |  Size: 6.4 MiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 6.4 MiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 6.4 MiB

After

Width:  |  Height:  |  Size: 6.4 MiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 6.6 MiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 6.6 MiB

After

Width:  |  Height:  |  Size: 6.5 MiB

View File

@ -37,7 +37,7 @@ class MainActivity : AppCompatActivity() {
override fun onOptionsItemSelected(item: MenuItem): Boolean {
val d = when (item.itemId) {
R.id.action_edit -> EditActivity::class.java
R.id.action_stats -> StatActivity::class.java
R.id.action_stats -> StatsActivity::class.java
R.id.action_settings -> SettingsActivity::class.java
else -> throw Exception("Non Existent Menu Item")
}

View File

@ -4,7 +4,6 @@ import android.os.Bundle
import android.view.MenuItem
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import androidx.preference.PreferenceManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.viewpager2.adapter.FragmentStateAdapter
@ -12,18 +11,16 @@ import androidx.viewpager2.widget.ViewPager2
import com.google.android.material.tabs.TabLayoutMediator
import net.helcel.beans.R
import net.helcel.beans.activity.adapter.StatsListAdapter
import net.helcel.beans.countries.GeoLoc.LocType
import net.helcel.beans.databinding.ActivityStatBinding
import net.helcel.beans.helper.Settings
import net.helcel.beans.helper.Theme.createActionBar
const val WORLD = "Continents"
const val COUNTRY = "Countries"
const val REGION = "Regions"
private val MODE_LIST = listOf(WORLD, COUNTRY, REGION)
private val MODE_LIST = listOf(LocType.WORLD, LocType.COUNTRY, LocType.STATE)
class StatActivity : AppCompatActivity() {
class StatsActivity : AppCompatActivity() {
private lateinit var _binding: ActivityStatBinding
private var activeMode: String = WORLD
private var activeMode = LocType.WORLD
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@ -41,7 +38,7 @@ class StatActivity : AppCompatActivity() {
override fun createFragment(position: Int): Fragment = Fragment()
}
TabLayoutMediator(_binding.tab, _binding.pager) { tab, position ->
tab.text = MODE_LIST[position]
tab.text = MODE_LIST[position].txt
}.attach()
_binding.pager.registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() {
@ -50,12 +47,10 @@ class StatActivity : AppCompatActivity() {
adapter.refreshMode(activeMode)
}
})
//adapter.refreshMode(activeMode)
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
finish()
return super.onOptionsItemSelected(item)
}
}

View File

@ -9,7 +9,6 @@ import android.view.ViewGroup
import androidx.fragment.app.FragmentActivity
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.checkbox.MaterialCheckBox
import net.helcel.beans.R
import net.helcel.beans.activity.fragment.EditPlaceColorFragment
import net.helcel.beans.activity.fragment.EditPlaceFragment
import net.helcel.beans.countries.GeoLoc
@ -79,7 +78,7 @@ class GeolocListAdapter(
_binding.textView.backgroundTintList =
ColorStateList.valueOf(colorWrapper(ctx, android.R.attr.colorBackground).color)
if (el.shouldShowChildren(ctx))
if (el.children.isNotEmpty())
bindGroup(el)
refreshCheck(el)
@ -94,7 +93,7 @@ class GeolocListAdapter(
}
fun addListeners(el: GeoLoc, expandLambda: () -> Boolean) {
if (el.shouldShowChildren(ctx)) {
if (el.children.isNotEmpty()) {
_binding.textView.setOnClickListener { expandLambda() }
}
_binding.checkBox.setOnClickListener {
@ -141,23 +140,13 @@ class GeolocListAdapter(
private fun refreshCheck(geoLoc: GeoLoc) {
_binding.checkBox.checkedState =
if (Data.visits.getVisited(geoLoc) == AUTO_GROUP && !Settings.isRegional(ctx) && geoLoc.type == GeoLoc.LocType.COUNTRY) {
if (Data.visits.getVisited(geoLoc) !in listOf(NO_GROUP, AUTO_GROUP)) {
MaterialCheckBox.STATE_CHECKED
} else if (Data.visits.getVisited(geoLoc) !in listOf(NO_GROUP, AUTO_GROUP)) {
MaterialCheckBox.STATE_CHECKED
} else if (
Data.visits.getVisited(geoLoc) == AUTO_GROUP
&& Settings.isRegional(ctx)
&& geoLoc.type == GeoLoc.LocType.COUNTRY
&& (geoLoc.children.all { Data.visits.getVisited(it) == NO_GROUP })
&& geoLoc != Data.clearing_geoloc
} else if (geoLoc.children.isNotEmpty() &&
geoLoc.children.all {
Data.visits.getVisited(it) !in listOf(NO_GROUP, AUTO_GROUP)
}
) {
MaterialCheckBox.STATE_CHECKED
} else if (geoLoc.children.isNotEmpty() && geoLoc.children.all {
Data.visits.getVisited(
it
) != NO_GROUP
}) {
Data.visits.setVisited(geoLoc, AUTO_GROUP)
MaterialCheckBox.STATE_CHECKED
} else if (geoLoc.children.any { Data.visits.getVisited(it) != NO_GROUP }) {
@ -165,7 +154,7 @@ class GeolocListAdapter(
MaterialCheckBox.STATE_INDETERMINATE
} else {
Data.visits.setVisited(geoLoc, NO_GROUP)
if (geoLoc == Data.clearing_geoloc) {
if (Data.clearing_geoloc == geoLoc) {
Data.clearing_geoloc = null
}
MaterialCheckBox.STATE_UNCHECKED

View File

@ -1,16 +1,13 @@
package net.helcel.beans.activity.adapter
import android.annotation.SuppressLint
import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.textview.MaterialTextView
import net.helcel.beans.R
import net.helcel.beans.activity.COUNTRY
import net.helcel.beans.activity.REGION
import net.helcel.beans.activity.WORLD
import net.helcel.beans.countries.GeoLoc
import net.helcel.beans.countries.GeoLoc.LocType
import net.helcel.beans.countries.World
import net.helcel.beans.databinding.ItemListGroupBinding
import net.helcel.beans.helper.AUTO_GROUP
@ -21,14 +18,15 @@ import net.helcel.beans.helper.Theme.getContrastColor
class StatsListAdapter(private val stats: RecyclerView, private val total: MaterialTextView) :
RecyclerView.Adapter<StatsListAdapter.StatsViewHolder>() {
private var locMode: String = WORLD
private var locMode = LocType.WORLD
private lateinit var ctx: Context
private var countMode: Boolean = true
private var initialSum: Int = 0
private val wwwTotal: List<GeoLoc> = World.WWW.children.toList()
private val countryTotal: List<GeoLoc> = World.WWW.children.flatMap { it.children }
private val stateTotal: List<GeoLoc> = World.WWW.children.flatMap{ it.children.flatMap { itt -> itt.children } }
private val stateTotal: List<GeoLoc> =
World.WWW.children.flatMap { it.children.flatMap { itt -> itt.children } }
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): StatsViewHolder {
ctx = parent.context
@ -40,7 +38,12 @@ class StatsListAdapter(private val stats: RecyclerView, private val total: Mater
override fun onBindViewHolder(holder: StatsViewHolder, pos: Int) {
initialSum += if (pos == itemCount - 1) {
holder.bind(Pair(AUTO_GROUP, Groups.Group(AUTO_GROUP, ctx.getString(R.string.uncategorized))))
holder.bind(
Pair(
AUTO_GROUP,
Groups.Group(AUTO_GROUP, ctx.getString(R.string.uncategorized))
)
)
} else {
holder.bind(Data.groups.getGroupFromPos(pos))
}
@ -54,22 +57,22 @@ class StatsListAdapter(private val stats: RecyclerView, private val total: Mater
private fun getTotal(): Int {
return if (countMode) {
when (locMode) {
WORLD -> wwwTotal.size
COUNTRY -> countryTotal.size
REGION -> stateTotal.size
LocType.WORLD -> wwwTotal.size
LocType.COUNTRY -> countryTotal.size
LocType.STATE -> stateTotal.size
else -> 0
}
} else {
when (locMode) {
WORLD -> wwwTotal.sumOf { it.area }
COUNTRY -> countryTotal.sumOf { it.area }
REGION -> stateTotal.sumOf { it.area }
LocType.WORLD -> wwwTotal.sumOf { it.area }
LocType.COUNTRY -> countryTotal.sumOf { it.area }
LocType.STATE -> stateTotal.sumOf { it.area }
else -> 0
}
}
}
fun refreshMode(mode: String) {
fun refreshMode(mode: LocType) {
val sum = (0 until itemCount).map {
val viewHolder = stats.findViewHolderForAdapterPosition(it) as? StatsViewHolder
viewHolder?.refresh(mode)
@ -116,22 +119,22 @@ class StatsListAdapter(private val stats: RecyclerView, private val total: Mater
.flatten().flatten()
}
fun refresh(mode: String): Int {
fun refresh(mode: LocType): Int {
locMode = mode
return if (countMode) {
val count = when (locMode) {
WORLD -> wwwCount.size
COUNTRY -> countryCount.size
REGION -> stateCount.size
LocType.WORLD -> wwwCount.size
LocType.COUNTRY -> countryCount.size
LocType.STATE -> stateCount.size
else -> -1
}
_binding.name.text = count.toString()
count
} else {
val area = when (locMode) {
WORLD -> wwwCount.sumOf { it.area }
COUNTRY -> countryCount.sumOf { it.area }
REGION -> stateCount.sumOf { it.area }
LocType.WORLD -> wwwCount.sumOf { it.area }
LocType.COUNTRY -> countryCount.sumOf { it.area }
LocType.STATE -> stateCount.sumOf { it.area }
else -> -1
}
_binding.name.text = area.toString()

View File

@ -8,7 +8,6 @@ import androidx.preference.PreferenceFragmentCompat
import androidx.preference.PreferenceManager
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import net.helcel.beans.R
import net.helcel.beans.activity.MainActivity
import net.helcel.beans.countries.GeoLocImporter
import net.helcel.beans.helper.Data
import net.helcel.beans.helper.DialogCloser
@ -58,18 +57,22 @@ class SettingsFragment : PreferenceFragmentCompat(), DialogCloser {
.setMessage(R.string.delete_regions)
.setPositiveButton(android.R.string.ok) { _, _ ->
GeoLocImporter.clearStates()
val sp = PreferenceManager.getDefaultSharedPreferences(ctx)
sp.edit().putString(ctx.getString(R.string.key_regional), ctx.getString(R.string.off)).apply()
PreferenceManager.getDefaultSharedPreferences(ctx).edit().putString(
ctx.getString(R.string.key_regional),
ctx.getString(R.string.off)
).apply()
refreshPreferences()
}
.setNegativeButton(android.R.string.cancel) { _, _ -> }
.show()
false
}
ctx.getString(R.string.on) -> {
GeoLocImporter.importStates(ctx, true)
true
}
else -> false
}
}
@ -111,7 +114,7 @@ class SettingsFragment : PreferenceFragmentCompat(), DialogCloser {
// When turning groups off, select one group to keep and reassign everything
Data.selected_group?.let { selectedGroup ->
// Reassign all visited that are not to selectedGroup to selectedGroup
Data.visits.reassignAllVisitedtoGroup(selectedGroup.key)
Data.visits.reassignAllVisitedToGroup(selectedGroup.key)
// Delete all groups that are not selectedGroup
Data.groups.deleteAllExcept(selectedGroup.key)
@ -124,7 +127,8 @@ class SettingsFragment : PreferenceFragmentCompat(), DialogCloser {
// Actually change preference
val ctx = requireContext()
val sp = PreferenceManager.getDefaultSharedPreferences(ctx)
sp.edit().putString(ctx.getString(R.string.key_group), ctx.getString(R.string.off)).apply()
sp.edit().putString(ctx.getString(R.string.key_group), ctx.getString(R.string.off))
.apply()
// Refresh entire preference fragment to reflect changes
refreshPreferences()

View File

@ -1,13 +1,10 @@
package net.helcel.beans.countries
import android.content.Context
import net.helcel.beans.helper.Settings
interface GeoLoc {
enum class LocType {
WORLD, GROUP, CUSTOM_GROUP, COUNTRY, STATE;
enum class LocType(val txt: String) {
WORLD("World"), GROUP("Group"), CUSTOM_GROUP("Group"), COUNTRY("Country"), STATE("State");
}
val code: String
@ -16,15 +13,6 @@ interface GeoLoc {
val type: LocType
val children: Set<GeoLoc>
fun shouldShowChildren(ctx: Context): Boolean {
if (children.isEmpty())
return false
if (type == LocType.COUNTRY && !Settings.isRegional(ctx))
return false
return true
}
}

View File

@ -30,12 +30,9 @@ object GeoLocImporter {
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()
}
Data.saveData()
}
}

View File

@ -14,9 +14,6 @@ enum class World(override val fullName: String, override val children: Set<GeoLo
acc + i.area
}
override val type = GeoLoc.LocType.WORLD
override val code = this.name
}

View File

@ -46,7 +46,7 @@ class Visits(val id: Int, private val locs: HashMap<String, Int>) {
return locs.filter { it.value == key }.keys.toList()
}
fun reassignAllVisitedtoGroup(group: Int) {
fun reassignAllVisitedToGroup(group: Int) {
val keys = locs.filter { (_, grp) ->
grp !in listOf(NO_GROUP, AUTO_GROUP)
}.keys

View File

@ -1,12 +1,8 @@
package net.helcel.beans.svg
import android.content.Context
import net.helcel.beans.countries.Country
import net.helcel.beans.countries.GeoLoc
import net.helcel.beans.countries.State
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
@ -43,29 +39,16 @@ 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 (!Settings.isRegional(ctx) && k == AUTO_GROUP) {
if (groups.getGroupFromKey(k).key != NO_GROUP || (!Settings.isRegional(ctx) && k == AUTO_GROUP)) {
v.joinToString(",") { "#${it}$id,#${it}" } + "{fill:${
colorToHex6(colorWrapper(ctx, android.R.attr.colorPrimary))
colorToHex6(
if (k == AUTO_GROUP)
colorWrapper(ctx, android.R.attr.colorPrimary)
else groups.getGroupFromKey(k).color
)
};}"
}
else if (Settings.isRegional(ctx) && k == AUTO_GROUP) {
Country.entries.filter { it.code in v }
.filter {
it.children.all { itt ->
visits.getVisited(itt) == NO_GROUP
}
}.map {
it.code
}.takeIf { it.isNotEmpty() }?.joinToString(",") { "#${it}$id,#${it}" } + "{fill:${
colorToHex6(colorWrapper(ctx, android.R.attr.colorPrimary))
};}"
}
else if (groups.getGroupFromKey(k).key == NO_GROUP)
} else {
""
else {
v.joinToString(",") { "#${it}$id,#${it}" } + "{fill:${
colorToHex6(groups.getGroupFromKey(k).color)
};}"
}
}.joinToString("")
}

View File

@ -8,13 +8,14 @@ import net.helcel.beans.R
class SVGWrapper(ctx: Context) {
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(ctx)
val svgFile = when (sharedPreferences.getString(ctx.getString(R.string.key_projection), ctx.getString(R.string.mercator))) {
private val svgFile = when (sharedPreferences.getString(
ctx.getString(R.string.key_projection),
ctx.getString(R.string.mercator)
)) {
ctx.getString(R.string.azimuthalequidistant) -> "aeqd01.svg"
ctx.getString(R.string.equirectangular) -> "eqdc01.svg"
ctx.getString(R.string.equidistant) -> "eqearth01.svg"
ctx.getString(R.string.mercator) -> "mercator01.svg"
ctx.getString(R.string.loximuthal) -> "loxim01.svg"
ctx.getString(R.string.webmercator) -> "webmercator01.svg"
ctx.getString(R.string.mercator) -> "webmercator01.svg"
else -> "webmercator01.svg"
}

View File

@ -12,12 +12,11 @@
android:orientation="vertical">
<com.google.android.material.imageview.ShapeableImageView
android:layout_width="250dp"
android:layout_height="250dp"
android:layout_marginTop="40dp"
android:layout_marginBottom="30dp"
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_marginTop="20dp"
android:contentDescription="@string/logo"
android:src="@mipmap/ic_launcher_round" />
android:src="@drawable/ic_launcher_foreground" />
<com.google.android.material.textview.MaterialTextView
android:layout_width="match_parent"

View File

@ -19,8 +19,6 @@
<string-array name="map_projection">
<item>@string/azimuthalequidistant</item>
<item>@string/equirectangular</item>
<item>@string/equidistant</item>
<item>@string/mercator</item>
<item>@string/loximuthal</item>
<item>@string/webmercator</item>

View File

@ -132,12 +132,10 @@ toSVG_01() {
done
# "$mapshaper" -i combine-files ${input_files[@]} -proj eqdc +lat_1=55 +lat_2=60 -simplify 0.005 weighted keep-shapes resolution=1200x1200 -o ./app/src/main/assets/eqdc01.svg svg-data=GID_0,COUNTRY,GID,NAME id-field=GID
# "$mapshaper" -i combine-files ${input_files[@]} -proj loxim -simplify 0.005 weighted keep-shapes resolution=1200x1200 -o ./app/src/main/assets/loxim01.svg svg-data=GID_0,COUNTRY,GID,NAME id-field=GID
# "$mapshaper" -i combine-files ${input_files[@]} -proj eqearth -simplify 0.005 weighted keep-shapes resolution=1200x1200 -o ./app/src/main/assets/eqearth01.svg svg-data=GID_0,COUNTRY,GID,NAME id-field=GID
"$mapshaper" -i combine-files ${input_files[@]} -proj merc +lat_ts=47.36667 -simplify 0.005 weighted keep-shapes resolution=1200x1200 -o ./app/src/main/assets/mercator01.svg svg-data=GID_0,COUNTRY,GID,NAME id-field=GID
# "$mapshaper" -i combine-files ${input_files[@]} -proj webmercator -simplify 0.005 weighted keep-shapes resolution=1200x1200 -o ./app/src/main/assets/webmercator01.svg svg-data=GID_0,COUNTRY,GID,NAME id-field=GID
# "$mapshaper" -i combine-files ${input_files[@]} -proj aeqd +lat_0=90 -simplify 0.005 weighted keep-shapes resolution=1200x1200 -o ./app/src/main/assets/aeqd01.svg svg-data=GID_0,COUNTRY,GID,NAME id-field=GID
"$mapshaper" -i combine-files ${input_files[@]} snap -proj eqdc +lat_1=55 +lat_2=60 -simplify 0.005 weighted keep-shapes resolution=1200x1200 -o ./app/src/main/assets/eqdc01.svg svg-data=GID_0,COUNTRY,GID,NAME id-field=GID
"$mapshaper" -i combine-files ${input_files[@]} snap -proj loxim densify -simplify 0.005 weighted keep-shapes resolution=1200x1200 -o ./app/src/main/assets/loxim01.svg svg-data=GID_0,COUNTRY,GID,NAME id-field=GID
"$mapshaper" -i combine-files ${input_files[@]} snap -proj webmercator densify -simplify 0.005 weighted keep-shapes resolution=1200x1200 -o ./app/src/main/assets/webmercator01.svg svg-data=GID_0,COUNTRY,GID,NAME id-field=GID
"$mapshaper" -i combine-files ${input_files[@]} snap -proj aeqd +lat_0=90 densify -simplify 0.005 weighted keep-shapes resolution=1200x1200 -o ./app/src/main/assets/aeqd01.svg svg-data=GID_0,COUNTRY,GID,NAME id-field=GID
}
do_1() {