home: added albums/tags items to drawer

This commit is contained in:
Thibault Deckers 2019-08-30 01:03:36 +09:00
parent 86e0c1b081
commit f73c72973a
7 changed files with 111 additions and 60 deletions

View file

@ -64,9 +64,11 @@ class _HomePageState extends State<HomePage> {
(entryMap) => localMediaCollection.add(ImageEntry.fromMap(entryMap)),
onDone: () async {
debugPrint('mediastore stream done');
localMediaCollection.updateAlbums();
await localMediaCollection.loadCatalogMetadata();
setState(() {});
await localMediaCollection.catalogEntries();
localMediaCollection.updateTags();
setState(() {});
await localMediaCollection.loadAddresses();
await localMediaCollection.locateEntries();

View file

@ -9,6 +9,7 @@ class ImageCollection with ChangeNotifier {
final List<ImageEntry> _rawEntries;
GroupFactor groupFactor = GroupFactor.date;
SortFactor sortFactor = SortFactor.date;
Set<String> albums = Set(), tags = Set();
ImageCollection({
@required List<ImageEntry> entries,
@ -20,9 +21,9 @@ class ImageCollection with ChangeNotifier {
int get videoCount => _rawEntries.where((entry) => entry.isVideo).length;
int get albumCount => 42;
int get albumCount => albums.length;
int get tagCount => 42;
int get tagCount => tags.length;
Map<dynamic, List<ImageEntry>> get sections {
switch (sortFactor) {
@ -75,6 +76,10 @@ class ImageCollection with ChangeNotifier {
return success;
}
updateAlbums() => albums = _rawEntries.map((entry) => entry.bucketDisplayName).toSet();
updateTags() => tags = _rawEntries.expand((entry) => entry.xmpSubjects).toSet();
loadCatalogMetadata() async {
debugPrint('$runtimeType loadCatalogMetadata start');
final start = DateTime.now();

View file

@ -1,6 +1,7 @@
import 'package:aves/model/image_collection.dart';
import 'package:aves/model/image_entry.dart';
import 'package:aves/widgets/album/filtered_collection_page.dart';
import 'package:collection/collection.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
@ -11,15 +12,13 @@ class AllCollectionDrawer extends StatelessWidget {
@override
Widget build(BuildContext context) {
final albums = collection.albums.toList()..sort(compareAsciiUpperCaseNatural);
final tags = collection.tags.toList()..sort(compareAsciiUpperCaseNatural);
return Drawer(
child: ListView(
padding: EdgeInsets.zero,
padding: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom),
children: [
DrawerHeader(
child: DefaultTextStyle(
style: TextStyle(
color: Colors.white,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
@ -71,20 +70,41 @@ class AllCollectionDrawer extends StatelessWidget {
],
),
],
)),
),
decoration: BoxDecoration(
color: Theme.of(context).accentColor,
),
),
_buildFilteredCollectionNavTile(context, 'Videos', (entry) => entry.isVideo),
_buildFilteredCollectionNavTile(
context: context,
leading: Icon(Icons.video_library),
title: 'Videos',
filter: (entry) => entry.isVideo,
),
Divider(),
...albums.map((album) => _buildFilteredCollectionNavTile(
context: context,
leading: Icon(Icons.photo_library),
title: album,
filter: (entry) => entry.bucketDisplayName == album,
)),
Divider(),
...tags.map((tag) => _buildFilteredCollectionNavTile(
context: context,
leading: Icon(Icons.label_outline),
title: tag,
filter: (entry) => entry.xmpSubjects.contains(tag),
)),
],
),
);
}
_buildFilteredCollectionNavTile(BuildContext context, String title, bool Function(ImageEntry) filter) {
_buildFilteredCollectionNavTile({BuildContext context, Widget leading, String title, bool Function(ImageEntry) filter}) {
return ListTile(
leading: leading,
title: Text(title),
dense: true,
onTap: () {
Navigator.pop(context);
Navigator.push(

View file

@ -22,6 +22,7 @@ class FilteredCollectionPage extends StatelessWidget {
floating: true,
),
),
resizeToAvoidBottomInset: false,
);
}
}

View file

@ -163,7 +163,7 @@ class FullscreenBodyState extends State<FullscreenBody> with SingleTickerProvide
if (notification is BackUpNotification) goToVerticalPage(0);
return false;
},
child: InfoPage(entry: entry),
child: InfoPage(collection: collection, entry: entry),
),
],
),

View file

@ -1,3 +1,4 @@
import 'package:aves/model/image_collection.dart';
import 'package:aves/model/image_entry.dart';
import 'package:aves/utils/file_utils.dart';
import 'package:aves/widgets/fullscreen/info/location_section.dart';
@ -7,9 +8,14 @@ import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
class InfoPage extends StatefulWidget {
final ImageCollection collection;
final ImageEntry entry;
const InfoPage({this.entry});
const InfoPage({
Key key,
@required this.collection,
@required this.entry,
}) : super(key: key);
@override
State<StatefulWidget> createState() => InfoPageState();
@ -52,7 +58,7 @@ class InfoPageState extends State<InfoPage> {
InfoRow('Size', formatFilesize(entry.sizeBytes)),
InfoRow('Path', entry.path),
LocationSection(entry: entry),
XmpTagSection(entry: entry),
XmpTagSection(collection: widget.collection, entry: entry),
MetadataSection(entry: entry),
],
),

View file

@ -1,11 +1,18 @@
import 'package:aves/model/image_collection.dart';
import 'package:aves/model/image_entry.dart';
import 'package:aves/widgets/album/filtered_collection_page.dart';
import 'package:aves/widgets/fullscreen/info/info_page.dart';
import 'package:flutter/material.dart';
class XmpTagSection extends AnimatedWidget {
final ImageCollection collection;
final ImageEntry entry;
const XmpTagSection({Key key, this.entry}) : super(key: key, listenable: entry);
const XmpTagSection({
Key key,
@required this.collection,
@required this.entry,
}) : super(key: key, listenable: entry);
@override
Widget build(BuildContext context) {
@ -20,9 +27,19 @@ class XmpTagSection extends AnimatedWidget {
children: tags
.map((tag) => Padding(
padding: EdgeInsets.symmetric(horizontal: 4.0),
child: Chip(
backgroundColor: Theme.of(context).accentColor,
child: ActionChip(
label: Text(tag),
onPressed: () => Navigator.push(
context,
MaterialPageRoute(
builder: (context) => FilteredCollectionPage(
collection: collection,
filter: (entry) => entry.xmpSubjects.contains(tag),
title: tag,
),
),
),
backgroundColor: Theme.of(context).accentColor,
),
))
.toList(),