Added 'go back' functionality and fileinfos to Fileviewer
This commit is contained in:
parent
0ab44e3046
commit
f31f667fd9
@ -1,6 +1,4 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'dart:developer';
|
|
||||||
|
|
||||||
import 'package:marianum_mobile/api/marianumcloud/webdav/queries/listFiles/listFiles.dart';
|
import 'package:marianum_mobile/api/marianumcloud/webdav/queries/listFiles/listFiles.dart';
|
||||||
import 'package:marianum_mobile/api/marianumcloud/webdav/queries/listFiles/listFilesParams.dart';
|
import 'package:marianum_mobile/api/marianumcloud/webdav/queries/listFiles/listFilesParams.dart';
|
||||||
import 'package:marianum_mobile/api/marianumcloud/webdav/queries/listFiles/listFilesResponse.dart';
|
import 'package:marianum_mobile/api/marianumcloud/webdav/queries/listFiles/listFilesResponse.dart';
|
||||||
@ -11,21 +9,17 @@ class ListFilesCache extends RequestCache<ListFilesResponse> {
|
|||||||
|
|
||||||
ListFilesCache({required onUpdate, required this.path}) : super(RequestCache.cacheNothing, onUpdate) {
|
ListFilesCache({required onUpdate, required this.path}) : super(RequestCache.cacheNothing, onUpdate) {
|
||||||
String cacheName = path.replaceAll(RegExp("[^A-Za-z0-9]"), "_"); //TODO this is very evil, "/ü/" > "___" also "/ä/" > "___"
|
String cacheName = path.replaceAll(RegExp("[^A-Za-z0-9]"), "_"); //TODO this is very evil, "/ü/" > "___" also "/ä/" > "___"
|
||||||
log(cacheName);
|
|
||||||
|
|
||||||
start("MarianumMobile", "wd-folder-$cacheName");
|
start("MarianumMobile", "wd-folder-$cacheName");
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<ListFilesResponse> onLoad() async {
|
Future<ListFilesResponse> onLoad() async {
|
||||||
log("Loading remote data");
|
|
||||||
ListFilesResponse data = await ListFiles(ListFilesParams(path)).run();
|
ListFilesResponse data = await ListFiles(ListFilesParams(path)).run();
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
ListFilesResponse onLocalData(String json) {
|
ListFilesResponse onLocalData(String json) {
|
||||||
log("Loading local data");
|
|
||||||
return ListFilesResponse.fromJson(jsonDecode(json));
|
return ListFilesResponse.fromJson(jsonDecode(json));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'dart:developer';
|
|
||||||
import 'package:marianum_mobile/api/apiRequest.dart';
|
import 'package:marianum_mobile/api/apiRequest.dart';
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
import 'package:marianum_mobile/api/webuntis/webuntisError.dart';
|
import 'package:marianum_mobile/api/webuntis/webuntisError.dart';
|
||||||
@ -53,7 +52,6 @@ abstract class WebuntisApi extends ApiRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<http.Response> post(String data, Map<String, String>? headers) async {
|
Future<http.Response> post(String data, Map<String, String>? headers) async {
|
||||||
log("POST: $endpoint\n$data");
|
|
||||||
return await http
|
return await http
|
||||||
.post(endpoint, body: data, headers: headers)
|
.post(endpoint, body: data, headers: headers)
|
||||||
.timeout(
|
.timeout(
|
||||||
|
45
lib/app.dart
45
lib/app.dart
@ -19,6 +19,25 @@ 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() {
|
||||||
@ -33,6 +52,8 @@ 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();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,18 +62,7 @@ class _AppState extends State<App> {
|
|||||||
final PageController pageController = PageController();
|
final PageController pageController = PageController();
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
resizeToAvoidBottomInset: false,
|
resizeToAvoidBottomInset: false,
|
||||||
appBar: 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()));
|
|
||||||
},
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
body: Column(
|
body: Column(
|
||||||
children: [
|
children: [
|
||||||
Visibility(
|
Visibility(
|
||||||
@ -66,11 +76,11 @@ class _AppState extends State<App> {
|
|||||||
Flexible(
|
Flexible(
|
||||||
child: PageView(
|
child: PageView(
|
||||||
controller: pageController,
|
controller: pageController,
|
||||||
children: const [
|
children: [
|
||||||
Timetable(),
|
const Timetable(),
|
||||||
ChatList(),
|
const ChatList(),
|
||||||
Files(),
|
Files(setAppBar),
|
||||||
Overhang(),
|
const Overhang(),
|
||||||
],
|
],
|
||||||
onPageChanged: (page) {
|
onPageChanged: (page) {
|
||||||
setState(() {
|
setState(() {
|
||||||
@ -132,6 +142,7 @@ class _AppState extends State<App> {
|
|||||||
|
|
||||||
currentIndex: currentPage,
|
currentIndex: currentPage,
|
||||||
onTap: (item) {
|
onTap: (item) {
|
||||||
|
setAppBar(context, null);
|
||||||
setState(() {
|
setState(() {
|
||||||
currentPage = item;
|
currentPage = item;
|
||||||
pageController.jumpToPage(item);
|
pageController.jumpToPage(item);
|
||||||
|
@ -1,12 +1,18 @@
|
|||||||
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';
|
||||||
import 'package:marianum_mobile/data/dataHolder.dart';
|
import 'package:marianum_mobile/data/dataHolder.dart';
|
||||||
|
|
||||||
|
extension ExtendedList on List {
|
||||||
|
T indexOrNull<T>(int index) => index +1 <= length ? this[index] : null;
|
||||||
|
T firstOrNull<T>() => isEmpty ? null : first;
|
||||||
|
T lastOrNull<T>() => isEmpty ? null : last;
|
||||||
|
}
|
||||||
|
|
||||||
class FilesProps extends DataHolder {
|
class FilesProps extends DataHolder {
|
||||||
String _path = "/";
|
List<String> folderPath = List<String>.empty(growable: true);
|
||||||
|
String currentFolderName = "Home";
|
||||||
|
String? backPath;
|
||||||
|
|
||||||
ListFilesResponse? _listFilesResponse;
|
ListFilesResponse? _listFilesResponse;
|
||||||
ListFilesResponse get listFilesResponse => _listFilesResponse!;
|
ListFilesResponse get listFilesResponse => _listFilesResponse!;
|
||||||
@ -18,21 +24,26 @@ class FilesProps extends DataHolder {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void run() {
|
void run() {
|
||||||
|
_listFilesResponse = null;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
ListFilesCache(
|
ListFilesCache(
|
||||||
path: _path,
|
path: folderPath.isEmpty ? "/" : folderPath.join("/"),
|
||||||
onUpdate: (ListFilesResponse data) => {
|
onUpdate: (ListFilesResponse data) => {
|
||||||
log("Got cache response"),
|
|
||||||
_listFilesResponse = data,
|
_listFilesResponse = data,
|
||||||
notifyListeners(),
|
notifyListeners(),
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setPath(String path) {
|
void enterFolder(String name) {
|
||||||
_listFilesResponse = null;
|
folderPath.add(name);
|
||||||
_path = path;
|
currentFolderName = name;
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void popFolder() {
|
||||||
|
folderPath.removeLast();
|
||||||
|
if(folderPath.isEmpty) currentFolderName = "Home";
|
||||||
|
run();
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,19 +1,15 @@
|
|||||||
|
|
||||||
import 'dart:developer';
|
|
||||||
|
|
||||||
import 'package:filesize/filesize.dart';
|
import 'package:filesize/filesize.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/api/marianumcloud/webdav/queries/listFiles/listFilesParams.dart';
|
import 'package:marianum_mobile/widget/errorView.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
import '../../../api/marianumcloud/webdav/queries/listFiles/listFiles.dart';
|
|
||||||
import '../../../api/marianumcloud/webdav/queries/listFiles/listFilesResponse.dart';
|
|
||||||
import '../../../data/files/filesProps.dart';
|
import '../../../data/files/filesProps.dart';
|
||||||
|
|
||||||
class Files extends StatefulWidget {
|
class Files extends StatefulWidget {
|
||||||
const Files({Key? key}) : super(key: key);
|
Function appBar;
|
||||||
|
Files(this.appBar, {Key? key}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<Files> createState() => _FilesState();
|
State<Files> createState() => _FilesState();
|
||||||
@ -23,23 +19,37 @@ class _FilesState extends State<Files> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
|
||||||
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
|
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
|
||||||
Provider.of<FilesProps>(context, listen: false).run();
|
Provider.of<FilesProps>(context, listen: false).run();
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
super.initState();
|
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
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
Future<ListFilesResponse> files = ListFiles(ListFilesParams("/")).run();
|
|
||||||
files.then((value) => log(value.toJson().toString()));
|
|
||||||
|
|
||||||
return Consumer<FilesProps>(
|
return Consumer<FilesProps>(
|
||||||
builder: (context, value, child) {
|
builder: (context, value, child) {
|
||||||
if(value.primaryLoading()) return const Center(child: CircularProgressIndicator());
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
return ListView.builder(
|
return ListView.builder(
|
||||||
itemCount: value.listFilesResponse.files.length,
|
itemCount: value.listFilesResponse.files.length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
@ -50,61 +60,43 @@ class _FilesState extends State<Files> {
|
|||||||
subtitle: file.isDirectory ? Text("geändert ${Jiffy(file.modifiedAt).fromNow()}") : Text("${filesize(file.size)}, ${Jiffy(file.modifiedAt).fromNow()}}"),
|
subtitle: file.isDirectory ? Text("geändert ${Jiffy(file.modifiedAt).fromNow()}") : Text("${filesize(file.size)}, ${Jiffy(file.modifiedAt).fromNow()}}"),
|
||||||
trailing: Icon(file.isDirectory ? Icons.arrow_right : Icons.open_in_new),
|
trailing: Icon(file.isDirectory ? Icons.arrow_right : Icons.open_in_new),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
|
FilesProps props = Provider.of<FilesProps>(context, listen: false);
|
||||||
|
updateAppBar(props);
|
||||||
if(file.isDirectory) {
|
if(file.isDirectory) {
|
||||||
Provider.of<FilesProps>(context, listen: false).setPath(file.path);
|
props.enterFolder(file.name);
|
||||||
|
} else {
|
||||||
|
//TODO implement file download / view
|
||||||
|
showDialog(context: context, builder: (context) {
|
||||||
|
return const AlertDialog(
|
||||||
|
title: Text("Datei öffnen"),
|
||||||
|
content: Text("Das öffnen von Dateien ist noch nicht implementiert!"),
|
||||||
|
);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
onLongPress: () {
|
||||||
|
showModalBottomSheet<void>(
|
||||||
|
context: context,
|
||||||
|
builder: (context) {
|
||||||
|
return ListView(
|
||||||
|
children: [
|
||||||
|
ListTile(
|
||||||
|
leading: const Icon(Icons.delete),
|
||||||
|
title: Text("'${file.name}' Löschen"),
|
||||||
|
),
|
||||||
|
const ListTile(
|
||||||
|
leading: Icon(Icons.share),
|
||||||
|
title: Text("Teilen"),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
// 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);
|
|
||||||
// },
|
|
||||||
// );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
class OfflineBanner extends StatelessWidget {
|
class ErrorView extends StatelessWidget {
|
||||||
final IconData icon;
|
final IconData icon;
|
||||||
final String text;
|
final String text;
|
||||||
const OfflineBanner({Key? key, this.icon = Icons.report_gmailerrorred, this.text = "Es ist ein Fehler aufgetreten!"}) : super(key: key);
|
const ErrorView({Key? key, this.icon = Icons.report_gmailerrorred, this.text = "Es ist ein Fehler aufgetreten!"}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
Loading…
x
Reference in New Issue
Block a user