From 2ce7ba3fc40db4a0d6eb747eeb8e8ecb1bf19fdd Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sun, 1 Sep 2019 18:09:52 +0200 Subject: [PATCH 1/9] remove tidepool from plugin list --- app/src/main/java/info/nightscout/androidaps/MainApp.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java index f2edd23882..3830376981 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainApp.java +++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java @@ -192,7 +192,8 @@ public class MainApp extends Application { if (Config.PUMPDRIVERS) pluginsList.add(LocalInsightPlugin.getPlugin()); pluginsList.add(CareportalPlugin.getPlugin()); if (Config.PUMPDRIVERS) pluginsList.add(ComboPlugin.getPlugin()); - if (Config.PUMPDRIVERS && engineeringMode) pluginsList.add(MedtronicPumpPlugin.getPlugin()); + if (Config.PUMPDRIVERS && engineeringMode) + pluginsList.add(MedtronicPumpPlugin.getPlugin()); if (Config.MDI) pluginsList.add(MDIPlugin.getPlugin()); pluginsList.add(VirtualPumpPlugin.getPlugin()); if (Config.APS) pluginsList.add(LoopPlugin.getPlugin()); @@ -223,8 +224,7 @@ public class MainApp extends Application { pluginsList.add(StatuslinePlugin.initPlugin(this)); pluginsList.add(PersistentNotificationPlugin.getPlugin()); pluginsList.add(NSClientPlugin.getPlugin()); - if (engineeringMode) - pluginsList.add(TidepoolPlugin.INSTANCE); +// if (engineeringMode) pluginsList.add(TidepoolPlugin.INSTANCE); pluginsList.add(MaintenancePlugin.initPlugin(this)); if (engineeringMode) pluginsList.add(AutomationPlugin.INSTANCE); @@ -453,7 +453,7 @@ public class MainApp extends Application { unregisterReceiver(btReceiver); } - if (timeDateOrTZChangeReceiver!=null) { + if (timeDateOrTZChangeReceiver != null) { unregisterReceiver(timeDateOrTZChangeReceiver); } From 99b5e1e9d55cea1ab6c88ad52c6e2d687fdedb5d Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 2 Sep 2019 08:44:21 +0200 Subject: [PATCH 2/9] fix NPE --- .../info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.java index 0425190723..d3f6cc8212 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.java @@ -291,7 +291,7 @@ public class LoopPlugin extends PluginBase { Profile profile = ProfileFunctions.getInstance().getProfile(); - if (!ProfileFunctions.getInstance().isProfileValid("Loop")) { + if (profile == null || !ProfileFunctions.getInstance().isProfileValid("Loop")) { if (L.isEnabled(L.APS)) log.debug(MainApp.gs(R.string.noprofileselected)); RxBus.INSTANCE.send(new EventLoopSetLastRunGui(MainApp.gs(R.string.noprofileselected))); From 11ca21ebbd27093d8b9b9ad723b3e65047c3ddc9 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 2 Sep 2019 08:55:08 +0200 Subject: [PATCH 3/9] automation without engineering mode --- app/src/main/java/info/nightscout/androidaps/MainApp.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java index f2edd23882..303e9ee4c9 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainApp.java +++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java @@ -226,8 +226,7 @@ public class MainApp extends Application { if (engineeringMode) pluginsList.add(TidepoolPlugin.INSTANCE); pluginsList.add(MaintenancePlugin.initPlugin(this)); - if (engineeringMode) - pluginsList.add(AutomationPlugin.INSTANCE); + pluginsList.add(AutomationPlugin.INSTANCE); pluginsList.add(ConfigBuilderPlugin.getPlugin()); From c848095060ab66464de036708fcc866400b93840 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Wed, 4 Sep 2019 11:30:55 +0200 Subject: [PATCH 4/9] add automation TT action TextWatcher --- .../actions/ActionStartTempTarget.java | 2 +- .../automation/elements/InputTempTarget.java | 20 ++++++++++++++++++- .../automation/elements/LabelWithElement.java | 5 +++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStartTempTarget.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStartTempTarget.java index 05d06f0b3a..659bb508eb 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStartTempTarget.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStartTempTarget.java @@ -71,7 +71,7 @@ public class ActionStartTempTarget extends Action { int unitResId = value.getUnits().equals(Constants.MGDL) ? R.string.mgdl : R.string.mmol; new LayoutBuilder() - .add(new LabelWithElement(MainApp.gs(R.string.careportal_temporarytarget), MainApp.gs(unitResId), value)) + .add(new LabelWithElement(MainApp.gs(R.string.careportal_temporarytarget) + " [" + MainApp.gs(unitResId) + "]", "", value)) .add(new LabelWithElement(MainApp.gs(R.string.careportal_newnstreatment_duration_min_label), "", duration)) .build(root); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTempTarget.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTempTarget.java index 8175c496a5..509eb05853 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTempTarget.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTempTarget.java @@ -1,5 +1,7 @@ package info.nightscout.androidaps.plugins.general.automation.elements; +import android.text.Editable; +import android.text.TextWatcher; import android.widget.LinearLayout; import java.text.DecimalFormat; @@ -17,6 +19,22 @@ public class InputTempTarget extends Element { private double step; private DecimalFormat decimalFormat; + final TextWatcher textWatcher = new TextWatcher() { + @Override + public void afterTextChanged(Editable s) { + value = Math.max(minValue, value); + value = Math.min(maxValue, value); + } + + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + } + }; + public InputTempTarget() { super(); setUnits(ProfileFunctions.getInstance().getProfileUnits()); @@ -36,7 +54,7 @@ public class InputTempTarget extends Element { @Override public void addToLayout(LinearLayout root) { NumberPicker numberPicker = new NumberPicker(root.getContext(), null); - numberPicker.setParams(value, minValue, maxValue, step, decimalFormat, true, null, null); + numberPicker.setParams(value, minValue, maxValue, step, decimalFormat, true, null, textWatcher); numberPicker.setOnValueChangedListener(value -> this.value = value); root.addView(numberPicker); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/LabelWithElement.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/LabelWithElement.java index 2531d56e6c..145d8c2d2c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/LabelWithElement.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/LabelWithElement.java @@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.general.automation.elements; import android.graphics.Typeface; import android.view.ViewGroup; import android.widget.LinearLayout; +import android.widget.TableLayout; import android.widget.TextView; import info.nightscout.androidaps.MainApp; @@ -37,6 +38,10 @@ public class LabelWithElement extends Element { textViewPre.setTypeface(textViewPre.getTypeface(), Typeface.BOLD); layout.addView(textViewPre); + TextView spacer = new TextView(root.getContext()); + spacer.setLayoutParams(new TableLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 1f)); + layout.addView(spacer); + // add element to layout element.addToLayout(layout); From d452d21c93861b3f7c5b62eb11c1e036c9076fff Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Wed, 4 Sep 2019 20:21:27 +0200 Subject: [PATCH 5/9] fix BG Difference in MGDL --- .../plugins/general/automation/triggers/TriggerDelta.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerDelta.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerDelta.java index 0b9edf148a..9e47ae0e69 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerDelta.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerDelta.java @@ -68,7 +68,7 @@ public class TriggerDelta extends Trigger { if (units.equals(Constants.MMOL)) value = new InputDelta(0, -MMOL_MAX, MMOL_MAX, 0.1d, new DecimalFormat("0.1"), DeltaType.DELTA); else - value = new InputDelta(0, -MGDL_MAX, MGDL_MAX, 0.1d, new DecimalFormat("1"), DeltaType.DELTA); + value = new InputDelta(0, -MGDL_MAX, MGDL_MAX, 1d, new DecimalFormat("1"), DeltaType.DELTA); } From 139455747e1d78fd85845831411c41549903e450 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Wed, 4 Sep 2019 21:00:00 +0200 Subject: [PATCH 6/9] fix copy constructors in automation plugin --- .../plugins/general/automation/elements/InputDouble.java | 4 ++-- .../general/automation/elements/InputDuration.java | 5 +++++ .../general/automation/elements/InputTempTarget.java | 2 +- .../general/automation/triggers/TriggerBolusAgo.java | 8 ++------ .../plugins/general/automation/triggers/TriggerCOB.java | 6 ++---- .../plugins/general/automation/triggers/TriggerDelta.java | 7 ++++--- .../general/automation/triggers/TriggerLocation.java | 7 ++++--- 7 files changed, 20 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDouble.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDouble.java index f8464e7ee0..518b00f5b4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDouble.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDouble.java @@ -25,8 +25,8 @@ public class InputDouble extends Element { }; private double value; - double minValue; - double maxValue; + private double minValue; + private double maxValue; private double step; private DecimalFormat decimalFormat; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDuration.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDuration.java index a35fe4a4ad..aa19896471 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDuration.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDuration.java @@ -20,6 +20,11 @@ public class InputDuration extends Element { this.value = value; } + public InputDuration(InputDuration another) { + unit = another.unit; + value = another.value; + } + @Override public void addToLayout(LinearLayout root) { NumberPicker numberPicker = new NumberPicker(root.getContext(), null); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTempTarget.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTempTarget.java index 509eb05853..4906e79add 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTempTarget.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTempTarget.java @@ -19,7 +19,7 @@ public class InputTempTarget extends Element { private double step; private DecimalFormat decimalFormat; - final TextWatcher textWatcher = new TextWatcher() { + private final TextWatcher textWatcher = new TextWatcher() { @Override public void afterTextChanged(Editable s) { value = Math.max(minValue, value); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBolusAgo.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBolusAgo.java index e1792d8bd3..0ad9f75ab2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBolusAgo.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBolusAgo.java @@ -11,8 +11,6 @@ import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.text.DecimalFormat; - import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.logging.L; @@ -28,9 +26,7 @@ import info.nightscout.androidaps.utils.T; public class TriggerBolusAgo extends Trigger { private static Logger log = LoggerFactory.getLogger(L.AUTOMATION); - private final double step = 1; - private DecimalFormat decimalFormat = new DecimalFormat("1"); - public InputDuration minutesAgo = new InputDuration(0, InputDuration.TimeUnit.MINUTES); + private InputDuration minutesAgo = new InputDuration(0, InputDuration.TimeUnit.MINUTES); private Comparator comparator = new Comparator(); public TriggerBolusAgo() { @@ -39,7 +35,7 @@ public class TriggerBolusAgo extends Trigger { private TriggerBolusAgo(TriggerBolusAgo triggerBolusAgo) { super(); - minutesAgo = new InputDuration(triggerBolusAgo.minutesAgo.getMinutes(), InputDuration.TimeUnit.MINUTES); + minutesAgo = new InputDuration(triggerBolusAgo.minutesAgo); lastRun = triggerBolusAgo.lastRun; comparator = new Comparator(triggerBolusAgo.comparator); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerCOB.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerCOB.java index a794851236..4ddeb4299a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerCOB.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerCOB.java @@ -32,10 +32,8 @@ import info.nightscout.androidaps.utils.T; public class TriggerCOB extends Trigger { private static Logger log = LoggerFactory.getLogger(L.AUTOMATION); private final int minValue = 0; - private final int maxValue = (int) (SP.getInt(R.string.key_treatmentssafety_maxcarbs, 48)); - private final double step = 1; - private DecimalFormat decimalFormat = new DecimalFormat("1"); - private InputDouble value = new InputDouble(0, (double) minValue, (double) maxValue, step, decimalFormat); + private final int maxValue = SP.getInt(R.string.key_treatmentssafety_maxcarbs, 48); + private InputDouble value = new InputDouble(0, (double) minValue, (double) maxValue, 1, new DecimalFormat("1")); private Comparator comparator = new Comparator(); public TriggerCOB() { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerDelta.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerDelta.java index 9e47ae0e69..a3939a60b7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerDelta.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerDelta.java @@ -51,10 +51,11 @@ public class TriggerDelta extends Trigger { private TriggerDelta(TriggerDelta triggerDelta) { super(); - this.units = ProfileFunctions.getInstance().getProfileUnits(); - initializer(); - value = triggerDelta.value; lastRun = triggerDelta.lastRun; + this.units = triggerDelta.units; + deltaType = triggerDelta.deltaType; + value = new InputDelta(triggerDelta.value); + comparator = new Comparator(triggerDelta.comparator); } public double getValue() { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerLocation.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerLocation.java index d2be0ffa1f..4772d29112 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerLocation.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerLocation.java @@ -51,10 +51,11 @@ public class TriggerLocation extends Trigger { private TriggerLocation(TriggerLocation triggerLocation) { super(); - latitude = new InputDouble(triggerLocation.latitude.getValue(), -90d, +90d, 0.00001d, new DecimalFormat("0.00000")); - longitude = new InputDouble(triggerLocation.longitude.getValue(), -180d, +180d, 0.00001d, new DecimalFormat("0.00000")); - distance = new InputDouble(200d, 0, 100000, 10d, new DecimalFormat("0")); + latitude = new InputDouble(triggerLocation.latitude); + longitude = new InputDouble(triggerLocation.longitude); + distance = new InputDouble(triggerLocation.distance); lastRun = triggerLocation.lastRun; + name = triggerLocation.name; } @Override From 07fd0654caa0b9edd7bc32da41e03ab3cda3c793 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Wed, 4 Sep 2019 22:11:45 +0200 Subject: [PATCH 7/9] remove doubled notifyDatasetChanged --- .../plugins/general/automation/EventListAdapter.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/EventListAdapter.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/EventListAdapter.java index b4c6fb1f11..ec1cac23d6 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/EventListAdapter.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/EventListAdapter.java @@ -84,14 +84,13 @@ class EventListAdapter extends RecyclerView.Adapter // enabled event holder.enabled.setOnCheckedChangeListener((buttonView, isChecked) -> { event.setEnabled(isChecked); - notifyDataSetChanged(); RxBus.INSTANCE.send(new EventAutomationDataChanged()); }); // remove event holder.iconTrash.setOnClickListener(v -> { mEventList.remove(event); - notifyDataSetChanged(); + RxBus.INSTANCE.send(new EventAutomationDataChanged()); }); // edit event From 91ebc11d9bf55463bc618db4a188536011982423 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Thu, 5 Sep 2019 20:26:23 +0200 Subject: [PATCH 8/9] ObjectivesExamDialog fine tunning --- .../objectives/ObjectivesFragment.kt | 36 +++++++- .../activities/ObjectivesExamDialog.kt | 69 ++++++++++++-- .../events/EventObjectivesUpdateGui.kt | 5 + .../objectives/objectives/Objective.java | 16 ++++ .../objectives/objectives/Objective2.java | 28 ++++-- .../res/layout/objectives_exam_fragment.xml | 92 ++++++++++++++++--- app/src/main/res/values/exam.xml | 26 ++++-- app/src/main/res/values/strings.xml | 4 + 8 files changed, 235 insertions(+), 41 deletions(-) create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/events/EventObjectivesUpdateGui.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesFragment.kt index 89840ae9f3..b0fb26c95a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesFragment.kt @@ -18,17 +18,23 @@ import androidx.recyclerview.widget.LinearSmoothScroller import androidx.recyclerview.widget.RecyclerView import info.nightscout.androidaps.MainApp import info.nightscout.androidaps.R +import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.plugins.constraints.objectives.activities.ObjectivesExamDialog -import info.nightscout.androidaps.plugins.constraints.objectives.objectives.Objective +import info.nightscout.androidaps.plugins.constraints.objectives.events.EventObjectivesUpdateGui import info.nightscout.androidaps.plugins.constraints.objectives.objectives.Objective.ExamTask import info.nightscout.androidaps.utils.DateUtil +import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.HtmlHelper +import io.reactivex.android.schedulers.AndroidSchedulers +import io.reactivex.disposables.CompositeDisposable import kotlinx.android.synthetic.main.objectives_fragment.* class ObjectivesFragment : Fragment() { private val objectivesAdapter = ObjectivesAdapter() private val handler = Handler(Looper.getMainLooper()) + private var disposable: CompositeDisposable = CompositeDisposable() + private val objectiveUpdater = object : Runnable { override fun run() { handler.postDelayed(this, (60 * 1000).toLong()) @@ -56,6 +62,26 @@ class ObjectivesFragment : Fragment() { startUpdateTimer() } + @Synchronized + override fun onResume() { + super.onResume() + disposable.add(RxBus + .toObservable(EventObjectivesUpdateGui::class.java) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe({ + objectives_recyclerview.adapter?.notifyDataSetChanged() + }, { + FabricPrivacy.logException(it) + }) + ) + } + + @Synchronized + override fun onPause() { + super.onPause() + disposable.clear() + } + @Synchronized override fun onDestroyView() { super.onDestroyView() @@ -152,9 +178,13 @@ class ObjectivesFragment : Fragment() { state.text = HtmlHelper.fromHtml(formattedHTML) state.gravity = Gravity.END holder.progress.addView(state, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT) - if (task is ExamTask) { + if (task is ExamTask) { state.setOnClickListener { - val dialog = ObjectivesExamDialog(); + val dialog = ObjectivesExamDialog() + val bundle = Bundle() + val position = objective.tasks.indexOf(task) + bundle.putInt("currentTask", position) + dialog.arguments = bundle ObjectivesExamDialog.objective = objective fragmentManager?.let { dialog.show(it, "ObjectivesFragment") } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/activities/ObjectivesExamDialog.kt b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/activities/ObjectivesExamDialog.kt index b28b2b221e..a0d6f6cedf 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/activities/ObjectivesExamDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/activities/ObjectivesExamDialog.kt @@ -5,15 +5,23 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.fragment.app.DialogFragment +import info.nightscout.androidaps.MainApp import info.nightscout.androidaps.R +import info.nightscout.androidaps.plugins.bus.RxBus +import info.nightscout.androidaps.plugins.constraints.objectives.events.EventObjectivesUpdateGui import info.nightscout.androidaps.plugins.constraints.objectives.objectives.Objective import info.nightscout.androidaps.plugins.constraints.objectives.objectives.Objective.* +import info.nightscout.androidaps.utils.DateUtil +import info.nightscout.androidaps.utils.OKDialog +import info.nightscout.androidaps.utils.T +import info.nightscout.androidaps.utils.ToastUtils import kotlinx.android.synthetic.main.objectives_exam_fragment.* class ObjectivesExamDialog : DialogFragment() { companion object { var objective: Objective? = null } + var currentTask = 0 override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, @@ -23,20 +31,31 @@ class ObjectivesExamDialog : DialogFragment() { currentTask = bundle.getInt("currentTask", 0) } - dialog.setCanceledOnTouchOutside(false) return inflater.inflate(R.layout.objectives_exam_fragment, container, false) } + override fun onStart() { + super.onStart() + dialog.setCanceledOnTouchOutside(false) + dialog.window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); + } + override fun onResume() { super.onResume() updateGui() } + override fun onSaveInstanceState(bundle: Bundle) { + super.onSaveInstanceState(bundle) + bundle.putInt("currentTask", currentTask) + } + fun updateGui() { objective?.let { objective -> val task: ExamTask = objective.tasks[currentTask] as ExamTask objectives_exam_name.setText(task.task) objectives_exam_question.setText(task.question) + // Options objectives_exam_options.removeAllViews() for (o in task.options) { val option: Option = o as Option; @@ -48,11 +67,17 @@ class ObjectivesExamDialog : DialogFragment() { } objectives_exam_options.addView(cb) } + // Hints objectives_exam_hints.removeAllViews() for (h in task.hints) { val hint: Hint = h as Hint; objectives_exam_hints.addView(hint.generate(context)) } + // Disabled to + objectives_exam_disabledto.text = MainApp.gs(R.string.answerdisabledto, DateUtil.timeString(task.disabledTo)) + objectives_exam_disabledto.visibility = if (task.isEnabledAnswer) View.GONE else View.VISIBLE + // Buttons + objectives_exam_verify.isEnabled = !task.answered && task.isEnabledAnswer objectives_exam_verify.setOnClickListener { var result = true for (o in task.options) { @@ -60,18 +85,48 @@ class ObjectivesExamDialog : DialogFragment() { result = result && option.evaluate() } task.setAnswered(result); + if (!result) { + task.disabledTo = DateUtil.now() + T.hours(1).msecs() + ToastUtils.showToastInUiThread(context, R.string.wronganswer) + } else task.disabledTo = 0 updateGui() + RxBus.send(EventObjectivesUpdateGui()) } - cancel.setOnClickListener { dismiss() } + close.setOnClickListener { dismiss() } objectives_exam_reset.setOnClickListener { task.answered = false + //task.disabledTo = 0 updateGui() + RxBus.send(EventObjectivesUpdateGui()) + } + objectives_back_button.isEnabled = currentTask != 0 + objectives_back_button.setOnClickListener { + currentTask-- + updateGui() + } + objectives_next_button.isEnabled = currentTask != objective.tasks.size - 1 + objectives_next_button.setOnClickListener { + currentTask++ + updateGui() + } + + objectives_next_unanswered_button.isEnabled = !objective.isCompleted + objectives_next_unanswered_button.setOnClickListener { + for (i in (currentTask + 1)..(objective.tasks.size - 1)) { + if (!objective.tasks[i].isCompleted) { + currentTask = i + updateGui() + return@setOnClickListener + } + } + for (i in 0..currentTask) { + if (!objective.tasks[i].isCompleted) { + currentTask = i + updateGui() + return@setOnClickListener + } + } } } } - - override fun onSaveInstanceState(bundle: Bundle) { - super.onSaveInstanceState(bundle) - bundle.putInt("currentTask", currentTask) - } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/events/EventObjectivesUpdateGui.kt b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/events/EventObjectivesUpdateGui.kt new file mode 100644 index 0000000000..fd59db7d9f --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/events/EventObjectivesUpdateGui.kt @@ -0,0 +1,5 @@ +package info.nightscout.androidaps.plugins.constraints.objectives.events + +import info.nightscout.androidaps.events.EventUpdateGui + +class EventObjectivesUpdateGui : EventUpdateGui() \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective.java b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective.java index 633e4caf5e..916cfa10be 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective.java @@ -14,6 +14,7 @@ import java.util.List; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; +import info.nightscout.androidaps.utils.DateUtil; import info.nightscout.androidaps.utils.SP; import info.nightscout.androidaps.utils.T; @@ -160,12 +161,27 @@ public abstract class Objective { List options = new ArrayList<>(); private 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) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective2.java b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective2.java index c02ebfe3dd..234fffb266 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective2.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective2.java @@ -3,9 +3,6 @@ package info.nightscout.androidaps.plugins.constraints.objectives.objectives; import java.util.List; import info.nightscout.androidaps.R; -import info.nightscout.androidaps.interfaces.PluginType; -import info.nightscout.androidaps.plugins.general.actions.ActionsPlugin; -import info.nightscout.androidaps.utils.SP; public class Objective2 extends Objective { @@ -16,12 +13,25 @@ public class Objective2 extends Objective { @Override protected void setupTasks(List tasks) { - tasks.add(new ExamTask(R.string.meaningofdia, R.string.whatmeansdia,"dia") - .option(new Option(R.string.minimumis3h, false)) - .option(new Option(R.string.minimumis5h, true)) - .option(new Option(R.string.meaningisequaltodiapump, false)) - .option(new Option(R.string.valuemustbedetermined, true)) - .hint(new Hint(R.string.diahint1)) + tasks.add(new ExamTask(R.string.dia_meaningofdia, R.string.dia_whatmeansdia,"dia") + .option(new Option(R.string.dia_minimumis3h, false)) + .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.hypott, R.string.hypott_whenhypott,"hypott") + .option(new Option(R.string.hypott_goinglow, true)) + .option(new Option(R.string.hypott_havinglow, true)) + .option(new Option(R.string.hypott_notlowanymorebutrising, false)) + .option(new Option(R.string.hypott_havehadalowbg, false)) + .hint(new Hint(R.string.hypott_hint1)) + ); + tasks.add(new ExamTask(R.string.offlineprofile, R.string.offlineprofile_whatprofile,"offlineprofile") + .option(new Option(R.string.localprofile, true)) + .option(new Option(R.string.nsprofile, false)) + .option(new Option(R.string.offlineprofile_nsprofile, true)) + .hint(new Hint(R.string.offlineprofile_hint1)) ); } } diff --git a/app/src/main/res/layout/objectives_exam_fragment.xml b/app/src/main/res/layout/objectives_exam_fragment.xml index 06283eee19..df432cc5d2 100644 --- a/app/src/main/res/layout/objectives_exam_fragment.xml +++ b/app/src/main/res/layout/objectives_exam_fragment.xml @@ -4,12 +4,12 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - android:padding="15dp" tools:context=".plugins.constraints.objectives.activities.ObjectivesExamDialog"> + android:layout_height="wrap_content" + android:layout_margin="10dp"> - - + tools:layout_editor_absoluteX="3dp" /> - -