feat(android-terminal): Phase E — offline queue + sync
Some checks failed
Some checks failed
Stamp / earn / enroll actions performed without connectivity now persist in the existing pending_transactions Room table and drain via a SyncWorker as soon as the network constraint is satisfied. Redemption stays online-only (server needs the authoritative balance — queueing would let cashiers redeem rewards customers have already spent). Pieces: - Hilt-Work plumbing: androidx.hilt:hilt-compiler KSP processor wired, RewardFlowApp now implements Configuration.Provider with the injected HiltWorkerFactory, AndroidManifest disables the WorkManager auto-init via the AndroidX startup tools:node="remove" pattern. Bumped Dagger to 2.55 so its compiler can read Kotlin 2.1 metadata — 2.51 crashed with "Unable to read Kotlin metadata due to unsupported metadata version" once we added @Inject lateinit var on the Application class. - data/sync/SyncWorker.kt — @HiltWorker CoroutineWorker that drains the queue FIFO. Per row: HTTP error → permanent markFailed; IOException → Result.retry(); success → markSynced + sweep at end of run. - data/repository/QueueRepository.kt — single entrypoint for "queue this offline action". queueStamp / queuePointsEarn / queueEnroll Moshi-serialize the request body and enqueueUniqueWork(KEEP) the worker under a NetworkType.CONNECTED constraint with 30s exponential backoff. scheduleSync() is idempotent. - TerminalViewModel: runAction(block, queueOnNetworkFailure) — on IOException AND a queue lambda is provided, queue + emit ActionResult.Queued. HttpException paths still surface the server's message inline. Stamp / Earn / Enroll go through the queue path; redeem actions pass null. setStaffPinId records who initiated each queued row. init schedules a sync so anything left from a previous session drains on screen entry. pendingSyncCount is combined into state via Flow<Int> from the DAO; when it drops to 0 we refresh the recent-transactions feed so the UI shows what just synced. - TerminalScreen: PendingSyncPill in the top bar (only visible when count > 0) gives the cashier feedback that a queued action is waiting + that the queue is draining live. Cleartext + readable HTTP errors from yesterday remain in. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -34,7 +34,11 @@ room = "2.6.1"
|
||||
workManager = "2.10.0"
|
||||
|
||||
# Dependency Injection
|
||||
hilt = "2.51.1"
|
||||
# Dagger 2.55 added support for Kotlin 2.1 metadata. Older versions
|
||||
# (2.51 and below) crash when Dagger validates @Inject fields on classes
|
||||
# compiled by the Kotlin 2.1 toolchain — surfaces as
|
||||
# "Unable to read Kotlin metadata due to unsupported metadata version".
|
||||
hilt = "2.55"
|
||||
hiltNavigationCompose = "1.2.0"
|
||||
|
||||
# Camera & QR scanning
|
||||
@@ -92,6 +96,10 @@ hilt-android = { group = "com.google.dagger", name = "hilt-android", version.ref
|
||||
hilt-compiler = { group = "com.google.dagger", name = "hilt-android-compiler", version.ref = "hilt" }
|
||||
hilt-navigation-compose = { group = "androidx.hilt", name = "hilt-navigation-compose", version.ref = "hiltNavigationCompose" }
|
||||
hilt-work = { group = "androidx.hilt", name = "hilt-work", version.ref = "hiltNavigationCompose" }
|
||||
# Annotation processor for @HiltWorker — separate from the Dagger compiler
|
||||
# above. Generates the WorkerFactory binding so workers get constructor
|
||||
# injection like every other @Inject class.
|
||||
androidx-hilt-compiler = { group = "androidx.hilt", name = "hilt-compiler", version.ref = "hiltNavigationCompose" }
|
||||
|
||||
# CameraX (QR scanning)
|
||||
camera-core = { group = "androidx.camera", name = "camera-core", version.ref = "cameraX" }
|
||||
|
||||
Reference in New Issue
Block a user