diff --git a/lib/events/tab_changed_event.dart b/lib/events/tab_changed_event.dart new file mode 100644 index 000000000..b279dd98e --- /dev/null +++ b/lib/events/tab_changed_event.dart @@ -0,0 +1,7 @@ +import 'package:sentry/sentry.dart'; + +class TabChangedEvent extends Event { + final selectedIndex; + + TabChangedEvent(this.selectedIndex); +} diff --git a/lib/ui/collections_gallery_widget.dart b/lib/ui/collections_gallery_widget.dart index c9c6cd45b..c98412c02 100644 --- a/lib/ui/collections_gallery_widget.dart +++ b/lib/ui/collections_gallery_widget.dart @@ -1,10 +1,13 @@ import 'dart:async'; +import 'package:event_bus/event_bus.dart'; import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; +import 'package:fluttertoast/fluttertoast.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/tab_changed_event.dart'; import 'package:photos/models/collection.dart'; import 'package:photos/models/file.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/thumbnail_widget.dart'; import 'package:path/path.dart' as p; +import 'package:photos/utils/toast_util.dart'; class CollectionsGalleryWidget extends StatefulWidget { const CollectionsGalleryWidget({Key key}) : super(key: key); @@ -80,9 +84,9 @@ class _CollectionsGalleryWidgetState extends State { padding: EdgeInsets.only(bottom: 12), physics: ScrollPhysics(), // to disable GridView's scrolling 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( crossAxisCount: 2, ), @@ -165,7 +169,27 @@ class _CollectionsGalleryWidgetState extends State { ); } - Widget _buildCollection(BuildContext context, CollectionWithThumbnail c) { + Widget _buildCollection(BuildContext context, + List 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( child: Column( children: [ diff --git a/lib/ui/home_widget.dart b/lib/ui/home_widget.dart index 3bc541f0f..41cf9d6c6 100644 --- a/lib/ui/home_widget.dart +++ b/lib/ui/home_widget.dart @@ -7,6 +7,7 @@ import 'package:flutter/widgets.dart'; import 'package:photos/core/configuration.dart'; import 'package:photos/core/event_bus.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/file.dart'; import 'package:photos/repositories/file_repository.dart'; @@ -47,6 +48,7 @@ class _HomeWidgetState extends State { int _selectedNavBarItem = 0; StreamSubscription _localPhotosUpdatedEventSubscription; + StreamSubscription _tabChangedEventSubscription; @override void initState() { @@ -60,6 +62,12 @@ class _HomeWidgetState extends State { Bus.instance.on().listen((event) { setState(() {}); }); + _tabChangedEventSubscription = + Bus.instance.on().listen((event) { + setState(() { + _selectedNavBarItem = event.selectedIndex; + }); + }); _initDeepLinks(); super.initState(); } @@ -211,6 +219,7 @@ class _HomeWidgetState extends State { void dispose() { _detector.stopListening(); _localPhotosUpdatedEventSubscription.cancel(); + _tabChangedEventSubscription.cancel(); super.dispose(); } } diff --git a/lib/utils/toast_util.dart b/lib/utils/toast_util.dart index 72ad1bb7a..30ef2b38f 100644 --- a/lib/utils/toast_util.dart +++ b/lib/utils/toast_util.dart @@ -1,13 +1,13 @@ import 'package:flutter/material.dart'; import 'package:fluttertoast/fluttertoast.dart'; -void showToast(String message, {toastLength: Toast.LENGTH_SHORT}) { - Fluttertoast.showToast( +Future showToast(String message, {toastLength: Toast.LENGTH_SHORT}) { + return Fluttertoast.showToast( msg: message, toastLength: toastLength, gravity: ToastGravity.BOTTOM, timeInSecForIosWeb: 1, - backgroundColor: Colors.grey[850], + backgroundColor: Colors.grey[800], textColor: Colors.white, fontSize: 16.0); }