refactor: dedup CountFormatter against commons util

amethyst/service/CountFormatter.countToHumanReadable(counter, str)
duplicates the identical 2-arg overloads already in
commons/util/NumberFormatters. Delete the duplicate and re-point the
two relay-row callers.

https://claude.ai/code/session_01H66WwvUYm5KtAWBLgUMcod
This commit is contained in:
Claude
2026-05-30 20:37:20 +00:00
parent 5d629faa05
commit 6eee100010
3 changed files with 2 additions and 45 deletions
@@ -1,43 +0,0 @@
/*
* Copyright (c) 2025 Vitor Pamplona
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.vitorpamplona.amethyst.service
import kotlin.math.roundToInt
fun countToHumanReadable(
counter: Int,
str: String,
) = when {
counter >= 1000000000 -> "${(counter / 1000000000f).roundToInt()}G $str"
counter >= 1000000 -> "${(counter / 1000000f).roundToInt()}M $str"
counter >= 1000 -> "${(counter / 1000f).roundToInt()}K $str"
else -> "$counter $str"
}
fun countToHumanReadable(
counter: Long,
str: String,
) = when {
counter >= 1000000000 -> "${(counter / 1000000000f).roundToInt()}G $str"
counter >= 1000000 -> "${(counter / 1000000f).roundToInt()}M $str"
counter >= 1000 -> "${(counter / 1000f).roundToInt()}K $str"
else -> "$counter $str"
}
@@ -39,7 +39,7 @@ import androidx.compose.ui.unit.dp
import com.vitorpamplona.amethyst.R
import com.vitorpamplona.amethyst.commons.icons.symbols.Icon
import com.vitorpamplona.amethyst.commons.icons.symbols.MaterialSymbols
import com.vitorpamplona.amethyst.service.countToHumanReadable
import com.vitorpamplona.amethyst.commons.util.countToHumanReadable
import com.vitorpamplona.amethyst.ui.stringRes
import com.vitorpamplona.amethyst.ui.theme.Font10SP
import com.vitorpamplona.amethyst.ui.theme.Size10Modifier
@@ -36,7 +36,7 @@ import androidx.compose.ui.unit.dp
import com.vitorpamplona.amethyst.R
import com.vitorpamplona.amethyst.commons.icons.symbols.Icon
import com.vitorpamplona.amethyst.commons.icons.symbols.MaterialSymbols
import com.vitorpamplona.amethyst.service.countToHumanReadable
import com.vitorpamplona.amethyst.commons.util.countToHumanReadable
import com.vitorpamplona.amethyst.service.countToHumanReadableBytes
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
import com.vitorpamplona.amethyst.ui.screen.loggedIn.mockAccountViewModel