mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-21 20:47:03 -05:00
Change global update unmetered connection restriction to connected to Wi-Fi (closes #6117)
This commit is contained in:
parent
3d8f123e05
commit
8a70c3353f
6 changed files with 23 additions and 20 deletions
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package eu.kanade.tachiyomi.data.preference
|
|||
|
||||
import eu.kanade.tachiyomi.R
|
||||
|
||||
const val UNMETERED_NETWORK = "wifi"
|
||||
const val ONLY_ON_WIFI = "wifi"
|
||||
const val CHARGING = "ac"
|
||||
|
||||
/**
|
||||
|
|
|
@ -236,7 +236,7 @@ class PreferencesHelper(val context: Context) {
|
|||
|
||||
fun libraryUpdateInterval() = flowPrefs.getInt(Keys.libraryUpdateInterval, 24)
|
||||
|
||||
fun libraryUpdateRestriction() = flowPrefs.getStringSet(Keys.libraryUpdateRestriction, setOf(UNMETERED_NETWORK))
|
||||
fun libraryUpdateRestriction() = flowPrefs.getStringSet(Keys.libraryUpdateRestriction, setOf(ONLY_ON_WIFI))
|
||||
|
||||
fun libraryUpdateCategories() = flowPrefs.getStringSet(Keys.libraryUpdateCategories, emptySet())
|
||||
fun libraryUpdateCategoriesExclude() = flowPrefs.getStringSet(Keys.libraryUpdateCategoriesExclude, emptySet())
|
||||
|
|
|
@ -66,7 +66,7 @@ class SettingsDownloadController : SettingsController() {
|
|||
}
|
||||
switchPreference {
|
||||
key = Keys.downloadOnlyOverWifi
|
||||
titleRes = R.string.pref_download_only_over_wifi
|
||||
titleRes = R.string.connected_to_wifi
|
||||
defaultValue = true
|
||||
}
|
||||
preferenceCategory {
|
||||
|
|
|
@ -12,8 +12,8 @@ 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.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.data.preference.asImmediateFlow
|
||||
import eu.kanade.tachiyomi.data.track.TrackManager
|
||||
import eu.kanade.tachiyomi.databinding.PrefLibraryColumnsBinding
|
||||
|
@ -161,9 +161,9 @@ class SettingsLibraryController : SettingsController() {
|
|||
multiSelectListPreference {
|
||||
key = Keys.libraryUpdateRestriction
|
||||
titleRes = R.string.pref_library_update_restriction
|
||||
entriesRes = arrayOf(R.string.network_unmetered, R.string.charging)
|
||||
entryValues = arrayOf(UNMETERED_NETWORK, CHARGING)
|
||||
defaultValue = setOf(UNMETERED_NETWORK)
|
||||
entriesRes = arrayOf(R.string.connected_to_wifi, R.string.charging)
|
||||
entryValues = arrayOf(ONLY_ON_WIFI, CHARGING)
|
||||
defaultValue = setOf(ONLY_ON_WIFI)
|
||||
|
||||
preferences.libraryUpdateInterval().asImmediateFlow { isVisible = it > 0 }
|
||||
.launchIn(viewScope)
|
||||
|
@ -179,7 +179,7 @@ class SettingsLibraryController : SettingsController() {
|
|||
.sorted()
|
||||
.map {
|
||||
when (it) {
|
||||
UNMETERED_NETWORK -> context.getString(R.string.network_unmetered)
|
||||
ONLY_ON_WIFI -> context.getString(R.string.connected_to_wifi)
|
||||
CHARGING -> context.getString(R.string.charging)
|
||||
else -> it
|
||||
}
|
||||
|
|
|
@ -221,7 +221,7 @@
|
|||
<string name="update_weekly">Weekly</string>
|
||||
<string name="pref_library_update_prioritization">Update order</string>
|
||||
<string name="pref_library_update_restriction">Update restrictions</string>
|
||||
<string name="network_unmetered">Unmetered network</string>
|
||||
<string name="connected_to_wifi">Only on Wi-Fi</string>
|
||||
<string name="charging">Charging</string>
|
||||
<string name="restrictions">Restrictions: %s</string>
|
||||
<string name="pref_update_only_non_completed">Only update ongoing manga</string>
|
||||
|
@ -384,7 +384,6 @@
|
|||
|
||||
<!-- Downloads section -->
|
||||
<string name="pref_download_directory">Download location</string>
|
||||
<string name="pref_download_only_over_wifi">Only download over Wi-Fi</string>
|
||||
<string name="pref_category_delete_chapters">Delete chapters</string>
|
||||
<string name="pref_remove_after_marked_as_read">After marked as read</string>
|
||||
<string name="pref_remove_after_read">Automatically after reading</string>
|
||||
|
|
Loading…
Reference in a new issue