Prepare webdavApi.dart implementation

This commit is contained in:
2023-02-22 00:47:31 +01:00
parent edd8c1600a
commit 09003439a6
13 changed files with 390 additions and 252 deletions

View File

@ -1,11 +1,13 @@
import 'dart:developer';
import 'package:flutter/material.dart';
import 'package:marianum_mobile/api/marianumcloud/webdav/queries/listFiles/listFilesCache.dart';
import 'package:marianum_mobile/data/files/filesProps.dart';
import 'package:marianum_mobile/widget/loadingPacket.dart';
import 'package:nextcloud/nextcloud.dart';
import 'package:provider/provider.dart';
import 'package:webdav_client/webdav_client.dart';
import '../../../dataOld/incommingPackets/fileListPacket.dart';
import '../../../widget/loadingSpinner.dart';
import 'package:webdav/webdav.dart';
class Files extends StatefulWidget {
const Files({Key? key}) : super(key: key);
@ -15,256 +17,110 @@ class Files extends StatefulWidget {
}
class _FilesState extends State<Files> {
// List<String> path = List<String>.empty(growable: true);
// List<File> files = List<File>.empty(growable: true);
//
// var client = newClient(
// "https://cloud.marianum-fulda.de/remote.php/dav/files/***REMOVED***/",
// user: "***REMOVED***",
// password: "***REMOVED***",
// );
@override
void initState() {
Provider.of<FileListPacket>(context, listen: false).invoke();
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
//Provider.of<FilesProps>(context, listen: false).run();
});
super.initState();
// client.setHeaders(
// {
// "Authorization": "Bearer",
// "User-Agent": "Marianum Fulda/Alpha0.1 (Development build) ; https://mhsl.eu/id.html",
// }
// );
//
// path.add("/");
// Future.delayed(Duration.zero).then((context) => updatePath());
}
// void homeFolder() {
// path.clear();
// path.add("/");
// updatePath();
// }
//
// void popFolder() {
// if(path.length == 1) return;
// path.removeLast();
// updatePath();
// }
//
// void enterFolder(String sub) {
// path.add(sub);
// updatePath();
// }
//
// void updatePath() {
//
// final files = client.readDir(path.join("/"));
//
// showDialog(
// context: context,
// barrierDismissible: false,
// builder: (BuildContext context) {
// return const LoadingSpinner();
// }
// );
//
// files.then((value) =>
// setState(() {
// Navigator.pop(context);
// this.files.clear();
// this.files = value;
// })
// );
// }
@override
Widget build(BuildContext context) {
// List<Widget> items = List<Widget>.empty(growable: true);
//
// var counter = 0;
// for (final file in files) {
// bool isDir = file.isDir ?? false;
// String name = file.name ?? "?";
//
// items.add(ListTile(
// title: Text(file.name ?? "?"),
// leading: Icon(isDir ? Icons.folder_outlined : Icons.file_copy),
// trailing: Icon(isDir ? Icons.arrow_right : null),
// onTap: () {
// enterFolder(file.name ?? "");
// },
// onLongPress: () {
// setState(() {
// items[counter] = ListTile(
// title: Text(file.name ?? "?"),
// trailing: const Icon(Icons.delete),
// );
// });
// },
// ));
//
// }
//
// items.insert(0, AppBar(
// leading: path.length == 1 ? null : IconButton(
// icon: const Icon(Icons.keyboard_arrow_left),
// onPressed: () {
// popFolder();
// },
// ),
// actions: [
// IconButton(
// icon: const Icon(Icons.home),
// onPressed: () {
// homeFolder();
// },
// ),
//
// IconButton(
// icon: const Icon(Icons.refresh),
// onPressed: () {
// updatePath();
// },
// )
// ],
//
// title: Text(path.length == 1 ? "Dateien" : path.last),
// ));
//
// return ListView(
// children: items,
// log("NEW CLIENT");
// Client client = newClient(
// "https://***REMOVED***:***REMOVED***@cloud.marianum-fulda.de/remote.php/dav/files/***REMOVED***/",
// user: "***REMOVED***",
// password: "***REMOVED***",
// debug: true
// );
//
// // client.setHeaders(
// // {
// // "User-Agent": "Marianum Fulda/Alpha0.1 (Development build) ; https://mhsl.eu/id.html",
// // }
// // );
//
// log("DATA");
// log(client.readDir("/").toString());
return Consumer<FileListPacket>(
builder: (context, data, child) {
List<ListTile> entries = List<ListTile>.empty(growable: true);
// Future<List<FileInfo>> files = Client("https://cloud.marianum-fulda.de/remote.php/dav/files/***REMOVED***", "***REMOVED***", "***REMOVED***").ls();
// log(files.toString());
// log("REQUEST FINISH");
//
// files.then((asd) => {
// asd.forEach((element) {
// log(element.name);
// }),
// });
data.entries.forEach((element) {
entries.add(ListTile(
title: Text(element.name),
leading: Icon(element.isFolder ? Icons.folder : Icons.file_copy_outlined),
onTap: () {
if(element.isFolder) {
Provider.of<FileListPacket>(context, listen: false).invoke(
data: {
"path": element.path
},
indicateLoading: true,
);
} else {
// TODO: Open an File
}
},
onLongPress: () {
showModalBottomSheet<void>(
context: context,
builder: (context) {
return ListView(
children: [
ListTile(
leading: Icon(Icons.delete),
title: Text("'${element.name.replaceRange(20, element.name.length, " ...")}' Löschen"),
),
const ListTile(
leading: Icon(Icons.share),
title: Text("Teilen"),
)
],
);
},
);
},
));
});
// var client = NextcloudClient("https://cloud.marianum-fulda.de", username: "***REMOVED***", password: "***REMOVED***");
//
// //client.baseHeaders.putIfAbsent("Authorization", () => "Basic ***REMOVED***");
// //client.authentication?.headers.putIfAbsent("Authorization", () => "Basic ***REMOVED***");
// //client.webdav.rootClient.baseHeaders.putIfAbsent("Authorization", () => "Basic ***REMOVED***");
//
// client.webdav.ls("/").then((value) => () {
// log("TEST");
// value.forEach((element) {
// log(element.name);
// });
// });
return Scaffold(
appBar: AppBar(
leading: IconButton(
icon: const Icon(Icons.arrow_back_outlined),
onPressed: () {
Provider.of<FileListPacket>(context, listen: false).invoke(
data: {
"path": data.lastPath
},
indicateLoading: true,
);
}
),
title: Text(data.lastPath),
actions: [
IconButton(
onPressed: () {
Provider.of<FileListPacket>(context, listen: false).invoke(indicateLoading: true);
},
icon: const Icon(Icons.home)
),
PopupMenuButton(
icon: Icon(Icons.add),
itemBuilder: (context) {
return [
const PopupMenuItem<int>(
value: 0,
child: ListTile(
leading: Icon(Icons.folder),
title: Text("Ordner erstellen"),
),
),
const PopupMenuItem<int>(
value: 1,
child: ListTile(
leading: Icon(Icons.upload),
title: Text("Datei Hochladen"),
),
)
];
},
)
],
),
floatingActionButton: FloatingActionButton.small(
onPressed: () {
showModalBottomSheet(
isScrollControlled: true,
context: context,
backgroundColor: Colors.transparent,
builder: (context) {
return Container(
height: MediaQuery.of(context).size.height * 0.3,
decoration: const BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(25.0),
topRight: Radius.circular(25.0),
)
),
child: ListView(
children: const [
ListTile(
leading: Icon(Icons.create_new_folder_sharp),
title: Text("Neuer Ordner"),
),
ListTile(
leading: Icon(Icons.upload),
title: Text("Hochladen"),
)
],
),
);
},
);
},
backgroundColor: Theme.of(context).primaryColor,
child: const Icon(Icons.add),
),
body: LoadingPacket(packet: data, child: ListView(children: entries)),
);
},
return const Center(
child: Text("Currently not implemented!"),
);
// return Consumer<FilesProps>(
// builder: (context, data, child) {
//
// if(data.primaryLoading()) {
// return const Center(child: CircularProgressIndicator());
// }
//
// List<ListTile> entries = List<ListTile>.empty(growable: true);
//
// data.listFilesResponse.files.forEach((element) {
// entries.add(ListTile(
// title: Text(element.name ?? "?"),
// leading: Icon(element.isDir ?? false ? Icons.folder : Icons.file_copy_outlined),
// onTap: () {
// if(element.isDir ?? false) {
// // TODO: Open Folder
// } else {
// // TODO: Open an File
// }
// },
//
// onLongPress: () {
// showModalBottomSheet<void>(
// context: context,
// builder: (context) {
// return ListView(
// children: [
// ListTile(
// leading: const Icon(Icons.delete),
// title: Text("'${element.name?.replaceRange(20, element.name?.length, " ...")}' Löschen"),
// ),
// const ListTile(
// leading: Icon(Icons.share),
// title: Text("Teilen"),
// )
// ],
// );
// },
// );
// },
// ));
// });
//
// return ListView(children: entries);
// },
// );
}
}