Added 'go back' functionality and fileinfos to Fileviewer

This commit is contained in:
2023-02-26 22:24:37 +01:00
parent 0ab44e3046
commit f31f667fd9
6 changed files with 101 additions and 95 deletions

View File

@ -1,12 +1,18 @@
import 'dart:developer';
import 'package:marianum_mobile/api/apiResponse.dart';
import 'package:marianum_mobile/api/marianumcloud/webdav/queries/listFiles/listFilesCache.dart';
import 'package:marianum_mobile/api/marianumcloud/webdav/queries/listFiles/listFilesResponse.dart';
import 'package:marianum_mobile/data/dataHolder.dart';
extension ExtendedList on List {
T indexOrNull<T>(int index) => index +1 <= length ? this[index] : null;
T firstOrNull<T>() => isEmpty ? null : first;
T lastOrNull<T>() => isEmpty ? null : last;
}
class FilesProps extends DataHolder {
String _path = "/";
List<String> folderPath = List<String>.empty(growable: true);
String currentFolderName = "Home";
String? backPath;
ListFilesResponse? _listFilesResponse;
ListFilesResponse get listFilesResponse => _listFilesResponse!;
@ -18,21 +24,26 @@ class FilesProps extends DataHolder {
@override
void run() {
_listFilesResponse = null;
notifyListeners();
ListFilesCache(
path: _path,
path: folderPath.isEmpty ? "/" : folderPath.join("/"),
onUpdate: (ListFilesResponse data) => {
log("Got cache response"),
_listFilesResponse = data,
notifyListeners(),
}
);
}
void setPath(String path) {
_listFilesResponse = null;
_path = path;
void enterFolder(String name) {
folderPath.add(name);
currentFolderName = name;
run();
}
void popFolder() {
folderPath.removeLast();
if(folderPath.isEmpty) currentFolderName = "Home";
run();
}
}