Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

basic ritual page

laurenspriem49362ce25a9c
diff --git a/mobile/apps/photos/lib/ui/rituals/all_rituals_screen.dart b/mobile/apps/photos/lib/ui/rituals/all_rituals_screen.dart
index cb652ae92f..9703c60717 100644
--- a/mobile/apps/photos/lib/ui/rituals/all_rituals_screen.dart
+++ b/mobile/apps/photos/lib/ui/rituals/all_rituals_screen.dart
@@ -7,6 +7,8 @@ import "package:photos/theme/ente_theme.dart";
import "package:photos/ui/rituals/ritual_camera_page.dart";
import "package:photos/ui/rituals/ritual_day_thumbnail.dart";
import "package:photos/ui/rituals/ritual_editor_dialog.dart";
+import "package:photos/ui/rituals/ritual_page.dart";
+import "package:photos/utils/navigation_util.dart";
class AllRitualsScreen extends StatelessWidget {
const AllRitualsScreen({super.key, this.ritual});
@@ -183,6 +185,12 @@ class _RitualOverviewCard extends StatelessWidget {
];
return GestureDetector(
+ onTap: () {
+ routeToPage(
+ context,
+ RitualPage(ritualId: ritual.id),
+ );
+ },
onLongPress: () async {
final action = await showModalBottomSheet<String>(
context: context,
diff --git a/mobile/apps/photos/lib/ui/rituals/ritual_page.dart b/mobile/apps/photos/lib/ui/rituals/ritual_page.dart
new file mode 100644
index 0000000000..a602bffe17
--- /dev/null
+++ b/mobile/apps/photos/lib/ui/rituals/ritual_page.dart
@@ -0,0 +1,1088 @@
+import "package:flutter/material.dart";
+import "package:intl/intl.dart";
+import "package:photos/l10n/l10n.dart";
+import "package:photos/models/collection/collection_items.dart";
+import "package:photos/models/rituals/ritual_models.dart";
+import "package:photos/service_locator.dart";
+import "package:photos/services/collections_service.dart";
+import "package:photos/theme/ente_theme.dart";
+import "package:photos/ui/rituals/ritual_camera_page.dart";
+import "package:photos/ui/rituals/ritual_day_thumbnail.dart";
+import "package:photos/ui/rituals/ritual_editor_dialog.dart";
+import "package:photos/ui/viewer/gallery/collection_page.dart";
+import "package:photos/utils/navigation_util.dart";
+
+class RitualPage extends StatefulWidget {
+ const RitualPage({
+ super.key,
+ required this.ritualId,
+ });
+
+ final String ritualId;
+
+ @override
+ State<RitualPage> createState() => _RitualPageState();
+}
+
+class _RitualPageState extends State<RitualPage> {
+ late DateTime _visibleMonth;
+
+ @override
+ void initState() {
+ super.initState();
+ final now = DateTime.now();
+ _visibleMonth = DateTime(now.year, now.month);
+ }
+
+ void _goToPreviousMonth() {
+ setState(() {
+ _visibleMonth = DateTime(_visibleMonth.year, _visibleMonth.month - 1);
+ });
+ }
+
+ void _goToNextMonth() {
+ final now = DateTime.now();
+ final currentMonth = DateTime(now.year, now.month);
+ final nextMonth = DateTime(_visibleMonth.year, _visibleMonth.month + 1);
+ if (!nextMonth.isAfter(currentMonth)) {
+ setState(() {
+ _visibleMonth = nextMonth;
+ });
+ }
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ return ValueListenableBuilder<RitualsState>(
+ valueListenable: ritualsService.stateNotifier,
+ builder: (context, state, _) {
+ Ritual? ritual;
+ for (final candidate in state.rituals) {
+ if (candidate.id == widget.ritualId) {
+ ritual = candidate;
+ break;
+ }
+ }
+ final currentRitual = ritual;
+ if (currentRitual == null) {
+ return Scaffold(
+ appBar: AppBar(),
+ body: Center(
+ child: Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 24),
+ child: Text(
+ context.l10n.ritualUntitled,
+ textAlign: TextAlign.center,
+ ),
+ ),
+ ),
+ );
+ }
+
+ final progress = state.summary?.ritualProgress[currentRitual.id];
+ final now = DateTime.now();
+ final todayMidnight = DateTime(now.year, now.month, now.day);
+ final lastStreakDay = _mostRecentStreakDay(
+ ritual: currentRitual,
+ progress: progress,
+ todayMidnight: todayMidnight,
+ );
+
+ final colorScheme = getEnteColorScheme(context);
+ final isDark = Theme.of(context).brightness == Brightness.dark;
+
+ final actionBackground =
+ isDark ? colorScheme.backgroundElevated2 : const Color(0xFFF3F3F3);
+
+ return Scaffold(
+ appBar: AppBar(
+ title: const SizedBox.shrink(),
+ centerTitle: false,
+ actions: [
+ _TopActionButton(
+ background: actionBackground,
+ icon: Icons.photo_camera_outlined,
+ onPressed: () => openRitualCamera(context, currentRitual),
+ tooltip: context.l10n.ritualOpenCameraTooltip,
+ ),
+ const SizedBox(width: 8),
+ _TopActionButton(
+ background: actionBackground,
+ icon: Icons.ios_share,
+ onPressed: () {},
+ tooltip: MaterialLocalizations.of(context).shareButtonLabel,
+ ),
+ const SizedBox(width: 8),
+ _OverflowMenuButton(
+ background: actionBackground,
+ onEdit: () async {
+ await showRitualEditor(context, ritual: currentRitual);
+ },
+ onDelete: () async {
+ await ritualsService.deleteRitual(currentRitual.id);
+ if (context.mounted) {
+ await Navigator.of(context).maybePop();
+ }
+ },
+ ),
+ const SizedBox(width: 16),
+ ],
+ ),
+ body: SafeArea(
+ child: ListView(
+ physics: const BouncingScrollPhysics(),
+ padding: const EdgeInsets.fromLTRB(16, 12, 16, 48),
+ children: [
+ const SizedBox(height: 8),
+ Center(
+ child: _StreakCircle(
+ streak: progress?.currentStreak ?? 0,
+ background:
+ isDark ? colorScheme.backgroundElevated2 : Colors.white,
+ shadow: isDark
+ ? null
+ : const [
+ BoxShadow(
+ color: Color(0x0F000000),
+ blurRadius: 24,
+ offset: Offset(0, 10),
+ ),
+ ],
+ ),
+ ),
+ const SizedBox(height: 18),
+ Center(
+ child: _RitualHeader(
+ ritual: currentRitual,
+ ),
+ ),
+ const SizedBox(height: 18),
+ Row(
+ children: [
+ Expanded(
+ child: _StreakStatCard(
+ label: "Longest this month",
+ streak: progress?.longestStreakThisMonth ?? 0,
+ ),
+ ),
+ const SizedBox(width: 12),
+ Expanded(
+ child: _StreakStatCard(
+ label: "Longest overall",
+ streak: progress?.longestStreakOverall ?? 0,
+ ),
+ ),
+ ],
+ ),
+ const SizedBox(height: 18),
+ _RecentDaysCard(
+ ritual: currentRitual,
+ progress: progress,
+ ),
+ const SizedBox(height: 18),
+ _MonthOverviewCard(
+ ritual: currentRitual,
+ progress: progress,
+ visibleMonth: _visibleMonth,
+ lastStreakDay: lastStreakDay,
+ onPreviousMonth: _goToPreviousMonth,
+ onNextMonth: _goToNextMonth,
+ ),
+ ],
+ ),
+ ),
+ );
+ },
+ );
+ }
+}
+
+class _TopActionButton extends StatelessWidget {
+ const _TopActionButton({
+ required this.background,
+ required this.icon,
+ required this.onPressed,
+ required this.tooltip,
+ });
+
+ final Color background;
+ final IconData icon;
+ final VoidCallback? onPressed;
+ final String tooltip;
+
+ @override
+ Widget build(BuildContext context) {
+ final colorScheme = getEnteColorScheme(context);
+ return IconButton(
+ tooltip: tooltip,
+ style: IconButton.styleFrom(
+ backgroundColor: background,
+ shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
+ padding: const EdgeInsets.all(8),
+ minimumSize: const Size(40, 40),
+ ),
+ icon: Icon(
+ icon,
+ size: 22,
+ color: colorScheme.textBase,
+ ),
+ onPressed: onPressed,
+ );
+ }
+}
+
+enum _RitualOverflowAction { edit, delete }
+
+class _OverflowMenuButton extends StatelessWidget {
+ const _OverflowMenuButton({
+ required this.background,
+ required this.onEdit,
+ required this.onDelete,
+ });
+
+ final Color background;
+ final VoidCallback onEdit;
+ final VoidCallback onDelete;
+
+ @override
+ Widget build(BuildContext context) {
+ final colorScheme = getEnteColorScheme(context);
+ return PopupMenuButton<_RitualOverflowAction>(
+ tooltip: MaterialLocalizations.of(context).showMenuTooltip,
+ onSelected: (action) {
+ switch (action) {
+ case _RitualOverflowAction.edit:
+ onEdit();
+ break;
+ case _RitualOverflowAction.delete:
+ onDelete();
+ break;
+ }
+ },
+ itemBuilder: (context) => [
+ PopupMenuItem(
+ value: _RitualOverflowAction.edit,
+ child: Row(
+ children: [
+ Icon(Icons.edit_outlined, color: colorScheme.textBase, size: 20),
+ const SizedBox(width: 10),
+ Text(context.l10n.edit),
+ ],
+ ),
+ ),
+ PopupMenuItem(
+ value: _RitualOverflowAction.delete,
+ child: Row(
+ children: [
+ const Icon(Icons.delete_outline, color: Colors.red, size: 20),
+ const SizedBox(width: 10),
+ Text(
+ context.l10n.delete,
+ style: const TextStyle(color: Colors.red),
+ ),
+ ],
+ ),
+ ),
+ ],
+ child: Container(
+ width: 40,
+ height: 40,
+ decoration: BoxDecoration(
+ color: background,
+ borderRadius: BorderRadius.circular(10),
+ ),
+ child: Center(
+ child: Icon(
+ Icons.more_horiz,
+ size: 22,
+ color: colorScheme.textBase,
+ ),
+ ),
+ ),
+ );
+ }
+}
+
+class _StreakCircle extends StatelessWidget {
+ const _StreakCircle({
+ required this.streak,
+ required this.background,
+ this.shadow,
+ });
+
+ final int streak;
+ final Color background;
+ final List<BoxShadow>? shadow;
+
+ @override
+ Widget build(BuildContext context) {
+ final colorScheme = getEnteColorScheme(context);
+ final textColor = colorScheme.textBase;
+ return Container(
+ width: 132,
+ height: 132,
+ decoration: BoxDecoration(
+ shape: BoxShape.circle,
+ color: background,
+ boxShadow: shadow,
+ ),
+ child: Center(
+ child: Row(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.end,
+ children: [
+ Text(
+ streak.toString(),
+ textHeightBehavior: _tightTextHeightBehavior,
+ style: TextStyle(
+ fontFamily: "Nunito",
+ fontSize: 64,
+ fontWeight: FontWeight.w900,
+ letterSpacing: -1.6,
+ height: 1,
+ color: textColor,
+ ),
+ ),
+ const SizedBox(width: 2),
+ const Padding(
+ padding: EdgeInsets.only(bottom: 12),
+ child: _LightningIcon(
+ size: 24,
+ color: Color(0xFFFFB800),
+ ),
+ ),
+ ],
+ ),
+ ),
+ );
+ }
+}
+
+class _RitualHeader extends StatelessWidget {
+ const _RitualHeader({
+ required this.ritual,
+ });
+
+ final Ritual ritual;
+
+ @override
+ Widget build(BuildContext context) {
+ final textTheme = getEnteTextTheme(context);
+ final title =
+ ritual.title.isEmpty ? context.l10n.ritualUntitled : ritual.title;
+ return Row(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ Text(
+ ritual.icon,
+ style: textTheme.largeBold.copyWith(height: 1),
+ textHeightBehavior: _tightTextHeightBehavior,
+ ),
+ const SizedBox(width: 8),
+ Text(
+ title,
+ style: textTheme.largeBold,
+ textHeightBehavior: _tightTextHeightBehavior,
+ ),
+ ],
+ );
+ }
+}
+
+class _StreakStatCard extends StatelessWidget {
+ const _StreakStatCard({
+ required this.label,
+ required this.streak,
+ });
+
+ final String label;
+ final int streak;
+
+ @override
+ Widget build(BuildContext context) {
+ final colorScheme = getEnteColorScheme(context);
+ final textTheme = getEnteTextTheme(context);
+ final isDark = Theme.of(context).brightness == Brightness.dark;
+ return Container(
+ padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 14),
+ decoration: BoxDecoration(
+ color:
+ isDark ? colorScheme.backgroundElevated2 : const Color(0xFFFAFAFA),
+ borderRadius: BorderRadius.circular(16),
+ border: Border.all(color: colorScheme.strokeFaint),
+ ),
+ child: Column(
+ children: [
+ Text(
+ label,
+ style: textTheme.tinyMuted,
+ textAlign: TextAlign.center,
+ ),
+ const SizedBox(height: 10),
+ Row(
+ mainAxisAlignment: MainAxisAlignment.center,
+ children: [
+ Text(
+ streak.toString(),
+ style: TextStyle(
+ fontFamily: "Nunito",
+ fontSize: 20,
+ fontWeight: FontWeight.w900,
+ letterSpacing: -0.2,
+ height: 1,
+ color: colorScheme.textBase,
+ ),
+ textHeightBehavior: _tightTextHeightBehavior,
+ ),
+ const SizedBox(width: 6),
+ const _LightningIcon(
+ size: 16,
+ color: Color(0xFFFFB800),
+ ),
+ ],
+ ),
+ ],
+ ),
+ );
+ }
+}
+
+class _RecentDaysCard extends StatelessWidget {
+ const _RecentDaysCard({
+ required this.ritual,
+ required this.progress,
+ });
+
+ final Ritual ritual;
+ final RitualProgress? progress;
+
+ @override
+ Widget build(BuildContext context) {
+ final colorScheme = getEnteColorScheme(context);
+ final isDark = Theme.of(context).brightness == Brightness.dark;
+ final now = DateTime.now();
+ final today = DateTime(now.year, now.month, now.day);
+ final days = _lastScheduledDaysInclusive(
+ ritual: ritual,
+ todayMidnight: today,
+ count: 4,
+ );
+ final completions = [
+ for (final day in days) progress?.hasCompleted(day) ?? false,
+ ];
+
+ return Container(
+ padding: const EdgeInsets.all(16),
+ decoration: BoxDecoration(
+ color:
+ isDark ? colorScheme.backgroundElevated2 : const Color(0xFFFAFAFA),
+ borderRadius: BorderRadius.circular(20),
+ border: Border.all(color: colorScheme.strokeFaint),
+ ),
+ child: LayoutBuilder(
+ builder: (context, constraints) {
+ const spacing = 16.0;
+ const slots = 5;
+ final available = constraints.maxWidth - (spacing * (slots - 1));
+ final tileWidth = available / slots;
+ return Row(
+ crossAxisAlignment: CrossAxisAlignment.end,
+ children: [
+ for (final (index, day) in days.indexed) ...[
+ if (index != 0) const SizedBox(width: spacing),
+ Expanded(
+ child: Align(
+ alignment: Alignment.center,
+ child: _buildDayThumbnail(
+ context: context,
+ ritual: ritual,
+ day: day,
+ tileWidth: tileWidth,
+ completed: completions[index],
+ nextCompleted: index == days.length - 1
+ ? null
+ : completions[index + 1],
+ index: index,
+ ),
+ ),
+ ),
+ ],
+ if (days.isNotEmpty) const SizedBox(width: spacing),
+ Expanded(
+ child: Align(
+ alignment: Alignment.center,
+ child: _AlbumChevronThumbnail(
+ width: tileWidth,
+ onTap: () => _openRitualAlbum(context, ritual),
+ ),
+ ),
+ ),
+ ],
+ );
+ },
+ ),
+ );
+ }
+
+ Widget _buildDayThumbnail({
+ required BuildContext context,
+ required Ritual ritual,
+ required DateTime day,
+ required double tileWidth,
+ required bool completed,
+ required bool? nextCompleted,
+ required int index,
+ }) {
+ final now = DateTime.now();
+ final today = DateTime(now.year, now.month, now.day);
+ final dayKey =
+ DateTime(day.year, day.month, day.day).millisecondsSinceEpoch;
+ final file = progress?.recentFilesByDay[dayKey];
+ final count =
+ progress?.recentFileCountsByDay[dayKey] ?? (completed ? 1 : 0);
+ final fadePhoto = completed && nextCompleted == false;
+ final isToday = _isSameDay(day, today);
+ final rotation = switch (index % 4) {
+ 0 => -0.05,
+ 1 => 0.10,
+ 2 => -0.08,
+ _ => 0.08,
+ };
+
+ final variant = completed
+ ? RitualDayThumbnailVariant.photo
+ : (isToday
+ ? RitualDayThumbnailVariant.camera
+ : RitualDayThumbnailVariant.empty);
+
+ return RitualDayThumbnail(
+ day: day,
+ variant: variant,
+ width: tileWidth,
+ photoFile: file,
+ photoCount: count,
+ fadePhoto: fadePhoto,
+ rotation: rotation,
+ onCameraTap: isToday && !completed
+ ? () => openRitualCamera(context, ritual)
+ : null,
+ );
+ }
+}
+
+class _AlbumChevronThumbnail extends StatelessWidget {
+ const _AlbumChevronThumbnail({
+ required this.width,
+ required this.onTap,
+ });
+
+ final double width;
+ final VoidCallback onTap;
+
+ @override
+ Widget build(BuildContext context) {
+ final colorScheme = getEnteColorScheme(context);
+ final tileHeight = width * (72 / 48);
+ return SizedBox(
+ width: width,
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ Material(
+ color: Colors.transparent,
+ child: InkWell(
+ onTap: onTap,
+ borderRadius: BorderRadius.circular(8),
+ child: Container(
+ width: width,
+ height: tileHeight,
+ decoration: BoxDecoration(
+ color: colorScheme.backgroundElevated,
+ borderRadius: BorderRadius.circular(8),
+ ),
+ child: Center(
+ child: Container(
+ width: 30,
+ height: 30,
+ decoration: BoxDecoration(
+ color: Colors.white,
+ shape: BoxShape.circle,
+ border: Border.all(
+ color: Colors.black.withValues(alpha: 0.06),
+ ),
+ ),
+ child: Icon(
+ Icons.chevron_right_rounded,
+ color: colorScheme.textBase,
+ size: 22,
+ ),
+ ),
+ ),
+ ),
+ ),
+ ),
+ const SizedBox(height: 8),
+ const SizedBox(height: 28),
+ ],
+ ),
+ );
+ }
+}
+
+class _MonthOverviewCard extends StatelessWidget {
+ const _MonthOverviewCard({
+ required this.ritual,
+ required this.progress,
+ required this.visibleMonth,
+ required this.lastStreakDay,
+ required this.onPreviousMonth,
+ required this.onNextMonth,
+ });
+
+ final Ritual ritual;
+ final RitualProgress? progress;
+ final DateTime visibleMonth;
+ final DateTime? lastStreakDay;
+ final VoidCallback onPreviousMonth;
+ final VoidCallback onNextMonth;
+
+ @override
+ Widget build(BuildContext context) {
+ final colorScheme = getEnteColorScheme(context);
+ final textTheme = getEnteTextTheme(context);
+ final isDark = Theme.of(context).brightness == Brightness.dark;
+ final now = DateTime.now();
+ final currentMonth = DateTime(now.year, now.month);
+ final todayMidnight = DateTime(now.year, now.month, now.day);
+
+ final canGoNext = visibleMonth.isBefore(currentMonth);
+ final monthLabel = DateFormat.yMMM(
+ Localizations.localeOf(context).toString(),
+ ).format(visibleMonth);
+
+ final weekdayLabels = _sundayFirstNarrowWeekdays(context);
+
+ return Container(
+ padding: const EdgeInsets.fromLTRB(16, 16, 16, 18),
+ decoration: BoxDecoration(
+ color:
+ isDark ? colorScheme.backgroundElevated2 : const Color(0xFFFAFAFA),
+ borderRadius: BorderRadius.circular(20),
+ border: Border.all(color: colorScheme.strokeFaint),
+ ),
+ child: Column(
+ children: [
+ Row(
+ children: [
+ Expanded(
+ child: Text(
+ monthLabel,
+ style: textTheme.bodyBold,
+ textHeightBehavior: _tightTextHeightBehavior,
+ ),
+ ),
+ Container(
+ decoration: BoxDecoration(
+ color: isDark
+ ? colorScheme.backgroundElevated
+ : const Color(0xFFF3F3F3),
+ borderRadius: BorderRadius.circular(14),
+ border: Border.all(color: colorScheme.strokeFaint),
+ ),
+ child: Row(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ _MonthChevronButton(
+ icon: Icons.chevron_left_rounded,
+ onTap: onPreviousMonth,
+ enabled: true,
+ ),
+ _MonthChevronButton(
+ icon: Icons.chevron_right_rounded,
+ onTap: onNextMonth,
+ enabled: canGoNext,
+ ),
+ ],
+ ),
+ ),
+ ],
+ ),
+ const SizedBox(height: 18),
+ Row(
+ children: [
+ for (final label in weekdayLabels)
+ Expanded(
+ child: Center(
+ child: Text(
+ label,
+ style: textTheme.miniMuted,
+ textHeightBehavior: _tightTextHeightBehavior,
+ ),
+ ),
+ ),
+ ],
+ ),
+ const SizedBox(height: 14),
+ _MonthGrid(
+ ritual: ritual,
+ progress: progress,
+ visibleMonth: visibleMonth,
+ todayMidnight: todayMidnight,
+ lastStreakDay: lastStreakDay,
+ ),
+ ],
+ ),
+ );
+ }
+}
+
+class _MonthChevronButton extends StatelessWidget {
+ const _MonthChevronButton({
+ required this.icon,
+ required this.onTap,
+ required this.enabled,
+ });
+
+ final IconData icon;
+ final VoidCallback onTap;
+ final bool enabled;
+
+ @override
+ Widget build(BuildContext context) {
+ final colorScheme = getEnteColorScheme(context);
+ return InkWell(
+ onTap: enabled ? onTap : null,
+ borderRadius: BorderRadius.circular(14),
+ child: SizedBox(
+ width: 36,
+ height: 34,
+ child: Icon(
+ icon,
+ size: 20,
+ color: enabled ? colorScheme.textBase : colorScheme.textFaint,
+ ),
+ ),
+ );
+ }
+}
+
+class _MonthGrid extends StatelessWidget {
+ const _MonthGrid({
+ required this.ritual,
+ required this.progress,
+ required this.visibleMonth,
+ required this.todayMidnight,
+ required this.lastStreakDay,
+ });
+
+ final Ritual ritual;
+ final RitualProgress? progress;
+ final DateTime visibleMonth;
+ final DateTime todayMidnight;
+ final DateTime? lastStreakDay;
+
+ static const _cellSize = 34.0;
+ static const _cellSpacingX = 10.0;
+ static const _cellSpacingY = 14.0;
+
+ @override
+ Widget build(BuildContext context) {
+ final colorScheme = getEnteColorScheme(context);
+ final textTheme = getEnteTextTheme(context);
+
+ final firstDay = DateTime(visibleMonth.year, visibleMonth.month, 1);
+ final daysInMonth =
+ DateTime(visibleMonth.year, visibleMonth.month + 1, 0).day;
+ final leadingEmpty = firstDay.weekday % 7; // Sunday-first
+ final totalDaysCells = leadingEmpty + daysInMonth;
+ final trailingEmpty = (7 - (totalDaysCells % 7)) % 7;
+ final totalCells = totalDaysCells + trailingEmpty;
+
+ final lastStreakKey = lastStreakDay == null
+ ? null
+ : DateTime(
+ lastStreakDay!.year,
+ lastStreakDay!.month,
+ lastStreakDay!.day,
+ ).millisecondsSinceEpoch;
+
+ return GridView.builder(
+ shrinkWrap: true,
+ physics: const NeverScrollableScrollPhysics(),
+ gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
+ crossAxisCount: 7,
+ mainAxisSpacing: _cellSpacingY,
+ crossAxisSpacing: _cellSpacingX,
+ childAspectRatio: 1,
+ ),
+ itemCount: totalCells,
+ itemBuilder: (context, index) {
+ if (index < leadingEmpty || index >= leadingEmpty + daysInMonth) {
+ return const SizedBox.shrink();
+ }
+ final dayNumber = index - leadingEmpty + 1;
+ final day = DateTime(visibleMonth.year, visibleMonth.month, dayNumber);
+ final dayKey =
+ DateTime(day.year, day.month, day.day).millisecondsSinceEpoch;
+ final enabled = _isEnabledDay(ritual, day);
+ final completed = progress?.completedDayKeys.contains(dayKey) ?? false;
+ final isFuture = day.isAfter(todayMidnight);
+ final isLastStreakDay =
+ lastStreakKey != null && dayKey == lastStreakKey;
+
+ if (!enabled) {
+ return const _CrossedOutDay(size: _cellSize);
+ }
+
+ if (isLastStreakDay) {
+ return const Center(
+ child: _LightningIcon(size: 18, color: Color(0xFFFFB800)),
+ );
+ }
+
+ if (completed) {
+ return Center(
+ child: Container(
+ width: _cellSize,
+ height: _cellSize,
+ decoration: const BoxDecoration(
+ color: Color(0xFF1DB954),
+ shape: BoxShape.circle,
+ ),
+ child: const Center(
+ child: _LightningIcon(size: 16, color: Colors.white),
+ ),
+ ),
+ );
+ }
+
+ return Center(
+ child: Text(
+ dayNumber.toString(),
+ style: (isFuture ? textTheme.smallFaint : textTheme.small).copyWith(
+ height: 1,
+ color: isFuture ? colorScheme.textFaint : colorScheme.textMuted,
+ ),
+ textHeightBehavior: _tightTextHeightBehavior,
+ ),
+ );
+ },
+ );
+ }
+}
+
+class _CrossedOutDay extends StatelessWidget {
+ const _CrossedOutDay({required this.size});
+
+ final double size;
+
+ @override
+ Widget build(BuildContext context) {
+ final colorScheme = getEnteColorScheme(context);
+ final isDark = Theme.of(context).brightness == Brightness.dark;
+ final background =
+ isDark ? colorScheme.backgroundElevated : const Color(0xFFF3F3F3);
+ final stroke =
+ isDark ? colorScheme.strokeFaint : Colors.black.withValues(alpha: 0.08);
+ return Center(
+ child: SizedBox(
+ width: size,
+ height: size,
+ child: ClipOval(
+ child: ColoredBox(
+ color: background,
+ child: CustomPaint(
+ painter: _CrossHatchPainter(
+ color: stroke,
+ strokeWidth: 1,
+ gap: 5,
+ ),
+ ),
+ ),
+ ),
+ ),
+ );
+ }
+}
+
+class _CrossHatchPainter extends CustomPainter {
+ const _CrossHatchPainter({
+ required this.color,
+ required this.strokeWidth,
+ required this.gap,
+ });
+
+ final Color color;
+ final double strokeWidth;
+ final double gap;
+
+ @override
+ void paint(Canvas canvas, Size size) {
+ final paint = Paint()
+ ..color = color
+ ..strokeWidth = strokeWidth
+ ..style = PaintingStyle.stroke;
+
+ final diagonal = size.height;
+ for (double startX = -diagonal;
+ startX < size.width + diagonal;
+ startX += gap) {
+ canvas.drawLine(
+ Offset(startX, 0),
+ Offset(startX + diagonal, diagonal),
+ paint,
+ );
+ }
+ }
+
+ @override
+ bool shouldRepaint(_CrossHatchPainter oldDelegate) {
+ return oldDelegate.color != color ||
+ oldDelegate.strokeWidth != strokeWidth ||
+ oldDelegate.gap != gap;
+ }
+}
+
+class _LightningIcon extends StatelessWidget {
+ const _LightningIcon({
+ required this.size,
+ required this.color,
+ });
+
+ final double size;
+ final Color color;
+
+ @override
+ Widget build(BuildContext context) {
+ return CustomPaint(
+ size: Size.square(size),
+ painter: _LightningPainter(color: color),
+ );
+ }
+}
+
+class _LightningPainter extends CustomPainter {
+ const _LightningPainter({required this.color});
+
+ final Color color;
+
+ @override
+ void paint(Canvas canvas, Size size) {
+ final paint = Paint()
+ ..color = color
+ ..style = PaintingStyle.fill;
+
+ final w = size.width;
+ final h = size.height;
+
+ final path = Path()
+ ..moveTo(w * 0.58, h * 0.05)
+ ..lineTo(w * 0.22, h * 0.56)
+ ..lineTo(w * 0.50, h * 0.56)
+ ..lineTo(w * 0.36, h * 0.96)
+ ..lineTo(w * 0.80, h * 0.42)
+ ..lineTo(w * 0.54, h * 0.42)
+ ..close();
+
+ canvas.drawPath(path, paint);
+ }
+
+ @override
+ bool shouldRepaint(_LightningPainter oldDelegate) {
+ return oldDelegate.color != color;
+ }
+}
+
+Future<void> _openRitualAlbum(BuildContext context, Ritual ritual) async {
+ final albumId = ritual.albumId;
+ if (albumId == null || albumId <= 0) {
+ ScaffoldMessenger.of(context).showSnackBar(
+ SnackBar(
+ content: Text(context.l10n.ritualAlbumMissing),
+ ),
+ );
+ return;
+ }
+ final collection = CollectionsService.instance.getCollectionByID(albumId);
+ if (collection == null) {
+ ScaffoldMessenger.of(context).showSnackBar(
+ SnackBar(
+ content: Text(context.l10n.ritualAlbumMissing),
+ ),
+ );
+ return;
+ }
+ final thumbnail = await CollectionsService.instance.getCover(collection);
+ if (!context.mounted) return;
+ await routeToPage(
+ context,
+ CollectionPage(CollectionWithThumbnail(collection, thumbnail)),
+ );
+}
+
+DateTime? _mostRecentStreakDay({
+ required Ritual ritual,
+ required RitualProgress? progress,
+ required DateTime todayMidnight,
+}) {
+ if (progress == null || progress.currentStreak <= 0) return null;
+ final daysOfWeek = ritual.daysOfWeek;
+ if (daysOfWeek.length != 7 || !daysOfWeek.any((enabled) => enabled)) {
+ return null;
+ }
+
+ for (int offset = 0; offset < 366; offset++) {
+ final day = todayMidnight.subtract(Duration(days: offset));
+ final weekdayIndex = day.weekday % 7; // Sunday-first
+ if (!daysOfWeek[weekdayIndex]) continue;
+ return progress.hasCompleted(day) ? day : null;
+ }
+ return null;
+}
+
+List<DateTime> _lastScheduledDaysInclusive({
+ required Ritual ritual,
+ required DateTime todayMidnight,
+ required int count,
+}) {
+ final daysOfWeek = ritual.daysOfWeek;
+ if (daysOfWeek.length != 7 || !daysOfWeek.any((enabled) => enabled)) {
+ return const [];
+ }
+
+ final result = <DateTime>[];
+ for (int offset = 0; result.length < count && offset < 366; offset++) {
+ final day = todayMidnight.subtract(Duration(days: offset));
+ final weekdayIndex = day.weekday % 7; // Sunday-first
+ if (!daysOfWeek[weekdayIndex]) continue;
+ result.add(day);
+ }
+ return result.reversed.toList(growable: false);
+}
+
+bool _isSameDay(DateTime a, DateTime b) {
+ return a.year == b.year && a.month == b.month && a.day == b.day;
+}
+
+bool _isEnabledDay(Ritual ritual, DateTime day) {
+ final daysOfWeek = ritual.daysOfWeek;
+ if (daysOfWeek.length != 7) return true;
+ final weekdayIndex = day.weekday % 7; // Sunday-first
+ return daysOfWeek[weekdayIndex];
+}
+
+List<String> _sundayFirstNarrowWeekdays(BuildContext context) {
+ final labels = MaterialLocalizations.of(context).narrowWeekdays;
+ if (labels.length != 7) {
+ return const ["S", "M", "T", "W", "T", "F", "S"];
+ }
+ return <String>[
+ labels.last,
+ ...labels.sublist(0, 6),
+ ];
+}
+
+const _tightTextHeightBehavior = TextHeightBehavior(
+ applyHeightToFirstAscent: false,
+ applyHeightToLastDescent: false,
+);