diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/sync/domain/SyncController.kt b/app/src/main/kotlin/org/koitharu/kotatsu/sync/domain/SyncController.kt index ba00c6285..dff6ca7c6 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/sync/domain/SyncController.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/sync/domain/SyncController.kt @@ -43,10 +43,12 @@ class SyncController @Inject constructor( private val defaultGcPeriod = TimeUnit.DAYS.toMillis(2) // gc period if sync disabled override fun onInvalidated(tables: Set) { - requestSync( - favourites = TABLE_FAVOURITES in tables || TABLE_FAVOURITE_CATEGORIES in tables, - history = TABLE_HISTORY in tables, - ) + val favourites = (TABLE_FAVOURITES in tables || TABLE_FAVOURITE_CATEGORIES in tables) + && !isSyncActiveOrPending(authorityFavourites) + val history = TABLE_HISTORY in tables && !isSyncActiveOrPending(authorityHistory) + if (favourites || history) { + requestSync(favourites, history) + } } fun isEnabled(account: Account): Boolean { @@ -126,6 +128,11 @@ class SyncController @Inject constructor( } } + private fun isSyncActiveOrPending(authority: String): Boolean { + val account = peekAccount() ?: return false + return ContentResolver.isSyncActive(account, authority) || ContentResolver.isSyncPending(account, authority) + } + companion object { @JvmStatic