Merge pull request 'formatting_toolbar' (#475) from formatting_toolbar into trunk
continuous-integration/drone/push Build was killed
Details
continuous-integration/drone/push Build was killed
Details
Reviewed-on: #475 Reviewed-by: Dan Ballard <dan@openprivacy.ca>
This commit is contained in:
commit
644ae502e5
|
@ -64,6 +64,8 @@ class FileMessage extends Message {
|
||||||
}
|
}
|
||||||
return Container(
|
return Container(
|
||||||
alignment: Alignment.center,
|
alignment: Alignment.center,
|
||||||
|
width: 50,
|
||||||
|
height: 50,
|
||||||
child: FileBubble(
|
child: FileBubble(
|
||||||
nameSuggestion,
|
nameSuggestion,
|
||||||
rootHash,
|
rootHash,
|
||||||
|
@ -71,6 +73,7 @@ class FileMessage extends Message {
|
||||||
fileSize,
|
fileSize,
|
||||||
isAuto: metadata.isAuto,
|
isAuto: metadata.isAuto,
|
||||||
interactive: false,
|
interactive: false,
|
||||||
|
isPreview: true,
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
import 'package:cwtch/models/message.dart';
|
import 'package:cwtch/models/message.dart';
|
||||||
import 'package:cwtch/models/messages/malformedmessage.dart';
|
|
||||||
import 'package:cwtch/widgets/malformedbubble.dart';
|
import 'package:cwtch/widgets/malformedbubble.dart';
|
||||||
import 'package:cwtch/widgets/messagerow.dart';
|
import 'package:cwtch/widgets/messagerow.dart';
|
||||||
import 'package:cwtch/widgets/quotedmessage.dart';
|
import 'package:cwtch/widgets/quotedmessage.dart';
|
||||||
|
@ -30,8 +29,14 @@ class QuotedMessage extends Message {
|
||||||
value: this.metadata,
|
value: this.metadata,
|
||||||
builder: (bcontext, child) {
|
builder: (bcontext, child) {
|
||||||
try {
|
try {
|
||||||
dynamic message = jsonDecode(this.content);
|
dynamic message = jsonDecode(
|
||||||
return Text(message["body"]);
|
this.content,
|
||||||
|
);
|
||||||
|
var content = message["body"];
|
||||||
|
return Text(
|
||||||
|
content,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return MalformedBubble();
|
return MalformedBubble();
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,10 @@ class TextMessage extends Message {
|
||||||
return ChangeNotifierProvider.value(
|
return ChangeNotifierProvider.value(
|
||||||
value: this.metadata,
|
value: this.metadata,
|
||||||
builder: (bcontext, child) {
|
builder: (bcontext, child) {
|
||||||
return Text(this.content.substring(0, min(this.content.length, 50)));
|
return Text(
|
||||||
|
this.content,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
import 'dart:ui';
|
||||||
import 'package:crypto/crypto.dart';
|
import 'package:crypto/crypto.dart';
|
||||||
import 'package:cwtch/cwtch/cwtch.dart';
|
import 'package:cwtch/cwtch/cwtch.dart';
|
||||||
import 'package:cwtch/cwtch_icons_icons.dart';
|
import 'package:cwtch/cwtch_icons_icons.dart';
|
||||||
|
@ -10,6 +11,7 @@ import 'package:cwtch/models/message.dart';
|
||||||
import 'package:cwtch/models/messagecache.dart';
|
import 'package:cwtch/models/messagecache.dart';
|
||||||
import 'package:cwtch/models/messages/quotedmessage.dart';
|
import 'package:cwtch/models/messages/quotedmessage.dart';
|
||||||
import 'package:cwtch/models/profile.dart';
|
import 'package:cwtch/models/profile.dart';
|
||||||
|
import 'package:cwtch/third_party/linkify/flutter_linkify.dart';
|
||||||
import 'package:cwtch/widgets/malformedbubble.dart';
|
import 'package:cwtch/widgets/malformedbubble.dart';
|
||||||
import 'package:cwtch/widgets/messageloadingbubble.dart';
|
import 'package:cwtch/widgets/messageloadingbubble.dart';
|
||||||
import 'package:cwtch/widgets/profileimage.dart';
|
import 'package:cwtch/widgets/profileimage.dart';
|
||||||
|
@ -44,6 +46,7 @@ class _MessageViewState extends State<MessageView> {
|
||||||
ItemPositionsListener scrollListener = ItemPositionsListener.create();
|
ItemPositionsListener scrollListener = ItemPositionsListener.create();
|
||||||
File? imagePreview;
|
File? imagePreview;
|
||||||
bool showDown = false;
|
bool showDown = false;
|
||||||
|
bool showPreview = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
|
@ -91,6 +94,7 @@ class _MessageViewState extends State<MessageView> {
|
||||||
return Card(child: Center(child: Text(AppLocalizations.of(context)!.addContactFirst)));
|
return Card(child: Center(child: Text(AppLocalizations.of(context)!.addContactFirst)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var showMessageFormattingPreview = Provider.of<Settings>(context).isExperimentEnabled(FormattingExperiment);
|
||||||
var showFileSharing = Provider.of<Settings>(context).isExperimentEnabled(FileSharingExperiment);
|
var showFileSharing = Provider.of<Settings>(context).isExperimentEnabled(FileSharingExperiment);
|
||||||
var appBarButtons = <Widget>[];
|
var appBarButtons = <Widget>[];
|
||||||
if (Provider.of<ContactInfoState>(context).isOnline()) {
|
if (Provider.of<ContactInfoState>(context).isOnline()) {
|
||||||
|
@ -176,11 +180,11 @@ class _MessageViewState extends State<MessageView> {
|
||||||
actions: appBarButtons,
|
actions: appBarButtons,
|
||||||
),
|
),
|
||||||
body: Padding(
|
body: Padding(
|
||||||
padding: EdgeInsets.fromLTRB(8.0, 8.0, 8.0, 108.0),
|
padding: EdgeInsets.fromLTRB(8.0, 8.0, 8.0, 182.0),
|
||||||
child: MessageList(
|
child: MessageList(
|
||||||
scrollListener,
|
scrollListener,
|
||||||
)),
|
)),
|
||||||
bottomSheet: _buildComposeBox(),
|
bottomSheet: showPreview && showMessageFormattingPreview ? _buildPreviewBox() : _buildComposeBox(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -313,64 +317,216 @@ class _MessageViewState extends State<MessageView> {
|
||||||
Provider.of<FlwtchState>(context, listen: false).cwtch.SetConversationAttribute(profileOnion, identifier, LastMessageSeenTimeKey, DateTime.now().toIso8601String());
|
Provider.of<FlwtchState>(context, listen: false).cwtch.SetConversationAttribute(profileOnion, identifier, LastMessageSeenTimeKey, DateTime.now().toIso8601String());
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildComposeBox() {
|
Widget _buildPreviewBox() {
|
||||||
bool isOffline = Provider.of<ContactInfoState>(context).isOnline() == false;
|
var showClickableLinks = Provider.of<Settings>(context).isExperimentEnabled(ClickableLinksExperiment);
|
||||||
bool isGroup = Provider.of<ContactInfoState>(context).isGroup;
|
|
||||||
|
|
||||||
var charLength = ctrlrCompose.value.text.characters.length;
|
var wdgMessage = Padding(
|
||||||
var expectedLength = ctrlrCompose.value.text.length;
|
padding: EdgeInsets.all(8),
|
||||||
var numberOfBytesMoreThanChar = (expectedLength - charLength);
|
child: SelectableLinkify(
|
||||||
|
text: ctrlrCompose.text + '\n',
|
||||||
|
options: LinkifyOptions(messageFormatting: true, parseLinks: showClickableLinks, looseUrl: true, defaultToHttps: true),
|
||||||
|
linkifiers: [UrlLinkifier()],
|
||||||
|
onOpen: showClickableLinks ? null : null,
|
||||||
|
style: TextStyle(
|
||||||
|
color: Provider.of<Settings>(context).theme.messageFromMeTextColor,
|
||||||
|
fontSize: 16,
|
||||||
|
),
|
||||||
|
linkStyle: TextStyle(
|
||||||
|
color: Provider.of<Settings>(context).theme.messageFromMeTextColor,
|
||||||
|
fontSize: 16,
|
||||||
|
),
|
||||||
|
codeStyle: TextStyle(
|
||||||
|
// note: these colors are flipped
|
||||||
|
fontSize: 16,
|
||||||
|
color: Provider.of<Settings>(context).theme.messageFromOtherTextColor,
|
||||||
|
backgroundColor: Provider.of<Settings>(context).theme.messageFromOtherBackgroundColor),
|
||||||
|
textAlign: TextAlign.left,
|
||||||
|
textWidthBasis: TextWidthBasis.longestLine,
|
||||||
|
));
|
||||||
|
|
||||||
|
var showMessageFormattingPreview = Provider.of<Settings>(context).isExperimentEnabled(FormattingExperiment);
|
||||||
|
var preview = showMessageFormattingPreview
|
||||||
|
? IconButton(
|
||||||
|
icon: Icon(Icons.text_fields),
|
||||||
|
onPressed: () {
|
||||||
|
setState(() {
|
||||||
|
showPreview = false;
|
||||||
|
});
|
||||||
|
})
|
||||||
|
: Container();
|
||||||
|
|
||||||
var composeBox = Container(
|
var composeBox = Container(
|
||||||
color: Provider.of<Settings>(context).theme.backgroundMainColor,
|
color: Provider.of<Settings>(context).theme.backgroundMainColor,
|
||||||
padding: EdgeInsets.all(2),
|
padding: EdgeInsets.all(2),
|
||||||
margin: EdgeInsets.all(2),
|
margin: EdgeInsets.all(2),
|
||||||
height: 100,
|
|
||||||
child: Row(
|
// 164 minimum height + 16px for every line of text so the entire message is displayed when previewed.
|
||||||
children: <Widget>[
|
height: 164 + ((ctrlrCompose.text.split("\n").length - 1) * 16),
|
||||||
Expanded(
|
child: Column(
|
||||||
child: Container(
|
children: [
|
||||||
decoration: BoxDecoration(border: Border(top: BorderSide(color: Provider.of<Settings>(context).theme.defaultButtonActiveColor))),
|
Row(mainAxisAlignment: MainAxisAlignment.start, mainAxisSize: MainAxisSize.max, children: [preview]),
|
||||||
child: RawKeyboardListener(
|
Container(
|
||||||
focusNode: FocusNode(),
|
decoration: BoxDecoration(border: Border(top: BorderSide(color: Provider.of<Settings>(context).theme.defaultButtonActiveColor))),
|
||||||
onKey: handleKeyPress,
|
child: Row(mainAxisAlignment: MainAxisAlignment.start, children: [wdgMessage])),
|
||||||
child: Padding(
|
|
||||||
padding: EdgeInsets.all(8),
|
|
||||||
child: TextFormField(
|
|
||||||
key: Key('txtCompose'),
|
|
||||||
controller: ctrlrCompose,
|
|
||||||
focusNode: focusNode,
|
|
||||||
autofocus: !Platform.isAndroid,
|
|
||||||
textInputAction: TextInputAction.newline,
|
|
||||||
keyboardType: TextInputType.multiline,
|
|
||||||
enableIMEPersonalizedLearning: false,
|
|
||||||
minLines: 1,
|
|
||||||
maxLength: (isGroup ? GroupMessageLengthMax : P2PMessageLengthMax) - numberOfBytesMoreThanChar,
|
|
||||||
maxLengthEnforcement: MaxLengthEnforcement.enforced,
|
|
||||||
maxLines: null,
|
|
||||||
onFieldSubmitted: _sendMessage,
|
|
||||||
enabled: true, // always allow editing...
|
|
||||||
onChanged: (String x) {
|
|
||||||
setState(() {
|
|
||||||
// we need to force a rerender here to update the max length count
|
|
||||||
});
|
|
||||||
},
|
|
||||||
decoration: InputDecoration(
|
|
||||||
hintText: isOffline ? "" : AppLocalizations.of(context)!.placeholderEnterMessage,
|
|
||||||
hintStyle: TextStyle(color: Provider.of<Settings>(context).theme.sendHintTextColor),
|
|
||||||
enabledBorder: InputBorder.none,
|
|
||||||
focusedBorder: InputBorder.none,
|
|
||||||
enabled: true,
|
|
||||||
suffixIcon: ElevatedButton(
|
|
||||||
key: Key("btnSend"),
|
|
||||||
style: ElevatedButton.styleFrom(padding: EdgeInsets.all(0.0), shape: new RoundedRectangleBorder(borderRadius: new BorderRadius.circular(45.0))),
|
|
||||||
child: Icon(CwtchIcons.send_24px, size: 24, color: Provider.of<Settings>(context).theme.defaultButtonTextColor),
|
|
||||||
onPressed: isOffline ? null : _sendMessage,
|
|
||||||
))),
|
|
||||||
)))),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
return Container(
|
||||||
|
color: Provider.of<Settings>(context).theme.backgroundMainColor, child: Column(mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, children: [composeBox]));
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildComposeBox() {
|
||||||
|
bool isOffline = Provider.of<ContactInfoState>(context).isOnline() == false;
|
||||||
|
bool isGroup = Provider.of<ContactInfoState>(context).isGroup;
|
||||||
|
var showToolbar = Provider.of<Settings>(context).isExperimentEnabled(FormattingExperiment);
|
||||||
|
var charLength = ctrlrCompose.value.text.characters.length;
|
||||||
|
var expectedLength = ctrlrCompose.value.text.length;
|
||||||
|
var numberOfBytesMoreThanChar = (expectedLength - charLength);
|
||||||
|
|
||||||
|
var bold = IconButton(
|
||||||
|
icon: Icon(Icons.format_bold),
|
||||||
|
onPressed: () {
|
||||||
|
setState(() {
|
||||||
|
var selected = ctrlrCompose.selection.textInside(ctrlrCompose.text);
|
||||||
|
var selection = ctrlrCompose.selection;
|
||||||
|
var start = ctrlrCompose.selection.start;
|
||||||
|
var end = ctrlrCompose.selection.end;
|
||||||
|
ctrlrCompose.text = ctrlrCompose.text.replaceRange(start, end, "**" + selected + "**");
|
||||||
|
ctrlrCompose.selection = selection.copyWith(baseOffset: selection.start + 2, extentOffset: selection.start + 2);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
var italic = IconButton(
|
||||||
|
icon: Icon(Icons.format_italic),
|
||||||
|
onPressed: () {
|
||||||
|
setState(() {
|
||||||
|
var selected = ctrlrCompose.selection.textInside(ctrlrCompose.text);
|
||||||
|
var selection = ctrlrCompose.selection;
|
||||||
|
var start = ctrlrCompose.selection.start;
|
||||||
|
var end = ctrlrCompose.selection.end;
|
||||||
|
ctrlrCompose.text = ctrlrCompose.text.replaceRange(start, end, "*" + selected + "*");
|
||||||
|
ctrlrCompose.selection = selection.copyWith(baseOffset: selection.start + 1, extentOffset: selection.start + 1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
var code = IconButton(
|
||||||
|
icon: Icon(Icons.code),
|
||||||
|
onPressed: () {
|
||||||
|
setState(() {
|
||||||
|
var selected = ctrlrCompose.selection.textInside(ctrlrCompose.text);
|
||||||
|
var selection = ctrlrCompose.selection;
|
||||||
|
var start = ctrlrCompose.selection.start;
|
||||||
|
var end = ctrlrCompose.selection.end;
|
||||||
|
ctrlrCompose.text = ctrlrCompose.text.replaceRange(start, end, "`" + selected + "`");
|
||||||
|
ctrlrCompose.selection = selection.copyWith(baseOffset: selection.start + 1, extentOffset: selection.start + 1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
var superscript = IconButton(
|
||||||
|
icon: Icon(Icons.superscript),
|
||||||
|
onPressed: () {
|
||||||
|
setState(() {
|
||||||
|
var selected = ctrlrCompose.selection.textInside(ctrlrCompose.text);
|
||||||
|
var selection = ctrlrCompose.selection;
|
||||||
|
var start = ctrlrCompose.selection.start;
|
||||||
|
var end = ctrlrCompose.selection.end;
|
||||||
|
ctrlrCompose.text = ctrlrCompose.text.replaceRange(start, end, "^" + selected + "^");
|
||||||
|
ctrlrCompose.selection = selection.copyWith(baseOffset: selection.start + 1, extentOffset: selection.start + 1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
var subscript = IconButton(
|
||||||
|
icon: Icon(Icons.subscript),
|
||||||
|
onPressed: () {
|
||||||
|
setState(() {
|
||||||
|
var selected = ctrlrCompose.selection.textInside(ctrlrCompose.text);
|
||||||
|
var selection = ctrlrCompose.selection;
|
||||||
|
var start = ctrlrCompose.selection.start;
|
||||||
|
var end = ctrlrCompose.selection.end;
|
||||||
|
ctrlrCompose.text = ctrlrCompose.text.replaceRange(start, end, "_" + selected + "_");
|
||||||
|
ctrlrCompose.selection = selection.copyWith(baseOffset: selection.start + 1, extentOffset: selection.start + 1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
var strikethrough = IconButton(
|
||||||
|
icon: Icon(Icons.format_strikethrough),
|
||||||
|
onPressed: () {
|
||||||
|
setState(() {
|
||||||
|
var selected = ctrlrCompose.selection.textInside(ctrlrCompose.text);
|
||||||
|
var selection = ctrlrCompose.selection;
|
||||||
|
var start = ctrlrCompose.selection.start;
|
||||||
|
var end = ctrlrCompose.selection.end;
|
||||||
|
ctrlrCompose.text = ctrlrCompose.text.replaceRange(start, end, "~~" + selected + "~~");
|
||||||
|
ctrlrCompose.selection = selection.copyWith(baseOffset: selection.start + 2, extentOffset: selection.start + 2);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
var preview = IconButton(
|
||||||
|
icon: Icon(Icons.text_format),
|
||||||
|
onPressed: () {
|
||||||
|
setState(() {
|
||||||
|
showPreview = true;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
var vline = Padding(
|
||||||
|
padding: EdgeInsets.symmetric(vertical: 1, horizontal: 2),
|
||||||
|
child: Container(height: 16, width: 1, decoration: BoxDecoration(color: Provider.of<Settings>(context).theme.messageFromMeTextColor)));
|
||||||
|
|
||||||
|
var formattingToolbar = Container(
|
||||||
|
decoration: BoxDecoration(color: Provider.of<Settings>(context).theme.defaultButtonActiveColor),
|
||||||
|
child: Row(mainAxisAlignment: MainAxisAlignment.start, children: [bold, italic, code, superscript, subscript, strikethrough, vline, preview]));
|
||||||
|
|
||||||
|
var textField = Container(
|
||||||
|
decoration: BoxDecoration(border: Border(top: BorderSide(color: Provider.of<Settings>(context).theme.defaultButtonActiveColor))),
|
||||||
|
child: RawKeyboardListener(
|
||||||
|
focusNode: FocusNode(),
|
||||||
|
onKey: handleKeyPress,
|
||||||
|
child: Padding(
|
||||||
|
padding: EdgeInsets.all(8),
|
||||||
|
child: TextFormField(
|
||||||
|
key: Key('txtCompose'),
|
||||||
|
controller: ctrlrCompose,
|
||||||
|
focusNode: focusNode,
|
||||||
|
autofocus: !Platform.isAndroid,
|
||||||
|
textInputAction: TextInputAction.newline,
|
||||||
|
keyboardType: TextInputType.multiline,
|
||||||
|
enableIMEPersonalizedLearning: false,
|
||||||
|
minLines: 1,
|
||||||
|
maxLength: (isGroup ? GroupMessageLengthMax : P2PMessageLengthMax) - numberOfBytesMoreThanChar,
|
||||||
|
maxLengthEnforcement: MaxLengthEnforcement.enforced,
|
||||||
|
maxLines: 3,
|
||||||
|
onFieldSubmitted: _sendMessage,
|
||||||
|
enabled: true, // always allow editing...
|
||||||
|
|
||||||
|
onChanged: (String x) {
|
||||||
|
setState(() {
|
||||||
|
// we need to force a rerender here to update the max length count
|
||||||
|
});
|
||||||
|
},
|
||||||
|
decoration: InputDecoration(
|
||||||
|
hintText: isOffline ? "" : AppLocalizations.of(context)!.placeholderEnterMessage,
|
||||||
|
hintStyle: TextStyle(color: Provider.of<Settings>(context).theme.sendHintTextColor),
|
||||||
|
enabledBorder: InputBorder.none,
|
||||||
|
focusedBorder: InputBorder.none,
|
||||||
|
enabled: true,
|
||||||
|
suffixIcon: ElevatedButton(
|
||||||
|
key: Key("btnSend"),
|
||||||
|
style: ElevatedButton.styleFrom(padding: EdgeInsets.all(0.0), shape: new RoundedRectangleBorder(borderRadius: new BorderRadius.circular(45.0))),
|
||||||
|
child: Icon(CwtchIcons.send_24px, size: 24, color: Provider.of<Settings>(context).theme.defaultButtonTextColor),
|
||||||
|
onPressed: isOffline ? null : _sendMessage,
|
||||||
|
))),
|
||||||
|
)));
|
||||||
|
|
||||||
|
var textEditChildren;
|
||||||
|
if (showToolbar) {
|
||||||
|
textEditChildren = [formattingToolbar, textField];
|
||||||
|
} else {
|
||||||
|
textEditChildren = [textField];
|
||||||
|
}
|
||||||
|
|
||||||
|
var composeBox =
|
||||||
|
Container(color: Provider.of<Settings>(context).theme.backgroundMainColor, padding: EdgeInsets.all(2), margin: EdgeInsets.all(2), height: 164, child: Column(children: textEditChildren));
|
||||||
|
|
||||||
var children;
|
var children;
|
||||||
if (Provider.of<AppState>(context).selectedConversation != null && Provider.of<AppState>(context).selectedIndex != null) {
|
if (Provider.of<AppState>(context).selectedConversation != null && Provider.of<AppState>(context).selectedIndex != null) {
|
||||||
|
@ -419,7 +575,7 @@ class _MessageViewState extends State<MessageView> {
|
||||||
children = [composeBox];
|
children = [composeBox];
|
||||||
}
|
}
|
||||||
|
|
||||||
return Container(color: Provider.of<Settings>(context).theme.backgroundMainColor, child: Column(mainAxisSize: MainAxisSize.min, children: children));
|
return Container(color: Provider.of<Settings>(context).theme.backgroundMainColor, child: Column(mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, children: children));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send the message if enter is pressed without the shift key...
|
// Send the message if enter is pressed without the shift key...
|
||||||
|
|
|
@ -3,11 +3,8 @@ import 'dart:io';
|
||||||
import 'package:cwtch/models/appstate.dart';
|
import 'package:cwtch/models/appstate.dart';
|
||||||
import 'package:cwtch/models/contact.dart';
|
import 'package:cwtch/models/contact.dart';
|
||||||
import 'package:cwtch/models/profile.dart';
|
import 'package:cwtch/models/profile.dart';
|
||||||
import 'package:cwtch/models/profileservers.dart';
|
|
||||||
import 'package:cwtch/views/contactsview.dart';
|
import 'package:cwtch/views/contactsview.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/painting.dart';
|
|
||||||
import 'package:cwtch/views/messageview.dart';
|
|
||||||
import 'package:cwtch/widgets/profileimage.dart';
|
import 'package:cwtch/widgets/profileimage.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||||
|
@ -156,7 +153,7 @@ class _ContactRowState extends State<ContactRow> {
|
||||||
return AppLocalizations.of(context)!.conversationNotificationPolicyNever;
|
return AppLocalizations.of(context)!.conversationNotificationPolicyNever;
|
||||||
}
|
}
|
||||||
// If the last message was over a day ago, just state the date
|
// If the last message was over a day ago, just state the date
|
||||||
if (DateTime.now().difference(date).inDays > 1) {
|
if (DateTime.now().difference(date).inDays > 0) {
|
||||||
return DateFormat.yMd(Platform.localeName).format(date.toLocal());
|
return DateFormat.yMd(Platform.localeName).format(date.toLocal());
|
||||||
}
|
}
|
||||||
// Otherwise just state the time.
|
// Otherwise just state the time.
|
||||||
|
|
|
@ -25,8 +25,9 @@ class FileBubble extends StatefulWidget {
|
||||||
final int fileSize;
|
final int fileSize;
|
||||||
final bool interactive;
|
final bool interactive;
|
||||||
final bool isAuto;
|
final bool isAuto;
|
||||||
|
final bool isPreview;
|
||||||
|
|
||||||
FileBubble(this.nameSuggestion, this.rootHash, this.nonce, this.fileSize, {this.isAuto = false, this.interactive = true});
|
FileBubble(this.nameSuggestion, this.rootHash, this.nonce, this.fileSize, {this.isAuto = false, this.interactive = true, this.isPreview = false});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
FileBubbleState createState() => FileBubbleState();
|
FileBubbleState createState() => FileBubbleState();
|
||||||
|
@ -44,6 +45,22 @@ class FileBubbleState extends State<FileBubble> {
|
||||||
super.initState();
|
super.initState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget getPreview(context) {
|
||||||
|
return Image.file(
|
||||||
|
myFile!,
|
||||||
|
cacheWidth: (MediaQuery.of(context).size.width * 0.6).floor(),
|
||||||
|
// limit the amount of space the image can decode too, we keep this high-ish to allow quality previews...
|
||||||
|
filterQuality: FilterQuality.medium,
|
||||||
|
fit: BoxFit.scaleDown,
|
||||||
|
alignment: Alignment.center,
|
||||||
|
height: MediaQuery.of(context).size.height * 0.30,
|
||||||
|
isAntiAlias: false,
|
||||||
|
errorBuilder: (context, error, stackTrace) {
|
||||||
|
return MalformedBubble();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
var fromMe = Provider.of<MessageMetadata>(context).senderHandle == Provider.of<ProfileInfoState>(context).onion;
|
var fromMe = Provider.of<MessageMetadata>(context).senderHandle == Provider.of<ProfileInfoState>(context).onion;
|
||||||
|
@ -109,6 +126,12 @@ class FileBubbleState extends State<FileBubble> {
|
||||||
senderDisplayStr = Provider.of<MessageMetadata>(context).senderHandle;
|
senderDisplayStr = Provider.of<MessageMetadata>(context).senderHandle;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// we don't preview a non downloaded file...
|
||||||
|
if (widget.isPreview && myFile != null) {
|
||||||
|
return getPreview(context);
|
||||||
|
}
|
||||||
|
|
||||||
return LayoutBuilder(builder: (bcontext, constraints) {
|
return LayoutBuilder(builder: (bcontext, constraints) {
|
||||||
var wdgSender = Visibility(
|
var wdgSender = Visibility(
|
||||||
visible: widget.interactive,
|
visible: widget.interactive,
|
||||||
|
@ -133,21 +156,7 @@ class FileBubbleState extends State<FileBubble> {
|
||||||
child: MouseRegion(
|
child: MouseRegion(
|
||||||
cursor: SystemMouseCursors.click,
|
cursor: SystemMouseCursors.click,
|
||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
child: Padding(
|
child: Padding(padding: EdgeInsets.all(1.0), child: getPreview(context)),
|
||||||
padding: EdgeInsets.all(1.0),
|
|
||||||
child: Image.file(
|
|
||||||
myFile!,
|
|
||||||
cacheWidth: (MediaQuery.of(bcontext).size.width * 0.6).floor(),
|
|
||||||
// limit the amount of space the image can decode too, we keep this high-ish to allow quality previews...
|
|
||||||
filterQuality: FilterQuality.medium,
|
|
||||||
fit: BoxFit.scaleDown,
|
|
||||||
alignment: Alignment.center,
|
|
||||||
height: MediaQuery.of(bcontext).size.height * 0.30,
|
|
||||||
isAntiAlias: false,
|
|
||||||
errorBuilder: (context, error, stackTrace) {
|
|
||||||
return MalformedBubble();
|
|
||||||
},
|
|
||||||
)),
|
|
||||||
onTap: () {
|
onTap: () {
|
||||||
pop(bcontext, myFile!, wdgMessage);
|
pop(bcontext, myFile!, wdgMessage);
|
||||||
},
|
},
|
||||||
|
|
|
@ -7,6 +7,7 @@ import 'package:cwtch/third_party/linkify/flutter_linkify.dart';
|
||||||
import 'package:cwtch/views/contactsview.dart';
|
import 'package:cwtch/views/contactsview.dart';
|
||||||
import 'package:cwtch/widgets/malformedbubble.dart';
|
import 'package:cwtch/widgets/malformedbubble.dart';
|
||||||
import 'package:cwtch/widgets/messageloadingbubble.dart';
|
import 'package:cwtch/widgets/messageloadingbubble.dart';
|
||||||
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
|
@ -94,10 +95,18 @@ class QuotedMessageBubbleState extends State<QuotedMessageBubble> {
|
||||||
child: Container(
|
child: Container(
|
||||||
margin: EdgeInsets.all(5),
|
margin: EdgeInsets.all(5),
|
||||||
padding: EdgeInsets.all(5),
|
padding: EdgeInsets.all(5),
|
||||||
|
clipBehavior: Clip.antiAlias,
|
||||||
|
decoration: BoxDecoration(),
|
||||||
|
height: 75,
|
||||||
color: fromMe ? Provider.of<Settings>(context).theme.messageFromOtherBackgroundColor : Provider.of<Settings>(context).theme.messageFromMeBackgroundColor,
|
color: fromMe ? Provider.of<Settings>(context).theme.messageFromOtherBackgroundColor : Provider.of<Settings>(context).theme.messageFromMeBackgroundColor,
|
||||||
child: Wrap(runAlignment: WrapAlignment.spaceEvenly, alignment: WrapAlignment.spaceEvenly, runSpacing: 1.0, crossAxisAlignment: WrapCrossAlignment.center, children: [
|
child: Row(mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.start, children: [
|
||||||
Center(widthFactor: 1, child: Padding(padding: EdgeInsets.all(10.0), child: Icon(Icons.reply, size: 32, color: qTextColor))),
|
Padding(padding: EdgeInsets.symmetric(vertical: 5.0, horizontal: 10.0), child: Icon(Icons.reply, size: 32, color: qTextColor)),
|
||||||
Center(widthFactor: 1.0, child: DefaultTextStyle(child: qMessage.getPreviewWidget(context), style: TextStyle(color: qTextColor)))
|
DefaultTextStyle(
|
||||||
|
textWidthBasis: TextWidthBasis.parent,
|
||||||
|
child: qMessage.getPreviewWidget(context),
|
||||||
|
style: TextStyle(color: qTextColor),
|
||||||
|
overflow: TextOverflow.fade,
|
||||||
|
)
|
||||||
]))));
|
]))));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print(e);
|
print(e);
|
||||||
|
|
Loading…
Reference in New Issue