Skip to content

armgit / ente

Public Imported from GitHub
0

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

Match search file type cards to design

ashilkn3770f6a7f8c6
diff --git a/mobile/apps/photos/lib/ui/viewer/search_tab/file_type_section.dart b/mobile/apps/photos/lib/ui/viewer/search_tab/file_type_section.dart
index b9a485a881..3cd15f2ddd 100644
--- a/mobile/apps/photos/lib/ui/viewer/search_tab/file_type_section.dart
+++ b/mobile/apps/photos/lib/ui/viewer/search_tab/file_type_section.dart
@@ -1,4 +1,5 @@
import "dart:async";
+import "dart:math" as math;
import "package:ente_components/theme/text_styles.dart";
import "package:ente_pure_utils/ente_pure_utils.dart";
@@ -14,6 +15,7 @@ import "package:photos/theme/ente_theme.dart";
import "package:photos/ui/viewer/search/result/search_result_page.dart";
import "package:photos/ui/viewer/search/search_section_cta.dart";
import "package:photos/ui/viewer/search_tab/section_header.dart";
+import "package:photos/utils/pending_translation.dart";
class FileTypeSection extends StatelessWidget {
final bool hasAnySearchableFiles;
@@ -99,13 +101,13 @@ class FileTypeSection extends StatelessWidget {
label: videos,
name: videos,
type: FileType.video,
- icon: HugeIcons.strokeRoundedVideo02,
+ icon: HugeIcons.strokeRoundedPlayCircle,
),
_FileTypeTile.fileType(
- label: livePhotos,
+ label: pendingTranslation("Live"),
name: livePhotos,
type: FileType.livePhoto,
- icon: HugeIcons.strokeRoundedLiveStreaming01,
+ icon: HugeIcons.strokeRoundedPlayCircle,
),
const _FileTypeTile.extension(
label: "PNG",
@@ -141,6 +143,7 @@ class _FileTypeTile {
final FileType? fileType;
final String? extension;
final List<List<dynamic>> icon;
+ bool get isFileType => fileType != null;
const _FileTypeTile.fileType({
required this.label,
@@ -187,34 +190,11 @@ class _FileTypeRecommendationState extends State<_FileTypeRecommendation> {
@override
Widget build(BuildContext context) {
- final colorScheme = getEnteColorScheme(context);
return GestureDetector(
onTap: _onTap,
- child: Container(
- width: 78.75,
- height: 56,
- decoration: BoxDecoration(
- color: colorScheme.fill,
- borderRadius: BorderRadius.circular(25),
- ),
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- HugeIcon(
- icon: widget.tile.icon,
- size: 22,
- color: colorScheme.textBase,
- ),
- const SizedBox(height: 2),
- Text(
- widget.tile.label,
- style: TextStyles.tiny.copyWith(color: colorScheme.textBase),
- maxLines: 1,
- overflow: TextOverflow.ellipsis,
- ),
- ],
- ),
- ),
+ child: widget.tile.isFileType
+ ? _FileTypeCard(widget.tile)
+ : _FileExtensionPill(widget.tile),
);
}
@@ -231,3 +211,179 @@ class _FileTypeRecommendationState extends State<_FileTypeRecommendation> {
}
}
}
+
+class _FileTypeCard extends StatelessWidget {
+ static const width = 108.0;
+ static const height = 56.0;
+
+ final _FileTypeTile tile;
+
+ const _FileTypeCard(this.tile);
+
+ @override
+ Widget build(BuildContext context) {
+ final colorScheme = getEnteColorScheme(context);
+ return CustomPaint(
+ painter: _FileTypeCardBackgroundPainter(colorScheme.fill),
+ child: SizedBox(
+ width: width,
+ height: height,
+ child: Stack(
+ children: [
+ Positioned(
+ left: 13,
+ right: 38,
+ top: 31,
+ height: 17,
+ child: Text(
+ tile.label,
+ style: TextStyles.mini.copyWith(
+ color: colorScheme.textBase,
+ fontSize: 12.461538,
+ fontWeight: FontWeight.w700,
+ height: 16.615385 / 12.461538,
+ ),
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ ),
+ ),
+ Positioned(
+ left: 74,
+ top: 7,
+ width: 34,
+ height: 34,
+ child: Center(
+ child: HugeIcon(
+ icon: tile.icon,
+ size: 18,
+ color: colorScheme.textBase,
+ ),
+ ),
+ ),
+ ],
+ ),
+ ),
+ );
+ }
+}
+
+class _FileExtensionPill extends StatelessWidget {
+ final _FileTypeTile tile;
+
+ const _FileExtensionPill(this.tile);
+
+ @override
+ Widget build(BuildContext context) {
+ final colorScheme = getEnteColorScheme(context);
+ return Container(
+ width: 78.75,
+ height: 56,
+ decoration: BoxDecoration(
+ color: colorScheme.fill,
+ borderRadius: BorderRadius.circular(25),
+ ),
+ child: Column(
+ mainAxisAlignment: MainAxisAlignment.center,
+ children: [
+ HugeIcon(icon: tile.icon, size: 22, color: colorScheme.textBase),
+ const SizedBox(height: 2),
+ Text(
+ tile.label,
+ style: TextStyles.tiny.copyWith(color: colorScheme.textBase),
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ ),
+ ],
+ ),
+ );
+ }
+}
+
+class _FileTypeCardBackgroundPainter extends CustomPainter {
+ final Color color;
+
+ const _FileTypeCardBackgroundPainter(this.color);
+
+ @override
+ void paint(Canvas canvas, Size size) {
+ final paint = Paint()
+ ..color = color
+ ..isAntiAlias = true;
+ canvas.drawPath(_FileTypeCardPath.build(size), paint);
+ }
+
+ @override
+ bool shouldRepaint(_FileTypeCardBackgroundPainter oldDelegate) {
+ return color != oldDelegate.color;
+ }
+}
+
+class _FileTypeCardPath {
+ static const _figmaWidth = 108.0;
+ static const _figmaHeight = 56.0;
+ static const _figmaPoints = [
+ Offset(0, 0),
+ Offset(47.5, 0),
+ Offset(53.5, 7),
+ Offset(108, 7),
+ Offset(108, 56),
+ Offset(0, 56),
+ ];
+ static const _figmaRadii = [16.0, 8.0, 0.0, 16.0, 16.0, 16.0];
+
+ static Path build(Size size) {
+ final scaleX = size.width / _figmaWidth;
+ final scaleY = size.height / _figmaHeight;
+ final radiusScale = math.min(scaleX, scaleY);
+ final points = _figmaPoints
+ .map((point) => Offset(point.dx * scaleX, point.dy * scaleY))
+ .toList();
+ final radii = _figmaRadii.map((radius) => radius * radiusScale).toList();
+ return _roundedPolygon(points, radii);
+ }
+
+ static Path _roundedPolygon(List<Offset> points, List<double> radii) {
+ final path = Path();
+ for (var index = 0; index < points.length; index++) {
+ final current = points[index];
+ final previous = points[(index - 1 + points.length) % points.length];
+ final next = points[(index + 1) % points.length];
+ final incoming = previous - current;
+ final outgoing = next - current;
+ final incomingLength = incoming.distance;
+ final outgoingLength = outgoing.distance;
+ final radius = radii[index];
+
+ if (radius <= 0 || incomingLength == 0 || outgoingLength == 0) {
+ if (index == 0) {
+ path.moveTo(current.dx, current.dy);
+ } else {
+ path.lineTo(current.dx, current.dy);
+ }
+ continue;
+ }
+
+ final incomingUnit = incoming / incomingLength;
+ final outgoingUnit = outgoing / outgoingLength;
+ final dotProduct =
+ (incomingUnit.dx * outgoingUnit.dx) +
+ (incomingUnit.dy * outgoingUnit.dy);
+ final angle = math.acos(dotProduct.clamp(-1.0, 1.0));
+ final tangentLength = math.min(
+ radius / math.tan(angle / 2),
+ math.min(incomingLength, outgoingLength) / 2,
+ );
+ final start = current + incomingUnit * tangentLength;
+ final end = current + outgoingUnit * tangentLength;
+
+ if (index == 0) {
+ path.moveTo(start.dx, start.dy);
+ } else {
+ path.lineTo(start.dx, start.dy);
+ }
+ path.quadraticBezierTo(current.dx, current.dy, end.dx, end.dy);
+ }
+ path.close();
+ return path;
+ }
+}