Improve stats
This commit is contained in:
parent
06f8a1db7a
commit
76b0ad9f41
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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>
|
||||
|
Loading…
x
Reference in New Issue
Block a user