Don't run automatic backup or library update jobs if battery is low

(cherry picked from commit 74f74eef56ce83b52cd7969f705e370c7977af87)

# Conflicts:
#	app/build.gradle.kts
#	app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateJob.kt
This commit is contained in:
arkon
2023-08-24 22:25:29 -04:00
committed by Jobobby04
parent 8f07b7ab5b
commit 105a971a4c
18 changed files with 90 additions and 77 deletions
@@ -14,7 +14,7 @@ class CreateCategoryWithName(
private val initialFlags: Long
get() {
val sort = preferences.librarySortingMode().get()
val sort = preferences.sortingMode().get()
return sort.type.flag or sort.direction.flag
}
@@ -10,7 +10,7 @@ class ResetCategoryFlags(
) {
suspend fun await() {
val sort = preferences.librarySortingMode().get()
val sort = preferences.sortingMode().get()
categoryRepository.updateAllFlags(sort.type + sort.direction)
}
}
@@ -8,6 +8,6 @@ class SetDisplayMode(
) {
fun await(display: LibraryDisplayMode) {
preferences.libraryDisplayMode().set(display)
preferences.displayMode().set(display)
}
}
@@ -16,7 +16,7 @@ class SetSortModeForCategory(
suspend fun await(categoryId: Long?, type: LibrarySort.Type, direction: LibrarySort.Direction) {
// SY -->
if (preferences.groupLibraryBy().get() != LibraryGroup.BY_DEFAULT) {
preferences.librarySortingMode().set(LibrarySort(type, direction))
preferences.sortingMode().set(LibrarySort(type, direction))
return
}
// SY <--
@@ -30,7 +30,7 @@ class SetSortModeForCategory(
),
)
} else {
preferences.librarySortingMode().set(LibrarySort(type, direction))
preferences.sortingMode().set(LibrarySort(type, direction))
categoryRepository.updateAllFlags(flags)
}
}
@@ -13,24 +13,24 @@ class LibraryPreferences(
private val preferenceStore: PreferenceStore,
) {
fun libraryDisplayMode() = preferenceStore.getObject("pref_display_mode_library", LibraryDisplayMode.default, LibraryDisplayMode.Serializer::serialize, LibraryDisplayMode.Serializer::deserialize)
fun displayMode() = preferenceStore.getObject("pref_display_mode_library", LibraryDisplayMode.default, LibraryDisplayMode.Serializer::serialize, LibraryDisplayMode.Serializer::deserialize)
fun librarySortingMode() = preferenceStore.getObject("library_sorting_mode", LibrarySort.default, LibrarySort.Serializer::serialize, LibrarySort.Serializer::deserialize)
fun sortingMode() = preferenceStore.getObject("library_sorting_mode", LibrarySort.default, LibrarySort.Serializer::serialize, LibrarySort.Serializer::deserialize)
fun portraitColumns() = preferenceStore.getInt("pref_library_columns_portrait_key", 0)
fun landscapeColumns() = preferenceStore.getInt("pref_library_columns_landscape_key", 0)
fun libraryUpdateInterval() = preferenceStore.getInt("pref_library_update_interval_key", 0)
fun libraryUpdateLastTimestamp() = preferenceStore.getLong("library_update_last_timestamp", 0L)
fun lastUpdatedTimestamp() = preferenceStore.getLong("library_update_last_timestamp", 0L)
fun autoUpdateInterval() = preferenceStore.getInt("pref_library_update_interval_key", 0)
fun libraryUpdateDeviceRestriction() = preferenceStore.getStringSet(
fun autoUpdateDeviceRestrictions() = preferenceStore.getStringSet(
"library_update_restriction",
setOf(
DEVICE_ONLY_ON_WIFI,
),
)
fun libraryUpdateMangaRestriction() = preferenceStore.getStringSet(
fun autoUpdateMangaRestrictions() = preferenceStore.getStringSet(
"library_update_manga_restriction",
setOf(
MANGA_HAS_UNREAD,
@@ -101,9 +101,9 @@ class LibraryPreferences(
fun categorizedDisplaySettings() = preferenceStore.getBoolean("categorized_display", false)
fun libraryUpdateCategories() = preferenceStore.getStringSet("library_update_categories", emptySet())
fun updateCategories() = preferenceStore.getStringSet("library_update_categories", emptySet())
fun libraryUpdateCategoriesExclude() = preferenceStore.getStringSet("library_update_categories_exclude", emptySet())
fun updateCategoriesExclude() = preferenceStore.getStringSet("library_update_categories_exclude", emptySet())
// endregion
@@ -164,7 +164,6 @@ class LibraryPreferences(
const val DEVICE_ONLY_ON_WIFI = "wifi"
const val DEVICE_NETWORK_NOT_METERED = "network_not_metered"
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"