Added long press options to chatbubbles

This commit is contained in:
Elias Müller 2023-02-25 18:28:56 +01:00
parent 2f91b89e0f
commit ff4566cf05
4 changed files with 80 additions and 53 deletions
lib/screen

@ -5,6 +5,7 @@ import 'package:marianum_mobile/api/marianumcloud/talk/chat/getChatResponse.dart
import 'package:marianum_mobile/screen/pages/talk/chatMessage.dart'; import 'package:marianum_mobile/screen/pages/talk/chatMessage.dart';
import '../../../api/marianumcloud/talk/room/getRoomResponse.dart'; import '../../../api/marianumcloud/talk/room/getRoomResponse.dart';
import '../../settings/debug/jsonViewer.dart';
class ChatBubble { class ChatBubble {
static const styleSystem = BubbleStyle( static const styleSystem = BubbleStyle(
@ -64,58 +65,81 @@ class ChatBubble {
} }
} }
Bubble generateBubble() { Widget generateBubble() {
bool showActorDisplayName = bubbleData.messageType == GetRoomResponseObjectMessageType.comment && chatData.type != GetRoomResponseObjectConversationType.oneToOne; bool showActorDisplayName = bubbleData.messageType == GetRoomResponseObjectMessageType.comment && chatData.type != GetRoomResponseObjectConversationType.oneToOne;
bool showBubbleTime = bubbleData.messageType != GetRoomResponseObjectMessageType.system; bool showBubbleTime = bubbleData.messageType != GetRoomResponseObjectMessageType.system;
var actorTextStyle = TextStyle(color: Theme.of(context).primaryColor, fontWeight: FontWeight.bold); var actorTextStyle = TextStyle(color: Theme.of(context).primaryColor, fontWeight: FontWeight.bold);
return Bubble( return GestureDetector(
child: Bubble(
style: getStyle(), style: getStyle(),
child: Container( child: Container(
constraints: BoxConstraints( constraints: BoxConstraints(
maxWidth: MediaQuery.of(context).size.width * 0.9, maxWidth: MediaQuery.of(context).size.width * 0.9,
minWidth: showActorDisplayName ? _textSize(bubbleData.actorDisplayName, actorTextStyle).width : 30, minWidth: showActorDisplayName ? _textSize(bubbleData.actorDisplayName, actorTextStyle).width : 30,
), ),
child: Stack( child: Stack(
children: [ children: [
Padding( Padding(
padding: EdgeInsets.only(bottom: showBubbleTime ? 18 : 0, top: showActorDisplayName ? 18 : 0), padding: EdgeInsets.only(bottom: showBubbleTime ? 18 : 0, top: showActorDisplayName ? 18 : 0),
child: FutureBuilder( child: FutureBuilder(
future: message.getWidget(), future: message.getWidget(),
builder: (context, snapshot) { builder: (context, snapshot) {
if(!snapshot.hasData) return const CircularProgressIndicator(); if(!snapshot.hasData) return const CircularProgressIndicator();
return snapshot.data ?? const Icon(Icons.error); return snapshot.data ?? const Icon(Icons.error);
}, },
) )
), ),
Visibility( Visibility(
visible: showActorDisplayName, visible: showActorDisplayName,
child: Positioned( child: Positioned(
top: 0, top: 0,
left: 0, left: 0,
child: Text( child: Text(
bubbleData.actorDisplayName, bubbleData.actorDisplayName,
textAlign: TextAlign.start, textAlign: TextAlign.start,
style: actorTextStyle, style: actorTextStyle,
),
), ),
), ),
), Visibility(
Visibility( visible: showBubbleTime,
visible: showBubbleTime, child: Positioned(
child: Positioned( bottom: 0,
bottom: 0, right: 0,
right: 0, child: Text(
child: Text( Jiffy.unixFromSecondsSinceEpoch(bubbleData.timestamp).format("HH:mm"),
Jiffy.unixFromSecondsSinceEpoch(bubbleData.timestamp).format("HH:mm"), textAlign: TextAlign.end,
textAlign: TextAlign.end, style: const TextStyle(color: Colors.grey, fontSize: 12),
style: const TextStyle(color: Colors.grey, fontSize: 12), ),
), ),
), ),
), ],
], ),
), ),
), ),
onLongPress: () {
showDialog(context: context, builder: (context) {
return SimpleDialog(
children: [
ListTile(
leading: Icon(Icons.copy),
title: Text("Nachricht kopieren"),
),
ListTile(
leading: Icon(Icons.person),
title: Text("Zu '${bubbleData.actorDisplayName}' wechseln"),
),
ListTile(
leading: Icon(Icons.bug_report_outlined),
title: Text("Debugdaten anzeigen"),
onTap: () => JsonViewer.asDialog(context, bubbleData.toJson()),
)
],
);
});
},
); );
} }

@ -1,5 +1,4 @@
import 'package:bubble/bubble.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:marianum_mobile/api/marianumcloud/talk/room/getRoomResponse.dart'; import 'package:marianum_mobile/api/marianumcloud/talk/room/getRoomResponse.dart';
import 'package:marianum_mobile/data/chatList/chatProps.dart'; import 'package:marianum_mobile/data/chatList/chatProps.dart';
@ -35,7 +34,7 @@ class _ChatViewState extends State<ChatView> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Consumer<ChatProps>( return Consumer<ChatProps>(
builder: (context, data, child) { builder: (context, data, child) {
List<Bubble> messages = List<Bubble>.empty(growable: true); List<Widget> messages = List<Widget>.empty(growable: true);
if(!data.primaryLoading()) { if(!data.primaryLoading()) {

@ -86,16 +86,7 @@ class _WeekViewState extends State<WeekView> {
ListTile( ListTile(
leading: const Icon(Icons.bug_report_outlined), leading: const Icon(Icons.bug_report_outlined),
title: const Text("Webuntis Rohdaten zeigen"), title: const Text("Webuntis Rohdaten zeigen"),
onTap: () => showDialog(context: context, builder: (context) { onTap: () => JsonViewer.asDialog(context, timetableData.toJson()),
return AlertDialog(
scrollable: true,
title: const Text("Rohdaten"),
content: Text(JsonViewer.format(timetableData.toJson())),
actions: [
TextButton(onPressed: () => Navigator.of(context).pop(), child: const SingleChildScrollView(child: Text("Schließen")))
],
);
}),
) )
], ],
), ),

@ -24,4 +24,17 @@ class JsonViewer extends StatelessWidget {
return prettyJson(jsonInput, indent: 2); return prettyJson(jsonInput, indent: 2);
//return jsonInput.replaceAllMapped(RegExp(r'[{,}]'), (match) => "${match.group(0)}\n "); //return jsonInput.replaceAllMapped(RegExp(r'[{,}]'), (match) => "${match.group(0)}\n ");
} }
static void asDialog(BuildContext context, Map<String, dynamic> dataMap) {
showDialog(context: context, builder: (context) {
return AlertDialog(
scrollable: true,
title: const Text("Rohdaten"),
content: Text(JsonViewer.format(dataMap)),
actions: [
TextButton(onPressed: () => Navigator.of(context).pop(), child: const SingleChildScrollView(child: Text("Schließen")))
],
);
});
}
} }