From 8cc51abae91e298031f16c78db965a780b9c8402 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 21 Apr 2020 10:52:40 +0200 Subject: [PATCH] allow start of objective when all previous are finished --- .../plugins/constraints/objectives/ObjectivesFragment.kt | 2 +- .../plugins/constraints/objectives/ObjectivesPlugin.kt | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) 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 651fe0c4ac..d891a89dda 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 @@ -161,7 +161,7 @@ class ObjectivesFragment : DaggerFragment() { holder.accomplished.visibility = View.GONE holder.unFinish.visibility = View.GONE holder.unStart.visibility = View.GONE - if (position == 0 || objectivesPlugin.objectives[position - 1].isAccomplished) + if (position == 0 || objectivesPlugin.allPriorAccomplished(position)) holder.start.visibility = View.VISIBLE else holder.start.visibility = View.GONE diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPlugin.kt index a5eb85a582..209a74f44a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPlugin.kt @@ -144,6 +144,14 @@ class ObjectivesPlugin @Inject constructor( } } + fun allPriorAccomplished(position: Int) : Boolean { + var accomplished = true + for (i in 0 until position) { + accomplished = accomplished && objectives[i].isAccomplished + } + return accomplished + } + /** * Constraints interface */