From 17d71d218b4f623f75a5cba4efbcba33f24a45d8 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Thu, 11 Jun 2020 14:55:29 +0200 Subject: [PATCH] allow RandomBg upload --- .../androidaps/plugins/source/RandomBgPlugin.kt | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/source/RandomBgPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/source/RandomBgPlugin.kt index 763d5a7fb4..12af6cfe04 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/source/RandomBgPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/source/RandomBgPlugin.kt @@ -12,12 +12,14 @@ import info.nightscout.androidaps.interfaces.PluginDescription import info.nightscout.androidaps.interfaces.PluginType import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag +import info.nightscout.androidaps.plugins.general.nsclient.NSUpload import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.T import info.nightscout.androidaps.utils.buildHelper.BuildHelper import info.nightscout.androidaps.utils.extensions.isRunningTest import info.nightscout.androidaps.utils.resources.ResourceHelper +import info.nightscout.androidaps.utils.sharedPreferences.SP import java.util.* import javax.inject.Inject import javax.inject.Singleton @@ -29,13 +31,14 @@ class RandomBgPlugin @Inject constructor( injector: HasAndroidInjector, resourceHelper: ResourceHelper, aapsLogger: AAPSLogger, - private val virtualPumpPlugin: VirtualPumpPlugin, - private val buildHelper: BuildHelper + private val sp: SP, + private val nsUpload: NSUpload ) : PluginBase(PluginDescription() .mainType(PluginType.BGSOURCE) .fragmentClass(BGSourceFragment::class.java.name) .pluginName(R.string.randombg) .shortName(R.string.randombg_short) + .preferencesId(R.xml.pref_bgsource) .description(R.string.description_source_randombg), aapsLogger, resourceHelper, injector ), BgSourceInterface { @@ -85,7 +88,12 @@ class RandomBgPlugin @Inject constructor( bgReading.value = bgMgdl bgReading.date = DateUtil.now() bgReading.raw = bgMgdl - MainApp.getDbHelper().createIfNotExists(bgReading, "RandomBG") + if (MainApp.getDbHelper().createIfNotExists(bgReading, "RandomBG")) { + if (sp.getBoolean(R.string.key_dexcomg5_nsupload, false)) + nsUpload.uploadBg(bgReading, "AndroidAPS-RandomBG") + if (sp.getBoolean(R.string.key_dexcomg5_xdripupload, false)) + nsUpload.sendToXdrip(bgReading) + } aapsLogger.debug(LTag.BGSOURCE, "Generated BG: $bgReading") } }