mirror of https://github.com/tasks/tasks
Separate sync work for each service
parent
15637e784e
commit
7078dfa2bf
@ -0,0 +1,42 @@
|
||||
package org.tasks.jobs
|
||||
|
||||
import android.content.Context
|
||||
import androidx.hilt.Assisted
|
||||
import androidx.hilt.work.WorkerInject
|
||||
import androidx.work.WorkerParameters
|
||||
import kotlinx.coroutines.*
|
||||
import org.tasks.LocalBroadcastManager
|
||||
import org.tasks.R
|
||||
import org.tasks.analytics.Firebase
|
||||
import org.tasks.caldav.CaldavSynchronizer
|
||||
import org.tasks.data.CaldavAccount.Companion.TYPE_CALDAV
|
||||
import org.tasks.data.CaldavDao
|
||||
import org.tasks.preferences.Preferences
|
||||
|
||||
class SyncCaldavWork @WorkerInject constructor(
|
||||
@Assisted context: Context,
|
||||
@Assisted workerParams: WorkerParameters,
|
||||
firebase: Firebase,
|
||||
localBroadcastManager: LocalBroadcastManager,
|
||||
preferences: Preferences,
|
||||
private val caldavDao: CaldavDao,
|
||||
private val caldavSynchronizer: CaldavSynchronizer
|
||||
) : SyncWork(context, workerParams, firebase, localBroadcastManager, preferences) {
|
||||
|
||||
override suspend fun enabled() = caldavDao.getAccounts(TYPE_CALDAV).isNotEmpty()
|
||||
|
||||
override val syncStatus = R.string.p_sync_ongoing_caldav
|
||||
|
||||
override suspend fun doSync() {
|
||||
caldavJobs().awaitAll()
|
||||
}
|
||||
|
||||
private suspend fun caldavJobs(): List<Deferred<Unit>> = coroutineScope {
|
||||
caldavDao.getAccounts(TYPE_CALDAV)
|
||||
.map {
|
||||
async(Dispatchers.IO) {
|
||||
caldavSynchronizer.sync(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package org.tasks.jobs
|
||||
|
||||
import android.content.Context
|
||||
import androidx.hilt.Assisted
|
||||
import androidx.hilt.work.WorkerInject
|
||||
import androidx.work.WorkerParameters
|
||||
import kotlinx.coroutines.*
|
||||
import org.tasks.LocalBroadcastManager
|
||||
import org.tasks.R
|
||||
import org.tasks.analytics.Firebase
|
||||
import org.tasks.data.CaldavAccount.Companion.TYPE_ETESYNC
|
||||
import org.tasks.data.CaldavDao
|
||||
import org.tasks.etesync.EteSynchronizer
|
||||
import org.tasks.preferences.Preferences
|
||||
|
||||
class SyncEteSyncWork @WorkerInject constructor(
|
||||
@Assisted context: Context,
|
||||
@Assisted workerParams: WorkerParameters,
|
||||
firebase: Firebase,
|
||||
localBroadcastManager: LocalBroadcastManager,
|
||||
preferences: Preferences,
|
||||
private val caldavDao: CaldavDao,
|
||||
private val eteSynchronizer: EteSynchronizer
|
||||
) : SyncWork(context, workerParams, firebase, localBroadcastManager, preferences) {
|
||||
|
||||
override suspend fun enabled() = caldavDao.getAccounts(TYPE_ETESYNC).isNotEmpty()
|
||||
|
||||
override val syncStatus = R.string.p_sync_ongoing_etesync
|
||||
|
||||
override suspend fun doSync() {
|
||||
etesyncJobs().awaitAll()
|
||||
}
|
||||
|
||||
private suspend fun etesyncJobs(): List<Deferred<Unit>> = coroutineScope {
|
||||
caldavDao.getAccounts(TYPE_ETESYNC)
|
||||
.map {
|
||||
async(Dispatchers.IO) {
|
||||
eteSynchronizer.sync(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package org.tasks.jobs
|
||||
|
||||
import android.content.Context
|
||||
import androidx.hilt.Assisted
|
||||
import androidx.hilt.work.WorkerInject
|
||||
import androidx.work.WorkerParameters
|
||||
import kotlinx.coroutines.*
|
||||
import org.tasks.LocalBroadcastManager
|
||||
import org.tasks.R
|
||||
import org.tasks.analytics.Firebase
|
||||
import org.tasks.data.GoogleTaskListDao
|
||||
import org.tasks.gtasks.GoogleTaskSynchronizer
|
||||
import org.tasks.preferences.Preferences
|
||||
|
||||
class SyncGoogleTasksWork @WorkerInject constructor(
|
||||
@Assisted context: Context,
|
||||
@Assisted workerParams: WorkerParameters,
|
||||
firebase: Firebase,
|
||||
localBroadcastManager: LocalBroadcastManager,
|
||||
preferences: Preferences,
|
||||
private val googleTaskListDao: GoogleTaskListDao,
|
||||
private val googleTaskSynchronizer: GoogleTaskSynchronizer
|
||||
) : SyncWork(context, workerParams, firebase, localBroadcastManager, preferences) {
|
||||
|
||||
override suspend fun enabled() = googleTaskListDao.getAccounts().isNotEmpty()
|
||||
|
||||
override val syncStatus = R.string.p_sync_ongoing_google_tasks
|
||||
|
||||
override suspend fun doSync() {
|
||||
googleTaskJobs().awaitAll()
|
||||
}
|
||||
|
||||
private suspend fun googleTaskJobs(): List<Deferred<Unit>> = coroutineScope {
|
||||
googleTaskListDao
|
||||
.getAccounts()
|
||||
.mapIndexed { i, account ->
|
||||
async(Dispatchers.IO) {
|
||||
googleTaskSynchronizer.sync(account, i)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue