OverviewMenus synchronized

This commit is contained in:
Milos Kozak 2022-08-05 14:20:39 +02:00
parent fed18bc969
commit d39fc1ddf9
3 changed files with 36 additions and 34 deletions

View file

@ -21,10 +21,10 @@ import info.nightscout.androidaps.events.EventScale
import info.nightscout.androidaps.extensions.toVisibility import info.nightscout.androidaps.extensions.toVisibility
import info.nightscout.androidaps.extensions.toVisibilityKeepSpace import info.nightscout.androidaps.extensions.toVisibilityKeepSpace
import info.nightscout.androidaps.interfaces.ActivePlugin import info.nightscout.androidaps.interfaces.ActivePlugin
import info.nightscout.androidaps.interfaces.BuildHelper
import info.nightscout.androidaps.interfaces.Config import info.nightscout.androidaps.interfaces.Config
import info.nightscout.androidaps.interfaces.Loop import info.nightscout.androidaps.interfaces.Loop
import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.interfaces.ProfileFunction
import info.nightscout.androidaps.plugins.general.nsclient.data.NSDeviceStatus
import info.nightscout.androidaps.plugins.general.overview.OverviewData import info.nightscout.androidaps.plugins.general.overview.OverviewData
import info.nightscout.androidaps.plugins.general.overview.OverviewMenus import info.nightscout.androidaps.plugins.general.overview.OverviewMenus
import info.nightscout.androidaps.plugins.general.overview.events.EventUpdateOverviewGraph import info.nightscout.androidaps.plugins.general.overview.events.EventUpdateOverviewGraph
@ -37,7 +37,6 @@ import info.nightscout.androidaps.utils.DefaultValueHelper
import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.T import info.nightscout.androidaps.utils.T
import info.nightscout.androidaps.utils.Translator import info.nightscout.androidaps.utils.Translator
import info.nightscout.androidaps.interfaces.BuildHelper
import info.nightscout.androidaps.utils.rx.AapsSchedulers import info.nightscout.androidaps.utils.rx.AapsSchedulers
import info.nightscout.androidaps.workflow.CalculationWorkflow import info.nightscout.androidaps.workflow.CalculationWorkflow
import info.nightscout.shared.logging.LTag import info.nightscout.shared.logging.LTag
@ -63,7 +62,6 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() {
@Inject lateinit var dateUtil: DateUtil @Inject lateinit var dateUtil: DateUtil
@Inject lateinit var config: Config @Inject lateinit var config: Config
@Inject lateinit var loop: Loop @Inject lateinit var loop: Loop
@Inject lateinit var nsDeviceStatus: NSDeviceStatus
@Inject lateinit var translator: Translator @Inject lateinit var translator: Translator
@Inject lateinit var context: Context @Inject lateinit var context: Context
@Inject lateinit var dataWorker: DataWorker @Inject lateinit var dataWorker: DataWorker

View file

@ -120,7 +120,6 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
@Inject lateinit var repository: AppRepository @Inject lateinit var repository: AppRepository
@Inject lateinit var glucoseStatusProvider: GlucoseStatusProvider @Inject lateinit var glucoseStatusProvider: GlucoseStatusProvider
@Inject lateinit var overviewData: OverviewData @Inject lateinit var overviewData: OverviewData
@Inject lateinit var overviewPlugin: OverviewPlugin
@Inject lateinit var automationPlugin: AutomationPlugin @Inject lateinit var automationPlugin: AutomationPlugin
@Inject lateinit var bgQualityCheckPlugin: BgQualityCheckPlugin @Inject lateinit var bgQualityCheckPlugin: BgQualityCheckPlugin
@ -417,7 +416,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
uel.log(Action.ACCEPTS_TEMP_BASAL, Sources.Overview) uel.log(Action.ACCEPTS_TEMP_BASAL, Sources.Overview)
(context?.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager?)?.cancel(Constants.notificationID) (context?.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager?)?.cancel(Constants.notificationID)
rxBus.send(EventMobileToWear(EventData.CancelNotification(dateUtil.now()))) rxBus.send(EventMobileToWear(EventData.CancelNotification(dateUtil.now())))
Thread { loop.acceptChangeRequest() }.run() Thread { loop.acceptChangeRequest() }.start()
binding.buttonsLayout.acceptTempButton.visibility = View.GONE binding.buttonsLayout.acceptTempButton.visibility = View.GONE
}) })
}) })
@ -827,7 +826,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
} }
} }
fun updateProfile() { private fun updateProfile() {
val profile = profileFunction.getProfile() val profile = profileFunction.getProfile()
runOnUiThread { runOnUiThread {
_binding ?: return@runOnUiThread _binding ?: return@runOnUiThread
@ -885,7 +884,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
} }
} }
fun updateTime() { private fun updateTime() {
_binding ?: return _binding ?: return
binding.infoLayout.time.text = dateUtil.timeString(dateUtil.now()) binding.infoLayout.time.text = dateUtil.timeString(dateUtil.now())
// Status lights // Status lights
@ -915,7 +914,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
) )
} }
fun updateIobCob() { private fun updateIobCob() {
val iobText = overviewData.iobText(iobCobCalculator) val iobText = overviewData.iobText(iobCobCalculator)
val iobDialogText = overviewData.iobDialogText(iobCobCalculator) val iobDialogText = overviewData.iobDialogText(iobCobCalculator)
val displayText = overviewData.cobInfo(iobCobCalculator).displayText(rh, dateUtil, buildHelper.isEngineeringMode()) val displayText = overviewData.cobInfo(iobCobCalculator).displayText(rh, dateUtil, buildHelper.isEngineeringMode())
@ -999,6 +998,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
val pump = activePlugin.activePump val pump = activePlugin.activePump
val graphData = GraphData(injector, binding.graphsLayout.bgGraph, overviewData) val graphData = GraphData(injector, binding.graphsLayout.bgGraph, overviewData)
val menuChartSettings = overviewMenus.setting val menuChartSettings = overviewMenus.setting
if (menuChartSettings.isEmpty()) return
graphData.addInRangeArea(overviewData.fromTime, overviewData.endTime, defaultValueHelper.determineLowLine(), defaultValueHelper.determineHighLine()) graphData.addInRangeArea(overviewData.fromTime, overviewData.endTime, defaultValueHelper.determineLowLine(), defaultValueHelper.determineHighLine())
graphData.addBgReadings(menuChartSettings[0][OverviewMenus.CharType.PRE.ordinal], context) graphData.addBgReadings(menuChartSettings[0][OverviewMenus.CharType.PRE.ordinal], context)
if (buildHelper.isDev()) graphData.addBucketedData() if (buildHelper.isDev()) graphData.addBucketedData()

View file

@ -69,14 +69,16 @@ class OverviewMenus @Inject constructor(
private var _setting: MutableList<Array<Boolean>> = ArrayList() private var _setting: MutableList<Array<Boolean>> = ArrayList()
val setting: List<Array<Boolean>> val setting: List<Array<Boolean>>
get() = _setting.toMutableList() // implicitly does a list copy @Synchronized get() = _setting.toMutableList() // implicitly does a list copy
@Synchronized
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)
} }
@Synchronized
fun loadGraphConfig() { fun loadGraphConfig() {
val sts = sp.getString(R.string.key_graphconfig, "") val sts = sp.getString(R.string.key_graphconfig, "")
if (sts.isNotEmpty()) { if (sts.isNotEmpty()) {
@ -115,7 +117,7 @@ class OverviewMenus @Inject constructor(
val used = arrayListOf<Int>() val used = arrayListOf<Int>()
for (g in 0 until numOfGraphs) { for (g in 0 until numOfGraphs) {
if (g != 0 && g < numOfGraphs) { if (g != 0) {
val dividerItem = popup.menu.add(Menu.NONE, g, Menu.NONE, "------- ${rh.gs(R.string.graph_menu_divider_header)} $g -------") val dividerItem = popup.menu.add(Menu.NONE, g, Menu.NONE, "------- ${rh.gs(R.string.graph_menu_divider_header)} $g -------")
dividerItem.isCheckable = true dividerItem.isCheckable = true
dividerItem.isChecked = true dividerItem.isChecked = true
@ -150,36 +152,38 @@ class OverviewMenus @Inject constructor(
} }
popup.setOnMenuItemClickListener { popup.setOnMenuItemClickListener {
try { synchronized(this) {
// id < 100 graph header - divider 1, 2, 3 ..... try {
when { // id < 100 graph header - divider 1, 2, 3 .....
it.itemId == SCALE_ID -> { when {
// do nothing, submenu it.itemId == SCALE_ID -> {
} // do nothing, submenu
}
it.itemId > SCALE_ID && it.itemId < SCALE_ID + 100 -> { it.itemId > SCALE_ID && it.itemId < SCALE_ID + 100 -> {
val hours = it.itemId - SCALE_ID // 6,12,.... val hours = it.itemId - SCALE_ID // 6,12,....
rxBus.send(EventScale(hours)) rxBus.send(EventScale(hours))
} }
it.itemId == numOfGraphs -> { it.itemId == numOfGraphs -> {
// add new empty // add new empty
_setting.add(Array(CharType.values().size) { false }) _setting.add(Array(CharType.values().size) { false })
} }
it.itemId < 100 -> { 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
}
} }
} catch (exception: Exception) {
fabricPrivacy.logException(exception)
} }
} catch (exception: Exception) {
fabricPrivacy.logException(exception)
} }
storeGraphConfig() storeGraphConfig()
setupChartMenu(context, chartButton) setupChartMenu(context, chartButton)