Compare commits
No commits in common. "66650ca3cca6299a4d97070848cc15c897ffee01" and "eec785666419a7c0d43bd0fa39ad49430a533368" have entirely different histories.
66650ca3cc
...
eec7856664
@ -255,4 +255,4 @@ repos:
|
||||
entry: scripts/check_repo_contract.sh
|
||||
language: system
|
||||
pass_filenames: false
|
||||
files: ^(CLAUDE\.md|AGENTS\.md|scripts/test_changed\.sh)$|(^|/)(AndroidManifest\.xml|build\.gradle(\.kts)?|strings\.xml|pubspec\.yaml|repo-contract\.toml|[^/]+\.desktop|assets/icon/[^/]+\.png)$
|
||||
files: ^(CLAUDE\.md|AGENTS\.md|scripts/test_changed\.sh)$
|
||||
|
||||
@ -24,7 +24,7 @@
|
||||
perceived lateness, which trades robustness for precision we don't
|
||||
need. -->
|
||||
<application
|
||||
android:label="DietGuard"
|
||||
android:label="diet_guard_app"
|
||||
android:name="${applicationName}"
|
||||
android:icon="@mipmap/ic_launcher">
|
||||
<activity
|
||||
|
||||
|
Before Width: | Height: | Size: 5.6 KiB After Width: | Height: | Size: 5.3 KiB |
|
Before Width: | Height: | Size: 5.4 KiB After Width: | Height: | Size: 5.2 KiB |
|
Before Width: | Height: | Size: 3.5 KiB After Width: | Height: | Size: 3.3 KiB |
|
Before Width: | Height: | Size: 3.5 KiB After Width: | Height: | Size: 3.3 KiB |
|
Before Width: | Height: | Size: 6.9 KiB After Width: | Height: | Size: 6.5 KiB |
|
Before Width: | Height: | Size: 6.5 KiB After Width: | Height: | Size: 6.0 KiB |
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 9.5 KiB |
|
Before Width: | Height: | Size: 8.8 KiB After Width: | Height: | Size: 8.3 KiB |
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 1.9 KiB |
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 2.3 KiB After Width: | Height: | Size: 2.2 KiB |
|
Before Width: | Height: | Size: 3.7 KiB After Width: | Height: | Size: 3.5 KiB |
|
Before Width: | Height: | Size: 4.6 KiB After Width: | Height: | Size: 4.3 KiB |
@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-9.8.2-all.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-9.8.1-all.zip
|
||||
|
||||
|
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 22 KiB |
@ -1,6 +1,6 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="1024" height="1024" viewBox="0 0 1024 1024">
|
||||
<rect width="1024" height="1024" fill="#211D1B"/>
|
||||
<g fill="none" stroke="#B8862E" stroke-width="66.7417" stroke-linecap="round" stroke-linejoin="round" transform="translate(-40.3384,-42.496) scale(1.07879)">
|
||||
<g fill="none" stroke="#B8862E" stroke-width="72" stroke-linecap="round" stroke-linejoin="round" transform="translate(0,-2)">
|
||||
<path d="M 512 275 L 752 366 L 752 544 C 752 655 646 723 512 753 C 378 723 272 655 272 544 L 272 366 Z"/>
|
||||
<g transform="translate(356,362) scale(13)" fill="#B8862E" stroke="none">
|
||||
<path d="M11 9H9V2H7v7H5V2H3v7c0 2.12 1.66 3.84 3.75 3.97V22h2.5v-9.03C11.34 12.84 13 11.12 13 9V2h-2v7z"/>
|
||||
|
||||
|
Before Width: | Height: | Size: 688 B After Width: | Height: | Size: 656 B |
|
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 24 KiB |
@ -1,5 +1,5 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="1024" height="1024" viewBox="0 0 1024 1024">
|
||||
<g fill="none" stroke="#B8862E" stroke-width="66.7417" stroke-linecap="round" stroke-linejoin="round" transform="translate(-40.3384,-42.496) scale(1.07879)">
|
||||
<g fill="none" stroke="#B8862E" stroke-width="72" stroke-linecap="round" stroke-linejoin="round" transform="translate(0,-2)">
|
||||
<path d="M 512 275 L 752 366 L 752 544 C 752 655 646 723 512 753 C 378 723 272 655 272 544 L 272 366 Z"/>
|
||||
<g transform="translate(356,362) scale(13)" fill="#B8862E" stroke="none">
|
||||
<path d="M11 9H9V2H7v7H5V2H3v7c0 2.12 1.66 3.84 3.75 3.97V22h2.5v-9.03C11.34 12.84 13 11.12 13 9V2h-2v7z"/>
|
||||
|
||||
|
Before Width: | Height: | Size: 636 B After Width: | Height: | Size: 604 B |
|
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 20 KiB |
@ -1,5 +1,5 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="1024" height="1024" viewBox="0 0 1024 1024">
|
||||
<g fill="none" stroke="#FFFFFF" stroke-width="66.7417" stroke-linecap="round" stroke-linejoin="round" transform="translate(-40.3384,-42.496) scale(1.07879)">
|
||||
<g fill="none" stroke="#FFFFFF" stroke-width="72" stroke-linecap="round" stroke-linejoin="round" transform="translate(0,-2)">
|
||||
<path d="M 512 275 L 752 366 L 752 544 C 752 655 646 723 512 753 C 378 723 272 655 272 544 L 272 366 Z"/>
|
||||
<g transform="translate(356,362) scale(13)" fill="#FFFFFF" stroke="none">
|
||||
<path d="M11 9H9V2H7v7H5V2H3v7c0 2.12 1.66 3.84 3.75 3.97V22h2.5v-9.03C11.34 12.84 13 11.12 13 9V2h-2v7z"/>
|
||||
|
||||
|
Before Width: | Height: | Size: 636 B After Width: | Height: | Size: 604 B |
|
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 2.6 KiB |
|
Before Width: | Height: | Size: 403 B After Width: | Height: | Size: 380 B |
|
Before Width: | Height: | Size: 584 B After Width: | Height: | Size: 542 B |
|
Before Width: | Height: | Size: 5.1 KiB After Width: | Height: | Size: 4.8 KiB |
|
Before Width: | Height: | Size: 794 B After Width: | Height: | Size: 726 B |
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.0 KiB |
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 9.8 KiB |
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.4 KiB |
@ -77,7 +77,7 @@ install_desktop_entry() {
|
||||
cat > "$DESKTOP_DIR/$ICON_NAME.desktop" <<EOF
|
||||
[Desktop Entry]
|
||||
Type=Application
|
||||
Name=DietGuard
|
||||
Name=diet guard
|
||||
Comment=Diet logging and budget companion
|
||||
Exec=$LAUNCHER
|
||||
Icon=$ICON_NAME
|
||||
|
||||
@ -6,7 +6,6 @@
|
||||
/// `kuchnia_fill_flow.dart`; this only connects them to the screen.
|
||||
library;
|
||||
|
||||
import 'package:diet_guard_app/screens/log_meal_future_mixin.dart';
|
||||
import 'package:diet_guard_app/screens/log_meal_kuchnia_mixin.dart';
|
||||
import 'package:diet_guard_app/screens/log_meal_sync_mixin.dart';
|
||||
import 'package:diet_guard_app/services/kuchnia_fill_flow.dart';
|
||||
@ -16,7 +15,7 @@ import 'package:flutter/material.dart';
|
||||
|
||||
/// Drives the screen's [FillAllFlow] and tidies the screen after a fill.
|
||||
mixin LogMealFillMixin<T extends StatefulWidget>
|
||||
on LogMealSyncMixin<T>, LogMealKuchniaMixin<T>, LogMealFutureMixin<T> {
|
||||
on LogMealSyncMixin<T>, LogMealKuchniaMixin<T> {
|
||||
/// The flow behind the button. Per-screen, so leaving the screen drops an
|
||||
/// armed proposal along with it.
|
||||
FillAllFlow fillFlow = FillAllFlow();
|
||||
@ -24,19 +23,9 @@ mixin LogMealFillMixin<T extends StatefulWidget>
|
||||
/// Shows [message] in the form's status line. Supplied by the screen.
|
||||
void showFillStatus(String message);
|
||||
|
||||
/// A proposal belongs to the date it was fetched for; picking another (or
|
||||
/// going back to today) must not leave "Confirm (N)" offering it.
|
||||
@override
|
||||
void onLogDateChanged() {
|
||||
super.onLogDateChanged();
|
||||
fillFlow.cancel();
|
||||
}
|
||||
|
||||
/// Runs one tap: the first proposes, a second on the same day confirms.
|
||||
/// Fills the "Log for later" date when one is picked, else today.
|
||||
Future<void> onFillAll() async {
|
||||
final day = futureDate;
|
||||
final pending = fillFlow.tap(day: day);
|
||||
final pending = fillFlow.tap();
|
||||
setState(() {}); // show the busy label while the fetch/writes run
|
||||
final FillOutcome? outcome;
|
||||
try {
|
||||
@ -55,9 +44,7 @@ mixin LogMealFillMixin<T extends StatefulWidget>
|
||||
if (!mounted) return;
|
||||
setState(() {});
|
||||
if (outcome == null) return;
|
||||
if (outcome.written.isNotEmpty) {
|
||||
await _afterFill(outcome.written, later: day != null);
|
||||
}
|
||||
if (outcome.written.isNotEmpty) await _afterFill(outcome.written);
|
||||
if (!mounted) return;
|
||||
showFillStatus(outcome.message);
|
||||
}
|
||||
@ -71,20 +58,7 @@ mixin LogMealFillMixin<T extends StatefulWidget>
|
||||
/// Publishes the batch once and drops the filled dishes from the delivery
|
||||
/// queue, so "Today's delivery (N more to go)" and the prefilled form do
|
||||
/// not keep offering meals that were just logged.
|
||||
///
|
||||
/// A [later] fill logged another day's delivery: today's queue and form are
|
||||
/// left alone, and the screen goes back to today, as after a manual
|
||||
/// "Log for later" -- the picked day's slot row would otherwise be stale.
|
||||
Future<void> _afterFill(
|
||||
List<SlottedDish> written, {
|
||||
required bool later,
|
||||
}) async {
|
||||
if (later) {
|
||||
resetFutureLog();
|
||||
await publishAfterLog();
|
||||
await refreshSlots();
|
||||
return;
|
||||
}
|
||||
Future<void> _afterFill(List<SlottedDish> written) async {
|
||||
if (KuchniaQueueService.isInitialized) {
|
||||
for (final item in written) {
|
||||
KuchniaQueueService.instance.markLogged(item.dish);
|
||||
|
||||
@ -33,10 +33,6 @@ mixin LogMealFutureMixin<T extends StatefulWidget> on State<T> {
|
||||
/// The slot chosen for [futureDate], or null until one is picked.
|
||||
int? get futureSlot => _futureSlot;
|
||||
|
||||
/// Called after the picked date changes (including back to today), for
|
||||
/// state keyed to the old date to drop itself. No-op unless overridden.
|
||||
void onLogDateChanged() {}
|
||||
|
||||
/// Clears back to "log for today", dropping the picked date and slot.
|
||||
void resetFutureLog() {
|
||||
setState(() {
|
||||
@ -45,7 +41,6 @@ mixin LogMealFutureMixin<T extends StatefulWidget> on State<T> {
|
||||
_futureLoggedSlots = {};
|
||||
_futureSchedule = null;
|
||||
});
|
||||
onLogDateChanged();
|
||||
}
|
||||
|
||||
Future<void> _pickFutureDate() async {
|
||||
@ -58,12 +53,6 @@ mixin LogMealFutureMixin<T extends StatefulWidget> on State<T> {
|
||||
initialDate: _futureDate ?? tomorrow,
|
||||
);
|
||||
if (picked == null || !mounted) return;
|
||||
await selectLogDate(picked);
|
||||
}
|
||||
|
||||
/// Switches the form to log against [picked] (strictly after today): what
|
||||
/// the date picker does once a date is chosen.
|
||||
Future<void> selectLogDate(DateTime picked) async {
|
||||
final log = await LogStorageService.instance.readLog();
|
||||
if (!mounted) return;
|
||||
final day = localDateKey(picked);
|
||||
@ -81,7 +70,6 @@ mixin LogMealFutureMixin<T extends StatefulWidget> on State<T> {
|
||||
_futureLoggedSlots = logged;
|
||||
_futureSlot = null;
|
||||
});
|
||||
onLogDateChanged();
|
||||
}
|
||||
|
||||
/// The "When" row: a "Log for later" button, or the picked date with a
|
||||
|
||||
@ -47,8 +47,8 @@ class _LogMealScreenState extends State<LogMealScreen>
|
||||
LogMealSyncMixin<LogMealScreen>,
|
||||
LogMealNavMixin<LogMealScreen>,
|
||||
LogMealKuchniaMixin<LogMealScreen>,
|
||||
LogMealFutureMixin<LogMealScreen>,
|
||||
LogMealFillMixin<LogMealScreen> {
|
||||
LogMealFillMixin<LogMealScreen>,
|
||||
LogMealFutureMixin<LogMealScreen> {
|
||||
@override
|
||||
http.Client? get syncHttpClient => widget.httpClient;
|
||||
|
||||
|
||||
@ -9,14 +9,11 @@
|
||||
/// reached from the second tap of `FillAllFlow`.
|
||||
library;
|
||||
|
||||
import 'package:diet_guard_app/models/food_entry.dart';
|
||||
import 'package:diet_guard_app/models/kuchnia_dish.dart';
|
||||
import 'package:diet_guard_app/models/local_time.dart';
|
||||
import 'package:diet_guard_app/models/nutrition.dart';
|
||||
import 'package:diet_guard_app/models/slot.dart';
|
||||
import 'package:diet_guard_app/services/kuchnia_spread.dart';
|
||||
import 'package:diet_guard_app/services/log_storage_service.dart';
|
||||
import 'package:diet_guard_app/services/meal_schedule_service.dart';
|
||||
|
||||
/// Marks entries this feature created, the same tag the PC's Fill all writes
|
||||
/// (`_kuchnia_log.SOURCE`), so both devices' batch fills read alike.
|
||||
@ -64,49 +61,23 @@ Nutrition dishNutrition(KuchniaDish dish) => nutritionForPortion(
|
||||
String _dedupKey(String desc, int? slotMinute) =>
|
||||
'${desc.trim().toLowerCase()}\u0000$slotMinute';
|
||||
|
||||
/// Returns [day]'s live entries; today's when [day] is null.
|
||||
Future<List<FoodEntry>> dayEntries(
|
||||
LogStorageService store,
|
||||
DateTime? day,
|
||||
) async {
|
||||
if (day == null) return await store.todayEntries();
|
||||
final log = await store.readLog();
|
||||
return [
|
||||
for (final entry in log[localDateKey(day)] ?? const <FoodEntry>[])
|
||||
if (!entry.deleted) entry,
|
||||
];
|
||||
}
|
||||
|
||||
/// [day]'s satisfied slot minutes under the schedule in force *that* day --
|
||||
/// `LogStorageService.loggedSlotsToday` for any date, as the "Log for later"
|
||||
/// slot row computes it.
|
||||
Future<Set<int>> loggedSlotsOn(LogStorageService store, DateTime day) async {
|
||||
final entries = await dayEntries(store, day);
|
||||
return satisfiedSlots([
|
||||
for (final entry in entries) ?entry.slotMinute,
|
||||
], MealScheduleService.history.forDay(localDateKey(day)));
|
||||
}
|
||||
|
||||
/// Logs each chosen dish, skipping any already logged that day in that slot.
|
||||
/// Logs each chosen dish, skipping any already logged today in that slot.
|
||||
///
|
||||
/// Mirrors `log_dishes`, including its intra-batch skip: two identical dishes
|
||||
/// spread into the same slot land once, because the write is reflected in the
|
||||
/// seen set before the next dish is checked.
|
||||
///
|
||||
/// Writes through [LogStorageService.logMeal], the same call a manual log
|
||||
/// makes; the caller then publishes once for the whole batch. With [day]
|
||||
/// (a "Log for later" date, strictly after today) each dish is stamped at its
|
||||
/// slot's time on that day; without it, now -- as a manual log is.
|
||||
/// makes; the caller then publishes once for the whole batch.
|
||||
///
|
||||
/// Returns the dishes actually written, in order.
|
||||
Future<List<SlottedDish>> logDishes(
|
||||
List<SlottedDish> chosen, {
|
||||
LogStorageService? storage,
|
||||
DateTime? day,
|
||||
}) async {
|
||||
final store = storage ?? LogStorageService.instance;
|
||||
final seen = {
|
||||
for (final entry in await dayEntries(store, day))
|
||||
for (final entry in await store.todayEntries())
|
||||
_dedupKey(entry.desc, entry.slotMinute),
|
||||
};
|
||||
final written = <SlottedDish>[];
|
||||
@ -117,15 +88,6 @@ Future<List<SlottedDish>> logDishes(
|
||||
item.dish.name,
|
||||
dishNutrition(item.dish),
|
||||
slotMinute: item.slot,
|
||||
when: day == null
|
||||
? null
|
||||
: DateTime(
|
||||
day.year,
|
||||
day.month,
|
||||
day.day,
|
||||
item.slot ~/ 60,
|
||||
item.slot % 60,
|
||||
),
|
||||
);
|
||||
written.add(item);
|
||||
}
|
||||
|
||||
@ -1,17 +1,15 @@
|
||||
/// The two-tap state machine behind "Fill all with catering".
|
||||
///
|
||||
/// Mirrors `diet_guard/_gatelock_fillall.py`'s `FillAllFlow`. Two taps, never
|
||||
/// one: the first fetches the day's delivery (today's, or the date picked
|
||||
/// through "Log for later") and proposes exactly what would be written; only
|
||||
/// the second writes. No modal dialog -- the proposal is a status line and
|
||||
/// the button relabels to "✓ Confirm (N)".
|
||||
/// one: the first fetches today's delivery and proposes exactly what would be
|
||||
/// written; only the second writes. No modal dialog -- the proposal is a
|
||||
/// status line and the button relabels to "✓ Confirm (N)".
|
||||
///
|
||||
/// Widget-free so the flow's guarantees (first tap writes nothing, confirm
|
||||
/// re-checks occupancy, a plan from before midnight refetches) are testable
|
||||
/// with an injected clock and fetch.
|
||||
library;
|
||||
|
||||
import 'package:diet_guard_app/models/local_time.dart';
|
||||
import 'package:diet_guard_app/models/slot.dart';
|
||||
import 'package:diet_guard_app/services/kuchnia_fill.dart';
|
||||
import 'package:diet_guard_app/services/kuchnia_import.dart';
|
||||
@ -19,7 +17,6 @@ import 'package:diet_guard_app/services/kuchnia_queue.dart';
|
||||
import 'package:diet_guard_app/services/kuchnia_spread.dart';
|
||||
import 'package:diet_guard_app/services/log_storage_service.dart';
|
||||
import 'package:diet_guard_app/services/meal_schedule_service.dart';
|
||||
import 'package:flutter/foundation.dart' show visibleForTesting;
|
||||
|
||||
/// Fetches one day's delivery.
|
||||
typedef DeliveryFetch = Future<KuchniaRefresh> Function(DateTime day);
|
||||
@ -34,19 +31,11 @@ const _none = <SlottedDish>[];
|
||||
const nothingToFillMessage = 'Every slot already has a meal — nothing to fill.';
|
||||
|
||||
/// The explicit tap's fetch: unguarded, like "Today's delivery", and it
|
||||
/// records today's fetch so the automatic path is spared a second walk.
|
||||
///
|
||||
/// Only today's: the marker holds a single day, so recording a "Log for
|
||||
/// later" date would make the automatic fetch skip that day when it comes.
|
||||
@visibleForTesting
|
||||
Future<KuchniaRefresh> fetchAndRecord(
|
||||
DateTime day, {
|
||||
DeliveryFetch fetch = refreshDelivery,
|
||||
}) async {
|
||||
final result = await fetch(day);
|
||||
/// records the fetch so the automatic path is spared a second walk.
|
||||
Future<KuchniaRefresh> _fetchAndRecord(DateTime day) async {
|
||||
final result = await refreshDelivery(day);
|
||||
if (result.ok &&
|
||||
result.dishes.isNotEmpty &&
|
||||
localDateKey(day) == localDateKey(DateTime.now()) &&
|
||||
KuchniaQueueService.isInitialized) {
|
||||
await KuchniaQueueService.instance.recordFetched(day);
|
||||
}
|
||||
@ -59,24 +48,21 @@ class FillAllFlow {
|
||||
FillAllFlow({
|
||||
DeliveryFetch? fetch,
|
||||
DateTime Function()? now,
|
||||
List<int> Function(DateTime day)? slots,
|
||||
Future<Set<int>> Function(DateTime day)? occupiedSlots,
|
||||
List<int> Function()? slots,
|
||||
Future<Set<int>> Function()? occupiedSlots,
|
||||
LogStorageService? storage,
|
||||
}) : _fetch = fetch ?? fetchAndRecord,
|
||||
}) : _fetch = fetch ?? _fetchAndRecord,
|
||||
_now = now ?? DateTime.now,
|
||||
_slots =
|
||||
slots ??
|
||||
((day) =>
|
||||
daySlots(MealScheduleService.history.forDay(localDateKey(day)))),
|
||||
_slots = slots ?? (() => daySlots(MealScheduleService.current)),
|
||||
_occupied =
|
||||
occupiedSlots ??
|
||||
((day) => loggedSlotsOn(storage ?? LogStorageService.instance, day)),
|
||||
(() => (storage ?? LogStorageService.instance).loggedSlotsToday()),
|
||||
_storage = storage;
|
||||
|
||||
final DeliveryFetch _fetch;
|
||||
final DateTime Function() _now;
|
||||
final List<int> Function(DateTime day) _slots;
|
||||
final Future<Set<int>> Function(DateTime day) _occupied;
|
||||
final List<int> Function() _slots;
|
||||
final Future<Set<int>> Function() _occupied;
|
||||
final LogStorageService? _storage;
|
||||
|
||||
List<SlottedDish> _plan = const [];
|
||||
@ -96,43 +82,37 @@ class FillAllFlow {
|
||||
|
||||
/// First tap fetches and proposes; a second tap on the same day confirms.
|
||||
///
|
||||
/// [day] is the "Log for later" date when one is picked; null means today.
|
||||
///
|
||||
/// Returns null when the tap was ignored because one is already in flight,
|
||||
/// or when [cancel] ran while its fetch was.
|
||||
Future<FillOutcome?> tap({DateTime? day}) async {
|
||||
Future<FillOutcome?> tap() async {
|
||||
if (busy) return null;
|
||||
final target = day == null
|
||||
? _today()
|
||||
: DateTime(day.year, day.month, day.day);
|
||||
if (_plan.isNotEmpty && _planDay == target) return await _confirm();
|
||||
// No plan, one for another picked day, or one proposed before midnight:
|
||||
// fetch (again). The day is pinned here, not when the result lands, so a
|
||||
// fetch still in flight at midnight can never confirm yesterday's menu
|
||||
// into today.
|
||||
final today = _today();
|
||||
if (_plan.isNotEmpty && _planDay == today) return await _confirm();
|
||||
// No plan, or one proposed before midnight: fetch (again). The day is
|
||||
// pinned here, not when the result lands, so a fetch still in flight at
|
||||
// midnight can never confirm yesterday's menu into today.
|
||||
cancel();
|
||||
_planDay = target;
|
||||
_planDay = today;
|
||||
busy = true;
|
||||
try {
|
||||
return await _propose(target);
|
||||
return await _propose(today);
|
||||
} finally {
|
||||
busy = false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<FillOutcome?> _propose(DateTime day) async {
|
||||
final result = await _fetch(day);
|
||||
Future<FillOutcome?> _propose(DateTime today) async {
|
||||
final result = await _fetch(today);
|
||||
// Cancelled while the fetch was in flight: arming now would show
|
||||
// "Confirm (N)" for a plan the user already dismissed.
|
||||
if (_planDay != day) return null;
|
||||
if (_planDay != today) return null;
|
||||
if (!result.ok) return (message: result.reason!, written: _none);
|
||||
if (result.dishes.isEmpty) {
|
||||
final when = day == _today() ? 'today' : 'on ${localDateKey(day)}';
|
||||
return (message: 'No catering delivery $when.', written: _none);
|
||||
return (message: 'No catering delivery today.', written: _none);
|
||||
}
|
||||
final plan = fillPlan(
|
||||
assignSlots(result.dishes, _slots(day)),
|
||||
await _occupied(day),
|
||||
assignSlots(result.dishes, _slots()),
|
||||
await _occupied(),
|
||||
);
|
||||
if (plan.isEmpty) return (message: nothingToFillMessage, written: _none);
|
||||
_plan = plan;
|
||||
@ -144,20 +124,15 @@ class FillAllFlow {
|
||||
try {
|
||||
// Re-checked at write time: a meal logged in between the two taps --
|
||||
// here or synced from the PC -- has taken its slot and keeps it.
|
||||
final day = _planDay!;
|
||||
final plan = fillPlan(_plan, await _occupied(day));
|
||||
final plan = fillPlan(_plan, await _occupied());
|
||||
cancel();
|
||||
if (plan.isEmpty) {
|
||||
return (message: nothingToFillMessage, written: _none);
|
||||
}
|
||||
// A later day's dishes are stamped at their slot times on that day;
|
||||
// today's at now, like any manual log.
|
||||
final later = day == _today() ? null : day;
|
||||
final written = await logDishes(plan, storage: _storage, day: later);
|
||||
final written = await logDishes(plan, storage: _storage);
|
||||
final noun = written.length == 1 ? 'dish' : 'dishes';
|
||||
final suffix = later == null ? '' : ' for ${localDateKey(later)}';
|
||||
return (
|
||||
message: 'Logged ${written.length} catering $noun$suffix.',
|
||||
message: 'Logged ${written.length} catering $noun.',
|
||||
written: written,
|
||||
);
|
||||
} finally {
|
||||
|
||||
@ -182,10 +182,10 @@ packages:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: fl_chart
|
||||
sha256: "5ed69b8be550c6276c8f0bc25c09704fb061018ed1b1681867ad18fcf477e7b7"
|
||||
sha256: b938f77d042cbcd822936a7a359a7235bad8bd72070de1f827efc2cc297ac888
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.3.0"
|
||||
version: "1.2.0"
|
||||
flutter:
|
||||
dependency: "direct main"
|
||||
description: flutter
|
||||
@ -908,10 +908,10 @@ packages:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: web
|
||||
sha256: e119e82ac4795c7925103b7cf3768191f33941b99e7ccffbd6c645201d9f606b
|
||||
sha256: "868d88a33d8a87b18ffc05f9f030ba328ffefba92d6c127917a2ba740f9cfe4a"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.1.2"
|
||||
version: "1.1.1"
|
||||
win32:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
||||
@ -2,7 +2,7 @@ name: diet_guard_app
|
||||
description: "Companion phone app for diet_guard: log meals on the go."
|
||||
publish_to: 'none'
|
||||
|
||||
version: 1.0.121+1
|
||||
version: 1.0.118+1
|
||||
|
||||
environment:
|
||||
sdk: ^3.12.2
|
||||
@ -14,7 +14,7 @@ dependencies:
|
||||
ref: crdt_sync_dart-v0.11.1
|
||||
path: crdt_sync_dart
|
||||
crypto: 3.0.7
|
||||
fl_chart: 1.3.0
|
||||
fl_chart: 1.2.0
|
||||
flutter:
|
||||
sdk: flutter
|
||||
flutter_local_notifications: 22.3.2
|
||||
@ -47,7 +47,7 @@ dependencies:
|
||||
path: sync_settings_ui
|
||||
url_launcher: 6.3.3
|
||||
uuid: 4.6.0
|
||||
web: 1.1.2
|
||||
web: 1.1.1
|
||||
workmanager: 0.10.10
|
||||
|
||||
dev_dependencies:
|
||||
|
||||
@ -25,8 +25,8 @@ void main() {
|
||||
return KuchniaRefresh(dishes: dishes(4));
|
||||
},
|
||||
now: () => DateTime(2026, 8, 23, 10),
|
||||
slots: (_) => defaultSlots,
|
||||
occupiedSlots: (_) async => <int>{},
|
||||
slots: () => defaultSlots,
|
||||
occupiedSlots: () async => <int>{},
|
||||
storage: freshStorage(),
|
||||
);
|
||||
|
||||
|
||||
@ -1,150 +0,0 @@
|
||||
/// "Fill all with catering" with a later date picked through "Log for later".
|
||||
///
|
||||
/// The flow used to hard-code today: picking 24.10 on 23.10 fetched 23.10's
|
||||
/// delivery and reported "No catering delivery today." Each test pins the
|
||||
/// *picked* day end to end -- the fetch, the occupancy, and where the entries
|
||||
/// land -- by reading the log, not a return value.
|
||||
///
|
||||
/// The clock is the real one: `logMeal` refuses a `when` in the past against
|
||||
/// `DateTime.now()`, so the picked day has to be genuinely in the future.
|
||||
library;
|
||||
|
||||
import 'package:diet_guard_app/models/local_time.dart';
|
||||
import 'package:diet_guard_app/models/nutrition.dart';
|
||||
import 'package:diet_guard_app/services/kuchnia_fill_flow.dart';
|
||||
import 'package:diet_guard_app/services/kuchnia_import.dart';
|
||||
import 'package:diet_guard_app/services/kuchnia_queue.dart';
|
||||
import 'package:diet_guard_app/services/log_storage_service.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import 'kuchnia_fill_support.dart';
|
||||
|
||||
/// `desc@slot time` for every live entry stored under [day].
|
||||
Future<List<String>> loggedOn(LogStorageService storage, DateTime day) async {
|
||||
final log = await storage.readLog();
|
||||
return [
|
||||
for (final e in log[localDateKey(day)] ?? const [])
|
||||
if (!e.deleted) '${e.desc}@${e.slotMinute} ${e.time.substring(11, 16)}',
|
||||
];
|
||||
}
|
||||
|
||||
void main() {
|
||||
late LogStorageService storage;
|
||||
late List<DateTime> fetched;
|
||||
late KuchniaRefresh delivery;
|
||||
late FillAllFlow flow;
|
||||
final now = DateTime.now();
|
||||
final tomorrow = DateTime(now.year, now.month, now.day + 1);
|
||||
final dayAfter = DateTime(now.year, now.month, now.day + 2);
|
||||
|
||||
setUp(() {
|
||||
storage = freshStorage();
|
||||
fetched = [];
|
||||
delivery = KuchniaRefresh(dishes: dishes(4));
|
||||
flow = FillAllFlow(
|
||||
fetch: (day) async {
|
||||
fetched.add(day);
|
||||
return delivery;
|
||||
},
|
||||
storage: storage,
|
||||
);
|
||||
});
|
||||
|
||||
tearDown(LogStorageService.resetForTesting);
|
||||
|
||||
test('fetches the picked day and logs onto it at slot times', () async {
|
||||
final first = await flow.tap(day: tomorrow);
|
||||
|
||||
expect(fetched, [tomorrow]);
|
||||
expect(first!.message, startsWith('Will log 4'));
|
||||
expect(await loggedOn(storage, tomorrow), isEmpty);
|
||||
|
||||
final second = await flow.tap(day: tomorrow);
|
||||
|
||||
expect(
|
||||
second!.message,
|
||||
'Logged 4 catering dishes for '
|
||||
'${localDateKey(tomorrow)}.',
|
||||
);
|
||||
expect(await loggedOn(storage, tomorrow), [
|
||||
'D1@480 08:00',
|
||||
'D2@720 12:00',
|
||||
'D3@960 16:00',
|
||||
'D4@1200 20:00',
|
||||
]);
|
||||
expect(await loggedToday(storage), isEmpty);
|
||||
});
|
||||
|
||||
test("occupancy is the picked day's, not today's", () async {
|
||||
// Today's 08:00 is taken, which must not block tomorrow's 08:00 ...
|
||||
await storage.logMeal('eaten today', _kcal, slotMinute: 480);
|
||||
// ... while tomorrow's pre-logged 12:00 keeps its meal.
|
||||
await storage.logMeal(
|
||||
'pre-logged',
|
||||
_kcal,
|
||||
slotMinute: 720,
|
||||
when: tomorrow.add(const Duration(hours: 12)),
|
||||
);
|
||||
|
||||
await flow.tap(day: tomorrow);
|
||||
await flow.tap(day: tomorrow);
|
||||
|
||||
expect(await loggedOn(storage, tomorrow), [
|
||||
'pre-logged@720 12:00',
|
||||
'D1@480 08:00',
|
||||
'D3@960 16:00',
|
||||
'D4@1200 20:00',
|
||||
]);
|
||||
});
|
||||
|
||||
test('a plan proposed for one day never confirms onto another', () async {
|
||||
await flow.tap(day: tomorrow);
|
||||
final outcome = await flow.tap(day: dayAfter);
|
||||
|
||||
expect(fetched, [tomorrow, dayAfter]);
|
||||
expect(outcome!.written, isEmpty);
|
||||
expect(await loggedOn(storage, tomorrow), isEmpty);
|
||||
expect(await loggedOn(storage, dayAfter), isEmpty);
|
||||
});
|
||||
|
||||
test('an empty delivery names the picked day', () async {
|
||||
delivery = const KuchniaRefresh(dishes: []);
|
||||
|
||||
final outcome = await flow.tap(day: tomorrow);
|
||||
|
||||
expect(
|
||||
outcome!.message,
|
||||
'No catering delivery on ${localDateKey(tomorrow)}.',
|
||||
);
|
||||
});
|
||||
|
||||
test('no day still means today', () async {
|
||||
await flow.tap();
|
||||
|
||||
expect(fetched, [DateTime(now.year, now.month, now.day)]);
|
||||
});
|
||||
|
||||
test("a later day's fetch never marks that day as already fetched", () async {
|
||||
// The marker holds one day, read by the automatic "Today's delivery"
|
||||
// fetch: recording tomorrow would skip that fetch when tomorrow comes.
|
||||
await KuchniaQueueService.initForTesting(MemoryStore());
|
||||
addTearDown(KuchniaQueueService.resetForTesting);
|
||||
final today = DateTime(now.year, now.month, now.day);
|
||||
Future<KuchniaRefresh> fake(DateTime _) async => delivery;
|
||||
|
||||
await fetchAndRecord(tomorrow, fetch: fake);
|
||||
expect(KuchniaQueueService.instance.alreadyFetched(tomorrow), isFalse);
|
||||
|
||||
await fetchAndRecord(today, fetch: fake);
|
||||
expect(KuchniaQueueService.instance.alreadyFetched(today), isTrue);
|
||||
});
|
||||
}
|
||||
|
||||
const _kcal = Nutrition(
|
||||
grams: 100,
|
||||
kcal: 100,
|
||||
proteinG: 1,
|
||||
carbsG: 1,
|
||||
fatG: 1,
|
||||
source: 'manual',
|
||||
);
|
||||
@ -49,8 +49,8 @@ void main() {
|
||||
flow = FillAllFlow(
|
||||
fetch: fetcher.call,
|
||||
now: () => clock,
|
||||
slots: (_) => defaultSlots,
|
||||
occupiedSlots: (_) async {
|
||||
slots: () => defaultSlots,
|
||||
occupiedSlots: () async {
|
||||
occupancyReads++;
|
||||
if (occupancyGate != null) await occupancyGate!.future;
|
||||
return {...occupied};
|
||||
|
||||
@ -12,9 +12,7 @@
|
||||
library;
|
||||
|
||||
import 'package:diet_guard_app/models/kuchnia_dish.dart';
|
||||
import 'package:diet_guard_app/models/local_time.dart';
|
||||
import 'package:diet_guard_app/screens/log_meal_fill_mixin.dart';
|
||||
import 'package:diet_guard_app/screens/log_meal_future_mixin.dart';
|
||||
import 'package:diet_guard_app/screens/log_meal_kuchnia_mixin.dart';
|
||||
import 'package:diet_guard_app/screens/log_meal_sync_mixin.dart';
|
||||
import 'package:diet_guard_app/services/kuchnia_fill.dart';
|
||||
@ -44,7 +42,6 @@ class _HostState extends State<_Host>
|
||||
WidgetsBindingObserver,
|
||||
LogMealSyncMixin<_Host>,
|
||||
LogMealKuchniaMixin<_Host>,
|
||||
LogMealFutureMixin<_Host>,
|
||||
LogMealFillMixin<_Host> {
|
||||
final TextEditingController desc = TextEditingController();
|
||||
final MacroControllers macros = MacroControllers();
|
||||
@ -68,7 +65,7 @@ class _HostState extends State<_Host>
|
||||
super.initState();
|
||||
fillFlow = FillAllFlow(
|
||||
fetch: (_) async => KuchniaRefresh(dishes: widget.delivery),
|
||||
slots: (_) => defaultSlots,
|
||||
slots: () => defaultSlots,
|
||||
storage: widget.storage,
|
||||
);
|
||||
}
|
||||
@ -178,8 +175,8 @@ void main() {
|
||||
await pumpHost(t);
|
||||
host.fillFlow = FillAllFlow(
|
||||
fetch: (_) async => KuchniaRefresh(dishes: delivery),
|
||||
slots: (_) => defaultSlots,
|
||||
occupiedSlots: (_) async => throw Exception('storage unavailable'),
|
||||
slots: () => defaultSlots,
|
||||
occupiedSlots: () async => throw Exception('storage unavailable'),
|
||||
storage: storage,
|
||||
);
|
||||
|
||||
@ -189,43 +186,4 @@ void main() {
|
||||
expect(host.publishes, 1, reason: 'a partial batch must still sync');
|
||||
expect(host.fillFlow.busy, isFalse);
|
||||
});
|
||||
|
||||
testWidgets('a later-day fill leaves today alone and returns to it', (
|
||||
t,
|
||||
) async {
|
||||
final now = DateTime.now();
|
||||
final tomorrow = DateTime(now.year, now.month, now.day + 1);
|
||||
await pumpHost(t);
|
||||
await t.runAsync(() async {
|
||||
await host.selectLogDate(tomorrow);
|
||||
await host.onFillAll();
|
||||
await host.onFillAll();
|
||||
});
|
||||
|
||||
expect(
|
||||
host.status,
|
||||
'Logged 4 catering dishes for ${localDateKey(tomorrow)}.',
|
||||
);
|
||||
final log = await t.runAsync(storage.readLog);
|
||||
expect(log![localDateKey(tomorrow)], hasLength(4));
|
||||
expect(await t.runAsync(storage.todayEntries), isEmpty);
|
||||
expect(host.publishes, 1);
|
||||
expect(KuchniaQueueService.remaining, 4, reason: "today's queue untouched");
|
||||
expect(host.desc.text, 'D1');
|
||||
expect(host.futureDate, isNull);
|
||||
});
|
||||
|
||||
testWidgets('changing the date disarms a proposal', (t) async {
|
||||
final now = DateTime.now();
|
||||
await pumpHost(t);
|
||||
await t.runAsync(() async {
|
||||
await host.selectLogDate(DateTime(now.year, now.month, now.day + 1));
|
||||
await host.onFillAll();
|
||||
});
|
||||
expect(host.fillFlow.armedCount, 4);
|
||||
|
||||
host.resetFutureLog();
|
||||
|
||||
expect(host.fillFlow.armedCount, 0);
|
||||
});
|
||||
}
|
||||
|
||||
|
Before Width: | Height: | Size: 794 B After Width: | Height: | Size: 917 B |
|
Before Width: | Height: | Size: 3.9 KiB After Width: | Height: | Size: 5.2 KiB |
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 8.1 KiB |
|
Before Width: | Height: | Size: 3.9 KiB After Width: | Height: | Size: 5.5 KiB |
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 20 KiB |
@ -76,7 +76,7 @@ WRAPPER
|
||||
install -Dm644 /dev/stdin "$pkgdir/usr/share/applications/diet-guard-app.desktop" <<'DESKTOP'
|
||||
[Desktop Entry]
|
||||
Type=Application
|
||||
Name=DietGuard
|
||||
Name=diet guard
|
||||
Comment=Diet logging and budget companion
|
||||
Exec=/usr/bin/diet-guard-app
|
||||
Icon=diet-guard-app
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
# Runtime: tkinter/json/hmac/fcntl (stdlib) plus gatelock and requests below.
|
||||
bandit==1.9.4
|
||||
codespell==2.4.3
|
||||
coverage==7.17.0
|
||||
coverage==7.16.2
|
||||
crdt-sync @ git+https://github.com/kuhyx/utils@crdt-sync-v0.9.2#subdirectory=crdt-sync
|
||||
defusedxml==0.7.1
|
||||
freedays @ git+https://github.com/kuhyx/utils@freedays-v0.4.0#subdirectory=freedays
|
||||
@ -19,5 +19,5 @@ pytest-sugar==1.1.1
|
||||
pytest-xdist==3.8.0
|
||||
pytest-xvfb==3.1.1
|
||||
requests==2.34.2
|
||||
ruff==0.17.2
|
||||
ruff==0.17.1
|
||||
sickdays @ git+https://github.com/kuhyx/utils@sickdays-v0.3.0#subdirectory=sickdays
|
||||
|
||||