Include Google Task children when moving tasks

pull/820/head
Alex Baker 6 years ago
parent ec02699166
commit 72efc18009

@ -65,6 +65,10 @@ public abstract class TaskDao {
@Query("SELECT * FROM tasks WHERE _id IN (:taskIds)") @Query("SELECT * FROM tasks WHERE _id IN (:taskIds)")
public abstract List<Task> fetch(List<Long> taskIds); public abstract List<Task> fetch(List<Long> taskIds);
@Query(
"SELECT tasks.* FROM tasks LEFT JOIN google_tasks ON gt_task = _id WHERE _id IN (:taskIds) AND gt_parent NOT IN (:taskIds)")
public abstract List<Task> fetchExcludingChildren(List<Long> taskIds);
@Query("SELECT COUNT(1) FROM tasks WHERE timerStart > 0 AND deleted = 0") @Query("SELECT COUNT(1) FROM tasks WHERE timerStart > 0 AND deleted = 0")
public abstract int activeTimers(); public abstract int activeTimers();

@ -1,6 +1,11 @@
package com.todoroo.astrid.service; package com.todoroo.astrid.service;
import static com.google.common.collect.Iterables.concat;
import static com.google.common.collect.Iterables.transform;
import static com.google.common.collect.Lists.transform;
import static com.todoroo.andlib.utility.DateUtilities.now; import static com.todoroo.andlib.utility.DateUtilities.now;
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
import com.todoroo.astrid.api.CaldavFilter; import com.todoroo.astrid.api.CaldavFilter;
import com.todoroo.astrid.api.Filter; import com.todoroo.astrid.api.Filter;
@ -44,7 +49,7 @@ public class TaskMover {
} }
public void move(List<Long> tasks, Filter selectedList) { public void move(List<Long> tasks, Filter selectedList) {
List<Task> fetch = taskDao.fetch(tasks); List<Task> fetch = taskDao.fetchExcludingChildren(tasks);
for (Task task : fetch) { for (Task task : fetch) {
performMove(task, selectedList); performMove(task, selectedList);
task.putTransitory(SyncFlags.GTASKS_SUPPRESS_SYNC, true); task.putTransitory(SyncFlags.GTASKS_SUPPRESS_SYNC, true);
@ -76,6 +81,7 @@ public class TaskMover {
private void performMove(Task task, Filter selectedList) { private void performMove(Task task, Filter selectedList) {
long id = task.getId(); long id = task.getId();
GoogleTask googleTask = googleTaskDao.getByTaskId(id); GoogleTask googleTask = googleTaskDao.getByTaskId(id);
List<GoogleTask> googleTaskChildren = emptyList();
if (googleTask != null if (googleTask != null
&& selectedList instanceof GtasksFilter && selectedList instanceof GtasksFilter
&& googleTask.getListId().equals(((GtasksFilter) selectedList).getRemoteId())) { && googleTask.getListId().equals(((GtasksFilter) selectedList).getRemoteId())) {
@ -89,8 +95,8 @@ public class TaskMover {
} }
task.putTransitory(SyncFlags.FORCE_SYNC, true); task.putTransitory(SyncFlags.FORCE_SYNC, true);
if (googleTask != null) { if (googleTask != null) {
googleTask.setDeleted(now()); googleTaskChildren = googleTaskDao.getChildren(id);
googleTaskDao.update(googleTask); googleTaskDao.markDeleted(now(), id);
} }
if (caldavTask != null) { if (caldavTask != null) {
@ -99,12 +105,25 @@ public class TaskMover {
} }
if (selectedList instanceof GtasksFilter) { if (selectedList instanceof GtasksFilter) {
googleTaskDao.insertAndShift( String listId = ((GtasksFilter) selectedList).getRemoteId();
new GoogleTask(id, ((GtasksFilter) selectedList).getRemoteId()), googleTaskDao.insertAndShift(new GoogleTask(id, listId), preferences.addGoogleTasksToTop());
preferences.addGoogleTasksToTop()); if (!googleTaskChildren.isEmpty()) {
googleTaskDao.insert(
transform(
googleTaskChildren,
child -> {
GoogleTask newChild = new GoogleTask(child.getTask(), listId);
newChild.setOrder(child.getOrder());
newChild.setParent(id);
return newChild;
}));
}
} else if (selectedList instanceof CaldavFilter) { } else if (selectedList instanceof CaldavFilter) {
String listId = ((CaldavFilter) selectedList).getUuid();
caldavDao.insert( caldavDao.insert(
new CaldavTask(id, ((CaldavFilter) selectedList).getUuid(), UUIDHelper.newUUID())); transform(
concat(singletonList(id), transform(googleTaskChildren, GoogleTask::getId)),
_id -> new CaldavTask(_id, listId, UUIDHelper.newUUID())));
} }
} }
} }

@ -42,6 +42,9 @@ public interface CaldavDao {
@Insert @Insert
long insert(CaldavTask caldavTask); long insert(CaldavTask caldavTask);
@Insert
void insert(Iterable<CaldavTask> tasks);
@Update @Update
void update(CaldavTask caldavTask); void update(CaldavTask caldavTask);

@ -16,6 +16,9 @@ public abstract class GoogleTaskDao {
@Insert @Insert
public abstract void insert(GoogleTask task); public abstract void insert(GoogleTask task);
@Insert
public abstract void insert(Iterable<GoogleTask> tasks);
@Transaction @Transaction
public void insertAndShift(GoogleTask task, boolean top) { public void insertAndShift(GoogleTask task, boolean top) {
if (top) { if (top) {
@ -70,6 +73,9 @@ public abstract class GoogleTaskDao {
@Update @Update
public abstract void update(GoogleTask googleTask); public abstract void update(GoogleTask googleTask);
@Query("UPDATE google_tasks SET gt_deleted = :now WHERE gt_task = :task OR gt_parent = :task")
public abstract void markDeleted(long now, long task);
@Delete @Delete
public abstract void delete(GoogleTask deleted); public abstract void delete(GoogleTask deleted);
@ -88,6 +94,9 @@ public abstract class GoogleTaskDao {
@Query("SELECT gt_task FROM google_tasks WHERE gt_parent IN (:ids)") @Query("SELECT gt_task FROM google_tasks WHERE gt_parent IN (:ids)")
public abstract List<Long> getChildren(List<Long> ids); public abstract List<Long> getChildren(List<Long> ids);
@Query("SELECT * FROM google_tasks WHERE gt_parent = :id AND gt_deleted = 0")
public abstract List<GoogleTask> getChildren(Long id);
@Query( @Query(
"SELECT IFNULL(MAX(gt_order), -1) + 1 FROM google_tasks WHERE gt_list_id = :listId AND gt_parent = :parent") "SELECT IFNULL(MAX(gt_order), -1) + 1 FROM google_tasks WHERE gt_list_id = :listId AND gt_parent = :parent")
public abstract long getBottom(String listId, long parent); public abstract long getBottom(String listId, long parent);

Loading…
Cancel
Save