From d8c72a5d2865249e15c9613d28e7300ebab27f07 Mon Sep 17 00:00:00 2001 From: Pupsi28 Date: Sun, 7 Apr 2024 16:48:38 +0200 Subject: [PATCH] solved most pr comments and a bug --- lib/view/pages/files/files.dart | 6 +- lib/view/pages/files/filesUploadDialog.dart | 108 ++++++++---------- .../pages/talk/components/chatTextfield.dart | 6 +- 3 files changed, 55 insertions(+), 65 deletions(-) diff --git a/lib/view/pages/files/files.dart b/lib/view/pages/files/files.dart index 2b1a6f9..a39bdbe 100644 --- a/lib/view/pages/files/files.dart +++ b/lib/view/pages/files/files.dart @@ -65,9 +65,7 @@ class SortOptions { ) }; - static BetterSortOption getOption(SortOption option) { - return options[option]!; - } + static BetterSortOption getOption(SortOption option) => options[option]!; } class _FilesState extends State { @@ -99,7 +97,7 @@ class _FilesState extends State { ); } - void mediaUpload(List? paths) async { + Future mediaUpload(List? paths) async { if(paths == null) return; pushScreen( diff --git a/lib/view/pages/files/filesUploadDialog.dart b/lib/view/pages/files/filesUploadDialog.dart index c90b5b0..794d9a7 100644 --- a/lib/view/pages/files/filesUploadDialog.dart +++ b/lib/view/pages/files/filesUploadDialog.dart @@ -43,21 +43,15 @@ class _FilesUploadDialogState extends State { super.initState(); _uploadableFiles = widget.filePaths.map((filePath) { - String fileName = filePath.split(Platform.pathSeparator).last; + var fileName = filePath.split(Platform.pathSeparator).last; return UploadableFile(filePath, fileName); }).toList(); - - /*_uploadableFiles.addAll(widget.filePaths.map((filePath) { - String fileName = filePath.split(Platform.pathSeparator).last; - return UploadableFile(filePath, fileName); - }));*/ } void showHttpErrorCode(int httpErrorCode){ showDialog( context: context, - builder: (BuildContext context) { - return AlertDialog( + builder: (BuildContext context) => AlertDialog( title: const Text('Ein Fehler ist aufgetreten'), contentPadding: const EdgeInsets.all(10), content: Text('Error code: $httpErrorCode'), @@ -67,12 +61,11 @@ class _FilesUploadDialogState extends State { child: const Text('Schließen', textAlign: TextAlign.center), ), ], - ); - } + ) ); } - void uploadFiles({bool override = false}) async { + Future uploadFiles({bool override = false}) async { setState(() { _isUploading = true; _infoText = 'Vorbereiten'; @@ -81,41 +74,33 @@ class _FilesUploadDialogState extends State { } }); - WebDavClient webdavClient = await WebdavApi.webdav; + var webdavClient = await WebdavApi.webdav; if (!override) { - List result = (await webdavClient.propfind(PathUri.parse(widget.remotePath))).responses; - List conflictingFiles = _uploadableFiles.where((file) { - String fileName = file.fileName; - if (result.any((element) => Uri.decodeComponent(element.href!).endsWith('/$fileName'))) { - // konflikt - return true; - } - return false; + 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) { - return AlertDialog( + 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.\n' - '(Datei ${_uploadableFiles.indexOf(conflictingFiles.first)+1})', + 'Eine Datei mit dem Namen "${conflictingFiles.map((e) => e.fileName).first}" existiert bereits.', textAlign: TextAlign.left, ) : SingleChildScrollView( child: Text( - '${conflictingFiles.length} Dateien mit den Namen: ${conflictingFiles.map((e) => '\n${e.fileName}').join(', ')}\n existieren bereits.\n' - '(Dateien ${conflictingFiles.map((e) => _uploadableFiles.indexOf(e)+1).join(', ')})', + '${conflictingFiles.length} Dateien mit folgenden Namen existieren bereits: \n${conflictingFiles.map((e) => '\n - ${e.fileName}').join('')}', textAlign: TextAlign.left, ), ), - actions: [ TextButton( onPressed: () { @@ -127,55 +112,52 @@ class _FilesUploadDialogState extends State { onPressed: () { showDialog( context: context, - builder: (context) { - return ConfirmDialog( - title: 'Bestätigen', - content: 'Bist du sicher, dass du ${conflictingFiles.map((e) => e.fileName).toList()} überschreiben möchtest?', - onConfirm: () { - Navigator.pop(context, true); - }, - confirmButton: 'Ja', - cancelButton: 'Nein', - ); - } + 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) { - for (var element in conflictingFiles) { - element.isConflicting = true; - } setState(() { _isUploading = false; _overallProgressValue = 0.0; _infoText = ''; + for (var element in conflictingFiles) { + element.isConflicting = true; + } }); return; } } } - List uploadetFilePaths = []; + var uploadetFilePaths = []; for (var file in _uploadableFiles) { - String fileName = file.fileName; - String filePath = file.filePath; + var fileName = file.fileName; + var filePath = file.filePath; if(widget.uniqueNames) fileName = '${fileName.split('.').first}-${const Uuid().v4()}.${fileName.split('.').last}'; - String fullRemotePath = '${widget.remotePath}/$fileName'; + var fullRemotePath = '${widget.remotePath}/$fileName'; setState(() { _infoText = '${_uploadableFiles.indexOf(file) + 1}/${_uploadableFiles.length}'; }); - HttpClientResponse uploadTask = await webdavClient.putFile( + var uploadTask = await webdavClient.putFile( File(filePath), FileStat.statSync(filePath), PathUri.parse(fullRemotePath), @@ -211,8 +193,7 @@ class _FilesUploadDialogState extends State { } @override - Widget build(BuildContext context) { - return Scaffold( + Widget build(BuildContext context) => Scaffold( appBar: AppBar( title: const Text('Dateien hochladen'), automaticallyImplyLeading: false, @@ -318,13 +299,25 @@ class _FilesUploadDialogState extends State { onPressed: () => uploadFiles(override: widget.uniqueNames), child: const Text('Hochladen'), ), - child: Stack( - alignment: Alignment.center, - children: [ - CircularProgressIndicator(value: _overallProgressValue), - Center(child: Text(_infoText)), - ], + 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)), + ], + ), ), + + ), ], ), @@ -333,5 +326,4 @@ class _FilesUploadDialogState extends State { ), ), ); - } -} \ No newline at end of file +} diff --git a/lib/view/pages/talk/components/chatTextfield.dart b/lib/view/pages/talk/components/chatTextfield.dart index 791db03..a39be26 100644 --- a/lib/view/pages/talk/components/chatTextfield.dart +++ b/lib/view/pages/talk/components/chatTextfield.dart @@ -35,7 +35,7 @@ class _ChatTextfieldState extends State { void share(String shareFolder, List filePaths) { for (var element in filePaths) { - String fileName = element.split(Platform.pathSeparator).last; + var fileName = element.split(Platform.pathSeparator).last; FileSharingApi().share(FileSharingApiParams( shareType: 10, shareWith: widget.sendToToken, @@ -44,10 +44,10 @@ class _ChatTextfieldState extends State { } } - void mediaUpload(List? paths) async { + Future mediaUpload(List? paths) async { if (paths == null) return; - String shareFolder = 'MarianumMobile'; + var shareFolder = 'MarianumMobile'; WebdavApi.webdav.then((webdav) { webdav.mkcol(PathUri.parse('/$shareFolder')); });