Ver código fonte

优化引用的展示样式和增加跳转到引用的内容的功能

master
KerwinZheng 5 anos atrás
pai
commit
4caa092156
2 arquivos alterados com 229 adições e 151 exclusões
  1. +204
    -124
      lib/chat/group_chat_item.dart
  2. +25
    -27
      lib/chat/group_chat_view.dart

+ 204
- 124
lib/chat/group_chat_item.dart Ver arquivo

@@ -92,6 +92,8 @@ class _GroupChatPageItemState extends State<GroupChatPageItem>
bool isLongPressed = false;
double maxWidth = Screen.width - 140;
@override
void initState() {
super.initState();
@@ -277,6 +279,8 @@ class _GroupChatPageItemState extends State<GroupChatPageItem>
}
_textMsg(MsgModel msgModel) {
List<Widget> showMsg = [];
var width = 0.0;
var msg = utf8.decode(msgModel.msgContent);
if (msg.contains('[ ')) {
msg = msg.replaceAll('[ ', '[');
@@ -284,53 +288,89 @@ class _GroupChatPageItemState extends State<GroupChatPageItem>
if (msg.contains(' ]')) {
msg = msg.replaceAll(' ]', ']');
}
bool isUrl =false;
if(textList[curTextType].contains('http') ){
isUrl =true;
bool isUrl = false;
if (textList[curTextType].contains('http')) {
isUrl = true;
}
Widget text = Container(
if (msgModel.refMsgContent != null && msgModel.refMsgContent.length > 0) {
QuoteMsg quoteMsg = QuoteMsg.fromBuffer(msgModel.refMsgContent);
var refName = Provider.of<RefNameProvider>(context)
.getGroupRefName(msgModel.sessionId, quoteMsg.sendUserId);
var msgDate =
DateTime.fromMillisecondsSinceEpoch(quoteMsg.sendTime.toInt());
var showTimeStr = getTodayTime(msgDate);
var timetWidth = _getRealTextWidht(showTimeStr, fontSize: 13);
var nameWidhth = _getRealTextWidht(refName, fontSize: 13);
width = timetWidth + (nameWidhth > 70 ? 70 : nameWidhth) + 36;
if (width > maxWidth) {
width = maxWidth;
}
showMsg.add(InkWell(
onTap: () {
MessageMgr().emit('Jump to Msg', quoteMsg.sendTime.toInt());
},
child: Container(
padding: EdgeInsets.all(8),
margin: EdgeInsets.only(bottom: 5),
decoration: BoxDecoration(
color: Color(0xFFC4E0F5),
borderRadius: BorderRadius.circular(5.5)),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Row(children: <Widget>[
Container(
constraints: BoxConstraints(maxWidth: 70),
child: Text(
refName,
style: TextStyle(fontSize: 13),
overflow: TextOverflow.ellipsis,
)),
SizedBox(width: 20),
Text(
showTimeStr,
style: TextStyle(fontSize: 13),
)
]),
SizedBox(height: 7.5),
Text(
quoteMsg.content.substring(quoteMsg.content.indexOf(':') + 2),
style: TextStyle(fontSize: 13),
)
],
),
)));
}
var contentWidth = _getTextWidth(textList[curTextType]);
if (contentWidth > width && contentWidth <= maxWidth) {
width = contentWidth;
}
showMsg.add(Container(
constraints: BoxConstraints(maxWidth: maxWidth, minHeight: 22),
alignment: Alignment.centerLeft,
child: extendedText(
textList[curTextType],
color: isUrl ? Colors.blue : Constants.BlackTextColor,
hideKeyboard: widget.hideKeyboard,
fontSize: FontSize,
)));
return Container(
constraints: BoxConstraints(maxWidth: Screen.width - 120),
child: extendedText(
msg,
hideKeyboard: widget.hideKeyboard,
fontSize: FontSize,
color: isUrl?Colors.blue:SendMsgText,
),
width: width + 20,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start, children: showMsg),
padding: EdgeInsets.symmetric(horizontal: 9, vertical: 10.5),
decoration: BoxDecoration(
color: isLongPressed ? Colors.grey[300] : SendMsgBg,
border: Border.all(color: Color(0xFFB9CBD7), width: 0.6),
borderRadius: BorderRadius.all(Radius.circular(ChatRadius))),
);
if (msgModel.refMsgContent != null && msgModel.refMsgContent.length > 0) {
QuoteMsg quoteMsg = QuoteMsg.fromBuffer(msgModel.refMsgContent);
return Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
text,
SizedBox(height: 2),
Container(
constraints: BoxConstraints(maxWidth: Screen.width - 120),
padding: EdgeInsets.symmetric(vertical: 1, horizontal: 3),
child: Text(
quoteMsg.content,
maxLines: 1,
textScaleFactor: 1.0,
overflow: TextOverflow.ellipsis,
style: TextStyle(fontSize: 12),
),
decoration: BoxDecoration(
color: Colors.grey[300],
borderRadius: BorderRadius.circular(5)),
)
],
);
} else {
return text;
}
}
_soundMsg() {
@@ -472,7 +512,9 @@ class _GroupChatPageItemState extends State<GroupChatPageItem>
_imgMsg(List<int> imgData) {
var imgSize = _getImgSize();
ImageProvider provider = MemoryImage(widget.msg.localFile==null?Uint8List.fromList(imgData):File(widget.msg.localFile).readAsBytesSync());
ImageProvider provider = MemoryImage(widget.msg.localFile == null
? Uint8List.fromList(imgData)
: File(widget.msg.localFile).readAsBytesSync());
return GestureDetector(
child: ClipRRect(
@@ -484,7 +526,7 @@ class _GroupChatPageItemState extends State<GroupChatPageItem>
width: imgSize.width,
child: Image(
fit: BoxFit.contain,
image:provider,
image: provider,
),
)),
borderRadius: BorderRadius.circular(5),
@@ -586,46 +628,46 @@ class _GroupChatPageItemState extends State<GroupChatPageItem>
MessageMgr().emit('Delete Select Message', widget.msg);
});
///转发
if (widget.msg.msgType == ChatType.TextChatType.value||
widget.msg.msgType == ChatType.ImageChatType.value||
widget.msg.msgType == ChatType.ShortVideoChatType.value||
widget.msg.msgType == ChatType.PlaceChatType.value||
widget.msg.msgType == ChatType.EmoticonType.value||
widget.msg.msgType == ChatType.FileChatType.value
){
actions.add( I18n.of(context).forward);
if (widget.msg.msgType == ChatType.TextChatType.value ||
widget.msg.msgType == ChatType.ImageChatType.value ||
widget.msg.msgType == ChatType.ShortVideoChatType.value ||
widget.msg.msgType == ChatType.PlaceChatType.value ||
widget.msg.msgType == ChatType.EmoticonType.value ||
widget.msg.msgType == ChatType.FileChatType.value) {
actions.add(I18n.of(context).forward);
actionsFunc.add(() {
print('转发消息');
if(widget.msg.msgType == ChatType.FileChatType.value && widget.msg.localFile==null){
if (widget.msg.msgType == ChatType.FileChatType.value &&
widget.msg.localFile == null) {
showToast('请先下载文件');
return ;
return;
}
AppNavigator.pushForwardPage(context, widget.msg);
});
}
if (widget.msg.msgType == ChatType.FileChatType.value &&widget.msg.localFile!=null) {
if (widget.msg.msgType == ChatType.FileChatType.value &&
widget.msg.localFile != null) {
//分享文件
actions.add( I18n.of(context).copy_download_url);
actionsFunc.add(() async{
actions.add(I18n.of(context).copy_download_url);
actionsFunc.add(() async {
//如果是文件增加复制下载地址
String path = widget.msg.localFile;
UploadUtil().copyFileUrl(widget.msg, context);
String type='file';
if(path.contains('mp4') ||path.contains('mp3')){
type = 'video';
}else if(path.contains('png')||path.contains('jpg')||path.contains('jpeg')||path.contains('JPG')||path.contains('PNG')){
type = 'image';
}
ShareExtend.share(FileCacheMgr.replacePath(path), type);
String path = widget.msg.localFile;
UploadUtil().copyFileUrl(widget.msg, context);
String type = 'file';
if (path.contains('mp4') || path.contains('mp3')) {
type = 'video';
} else if (path.contains('png') ||
path.contains('jpg') ||
path.contains('jpeg') ||
path.contains('JPG') ||
path.contains('PNG')) {
type = 'image';
}
ShareExtend.share(FileCacheMgr.replacePath(path), type);
});
}
if (widget.msg.msgType == ChatType.TextChatType.value) {
@@ -639,8 +681,6 @@ class _GroupChatPageItemState extends State<GroupChatPageItem>
});
}
if (widget.msg.msgType == ChatType.ShortVoiceChatType.value) {
var soundPlayMode =
Provider.of<KeyboardIndexProvider>(context).soundPlayMode;
@@ -656,23 +696,22 @@ class _GroupChatPageItemState extends State<GroupChatPageItem>
}
// String date2 = DateTime.fromMillisecondsSinceEpoch(widget.msg.time).toString();
bool isUrl =false;
if(widget.msg.msgType==ChatType.TextChatType.value ){
if( textList[curTextType].contains('http')){
isUrl =true;
bool isUrl = false;
if (widget.msg.msgType == ChatType.TextChatType.value) {
if (textList[curTextType].contains('http')) {
isUrl = true;
}
}
return WPopupMenu(
child: item,
actions: actions,
onTap: ()async{
if(isUrl){
if (await canLaunch(textList[curTextType])) {
launch(textList[curTextType]);
onTap: () async {
if (isUrl) {
if (await canLaunch(textList[curTextType])) {
launch(textList[curTextType]);
}
}
}
},
onLongPressStart: () {
isLongPressed = true;
@@ -739,16 +778,27 @@ class _GroupChatPageItemState extends State<GroupChatPageItem>
selectionEnabled: false, hideKeyboard: widget.hideKeyboard));
}
double _getTextWidth(String text) {
double _getRealTextWidht(String text, {double fontSize = FontSize}) {
TextPainter _textPainter = TextPainter(
maxLines: 2,
text: TextSpan(
text: text,
style: TextStyle(fontSize: fontSize, color: Colors.black)),
textDirection: TextDirection.ltr)
..layout();
return _textPainter.width;
}
double _getTextWidth(String text, {double fontSize = FontSize}) {
var tp = TextPainter(
text: TextSpan(
style: TextStyle(fontSize: FontSize), text: textList[curTextType]),
style: TextStyle(fontSize: fontSize), text: textList[curTextType]),
textAlign: TextAlign.left,
textDirection: TextDirection.ltr,
textScaleFactor: 1,
);
tp.layout(maxWidth: Screen.width - 140);
tp.layout(maxWidth: maxWidth);
if (text.contains('[')) {
if (text.length < 5 && text.startsWith('[') && text.endsWith(']')) {
///单表情
@@ -763,7 +813,7 @@ class _GroupChatPageItemState extends State<GroupChatPageItem>
if (length > 6) scale = 7;
double width = tp.width + length * scale;
return width > (Screen.width - 140) ? Screen.width - 140 : width;
return width > (maxWidth) ? maxWidth : width;
}
}
return tp.width;
@@ -785,10 +835,70 @@ class _GroupChatPageItemState extends State<GroupChatPageItem>
_receiveText(MsgModel msg) {
List<Widget> showMsg = [];
double width = 0.0;
if (textList.length > 0) {
bool isUrl =false;
if(textList[curTextType].contains('http') ){
isUrl =true;
bool isUrl = false;
if (textList[curTextType].contains('http')) {
isUrl = true;
}
if (msg.refMsgContent != null && msg.refMsgContent.length > 0) {
QuoteMsg quoteMsg = QuoteMsg.fromBuffer(msg.refMsgContent);
var refName = Provider.of<RefNameProvider>(context)
.getGroupRefName(msg.sessionId, quoteMsg.sendUserId);
var msgDate =
DateTime.fromMillisecondsSinceEpoch(quoteMsg.sendTime.toInt());
var showTimeStr = getTodayTime(msgDate);
var timetWidth = _getRealTextWidht(showTimeStr, fontSize: 13);
var nameWidhth = _getRealTextWidht(refName, fontSize: 13);
width = timetWidth + (nameWidhth > 70 ? 70 : nameWidhth) + 36;
if (width > maxWidth) {
width = maxWidth;
}
showMsg.add(InkWell(
onTap: () {
MessageMgr().emit('Jump to Msg', quoteMsg.sendTime.toInt());
},
child: Container(
padding: EdgeInsets.all(8),
margin: EdgeInsets.only(bottom: 5),
decoration: BoxDecoration(
color: Color(0xFFC4E0F5),
borderRadius: BorderRadius.circular(5.5)),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Row(children: <Widget>[
Container(
constraints: BoxConstraints(maxWidth: 70),
child: Text(
refName,
style: TextStyle(fontSize: 13),
overflow: TextOverflow.ellipsis,
)),
SizedBox(width: 20),
Text(
showTimeStr,
style: TextStyle(fontSize: 13),
)
]),
SizedBox(height: 7.5),
Text(
quoteMsg.content
.substring(quoteMsg.content.indexOf(':') + 2),
style: TextStyle(fontSize: 13),
)
],
),
)));
}
var contentWidth = _getTextWidth(textList[curTextType]);
if (contentWidth > width && contentWidth <= maxWidth) {
width = contentWidth;
}
showMsg.add(InkWell(
@@ -805,8 +915,7 @@ class _GroupChatPageItemState extends State<GroupChatPageItem>
}
},
child: Container(
constraints:
BoxConstraints(maxWidth: Screen.width - 140, minHeight: 22),
constraints: BoxConstraints(maxWidth: maxWidth, minHeight: 22),
alignment: Alignment.centerLeft,
child: extendedText(
textList[curTextType],
@@ -816,8 +925,6 @@ class _GroupChatPageItemState extends State<GroupChatPageItem>
))));
}
var width = _getTextWidth(textList[curTextType]);
var minWidth = width + 20;
if (msg.transTag != 0) {
minWidth = 200;
@@ -841,7 +948,7 @@ class _GroupChatPageItemState extends State<GroupChatPageItem>
color: isLongPressed ? Colors.grey[300] : Colors.white,
borderRadius: BorderRadius.all(Radius.circular(ChatRadius))),
),
msg.transTag != 1 && msg.transTag !=0
msg.transTag != 1 && msg.transTag != 0
? Positioned(
right: 5,
top: 5,
@@ -855,34 +962,7 @@ class _GroupChatPageItemState extends State<GroupChatPageItem>
: Container()
]);
if (msg.refMsgContent != null && msg.refMsgContent.length > 0) {
QuoteMsg quoteMsg = QuoteMsg.fromBuffer(msg.refMsgContent);
return Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
text,
SizedBox(height: 2),
Container(
constraints: BoxConstraints(maxWidth: Screen.width - 120),
padding: EdgeInsets.symmetric(vertical: 1, horizontal: 3),
child: Text(
quoteMsg.content,
maxLines: 1,
textScaleFactor: 1.0,
overflow: TextOverflow.ellipsis,
style: TextStyle(fontSize: 12),
),
decoration: BoxDecoration(
color: Colors.grey[300],
borderRadius: BorderRadius.circular(5)),
)
],
);
} else {
return text;
}
return text;
}
//用户评价人工翻译,差评
@@ -1083,14 +1163,16 @@ class _GroupChatPageItemState extends State<GroupChatPageItem>
_receiveImg(BuildContext context, List<int> imgData, {String downloadData}) {
// ImageProvider provider = MemoryImage(Uint8List.fromList(imgData));
ImageProvider provider = MemoryImage(widget.msg.localFile==null?Uint8List.fromList(imgData):File(widget.msg.localFile).readAsBytesSync());
ImageProvider provider = MemoryImage(widget.msg.localFile == null
? Uint8List.fromList(imgData)
: File(widget.msg.localFile).readAsBytesSync());
var imgSize = _getImgSize();
return DownloadItem(
isAutoDown: false,
msg: widget.msg,
onFinishTap: (){
onFinishTap: () {
widget.hideKeyboard();
showFullImg(context, widget.msg);
},
@@ -1106,7 +1188,6 @@ class _GroupChatPageItemState extends State<GroupChatPageItem>
),
),
);
}
_receiveVideo(BuildContext context, List<int> imgData,
@@ -1116,7 +1197,6 @@ class _GroupChatPageItemState extends State<GroupChatPageItem>
return InkWell(
onTap: () {
if (widget.msg.localFile != null) {
showVideoPage(context, widget.msg.localFile);
}
},


+ 25
- 27
lib/chat/group_chat_view.dart Ver arquivo

@@ -84,6 +84,7 @@ class _GroupChatPageState extends State<GroupChatPage> {
msgMgr.off('Keyboard Hide', dealWithKeyboardHide);
msgMgr.off('Update Group Info', updateGroupInfo);
msgMgr.off('Delete Select Message', _deleteItem);
msgMgr.off('Jump to Msg', jumpToMsg);
MsgHandler.curActiveSession = 0;
SoundUtils().stop();
@@ -126,6 +127,7 @@ class _GroupChatPageState extends State<GroupChatPage> {
msgMgr.on('Keyboard Hide', dealWithKeyboardHide);
msgMgr.on('Update Group Info', updateGroupInfo);
msgMgr.on('Delete Select Message', _deleteItem);
msgMgr.on('Jump to Msg', jumpToMsg);
WidgetsBinding.instance.addPostFrameCallback((_) {
if (widget.enterType == 1) {
@@ -157,6 +159,24 @@ class _GroupChatPageState extends State<GroupChatPage> {
});
}
jumpToMsg(time) {
var screenItemNums = itemPositionListener.itemPositions.value.length;
int jumIndex = 0;
for (int i = 0; i < msgList.length; i++) {
if (time == msgList[i].time) {
jumIndex = i - screenItemNums + 2;
break;
}
}
if (jumIndex < 0) {
jumIndex = 0;
}
if (jumIndex > msgList.length - 1) {
jumIndex = msgList.length - 1;
}
itemScrollController.jumpTo(index: jumIndex);
}
void _sendFile(File file) async {
// File file = await FilePicker.getFile();
int fileSize = file.lengthSync();
@@ -253,7 +273,7 @@ class _GroupChatPageState extends State<GroupChatPage> {
Map refMap = Provider.of<RefNameProvider>(context).refMap;
bool isHaveUnreadNews = unreadTime !=null;
bool isHaveUnreadNews = unreadTime != null;
bool isAlterYou = alterTime != null;
return MultiProvider(
@@ -301,31 +321,9 @@ class _GroupChatPageState extends State<GroupChatPage> {
right: 0,
child: InkWell(
onTap: () {
var screenItemNums =
itemPositionListener
.itemPositions.value.length;
int jumIndex = 0;
if (isAlterYou) {
for (int i = 0;
i < msgList.length;
i++) {
if (alterTime == msgList[i].time) {
jumIndex = i - screenItemNums + 2;
break;
}
}
} else {
for (int i = 0;
i < msgList.length;
i++) {
if (unreadTime == msgList[i].time) {
jumIndex = i - screenItemNums + 2;
break;
}
}
}
itemScrollController.jumpTo(
index: jumIndex);
jumpToMsg(isAlterYou
? alterTime
: unreadTime);
unreadTime = null;
setState(() {});
},
@@ -349,7 +347,7 @@ class _GroupChatPageState extends State<GroupChatPage> {
child: Row(
children: <Widget>[
Icon(
Icons.file_upload,
Icons.arrow_upward,
color: Color(0xFF3875E9),
size: 20,
),


Carregando…
Cancelar
Salvar