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:
parent
6bad9e719d
commit
5ff949c49c
1 changed files with 10 additions and 2 deletions
|
@ -20,6 +20,7 @@ package org.oxycblt.auxio.home
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.os.SystemClock
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
@ -94,6 +95,7 @@ class HomeFragment :
|
||||||
private var storagePermissionLauncher: ActivityResultLauncher<String>? = null
|
private var storagePermissionLauncher: ActivityResultLauncher<String>? = null
|
||||||
private var getContentLauncher: ActivityResultLauncher<String>? = null
|
private var getContentLauncher: ActivityResultLauncher<String>? = null
|
||||||
private var pendingImportTarget: Playlist? = null
|
private var pendingImportTarget: Playlist? = null
|
||||||
|
private var lastUpdateTime = -1L
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
@ -368,13 +370,19 @@ class HomeFragment :
|
||||||
}
|
}
|
||||||
is IndexingProgress.Songs -> {
|
is IndexingProgress.Songs -> {
|
||||||
// Actively loading songs, show the current progress.
|
// Actively loading songs, show the current progress.
|
||||||
binding.homeIndexingStatus.text =
|
|
||||||
getString(R.string.fmt_indexing, progress.loaded, progress.explored)
|
|
||||||
binding.homeIndexingProgress.apply {
|
binding.homeIndexingProgress.apply {
|
||||||
isIndeterminate = false
|
isIndeterminate = false
|
||||||
max = progress.explored
|
max = progress.explored
|
||||||
this.progress = progress.loaded
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue