Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c212a6a488 | ||
|
|
08fcb25a2a | ||
|
|
b8b135ee63 | ||
|
|
6066527dc0 |
@@ -34,8 +34,8 @@ android {
|
|||||||
applicationId = "pl.firmatpp.kierowca"
|
applicationId = "pl.firmatpp.kierowca"
|
||||||
minSdk = 26
|
minSdk = 26
|
||||||
targetSdk = 36
|
targetSdk = 36
|
||||||
versionCode = 131
|
versionCode = 133
|
||||||
versionName = "1.0.78"
|
versionName = "1.0.80"
|
||||||
setProperty("archivesBaseName", "pl.firmatpp.kierowca")
|
setProperty("archivesBaseName", "pl.firmatpp.kierowca")
|
||||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package pl.firmatpp.kierowca.data
|
package pl.firmatpp.kierowca.data
|
||||||
|
|
||||||
|
import java.io.Serializable
|
||||||
import okhttp3.MediaType.Companion.toMediaTypeOrNull
|
import okhttp3.MediaType.Companion.toMediaTypeOrNull
|
||||||
import okhttp3.RequestBody
|
import okhttp3.RequestBody
|
||||||
import okhttp3.RequestBody.Companion.toRequestBody
|
import okhttp3.RequestBody.Companion.toRequestBody
|
||||||
@@ -9,7 +10,7 @@ data class PhotoUploadMetadata(
|
|||||||
val latitude: Double? = null,
|
val latitude: Double? = null,
|
||||||
val longitude: Double? = null,
|
val longitude: Double? = null,
|
||||||
val locationAccuracyMeters: Double? = null,
|
val locationAccuracyMeters: Double? = null,
|
||||||
)
|
) : Serializable
|
||||||
|
|
||||||
fun PhotoUploadMetadata.toMultipartTextParts(): Map<String, RequestBody> = buildMap {
|
fun PhotoUploadMetadata.toMultipartTextParts(): Map<String, RequestBody> = buildMap {
|
||||||
takenAt?.let { put("takenAt", it.toPlainTextBody()) }
|
takenAt?.let { put("takenAt", it.toPlainTextBody()) }
|
||||||
|
|||||||
@@ -115,6 +115,7 @@ import androidx.compose.runtime.getValue
|
|||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.rememberCoroutineScope
|
import androidx.compose.runtime.rememberCoroutineScope
|
||||||
|
import androidx.compose.runtime.saveable.rememberSaveable
|
||||||
import androidx.compose.runtime.snapshotFlow
|
import androidx.compose.runtime.snapshotFlow
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
@@ -1202,9 +1203,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 +1229,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 +1245,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 +1360,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)
|
||||||
@@ -4441,21 +4463,28 @@ private fun RouteStageScreen(
|
|||||||
) {
|
) {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val coroutineScope = rememberCoroutineScope()
|
val coroutineScope = rememberCoroutineScope()
|
||||||
var cameraUri by remember { mutableStateOf<Uri?>(null) }
|
var cameraUri by rememberSaveable(stage) { mutableStateOf<Uri?>(null) }
|
||||||
var pendingCameraMode by remember { mutableStateOf<RouteStageCameraMode?>(null) }
|
var pendingCameraMode by rememberSaveable(stage) { mutableStateOf<RouteStageCameraMode?>(null) }
|
||||||
var showMultiplePhotoCamera by remember(stage) { mutableStateOf(false) }
|
var showMultiplePhotoCamera by rememberSaveable(stage) { mutableStateOf(false) }
|
||||||
var multiplePhotoLocationMetadata by remember(stage) { mutableStateOf(PhotoUploadMetadata()) }
|
var multiplePhotoLocationMetadata by rememberSaveable(stage) { mutableStateOf(PhotoUploadMetadata()) }
|
||||||
var showPreciseLocationPermissionDialog by remember { mutableStateOf(false) }
|
var showPreciseLocationPermissionDialog by rememberSaveable(stage) { mutableStateOf(false) }
|
||||||
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 rememberSaveable(stage) { mutableStateOf<RouteWorkflowAttachmentTarget?>(null) }
|
||||||
var pickerAttachmentTarget by remember(stage) { mutableStateOf<RouteWorkflowAttachmentTarget?>(null) }
|
var pickerAttachmentTarget by rememberSaveable(stage) { mutableStateOf<RouteWorkflowAttachmentTarget?>(null) }
|
||||||
|
var singlePhotoLocationMetadata by rememberSaveable(stage) { mutableStateOf(PhotoUploadMetadata()) }
|
||||||
|
var singlePhotoMetadataGeneration by rememberSaveable(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 +4523,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 +4550,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 +4575,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 +4583,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 +4599,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 +4677,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 +4690,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 +4776,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 +4812,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,
|
||||||
@@ -4807,7 +4859,7 @@ private fun RouteStageScreen(
|
|||||||
private data class RouteWorkflowAttachmentTarget(
|
private data class RouteWorkflowAttachmentTarget(
|
||||||
val stepId: String,
|
val stepId: String,
|
||||||
val documentId: String,
|
val documentId: String,
|
||||||
)
|
) : java.io.Serializable
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun RouteWorkflowStepsCard(
|
private fun RouteWorkflowStepsCard(
|
||||||
@@ -4816,6 +4868,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 +4955,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 +6007,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 +6017,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 +6070,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 +6120,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 +6356,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,23 +1507,46 @@ 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,
|
||||||
uri = uri,
|
uri = uri,
|
||||||
source = source,
|
source = source,
|
||||||
metadata = metadata,
|
metadata = metadata,
|
||||||
stage = stage,
|
stage = stage,
|
||||||
workflowVersion = snapshot.routeWorkflow?.version,
|
workflowVersion = snapshot.routeWorkflow?.version,
|
||||||
workflowStepId = workflowStepId,
|
workflowStepId = workflowStepId,
|
||||||
workflowDocumentId = workflowDocumentId,
|
workflowDocumentId = workflowDocumentId,
|
||||||
)
|
)
|
||||||
}
|
|
||||||
.onFailure { throwable ->
|
|
||||||
_state.update { it.withApiError(throwable) }
|
|
||||||
}
|
}
|
||||||
|
.onFailure { 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)
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ import androidx.compose.runtime.mutableStateOf
|
|||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.rememberCoroutineScope
|
import androidx.compose.runtime.rememberCoroutineScope
|
||||||
import androidx.compose.runtime.rememberUpdatedState
|
import androidx.compose.runtime.rememberUpdatedState
|
||||||
|
import androidx.compose.runtime.saveable.rememberSaveable
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
@@ -74,7 +75,7 @@ internal fun MultiplePhotoCameraScreen(
|
|||||||
imageCaptureMode = ImageCapture.CAPTURE_MODE_MINIMIZE_LATENCY
|
imageCaptureMode = ImageCapture.CAPTURE_MODE_MINIMIZE_LATENCY
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var capturedCount by remember { mutableIntStateOf(0) }
|
var capturedCount by rememberSaveable(stage) { mutableIntStateOf(0) }
|
||||||
var pendingUploads by remember { mutableIntStateOf(0) }
|
var pendingUploads by remember { mutableIntStateOf(0) }
|
||||||
var isCapturing by remember { mutableStateOf(false) }
|
var isCapturing by remember { mutableStateOf(false) }
|
||||||
var cameraUnavailable by remember { mutableStateOf(false) }
|
var cameraUnavailable by remember { mutableStateOf(false) }
|
||||||
|
|||||||
Reference in New Issue
Block a user