From c0ad12593436aed370ed30079f406e97f2c0f9c1 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sun, 1 Dec 2019 21:59:12 +0100 Subject: [PATCH] warn if profile is not uploadable to NS --- .../profile/local/LocalProfileFragment.kt | 2 +- .../plugins/profile/local/LocalProfilePlugin.kt | 16 ++++++++++++++-- app/src/main/res/values/strings.xml | 1 + 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfileFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfileFragment.kt index 67f9f91817..3b6dbe7315 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfileFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfileFragment.kt @@ -192,7 +192,7 @@ class LocalProfileFragment : Fragment() { if (!LocalProfilePlugin.isValidEditState()) { return@setOnClickListener //Should not happen as saveButton should not be visible if not valid } - LocalProfilePlugin.storeSettings() + LocalProfilePlugin.storeSettings(activity) build() } updateGUI() diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfilePlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfilePlugin.kt index 525bd8847b..e2c8d051ac 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfilePlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfilePlugin.kt @@ -1,5 +1,6 @@ package info.nightscout.androidaps.plugins.profile.local +import android.app.Activity import info.nightscout.androidaps.Constants import info.nightscout.androidaps.MainApp import info.nightscout.androidaps.R @@ -16,6 +17,7 @@ import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions import info.nightscout.androidaps.plugins.general.nsclient.NSUpload import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.DecimalFormatter +import info.nightscout.androidaps.utils.OKDialog import info.nightscout.androidaps.utils.SP import org.json.JSONArray import org.json.JSONException @@ -100,7 +102,7 @@ object LocalProfilePlugin : PluginBase(PluginDescription() } @Synchronized - fun storeSettings() { + fun storeSettings(activity: Activity? = null) { for (i in 0 until numOfProfiles) { profiles[i].run { val LOCAL_PROFILE_NUMBERED = LOCAL_PROFILE + "_" + i + "_" @@ -121,7 +123,17 @@ object LocalProfilePlugin : PluginBase(PluginDescription() if (L.isEnabled(L.PROFILE)) log.debug("Storing settings: " + rawProfile?.data.toString()) RxBus.send(EventProfileStoreChanged()) - rawProfile?.let { NSUpload.uploadProfileStore(it.data) } + var namesOK = true + profiles.forEach { + val name = it.name ?: "." + if (name.contains(".")) namesOK = false + } + if (namesOK) + rawProfile?.let { NSUpload.uploadProfileStore(it.data) } + else + activity?.let { + OKDialog.show(it,"", MainApp.gs(R.string.profilenamecontainsdot), null) + } } @Synchronized diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 83319382ad..5353bdedd2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1657,5 +1657,6 @@ Save or reset current changes first Delete current profile? Create new local profile from this profile switch? + Profile name contains dots.\nThis is not supported by NS.\nProfile is not uploaded to NS.