mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-02-02 06:46:22 +01:00
Refactoring: replace tuple with actual class
This commit is contained in:
parent
19367e2a0d
commit
f7ed6d1a01
5 changed files with 29 additions and 19 deletions
|
@ -8,11 +8,11 @@ import 'package:nc_photos/entity/share.dart';
|
|||
import 'package:nc_photos/entity/share/data_source.dart';
|
||||
import 'package:nc_photos/event/event.dart';
|
||||
import 'package:nc_photos/exception.dart';
|
||||
import 'package:nc_photos/exception_event.dart';
|
||||
import 'package:nc_photos/remote_storage_util.dart' as remote_storage_util;
|
||||
import 'package:nc_photos/string_extension.dart';
|
||||
import 'package:nc_photos/throttler.dart';
|
||||
import 'package:nc_photos/use_case/list_album.dart';
|
||||
import 'package:tuple/tuple.dart';
|
||||
|
||||
class ListAlbumBlocItem {
|
||||
ListAlbumBlocItem(this.album, this.isSharedByMe, this.isSharedToMe);
|
||||
|
@ -232,15 +232,15 @@ class ListAlbumBloc extends Bloc<ListAlbumBlocEvent, ListAlbumBlocState> {
|
|||
final errors = <dynamic>[];
|
||||
await for (final result in ListAlbum(
|
||||
FileRepo(fileDataSource), AlbumRepo(albumDataSrc))(ev.account)) {
|
||||
if (result is Tuple2) {
|
||||
if (result.item1 is CacheNotFoundException) {
|
||||
if (result is ExceptionEvent) {
|
||||
if (result.error is CacheNotFoundException) {
|
||||
_log.info(
|
||||
"[_queryWithAlbumDataSource] Cache not found", result.item1);
|
||||
"[_queryWithAlbumDataSource] Cache not found", result.error);
|
||||
} else {
|
||||
_log.shout("[_queryWithAlbumDataSource] Exception while ListAlbum",
|
||||
result.item1, result.item2);
|
||||
result.error, result.stackTrace);
|
||||
}
|
||||
errors.add(result.item1);
|
||||
errors.add(result.error);
|
||||
} else if (result is Album) {
|
||||
albums.add(result);
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import 'package:nc_photos/entity/album.dart';
|
|||
import 'package:nc_photos/entity/file.dart';
|
||||
import 'package:nc_photos/entity/file/data_source.dart';
|
||||
import 'package:nc_photos/event/event.dart';
|
||||
import 'package:nc_photos/exception_event.dart';
|
||||
import 'package:nc_photos/remote_storage_util.dart' as remote_storage_util;
|
||||
import 'package:nc_photos/use_case/list_pending_shared_album.dart';
|
||||
import 'package:tuple/tuple.dart';
|
||||
|
@ -138,10 +139,10 @@ class ListPendingSharedAlbumBloc extends Bloc<
|
|||
final errors = <dynamic>[];
|
||||
await for (final result
|
||||
in ListPendingSharedAlbum(fileRepo, albumRepo)(ev.account)) {
|
||||
if (result is Tuple2) {
|
||||
if (result is ExceptionEvent) {
|
||||
_log.severe("[_onEventQuery] Exception while ListPendingSharedAlbum",
|
||||
result.item1, result.item2);
|
||||
errors.add(result.item1);
|
||||
result.error, result.stackTrace);
|
||||
errors.add(result.error);
|
||||
} else if (result is Album) {
|
||||
albums.add(result);
|
||||
}
|
||||
|
|
9
lib/exception_event.dart
Normal file
9
lib/exception_event.dart
Normal file
|
@ -0,0 +1,9 @@
|
|||
class ExceptionEvent {
|
||||
const ExceptionEvent(
|
||||
this.error, [
|
||||
this.stackTrace,
|
||||
]);
|
||||
|
||||
final dynamic error;
|
||||
final StackTrace? stackTrace;
|
||||
}
|
|
@ -3,11 +3,11 @@ import 'package:nc_photos/account.dart';
|
|||
import 'package:nc_photos/entity/album.dart';
|
||||
import 'package:nc_photos/entity/file.dart';
|
||||
import 'package:nc_photos/exception.dart';
|
||||
import 'package:nc_photos/exception_event.dart';
|
||||
import 'package:nc_photos/remote_storage_util.dart' as remote_storage_util;
|
||||
import 'package:nc_photos/use_case/compat/v15.dart';
|
||||
import 'package:nc_photos/use_case/compat/v25.dart';
|
||||
import 'package:nc_photos/use_case/ls.dart';
|
||||
import 'package:tuple/tuple.dart';
|
||||
|
||||
class ListAlbum {
|
||||
ListAlbum(this.fileRepo, this.albumRepo);
|
||||
|
@ -38,12 +38,12 @@ class ListAlbum {
|
|||
File(
|
||||
path: remote_storage_util.getRemoteAlbumsDir(account),
|
||||
));
|
||||
} catch (e, stacktrace) {
|
||||
} catch (e, stackTrace) {
|
||||
if (e is ApiException && e.response.statusCode == 404) {
|
||||
// no albums
|
||||
return;
|
||||
}
|
||||
yield Tuple2(e, stacktrace);
|
||||
yield ExceptionEvent(e, stackTrace);
|
||||
return;
|
||||
}
|
||||
final albumFiles =
|
||||
|
@ -56,8 +56,8 @@ class ListAlbum {
|
|||
}
|
||||
albumFiles[i] = f;
|
||||
yield await albumRepo.get(account, f);
|
||||
} catch (e, stacktrace) {
|
||||
yield Tuple2(e, stacktrace);
|
||||
} catch (e, stackTrace) {
|
||||
yield ExceptionEvent(e, stackTrace);
|
||||
}
|
||||
}
|
||||
try {
|
||||
|
|
|
@ -3,9 +3,9 @@ import 'package:nc_photos/account.dart';
|
|||
import 'package:nc_photos/entity/album.dart';
|
||||
import 'package:nc_photos/entity/file.dart';
|
||||
import 'package:nc_photos/exception.dart';
|
||||
import 'package:nc_photos/exception_event.dart';
|
||||
import 'package:nc_photos/remote_storage_util.dart' as remote_storage_util;
|
||||
import 'package:nc_photos/use_case/ls.dart';
|
||||
import 'package:tuple/tuple.dart';
|
||||
|
||||
class ListPendingSharedAlbum {
|
||||
ListPendingSharedAlbum(this.fileRepo, this.albumRepo);
|
||||
|
@ -23,12 +23,12 @@ class ListPendingSharedAlbum {
|
|||
File(
|
||||
path: remote_storage_util.getRemotePendingSharedAlbumsDir(account),
|
||||
));
|
||||
} catch (e, stacktrace) {
|
||||
} catch (e, stackTrace) {
|
||||
if (e is ApiException && e.response.statusCode == 404) {
|
||||
// no albums
|
||||
return;
|
||||
}
|
||||
yield Tuple2(e, stacktrace);
|
||||
yield ExceptionEvent(e, stackTrace);
|
||||
return;
|
||||
}
|
||||
final albumFiles =
|
||||
|
@ -36,8 +36,8 @@ class ListPendingSharedAlbum {
|
|||
for (final f in albumFiles) {
|
||||
try {
|
||||
yield await albumRepo.get(account, f);
|
||||
} catch (e, stacktrace) {
|
||||
yield Tuple2(e, stacktrace);
|
||||
} catch (e, stackTrace) {
|
||||
yield ExceptionEvent(e, stackTrace);
|
||||
}
|
||||
}
|
||||
try {
|
||||
|
|
Loading…
Reference in a new issue