Skip to content

Universal data portability: CSV import/export, clearer backup labels, alarm fixes - #22

Open
nufuturepro wants to merge 1 commit into
FeDeveloper95:mainfrom
nufuturepro:upstream-contribution
Open

Universal data portability: CSV import/export, clearer backup labels, alarm fixes#22
nufuturepro wants to merge 1 commit into
FeDeveloper95:mainfrom
nufuturepro:upstream-contribution

Conversation

@nufuturepro

@nufuturepro nufuturepro commented Sep 12, 2026

Copy link
Copy Markdown

Universal data portability + supply tracking + alarm fixes

This PR bundles four improvements to Med, all verified working on-device:

1. CSV export/import (RFC 4180, zero dependencies)

  • Export CSV joins the existing backup options in Advanced Settings. One row per schedule entry; hand-typed spreadsheets are valid imports — only title, creation_date, and creation_time are required.
  • Quoting follows RFC 4180 (commas, quotes, and embedded newlines), so notes containing special characters round-trip correctly in Excel/Sheets.
  • Import merges into existing data with the same semantics as JSON backups: existing entries match by ID and taken-dates are unioned, so re-importing a file never duplicates history.
  • Imports also schedule alarms immediately, so restored meds remind right away instead of staying silent until the next reboot.
  • A safety snapshot of current data is written before every import, so a bad file can never destroy existing records.

2. "Export Settings" → "Export Data"

The button has always exported a full backup (meds, history, and settings), but the label said "Settings" — users reasonably concluded it was not a data backup. All related labels and toasts now say "Data".

3. Supply (inventory) tracking with low-supply alerts

Per-medication stock tracking in the medicine editor:

  • Track supply switch reveals three steppers: doses left, refill size (doses per refill, e.g. 30 tablets), and the alert threshold.
  • Taking a dose decrements stock and un-taking restores it — consistently across all take paths (in-app, notification action, watch).
  • Card badge shows "N left" and turns red at the threshold.
  • A one-time low-supply notification fires per medication when stock reaches the threshold; it stays quiet until refilled, and stale alerts are cancelled automatically on refill, edit, or delete.
  • Supply fields ride along in JSON backups and CSV (old files without them still import fine).

Audit hardening included from on-device testing:

  • Per-item alert IDs, so several medications running low simultaneously do not overwrite each other's notifications.
  • Threshold evaluation runs at app start, boot/reinstall, and import — supply that is already low alerts without waiting for a dose event.
  • Race fix: toggling a dose from the UI now re-reads stored state first, so it cannot clobber a dose just logged from a notification or watch.

4. Lowest-supply home-screen widget

A resizable widget that always shows the medication with the lowest supply, including a progress bar toward the refill size and a red count at the threshold. It re-renders automatically on every data save — no polling, no battery cost.

5. Reminder fixes for early doses

Previously, logging a dose before the reminder time did not cancel that day's alarm (only the notification's Take button re-armed anything). Now:

  • getNextOccurrence skips today's slot when already taken, so an early dose cancels the pending alarm.
  • The in-app take/undo path re-arms alarms immediately — undoing an accidental "Taken" re-arms the same-day alarm, as expected.
  • Notifications never fire for meds already logged today (fire-time race).

6. local.properties untracked

.gitignore already lists local.properties, but a committed copy was still tracked and silently overrode every contributor's SDK path. This untracks it (the file remains on disk locally).

Testing

  • CSV round-trip (export → parse → export) is byte-stable; hand-written minimal CSVs import correctly.
  • Supply tracking verified end-to-end on device: take decrements, un-take restores, threshold alert fires and de-duplicates, refill cancels the stale alert, widget updates on save.
  • Reminder fixes verified on device: early take cancels the day's alarm; the alarm correctly advances to the next scheduled day.
  • No behavior change for users who never touch the new features; existing JSON backups import unchanged.
  • English-only strings, consistent with the existing codebase.

@nufuturepro
nufuturepro deleted the upstream-contribution branch September 14, 2026 14:23
@nufuturepro nufuturepro reopened this Sep 14, 2026
- CSV export/import (RFC 4180, zero deps): spreadsheet-friendly, merging
  imports, pre-import safety snapshot, immediate alarm scheduling
- Supply (inventory) tracking: doses left / refill size / low threshold
  per medication, automatic decrement on take across all take paths,
  one-time low-supply alerts with per-item IDs, stale-alert cleanup,
  threshold evaluation at start/boot/import, JSON + CSV persistence
- Lowest-supply home-screen widget with progress bar, refreshed on every
  data save
- Reminder fixes for early doses: taking a dose before the reminder now
  cancels that day's alarm; UI take/undo re-arms immediately; fire-time
  race suppressed
- "Export Settings" relabeled to "Export Data" (it was always a full
  backup)
- local.properties untracked (already gitignored; committed copy overrode
  contributors' SDK paths)

All verified on-device: take/un-take stock math, threshold alert fire +
dedup + cancel, widget updates, early-take alarm cancellation, CSV/JSON
round-trips.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
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