# Offline Data Collection & Synchronization {#offline-data-collection--synchronization}


MQUAD is built from the ground up as an **offline-first** system. You never need an active internet connection to browse assigned surveys, fill out complex questionnaires, capture photos, record audio, or review collected responses.

---


## 1. How Offline Mode Works {#1-how-offline-mode-works}


- All assigned survey schemas, version definitions, choice lists, external lookup datasets (CSV/XML), and pre-downloaded map tiles are stored in a high-security encrypted local SQLite database (SQLCipher) on the device.
- While offline, completed responses are given a cryptographically secure local Response ID (RID), signed with an integrity hash, and stored in the local outbox.
- When an internet connection becomes available, MQUAD automatically coordinates with the central **Sync Service** to transmit pending records without interrupting your fieldwork.

---


## 2. Sync Execution Modes {#2-sync-execution-modes}


MQUAD supports three coordinated synchronization triggers:


### 1. Foreground Sync (Immediate) {#1-foreground-sync-immediate}
When the app is open and internet connectivity is detected:
- The sync engine listens for local state changes.
- Within 2 seconds of completing a form or making edits, transmission begins automatically.


### 2. Background Periodic Sync {#2-background-periodic-sync}
When the app is minimized or the screen is turned off:
- On **Android & iOS**, background worker tasks trigger approximately every 15 minutes.
- Background sync activates only if:
  - Network connectivity is active.
  - Device battery level is greater than 20% (to prevent draining enumerator devices in the field).
- On **Desktop**, sync runs in a lightweight background isolate every 15 minutes.


### 3. Manual Sync {#3-manual-sync}
- Tap the **Sync Now** button on the Home dashboard at any time.
- Or perform a **pull-to-refresh** gesture on the Surveys, Responses, or Drafts lists.

---


## 3. Visual Sync Status Indicators {#3-visual-sync-status-indicators}


Every survey, draft, and completed response displays a distinct sync indicator badge:

| Indicator | Status Name | Description |
|-----------|-------------|-------------|
| 🟢 Green Checkmark | **Synced** | Response is confirmed received, verified, and saved on the central server. |
| 🔄 Spinning Arrows | **Syncing** | Data or media chunks are currently transmitting to the server. |
| 🟡 Yellow Clock | **Pending Upload** | Response is completed on the device and waiting in the queue for a network connection. |
| ⚫ Grey Cloud Slash | **Offline Queue** | Device is currently offline; records will transmit automatically once reconnected. |
| 🔴 Red Exclamation | **Sync Error / Conflict** | Submission requires review or conflict resolution before finalization. |

---


## 4. Bandwidth & Network Data Controls {#4-bandwidth--network-data-controls}


To conserve mobile data allowances when operating over cellular connections:

1. Open **Settings → Sync Settings**.
2. **Sync Over Wi-Fi Only**: When enabled, MQUAD pauses automatic upload of heavy submissions and media until the device connects to an authorized Wi-Fi network. Urgent text-only responses can still be manually synced if needed.
3. **Block Sync While Roaming**: Automatically blocks data transfer when your device is connected to international or out-of-region cellular roaming networks.

---


## 5. Media Synchronization {#5-media-synchronization}


Surveys with photos, signatures, audio recordings, or videos can generate significant data volume:

- **Automatic Pre-Compression**: Images and videos are compressed on-device immediately upon capture using optimized quality curves.
- **Chunked Resumable Uploads**: Large media files are uploaded in chunks. If the cellular connection drops halfway through a photo upload, transmission resumes from the last confirmed chunk when the network returns.
- **Media Gate Check**: Before beginning interviews, MQUAD checks that all required survey media assets (e.g. choice images, audio prompts) are downloaded and verified.

---


## 6. Conflict Resolution {#6-conflict-resolution}


In rare instances where a record has been edited on the web dashboard while simultaneous offline edits occurred on a mobile device:

1. A **Conflict Alert** banner will appear on the Home dashboard and under **Settings → Conflicts**.
2. Tap on the conflicted response to open the **Conflict Resolution Screen**.
3. MQUAD displays a side-by-side comparison of:
   - **Local Version**: The answers and timestamp recorded on your mobile device.
   - **Server Version**: The answers and timestamp stored on the central server.
4. Resolution choices:
   - **Keep Local**: Overwrites the server record with your mobile device's answers.
   - **Keep Server**: Discards the local changes and accepts the central server's record.
   - **Resolve All**: If multiple conflicts exist, batch-applies your preferred rule across all items.

---


## 7. Device Storage Management {#7-device-storage-management}


Field campaigns that run for weeks or months can accumulate thousands of responses and gigabytes of photos:

1. Open **Settings → Storage**.
2. The visual storage gauge shows internal device capacity:
   - **Green**: Normal (< 80% used).
   - **Amber Warning**: Storage reaches 80%—cleanup recommended.
   - **Red Critical**: Storage reaches 95%—submission capture may pause until space is freed.
3. Safe Cleanup Actions:
   - **Clear Synced Media Cache**: Deletes local cached copies of photos that have already been confirmed synced to the server. (Unsynced media is never deleted).
   - **Clear Offline Map Tiles**: Frees storage used by cached map tiles without deleting survey data.
