From 5f7d5cad188ca7aff6c3177fc1f87a84407ae5a8 Mon Sep 17 00:00:00 2001 From: Tuomas Airaksinen Date: Wed, 7 Jun 2023 09:43:59 +0300 Subject: [PATCH] Force synchronize when opening drawer --- .../view/activity/page/MainBibleActivity.kt | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 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 a54fc06e73..38c95a0548 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 @@ -616,6 +616,7 @@ class MainBibleActivity : CustomTitlebarActivityBase() { drawerLayout.closeDrawers() } else { drawerLayout.openDrawer(GravityCompat.START) + lifecycleScope.launch { synchronize(true) } } } @@ -1293,12 +1294,7 @@ class MainBibleActivity : CustomTitlebarActivityBase() { Log.i(TAG, "Periodic sync starting") try { while (true) { - windowRepository.saveIntoDb(false) - if(DeviceSynchronize.hasChanges()) { - Log.i(TAG, "Performing periodic sync") - DeviceSynchronize.start() - DeviceSynchronize.waitUntilFinished() - } + synchronize() delay(CommonUtils.settings.getLong("gdrive_sync_interval", 60L) * 1000) } } catch (e: StopSync) { @@ -1307,6 +1303,17 @@ class MainBibleActivity : CustomTitlebarActivityBase() { } } + private suspend fun synchronize(force: Boolean = false) { + if(CommonUtils.isGoogleDriveSyncEnabled && DeviceSynchronize.signedIn) { + windowRepository.saveIntoDb(false) + if (force || DeviceSynchronize.hasChanges()) { + Log.i(TAG, "Performing periodic sync") + DeviceSynchronize.start() + DeviceSynchronize.waitUntilFinished() + } + } + } + /** * Need to know when app is returned to foreground to check the screen colours */