Skip to content

An open-source remote desktop application designed for self-hosting, as an alternative to TeamViewer.

refact: mobile more actions, divider (#8512)

fufesoud689bbf38e7a
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<T> {
@@ -77,36 +90,6 @@ List<TTextMenu> toolbarControls(BuildContext context, String id, FFI ffi) {
final sessionId = ffi.sessionId;
List<TTextMenu> 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<RemotePage> {
color: MyTheme.canvasColor, child: Stack(children: paints));
}
+ List<TTextMenu> _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<int>(child: getChild(e.value), value: e.key))
- .toList();
+ final List<PopupMenuEntry<int>> more = [
+ ...mobileActionMenus
+ .asMap()
+ .entries
+ .map((e) =>
+ PopupMenuItem<int>(child: e.value.getChild(), value: e.key))
+ .toList(),
+ if (mobileActionMenus.isNotEmpty) PopupMenuDivider(),
+ ...menus
+ .asMap()
+ .entries
+ .map((e) => PopupMenuItem<int>(
+ 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<RemotePage> {
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<RemotePage> {
),
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<int>(child: getChild(e.value), value: e.key))
+ .map((e) => PopupMenuItem<int>(child: e.value.getChild(), value: e.key))
.toList();
Future.delayed(Duration.zero, () async {
final size = MediaQuery.of(context).size;