|
@@ -1,16 +1,13 @@
|
|
|
-import 'dart:io';
|
|
|
-
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
import 'package:flutter/material.dart';
|
|
|
import 'package:flutter/widgets.dart';
|
|
|
-import 'package:logger/logger.dart';
|
|
|
-import 'package:myapp/db/db_helper.dart';
|
|
|
import 'package:myapp/models/photo.dart';
|
|
|
import 'package:myapp/photo_loader.dart';
|
|
|
+import 'package:myapp/ui/album_list_widget.dart';
|
|
|
+import 'package:myapp/ui/change_notifier_builder.dart';
|
|
|
+import 'package:myapp/ui/gallery_app_bar_widget.dart';
|
|
|
+import 'package:myapp/ui/gallery_container_widget.dart';
|
|
|
import 'package:provider/provider.dart';
|
|
|
-import 'package:share_extend/share_extend.dart';
|
|
|
-
|
|
|
-import 'gallery_container_widget.dart';
|
|
|
|
|
|
class HomeWidget extends StatefulWidget {
|
|
|
final String title;
|
|
@@ -32,18 +29,34 @@ class _HomeWidgetState extends State<HomeWidget> {
|
|
|
title: widget.title,
|
|
|
theme: ThemeData.dark(),
|
|
|
home: Scaffold(
|
|
|
- appBar: _buildAppBar(context),
|
|
|
- bottomNavigationBar: _buildBottomNavigationBar(),
|
|
|
- body: GalleryContainer(
|
|
|
- _selectedNavBarItem == 0
|
|
|
- ? GalleryType.important_photos
|
|
|
- : GalleryType.all_photos,
|
|
|
- photoSelectionChangeCallback: (Set<Photo> selectedPhotos) {
|
|
|
+ appBar: GalleryAppBarWidget(
|
|
|
+ widget.title,
|
|
|
+ _selectedPhotos,
|
|
|
+ onSelectionClear: () {
|
|
|
setState(() {
|
|
|
- _selectedPhotos = selectedPhotos;
|
|
|
+ _selectedPhotos.clear();
|
|
|
});
|
|
|
},
|
|
|
),
|
|
|
+ bottomNavigationBar: _buildBottomNavigationBar(),
|
|
|
+ body: IndexedStack(
|
|
|
+ children: <Widget>[
|
|
|
+ GalleryContainer(
|
|
|
+ photoSelectionChangeCallback: (Set<Photo> selectedPhotos) {
|
|
|
+ setState(() {
|
|
|
+ _selectedPhotos = selectedPhotos;
|
|
|
+ });
|
|
|
+ },
|
|
|
+ ),
|
|
|
+ ChangeNotifierBuilder(
|
|
|
+ value: photoLoader,
|
|
|
+ builder: (_, __) {
|
|
|
+ return AlbumListWidget(photoLoader.photos);
|
|
|
+ },
|
|
|
+ )
|
|
|
+ ],
|
|
|
+ index: _selectedNavBarItem,
|
|
|
+ ),
|
|
|
),
|
|
|
);
|
|
|
}
|
|
@@ -69,96 +82,4 @@ class _HomeWidgetState extends State<HomeWidget> {
|
|
|
},
|
|
|
);
|
|
|
}
|
|
|
-
|
|
|
- Widget _buildAppBar(BuildContext context) {
|
|
|
- if (_selectedPhotos.isEmpty) {
|
|
|
- return AppBar(title: Text(widget.title));
|
|
|
- }
|
|
|
-
|
|
|
- return AppBar(
|
|
|
- leading: IconButton(
|
|
|
- icon: Icon(Icons.close),
|
|
|
- onPressed: () {
|
|
|
- setState(() {
|
|
|
- _selectedPhotos.clear();
|
|
|
- });
|
|
|
- },
|
|
|
- ),
|
|
|
- title: Text(_selectedPhotos.length.toString()),
|
|
|
- actions: _getActions(context),
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
- List<Widget> _getActions(BuildContext context) {
|
|
|
- List<Widget> actions = List<Widget>();
|
|
|
- if (_selectedPhotos.isNotEmpty) {
|
|
|
- actions.add(IconButton(
|
|
|
- icon: Icon(Icons.delete),
|
|
|
- onPressed: () {
|
|
|
- _showDeletePhotosSheet(context);
|
|
|
- },
|
|
|
- ));
|
|
|
- actions.add(IconButton(
|
|
|
- icon: Icon(Icons.share),
|
|
|
- onPressed: () {
|
|
|
- _shareSelectedPhotos(context);
|
|
|
- },
|
|
|
- ));
|
|
|
- }
|
|
|
- return actions;
|
|
|
- }
|
|
|
-
|
|
|
- void _shareSelectedPhotos(BuildContext context) {
|
|
|
- var photoPaths = List<String>();
|
|
|
- for (Photo photo in _selectedPhotos) {
|
|
|
- photoPaths.add(photo.localPath);
|
|
|
- }
|
|
|
- ShareExtend.shareMultiple(photoPaths, "image");
|
|
|
- }
|
|
|
-
|
|
|
- void _showDeletePhotosSheet(BuildContext context) {
|
|
|
- final action = CupertinoActionSheet(
|
|
|
- actions: <Widget>[
|
|
|
- CupertinoActionSheetAction(
|
|
|
- child: Text("Delete on device"),
|
|
|
- isDestructiveAction: true,
|
|
|
- onPressed: () async {
|
|
|
- for (Photo photo in _selectedPhotos) {
|
|
|
- await DatabaseHelper.instance.deletePhoto(photo);
|
|
|
- File file = File(photo.localPath);
|
|
|
- await file.delete();
|
|
|
- }
|
|
|
- photoLoader.reloadPhotos();
|
|
|
- setState(() {
|
|
|
- _selectedPhotos.clear();
|
|
|
- });
|
|
|
- Navigator.pop(context);
|
|
|
- },
|
|
|
- ),
|
|
|
- CupertinoActionSheetAction(
|
|
|
- child: Text("Delete everywhere [WiP]"),
|
|
|
- isDestructiveAction: true,
|
|
|
- onPressed: () async {
|
|
|
- for (Photo photo in _selectedPhotos) {
|
|
|
- await DatabaseHelper.instance.markPhotoAsDeleted(photo);
|
|
|
- File file = File(photo.localPath);
|
|
|
- await file.delete();
|
|
|
- }
|
|
|
- photoLoader.reloadPhotos();
|
|
|
- setState(() {
|
|
|
- _selectedPhotos.clear();
|
|
|
- });
|
|
|
- Navigator.pop(context);
|
|
|
- },
|
|
|
- )
|
|
|
- ],
|
|
|
- cancelButton: CupertinoActionSheetAction(
|
|
|
- child: Text("Cancel"),
|
|
|
- onPressed: () {
|
|
|
- Navigator.pop(context);
|
|
|
- },
|
|
|
- ),
|
|
|
- );
|
|
|
- showCupertinoModalPopup(context: context, builder: (_) => action);
|
|
|
- }
|
|
|
}
|