Message ListView

This commit is contained in:
Hanh 2022-04-18 16:03:15 +08:00
parent 2c236e47ab
commit 0d1ae10217
12 changed files with 183 additions and 4 deletions

View File

@ -320,6 +320,8 @@ class MessageLookup extends MessageLookupByLibrary {
"Shield Transparent Balance When Sending"), "Shield Transparent Balance When Sending"),
"shieldingInProgress": "shieldingInProgress":
MessageLookupByLibrary.simpleMessage("Shielding in progress..."), MessageLookupByLibrary.simpleMessage("Shielding in progress..."),
"showMessagesAsTable":
MessageLookupByLibrary.simpleMessage("Show Messages as Table"),
"sign": MessageLookupByLibrary.simpleMessage("Sign Transaction"), "sign": MessageLookupByLibrary.simpleMessage("Sign Transaction"),
"signOffline": MessageLookupByLibrary.simpleMessage("Sign"), "signOffline": MessageLookupByLibrary.simpleMessage("Sign"),
"simple": MessageLookupByLibrary.simpleMessage("Simple"), "simple": MessageLookupByLibrary.simpleMessage("Simple"),

View File

@ -317,6 +317,8 @@ class MessageLookup extends MessageLookupByLibrary {
MessageLookupByLibrary.simpleMessage("Blindar Saldo Transparente"), MessageLookupByLibrary.simpleMessage("Blindar Saldo Transparente"),
"shieldingInProgress": "shieldingInProgress":
MessageLookupByLibrary.simpleMessage("Blindaje en progreso…"), MessageLookupByLibrary.simpleMessage("Blindaje en progreso…"),
"showMessagesAsTable":
MessageLookupByLibrary.simpleMessage("Show Messages as Table"),
"sign": MessageLookupByLibrary.simpleMessage("Sign"), "sign": MessageLookupByLibrary.simpleMessage("Sign"),
"signOffline": MessageLookupByLibrary.simpleMessage("Firmar"), "signOffline": MessageLookupByLibrary.simpleMessage("Firmar"),
"simple": MessageLookupByLibrary.simpleMessage("Sencillo"), "simple": MessageLookupByLibrary.simpleMessage("Sencillo"),

View File

@ -323,6 +323,8 @@ class MessageLookup extends MessageLookupByLibrary {
"Masquer le solde transparent"), "Masquer le solde transparent"),
"shieldingInProgress": "shieldingInProgress":
MessageLookupByLibrary.simpleMessage("Masquage en cours..."), MessageLookupByLibrary.simpleMessage("Masquage en cours..."),
"showMessagesAsTable":
MessageLookupByLibrary.simpleMessage("Show Messages as Table"),
"sign": MessageLookupByLibrary.simpleMessage("Sign"), "sign": MessageLookupByLibrary.simpleMessage("Sign"),
"signOffline": MessageLookupByLibrary.simpleMessage("Signer"), "signOffline": MessageLookupByLibrary.simpleMessage("Signer"),
"simple": MessageLookupByLibrary.simpleMessage("Simple"), "simple": MessageLookupByLibrary.simpleMessage("Simple"),

View File

@ -2251,6 +2251,16 @@ class S {
args: [], args: [],
); );
} }
/// `Show Messages as Table`
String get showMessagesAsTable {
return Intl.message(
'Show Messages as Table',
name: 'showMessagesAsTable',
desc: '',
args: [],
);
}
} }
class AppLocalizationDelegate extends LocalizationsDelegate<S> { class AppLocalizationDelegate extends LocalizationsDelegate<S> {

View File

@ -218,5 +218,6 @@
"recipient": "Recipient", "recipient": "Recipient",
"fromto": "From/To", "fromto": "From/To",
"rescanning": "Rescanning...", "rescanning": "Rescanning...",
"markAllAsRead": "Mark All as Read" "markAllAsRead": "Mark All as Read",
"showMessagesAsTable": "Show Messages as Table"
} }

View File

@ -216,5 +216,6 @@
"recipient": "Recipient", "recipient": "Recipient",
"fromto": "From/To", "fromto": "From/To",
"rescanning": "Rescanning...", "rescanning": "Rescanning...",
"markAllAsRead": "Mark All as Read" "markAllAsRead": "Mark All as Read",
"showMessagesAsTable": "Show Messages as Table"
} }

View File

@ -216,5 +216,6 @@
"recipient": "Recipient", "recipient": "Recipient",
"fromto": "From/To", "fromto": "From/To",
"rescanning": "Rescanning...", "rescanning": "Rescanning...",
"markAllAsRead": "Mark All as Read" "markAllAsRead": "Mark All as Read",
"showMessagesAsTable": "Show Messages as Table"
} }

View File

@ -6,6 +6,7 @@ import 'package:warp_api/warp_api.dart';
import 'db.dart'; import 'db.dart';
import 'generated/l10n.dart'; import 'generated/l10n.dart';
import 'main.dart'; import 'main.dart';
import 'message_item.dart';
import 'store.dart'; import 'store.dart';
class MessagesTab extends StatefulWidget { class MessagesTab extends StatefulWidget {
@ -23,6 +24,10 @@ class MessagesState extends State<MessagesTab> with AutomaticKeepAliveClientMixi
Widget build(BuildContext context) { Widget build(BuildContext context) {
super.build(context); super.build(context);
final s = S.of(context); final s = S.of(context);
if (!settings.messageTable)
return MessageList();
final _source = MessagesDataSource(context); final _source = MessagesDataSource(context);
source = _source; source = _source;
return SingleChildScrollView( return SingleChildScrollView(
@ -116,6 +121,23 @@ class MessagesDataSource extends DataTableSource {
} }
} }
class MessageList extends StatefulWidget {
@override
MessageListState createState() => MessageListState();
}
class MessageListState extends State<MessageList> {
@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 { class MessagePage extends StatefulWidget {
final index; final index;
MessagePage(this.index); MessagePage(this.index);

118
lib/message_item.dart Normal file
View File

@ -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;
}

View File

@ -183,6 +183,11 @@ class SettingsState extends State<SettingsPage> with SingleTickerProviderStateMi
title: Text(s.includeReplyTo), title: Text(s.includeReplyTo),
initialValue: settings.includeReplyTo, initialValue: settings.includeReplyTo,
onSaved: _onIncludeReplyTo), onSaved: _onIncludeReplyTo),
if (!simpleMode) FormBuilderCheckbox(
name: 'message_table',
title: Text(s.showMessagesAsTable),
initialValue: settings.messageTable,
onSaved: _onMessageTable),
if (!simpleMode) TextFormField( if (!simpleMode) TextFormField(
decoration: InputDecoration( decoration: InputDecoration(
labelText: 'Auto Shield Threshold'), labelText: 'Auto Shield Threshold'),
@ -252,6 +257,10 @@ class SettingsState extends State<SettingsPage> with SingleTickerProviderStateMi
settings.setIncludeReplyTo(v); settings.setIncludeReplyTo(v);
} }
_onMessageTable(v) {
settings.setMessageTable(v);
}
_onProtectSend(v) { _onProtectSend(v) {
settings.setProtectSend(v); settings.setProtectSend(v);
} }

View File

@ -135,6 +135,9 @@ abstract class _Settings with Store {
@observable @observable
bool includeReplyTo = false; bool includeReplyTo = false;
@observable
bool messageTable = false;
@observable @observable
bool protectSend = false; bool protectSend = false;
@ -172,6 +175,7 @@ abstract class _Settings with Store {
autoHide = prefs.getBool('auto_hide') ?? true; autoHide = prefs.getBool('auto_hide') ?? true;
protectSend = prefs.getBool('protect_send') ?? false; protectSend = prefs.getBool('protect_send') ?? false;
includeReplyTo = prefs.getBool('include_reply_to') ?? false; includeReplyTo = prefs.getBool('include_reply_to') ?? false;
messageTable = prefs.getBool('message_table') ?? false;
primaryColorValue = prefs.getInt('primary') ?? Colors.blue.value; primaryColorValue = prefs.getInt('primary') ?? Colors.blue.value;
primaryVariantColorValue = primaryVariantColorValue =
@ -407,6 +411,13 @@ abstract class _Settings with Store {
prefs.setBool('include_reply_to', includeReplyTo); prefs.setBool('include_reply_to', includeReplyTo);
} }
@action
Future<void> setMessageTable(bool v) async {
final prefs = await SharedPreferences.getInstance();
messageTable = v;
prefs.setBool('message_table', messageTable);
}
@action @action
Future<void> setMemoSignature(String v) async { Future<void> setMemoSignature(String v) async {
final prefs = await SharedPreferences.getInstance(); final prefs = await SharedPreferences.getInstance();

View File

@ -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. # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at # Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.2.4+227 version: 1.2.4+229
environment: environment:
sdk: ">=2.12.0 <3.0.0" sdk: ">=2.12.0 <3.0.0"