WIP: File Browsing with Backbutton
This commit is contained in:
parent
3e7dd1b0c7
commit
d7a2de4a92
23
lib/app.dart
23
lib/app.dart
@ -22,25 +22,6 @@ class App extends StatefulWidget {
|
||||
|
||||
class _AppState extends State<App> {
|
||||
int currentPage = 0;
|
||||
late AppBar _appBar;
|
||||
|
||||
void setAppBar(BuildContext context, AppBar? appBar) {
|
||||
setState(() {
|
||||
_appBar = appBar ?? AppBar(
|
||||
title: const Text("Marianum Fulda"),
|
||||
actions: <Widget>[
|
||||
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<App> {
|
||||
Provider.of<ChatListProps>(context, listen: false).run();
|
||||
});
|
||||
|
||||
setAppBar(context, null);
|
||||
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@ -75,7 +54,7 @@ class _AppState extends State<App> {
|
||||
screens: [
|
||||
const Timetable(),
|
||||
const ChatList(),
|
||||
Files(setAppBar),
|
||||
Files(const []),
|
||||
const Overhang(),
|
||||
],
|
||||
items: [
|
||||
|
@ -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<String> folderPath = List<String>.empty(growable: true);
|
||||
String currentFolderName = "Home";
|
||||
String? backPath;
|
||||
|
||||
ListFilesResponse? _listFilesResponse;
|
||||
ListFilesResponse get listFilesResponse => _listFilesResponse!;
|
||||
|
||||
void runPath(List<String> path) {
|
||||
log(path.toString());
|
||||
folderPath = path;
|
||||
run();
|
||||
}
|
||||
|
||||
@override
|
||||
List<ApiResponse?> 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(),
|
||||
}
|
||||
);
|
||||
|
@ -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<String> path;
|
||||
FileElement(this.file, this.path, {Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<FileElement> createState() => _FileElementState();
|
||||
@ -99,15 +100,20 @@ class _FileElementState extends State<FileElement> {
|
||||
subtitle: getSubtitle(),
|
||||
trailing: Icon(widget.file.isDirectory ? Icons.arrow_right : Icons.open_in_browser),
|
||||
onTap: () {
|
||||
FilesProps props = Provider.of<FilesProps>(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);
|
||||
|
||||
}
|
||||
|
@ -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<String> path;
|
||||
Files(this.path, {Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<Files> createState() => _FilesState();
|
||||
}
|
||||
|
||||
class _FilesState extends State<Files> {
|
||||
FilesProps props = FilesProps();
|
||||
ListFilesResponse? data;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
log("Init files: ${widget.path.toString()}");
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
|
||||
Provider.of<FilesProps>(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<Files> {
|
||||
)
|
||||
],
|
||||
),
|
||||
body: Consumer<FilesProps>(
|
||||
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<CacheableFile> 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<FilesProps>(
|
||||
// builder: (context, value, child) {
|
||||
//
|
||||
// if(value.listFilesResponse.files.isEmpty) {
|
||||
// return const ErrorView(text: "Der Ordner ist leer", icon: Icons.folder_off_outlined);
|
||||
// }
|
||||
//
|
||||
// List<CacheableFile> 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);
|
||||
// },
|
||||
// );
|
||||
// }
|
||||
// ),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user