From 5451216695005ef3a4340b7fe22046bb1b5d6b62 Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Sun, 9 Feb 2020 16:26:24 +0100 Subject: [PATCH] Splash color on select --- lib/components/list_items/message.dart | 164 +++++++++---------------- lib/main.dart | 2 +- lib/utils/event_extension.dart | 16 +-- 3 files changed, 66 insertions(+), 116 deletions(-) diff --git a/lib/components/list_items/message.dart b/lib/components/list_items/message.dart index b09c543c..f1c6d00a 100644 --- a/lib/components/list_items/message.dart +++ b/lib/components/list_items/message.dart @@ -48,106 +48,51 @@ class Message extends StatelessWidget { ? Colors.redAccent : Theme.of(context).primaryColor; } - List> popupMenuList = []; - if (event.canRedact && !event.redacted && event.status > 1) { - popupMenuList.add( - PopupMenuItem( - value: "remove", - child: Text(I18n.of(context).removeMessage), - ), - ); - } - - if (!event.redacted && - [ - MessageTypes.Text, - MessageTypes.Reply, - MessageTypes.Location, - MessageTypes.Notice, - MessageTypes.Emote, - MessageTypes.None, - ].contains(event.messageType) && - event.body.isNotEmpty) { - popupMenuList.add( - PopupMenuItem( - value: "copy", - child: Text(I18n.of(context).copy), - ), - ); - } - - if (!event.redacted) { - popupMenuList.add( - PopupMenuItem( - value: "forward", - child: Text(I18n.of(context).forward), - ), - ); - } - - if (ownMessage && event.status == -1) { - popupMenuList.add( - PopupMenuItem( - value: "resend", - child: Text(I18n.of(context).tryToSendAgain), - ), - ); - popupMenuList.add( - PopupMenuItem( - value: "delete", - child: Text(I18n.of(context).deleteMessage), - ), - ); - } List rowChildren = [ Expanded( - child: InkWell( - onTap: longPressSelect ? null : () => onSelect(event), - onLongPress: !longPressSelect ? null : () => onSelect(event), - child: AnimatedOpacity( - duration: Duration(milliseconds: 500), - opacity: (event.status == 0 || event.redacted) ? 0.5 : 1, - child: Bubble( - elevation: 0, - radius: Radius.circular(8), - alignment: alignment, - margin: BubbleEdges.symmetric(horizontal: 4), - color: color, - nip: nip, - child: Column( - mainAxisSize: MainAxisSize.min, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - mainAxisSize: MainAxisSize.min, - children: [ - Text( - ownMessage - ? I18n.of(context).you - : event.sender.calcDisplayname(), - style: TextStyle( - color: ownMessage - ? textColor - : event.sender.calcDisplayname().color, - fontWeight: FontWeight.bold, - ), + child: AnimatedOpacity( + duration: Duration(milliseconds: 500), + opacity: (event.status == 0 || event.redacted) ? 0.5 : 1, + child: Bubble( + elevation: 0, + radius: Radius.circular(8), + alignment: alignment, + margin: BubbleEdges.symmetric(horizontal: 4), + color: color, + nip: nip, + child: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + mainAxisSize: MainAxisSize.min, + children: [ + Text( + ownMessage + ? I18n.of(context).you + : event.sender.calcDisplayname(), + style: TextStyle( + color: ownMessage + ? textColor + : event.sender.calcDisplayname().color, + fontWeight: FontWeight.bold, ), - SizedBox(width: 4), - Text( - event.time.localizedTime(context), - style: TextStyle( - color: textColor.withAlpha(180), - ), + ), + SizedBox(width: 4), + Text( + event.time.localizedTime(context), + style: TextStyle( + color: textColor.withAlpha(180), ), - ], - ), - MessageContent( - event, - textColor: textColor, - ), - ], - ), + ), + ], + ), + MessageContent( + event, + textColor: textColor, + ), + ], ), ), ), @@ -171,18 +116,23 @@ class Message extends StatelessWidget { rowChildren.insert(0, avatarOrSizedBox); } - return AnimatedContainer( - duration: Duration(milliseconds: 300), - curve: Curves.fastOutSlowIn, - color: selected - ? Theme.of(context).primaryColor.withAlpha(100) - : Theme.of(context).backgroundColor, - padding: EdgeInsets.only( - left: 8.0, right: 8.0, bottom: sameSender ? 4.0 : 8.0), - child: Row( - crossAxisAlignment: CrossAxisAlignment.end, - mainAxisAlignment: rowMainAxisAlignment, - children: rowChildren, + return InkWell( + onTap: longPressSelect ? () => null : () => onSelect(event), + splashColor: Theme.of(context).primaryColor.withAlpha(100), + onLongPress: !longPressSelect ? null : () => onSelect(event), + child: AnimatedContainer( + duration: Duration(milliseconds: 300), + curve: Curves.fastOutSlowIn, + color: selected + ? Theme.of(context).primaryColor.withAlpha(100) + : Theme.of(context).primaryColor.withAlpha(0), + padding: EdgeInsets.only( + left: 8.0, right: 8.0, bottom: sameSender ? 4.0 : 8.0), + child: Row( + crossAxisAlignment: CrossAxisAlignment.end, + mainAxisAlignment: rowMainAxisAlignment, + children: rowChildren, + ), ), ); } diff --git a/lib/main.dart b/lib/main.dart index dfb2ea13..cc31647e 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -44,7 +44,7 @@ class App extends StatelessWidget { appBarTheme: AppBarTheme( brightness: Brightness.light, color: Colors.white, - elevation: 1, + //elevation: 1, textTheme: TextTheme( title: TextStyle( color: Colors.black, diff --git a/lib/utils/event_extension.dart b/lib/utils/event_extension.dart index 2dc2dc97..debe7f0f 100644 --- a/lib/utils/event_extension.dart +++ b/lib/utils/event_extension.dart @@ -12,7 +12,7 @@ extension LocalizedBody on Event { MessageTypes.None, }; - getLocalizedBody(BuildContext context, + String getLocalizedBody(BuildContext context, {bool withSenderNamePrefix = false, bool hideQuotes = false}) { if (this.redacted) { return I18n.of(context) @@ -204,6 +204,13 @@ extension LocalizedBody on Event { localizedBody = I18n.of(context).unknownEvent(this.typeKey); } + // Hide quotes + if (hideQuotes) { + List lines = localizedBody.split("\n"); + lines.removeWhere((s) => s.startsWith("> ") || s.isEmpty); + localizedBody = lines.join("\n"); + } + // Add the sender name prefix if (withSenderNamePrefix && this.type == EventTypes.Message && @@ -214,13 +221,6 @@ extension LocalizedBody on Event { localizedBody = "$senderNameOrYou: $localizedBody"; } - // Hide quotes - if (hideQuotes) { - List lines = localizedBody.split("\n"); - lines.removeWhere((s) => s.startsWith("> ")); - localizedBody = lines.join("\n"); - } - return localizedBody; } }