Browse Source

Refactor thumbnail widget

Neeraj Gupta 3 years ago
parent
commit
54c118b5e7

+ 0 - 2
lib/ui/common/common_elements.dart

@@ -14,5 +14,3 @@ Widget nothingToSeeHere({Color textColor}) {
     ),
     ),
   );
   );
 }
 }
-
-final emptyContainer = const SizedBox.shrink();

+ 5 - 6
lib/ui/viewer/file/file_icons_widget.dart

@@ -1,18 +1,17 @@
 import 'package:flutter/material.dart';
 import 'package:flutter/material.dart';
+import 'package:photos/ente_theme_data.dart';
 import 'package:photos/models/trash_file.dart';
 import 'package:photos/models/trash_file.dart';
 import 'package:photos/utils/date_time_util.dart';
 import 'package:photos/utils/date_time_util.dart';
 
 
 class ThumbnailPlaceHolder extends StatelessWidget {
 class ThumbnailPlaceHolder extends StatelessWidget {
-  final Color backgroundColor;
-
-  const ThumbnailPlaceHolder(this.backgroundColor, {Key key}) : super(key: key);
+  const ThumbnailPlaceHolder({Key key}) : super(key: key);
 
 
   @override
   @override
   Widget build(BuildContext context) {
   Widget build(BuildContext context) {
     debugPrint("building placeHolder for thumbnail");
     debugPrint("building placeHolder for thumbnail");
     return Container(
     return Container(
       alignment: Alignment.center,
       alignment: Alignment.center,
-      color: backgroundColor,
+      color: Theme.of(context).colorScheme.galleryThumbBackgroundColor,
     );
     );
   }
   }
 }
 }
@@ -70,7 +69,7 @@ class LivePhotoOverlayIcon extends StatelessWidget {
 
 
   @override
   @override
   Widget build(BuildContext context) {
   Widget build(BuildContext context) {
-    Align(
+    return Align(
       alignment: Alignment.topRight,
       alignment: Alignment.topRight,
       child: Padding(
       child: Padding(
         padding: const EdgeInsets.only(right: 8, top: 4),
         padding: const EdgeInsets.only(right: 8, top: 4),
@@ -117,7 +116,7 @@ class ArchiveOverlayIcon extends StatelessWidget {
 
 
   @override
   @override
   Widget build(BuildContext context) {
   Widget build(BuildContext context) {
-    Align(
+    return Align(
       alignment: Alignment.bottomRight,
       alignment: Alignment.bottomRight,
       child: Padding(
       child: Padding(
         padding: const EdgeInsets.only(right: 8, bottom: 8),
         padding: const EdgeInsets.only(right: 8, bottom: 8),

+ 24 - 37
lib/ui/viewer/file/thumbnail_widget.dart

@@ -11,7 +11,6 @@ import 'package:photos/events/local_photos_updated_event.dart';
 import 'package:photos/models/file.dart';
 import 'package:photos/models/file.dart';
 import 'package:photos/models/file_type.dart';
 import 'package:photos/models/file_type.dart';
 import 'package:photos/models/trash_file.dart';
 import 'package:photos/models/trash_file.dart';
-import 'package:photos/ui/common/common_elements.dart';
 import 'package:photos/ui/viewer/file/file_icons_widget.dart';
 import 'package:photos/ui/viewer/file/file_icons_widget.dart';
 import 'package:photos/utils/file_util.dart';
 import 'package:photos/utils/file_util.dart';
 import 'package:photos/utils/thumbnail_util.dart';
 import 'package:photos/utils/thumbnail_util.dart';
@@ -40,13 +39,6 @@ class ThumbnailWidget extends StatefulWidget {
   _ThumbnailWidgetState createState() => _ThumbnailWidgetState();
   _ThumbnailWidgetState createState() => _ThumbnailWidgetState();
 }
 }
 
 
-Widget getFileInfoContainer(BuildContext context, File file) {
-  if (file is TrashFile) {
-    return TrashedFileOverlayText(file);
-  }
-  return emptyContainer;
-}
-
 class _ThumbnailWidgetState extends State<ThumbnailWidget> {
 class _ThumbnailWidgetState extends State<ThumbnailWidget> {
   static final _logger = Logger("ThumbnailWidget");
   static final _logger = Logger("ThumbnailWidget");
   bool _hasLoadedThumbnail = false;
   bool _hasLoadedThumbnail = false;
@@ -94,51 +86,46 @@ class _ThumbnailWidgetState extends State<ThumbnailWidget> {
         fit: widget.fit,
         fit: widget.fit,
       );
       );
     }
     }
-    // todo: [2ndJuly22] pref-review if the content Widget which contains depends on thumbnail fetch
-    // logic should be part of separate stateFull widget and
-    // Thumbnail widget can be stateless
+    // todo: [2ndJuly22] pref-review if the content Widget which depends on
+    // thumbnail fetch logic should be part of separate stateFull widget.
+    // If yes, parent thumbnail widget can be stateless
     Widget content;
     Widget content;
     if (image != null) {
     if (image != null) {
+      List<Widget> contentChildren = [image];
       if (widget.file.fileType == FileType.video) {
       if (widget.file.fileType == FileType.video) {
-        content = Stack(
-          children: [
-            image,
-            const VideoOverlayIcon(),
-          ],
-          fit: StackFit.expand,
-        );
+        contentChildren.add(const VideoOverlayIcon());
       } else if (widget.file.fileType == FileType.livePhoto &&
       } else if (widget.file.fileType == FileType.livePhoto &&
           widget.shouldShowLivePhotoOverlay) {
           widget.shouldShowLivePhotoOverlay) {
-        content = Stack(
-          children: [
-            image,
-            const LivePhotoOverlayIcon(),
-          ],
-          fit: StackFit.expand,
-        );
-      } else {
-        content = image;
+        contentChildren.add(const LivePhotoOverlayIcon());
       }
       }
+      content = contentChildren.length == 1
+          ? contentChildren.first
+          : Stack(
+              children: contentChildren,
+              fit: StackFit.expand,
+            );
     }
     }
-    List<Widget> viewChildrens = [
-      Theme.of(context).brightness == Brightness.light
-          ? const ThumbnailPlaceHolder(Color.fromRGBO(240, 240, 240, 1))
-          : const ThumbnailPlaceHolder(Color.fromRGBO(20, 20, 20, 1)),
+    List<Widget> viewChildren = [
+      const ThumbnailPlaceHolder(),
       AnimatedOpacity(
       AnimatedOpacity(
         opacity: content == null ? 0 : 1.0,
         opacity: content == null ? 0 : 1.0,
         duration: Duration(milliseconds: 200),
         duration: Duration(milliseconds: 200),
         child: content,
         child: content,
-      ),
-      widget.shouldShowSyncStatus && widget.file.uploadedFileID == null
-          ? const UnSyncedIcon()
-          : getFileInfoContainer(context, widget.file),
+      )
     ];
     ];
+    if (widget.shouldShowSyncStatus && widget.file.uploadedFileID == null) {
+      viewChildren.add(const UnSyncedIcon());
+    }
+    if (widget.file is TrashFile) {
+      viewChildren.add(TrashedFileOverlayText(widget.file));
+    }
     // todo: Move this icon overlay to the collection widget.
     // todo: Move this icon overlay to the collection widget.
     if (widget.shouldShowArchiveStatus) {
     if (widget.shouldShowArchiveStatus) {
-      viewChildrens.add(const ArchiveOverlayIcon());
+      viewChildren.add(const ArchiveOverlayIcon());
     }
     }
+
     return Stack(
     return Stack(
-      children: viewChildrens,
+      children: viewChildren,
       fit: StackFit.expand,
       fit: StackFit.expand,
     );
     );
   }
   }