Browse Source

Code refactor

ashilkn 2 năm trước cách đây
mục cha
commit
8a4a4580c7

+ 30 - 26
lib/ui/viewer/location/add_location_gallery_widget.dart

@@ -29,32 +29,7 @@ class _AddLocationGalleryWidgetState extends State<AddLocationGalleryWidget> {
 
   @override
   void initState() {
-    final ownerID = Configuration.instance.getUserID();
-    final hasSelectedAllForBackup =
-        Configuration.instance.hasSelectedAllFoldersForBackup();
-    final collectionsToHide =
-        CollectionsService.instance.collectionsHiddenFromTimeline();
-    if (hasSelectedAllForBackup) {
-      fileLoadResult = FilesDB.instance.getAllLocalAndUploadedFiles(
-        galleryLoadStartTime,
-        galleryLoadEndTime,
-        ownerID!,
-        limit: null,
-        asc: true,
-        ignoredCollectionIDs: collectionsToHide,
-        onlyFilesWithLocation: true,
-      );
-    } else {
-      fileLoadResult = FilesDB.instance.getAllPendingOrUploadedFiles(
-        galleryLoadStartTime,
-        galleryLoadEndTime,
-        ownerID!,
-        limit: null,
-        asc: true,
-        ignoredCollectionIDs: collectionsToHide,
-        onlyFilesWithLocation: true,
-      );
-    }
+    fileLoadResult = _fetchAllFilesWithLocationData();
     removeIgnoredFiles = _removeIgnoredFiles(fileLoadResult);
     super.initState();
   }
@@ -154,4 +129,33 @@ class _AddLocationGalleryWidgetState extends State<AddLocationGalleryWidget> {
         (galleryGridSpacing * (numberOfRows - 1));
     return galleryHeight + 120;
   }
+
+  Future<FileLoadResult> _fetchAllFilesWithLocationData() {
+    final ownerID = Configuration.instance.getUserID();
+    final hasSelectedAllForBackup =
+        Configuration.instance.hasSelectedAllFoldersForBackup();
+    final collectionsToHide =
+        CollectionsService.instance.collectionsHiddenFromTimeline();
+    if (hasSelectedAllForBackup) {
+      return FilesDB.instance.getAllLocalAndUploadedFiles(
+        galleryLoadStartTime,
+        galleryLoadEndTime,
+        ownerID!,
+        limit: null,
+        asc: true,
+        ignoredCollectionIDs: collectionsToHide,
+        onlyFilesWithLocation: true,
+      );
+    } else {
+      return FilesDB.instance.getAllPendingOrUploadedFiles(
+        galleryLoadStartTime,
+        galleryLoadEndTime,
+        ownerID!,
+        limit: null,
+        asc: true,
+        ignoredCollectionIDs: collectionsToHide,
+        onlyFilesWithLocation: true,
+      );
+    }
+  }
 }

+ 2 - 0
lib/ui/viewer/location/add_location_sheet.dart

@@ -41,6 +41,8 @@ class AddLocationSheet extends StatefulWidget {
 }
 
 class _AddLocationSheetState extends State<AddLocationSheet> {
+  //When memoriesCountNotifier is null, we show the loading widget in the
+  //memories count section which also means the gallery is loading.
   ValueNotifier<int?> memoriesCountNotifier = ValueNotifier(null);
   @override
   Widget build(BuildContext context) {