Update taskIsChild logic

gtask_related_email
Alex Baker 6 years ago
parent 7c031f1141
commit 691a6e3931

@ -29,8 +29,7 @@ public final class CaldavTaskAdapter extends TaskAdapter {
public boolean canMove(ViewHolder sourceVh, ViewHolder targetVh) { public boolean canMove(ViewHolder sourceVh, ViewHolder targetVh) {
TaskContainer source = sourceVh.task; TaskContainer source = sourceVh.task;
int to = targetVh.getAdapterPosition(); int to = targetVh.getAdapterPosition();
return !taskIsChild(source, to);
return !taskIsChild(source.getCaldavTask(), to);
} }
@Override @Override
@ -52,7 +51,7 @@ public final class CaldavTaskAdapter extends TaskAdapter {
@Override @Override
public void moved(int from, int to, int indent) { public void moved(int from, int to, int indent) {
TaskContainer task = getTask(from); TaskContainer task = getTask(from);
TaskContainer previous = to > 0 ? getTask(to-1) : null; TaskContainer previous = to > 0 ? getTask(to - 1) : null;
long newParent = task.getParent(); long newParent = task.getParent();
if (indent == 0) { if (indent == 0) {
@ -94,28 +93,16 @@ public final class CaldavTaskAdapter extends TaskAdapter {
caldavDao.update(caldavTask); caldavDao.update(caldavTask);
} }
private boolean taskIsChild(CaldavTask parent, int destinationIndex) { private boolean taskIsChild(TaskContainer source, int destinationIndex) {
// Don't allow dropping a parent onto their child TaskContainer destination = getTask(destinationIndex);
TaskContainer ownChildCheck = getTask(destinationIndex); while (destination.getParent() != 0) {
long movingCaldavTaskId = parent.getId(); if (destination.getParent() == source.getParent()) {
int itemIndex = destinationIndex; return false;
// Iterate levels of the hierarchy
while (ownChildCheck != null && ownChildCheck.getParent() != 0) {
// If the task we're trying to move is a parent of the destination, cancel the move
if (ownChildCheck.getParent() == movingCaldavTaskId) {
return true;
} }
if (destination.getParent() == source.getId()) {
// Loop through the items in the view above the current task, looking for the parent return true;
long searchParent = ownChildCheck.getParent();
while (ownChildCheck.getId() != searchParent) {
// Handle case of parent not found in search, which shouldn't ever occur
if (itemIndex == 0) {
Timber.w("Couldn't find parent");
return true;
}
ownChildCheck = getTask(--itemIndex);
} }
destination = getTask(--destinationIndex);
} }
return false; return false;
} }

Loading…
Cancel
Save