Skip to content

armgit / ente

Public Imported from GitHub
0

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

Prettify activity overview

laurensprieme0076c8e79b0
diff --git a/mobile/apps/photos/lib/services/activity/activity_service.dart b/mobile/apps/photos/lib/services/activity/activity_service.dart
index 335ba5892c..e24f6533c2 100644
--- a/mobile/apps/photos/lib/services/activity/activity_service.dart
+++ b/mobile/apps/photos/lib/services/activity/activity_service.dart
@@ -83,7 +83,7 @@ class ActivityService {
if (userId == null) {
return ActivitySummary(
last365Days: _emptyDays(),
- last7Days: _emptyDays().sublist(358),
+ last7Days: _emptyDays().sublist(_emptyDays().length - 7),
currentStreak: 0,
longestStreak: 0,
badgesUnlocked: _badgeStates(0),
@@ -93,7 +93,7 @@ class ActivityService {
}
final today = DateTime.now();
final todayMidnight = DateTime(today.year, today.month, today.day);
- final cutoffDate = todayMidnight.subtract(const Duration(days: 364));
+ final cutoffDate = todayMidnight.subtract(const Duration(days: 371));
final endOfToday = todayMidnight.add(
const Duration(
hours: 23,
@@ -140,7 +140,7 @@ class ActivityService {
}
}
- final List<ActivityDay> last365Days = List.generate(365, (index) {
+ final List<ActivityDay> last365Days = List.generate(372, (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));
@@ -193,9 +193,9 @@ class ActivityService {
List<ActivityDay> _emptyDays() {
final today = DateTime.now();
final todayMidnight = DateTime(today.year, today.month, today.day);
- final cutoffDate = todayMidnight.subtract(const Duration(days: 364));
+ final cutoffDate = todayMidnight.subtract(const Duration(days: 371));
return List.generate(
- 365,
+ 372,
(index) => ActivityDay(
date: cutoffDate.add(Duration(days: index)),
hasActivity: false,
diff --git a/mobile/apps/photos/lib/ui/activity/activity_screen.dart b/mobile/apps/photos/lib/ui/activity/activity_screen.dart
index 682d8b0a81..847a4bf986 100644
--- a/mobile/apps/photos/lib/ui/activity/activity_screen.dart
+++ b/mobile/apps/photos/lib/ui/activity/activity_screen.dart
@@ -57,9 +57,9 @@ class _ActivityHeatmapCard extends StatelessWidget {
Widget build(BuildContext context) {
final last365 = summary?.last365Days ??
List.generate(
- 365,
+ 372,
(i) => ActivityDay(
- date: DateTime.now().subtract(Duration(days: 364 - i)),
+ date: DateTime.now().subtract(Duration(days: 371 - i)),
hasActivity: false,
),
);
@@ -87,10 +87,18 @@ class _Heatmap extends StatelessWidget {
@override
Widget build(BuildContext context) {
+ final renderDays =
+ days.length > 365 ? days.sublist(days.length - 365) : days;
final dayHeader = ["S", "M", "T", "W", "Th", "F", "Sa"];
final today = DateTime.now();
final todayMidnight = DateTime(today.year, today.month, today.day);
- final firstDay = todayMidnight.subtract(const Duration(days: 364));
+ final DateTime firstDay = renderDays.isNotEmpty
+ ? DateTime(
+ renderDays.first.date.year,
+ renderDays.first.date.month,
+ renderDays.first.date.day,
+ )
+ : todayMidnight.subtract(const Duration(days: 364));
final normalizedDayMap = <int, ActivityDay>{
for (final d in days)
@@ -98,20 +106,30 @@ class _Heatmap extends StatelessWidget {
.millisecondsSinceEpoch: d,
};
- final int startOffset = firstDay.weekday % 7; // days since previous Sunday
+ // Always start on the Sunday before/including the first day to render
+ final int startOffset = firstDay.weekday % 7;
final DateTime gridStart =
firstDay.subtract(Duration(days: startOffset)); // Sunday-aligned
+ // End exactly on today; last row can be partial
+ final DateTime gridEnd = todayMidnight;
final int totalDays =
- todayMidnight.difference(gridStart).inDays + 1; // inclusive of today
+ gridEnd.difference(gridStart).inDays + 1; // inclusive of gridEnd
final List<ActivityDay?> gridDays = List.generate(totalDays, (index) {
final date = gridStart.add(Duration(days: index));
- if (date.isBefore(firstDay)) {
- return null; // top padding
- }
+ // Leading days before the 365-day window can still be active if present
+ // in the extended map (we fetched extra days), otherwise remain empty.
final key = DateTime(date.year, date.month, date.day)
.millisecondsSinceEpoch;
- return normalizedDayMap[key] ??
+ final activity = normalizedDayMap[key];
+ if (date.isBefore(firstDay)) {
+ return activity ??
+ ActivityDay(
+ date: date,
+ hasActivity: false,
+ );
+ }
+ return activity ??
ActivityDay(
date: date,
hasActivity: false,
@@ -195,27 +213,27 @@ class _Heatmap extends StatelessWidget {
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
- const SizedBox(height: 20),
- ...weeks.asMap().entries.map(
- (entry) {
- final isLast = entry.key == weeks.length - 1;
- return SizedBox(
- height: cellHeight + (isLast ? 0 : gapY),
- width: monthLabelWidth,
- child: Align(
- alignment: Alignment.centerLeft,
+ const SizedBox(height: 8),
+ ...weeks.asMap().entries.map((entry) {
+ final isLast = entry.key == weeks.length - 1;
+ return SizedBox(
+ height: cellHeight + (isLast ? 0 : gapY),
+ width: monthLabelWidth,
+ child: Center(
+ child: Transform.translate(
+ offset: const Offset(0, -1),
child: Text(
monthLabels[entry.key] ?? "",
style: headerStyle.copyWith(
fontSize: 8.542,
- height: 1.8,
+ height: 1.4,
),
textAlign: TextAlign.center,
),
),
- );
- },
- ),
+ ),
+ );
+ }),
],
),
const SizedBox(width: gapX),
@@ -238,8 +256,8 @@ class _Heatmap extends StatelessWidget {
? Colors.transparent
: cell.value!.hasActivity
? const Color(0xFF1DB954)
- : const Color(0xFF1DB954).withOpacity(
- 0.25,
+ : const Color(0xFF1DB954).withValues(
+ alpha: 0.25,
);
return Row(
children: [