History activity performance improvement
This commit is contained in:
parent
7a086450b5
commit
ec3ebd17db
5 changed files with 113 additions and 79 deletions
|
@ -3,7 +3,6 @@ package info.nightscout.androidaps.historyBrowser
|
|||
import android.app.DatePickerDialog
|
||||
import android.graphics.Color
|
||||
import android.os.Bundle
|
||||
import android.os.SystemClock
|
||||
import android.util.DisplayMetrics
|
||||
import android.view.ViewGroup
|
||||
import android.widget.LinearLayout
|
||||
|
@ -15,12 +14,13 @@ import info.nightscout.androidaps.activities.NoSplashAppCompatActivity
|
|||
import info.nightscout.androidaps.events.EventCustomCalculationFinished
|
||||
import info.nightscout.androidaps.events.EventRefreshOverview
|
||||
import info.nightscout.androidaps.interfaces.ActivePluginProvider
|
||||
import info.nightscout.androidaps.interfaces.ProfileFunction
|
||||
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.overview.OverviewMenus
|
||||
import info.nightscout.androidaps.plugins.general.overview.graphData.GraphData
|
||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensBgLoaded
|
||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensCalculationFinished
|
||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventIobCalculationProgress
|
||||
import info.nightscout.androidaps.utils.DateUtil
|
||||
|
@ -33,6 +33,7 @@ import info.nightscout.androidaps.utils.resources.ResourceHelper
|
|||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.disposables.CompositeDisposable
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import kotlinx.android.synthetic.main.activity_historybrowse.*
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
|
@ -74,12 +75,10 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() {
|
|||
|
||||
historybrowse_left.setOnClickListener {
|
||||
start -= T.hours(rangeToDisplay.toLong()).msecs()
|
||||
updateGUI("onClickLeft")
|
||||
runCalculation("onClickLeft")
|
||||
}
|
||||
historybrowse_right.setOnClickListener {
|
||||
start += T.hours(rangeToDisplay.toLong()).msecs()
|
||||
updateGUI("onClickRight")
|
||||
runCalculation("onClickRight")
|
||||
}
|
||||
historybrowse_end.setOnClickListener {
|
||||
|
@ -90,13 +89,12 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() {
|
|||
calendar[Calendar.MINUTE] = 0
|
||||
calendar[Calendar.HOUR_OF_DAY] = 0
|
||||
start = calendar.timeInMillis
|
||||
updateGUI("onClickEnd")
|
||||
runCalculation("onClickEnd")
|
||||
}
|
||||
historybrowse_zoom.setOnClickListener {
|
||||
rangeToDisplay += 6
|
||||
rangeToDisplay = if (rangeToDisplay > 24) 6 else rangeToDisplay
|
||||
updateGUI("rangeChange")
|
||||
updateGUI("rangeChange", false)
|
||||
}
|
||||
historybrowse_zoom.setOnLongClickListener {
|
||||
val calendar = Calendar.getInstance()
|
||||
|
@ -106,7 +104,6 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() {
|
|||
calendar[Calendar.MINUTE] = 0
|
||||
calendar[Calendar.HOUR_OF_DAY] = 0
|
||||
start = calendar.timeInMillis
|
||||
updateGUI("resetToMidnight")
|
||||
runCalculation("onLongClickZoom")
|
||||
true
|
||||
}
|
||||
|
@ -120,7 +117,6 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() {
|
|||
cal.set(Calendar.DAY_OF_MONTH, dayOfMonth)
|
||||
start = cal.timeInMillis
|
||||
historybrowse_date?.text = dateUtil.dateAndTimeString(start)
|
||||
updateGUI("onClickDate")
|
||||
runCalculation("onClickDate")
|
||||
}
|
||||
|
||||
|
@ -144,6 +140,11 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() {
|
|||
|
||||
overviewMenus.setupChartMenu(overview_chartMenuButton)
|
||||
prepareGraphs()
|
||||
savedInstanceState?.let { bundle ->
|
||||
rangeToDisplay = bundle.getInt("rangeToDisplay", 0)
|
||||
start = bundle.getLong("start", 0)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public override fun onPause() {
|
||||
|
@ -156,12 +157,21 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() {
|
|||
super.onResume()
|
||||
disposable.add(rxBus
|
||||
.toObservable(EventAutosensCalculationFinished::class.java)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe({ event: EventAutosensCalculationFinished ->
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe({
|
||||
// catch only events from iobCobCalculatorPluginHistory
|
||||
if (event.cause === eventCustomCalculationFinished) {
|
||||
aapsLogger.debug(LTag.AUTOSENS, "EventAutosensCalculationFinished")
|
||||
updateGUI("EventAutosensCalculationFinished")
|
||||
if (it.cause is EventCustomCalculationFinished) {
|
||||
updateGUI("EventAutosensCalculationFinished", bgOnly = false)
|
||||
}
|
||||
}) { fabricPrivacy::logException }
|
||||
)
|
||||
disposable.add(rxBus
|
||||
.toObservable(EventAutosensBgLoaded::class.java)
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe({
|
||||
// catch only events from iobCobCalculatorPluginHistory
|
||||
if (it.cause is EventCustomCalculationFinished) {
|
||||
updateGUI("EventAutosensCalculationFinished", bgOnly = true)
|
||||
}
|
||||
}) { fabricPrivacy::logException }
|
||||
)
|
||||
|
@ -174,10 +184,13 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() {
|
|||
.toObservable(EventRefreshOverview::class.java)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe({
|
||||
if (it.now) {
|
||||
prepareGraphs()
|
||||
updateGUI("EventRefreshOverview")
|
||||
updateGUI("EventRefreshOverview", bgOnly = false)
|
||||
}
|
||||
}) { fabricPrivacy::logException }
|
||||
)
|
||||
if (start == 0L) {
|
||||
// set start of current day
|
||||
val calendar = Calendar.getInstance()
|
||||
calendar.timeInMillis = System.currentTimeMillis()
|
||||
|
@ -187,8 +200,16 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() {
|
|||
calendar[Calendar.HOUR_OF_DAY] = 0
|
||||
start = calendar.timeInMillis
|
||||
runCalculation("onResume")
|
||||
SystemClock.sleep(1000)
|
||||
updateGUI("onResume")
|
||||
} else {
|
||||
updateGUI("onResume", bgOnly = false)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onSaveInstanceState(outState: Bundle) {
|
||||
super.onSaveInstanceState(outState)
|
||||
outState.putInt("rangeToDisplay", rangeToDisplay)
|
||||
outState.putLong("start", start)
|
||||
|
||||
}
|
||||
|
||||
private fun prepareGraphs() {
|
||||
|
@ -221,29 +242,30 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() {
|
|||
}
|
||||
|
||||
private fun runCalculation(from: String) {
|
||||
GlobalScope.launch(Dispatchers.Default) {
|
||||
treatmentsPluginHistory.initializeData(start - T.hours(8).msecs())
|
||||
val end = start + T.hours(rangeToDisplay.toLong()).msecs()
|
||||
iobCobCalculatorPluginHistory.stopCalculation(from)
|
||||
iobCobCalculatorPluginHistory.clearCache()
|
||||
iobCobCalculatorPluginHistory.runCalculation(from, end, true, false, eventCustomCalculationFinished)
|
||||
}
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun updateGUI(from: String) {
|
||||
fun updateGUI(from: String, bgOnly: Boolean) {
|
||||
aapsLogger.debug(LTag.UI, "updateGUI from: $from")
|
||||
val pump = activePlugin.activePump
|
||||
val profile = profileFunction.getProfile()
|
||||
|
||||
historybrowse_noprofile?.visibility = (profile == null).toVisibility()
|
||||
profile ?: return
|
||||
|
||||
val lowLine = defaultValueHelper.determineLowLine()
|
||||
val highLine = defaultValueHelper.determineHighLine()
|
||||
historybrowse_date?.text = dateUtil.dateAndTimeString(start)
|
||||
historybrowse_zoom?.text = rangeToDisplay.toString()
|
||||
|
||||
GlobalScope.launch(Dispatchers.Main) {
|
||||
historybrowse_noprofile?.visibility = (profile == null).toVisibility()
|
||||
profile ?: return@launch
|
||||
|
||||
historybrowse_bggraph ?: return@launch
|
||||
historybrowse_date?.text = dateUtil.dateAndTimeString(start)
|
||||
historybrowse_zoom?.text = rangeToDisplay.toString()
|
||||
val graphData = GraphData(injector, historybrowse_bggraph, iobCobCalculatorPluginHistory, treatmentsPluginHistory)
|
||||
val secondaryGraphsData: ArrayList<GraphData> = ArrayList()
|
||||
|
||||
|
@ -263,6 +285,13 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() {
|
|||
// set manual x bounds to have nice steps
|
||||
graphData.formatAxis(fromTime, toTime)
|
||||
|
||||
// add target line
|
||||
graphData.addTargetLine(fromTime, toTime, profile, null)
|
||||
|
||||
// **** NOW line ****
|
||||
graphData.addNowLine(pointer)
|
||||
|
||||
if (!bgOnly) {
|
||||
// Treatments
|
||||
graphData.addTreatments(fromTime, toTime)
|
||||
if (overviewMenus.setting[0][OverviewMenus.CharType.ACT.ordinal])
|
||||
|
@ -272,13 +301,6 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() {
|
|||
if (pump.pumpDescription.isTempBasalCapable && overviewMenus.setting[0][OverviewMenus.CharType.BAS.ordinal]) {
|
||||
graphData.addBasals(fromTime, toTime, lowLine / graphData.maxY / 1.2)
|
||||
}
|
||||
|
||||
// add target line
|
||||
graphData.addTargetLine(fromTime, toTime, profile, null)
|
||||
|
||||
// **** NOW line ****
|
||||
graphData.addNowLine(pointer)
|
||||
|
||||
// ------------------ 2nd graph
|
||||
for (g in 0 until secondaryGraphs.size) {
|
||||
val secondGraphData = GraphData(injector, secondaryGraphs[g], iobCobCalculatorPluginHistory, treatmentsPluginHistory)
|
||||
|
@ -313,11 +335,12 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() {
|
|||
secondaryGraphsData.add(secondGraphData)
|
||||
}
|
||||
}
|
||||
}
|
||||
// finally enforce drawing of graphs in UI thread
|
||||
graphData.performUpdate()
|
||||
for (g in 0 until secondaryGraphs.size) {
|
||||
secondaryGraphsLabel[g].text = overviewMenus.enabledTypes(g + 1)
|
||||
secondaryGraphs[g].visibility = (
|
||||
secondaryGraphs[g].visibility = (!bgOnly && (
|
||||
overviewMenus.setting[g + 1][OverviewMenus.CharType.IOB.ordinal] ||
|
||||
overviewMenus.setting[g + 1][OverviewMenus.CharType.COB.ordinal] ||
|
||||
overviewMenus.setting[g + 1][OverviewMenus.CharType.DEV.ordinal] ||
|
||||
|
@ -325,7 +348,7 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() {
|
|||
overviewMenus.setting[g + 1][OverviewMenus.CharType.ACT.ordinal] ||
|
||||
overviewMenus.setting[g + 1][OverviewMenus.CharType.ABS.ordinal] ||
|
||||
overviewMenus.setting[g + 1][OverviewMenus.CharType.DEVSLOPE.ordinal]
|
||||
).toVisibility()
|
||||
)).toVisibility()
|
||||
secondaryGraphsData[g].performUpdate()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ import info.nightscout.androidaps.interfaces.ProfileFunction;
|
|||
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
|
||||
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
|
||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.data.AutosensData;
|
||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensBgLoaded;
|
||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensCalculationFinished;
|
||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventIobCalculationProgress;
|
||||
import info.nightscout.androidaps.plugins.sensitivity.SensitivityAAPSPlugin;
|
||||
|
@ -114,6 +115,7 @@ public class IobCobOref1Thread extends Thread {
|
|||
if (bgDataReload) {
|
||||
iobCobCalculatorPlugin.loadBgData(end);
|
||||
iobCobCalculatorPlugin.createBucketedData();
|
||||
rxBus.send(new EventAutosensBgLoaded(cause));
|
||||
}
|
||||
List<BgReading> bucketed_data = iobCobCalculatorPlugin.getBucketedData();
|
||||
LongSparseArray<AutosensData> autosensDataTable = iobCobCalculatorPlugin.getAutosensDataTable();
|
||||
|
|
|
@ -28,6 +28,7 @@ import info.nightscout.androidaps.interfaces.ProfileFunction;
|
|||
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
|
||||
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
|
||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.data.AutosensData;
|
||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensBgLoaded;
|
||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensCalculationFinished;
|
||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventIobCalculationProgress;
|
||||
import info.nightscout.androidaps.plugins.sensitivity.SensitivityAAPSPlugin;
|
||||
|
@ -111,6 +112,7 @@ public class IobCobThread extends Thread {
|
|||
if (bgDataReload) {
|
||||
iobCobCalculatorPlugin.loadBgData(end);
|
||||
iobCobCalculatorPlugin.createBucketedData();
|
||||
rxBus.send(new EventAutosensBgLoaded(cause));
|
||||
}
|
||||
List<BgReading> bucketed_data = iobCobCalculatorPlugin.getBucketedData();
|
||||
LongSparseArray<AutosensData> autosensDataTable = iobCobCalculatorPlugin.getAutosensDataTable();
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
package info.nightscout.androidaps.plugins.iob.iobCobCalculator.events
|
||||
|
||||
import info.nightscout.androidaps.events.Event
|
||||
import info.nightscout.androidaps.events.EventLoop
|
||||
|
||||
class EventAutosensBgLoaded(var cause: Event) : EventLoop()
|
|
@ -79,6 +79,7 @@ class FabricPrivacy @Inject constructor(
|
|||
try {
|
||||
val crashlytics = Crashlytics.getInstance()
|
||||
crashlytics.core.logException(throwable)
|
||||
aapsLogger.debug(LTag.CORE, "Exception: ", throwable)
|
||||
} catch (e: NullPointerException) {
|
||||
aapsLogger.debug(LTag.CORE, "Ignoring opted out non-initialized log: $throwable")
|
||||
} catch (e: IllegalStateException) {
|
||||
|
|
Loading…
Reference in a new issue