Browse Source

Eagerly supply all available device folder files

Vishnu Mohandas 4 years ago
parent
commit
2effbf834d

+ 12 - 0
lib/db/files_db.dart

@@ -172,6 +172,18 @@ class FilesDB {
     return _convertToFiles(results);
   }
 
+  Future<List<File>> getAllInPath(String path) async {
+    final db = await instance.database;
+    final results = await db.query(
+      table,
+      where: '$columnLocalID IS NOT NULL AND $columnDeviceFolder = ?',
+      whereArgs: [path],
+      orderBy: '$columnCreationTime DESC',
+      groupBy: '$columnLocalID',
+    );
+    return _convertToFiles(results);
+  }
+
   Future<List<File>> getAllInPathBeforeCreationTime(
       String path, int beforeCreationTime, int limit) async {
     final db = await instance.database;

+ 4 - 5
lib/models/device_folder.dart

@@ -1,16 +1,15 @@
-import 'package:photos/models/filters/gallery_items_filter.dart';
 import 'package:photos/models/file.dart';
 
 class DeviceFolder {
   final String name;
   final String path;
   final File thumbnail;
-  final GalleryItemsFilter filter;
+  final List<File> files;
 
   DeviceFolder(
     this.name,
     this.path,
-    this.thumbnail, {
-    this.filter,
-  });
+    this.thumbnail,
+    this.files,
+  );
 }

+ 2 - 1
lib/ui/collections_gallery_widget.dart

@@ -132,7 +132,8 @@ class _CollectionsGalleryWidgetState extends State<CollectionsGalleryWidget>
     }
     for (final path in thumbnailPathMap.keys) {
       final folderName = p.basename(path);
-      folders.add(DeviceFolder(folderName, path, thumbnailPathMap[path]));
+      folders.add(DeviceFolder(
+          folderName, path, thumbnailPathMap[path], filePathMap[path]));
     }
     final collectionsWithThumbnail = List<CollectionWithThumbnail>();
     final collections = collectionsService.getCollections();

+ 1 - 8
lib/ui/device_folder_page.dart

@@ -1,6 +1,5 @@
 import 'package:flutter/material.dart';
 import 'package:photos/core/event_bus.dart';
-import 'package:photos/db/files_db.dart';
 import 'package:photos/events/local_photos_updated_event.dart';
 import 'package:photos/models/device_folder.dart';
 import 'package:photos/models/selected_files.dart';
@@ -22,13 +21,7 @@ class _DeviceFolderPageState extends State<DeviceFolderPage> {
   @override
   Widget build(Object context) {
     var gallery = Gallery(
-      asyncLoader: (lastFile, limit) => FilesDB.instance
-          .getAllInPathBeforeCreationTime(
-              widget.folder.path,
-              lastFile == null
-                  ? DateTime.now().microsecondsSinceEpoch
-                  : lastFile.creationTime,
-              limit),
+      syncLoader: () => widget.folder.files,
       reloadEvent: Bus.instance.on<LocalPhotosUpdatedEvent>(),
       tagPrefix: "device_folder:" + widget.folder.path,
       selectedFiles: _selectedFiles,