105 lines
3.4 KiB
Dart
105 lines
3.4 KiB
Dart
import 'dart:developer';
|
|
|
|
import 'package:filesize/filesize.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/fileDownload.dart';
|
|
import 'package:marianum_mobile/widget/errorView.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
import '../../../data/files/filesProps.dart';
|
|
|
|
class Files extends StatefulWidget {
|
|
Function appBar;
|
|
Files(this.appBar, {Key? key}) : super(key: key);
|
|
|
|
@override
|
|
State<Files> createState() => _FilesState();
|
|
}
|
|
|
|
class _FilesState extends State<Files> {
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
|
|
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),
|
|
));
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return 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);
|
|
}
|
|
|
|
return ListView.builder(
|
|
itemCount: value.listFilesResponse.files.length,
|
|
itemBuilder: (context, index) {
|
|
CacheableFile file = value.listFilesResponse.files.skip(index).first;
|
|
return ListTile(
|
|
leading: Icon(file.isDirectory ? Icons.folder : Icons.file_open_outlined),
|
|
title: Text(file.name),
|
|
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),
|
|
onTap: () {
|
|
FilesProps props = Provider.of<FilesProps>(context, listen: false);
|
|
updateAppBar(props);
|
|
if(file.isDirectory) {
|
|
props.enterFolder(file.name);
|
|
} else {
|
|
//TODO implement file download / view
|
|
log(file.path);
|
|
|
|
showDialog(context: context, builder: (context) {
|
|
return FileDownload(file.path, file.name);
|
|
});
|
|
}
|
|
},
|
|
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"),
|
|
)
|
|
],
|
|
);
|
|
},
|
|
);
|
|
},
|
|
);
|
|
},
|
|
);
|
|
}
|
|
);
|
|
}
|
|
}
|