mirror of
https://github.com/Michatec/michas-droid.git
synced 2026-05-30 18:02:43 +02:00
Schedule job if necessary only
This commit is contained in:
@@ -56,7 +56,7 @@ class MainApplication: Application() {
|
||||
}
|
||||
|
||||
Cache.cleanup(this)
|
||||
updateSyncJob()
|
||||
updateSyncJob(false)
|
||||
}
|
||||
|
||||
private fun listenApplications() {
|
||||
@@ -102,7 +102,7 @@ class MainApplication: Application() {
|
||||
val autoSync = Preferences[Preferences.Key.AutoSync]
|
||||
if (lastAutoSync != autoSync) {
|
||||
lastAutoSync = autoSync
|
||||
updateSyncJob()
|
||||
updateSyncJob(true)
|
||||
}
|
||||
} else if (it == Preferences.Key.UpdateUnstable) {
|
||||
val updateUnstable = Preferences[Preferences.Key.UpdateUnstable]
|
||||
@@ -114,9 +114,11 @@ class MainApplication: Application() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateSyncJob() {
|
||||
val autoSync = Preferences[Preferences.Key.AutoSync]
|
||||
private fun updateSyncJob(force: Boolean) {
|
||||
val jobScheduler = getSystemService(JOB_SCHEDULER_SERVICE) as JobScheduler
|
||||
val reschedule = force || !jobScheduler.allPendingJobs.any { it.id == Common.JOB_ID_SYNC }
|
||||
if (reschedule) {
|
||||
val autoSync = Preferences[Preferences.Key.AutoSync]
|
||||
when (autoSync) {
|
||||
Preferences.AutoSync.Never -> {
|
||||
jobScheduler.cancel(Common.JOB_ID_SYNC)
|
||||
@@ -143,6 +145,7 @@ class MainApplication: Application() {
|
||||
}
|
||||
}::class.java
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateProxy() {
|
||||
val type = Preferences[Preferences.Key.ProxyType].proxyType
|
||||
|
||||
Reference in New Issue
Block a user