From 3e998c3115e5950c6a762b7e80bb5ac5f5f40892 Mon Sep 17 00:00:00 2001 From: Alex Baker Date: Tue, 2 Feb 2016 14:39:12 -0600 Subject: [PATCH] Only save if task changed --- .../astrid/activity/TaskEditFragment.java | 51 +++++++++++-------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/todoroo/astrid/activity/TaskEditFragment.java b/src/main/java/com/todoroo/astrid/activity/TaskEditFragment.java index 0089735a3..e20ddce25 100755 --- a/src/main/java/com/todoroo/astrid/activity/TaskEditFragment.java +++ b/src/main/java/com/todoroo/astrid/activity/TaskEditFragment.java @@ -332,26 +332,30 @@ public final class TaskEditFragment extends InjectingFragment implements EditNot /** Save task model from values in UI components */ public void save() { - for (TaskEditControlFragment fragment : getFragments()) { - fragment.apply(model); - } - taskService.save(model); + List fragments = getFragments(); + if (hasChanges(fragments)) { + for (TaskEditControlFragment fragment : fragments) { + fragment.apply(model); + } + taskService.save(model); - boolean tagsChanged = Flags.check(Flags.TAGS_CHANGED); + boolean tagsChanged = Flags.check(Flags.TAGS_CHANGED); - // Notify task list fragment in multi-column case - // since the activity isn't actually finishing - TaskListActivity tla = (TaskListActivity) getActivity(); + // Notify task list fragment in multi-column case + // since the activity isn't actually finishing + TaskListActivity tla = (TaskListActivity) getActivity(); - if (tagsChanged) { - tla.tagsChanged(); - } - if (isNewTask) { - tla.getTaskListFragment().onTaskCreated(model.getId(), model.getUuid()); + if (tagsChanged) { + tla.tagsChanged(); + } + if (isNewTask) { + tla.getTaskListFragment().onTaskCreated(model.getId(), model.getUuid()); + } + removeExtrasFromIntent(getActivity().getIntent()); + callback.taskEditFinished(); + } else { + discard(); } - - removeExtrasFromIntent(getActivity().getIntent()); - callback.taskEditFinished(); } private EditTitleControlSet getEditTitleControlSet() { @@ -386,12 +390,17 @@ public final class TaskEditFragment extends InjectingFragment implements EditNot * ====================================================================== */ - public void discardButtonClick() { - boolean hasChanges = false; - for (TaskEditControlFragment fragment : getFragments()) { - hasChanges |= fragment.hasChanges(model); + private boolean hasChanges(List fragments) { + for (TaskEditControlFragment fragment : fragments) { + if (fragment.hasChanges(model)) { + return true; + } } - if (hasChanges) { + return false; + } + + public void discardButtonClick() { + if (hasChanges(getFragments())) { dialogBuilder.newMessageDialog(R.string.discard_confirmation) .setPositiveButton(R.string.keep_editing, null) .setNegativeButton(R.string.discard, new DialogInterface.OnClickListener() {