Implement offline sync with WorkManager and DataStore for Android
Summary
Comprehensive offline sync service using Android best practices with WorkManager and DataStore
Changes
- Added
OfflineSyncService.ktwith full offline sync implementation (539 lines) - Auto-sync on network connection (ConnectivityManager)
- Periodic WorkManager background sync (15 min intervals)
- Sync queue with exponential backoff retry
- DataStore Preferences for fast persistence
- StateFlow for reactive UI updates
- Conflict detection and resolution
Architecture
- WorkManager: Reliable background work with constraints
- DataStore: Modern replacement for SharedPreferences
- ConnectivityManager: Network state monitoring with callbacks
- StateFlow: Reactive sync status updates for Compose UI
- Coroutines: Structured concurrency for async operations
Data Synchronized
- User profile from user-service (java-microservices)
- Recent content from content-service (java-microservices)
- User favorites
- Pending operations queue
Conflict Resolution Strategies
- LOCAL_WINS: Force local changes
- REMOTE_WINS: Accept remote state
- MERGE: Attempt automatic merge
- USER_CHOICE: Prompt user for decision
Integration Points
- Depends on user-service from java-microservices group
- Depends on content-service from java-microservices group
- SyncWorker for WorkManager background execution
Testing
-
Network state transitions (WiFi/cellular/offline) -
WorkManager periodic sync execution -
DataStore persistence across app restarts -
Conflict resolution all strategies -
Manual sync (pull-to-refresh) -
Background sync constraints
Related Issues
Closes #3 (closed)
Cross-group dependencies
- Depends on user-service (java-microservices group)
- Depends on content-service (java-microservices group)
- Coordinates with ios-app (mobile-section