Minor fixes for file download handling

This commit is contained in:
2023-05-04 21:35:25 +02:00
parent 9b6a307212
commit eab9e30943
14 changed files with 246 additions and 115 deletions

View File

@ -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),