mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-01-23 01:06:21 +01:00
Ensure isEditMode is false when calling done
This commit is contained in:
parent
a07fb0d9a4
commit
8eef2a2084
3 changed files with 54 additions and 51 deletions
|
@ -104,40 +104,39 @@ class _AlbumViewerState extends State<AlbumViewer>
|
|||
}
|
||||
}
|
||||
|
||||
@override
|
||||
validateEditMode() => _editFormKey?.currentState?.validate() == true;
|
||||
|
||||
@override
|
||||
doneEditMode() {
|
||||
if (_editFormKey?.currentState?.validate() == true) {
|
||||
try {
|
||||
// persist the changes
|
||||
_editFormKey.currentState.save();
|
||||
final newAlbum = makeEdited(_editAlbum);
|
||||
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 {
|
||||
try {
|
||||
// persist the changes
|
||||
_editFormKey.currentState.save();
|
||||
final newAlbum = makeEdited(_editAlbum);
|
||||
if (newAlbum.copyWith(lastUpdated: _album.lastUpdated) != _album) {
|
||||
_log.info("[doneEditMode] Album modified: $newAlbum");
|
||||
final albumRepo = AlbumRepo(AlbumCachedDataSource());
|
||||
setState(() {
|
||||
// reset edits
|
||||
_editAlbum = null;
|
||||
// update the list to show the real album
|
||||
_transformItems();
|
||||
_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");
|
||||
}
|
||||
} finally {
|
||||
setState(() {
|
||||
// reset edits
|
||||
_editAlbum = null;
|
||||
// update the list to show the real album
|
||||
_transformItems();
|
||||
});
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void _initAlbum() {
|
||||
|
|
|
@ -168,10 +168,11 @@ mixin AlbumViewerMixin<T extends StatefulWidget>
|
|||
color: Theme.of(context).colorScheme.primary,
|
||||
tooltip: AppLocalizations.of(context).doneButtonTooltip,
|
||||
onPressed: () {
|
||||
if (doneEditMode()) {
|
||||
if (validateEditMode()) {
|
||||
setState(() {
|
||||
_isEditMode = false;
|
||||
});
|
||||
doneEditMode();
|
||||
}
|
||||
},
|
||||
),
|
||||
|
@ -186,8 +187,12 @@ mixin AlbumViewerMixin<T extends StatefulWidget>
|
|||
@mustCallSuper
|
||||
void enterEditMode() {}
|
||||
|
||||
/// Validates the pending modifications
|
||||
@protected
|
||||
bool doneEditMode();
|
||||
bool validateEditMode();
|
||||
|
||||
@protected
|
||||
void doneEditMode();
|
||||
|
||||
/// Return a new album with the edits
|
||||
@protected
|
||||
|
|
|
@ -90,30 +90,29 @@ class _DynamicAlbumViewerState extends State<DynamicAlbumViewer>
|
|||
);
|
||||
}
|
||||
|
||||
@override
|
||||
validateEditMode() => _editFormKey?.currentState?.validate() == true;
|
||||
|
||||
@override
|
||||
doneEditMode() {
|
||||
if (_editFormKey?.currentState?.validate() == true) {
|
||||
_editFormKey.currentState.save();
|
||||
final newAlbum = makeEdited(_album);
|
||||
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;
|
||||
_editFormKey.currentState.save();
|
||||
final newAlbum = makeEdited(_album);
|
||||
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 false;
|
||||
}
|
||||
|
||||
void _initAlbum() {
|
||||
|
|
Loading…
Reference in a new issue