diff --git a/app/src/main/java/net/helcel/beans/activity/StatsActivity.kt b/app/src/main/java/net/helcel/beans/activity/StatsActivity.kt index 14a6818..b13c776 100644 --- a/app/src/main/java/net/helcel/beans/activity/StatsActivity.kt +++ b/app/src/main/java/net/helcel/beans/activity/StatsActivity.kt @@ -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) { diff --git a/app/src/main/java/net/helcel/beans/activity/adapter/StatsListAdapter.kt b/app/src/main/java/net/helcel/beans/activity/adapter/StatsListAdapter.kt index ce69553..f36efef 100644 --- a/app/src/main/java/net/helcel/beans/activity/adapter/StatsListAdapter.kt +++ b/app/src/main/java/net/helcel/beans/activity/adapter/StatsListAdapter.kt @@ -18,6 +18,8 @@ import net.helcel.beans.helper.Theme.getContrastColor class StatsListAdapter(private val stats: RecyclerView, private val total: MaterialTextView) : RecyclerView.Adapter() { + 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 } } diff --git a/app/src/main/java/net/helcel/beans/helper/Settings.kt b/app/src/main/java/net/helcel/beans/helper/Settings.kt index 0745576..af64328 100644 --- a/app/src/main/java/net/helcel/beans/helper/Settings.kt +++ b/app/src/main/java/net/helcel/beans/helper/Settings.kt @@ -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) + } + } } } } \ No newline at end of file diff --git a/app/src/main/res/values/en.xml b/app/src/main/res/values/en.xml index 66448ce..dd0d464 100644 --- a/app/src/main/res/values/en.xml +++ b/app/src/main/res/values/en.xml @@ -30,7 +30,9 @@ Logo Name %1$d/%2$d + %1$d / %2$d %3$s %1$d% + %1$d %2$s RRGGBB # On