home: ratelimit textual progress updates

A la the notification, except on a shorter time internal since
it's more for efficiency rather than avoiding system rate limits.
This commit is contained in:
Alexander Capehart 2024-12-20 22:15:04 -05:00
parent 6bad9e719d
commit 5ff949c49c
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47

View file

@ -20,6 +20,7 @@ package org.oxycblt.auxio.home
import android.annotation.SuppressLint
import android.os.Bundle
import android.os.SystemClock
import android.view.LayoutInflater
import android.view.MenuItem
import android.view.View
@ -94,6 +95,7 @@ class HomeFragment :
private var storagePermissionLauncher: ActivityResultLauncher<String>? = null
private var getContentLauncher: ActivityResultLauncher<String>? = null
private var pendingImportTarget: Playlist? = null
private var lastUpdateTime = -1L
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@ -368,13 +370,19 @@ class HomeFragment :
}
is IndexingProgress.Songs -> {
// Actively loading songs, show the current progress.
binding.homeIndexingStatus.text =
getString(R.string.fmt_indexing, progress.loaded, progress.explored)
binding.homeIndexingProgress.apply {
isIndeterminate = false
max = progress.explored
this.progress = progress.loaded
}
// Avoid aggressively updating the UI for rapid progress updates.
val now = SystemClock.elapsedRealtime()
if (lastUpdateTime > -1 && (now - lastUpdateTime) < 250) {
return
}
lastUpdateTime = SystemClock.elapsedRealtime()
binding.homeIndexingStatus.text =
getString(R.string.fmt_indexing, progress.loaded, progress.explored)
}
}
}