Skip to content

armgit / ente

Public Imported from GitHub
0

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

activity screen start

laurenspriemdf6430eb00ff
diff --git a/mobile/apps/photos/lib/main.dart b/mobile/apps/photos/lib/main.dart
index 11ec5d1bff..3837356f53 100644
--- a/mobile/apps/photos/lib/main.dart
+++ b/mobile/apps/photos/lib/main.dart
@@ -300,6 +300,10 @@ Future<void> _init(bool isBackground, {String via = ''}) async {
await SyncService.instance.init(preferences);
_logger.info("SyncService init done $tlog");
+ _logger.info("ActivityService init $tlog");
+ await activityService.init();
+ _logger.info("ActivityService init done $tlog");
+
if (!isBackground) {
await _scheduleFGHomeWidgetSync();
}
diff --git a/mobile/apps/photos/lib/models/activity/activity_models.dart b/mobile/apps/photos/lib/models/activity/activity_models.dart
new file mode 100644
index 0000000000..b4daec076e
--- /dev/null
+++ b/mobile/apps/photos/lib/models/activity/activity_models.dart
@@ -0,0 +1,168 @@
+import "package:flutter/material.dart";
+import "package:photos/models/base/id.dart";
+
+class ActivityDay {
+ final DateTime date;
+ final bool hasActivity;
+
+ const ActivityDay({
+ required this.date,
+ required this.hasActivity,
+ });
+}
+
+class ActivitySummary {
+ final List<ActivityDay> last365Days;
+ final List<ActivityDay> last7Days;
+ final int currentStreak;
+ final int longestStreak;
+ final Map<int, bool> badgesUnlocked;
+ final Map<String, RitualProgress> ritualProgress;
+ final DateTime generatedAt;
+
+ const ActivitySummary({
+ required this.last365Days,
+ required this.last7Days,
+ required this.currentStreak,
+ required this.longestStreak,
+ required this.badgesUnlocked,
+ required this.ritualProgress,
+ required this.generatedAt,
+ });
+
+ bool get hasSevenDayFire => last7Days.every((d) => d.hasActivity);
+}
+
+class Ritual {
+ Ritual({
+ required this.id,
+ required this.title,
+ required this.daysOfWeek, // Sunday-first ordering of length 7
+ required this.timeOfDay,
+ required this.albumId,
+ required this.albumName,
+ required this.icon,
+ required this.createdAt,
+ });
+
+ final String id;
+ final String title;
+ final List<bool> daysOfWeek;
+ final TimeOfDay timeOfDay;
+ final int? albumId;
+ final String? albumName;
+ final String icon;
+ final DateTime createdAt;
+
+ Ritual copyWith({
+ String? id,
+ String? title,
+ List<bool>? daysOfWeek,
+ TimeOfDay? timeOfDay,
+ int? albumId,
+ String? albumName,
+ String? icon,
+ DateTime? createdAt,
+ }) {
+ return Ritual(
+ id: id ?? this.id,
+ title: title ?? this.title,
+ daysOfWeek: daysOfWeek ?? this.daysOfWeek,
+ timeOfDay: timeOfDay ?? this.timeOfDay,
+ albumId: albumId ?? this.albumId,
+ albumName: albumName ?? this.albumName,
+ icon: icon ?? this.icon,
+ createdAt: createdAt ?? this.createdAt,
+ );
+ }
+
+ Map<String, dynamic> toJson() {
+ return {
+ "id": id,
+ "title": title,
+ "daysOfWeek": daysOfWeek,
+ "hour": timeOfDay.hour,
+ "minute": timeOfDay.minute,
+ "albumId": albumId,
+ "albumName": albumName,
+ "icon": icon,
+ "createdAt": createdAt.millisecondsSinceEpoch,
+ };
+ }
+
+ factory Ritual.fromJson(Map<String, dynamic> json) {
+ return Ritual(
+ id: json["id"] as String? ?? newID("ritual"),
+ title: json["title"] as String? ?? "",
+ daysOfWeek: List<bool>.from(
+ (json["daysOfWeek"] as List<dynamic>? ?? List<bool>.filled(7, false)),
+ ),
+ timeOfDay: TimeOfDay(
+ hour: (json["hour"] as num?)?.toInt() ?? 9,
+ minute: (json["minute"] as num?)?.toInt() ?? 0,
+ ),
+ albumId: (json["albumId"] as num?)?.toInt(),
+ albumName: json["albumName"] as String?,
+ icon: json["icon"] as String? ?? "πŸ“Έ",
+ createdAt: DateTime.fromMillisecondsSinceEpoch(
+ (json["createdAt"] as num?)?.toInt() ??
+ DateTime.now().millisecondsSinceEpoch,
+ ),
+ );
+ }
+}
+
+class RitualProgress {
+ final String ritualId;
+ final Set<DateTime> completedDays;
+
+ const RitualProgress({
+ required this.ritualId,
+ required this.completedDays,
+ });
+
+ bool hasCompleted(DateTime day) {
+ final dayKey = DateTime(day.year, day.month, day.day);
+ return completedDays.any(
+ (d) =>
+ d.year == dayKey.year &&
+ d.month == dayKey.month &&
+ d.day == dayKey.day,
+ );
+ }
+}
+
+class ActivityState {
+ final bool loading;
+ final ActivitySummary? summary;
+ final List<Ritual> rituals;
+ final String? error;
+
+ const ActivityState({
+ required this.loading,
+ required this.summary,
+ required this.rituals,
+ required this.error,
+ });
+
+ factory ActivityState.loading() => const ActivityState(
+ loading: true,
+ summary: null,
+ rituals: [],
+ error: null,
+ );
+
+ ActivityState copyWith({
+ bool? loading,
+ ActivitySummary? summary,
+ List<Ritual>? rituals,
+ String? error,
+ }) {
+ return ActivityState(
+ loading: loading ?? this.loading,
+ summary: summary ?? this.summary,
+ rituals: rituals ?? this.rituals,
+ error: error,
+ );
+ }
+}
diff --git a/mobile/apps/photos/lib/service_locator.dart b/mobile/apps/photos/lib/service_locator.dart
index ab09d0dd70..cf8f8bdb31 100644
--- a/mobile/apps/photos/lib/service_locator.dart
+++ b/mobile/apps/photos/lib/service_locator.dart
@@ -6,6 +6,7 @@ import "package:package_info_plus/package_info_plus.dart";
import "package:photos/gateways/entity_gw.dart";
import "package:photos/module/download/manager.dart";
import "package:photos/services/account/billing_service.dart";
+import "package:photos/services/activity/activity_service.dart";
import "package:photos/services/collections_service.dart";
import "package:photos/services/entity_service.dart";
import "package:photos/services/filedata/filedata_service.dart";
@@ -194,6 +195,12 @@ SmartAlbumsService get smartAlbumsService {
return _smartAlbumsService!;
}
+ActivityService? _activityService;
+ActivityService get activityService {
+ _activityService ??= ActivityService.instance;
+ return _activityService!;
+}
+
CollectionsService? _collectionsService;
CollectionsService get collectionsService {
_collectionsService ??= CollectionsService.instance;
diff --git a/mobile/apps/photos/lib/services/activity/activity_service.dart b/mobile/apps/photos/lib/services/activity/activity_service.dart
new file mode 100644
index 0000000000..df18eeed90
--- /dev/null
+++ b/mobile/apps/photos/lib/services/activity/activity_service.dart
@@ -0,0 +1,318 @@
+import "dart:async";
+import "dart:convert";
+import "dart:math";
+
+import "package:flutter/material.dart";
+import "package:logging/logging.dart";
+import "package:photos/core/configuration.dart";
+import "package:photos/core/event_bus.dart";
+import "package:photos/db/files_db.dart";
+import "package:photos/events/files_updated_event.dart";
+import "package:photos/models/activity/activity_models.dart";
+import "package:photos/models/base/id.dart";
+import "package:photos/models/file/file.dart";
+import "package:photos/service_locator.dart";
+import "package:photos/services/notification_service.dart";
+import "package:shared_preferences/shared_preferences.dart";
+
+class ActivityService {
+ static final ActivityService instance = ActivityService._privateConstructor();
+
+ ActivityService._privateConstructor();
+
+ final Logger _logger = Logger("ActivityService");
+ final ValueNotifier<ActivityState> stateNotifier =
+ ValueNotifier<ActivityState>(ActivityState.loading());
+ late SharedPreferences _preferences;
+ Timer? _debounce;
+ StreamSubscription<FilesUpdatedEvent>? _filesUpdatedSubscription;
+
+ static const _ritualsPrefsKey = "activity_rituals_v1";
+ static const _badgeThresholds = [7, 14, 30, 90, 180, 365];
+
+ Future<void> init() async {
+ _preferences = ServiceLocator.instance.prefs;
+ _filesUpdatedSubscription =
+ Bus.instance.on<FilesUpdatedEvent>().listen((event) {
+ _scheduleRefresh();
+ });
+ _scheduleRefresh(initial: true);
+ }
+
+ void dispose() {
+ _filesUpdatedSubscription?.cancel();
+ _debounce?.cancel();
+ }
+
+ void _scheduleRefresh({bool initial = false}) {
+ _debounce?.cancel();
+ _debounce = Timer(
+ initial ? const Duration(seconds: 4) : const Duration(seconds: 1),
+ refresh,
+ );
+ }
+
+ Future<void> refresh() async {
+ try {
+ stateNotifier.value = stateNotifier.value.copyWith(
+ loading: true,
+ error: null,
+ );
+ final rituals = await _loadRituals();
+ for (final ritual in rituals) {
+ await _scheduleRitualNotifications(ritual);
+ }
+ final summary = await _buildSummary(rituals);
+ stateNotifier.value = ActivityState(
+ loading: false,
+ summary: summary,
+ rituals: rituals,
+ error: null,
+ );
+ } catch (e, s) {
+ _logger.severe("Failed to refresh activity", e, s);
+ stateNotifier.value = stateNotifier.value.copyWith(
+ loading: false,
+ error: e.toString(),
+ );
+ }
+ }
+
+ Future<ActivitySummary> _buildSummary(List<Ritual> rituals) async {
+ final userId = Configuration.instance.getUserID();
+ if (userId == null) {
+ return ActivitySummary(
+ last365Days: _emptyDays(),
+ last7Days: _emptyDays().sublist(358),
+ currentStreak: 0,
+ longestStreak: 0,
+ badgesUnlocked: _badgeStates(0),
+ ritualProgress: {},
+ generatedAt: DateTime.now(),
+ );
+ }
+ final today = DateTime.now();
+ final todayMidnight = DateTime(today.year, today.month, today.day);
+ final cutoffDate = todayMidnight.subtract(const Duration(days: 364));
+ final endOfToday = todayMidnight.add(
+ const Duration(
+ hours: 23,
+ minutes: 59,
+ seconds: 59,
+ milliseconds: 999,
+ ),
+ );
+ final startMicros = cutoffDate.microsecondsSinceEpoch;
+ final endMicros = endOfToday.microsecondsSinceEpoch;
+ final durations = <List<int>>[
+ [startMicros, endMicros + 1],
+ ];
+ final files = await FilesDB.instance.getFilesCreatedWithinDurations(
+ durations,
+ <int>{},
+ order: 'ASC',
+ );
+
+ final Set<int> dayKeys = <int>{};
+ final Map<int, Set<int>> collectionActivity = {};
+
+ for (final EnteFile file in files) {
+ final bool ownerMatches =
+ file.ownerID == null ? true : file.ownerID == userId;
+ final bool uploaded =
+ file.uploadedFileID != null && file.uploadedFileID != -1;
+ if (!(ownerMatches && uploaded)) {
+ continue;
+ }
+ if (file.creationTime == null) continue;
+ final date =
+ DateTime.fromMicrosecondsSinceEpoch(file.creationTime!).toLocal();
+ final bucket = DateTime(date.year, date.month, date.day);
+ final dayKey = bucket.millisecondsSinceEpoch;
+ if (bucket.isBefore(cutoffDate) || bucket.isAfter(todayMidnight)) {
+ continue;
+ }
+ dayKeys.add(dayKey);
+ if (file.collectionID != null && file.collectionID! > 0) {
+ collectionActivity
+ .putIfAbsent(file.collectionID!, () => <int>{})
+ .add(dayKey);
+ }
+ }
+
+ final List<ActivityDay> last365Days = List.generate(365, (index) {
+ final day = cutoffDate.add(Duration(days: index));
+ final key = DateTime(day.year, day.month, day.day).millisecondsSinceEpoch;
+ return ActivityDay(date: day, hasActivity: dayKeys.contains(key));
+ });
+ final List<ActivityDay> last7Days =
+ last365Days.sublist(last365Days.length - 7);
+
+ int longestStreak = 0;
+ int rolling = 0;
+ for (final day in last365Days) {
+ if (day.hasActivity) {
+ rolling += 1;
+ longestStreak = max(longestStreak, rolling);
+ } else {
+ rolling = 0;
+ }
+ }
+ int currentStreak = 0;
+ for (int i = last365Days.length - 1; i >= 0; i--) {
+ if (last365Days[i].hasActivity) {
+ currentStreak += 1;
+ } else {
+ break;
+ }
+ }
+
+ final ritualProgress = <String, RitualProgress>{};
+ for (final ritual in rituals) {
+ if (ritual.albumId == null) continue;
+ final dates = collectionActivity[ritual.albumId] ?? <int>{};
+ ritualProgress[ritual.id] = RitualProgress(
+ ritualId: ritual.id,
+ completedDays: dates
+ .map((millis) => DateTime.fromMillisecondsSinceEpoch(millis))
+ .toSet(),
+ );
+ }
+
+ return ActivitySummary(
+ last365Days: last365Days,
+ last7Days: last7Days,
+ currentStreak: currentStreak,
+ longestStreak: longestStreak,
+ badgesUnlocked: _badgeStates(longestStreak),
+ ritualProgress: ritualProgress,
+ generatedAt: DateTime.now(),
+ );
+ }
+
+ List<ActivityDay> _emptyDays() {
+ final today = DateTime.now();
+ final todayMidnight = DateTime(today.year, today.month, today.day);
+ final cutoffDate = todayMidnight.subtract(const Duration(days: 364));
+ return List.generate(
+ 365,
+ (index) => ActivityDay(
+ date: cutoffDate.add(Duration(days: index)),
+ hasActivity: false,
+ ),
+ );
+ }
+
+ Map<int, bool> _badgeStates(int streak) {
+ return {
+ for (final t in _badgeThresholds) t: streak >= t,
+ };
+ }
+
+ Future<List<Ritual>> _loadRituals() async {
+ final raw = _preferences.getStringList(_ritualsPrefsKey) ?? [];
+ return raw
+ .map(
+ (str) => Ritual.fromJson(
+ Map<String, dynamic>.from(_decode(str)),
+ ),
+ )
+ .where((element) => element.id.isNotEmpty)
+ .toList(growable: true);
+ }
+
+ Map<String, dynamic> _decode(String value) {
+ try {
+ final decoded = jsonDecode(value);
+ if (decoded is Map<String, dynamic>) {
+ return decoded;
+ }
+ if (decoded is Map) {
+ return Map<String, dynamic>.from(decoded);
+ }
+ return <String, dynamic>{};
+ } catch (_) {
+ return <String, dynamic>{};
+ }
+ }
+
+ String _encode(Ritual ritual) => jsonEncode(ritual.toJson());
+
+ Future<void> saveRitual(Ritual ritual) async {
+ final rituals = await _loadRituals();
+ final existingIndex = rituals.indexWhere((r) => r.id == ritual.id);
+ if (existingIndex == -1) {
+ rituals.add(ritual);
+ } else {
+ rituals[existingIndex] = ritual;
+ }
+ await _persistRituals(rituals);
+ await _scheduleRitualNotifications(ritual);
+ await refresh();
+ }
+
+ Future<void> deleteRitual(String id) async {
+ final rituals = await _loadRituals();
+ rituals.removeWhere((r) => r.id == id);
+ await _persistRituals(rituals);
+ await NotificationService.instance.clearAllScheduledNotifications(
+ containingPayload: "ritualId=$id",
+ );
+ await refresh();
+ }
+
+ Future<void> _persistRituals(List<Ritual> rituals) async {
+ final encoded = rituals.map(_encode).toList();
+ await _preferences.setStringList(_ritualsPrefsKey, encoded);
+ }
+
+ Future<void> _scheduleRitualNotifications(Ritual ritual) async {
+ await NotificationService.instance.clearAllScheduledNotifications(
+ containingPayload: ritual.id,
+ );
+ final now = DateTime.now();
+ final today = DateTime(now.year, now.month, now.day);
+ final baseId = ritual.id.hashCode & 0x7fffffff;
+ int scheduled = 0;
+ for (int offset = 0; offset < 14; offset++) {
+ final targetDate = today.add(Duration(days: offset));
+ final dayIndex = targetDate.weekday % 7; // Sunday -> 0
+ if (!ritual.daysOfWeek[dayIndex]) continue;
+ final scheduledDate = DateTime(
+ targetDate.year,
+ targetDate.month,
+ targetDate.day,
+ ritual.timeOfDay.hour,
+ ritual.timeOfDay.minute,
+ );
+ if (scheduledDate.isBefore(now)) {
+ continue;
+ }
+ await NotificationService.instance.scheduleNotification(
+ ritual.title.isEmpty ? "Time for your ritual" : ritual.title,
+ message: ritual.title,
+ id: baseId + scheduled,
+ channelID: "ritual_reminders",
+ channelName: "Ritual reminders",
+ payload:
+ "ente://ritual?ritualId=${ritual.id}&albumId=${ritual.albumId ?? ""}",
+ dateTime: scheduledDate,
+ );
+ scheduled += 1;
+ if (scheduled >= 7) break;
+ }
+ }
+
+ Ritual createEmptyRitual() {
+ return Ritual(
+ id: newID("ritual"),
+ title: "",
+ daysOfWeek: List<bool>.filled(7, true),
+ timeOfDay: const TimeOfDay(hour: 9, minute: 0),
+ albumId: null,
+ albumName: null,
+ icon: "πŸ“Έ",
+ createdAt: DateTime.now(),
+ );
+ }
+}
diff --git a/mobile/apps/photos/lib/ui/activity/activity_banner.dart b/mobile/apps/photos/lib/ui/activity/activity_banner.dart
new file mode 100644
index 0000000000..a7b98d0446
--- /dev/null
+++ b/mobile/apps/photos/lib/ui/activity/activity_banner.dart
@@ -0,0 +1,140 @@
+import "package:flutter/material.dart";
+import "package:photos/models/activity/activity_models.dart";
+import "package:photos/service_locator.dart";
+import "package:photos/ui/activity/activity_screen.dart";
+import "package:photos/utils/navigation_util.dart";
+
+class ActivityBanner extends StatelessWidget {
+ const ActivityBanner({super.key});
+
+ @override
+ Widget build(BuildContext context) {
+ final colorScheme = Theme.of(context).colorScheme;
+ return ValueListenableBuilder<ActivityState>(
+ valueListenable: activityService.stateNotifier,
+ builder: (context, state, _) {
+ final summary = state.summary;
+ final seven = summary?.last7Days ??
+ List.generate(
+ 7,
+ (index) => ActivityDay(
+ date: DateTime.now().subtract(Duration(days: 6 - index)),
+ hasActivity: false,
+ ),
+ );
+ final hasFire = summary?.hasSevenDayFire ?? false;
+
+ return Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
+ child: Material(
+ color: const Color(0xFFFAFAFA),
+ borderRadius: BorderRadius.circular(20),
+ child: InkWell(
+ borderRadius: BorderRadius.circular(20),
+ onTap: () {
+ routeToPage(context, const ActivityScreen());
+ },
+ child: Padding(
+ padding:
+ const EdgeInsets.symmetric(horizontal: 12, vertical: 12),
+ child: Row(
+ children: [
+ CircleAvatar(
+ radius: 24,
+ backgroundColor:
+ colorScheme.primary.withAlpha((0.12 * 255).round()),
+ child: const Text("πŸ“Έ", style: TextStyle(fontSize: 20)),
+ ),
+ const SizedBox(width: 12),
+ Expanded(
+ child: Row(
+ mainAxisAlignment: MainAxisAlignment.spaceBetween,
+ children: [
+ ...seven.asMap().entries.map(
+ (entry) {
+ final isLast = entry.key == seven.length - 1;
+ final active = entry.value.hasActivity;
+ if (isLast && hasFire) {
+ return _FireDot();
+ }
+ return _DayDot(
+ label: _dayLabel(entry.value.date),
+ active: active,
+ );
+ },
+ ),
+ ],
+ ),
+ ),
+ const SizedBox(width: 8),
+ Icon(
+ Icons.chevron_right_rounded,
+ color: Colors.black.withAlpha((0.4 * 255).round()),
+ ),
+ ],
+ ),
+ ),
+ ),
+ ),
+ );
+ },
+ );
+ }
+
+ String _dayLabel(DateTime date) {
+ const labels = ["S", "M", "T", "W", "T", "F", "S"];
+ return labels[date.weekday % 7];
+ }
+}
+
+class _DayDot extends StatelessWidget {
+ const _DayDot({
+ required this.label,
+ required this.active,
+ });
+
+ final String label;
+ final bool active;
+
+ @override
+ Widget build(BuildContext context) {
+ return Container(
+ margin: const EdgeInsets.symmetric(horizontal: 2),
+ width: 32,
+ height: 32,
+ decoration: BoxDecoration(
+ color: active ? const Color(0xFF1DB954) : const Color(0xFFE7E7E7),
+ shape: BoxShape.circle,
+ ),
+ alignment: Alignment.center,
+ child: Text(
+ label,
+ style: const TextStyle(
+ color: Colors.white,
+ fontWeight: FontWeight.w700,
+ fontSize: 12,
+ ),
+ ),
+ );
+ }
+}
+
+class _FireDot extends StatelessWidget {
+ @override
+ Widget build(BuildContext context) {
+ return Container(
+ margin: const EdgeInsets.symmetric(horizontal: 2),
+ width: 32,
+ height: 32,
+ decoration: const BoxDecoration(
+ color: Color(0xFFFFF4E5),
+ shape: BoxShape.circle,
+ ),
+ alignment: Alignment.center,
+ child: const Icon(
+ Icons.local_fire_department_rounded,
+ color: Color(0xFFFF8C00),
+ ),
+ );
+ }
+}
diff --git a/mobile/apps/photos/lib/ui/activity/activity_screen.dart b/mobile/apps/photos/lib/ui/activity/activity_screen.dart
new file mode 100644
index 0000000000..d12ad2d9bd
--- /dev/null
+++ b/mobile/apps/photos/lib/ui/activity/activity_screen.dart
@@ -0,0 +1,688 @@
+import "package:flutter/material.dart";
+import "package:photos/models/activity/activity_models.dart";
+import "package:photos/models/collection/collection.dart";
+import "package:photos/service_locator.dart";
+import "package:photos/services/collections_service.dart";
+import "package:photos/ui/activity/activity_banner.dart";
+import "package:photos/ui/notification/toast.dart";
+
+class ActivityScreen extends StatelessWidget {
+ const ActivityScreen({super.key});
+
+ @override
+ Widget build(BuildContext context) {
+ return Scaffold(
+ appBar: AppBar(
+ title: const Text("Photos taken"),
+ actions: [
+ IconButton(
+ icon: const Icon(Icons.ios_share),
+ onPressed: () {},
+ tooltip: "Share (coming soon)",
+ ),
+ ],
+ ),
+ body: SafeArea(
+ child: ValueListenableBuilder<ActivityState>(
+ valueListenable: activityService.stateNotifier,
+ builder: (context, state, _) {
+ final summary = state.summary;
+ return RefreshIndicator(
+ onRefresh: activityService.refresh,
+ child: ListView(
+ physics: const BouncingScrollPhysics(),
+ padding: const EdgeInsets.only(bottom: 48),
+ children: [
+ const ActivityBanner(),
+ _ActivityHeatmapCard(summary: summary),
+ _AchievementsRow(summary: summary),
+ _RitualsSection(
+ rituals: state.rituals,
+ progress: summary?.ritualProgress ?? const {},
+ ),
+ ],
+ ),
+ );
+ },
+ ),
+ ),
+ );
+ }
+}
+
+class _ActivityHeatmapCard extends StatelessWidget {
+ const _ActivityHeatmapCard({required this.summary});
+
+ final ActivitySummary? summary;
+
+ @override
+ Widget build(BuildContext context) {
+ final colorScheme = Theme.of(context).colorScheme;
+ final last365 = summary?.last365Days ??
+ List.generate(
+ 365,
+ (i) => ActivityDay(
+ date: DateTime.now().subtract(Duration(days: 364 - i)),
+ hasActivity: false,
+ ),
+ );
+
+ return Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
+ child: Container(
+ decoration: BoxDecoration(
+ color: const Color(0xFFFAFAFA),
+ borderRadius: BorderRadius.circular(24),
+ border: Border.all(color: const Color(0xFFF5F5F5), width: 2),
+ ),
+ padding: const EdgeInsets.all(16),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ children: [
+ Row(
+ mainAxisAlignment: MainAxisAlignment.spaceBetween,
+ children: [
+ Text(
+ "Past year",
+ style: Theme.of(context).textTheme.titleMedium,
+ ),
+ if (summary != null)
+ Text(
+ "${summary!.currentStreak}d streak",
+ style: Theme.of(context)
+ .textTheme
+ .labelMedium
+ ?.copyWith(color: colorScheme.primary),
+ ),
+ ],
+ ),
+ const SizedBox(height: 16),
+ _Heatmap(days: last365),
+ ],
+ ),
+ ),
+ );
+ }
+}
+
+class _Heatmap extends StatelessWidget {
+ const _Heatmap({required this.days});
+
+ final List<ActivityDay> days;
+
+ @override
+ Widget build(BuildContext context) {
+ final dayHeader = ["S", "M", "T", "W", "T", "F", "S"];
+ final weeks = <List<ActivityDay>>[];
+ for (int i = 0; i < days.length; i += 7) {
+ weeks.add(days.skip(i).take(7).toList());
+ }
+
+ final monthLabels = <int, String>{};
+ for (final day in days) {
+ if (day.date.day == 1) {
+ monthLabels[weeks.indexWhere(
+ (week) => week.any(
+ (d) =>
+ d.date.year == day.date.year &&
+ d.date.month == day.date.month &&
+ d.date.day == day.date.day,
+ ),
+ )] = _monthLabel(day.date.month);
+ }
+ }
+
+ return SingleChildScrollView(
+ scrollDirection: Axis.horizontal,
+ child: Row(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Column(
+ children: [
+ const SizedBox(height: 16),
+ ...weeks.asMap().entries.map(
+ (entry) => SizedBox(
+ height: 16,
+ width: 28,
+ child: Center(
+ child: Text(
+ monthLabels[entry.key] ?? "",
+ style:
+ Theme.of(context).textTheme.labelSmall?.copyWith(
+ color: Colors.black
+ .withAlpha((0.25 * 255).round()),
+ fontSize: 10,
+ ),
+ ),
+ ),
+ ),
+ ),
+ ],
+ ),
+ const SizedBox(width: 8),
+ Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Row(
+ children: dayHeader
+ .map(
+ (d) => SizedBox(
+ width: 18,
+ child: Center(
+ child: Text(
+ d,
+ style: Theme.of(context)
+ .textTheme
+ .labelSmall
+ ?.copyWith(
+ color: Colors.black
+ .withAlpha((0.25 * 255).round()),
+ fontSize: 10,
+ ),
+ ),
+ ),
+ ),
+ )
+ .toList(),
+ ),
+ const SizedBox(height: 4),
+ ...weeks.map(
+ (week) => Row(
+ children: week
+ .map(
+ (day) => Container(
+ margin: const EdgeInsets.symmetric(
+ horizontal: 2,
+ vertical: 1,
+ ),
+ width: 18,
+ height: 12,
+ decoration: BoxDecoration(
+ color: day.hasActivity
+ ? const Color(0xFF1DB954)
+ : const Color(0xFFDFF3E4),
+ borderRadius: BorderRadius.circular(10),
+ ),
+ ),
+ )
+ .toList(),
+ ),
+ ),
+ ],
+ ),
+ ],
+ ),
+ );
+ }
+
+ String _monthLabel(int month) {
+ const labels = [
+ "Jan",
+ "Feb",
+ "Mar",
+ "Apr",
+ "May",
+ "Jun",
+ "Jul",
+ "Aug",
+ "Sep",
+ "Oct",
+ "Nov",
+ "Dec",
+ ];
+ return labels[month - 1];
+ }
+}
+
+class _AchievementsRow extends StatelessWidget {
+ const _AchievementsRow({required this.summary});
+
+ final ActivitySummary? summary;
+
+ @override
+ Widget build(BuildContext context) {
+ final badges = summary?.badgesUnlocked ??
+ {
+ 7: false,
+ 14: false,
+ 30: false,
+ 90: false,
+ 180: false,
+ 365: false,
+ };
+ return Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Row(
+ children: [
+ Text(
+ "Achievements",
+ style: Theme.of(context).textTheme.titleMedium,
+ ),
+ const Spacer(),
+ const Icon(Icons.chevron_right_rounded),
+ ],
+ ),
+ const SizedBox(height: 12),
+ SingleChildScrollView(
+ scrollDirection: Axis.horizontal,
+ child: Row(
+ children: badges.entries
+ .map(
+ (entry) => _BadgePill(
+ label: "${entry.key}d",
+ unlocked: entry.value,
+ ),
+ )
+ .toList(),
+ ),
+ ),
+ ],
+ ),
+ );
+ }
+}
+
+class _BadgePill extends StatelessWidget {
+ const _BadgePill({required this.label, required this.unlocked});
+
+ final String label;
+ final bool unlocked;
+
+ @override
+ Widget build(BuildContext context) {
+ final color = unlocked ? const Color(0xFF1DB954) : Colors.grey.shade300;
+ return Container(
+ margin: const EdgeInsets.only(right: 10),
+ padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
+ decoration: BoxDecoration(
+ color: color.withAlpha((0.2 * 255).round()),
+ borderRadius: BorderRadius.circular(20),
+ border: Border.all(color: color),
+ ),
+ child: Row(
+ children: [
+ CircleAvatar(
+ radius: 14,
+ backgroundColor: color,
+ child: const Text("πŸ…", style: TextStyle(fontSize: 14)),
+ ),
+ const SizedBox(width: 8),
+ Text(
+ label,
+ style: Theme.of(context).textTheme.bodyMedium?.copyWith(
+ color: unlocked ? Colors.black : Colors.black54,
+ fontWeight: FontWeight.w700,
+ ),
+ ),
+ ],
+ ),
+ );
+ }
+}
+
+class _RitualsSection extends StatelessWidget {
+ const _RitualsSection({
+ required this.rituals,
+ required this.progress,
+ });
+
+ final List<Ritual> rituals;
+ final Map<String, RitualProgress> progress;
+
+ @override
+ Widget build(BuildContext context) {
+ return Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Row(
+ children: [
+ Text(
+ "Activity",
+ style: Theme.of(context).textTheme.titleMedium,
+ ),
+ const Spacer(),
+ IconButton(
+ onPressed: () async {
+ await _showRitualEditor(context, ritual: null);
+ },
+ icon: const Icon(Icons.add_rounded),
+ ),
+ ],
+ ),
+ const SizedBox(height: 8),
+ if (rituals.isEmpty)
+ Text(
+ "Create a ritual to get daily reminders.",
+ style: Theme.of(context).textTheme.bodyMedium,
+ )
+ else
+ Column(
+ children: rituals
+ .map(
+ (ritual) => _RitualCard(
+ ritual: ritual,
+ completedToday:
+ progress[ritual.id]?.hasCompleted(DateTime.now()) ??
+ false,
+ ),
+ )
+ .toList(),
+ ),
+ ],
+ ),
+ );
+ }
+}
+
+class _RitualCard extends StatelessWidget {
+ const _RitualCard({
+ required this.ritual,
+ required this.completedToday,
+ });
+
+ final Ritual ritual;
+ final bool completedToday;
+
+ @override
+ Widget build(BuildContext context) {
+ return Container(
+ margin: const EdgeInsets.only(bottom: 12),
+ decoration: BoxDecoration(
+ color: const Color(0xFFFAFAFA),
+ borderRadius: BorderRadius.circular(16),
+ ),
+ child: ListTile(
+ leading: CircleAvatar(
+ backgroundColor: Colors.grey.shade200,
+ child: Text(
+ ritual.icon,
+ style: const TextStyle(fontSize: 18),
+ ),
+ ),
+ title: Text(ritual.title.isEmpty ? "Untitled ritual" : ritual.title),
+ subtitle: Text(
+ [
+ _daysLabel(ritual.daysOfWeek),
+ if (ritual.albumName != null) ritual.albumName!,
+ ].join(" β€’ "),
+ ),
+ trailing: Row(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ if (completedToday)
+ const Icon(
+ Icons.check_circle,
+ color: Color(0xFF1DB954),
+ ),
+ PopupMenuButton<String>(
+ onSelected: (value) async {
+ switch (value) {
+ case "edit":
+ await _showRitualEditor(context, ritual: ritual);
+ break;
+ case "delete":
+ await activityService.deleteRitual(ritual.id);
+ break;
+ }
+ },
+ itemBuilder: (context) => [
+ const PopupMenuItem(value: "edit", child: Text("Edit")),
+ const PopupMenuItem(
+ value: "delete",
+ child: Text(
+ "Delete",
+ style: TextStyle(color: Colors.red),
+ ),
+ ),
+ ],
+ ),
+ ],
+ ),
+ ),
+ );
+ }
+
+ String _daysLabel(List<bool> days) {
+ const labels = ["S", "M", "T", "W", "T", "F", "S"];
+ final selected = <String>[];
+ for (int i = 0; i < days.length; i++) {
+ if (days[i]) selected.add(labels[i]);
+ }
+ if (selected.length == 7) return "Every day";
+ return selected.join(" ");
+ }
+}
+
+Future<void> _showRitualEditor(BuildContext context, {Ritual? ritual}) async {
+ final controller = TextEditingController(text: ritual?.title ?? "");
+ final days = [...(ritual?.daysOfWeek ?? List<bool>.filled(7, true))];
+ final selectedAlbumName = ValueNotifier<String?>(ritual?.albumName);
+ int? selectedAlbumId = ritual?.albumId;
+ TimeOfDay selectedTime =
+ ritual?.timeOfDay ?? const TimeOfDay(hour: 9, minute: 0);
+ final String icon = ritual?.icon ?? "πŸ“Έ";
+ final formKey = GlobalKey<FormState>();
+
+ await showModalBottomSheet(
+ context: context,
+ isScrollControlled: true,
+ shape: const RoundedRectangleBorder(
+ borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
+ ),
+ builder: (context) {
+ return StatefulBuilder(
+ builder: (context, setState) {
+ return Padding(
+ padding: EdgeInsets.only(
+ bottom: MediaQuery.of(context).viewInsets.bottom + 16,
+ left: 16,
+ right: 16,
+ top: 16,
+ ),
+ child: Form(
+ key: formKey,
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ Row(
+ children: [
+ Text(
+ ritual == null ? "New ritual" : "Edit ritual",
+ style: Theme.of(context).textTheme.titleMedium,
+ ),
+ const Spacer(),
+ IconButton(
+ icon: const Icon(Icons.close),
+ onPressed: () => Navigator.of(context).pop(),
+ ),
+ ],
+ ),
+ TextFormField(
+ controller: controller,
+ autofocus: true,
+ decoration: const InputDecoration(
+ labelText: "Description",
+ ),
+ validator: (value) {
+ if (value == null || value.trim().isEmpty) {
+ return "Please enter a description";
+ }
+ return null;
+ },
+ ),
+ const SizedBox(height: 12),
+ Row(
+ children: [
+ const Text("Days"),
+ const SizedBox(width: 12),
+ Expanded(
+ child: Wrap(
+ spacing: 6,
+ children: List.generate(
+ days.length,
+ (index) => ChoiceChip(
+ label: Text(_weekLabel(index)),
+ selected: days[index],
+ onSelected: (value) {
+ setState(() {
+ days[index] = value;
+ });
+ },
+ ),
+ ),
+ ),
+ ),
+ ],
+ ),
+ const SizedBox(height: 12),
+ Row(
+ children: [
+ const Text("Time"),
+ const SizedBox(width: 12),
+ OutlinedButton.icon(
+ onPressed: () async {
+ final result = await showTimePicker(
+ context: context,
+ initialTime: selectedTime,
+ );
+ if (result != null) {
+ setState(() {
+ selectedTime = result;
+ });
+ }
+ },
+ icon: const Icon(Icons.schedule),
+ label: Text(
+ selectedTime.format(context),
+ ),
+ ),
+ ],
+ ),
+ const SizedBox(height: 12),
+ ValueListenableBuilder<String?>(
+ valueListenable: selectedAlbumName,
+ builder: (context, value, _) {
+ return ListTile(
+ contentPadding: EdgeInsets.zero,
+ title: const Text("Album"),
+ subtitle: Text(value ?? "Select album"),
+ trailing: const Icon(Icons.chevron_right),
+ onTap: () async {
+ final result = await _pickAlbum(context);
+ if (result != null) {
+ selectedAlbumId = result.id;
+ selectedAlbumName.value = result.displayName;
+ }
+ },
+ );
+ },
+ ),
+ const SizedBox(height: 8),
+ Align(
+ alignment: Alignment.centerRight,
+ child: ElevatedButton(
+ onPressed: () async {
+ if (!formKey.currentState!.validate()) return;
+ if (selectedAlbumId == null) {
+ showToast(context, "Please select an album");
+ return;
+ }
+ final updated =
+ (ritual ?? activityService.createEmptyRitual())
+ .copyWith(
+ title: controller.text.trim(),
+ daysOfWeek: days,
+ timeOfDay: selectedTime,
+ albumId: selectedAlbumId,
+ albumName: selectedAlbumName.value,
+ icon: icon,
+ );
+ await activityService.saveRitual(updated);
+ Navigator.of(context).pop();
+ },
+ child: const Text("Save"),
+ ),
+ ),
+ ],
+ ),
+ ),
+ );
+ },
+ );
+ },
+ );
+}
+
+String _weekLabel(int index) {
+ const labels = ["S", "M", "T", "W", "T", "F", "S"];
+ return labels[index];
+}
+
+Future<Collection?> _pickAlbum(BuildContext context) async {
+ final service = CollectionsService.instance;
+ final albums = await service.getCollectionForWidgetSelection();
+ Collection? selected;
+ await showModalBottomSheet(
+ context: context,
+ builder: (context) {
+ final controller = TextEditingController();
+ return StatefulBuilder(
+ builder: (context, setState) {
+ return Padding(
+ padding: const EdgeInsets.all(16),
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ Row(
+ children: [
+ const Text("Select album"),
+ const Spacer(),
+ IconButton(
+ icon: const Icon(Icons.close),
+ onPressed: () => Navigator.of(context).pop(),
+ ),
+ ],
+ ),
+ TextField(
+ controller: controller,
+ decoration: const InputDecoration(
+ labelText: "Create new album",
+ ),
+ onSubmitted: (value) async {
+ if (value.trim().isEmpty) return;
+ final created = await service.createAlbum(value.trim());
+ albums.insert(0, created);
+ setState(() {});
+ },
+ ),
+ const SizedBox(height: 12),
+ SizedBox(
+ height: 320,
+ child: ListView.builder(
+ itemCount: albums.length,
+ itemBuilder: (context, index) {
+ final album = albums[index];
+ return ListTile(
+ title: Text(album.displayName),
+ onTap: () {
+ selected = album;
+ Navigator.of(context).pop();
+ },
+ );
+ },
+ ),
+ ),
+ ],
+ ),
+ );
+ },
+ );
+ },
+ );
+ return selected;
+}
diff --git a/mobile/apps/photos/lib/ui/activity/ritual_camera_page.dart b/mobile/apps/photos/lib/ui/activity/ritual_camera_page.dart
new file mode 100644
index 0000000000..710db37ebf
--- /dev/null
+++ b/mobile/apps/photos/lib/ui/activity/ritual_camera_page.dart
@@ -0,0 +1,82 @@
+import "package:flutter/material.dart";
+import "package:photos/models/collection/collection.dart";
+import "package:photos/models/collection/collection_items.dart";
+import "package:photos/services/collections_service.dart";
+import "package:photos/ui/activity/activity_screen.dart";
+import "package:photos/ui/viewer/gallery/collection_page.dart";
+import "package:photos/utils/navigation_util.dart";
+
+class RitualCameraPage extends StatelessWidget {
+ const RitualCameraPage({
+ super.key,
+ required this.ritualId,
+ required this.albumId,
+ });
+
+ final String ritualId;
+ final int? albumId;
+
+ @override
+ Widget build(BuildContext context) {
+ return Scaffold(
+ appBar: AppBar(
+ title: const Text("Ritual capture"),
+ ),
+ body: Padding(
+ padding: const EdgeInsets.all(16),
+ child: FutureBuilder<Collection?>(
+ future: _loadCollection(),
+ builder: (context, snapshot) {
+ final collection = snapshot.data;
+ return Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ const Text(
+ "Ready to take today's ritual photo?",
+ style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600),
+ ),
+ const SizedBox(height: 12),
+ const Text(
+ "Use your device camera to take a photo, then add it to the selected album. We will improve this with an in-app camera flow soon.",
+ ),
+ const SizedBox(height: 24),
+ ElevatedButton.icon(
+ onPressed: () {
+ if (collection != null) {
+ routeToPage(
+ context,
+ CollectionPage(
+ CollectionWithThumbnail(collection, null),
+ ),
+ );
+ } else {
+ Navigator.of(context).pop();
+ }
+ },
+ icon: const Icon(Icons.photo_camera_rounded),
+ label: Text(
+ collection == null
+ ? "Open album"
+ : "Go to ${collection.displayName}",
+ ),
+ ),
+ const SizedBox(height: 12),
+ OutlinedButton(
+ onPressed: () {
+ routeToPage(context, const ActivityScreen());
+ },
+ child: const Text("View activity"),
+ ),
+ ],
+ );
+ },
+ ),
+ ),
+ );
+ }
+
+ Future<Collection?> _loadCollection() async {
+ if (albumId == null) return null;
+ return CollectionsService.instance.getCollectionByID(albumId!);
+ }
+}
diff --git a/mobile/apps/photos/lib/ui/tabs/home_widget.dart b/mobile/apps/photos/lib/ui/tabs/home_widget.dart
index 03545827a6..61922c4235 100644
--- a/mobile/apps/photos/lib/ui/tabs/home_widget.dart
+++ b/mobile/apps/photos/lib/ui/tabs/home_widget.dart
@@ -51,6 +51,7 @@ import 'package:photos/states/user_details_state.dart';
import 'package:photos/theme/colors.dart';
import "package:photos/theme/effects.dart";
import 'package:photos/theme/ente_theme.dart';
+import "package:photos/ui/activity/ritual_camera_page.dart";
import 'package:photos/ui/collections/collection_action_sheet.dart';
import "package:photos/ui/common/web_page.dart";
import "package:photos/ui/components/buttons/button_widget.dart";
@@ -944,6 +945,23 @@ class _HomeWidgetState extends State<HomeWidget> {
final String? payload = notificationResponse.payload;
if (payload != null) {
debugPrint('notification payload: $payload');
+ final uri = Uri.tryParse(payload);
+ if (uri != null && uri.host.toLowerCase() == "ritual") {
+ final ritualId = uri.queryParameters["ritualId"] ?? "";
+ final albumIdRaw = uri.queryParameters["albumId"];
+ final int? albumId = albumIdRaw != null && albumIdRaw.isNotEmpty
+ ? int.tryParse(albumIdRaw)
+ : null;
+ // ignore: unawaited_futures
+ routeToPage(
+ context,
+ RitualCameraPage(
+ ritualId: ritualId,
+ albumId: albumId,
+ ),
+ );
+ return;
+ }
if (payload.toLowerCase().contains("onthisday")) {
_logger.info("On this day notification received");
// ignore: unawaited_futures
diff --git a/mobile/apps/photos/lib/ui/viewer/search_tab/search_tab.dart b/mobile/apps/photos/lib/ui/viewer/search_tab/search_tab.dart
index ef07076abc..c739f60a81 100644
--- a/mobile/apps/photos/lib/ui/viewer/search_tab/search_tab.dart
+++ b/mobile/apps/photos/lib/ui/viewer/search_tab/search_tab.dart
@@ -12,6 +12,7 @@ import "package:photos/models/search/search_types.dart";
import "package:photos/service_locator.dart";
import "package:photos/services/wrapped/wrapped_service.dart";
import "package:photos/states/all_sections_examples_state.dart";
+import "package:photos/ui/activity/activity_banner.dart";
import "package:photos/ui/common/loading_widget.dart";
import "package:photos/ui/viewer/search/result/no_result_widget.dart";
import "package:photos/ui/viewer/search/search_suggestions.dart";
@@ -114,27 +115,29 @@ class _AllSearchSectionsState extends State<AllSearchSections> {
return ListView.builder(
padding: const EdgeInsets.only(bottom: 180),
physics: const BouncingScrollPhysics(),
- itemCount: searchTypes.length,
- // ignore: body_might_complete_normally_nullable
+ itemCount: searchTypes.length + 1,
itemBuilder: (context, index) {
- switch (searchTypes[index]) {
+ if (index == 0) {
+ return const ActivityBanner();
+ }
+ final sectionIndex = index - 1;
+ switch (searchTypes[sectionIndex]) {
case SectionType.face:
if (!flagService.hasGrantedMLConsent) {
return const SizedBox.shrink();
}
return PeopleSection(
- examples: snapshot.data!.elementAt(index)
+ examples: snapshot.data!.elementAt(sectionIndex)
as List<GenericSearchResult>,
);
case SectionType.album:
return AlbumsSection(
- snapshot.data!.elementAt(index)
+ snapshot.data!.elementAt(sectionIndex)
as List<AlbumSearchResult>,
);
case SectionType.wrapped:
return ValueListenableBuilder<WrappedEntryState>(
- valueListenable:
- wrappedService.stateListenable,
+ valueListenable: wrappedService.stateListenable,
builder: (
BuildContext context,
WrappedEntryState state,
@@ -148,19 +151,19 @@ class _AllSearchSectionsState extends State<AllSearchSections> {
);
case SectionType.location:
return LocationsSection(
- snapshot.data!.elementAt(index)
+ snapshot.data!.elementAt(sectionIndex)
as List<GenericSearchResult>,
);
case SectionType.contacts:
return const SizedBox.shrink();
case SectionType.fileTypesAndExtension:
return FileTypeSection(
- snapshot.data!.elementAt(index)
+ snapshot.data!.elementAt(sectionIndex)
as List<GenericSearchResult>,
);
case SectionType.magic:
return MagicSection(
- snapshot.data!.elementAt(index)
+ snapshot.data!.elementAt(sectionIndex)
as List<GenericSearchResult>,
);
}