better loading indicators for timetables, talk and files

This commit is contained in:
2026-05-05 21:07:48 +02:00
parent bee5c02a4f
commit db9c3386f1
25 changed files with 439 additions and 203 deletions
@@ -11,9 +11,22 @@ class ListFiles extends WebdavApi<ListFilesParams> {
ListFiles(this.params) : super(params);
// The Nextcloud root listing is significantly slower than subdirectories on
// our instance, so it gets a much longer ceiling. Subfolders fall back to a
// tighter timeout to keep the UI responsive.
static const Duration _rootTimeout = Duration(minutes: 3);
static const Duration _subfolderTimeout = Duration(seconds: 30);
bool get _isRoot {
final p = params.path.replaceAll('/', '').trim();
return p.isEmpty;
}
@override
Future<ListFilesResponse> run() async {
var davFiles = (await (await WebdavApi.webdav).propfind(PathUri.parse(params.path))).toWebDavFiles();
final webdav = await WebdavApi.webdav;
final timeout = _isRoot ? _rootTimeout : _subfolderTimeout;
final davFiles = (await webdav.propfind(PathUri.parse(params.path)).timeout(timeout)).toWebDavFiles();
var files = davFiles.map(CacheableFile.fromDavFile).toSet();
// webdav handles subdirectories wrong, this is a fix
@@ -9,7 +9,19 @@ import 'listFilesResponse.dart';
class ListFilesCache extends RequestCache<ListFilesResponse> {
String path;
ListFilesCache({required void Function(ListFilesResponse) onUpdate, required this.path}) : super(RequestCache.cacheNothing, onUpdate) {
ListFilesCache({
required void Function(ListFilesResponse) onUpdate,
void Function(ListFilesResponse)? onCacheData,
void Function(ListFilesResponse)? onNetworkData,
void Function(Exception)? onError,
required this.path,
}) : super(
RequestCache.cacheNothing,
onUpdate,
onError: onError ?? RequestCache.ignore,
onCacheData: onCacheData,
onNetworkData: onNetworkData,
) {
var bytes = utf8.encode('MarianumMobile-$path');
var cacheName = md5.convert(bytes).toString();
start('wd-folder-$cacheName');
+4 -2
View File
@@ -15,9 +15,11 @@ abstract class WebdavApi<T> extends ApiRequest {
Future<ApiResponse> run();
static Future<WebDavClient> webdav = establishWebdavConnection();
static Future<String> webdavConnectString = buildWebdavConnectString();
static Future<WebDavClient> establishWebdavConnection() async => NextcloudClient(Uri.parse('https://${EndpointData().nextcloud().full()}'), password: AccountData().getPassword(), loginName: AccountData().getUsername()).webdav;
static Future<String> buildWebdavConnectString() async => 'https://${AccountData().buildHttpAuthString()}@${EndpointData().nextcloud().full()}/remote.php/dav/files/${AccountData().getUsername()}/';
/// Builds the WebDAV download URL without embedded credentials. Callers must
/// authenticate via the [AccountData.authHeaders] header instead.
static String buildWebdavUrl() =>
'https://${EndpointData().nextcloud().full()}/remote.php/dav/files/${AccountData().getUsername()}/';
}