Selaa lähdekoodia

Add a gallery for shared collections

Vishnu Mohandas 4 vuotta sitten
vanhempi
commit
f6b9e50f8a

+ 14 - 0
lib/db/files_db.dart

@@ -149,6 +149,20 @@ class FilesDB {
     return _convertToFiles(results);
     return _convertToFiles(results);
   }
   }
 
 
+  Future<List<File>> 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<List<File>> getFilesCreatedWithinDuration(
   Future<List<File>> getFilesCreatedWithinDuration(
       int startCreationTime, int endCreationTime) async {
       int startCreationTime, int endCreationTime) async {
     final db = await instance.database;
     final db = await instance.database;

+ 2 - 2
lib/ui/gallery_app_bar_widget.dart

@@ -19,7 +19,7 @@ import 'package:photos/utils/share_util.dart';
 enum GalleryAppBarType {
 enum GalleryAppBarType {
   homepage,
   homepage,
   local_folder,
   local_folder,
-  remote_folder,
+  shared_collection,
   search_results,
   search_results,
 }
 }
 
 
@@ -156,7 +156,7 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
   List<Widget> _getActions(BuildContext context) {
   List<Widget> _getActions(BuildContext context) {
     List<Widget> actions = List<Widget>();
     List<Widget> actions = List<Widget>();
     if (widget.selectedFiles.files.isNotEmpty) {
     if (widget.selectedFiles.files.isNotEmpty) {
-      if (widget.type != GalleryAppBarType.remote_folder &&
+      if (widget.type != GalleryAppBarType.shared_collection &&
           widget.type != GalleryAppBarType.search_results) {
           widget.type != GalleryAppBarType.search_results) {
         actions.add(IconButton(
         actions.add(IconButton(
           icon: Icon(Icons.delete),
           icon: Icon(Icons.delete),

+ 1 - 1
lib/ui/remote_folder_page.dart

@@ -32,7 +32,7 @@ class _RemoteFolderPageState extends State<RemoteFolderPage> {
     );
     );
     return Scaffold(
     return Scaffold(
       appBar: GalleryAppBarWidget(
       appBar: GalleryAppBarWidget(
-        GalleryAppBarType.remote_folder,
+        GalleryAppBarType.shared_collection,
         widget.folder.name,
         widget.folder.name,
         _selectedFiles,
         _selectedFiles,
         widget.folder.deviceFolder,
         widget.folder.deviceFolder,

+ 42 - 0
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<SharedCollectionPage> {
+  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,
+    );
+  }
+}

+ 10 - 10
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/models/shared_collection.dart';
 import 'package:photos/ui/common_elements.dart';
 import 'package:photos/ui/common_elements.dart';
 import 'package:photos/ui/loading_widget.dart';
 import 'package:photos/ui/loading_widget.dart';
+import 'package:photos/ui/shared_collection_page.dart';
 import 'package:photos/ui/thumbnail_widget.dart';
 import 'package:photos/ui/thumbnail_widget.dart';
 
 
 class SharedCollectionGallery extends StatefulWidget {
 class SharedCollectionGallery extends StatefulWidget {
@@ -101,7 +102,7 @@ class _SharedCollectionGalleryState extends State<SharedCollectionGallery> {
                     null // When the user has shared a folder without photos
                     null // When the user has shared a folder without photos
                 ? Icon(Icons.error)
                 ? Icon(Icons.error)
                 : Hero(
                 : Hero(
-                    tag: "remote_folder" + c.thumbnail.tag(),
+                    tag: "shared_collection" + c.thumbnail.tag(),
                     child: ThumbnailWidget(c.thumbnail)),
                     child: ThumbnailWidget(c.thumbnail)),
             height: 150,
             height: 150,
             width: 150,
             width: 150,
@@ -118,15 +119,14 @@ class _SharedCollectionGalleryState extends State<SharedCollectionGallery> {
         ],
         ],
       ),
       ),
       onTap: () {
       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;
+            },
+          ),
+        );
       },
       },
     );
     );
   }
   }