mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-09 18:10:29 +00:00
fix(ui): enable task detail text selection and compact extension stats (#1511)
This commit is contained in:
6 files changed
+236
-71
No files matched your search
@@ -0,0 +1,23 @@
|
||||
abstract final class CompactCountFormatter {
|
||||
// Counts start compacting at ten thousand by product convention, then use
|
||||
// progressively larger decimal units so the rendered label stays bounded.
|
||||
static const _units = [
|
||||
(divisor: 1000000000000000000, suffix: 'qi'),
|
||||
(divisor: 1000000000000000, suffix: 'q'),
|
||||
(divisor: 1000000000000, suffix: 't'),
|
||||
(divisor: 1000000000, suffix: 'b'),
|
||||
(divisor: 1000000, suffix: 'm'),
|
||||
(divisor: 10000, suffix: 'w'),
|
||||
];
|
||||
|
||||
static String format(int count) {
|
||||
if (count <= 0) return '0';
|
||||
if (count < _units.last.divisor) return count.toString();
|
||||
|
||||
final unit = _units.firstWhere((unit) => count >= unit.divisor);
|
||||
final whole = count ~/ unit.divisor;
|
||||
final tenth = (count % unit.divisor) ~/ (unit.divisor ~/ 10);
|
||||
final value = whole < 10 && tenth > 0 ? '$whole.$tenth' : '$whole';
|
||||
return '$value${unit.suffix}';
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user