Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mob][photos] Show video duration on thumbnails

laurenspriem65201d2b5762
diff --git a/mobile/lib/ui/viewer/file/file_icons_widget.dart b/mobile/lib/ui/viewer/file/file_icons_widget.dart
index 1d22a5c469..d99155b076 100644
--- a/mobile/lib/ui/viewer/file/file_icons_widget.dart
+++ b/mobile/lib/ui/viewer/file/file_icons_widget.dart
@@ -121,6 +121,33 @@ class VideoOverlayIcon extends StatelessWidget {
}
}
+class VideoOverlayDuration extends StatelessWidget {
+ final int duration;
+ const VideoOverlayDuration({Key? key, required this.duration})
+ : super(key: key);
+
+ @override
+ Widget build(BuildContext context) {
+ final String formattedDuration =
+ Duration(seconds: duration).toString().split('.').first;
+ final List<String> separated = formattedDuration.split(':');
+ final String hour =
+ (separated[0] == '0') ? '' : int.parse(separated[0]).toString() + ':';
+ final String minute = int.parse(separated[1]).toString() + ':';
+ final String second = int.parse(separated[2]).toString();
+ final String strippedDuration = hour + minute + second;
+ return _BottomRightOverlayText(
+ Text(
+ strippedDuration,
+ style: Theme.of(context)
+ .textTheme
+ .titleSmall!
+ .copyWith(color: Colors.white),
+ ),
+ );
+ }
+}
+
class OwnerAvatarOverlayIcon extends StatelessWidget {
final User user;
const OwnerAvatarOverlayIcon(this.user, {Key? key}) : super(key: key);
@@ -325,3 +352,43 @@ class _BottomRightOverlayIcon extends StatelessWidget {
);
}
}
+
+class _BottomRightOverlayText extends StatelessWidget {
+ final Text text;
+
+ const _BottomRightOverlayText(
+ this.text, {
+ Key? key,
+ }) : super(key: key);
+
+ @override
+ Widget build(BuildContext context) {
+ return LayoutBuilder(
+ builder: (context, constraints) {
+ const double inset = 4;
+
+ return Container(
+ decoration: const BoxDecoration(
+ gradient: LinearGradient(
+ begin: Alignment.bottomRight,
+ end: Alignment.center,
+ colors: [
+ Color.fromRGBO(0, 0, 0, 0.14),
+ Color.fromRGBO(0, 0, 0, 0.05),
+ Color.fromRGBO(0, 0, 0, 0.0),
+ ],
+ stops: [0, 0.6, 1],
+ ),
+ ),
+ child: Align(
+ alignment: Alignment.bottomRight,
+ child: Padding(
+ padding: const EdgeInsets.only(bottom: inset, right: inset),
+ child: text,
+ ),
+ ),
+ );
+ },
+ );
+ }
+}
diff --git a/mobile/lib/ui/viewer/file/thumbnail_widget.dart b/mobile/lib/ui/viewer/file/thumbnail_widget.dart
index 499981e71b..e48dfc0c83 100644
--- a/mobile/lib/ui/viewer/file/thumbnail_widget.dart
+++ b/mobile/lib/ui/viewer/file/thumbnail_widget.dart
@@ -19,6 +19,7 @@ import 'package:photos/services/collections_service.dart';
import 'package:photos/services/favorites_service.dart';
import 'package:photos/ui/viewer/file/file_icons_widget.dart';
import 'package:photos/utils/file_util.dart';
+import "package:photos/utils/local_settings.dart";
import 'package:photos/utils/thumbnail_util.dart';
class ThumbnailWidget extends StatefulWidget {
@@ -140,7 +141,14 @@ class _ThumbnailWidgetState extends State<ThumbnailWidget> {
}
if (widget.file.fileType == FileType.video) {
- contentChildren.add(const VideoOverlayIcon());
+ if (widget.file.duration == null ||
+ widget.file.duration! < 10 ||
+ LocalSettings.instance.getPhotoGridSize() > 4) {
+ contentChildren.add(const VideoOverlayIcon());
+ } else {
+ contentChildren
+ .add(VideoOverlayDuration(duration: widget.file.duration!));
+ }
} else if (widget.shouldShowLivePhotoOverlay &&
widget.file.isLiveOrMotionPhoto) {
contentChildren.add(const LivePhotoOverlayIcon());