From d689bbf38e7a7401405a4d04d2ea9f9520c750bd Mon Sep 17 00:00:00 2001 From: fufesou <13586388+fufesou@users.noreply.github.com> Date: Fri, 28 Jun 2024 00:57:16 +0800 Subject: [PATCH] refact: mobile more actions, divider (#8512) Signed-off-by: fufesou --- flutter/lib/common/widgets/toolbar.dart | 45 ++++-------- flutter/lib/mobile/pages/remote_page.dart | 89 +++++++++++++++-------- 2 files changed, 71 insertions(+), 63 deletions(-) diff --git a/flutter/lib/common/widgets/toolbar.dart b/flutter/lib/common/widgets/toolbar.dart index 27629d486..2c2da922a 100644 --- a/flutter/lib/common/widgets/toolbar.dart +++ b/flutter/lib/common/widgets/toolbar.dart @@ -6,7 +6,6 @@ import 'package:flutter_hbb/common.dart'; import 'package:flutter_hbb/common/shared_state.dart'; import 'package:flutter_hbb/common/widgets/dialog.dart'; import 'package:flutter_hbb/consts.dart'; -import 'package:flutter_hbb/models/input_model.dart'; import 'package:flutter_hbb/models/model.dart'; import 'package:flutter_hbb/models/platform_model.dart'; import 'package:get/get.dart'; @@ -23,6 +22,20 @@ class TTextMenu { required this.onPressed, this.trailingIcon, this.divider = false}); + + Widget getChild() { + if (trailingIcon != null) { + return Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + child, + trailingIcon!, + ], + ); + } else { + return child; + } + } } class TRadioMenu { @@ -77,36 +90,6 @@ List toolbarControls(BuildContext context, String id, FFI ffi) { final sessionId = ffi.sessionId; List v = []; - if (isMobile && - pi.platform == kPeerPlatformAndroid && - perms['keyboard'] != false) { - v.addAll([ - TTextMenu( - child: Text(translate('Back')), - onPressed: () => ffi.inputModel.onMobileBack(), - ), - TTextMenu( - child: Text(translate('Home')), - onPressed: () => ffi.inputModel.onMobileHome(), - ), - TTextMenu( - child: Text(translate('Apps')), - onPressed: () => ffi.inputModel.onMobileApps(), - ), - TTextMenu( - child: Text(translate('Volume up')), - onPressed: () => ffi.inputModel.onMobileVolumeUp(), - ), - TTextMenu( - child: Text(translate('Volume down')), - onPressed: () => ffi.inputModel.onMobileVolumeDown(), - ), - TTextMenu( - child: Text(translate('Power')), - onPressed: () => ffi.inputModel.onMobilePower(), - ), - ]); - } // elevation if (perms['keyboard'] != false && ffi.elevationModel.showRequestMenu) { v.add( diff --git a/flutter/lib/mobile/pages/remote_page.dart b/flutter/lib/mobile/pages/remote_page.dart index 490861f0e..7c4adcf92 100644 --- a/flutter/lib/mobile/pages/remote_page.dart +++ b/flutter/lib/mobile/pages/remote_page.dart @@ -553,29 +553,62 @@ class _RemotePageState extends State { color: MyTheme.canvasColor, child: Stack(children: paints)); } + List _getMobileActionMenus() { + if (gFFI.ffiModel.pi.platform != kPeerPlatformAndroid || + !gFFI.ffiModel.keyboard) { + return []; + } + return [ + TTextMenu( + child: Text(translate('Back')), + onPressed: () => gFFI.inputModel.onMobileBack(), + ), + TTextMenu( + child: Text(translate('Home')), + onPressed: () => gFFI.inputModel.onMobileHome(), + ), + TTextMenu( + child: Text(translate('Apps')), + onPressed: () => gFFI.inputModel.onMobileApps(), + ), + TTextMenu( + child: Text(translate('Volume up')), + onPressed: () => gFFI.inputModel.onMobileVolumeUp(), + ), + TTextMenu( + child: Text(translate('Volume down')), + onPressed: () => gFFI.inputModel.onMobileVolumeDown(), + ), + TTextMenu( + child: Text(translate('Power')), + onPressed: () => gFFI.inputModel.onMobilePower(), + ), + ]; + } + void showActions(String id) async { final size = MediaQuery.of(context).size; final x = 120.0; final y = size.height; + final mobileActionMenus = _getMobileActionMenus(); final menus = toolbarControls(context, id, gFFI); - getChild(TTextMenu menu) { - if (menu.trailingIcon != null) { - return Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - menu.child, - menu.trailingIcon!, - ]); - } else { - return menu.child; - } - } - final more = menus - .asMap() - .entries - .map((e) => PopupMenuItem(child: getChild(e.value), value: e.key)) - .toList(); + final List> more = [ + ...mobileActionMenus + .asMap() + .entries + .map((e) => + PopupMenuItem(child: e.value.getChild(), value: e.key)) + .toList(), + if (mobileActionMenus.isNotEmpty) PopupMenuDivider(), + ...menus + .asMap() + .entries + .map((e) => PopupMenuItem( + child: e.value.getChild(), + value: e.key + mobileActionMenus.length)) + .toList(), + ]; () async { var index = await showMenu( context: context, @@ -583,8 +616,12 @@ class _RemotePageState extends State { items: more, elevation: 8, ); - if (index != null && index < menus.length) { - menus[index].onPressed.call(); + if (index != null) { + if (index < mobileActionMenus.length) { + mobileActionMenus[index].onPressed.call(); + } else if (index < mobileActionMenus.length + more.length) { + menus[index - mobileActionMenus.length].onPressed.call(); + } } }(); } @@ -639,23 +676,11 @@ class _RemotePageState extends State { ), onPressVoiceCall), ]; - getChild(TTextMenu menu) { - if (menu.trailingIcon != null) { - return Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - menu.child, - menu.trailingIcon!, - ]); - } else { - return menu.child; - } - } final menuItems = menus .asMap() .entries - .map((e) => PopupMenuItem(child: getChild(e.value), value: e.key)) + .map((e) => PopupMenuItem(child: e.value.getChild(), value: e.key)) .toList(); Future.delayed(Duration.zero, () async { final size = MediaQuery.of(context).size;