The dashboard (Raspberry Pi 3.5" screen + web pages), the end-to-end encrypted sync mailbox (PHP + SQLite) and the Android companion app (Flutter), with docs, clean-install checks and screenshots made from demo data. Built mostly with an AI coding assistant; not yet reviewed line by line by a human (see README and SECURITY.md). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
27 lines
1.1 KiB
Dart
27 lines
1.1 KiB
Dart
// The one time period every Health chart shows (as the web pages' shared range): 1 day … all.
|
|
// Any chart's corner chip changes it for all of them; kept on this phone (store meta, not synced).
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
import '../sync/store.dart';
|
|
import 'cycle_model.dart' show plus;
|
|
|
|
const ranges = [('1d', '1 day', 1), ('1w', '1 week', 7), ('1m', '1 month', 30), ('3m', '3 months', 91),
|
|
('1y', '1 year', 365), ('all', 'All', 0)];
|
|
|
|
class HealthRange extends ValueNotifier<String> {
|
|
HealthRange(this._store) : super(ranges[(_store.meta('ui_range') == 0 ? 2 : _store.meta('ui_range')) - 1].$1);
|
|
final SyncStore _store;
|
|
|
|
String get label => ranges.firstWhere((r) => r.$1 == value).$2;
|
|
|
|
void set(String key) {
|
|
value = key;
|
|
_store.setMeta('ui_range', ranges.indexWhere((r) => r.$1 == key) + 1); // 0 = never set → 1 week
|
|
}
|
|
|
|
/// The first day shown: [days] back including today, or (All) the data's first day.
|
|
DateTime from(DateTime first, DateTime now) {
|
|
final days = ranges.firstWhere((r) => r.$1 == value).$3;
|
|
return days == 0 ? first : plus(now, -(days - 1));
|
|
}
|
|
}
|