Added in-app fileviewer for images and pdf files

This commit is contained in:
2023-06-18 18:15:49 +02:00
parent 6fda2f1078
commit 3d6e0cec0e
3 changed files with 77 additions and 9 deletions

View File

@ -11,6 +11,7 @@ import 'package:path_provider/path_provider.dart';
import '../../../api/marianumcloud/webdav/queries/listFiles/cacheableFile.dart';
import '../../../api/marianumcloud/webdav/webdavApi.dart';
import '../../../widget/confirmDialog.dart';
import '../../../widget/fileViewer.dart';
import '../../../widget/unimplementedDialog.dart';
import 'files.dart';
@ -20,8 +21,8 @@ class FileElement extends StatefulWidget {
final void Function() refetch;
const FileElement(this.file, this.path, this.refetch, {Key? key}) : super(key: key);
static Future<DownloaderCore> download(String remotePath, String name, Function(double) onProgress, Function(OpenResult) onDone) async {
Directory paths = await getApplicationDocumentsDirectory();
static Future<DownloaderCore> download(BuildContext context, String remotePath, String name, Function(double) onProgress, Function(OpenResult) onDone) async {
Directory paths = await getTemporaryDirectory();
String local = paths.path + Platform.pathSeparator + name;
@ -34,11 +35,12 @@ class FileElement extends StatefulWidget {
progress: ProgressImplementation(),
deleteOnCancel: true,
onDone: () {
Future<OpenResult> result = OpenFile.open(local);
result.then((value) => {
onDone(value)
});
//Future<OpenResult> result = OpenFile.open(local); // TODO legacy - refactor remove
Navigator.of(context).push(MaterialPageRoute(builder: (context) => FileViewer(path: local)));
onDone(OpenResult(message: "File viewer opened", type: ResultType.done));
// result.then((value) => {
// onDone(value)
// });
},
);
@ -125,7 +127,7 @@ class _FileElementState extends State<FileElement> {
log("Download: ${widget.file.path} to ${widget.file.name}");
downloadCore = FileElement.download(widget.file.path, widget.file.name, (progress) {
downloadCore = FileElement.download(context, widget.file.path, widget.file.name, (progress) {
setState(() => percent = progress);
}, (result) {
if(result.type != ResultType.done) {