Added early basic media viewing in Talk
This commit is contained in:
@ -1,7 +1,12 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:marianum_mobile/api/marianumcloud/talk/chat/getChatResponse.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
class RichObjectStringProcessor {
|
||||
static String parse(String message, Map<String, RichObjectString>? data) {
|
||||
static String parseTextPreview(String message, Map<String, RichObjectString>? data) {
|
||||
if(data == null) return message;
|
||||
|
||||
data.forEach((key, value) {
|
||||
@ -10,4 +15,31 @@ class RichObjectStringProcessor {
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
static Future<Widget> parseAnyToWidget(String message, Map<String, RichObjectString>? data) async {
|
||||
if(data == null) return Text(message);
|
||||
if(!message.contains(RegExp("{file}"))) return Text(parseTextPreview(message, data));
|
||||
|
||||
SharedPreferences preferences = await SharedPreferences.getInstance();
|
||||
|
||||
Widget? back;
|
||||
data.forEach((key, value) {
|
||||
back = CachedNetworkImage(
|
||||
errorWidget: (context, url, error) {
|
||||
return Text("Datei: ${value.name}", style: const TextStyle(fontWeight: FontWeight.bold));
|
||||
},
|
||||
alignment: Alignment.center,
|
||||
placeholder: (context, url) {
|
||||
return const Padding(padding: EdgeInsets.all(10), child: CircularProgressIndicator());
|
||||
},
|
||||
fadeInDuration: const Duration(seconds: 1),
|
||||
imageUrl: "https://cloud.marianum-fulda.de/core/preview?fileId=${value.id}&x=110&y=-1&a=1",
|
||||
httpHeaders: {
|
||||
"Authorization": "Basic ${base64.encode(utf8.encode("${preferences.getString("username")}:${preferences.getString("password")}"))}"
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
return back ?? Text("NOPE");
|
||||
}
|
||||
}
|
@ -56,7 +56,7 @@ class _ChatListState extends State<ChatList> {
|
||||
|
||||
chats.add(ListTile(
|
||||
title: Text(chatRoom.displayName),
|
||||
subtitle: Text("${Jiffy.unixFromSecondsSinceEpoch(chatRoom.lastMessage.timestamp).fromNow()}: ${RichObjectStringProcessor.parse(chatRoom.lastMessage.message.replaceAll("\n", " "), chatRoom.lastMessage.messageParameters)}", overflow: TextOverflow.ellipsis),
|
||||
subtitle: Text("${Jiffy.unixFromSecondsSinceEpoch(chatRoom.lastMessage.timestamp).fromNow()}: ${RichObjectStringProcessor.parseTextPreview(chatRoom.lastMessage.message.replaceAll("\n", " "), chatRoom.lastMessage.messageParameters)}", overflow: TextOverflow.ellipsis),
|
||||
trailing: Visibility(
|
||||
visible: chatRoom.unreadMessages > 0,
|
||||
child: Container(
|
||||
@ -83,7 +83,7 @@ class _ChatListState extends State<ChatList> {
|
||||
onTap: () async {
|
||||
Navigator.of(context).push(MaterialPageRoute(builder: (context) {
|
||||
return ChatView(
|
||||
user: chatRoom,
|
||||
room: chatRoom,
|
||||
selfId: username,
|
||||
avatar: circleAvatar,
|
||||
);
|
||||
|
@ -10,11 +10,11 @@ import 'package:marianum_mobile/data/chatList/chatProps.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class ChatView extends StatefulWidget {
|
||||
final GetRoomResponseObject user;
|
||||
final GetRoomResponseObject room;
|
||||
final String selfId;
|
||||
final CircleAvatar avatar;
|
||||
|
||||
const ChatView({Key? key, required this.user, required this.selfId, required this.avatar}) : super(key: key);
|
||||
const ChatView({Key? key, required this.room, required this.selfId, required this.avatar}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<ChatView> createState() => _ChatViewState();
|
||||
@ -56,7 +56,7 @@ class _ChatViewState extends State<ChatView> {
|
||||
super.initState();
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
|
||||
Provider.of<ChatProps>(context, listen: false).setQueryToken(widget.user.token);
|
||||
Provider.of<ChatProps>(context, listen: false).setQueryToken(widget.room.token);
|
||||
});
|
||||
}
|
||||
|
||||
@ -67,11 +67,13 @@ class _ChatViewState extends State<ChatView> {
|
||||
List<Bubble> messages = List<Bubble>.empty(growable: true);
|
||||
|
||||
if(!data.primaryLoading()) {
|
||||
bool showMetadata = true;
|
||||
bool showActorDisplayName = true;
|
||||
bool showBubbleTime = true;
|
||||
|
||||
data.getChatResponse.sortByTimestamp().forEach((element) {
|
||||
|
||||
showMetadata = element.messageType == GetRoomResponseObjectMessageType.comment;
|
||||
showActorDisplayName = element.messageType == GetRoomResponseObjectMessageType.comment && widget.room.type != GetRoomResponseObjectConversationType.oneToOne;
|
||||
showBubbleTime = element.messageType != GetRoomResponseObjectMessageType.system;
|
||||
|
||||
BubbleStyle currentStyle;
|
||||
if(element.messageType == GetRoomResponseObjectMessageType.comment) {
|
||||
@ -84,38 +86,85 @@ class _ChatViewState extends State<ChatView> {
|
||||
currentStyle = styleSystem;
|
||||
}
|
||||
|
||||
var _actorTextStyle = TextStyle(color: Theme.of(context).primaryColor, fontWeight: FontWeight.bold);
|
||||
|
||||
messages.add(Bubble(
|
||||
margin: BubbleEdges.only(bottom: element == data.getChatResponse.sortByTimestamp().last ? 20 : 0),
|
||||
|
||||
style: currentStyle,
|
||||
child: Stack(
|
||||
children: [
|
||||
Visibility(
|
||||
visible: showMetadata,
|
||||
child: Positioned(
|
||||
top: 0,
|
||||
left: 0,
|
||||
child: Text(element.actorDisplayName, style: TextStyle(fontWeight: FontWeight.bold, color: Theme.of(context).primaryColor)),
|
||||
child: Container(
|
||||
constraints: BoxConstraints(
|
||||
maxWidth: MediaQuery.of(context).size.width * 0.9,
|
||||
minWidth: _textSize(element.actorDisplayName, _actorTextStyle).width,
|
||||
),
|
||||
child: Stack(
|
||||
children: [
|
||||
Padding(
|
||||
padding: EdgeInsets.only(bottom: showBubbleTime ? 18 : 0, top: showActorDisplayName ? 18 : 0),
|
||||
child: FutureBuilder(
|
||||
future: RichObjectStringProcessor.parseAnyToWidget(element.message, element.messageParameters),
|
||||
builder: (context, snapshot) {
|
||||
if(!snapshot.hasData) return const CircularProgressIndicator();
|
||||
return snapshot.data ?? const Icon(Icons.error);
|
||||
},
|
||||
)
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: showMetadata ? 18 : 0),
|
||||
child: Text(RichObjectStringProcessor.parse(element.message, element.messageParameters)),
|
||||
),
|
||||
Visibility(
|
||||
visible: showMetadata,
|
||||
child: Positioned(
|
||||
bottom: 0,
|
||||
right: 0,
|
||||
child: Text(
|
||||
"${Jiffy.unixFromSecondsSinceEpoch(element.timestamp).yMMMMd} - ${Jiffy.unixFromSecondsSinceEpoch(element.timestamp).format("HH:mm")}",
|
||||
style: TextStyle(color: Theme.of(context).disabledColor),
|
||||
Visibility(
|
||||
visible: showActorDisplayName,
|
||||
child: Positioned(
|
||||
top: 0,
|
||||
left: 0,
|
||||
child: Text(
|
||||
element.actorDisplayName,
|
||||
textAlign: TextAlign.start,
|
||||
style: _actorTextStyle,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
Visibility(
|
||||
visible: showBubbleTime,
|
||||
child: Positioned(
|
||||
bottom: 0,
|
||||
right: 0,
|
||||
child: Text(
|
||||
Jiffy.unixFromSecondsSinceEpoch(element.timestamp).format("HH:mm"),
|
||||
textAlign: TextAlign.end,
|
||||
style: const TextStyle(color: Colors.grey, fontSize: 12),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
|
||||
// Stack(
|
||||
// children: [
|
||||
// Visibility(
|
||||
// visible: showMetadata,
|
||||
// child: Positioned(
|
||||
// top: 0,
|
||||
// left: 0,
|
||||
// child: Expanded(child: Text(element.actorDisplayName, style: TextStyle(fontWeight: FontWeight.bold, color: Theme.of(context).primaryColor))),
|
||||
// ),
|
||||
// ),
|
||||
// Padding(
|
||||
// padding: EdgeInsets.symmetric(vertical: showMetadata ? 18 : 0),
|
||||
// child: Text(RichObjectStringProcessor.parse(element.message, element.messageParameters)),
|
||||
// ),
|
||||
// Visibility(
|
||||
// visible: showMetadata,
|
||||
// child: Positioned(
|
||||
// bottom: 0,
|
||||
// right: 0,
|
||||
// child: Text(
|
||||
// "${Jiffy.unixFromSecondsSinceEpoch(element.timestamp).yMMMMd} - ${Jiffy.unixFromSecondsSinceEpoch(element.timestamp).format("HH:mm")}",
|
||||
// style: TextStyle(color: Theme.of(context).disabledColor),
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
));
|
||||
});
|
||||
}
|
||||
@ -127,7 +176,9 @@ class _ChatViewState extends State<ChatView> {
|
||||
children: [
|
||||
widget.avatar,
|
||||
const SizedBox(width: 10),
|
||||
Text(widget.user.displayName, overflow: TextOverflow.ellipsis, maxLines: 1),
|
||||
Expanded(
|
||||
child: Text(widget.room.displayName, overflow: TextOverflow.ellipsis, maxLines: 1),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
@ -175,7 +226,7 @@ class _ChatViewState extends State<ChatView> {
|
||||
setState(() {
|
||||
sending = true;
|
||||
});
|
||||
SendMessage(widget.user.token, SendMessageParams(_textBoxController.text)).run().then((value) => {
|
||||
SendMessage(widget.room.token, SendMessageParams(_textBoxController.text)).run().then((value) => {
|
||||
Provider.of<ChatProps>(context, listen: false).run(),
|
||||
_textBoxController.text = "",
|
||||
setState(() {
|
||||
@ -196,4 +247,13 @@ class _ChatViewState extends State<ChatView> {
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Size _textSize(String text, TextStyle style) {
|
||||
final TextPainter textPainter = TextPainter(
|
||||
text: TextSpan(text: text, style: style),
|
||||
maxLines: 1,
|
||||
textDirection: TextDirection.ltr)
|
||||
..layout(minWidth: 0, maxWidth: double.infinity);
|
||||
return textPainter.size;
|
||||
}
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ class _DebugOverviewState extends State<DebugOverview> {
|
||||
leading: const Icon(Icons.delete_forever),
|
||||
title: const Text("Cache löschen"),
|
||||
onTap: () {
|
||||
PaintingBinding.instance.imageCache.clear();
|
||||
storage.collection("MarianumMobile").delete().then((value) => {
|
||||
Navigator.pop(context)
|
||||
});
|
||||
|
Reference in New Issue
Block a user