π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mob][photos] Add rounded map marker preview
ashil-pilote997cc07cd60
diff --git a/mobile/apps/photos/lib/ui/map/map_gallery_tile_badge.dart b/mobile/apps/photos/lib/ui/map/map_gallery_tile_badge.dartindex b13572d4eb..d562333048 100644--- a/mobile/apps/photos/lib/ui/map/map_gallery_tile_badge.dart+++ b/mobile/apps/photos/lib/ui/map/map_gallery_tile_badge.dart@@ -5,7 +5,7 @@ class MapGalleryTileBadge extends StatelessWidget {final int size;const MapGalleryTileBadge({super.key, required this.size});- String formatNumber(int number) {+ static String formatNumber(int number) {if (number <= 99) {return number.toString();} else if (number <= 999) {diff --git a/mobile/apps/photos/lib/ui/map/map_marker.dart b/mobile/apps/photos/lib/ui/map/map_marker.dartindex 58449c0ea4..dc6f992a9f 100644--- a/mobile/apps/photos/lib/ui/map/map_marker.dart+++ b/mobile/apps/photos/lib/ui/map/map_marker.dart@@ -5,31 +5,39 @@ import "package:photos/ui/map/image_marker.dart";import "package:photos/ui/map/map_gallery_tile_badge.dart";import "package:photos/ui/map/map_view.dart";import "package:photos/ui/map/marker_image.dart";+import "package:photos/ui/map/photo_map_marker.dart";Marker mapMarker(ImageMarker imageMarker,ValueKey<int> key, {Size markerSize = MapView.defaultMarkerSize,+ bool useRoundedMarker = false,VoidCallback? onTap,}) {- final markerChild = Stack(- children: [- MarkerImage(- file: imageMarker.imageFile,- seperator:- (MapView.defaultMarkerSize.height + 10) -- (MapView.defaultMarkerSize.height - markerSize.height),- ),- if (imageMarker.imageCount > 1)- MapGalleryTileBadge(size: imageMarker.imageCount),- ],- );+ final markerChild = useRoundedMarker+ ? PhotoMapMarker(+ file: imageMarker.imageFile,+ count: imageMarker.imageCount,+ )+ : Stack(+ children: [+ MarkerImage(+ file: imageMarker.imageFile,+ seperator:+ (MapView.defaultMarkerSize.height + 10) -+ (MapView.defaultMarkerSize.height - markerSize.height),+ ),+ if (imageMarker.imageCount > 1)+ MapGalleryTileBadge(size: imageMarker.imageCount),+ ],+ );+ final size = useRoundedMarker ? PhotoMapMarker.markerSize : markerSize;return Marker(alignment: Alignment.topCenter,key: key,- width: markerSize.width,- height: markerSize.height,+ width: size.width,+ height: size.height,point: LatLng(imageMarker.latitude, imageMarker.longitude),child: onTap == null? markerChilddiff --git a/mobile/apps/photos/lib/ui/map/map_view.dart b/mobile/apps/photos/lib/ui/map/map_view.dartindex 618a9856f2..0b9d949283 100644--- a/mobile/apps/photos/lib/ui/map/map_view.dart+++ b/mobile/apps/photos/lib/ui/map/map_view.dart@@ -71,6 +71,7 @@ class MapView extends StatefulWidget {}class _MapViewState extends State<MapView> {+ static const _previewEnabled = bool.fromEnvironment("MAP_MARKER_PREVIEW");late List<Marker> _markers;@override@@ -82,7 +83,10 @@ class _MapViewState extends State<MapView> {@overridevoid didUpdateWidget(MapView oldWidget) {super.didUpdateWidget(oldWidget);- if (!identical(oldWidget.imageMarkers, widget.imageMarkers)) {+ if (!identical(oldWidget.imageMarkers, widget.imageMarkers) ||+ oldWidget.markerSize != widget.markerSize ||+ oldWidget.showControls != widget.showControls ||+ oldWidget.maxZoom != widget.maxZoom) {_markers = _buildMarkers();}}@@ -208,6 +212,7 @@ class _MapViewState extends State<MapView> {imageMarker,ValueKey(index),markerSize: widget.markerSize,+ useRoundedMarker: _previewEnabled && widget.showControls,onTap: clusterBounds == null? null: () {diff --git a/mobile/apps/photos/lib/ui/map/photo_map_marker.dart b/mobile/apps/photos/lib/ui/map/photo_map_marker.dartnew file mode 100644index 0000000000..c1f309351e--- /dev/null+++ b/mobile/apps/photos/lib/ui/map/photo_map_marker.dart@@ -0,0 +1,165 @@+import "dart:math" as math;++import "package:flutter/material.dart";+import "package:photos/models/file/file.dart";+import "package:photos/theme/ente_theme.dart";+import "package:photos/ui/map/map_gallery_tile_badge.dart";+import "package:photos/ui/viewer/file/thumbnail_widget.dart";++class PhotoMapMarker extends StatelessWidget {+ static const _sideInset = 12.0;+ static const _topInset = 9.0;+ static const _pointerHeight = 5.0;+ static const _frameWidth = 2.0;++ final EnteFile file;+ final int count;++ const PhotoMapMarker({super.key, required this.file, required this.count});++ static const _bodySize = Size(64, 64);++ static Size get markerSize {+ const body = _bodySize;+ return Size(+ body.width + _sideInset * 2,+ body.height + _topInset + _pointerHeight,+ );+ }++ @override+ Widget build(BuildContext context) {+ const body = _bodySize;+ const radius = 13.0;+ final colors = getEnteColorScheme(context);+ final frameColor = colors.backgroundElevated2;++ return Stack(+ children: [+ Positioned.fill(+ child: CustomPaint(+ painter: _PhotoPinFramePainter(+ body: Rect.fromLTWH(+ _sideInset,+ _topInset,+ body.width,+ body.height,+ ),+ radius: radius,+ color: frameColor,+ ),+ ),+ ),+ Positioned(+ left: _sideInset + _frameWidth,+ top: _topInset + _frameWidth,+ width: body.width - _frameWidth * 2,+ height: body.height - _frameWidth * 2,+ child: ClipRRect(+ borderRadius: BorderRadius.circular(radius - _frameWidth),+ child: ThumbnailWidget(file, rawThumbnail: true),+ ),+ ),+ if (count > 1)+ Positioned(+ top: 0,+ right: 0,+ child: Container(+ constraints: const BoxConstraints(minWidth: 24, minHeight: 22),+ padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),+ decoration: BoxDecoration(+ color: Colors.white,+ borderRadius: BorderRadius.circular(20),+ border: Border.all(color: const Color(0xFFDADADA)),+ boxShadow: const [+ BoxShadow(+ color: Color(0x1A000000),+ blurRadius: 3,+ offset: Offset(0, 1),+ ),+ ],+ ),+ child: Text(+ MapGalleryTileBadge.formatNumber(count),+ textAlign: TextAlign.center,+ textScaler: TextScaler.noScaling,+ style: const TextStyle(+ fontSize: 12,+ height: 1.2,+ fontWeight: FontWeight.w600,+ color: Color(0xFF242424),+ ),+ ),+ ),+ ),+ ],+ );+ }+}++class _PhotoPinFramePainter extends CustomPainter {+ final Rect body;+ final double radius;+ final Color color;++ const _PhotoPinFramePainter({+ required this.body,+ required this.radius,+ required this.color,+ });++ @override+ void paint(Canvas canvas, Size size) {+ final center = body.center.dx;+ const halfWidth = 6.0;+ const pointerRadius = 1.0;+ const curveRadius = Radius.circular(pointerRadius);+ final tangentHeight = size.height - body.bottom - pointerRadius * 2;+ // A shared tangent keeps the circular rounds within the same size and anchor.+ final angle =+ math.atan2(tangentHeight, halfWidth) ++ math.asin(+ pointerRadius *+ 2 /+ math.sqrt(halfWidth * halfWidth + tangentHeight * tangentHeight),+ );+ final tangentX = pointerRadius * math.sin(angle);+ final tangentY = pointerRadius * math.cos(angle);+ final pointer = Path()+ ..moveTo(center - halfWidth, body.bottom - 1)+ ..lineTo(center - halfWidth, body.bottom)+ ..arcToPoint(+ Offset(+ center - halfWidth + tangentX,+ body.bottom + pointerRadius - tangentY,+ ),+ radius: curveRadius,+ )+ ..lineTo(center - tangentX, size.height - pointerRadius + tangentY)+ ..arcToPoint(+ Offset(center + tangentX, size.height - pointerRadius + tangentY),+ radius: curveRadius,+ clockwise: false,+ )+ ..lineTo(+ center + halfWidth - tangentX,+ body.bottom + pointerRadius - tangentY,+ )+ ..arcToPoint(Offset(center + halfWidth, body.bottom), radius: curveRadius)+ ..lineTo(center + halfWidth, body.bottom - 1)+ ..close();+ final frame = Path.combine(+ PathOperation.union,+ Path()..addRRect(RRect.fromRectAndRadius(body, Radius.circular(radius))),+ pointer,+ );+ canvas.drawShadow(frame, const Color(0x45000000), 3, false);+ canvas.drawPath(frame, Paint()..color = color);+ }++ @override+ bool shouldRepaint(_PhotoPinFramePainter oldDelegate) =>+ body != oldDelegate.body ||+ radius != oldDelegate.radius ||+ color != oldDelegate.color;+}