Merge pull request #1420 from tanja3981/improvement/#1269

[2.0] Improvement: Allow some objectives to go back.
This commit is contained in:
Milos Kozak 2019-03-19 23:42:38 +01:00 committed by GitHub
commit 381ae67829
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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) {
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,7 +173,19 @@ public class ObjectivesFragment extends SubscriberFragment {
scrollToCurrentObjective();
startUpdateTimer();
});
holder.revert.setOnClickListener((view) -> {
objective.setAccomplishedOn(null);
objective.setStartedOn(null);
if (position > 0) {
Objective prevObj = ObjectivesPlugin.getPlugin().getObjectives().get(position - 1);
prevObj.setAccomplishedOn(null);
}
notifyDataSetChanged();
scrollToCurrentObjective();
});
}
@Override
public int getItemCount() {
@ -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);
}
}
}

View file

@ -42,6 +42,10 @@ public abstract class Objective {
return true;
}
public boolean isRevertable() {
return false;
}
public boolean isAccomplished() {
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_height="wrap_content"
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>
</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_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_verify">Verify</string>
<string name="nsprofileview_units_label">Units</string>