From 3feea7114614726cd0f5b87729a6c6195d180949 Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 24 Apr 2022 15:25:08 -0400 Subject: [PATCH] Add battery not low restriction for global updates (closes #6980) --- .../eu/kanade/tachiyomi/data/library/LibraryUpdateJob.kt | 2 ++ .../eu/kanade/tachiyomi/data/preference/PreferenceValues.kt | 1 + .../tachiyomi/ui/setting/SettingsLibraryController.kt | 6 ++++-- app/src/main/res/values/strings.xml | 1 + 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateJob.kt b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateJob.kt index 218c82554..be2c51ab2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateJob.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateJob.kt @@ -8,6 +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 @@ -43,6 +44,7 @@ class LibraryUpdateJob(private val context: Context, workerParams: WorkerParamet val constraints = Constraints.Builder() .setRequiredNetworkType(NetworkType.CONNECTED) .setRequiresCharging(DEVICE_CHARGING in restrictions) + .setRequiresBatteryNotLow(DEVICE_BATTERY_NOT_LOW in restrictions) .build() val request = PeriodicWorkRequestBuilder( diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceValues.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceValues.kt index 9ec000569..28cadea0c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceValues.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceValues.kt @@ -4,6 +4,7 @@ import eu.kanade.tachiyomi.R const val DEVICE_ONLY_ON_WIFI = "wifi" const val DEVICE_CHARGING = "ac" +const val DEVICE_BATTERY_NOT_LOW = "battery_not_low" const val MANGA_NON_COMPLETED = "manga_ongoing" const val MANGA_HAS_UNREAD = "manga_fully_read" diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt index b1e82abf0..93263b04d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt @@ -11,6 +11,7 @@ import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.database.models.Category import eu.kanade.tachiyomi.data.library.LibraryUpdateJob +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.MANGA_HAS_UNREAD @@ -159,8 +160,8 @@ class SettingsLibraryController : SettingsController() { multiSelectListPreference { bindTo(preferences.libraryUpdateDeviceRestriction()) titleRes = R.string.pref_library_update_restriction - entriesRes = arrayOf(R.string.connected_to_wifi, R.string.charging) - entryValues = arrayOf(DEVICE_ONLY_ON_WIFI, DEVICE_CHARGING) + entriesRes = arrayOf(R.string.connected_to_wifi, R.string.charging, R.string.battery_not_low) + entryValues = arrayOf(DEVICE_ONLY_ON_WIFI, DEVICE_CHARGING, DEVICE_BATTERY_NOT_LOW) visibleIf(preferences.libraryUpdateInterval()) { it > 0 } @@ -177,6 +178,7 @@ class SettingsLibraryController : SettingsController() { when (it) { DEVICE_ONLY_ON_WIFI -> context.getString(R.string.connected_to_wifi) DEVICE_CHARGING -> context.getString(R.string.charging) + DEVICE_BATTERY_NOT_LOW -> context.getString(R.string.battery_not_low) else -> it } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b3b4629fd..aab991a66 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -224,6 +224,7 @@ Automatic updates device restrictions Only on Wi-Fi Charging + Battery not low Restrictions: %s Skip updating titles