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 b0fb26c95a..63f522da8d 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
@@ -25,6 +25,7 @@ import info.nightscout.androidaps.plugins.constraints.objectives.objectives.Obje
import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.HtmlHelper
+import info.nightscout.androidaps.utils.SP
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import kotlinx.android.synthetic.main.objectives_fragment.*
@@ -219,6 +220,11 @@ class ObjectivesFragment : Fragment() {
scrollToCurrentObjective()
}
if (objective.hasSpecialInput && !objective.isAccomplished && objective.isStarted) {
+ // generate random request code if none exists
+ val request = SP.getString(R.string.key_objectives_request_code, String.format("%1$05d", (Math.random() * 99999).toInt()))
+ SP.putString(R.string.key_objectives_request_code, request)
+ holder.requestCode.text = MainApp.gs(R.string.requestcode, request)
+ holder.requestCode.visibility = View.VISIBLE
holder.enterButton.visibility = View.VISIBLE
holder.input.visibility = View.VISIBLE
holder.inputHint.visibility = View.VISIBLE
@@ -231,6 +237,7 @@ class ObjectivesFragment : Fragment() {
holder.enterButton.visibility = View.GONE
holder.input.visibility = View.GONE
holder.inputHint.visibility = View.GONE
+ holder.requestCode.visibility = View.GONE
}
}
@@ -251,6 +258,7 @@ class ObjectivesFragment : Fragment() {
val inputHint: TextView = itemView.findViewById(R.id.objective_inputhint)
val input: EditText = itemView.findViewById(R.id.objective_input)
val enterButton: Button = itemView.findViewById(R.id.objective_enterbutton)
+ val requestCode: TextView = itemView.findViewById(R.id.objective_requestcode)
}
}
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 86a0098bb1..dcd9dd31d1 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
@@ -102,9 +102,10 @@ object ObjectivesPlugin : PluginBase(PluginDescription()
}
fun completeObjectives(activity: Activity, request: String) {
+ val requestCode = SP.getString(R.string.key_objectives_request_code, "")
var url = SP.getString(R.string.key_nsclientinternal_url, "").toLowerCase()
if (!url.endsWith("\"")) url = "$url/"
- val hashNS = Hashing.sha1().hashString(url + BuildConfig.APPLICATION_ID, Charsets.UTF_8).toString()
+ val hashNS = Hashing.sha1().hashString(url + BuildConfig.APPLICATION_ID + "/" + requestCode, Charsets.UTF_8).toString()
if (request.equals(hashNS.substring(0, 10), ignoreCase = true)) {
SP.putLong("Objectives_" + "openloop" + "_started", DateUtil.now())
SP.putLong("Objectives_" + "openloop" + "_accomplished", DateUtil.now())
diff --git a/app/src/main/res/layout/objectives_item.xml b/app/src/main/res/layout/objectives_item.xml
index 42ea14741e..76adaeb015 100644
--- a/app/src/main/res/layout/objectives_item.xml
+++ b/app/src/main/res/layout/objectives_item.xml
@@ -80,6 +80,12 @@
android:layout_height="wrap_content"
android:text="@string/enter_code_obtained_from_developers_to_bypass_the_rest_of_objectives" />
+
+
Wrong answer!
Next unfinished
Close
+ objectives_request_code
+ Request code: %1$s
- %1$d day