ui: Use KiB instead of KB for free space
All checks were successful
/ build-debug (push) Successful in 4m27s

Fixes #19.
This commit is contained in:
Peter Cai 2024-03-30 15:30:40 -04:00
parent 1ed5a4de38
commit 80adac68c8
2 changed files with 10 additions and 3 deletions

View file

@ -5,7 +5,6 @@ import android.app.Dialog
import android.content.DialogInterface
import android.os.Bundle
import android.text.Editable
import android.text.format.Formatter
import android.util.Log
import android.view.*
import android.widget.ProgressBar
@ -131,7 +130,7 @@ class ProfileDownloadFragment : BaseMaterialDialogFragment(),
// Fetch remaining NVRAM
val str = channel.lpa.euiccInfo2?.freeNvram?.also {
freeNvram = it
}?.let { Formatter.formatShortFileSize(requireContext(), it.toLong()) }
}?.let { formatFreeSpace(it) }
withContext(Dispatchers.Main) {
profileDownloadFreeSpace.text = getString(R.string.profile_download_free_space,

View file

@ -19,4 +19,12 @@ fun ByteArray.encodeHex(): String {
sb.append(String.format("%02X", this[i]))
}
return sb.toString()
}
}
fun formatFreeSpace(size: Int): String =
// SIM cards probably won't have much more space anytime soon.
if (size >= 1024) {
"%.2f KiB".format(size.toDouble() / 1024)
} else {
"$size B"
}