You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
1.8 KiB
79 lines
1.8 KiB
2 years ago
|
part of '../neon_files.dart';
|
||
3 years ago
|
|
||
|
abstract class FilesBrowserBlocEvents {
|
||
|
void setPath(final List<String> path);
|
||
|
|
||
|
void createFolder(final List<String> path);
|
||
|
}
|
||
|
|
||
|
abstract class FilesBrowserBlocStates {
|
||
|
BehaviorSubject<Result<List<WebDavFile>>> get files;
|
||
|
|
||
|
BehaviorSubject<List<String>> get path;
|
||
|
}
|
||
|
|
||
2 years ago
|
class FilesBrowserBloc extends InteractiveBloc implements FilesBrowserBlocEvents, FilesBrowserBlocStates {
|
||
3 years ago
|
FilesBrowserBloc(
|
||
|
this.options,
|
||
|
this.client,
|
||
|
) {
|
||
2 years ago
|
unawaited(refresh());
|
||
3 years ago
|
}
|
||
|
|
||
|
final FilesAppSpecificOptions options;
|
||
|
final NextcloudClient client;
|
||
|
|
||
|
@override
|
||
|
void dispose() {
|
||
2 years ago
|
unawaited(files.close());
|
||
|
unawaited(path.close());
|
||
3 years ago
|
super.dispose();
|
||
|
}
|
||
|
|
||
|
@override
|
||
2 years ago
|
BehaviorSubject<Result<List<WebDavFile>>> files = BehaviorSubject<Result<List<WebDavFile>>>();
|
||
|
|
||
|
@override
|
||
|
BehaviorSubject<List<String>> path = BehaviorSubject<List<String>>.seeded([]);
|
||
|
|
||
|
@override
|
||
|
Future refresh() async {
|
||
|
// TODO: We have to do this manually, because we can't cache WebDAV stuff right now
|
||
|
try {
|
||
|
files.add(Result.loading());
|
||
|
final data = await client.webdav.ls(
|
||
|
path.value.join('/'),
|
||
|
props: {
|
||
|
WebDavProps.davContentType.name,
|
||
|
WebDavProps.davETag.name,
|
||
|
WebDavProps.davLastModified.name,
|
||
|
WebDavProps.ncHasPreview.name,
|
||
|
WebDavProps.ocSize.name,
|
||
|
WebDavProps.ocFavorite.name,
|
||
|
},
|
||
|
);
|
||
|
files.add(Result.success(data));
|
||
|
} catch (e, s) {
|
||
|
debugPrint(e.toString());
|
||
|
debugPrint(s.toString());
|
||
|
files.add(Result.error(e));
|
||
|
}
|
||
|
}
|
||
3 years ago
|
|
||
|
@override
|
||
2 years ago
|
void setPath(final List<String> p) {
|
||
|
path.add(p);
|
||
|
unawaited(refresh());
|
||
|
}
|
||
3 years ago
|
|
||
|
@override
|
||
2 years ago
|
void createFolder(final List<String> path) {
|
||
|
wrapAction(
|
||
|
() async => client.webdav.mkdir(
|
||
|
path.join('/'),
|
||
|
safe: false,
|
||
|
),
|
||
|
);
|
||
|
}
|
||
3 years ago
|
}
|