mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-03-24 16:04:43 +01:00
Sort photos in album by time in asc/desc order
This commit is contained in:
parent
2b555598db
commit
7644a23f44
3 changed files with 139 additions and 18 deletions
|
@ -534,6 +534,19 @@
|
||||||
"@genericProcessingDialogContent": {
|
"@genericProcessingDialogContent": {
|
||||||
"description": "Generic dialog shown when the app is temporarily blocking user input to work on something"
|
"description": "Generic dialog shown when the app is temporarily blocking user input to work on something"
|
||||||
},
|
},
|
||||||
|
"sortTooltip": "Sort",
|
||||||
|
"sortOptionDialogTitle": "Sort by",
|
||||||
|
"@sortOptionDialogTitle": {
|
||||||
|
"description": "Select how the photos should be sorted"
|
||||||
|
},
|
||||||
|
"sortOptionTimeAscendingLabel": "Oldest first",
|
||||||
|
"@sortOptionTimeAscendingLabel": {
|
||||||
|
"description": "Sort by time, in ascending order"
|
||||||
|
},
|
||||||
|
"sortOptionTimeDescendingLabel": "Newest first",
|
||||||
|
"@sortOptionTimeDescendingLabel": {
|
||||||
|
"description": "Sort by time, in descending order"
|
||||||
|
},
|
||||||
|
|
||||||
"changelogTitle": "Changelog",
|
"changelogTitle": "Changelog",
|
||||||
"@changelogTitle": {
|
"@changelogTitle": {
|
||||||
|
|
|
@ -86,28 +86,44 @@ class _AlbumViewerState extends State<AlbumViewer>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
enterEditMode() {
|
||||||
|
super.enterEditMode();
|
||||||
|
_editAlbum = _album.copyWith();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
doneEditMode() {
|
doneEditMode() {
|
||||||
if (_editFormKey?.currentState?.validate() == true) {
|
if (_editFormKey?.currentState?.validate() == true) {
|
||||||
_editFormKey.currentState.save();
|
try {
|
||||||
final newAlbum = makeEdited(_album);
|
// persist the changes
|
||||||
if (newAlbum.copyWith(lastUpdated: _album.lastUpdated) != _album) {
|
_editFormKey.currentState.save();
|
||||||
_log.info("[doneEditMode] Album modified: $newAlbum");
|
final newAlbum = makeEdited(_editAlbum);
|
||||||
final albumRepo = AlbumRepo(AlbumCachedDataSource());
|
if (newAlbum.copyWith(lastUpdated: _album.lastUpdated) != _album) {
|
||||||
|
_log.info("[doneEditMode] Album modified: $newAlbum");
|
||||||
|
final albumRepo = AlbumRepo(AlbumCachedDataSource());
|
||||||
|
setState(() {
|
||||||
|
_album = newAlbum;
|
||||||
|
});
|
||||||
|
UpdateAlbum(albumRepo)(widget.account, newAlbum)
|
||||||
|
.catchError((e, stacktrace) {
|
||||||
|
SnackBarManager().showSnackBar(SnackBar(
|
||||||
|
content: Text(exception_util.toUserString(e, context)),
|
||||||
|
duration: k.snackBarDurationNormal,
|
||||||
|
));
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
_log.fine("[doneEditMode] Album not modified");
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} finally {
|
||||||
setState(() {
|
setState(() {
|
||||||
_album = newAlbum;
|
// reset edits
|
||||||
|
_editAlbum = null;
|
||||||
|
// update the list to show the real album
|
||||||
|
_transformItems();
|
||||||
});
|
});
|
||||||
UpdateAlbum(albumRepo)(widget.account, newAlbum)
|
|
||||||
.catchError((e, stacktrace) {
|
|
||||||
SnackBarManager().showSnackBar(SnackBar(
|
|
||||||
content: Text(exception_util.toUserString(e, context)),
|
|
||||||
duration: k.snackBarDurationNormal,
|
|
||||||
));
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
_log.fine("[doneEditMode] Album not modified");
|
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -192,7 +208,13 @@ class _AlbumViewerState extends State<AlbumViewer>
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildEditAppBar(BuildContext context) {
|
Widget _buildEditAppBar(BuildContext context) {
|
||||||
return buildEditAppBar(context, widget.account, widget.album);
|
return buildEditAppBar(context, widget.account, widget.album, actions: [
|
||||||
|
IconButton(
|
||||||
|
icon: Icon(Icons.sort_by_alpha),
|
||||||
|
tooltip: AppLocalizations.of(context).sortTooltip,
|
||||||
|
onPressed: _onEditAppBarSortPressed,
|
||||||
|
),
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onItemTap(int index) {
|
void _onItemTap(int index) {
|
||||||
|
@ -247,8 +269,88 @@ class _AlbumViewerState extends State<AlbumViewer>
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _onEditAppBarSortPressed() {
|
||||||
|
final sortProvider = _editAlbum.sortProvider;
|
||||||
|
final isOldest =
|
||||||
|
sortProvider is AlbumTimeSortProvider && sortProvider.isAscending;
|
||||||
|
final isNewest =
|
||||||
|
sortProvider is AlbumTimeSortProvider && !sortProvider.isAscending;
|
||||||
|
final activeTextStyle = TextStyle(
|
||||||
|
color: Theme.of(context).colorScheme.primary,
|
||||||
|
);
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (context) => SimpleDialog(
|
||||||
|
title: Text(AppLocalizations.of(context).sortOptionDialogTitle),
|
||||||
|
children: [
|
||||||
|
SimpleDialogOption(
|
||||||
|
child: ListTile(
|
||||||
|
leading: Icon(
|
||||||
|
isOldest ? Icons.check : null,
|
||||||
|
color: Theme.of(context).colorScheme.primary,
|
||||||
|
),
|
||||||
|
title: Text(
|
||||||
|
AppLocalizations.of(context).sortOptionTimeAscendingLabel,
|
||||||
|
style: isOldest ? activeTextStyle : null,
|
||||||
|
),
|
||||||
|
onTap: isOldest
|
||||||
|
? null
|
||||||
|
: () {
|
||||||
|
_onSortOldestPressed();
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SimpleDialogOption(
|
||||||
|
child: ListTile(
|
||||||
|
leading: Icon(
|
||||||
|
isNewest ? Icons.check : null,
|
||||||
|
color: Theme.of(context).colorScheme.primary,
|
||||||
|
),
|
||||||
|
title: Text(
|
||||||
|
AppLocalizations.of(context).sortOptionTimeDescendingLabel,
|
||||||
|
style: isNewest ? activeTextStyle : null,
|
||||||
|
),
|
||||||
|
onTap: isNewest
|
||||||
|
? null
|
||||||
|
: () {
|
||||||
|
_onSortNewestPressed();
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _onSortOldestPressed() {
|
||||||
|
_editAlbum = _editAlbum.copyWith(
|
||||||
|
sortProvider: AlbumTimeSortProvider(isAscending: true),
|
||||||
|
);
|
||||||
|
setState(() {
|
||||||
|
_transformItems();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void _onSortNewestPressed() {
|
||||||
|
_editAlbum = _editAlbum.copyWith(
|
||||||
|
sortProvider: AlbumTimeSortProvider(isAscending: false),
|
||||||
|
);
|
||||||
|
setState(() {
|
||||||
|
_transformItems();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void _transformItems() {
|
void _transformItems() {
|
||||||
_backingFiles = _album.sortProvider.sort(_getAlbumItemsOf(_album))
|
List<AlbumItem> sortedItems;
|
||||||
|
if (_editAlbum != null) {
|
||||||
|
// edit mode
|
||||||
|
sortedItems = _editAlbum.sortProvider.sort(_getAlbumItemsOf(_editAlbum));
|
||||||
|
} else {
|
||||||
|
sortedItems = _album.sortProvider.sort(_getAlbumItemsOf(_album));
|
||||||
|
}
|
||||||
|
_backingFiles = sortedItems
|
||||||
.whereType<AlbumFileItem>()
|
.whereType<AlbumFileItem>()
|
||||||
.map((e) => e.file)
|
.map((e) => e.file)
|
||||||
.where((element) => file_util.isSupportedFormat(element))
|
.where((element) => file_util.isSupportedFormat(element))
|
||||||
|
@ -316,6 +418,7 @@ class _AlbumViewerState extends State<AlbumViewer>
|
||||||
var _backingFiles = <File>[];
|
var _backingFiles = <File>[];
|
||||||
|
|
||||||
final _editFormKey = GlobalKey<FormState>();
|
final _editFormKey = GlobalKey<FormState>();
|
||||||
|
Album _editAlbum;
|
||||||
|
|
||||||
static final _log = Logger("widget.album_viewer._AlbumViewerState");
|
static final _log = Logger("widget.album_viewer._AlbumViewerState");
|
||||||
}
|
}
|
||||||
|
|
|
@ -182,6 +182,10 @@ mixin AlbumViewerMixin<T extends StatefulWidget>
|
||||||
@protected
|
@protected
|
||||||
get isEditMode => _isEditMode;
|
get isEditMode => _isEditMode;
|
||||||
|
|
||||||
|
@protected
|
||||||
|
@mustCallSuper
|
||||||
|
void enterEditMode() {}
|
||||||
|
|
||||||
@protected
|
@protected
|
||||||
bool doneEditMode();
|
bool doneEditMode();
|
||||||
|
|
||||||
|
@ -211,6 +215,7 @@ mixin AlbumViewerMixin<T extends StatefulWidget>
|
||||||
void _onAppBarEditPressed(BuildContext context, Album album) {
|
void _onAppBarEditPressed(BuildContext context, Album album) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_isEditMode = true;
|
_isEditMode = true;
|
||||||
|
enterEditMode();
|
||||||
_editNameValue = album.name;
|
_editNameValue = album.name;
|
||||||
_editFormValue = _EditFormValue();
|
_editFormValue = _EditFormValue();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue