mirror of
https://github.com/oliexdev/openScale.git
synced 2025-10-29 14:47:19 +01:00
The splitter's position is now updated locally during the drag gesture for a smoother, more responsive user experience. The final position is then saved to the settings only when the drag gesture ends, reducing the number of preference updates.
This commit is contained in:
@@ -193,10 +193,15 @@ fun MeasurementChart(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val upperPaneWeight by remember(SettingsPreferenceKeys.GRAPH_SCREEN_CONTEXT, sharedViewModel) {
|
val splitterWeight by remember(SettingsPreferenceKeys.GRAPH_SCREEN_CONTEXT, sharedViewModel) {
|
||||||
sharedViewModel.observeSplitterWeight(SettingsPreferenceKeys.GRAPH_SCREEN_CONTEXT, 0.25f)
|
sharedViewModel.observeSplitterWeight(SettingsPreferenceKeys.GRAPH_SCREEN_CONTEXT, 0.25f)
|
||||||
}.collectAsState(initial = 0.25f)
|
}.collectAsState(initial = 0.25f)
|
||||||
|
|
||||||
|
var localSplitterWeight by remember { mutableStateOf(splitterWeight) }
|
||||||
|
|
||||||
|
LaunchedEffect(splitterWeight) {
|
||||||
|
localSplitterWeight = splitterWeight
|
||||||
|
}
|
||||||
|
|
||||||
val showDataPointsSetting by sharedViewModel
|
val showDataPointsSetting by sharedViewModel
|
||||||
.showChartDataPoints
|
.showChartDataPoints
|
||||||
@@ -446,7 +451,7 @@ fun MeasurementChart(
|
|||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.weight(upperPaneWeight)
|
.weight(localSplitterWeight)
|
||||||
.padding(horizontal = 8.dp)
|
.padding(horizontal = 8.dp)
|
||||||
) {
|
) {
|
||||||
PeriodChart(
|
PeriodChart(
|
||||||
@@ -465,16 +470,22 @@ fun MeasurementChart(
|
|||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.height(16.dp)
|
.height(16.dp)
|
||||||
.pointerInput(Unit) {
|
.pointerInput(Unit) {
|
||||||
detectDragGestures { change, _ ->
|
detectDragGestures (
|
||||||
change.consume()
|
onDrag = { change, dragAmount ->
|
||||||
|
change.consume()
|
||||||
val deltaY = (change.position.y - change.previousPosition.y)
|
val deltaY = dragAmount.y
|
||||||
val weightDelta = deltaY / 2000f
|
val weightDelta = deltaY / 2000f
|
||||||
val newWeight = (upperPaneWeight + weightDelta).coerceIn(0.01f, 0.7f)
|
localSplitterWeight = (localSplitterWeight + weightDelta).coerceIn(0.01f, 0.8f)
|
||||||
scope.launch {
|
},
|
||||||
sharedViewModel.setSplitterWeight(SettingsPreferenceKeys.GRAPH_SCREEN_CONTEXT, newWeight)
|
onDragEnd = {
|
||||||
}
|
scope.launch {
|
||||||
}
|
sharedViewModel.setSplitterWeight(
|
||||||
|
SettingsPreferenceKeys.GRAPH_SCREEN_CONTEXT,
|
||||||
|
localSplitterWeight
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
},
|
},
|
||||||
contentAlignment = Alignment.Center
|
contentAlignment = Alignment.Center
|
||||||
) {
|
) {
|
||||||
@@ -765,7 +776,7 @@ fun MeasurementChart(
|
|||||||
modelProducer = modelProducer,
|
modelProducer = modelProducer,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.weight(if (showPeriodChart) 1f - upperPaneWeight else 1f),
|
.weight(if (showPeriodChart) 1f - localSplitterWeight else 1f),
|
||||||
scrollState = scrollState,
|
scrollState = scrollState,
|
||||||
zoomState = zoomState
|
zoomState = zoomState
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -29,6 +29,9 @@ import androidx.activity.compose.rememberLauncherForActivityResult
|
|||||||
import androidx.activity.result.ActivityResult
|
import androidx.activity.result.ActivityResult
|
||||||
import androidx.activity.result.contract.ActivityResultContracts
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
import androidx.compose.animation.AnimatedVisibility
|
import androidx.compose.animation.AnimatedVisibility
|
||||||
|
import androidx.compose.animation.core.Spring
|
||||||
|
import androidx.compose.animation.core.animateFloatAsState
|
||||||
|
import androidx.compose.animation.core.spring
|
||||||
import androidx.compose.foundation.BorderStroke
|
import androidx.compose.foundation.BorderStroke
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
@@ -325,10 +328,16 @@ fun OverviewScreen(
|
|||||||
val listState = rememberLazyListState()
|
val listState = rememberLazyListState()
|
||||||
val scope = rememberCoroutineScope()
|
val scope = rememberCoroutineScope()
|
||||||
var highlightedMeasurementId by rememberSaveable { mutableStateOf<Int?>(null) }
|
var highlightedMeasurementId by rememberSaveable { mutableStateOf<Int?>(null) }
|
||||||
val upperPaneWeight by remember(SettingsPreferenceKeys.OVERVIEW_SCREEN_CONTEXT, sharedViewModel) {
|
val splitterWeight by remember(SettingsPreferenceKeys.OVERVIEW_SCREEN_CONTEXT, sharedViewModel) {
|
||||||
sharedViewModel.observeSplitterWeight(SettingsPreferenceKeys.OVERVIEW_SCREEN_CONTEXT, 0.3f)
|
sharedViewModel.observeSplitterWeight(SettingsPreferenceKeys.OVERVIEW_SCREEN_CONTEXT, 0.3f)
|
||||||
}.collectAsState(initial = 0.3f)
|
}.collectAsState(initial = 0.3f)
|
||||||
|
|
||||||
|
var localSplitterWeight by remember { mutableStateOf(splitterWeight) }
|
||||||
|
|
||||||
|
LaunchedEffect(splitterWeight) {
|
||||||
|
localSplitterWeight = splitterWeight
|
||||||
|
}
|
||||||
|
|
||||||
// Time filter action for the top bar, specific to this screen's context
|
// Time filter action for the top bar, specific to this screen's context
|
||||||
val timeFilterAction = provideFilterTopBarAction(
|
val timeFilterAction = provideFilterTopBarAction(
|
||||||
sharedViewModel = sharedViewModel,
|
sharedViewModel = sharedViewModel,
|
||||||
@@ -584,7 +593,7 @@ fun OverviewScreen(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Chart
|
// Chart
|
||||||
Box(modifier = Modifier.weight(upperPaneWeight)) {
|
Box(modifier = Modifier.weight(localSplitterWeight)) {
|
||||||
MeasurementChart(
|
MeasurementChart(
|
||||||
sharedViewModel = sharedViewModel,
|
sharedViewModel = sharedViewModel,
|
||||||
screenContextName = SettingsPreferenceKeys.OVERVIEW_SCREEN_CONTEXT,
|
screenContextName = SettingsPreferenceKeys.OVERVIEW_SCREEN_CONTEXT,
|
||||||
@@ -619,16 +628,22 @@ fun OverviewScreen(
|
|||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.height(16.dp)
|
.height(16.dp)
|
||||||
.pointerInput(Unit) {
|
.pointerInput(Unit) {
|
||||||
detectDragGestures { change, _ ->
|
detectDragGestures (
|
||||||
change.consume()
|
onDrag = { change, dragAmount ->
|
||||||
|
change.consume()
|
||||||
val deltaY = (change.position.y - change.previousPosition.y)
|
val deltaY = dragAmount.y
|
||||||
val weightDelta = deltaY / 2000f
|
val weightDelta = deltaY / 2000f
|
||||||
val newWeight = (upperPaneWeight + weightDelta).coerceIn(0.01f, 0.7f)
|
localSplitterWeight = (localSplitterWeight + weightDelta).coerceIn(0.01f, 0.8f)
|
||||||
scope.launch {
|
},
|
||||||
sharedViewModel.setSplitterWeight(SettingsPreferenceKeys.OVERVIEW_SCREEN_CONTEXT, newWeight)
|
onDragEnd = {
|
||||||
}
|
scope.launch {
|
||||||
}
|
sharedViewModel.setSplitterWeight(
|
||||||
|
SettingsPreferenceKeys.OVERVIEW_SCREEN_CONTEXT,
|
||||||
|
localSplitterWeight
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
},
|
},
|
||||||
contentAlignment = Alignment.Center
|
contentAlignment = Alignment.Center
|
||||||
) {
|
) {
|
||||||
@@ -764,7 +779,7 @@ fun OverviewScreen(
|
|||||||
LazyColumn(
|
LazyColumn(
|
||||||
state = listState,
|
state = listState,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.weight(1f - upperPaneWeight) // Takes remaining space in the Column
|
.weight(1f - localSplitterWeight) // Takes remaining space in the Column
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
.padding(horizontal = 16.dp, vertical = 8.dp),
|
.padding(horizontal = 16.dp, vertical = 8.dp),
|
||||||
verticalArrangement = Arrangement.spacedBy(12.dp)
|
verticalArrangement = Arrangement.spacedBy(12.dp)
|
||||||
|
|||||||
Reference in New Issue
Block a user