From 5f0ce49c46720fc3cb7d7576e50843023411aa07 Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Tue, 19 Jan 2021 15:46:43 +0100 Subject: [PATCH] fix: Dialogs --- lib/components/dialogs/bootstrap_dialog.dart | 50 +++++++++++-------- .../dialogs/key_verification_dialog.dart | 47 +++++++++-------- .../dialogs/permission_slider_dialog.dart | 19 ++++--- lib/components/dialogs/recording_dialog.dart | 13 +++-- lib/components/matrix.dart | 5 +- lib/components/message_content.dart | 5 +- lib/components/user_bottom_sheet.dart | 9 ++-- lib/views/chat.dart | 1 + lib/views/chat_encryption_settings.dart | 10 +++- lib/views/chat_permissions_settings.dart | 7 +-- lib/views/settings.dart | 6 ++- 11 files changed, 104 insertions(+), 68 deletions(-) diff --git a/lib/components/dialogs/bootstrap_dialog.dart b/lib/components/dialogs/bootstrap_dialog.dart index ebd3f92a..66cadc96 100644 --- a/lib/components/dialogs/bootstrap_dialog.dart +++ b/lib/components/dialogs/bootstrap_dialog.dart @@ -11,10 +11,14 @@ import 'package:flutter_gen/gen_l10n/l10n.dart'; import '../matrix.dart'; class BootstrapDialog extends StatefulWidget { + const BootstrapDialog({Key key, @required this.l10n}) : super(key: key); + Future show(BuildContext context) => PlatformInfos.isCupertinoStyle ? showCupertinoDialog(context: context, builder: (context) => this) : showDialog(context: context, builder: (context) => this); + final L10n l10n; + @override _BootstrapDialogState createState() => _BootstrapDialogState(); } @@ -39,36 +43,36 @@ class _BootstrapDialogState extends State { case BootstrapState.askWipeSsss: body = Text('Wipe chat backup?'); buttons.add(AdaptiveFlatButton( - child: Text(L10n.of(context).yes), + child: Text(widget.l10n.yes), onPressed: () => bootstrap.wipeSsss(true), )); buttons.add(AdaptiveFlatButton( textColor: Theme.of(context).textTheme.bodyText1.color, - child: Text(L10n.of(context).no), + child: Text(widget.l10n.no), onPressed: () => bootstrap.wipeSsss(false), )); break; case BootstrapState.askUseExistingSsss: body = Text('Use existing chat backup?'); buttons.add(AdaptiveFlatButton( - child: Text(L10n.of(context).yes), + child: Text(widget.l10n.yes), onPressed: () => bootstrap.useExistingSsss(true), )); buttons.add(AdaptiveFlatButton( textColor: Theme.of(context).textTheme.bodyText1.color, - child: Text(L10n.of(context).no), + child: Text(widget.l10n.no), onPressed: () => bootstrap.useExistingSsss(false), )); break; case BootstrapState.askBadSsss: body = Text('SSSS bad - continue nevertheless? DATALOSS!!!'); buttons.add(AdaptiveFlatButton( - child: Text(L10n.of(context).yes), + child: Text(widget.l10n.yes), onPressed: () => bootstrap.ignoreBadSecrets(true), )); buttons.add(AdaptiveFlatButton( textColor: Theme.of(context).textTheme.bodyText1.color, - child: Text(L10n.of(context).no), + child: Text(widget.l10n.no), onPressed: () => bootstrap.ignoreBadSecrets(false), )); break; @@ -77,14 +81,15 @@ class _BootstrapDialogState extends State { for (final entry in bootstrap.oldSsssKeys.entries) { final keyId = entry.key; final key = entry.value; - widgets.add(Flexible(child: _AskUnlockOldSsss(keyId, key))); + widgets + .add(Flexible(child: _AskUnlockOldSsss(keyId, key, widget.l10n))); } body = Column( children: widgets, mainAxisSize: MainAxisSize.min, ); buttons.add(AdaptiveFlatButton( - child: Text(L10n.of(context).confirm), + child: Text(widget.l10n.confirm), onPressed: () => bootstrap.unlockedSsss(), )); break; @@ -130,19 +135,19 @@ class _BootstrapDialogState extends State { case BootstrapState.askWipeCrossSigning: body = Text('Wipe cross-signing?'); buttons.add(AdaptiveFlatButton( - child: Text(L10n.of(context).yes), + child: Text(widget.l10n.yes), onPressed: () => bootstrap.wipeCrossSigning(true), )); buttons.add(AdaptiveFlatButton( textColor: Theme.of(context).textTheme.bodyText1.color, - child: Text(L10n.of(context).no), + child: Text(widget.l10n.no), onPressed: () => bootstrap.wipeCrossSigning(false), )); break; case BootstrapState.askSetupCrossSigning: body = Text('Set up cross-signing?'); buttons.add(AdaptiveFlatButton( - child: Text(L10n.of(context).yes), + child: Text(widget.l10n.yes), onPressed: () => bootstrap.askSetupCrossSigning( setupMasterKey: true, setupSelfSigningKey: true, @@ -151,31 +156,31 @@ class _BootstrapDialogState extends State { )); buttons.add(AdaptiveFlatButton( textColor: Theme.of(context).textTheme.bodyText1.color, - child: Text(L10n.of(context).no), + child: Text(widget.l10n.no), onPressed: () => bootstrap.askSetupCrossSigning(), )); break; case BootstrapState.askWipeOnlineKeyBackup: body = Text('Wipe chat backup?'); buttons.add(AdaptiveFlatButton( - child: Text(L10n.of(context).yes), + child: Text(widget.l10n.yes), onPressed: () => bootstrap.wipeOnlineKeyBackup(true), )); buttons.add(AdaptiveFlatButton( textColor: Theme.of(context).textTheme.bodyText1.color, - child: Text(L10n.of(context).no), + child: Text(widget.l10n.no), onPressed: () => bootstrap.wipeOnlineKeyBackup(false), )); break; case BootstrapState.askSetupOnlineKeyBackup: body = Text('Set up chat backup?'); buttons.add(AdaptiveFlatButton( - child: Text(L10n.of(context).yes), + child: Text(widget.l10n.yes), onPressed: () => bootstrap.askSetupOnlineKeyBackup(true), )); buttons.add(AdaptiveFlatButton( textColor: Theme.of(context).textTheme.bodyText1.color, - child: Text(L10n.of(context).no), + child: Text(widget.l10n.no), onPressed: () => bootstrap.askSetupOnlineKeyBackup(false), )); break; @@ -183,10 +188,10 @@ class _BootstrapDialogState extends State { body = ListTile( contentPadding: EdgeInsets.zero, leading: Icon(Icons.error_outline, color: Colors.red), - title: Text(L10n.of(context).oopsSomethingWentWrong), + title: Text(widget.l10n.oopsSomethingWentWrong), ); buttons.add(AdaptiveFlatButton( - child: Text(L10n.of(context).close), + child: Text(widget.l10n.close), onPressed: () => Navigator.of(context).pop(false), )); break; @@ -197,7 +202,7 @@ class _BootstrapDialogState extends State { title: Text('Chat backup has been initialized!'), ); buttons.add(AdaptiveFlatButton( - child: Text(L10n.of(context).close), + child: Text(widget.l10n.close), onPressed: () => Navigator.of(context).pop(false), )); break; @@ -222,7 +227,8 @@ class _BootstrapDialogState extends State { class _AskUnlockOldSsss extends StatefulWidget { final String keyId; final OpenSSSS ssssKey; - _AskUnlockOldSsss(this.keyId, this.ssssKey); + final L10n l10n; + _AskUnlockOldSsss(this.keyId, this.ssssKey, this.l10n); @override _AskUnlockOldSsssState createState() => _AskUnlockOldSsssState(); @@ -274,7 +280,7 @@ class _AskUnlockOldSsssState extends State<_AskUnlockOldSsss> { maxLines: 1, obscureText: true, decoration: InputDecoration( - hintText: L10n.of(context).passphraseOrKey, + hintText: widget.l10n.passphraseOrKey, prefixStyle: TextStyle(color: Theme.of(context).primaryColor), suffixStyle: TextStyle(color: Theme.of(context).primaryColor), border: OutlineInputBorder(), @@ -285,7 +291,7 @@ class _AskUnlockOldSsssState extends State<_AskUnlockOldSsss> { color: Theme.of(context).primaryColor, elevation: 5, textColor: Colors.white, - child: Text(L10n.of(context).submit), + child: Text(widget.l10n.submit), onPressed: () { input = textEditingController.text; checkInput(context); diff --git a/lib/components/dialogs/key_verification_dialog.dart b/lib/components/dialogs/key_verification_dialog.dart index b0981e8e..327e55a7 100644 --- a/lib/components/dialogs/key_verification_dialog.dart +++ b/lib/components/dialogs/key_verification_dialog.dart @@ -16,7 +16,12 @@ class KeyVerificationDialog extends StatefulWidget { final KeyVerification request; - KeyVerificationDialog({this.request}); + final L10n l10n; + + KeyVerificationDialog({ + this.request, + @required this.l10n, + }); @override _KeyVerificationPageState createState() => _KeyVerificationPageState(); @@ -86,7 +91,7 @@ class _KeyVerificationPageState extends State { if (valid.error != null) { await showOkAlertDialog( context: context, - message: L10n.of(context).incorrectPassphraseOrKey, + message: widget.l10n.incorrectPassphraseOrKey, ); } }; @@ -94,8 +99,7 @@ class _KeyVerificationPageState extends State { margin: EdgeInsets.only(left: 8.0, right: 8.0), child: Column( children: [ - Text(L10n.of(context).askSSSSSign, - style: TextStyle(fontSize: 20)), + Text(widget.l10n.askSSSSSign, style: TextStyle(fontSize: 20)), Container(height: 10), TextField( controller: textEditingController, @@ -109,7 +113,7 @@ class _KeyVerificationPageState extends State { maxLines: 1, obscureText: true, decoration: InputDecoration( - hintText: L10n.of(context).passphraseOrKey, + hintText: widget.l10n.passphraseOrKey, prefixStyle: TextStyle(color: Theme.of(context).primaryColor), suffixStyle: TextStyle(color: Theme.of(context).primaryColor), border: OutlineInputBorder(), @@ -120,30 +124,29 @@ class _KeyVerificationPageState extends State { ), ); buttons.add(AdaptiveFlatButton( - child: Text(L10n.of(context).submit), + child: Text(widget.l10n.submit), onPressed: () { input = textEditingController.text; checkInput(); }, )); buttons.add(AdaptiveFlatButton( - child: Text(L10n.of(context).skip), + child: Text(widget.l10n.skip), onPressed: () => widget.request.openSSSS(skip: true), )); break; case KeyVerificationState.askAccept: body = Container( - child: Text( - L10n.of(context).askVerificationRequest(widget.request.userId), + child: Text(widget.l10n.askVerificationRequest(widget.request.userId), style: TextStyle(fontSize: 20)), margin: EdgeInsets.only(left: 8.0, right: 8.0), ); buttons.add(AdaptiveFlatButton( - child: Text(L10n.of(context).accept), + child: Text(widget.l10n.accept), onPressed: () => widget.request.acceptVerification(), )); buttons.add(AdaptiveFlatButton( - child: Text(L10n.of(context).reject), + child: Text(widget.l10n.reject), onPressed: () { widget.request.rejectVerification().then((_) { Navigator.of(context).pop(); @@ -159,7 +162,7 @@ class _KeyVerificationPageState extends State { : CircularProgressIndicator(), SizedBox(height: 10), Text( - L10n.of(context).waitingPartnerAcceptRequest, + widget.l10n.waitingPartnerAcceptRequest, textAlign: TextAlign.center, ), ], @@ -172,14 +175,14 @@ class _KeyVerificationPageState extends State { // view for if "emoji" is a present sasType or not? String compareText; if (widget.request.sasTypes.contains('emoji')) { - compareText = L10n.of(context).compareEmojiMatch; + compareText = widget.l10n.compareEmojiMatch; compareWidget = TextSpan( children: widget.request.sasEmojis .map((e) => WidgetSpan(child: _Emoji(e))) .toList(), ); } else { - compareText = L10n.of(context).compareNumbersMatch; + compareText = widget.l10n.compareNumbersMatch; final numbers = widget.request.sasNumbers; final numbstr = '${numbers[0]}-${numbers[1]}-${numbers[2]}'; compareWidget = @@ -203,19 +206,19 @@ class _KeyVerificationPageState extends State { mainAxisSize: MainAxisSize.min, ); buttons.add(AdaptiveFlatButton( - child: Text(L10n.of(context).theyMatch), + child: Text(widget.l10n.theyMatch), onPressed: () => widget.request.acceptSas(), )); buttons.add(AdaptiveFlatButton( textColor: Colors.red, - child: Text(L10n.of(context).theyDontMatch), + child: Text(widget.l10n.theyDontMatch), onPressed: () => widget.request.rejectSas(), )); break; case KeyVerificationState.waitingSas: var acceptText = widget.request.sasTypes.contains('emoji') - ? L10n.of(context).waitingPartnerEmoji - : L10n.of(context).waitingPartnerNumbers; + ? widget.l10n.waitingPartnerEmoji + : widget.l10n.waitingPartnerNumbers; body = Column( children: [ PlatformInfos.isCupertinoStyle @@ -236,14 +239,14 @@ class _KeyVerificationPageState extends State { Icon(Icons.check_circle_outlined, color: Colors.green, size: 200.0), SizedBox(height: 10), Text( - L10n.of(context).verifySuccess, + widget.l10n.verifySuccess, textAlign: TextAlign.center, ), ], mainAxisSize: MainAxisSize.min, ); buttons.add(AdaptiveFlatButton( - child: Text(L10n.of(context).close), + child: Text(widget.l10n.close), onPressed: () => Navigator.of(context).pop(), )); break; @@ -260,7 +263,7 @@ class _KeyVerificationPageState extends State { mainAxisSize: MainAxisSize.min, ); buttons.add(FlatButton( - child: Text(L10n.of(context).close), + child: Text(widget.l10n.close), onPressed: () => Navigator.of(context).pop(), )); break; @@ -305,7 +308,7 @@ class _KeyVerificationPageState extends State { ], crossAxisAlignment: CrossAxisAlignment.start, ); - final title = Text(L10n.of(context).verifyTitle); + final title = Text(widget.l10n.verifyTitle); final content = Scrollbar( isAlwaysShown: true, controller: _scrollController, diff --git a/lib/components/dialogs/permission_slider_dialog.dart b/lib/components/dialogs/permission_slider_dialog.dart index 137e9cba..d49a2c6f 100644 --- a/lib/components/dialogs/permission_slider_dialog.dart +++ b/lib/components/dialogs/permission_slider_dialog.dart @@ -5,8 +5,13 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart'; class PermissionSliderDialog extends StatefulWidget { - const PermissionSliderDialog({Key key, this.initialPermission = 0}) - : super(key: key); + const PermissionSliderDialog({ + Key key, + this.initialPermission = 0, + @required this.l10n, + }) : super(key: key); + + final L10n l10n; Future show(BuildContext context) => PlatformInfos.isCupertinoStyle ? showCupertinoDialog(context: context, builder: (context) => this) @@ -41,7 +46,7 @@ class _PermissionSliderDialogState extends State { min: 0.0, ); final title = Text( - L10n.of(context).setPermissionsLevel, + widget.l10n.setPermissionsLevel, textAlign: TextAlign.center, ); final content = Column( @@ -49,9 +54,9 @@ class _PermissionSliderDialogState extends State { children: [ Text('Level: ' + (_permission == 100 - ? '$_permission (${L10n.of(context).admin})' + ? '$_permission (${widget.l10n.admin})' : _permission >= 50 - ? '$_permission (${L10n.of(context).moderator})' + ? '$_permission (${widget.l10n.moderator})' : _permission.toString())), Container( height: 56, @@ -61,11 +66,11 @@ class _PermissionSliderDialogState extends State { ); final buttons = [ AdaptiveFlatButton( - child: Text(L10n.of(context).cancel), + child: Text(widget.l10n.cancel), onPressed: () => Navigator.of(context).pop(null), ), AdaptiveFlatButton( - child: Text(L10n.of(context).confirm), + child: Text(widget.l10n.confirm), onPressed: () => Navigator.of(context).pop(_permission), ), ]; diff --git a/lib/components/dialogs/recording_dialog.dart b/lib/components/dialogs/recording_dialog.dart index a843577d..3dfe922d 100644 --- a/lib/components/dialogs/recording_dialog.dart +++ b/lib/components/dialogs/recording_dialog.dart @@ -7,8 +7,13 @@ import 'package:intl/intl.dart'; class RecordingDialog extends StatefulWidget { final Function onFinished; + final L10n l10n; - const RecordingDialog({this.onFinished, Key key}) : super(key: key); + const RecordingDialog({ + this.onFinished, + @required this.l10n, + Key key, + }) : super(key: key); @override _RecordingDialogState createState() => _RecordingDialogState(); @@ -67,7 +72,7 @@ class _RecordingDialogState extends State { SizedBox(width: 8), Expanded( child: Text( - '${L10n.of(context).recording}: $time', + '${widget.l10n.recording}: $time', style: TextStyle( fontSize: 18, ), @@ -78,7 +83,7 @@ class _RecordingDialogState extends State { actions: [ FlatButton( child: Text( - L10n.of(context).cancel.toUpperCase(), + widget.l10n.cancel.toUpperCase(), style: TextStyle( color: Theme.of(context).textTheme.bodyText2.color.withAlpha(150), ), @@ -88,7 +93,7 @@ class _RecordingDialogState extends State { FlatButton( child: Row( children: [ - Text(L10n.of(context).send.toUpperCase()), + Text(widget.l10n.send.toUpperCase()), SizedBox(width: 4), Icon(Icons.send_outlined, size: 15), ], diff --git a/lib/components/matrix.dart b/lib/components/matrix.dart index 93878834..724dead3 100644 --- a/lib/components/matrix.dart +++ b/lib/components/matrix.dart @@ -362,7 +362,10 @@ class MatrixState extends State { request.onUpdate = null; hidPopup = true; await request.acceptVerification(); - await KeyVerificationDialog(request: request).show(context); + await KeyVerificationDialog( + request: request, + l10n: L10n.of(context), + ).show(context); } else { request.onUpdate = null; hidPopup = true; diff --git a/lib/components/message_content.dart b/lib/components/message_content.dart index 79edf06d..dad4907c 100644 --- a/lib/components/message_content.dart +++ b/lib/components/message_content.dart @@ -52,7 +52,10 @@ class MessageContent extends StatelessWidget { timeline.cancelSubscriptions(); } }; - await KeyVerificationDialog(request: req).show(context); + await KeyVerificationDialog( + request: req, + l10n: L10n.of(context), + ).show(context); } else { final success = await showFutureLoadingDialog( context: context, diff --git a/lib/components/user_bottom_sheet.dart b/lib/components/user_bottom_sheet.dart index 60ca9d53..448219c8 100644 --- a/lib/components/user_bottom_sheet.dart +++ b/lib/components/user_bottom_sheet.dart @@ -59,9 +59,10 @@ class UserBottomSheet extends StatelessWidget { } break; case 'permission': - final newPermission = - await PermissionSliderDialog(initialPermission: user.powerLevel) - .show(context); + final newPermission = await PermissionSliderDialog( + initialPermission: user.powerLevel, + l10n: L10n.of(context), + ).show(context); if (newPermission != null) { if (newPermission == 100 && await _askConfirmation() == false) break; await showFutureLoadingDialog( @@ -82,7 +83,7 @@ class UserBottomSheet extends StatelessWidget { void _verifyAction(BuildContext context) async { final client = user.room.client; final req = await client.userDeviceKeys[user.id].startVerification(); - await KeyVerificationDialog(request: req).show(context); + await KeyVerificationDialog(request: req,l10n: L10n.of(context),).show(context); } @override diff --git a/lib/views/chat.dart b/lib/views/chat.dart index 87ec92b1..4a26d258 100644 --- a/lib/views/chat.dart +++ b/lib/views/chat.dart @@ -265,6 +265,7 @@ class _ChatState extends State { context: context, builder: (context) => RecordingDialog( onFinished: (r) => result = r, + l10n: L10n.of(context), )); if (result == null) return; final audioFile = File(result); diff --git a/lib/views/chat_encryption_settings.dart b/lib/views/chat_encryption_settings.dart index 4ff8b78a..50730c2c 100644 --- a/lib/views/chat_encryption_settings.dart +++ b/lib/views/chat_encryption_settings.dart @@ -36,7 +36,10 @@ class _ChatEncryptionSettingsState extends State { setState(() => null); } }; - await KeyVerificationDialog(request: req).show(context); + await KeyVerificationDialog( + request: req, + l10n: L10n.of(context), + ).show(context); break; case 'verify_manual': if (await showOkCancelAlertDialog( @@ -59,7 +62,10 @@ class _ChatEncryptionSettingsState extends State { setState(() => null); } }; - await KeyVerificationDialog(request: req).show(context); + await KeyVerificationDialog( + request: req, + l10n: L10n.of(context), + ).show(context); break; case 'block': if (key.directVerified) { diff --git a/lib/views/chat_permissions_settings.dart b/lib/views/chat_permissions_settings.dart index ae5c3bc3..b064ac38 100644 --- a/lib/views/chat_permissions_settings.dart +++ b/lib/views/chat_permissions_settings.dart @@ -20,9 +20,10 @@ class ChatPermissionsSettings extends StatelessWidget { return FlushbarHelper.createError(message: L10n.of(context).noPermission) .show(context); } - final newLevel = - await PermissionSliderDialog(initialPermission: currentLevel) - .show(context); + final newLevel = await PermissionSliderDialog( + initialPermission: currentLevel, + l10n: L10n.of(context), + ).show(context); if (newLevel == null) return; final content = Map.from( room.getState(EventTypes.RoomPowerLevels).content); diff --git a/lib/views/settings.dart b/lib/views/settings.dart index 37714cdd..1c08dd0b 100644 --- a/lib/views/settings.dart +++ b/lib/views/settings.dart @@ -516,7 +516,8 @@ class _SettingsState extends State { : null, onTap: () async { if (!client.encryption.crossSigning.enabled) { - return BootstrapDialog().show(context); + return BootstrapDialog(l10n: L10n.of(context)) + .show(context); } if (client.isUnknownSession) { final input = await showTextInputDialog( @@ -592,7 +593,8 @@ class _SettingsState extends State { : null, onTap: () async { if (!client.encryption.keyManager.enabled) { - return BootstrapDialog().show(context); + return BootstrapDialog(l10n: L10n.of(context)) + .show(context); } if (!(await client.encryption.keyManager.isCached())) { await requestSSSSCache(context);