install
source · Clone the upstream repo
git clone https://github.com/ComeOnOliver/skillshub
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ComeOnOliver/skillshub "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/new-silvermoon/awesome-android-agent-skills/android-data-layer" ~/.claude/skills/comeonoliver-skillshub-android-data-layer && rm -rf "$T"
manifest:
skills/new-silvermoon/awesome-android-agent-skills/android-data-layer/SKILL.mdsource content
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() // Sync operation suspend fun refreshNews() { val remoteNews = newsApi.fetchLatest() newsDao.insertAll(remoteNews) } }
2. Local Persistence (Room)
- Usage: Primary cache and offline storage.
- Entities: Define
data classes.@Entity - DAOs: Return
for observable data.Flow<T>
3. Remote Data (Retrofit)
- Usage: Fetching data from backend.
- Response: Use
functions in interfaces.suspend - Error Handling: Wrap network calls in
blocks or atry-catch
wrapper to handle exceptions (NoInternet, 404, etc.) gracefully.Result
4. Synchronization
- Read: "Stale-While-Revalidate". Show local data immediately, trigger a background refresh.
- Write: "Outbox Pattern" (Advanced). Save local change immediately, mark as "unsynced", use
to push changes to server.WorkManager
5. Dependency Injection
- Bind Repository interfaces to implementations in a Hilt Module.
@Binds abstract fun bindNewsRepository(impl: OfflineFirstNewsRepository): NewsRepository