Skip to content

armgit / ente

Public Imported from GitHub
0

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

Improve first ritual experience

laurenspriem7ad4d3d4139a
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 9f1d1d6dcd..48ab5658f6 100644
--- a/mobile/apps/photos/lib/ui/rituals/all_rituals_screen.dart
+++ b/mobile/apps/photos/lib/ui/rituals/all_rituals_screen.dart
@@ -116,28 +116,14 @@ class _RitualOverviewCard extends StatelessWidget {
final textTheme = getEnteTextTheme(context);
final now = DateTime.now();
final today = DateTime(now.year, now.month, now.day);
- final pastDays = _lastScheduledDaysInclusive(
+ final preview = _ritualPreviewDays(
ritual: ritual,
+ progress: progress,
todayMidnight: today,
count: 5,
);
- final pastCompletions = [
- for (final day in pastDays) progress?.hasCompleted(day) ?? false,
- ];
- final hasTodayInPreview = pastDays.any((day) => _isSameDay(day, today));
- final createdToday = _isSameDay(ritual.createdAt, today);
- final showFuturePreview = createdToday &&
- hasTodayInPreview &&
- progress != null &&
- !pastCompletions.any((completed) => completed);
-
- final days = showFuturePreview
- ? _nextScheduledDaysInclusive(
- ritual: ritual,
- todayMidnight: today,
- count: 5,
- )
- : pastDays;
+ final days = preview.days;
+ final showFuturePreview = preview.showFuturePreview;
final completions = [
for (final day in days) progress?.hasCompleted(day) ?? false,
];
@@ -276,9 +262,10 @@ class _RitualOverviewCard extends StatelessWidget {
final file = progress?.recentFilesByDay[dayKey];
final count =
progress?.recentFileCountsByDay[dayKey] ?? (completed ? 1 : 0);
- final isYesterday = _isSameDay(day, yesterday);
- final fadePhoto = completed && nextCompleted == false && !isYesterday;
final isToday = _isSameDay(day, today);
+ final isYesterday = _isSameDay(day, yesterday);
+ final fadePhoto =
+ completed && nextCompleted == false && !isYesterday && !isToday;
final rotation = switch (index % 4) {
0 => -0.05,
1 => 0.10,
@@ -444,6 +431,98 @@ bool _isSameDay(DateTime a, DateTime b) {
return a.year == b.year && a.month == b.month && a.day == b.day;
}
+({List<DateTime> days, bool showFuturePreview}) _ritualPreviewDays({
+ required Ritual ritual,
+ required RitualProgress? progress,
+ required DateTime todayMidnight,
+ required int count,
+}) {
+ final pastDays = _lastScheduledDaysInclusive(
+ ritual: ritual,
+ todayMidnight: todayMidnight,
+ count: count,
+ );
+ final todayScheduled = pastDays.any((day) => _isSameDay(day, todayMidnight));
+
+ if (progress == null || count <= 1) {
+ return (days: pastDays, showFuturePreview: false);
+ }
+
+ final createdAt = ritual.createdAt.toLocal();
+ final createdDayMidnight =
+ DateTime(createdAt.year, createdAt.month, createdAt.day);
+
+ final lookbackCount = count - 1;
+ final daysBeforeCreation = _lastScheduledDaysInclusive(
+ ritual: ritual,
+ todayMidnight: createdDayMidnight.subtract(const Duration(days: 1)),
+ count: lookbackCount,
+ );
+ final hadCompletionsBeforeCreation =
+ daysBeforeCreation.any(progress.hasCompleted);
+ if (hadCompletionsBeforeCreation) {
+ return (days: pastDays, showFuturePreview: false);
+ }
+
+ final maxShift = count - 1;
+ final shiftSlots = _scheduledSlotsSinceCreation(
+ ritual: ritual,
+ createdDayMidnight: createdDayMidnight,
+ todayMidnight: todayMidnight,
+ maxSlots: maxShift,
+ );
+ if (shiftSlots >= maxShift) {
+ return (days: pastDays, showFuturePreview: false);
+ }
+
+ final shiftedPast = todayScheduled
+ ? _lastScheduledDaysInclusive(
+ ritual: ritual,
+ todayMidnight: todayMidnight,
+ count: shiftSlots + 1,
+ )
+ : _lastScheduledDaysInclusive(
+ ritual: ritual,
+ todayMidnight: todayMidnight,
+ count: shiftSlots,
+ );
+ final shiftedFuture = _nextScheduledDaysInclusive(
+ ritual: ritual,
+ todayMidnight: todayMidnight,
+ count: count - shiftSlots,
+ );
+ final days = [
+ ...shiftedPast,
+ ...(todayScheduled ? shiftedFuture.skip(1) : shiftedFuture),
+ ];
+ return (days: days, showFuturePreview: true);
+}
+
+int _scheduledSlotsSinceCreation({
+ required Ritual ritual,
+ required DateTime createdDayMidnight,
+ required DateTime todayMidnight,
+ required int maxSlots,
+}) {
+ if (maxSlots <= 0) return 0;
+ if (todayMidnight.isBefore(createdDayMidnight)) return 0;
+
+ final daysOfWeek = ritual.daysOfWeek;
+ if (daysOfWeek.length != 7 || !daysOfWeek.any((enabled) => enabled)) {
+ return 0;
+ }
+
+ int slots = 0;
+ for (int offset = 1; slots < maxSlots && offset < 366; offset++) {
+ final day = todayMidnight.subtract(Duration(days: offset));
+ if (day.isBefore(createdDayMidnight)) break;
+ final weekdayIndex = day.weekday % 7; // Sunday-first
+ if (!daysOfWeek[weekdayIndex]) continue;
+ slots += 1;
+ }
+ return slots;
+}
+
const _tightTextHeightBehavior = TextHeightBehavior(
applyHeightToFirstAscent: false,
applyHeightToLastDescent: false,
diff --git a/mobile/apps/photos/lib/ui/rituals/ritual_page.dart b/mobile/apps/photos/lib/ui/rituals/ritual_page.dart
index 456caad7d7..bbabf7c5b4 100644
--- a/mobile/apps/photos/lib/ui/rituals/ritual_page.dart
+++ b/mobile/apps/photos/lib/ui/rituals/ritual_page.dart
@@ -685,28 +685,14 @@ class _RecentDaysCard extends StatelessWidget {
final isDark = Theme.of(context).brightness == Brightness.dark;
final now = DateTime.now();
final today = DateTime(now.year, now.month, now.day);
- final pastDays = _lastScheduledDaysInclusive(
+ final preview = _ritualPreviewDays(
ritual: ritual,
+ progress: progress,
todayMidnight: today,
count: 4,
);
- final pastCompletions = [
- for (final day in pastDays) progress?.hasCompleted(day) ?? false,
- ];
- final hasTodayInPreview = pastDays.any((day) => _isSameDay(day, today));
- final createdToday = _isSameDay(ritual.createdAt, today);
- final showFuturePreview = createdToday &&
- hasTodayInPreview &&
- progress != null &&
- !pastCompletions.any((completed) => completed);
-
- final days = showFuturePreview
- ? _nextScheduledDaysInclusive(
- ritual: ritual,
- todayMidnight: today,
- count: 4,
- )
- : pastDays;
+ final days = preview.days;
+ final showFuturePreview = preview.showFuturePreview;
final completions = [
for (final day in days) progress?.hasCompleted(day) ?? false,
];
@@ -783,9 +769,10 @@ class _RecentDaysCard extends StatelessWidget {
final file = progress?.recentFilesByDay[dayKey];
final count =
progress?.recentFileCountsByDay[dayKey] ?? (completed ? 1 : 0);
- final isYesterday = _isSameDay(day, yesterday);
- final fadePhoto = completed && nextCompleted == false && !isYesterday;
final isToday = _isSameDay(day, today);
+ final isYesterday = _isSameDay(day, yesterday);
+ final fadePhoto =
+ completed && nextCompleted == false && !isYesterday && !isToday;
final rotation = switch (index % 4) {
0 => -0.05,
1 => 0.10,
@@ -1470,6 +1457,98 @@ bool _isSameDay(DateTime a, DateTime b) {
return a.year == b.year && a.month == b.month && a.day == b.day;
}
+({List<DateTime> days, bool showFuturePreview}) _ritualPreviewDays({
+ required Ritual ritual,
+ required RitualProgress? progress,
+ required DateTime todayMidnight,
+ required int count,
+}) {
+ final pastDays = _lastScheduledDaysInclusive(
+ ritual: ritual,
+ todayMidnight: todayMidnight,
+ count: count,
+ );
+ final todayScheduled = pastDays.any((day) => _isSameDay(day, todayMidnight));
+
+ if (progress == null || count <= 1) {
+ return (days: pastDays, showFuturePreview: false);
+ }
+
+ final createdAt = ritual.createdAt.toLocal();
+ final createdDayMidnight =
+ DateTime(createdAt.year, createdAt.month, createdAt.day);
+
+ final lookbackCount = count - 1;
+ final daysBeforeCreation = _lastScheduledDaysInclusive(
+ ritual: ritual,
+ todayMidnight: createdDayMidnight.subtract(const Duration(days: 1)),
+ count: lookbackCount,
+ );
+ final hadCompletionsBeforeCreation =
+ daysBeforeCreation.any(progress.hasCompleted);
+ if (hadCompletionsBeforeCreation) {
+ return (days: pastDays, showFuturePreview: false);
+ }
+
+ final maxShift = count - 1;
+ final shiftSlots = _scheduledSlotsSinceCreation(
+ ritual: ritual,
+ createdDayMidnight: createdDayMidnight,
+ todayMidnight: todayMidnight,
+ maxSlots: maxShift,
+ );
+ if (shiftSlots >= maxShift) {
+ return (days: pastDays, showFuturePreview: false);
+ }
+
+ final shiftedPast = todayScheduled
+ ? _lastScheduledDaysInclusive(
+ ritual: ritual,
+ todayMidnight: todayMidnight,
+ count: shiftSlots + 1,
+ )
+ : _lastScheduledDaysInclusive(
+ ritual: ritual,
+ todayMidnight: todayMidnight,
+ count: shiftSlots,
+ );
+ final shiftedFuture = _nextScheduledDaysInclusive(
+ ritual: ritual,
+ todayMidnight: todayMidnight,
+ count: count - shiftSlots,
+ );
+ final days = [
+ ...shiftedPast,
+ ...(todayScheduled ? shiftedFuture.skip(1) : shiftedFuture),
+ ];
+ return (days: days, showFuturePreview: true);
+}
+
+int _scheduledSlotsSinceCreation({
+ required Ritual ritual,
+ required DateTime createdDayMidnight,
+ required DateTime todayMidnight,
+ required int maxSlots,
+}) {
+ if (maxSlots <= 0) return 0;
+ if (todayMidnight.isBefore(createdDayMidnight)) return 0;
+
+ final daysOfWeek = ritual.daysOfWeek;
+ if (daysOfWeek.length != 7 || !daysOfWeek.any((enabled) => enabled)) {
+ return 0;
+ }
+
+ int slots = 0;
+ for (int offset = 1; slots < maxSlots && offset < 366; offset++) {
+ final day = todayMidnight.subtract(Duration(days: offset));
+ if (day.isBefore(createdDayMidnight)) break;
+ final weekdayIndex = day.weekday % 7; // Sunday-first
+ if (!daysOfWeek[weekdayIndex]) continue;
+ slots += 1;
+ }
+ return slots;
+}
+
bool _isEnabledDay(Ritual ritual, DateTime day) {
final daysOfWeek = ritual.daysOfWeek;
if (daysOfWeek.length != 7) return true;