A framework for building convergent cross-platform Nextcloud clients using Flutter.
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.

78 lines
1.8 KiB

part of '../neon_files.dart';
3 years ago
abstract interface class FilesBrowserBlocEvents {
void setPath(final PathUri uri);
3 years ago
void createFolder(final PathUri uri);
3 years ago
}
abstract interface class FilesBrowserBlocStates {
3 years ago
BehaviorSubject<Result<List<WebDavFile>>> get files;
BehaviorSubject<PathUri> get uri;
3 years ago
}
class FilesBrowserBloc extends InteractiveBloc implements FilesBrowserBlocEvents, FilesBrowserBlocStates {
3 years ago
FilesBrowserBloc(
this.options,
this.account, {
final PathUri? initialPath,
}) {
if (initialPath != null) {
uri.add(initialPath);
}
unawaited(refresh());
3 years ago
}
final FilesAppSpecificOptions options;
final Account account;
3 years ago
@override
void dispose() {
unawaited(files.close());
unawaited(uri.close());
3 years ago
super.dispose();
}
@override
BehaviorSubject<Result<List<WebDavFile>>> files = BehaviorSubject<Result<List<WebDavFile>>>();
@override
BehaviorSubject<PathUri> uri = BehaviorSubject.seeded(PathUri.cwd());
@override
Future<void> refresh() async {
await RequestManager.instance.wrapWebDav<List<WebDavFile>>(
account.id,
'files-${uri.value.path}',
files,
() => account.client.webdav.propfind(
uri.value,
prop: WebDavPropWithoutValues.fromBools(
davgetcontenttype: true,
davgetetag: true,
davgetlastmodified: true,
nchaspreview: true,
ocsize: true,
ocfavorite: true,
),
depth: WebDavDepth.one,
),
(final response) => response.toWebDavFiles().sublist(1),
emitEmptyCache: true,
);
}
3 years ago
@override
void setPath(final PathUri uri) {
this.uri.add(uri);
unawaited(refresh());
}
3 years ago
@override
void createFolder(final PathUri uri) {
wrapAction(() async => account.client.webdav.mkcol(uri));
}
3 years ago
}