From 0d1ae1021796c40ae39b30fa0e998df71ece555b Mon Sep 17 00:00:00 2001 From: Hanh Date: Mon, 18 Apr 2022 16:03:15 +0800 Subject: [PATCH] Message ListView --- lib/generated/intl/messages_en.dart | 2 + lib/generated/intl/messages_es.dart | 2 + lib/generated/intl/messages_fr.dart | 2 + lib/generated/l10n.dart | 10 +++ lib/l10n/intl_en.arb | 3 +- lib/l10n/intl_es.arb | 3 +- lib/l10n/intl_fr.arb | 3 +- lib/message.dart | 22 ++++++ lib/message_item.dart | 118 ++++++++++++++++++++++++++++ lib/settings.dart | 9 +++ lib/store.dart | 11 +++ pubspec.yaml | 2 +- 12 files changed, 183 insertions(+), 4 deletions(-) create mode 100644 lib/message_item.dart diff --git a/lib/generated/intl/messages_en.dart b/lib/generated/intl/messages_en.dart index 5cb8ec3..100dca4 100644 --- a/lib/generated/intl/messages_en.dart +++ b/lib/generated/intl/messages_en.dart @@ -320,6 +320,8 @@ class MessageLookup extends MessageLookupByLibrary { "Shield Transparent Balance When Sending"), "shieldingInProgress": MessageLookupByLibrary.simpleMessage("Shielding in progress..."), + "showMessagesAsTable": + MessageLookupByLibrary.simpleMessage("Show Messages as Table"), "sign": MessageLookupByLibrary.simpleMessage("Sign Transaction"), "signOffline": MessageLookupByLibrary.simpleMessage("Sign"), "simple": MessageLookupByLibrary.simpleMessage("Simple"), diff --git a/lib/generated/intl/messages_es.dart b/lib/generated/intl/messages_es.dart index e4eef71..97bd9a4 100644 --- a/lib/generated/intl/messages_es.dart +++ b/lib/generated/intl/messages_es.dart @@ -317,6 +317,8 @@ class MessageLookup extends MessageLookupByLibrary { MessageLookupByLibrary.simpleMessage("Blindar Saldo Transparente"), "shieldingInProgress": MessageLookupByLibrary.simpleMessage("Blindaje en progreso…"), + "showMessagesAsTable": + MessageLookupByLibrary.simpleMessage("Show Messages as Table"), "sign": MessageLookupByLibrary.simpleMessage("Sign"), "signOffline": MessageLookupByLibrary.simpleMessage("Firmar"), "simple": MessageLookupByLibrary.simpleMessage("Sencillo"), diff --git a/lib/generated/intl/messages_fr.dart b/lib/generated/intl/messages_fr.dart index efab7b3..a350421 100644 --- a/lib/generated/intl/messages_fr.dart +++ b/lib/generated/intl/messages_fr.dart @@ -323,6 +323,8 @@ class MessageLookup extends MessageLookupByLibrary { "Masquer le solde transparent"), "shieldingInProgress": MessageLookupByLibrary.simpleMessage("Masquage en cours..."), + "showMessagesAsTable": + MessageLookupByLibrary.simpleMessage("Show Messages as Table"), "sign": MessageLookupByLibrary.simpleMessage("Sign"), "signOffline": MessageLookupByLibrary.simpleMessage("Signer"), "simple": MessageLookupByLibrary.simpleMessage("Simple"), diff --git a/lib/generated/l10n.dart b/lib/generated/l10n.dart index bbb0191..92d11aa 100644 --- a/lib/generated/l10n.dart +++ b/lib/generated/l10n.dart @@ -2251,6 +2251,16 @@ class S { args: [], ); } + + /// `Show Messages as Table` + String get showMessagesAsTable { + return Intl.message( + 'Show Messages as Table', + name: 'showMessagesAsTable', + desc: '', + args: [], + ); + } } class AppLocalizationDelegate extends LocalizationsDelegate { diff --git a/lib/l10n/intl_en.arb b/lib/l10n/intl_en.arb index 2f44386..b5bc9ad 100644 --- a/lib/l10n/intl_en.arb +++ b/lib/l10n/intl_en.arb @@ -218,5 +218,6 @@ "recipient": "Recipient", "fromto": "From/To", "rescanning": "Rescanning...", - "markAllAsRead": "Mark All as Read" + "markAllAsRead": "Mark All as Read", + "showMessagesAsTable": "Show Messages as Table" } diff --git a/lib/l10n/intl_es.arb b/lib/l10n/intl_es.arb index b99424a..c547751 100644 --- a/lib/l10n/intl_es.arb +++ b/lib/l10n/intl_es.arb @@ -216,5 +216,6 @@ "recipient": "Recipient", "fromto": "From/To", "rescanning": "Rescanning...", - "markAllAsRead": "Mark All as Read" + "markAllAsRead": "Mark All as Read", + "showMessagesAsTable": "Show Messages as Table" } diff --git a/lib/l10n/intl_fr.arb b/lib/l10n/intl_fr.arb index 4ddacf9..4d78ef0 100644 --- a/lib/l10n/intl_fr.arb +++ b/lib/l10n/intl_fr.arb @@ -216,5 +216,6 @@ "recipient": "Recipient", "fromto": "From/To", "rescanning": "Rescanning...", - "markAllAsRead": "Mark All as Read" + "markAllAsRead": "Mark All as Read", + "showMessagesAsTable": "Show Messages as Table" } diff --git a/lib/message.dart b/lib/message.dart index b7ef16d..a403db3 100644 --- a/lib/message.dart +++ b/lib/message.dart @@ -6,6 +6,7 @@ import 'package:warp_api/warp_api.dart'; import 'db.dart'; import 'generated/l10n.dart'; import 'main.dart'; +import 'message_item.dart'; import 'store.dart'; class MessagesTab extends StatefulWidget { @@ -23,6 +24,10 @@ class MessagesState extends State with AutomaticKeepAliveClientMixi Widget build(BuildContext context) { super.build(context); final s = S.of(context); + + if (!settings.messageTable) + return MessageList(); + final _source = MessagesDataSource(context); source = _source; return SingleChildScrollView( @@ -116,6 +121,23 @@ class MessagesDataSource extends DataTableSource { } } +class MessageList extends StatefulWidget { + @override + MessageListState createState() => MessageListState(); +} + +class MessageListState extends State { + @override + Widget build(BuildContext context) { + if (active.messages.isEmpty) return Container(); + return Container(child: ListView.builder( + itemCount: active.messages.length, + itemBuilder: (context, index) { + return MessageItem(active.messages[index], index); + })); + } +} + class MessagePage extends StatefulWidget { final index; MessagePage(this.index); diff --git a/lib/message_item.dart b/lib/message_item.dart new file mode 100644 index 0000000..0934647 --- /dev/null +++ b/lib/message_item.dart @@ -0,0 +1,118 @@ +import 'package:ZYWallet/db.dart'; +import 'package:flutter/material.dart'; + +import 'main.dart'; + +class MessageItem extends StatelessWidget { + final ZMessage message; + final int index; + + MessageItem(this.message, this.index); + + @override + Widget build(BuildContext context) { + final theme = Theme.of(context); + final textTheme = theme.textTheme; + final s = message.incoming ? message.sender : message.recipient; + final initial = (s == null || s.isEmpty) ? "?" : s[0]; + final width = MediaQuery.of(context).size.width; + + final unreadStyle = (TextStyle? s) => message.read ? s : s?.copyWith(fontWeight: FontWeight.bold); + + return GestureDetector( + onTap: () { + _onSelect(context); + }, + onLongPress: () { + active.markAllMessagesAsRead(); + }, + child: Container( + margin: EdgeInsets.only(top: 3.0, bottom: 3.0, right: 0.0), + padding: EdgeInsets.symmetric(horizontal: 5.0, vertical: 10.0), + child: Row(children: [ + CircleAvatar( + backgroundColor: initialToColor(initial), + child: Text( + initial, + style: TextStyle( + fontSize: 28, + fontWeight: FontWeight.bold, + color: Colors.white, + ), + ), + radius: 24.0, + ), + SizedBox( + width: 15.0, + height: 30.0, + ), + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text(message.fromto(), style: unreadStyle(textTheme.caption)), + SizedBox( + height: 5.0, + ), + Container( + width: width * 0.6, + child: Text( + message.subject, + style: unreadStyle(textTheme.titleMedium), overflow: TextOverflow.ellipsis)), + SizedBox( + height: 4.0, + ), + Container( + width: width * 0.8, + child: Text( + message.body, + softWrap: true, maxLines: 5, overflow: TextOverflow.ellipsis, + ), + ), + ], + ) + ]))); + } + + _onSelect(BuildContext context) { + Navigator.of(context).pushNamed('/message', arguments: index); + } +} + +final colors = [ + const Color(0xFF1DE9B6), + const Color(0xFFCDDC39), + const Color(0xFFAA00FF), + const Color(0xFF2196F3), + const Color(0xFF689F38), + const Color(0xFF388E3C), + const Color(0xFFF57C00), + const Color(0xFFFFA000), + const Color(0xFFFBC02D), + const Color(0xFFFFEA00), + const Color(0xFFE64A19), + const Color(0xFF5D4037), + const Color(0xFF7E57C2), + const Color(0xFF2196F3), + const Color(0xFFAA00FF), + const Color(0xFF2196F3), + const Color(0xFF00B0FF), + const Color(0xFF00E5FF), + const Color(0xFFAA00FF), + const Color(0xFF2196F3), + const Color(0xFF64DD17), + const Color(0xFFAEEA00), + const Color(0xFFAA00FF), + const Color(0xFFFFAB00), + const Color(0xFFAA00FF), + const Color(0xFF2196F3), +]; + +final defaultColor = const Color(0xFF717171); + +Color initialToColor(String s) { + final i = s.toUpperCase().codeUnitAt(0); + if (i >= 65 && i < 91) { + return colors[i-65]; + } + return defaultColor; +} diff --git a/lib/settings.dart b/lib/settings.dart index fae93a5..50ee5d9 100644 --- a/lib/settings.dart +++ b/lib/settings.dart @@ -183,6 +183,11 @@ class SettingsState extends State with SingleTickerProviderStateMi title: Text(s.includeReplyTo), initialValue: settings.includeReplyTo, onSaved: _onIncludeReplyTo), + if (!simpleMode) FormBuilderCheckbox( + name: 'message_table', + title: Text(s.showMessagesAsTable), + initialValue: settings.messageTable, + onSaved: _onMessageTable), if (!simpleMode) TextFormField( decoration: InputDecoration( labelText: 'Auto Shield Threshold'), @@ -252,6 +257,10 @@ class SettingsState extends State with SingleTickerProviderStateMi settings.setIncludeReplyTo(v); } + _onMessageTable(v) { + settings.setMessageTable(v); + } + _onProtectSend(v) { settings.setProtectSend(v); } diff --git a/lib/store.dart b/lib/store.dart index 6d3a7fa..2e982fb 100644 --- a/lib/store.dart +++ b/lib/store.dart @@ -135,6 +135,9 @@ abstract class _Settings with Store { @observable bool includeReplyTo = false; + @observable + bool messageTable = false; + @observable bool protectSend = false; @@ -172,6 +175,7 @@ abstract class _Settings with Store { autoHide = prefs.getBool('auto_hide') ?? true; protectSend = prefs.getBool('protect_send') ?? false; includeReplyTo = prefs.getBool('include_reply_to') ?? false; + messageTable = prefs.getBool('message_table') ?? false; primaryColorValue = prefs.getInt('primary') ?? Colors.blue.value; primaryVariantColorValue = @@ -407,6 +411,13 @@ abstract class _Settings with Store { prefs.setBool('include_reply_to', includeReplyTo); } + @action + Future setMessageTable(bool v) async { + final prefs = await SharedPreferences.getInstance(); + messageTable = v; + prefs.setBool('message_table', messageTable); + } + @action Future setMemoSignature(String v) async { final prefs = await SharedPreferences.getInstance(); diff --git a/pubspec.yaml b/pubspec.yaml index 6e6a23d..4f11fd1 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -15,7 +15,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -version: 1.2.4+227 +version: 1.2.4+229 environment: sdk: ">=2.12.0 <3.0.0"