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