Auto pick table/list based on orientation

This commit is contained in:
Hanh 2022-09-15 15:50:00 +08:00
parent 2afb7bfc71
commit 0111e6ac18
14 changed files with 290 additions and 225 deletions

View File

@ -373,10 +373,6 @@ class MessageLookup extends MessageLookupByLibrary {
MessageLookupByLibrary.simpleMessage("Shielding in progress..."),
"showMessagesAsTable":
MessageLookupByLibrary.simpleMessage("Show Messages as Table"),
"showNotesAsTable":
MessageLookupByLibrary.simpleMessage("Show Notes as Table"),
"showTransactionsAsTable":
MessageLookupByLibrary.simpleMessage("Show Transactions as Table"),
"sign": MessageLookupByLibrary.simpleMessage("Sign Transaction"),
"signOffline": MessageLookupByLibrary.simpleMessage("Sign"),
"signOnYourOfflineDevice":
@ -428,6 +424,7 @@ class MessageLookup extends MessageLookupByLibrary {
MessageLookupByLibrary.simpleMessage("Transaction Details"),
"transactionHistory":
MessageLookupByLibrary.simpleMessage("Transaction History"),
"transactions": MessageLookupByLibrary.simpleMessage("Transactions"),
"txId": m19,
"underConfirmed":
MessageLookupByLibrary.simpleMessage("Under Confirmed"),

View File

@ -376,10 +376,6 @@ class MessageLookup extends MessageLookupByLibrary {
MessageLookupByLibrary.simpleMessage("Blindaje en progreso…"),
"showMessagesAsTable":
MessageLookupByLibrary.simpleMessage("Mostrar mensajes como tabla"),
"showNotesAsTable":
MessageLookupByLibrary.simpleMessage("Show Notes as Table"),
"showTransactionsAsTable":
MessageLookupByLibrary.simpleMessage("Show Transactions as Table"),
"sign": MessageLookupByLibrary.simpleMessage("Firma"),
"signOffline": MessageLookupByLibrary.simpleMessage("Firmar"),
"signOnYourOfflineDevice": MessageLookupByLibrary.simpleMessage(
@ -431,6 +427,7 @@ class MessageLookup extends MessageLookupByLibrary {
MessageLookupByLibrary.simpleMessage("Detalles de la transacción"),
"transactionHistory":
MessageLookupByLibrary.simpleMessage("Historial de transacciones"),
"transactions": MessageLookupByLibrary.simpleMessage("Transacciónes"),
"txId": m19,
"underConfirmed":
MessageLookupByLibrary.simpleMessage("Confirmaciones insuficiente"),

View File

@ -379,10 +379,6 @@ class MessageLookup extends MessageLookupByLibrary {
MessageLookupByLibrary.simpleMessage("Masquage en cours..."),
"showMessagesAsTable":
MessageLookupByLibrary.simpleMessage("Messages vus en table"),
"showNotesAsTable":
MessageLookupByLibrary.simpleMessage("Show Notes as Table"),
"showTransactionsAsTable":
MessageLookupByLibrary.simpleMessage("Show Transactions as Table"),
"sign": MessageLookupByLibrary.simpleMessage("Sign"),
"signOffline": MessageLookupByLibrary.simpleMessage("Signer"),
"signOnYourOfflineDevice": MessageLookupByLibrary.simpleMessage(
@ -435,6 +431,7 @@ class MessageLookup extends MessageLookupByLibrary {
MessageLookupByLibrary.simpleMessage("Détails de la transaction"),
"transactionHistory":
MessageLookupByLibrary.simpleMessage("Historique des Transactions"),
"transactions": MessageLookupByLibrary.simpleMessage("Transactions"),
"txId": m19,
"underConfirmed":
MessageLookupByLibrary.simpleMessage("Pas assez de confs"),

View File

@ -2672,21 +2672,11 @@ class S {
);
}
/// `Show Notes as Table`
String get showNotesAsTable {
/// `Transactions`
String get transactions {
return Intl.message(
'Show Notes as Table',
name: 'showNotesAsTable',
desc: '',
args: [],
);
}
/// `Show Transactions as Table`
String get showTransactionsAsTable {
return Intl.message(
'Show Transactions as Table',
name: 'showTransactionsAsTable',
'Transactions',
name: 'transactions',
desc: '',
args: [],
);

View File

@ -13,22 +13,26 @@ class HistoryWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Observer(builder: (context) {
if (settings.txTable)
return HistoryWidgetTable();
else
return HistoryWidgetList();
switch (settings.txView) {
case ViewStyle.Table: return HistoryTable();
case ViewStyle.List: return HistoryList();
case ViewStyle.Auto: return OrientationBuilder(builder: (context, orientation) {
if (orientation == Orientation.portrait) return HistoryList();
else return HistoryTable();
});
}
});
}
}
class HistoryWidgetTable extends StatefulWidget {
HistoryWidgetTable();
class HistoryTable extends StatefulWidget {
HistoryTable();
@override
HistoryState createState() => HistoryState();
}
class HistoryState extends State<HistoryWidgetTable>
class HistoryState extends State<HistoryTable>
with AutomaticKeepAliveClientMixin {
@override
bool get wantKeepAlive => true; //Set to true
@ -166,12 +170,12 @@ class HistoryDataSource extends DataTableSource {
int get selectedRowCount => 0;
}
class HistoryWidgetList extends StatefulWidget {
class HistoryList extends StatefulWidget {
@override
HistoryListState createState() => HistoryListState();
}
class HistoryListState extends State<HistoryWidgetList> {
class HistoryListState extends State<HistoryList> with AutomaticKeepAliveClientMixin {
@override
Widget build(BuildContext context) {
return Observer(builder: (context) {
@ -191,6 +195,9 @@ class HistoryListState extends State<HistoryWidgetList> {
});
});
}
@override
bool get wantKeepAlive => true;
}
class TxItem extends StatelessWidget {
@ -220,7 +227,7 @@ class TxItem extends StatelessWidget {
Text('${tx.txid}', style: theme.textTheme.labelSmall),
]),
Padding(padding: EdgeInsets.symmetric(horizontal: 4)),
Expanded(child: MessageWidget(tx.contact ?? tx.address, message, tx.memo)),
Expanded(child: MessageContentWidget(tx.contact ?? tx.address, message, tx.memo)),
SizedBox(
width: 100,
child: Column(children: [
@ -237,12 +244,12 @@ class TxItem extends StatelessWidget {
}
}
class MessageWidget extends StatelessWidget {
class MessageContentWidget extends StatelessWidget {
final String address;
final ZMessage? message;
final String memo;
MessageWidget(this.address, this.message, this.memo);
MessageContentWidget(this.address, this.message, this.memo);
@override
Widget build(BuildContext context) {

View File

@ -211,7 +211,7 @@ class HomeInnerState extends State<HomeInnerPage> with SingleTickerProviderState
controller: _tabController,
children: [
AccountPage(),
MessagesTab(key: messageKey),
MessageWidget(messageKey),
if (!simpleMode) NoteWidget(),
HistoryWidget(),
if (!simpleMode) BudgetWidget(),

View File

@ -261,6 +261,5 @@
"expert": "Expert",
"blockReorgDetectedRewind": "Block reorg detected. Rewind to {rewindHeight}",
"goToTransaction": "Show Transaction",
"showNotesAsTable": "Show Notes as Table",
"showTransactionsAsTable": "Show Transactions as Table"
"transactions": "Transactions"
}

View File

@ -259,6 +259,5 @@
"expert": "Expert",
"blockReorgDetectedRewind": "Block reorg detected. Rewind to {rewindHeight}",
"goToTransaction": "Ver Transacción",
"showNotesAsTable": "Show Notes as Table",
"showTransactionsAsTable": "Show Transactions as Table"
"transactions": "Transacciónes"
}

View File

@ -259,6 +259,5 @@
"expert": "Expert",
"blockReorgDetectedRewind": "Réorganisation détectée. Retour à {rewindHeight}",
"goToTransaction": "Voir la Transaction",
"showNotesAsTable": "Show Notes as Table",
"showTransactionsAsTable": "Show Transactions as Table"
"transactions": "Transactions"
}

View File

@ -76,7 +76,7 @@ var eta = ETAStore();
var contacts = ContactStore();
var accounts = AccountManager2();
var active = ActiveAccount();
final messageKey = GlobalKey<MessagesState>();
final messageKey = GlobalKey<MessageTableState>();
StreamSubscription? subUniLinks;

View File

@ -9,13 +9,32 @@ import 'main.dart';
import 'message_item.dart';
import 'store.dart';
class MessagesTab extends StatefulWidget {
MessagesTab({Key? key}): super(key: key);
class MessageWidget extends StatelessWidget {
final Key key;
MessageWidget(this.key);
@override
MessagesState createState() => MessagesState();
Widget build(BuildContext context) {
return Observer(builder: (context) {
switch (settings.messageView) {
case ViewStyle.Table: return MessageTable(key: key);
case ViewStyle.List: return MessageList();
case ViewStyle.Auto: return OrientationBuilder(builder: (context, orientation) {
if (orientation == Orientation.portrait) return MessageList();
else return MessageTable();
});
}
});
}
}
class MessagesState extends State<MessagesTab> with AutomaticKeepAliveClientMixin {
class MessageTable extends StatefulWidget {
MessageTable({Key? key}): super(key: key);
@override
MessageTableState createState() => MessageTableState();
}
class MessageTableState extends State<MessageTable> with AutomaticKeepAliveClientMixin {
MessagesDataSource? source;
@override
bool get wantKeepAlive => true; //Set to true
@ -25,9 +44,6 @@ class MessagesState extends State<MessagesTab> with AutomaticKeepAliveClientMixi
super.build(context);
final s = S.of(context);
if (!settings.messageTable)
return MessageList();
final _source = MessagesDataSource(context);
source = _source;
return SingleChildScrollView(
@ -126,9 +142,10 @@ class MessageList extends StatefulWidget {
MessageListState createState() => MessageListState();
}
class MessageListState extends State<MessageList> {
class MessageListState extends State<MessageList> with AutomaticKeepAliveClientMixin {
@override
Widget build(BuildContext context) {
super.build(context);
if (active.messages.isEmpty) return Container();
return Container(child: ListView.builder(
itemCount: active.messages.length,
@ -136,6 +153,9 @@ class MessageListState extends State<MessageList> {
return MessageItem(active.messages[index], index);
}));
}
@override
bool get wantKeepAlive => true;
}
class MessagePage extends StatefulWidget {

View File

@ -11,22 +11,26 @@ class NoteWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Observer(builder: (context) {
if (settings.noteTable)
return NoteWidgetTable();
else
return NoteWidgetList();
switch (settings.noteView) {
case ViewStyle.Table: return NoteTable();
case ViewStyle.List: return NoteList();
case ViewStyle.Auto: return OrientationBuilder(builder: (context, orientation) {
if (orientation == Orientation.portrait) return NoteList();
else return NoteTable();
});
}
});
}
}
class NoteWidgetTable extends StatefulWidget {
NoteWidgetTable();
class NoteTable extends StatefulWidget {
NoteTable();
@override
State<StatefulWidget> createState() => _NoteState();
State<StatefulWidget> createState() => _NoteTableState();
}
class _NoteState extends State<NoteWidgetTable> with AutomaticKeepAliveClientMixin {
class _NoteTableState extends State<NoteTable> with AutomaticKeepAliveClientMixin {
@override
bool get wantKeepAlive => true; //Set to true
@ -151,15 +155,15 @@ class NotesDataSource extends DataTableSource {
}
}
class NoteWidgetList extends StatefulWidget {
class NoteList extends StatefulWidget {
@override
NoteListState createState() => NoteListState();
}
class NoteListState extends State<NoteWidgetList> {
class NoteListState extends State<NoteList> with AutomaticKeepAliveClientMixin {
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
super.build(context);
final s = S.of(context);
return Observer(builder: (context) {
final notes = active.sortedNotes;
@ -184,6 +188,9 @@ class NoteListState extends State<NoteWidgetList> {
_onInvert() {
active.invertExcludedNotes();
}
@override
bool get wantKeepAlive => true;
}
class NoteItem extends StatefulWidget {

View File

@ -1,3 +1,4 @@
import 'package:YWallet/store.dart';
import 'package:flutter/material.dart';
import 'package:flutter_form_builder/flutter_form_builder.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
@ -15,7 +16,8 @@ class SettingsPage extends StatefulWidget {
final _settingsFormKey = GlobalKey<FormBuilderState>();
class SettingsState extends State<SettingsPage> with SingleTickerProviderStateMixin {
class SettingsState extends State<SettingsPage>
with SingleTickerProviderStateMixin {
var _anchorController =
TextEditingController(text: "${settings.anchorOffset}");
var _thresholdController = TextEditingController(
@ -24,6 +26,9 @@ class SettingsState extends State<SettingsPage> with SingleTickerProviderStateMi
var _gapLimitController = TextEditingController(text: "${settings.gapLimit}");
var _currency = settings.currency;
var _needAuth = false;
var _messageView = settings.messageView;
var _noteView = settings.noteView;
var _txView = settings.txView;
late TabController _tabController;
@override
@ -50,9 +55,9 @@ class SettingsState extends State<SettingsPage> with SingleTickerProviderStateMi
FormBuilderRadioGroup(
orientation: OptionsOrientation.horizontal,
name: 'mode',
decoration: InputDecoration(
labelText: s.mode),
initialValue: settings.simpleMode ? 'simple' : 'advanced',
decoration: InputDecoration(labelText: s.mode),
initialValue:
settings.simpleMode ? 'simple' : 'advanced',
onSaved: _onMode,
options: [
FormBuilderFieldOption(
@ -60,8 +65,19 @@ class SettingsState extends State<SettingsPage> with SingleTickerProviderStateMi
FormBuilderFieldOption(
child: Text(s.advanced), value: 'advanced'),
]),
if (!simpleMode) TabBar(controller: _tabController, tabs: [Tab(text: "Zcash"), Tab(text: "Ycash")]),
if (!simpleMode) SizedBox(height: 270, child: TabBarView(controller: _tabController, children: [ServerSelect(0), ServerSelect(1)])),
if (!simpleMode)
TabBar(
controller: _tabController,
tabs: [Tab(text: "Zcash"), Tab(text: "Ycash")]),
if (!simpleMode)
SizedBox(
height: 270,
child: TabBarView(
controller: _tabController,
children: [
ServerSelect(0),
ServerSelect(1)
])),
// if (!simpleMode) FormBuilderRadioGroup(
// orientation: OptionsOrientation.vertical,
// name: 'servers',
@ -73,47 +89,43 @@ class SettingsState extends State<SettingsPage> with SingleTickerProviderStateMi
FormBuilderRadioGroup(
orientation: OptionsOrientation.horizontal,
name: 'themes',
decoration: InputDecoration(
labelText: s.theme),
decoration: InputDecoration(labelText: s.theme),
initialValue: settings.theme,
onChanged: _onTheme,
options: [
FormBuilderFieldOption(
child: Text(s.gold), value: 'gold'),
FormBuilderFieldOption(
child: Text(s.blue),
value: 'blue'),
child: Text(s.blue), value: 'blue'),
FormBuilderFieldOption(
child: Text(s.pink),
value: 'pink'),
child: Text(s.pink), value: 'pink'),
FormBuilderFieldOption(
child: Text(s.purple),
value: 'purple'),
child: Text(s.purple), value: 'purple'),
FormBuilderFieldOption(
child: Text(s.custom),
value: 'custom'),
child: Text(s.custom), value: 'custom'),
]),
Row(children: [Expanded(child: FormBuilderRadioGroup(
orientation: OptionsOrientation.horizontal,
name: 'brightness',
initialValue: settings.themeBrightness,
onChanged: _onThemeBrightness,
options: [
FormBuilderFieldOption(
child: Text(s.light),
value: 'light'),
FormBuilderFieldOption(
child: Text(s.dark),
value: 'dark'),
])),
IconButton(onPressed: _editTheme, icon: Icon(Icons.edit))
Row(children: [
Expanded(
child: FormBuilderRadioGroup(
orientation: OptionsOrientation.horizontal,
name: 'brightness',
initialValue: settings.themeBrightness,
onChanged: _onThemeBrightness,
options: [
FormBuilderFieldOption(
child: Text(s.light), value: 'light'),
FormBuilderFieldOption(
child: Text(s.dark), value: 'dark'),
])),
IconButton(
onPressed: _editTheme, icon: Icon(Icons.edit))
]),
Row(children: [
SizedBox(
width: 100,
child: DropdownButtonFormField<String>(
decoration: InputDecoration(
labelText: s.currency),
decoration:
InputDecoration(labelText: s.currency),
value: _currency,
items: settings.currencies
.map((c) => DropdownMenuItem(
@ -153,40 +165,42 @@ class SettingsState extends State<SettingsPage> with SingleTickerProviderStateMi
// initialValue: settings.useUA,
// onSaved: _onUseUA)),
]),
if (!simpleMode) FormBuilderTextField(
decoration: InputDecoration(
labelText: s.numberOfConfirmationsNeededBeforeSpending),
name: 'anchor',
keyboardType: TextInputType.number,
controller: _anchorController,
onSaved: _onAnchorOffset),
if (!simpleMode) FormBuilderRadioGroup(
orientation: OptionsOrientation.horizontal,
name: 'pnl',
decoration: InputDecoration(
labelText: s.tradingChartRange),
initialValue: settings.chartRange,
onSaved: _onChartRange,
options: [
FormBuilderFieldOption(
child: Text(s.M1), value: '1M'),
FormBuilderFieldOption(
child: Text(s.M3), value: '3M'),
FormBuilderFieldOption(
child: Text(s.M6), value: '6M'),
FormBuilderFieldOption(
child: Text(s.Y1), value: '1Y'),
]),
if (!simpleMode) FormBuilderCheckbox(
name: 'get_tx',
title: Text(
s.retrieveTransactionDetails),
initialValue: settings.getTx,
onSaved: _onGetTx),
if (!simpleMode)
FormBuilderTextField(
decoration: InputDecoration(
labelText: s
.numberOfConfirmationsNeededBeforeSpending),
name: 'anchor',
keyboardType: TextInputType.number,
controller: _anchorController,
onSaved: _onAnchorOffset),
if (!simpleMode)
FormBuilderRadioGroup(
orientation: OptionsOrientation.horizontal,
name: 'pnl',
decoration: InputDecoration(
labelText: s.tradingChartRange),
initialValue: settings.chartRange,
onSaved: _onChartRange,
options: [
FormBuilderFieldOption(
child: Text(s.M1), value: '1M'),
FormBuilderFieldOption(
child: Text(s.M3), value: '3M'),
FormBuilderFieldOption(
child: Text(s.M6), value: '6M'),
FormBuilderFieldOption(
child: Text(s.Y1), value: '1Y'),
]),
if (!simpleMode)
FormBuilderCheckbox(
name: 'get_tx',
title: Text(s.retrieveTransactionDetails),
initialValue: settings.getTx,
onSaved: _onGetTx),
FormBuilderCheckbox(
name: 'auto_hide',
title: Text(
s.autoHideBalance),
title: Text(s.autoHideBalance),
initialValue: settings.autoHide,
onSaved: _onAutoHide),
FormBuilderCheckbox(
@ -194,63 +208,100 @@ class SettingsState extends State<SettingsPage> 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) FormBuilderCheckbox(
name: 'note_table',
title: Text(s.showNotesAsTable),
initialValue: settings.noteTable,
onSaved: _onNoteTable),
if (!simpleMode) FormBuilderCheckbox(
name: 'tx_table',
title: Text(s.showTransactionsAsTable),
initialValue: settings.txTable,
onSaved: _onTxTable),
if (!simpleMode) TextFormField(
decoration: InputDecoration(
labelText: 'Auto Shield Threshold'),
keyboardType: TextInputType.number,
controller: _thresholdController,
inputFormatters: [makeInputFormatter(true)],
onSaved: _onAutoShieldThreshold,
validator: _checkAmount),
if (!simpleMode) FormBuilderCheckbox(
name: 'use_trp',
title: Text(s.useTransparentBalance),
initialValue: settings.shieldBalance,
onSaved: _shieldBalance),
if (!simpleMode) FormBuilderCheckbox(
name: 'use_cold_qr',
title: Text(s.useQrForOfflineSigning),
initialValue: settings.qrOffline,
onSaved: _qrOffline),
if (!simpleMode) FormBuilderCheckbox(
name: 'antispam',
title: Text(s.antispamFilter),
initialValue: settings.antispam,
onSaved: _antispam),
if (!simpleMode && WarpApi.hasGPU()) FormBuilderCheckbox(
name: 'gpu',
title: Text(s.useGpu),
initialValue: settings.useGPU,
onSaved: _useGPU),
if (!simpleMode) FormBuilderTextField(
decoration: InputDecoration(
labelText: s.defaultMemo),
name: 'memo',
controller: _memoController,
onSaved: _onMemo),
if (!simpleMode ) FormBuilderTextField(
decoration: InputDecoration(
labelText: s.gapLimit),
name: 'gap_limit',
keyboardType: TextInputType.number,
controller: _gapLimitController,
onSaved: _ongapLimit),
ButtonBar(children: confirmButtons(context, _onSave))
if (!simpleMode) Row(children: [
Expanded(child: DropdownButtonFormField<ViewStyle>(
decoration: InputDecoration(labelText: s.messages),
value: _messageView,
items: ViewStyle.values.map((v) => DropdownMenuItem(
child: Text(v.name), value: v)).toList(),
onChanged: (v) {
setState(() { _messageView = v!; });
},
onSaved: (_) {
settings.setMessageView(_messageView);
})),
Expanded(child: DropdownButtonFormField<ViewStyle>(
decoration: InputDecoration(labelText: s.notes),
value: _noteView,
items: ViewStyle.values.map((v) => DropdownMenuItem(
child: Text(v.name), value: v)).toList(),
onChanged: (v) {
setState(() { _noteView = v!; });
},
onSaved: (_) {
settings.setNoteView(_noteView);
})),
Expanded(child: DropdownButtonFormField<ViewStyle>(
decoration: InputDecoration(labelText: s.transactions),
value: _txView,
items: ViewStyle.values.map((v) => DropdownMenuItem(
child: Text(v.name), value: v)).toList(),
onChanged: (v) {
setState(() { _txView = v!; });
},
onSaved: (_) {
settings.setTxView(_txView);
})),
]),
// if (!simpleMode) FormBuilderCheckbox(
// name: 'note_table',
// title: Text(s.showNotesAsTable),
// initialValue: settings.noteTable,
// onSaved: _onNoteTable),
// if (!simpleMode) FormBuilderCheckbox(
// name: 'tx_table',
// title: Text(s.showTransactionsAsTable),
// initialValue: settings.txTable,
// onSaved: _onTxTable),
if (!simpleMode)
TextFormField(
decoration: InputDecoration(
labelText: 'Auto Shield Threshold'),
keyboardType: TextInputType.number,
controller: _thresholdController,
inputFormatters: [makeInputFormatter(true)],
onSaved: _onAutoShieldThreshold,
validator: _checkAmount),
if (!simpleMode)
FormBuilderCheckbox(
name: 'use_trp',
title: Text(s.useTransparentBalance),
initialValue: settings.shieldBalance,
onSaved: _shieldBalance),
if (!simpleMode)
FormBuilderCheckbox(
name: 'use_cold_qr',
title: Text(s.useQrForOfflineSigning),
initialValue: settings.qrOffline,
onSaved: _qrOffline),
if (!simpleMode)
FormBuilderCheckbox(
name: 'antispam',
title: Text(s.antispamFilter),
initialValue: settings.antispam,
onSaved: _antispam),
if (!simpleMode && WarpApi.hasGPU())
FormBuilderCheckbox(
name: 'gpu',
title: Text(s.useGpu),
initialValue: settings.useGPU,
onSaved: _useGPU),
if (!simpleMode)
FormBuilderTextField(
decoration:
InputDecoration(labelText: s.defaultMemo),
name: 'memo',
controller: _memoController,
onSaved: _onMemo),
if (!simpleMode)
FormBuilderTextField(
decoration:
InputDecoration(labelText: s.gapLimit),
name: 'gap_limit',
keyboardType: TextInputType.number,
controller: _gapLimitController,
onSaved: _ongapLimit),
ButtonBar(children: confirmButtons(context, _onSave))
]))))));
}
@ -305,15 +356,15 @@ class SettingsState extends State<SettingsPage> with SingleTickerProviderStateMi
}
_onMessageTable(v) {
settings.setMessageTable(v);
settings.setMessageView(v);
}
_onNoteTable(v) {
settings.setNoteTable(v);
settings.setNoteView(v);
}
_onTxTable(v) {
settings.setTxTable(v);
settings.setTxView(v);
}
_onProtectSend(v) {
@ -335,7 +386,9 @@ class SettingsState extends State<SettingsPage> with SingleTickerProviderStateMi
_onSave() async {
final form = _settingsFormKey.currentState!;
if (form.validate()) {
if (_needAuth && !await authenticate(context, S.of(context).protectSendSettingChanged)) return;
if (_needAuth &&
!await authenticate(context, S.of(context).protectSendSettingChanged))
return;
form.save();
settings.updateLWD();
Navigator.of(context).pop();
@ -370,8 +423,8 @@ class ServerSelect extends StatefulWidget {
_ServerSelectState createState() => _ServerSelectState(coin);
}
class _ServerSelectState extends State<ServerSelect> with
AutomaticKeepAliveClientMixin {
class _ServerSelectState extends State<ServerSelect>
with AutomaticKeepAliveClientMixin {
final int coin;
late String choice;
late String customUrl;
@ -390,13 +443,10 @@ class _ServerSelectState extends State<ServerSelect> with
final s = S.of(context);
List<FormBuilderFieldOption<String>> options = coinDef.lwd
.map((lwd) => FormBuilderFieldOption<String>(
child: Text(lwd.name), value: lwd.name))
child: Text(lwd.name), value: lwd.name))
.toList();
options.insert(0,
FormBuilderFieldOption(
value: 'auto',
child: Text(s.auto))
);
options.insert(
0, FormBuilderFieldOption(value: 'auto', child: Text(s.auto)));
options.add(
FormBuilderFieldOption(
@ -410,24 +460,23 @@ class _ServerSelectState extends State<ServerSelect> with
if (v == null) return;
customUrl = v;
_saved = false;
},
},
)),
);
return Column(children: [
FormBuilderRadioGroup<String>(
orientation: OptionsOrientation.vertical,
name: 'lwd ${coinDef.ticker}',
decoration: InputDecoration(
labelText: s.server),
initialValue: choice,
onSaved: _save,
onChanged: (v) {
if (v == null) return;
choice = v;
_saved = false;
orientation: OptionsOrientation.vertical,
name: 'lwd ${coinDef.ticker}',
decoration: InputDecoration(labelText: s.server),
initialValue: choice,
onSaved: _save,
onChanged: (v) {
if (v == null) return;
choice = v;
_saved = false;
},
options: options),
options: options),
Padding(padding: EdgeInsets.symmetric(vertical: 2)),
Observer(builder: (context) => Text(settings.servers[coin].current)),
]);

View File

@ -21,6 +21,10 @@ import 'main.dart';
part 'store.g.dart';
enum ViewStyle {
Auto, Table, List
}
class LWDServer = _LWDServer with _$LWDServer;
abstract class _LWDServer with Store {
@ -150,13 +154,13 @@ abstract class _Settings with Store {
bool includeReplyTo = false;
@observable
bool messageTable = false;
ViewStyle messageView = ViewStyle.Auto;
@observable
bool noteTable = true;
ViewStyle noteView = ViewStyle.Auto;
@observable
bool txTable = true;
ViewStyle txView = ViewStyle.Auto;
@observable
bool protectSend = false;
@ -217,9 +221,9 @@ abstract class _Settings with Store {
protectSend = prefs.getBool('protect_send') ?? false;
protectOpen = prefs.getBool('protect_open') ?? false;
includeReplyTo = prefs.getBool('include_reply_to') ?? false;
messageTable = prefs.getBool('message_table') ?? false;
noteTable = prefs.getBool('note_table') ?? true;
txTable = prefs.getBool('tx_table') ?? true;
messageView = ViewStyle.values[(prefs.getInt('message_view') ?? 0)];
noteView = ViewStyle.values[(prefs.getInt('note_view') ?? 0)];
txView = ViewStyle.values[(prefs.getInt('tx_view') ?? 0)];
gapLimit = prefs.getInt('gap_limit') ?? 10;
qrOffline = prefs.getBool('qr_offline') ?? true;
@ -504,24 +508,24 @@ abstract class _Settings with Store {
}
@action
Future<void> setMessageTable(bool v) async {
Future<void> setMessageView(ViewStyle v) async {
final prefs = await SharedPreferences.getInstance();
messageTable = v;
prefs.setBool('message_table', messageTable);
messageView = v;
prefs.setInt('message_view', v.index);
}
@action
Future<void> setNoteTable(bool v) async {
Future<void> setNoteView(ViewStyle v) async {
final prefs = await SharedPreferences.getInstance();
noteTable = v;
prefs.setBool('note_table', noteTable);
noteView = v;
prefs.setInt('note_view', v.index);
}
@action
Future<void> setTxTable(bool v) async {
Future<void> setTxView(ViewStyle v) async {
final prefs = await SharedPreferences.getInstance();
txTable = v;
prefs.setBool('tx_table', txTable);
txView = v;
prefs.setInt('tx_view', v.index);
}
@action