mirror of https://github.com/tasks/tasks
Delete lists and accounts in a transaction
* Delete google tasks when they're remotely cleared or deleted * Delete caldav tasks when they're remotely deletedpull/685/merge
parent
f0fd3fa944
commit
fd79338c26
@ -0,0 +1,105 @@
|
||||
package org.tasks.data;
|
||||
|
||||
import android.arch.persistence.room.Dao;
|
||||
import android.arch.persistence.room.Delete;
|
||||
import android.arch.persistence.room.Query;
|
||||
import android.arch.persistence.room.Transaction;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Dao
|
||||
public abstract class DeletionDao {
|
||||
@Query("SELECT _id FROM tasks WHERE deleted > 0")
|
||||
public abstract List<Long> getDeleted();
|
||||
|
||||
@Query("DELETE FROM caldav_tasks WHERE task IN(:ids)")
|
||||
abstract void deleteCaldavTasks(List<Long> ids);
|
||||
|
||||
@Query("DELETE FROM google_tasks WHERE task IN(:ids)")
|
||||
abstract void deleteGoogleTasks(List<Long> ids);
|
||||
|
||||
@Query("DELETE FROM tags WHERE task IN(:ids)")
|
||||
abstract void deleteTags(List<Long> ids);
|
||||
|
||||
@Query("DELETE FROM locations WHERE task IN(:ids)")
|
||||
abstract void deleteGeofences(List<Long> ids);
|
||||
|
||||
@Query("DELETE FROM alarms WHERE task IN(:ids)")
|
||||
abstract void deleteAlarms(List<Long> ids);
|
||||
|
||||
@Query("DELETE FROM tasks WHERE _id IN(:ids)")
|
||||
abstract void deleteTasks(List<Long> ids);
|
||||
|
||||
@Transaction
|
||||
public void delete(List<Long> ids) {
|
||||
deleteAlarms(ids);
|
||||
deleteGeofences(ids);
|
||||
deleteTags(ids);
|
||||
deleteGoogleTasks(ids);
|
||||
deleteCaldavTasks(ids);
|
||||
deleteTasks(ids);
|
||||
}
|
||||
|
||||
@Query("SELECT task FROM google_tasks WHERE deleted = 0 AND list_id = :listId")
|
||||
abstract List<Long> getActiveGoogleTasks(String listId);
|
||||
|
||||
@Delete
|
||||
abstract void deleteGoogleTaskList(GoogleTaskList googleTaskList);
|
||||
|
||||
@Transaction
|
||||
public List<Long> delete(GoogleTaskList googleTaskList) {
|
||||
List<Long> tasks = getActiveGoogleTasks(googleTaskList.getRemoteId());
|
||||
delete(tasks);
|
||||
deleteGoogleTaskList(googleTaskList);
|
||||
return tasks;
|
||||
}
|
||||
|
||||
@Delete
|
||||
abstract void deleteGoogleTaskAccount(GoogleTaskAccount googleTaskAccount);
|
||||
|
||||
@Query("SELECT * FROM google_task_lists WHERE account = :account ORDER BY title ASC")
|
||||
abstract List<GoogleTaskList> getLists(String account);
|
||||
|
||||
@Transaction
|
||||
public List<Long> delete(GoogleTaskAccount googleTaskAccount) {
|
||||
List<Long> deleted = new ArrayList<>();
|
||||
for (GoogleTaskList list : getLists(googleTaskAccount.getAccount())) {
|
||||
deleted.addAll(delete(list));
|
||||
}
|
||||
deleteGoogleTaskAccount(googleTaskAccount);
|
||||
return deleted;
|
||||
}
|
||||
|
||||
@Query("UPDATE tasks SET deleted = :timestamp WHERE _id IN(:ids)")
|
||||
public abstract void markDeleted(long timestamp, List<Long> ids);
|
||||
|
||||
@Query("SELECT task FROM caldav_tasks WHERE calendar = :calendar AND deleted = 0")
|
||||
abstract List<Long> getActiveCaldavTasks(String calendar);
|
||||
|
||||
@Delete
|
||||
abstract void deleteCaldavCalendar(CaldavCalendar caldavCalendar);
|
||||
|
||||
@Transaction
|
||||
public List<Long> delete(CaldavCalendar caldavCalendar) {
|
||||
List<Long> tasks = getActiveCaldavTasks(caldavCalendar.getUuid());
|
||||
delete(tasks);
|
||||
deleteCaldavCalendar(caldavCalendar);
|
||||
return tasks;
|
||||
}
|
||||
|
||||
@Query("SELECT * FROM caldav_calendar WHERE account = :account")
|
||||
abstract List<CaldavCalendar> getCalendars(String account);
|
||||
|
||||
@Delete
|
||||
abstract void deleteCaldavAccount(CaldavAccount caldavAccount);
|
||||
|
||||
@Transaction
|
||||
public List<Long> delete(CaldavAccount caldavAccount) {
|
||||
List<Long> deleted = new ArrayList<>();
|
||||
for (CaldavCalendar calendar : getCalendars(caldavAccount.getUuid())) {
|
||||
deleted.addAll(delete(calendar));
|
||||
}
|
||||
deleteCaldavAccount(caldavAccount);
|
||||
return deleted;
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package org.tasks.jobs;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import com.evernote.android.job.util.support.PersistableBundleCompat;
|
||||
import com.todoroo.astrid.alarms.AlarmService;
|
||||
import com.todoroo.astrid.reminders.ReminderService;
|
||||
import com.todoroo.astrid.timers.TimerPlugin;
|
||||
import javax.inject.Inject;
|
||||
import org.tasks.injection.InjectingJob;
|
||||
import org.tasks.injection.JobComponent;
|
||||
import org.tasks.location.GeofenceService;
|
||||
import org.tasks.notifications.NotificationManager;
|
||||
import timber.log.Timber;
|
||||
|
||||
public class CleanupJob extends InjectingJob {
|
||||
|
||||
static final String EXTRA_TASK_IDS = "extra_task_ids";
|
||||
|
||||
@Inject NotificationManager notificationManager;
|
||||
@Inject GeofenceService geofenceService;
|
||||
@Inject TimerPlugin timerPlugin;
|
||||
@Inject ReminderService reminderService;
|
||||
@Inject AlarmService alarmService;
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
protected Result onRunJob(@NonNull Params params) {
|
||||
super.onRunJob(params);
|
||||
|
||||
PersistableBundleCompat extras = params.getExtras();
|
||||
long[] tasks = extras.getLongArray(EXTRA_TASK_IDS);
|
||||
if (tasks == null) {
|
||||
Timber.e("No task ids provided");
|
||||
return Result.FAILURE;
|
||||
}
|
||||
for (long task : tasks) {
|
||||
alarmService.cancelAlarms(task);
|
||||
reminderService.cancelReminder(task);
|
||||
notificationManager.cancel(task);
|
||||
geofenceService.cancelGeofences(task);
|
||||
}
|
||||
timerPlugin.updateNotifications();
|
||||
return Result.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void inject(JobComponent component) {
|
||||
component.inject(this);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue