Merge pull request from 21pages/android

opt mobile ui
This commit is contained in:
RustDesk 2023-06-10 11:55:48 +08:00 committed by GitHub
commit c4712d68a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 71 deletions
flutter/lib
common/widgets
mobile/pages

@ -450,75 +450,49 @@ class _PeerSortDropdownState extends State<PeerSortDropdown> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final deco = BoxDecoration( final enableStyle = TextStyle(
color: Theme.of(context).colorScheme.background, color: Theme.of(context).textTheme.titleLarge?.color,
borderRadius: BorderRadius.circular(5), fontSize: MenuConfig.fontSize,
); fontWeight: FontWeight.normal);
final disableStyle = TextStyle(
final translated_text = { color: Colors.grey,
for (var e in PeerSortType.values) e: translate(e) fontSize: MenuConfig.fontSize,
}; fontWeight: FontWeight.normal);
List<PopupMenuEntry> items = List.empty(growable: true);
final double max_width = items.add(PopupMenuItem(
50 + translated_text.values.map((e) => e.length).reduce(max) * 10; enabled: false,
return Container( child: Text(translate("Sort by"), style: disableStyle)));
padding: EdgeInsets.all(4.0), for (var e in PeerSortType.values) {
decoration: deco, items.add(PopupMenuItem(
child: DropdownButtonHideUnderline( child: Obx(() => getRadio(
child: DropdownButton2<String>( Text(translate(e), style: enableStyle), e, peerSort.value,
onChanged: (v) async { (String? v) async {
if (v != null) { if (v != null) {
setState(() => peerSort.value = v); peerSort.value = v;
await bind.setLocalFlutterConfig( await bind.setLocalFlutterConfig(
k: "peer-sorting", k: "peer-sorting",
v: peerSort.value, v: peerSort.value,
); );
} }
}, }))));
customButton: Icon( }
return InkWell(
child: Icon(
Icons.sort, Icons.sort,
size: 18, size: 18,
), ),
isExpanded: true, onTapDown: (details) {
dropdownStyleData: DropdownStyleData( final x = details.globalPosition.dx;
decoration: BoxDecoration( final y = details.globalPosition.dy;
color: Theme.of(context).cardColor, final menuPos = RelativeRect.fromLTRB(x, y, x, y);
borderRadius: BorderRadius.circular(10), showMenu(
), context: context,
width: max_width, position: menuPos,
), items: items,
items: [ elevation: 8,
DropdownMenuItem<String>( );
alignment: Alignment.center, },
child: Text(
translate("Sort by"),
style: TextStyle(fontWeight: FontWeight.bold),
),
enabled: false,
),
...translated_text.entries
.map<DropdownMenuItem<String>>(
(MapEntry entry) => DropdownMenuItem<String>(
value: entry.key,
child: Row(
children: [
Icon(
entry.key == peerSort.value
? Icons.radio_button_checked_rounded
: Icons.radio_button_off_rounded,
size: 18,
).paddingOnly(right: 12),
Text(
entry.value,
overflow: TextOverflow.ellipsis,
),
],
),
),
)
.toList(),
]),
),
); );
} }
} }

@ -317,8 +317,8 @@ class _SettingsState extends State<SettingsPage> with WidgetsBindingObserver {
await AndroidPermissionManager.request( await AndroidPermissionManager.request(
kRequestIgnoreBatteryOptimizations); kRequestIgnoreBatteryOptimizations);
} else { } else {
final res = await gFFI.dialogManager final res = await gFFI.dialogManager.show<bool>(
.show<bool>((setState, close, context) => CustomAlertDialog( (setState, close, context) => CustomAlertDialog(
title: Text(translate("Open System Setting")), title: Text(translate("Open System Setting")),
content: Text(translate( content: Text(translate(
"android_open_battery_optimizations_tip")), "android_open_battery_optimizations_tip")),
@ -506,12 +506,12 @@ void showLanguageSettings(OverlayDialogManager dialogManager) async {
final langs = json.decode(await bind.mainGetLangs()) as List<dynamic>; final langs = json.decode(await bind.mainGetLangs()) as List<dynamic>;
var lang = bind.mainGetLocalOption(key: "lang"); var lang = bind.mainGetLocalOption(key: "lang");
dialogManager.show((setState, close, context) { dialogManager.show((setState, close, context) {
setLang(v) { setLang(v) async {
if (lang != v) { if (lang != v) {
setState(() { setState(() {
lang = v; lang = v;
}); });
bind.mainSetLocalOption(key: "lang", value: v); await bind.mainSetLocalOption(key: "lang", value: v);
HomePage.homeKey.currentState?.refreshPages(); HomePage.homeKey.currentState?.refreshPages();
Future.delayed(Duration(milliseconds: 200), close); Future.delayed(Duration(milliseconds: 200), close);
} }