File upload ui, creating folders, automatic reload
This commit is contained in:
@ -5,20 +5,19 @@ import 'dart:io';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:loader_overlay/loader_overlay.dart';
|
||||
import 'package:marianum_mobile/api/marianumcloud/webdav/queries/listFiles/cacheableFile.dart';
|
||||
import 'package:marianum_mobile/screen/pages/files/fileUpload.dart';
|
||||
import 'package:marianum_mobile/widget/errorView.dart';
|
||||
import 'package:persistent_bottom_nav_bar/persistent_tab_view.dart';
|
||||
|
||||
import '../../../api/marianumcloud/webdav/queries/listFiles/listFilesCache.dart';
|
||||
import '../../../api/marianumcloud/webdav/queries/listFiles/listFilesResponse.dart';
|
||||
import '../../../api/marianumcloud/webdav/webdavApi.dart';
|
||||
import '../../../data/files/filesProps.dart';
|
||||
import '../../../widget/filePick.dart';
|
||||
import 'fileUploadDialog.dart';
|
||||
import 'fileElement.dart';
|
||||
|
||||
class Files extends StatefulWidget {
|
||||
List<String> path;
|
||||
Files(this.path, {Key? key}) : super(key: key);
|
||||
final List<String> path;
|
||||
const Files(this.path, {Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<Files> createState() => _FilesState();
|
||||
@ -83,10 +82,11 @@ class _FilesState extends State<Files> {
|
||||
void _query() {
|
||||
ListFilesCache(
|
||||
path: widget.path.isEmpty ? "/" : widget.path.join("/"),
|
||||
onUpdate: (ListFilesResponse d) => {
|
||||
onUpdate: (ListFilesResponse d) {
|
||||
if(!context.mounted) return; // prevent setState when widget is possibly already disposed
|
||||
setState(() {
|
||||
data = d;
|
||||
}),
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
@ -100,12 +100,12 @@ class _FilesState extends State<Files> {
|
||||
appBar: AppBar(
|
||||
title: Text(widget.path.isNotEmpty ? widget.path.last : "Dateien"),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.search),
|
||||
onPressed: () => {
|
||||
// TODO implement search
|
||||
},
|
||||
),
|
||||
// IconButton(
|
||||
// icon: const Icon(Icons.search),
|
||||
// onPressed: () => {
|
||||
// // TODO implement search
|
||||
// },
|
||||
// ),
|
||||
PopupMenuButton<bool>(
|
||||
icon: Icon(currentSortDirection ? Icons.text_rotate_up : Icons.text_rotation_down),
|
||||
itemBuilder: (context) {
|
||||
@ -151,22 +151,44 @@ class _FilesState extends State<Files> {
|
||||
],
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
backgroundColor: Theme.of(context).primaryColor,
|
||||
onPressed: () {
|
||||
showDialog(context: context, builder: (context) {
|
||||
return SimpleDialog(
|
||||
children: [
|
||||
ListTile(
|
||||
leading: const Icon(Icons.folder),
|
||||
title: const Text("Neuer Ordner"),
|
||||
title: const Text("Ordner erstellen"),
|
||||
onTap: () {
|
||||
WebdavApi.webdav.then((webdav) {
|
||||
webdav.mkdirs("/MarianumMobileTest");
|
||||
Navigator.of(context).pop();
|
||||
showDialog(context: context, builder: (context) {
|
||||
var inputController = TextEditingController();
|
||||
return AlertDialog(
|
||||
title: const Text("Neuer Ordner"),
|
||||
content: TextField(
|
||||
controller: inputController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: "Name",
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
}, child: const Text("Abbrechen")),
|
||||
TextButton(onPressed: () {
|
||||
WebdavApi.webdav.then((webdav) {
|
||||
webdav.mkdirs("${widget.path.join("/")}/${inputController.text}").then((value) => _query());
|
||||
});
|
||||
Navigator.of(context).pop();
|
||||
}, child: const Text("Ordner erstellen")),
|
||||
],
|
||||
);
|
||||
});
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.file_open),
|
||||
title: const Text("Aus Dateien auswählen"),
|
||||
title: const Text("Aus Dateien hochladen"),
|
||||
onTap: () {
|
||||
context.loaderOverlay.show();
|
||||
FilePick.documentPick().then((value) {
|
||||
@ -178,7 +200,7 @@ class _FilesState extends State<Files> {
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.image),
|
||||
title: const Text("Aus Gallerie auswählen"),
|
||||
title: const Text("Aus Gallerie hochladen"),
|
||||
onTap: () {
|
||||
context.loaderOverlay.show();
|
||||
FilePick.galleryPick().then((value) {
|
||||
@ -192,7 +214,7 @@ class _FilesState extends State<Files> {
|
||||
);
|
||||
});
|
||||
},
|
||||
child: const Icon(Icons.upload),
|
||||
child: const Icon(Icons.add),
|
||||
),
|
||||
body: data == null ? const Center(child: CircularProgressIndicator()) : data!.files.isEmpty ? const ErrorView(icon: Icons.folder_off_rounded, text: "Der Ordner ist leer") : LoaderOverlay(
|
||||
child: RefreshIndicator(
|
||||
@ -203,7 +225,7 @@ class _FilesState extends State<Files> {
|
||||
child: ListView.builder(
|
||||
itemCount: files.length,
|
||||
itemBuilder: (context, index) {
|
||||
CacheableFile file = files.toList().skip(index).first;
|
||||
CacheableFile file = files.toList()[index];
|
||||
return FileElement(file, widget.path);
|
||||
},
|
||||
),
|
||||
@ -213,15 +235,13 @@ class _FilesState extends State<Files> {
|
||||
}
|
||||
|
||||
void mediaUpload(String? path) async {
|
||||
context.loaderOverlay.hide();
|
||||
|
||||
if(path == null) {
|
||||
context.loaderOverlay.hide();
|
||||
return;
|
||||
}
|
||||
|
||||
context.loaderOverlay.show();
|
||||
File file = File(path);
|
||||
var remotePath = "${widget.path.join("/")}/${file.path.split(Platform.pathSeparator).last}";
|
||||
PersistentNavBarNavigator.pushNewScreen(context, screen: FileUpload(localPath: path, remotePath: remotePath), withNavBar: false);
|
||||
|
||||
var fileName = path.split(Platform.pathSeparator).last;
|
||||
showDialog(context: context, builder: (context) => FileUploadDialog(localPath: path, remotePath: widget.path, fileName: fileName, triggerReload: () => _query()), barrierDismissible: false);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user