|
@@ -8,10 +8,7 @@ import androidx.work.PeriodicWorkRequestBuilder
|
|
|
import androidx.work.WorkManager
|
|
|
import androidx.work.Worker
|
|
|
import androidx.work.WorkerParameters
|
|
|
-import eu.kanade.tachiyomi.data.preference.DEVICE_BATTERY_NOT_LOW
|
|
|
-import eu.kanade.tachiyomi.data.preference.DEVICE_CHARGING
|
|
|
-import eu.kanade.tachiyomi.data.preference.DEVICE_ONLY_ON_WIFI
|
|
|
-import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
|
|
+import eu.kanade.tachiyomi.data.preference.*
|
|
|
import eu.kanade.tachiyomi.util.system.isConnectedToWifi
|
|
|
import uy.kohesive.injekt.Injekt
|
|
|
import uy.kohesive.injekt.api.get
|
|
@@ -22,8 +19,9 @@ class LibraryUpdateJob(private val context: Context, workerParams: WorkerParamet
|
|
|
|
|
|
override fun doWork(): Result {
|
|
|
val preferences = Injekt.get<PreferencesHelper>()
|
|
|
- if (requiresWifiConnection(preferences) && !context.isConnectedToWifi()) {
|
|
|
- Result.failure()
|
|
|
+ val restrictions = preferences.libraryUpdateDeviceRestriction().get()
|
|
|
+ if ((DEVICE_ONLY_ON_WIFI in restrictions) && !context.isConnectedToWifi()) {
|
|
|
+ return Result.failure()
|
|
|
}
|
|
|
|
|
|
return if (LibraryUpdateService.start(context)) {
|
|
@@ -42,7 +40,7 @@ class LibraryUpdateJob(private val context: Context, workerParams: WorkerParamet
|
|
|
if (interval > 0) {
|
|
|
val restrictions = preferences.libraryUpdateDeviceRestriction().get()
|
|
|
val constraints = Constraints.Builder()
|
|
|
- .setRequiredNetworkType(NetworkType.CONNECTED)
|
|
|
+ .setRequiredNetworkType(if (DEVICE_NETWORK_NOT_METERED in restrictions) { NetworkType.UNMETERED } else { NetworkType.CONNECTED })
|
|
|
.setRequiresCharging(DEVICE_CHARGING in restrictions)
|
|
|
.setRequiresBatteryNotLow(DEVICE_BATTERY_NOT_LOW in restrictions)
|
|
|
.build()
|
|
@@ -62,10 +60,5 @@ class LibraryUpdateJob(private val context: Context, workerParams: WorkerParamet
|
|
|
WorkManager.getInstance(context).cancelAllWorkByTag(TAG)
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- fun requiresWifiConnection(preferences: PreferencesHelper): Boolean {
|
|
|
- val restrictions = preferences.libraryUpdateDeviceRestriction().get()
|
|
|
- return DEVICE_ONLY_ON_WIFI in restrictions
|
|
|
- }
|
|
|
}
|
|
|
}
|