Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
541dda292f |
@@ -33,8 +33,8 @@ android {
|
|||||||
applicationId = "pl.firmatpp.kierowca"
|
applicationId = "pl.firmatpp.kierowca"
|
||||||
minSdk = 26
|
minSdk = 26
|
||||||
targetSdk = 35
|
targetSdk = 35
|
||||||
versionCode = 28
|
versionCode = 29
|
||||||
versionName = "1.0.27"
|
versionName = "1.0.28"
|
||||||
setProperty("archivesBaseName", "pl.firmatpp.kierowca")
|
setProperty("archivesBaseName", "pl.firmatpp.kierowca")
|
||||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ data class ApiError(
|
|||||||
val retryable: Boolean,
|
val retryable: Boolean,
|
||||||
val code: String? = null,
|
val code: String? = null,
|
||||||
val statusCode: Int? = null,
|
val statusCode: Int? = null,
|
||||||
|
val responseBody: String? = null,
|
||||||
)
|
)
|
||||||
|
|
||||||
object ApiErrorMapper {
|
object ApiErrorMapper {
|
||||||
@@ -48,10 +49,17 @@ object ApiErrorMapper {
|
|||||||
code = code,
|
code = code,
|
||||||
message = message,
|
message = message,
|
||||||
retryable = retryable,
|
retryable = retryable,
|
||||||
|
responseBody = body,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun mapProblem(statusCode: Int, code: String?, message: String?, retryable: Boolean?): ApiError {
|
fun mapProblem(
|
||||||
|
statusCode: Int,
|
||||||
|
code: String?,
|
||||||
|
message: String?,
|
||||||
|
retryable: Boolean?,
|
||||||
|
responseBody: String? = null,
|
||||||
|
): ApiError {
|
||||||
val kind = when (statusCode) {
|
val kind = when (statusCode) {
|
||||||
401 -> ApiErrorKind.Auth
|
401 -> ApiErrorKind.Auth
|
||||||
403 -> ApiErrorKind.Forbidden
|
403 -> ApiErrorKind.Forbidden
|
||||||
@@ -80,6 +88,7 @@ object ApiErrorMapper {
|
|||||||
retryable = resolvedRetryable,
|
retryable = resolvedRetryable,
|
||||||
code = code,
|
code = code,
|
||||||
statusCode = statusCode,
|
statusCode = statusCode,
|
||||||
|
responseBody = responseBody,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package pl.firmatpp.kierowca.data.upload
|
||||||
|
|
||||||
|
import pl.firmatpp.kierowca.data.ApiError
|
||||||
|
import pl.firmatpp.kierowca.data.ApiErrorKind
|
||||||
|
|
||||||
|
object PhotoUploadFailureDetails {
|
||||||
|
fun fromApiError(error: ApiError): String {
|
||||||
|
val type = when (error.kind) {
|
||||||
|
ApiErrorKind.Network -> "błąd komunikacji"
|
||||||
|
ApiErrorKind.Server,
|
||||||
|
ApiErrorKind.RateLimited,
|
||||||
|
ApiErrorKind.Validation,
|
||||||
|
ApiErrorKind.Forbidden,
|
||||||
|
ApiErrorKind.Auth,
|
||||||
|
ApiErrorKind.Conflict,
|
||||||
|
-> "błąd serwera"
|
||||||
|
ApiErrorKind.Unknown -> "błąd aplikacji"
|
||||||
|
}
|
||||||
|
|
||||||
|
return buildString {
|
||||||
|
appendLine("Typ: $type")
|
||||||
|
appendLine("Komunikat: ${error.message}")
|
||||||
|
error.statusCode?.let { appendLine("HTTP: $it") }
|
||||||
|
error.code?.takeIf { it.isNotBlank() }?.let { appendLine("Kod: $it") }
|
||||||
|
error.responseBody
|
||||||
|
?.takeIf { it.isNotBlank() }
|
||||||
|
?.let {
|
||||||
|
appendLine("Odpowiedź serwera:")
|
||||||
|
append(it.take(MAX_RESPONSE_CHARS))
|
||||||
|
if (it.length > MAX_RESPONSE_CHARS) append("...")
|
||||||
|
}
|
||||||
|
}.trim()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun local(message: String): String =
|
||||||
|
"Typ: błąd aplikacji\nKomunikat: $message"
|
||||||
|
|
||||||
|
private const val MAX_RESPONSE_CHARS = 1200
|
||||||
|
}
|
||||||
@@ -22,11 +22,12 @@ class PhotoUploadWorker(
|
|||||||
val file = File(upload.localPath)
|
val file = File(upload.localPath)
|
||||||
|
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
|
val message = "Lokalny plik zdjęcia nie istnieje. Zdjęcie nie zostało zapisane."
|
||||||
dao.updateStatus(
|
dao.updateStatus(
|
||||||
clientRequestId = clientRequestId,
|
clientRequestId = clientRequestId,
|
||||||
status = PhotoUploadStatus.FailedPermanent.storageValue,
|
status = PhotoUploadStatus.FailedPermanent.storageValue,
|
||||||
progress = 0,
|
progress = 0,
|
||||||
lastError = "Lokalny plik zdjęcia nie istnieje. Zdjęcie nie zostało zapisane.",
|
lastError = PhotoUploadFailureDetails.local(message),
|
||||||
attemptIncrement = 0,
|
attemptIncrement = 0,
|
||||||
)
|
)
|
||||||
return Result.failure()
|
return Result.failure()
|
||||||
@@ -68,7 +69,7 @@ class PhotoUploadWorker(
|
|||||||
clientRequestId = clientRequestId,
|
clientRequestId = clientRequestId,
|
||||||
status = status.storageValue,
|
status = status.storageValue,
|
||||||
progress = 0,
|
progress = 0,
|
||||||
lastError = error.message,
|
lastError = PhotoUploadFailureDetails.fromApiError(error),
|
||||||
attemptIncrement = 0,
|
attemptIncrement = 0,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ import androidx.compose.material.icons.outlined.CheckCircle
|
|||||||
import androidx.compose.material.icons.outlined.CloudUpload
|
import androidx.compose.material.icons.outlined.CloudUpload
|
||||||
import androidx.compose.material.icons.outlined.Factory
|
import androidx.compose.material.icons.outlined.Factory
|
||||||
import androidx.compose.material.icons.outlined.Delete
|
import androidx.compose.material.icons.outlined.Delete
|
||||||
|
import androidx.compose.material.icons.outlined.Info
|
||||||
import androidx.compose.material.icons.outlined.LocationOn
|
import androidx.compose.material.icons.outlined.LocationOn
|
||||||
import androidx.compose.material.icons.outlined.LocalShipping
|
import androidx.compose.material.icons.outlined.LocalShipping
|
||||||
import androidx.compose.material.icons.outlined.Navigation
|
import androidx.compose.material.icons.outlined.Navigation
|
||||||
@@ -612,6 +613,8 @@ private fun PhotoQueueScreen(
|
|||||||
@Composable
|
@Composable
|
||||||
private fun PhotoQueueItem(upload: PhotoUploadEntity, onRetryUpload: (PhotoUploadEntity) -> Unit) {
|
private fun PhotoQueueItem(upload: PhotoUploadEntity, onRetryUpload: (PhotoUploadEntity) -> Unit) {
|
||||||
val status = upload.statusType
|
val status = upload.statusType
|
||||||
|
val hasFailureDetails = canShowPhotoUploadFailureDetails(upload.status, upload.lastError)
|
||||||
|
var showFailureDetails by remember { mutableStateOf(false) }
|
||||||
Card(
|
Card(
|
||||||
colors = CardDefaults.cardColors(containerColor = Color.White),
|
colors = CardDefaults.cardColors(containerColor = Color.White),
|
||||||
border = BorderStroke(1.dp, TppColors.Outline),
|
border = BorderStroke(1.dp, TppColors.Outline),
|
||||||
@@ -632,8 +635,8 @@ private fun PhotoQueueItem(upload: PhotoUploadEntity, onRetryUpload: (PhotoUploa
|
|||||||
Column(Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(6.dp)) {
|
Column(Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(6.dp)) {
|
||||||
Text("Kurs #${upload.routeId}", color = TppColors.Ink, fontWeight = FontWeight.Bold)
|
Text("Kurs #${upload.routeId}", color = TppColors.Ink, fontWeight = FontWeight.Bold)
|
||||||
Text(
|
Text(
|
||||||
upload.lastError?.takeIf { status == PhotoUploadStatus.FailedPermanent } ?: status.label,
|
upload.lastError?.lineSequence()?.firstOrNull { it.isNotBlank() }?.takeIf { hasFailureDetails } ?: status.label,
|
||||||
color = if (status == PhotoUploadStatus.FailedPermanent) TppColors.Error else TppColors.Muted,
|
color = if (hasFailureDetails) TppColors.Error else TppColors.Muted,
|
||||||
fontFamily = FontFamily.Monospace,
|
fontFamily = FontFamily.Monospace,
|
||||||
style = MaterialTheme.typography.labelMedium,
|
style = MaterialTheme.typography.labelMedium,
|
||||||
)
|
)
|
||||||
@@ -646,25 +649,75 @@ private fun PhotoQueueItem(upload: PhotoUploadEntity, onRetryUpload: (PhotoUploa
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (canRetryPhotoUpload(upload.status)) {
|
if (hasFailureDetails || canRetryPhotoUpload(upload.status)) {
|
||||||
Button(
|
Row(horizontalArrangement = Arrangement.spacedBy(4.dp), verticalAlignment = Alignment.CenterVertically) {
|
||||||
onClick = { onRetryUpload(upload) },
|
if (hasFailureDetails) {
|
||||||
colors = ButtonDefaults.buttonColors(containerColor = TppColors.Forest),
|
IconButton(
|
||||||
shape = RoundedCornerShape(4.dp),
|
onClick = { showFailureDetails = true },
|
||||||
contentPadding = PaddingValues(horizontal = 12.dp, vertical = 8.dp),
|
modifier = Modifier
|
||||||
) {
|
.size(40.dp)
|
||||||
Icon(
|
.background(TppColors.Surface, RoundedCornerShape(20.dp))
|
||||||
Icons.Outlined.Refresh,
|
.border(1.dp, TppColors.Error.copy(alpha = 0.35f), RoundedCornerShape(20.dp)),
|
||||||
contentDescription = null,
|
) {
|
||||||
tint = Color.White,
|
Icon(
|
||||||
modifier = Modifier.size(18.dp),
|
Icons.Outlined.Info,
|
||||||
)
|
contentDescription = "Pokaż szczegóły błędu",
|
||||||
Spacer(Modifier.width(6.dp))
|
tint = TppColors.Error,
|
||||||
Text("Ponów", color = Color.White, fontWeight = FontWeight.Bold)
|
modifier = Modifier.size(20.dp),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (canRetryPhotoUpload(upload.status)) {
|
||||||
|
Button(
|
||||||
|
onClick = { onRetryUpload(upload) },
|
||||||
|
colors = ButtonDefaults.buttonColors(containerColor = TppColors.Forest),
|
||||||
|
shape = RoundedCornerShape(4.dp),
|
||||||
|
contentPadding = PaddingValues(horizontal = 12.dp, vertical = 8.dp),
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
Icons.Outlined.Refresh,
|
||||||
|
contentDescription = null,
|
||||||
|
tint = Color.White,
|
||||||
|
modifier = Modifier.size(18.dp),
|
||||||
|
)
|
||||||
|
Spacer(Modifier.width(6.dp))
|
||||||
|
Text("Ponów", color = Color.White, fontWeight = FontWeight.Bold)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (showFailureDetails) {
|
||||||
|
PhotoUploadFailureDialog(
|
||||||
|
details = upload.lastError.orEmpty(),
|
||||||
|
onDismiss = { showFailureDetails = false },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun PhotoUploadFailureDialog(details: String, onDismiss: () -> Unit) {
|
||||||
|
AlertDialog(
|
||||||
|
onDismissRequest = onDismiss,
|
||||||
|
title = {
|
||||||
|
Text("Dlaczego nie wysłano zdjęcia?", color = TppColors.Ink, fontWeight = FontWeight.Bold)
|
||||||
|
},
|
||||||
|
text = {
|
||||||
|
Text(
|
||||||
|
details,
|
||||||
|
color = TppColors.Ink,
|
||||||
|
fontFamily = FontFamily.Monospace,
|
||||||
|
style = MaterialTheme.typography.bodySmall,
|
||||||
|
modifier = Modifier.heightIn(max = 320.dp).verticalScroll(rememberScrollState()),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
confirmButton = {
|
||||||
|
TextButton(onClick = onDismiss) {
|
||||||
|
Text("Zamknij", color = TppColors.Forest, fontWeight = FontWeight.Bold)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@@ -1551,6 +1604,14 @@ private fun PendingPhotoTile(
|
|||||||
) {
|
) {
|
||||||
val status = upload.statusType
|
val status = upload.statusType
|
||||||
val canDeleteServerPhoto = confirmedUploadServerPhotoId(upload.status, upload.serverPhotoId) != null
|
val canDeleteServerPhoto = confirmedUploadServerPhotoId(upload.status, upload.serverPhotoId) != null
|
||||||
|
val hasFailureDetails = canShowPhotoUploadFailureDetails(upload.status, upload.lastError)
|
||||||
|
var showFailureDetails by remember { mutableStateOf(false) }
|
||||||
|
if (showFailureDetails) {
|
||||||
|
PhotoUploadFailureDialog(
|
||||||
|
details = upload.lastError.orEmpty(),
|
||||||
|
onDismiss = { showFailureDetails = false },
|
||||||
|
)
|
||||||
|
}
|
||||||
Box(modifier.aspectRatio(1f).background(TppColors.Panel, RoundedCornerShape(4.dp))) {
|
Box(modifier.aspectRatio(1f).background(TppColors.Panel, RoundedCornerShape(4.dp))) {
|
||||||
AsyncImage(
|
AsyncImage(
|
||||||
model = File(upload.localPath),
|
model = File(upload.localPath),
|
||||||
@@ -1586,6 +1647,25 @@ private fun PendingPhotoTile(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (hasFailureDetails) {
|
||||||
|
IconButton(
|
||||||
|
onClick = { showFailureDetails = true },
|
||||||
|
enabled = !isDeleting,
|
||||||
|
modifier = Modifier
|
||||||
|
.align(Alignment.TopStart)
|
||||||
|
.padding(8.dp)
|
||||||
|
.size(40.dp)
|
||||||
|
.background(TppColors.Surface.copy(alpha = 0.96f), RoundedCornerShape(20.dp))
|
||||||
|
.border(1.dp, TppColors.Error.copy(alpha = 0.35f), RoundedCornerShape(20.dp)),
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
Icons.Outlined.Info,
|
||||||
|
contentDescription = "Pokaż szczegóły błędu wysłania",
|
||||||
|
tint = TppColors.Error,
|
||||||
|
modifier = Modifier.size(20.dp),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
if (canRetryPhotoUpload(upload.status)) {
|
if (canRetryPhotoUpload(upload.status)) {
|
||||||
IconButton(
|
IconButton(
|
||||||
onClick = { onRetry(upload) },
|
onClick = { onRetry(upload) },
|
||||||
@@ -1610,8 +1690,8 @@ private fun PendingPhotoTile(
|
|||||||
verticalArrangement = Arrangement.spacedBy(8.dp),
|
verticalArrangement = Arrangement.spacedBy(8.dp),
|
||||||
) {
|
) {
|
||||||
Text(
|
Text(
|
||||||
upload.lastError?.takeIf { status == PhotoUploadStatus.FailedPermanent } ?: status.label,
|
upload.lastError?.lineSequence()?.firstOrNull { it.isNotBlank() }?.takeIf { hasFailureDetails } ?: status.label,
|
||||||
color = if (status == PhotoUploadStatus.FailedPermanent) TppColors.Error else TppColors.Ink,
|
color = if (hasFailureDetails) TppColors.Error else TppColors.Ink,
|
||||||
fontFamily = FontFamily.Monospace,
|
fontFamily = FontFamily.Monospace,
|
||||||
fontWeight = FontWeight.Bold,
|
fontWeight = FontWeight.Bold,
|
||||||
style = MaterialTheme.typography.labelMedium,
|
style = MaterialTheme.typography.labelMedium,
|
||||||
|
|||||||
@@ -38,6 +38,9 @@ fun confirmedUploadServerPhotoId(status: String, serverPhotoId: String?): String
|
|||||||
fun canRetryPhotoUpload(status: String): Boolean =
|
fun canRetryPhotoUpload(status: String): Boolean =
|
||||||
status == "FAILED_RETRYABLE"
|
status == "FAILED_RETRYABLE"
|
||||||
|
|
||||||
|
fun canShowPhotoUploadFailureDetails(status: String, lastError: String?): Boolean =
|
||||||
|
status in setOf("FAILED_RETRYABLE", "FAILED_PERMANENT") && !lastError.isNullOrBlank()
|
||||||
|
|
||||||
fun localUploadPreviewPhoto(upload: PhotoUploadEntity): RoutePhotoDto? {
|
fun localUploadPreviewPhoto(upload: PhotoUploadEntity): RoutePhotoDto? {
|
||||||
if (upload.localPath.isBlank()) return null
|
if (upload.localPath.isBlank()) return null
|
||||||
|
|
||||||
|
|||||||
@@ -39,4 +39,16 @@ class ApiErrorMapperTest {
|
|||||||
assertTrue(error.retryable)
|
assertTrue(error.retryable)
|
||||||
assertEquals("Serwer nie potwierdził operacji. Aplikacja spróbuje ponownie.", error.message)
|
assertEquals("Serwer nie potwierdził operacji. Aplikacja spróbuje ponownie.", error.message)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun keepsRawServerResponseForTroubleshooting() {
|
||||||
|
val body = """{"code":"PHOTO_SERVER_UNAVAILABLE","message":"Storage timeout","retryable":true}"""
|
||||||
|
val error = ApiErrorMapper.mapHttpStatus(503, body)
|
||||||
|
|
||||||
|
assertEquals(ApiErrorKind.Server, error.kind)
|
||||||
|
assertEquals(503, error.statusCode)
|
||||||
|
assertEquals("PHOTO_SERVER_UNAVAILABLE", error.code)
|
||||||
|
assertEquals("Storage timeout", error.message)
|
||||||
|
assertEquals(body, error.responseBody)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package pl.firmatpp.kierowca.data.upload
|
||||||
|
|
||||||
|
import org.junit.Assert.assertFalse
|
||||||
|
import org.junit.Assert.assertTrue
|
||||||
|
import org.junit.Test
|
||||||
|
import pl.firmatpp.kierowca.data.ApiError
|
||||||
|
import pl.firmatpp.kierowca.data.ApiErrorKind
|
||||||
|
|
||||||
|
class PhotoUploadFailureDetailsTest {
|
||||||
|
@Test
|
||||||
|
fun describesServerFailureWithStatusCodeBackendCodeAndResponseBody() {
|
||||||
|
val details = PhotoUploadFailureDetails.fromApiError(
|
||||||
|
ApiError(
|
||||||
|
kind = ApiErrorKind.Server,
|
||||||
|
message = "Storage timeout",
|
||||||
|
retryable = true,
|
||||||
|
code = "PHOTO_STORAGE_FAILED",
|
||||||
|
statusCode = 503,
|
||||||
|
responseBody = """{"code":"PHOTO_STORAGE_FAILED","message":"Storage timeout"}""",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
assertTrue(details.contains("Typ: błąd serwera"))
|
||||||
|
assertTrue(details.contains("HTTP: 503"))
|
||||||
|
assertTrue(details.contains("Kod: PHOTO_STORAGE_FAILED"))
|
||||||
|
assertTrue(details.contains("Odpowiedź serwera:"))
|
||||||
|
assertTrue(details.contains("Storage timeout"))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun describesNetworkFailureWithoutHttpStatus() {
|
||||||
|
val details = PhotoUploadFailureDetails.fromApiError(
|
||||||
|
ApiError(
|
||||||
|
kind = ApiErrorKind.Network,
|
||||||
|
message = "Nie udało się połączyć z serwerem.",
|
||||||
|
retryable = true,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
assertTrue(details.contains("Typ: błąd komunikacji"))
|
||||||
|
assertTrue(details.contains("Nie udało się połączyć z serwerem."))
|
||||||
|
assertFalse(details.contains("HTTP:"))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -111,6 +111,16 @@ class DriverUiRulesTest {
|
|||||||
assertFalse(canRetryPhotoUpload("CANCELLED"))
|
assertFalse(canRetryPhotoUpload("CANCELLED"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun showsFailureDetailsOnlyForFailedUploadsWithErrorMessage() {
|
||||||
|
assertTrue(canShowPhotoUploadFailureDetails("FAILED_RETRYABLE", "Typ: błąd serwera"))
|
||||||
|
assertTrue(canShowPhotoUploadFailureDetails("FAILED_PERMANENT", "Typ: błąd aplikacji"))
|
||||||
|
assertFalse(canShowPhotoUploadFailureDetails("FAILED_RETRYABLE", null))
|
||||||
|
assertFalse(canShowPhotoUploadFailureDetails("FAILED_RETRYABLE", ""))
|
||||||
|
assertFalse(canShowPhotoUploadFailureDetails("UPLOADING", "Typ: błąd serwera"))
|
||||||
|
assertFalse(canShowPhotoUploadFailureDetails("CONFIRMED", "Typ: błąd serwera"))
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun createsFullScreenPreviewForLocalUploadBeforeRouteRefresh() {
|
fun createsFullScreenPreviewForLocalUploadBeforeRouteRefresh() {
|
||||||
val photo = localUploadPreviewPhoto(upload(status = "CONFIRMED", serverPhotoId = "55"))
|
val photo = localUploadPreviewPhoto(upload(status = "CONFIRMED", serverPhotoId = "55"))
|
||||||
|
|||||||
Reference in New Issue
Block a user