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 7a3a983bd1..255a73f755 100644 --- a/app/src/main/java/info/nightscout/androidaps/historyBrowser/HistoryBrowseActivity.kt +++ b/app/src/main/java/info/nightscout/androidaps/historyBrowser/HistoryBrowseActivity.kt @@ -44,6 +44,7 @@ import java.util.* import javax.inject.Inject class HistoryBrowseActivity : NoSplashAppCompatActivity() { + @Inject lateinit var injector: HasAndroidInjector @Inject lateinit var aapsLogger: AAPSLogger @Inject lateinit var rxBus: RxBusWrapper @@ -144,7 +145,7 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() { historybrowse_bggraph?.gridLabelRenderer?.labelVerticalWidth = axisWidth overviewMenus.setupChartMenu(overview_chartMenuButton) - prepareGraphs() + prepareGraphsIfNeeded(overviewMenus.setting.size) savedInstanceState?.let { bundle -> rangeToDisplay = bundle.getInt("rangeToDisplay", 0) start = bundle.getLong("start", 0) @@ -168,7 +169,7 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() { if (it.cause is EventCustomCalculationFinished) { updateGUI("EventAutosensCalculationFinished", bgOnly = false) } - }, fabricPrivacy::logException ) + }, fabricPrivacy::logException) ) disposable.add(rxBus .toObservable(EventAutosensBgLoaded::class.java) @@ -178,22 +179,21 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() { if (it.cause is EventCustomCalculationFinished) { updateGUI("EventAutosensCalculationFinished", bgOnly = true) } - }, fabricPrivacy::logException ) + }, fabricPrivacy::logException) ) disposable.add(rxBus .toObservable(EventIobCalculationProgress::class.java) .observeOn(AndroidSchedulers.mainThread()) - .subscribe({ overview_iobcalculationprogess?.text = it.progress }, fabricPrivacy::logException ) + .subscribe({ overview_iobcalculationprogess?.text = it.progress }, fabricPrivacy::logException) ) disposable.add(rxBus .toObservable(EventRefreshOverview::class.java) .observeOn(AndroidSchedulers.mainThread()) .subscribe({ if (it.now) { - prepareGraphs() updateGUI("EventRefreshOverview", bgOnly = false) } - }, fabricPrivacy::logException ) + }, fabricPrivacy::logException) ) if (start == 0L) { // set start of current day @@ -217,8 +217,7 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() { } - private fun prepareGraphs() { - val numOfGraphs = overviewMenus.setting.size + private fun prepareGraphsIfNeeded(numOfGraphs: Int) { if (numOfGraphs != secondaryGraphs.size - 1) { //aapsLogger.debug("New secondary graph count ${numOfGraphs-1}") @@ -267,6 +266,7 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() { fun updateGUI(from: String, bgOnly: Boolean) { val menuChartSettings = overviewMenus.setting + prepareGraphsIfNeeded(menuChartSettings.size) aapsLogger.debug(LTag.UI, "updateGUI from: $from") val pump = activePlugin.activePump val profile = profileFunction.getProfile() 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 653d6b4332..8609a19c33 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 @@ -177,8 +177,8 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList sp.putBoolean(R.string.key_objectiveusescale, true) false } + prepareGraphsIfNeeded(overviewMenus.setting.size) overviewMenus.setupChartMenu(overview_chartMenuButton) - prepareGraphs() overview_activeprofile?.setOnClickListener(this) overview_activeprofile?.setOnLongClickListener(this) @@ -210,7 +210,6 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList .toObservable(EventRefreshOverview::class.java) .observeOn(AndroidSchedulers.mainThread()) .subscribe({ - prepareGraphs() if (it.now) updateGUI(it.from) else scheduleUpdateGUI(it.from) }) { fabricPrivacy.logException(it) }) @@ -276,20 +275,20 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList updateGUI("onResume") } - override fun onClick(v: View) { // 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 if (childFragmentManager.isStateSaved) return activity?.let { activity -> when (v.id) { - 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_insulinbutton -> protectionCheck.queryProtection(activity, ProtectionCheck.Protection.BOLUS, UIRunnable { InsulinDialog().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_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_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_activeprofile -> { + 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_activeprofile -> { val args = Bundle() args.putLong("time", DateUtil.now()) args.putInt("mode", ProfileViewerDialog.Mode.RUNNING_PROFILE.ordinal) @@ -297,6 +296,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList pvd.arguments = args pvd.show(childFragmentManager, "ProfileViewDialog") } + R.id.overview_cgmbutton -> { if (xdripPlugin.isEnabled(PluginType.BGSOURCE)) 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() args.putInt("showOkCancel", 1) // 1-> true val pvd = LoopDialog() @@ -372,15 +372,17 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList startActivity(Intent(v.context, QuickWizardListActivity::class.java)) return true } - R.id.overview_apsmode -> { + + R.id.overview_apsmode -> { val args = Bundle() args.putInt("showOkCancel", 0) // 0-> false val pvd = LoopDialog() pvd.arguments = args 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 @@ -468,10 +470,8 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList } - private fun prepareGraphs() { + private fun prepareGraphsIfNeeded(numOfGraphs: Int) { synchronized(graphLock) { - val numOfGraphs = overviewMenus.setting.size - if (numOfGraphs != secondaryGraphs.size - 1) { //aapsLogger.debug("New secondary graph count ${numOfGraphs-1}") // rebuild needed @@ -798,6 +798,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList viewLifecycleOwner.lifecycleScope.launch(Dispatchers.Main) { overview_bggraph ?: return@launch val menuChartSettings = overviewMenus.setting + prepareGraphsIfNeeded(menuChartSettings.size) val graphData = GraphData(injector, overview_bggraph, iobCobCalculatorPlugin, treatmentsPlugin) val secondaryGraphsData: ArrayList = ArrayList()