Browse Source

minor logic change + refactoring

ashilkn 3 năm trước cách đây
mục cha
commit
8c38c05c28
2 tập tin đã thay đổi với 109 bổ sung92 xóa
  1. 98 0
      lib/ui/viewer/file/RawExifButton.dart
  2. 11 92
      lib/ui/viewer/file/file_info_dialog.dart

+ 98 - 0
lib/ui/viewer/file/RawExifButton.dart

@@ -0,0 +1,98 @@
+import 'package:exif/exif.dart';
+import 'package:flutter/cupertino.dart';
+import 'package:flutter/material.dart';
+import 'package:photos/ente_theme_data.dart';
+import "package:photos/models/file.dart";
+import 'package:photos/ui/viewer/file/exif_info_dialog.dart';
+import 'package:photos/utils/toast_util.dart';
+
+enum Status {
+  loading,
+  exifIsAvailable,
+  noExif,
+}
+
+class RawExifButton extends StatelessWidget {
+  final File file;
+  final Map<String, IfdTag> exif;
+  const RawExifButton(this.exif, this.file, {Key key}) : super(key: key);
+
+  @override
+  Widget build(BuildContext context) {
+    Status exifStatus = Status.loading;
+    if (exif == null) {
+      exifStatus = Status.loading;
+    } else if (exif.isNotEmpty) {
+      exifStatus = Status.exifIsAvailable;
+    } else {
+      exifStatus = Status.noExif;
+    }
+    return GestureDetector(
+      onTap:
+          exifStatus == Status.loading || exifStatus == Status.exifIsAvailable
+              ? () {
+                  showDialog(
+                    context: context,
+                    builder: (BuildContext context) {
+                      return ExifInfoDialog(file);
+                    },
+                    barrierColor: Colors.black87,
+                  );
+                }
+              : exifStatus == Status.noExif
+                  ? () {
+                      showShortToast(context, "This image has no exif data");
+                    }
+                  : null,
+      child: Container(
+        height: 40,
+        width: 140,
+        decoration: BoxDecoration(
+          color: Theme.of(context)
+              .colorScheme
+              .inverseBackgroundColor
+              .withOpacity(0.12),
+          borderRadius: const BorderRadius.all(
+            Radius.circular(20),
+          ),
+        ),
+        child: Center(
+          child: exifStatus == Status.loading
+              ? Row(
+                  mainAxisAlignment: MainAxisAlignment.center,
+                  children: const [
+                    CupertinoActivityIndicator(
+                      radius: 8,
+                    ),
+                    SizedBox(
+                      width: 8,
+                    ),
+                    Text('EXIF')
+                  ],
+                )
+              : exifStatus == Status.exifIsAvailable
+                  ? Row(
+                      mainAxisAlignment: MainAxisAlignment.center,
+                      children: const [
+                        Icon(Icons.feed_outlined),
+                        SizedBox(
+                          width: 8,
+                        ),
+                        Text('Raw EXIF'),
+                      ],
+                    )
+                  : Row(
+                      mainAxisAlignment: MainAxisAlignment.center,
+                      children: const [
+                        Icon(Icons.feed_outlined),
+                        SizedBox(
+                          width: 8,
+                        ),
+                        Text('No EXIF'),
+                      ],
+                    ),
+        ),
+      ),
+    );
+  }
+}

+ 11 - 92
lib/ui/viewer/file/file_info_dialog.dart

@@ -7,6 +7,7 @@ import "package:photos/ente_theme_data.dart";
 import "package:photos/models/file.dart";
 import "package:photos/models/file_type.dart";
 import "package:photos/services/collections_service.dart";
+import 'package:photos/ui/viewer/file/RawExifButton.dart';
 import "package:photos/ui/viewer/file/exif_info_dialog.dart";
 import "package:photos/utils/date_time_util.dart";
 import "package:photos/utils/exif_util.dart";
@@ -58,6 +59,12 @@ class _FileInfoWidgetState extends State<FileInfoWidget> {
   @override
   Widget build(BuildContext context) {
     final file = widget.file;
+    print('file');
+    print(file);
+    print("file.localID");
+    print(file.localID);
+    print("file.duration");
+    print(file.duration);
     final dateTime = DateTime.fromMicrosecondsSinceEpoch(file.creationTime);
     final dateTimeForUpdationTime =
         DateTime.fromMicrosecondsSinceEpoch(file.updationTime);
@@ -127,7 +134,10 @@ class _FileInfoWidgetState extends State<FileInfoWidget> {
               padding: const EdgeInsets.only(right: 10),
               child: _getFileSize(),
             ),
-            !_isImage ? _getVideoDuration() : const SizedBox.shrink(),
+            (file.fileType == FileType.video) &&
+                    (file.localID != null || file.duration != 0)
+                ? _getVideoDuration()
+                : const SizedBox.shrink(),
           ],
         ),
         trailing: file.uploadedFileID == null ||
@@ -399,94 +409,3 @@ class DividerWithPadding extends StatelessWidget {
     );
   }
 }
-
-enum Status {
-  loading,
-  exifIsAvailable,
-  noExif,
-}
-
-class RawExifButton extends StatelessWidget {
-  final File file;
-  final Map<String, IfdTag> exif;
-  const RawExifButton(this.exif, this.file, {Key key}) : super(key: key);
-
-  @override
-  Widget build(BuildContext context) {
-    Status exifStatus = Status.loading;
-    if (exif == null) {
-      exifStatus = Status.loading;
-    } else if (exif.isNotEmpty) {
-      exifStatus = Status.exifIsAvailable;
-    } else {
-      exifStatus = Status.noExif;
-    }
-    return GestureDetector(
-      onTap:
-          exifStatus == Status.loading || exifStatus == Status.exifIsAvailable
-              ? () {
-                  showDialog(
-                    context: context,
-                    builder: (BuildContext context) {
-                      return ExifInfoDialog(file);
-                    },
-                    barrierColor: Colors.black87,
-                  );
-                }
-              : exifStatus == Status.noExif
-                  ? () {
-                      showShortToast(context, "This image has no exif data");
-                    }
-                  : null,
-      child: Container(
-        height: 40,
-        width: 140,
-        decoration: BoxDecoration(
-          color: Theme.of(context)
-              .colorScheme
-              .inverseBackgroundColor
-              .withOpacity(0.12),
-          borderRadius: const BorderRadius.all(
-            Radius.circular(20),
-          ),
-        ),
-        child: Center(
-          child: exifStatus == Status.loading
-              ? Row(
-                  mainAxisAlignment: MainAxisAlignment.center,
-                  children: const [
-                    CupertinoActivityIndicator(
-                      radius: 8,
-                    ),
-                    SizedBox(
-                      width: 8,
-                    ),
-                    Text('EXIF')
-                  ],
-                )
-              : exifStatus == Status.exifIsAvailable
-                  ? Row(
-                      mainAxisAlignment: MainAxisAlignment.center,
-                      children: const [
-                        Icon(Icons.feed_outlined),
-                        SizedBox(
-                          width: 8,
-                        ),
-                        Text('Raw EXIF'),
-                      ],
-                    )
-                  : Row(
-                      mainAxisAlignment: MainAxisAlignment.center,
-                      children: const [
-                        Icon(Icons.feed_outlined),
-                        SizedBox(
-                          width: 8,
-                        ),
-                        Text('No EXIF'),
-                      ],
-                    ),
-        ),
-      ),
-    );
-  }
-}