diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsDataScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsDataScreen.kt index b58a44427eba..9474b6894777 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsDataScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsDataScreen.kt @@ -537,7 +537,7 @@ object SettingsDataScreen : SearchableSettings { subtitle = stringResource(SYMR.strings.pref_sync_now_subtitle), onClick = { if (!SyncDataJob.isRunning(context)) { - SyncDataJob.startNow(context) + SyncDataJob.startNow(context, manual = true) } else { context.toast(SYMR.strings.sync_in_progress) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/sync/SyncDataJob.kt b/app/src/main/java/eu/kanade/tachiyomi/data/sync/SyncDataJob.kt index 3aeca8fad241..66d4f6660613 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/sync/SyncDataJob.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/sync/SyncDataJob.kt @@ -15,6 +15,7 @@ import androidx.work.WorkerParameters import eu.kanade.domain.sync.SyncPreferences import eu.kanade.tachiyomi.data.notification.Notifications import eu.kanade.tachiyomi.util.system.cancelNotification +import eu.kanade.tachiyomi.util.system.isOnline import eu.kanade.tachiyomi.util.system.isRunning import eu.kanade.tachiyomi.util.system.setForegroundSafely import eu.kanade.tachiyomi.util.system.workManager @@ -31,6 +32,9 @@ class SyncDataJob(private val context: Context, workerParams: WorkerParameters) override suspend fun doWork(): Result { if (tags.contains(TAG_AUTO)) { + if (!context.isOnline()) { + return Result.retry() + } // Find a running manual worker. If exists, try again later if (context.workManager.isRunning(TAG_MANUAL)) { return Result.retry() @@ -93,17 +97,18 @@ class SyncDataJob(private val context: Context, workerParams: WorkerParameters) } } - fun startNow(context: Context) { + fun startNow(context: Context, manual: Boolean = false) { val wm = context.workManager if (wm.isRunning(TAG_JOB)) { // Already running either as a scheduled or manual job return } + val tag = if (manual) TAG_MANUAL else TAG_AUTO val request = OneTimeWorkRequestBuilder() .addTag(TAG_JOB) - .addTag(TAG_MANUAL) + .addTag(tag) .build() - context.workManager.enqueueUniqueWork(TAG_MANUAL, ExistingWorkPolicy.KEEP, request) + context.workManager.enqueueUniqueWork(tag, ExistingWorkPolicy.KEEP, request) } fun stop(context: Context) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryTab.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryTab.kt index 145494c30dc7..233b59e58abc 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryTab.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryTab.kt @@ -165,7 +165,7 @@ object LibraryTab : Tab { }, onClickSyncNow = { if (!SyncDataJob.isRunning(context)) { - SyncDataJob.startNow(context) + SyncDataJob.startNow(context, manual = true) } else { context.toast(SYMR.strings.sync_in_progress) }