Show library size in About screen

This commit is contained in:
Nolan Hoenert
2025-12-31 20:38:09 -07:00
committed by Alexander Capehart
parent 8fd3ef8eaa
commit 869ab8aadb
5 changed files with 50 additions and 2 deletions
@@ -100,7 +100,8 @@ constructor(
library.albums.size,
library.artists.size,
library.genres.size,
library.songs.sumOf { it.durationMs })
library.songs.sumOf { it.durationMs },
library.songs.sumOf { it.size })
L.d("Updated statistics: ${_statistics.value}")
}
@@ -362,7 +363,8 @@ constructor(
val albums: Int,
val artists: Int,
val genres: Int,
val durationMs: Long
val durationMs: Long,
val totalSizeBytes: Long
)
}
@@ -36,6 +36,7 @@ import org.oxycblt.auxio.playback.formatDurationMs
import org.oxycblt.auxio.ui.ViewBindingFragment
import org.oxycblt.auxio.util.collectImmediately
import org.oxycblt.auxio.util.openInBrowser
import org.oxycblt.auxio.util.formatFileSize
import org.oxycblt.auxio.util.startIntent
import org.oxycblt.auxio.util.systemBarInsetsCompat
@@ -98,6 +99,11 @@ class AboutFragment : ViewBindingFragment<FragmentAboutBinding>() {
getString(
R.string.fmt_lib_total_duration,
(statistics?.durationMs ?: 0).formatDurationMs(false))
binding.aboutTotalSize.text =
getString(
R.string.fmt_lib_total_size,
(statistics?.totalSizeBytes ?: 0L).formatFileSize())
}
private fun Context.sendEmail(recipient: String) {
@@ -0,0 +1,28 @@
/*
* Copyright (c) 2025 Auxio Project
* SizeUtil.kt is part of Auxio.
*/
package org.oxycblt.auxio.util
import java.util.Locale
/**
* Format a byte count into a human readable string (B, KB, MB, GB, ...).
*/
fun Long.formatFileSize(): String {
if (this <= 0L) return "0 B"
var size = this.toDouble()
val units = arrayOf("B", "KB", "MB", "GB", "TB")
var unitIndex = 0
while (size >= 1024.0 && unitIndex < units.size - 1) {
size /= 1024.0
unitIndex++
}
val formatted = when {
size >= 100 -> String.format(Locale.getDefault(), "%.0f", size)
size >= 10 -> String.format(Locale.getDefault(), "%.1f", size)
else -> String.format(Locale.getDefault(), "%.2f", size)
}
return "$formatted ${units[unitIndex]}"
}
@@ -364,6 +364,17 @@
app:layout_constraintTop_toBottomOf="@+id/about_licenses"
tools:text="Total duration: 16:16:16" />
<TextView
android:id="@+id/about_total_size"
style="@style/Widget.Auxio.TextView.Icon"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:drawableStartCompat="@drawable/ic_time_24"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/about_licenses"
tools:text="Total size: 1.2 GB" />
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
</LinearLayout>
+1
View File
@@ -470,6 +470,7 @@
<string name="fmt_lib_genre_count">Genres loaded: %d</string>
<!-- As in the total duration of all songs in the music library -->
<string name="fmt_lib_total_duration">Total duration: %s</string>
<string name="fmt_lib_total_size">Total size: %s</string>
<plurals name="fmt_song_count">
<item quantity="one">%d song</item>