HistoryBrowser: synchronize access to graph
This commit is contained in:
parent
3682693c10
commit
90f6908b22
1 changed files with 77 additions and 71 deletions
|
@ -69,6 +69,8 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() {
|
||||||
private var rangeToDisplay = 24 // for graph
|
private var rangeToDisplay = 24 // for graph
|
||||||
private var start: Long = 0
|
private var start: Long = 0
|
||||||
|
|
||||||
|
private val graphLock = Object()
|
||||||
|
|
||||||
private var eventCustomCalculationFinished = EventCustomCalculationFinished()
|
private var eventCustomCalculationFinished = EventCustomCalculationFinished()
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
@ -218,7 +220,7 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun prepareGraphsIfNeeded(numOfGraphs: Int) {
|
private fun prepareGraphsIfNeeded(numOfGraphs: Int) {
|
||||||
|
synchronized(graphLock) {
|
||||||
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
|
||||||
|
@ -251,7 +253,7 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() {
|
||||||
secondaryGraphs.add(graph)
|
secondaryGraphs.add(graph)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun runCalculation(from: String) {
|
private fun runCalculation(from: String) {
|
||||||
|
@ -317,6 +319,7 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() {
|
||||||
graphData.addBasals(fromTime, toTime, lowLine / graphData.maxY / 1.2)
|
graphData.addBasals(fromTime, toTime, lowLine / graphData.maxY / 1.2)
|
||||||
}
|
}
|
||||||
// ------------------ 2nd graph
|
// ------------------ 2nd graph
|
||||||
|
synchronized(graphLock) {
|
||||||
for (g in 0 until secondaryGraphs.size) {
|
for (g in 0 until secondaryGraphs.size) {
|
||||||
val secondGraphData = GraphData(injector, secondaryGraphs[g], iobCobCalculatorPluginHistory, treatmentsPluginHistory)
|
val secondGraphData = GraphData(injector, secondaryGraphs[g], iobCobCalculatorPluginHistory, treatmentsPluginHistory)
|
||||||
var useIobForScale = false
|
var useIobForScale = false
|
||||||
|
@ -351,9 +354,11 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// finally enforce drawing of graphs in UI thread
|
// finally enforce drawing of graphs in UI thread
|
||||||
graphData.performUpdate()
|
graphData.performUpdate()
|
||||||
if (!bgOnly)
|
if (!bgOnly)
|
||||||
|
synchronized(graphLock) {
|
||||||
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 && (
|
||||||
|
@ -370,3 +375,4 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue