Added option for file deletion
This commit is contained in:
parent
2f4e6fef37
commit
6709e3db47
@ -9,6 +9,8 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:jiffy/jiffy.dart';
|
import 'package:jiffy/jiffy.dart';
|
||||||
import 'package:marianum_mobile/api/marianumcloud/webdav/queries/listFiles/cacheableFile.dart';
|
import 'package:marianum_mobile/api/marianumcloud/webdav/queries/listFiles/cacheableFile.dart';
|
||||||
import 'package:marianum_mobile/screen/pages/files/files.dart';
|
import 'package:marianum_mobile/screen/pages/files/files.dart';
|
||||||
|
import 'package:marianum_mobile/widget/confirmDialog.dart';
|
||||||
|
import 'package:marianum_mobile/widget/unimplementedDialog.dart';
|
||||||
import 'package:path_provider/path_provider.dart';
|
import 'package:path_provider/path_provider.dart';
|
||||||
|
|
||||||
import '../../../api/marianumcloud/webdav/webdavApi.dart';
|
import '../../../api/marianumcloud/webdav/webdavApi.dart';
|
||||||
@ -16,7 +18,8 @@ import '../../../api/marianumcloud/webdav/webdavApi.dart';
|
|||||||
class FileElement extends StatefulWidget {
|
class FileElement extends StatefulWidget {
|
||||||
final CacheableFile file;
|
final CacheableFile file;
|
||||||
final List<String> path;
|
final List<String> path;
|
||||||
const FileElement(this.file, this.path, {Key? key}) : super(key: key);
|
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 {
|
static Future<DownloaderCore> download(String remotePath, String name, Function(double) onProgress, Function(OpenResult) onDone) async {
|
||||||
Directory paths = await getApplicationDocumentsDirectory();
|
Directory paths = await getApplicationDocumentsDirectory();
|
||||||
@ -147,23 +150,36 @@ class _FileElementState extends State<FileElement> {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
onLongPress: () {
|
onLongPress: () {
|
||||||
showModalBottomSheet<void>(
|
showDialog(context: context, builder: (context) {
|
||||||
context: context,
|
return SimpleDialog(
|
||||||
builder: (context) {
|
children: [
|
||||||
return ListView(
|
ListTile(
|
||||||
children: [
|
leading: const Icon(Icons.delete_outline),
|
||||||
ListTile(
|
title: const Text("Löschen"),
|
||||||
leading: const Icon(Icons.delete_outline),
|
onTap: () {
|
||||||
title: Text("'${widget.file.name}' Löschen"),
|
Navigator.of(context).pop();
|
||||||
),
|
showDialog(context: context, builder: (context) => ConfirmDialog(
|
||||||
const ListTile(
|
title: "Element löschen?",
|
||||||
leading: Icon(Icons.share_outlined),
|
content: "Das Element wird unwiederruflich gelöscht.",
|
||||||
title: Text("Teilen"),
|
onConfirm: () {
|
||||||
)
|
WebdavApi.webdav
|
||||||
],
|
.then((value) => value.delete(widget.file.path))
|
||||||
);
|
.then((value) => widget.refetch());
|
||||||
},
|
}
|
||||||
);
|
));
|
||||||
|
},
|
||||||
|
),
|
||||||
|
ListTile(
|
||||||
|
leading: const Icon(Icons.share_outlined),
|
||||||
|
title: const Text("Teilen"),
|
||||||
|
onTap: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
UnimplementedDialog.show(context);
|
||||||
|
},
|
||||||
|
)
|
||||||
|
],
|
||||||
|
);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -226,7 +226,7 @@ class _FilesState extends State<Files> {
|
|||||||
itemCount: files.length,
|
itemCount: files.length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
CacheableFile file = files.toList()[index];
|
CacheableFile file = files.toList()[index];
|
||||||
return FileElement(file, widget.path);
|
return FileElement(file, widget.path, _query);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
29
lib/widget/confirmDialog.dart
Normal file
29
lib/widget/confirmDialog.dart
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class ConfirmDialog extends StatelessWidget {
|
||||||
|
final String title;
|
||||||
|
final String content;
|
||||||
|
final IconData? icon;
|
||||||
|
final String confirmButton;
|
||||||
|
final String cancelButton;
|
||||||
|
final void Function() onConfirm;
|
||||||
|
const ConfirmDialog({Key? key, required this.title, this.content = "", this.icon, this.confirmButton = "Ok", this.cancelButton = "Abbrechen", required this.onConfirm}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return AlertDialog(
|
||||||
|
icon: icon != null ? Icon(icon) : null,
|
||||||
|
title: Text(title),
|
||||||
|
content: Text(content),
|
||||||
|
actions: [
|
||||||
|
TextButton(onPressed: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
}, child: Text(cancelButton)),
|
||||||
|
TextButton(onPressed: () {
|
||||||
|
onConfirm();
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
}, child: Text(confirmButton)),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user