Allow some objectives to go back.

This commit is contained in:
Tanja Schmidt 2018-07-30 18:51:36 +02:00
parent 1a73d60535
commit a5d1905be8
5 changed files with 35 additions and 0 deletions

View file

@ -120,6 +120,7 @@ public class ObjectivesFragment extends SubscriberFragment {
public void onBindViewHolder(@NonNull ViewHolder holder, int position) { public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
Objective objective = ObjectivesPlugin.getPlugin().getObjectives().get(position); Objective objective = ObjectivesPlugin.getPlugin().getObjectives().get(position);
holder.title.setText(MainApp.gs(R.string.nth_objective, position + 1)); holder.title.setText(MainApp.gs(R.string.nth_objective, position + 1));
holder.revert.setVisibility(View.INVISIBLE);
if (objective.getObjective() != 0) { if (objective.getObjective() != 0) {
holder.objective.setVisibility(View.VISIBLE); holder.objective.setVisibility(View.VISIBLE);
holder.objective.setText(MainApp.gs(objective.getObjective())); holder.objective.setText(MainApp.gs(objective.getObjective()));
@ -145,6 +146,9 @@ public class ObjectivesFragment extends SubscriberFragment {
holder.verify.setVisibility(View.VISIBLE); holder.verify.setVisibility(View.VISIBLE);
holder.verify.setEnabled(objective.isCompleted() || enableFake.isChecked()); holder.verify.setEnabled(objective.isCompleted() || enableFake.isChecked());
holder.start.setVisibility(View.GONE); holder.start.setVisibility(View.GONE);
if(objective.isRevertable()) {
holder.revert.setVisibility(View.VISIBLE);
}
holder.progress.setVisibility(View.VISIBLE); holder.progress.setVisibility(View.VISIBLE);
holder.progress.removeAllViews(); holder.progress.removeAllViews();
for (Objective.Task task : objective.getTasks()) { for (Objective.Task task : objective.getTasks()) {
@ -169,8 +173,20 @@ public class ObjectivesFragment extends SubscriberFragment {
scrollToCurrentObjective(); scrollToCurrentObjective();
startUpdateTimer(); 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 @Override
public int getItemCount() { public int getItemCount() {
return ObjectivesPlugin.getPlugin().getObjectives().size(); return ObjectivesPlugin.getPlugin().getObjectives().size();
@ -185,6 +201,7 @@ public class ObjectivesFragment extends SubscriberFragment {
public LinearLayout progress; public LinearLayout progress;
public Button verify; public Button verify;
public Button start; public Button start;
public Button revert;
public ViewHolder(View itemView) { public ViewHolder(View itemView) {
super(itemView); super(itemView);
@ -195,6 +212,7 @@ public class ObjectivesFragment extends SubscriberFragment {
progress = itemView.findViewById(R.id.objective_progress); progress = itemView.findViewById(R.id.objective_progress);
verify = itemView.findViewById(R.id.objective_verify); verify = itemView.findViewById(R.id.objective_verify);
start = itemView.findViewById(R.id.objective_start); start = itemView.findViewById(R.id.objective_start);
revert = itemView.findViewById(R.id.objective_back);
} }
} }
} }

View file

@ -42,6 +42,10 @@ public abstract class Objective {
return true; return true;
} }
public boolean isRevertable() {
return false;
}
public boolean isAccomplished() { public boolean isAccomplished() {
return accomplishedOn != null; return accomplishedOn != null;
} }

View file

@ -25,4 +25,9 @@ public class Objective4 extends Objective {
} }
}); });
} }
@Override
public boolean isRevertable() {
return true;
}
} }

View file

@ -65,6 +65,13 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/objectives_button_start" /> android:text="@string/objectives_button_start" />
<Button
android:id="@+id/objective_back"
style="@style/Widget.AppCompat.Button.Borderless.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/objectives_button_back" />
</LinearLayout> </LinearLayout>
</android.support.v7.widget.CardView> </android.support.v7.widget.CardView>

View file

@ -55,6 +55,7 @@
<string name="description_xdrip_status_line">Show information about your loop on your xDrip+ watchface.</string> <string name="description_xdrip_status_line">Show information about your loop on your xDrip+ watchface.</string>
<string name="description_sms_communicator">Remote control AndroidAPS using SMS commands.</string> <string name="description_sms_communicator">Remote control AndroidAPS using SMS commands.</string>
<string name="objectives_button_back">Back</string>
<string name="objectives_button_start">Start</string> <string name="objectives_button_start">Start</string>
<string name="objectives_button_verify">Verify</string> <string name="objectives_button_verify">Verify</string>
<string name="nsprofileview_units_label">Units</string> <string name="nsprofileview_units_label">Units</string>