Skip to content

armgit / ente

Public Imported from GitHub
0

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

share with ente assets

laurenspriem733d63836213
diff --git a/mobile/apps/photos/lib/ui/activity/activity_heatmap_card.dart b/mobile/apps/photos/lib/ui/activity/activity_heatmap_card.dart
index 3657b2aee4..b619564080 100644
--- a/mobile/apps/photos/lib/ui/activity/activity_heatmap_card.dart
+++ b/mobile/apps/photos/lib/ui/activity/activity_heatmap_card.dart
@@ -6,9 +6,16 @@ import "package:photos/theme/colors.dart";
import "package:photos/theme/ente_theme.dart";
class ActivityHeatmapCard extends StatelessWidget {
- const ActivityHeatmapCard({required this.summary, super.key});
+ const ActivityHeatmapCard({
+ required this.summary,
+ this.compact = false,
+ this.allowHorizontalScroll = false,
+ super.key,
+ });
final ActivitySummary? summary;
+ final bool compact;
+ final bool allowHorizontalScroll;
@override
Widget build(BuildContext context) {
@@ -36,16 +43,33 @@ class ActivityHeatmapCard extends StatelessWidget {
),
),
padding: const EdgeInsets.fromLTRB(12, 12, 12, 12),
- child: _Heatmap(days: last365),
+ child: allowHorizontalScroll
+ ? SingleChildScrollView(
+ scrollDirection: Axis.horizontal,
+ physics: const ClampingScrollPhysics(),
+ clipBehavior: Clip.none,
+ child: _Heatmap(
+ days: last365,
+ compact: compact,
+ ),
+ )
+ : _Heatmap(
+ days: last365,
+ compact: compact,
+ ),
),
);
}
}
class _Heatmap extends StatelessWidget {
- const _Heatmap({required this.days});
+ const _Heatmap({
+ required this.days,
+ required this.compact,
+ });
final List<ActivityDay> days;
+ final bool compact;
@override
Widget build(BuildContext context) {
@@ -128,13 +152,13 @@ class _Heatmap extends StatelessWidget {
return LayoutBuilder(
builder: (context, constraints) {
// Keep a minimum gutter width in case the container gets very narrow.
- const double monthLabelWidth = 32;
- const double gapX = 4;
- const double gapY = 3;
- const double cellWidth = 38.31;
- const double cellHeight = 9.82;
- const double headerRowHeight = 16;
- const double headerToGridGap = 4;
+ final double monthLabelWidth = compact ? 28 : 32;
+ final double gapX = compact ? 2.5 : 4;
+ final double gapY = compact ? 2 : 3;
+ final double cellWidth = compact ? 30 : 38.31;
+ final double cellHeight = compact ? 8.5 : 9.82;
+ final double headerRowHeight = compact ? 13 : 16;
+ final double headerToGridGap = compact ? 3 : 4;
final double gridWidth =
(dayHeader.length * cellWidth) + ((dayHeader.length - 1) * gapX);
final double remainingWidth =
@@ -145,9 +169,9 @@ class _Heatmap extends StatelessWidget {
final BorderRadius pillRadius = BorderRadius.circular(cellHeight);
final TextStyle headerStyle = TextStyle(
color: colorScheme.textMuted.withValues(alpha: 0.45),
- fontSize: 6.834,
+ fontSize: compact ? 6.2 : 6.834,
fontWeight: FontWeight.w600,
- height: 2.45,
+ height: compact ? 2.2 : 2.45,
fontFamily: "Inter",
decoration: TextDecoration.none,
);
@@ -168,7 +192,7 @@ class _Heatmap extends StatelessWidget {
),
);
if (i != dayHeader.length - 1) {
- dayHeaderRow.add(const SizedBox(width: gapX));
+ dayHeaderRow.add(SizedBox(width: gapX));
}
}
@@ -180,7 +204,7 @@ class _Heatmap extends StatelessWidget {
SizedBox(
width: gutterWidth,
child: Padding(
- padding: const EdgeInsets.only(
+ padding: EdgeInsets.only(
top: headerRowHeight + headerToGridGap + 8,
),
child: Column(
@@ -207,7 +231,7 @@ class _Heatmap extends StatelessWidget {
),
),
),
- const SizedBox(width: gapX),
+ SizedBox(width: gapX),
SizedBox(
width: gridWidth,
child: Column(
@@ -215,7 +239,7 @@ class _Heatmap extends StatelessWidget {
children: [
const SizedBox(height: 8),
Row(children: dayHeaderRow),
- const SizedBox(height: headerToGridGap),
+ SizedBox(height: headerToGridGap),
...weeks.asMap().entries.map(
(entry) {
final isLast = entry.key == weeks.length - 1;
@@ -244,7 +268,7 @@ class _Heatmap extends StatelessWidget {
borderRadius: pillRadius,
),
),
- if (!isLastCell) const SizedBox(width: gapX),
+ if (!isLastCell) SizedBox(width: gapX),
],
);
}).toList(),
@@ -255,7 +279,7 @@ class _Heatmap extends StatelessWidget {
],
),
),
- const Spacer(),
+ const SizedBox.shrink(),
],
),
);
diff --git a/mobile/apps/photos/lib/ui/activity/activity_screen.dart b/mobile/apps/photos/lib/ui/activity/activity_screen.dart
index 8564ad9683..fcc3c58ee2 100644
--- a/mobile/apps/photos/lib/ui/activity/activity_screen.dart
+++ b/mobile/apps/photos/lib/ui/activity/activity_screen.dart
@@ -1,9 +1,19 @@
+import "dart:io";
+import "dart:math" as math;
+import "dart:typed_data";
+import "dart:ui" as ui;
+
import "package:flutter/material.dart";
+import "package:flutter/rendering.dart";
+import "package:path_provider/path_provider.dart";
import "package:photos/models/activity/activity_models.dart";
import "package:photos/service_locator.dart";
+import "package:photos/theme/ente_theme.dart";
import "package:photos/ui/activity/achievements_row.dart";
import "package:photos/ui/activity/activity_heatmap_card.dart";
import "package:photos/ui/activity/rituals_section.dart";
+import "package:photos/utils/share_util.dart";
+import "package:share_plus/share_plus.dart";
class ActivityScreen extends StatefulWidget {
const ActivityScreen({super.key, this.ritual});
@@ -16,6 +26,7 @@ class ActivityScreen extends StatefulWidget {
class _ActivityScreenState extends State<ActivityScreen> {
Ritual? _selectedRitual;
+ final GlobalKey _shareButtonKey = GlobalKey();
@override
void initState() {
@@ -57,12 +68,14 @@ class _ActivityScreenState extends State<ActivityScreen> {
final displaySummary = summary != null && selectedRitual != null
? _summaryForRitual(summary, selectedRitual)
: summary;
+ final summaryToShare = displaySummary;
final iconColor = Theme.of(context).iconTheme.color;
final String sectionTitle = selectedRitual == null
? "Take a photo every day"
: (selectedRitual.title.isEmpty
? "Untitled ritual"
: selectedRitual.title);
+ final bool shareEnabled = summaryToShare != null;
return RefreshIndicator(
onRefresh: activityService.refresh,
child: ListView(
@@ -92,8 +105,14 @@ class _ActivityScreenState extends State<ActivityScreen> {
),
const Spacer(),
InkWell(
+ key: _shareButtonKey,
customBorder: const CircleBorder(),
- onTap: () {},
+ onTap: summaryToShare != null
+ ? () => _shareActivity(
+ summaryToShare,
+ sectionTitle,
+ )
+ : null,
child: SizedBox(
width: 44,
height: 44,
@@ -102,7 +121,11 @@ class _ActivityScreenState extends State<ActivityScreen> {
child: Icon(
Icons.share_outlined,
size: 22,
- color: iconColor,
+ color: shareEnabled
+ ? iconColor
+ : Theme.of(context)
+ .disabledColor
+ .withValues(alpha: 0.7),
),
),
),
@@ -122,6 +145,96 @@ class _ActivityScreenState extends State<ActivityScreen> {
);
}
+ Future<void> _shareActivity(
+ ActivitySummary summary,
+ String title,
+ ) async {
+ OverlayEntry? entry;
+ final prevPaintSize = debugPaintSizeEnabled;
+ final prevPaintBaselines = debugPaintBaselinesEnabled;
+ final prevPaintPointers = debugPaintPointersEnabled;
+ final prevRepaintRainbow = debugRepaintRainbowEnabled;
+ try {
+ debugPaintSizeEnabled = false;
+ debugPaintBaselinesEnabled = false;
+ debugPaintPointersEnabled = false;
+ debugRepaintRainbowEnabled = false;
+
+ final overlay = Overlay.maybeOf(context, rootOverlay: true);
+ if (overlay == null) {
+ throw StateError("Overlay not available for sharing");
+ }
+ final key = GlobalKey();
+ entry = OverlayEntry(
+ builder: (context) {
+ return Center(
+ child: Material(
+ type: MaterialType.transparency,
+ child: RepaintBoundary(
+ key: key,
+ child: _ActivityShareCard(
+ summary: summary,
+ title: title,
+ ),
+ ),
+ ),
+ );
+ },
+ );
+ overlay.insert(entry);
+ await WidgetsBinding.instance.endOfFrame;
+ await Future.delayed(const Duration(milliseconds: 40));
+ final boundary =
+ key.currentContext?.findRenderObject() as RenderRepaintBoundary?;
+ if (boundary == null) {
+ throw StateError("Render boundary unavailable");
+ }
+ if (boundary.size.isEmpty) {
+ throw StateError("Render boundary has zero size");
+ }
+ if (boundary.debugNeedsPaint) {
+ await WidgetsBinding.instance.endOfFrame;
+ await Future.delayed(const Duration(milliseconds: 24));
+ }
+ if (boundary.debugNeedsPaint) {
+ throw StateError("Render boundary not ready to paint");
+ }
+ final double pixelRatio =
+ (MediaQuery.of(context).devicePixelRatio * 1.6).clamp(2.0, 3.5);
+ final ui.Image image =
+ await boundary.toImage(pixelRatio: pixelRatio.toDouble());
+ final ByteData? byteData =
+ await image.toByteData(format: ui.ImageByteFormat.png);
+ final data = byteData?.buffer.asUint8List();
+ if (data == null) return;
+ final dir = await getTemporaryDirectory();
+ final file = File(
+ "${dir.path}/activity_share_${DateTime.now().millisecondsSinceEpoch}.png",
+ );
+ await file.writeAsBytes(data, flush: true);
+ await SharePlus.instance.share(
+ ShareParams(
+ files: [XFile(file.path)],
+ sharePositionOrigin: shareButtonRect(context, _shareButtonKey),
+ ),
+ );
+ } catch (e, s) {
+ debugPrint("Failed to share activity: $e\n$s");
+ if (!mounted) return;
+ ScaffoldMessenger.of(context).showSnackBar(
+ const SnackBar(
+ content: Text("Unable to share right now. Please try again."),
+ ),
+ );
+ } finally {
+ debugPaintSizeEnabled = prevPaintSize;
+ debugPaintBaselinesEnabled = prevPaintBaselines;
+ debugPaintPointersEnabled = prevPaintPointers;
+ debugRepaintRainbowEnabled = prevRepaintRainbow;
+ entry?.remove();
+ }
+ }
+
ActivitySummary _summaryForRitual(
ActivitySummary summary,
Ritual ritual,
@@ -192,3 +305,89 @@ class _ActivityScreenState extends State<ActivityScreen> {
);
}
}
+
+class _ActivityShareCard extends StatelessWidget {
+ const _ActivityShareCard({
+ required this.summary,
+ required this.title,
+ });
+
+ final ActivitySummary summary;
+ final String title;
+
+ @override
+ Widget build(BuildContext context) {
+ final colorScheme = getEnteColorScheme(context);
+ final textTheme = getEnteTextTheme(context);
+ final double maxWidth = math
+ .min(
+ math.max(MediaQuery.of(context).size.width - 32, 360),
+ 440,
+ )
+ .toDouble();
+ return Container(
+ color: colorScheme.backgroundBase,
+ padding: const EdgeInsets.all(12),
+ child: Center(
+ child: SizedBox(
+ width: maxWidth,
+ child: ClipRRect(
+ borderRadius: BorderRadius.circular(24),
+ child: Container(
+ color: Theme.of(context).brightness == Brightness.dark
+ ? colorScheme.backgroundElevated2
+ : Colors.white,
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ children: [
+ Padding(
+ padding: const EdgeInsets.fromLTRB(16, 16, 16, 4),
+ child: Text(
+ title,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ textAlign: TextAlign.center,
+ style: textTheme.bodyBold.copyWith(
+ fontSize: 20,
+ height: 1.2,
+ decoration: TextDecoration.none,
+ decorationColor: Colors.transparent,
+ decorationThickness: 0,
+ ),
+ ),
+ ),
+ const SizedBox(height: 4),
+ Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 6),
+ child: ActivityHeatmapCard(
+ summary: summary,
+ compact: true,
+ allowHorizontalScroll: false,
+ ),
+ ),
+ const SizedBox(height: 6),
+ Container(
+ color: Colors.black,
+ padding: const EdgeInsets.symmetric(
+ horizontal: 18,
+ vertical: 12,
+ ),
+ child: Center(
+ child: Image.asset(
+ "assets/ente_io_green.png",
+ width: 116,
+ height: 27,
+ fit: BoxFit.contain,
+ ),
+ ),
+ ),
+ ],
+ ),
+ ),
+ ),
+ ),
+ ),
+ );
+ }
+}