Merge pull request 'added upload with multiple files' (#61) from develop-uploadMultipleFiles into develop
Reviewed-on: #61
This commit is contained in:
commit
92361ec455
@ -1,233 +0,0 @@
|
|||||||
import 'dart:developer';
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:async/async.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:nextcloud/nextcloud.dart';
|
|
||||||
|
|
||||||
import '../../../api/marianumcloud/webdav/webdavApi.dart';
|
|
||||||
|
|
||||||
class FileUploadDialog extends StatefulWidget {
|
|
||||||
final String localPath;
|
|
||||||
final List<String> remotePath;
|
|
||||||
final String fileName;
|
|
||||||
final void Function() onUploadFinished;
|
|
||||||
|
|
||||||
final bool doShowFinish;
|
|
||||||
|
|
||||||
const FileUploadDialog({super.key, required this.localPath, required this.remotePath, required this.fileName, required this.onUploadFinished, this.doShowFinish = true});
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<FileUploadDialog> createState() => _FileUploadDialogState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _FileUploadDialogState extends State<FileUploadDialog> {
|
|
||||||
FileUploadState state = FileUploadState.naming;
|
|
||||||
CancelableOperation? cancelableOperation;
|
|
||||||
late String targetFileName;
|
|
||||||
late String remoteFolderName;
|
|
||||||
late String fullRemotePath = "${widget.remotePath.join("/")}/$targetFileName";
|
|
||||||
String? lastError;
|
|
||||||
|
|
||||||
TextEditingController fileNameController = TextEditingController();
|
|
||||||
|
|
||||||
|
|
||||||
Future<void> upload({bool override = false}) async {
|
|
||||||
setState(() {
|
|
||||||
state = FileUploadState.upload;
|
|
||||||
});
|
|
||||||
|
|
||||||
var webdavClient = await WebdavApi.webdav;
|
|
||||||
|
|
||||||
if(!override) {
|
|
||||||
setState(() {
|
|
||||||
state = FileUploadState.checkConflict;
|
|
||||||
});
|
|
||||||
var result = (await webdavClient.propfind(PathUri.parse(widget.remotePath.join('/')))).responses;
|
|
||||||
if(result.any((element) => element.href!.endsWith('/$targetFileName'))) {
|
|
||||||
setState(() {
|
|
||||||
state = FileUploadState.conflict;
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
setState(() {
|
|
||||||
state = FileUploadState.upload;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var uploadTask = webdavClient.putFile(File(widget.localPath), FileStat.statSync(widget.localPath), PathUri.parse(fullRemotePath)); // TODO use onProgress from putFile
|
|
||||||
uploadTask.then(Future<HttpClientResponse?>.value).catchError((e) {
|
|
||||||
setState(() {
|
|
||||||
state = FileUploadState.error;
|
|
||||||
});
|
|
||||||
return null;
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
cancelableOperation = CancelableOperation<HttpClientResponse>.fromFuture(
|
|
||||||
uploadTask,
|
|
||||||
onCancel: () => log('Upload cancelled'),
|
|
||||||
);
|
|
||||||
|
|
||||||
cancelableOperation!.then((value) {
|
|
||||||
setState(() {
|
|
||||||
state = FileUploadState.done;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void cancel() {
|
|
||||||
cancelableOperation?.cancel();
|
|
||||||
setState(() {
|
|
||||||
state = FileUploadState.naming;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
targetFileName = widget.fileName;
|
|
||||||
remoteFolderName = widget.remotePath.isNotEmpty ? widget.remotePath.last : '/';
|
|
||||||
fileNameController.text = widget.fileName;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
if(state == FileUploadState.naming) {
|
|
||||||
return AlertDialog(
|
|
||||||
title: const Text('Datei hochladen'),
|
|
||||||
content: Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
TextField(
|
|
||||||
controller: fileNameController,
|
|
||||||
onChanged: (input) {
|
|
||||||
targetFileName = input;
|
|
||||||
},
|
|
||||||
autocorrect: false,
|
|
||||||
decoration: const InputDecoration(
|
|
||||||
labelText: 'Dateiname',
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
actions: [
|
|
||||||
TextButton(onPressed: () {
|
|
||||||
Navigator.of(context).pop();
|
|
||||||
}, child: const Text('Abbrechen')),
|
|
||||||
TextButton(onPressed: () async {
|
|
||||||
upload();
|
|
||||||
}, child: const Text('Hochladen')),
|
|
||||||
],
|
|
||||||
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(state == FileUploadState.conflict) {
|
|
||||||
return AlertDialog(
|
|
||||||
icon: const Icon(Icons.error_outline),
|
|
||||||
title: const Text('Datei konflikt'),
|
|
||||||
content: Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
Text("Es gibt bereits eine Datei mit dem Namen $targetFileName in dem ausgewählten Ordner '$remoteFolderName'", textAlign: TextAlign.center),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
actions: [
|
|
||||||
TextButton(onPressed: () {
|
|
||||||
setState(() {
|
|
||||||
state = FileUploadState.naming;
|
|
||||||
});
|
|
||||||
}, child: const Text('Datei umbenennen')),
|
|
||||||
TextButton(onPressed: () {
|
|
||||||
upload(override: true);
|
|
||||||
}, child: const Text('Datei überschreiben')),
|
|
||||||
],
|
|
||||||
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(state == FileUploadState.upload || state == FileUploadState.checkConflict) {
|
|
||||||
return AlertDialog(
|
|
||||||
icon: const Icon(Icons.upload),
|
|
||||||
title: const Text('Hochladen'),
|
|
||||||
content: Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
children: [
|
|
||||||
Visibility(
|
|
||||||
visible: state == FileUploadState.upload,
|
|
||||||
replacement: const Text('Prüfe auf dateikonflikte...'),
|
|
||||||
child: const Text('Upload läuft!\nDies kann je nach Dateigröße einige Zeit dauern...', textAlign: TextAlign.center),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 30),
|
|
||||||
const CircularProgressIndicator()
|
|
||||||
],
|
|
||||||
),
|
|
||||||
actions: const [
|
|
||||||
// TODO implement working upload cancelling
|
|
||||||
// TextButton(onPressed: () {
|
|
||||||
// cancel();
|
|
||||||
// }, child: const Text("Abbrechen")),
|
|
||||||
],
|
|
||||||
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(state == FileUploadState.done) {
|
|
||||||
widget.onUploadFinished();
|
|
||||||
if(!widget.doShowFinish) {
|
|
||||||
Navigator.of(context).pop();
|
|
||||||
return const SizedBox.shrink();
|
|
||||||
}
|
|
||||||
return AlertDialog(
|
|
||||||
icon: const Icon(Icons.done),
|
|
||||||
title: const Text('Upload fertig'),
|
|
||||||
content: Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
Text("Die Datei wurde erfolgreich nach '$remoteFolderName' hochgeladen!", textAlign: TextAlign.center),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
actions: [
|
|
||||||
TextButton(onPressed: () {
|
|
||||||
Navigator.of(context).pop();
|
|
||||||
}, child: const Text('Fertig')),
|
|
||||||
],
|
|
||||||
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(state == FileUploadState.error) {
|
|
||||||
return AlertDialog(
|
|
||||||
icon: const Icon(Icons.error_outline),
|
|
||||||
title: const Text('Fehler'),
|
|
||||||
content: const Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
Text('Es ist ein Fehler aufgetreten!', textAlign: TextAlign.center),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
actions: [
|
|
||||||
TextButton(onPressed: () {
|
|
||||||
Navigator.of(context).pop();
|
|
||||||
}, child: const Text('Schlißen')),
|
|
||||||
],
|
|
||||||
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
throw UnimplementedError('Invalid state');
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
enum FileUploadState {
|
|
||||||
naming,
|
|
||||||
checkConflict,
|
|
||||||
conflict,
|
|
||||||
upload,
|
|
||||||
done,
|
|
||||||
error
|
|
||||||
}
|
|
@ -4,6 +4,7 @@ import 'dart:io';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:loader_overlay/loader_overlay.dart';
|
import 'package:loader_overlay/loader_overlay.dart';
|
||||||
import 'package:nextcloud/nextcloud.dart';
|
import 'package:nextcloud/nextcloud.dart';
|
||||||
|
import 'package:persistent_bottom_nav_bar_v2/persistent_bottom_nav_bar_v2.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
import '../../../api/marianumcloud/webdav/queries/listFiles/cacheableFile.dart';
|
import '../../../api/marianumcloud/webdav/queries/listFiles/cacheableFile.dart';
|
||||||
@ -15,8 +16,8 @@ import '../../../storage/base/settingsProvider.dart';
|
|||||||
import '../../../widget/loadingSpinner.dart';
|
import '../../../widget/loadingSpinner.dart';
|
||||||
import '../../../widget/placeholderView.dart';
|
import '../../../widget/placeholderView.dart';
|
||||||
import '../../../widget/filePick.dart';
|
import '../../../widget/filePick.dart';
|
||||||
import 'fileUploadDialog.dart';
|
|
||||||
import 'fileElement.dart';
|
import 'fileElement.dart';
|
||||||
|
import 'filesUploadDialog.dart';
|
||||||
|
|
||||||
class Files extends StatefulWidget {
|
class Files extends StatefulWidget {
|
||||||
final List<String> path;
|
final List<String> path;
|
||||||
@ -88,7 +89,6 @@ class _FilesState extends State<Files> {
|
|||||||
ListFilesCache(
|
ListFilesCache(
|
||||||
path: widget.path.isEmpty ? '/' : widget.path.join('/'),
|
path: widget.path.isEmpty ? '/' : widget.path.join('/'),
|
||||||
onUpdate: (ListFilesResponse d) {
|
onUpdate: (ListFilesResponse d) {
|
||||||
if(!context.mounted) return; // prevent setState when widget is possibly already disposed
|
|
||||||
d.files.removeWhere((element) => element.name.isEmpty || element.name == widget.path.lastOrNull());
|
d.files.removeWhere((element) => element.name.isEmpty || element.name == widget.path.lastOrNull());
|
||||||
setState(() {
|
setState(() {
|
||||||
data = d;
|
data = d;
|
||||||
@ -97,6 +97,18 @@ class _FilesState extends State<Files> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> mediaUpload(List<String>? paths) async {
|
||||||
|
if(paths == null) return;
|
||||||
|
|
||||||
|
pushScreen(
|
||||||
|
context,
|
||||||
|
withNavBar: false,
|
||||||
|
screen: FilesUploadDialog(filePaths: paths, remotePath: widget.path.join('/'), onUploadFinished: (uploadedFilePaths) => _query()),
|
||||||
|
);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
var files = data?.sortBy(
|
var files = data?.sortBy(
|
||||||
@ -144,7 +156,7 @@ class _FilesState extends State<Files> {
|
|||||||
children: [
|
children: [
|
||||||
Icon(SortOptions.getOption(key).icon, color: Theme.of(context).colorScheme.onSurface),
|
Icon(SortOptions.getOption(key).icon, color: Theme.of(context).colorScheme.onSurface),
|
||||||
const SizedBox(width: 15),
|
const SizedBox(width: 15),
|
||||||
Text(SortOptions.getOption(key).displayName)
|
Text(SortOptions.getOption(key).displayName),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
)).toList(),
|
)).toList(),
|
||||||
@ -197,7 +209,6 @@ class _FilesState extends State<Files> {
|
|||||||
leading: const Icon(Icons.upload_file),
|
leading: const Icon(Icons.upload_file),
|
||||||
title: const Text('Aus Dateien hochladen'),
|
title: const Text('Aus Dateien hochladen'),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
context.loaderOverlay.show();
|
|
||||||
FilePick.documentPick().then(mediaUpload);
|
FilePick.documentPick().then(mediaUpload);
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
},
|
},
|
||||||
@ -208,9 +219,8 @@ class _FilesState extends State<Files> {
|
|||||||
leading: const Icon(Icons.add_a_photo_outlined),
|
leading: const Icon(Icons.add_a_photo_outlined),
|
||||||
title: const Text('Aus Gallerie hochladen'),
|
title: const Text('Aus Gallerie hochladen'),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
context.loaderOverlay.show();
|
FilePick.multipleGalleryPick().then((value) {
|
||||||
FilePick.galleryPick().then((value) {
|
if(value != null) mediaUpload(value.map((e) => e.path).toList());
|
||||||
mediaUpload(value?.path);
|
|
||||||
});
|
});
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
},
|
},
|
||||||
@ -239,15 +249,4 @@ class _FilesState extends State<Files> {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> mediaUpload(String? path) async {
|
|
||||||
context.loaderOverlay.hide();
|
|
||||||
|
|
||||||
if(path == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var fileName = path.split(Platform.pathSeparator).last;
|
|
||||||
showDialog(context: context, builder: (context) => FileUploadDialog(localPath: path, remotePath: widget.path, fileName: fileName, onUploadFinished: _query), barrierDismissible: false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
311
lib/view/pages/files/filesUploadDialog.dart
Normal file
311
lib/view/pages/files/filesUploadDialog.dart
Normal file
@ -0,0 +1,311 @@
|
|||||||
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:loader_overlay/loader_overlay.dart';
|
||||||
|
import 'package:nextcloud/nextcloud.dart';
|
||||||
|
import 'package:uuid/uuid.dart';
|
||||||
|
|
||||||
|
import '../../../api/marianumcloud/webdav/webdavApi.dart';
|
||||||
|
import '../../../widget/confirmDialog.dart';
|
||||||
|
import '../../../widget/focusBehaviour.dart';
|
||||||
|
|
||||||
|
class FilesUploadDialog extends StatefulWidget {
|
||||||
|
final List<String> filePaths;
|
||||||
|
final String remotePath;
|
||||||
|
final void Function(List<String> uploadedFilePaths) onUploadFinished;
|
||||||
|
final bool uniqueNames;
|
||||||
|
|
||||||
|
const FilesUploadDialog({super.key, required this.filePaths, required this.remotePath, required this.onUploadFinished, this.uniqueNames = false});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<FilesUploadDialog> createState() => _FilesUploadDialogState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class UploadableFile {
|
||||||
|
TextEditingController fileNameController = TextEditingController();
|
||||||
|
String filePath;
|
||||||
|
String fileName;
|
||||||
|
double? _uploadProgress;
|
||||||
|
bool isConflicting = false;
|
||||||
|
|
||||||
|
UploadableFile(this.filePath, this.fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class _FilesUploadDialogState extends State<FilesUploadDialog> {
|
||||||
|
late List<UploadableFile> _uploadableFiles;
|
||||||
|
bool _isUploading = false;
|
||||||
|
double _overallProgressValue = 0.0;
|
||||||
|
String _infoText = '';
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
|
||||||
|
_uploadableFiles = widget.filePaths.map((filePath) {
|
||||||
|
var fileName = filePath.split(Platform.pathSeparator).last;
|
||||||
|
return UploadableFile(filePath, fileName);
|
||||||
|
}).toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
void showHttpErrorCode(int httpErrorCode){
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (BuildContext context) => AlertDialog(
|
||||||
|
title: const Text('Ein Fehler ist aufgetreten'),
|
||||||
|
contentPadding: const EdgeInsets.all(10),
|
||||||
|
content: Text('Error code: $httpErrorCode'),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => Navigator.of(context).pop(),
|
||||||
|
child: const Text('Schließen', textAlign: TextAlign.center),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> uploadFiles({bool override = false}) async {
|
||||||
|
setState(() {
|
||||||
|
_isUploading = true;
|
||||||
|
_infoText = 'Vorbereiten';
|
||||||
|
for (var file in _uploadableFiles) {
|
||||||
|
file.isConflicting = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var webdavClient = await WebdavApi.webdav;
|
||||||
|
|
||||||
|
if (!override) {
|
||||||
|
var result = (await webdavClient.propfind(PathUri.parse(widget.remotePath))).responses;
|
||||||
|
var conflictingFiles = _uploadableFiles.where((file) {
|
||||||
|
var fileName = file.fileName;
|
||||||
|
return result.any((element) => Uri.decodeComponent(element.href!).endsWith('/$fileName'));
|
||||||
|
}).toList();
|
||||||
|
|
||||||
|
if(conflictingFiles.isNotEmpty) {
|
||||||
|
bool replaceFiles = await showDialog(
|
||||||
|
context: context,
|
||||||
|
barrierDismissible: false,
|
||||||
|
builder: (context) => AlertDialog(
|
||||||
|
contentPadding: const EdgeInsets.all(10),
|
||||||
|
title: const Text('Konflikt', textAlign: TextAlign.center),
|
||||||
|
content: conflictingFiles.length == 1 ?
|
||||||
|
Text(
|
||||||
|
'Eine Datei mit dem Namen "${conflictingFiles.map((e) => e.fileName).first}" existiert bereits.',
|
||||||
|
textAlign: TextAlign.left,
|
||||||
|
) :
|
||||||
|
SingleChildScrollView(
|
||||||
|
child: Text(
|
||||||
|
'${conflictingFiles.length} Dateien mit folgenden Namen existieren bereits: \n${conflictingFiles.map((e) => '\n - ${e.fileName}').join('')}',
|
||||||
|
textAlign: TextAlign.left,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.pop(context, false);
|
||||||
|
},
|
||||||
|
child: const Text('Bearbeiten', textAlign: TextAlign.center),
|
||||||
|
),
|
||||||
|
TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (context) => ConfirmDialog(
|
||||||
|
title: 'Bestätigen?',
|
||||||
|
content: 'Bist du sicher, dass du ${conflictingFiles.length} Dateien überschreiben möchtest?',
|
||||||
|
onConfirm: () {
|
||||||
|
Navigator.pop(context, true);
|
||||||
|
},
|
||||||
|
confirmButton: 'Ja',
|
||||||
|
cancelButton: 'Nein',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
},
|
||||||
|
child: const Text('Überschreiben', textAlign: TextAlign.center),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
if(!replaceFiles) {
|
||||||
|
setState(() {
|
||||||
|
_isUploading = false;
|
||||||
|
_overallProgressValue = 0.0;
|
||||||
|
_infoText = '';
|
||||||
|
for (var element in conflictingFiles) {
|
||||||
|
element.isConflicting = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var uploadetFilePaths = <String>[];
|
||||||
|
for (var file in _uploadableFiles) {
|
||||||
|
var fileName = file.fileName;
|
||||||
|
var filePath = file.filePath;
|
||||||
|
|
||||||
|
if(widget.uniqueNames) fileName = '${fileName.split('.').first}-${const Uuid().v4()}.${fileName.split('.').last}';
|
||||||
|
|
||||||
|
var fullRemotePath = '${widget.remotePath}/$fileName';
|
||||||
|
|
||||||
|
setState(() {
|
||||||
|
_infoText = '${_uploadableFiles.indexOf(file) + 1}/${_uploadableFiles.length}';
|
||||||
|
});
|
||||||
|
|
||||||
|
var uploadTask = await webdavClient.putFile(
|
||||||
|
File(filePath),
|
||||||
|
FileStat.statSync(filePath),
|
||||||
|
PathUri.parse(fullRemotePath),
|
||||||
|
onProgress: (progress) {
|
||||||
|
setState(() {
|
||||||
|
file._uploadProgress = progress;
|
||||||
|
_overallProgressValue = ((progress + _uploadableFiles.indexOf(file)) / _uploadableFiles.length).toDouble();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
if(uploadTask.statusCode < 200 || uploadTask.statusCode > 299) {
|
||||||
|
setState(() {
|
||||||
|
_isUploading = false;
|
||||||
|
_overallProgressValue = 0.0;
|
||||||
|
_infoText = '';
|
||||||
|
});
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
showHttpErrorCode(uploadTask.statusCode);
|
||||||
|
} else {
|
||||||
|
uploadetFilePaths.add(fullRemotePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setState(() {
|
||||||
|
_isUploading = false;
|
||||||
|
_overallProgressValue = 0.0;
|
||||||
|
_infoText = '';
|
||||||
|
});
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
widget.onUploadFinished(uploadetFilePaths);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) => Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
title: const Text('Dateien hochladen'),
|
||||||
|
automaticallyImplyLeading: false,
|
||||||
|
),
|
||||||
|
body: LoaderOverlay(
|
||||||
|
overlayWholeScreen: true,
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: ListView.builder(
|
||||||
|
itemCount: _uploadableFiles.length,
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
final currentFile = _uploadableFiles[index];
|
||||||
|
currentFile.fileNameController.text = currentFile.fileName;
|
||||||
|
return ListTile(
|
||||||
|
title: TextField(
|
||||||
|
readOnly: _isUploading,
|
||||||
|
controller: currentFile.fileNameController,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
border: const UnderlineInputBorder(),
|
||||||
|
label: Text('Datei ${index+1}'),
|
||||||
|
errorText: currentFile.isConflicting ? 'existiert bereits' : null,
|
||||||
|
errorStyle: const TextStyle(color: Colors.red),
|
||||||
|
),
|
||||||
|
onChanged: (input) {
|
||||||
|
currentFile.fileName = input;
|
||||||
|
},
|
||||||
|
onTapOutside: (PointerDownEvent event) {
|
||||||
|
FocusBehaviour.textFieldTapOutside(context);
|
||||||
|
if(currentFile.isConflicting){
|
||||||
|
setState(() {
|
||||||
|
currentFile.isConflicting = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onEditingComplete: () {
|
||||||
|
if(currentFile.isConflicting){
|
||||||
|
setState(() {
|
||||||
|
currentFile.isConflicting = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
subtitle: _isUploading && (currentFile._uploadProgress ?? 0) < 1 ? LinearProgressIndicator(
|
||||||
|
value: currentFile._uploadProgress,
|
||||||
|
borderRadius: const BorderRadius.all(Radius.circular(2)),
|
||||||
|
) : null,
|
||||||
|
trailing: Container(
|
||||||
|
width: 24,
|
||||||
|
height: 24,
|
||||||
|
padding: EdgeInsets.zero,
|
||||||
|
child: IconButton(
|
||||||
|
tooltip: 'Datei entfernen',
|
||||||
|
padding: EdgeInsets.zero,
|
||||||
|
onPressed: () {
|
||||||
|
if(!_isUploading) {
|
||||||
|
if(_uploadableFiles.length-1 <= 0) Navigator.of(context).pop();
|
||||||
|
setState(() {
|
||||||
|
_uploadableFiles.removeAt(index);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
icon: const Icon(Icons.delete_outlined),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(left: 15, right: 15, bottom: 15, top: 5),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.end,
|
||||||
|
children: [
|
||||||
|
Visibility(
|
||||||
|
visible: !_isUploading,
|
||||||
|
child: TextButton(
|
||||||
|
onPressed: () => Navigator.of(context).pop(),
|
||||||
|
child: const Text('Abbrechen'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const Expanded(child: SizedBox.shrink()),
|
||||||
|
Visibility(
|
||||||
|
visible: _isUploading,
|
||||||
|
replacement: TextButton(
|
||||||
|
onPressed: () => uploadFiles(override: widget.uniqueNames),
|
||||||
|
child: const Text('Hochladen'),
|
||||||
|
),
|
||||||
|
child: Visibility(
|
||||||
|
visible: _infoText.length < 5,
|
||||||
|
replacement: Row(
|
||||||
|
children: [
|
||||||
|
Text(_infoText),
|
||||||
|
const SizedBox(width: 15),
|
||||||
|
CircularProgressIndicator(value: _overallProgressValue),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
child: Stack(
|
||||||
|
alignment: Alignment.center,
|
||||||
|
children: [
|
||||||
|
CircularProgressIndicator(value: _overallProgressValue),
|
||||||
|
Center(child: Text(_infoText)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
@ -1,10 +1,9 @@
|
|||||||
|
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:loader_overlay/loader_overlay.dart';
|
|
||||||
import 'package:nextcloud/nextcloud.dart';
|
import 'package:nextcloud/nextcloud.dart';
|
||||||
|
import 'package:persistent_bottom_nav_bar_v2/persistent_bottom_nav_bar_v2.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:uuid/uuid.dart';
|
|
||||||
|
|
||||||
import '../../../../api/marianumcloud/files-sharing/fileSharingApi.dart';
|
import '../../../../api/marianumcloud/files-sharing/fileSharingApi.dart';
|
||||||
import '../../../../api/marianumcloud/files-sharing/fileSharingApiParams.dart';
|
import '../../../../api/marianumcloud/files-sharing/fileSharingApiParams.dart';
|
||||||
@ -15,7 +14,7 @@ import '../../../../model/chatList/chatProps.dart';
|
|||||||
import '../../../../storage/base/settingsProvider.dart';
|
import '../../../../storage/base/settingsProvider.dart';
|
||||||
import '../../../../widget/filePick.dart';
|
import '../../../../widget/filePick.dart';
|
||||||
import '../../../../widget/focusBehaviour.dart';
|
import '../../../../widget/focusBehaviour.dart';
|
||||||
import '../../files/fileUploadDialog.dart';
|
import '../../files/filesUploadDialog.dart';
|
||||||
|
|
||||||
class ChatTextfield extends StatefulWidget {
|
class ChatTextfield extends StatefulWidget {
|
||||||
final String sendToToken;
|
final String sendToToken;
|
||||||
@ -34,32 +33,37 @@ class _ChatTextfieldState extends State<ChatTextfield> {
|
|||||||
Provider.of<ChatProps>(context, listen: false).run();
|
Provider.of<ChatProps>(context, listen: false).run();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> mediaUpload(String? path) async {
|
void share(String shareFolder, List<String> filePaths) {
|
||||||
context.loaderOverlay.hide();
|
for (var element in filePaths) {
|
||||||
|
var fileName = element.split(Platform.pathSeparator).last;
|
||||||
if(path == null) {
|
FileSharingApi().share(FileSharingApiParams(
|
||||||
return;
|
shareType: 10,
|
||||||
|
shareWith: widget.sendToToken,
|
||||||
|
path: '$shareFolder/$fileName',
|
||||||
|
)).then((value) => _query());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> mediaUpload(List<String>? paths) async {
|
||||||
|
if (paths == null) return;
|
||||||
|
|
||||||
var filename = "${path.split("/").last.split(".").first}-${const Uuid().v4()}.${path.split(".").last}";
|
|
||||||
var shareFolder = 'MarianumMobile';
|
var shareFolder = 'MarianumMobile';
|
||||||
WebdavApi.webdav.then((webdav) {
|
WebdavApi.webdav.then((webdav) {
|
||||||
webdav.mkcol(PathUri.parse('/$shareFolder'));
|
webdav.mkcol(PathUri.parse('/$shareFolder'));
|
||||||
});
|
});
|
||||||
|
|
||||||
showDialog(context: context, builder: (context) => FileUploadDialog(
|
pushScreen(
|
||||||
doShowFinish: false,
|
context,
|
||||||
fileName: filename,
|
withNavBar: false,
|
||||||
localPath: path,
|
screen: FilesUploadDialog(
|
||||||
remotePath: [shareFolder],
|
filePaths: paths,
|
||||||
onUploadFinished: () {
|
remotePath: shareFolder,
|
||||||
FileSharingApi().share(FileSharingApiParams(
|
onUploadFinished: (uploadedFilePaths) {
|
||||||
shareType: 10,
|
share(shareFolder, uploadedFilePaths);
|
||||||
shareWith: widget.sendToToken,
|
},
|
||||||
path: '$shareFolder/$filename',
|
uniqueNames: true,
|
||||||
)).then((value) => _query());
|
),
|
||||||
},
|
);
|
||||||
), barrierDismissible: false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setDraft(String text) {
|
void setDraft(String text) {
|
||||||
@ -97,7 +101,6 @@ class _ChatTextfieldState extends State<ChatTextfield> {
|
|||||||
leading: const Icon(Icons.file_open),
|
leading: const Icon(Icons.file_open),
|
||||||
title: const Text('Aus Dateien auswählen'),
|
title: const Text('Aus Dateien auswählen'),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
context.loaderOverlay.show();
|
|
||||||
FilePick.documentPick().then(mediaUpload);
|
FilePick.documentPick().then(mediaUpload);
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
},
|
},
|
||||||
@ -108,9 +111,8 @@ class _ChatTextfieldState extends State<ChatTextfield> {
|
|||||||
leading: const Icon(Icons.image),
|
leading: const Icon(Icons.image),
|
||||||
title: const Text('Aus Gallerie auswählen'),
|
title: const Text('Aus Gallerie auswählen'),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
context.loaderOverlay.show();
|
FilePick.multipleGalleryPick().then((value) {
|
||||||
FilePick.galleryPick().then((value) {
|
if(value != null) mediaUpload(value.map((e) => e.path).toList());
|
||||||
mediaUpload(value?.path);
|
|
||||||
});
|
});
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
},
|
},
|
||||||
|
@ -13,8 +13,17 @@ class FilePick {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<String?> documentPick() async {
|
static Future<List<XFile>?> multipleGalleryPick() async {
|
||||||
var result = await FilePicker.platform.pickFiles();
|
final pickedImages = await _picker.pickMultiImage();
|
||||||
return result?.files.single.path;
|
if(pickedImages.isNotEmpty) {
|
||||||
|
return pickedImages;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<List<String>?> documentPick() async {
|
||||||
|
var result = await FilePicker.platform.pickFiles(allowMultiple: true);
|
||||||
|
var paths = result?.files.nonNulls.map((e) => e.path).toList();
|
||||||
|
return paths?.nonNulls.toList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user