From 35a3b42a32d8691186300e58c6fbcaebe9093e78 Mon Sep 17 00:00:00 2001 From: Daniele Verducci Date: Sun, 24 Nov 2024 08:31:30 +0100 Subject: [PATCH] Avoid frequent reloads --- .../java/it/danieleverducci/lunatracker/MainActivity.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/it/danieleverducci/lunatracker/MainActivity.kt b/app/src/main/java/it/danieleverducci/lunatracker/MainActivity.kt index 0e3f8df..ac93d57 100644 --- a/app/src/main/java/it/danieleverducci/lunatracker/MainActivity.kt +++ b/app/src/main/java/it/danieleverducci/lunatracker/MainActivity.kt @@ -34,6 +34,7 @@ import org.json.JSONException class MainActivity : AppCompatActivity() { companion object { val TAG = "MainActivity" + val UPDATE_EVERY_SECS: Long = 30 } lateinit var logbook: Logbook @@ -145,7 +146,6 @@ class MainActivity : AppCompatActivity() { // Reload data loadLogbook() - handler.postDelayed(updateListRunnable, 1000*30) } override fun onStop() { @@ -253,6 +253,10 @@ class MainActivity : AppCompatActivity() { if (savingEvent) return + // Reset time counter + handler.removeCallbacks(updateListRunnable) + handler.postDelayed(updateListRunnable, UPDATE_EVERY_SECS*1000) + // Load data setLoading(true) logbookRepo?.loadLogbook(this, object: LogbookLoadedListener{