Browse Source

Refactor: Pass photoGridSize from gallery to inner widgets

Neeraj Gupta 2 years ago
parent
commit
a0b22cd3a1
2 changed files with 18 additions and 12 deletions
  1. 14 12
      lib/ui/huge_listview/lazy_loading_gallery.dart
  2. 4 0
      lib/ui/viewer/gallery/gallery.dart

+ 14 - 12
lib/ui/huge_listview/lazy_loading_gallery.dart

@@ -19,7 +19,6 @@ import 'package:photos/ui/viewer/file/detail_page.dart';
 import 'package:photos/ui/viewer/file/thumbnail_widget.dart';
 import 'package:photos/ui/viewer/gallery/gallery.dart';
 import 'package:photos/utils/date_time_util.dart';
-import 'package:photos/utils/local_settings.dart';
 import 'package:photos/utils/navigation_util.dart';
 import 'package:visibility_detector/visibility_detector.dart';
 
@@ -33,6 +32,7 @@ class LazyLoadingGallery extends StatefulWidget {
   final String tag;
   final String logTag;
   final Stream<int> currentIndexStream;
+  final int photoGirdSize;
 
   LazyLoadingGallery(
     this.files,
@@ -44,6 +44,7 @@ class LazyLoadingGallery extends StatefulWidget {
     this.tag,
     this.currentIndexStream, {
     this.logTag = "",
+    this.photoGirdSize = photoGridSizeDefault,
     Key key,
   }) : super(key: key ?? UniqueKey());
 
@@ -236,7 +237,7 @@ class _LazyLoadingGalleryState extends State<LazyLoadingGallery> {
             ? _getGallery()
             : PlaceHolderWidget(
                 _files.length,
-                LocalSettings.instance.getPhotoGridSize(),
+                widget.photoGirdSize,
               ),
       ],
     );
@@ -258,6 +259,7 @@ class _LazyLoadingGalleryState extends State<LazyLoadingGallery> {
           _files.length > kRecycleLimit,
           _toggleSelectAllFromDay,
           _areAllFromDaySelected,
+          widget.photoGirdSize,
         ),
       );
     }
@@ -285,6 +287,7 @@ class LazyLoadingGridView extends StatefulWidget {
   final bool shouldRecycle;
   final ValueNotifier toggleSelectAllFromDay;
   final ValueNotifier areAllFilesSelected;
+  final int photoGridSize;
 
   LazyLoadingGridView(
     this.tag,
@@ -294,7 +297,8 @@ class LazyLoadingGridView extends StatefulWidget {
     this.shouldRender,
     this.shouldRecycle,
     this.toggleSelectAllFromDay,
-    this.areAllFilesSelected, {
+    this.areAllFilesSelected,
+    this.photoGridSize, {
     Key key,
   }) : super(key: key ?? UniqueKey());
 
@@ -304,7 +308,6 @@ class LazyLoadingGridView extends StatefulWidget {
 
 class _LazyLoadingGridViewState extends State<LazyLoadingGridView> {
   bool _shouldRender;
-  int _photoGridSize;
   StreamSubscription<ClearSelectionsEvent> _clearSelectionsEvent;
 
   @override
@@ -340,7 +343,6 @@ class _LazyLoadingGridViewState extends State<LazyLoadingGridView> {
 
   @override
   Widget build(BuildContext context) {
-    _photoGridSize = LocalSettings.instance.getPhotoGridSize();
     if (widget.shouldRecycle) {
       return _getRecyclableView();
     } else {
@@ -361,7 +363,7 @@ class _LazyLoadingGridViewState extends State<LazyLoadingGridView> {
       },
       child: _shouldRender
           ? _getGridView()
-          : PlaceHolderWidget(widget.filesInDay.length, _photoGridSize),
+          : PlaceHolderWidget(widget.filesInDay.length, widget.photoGridSize),
     );
   }
 
@@ -376,7 +378,8 @@ class _LazyLoadingGridViewState extends State<LazyLoadingGridView> {
             });
           }
         },
-        child: PlaceHolderWidget(widget.filesInDay.length, _photoGridSize),
+        child:
+            PlaceHolderWidget(widget.filesInDay.length, widget.photoGridSize),
       );
     } else {
       return _getGridView();
@@ -386,8 +389,8 @@ class _LazyLoadingGridViewState extends State<LazyLoadingGridView> {
   Widget _getGridView() {
     return GridView.builder(
       shrinkWrap: true,
-      physics:
-          const NeverScrollableScrollPhysics(), // to disable GridView's scrolling
+      physics: const NeverScrollableScrollPhysics(),
+      // to disable GridView's scrolling
       itemBuilder: (context, index) {
         return _buildFile(context, widget.filesInDay[index]);
       },
@@ -395,7 +398,7 @@ class _LazyLoadingGridViewState extends State<LazyLoadingGridView> {
       gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
         crossAxisSpacing: 2,
         mainAxisSpacing: 2,
-        crossAxisCount: _photoGridSize,
+        crossAxisCount: widget.photoGridSize,
       ),
       padding: const EdgeInsets.all(0),
     );
@@ -433,8 +436,7 @@ class _LazyLoadingGridViewState extends State<LazyLoadingGridView> {
                   serverLoadDeferDuration: thumbnailServerLoadDeferDuration,
                   shouldShowLivePhotoOverlay: true,
                   key: Key(widget.tag + file.tag),
-                  thumbnailSize: LocalSettings.instance.getPhotoGridSize() <
-                          photoGridSizeDefault
+                  thumbnailSize: widget.photoGridSize < photoGridSizeDefault
                       ? thumbnailLargeSize
                       : thumbnailSmallSize,
                 ),

+ 4 - 0
lib/ui/viewer/gallery/gallery.dart

@@ -19,6 +19,7 @@ import 'package:photos/ui/huge_listview/huge_listview.dart';
 import 'package:photos/ui/huge_listview/lazy_loading_gallery.dart';
 import 'package:photos/ui/viewer/gallery/empty_state.dart';
 import 'package:photos/utils/date_time_util.dart';
+import 'package:photos/utils/local_settings.dart';
 import 'package:scrollable_positioned_list/scrollable_positioned_list.dart';
 
 typedef GalleryLoader = Future<FileLoadResult> Function(
@@ -77,6 +78,7 @@ class _GalleryState extends State<Gallery> {
   StreamSubscription<TabDoubleTapEvent> _tabDoubleTapEvent;
   final _forceReloadEventSubscriptions = <StreamSubscription<Event>>[];
   String _logTag;
+  int _photoGridSize;
 
   @override
   void initState() {
@@ -200,6 +202,7 @@ class _GalleryState extends State<Gallery> {
     if (!_hasLoadedFiles) {
       return const EnteLoadingWidget();
     }
+    _photoGridSize = LocalSettings.instance.getPhotoGridSize();
     return _getListView();
   }
 
@@ -246,6 +249,7 @@ class _GalleryState extends State<Gallery> {
               .where((event) => event.tag == widget.tagPrefix)
               .map((event) => event.index),
           logTag: _logTag,
+          photoGirdSize: _photoGridSize,
         );
         if (widget.header != null && index == 0) {
           gallery = Column(children: [widget.header, gallery]);