diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesFragment.java index 9f1ac748d5..08c063c437 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesFragment.java @@ -120,6 +120,7 @@ public class ObjectivesFragment extends SubscriberFragment { public void onBindViewHolder(@NonNull ViewHolder holder, int position) { Objective objective = ObjectivesPlugin.getPlugin().getObjectives().get(position); holder.title.setText(MainApp.gs(R.string.nth_objective, position + 1)); + holder.revert.setVisibility(View.INVISIBLE); if (objective.getObjective() != 0) { holder.objective.setVisibility(View.VISIBLE); holder.objective.setText(MainApp.gs(objective.getObjective())); @@ -145,6 +146,9 @@ public class ObjectivesFragment extends SubscriberFragment { holder.verify.setVisibility(View.VISIBLE); holder.verify.setEnabled(objective.isCompleted() || enableFake.isChecked()); holder.start.setVisibility(View.GONE); + if(objective.isRevertable()) { + holder.revert.setVisibility(View.VISIBLE); + } holder.progress.setVisibility(View.VISIBLE); holder.progress.removeAllViews(); for (Objective.Task task : objective.getTasks()) { @@ -169,8 +173,20 @@ public class ObjectivesFragment extends SubscriberFragment { scrollToCurrentObjective(); startUpdateTimer(); }); + holder.revert.setOnClickListener((view) -> { + objective.setAccomplishedOn(null); + objective.setStartedOn(null); + if (position > 0) { + Objective prevObj = ObjectivesPlugin.getObjectives().get(position - 1); + prevObj.setAccomplishedOn(null); + } + notifyDataSetChanged(); + scrollToCurrentObjective(); + }); } + + @Override public int getItemCount() { return ObjectivesPlugin.getPlugin().getObjectives().size(); @@ -185,6 +201,7 @@ public class ObjectivesFragment extends SubscriberFragment { public LinearLayout progress; public Button verify; public Button start; + public Button revert; public ViewHolder(View itemView) { super(itemView); @@ -195,6 +212,7 @@ public class ObjectivesFragment extends SubscriberFragment { progress = itemView.findViewById(R.id.objective_progress); verify = itemView.findViewById(R.id.objective_verify); start = itemView.findViewById(R.id.objective_start); + revert = itemView.findViewById(R.id.objective_back); } } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective.java b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective.java index a1935c2ec6..83abe15688 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective.java @@ -42,6 +42,10 @@ public abstract class Objective { return true; } + public boolean isRevertable() { + return false; + } + public boolean isAccomplished() { return accomplishedOn != null; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective4.java b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective4.java index 5708565ebe..1bbb4ef7c2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective4.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective4.java @@ -25,4 +25,9 @@ public class Objective4 extends Objective { } }); } + + @Override + public boolean isRevertable() { + return true; + } } diff --git a/app/src/main/res/layout/objectives_item.xml b/app/src/main/res/layout/objectives_item.xml index b6029e5842..283195db23 100644 --- a/app/src/main/res/layout/objectives_item.xml +++ b/app/src/main/res/layout/objectives_item.xml @@ -65,6 +65,13 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/objectives_button_start" /> + +