Fix driver route crash on null photos
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package pl.firmatpp.kierowca.ui
|
||||
|
||||
import pl.firmatpp.kierowca.data.model.DriverRouteDto
|
||||
import pl.firmatpp.kierowca.data.model.RoutePhotoDto
|
||||
import pl.firmatpp.kierowca.data.upload.RouteActionEntity
|
||||
import pl.firmatpp.kierowca.data.upload.RouteActionStatus
|
||||
import pl.firmatpp.kierowca.data.upload.RouteActionType
|
||||
@@ -41,6 +42,7 @@ fun projectDriverRoute(route: DriverRouteDto, actions: List<RouteActionEntity>):
|
||||
status = "W TRAKCIE",
|
||||
loadingWeight = action.weight,
|
||||
trackingStatus = "active",
|
||||
photos = projectedRoute.safePhotos(),
|
||||
)
|
||||
loadingWeightPending = action.status != RouteActionStatus.Confirmed
|
||||
}
|
||||
@@ -50,6 +52,7 @@ fun projectDriverRoute(route: DriverRouteDto, actions: List<RouteActionEntity>):
|
||||
unloadingWeight = action.weight,
|
||||
trackingStatus = "finished",
|
||||
completedAt = action.occurredAt,
|
||||
photos = projectedRoute.safePhotos(),
|
||||
)
|
||||
unloadingWeightPending = action.status != RouteActionStatus.Confirmed
|
||||
}
|
||||
@@ -71,3 +74,5 @@ fun projectDriverRoutes(routes: List<DriverRouteDto>, actions: List<RouteActionE
|
||||
|
||||
fun routeActionNeedsAttention(status: String): Boolean =
|
||||
status == RouteActionStatus.FailedConflict || status == RouteActionStatus.FailedPermanent
|
||||
|
||||
internal fun DriverRouteDto.safePhotos(): List<RoutePhotoDto> = photos.orEmpty()
|
||||
|
||||
@@ -151,9 +151,9 @@ fun routeFlowSteps(route: DriverRouteDto, actions: List<RouteActionEntity>): Lis
|
||||
)
|
||||
}
|
||||
|
||||
fun routePhotosForStage(photos: List<RoutePhotoDto>, stage: String): List<RoutePhotoDto> {
|
||||
fun routePhotosForStage(photos: List<RoutePhotoDto>?, stage: String): List<RoutePhotoDto> {
|
||||
val normalized = normalizedRoutePhotoStage(stage)
|
||||
return photos.filter { normalizedRoutePhotoStage(it.stage) == normalized }
|
||||
return photos.orEmpty().filter { normalizedRoutePhotoStage(it.stage) == normalized }
|
||||
}
|
||||
|
||||
fun normalizedRoutePhotoStage(stage: String?): String =
|
||||
|
||||
@@ -617,6 +617,7 @@ class DriverViewModel(application: Application) : AndroidViewModel(application)
|
||||
status = "W TRAKCIE",
|
||||
loadingWeight = weight,
|
||||
trackingStatus = "active",
|
||||
photos = route.safePhotos(),
|
||||
)
|
||||
}
|
||||
"unloading" -> {
|
||||
@@ -626,6 +627,7 @@ class DriverViewModel(application: Application) : AndroidViewModel(application)
|
||||
unloadingWeight = weight,
|
||||
trackingStatus = "finished",
|
||||
completedAt = Instant.now().toString(),
|
||||
photos = route.safePhotos(),
|
||||
)
|
||||
}
|
||||
else -> route
|
||||
|
||||
Reference in New Issue
Block a user