Skip to content

armgit / ente

Public Imported from GitHub
0

💚 End-to-end encrypted cloud for everything.

Split wrapped builders and cards

laurenspriem655bb51b7418
diff --git a/mobile/apps/photos/lib/services/wrapped/builders/aesthetics_candidate_builder.dart b/mobile/apps/photos/lib/services/wrapped/builders/aesthetics_candidate_builder.dart
new file mode 100644
index 0000000000..b062c53381
--- /dev/null
+++ b/mobile/apps/photos/lib/services/wrapped/builders/aesthetics_candidate_builder.dart
@@ -0,0 +1,13 @@
+part of 'package:photos/services/wrapped/candidate_builders.dart';
+
+class AestheticsCandidateBuilder extends WrappedCandidateBuilder {
+ const AestheticsCandidateBuilder();
+
+ @override
+ String get debugLabel => "aesthetics";
+
+ @override
+ Future<List<WrappedCard>> build(WrappedEngineContext context) async {
+ return <WrappedCard>[];
+ }
+}
diff --git a/mobile/apps/photos/lib/services/wrapped/builders/curation_candidate_builder.dart b/mobile/apps/photos/lib/services/wrapped/builders/curation_candidate_builder.dart
new file mode 100644
index 0000000000..0dc8623b06
--- /dev/null
+++ b/mobile/apps/photos/lib/services/wrapped/builders/curation_candidate_builder.dart
@@ -0,0 +1,13 @@
+part of 'package:photos/services/wrapped/candidate_builders.dart';
+
+class CurationCandidateBuilder extends WrappedCandidateBuilder {
+ const CurationCandidateBuilder();
+
+ @override
+ String get debugLabel => "curation";
+
+ @override
+ Future<List<WrappedCard>> build(WrappedEngineContext context) async {
+ return <WrappedCard>[];
+ }
+}
diff --git a/mobile/apps/photos/lib/services/wrapped/builders/narrative_candidate_builder.dart b/mobile/apps/photos/lib/services/wrapped/builders/narrative_candidate_builder.dart
new file mode 100644
index 0000000000..4c0e5bb540
--- /dev/null
+++ b/mobile/apps/photos/lib/services/wrapped/builders/narrative_candidate_builder.dart
@@ -0,0 +1,13 @@
+part of 'package:photos/services/wrapped/candidate_builders.dart';
+
+class NarrativeCandidateBuilder extends WrappedCandidateBuilder {
+ const NarrativeCandidateBuilder();
+
+ @override
+ String get debugLabel => "narrative";
+
+ @override
+ Future<List<WrappedCard>> build(WrappedEngineContext context) async {
+ return <WrappedCard>[];
+ }
+}
diff --git a/mobile/apps/photos/lib/services/wrapped/builders/people_candidate_builder.dart b/mobile/apps/photos/lib/services/wrapped/builders/people_candidate_builder.dart
new file mode 100644
index 0000000000..97891c0cf1
--- /dev/null
+++ b/mobile/apps/photos/lib/services/wrapped/builders/people_candidate_builder.dart
@@ -0,0 +1,13 @@
+part of 'package:photos/services/wrapped/candidate_builders.dart';
+
+class PeopleCandidateBuilder extends WrappedCandidateBuilder {
+ const PeopleCandidateBuilder();
+
+ @override
+ String get debugLabel => "people";
+
+ @override
+ Future<List<WrappedCard>> build(WrappedEngineContext context) async {
+ return <WrappedCard>[];
+ }
+}
diff --git a/mobile/apps/photos/lib/services/wrapped/builders/places_candidate_builder.dart b/mobile/apps/photos/lib/services/wrapped/builders/places_candidate_builder.dart
new file mode 100644
index 0000000000..c2c5dfb0d4
--- /dev/null
+++ b/mobile/apps/photos/lib/services/wrapped/builders/places_candidate_builder.dart
@@ -0,0 +1,13 @@
+part of 'package:photos/services/wrapped/candidate_builders.dart';
+
+class PlacesCandidateBuilder extends WrappedCandidateBuilder {
+ const PlacesCandidateBuilder();
+
+ @override
+ String get debugLabel => "places";
+
+ @override
+ Future<List<WrappedCard>> build(WrappedEngineContext context) async {
+ return <WrappedCard>[];
+ }
+}
diff --git a/mobile/apps/photos/lib/services/wrapped/builders/stats_candidate_builder.dart b/mobile/apps/photos/lib/services/wrapped/builders/stats_candidate_builder.dart
new file mode 100644
index 0000000000..c9b7a31534
--- /dev/null
+++ b/mobile/apps/photos/lib/services/wrapped/builders/stats_candidate_builder.dart
@@ -0,0 +1,911 @@
+part of 'package:photos/services/wrapped/candidate_builders.dart';
+
+class StatsCandidateBuilder extends WrappedCandidateBuilder {
+ const StatsCandidateBuilder();
+
+ @override
+ String get debugLabel => "stats";
+
+ @override
+ Future<List<WrappedCard>> build(WrappedEngineContext context) async {
+ final _StatsSnapshot snapshot = _StatsSnapshot.fromContext(context);
+ if (snapshot.totalCount == 0) {
+ return <WrappedCard>[];
+ }
+
+ final List<WrappedCard> cards = <WrappedCard>[];
+ cards.add(_buildTotalsCard(snapshot));
+
+ final WrappedCard? rhythmCard = _buildRhythmCard(snapshot);
+ if (rhythmCard != null) {
+ cards.add(rhythmCard);
+ }
+
+ final WrappedCard? busiestDayCard = _buildBusiestDayCard(snapshot);
+ if (busiestDayCard != null) {
+ cards.add(busiestDayCard);
+ }
+
+ cards.addAll(_buildHeatmapCards(snapshot));
+
+ return cards;
+ }
+
+ WrappedCard _buildTotalsCard(_StatsSnapshot snapshot) {
+ final NumberFormat numberFormat = NumberFormat.decimalPattern();
+ final DateFormat fullDateFormat = DateFormat("MMMM d");
+
+ final int stillPhotoCount =
+ math.max(snapshot.photoCount - snapshot.livePhotoCount, 0);
+ final List<String> detailChips = <String>[];
+ if (stillPhotoCount > 0) {
+ detailChips.add(
+ "${numberFormat.format(stillPhotoCount)} ${stillPhotoCount == 1 ? 'photo' : 'photos'}",
+ );
+ }
+ if (snapshot.livePhotoCount > 0) {
+ detailChips.add(
+ "${numberFormat.format(snapshot.livePhotoCount)} live ${snapshot.livePhotoCount == 1 ? 'photo' : 'photos'}",
+ );
+ }
+ if (snapshot.videoCount > 0) {
+ detailChips.add(
+ "${numberFormat.format(snapshot.videoCount)} ${snapshot.videoCount == 1 ? 'video' : 'videos'}",
+ );
+ }
+ if (snapshot.storageBytes > 0) {
+ detailChips.add("${formatBytes(snapshot.storageBytes, 1)} captured");
+ }
+
+ final String title =
+ "You bottled ${numberFormat.format(snapshot.totalCount)} memories";
+ final String subtitle = snapshot.videoCount > 0
+ ? "That’s ${numberFormat.format(snapshot.photoCount)} photos and "
+ "${numberFormat.format(snapshot.videoCount)} videos ready to relive."
+ : "That’s ${numberFormat.format(snapshot.photoCount)} photos you kept close this year.";
+
+ final List<int> heroIds = _collectUniqueIds(
+ <List<int>>[
+ snapshot.firstCaptureUploadedIDs,
+ snapshot.busiestDayMediaUploadedIDs,
+ snapshot.lastCaptureUploadedIDs,
+ ],
+ );
+
+ final String? firstCaptureLine = snapshot.firstCaptureDay != null
+ ? "First frame: ${fullDateFormat.format(snapshot.firstCaptureDay!)}"
+ : null;
+
+ final Map<String, Object?> meta = <String, Object?>{
+ "year": snapshot.year,
+ "totalCount": snapshot.totalCount,
+ "photoCount": snapshot.photoCount,
+ "videoCount": snapshot.videoCount,
+ "livePhotoCount": snapshot.livePhotoCount,
+ "otherCount": snapshot.otherCount,
+ "storageBytes": snapshot.storageBytes,
+ "storageReadable": snapshot.storageBytes > 0
+ ? formatBytes(snapshot.storageBytes, 1)
+ : "0 bytes",
+ "daysWithCaptures": snapshot.daysWithCaptures,
+ "elapsedDays": snapshot.elapsedDays,
+ "detailChips": detailChips,
+ if (firstCaptureLine != null) "firstCaptureLine": firstCaptureLine,
+ "displayDurationMillis": 9000,
+ };
+
+ return WrappedCard(
+ type: WrappedCardType.statsTotals,
+ title: title,
+ subtitle: subtitle,
+ media: heroIds.map(MediaRef.new).toList(growable: false),
+ meta: meta,
+ );
+ }
+
+ WrappedCard? _buildRhythmCard(_StatsSnapshot snapshot) {
+ if (snapshot.elapsedDays <= 0) {
+ return null;
+ }
+
+ final NumberFormat averageFormat = NumberFormat("0.#");
+ final NumberFormat numberFormat = NumberFormat.decimalPattern();
+ final DateFormat monthFormat = DateFormat("MMMM");
+
+ final String title =
+ "${averageFormat.format(snapshot.averagePerDay)} memories per day";
+ final List<String> subtitleParts = <String>[];
+ String? busiestMonthName;
+ if (snapshot.busiestMonth != null && snapshot.busiestMonthCount > 0) {
+ busiestMonthName = monthFormat
+ .format(DateTime(snapshot.year, snapshot.busiestMonth!, 1));
+ subtitleParts.add(
+ "$busiestMonthName peaked at ${numberFormat.format(snapshot.busiestMonthCount)}",
+ );
+ }
+ subtitleParts.add(
+ "${numberFormat.format(snapshot.daysWithCaptures)} active days",
+ );
+ if (snapshot.daysWithCaptures > 0 &&
+ snapshot.averagePerActiveDay > snapshot.averagePerDay) {
+ subtitleParts.add(
+ "${averageFormat.format(snapshot.averagePerActiveDay)} on shooting days",
+ );
+ }
+
+ final List<String> chips = <String>[
+ "${numberFormat.format(snapshot.daysWithCaptures)} active days",
+ if (snapshot.longestStreakDays >= 3)
+ "Longest streak: ${numberFormat.format(snapshot.longestStreakDays)} days",
+ if (snapshot.longestGapDays >= 2)
+ "Longest breather: ${numberFormat.format(snapshot.longestGapDays)} days",
+ ];
+
+ final List<int> rhythmIds = _collectUniqueIds(
+ <List<int>>[
+ snapshot.streakStartUploadedIDs,
+ snapshot.busiestMonthHighlightUploadedIDs,
+ snapshot.breakReturnUploadedIDs,
+ ],
+ );
+
+ final Map<String, Object?> meta = <String, Object?>{
+ "year": snapshot.year,
+ "averagePerDay": snapshot.averagePerDay,
+ "averagePerActiveDay": snapshot.averagePerActiveDay,
+ "elapsedDays": snapshot.elapsedDays,
+ "daysWithCaptures": snapshot.daysWithCaptures,
+ "busiestMonth": snapshot.busiestMonth,
+ "busiestMonthName": busiestMonthName,
+ "busiestMonthCount": snapshot.busiestMonthCount,
+ "monthCounts": <String, int>{
+ for (final MapEntry<int, int> entry in snapshot.monthCounts.entries)
+ entry.key.toString(): entry.value,
+ },
+ "dailyCounts": snapshot.dailyCounts,
+ "detailChips": chips,
+ if (snapshot.longestStreakStart != null)
+ "longestStreakStart": snapshot.longestStreakStart!.toIso8601String(),
+ if (snapshot.longestStreakEnd != null)
+ "longestStreakEnd": snapshot.longestStreakEnd!.toIso8601String(),
+ "longestStreakDays": snapshot.longestStreakDays,
+ "longestGapDays": snapshot.longestGapDays,
+ if (snapshot.longestGapStart != null)
+ "longestGapStart": snapshot.longestGapStart!.toIso8601String(),
+ if (snapshot.longestGapEnd != null)
+ "longestGapEnd": snapshot.longestGapEnd!.toIso8601String(),
+ };
+
+ return WrappedCard(
+ type: WrappedCardType.statsVelocity,
+ title: title,
+ subtitle: subtitleParts.join(" · "),
+ media: rhythmIds.map(MediaRef.new).toList(growable: false),
+ meta: meta,
+ );
+ }
+
+ WrappedCard? _buildBusiestDayCard(_StatsSnapshot snapshot) {
+ if (snapshot.busiestDay == null || snapshot.busiestDayCount == 0) {
+ return null;
+ }
+
+ final DateFormat longDateFormat = DateFormat("MMMM d, yyyy");
+ final DateFormat weekdayFormat = DateFormat("EEEE");
+ final NumberFormat numberFormat = NumberFormat.decimalPattern();
+ final DateTime day = snapshot.busiestDay!;
+
+ final List<MediaRef> mediaRefs = snapshot.busiestDayMediaUploadedIDs
+ .take(6)
+ .map(MediaRef.new)
+ .toList(growable: false);
+
+ final Map<String, Object?> meta = <String, Object?>{
+ "date": day.toIso8601String(),
+ "weekday": weekdayFormat.format(day),
+ "count": snapshot.busiestDayCount,
+ "detailChips": <String>[
+ "${numberFormat.format(snapshot.busiestDayCount)} memories in 24 hours",
+ weekdayFormat.format(day),
+ ],
+ if (mediaRefs.isNotEmpty)
+ "uploadedFileIDs": snapshot.busiestDayMediaUploadedIDs,
+ };
+
+ return WrappedCard(
+ type: WrappedCardType.busiestDay,
+ title: "${longDateFormat.format(day)} went off",
+ subtitle:
+ "${numberFormat.format(snapshot.busiestDayCount)} memories captured in a single day.",
+ media: mediaRefs,
+ meta: meta,
+ );
+ }
+
+ List<WrappedCard> _buildHeatmapCards(_StatsSnapshot snapshot) {
+ if (snapshot.heatmapRows.isEmpty) {
+ return const <WrappedCard>[];
+ }
+
+ final List<Map<String, Object?>> quarterBlocks =
+ _QuarterHeatmapData.fromSnapshot(snapshot);
+ if (quarterBlocks.isEmpty) {
+ return const <WrappedCard>[];
+ }
+
+ final NumberFormat numberFormat = NumberFormat.decimalPattern();
+ final Map<String, Object?> meta = <String, Object?>{
+ "weekdayLabels": snapshot.heatmapWeekdayLabels,
+ "quarters": quarterBlocks,
+ "maxCount": snapshot.heatmapMaxCount,
+ "detailChips": <String>[
+ if (snapshot.busiestMonthName != null)
+ "Peak month: ${snapshot.busiestMonthName}",
+ "${numberFormat.format(snapshot.totalCount)} captures this year",
+ ],
+ };
+
+ return <WrappedCard>[
+ WrappedCard(
+ type: WrappedCardType.statsHeatmap,
+ title: "Seasons of snapshots",
+ subtitle: "Your year, one quarter at a time.",
+ meta: meta,
+ ),
+ ];
+ }
+
+ List<int> _collectUniqueIds(List<List<int>> sources) {
+ final Set<int> seen = <int>{};
+ final List<int> result = <int>[];
+ for (final List<int> source in sources) {
+ for (final int id in source) {
+ if (id <= 0) continue;
+ if (seen.add(id)) {
+ result.add(id);
+ }
+ if (result.length >= 6) {
+ return result;
+ }
+ }
+ }
+ return result;
+ }
+}
+
+class _StatsSnapshot {
+ _StatsSnapshot({
+ required this.year,
+ required this.totalCount,
+ required this.photoCount,
+ required this.videoCount,
+ required this.livePhotoCount,
+ required this.otherCount,
+ required this.storageBytes,
+ required this.monthCounts,
+ required this.dailyCounts,
+ required this.elapsedDays,
+ required this.daysWithCaptures,
+ required this.averagePerDay,
+ required this.averagePerActiveDay,
+ required this.busiestMonth,
+ required this.busiestMonthCount,
+ required this.busiestMonthName,
+ required this.busiestDay,
+ required this.busiestDayCount,
+ required this.busiestDayMediaUploadedIDs,
+ required this.longestStreakDays,
+ required this.longestStreakStart,
+ required this.longestStreakEnd,
+ required this.streakStartUploadedIDs,
+ required this.longestGapDays,
+ required this.longestGapStart,
+ required this.longestGapEnd,
+ required this.breakReturnUploadedIDs,
+ required this.firstCaptureDay,
+ required this.firstCaptureUploadedIDs,
+ required this.lastCaptureDay,
+ required this.lastCaptureUploadedIDs,
+ required this.busiestMonthHighlightUploadedIDs,
+ required this.periodEndDay,
+ required this.heatmapStart,
+ required this.heatmapEnd,
+ required this.heatmapRows,
+ required this.heatmapWeekLabels,
+ required this.heatmapWeekdayLabels,
+ required this.heatmapWeekStartDates,
+ required this.heatmapMaxCount,
+ });
+
+ final int year;
+ final int totalCount;
+ final int photoCount;
+ final int videoCount;
+ final int livePhotoCount;
+ final int otherCount;
+ final int storageBytes;
+ final Map<int, int> monthCounts;
+ final Map<String, int> dailyCounts;
+ final int elapsedDays;
+ final int daysWithCaptures;
+ final double averagePerDay;
+ final double averagePerActiveDay;
+ final int? busiestMonth;
+ final int busiestMonthCount;
+ final String? busiestMonthName;
+ final DateTime? busiestDay;
+ final int busiestDayCount;
+ final List<int> busiestDayMediaUploadedIDs;
+ final int longestStreakDays;
+ final DateTime? longestStreakStart;
+ final DateTime? longestStreakEnd;
+ final List<int> streakStartUploadedIDs;
+ final int longestGapDays;
+ final DateTime? longestGapStart;
+ final DateTime? longestGapEnd;
+ final List<int> breakReturnUploadedIDs;
+ final DateTime? firstCaptureDay;
+ final List<int> firstCaptureUploadedIDs;
+ final DateTime? lastCaptureDay;
+ final List<int> lastCaptureUploadedIDs;
+ final List<int> busiestMonthHighlightUploadedIDs;
+ final DateTime periodEndDay;
+ final DateTime heatmapStart;
+ final DateTime heatmapEnd;
+ final List<List<int>> heatmapRows;
+ final List<String> heatmapWeekLabels;
+ final List<String> heatmapWeekdayLabels;
+ final List<DateTime> heatmapWeekStartDates;
+ final int heatmapMaxCount;
+
+ static _StatsSnapshot fromContext(WrappedEngineContext context) {
+ final int year = context.year;
+ final DateTime startOfYear = DateTime(year, 1, 1);
+ final DateTime periodEndDay = _resolvePeriodEndDay(context.now, year);
+ final DateFormat monthNameFormat = DateFormat("MMMM");
+ final Map<int, int> monthCounts = <int, int>{
+ for (int month = 1; month <= 12; month += 1) month: 0,
+ };
+ final Map<int, _DayAggregate> dayAggregates = <int, _DayAggregate>{};
+
+ int totalCount = 0;
+ int photoCount = 0;
+ int videoCount = 0;
+ int livePhotoCount = 0;
+ int otherCount = 0;
+ int storageBytes = 0;
+
+ for (final EnteFile file in context.files) {
+ final int? creationTime = file.creationTime;
+ if (creationTime == null) continue;
+
+ final DateTime captured =
+ DateTime.fromMicrosecondsSinceEpoch(creationTime);
+ if (captured.year != year) continue;
+
+ totalCount += 1;
+
+ switch (file.fileType) {
+ case FileType.video:
+ videoCount += 1;
+ break;
+ case FileType.livePhoto:
+ livePhotoCount += 1;
+ photoCount += 1;
+ break;
+ case FileType.image:
+ photoCount += 1;
+ break;
+ default:
+ otherCount += 1;
+ }
+
+ if (file.fileSize != null && file.fileSize! > 0) {
+ storageBytes += file.fileSize!;
+ }
+
+ monthCounts[captured.month] = (monthCounts[captured.month] ?? 0) + 1;
+
+ final DateTime day =
+ DateTime(captured.year, captured.month, captured.day);
+ final int dayKey = day.microsecondsSinceEpoch;
+ final _DayAggregate aggregate =
+ dayAggregates.putIfAbsent(dayKey, () => _DayAggregate(day));
+ aggregate.count += 1;
+ final int? uploadedId = file.uploadedFileID;
+ if (uploadedId != null && aggregate.uploadedFileIDs.length < 9) {
+ aggregate.uploadedFileIDs.add(uploadedId);
+ }
+ }
+
+ final List<_DayAggregate> sortedAggregates = dayAggregates.values
+ .toList(growable: false)
+ ..sort((a, b) => a.day.compareTo(b.day));
+
+ final int daysWithCaptures = sortedAggregates.length;
+ final Map<String, int> dailyCounts = <String, int>{
+ for (final _DayAggregate aggregate in sortedAggregates)
+ aggregate.day.toIso8601String(): aggregate.count,
+ };
+
+ final DateTime? firstCaptureDay =
+ sortedAggregates.isEmpty ? null : sortedAggregates.first.day;
+ final List<int> firstCaptureUploadedIDs = firstCaptureDay == null
+ ? const <int>[]
+ : List<int>.unmodifiable(sortedAggregates.first.uploadedFileIDs);
+ final DateTime? lastCaptureDay =
+ sortedAggregates.isEmpty ? null : sortedAggregates.last.day;
+ final List<int> lastCaptureUploadedIDs = lastCaptureDay == null
+ ? const <int>[]
+ : List<int>.unmodifiable(sortedAggregates.last.uploadedFileIDs);
+
+ int? busiestMonth;
+ int busiestMonthCount = 0;
+ String? busiestMonthName;
+ monthCounts.forEach((int month, int count) {
+ if (count > busiestMonthCount ||
+ (count == busiestMonthCount &&
+ (busiestMonth == null || month < busiestMonth!))) {
+ busiestMonth = month;
+ busiestMonthCount = count;
+ busiestMonthName = monthNameFormat.format(DateTime(year, month, 1));
+ }
+ });
+
+ _DayAggregate? busiestDayAggregate;
+ for (final _DayAggregate candidate in sortedAggregates) {
+ if (busiestDayAggregate == null ||
+ candidate.count > busiestDayAggregate.count ||
+ (candidate.count == busiestDayAggregate.count &&
+ candidate.day.isBefore(busiestDayAggregate.day))) {
+ busiestDayAggregate = candidate;
+ }
+ }
+
+ final List<int> busiestMonthHighlightUploadedIDs;
+ if (busiestMonth == null) {
+ busiestMonthHighlightUploadedIDs = const <int>[];
+ } else {
+ _DayAggregate? bestInMonth;
+ for (final _DayAggregate aggregate in sortedAggregates) {
+ if (aggregate.day.month != busiestMonth) {
+ continue;
+ }
+ if (bestInMonth == null ||
+ aggregate.count > bestInMonth.count ||
+ (aggregate.count == bestInMonth.count &&
+ aggregate.day.isBefore(bestInMonth.day))) {
+ bestInMonth = aggregate;
+ }
+ }
+ busiestMonthHighlightUploadedIDs = bestInMonth == null
+ ? const <int>[]
+ : List<int>.unmodifiable(bestInMonth.uploadedFileIDs);
+ }
+
+ final _StreakResult streakResult =
+ _calculateLongestStreak(sortedAggregates);
+ final _GapResult gapResult =
+ _calculateLongestGap(sortedAggregates, startOfYear, periodEndDay);
+
+ final List<int> streakStartUploadedIDs =
+ _uploadedIDsForDay(dayAggregates, streakResult.start);
+
+ List<int> breakReturnUploadedIDs = const <int>[];
+ if (gapResult.length > 0 && gapResult.end != null) {
+ final DateTime resumeDay = gapResult.end!.add(const Duration(days: 1));
+ if (resumeDay.year == year) {
+ breakReturnUploadedIDs = _uploadedIDsForDay(dayAggregates, resumeDay);
+ }
+ }
+
+ int rawElapsedDays = periodEndDay.difference(startOfYear).inDays;
+ if (rawElapsedDays < 0) rawElapsedDays = 0;
+ final int elapsedDays = math.max(1, math.min(rawElapsedDays + 1, 366));
+
+ final double averagePerDay =
+ elapsedDays > 0 ? totalCount / elapsedDays : 0.0;
+ final double averagePerActiveDay =
+ daysWithCaptures > 0 ? totalCount / daysWithCaptures : 0.0;
+
+ final DateTime? busiestDay = busiestDayAggregate?.day;
+ final int busiestDayCount = busiestDayAggregate?.count ?? 0;
+ final List<int> busiestDayMediaUploadedIDs = busiestDayAggregate == null ||
+ busiestDayAggregate.uploadedFileIDs.isEmpty
+ ? const <int>[]
+ : List<int>.unmodifiable(busiestDayAggregate.uploadedFileIDs);
+
+ final DateTime heatmapStart = _alignToMonday(DateTime(year, 1, 1));
+ final DateTime heatmapEnd = _alignToSunday(DateTime(year, 12, 31));
+ final int heatmapDayCount = heatmapEnd.difference(heatmapStart).inDays + 1;
+ final int heatmapWeekCount = heatmapDayCount ~/ 7;
+ final List<List<int>> heatmapRows = List<List<int>>.generate(
+ heatmapWeekCount,
+ (_) => List<int>.filled(7, 0),
+ growable: false,
+ );
+ final List<DateTime> heatmapWeekStartDates =
+ List<DateTime>.filled(heatmapWeekCount, heatmapStart);
+ int heatmapMaxCount = 0;
+ DateTime weekCursor = heatmapStart;
+ for (int weekIndex = 0; weekIndex < heatmapWeekCount; weekIndex += 1) {
+ heatmapWeekStartDates[weekIndex] = weekCursor;
+ for (int dayOffset = 0; dayOffset < 7; dayOffset += 1) {
+ final DateTime day = weekCursor.add(Duration(days: dayOffset));
+ final int count = dailyCounts[day.toIso8601String()] ?? 0;
+ heatmapRows[weekIndex][dayOffset] = count;
+ if (count > heatmapMaxCount) {
+ heatmapMaxCount = count;
+ }
+ }
+ weekCursor = weekCursor.add(const Duration(days: 7));
+ }
+
+ final DateFormat monthAbbrevFormat = DateFormat("MMM");
+ final List<String> heatmapWeekLabels =
+ List<String>.filled(heatmapWeekCount, "", growable: false);
+ int? lastLabeledMonth;
+ for (int row = 0; row < heatmapWeekCount; row += 1) {
+ final DateTime weekStart = heatmapWeekStartDates[row];
+ final DateTime weekEnd = weekStart.add(const Duration(days: 6));
+ final int representativeMonth = weekEnd.month;
+ if (row == 0 || representativeMonth != lastLabeledMonth) {
+ heatmapWeekLabels[row] = monthAbbrevFormat.format(weekEnd);
+ lastLabeledMonth = representativeMonth;
+ }
+ }
+
+ const List<String> heatmapWeekdayLabels = <String>[
+ "M",
+ "T",
+ "W",
+ "T",
+ "F",
+ "S",
+ "S",
+ ];
+
+ final List<List<int>> normalizedHeatmapRows = heatmapRows
+ .map((List<int> row) => List<int>.unmodifiable(row))
+ .toList(growable: false);
+ final List<String> normalizedWeekLabels =
+ List<String>.unmodifiable(heatmapWeekLabels);
+ final List<String> normalizedWeekdayLabels =
+ List<String>.unmodifiable(heatmapWeekdayLabels);
+ final List<DateTime> normalizedWeekStartDates =
+ List<DateTime>.unmodifiable(heatmapWeekStartDates);
+
+ return _StatsSnapshot(
+ year: year,
+ totalCount: totalCount,
+ photoCount: photoCount,
+ videoCount: videoCount,
+ livePhotoCount: livePhotoCount,
+ otherCount: otherCount,
+ storageBytes: storageBytes,
+ monthCounts: Map<int, int>.unmodifiable(monthCounts),
+ dailyCounts: Map<String, int>.unmodifiable(dailyCounts),
+ elapsedDays: elapsedDays,
+ daysWithCaptures: daysWithCaptures,
+ averagePerDay: averagePerDay,
+ averagePerActiveDay: averagePerActiveDay,
+ busiestMonth: busiestMonth,
+ busiestMonthCount: busiestMonthCount,
+ busiestMonthName: busiestMonthName,
+ busiestDay: busiestDay,
+ busiestDayCount: busiestDayCount,
+ busiestDayMediaUploadedIDs: busiestDayMediaUploadedIDs,
+ longestStreakDays: streakResult.length,
+ longestStreakStart: streakResult.start,
+ longestStreakEnd: streakResult.end,
+ streakStartUploadedIDs: streakStartUploadedIDs,
+ longestGapDays: gapResult.length,
+ longestGapStart: gapResult.start,
+ longestGapEnd: gapResult.end,
+ breakReturnUploadedIDs: breakReturnUploadedIDs,
+ firstCaptureDay: firstCaptureDay,
+ firstCaptureUploadedIDs: firstCaptureUploadedIDs,
+ lastCaptureDay: lastCaptureDay,
+ lastCaptureUploadedIDs: lastCaptureUploadedIDs,
+ busiestMonthHighlightUploadedIDs: busiestMonthHighlightUploadedIDs,
+ periodEndDay: periodEndDay,
+ heatmapStart: heatmapStart,
+ heatmapEnd: heatmapEnd,
+ heatmapRows: normalizedHeatmapRows,
+ heatmapWeekLabels: normalizedWeekLabels,
+ heatmapWeekdayLabels: normalizedWeekdayLabels,
+ heatmapWeekStartDates: normalizedWeekStartDates,
+ heatmapMaxCount: heatmapMaxCount,
+ );
+ }
+}
+
+class _DayAggregate {
+ _DayAggregate(this.day);
+
+ final DateTime day;
+ int count = 0;
+ final List<int> uploadedFileIDs = <int>[];
+}
+
+class _QuarterHeatmapData {
+ static List<Map<String, Object?>> fromSnapshot(_StatsSnapshot snapshot) {
+ if (snapshot.heatmapRows.isEmpty) {
+ return const <Map<String, Object?>>[];
+ }
+ final DateFormat monthFormat = DateFormat("MMM");
+ final DateTime lastVisibleDay =
+ snapshot.periodEndDay.isBefore(snapshot.heatmapEnd)
+ ? snapshot.periodEndDay
+ : snapshot.heatmapEnd;
+ final List<List<List<int>>> quarterWeeks =
+ List<List<List<int>>>.generate(4, (_) => <List<int>>[]);
+ final List<List<DateTime>> quarterWeekDates =
+ List<List<DateTime>>.generate(4, (_) => <DateTime>[]);
+
+ for (int index = 0;
+ index < snapshot.heatmapRows.length &&
+ index < snapshot.heatmapWeekStartDates.length;
+ index += 1) {
+ final DateTime weekStart = snapshot.heatmapWeekStartDates[index];
+ final int quarterIndex = ((weekStart.month - 1) ~/ 3).clamp(0, 3);
+ final List<int> counts = snapshot.heatmapRows[index];
+ final List<int> sanitized = List<int>.filled(7, 0);
+ final DateTime yearStart = DateTime(snapshot.year, 1, 1);
+ for (int dayOffset = 0; dayOffset < 7; dayOffset += 1) {
+ final DateTime day = weekStart.add(Duration(days: dayOffset));
+ if (day.isAfter(lastVisibleDay)) {
+ sanitized[dayOffset] = kWrappedHeatmapFutureValue;
+ } else if (day.isBefore(yearStart)) {
+ sanitized[dayOffset] = kWrappedHeatmapPaddedValue;
+ } else {
+ sanitized[dayOffset] =
+ dayOffset < counts.length ? counts[dayOffset] : 0;
+ }
+ }
+ quarterWeeks[quarterIndex].add(sanitized);
+ quarterWeekDates[quarterIndex].add(weekStart);
+ }
+
+ final List<Map<String, Object?>> blocks = <Map<String, Object?>>[];
+ for (int quarter = 0; quarter < quarterWeeks.length; quarter += 1) {
+ final List<List<int>> weeks = quarterWeeks[quarter];
+ if (weeks.isEmpty) {
+ continue;
+ }
+ final List<List<int>> grid = _transposeWeeks(weeks);
+ final List<String> columnLabels =
+ _buildColumnLabels(quarterWeekDates[quarter], monthFormat);
+ blocks.add(<String, Object?>{
+ "label": _quarterLabel(quarter),
+ "grid": grid
+ .map((List<int> row) => List<int>.unmodifiable(row))
+ .toList(growable: false),
+ "columnLabels": columnLabels,
+ });
+ }
+ return blocks;
+ }
+
+ static List<List<int>> _transposeWeeks(List<List<int>> weeks) {
+ if (weeks.isEmpty) {
+ return List<List<int>>.generate(
+ 7,
+ (_) => const <int>[],
+ growable: false,
+ );
+ }
+ final int columnCount = weeks.length;
+ final int rowCount = weeks.first.length;
+ return List<List<int>>.generate(
+ rowCount,
+ (int dayIndex) => List<int>.generate(
+ columnCount,
+ (int columnIndex) => weeks[columnIndex][dayIndex],
+ growable: false,
+ ),
+ growable: false,
+ );
+ }
+
+ static List<String> _buildColumnLabels(
+ List<DateTime> weekStarts,
+ DateFormat monthFormat,
+ ) {
+ final List<String> labels = <String>[];
+ int? lastMonth;
+ for (final DateTime start in weekStarts) {
+ final int month = start.month;
+ final bool isNewMonth = labels.isEmpty || month != lastMonth;
+ final bool isQuarterStart = start.day <= 7;
+ if (isNewMonth && isQuarterStart) {
+ final String monthLabel = monthFormat.format(start);
+ final String singleChar =
+ monthLabel.isEmpty ? "" : monthLabel.substring(0, 1);
+ labels.add(singleChar.toUpperCase());
+ lastMonth = month;
+ } else {
+ labels.add("");
+ }
+ }
+ return List<String>.unmodifiable(labels);
+ }
+
+ static String _quarterLabel(int index) {
+ switch (index) {
+ case 0:
+ return "Jan – Mar";
+ case 1:
+ return "Apr – Jun";
+ case 2:
+ return "Jul – Sep";
+ case 3:
+ default:
+ return "Oct – Dec";
+ }
+ }
+}
+
+class _StreakResult {
+ const _StreakResult({
+ required this.length,
+ this.start,
+ this.end,
+ });
+
+ final int length;
+ final DateTime? start;
+ final DateTime? end;
+}
+
+_StreakResult _calculateLongestStreak(List<_DayAggregate> aggregates) {
+ if (aggregates.isEmpty) {
+ return const _StreakResult(length: 0);
+ }
+
+ int longest = 1;
+ int current = 0;
+ DateTime? currentStart;
+ DateTime? bestStart = aggregates.first.day;
+ DateTime? bestEnd = aggregates.first.day;
+ DateTime? previousDay;
+
+ for (final _DayAggregate aggregate in aggregates) {
+ final DateTime day = aggregate.day;
+ if (previousDay == null || day.difference(previousDay).inDays > 1) {
+ current = 1;
+ currentStart = day;
+ } else {
+ current += 1;
+ }
+
+ if (current > longest ||
+ (current == longest &&
+ currentStart != null &&
+ bestStart != null &&
+ currentStart.isBefore(bestStart))) {
+ longest = current;
+ bestStart = currentStart ?? day;
+ bestEnd = day;
+ }
+
+ previousDay = day;
+ }
+
+ return _StreakResult(
+ length: longest,
+ start: bestStart,
+ end: bestEnd,
+ );
+}
+
+class _GapResult {
+ const _GapResult({
+ required this.length,
+ this.start,
+ this.end,
+ });
+
+ final int length;
+ final DateTime? start;
+ final DateTime? end;
+}
+
+_GapResult _calculateLongestGap(
+ List<_DayAggregate> aggregates,
+ DateTime startOfYear,
+ DateTime periodEndDay,
+) {
+ if (aggregates.isEmpty) {
+ final int fullSpan =
+ math.max(0, periodEndDay.difference(startOfYear).inDays + 1);
+ return _GapResult(length: fullSpan, start: startOfYear, end: periodEndDay);
+ }
+
+ int longest = 0;
+ DateTime? gapStart;
+ DateTime? gapEnd;
+
+ final DateTime firstDay = aggregates.first.day;
+ final int leadingGap = firstDay.difference(startOfYear).inDays;
+ if (leadingGap > longest) {
+ longest = leadingGap;
+ if (leadingGap > 0) {
+ gapStart = startOfYear;
+ gapEnd = firstDay.subtract(const Duration(days: 1));
+ }
+ }
+
+ for (int i = 1; i < aggregates.length; i += 1) {
+ final DateTime prev = aggregates[i - 1].day;
+ final DateTime current = aggregates[i].day;
+ final int gap = current.difference(prev).inDays - 1;
+ if (gap > longest) {
+ longest = gap;
+ gapStart = prev.add(const Duration(days: 1));
+ gapEnd = current.subtract(const Duration(days: 1));
+ }
+ }
+
+ final DateTime lastDay = aggregates.last.day;
+ final int trailingGap = periodEndDay.difference(lastDay).inDays;
+ if (trailingGap > longest) {
+ longest = trailingGap;
+ if (trailingGap > 0) {
+ gapStart = lastDay.add(const Duration(days: 1));
+ gapEnd = periodEndDay;
+ }
+ }
+
+ if (longest <= 0 || gapStart == null || gapEnd == null) {
+ return const _GapResult(length: 0);
+ }
+
+ return _GapResult(length: longest, start: gapStart, end: gapEnd);
+}
+
+List<int> _uploadedIDsForDay(
+ Map<int, _DayAggregate> aggregates,
+ DateTime? day,
+) {
+ if (day == null) {
+ return const <int>[];
+ }
+ final DateTime normalized = DateTime(day.year, day.month, day.day);
+ final _DayAggregate? aggregate =
+ aggregates[normalized.microsecondsSinceEpoch];
+ if (aggregate == null || aggregate.uploadedFileIDs.isEmpty) {
+ return const <int>[];
+ }
+ return List<int>.unmodifiable(aggregate.uploadedFileIDs);
+}
+
+DateTime _resolvePeriodEndDay(DateTime now, int year) {
+ if (now.year < year) {
+ return DateTime(year, 12, 31);
+ }
+ if (now.year > year) {
+ return DateTime(year, 12, 31);
+ }
+ return DateTime(year, now.month, now.day);
+}
+
+DateTime _alignToMonday(DateTime date) {
+ int delta = date.weekday - DateTime.monday;
+ if (delta < 0) {
+ delta += 7;
+ }
+ return DateTime(date.year, date.month, date.day).subtract(
+ Duration(days: delta),
+ );
+}
+
+DateTime _alignToSunday(DateTime date) {
+ int delta = DateTime.sunday - date.weekday;
+ if (delta < 0) {
+ delta += 7;
+ }
+ return DateTime(date.year, date.month, date.day).add(
+ Duration(days: delta),
+ );
+}
diff --git a/mobile/apps/photos/lib/services/wrapped/candidate_builders.dart b/mobile/apps/photos/lib/services/wrapped/candidate_builders.dart
index 104b904736..83209a90cc 100644
--- a/mobile/apps/photos/lib/services/wrapped/candidate_builders.dart
+++ b/mobile/apps/photos/lib/services/wrapped/candidate_builders.dart
@@ -7,6 +7,13 @@ import "package:photos/models/file/file_type.dart";
import "package:photos/services/wrapped/models.dart";
import "package:photos/utils/standalone/data.dart";
+part "builders/stats_candidate_builder.dart";
+part "builders/people_candidate_builder.dart";
+part "builders/places_candidate_builder.dart";
+part "builders/aesthetics_candidate_builder.dart";
+part "builders/curation_candidate_builder.dart";
+part "builders/narrative_candidate_builder.dart";
+
/// Provides basic context details for candidate builders.
@immutable
class WrappedEngineContext {
@@ -30,339 +37,6 @@ abstract class WrappedCandidateBuilder {
Future<List<WrappedCard>> build(WrappedEngineContext context);
}
-class StatsCandidateBuilder extends WrappedCandidateBuilder {
- const StatsCandidateBuilder();
-
- @override
- String get debugLabel => "stats";
-
- @override
- Future<List<WrappedCard>> build(WrappedEngineContext context) async {
- final _StatsSnapshot snapshot = _StatsSnapshot.fromContext(context);
- if (snapshot.totalCount == 0) {
- return <WrappedCard>[];
- }
-
- final List<WrappedCard> cards = <WrappedCard>[];
- cards.add(_buildTotalsCard(snapshot));
-
- final WrappedCard? rhythmCard = _buildRhythmCard(snapshot);
- if (rhythmCard != null) {
- cards.add(rhythmCard);
- }
-
- final WrappedCard? busiestDayCard = _buildBusiestDayCard(snapshot);
- if (busiestDayCard != null) {
- cards.add(busiestDayCard);
- }
-
- cards.addAll(_buildHeatmapCards(snapshot));
-
- return cards;
- }
-
- WrappedCard _buildTotalsCard(_StatsSnapshot snapshot) {
- final NumberFormat numberFormat = NumberFormat.decimalPattern();
- final DateFormat fullDateFormat = DateFormat("MMMM d");
-
- final int stillPhotoCount =
- math.max(snapshot.photoCount - snapshot.livePhotoCount, 0);
- final List<String> detailChips = <String>[];
- if (stillPhotoCount > 0) {
- detailChips.add(
- "${numberFormat.format(stillPhotoCount)} ${stillPhotoCount == 1 ? 'photo' : 'photos'}",
- );
- }
- if (snapshot.livePhotoCount > 0) {
- detailChips.add(
- "${numberFormat.format(snapshot.livePhotoCount)} live ${snapshot.livePhotoCount == 1 ? 'photo' : 'photos'}",
- );
- }
- if (snapshot.videoCount > 0) {
- detailChips.add(
- "${numberFormat.format(snapshot.videoCount)} ${snapshot.videoCount == 1 ? 'video' : 'videos'}",
- );
- }
- if (snapshot.storageBytes > 0) {
- detailChips.add("${formatBytes(snapshot.storageBytes, 1)} captured");
- }
-
- final String title =
- "You bottled ${numberFormat.format(snapshot.totalCount)} memories";
- final String subtitle = snapshot.videoCount > 0
- ? "That’s ${numberFormat.format(snapshot.photoCount)} photos and "
- "${numberFormat.format(snapshot.videoCount)} videos ready to relive."
- : "That’s ${numberFormat.format(snapshot.photoCount)} photos you kept close this year.";
-
- final List<int> heroIds = _collectUniqueIds(
- <List<int>>[
- snapshot.firstCaptureUploadedIDs,
- snapshot.busiestDayMediaUploadedIDs,
- snapshot.lastCaptureUploadedIDs,
- ],
- );
-
- final String? firstCaptureLine = snapshot.firstCaptureDay != null
- ? "First frame: ${fullDateFormat.format(snapshot.firstCaptureDay!)}"
- : null;
-
- final Map<String, Object?> meta = <String, Object?>{
- "year": snapshot.year,
- "totalCount": snapshot.totalCount,
- "photoCount": snapshot.photoCount,
- "videoCount": snapshot.videoCount,
- "livePhotoCount": snapshot.livePhotoCount,
- "otherCount": snapshot.otherCount,
- "storageBytes": snapshot.storageBytes,
- "storageReadable": snapshot.storageBytes > 0
- ? formatBytes(snapshot.storageBytes, 1)
- : "0 bytes",
- "daysWithCaptures": snapshot.daysWithCaptures,
- "elapsedDays": snapshot.elapsedDays,
- "detailChips": detailChips,
- if (firstCaptureLine != null) "firstCaptureLine": firstCaptureLine,
- "displayDurationMillis": 9000,
- };
-
- return WrappedCard(
- type: WrappedCardType.statsTotals,
- title: title,
- subtitle: subtitle,
- media: heroIds.map(MediaRef.new).toList(growable: false),
- meta: meta,
- );
- }
-
- WrappedCard? _buildRhythmCard(_StatsSnapshot snapshot) {
- if (snapshot.elapsedDays <= 0) {
- return null;
- }
-
- final NumberFormat averageFormat = NumberFormat("0.#");
- final NumberFormat numberFormat = NumberFormat.decimalPattern();
- final DateFormat monthFormat = DateFormat("MMMM");
-
- final String title =
- "${averageFormat.format(snapshot.averagePerDay)} memories per day";
- final List<String> subtitleParts = <String>[];
- String? busiestMonthName;
- if (snapshot.busiestMonth != null && snapshot.busiestMonthCount > 0) {
- busiestMonthName = monthFormat
- .format(DateTime(snapshot.year, snapshot.busiestMonth!, 1));
- subtitleParts.add(
- "$busiestMonthName peaked at ${numberFormat.format(snapshot.busiestMonthCount)}",
- );
- }
- subtitleParts.add(
- "${numberFormat.format(snapshot.daysWithCaptures)} active days",
- );
- if (snapshot.daysWithCaptures > 0 &&
- snapshot.averagePerActiveDay > snapshot.averagePerDay) {
- subtitleParts.add(
- "${averageFormat.format(snapshot.averagePerActiveDay)} on shooting days",
- );
- }
-
- final List<String> chips = <String>[
- "${numberFormat.format(snapshot.daysWithCaptures)} active days",
- if (snapshot.longestStreakDays >= 3)
- "Longest streak: ${numberFormat.format(snapshot.longestStreakDays)} days",
- if (snapshot.longestGapDays >= 2)
- "Longest breather: ${numberFormat.format(snapshot.longestGapDays)} days",
- ];
-
- final List<int> rhythmIds = _collectUniqueIds(
- <List<int>>[
- snapshot.streakStartUploadedIDs,
- snapshot.busiestMonthHighlightUploadedIDs,
- snapshot.breakReturnUploadedIDs,
- ],
- );
-
- final Map<String, Object?> meta = <String, Object?>{
- "year": snapshot.year,
- "averagePerDay": snapshot.averagePerDay,
- "averagePerActiveDay": snapshot.averagePerActiveDay,
- "elapsedDays": snapshot.elapsedDays,
- "daysWithCaptures": snapshot.daysWithCaptures,
- "busiestMonth": snapshot.busiestMonth,
- "busiestMonthName": busiestMonthName,
- "busiestMonthCount": snapshot.busiestMonthCount,
- "monthCounts": <String, int>{
- for (final MapEntry<int, int> entry in snapshot.monthCounts.entries)
- entry.key.toString(): entry.value,
- },
- "dailyCounts": snapshot.dailyCounts,
- "detailChips": chips,
- if (snapshot.longestStreakStart != null)
- "longestStreakStart": snapshot.longestStreakStart!.toIso8601String(),
- if (snapshot.longestStreakEnd != null)
- "longestStreakEnd": snapshot.longestStreakEnd!.toIso8601String(),
- "longestStreakDays": snapshot.longestStreakDays,
- "longestGapDays": snapshot.longestGapDays,
- if (snapshot.longestGapStart != null)
- "longestGapStart": snapshot.longestGapStart!.toIso8601String(),
- if (snapshot.longestGapEnd != null)
- "longestGapEnd": snapshot.longestGapEnd!.toIso8601String(),
- };
-
- return WrappedCard(
- type: WrappedCardType.statsVelocity,
- title: title,
- subtitle: subtitleParts.join(" · "),
- media: rhythmIds.map(MediaRef.new).toList(growable: false),
- meta: meta,
- );
- }
-
- WrappedCard? _buildBusiestDayCard(_StatsSnapshot snapshot) {
- if (snapshot.busiestDay == null || snapshot.busiestDayCount == 0) {
- return null;
- }
-
- final DateFormat longDateFormat = DateFormat("MMMM d, yyyy");
- final DateFormat weekdayFormat = DateFormat("EEEE");
- final NumberFormat numberFormat = NumberFormat.decimalPattern();
- final DateTime day = snapshot.busiestDay!;
-
- final List<MediaRef> mediaRefs = snapshot.busiestDayMediaUploadedIDs
- .take(6)
- .map(MediaRef.new)
- .toList(growable: false);
-
- final Map<String, Object?> meta = <String, Object?>{
- "date": day.toIso8601String(),
- "weekday": weekdayFormat.format(day),
- "count": snapshot.busiestDayCount,
- "detailChips": <String>[
- "${numberFormat.format(snapshot.busiestDayCount)} memories in 24 hours",
- weekdayFormat.format(day),
- ],
- if (mediaRefs.isNotEmpty)
- "uploadedFileIDs": snapshot.busiestDayMediaUploadedIDs,
- };
-
- return WrappedCard(
- type: WrappedCardType.busiestDay,
- title: "${longDateFormat.format(day)} went off",
- subtitle:
- "${numberFormat.format(snapshot.busiestDayCount)} memories captured in a single day.",
- media: mediaRefs,
- meta: meta,
- );
- }
-
- List<WrappedCard> _buildHeatmapCards(_StatsSnapshot snapshot) {
- if (snapshot.heatmapRows.isEmpty) {
- return const <WrappedCard>[];
- }
-
- final List<Map<String, Object?>> quarterBlocks =
- _QuarterHeatmapData.fromSnapshot(snapshot);
- if (quarterBlocks.isEmpty) {
- return const <WrappedCard>[];
- }
-
- final NumberFormat numberFormat = NumberFormat.decimalPattern();
- final Map<String, Object?> meta = <String, Object?>{
- "weekdayLabels": snapshot.heatmapWeekdayLabels,
- "quarters": quarterBlocks,
- "maxCount": snapshot.heatmapMaxCount,
- "detailChips": <String>[
- if (snapshot.busiestMonthName != null)
- "Peak month: ${snapshot.busiestMonthName}",
- "${numberFormat.format(snapshot.totalCount)} captures this year",
- ],
- };
-
- return <WrappedCard>[
- WrappedCard(
- type: WrappedCardType.statsHeatmap,
- title: "Seasons of snapshots",
- subtitle: "Your year, one quarter at a time.",
- meta: meta,
- ),
- ];
- }
-
- List<int> _collectUniqueIds(List<List<int>> sources) {
- final Set<int> seen = <int>{};
- final List<int> result = <int>[];
- for (final List<int> source in sources) {
- for (final int id in source) {
- if (id <= 0) continue;
- if (seen.add(id)) {
- result.add(id);
- }
- if (result.length >= 6) {
- return result;
- }
- }
- }
- return result;
- }
-}
-
-class PeopleCandidateBuilder extends WrappedCandidateBuilder {
- const PeopleCandidateBuilder();
-
- @override
- String get debugLabel => "people";
-
- @override
- Future<List<WrappedCard>> build(WrappedEngineContext context) async {
- return <WrappedCard>[];
- }
-}
-
-class PlacesCandidateBuilder extends WrappedCandidateBuilder {
- const PlacesCandidateBuilder();
-
- @override
- String get debugLabel => "places";
-
- @override
- Future<List<WrappedCard>> build(WrappedEngineContext context) async {
- return <WrappedCard>[];
- }
-}
-
-class AestheticsCandidateBuilder extends WrappedCandidateBuilder {
- const AestheticsCandidateBuilder();
-
- @override
- String get debugLabel => "aesthetics";
-
- @override
- Future<List<WrappedCard>> build(WrappedEngineContext context) async {
- return <WrappedCard>[];
- }
-}
-
-class CurationCandidateBuilder extends WrappedCandidateBuilder {
- const CurationCandidateBuilder();
-
- @override
- String get debugLabel => "curation";
-
- @override
- Future<List<WrappedCard>> build(WrappedEngineContext context) async {
- return <WrappedCard>[];
- }
-}
-
-class NarrativeCandidateBuilder extends WrappedCandidateBuilder {
- const NarrativeCandidateBuilder();
-
- @override
- String get debugLabel => "narrative";
-
- @override
- Future<List<WrappedCard>> build(WrappedEngineContext context) async {
- return <WrappedCard>[];
- }
-}
-
/// Registry of all candidate builders invoked by the engine.
const List<WrappedCandidateBuilder> wrappedCandidateBuilders =
<WrappedCandidateBuilder>[
@@ -373,640 +47,3 @@ const List<WrappedCandidateBuilder> wrappedCandidateBuilders =
CurationCandidateBuilder(),
NarrativeCandidateBuilder(),
];
-
-class _StatsSnapshot {
- _StatsSnapshot({
- required this.year,
- required this.totalCount,
- required this.photoCount,
- required this.videoCount,
- required this.livePhotoCount,
- required this.otherCount,
- required this.storageBytes,
- required this.monthCounts,
- required this.dailyCounts,
- required this.elapsedDays,
- required this.daysWithCaptures,
- required this.averagePerDay,
- required this.averagePerActiveDay,
- required this.busiestMonth,
- required this.busiestMonthCount,
- required this.busiestMonthName,
- required this.busiestDay,
- required this.busiestDayCount,
- required this.busiestDayMediaUploadedIDs,
- required this.longestStreakDays,
- required this.longestStreakStart,
- required this.longestStreakEnd,
- required this.streakStartUploadedIDs,
- required this.longestGapDays,
- required this.longestGapStart,
- required this.longestGapEnd,
- required this.breakReturnUploadedIDs,
- required this.firstCaptureDay,
- required this.firstCaptureUploadedIDs,
- required this.lastCaptureDay,
- required this.lastCaptureUploadedIDs,
- required this.busiestMonthHighlightUploadedIDs,
- required this.periodEndDay,
- required this.heatmapStart,
- required this.heatmapEnd,
- required this.heatmapRows,
- required this.heatmapWeekLabels,
- required this.heatmapWeekdayLabels,
- required this.heatmapWeekStartDates,
- required this.heatmapMaxCount,
- });
-
- final int year;
- final int totalCount;
- final int photoCount;
- final int videoCount;
- final int livePhotoCount;
- final int otherCount;
- final int storageBytes;
- final Map<int, int> monthCounts;
- final Map<String, int> dailyCounts;
- final int elapsedDays;
- final int daysWithCaptures;
- final double averagePerDay;
- final double averagePerActiveDay;
- final int? busiestMonth;
- final int busiestMonthCount;
- final String? busiestMonthName;
- final DateTime? busiestDay;
- final int busiestDayCount;
- final List<int> busiestDayMediaUploadedIDs;
- final int longestStreakDays;
- final DateTime? longestStreakStart;
- final DateTime? longestStreakEnd;
- final List<int> streakStartUploadedIDs;
- final int longestGapDays;
- final DateTime? longestGapStart;
- final DateTime? longestGapEnd;
- final List<int> breakReturnUploadedIDs;
- final DateTime? firstCaptureDay;
- final List<int> firstCaptureUploadedIDs;
- final DateTime? lastCaptureDay;
- final List<int> lastCaptureUploadedIDs;
- final List<int> busiestMonthHighlightUploadedIDs;
- final DateTime periodEndDay;
- final DateTime heatmapStart;
- final DateTime heatmapEnd;
- final List<List<int>> heatmapRows;
- final List<String> heatmapWeekLabels;
- final List<String> heatmapWeekdayLabels;
- final List<DateTime> heatmapWeekStartDates;
- final int heatmapMaxCount;
-
- static _StatsSnapshot fromContext(WrappedEngineContext context) {
- final int year = context.year;
- final DateTime startOfYear = DateTime(year, 1, 1);
- final DateTime periodEndDay = _resolvePeriodEndDay(context.now, year);
- final DateFormat monthNameFormat = DateFormat("MMMM");
- final Map<int, int> monthCounts = <int, int>{
- for (int month = 1; month <= 12; month += 1) month: 0,
- };
- final Map<int, _DayAggregate> dayAggregates = <int, _DayAggregate>{};
-
- int totalCount = 0;
- int photoCount = 0;
- int videoCount = 0;
- int livePhotoCount = 0;
- int otherCount = 0;
- int storageBytes = 0;
-
- for (final EnteFile file in context.files) {
- final int? creationTime = file.creationTime;
- if (creationTime == null) continue;
-
- final DateTime captured =
- DateTime.fromMicrosecondsSinceEpoch(creationTime);
- if (captured.year != year) continue;
-
- totalCount += 1;
-
- switch (file.fileType) {
- case FileType.video:
- videoCount += 1;
- break;
- case FileType.livePhoto:
- livePhotoCount += 1;
- photoCount += 1;
- break;
- case FileType.image:
- photoCount += 1;
- break;
- default:
- otherCount += 1;
- }
-
- if (file.fileSize != null && file.fileSize! > 0) {
- storageBytes += file.fileSize!;
- }
-
- monthCounts[captured.month] = (monthCounts[captured.month] ?? 0) + 1;
-
- final DateTime day =
- DateTime(captured.year, captured.month, captured.day);
- final int dayKey = day.microsecondsSinceEpoch;
- final _DayAggregate aggregate =
- dayAggregates.putIfAbsent(dayKey, () => _DayAggregate(day));
- aggregate.count += 1;
- final int? uploadedId = file.uploadedFileID;
- if (uploadedId != null && aggregate.uploadedFileIDs.length < 9) {
- aggregate.uploadedFileIDs.add(uploadedId);
- }
- }
-
- final List<_DayAggregate> sortedAggregates = dayAggregates.values
- .toList(growable: false)
- ..sort((a, b) => a.day.compareTo(b.day));
-
- final int daysWithCaptures = sortedAggregates.length;
- final Map<String, int> dailyCounts = <String, int>{
- for (final _DayAggregate aggregate in sortedAggregates)
- aggregate.day.toIso8601String(): aggregate.count,
- };
-
- final DateTime? firstCaptureDay =
- sortedAggregates.isEmpty ? null : sortedAggregates.first.day;
- final List<int> firstCaptureUploadedIDs = firstCaptureDay == null
- ? const <int>[]
- : List<int>.unmodifiable(sortedAggregates.first.uploadedFileIDs);
- final DateTime? lastCaptureDay =
- sortedAggregates.isEmpty ? null : sortedAggregates.last.day;
- final List<int> lastCaptureUploadedIDs = lastCaptureDay == null
- ? const <int>[]
- : List<int>.unmodifiable(sortedAggregates.last.uploadedFileIDs);
-
- int? busiestMonth;
- int busiestMonthCount = 0;
- String? busiestMonthName;
- monthCounts.forEach((int month, int count) {
- if (count > busiestMonthCount ||
- (count == busiestMonthCount &&
- (busiestMonth == null || month < busiestMonth!))) {
- busiestMonth = month;
- busiestMonthCount = count;
- busiestMonthName = monthNameFormat.format(DateTime(year, month, 1));
- }
- });
-
- _DayAggregate? busiestDayAggregate;
- for (final _DayAggregate candidate in sortedAggregates) {
- if (busiestDayAggregate == null ||
- candidate.count > busiestDayAggregate.count ||
- (candidate.count == busiestDayAggregate.count &&
- candidate.day.isBefore(busiestDayAggregate.day))) {
- busiestDayAggregate = candidate;
- }
- }
-
- final List<int> busiestMonthHighlightUploadedIDs;
- if (busiestMonth == null) {
- busiestMonthHighlightUploadedIDs = const <int>[];
- } else {
- _DayAggregate? bestInMonth;
- for (final _DayAggregate aggregate in sortedAggregates) {
- if (aggregate.day.month != busiestMonth) {
- continue;
- }
- if (bestInMonth == null ||
- aggregate.count > bestInMonth.count ||
- (aggregate.count == bestInMonth.count &&
- aggregate.day.isBefore(bestInMonth.day))) {
- bestInMonth = aggregate;
- }
- }
- busiestMonthHighlightUploadedIDs = bestInMonth == null
- ? const <int>[]
- : List<int>.unmodifiable(bestInMonth.uploadedFileIDs);
- }
-
- final _StreakResult streakResult =
- _calculateLongestStreak(sortedAggregates);
- final _GapResult gapResult =
- _calculateLongestGap(sortedAggregates, startOfYear, periodEndDay);
-
- final List<int> streakStartUploadedIDs =
- _uploadedIDsForDay(dayAggregates, streakResult.start);
-
- List<int> breakReturnUploadedIDs = const <int>[];
- if (gapResult.length > 0 && gapResult.end != null) {
- final DateTime resumeDay = gapResult.end!.add(const Duration(days: 1));
- if (resumeDay.year == year) {
- breakReturnUploadedIDs = _uploadedIDsForDay(dayAggregates, resumeDay);
- }
- }
-
- int rawElapsedDays = periodEndDay.difference(startOfYear).inDays;
- if (rawElapsedDays < 0) rawElapsedDays = 0;
- final int elapsedDays = math.max(1, math.min(rawElapsedDays + 1, 366));
-
- final double averagePerDay =
- elapsedDays > 0 ? totalCount / elapsedDays : 0.0;
- final double averagePerActiveDay =
- daysWithCaptures > 0 ? totalCount / daysWithCaptures : 0.0;
-
- final DateTime? busiestDay = busiestDayAggregate?.day;
- final int busiestDayCount = busiestDayAggregate?.count ?? 0;
- final List<int> busiestDayMediaUploadedIDs = busiestDayAggregate == null ||
- busiestDayAggregate.uploadedFileIDs.isEmpty
- ? const <int>[]
- : List<int>.unmodifiable(busiestDayAggregate.uploadedFileIDs);
-
- final DateTime heatmapStart = _alignToMonday(DateTime(year, 1, 1));
- final DateTime heatmapEnd = _alignToSunday(DateTime(year, 12, 31));
- final int heatmapDayCount = heatmapEnd.difference(heatmapStart).inDays + 1;
- final int heatmapWeekCount = heatmapDayCount ~/ 7;
- final List<List<int>> heatmapRows = List<List<int>>.generate(
- heatmapWeekCount,
- (_) => List<int>.filled(7, 0),
- growable: false,
- );
- final List<DateTime> heatmapWeekStartDates =
- List<DateTime>.filled(heatmapWeekCount, heatmapStart);
- int heatmapMaxCount = 0;
- DateTime weekCursor = heatmapStart;
- for (int weekIndex = 0; weekIndex < heatmapWeekCount; weekIndex += 1) {
- heatmapWeekStartDates[weekIndex] = weekCursor;
- for (int dayOffset = 0; dayOffset < 7; dayOffset += 1) {
- final DateTime day = weekCursor.add(Duration(days: dayOffset));
- final int count = dailyCounts[day.toIso8601String()] ?? 0;
- heatmapRows[weekIndex][dayOffset] = count;
- if (count > heatmapMaxCount) {
- heatmapMaxCount = count;
- }
- }
- weekCursor = weekCursor.add(const Duration(days: 7));
- }
-
- final DateFormat monthAbbrevFormat = DateFormat("MMM");
- final List<String> heatmapWeekLabels =
- List<String>.filled(heatmapWeekCount, "", growable: false);
- int? lastLabeledMonth;
- for (int row = 0; row < heatmapWeekCount; row += 1) {
- final DateTime weekStart = heatmapWeekStartDates[row];
- final DateTime weekEnd = weekStart.add(const Duration(days: 6));
- final int representativeMonth = weekEnd.month;
- if (row == 0 || representativeMonth != lastLabeledMonth) {
- heatmapWeekLabels[row] = monthAbbrevFormat.format(weekEnd);
- lastLabeledMonth = representativeMonth;
- }
- }
-
- const List<String> heatmapWeekdayLabels = <String>[
- "M",
- "T",
- "W",
- "T",
- "F",
- "S",
- "S",
- ];
-
- final List<List<int>> normalizedHeatmapRows = heatmapRows
- .map((List<int> row) => List<int>.unmodifiable(row))
- .toList(growable: false);
- final List<String> normalizedWeekLabels =
- List<String>.unmodifiable(heatmapWeekLabels);
- final List<String> normalizedWeekdayLabels =
- List<String>.unmodifiable(heatmapWeekdayLabels);
- final List<DateTime> normalizedWeekStartDates =
- List<DateTime>.unmodifiable(heatmapWeekStartDates);
-
- return _StatsSnapshot(
- year: year,
- totalCount: totalCount,
- photoCount: photoCount,
- videoCount: videoCount,
- livePhotoCount: livePhotoCount,
- otherCount: otherCount,
- storageBytes: storageBytes,
- monthCounts: Map<int, int>.unmodifiable(monthCounts),
- dailyCounts: Map<String, int>.unmodifiable(dailyCounts),
- elapsedDays: elapsedDays,
- daysWithCaptures: daysWithCaptures,
- averagePerDay: averagePerDay,
- averagePerActiveDay: averagePerActiveDay,
- busiestMonth: busiestMonth,
- busiestMonthCount: busiestMonthCount,
- busiestMonthName: busiestMonthName,
- busiestDay: busiestDay,
- busiestDayCount: busiestDayCount,
- busiestDayMediaUploadedIDs: busiestDayMediaUploadedIDs,
- longestStreakDays: streakResult.length,
- longestStreakStart: streakResult.start,
- longestStreakEnd: streakResult.end,
- streakStartUploadedIDs: streakStartUploadedIDs,
- longestGapDays: gapResult.length,
- longestGapStart: gapResult.start,
- longestGapEnd: gapResult.end,
- breakReturnUploadedIDs: breakReturnUploadedIDs,
- firstCaptureDay: firstCaptureDay,
- firstCaptureUploadedIDs: firstCaptureUploadedIDs,
- lastCaptureDay: lastCaptureDay,
- lastCaptureUploadedIDs: lastCaptureUploadedIDs,
- busiestMonthHighlightUploadedIDs: busiestMonthHighlightUploadedIDs,
- periodEndDay: periodEndDay,
- heatmapStart: heatmapStart,
- heatmapEnd: heatmapEnd,
- heatmapRows: normalizedHeatmapRows,
- heatmapWeekLabels: normalizedWeekLabels,
- heatmapWeekdayLabels: normalizedWeekdayLabels,
- heatmapWeekStartDates: normalizedWeekStartDates,
- heatmapMaxCount: heatmapMaxCount,
- );
- }
-}
-
-class _DayAggregate {
- _DayAggregate(this.day);
-
- final DateTime day;
- int count = 0;
- final List<int> uploadedFileIDs = <int>[];
-}
-
-class _QuarterHeatmapData {
- static List<Map<String, Object?>> fromSnapshot(_StatsSnapshot snapshot) {
- if (snapshot.heatmapRows.isEmpty) {
- return const <Map<String, Object?>>[];
- }
- final DateFormat monthFormat = DateFormat("MMM");
- final DateTime lastVisibleDay =
- snapshot.periodEndDay.isBefore(snapshot.heatmapEnd)
- ? snapshot.periodEndDay
- : snapshot.heatmapEnd;
- final List<List<List<int>>> quarterWeeks =
- List<List<List<int>>>.generate(4, (_) => <List<int>>[]);
- final List<List<DateTime>> quarterWeekDates =
- List<List<DateTime>>.generate(4, (_) => <DateTime>[]);
-
- for (int index = 0;
- index < snapshot.heatmapRows.length &&
- index < snapshot.heatmapWeekStartDates.length;
- index += 1) {
- final DateTime weekStart = snapshot.heatmapWeekStartDates[index];
- final int quarterIndex = ((weekStart.month - 1) ~/ 3).clamp(0, 3);
- final List<int> counts = snapshot.heatmapRows[index];
- final List<int> sanitized = List<int>.filled(7, 0);
- final DateTime yearStart = DateTime(snapshot.year, 1, 1);
- for (int dayOffset = 0; dayOffset < 7; dayOffset += 1) {
- final DateTime day = weekStart.add(Duration(days: dayOffset));
- if (day.isAfter(lastVisibleDay)) {
- sanitized[dayOffset] = kWrappedHeatmapFutureValue;
- } else if (day.isBefore(yearStart)) {
- sanitized[dayOffset] = kWrappedHeatmapPaddedValue;
- } else {
- sanitized[dayOffset] =
- dayOffset < counts.length ? counts[dayOffset] : 0;
- }
- }
- quarterWeeks[quarterIndex].add(sanitized);
- quarterWeekDates[quarterIndex].add(weekStart);
- }
-
- final List<Map<String, Object?>> blocks = <Map<String, Object?>>[];
- for (int quarter = 0; quarter < quarterWeeks.length; quarter += 1) {
- final List<List<int>> weeks = quarterWeeks[quarter];
- if (weeks.isEmpty) {
- continue;
- }
- final List<List<int>> grid = _transposeWeeks(weeks);
- final List<String> columnLabels =
- _buildColumnLabels(quarterWeekDates[quarter], monthFormat);
- blocks.add(<String, Object?>{
- "label": _quarterLabel(quarter),
- "grid": grid
- .map((List<int> row) => List<int>.unmodifiable(row))
- .toList(growable: false),
- "columnLabels": columnLabels,
- });
- }
- return blocks;
- }
-
- static List<List<int>> _transposeWeeks(List<List<int>> weeks) {
- if (weeks.isEmpty) {
- return List<List<int>>.generate(
- 7,
- (_) => const <int>[],
- growable: false,
- );
- }
- final int columnCount = weeks.length;
- final int rowCount = weeks.first.length;
- return List<List<int>>.generate(
- rowCount,
- (int dayIndex) => List<int>.generate(
- columnCount,
- (int columnIndex) => weeks[columnIndex][dayIndex],
- growable: false,
- ),
- growable: false,
- );
- }
-
- static List<String> _buildColumnLabels(
- List<DateTime> weekStarts,
- DateFormat monthFormat,
- ) {
- final List<String> labels = <String>[];
- int? lastMonth;
- for (final DateTime start in weekStarts) {
- final int month = start.month;
- final bool isNewMonth = labels.isEmpty || month != lastMonth;
- final bool isQuarterStart = start.day <= 7;
- if (isNewMonth && isQuarterStart) {
- final String monthLabel = monthFormat.format(start);
- final String singleChar =
- monthLabel.isEmpty ? "" : monthLabel.substring(0, 1);
- labels.add(singleChar.toUpperCase());
- lastMonth = month;
- } else {
- labels.add("");
- }
- }
- return List<String>.unmodifiable(labels);
- }
-
- static String _quarterLabel(int index) {
- switch (index) {
- case 0:
- return "Jan – Mar";
- case 1:
- return "Apr – Jun";
- case 2:
- return "Jul – Sep";
- case 3:
- default:
- return "Oct – Dec";
- }
- }
-}
-
-class _StreakResult {
- const _StreakResult({
- required this.length,
- this.start,
- this.end,
- });
-
- final int length;
- final DateTime? start;
- final DateTime? end;
-}
-
-_StreakResult _calculateLongestStreak(List<_DayAggregate> aggregates) {
- if (aggregates.isEmpty) {
- return const _StreakResult(length: 0);
- }
-
- int longest = 1;
- int current = 0;
- DateTime? currentStart;
- DateTime? bestStart = aggregates.first.day;
- DateTime? bestEnd = aggregates.first.day;
- DateTime? previousDay;
-
- for (final _DayAggregate aggregate in aggregates) {
- final DateTime day = aggregate.day;
- if (previousDay == null || day.difference(previousDay).inDays > 1) {
- current = 1;
- currentStart = day;
- } else {
- current += 1;
- }
-
- if (current > longest ||
- (current == longest &&
- currentStart != null &&
- bestStart != null &&
- currentStart.isBefore(bestStart))) {
- longest = current;
- bestStart = currentStart ?? day;
- bestEnd = day;
- }
-
- previousDay = day;
- }
-
- return _StreakResult(
- length: longest,
- start: bestStart,
- end: bestEnd,
- );
-}
-
-class _GapResult {
- const _GapResult({
- required this.length,
- this.start,
- this.end,
- });
-
- final int length;
- final DateTime? start;
- final DateTime? end;
-}
-
-_GapResult _calculateLongestGap(
- List<_DayAggregate> aggregates,
- DateTime startOfYear,
- DateTime periodEndDay,
-) {
- if (aggregates.isEmpty) {
- final int fullSpan =
- math.max(0, periodEndDay.difference(startOfYear).inDays + 1);
- return _GapResult(length: fullSpan, start: startOfYear, end: periodEndDay);
- }
-
- int longest = 0;
- DateTime? gapStart;
- DateTime? gapEnd;
-
- final DateTime firstDay = aggregates.first.day;
- final int leadingGap = firstDay.difference(startOfYear).inDays;
- if (leadingGap > longest) {
- longest = leadingGap;
- if (leadingGap > 0) {
- gapStart = startOfYear;
- gapEnd = firstDay.subtract(const Duration(days: 1));
- }
- }
-
- for (int i = 1; i < aggregates.length; i += 1) {
- final DateTime prev = aggregates[i - 1].day;
- final DateTime current = aggregates[i].day;
- final int gap = current.difference(prev).inDays - 1;
- if (gap > longest) {
- longest = gap;
- gapStart = prev.add(const Duration(days: 1));
- gapEnd = current.subtract(const Duration(days: 1));
- }
- }
-
- final DateTime lastDay = aggregates.last.day;
- final int trailingGap = periodEndDay.difference(lastDay).inDays;
- if (trailingGap > longest) {
- longest = trailingGap;
- if (trailingGap > 0) {
- gapStart = lastDay.add(const Duration(days: 1));
- gapEnd = periodEndDay;
- }
- }
-
- if (longest <= 0 || gapStart == null || gapEnd == null) {
- return const _GapResult(length: 0);
- }
-
- return _GapResult(length: longest, start: gapStart, end: gapEnd);
-}
-
-List<int> _uploadedIDsForDay(
- Map<int, _DayAggregate> aggregates,
- DateTime? day,
-) {
- if (day == null) {
- return const <int>[];
- }
- final DateTime normalized = DateTime(day.year, day.month, day.day);
- final _DayAggregate? aggregate =
- aggregates[normalized.microsecondsSinceEpoch];
- if (aggregate == null || aggregate.uploadedFileIDs.isEmpty) {
- return const <int>[];
- }
- return List<int>.unmodifiable(aggregate.uploadedFileIDs);
-}
-
-DateTime _resolvePeriodEndDay(DateTime now, int year) {
- if (now.year < year) {
- return DateTime(year, 12, 31);
- }
- if (now.year > year) {
- return DateTime(year, 12, 31);
- }
- return DateTime(year, now.month, now.day);
-}
-
-DateTime _alignToMonday(DateTime date) {
- int delta = date.weekday - DateTime.monday;
- if (delta < 0) {
- delta += 7;
- }
- return DateTime(date.year, date.month, date.day).subtract(
- Duration(days: delta),
- );
-}
-
-DateTime _alignToSunday(DateTime date) {
- int delta = DateTime.sunday - date.weekday;
- if (delta < 0) {
- delta += 7;
- }
- return DateTime(date.year, date.month, date.day).add(
- Duration(days: delta),
- );
-}
diff --git a/mobile/apps/photos/lib/ui/wrapped/cards/aesthetics_card_content.dart b/mobile/apps/photos/lib/ui/wrapped/cards/aesthetics_card_content.dart
new file mode 100644
index 0000000000..2c3773b3b6
--- /dev/null
+++ b/mobile/apps/photos/lib/ui/wrapped/cards/aesthetics_card_content.dart
@@ -0,0 +1,9 @@
+part of 'package:photos/ui/wrapped/wrapped_viewer_page.dart';
+
+Widget? buildAestheticsCardContent(
+ WrappedCard card,
+ EnteColorScheme colorScheme,
+ EnteTextTheme textTheme,
+) {
+ return null;
+}
diff --git a/mobile/apps/photos/lib/ui/wrapped/cards/curation_card_content.dart b/mobile/apps/photos/lib/ui/wrapped/cards/curation_card_content.dart
new file mode 100644
index 0000000000..2d5d7d48a4
--- /dev/null
+++ b/mobile/apps/photos/lib/ui/wrapped/cards/curation_card_content.dart
@@ -0,0 +1,9 @@
+part of 'package:photos/ui/wrapped/wrapped_viewer_page.dart';
+
+Widget? buildCurationCardContent(
+ WrappedCard card,
+ EnteColorScheme colorScheme,
+ EnteTextTheme textTheme,
+) {
+ return null;
+}
diff --git a/mobile/apps/photos/lib/ui/wrapped/cards/narrative_card_content.dart b/mobile/apps/photos/lib/ui/wrapped/cards/narrative_card_content.dart
new file mode 100644
index 0000000000..9360fcc7a1
--- /dev/null
+++ b/mobile/apps/photos/lib/ui/wrapped/cards/narrative_card_content.dart
@@ -0,0 +1,9 @@
+part of 'package:photos/ui/wrapped/wrapped_viewer_page.dart';
+
+Widget? buildNarrativeCardContent(
+ WrappedCard card,
+ EnteColorScheme colorScheme,
+ EnteTextTheme textTheme,
+) {
+ return null;
+}
diff --git a/mobile/apps/photos/lib/ui/wrapped/cards/people_card_content.dart b/mobile/apps/photos/lib/ui/wrapped/cards/people_card_content.dart
new file mode 100644
index 0000000000..433ab4e566
--- /dev/null
+++ b/mobile/apps/photos/lib/ui/wrapped/cards/people_card_content.dart
@@ -0,0 +1,9 @@
+part of 'package:photos/ui/wrapped/wrapped_viewer_page.dart';
+
+Widget? buildPeopleCardContent(
+ WrappedCard card,
+ EnteColorScheme colorScheme,
+ EnteTextTheme textTheme,
+) {
+ return null;
+}
diff --git a/mobile/apps/photos/lib/ui/wrapped/cards/places_card_content.dart b/mobile/apps/photos/lib/ui/wrapped/cards/places_card_content.dart
new file mode 100644
index 0000000000..e0e5e64b25
--- /dev/null
+++ b/mobile/apps/photos/lib/ui/wrapped/cards/places_card_content.dart
@@ -0,0 +1,9 @@
+part of 'package:photos/ui/wrapped/wrapped_viewer_page.dart';
+
+Widget? buildPlacesCardContent(
+ WrappedCard card,
+ EnteColorScheme colorScheme,
+ EnteTextTheme textTheme,
+) {
+ return null;
+}
diff --git a/mobile/apps/photos/lib/ui/wrapped/cards/shared_widgets.dart b/mobile/apps/photos/lib/ui/wrapped/cards/shared_widgets.dart
new file mode 100644
index 0000000000..1986bb7a87
--- /dev/null
+++ b/mobile/apps/photos/lib/ui/wrapped/cards/shared_widgets.dart
@@ -0,0 +1,415 @@
+part of 'package:photos/ui/wrapped/wrapped_viewer_page.dart';
+
+class _DetailChips extends StatelessWidget {
+ const _DetailChips({
+ required this.chips,
+ required this.colorScheme,
+ required this.textTheme,
+ });
+
+ final List<String> chips;
+ final EnteColorScheme colorScheme;
+ final EnteTextTheme textTheme;
+
+ @override
+ Widget build(BuildContext context) {
+ if (chips.isEmpty) {
+ return const SizedBox.shrink();
+ }
+ return Wrap(
+ spacing: 10,
+ runSpacing: 8,
+ children: chips
+ .map(
+ (String chip) => Container(
+ padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
+ decoration: BoxDecoration(
+ color: colorScheme.fillFaint,
+ borderRadius: BorderRadius.circular(14),
+ ),
+ child: Text(
+ chip,
+ style: textTheme.smallMuted,
+ ),
+ ),
+ )
+ .toList(growable: false),
+ );
+ }
+}
+
+class _HeroMediaCollage extends StatelessWidget {
+ const _HeroMediaCollage({
+ required this.media,
+ required this.colorScheme,
+ });
+
+ final List<MediaRef> media;
+ final EnteColorScheme colorScheme;
+
+ @override
+ Widget build(BuildContext context) {
+ if (media.isEmpty) {
+ return _MediaPlaceholder(
+ height: 220,
+ colorScheme: colorScheme,
+ borderRadius: 24,
+ );
+ }
+
+ final List<MediaRef> trimmed = media.take(3).toList(growable: false);
+ final MediaRef primary = trimmed.first;
+ final List<MediaRef> side = trimmed.skip(1).toList(growable: false);
+
+ return SizedBox(
+ height: 220,
+ child: Row(
+ children: [
+ Expanded(
+ flex: 2,
+ child: _MediaTile(
+ mediaRef: primary,
+ borderRadius: 24,
+ aspectRatio: 3 / 4,
+ ),
+ ),
+ if (side.isNotEmpty) ...[
+ const SizedBox(width: 12),
+ Expanded(
+ child: Column(
+ children: List<Widget>.generate(
+ 2,
+ (int index) {
+ final MediaRef? ref =
+ index < side.length ? side[index] : null;
+ return Expanded(
+ child: Padding(
+ padding: EdgeInsets.only(
+ bottom: index == 0 ? 12 : 0,
+ ),
+ child: ref != null
+ ? _MediaTile(
+ mediaRef: ref,
+ borderRadius: 20,
+ )
+ : _MediaPlaceholder(
+ colorScheme: colorScheme,
+ borderRadius: 20,
+ ),
+ ),
+ );
+ },
+ ),
+ ),
+ ),
+ ],
+ ],
+ ),
+ );
+ }
+}
+
+class _MediaRow extends StatelessWidget {
+ const _MediaRow({
+ required this.media,
+ required this.colorScheme,
+ });
+
+ final List<MediaRef> media;
+ final EnteColorScheme colorScheme;
+
+ @override
+ Widget build(BuildContext context) {
+ return SizedBox(
+ height: 96,
+ child: Row(
+ children: [
+ for (final (int index, MediaRef ref) in media.indexed) ...[
+ Expanded(
+ child: Padding(
+ padding:
+ EdgeInsets.only(right: index == media.length - 1 ? 0 : 12),
+ child: _MediaTile(
+ mediaRef: ref,
+ borderRadius: 18,
+ ),
+ ),
+ ),
+ ],
+ if (media.isEmpty)
+ Expanded(
+ child: _MediaPlaceholder(
+ colorScheme: colorScheme,
+ borderRadius: 18,
+ ),
+ ),
+ ],
+ ),
+ );
+ }
+}
+
+class _MediaGrid extends StatelessWidget {
+ const _MediaGrid({
+ required this.media,
+ required this.colorScheme,
+ });
+
+ final List<MediaRef> media;
+ final EnteColorScheme colorScheme;
+
+ @override
+ Widget build(BuildContext context) {
+ if (media.isEmpty) {
+ return _MediaPlaceholder(
+ height: 200,
+ colorScheme: colorScheme,
+ );
+ }
+ return AspectRatio(
+ aspectRatio: 2 / 3,
+ child: Column(
+ children: List<Widget>.generate(3, (int row) {
+ return Expanded(
+ child: Row(
+ children: List<Widget>.generate(2, (int column) {
+ final int index = row * 2 + column;
+ final MediaRef? ref =
+ index < media.length ? media[index] : null;
+ return Expanded(
+ child: Padding(
+ padding: EdgeInsets.only(
+ right: column == 1 ? 0 : 10,
+ bottom: row == 2 ? 0 : 10,
+ ),
+ child: ref != null
+ ? _MediaTile(
+ mediaRef: ref,
+ borderRadius: 16,
+ )
+ : _MediaPlaceholder(
+ colorScheme: colorScheme,
+ borderRadius: 16,
+ ),
+ ),
+ );
+ }),
+ ),
+ );
+ }),
+ ),
+ );
+ }
+}
+
+class _MediaTile extends StatelessWidget {
+ const _MediaTile({
+ required this.mediaRef,
+ required this.borderRadius,
+ this.aspectRatio,
+ });
+
+ final MediaRef mediaRef;
+ final double borderRadius;
+ final double? aspectRatio;
+
+ @override
+ Widget build(BuildContext context) {
+ Widget content = ClipRRect(
+ borderRadius: BorderRadius.circular(borderRadius),
+ child: SizedBox.expand(
+ child: _MediaThumb(
+ ref: mediaRef,
+ ),
+ ),
+ );
+ if (aspectRatio != null) {
+ content = AspectRatio(
+ aspectRatio: aspectRatio!,
+ child: content,
+ );
+ }
+ return content;
+ }
+}
+
+class _MediaPlaceholder extends StatelessWidget {
+ const _MediaPlaceholder({
+ required this.colorScheme,
+ this.height,
+ this.borderRadius = 20,
+ });
+
+ final EnteColorScheme colorScheme;
+ final double? height;
+ final double borderRadius;
+
+ @override
+ Widget build(BuildContext context) {
+ final Widget child = Container(
+ decoration: BoxDecoration(
+ color: colorScheme.primary400.withValues(alpha: 0.12),
+ borderRadius: BorderRadius.circular(borderRadius),
+ ),
+ );
+ if (height != null) {
+ return SizedBox(
+ height: height,
+ child: child,
+ );
+ }
+ return child;
+ }
+}
+
+class _MediaThumb extends StatefulWidget {
+ const _MediaThumb({required this.ref});
+
+ final MediaRef ref;
+
+ @override
+ State<_MediaThumb> createState() => _MediaThumbState();
+}
+
+class _MediaThumbState extends State<_MediaThumb> {
+ late Future<EnteFile?> _fileFuture;
+
+ @override
+ void initState() {
+ super.initState();
+ _fileFuture = FilesDB.instance.getAnyUploadedFile(
+ widget.ref.uploadedFileID,
+ );
+ }
+
+ @override
+ void didUpdateWidget(covariant _MediaThumb oldWidget) {
+ super.didUpdateWidget(oldWidget);
+ if (oldWidget.ref.uploadedFileID != widget.ref.uploadedFileID) {
+ _fileFuture = FilesDB.instance.getAnyUploadedFile(
+ widget.ref.uploadedFileID,
+ );
+ }
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final colorScheme = getEnteColorScheme(context);
+ return FutureBuilder<EnteFile?>(
+ future: _fileFuture,
+ builder: (BuildContext context, AsyncSnapshot<EnteFile?> snapshot) {
+ if (snapshot.connectionState != ConnectionState.done) {
+ return Container(
+ color: colorScheme.fillFaint,
+ );
+ }
+ final EnteFile? file = snapshot.data;
+ if (file == null) {
+ return Container(
+ color: colorScheme.fillFaint,
+ );
+ }
+ return ThumbnailWidget(
+ file,
+ fit: BoxFit.cover,
+ rawThumbnail: true,
+ shouldShowSyncStatus: false,
+ shouldShowArchiveStatus: false,
+ shouldShowPinIcon: false,
+ shouldShowOwnerAvatar: false,
+ shouldShowFavoriteIcon: false,
+ shouldShowVideoDuration: false,
+ shouldShowVideoOverlayIcon: false,
+ );
+ },
+ );
+ }
+}
+
+Color _heatmapColorForValue(
+ int value,
+ int maxValue,
+ EnteColorScheme scheme,
+) {
+ if (value <= 0 || maxValue <= 0) {
+ return scheme.fillFaint;
+ }
+ final double t = (value / maxValue).clamp(0.0, 1.0);
+ return Color.lerp(
+ scheme.primary400.withValues(alpha: 0.25),
+ scheme.primary500,
+ t,
+ ) ??
+ scheme.primary500;
+}
+
+List<String> _stringListFromMeta(
+ Map<String, Object?> meta,
+ String key,
+) {
+ final Object? raw = meta[key];
+ if (raw is List) {
+ return raw.whereType<String>().toList(growable: false);
+ }
+ return const <String>[];
+}
+
+class _StoryProgressBar extends StatelessWidget {
+ const _StoryProgressBar({
+ required this.progressValues,
+ required this.colorScheme,
+ });
+
+ final List<double> progressValues;
+ final EnteColorScheme colorScheme;
+
+ @override
+ Widget build(BuildContext context) {
+ return Row(
+ children: [
+ for (final (int index, double value)
+ in progressValues.indexed) ...<Widget>[
+ Expanded(
+ child: _ProgressSegment(
+ progress: value,
+ colorScheme: colorScheme,
+ ),
+ ),
+ if (index != progressValues.length - 1) const SizedBox(width: 6),
+ ],
+ ],
+ );
+ }
+}
+
+class _ProgressSegment extends StatelessWidget {
+ const _ProgressSegment({
+ required this.progress,
+ required this.colorScheme,
+ });
+
+ final double progress;
+ final EnteColorScheme colorScheme;
+
+ @override
+ Widget build(BuildContext context) {
+ return ClipRRect(
+ borderRadius: BorderRadius.circular(6),
+ child: Stack(
+ children: [
+ Container(
+ height: 4,
+ color: colorScheme.fillFaint,
+ ),
+ FractionallySizedBox(
+ widthFactor: progress.clamp(0.0, 1.0),
+ child: Container(
+ height: 4,
+ color: colorScheme.primary500,
+ ),
+ ),
+ ],
+ ),
+ );
+ }
+}
diff --git a/mobile/apps/photos/lib/ui/wrapped/cards/stats_card_content.dart b/mobile/apps/photos/lib/ui/wrapped/cards/stats_card_content.dart
new file mode 100644
index 0000000000..6fdce3fc7d
--- /dev/null
+++ b/mobile/apps/photos/lib/ui/wrapped/cards/stats_card_content.dart
@@ -0,0 +1,526 @@
+part of 'package:photos/ui/wrapped/wrapped_viewer_page.dart';
+
+Widget? buildStatsCardContent(
+ WrappedCard card,
+ EnteColorScheme colorScheme,
+ EnteTextTheme textTheme,
+) {
+ switch (card.type) {
+ case WrappedCardType.statsTotals:
+ return _TotalsCardContent(
+ card: card,
+ colorScheme: colorScheme,
+ textTheme: textTheme,
+ );
+ case WrappedCardType.statsVelocity:
+ return _RhythmCardContent(
+ card: card,
+ colorScheme: colorScheme,
+ textTheme: textTheme,
+ );
+ case WrappedCardType.busiestDay:
+ return _BusiestDayCardContent(
+ card: card,
+ colorScheme: colorScheme,
+ textTheme: textTheme,
+ );
+ case WrappedCardType.statsHeatmap:
+ return _HeatmapCardContent(
+ card: card,
+ colorScheme: colorScheme,
+ textTheme: textTheme,
+ );
+ default:
+ return null;
+ }
+}
+
+class _TotalsCardContent extends StatelessWidget {
+ const _TotalsCardContent({
+ required this.card,
+ required this.colorScheme,
+ required this.textTheme,
+ });
+
+ final WrappedCard card;
+ final EnteColorScheme colorScheme;
+ final EnteTextTheme textTheme;
+
+ @override
+ Widget build(BuildContext context) {
+ final List<String> chips = _stringListFromMeta(card.meta, "detailChips");
+ final String? firstCaptureLine = card.meta["firstCaptureLine"] as String?;
+
+ return Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ _HeroMediaCollage(
+ media: card.media,
+ colorScheme: colorScheme,
+ ),
+ const SizedBox(height: 24),
+ Text(
+ card.title,
+ style: textTheme.h2Bold,
+ ),
+ if (card.subtitle != null && card.subtitle!.isNotEmpty)
+ Padding(
+ padding: const EdgeInsets.only(top: 12),
+ child: Text(
+ card.subtitle!,
+ style: textTheme.bodyMuted,
+ ),
+ ),
+ if (chips.isNotEmpty) ...[
+ const SizedBox(height: 20),
+ _DetailChips(
+ chips: chips,
+ colorScheme: colorScheme,
+ textTheme: textTheme,
+ ),
+ ],
+ if (firstCaptureLine != null) ...[
+ const SizedBox(height: 16),
+ Text(
+ firstCaptureLine,
+ style: textTheme.smallMuted,
+ ),
+ ],
+ const Spacer(),
+ ],
+ );
+ }
+}
+
+class _RhythmCardContent extends StatelessWidget {
+ const _RhythmCardContent({
+ required this.card,
+ required this.colorScheme,
+ required this.textTheme,
+ });
+
+ final WrappedCard card;
+ final EnteColorScheme colorScheme;
+ final EnteTextTheme textTheme;
+
+ @override
+ Widget build(BuildContext context) {
+ final List<String> chips = _stringListFromMeta(card.meta, "detailChips");
+
+ return Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(
+ card.title,
+ style: textTheme.h2Bold,
+ ),
+ if (card.subtitle != null && card.subtitle!.isNotEmpty)
+ Padding(
+ padding: const EdgeInsets.only(top: 12),
+ child: Text(
+ card.subtitle!,
+ style: textTheme.bodyMuted,
+ ),
+ ),
+ if (chips.isNotEmpty) ...[
+ const SizedBox(height: 18),
+ _DetailChips(
+ chips: chips,
+ colorScheme: colorScheme,
+ textTheme: textTheme,
+ ),
+ ],
+ if (card.media.isNotEmpty) ...[
+ const SizedBox(height: 22),
+ _MediaRow(
+ media: card.media.take(3).toList(growable: false),
+ colorScheme: colorScheme,
+ ),
+ ],
+ const Spacer(),
+ ],
+ );
+ }
+}
+
+class _BusiestDayCardContent extends StatelessWidget {
+ const _BusiestDayCardContent({
+ required this.card,
+ required this.colorScheme,
+ required this.textTheme,
+ });
+
+ final WrappedCard card;
+ final EnteColorScheme colorScheme;
+ final EnteTextTheme textTheme;
+
+ @override
+ Widget build(BuildContext context) {
+ final List<String> chips = _stringListFromMeta(card.meta, "detailChips");
+
+ return Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(
+ card.title,
+ style: textTheme.h2Bold,
+ ),
+ if (card.subtitle != null && card.subtitle!.isNotEmpty)
+ Padding(
+ padding: const EdgeInsets.only(top: 12),
+ child: Text(
+ card.subtitle!,
+ style: textTheme.bodyMuted,
+ ),
+ ),
+ if (chips.isNotEmpty) ...[
+ const SizedBox(height: 18),
+ _DetailChips(
+ chips: chips,
+ colorScheme: colorScheme,
+ textTheme: textTheme,
+ ),
+ ],
+ const SizedBox(height: 22),
+ _MediaGrid(
+ media: card.media.take(6).toList(growable: false),
+ colorScheme: colorScheme,
+ ),
+ const Spacer(),
+ ],
+ );
+ }
+}
+
+class _HeatmapCardContent extends StatelessWidget {
+ const _HeatmapCardContent({
+ required this.card,
+ required this.colorScheme,
+ required this.textTheme,
+ });
+
+ final WrappedCard card;
+ final EnteColorScheme colorScheme;
+ final EnteTextTheme textTheme;
+
+ @override
+ Widget build(BuildContext context) {
+ final List<String> chips = _stringListFromMeta(card.meta, "detailChips");
+ final List<dynamic> rawQuarters =
+ card.meta["quarters"] as List<dynamic>? ?? const <dynamic>[];
+ final List<_QuarterBlock> quarters = rawQuarters
+ .map(
+ (dynamic entry) => _QuarterBlock.fromJson(
+ (entry as Map).cast<String, Object?>(),
+ ),
+ )
+ .where((_QuarterBlock block) => block.grid.isNotEmpty)
+ .toList(growable: false);
+ final List<String> weekdayLabels =
+ (card.meta["weekdayLabels"] as List<dynamic>? ?? const <dynamic>[])
+ .whereType<String>()
+ .toList(growable: false);
+ final int maxCount = (card.meta["maxCount"] as num?)?.toInt() ?? 0;
+
+ return Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(
+ card.title,
+ style: textTheme.h2Bold,
+ ),
+ if (card.subtitle != null && card.subtitle!.isNotEmpty)
+ Padding(
+ padding: const EdgeInsets.only(top: 12),
+ child: Text(
+ card.subtitle!,
+ style: textTheme.bodyMuted,
+ ),
+ ),
+ const SizedBox(height: 18),
+ if (quarters.isEmpty)
+ _MediaPlaceholder(
+ height: 180,
+ colorScheme: colorScheme,
+ )
+ else
+ LayoutBuilder(
+ builder: (BuildContext context, BoxConstraints constraints) {
+ final double maxWidth = constraints.maxWidth;
+ final int columns =
+ quarters.length <= 1 ? 1 : (maxWidth >= 280 ? 2 : 1);
+ final double spacing = columns > 1 ? 18 : 0;
+ final double itemWidth = columns > 1
+ ? (maxWidth - ((columns - 1) * spacing)) / columns
+ : maxWidth;
+ final int maxColumnCount = quarters
+ .map(
+ (_QuarterBlock block) =>
+ block.grid.isNotEmpty ? block.grid.first.length : 0,
+ )
+ .fold(0, math.max);
+ const double labelColumnWidth = 20;
+ const double cellSpacing = 1.5;
+ const double fallbackCellSize = 6;
+ const double maxCellWidth = 18;
+ const double maxCellHeight = 12;
+
+ double computeCellWidth(double availableWidth) {
+ if (maxColumnCount <= 0) {
+ return fallbackCellSize;
+ }
+ final double usable = math.max(
+ 0,
+ availableWidth -
+ cellSpacing * math.max(0, maxColumnCount - 1),
+ );
+ final double raw = usable / math.max(1, maxColumnCount);
+ return raw.clamp(fallbackCellSize, maxCellWidth);
+ }
+
+ final double cellWidthWithLabels =
+ computeCellWidth(itemWidth - labelColumnWidth);
+ final double cellWidthWithoutLabels = computeCellWidth(itemWidth);
+ final double cellWidth =
+ math.min(cellWidthWithLabels, cellWidthWithoutLabels);
+ final double cellHeight = math.min(
+ maxCellHeight,
+ cellWidth.clamp(fallbackCellSize, maxCellHeight),
+ );
+ return Wrap(
+ spacing: spacing,
+ runSpacing: 18,
+ children: <Widget>[
+ for (final (int index, _QuarterBlock block)
+ in quarters.indexed)
+ SizedBox(
+ width: itemWidth,
+ child: _QuarterHeatmap(
+ block: block,
+ weekdayLabels: weekdayLabels,
+ maxCount: maxCount,
+ colorScheme: colorScheme,
+ textTheme: textTheme,
+ showDayLabels: columns == 1 || index % columns == 0,
+ cellWidth: cellWidth,
+ cellHeight: cellHeight,
+ cellSpacing: cellSpacing,
+ labelColumnWidth: labelColumnWidth,
+ ),
+ ),
+ ],
+ );
+ },
+ ),
+ if (chips.isNotEmpty) ...[
+ const SizedBox(height: 20),
+ _DetailChips(
+ chips: chips,
+ colorScheme: colorScheme,
+ textTheme: textTheme,
+ ),
+ ],
+ const Spacer(),
+ ],
+ );
+ }
+}
+
+class _QuarterBlock {
+ _QuarterBlock({
+ required this.label,
+ required this.grid,
+ required this.columnLabels,
+ });
+
+ final String label;
+ final List<List<int>> grid;
+ final List<String> columnLabels;
+
+ static _QuarterBlock fromJson(Map<String, Object?> json) {
+ final List<List<int>> grid =
+ (json["grid"] as List<dynamic>? ?? const <dynamic>[])
+ .map(
+ (dynamic row) => (row as List<dynamic>)
+ .map((dynamic value) => (value as num).toInt())
+ .toList(growable: false),
+ )
+ .toList(growable: false);
+ final List<String> columnLabels =
+ (json["columnLabels"] as List<dynamic>? ?? const <dynamic>[])
+ .whereType<String>()
+ .toList(growable: false);
+ return _QuarterBlock(
+ label: json["label"] as String? ?? "",
+ grid: grid,
+ columnLabels: columnLabels,
+ );
+ }
+}
+
+class _QuarterHeatmap extends StatelessWidget {
+ const _QuarterHeatmap({
+ required this.block,
+ required this.weekdayLabels,
+ required this.maxCount,
+ required this.colorScheme,
+ required this.textTheme,
+ required this.showDayLabels,
+ required this.cellWidth,
+ required this.cellHeight,
+ required this.cellSpacing,
+ required this.labelColumnWidth,
+ });
+
+ final _QuarterBlock block;
+ final List<String> weekdayLabels;
+ final int maxCount;
+ final EnteColorScheme colorScheme;
+ final EnteTextTheme textTheme;
+ final bool showDayLabels;
+ final double cellWidth;
+ final double cellHeight;
+ final double cellSpacing;
+ final double labelColumnWidth;
+
+ @override
+ Widget build(BuildContext context) {
+ final int columnCount = block.grid.isEmpty ? 0 : block.grid.first.length;
+ if (columnCount == 0) {
+ return _MediaPlaceholder(
+ height: 120,
+ colorScheme: colorScheme,
+ );
+ }
+
+ final TextStyle axisStyle =
+ textTheme.tinyMuted.copyWith(fontSize: 8.5, height: 1.15);
+ final List<String> headerLabels = List<String>.generate(
+ columnCount,
+ (int index) =>
+ index < block.columnLabels.length ? block.columnLabels[index] : "",
+ );
+
+ return Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(
+ block.label,
+ style: textTheme.smallBold,
+ ),
+ const SizedBox(height: 6),
+ Row(
+ children: [
+ SizedBox(width: labelColumnWidth),
+ for (int columnIndex = 0;
+ columnIndex < headerLabels.length;
+ columnIndex += 1) ...[
+ SizedBox(
+ width: cellWidth,
+ child: Text(
+ headerLabels[columnIndex],
+ style: axisStyle,
+ textAlign: TextAlign.center,
+ softWrap: false,
+ overflow: TextOverflow.fade,
+ ),
+ ),
+ SizedBox(
+ width: columnIndex == headerLabels.length - 1 ? 0 : cellSpacing,
+ ),
+ ],
+ ],
+ ),
+ const SizedBox(height: 4),
+ Column(
+ children: List<Widget>.generate(weekdayLabels.length, (int dayIndex) {
+ final List<int> row = block.grid.length > dayIndex
+ ? block.grid[dayIndex]
+ : const <int>[];
+ final String dayLabel =
+ dayIndex < weekdayLabels.length ? weekdayLabels[dayIndex] : "";
+ return Padding(
+ padding: EdgeInsets.only(
+ bottom: dayIndex == weekdayLabels.length - 1 ? 0 : cellSpacing,
+ ),
+ child: Row(
+ children: [
+ SizedBox(
+ width: labelColumnWidth,
+ child: Visibility(
+ visible: showDayLabels,
+ maintainSize: true,
+ maintainAnimation: true,
+ maintainState: true,
+ child: Text(
+ dayLabel,
+ style: axisStyle,
+ ),
+ ),
+ ),
+ for (int columnIndex = 0;
+ columnIndex < columnCount;
+ columnIndex += 1) ...[
+ _HeatmapCell(
+ value: columnIndex < row.length ? row[columnIndex] : -1,
+ width: cellWidth,
+ height: cellHeight,
+ colorScheme: colorScheme,
+ maxCount: maxCount,
+ ),
+ SizedBox(
+ width: columnIndex == columnCount - 1 ? 0 : cellSpacing,
+ ),
+ ],
+ ],
+ ),
+ );
+ }),
+ ),
+ ],
+ );
+ }
+}
+
+class _HeatmapCell extends StatelessWidget {
+ const _HeatmapCell({
+ required this.value,
+ required this.width,
+ required this.height,
+ required this.colorScheme,
+ required this.maxCount,
+ });
+
+ final int value;
+ final double width;
+ final double height;
+ final EnteColorScheme colorScheme;
+ final int maxCount;
+
+ @override
+ Widget build(BuildContext context) {
+ if (value == kWrappedHeatmapFutureValue) {
+ return SizedBox(width: width, height: height);
+ }
+ if (value == kWrappedHeatmapPaddedValue) {
+ final Color base = colorScheme.fillFaint;
+ final double placeholderAlpha = (base.a * 0.4).clamp(0.0, 1.0).toDouble();
+ return Container(
+ width: width,
+ height: height,
+ decoration: BoxDecoration(
+ color: base.withValues(alpha: placeholderAlpha),
+ borderRadius: BorderRadius.circular(3),
+ ),
+ );
+ }
+ return Container(
+ width: width,
+ height: height,
+ decoration: BoxDecoration(
+ color: _heatmapColorForValue(value, maxCount, colorScheme),
+ borderRadius: BorderRadius.circular(3),
+ ),
+ );
+ }
+}
diff --git a/mobile/apps/photos/lib/ui/wrapped/cards/story_card.dart b/mobile/apps/photos/lib/ui/wrapped/cards/story_card.dart
new file mode 100644
index 0000000000..16cae6a6c7
--- /dev/null
+++ b/mobile/apps/photos/lib/ui/wrapped/cards/story_card.dart
@@ -0,0 +1,111 @@
+part of 'package:photos/ui/wrapped/wrapped_viewer_page.dart';
+
+typedef _CardContentBuilder = Widget? Function(
+ WrappedCard card,
+ EnteColorScheme colorScheme,
+ EnteTextTheme textTheme,
+);
+
+final List<_CardContentBuilder> _cardContentBuilders = <_CardContentBuilder>[
+ buildStatsCardContent,
+ buildPeopleCardContent,
+ buildPlacesCardContent,
+ buildAestheticsCardContent,
+ buildCurationCardContent,
+ buildNarrativeCardContent,
+];
+
+class _StoryCard extends StatelessWidget {
+ const _StoryCard({
+ required this.card,
+ required this.colorScheme,
+ required this.textTheme,
+ required this.isActive,
+ });
+
+ final WrappedCard card;
+ final EnteColorScheme colorScheme;
+ final EnteTextTheme textTheme;
+ final bool isActive;
+
+ @override
+ Widget build(BuildContext context) {
+ return AnimatedOpacity(
+ duration: const Duration(milliseconds: 200),
+ opacity: isActive ? 1.0 : 0.6,
+ child: Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 18, vertical: 12),
+ child: Material(
+ color: colorScheme.backgroundElevated,
+ borderRadius: BorderRadius.circular(24),
+ child: Padding(
+ padding: const EdgeInsets.fromLTRB(24, 28, 24, 32),
+ child: _CardContent(
+ card: card,
+ colorScheme: colorScheme,
+ textTheme: textTheme,
+ ),
+ ),
+ ),
+ ),
+ );
+ }
+}
+
+class _CardContent extends StatelessWidget {
+ const _CardContent({
+ required this.card,
+ required this.colorScheme,
+ required this.textTheme,
+ });
+
+ final WrappedCard card;
+ final EnteColorScheme colorScheme;
+ final EnteTextTheme textTheme;
+
+ @override
+ Widget build(BuildContext context) {
+ for (final _CardContentBuilder builder in _cardContentBuilders) {
+ final Widget? built = builder(card, colorScheme, textTheme);
+ if (built != null) {
+ return built;
+ }
+ }
+ return _GenericCardContent(
+ card: card,
+ textTheme: textTheme,
+ );
+ }
+}
+
+class _GenericCardContent extends StatelessWidget {
+ const _GenericCardContent({
+ required this.card,
+ required this.textTheme,
+ });
+
+ final WrappedCard card;
+ final EnteTextTheme textTheme;
+
+ @override
+ Widget build(BuildContext context) {
+ return Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(
+ card.title,
+ style: textTheme.h2Bold,
+ ),
+ if (card.subtitle != null && card.subtitle!.isNotEmpty)
+ Padding(
+ padding: const EdgeInsets.only(top: 12),
+ child: Text(
+ card.subtitle!,
+ style: textTheme.bodyMuted,
+ ),
+ ),
+ const Spacer(),
+ ],
+ );
+ }
+}
diff --git a/mobile/apps/photos/lib/ui/wrapped/wrapped_viewer_page.dart b/mobile/apps/photos/lib/ui/wrapped/wrapped_viewer_page.dart
index 32395501b7..4bc0cd34c5 100644
--- a/mobile/apps/photos/lib/ui/wrapped/wrapped_viewer_page.dart
+++ b/mobile/apps/photos/lib/ui/wrapped/wrapped_viewer_page.dart
@@ -19,6 +19,15 @@ import "package:photos/ui/viewer/file/thumbnail_widget.dart";
import "package:photos/utils/share_util.dart";
import "package:share_plus/share_plus.dart";
+part "cards/story_card.dart";
+part "cards/stats_card_content.dart";
+part "cards/people_card_content.dart";
+part "cards/places_card_content.dart";
+part "cards/aesthetics_card_content.dart";
+part "cards/curation_card_content.dart";
+part "cards/narrative_card_content.dart";
+part "cards/shared_widgets.dart";
+
/// Basic viewer for the stats-only Ente Wrapped experience.
class WrappedViewerPage extends StatefulWidget {
const WrappedViewerPage({
@@ -404,1023 +413,3 @@ class _WrappedViewerPageState extends State<WrappedViewerPage>
return byteData?.buffer.asUint8List();
}
}
-
-class _StoryCard extends StatelessWidget {
- const _StoryCard({
- required this.card,
- required this.colorScheme,
- required this.textTheme,
- required this.isActive,
- });
-
- final WrappedCard card;
- final EnteColorScheme colorScheme;
- final EnteTextTheme textTheme;
- final bool isActive;
-
- @override
- Widget build(BuildContext context) {
- return AnimatedOpacity(
- duration: const Duration(milliseconds: 200),
- opacity: isActive ? 1.0 : 0.6,
- child: Padding(
- padding: const EdgeInsets.symmetric(horizontal: 18, vertical: 12),
- child: Material(
- color: colorScheme.backgroundElevated,
- borderRadius: BorderRadius.circular(24),
- child: Padding(
- padding: const EdgeInsets.fromLTRB(24, 28, 24, 32),
- child: _CardContent(
- card: card,
- colorScheme: colorScheme,
- textTheme: textTheme,
- ),
- ),
- ),
- ),
- );
- }
-}
-
-class _CardContent extends StatelessWidget {
- const _CardContent({
- required this.card,
- required this.colorScheme,
- required this.textTheme,
- });
-
- final WrappedCard card;
- final EnteColorScheme colorScheme;
- final EnteTextTheme textTheme;
-
- @override
- Widget build(BuildContext context) {
- switch (card.type) {
- case WrappedCardType.statsTotals:
- return _TotalsCardContent(
- card: card,
- colorScheme: colorScheme,
- textTheme: textTheme,
- );
- case WrappedCardType.statsVelocity:
- return _RhythmCardContent(
- card: card,
- colorScheme: colorScheme,
- textTheme: textTheme,
- );
- case WrappedCardType.busiestDay:
- return _BusiestDayCardContent(
- card: card,
- colorScheme: colorScheme,
- textTheme: textTheme,
- );
- case WrappedCardType.statsHeatmap:
- return _HeatmapCardContent(
- card: card,
- colorScheme: colorScheme,
- textTheme: textTheme,
- );
- default:
- return _GenericCardContent(
- card: card,
- textTheme: textTheme,
- );
- }
- }
-}
-
-class _TotalsCardContent extends StatelessWidget {
- const _TotalsCardContent({
- required this.card,
- required this.colorScheme,
- required this.textTheme,
- });
-
- final WrappedCard card;
- final EnteColorScheme colorScheme;
- final EnteTextTheme textTheme;
-
- @override
- Widget build(BuildContext context) {
- final List<String> chips = _stringListFromMeta(card.meta, "detailChips");
- final String? firstCaptureLine = card.meta["firstCaptureLine"] as String?;
-
- return Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- _HeroMediaCollage(
- media: card.media,
- colorScheme: colorScheme,
- ),
- const SizedBox(height: 24),
- Text(
- card.title,
- style: textTheme.h2Bold,
- ),
- if (card.subtitle != null && card.subtitle!.isNotEmpty)
- Padding(
- padding: const EdgeInsets.only(top: 12),
- child: Text(
- card.subtitle!,
- style: textTheme.bodyMuted,
- ),
- ),
- if (chips.isNotEmpty) ...[
- const SizedBox(height: 20),
- _DetailChips(
- chips: chips,
- colorScheme: colorScheme,
- textTheme: textTheme,
- ),
- ],
- if (firstCaptureLine != null) ...[
- const SizedBox(height: 16),
- Text(
- firstCaptureLine,
- style: textTheme.smallMuted,
- ),
- ],
- const Spacer(),
- ],
- );
- }
-}
-
-class _RhythmCardContent extends StatelessWidget {
- const _RhythmCardContent({
- required this.card,
- required this.colorScheme,
- required this.textTheme,
- });
-
- final WrappedCard card;
- final EnteColorScheme colorScheme;
- final EnteTextTheme textTheme;
-
- @override
- Widget build(BuildContext context) {
- final List<String> chips = _stringListFromMeta(card.meta, "detailChips");
-
- return Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(
- card.title,
- style: textTheme.h2Bold,
- ),
- if (card.subtitle != null && card.subtitle!.isNotEmpty)
- Padding(
- padding: const EdgeInsets.only(top: 12),
- child: Text(
- card.subtitle!,
- style: textTheme.bodyMuted,
- ),
- ),
- if (chips.isNotEmpty) ...[
- const SizedBox(height: 18),
- _DetailChips(
- chips: chips,
- colorScheme: colorScheme,
- textTheme: textTheme,
- ),
- ],
- if (card.media.isNotEmpty) ...[
- const SizedBox(height: 22),
- _MediaRow(
- media: card.media.take(3).toList(growable: false),
- colorScheme: colorScheme,
- ),
- ],
- const Spacer(),
- ],
- );
- }
-}
-
-class _BusiestDayCardContent extends StatelessWidget {
- const _BusiestDayCardContent({
- required this.card,
- required this.colorScheme,
- required this.textTheme,
- });
-
- final WrappedCard card;
- final EnteColorScheme colorScheme;
- final EnteTextTheme textTheme;
-
- @override
- Widget build(BuildContext context) {
- final List<String> chips = _stringListFromMeta(card.meta, "detailChips");
-
- return Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(
- card.title,
- style: textTheme.h2Bold,
- ),
- if (card.subtitle != null && card.subtitle!.isNotEmpty)
- Padding(
- padding: const EdgeInsets.only(top: 12),
- child: Text(
- card.subtitle!,
- style: textTheme.bodyMuted,
- ),
- ),
- if (chips.isNotEmpty) ...[
- const SizedBox(height: 18),
- _DetailChips(
- chips: chips,
- colorScheme: colorScheme,
- textTheme: textTheme,
- ),
- ],
- const SizedBox(height: 22),
- _MediaGrid(
- media: card.media.take(6).toList(growable: false),
- colorScheme: colorScheme,
- ),
- const Spacer(),
- ],
- );
- }
-}
-
-class _HeatmapCardContent extends StatelessWidget {
- const _HeatmapCardContent({
- required this.card,
- required this.colorScheme,
- required this.textTheme,
- });
-
- final WrappedCard card;
- final EnteColorScheme colorScheme;
- final EnteTextTheme textTheme;
-
- @override
- Widget build(BuildContext context) {
- final List<String> chips = _stringListFromMeta(card.meta, "detailChips");
- final List<dynamic> rawQuarters =
- card.meta["quarters"] as List<dynamic>? ?? const <dynamic>[];
- final List<_QuarterBlock> quarters = rawQuarters
- .map(
- (dynamic entry) => _QuarterBlock.fromJson(
- (entry as Map).cast<String, Object?>(),
- ),
- )
- .where((_QuarterBlock block) => block.grid.isNotEmpty)
- .toList(growable: false);
- final List<String> weekdayLabels =
- (card.meta["weekdayLabels"] as List<dynamic>? ?? const <dynamic>[])
- .whereType<String>()
- .toList(growable: false);
- final int maxCount = (card.meta["maxCount"] as num?)?.toInt() ?? 0;
-
- return Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(
- card.title,
- style: textTheme.h2Bold,
- ),
- if (card.subtitle != null && card.subtitle!.isNotEmpty)
- Padding(
- padding: const EdgeInsets.only(top: 12),
- child: Text(
- card.subtitle!,
- style: textTheme.bodyMuted,
- ),
- ),
- const SizedBox(height: 18),
- if (quarters.isEmpty)
- _MediaPlaceholder(
- height: 180,
- colorScheme: colorScheme,
- )
- else
- LayoutBuilder(
- builder: (BuildContext context, BoxConstraints constraints) {
- final double maxWidth = constraints.maxWidth;
- final int columns =
- quarters.length <= 1 ? 1 : (maxWidth >= 280 ? 2 : 1);
- final double spacing = columns > 1 ? 18 : 0;
- final double itemWidth = columns > 1
- ? (maxWidth - ((columns - 1) * spacing)) / columns
- : maxWidth;
- final int maxColumnCount = quarters
- .map(
- (_QuarterBlock block) =>
- block.grid.isNotEmpty ? block.grid.first.length : 0,
- )
- .fold(0, math.max);
- const double labelColumnWidth = 20;
- const double cellSpacing = 1.5;
- const double fallbackCellSize = 6;
- const double maxCellWidth = 18;
- const double maxCellHeight = 12;
-
- double computeCellWidth(double availableWidth) {
- if (maxColumnCount <= 0) {
- return fallbackCellSize;
- }
- final double usable = math.max(
- 0,
- availableWidth -
- cellSpacing * math.max(0, maxColumnCount - 1),
- );
- final double raw = usable / math.max(1, maxColumnCount);
- return raw.clamp(fallbackCellSize, maxCellWidth);
- }
-
- final double cellWidthWithLabels =
- computeCellWidth(itemWidth - labelColumnWidth);
- final double cellWidthWithoutLabels = computeCellWidth(itemWidth);
- final double cellWidth =
- math.min(cellWidthWithLabels, cellWidthWithoutLabels);
- final double cellHeight = math.min(
- maxCellHeight,
- cellWidth.clamp(fallbackCellSize, maxCellHeight),
- );
- return Wrap(
- spacing: spacing,
- runSpacing: 18,
- children: <Widget>[
- for (final (int index, _QuarterBlock block)
- in quarters.indexed)
- SizedBox(
- width: itemWidth,
- child: _QuarterHeatmap(
- block: block,
- weekdayLabels: weekdayLabels,
- maxCount: maxCount,
- colorScheme: colorScheme,
- textTheme: textTheme,
- showDayLabels: columns == 1 || index % columns == 0,
- cellWidth: cellWidth,
- cellHeight: cellHeight,
- cellSpacing: cellSpacing,
- labelColumnWidth: labelColumnWidth,
- ),
- ),
- ],
- );
- },
- ),
- if (chips.isNotEmpty) ...[
- const SizedBox(height: 20),
- _DetailChips(
- chips: chips,
- colorScheme: colorScheme,
- textTheme: textTheme,
- ),
- ],
- const Spacer(),
- ],
- );
- }
-}
-
-class _GenericCardContent extends StatelessWidget {
- const _GenericCardContent({
- required this.card,
- required this.textTheme,
- });
-
- final WrappedCard card;
- final EnteTextTheme textTheme;
-
- @override
- Widget build(BuildContext context) {
- return Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(
- card.title,
- style: textTheme.h2Bold,
- ),
- if (card.subtitle != null && card.subtitle!.isNotEmpty)
- Padding(
- padding: const EdgeInsets.only(top: 12),
- child: Text(
- card.subtitle!,
- style: textTheme.bodyMuted,
- ),
- ),
- const Spacer(),
- ],
- );
- }
-}
-
-class _QuarterBlock {
- _QuarterBlock({
- required this.label,
- required this.grid,
- required this.columnLabels,
- });
-
- final String label;
- final List<List<int>> grid;
- final List<String> columnLabels;
-
- static _QuarterBlock fromJson(Map<String, Object?> json) {
- final List<List<int>> grid =
- (json["grid"] as List<dynamic>? ?? const <dynamic>[])
- .map(
- (dynamic row) => (row as List<dynamic>)
- .map((dynamic value) => (value as num).toInt())
- .toList(growable: false),
- )
- .toList(growable: false);
- final List<String> columnLabels =
- (json["columnLabels"] as List<dynamic>? ?? const <dynamic>[])
- .whereType<String>()
- .toList(growable: false);
- return _QuarterBlock(
- label: json["label"] as String? ?? "",
- grid: grid,
- columnLabels: columnLabels,
- );
- }
-}
-
-class _QuarterHeatmap extends StatelessWidget {
- const _QuarterHeatmap({
- required this.block,
- required this.weekdayLabels,
- required this.maxCount,
- required this.colorScheme,
- required this.textTheme,
- required this.showDayLabels,
- required this.cellWidth,
- required this.cellHeight,
- required this.cellSpacing,
- required this.labelColumnWidth,
- });
-
- final _QuarterBlock block;
- final List<String> weekdayLabels;
- final int maxCount;
- final EnteColorScheme colorScheme;
- final EnteTextTheme textTheme;
- final bool showDayLabels;
- final double cellWidth;
- final double cellHeight;
- final double cellSpacing;
- final double labelColumnWidth;
-
- @override
- Widget build(BuildContext context) {
- final int columnCount = block.grid.isEmpty ? 0 : block.grid.first.length;
- if (columnCount == 0) {
- return _MediaPlaceholder(
- height: 120,
- colorScheme: colorScheme,
- );
- }
-
- final TextStyle axisStyle =
- textTheme.tinyMuted.copyWith(fontSize: 8.5, height: 1.15);
- final List<String> headerLabels = List<String>.generate(
- columnCount,
- (int index) =>
- index < block.columnLabels.length ? block.columnLabels[index] : "",
- );
-
- return Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(
- block.label,
- style: textTheme.smallBold,
- ),
- const SizedBox(height: 6),
- Row(
- children: [
- SizedBox(width: labelColumnWidth),
- for (int columnIndex = 0;
- columnIndex < headerLabels.length;
- columnIndex += 1) ...[
- SizedBox(
- width: cellWidth,
- child: Text(
- headerLabels[columnIndex],
- style: axisStyle,
- textAlign: TextAlign.center,
- softWrap: false,
- overflow: TextOverflow.fade,
- ),
- ),
- SizedBox(
- width: columnIndex == headerLabels.length - 1 ? 0 : cellSpacing,
- ),
- ],
- ],
- ),
- const SizedBox(height: 4),
- Column(
- children: List<Widget>.generate(weekdayLabels.length, (int dayIndex) {
- final List<int> row = block.grid.length > dayIndex
- ? block.grid[dayIndex]
- : const <int>[];
- final String dayLabel =
- dayIndex < weekdayLabels.length ? weekdayLabels[dayIndex] : "";
- return Padding(
- padding: EdgeInsets.only(
- bottom: dayIndex == weekdayLabels.length - 1 ? 0 : cellSpacing,
- ),
- child: Row(
- children: [
- SizedBox(
- width: labelColumnWidth,
- child: Visibility(
- visible: showDayLabels,
- maintainSize: true,
- maintainAnimation: true,
- maintainState: true,
- child: Text(
- dayLabel,
- style: axisStyle,
- ),
- ),
- ),
- for (int columnIndex = 0;
- columnIndex < columnCount;
- columnIndex += 1) ...[
- _HeatmapCell(
- value: columnIndex < row.length ? row[columnIndex] : -1,
- width: cellWidth,
- height: cellHeight,
- colorScheme: colorScheme,
- maxCount: maxCount,
- ),
- SizedBox(
- width: columnIndex == columnCount - 1 ? 0 : cellSpacing,
- ),
- ],
- ],
- ),
- );
- }),
- ),
- ],
- );
- }
-}
-
-class _HeatmapCell extends StatelessWidget {
- const _HeatmapCell({
- required this.value,
- required this.width,
- required this.height,
- required this.colorScheme,
- required this.maxCount,
- });
-
- final int value;
- final double width;
- final double height;
- final EnteColorScheme colorScheme;
- final int maxCount;
-
- @override
- Widget build(BuildContext context) {
- if (value == kWrappedHeatmapFutureValue) {
- return SizedBox(width: width, height: height);
- }
- if (value == kWrappedHeatmapPaddedValue) {
- final Color base = colorScheme.fillFaint;
- final double placeholderAlpha = (base.a * 0.4).clamp(0.0, 1.0).toDouble();
- return Container(
- width: width,
- height: height,
- decoration: BoxDecoration(
- color: base.withValues(alpha: placeholderAlpha),
- borderRadius: BorderRadius.circular(3),
- ),
- );
- }
- return Container(
- width: width,
- height: height,
- decoration: BoxDecoration(
- color: _heatmapColorForValue(value, maxCount, colorScheme),
- borderRadius: BorderRadius.circular(3),
- ),
- );
- }
-}
-
-class _DetailChips extends StatelessWidget {
- const _DetailChips({
- required this.chips,
- required this.colorScheme,
- required this.textTheme,
- });
-
- final List<String> chips;
- final EnteColorScheme colorScheme;
- final EnteTextTheme textTheme;
-
- @override
- Widget build(BuildContext context) {
- if (chips.isEmpty) {
- return const SizedBox.shrink();
- }
- return Wrap(
- spacing: 10,
- runSpacing: 8,
- children: chips
- .map(
- (String chip) => Container(
- padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
- decoration: BoxDecoration(
- color: colorScheme.fillFaint,
- borderRadius: BorderRadius.circular(14),
- ),
- child: Text(
- chip,
- style: textTheme.smallMuted,
- ),
- ),
- )
- .toList(growable: false),
- );
- }
-}
-
-class _HeroMediaCollage extends StatelessWidget {
- const _HeroMediaCollage({
- required this.media,
- required this.colorScheme,
- });
-
- final List<MediaRef> media;
- final EnteColorScheme colorScheme;
-
- @override
- Widget build(BuildContext context) {
- if (media.isEmpty) {
- return _MediaPlaceholder(
- height: 220,
- colorScheme: colorScheme,
- borderRadius: 24,
- );
- }
-
- final List<MediaRef> trimmed = media.take(3).toList(growable: false);
- final MediaRef primary = trimmed.first;
- final List<MediaRef> side = trimmed.skip(1).toList(growable: false);
-
- return SizedBox(
- height: 220,
- child: Row(
- children: [
- Expanded(
- flex: 2,
- child: _MediaTile(
- mediaRef: primary,
- borderRadius: 24,
- aspectRatio: 3 / 4,
- ),
- ),
- if (side.isNotEmpty) ...[
- const SizedBox(width: 12),
- Expanded(
- child: Column(
- children: List<Widget>.generate(
- 2,
- (int index) {
- final MediaRef? ref =
- index < side.length ? side[index] : null;
- return Expanded(
- child: Padding(
- padding: EdgeInsets.only(
- bottom: index == 0 ? 12 : 0,
- ),
- child: ref != null
- ? _MediaTile(
- mediaRef: ref,
- borderRadius: 20,
- )
- : _MediaPlaceholder(
- colorScheme: colorScheme,
- borderRadius: 20,
- ),
- ),
- );
- },
- ),
- ),
- ),
- ],
- ],
- ),
- );
- }
-}
-
-class _MediaRow extends StatelessWidget {
- const _MediaRow({
- required this.media,
- required this.colorScheme,
- });
-
- final List<MediaRef> media;
- final EnteColorScheme colorScheme;
-
- @override
- Widget build(BuildContext context) {
- return SizedBox(
- height: 96,
- child: Row(
- children: [
- for (final (int index, MediaRef ref) in media.indexed) ...[
- Expanded(
- child: Padding(
- padding:
- EdgeInsets.only(right: index == media.length - 1 ? 0 : 12),
- child: _MediaTile(
- mediaRef: ref,
- borderRadius: 18,
- ),
- ),
- ),
- ],
- if (media.isEmpty)
- Expanded(
- child: _MediaPlaceholder(
- colorScheme: colorScheme,
- borderRadius: 18,
- ),
- ),
- ],
- ),
- );
- }
-}
-
-class _MediaGrid extends StatelessWidget {
- const _MediaGrid({
- required this.media,
- required this.colorScheme,
- });
-
- final List<MediaRef> media;
- final EnteColorScheme colorScheme;
-
- @override
- Widget build(BuildContext context) {
- if (media.isEmpty) {
- return _MediaPlaceholder(
- height: 200,
- colorScheme: colorScheme,
- );
- }
- return AspectRatio(
- aspectRatio: 2 / 3,
- child: Column(
- children: List<Widget>.generate(3, (int row) {
- return Expanded(
- child: Row(
- children: List<Widget>.generate(2, (int column) {
- final int index = row * 2 + column;
- final MediaRef? ref =
- index < media.length ? media[index] : null;
- return Expanded(
- child: Padding(
- padding: EdgeInsets.only(
- right: column == 1 ? 0 : 10,
- bottom: row == 2 ? 0 : 10,
- ),
- child: ref != null
- ? _MediaTile(
- mediaRef: ref,
- borderRadius: 16,
- )
- : _MediaPlaceholder(
- colorScheme: colorScheme,
- borderRadius: 16,
- ),
- ),
- );
- }),
- ),
- );
- }),
- ),
- );
- }
-}
-
-class _MediaTile extends StatelessWidget {
- const _MediaTile({
- required this.mediaRef,
- required this.borderRadius,
- this.aspectRatio,
- });
-
- final MediaRef mediaRef;
- final double borderRadius;
- final double? aspectRatio;
-
- @override
- Widget build(BuildContext context) {
- Widget content = ClipRRect(
- borderRadius: BorderRadius.circular(borderRadius),
- child: SizedBox.expand(
- child: _MediaThumb(
- ref: mediaRef,
- ),
- ),
- );
- if (aspectRatio != null) {
- content = AspectRatio(
- aspectRatio: aspectRatio!,
- child: content,
- );
- }
- return content;
- }
-}
-
-class _MediaPlaceholder extends StatelessWidget {
- const _MediaPlaceholder({
- required this.colorScheme,
- this.height,
- this.borderRadius = 20,
- });
-
- final EnteColorScheme colorScheme;
- final double? height;
- final double borderRadius;
-
- @override
- Widget build(BuildContext context) {
- final Widget child = Container(
- decoration: BoxDecoration(
- color: colorScheme.primary400.withValues(alpha: 0.12),
- borderRadius: BorderRadius.circular(borderRadius),
- ),
- );
- if (height != null) {
- return SizedBox(
- height: height,
- child: child,
- );
- }
- return child;
- }
-}
-
-class _MediaThumb extends StatefulWidget {
- const _MediaThumb({required this.ref});
-
- final MediaRef ref;
-
- @override
- State<_MediaThumb> createState() => _MediaThumbState();
-}
-
-class _MediaThumbState extends State<_MediaThumb> {
- late Future<EnteFile?> _fileFuture;
-
- @override
- void initState() {
- super.initState();
- _fileFuture = FilesDB.instance.getAnyUploadedFile(
- widget.ref.uploadedFileID,
- );
- }
-
- @override
- void didUpdateWidget(covariant _MediaThumb oldWidget) {
- super.didUpdateWidget(oldWidget);
- if (oldWidget.ref.uploadedFileID != widget.ref.uploadedFileID) {
- _fileFuture = FilesDB.instance.getAnyUploadedFile(
- widget.ref.uploadedFileID,
- );
- }
- }
-
- @override
- Widget build(BuildContext context) {
- final colorScheme = getEnteColorScheme(context);
- return FutureBuilder<EnteFile?>(
- future: _fileFuture,
- builder: (BuildContext context, AsyncSnapshot<EnteFile?> snapshot) {
- if (snapshot.connectionState != ConnectionState.done) {
- return Container(
- color: colorScheme.fillFaint,
- );
- }
- final EnteFile? file = snapshot.data;
- if (file == null) {
- return Container(
- color: colorScheme.fillFaint,
- );
- }
- return ThumbnailWidget(
- file,
- fit: BoxFit.cover,
- rawThumbnail: true,
- shouldShowSyncStatus: false,
- shouldShowArchiveStatus: false,
- shouldShowPinIcon: false,
- shouldShowOwnerAvatar: false,
- shouldShowFavoriteIcon: false,
- shouldShowVideoDuration: false,
- shouldShowVideoOverlayIcon: false,
- );
- },
- );
- }
-}
-
-Color _heatmapColorForValue(
- int value,
- int maxValue,
- EnteColorScheme scheme,
-) {
- if (value <= 0 || maxValue <= 0) {
- return scheme.fillFaint;
- }
- final double t = (value / maxValue).clamp(0.0, 1.0);
- return Color.lerp(
- scheme.primary400.withValues(alpha: 0.25),
- scheme.primary500,
- t,
- ) ??
- scheme.primary500;
-}
-
-List<String> _stringListFromMeta(
- Map<String, Object?> meta,
- String key,
-) {
- final Object? raw = meta[key];
- if (raw is List) {
- return raw.whereType<String>().toList(growable: false);
- }
- return const <String>[];
-}
-
-class _StoryProgressBar extends StatelessWidget {
- const _StoryProgressBar({
- required this.progressValues,
- required this.colorScheme,
- });
-
- final List<double> progressValues;
- final EnteColorScheme colorScheme;
-
- @override
- Widget build(BuildContext context) {
- return Row(
- children: [
- for (final (int index, double value)
- in progressValues.indexed) ...<Widget>[
- Expanded(
- child: _ProgressSegment(
- progress: value,
- colorScheme: colorScheme,
- ),
- ),
- if (index != progressValues.length - 1) const SizedBox(width: 6),
- ],
- ],
- );
- }
-}
-
-class _ProgressSegment extends StatelessWidget {
- const _ProgressSegment({
- required this.progress,
- required this.colorScheme,
- });
-
- final double progress;
- final EnteColorScheme colorScheme;
-
- @override
- Widget build(BuildContext context) {
- return ClipRRect(
- borderRadius: BorderRadius.circular(6),
- child: Stack(
- children: [
- Container(
- height: 4,
- color: colorScheme.fillFaint,
- ),
- FractionallySizedBox(
- widthFactor: progress.clamp(0.0, 1.0),
- child: Container(
- height: 4,
- color: colorScheme.primary500,
- ),
- ),
- ],
- ),
- );
- }
-}