From 4d9088b63e15ed90af23a20ca9d2a67ca37f0d5d Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Wed, 25 Sep 2019 14:33:23 +0200 Subject: [PATCH] objectives: links for another tasks --- .../objectives/ObjectivesFragment.kt | 12 ++- .../activities/ObjectivesExamDialog.kt | 3 +- .../objectives/objectives/Objective.java | 22 +++--- .../objectives/objectives/Objective1.java | 13 ++-- app/src/main/res/values/objectives.xml | 77 +++++++++++++++++++ app/src/main/res/values/strings.xml | 68 ---------------- 6 files changed, 105 insertions(+), 90 deletions(-) create mode 100644 app/src/main/res/values/objectives.xml 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 63f522da8d..ac2bf50cc4 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 @@ -168,10 +168,17 @@ class ObjectivesFragment : Fragment() { holder.progress.removeAllViews() for (task in objective.tasks) { if (task.shouldBeIgnored()) continue + // name val name = TextView(holder.progress.context) name.text = MainApp.gs(task.task) + ":" name.setTextColor(-0x1) holder.progress.addView(name, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT) + // hint + task.hints.forEach { h -> + if (!task.isCompleted) + holder.progress.addView(h.generate(context)) + } + // state val state = TextView(holder.progress.context) state.setTextColor(-0x1) val basicHTML = "%2\$s" @@ -183,13 +190,14 @@ class ObjectivesFragment : Fragment() { state.setOnClickListener { val dialog = ObjectivesExamDialog() val bundle = Bundle() - val position = objective.tasks.indexOf(task) - bundle.putInt("currentTask", position) + val taskPosition = objective.tasks.indexOf(task) + bundle.putInt("currentTask", taskPosition) dialog.arguments = bundle ObjectivesExamDialog.objective = objective fragmentManager?.let { dialog.show(it, "ObjectivesFragment") } } } + // horizontal line val separator = View(holder.progress.context) separator.setBackgroundColor(Color.DKGRAY) holder.progress.addView(separator, LinearLayout.LayoutParams.MATCH_PARENT, 2) 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 1c7c6c7ee1..30ab4b500b 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 @@ -70,8 +70,7 @@ class ObjectivesExamDialog : DialogFragment() { // Hints objectives_exam_hints.removeAllViews() for (h in task.hints) { - val hint: Hint = h as Hint; - objectives_exam_hints.addView(hint.generate(context)) + objectives_exam_hints.addView(h.generate(context)) } // Disabled to objectives_exam_disabledto.text = MainApp.gs(R.string.answerdisabledto, DateUtil.timeString(task.disabledTo)) 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 f58d469fa2..a59a33454d 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 @@ -100,6 +100,7 @@ public abstract class Objective { @StringRes private int task; private Objective objective; + ArrayList hints = new ArrayList<>(); public Task(@StringRes int task) { this.task = task; @@ -119,6 +120,15 @@ public abstract class Objective { return MainApp.gs(isCompleted() ? R.string.completed_well_done : R.string.not_completed_yet); } + Task hint(Hint hint) { + hints.add(hint); + return this; + } + + public ArrayList getHints() { + return hints; + } + public boolean shouldBeIgnored() { return false; } @@ -157,8 +167,7 @@ public abstract class Objective { public class ExamTask extends Task { @StringRes int question; - List hints = new ArrayList<>(); - List options = new ArrayList<>(); + ArrayList