From c311d593c13948d0ac24dd30e86a1c9058691c62 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Fri, 15 May 2020 08:20:09 +0200 Subject: [PATCH 1/8] show actions tab in NSC --- .../nightscout/androidaps/dependencyInjection/PluginsModule.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/PluginsModule.kt b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/PluginsModule.kt index 1e02c6100d..f179580a55 100644 --- a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/PluginsModule.kt +++ b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/PluginsModule.kt @@ -64,7 +64,7 @@ abstract class PluginsModule { abstract fun bindIobCobCalculatorPlugin(plugin: IobCobCalculatorPlugin): PluginBase @Binds - @NotNSClient + @AllConfigs @IntoMap @IntKey(20) abstract fun bindActionsPlugin(plugin: ActionsPlugin): PluginBase From e98e5ec9def030bcc5ce6969c5a36be4b006afab Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Fri, 15 May 2020 21:50:40 +0200 Subject: [PATCH 2/8] fix danars parsing history --- .../danars/comm/DanaRS_Packet_History_.kt | 50 ++++++++++++------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_History_.kt b/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_History_.kt index 5026d117d6..c5a0b40ceb 100644 --- a/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_History_.kt +++ b/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_History_.kt @@ -1,12 +1,12 @@ package info.nightscout.androidaps.danars.comm import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.dana.comm.RecordTypes import info.nightscout.androidaps.db.DanaRHistoryRecord +import info.nightscout.androidaps.events.EventDanaRSyncStatus import info.nightscout.androidaps.interfaces.DatabaseHelperInterface import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBusWrapper -import info.nightscout.androidaps.dana.comm.RecordTypes -import info.nightscout.androidaps.events.EventDanaRSyncStatus import org.joda.time.DateTime import java.util.* import javax.inject.Inject @@ -83,20 +83,17 @@ abstract class DanaRS_Packet_History_( val historySecond = byteArrayToInt(getBytes(data, DATA_START + 6, 1)) val paramByte7 = historySecond.toByte() val dailyBolus: Double = ((data[DATA_START + 6].toInt() and 0xFF shl 8) + (data[DATA_START + 7].toInt() and 0xFF)) * 0.01 - val date = DateTime(2000 + historyYear, historyMonth, historyDay, 0, 0) - val datetime = DateTime(2000 + historyYear, historyMonth, historyDay, historyHour, historyMinute) - val datetimewihtsec = DateTime(2000 + historyYear, historyMonth, historyDay, historyHour, historyMinute, historySecond) val historyCode = byteArrayToInt(getBytes(data, DATA_START + 7, 1)) val paramByte8 = historyCode.toByte() val value: Int = (data[DATA_START + 8].toInt() and 0xFF shl 8) + (data[DATA_START + 9].toInt() and 0xFF) - aapsLogger.debug(LTag.PUMPCOMM, "History packet: " + recordCode + " Date: " + dateUtil.dateAndTimeString(datetimewihtsec.millis) + " Code: " + historyCode + " Value: " + value) danaRHistoryRecord.setBytes(data) // danaRHistoryRecord.recordCode is different from DanaR codes -// set in switch for every type + // set in switch for every type var messageType = "" when (recordCode) { 0x02 -> { - danaRHistoryRecord.recordCode = info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_BOLUS + danaRHistoryRecord.recordCode = RecordTypes.RECORD_TYPE_BOLUS + val datetime = DateTime(2000 + historyYear, historyMonth, historyDay, historyHour, historyMinute) danaRHistoryRecord.recordDate = datetime.millis when (0xF0 and paramByte8.toInt()) { 0xA0 -> { @@ -123,61 +120,77 @@ abstract class DanaRS_Packet_History_( } danaRHistoryRecord.recordDuration = (paramByte8.toInt() and 0x0F) * 60 + paramByte7.toInt() danaRHistoryRecord.recordValue = value * 0.01 + aapsLogger.debug(LTag.PUMPCOMM, "History packet: " + recordCode + " Date: " + dateUtil.dateAndTimeString(datetime.millis) + " Code: " + historyCode + " Value: " + value) } 0x03 -> { - danaRHistoryRecord.recordCode = info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_DAILY + danaRHistoryRecord.recordCode = RecordTypes.RECORD_TYPE_DAILY messageType += "dailyinsulin" + val date = DateTime(2000 + historyYear, historyMonth, historyDay, 0, 0) danaRHistoryRecord.recordDate = date.millis danaRHistoryRecord.recordDailyBasal = dailyBasal danaRHistoryRecord.recordDailyBolus = dailyBolus + aapsLogger.debug(LTag.PUMPCOMM, "History packet: " + recordCode + " Date: " + dateUtil.dateAndTimeString(date.millis) + " Code: " + historyCode + " Value: " + value) } 0x04 -> { - danaRHistoryRecord.recordCode = info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_PRIME + danaRHistoryRecord.recordCode = RecordTypes.RECORD_TYPE_PRIME messageType += "prime" + val datetimewihtsec = DateTime(2000 + historyYear, historyMonth, historyDay, historyHour, historyMinute, historySecond) danaRHistoryRecord.recordDate = datetimewihtsec.millis danaRHistoryRecord.recordValue = value * 0.01 + aapsLogger.debug(LTag.PUMPCOMM, "History packet: " + recordCode + " Date: " + dateUtil.dateAndTimeString(datetimewihtsec.millis) + " Code: " + historyCode + " Value: " + value) } 0x05 -> { - danaRHistoryRecord.recordCode = info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_REFILL + danaRHistoryRecord.recordCode = RecordTypes.RECORD_TYPE_REFILL messageType += "refill" + val datetimewihtsec = DateTime(2000 + historyYear, historyMonth, historyDay, historyHour, historyMinute, historySecond) danaRHistoryRecord.recordDate = datetimewihtsec.millis danaRHistoryRecord.recordValue = value * 0.01 + aapsLogger.debug(LTag.PUMPCOMM, "History packet: " + recordCode + " Date: " + dateUtil.dateAndTimeString(datetimewihtsec.millis) + " Code: " + historyCode + " Value: " + value) } 0x0b -> { - danaRHistoryRecord.recordCode = info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_BASALHOUR + danaRHistoryRecord.recordCode = RecordTypes.RECORD_TYPE_BASALHOUR messageType += "basal hour" + val datetimewihtsec = DateTime(2000 + historyYear, historyMonth, historyDay, historyHour, historyMinute, historySecond) danaRHistoryRecord.recordDate = datetimewihtsec.millis danaRHistoryRecord.recordValue = value * 0.01 + aapsLogger.debug(LTag.PUMPCOMM, "History packet: " + recordCode + " Date: " + dateUtil.dateAndTimeString(datetimewihtsec.millis) + " Code: " + historyCode + " Value: " + value) } 0x99 -> { - danaRHistoryRecord.recordCode = info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_TEMP_BASAL + danaRHistoryRecord.recordCode = RecordTypes.RECORD_TYPE_TEMP_BASAL messageType += "tb" + val datetimewihtsec = DateTime(2000 + historyYear, historyMonth, historyDay, historyHour, historyMinute, historySecond) danaRHistoryRecord.recordDate = datetimewihtsec.millis danaRHistoryRecord.recordValue = value * 0.01 + aapsLogger.debug(LTag.PUMPCOMM, "History packet: " + recordCode + " Date: " + dateUtil.dateAndTimeString(datetimewihtsec.millis) + " Code: " + historyCode + " Value: " + value) } 0x06 -> { - danaRHistoryRecord.recordCode = info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_GLUCOSE + danaRHistoryRecord.recordCode = RecordTypes.RECORD_TYPE_GLUCOSE messageType += "glucose" + val datetimewihtsec = DateTime(2000 + historyYear, historyMonth, historyDay, historyHour, historyMinute, historySecond) danaRHistoryRecord.recordDate = datetimewihtsec.millis danaRHistoryRecord.recordValue = value.toDouble() + aapsLogger.debug(LTag.PUMPCOMM, "History packet: " + recordCode + " Date: " + dateUtil.dateAndTimeString(datetimewihtsec.millis) + " Code: " + historyCode + " Value: " + value) } 0x07 -> { - danaRHistoryRecord.recordCode = info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_CARBO + danaRHistoryRecord.recordCode = RecordTypes.RECORD_TYPE_CARBO messageType += "carbo" + val datetimewihtsec = DateTime(2000 + historyYear, historyMonth, historyDay, historyHour, historyMinute, historySecond) danaRHistoryRecord.recordDate = datetimewihtsec.millis danaRHistoryRecord.recordValue = value.toDouble() + aapsLogger.debug(LTag.PUMPCOMM, "History packet: " + recordCode + " Date: " + dateUtil.dateAndTimeString(datetimewihtsec.millis) + " Code: " + historyCode + " Value: " + value) } 0x0a -> { - danaRHistoryRecord.recordCode = info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_ALARM + danaRHistoryRecord.recordCode = RecordTypes.RECORD_TYPE_ALARM messageType += "alarm" + val datetimewihtsec = DateTime(2000 + historyYear, historyMonth, historyDay, historyHour, historyMinute, historySecond) danaRHistoryRecord.recordDate = datetimewihtsec.millis var strAlarm = "None" when (paramByte8.toInt()) { @@ -188,15 +201,18 @@ abstract class DanaRS_Packet_History_( } danaRHistoryRecord.recordAlarm = strAlarm danaRHistoryRecord.recordValue = value * 0.01 + aapsLogger.debug(LTag.PUMPCOMM, "History packet: " + recordCode + " Date: " + dateUtil.dateAndTimeString(datetimewihtsec.millis) + " Code: " + historyCode + " Value: " + value) } 0x09 -> { - danaRHistoryRecord.recordCode = info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_SUSPEND + danaRHistoryRecord.recordCode = RecordTypes.RECORD_TYPE_SUSPEND messageType += "suspend" + val datetimewihtsec = DateTime(2000 + historyYear, historyMonth, historyDay, historyHour, historyMinute, historySecond) danaRHistoryRecord.recordDate = datetimewihtsec.millis var strRecordValue = "Off" if (paramByte8.toInt() == 79) strRecordValue = "On" danaRHistoryRecord.stringRecordValue = strRecordValue + aapsLogger.debug(LTag.PUMPCOMM, "History packet: " + recordCode + " Date: " + dateUtil.dateAndTimeString(datetimewihtsec.millis) + " Code: " + historyCode + " Value: " + value) } } databaseHelper.createOrUpdate(danaRHistoryRecord) From ca94e6cc67654abe47f8d1b29092a40d0792cd64 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Fri, 15 May 2020 22:41:14 +0200 Subject: [PATCH 3/8] layout #2 --- .../androidaps/plugins/general/overview/OverviewFragment.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 232c8c02bf..a7c2517aa2 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 @@ -478,11 +478,11 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList overview_iobgraph.removeAllViews() for (i in 1 until numOfGraphs) { val label = TextView(context) - label.layoutParams = LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT).also { it.setMargins(100, 0, 0, -90) } + label.layoutParams = LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT).also { it.setMargins(100, 0, 0, -120) } overview_iobgraph.addView(label) secondaryGraphsLabel.add(label) val graph = GraphView(context) - graph.layoutParams = LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, resourceHelper.dpToPx(100)).also { it.setMargins(0, resourceHelper.dpToPx(5), 0, resourceHelper.dpToPx(10)) } + graph.layoutParams = LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, resourceHelper.dpToPx(100)).also { it.setMargins(0, resourceHelper.dpToPx(35), 0, resourceHelper.dpToPx(15)) } graph.gridLabelRenderer?.gridColor = resourceHelper.gc(R.color.graphgrid) graph.gridLabelRenderer?.reloadStyles() graph.gridLabelRenderer?.isHorizontalLabelsVisible = false From 8729fe18bd2455b8616ae38db93b0d6d934829fe Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 16 May 2020 22:43:18 +0200 Subject: [PATCH 4/8] fix urgent NS alarm preference --- .../general/overview/notifications/NotificationWithAction.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/NotificationWithAction.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/NotificationWithAction.kt index 2d8ad45c2b..f492196b29 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/NotificationWithAction.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/NotificationWithAction.kt @@ -57,7 +57,7 @@ class NotificationWithAction constructor( id = NSURGENTALARM level = URGENT text = nsAlarm.title() - if (nsAlarm.low() && sp.getBoolean(R.string.key_nsalarm_low, false) || nsAlarm.high() && sp.getBoolean(R.string.key_nsalarm_high, false) || nsAlarm.timeago() && sp.getBoolean(R.string.key_nsalarm_staledata, false)) soundId = R.raw.urgentalarm + if (nsAlarm.low() && sp.getBoolean(R.string.key_nsalarm_urgent_low, false) || nsAlarm.high() && sp.getBoolean(R.string.key_nsalarm_urgent_high, false) || nsAlarm.timeago() && sp.getBoolean(R.string.key_nsalarm_staledata, false)) soundId = R.raw.urgentalarm } } buttonText = R.string.snooze From 480542a143d2beeecaaceaa198e8450243a127f1 Mon Sep 17 00:00:00 2001 From: Philoul Date: Sun, 17 May 2020 01:58:07 +0200 Subject: [PATCH 5/8] Fix Wear Control Kotlin doesn't like regex... (AAPS crashed on these lines with ""\\s+", replaced by a space) --- .../androidaps/plugins/general/wear/ActionStringHandler.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/ActionStringHandler.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/ActionStringHandler.kt index 29ed323ee1..a7f5ee98da 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/ActionStringHandler.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/ActionStringHandler.kt @@ -86,7 +86,7 @@ class ActionStringHandler @Inject constructor( var rMessage = "" var rAction = "" // do the parsing and check constraints - val act = actionString.split("\\s+").toTypedArray() + val act = actionString.split(" ").toTypedArray() if ("fillpreset" == act[0]) { ///////////////////////////////////// PRIME/FILL val amount: Double = if ("1" == act[1]) { sp.getDouble("fill_button1", 0.3) @@ -470,7 +470,7 @@ class ActionStringHandler @Inject constructor( if (System.currentTimeMillis() - lastSentTimestamp > TIMEOUT) return lastConfirmActionString = null // do the parsing, check constraints and enact! - val act = actionString.split("\\s+").toTypedArray() + val act = actionString.split(" ").toTypedArray() if ("fill" == act[0]) { val amount = SafeParse.stringToDouble(act[1]) val insulinAfterConstraints = constraintChecker.applyBolusConstraints(Constraint(amount)).value() From 72e541908cbc0bb94df16e5027eec62781922fce Mon Sep 17 00:00:00 2001 From: Philoul Date: Sun, 17 May 2020 08:09:58 +0200 Subject: [PATCH 6/8] Revert "Fix Wear Control Kotlin doesn't like regex... (AAPS crashed on these lines with ""\\s+", replaced by a space)" => Second proposal better than my first one, split works with regex if it is of type Regex (it doesn't recognize first \ as a regex string but as an escape character...) This reverts commit 480542a1 --- .../androidaps/plugins/general/wear/ActionStringHandler.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/ActionStringHandler.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/ActionStringHandler.kt index a7f5ee98da..3aa96ae31d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/ActionStringHandler.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/ActionStringHandler.kt @@ -86,7 +86,7 @@ class ActionStringHandler @Inject constructor( var rMessage = "" var rAction = "" // do the parsing and check constraints - val act = actionString.split(" ").toTypedArray() + val act = actionString.split("\\s+".toRegex()).toTypedArray() if ("fillpreset" == act[0]) { ///////////////////////////////////// PRIME/FILL val amount: Double = if ("1" == act[1]) { sp.getDouble("fill_button1", 0.3) @@ -470,7 +470,7 @@ class ActionStringHandler @Inject constructor( if (System.currentTimeMillis() - lastSentTimestamp > TIMEOUT) return lastConfirmActionString = null // do the parsing, check constraints and enact! - val act = actionString.split(" ").toTypedArray() + val act = actionString.split("\\s+".toRegex()).toTypedArray() if ("fill" == act[0]) { val amount = SafeParse.stringToDouble(act[1]) val insulinAfterConstraints = constraintChecker.applyBolusConstraints(Constraint(amount)).value() From eeb4ce1686d2e5b2dd427dc276cf4aae8c0c121b Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 19 May 2020 12:52:01 +0200 Subject: [PATCH 7/8] fix HistoryBrowser injection --- .../historyBrowser/HistoryBrowseActivity.kt | 18 ++++---- ...in.kt => IobCobCalculatorPluginHistory.kt} | 7 ++-- .../historyBrowser/TreatmentsPluginHistory.kt | 41 +++++++++++++++++++ .../general/overview/OverviewFragment.kt | 4 +- .../general/overview/graphData/GraphData.kt | 11 +++-- .../plugins/treatments/TreatmentsPlugin.java | 2 +- 6 files changed, 64 insertions(+), 19 deletions(-) rename app/src/main/java/info/nightscout/androidaps/historyBrowser/{IobCobStaticCalculatorPlugin.kt => IobCobCalculatorPluginHistory.kt} (83%) create mode 100644 app/src/main/java/info/nightscout/androidaps/historyBrowser/TreatmentsPluginHistory.kt diff --git a/app/src/main/java/info/nightscout/androidaps/historyBrowser/HistoryBrowseActivity.kt b/app/src/main/java/info/nightscout/androidaps/historyBrowser/HistoryBrowseActivity.kt index f59a38d770..5d0df4dbf3 100644 --- a/app/src/main/java/info/nightscout/androidaps/historyBrowser/HistoryBrowseActivity.kt +++ b/app/src/main/java/info/nightscout/androidaps/historyBrowser/HistoryBrowseActivity.kt @@ -49,7 +49,8 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() { @Inject lateinit var resourceHelper: ResourceHelper @Inject lateinit var profileFunction: ProfileFunction @Inject lateinit var defaultValueHelper: DefaultValueHelper - @Inject lateinit var iobCobStaticCalculatorPlugin: IobCobStaticCalculatorPlugin + @Inject lateinit var iobCobCalculatorPluginHistory: IobCobCalculatorPluginHistory + @Inject lateinit var treatmentsPluginHistory: TreatmentsPluginHistory @Inject lateinit var activePlugin: ActivePluginProvider @Inject lateinit var buildHelper: BuildHelper @Inject lateinit var fabricPrivacy: FabricPrivacy @@ -148,7 +149,7 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() { public override fun onPause() { super.onPause() disposable.clear() - iobCobStaticCalculatorPlugin.stopCalculation("onPause") + iobCobCalculatorPluginHistory.stopCalculation("onPause") } public override fun onResume() { @@ -157,7 +158,7 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() { .toObservable(EventAutosensCalculationFinished::class.java) .observeOn(AndroidSchedulers.mainThread()) .subscribe({ event: EventAutosensCalculationFinished -> - // catch only events from iobCobStaticCalculatorPlugin + // catch only events from iobCobCalculatorPluginHistory if (event.cause === eventCustomCalculationFinished) { aapsLogger.debug(LTag.AUTOSENS, "EventAutosensCalculationFinished") updateGUI("EventAutosensCalculationFinished") @@ -220,10 +221,11 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() { } private fun runCalculation(from: String) { + treatmentsPluginHistory.initializeData(start - T.hours(8).msecs()) val end = start + T.hours(rangeToDisplay.toLong()).msecs() - iobCobStaticCalculatorPlugin.stopCalculation(from) - iobCobStaticCalculatorPlugin.clearCache() - iobCobStaticCalculatorPlugin.runCalculation(from, end, true, false, eventCustomCalculationFinished) + iobCobCalculatorPluginHistory.stopCalculation(from) + iobCobCalculatorPluginHistory.clearCache() + iobCobCalculatorPluginHistory.runCalculation(from, end, true, false, eventCustomCalculationFinished) } @Synchronized @@ -242,7 +244,7 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() { GlobalScope.launch(Dispatchers.Main) { historybrowse_bggraph ?: return@launch - val graphData = GraphData(injector, historybrowse_bggraph, iobCobStaticCalculatorPlugin) + val graphData = GraphData(injector, historybrowse_bggraph, iobCobCalculatorPluginHistory, treatmentsPluginHistory) val secondaryGraphsData: ArrayList = ArrayList() // do preparation in different thread @@ -279,7 +281,7 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() { // ------------------ 2nd graph for (g in 0 until secondaryGraphs.size) { - val secondGraphData = GraphData(injector, secondaryGraphs[g], iobCobStaticCalculatorPlugin) + val secondGraphData = GraphData(injector, secondaryGraphs[g], iobCobCalculatorPluginHistory, treatmentsPluginHistory) var useIobForScale = false var useCobForScale = false var useDevForScale = false diff --git a/app/src/main/java/info/nightscout/androidaps/historyBrowser/IobCobStaticCalculatorPlugin.kt b/app/src/main/java/info/nightscout/androidaps/historyBrowser/IobCobCalculatorPluginHistory.kt similarity index 83% rename from app/src/main/java/info/nightscout/androidaps/historyBrowser/IobCobStaticCalculatorPlugin.kt rename to app/src/main/java/info/nightscout/androidaps/historyBrowser/IobCobCalculatorPluginHistory.kt index 03214175d2..bf7401036a 100644 --- a/app/src/main/java/info/nightscout/androidaps/historyBrowser/IobCobStaticCalculatorPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/historyBrowser/IobCobCalculatorPluginHistory.kt @@ -9,7 +9,6 @@ import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorP import info.nightscout.androidaps.plugins.sensitivity.SensitivityAAPSPlugin import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref1Plugin import info.nightscout.androidaps.plugins.sensitivity.SensitivityWeightedAveragePlugin -import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.resources.ResourceHelper @@ -18,7 +17,7 @@ import javax.inject.Inject import javax.inject.Singleton @Singleton -class IobCobStaticCalculatorPlugin @Inject constructor( +class IobCobCalculatorPluginHistory @Inject constructor( injector: HasAndroidInjector, aapsLogger: AAPSLogger, rxBus: RxBusWrapper, @@ -26,14 +25,14 @@ class IobCobStaticCalculatorPlugin @Inject constructor( resourceHelper: ResourceHelper, profileFunction: ProfileFunction, activePlugin: ActivePluginProvider, - treatmentsPlugin: TreatmentsPlugin, + treatmentsPluginHistory: TreatmentsPluginHistory, sensitivityOref1Plugin: SensitivityOref1Plugin, sensitivityAAPSPlugin: SensitivityAAPSPlugin, sensitivityWeightedAveragePlugin: SensitivityWeightedAveragePlugin, fabricPrivacy: FabricPrivacy, dateUtil: DateUtil ) : IobCobCalculatorPlugin(injector, aapsLogger, rxBus, sp, resourceHelper, profileFunction, - activePlugin, treatmentsPlugin, sensitivityOref1Plugin, sensitivityAAPSPlugin, sensitivityWeightedAveragePlugin, fabricPrivacy, dateUtil) { + activePlugin, treatmentsPluginHistory, sensitivityOref1Plugin, sensitivityAAPSPlugin, sensitivityWeightedAveragePlugin, fabricPrivacy, dateUtil) { override fun onStart() { // do not attach to rxbus } diff --git a/app/src/main/java/info/nightscout/androidaps/historyBrowser/TreatmentsPluginHistory.kt b/app/src/main/java/info/nightscout/androidaps/historyBrowser/TreatmentsPluginHistory.kt new file mode 100644 index 0000000000..caa0fb1b1a --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/historyBrowser/TreatmentsPluginHistory.kt @@ -0,0 +1,41 @@ +package info.nightscout.androidaps.historyBrowser + +import android.content.Context +import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.interfaces.ActivePluginProvider +import info.nightscout.androidaps.interfaces.ProfileFunction +import info.nightscout.androidaps.logging.AAPSLogger +import info.nightscout.androidaps.plugins.bus.RxBusWrapper +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 +import info.nightscout.androidaps.utils.FabricPrivacy +import info.nightscout.androidaps.utils.resources.ResourceHelper +import info.nightscout.androidaps.utils.sharedPreferences.SP +import javax.inject.Inject +import javax.inject.Singleton + +@Singleton +class TreatmentsPluginHistory @Inject constructor( + injector: HasAndroidInjector, + aapsLogger: AAPSLogger, + rxBus: RxBusWrapper, + resourceHelper: ResourceHelper, + context: Context, + sp: SP, + profileFunction: ProfileFunction, + activePlugin: ActivePluginProvider, + nsUpload: NSUpload, + fabricPrivacy: FabricPrivacy, dateUtil: DateUtil +) : TreatmentsPlugin(injector, aapsLogger, rxBus, resourceHelper, context, sp, profileFunction, activePlugin, nsUpload, fabricPrivacy, dateUtil) { + + init { + onStart() + } + + override fun onStart() { + service = TreatmentService(injector) + initializeData(range()) + } +} \ No newline at end of file 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 a7c2517aa2..1188caccf7 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 @@ -771,7 +771,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList // ****** GRAPH ******* GlobalScope.launch(Dispatchers.Main) { overview_bggraph ?: return@launch - val graphData = GraphData(injector, overview_bggraph, iobCobCalculatorPlugin) + val graphData = GraphData(injector, overview_bggraph, iobCobCalculatorPlugin, treatmentsPlugin) val secondaryGraphsData: ArrayList = ArrayList() // do preparation in different thread @@ -834,7 +834,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList // ------------------ 2nd graph for (g in 0 until secondaryGraphs.size) { - val secondGraphData = GraphData(injector, secondaryGraphs[g], iobCobCalculatorPlugin) + val secondGraphData = GraphData(injector, secondaryGraphs[g], iobCobCalculatorPlugin, treatmentsPlugin) var useIobForScale = false var useCobForScale = false var useDevForScale = false 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 70e4f9f8fc..f3a779af22 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 @@ -34,7 +34,13 @@ import kotlin.math.abs import kotlin.math.max import kotlin.math.min -class GraphData(injector: HasAndroidInjector, private val graph: GraphView, private val iobCobCalculatorPlugin: IobCobCalculatorPlugin) { +class GraphData( + injector: HasAndroidInjector, + private val graph: GraphView, + private val iobCobCalculatorPlugin: IobCobCalculatorPlugin, + private val treatmentsPlugin: TreatmentsInterface + +) { // IobCobCalculatorPlugin Cannot be injected: HistoryBrowser @Inject lateinit var aapsLogger: AAPSLogger @@ -42,8 +48,6 @@ class GraphData(injector: HasAndroidInjector, private val graph: GraphView, priv @Inject lateinit var resourceHelper: ResourceHelper @Inject lateinit var activePlugin: ActivePluginProvider - private val treatmentsPlugin: TreatmentsInterface - var maxY = Double.MIN_VALUE private var minY = Double.MAX_VALUE private var bgReadingsArray: List? = null @@ -53,7 +57,6 @@ class GraphData(injector: HasAndroidInjector, private val graph: GraphView, priv init { injector.androidInjector().inject(this) units = profileFunction.getUnits() - treatmentsPlugin = activePlugin.activeTreatments } @Suppress("UNUSED_PARAMETER") diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentsPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentsPlugin.java index f273015441..0af7ac8d33 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentsPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentsPlugin.java @@ -178,7 +178,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface return this.service; } - private long range() { + protected long range() { double dia = Constants.defaultDIA; if (profileFunction.getProfile() != null) dia = profileFunction.getProfile().getDia(); From b2b1485c273e6edd4152a0543701cc4329d25137 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 19 May 2020 13:22:02 +0200 Subject: [PATCH 8/8] fix Actions buttons visibility --- .../general/actions/ActionsFragment.kt | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.kt index 47651ef9ac..22973b3caf 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.kt @@ -18,9 +18,9 @@ import info.nightscout.androidaps.events.* import info.nightscout.androidaps.historyBrowser.HistoryBrowseActivity 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.plugins.bus.RxBusWrapper -import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction import info.nightscout.androidaps.plugins.general.overview.StatusLightHandler import info.nightscout.androidaps.queue.Callback @@ -192,17 +192,15 @@ class ActionsFragment : DaggerFragment() { @Synchronized fun updateGui() { - actions_profileswitch?.visibility = (activePlugin.activeProfileInterface.profile != null).toVisibility() val profile = profileFunction.getProfile() val pump = activePlugin.activePump - actions_temptarget?.visibility = (profile != null).toVisibility() - actions_historybrowser.visibility = (profile != null).toVisibility() - - val basalProfileEnabled = buildHelper.isEngineeringModeOrRelease() && pump.pumpDescription.isSetBasalProfileCapable - - actions_profileswitch?.visibility = if (!basalProfileEnabled || !pump.isInitialized || pump.isSuspended) View.GONE else View.VISIBLE + actions_profileswitch?.visibility = ( + activePlugin.activeProfileInterface.profile != null && + pump.pumpDescription.isSetBasalProfileCapable && + pump.isInitialized && + !pump.isSuspended).toVisibility() if (!pump.pumpDescription.isExtendedBolusCapable || !pump.isInitialized || pump.isSuspended || pump.isFakingTempsByExtendedBoluses) { actions_extendedbolus?.visibility = View.GONE @@ -236,12 +234,11 @@ class ActionsFragment : DaggerFragment() { } } - actions_fill?.visibility = - if (!pump.pumpDescription.isRefillingCapable || !pump.isInitialized || pump.isSuspended) View.GONE - else View.VISIBLE - - actions_temptarget?.visibility = config.APS.toVisibility() + actions_historybrowser.visibility = (profile != null).toVisibility() + actions_fill?.visibility = (pump.pumpDescription.isRefillingCapable && pump.isInitialized && !pump.isSuspended).toVisibility() + actions_temptarget?.visibility = (profile != null && config.APS).toVisibility() actions_tddstats?.visibility = pump.pumpDescription.supportsTDDs.toVisibility() + statusLightHandler.updateStatusLights(careportal_canulaage, careportal_insulinage, null, careportal_sensorage, careportal_pbage, null) checkPumpCustomActions() }