Import potential shared albums in sharing browser

This commit is contained in:
Ming Ming 2021-10-13 00:54:21 +08:00
parent eec1c99a8e
commit be2867ae41

View file

@ -12,15 +12,18 @@ import 'package:nc_photos/bloc/list_sharing.dart';
import 'package:nc_photos/cache_manager_util.dart';
import 'package:nc_photos/debug_util.dart';
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/entity/share.dart';
import 'package:nc_photos/event/event.dart';
import 'package:nc_photos/exception_util.dart' as exception_util;
import 'package:nc_photos/iterable_extension.dart';
import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/lab.dart';
import 'package:nc_photos/or_null.dart';
import 'package:nc_photos/pref.dart';
import 'package:nc_photos/snack_bar_manager.dart';
import 'package:nc_photos/theme.dart';
import 'package:nc_photos/use_case/import_potential_shared_album.dart';
import 'package:nc_photos/use_case/ls_single_file.dart';
import 'package:nc_photos/widget/album_browser_util.dart' as album_browser_util;
import 'package:nc_photos/widget/empty_list_indicator.dart';
@ -62,7 +65,14 @@ class _SharingBrowserState extends State<SharingBrowser> {
@override
initState() {
super.initState();
if (Lab().enableSharedAlbum) {
_importPotentialSharedAlbum().whenComplete(() {
_initBloc();
});
Pref.inst().setNewSharedAlbum(false);
} else {
_initBloc();
}
}
@override
@ -319,6 +329,22 @@ class _SharingBrowserState extends State<SharingBrowser> {
_bloc.add(ListSharingBlocQuery(widget.account));
}
Future<List<Album>> _importPotentialSharedAlbum() async {
const fileRepo = FileRepo(FileWebdavDataSource());
// don't want the potential albums to be cached at this moment
final albumRepo = AlbumRepo(AlbumRemoteDataSource());
try {
return await ImportPotentialSharedAlbum(fileRepo, albumRepo)(
widget.account);
} catch (e, stackTrace) {
_log.shout(
"[_importPotentialSharedAlbum] Failed while ImportPotentialSharedAlbum",
e,
stackTrace);
return [];
}
}
late final _bloc = ListSharingBloc.of(widget.account);
var _items = <List<ListSharingItem>>[];