diff --git a/lib/app.dart b/lib/app.dart index 409e5c6..f549f9f 100644 --- a/lib/app.dart +++ b/lib/app.dart @@ -22,25 +22,6 @@ class App extends StatefulWidget { class _AppState extends State { int currentPage = 0; - late AppBar _appBar; - - void setAppBar(BuildContext context, AppBar? appBar) { - setState(() { - _appBar = appBar ?? AppBar( - title: const Text("Marianum Fulda"), - actions: [ - IconButton( - padding: const EdgeInsets.only(right: 15), - icon: const Icon(Icons.settings), - onPressed: () { - Navigator.push(context, MaterialPageRoute(builder: (context) => const Settings())); - }, - ) - ], - ); - }); - setState(() {}); - } @override void initState() { @@ -55,8 +36,6 @@ class _AppState extends State { Provider.of(context, listen: false).run(); }); - setAppBar(context, null); - super.initState(); } @@ -75,7 +54,7 @@ class _AppState extends State { screens: [ const Timetable(), const ChatList(), - Files(setAppBar), + Files(const []), const Overhang(), ], items: [ diff --git a/lib/data/files/filesProps.dart b/lib/data/files/filesProps.dart index f5c083e..b45a5a3 100644 --- a/lib/data/files/filesProps.dart +++ b/lib/data/files/filesProps.dart @@ -1,4 +1,6 @@ +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'; @@ -13,11 +15,16 @@ extension ExtendedList on List { class FilesProps extends DataHolder { List folderPath = List.empty(growable: true); String currentFolderName = "Home"; - String? backPath; ListFilesResponse? _listFilesResponse; ListFilesResponse get listFilesResponse => _listFilesResponse!; + void runPath(List path) { + log(path.toString()); + folderPath = path; + run(); + } + @override List properties() { return [_listFilesResponse]; @@ -27,10 +34,12 @@ class FilesProps extends DataHolder { void run() { _listFilesResponse = null; notifyListeners(); + log("fetch data"); ListFilesCache( path: folderPath.isEmpty ? "/" : folderPath.join("/"), onUpdate: (ListFilesResponse data) => { _listFilesResponse = data, + log("got data"), notifyListeners(), } ); diff --git a/lib/screen/pages/files/fileElement.dart b/lib/screen/pages/files/fileElement.dart index 9d2fba7..25fa159 100644 --- a/lib/screen/pages/files/fileElement.dart +++ b/lib/screen/pages/files/fileElement.dart @@ -8,6 +8,7 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:jiffy/jiffy.dart'; import 'package:marianum_mobile/api/marianumcloud/webdav/queries/listFiles/cacheableFile.dart'; +import 'package:marianum_mobile/screen/pages/files/files.dart'; import 'package:path_provider/path_provider.dart'; import 'package:provider/provider.dart'; @@ -16,8 +17,8 @@ import '../../../data/files/filesProps.dart'; class FileElement extends StatefulWidget { CacheableFile file; - Function updateAppBar; - FileElement(this.file, this.updateAppBar, {Key? key}) : super(key: key); + List path; + FileElement(this.file, this.path, {Key? key}) : super(key: key); @override State createState() => _FileElementState(); @@ -99,15 +100,20 @@ class _FileElementState extends State { subtitle: getSubtitle(), trailing: Icon(widget.file.isDirectory ? Icons.arrow_right : Icons.open_in_browser), onTap: () { - FilesProps props = Provider.of(context, listen: false); - widget.updateAppBar(props); if(widget.file.isDirectory) { - props.enterFolder(widget.file.name); + Navigator.of(context).push(MaterialPageRoute( + builder: (context) { + return Files(widget.path.toList()..add(widget.file.name)); + }, + )); + //props.enterFolder(widget.file.name); } else { setState(() { widget.file.currentlyDownloading = true; }); + log("Download: ${widget.file.path} to ${widget.file.name}"); + download(widget.file.path, widget.file.name); } diff --git a/lib/screen/pages/files/files.dart b/lib/screen/pages/files/files.dart index d67a9c6..10cf63e 100644 --- a/lib/screen/pages/files/files.dart +++ b/lib/screen/pages/files/files.dart @@ -1,43 +1,41 @@ +import 'dart:developer'; + import 'package:flutter/material.dart'; import 'package:marianum_mobile/api/marianumcloud/webdav/queries/listFiles/cacheableFile.dart'; import 'package:marianum_mobile/widget/errorView.dart'; import 'package:provider/provider.dart'; +import '../../../api/marianumcloud/webdav/queries/listFiles/listFilesCache.dart'; +import '../../../api/marianumcloud/webdav/queries/listFiles/listFilesResponse.dart'; import '../../../data/files/filesProps.dart'; import 'fileElement.dart'; class Files extends StatefulWidget { - Function appBar; - Files(this.appBar, {Key? key}) : super(key: key); + List path; + Files(this.path, {Key? key}) : super(key: key); @override State createState() => _FilesState(); } class _FilesState extends State { + FilesProps props = FilesProps(); + ListFilesResponse? data; @override void initState() { super.initState(); + log("Init files: ${widget.path.toString()}"); - WidgetsBinding.instance.addPostFrameCallback((timeStamp) { - Provider.of(context, listen: false).run(); - }); - } - - void updateAppBar(FilesProps props) { - WidgetsBinding.instance.addPostFrameCallback((timeStamp) { - widget.appBar(context, AppBar( - leading: BackButton( - onPressed: () { - updateAppBar(props); - props.popFolder(); - }, - ), - title: Text(props.currentFolderName), - )); - }); + ListFilesCache( + path: widget.path.isEmpty ? "/" : widget.path.join("/"), + onUpdate: (ListFilesResponse d) => { + setState(() { + data = d; + }), + } + ); } @override @@ -56,26 +54,32 @@ class _FilesState extends State { ) ], ), - body: Consumer( - builder: (context, value, child) { - if(value.primaryLoading()) return const Center(child: CircularProgressIndicator()); - - if(value.listFilesResponse.files.isEmpty) { - return const ErrorView(text: "Der Ordner ist leer", icon: Icons.folder_off_outlined); - } - - List files = value.listFilesResponse.files.toList(); - files.sort((a, b) => a.isDirectory ? -1 : 1); - - return ListView.builder( - itemCount: files.length, - itemBuilder: (context, index) { - CacheableFile file = files.skip(index).first; - return FileElement(file, updateAppBar); - }, - ); - } - ), + body: data == null ? Center(child: CircularProgressIndicator()) : ListView.builder( + itemCount: data!.files.toList().length, + itemBuilder: (context, index) { + CacheableFile file = data!.files.toList().skip(index).first; + return FileElement(file, widget.path); + }, + ), + // Consumer( + // builder: (context, value, child) { + // + // if(value.listFilesResponse.files.isEmpty) { + // return const ErrorView(text: "Der Ordner ist leer", icon: Icons.folder_off_outlined); + // } + // + // List files = value.listFilesResponse.files.toList(); + // files.sort((a, b) => a.isDirectory ? -1 : 1); + // + // return ListView.builder( + // itemCount: files.length, + // itemBuilder: (context, index) { + // CacheableFile file = files.skip(index).first; + // return FileElement(file, props); + // }, + // ); + // } + // ), ); } }