Unify exception snackbar handling

This commit is contained in:
Ming Ming 2024-06-19 14:58:08 +08:00
parent 9bf3e0e7ff
commit fdbb798691
37 changed files with 116 additions and 265 deletions

View file

@ -1,5 +1,6 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:nc_photos/app_localizations.dart';
import 'package:nc_photos/exception.dart';
@ -26,3 +27,25 @@ String toUserString(Object? exception) {
}
return exception?.toString() ?? "Unknown error";
}
(String text, SnackBarAction? action) exceptionToSnackBarData(
Object? exception) {
if (exception is ApiException) {
if (exception.response.statusCode == 401) {
return (L10n.global().errorUnauthenticated, null);
} else if (exception.response.statusCode == 404) {
return ("HTTP 404 not found", null);
} else if (exception.response.statusCode == 423) {
return (L10n.global().errorLocked, null);
} else if (exception.response.statusCode == 500) {
return (L10n.global().errorServerError, null);
}
} else if (exception is SocketException) {
return (L10n.global().errorDisconnected, null);
} else if (exception is InvalidBaseUrlException) {
return (L10n.global().errorInvalidBaseUrl, null);
} else if (exception is AlbumDowngradeException) {
return (L10n.global().errorAlbumDowngrade, null);
}
return (exception?.toString() ?? "Unknown error", null);
}

View file

@ -8,7 +8,6 @@ import 'package:nc_photos/entity/file.dart';
import 'package:nc_photos/entity/file_descriptor.dart';
import 'package:nc_photos/entity/file_util.dart' as file_util;
import 'package:nc_photos/exception.dart';
import 'package:nc_photos/exception_util.dart' as exception_util;
import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/platform/download.dart';
import 'package:nc_photos/snack_bar_manager.dart';
@ -84,10 +83,7 @@ class InternalDownloadHandler {
} catch (e, stacktrace) {
_log.shout(
"[downloadPreviews] Failed while DownloadPreview", e, stacktrace);
SnackBarManager().showSnackBar(SnackBar(
content: Text(exception_util.toUserString(e)),
duration: k.snackBarDurationNormal,
));
SnackBarManager().showSnackBarForException(e);
}
}
return results.toMap();
@ -156,10 +152,7 @@ class InternalDownloadHandler {
} catch (e, stacktrace) {
_log.shout(
"[downloadFiles] Failed while downloadFile", e, stacktrace);
SnackBarManager().showSnackBar(SnackBar(
content: Text(exception_util.toUserString(e)),
duration: k.snackBarDurationNormal,
));
SnackBarManager().showSnackBarForException(e);
}
}
return results.toMap();

View file

@ -9,7 +9,6 @@ import 'package:nc_photos/app_localizations.dart';
import 'package:nc_photos/di_container.dart';
import 'package:nc_photos/entity/file_util.dart' as file_util;
import 'package:nc_photos/exception.dart';
import 'package:nc_photos/exception_util.dart' as exception_util;
import 'package:nc_photos/help_utils.dart' as help_util;
import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/legacy/app_password_exchange_bloc.dart';
@ -121,10 +120,7 @@ class _ConnectState extends State<Connect> {
));
Navigator.of(context).pop(null);
} else {
SnackBarManager().showSnackBar(SnackBar(
content: Text(exception_util.toUserString(state.exception)),
duration: k.snackBarDurationNormal,
));
SnackBarManager().showSnackBarForException(state.exception);
Navigator.of(context).pop(null);
}
}
@ -181,10 +177,7 @@ class _ConnectState extends State<Connect> {
if (e.response.statusCode == 404) {
return _onCheckWebDavUrlFailed(context, account);
}
SnackBarManager().showSnackBar(SnackBar(
content: Text(exception_util.toUserString(e)),
duration: k.snackBarDurationNormal,
));
SnackBarManager().showSnackBarForException(e);
Navigator.of(context).pop(null);
} on StateError catch (_) {
// Nextcloud for some reason doesn't return HTTP error when listing home
@ -192,10 +185,7 @@ class _ConnectState extends State<Connect> {
return _onCheckWebDavUrlFailed(context, account);
} catch (e, stackTrace) {
_log.shout("[_checkWebDavUrl] Failed", e, stackTrace);
SnackBarManager().showSnackBar(SnackBar(
content: Text(exception_util.toUserString(e)),
duration: k.snackBarDurationNormal,
));
SnackBarManager().showSnackBarForException(e);
Navigator.of(context).pop(null);
}
}

View file

@ -6,9 +6,7 @@ import 'package:nc_photos/account.dart';
import 'package:nc_photos/di_container.dart';
import 'package:nc_photos/entity/file.dart';
import 'package:nc_photos/entity/file_descriptor.dart';
import 'package:nc_photos/exception_util.dart' as exception_util;
import 'package:nc_photos/internal_download_handler.dart';
import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/mobile/share.dart';
import 'package:nc_photos/snack_bar_manager.dart';
import 'package:nc_photos/use_case/inflate_file_descriptor.dart';
@ -41,10 +39,7 @@ class SetAsHandler {
}
} catch (e, stackTrace) {
_log.shout("[setAsFile] Failed while sharing files", e, stackTrace);
SnackBarManager().showSnackBar(SnackBar(
content: Text(exception_util.toUserString(e)),
duration: k.snackBarDurationNormal,
));
SnackBarManager().showSnackBarForException(e);
} finally {
if (!isSelectionCleared) {
clearSelection?.call();

View file

@ -16,7 +16,6 @@ import 'package:nc_photos/entity/file_util.dart' as file_util;
import 'package:nc_photos/entity/local_file.dart';
import 'package:nc_photos/entity/share.dart';
import 'package:nc_photos/entity/share/data_source.dart';
import 'package:nc_photos/exception_util.dart' as exception_util;
import 'package:nc_photos/internal_download_handler.dart';
import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/mobile/share.dart';
@ -62,10 +61,7 @@ class ShareHandler {
e,
stackTrace);
if (!hasShownError) {
SnackBarManager().showSnackBar(SnackBar(
content: Text(exception_util.toUserString(e)),
duration: k.snackBarDurationNormal,
));
SnackBarManager().showSnackBarForException(e);
hasShownError = true;
}
}
@ -91,10 +87,7 @@ class ShareHandler {
}
} catch (e, stackTrace) {
_log.shout("[shareFiles] Failed while sharing files", e, stackTrace);
SnackBarManager().showSnackBar(SnackBar(
content: Text(exception_util.toUserString(e)),
duration: k.snackBarDurationNormal,
));
SnackBarManager().showSnackBarForException(e);
} finally {
if (!isSelectionCleared) {
clearSelection?.call();
@ -199,10 +192,7 @@ class ShareHandler {
} catch (e, stackTrace) {
_log.shout(
"[_shareFileAsLink] Failed while CreateLinkShare", e, stackTrace);
SnackBarManager().showSnackBar(SnackBar(
content: Text(exception_util.toUserString(e)),
duration: k.snackBarDurationNormal,
));
SnackBarManager().showSnackBarForException(e);
}
}

View file

@ -2,6 +2,8 @@ import 'dart:collection';
import 'package:flutter/material.dart';
import 'package:logging/logging.dart';
import 'package:nc_photos/exception_util.dart';
import 'package:nc_photos/k.dart' as k;
import 'package:np_codegen/np_codegen.dart';
part 'snack_bar_manager.g.dart';
@ -40,6 +42,15 @@ class SnackBarManager {
_ensureRunning();
}
void showSnackBarForException(Object? exception) {
final (text, action) = exceptionToSnackBarData(exception);
showSnackBar(SnackBar(
content: Text(text),
action: action,
duration: k.snackBarDurationNormal,
));
}
void _ensureRunning() {
if (!_isRunning) {
_isRunning = true;

View file

@ -16,7 +16,6 @@ import 'package:nc_photos/entity/album/sort_provider.dart';
import 'package:nc_photos/entity/file.dart';
import 'package:nc_photos/entity/file_descriptor.dart';
import 'package:nc_photos/entity/file_util.dart' as file_util;
import 'package:nc_photos/exception_util.dart' as exception_util;
import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/snack_bar_manager.dart';
import 'package:nc_photos/use_case/album/create_album.dart';
@ -210,10 +209,7 @@ class _AlbumImporterState extends State<AlbumImporter> {
state is ListImportableAlbumBlocLoading) {
_transformItems(state.items);
} else if (state is ListImportableAlbumBlocFailure) {
SnackBarManager().showSnackBar(SnackBar(
content: Text(exception_util.toUserString(state.exception)),
duration: k.snackBarDurationNormal,
));
SnackBarManager().showSnackBarForException(state.exception);
}
}
@ -258,10 +254,7 @@ class _AlbumImporterState extends State<AlbumImporter> {
} catch (e, stacktrace) {
_log.shout(
"[_createAllAlbums] Failed creating dir album", e, stacktrace);
SnackBarManager().showSnackBar(SnackBar(
content: Text(exception_util.toUserString(e)),
duration: k.snackBarDurationNormal,
));
SnackBarManager().showSnackBarForException(e);
}
}
}

View file

@ -11,8 +11,6 @@ import 'package:nc_photos/entity/file_descriptor.dart';
import 'package:nc_photos/entity/file_util.dart' as file_util;
import 'package:nc_photos/entity/share.dart';
import 'package:nc_photos/entity/share/data_source.dart';
import 'package:nc_photos/exception_util.dart' as exception_util;
import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/snack_bar_manager.dart';
import 'package:nc_photos/use_case/create_share.dart';
import 'package:nc_photos/use_case/remove_share.dart';
@ -314,10 +312,7 @@ class _AlbumShareOutlierBrowserState extends State<AlbumShareOutlierBrowser> {
_transformItems(state.items);
} else if (state is ListAlbumShareOutlierBlocFailure) {
_transformItems(state.items);
SnackBarManager().showSnackBar(SnackBar(
content: Text(exception_util.toUserString(state.exception)),
duration: k.snackBarDurationNormal,
));
SnackBarManager().showSnackBarForException(state.exception);
}
}
@ -384,10 +379,7 @@ class _AlbumShareOutlierBrowserState extends State<AlbumShareOutlierBrowser> {
} catch (e, stackTrace) {
_log.shout(
"[_fixMissingSharee] Failed while CreateUserShare", e, stackTrace);
SnackBarManager().showSnackBar(SnackBar(
content: Text(exception_util.toUserString(e)),
duration: k.snackBarDurationNormal,
));
SnackBarManager().showSnackBarForException(e);
if (mounted) {
setState(() {
_removeItemStatus(item.file.fdPath, item.shareWith);
@ -412,10 +404,7 @@ class _AlbumShareOutlierBrowserState extends State<AlbumShareOutlierBrowser> {
}
} catch (e, stackTrace) {
_log.shout("[_fixExtraShare] Failed while RemoveShare", e, stackTrace);
SnackBarManager().showSnackBar(SnackBar(
content: Text(exception_util.toUserString(e)),
duration: k.snackBarDurationNormal,
));
SnackBarManager().showSnackBarForException(e);
if (mounted) {
setState(() {
_removeItemStatus(item.file.fdPath, item.share.shareWith!);

View file

@ -15,7 +15,6 @@ import 'package:nc_photos/controller/pref_controller.dart';
import 'package:nc_photos/entity/file_descriptor.dart';
import 'package:nc_photos/entity/file_util.dart' as file_util;
import 'package:nc_photos/exception_event.dart';
import 'package:nc_photos/exception_util.dart' as exception_util;
import 'package:nc_photos/flutter_util.dart' as flutter_util;
import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/snack_bar_manager.dart';
@ -103,10 +102,7 @@ class _WrappedArchiveBrowserState extends State<_WrappedArchiveBrowser>
duration: k.snackBarDurationNormal,
));
} else {
SnackBarManager().showSnackBar(SnackBar(
content: Text(exception_util.toUserString(error.error)),
duration: k.snackBarDurationNormal,
));
SnackBarManager().showSnackBarForException(error.error);
}
}
},

View file

@ -35,7 +35,6 @@ import 'package:nc_photos/entity/file_descriptor.dart';
import 'package:nc_photos/entity/file_util.dart' as file_util;
import 'package:nc_photos/entity/pref.dart';
import 'package:nc_photos/exception_event.dart';
import 'package:nc_photos/exception_util.dart' as exception_util;
import 'package:nc_photos/flutter_util.dart' as flutter_util;
import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/np_api_util.dart';
@ -216,21 +215,23 @@ class _WrappedCollectionBrowserState extends State<_WrappedCollectionBrowser>
selector: (state) => state.error,
listener: (context, error) {
if (error != null && isPageVisible()) {
final String content;
if (error.error is _ArchiveFailedError) {
content = L10n.global()
.archiveSelectedFailureNotification(
(error.error as _ArchiveFailedError).count);
SnackBarManager().showSnackBar(SnackBar(
content: Text(L10n.global()
.archiveSelectedFailureNotification(
(error.error as _ArchiveFailedError).count)),
duration: k.snackBarDurationNormal,
));
} else if (error.error is _RemoveFailedError) {
content = L10n.global().deleteSelectedFailureNotification(
(error.error as _RemoveFailedError).count);
SnackBarManager().showSnackBar(SnackBar(
content: Text(L10n.global()
.deleteSelectedFailureNotification(
(error.error as _RemoveFailedError).count)),
duration: k.snackBarDurationNormal,
));
} else {
content = exception_util.toUserString(error.error);
SnackBarManager().showSnackBarForException(error.error);
}
SnackBarManager().showSnackBar(SnackBar(
content: Text(content),
duration: k.snackBarDurationNormal,
));
}
},
),

View file

@ -17,7 +17,6 @@ import 'package:nc_photos/entity/collection.dart';
import 'package:nc_photos/entity/collection/adapter.dart';
import 'package:nc_photos/entity/collection/util.dart' as collection_util;
import 'package:nc_photos/exception_event.dart';
import 'package:nc_photos/exception_util.dart' as exception_util;
import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/np_api_util.dart';
import 'package:nc_photos/snack_bar_manager.dart';
@ -99,11 +98,7 @@ class _WrappedCollectionPickerState extends State<_WrappedCollectionPicker> {
listenWhen: (previous, current) => previous.error != current.error,
listener: (context, state) {
if (state.error != null) {
SnackBarManager().showSnackBar(SnackBar(
content:
Text(exception_util.toUserString(state.error!.error)),
duration: k.snackBarDurationNormal,
));
SnackBarManager().showSnackBarForException(state.error!.error);
}
},
),

View file

@ -10,7 +10,6 @@ import 'package:nc_photos/di_container.dart';
import 'package:nc_photos/entity/file.dart';
import 'package:nc_photos/entity/file_descriptor.dart';
import 'package:nc_photos/entity/file_util.dart' as file_util;
import 'package:nc_photos/exception_util.dart' as exception_util;
import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/snack_bar_manager.dart';
import 'package:np_codegen/np_codegen.dart';
@ -123,10 +122,7 @@ class DirPickerState extends State<DirPicker> {
try {
_navigateInto(File(path: path_lib.dirname(_currentPath)));
} catch (e) {
SnackBarManager().showSnackBar(SnackBar(
content: Text(exception_util.toUserString(e)),
duration: k.snackBarDurationNormal,
));
SnackBarManager().showSnackBarForException(e);
}
},
);
@ -219,10 +215,7 @@ class DirPickerState extends State<DirPicker> {
try {
_navigateInto(item.file);
} catch (e) {
SnackBarManager().showSnackBar(SnackBar(
content: Text(exception_util.toUserString(e)),
duration: k.snackBarDurationNormal,
));
SnackBarManager().showSnackBarForException(e);
}
}
: null,
@ -238,10 +231,7 @@ class DirPickerState extends State<DirPicker> {
: ""));
}
} else if (state is LsDirBlocFailure) {
SnackBarManager().showSnackBar(SnackBar(
content: Text(exception_util.toUserString(state.exception)),
duration: k.snackBarDurationNormal,
));
SnackBarManager().showSnackBarForException(state.exception);
}
}

View file

@ -21,7 +21,6 @@ import 'package:nc_photos/entity/collection/content_provider/nc_album.dart';
import 'package:nc_photos/entity/collection/util.dart' as collection_util;
import 'package:nc_photos/entity/pref.dart';
import 'package:nc_photos/exception_event.dart';
import 'package:nc_photos/exception_util.dart' as exception_util;
import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/np_api_util.dart';
import 'package:nc_photos/platform/features.dart' as features;
@ -104,10 +103,7 @@ class _WrappedHomeCollectionsState extends State<_WrappedHomeCollections>
listenWhen: (previous, current) => previous.error != current.error,
listener: (context, state) {
if (state.error != null && isPageVisible()) {
SnackBarManager().showSnackBar(SnackBar(
content: Text(exception_util.toUserString(state.error!.error)),
duration: k.snackBarDurationNormal,
));
SnackBarManager().showSnackBarForException(state.error!.error);
}
},
),

View file

@ -32,7 +32,6 @@ import 'package:nc_photos/entity/file_descriptor.dart';
import 'package:nc_photos/entity/file_util.dart' as file_util;
import 'package:nc_photos/event/event.dart';
import 'package:nc_photos/exception_event.dart';
import 'package:nc_photos/exception_util.dart' as exception_util;
import 'package:nc_photos/flutter_util.dart' as flutter_util;
import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/progress_util.dart';
@ -138,20 +137,23 @@ class _WrappedHomePhotosState extends State<_WrappedHomePhotos> {
selector: (state) => state.error,
listener: (context, error) {
if (error != null && _isVisible == true) {
final String content;
if (error.error is _ArchiveFailedError) {
content = L10n.global().archiveSelectedFailureNotification(
(error.error as _ArchiveFailedError).count);
SnackBarManager().showSnackBar(SnackBar(
content: Text(L10n.global()
.archiveSelectedFailureNotification(
(error.error as _ArchiveFailedError).count)),
duration: k.snackBarDurationNormal,
));
} else if (error.error is _RemoveFailedError) {
content = L10n.global().deleteSelectedFailureNotification(
(error.error as _RemoveFailedError).count);
SnackBarManager().showSnackBar(SnackBar(
content: Text(L10n.global()
.deleteSelectedFailureNotification(
(error.error as _RemoveFailedError).count)),
duration: k.snackBarDurationNormal,
));
} else {
content = exception_util.toUserString(error.error);
SnackBarManager().showSnackBarForException(error.error);
}
SnackBarManager().showSnackBar(SnackBar(
content: Text(content),
duration: k.snackBarDurationNormal,
));
}
},
),

View file

@ -14,7 +14,6 @@ import 'package:nc_photos/download_handler.dart';
import 'package:nc_photos/entity/file_descriptor.dart';
import 'package:nc_photos/entity/pref.dart';
import 'package:nc_photos/entity/search.dart';
import 'package:nc_photos/exception_util.dart' as exception_util;
import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/language_util.dart' as language_util;
import 'package:nc_photos/object_extension.dart';
@ -341,10 +340,7 @@ class _HomeSearchState extends State<HomeSearch>
} else if (state is SearchBlocFailure) {
_transformItems(state.items);
if (isPageVisible()) {
SnackBarManager().showSnackBar(SnackBar(
content: Text(exception_util.toUserString(state.exception)),
duration: k.snackBarDurationNormal,
));
SnackBarManager().showSnackBarForException(state.exception);
}
} else if (state is SearchBlocInconsistent) {
_reqQuery(_activeInput, _activeFilters);

View file

@ -8,8 +8,6 @@ import 'package:nc_photos/entity/collection.dart';
import 'package:nc_photos/entity/collection/builder.dart';
import 'package:nc_photos/entity/person.dart';
import 'package:nc_photos/entity/tag.dart';
import 'package:nc_photos/exception_util.dart' as exception_util;
import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/object_extension.dart';
import 'package:nc_photos/snack_bar_manager.dart';
import 'package:nc_photos/use_case/list_location_group.dart';
@ -119,10 +117,7 @@ class _HomeSearchSuggestionState extends State<HomeSearchSuggestion>
} else if (state is HomeSearchSuggestionBlocFailure) {
_transformItems(state.results);
if (isPageVisible()) {
SnackBarManager().showSnackBar(SnackBar(
content: Text(exception_util.toUserString(state.exception)),
duration: k.snackBarDurationNormal,
));
SnackBarManager().showSnackBarForException(state.exception);
}
}
}

View file

@ -7,7 +7,6 @@ import 'package:nc_photos/account.dart';
import 'package:nc_photos/api/api_util.dart' as api_util;
import 'package:nc_photos/cache_manager_util.dart';
import 'package:nc_photos/entity/file_descriptor.dart';
import 'package:nc_photos/exception_util.dart' as exception_util;
import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/np_api_util.dart';
import 'package:nc_photos/snack_bar_manager.dart';
@ -55,10 +54,7 @@ class _LivePhotoViewerState extends State<LivePhotoViewer> {
}
}).onError((e, stacktrace) {
_log.shout("[initState] Failed while _getVideoUrl", e, stacktrace);
SnackBarManager().showSnackBar(SnackBar(
content: Text(exception_util.toUserString(e)),
duration: k.snackBarDurationNormal,
));
SnackBarManager().showSnackBarForException(e);
widget.onLoadFailure?.call();
});
@ -122,10 +118,7 @@ class _LivePhotoViewerState extends State<LivePhotoViewer> {
await _controller.play();
} catch (e, stackTrace) {
_log.shout("[_initController] Failed while initialize", e, stackTrace);
SnackBarManager().showSnackBar(SnackBar(
content: Text(exception_util.toUserString(e)),
duration: k.snackBarDurationNormal,
));
SnackBarManager().showSnackBarForException(e);
widget.onLoadFailure?.call();
}
}

View file

@ -14,7 +14,6 @@ import 'package:nc_photos/controller/persons_controller.dart';
import 'package:nc_photos/entity/collection/builder.dart';
import 'package:nc_photos/entity/person.dart';
import 'package:nc_photos/exception_event.dart';
import 'package:nc_photos/exception_util.dart' as exception_util;
import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/snack_bar_manager.dart';
import 'package:nc_photos/widget/collection_browser.dart';
@ -86,10 +85,7 @@ class _WrappedPeopleBrowserState extends State<_WrappedPeopleBrowser>
listenWhen: (previous, current) => previous.error != current.error,
listener: (context, state) {
if (state.error != null && isPageVisible()) {
SnackBarManager().showSnackBar(SnackBar(
content: Text(exception_util.toUserString(state.error!.error)),
duration: k.snackBarDurationNormal,
));
SnackBarManager().showSnackBarForException(state.error!.error);
}
},
),

View file

@ -13,8 +13,6 @@ import 'package:nc_photos/controller/account_controller.dart';
import 'package:nc_photos/controller/places_controller.dart';
import 'package:nc_photos/entity/collection/builder.dart';
import 'package:nc_photos/exception_event.dart';
import 'package:nc_photos/exception_util.dart' as exception_util;
import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/snack_bar_manager.dart';
import 'package:nc_photos/theme.dart';
import 'package:nc_photos/use_case/list_location_group.dart';
@ -88,10 +86,7 @@ class _WrappedPlacesBrowserState extends State<_WrappedPlacesBrowser>
listenWhen: (previous, current) => previous.error != current.error,
listener: (context, state) {
if (state.error != null && isPageVisible()) {
SnackBarManager().showSnackBar(SnackBar(
content: Text(exception_util.toUserString(state.error!.error)),
duration: k.snackBarDurationNormal,
));
SnackBarManager().showSnackBarForException(state.error!.error);
}
},
),

View file

@ -6,7 +6,6 @@ import 'package:nc_photos/app_localizations.dart';
import 'package:nc_photos/di_container.dart';
import 'package:nc_photos/entity/file.dart';
import 'package:nc_photos/entity/pref.dart';
import 'package:nc_photos/exception_util.dart' as exception_util;
import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/snack_bar_manager.dart';
import 'package:nc_photos/theme.dart';
@ -112,10 +111,7 @@ class _ResultViewerState extends State<ResultViewer> {
file = await LsSingleFile(_c)(_account!, filePath);
} catch (e, stackTrace) {
_log.severe("[_doWork] Failed while LsSingleFile", e, stackTrace);
SnackBarManager().showSnackBar(SnackBar(
content: Text(exception_util.toUserString(e)),
duration: k.snackBarDurationNormal,
));
SnackBarManager().showSnackBarForException(e);
Navigator.of(context).pop();
return;
}

View file

@ -16,7 +16,6 @@ import 'package:nc_photos/entity/collection/builder.dart';
import 'package:nc_photos/entity/person.dart';
import 'package:nc_photos/exception.dart';
import 'package:nc_photos/exception_event.dart';
import 'package:nc_photos/exception_util.dart' as exception_util;
import 'package:nc_photos/help_utils.dart' as help_util;
import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/snack_bar_manager.dart';
@ -134,11 +133,7 @@ class _WrappedSearchLandingState extends State<_WrappedSearchLanding> {
return;
}
}
SnackBarManager().showSnackBar(SnackBar(
content:
Text(exception_util.toUserString(state.error!.error)),
duration: k.snackBarDurationNormal,
));
SnackBarManager().showSnackBarForException(state.error!.error);
}
},
),

View file

@ -14,7 +14,6 @@ import 'package:nc_photos/di_container.dart';
import 'package:nc_photos/entity/person.dart';
import 'package:nc_photos/entity/pref.dart';
import 'package:nc_photos/exception_event.dart';
import 'package:nc_photos/exception_util.dart' as exception_util;
import 'package:nc_photos/help_utils.dart' as help_util;
import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/snack_bar_manager.dart';
@ -129,19 +128,22 @@ class _WrappedAccountSettingsState extends State<_WrappedAccountSettings>
listenWhen: (previous, current) => previous.error != current.error,
listener: (context, state) {
if (state.error != null && isPageVisible()) {
final String errorMsg;
if (state.error is _AccountConflictError) {
errorMsg =
L10n.global().editAccountConflictFailureNotification;
SnackBarManager().showSnackBar(SnackBar(
content: Text(
L10n.global().editAccountConflictFailureNotification),
duration: k.snackBarDurationNormal,
));
} else if (state.error is _WritePrefError) {
errorMsg = L10n.global().writePreferenceFailureNotification;
SnackBarManager().showSnackBar(SnackBar(
content:
Text(L10n.global().writePreferenceFailureNotification),
duration: k.snackBarDurationNormal,
));
} else {
errorMsg = exception_util.toUserString(state.error!.error);
SnackBarManager()
.showSnackBarForException(state.error!.error);
}
SnackBarManager().showSnackBar(SnackBar(
content: Text(errorMsg),
duration: k.snackBarDurationNormal,
));
}
},
),

View file

@ -6,8 +6,6 @@ import 'package:nc_photos/app_localizations.dart';
import 'package:nc_photos/bloc_util.dart';
import 'package:nc_photos/controller/pref_controller.dart';
import 'package:nc_photos/exception_event.dart';
import 'package:nc_photos/exception_util.dart' as exception_util;
import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/snack_bar_manager.dart';
import 'package:nc_photos/widget/page_visibility_mixin.dart';
import 'package:np_codegen/np_codegen.dart';
@ -59,11 +57,7 @@ class _WrappedAlbumSettingsState extends State<_WrappedAlbumSettings>
listenWhen: (previous, current) => previous.error != current.error,
listener: (context, state) {
if (state.error != null && isPageVisible()) {
SnackBarManager().showSnackBar(SnackBar(
content:
Text(exception_util.toUserString(state.error!.error)),
duration: k.snackBarDurationNormal,
));
SnackBarManager().showSnackBarForException(state.error!.error);
}
},
),

View file

@ -8,7 +8,6 @@ import 'package:nc_photos/bloc_util.dart';
import 'package:nc_photos/cache_manager_util.dart';
import 'package:nc_photos/di_container.dart';
import 'package:nc_photos/exception_event.dart';
import 'package:nc_photos/exception_util.dart' as exception_util;
import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/mobile/self_signed_cert_manager.dart';
import 'package:nc_photos/snack_bar_manager.dart';
@ -53,11 +52,7 @@ class _WrappedDeveloperSettingsState extends State<_WrappedDeveloperSettings>
listenWhen: (previous, current) => previous.error != current.error,
listener: (context, state) {
if (state.error != null && isPageVisible()) {
SnackBarManager().showSnackBar(SnackBar(
content:
Text(exception_util.toUserString(state.error!.error)),
duration: k.snackBarDurationNormal,
));
SnackBarManager().showSnackBarForException(state.error!.error);
}
},
),

View file

@ -6,8 +6,6 @@ import 'package:nc_photos/app_localizations.dart';
import 'package:nc_photos/bloc_util.dart';
import 'package:nc_photos/controller/pref_controller.dart';
import 'package:nc_photos/exception_event.dart';
import 'package:nc_photos/exception_util.dart' as exception_util;
import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/size.dart';
import 'package:nc_photos/snack_bar_manager.dart';
import 'package:nc_photos/widget/page_visibility_mixin.dart';
@ -69,11 +67,7 @@ class _WrappedEnhancementSettingsState
listenWhen: (previous, current) => previous.error != current.error,
listener: (context, state) {
if (state.error != null && isPageVisible()) {
SnackBarManager().showSnackBar(SnackBar(
content:
Text(exception_util.toUserString(state.error!.error)),
duration: k.snackBarDurationNormal,
));
SnackBarManager().showSnackBarForException(state.error!.error);
}
},
),

View file

@ -10,8 +10,6 @@ import 'package:nc_photos/bloc_util.dart';
import 'package:nc_photos/db/entity_converter.dart';
import 'package:nc_photos/di_container.dart';
import 'package:nc_photos/entity/pref.dart';
import 'package:nc_photos/exception_util.dart' as exception_util;
import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/snack_bar_manager.dart';
import 'package:np_codegen/np_codegen.dart';
import 'package:np_db/np_db.dart';
@ -50,10 +48,7 @@ class _WrappedExpertSettingsState extends State<_WrappedExpertSettings> {
super.initState();
_errorSubscription = context.read<_Bloc>().errorStream().listen((error) {
if (error.ev is _ClearCacheDatabase) {
SnackBarManager().showSnackBar(SnackBar(
content: Text(exception_util.toUserString(error.error)),
duration: k.snackBarDurationNormal,
));
SnackBarManager().showSnackBarForException(error.error);
}
});
}

View file

@ -6,8 +6,6 @@ import 'package:nc_photos/app_localizations.dart';
import 'package:nc_photos/bloc_util.dart';
import 'package:nc_photos/controller/pref_controller.dart';
import 'package:nc_photos/exception_event.dart';
import 'package:nc_photos/exception_util.dart' as exception_util;
import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/language_util.dart' as language_util;
import 'package:nc_photos/snack_bar_manager.dart';
import 'package:nc_photos/widget/page_visibility_mixin.dart';
@ -65,10 +63,7 @@ class _WrappedLanguageSettingsState extends State<_WrappedLanguageSettings>
listenWhen: (previous, current) => previous.error != current.error,
listener: (context, state) {
if (state.error != null && isPageVisible()) {
SnackBarManager().showSnackBar(SnackBar(
content: Text(exception_util.toUserString(state.error!.error)),
duration: k.snackBarDurationNormal,
));
SnackBarManager().showSnackBarForException(state.error!.error);
}
},
),

View file

@ -6,8 +6,6 @@ import 'package:nc_photos/app_localizations.dart';
import 'package:nc_photos/bloc_util.dart';
import 'package:nc_photos/controller/pref_controller.dart';
import 'package:nc_photos/exception_event.dart';
import 'package:nc_photos/exception_util.dart' as exception_util;
import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/service.dart';
import 'package:nc_photos/snack_bar_manager.dart';
import 'package:nc_photos/widget/page_visibility_mixin.dart';
@ -61,11 +59,7 @@ class _WrappedMetadataSettingsState extends State<_WrappedMetadataSettings>
listenWhen: (previous, current) => previous.error != current.error,
listener: (context, state) {
if (state.error != null && isPageVisible()) {
SnackBarManager().showSnackBar(SnackBar(
content:
Text(exception_util.toUserString(state.error!.error)),
duration: k.snackBarDurationNormal,
));
SnackBarManager().showSnackBarForException(state.error!.error);
}
},
),

View file

@ -6,8 +6,6 @@ import 'package:nc_photos/app_localizations.dart';
import 'package:nc_photos/bloc_util.dart';
import 'package:nc_photos/controller/pref_controller.dart';
import 'package:nc_photos/exception_event.dart';
import 'package:nc_photos/exception_util.dart' as exception_util;
import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/protected_page_handler.dart';
import 'package:nc_photos/snack_bar_manager.dart';
import 'package:nc_photos/widget/page_visibility_mixin.dart';
@ -59,11 +57,7 @@ class _WrappedMiscSettingsState extends State<_WrappedMiscSettings>
listenWhen: (previous, current) => previous.error != current.error,
listener: (context, state) {
if (state.error != null && isPageVisible()) {
SnackBarManager().showSnackBar(SnackBar(
content:
Text(exception_util.toUserString(state.error!.error)),
duration: k.snackBarDurationNormal,
));
SnackBarManager().showSnackBarForException(state.error!.error);
}
},
),

View file

@ -8,8 +8,6 @@ import 'package:nc_photos/controller/account_controller.dart';
import 'package:nc_photos/controller/account_pref_controller.dart';
import 'package:nc_photos/controller/pref_controller.dart';
import 'package:nc_photos/exception_event.dart';
import 'package:nc_photos/exception_util.dart' as exception_util;
import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/snack_bar_manager.dart';
import 'package:nc_photos/widget/page_visibility_mixin.dart';
import 'package:np_codegen/np_codegen.dart';
@ -63,11 +61,7 @@ class _WrappedPhotosSettingsState extends State<_WrappedPhotosSettings>
listenWhen: (previous, current) => previous.error != current.error,
listener: (context, state) {
if (state.error != null && isPageVisible()) {
SnackBarManager().showSnackBar(SnackBar(
content:
Text(exception_util.toUserString(state.error!.error)),
duration: k.snackBarDurationNormal,
));
SnackBarManager().showSnackBarForException(state.error!.error);
}
},
),

View file

@ -9,8 +9,6 @@ import 'package:nc_photos/app_localizations.dart';
import 'package:nc_photos/bloc_util.dart';
import 'package:nc_photos/controller/pref_controller.dart';
import 'package:nc_photos/exception_event.dart';
import 'package:nc_photos/exception_util.dart' as exception_util;
import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/mobile/android/android_info.dart';
import 'package:nc_photos/object_extension.dart';
import 'package:nc_photos/session_storage.dart';
@ -65,11 +63,7 @@ class _WrappedThemeSettingsState extends State<_WrappedThemeSettings>
listenWhen: (previous, current) => previous.error != current.error,
listener: (context, state) {
if (state.error != null && isPageVisible()) {
SnackBarManager().showSnackBar(SnackBar(
content:
Text(exception_util.toUserString(state.error!.error)),
duration: k.snackBarDurationNormal,
));
SnackBarManager().showSnackBarForException(state.error!.error);
}
},
),

View file

@ -6,9 +6,7 @@ import 'package:nc_photos/app_localizations.dart';
import 'package:nc_photos/bloc_util.dart';
import 'package:nc_photos/controller/pref_controller.dart';
import 'package:nc_photos/exception_event.dart';
import 'package:nc_photos/exception_util.dart' as exception_util;
import 'package:nc_photos/gps_map_util.dart';
import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/snack_bar_manager.dart';
import 'package:nc_photos/widget/page_visibility_mixin.dart';
import 'package:np_codegen/np_codegen.dart';
@ -64,11 +62,7 @@ class _WrappedViewerSettingsState extends State<_WrappedViewerSettings>
listenWhen: (previous, current) => previous.error != current.error,
listener: (context, state) {
if (state.error != null && isPageVisible()) {
SnackBarManager().showSnackBar(SnackBar(
content:
Text(exception_util.toUserString(state.error!.error)),
duration: k.snackBarDurationNormal,
));
SnackBarManager().showSnackBarForException(state.error!.error);
}
},
),

View file

@ -14,7 +14,6 @@ import 'package:nc_photos/entity/file.dart';
import 'package:nc_photos/entity/file_descriptor.dart';
import 'package:nc_photos/entity/share.dart';
import 'package:nc_photos/entity/share/data_source.dart';
import 'package:nc_photos/exception_util.dart' as exception_util;
import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/np_api_util.dart';
import 'package:nc_photos/remote_storage_util.dart' as remote_storage_util;
@ -240,10 +239,7 @@ class _SharedFileViewerState extends State<SharedFileViewer> {
} catch (e, stackTrace) {
_log.shout(
"[_onItemUnsharePressed] Failed while RemoveShare", e, stackTrace);
SnackBarManager().showSnackBar(SnackBar(
content: Text(exception_util.toUserString(e)),
duration: k.snackBarDurationNormal,
));
SnackBarManager().showSnackBarForException(e);
}
}

View file

@ -22,8 +22,6 @@ import 'package:nc_photos/entity/file/data_source.dart';
import 'package:nc_photos/entity/pref.dart';
import 'package:nc_photos/entity/share.dart';
import 'package:nc_photos/exception_event.dart';
import 'package:nc_photos/exception_util.dart' as exception_util;
import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/object_extension.dart';
import 'package:nc_photos/snack_bar_manager.dart';
import 'package:nc_photos/use_case/import_potential_shared_album.dart';
@ -112,10 +110,7 @@ class _WrappedSharingBrowserState extends State<_WrappedSharingBrowser>
listenWhen: (previous, current) => previous.error != current.error,
listener: (context, state) {
if (state.error != null && isPageVisible()) {
SnackBarManager().showSnackBar(SnackBar(
content: Text(exception_util.toUserString(state.error!.error)),
duration: k.snackBarDurationNormal,
));
SnackBarManager().showSnackBarForException(state.error!.error);
}
},
),

View file

@ -6,7 +6,6 @@ import 'package:nc_photos/app_localizations.dart';
import 'package:nc_photos/bloc/list_tag.dart';
import 'package:nc_photos/bloc/search_suggestion.dart';
import 'package:nc_photos/entity/tag.dart';
import 'package:nc_photos/exception_util.dart' as exception_util;
import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/snack_bar_manager.dart';
import 'package:nc_photos/widget/dialog_scaffold.dart';
@ -109,10 +108,7 @@ class _TagPickerDialogState extends State<TagPickerDialog> {
if (state is ListTagBlocSuccess) {
_transformSuggestionItems(state.items);
} else if (state is ListTagBlocFailure) {
SnackBarManager().showSnackBar(SnackBar(
content: Text(exception_util.toUserString(state.exception)),
duration: k.snackBarDurationNormal,
));
SnackBarManager().showSnackBarForException(state.exception);
}
}

View file

@ -14,7 +14,6 @@ import 'package:nc_photos/di_container.dart';
import 'package:nc_photos/entity/file.dart';
import 'package:nc_photos/entity/file_descriptor.dart';
import 'package:nc_photos/entity/pref.dart';
import 'package:nc_photos/exception_util.dart' as exception_util;
import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/language_util.dart' as language_util;
import 'package:nc_photos/object_extension.dart';
@ -258,10 +257,7 @@ class _TrashbinBrowserState extends State<TrashbinBrowser>
_transformItems(state.items);
} else if (state is LsTrashbinBlocFailure) {
_transformItems(state.items);
SnackBarManager().showSnackBar(SnackBar(
content: Text(exception_util.toUserString(state.exception)),
duration: k.snackBarDurationNormal,
));
SnackBarManager().showSnackBarForException(state.exception);
} else if (state is LsTrashbinBlocInconsistent) {
_reqQuery();
}

View file

@ -9,7 +9,6 @@ import 'package:nc_photos/app_localizations.dart';
import 'package:nc_photos/di_container.dart';
import 'package:nc_photos/entity/file_descriptor.dart';
import 'package:nc_photos/entity/pref.dart';
import 'package:nc_photos/exception_util.dart' as exception_util;
import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/np_api_util.dart';
import 'package:nc_photos/snack_bar_manager.dart';
@ -69,10 +68,7 @@ class _VideoViewerState extends State<VideoViewer>
}
}).onError((e, stacktrace) {
_log.shout("[initState] Failed while _getVideoUrl", e, stacktrace);
SnackBarManager().showSnackBar(SnackBar(
content: Text(exception_util.toUserString(e)),
duration: k.snackBarDurationNormal,
));
SnackBarManager().showSnackBarForException(e);
widget.onLoadFailure?.call();
});
}
@ -135,10 +131,7 @@ class _VideoViewerState extends State<VideoViewer>
});
} catch (e, stackTrace) {
_log.shout("[_initController] Failed while initialize", e, stackTrace);
SnackBarManager().showSnackBar(SnackBar(
content: Text(exception_util.toUserString(e)),
duration: k.snackBarDurationNormal,
));
SnackBarManager().showSnackBarForException(e);
widget.onLoadFailure?.call();
}
}