allow bypass objectives

This commit is contained in:
Milos Kozak 2019-09-02 08:42:25 +02:00
parent 12a2d789c1
commit 99893a3ab1
6 changed files with 85 additions and 3 deletions

View file

@ -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);
}
}
}

View file

@ -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
**/

View file

@ -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<Task> 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;
}

View file

@ -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);
}
}

View file

@ -49,7 +49,33 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:orientation="vertical" />
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<EditText
android:id="@+id/objective_input"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:hint="@string/enter_code_obtained_from_developers_to_bypass_the_rest_of_objectives"
android:inputType="text"
android:text="@string/orentercode" />
<Button
android:id="@+id/objective_enterbutton"
style="@style/Widget.AppCompat.Button.Borderless.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/objectives_button_enter" />
</LinearLayout>
<Button
android:id="@+id/objective_verify"

View file

@ -1622,6 +1622,9 @@
<string name="objectives_useactions">In Config Builder enable Actions plugin, make it visible and display its content from top menu</string>
<string name="objectives_useloop">Display content of Loop plugin</string>
<string name="objectives_usescale">Use scale function by long-pressing BG chart</string>
<string name="objectives_button_enter">Enter</string>
<string name="orentercode">or enter code</string>
<string name="enter_code_obtained_from_developers_to_bypass_the_rest_of_objectives">Enter code obtained from developers to bypass the rest of objectives</string>
<plurals name="objective_days">
<item quantity="one">%1$d day</item>