mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-02-02 14:56:20 +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/entity/share/data_source.dart';
|
||||||
import 'package:nc_photos/event/event.dart';
|
import 'package:nc_photos/event/event.dart';
|
||||||
import 'package:nc_photos/exception.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/remote_storage_util.dart' as remote_storage_util;
|
||||||
import 'package:nc_photos/string_extension.dart';
|
import 'package:nc_photos/string_extension.dart';
|
||||||
import 'package:nc_photos/throttler.dart';
|
import 'package:nc_photos/throttler.dart';
|
||||||
import 'package:nc_photos/use_case/list_album.dart';
|
import 'package:nc_photos/use_case/list_album.dart';
|
||||||
import 'package:tuple/tuple.dart';
|
|
||||||
|
|
||||||
class ListAlbumBlocItem {
|
class ListAlbumBlocItem {
|
||||||
ListAlbumBlocItem(this.album, this.isSharedByMe, this.isSharedToMe);
|
ListAlbumBlocItem(this.album, this.isSharedByMe, this.isSharedToMe);
|
||||||
|
@ -232,15 +232,15 @@ class ListAlbumBloc extends Bloc<ListAlbumBlocEvent, ListAlbumBlocState> {
|
||||||
final errors = <dynamic>[];
|
final errors = <dynamic>[];
|
||||||
await for (final result in ListAlbum(
|
await for (final result in ListAlbum(
|
||||||
FileRepo(fileDataSource), AlbumRepo(albumDataSrc))(ev.account)) {
|
FileRepo(fileDataSource), AlbumRepo(albumDataSrc))(ev.account)) {
|
||||||
if (result is Tuple2) {
|
if (result is ExceptionEvent) {
|
||||||
if (result.item1 is CacheNotFoundException) {
|
if (result.error is CacheNotFoundException) {
|
||||||
_log.info(
|
_log.info(
|
||||||
"[_queryWithAlbumDataSource] Cache not found", result.item1);
|
"[_queryWithAlbumDataSource] Cache not found", result.error);
|
||||||
} else {
|
} else {
|
||||||
_log.shout("[_queryWithAlbumDataSource] Exception while ListAlbum",
|
_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) {
|
} else if (result is Album) {
|
||||||
albums.add(result);
|
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.dart';
|
||||||
import 'package:nc_photos/entity/file/data_source.dart';
|
import 'package:nc_photos/entity/file/data_source.dart';
|
||||||
import 'package:nc_photos/event/event.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/remote_storage_util.dart' as remote_storage_util;
|
||||||
import 'package:nc_photos/use_case/list_pending_shared_album.dart';
|
import 'package:nc_photos/use_case/list_pending_shared_album.dart';
|
||||||
import 'package:tuple/tuple.dart';
|
import 'package:tuple/tuple.dart';
|
||||||
|
@ -138,10 +139,10 @@ class ListPendingSharedAlbumBloc extends Bloc<
|
||||||
final errors = <dynamic>[];
|
final errors = <dynamic>[];
|
||||||
await for (final result
|
await for (final result
|
||||||
in ListPendingSharedAlbum(fileRepo, albumRepo)(ev.account)) {
|
in ListPendingSharedAlbum(fileRepo, albumRepo)(ev.account)) {
|
||||||
if (result is Tuple2) {
|
if (result is ExceptionEvent) {
|
||||||
_log.severe("[_onEventQuery] Exception while ListPendingSharedAlbum",
|
_log.severe("[_onEventQuery] Exception while ListPendingSharedAlbum",
|
||||||
result.item1, result.item2);
|
result.error, result.stackTrace);
|
||||||
errors.add(result.item1);
|
errors.add(result.error);
|
||||||
} else if (result is Album) {
|
} else if (result is Album) {
|
||||||
albums.add(result);
|
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/album.dart';
|
||||||
import 'package:nc_photos/entity/file.dart';
|
import 'package:nc_photos/entity/file.dart';
|
||||||
import 'package:nc_photos/exception.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/remote_storage_util.dart' as remote_storage_util;
|
||||||
import 'package:nc_photos/use_case/compat/v15.dart';
|
import 'package:nc_photos/use_case/compat/v15.dart';
|
||||||
import 'package:nc_photos/use_case/compat/v25.dart';
|
import 'package:nc_photos/use_case/compat/v25.dart';
|
||||||
import 'package:nc_photos/use_case/ls.dart';
|
import 'package:nc_photos/use_case/ls.dart';
|
||||||
import 'package:tuple/tuple.dart';
|
|
||||||
|
|
||||||
class ListAlbum {
|
class ListAlbum {
|
||||||
ListAlbum(this.fileRepo, this.albumRepo);
|
ListAlbum(this.fileRepo, this.albumRepo);
|
||||||
|
@ -38,12 +38,12 @@ class ListAlbum {
|
||||||
File(
|
File(
|
||||||
path: remote_storage_util.getRemoteAlbumsDir(account),
|
path: remote_storage_util.getRemoteAlbumsDir(account),
|
||||||
));
|
));
|
||||||
} catch (e, stacktrace) {
|
} catch (e, stackTrace) {
|
||||||
if (e is ApiException && e.response.statusCode == 404) {
|
if (e is ApiException && e.response.statusCode == 404) {
|
||||||
// no albums
|
// no albums
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
yield Tuple2(e, stacktrace);
|
yield ExceptionEvent(e, stackTrace);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final albumFiles =
|
final albumFiles =
|
||||||
|
@ -56,8 +56,8 @@ class ListAlbum {
|
||||||
}
|
}
|
||||||
albumFiles[i] = f;
|
albumFiles[i] = f;
|
||||||
yield await albumRepo.get(account, f);
|
yield await albumRepo.get(account, f);
|
||||||
} catch (e, stacktrace) {
|
} catch (e, stackTrace) {
|
||||||
yield Tuple2(e, stacktrace);
|
yield ExceptionEvent(e, stackTrace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -3,9 +3,9 @@ import 'package:nc_photos/account.dart';
|
||||||
import 'package:nc_photos/entity/album.dart';
|
import 'package:nc_photos/entity/album.dart';
|
||||||
import 'package:nc_photos/entity/file.dart';
|
import 'package:nc_photos/entity/file.dart';
|
||||||
import 'package:nc_photos/exception.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/remote_storage_util.dart' as remote_storage_util;
|
||||||
import 'package:nc_photos/use_case/ls.dart';
|
import 'package:nc_photos/use_case/ls.dart';
|
||||||
import 'package:tuple/tuple.dart';
|
|
||||||
|
|
||||||
class ListPendingSharedAlbum {
|
class ListPendingSharedAlbum {
|
||||||
ListPendingSharedAlbum(this.fileRepo, this.albumRepo);
|
ListPendingSharedAlbum(this.fileRepo, this.albumRepo);
|
||||||
|
@ -23,12 +23,12 @@ class ListPendingSharedAlbum {
|
||||||
File(
|
File(
|
||||||
path: remote_storage_util.getRemotePendingSharedAlbumsDir(account),
|
path: remote_storage_util.getRemotePendingSharedAlbumsDir(account),
|
||||||
));
|
));
|
||||||
} catch (e, stacktrace) {
|
} catch (e, stackTrace) {
|
||||||
if (e is ApiException && e.response.statusCode == 404) {
|
if (e is ApiException && e.response.statusCode == 404) {
|
||||||
// no albums
|
// no albums
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
yield Tuple2(e, stacktrace);
|
yield ExceptionEvent(e, stackTrace);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final albumFiles =
|
final albumFiles =
|
||||||
|
@ -36,8 +36,8 @@ class ListPendingSharedAlbum {
|
||||||
for (final f in albumFiles) {
|
for (final f in albumFiles) {
|
||||||
try {
|
try {
|
||||||
yield await albumRepo.get(account, f);
|
yield await albumRepo.get(account, f);
|
||||||
} catch (e, stacktrace) {
|
} catch (e, stackTrace) {
|
||||||
yield Tuple2(e, stacktrace);
|
yield ExceptionEvent(e, stackTrace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in a new issue