confirm dialog on entering code

This commit is contained in:
Milos Kozak 2019-09-02 23:10:31 +02:00
parent 99893a3ab1
commit b9e91f3d20
6 changed files with 55 additions and 33 deletions

View file

@ -189,17 +189,19 @@ public class ObjectivesFragment extends SubscriberFragment {
notifyDataSetChanged(); notifyDataSetChanged();
scrollToCurrentObjective(); scrollToCurrentObjective();
}); });
if (objective.hasSpecialInput) { if (objective.hasSpecialInput && !objective.isAccomplished()) {
holder.enterButton.setVisibility(View.VISIBLE); holder.enterButton.setVisibility(View.VISIBLE);
holder.input.setVisibility(View.VISIBLE); holder.input.setVisibility(View.VISIBLE);
holder.inputHint.setVisibility(View.VISIBLE);
holder.enterButton.setOnClickListener((view) -> { holder.enterButton.setOnClickListener((view) -> {
String input = holder.input.getText().toString(); String input = holder.input.getText().toString();
objective.specialAction(input); objective.specialAction(getActivity(), input);
notifyDataSetChanged(); notifyDataSetChanged();
}); });
} else { } else {
holder.enterButton.setVisibility(View.GONE); holder.enterButton.setVisibility(View.GONE);
holder.input.setVisibility(View.GONE); holder.input.setVisibility(View.GONE);
holder.inputHint.setVisibility(View.GONE);
} }
} }
@ -220,6 +222,7 @@ public class ObjectivesFragment extends SubscriberFragment {
Button verify; Button verify;
public Button start; public Button start;
Button revert; Button revert;
TextView inputHint;
EditText input; EditText input;
Button enterButton; Button enterButton;
@ -234,6 +237,7 @@ public class ObjectivesFragment extends SubscriberFragment {
start = itemView.findViewById(R.id.objective_start); start = itemView.findViewById(R.id.objective_start);
revert = itemView.findViewById(R.id.objective_back); revert = itemView.findViewById(R.id.objective_back);
accomplished = itemView.findViewById(R.id.objective_accomplished); accomplished = itemView.findViewById(R.id.objective_accomplished);
inputHint = itemView.findViewById(R.id.objective_inputhint);
input = itemView.findViewById(R.id.objective_input); input = itemView.findViewById(R.id.objective_input);
enterButton = itemView.findViewById(R.id.objective_enterbutton); enterButton = itemView.findViewById(R.id.objective_enterbutton);
} }

View file

@ -1,5 +1,7 @@
package info.nightscout.androidaps.plugins.constraints.objectives; package info.nightscout.androidaps.plugins.constraints.objectives;
import android.app.Activity;
import com.google.common.base.Charsets; import com.google.common.base.Charsets;
import com.google.common.hash.Hashing; import com.google.common.hash.Hashing;
@ -33,6 +35,7 @@ import info.nightscout.androidaps.plugins.constraints.objectives.objectives.Obje
import info.nightscout.androidaps.plugins.constraints.objectives.objectives.Objective7; import info.nightscout.androidaps.plugins.constraints.objectives.objectives.Objective7;
import info.nightscout.androidaps.plugins.constraints.objectives.objectives.Objective8; import info.nightscout.androidaps.plugins.constraints.objectives.objectives.Objective8;
import info.nightscout.androidaps.utils.DateUtil; import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.OKDialog;
import info.nightscout.androidaps.utils.SP; import info.nightscout.androidaps.utils.SP;
/** /**
@ -106,6 +109,7 @@ public class ObjectivesPlugin extends PluginBase implements ConstraintsInterface
} }
private void setupObjectives() { private void setupObjectives() {
objectives.clear();
objectives.add(new Objective0()); objectives.add(new Objective0());
objectives.add(new Objective1()); objectives.add(new Objective1());
objectives.add(new Objective2()); objectives.add(new Objective2());
@ -153,11 +157,11 @@ public class ObjectivesPlugin extends PluginBase implements ConstraintsInterface
return objectives; return objectives;
} }
public void completeObjectives(String request) { public void completeObjectives(Activity activity, String request) {
String url = SP.getString(R.string.key_nsclientinternal_url, "").toLowerCase(); String url = SP.getString(R.string.key_nsclientinternal_url, "").toLowerCase();
if (!url.endsWith("\"")) url = url + "\""; if (!url.endsWith("\"")) url = url + "/";
String hashNS = Hashing.sha1().hashString(url + BuildConfig.APPLICATION_ID, Charsets.UTF_8).toString(); String hashNS = Hashing.sha1().hashString(url + BuildConfig.APPLICATION_ID, Charsets.UTF_8).toString();
if (request.equalsIgnoreCase(hashNS.substring(0, 9))) { if (request.equalsIgnoreCase(hashNS.substring(0, 10))) {
SP.putLong("Objectives_" + "openloop" + "_started", DateUtil.now()); SP.putLong("Objectives_" + "openloop" + "_started", DateUtil.now());
SP.putLong("Objectives_" + "openloop" + "_accomplished", DateUtil.now()); SP.putLong("Objectives_" + "openloop" + "_accomplished", DateUtil.now());
SP.putLong("Objectives_" + "maxbasal" + "_started", DateUtil.now()); SP.putLong("Objectives_" + "maxbasal" + "_started", DateUtil.now());
@ -172,6 +176,10 @@ public class ObjectivesPlugin extends PluginBase implements ConstraintsInterface
SP.putLong("Objectives_" + "ama" + "_accomplished", DateUtil.now()); SP.putLong("Objectives_" + "ama" + "_accomplished", DateUtil.now());
SP.putLong("Objectives_" + "smb" + "_started", DateUtil.now()); SP.putLong("Objectives_" + "smb" + "_started", DateUtil.now());
SP.putLong("Objectives_" + "smb" + "_accomplished", DateUtil.now()); SP.putLong("Objectives_" + "smb" + "_accomplished", DateUtil.now());
setupObjectives();
OKDialog.show(activity, "", MainApp.gs(R.string.codeaccepted), null);
} else {
OKDialog.show(activity, "", MainApp.gs(R.string.codeinvalid), null);
} }
} }

View file

@ -1,5 +1,7 @@
package info.nightscout.androidaps.plugins.constraints.objectives.objectives; package info.nightscout.androidaps.plugins.constraints.objectives.objectives;
import android.app.Activity;
import androidx.annotation.StringRes; import androidx.annotation.StringRes;
import java.util.ArrayList; import java.util.ArrayList;
@ -86,7 +88,7 @@ public abstract class Objective {
return tasks; return tasks;
} }
public void specialAction(String input) {} public void specialAction(Activity activity, String input) {}
public abstract class Task { public abstract class Task {
@StringRes @StringRes

View file

@ -1,5 +1,7 @@
package info.nightscout.androidaps.plugins.constraints.objectives.objectives; package info.nightscout.androidaps.plugins.constraints.objectives.objectives;
import android.app.Activity;
import java.util.List; import java.util.List;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
@ -36,7 +38,7 @@ public class Objective2 extends Objective {
} }
@Override @Override
public void specialAction(String input) { public void specialAction(Activity activity, String input) {
ObjectivesPlugin.getPlugin().completeObjectives(input); ObjectivesPlugin.getPlugin().completeObjectives(activity, input);
} }
} }

View file

@ -53,30 +53,6 @@
</LinearLayout> </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 <Button
android:id="@+id/objective_verify" android:id="@+id/objective_verify"
style="@style/Widget.AppCompat.Button.Borderless.Colored" style="@style/Widget.AppCompat.Button.Borderless.Colored"
@ -98,6 +74,35 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/objectives_button_back" /> android:text="@string/objectives_button_back" />
<TextView
android:id="@+id/objective_inputhint"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/enter_code_obtained_from_developers_to_bypass_the_rest_of_objectives" />
<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="XXXXXXXXXX"
android:inputType="text" />
<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>
<TextView <TextView
android:id="@+id/objective_accomplished" android:id="@+id/objective_accomplished"
android:layout_width="wrap_content" android:layout_width="wrap_content"

View file

@ -1623,8 +1623,9 @@
<string name="objectives_useloop">Display content of Loop plugin</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_usescale">Use scale function by long-pressing BG chart</string>
<string name="objectives_button_enter">Enter</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> <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>
<string name="codeaccepted">Code accepted</string>
<string name="codeinvalid">Code invalid</string>
<plurals name="objective_days"> <plurals name="objective_days">
<item quantity="one">%1$d day</item> <item quantity="one">%1$d day</item>