Compare commits

...

2 Commits

Author SHA1 Message Date
fgerber
76b0ad9f41 Improve stats 2024-04-11 00:03:37 +02:00
fgerber
06f8a1db7a Remove equidistant projection since similar to azimuthal equatorial 2024-04-10 23:17:07 +02:00
7 changed files with 24 additions and 4905 deletions

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 6.4 MiB

View File

@ -31,6 +31,7 @@ class StatsActivity : AppCompatActivity() {
_binding.stats.layoutManager =
LinearLayoutManager(this, RecyclerView.VERTICAL, false)
val adapter = StatsListAdapter(_binding.stats, _binding.name)
_binding.groupColor.setOnClickListener { adapter.invertCountMode() }
_binding.stats.adapter = adapter
_binding.pager.adapter = object : FragmentStateAdapter(supportFragmentManager, lifecycle) {

View File

@ -18,6 +18,8 @@ import net.helcel.beans.helper.Theme.getContrastColor
class StatsListAdapter(private val stats: RecyclerView, private val total: MaterialTextView) :
RecyclerView.Adapter<StatsListAdapter.StatsViewHolder>() {
private val unit = "km²"
private var locMode = LocType.WORLD
private lateinit var ctx: Context
private var countMode: Boolean = true
@ -47,7 +49,8 @@ class StatsListAdapter(private val stats: RecyclerView, private val total: Mater
} else {
holder.bind(Data.groups.getGroupFromPos(pos))
}
total.text = Settings.getStats(ctx, initialSum, getTotal())
val unitNow = if (!countMode) unit else ""
total.text = Settings.getStats(ctx, initialSum, getTotal(), unitNow)
}
override fun getItemCount(): Int {
@ -77,7 +80,13 @@ class StatsListAdapter(private val stats: RecyclerView, private val total: Mater
val viewHolder = stats.findViewHolderForAdapterPosition(it) as? StatsViewHolder
viewHolder?.refresh(mode)
}.reduce { acc, i -> acc?.plus((i ?: 0)) }
total.text = Settings.getStats(ctx, sum, getTotal())
val unitNow = if (!countMode) unit else ""
total.text = Settings.getStats(ctx, sum, getTotal(), unitNow)
}
fun invertCountMode() {
countMode = !countMode
refreshMode(locMode)
}
inner class StatsViewHolder(
@ -100,10 +109,7 @@ class StatsListAdapter(private val stats: RecyclerView, private val total: Mater
_binding.groupColor.setTextColor(contrastEntryColor)
_binding.name.setTextColor(contrastEntryColor)
_binding.groupColor.setOnClickListener {
countMode = !countMode
refreshMode(locMode)
}
_binding.groupColor.setOnClickListener { invertCountMode() }
compute()
return refresh(locMode)
}
@ -137,7 +143,7 @@ class StatsListAdapter(private val stats: RecyclerView, private val total: Mater
LocType.STATE -> stateCount.sumOf { it.area }
else -> -1
}
_binding.name.text = area.toString()
_binding.name.text = ctx.getString(R.string.number_with_unit, area, unit)
area
}
}

View File

@ -53,7 +53,7 @@ object Settings {
}
}
fun getStats(ctx: Context, numerator: Int?, denominator: Int?): String {
fun getStats(ctx: Context, numerator: Int?, denominator: Int?, unit: String = ""): String {
if (numerator == null || denominator == null || denominator == 0) {
return ""
}
@ -63,7 +63,13 @@ object Settings {
(100 * (numerator.toFloat() / denominator.toFloat())).toInt()
)
else -> ctx.getString(R.string.rate, numerator, denominator)
else -> {
if (unit == "") {
ctx.getString(R.string.rate, numerator, denominator)
} else {
ctx.getString(R.string.rate_with_unit, numerator, denominator, unit)
}
}
}
}
}

View File

@ -13,7 +13,6 @@ class SVGWrapper(ctx: Context) {
ctx.getString(R.string.mercator)
)) {
ctx.getString(R.string.azimuthalequidistant) -> "aeqd01.svg"
ctx.getString(R.string.equirectangular) -> "eqdc01.svg"
ctx.getString(R.string.loximuthal) -> "loxim01.svg"
ctx.getString(R.string.mercator) -> "webmercator01.svg"
else -> "webmercator01.svg"

View File

@ -18,7 +18,6 @@
<string-array name="map_projection">
<item>@string/azimuthalequidistant</item>
<item>@string/equirectangular</item>
<item>@string/loximuthal</item>
<item>@string/mercator</item>

View File

@ -30,7 +30,9 @@
<string name="logo">Logo</string>
<string name="name">Name</string>
<string name="rate">%1$d/%2$d</string>
<string name="rate_with_unit">%1$d / %2$d %3$s</string>
<string name="percentage">%1$d&#65285;</string>
<string name="number_with_unit">%1$d %2$s</string>
<string name="color_rrggbb">RRGGBB</string>
<string name="hashtag">#</string>
<string name="on">On</string>
@ -41,7 +43,6 @@
<string name="total">Total</string>
<string name="uncategorized">Uncategorized</string>
<string name="azimuthalequidistant">Azimuthal Equidistant</string>
<string name="equirectangular">Equirectangular</string>
<string name="mercator">Mercator</string>
<string name="loximuthal">Loximuthal</string>
<string name="key_projection">Map Projection</string>