Avoid frequent reloads

This commit is contained in:
Daniele Verducci 2024-11-24 08:31:30 +01:00
parent d5cb30cdd7
commit 35a3b42a32

View File

@ -34,6 +34,7 @@ import org.json.JSONException
class MainActivity : AppCompatActivity() { class MainActivity : AppCompatActivity() {
companion object { companion object {
val TAG = "MainActivity" val TAG = "MainActivity"
val UPDATE_EVERY_SECS: Long = 30
} }
lateinit var logbook: Logbook lateinit var logbook: Logbook
@ -145,7 +146,6 @@ class MainActivity : AppCompatActivity() {
// Reload data // Reload data
loadLogbook() loadLogbook()
handler.postDelayed(updateListRunnable, 1000*30)
} }
override fun onStop() { override fun onStop() {
@ -253,6 +253,10 @@ class MainActivity : AppCompatActivity() {
if (savingEvent) if (savingEvent)
return return
// Reset time counter
handler.removeCallbacks(updateListRunnable)
handler.postDelayed(updateListRunnable, UPDATE_EVERY_SECS*1000)
// Load data // Load data
setLoading(true) setLoading(true)
logbookRepo?.loadLogbook(this, object: LogbookLoadedListener{ logbookRepo?.loadLogbook(this, object: LogbookLoadedListener{