mirror of
https://github.com/bleackstorm/satiea.git
synced 2026-12-03 07:41:56 +01:00
fix(ui): always honor ModalBottomSheet dismiss during AI loading to prevent app freeze
This commit is contained in:
1 parent
7181ea58fc
commit
e3bd4d3312
5 files changed
+12
-21
No files matched your search
@@ -66,11 +66,7 @@ fun AdaptMenusForExpiringSheet(
|
|||||||
val dayFmt = remember { DateTimeFormatter.ofPattern("EEEE d MMM", Locale.FRENCH) }
|
val dayFmt = remember { DateTimeFormatter.ofPattern("EEEE d MMM", Locale.FRENCH) }
|
||||||
|
|
||||||
ModalBottomSheet(
|
ModalBottomSheet(
|
||||||
onDismissRequest = {
|
onDismissRequest = onDismiss,
|
||||||
if (adaptationState !is MenuAdaptationUiState.Loading) {
|
|
||||||
onDismiss()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
sheetState = sheetState,
|
sheetState = sheetState,
|
||||||
shape = RoundedCornerShape(topStart = 24.dp, topEnd = 24.dp)
|
shape = RoundedCornerShape(topStart = 24.dp, topEnd = 24.dp)
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -146,6 +146,7 @@ class PlanningViewModel internal constructor(
|
|||||||
private val checkedKeysMutex = Mutex()
|
private val checkedKeysMutex = Mutex()
|
||||||
private var predictionJob: Job? = null
|
private var predictionJob: Job? = null
|
||||||
private var adaptationJob: Job? = null
|
private var adaptationJob: Job? = null
|
||||||
|
private var receiptScanJob: Job? = null
|
||||||
|
|
||||||
private val _uiEvents = Channel<UiEvent>(Channel.BUFFERED)
|
private val _uiEvents = Channel<UiEvent>(Channel.BUFFERED)
|
||||||
val uiEvents: Flow<UiEvent> = _uiEvents.receiveAsFlow()
|
val uiEvents: Flow<UiEvent> = _uiEvents.receiveAsFlow()
|
||||||
@@ -989,7 +990,8 @@ class PlanningViewModel internal constructor(
|
|||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
|
||||||
fun scanReceiptFromUri(uri: Uri) {
|
fun scanReceiptFromUri(uri: Uri) {
|
||||||
viewModelScope.launch {
|
receiptScanJob?.cancel()
|
||||||
|
receiptScanJob = viewModelScope.launch {
|
||||||
_receiptScanState.value = ReceiptScanUiState.Scanning
|
_receiptScanState.value = ReceiptScanUiState.Scanning
|
||||||
val bitmap = ImageUtils.loadResizedBitmapForAi(getApplication(), uri, maxDimension = 1440)
|
val bitmap = ImageUtils.loadResizedBitmapForAi(getApplication(), uri, maxDimension = 1440)
|
||||||
if (bitmap == null) {
|
if (bitmap == null) {
|
||||||
@@ -1101,6 +1103,8 @@ class PlanningViewModel internal constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun dismissReceiptScan() {
|
fun dismissReceiptScan() {
|
||||||
|
receiptScanJob?.cancel()
|
||||||
|
receiptScanJob = null
|
||||||
_receiptScanState.value = ReceiptScanUiState.Idle
|
_receiptScanState.value = ReceiptScanUiState.Idle
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -127,11 +127,7 @@ fun PredictWeekSheet(
|
|||||||
}
|
}
|
||||||
|
|
||||||
ModalBottomSheet(
|
ModalBottomSheet(
|
||||||
onDismissRequest = {
|
onDismissRequest = onDismiss,
|
||||||
if (predictionState !is WeekPredictionUiState.Loading) {
|
|
||||||
onDismiss()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
sheetState = sheetState,
|
sheetState = sheetState,
|
||||||
shape = RoundedCornerShape(topStart = 24.dp, topEnd = 24.dp)
|
shape = RoundedCornerShape(topStart = 24.dp, topEnd = 24.dp)
|
||||||
) {
|
) {
|
||||||
@@ -359,6 +355,9 @@ fun PredictWeekSheet(
|
|||||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
textAlign = TextAlign.Center
|
textAlign = TextAlign.Center
|
||||||
)
|
)
|
||||||
|
TextButton(onClick = onDismiss) {
|
||||||
|
Text("Annuler")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -87,11 +87,7 @@ fun ReceiptReviewSheet(
|
|||||||
var alsoCheckShoppingList by remember { mutableStateOf(true) }
|
var alsoCheckShoppingList by remember { mutableStateOf(true) }
|
||||||
|
|
||||||
ModalBottomSheet(
|
ModalBottomSheet(
|
||||||
onDismissRequest = {
|
onDismissRequest = onDismiss,
|
||||||
if (scanState !is ReceiptScanUiState.Scanning) {
|
|
||||||
onDismiss()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
sheetState = sheetState,
|
sheetState = sheetState,
|
||||||
shape = RoundedCornerShape(topStart = 24.dp, topEnd = 24.dp)
|
shape = RoundedCornerShape(topStart = 24.dp, topEnd = 24.dp)
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -157,11 +157,7 @@ fun ImportRecipeSheet(
|
|||||||
}
|
}
|
||||||
|
|
||||||
ModalBottomSheet(
|
ModalBottomSheet(
|
||||||
onDismissRequest = {
|
onDismissRequest = onDismiss,
|
||||||
if (importState !is RecipeImportUiState.Loading) {
|
|
||||||
onDismiss()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
sheetState = sheetState,
|
sheetState = sheetState,
|
||||||
shape = RoundedCornerShape(topStart = 24.dp, topEnd = 24.dp)
|
shape = RoundedCornerShape(topStart = 24.dp, topEnd = 24.dp)
|
||||||
) {
|
) {
|
||||||
|
|||||||
Reference in new issue
Block a user