Objectives -> kt

This commit is contained in:
Milos Kozak 2021-02-15 00:12:56 +01:00
parent a3b500edf2
commit 475517c328
27 changed files with 681 additions and 904 deletions

View file

@ -114,7 +114,7 @@ class OpenAPSAMAFragment : DaggerFragment() {
if (openAPSAMAPlugin.lastAPSRun != 0L) {
binding.lastrun.text = dateUtil.dateAndTimeString(openAPSAMAPlugin.lastAPSRun)
}
openAPSAMAPlugin.lastAutosensResult?.let {
openAPSAMAPlugin.lastAutosensResult.let {
binding.autosensdata.text = JSONFormatter.format(it.json())
}
}

View file

@ -196,19 +196,19 @@ class ObjectivesFragment : DaggerFragment() {
if (task.shouldBeIgnored()) continue
// name
val name = TextView(holder.binding.progress.context)
name.text = resourceHelper.gs(task.task) + ":"
name.text = "${resourceHelper.gs(task.task)}:"
name.setTextColor(-0x1)
holder.binding.progress.addView(name, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)
// hint
task.hints.forEach { h ->
if (!task.isCompleted)
holder.binding.progress.addView(h.generate(context))
if (!task.isCompleted())
context?.let { holder.binding.progress.addView(h.generate(it)) }
}
// state
val state = TextView(holder.binding.progress.context)
state.setTextColor(-0x1)
val basicHTML = "<font color=\"%1\$s\"><b>%2\$s</b></font>"
val formattedHTML = String.format(basicHTML, if (task.isCompleted) "#4CAF50" else "#FF9800", task.progress)
val formattedHTML = String.format(basicHTML, if (task.isCompleted()) "#4CAF50" else "#FF9800", task.progress)
state.text = HtmlHelper.fromHtml(formattedHTML)
state.gravity = Gravity.END
holder.binding.progress.addView(state, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)
@ -307,7 +307,7 @@ class ObjectivesFragment : DaggerFragment() {
holder.binding.unstart.setOnClickListener {
activity?.let { activity ->
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.objectives), resourceHelper.gs(R.string.doyouwantresetstart), Runnable {
uel.log("OBJECTVE UNSTARTED", i1 = position + 1)
uel.log("OBJECTIVE UNSTARTED", i1 = position + 1)
objective.startedOn = 0
scrollToCurrentObjective()
rxBus.send(EventObjectivesUpdateGui())
@ -332,7 +332,7 @@ class ObjectivesFragment : DaggerFragment() {
holder.binding.inputhint.visibility = View.VISIBLE
holder.binding.enterbutton.setOnClickListener {
val input = holder.binding.input.text.toString()
objective.specialAction(activity, input)
activity?.let { activity -> objective.specialAction(activity, input) }
rxBus.send(EventObjectivesUpdateGui())
}
} else {

View file

@ -80,28 +80,30 @@ class ObjectivesExamDialog : DaggerDialogFragment() {
// Options
binding.examOptions.removeAllViews()
task.options.forEach {
val cb = it.generate(context)
if (task.answered) {
cb.isEnabled = false
if (it.isCorrect)
cb.isChecked = true
context?.let { context ->
val cb = it.generate(context)
if (task.answered) {
cb.isEnabled = false
if (it.isCorrect)
cb.isChecked = true
}
binding.examOptions.addView(cb)
}
binding.examOptions.addView(cb)
}
// Hints
binding.examHints.removeAllViews()
for (h in task.hints) {
binding.examHints.addView(h.generate(context))
context?.let { binding.examHints.addView(h.generate(it)) }
}
// Disabled to
binding.examDisabledto.text = resourceHelper.gs(R.string.answerdisabledto, dateUtil.timeString(task.disabledTo))
binding.examDisabledto.visibility = if (task.isEnabledAnswer) View.GONE else View.VISIBLE
binding.examDisabledto.visibility = if (task.isEnabledAnswer()) View.GONE else View.VISIBLE
// Buttons
binding.examVerify.isEnabled = !task.answered && task.isEnabledAnswer
binding.examVerify.isEnabled = !task.answered && task.isEnabledAnswer()
binding.examVerify.setOnClickListener {
var result = true
for (o in task.options) {
val option: Option = o as Option
val option: Option = o
result = result && option.evaluate()
}
task.answered = result
@ -133,14 +135,14 @@ class ObjectivesExamDialog : DaggerDialogFragment() {
binding.nextUnansweredButton.isEnabled = !objective.isCompleted
binding.nextUnansweredButton.setOnClickListener {
for (i in (currentTask + 1) until objective.tasks.size) {
if (!objective.tasks[i].isCompleted) {
if (!objective.tasks[i].isCompleted()) {
currentTask = i
updateGui()
return@setOnClickListener
}
}
for (i in 0..currentTask) {
if (!objective.tasks[i].isCompleted) {
if (!objective.tasks[i].isCompleted()) {
currentTask = i
updateGui()
return@setOnClickListener

View file

@ -1,295 +0,0 @@
package info.nightscout.androidaps.plugins.constraints.objectives.objectives;
import android.content.Context;
import android.graphics.Color;
import android.text.util.Linkify;
import android.widget.CheckBox;
import android.widget.TextView;
import androidx.annotation.StringRes;
import androidx.fragment.app.FragmentActivity;
import java.util.ArrayList;
import java.util.List;
import javax.inject.Inject;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.T;
import info.nightscout.androidaps.utils.resources.ResourceHelper;
import info.nightscout.androidaps.utils.sharedPreferences.SP;
public abstract class Objective {
@Inject public SP sp;
@Inject public ResourceHelper resourceHelper;
private final String spName;
@StringRes private final int objective;
@StringRes private final int gate;
private long startedOn;
private long accomplishedOn;
List<Task> tasks = new ArrayList<>();
public boolean hasSpecialInput = false;
public Objective(HasAndroidInjector injector, String spName, @StringRes int objective, @StringRes int gate) {
injector.androidInjector().inject(this);
this.spName = spName;
this.objective = objective;
this.gate = gate;
startedOn = sp.getLong("Objectives_" + spName + "_started", 0L);
accomplishedOn = sp.getLong("Objectives_" + spName + "_accomplished", 0L);
if ((accomplishedOn - DateUtil.now()) > T.hours(3).msecs() || (startedOn - DateUtil.now()) > T.hours(3).msecs()) { // more than 3 hours in the future
startedOn = 0;
accomplishedOn = 0;
}
setupTasks(tasks);
for (Task task : tasks) task.objective = this;
}
public boolean isCompleted() {
for (Task task : tasks) {
if (!task.shouldBeIgnored() && !task.isCompleted())
return false;
}
return true;
}
public boolean isCompleted(long trueTime) {
for (Task task : tasks) {
if (!task.shouldBeIgnored() && !task.isCompleted(trueTime))
return false;
}
return true;
}
public boolean isAccomplished() {
return accomplishedOn != 0 && accomplishedOn < DateUtil.now();
}
public boolean isStarted() {
return startedOn != 0;
}
public long getStartedOn() {
return startedOn;
}
public int getObjective() {
return objective;
}
public int getGate() {
return gate;
}
public void setStartedOn(long startedOn) {
this.startedOn = startedOn;
sp.putLong("Objectives_" + spName + "_started", startedOn);
}
public void setAccomplishedOn(long accomplishedOn) {
this.accomplishedOn = accomplishedOn;
sp.putLong("Objectives_" + spName + "_accomplished", accomplishedOn);
}
public long getAccomplishedOn() {
return accomplishedOn;
}
protected void setupTasks(List<Task> tasks) {
}
public List<Task> getTasks() {
return tasks;
}
public boolean specialActionEnabled() {
return true;
}
public void specialAction(FragmentActivity activity, String input) {
}
public abstract class Task {
@StringRes
private final int task;
private Objective objective;
ArrayList<Hint> hints = new ArrayList<>();
public Task(@StringRes int task) {
this.task = task;
}
public @StringRes int getTask() {
return task;
}
protected Objective getObjective() {
return objective;
}
public abstract boolean isCompleted();
public boolean isCompleted(long trueTime) {
return isCompleted();
}
public String getProgress() {
return resourceHelper.gs(isCompleted() ? R.string.completed_well_done : R.string.not_completed_yet);
}
Task hint(Hint hint) {
hints.add(hint);
return this;
}
public ArrayList<Hint> getHints() {
return hints;
}
public boolean shouldBeIgnored() {
return false;
}
}
public class MinimumDurationTask extends Task {
private final long minimumDuration;
MinimumDurationTask(long minimumDuration) {
super(R.string.time_elapsed);
this.minimumDuration = minimumDuration;
}
@Override
public boolean isCompleted() {
return getObjective().isStarted() && System.currentTimeMillis() - getObjective().getStartedOn() >= minimumDuration;
}
@Override
public boolean isCompleted(long trueTime) {
return getObjective().isStarted() && trueTime - getObjective().getStartedOn() >= minimumDuration;
}
@Override
public String getProgress() {
return getDurationText(System.currentTimeMillis() - getObjective().getStartedOn())
+ " / " + getDurationText(minimumDuration);
}
private String getDurationText(long duration) {
int days = (int) Math.floor((double) duration / T.days(1).msecs());
int hours = (int) Math.floor((double) duration / T.hours(1).msecs());
int minutes = (int) Math.floor((double) duration / T.mins(1).msecs());
if (days > 0) return resourceHelper.gq(R.plurals.days, days, days);
else if (hours > 0) return resourceHelper.gq(R.plurals.hours, hours, hours);
else return resourceHelper.gq(R.plurals.minutes, minutes, minutes);
}
}
public class ExamTask extends Task {
@StringRes
int question;
ArrayList<Option> options = new ArrayList<>();
private final String spIdentifier;
private boolean answered;
private long disabledTo;
ExamTask(@StringRes int task, @StringRes int question, String spIdentifier) {
super(task);
this.question = question;
this.spIdentifier = spIdentifier;
answered = sp.getBoolean("ExamTask_" + spIdentifier, false);
disabledTo = sp.getLong("DisabledTo_" + spIdentifier, 0L);
}
public void setDisabledTo(long newState) {
disabledTo = newState;
sp.putLong("DisabledTo_" + spIdentifier, disabledTo);
}
public long getDisabledTo() {
return disabledTo;
}
public boolean isEnabledAnswer() {
return disabledTo < DateUtil.now();
}
public void setAnswered(boolean newState) {
answered = newState;
sp.putBoolean("ExamTask_" + spIdentifier, answered);
}
public boolean getAnswered() {
return answered;
}
ExamTask option(Option option) {
options.add(option);
return this;
}
public @StringRes int getQuestion() {
return question;
}
public List<Objective.Option> getOptions() {
return options;
}
@Override
public boolean isCompleted() {
return answered;
}
}
public class Option {
@StringRes int option;
boolean isCorrect;
CheckBox cb; // TODO: change it, this will block releasing memeory
Option(@StringRes int option, boolean isCorrect) {
this.option = option;
this.isCorrect = isCorrect;
}
public boolean isCorrect() {
return isCorrect;
}
public CheckBox generate(Context context) {
cb = new CheckBox(context);
cb.setText(option);
return cb;
}
public boolean evaluate() {
boolean selection = cb.isChecked();
if (selection && isCorrect) return true;
return !selection && !isCorrect;
}
}
public class Hint {
@StringRes int hint;
Hint(@StringRes int hint) {
this.hint = hint;
}
public TextView generate(Context context) {
TextView textView = new TextView(context);
textView.setText(hint);
textView.setAutoLinkMask(Linkify.WEB_URLS);
textView.setLinksClickable(true);
textView.setLinkTextColor(Color.YELLOW);
Linkify.addLinks(textView, Linkify.WEB_URLS);
return textView;
}
}
}

View file

@ -0,0 +1,183 @@
package info.nightscout.androidaps.plugins.constraints.objectives.objectives
import android.content.Context
import android.graphics.Color
import android.text.util.Linkify
import android.widget.CheckBox
import android.widget.TextView
import androidx.annotation.StringRes
import androidx.fragment.app.FragmentActivity
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.R
import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.T
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.sharedPreferences.SP
import java.util.*
import javax.inject.Inject
import kotlin.math.floor
abstract class Objective(injector: HasAndroidInjector, spName: String, @StringRes objective: Int, @StringRes gate: Int) {
@Inject lateinit var sp: SP
@Inject lateinit var resourceHelper: ResourceHelper
private val spName: String
@StringRes val objective: Int
@StringRes val gate: Int
var startedOn: Long = 0
set(value) {
field = value
sp.putLong("Objectives_" + spName + "_started", startedOn)
}
var accomplishedOn: Long = 0
set(value) {
field = value
sp.putLong("Objectives_" + spName + "_accomplished", value)
}
var tasks: MutableList<Task> = ArrayList()
var hasSpecialInput = false
val isCompleted: Boolean
get() {
for (task in tasks) {
if (!task.shouldBeIgnored() && !task.isCompleted()) return false
}
return true
}
init {
injector.androidInjector().inject(this)
this.spName = spName
this.objective = objective
this.gate = gate
startedOn = sp.getLong("Objectives_" + spName + "_started", 0L)
accomplishedOn = sp.getLong("Objectives_" + spName + "_accomplished", 0L)
if (accomplishedOn - DateUtil.now() > T.hours(3).msecs() || startedOn - DateUtil.now() > T.hours(3).msecs()) { // more than 3 hours in the future
startedOn = 0
accomplishedOn = 0
}
}
fun isCompleted(trueTime: Long): Boolean {
for (task in tasks) {
if (!task.shouldBeIgnored() && !task.isCompleted(trueTime)) return false
}
return true
}
val isAccomplished: Boolean
get() = accomplishedOn != 0L && accomplishedOn < DateUtil.now()
val isStarted: Boolean
get() = startedOn != 0L
open fun specialActionEnabled(): Boolean {
return true
}
open fun specialAction(activity: FragmentActivity, input: String) {}
abstract inner class Task(var objective: Objective, @StringRes val task: Int) {
var hints = ArrayList<Hint>()
abstract fun isCompleted(): Boolean
open fun isCompleted(trueTime: Long): Boolean = isCompleted
open val progress: String
get() = resourceHelper.gs(if (isCompleted) R.string.completed_well_done else R.string.not_completed_yet)
fun hint(hint: Hint): Task {
hints.add(hint)
return this
}
open fun shouldBeIgnored(): Boolean = false
}
inner class MinimumDurationTask internal constructor(objective: Objective, private val minimumDuration: Long) : Task(objective, R.string.time_elapsed) {
override fun isCompleted(): Boolean =
objective.isStarted && System.currentTimeMillis() - objective.startedOn >= minimumDuration
override fun isCompleted(trueTime: Long): Boolean {
return objective.isStarted && trueTime - objective.startedOn >= minimumDuration
}
override val progress: String
get() = (getDurationText(System.currentTimeMillis() - objective.startedOn)
+ " / " + getDurationText(minimumDuration))
private fun getDurationText(duration: Long): String {
val days = floor(duration.toDouble() / T.days(1).msecs()).toInt()
val hours = floor(duration.toDouble() / T.hours(1).msecs()).toInt()
val minutes = floor(duration.toDouble() / T.mins(1).msecs()).toInt()
return when {
days > 0 -> resourceHelper.gq(R.plurals.days, days, days)
hours > 0 -> resourceHelper.gq(R.plurals.hours, hours, hours)
else -> resourceHelper.gq(R.plurals.minutes, minutes, minutes)
}
}
}
inner class ExamTask internal constructor(objective: Objective, @StringRes task: Int, @StringRes val question: Int, private val spIdentifier: String) : Task(objective, task) {
var options = ArrayList<Option>()
var answered: Boolean = false
set(value) {
field = value
sp.putBoolean("ExamTask_$spIdentifier", value)
}
var disabledTo: Long = 0
set(value) {
field = value
sp.putLong("DisabledTo_$spIdentifier", value)
}
init {
answered = sp.getBoolean("ExamTask_$spIdentifier", false)
disabledTo = sp.getLong("DisabledTo_$spIdentifier", 0L)
}
override fun isCompleted(): Boolean = answered
fun isEnabledAnswer(): Boolean = disabledTo < DateUtil.now()
fun option(option: Option): ExamTask {
options.add(option)
return this
}
}
inner class Option internal constructor(@StringRes var option: Int, var isCorrect: Boolean) {
var cb: CheckBox? = null // TODO: change it, this will block releasing memory
fun generate(context: Context): CheckBox {
cb = CheckBox(context)
cb?.setText(option)
return cb!!
}
fun evaluate(): Boolean {
val selection = cb!!.isChecked
return if (selection && isCorrect) true else !selection && !isCorrect
}
}
inner class Hint internal constructor(@StringRes var hint: Int) {
fun generate(context: Context): TextView {
val textView = TextView(context)
textView.setText(hint)
textView.autoLinkMask = Linkify.WEB_URLS
textView.linksClickable = true
textView.setLinkTextColor(Color.YELLOW)
Linkify.addLinks(textView, Linkify.WEB_URLS)
return textView
}
}
}

View file

@ -1,91 +0,0 @@
package info.nightscout.androidaps.plugins.constraints.objectives.objectives;
import java.util.List;
import javax.inject.Inject;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.APSInterface;
import info.nightscout.androidaps.interfaces.ActivePluginProvider;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin;
import info.nightscout.androidaps.plugins.general.nsclient.NSClientPlugin;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin;
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.sharedPreferences.SP;
public class Objective0 extends Objective {
@Inject SP sp;
@Inject ActivePluginProvider activePlugin;
@Inject VirtualPumpPlugin virtualPumpPlugin;
@Inject TreatmentsPlugin treatmentsPlugin;
@Inject LoopPlugin loopPlugin;
@Inject NSClientPlugin nsClientPlugin;
@Inject IobCobCalculatorPlugin iobCobCalculatorPlugin;
public Objective0(HasAndroidInjector injector) {
super(injector, "config", R.string.objectives_0_objective, R.string.objectives_0_gate);
}
@Override
protected void setupTasks(List<Task> tasks) {
tasks.add(new Task(R.string.objectives_bgavailableinns) {
@Override
public boolean isCompleted() {
return sp.getBoolean(R.string.key_ObjectivesbgIsAvailableInNS, false);
}
});
tasks.add(new Task(R.string.nsclienthaswritepermission) {
@Override
public boolean isCompleted() {
return nsClientPlugin.hasWritePermission();
}
});
tasks.add(new Task(R.string.virtualpump_uploadstatus_title) {
@Override
public boolean isCompleted() {
return sp.getBoolean(R.string.key_virtualpump_uploadstatus, false);
}
@Override
public boolean shouldBeIgnored() {
return !virtualPumpPlugin.isEnabled(PluginType.PUMP);
}
});
tasks.add(new Task(R.string.objectives_pumpstatusavailableinns) {
@Override
public boolean isCompleted() {
return sp.getBoolean(R.string.key_ObjectivespumpStatusIsAvailableInNS, false);
}
});
tasks.add(new Task(R.string.hasbgdata) {
@Override
public boolean isCompleted() {
return iobCobCalculatorPlugin.lastBg() != null;
}
});
tasks.add(new Task(R.string.loopenabled) {
@Override
public boolean isCompleted() {
return loopPlugin.isEnabled(PluginType.LOOP);
}
});
tasks.add(new Task(R.string.apsselected) {
@Override
public boolean isCompleted() {
APSInterface usedAPS = activePlugin.getActiveAPS();
return ((PluginBase) usedAPS).isEnabled(PluginType.APS);
}
});
tasks.add(new Task(R.string.activate_profile) {
@Override
public boolean isCompleted() {
return treatmentsPlugin.getProfileSwitchFromHistory(DateUtil.now()) != null;
}
});
}
}

View file

@ -0,0 +1,72 @@
package info.nightscout.androidaps.plugins.constraints.objectives.objectives
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.R
import info.nightscout.androidaps.interfaces.ActivePluginProvider
import info.nightscout.androidaps.interfaces.PluginBase
import info.nightscout.androidaps.interfaces.PluginType
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin
import info.nightscout.androidaps.plugins.general.nsclient.NSClientPlugin
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin
import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
import info.nightscout.androidaps.utils.DateUtil
import javax.inject.Inject
class Objective0(injector: HasAndroidInjector) : Objective(injector, "config", R.string.objectives_0_objective, R.string.objectives_0_gate) {
@Inject lateinit var activePlugin: ActivePluginProvider
@Inject lateinit var virtualPumpPlugin: VirtualPumpPlugin
@Inject lateinit var treatmentsPlugin: TreatmentsPlugin
@Inject lateinit var loopPlugin: LoopPlugin
@Inject lateinit var nsClientPlugin: NSClientPlugin
@Inject lateinit var iobCobCalculatorPlugin: IobCobCalculatorPlugin
init {
tasks.add(object : Task(this, R.string.objectives_bgavailableinns) {
override fun isCompleted(): Boolean {
return sp.getBoolean(R.string.key_ObjectivesbgIsAvailableInNS, false)
}
})
tasks.add(object : Task(this, R.string.nsclienthaswritepermission) {
override fun isCompleted(): Boolean {
return nsClientPlugin.hasWritePermission()
}
})
tasks.add(object : Task(this, R.string.virtualpump_uploadstatus_title) {
override fun isCompleted(): Boolean {
return sp.getBoolean(R.string.key_virtualpump_uploadstatus, false)
}
override fun shouldBeIgnored(): Boolean {
return !virtualPumpPlugin.isEnabled(PluginType.PUMP)
}
})
tasks.add(object : Task(this, R.string.objectives_pumpstatusavailableinns) {
override fun isCompleted(): Boolean {
return sp.getBoolean(R.string.key_ObjectivespumpStatusIsAvailableInNS, false)
}
})
tasks.add(object : Task(this, R.string.hasbgdata) {
override fun isCompleted(): Boolean {
return iobCobCalculatorPlugin.lastBg() != null
}
})
tasks.add(object : Task(this, R.string.loopenabled) {
override fun isCompleted(): Boolean {
return loopPlugin.isEnabled(PluginType.LOOP)
}
})
tasks.add(object : Task(this, R.string.apsselected) {
override fun isCompleted(): Boolean {
val usedAPS = activePlugin.activeAPS
return (usedAPS as PluginBase).isEnabled(PluginType.APS)
}
})
tasks.add(object : Task(this, R.string.activate_profile) {
override fun isCompleted(): Boolean {
return treatmentsPlugin.getProfileSwitchFromHistory(DateUtil.now()) != null
}
})
}
}

View file

@ -1,67 +0,0 @@
package info.nightscout.androidaps.plugins.constraints.objectives.objectives;
import java.util.List;
import javax.inject.Inject;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.plugins.general.actions.ActionsPlugin;
import info.nightscout.androidaps.utils.sharedPreferences.SP;
public class Objective1 extends Objective {
@Inject SP sp;
@Inject ActionsPlugin actionsPlugin;
@Inject
public Objective1(HasAndroidInjector injector) {
super(injector, "usage", R.string.objectives_usage_objective, R.string.objectives_usage_gate);
}
@Override
protected void setupTasks(List<Task> tasks) {
tasks.add(new Task(R.string.objectives_useprofileswitch) {
@Override
public boolean isCompleted() {
return sp.getBoolean(R.string.key_objectiveuseprofileswitch, false);
}
});
tasks.add(new Task(R.string.objectives_usedisconnectpump) {
@Override
public boolean isCompleted() {
return sp.getBoolean(R.string.key_objectiveusedisconnect, false);
}
}.hint(new Hint(R.string.disconnectpump_hint)));
tasks.add(new Task(R.string.objectives_usereconnectpump) {
@Override
public boolean isCompleted() {
return sp.getBoolean(R.string.key_objectiveusereconnect, false);
}
}.hint(new Hint(R.string.disconnectpump_hint)));
tasks.add(new Task(R.string.objectives_usetemptarget) {
@Override
public boolean isCompleted() {
return sp.getBoolean(R.string.key_objectiveusetemptarget, false);
}
}.hint(new Hint(R.string.usetemptarget_hint)));
tasks.add(new Task(R.string.objectives_useactions) {
@Override
public boolean isCompleted() {
return sp.getBoolean(R.string.key_objectiveuseactions, false) && actionsPlugin.isEnabled(PluginType.GENERAL) && actionsPlugin.isFragmentVisible();
}
}.hint(new Hint(R.string.useaction_hint)));
tasks.add(new Task(R.string.objectives_useloop) {
@Override
public boolean isCompleted() {
return sp.getBoolean(R.string.key_objectiveuseloop, false);
}
}.hint(new Hint(R.string.useaction_hint)));
tasks.add(new Task(R.string.objectives_usescale) {
@Override
public boolean isCompleted() {
return sp.getBoolean(R.string.key_objectiveusescale, false);
}
}.hint(new Hint(R.string.usescale_hint)));
}
}

View file

@ -0,0 +1,50 @@
package info.nightscout.androidaps.plugins.constraints.objectives.objectives
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.R
import info.nightscout.androidaps.interfaces.PluginType
import info.nightscout.androidaps.plugins.general.actions.ActionsPlugin
import javax.inject.Inject
class Objective1 @Inject constructor(injector: HasAndroidInjector) : Objective(injector, "usage", R.string.objectives_usage_objective, R.string.objectives_usage_gate) {
@Inject lateinit var actionsPlugin: ActionsPlugin
init {
tasks.add(object : Task(this, R.string.objectives_useprofileswitch) {
override fun isCompleted(): Boolean {
return sp.getBoolean(R.string.key_objectiveuseprofileswitch, false)
}
})
tasks.add(object : Task(this, R.string.objectives_usedisconnectpump) {
override fun isCompleted(): Boolean {
return sp.getBoolean(R.string.key_objectiveusedisconnect, false)
}
}.hint(Hint(R.string.disconnectpump_hint)))
tasks.add(object : Task(this, R.string.objectives_usereconnectpump) {
override fun isCompleted(): Boolean {
return sp.getBoolean(R.string.key_objectiveusereconnect, false)
}
}.hint(Hint(R.string.disconnectpump_hint)))
tasks.add(object : Task(this, R.string.objectives_usetemptarget) {
override fun isCompleted(): Boolean {
return sp.getBoolean(R.string.key_objectiveusetemptarget, false)
}
}.hint(Hint(R.string.usetemptarget_hint)))
tasks.add(object : Task(this, R.string.objectives_useactions) {
override fun isCompleted(): Boolean {
return sp.getBoolean(R.string.key_objectiveuseactions, false) && actionsPlugin.isEnabled(PluginType.GENERAL) && actionsPlugin.isFragmentVisible()
}
}.hint(Hint(R.string.useaction_hint)))
tasks.add(object : Task(this, R.string.objectives_useloop) {
override fun isCompleted(): Boolean {
return sp.getBoolean(R.string.key_objectiveuseloop, false)
}
}.hint(Hint(R.string.useaction_hint)))
tasks.add(object : Task(this, R.string.objectives_usescale) {
override fun isCompleted(): Boolean {
return sp.getBoolean(R.string.key_objectiveusescale, false)
}
}.hint(Hint(R.string.usescale_hint)))
}
}

View file

@ -1,19 +0,0 @@
package info.nightscout.androidaps.plugins.constraints.objectives.objectives;
import java.util.List;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.utils.T;
public class Objective10 extends Objective {
public Objective10(HasAndroidInjector injector) {
super(injector, "auto", R.string.objectives_auto_objective, R.string.objectives_auto_gate);
}
@Override
protected void setupTasks(List<Task> tasks) {
tasks.add(new MinimumDurationTask(T.days(28).msecs()));
}
}

View file

@ -0,0 +1,12 @@
package info.nightscout.androidaps.plugins.constraints.objectives.objectives
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.R
import info.nightscout.androidaps.utils.T
class Objective10(injector: HasAndroidInjector) : Objective(injector, "auto", R.string.objectives_auto_objective, R.string.objectives_auto_gate) {
init {
tasks.add(MinimumDurationTask(this, T.days(28).msecs()))
}
}

View file

@ -1,222 +0,0 @@
package info.nightscout.androidaps.plugins.constraints.objectives.objectives;
import java.util.Collections;
import java.util.List;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
public class Objective2 extends Objective {
public Objective2(HasAndroidInjector injector) {
super(injector, "exam", R.string.objectives_exam_objective, R.string.objectives_exam_gate);
for (Task task : tasks) {
if (!task.isCompleted()) setAccomplishedOn(0);
}
}
@Override
protected void setupTasks(List<Task> tasks) {
tasks.add(new ExamTask(R.string.prerequisites_label, R.string.prerequisites_what, "prerequisites")
.option(new Option(R.string.prerequisites_nightscout, true))
.option(new Option(R.string.prerequisites_computer, true))
.option(new Option(R.string.prerequisites_pump, true))
.option(new Option(R.string.prerequisites_beanandroiddeveloper, false))
.hint(new Hint(R.string.prerequisites_hint1))
);
tasks.add(new ExamTask(R.string.prerequisites2_label, R.string.prerequisites2_what, "prerequisites2")
.option(new Option(R.string.prerequisites2_profile, true))
.option(new Option(R.string.prerequisites2_device, true))
.option(new Option(R.string.prerequisites2_internet, false))
.option(new Option(R.string.prerequisites2_supportedcgm, true))
.hint(new Hint(R.string.prerequisites2_hint1))
);
tasks.add(new ExamTask(R.string.basaltest_label, R.string.basaltest_when,"basaltest")
.option(new Option(R.string.basaltest_fixed, false))
.option(new Option(R.string.basaltest_havingregularhighlow, true))
.option(new Option(R.string.basaltest_weekly, false))
.option(new Option(R.string.basaltest_beforeloop, true))
.hint(new Hint(R.string.basaltest_hint1))
);
tasks.add(new ExamTask(R.string.dia_label_exam, R.string.dia_whatmeansdia,"dia")
.option(new Option(R.string.dia_profile, true))
.option(new Option(R.string.dia_minimumis5h, true))
.option(new Option(R.string.dia_meaningisequaltodiapump, false))
.option(new Option(R.string.dia_valuemustbedetermined, true))
.hint(new Hint(R.string.dia_hint1))
);
tasks.add(new ExamTask(R.string.isf_label_exam, R.string.blank,"isf")
.option(new Option(R.string.isf_decreasingvalue, true))
.option(new Option(R.string.isf_preferences, false))
.option(new Option(R.string.isf_increasingvalue, false))
.option(new Option(R.string.isf_noeffect, false))
.hint(new Hint(R.string.isf_hint1))
.hint(new Hint(R.string.isf_hint2))
);
tasks.add(new ExamTask(R.string.ic_label_exam, R.string.blank,"ic")
.option(new Option(R.string.ic_increasingvalue, true))
.option(new Option(R.string.ic_decreasingvalue, false))
.option(new Option(R.string.ic_multiple, true))
.option(new Option(R.string.ic_isf, false))
.hint(new Hint(R.string.ic_hint1))
);
tasks.add(new ExamTask(R.string.hypott_label, R.string.hypott_whenhypott,"hypott")
.option(new Option(R.string.hypott_preventoversmb, true))
.option(new Option(R.string.hypott_exercise, false))
.option(new Option(R.string.hypott_wrongbasal, false))
.option(new Option(R.string.hypott_0basal, false))
.hint(new Hint(R.string.hypott_hint1))
);
tasks.add(new ExamTask(R.string.profileswitch_label, R.string.profileswitch_pctwillchange,"profileswitch")
.option(new Option(R.string.profileswitch_basallower, true))
.option(new Option(R.string.profileswitch_isfhigher, true))
.option(new Option(R.string.profileswitch_iclower, false))
.option(new Option(R.string.profileswitch_unchanged, false))
.hint(new Hint(R.string.profileswitch_hint1))
);
tasks.add(new ExamTask(R.string.profileswitch2_label, R.string.profileswitch2_pctwillchange,"profileswitch2")
.option(new Option(R.string.profileswitch2_bghigher, false))
.option(new Option(R.string.profileswitch2_basalhigher, true))
.option(new Option(R.string.profileswitch2_bgunchanged, true))
.option(new Option(R.string.profileswitch2_isfhigher, false))
.hint(new Hint(R.string.profileswitch_hint1))
);
tasks.add(new ExamTask(R.string.profileswitchtime_label, R.string.profileswitchtime_iwant,"profileswitchtime")
.option(new Option(R.string.profileswitchtime_2, false))
.option(new Option(R.string.profileswitchtime__2, true))
.option(new Option(R.string.profileswitchtime_tt, false))
.option(new Option(R.string.profileswitchtime_100, false))
.hint(new Hint(R.string.profileswitchtime_hint1))
);
tasks.add(new ExamTask(R.string.profileswitch4_label, R.string.blank,"profileswitch4")
.option(new Option(R.string.profileswitch4_rates, true))
.option(new Option(R.string.profileswitch4_internet, true))
.option(new Option(R.string.profileswitch4_sufficient, false))
.option(new Option(R.string.profileswitch4_multi, true))
.hint(new Hint(R.string.profileswitch_hint1))
);
tasks.add(new ExamTask(R.string.exerciseprofile_label, R.string.exerciseprofile_whattodo,"exercise")
.option(new Option(R.string.exerciseprofile_switchprofileabove100, false))
.option(new Option(R.string.exerciseprofile_switchprofilebelow100, true))
.option(new Option(R.string.exerciseprofile_suspendloop, false))
.option(new Option(R.string.exerciseprofile_leaveat100, false))
.hint(new Hint(R.string.exerciseprofile_hint1))
);
tasks.add(new ExamTask(R.string.exercise_label, R.string.exercise_whattodo,"exercise2")
.option(new Option(R.string.exercise_settt, true))
.option(new Option(R.string.exercise_setfinished, false))
.option(new Option(R.string.exercise_setunchanged, false))
.option(new Option(R.string.exercise_15g, false))
.hint(new Hint(R.string.exercise_hint1))
);
tasks.add(new ExamTask(R.string.noisycgm_label, R.string.noisycgm_whattodo,"noisycgm")
.option(new Option(R.string.noisycgm_nothing, false))
.option(new Option(R.string.noisycgm_pause, true))
.option(new Option(R.string.noisycgm_replacesensor, true))
.option(new Option(R.string.noisycgm_checksmoothing, true))
.hint(new Hint(R.string.noisycgm_hint1))
);
tasks.add(new ExamTask(R.string.pumpdisconnect_label, R.string.blank,"pumpdisconnect")
.option(new Option(R.string.pumpdisconnect_unnecessary, false))
.option(new Option(R.string.pumpdisconnect_missinginsulin, true))
.option(new Option(R.string.pumpdisconnect_notstop, false))
.option(new Option(R.string.pumpdisconnect_openloop, false))
.hint(new Hint(R.string.pumpdisconnect_hint1))
);
tasks.add(new ExamTask(R.string.insulin_label, R.string.insulin_ultrarapid,"insulin")
.option(new Option(R.string.insulin_novorapid, false))
.option(new Option(R.string.insulin_humalog, false))
.option(new Option(R.string.insulin_actrapid, false))
.option(new Option(R.string.insulin_fiasp, true))
.hint(new Hint(R.string.insulin_hint1))
);
tasks.add(new ExamTask(R.string.sensitivity_label, R.string.blank,"sensitivity")
.option(new Option(R.string.sensitivity_adjust, true))
.option(new Option(R.string.sensitivity_edit, false))
.option(new Option(R.string.sensitivity_cannula, true))
.option(new Option(R.string.sensitivity_time, true))
.hint(new Hint(R.string.sensitivity_hint1))
);
tasks.add(new ExamTask(R.string.objectives_label, R.string.objectives_howtosave,"objectives")
.option(new Option(R.string.objectives_notesettings, false))
.option(new Option(R.string.objectives_afterobjective, true))
.option(new Option(R.string.objectives_afterchange, true))
.option(new Option(R.string.objectives_afterinitialsetup, true))
.hint(new Hint(R.string.objectives_hint1))
.hint(new Hint(R.string.objectives_hint2))
);
tasks.add(new ExamTask(R.string.objectives2_label, R.string.objectives_howtosave,"objectives2")
.option(new Option(R.string.objectives2_maintenance, true))
.option(new Option(R.string.objectives2_internalstorage, true))
.option(new Option(R.string.objectives2_cloud, true))
.option(new Option(R.string.objectives2_easyrestore, false))
.hint(new Hint(R.string.objectives_hint1))
.hint(new Hint(R.string.objectives_hint2))
);
tasks.add(new ExamTask(R.string.update_label, R.string.blank,"update")
.option(new Option(R.string.update_git, true))
.option(new Option(R.string.update_askfriend, false))
.option(new Option(R.string.update_keys, true))
.option(new Option(R.string.update_asap, true))
.hint(new Hint(R.string.update_hint1))
);
tasks.add(new ExamTask(R.string.troubleshooting_label, R.string.troubleshooting_wheretoask,"troubleshooting")
.option(new Option(R.string.troubleshooting_fb, true))
.option(new Option(R.string.troubleshooting_wiki, true))
.option(new Option(R.string.troubleshooting_gitter, true))
.option(new Option(R.string.troubleshooting_yourendo, false))
.hint(new Hint(R.string.troubleshooting_hint1))
.hint(new Hint(R.string.troubleshooting_hint2))
.hint(new Hint(R.string.troubleshooting_hint3))
);
tasks.add(new ExamTask(R.string.wrongcarbs_label, R.string.wrongcarbs_whattodo,"wrongcarbs")
.option(new Option(R.string.wrongcarbs_addinsulin, false))
.option(new Option(R.string.wrongcarbs_treatmentstab, true))
.option(new Option(R.string.wrongcarbs_donothing, false))
.option(new Option(R.string.wrongcarbs_bolus, false))
);
tasks.add(new ExamTask(R.string.wronginsulin_label, R.string.wronginsulin_whattodo,"wronginsulin")
.option(new Option(R.string.wronginsulin_careportal, false))
.option(new Option(R.string.wronginsulin_compare, true))
.option(new Option(R.string.wronginsulin_prime, true))
.option(new Option(R.string.wrongcarbs_donothing, false))
);
tasks.add(new ExamTask(R.string.iob_label, R.string.blank,"iob")
.option(new Option(R.string.iob_value, true))
.option(new Option(R.string.iob_hightemp, false))
.option(new Option(R.string.iob_negiob, true))
.option(new Option(R.string.iob_posiob, true))
);
tasks.add(new ExamTask(R.string.breadgrams_label, R.string.blank,"breadgrams")
.option(new Option(R.string.breadgrams_grams, true))
.option(new Option(R.string.breadgrams_exchange, false))
.option(new Option(R.string.breadgrams_decay, true))
.option(new Option(R.string.breadgrams_calc, true))
.hint(new Hint(R.string.breadgrams_hint1))
);
tasks.add(new ExamTask(R.string.extendedcarbs_label, R.string.extendedcarbs_handling,"extendedcarbs")
.option(new Option(R.string.extendedcarbs_future, true))
.option(new Option(R.string.extendedcarbs_free, false))
.option(new Option(R.string.extendedcarbs_fat, true))
.option(new Option(R.string.extendedcarbs_rescue, false))
.hint(new Hint(R.string.extendedcarbs_hint1))
);
tasks.add(new ExamTask(R.string.nsclient_label, R.string.nsclient_howcanyou,"nsclient")
.option(new Option(R.string.nsclient_nightscout, true))
.option(new Option(R.string.nsclient_dexcomfollow, true))
.option(new Option(R.string.nsclient_data, true))
.option(new Option(R.string.nsclient_fullcontrol, false))
.hint(new Hint(R.string.nsclient_hint1))
);
tasks.add(new ExamTask(R.string.other_medication_label, R.string.other_medication_text,"otherMedicationWarning")
.option(new Option(R.string.yes, true))
.option(new Option(R.string.no, false))
);
for (Task task : tasks)
Collections.shuffle(((ExamTask)task).options);
}
}

View file

@ -0,0 +1,211 @@
package info.nightscout.androidaps.plugins.constraints.objectives.objectives
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.R
@Suppress("SpellCheckingInspection")
class Objective2(injector: HasAndroidInjector) : Objective(injector, "exam", R.string.objectives_exam_objective, R.string.objectives_exam_gate) {
init {
tasks.add(ExamTask(this, R.string.prerequisites_label, R.string.prerequisites_what, "prerequisites")
.option(Option(R.string.prerequisites_nightscout, true))
.option(Option(R.string.prerequisites_computer, true))
.option(Option(R.string.prerequisites_pump, true))
.option(Option(R.string.prerequisites_beanandroiddeveloper, false))
.hint(Hint(R.string.prerequisites_hint1))
)
tasks.add(ExamTask(this, R.string.prerequisites2_label, R.string.prerequisites2_what, "prerequisites2")
.option(Option(R.string.prerequisites2_profile, true))
.option(Option(R.string.prerequisites2_device, true))
.option(Option(R.string.prerequisites2_internet, false))
.option(Option(R.string.prerequisites2_supportedcgm, true))
.hint(Hint(R.string.prerequisites2_hint1))
)
tasks.add(ExamTask(this, R.string.basaltest_label, R.string.basaltest_when, "basaltest")
.option(Option(R.string.basaltest_fixed, false))
.option(Option(R.string.basaltest_havingregularhighlow, true))
.option(Option(R.string.basaltest_weekly, false))
.option(Option(R.string.basaltest_beforeloop, true))
.hint(Hint(R.string.basaltest_hint1))
)
tasks.add(ExamTask(this, R.string.dia_label_exam, R.string.dia_whatmeansdia, "dia")
.option(Option(R.string.dia_profile, true))
.option(Option(R.string.dia_minimumis5h, true))
.option(Option(R.string.dia_meaningisequaltodiapump, false))
.option(Option(R.string.dia_valuemustbedetermined, true))
.hint(Hint(R.string.dia_hint1))
)
tasks.add(ExamTask(this, R.string.isf_label_exam, R.string.blank, "isf")
.option(Option(R.string.isf_decreasingvalue, true))
.option(Option(R.string.isf_preferences, false))
.option(Option(R.string.isf_increasingvalue, false))
.option(Option(R.string.isf_noeffect, false))
.hint(Hint(R.string.isf_hint1))
.hint(Hint(R.string.isf_hint2))
)
tasks.add(ExamTask(this, R.string.ic_label_exam, R.string.blank, "ic")
.option(Option(R.string.ic_increasingvalue, true))
.option(Option(R.string.ic_decreasingvalue, false))
.option(Option(R.string.ic_multiple, true))
.option(Option(R.string.ic_isf, false))
.hint(Hint(R.string.ic_hint1))
)
tasks.add(ExamTask(this, R.string.hypott_label, R.string.hypott_whenhypott, "hypott")
.option(Option(R.string.hypott_preventoversmb, true))
.option(Option(R.string.hypott_exercise, false))
.option(Option(R.string.hypott_wrongbasal, false))
.option(Option(R.string.hypott_0basal, false))
.hint(Hint(R.string.hypott_hint1))
)
tasks.add(ExamTask(this, R.string.profileswitch_label, R.string.profileswitch_pctwillchange, "profileswitch")
.option(Option(R.string.profileswitch_basallower, true))
.option(Option(R.string.profileswitch_isfhigher, true))
.option(Option(R.string.profileswitch_iclower, false))
.option(Option(R.string.profileswitch_unchanged, false))
.hint(Hint(R.string.profileswitch_hint1))
)
tasks.add(ExamTask(this, R.string.profileswitch2_label, R.string.profileswitch2_pctwillchange, "profileswitch2")
.option(Option(R.string.profileswitch2_bghigher, false))
.option(Option(R.string.profileswitch2_basalhigher, true))
.option(Option(R.string.profileswitch2_bgunchanged, true))
.option(Option(R.string.profileswitch2_isfhigher, false))
.hint(Hint(R.string.profileswitch_hint1))
)
tasks.add(ExamTask(this, R.string.profileswitchtime_label, R.string.profileswitchtime_iwant, "profileswitchtime")
.option(Option(R.string.profileswitchtime_2, false))
.option(Option(R.string.profileswitchtime__2, true))
.option(Option(R.string.profileswitchtime_tt, false))
.option(Option(R.string.profileswitchtime_100, false))
.hint(Hint(R.string.profileswitchtime_hint1))
)
tasks.add(ExamTask(this, R.string.profileswitch4_label, R.string.blank, "profileswitch4")
.option(Option(R.string.profileswitch4_rates, true))
.option(Option(R.string.profileswitch4_internet, true))
.option(Option(R.string.profileswitch4_sufficient, false))
.option(Option(R.string.profileswitch4_multi, true))
.hint(Hint(R.string.profileswitch_hint1))
)
tasks.add(ExamTask(this, R.string.exerciseprofile_label, R.string.exerciseprofile_whattodo, "exercise")
.option(Option(R.string.exerciseprofile_switchprofileabove100, false))
.option(Option(R.string.exerciseprofile_switchprofilebelow100, true))
.option(Option(R.string.exerciseprofile_suspendloop, false))
.option(Option(R.string.exerciseprofile_leaveat100, false))
.hint(Hint(R.string.exerciseprofile_hint1))
)
tasks.add(ExamTask(this, R.string.exercise_label, R.string.exercise_whattodo, "exercise2")
.option(Option(R.string.exercise_settt, true))
.option(Option(R.string.exercise_setfinished, false))
.option(Option(R.string.exercise_setunchanged, false))
.option(Option(R.string.exercise_15g, false))
.hint(Hint(R.string.exercise_hint1))
)
tasks.add(ExamTask(this, R.string.noisycgm_label, R.string.noisycgm_whattodo, "noisycgm")
.option(Option(R.string.noisycgm_nothing, false))
.option(Option(R.string.noisycgm_pause, true))
.option(Option(R.string.noisycgm_replacesensor, true))
.option(Option(R.string.noisycgm_checksmoothing, true))
.hint(Hint(R.string.noisycgm_hint1))
)
tasks.add(ExamTask(this, R.string.pumpdisconnect_label, R.string.blank, "pumpdisconnect")
.option(Option(R.string.pumpdisconnect_unnecessary, false))
.option(Option(R.string.pumpdisconnect_missinginsulin, true))
.option(Option(R.string.pumpdisconnect_notstop, false))
.option(Option(R.string.pumpdisconnect_openloop, false))
.hint(Hint(R.string.pumpdisconnect_hint1))
)
tasks.add(ExamTask(this, R.string.insulin_label, R.string.insulin_ultrarapid, "insulin")
.option(Option(R.string.insulin_novorapid, false))
.option(Option(R.string.insulin_humalog, false))
.option(Option(R.string.insulin_actrapid, false))
.option(Option(R.string.insulin_fiasp, true))
.hint(Hint(R.string.insulin_hint1))
)
tasks.add(ExamTask(this, R.string.sensitivity_label, R.string.blank, "sensitivity")
.option(Option(R.string.sensitivity_adjust, true))
.option(Option(R.string.sensitivity_edit, false))
.option(Option(R.string.sensitivity_cannula, true))
.option(Option(R.string.sensitivity_time, true))
.hint(Hint(R.string.sensitivity_hint1))
)
tasks.add(ExamTask(this, R.string.objectives_label, R.string.objectives_howtosave, "objectives")
.option(Option(R.string.objectives_notesettings, false))
.option(Option(R.string.objectives_afterobjective, true))
.option(Option(R.string.objectives_afterchange, true))
.option(Option(R.string.objectives_afterinitialsetup, true))
.hint(Hint(R.string.objectives_hint1))
.hint(Hint(R.string.objectives_hint2))
)
tasks.add(ExamTask(this, R.string.objectives2_label, R.string.objectives_howtosave, "objectives2")
.option(Option(R.string.objectives2_maintenance, true))
.option(Option(R.string.objectives2_internalstorage, true))
.option(Option(R.string.objectives2_cloud, true))
.option(Option(R.string.objectives2_easyrestore, false))
.hint(Hint(R.string.objectives_hint1))
.hint(Hint(R.string.objectives_hint2))
)
tasks.add(ExamTask(this, R.string.update_label, R.string.blank, "update")
.option(Option(R.string.update_git, true))
.option(Option(R.string.update_askfriend, false))
.option(Option(R.string.update_keys, true))
.option(Option(R.string.update_asap, true))
.hint(Hint(R.string.update_hint1))
)
tasks.add(ExamTask(this, R.string.troubleshooting_label, R.string.troubleshooting_wheretoask, "troubleshooting")
.option(Option(R.string.troubleshooting_fb, true))
.option(Option(R.string.troubleshooting_wiki, true))
.option(Option(R.string.troubleshooting_gitter, true))
.option(Option(R.string.troubleshooting_yourendo, false))
.hint(Hint(R.string.troubleshooting_hint1))
.hint(Hint(R.string.troubleshooting_hint2))
.hint(Hint(R.string.troubleshooting_hint3))
)
tasks.add(ExamTask(this, R.string.wrongcarbs_label, R.string.wrongcarbs_whattodo, "wrongcarbs")
.option(Option(R.string.wrongcarbs_addinsulin, false))
.option(Option(R.string.wrongcarbs_treatmentstab, true))
.option(Option(R.string.wrongcarbs_donothing, false))
.option(Option(R.string.wrongcarbs_bolus, false))
)
tasks.add(ExamTask(this, R.string.wronginsulin_label, R.string.wronginsulin_whattodo, "wronginsulin")
.option(Option(R.string.wronginsulin_careportal, false))
.option(Option(R.string.wronginsulin_compare, true))
.option(Option(R.string.wronginsulin_prime, true))
.option(Option(R.string.wrongcarbs_donothing, false))
)
tasks.add(ExamTask(this, R.string.iob_label, R.string.blank, "iob")
.option(Option(R.string.iob_value, true))
.option(Option(R.string.iob_hightemp, false))
.option(Option(R.string.iob_negiob, true))
.option(Option(R.string.iob_posiob, true))
)
tasks.add(ExamTask(this, R.string.breadgrams_label, R.string.blank, "breadgrams")
.option(Option(R.string.breadgrams_grams, true))
.option(Option(R.string.breadgrams_exchange, false))
.option(Option(R.string.breadgrams_decay, true))
.option(Option(R.string.breadgrams_calc, true))
.hint(Hint(R.string.breadgrams_hint1))
)
tasks.add(ExamTask(this, R.string.extendedcarbs_label, R.string.extendedcarbs_handling, "extendedcarbs")
.option(Option(R.string.extendedcarbs_future, true))
.option(Option(R.string.extendedcarbs_free, false))
.option(Option(R.string.extendedcarbs_fat, true))
.option(Option(R.string.extendedcarbs_rescue, false))
.hint(Hint(R.string.extendedcarbs_hint1))
)
tasks.add(ExamTask(this, R.string.nsclient_label, R.string.nsclient_howcanyou, "nsclient")
.option(Option(R.string.nsclient_nightscout, true))
.option(Option(R.string.nsclient_dexcomfollow, true))
.option(Option(R.string.nsclient_data, true))
.option(Option(R.string.nsclient_fullcontrol, false))
.hint(Hint(R.string.nsclient_hint1))
)
tasks.add(ExamTask(this, R.string.other_medication_label, R.string.other_medication_text, "otherMedicationWarning")
.option(Option(R.string.yes, true))
.option(Option(R.string.no, false))
)
for (task in tasks) (task as ExamTask).options.shuffle()
for (task in tasks) {
if (!task.isCompleted()) accomplishedOn = 0
}
}
}

View file

@ -1,61 +0,0 @@
package info.nightscout.androidaps.plugins.constraints.objectives.objectives;
import androidx.fragment.app.FragmentActivity;
import java.util.List;
import javax.inject.Inject;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.constraints.objectives.ObjectivesPlugin;
import info.nightscout.androidaps.plugins.general.nsclient.NSClientPlugin;
import info.nightscout.androidaps.plugins.general.nsclient.services.NSClientService;
import info.nightscout.androidaps.utils.T;
import info.nightscout.androidaps.utils.resources.ResourceHelper;
import info.nightscout.androidaps.utils.sharedPreferences.SP;
public class Objective3 extends Objective {
@Inject SP sp;
@Inject ObjectivesPlugin objectivesPlugin;
@Inject ResourceHelper resourceHelper;
@Inject NSClientPlugin nsClientPlugin;
private final int MANUAL_ENACTS_NEEDED = 20;
@Inject
public Objective3(HasAndroidInjector injector) {
super(injector, "openloop", R.string.objectives_openloop_objective, R.string.objectives_openloop_gate);
// disable option for skipping objectives for now
// hasSpecialInput = true;
}
@Override
protected void setupTasks(List<Task> tasks) {
tasks.add(new MinimumDurationTask(T.days(7).msecs()));
tasks.add(new Task(R.string.objectives_manualenacts) {
@Override
public boolean isCompleted() {
return sp.getInt(R.string.key_ObjectivesmanualEnacts, 0) >= MANUAL_ENACTS_NEEDED;
}
@Override
public String getProgress() {
if (sp.getInt(R.string.key_ObjectivesmanualEnacts, 0) >= MANUAL_ENACTS_NEEDED)
return resourceHelper.gs(R.string.completed_well_done);
else
return sp.getInt(R.string.key_ObjectivesmanualEnacts, 0) + " / " + MANUAL_ENACTS_NEEDED;
}
});
}
@Override
public boolean specialActionEnabled() {
return NSClientService.isConnected && NSClientService.hasWriteAuth;
}
@Override
public void specialAction(FragmentActivity activity, String input) {
objectivesPlugin.completeObjectives(activity, input);
}
}

View file

@ -0,0 +1,41 @@
package info.nightscout.androidaps.plugins.constraints.objectives.objectives
import androidx.fragment.app.FragmentActivity
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.R
import info.nightscout.androidaps.plugins.constraints.objectives.ObjectivesPlugin
import info.nightscout.androidaps.plugins.general.nsclient.NSClientPlugin
import info.nightscout.androidaps.plugins.general.nsclient.services.NSClientService
import info.nightscout.androidaps.utils.T
import javax.inject.Inject
@Suppress("SpellCheckingInspection")
class Objective3 @Inject constructor(injector: HasAndroidInjector) : Objective(injector, "openloop", R.string.objectives_openloop_objective, R.string.objectives_openloop_gate) {
@Inject lateinit var objectivesPlugin: ObjectivesPlugin
@Inject lateinit var nsClientPlugin: NSClientPlugin
init {
tasks.add(MinimumDurationTask(this, T.days(7).msecs()))
tasks.add(object : Task(this, R.string.objectives_manualenacts) {
override fun isCompleted(): Boolean {
return sp.getInt(R.string.key_ObjectivesmanualEnacts, 0) >= MANUAL_ENACTS_NEEDED
}
override val progress: String
get() = if (sp.getInt(R.string.key_ObjectivesmanualEnacts, 0) >= MANUAL_ENACTS_NEEDED) resourceHelper.gs(R.string.completed_well_done) else sp.getInt(R.string.key_ObjectivesmanualEnacts, 0).toString() + " / " + MANUAL_ENACTS_NEEDED
})
}
override fun specialActionEnabled(): Boolean =
NSClientService.isConnected && NSClientService.hasWriteAuth
override fun specialAction(activity: FragmentActivity, input: String) {
objectivesPlugin.completeObjectives(activity, input)
}
companion object {
private const val MANUAL_ENACTS_NEEDED = 20
}
}

View file

@ -1,11 +0,0 @@
package info.nightscout.androidaps.plugins.constraints.objectives.objectives;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.R;
public class Objective4 extends Objective {
public Objective4(HasAndroidInjector injector) {
super(injector, "maxbasal", R.string.objectives_maxbasal_objective, R.string.objectives_maxbasal_gate);
}
}

View file

@ -0,0 +1,7 @@
package info.nightscout.androidaps.plugins.constraints.objectives.objectives
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.R
@Suppress("SpellCheckingInspection")
class Objective4(injector: HasAndroidInjector) : Objective(injector, "maxbasal", R.string.objectives_maxbasal_objective, R.string.objectives_maxbasal_gate)

View file

@ -1,32 +0,0 @@
package info.nightscout.androidaps.plugins.constraints.objectives.objectives;
import java.util.List;
import javax.inject.Inject;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.Constraint;
import info.nightscout.androidaps.plugins.constraints.safety.SafetyPlugin;
import info.nightscout.androidaps.utils.T;
public class Objective5 extends Objective {
@Inject SafetyPlugin safetyPlugin;
public Objective5(HasAndroidInjector injector) {
super(injector, "maxiobzero", R.string.objectives_maxiobzero_objective, R.string.objectives_maxiobzero_gate);
}
@Override
protected void setupTasks(List<Task> tasks) {
tasks.add(new MinimumDurationTask(T.days(5).msecs()));
tasks.add(new Task(R.string.closedmodeenabled) {
@Override
public boolean isCompleted() {
Constraint<Boolean> closedLoopEnabled = new Constraint<>(true);
safetyPlugin.isClosedLoopAllowed(closedLoopEnabled);
return closedLoopEnabled.value();
}
});
}
}

View file

@ -0,0 +1,25 @@
package info.nightscout.androidaps.plugins.constraints.objectives.objectives
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.R
import info.nightscout.androidaps.interfaces.Constraint
import info.nightscout.androidaps.plugins.constraints.safety.SafetyPlugin
import info.nightscout.androidaps.utils.T
import javax.inject.Inject
@Suppress("SpellCheckingInspection")
class Objective5(injector: HasAndroidInjector) : Objective(injector, "maxiobzero", R.string.objectives_maxiobzero_objective, R.string.objectives_maxiobzero_gate) {
@Inject lateinit var safetyPlugin: SafetyPlugin
init {
tasks.add(MinimumDurationTask(this, T.days(5).msecs()))
tasks.add(object : Task(this, R.string.closedmodeenabled) {
override fun isCompleted(): Boolean {
val closedLoopEnabled = Constraint(true)
safetyPlugin.isClosedLoopAllowed(closedLoopEnabled)
return closedLoopEnabled.value()
}
})
}
}

View file

@ -1,30 +0,0 @@
package info.nightscout.androidaps.plugins.constraints.objectives.objectives;
import java.util.List;
import javax.inject.Inject;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
import info.nightscout.androidaps.utils.T;
public class Objective6 extends Objective {
@Inject ConstraintChecker constraintChecker;
public Objective6(HasAndroidInjector injector) {
super(injector, "maxiob", R.string.objectives_maxiob_objective, R.string.objectives_maxiob_gate);
}
@Override
protected void setupTasks(List<Task> tasks) {
tasks.add(new MinimumDurationTask(T.days(1).msecs()));
tasks.add(new Task(R.string.maxiobset) {
@Override
public boolean isCompleted() {
double maxIOB = constraintChecker.getMaxIOBAllowed().value();
return maxIOB > 0;
}
});
}
}

View file

@ -0,0 +1,23 @@
package info.nightscout.androidaps.plugins.constraints.objectives.objectives
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.R
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
import info.nightscout.androidaps.utils.T
import javax.inject.Inject
@Suppress("SpellCheckingInspection")
class Objective6(injector: HasAndroidInjector) : Objective(injector, "maxiob", R.string.objectives_maxiob_objective, R.string.objectives_maxiob_gate) {
@Inject lateinit var constraintChecker: ConstraintChecker
init {
tasks.add(MinimumDurationTask(this, T.days(1).msecs()))
tasks.add(object : Task(this, R.string.maxiobset) {
override fun isCompleted(): Boolean {
val maxIOB = constraintChecker.getMaxIOBAllowed().value()
return maxIOB > 0
}
})
}
}

View file

@ -1,19 +0,0 @@
package info.nightscout.androidaps.plugins.constraints.objectives.objectives;
import java.util.List;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.utils.T;
public class Objective7 extends Objective {
public Objective7(HasAndroidInjector injector) {
super(injector, "autosens", R.string.objectives_autosens_objective, R.string.objectives_autosens_gate);
}
@Override
protected void setupTasks(List<Task> tasks) {
tasks.add(new MinimumDurationTask(T.days(7).msecs()));
}
}

View file

@ -0,0 +1,12 @@
package info.nightscout.androidaps.plugins.constraints.objectives.objectives
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.R
import info.nightscout.androidaps.utils.T
class Objective7(injector: HasAndroidInjector) : Objective(injector, "autosens", R.string.objectives_autosens_objective, R.string.objectives_autosens_gate) {
init {
tasks.add(MinimumDurationTask(this, T.days(7).msecs()))
}
}

View file

@ -1,19 +0,0 @@
package info.nightscout.androidaps.plugins.constraints.objectives.objectives;
import java.util.List;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.utils.T;
public class Objective8 extends Objective {
public Objective8(HasAndroidInjector injector) {
super(injector, "ama", R.string.objectives_ama_objective, 0);
}
@Override
protected void setupTasks(List<Task> tasks) {
tasks.add(new MinimumDurationTask(T.days(28).msecs()));
}
}

View file

@ -0,0 +1,12 @@
package info.nightscout.androidaps.plugins.constraints.objectives.objectives
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.R
import info.nightscout.androidaps.utils.T
class Objective8(injector: HasAndroidInjector) : Objective(injector, "ama", R.string.objectives_ama_objective, 0) {
init {
tasks.add(MinimumDurationTask(this, T.days(28).msecs()))
}
}

View file

@ -1,19 +0,0 @@
package info.nightscout.androidaps.plugins.constraints.objectives.objectives;
import java.util.List;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.utils.T;
public class Objective9 extends Objective {
public Objective9(HasAndroidInjector injector) {
super(injector, "smb", R.string.objectives_smb_objective, R.string.objectives_smb_gate);
}
@Override
protected void setupTasks(List<Task> tasks) {
tasks.add(new MinimumDurationTask(T.days(28).msecs()));
}
}

View file

@ -0,0 +1,12 @@
package info.nightscout.androidaps.plugins.constraints.objectives.objectives
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.R
import info.nightscout.androidaps.utils.T
class Objective9(injector: HasAndroidInjector) : Objective(injector, "smb", R.string.objectives_smb_objective, R.string.objectives_smb_gate) {
init {
tasks.add(MinimumDurationTask(this, T.days(28).msecs()))
}
}