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