From 275ec02d821669c354851341dbc1eb426a64fe95 Mon Sep 17 00:00:00 2001 From: Tuomas Airaksinen Date: Sun, 11 Jun 2023 16:54:09 +0300 Subject: [PATCH] Do not force-sync when switching to another activity --- .../view/activity/page/MainBibleActivity.kt | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/net/bible/android/view/activity/page/MainBibleActivity.kt b/app/src/main/java/net/bible/android/view/activity/page/MainBibleActivity.kt index e445ed3f1d..0e2bbcb6a9 100644 --- a/app/src/main/java/net/bible/android/view/activity/page/MainBibleActivity.kt +++ b/app/src/main/java/net/bible/android/view/activity/page/MainBibleActivity.kt @@ -551,11 +551,6 @@ class MainBibleActivity : CustomTitlebarActivityBase() { override fun onPause() { CommonUtils.windowControl.windowRepository.saveIntoDb(false) - if(CommonUtils.isGoogleDriveSyncEnabled) { - syncJob?.cancel(StopSync()) - syncJob = null - lifecycleScope.launch { DeviceSynchronize.start() } - } fullScreen = false; if(CommonUtils.showCalculator) { (window.decorView as ViewGroup).removeView(binding.root) @@ -1268,7 +1263,9 @@ class MainBibleActivity : CustomTitlebarActivityBase() { */ override fun onRestart() { super.onRestart() - startSync() + if(syncJob != null) { + startSync() + } if (mWholeAppWasInBackground) { mWholeAppWasInBackground = false refreshIfNightModeChange() @@ -1286,7 +1283,11 @@ class MainBibleActivity : CustomTitlebarActivityBase() { if(now - lastSynchronized > syncInterval) { synchronize(true) } - syncJob = lifecycleScope.launch { periodicSync() } + if(syncJob != null) { + Log.e(TAG, "syncJob already exists") + } else { + syncJob = lifecycleScope.launch { periodicSync() } + } } } } @@ -1338,6 +1339,11 @@ class MainBibleActivity : CustomTitlebarActivityBase() { fun onEvent(event: AppToBackgroundEvent) { if (event.isMovedToBackground) { mWholeAppWasInBackground = true + syncJob?.cancel(StopSync()) + syncJob = null + if(CommonUtils.isGoogleDriveSyncEnabled) { + lifecycleScope.launch { DeviceSynchronize.start() } + } } else { updateActions()