diff --git a/lib/db/files_db.dart b/lib/db/files_db.dart index 2dd4801db..5f47b4894 100644 --- a/lib/db/files_db.dart +++ b/lib/db/files_db.dart @@ -149,6 +149,20 @@ class FilesDB { return _convertToFiles(results); } + Future> getAllInCollection( + int collectionID, int beforeCreationTime, int limit) async { + final db = await instance.database; + final results = await db.query( + table, + where: + '$columnCollectionID = ? AND $columnIsDeleted = 0 AND $columnCreationTime < ?', + whereArgs: [collectionID, beforeCreationTime], + orderBy: '$columnCreationTime DESC', + limit: limit, + ); + return _convertToFiles(results); + } + Future> getFilesCreatedWithinDuration( int startCreationTime, int endCreationTime) async { final db = await instance.database; diff --git a/lib/ui/gallery_app_bar_widget.dart b/lib/ui/gallery_app_bar_widget.dart index 21a4041a0..50dd4bfa1 100644 --- a/lib/ui/gallery_app_bar_widget.dart +++ b/lib/ui/gallery_app_bar_widget.dart @@ -19,7 +19,7 @@ import 'package:photos/utils/share_util.dart'; enum GalleryAppBarType { homepage, local_folder, - remote_folder, + shared_collection, search_results, } @@ -156,7 +156,7 @@ class _GalleryAppBarWidgetState extends State { List _getActions(BuildContext context) { List actions = List(); if (widget.selectedFiles.files.isNotEmpty) { - if (widget.type != GalleryAppBarType.remote_folder && + if (widget.type != GalleryAppBarType.shared_collection && widget.type != GalleryAppBarType.search_results) { actions.add(IconButton( icon: Icon(Icons.delete), diff --git a/lib/ui/remote_folder_page.dart b/lib/ui/remote_folder_page.dart index 9054fcd18..d31b71614 100644 --- a/lib/ui/remote_folder_page.dart +++ b/lib/ui/remote_folder_page.dart @@ -32,7 +32,7 @@ class _RemoteFolderPageState extends State { ); return Scaffold( appBar: GalleryAppBarWidget( - GalleryAppBarType.remote_folder, + GalleryAppBarType.shared_collection, widget.folder.name, _selectedFiles, widget.folder.deviceFolder, diff --git a/lib/ui/shared_collection_page.dart b/lib/ui/shared_collection_page.dart new file mode 100644 index 000000000..25a56d372 --- /dev/null +++ b/lib/ui/shared_collection_page.dart @@ -0,0 +1,42 @@ +import 'package:flutter/material.dart'; +import 'package:photos/db/files_db.dart'; +import 'package:photos/models/selected_files.dart'; +import 'package:photos/models/shared_collection.dart'; +import 'package:photos/ui/gallery.dart'; +import 'package:photos/ui/gallery_app_bar_widget.dart'; + +class SharedCollectionPage extends StatefulWidget { + final SharedCollection collection; + + const SharedCollectionPage(this.collection, {Key key}) : super(key: key); + + @override + _SharedCollectionPageState createState() => _SharedCollectionPageState(); +} + +class _SharedCollectionPageState extends State { + final _selectedFiles = SelectedFiles(); + + @override + Widget build(Object context) { + var gallery = Gallery( + asyncLoader: (lastFile, limit) => FilesDB.instance.getAllInCollection( + widget.collection.id, + lastFile == null + ? DateTime.now().microsecondsSinceEpoch + : lastFile.creationTime, + limit), + // onRefresh: () => FolderSharingService.instance.syncDiff(widget.folder), + tagPrefix: "shared_collection", + selectedFiles: _selectedFiles, + ); + return Scaffold( + appBar: GalleryAppBarWidget( + GalleryAppBarType.shared_collection, + widget.collection.name, + _selectedFiles, + ), + body: gallery, + ); + } +} diff --git a/lib/ui/shared_collections_gallery.dart b/lib/ui/shared_collections_gallery.dart index 7827005a0..566975eb9 100644 --- a/lib/ui/shared_collections_gallery.dart +++ b/lib/ui/shared_collections_gallery.dart @@ -11,6 +11,7 @@ import 'package:photos/models/file.dart'; import 'package:photos/models/shared_collection.dart'; import 'package:photos/ui/common_elements.dart'; import 'package:photos/ui/loading_widget.dart'; +import 'package:photos/ui/shared_collection_page.dart'; import 'package:photos/ui/thumbnail_widget.dart'; class SharedCollectionGallery extends StatefulWidget { @@ -101,7 +102,7 @@ class _SharedCollectionGalleryState extends State { null // When the user has shared a folder without photos ? Icon(Icons.error) : Hero( - tag: "remote_folder" + c.thumbnail.tag(), + tag: "shared_collection" + c.thumbnail.tag(), child: ThumbnailWidget(c.thumbnail)), height: 150, width: 150, @@ -118,15 +119,14 @@ class _SharedCollectionGalleryState extends State { ], ), onTap: () { - // TODO - // final page = RemoteFolderPage(folder); - // Navigator.of(context).push( - // MaterialPageRoute( - // builder: (BuildContext context) { - // return page; - // }, - // ), - // ); + final page = SharedCollectionPage(c.collection); + Navigator.of(context).push( + MaterialPageRoute( + builder: (BuildContext context) { + return page; + }, + ), + ); }, ); }