Przyspiesz wyświetlanie dodawanych zdjęć
This commit is contained in:
@@ -1202,9 +1202,22 @@ private fun RoutesScreen(
|
|||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val coroutineScope = rememberCoroutineScope()
|
val coroutineScope = rememberCoroutineScope()
|
||||||
var cameraUri by remember { mutableStateOf<Uri?>(null) }
|
var cameraUri by remember { mutableStateOf<Uri?>(null) }
|
||||||
|
var cameraLocationMetadata by remember { mutableStateOf(PhotoUploadMetadata()) }
|
||||||
|
var cameraMetadataGeneration by remember { mutableStateOf(0L) }
|
||||||
var showPreciseLocationPermissionDialog by remember { mutableStateOf(false) }
|
var showPreciseLocationPermissionDialog by remember { mutableStateOf(false) }
|
||||||
var showRouteDatePicker by remember { mutableStateOf(false) }
|
var showRouteDatePicker by remember { mutableStateOf(false) }
|
||||||
var showTachographConfirmation by remember { mutableStateOf(false) }
|
var showTachographConfirmation by remember { mutableStateOf(false) }
|
||||||
|
val prepareCameraMetadata = {
|
||||||
|
val generation = cameraMetadataGeneration + 1
|
||||||
|
cameraMetadataGeneration = generation
|
||||||
|
cameraLocationMetadata = PhotoUploadMetadata()
|
||||||
|
coroutineScope.launch {
|
||||||
|
val metadata = cameraPhotoMetadata(context).copy(takenAt = null)
|
||||||
|
if (cameraMetadataGeneration == generation) {
|
||||||
|
cameraLocationMetadata = metadata
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
val cameraLauncher = rememberLauncherForActivityResult(ActivityResultContracts.TakePicture()) { ok ->
|
val cameraLauncher = rememberLauncherForActivityResult(ActivityResultContracts.TakePicture()) { ok ->
|
||||||
val capturedUri = cameraUri
|
val capturedUri = cameraUri
|
||||||
if (
|
if (
|
||||||
@@ -1215,10 +1228,13 @@ private fun RoutesScreen(
|
|||||||
hasFineLocation = hasPermission(context, Manifest.permission.ACCESS_FINE_LOCATION),
|
hasFineLocation = hasPermission(context, Manifest.permission.ACCESS_FINE_LOCATION),
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
coroutineScope.launch {
|
onDispatchSheetUpload(
|
||||||
onDispatchSheetUpload(capturedUri, "camera", cameraPhotoMetadata(context))
|
capturedUri,
|
||||||
}
|
"camera",
|
||||||
|
cameraLocationMetadata.copy(takenAt = Instant.now().toString()),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
cameraMetadataGeneration += 1
|
||||||
cameraUri = null
|
cameraUri = null
|
||||||
}
|
}
|
||||||
val cameraPermissionLauncher = rememberLauncherForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) { grants ->
|
val cameraPermissionLauncher = rememberLauncherForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) { grants ->
|
||||||
@@ -1228,10 +1244,14 @@ private fun RoutesScreen(
|
|||||||
hasPermission(context, Manifest.permission.ACCESS_FINE_LOCATION)
|
hasPermission(context, Manifest.permission.ACCESS_FINE_LOCATION)
|
||||||
if (!canLaunchCameraWithLocationPolicy(state.requirePreciseLocationForPhotos, fineLocationGranted)) {
|
if (!canLaunchCameraWithLocationPolicy(state.requirePreciseLocationForPhotos, fineLocationGranted)) {
|
||||||
showPreciseLocationPermissionDialog = true
|
showPreciseLocationPermissionDialog = true
|
||||||
|
cameraMetadataGeneration += 1
|
||||||
cameraUri = null
|
cameraUri = null
|
||||||
return@rememberLauncherForActivityResult
|
return@rememberLauncherForActivityResult
|
||||||
}
|
}
|
||||||
if (cameraGranted && pendingUri != null) cameraLauncher.launch(pendingUri)
|
if (cameraGranted && pendingUri != null) {
|
||||||
|
prepareCameraMetadata()
|
||||||
|
cameraLauncher.launch(pendingUri)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LaunchedEffect(state.routeDayLiveUpdateMessage) {
|
LaunchedEffect(state.routeDayLiveUpdateMessage) {
|
||||||
@@ -1339,6 +1359,7 @@ private fun RoutesScreen(
|
|||||||
requirePreciseLocation = state.requirePreciseLocationForPhotos,
|
requirePreciseLocation = state.requirePreciseLocationForPhotos,
|
||||||
)
|
)
|
||||||
if (missingPermissions.isEmpty()) {
|
if (missingPermissions.isEmpty()) {
|
||||||
|
prepareCameraMetadata()
|
||||||
cameraLauncher.launch(newUri)
|
cameraLauncher.launch(newUri)
|
||||||
} else {
|
} else {
|
||||||
cameraPermissionLauncher.launch(missingPermissions)
|
cameraPermissionLauncher.launch(missingPermissions)
|
||||||
@@ -4449,13 +4470,20 @@ private fun RouteStageScreen(
|
|||||||
var voiceDictationActive by remember(stage) { mutableStateOf(false) }
|
var voiceDictationActive by remember(stage) { mutableStateOf(false) }
|
||||||
var cameraAttachmentTarget by remember(stage) { mutableStateOf<RouteWorkflowAttachmentTarget?>(null) }
|
var cameraAttachmentTarget by remember(stage) { mutableStateOf<RouteWorkflowAttachmentTarget?>(null) }
|
||||||
var pickerAttachmentTarget by remember(stage) { mutableStateOf<RouteWorkflowAttachmentTarget?>(null) }
|
var pickerAttachmentTarget by remember(stage) { mutableStateOf<RouteWorkflowAttachmentTarget?>(null) }
|
||||||
|
var singlePhotoLocationMetadata by remember(stage) { mutableStateOf(PhotoUploadMetadata()) }
|
||||||
|
var singlePhotoMetadataGeneration by remember(stage) { mutableStateOf(0L) }
|
||||||
val route = state.displaySelectedRoute
|
val route = state.displaySelectedRoute
|
||||||
val stagePhotos = route?.photos?.let { routePhotosForStage(it, stage) }.orEmpty()
|
val stagePhotos = route?.photos?.let { routePhotosForStage(it, stage) }.orEmpty()
|
||||||
val stageUploads = state.photoUploads.filter { normalizedRoutePhotoStage(it.stage) == stage }
|
val stageUploads = state.photoUploads.filter { normalizedRoutePhotoStage(it.stage) == stage }
|
||||||
|
val stagePreparations = state.preparingPhotoUploads.filter { normalizedRoutePhotoStage(it.stage) == stage }
|
||||||
val usableStageUploads = routeStageUsableUploads(stageUploads)
|
val usableStageUploads = routeStageUsableUploads(stageUploads)
|
||||||
val cargoStagePhotos = stagePhotos.filter { it.workflowDocumentId.isNullOrBlank() }
|
val cargoStagePhotos = stagePhotos.filter { it.workflowDocumentId.isNullOrBlank() }
|
||||||
val cargoStageUploads = usableStageUploads.filter { it.workflowDocumentId.isNullOrBlank() }
|
val cargoStageUploads = usableStageUploads.filter { it.workflowDocumentId.isNullOrBlank() }
|
||||||
val attachmentCount = visiblePhotoAttachmentCount(cargoStagePhotos.size, cargoStageUploads.size)
|
val cargoStagePreparations = stagePreparations.filter { it.workflowDocumentId.isNullOrBlank() }
|
||||||
|
val attachmentCount = visiblePhotoAttachmentCount(
|
||||||
|
cargoStagePhotos.size,
|
||||||
|
cargoStageUploads.size + cargoStagePreparations.size,
|
||||||
|
)
|
||||||
val photoRequirement = if (stage == "loading") state.loadingPhotoRequirement else state.unloadingPhotoRequirement
|
val photoRequirement = if (stage == "loading") state.loadingPhotoRequirement else state.unloadingPhotoRequirement
|
||||||
val weightRequirement = if (stage == "loading") state.loadingWeightRequirement else state.unloadingWeightRequirement
|
val weightRequirement = if (stage == "loading") state.loadingWeightRequirement else state.unloadingWeightRequirement
|
||||||
val submitBlocker = if (state.routeWorkflow != null) {
|
val submitBlocker = if (state.routeWorkflow != null) {
|
||||||
@@ -4494,9 +4522,21 @@ private fun RouteStageScreen(
|
|||||||
submitBlocker
|
submitBlocker
|
||||||
}
|
}
|
||||||
val weightBlocker = submitBlocker?.takeIf { it.contains("wag", ignoreCase = true) || it.contains("popraw", ignoreCase = true) }
|
val weightBlocker = submitBlocker?.takeIf { it.contains("wag", ignoreCase = true) || it.contains("popraw", ignoreCase = true) }
|
||||||
|
val prepareSinglePhotoMetadata = {
|
||||||
|
val generation = singlePhotoMetadataGeneration + 1
|
||||||
|
singlePhotoMetadataGeneration = generation
|
||||||
|
singlePhotoLocationMetadata = PhotoUploadMetadata()
|
||||||
|
coroutineScope.launch {
|
||||||
|
val metadata = cameraPhotoMetadata(context).copy(takenAt = null)
|
||||||
|
if (singlePhotoMetadataGeneration == generation) {
|
||||||
|
singlePhotoLocationMetadata = metadata
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val cameraLauncher = rememberLauncherForActivityResult(ActivityResultContracts.TakePicture()) { ok ->
|
val cameraLauncher = rememberLauncherForActivityResult(ActivityResultContracts.TakePicture()) { ok ->
|
||||||
val capturedUri = cameraUri
|
val capturedUri = cameraUri
|
||||||
|
val attachmentTarget = cameraAttachmentTarget
|
||||||
if (
|
if (
|
||||||
ok &&
|
ok &&
|
||||||
capturedUri != null &&
|
capturedUri != null &&
|
||||||
@@ -4509,12 +4549,13 @@ private fun RouteStageScreen(
|
|||||||
onUpload(
|
onUpload(
|
||||||
capturedUri,
|
capturedUri,
|
||||||
"camera",
|
"camera",
|
||||||
cameraPhotoMetadata(context),
|
singlePhotoLocationMetadata.copy(takenAt = Instant.now().toString()),
|
||||||
cameraAttachmentTarget?.stepId,
|
attachmentTarget?.stepId,
|
||||||
cameraAttachmentTarget?.documentId,
|
attachmentTarget?.documentId,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
singlePhotoMetadataGeneration += 1
|
||||||
cameraUri = null
|
cameraUri = null
|
||||||
cameraAttachmentTarget = null
|
cameraAttachmentTarget = null
|
||||||
}
|
}
|
||||||
@@ -4533,6 +4574,7 @@ private fun RouteStageScreen(
|
|||||||
hasPermission(context, Manifest.permission.ACCESS_FINE_LOCATION)
|
hasPermission(context, Manifest.permission.ACCESS_FINE_LOCATION)
|
||||||
if (!canLaunchCameraWithLocationPolicy(state.requirePreciseLocationForPhotos, fineLocationGranted)) {
|
if (!canLaunchCameraWithLocationPolicy(state.requirePreciseLocationForPhotos, fineLocationGranted)) {
|
||||||
showPreciseLocationPermissionDialog = true
|
showPreciseLocationPermissionDialog = true
|
||||||
|
singlePhotoMetadataGeneration += 1
|
||||||
cameraUri = null
|
cameraUri = null
|
||||||
pendingCameraMode = null
|
pendingCameraMode = null
|
||||||
return@rememberLauncherForActivityResult
|
return@rememberLauncherForActivityResult
|
||||||
@@ -4540,7 +4582,10 @@ private fun RouteStageScreen(
|
|||||||
if (cameraGranted) {
|
if (cameraGranted) {
|
||||||
when (requestedMode) {
|
when (requestedMode) {
|
||||||
RouteStageCameraMode.Single -> {
|
RouteStageCameraMode.Single -> {
|
||||||
if (pendingUri != null) cameraLauncher.launch(pendingUri)
|
if (pendingUri != null) {
|
||||||
|
prepareSinglePhotoMetadata()
|
||||||
|
cameraLauncher.launch(pendingUri)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
RouteStageCameraMode.Multiple -> {
|
RouteStageCameraMode.Multiple -> {
|
||||||
openMultiplePhotoCamera()
|
openMultiplePhotoCamera()
|
||||||
@@ -4553,28 +4598,30 @@ private fun RouteStageScreen(
|
|||||||
pendingCameraMode = null
|
pendingCameraMode = null
|
||||||
}
|
}
|
||||||
val pickerLauncher = rememberLauncherForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri ->
|
val pickerLauncher = rememberLauncherForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri ->
|
||||||
|
val attachmentTarget = pickerAttachmentTarget
|
||||||
if (uri != null) {
|
if (uri != null) {
|
||||||
coroutineScope.launch {
|
coroutineScope.launch {
|
||||||
onUpload(
|
onUpload(
|
||||||
uri,
|
uri,
|
||||||
"gallery",
|
"gallery",
|
||||||
PhotoUploadMetadata(),
|
PhotoUploadMetadata(),
|
||||||
pickerAttachmentTarget?.stepId,
|
attachmentTarget?.stepId,
|
||||||
pickerAttachmentTarget?.documentId,
|
attachmentTarget?.documentId,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pickerAttachmentTarget = null
|
pickerAttachmentTarget = null
|
||||||
}
|
}
|
||||||
val filePickerLauncher = rememberLauncherForActivityResult(ActivityResultContracts.OpenDocument()) { uri ->
|
val filePickerLauncher = rememberLauncherForActivityResult(ActivityResultContracts.OpenDocument()) { uri ->
|
||||||
|
val attachmentTarget = pickerAttachmentTarget
|
||||||
if (uri != null) {
|
if (uri != null) {
|
||||||
coroutineScope.launch {
|
coroutineScope.launch {
|
||||||
onUpload(
|
onUpload(
|
||||||
uri,
|
uri,
|
||||||
"file",
|
"file",
|
||||||
PhotoUploadMetadata(),
|
PhotoUploadMetadata(),
|
||||||
pickerAttachmentTarget?.stepId,
|
attachmentTarget?.stepId,
|
||||||
pickerAttachmentTarget?.documentId,
|
attachmentTarget?.documentId,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4629,6 +4676,7 @@ private fun RouteStageScreen(
|
|||||||
weightText = state.routeStageWeightText,
|
weightText = state.routeStageWeightText,
|
||||||
serverPhotos = stagePhotos,
|
serverPhotos = stagePhotos,
|
||||||
localUploads = usableStageUploads,
|
localUploads = usableStageUploads,
|
||||||
|
preparingUploads = stagePreparations,
|
||||||
onStepToggle = onStepToggle,
|
onStepToggle = onStepToggle,
|
||||||
onTakeDocumentPhoto = { stepId, documentId ->
|
onTakeDocumentPhoto = { stepId, documentId ->
|
||||||
cameraAttachmentTarget = RouteWorkflowAttachmentTarget(stepId, documentId)
|
cameraAttachmentTarget = RouteWorkflowAttachmentTarget(stepId, documentId)
|
||||||
@@ -4641,6 +4689,7 @@ private fun RouteStageScreen(
|
|||||||
)
|
)
|
||||||
if (missingPermissions.isEmpty()) {
|
if (missingPermissions.isEmpty()) {
|
||||||
pendingCameraMode = null
|
pendingCameraMode = null
|
||||||
|
prepareSinglePhotoMetadata()
|
||||||
cameraLauncher.launch(newUri)
|
cameraLauncher.launch(newUri)
|
||||||
} else {
|
} else {
|
||||||
cameraPermissionLauncher.launch(missingPermissions)
|
cameraPermissionLauncher.launch(missingPermissions)
|
||||||
@@ -4726,6 +4775,7 @@ private fun RouteStageScreen(
|
|||||||
)
|
)
|
||||||
if (missingPermissions.isEmpty()) {
|
if (missingPermissions.isEmpty()) {
|
||||||
pendingCameraMode = null
|
pendingCameraMode = null
|
||||||
|
prepareSinglePhotoMetadata()
|
||||||
cameraLauncher.launch(newUri)
|
cameraLauncher.launch(newUri)
|
||||||
} else {
|
} else {
|
||||||
cameraPermissionLauncher.launch(missingPermissions)
|
cameraPermissionLauncher.launch(missingPermissions)
|
||||||
@@ -4761,6 +4811,7 @@ private fun RouteStageScreen(
|
|||||||
PhotoGrid(
|
PhotoGrid(
|
||||||
photos = cargoStagePhotos,
|
photos = cargoStagePhotos,
|
||||||
uploads = stageUploads.filter { it.workflowDocumentId.isNullOrBlank() },
|
uploads = stageUploads.filter { it.workflowDocumentId.isNullOrBlank() },
|
||||||
|
preparations = cargoStagePreparations,
|
||||||
deletingPhotoIds = state.deletingPhotoIds,
|
deletingPhotoIds = state.deletingPhotoIds,
|
||||||
imageAuthHeader = state.imageAuthHeader,
|
imageAuthHeader = state.imageAuthHeader,
|
||||||
onPhoto = onPhoto,
|
onPhoto = onPhoto,
|
||||||
@@ -4816,6 +4867,7 @@ private fun RouteWorkflowStepsCard(
|
|||||||
weightText: String,
|
weightText: String,
|
||||||
serverPhotos: List<RoutePhotoDto>,
|
serverPhotos: List<RoutePhotoDto>,
|
||||||
localUploads: List<PhotoUploadEntity>,
|
localUploads: List<PhotoUploadEntity>,
|
||||||
|
preparingUploads: List<PreparingPhotoUpload>,
|
||||||
onStepToggle: (String, Boolean) -> Unit,
|
onStepToggle: (String, Boolean) -> Unit,
|
||||||
onTakeDocumentPhoto: (String, String) -> Unit,
|
onTakeDocumentPhoto: (String, String) -> Unit,
|
||||||
onPickDocumentPhoto: (String, String) -> Unit,
|
onPickDocumentPhoto: (String, String) -> Unit,
|
||||||
@@ -4902,7 +4954,10 @@ private fun RouteWorkflowStepsCard(
|
|||||||
it.status != PhotoUploadStatus.Cancelled.storageValue &&
|
it.status != PhotoUploadStatus.Cancelled.storageValue &&
|
||||||
it.status != PhotoUploadStatus.FailedPermanent.storageValue
|
it.status != PhotoUploadStatus.FailedPermanent.storageValue
|
||||||
}
|
}
|
||||||
val count = documentServerPhotos.size + documentUploads.size
|
val documentPreparations = preparingUploads.count {
|
||||||
|
it.workflowStepId == step.id && it.workflowDocumentId == document.id
|
||||||
|
}
|
||||||
|
val count = documentServerPhotos.size + documentUploads.size + documentPreparations
|
||||||
Column(
|
Column(
|
||||||
Modifier
|
Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
@@ -5951,6 +6006,7 @@ private fun CargoActionButton(label: String, icon: ImageVector, color: Color, on
|
|||||||
private fun PhotoGrid(
|
private fun PhotoGrid(
|
||||||
photos: List<RoutePhotoDto>,
|
photos: List<RoutePhotoDto>,
|
||||||
uploads: List<PhotoUploadEntity>,
|
uploads: List<PhotoUploadEntity>,
|
||||||
|
preparations: List<PreparingPhotoUpload> = emptyList(),
|
||||||
deletingPhotoIds: Set<String>,
|
deletingPhotoIds: Set<String>,
|
||||||
imageAuthHeader: String?,
|
imageAuthHeader: String?,
|
||||||
onPhoto: (RoutePhotoDto) -> Unit,
|
onPhoto: (RoutePhotoDto) -> Unit,
|
||||||
@@ -5960,9 +6016,13 @@ private fun PhotoGrid(
|
|||||||
readOnly: Boolean = false,
|
readOnly: Boolean = false,
|
||||||
) {
|
) {
|
||||||
var pendingDelete by remember { mutableStateOf<PhotoDeleteTarget?>(null) }
|
var pendingDelete by remember { mutableStateOf<PhotoDeleteTarget?>(null) }
|
||||||
val items = (uploads.map { PhotoGridItem.Upload(it) } + photos.map { PhotoGridItem.Server(it) })
|
val items = (
|
||||||
|
preparations.map { PhotoGridItem.Preparing(it) } +
|
||||||
|
uploads.map { PhotoGridItem.Upload(it) } +
|
||||||
|
photos.map { PhotoGridItem.Server(it) }
|
||||||
|
)
|
||||||
.sortedByDescending { it.sortEpochMillis }
|
.sortedByDescending { it.sortEpochMillis }
|
||||||
val visibleAttachmentCount = visiblePhotoAttachmentCount(photos.size, uploads.size)
|
val visibleAttachmentCount = visiblePhotoAttachmentCount(photos.size, uploads.size + preparations.size)
|
||||||
|
|
||||||
Card(
|
Card(
|
||||||
colors = CardDefaults.cardColors(containerColor = TppTheme.colors.card),
|
colors = CardDefaults.cardColors(containerColor = TppTheme.colors.card),
|
||||||
@@ -6009,6 +6069,10 @@ private fun PhotoGrid(
|
|||||||
readOnly = readOnly,
|
readOnly = readOnly,
|
||||||
modifier = Modifier.weight(1f),
|
modifier = Modifier.weight(1f),
|
||||||
)
|
)
|
||||||
|
is PhotoGridItem.Preparing -> PreparingPhotoTile(
|
||||||
|
preparation = item.preparation,
|
||||||
|
modifier = Modifier.weight(1f),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (rowItems.size == 1) {
|
if (rowItems.size == 1) {
|
||||||
@@ -6055,6 +6119,9 @@ private sealed class PhotoGridItem(open val sortEpochMillis: Long) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
data class Upload(val upload: PhotoUploadEntity) : PhotoGridItem(upload.createdAtEpochMillis)
|
data class Upload(val upload: PhotoUploadEntity) : PhotoGridItem(upload.createdAtEpochMillis)
|
||||||
|
|
||||||
|
data class Preparing(val preparation: PreparingPhotoUpload) :
|
||||||
|
PhotoGridItem(preparation.createdAtEpochMillis)
|
||||||
}
|
}
|
||||||
|
|
||||||
private sealed class PhotoDeleteTarget {
|
private sealed class PhotoDeleteTarget {
|
||||||
@@ -6288,6 +6355,40 @@ private fun PendingPhotoTile(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun PreparingPhotoTile(
|
||||||
|
preparation: PreparingPhotoUpload,
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
|
) {
|
||||||
|
Box(modifier.aspectRatio(1f).background(TppTheme.colors.panel, RoundedCornerShape(4.dp))) {
|
||||||
|
AsyncImage(
|
||||||
|
model = preparation.uri,
|
||||||
|
contentDescription = "Przygotowywane zdjęcie",
|
||||||
|
contentScale = ContentScale.Crop,
|
||||||
|
modifier = Modifier.fillMaxSize(),
|
||||||
|
)
|
||||||
|
Box(Modifier.fillMaxSize().background(Color.Black.copy(alpha = 0.24f)))
|
||||||
|
CircularProgressIndicator(
|
||||||
|
modifier = Modifier.align(Alignment.Center).size(30.dp),
|
||||||
|
color = Color.White,
|
||||||
|
trackColor = Color.White.copy(alpha = 0.3f),
|
||||||
|
strokeWidth = 2.5.dp,
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
"Przygotowuję zdjęcie",
|
||||||
|
color = TppTheme.colors.ink,
|
||||||
|
fontFamily = FontFamily.Monospace,
|
||||||
|
fontWeight = FontWeight.Bold,
|
||||||
|
style = MaterialTheme.typography.labelMedium,
|
||||||
|
modifier = Modifier
|
||||||
|
.align(Alignment.BottomStart)
|
||||||
|
.fillMaxWidth()
|
||||||
|
.background(Color.White.copy(alpha = 0.94f))
|
||||||
|
.padding(10.dp),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun PhotoTileLoadingOverlay() {
|
private fun PhotoTileLoadingOverlay() {
|
||||||
Box(
|
Box(
|
||||||
|
|||||||
@@ -73,6 +73,16 @@ enum class DriverScreen { Initializing, Phone, Otp, Routes, Profile, Diagnostics
|
|||||||
|
|
||||||
enum class ServerConnectionState { Unknown, Reachable, Degraded }
|
enum class ServerConnectionState { Unknown, Reachable, Degraded }
|
||||||
|
|
||||||
|
data class PreparingPhotoUpload(
|
||||||
|
val id: String,
|
||||||
|
val routeId: String,
|
||||||
|
val uri: Uri,
|
||||||
|
val stage: String,
|
||||||
|
val workflowStepId: String?,
|
||||||
|
val workflowDocumentId: String?,
|
||||||
|
val createdAtEpochMillis: Long = System.currentTimeMillis(),
|
||||||
|
)
|
||||||
|
|
||||||
data class DriverUiState(
|
data class DriverUiState(
|
||||||
val screen: DriverScreen = DriverScreen.Initializing,
|
val screen: DriverScreen = DriverScreen.Initializing,
|
||||||
val loading: Boolean = true,
|
val loading: Boolean = true,
|
||||||
@@ -111,6 +121,7 @@ data class DriverUiState(
|
|||||||
val routeActions: List<RouteActionEntity> = emptyList(),
|
val routeActions: List<RouteActionEntity> = emptyList(),
|
||||||
val visibleRouteActions: List<RouteActionEntity> = emptyList(),
|
val visibleRouteActions: List<RouteActionEntity> = emptyList(),
|
||||||
val photoUploads: List<PhotoUploadEntity> = emptyList(),
|
val photoUploads: List<PhotoUploadEntity> = emptyList(),
|
||||||
|
val preparingPhotoUploads: List<PreparingPhotoUpload> = emptyList(),
|
||||||
val queuedPhotoUploads: List<PhotoUploadEntity> = emptyList(),
|
val queuedPhotoUploads: List<PhotoUploadEntity> = emptyList(),
|
||||||
val dispatchSheetReminder: DispatchSheetReminderDto? = null,
|
val dispatchSheetReminder: DispatchSheetReminderDto? = null,
|
||||||
val tachographReminder: TachographReminderDto? = null,
|
val tachographReminder: TachographReminderDto? = null,
|
||||||
@@ -1496,8 +1507,22 @@ class DriverViewModel(application: Application) : AndroidViewModel(application)
|
|||||||
_state.update { it.copy(error = "Zdjęcia możesz dodać tylko w zaplanowanym zakresie kursu.") }
|
_state.update { it.copy(error = "Zdjęcia możesz dodać tylko w zaplanowanym zakresie kursu.") }
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
val preparation = PreparingPhotoUpload(
|
||||||
|
id = UUID.randomUUID().toString(),
|
||||||
|
routeId = route.id,
|
||||||
|
uri = uri,
|
||||||
|
stage = stage,
|
||||||
|
workflowStepId = workflowStepId,
|
||||||
|
workflowDocumentId = workflowDocumentId,
|
||||||
|
)
|
||||||
|
_state.update {
|
||||||
|
it.copy(
|
||||||
|
preparingPhotoUploads = it.preparingPhotoUploads + preparation,
|
||||||
|
error = null,
|
||||||
|
)
|
||||||
|
}
|
||||||
return viewModelScope.launch {
|
return viewModelScope.launch {
|
||||||
_state.update { it.copy(error = null) }
|
try {
|
||||||
runCatching {
|
runCatching {
|
||||||
photoUploadOutbox.enqueue(
|
photoUploadOutbox.enqueue(
|
||||||
routeId = route.id,
|
routeId = route.id,
|
||||||
@@ -1513,6 +1538,15 @@ class DriverViewModel(application: Application) : AndroidViewModel(application)
|
|||||||
.onFailure { throwable ->
|
.onFailure { throwable ->
|
||||||
_state.update { it.withApiError(throwable) }
|
_state.update { it.withApiError(throwable) }
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
_state.update {
|
||||||
|
it.copy(
|
||||||
|
preparingPhotoUploads = it.preparingPhotoUploads.filterNot { item ->
|
||||||
|
item.id == preparation.id
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2017,7 +2051,14 @@ class DriverViewModel(application: Application) : AndroidViewModel(application)
|
|||||||
DriverScreen.Detail -> {
|
DriverScreen.Detail -> {
|
||||||
photoUploadsJob?.cancel()
|
photoUploadsJob?.cancel()
|
||||||
routeActionsJob?.cancel()
|
routeActionsJob?.cancel()
|
||||||
it.copy(screen = DriverScreen.Routes, selectedRoute = null, routeActions = emptyList(), photoUploads = emptyList(), feedback = null)
|
it.copy(
|
||||||
|
screen = DriverScreen.Routes,
|
||||||
|
selectedRoute = null,
|
||||||
|
routeActions = emptyList(),
|
||||||
|
photoUploads = emptyList(),
|
||||||
|
preparingPhotoUploads = emptyList(),
|
||||||
|
feedback = null,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
DriverScreen.Profile -> it.copy(screen = DriverScreen.Routes)
|
DriverScreen.Profile -> it.copy(screen = DriverScreen.Routes)
|
||||||
DriverScreen.Diagnostics -> it.copy(screen = DriverScreen.Profile)
|
DriverScreen.Diagnostics -> it.copy(screen = DriverScreen.Profile)
|
||||||
|
|||||||
Reference in New Issue
Block a user