mirror of
https://github.com/bleackstorm/satiea.git
synced 2026-12-03 07:41:56 +01:00
feat(planning): add burst barcode scanner with Open Food Facts lookup
This commit is contained in:
1 parent
381fe9ab72
commit
7c5dab5477
10 files changed
+1614
-9
No files matched your search
@@ -65,6 +65,7 @@ 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
|
||||
@@ -124,6 +125,14 @@ 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 = {},
|
||||
onShowMessage: (String) -> Unit
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
@@ -144,6 +153,7 @@ 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 } }
|
||||
|
||||
@@ -220,6 +230,29 @@ fun PlanningScreen(
|
||||
)
|
||||
}
|
||||
|
||||
val barcodeCameraPermissionLauncher = rememberLauncherForActivityResult(
|
||||
contract = ActivityResultContracts.RequestPermission()
|
||||
) { granted ->
|
||||
if (granted) {
|
||||
showBarcodeScanner = true
|
||||
} else {
|
||||
onShowMessage("Autorisation caméra nécessaire pour scanner les codes-barres (vous pouvez aussi les saisir au clavier)")
|
||||
showBarcodeScanner = true
|
||||
}
|
||||
}
|
||||
|
||||
val triggerBarcodeScanner = {
|
||||
val hasCameraPerm = ContextCompat.checkSelfPermission(
|
||||
context,
|
||||
Manifest.permission.CAMERA
|
||||
) == PackageManager.PERMISSION_GRANTED
|
||||
if (hasCameraPerm) {
|
||||
showBarcodeScanner = true
|
||||
} else {
|
||||
barcodeCameraPermissionLauncher.launch(Manifest.permission.CAMERA)
|
||||
}
|
||||
}
|
||||
|
||||
val uncheckedShoppingCount = shoppingItems.count { !it.isChecked }
|
||||
|
||||
Box(
|
||||
@@ -332,6 +365,7 @@ fun PlanningScreen(
|
||||
InventoryTab(
|
||||
inventoryItems = inventoryItems,
|
||||
alertThresholdDays = expirationAlertDays,
|
||||
onScanBarcodeClick = triggerBarcodeScanner,
|
||||
onScanReceiptClick = { showReceiptSourceDialog = true },
|
||||
onAddManualClick = {
|
||||
editingInventoryItem = null
|
||||
@@ -550,6 +584,21 @@ 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