From 843933f45e05c81467a96346e384284f7211258d Mon Sep 17 00:00:00 2001 From: lxm <1274844347@qq.com> Date: Sat, 20 Sep 2025 21:43:06 +0800 Subject: [PATCH] =?UTF-8?q?refactor(translation):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E6=9D=83=E9=99=90=E6=A3=80=E6=9F=A5=E9=80=BB=E8=BE=91=E5=92=8C?= =?UTF-8?q?=E6=82=AC=E6=B5=AE=E6=8C=89=E9=92=AE=E6=8B=96=E6=8B=BD=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复Android 11+版本存储权限检查直接返回的问题 将悬浮按钮拖拽逻辑提取为独立方法并增加安全区域检查 在调试模式下显示opus解码测试选项 --- lib/modules/settings/views/settings_view.dart | 37 +++++++++++-------- .../translation_list_controller.dart | 2 +- .../widgets/draggable_floating_button.dart | 36 +++++++++++------- 3 files changed, 45 insertions(+), 30 deletions(-) diff --git a/lib/modules/settings/views/settings_view.dart b/lib/modules/settings/views/settings_view.dart index 42b9daa3d..d36801018 100644 --- a/lib/modules/settings/views/settings_view.dart +++ b/lib/modules/settings/views/settings_view.dart @@ -515,22 +515,27 @@ class SettingsView extends GetView { // ? Colors.white.withOpacity(0.1) // : Colors.grey[200]), // //BLE测试 - // _buildSimpleNavigationSetting( - // title: 'opus解码测试', - // subtitle: '测试opus解码', - // icon: Icons.bluetooth_searching, - // iconBgColor: isDarkMode - // ? Colors.green[900]!.withOpacity(0.3) - // : Colors.green[100]!, - // iconColor: - // isDarkMode ? Colors.green[300]! : Colors.green[600]!, - // titleColor: isDarkMode ? Colors.white : null, - // subtitleColor: isDarkMode ? Colors.white70 : null, - // onTap: () { - // Get.toNamed(Routes.opusTest); - // }, - // isDarkMode: isDarkMode, - // ), + + Obx(() => controller.showDebugInfo.value + ? _buildSimpleNavigationSetting( + title: 'opus解码测试', + subtitle: '测试opus解码', + icon: Icons.bluetooth_searching, + iconBgColor: isDarkMode + ? Colors.green[900]!.withOpacity(0.3) + : Colors.green[100]!, + iconColor: isDarkMode + ? Colors.green[300]! + : Colors.green[600]!, + titleColor: isDarkMode ? Colors.white : null, + subtitleColor: isDarkMode ? Colors.white70 : null, + onTap: () { + Get.toNamed(Routes.opusTest); + }, + isDarkMode: isDarkMode, + ) + : const SizedBox.shrink()), + // Divider( // height: 1, // color: isDarkMode diff --git a/lib/modules/translation/controllers/translation_list_controller.dart b/lib/modules/translation/controllers/translation_list_controller.dart index 55539706c..2d4bffc19 100644 --- a/lib/modules/translation/controllers/translation_list_controller.dart +++ b/lib/modules/translation/controllers/translation_list_controller.dart @@ -104,7 +104,7 @@ class TranslationListController extends GetxController { // Android 11+ (API 30+) 不需要存储权限 if (sdkVersion >= 30) { Logger.d("Permission", "Android 11+版本,无需请求存储权限"); - //return true; // 直接返回true,表示可以使用存储 + return; // 直接返回,表示可以使用存储 } } catch (e) { Logger.e("Permission", "获取Android版本信息失败: $e"); diff --git a/lib/modules/translation/views/widgets/draggable_floating_button.dart b/lib/modules/translation/views/widgets/draggable_floating_button.dart index 98b25adb3..80fa508f0 100644 --- a/lib/modules/translation/views/widgets/draggable_floating_button.dart +++ b/lib/modules/translation/views/widgets/draggable_floating_button.dart @@ -55,19 +55,7 @@ class DraggableFloatingButton extends StatelessWidget { ), ), onDragEnd: (details) { - // 计算新位置(相对于屏幕右下角) - final screenSize = MediaQuery.of(Get.context!).size; - final newRight = screenSize.width - details.offset.dx - 56.w; - final newBottom = screenSize.height - details.offset.dy - 56.w; - - // 边界检查,确保按钮不会超出屏幕 - final clampedRight = newRight.clamp(0.0, screenSize.width - 56.w); - final clampedBottom = - newBottom.clamp(0.0, screenSize.height - 56.w); - - // 保存新位置 - controller.saveFloatingButtonPosition( - Offset(clampedRight, clampedBottom)); + _handleDragEnd(context, details); }, child: GestureDetector( onTap: () => _showTranslationModeSelector(isDarkMode), @@ -96,6 +84,28 @@ class DraggableFloatingButton extends StatelessWidget { )); } + /// 处理拖拽结束事件 + void _handleDragEnd(BuildContext context, DraggableDetails details) { + final screenSize = MediaQuery.of(context).size; + final appBarHeight = Scaffold.of(context).appBarMaxHeight ?? kToolbarHeight; + final statusBarHeight = MediaQuery.of(context).padding.top; + final safeAreaTop = statusBarHeight + appBarHeight; + + // 计算新位置(相对于屏幕右下角) + final newRight = screenSize.width - details.offset.dx - 56.w; + final newBottom = screenSize.height - details.offset.dy - 56.w; + + // 边界检查,确保按钮不会超出屏幕或被AppBar遮盖 + final clampedRight = newRight.clamp(0.0, screenSize.width - 56.w); + final clampedBottom = newBottom.clamp( + 0.0, // 底部边界 + screenSize.height - safeAreaTop - 56.w, // 顶部边界(避免被AppBar遮盖) + ); + + // 保存新位置 + controller.saveFloatingButtonPosition(Offset(clampedRight, clampedBottom)); + } + /// 显示翻译模式选择器 void _showTranslationModeSelector(bool isDarkMode) { TranslationModeSelector.show(isDarkMode);