Skip to content

Colota - Android GPS Location tracker

fix(export): show a spinner on Import a file while it parses (#864)

Max Dietrich07455f2ce082
diff --git a/apps/docs/docs/development/architecture.md b/apps/docs/docs/development/architecture.md
index 3687eaa9..253d5995 100644
--- a/apps/docs/docs/development/architecture.md
+++ b/apps/docs/docs/development/architecture.md
@@ -133,7 +133,7 @@ Native-only modules in the `importer/` package. Format-specific parsers all retu
| `JsonReadHelpers` | Shared `JsonReader` extensions (`readNullableInt`, `readNullableDouble`) plus `parseIso8601Seconds` backed by pre-built immutable `DateTimeFormatter` instances (thread-safe and ~10× faster than `SimpleDateFormat`, which matters for Timeline files with 100k+ timestamps). |
| `ImportFormat` / `ImportRow` / `UnsupportedFormatException` | Shared data types. `ImportRow` is the normalised location shape produced by every parser before dedup; format-specific quirks (E7 coords, ISO timestamps, degree-suffix strings) are resolved before construction so the orchestrator never sees them. |
-The on-disk format is **never** authoritative for sync decisions: imported rows go in with `sent = 1` by default (no re-upload), and only the explicit "Import + Queue for Sync" button flips that to `sent = 0` + queue rows. See [Data Import](../guides/data-import.md) for the user-facing semantics.
+The on-disk format is **never** authoritative for sync decisions: imported rows go in with `sent = 1` by default (no re-upload), and only the **Also queue for upload** switch on the import preview flips that to `sent = 0` + queue rows. See [Data Import](../guides/data-import.md) for the user-facing semantics.
### LocationProvider Abstraction
diff --git a/apps/docs/docs/faq.md b/apps/docs/docs/faq.md
index 5baa71a0..cb591a6c 100644
--- a/apps/docs/docs/faq.md
+++ b/apps/docs/docs/faq.md
@@ -48,7 +48,7 @@ Yes. Go to **Settings → Offline maps** to download map areas to your device. P
### Can I export my location history?
-Yes. Go to **Settings → Export locations** to export in CSV, GeoJSON, GPX or KML, or export a single day's trips from the **History** tab. **Settings → Auto-export** writes the same formats to a folder you pick on a daily, weekly or monthly schedule. See [Data Export](/docs/guides/data-export) for details.
+Yes. Go to **Settings → Export & import** to export in CSV, GeoJSON, GPX or KML, or export a single day's trips from the **History** tab. Its **Automatic export** row writes the same formats to a folder you pick on a daily, weekly or monthly schedule. See [Data Export](/docs/guides/data-export) for details.
### Can I import location history from another app?
diff --git a/apps/docs/docs/guides/data-export.md b/apps/docs/docs/guides/data-export.md
index d65987b2..cd27b48d 100644
--- a/apps/docs/docs/guides/data-export.md
+++ b/apps/docs/docs/guides/data-export.md
@@ -43,10 +43,10 @@ For exports on a schedule instead of on demand, see [Scheduled Export](#schedule
Go to the **History** tab → **Trips**. There are two ways to export:
-- **All trips for the day** - tap the share icon in the header, pick a format, share.
-- **A custom selection** - long-press a trip to enter selection mode. Tap other trips to add or remove them; **Select all** is in the selection header's overflow menu. Tap the share icon in the selection header, pick a format, share. Works for a single trip too.
+- **All trips for the day** - tap the export icon in the header, pick a format, share.
+- **A custom selection** - long-press a trip to enter selection mode. Tap other trips to add or remove them; **Select all** is in the selection header's overflow menu. Tap the export icon in the selection header, pick a format, share. Works for a single trip too.
-For a single trip you can also tap it to open **Trip Detail** and use the share icon in the header.
+For a single trip you can also tap it to open **Trip Detail** and use the export icon in the header.
Trip exports include a `trip` column/property so each location is tagged with its trip number. Custom selections produce a single file containing only the chosen trips.
@@ -62,14 +62,14 @@ Automatically export your location data on a schedule without opening the app.
### Setup
-1. Go to **Settings → Auto-export**
+1. Go to **Settings → Export & import → Automatic export**
2. Select an export directory (files are saved there via Android's Storage Access Framework)
3. Choose a format (CSV, GeoJSON, GPX, or KML)
4. Set the frequency: **Daily**, **Weekly**, or **Monthly**
5. Pick the **Time** (24-hour) in your device's local timezone. For **Weekly**, also pick a day of week. For **Monthly**, pick a day of month (1-31)
6. Enable the toggle
-You can also tap **Export Now** to trigger an immediate export using your current auto-export settings, without waiting for the next scheduled run. It works whether or not the toggle is on: the toggle governs the schedule, not the button. A line under the button says the export is running, and it keeps running if you leave the screen.
+You can also tap **Export now** to trigger an immediate export using your current auto-export settings, without waiting for the next scheduled run. It works whether or not the toggle is on: the toggle governs the schedule, not the button. A line under the button says the export is running, and it keeps running if you leave the screen.
### Export Range
@@ -101,7 +101,7 @@ If several devices export into the same folder and none of the templates include
- Uses Android AlarmManager (`setAndAllowWhileIdle`) to fire at your configured wall-clock time. Typical accuracy is within minutes; Doze mode may delay by up to ~15 minutes
- After each export the next alarm is armed automatically. Alarms also re-arm after device reboot
-- Exports fire at the configured time, not on enable. To run an export immediately for testing or backup, tap **Export Now**, which needs only an export directory
+- Exports fire at the configured time, not on enable. To run an export immediately for testing or backup, tap **Export now**, which needs only an export directory
- Promotes to a foreground service during export, preventing Android from killing long-running exports
- Streams data in chunks (10,000 locations at a time) to keep memory usage low even with very large datasets
- Writes to a temporary file first, then copies to the export directory - if something goes wrong mid-export, you never get a partial or corrupted file
diff --git a/apps/docs/docs/guides/data-management.md b/apps/docs/docs/guides/data-management.md
index b6d4d318..23de2b39 100644
--- a/apps/docs/docs/guides/data-management.md
+++ b/apps/docs/docs/guides/data-management.md
@@ -55,7 +55,7 @@ Deleting locally does not remove anything already uploaded to your server.
## Imported locations and the queue
-Locations brought in via [Data Import](data-import.md) are marked as already synced by default, so they **do not show up in the queue counter** and don't get re-uploaded to your backend. If you used the **Import + Queue for Sync** button on the import dialog instead (the "migration" path), the imported rows do land in the queue and the next sync drains them - the counters here will reflect that until they finish uploading.
+Locations brought in via [Data Import](data-import.md) are marked as already synced by default, so they **do not show up in the queue counter** and don't get re-uploaded to your backend. If you switched on **Also queue for upload** on the import preview instead (the "migration" path), the imported rows do land in the queue and the next sync drains them - the counters here will reflect that until they finish uploading.
## Storage Reference
diff --git a/apps/docs/docs/guides/troubleshooting.md b/apps/docs/docs/guides/troubleshooting.md
index d94bfa28..283000cd 100644
--- a/apps/docs/docs/guides/troubleshooting.md
+++ b/apps/docs/docs/guides/troubleshooting.md
@@ -137,9 +137,9 @@ To change: **Settings > Tracking & sync > Sync only on**.
## Auto-export not working
-- Verify a directory is selected in **Settings > Auto-export**
+- Verify a directory is selected in **Settings > Export & import > Automatic export**
- Check that the toggle is enabled
-- The first export fires at the configured time, not on enable. Tap **Export Now** to confirm the pipeline works without waiting
+- The first export fires at the configured time, not on enable. Tap **Export now** to confirm the pipeline works without waiting
- Doze mode can delay an alarm by up to ~15 minutes - if exports are running but a few minutes late, that's expected
- If you see a "Directory permission lost" notification, re-select the export directory
- Check that the selected directory still exists and is accessible
diff --git a/apps/docs/src/pages/privacy-policy.md b/apps/docs/src/pages/privacy-policy.md
index cc01c36e..de39c8f8 100644
--- a/apps/docs/src/pages/privacy-policy.md
+++ b/apps/docs/src/pages/privacy-policy.md
@@ -62,7 +62,7 @@ Authentication credentials (if configured) are encrypted.
### Importing Data
-You can import location history from external files (GeoJSON, Google Timeline, GPX, KML, CSV) into the local database. The file is read from a location you select via the Android document picker; nothing leaves your device during import. If you opt in to "Import + Queue for Sync", imported rows are enqueued for replication to your sync backend like any other location data.
+You can import location history from external files (GeoJSON, Google Timeline, GPX, KML, CSV) into the local database. The file is read from a location you select via the Android document picker; nothing leaves your device during import. If you switch on "Also queue for upload", imported rows are enqueued for replication to your sync backend like any other location data.
### Client Certificates and Trusted CAs
diff --git a/apps/mobile/src/screens/ExportImportScreen.tsx b/apps/mobile/src/screens/ExportImportScreen.tsx
index 990c7bd2..0fcda404 100644
--- a/apps/mobile/src/screens/ExportImportScreen.tsx
+++ b/apps/mobile/src/screens/ExportImportScreen.tsx
@@ -18,6 +18,7 @@ import {
LoadingOverlay,
SectionTitle,
SettingRow,
+ SpinningLoader,
StateLine,
StatRow,
Toggle
@@ -316,12 +317,12 @@ export function ExportImportScreen({ navigation }: ScreenProps) {
<ListItem
testID="import-file-row"
icon={FileText}
- trailingIcon={Download}
+ trailingIcon={busy === "parse" ? SpinningLoader : Download}
label="Import a file"
sub={importRowSub(busy === "parse")}
subLines={2}
accessibilityHint="Opens the file picker"
- disabled={busy !== null}
+ disabled={busy === "parse" ? false : busy !== null}
onPress={handleChooseFile}
/>
</Card>
diff --git a/apps/mobile/src/screens/__tests__/ExportImportScreen.test.tsx b/apps/mobile/src/screens/__tests__/ExportImportScreen.test.tsx
index f2a693e1..2e40e0cd 100644
--- a/apps/mobile/src/screens/__tests__/ExportImportScreen.test.tsx
+++ b/apps/mobile/src/screens/__tests__/ExportImportScreen.test.tsx
@@ -88,10 +88,17 @@ jest.mock("../../components", () => {
R.createElement(View, null, R.createElement(Text, null, label), R.createElement(Text, null, hint), children),
Toggle: ({ value, onValueChange, testID }: any) =>
R.createElement(Pressable, { testID, onPress: () => onValueChange(!value) }),
- ListItem: ({ label, sub, testID, onPress, disabled }: any) =>
+ SpinningLoader: Object.assign(() => null, { displayName: "SpinningLoader" }),
+ ListItem: ({ label, sub, testID, onPress, disabled, trailingIcon }: any) =>
R.createElement(
Pressable,
- { testID, onPress, disabled, accessibilityState: { disabled: !!disabled } },
+ {
+ testID,
+ onPress,
+ disabled,
+ accessibilityState: { disabled: !!disabled },
+ accessibilityValue: { text: trailingIcon?.displayName ?? "chevron" }
+ },
R.createElement(Text, null, label),
R.createElement(Text, null, sub)
),
@@ -317,7 +324,7 @@ describe("ExportImportScreen", () => {
expect(mockNavigation.navigate).toHaveBeenCalledWith("Backup & Restore")
})
- it("says the file is being read and blocks a second pick while it is", async () => {
+ it("shows a spinner on the row while the file is read, and ignores a second pick", async () => {
mockPickImportSource.mockResolvedValue({ uri: "content://file" })
mockImportLocationsFromFile.mockReturnValue(new Promise(() => {}))
const api = renderScreen()
@@ -326,7 +333,12 @@ describe("ExportImportScreen", () => {
fireEvent.press(api.getByTestId("import-file-row"))
expect(await api.findByText("Reading the file…")).toBeTruthy()
- expect(api.getByTestId("import-file-row").props.accessibilityState.disabled).toBe(true)
+ const row = api.getByTestId("import-file-row")
+ expect(row.props.accessibilityValue.text).toBe("SpinningLoader")
+ expect(row.props.accessibilityState.disabled).toBe(false)
+
+ fireEvent.press(row)
+ expect(mockPickImportSource).toHaveBeenCalledTimes(1)
})
// Opening Backup & Restore blurs this screen without unmounting it.
diff --git a/apps/mobile/src/utils/__tests__/format.test.ts b/apps/mobile/src/utils/__tests__/format.test.ts
index 33de23a3..3068557d 100644
--- a/apps/mobile/src/utils/__tests__/format.test.ts
+++ b/apps/mobile/src/utils/__tests__/format.test.ts
@@ -51,6 +51,10 @@ describe("formatBytes", () => {
expect(formatBytes(1.2 * 1024 ** 3, { decimals: 0, locale: "en-US" })).toBe("1 GB")
})
+ it("never groups digits, so 1000 MB cannot read as one megabyte", () => {
+ expect(formatBytes(1000.4 * 1024 * 1024, { decimals: 0, locale: "de-DE" })).toBe("1000 MB")
+ })
+
// Callers convert megabytes, which can leave a fraction of a byte.
it("rounds a fraction of a byte instead of printing it", () => {
expect(formatBytes(524.288, { locale: "en-US" })).toBe("524 B")
diff --git a/apps/mobile/src/utils/format.ts b/apps/mobile/src/utils/format.ts
index bfdefbc6..8f1a687b 100644
--- a/apps/mobile/src/utils/format.ts
+++ b/apps/mobile/src/utils/format.ts
@@ -3,13 +3,13 @@
* Licensed under the GNU AGPLv3. See LICENSE in the project root for details.
*/
-/** B, KB, MB or GB in the device locale's separators, with one decimal unless `decimals` says otherwise. */
+/** B, KB, MB or GB in the device locale's decimal separator, ungrouped, with one decimal unless `decimals` says otherwise. */
export const formatBytes = (
bytes: number,
{ decimals = 1, locale }: { decimals?: number; locale?: string } = {}
): string => {
const scaled = (n: number) =>
- n.toLocaleString(locale, { minimumFractionDigits: decimals, maximumFractionDigits: decimals })
+ n.toLocaleString(locale, { minimumFractionDigits: decimals, maximumFractionDigits: decimals, useGrouping: false })
if (bytes < 1024) return `${Math.round(bytes)} B`
if (bytes < 1024 ** 2) return `${scaled(bytes / 1024)} KB`
if (bytes < 1024 ** 3) return `${scaled(bytes / 1024 ** 2)} MB`