Compare commits
2 Commits
c01420a3c6
...
76b0ad9f41
Author | SHA1 | Date | |
---|---|---|---|
|
76b0ad9f41 | ||
|
06f8a1db7a |
File diff suppressed because one or more lines are too long
Before Width: | Height: | Size: 6.4 MiB |
@ -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) {
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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"
|
||||
|
@ -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>
|
||||
|
||||
|
@ -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%</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>
|
||||
|
Loading…
x
Reference in New Issue
Block a user