Skip to content

Commit

Permalink
Fix sync coroutine scope
Browse files Browse the repository at this point in the history
  • Loading branch information
tuomas2 committed Jun 12, 2023
1 parent 433188d commit b39b15c
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ import androidx.core.view.children
import androidx.drawerlayout.widget.DrawerLayout
import androidx.lifecycle.lifecycleScope
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import net.bible.android.activity.R
Expand Down Expand Up @@ -147,6 +149,7 @@ import kotlin.system.exitProcess

const val DEFAULT_SYNC_INTERVAL = 5*60L // 5 minutes

private val syncScope = CoroutineScope(Dispatchers.IO)

class OpenLink(val url: String)

Expand Down Expand Up @@ -1333,14 +1336,14 @@ class MainBibleActivity : CustomTitlebarActivityBase() {
syncJob = null
}

fun onEvent(event: AppToBackgroundEvent) = lifecycleScope.launch {
fun onEvent(event: AppToBackgroundEvent) {
if (event.isMovedToBackground) {
mWholeAppWasInBackground = true
stopPeriodicSync()
synchronize(true)
syncScope.launch { synchronize(true) }
} else {
updateActions()
startSync()
syncScope.launch { startSync() }
}
}

Expand Down

0 comments on commit b39b15c

Please sign in to comment.