UI optimization

This commit is contained in:
csf 2022-07-29 22:07:45 +08:00
parent 2d31e44b54
commit 67a3db7378
3 changed files with 64 additions and 34 deletions

View File

@ -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");

View File

@ -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();
}
})
];

View File

@ -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")),