From 7fc631a7296f6d9baa6ecafa17659a3b76e4e1b8 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 9 May 2020 10:52:20 +0200 Subject: [PATCH] RS -> danaRS finished --- .../info/nightscout/androidaps/MainApp.java | 10 +- .../androidaps/db/DatabaseHelper.java | 4 +- .../androidaps/db/DatabaseHelperProvider.java | 68 +++++++++++++ .../dependencyInjection/AppModule.kt | 8 +- .../dependencyInjection/FragmentsModule.kt | 2 +- .../androidaps/dialogs/CarbsDialog.kt | 3 +- .../androidaps/dialogs/CareDialog.kt | 3 +- .../androidaps/dialogs/FillDialog.kt | 31 +----- .../plugins/aps/loop/LoopPlugin.java | 7 +- .../objectives/ObjectivesFragment.kt | 4 +- .../automation/actions/ActionNotification.kt | 3 +- .../Dialogs/NewNSTreatmentDialog.java | 3 +- .../plugins/general/food/FoodFragment.kt | 3 +- .../general/nsclient/NSClientFragment.java | 7 +- .../general/nsclient/NSClientPlugin.java | 4 - .../plugins/general/nsclient/UploadQueue.java | 87 ++++++++++------- .../nsclient/services/NSClientService.java | 62 ++++++------ .../general/overview/OverviewFragment.kt | 8 +- .../general/overview/graphData/GraphData.kt | 4 +- .../plugins/general/wear/WearPlugin.kt | 2 +- .../wearintegration/WatchUpdaterService.java | 8 +- .../profile/local/LocalProfilePlugin.kt | 5 +- .../plugins/pump/combo/ComboPlugin.java | 4 +- .../pump/common/PumpPluginAbstract.java | 4 +- .../pump/danaR/AbstractDanaRPlugin.java | 4 +- .../pump/danaR/comm/MessageHashTableR.kt | 4 +- .../plugins/pump/danaR/comm/MsgError.kt | 5 +- .../plugins/pump/danaR/comm/MsgHistoryAll.kt | 2 +- .../danaR/services/DanaRExecutionService.java | 3 +- .../comm/MessageHashTableRKorean.kt | 4 +- .../services/DanaRKoreanExecutionService.java | 3 +- .../pump/danaRv2/comm/MessageHashTableRv2.kt | 4 +- .../services/DanaRv2ExecutionService.java | 3 +- .../pump/insight/LocalInsightPlugin.java | 27 ++--- .../plugins/pump/mdi/MDIPlugin.java | 4 +- .../medtronic/data/MedtronicHistoryData.java | 5 +- .../wizard/pages/InitPodRefreshAction.java | 3 +- .../plugins/pump/virtual/VirtualPumpPlugin.kt | 4 +- .../androidaps/plugins/source/DexcomPlugin.kt | 11 ++- .../plugins/source/EversensePlugin.kt | 9 +- .../plugins/source/PoctechPlugin.kt | 7 +- .../androidaps/plugins/source/TomatoPlugin.kt | 7 +- .../fragments/TreatmentsBolusFragment.kt | 10 +- .../fragments/TreatmentsCareportalFragment.kt | 10 +- .../TreatmentsExtendedBolusesFragment.kt | 6 +- .../TreatmentsProfileSwitchFragment.kt | 6 +- .../TreatmentsTempTargetFragment.java | 6 +- .../TreatmentsTemporaryBasalsFragment.kt | 6 +- .../androidaps/receivers/KeepAliveReceiver.kt | 6 +- .../androidaps/services/DataService.java | 4 +- .../nightscout/androidaps/utils/HardLimits.kt | 13 +-- .../androidaps/utils/LocalAlertUtils.kt | 5 +- .../androidaps/utils/stats/TddCalculator.kt | 4 +- app/src/main/res/layout/okcancel.xml | 44 +++++++++ app/src/main/res/values/colors.xml | 2 - app/src/main/res/values/strings.xml | 92 +----------------- .../activities/TDDStatsActivity.java | 27 ++--- .../androidaps}/dialogs/NtpProgressDialog.kt | 6 +- .../androidaps/dialogs/ProfileViewerDialog.kt | 12 +-- .../events/EventDanaRSyncStatus.kt | 2 +- .../events/EventExtendedBolusChange.kt | 0 .../nightscout/androidaps/events/EventLoop.kt | 0 .../androidaps}/events/EventNtpStatus.kt | 2 +- .../androidaps/events/EventTempBasalChange.kt | 0 .../interfaces/DatabaseHelperInterface.kt | 18 +++- .../androidaps/interfaces/PumpInterface.java | 2 +- .../plugins/general/nsclient/NSUpload.java | 41 +++++++- .../treatments/fragments/ProfileGraph.kt | 0 .../queue/events/EventQueueChanged.kt | 0 .../utils/DigitsKeyListenerWithComma.java | 0 .../androidaps/utils/NumberPicker.java | 2 +- .../nightscout/androidaps/utils/WarnColors.kt | 2 +- .../CompositeDisposablePlusAssign.kt | 0 .../utils/extensions/Concurrency.kt | 0 core/src/main/res/layout/close.xml | 19 ++++ .../main/res/layout/danar_statsactivity.xml | 0 .../main/res/layout/dialog_profileviewer.xml | 0 .../main/res/layout/number_picker_layout.xml | 0 .../src/main/res/layout/spinner_centered.xml | 0 {app => core}/src/main/res/raw/boluserror.mp3 | Bin core/src/main/res/values/colors.xml | 4 + core/src/main/res/values/strings.xml | 32 ++++++ danars/build.gradle | 6 ++ .../plugins/pump/danaR/DanaRFragment.kt | 8 +- .../danaR/activities/DanaRHistoryActivity.kt | 34 +++---- .../activities/DanaRUserOptionsActivity.kt | 27 +++-- .../plugins/pump/danaRS/DanaRSPlugin.kt | 4 +- .../pump/danaRS/comm/DanaRS_Packet.java | 13 +-- .../comm/DanaRS_Packet_APS_History_Events.kt | 7 +- .../DanaRS_Packet_Bolus_Get_Bolus_Option.kt | 1 - ...DanaRS_Packet_Bolus_Set_Step_Bolus_Stop.kt | 2 +- .../DanaRS_Packet_General_Get_Pump_Check.kt | 2 +- .../danaRS/comm/DanaRS_Packet_History_.kt | 7 +- .../danaRS/comm/DanaRS_Packet_Notify_Alarm.kt | 5 +- .../DanaRS_Packet_Notify_Delivery_Complete.kt | 2 +- ...aRS_Packet_Notify_Delivery_Rate_Display.kt | 2 +- .../plugins/pump/danaRS/services/BLEComm.kt | 7 +- .../pump/danaRS/services/DanaRSService.kt | 4 +- .../src/main/res/layout/danar_fragment.xml | 0 .../main/res/layout/danar_history_item.xml | 0 .../main/res/layout/danar_historyactivity.xml | 0 .../layout/danar_user_options_activity.xml | 0 danars/src/main/res/layout/okcancel.xml | 44 +++++++++ danars/src/main/res/values/strings.xml | 62 ++++++++++++ 104 files changed, 666 insertions(+), 407 deletions(-) create mode 100644 app/src/main/java/info/nightscout/androidaps/db/DatabaseHelperProvider.java create mode 100644 app/src/main/res/layout/okcancel.xml rename {app => core}/src/main/java/info/nightscout/androidaps/activities/TDDStatsActivity.java (94%) rename {app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives => core/src/main/java/info/nightscout/androidaps}/dialogs/NtpProgressDialog.kt (94%) rename {app => core}/src/main/java/info/nightscout/androidaps/dialogs/ProfileViewerDialog.kt (89%) rename {app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR => core/src/main/java/info/nightscout/androidaps}/events/EventDanaRSyncStatus.kt (63%) rename {app => core}/src/main/java/info/nightscout/androidaps/events/EventExtendedBolusChange.kt (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/events/EventLoop.kt (100%) rename {app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives => core/src/main/java/info/nightscout/androidaps}/events/EventNtpStatus.kt (61%) rename {app => core}/src/main/java/info/nightscout/androidaps/events/EventTempBasalChange.kt (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/ProfileGraph.kt (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/queue/events/EventQueueChanged.kt (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/utils/DigitsKeyListenerWithComma.java (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/utils/NumberPicker.java (99%) rename app/src/main/java/info/nightscout/androidaps/utils/SetWarnColor.kt => core/src/main/java/info/nightscout/androidaps/utils/WarnColors.kt (97%) rename {app => core}/src/main/java/info/nightscout/androidaps/utils/extensions/CompositeDisposablePlusAssign.kt (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/utils/extensions/Concurrency.kt (100%) create mode 100644 core/src/main/res/layout/close.xml rename {app => core}/src/main/res/layout/danar_statsactivity.xml (100%) rename {app => core}/src/main/res/layout/dialog_profileviewer.xml (100%) rename {app => core}/src/main/res/layout/number_picker_layout.xml (100%) rename {app => core}/src/main/res/layout/spinner_centered.xml (100%) rename {app => core}/src/main/res/raw/boluserror.mp3 (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/activities/DanaRHistoryActivity.kt (84%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/activities/DanaRUserOptionsActivity.kt (88%) rename {app => danars}/src/main/res/layout/danar_fragment.xml (100%) rename {app => danars}/src/main/res/layout/danar_history_item.xml (100%) rename {app => danars}/src/main/res/layout/danar_historyactivity.xml (100%) rename {app => danars}/src/main/res/layout/danar_user_options_activity.xml (100%) create mode 100644 danars/src/main/res/layout/okcancel.xml diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java index 85d8f83ed7..27d60be03c 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainApp.java +++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java @@ -23,6 +23,7 @@ import javax.inject.Inject; import dagger.android.AndroidInjector; import dagger.android.DaggerApplication; import info.nightscout.androidaps.db.BgReading; +import info.nightscout.androidaps.db.CareportalEvent; import info.nightscout.androidaps.db.DatabaseHelper; import info.nightscout.androidaps.db.StaticInjector; import info.nightscout.androidaps.dependencyInjection.DaggerAppComponent; @@ -45,7 +46,7 @@ import info.nightscout.androidaps.utils.ActivityMonitor; import info.nightscout.androidaps.utils.LocaleHelper; import info.nightscout.androidaps.utils.sharedPreferences.SP; -public class MainApp extends DaggerApplication implements DatabaseHelperInterface { +public class MainApp extends DaggerApplication { static MainApp sInstance; private static Resources sResources; @@ -57,6 +58,7 @@ public class MainApp extends DaggerApplication implements DatabaseHelperInterfac @Inject ActivityMonitor activityMonitor; @Inject VersionCheckerUtils versionCheckersUtils; @Inject SP sp; + @Inject NSUpload nsUpload; @Inject ConfigBuilderPlugin configBuilderPlugin; @Inject KeepAliveReceiver.KeepAliveManager keepAliveManager; @@ -99,7 +101,7 @@ public class MainApp extends DaggerApplication implements DatabaseHelperInterfac pluginStore.setPlugins(plugins); configBuilderPlugin.initialize(); - NSUpload.uploadAppStart(); + nsUpload.uploadAppStart(); new Thread(() -> keepAliveManager.setAlarm(this)).start(); doMigrations(); @@ -173,8 +175,4 @@ public class MainApp extends DaggerApplication implements DatabaseHelperInterfac keepAliveManager.cancelAlarm(this); super.onTerminate(); } - - @NotNull @Override public List getAllBgreadingsDataFromTime(long mills, boolean ascending) { - return getDbHelper().getAllBgreadingsDataFromTime(mills, ascending); - } } diff --git a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java index abc6df92c9..b5e5c89819 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java +++ b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java @@ -1733,7 +1733,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } */ - public void createProfileSwitchFromJsonIfNotExists(ActivePluginProvider activePluginProvider, JSONObject trJson) { + public void createProfileSwitchFromJsonIfNotExists(ActivePluginProvider activePluginProvider, NSUpload nsUpload, JSONObject trJson) { try { ProfileSwitch profileSwitch = new ProfileSwitch(MainApp.instance()); profileSwitch.date = trJson.getLong("mills"); @@ -1759,7 +1759,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { if (L.isEnabled(LTag.DATABASE)) log.debug("Profile switch prefilled with JSON from local store"); // Update data in NS - NSUpload.updateProfileSwitch(profileSwitch); + nsUpload.updateProfileSwitch(profileSwitch); } else { if (L.isEnabled(LTag.DATABASE)) log.debug("JSON for profile switch doesn't exist. Ignoring: " + trJson.toString()); diff --git a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelperProvider.java b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelperProvider.java new file mode 100644 index 0000000000..60c7578b74 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelperProvider.java @@ -0,0 +1,68 @@ +package info.nightscout.androidaps.db; + +import com.j256.ormlite.dao.CloseableIterator; + +import org.jetbrains.annotations.NotNull; + +import java.sql.SQLException; +import java.util.List; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.interfaces.DatabaseHelperInterface; + +@Singleton +public class DatabaseHelperProvider implements DatabaseHelperInterface { + + @Inject DatabaseHelperProvider() {} + + @NotNull @Override public List getAllBgreadingsDataFromTime(long mills, boolean ascending) { + return MainApp.getDbHelper().getAllBgreadingsDataFromTime(mills, ascending); + } + + @Override public void createOrUpdate(@NotNull CareportalEvent careportalEvent) { + MainApp.getDbHelper().createOrUpdate(careportalEvent); + } + + @Override public void createOrUpdate(@NotNull DanaRHistoryRecord record) { + MainApp.getDbHelper().createOrUpdate(record); + } + + @NotNull @Override public List getDanaRHistoryRecordsByType(byte type) { + return MainApp.getDbHelper().getDanaRHistoryRecordsByType(type); + } + + @NotNull @Override public List getTDDs() { + return MainApp.getDbHelper().getTDDs(); + } + + @Override public long size(@NotNull String table) { + return MainApp.getDbHelper().size(table); + } + + @Override public void create(@NotNull DbRequest record) { + try { + MainApp.getDbHelper().create(record); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + @Override public void deleteAllDbRequests() { + MainApp.getDbHelper().deleteAllDbRequests(); + } + + @Override public int deleteDbRequest(@NotNull String id) { + return MainApp.getDbHelper().deleteDbRequest(id); + } + + @Override public void deleteDbRequestbyMongoId(@NotNull String action, @NotNull String _id) { + MainApp.getDbHelper().deleteDbRequestbyMongoId(action, _id); + } + + @NotNull @Override public CloseableIterator getDbRequestInterator() { + return MainApp.getDbHelper().getDbRequestInterator(); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt index e405ab91fd..16543e8a86 100644 --- a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt +++ b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt @@ -8,13 +8,16 @@ import dagger.Provides import dagger.android.HasAndroidInjector import info.nightscout.androidaps.Config import info.nightscout.androidaps.MainApp +import info.nightscout.androidaps.db.DatabaseHelperProvider import info.nightscout.androidaps.interfaces.* import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.plugins.configBuilder.PluginStore import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctionImplementation +import info.nightscout.androidaps.plugins.general.nsclient.UploadQueue import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin import info.nightscout.androidaps.queue.CommandQueue import info.nightscout.androidaps.utils.FabricPrivacy +import info.nightscout.androidaps.utils.androidNotification.NotificationHolder import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.sharedPreferences.SP import info.nightscout.androidaps.utils.storage.FileStorage @@ -61,11 +64,12 @@ open class AppModule { @Binds fun bindContext(mainApp: MainApp): Context @Binds fun bindInjector(mainApp: MainApp): HasAndroidInjector - @Binds fun bindDatabaseHelperInterface(mainApp: MainApp): DatabaseHelperInterface @Binds fun bindActivePluginProvider(pluginStore: PluginStore): ActivePluginProvider @Binds fun commandQueueProvider(commandQueue: CommandQueue): CommandQueueProvider @Binds fun configInterfaceProvider(config: Config): ConfigInterface @Binds fun treatmentInterfaceProvider(treatmentsPlugin: TreatmentsPlugin): TreatmentsInterface - + @Binds fun provideDatabaseHelperInterface(databaseHelperProvider: DatabaseHelperProvider): DatabaseHelperInterface + @Binds fun provideUploadQueueInterface(uploadQueue: UploadQueue): UploadQueueInterface + @Binds fun provideNotificationHolderInterface(notificationHolder: NotificationHolder): NotificationHolderInterface } } diff --git a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/FragmentsModule.kt b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/FragmentsModule.kt index 89783c9e4f..8748891d07 100644 --- a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/FragmentsModule.kt +++ b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/FragmentsModule.kt @@ -10,7 +10,7 @@ import info.nightscout.androidaps.plugins.aps.openAPSSMB.OpenAPSSMBFragment import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderFragment import info.nightscout.androidaps.plugins.constraints.objectives.ObjectivesFragment import info.nightscout.androidaps.plugins.constraints.objectives.activities.ObjectivesExamDialog -import info.nightscout.androidaps.plugins.constraints.objectives.dialogs.NtpProgressDialog +import info.nightscout.androidaps.dialogs.NtpProgressDialog import info.nightscout.androidaps.plugins.general.actions.ActionsFragment import info.nightscout.androidaps.plugins.general.automation.AutomationFragment import info.nightscout.androidaps.plugins.general.automation.dialogs.ChooseActionDialog diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/CarbsDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/CarbsDialog.kt index 28abd8eb60..31ced947d0 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/CarbsDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/CarbsDialog.kt @@ -40,6 +40,7 @@ class CarbsDialog : DialogFragmentWithDate() { @Inject lateinit var treatmentsPlugin: TreatmentsPlugin @Inject lateinit var profileFunction: ProfileFunction @Inject lateinit var iobCobCalculatorPlugin: IobCobCalculatorPlugin + @Inject lateinit var nsUpload: NSUpload @Inject lateinit var carbsGenerator: CarbsGenerator companion object { @@ -233,7 +234,7 @@ class CarbsDialog : DialogFragmentWithDate() { } else { aapsLogger.debug("USER ENTRY: CARBS $carbsAfterConstraints time: $time duration: $duration") carbsGenerator.generateCarbs(carbsAfterConstraints, time, duration, notes) - NSUpload.uploadEvent(CareportalEvent.NOTE, DateUtil.now() - 2000, resourceHelper.gs(R.string.generated_ecarbs_note, carbsAfterConstraints, duration, timeOffset)) + nsUpload.uploadEvent(CareportalEvent.NOTE, DateUtil.now() - 2000, resourceHelper.gs(R.string.generated_ecarbs_note, carbsAfterConstraints, duration, timeOffset)) } } }, null) diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/CareDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/CareDialog.kt index 1eda2e060e..f9fa675438 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/CareDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/CareDialog.kt @@ -36,6 +36,7 @@ class CareDialog : DialogFragmentWithDate() { @Inject lateinit var mainApp: MainApp @Inject lateinit var resourceHelper: ResourceHelper @Inject lateinit var profileFunction: ProfileFunction + @Inject lateinit var nsUpload: NSUpload @Inject lateinit var translator: Translator enum class EventType { @@ -197,7 +198,7 @@ class CareDialog : DialogFragmentWithDate() { careportalEvent.json = json.toString() aapsLogger.debug("USER ENTRY: CAREPORTAL ${careportalEvent.eventType} json: ${careportalEvent.json}") MainApp.getDbHelper().createOrUpdate(careportalEvent) - NSUpload.uploadCareportalEntryToNS(json) + nsUpload.uploadCareportalEntryToNS(json) }, null) } return true diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/FillDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/FillDialog.kt index eb5e9ccf59..580b27228c 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/FillDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/FillDialog.kt @@ -40,9 +40,9 @@ class FillDialog : DialogFragmentWithDate() { @Inject lateinit var constraintChecker: ConstraintChecker @Inject lateinit var resourceHelper: ResourceHelper @Inject lateinit var ctx: Context + @Inject lateinit var nsUpload: NSUpload @Inject lateinit var commandQueue: CommandQueueProvider @Inject lateinit var activePlugin: ActivePluginProvider - @Inject lateinit var injector: HasAndroidInjector override fun onSaveInstanceState(savedInstanceState: Bundle) { super.onSaveInstanceState(savedInstanceState) @@ -124,12 +124,12 @@ class FillDialog : DialogFragmentWithDate() { } if (siteChange) { aapsLogger.debug("USER ENTRY: SITE CHANGE") - generateCareportalEvent(CareportalEvent.SITECHANGE, eventTime, notes, resourceHelper, sp, injector) + nsUpload.generateCareportalEvent(CareportalEvent.SITECHANGE, eventTime, notes) } if (insulinChange) { // add a second for case of both checked aapsLogger.debug("USER ENTRY: INSULIN CHANGE") - generateCareportalEvent(CareportalEvent.INSULINCHANGE, eventTime + 1000, notes, resourceHelper, sp, injector) + nsUpload.generateCareportalEvent(CareportalEvent.INSULINCHANGE, eventTime + 1000, notes) } }, null) } @@ -162,29 +162,4 @@ class FillDialog : DialogFragmentWithDate() { } }) } - - companion object { - fun generateCareportalEvent(eventType: String, time: Long, notes: String, resourceHelper: ResourceHelper, sp: SP, injector: HasAndroidInjector) { - val careportalEvent = CareportalEvent(injector) - careportalEvent.source = Source.USER - careportalEvent.date = time - careportalEvent.json = generateJson(eventType, time, notes, resourceHelper, sp).toString() - careportalEvent.eventType = eventType - MainApp.getDbHelper().createOrUpdate(careportalEvent) - NSUpload.uploadEvent(eventType, time, notes) - } - - private fun generateJson(careportalEvent: String, time: Long, notes: String, resourceHelper: ResourceHelper, sp: SP): JSONObject { - val data = JSONObject() - try { - data.put("eventType", careportalEvent) - data.put("created_at", DateUtil.toISOString(time)) - data.put("mills", time) - data.put("enteredBy", sp.getString("careportal_enteredby", resourceHelper.gs(R.string.app_name))) - if (notes.isNotEmpty()) data.put("notes", notes) - } catch (ignored: JSONException) { - } - return data - } - } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.java index f04035277e..6b25f97882 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.java @@ -22,6 +22,7 @@ import javax.inject.Singleton; import dagger.Lazy; import dagger.android.HasAndroidInjector; +import info.nightscout.androidaps.BuildConfig; import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainActivity; import info.nightscout.androidaps.MainApp; @@ -103,7 +104,7 @@ public class LoopPlugin extends PluginBase implements LoopInterface { private boolean isSuperBolus; private boolean isDisconnected; - @Nullable public LastRun lastRun = null; + @Nullable private LastRun lastRun = null; @Nullable @Override public LastRun getLastRun() { return lastRun; @@ -412,7 +413,7 @@ public class LoopPlugin extends PluginBase implements LoopInterface { lastRun.setLastSMBEnact(0); lastRun.setLastSMBRequest(0); - nsUpload.uploadDeviceStatus(this, iobCobCalculatorPlugin, profileFunction, activePlugin.getActivePump(), receiverStatusStore); + nsUpload.uploadDeviceStatus(this, iobCobCalculatorPlugin, profileFunction, activePlugin.getActivePump(), receiverStatusStore, BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION); if (isSuspended()) { getAapsLogger().debug(LTag.APS, resourceHelper.gs(R.string.loopsuspended)); @@ -537,7 +538,7 @@ public class LoopPlugin extends PluginBase implements LoopInterface { lastRun.setLastTBRRequest(lastRun.getLastAPSRun()); lastRun.setLastTBREnact(DateUtil.now()); lastRun.setLastOpenModeAccept(DateUtil.now()); - nsUpload.uploadDeviceStatus(lp, iobCobCalculatorPlugin, profileFunction, activePlugin.getActivePump(), receiverStatusStore); + nsUpload.uploadDeviceStatus(lp, iobCobCalculatorPlugin, profileFunction, activePlugin.getActivePump(), receiverStatusStore, BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION); sp.incInt(R.string.key_ObjectivesmanualEnacts); } rxBus.send(new EventAcceptOpenLoopChange()); 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 1e01d814f6..69a8892bdc 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 @@ -22,8 +22,8 @@ import info.nightscout.androidaps.R import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.constraints.objectives.activities.ObjectivesExamDialog -import info.nightscout.androidaps.plugins.constraints.objectives.dialogs.NtpProgressDialog -import info.nightscout.androidaps.plugins.constraints.objectives.events.EventNtpStatus +import info.nightscout.androidaps.dialogs.NtpProgressDialog +import info.nightscout.androidaps.events.EventNtpStatus import info.nightscout.androidaps.plugins.constraints.objectives.events.EventObjectivesUpdateGui import info.nightscout.androidaps.plugins.constraints.objectives.objectives.Objective.ExamTask import info.nightscout.androidaps.receivers.ReceiverStatusStore diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionNotification.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionNotification.kt index 7a730585c1..43342f35e5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionNotification.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionNotification.kt @@ -22,6 +22,7 @@ import javax.inject.Inject class ActionNotification(injector: HasAndroidInjector) : Action(injector) { @Inject lateinit var resourceHelper: ResourceHelper @Inject lateinit var rxBus: RxBusWrapper + @Inject lateinit var nsUpload: NSUpload var text = InputString(injector) @@ -32,7 +33,7 @@ class ActionNotification(injector: HasAndroidInjector) : Action(injector) { override fun doAction(callback: Callback) { val notification = NotificationUserMessage(text.value) rxBus.send(EventNewNotification(notification)) - NSUpload.uploadError(text.value) + nsUpload.uploadError(text.value) rxBus.send(EventRefreshOverview("ActionNotification")) callback.result(PumpEnactResult(injector).success(true).comment(R.string.ok))?.run() } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/careportal/Dialogs/NewNSTreatmentDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/careportal/Dialogs/NewNSTreatmentDialog.java index 8fe577ced3..52d7a25c49 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/careportal/Dialogs/NewNSTreatmentDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/careportal/Dialogs/NewNSTreatmentDialog.java @@ -78,6 +78,7 @@ public class NewNSTreatmentDialog extends DaggerDialogFragment implements View.O @Inject ActivePluginProvider activePlugin; @Inject TreatmentsPlugin treatmentsPlugin; @Inject HardLimits hardLimits; + @Inject NSUpload nsUpload; @Inject Translator translator; @Inject DateUtil dateUtil; @@ -714,7 +715,7 @@ public class NewNSTreatmentDialog extends DaggerDialogFragment implements View.O private void confirmNSTreatmentCreation() { final JSONObject data = gatherData(); - OKDialog.showConfirmation(getContext(), translator.translate(JsonHelper.safeGetString(data, "eventType", resourceHelper.gs(R.string.overview_treatment_label))), buildConfirmText(data), () -> NSUpload.createNSTreatment(data, profileStore, profileFunction, eventTime.getTime())); + OKDialog.showConfirmation(getContext(), translator.translate(JsonHelper.safeGetString(data, "eventType", resourceHelper.gs(R.string.overview_treatment_label))), buildConfirmText(data), () -> nsUpload.createNSTreatment(data, profileStore, profileFunction, eventTime.getTime())); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/food/FoodFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/food/FoodFragment.kt index c54e383afc..d4efd0ff96 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/food/FoodFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/food/FoodFragment.kt @@ -35,6 +35,7 @@ class FoodFragment : DaggerFragment() { @Inject lateinit var resourceHelper: ResourceHelper @Inject lateinit var fabricPrivacy: FabricPrivacy @Inject lateinit var foodPlugin: FoodPlugin + @Inject lateinit var nsUpload: NSUpload private val disposable = CompositeDisposable() private lateinit var unfiltered: List @@ -200,7 +201,7 @@ class FoodFragment : DaggerFragment() { activity?.let { activity -> showConfirmation(activity, resourceHelper.gs(R.string.confirmation), resourceHelper.gs(R.string.removerecord) + "\n" + food.name, DialogInterface.OnClickListener { _: DialogInterface?, _: Int -> if (food._id != null && food._id != "") { - NSUpload.removeFoodFromNS(food._id) + nsUpload.removeFoodFromNS(food._id) } foodPlugin.service?.delete(food) }, null) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientFragment.java index 89d0f65bc7..27310dad90 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientFragment.java @@ -33,6 +33,7 @@ public class NSClientFragment extends DaggerFragment implements View.OnClickList @Inject SP sp; @Inject ResourceHelper resourceHelper; @Inject RxBusWrapper rxBus; + @Inject UploadQueue uploadQueue; @Inject FabricPrivacy fabricPrivacy; private CompositeDisposable disposable = new CompositeDisposable(); @@ -119,13 +120,13 @@ public class NSClientFragment extends DaggerFragment implements View.OnClickList break; case R.id.nsclientinternal_clearqueue: OKDialog.showConfirmation(getContext(), resourceHelper.gs(R.string.nsclientinternal), resourceHelper.gs(R.string.clearqueueconfirm), () -> { - UploadQueue.clearQueue(); + uploadQueue.clearQueue(); updateGui(); fabricPrivacy.logCustom("NSClientClearQueue"); }); break; case R.id.nsclientinternal_showqueue: - rxBus.send(new EventNSClientNewLog("QUEUE", nsClientPlugin.queue().textList())); + rxBus.send(new EventNSClientNewLog("QUEUE", uploadQueue.textList())); break; } } @@ -154,7 +155,7 @@ public class NSClientFragment extends DaggerFragment implements View.OnClickList logScrollview.fullScroll(ScrollView.FOCUS_DOWN); } urlTextView.setText(nsClientPlugin.url()); - Spanned queuetext = Html.fromHtml(resourceHelper.gs(R.string.queue) + " " + UploadQueue.size() + ""); + Spanned queuetext = Html.fromHtml(resourceHelper.gs(R.string.queue) + " " + uploadQueue.size() + ""); queueTextView.setText(queuetext); statusTextView.setText(nsClientPlugin.status); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientPlugin.java index da77936384..9443e23e39 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientPlugin.java @@ -253,10 +253,6 @@ public class NSClientPlugin extends PluginBase { rxBus.send(new EventPreferenceChange(resourceHelper, R.string.key_nsclientinternal_paused)); } - public UploadQueue queue() { - return NSClientService.uploadQueue; - } - public String url() { return NSClientService.nsURL; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/UploadQueue.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/UploadQueue.java index d9bd5a6307..08fecd9283 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/UploadQueue.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/UploadQueue.java @@ -8,71 +8,86 @@ import com.j256.ormlite.dao.CloseableIterator; import org.json.JSONException; import org.json.JSONObject; -import org.slf4j.Logger; import java.sql.SQLException; -import info.nightscout.androidaps.MainApp; +import javax.inject.Inject; + import info.nightscout.androidaps.R; import info.nightscout.androidaps.db.DatabaseHelper; import info.nightscout.androidaps.db.DbRequest; +import info.nightscout.androidaps.interfaces.DatabaseHelperInterface; import info.nightscout.androidaps.interfaces.UploadQueueInterface; -import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.LTag; -import info.nightscout.androidaps.logging.StacktraceLoggerWrapper; -import info.nightscout.androidaps.plugins.bus.RxBus; +import info.nightscout.androidaps.plugins.bus.RxBusWrapper; import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientResend; import info.nightscout.androidaps.plugins.general.nsclient.services.NSClientService; -import info.nightscout.androidaps.utils.SP; +import info.nightscout.androidaps.utils.sharedPreferences.SP; /** * Created by mike on 21.02.2016. */ public class UploadQueue implements UploadQueueInterface { - private static Logger log = StacktraceLoggerWrapper.getLogger(LTag.NSCLIENT); + private final AAPSLogger aapsLogger; + private final DatabaseHelperInterface databaseHelper; + private final Context context; + private final SP sp; + private final RxBusWrapper rxBus; - public static String status() { - return "QUEUE: " + MainApp.getDbHelper().size(DatabaseHelper.DATABASE_DBREQUESTS); + @Inject + public UploadQueue( + AAPSLogger aapsLogger, + DatabaseHelperInterface databaseHelper, + Context context, + SP sp, + RxBusWrapper rxBus + ) { + this.aapsLogger = aapsLogger; + this.databaseHelper = databaseHelper; + this.context = context; + this.sp = sp; + this.rxBus = rxBus; } - public static long size() { - return MainApp.getDbHelper().size(DatabaseHelper.DATABASE_DBREQUESTS); + public String status() { + return "QUEUE: " + databaseHelper.size(DatabaseHelper.DATABASE_DBREQUESTS); } - private static void startService() { + public long size() { + return databaseHelper.size(DatabaseHelper.DATABASE_DBREQUESTS); + } + + private void startService() { if (NSClientService.handler == null) { - Context context = MainApp.instance(); context.startService(new Intent(context, NSClientService.class)); SystemClock.sleep(2000); } } - public static void add(final DbRequest dbr) { - if (SP.getBoolean(R.string.key_ns_noupload, false)) return; - if (L.isEnabled(LTag.NSCLIENT)) - log.debug("Adding to queue: " + dbr.log()); + public void add(final DbRequest dbr) { + if (sp.getBoolean(R.string.key_ns_noupload, false)) return; + aapsLogger.debug(LTag.NSCLIENT, "Adding to queue: " + dbr.log()); try { - MainApp.getDbHelper().create(dbr); + databaseHelper.create(dbr); } catch (Exception e) { - log.error("Unhandled exception", e); + aapsLogger.error("Unhandled exception", e); } - RxBus.getINSTANCE().send(new EventNSClientResend("newdata")); + rxBus.send(new EventNSClientResend("newdata")); } - static void clearQueue() { + void clearQueue() { startService(); if (NSClientService.handler != null) { NSClientService.handler.post(() -> { - if (L.isEnabled(LTag.NSCLIENT)) - log.debug("ClearQueue"); - MainApp.getDbHelper().deleteAllDbRequests(); - if (L.isEnabled(LTag.NSCLIENT)) - log.debug(status()); + aapsLogger.debug(LTag.NSCLIENT, "ClearQueue"); + databaseHelper.deleteAllDbRequests(); + aapsLogger.debug(LTag.NSCLIENT, status()); }); } } - public static void removeID(final JSONObject record) { + public void removeID(final JSONObject record) { startService(); if (NSClientService.handler != null) { NSClientService.handler.post(() -> { @@ -83,26 +98,24 @@ public class UploadQueue implements UploadQueueInterface { } else { return; } - if (MainApp.getDbHelper().deleteDbRequest(id) == 1) { - if (L.isEnabled(LTag.NSCLIENT)) - log.debug("Removed item from UploadQueue. " + UploadQueue.status()); + if (databaseHelper.deleteDbRequest(id) == 1) { + aapsLogger.debug(LTag.NSCLIENT, "Removed item from UploadQueue. " + status()); } } catch (JSONException e) { - log.error("Unhandled exception", e); + aapsLogger.error("Unhandled exception", e); } }); } } - public static void removeID(final String action, final String _id) { + public void removeID(final String action, final String _id) { if (_id == null || _id.equals("")) return; startService(); if (NSClientService.handler != null) { NSClientService.handler.post(() -> { - MainApp.getDbHelper().deleteDbRequestbyMongoId(action, _id); - if (L.isEnabled(LTag.NSCLIENT)) - log.debug("Removing " + _id + " from UploadQueue. " + UploadQueue.status()); + databaseHelper.deleteDbRequestbyMongoId(action, _id); + aapsLogger.debug(LTag.NSCLIENT, "Removing " + _id + " from UploadQueue. " + status()); }); } } @@ -111,7 +124,7 @@ public class UploadQueue implements UploadQueueInterface { String result = ""; CloseableIterator iterator; try { - iterator = MainApp.getDbHelper().getDbRequestInterator(); + iterator = databaseHelper.getDbRequestInterator(); try { while (iterator.hasNext()) { DbRequest dbr = iterator.next(); @@ -124,7 +137,7 @@ public class UploadQueue implements UploadQueueInterface { iterator.close(); } } catch (SQLException e) { - log.error("Unhandled exception", e); + aapsLogger.error("Unhandled exception", e); } return result; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/services/NSClientService.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/services/NSClientService.java index 3187ccc924..195bb577cf 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/services/NSClientService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/services/NSClientService.java @@ -31,15 +31,15 @@ import javax.inject.Inject; import dagger.android.DaggerService; import dagger.android.HasAndroidInjector; import info.nightscout.androidaps.Config; -import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; -import info.nightscout.androidaps.interfaces.ProfileStore; import info.nightscout.androidaps.db.DbRequest; import info.nightscout.androidaps.events.EventAppExit; import info.nightscout.androidaps.events.EventConfigBuilderChange; import info.nightscout.androidaps.events.EventNsFood; import info.nightscout.androidaps.events.EventPreferenceChange; +import info.nightscout.androidaps.interfaces.DatabaseHelperInterface; import info.nightscout.androidaps.interfaces.PluginType; +import info.nightscout.androidaps.interfaces.ProfileStore; import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.logging.LTag; @@ -83,7 +83,7 @@ public class NSClientService extends DaggerService { @Inject AAPSLogger aapsLogger; @Inject NSSettingsStatus nsSettingsStatus; @Inject NSDeviceStatus nsDeviceStatus; - @Inject MainApp mainApp; + @Inject DatabaseHelperInterface databaseHelper; @Inject RxBusWrapper rxBus; @Inject ResourceHelper resourceHelper; @Inject SP sp; @@ -91,6 +91,7 @@ public class NSClientService extends DaggerService { @Inject BuildHelper buildHelper; @Inject Config config; @Inject DateUtil dateUtil; + @Inject UploadQueue uploadQueue; private static Logger log = StacktraceLoggerWrapper.getLogger(LTag.NSCLIENT); private CompositeDisposable disposable = new CompositeDisposable(); @@ -124,8 +125,6 @@ public class NSClientService extends DaggerService { private String nsAPIhashCode = ""; - public static UploadQueue uploadQueue = new UploadQueue(); - private final ArrayList reconnections = new ArrayList<>(); private int WATCHDOG_INTERVAL_MINUTES = 2; private int WATCHDOG_RECONNECT_IN = 15; @@ -143,7 +142,7 @@ public class NSClientService extends DaggerService { @Override public void onCreate() { super.onCreate(); - PowerManager powerManager = (PowerManager) mainApp.getApplicationContext().getSystemService(Context.POWER_SERVICE); + PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "AndroidAPS:NSClientService"); mWakeLock.acquire(); @@ -528,7 +527,7 @@ public class NSClientService extends DaggerService { @Override public void call(final Object... args) { NSClientService.handler.post(() -> { - PowerManager powerManager = (PowerManager) mainApp.getApplicationContext().getSystemService(Context.POWER_SERVICE); + PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "AndroidAPS:NSClientService_onDataUpdate"); wakeLock.acquire(); @@ -604,7 +603,7 @@ public class NSClientService extends DaggerService { NSTreatment treatment = new NSTreatment(jsonTreatment); // remove from upload queue if Ack is failing - UploadQueue.removeID(jsonTreatment); + uploadQueue.removeID(jsonTreatment); //Find latest date in treatment if (treatment.getMills() != null && treatment.getMills() < System.currentTimeMillis()) if (treatment.getMills() > latestDateInReceivedData) @@ -636,7 +635,7 @@ public class NSClientService extends DaggerService { for (Integer index = 0; index < devicestatuses.length(); index++) { JSONObject jsonStatus = devicestatuses.getJSONObject(index); // remove from upload queue if Ack is failing - UploadQueue.removeID(jsonStatus); + uploadQueue.removeID(jsonStatus); } nsDeviceStatus.handleNewData(devicestatuses); } @@ -652,7 +651,7 @@ public class NSClientService extends DaggerService { JSONObject jsonFood = foods.getJSONObject(index); // remove from upload queue if Ack is failing - UploadQueue.removeID(jsonFood); + uploadQueue.removeID(jsonFood); String action = JsonHelper.safeGetString(jsonFood, "action"); @@ -684,7 +683,7 @@ public class NSClientService extends DaggerService { for (Integer index = 0; index < mbgs.length(); index++) { JSONObject jsonMbg = mbgs.getJSONObject(index); // remove from upload queue if Ack is failing - UploadQueue.removeID(jsonMbg); + uploadQueue.removeID(jsonMbg); } handleNewMbg(mbgs, isDelta); } @@ -695,7 +694,7 @@ public class NSClientService extends DaggerService { // Retreive actual calibration for (Integer index = 0; index < cals.length(); index++) { // remove from upload queue if Ack is failing - UploadQueue.removeID(cals.optJSONObject(index)); + uploadQueue.removeID(cals.optJSONObject(index)); } handleNewCal(cals, isDelta); } @@ -709,7 +708,7 @@ public class NSClientService extends DaggerService { NSSgv sgv = new NSSgv(jsonSgv); // Handle new sgv here // remove from upload queue if Ack is failing - UploadQueue.removeID(jsonSgv); + uploadQueue.removeID(jsonSgv); //Find latest date in sgv if (sgv.getMills() != null && sgv.getMills() < System.currentTimeMillis()) if (sgv.getMills() > latestDateInReceivedData) @@ -795,7 +794,7 @@ public class NSClientService extends DaggerService { } public void resend(final String reason) { - if (UploadQueue.size() == 0) + if (uploadQueue.size() == 0) return; if (!isConnected || !hasWriteAuth) return; @@ -804,8 +803,7 @@ public class NSClientService extends DaggerService { if (mSocket == null || !mSocket.connected()) return; if (lastResendTime > System.currentTimeMillis() - 10 * 1000L) { - if (L.isEnabled(LTag.NSCLIENT)) - log.debug("Skipping resend by lastResendTime: " + ((System.currentTimeMillis() - lastResendTime) / 1000L) + " sec"); + aapsLogger.debug(LTag.NSCLIENT, "Skipping resend by lastResendTime: " + ((System.currentTimeMillis() - lastResendTime) / 1000L) + " sec"); return; } lastResendTime = System.currentTimeMillis(); @@ -815,7 +813,7 @@ public class NSClientService extends DaggerService { CloseableIterator iterator; int maxcount = 30; try { - iterator = mainApp.getDbHelper().getDbRequestInterator(); + iterator = databaseHelper.getDbRequestInterator(); try { while (iterator.hasNext() && maxcount > 0) { DbRequest dbr = iterator.next(); @@ -852,7 +850,7 @@ public class NSClientService extends DaggerService { private void handleAnnouncement(JSONObject announcement) { NSAlarm nsAlarm = new NSAlarm(announcement); - Notification notification = new NotificationWithAction(mainApp, nsAlarm); + Notification notification = new NotificationWithAction(injector, nsAlarm); rxBus.send(new EventNewNotification(notification)); rxBus.send(new EventNSClientNewLog("ANNOUNCEMENT", JsonHelper.safeGetString(announcement, "message", "received"))); aapsLogger.debug(LTag.NSCLIENT, announcement.toString()); @@ -862,7 +860,7 @@ public class NSClientService extends DaggerService { long snoozedTo = sp.getLong(R.string.key_snoozedTo, 0L); if (snoozedTo == 0L || System.currentTimeMillis() > snoozedTo) { NSAlarm nsAlarm = new NSAlarm(alarm); - Notification notification = new NotificationWithAction(mainApp, nsAlarm); + Notification notification = new NotificationWithAction(injector, nsAlarm); rxBus.send(new EventNewNotification(notification)); } rxBus.send(new EventNSClientNewLog("ALARM", JsonHelper.safeGetString(alarm, "message", "received"))); @@ -873,7 +871,7 @@ public class NSClientService extends DaggerService { long snoozedTo = sp.getLong(R.string.key_snoozedTo, 0L); if (snoozedTo == 0L || System.currentTimeMillis() > snoozedTo) { NSAlarm nsAlarm = new NSAlarm(alarm); - Notification notification = new NotificationWithAction(mainApp, nsAlarm); + Notification notification = new NotificationWithAction(injector, nsAlarm); rxBus.send(new EventNewNotification(notification)); } rxBus.send(new EventNSClientNewLog("URGENTALARM", JsonHelper.safeGetString(alarm, "message", "received"))); @@ -887,7 +885,7 @@ public class NSClientService extends DaggerService { Intent intent = new Intent(Intents.ACTION_NEW_CAL); intent.putExtras(bundle); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - LocalBroadcastManager.getInstance(mainApp).sendBroadcast(intent); + LocalBroadcastManager.getInstance(this).sendBroadcast(intent); } public void handleNewMbg(JSONArray mbgs, boolean isDelta) { @@ -897,7 +895,7 @@ public class NSClientService extends DaggerService { Intent intent = new Intent(Intents.ACTION_NEW_MBG); intent.putExtras(bundle); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - LocalBroadcastManager.getInstance(mainApp).sendBroadcast(intent); + LocalBroadcastManager.getInstance(this).sendBroadcast(intent); } public void handleNewProfile(ProfileStore profile, boolean isDelta) { @@ -907,7 +905,7 @@ public class NSClientService extends DaggerService { Intent intent = new Intent(Intents.ACTION_NEW_PROFILE); intent.putExtras(bundle); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - LocalBroadcastManager.getInstance(mainApp).sendBroadcast(intent); + LocalBroadcastManager.getInstance(this).sendBroadcast(intent); if (sp.getBoolean(R.string.key_nsclient_localbroadcasts, false)) { bundle = new Bundle(); @@ -916,7 +914,7 @@ public class NSClientService extends DaggerService { intent = new Intent(Intents.ACTION_NEW_PROFILE); intent.putExtras(bundle); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - mainApp.sendBroadcast(intent); + this.sendBroadcast(intent); } } @@ -929,7 +927,7 @@ public class NSClientService extends DaggerService { Intent intent = new Intent(Intents.ACTION_NEW_SGV); intent.putExtras(bundle); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - LocalBroadcastManager.getInstance(mainApp).sendBroadcast(intent); + LocalBroadcastManager.getInstance(this).sendBroadcast(intent); } if (sp.getBoolean(R.string.key_nsclient_localbroadcasts, false)) { @@ -940,7 +938,7 @@ public class NSClientService extends DaggerService { Intent intent = new Intent(Intents.ACTION_NEW_SGV); intent.putExtras(bundle); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - mainApp.sendBroadcast(intent); + this.sendBroadcast(intent); } } } @@ -954,7 +952,7 @@ public class NSClientService extends DaggerService { Intent intent = new Intent(Intents.ACTION_NEW_TREATMENT); intent.putExtras(bundle); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - LocalBroadcastManager.getInstance(mainApp).sendBroadcast(intent); + LocalBroadcastManager.getInstance(this).sendBroadcast(intent); } if (sp.getBoolean(R.string.key_nsclient_localbroadcasts, false)) { @@ -966,7 +964,7 @@ public class NSClientService extends DaggerService { Intent intent = new Intent(Intents.ACTION_NEW_TREATMENT); intent.putExtras(bundle); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - mainApp.getApplicationContext().sendBroadcast(intent); + this.getApplicationContext().sendBroadcast(intent); } } } @@ -980,7 +978,7 @@ public class NSClientService extends DaggerService { Intent intent = new Intent(Intents.ACTION_CHANGED_TREATMENT); intent.putExtras(bundle); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - LocalBroadcastManager.getInstance(mainApp).sendBroadcast(intent); + LocalBroadcastManager.getInstance(this).sendBroadcast(intent); } if (sp.getBoolean(R.string.key_nsclient_localbroadcasts, false)) { @@ -992,7 +990,7 @@ public class NSClientService extends DaggerService { Intent intent = new Intent(Intents.ACTION_CHANGED_TREATMENT); intent.putExtras(bundle); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - mainApp.getApplicationContext().sendBroadcast(intent); + this.getApplicationContext().sendBroadcast(intent); } } } @@ -1004,7 +1002,7 @@ public class NSClientService extends DaggerService { Intent intent = new Intent(Intents.ACTION_REMOVED_TREATMENT); intent.putExtras(bundle); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - LocalBroadcastManager.getInstance(mainApp).sendBroadcast(intent); + LocalBroadcastManager.getInstance(this).sendBroadcast(intent); if (sp.getBoolean(R.string.key_nsclient_localbroadcasts, false)) { @@ -1014,7 +1012,7 @@ public class NSClientService extends DaggerService { intent = new Intent(Intents.ACTION_REMOVED_TREATMENT); intent.putExtras(bundle); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - mainApp.getApplicationContext().sendBroadcast(intent); + this.getApplicationContext().sendBroadcast(intent); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt index 2a462fb44a..bda7d5b249 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt @@ -20,6 +20,7 @@ import android.view.View.OnLongClickListener import android.view.ViewGroup import android.widget.LinearLayout import android.widget.TextView +import androidx.core.text.toSpanned import androidx.recyclerview.widget.LinearLayoutManager import com.jjoe64.graphview.GraphView import dagger.android.HasAndroidInjector @@ -344,8 +345,9 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList if (loopPlugin.isEnabled(PluginType.LOOP)) { val lastRun = loopPlugin.lastRun loopPlugin.invoke("Accept temp button", false) - if (lastRun?.lastAPSRun != null && lastRun.constraintsProcessed.isChangeRequested) { - OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.pump_tempbasal_label), lastRun.constraintsProcessed.toSpanned(), Runnable { + if (lastRun?.lastAPSRun != null && lastRun.constraintsProcessed?.isChangeRequested == true) { + OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.pump_tempbasal_label), lastRun.constraintsProcessed?.toSpanned() + ?: "".toSpanned(), Runnable { aapsLogger.debug("USER ENTRY: ACCEPT TEMP BASAL") overview_accepttempbutton?.visibility = View.GONE (context?.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager).cancel(Constants.notificationID) @@ -442,7 +444,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList val showAcceptButton = !closedLoopEnabled.value() && // Open mode needed lastRun != null && (lastRun.lastOpenModeAccept == 0L || lastRun.lastOpenModeAccept < lastRun.lastAPSRun) &&// never accepted or before last result - lastRun.constraintsProcessed.isChangeRequested // change is requested + lastRun.constraintsProcessed?.isChangeRequested == true // change is requested if (showAcceptButton && pump.isInitialized && !pump.isSuspended && loopPlugin.isEnabled(PluginType.LOOP)) { overview_accepttempbutton?.visibility = View.VISIBLE diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphData/GraphData.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphData/GraphData.kt index 02ccf1480f..70e4f9f8fc 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphData/GraphData.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphData/GraphData.kt @@ -16,10 +16,10 @@ import info.nightscout.androidaps.data.IobTotal import info.nightscout.androidaps.data.Profile import info.nightscout.androidaps.db.BgReading import info.nightscout.androidaps.interfaces.ActivePluginProvider +import info.nightscout.androidaps.interfaces.LoopInterface import info.nightscout.androidaps.interfaces.TreatmentsInterface import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag -import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin.LastRun import info.nightscout.androidaps.plugins.aps.openAPSSMB.SMBDefaults import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.plugins.general.overview.graphExtensions.* @@ -197,7 +197,7 @@ class GraphData(injector: HasAndroidInjector, private val graph: GraphView, priv basalScale.setMultiplier(maxY * scale / maxBasalValueFound) } - fun addTargetLine(fromTime: Long, toTimeParam: Long, profile: Profile, lastRun: LastRun?) { + fun addTargetLine(fromTime: Long, toTimeParam: Long, profile: Profile, lastRun: LoopInterface.LastRun?) { var toTime = toTimeParam val targetsSeriesArray: MutableList = ArrayList() var lastTarget = -1.0 diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/WearPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/WearPlugin.kt index abff22eae3..02b201f5ab 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/WearPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/WearPlugin.kt @@ -104,7 +104,7 @@ class WearPlugin @Inject constructor( .observeOn(Schedulers.io()) .subscribe({ event: EventDismissBolusProgressIfRunning -> if (event.result == null) return@subscribe - val status: String = if (event.result.success) { + val status: String = if (event.result!!.success) { resourceHelper.gs(R.string.success) } else { resourceHelper.gs(R.string.nosuccess) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/wearintegration/WatchUpdaterService.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/wearintegration/WatchUpdaterService.java index e0a0657826..dd0babf951 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/wearintegration/WatchUpdaterService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/wearintegration/WatchUpdaterService.java @@ -531,9 +531,9 @@ public class WatchUpdaterService extends WearableListenerService implements Goog } - final LoopPlugin.LastRun finalLastRun = loopPlugin.lastRun; - if (sp.getBoolean("wear_predictions", true) && finalLastRun != null && finalLastRun.request.hasPredictions && finalLastRun.constraintsProcessed != null) { - List predArray = finalLastRun.constraintsProcessed.getPredictions(); + final LoopPlugin.LastRun finalLastRun = loopPlugin.getLastRun(); + if (sp.getBoolean("wear_predictions", true) && finalLastRun != null && finalLastRun.getRequest().hasPredictions && finalLastRun.getConstraintsProcessed() != null) { + List predArray = finalLastRun.getConstraintsProcessed().getPredictions(); if (!predArray.isEmpty()) { for (BgReading bg : predArray) { @@ -715,7 +715,7 @@ public class WatchUpdaterService extends WearableListenerService implements Goog //OpenAPS status if (config.getAPS()) { //we are AndroidAPS - openApsStatus = loopPlugin.lastRun != null && loopPlugin.lastRun.lastTBREnact != 0 ? loopPlugin.lastRun.lastTBREnact : -1; + openApsStatus = loopPlugin.getLastRun() != null && loopPlugin.getLastRun().getLastTBREnact() != 0 ? loopPlugin.getLastRun().getLastTBREnact() : -1; } else { //NSClient or remote openApsStatus = NSDeviceStatus.getOpenApsTimestamp(); 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 8d2761cfa3..7944707e57 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 @@ -37,7 +37,8 @@ class LocalProfilePlugin @Inject constructor( private val rxBus: RxBusWrapper, resourceHelper: ResourceHelper, private val sp: SP, - private val profileFunction: ProfileFunction + private val profileFunction: ProfileFunction, + private val nsUpload: NSUpload ) : PluginBase(PluginDescription() .mainType(PluginType.PROFILE) .fragmentClass(LocalProfileFragment::class.java.name) @@ -140,7 +141,7 @@ class LocalProfilePlugin @Inject constructor( if (name.contains(".")) namesOK = false } if (namesOK) - rawProfile?.let { NSUpload.uploadProfileStore(it.data) } + rawProfile?.let { nsUpload.uploadProfileStore(it.data) } else activity?.let { OKDialog.show(it, "", resourceHelper.gs(R.string.profilenamecontainsdot)) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ComboPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ComboPlugin.java index de9b4e66fc..50f40318d9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ComboPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ComboPlugin.java @@ -1259,7 +1259,7 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr } @NonNull @Override - public JSONObject getJSONStatus(Profile profile, String profileName) { + public JSONObject getJSONStatus(Profile profile, String profileName, String version) { if (!pump.initialized) { return null; } @@ -1281,7 +1281,7 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr pumpJson.put("status", statusJson); JSONObject extendedJson = new JSONObject(); - extendedJson.put("Version", BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION); + extendedJson.put("Version", version); extendedJson.put("ActiveProfile", profileFunction.getProfileName()); PumpState ps = pump.state; if (ps.tbrActive) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/PumpPluginAbstract.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/PumpPluginAbstract.java index 6d06f2e788..6227d2ea2a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/PumpPluginAbstract.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/PumpPluginAbstract.java @@ -324,7 +324,7 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI @NonNull @Override - public JSONObject getJSONStatus(Profile profile, String profileName) { + public JSONObject getJSONStatus(Profile profile, String profileName, String version) { if ((getPumpStatusData().lastConnection + 5 * 60 * 1000L) < System.currentTimeMillis()) { return new JSONObject(); @@ -337,7 +337,7 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI try { battery.put("percent", getPumpStatusData().batteryRemaining); status.put("status", getPumpStatusData().pumpStatusType != null ? getPumpStatusData().pumpStatusType.getStatus() : "normal"); - extended.put("Version", BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION); + extended.put("Version", version); try { extended.put("ActiveProfile", profileName); } catch (Exception ignored) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/AbstractDanaRPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/AbstractDanaRPlugin.java index b055cacda3..3e0a853dc5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/AbstractDanaRPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/AbstractDanaRPlugin.java @@ -366,7 +366,7 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump } @NonNull @Override - public JSONObject getJSONStatus(Profile profile, String profilename) { + public JSONObject getJSONStatus(Profile profile, String profilename, String version) { DanaRPump pump = danaRPump; long now = System.currentTimeMillis(); if (pump.getLastConnection() + 5 * 60 * 1000L < System.currentTimeMillis()) { @@ -380,7 +380,7 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump battery.put("percent", pump.getBatteryRemaining()); status.put("status", pump.getPumpSuspended() ? "suspended" : "normal"); status.put("timestamp", DateUtil.toISOString(pump.getLastConnection())); - extended.put("Version", BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION); + extended.put("Version", version); if (pump.getLastBolusTime() != 0) { extended.put("LastBolus", dateUtil.dateAndTimeString(pump.getLastBolusTime())); extended.put("LastBolusAmount", pump.getLastBolusAmount()); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MessageHashTableR.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MessageHashTableR.kt index dd4c59cee4..630bb9ecad 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MessageHashTableR.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MessageHashTableR.kt @@ -7,6 +7,7 @@ import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker +import info.nightscout.androidaps.plugins.general.nsclient.NSUpload import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin @@ -28,6 +29,7 @@ class MessageHashTableR @Inject constructor( configBuilderPlugin: ConfigBuilderPlugin, commandQueue: CommandQueueProvider, activePlugin: ActivePluginProvider, + nsUpload: NSUpload, injector: HasAndroidInjector, dateUtil: DateUtil ) : MessageHashTableBase { @@ -54,7 +56,7 @@ class MessageHashTableR @Inject constructor( put(MsgSetTempBasalStop(aapsLogger)) // 0x0403 CMD_PUMPSET_EXERCISE_STOP put(MsgSetExtendedBolusStop(aapsLogger)) // 0x0406 CMD_PUMPSET_EXPANS_INS_STOP put(MsgSetExtendedBolusStart(aapsLogger, constraintChecker, 0.0, 0)) // 0x0407 CMD_PUMPSET_EXPANS_INS_S - put(MsgError(aapsLogger, rxBus, resourceHelper, danaRPump)) // 0x0601 CMD_PUMPOWAY_SYSTEM_STATUS + put(MsgError(aapsLogger, rxBus, resourceHelper, danaRPump, nsUpload)) // 0x0601 CMD_PUMPOWAY_SYSTEM_STATUS put(MsgPCCommStart(aapsLogger)) // 0x3001 CMD_CONNECT put(MsgPCCommStop(aapsLogger)) // 0x3002 CMD_DISCONNECT put(MsgHistoryBolus(aapsLogger, rxBus, dateUtil)) // 0x3101 CMD_HISTORY_MEAL_INS diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgError.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgError.kt index 6069520870..08d4c57324 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgError.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgError.kt @@ -13,7 +13,8 @@ class MsgError( private val aapsLogger: AAPSLogger, private val rxBus: RxBusWrapper, private val resourceHelper: ResourceHelper, - private val danaRPump: DanaRPump + private val danaRPump: DanaRPump, + private val nsUpload: NSUpload ) : MessageBase() { init { @@ -41,6 +42,6 @@ class MsgError( failed = false } aapsLogger.debug(LTag.PUMPCOMM, "Error detected: $errorString") - NSUpload.uploadError(errorString) + nsUpload.uploadError(errorString) } } \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryAll.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryAll.kt index b25a5b9b1f..26f48639d2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryAll.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryAll.kt @@ -5,7 +5,7 @@ import info.nightscout.androidaps.db.DanaRHistoryRecord import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBusWrapper -import info.nightscout.androidaps.plugins.pump.danaR.events.EventDanaRSyncStatus +import info.nightscout.androidaps.events.EventDanaRSyncStatus import info.nightscout.androidaps.utils.DateUtil open class MsgHistoryAll( diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/services/DanaRExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/services/DanaRExecutionService.java index 73fe0ec10c..2a357761f5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/services/DanaRExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/services/DanaRExecutionService.java @@ -83,6 +83,7 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService { @Inject MessageHashTableR messageHashTableR; @Inject ActivePluginProvider activePlugin; @Inject ProfileFunction profileFunction; + @Inject NSUpload nsUpload; @Inject SP sp; @Inject HasAndroidInjector injector; @@ -214,7 +215,7 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService { if (System.currentTimeMillis() > lastApproachingDailyLimit + 30 * 60 * 1000) { Notification reportFail = new Notification(Notification.APPROACHING_DAILY_LIMIT, resourceHelper.gs(R.string.approachingdailylimit), Notification.URGENT); rxBus.send(new EventNewNotification(reportFail)); - NSUpload.uploadError(resourceHelper.gs(R.string.approachingdailylimit) + ": " + danaRPump.getDailyTotalUnits() + "/" + danaRPump.getMaxDailyTotalUnits() + "U"); + nsUpload.uploadError(resourceHelper.gs(R.string.approachingdailylimit) + ": " + danaRPump.getDailyTotalUnits() + "/" + danaRPump.getMaxDailyTotalUnits() + "U"); lastApproachingDailyLimit = System.currentTimeMillis(); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MessageHashTableRKorean.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MessageHashTableRKorean.kt index 882ab11739..67ce3eb6b4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MessageHashTableRKorean.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MessageHashTableRKorean.kt @@ -7,6 +7,7 @@ import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker +import info.nightscout.androidaps.plugins.general.nsclient.NSUpload import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump import info.nightscout.androidaps.plugins.pump.danaR.comm.* @@ -30,6 +31,7 @@ class MessageHashTableRKorean @Inject constructor( commandQueue: CommandQueueProvider, activePlugin: ActivePluginProvider, dateUtil: DateUtil, + nsUpload: NSUpload, injector: HasAndroidInjector ) : MessageHashTableBase { @@ -52,7 +54,7 @@ class MessageHashTableRKorean @Inject constructor( put(MsgSetTempBasalStop(aapsLogger)) // 0x0403 CMD_PUMPSET_EXERCISE_STOP put(MsgSetExtendedBolusStop(aapsLogger)) // 0x0406 CMD_PUMPSET_EXPANS_INS_STOP put(MsgSetExtendedBolusStart(aapsLogger, constraintChecker, 0.0, 0)) // 0x0407 CMD_PUMPSET_EXPANS_INS_S - put(MsgError(aapsLogger, rxBus, resourceHelper, danaRPump)) // 0x0601 CMD_PUMPOWAY_SYSTEM_STATUS + put(MsgError(aapsLogger, rxBus, resourceHelper, danaRPump, nsUpload)) // 0x0601 CMD_PUMPOWAY_SYSTEM_STATUS put(MsgPCCommStart(aapsLogger)) // 0x3001 CMD_CONNECT put(MsgPCCommStop(aapsLogger)) // 0x3002 CMD_DISCONNECT put(MsgHistoryBolus(aapsLogger, rxBus, dateUtil)) // 0x3101 CMD_HISTORY_MEAL_INS diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/services/DanaRKoreanExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/services/DanaRKoreanExecutionService.java index 2f00754404..d8da9b78c2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/services/DanaRKoreanExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/services/DanaRKoreanExecutionService.java @@ -75,6 +75,7 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService { @Inject MessageHashTableRKorean messageHashTableRKorean; @Inject ActivePluginProvider activePlugin; @Inject ProfileFunction profileFunction; + @Inject NSUpload nsUpload; @Inject DateUtil dateUtil; public DanaRKoreanExecutionService() { @@ -203,7 +204,7 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService { if (System.currentTimeMillis() > lastApproachingDailyLimit + 30 * 60 * 1000) { Notification reportFail = new Notification(Notification.APPROACHING_DAILY_LIMIT, resourceHelper.gs(R.string.approachingdailylimit), Notification.URGENT); rxBus.send(new EventNewNotification(reportFail)); - NSUpload.uploadError(resourceHelper.gs(R.string.approachingdailylimit) + ": " + danaRPump.getDailyTotalUnits() + "/" + danaRPump.getMaxDailyTotalUnits() + "U"); + nsUpload.uploadError(resourceHelper.gs(R.string.approachingdailylimit) + ": " + danaRPump.getDailyTotalUnits() + "/" + danaRPump.getMaxDailyTotalUnits() + "U"); lastApproachingDailyLimit = System.currentTimeMillis(); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MessageHashTableRv2.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MessageHashTableRv2.kt index 8833ea6b3f..836de3d6cc 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MessageHashTableRv2.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MessageHashTableRv2.kt @@ -7,6 +7,7 @@ import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker +import info.nightscout.androidaps.plugins.general.nsclient.NSUpload import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump @@ -35,6 +36,7 @@ class MessageHashTableRv2 @Inject constructor( activePlugin: ActivePluginProvider, detailedBolusInfoStorage: DetailedBolusInfoStorage, treatmentsPlugin: TreatmentsPlugin, + nsUpload: NSUpload, injector: HasAndroidInjector, dateUtil: DateUtil ) : MessageHashTableBase { @@ -60,7 +62,7 @@ class MessageHashTableRv2 @Inject constructor( put(MsgSetTempBasalStop(aapsLogger)) // 0x0403 CMD_PUMPSET_EXERCISE_STOP put(MsgSetExtendedBolusStop(aapsLogger)) // 0x0406 CMD_PUMPSET_EXPANS_INS_STOP put(MsgSetExtendedBolusStart(aapsLogger, constraintChecker, 0.0, 0)) // 0x0407 CMD_PUMPSET_EXPANS_INS_S - put(MsgError(aapsLogger, rxBus, resourceHelper, danaRPump)) // 0x0601 CMD_PUMPOWAY_SYSTEM_STATUS + put(MsgError(aapsLogger, rxBus, resourceHelper, danaRPump, nsUpload)) // 0x0601 CMD_PUMPOWAY_SYSTEM_STATUS put(MsgPCCommStart(aapsLogger)) // 0x3001 CMD_CONNECT put(MsgPCCommStop(aapsLogger)) // 0x3002 CMD_DISCONNECT put(MsgHistoryBolus(aapsLogger, rxBus, dateUtil)) // 0x3101 CMD_HISTORY_MEAL_INS diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/services/DanaRv2ExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/services/DanaRv2ExecutionService.java index 4c664ea1df..f072d3a8e1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/services/DanaRv2ExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/services/DanaRv2ExecutionService.java @@ -99,6 +99,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService { @Inject DetailedBolusInfoStorage detailedBolusInfoStorage; @Inject TreatmentsPlugin treatmentsPlugin; @Inject ProfileFunction profileFunction; + @Inject NSUpload nsUpload; @Inject SP sp; @Inject DateUtil dateUtil; @@ -255,7 +256,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService { if (System.currentTimeMillis() > lastApproachingDailyLimit + 30 * 60 * 1000) { Notification reportFail = new Notification(Notification.APPROACHING_DAILY_LIMIT, resourceHelper.gs(R.string.approachingdailylimit), Notification.URGENT); rxBus.send(new EventNewNotification(reportFail)); - NSUpload.uploadError(resourceHelper.gs(R.string.approachingdailylimit) + ": " + danaRPump.getDailyTotalUnits() + "/" + danaRPump.getMaxDailyTotalUnits() + "U"); + nsUpload.uploadError(resourceHelper.gs(R.string.approachingdailylimit) + ": " + danaRPump.getDailyTotalUnits() + "/" + danaRPump.getMaxDailyTotalUnits() + "U"); lastApproachingDailyLimit = System.currentTimeMillis(); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java index d44470bad1..f8d1cf1ce5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java @@ -27,7 +27,6 @@ import javax.inject.Inject; import javax.inject.Singleton; import dagger.android.HasAndroidInjector; -import info.nightscout.androidaps.BuildConfig; import info.nightscout.androidaps.Config; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; @@ -39,6 +38,7 @@ import info.nightscout.androidaps.db.ExtendedBolus; import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.db.TDD; import info.nightscout.androidaps.db.TemporaryBasal; +import info.nightscout.androidaps.db.Treatment; import info.nightscout.androidaps.events.EventInitializationChanged; import info.nightscout.androidaps.events.EventRefreshOverview; import info.nightscout.androidaps.interfaces.CommandQueueProvider; @@ -46,6 +46,7 @@ import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.ConstraintsInterface; import info.nightscout.androidaps.interfaces.PluginDescription; import info.nightscout.androidaps.interfaces.PluginType; +import info.nightscout.androidaps.interfaces.ProfileFunction; import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.interfaces.PumpPluginBase; @@ -53,7 +54,6 @@ import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.plugins.bus.RxBusWrapper; import info.nightscout.androidaps.plugins.common.ManufacturerType; -import info.nightscout.androidaps.interfaces.ProfileFunction; import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction; import info.nightscout.androidaps.plugins.general.actions.defs.CustomActionType; import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; @@ -132,7 +132,6 @@ import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_erro import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.NoActiveTBRToCanceLException; import info.nightscout.androidaps.plugins.pump.insight.utils.ExceptionTranslator; import info.nightscout.androidaps.plugins.pump.insight.utils.ParameterBlockUtil; -import info.nightscout.androidaps.db.Treatment; import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; import info.nightscout.androidaps.utils.DateUtil; import info.nightscout.androidaps.utils.TimeChangeType; @@ -149,7 +148,9 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface, private final SP sp; private final CommandQueueProvider commandQueue; private final ProfileFunction profileFunction; + private final NSUpload nsUpload; private final Context context; + private final UploadQueue uploadQueue; private final DateUtil dateUtil; public static final String ALERT_CHANNEL_ID = "AndroidAPS-InsightAlert"; @@ -209,7 +210,9 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface, SP sp, CommandQueueProvider commandQueue, ProfileFunction profileFunction, + NSUpload nsUpload, Context context, + UploadQueue uploadQueue, Config config, DateUtil dateUtil ) { @@ -230,7 +233,9 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface, this.sp = sp; this.commandQueue = commandQueue; this.profileFunction = profileFunction; + this.nsUpload = nsUpload; this.context = context; + this.uploadQueue = uploadQueue; this.dateUtil = dateUtil; pumpDescription = new PumpDescription(); @@ -929,8 +934,8 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface, if (extendedBolus.durationInMinutes <= 0) { final String _id = extendedBolus._id; if (NSUpload.isIdValid(_id)) - NSUpload.removeCareportalEntryFromNS(_id); - else UploadQueue.removeID("dbAdd", _id); + nsUpload.removeCareportalEntryFromNS(_id); + else uploadQueue.removeID("dbAdd", _id); MainApp.getDbHelper().delete(extendedBolus); } else treatmentsPlugin.addToHistoryExtendedBolus(extendedBolus); @@ -978,7 +983,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface, } @NonNull @Override - public JSONObject getJSONStatus(Profile profile, String profileName) { + public JSONObject getJSONStatus(Profile profile, String profileName, String version) { long now = System.currentTimeMillis(); if (connectionService == null) return null; if (System.currentTimeMillis() - connectionService.getLastConnected() > (60 * 60 * 1000)) { @@ -991,7 +996,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface, final JSONObject extended = new JSONObject(); try { status.put("timestamp", DateUtil.toISOString(connectionService.getLastConnected())); - extended.put("Version", BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION); + extended.put("Version", version); try { extended.put("ActiveProfile", profileFunction.getProfileName()); } catch (Exception e) { @@ -1451,8 +1456,8 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface, ExtendedBolus extendedBolus = MainApp.getDbHelper().getExtendedBolusByPumpId(bolusID.id); if (extendedBolus != null) { final String _id = extendedBolus._id; - if (NSUpload.isIdValid(_id)) NSUpload.removeCareportalEntryFromNS(_id); - else UploadQueue.removeID("dbAdd", _id); + if (NSUpload.isIdValid(_id)) nsUpload.removeCareportalEntryFromNS(_id); + else uploadQueue.removeID("dbAdd", _id); MainApp.getDbHelper().delete(extendedBolus); } } else { @@ -1583,7 +1588,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface, careportalEvent.eventType = CareportalEvent.NOTE; careportalEvent.json = data.toString(); MainApp.getDbHelper().createOrUpdate(careportalEvent); - NSUpload.uploadCareportalEntryToNS(data); + nsUpload.uploadCareportalEntryToNS(data); } catch (JSONException e) { aapsLogger.error("Unhandled exception", e); } @@ -1617,7 +1622,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface, careportalEvent.eventType = event; careportalEvent.json = data.toString(); MainApp.getDbHelper().createOrUpdate(careportalEvent); - NSUpload.uploadCareportalEntryToNS(data); + nsUpload.uploadCareportalEntryToNS(data); } catch (JSONException e) { aapsLogger.error("Unhandled exception", e); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/mdi/MDIPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/mdi/MDIPlugin.java index b5d7fafb4e..44550ebea6 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/mdi/MDIPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/mdi/MDIPlugin.java @@ -227,14 +227,14 @@ public class MDIPlugin extends PumpPluginBase implements PumpInterface { } @NonNull @Override - public JSONObject getJSONStatus(Profile profile, String profileName) { + public JSONObject getJSONStatus(Profile profile, String profileName, String version) { long now = System.currentTimeMillis(); JSONObject pump = new JSONObject(); JSONObject status = new JSONObject(); JSONObject extended = new JSONObject(); try { status.put("status", "normal"); - extended.put("Version", BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION); + extended.put("Version", version); try { extended.put("ActiveProfile", profileName); } catch (Exception e) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/MedtronicHistoryData.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/MedtronicHistoryData.java index d8f5c47b4f..76f011da16 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/MedtronicHistoryData.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/MedtronicHistoryData.java @@ -78,6 +78,7 @@ public class MedtronicHistoryData { private final AAPSLogger aapsLogger; private final SP sp; private final ActivePluginProvider activePlugin; + private final NSUpload nsUpload; private final MedtronicUtil medtronicUtil; private final MedtronicPumpHistoryDecoder medtronicPumpHistoryDecoder; @@ -106,6 +107,7 @@ public class MedtronicHistoryData { AAPSLogger aapsLogger, SP sp, ActivePluginProvider activePlugin, + NSUpload nsUpload, MedtronicUtil medtronicUtil, MedtronicPumpHistoryDecoder medtronicPumpHistoryDecoder ) { @@ -115,6 +117,7 @@ public class MedtronicHistoryData { this.aapsLogger = aapsLogger; this.sp = sp; this.activePlugin = activePlugin; + this.nsUpload = nsUpload; this.medtronicUtil = medtronicUtil; this.medtronicPumpHistoryDecoder = medtronicPumpHistoryDecoder; } @@ -543,7 +546,7 @@ public class MedtronicHistoryData { careportalEvent.eventType = event; careportalEvent.json = data.toString(); MainApp.getDbHelper().createOrUpdate(careportalEvent); - NSUpload.uploadCareportalEntryToNS(data); + nsUpload.uploadCareportalEntryToNS(data); } catch (JSONException e) { aapsLogger.error("Unhandled exception", e); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/pages/InitPodRefreshAction.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/pages/InitPodRefreshAction.java index 37c6d420f7..70dac25789 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/pages/InitPodRefreshAction.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/pages/InitPodRefreshAction.java @@ -35,6 +35,7 @@ public class InitPodRefreshAction extends AbstractCancelAction implements Finish @Inject OmnipodUtil omnipodUtil; @Inject AAPSLogger aapsLogger; @Inject SP sp; + @Inject NSUpload nsUpload; public InitPodRefreshAction(HasAndroidInjector injector, PodManagementActivity podManagementActivity, PodActionType actionType) { injector.androidInjector().inject(this); @@ -86,7 +87,7 @@ public class InitPodRefreshAction extends AbstractCancelAction implements Finish careportalEvent.eventType = event; careportalEvent.json = data.toString(); MainApp.getDbHelper().createOrUpdate(careportalEvent); - NSUpload.uploadCareportalEntryToNS(data); + nsUpload.uploadCareportalEntryToNS(data); } catch (JSONException e) { aapsLogger.error(LTag.PUMPCOMM, "Unhandled exception when uploading SiteChange event.", e); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPlugin.kt index 3db377a230..e8916b5647 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPlugin.kt @@ -337,7 +337,7 @@ class VirtualPumpPlugin @Inject constructor( return result } - override fun getJSONStatus(profile: Profile, profileName: String): JSONObject { + override fun getJSONStatus(profile: Profile, profileName: String, version: String): JSONObject { val now = System.currentTimeMillis() if (!sp.getBoolean("virtualpump_uploadstatus", false)) { return JSONObject() @@ -349,7 +349,7 @@ class VirtualPumpPlugin @Inject constructor( try { battery.put("percent", batteryPercent) status.put("status", "normal") - extended.put("Version", BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION) + extended.put("Version", version) try { extended.put("ActiveProfile", profileName) } catch (ignored: Exception) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/source/DexcomPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/source/DexcomPlugin.kt index 7e854f7e96..41d1c07ddc 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/source/DexcomPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/source/DexcomPlugin.kt @@ -31,7 +31,8 @@ class DexcomPlugin @Inject constructor( private val sp: SP, private val mainApp: MainApp, resourceHelper: ResourceHelper, - aapsLogger: AAPSLogger + aapsLogger: AAPSLogger, + private val nsUpload: NSUpload ) : PluginBase(PluginDescription() .mainType(PluginType.BGSOURCE) .fragmentClass(BGSourceFragment::class.java.name) @@ -78,10 +79,10 @@ class DexcomPlugin @Inject constructor( bgReading.raw = 0.0 if (MainApp.getDbHelper().createIfNotExists(bgReading, "Dexcom$sensorType")) { if (sp.getBoolean(R.string.key_dexcomg5_nsupload, false)) { - NSUpload.uploadBg(bgReading, "AndroidAPS-Dexcom$sensorType") + nsUpload.uploadBg(bgReading, "AndroidAPS-Dexcom$sensorType") } if (sp.getBoolean(R.string.key_dexcomg5_xdripupload, false)) { - NSUpload.sendToXdrip(bgReading) + nsUpload.sendToXdrip(bgReading) } } } @@ -108,7 +109,7 @@ class DexcomPlugin @Inject constructor( careportalEvent.eventType = CareportalEvent.BGCHECK careportalEvent.json = jsonObject.toString() MainApp.getDbHelper().createOrUpdate(careportalEvent) - NSUpload.uploadCareportalEntryToNS(jsonObject) + nsUpload.uploadCareportalEntryToNS(jsonObject) } } } @@ -128,7 +129,7 @@ class DexcomPlugin @Inject constructor( careportalEvent.eventType = CareportalEvent.SENSORCHANGE careportalEvent.json = jsonObject.toString() MainApp.getDbHelper().createOrUpdate(careportalEvent) - NSUpload.uploadCareportalEntryToNS(jsonObject) + nsUpload.uploadCareportalEntryToNS(jsonObject) } } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/source/EversensePlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/source/EversensePlugin.kt index 6b0021fbcf..9141d57214 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/source/EversensePlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/source/EversensePlugin.kt @@ -29,7 +29,8 @@ class EversensePlugin @Inject constructor( private val sp: SP, resourceHelper: ResourceHelper, aapsLogger: AAPSLogger, - private val dateUtil: DateUtil + private val dateUtil: DateUtil, + private val nsUpload: NSUpload ) : PluginBase(PluginDescription() .mainType(PluginType.BGSOURCE) .fragmentClass(BGSourceFragment::class.java.name) @@ -77,10 +78,10 @@ class EversensePlugin @Inject constructor( bgReading.raw = 0.0 val isNew = MainApp.getDbHelper().createIfNotExists(bgReading, "Eversense") if (isNew && sp.getBoolean(R.string.key_dexcomg5_nsupload, false)) { - NSUpload.uploadBg(bgReading, "AndroidAPS-Eversense") + nsUpload.uploadBg(bgReading, "AndroidAPS-Eversense") } if (isNew && sp.getBoolean(R.string.key_dexcomg5_xdripupload, false)) { - NSUpload.sendToXdrip(bgReading) + nsUpload.sendToXdrip(bgReading) } } } @@ -103,7 +104,7 @@ class EversensePlugin @Inject constructor( data.put("glucoseType", "Finger") data.put("glucose", calibrationGlucoseLevels[i]) data.put("units", Constants.MGDL) - NSUpload.uploadCareportalEntryToNS(data) + nsUpload.uploadCareportalEntryToNS(data) } } catch (e: JSONException) { aapsLogger.error("Unhandled exception", e) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/source/PoctechPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/source/PoctechPlugin.kt index c33cfaee0f..2032dd4479 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/source/PoctechPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/source/PoctechPlugin.kt @@ -26,7 +26,8 @@ class PoctechPlugin @Inject constructor( injector: HasAndroidInjector, resourceHelper: ResourceHelper, aapsLogger: AAPSLogger, - private val sp: SP + private val sp: SP, + private val nsUpload: NSUpload ) : PluginBase(PluginDescription() .mainType(PluginType.BGSOURCE) .fragmentClass(BGSourceFragment::class.java.name) @@ -58,10 +59,10 @@ class PoctechPlugin @Inject constructor( if (safeGetString(json, "units", Constants.MGDL) == "mmol/L") bgReading.value = bgReading.value * Constants.MMOLL_TO_MGDL val isNew = MainApp.getDbHelper().createIfNotExists(bgReading, "Poctech") if (isNew && sp.getBoolean(R.string.key_dexcomg5_nsupload, false)) { - NSUpload.uploadBg(bgReading, "AndroidAPS-Poctech") + nsUpload.uploadBg(bgReading, "AndroidAPS-Poctech") } if (isNew && sp.getBoolean(R.string.key_dexcomg5_xdripupload, false)) { - NSUpload.sendToXdrip(bgReading) + nsUpload.sendToXdrip(bgReading) } } } catch (e: JSONException) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/source/TomatoPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/source/TomatoPlugin.kt index db4c658614..1ba7958b61 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/source/TomatoPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/source/TomatoPlugin.kt @@ -22,7 +22,8 @@ class TomatoPlugin @Inject constructor( injector: HasAndroidInjector, resourceHelper: ResourceHelper, aapsLogger: AAPSLogger, - private val sp: SP + private val sp: SP, + private val nsUpload: NSUpload ) : PluginBase(PluginDescription() .mainType(PluginType.BGSOURCE) .fragmentClass(BGSourceFragment::class.java.name) @@ -46,10 +47,10 @@ class TomatoPlugin @Inject constructor( bgReading.date = bundle.getLong("com.fanqies.tomatofn.Extras.Time") val isNew = MainApp.getDbHelper().createIfNotExists(bgReading, "Tomato") if (isNew && sp.getBoolean(R.string.key_dexcomg5_nsupload, false)) { - NSUpload.uploadBg(bgReading, "AndroidAPS-Tomato") + nsUpload.uploadBg(bgReading, "AndroidAPS-Tomato") } if (isNew && sp.getBoolean(R.string.key_dexcomg5_xdripupload, false)) { - NSUpload.sendToXdrip(bgReading) + nsUpload.sendToXdrip(bgReading) } } } \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsBolusFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsBolusFragment.kt index 63574ea8d2..e6d2f02883 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsBolusFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsBolusFragment.kt @@ -42,6 +42,8 @@ class TreatmentsBolusFragment : DaggerFragment() { @Inject lateinit var fabricPrivacy: FabricPrivacy @Inject lateinit var treatmentsPlugin: TreatmentsPlugin @Inject lateinit var profileFunction: ProfileFunction + @Inject lateinit var nsUpload: NSUpload + @Inject lateinit var uploadQueue: UploadQueue @Inject lateinit var dateUtil: DateUtil override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, @@ -68,9 +70,9 @@ class TreatmentsBolusFragment : DaggerFragment() { val futureTreatments = treatmentsPlugin.service.getTreatmentDataFromTime(DateUtil.now() + 1000, true) for (treatment in futureTreatments) { if (NSUpload.isIdValid(treatment._id)) - NSUpload.removeCareportalEntryFromNS(treatment._id) + nsUpload.removeCareportalEntryFromNS(treatment._id) else - UploadQueue.removeID("dbAdd", treatment._id) + uploadQueue.removeID("dbAdd", treatment._id) treatmentsPlugin.service.delete(treatment) } updateGui() @@ -166,9 +168,9 @@ class TreatmentsBolusFragment : DaggerFragment() { treatmentsPlugin.service.update(treatment) } else { if (NSUpload.isIdValid(treatment._id)) - NSUpload.removeCareportalEntryFromNS(treatment._id) + nsUpload.removeCareportalEntryFromNS(treatment._id) else - UploadQueue.removeID("dbAdd", treatment._id) + uploadQueue.removeID("dbAdd", treatment._id) treatmentsPlugin.service.delete(treatment) } updateGui() diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsCareportalFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsCareportalFragment.kt index 9307238211..191957a8f3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsCareportalFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsCareportalFragment.kt @@ -38,6 +38,8 @@ class TreatmentsCareportalFragment : DaggerFragment() { @Inject lateinit var resourceHelper: ResourceHelper @Inject lateinit var fabricPrivacy: FabricPrivacy @Inject lateinit var translator: Translator + @Inject lateinit var nsUpload: NSUpload + @Inject lateinit var uploadQueue: UploadQueue @Inject lateinit var dateUtil: DateUtil override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, @@ -66,9 +68,9 @@ class TreatmentsCareportalFragment : DaggerFragment() { val careportalEvent = events[i] if (careportalEvent.json.contains(resourceHelper.gs(R.string.androidaps_start))) { if (NSUpload.isIdValid(careportalEvent._id)) - NSUpload.removeCareportalEntryFromNS(careportalEvent._id) + nsUpload.removeCareportalEntryFromNS(careportalEvent._id) else - UploadQueue.removeID("dbAdd", careportalEvent._id) + uploadQueue.removeID("dbAdd", careportalEvent._id) MainApp.getDbHelper().delete(careportalEvent) } } @@ -136,9 +138,9 @@ class TreatmentsCareportalFragment : DaggerFragment() { resourceHelper.gs(R.string.date) + ": " + dateUtil.dateAndTimeString(careportalEvent.date) OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.removerecord), text, Runnable { if (NSUpload.isIdValid(careportalEvent._id)) - NSUpload.removeCareportalEntryFromNS(careportalEvent._id) + nsUpload.removeCareportalEntryFromNS(careportalEvent._id) else - UploadQueue.removeID("dbAdd", careportalEvent._id) + uploadQueue.removeID("dbAdd", careportalEvent._id) MainApp.getDbHelper().delete(careportalEvent) }, null) } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsExtendedBolusesFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsExtendedBolusesFragment.kt index d2dcd632ea..91e3b098fc 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsExtendedBolusesFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsExtendedBolusesFragment.kt @@ -40,6 +40,8 @@ class TreatmentsExtendedBolusesFragment : DaggerFragment() { @Inject lateinit var rxBus: RxBusWrapper @Inject lateinit var resourceHelper: ResourceHelper @Inject lateinit var fabricPrivacy: FabricPrivacy + @Inject lateinit var nsUpload: NSUpload + @Inject lateinit var uploadQueue: UploadQueue @Inject lateinit var dateUtil: DateUtil override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, @@ -116,8 +118,8 @@ class TreatmentsExtendedBolusesFragment : DaggerFragment() { ${resourceHelper.gs(R.string.date)}: ${dateUtil.dateAndTimeString(extendedBolus.date)} """.trimIndent(), DialogInterface.OnClickListener { _: DialogInterface, _: Int -> val id = extendedBolus._id - if (NSUpload.isIdValid(id)) NSUpload.removeCareportalEntryFromNS(id) - else UploadQueue.removeID("dbAdd", id) + if (NSUpload.isIdValid(id)) nsUpload.removeCareportalEntryFromNS(id) + else uploadQueue.removeID("dbAdd", id) MainApp.getDbHelper().delete(extendedBolus) }, null) } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsProfileSwitchFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsProfileSwitchFragment.kt index 77934e304c..886c0ec34e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsProfileSwitchFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsProfileSwitchFragment.kt @@ -43,6 +43,8 @@ class TreatmentsProfileSwitchFragment : DaggerFragment() { @Inject lateinit var localProfilePlugin: LocalProfilePlugin @Inject lateinit var resourceHelper: ResourceHelper @Inject lateinit var fabricPrivacy: FabricPrivacy + @Inject lateinit var nsUpload: NSUpload + @Inject lateinit var uploadQueue: UploadQueue @Inject lateinit var dateUtil: DateUtil override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, @@ -135,8 +137,8 @@ class TreatmentsProfileSwitchFragment : DaggerFragment() { resourceHelper.gs(R.string.careportal_profileswitch) + ": " + profileSwitch.profileName + "\n" + resourceHelper.gs(R.string.date) + ": " + dateUtil.dateAndTimeString(profileSwitch.date), Runnable { val id = profileSwitch._id - if (NSUpload.isIdValid(id)) NSUpload.removeCareportalEntryFromNS(id) - else UploadQueue.removeID("dbAdd", id) + if (NSUpload.isIdValid(id)) nsUpload.removeCareportalEntryFromNS(id) + else uploadQueue.removeID("dbAdd", id) MainApp.getDbHelper().delete(profileSwitch) }) } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsTempTargetFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsTempTargetFragment.java index 7df7db72be..980e9efe7d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsTempTargetFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsTempTargetFragment.java @@ -47,6 +47,8 @@ public class TreatmentsTempTargetFragment extends DaggerFragment { @Inject RxBusWrapper rxBus; @Inject ProfileFunction profileFunction; @Inject ResourceHelper resourceHelper; + @Inject NSUpload nsUpload; + @Inject UploadQueue uploadQueue; @Inject FabricPrivacy fabricPrivacy; @Inject DateUtil dateUtil; @@ -146,9 +148,9 @@ public class TreatmentsTempTargetFragment extends DaggerFragment { (dialog, id) -> { final String _id = tempTarget._id; if (NSUpload.isIdValid(_id)) { - NSUpload.removeCareportalEntryFromNS(_id); + nsUpload.removeCareportalEntryFromNS(_id); } else { - UploadQueue.removeID("dbAdd", _id); + uploadQueue.removeID("dbAdd", _id); } MainApp.getDbHelper().delete(tempTarget); }, null); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsTemporaryBasalsFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsTemporaryBasalsFragment.kt index 4ff6b15950..8b8aee6b91 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsTemporaryBasalsFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsTemporaryBasalsFragment.kt @@ -44,6 +44,8 @@ class TreatmentsTemporaryBasalsFragment : DaggerFragment() { @Inject lateinit var fabricPrivacy: FabricPrivacy @Inject lateinit var activePlugin: ActivePluginProvider @Inject lateinit var profileFunction: ProfileFunction + @Inject lateinit var nsUpload: NSUpload + @Inject lateinit var uploadQueue: UploadQueue @Inject lateinit var dateUtil: DateUtil override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, @@ -165,8 +167,8 @@ class TreatmentsTemporaryBasalsFragment : DaggerFragment() { """.trimIndent(), DialogInterface.OnClickListener { _: DialogInterface?, _: Int -> val id = tempBasal._id - if (NSUpload.isIdValid(id)) NSUpload.removeCareportalEntryFromNS(id) - else UploadQueue.removeID("dbAdd", id) + if (NSUpload.isIdValid(id)) nsUpload.removeCareportalEntryFromNS(id) + else uploadQueue.removeID("dbAdd", id) MainApp.getDbHelper().delete(tempBasal) }, null) } diff --git a/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.kt b/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.kt index a3dda44325..b6705ac733 100644 --- a/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.kt +++ b/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.kt @@ -8,15 +8,16 @@ import android.content.Intent import android.os.PowerManager import android.os.SystemClock import dagger.android.DaggerBroadcastReceiver +import info.nightscout.androidaps.BuildConfig import info.nightscout.androidaps.Config import info.nightscout.androidaps.events.EventProfileNeedsUpdate import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.interfaces.CommandQueueProvider +import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin import info.nightscout.androidaps.plugins.bus.RxBusWrapper -import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.plugins.general.nsclient.NSUpload import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin import info.nightscout.androidaps.queue.commands.Command @@ -39,6 +40,7 @@ class KeepAliveReceiver : DaggerBroadcastReceiver() { @Inject lateinit var fabricPrivacy: FabricPrivacy @Inject lateinit var receiverStatusStore: ReceiverStatusStore @Inject lateinit var config: Config + @Inject lateinit var nsUpload: NSUpload @Inject lateinit var dateUtil: DateUtil companion object { @@ -108,7 +110,7 @@ class KeepAliveReceiver : DaggerBroadcastReceiver() { else if (DateUtil.isOlderThan(activePlugin.activeAPS.lastAPSRun, 5)) shouldUploadStatus = true if (DateUtil.isOlderThan(lastIobUpload, IOB_UPDATE_FREQUENCY) && shouldUploadStatus) { lastIobUpload = DateUtil.now() - NSUpload.uploadDeviceStatus(loopPlugin, iobCobCalculatorPlugin, profileFunction, activePlugin.activePump, receiverStatusStore) + nsUpload.uploadDeviceStatus(loopPlugin, iobCobCalculatorPlugin, profileFunction, activePlugin.activePump, receiverStatusStore, BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION) } } diff --git a/app/src/main/java/info/nightscout/androidaps/services/DataService.java b/app/src/main/java/info/nightscout/androidaps/services/DataService.java index 83891275a2..cf1833e892 100644 --- a/app/src/main/java/info/nightscout/androidaps/services/DataService.java +++ b/app/src/main/java/info/nightscout/androidaps/services/DataService.java @@ -20,6 +20,7 @@ import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.BundleLogger; import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.plugins.bus.RxBusWrapper; +import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; import info.nightscout.androidaps.plugins.general.nsclient.data.NSMbg; import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; @@ -42,6 +43,7 @@ public class DataService extends DaggerIntentService { @Inject AAPSLogger aapsLogger; @Inject SP sp; @Inject RxBusWrapper rxBus; + @Inject NSUpload nsUpload; @Inject SmsCommunicatorPlugin smsCommunicatorPlugin; @Inject DexcomPlugin dexcomPlugin; @Inject EversensePlugin eversensePlugin; @@ -210,7 +212,7 @@ public class DataService extends DaggerIntentService { } else if (eventType.equals(CareportalEvent.COMBOBOLUS)) { MainApp.getDbHelper().createExtendedBolusFromJsonIfNotExists(json); } else if (eventType.equals(CareportalEvent.PROFILESWITCH)) { - MainApp.getDbHelper().createProfileSwitchFromJsonIfNotExists(activePlugin, json); + MainApp.getDbHelper().createProfileSwitchFromJsonIfNotExists(activePlugin, nsUpload, json); } else if (eventType.equals(CareportalEvent.SITECHANGE) || eventType.equals(CareportalEvent.INSULINCHANGE) || eventType.equals(CareportalEvent.SENSORCHANGE) || diff --git a/app/src/main/java/info/nightscout/androidaps/utils/HardLimits.kt b/app/src/main/java/info/nightscout/androidaps/utils/HardLimits.kt index c9e2835ceb..bec9c0fa16 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/HardLimits.kt +++ b/app/src/main/java/info/nightscout/androidaps/utils/HardLimits.kt @@ -12,11 +12,12 @@ import javax.inject.Singleton @Singleton class HardLimits @Inject constructor( - val aapsLogger: AAPSLogger, - val rxBus: RxBusWrapper, - val sp: SP, - val resourceHelper: ResourceHelper, - val context: Context + private val aapsLogger: AAPSLogger, + private val rxBus: RxBusWrapper, + private val sp: SP, + private val resourceHelper: ResourceHelper, + private val context: Context, + private val nsUpload: NSUpload ) { val CHILD = 0 @@ -90,7 +91,7 @@ class HardLimits @Inject constructor( msg += ".\n" msg += String.format(resourceHelper.gs(R.string.valuelimitedto), value, newvalue) aapsLogger.error(msg) - NSUpload.uploadError(msg) + nsUpload.uploadError(msg) ToastUtils.showToastInUiThread(context, rxBus, msg, R.raw.error) } return newvalue diff --git a/app/src/main/java/info/nightscout/androidaps/utils/LocalAlertUtils.kt b/app/src/main/java/info/nightscout/androidaps/utils/LocalAlertUtils.kt index eff444aa6e..f5ac9d64ce 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/LocalAlertUtils.kt +++ b/app/src/main/java/info/nightscout/androidaps/utils/LocalAlertUtils.kt @@ -31,6 +31,7 @@ class LocalAlertUtils @Inject constructor( private val profileFunction: ProfileFunction, private val iobCobCalculatorPlugin: IobCobCalculatorPlugin, private val config: Config, + private val nsUpload: NSUpload, private val dateUtil: DateUtil ) { @@ -53,7 +54,7 @@ class LocalAlertUtils @Inject constructor( sp.putLong("nextPumpDisconnectedAlarm", System.currentTimeMillis() + pumpUnreachableThreshold()) rxBus.send(EventNewNotification(n)) if (sp.getBoolean(R.string.key_ns_create_announcements_from_errors, true)) { - NSUpload.uploadError(n.text) + nsUpload.uploadError(n.text) } } if (!isStatusOutdated && !alarmTimeoutExpired) rxBus.send(EventDismissNotification(Notification.PUMP_UNREACHABLE)) @@ -101,7 +102,7 @@ class LocalAlertUtils @Inject constructor( sp.putLong("nextMissedReadingsAlarm", System.currentTimeMillis() + missedReadingsThreshold()) rxBus.send(EventNewNotification(n)) if (sp.getBoolean(R.string.key_ns_create_announcements_from_errors, true)) { - NSUpload.uploadError(n.text) + nsUpload.uploadError(n.text) } } } diff --git a/app/src/main/java/info/nightscout/androidaps/utils/stats/TddCalculator.kt b/app/src/main/java/info/nightscout/androidaps/utils/stats/TddCalculator.kt index 6ee3024fc6..1e567dd94a 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/stats/TddCalculator.kt +++ b/app/src/main/java/info/nightscout/androidaps/utils/stats/TddCalculator.kt @@ -11,6 +11,7 @@ import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.interfaces.ProfileFunction +import info.nightscout.androidaps.plugins.general.nsclient.NSUpload import info.nightscout.androidaps.plugins.treatments.TreatmentService import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin import info.nightscout.androidaps.utils.DateUtil @@ -32,8 +33,9 @@ class TddCalculator @Inject constructor( val activePlugin: ActivePluginProvider, val profileFunction: ProfileFunction, fabricPrivacy: FabricPrivacy, + nsUpload: NSUpload, private val dateUtil: DateUtil -) : TreatmentsPlugin(injector, aapsLogger, rxBus, resourceHelper, mainApp, sp, profileFunction, activePlugin, fabricPrivacy, dateUtil) { +) : TreatmentsPlugin(injector, aapsLogger, rxBus, resourceHelper, mainApp, sp, profileFunction, activePlugin, nsUpload, fabricPrivacy, dateUtil) { init { service = TreatmentService(injector) // plugin is not started diff --git a/app/src/main/res/layout/okcancel.xml b/app/src/main/res/layout/okcancel.xml new file mode 100644 index 0000000000..f1322fd566 --- /dev/null +++ b/app/src/main/res/layout/okcancel.xml @@ -0,0 +1,44 @@ + + + + +