Skip to content

Commit 15ba5f5

Browse files
committed
app: show container RAM usage with a unit per side, fastfetch style
The RAM chip on the running-container cards, and the same text on the details screen, printed whole megabytes on both sides: "1/1536 MB (0%)". Now each side picks its own unit with two decimals, spaced the way fastfetch prints memory: "13.50 MB / 1.50 GB (1%)", and a container idling below a megabyte reads in KB instead of "0 MB". Without a limit the chip stays used-only, "13.50 MB (0.2%)" of the host's RAM, as before. The backend already sends kilobytes; the app threw the precision away when it stored megabytes in OSInfo. Keep the kilobytes and format them through a new ResourceLimits.formatMemoryUsage(). The limit chip and the config form keep formatMemory()'s round "128 MB" / "1.5 GB" look, since a slider label with two decimals would only add noise. The two string resources change argument type from %d to %s, and a stale translation of the old key would make getString() throw, so they are new keys and the old ones are dropped from every locale. Signed-off-by: ravindu644 <droidcasts@protonmail.com>
1 parent 899085a commit 15ba5f5

14 files changed

Lines changed: 30 additions & 28 deletions

File tree

‎Android/app/src/main/java/com/droidspaces/app/ui/component/RunningContainerCard.kt‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,11 @@ fun RunningContainerCard(
132132

133133

134134
// Resource usage row, only shown when we have real data. Null is the
135-
// only "no data" signal: a container idling under 1MB reads as 0 and
135+
// only "no data" signal: a container idling under 1 MB reads in KB and
136136
// still deserves its chip.
137-
val ramUsageMb = osInfo?.ramUsageMb
137+
val ramUsedKb = osInfo?.ramUsedKb
138138
val cpuPercent = osInfo?.cpuUsage ?: -1.0
139-
if (ramUsageMb != null || cpuPercent >= 0.0) {
139+
if (ramUsedKb != null || cpuPercent >= 0.0) {
140140
Surface(
141141
modifier = Modifier.fillMaxWidth(),
142142
shape = RoundedCornerShape(10.dp),
@@ -171,7 +171,7 @@ fun RunningContainerCard(
171171
)
172172
}
173173
}
174-
if (ramUsageMb != null) {
174+
if (ramUsedKb != null) {
175175
Row(
176176
verticalAlignment = Alignment.CenterVertically,
177177
horizontalArrangement = Arrangement.spacedBy(4.dp)

‎Android/app/src/main/java/com/droidspaces/app/ui/screen/ContainerDetailsScreen.kt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,9 @@ private fun hasOSInfoChanged(old: ContainerOSInfoManager.OSInfo, new: ContainerO
295295
old.ipAddress != new.ipAddress ||
296296
old.uptime != new.uptime ||
297297
old.cpuUsage != new.cpuUsage ||
298-
old.ramUsageMb != new.ramUsageMb ||
298+
old.ramUsedKb != new.ramUsedKb ||
299299
old.ramPercent != new.ramPercent ||
300-
old.ramLimitMb != new.ramLimitMb
300+
old.ramLimitKb != new.ramLimitKb
301301
}
302302

303303

‎Android/app/src/main/java/com/droidspaces/app/util/ContainerOSInfoManager.kt‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,18 @@ object ContainerOSInfoManager {
4040
val ipAddress: String?,
4141
val uptime: String? = null,
4242
val cpuUsage: Double? = null,
43-
val ramUsageMb: Long? = null,
43+
val ramUsedKb: Long? = null,
4444
val ramPercent: Double? = null,
4545
/** The memory limit in force. Null when unlimited, and then [ramPercent] is of the host's RAM. */
46-
val ramLimitMb: Long? = null
46+
val ramLimitKb: Long? = null
4747
) {
48-
/** "115/512 MB (22%)" under a limit, "115 MB (1.5%)" of the host without one. */
48+
/** "13.50 MB / 1.50 GB (1%)" under a limit, "13.50 MB (0.2%)" of the host without one.
49+
* Each side picks its own unit, the way fastfetch prints memory. */
4950
fun ramLabel(context: Context): String? {
50-
val used = ramUsageMb ?: return null
51+
val used = ResourceLimits.formatMemoryUsage(context, ramUsedKb ?: return null)
5152
val percent = ramPercent ?: 0.0
52-
return if (ramLimitMb != null) context.getString(R.string.ram_limit_percent_label, used.toInt(), ramLimitMb.toInt(), percent)
53-
else context.getString(R.string.ram_percent_label, used.toInt(), percent)
53+
return if (ramLimitKb != null) context.getString(R.string.ram_used_of_limit_label, used, ResourceLimits.formatMemoryUsage(context, ramLimitKb), percent)
54+
else context.getString(R.string.ram_used_label, used, percent)
5455
}
5556
}
5657

@@ -137,9 +138,9 @@ object ContainerOSInfoManager {
137138
ipAddress = obj.optString("ip").ifEmpty { null },
138139
uptime = obj.optString("uptime").ifEmpty { null },
139140
cpuUsage = (if (cpuLimitPermill > 0) cpuPermill * 100.0 / cpuLimitPermill else cpuPermill / 10.0).coerceIn(0.0, 100.0),
140-
ramUsageMb = if (ramTotalKb > 0) ramUsedKb / 1024 else null,
141+
ramUsedKb = if (ramTotalKb > 0) ramUsedKb else null,
141142
ramPercent = if (ramTotalKb > 0) (ramUsedKb.toDouble() / ramBaseKb * 100.0).coerceIn(0.0, 100.0) else null,
142-
ramLimitMb = (ramLimitKb / 1024).takeIf { it > 0 }
143+
ramLimitKb = ramLimitKb.takeIf { it > 0 }
143144
)
144145
}
145146

‎Android/app/src/main/java/com/droidspaces/app/util/ResourceLimits.kt‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@ object ResourceLimits {
3333
if (mb < 1024) context.getString(R.string.memory_mb, mb)
3434
else context.getString(R.string.memory_gb, String.format(Locale.getDefault(), "%.1f", mb / 1024f))
3535

36+
/** A live figure: "13.50 MB", "2.88 GB", two decimals in whichever unit fits, the way
37+
* fastfetch prints memory. Limits keep the round [formatMemory] look. */
38+
fun formatMemoryUsage(context: Context, kb: Long): String {
39+
fun two(v: Double) = String.format(Locale.getDefault(), "%.2f", v)
40+
return when {
41+
kb < 1024 -> context.getString(R.string.memory_kb, two(kb.toDouble()))
42+
kb < 1024 * 1024 -> context.getString(R.string.memory_mb_decimal, two(kb / 1024.0))
43+
else -> context.getString(R.string.memory_gb, two(kb / 1048576.0))
44+
}
45+
}
46+
3647
fun formatCores(context: Context, cores: Float): String {
3748
val n = if (cores % 1f == 0f) cores.toInt().toString() else String.format(Locale.getDefault(), "%.1f", cores)
3849
return context.resources.getQuantityString(R.plurals.cpu_cores, if (cores == 1f) 1 else 2, n)

‎Android/app/src/main/res/values-cs/strings.xml‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,6 @@
311311
<string name="cpu_usage_label">Využití CPU</string>
312312
<string name="ram_usage_label">Využití RAM</string>
313313
<string name="cpu_percent_label">%1$.1f%%</string>
314-
<string name="ram_percent_label">%1$d MB (%2$.1f%%)</string>
315314
<string name="sessions_running_plural">Počet spuštěných relací: %1$d · klepnutím obnovíte</string>
316315
<string name="session_running_singular">Spuštěna 1 relace · klepnutím obnovíte</string>
317316
<string name="systemd_services">Služby systemd</string>
@@ -585,5 +584,4 @@
585584
<item quantity="many">%1$s jader</item>
586585
<item quantity="other">%1$s jader</item>
587586
</plurals>
588-
<string name="ram_limit_percent_label">%1$d/%2$d MB (%3$.0f%%)</string>
589587
</resources>

‎Android/app/src/main/res/values-de/strings.xml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,6 @@
367367
<string name="cpu_usage_label">CPU-Auslastung</string>
368368
<string name="ram_usage_label">RAM-Auslastung</string>
369369
<string name="cpu_percent_label">%1$.1f%%</string>
370-
<string name="ram_percent_label">%1$d MB (%2$.1f%%)</string>
371370
<string name="sessions_running_plural">%1$d Sitzungen laufen · Zur Rückkehr antippen</string>
372371
<string name="session_running_singular">1 Sitzung läuft · Zur Rückkehr antippen</string>
373372
<string name="please_wait_hint">Bitte warten, während wir Ihre Anfrage bearbeiten...</string>

‎Android/app/src/main/res/values-in/strings.xml‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,6 @@
351351
<string name="cpu_usage_label">Penggunaan CPU</string>
352352
<string name="ram_usage_label">Penggunaan RAM</string>
353353
<string name="cpu_percent_label">%1$.1f%%</string>
354-
<string name="ram_percent_label">%1$d MB (%2$.1f%%)</string>
355354
<string name="sessions_running_plural">%1$d sesi berjalan · ketuk untuk memulihkan</string>
356355
<string name="session_running_singular">1 sesi berjalan · ketuk untuk memulihkan</string>
357356
<string name="masked_legend">Disembunyikan</string>
@@ -563,7 +562,6 @@
563562
</plurals>
564563
<string name="env_placeholder">KEY=VALUE, satu per baris. Baris yang diawali dengan # akan diabaikan.</string>
565564
<string name="env_lines_skipped">%1$d baris tidak dalam format KEY=VALUE</string>
566-
<string name="ram_limit_percent_label">%1$d/%2$d MB (%3$.0f%%)</string>
567565
<string name="fetching_logs">Mengambil log...</string>
568566
<string name="journal_load_error_title">Tidak dapat memuat log</string>
569567
<string name="journal_load_error_message">Unit mungkin tidak memiliki jurnal, atau kontainer tidak dapat dijangkau.</string>

‎Android/app/src/main/res/values-it/strings.xml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,6 @@
368368
<string name="cpu_usage_label">Utilizzo CPU</string>
369369
<string name="ram_usage_label">Utilizzo RAM</string>
370370
<string name="cpu_percent_label">%1$.1f%%</string>
371-
<string name="ram_percent_label">%1$d MB (%2$.1f%%)</string>
372371
<string name="sessions_running_plural">%1$d sessioni in esecuzione · toccare per ripristinare</string>
373372
<string name="session_running_singular">1 sessione in esecuzione · toccare per ripristinare</string>
374373
<string name="please_wait_hint">Attendi mentre elaboriamo la tua richiesta...</string>

‎Android/app/src/main/res/values-km/strings.xml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,6 @@
262262
<string name="cpu_usage_label">ការប្រើប្រាស់ស៊ីភីយូ</string>
263263
<string name="ram_usage_label">ការប្រើប្រាស់ RAM</string>
264264
<string name="cpu_percent_label">%1$.1f%%</string>
265-
<string name="ram_percent_label">%1$d មេកាបៃ (%2$.1f%%)</string>
266265
<string name="sessions_running_plural">កំពុងដំណើរការវគ្គ %1$d · ចុចដើម្បីស្ដារ</string>
267266
<string name="session_running_singular">កំពុងដំណើរការវគ្គចំនួន 1 · ចុចដើម្បីស្ដារ</string>
268267
<string name="systemd_services">សេវាកម្មប្រព័ន្ធ</string>

‎Android/app/src/main/res/values-ko/strings.xml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,6 @@
336336
<string name="cpu_usage_label">CPU 사용량</string>
337337
<string name="ram_usage_label">RAM 사용량</string>
338338
<string name="cpu_percent_label">%1$.1f%%</string>
339-
<string name="ram_percent_label">%1$d MB(%2$.1f%%)</string>
340339
<string name="sessions_running_plural">%1$d개 세션 실행 중 · 탭하여 복원</string>
341340
<string name="session_running_singular">1개 세션 실행 중 · 탭하여 복원</string>
342341
<!-- Systemd Screen -->

0 commit comments

Comments
 (0)