allow objective skip only when NS is connected and in RW mode

This commit is contained in:
Milos Kozak 2019-11-29 12:19:32 +01:00
parent b8ba94fa30
commit f82c610d16
4 changed files with 12 additions and 2 deletions

View file

@ -210,6 +210,7 @@ class ObjectivesFragment : Fragment() {
scrollToCurrentObjective() scrollToCurrentObjective()
startUpdateTimer() startUpdateTimer()
RxBus.send(EventObjectivesUpdateGui()) RxBus.send(EventObjectivesUpdateGui())
holder.verify.visibility = View.INVISIBLE
} else } else
SntpClient.ntpTime(object : SntpClient.Callback() { SntpClient.ntpTime(object : SntpClient.Callback() {
override fun run() { override fun run() {
@ -242,6 +243,7 @@ class ObjectivesFragment : Fragment() {
scrollToCurrentObjective() scrollToCurrentObjective()
startUpdateTimer() startUpdateTimer()
RxBus.send(EventObjectivesUpdateGui()) RxBus.send(EventObjectivesUpdateGui())
holder.start.visibility = View.VISIBLE
} else } else
SntpClient.ntpTime(object : SntpClient.Callback() { SntpClient.ntpTime(object : SntpClient.Callback() {
override fun run() { override fun run() {
@ -272,7 +274,7 @@ class ObjectivesFragment : Fragment() {
scrollToCurrentObjective() scrollToCurrentObjective()
RxBus.send(EventObjectivesUpdateGui()) RxBus.send(EventObjectivesUpdateGui())
} }
if (objective.hasSpecialInput && !objective.isAccomplished && objective.isStarted) { if (objective.hasSpecialInput && !objective.isAccomplished && objective.isStarted && objective.specialActionEnabled()) {
// generate random request code if none exists // generate random request code if none exists
val request = SP.getString(R.string.key_objectives_request_code, String.format("%1$05d", (Math.random() * 99999).toInt())) val request = SP.getString(R.string.key_objectives_request_code, String.format("%1$05d", (Math.random() * 99999).toInt()))
SP.putString(R.string.key_objectives_request_code, request) SP.putString(R.string.key_objectives_request_code, request)

View file

@ -104,7 +104,7 @@ object ObjectivesPlugin : PluginBase(PluginDescription()
fun completeObjectives(activity: Activity, request: String) { fun completeObjectives(activity: Activity, request: String) {
val requestCode = SP.getString(R.string.key_objectives_request_code, "") val requestCode = SP.getString(R.string.key_objectives_request_code, "")
var url = SP.getString(R.string.key_nsclientinternal_url, "").toLowerCase() var url = SP.getString(R.string.key_nsclientinternal_url, "").toLowerCase()
if (!url.endsWith("\"")) url = "$url/" if (!url.endsWith("/")) url = "$url/"
@Suppress("DEPRECATION") val hashNS = Hashing.sha1().hashString(url + BuildConfig.APPLICATION_ID + "/" + requestCode, Charsets.UTF_8).toString() @Suppress("DEPRECATION") val hashNS = Hashing.sha1().hashString(url + BuildConfig.APPLICATION_ID + "/" + requestCode, Charsets.UTF_8).toString()
if (request.equals(hashNS.substring(0, 10), ignoreCase = true)) { if (request.equals(hashNS.substring(0, 10), ignoreCase = true)) {
SP.putLong("Objectives_" + "openloop" + "_started", DateUtil.now()) SP.putLong("Objectives_" + "openloop" + "_started", DateUtil.now())

View file

@ -107,6 +107,8 @@ public abstract class Objective {
return tasks; return tasks;
} }
public boolean specialActionEnabled() { return true; }
public void specialAction(Activity activity, String input) {} public void specialAction(Activity activity, String input) {}
public abstract class Task { public abstract class Task {

View file

@ -7,6 +7,7 @@ import java.util.List;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.constraints.objectives.ObjectivesPlugin; import info.nightscout.androidaps.plugins.constraints.objectives.ObjectivesPlugin;
import info.nightscout.androidaps.plugins.general.nsclient.NSClientPlugin;
import info.nightscout.androidaps.utils.SP; import info.nightscout.androidaps.utils.SP;
import info.nightscout.androidaps.utils.T; import info.nightscout.androidaps.utils.T;
@ -38,6 +39,11 @@ public class Objective3 extends Objective {
}); });
} }
@Override
public boolean specialActionEnabled() {
return NSClientPlugin.getPlugin().nsClientService.isConnected && NSClientPlugin.getPlugin().nsClientService.hasWriteAuth;
}
@Override @Override
public void specialAction(Activity activity, String input) { public void specialAction(Activity activity, String input) {
ObjectivesPlugin.INSTANCE.completeObjectives(activity, input); ObjectivesPlugin.INSTANCE.completeObjectives(activity, input);