mirror of
https://github.com/bleackstorm/satiea.git
synced 2026-12-03 07:41:56 +01:00
fix(planning): render barcode scanner as full-screen activity overlay instead of Dialog
This commit is contained in:
1 parent
6b245d31bb
commit
6bbbe7d423
3 files changed
+33
-58
No files matched your search
@@ -65,6 +65,7 @@ import com.example.ui.journal.JournalScreen
|
||||
import com.example.ui.journal.MealViewModel
|
||||
import com.example.ui.journal.MealsUiState
|
||||
import com.example.ui.meal.MealEntrySheet
|
||||
import com.example.ui.planning.BarcodeScannerScreen
|
||||
import com.example.ui.planning.PlanningScreen
|
||||
import com.example.ui.planning.PlanningViewModel
|
||||
import com.example.ui.planning.StockDeductionDialog
|
||||
@@ -210,6 +211,7 @@ fun AppRoot(
|
||||
var selectedRecipeId by remember { mutableStateOf<String?>(null) }
|
||||
var showRecipeEditor by remember { mutableStateOf(false) }
|
||||
var editingRecipe by remember { mutableStateOf<RecipeEntry?>(null) }
|
||||
var showBarcodeScanner by rememberSaveable { mutableStateOf(false) }
|
||||
|
||||
LaunchedEffect(openPlanningRequested) {
|
||||
if (openPlanningRequested) {
|
||||
@@ -428,10 +430,11 @@ fun AppRoot(
|
||||
}
|
||||
}
|
||||
|
||||
BackHandler(enabled = currentTab != MainTab.JOURNAL) {
|
||||
BackHandler(enabled = currentTab != MainTab.JOURNAL && !showBarcodeScanner) {
|
||||
currentTab = MainTab.JOURNAL
|
||||
}
|
||||
|
||||
Box(modifier = Modifier.fillMaxSize()) {
|
||||
Scaffold(
|
||||
contentWindowInsets = WindowInsets.safeDrawing,
|
||||
snackbarHost = { SnackbarHost(hostState = snackbarHostState) },
|
||||
@@ -678,18 +681,7 @@ fun AppRoot(
|
||||
planningViewModel.confirmScannedReceiptImport(items, alsoCheckShopping)
|
||||
},
|
||||
onDismissReceiptScan = { planningViewModel.dismissReceiptScan() },
|
||||
barcodeScanItems = barcodeScanItems,
|
||||
barcodeScanFeedback = barcodeScanFeedback,
|
||||
onBarcodeDetected = { code -> planningViewModel.onBarcodeScanned(code) },
|
||||
onAdjustBarcodePacks = { id, delta ->
|
||||
planningViewModel.adjustBarcodeItemPacks(id, delta)
|
||||
},
|
||||
onUpdateBarcodeItem = { item -> planningViewModel.updateBarcodeItem(item) },
|
||||
onRemoveBarcodeItem = { id -> planningViewModel.removeBarcodeItem(id) },
|
||||
onConfirmBarcodeImport = { alsoCheckShopping ->
|
||||
planningViewModel.confirmBarcodeBurstImport(alsoCheckShopping)
|
||||
},
|
||||
onClearBarcodeScanSession = { planningViewModel.clearBarcodeScanSession() },
|
||||
onOpenBarcodeScanner = { showBarcodeScanner = true },
|
||||
onShowMessage = { msg -> viewModel.emitEvent(UiEvent.ShowSnackbar(msg)) }
|
||||
)
|
||||
}
|
||||
@@ -877,4 +869,21 @@ fun AppRoot(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (showBarcodeScanner) {
|
||||
BarcodeScannerScreen(
|
||||
scannedItems = barcodeScanItems,
|
||||
lastFeedback = barcodeScanFeedback,
|
||||
onBarcodeDetected = { code -> planningViewModel.onBarcodeScanned(code) },
|
||||
onAdjustPacks = { id, delta -> planningViewModel.adjustBarcodeItemPacks(id, delta) },
|
||||
onUpdateItem = { item -> planningViewModel.updateBarcodeItem(item) },
|
||||
onRemoveItem = { id -> planningViewModel.removeBarcodeItem(id) },
|
||||
onConfirmImport = { alsoCheckShopping ->
|
||||
planningViewModel.confirmBarcodeBurstImport(alsoCheckShopping)
|
||||
},
|
||||
onClearAll = { planningViewModel.clearBarcodeScanSession() },
|
||||
onDismiss = { showBarcodeScanner = false }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -90,8 +90,6 @@ import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.viewinterop.AndroidView
|
||||
import androidx.compose.ui.window.Dialog
|
||||
import androidx.compose.ui.window.DialogProperties
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.lifecycle.compose.LocalLifecycleOwner
|
||||
import coil.compose.AsyncImage
|
||||
@@ -136,21 +134,14 @@ fun BarcodeScannerScreen(
|
||||
scannedItems.sumOf { it.packCount }
|
||||
}
|
||||
|
||||
Dialog(
|
||||
onDismissRequest = onDismiss,
|
||||
properties = DialogProperties(
|
||||
usePlatformDefaultWidth = false,
|
||||
decorFitsSystemWindows = false
|
||||
)
|
||||
) {
|
||||
BackHandler(onBack = onDismiss)
|
||||
BackHandler(onBack = onDismiss)
|
||||
|
||||
Scaffold(
|
||||
contentWindowInsets = WindowInsets(0, 0, 0, 0),
|
||||
containerColor = Color.Black,
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.testTag("barcode_scanner_screen"),
|
||||
Scaffold(
|
||||
contentWindowInsets = WindowInsets(0, 0, 0, 0),
|
||||
containerColor = Color.Black,
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.testTag("barcode_scanner_screen"),
|
||||
bottomBar = {
|
||||
Surface(
|
||||
tonalElevation = 6.dp,
|
||||
@@ -471,7 +462,6 @@ fun BarcodeScannerScreen(
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (showManualBarcodeDialog) {
|
||||
ManualBarcodeInputDialog(
|
||||
|
||||
@@ -65,7 +65,6 @@ import com.example.data.model.PlannedMealEntry
|
||||
import com.example.data.model.PredictionMealScope
|
||||
import com.example.data.model.ReceiptScanUiState
|
||||
import com.example.data.model.RecipeEntry
|
||||
import com.example.data.model.ScannedBarcodeItem
|
||||
import com.example.data.model.ScannedReceiptItem
|
||||
import com.example.data.model.ShoppingListItem
|
||||
import com.example.data.model.StorageLocation
|
||||
@@ -125,14 +124,7 @@ fun PlanningScreen(
|
||||
onAddBlankScannedItem: () -> Unit,
|
||||
onConfirmReceiptImport: (List<ScannedReceiptItem>, Boolean) -> Unit,
|
||||
onDismissReceiptScan: () -> Unit,
|
||||
barcodeScanItems: List<ScannedBarcodeItem> = emptyList(),
|
||||
barcodeScanFeedback: String? = null,
|
||||
onBarcodeDetected: (String) -> Unit = {},
|
||||
onAdjustBarcodePacks: (itemId: String, delta: Int) -> Unit = { _, _ -> },
|
||||
onUpdateBarcodeItem: (ScannedBarcodeItem) -> Unit = {},
|
||||
onRemoveBarcodeItem: (String) -> Unit = {},
|
||||
onConfirmBarcodeImport: (Boolean) -> Unit = {},
|
||||
onClearBarcodeScanSession: () -> Unit = {},
|
||||
onOpenBarcodeScanner: () -> Unit = {},
|
||||
onShowMessage: (String) -> Unit
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
@@ -153,7 +145,6 @@ fun PlanningScreen(
|
||||
var shoppingItemForStockPrompt by remember { mutableStateOf<ShoppingListItem?>(null) }
|
||||
var showPredictWeekSheet by rememberSaveable { mutableStateOf(false) }
|
||||
var showShoppingMode by rememberSaveable { mutableStateOf(false) }
|
||||
var showBarcodeScanner by rememberSaveable { mutableStateOf(false) }
|
||||
|
||||
val recipesById = remember(recipes) { recipes.associateBy { it.id } }
|
||||
|
||||
@@ -234,10 +225,10 @@ fun PlanningScreen(
|
||||
contract = ActivityResultContracts.RequestPermission()
|
||||
) { granted ->
|
||||
if (granted) {
|
||||
showBarcodeScanner = true
|
||||
onOpenBarcodeScanner()
|
||||
} else {
|
||||
onShowMessage("Autorisation caméra nécessaire pour scanner les codes-barres (vous pouvez aussi les saisir au clavier)")
|
||||
showBarcodeScanner = true
|
||||
onOpenBarcodeScanner()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -247,7 +238,7 @@ fun PlanningScreen(
|
||||
Manifest.permission.CAMERA
|
||||
) == PackageManager.PERMISSION_GRANTED
|
||||
if (hasCameraPerm) {
|
||||
showBarcodeScanner = true
|
||||
onOpenBarcodeScanner()
|
||||
} else {
|
||||
barcodeCameraPermissionLauncher.launch(Manifest.permission.CAMERA)
|
||||
}
|
||||
@@ -586,21 +577,6 @@ fun PlanningScreen(
|
||||
onDismiss = { showShoppingMode = false }
|
||||
)
|
||||
}
|
||||
|
||||
// Fullscreen Burst Barcode Scanner (Open Food Facts)
|
||||
if (showBarcodeScanner) {
|
||||
BarcodeScannerScreen(
|
||||
scannedItems = barcodeScanItems,
|
||||
lastFeedback = barcodeScanFeedback,
|
||||
onBarcodeDetected = onBarcodeDetected,
|
||||
onAdjustPacks = onAdjustBarcodePacks,
|
||||
onUpdateItem = onUpdateBarcodeItem,
|
||||
onRemoveItem = onRemoveBarcodeItem,
|
||||
onConfirmImport = onConfirmBarcodeImport,
|
||||
onClearAll = onClearBarcodeScanSession,
|
||||
onDismiss = { showBarcodeScanner = false }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
|
||||
Reference in new issue
Block a user