|
@@ -9,8 +9,9 @@ import androidx.work.WorkManager
|
|
|
import androidx.work.Worker
|
|
|
import androidx.work.WorkerParameters
|
|
|
import eu.kanade.tachiyomi.data.preference.CHARGING
|
|
|
+import eu.kanade.tachiyomi.data.preference.ONLY_ON_WIFI
|
|
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
|
|
-import eu.kanade.tachiyomi.data.preference.UNMETERED_NETWORK
|
|
|
+import eu.kanade.tachiyomi.util.system.isConnectedToWifi
|
|
|
import uy.kohesive.injekt.Injekt
|
|
|
import uy.kohesive.injekt.api.get
|
|
|
import java.util.concurrent.TimeUnit
|
|
@@ -19,6 +20,11 @@ class LibraryUpdateJob(private val context: Context, workerParams: WorkerParamet
|
|
|
Worker(context, workerParams) {
|
|
|
|
|
|
override fun doWork(): Result {
|
|
|
+ val preferences = Injekt.get<PreferencesHelper>()
|
|
|
+ if (requiresWifiConnection(preferences) && !context.isConnectedToWifi()) {
|
|
|
+ Result.failure()
|
|
|
+ }
|
|
|
+
|
|
|
return if (LibraryUpdateService.start(context)) {
|
|
|
Result.success()
|
|
|
} else {
|
|
@@ -34,16 +40,9 @@ class LibraryUpdateJob(private val context: Context, workerParams: WorkerParamet
|
|
|
val interval = prefInterval ?: preferences.libraryUpdateInterval().get()
|
|
|
if (interval > 0) {
|
|
|
val restrictions = preferences.libraryUpdateRestriction().get()
|
|
|
- val acRestriction = CHARGING in restrictions
|
|
|
- val wifiRestriction = if (UNMETERED_NETWORK in restrictions) {
|
|
|
- NetworkType.UNMETERED
|
|
|
- } else {
|
|
|
- NetworkType.CONNECTED
|
|
|
- }
|
|
|
-
|
|
|
val constraints = Constraints.Builder()
|
|
|
- .setRequiredNetworkType(wifiRestriction)
|
|
|
- .setRequiresCharging(acRestriction)
|
|
|
+ .setRequiredNetworkType(NetworkType.CONNECTED)
|
|
|
+ .setRequiresCharging(CHARGING in restrictions)
|
|
|
.build()
|
|
|
|
|
|
val request = PeriodicWorkRequestBuilder<LibraryUpdateJob>(
|
|
@@ -61,5 +60,10 @@ class LibraryUpdateJob(private val context: Context, workerParams: WorkerParamet
|
|
|
WorkManager.getInstance(context).cancelAllWorkByTag(TAG)
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ fun requiresWifiConnection(preferences: PreferencesHelper): Boolean {
|
|
|
+ val restrictions = preferences.libraryUpdateRestriction().get()
|
|
|
+ return ONLY_ON_WIFI in restrictions
|
|
|
+ }
|
|
|
}
|
|
|
}
|