mirror of https://github.com/tasks/tasks
Add UpdateCalendarWork
parent
86b8f9dcca
commit
730c82a037
@ -0,0 +1,41 @@
|
||||
package org.tasks.jobs
|
||||
|
||||
import android.content.Context
|
||||
import androidx.hilt.Assisted
|
||||
import androidx.hilt.work.WorkerInject
|
||||
import androidx.work.WorkerParameters
|
||||
import com.todoroo.astrid.gcal.GCalHelper
|
||||
import org.tasks.analytics.Firebase
|
||||
import org.tasks.calendars.CalendarEventProvider
|
||||
import org.tasks.data.TaskDao
|
||||
import org.tasks.injection.BaseWorker
|
||||
import org.tasks.preferences.PermissionChecker
|
||||
|
||||
class UpdateCalendarWork @WorkerInject constructor(
|
||||
@Assisted context: Context,
|
||||
@Assisted workerParams: WorkerParameters,
|
||||
firebase: Firebase,
|
||||
private val taskDao: TaskDao,
|
||||
private val gCalHelper: GCalHelper,
|
||||
private val calendarEventProvider: CalendarEventProvider,
|
||||
private val permissionChecker: PermissionChecker
|
||||
) : BaseWorker(context, workerParams, firebase) {
|
||||
|
||||
override suspend fun run(): Result {
|
||||
if (!permissionChecker.canAccessCalendars()) {
|
||||
return Result.failure()
|
||||
}
|
||||
val taskId = inputData.getLong(EXTRA_ID, -1)
|
||||
val task = taskDao.fetch(taskId) ?: return Result.failure()
|
||||
if (task.hasDueDate()) {
|
||||
gCalHelper.updateEvent(task)
|
||||
} else {
|
||||
calendarEventProvider.deleteEvent(task)
|
||||
}
|
||||
return Result.success()
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val EXTRA_ID = "extra_id"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue