Merge pull request #149 from nightscout/adrian/overviewMenus-access
Adrian/overview menus access
This commit is contained in:
commit
1229e53c3b
3 changed files with 96 additions and 88 deletions
|
@ -44,6 +44,7 @@ import java.util.*
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class HistoryBrowseActivity : NoSplashAppCompatActivity() {
|
class HistoryBrowseActivity : NoSplashAppCompatActivity() {
|
||||||
|
|
||||||
@Inject lateinit var injector: HasAndroidInjector
|
@Inject lateinit var injector: HasAndroidInjector
|
||||||
@Inject lateinit var aapsLogger: AAPSLogger
|
@Inject lateinit var aapsLogger: AAPSLogger
|
||||||
@Inject lateinit var rxBus: RxBusWrapper
|
@Inject lateinit var rxBus: RxBusWrapper
|
||||||
|
@ -144,7 +145,7 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() {
|
||||||
historybrowse_bggraph?.gridLabelRenderer?.labelVerticalWidth = axisWidth
|
historybrowse_bggraph?.gridLabelRenderer?.labelVerticalWidth = axisWidth
|
||||||
|
|
||||||
overviewMenus.setupChartMenu(overview_chartMenuButton)
|
overviewMenus.setupChartMenu(overview_chartMenuButton)
|
||||||
prepareGraphs()
|
prepareGraphsIfNeeded(overviewMenus.setting.size)
|
||||||
savedInstanceState?.let { bundle ->
|
savedInstanceState?.let { bundle ->
|
||||||
rangeToDisplay = bundle.getInt("rangeToDisplay", 0)
|
rangeToDisplay = bundle.getInt("rangeToDisplay", 0)
|
||||||
start = bundle.getLong("start", 0)
|
start = bundle.getLong("start", 0)
|
||||||
|
@ -168,7 +169,7 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() {
|
||||||
if (it.cause is EventCustomCalculationFinished) {
|
if (it.cause is EventCustomCalculationFinished) {
|
||||||
updateGUI("EventAutosensCalculationFinished", bgOnly = false)
|
updateGUI("EventAutosensCalculationFinished", bgOnly = false)
|
||||||
}
|
}
|
||||||
}, fabricPrivacy::logException )
|
}, fabricPrivacy::logException)
|
||||||
)
|
)
|
||||||
disposable.add(rxBus
|
disposable.add(rxBus
|
||||||
.toObservable(EventAutosensBgLoaded::class.java)
|
.toObservable(EventAutosensBgLoaded::class.java)
|
||||||
|
@ -178,22 +179,21 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() {
|
||||||
if (it.cause is EventCustomCalculationFinished) {
|
if (it.cause is EventCustomCalculationFinished) {
|
||||||
updateGUI("EventAutosensCalculationFinished", bgOnly = true)
|
updateGUI("EventAutosensCalculationFinished", bgOnly = true)
|
||||||
}
|
}
|
||||||
}, fabricPrivacy::logException )
|
}, fabricPrivacy::logException)
|
||||||
)
|
)
|
||||||
disposable.add(rxBus
|
disposable.add(rxBus
|
||||||
.toObservable(EventIobCalculationProgress::class.java)
|
.toObservable(EventIobCalculationProgress::class.java)
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe({ overview_iobcalculationprogess?.text = it.progress }, fabricPrivacy::logException )
|
.subscribe({ overview_iobcalculationprogess?.text = it.progress }, fabricPrivacy::logException)
|
||||||
)
|
)
|
||||||
disposable.add(rxBus
|
disposable.add(rxBus
|
||||||
.toObservable(EventRefreshOverview::class.java)
|
.toObservable(EventRefreshOverview::class.java)
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe({
|
.subscribe({
|
||||||
if (it.now) {
|
if (it.now) {
|
||||||
prepareGraphs()
|
|
||||||
updateGUI("EventRefreshOverview", bgOnly = false)
|
updateGUI("EventRefreshOverview", bgOnly = false)
|
||||||
}
|
}
|
||||||
}, fabricPrivacy::logException )
|
}, fabricPrivacy::logException)
|
||||||
)
|
)
|
||||||
if (start == 0L) {
|
if (start == 0L) {
|
||||||
// set start of current day
|
// set start of current day
|
||||||
|
@ -217,8 +217,7 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun prepareGraphs() {
|
private fun prepareGraphsIfNeeded(numOfGraphs: Int) {
|
||||||
val numOfGraphs = overviewMenus.setting.size
|
|
||||||
|
|
||||||
if (numOfGraphs != secondaryGraphs.size - 1) {
|
if (numOfGraphs != secondaryGraphs.size - 1) {
|
||||||
//aapsLogger.debug("New secondary graph count ${numOfGraphs-1}")
|
//aapsLogger.debug("New secondary graph count ${numOfGraphs-1}")
|
||||||
|
@ -266,6 +265,8 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateGUI(from: String, bgOnly: Boolean) {
|
fun updateGUI(from: String, bgOnly: Boolean) {
|
||||||
|
val menuChartSettings = overviewMenus.setting
|
||||||
|
prepareGraphsIfNeeded(menuChartSettings.size)
|
||||||
aapsLogger.debug(LTag.UI, "updateGUI from: $from")
|
aapsLogger.debug(LTag.UI, "updateGUI from: $from")
|
||||||
val pump = activePlugin.activePump
|
val pump = activePlugin.activePump
|
||||||
val profile = profileFunction.getProfile()
|
val profile = profileFunction.getProfile()
|
||||||
|
@ -308,11 +309,11 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() {
|
||||||
if (!bgOnly) {
|
if (!bgOnly) {
|
||||||
// Treatments
|
// Treatments
|
||||||
graphData.addTreatments(fromTime, toTime)
|
graphData.addTreatments(fromTime, toTime)
|
||||||
if (overviewMenus.setting[0][OverviewMenus.CharType.ACT.ordinal])
|
if (menuChartSettings[0][OverviewMenus.CharType.ACT.ordinal])
|
||||||
graphData.addActivity(fromTime, toTime, false, 0.8)
|
graphData.addActivity(fromTime, toTime, false, 0.8)
|
||||||
|
|
||||||
// add basal data
|
// add basal data
|
||||||
if (pump.pumpDescription.isTempBasalCapable && overviewMenus.setting[0][OverviewMenus.CharType.BAS.ordinal]) {
|
if (pump.pumpDescription.isTempBasalCapable && menuChartSettings[0][OverviewMenus.CharType.BAS.ordinal]) {
|
||||||
graphData.addBasals(fromTime, toTime, lowLine / graphData.maxY / 1.2)
|
graphData.addBasals(fromTime, toTime, lowLine / graphData.maxY / 1.2)
|
||||||
}
|
}
|
||||||
// ------------------ 2nd graph
|
// ------------------ 2nd graph
|
||||||
|
@ -326,22 +327,22 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() {
|
||||||
var useIAForScale = false
|
var useIAForScale = false
|
||||||
var useABSForScale = false
|
var useABSForScale = false
|
||||||
when {
|
when {
|
||||||
overviewMenus.setting[g + 1][OverviewMenus.CharType.IOB.ordinal] -> useIobForScale = true
|
menuChartSettings[g + 1][OverviewMenus.CharType.IOB.ordinal] -> useIobForScale = true
|
||||||
overviewMenus.setting[g + 1][OverviewMenus.CharType.COB.ordinal] -> useCobForScale = true
|
menuChartSettings[g + 1][OverviewMenus.CharType.COB.ordinal] -> useCobForScale = true
|
||||||
overviewMenus.setting[g + 1][OverviewMenus.CharType.DEV.ordinal] -> useDevForScale = true
|
menuChartSettings[g + 1][OverviewMenus.CharType.DEV.ordinal] -> useDevForScale = true
|
||||||
overviewMenus.setting[g + 1][OverviewMenus.CharType.SEN.ordinal] -> useRatioForScale = true
|
menuChartSettings[g + 1][OverviewMenus.CharType.SEN.ordinal] -> useRatioForScale = true
|
||||||
overviewMenus.setting[g + 1][OverviewMenus.CharType.ACT.ordinal] -> useIAForScale = true
|
menuChartSettings[g + 1][OverviewMenus.CharType.ACT.ordinal] -> useIAForScale = true
|
||||||
overviewMenus.setting[g + 1][OverviewMenus.CharType.ABS.ordinal] -> useABSForScale = true
|
menuChartSettings[g + 1][OverviewMenus.CharType.ABS.ordinal] -> useABSForScale = true
|
||||||
overviewMenus.setting[g + 1][OverviewMenus.CharType.DEVSLOPE.ordinal] -> useDSForScale = true
|
menuChartSettings[g + 1][OverviewMenus.CharType.DEVSLOPE.ordinal] -> useDSForScale = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if (overviewMenus.setting[g + 1][OverviewMenus.CharType.IOB.ordinal]) secondGraphData.addIob(fromTime, toTime, useIobForScale, 1.0, overviewMenus.setting[g + 1][OverviewMenus.CharType.PRE.ordinal])
|
if (menuChartSettings[g + 1][OverviewMenus.CharType.IOB.ordinal]) secondGraphData.addIob(fromTime, toTime, useIobForScale, 1.0, menuChartSettings[g + 1][OverviewMenus.CharType.PRE.ordinal])
|
||||||
if (overviewMenus.setting[g + 1][OverviewMenus.CharType.COB.ordinal]) secondGraphData.addCob(fromTime, toTime, useCobForScale, if (useCobForScale) 1.0 else 0.5)
|
if (menuChartSettings[g + 1][OverviewMenus.CharType.COB.ordinal]) secondGraphData.addCob(fromTime, toTime, useCobForScale, if (useCobForScale) 1.0 else 0.5)
|
||||||
if (overviewMenus.setting[g + 1][OverviewMenus.CharType.DEV.ordinal]) secondGraphData.addDeviations(fromTime, toTime, useDevForScale, 1.0)
|
if (menuChartSettings[g + 1][OverviewMenus.CharType.DEV.ordinal]) secondGraphData.addDeviations(fromTime, toTime, useDevForScale, 1.0)
|
||||||
if (overviewMenus.setting[g + 1][OverviewMenus.CharType.SEN.ordinal]) secondGraphData.addRatio(fromTime, toTime, useRatioForScale, 1.0)
|
if (menuChartSettings[g + 1][OverviewMenus.CharType.SEN.ordinal]) secondGraphData.addRatio(fromTime, toTime, useRatioForScale, 1.0)
|
||||||
if (overviewMenus.setting[g + 1][OverviewMenus.CharType.ACT.ordinal]) secondGraphData.addActivity(fromTime, toTime, useIAForScale, 0.8)
|
if (menuChartSettings[g + 1][OverviewMenus.CharType.ACT.ordinal]) secondGraphData.addActivity(fromTime, toTime, useIAForScale, 0.8)
|
||||||
if (overviewMenus.setting[g + 1][OverviewMenus.CharType.ABS.ordinal]) secondGraphData.addAbsIob(fromTime, toTime, useABSForScale, 1.0)
|
if (menuChartSettings[g + 1][OverviewMenus.CharType.ABS.ordinal]) secondGraphData.addAbsIob(fromTime, toTime, useABSForScale, 1.0)
|
||||||
if (overviewMenus.setting[g + 1][OverviewMenus.CharType.DEVSLOPE.ordinal] && buildHelper.isDev()) secondGraphData.addDeviationSlope(fromTime, toTime, useDSForScale, 1.0)
|
if (menuChartSettings[g + 1][OverviewMenus.CharType.DEVSLOPE.ordinal] && buildHelper.isDev()) secondGraphData.addDeviationSlope(fromTime, toTime, useDSForScale, 1.0)
|
||||||
|
|
||||||
// set manual x bounds to have nice steps
|
// set manual x bounds to have nice steps
|
||||||
secondGraphData.formatAxis(fromTime, toTime)
|
secondGraphData.formatAxis(fromTime, toTime)
|
||||||
|
@ -356,13 +357,13 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() {
|
||||||
for (g in 0 until secondaryGraphs.size) {
|
for (g in 0 until secondaryGraphs.size) {
|
||||||
secondaryGraphsLabel[g].text = overviewMenus.enabledTypes(g + 1)
|
secondaryGraphsLabel[g].text = overviewMenus.enabledTypes(g + 1)
|
||||||
secondaryGraphs[g].visibility = (!bgOnly && (
|
secondaryGraphs[g].visibility = (!bgOnly && (
|
||||||
overviewMenus.setting[g + 1][OverviewMenus.CharType.IOB.ordinal] ||
|
menuChartSettings[g + 1][OverviewMenus.CharType.IOB.ordinal] ||
|
||||||
overviewMenus.setting[g + 1][OverviewMenus.CharType.COB.ordinal] ||
|
menuChartSettings[g + 1][OverviewMenus.CharType.COB.ordinal] ||
|
||||||
overviewMenus.setting[g + 1][OverviewMenus.CharType.DEV.ordinal] ||
|
menuChartSettings[g + 1][OverviewMenus.CharType.DEV.ordinal] ||
|
||||||
overviewMenus.setting[g + 1][OverviewMenus.CharType.SEN.ordinal] ||
|
menuChartSettings[g + 1][OverviewMenus.CharType.SEN.ordinal] ||
|
||||||
overviewMenus.setting[g + 1][OverviewMenus.CharType.ACT.ordinal] ||
|
menuChartSettings[g + 1][OverviewMenus.CharType.ACT.ordinal] ||
|
||||||
overviewMenus.setting[g + 1][OverviewMenus.CharType.ABS.ordinal] ||
|
menuChartSettings[g + 1][OverviewMenus.CharType.ABS.ordinal] ||
|
||||||
overviewMenus.setting[g + 1][OverviewMenus.CharType.DEVSLOPE.ordinal]
|
menuChartSettings[g + 1][OverviewMenus.CharType.DEVSLOPE.ordinal]
|
||||||
)).toVisibility()
|
)).toVisibility()
|
||||||
secondaryGraphsData[g].performUpdate()
|
secondaryGraphsData[g].performUpdate()
|
||||||
}
|
}
|
||||||
|
|
|
@ -177,8 +177,8 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
|
||||||
sp.putBoolean(R.string.key_objectiveusescale, true)
|
sp.putBoolean(R.string.key_objectiveusescale, true)
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
prepareGraphsIfNeeded(overviewMenus.setting.size)
|
||||||
overviewMenus.setupChartMenu(overview_chartMenuButton)
|
overviewMenus.setupChartMenu(overview_chartMenuButton)
|
||||||
prepareGraphs()
|
|
||||||
|
|
||||||
overview_activeprofile?.setOnClickListener(this)
|
overview_activeprofile?.setOnClickListener(this)
|
||||||
overview_activeprofile?.setOnLongClickListener(this)
|
overview_activeprofile?.setOnLongClickListener(this)
|
||||||
|
@ -210,7 +210,6 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
|
||||||
.toObservable(EventRefreshOverview::class.java)
|
.toObservable(EventRefreshOverview::class.java)
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe({
|
.subscribe({
|
||||||
prepareGraphs()
|
|
||||||
if (it.now) updateGUI(it.from)
|
if (it.now) updateGUI(it.from)
|
||||||
else scheduleUpdateGUI(it.from)
|
else scheduleUpdateGUI(it.from)
|
||||||
}) { fabricPrivacy.logException(it) })
|
}) { fabricPrivacy.logException(it) })
|
||||||
|
@ -276,20 +275,20 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
|
||||||
updateGUI("onResume")
|
updateGUI("onResume")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
override fun onClick(v: View) {
|
override fun onClick(v: View) {
|
||||||
// try to fix https://fabric.io/nightscout3/android/apps/info.nightscout.androidaps/issues/5aca7a1536c7b23527eb4be7?time=last-seven-days
|
// try to fix https://fabric.io/nightscout3/android/apps/info.nightscout.androidaps/issues/5aca7a1536c7b23527eb4be7?time=last-seven-days
|
||||||
// https://stackoverflow.com/questions/14860239/checking-if-state-is-saved-before-committing-a-fragmenttransaction
|
// https://stackoverflow.com/questions/14860239/checking-if-state-is-saved-before-committing-a-fragmenttransaction
|
||||||
if (childFragmentManager.isStateSaved) return
|
if (childFragmentManager.isStateSaved) return
|
||||||
activity?.let { activity ->
|
activity?.let { activity ->
|
||||||
when (v.id) {
|
when (v.id) {
|
||||||
R.id.overview_treatmentbutton -> protectionCheck.queryProtection(activity, ProtectionCheck.Protection.BOLUS, UIRunnable { TreatmentDialog().show(childFragmentManager, "Overview") })
|
R.id.overview_treatmentbutton -> protectionCheck.queryProtection(activity, ProtectionCheck.Protection.BOLUS, UIRunnable { TreatmentDialog().show(childFragmentManager, "Overview") })
|
||||||
R.id.overview_wizardbutton -> protectionCheck.queryProtection(activity, ProtectionCheck.Protection.BOLUS, UIRunnable { WizardDialog().show(childFragmentManager, "Overview") })
|
R.id.overview_wizardbutton -> protectionCheck.queryProtection(activity, ProtectionCheck.Protection.BOLUS, UIRunnable { WizardDialog().show(childFragmentManager, "Overview") })
|
||||||
R.id.overview_insulinbutton -> protectionCheck.queryProtection(activity, ProtectionCheck.Protection.BOLUS, UIRunnable { InsulinDialog().show(childFragmentManager, "Overview") })
|
R.id.overview_insulinbutton -> protectionCheck.queryProtection(activity, ProtectionCheck.Protection.BOLUS, UIRunnable { InsulinDialog().show(childFragmentManager, "Overview") })
|
||||||
R.id.overview_quickwizardbutton -> protectionCheck.queryProtection(activity, ProtectionCheck.Protection.BOLUS, UIRunnable { onClickQuickWizard() })
|
R.id.overview_quickwizardbutton -> protectionCheck.queryProtection(activity, ProtectionCheck.Protection.BOLUS, UIRunnable { onClickQuickWizard() })
|
||||||
R.id.overview_carbsbutton -> protectionCheck.queryProtection(activity, ProtectionCheck.Protection.BOLUS, UIRunnable { CarbsDialog().show(childFragmentManager, "Overview") })
|
R.id.overview_carbsbutton -> protectionCheck.queryProtection(activity, ProtectionCheck.Protection.BOLUS, UIRunnable { CarbsDialog().show(childFragmentManager, "Overview") })
|
||||||
R.id.overview_temptarget -> protectionCheck.queryProtection(activity, ProtectionCheck.Protection.BOLUS, UIRunnable { TempTargetDialog().show(childFragmentManager, "Overview") })
|
R.id.overview_temptarget -> protectionCheck.queryProtection(activity, ProtectionCheck.Protection.BOLUS, UIRunnable { TempTargetDialog().show(childFragmentManager, "Overview") })
|
||||||
R.id.overview_activeprofile -> {
|
|
||||||
|
R.id.overview_activeprofile -> {
|
||||||
val args = Bundle()
|
val args = Bundle()
|
||||||
args.putLong("time", DateUtil.now())
|
args.putLong("time", DateUtil.now())
|
||||||
args.putInt("mode", ProfileViewerDialog.Mode.RUNNING_PROFILE.ordinal)
|
args.putInt("mode", ProfileViewerDialog.Mode.RUNNING_PROFILE.ordinal)
|
||||||
|
@ -297,6 +296,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
|
||||||
pvd.arguments = args
|
pvd.arguments = args
|
||||||
pvd.show(childFragmentManager, "ProfileViewDialog")
|
pvd.show(childFragmentManager, "ProfileViewDialog")
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.overview_cgmbutton -> {
|
R.id.overview_cgmbutton -> {
|
||||||
if (xdripPlugin.isEnabled(PluginType.BGSOURCE))
|
if (xdripPlugin.isEnabled(PluginType.BGSOURCE))
|
||||||
openCgmApp("com.eveningoutpost.dexdrip")
|
openCgmApp("com.eveningoutpost.dexdrip")
|
||||||
|
@ -341,7 +341,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.overview_apsmode -> {
|
R.id.overview_apsmode -> {
|
||||||
val args = Bundle()
|
val args = Bundle()
|
||||||
args.putInt("showOkCancel", 1) // 1-> true
|
args.putInt("showOkCancel", 1) // 1-> true
|
||||||
val pvd = LoopDialog()
|
val pvd = LoopDialog()
|
||||||
|
@ -372,15 +372,17 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
|
||||||
startActivity(Intent(v.context, QuickWizardListActivity::class.java))
|
startActivity(Intent(v.context, QuickWizardListActivity::class.java))
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
R.id.overview_apsmode -> {
|
|
||||||
|
R.id.overview_apsmode -> {
|
||||||
val args = Bundle()
|
val args = Bundle()
|
||||||
args.putInt("showOkCancel", 0) // 0-> false
|
args.putInt("showOkCancel", 0) // 0-> false
|
||||||
val pvd = LoopDialog()
|
val pvd = LoopDialog()
|
||||||
pvd.arguments = args
|
pvd.arguments = args
|
||||||
pvd.show(childFragmentManager, "Overview")
|
pvd.show(childFragmentManager, "Overview")
|
||||||
}
|
}
|
||||||
R.id.overview_temptarget -> v.performClick()
|
|
||||||
R.id.overview_activeprofile -> activity?.let { activity -> protectionCheck.queryProtection(activity, ProtectionCheck.Protection.BOLUS, UIRunnable { ProfileSwitchDialog().show(childFragmentManager, "Overview") })}
|
R.id.overview_temptarget -> v.performClick()
|
||||||
|
R.id.overview_activeprofile -> activity?.let { activity -> protectionCheck.queryProtection(activity, ProtectionCheck.Protection.BOLUS, UIRunnable { ProfileSwitchDialog().show(childFragmentManager, "Overview") }) }
|
||||||
|
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
@ -468,10 +470,8 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun prepareGraphs() {
|
private fun prepareGraphsIfNeeded(numOfGraphs: Int) {
|
||||||
synchronized(graphLock) {
|
synchronized(graphLock) {
|
||||||
val numOfGraphs = overviewMenus.setting.size
|
|
||||||
|
|
||||||
if (numOfGraphs != secondaryGraphs.size - 1) {
|
if (numOfGraphs != secondaryGraphs.size - 1) {
|
||||||
//aapsLogger.debug("New secondary graph count ${numOfGraphs-1}")
|
//aapsLogger.debug("New secondary graph count ${numOfGraphs-1}")
|
||||||
// rebuild needed
|
// rebuild needed
|
||||||
|
@ -797,6 +797,8 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
|
||||||
private fun updateGraph(lastRun: LoopInterface.LastRun?, predictionsAvailable: Boolean, lowLine: Double, highLine: Double, pump: PumpInterface, profile: Profile) {
|
private fun updateGraph(lastRun: LoopInterface.LastRun?, predictionsAvailable: Boolean, lowLine: Double, highLine: Double, pump: PumpInterface, profile: Profile) {
|
||||||
viewLifecycleOwner.lifecycleScope.launch(Dispatchers.Main) {
|
viewLifecycleOwner.lifecycleScope.launch(Dispatchers.Main) {
|
||||||
overview_bggraph ?: return@launch
|
overview_bggraph ?: return@launch
|
||||||
|
val menuChartSettings = overviewMenus.setting
|
||||||
|
prepareGraphsIfNeeded(menuChartSettings.size)
|
||||||
val graphData = GraphData(injector, overview_bggraph, iobCobCalculatorPlugin, treatmentsPlugin)
|
val graphData = GraphData(injector, overview_bggraph, iobCobCalculatorPlugin, treatmentsPlugin)
|
||||||
val secondaryGraphsData: ArrayList<GraphData> = ArrayList()
|
val secondaryGraphsData: ArrayList<GraphData> = ArrayList()
|
||||||
|
|
||||||
|
@ -814,7 +816,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
|
||||||
val fromTime: Long
|
val fromTime: Long
|
||||||
val endTime: Long
|
val endTime: Long
|
||||||
val apsResult = if (config.APS) lastRun?.constraintsProcessed else NSDeviceStatus.getAPSResult(injector)
|
val apsResult = if (config.APS) lastRun?.constraintsProcessed else NSDeviceStatus.getAPSResult(injector)
|
||||||
if (predictionsAvailable && apsResult != null && overviewMenus.setting[0][OverviewMenus.CharType.PRE.ordinal]) {
|
if (predictionsAvailable && apsResult != null && menuChartSettings[0][OverviewMenus.CharType.PRE.ordinal]) {
|
||||||
var predictionHours = (ceil(apsResult.latestPredictionsTime - System.currentTimeMillis().toDouble()) / (60 * 60 * 1000)).toInt()
|
var predictionHours = (ceil(apsResult.latestPredictionsTime - System.currentTimeMillis().toDouble()) / (60 * 60 * 1000)).toInt()
|
||||||
predictionHours = min(2, predictionHours)
|
predictionHours = min(2, predictionHours)
|
||||||
predictionHours = max(0, predictionHours)
|
predictionHours = max(0, predictionHours)
|
||||||
|
@ -836,7 +838,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
|
||||||
graphData.addInRangeArea(fromTime, endTime, lowLine, highLine)
|
graphData.addInRangeArea(fromTime, endTime, lowLine, highLine)
|
||||||
|
|
||||||
// **** BG ****
|
// **** BG ****
|
||||||
if (predictionsAvailable && overviewMenus.setting[0][OverviewMenus.CharType.PRE.ordinal])
|
if (predictionsAvailable && menuChartSettings[0][OverviewMenus.CharType.PRE.ordinal])
|
||||||
graphData.addBgReadings(fromTime, toTime, lowLine, highLine, apsResult?.predictions)
|
graphData.addBgReadings(fromTime, toTime, lowLine, highLine, apsResult?.predictions)
|
||||||
else graphData.addBgReadings(fromTime, toTime, lowLine, highLine, null)
|
else graphData.addBgReadings(fromTime, toTime, lowLine, highLine, null)
|
||||||
|
|
||||||
|
@ -845,11 +847,11 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
|
||||||
|
|
||||||
// Treatments
|
// Treatments
|
||||||
graphData.addTreatments(fromTime, endTime)
|
graphData.addTreatments(fromTime, endTime)
|
||||||
if (overviewMenus.setting[0][OverviewMenus.CharType.ACT.ordinal])
|
if (menuChartSettings[0][OverviewMenus.CharType.ACT.ordinal])
|
||||||
graphData.addActivity(fromTime, endTime, false, 0.8)
|
graphData.addActivity(fromTime, endTime, false, 0.8)
|
||||||
|
|
||||||
// add basal data
|
// add basal data
|
||||||
if (pump.pumpDescription.isTempBasalCapable && overviewMenus.setting[0][OverviewMenus.CharType.BAS.ordinal])
|
if (pump.pumpDescription.isTempBasalCapable && menuChartSettings[0][OverviewMenus.CharType.BAS.ordinal])
|
||||||
graphData.addBasals(fromTime, now, lowLine / graphData.maxY / 1.2)
|
graphData.addBasals(fromTime, now, lowLine / graphData.maxY / 1.2)
|
||||||
|
|
||||||
// add target line
|
// add target line
|
||||||
|
@ -860,7 +862,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
|
||||||
|
|
||||||
// ------------------ 2nd graph
|
// ------------------ 2nd graph
|
||||||
synchronized(graphLock) {
|
synchronized(graphLock) {
|
||||||
for (g in 0 until min(secondaryGraphs.size, overviewMenus.setting.size + 1)) {
|
for (g in 0 until min(secondaryGraphs.size, menuChartSettings.size + 1)) {
|
||||||
val secondGraphData = GraphData(injector, secondaryGraphs[g], iobCobCalculatorPlugin, treatmentsPlugin)
|
val secondGraphData = GraphData(injector, secondaryGraphs[g], iobCobCalculatorPlugin, treatmentsPlugin)
|
||||||
var useABSForScale = false
|
var useABSForScale = false
|
||||||
var useIobForScale = false
|
var useIobForScale = false
|
||||||
|
@ -870,22 +872,22 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
|
||||||
var useDSForScale = false
|
var useDSForScale = false
|
||||||
var useIAForScale = false
|
var useIAForScale = false
|
||||||
when {
|
when {
|
||||||
overviewMenus.setting[g + 1][OverviewMenus.CharType.ABS.ordinal] -> useABSForScale = true
|
menuChartSettings[g + 1][OverviewMenus.CharType.ABS.ordinal] -> useABSForScale = true
|
||||||
overviewMenus.setting[g + 1][OverviewMenus.CharType.IOB.ordinal] -> useIobForScale = true
|
menuChartSettings[g + 1][OverviewMenus.CharType.IOB.ordinal] -> useIobForScale = true
|
||||||
overviewMenus.setting[g + 1][OverviewMenus.CharType.COB.ordinal] -> useCobForScale = true
|
menuChartSettings[g + 1][OverviewMenus.CharType.COB.ordinal] -> useCobForScale = true
|
||||||
overviewMenus.setting[g + 1][OverviewMenus.CharType.DEV.ordinal] -> useDevForScale = true
|
menuChartSettings[g + 1][OverviewMenus.CharType.DEV.ordinal] -> useDevForScale = true
|
||||||
overviewMenus.setting[g + 1][OverviewMenus.CharType.SEN.ordinal] -> useRatioForScale = true
|
menuChartSettings[g + 1][OverviewMenus.CharType.SEN.ordinal] -> useRatioForScale = true
|
||||||
overviewMenus.setting[g + 1][OverviewMenus.CharType.ACT.ordinal] -> useIAForScale = true
|
menuChartSettings[g + 1][OverviewMenus.CharType.ACT.ordinal] -> useIAForScale = true
|
||||||
overviewMenus.setting[g + 1][OverviewMenus.CharType.DEVSLOPE.ordinal] -> useDSForScale = true
|
menuChartSettings[g + 1][OverviewMenus.CharType.DEVSLOPE.ordinal] -> useDSForScale = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if (overviewMenus.setting[g + 1][OverviewMenus.CharType.ABS.ordinal]) secondGraphData.addAbsIob(fromTime, now, useABSForScale, 1.0)
|
if (menuChartSettings[g + 1][OverviewMenus.CharType.ABS.ordinal]) secondGraphData.addAbsIob(fromTime, now, useABSForScale, 1.0)
|
||||||
if (overviewMenus.setting[g + 1][OverviewMenus.CharType.IOB.ordinal]) secondGraphData.addIob(fromTime, now, useIobForScale, 1.0, overviewMenus.setting[g + 1][OverviewMenus.CharType.PRE.ordinal])
|
if (menuChartSettings[g + 1][OverviewMenus.CharType.IOB.ordinal]) secondGraphData.addIob(fromTime, now, useIobForScale, 1.0, menuChartSettings[g + 1][OverviewMenus.CharType.PRE.ordinal])
|
||||||
if (overviewMenus.setting[g + 1][OverviewMenus.CharType.COB.ordinal]) secondGraphData.addCob(fromTime, now, useCobForScale, if (useCobForScale) 1.0 else 0.5)
|
if (menuChartSettings[g + 1][OverviewMenus.CharType.COB.ordinal]) secondGraphData.addCob(fromTime, now, useCobForScale, if (useCobForScale) 1.0 else 0.5)
|
||||||
if (overviewMenus.setting[g + 1][OverviewMenus.CharType.DEV.ordinal]) secondGraphData.addDeviations(fromTime, now, useDevForScale, 1.0)
|
if (menuChartSettings[g + 1][OverviewMenus.CharType.DEV.ordinal]) secondGraphData.addDeviations(fromTime, now, useDevForScale, 1.0)
|
||||||
if (overviewMenus.setting[g + 1][OverviewMenus.CharType.SEN.ordinal]) secondGraphData.addRatio(fromTime, now, useRatioForScale, 1.0)
|
if (menuChartSettings[g + 1][OverviewMenus.CharType.SEN.ordinal]) secondGraphData.addRatio(fromTime, now, useRatioForScale, 1.0)
|
||||||
if (overviewMenus.setting[g + 1][OverviewMenus.CharType.ACT.ordinal]) secondGraphData.addActivity(fromTime, endTime, useIAForScale, 0.8)
|
if (menuChartSettings[g + 1][OverviewMenus.CharType.ACT.ordinal]) secondGraphData.addActivity(fromTime, endTime, useIAForScale, 0.8)
|
||||||
if (overviewMenus.setting[g + 1][OverviewMenus.CharType.DEVSLOPE.ordinal] && buildHelper.isDev()) secondGraphData.addDeviationSlope(fromTime, now, useDSForScale, 1.0)
|
if (menuChartSettings[g + 1][OverviewMenus.CharType.DEVSLOPE.ordinal] && buildHelper.isDev()) secondGraphData.addDeviationSlope(fromTime, now, useDSForScale, 1.0)
|
||||||
|
|
||||||
// set manual x bounds to have nice steps
|
// set manual x bounds to have nice steps
|
||||||
secondGraphData.formatAxis(fromTime, endTime)
|
secondGraphData.formatAxis(fromTime, endTime)
|
||||||
|
@ -897,16 +899,16 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
|
||||||
// finally enforce drawing of graphs in UI thread
|
// finally enforce drawing of graphs in UI thread
|
||||||
graphData.performUpdate()
|
graphData.performUpdate()
|
||||||
synchronized(graphLock) {
|
synchronized(graphLock) {
|
||||||
for (g in 0 until min(secondaryGraphs.size, overviewMenus.setting.size + 1)) {
|
for (g in 0 until min(secondaryGraphs.size, menuChartSettings.size + 1)) {
|
||||||
secondaryGraphsLabel[g].text = overviewMenus.enabledTypes(g + 1)
|
secondaryGraphsLabel[g].text = overviewMenus.enabledTypes(g + 1)
|
||||||
secondaryGraphs[g].visibility = (
|
secondaryGraphs[g].visibility = (
|
||||||
overviewMenus.setting[g + 1][OverviewMenus.CharType.ABS.ordinal] ||
|
menuChartSettings[g + 1][OverviewMenus.CharType.ABS.ordinal] ||
|
||||||
overviewMenus.setting[g + 1][OverviewMenus.CharType.IOB.ordinal] ||
|
menuChartSettings[g + 1][OverviewMenus.CharType.IOB.ordinal] ||
|
||||||
overviewMenus.setting[g + 1][OverviewMenus.CharType.COB.ordinal] ||
|
menuChartSettings[g + 1][OverviewMenus.CharType.COB.ordinal] ||
|
||||||
overviewMenus.setting[g + 1][OverviewMenus.CharType.DEV.ordinal] ||
|
menuChartSettings[g + 1][OverviewMenus.CharType.DEV.ordinal] ||
|
||||||
overviewMenus.setting[g + 1][OverviewMenus.CharType.SEN.ordinal] ||
|
menuChartSettings[g + 1][OverviewMenus.CharType.SEN.ordinal] ||
|
||||||
overviewMenus.setting[g + 1][OverviewMenus.CharType.ACT.ordinal] ||
|
menuChartSettings[g + 1][OverviewMenus.CharType.ACT.ordinal] ||
|
||||||
overviewMenus.setting[g + 1][OverviewMenus.CharType.DEVSLOPE.ordinal]
|
menuChartSettings[g + 1][OverviewMenus.CharType.DEVSLOPE.ordinal]
|
||||||
).toVisibility()
|
).toVisibility()
|
||||||
secondaryGraphsData[g].performUpdate()
|
secondaryGraphsData[g].performUpdate()
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,17 +50,22 @@ class OverviewMenus @Inject constructor(
|
||||||
|
|
||||||
fun enabledTypes(graph: Int): String {
|
fun enabledTypes(graph: Int): String {
|
||||||
val r = StringBuilder()
|
val r = StringBuilder()
|
||||||
for (type in CharType.values()) if (setting[graph][type.ordinal]) {
|
for (type in CharType.values()) if (_setting[graph][type.ordinal]) {
|
||||||
r.append(resourceHelper.gs(type.shortnameId))
|
r.append(resourceHelper.gs(type.shortnameId))
|
||||||
r.append(" ")
|
r.append(" ")
|
||||||
}
|
}
|
||||||
return r.toString()
|
return r.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
var setting: MutableList<Array<Boolean>> = ArrayList()
|
|
||||||
|
|
||||||
|
private var _setting: MutableList<Array<Boolean>> = ArrayList()
|
||||||
|
|
||||||
|
val setting: List<Array<Boolean>>
|
||||||
|
get() = _setting.toMutableList() // implicitly does a list copy
|
||||||
|
|
||||||
private fun storeGraphConfig() {
|
private fun storeGraphConfig() {
|
||||||
val sts = Gson().toJson(setting)
|
val sts = Gson().toJson(_setting)
|
||||||
sp.putString(R.string.key_graphconfig, sts)
|
sp.putString(R.string.key_graphconfig, sts)
|
||||||
aapsLogger.debug(sts)
|
aapsLogger.debug(sts)
|
||||||
}
|
}
|
||||||
|
@ -68,22 +73,22 @@ class OverviewMenus @Inject constructor(
|
||||||
private fun loadGraphConfig() {
|
private fun loadGraphConfig() {
|
||||||
val sts = sp.getString(R.string.key_graphconfig, "")
|
val sts = sp.getString(R.string.key_graphconfig, "")
|
||||||
if (sts.isNotEmpty()) {
|
if (sts.isNotEmpty()) {
|
||||||
setting = Gson().fromJson(sts, Array<Array<Boolean>>::class.java).toMutableList()
|
_setting = Gson().fromJson(sts, Array<Array<Boolean>>::class.java).toMutableList()
|
||||||
// reset when new CharType added
|
// reset when new CharType added
|
||||||
for (s in setting)
|
for (s in _setting)
|
||||||
if (s.size != CharType.values().size) {
|
if (s.size != CharType.values().size) {
|
||||||
setting = ArrayList()
|
_setting = ArrayList()
|
||||||
setting.add(Array(CharType.values().size) { true })
|
_setting.add(Array(CharType.values().size) { true })
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
setting = ArrayList()
|
_setting = ArrayList()
|
||||||
setting.add(Array(CharType.values().size) { true })
|
_setting.add(Array(CharType.values().size) { true })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setupChartMenu(chartButton: ImageButton) {
|
fun setupChartMenu(chartButton: ImageButton) {
|
||||||
loadGraphConfig()
|
loadGraphConfig()
|
||||||
val numOfGraphs = setting.size // 1 main + x secondary
|
val numOfGraphs = _setting.size // 1 main + x secondary
|
||||||
|
|
||||||
chartButton.setOnClickListener { v: View ->
|
chartButton.setOnClickListener { v: View ->
|
||||||
val predictionsAvailable: Boolean = when {
|
val predictionsAvailable: Boolean = when {
|
||||||
|
@ -112,7 +117,7 @@ class OverviewMenus @Inject constructor(
|
||||||
s.setSpan(ForegroundColorSpan(resourceHelper.gc(m.colorId)), 0, s.length, 0)
|
s.setSpan(ForegroundColorSpan(resourceHelper.gc(m.colorId)), 0, s.length, 0)
|
||||||
item.title = s
|
item.title = s
|
||||||
item.isCheckable = true
|
item.isCheckable = true
|
||||||
item.isChecked = setting[g][m.ordinal]
|
item.isChecked = _setting[g][m.ordinal]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -126,14 +131,14 @@ class OverviewMenus @Inject constructor(
|
||||||
// id < 100 graph header - divider 1, 2, 3 .....
|
// id < 100 graph header - divider 1, 2, 3 .....
|
||||||
if (it.itemId == numOfGraphs) {
|
if (it.itemId == numOfGraphs) {
|
||||||
// add new empty
|
// add new empty
|
||||||
setting.add(Array(CharType.values().size) { false })
|
_setting.add(Array(CharType.values().size) { false })
|
||||||
} else if (it.itemId < 100) {
|
} else if (it.itemId < 100) {
|
||||||
// remove graph
|
// remove graph
|
||||||
setting.removeAt(it.itemId)
|
_setting.removeAt(it.itemId)
|
||||||
} else {
|
} else {
|
||||||
val graphNumber = it.itemId / 100 - 1
|
val graphNumber = it.itemId / 100 - 1
|
||||||
val item = it.itemId % 100
|
val item = it.itemId % 100
|
||||||
setting[graphNumber][item] = !it.isChecked
|
_setting[graphNumber][item] = !it.isChecked
|
||||||
}
|
}
|
||||||
storeGraphConfig()
|
storeGraphConfig()
|
||||||
setupChartMenu(chartButton)
|
setupChartMenu(chartButton)
|
||||||
|
|
Loading…
Reference in a new issue