mirror of
https://github.com/kuhyx/wake-alarm.git
synced 2026-11-28 07:49:35 +01:00
The shared pool (~/utils/freedays) was CLI-only: the gates on the PC stood down, but the phone kept ringing at 08:00 and there was nowhere to mark a day from bed. This is the one picker for every app. FreeDayPool is a Dart port of the Python rules with the identical record shape (id = ISO date; state/consumed/actor/reason on one tick; un-mark is a state flip, never a tombstone), verified by a real cross-language round trip: a log written here reads back through freedays.is_free_day and remaining() with the same verdicts and count, and the PC's live pool reads here as the same 27 of 35 that `freedays status` prints. The alarm fires from Kotlin with no engine running, so the pool is mirrored into a native SharedPreferences set after every mark, release and sync (channel method setFreeDays), and AlarmReceiver consults it before starting AlarmService. Fail closed: a missing or corrupt cache rings. All three branches exercised on the API 36 AVD by broadcasting the receiver. Firebase only for this namespace -- no GitHub mirror; the alarm record keeps its own because un-migrated installs depend on it. Known gap, documented rather than papered over: a day marked on the PC reaches the phone at the next app launch or picker open, not overnight. The ring path takes no background dependency by design, so mark on the phone, or open the app once after marking on the PC. Verified on the phone (release build, 23181JEGR08034): picker shows the budget, marks 2026-09-30 with a reason, pushes it to freedays-sync/devices/<uuid>, releases it with a full refund back to 35. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019pBgaXSJKyY3DarYpDatDF
112 lines
3.6 KiB
Dart
112 lines
3.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:wake_alarm_sync/services/free_day_pool.dart';
|
|
import 'package:wake_alarm_sync/ui/theme.dart';
|
|
|
|
/// One upcoming free day, as the list shows it.
|
|
typedef UpcomingFreeDay = ({DateTime day, String reason});
|
|
|
|
/// The picker's body: the year's budget, the upcoming days, the status line.
|
|
///
|
|
/// Stateless and fed plain values, like `HomeBody`: the screen owns the pool
|
|
/// and the sync ordering, this only draws.
|
|
class FreeDaysBody extends StatelessWidget {
|
|
/// Creates the body from already-resolved state.
|
|
const FreeDaysBody({
|
|
required this.year,
|
|
required this.remaining,
|
|
required this.upcoming,
|
|
required this.status,
|
|
required this.busy,
|
|
required this.onRelease,
|
|
super.key,
|
|
});
|
|
|
|
/// The calendar year the budget line describes.
|
|
final int year;
|
|
|
|
/// Days left in [year].
|
|
final int remaining;
|
|
|
|
/// Free days from today on, ascending.
|
|
final List<UpcomingFreeDay> upcoming;
|
|
|
|
/// The status line; may be a raw `Error: …`.
|
|
final String status;
|
|
|
|
/// Whether a sync is in flight, disabling the release buttons.
|
|
final bool busy;
|
|
|
|
/// Called when the user gives a day back.
|
|
final void Function(DateTime day) onRelease;
|
|
|
|
static const _weekdays = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
|
|
|
|
String _label(DateTime day) =>
|
|
'${_weekdays[day.weekday - 1]} ${FreeDayPool.toIso(day)}';
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final theme = Theme.of(context);
|
|
final statusColors = theme.extension<AppStatusColors>()!;
|
|
return SafeArea(
|
|
child: ListView(
|
|
// Bottom room for the extended FAB, so the last row stays tappable.
|
|
padding: const EdgeInsets.fromLTRB(16, 16, 16, 96),
|
|
children: [
|
|
Text(
|
|
'$remaining of ${FreeDayPool.annualBudget}',
|
|
style: theme.textTheme.displayMedium?.copyWith(
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
Text(
|
|
'free days left in $year',
|
|
style: theme.textTheme.bodyMedium?.copyWith(
|
|
color: theme.colorScheme.onSurfaceVariant,
|
|
),
|
|
),
|
|
const SizedBox(height: 8),
|
|
Text(
|
|
'On a free day nothing locks, nothing rings and nothing asks. '
|
|
'Every app, at once.',
|
|
style: theme.textTheme.bodySmall?.copyWith(
|
|
color: theme.colorScheme.onSurfaceVariant,
|
|
),
|
|
),
|
|
if (status.isNotEmpty) ...[
|
|
const SizedBox(height: 16),
|
|
Text(
|
|
status,
|
|
maxLines: 4,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: TextStyle(
|
|
color: status.contains('Error')
|
|
? theme.colorScheme.error
|
|
: statusColors.success,
|
|
),
|
|
),
|
|
],
|
|
const SizedBox(height: 24),
|
|
Text('Booked ahead', style: theme.textTheme.titleMedium),
|
|
const SizedBox(height: 8),
|
|
if (upcoming.isEmpty)
|
|
Text(
|
|
'None. Tap "Take a day" to book one.',
|
|
style: TextStyle(color: theme.colorScheme.onSurfaceVariant),
|
|
),
|
|
for (final entry in upcoming)
|
|
ListTile(
|
|
contentPadding: EdgeInsets.zero,
|
|
title: Text(_label(entry.day)),
|
|
subtitle: entry.reason.isEmpty ? null : Text(entry.reason),
|
|
trailing: TextButton(
|
|
onPressed: busy ? null : () => onRelease(entry.day),
|
|
child: const Text('Release'),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|