Merge pull request #32 from ente-io/album_sorting
Add option to sort album by name, recent photo & last updated time
This commit is contained in:
commit
49a42cf2ac
2 changed files with 49 additions and 35 deletions
|
@ -152,38 +152,7 @@ class _CollectionsGalleryWidgetState extends State<CollectionsGalleryWidget>
|
|||
),
|
||||
Padding(padding: EdgeInsets.all(4)),
|
||||
Divider(),
|
||||
PopupMenuButton(
|
||||
offset: Offset(10, 40),
|
||||
initialValue: sortKey?.index ?? 0,
|
||||
child: Align(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
Text(sortKey.toString(),
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 12,
|
||||
color: Theme.of(context).buttonColor,
|
||||
),
|
||||
),
|
||||
Padding(padding: EdgeInsets.only(left: 5.0)),
|
||||
Icon(Icons.sort_outlined),
|
||||
],
|
||||
)),
|
||||
onSelected: (int index) {
|
||||
setState(() {
|
||||
sortKey = AlbumSortKey.values[index];
|
||||
});
|
||||
},
|
||||
itemBuilder: (context) {
|
||||
return List.generate(AlbumSortKey.values.length, (index) {
|
||||
return PopupMenuItem(
|
||||
value: index,
|
||||
child: Text('${AlbumSortKey.values[index]}'),
|
||||
);
|
||||
});
|
||||
},
|
||||
),
|
||||
_sortMenu(),
|
||||
SectionTitle("on ente"),
|
||||
Padding(padding: EdgeInsets.all(12)),
|
||||
Configuration.instance.hasConfiguredAccount()
|
||||
|
@ -209,6 +178,52 @@ class _CollectionsGalleryWidgetState extends State<CollectionsGalleryWidget>
|
|||
);
|
||||
}
|
||||
|
||||
PopupMenuButton<int> _sortMenu() {
|
||||
String sortOptionText(AlbumSortKey key) {
|
||||
switch (key) {
|
||||
case AlbumSortKey.albumName:
|
||||
return "album name";
|
||||
case AlbumSortKey.lastUpdated:
|
||||
return "last updated";
|
||||
case AlbumSortKey.recentPhoto:
|
||||
return "recent photo";
|
||||
}
|
||||
return key.toString();
|
||||
}
|
||||
return PopupMenuButton(
|
||||
offset: Offset(10, 40),
|
||||
initialValue: sortKey?.index ?? 0,
|
||||
child: Align(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
Text(sortOptionText(sortKey),
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 14,
|
||||
color: Theme.of(context).buttonColor,
|
||||
),
|
||||
),
|
||||
Padding(padding: EdgeInsets.only(left: 5.0)),
|
||||
Icon(Icons.sort_outlined),
|
||||
],
|
||||
)),
|
||||
onSelected: (int index) {
|
||||
setState(() {
|
||||
sortKey = AlbumSortKey.values[index];
|
||||
});
|
||||
},
|
||||
itemBuilder: (context) {
|
||||
return List.generate(AlbumSortKey.values.length, (index) {
|
||||
return PopupMenuItem(
|
||||
value: index,
|
||||
child: Text(sortOptionText(AlbumSortKey.values[index])),
|
||||
);
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildCollection(BuildContext context,
|
||||
List<CollectionWithThumbnail> collections, int index) {
|
||||
if (index < collections.length) {
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
import 'package:logging/logging.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
enum AlbumSortKey {
|
||||
albumName,
|
||||
lastModified,
|
||||
lastUpdated,
|
||||
recentPhoto,
|
||||
}
|
||||
|
||||
|
@ -20,7 +19,7 @@ class LocalSettings {
|
|||
|
||||
AlbumSortKey albumSortKey() {
|
||||
return AlbumSortKey.values[_prefs?.getInt(kCollectionSortPref) ?? 0] ??
|
||||
AlbumSortKey.lastModified;
|
||||
AlbumSortKey.lastUpdated;
|
||||
}
|
||||
|
||||
void setAlbumSortKey(AlbumSortKey key) {
|
||||
|
|
Loading…
Add table
Reference in a new issue