Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
32d45f6430 | ||
|
|
4a06e9da8b |
@@ -34,8 +34,8 @@ android {
|
||||
applicationId = "pl.firmatpp.kierowca"
|
||||
minSdk = 26
|
||||
targetSdk = 35
|
||||
versionCode = 50
|
||||
versionName = "1.0.44"
|
||||
versionCode = 51
|
||||
versionName = "1.0.45"
|
||||
setProperty("archivesBaseName", "pl.firmatpp.kierowca")
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
|
||||
|
||||
@@ -14,7 +14,10 @@ class PhotoUploadWorker(
|
||||
appContext: Context,
|
||||
params: WorkerParameters,
|
||||
) : CoroutineWorker(appContext, params) {
|
||||
private val dao = DriverDatabase.get(appContext).photoUploadDao()
|
||||
private val database = DriverDatabase.get(appContext)
|
||||
private val dao = database.photoUploadDao()
|
||||
private val routeActionDao = database.routeActionDao()
|
||||
private val routeActionOutbox = RouteActionOutbox(appContext)
|
||||
private val repository = DriverRepository(appContext)
|
||||
|
||||
override suspend fun doWork(): Result {
|
||||
@@ -62,6 +65,7 @@ class PhotoUploadWorker(
|
||||
}
|
||||
|
||||
dao.markConfirmed(clientRequestId, receipt.serverPhotoId)
|
||||
enqueueRouteActionsWaitingForPhoto(clientRequestId)
|
||||
Result.success()
|
||||
}.getOrElse { throwable ->
|
||||
val error = ApiErrorMapper.map(throwable)
|
||||
@@ -90,6 +94,12 @@ class PhotoUploadWorker(
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun enqueueRouteActionsWaitingForPhoto(clientRequestId: String) {
|
||||
routeActionDao.waitingForPhotosActions()
|
||||
.filter { routeActionReferencesPhotoClientRequest(it, clientRequestId) }
|
||||
.forEach { routeActionOutbox.enqueueWorker(it.clientActionId) }
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val KEY_CLIENT_REQUEST_ID = "clientRequestId"
|
||||
const val KEY_PROGRESS = "progress"
|
||||
|
||||
@@ -14,6 +14,9 @@ interface RouteActionDao {
|
||||
@Query("SELECT * FROM route_actions WHERE clientActionId = :clientActionId LIMIT 1")
|
||||
suspend fun find(clientActionId: String): RouteActionEntity?
|
||||
|
||||
@Query("SELECT * FROM route_actions WHERE status = 'WAITING_FOR_PHOTOS'")
|
||||
suspend fun waitingForPhotosActions(): List<RouteActionEntity>
|
||||
|
||||
@Query(
|
||||
"""
|
||||
SELECT * FROM route_actions
|
||||
|
||||
@@ -53,7 +53,7 @@ class RouteActionOutbox(
|
||||
return entity
|
||||
}
|
||||
|
||||
private fun enqueueWorker(clientActionId: String) {
|
||||
fun enqueueWorker(clientActionId: String) {
|
||||
val request = OneTimeWorkRequestBuilder<RouteActionWorker>()
|
||||
.setInputData(workDataOf(RouteActionWorker.KEY_CLIENT_ACTION_ID to clientActionId))
|
||||
.setConstraints(Constraints.Builder().setRequiredNetworkType(NetworkType.CONNECTED).build())
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package pl.firmatpp.kierowca.data.upload
|
||||
|
||||
import com.google.gson.Gson
|
||||
|
||||
private val routeActionPhotoDependencyGson = Gson()
|
||||
|
||||
fun routeActionReferencesPhotoClientRequest(action: RouteActionEntity, clientRequestId: String): Boolean {
|
||||
val needle = clientRequestId.trim()
|
||||
if (needle.isBlank()) return false
|
||||
|
||||
return runCatching {
|
||||
routeActionPhotoDependencyGson
|
||||
.fromJson(action.photoClientRequestIdsJson, Array<String>::class.java)
|
||||
?.any { it.trim() == needle }
|
||||
?: false
|
||||
}.getOrDefault(false)
|
||||
}
|
||||
@@ -114,8 +114,10 @@ fun routeSyncCallout(actions: List<RouteActionEntity>): RouteSyncCalloutUi? {
|
||||
} else {
|
||||
when (unresolved.status) {
|
||||
RouteActionStatus.WaitingForPhotos -> "Czekam na wysłanie zdjęć etapu, potem wyślę zmianę statusu."
|
||||
RouteActionStatus.Pending,
|
||||
RouteActionStatus.Syncing -> "Trwa wysyłanie zmiany statusu kursu."
|
||||
RouteActionStatus.FailedRetryable -> "Nie udało się wysłać. Aplikacja spróbuje ponownie."
|
||||
else -> "Zmiana zapisana w telefonie. Wyślemy ją po odzyskaniu internetu."
|
||||
else -> "Zmiana zapisana w telefonie. Aplikacja wyśle ją automatycznie."
|
||||
}
|
||||
},
|
||||
isConflict = isConflict,
|
||||
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package pl.firmatpp.kierowca.data.upload
|
||||
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
class RouteActionPhotoDependenciesTest {
|
||||
@Test
|
||||
fun detectsRouteActionWaitingForConfirmedPhotoClientRequest() {
|
||||
val action = action("""["photo-a","photo-b"]""")
|
||||
|
||||
assertTrue(routeActionReferencesPhotoClientRequest(action, "photo-b"))
|
||||
assertFalse(routeActionReferencesPhotoClientRequest(action, "photo-c"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun malformedPhotoRequestJsonDoesNotMatch() {
|
||||
assertFalse(routeActionReferencesPhotoClientRequest(action("not-json"), "photo-a"))
|
||||
}
|
||||
|
||||
private fun action(photoClientRequestIdsJson: String): RouteActionEntity =
|
||||
RouteActionEntity(
|
||||
clientActionId = "action-1",
|
||||
routeId = "route-1",
|
||||
action = RouteActionType.Start,
|
||||
weight = 12.5,
|
||||
occurredAt = "2026-06-30T07:40:00Z",
|
||||
photoClientRequestIdsJson = photoClientRequestIdsJson,
|
||||
status = RouteActionStatus.WaitingForPhotos,
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user