Skip to content

feat: Add cloud sync integration#803

Closed
muava12 wants to merge 1 commit intoCrustack:mainfrom
muava12:sync-server
Closed

feat: Add cloud sync integration#803
muava12 wants to merge 1 commit intoCrustack:mainfrom
muava12:sync-server

Conversation

@muava12
Copy link
Copy Markdown

@muava12 muava12 commented Jan 26, 2026

  • Add Retrofit dependencies for API communication
  • Create NotallyApi interface for sync endpoints
  • Implement SyncWorker for background synchronization
  • Add Cloud Sync section in Settings with Backend URL input
  • Add preferences for backendUrl and lastSync timestamp
  • Integrate WorkManager for scheduling sync tasks
  • Map data models between Room entities and API DTOs

Summary by CodeRabbit

  • New Features
    • Added cloud synchronization feature allowing users to configure a backend server URL and manually sync notes.

✏️ Tip: You can customize this high-level summary in your review settings.

- Add Retrofit dependencies for API communication
- Create NotallyApi interface for sync endpoints
- Implement SyncWorker for background synchronization
- Add Cloud Sync section in Settings with Backend URL input
- Add preferences for backendUrl and lastSync timestamp
- Integrate WorkManager for scheduling sync tasks
- Map data models between Room entities and API DTOs
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jan 26, 2026

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

This pull request introduces remote data synchronization to the application. It adds Retrofit and OkHttp networking dependencies, creates a remote API interface with three sync endpoints, implements a background WorkManager-based sync worker with bidirectional synchronization logic, extends user preferences with backend URL and sync timestamp storage, and integrates cloud sync controls into the settings UI.

Changes

Cohort / File(s) Summary
Dependencies
app/build.gradle.kts
Added Retrofit 2.11.0, Retrofit Gson converter 2.11.0, and OkHttp logging interceptor 4.12.0 for remote API communication and request/response logging
Remote API Layer
app/src/main/java/com/philkes/notallyx/data/remote/NotallyApi.kt
New Retrofit interface defining three suspend endpoints: pullChanges() (GET), pushChanges() (POST), registerDevice() (POST). Defined nine serializable data classes for requests/responses (SyncRequest, SyncResponse, RegisterDeviceRequest, RegisterDeviceResponse) and models (SyncNote, SyncLabel, SyncSpan, SyncListItem) with sensible defaults
Sync Worker
app/src/main/java/com/philkes/notallyx/data/sync/SyncWorker.kt
New WorkManager coroutine worker (263 lines) implementing bidirectional sync: device registration, pulling remote changes to local DB, and pushing local changes to server. Includes mapping helpers between domain and API models, Retrofit/OkHttp client configuration, timeout settings, error handling, and work request factory
Preferences
app/src/main/java/com/philkes/notallyx/presentation/viewmodel/preference/NotallyXPreferences.kt
Added two new preference properties: backendUrl (StringPreference) and lastSync (LongPreference) for storing server URL and sync timestamp
Settings UI
app/src/main/java/com/philkes/notallyx/presentation/activity/main/fragment/settings/SettingsFragment.kt
Added backend URL editing dialog, manual sync trigger via "SyncNow" action, WorkManager integration to enqueue SyncWorker, and observation of backendUrl preference changes
Settings Layout & Strings
app/src/main/res/layout/fragment_settings.xml, app/src/main/res/values/strings.xml
Added "Cloud Sync" section header, BackendUrl preference include, SyncNow button, divider line; added seven new string resources (cloud_sync, backend_url, backend_url_title, sync_now, sync_success, sync_failed, and duplicate cleared_data)

Sequence Diagram

sequenceDiagram
    participant User as User/UI
    participant SettingsFragment as SettingsFragment
    participant WorkManager as WorkManager
    participant SyncWorker as SyncWorker
    participant RemoteAPI as Remote API
    participant LocalDB as Local Database

    User->>SettingsFragment: Enter backend URL or tap Sync Now
    SettingsFragment->>WorkManager: Enqueue SyncWorker with backend URL
    WorkManager->>SyncWorker: Start sync task
    SyncWorker->>RemoteAPI: registerDevice()
    RemoteAPI-->>SyncWorker: Device registered
    SyncWorker->>RemoteAPI: pullChanges(lastSync timestamp)
    RemoteAPI-->>SyncWorker: Return remote notes & timestamp
    SyncWorker->>LocalDB: Convert & upsert pulled notes
    LocalDB-->>SyncWorker: Success
    SyncWorker->>LocalDB: Query notes modified since lastSync
    LocalDB-->>SyncWorker: Local changes
    SyncWorker->>RemoteAPI: pushChanges(local notes & labels)
    RemoteAPI-->>SyncWorker: Sync response with new timestamp
    SyncWorker->>LocalDB: Update lastSync timestamp
    LocalDB-->>SyncWorker: Success
    SyncWorker-->>WorkManager: Sync complete
    WorkManager-->>SettingsFragment: Notify sync result
Loading

Estimated Code Review Effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly Related PRs

Poem

🐰 Hops through the clouds so bright,
Syncing notes left and right,
Retrofit threads dance with care,
WorkManager whispers in the air,
A rabbit's gift—your data shared! ☁️✨

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@muava12 muava12 closed this Jan 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant