Skip to content

Commit

Permalink
Force synchronize when opening drawer
Browse files Browse the repository at this point in the history
  • Loading branch information
tuomas2 committed Jun 7, 2023
1 parent d4b6de4 commit 5f7d5ca
Showing 1 changed file with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,7 @@ class MainBibleActivity : CustomTitlebarActivityBase() {
drawerLayout.closeDrawers()
} else {
drawerLayout.openDrawer(GravityCompat.START)
lifecycleScope.launch { synchronize(true) }
}
}

Expand Down Expand Up @@ -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) {
Expand All @@ -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
*/
Expand Down

0 comments on commit 5f7d5ca

Please sign in to comment.