ObjectivesPlugin -> kotlin
This commit is contained in:
parent
05bb5a660b
commit
a75312eea0
|
@ -202,7 +202,7 @@ public class MainApp extends Application {
|
|||
if (Config.SAFETY) pluginsList.add(VersionCheckerPlugin.INSTANCE);
|
||||
if (Config.SAFETY) pluginsList.add(StorageConstraintPlugin.getPlugin());
|
||||
if (Config.SAFETY) pluginsList.add(SignatureVerifier.getPlugin());
|
||||
if (Config.APS) pluginsList.add(ObjectivesPlugin.getPlugin());
|
||||
if (Config.APS) pluginsList.add(ObjectivesPlugin.INSTANCE);
|
||||
pluginsList.add(SourceXdripPlugin.getPlugin());
|
||||
pluginsList.add(SourceNSClientPlugin.getPlugin());
|
||||
pluginsList.add(SourceMM640gPlugin.getPlugin());
|
||||
|
|
|
@ -55,7 +55,7 @@ public class ObjectivesFragment extends SubscriberFragment {
|
|||
reset = view.findViewById(R.id.objectives_reset);
|
||||
enableFake.setOnClickListener(v -> updateGUI());
|
||||
reset.setOnClickListener(v -> {
|
||||
ObjectivesPlugin.getPlugin().reset();
|
||||
ObjectivesPlugin.INSTANCE.reset();
|
||||
recyclerView.getAdapter().notifyDataSetChanged();
|
||||
scrollToCurrentObjective();
|
||||
});
|
||||
|
@ -77,7 +77,7 @@ public class ObjectivesFragment extends SubscriberFragment {
|
|||
|
||||
private void startUpdateTimer() {
|
||||
handler.removeCallbacks(objectiveUpdater);
|
||||
for (Objective objective : ObjectivesPlugin.getPlugin().getObjectives()) {
|
||||
for (Objective objective : ObjectivesPlugin.INSTANCE.getObjectives()) {
|
||||
if (objective.isStarted() && !objective.isAccomplished()) {
|
||||
long timeTillNextMinute = (System.currentTimeMillis() - objective.getStartedOn()) % (60 * 1000);
|
||||
handler.postDelayed(objectiveUpdater, timeTillNextMinute);
|
||||
|
@ -87,8 +87,8 @@ public class ObjectivesFragment extends SubscriberFragment {
|
|||
}
|
||||
|
||||
private void scrollToCurrentObjective() {
|
||||
for (int i = 0; i < ObjectivesPlugin.getPlugin().getObjectives().size(); i++) {
|
||||
Objective objective = ObjectivesPlugin.getPlugin().getObjectives().get(i);
|
||||
for (int i = 0; i < ObjectivesPlugin.INSTANCE.getObjectives().size(); i++) {
|
||||
Objective objective = ObjectivesPlugin.INSTANCE.getObjectives().get(i);
|
||||
if (!objective.isStarted() || !objective.isAccomplished()) {
|
||||
RecyclerView.SmoothScroller smoothScroller = new LinearSmoothScroller(getContext()) {
|
||||
@Override
|
||||
|
@ -118,7 +118,7 @@ public class ObjectivesFragment extends SubscriberFragment {
|
|||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
|
||||
Objective objective = ObjectivesPlugin.getPlugin().getObjectives().get(position);
|
||||
Objective objective = ObjectivesPlugin.INSTANCE.getObjectives().get(position);
|
||||
holder.title.setText(MainApp.gs(R.string.nth_objective, position + 1));
|
||||
holder.revert.setVisibility(View.INVISIBLE);
|
||||
if (objective.getObjective() != 0) {
|
||||
|
@ -134,7 +134,7 @@ public class ObjectivesFragment extends SubscriberFragment {
|
|||
holder.verify.setVisibility(View.GONE);
|
||||
holder.progress.setVisibility(View.GONE);
|
||||
holder.accomplished.setVisibility(View.GONE);
|
||||
if (position == 0 || ObjectivesPlugin.getPlugin().getObjectives().get(position - 1).isAccomplished())
|
||||
if (position == 0 || ObjectivesPlugin.INSTANCE.getObjectives().get(position - 1).isAccomplished())
|
||||
holder.start.setVisibility(View.VISIBLE);
|
||||
else holder.start.setVisibility(View.GONE);
|
||||
} else if (objective.isAccomplished()) {
|
||||
|
@ -182,7 +182,7 @@ public class ObjectivesFragment extends SubscriberFragment {
|
|||
objective.setAccomplishedOn(0);
|
||||
objective.setStartedOn(0);
|
||||
if (position > 0) {
|
||||
Objective prevObj = ObjectivesPlugin.getPlugin().getObjectives().get(position - 1);
|
||||
Objective prevObj = ObjectivesPlugin.INSTANCE.getObjectives().get(position - 1);
|
||||
prevObj.setAccomplishedOn(0);
|
||||
}
|
||||
notifyDataSetChanged();
|
||||
|
@ -207,7 +207,7 @@ public class ObjectivesFragment extends SubscriberFragment {
|
|||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return ObjectivesPlugin.getPlugin().getObjectives().size();
|
||||
return ObjectivesPlugin.INSTANCE.getObjectives().size();
|
||||
}
|
||||
|
||||
public class ViewHolder extends RecyclerView.ViewHolder {
|
||||
|
|
|
@ -1,198 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.constraints.objectives;
|
||||
|
||||
import android.app.Activity;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.hash.Hashing;
|
||||
|
||||
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;
|
||||
import info.nightscout.androidaps.interfaces.Constraint;
|
||||
import info.nightscout.androidaps.interfaces.ConstraintsInterface;
|
||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||
import info.nightscout.androidaps.interfaces.PluginDescription;
|
||||
import info.nightscout.androidaps.interfaces.PluginType;
|
||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.plugins.constraints.objectives.objectives.Objective;
|
||||
import info.nightscout.androidaps.plugins.constraints.objectives.objectives.Objective0;
|
||||
import info.nightscout.androidaps.plugins.constraints.objectives.objectives.Objective1;
|
||||
import info.nightscout.androidaps.plugins.constraints.objectives.objectives.Objective2;
|
||||
import info.nightscout.androidaps.plugins.constraints.objectives.objectives.Objective3;
|
||||
import info.nightscout.androidaps.plugins.constraints.objectives.objectives.Objective4;
|
||||
import info.nightscout.androidaps.plugins.constraints.objectives.objectives.Objective5;
|
||||
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.OKDialog;
|
||||
import info.nightscout.androidaps.utils.SP;
|
||||
|
||||
/**
|
||||
* Created by mike on 05.08.2016.
|
||||
*/
|
||||
public class ObjectivesPlugin extends PluginBase implements ConstraintsInterface {
|
||||
private static ObjectivesPlugin objectivesPlugin;
|
||||
|
||||
public static ObjectivesPlugin getPlugin() {
|
||||
if (objectivesPlugin == null) {
|
||||
objectivesPlugin = new ObjectivesPlugin();
|
||||
}
|
||||
return objectivesPlugin;
|
||||
}
|
||||
|
||||
public List<Objective> objectives = new ArrayList<>();
|
||||
|
||||
public static final int FIRST_OBJECTIVE = 0;
|
||||
public static final int USAGE_OBJECTIVE = 1;
|
||||
public static final int OPENLOOP_OBJECTIVE = 2;
|
||||
public static final int MAXBASAL_OBJECTIVE = 3;
|
||||
public static final int MAXIOB_ZERO_CL_OBJECTIVE = 4;
|
||||
public static final int MAXIOB_OBJECTIVE = 5;
|
||||
public static final int AUTOSENS_OBJECTIVE = 6;
|
||||
public static final int AMA_OBJECTIVE = 7;
|
||||
public static final int SMB_OBJECTIVE = 8;
|
||||
|
||||
private ObjectivesPlugin() {
|
||||
super(new PluginDescription()
|
||||
.mainType(PluginType.CONSTRAINTS)
|
||||
.fragmentClass(ObjectivesFragment.class.getName())
|
||||
.alwaysEnabled(!Config.NSCLIENT)
|
||||
.showInList(!Config.NSCLIENT)
|
||||
.pluginName(R.string.objectives)
|
||||
.shortName(R.string.objectives_shortname)
|
||||
.description(R.string.description_objectives)
|
||||
);
|
||||
convertSP();
|
||||
setupObjectives();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean specialEnableCondition() {
|
||||
PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump();
|
||||
return pump == null || pump.getPumpDescription().isTempBasalCapable;
|
||||
}
|
||||
|
||||
// convert 2.3 SP version
|
||||
private void convertSP() {
|
||||
doConvertSP(0, "config");
|
||||
doConvertSP(1, "openloop");
|
||||
doConvertSP(2, "maxbasal");
|
||||
doConvertSP(3, "maxiobzero");
|
||||
doConvertSP(4, "maxiob");
|
||||
doConvertSP(5, "autosens");
|
||||
doConvertSP(6, "ama");
|
||||
doConvertSP(7, "smb");
|
||||
}
|
||||
|
||||
private void doConvertSP(int number, String name) {
|
||||
if (!SP.contains("Objectives_" + name + "_started")) {
|
||||
SP.putLong("Objectives_" + name + "_started", SP.getLong("Objectives" + number + "accomplished", 0L));
|
||||
SP.putLong("Objectives_" + name + "_accomplished", SP.getLong("Objectives" + number + "accomplished", 0L));
|
||||
}
|
||||
}
|
||||
|
||||
private void setupObjectives() {
|
||||
objectives.clear();
|
||||
objectives.add(new Objective0());
|
||||
objectives.add(new Objective1());
|
||||
objectives.add(new Objective2());
|
||||
objectives.add(new Objective3());
|
||||
objectives.add(new Objective4());
|
||||
objectives.add(new Objective5());
|
||||
objectives.add(new Objective6());
|
||||
objectives.add(new Objective7());
|
||||
objectives.add(new Objective8());
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
for (Objective objective : objectives) {
|
||||
objective.setStartedOn(0);
|
||||
objective.setAccomplishedOn(0);
|
||||
}
|
||||
SP.putBoolean(R.string.key_ObjectivesbgIsAvailableInNS, false);
|
||||
SP.putBoolean(R.string.key_ObjectivespumpStatusIsAvailableInNS, false);
|
||||
SP.putInt(R.string.key_ObjectivesmanualEnacts, 0);
|
||||
}
|
||||
|
||||
public List<Objective> getObjectives() {
|
||||
return objectives;
|
||||
}
|
||||
|
||||
public void completeObjectives(Activity activity, 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, 10))) {
|
||||
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());
|
||||
setupObjectives();
|
||||
OKDialog.show(activity, "", MainApp.gs(R.string.codeaccepted), null);
|
||||
} else {
|
||||
OKDialog.show(activity, "", MainApp.gs(R.string.codeinvalid), null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constraints interface
|
||||
**/
|
||||
@Override
|
||||
public Constraint<Boolean> isLoopInvocationAllowed(Constraint<Boolean> value) {
|
||||
if (!objectives.get(FIRST_OBJECTIVE).isStarted())
|
||||
value.set(false, String.format(MainApp.gs(R.string.objectivenotstarted), FIRST_OBJECTIVE + 1), this);
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Constraint<Boolean> isClosedLoopAllowed(Constraint<Boolean> value) {
|
||||
if (!objectives.get(MAXIOB_ZERO_CL_OBJECTIVE).isStarted())
|
||||
value.set(false, String.format(MainApp.gs(R.string.objectivenotstarted), MAXIOB_ZERO_CL_OBJECTIVE + 1), this);
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Constraint<Boolean> isAutosensModeEnabled(Constraint<Boolean> value) {
|
||||
if (!objectives.get(AUTOSENS_OBJECTIVE).isStarted())
|
||||
value.set(false, String.format(MainApp.gs(R.string.objectivenotstarted), AUTOSENS_OBJECTIVE + 1), this);
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Constraint<Boolean> isAMAModeEnabled(Constraint<Boolean> value) {
|
||||
if (!objectives.get(AMA_OBJECTIVE).isStarted())
|
||||
value.set(false, String.format(MainApp.gs(R.string.objectivenotstarted), AMA_OBJECTIVE + 1), this);
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Constraint<Boolean> isSMBModeEnabled(Constraint<Boolean> value) {
|
||||
if (!objectives.get(SMB_OBJECTIVE).isStarted())
|
||||
value.set(false, String.format(MainApp.gs(R.string.objectivenotstarted), SMB_OBJECTIVE + 1), this);
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Constraint<Double> applyMaxIOBConstraints(Constraint<Double> maxIob) {
|
||||
if (objectives.get(MAXIOB_ZERO_CL_OBJECTIVE).isStarted() && !objectives.get(MAXIOB_ZERO_CL_OBJECTIVE).isAccomplished())
|
||||
maxIob.set(0d, String.format(MainApp.gs(R.string.objectivenotfinished), MAXIOB_ZERO_CL_OBJECTIVE + 1), this);
|
||||
return maxIob;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,167 @@
|
|||
package info.nightscout.androidaps.plugins.constraints.objectives
|
||||
|
||||
import android.app.Activity
|
||||
import com.google.common.base.Charsets
|
||||
import com.google.common.hash.Hashing
|
||||
import info.nightscout.androidaps.BuildConfig
|
||||
import info.nightscout.androidaps.Config
|
||||
import info.nightscout.androidaps.MainApp
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.interfaces.*
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
|
||||
import info.nightscout.androidaps.plugins.constraints.objectives.objectives.*
|
||||
import info.nightscout.androidaps.utils.DateUtil
|
||||
import info.nightscout.androidaps.utils.OKDialog
|
||||
import info.nightscout.androidaps.utils.SP
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Created by mike on 05.08.2016.
|
||||
*/
|
||||
object ObjectivesPlugin : PluginBase(PluginDescription()
|
||||
.mainType(PluginType.CONSTRAINTS)
|
||||
.fragmentClass(ObjectivesFragment::class.java.name)
|
||||
.alwaysEnabled(!Config.NSCLIENT)
|
||||
.showInList(!Config.NSCLIENT)
|
||||
.pluginName(R.string.objectives)
|
||||
.shortName(R.string.objectives_shortname)
|
||||
.description(R.string.description_objectives)), ConstraintsInterface {
|
||||
|
||||
var objectives: MutableList<Objective> = ArrayList()
|
||||
|
||||
val FIRST_OBJECTIVE = 0
|
||||
val USAGE_OBJECTIVE = 1
|
||||
val OPENLOOP_OBJECTIVE = 2
|
||||
val MAXBASAL_OBJECTIVE = 3
|
||||
val MAXIOB_ZERO_CL_OBJECTIVE = 4
|
||||
val MAXIOB_OBJECTIVE = 5
|
||||
val AUTOSENS_OBJECTIVE = 6
|
||||
val AMA_OBJECTIVE = 7
|
||||
val SMB_OBJECTIVE = 8
|
||||
|
||||
init {
|
||||
convertSP()
|
||||
setupObjectives()
|
||||
}
|
||||
|
||||
override fun specialEnableCondition(): Boolean {
|
||||
val pump = ConfigBuilderPlugin.getPlugin().activePump
|
||||
return pump == null || pump.pumpDescription.isTempBasalCapable
|
||||
}
|
||||
|
||||
// convert 2.3 SP version
|
||||
private fun convertSP() {
|
||||
doConvertSP(0, "config")
|
||||
doConvertSP(1, "openloop")
|
||||
doConvertSP(2, "maxbasal")
|
||||
doConvertSP(3, "maxiobzero")
|
||||
doConvertSP(4, "maxiob")
|
||||
doConvertSP(5, "autosens")
|
||||
doConvertSP(6, "ama")
|
||||
doConvertSP(7, "smb")
|
||||
}
|
||||
|
||||
private fun doConvertSP(number: Int, name: String) {
|
||||
if (!SP.contains("Objectives_" + name + "_started")) {
|
||||
SP.putLong("Objectives_" + name + "_started", SP.getLong("Objectives" + number + "accomplished", 0L))
|
||||
SP.putLong("Objectives_" + name + "_accomplished", SP.getLong("Objectives" + number + "accomplished", 0L))
|
||||
}
|
||||
// TODO: we can remove Objectives1accomplished sometimes later
|
||||
}
|
||||
|
||||
private fun setupObjectives() {
|
||||
objectives.clear()
|
||||
objectives.add(Objective0())
|
||||
objectives.add(Objective1())
|
||||
objectives.add(Objective2())
|
||||
objectives.add(Objective3())
|
||||
objectives.add(Objective4())
|
||||
objectives.add(Objective5())
|
||||
objectives.add(Objective6())
|
||||
objectives.add(Objective7())
|
||||
objectives.add(Objective8())
|
||||
}
|
||||
|
||||
fun reset() {
|
||||
for (objective in objectives) {
|
||||
objective.startedOn = 0
|
||||
objective.accomplishedOn = 0
|
||||
}
|
||||
SP.putBoolean(R.string.key_ObjectivesbgIsAvailableInNS, false)
|
||||
SP.putBoolean(R.string.key_ObjectivespumpStatusIsAvailableInNS, false)
|
||||
SP.putInt(R.string.key_ObjectivesmanualEnacts, 0)
|
||||
SP.putBoolean(R.string.key_objectiveuseprofileswitch, false);
|
||||
SP.putBoolean(R.string.key_objectiveusedisconnect, false);
|
||||
SP.putBoolean(R.string.key_objectiveusereconnect, false);
|
||||
SP.putBoolean(R.string.key_objectiveusetemptarget, false);
|
||||
SP.putBoolean(R.string.key_objectiveuseactions, false);
|
||||
SP.putBoolean(R.string.key_objectiveuseloop, false);
|
||||
SP.putBoolean(R.string.key_objectiveusescale, false);
|
||||
}
|
||||
|
||||
fun completeObjectives(activity: Activity, request: String) {
|
||||
var url = SP.getString(R.string.key_nsclientinternal_url, "").toLowerCase()
|
||||
if (!url.endsWith("\"")) url = "$url/"
|
||||
val hashNS = Hashing.sha1().hashString(url + BuildConfig.APPLICATION_ID, Charsets.UTF_8).toString()
|
||||
if (request.equals(hashNS.substring(0, 10), ignoreCase = true)) {
|
||||
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())
|
||||
setupObjectives()
|
||||
OKDialog.show(activity, "", MainApp.gs(R.string.codeaccepted), null)
|
||||
} else {
|
||||
OKDialog.show(activity, "", MainApp.gs(R.string.codeinvalid), null)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constraints interface
|
||||
*/
|
||||
override fun isLoopInvocationAllowed(value: Constraint<Boolean>): Constraint<Boolean> {
|
||||
if (!objectives[FIRST_OBJECTIVE].isStarted)
|
||||
value.set(false, String.format(MainApp.gs(R.string.objectivenotstarted), FIRST_OBJECTIVE + 1), this)
|
||||
return value
|
||||
}
|
||||
|
||||
override fun isClosedLoopAllowed(value: Constraint<Boolean>): Constraint<Boolean> {
|
||||
if (!objectives[MAXIOB_ZERO_CL_OBJECTIVE].isStarted)
|
||||
value.set(false, String.format(MainApp.gs(R.string.objectivenotstarted), MAXIOB_ZERO_CL_OBJECTIVE + 1), this)
|
||||
return value
|
||||
}
|
||||
|
||||
override fun isAutosensModeEnabled(value: Constraint<Boolean>): Constraint<Boolean> {
|
||||
if (!objectives[AUTOSENS_OBJECTIVE].isStarted)
|
||||
value.set(false, String.format(MainApp.gs(R.string.objectivenotstarted), AUTOSENS_OBJECTIVE + 1), this)
|
||||
return value
|
||||
}
|
||||
|
||||
override fun isAMAModeEnabled(value: Constraint<Boolean>): Constraint<Boolean> {
|
||||
if (!objectives[AMA_OBJECTIVE].isStarted)
|
||||
value.set(false, String.format(MainApp.gs(R.string.objectivenotstarted), AMA_OBJECTIVE + 1), this)
|
||||
return value
|
||||
}
|
||||
|
||||
override fun isSMBModeEnabled(value: Constraint<Boolean>): Constraint<Boolean> {
|
||||
if (!objectives[SMB_OBJECTIVE].isStarted)
|
||||
value.set(false, String.format(MainApp.gs(R.string.objectivenotstarted), SMB_OBJECTIVE + 1), this)
|
||||
return value
|
||||
}
|
||||
|
||||
override fun applyMaxIOBConstraints(maxIob: Constraint<Double>): Constraint<Double> {
|
||||
if (objectives[MAXIOB_ZERO_CL_OBJECTIVE].isStarted && !objectives[MAXIOB_ZERO_CL_OBJECTIVE].isAccomplished)
|
||||
maxIob.set(0.0, String.format(MainApp.gs(R.string.objectivenotfinished), MAXIOB_ZERO_CL_OBJECTIVE + 1), this)
|
||||
return maxIob
|
||||
}
|
||||
|
||||
}
|
|
@ -40,6 +40,6 @@ public class Objective2 extends Objective {
|
|||
|
||||
@Override
|
||||
public void specialAction(Activity activity, String input) {
|
||||
ObjectivesPlugin.getPlugin().completeObjectives(activity, input);
|
||||
ObjectivesPlugin.INSTANCE.completeObjectives(activity, input);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -425,8 +425,8 @@ public class SWDefinition {
|
|||
.add(new SWBreak())
|
||||
.add(new SWFragment(this)
|
||||
.add(new ObjectivesFragment()))
|
||||
.validator(() -> ObjectivesPlugin.getPlugin().objectives.get(ObjectivesPlugin.FIRST_OBJECTIVE).isStarted())
|
||||
.visibility(() -> !ObjectivesPlugin.getPlugin().objectives.get(ObjectivesPlugin.FIRST_OBJECTIVE).isStarted() && Config.APS);
|
||||
.validator(() -> ObjectivesPlugin.INSTANCE.getObjectives().get(ObjectivesPlugin.INSTANCE.getFIRST_OBJECTIVE()).isStarted())
|
||||
.visibility(() -> !ObjectivesPlugin.INSTANCE.getObjectives().get(ObjectivesPlugin.INSTANCE.getFIRST_OBJECTIVE()).isStarted() && Config.APS);
|
||||
|
||||
private void SWDefinitionFull() {
|
||||
// List all the screens here
|
||||
|
|
|
@ -75,7 +75,7 @@ public class ConstraintsCheckerTest {
|
|||
@Test
|
||||
public void isClosedLoopAllowedTest() throws Exception {
|
||||
when(SP.getString(R.string.key_aps_mode, "open")).thenReturn("closed");
|
||||
objectivesPlugin.objectives.get(ObjectivesPlugin.CLOSED_LOOP_OBJECTIVE).setStartedOn(null);
|
||||
objectivesPlugin.getObjectives().get(ObjectivesPlugin.CLOSED_LOOP_OBJECTIVE).setStartedOn(null);
|
||||
|
||||
Constraint<Boolean> c = constraintChecker.isClosedLoopAllowed();
|
||||
Assert.assertEquals(true, c.getReasonList().size() == 2); // Safety & Objectives
|
||||
|
@ -91,7 +91,7 @@ public class ConstraintsCheckerTest {
|
|||
|
||||
@Test
|
||||
public void isAutosensModeEnabledTest() throws Exception {
|
||||
objectivesPlugin.objectives.get(ObjectivesPlugin.AUTOSENS_OBJECTIVE).setStartedOn(null);
|
||||
objectivesPlugin.getObjectives().get(ObjectivesPlugin.Companion.getAUTOSENS_OBJECTIVE()).setStartedOn(null);
|
||||
when(SP.getBoolean(R.string.key_openapsama_useautosens, false)).thenReturn(false);
|
||||
|
||||
Constraint<Boolean> c = constraintChecker.isAutosensModeEnabled();
|
||||
|
@ -102,7 +102,7 @@ public class ConstraintsCheckerTest {
|
|||
|
||||
@Test
|
||||
public void isAMAModeEnabledTest() throws Exception {
|
||||
objectivesPlugin.objectives.get(ObjectivesPlugin.AMA_OBJECTIVE).setStartedOn(null);
|
||||
objectivesPlugin.getObjectives().get(ObjectivesPlugin.Companion.getAMA_OBJECTIVE()).setStartedOn(null);
|
||||
|
||||
Constraint<Boolean> c = constraintChecker.isAMAModeEnabled();
|
||||
Assert.assertEquals(true, c.getReasonList().size() == 1); // Objectives
|
||||
|
@ -130,7 +130,7 @@ public class ConstraintsCheckerTest {
|
|||
|
||||
@Test
|
||||
public void isSMBModeEnabledTest() throws Exception {
|
||||
objectivesPlugin.objectives.get(ObjectivesPlugin.SMB_OBJECTIVE).setStartedOn(null);
|
||||
objectivesPlugin.getObjectives().get(ObjectivesPlugin.Companion.getSMB_OBJECTIVE()).setStartedOn(null);
|
||||
when(SP.getBoolean(R.string.key_use_smb, false)).thenReturn(false);
|
||||
when(MainApp.getConstraintChecker().isClosedLoopAllowed()).thenReturn(new Constraint<>(true));
|
||||
|
||||
|
@ -294,7 +294,7 @@ public class ConstraintsCheckerTest {
|
|||
constraintChecker = new ConstraintChecker();
|
||||
|
||||
safetyPlugin = SafetyPlugin.getPlugin();
|
||||
objectivesPlugin = ObjectivesPlugin.getPlugin();
|
||||
objectivesPlugin = ObjectivesPlugin.Companion.getPlugin();
|
||||
comboPlugin = ComboPlugin.getPlugin();
|
||||
danaRPlugin = DanaRPlugin.getPlugin();
|
||||
danaRSPlugin = DanaRSPlugin.getPlugin();
|
||||
|
|
|
@ -28,18 +28,18 @@ public class ObjectivesPluginTest {
|
|||
|
||||
@Test
|
||||
public void notStartedObjectivesShouldLimitLoopInvocation() throws Exception {
|
||||
objectivesPlugin.objectives.get(ObjectivesPlugin.FIRST_OBJECTIVE).setStartedOn(null);
|
||||
objectivesPlugin.getObjectives().get(ObjectivesPlugin.Companion.getFIRST_OBJECTIVE()).setStartedOn(null);
|
||||
|
||||
Constraint<Boolean> c = new Constraint<>(true);
|
||||
c = objectivesPlugin.isLoopInvocationAllowed(c);
|
||||
Assert.assertEquals("Objectives: Objective 1 not started", c.getReasons());
|
||||
Assert.assertEquals(Boolean.FALSE, c.value());
|
||||
objectivesPlugin.objectives.get(ObjectivesPlugin.FIRST_OBJECTIVE).setStartedOn(new Date());
|
||||
objectivesPlugin.getObjectives().get(ObjectivesPlugin.Companion.getFIRST_OBJECTIVE()).setStartedOn(new Date());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void notStartedObjective4ShouldLimitClosedLoop() throws Exception {
|
||||
objectivesPlugin.objectives.get(ObjectivesPlugin.CLOSED_LOOP_OBJECTIVE).setStartedOn(null);
|
||||
objectivesPlugin.getObjectives().get(ObjectivesPlugin.CLOSED_LOOP_OBJECTIVE).setStartedOn(null);
|
||||
|
||||
Constraint<Boolean> c = new Constraint<>(true);
|
||||
c = objectivesPlugin.isClosedLoopAllowed(c);
|
||||
|
@ -49,7 +49,7 @@ public class ObjectivesPluginTest {
|
|||
|
||||
@Test
|
||||
public void notStartedObjective6ShouldLimitAutosensMode() throws Exception {
|
||||
objectivesPlugin.objectives.get(ObjectivesPlugin.AUTOSENS_OBJECTIVE).setStartedOn(null);
|
||||
objectivesPlugin.getObjectives().get(ObjectivesPlugin.Companion.getAUTOSENS_OBJECTIVE()).setStartedOn(null);
|
||||
|
||||
Constraint<Boolean> c = new Constraint<>(true);
|
||||
c = objectivesPlugin.isAutosensModeEnabled(c);
|
||||
|
@ -59,7 +59,7 @@ public class ObjectivesPluginTest {
|
|||
|
||||
@Test
|
||||
public void notStartedObjective7ShouldLimitAMAMode() throws Exception {
|
||||
objectivesPlugin.objectives.get(ObjectivesPlugin.AMA_OBJECTIVE).setStartedOn(null);
|
||||
objectivesPlugin.getObjectives().get(ObjectivesPlugin.Companion.getAMA_OBJECTIVE()).setStartedOn(null);
|
||||
|
||||
Constraint<Boolean> c = new Constraint<>(true);
|
||||
c = objectivesPlugin.isAMAModeEnabled(c);
|
||||
|
@ -69,7 +69,7 @@ public class ObjectivesPluginTest {
|
|||
|
||||
@Test
|
||||
public void notStartedObjective8ShouldLimitSMBMode() throws Exception {
|
||||
objectivesPlugin.objectives.get(ObjectivesPlugin.SMB_OBJECTIVE).setStartedOn(null);
|
||||
objectivesPlugin.getObjectives().get(ObjectivesPlugin.Companion.getSMB_OBJECTIVE()).setStartedOn(null);
|
||||
|
||||
Constraint<Boolean> c = new Constraint<>(true);
|
||||
c = objectivesPlugin.isSMBModeEnabled(c);
|
||||
|
@ -85,6 +85,6 @@ public class ObjectivesPluginTest {
|
|||
AAPSMocker.mockSP();
|
||||
AAPSMocker.mockStrings();
|
||||
|
||||
objectivesPlugin = ObjectivesPlugin.getPlugin();
|
||||
objectivesPlugin = ObjectivesPlugin.Companion.getPlugin();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue