From 599261081be9a2b32c9c0c19771e5030e8e8620a Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Thu, 28 Nov 2019 00:30:22 +0100 Subject: [PATCH] upload local profile to NS --- .../plugins/general/nsclient/NSUpload.java | 15 +++++++++++++++ .../plugins/profile/local/LocalProfilePlugin.kt | 4 +++- app/src/main/res/values/strings.xml | 2 ++ app/src/main/res/xml/pref_nsclientinternal.xml | 5 +++++ 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSUpload.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSUpload.java index bff305a678..582eedb0e7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSUpload.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSUpload.java @@ -510,6 +510,21 @@ public class NSUpload { } } + public static void uploadProfileStore(JSONObject profileStore) { + if (SP.getBoolean(R.string.key_ns_uploadlocalprofile, false)) { + Context context = MainApp.instance().getApplicationContext(); + Bundle bundle = new Bundle(); + bundle.putString("action", "dbAdd"); + bundle.putString("collection", "profile"); + bundle.putString("data", String.valueOf(profileStore)); + Intent intent = new Intent(Intents.ACTION_DATABASE); + intent.putExtras(bundle); + intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); + LocalBroadcastManager.getInstance(context).sendBroadcast(intent); + DbLogger.dbAdd(intent, String.valueOf(profileStore)); + } + } + public static void uploadEvent(String careportalEvent, long time, @Nullable String notes) { Context context = MainApp.instance().getApplicationContext(); Bundle bundle = new Bundle(); 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 49da7b6f8f..c6d1884886 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 @@ -12,6 +12,7 @@ import info.nightscout.androidaps.interfaces.ProfileInterface import info.nightscout.androidaps.logging.L import info.nightscout.androidaps.plugins.bus.RxBus 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.SP @@ -89,6 +90,7 @@ 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) } } @Synchronized @@ -167,7 +169,7 @@ object LocalProfilePlugin : PluginBase(PluginDescription() createAndStoreConvertedProfile() } - private fun isExistingName(name: String?) : Boolean { + private fun isExistingName(name: String?): Boolean { for (p in profiles) { if (p.name == name) return true } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7c8957c900..5dc900c68f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1639,5 +1639,7 @@ Off No pump selected Select units you want to display values in + ns_uploadlocalprofile + Upload local profile changes to NS diff --git a/app/src/main/res/xml/pref_nsclientinternal.xml b/app/src/main/res/xml/pref_nsclientinternal.xml index 4f3a3ca239..b27759f627 100644 --- a/app/src/main/res/xml/pref_nsclientinternal.xml +++ b/app/src/main/res/xml/pref_nsclientinternal.xml @@ -25,6 +25,11 @@ android:key="@string/key_ns_logappstartedevent" android:title="@string/ns_logappstartedevent" /> + +