Minor fixes for file download handling
This commit is contained in:
@ -3,6 +3,7 @@ import 'package:marianum_mobile/api/marianumcloud/webdav/queries/listFiles/cache
|
||||
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/webdavApi.dart';
|
||||
import 'package:nextcloud/nextcloud.dart';
|
||||
|
||||
class ListFiles extends WebdavApi<ListFilesParams> {
|
||||
ListFilesParams params;
|
||||
@ -11,7 +12,8 @@ class ListFiles extends WebdavApi<ListFilesParams> {
|
||||
|
||||
@override
|
||||
Future<ListFilesResponse> run() async {
|
||||
Set<CacheableFile> files = (await (await WebdavApi.webdav).ls(params.path)).map((e) => CacheableFile.fromDavFile(e)).toSet();
|
||||
//Set<CacheableFile> files = (await (await WebdavApi.webdav).ls(params.path)).map((e) => CacheableFile.fromDavFile(e)).toSet();
|
||||
Set<CacheableFile> files = (await (await WebdavApi.webdav).ls(params.path)).toWebDavFiles((await WebdavApi.webdav)).map((e) => CacheableFile.fromDavFile(e)).toSet();
|
||||
|
||||
return ListFilesResponse(files);
|
||||
}
|
||||
|
@ -20,16 +20,7 @@ class FileElement extends StatefulWidget {
|
||||
List<String> path;
|
||||
FileElement(this.file, this.path, {Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<FileElement> createState() => _FileElementState();
|
||||
}
|
||||
|
||||
class _FileElementState extends State<FileElement> {
|
||||
late DownloaderCore core;
|
||||
double percent = 0;
|
||||
|
||||
void download(String remotePath, String name) async {
|
||||
|
||||
static void download(String remotePath, String name, Function(double) onProgress, Function(OpenResult) onDone) async {
|
||||
Directory paths = await getApplicationDocumentsDirectory();
|
||||
|
||||
String local = paths.path + Platform.pathSeparator + name;
|
||||
@ -37,9 +28,7 @@ class _FileElementState extends State<FileElement> {
|
||||
DownloaderUtils options = DownloaderUtils(
|
||||
progressCallback: (current, total) {
|
||||
final progress = (current / total) * 100;
|
||||
setState(() => {
|
||||
percent = progress,
|
||||
});
|
||||
onProgress(progress);
|
||||
},
|
||||
file: File(local),
|
||||
progress: ProgressImplementation(),
|
||||
@ -48,29 +37,26 @@ class _FileElementState extends State<FileElement> {
|
||||
Future<OpenResult> result = OpenFile.open(local);
|
||||
|
||||
result.then((value) => {
|
||||
if(value.type != ResultType.done) {
|
||||
showDialog(context: context, builder: (context) {
|
||||
return AlertDialog(
|
||||
title: Text("Download"),
|
||||
content: Text(value.message),
|
||||
);
|
||||
})
|
||||
}
|
||||
onDone(value)
|
||||
});
|
||||
|
||||
widget.file.currentlyDownloading = false;
|
||||
percent = 0;
|
||||
},
|
||||
);
|
||||
|
||||
log(local);
|
||||
|
||||
core = await Flowder.download(
|
||||
await Flowder.download(
|
||||
"${await WebdavApi.webdavConnectString}$remotePath",
|
||||
options,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
State<FileElement> createState() => _FileElementState();
|
||||
}
|
||||
|
||||
class _FileElementState extends State<FileElement> {
|
||||
double percent = 0;
|
||||
|
||||
Widget getSubtitle() {
|
||||
if(widget.file.currentlyDownloading) {
|
||||
return Row(
|
||||
@ -114,7 +100,25 @@ class _FileElementState extends State<FileElement> {
|
||||
|
||||
log("Download: ${widget.file.path} to ${widget.file.name}");
|
||||
|
||||
download(widget.file.path, widget.file.name);
|
||||
FileElement.download(widget.file.path, widget.file.name, (progress) {
|
||||
setState(() => {
|
||||
percent = progress,
|
||||
});
|
||||
}, (result) {
|
||||
if(result.type != ResultType.done) {
|
||||
showDialog(context: context, builder: (context) {
|
||||
return AlertDialog(
|
||||
title: Text("Download"),
|
||||
content: Text(result.message),
|
||||
);
|
||||
});
|
||||
|
||||
setState(() {
|
||||
widget.file.currentlyDownloading = false;
|
||||
percent = 0;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
},
|
||||
|
@ -1,8 +1,10 @@
|
||||
import 'package:better_open_file/better_open_file.dart';
|
||||
import 'package:bubble/bubble.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:jiffy/jiffy.dart';
|
||||
import 'package:marianum_mobile/api/marianumcloud/talk/chat/getChatResponse.dart';
|
||||
import 'package:marianum_mobile/screen/pages/files/fileElement.dart';
|
||||
import 'package:marianum_mobile/screen/pages/talk/chatMessage.dart';
|
||||
|
||||
import '../../../api/marianumcloud/talk/room/getRoomResponse.dart';
|
||||
@ -43,6 +45,7 @@ class ChatBubble {
|
||||
bool isSender;
|
||||
GetChatResponseObject bubbleData;
|
||||
GetRoomResponseObject chatData;
|
||||
double downloadProgress = 0;
|
||||
late ChatMessage message;
|
||||
|
||||
ChatBubble({
|
||||
@ -109,11 +112,19 @@ class ChatBubble {
|
||||
child: Positioned(
|
||||
bottom: 0,
|
||||
right: 0,
|
||||
child: Text(
|
||||
Jiffy.unixFromSecondsSinceEpoch(bubbleData.timestamp).format("HH:mm"),
|
||||
textAlign: TextAlign.end,
|
||||
style: const TextStyle(color: Colors.grey, fontSize: 12),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Visibility(
|
||||
visible: downloadProgress > 0,
|
||||
child: LinearProgressIndicator(value: downloadProgress),
|
||||
),
|
||||
Text(
|
||||
Jiffy.unixFromSecondsSinceEpoch(bubbleData.timestamp).format("HH:mm"),
|
||||
textAlign: TextAlign.end,
|
||||
style: const TextStyle(color: Colors.grey, fontSize: 12),
|
||||
),
|
||||
],
|
||||
)
|
||||
),
|
||||
),
|
||||
],
|
||||
@ -135,10 +146,13 @@ class ChatBubble {
|
||||
},
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.person),
|
||||
title: Text("Zu '${bubbleData.actorDisplayName}' wechseln"),
|
||||
onTap: () => {},
|
||||
Visibility(
|
||||
visible: !isSender && chatData.type != GetRoomResponseObjectConversationType.oneToOne,
|
||||
child: ListTile(
|
||||
leading: const Icon(Icons.person),
|
||||
title: Text("Private Nachricht an '${bubbleData.actorDisplayName}'"),
|
||||
onTap: () => {},
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.bug_report_outlined),
|
||||
@ -149,10 +163,24 @@ class ChatBubble {
|
||||
);
|
||||
});
|
||||
},
|
||||
onTap: () {
|
||||
FileElement.download(message.file!.path!, message.file?.name ?? "Datei", (progress) => {
|
||||
downloadProgress = progress,
|
||||
}, (result) => {
|
||||
downloadProgress = 0,
|
||||
if(result.type != ResultType.done) {
|
||||
showDialog(context: context, builder: (context) {
|
||||
return AlertDialog(
|
||||
content: Text(result.message),
|
||||
);
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Size _textSize(String text, TextStyle style) {
|
||||
final TextPainter textPainter = TextPainter(
|
||||
text: TextSpan(text: text, style: style),
|
||||
|
@ -53,7 +53,7 @@ class ChatMessage {
|
||||
fadeInDuration: const Duration(seconds: 1),
|
||||
imageUrl: "https://cloud.marianum-fulda.de/core/preview?fileId=${file!.id}&x=100&y=-1&a=1",
|
||||
httpHeaders: {
|
||||
"Authorization": "Basic ${base64.encode(utf8.encode("${preferences.getString("username")}:${preferences.getString("password")}"))}"
|
||||
"Authorization": "Basic ${base64.encode(utf8.encode("${preferences.getString("username")}:${preferences.getString("password")}"))}" // TODO move authentication
|
||||
},
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user