Eagerly supply all available device folder files

This commit is contained in:
Vishnu Mohandas 2020-11-14 16:27:08 +05:30
parent 8334ec809e
commit 2effbf834d
4 changed files with 19 additions and 14 deletions

View file

@ -172,6 +172,18 @@ class FilesDB {
return _convertToFiles(results); 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( Future<List<File>> getAllInPathBeforeCreationTime(
String path, int beforeCreationTime, int limit) async { String path, int beforeCreationTime, int limit) async {
final db = await instance.database; final db = await instance.database;

View file

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

View file

@ -132,7 +132,8 @@ class _CollectionsGalleryWidgetState extends State<CollectionsGalleryWidget>
} }
for (final path in thumbnailPathMap.keys) { for (final path in thumbnailPathMap.keys) {
final folderName = p.basename(path); 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 collectionsWithThumbnail = List<CollectionWithThumbnail>();
final collections = collectionsService.getCollections(); final collections = collectionsService.getCollections();

View file

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