Guidance on implementing the Data Layer using Repository pattern, Room (Local), and Retrofit (Remote) with offline-first synchronization.
Android Data Layer & Offline-First
Instructions
The Data Layer coordinates data from multiple sources.
1. Repository Pattern
Role: Single Source of Truth (SSOT).
Logic: The repository decides whether to return cached data or fetch fresh data.
Implementation:
class NewsRepository @Inject constructor(
private val newsDao: NewsDao,
private val newsApi: NewsApi
) {
// Expose data from Local DB as the source of truth
val newsStream: Flow<List<News>> = newsDao.getAllNews()don't have the plugin yet? install it then click "run inline in claude" again.
by @affaan-m