Progress gives a Day/Week/Month view of routines held against a weekly target, compared with the same point of the previous period, with active time and the daily streak. Targets & reminders sets routines and minutes per week and schedules a heads-up before each routine. The runner's summary now shows today's held count and streak. Finished runs are mirrored to a device run log that feeds both. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KhQh614DMeYoQEH9SoMRUw
61 lines
1.9 KiB
Dart
61 lines
1.9 KiB
Dart
import '../../about/external/data/RoutineChain.dart';
|
|
import '../../about/external/data/pages/request/HistoryRequest.dart';
|
|
import '../../about/external/data/pages/request/PageAndSort.dart';
|
|
import '../../about/external/data/pages/request/Pageable.dart';
|
|
import '../../about/external/data/pages/request/Sort.dart';
|
|
import '../../about/internal/application/ProgressTargets.dart';
|
|
import '../../configs/NotificationServiceConfig.dart';
|
|
import '../../utils/ObjectConvertors.dart';
|
|
import '../../utils/ProgressEngine.dart';
|
|
import '../parent/ParentViewModel.dart';
|
|
import 'ConnectTargetSetup.dart';
|
|
|
|
class ViewTargetSetup extends ParentViewModel {
|
|
ConnectTargetSetup connection;
|
|
|
|
List<RoutineChain> _routines = <RoutineChain>[];
|
|
|
|
ViewTargetSetup(super.context, this.connection);
|
|
|
|
/// Targets are on the device; the routines are only needed to count the
|
|
/// schedule and to place reminders, so their failure is quiet.
|
|
void initialise() async {
|
|
final ProgressTargets targets =
|
|
await getDataManager().getProgressTargets();
|
|
|
|
try {
|
|
final response = await getDataManager().getMyRoutines(HistoryRequest(
|
|
query: PageAndSort(
|
|
sort: Sort('asc', 'startMinute'),
|
|
page: Pageable(0, 0, 50, 0),
|
|
),
|
|
));
|
|
_routines = getRoutineChainList(response.data);
|
|
} catch (e) {
|
|
_routines = <RoutineChain>[];
|
|
}
|
|
|
|
final int scheduled = ProgressEngine.scheduledPerWeek(_routines);
|
|
if (!targets.set && scheduled > 0) {
|
|
targets.routinesPerWeek = scheduled;
|
|
}
|
|
|
|
connection.onTargetsLoaded(targets, scheduled);
|
|
}
|
|
|
|
void save(ProgressTargets targets) async {
|
|
targets.set = true;
|
|
|
|
await getDataManager().setProgressTargets(targets);
|
|
|
|
if (targets.reminders) {
|
|
await LocalNotificationEngine.scheduleRoutineReminders(
|
|
_routines, targets.reminderLead);
|
|
} else {
|
|
await LocalNotificationEngine.cancelRoutineReminders();
|
|
}
|
|
|
|
connection.onTargetsSaved();
|
|
}
|
|
}
|