From 67a3db7378775765a6773a4c8432f986824f65f6 Mon Sep 17 00:00:00 2001 From: csf Date: Fri, 29 Jul 2022 22:07:45 +0800 Subject: [PATCH] UI optimization --- flutter/lib/models/server_model.dart | 38 ++++++++++--------- flutter/lib/pages/server_page.dart | 56 ++++++++++++++++++++-------- flutter/lib/widgets/dialog.dart | 4 ++ 3 files changed, 64 insertions(+), 34 deletions(-) diff --git a/flutter/lib/models/server_model.dart b/flutter/lib/models/server_model.dart index 94a0f8187..2cf41725b 100644 --- a/flutter/lib/models/server_model.dart +++ b/flutter/lib/models/server_model.dart @@ -89,14 +89,13 @@ class ServerModel with ChangeNotifier { }(); Timer.periodic(Duration(seconds: 1), (timer) { - var update = false; var status = int.tryParse(FFI.getByName('connect_statue')) ?? 0; if (status > 0) { status = 1; } if (status != _connectStatus) { _connectStatus = status; - update = true; + notifyListeners(); } final res = FFI.getByName('check_clients_length', _clients.length.toString()); @@ -105,25 +104,28 @@ class ServerModel with ChangeNotifier { updateClientState(res); } - final temporaryPassword = FFI.getByName("temporary_password"); - final verificationMethod = FFI.getByName("option", "verification-method"); - if (_serverPasswd.text != temporaryPassword) { - _serverPasswd.text = temporaryPassword; - update = true; - } - - if (_verificationMethod != verificationMethod) { - debugPrint("_verificationMethod changed: $verificationMethod"); - _verificationMethod = verificationMethod; - update = true; - } - - if (update) { - notifyListeners(); - } + updatePasswordModel(); }); } + updatePasswordModel() { + var update = false; + final temporaryPassword = FFI.getByName("temporary_password"); + final verificationMethod = FFI.getByName("option", "verification-method"); + if (_serverPasswd.text != temporaryPassword) { + _serverPasswd.text = temporaryPassword; + update = true; + } + + if (_verificationMethod != verificationMethod) { + _verificationMethod = verificationMethod; + update = true; + } + if (update) { + notifyListeners(); + } + } + toggleAudio() async { if (!_audioOk && !await PermissionManager.check("audio")) { final res = await PermissionManager.request("audio"); diff --git a/flutter/lib/pages/server_page.dart b/flutter/lib/pages/server_page.dart index 279420d7e..bb80b8d51 100644 --- a/flutter/lib/pages/server_page.dart +++ b/flutter/lib/pages/server_page.dart @@ -26,43 +26,66 @@ class ServerPage extends StatelessWidget implements PageShape { return [ PopupMenuItem( child: Text(translate("Change ID")), + padding: EdgeInsets.symmetric(horizontal: 16.0), value: "changeID", enabled: false, ), PopupMenuItem( child: Text(translate("Set permanent password")), + padding: EdgeInsets.symmetric(horizontal: 16.0), value: "setPermanentPassword", enabled: FFI.serverModel.verificationMethod != kUseTemporaryPassword, ), PopupMenuItem( child: Text(translate("Set temporary password length")), + padding: EdgeInsets.symmetric(horizontal: 16.0), value: "setTemporaryPasswordLength", enabled: FFI.serverModel.verificationMethod != kUsePermanentPassword, ), const PopupMenuDivider(), - CheckedPopupMenuItem( - checked: - FFI.serverModel.verificationMethod == kUseTemporaryPassword, - padding: EdgeInsets.all(0), + PopupMenuItem( + padding: EdgeInsets.symmetric(horizontal: 0.0), value: kUseTemporaryPassword, - child: Text(translate("Use temporary password")), + child: Container( + child: ListTile( + title: Text(translate("Use temporary password")), + trailing: Icon( + Icons.check, + color: FFI.serverModel.verificationMethod == + kUseTemporaryPassword + ? null + : Color(0xFFFFFFFF), + ))), ), - CheckedPopupMenuItem( - checked: - FFI.serverModel.verificationMethod == kUsePermanentPassword, - padding: EdgeInsets.all(0), + PopupMenuItem( + padding: EdgeInsets.symmetric(horizontal: 0.0), value: kUsePermanentPassword, - child: Text(translate("Use permanent password")), + child: ListTile( + title: Text(translate("Use permanent password")), + trailing: Icon( + Icons.check, + color: FFI.serverModel.verificationMethod == + kUsePermanentPassword + ? null + : Color(0xFFFFFFFF), + )), ), - CheckedPopupMenuItem( - checked: FFI.serverModel.verificationMethod != - kUseTemporaryPassword && - FFI.serverModel.verificationMethod != kUsePermanentPassword, - padding: EdgeInsets.all(0), + PopupMenuItem( + padding: EdgeInsets.symmetric(horizontal: 0.0), value: kUseBothPasswords, - child: Text(translate("Use both passwords")), + child: ListTile( + title: Text(translate("Use both passwords")), + trailing: Icon( + Icons.check, + color: FFI.serverModel.verificationMethod != + kUseTemporaryPassword && + FFI.serverModel.verificationMethod != + kUsePermanentPassword + ? null + : Color(0xFFFFFFFF), + )), ), ]; }, @@ -80,6 +103,7 @@ class ServerPage extends StatelessWidget implements PageShape { ..["name"] = "verification-method" ..["value"] = value; FFI.setByName('option', jsonEncode(msg)); + FFI.serverModel.updatePasswordModel(); } }) ]; diff --git a/flutter/lib/widgets/dialog.dart b/flutter/lib/widgets/dialog.dart index 106685071..699e30696 100644 --- a/flutter/lib/widgets/dialog.dart +++ b/flutter/lib/widgets/dialog.dart @@ -120,6 +120,10 @@ void setTemporaryPasswordLengthDialog() { ..["value"] = newValue; FFI.setByName("option", jsonEncode(msg)); FFI.setByName("temporary_password"); + Future.delayed(Duration(milliseconds: 200), () { + close(); + showSuccess(); + }); }; return CustomAlertDialog( title: Text(translate("Set temporary password length")),