fixed album order in drawer

This commit is contained in:
Thibault Deckers 2019-09-15 20:31:06 +09:00
parent b4d9863dda
commit 46928d8458
5 changed files with 25 additions and 12 deletions

View file

@ -11,7 +11,8 @@ class ImageCollection with ChangeNotifier {
Map<dynamic, List<ImageEntry>> sections = Map();
GroupFactor groupFactor = GroupFactor.date;
SortFactor sortFactor = SortFactor.date;
Set<String> albums = Set(), tags = Set();
List<String> sortedAlbums = List.unmodifiable(Iterable.empty());
List<String> sortedTags = List.unmodifiable(Iterable.empty());
ImageCollection({
@required List<ImageEntry> entries,
@ -25,9 +26,9 @@ class ImageCollection with ChangeNotifier {
int get videoCount => _rawEntries.where((entry) => entry.isVideo).length;
int get albumCount => albums.length;
int get albumCount => sortedAlbums.length;
int get tagCount => tags.length;
int get tagCount => sortedTags.length;
List<ImageEntry> get sortedEntries => List.unmodifiable(sections.entries.expand((e) => e.value));
@ -83,9 +84,22 @@ class ImageCollection with ChangeNotifier {
return success;
}
updateAlbums() => albums = _rawEntries.map((entry) => entry.directory).toSet();
updateAlbums() {
Set<String> albums = _rawEntries.map((entry) => entry.directory).toSet();
List<String> sorted = albums.toList()
..sort((a, b) {
final ua = getUniqueAlbumName(a, albums);
final ub = getUniqueAlbumName(b, albums);
return compareAsciiUpperCase(ua, ub);
});
sortedAlbums = List.unmodifiable(sorted);
}
updateTags() => tags = _rawEntries.expand((entry) => entry.xmpSubjects).toSet();
updateTags() {
Set<String> tags = _rawEntries.expand((entry) => entry.xmpSubjects).toSet();
List<String> sorted = tags.toList()..sort(compareAsciiUpperCase);
sortedTags = List.unmodifiable(sorted);
}
onMetadataChanged() {
// metadata dates impact sorting and grouping
@ -155,7 +169,7 @@ class ImageCollection with ChangeNotifier {
);
}
String getUniqueAlbumName(String album, List albums) {
String getUniqueAlbumName(String album, Iterable<String> albums) {
final otherAlbums = albums.where((item) => item != album);
final parts = album.split(separator);
int partCount = 0;

View file

@ -63,7 +63,7 @@ class Settings {
bool getBoolOrDefault(String key, bool defaultValue) => prefs.getKeys().contains(key) ? prefs.getBool(key) : defaultValue;
T getEnumOrDefault<T>(String key, T defaultValue, List<T> values) {
T getEnumOrDefault<T>(String key, T defaultValue, Iterable<T> values) {
final valueString = prefs.getString(key);
for (T element in values) {
if (element.toString() == valueString) {

View file

@ -2,7 +2,6 @@ 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/common/icons.dart';
import 'package:collection/collection.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
@ -13,8 +12,8 @@ class AllCollectionDrawer extends StatelessWidget {
@override
Widget build(BuildContext context) {
final albums = collection.albums.toList()..sort(compareAsciiUpperCaseNatural);
final tags = collection.tags.toList()..sort(compareAsciiUpperCaseNatural);
final albums = collection.sortedAlbums;
final tags = collection.sortedTags;
return Drawer(
child: ListView(
padding: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom),

View file

@ -118,7 +118,7 @@ class SectionSliver extends StatelessWidget {
}
header = SectionHeader(
leading: albumIcon,
title: collection.getUniqueAlbumName(sectionKey, sections.keys.toList()),
title: collection.getUniqueAlbumName(sectionKey, sections.keys.cast<String>()),
);
break;
case GroupFactor.date:

View file

@ -81,7 +81,7 @@ class MetadataSectionState extends State<MetadataSection> {
);
}
Widget getMetadataColumn(Map<String, Map> metadataMap, List<String> directoryNames) {
Widget getMetadataColumn(Map<String, Map> metadataMap, Iterable<String> directoryNames) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [