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 293d052a27..c9399edbc3 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 @@ -10,6 +10,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.CheckBox; +import android.widget.EditText; import android.widget.LinearLayout; import android.widget.TextView; @@ -188,6 +189,18 @@ public class ObjectivesFragment extends SubscriberFragment { notifyDataSetChanged(); scrollToCurrentObjective(); }); + if (objective.hasSpecialInput) { + holder.enterButton.setVisibility(View.VISIBLE); + holder.input.setVisibility(View.VISIBLE); + holder.enterButton.setOnClickListener((view) -> { + String input = holder.input.getText().toString(); + objective.specialAction(input); + notifyDataSetChanged(); + }); + } else { + holder.enterButton.setVisibility(View.GONE); + holder.input.setVisibility(View.GONE); + } } @@ -207,6 +220,8 @@ public class ObjectivesFragment extends SubscriberFragment { Button verify; public Button start; Button revert; + EditText input; + Button enterButton; ViewHolder(View itemView) { super(itemView); @@ -219,6 +234,8 @@ public class ObjectivesFragment extends SubscriberFragment { start = itemView.findViewById(R.id.objective_start); revert = itemView.findViewById(R.id.objective_back); accomplished = itemView.findViewById(R.id.objective_accomplished); + input = itemView.findViewById(R.id.objective_input); + enterButton = itemView.findViewById(R.id.objective_enterbutton); } } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPlugin.java index 42fd12b822..30267425c9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPlugin.java @@ -1,11 +1,15 @@ package info.nightscout.androidaps.plugins.constraints.objectives; +import com.google.common.base.Charsets; +import com.google.common.hash.Hashing; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.ArrayList; import java.util.List; +import info.nightscout.androidaps.BuildConfig; import info.nightscout.androidaps.Config; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; @@ -28,6 +32,7 @@ import info.nightscout.androidaps.plugins.constraints.objectives.objectives.Obje import info.nightscout.androidaps.plugins.constraints.objectives.objectives.Objective6; import info.nightscout.androidaps.plugins.constraints.objectives.objectives.Objective7; import info.nightscout.androidaps.plugins.constraints.objectives.objectives.Objective8; +import info.nightscout.androidaps.utils.DateUtil; import info.nightscout.androidaps.utils.SP; /** @@ -148,6 +153,28 @@ public class ObjectivesPlugin extends PluginBase implements ConstraintsInterface return objectives; } + public void completeObjectives(String request) { + String url = SP.getString(R.string.key_nsclientinternal_url, "").toLowerCase(); + if (!url.endsWith("\"")) url = url + "\""; + String hashNS = Hashing.sha1().hashString(url + BuildConfig.APPLICATION_ID, Charsets.UTF_8).toString(); + if (request.equalsIgnoreCase(hashNS.substring(0, 9))) { + SP.putLong("Objectives_" + "openloop" + "_started", DateUtil.now()); + SP.putLong("Objectives_" + "openloop" + "_accomplished", DateUtil.now()); + SP.putLong("Objectives_" + "maxbasal" + "_started", DateUtil.now()); + SP.putLong("Objectives_" + "maxbasal" + "_accomplished", DateUtil.now()); + SP.putLong("Objectives_" + "maxiobzero" + "_started", DateUtil.now()); + SP.putLong("Objectives_" + "maxiobzero" + "_accomplished", DateUtil.now()); + SP.putLong("Objectives_" + "maxiob" + "_started", DateUtil.now()); + SP.putLong("Objectives_" + "maxiob" + "_accomplished", DateUtil.now()); + SP.putLong("Objectives_" + "autosens" + "_started", DateUtil.now()); + SP.putLong("Objectives_" + "autosens" + "_accomplished", DateUtil.now()); + SP.putLong("Objectives_" + "ama" + "_started", DateUtil.now()); + SP.putLong("Objectives_" + "ama" + "_accomplished", DateUtil.now()); + SP.putLong("Objectives_" + "smb" + "_started", DateUtil.now()); + SP.putLong("Objectives_" + "smb" + "_accomplished", DateUtil.now()); + } + } + /** * Constraints interface **/ 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 70179a82bc..5a32e35c4f 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 @@ -12,7 +12,7 @@ import info.nightscout.androidaps.utils.T; public abstract class Objective { - String spName; + private String spName; @StringRes private int objective; @StringRes @@ -20,6 +20,7 @@ public abstract class Objective { private long startedOn; private long accomplishedOn; private List tasks = new ArrayList<>(); + public boolean hasSpecialInput = false; public Objective(String spName, @StringRes int objective, @StringRes int gate) { this.spName = spName; @@ -85,6 +86,8 @@ public abstract class Objective { return tasks; } + public void specialAction(String input) {} + public abstract class Task { @StringRes private int task; @@ -117,7 +120,7 @@ public abstract class Objective { private long minimumDuration; - public MinimumDurationTask(long minimumDuration) { + MinimumDurationTask(long minimumDuration) { super(R.string.time_elapsed); this.minimumDuration = minimumDuration; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective2.java b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective2.java index 646d8ea458..4096fd9d42 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective2.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective2.java @@ -13,6 +13,7 @@ public class Objective2 extends Objective { public Objective2() { super("openloop", R.string.objectives_openloop_objective, R.string.objectives_openloop_gate); + hasSpecialInput = true; } @Override @@ -33,4 +34,9 @@ public class Objective2 extends Objective { } }); } + + @Override + public void specialAction(String input) { + ObjectivesPlugin.getPlugin().completeObjectives(input); + } } diff --git a/app/src/main/res/layout/objectives_item.xml b/app/src/main/res/layout/objectives_item.xml index d11992b13f..e7a3901c59 100644 --- a/app/src/main/res/layout/objectives_item.xml +++ b/app/src/main/res/layout/objectives_item.xml @@ -49,7 +49,33 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="8dp" - android:orientation="vertical" /> + android:orientation="vertical" > + + + + + + + +