Compare commits
11
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e9e8a75bf1 | ||
|
|
c212a6a488 | ||
|
|
08fcb25a2a | ||
|
|
b8b135ee63 | ||
|
|
6066527dc0 | ||
|
|
1f39f27618 | ||
|
|
956be6a6de | ||
|
|
90ca9775ef | ||
|
|
0e33564b95 | ||
|
|
321b260e3d | ||
|
|
be3c885988 |
@@ -34,8 +34,8 @@ android {
|
|||||||
applicationId = "pl.firmatpp.kierowca"
|
applicationId = "pl.firmatpp.kierowca"
|
||||||
minSdk = 26
|
minSdk = 26
|
||||||
targetSdk = 36
|
targetSdk = 36
|
||||||
versionCode = 128
|
versionCode = 133
|
||||||
versionName = "1.0.75"
|
versionName = "1.0.80"
|
||||||
setProperty("archivesBaseName", "pl.firmatpp.kierowca")
|
setProperty("archivesBaseName", "pl.firmatpp.kierowca")
|
||||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||||
|
|
||||||
|
|||||||
@@ -202,6 +202,9 @@ class DriverRepository(
|
|||||||
source: String,
|
source: String,
|
||||||
stage: String = "other",
|
stage: String = "other",
|
||||||
metadata: PhotoUploadMetadata = PhotoUploadMetadata(),
|
metadata: PhotoUploadMetadata = PhotoUploadMetadata(),
|
||||||
|
workflowVersion: String? = null,
|
||||||
|
workflowStepId: String? = null,
|
||||||
|
workflowDocumentId: String? = null,
|
||||||
): PhotoUploadResponse {
|
): PhotoUploadResponse {
|
||||||
val resolver = context.contentResolver
|
val resolver = context.contentResolver
|
||||||
val mimeType = resolver.getType(uri) ?: "image/jpeg"
|
val mimeType = resolver.getType(uri) ?: "image/jpeg"
|
||||||
@@ -222,6 +225,9 @@ class DriverRepository(
|
|||||||
contentSha256.toPlainTextBody(),
|
contentSha256.toPlainTextBody(),
|
||||||
sourceBody,
|
sourceBody,
|
||||||
stage.toPlainTextBody(),
|
stage.toPlainTextBody(),
|
||||||
|
workflowVersion?.toPlainTextBody(),
|
||||||
|
workflowStepId?.toPlainTextBody(),
|
||||||
|
workflowDocumentId?.toPlainTextBody(),
|
||||||
metadataParts["takenAt"],
|
metadataParts["takenAt"],
|
||||||
metadataParts["latitude"],
|
metadataParts["latitude"],
|
||||||
metadataParts["longitude"],
|
metadataParts["longitude"],
|
||||||
@@ -249,6 +255,9 @@ class DriverRepository(
|
|||||||
upload.contentSha256.toPlainTextBody(),
|
upload.contentSha256.toPlainTextBody(),
|
||||||
upload.source.toPlainTextBody(),
|
upload.source.toPlainTextBody(),
|
||||||
upload.stage.toPlainTextBody(),
|
upload.stage.toPlainTextBody(),
|
||||||
|
upload.workflowVersion?.toPlainTextBody(),
|
||||||
|
upload.workflowStepId?.toPlainTextBody(),
|
||||||
|
upload.workflowDocumentId?.toPlainTextBody(),
|
||||||
metadataParts["takenAt"],
|
metadataParts["takenAt"],
|
||||||
metadataParts["latitude"],
|
metadataParts["latitude"],
|
||||||
metadataParts["longitude"],
|
metadataParts["longitude"],
|
||||||
|
|||||||
@@ -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()) }
|
||||||
|
|||||||
@@ -216,6 +216,9 @@ interface MobileDriverApi {
|
|||||||
@Part("contentSha256") contentSha256: RequestBody,
|
@Part("contentSha256") contentSha256: RequestBody,
|
||||||
@Part("source") source: RequestBody,
|
@Part("source") source: RequestBody,
|
||||||
@Part("stage") stage: RequestBody?,
|
@Part("stage") stage: RequestBody?,
|
||||||
|
@Part("workflowVersion") workflowVersion: RequestBody?,
|
||||||
|
@Part("workflowStepId") workflowStepId: RequestBody?,
|
||||||
|
@Part("workflowDocumentId") workflowDocumentId: RequestBody?,
|
||||||
@Part("takenAt") takenAt: RequestBody?,
|
@Part("takenAt") takenAt: RequestBody?,
|
||||||
@Part("latitude") latitude: RequestBody?,
|
@Part("latitude") latitude: RequestBody?,
|
||||||
@Part("longitude") longitude: RequestBody?,
|
@Part("longitude") longitude: RequestBody?,
|
||||||
|
|||||||
@@ -42,7 +42,10 @@ data class DriverDto(
|
|||||||
val anonymousLabel: String?,
|
val anonymousLabel: String?,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
data class DayPublicationDto(val date: String, val isVisible: Boolean, val version: Long)
|
||||||
|
|
||||||
data class BootstrapResponse(
|
data class BootstrapResponse(
|
||||||
|
val dayPublication: DayPublicationDto? = null,
|
||||||
val session: DriverSessionDto,
|
val session: DriverSessionDto,
|
||||||
val routes: RoutesBucketDto,
|
val routes: RoutesBucketDto,
|
||||||
val driverAppSettings: DriverAppSettingsDto?,
|
val driverAppSettings: DriverAppSettingsDto?,
|
||||||
@@ -78,6 +81,7 @@ data class DriverAppSettingsDto(
|
|||||||
val loadingWeightRequirement: String? = null,
|
val loadingWeightRequirement: String? = null,
|
||||||
val unloadingPhotoRequirement: String? = null,
|
val unloadingPhotoRequirement: String? = null,
|
||||||
val unloadingWeightRequirement: String? = null,
|
val unloadingWeightRequirement: String? = null,
|
||||||
|
val routeWorkflow: DriverRouteWorkflowDto? = null,
|
||||||
val dispatchSheetRemindersEnabled: Boolean? = null,
|
val dispatchSheetRemindersEnabled: Boolean? = null,
|
||||||
val dispatchSheetOnFridays: Boolean? = null,
|
val dispatchSheetOnFridays: Boolean? = null,
|
||||||
val dispatchSheetOnLastWorkingDay: Boolean? = null,
|
val dispatchSheetOnLastWorkingDay: Boolean? = null,
|
||||||
@@ -85,6 +89,33 @@ data class DriverAppSettingsDto(
|
|||||||
val leaveRequests: LeaveRequestsConfigDto? = null,
|
val leaveRequests: LeaveRequestsConfigDto? = null,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
data class DriverRouteWorkflowDto(
|
||||||
|
val version: String,
|
||||||
|
val customized: Boolean = false,
|
||||||
|
val loading: DriverRouteStageWorkflowDto,
|
||||||
|
val unloading: DriverRouteStageWorkflowDto,
|
||||||
|
)
|
||||||
|
|
||||||
|
data class DriverRouteStageWorkflowDto(
|
||||||
|
val steps: List<DriverRouteWorkflowStepDto> = emptyList(),
|
||||||
|
)
|
||||||
|
|
||||||
|
data class DriverRouteWorkflowStepDto(
|
||||||
|
val id: String,
|
||||||
|
val type: String,
|
||||||
|
val title: String,
|
||||||
|
val description: String = "",
|
||||||
|
val requirement: String = "required",
|
||||||
|
val documents: List<DriverRouteWorkflowDocumentDto> = emptyList(),
|
||||||
|
)
|
||||||
|
|
||||||
|
data class DriverRouteWorkflowDocumentDto(
|
||||||
|
val id: String,
|
||||||
|
val label: String,
|
||||||
|
val description: String = "",
|
||||||
|
val requirement: String = "required",
|
||||||
|
)
|
||||||
|
|
||||||
data class LeaveRequestsConfigDto(
|
data class LeaveRequestsConfigDto(
|
||||||
val enabled: Boolean = false,
|
val enabled: Boolean = false,
|
||||||
val types: List<String> = listOf("URLOP"),
|
val types: List<String> = listOf("URLOP"),
|
||||||
@@ -522,6 +553,10 @@ data class RoutePhotoDto(
|
|||||||
val contentSha256: String? = null,
|
val contentSha256: String? = null,
|
||||||
val source: String,
|
val source: String,
|
||||||
val stage: String = "other",
|
val stage: String = "other",
|
||||||
|
val workflowVersion: String? = null,
|
||||||
|
val workflowStepId: String? = null,
|
||||||
|
val workflowDocumentId: String? = null,
|
||||||
|
val originalName: String? = null,
|
||||||
val mimeType: String?,
|
val mimeType: String?,
|
||||||
val size: Long,
|
val size: Long,
|
||||||
val url: String,
|
val url: String,
|
||||||
@@ -552,6 +587,8 @@ data class StartRouteBody(
|
|||||||
val occurredAt: String,
|
val occurredAt: String,
|
||||||
val photoClientRequestIds: List<String>,
|
val photoClientRequestIds: List<String>,
|
||||||
val loadingNotes: String? = null,
|
val loadingNotes: String? = null,
|
||||||
|
val workflowVersion: String? = null,
|
||||||
|
val completedStepIds: List<String> = emptyList(),
|
||||||
)
|
)
|
||||||
|
|
||||||
data class FinishRouteBody(
|
data class FinishRouteBody(
|
||||||
@@ -560,6 +597,8 @@ data class FinishRouteBody(
|
|||||||
val occurredAt: String,
|
val occurredAt: String,
|
||||||
val photoClientRequestIds: List<String>,
|
val photoClientRequestIds: List<String>,
|
||||||
val unloadingNotes: String? = null,
|
val unloadingNotes: String? = null,
|
||||||
|
val workflowVersion: String? = null,
|
||||||
|
val completedStepIds: List<String> = emptyList(),
|
||||||
)
|
)
|
||||||
|
|
||||||
data class RouteActionResponse(
|
data class RouteActionResponse(
|
||||||
|
|||||||
@@ -37,6 +37,9 @@ interface DriverCacheDao {
|
|||||||
@Query("DELETE FROM driver_bootstrap_cache")
|
@Query("DELETE FROM driver_bootstrap_cache")
|
||||||
suspend fun clearBootstrap()
|
suspend fun clearBootstrap()
|
||||||
|
|
||||||
|
@Query("DELETE FROM driver_route_cache WHERE routeId = :routeId")
|
||||||
|
suspend fun deleteRoute(routeId: String)
|
||||||
|
|
||||||
@Query("DELETE FROM driver_route_cache")
|
@Query("DELETE FROM driver_route_cache")
|
||||||
suspend fun clearRoutes()
|
suspend fun clearRoutes()
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,13 @@ class DriverSyncRepository(
|
|||||||
val response = repository.bootstrap(date)
|
val response = repository.bootstrap(date)
|
||||||
val selectedDate = response.driverAppSettings?.selectedDate ?: requestedDate
|
val selectedDate = response.driverAppSettings?.selectedDate ?: requestedDate
|
||||||
val routeState = response.syncState?.scopes?.firstOrNull { it.scope == SCOPE_ROUTES }
|
val routeState = response.syncState?.scopes?.firstOrNull { it.scope == SCOPE_ROUTES }
|
||||||
|
if (response.dayPublication?.isVisible == false) {
|
||||||
|
// Previously downloaded details must not survive withdrawing a day.
|
||||||
|
dao.allRouteCaches().forEach { cached ->
|
||||||
|
val route = gson.fromJson(cached.payloadJson, RouteResponse::class.java).route
|
||||||
|
if (selectedDate in routeVisibleDates(route)) dao.deleteRoute(route.id)
|
||||||
|
}
|
||||||
|
}
|
||||||
dao.upsertBootstrap(
|
dao.upsertBootstrap(
|
||||||
DriverBootstrapCacheEntity(
|
DriverBootstrapCacheEntity(
|
||||||
date = selectedDate,
|
date = selectedDate,
|
||||||
@@ -61,6 +68,7 @@ class DriverSyncRepository(
|
|||||||
CachedValue(response, stale = false, syncedAtEpochMillis = System.currentTimeMillis())
|
CachedValue(response, stale = false, syncedAtEpochMillis = System.currentTimeMillis())
|
||||||
}.getOrElse { throwable ->
|
}.getOrElse { throwable ->
|
||||||
throwable.rethrowIfCancellation()
|
throwable.rethrowIfCancellation()
|
||||||
|
if (throwable is HttpException && throwable.code() == 404) dao.deleteRoute(routeId)
|
||||||
cachedRoute(routeId, throwable)
|
cachedRoute(routeId, throwable)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import pl.firmatpp.kierowca.data.sync.DriverSyncStateEntity
|
|||||||
DriverRouteCacheEntity::class,
|
DriverRouteCacheEntity::class,
|
||||||
DriverSyncStateEntity::class,
|
DriverSyncStateEntity::class,
|
||||||
],
|
],
|
||||||
version = 7,
|
version = 8,
|
||||||
exportSchema = false,
|
exportSchema = false,
|
||||||
)
|
)
|
||||||
abstract class DriverDatabase : RoomDatabase() {
|
abstract class DriverDatabase : RoomDatabase() {
|
||||||
@@ -208,6 +208,16 @@ abstract class DriverDatabase : RoomDatabase() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val migration7To8 = object : Migration(7, 8) {
|
||||||
|
override fun migrate(db: SupportSQLiteDatabase) {
|
||||||
|
db.execSQL("ALTER TABLE photo_uploads ADD COLUMN workflowVersion TEXT")
|
||||||
|
db.execSQL("ALTER TABLE photo_uploads ADD COLUMN workflowStepId TEXT")
|
||||||
|
db.execSQL("ALTER TABLE photo_uploads ADD COLUMN workflowDocumentId TEXT")
|
||||||
|
db.execSQL("ALTER TABLE route_actions ADD COLUMN workflowVersion TEXT")
|
||||||
|
db.execSQL("ALTER TABLE route_actions ADD COLUMN completedStepIdsJson TEXT NOT NULL DEFAULT '[]'")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun get(context: Context): DriverDatabase =
|
fun get(context: Context): DriverDatabase =
|
||||||
instance ?: synchronized(this) {
|
instance ?: synchronized(this) {
|
||||||
instance ?: Room.databaseBuilder(
|
instance ?: Room.databaseBuilder(
|
||||||
@@ -221,6 +231,7 @@ abstract class DriverDatabase : RoomDatabase() {
|
|||||||
migration4To5,
|
migration4To5,
|
||||||
migration5To6,
|
migration5To6,
|
||||||
migration6To7,
|
migration6To7,
|
||||||
|
migration7To8,
|
||||||
).build().also { instance = it }
|
).build().also { instance = it }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,9 @@ data class PhotoUploadEntity(
|
|||||||
val localPath: String,
|
val localPath: String,
|
||||||
val source: String,
|
val source: String,
|
||||||
val stage: String = "other",
|
val stage: String = "other",
|
||||||
|
val workflowVersion: String? = null,
|
||||||
|
val workflowStepId: String? = null,
|
||||||
|
val workflowDocumentId: String? = null,
|
||||||
val takenAt: String?,
|
val takenAt: String?,
|
||||||
val latitude: Double?,
|
val latitude: Double?,
|
||||||
val longitude: Double?,
|
val longitude: Double?,
|
||||||
|
|||||||
@@ -13,7 +13,9 @@ import java.io.File
|
|||||||
import java.security.MessageDigest
|
import java.security.MessageDigest
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import pl.firmatpp.kierowca.data.PhotoUploadMetadata
|
import pl.firmatpp.kierowca.data.PhotoUploadMetadata
|
||||||
import pl.firmatpp.kierowca.data.model.DriverRouteDto
|
import pl.firmatpp.kierowca.data.model.DriverRouteDto
|
||||||
import pl.firmatpp.kierowca.data.model.RoutePhotoDto
|
import pl.firmatpp.kierowca.data.model.RoutePhotoDto
|
||||||
@@ -29,12 +31,22 @@ class PhotoUploadOutbox(
|
|||||||
fun observeQueuedUploads(): Flow<List<PhotoUploadEntity>> =
|
fun observeQueuedUploads(): Flow<List<PhotoUploadEntity>> =
|
||||||
dao.observeQueuedUploads()
|
dao.observeQueuedUploads()
|
||||||
|
|
||||||
suspend fun enqueue(routeId: String, uri: Uri, source: String, metadata: PhotoUploadMetadata, stage: String = "other"): PhotoUploadEntity {
|
suspend fun enqueue(
|
||||||
|
routeId: String,
|
||||||
|
uri: Uri,
|
||||||
|
source: String,
|
||||||
|
metadata: PhotoUploadMetadata,
|
||||||
|
stage: String = "other",
|
||||||
|
workflowVersion: String? = null,
|
||||||
|
workflowStepId: String? = null,
|
||||||
|
workflowDocumentId: String? = null,
|
||||||
|
): PhotoUploadEntity = withContext(Dispatchers.IO) {
|
||||||
val clientRequestId = UUID.randomUUID().toString()
|
val clientRequestId = UUID.randomUUID().toString()
|
||||||
val mimeType = context.contentResolver.getType(uri) ?: "image/jpeg"
|
val mimeType = context.contentResolver.getType(uri) ?: "image/jpeg"
|
||||||
val extension = when (mimeType) {
|
val extension = when (mimeType) {
|
||||||
"image/png" -> "png"
|
"image/png" -> "png"
|
||||||
"image/webp" -> "webp"
|
"image/webp" -> "webp"
|
||||||
|
"application/pdf" -> "pdf"
|
||||||
else -> "jpg"
|
else -> "jpg"
|
||||||
}
|
}
|
||||||
val uploadDir = File(context.filesDir, "photo-upload-outbox").apply { mkdirs() }
|
val uploadDir = File(context.filesDir, "photo-upload-outbox").apply { mkdirs() }
|
||||||
@@ -46,6 +58,9 @@ class PhotoUploadOutbox(
|
|||||||
localPath = localFile.absolutePath,
|
localPath = localFile.absolutePath,
|
||||||
source = source,
|
source = source,
|
||||||
stage = stage,
|
stage = stage,
|
||||||
|
workflowVersion = workflowVersion,
|
||||||
|
workflowStepId = workflowStepId,
|
||||||
|
workflowDocumentId = workflowDocumentId,
|
||||||
takenAt = metadata.takenAt,
|
takenAt = metadata.takenAt,
|
||||||
latitude = metadata.latitude,
|
latitude = metadata.latitude,
|
||||||
longitude = metadata.longitude,
|
longitude = metadata.longitude,
|
||||||
@@ -58,7 +73,7 @@ class PhotoUploadOutbox(
|
|||||||
dao.upsert(upload)
|
dao.upsert(upload)
|
||||||
enqueueWorker(clientRequestId)
|
enqueueWorker(clientRequestId)
|
||||||
|
|
||||||
return upload
|
upload
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun retry(clientRequestId: String) {
|
suspend fun retry(clientRequestId: String) {
|
||||||
|
|||||||
@@ -33,6 +33,8 @@ data class RouteActionEntity(
|
|||||||
val weight: Double?,
|
val weight: Double?,
|
||||||
val occurredAt: String,
|
val occurredAt: String,
|
||||||
val photoClientRequestIdsJson: String,
|
val photoClientRequestIdsJson: String,
|
||||||
|
val workflowVersion: String? = null,
|
||||||
|
val completedStepIdsJson: String = "[]",
|
||||||
val status: String = RouteActionStatus.Pending,
|
val status: String = RouteActionStatus.Pending,
|
||||||
val attemptCount: Int = 0,
|
val attemptCount: Int = 0,
|
||||||
val lastError: String? = null,
|
val lastError: String? = null,
|
||||||
|
|||||||
@@ -48,16 +48,20 @@ class RouteActionOutbox(
|
|||||||
loadingWeight: Double?,
|
loadingWeight: Double?,
|
||||||
photoClientRequestIds: List<String>,
|
photoClientRequestIds: List<String>,
|
||||||
notes: String? = null,
|
notes: String? = null,
|
||||||
|
workflowVersion: String? = null,
|
||||||
|
completedStepIds: List<String> = emptyList(),
|
||||||
): RouteActionEntity =
|
): RouteActionEntity =
|
||||||
enqueue(RouteActionType.Start, routeId, loadingWeight, photoClientRequestIds, notes)
|
enqueue(RouteActionType.Start, routeId, loadingWeight, photoClientRequestIds, notes, workflowVersion, completedStepIds)
|
||||||
|
|
||||||
suspend fun enqueueFinish(
|
suspend fun enqueueFinish(
|
||||||
routeId: String,
|
routeId: String,
|
||||||
unloadingWeight: Double?,
|
unloadingWeight: Double?,
|
||||||
photoClientRequestIds: List<String>,
|
photoClientRequestIds: List<String>,
|
||||||
notes: String? = null,
|
notes: String? = null,
|
||||||
|
workflowVersion: String? = null,
|
||||||
|
completedStepIds: List<String> = emptyList(),
|
||||||
): RouteActionEntity =
|
): RouteActionEntity =
|
||||||
enqueue(RouteActionType.Finish, routeId, unloadingWeight, photoClientRequestIds, notes)
|
enqueue(RouteActionType.Finish, routeId, unloadingWeight, photoClientRequestIds, notes, workflowVersion, completedStepIds)
|
||||||
|
|
||||||
private suspend fun enqueue(
|
private suspend fun enqueue(
|
||||||
action: String,
|
action: String,
|
||||||
@@ -65,6 +69,8 @@ class RouteActionOutbox(
|
|||||||
weight: Double?,
|
weight: Double?,
|
||||||
photoClientRequestIds: List<String>,
|
photoClientRequestIds: List<String>,
|
||||||
notes: String?,
|
notes: String?,
|
||||||
|
workflowVersion: String?,
|
||||||
|
completedStepIds: List<String>,
|
||||||
): RouteActionEntity {
|
): RouteActionEntity {
|
||||||
dao.pruneConfirmed(System.currentTimeMillis() - TimeUnit.DAYS.toMillis(7))
|
dao.pruneConfirmed(System.currentTimeMillis() - TimeUnit.DAYS.toMillis(7))
|
||||||
val entity = RouteActionEntity(
|
val entity = RouteActionEntity(
|
||||||
@@ -74,6 +80,8 @@ class RouteActionOutbox(
|
|||||||
weight = weight,
|
weight = weight,
|
||||||
occurredAt = Instant.now().toString(),
|
occurredAt = Instant.now().toString(),
|
||||||
photoClientRequestIdsJson = gson.toJson(photoClientRequestIds.distinct()),
|
photoClientRequestIdsJson = gson.toJson(photoClientRequestIds.distinct()),
|
||||||
|
workflowVersion = workflowVersion,
|
||||||
|
completedStepIdsJson = gson.toJson(completedStepIds.distinct()),
|
||||||
notes = notes?.trim()?.takeIf { it.isNotEmpty() },
|
notes = notes?.trim()?.takeIf { it.isNotEmpty() },
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -181,6 +181,8 @@ class RouteActionWorker(
|
|||||||
occurredAt = action.occurredAt,
|
occurredAt = action.occurredAt,
|
||||||
photoClientRequestIds = photoClientRequestIds,
|
photoClientRequestIds = photoClientRequestIds,
|
||||||
loadingNotes = action.notes,
|
loadingNotes = action.notes,
|
||||||
|
workflowVersion = action.workflowVersion,
|
||||||
|
completedStepIds = completedStepIds(action),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
RouteActionType.Finish -> repository.finishRoute(
|
RouteActionType.Finish -> repository.finishRoute(
|
||||||
@@ -191,6 +193,8 @@ class RouteActionWorker(
|
|||||||
occurredAt = action.occurredAt,
|
occurredAt = action.occurredAt,
|
||||||
photoClientRequestIds = photoClientRequestIds,
|
photoClientRequestIds = photoClientRequestIds,
|
||||||
unloadingNotes = action.notes,
|
unloadingNotes = action.notes,
|
||||||
|
workflowVersion = action.workflowVersion,
|
||||||
|
completedStepIds = completedStepIds(action),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
else -> error("Nieznana akcja kursu: ${action.action}")
|
else -> error("Nieznana akcja kursu: ${action.action}")
|
||||||
@@ -204,6 +208,14 @@ class RouteActionWorker(
|
|||||||
.filter { it.isNotBlank() }
|
.filter { it.isNotBlank() }
|
||||||
.distinct()
|
.distinct()
|
||||||
|
|
||||||
|
private fun completedStepIds(action: RouteActionEntity): List<String> =
|
||||||
|
runCatching {
|
||||||
|
gson.fromJson(action.completedStepIdsJson, Array<String>::class.java)?.toList().orEmpty()
|
||||||
|
}.getOrDefault(emptyList())
|
||||||
|
.map { it.trim() }
|
||||||
|
.filter { it.isNotBlank() }
|
||||||
|
.distinct()
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val KEY_CLIENT_ACTION_ID = "clientActionId"
|
const val KEY_CLIENT_ACTION_ID = "clientActionId"
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,16 @@ class DriverFirebaseMessagingService : FirebaseMessagingService() {
|
|||||||
|
|
||||||
override fun onMessageReceived(message: RemoteMessage) {
|
override fun onMessageReceived(message: RemoteMessage) {
|
||||||
val data = message.data
|
val data = message.data
|
||||||
|
if (data["type"] == "driver_routes_published") {
|
||||||
|
NewRouteNotificationWorker.enqueuePublication(
|
||||||
|
context = applicationContext,
|
||||||
|
date = data["date"],
|
||||||
|
version = data["publicationVersion"]?.toLongOrNull(),
|
||||||
|
driverId = data["driverId"],
|
||||||
|
)
|
||||||
|
DriverSyncWorker.enqueue(applicationContext, data["date"], null)
|
||||||
|
return
|
||||||
|
}
|
||||||
if (data["type"] == "driver_new_route_notification") {
|
if (data["type"] == "driver_new_route_notification") {
|
||||||
NewRouteNotificationWorker.enqueue(
|
NewRouteNotificationWorker.enqueue(
|
||||||
context = applicationContext,
|
context = applicationContext,
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import pl.firmatpp.kierowca.data.ApiErrorKind
|
|||||||
import pl.firmatpp.kierowca.data.ApiErrorMapper
|
import pl.firmatpp.kierowca.data.ApiErrorMapper
|
||||||
import pl.firmatpp.kierowca.data.DriverRepository
|
import pl.firmatpp.kierowca.data.DriverRepository
|
||||||
import pl.firmatpp.kierowca.data.rethrowIfCancellation
|
import pl.firmatpp.kierowca.data.rethrowIfCancellation
|
||||||
|
import pl.firmatpp.kierowca.data.sync.DriverSyncRepository
|
||||||
import pl.firmatpp.kierowca.data.sync.NetworkMonitor
|
import pl.firmatpp.kierowca.data.sync.NetworkMonitor
|
||||||
import pl.firmatpp.kierowca.diagnostics.AppDiagnostics
|
import pl.firmatpp.kierowca.diagnostics.AppDiagnostics
|
||||||
import retrofit2.HttpException
|
import retrofit2.HttpException
|
||||||
@@ -39,25 +40,41 @@ class NewRouteNotificationWorker(
|
|||||||
|
|
||||||
override suspend fun doWork(): Result {
|
override suspend fun doWork(): Result {
|
||||||
if (!NetworkMonitor(applicationContext).isCurrentlyValidated()) return Result.retry()
|
if (!NetworkMonitor(applicationContext).isCurrentlyValidated()) return Result.retry()
|
||||||
val routeId = inputData.getString(KEY_ROUTE_ID)?.takeIf(String::isNotBlank) ?: return Result.success()
|
val routeId = inputData.getString(KEY_ROUTE_ID)?.takeIf(String::isNotBlank)
|
||||||
|
val publicationDate = inputData.getString(KEY_DATE)
|
||||||
|
val publicationVersion = inputData.getLong(KEY_PUBLICATION_VERSION, -1L)
|
||||||
|
val isPublication = publicationVersion >= 0L
|
||||||
|
if (!isPublication && routeId == null) return Result.success()
|
||||||
|
|
||||||
return runCatching {
|
return runCatching {
|
||||||
val route = repository.route(routeId).route
|
val route = if (isPublication) {
|
||||||
|
if (publicationDate.isNullOrBlank()) return@runCatching Result.success()
|
||||||
|
val bootstrap = DriverSyncRepository(applicationContext).bootstrap(publicationDate)
|
||||||
|
if (bootstrap.stale) return@runCatching Result.retry()
|
||||||
|
val publication = bootstrap.value.dayPublication
|
||||||
|
if (publication?.isVisible != true || publication.version != publicationVersion ||
|
||||||
|
bootstrap.value.notificationPreferences?.notifyNewRoutes != true ||
|
||||||
|
bootstrap.value.session.driver.id != inputData.getString(KEY_DRIVER_ID)) {
|
||||||
|
return@runCatching Result.success()
|
||||||
|
}
|
||||||
|
bootstrap.value.routes.today.firstOrNull() ?: return@runCatching Result.success()
|
||||||
|
} else repository.route(requireNotNull(routeId)).route
|
||||||
if (!canShowNotifications(applicationContext)) {
|
if (!canShowNotifications(applicationContext)) {
|
||||||
return@runCatching Result.success()
|
return@runCatching Result.success()
|
||||||
}
|
}
|
||||||
|
|
||||||
createChannel(applicationContext)
|
createChannel(applicationContext)
|
||||||
val contentTitle = NewRouteNotificationFormatter.title(route.routeDate ?: inputData.getString(KEY_DATE))
|
val contentTitle = if (isPublication) "Opublikowano kursy" else NewRouteNotificationFormatter.title(route.routeDate ?: publicationDate)
|
||||||
val contentText = NewRouteNotificationFormatter.collapsedText(route)
|
val contentText = if (isPublication) PublishedRoutesNotificationFormatter.text(publicationDate) else NewRouteNotificationFormatter.collapsedText(route)
|
||||||
val expandedText = NewRouteNotificationFormatter.expandedText(route)
|
val expandedText = if (isPublication) contentText else NewRouteNotificationFormatter.expandedText(route)
|
||||||
|
val notificationId = if (isPublication) "published-$publicationDate".hashCode() else route.id.hashCode()
|
||||||
val intent = Intent(applicationContext, MainActivity::class.java).apply {
|
val intent = Intent(applicationContext, MainActivity::class.java).apply {
|
||||||
flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP
|
flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP
|
||||||
putExtra(MainActivity.EXTRA_ROUTE_ID, route.id)
|
putExtra(MainActivity.EXTRA_ROUTE_ID, route.id)
|
||||||
}
|
}
|
||||||
val pendingIntent = PendingIntent.getActivity(
|
val pendingIntent = PendingIntent.getActivity(
|
||||||
applicationContext,
|
applicationContext,
|
||||||
route.id.hashCode(),
|
notificationId,
|
||||||
intent,
|
intent,
|
||||||
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE,
|
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE,
|
||||||
)
|
)
|
||||||
@@ -69,12 +86,13 @@ class NewRouteNotificationWorker(
|
|||||||
.setStyle(NotificationCompat.BigTextStyle().bigText(expandedText))
|
.setStyle(NotificationCompat.BigTextStyle().bigText(expandedText))
|
||||||
.setContentIntent(pendingIntent)
|
.setContentIntent(pendingIntent)
|
||||||
.setAutoCancel(true)
|
.setAutoCancel(true)
|
||||||
|
.setOnlyAlertOnce(true)
|
||||||
.setCategory(NotificationCompat.CATEGORY_REMINDER)
|
.setCategory(NotificationCompat.CATEGORY_REMINDER)
|
||||||
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
|
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
NotificationManagerCompat.from(applicationContext).notify(route.id.hashCode(), notification)
|
NotificationManagerCompat.from(applicationContext).notify(notificationId, notification)
|
||||||
} catch (_: SecurityException) {
|
} catch (_: SecurityException) {
|
||||||
return@runCatching Result.success()
|
return@runCatching Result.success()
|
||||||
}
|
}
|
||||||
@@ -125,6 +143,22 @@ class NewRouteNotificationWorker(
|
|||||||
private const val CHANNEL_ID = "new_routes"
|
private const val CHANNEL_ID = "new_routes"
|
||||||
private const val KEY_ROUTE_ID = "routeId"
|
private const val KEY_ROUTE_ID = "routeId"
|
||||||
private const val KEY_DATE = "date"
|
private const val KEY_DATE = "date"
|
||||||
|
private const val KEY_PUBLICATION_VERSION = "publicationVersion"
|
||||||
|
private const val KEY_DRIVER_ID = "driverId"
|
||||||
|
|
||||||
|
fun enqueuePublication(context: Context, date: String?, version: Long?, driverId: String?) {
|
||||||
|
if (date.isNullOrBlank() || version == null || version < 1L || driverId.isNullOrBlank()) return
|
||||||
|
val request = OneTimeWorkRequestBuilder<NewRouteNotificationWorker>()
|
||||||
|
.setInputData(workDataOf(KEY_DATE to date, KEY_PUBLICATION_VERSION to version, KEY_DRIVER_ID to driverId))
|
||||||
|
.setConstraints(Constraints.Builder().setRequiredNetworkType(NetworkType.CONNECTED).build())
|
||||||
|
.setBackoffCriteria(BackoffPolicy.EXPONENTIAL, 30, TimeUnit.SECONDS)
|
||||||
|
.build()
|
||||||
|
WorkManager.getInstance(context).enqueueUniqueWork(
|
||||||
|
"driver-day-publication-$date",
|
||||||
|
ExistingWorkPolicy.REPLACE,
|
||||||
|
request,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
fun enqueue(context: Context, routeId: String?, date: String?) {
|
fun enqueue(context: Context, routeId: String?, date: String?) {
|
||||||
if (routeId.isNullOrBlank()) return
|
if (routeId.isNullOrBlank()) return
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package pl.firmatpp.kierowca.sync
|
||||||
|
|
||||||
|
import java.time.DayOfWeek
|
||||||
|
import java.time.LocalDate
|
||||||
|
import java.time.format.DateTimeFormatter
|
||||||
|
|
||||||
|
object PublishedRoutesNotificationFormatter {
|
||||||
|
fun text(value: String?): String {
|
||||||
|
val date = runCatching { LocalDate.parse(value) }.getOrNull()
|
||||||
|
?: return "Opublikowano twoje kursy. Otwórz aplikację, aby je zobaczyć."
|
||||||
|
val weekday = when (date.dayOfWeek) {
|
||||||
|
DayOfWeek.MONDAY -> "poniedziałek"
|
||||||
|
DayOfWeek.TUESDAY -> "wtorek"
|
||||||
|
DayOfWeek.WEDNESDAY -> "środę"
|
||||||
|
DayOfWeek.THURSDAY -> "czwartek"
|
||||||
|
DayOfWeek.FRIDAY -> "piątek"
|
||||||
|
DayOfWeek.SATURDAY -> "sobotę"
|
||||||
|
DayOfWeek.SUNDAY -> "niedzielę"
|
||||||
|
}
|
||||||
|
return "Opublikowano twoje kursy na $weekday (${date.format(DateTimeFormatter.ofPattern("dd.MM.yyyy"))})."
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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
|
||||||
@@ -166,6 +167,7 @@ import pl.firmatpp.kierowca.data.model.DispatchSheetReminderDto
|
|||||||
import pl.firmatpp.kierowca.data.model.DriverLeaveCalendarEntryDto
|
import pl.firmatpp.kierowca.data.model.DriverLeaveCalendarEntryDto
|
||||||
import pl.firmatpp.kierowca.data.model.DriverLeaveRequestDto
|
import pl.firmatpp.kierowca.data.model.DriverLeaveRequestDto
|
||||||
import pl.firmatpp.kierowca.data.model.DriverRouteDto
|
import pl.firmatpp.kierowca.data.model.DriverRouteDto
|
||||||
|
import pl.firmatpp.kierowca.data.model.DriverRouteWorkflowStepDto
|
||||||
import pl.firmatpp.kierowca.data.model.NavigationPointDto
|
import pl.firmatpp.kierowca.data.model.NavigationPointDto
|
||||||
import pl.firmatpp.kierowca.data.model.RoutePhotoDto
|
import pl.firmatpp.kierowca.data.model.RoutePhotoDto
|
||||||
import pl.firmatpp.kierowca.data.model.TachographReminderDto
|
import pl.firmatpp.kierowca.data.model.TachographReminderDto
|
||||||
@@ -190,6 +192,11 @@ private enum class RouteLocationPermissionPurpose {
|
|||||||
RestoreRequiredTracking,
|
RestoreRequiredTracking,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private enum class RouteStageCameraMode {
|
||||||
|
Single,
|
||||||
|
Multiple,
|
||||||
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun DriverApp(
|
fun DriverApp(
|
||||||
viewModel: DriverViewModel,
|
viewModel: DriverViewModel,
|
||||||
@@ -464,6 +471,9 @@ fun DriverApp(
|
|||||||
locationPermissionGranted = locationPermissionGranted,
|
locationPermissionGranted = locationPermissionGranted,
|
||||||
onBack = viewModel::back,
|
onBack = viewModel::back,
|
||||||
onPhoto = viewModel::openPhoto,
|
onPhoto = viewModel::openPhoto,
|
||||||
|
onDeletePhoto = viewModel::deletePhoto,
|
||||||
|
onDeleteUpload = viewModel::deletePhotoUpload,
|
||||||
|
onRetryUpload = viewModel::retryPhotoUpload,
|
||||||
onRefresh = viewModel::refreshSelectedRoute,
|
onRefresh = viewModel::refreshSelectedRoute,
|
||||||
onStartRoute = openStartRoute,
|
onStartRoute = openStartRoute,
|
||||||
onFinishRoute = viewModel::openFinishRoute,
|
onFinishRoute = viewModel::openFinishRoute,
|
||||||
@@ -472,22 +482,24 @@ fun DriverApp(
|
|||||||
)
|
)
|
||||||
DriverScreen.StartRoute -> RouteStageScreen(
|
DriverScreen.StartRoute -> RouteStageScreen(
|
||||||
state = state,
|
state = state,
|
||||||
title = if (routeStageRequirementIsVisible(state.loadingPhotoRequirement)) "Zdjęcia załadunku" else "Potwierdź załadunek",
|
title = if (state.routeWorkflow != null) "Załadunek" else if (routeStageRequirementIsVisible(state.loadingPhotoRequirement)) "Zdjęcia załadunku" else "Potwierdź załadunek",
|
||||||
stage = "loading",
|
stage = "loading",
|
||||||
weightLabel = "Tonaż załadunku",
|
weightLabel = "Tonaż załadunku",
|
||||||
submitLabel = if (routeStageRequirementIsVisible(state.loadingWeightRequirement)) "Dalej: tonaż" else "Potwierdź załadunek",
|
submitLabel = if (state.routeWorkflow != null) "Potwierdź załadunek" else if (routeStageRequirementIsVisible(state.loadingWeightRequirement)) "Dalej: tonaż" else "Potwierdź załadunek",
|
||||||
showWeightInput = false,
|
showWeightInput = state.routeWorkflow?.let { routeWorkflowSteps(it, "loading").any { step -> step.type == RouteWorkflowStepType.Weight } } ?: false,
|
||||||
showNotesInput = !routeStageRequirementIsVisible(state.loadingWeightRequirement),
|
showNotesInput = state.routeWorkflow != null || !routeStageRequirementIsVisible(state.loadingWeightRequirement),
|
||||||
showPhotoActions = routeStageRequirementIsVisible(state.loadingPhotoRequirement),
|
showPhotoActions = routeStageRequirementIsVisible(state.loadingPhotoRequirement),
|
||||||
showPhotoGrid = routeStageRequirementIsVisible(state.loadingPhotoRequirement),
|
showPhotoGrid = routeStageRequirementIsVisible(state.loadingPhotoRequirement),
|
||||||
onBack = viewModel::back,
|
onBack = viewModel::back,
|
||||||
onWeightChange = viewModel::updateRouteStageWeight,
|
onWeightChange = viewModel::updateRouteStageWeight,
|
||||||
onNotesChange = viewModel::updateRouteStageNotes,
|
onNotesChange = viewModel::updateRouteStageNotes,
|
||||||
onUpload = { uri, source, metadata -> viewModel.uploadPhoto(uri, source, metadata, "loading") },
|
onUpload = { uri, source, metadata, stepId, documentId -> viewModel.uploadPhoto(uri, source, metadata, "loading", stepId, documentId)?.join() },
|
||||||
|
onStepToggle = viewModel::toggleRouteStageStep,
|
||||||
onPhoto = viewModel::openPhoto,
|
onPhoto = viewModel::openPhoto,
|
||||||
|
onDeletePhoto = viewModel::deletePhoto,
|
||||||
onDeleteUpload = viewModel::deletePhotoUpload,
|
onDeleteUpload = viewModel::deletePhotoUpload,
|
||||||
onRetryUpload = viewModel::retryPhotoUpload,
|
onRetryUpload = viewModel::retryPhotoUpload,
|
||||||
onSubmit = if (routeStageRequirementIsVisible(state.loadingWeightRequirement)) viewModel::openLoadingWeight else viewModel::submitStartRoute,
|
onSubmit = if (state.routeWorkflow == null && routeStageRequirementIsVisible(state.loadingWeightRequirement)) viewModel::openLoadingWeight else viewModel::submitStartRoute,
|
||||||
)
|
)
|
||||||
DriverScreen.LoadingWeight -> RouteStageScreen(
|
DriverScreen.LoadingWeight -> RouteStageScreen(
|
||||||
state = state,
|
state = state,
|
||||||
@@ -502,8 +514,10 @@ fun DriverApp(
|
|||||||
onBack = viewModel::back,
|
onBack = viewModel::back,
|
||||||
onWeightChange = viewModel::updateRouteStageWeight,
|
onWeightChange = viewModel::updateRouteStageWeight,
|
||||||
onNotesChange = viewModel::updateRouteStageNotes,
|
onNotesChange = viewModel::updateRouteStageNotes,
|
||||||
onUpload = { _, _, _ -> },
|
onUpload = { _, _, _, _, _ -> },
|
||||||
|
onStepToggle = viewModel::toggleRouteStageStep,
|
||||||
onPhoto = viewModel::openPhoto,
|
onPhoto = viewModel::openPhoto,
|
||||||
|
onDeletePhoto = viewModel::deletePhoto,
|
||||||
onDeleteUpload = viewModel::deletePhotoUpload,
|
onDeleteUpload = viewModel::deletePhotoUpload,
|
||||||
onRetryUpload = viewModel::retryPhotoUpload,
|
onRetryUpload = viewModel::retryPhotoUpload,
|
||||||
onSubmit = viewModel::submitStartRoute,
|
onSubmit = viewModel::submitStartRoute,
|
||||||
@@ -521,8 +535,10 @@ fun DriverApp(
|
|||||||
onBack = viewModel::back,
|
onBack = viewModel::back,
|
||||||
onWeightChange = viewModel::updateRouteStageWeight,
|
onWeightChange = viewModel::updateRouteStageWeight,
|
||||||
onNotesChange = viewModel::updateRouteStageNotes,
|
onNotesChange = viewModel::updateRouteStageNotes,
|
||||||
onUpload = { uri, source, metadata -> viewModel.uploadPhoto(uri, source, metadata, "unloading") },
|
onUpload = { uri, source, metadata, stepId, documentId -> viewModel.uploadPhoto(uri, source, metadata, "unloading", stepId, documentId)?.join() },
|
||||||
|
onStepToggle = viewModel::toggleRouteStageStep,
|
||||||
onPhoto = viewModel::openPhoto,
|
onPhoto = viewModel::openPhoto,
|
||||||
|
onDeletePhoto = viewModel::deletePhoto,
|
||||||
onDeleteUpload = viewModel::deletePhotoUpload,
|
onDeleteUpload = viewModel::deletePhotoUpload,
|
||||||
onRetryUpload = viewModel::retryPhotoUpload,
|
onRetryUpload = viewModel::retryPhotoUpload,
|
||||||
onSubmit = viewModel::submitFinishRoute,
|
onSubmit = viewModel::submitFinishRoute,
|
||||||
@@ -1187,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 (
|
||||||
@@ -1200,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 ->
|
||||||
@@ -1213,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) {
|
||||||
@@ -1324,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)
|
||||||
@@ -4416,25 +4453,50 @@ private fun RouteStageScreen(
|
|||||||
onBack: () -> Unit,
|
onBack: () -> Unit,
|
||||||
onWeightChange: (String) -> Unit,
|
onWeightChange: (String) -> Unit,
|
||||||
onNotesChange: (String) -> Unit,
|
onNotesChange: (String) -> Unit,
|
||||||
onUpload: (Uri, String, PhotoUploadMetadata) -> Unit,
|
onUpload: suspend (Uri, String, PhotoUploadMetadata, String?, String?) -> Unit,
|
||||||
|
onStepToggle: (String, Boolean) -> Unit,
|
||||||
onPhoto: (RoutePhotoDto) -> Unit,
|
onPhoto: (RoutePhotoDto) -> Unit,
|
||||||
|
onDeletePhoto: (RoutePhotoDto) -> Unit,
|
||||||
onDeleteUpload: (PhotoUploadEntity) -> Unit,
|
onDeleteUpload: (PhotoUploadEntity) -> Unit,
|
||||||
onRetryUpload: (PhotoUploadEntity) -> Unit,
|
onRetryUpload: (PhotoUploadEntity) -> Unit,
|
||||||
onSubmit: () -> Unit,
|
onSubmit: () -> Unit,
|
||||||
) {
|
) {
|
||||||
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 showPreciseLocationPermissionDialog by remember { mutableStateOf(false) }
|
var pendingCameraMode by rememberSaveable(stage) { mutableStateOf<RouteStageCameraMode?>(null) }
|
||||||
|
var showMultiplePhotoCamera by rememberSaveable(stage) { mutableStateOf(false) }
|
||||||
|
var multiplePhotoLocationMetadata by rememberSaveable(stage) { mutableStateOf(PhotoUploadMetadata()) }
|
||||||
|
var showPreciseLocationPermissionDialog by rememberSaveable(stage) { mutableStateOf(false) }
|
||||||
var voiceDictationActive by remember(stage) { mutableStateOf(false) }
|
var voiceDictationActive by remember(stage) { mutableStateOf(false) }
|
||||||
|
var cameraAttachmentTarget by rememberSaveable(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 attachmentCount = visiblePhotoAttachmentCount(stagePhotos.size, usableStageUploads.size)
|
val cargoStagePhotos = stagePhotos.filter { it.workflowDocumentId.isNullOrBlank() }
|
||||||
|
val cargoStageUploads = usableStageUploads.filter { it.workflowDocumentId.isNullOrBlank() }
|
||||||
|
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 = when {
|
val submitBlocker = if (state.routeWorkflow != null) {
|
||||||
|
routeWorkflowSubmitBlocker(
|
||||||
|
workflow = state.routeWorkflow,
|
||||||
|
stage = stage,
|
||||||
|
completedStepIds = state.routeStageCompletedStepIds,
|
||||||
|
weightText = state.routeStageWeightText,
|
||||||
|
serverPhotos = stagePhotos,
|
||||||
|
localUploads = usableStageUploads,
|
||||||
|
)
|
||||||
|
} else when {
|
||||||
!showWeightInput -> loadingPhotosSubmitBlocker(
|
!showWeightInput -> loadingPhotosSubmitBlocker(
|
||||||
serverPhotoCount = stagePhotos.size,
|
serverPhotoCount = stagePhotos.size,
|
||||||
localUploadCount = usableStageUploads.size,
|
localUploadCount = usableStageUploads.size,
|
||||||
@@ -4461,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 &&
|
||||||
@@ -4473,25 +4547,105 @@ private fun RouteStageScreen(
|
|||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
coroutineScope.launch {
|
coroutineScope.launch {
|
||||||
onUpload(capturedUri, "camera", cameraPhotoMetadata(context))
|
onUpload(
|
||||||
|
capturedUri,
|
||||||
|
"camera",
|
||||||
|
singlePhotoLocationMetadata.copy(takenAt = Instant.now().toString()),
|
||||||
|
attachmentTarget?.stepId,
|
||||||
|
attachmentTarget?.documentId,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
singlePhotoMetadataGeneration += 1
|
||||||
cameraUri = null
|
cameraUri = null
|
||||||
|
cameraAttachmentTarget = null
|
||||||
|
}
|
||||||
|
val openMultiplePhotoCamera = {
|
||||||
|
multiplePhotoLocationMetadata = PhotoUploadMetadata()
|
||||||
|
showMultiplePhotoCamera = true
|
||||||
|
coroutineScope.launch {
|
||||||
|
multiplePhotoLocationMetadata = cameraPhotoMetadata(context).copy(takenAt = null)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
val cameraPermissionLauncher = rememberLauncherForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) { grants ->
|
val cameraPermissionLauncher = rememberLauncherForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) { grants ->
|
||||||
|
val requestedMode = pendingCameraMode
|
||||||
val pendingUri = cameraUri
|
val pendingUri = cameraUri
|
||||||
val cameraGranted = grants[Manifest.permission.CAMERA] == true || hasPermission(context, Manifest.permission.CAMERA)
|
val cameraGranted = grants[Manifest.permission.CAMERA] == true || hasPermission(context, Manifest.permission.CAMERA)
|
||||||
val fineLocationGranted = grants[Manifest.permission.ACCESS_FINE_LOCATION] == true ||
|
val fineLocationGranted = grants[Manifest.permission.ACCESS_FINE_LOCATION] == true ||
|
||||||
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
|
||||||
return@rememberLauncherForActivityResult
|
return@rememberLauncherForActivityResult
|
||||||
}
|
}
|
||||||
if (cameraGranted && pendingUri != null) cameraLauncher.launch(pendingUri)
|
if (cameraGranted) {
|
||||||
|
when (requestedMode) {
|
||||||
|
RouteStageCameraMode.Single -> {
|
||||||
|
if (pendingUri != null) {
|
||||||
|
prepareSinglePhotoMetadata()
|
||||||
|
cameraLauncher.launch(pendingUri)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
RouteStageCameraMode.Multiple -> {
|
||||||
|
openMultiplePhotoCamera()
|
||||||
|
}
|
||||||
|
null -> Unit
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
cameraUri = null
|
||||||
|
}
|
||||||
|
pendingCameraMode = null
|
||||||
}
|
}
|
||||||
val pickerLauncher = rememberLauncherForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri ->
|
val pickerLauncher = rememberLauncherForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri ->
|
||||||
if (uri != null) onUpload(uri, "gallery", PhotoUploadMetadata())
|
val attachmentTarget = pickerAttachmentTarget
|
||||||
|
if (uri != null) {
|
||||||
|
coroutineScope.launch {
|
||||||
|
onUpload(
|
||||||
|
uri,
|
||||||
|
"gallery",
|
||||||
|
PhotoUploadMetadata(),
|
||||||
|
attachmentTarget?.stepId,
|
||||||
|
attachmentTarget?.documentId,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pickerAttachmentTarget = null
|
||||||
|
}
|
||||||
|
val filePickerLauncher = rememberLauncherForActivityResult(ActivityResultContracts.OpenDocument()) { uri ->
|
||||||
|
val attachmentTarget = pickerAttachmentTarget
|
||||||
|
if (uri != null) {
|
||||||
|
coroutineScope.launch {
|
||||||
|
onUpload(
|
||||||
|
uri,
|
||||||
|
"file",
|
||||||
|
PhotoUploadMetadata(),
|
||||||
|
attachmentTarget?.stepId,
|
||||||
|
attachmentTarget?.documentId,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pickerAttachmentTarget = null
|
||||||
|
}
|
||||||
|
|
||||||
|
if (showMultiplePhotoCamera) {
|
||||||
|
MultiplePhotoCameraScreen(
|
||||||
|
stage = stage,
|
||||||
|
onPhotoCaptured = { uri ->
|
||||||
|
onUpload(
|
||||||
|
uri,
|
||||||
|
"camera",
|
||||||
|
multiplePhotoLocationMetadata.copy(takenAt = Instant.now().toString()),
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
onClose = {
|
||||||
|
showMultiplePhotoCamera = false
|
||||||
|
},
|
||||||
|
)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
BoxWithConstraints(Modifier.fillMaxSize()) {
|
BoxWithConstraints(Modifier.fillMaxSize()) {
|
||||||
@@ -4515,7 +4669,44 @@ private fun RouteStageScreen(
|
|||||||
if (route != null) {
|
if (route != null) {
|
||||||
item { RouteStageSummaryCard(route) }
|
item { RouteStageSummaryCard(route) }
|
||||||
}
|
}
|
||||||
|
if (state.routeWorkflow != null) {
|
||||||
item {
|
item {
|
||||||
|
RouteWorkflowStepsCard(
|
||||||
|
steps = routeWorkflowSteps(state.routeWorkflow, stage),
|
||||||
|
completedStepIds = state.routeStageCompletedStepIds,
|
||||||
|
weightText = state.routeStageWeightText,
|
||||||
|
serverPhotos = stagePhotos,
|
||||||
|
localUploads = usableStageUploads,
|
||||||
|
preparingUploads = stagePreparations,
|
||||||
|
onStepToggle = onStepToggle,
|
||||||
|
onTakeDocumentPhoto = { stepId, documentId ->
|
||||||
|
cameraAttachmentTarget = RouteWorkflowAttachmentTarget(stepId, documentId)
|
||||||
|
val newUri = createCameraUri(context)
|
||||||
|
cameraUri = newUri
|
||||||
|
pendingCameraMode = RouteStageCameraMode.Single
|
||||||
|
val missingPermissions = cameraCapturePermissions(
|
||||||
|
context = context,
|
||||||
|
requirePreciseLocation = state.requirePreciseLocationForPhotos,
|
||||||
|
)
|
||||||
|
if (missingPermissions.isEmpty()) {
|
||||||
|
pendingCameraMode = null
|
||||||
|
prepareSinglePhotoMetadata()
|
||||||
|
cameraLauncher.launch(newUri)
|
||||||
|
} else {
|
||||||
|
cameraPermissionLauncher.launch(missingPermissions)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onPickDocumentPhoto = { stepId, documentId ->
|
||||||
|
pickerAttachmentTarget = RouteWorkflowAttachmentTarget(stepId, documentId)
|
||||||
|
pickerLauncher.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly))
|
||||||
|
},
|
||||||
|
onPickDocumentFile = { stepId, documentId ->
|
||||||
|
pickerAttachmentTarget = RouteWorkflowAttachmentTarget(stepId, documentId)
|
||||||
|
filePickerLauncher.launch(arrayOf("application/pdf", "image/jpeg", "image/png"))
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else item {
|
||||||
RouteStageChecklist(
|
RouteStageChecklist(
|
||||||
hasValidWeight = if (showWeightInput) {
|
hasValidWeight = if (showWeightInput) {
|
||||||
state.routeStageWeightText.trim().isNotBlank() && routeStageSubmitBlocker(
|
state.routeStageWeightText.trim().isNotBlank() && routeStageSubmitBlocker(
|
||||||
@@ -4573,21 +4764,43 @@ private fun RouteStageScreen(
|
|||||||
if (showPhotoActions) {
|
if (showPhotoActions) {
|
||||||
item {
|
item {
|
||||||
Column(verticalArrangement = Arrangement.spacedBy(12.dp)) {
|
Column(verticalArrangement = Arrangement.spacedBy(12.dp)) {
|
||||||
CargoActionButton("Zrób nowe zdjęcie", Icons.Outlined.CameraAlt, TppTheme.colors.forest) {
|
RouteStageCameraActions(
|
||||||
|
onSinglePhoto = {
|
||||||
|
cameraAttachmentTarget = null
|
||||||
val newUri = createCameraUri(context)
|
val newUri = createCameraUri(context)
|
||||||
cameraUri = newUri
|
cameraUri = newUri
|
||||||
|
pendingCameraMode = RouteStageCameraMode.Single
|
||||||
val missingPermissions = cameraCapturePermissions(
|
val missingPermissions = cameraCapturePermissions(
|
||||||
context = context,
|
context = context,
|
||||||
requirePreciseLocation = state.requirePreciseLocationForPhotos,
|
requirePreciseLocation = state.requirePreciseLocationForPhotos,
|
||||||
)
|
)
|
||||||
if (missingPermissions.isEmpty()) {
|
if (missingPermissions.isEmpty()) {
|
||||||
|
pendingCameraMode = null
|
||||||
|
prepareSinglePhotoMetadata()
|
||||||
cameraLauncher.launch(newUri)
|
cameraLauncher.launch(newUri)
|
||||||
} else {
|
} else {
|
||||||
cameraPermissionLauncher.launch(missingPermissions)
|
cameraPermissionLauncher.launch(missingPermissions)
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
onMultiplePhotos = {
|
||||||
|
cameraAttachmentTarget = null
|
||||||
|
cameraUri = null
|
||||||
|
pendingCameraMode = RouteStageCameraMode.Multiple
|
||||||
|
val missingPermissions = cameraCapturePermissions(
|
||||||
|
context = context,
|
||||||
|
requirePreciseLocation = state.requirePreciseLocationForPhotos,
|
||||||
|
)
|
||||||
|
if (missingPermissions.isEmpty()) {
|
||||||
|
pendingCameraMode = null
|
||||||
|
openMultiplePhotoCamera()
|
||||||
|
} else {
|
||||||
|
cameraPermissionLauncher.launch(missingPermissions)
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
if (state.allowGalleryUploads) {
|
if (state.allowGalleryUploads) {
|
||||||
CargoActionButton("Dodaj zdjęcie z galerii", Icons.Outlined.AddPhotoAlternate, TppTheme.colors.containerGreen) {
|
CargoActionButton("Dodaj zdjęcie z galerii", Icons.Outlined.AddPhotoAlternate, TppTheme.colors.containerGreen) {
|
||||||
|
pickerAttachmentTarget = null
|
||||||
pickerLauncher.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly))
|
pickerLauncher.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4597,12 +4810,13 @@ private fun RouteStageScreen(
|
|||||||
if (showPhotoGrid) {
|
if (showPhotoGrid) {
|
||||||
item {
|
item {
|
||||||
PhotoGrid(
|
PhotoGrid(
|
||||||
photos = stagePhotos,
|
photos = cargoStagePhotos,
|
||||||
uploads = stageUploads,
|
uploads = stageUploads.filter { it.workflowDocumentId.isNullOrBlank() },
|
||||||
|
preparations = cargoStagePreparations,
|
||||||
deletingPhotoIds = state.deletingPhotoIds,
|
deletingPhotoIds = state.deletingPhotoIds,
|
||||||
imageAuthHeader = state.imageAuthHeader,
|
imageAuthHeader = state.imageAuthHeader,
|
||||||
onPhoto = onPhoto,
|
onPhoto = onPhoto,
|
||||||
onDeletePhoto = {},
|
onDeletePhoto = onDeletePhoto,
|
||||||
onDeleteUpload = onDeleteUpload,
|
onDeleteUpload = onDeleteUpload,
|
||||||
onRetryUpload = onRetryUpload,
|
onRetryUpload = onRetryUpload,
|
||||||
)
|
)
|
||||||
@@ -4642,6 +4856,168 @@ private fun RouteStageScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private data class RouteWorkflowAttachmentTarget(
|
||||||
|
val stepId: String,
|
||||||
|
val documentId: String,
|
||||||
|
) : java.io.Serializable
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun RouteWorkflowStepsCard(
|
||||||
|
steps: List<DriverRouteWorkflowStepDto>,
|
||||||
|
completedStepIds: Set<String>,
|
||||||
|
weightText: String,
|
||||||
|
serverPhotos: List<RoutePhotoDto>,
|
||||||
|
localUploads: List<PhotoUploadEntity>,
|
||||||
|
preparingUploads: List<PreparingPhotoUpload>,
|
||||||
|
onStepToggle: (String, Boolean) -> Unit,
|
||||||
|
onTakeDocumentPhoto: (String, String) -> Unit,
|
||||||
|
onPickDocumentPhoto: (String, String) -> Unit,
|
||||||
|
onPickDocumentFile: (String, String) -> Unit,
|
||||||
|
) {
|
||||||
|
Card(
|
||||||
|
colors = CardDefaults.cardColors(containerColor = TppTheme.colors.card),
|
||||||
|
border = BorderStroke(1.dp, TppTheme.colors.outline),
|
||||||
|
shape = MaterialTheme.shapes.medium,
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
) {
|
||||||
|
Column(Modifier.padding(16.dp), verticalArrangement = Arrangement.spacedBy(14.dp)) {
|
||||||
|
Text(
|
||||||
|
"Kroki do wykonania",
|
||||||
|
color = TppTheme.colors.ink,
|
||||||
|
fontWeight = FontWeight.Bold,
|
||||||
|
style = MaterialTheme.typography.titleMedium,
|
||||||
|
)
|
||||||
|
if (steps.isEmpty()) {
|
||||||
|
Text("Brak dodatkowych czynności. Możesz potwierdzić etap.", color = TppTheme.colors.muted)
|
||||||
|
}
|
||||||
|
steps.forEachIndexed { index, step ->
|
||||||
|
val required = routeStageRequirementIsRequired(step.requirement)
|
||||||
|
val done = when (step.type) {
|
||||||
|
RouteWorkflowStepType.Confirmation -> step.id in completedStepIds
|
||||||
|
RouteWorkflowStepType.Weight -> parseRouteWeightTons(weightText)?.let { it > 0.0 } == true
|
||||||
|
RouteWorkflowStepType.Photos ->
|
||||||
|
serverPhotos.any { it.workflowDocumentId.isNullOrBlank() } ||
|
||||||
|
localUploads.any {
|
||||||
|
it.workflowDocumentId.isNullOrBlank() &&
|
||||||
|
it.status != PhotoUploadStatus.FailedPermanent.storageValue &&
|
||||||
|
it.status != PhotoUploadStatus.Cancelled.storageValue
|
||||||
|
}
|
||||||
|
else -> false
|
||||||
|
}
|
||||||
|
|
||||||
|
Column(
|
||||||
|
Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.background(TppTheme.colors.panel, RoundedCornerShape(8.dp))
|
||||||
|
.border(1.dp, TppTheme.colors.outline.copy(alpha = 0.7f), RoundedCornerShape(8.dp))
|
||||||
|
.padding(13.dp),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(8.dp),
|
||||||
|
) {
|
||||||
|
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp)) {
|
||||||
|
Box(
|
||||||
|
Modifier
|
||||||
|
.size(30.dp)
|
||||||
|
.background(if (done) TppTheme.colors.successContainer else TppTheme.colors.card, RoundedCornerShape(15.dp)),
|
||||||
|
contentAlignment = Alignment.Center,
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
if (done) "✓" else "${index + 1}",
|
||||||
|
color = if (done) TppTheme.colors.forest else TppTheme.colors.muted,
|
||||||
|
fontWeight = FontWeight.Bold,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Column(Modifier.weight(1f)) {
|
||||||
|
Text(step.title, color = TppTheme.colors.ink, fontWeight = FontWeight.Bold)
|
||||||
|
Text(
|
||||||
|
if (required) "WYMAGANY" else "OPCJONALNY",
|
||||||
|
color = if (required) TppTheme.colors.error else TppTheme.colors.muted,
|
||||||
|
fontFamily = FontFamily.Monospace,
|
||||||
|
style = MaterialTheme.typography.labelSmall,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (step.type == RouteWorkflowStepType.Confirmation) {
|
||||||
|
Checkbox(
|
||||||
|
checked = step.id in completedStepIds,
|
||||||
|
onCheckedChange = { onStepToggle(step.id, it) },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (step.description.isNotBlank()) {
|
||||||
|
Text(step.description, color = TppTheme.colors.muted, style = MaterialTheme.typography.bodyMedium)
|
||||||
|
}
|
||||||
|
|
||||||
|
step.documents.forEach { document ->
|
||||||
|
val documentServerPhotos = serverPhotos.filter {
|
||||||
|
it.workflowStepId == step.id && it.workflowDocumentId == document.id
|
||||||
|
}
|
||||||
|
val documentUploads = localUploads.filter {
|
||||||
|
it.workflowStepId == step.id && it.workflowDocumentId == document.id &&
|
||||||
|
it.status != PhotoUploadStatus.Cancelled.storageValue &&
|
||||||
|
it.status != PhotoUploadStatus.FailedPermanent.storageValue
|
||||||
|
}
|
||||||
|
val documentPreparations = preparingUploads.count {
|
||||||
|
it.workflowStepId == step.id && it.workflowDocumentId == document.id
|
||||||
|
}
|
||||||
|
val count = documentServerPhotos.size + documentUploads.size + documentPreparations
|
||||||
|
Column(
|
||||||
|
Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.background(TppTheme.colors.card, RoundedCornerShape(6.dp))
|
||||||
|
.padding(11.dp),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(8.dp),
|
||||||
|
) {
|
||||||
|
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||||
|
Icon(Icons.Outlined.Description, contentDescription = null, tint = TppTheme.colors.forest)
|
||||||
|
Column(Modifier.weight(1f)) {
|
||||||
|
Text(document.label, color = TppTheme.colors.ink, fontWeight = FontWeight.Bold)
|
||||||
|
Text(
|
||||||
|
if (count > 0) "$count ${photoCountLabel(count)}" else if (routeStageRequirementIsRequired(document.requirement)) "wymagany dokument" else "opcjonalny dokument",
|
||||||
|
color = if (count > 0) TppTheme.colors.forest else TppTheme.colors.muted,
|
||||||
|
fontFamily = FontFamily.Monospace,
|
||||||
|
style = MaterialTheme.typography.labelSmall,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (document.description.isNotBlank()) {
|
||||||
|
Text(document.description, color = TppTheme.colors.muted, style = MaterialTheme.typography.bodySmall)
|
||||||
|
}
|
||||||
|
Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(6.dp)) {
|
||||||
|
OutlinedButton(
|
||||||
|
onClick = { onTakeDocumentPhoto(step.id, document.id) },
|
||||||
|
modifier = Modifier.weight(1f),
|
||||||
|
contentPadding = PaddingValues(horizontal = 6.dp, vertical = 8.dp),
|
||||||
|
) {
|
||||||
|
Icon(Icons.Outlined.CameraAlt, contentDescription = null, modifier = Modifier.size(17.dp))
|
||||||
|
Spacer(Modifier.width(4.dp))
|
||||||
|
Text("Aparat", style = MaterialTheme.typography.labelMedium)
|
||||||
|
}
|
||||||
|
OutlinedButton(
|
||||||
|
onClick = { onPickDocumentPhoto(step.id, document.id) },
|
||||||
|
modifier = Modifier.weight(1f),
|
||||||
|
contentPadding = PaddingValues(horizontal = 6.dp, vertical = 8.dp),
|
||||||
|
) {
|
||||||
|
Icon(Icons.Outlined.AddPhotoAlternate, contentDescription = null, modifier = Modifier.size(17.dp))
|
||||||
|
Spacer(Modifier.width(4.dp))
|
||||||
|
Text("Galeria", style = MaterialTheme.typography.labelMedium)
|
||||||
|
}
|
||||||
|
OutlinedButton(
|
||||||
|
onClick = { onPickDocumentFile(step.id, document.id) },
|
||||||
|
modifier = Modifier.weight(1f),
|
||||||
|
contentPadding = PaddingValues(horizontal = 6.dp, vertical = 8.dp),
|
||||||
|
) {
|
||||||
|
Icon(Icons.Outlined.Description, contentDescription = null, modifier = Modifier.size(17.dp))
|
||||||
|
Spacer(Modifier.width(4.dp))
|
||||||
|
Text("Plik", style = MaterialTheme.typography.labelMedium)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun RouteStageSummaryCard(route: DriverRouteDto) {
|
private fun RouteStageSummaryCard(route: DriverRouteDto) {
|
||||||
Card(
|
Card(
|
||||||
@@ -4809,6 +5185,9 @@ private fun DetailScreen(
|
|||||||
locationPermissionGranted: Boolean,
|
locationPermissionGranted: Boolean,
|
||||||
onBack: () -> Unit,
|
onBack: () -> Unit,
|
||||||
onPhoto: (RoutePhotoDto) -> Unit,
|
onPhoto: (RoutePhotoDto) -> Unit,
|
||||||
|
onDeletePhoto: (RoutePhotoDto) -> Unit,
|
||||||
|
onDeleteUpload: (PhotoUploadEntity) -> Unit,
|
||||||
|
onRetryUpload: (PhotoUploadEntity) -> Unit,
|
||||||
onRefresh: () -> Unit,
|
onRefresh: () -> Unit,
|
||||||
onStartRoute: () -> Unit,
|
onStartRoute: () -> Unit,
|
||||||
onFinishRoute: () -> Unit,
|
onFinishRoute: () -> Unit,
|
||||||
@@ -4867,6 +5246,9 @@ private fun DetailScreen(
|
|||||||
loadingWeightPending = projection.loadingWeightPending,
|
loadingWeightPending = projection.loadingWeightPending,
|
||||||
unloadingWeightPending = projection.unloadingWeightPending,
|
unloadingWeightPending = projection.unloadingWeightPending,
|
||||||
onPhoto = onPhoto,
|
onPhoto = onPhoto,
|
||||||
|
onDeletePhoto = onDeletePhoto,
|
||||||
|
onDeleteUpload = onDeleteUpload,
|
||||||
|
onRetryUpload = onRetryUpload,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
item { ErrorText(state.error) }
|
item { ErrorText(state.error) }
|
||||||
@@ -5335,6 +5717,9 @@ private fun CargoDocumentationSection(
|
|||||||
loadingWeightPending: Boolean,
|
loadingWeightPending: Boolean,
|
||||||
unloadingWeightPending: Boolean,
|
unloadingWeightPending: Boolean,
|
||||||
onPhoto: (RoutePhotoDto) -> Unit,
|
onPhoto: (RoutePhotoDto) -> Unit,
|
||||||
|
onDeletePhoto: (RoutePhotoDto) -> Unit,
|
||||||
|
onDeleteUpload: (PhotoUploadEntity) -> Unit,
|
||||||
|
onRetryUpload: (PhotoUploadEntity) -> Unit,
|
||||||
) {
|
) {
|
||||||
val loadingPhotos = routePhotosForStage(route.photos, "loading")
|
val loadingPhotos = routePhotosForStage(route.photos, "loading")
|
||||||
val unloadingPhotos = routePhotosForStage(route.photos, "unloading")
|
val unloadingPhotos = routePhotosForStage(route.photos, "unloading")
|
||||||
@@ -5359,6 +5744,9 @@ private fun CargoDocumentationSection(
|
|||||||
imageAuthHeader = imageAuthHeader,
|
imageAuthHeader = imageAuthHeader,
|
||||||
weightPending = loadingWeightPending,
|
weightPending = loadingWeightPending,
|
||||||
onPhoto = onPhoto,
|
onPhoto = onPhoto,
|
||||||
|
onDeletePhoto = onDeletePhoto,
|
||||||
|
onDeleteUpload = onDeleteUpload,
|
||||||
|
onRetryUpload = onRetryUpload,
|
||||||
)
|
)
|
||||||
RouteStageDocumentationBlock(
|
RouteStageDocumentationBlock(
|
||||||
title = "Rozładunek",
|
title = "Rozładunek",
|
||||||
@@ -5370,6 +5758,9 @@ private fun CargoDocumentationSection(
|
|||||||
imageAuthHeader = imageAuthHeader,
|
imageAuthHeader = imageAuthHeader,
|
||||||
weightPending = unloadingWeightPending,
|
weightPending = unloadingWeightPending,
|
||||||
onPhoto = onPhoto,
|
onPhoto = onPhoto,
|
||||||
|
onDeletePhoto = onDeletePhoto,
|
||||||
|
onDeleteUpload = onDeleteUpload,
|
||||||
|
onRetryUpload = onRetryUpload,
|
||||||
)
|
)
|
||||||
if (otherPhotos.isNotEmpty() || otherUploads.isNotEmpty()) {
|
if (otherPhotos.isNotEmpty() || otherUploads.isNotEmpty()) {
|
||||||
RouteStageDocumentationBlock(
|
RouteStageDocumentationBlock(
|
||||||
@@ -5382,6 +5773,9 @@ private fun CargoDocumentationSection(
|
|||||||
imageAuthHeader = imageAuthHeader,
|
imageAuthHeader = imageAuthHeader,
|
||||||
weightPending = false,
|
weightPending = false,
|
||||||
onPhoto = onPhoto,
|
onPhoto = onPhoto,
|
||||||
|
onDeletePhoto = onDeletePhoto,
|
||||||
|
onDeleteUpload = onDeleteUpload,
|
||||||
|
onRetryUpload = onRetryUpload,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5398,6 +5792,9 @@ private fun RouteStageDocumentationBlock(
|
|||||||
imageAuthHeader: String?,
|
imageAuthHeader: String?,
|
||||||
weightPending: Boolean = false,
|
weightPending: Boolean = false,
|
||||||
onPhoto: (RoutePhotoDto) -> Unit,
|
onPhoto: (RoutePhotoDto) -> Unit,
|
||||||
|
onDeletePhoto: (RoutePhotoDto) -> Unit,
|
||||||
|
onDeleteUpload: (PhotoUploadEntity) -> Unit,
|
||||||
|
onRetryUpload: (PhotoUploadEntity) -> Unit,
|
||||||
) {
|
) {
|
||||||
val count = visiblePhotoAttachmentCount(photos.size, uploads.size)
|
val count = visiblePhotoAttachmentCount(photos.size, uploads.size)
|
||||||
Column(verticalArrangement = Arrangement.spacedBy(10.dp)) {
|
Column(verticalArrangement = Arrangement.spacedBy(10.dp)) {
|
||||||
@@ -5480,10 +5877,9 @@ private fun RouteStageDocumentationBlock(
|
|||||||
deletingPhotoIds = deletingPhotoIds,
|
deletingPhotoIds = deletingPhotoIds,
|
||||||
imageAuthHeader = imageAuthHeader,
|
imageAuthHeader = imageAuthHeader,
|
||||||
onPhoto = onPhoto,
|
onPhoto = onPhoto,
|
||||||
onDeletePhoto = {},
|
onDeletePhoto = onDeletePhoto,
|
||||||
onDeleteUpload = {},
|
onDeleteUpload = onDeleteUpload,
|
||||||
onRetryUpload = {},
|
onRetryUpload = onRetryUpload,
|
||||||
readOnly = true,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5492,6 +5888,107 @@ private fun RouteStageDocumentationBlock(
|
|||||||
private fun formatRouteWeight(weight: Double): String =
|
private fun formatRouteWeight(weight: Double): String =
|
||||||
if (weight % 1.0 == 0.0) "${weight.toInt()} t" else String.format(Locale("pl", "PL"), "%.3f t", weight)
|
if (weight % 1.0 == 0.0) "${weight.toInt()} t" else String.format(Locale("pl", "PL"), "%.3f t", weight)
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun RouteStageCameraActions(
|
||||||
|
onSinglePhoto: () -> Unit,
|
||||||
|
onMultiplePhotos: () -> Unit,
|
||||||
|
) {
|
||||||
|
BoxWithConstraints(Modifier.fillMaxWidth()) {
|
||||||
|
if (maxWidth >= 300.dp) {
|
||||||
|
Row(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(12.dp),
|
||||||
|
) {
|
||||||
|
RouteStageCameraActionButton(
|
||||||
|
label = "Jedno zdjęcie",
|
||||||
|
icon = Icons.Outlined.CameraAlt,
|
||||||
|
color = TppTheme.colors.forest,
|
||||||
|
compact = true,
|
||||||
|
modifier = Modifier.weight(1f),
|
||||||
|
onClick = onSinglePhoto,
|
||||||
|
)
|
||||||
|
RouteStageCameraActionButton(
|
||||||
|
label = "Wiele zdjęć",
|
||||||
|
icon = Icons.Outlined.CameraAlt,
|
||||||
|
color = TppTheme.colors.forest,
|
||||||
|
compact = true,
|
||||||
|
modifier = Modifier.weight(1f),
|
||||||
|
onClick = onMultiplePhotos,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Column(verticalArrangement = Arrangement.spacedBy(12.dp)) {
|
||||||
|
RouteStageCameraActionButton(
|
||||||
|
label = "Jedno zdjęcie",
|
||||||
|
icon = Icons.Outlined.CameraAlt,
|
||||||
|
color = TppTheme.colors.forest,
|
||||||
|
compact = false,
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
onClick = onSinglePhoto,
|
||||||
|
)
|
||||||
|
RouteStageCameraActionButton(
|
||||||
|
label = "Wiele zdjęć",
|
||||||
|
icon = Icons.Outlined.CameraAlt,
|
||||||
|
color = TppTheme.colors.forest,
|
||||||
|
compact = false,
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
onClick = onMultiplePhotos,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun RouteStageCameraActionButton(
|
||||||
|
label: String,
|
||||||
|
icon: ImageVector,
|
||||||
|
color: Color,
|
||||||
|
compact: Boolean,
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
|
onClick: () -> Unit,
|
||||||
|
) {
|
||||||
|
Button(
|
||||||
|
onClick = onClick,
|
||||||
|
modifier = modifier.height(if (compact) 76.dp else 64.dp),
|
||||||
|
colors = ButtonDefaults.buttonColors(containerColor = color),
|
||||||
|
contentPadding = PaddingValues(horizontal = 12.dp, vertical = 8.dp),
|
||||||
|
shape = MaterialTheme.shapes.medium,
|
||||||
|
) {
|
||||||
|
if (compact) {
|
||||||
|
Column(
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
|
verticalArrangement = Arrangement.spacedBy(4.dp),
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
icon,
|
||||||
|
contentDescription = null,
|
||||||
|
tint = Color.White,
|
||||||
|
modifier = Modifier.size(22.dp),
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
text = label,
|
||||||
|
color = Color.White,
|
||||||
|
style = MaterialTheme.typography.labelLarge,
|
||||||
|
fontWeight = FontWeight.Bold,
|
||||||
|
maxLines = 1,
|
||||||
|
overflow = TextOverflow.Ellipsis,
|
||||||
|
textAlign = TextAlign.Center,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Icon(icon, contentDescription = null, tint = Color.White)
|
||||||
|
Spacer(Modifier.width(10.dp))
|
||||||
|
Text(
|
||||||
|
text = label,
|
||||||
|
color = Color.White,
|
||||||
|
style = MaterialTheme.typography.titleMedium,
|
||||||
|
fontWeight = FontWeight.Bold,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun CargoActionButton(label: String, icon: ImageVector, color: Color, onClick: () -> Unit) {
|
private fun CargoActionButton(label: String, icon: ImageVector, color: Color, onClick: () -> Unit) {
|
||||||
Button(
|
Button(
|
||||||
@@ -5510,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,
|
||||||
@@ -5519,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),
|
||||||
@@ -5568,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) {
|
||||||
@@ -5614,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 {
|
||||||
@@ -5847,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(
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package pl.firmatpp.kierowca.ui
|
||||||
|
|
||||||
|
import java.time.LocalDate
|
||||||
|
import pl.firmatpp.kierowca.data.model.DriverRouteDto
|
||||||
|
|
||||||
|
fun routeIncludesPublicationDate(route: DriverRouteDto?, date: String?): Boolean {
|
||||||
|
if (route == null || date == null) return false
|
||||||
|
return runCatching {
|
||||||
|
val day = LocalDate.parse(date)
|
||||||
|
val start = LocalDate.parse(route.routeDate)
|
||||||
|
val end = LocalDate.parse(route.unloadingDate ?: route.routeDate)
|
||||||
|
!day.isBefore(start) && !day.isAfter(end)
|
||||||
|
}.getOrDefault(false)
|
||||||
|
}
|
||||||
@@ -12,6 +12,8 @@ import java.time.temporal.ChronoUnit
|
|||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
import pl.firmatpp.kierowca.data.model.DriverRouteDto
|
import pl.firmatpp.kierowca.data.model.DriverRouteDto
|
||||||
|
import pl.firmatpp.kierowca.data.model.DriverRouteWorkflowDto
|
||||||
|
import pl.firmatpp.kierowca.data.model.DriverRouteWorkflowStepDto
|
||||||
import pl.firmatpp.kierowca.data.model.DispatchSheetReminderDto
|
import pl.firmatpp.kierowca.data.model.DispatchSheetReminderDto
|
||||||
import pl.firmatpp.kierowca.data.model.RoutePhotoDto
|
import pl.firmatpp.kierowca.data.model.RoutePhotoDto
|
||||||
import pl.firmatpp.kierowca.data.model.TachographReminderDto
|
import pl.firmatpp.kierowca.data.model.TachographReminderDto
|
||||||
@@ -278,6 +280,75 @@ fun routeStageRequirementIsVisible(requirement: String): Boolean =
|
|||||||
fun routeStageRequirementIsRequired(requirement: String): Boolean =
|
fun routeStageRequirementIsRequired(requirement: String): Boolean =
|
||||||
normalizeRouteStageRequirement(requirement) == RouteStageRequirement.Required
|
normalizeRouteStageRequirement(requirement) == RouteStageRequirement.Required
|
||||||
|
|
||||||
|
object RouteWorkflowStepType {
|
||||||
|
const val Confirmation = "confirmation"
|
||||||
|
const val Weight = "weight"
|
||||||
|
const val Photos = "photos"
|
||||||
|
}
|
||||||
|
|
||||||
|
fun routeWorkflowSteps(workflow: DriverRouteWorkflowDto?, stage: String): List<DriverRouteWorkflowStepDto> =
|
||||||
|
when (stage) {
|
||||||
|
"loading" -> workflow?.loading?.steps
|
||||||
|
"unloading" -> workflow?.unloading?.steps
|
||||||
|
else -> null
|
||||||
|
}.orEmpty().filter { routeStageRequirementIsVisible(it.requirement) }
|
||||||
|
|
||||||
|
fun routeWorkflowSubmitBlocker(
|
||||||
|
workflow: DriverRouteWorkflowDto?,
|
||||||
|
stage: String,
|
||||||
|
completedStepIds: Set<String>,
|
||||||
|
weightText: String,
|
||||||
|
serverPhotos: List<RoutePhotoDto>,
|
||||||
|
localUploads: List<PhotoUploadEntity>,
|
||||||
|
): String? {
|
||||||
|
val steps = routeWorkflowSteps(workflow, stage)
|
||||||
|
if (steps.isEmpty()) return null
|
||||||
|
val normalizedWeight = parseRouteWeightTons(weightText)
|
||||||
|
|
||||||
|
for (step in steps) {
|
||||||
|
val required = routeStageRequirementIsRequired(step.requirement)
|
||||||
|
when (step.type) {
|
||||||
|
RouteWorkflowStepType.Confirmation -> if (required && step.id !in completedStepIds) {
|
||||||
|
return "Potwierdź krok: ${step.title}."
|
||||||
|
}
|
||||||
|
RouteWorkflowStepType.Weight -> when {
|
||||||
|
required && weightText.isBlank() -> return "Uzupełnij krok: ${step.title}."
|
||||||
|
weightText.isNotBlank() && normalizedWeight == null -> return "Podaj poprawny tonaż."
|
||||||
|
weightText.isNotBlank() && normalizedWeight != null && normalizedWeight <= 0.0 -> return "Tonaż musi być większy od zera."
|
||||||
|
weightText.isNotBlank() && normalizedWeight != null && normalizedWeight > routeWeightMaxTons -> return "Tonaż nie może przekraczać 999,999 t."
|
||||||
|
}
|
||||||
|
RouteWorkflowStepType.Photos -> if (
|
||||||
|
required &&
|
||||||
|
serverPhotos.none { it.workflowDocumentId.isNullOrBlank() } &&
|
||||||
|
localUploads.none {
|
||||||
|
it.workflowDocumentId.isNullOrBlank() &&
|
||||||
|
it.status != PhotoUploadStatus.Cancelled.storageValue &&
|
||||||
|
it.status != PhotoUploadStatus.FailedPermanent.storageValue
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
return "Dodaj zdjęcie dla kroku: ${step.title}."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (document in step.documents.filter { routeStageRequirementIsRequired(it.requirement) }) {
|
||||||
|
val serverPresent = serverPhotos.any {
|
||||||
|
it.workflowStepId == step.id && it.workflowDocumentId == document.id
|
||||||
|
}
|
||||||
|
val localPresent = localUploads.any {
|
||||||
|
it.workflowStepId == step.id &&
|
||||||
|
it.workflowDocumentId == document.id &&
|
||||||
|
it.status != PhotoUploadStatus.Cancelled.storageValue &&
|
||||||
|
it.status != PhotoUploadStatus.FailedPermanent.storageValue
|
||||||
|
}
|
||||||
|
if (!serverPresent && !localPresent) {
|
||||||
|
return "Dodaj dokument „${document.label}” w kroku „${step.title}”."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
fun normalizeRouteStageNotes(value: String): String = value.take(routeStageNotesMaxLength)
|
fun normalizeRouteStageNotes(value: String): String = value.take(routeStageNotesMaxLength)
|
||||||
|
|
||||||
fun parseRouteWeightTons(weightText: String): Double? {
|
fun parseRouteWeightTons(weightText: String): Double? {
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ import pl.firmatpp.kierowca.data.model.DriverLeaveForecastDto
|
|||||||
import pl.firmatpp.kierowca.data.model.DriverLeaveRequestDto
|
import pl.firmatpp.kierowca.data.model.DriverLeaveRequestDto
|
||||||
import pl.firmatpp.kierowca.data.model.DriverLeaveSummaryDto
|
import pl.firmatpp.kierowca.data.model.DriverLeaveSummaryDto
|
||||||
import pl.firmatpp.kierowca.data.model.DriverRouteDto
|
import pl.firmatpp.kierowca.data.model.DriverRouteDto
|
||||||
|
import pl.firmatpp.kierowca.data.model.DriverRouteWorkflowDto
|
||||||
import pl.firmatpp.kierowca.data.model.RoutePhotoDto
|
import pl.firmatpp.kierowca.data.model.RoutePhotoDto
|
||||||
import pl.firmatpp.kierowca.data.model.TachographReminderDto
|
import pl.firmatpp.kierowca.data.model.TachographReminderDto
|
||||||
import pl.firmatpp.kierowca.data.model.driverLifecycleStatus
|
import pl.firmatpp.kierowca.data.model.driverLifecycleStatus
|
||||||
@@ -72,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,
|
||||||
@@ -98,6 +109,7 @@ data class DriverUiState(
|
|||||||
val loadingWeightRequirement: String = RouteStageRequirement.Required,
|
val loadingWeightRequirement: String = RouteStageRequirement.Required,
|
||||||
val unloadingPhotoRequirement: String = RouteStageRequirement.Required,
|
val unloadingPhotoRequirement: String = RouteStageRequirement.Required,
|
||||||
val unloadingWeightRequirement: String = RouteStageRequirement.Required,
|
val unloadingWeightRequirement: String = RouteStageRequirement.Required,
|
||||||
|
val routeWorkflow: DriverRouteWorkflowDto? = null,
|
||||||
val notifyNewRoutes: Boolean = false,
|
val notifyNewRoutes: Boolean = false,
|
||||||
val routeProgressNotificationEnabled: Boolean = true,
|
val routeProgressNotificationEnabled: Boolean = true,
|
||||||
val notificationPermissionDenied: Boolean = false,
|
val notificationPermissionDenied: Boolean = false,
|
||||||
@@ -105,9 +117,11 @@ data class DriverUiState(
|
|||||||
val selectedPhoto: RoutePhotoDto? = null,
|
val selectedPhoto: RoutePhotoDto? = null,
|
||||||
val routeStageWeightText: String = "",
|
val routeStageWeightText: String = "",
|
||||||
val routeStageNotesText: String = "",
|
val routeStageNotesText: String = "",
|
||||||
|
val routeStageCompletedStepIds: Set<String> = emptySet(),
|
||||||
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,
|
||||||
@@ -613,6 +627,7 @@ class DriverViewModel(application: Application) : AndroidViewModel(application)
|
|||||||
loadingWeightRequirement = normalizeRouteStageRequirement(settings?.loadingWeightRequirement),
|
loadingWeightRequirement = normalizeRouteStageRequirement(settings?.loadingWeightRequirement),
|
||||||
unloadingPhotoRequirement = normalizeRouteStageRequirement(settings?.unloadingPhotoRequirement),
|
unloadingPhotoRequirement = normalizeRouteStageRequirement(settings?.unloadingPhotoRequirement),
|
||||||
unloadingWeightRequirement = normalizeRouteStageRequirement(settings?.unloadingWeightRequirement),
|
unloadingWeightRequirement = normalizeRouteStageRequirement(settings?.unloadingWeightRequirement),
|
||||||
|
routeWorkflow = settings?.routeWorkflow,
|
||||||
leaveRequestsConfig = settings?.leaveRequests?.let { config ->
|
leaveRequestsConfig = settings?.leaveRequests?.let { config ->
|
||||||
LeaveRequestsConfig(enabled = config.enabled, types = config.types)
|
LeaveRequestsConfig(enabled = config.enabled, types = config.types)
|
||||||
},
|
},
|
||||||
@@ -629,6 +644,10 @@ class DriverViewModel(application: Application) : AndroidViewModel(application)
|
|||||||
error = null,
|
error = null,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
if (!cached.stale && response.dayPublication?.isVisible == false &&
|
||||||
|
routeIncludesPublicationDate(_state.value.selectedRoute, response.dayPublication.date)) {
|
||||||
|
_state.value.selectedRoute?.id?.let(::closeUnavailableRoute)
|
||||||
|
}
|
||||||
response.session.driver.id.let { driverId ->
|
response.session.driver.id.let { driverId ->
|
||||||
liveSyncClient.start(driverId, response.realtime)
|
liveSyncClient.start(driverId, response.realtime)
|
||||||
if (_state.value.isOnline && !cached.stale) registerPushTokenIfAvailable(driverId)
|
if (_state.value.isOnline && !cached.stale) registerPushTokenIfAvailable(driverId)
|
||||||
@@ -750,6 +769,8 @@ class DriverViewModel(application: Application) : AndroidViewModel(application)
|
|||||||
if (generation != routeDetailRequestGeneration) return@onFailure
|
if (generation != routeDetailRequestGeneration) return@onFailure
|
||||||
if (ApiErrorMapper.map(throwable).kind == ApiErrorKind.Auth) {
|
if (ApiErrorMapper.map(throwable).kind == ApiErrorKind.Auth) {
|
||||||
handleExpiredSession()
|
handleExpiredSession()
|
||||||
|
} else if (ApiErrorMapper.map(throwable).statusCode == 404) {
|
||||||
|
closeUnavailableRoute(routeId)
|
||||||
} else {
|
} else {
|
||||||
_state.update { it.withApiError(throwable) }
|
_state.update { it.withApiError(throwable) }
|
||||||
}
|
}
|
||||||
@@ -759,6 +780,19 @@ class DriverViewModel(application: Application) : AndroidViewModel(application)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun closeUnavailableRoute(routeId: String) {
|
||||||
|
routeDetailRequestGeneration++
|
||||||
|
_state.update { current ->
|
||||||
|
if (current.selectedRoute?.id != routeId) current else current.copy(
|
||||||
|
selectedRoute = null,
|
||||||
|
selectedPhoto = null,
|
||||||
|
routes = current.routes.filterNot { it.id == routeId },
|
||||||
|
refreshing = false,
|
||||||
|
screen = if (current.screen in setOf(DriverScreen.Detail, DriverScreen.StartRoute, DriverScreen.LoadingWeight, DriverScreen.FinishRoute, DriverScreen.Photo)) DriverScreen.Routes else current.screen,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun openProfile() {
|
fun openProfile() {
|
||||||
_state.update { it.copy(screen = DriverScreen.Profile, error = null) }
|
_state.update { it.copy(screen = DriverScreen.Profile, error = null) }
|
||||||
if (
|
if (
|
||||||
@@ -1478,19 +1512,60 @@ class DriverViewModel(application: Application) : AndroidViewModel(application)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun uploadPhoto(uri: Uri, source: String, metadata: PhotoUploadMetadata = PhotoUploadMetadata(), stage: String = "other") {
|
fun uploadPhoto(
|
||||||
|
uri: Uri,
|
||||||
|
source: String,
|
||||||
|
metadata: PhotoUploadMetadata = PhotoUploadMetadata(),
|
||||||
|
stage: String = "other",
|
||||||
|
workflowStepId: String? = null,
|
||||||
|
workflowDocumentId: String? = null,
|
||||||
|
): Job? {
|
||||||
val snapshot = _state.value
|
val snapshot = _state.value
|
||||||
val route = snapshot.selectedRoute ?: return
|
val route = snapshot.selectedRoute ?: return null
|
||||||
if (!routeIsActiveToday(route, snapshot.selectedDate)) {
|
if (!routeIsActiveToday(route, snapshot.selectedDate)) {
|
||||||
_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
|
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 {
|
||||||
|
try {
|
||||||
|
runCatching {
|
||||||
|
photoUploadOutbox.enqueue(
|
||||||
|
routeId = route.id,
|
||||||
|
uri = uri,
|
||||||
|
source = source,
|
||||||
|
metadata = metadata,
|
||||||
|
stage = stage,
|
||||||
|
workflowVersion = snapshot.routeWorkflow?.version,
|
||||||
|
workflowStepId = workflowStepId,
|
||||||
|
workflowDocumentId = workflowDocumentId,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
viewModelScope.launch {
|
|
||||||
_state.update { it.copy(error = null) }
|
|
||||||
runCatching { photoUploadOutbox.enqueue(route.id, uri, source, metadata, stage) }
|
|
||||||
.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
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1505,7 +1580,9 @@ class DriverViewModel(application: Application) : AndroidViewModel(application)
|
|||||||
_state.update { it.copy(error = "Załadunek nie jest dostępny poza zaplanowanym zakresem kursu.") }
|
_state.update { it.copy(error = "Załadunek nie jest dostępny poza zaplanowanym zakresem kursu.") }
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
val targetScreen = if (
|
val targetScreen = if (snapshot.routeWorkflow != null) {
|
||||||
|
DriverScreen.StartRoute
|
||||||
|
} else if (
|
||||||
!routeStageRequirementIsVisible(snapshot.loadingPhotoRequirement) &&
|
!routeStageRequirementIsVisible(snapshot.loadingPhotoRequirement) &&
|
||||||
routeStageRequirementIsVisible(snapshot.loadingWeightRequirement)
|
routeStageRequirementIsVisible(snapshot.loadingWeightRequirement)
|
||||||
) DriverScreen.LoadingWeight else DriverScreen.StartRoute
|
) DriverScreen.LoadingWeight else DriverScreen.StartRoute
|
||||||
@@ -1514,6 +1591,7 @@ class DriverViewModel(application: Application) : AndroidViewModel(application)
|
|||||||
screen = targetScreen,
|
screen = targetScreen,
|
||||||
routeStageWeightText = "",
|
routeStageWeightText = "",
|
||||||
routeStageNotesText = route.loadingNotes.orEmpty(),
|
routeStageNotesText = route.loadingNotes.orEmpty(),
|
||||||
|
routeStageCompletedStepIds = emptySet(),
|
||||||
feedback = null,
|
feedback = null,
|
||||||
error = null,
|
error = null,
|
||||||
)
|
)
|
||||||
@@ -1559,6 +1637,7 @@ class DriverViewModel(application: Application) : AndroidViewModel(application)
|
|||||||
screen = DriverScreen.FinishRoute,
|
screen = DriverScreen.FinishRoute,
|
||||||
routeStageWeightText = route.unloadingWeight?.toString().orEmpty(),
|
routeStageWeightText = route.unloadingWeight?.toString().orEmpty(),
|
||||||
routeStageNotesText = route.unloadingNotes.orEmpty(),
|
routeStageNotesText = route.unloadingNotes.orEmpty(),
|
||||||
|
routeStageCompletedStepIds = emptySet(),
|
||||||
feedback = null,
|
feedback = null,
|
||||||
error = null,
|
error = null,
|
||||||
)
|
)
|
||||||
@@ -1574,6 +1653,18 @@ class DriverViewModel(application: Application) : AndroidViewModel(application)
|
|||||||
_state.update { it.copy(routeStageNotesText = normalizeRouteStageNotes(value)) }
|
_state.update { it.copy(routeStageNotesText = normalizeRouteStageNotes(value)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun toggleRouteStageStep(stepId: String, completed: Boolean) {
|
||||||
|
_state.update {
|
||||||
|
it.copy(
|
||||||
|
routeStageCompletedStepIds = if (completed) {
|
||||||
|
it.routeStageCompletedStepIds + stepId
|
||||||
|
} else {
|
||||||
|
it.routeStageCompletedStepIds - stepId
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun correctFailedRouteAction() {
|
fun correctFailedRouteAction() {
|
||||||
val snapshot = _state.value
|
val snapshot = _state.value
|
||||||
val action = (snapshot.visibleRouteActions + snapshot.routeActions)
|
val action = (snapshot.visibleRouteActions + snapshot.routeActions)
|
||||||
@@ -1672,7 +1763,16 @@ class DriverViewModel(application: Application) : AndroidViewModel(application)
|
|||||||
val stageUploads = routeStageUsableUploads(
|
val stageUploads = routeStageUsableUploads(
|
||||||
snapshot.photoUploads.filter { normalizedRoutePhotoStage(it.stage) == stage },
|
snapshot.photoUploads.filter { normalizedRoutePhotoStage(it.stage) == stage },
|
||||||
)
|
)
|
||||||
val submitBlocker = if (stage == "loading") {
|
val submitBlocker = if (snapshot.routeWorkflow != null) {
|
||||||
|
routeWorkflowSubmitBlocker(
|
||||||
|
workflow = snapshot.routeWorkflow,
|
||||||
|
stage = stage,
|
||||||
|
completedStepIds = snapshot.routeStageCompletedStepIds,
|
||||||
|
weightText = snapshot.routeStageWeightText,
|
||||||
|
serverPhotos = stagePhotos,
|
||||||
|
localUploads = stageUploads,
|
||||||
|
)
|
||||||
|
} else if (stage == "loading") {
|
||||||
loadingWeightSubmitBlocker(
|
loadingWeightSubmitBlocker(
|
||||||
weightText = snapshot.routeStageWeightText,
|
weightText = snapshot.routeStageWeightText,
|
||||||
serverPhotoCount = stagePhotos.size,
|
serverPhotoCount = stagePhotos.size,
|
||||||
@@ -1695,7 +1795,7 @@ class DriverViewModel(application: Application) : AndroidViewModel(application)
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val photoClientRequestIds = if (routeStageRequirementIsVisible(photoRequirement)) {
|
val photoClientRequestIds = if (snapshot.routeWorkflow != null || routeStageRequirementIsVisible(photoRequirement)) {
|
||||||
(stagePhotos.mapNotNull { it.clientRequestId } + stageUploads.map { it.clientRequestId })
|
(stagePhotos.mapNotNull { it.clientRequestId } + stageUploads.map { it.clientRequestId })
|
||||||
.map { it.trim() }
|
.map { it.trim() }
|
||||||
.filter { it.isNotBlank() }
|
.filter { it.isNotBlank() }
|
||||||
@@ -1714,7 +1814,14 @@ class DriverViewModel(application: Application) : AndroidViewModel(application)
|
|||||||
runCatching {
|
runCatching {
|
||||||
val updatedRoute = when (stage) {
|
val updatedRoute = when (stage) {
|
||||||
"loading" -> {
|
"loading" -> {
|
||||||
routeActionOutbox.enqueueStart(route.id, weight, photoClientRequestIds, notes)
|
routeActionOutbox.enqueueStart(
|
||||||
|
route.id,
|
||||||
|
weight,
|
||||||
|
photoClientRequestIds,
|
||||||
|
notes,
|
||||||
|
snapshot.routeWorkflow?.version,
|
||||||
|
snapshot.routeStageCompletedStepIds.toList(),
|
||||||
|
)
|
||||||
route.copy(
|
route.copy(
|
||||||
status = "W TRAKCIE",
|
status = "W TRAKCIE",
|
||||||
driverStatus = "W TRAKCIE",
|
driverStatus = "W TRAKCIE",
|
||||||
@@ -1725,7 +1832,14 @@ class DriverViewModel(application: Application) : AndroidViewModel(application)
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
"unloading" -> {
|
"unloading" -> {
|
||||||
routeActionOutbox.enqueueFinish(route.id, weight, photoClientRequestIds, notes)
|
routeActionOutbox.enqueueFinish(
|
||||||
|
route.id,
|
||||||
|
weight,
|
||||||
|
photoClientRequestIds,
|
||||||
|
notes,
|
||||||
|
snapshot.routeWorkflow?.version,
|
||||||
|
snapshot.routeStageCompletedStepIds.toList(),
|
||||||
|
)
|
||||||
route.copy(
|
route.copy(
|
||||||
status = "ZAKOŃCZONA",
|
status = "ZAKOŃCZONA",
|
||||||
driverStatus = "ZAKOŃCZONA",
|
driverStatus = "ZAKOŃCZONA",
|
||||||
@@ -1746,6 +1860,7 @@ class DriverViewModel(application: Application) : AndroidViewModel(application)
|
|||||||
routes = it.routes.map { item -> if (item.id == route.id) updatedRoute else item },
|
routes = it.routes.map { item -> if (item.id == route.id) updatedRoute else item },
|
||||||
routeStageWeightText = "",
|
routeStageWeightText = "",
|
||||||
routeStageNotesText = "",
|
routeStageNotesText = "",
|
||||||
|
routeStageCompletedStepIds = emptySet(),
|
||||||
feedback = if (stage == "loading") {
|
feedback = if (stage == "loading") {
|
||||||
if (snapshot.isOnline) "Potwierdzam załadunek z serwerem." else "Załadunek zapisano w telefonie. Wyślemy go po odzyskaniu internetu."
|
if (snapshot.isOnline) "Potwierdzam załadunek z serwerem." else "Załadunek zapisano w telefonie. Wyślemy go po odzyskaniu internetu."
|
||||||
} else {
|
} else {
|
||||||
@@ -1955,7 +2070,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)
|
||||||
@@ -2177,6 +2299,7 @@ class DriverViewModel(application: Application) : AndroidViewModel(application)
|
|||||||
val snapshot = _state.value
|
val snapshot = _state.value
|
||||||
when (hint.scope) {
|
when (hint.scope) {
|
||||||
DriverSyncRepository.SCOPE_ROUTES -> {
|
DriverSyncRepository.SCOPE_ROUTES -> {
|
||||||
|
if (routeIncludesPublicationDate(snapshot.selectedRoute, hint.date)) refreshSelectedRoute()
|
||||||
if (shouldShowRouteDayLiveUpdate(snapshot.selectedDate, hint.date)) {
|
if (shouldShowRouteDayLiveUpdate(snapshot.selectedDate, hint.date)) {
|
||||||
refreshRoutesSilently()
|
refreshRoutesSilently()
|
||||||
if (snapshot.screen == DriverScreen.Routes) {
|
if (snapshot.screen == DriverScreen.Routes) {
|
||||||
|
|||||||
@@ -0,0 +1,288 @@
|
|||||||
|
package pl.firmatpp.kierowca.ui
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.net.Uri
|
||||||
|
import androidx.activity.compose.BackHandler
|
||||||
|
import androidx.camera.core.ImageCapture
|
||||||
|
import androidx.camera.core.ImageCaptureException
|
||||||
|
import androidx.camera.view.CameraController
|
||||||
|
import androidx.camera.view.LifecycleCameraController
|
||||||
|
import androidx.camera.view.PreviewView
|
||||||
|
import androidx.compose.foundation.background
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
|
import androidx.compose.foundation.layout.Box
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.PaddingValues
|
||||||
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.height
|
||||||
|
import androidx.compose.foundation.layout.navigationBarsPadding
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.layout.size
|
||||||
|
import androidx.compose.foundation.layout.statusBarsPadding
|
||||||
|
import androidx.compose.foundation.layout.width
|
||||||
|
import androidx.compose.foundation.shape.CircleShape
|
||||||
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.automirrored.outlined.ArrowBack
|
||||||
|
import androidx.compose.material.icons.outlined.CameraAlt
|
||||||
|
import androidx.compose.material.icons.outlined.CheckCircle
|
||||||
|
import androidx.compose.material3.Button
|
||||||
|
import androidx.compose.material3.ButtonDefaults
|
||||||
|
import androidx.compose.material3.CircularProgressIndicator
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.IconButton
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.DisposableEffect
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableIntStateOf
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.rememberCoroutineScope
|
||||||
|
import androidx.compose.runtime.rememberUpdatedState
|
||||||
|
import androidx.compose.runtime.saveable.rememberSaveable
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.compose.ui.viewinterop.AndroidView
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
|
import androidx.core.content.FileProvider
|
||||||
|
import androidx.lifecycle.compose.LocalLifecycleOwner
|
||||||
|
import java.io.File
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import pl.firmatpp.kierowca.ui.theme.TppTheme
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
internal fun MultiplePhotoCameraScreen(
|
||||||
|
stage: String,
|
||||||
|
onPhotoCaptured: suspend (Uri) -> Unit,
|
||||||
|
onClose: () -> Unit,
|
||||||
|
) {
|
||||||
|
val context = LocalContext.current
|
||||||
|
val lifecycleOwner = LocalLifecycleOwner.current
|
||||||
|
val coroutineScope = rememberCoroutineScope()
|
||||||
|
val currentOnPhotoCaptured by rememberUpdatedState(onPhotoCaptured)
|
||||||
|
val cameraController = remember(context) {
|
||||||
|
LifecycleCameraController(context).apply {
|
||||||
|
setEnabledUseCases(CameraController.IMAGE_CAPTURE)
|
||||||
|
imageCaptureMode = ImageCapture.CAPTURE_MODE_MINIMIZE_LATENCY
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var capturedCount by rememberSaveable(stage) { mutableIntStateOf(0) }
|
||||||
|
var pendingUploads by remember { mutableIntStateOf(0) }
|
||||||
|
var isCapturing by remember { mutableStateOf(false) }
|
||||||
|
var cameraUnavailable by remember { mutableStateOf(false) }
|
||||||
|
var cameraError by remember { mutableStateOf<String?>(null) }
|
||||||
|
|
||||||
|
DisposableEffect(cameraController, lifecycleOwner) {
|
||||||
|
runCatching {
|
||||||
|
cameraController.bindToLifecycle(lifecycleOwner)
|
||||||
|
}.onFailure {
|
||||||
|
cameraUnavailable = true
|
||||||
|
cameraError = "Nie udało się uruchomić aparatu."
|
||||||
|
}
|
||||||
|
|
||||||
|
onDispose {
|
||||||
|
cameraController.unbind()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BackHandler {
|
||||||
|
if (!isCapturing && pendingUploads == 0) onClose()
|
||||||
|
}
|
||||||
|
|
||||||
|
Box(
|
||||||
|
Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.background(Color.Black),
|
||||||
|
) {
|
||||||
|
AndroidView(
|
||||||
|
factory = { previewContext ->
|
||||||
|
PreviewView(previewContext).apply {
|
||||||
|
controller = cameraController
|
||||||
|
implementationMode = PreviewView.ImplementationMode.COMPATIBLE
|
||||||
|
scaleType = PreviewView.ScaleType.FILL_CENTER
|
||||||
|
}
|
||||||
|
},
|
||||||
|
modifier = Modifier.fillMaxSize(),
|
||||||
|
)
|
||||||
|
|
||||||
|
Row(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.align(Alignment.TopCenter)
|
||||||
|
.background(Color.Black.copy(alpha = 0.62f))
|
||||||
|
.statusBarsPadding()
|
||||||
|
.padding(horizontal = 8.dp, vertical = 10.dp),
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
) {
|
||||||
|
IconButton(
|
||||||
|
onClick = onClose,
|
||||||
|
enabled = !isCapturing && pendingUploads == 0,
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
Icons.AutoMirrored.Outlined.ArrowBack,
|
||||||
|
contentDescription = "Wróć",
|
||||||
|
tint = Color.White,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Column {
|
||||||
|
Text(
|
||||||
|
text = if (stage == "loading") "Zdjęcia załadunku" else "Zdjęcia rozładunku",
|
||||||
|
color = Color.White,
|
||||||
|
style = MaterialTheme.typography.titleMedium,
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
text = if (pendingUploads > 0) {
|
||||||
|
"Wykonano: $capturedCount · zapisuję: $pendingUploads"
|
||||||
|
} else {
|
||||||
|
"Wykonano: $capturedCount"
|
||||||
|
},
|
||||||
|
color = Color.White.copy(alpha = 0.78f),
|
||||||
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.align(Alignment.BottomCenter)
|
||||||
|
.background(Color.Black.copy(alpha = 0.68f))
|
||||||
|
.navigationBarsPadding()
|
||||||
|
.padding(horizontal = 20.dp, vertical = 16.dp),
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
|
verticalArrangement = Arrangement.spacedBy(12.dp),
|
||||||
|
) {
|
||||||
|
cameraError?.let { message ->
|
||||||
|
Text(
|
||||||
|
text = message,
|
||||||
|
color = Color.White,
|
||||||
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.background(Color(0xFF8C1D18), RoundedCornerShape(6.dp))
|
||||||
|
.padding(10.dp),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.height(72.dp),
|
||||||
|
) {
|
||||||
|
Button(
|
||||||
|
onClick = {
|
||||||
|
if (isCapturing || cameraUnavailable) return@Button
|
||||||
|
|
||||||
|
val photoFile = createMultipleCameraFile(context)
|
||||||
|
val outputOptions = ImageCapture.OutputFileOptions.Builder(photoFile).build()
|
||||||
|
isCapturing = true
|
||||||
|
cameraController.takePicture(
|
||||||
|
outputOptions,
|
||||||
|
ContextCompat.getMainExecutor(context),
|
||||||
|
object : ImageCapture.OnImageSavedCallback {
|
||||||
|
override fun onImageSaved(outputFileResults: ImageCapture.OutputFileResults) {
|
||||||
|
isCapturing = false
|
||||||
|
cameraError = null
|
||||||
|
capturedCount += 1
|
||||||
|
pendingUploads += 1
|
||||||
|
coroutineScope.launch {
|
||||||
|
try {
|
||||||
|
currentOnPhotoCaptured(cameraFileUri(context, photoFile))
|
||||||
|
} finally {
|
||||||
|
pendingUploads = (pendingUploads - 1).coerceAtLeast(0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onError(exception: ImageCaptureException) {
|
||||||
|
isCapturing = false
|
||||||
|
photoFile.delete()
|
||||||
|
cameraError = "Nie udało się zapisać zdjęcia. Spróbuj ponownie."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
},
|
||||||
|
enabled = !isCapturing && !cameraUnavailable,
|
||||||
|
modifier = Modifier
|
||||||
|
.align(Alignment.Center)
|
||||||
|
.size(72.dp),
|
||||||
|
shape = CircleShape,
|
||||||
|
colors = ButtonDefaults.buttonColors(
|
||||||
|
containerColor = Color.White,
|
||||||
|
disabledContainerColor = Color.White.copy(alpha = 0.55f),
|
||||||
|
),
|
||||||
|
contentPadding = ButtonDefaults.ContentPadding,
|
||||||
|
) {
|
||||||
|
if (isCapturing) {
|
||||||
|
CircularProgressIndicator(
|
||||||
|
modifier = Modifier.size(28.dp),
|
||||||
|
color = TppTheme.colors.forest,
|
||||||
|
strokeWidth = 3.dp,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
Icon(
|
||||||
|
Icons.Outlined.CameraAlt,
|
||||||
|
contentDescription = "Zrób zdjęcie",
|
||||||
|
tint = TppTheme.colors.forest,
|
||||||
|
modifier = Modifier.size(32.dp),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Button(
|
||||||
|
onClick = onClose,
|
||||||
|
enabled = !isCapturing && pendingUploads == 0,
|
||||||
|
modifier = Modifier
|
||||||
|
.align(Alignment.CenterEnd)
|
||||||
|
.width(104.dp)
|
||||||
|
.height(52.dp),
|
||||||
|
colors = ButtonDefaults.buttonColors(
|
||||||
|
containerColor = TppTheme.colors.forest,
|
||||||
|
),
|
||||||
|
shape = RoundedCornerShape(6.dp),
|
||||||
|
contentPadding = PaddingValues(horizontal = 8.dp, vertical = 6.dp),
|
||||||
|
) {
|
||||||
|
if (pendingUploads > 0) {
|
||||||
|
CircularProgressIndicator(
|
||||||
|
modifier = Modifier.size(16.dp),
|
||||||
|
color = Color.White,
|
||||||
|
strokeWidth = 2.dp,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
Icon(
|
||||||
|
Icons.Outlined.CheckCircle,
|
||||||
|
contentDescription = null,
|
||||||
|
tint = Color.White,
|
||||||
|
modifier = Modifier.size(18.dp),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Text(
|
||||||
|
text = if (pendingUploads > 0) "Zapisuję" else "Gotowe",
|
||||||
|
color = Color.White,
|
||||||
|
style = MaterialTheme.typography.labelMedium,
|
||||||
|
maxLines = 1,
|
||||||
|
softWrap = false,
|
||||||
|
overflow = TextOverflow.Clip,
|
||||||
|
modifier = Modifier.padding(start = 4.dp),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun createMultipleCameraFile(context: Context): File {
|
||||||
|
val directory = File(context.cacheDir, "camera").apply { mkdirs() }
|
||||||
|
return File.createTempFile("ladunek-", ".jpg", directory)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun cameraFileUri(context: Context, file: File): Uri =
|
||||||
|
FileProvider.getUriForFile(context, "${context.packageName}.fileprovider", file)
|
||||||
+20
@@ -0,0 +1,20 @@
|
|||||||
|
package pl.firmatpp.kierowca.sync
|
||||||
|
|
||||||
|
import org.junit.Assert.assertEquals
|
||||||
|
import org.junit.Test
|
||||||
|
|
||||||
|
class PublishedRoutesNotificationFormatterTest {
|
||||||
|
@Test
|
||||||
|
fun formatsPublicationWithPolishWeekdayAndUnambiguousDate() {
|
||||||
|
assertEquals("Opublikowano twoje kursy na poniedziałek (28.09.2026).", PublishedRoutesNotificationFormatter.text("2026-09-28"))
|
||||||
|
assertEquals("Opublikowano twoje kursy na środę (30.09.2026).", PublishedRoutesNotificationFormatter.text("2026-09-30"))
|
||||||
|
assertEquals("Opublikowano twoje kursy na niedzielę (04.10.2026).", PublishedRoutesNotificationFormatter.text("2026-10-04"))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun handlesMissingAndInvalidDates() {
|
||||||
|
val fallback = "Opublikowano twoje kursy. Otwórz aplikację, aby je zobaczyć."
|
||||||
|
assertEquals(fallback, PublishedRoutesNotificationFormatter.text(null))
|
||||||
|
assertEquals(fallback, PublishedRoutesNotificationFormatter.text("invalid"))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package pl.firmatpp.kierowca.ui
|
||||||
|
|
||||||
|
import org.junit.Assert.assertFalse
|
||||||
|
import org.junit.Assert.assertTrue
|
||||||
|
import org.junit.Test
|
||||||
|
import pl.firmatpp.kierowca.data.model.DriverRouteDto
|
||||||
|
|
||||||
|
class DriverDayPublicationUiRulesTest {
|
||||||
|
private val route = DriverRouteDto(
|
||||||
|
id = "42", routeDate = "2026-09-28", unloadingDate = "2026-09-30",
|
||||||
|
startsAt = "09:00", originName = "Baza", destinationName = "Zakład",
|
||||||
|
contractorName = "Kontrahent", contractName = null, contractCode = null, relationLabel = "Baza → Zakład",
|
||||||
|
status = "ZAPLANOWANA", distanceKm = 20.0, notes = null, truck = null,
|
||||||
|
)
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun hidingAnyScheduledDayCanInvalidateOpenDetails() {
|
||||||
|
assertTrue(routeIncludesPublicationDate(route, "2026-09-28"))
|
||||||
|
assertTrue(routeIncludesPublicationDate(route, "2026-09-29"))
|
||||||
|
assertTrue(routeIncludesPublicationDate(route, "2026-09-30"))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun unrelatedOrInvalidDatesMustNotCloseTheOpenRoute() {
|
||||||
|
assertFalse(routeIncludesPublicationDate(route, "2026-09-27"))
|
||||||
|
assertFalse(routeIncludesPublicationDate(route, "2026-10-01"))
|
||||||
|
assertFalse(routeIncludesPublicationDate(route, "invalid"))
|
||||||
|
assertFalse(routeIncludesPublicationDate(null, "2026-09-28"))
|
||||||
|
assertFalse(routeIncludesPublicationDate(route, null))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun singleDayRoutesDoNotInheritTheNextDaysPublication() {
|
||||||
|
val singleDay = route.copy(unloadingDate = null)
|
||||||
|
assertTrue(routeIncludesPublicationDate(singleDay, "2026-09-28"))
|
||||||
|
assertFalse(routeIncludesPublicationDate(singleDay, "2026-09-29"))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,6 +6,10 @@ import org.junit.Assert.assertFalse
|
|||||||
import org.junit.Assert.assertTrue
|
import org.junit.Assert.assertTrue
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import pl.firmatpp.kierowca.data.model.DriverRouteDto
|
import pl.firmatpp.kierowca.data.model.DriverRouteDto
|
||||||
|
import pl.firmatpp.kierowca.data.model.DriverRouteStageWorkflowDto
|
||||||
|
import pl.firmatpp.kierowca.data.model.DriverRouteWorkflowDocumentDto
|
||||||
|
import pl.firmatpp.kierowca.data.model.DriverRouteWorkflowDto
|
||||||
|
import pl.firmatpp.kierowca.data.model.DriverRouteWorkflowStepDto
|
||||||
import pl.firmatpp.kierowca.data.model.DispatchSheetReminderDto
|
import pl.firmatpp.kierowca.data.model.DispatchSheetReminderDto
|
||||||
import pl.firmatpp.kierowca.data.model.RoutePhotoDto
|
import pl.firmatpp.kierowca.data.model.RoutePhotoDto
|
||||||
import pl.firmatpp.kierowca.data.model.TachographReminderDto
|
import pl.firmatpp.kierowca.data.model.TachographReminderDto
|
||||||
@@ -18,6 +22,52 @@ import pl.firmatpp.kierowca.data.upload.RouteActionType
|
|||||||
class DriverUiRulesTest {
|
class DriverUiRulesTest {
|
||||||
private val today = LocalDate.parse("2026-06-30")
|
private val today = LocalDate.parse("2026-06-30")
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun customWorkflowBlocksUntilConfirmationAndRequiredDocumentArePresent() {
|
||||||
|
val workflow = DriverRouteWorkflowDto(
|
||||||
|
version = "workflow-v1",
|
||||||
|
customized = true,
|
||||||
|
loading = DriverRouteStageWorkflowDto(
|
||||||
|
steps = listOf(
|
||||||
|
DriverRouteWorkflowStepDto(
|
||||||
|
id = "secure-load",
|
||||||
|
type = RouteWorkflowStepType.Confirmation,
|
||||||
|
title = "Sprawdź zabezpieczenie ładunku",
|
||||||
|
requirement = RouteStageRequirement.Required,
|
||||||
|
documents = listOf(
|
||||||
|
DriverRouteWorkflowDocumentDto(
|
||||||
|
id = "cmr",
|
||||||
|
label = "List przewozowy CMR",
|
||||||
|
requirement = RouteStageRequirement.Required,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
unloading = DriverRouteStageWorkflowDto(),
|
||||||
|
)
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
"Potwierdź krok: Sprawdź zabezpieczenie ładunku.",
|
||||||
|
routeWorkflowSubmitBlocker(workflow, "loading", emptySet(), "", emptyList(), emptyList()),
|
||||||
|
)
|
||||||
|
assertEquals(
|
||||||
|
"Dodaj dokument „List przewozowy CMR” w kroku „Sprawdź zabezpieczenie ładunku”.",
|
||||||
|
routeWorkflowSubmitBlocker(workflow, "loading", setOf("secure-load"), "", emptyList(), emptyList()),
|
||||||
|
)
|
||||||
|
assertEquals(
|
||||||
|
null,
|
||||||
|
routeWorkflowSubmitBlocker(
|
||||||
|
workflow,
|
||||||
|
"loading",
|
||||||
|
setOf("secure-load"),
|
||||||
|
"",
|
||||||
|
listOf(photo("cmr-photo", "loading").copy(workflowStepId = "secure-load", workflowDocumentId = "cmr")),
|
||||||
|
emptyList(),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun disabledRouteLocationNeverStartsTracking() {
|
fun disabledRouteLocationNeverStartsTracking() {
|
||||||
assertFalse(shouldTrackRouteLocation(RouteLocationMode.Disabled, optionalLocationEnabled = true, hasLocationPermission = true))
|
assertFalse(shouldTrackRouteLocation(RouteLocationMode.Disabled, optionalLocationEnabled = true, hasLocationPermission = true))
|
||||||
|
|||||||
Reference in New Issue
Block a user