Sfoglia il codice sorgente

Add a button to create an album

Vishnu Mohandas 4 anni fa
parent
commit
36ab7edb7c

+ 7 - 0
lib/events/tab_changed_event.dart

@@ -0,0 +1,7 @@
+import 'package:sentry/sentry.dart';
+
+class TabChangedEvent extends Event {
+  final selectedIndex;
+
+  TabChangedEvent(this.selectedIndex);
+}

+ 27 - 3
lib/ui/collections_gallery_widget.dart

@@ -1,10 +1,13 @@
 import 'dart:async';
 import 'dart:async';
 
 
+import 'package:event_bus/event_bus.dart';
 import 'package:flutter/material.dart';
 import 'package:flutter/material.dart';
 import 'package:flutter/widgets.dart';
 import 'package:flutter/widgets.dart';
+import 'package:fluttertoast/fluttertoast.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/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/events/tab_changed_event.dart';
 import 'package:photos/models/collection.dart';
 import 'package:photos/models/collection.dart';
 import 'package:photos/models/file.dart';
 import 'package:photos/models/file.dart';
 import 'package:photos/repositories/file_repository.dart';
 import 'package:photos/repositories/file_repository.dart';
@@ -15,6 +18,7 @@ import 'package:photos/ui/device_folder_page.dart';
 import 'package:photos/ui/loading_widget.dart';
 import 'package:photos/ui/loading_widget.dart';
 import 'package:photos/ui/thumbnail_widget.dart';
 import 'package:photos/ui/thumbnail_widget.dart';
 import 'package:path/path.dart' as p;
 import 'package:path/path.dart' as p;
+import 'package:photos/utils/toast_util.dart';
 
 
 class CollectionsGalleryWidget extends StatefulWidget {
 class CollectionsGalleryWidget extends StatefulWidget {
   const CollectionsGalleryWidget({Key key}) : super(key: key);
   const CollectionsGalleryWidget({Key key}) : super(key: key);
@@ -80,9 +84,9 @@ class _CollectionsGalleryWidgetState extends State<CollectionsGalleryWidget> {
             padding: EdgeInsets.only(bottom: 12),
             padding: EdgeInsets.only(bottom: 12),
             physics: ScrollPhysics(), // to disable GridView's scrolling
             physics: ScrollPhysics(), // to disable GridView's scrolling
             itemBuilder: (context, index) {
             itemBuilder: (context, index) {
-              return _buildCollection(context, items.collections[index]);
+              return _buildCollection(context, items.collections, index);
             },
             },
-            itemCount: items.collections.length,
+            itemCount: items.collections.length + 1, // To include the + button
             gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
             gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
               crossAxisCount: 2,
               crossAxisCount: 2,
             ),
             ),
@@ -165,7 +169,27 @@ class _CollectionsGalleryWidgetState extends State<CollectionsGalleryWidget> {
     );
     );
   }
   }
 
 
-  Widget _buildCollection(BuildContext context, CollectionWithThumbnail c) {
+  Widget _buildCollection(BuildContext context,
+      List<CollectionWithThumbnail> collections, int index) {
+    if (index == collections.length) {
+      return Container(
+        height: 150,
+        width: 150,
+        margin: EdgeInsets.fromLTRB(0, 0, 12, 28),
+        child: OutlineButton(
+          child: Icon(
+            Icons.add,
+          ),
+          onPressed: () async {
+            await showToast(
+                "Long press to select photos and click + to create an album.",
+                toastLength: Toast.LENGTH_LONG);
+            Bus.instance.fire(TabChangedEvent(0));
+          },
+        ),
+      );
+    }
+    final c = collections[index];
     return GestureDetector(
     return GestureDetector(
       child: Column(
       child: Column(
         children: <Widget>[
         children: <Widget>[

+ 9 - 0
lib/ui/home_widget.dart

@@ -7,6 +7,7 @@ import 'package:flutter/widgets.dart';
 import 'package:photos/core/configuration.dart';
 import 'package:photos/core/configuration.dart';
 import 'package:photos/core/event_bus.dart';
 import 'package:photos/core/event_bus.dart';
 import 'package:photos/events/local_photos_updated_event.dart';
 import 'package:photos/events/local_photos_updated_event.dart';
+import 'package:photos/events/tab_changed_event.dart';
 import 'package:photos/models/filters/important_items_filter.dart';
 import 'package:photos/models/filters/important_items_filter.dart';
 import 'package:photos/models/file.dart';
 import 'package:photos/models/file.dart';
 import 'package:photos/repositories/file_repository.dart';
 import 'package:photos/repositories/file_repository.dart';
@@ -47,6 +48,7 @@ class _HomeWidgetState extends State<HomeWidget> {
   int _selectedNavBarItem = 0;
   int _selectedNavBarItem = 0;
   StreamSubscription<LocalPhotosUpdatedEvent>
   StreamSubscription<LocalPhotosUpdatedEvent>
       _localPhotosUpdatedEventSubscription;
       _localPhotosUpdatedEventSubscription;
+  StreamSubscription<TabChangedEvent> _tabChangedEventSubscription;
 
 
   @override
   @override
   void initState() {
   void initState() {
@@ -60,6 +62,12 @@ class _HomeWidgetState extends State<HomeWidget> {
         Bus.instance.on<LocalPhotosUpdatedEvent>().listen((event) {
         Bus.instance.on<LocalPhotosUpdatedEvent>().listen((event) {
       setState(() {});
       setState(() {});
     });
     });
+    _tabChangedEventSubscription =
+        Bus.instance.on<TabChangedEvent>().listen((event) {
+      setState(() {
+        _selectedNavBarItem = event.selectedIndex;
+      });
+    });
     _initDeepLinks();
     _initDeepLinks();
     super.initState();
     super.initState();
   }
   }
@@ -211,6 +219,7 @@ class _HomeWidgetState extends State<HomeWidget> {
   void dispose() {
   void dispose() {
     _detector.stopListening();
     _detector.stopListening();
     _localPhotosUpdatedEventSubscription.cancel();
     _localPhotosUpdatedEventSubscription.cancel();
+    _tabChangedEventSubscription.cancel();
     super.dispose();
     super.dispose();
   }
   }
 }
 }

+ 3 - 3
lib/utils/toast_util.dart

@@ -1,13 +1,13 @@
 import 'package:flutter/material.dart';
 import 'package:flutter/material.dart';
 import 'package:fluttertoast/fluttertoast.dart';
 import 'package:fluttertoast/fluttertoast.dart';
 
 
-void showToast(String message, {toastLength: Toast.LENGTH_SHORT}) {
-  Fluttertoast.showToast(
+Future<void> showToast(String message, {toastLength: Toast.LENGTH_SHORT}) {
+  return Fluttertoast.showToast(
       msg: message,
       msg: message,
       toastLength: toastLength,
       toastLength: toastLength,
       gravity: ToastGravity.BOTTOM,
       gravity: ToastGravity.BOTTOM,
       timeInSecForIosWeb: 1,
       timeInSecForIosWeb: 1,
-      backgroundColor: Colors.grey[850],
+      backgroundColor: Colors.grey[800],
       textColor: Colors.white,
       textColor: Colors.white,
       fontSize: 16.0);
       fontSize: 16.0);
 }
 }