mirror of
https://github.com/bleackstorm/satiea.git
synced 2026-12-03 07:41:56 +01:00
feat(planning): add expiration dates, alerts, and AI menu adaptation
This commit is contained in:
1 parent
e534cfa7b0
commit
381fe9ab72
24 files changed
+2253
-54
No files matched your search
@@ -20,13 +20,18 @@ import androidx.compose.foundation.text.KeyboardOptions
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.ReceiptLong
|
||||
import androidx.compose.material.icons.filled.Add
|
||||
import androidx.compose.material.icons.filled.CalendarMonth
|
||||
import androidx.compose.material.icons.filled.Close
|
||||
import androidx.compose.material.icons.filled.DeleteOutline
|
||||
import androidx.compose.material.icons.filled.ErrorOutline
|
||||
import androidx.compose.material3.AssistChip
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.Card
|
||||
import androidx.compose.material3.CardDefaults
|
||||
import androidx.compose.material3.Checkbox
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.DatePicker
|
||||
import androidx.compose.material3.DatePickerDialog
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.FilterChip
|
||||
import androidx.compose.material3.Icon
|
||||
@@ -39,6 +44,7 @@ import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Switch
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.material3.rememberDatePickerState
|
||||
import androidx.compose.material3.rememberModalBottomSheetState
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
@@ -58,6 +64,11 @@ import com.example.data.model.ReceiptScanUiState
|
||||
import com.example.data.model.ScannedReceiptItem
|
||||
import com.example.data.model.StorageLocation
|
||||
import com.example.ui.common.FoodCategorySelectorRow
|
||||
import java.time.Instant
|
||||
import java.time.LocalDate
|
||||
import java.time.ZoneOffset
|
||||
import java.time.format.DateTimeFormatter
|
||||
import java.util.Locale
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
@@ -279,6 +290,7 @@ fun ReceiptReviewSheet(
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
private fun ScannedItemReviewCard(
|
||||
item: ScannedReceiptItem,
|
||||
@@ -290,6 +302,9 @@ private fun ScannedItemReviewCard(
|
||||
if (item.quantity % 1.0 == 0.0) item.quantity.toInt().toString() else item.quantity.toString()
|
||||
)
|
||||
}
|
||||
var showDatePicker by remember { mutableStateOf(false) }
|
||||
val today = remember { LocalDate.now() }
|
||||
val dateFmt = remember { DateTimeFormatter.ofPattern("d MMM", Locale.FRENCH) }
|
||||
|
||||
Card(
|
||||
shape = RoundedCornerShape(16.dp),
|
||||
@@ -402,6 +417,84 @@ private fun ScannedItemReviewCard(
|
||||
selectedCategory = item.category,
|
||||
onCategorySelected = { cat -> onUpdate(item.copy(category = cat)) }
|
||||
)
|
||||
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.spacedBy(6.dp),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
AssistChip(
|
||||
onClick = { showDatePicker = true },
|
||||
leadingIcon = {
|
||||
Icon(
|
||||
imageVector = Icons.Default.CalendarMonth,
|
||||
contentDescription = null,
|
||||
modifier = Modifier.size(16.dp)
|
||||
)
|
||||
},
|
||||
label = {
|
||||
Text(
|
||||
text = item.expirationDateEpochDay?.let {
|
||||
"DLC : ${LocalDate.ofEpochDay(it).format(dateFmt)}"
|
||||
} ?: "DLC : aucune",
|
||||
maxLines = 1
|
||||
)
|
||||
}
|
||||
)
|
||||
FilterChip(
|
||||
selected = item.expirationDateEpochDay == today.plusDays(3).toEpochDay(),
|
||||
onClick = { onUpdate(item.copy(expirationDateEpochDay = today.plusDays(3).toEpochDay())) },
|
||||
label = { Text("+3 j") }
|
||||
)
|
||||
FilterChip(
|
||||
selected = item.expirationDateEpochDay == today.plusDays(7).toEpochDay(),
|
||||
onClick = { onUpdate(item.copy(expirationDateEpochDay = today.plusDays(7).toEpochDay())) },
|
||||
label = { Text("+7 j") }
|
||||
)
|
||||
if (item.expirationDateEpochDay != null) {
|
||||
IconButton(
|
||||
onClick = { onUpdate(item.copy(expirationDateEpochDay = null)) },
|
||||
modifier = Modifier.size(32.dp)
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.Close,
|
||||
contentDescription = "Effacer la DLC",
|
||||
modifier = Modifier.size(16.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (showDatePicker) {
|
||||
val initialMillis = (item.expirationDateEpochDay ?: today.plusDays(5).toEpochDay()) * 86_400_000L
|
||||
val datePickerState = rememberDatePickerState(initialSelectedDateMillis = initialMillis)
|
||||
DatePickerDialog(
|
||||
onDismissRequest = { showDatePicker = false },
|
||||
confirmButton = {
|
||||
TextButton(
|
||||
onClick = {
|
||||
datePickerState.selectedDateMillis?.let { millis ->
|
||||
val pickedEpoch = Instant.ofEpochMilli(millis)
|
||||
.atZone(ZoneOffset.UTC)
|
||||
.toLocalDate()
|
||||
.toEpochDay()
|
||||
onUpdate(item.copy(expirationDateEpochDay = pickedEpoch))
|
||||
}
|
||||
showDatePicker = false
|
||||
}
|
||||
) {
|
||||
Text("Valider")
|
||||
}
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = { showDatePicker = false }) {
|
||||
Text("Annuler")
|
||||
}
|
||||
}
|
||||
) {
|
||||
DatePicker(state = datePickerState)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user