diff --git a/lib/pages/setting/models/play_settings.dart b/lib/pages/setting/models/play_settings.dart index 06c07c9fd..f8545e5fc 100644 --- a/lib/pages/setting/models/play_settings.dart +++ b/lib/pages/setting/models/play_settings.dart @@ -1,5 +1,8 @@ +import 'dart:io' show Platform; + import 'package:PiliPlus/common/widgets/custom_icon.dart'; import 'package:PiliPlus/pages/setting/models/model.dart'; +import 'package:PiliPlus/pages/setting/widgets/slider_dialog.dart'; import 'package:PiliPlus/plugin/pl_player/models/play_repeat.dart'; import 'package:PiliPlus/utils/platform_utils.dart'; import 'package:PiliPlus/utils/storage.dart'; @@ -7,6 +10,7 @@ import 'package:PiliPlus/utils/storage_key.dart'; import 'package:PiliPlus/utils/storage_pref.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; +import 'package:material_design_icons_flutter/material_design_icons_flutter.dart'; List get playSettings => [ const SwitchModel( @@ -22,6 +26,13 @@ List get playSettings => [ title: '倍速设置', subtitle: '设置视频播放速度', ), + if (Platform.isAndroid) + NormalModel( + onTap: _showAngleDegreesDialog, + leading: const Icon(MdiIcons.angleAcute), + title: '倾斜角度阈值', + getSubtitle: () => '当前:「${Pref.angleDegrees}°」', + ), SwitchModel( title: '全屏显示电池电量', leading: const Icon(Icons.battery_3_bar), @@ -76,3 +87,25 @@ List get playSettings => [ .whenComplete(setState), ), ]; + +Future _showAngleDegreesDialog( + BuildContext context, + VoidCallback setState, +) async { + final res = await showDialog( + context: context, + builder: (context) => SliderDialog( + title: '倾斜角度阈值', + min: 10.0, + max: 90.0, + divisions: 80, + precise: 0, + value: Pref.angleDegrees.toDouble(), + suffix: '°', + ), + ); + if (res != null) { + await GStorage.setting.put(SettingBoxKey.angleDegrees, res.toInt()); + setState(); + } +} diff --git a/lib/plugin/pl_player/controller.dart b/lib/plugin/pl_player/controller.dart index dfa48f197..3e6ed2654 100644 --- a/lib/plugin/pl_player/controller.dart +++ b/lib/plugin/pl_player/controller.dart @@ -487,7 +487,9 @@ class PlPlayerController with BlockConfigMixin { PlPlayerController._() { if (PlatformUtils.isMobile) { _orientationListener = NativeDeviceOrientationPlatform.instance - .onOrientationChanged(useSensor: Platform.isAndroid) + .onOrientationChanged( + angleDegrees: Platform.isAndroid ? Pref.angleDegrees : null, + ) .listen(_onOrientationChanged); } diff --git a/lib/utils/storage_key.dart b/lib/utils/storage_key.dart index b59964ee4..49811d908 100644 --- a/lib/utils/storage_key.dart +++ b/lib/utils/storage_key.dart @@ -52,7 +52,8 @@ abstract final class SettingBoxKey { followOrderType = 'followOrderType', enableImgMenu = 'enableImgMenu', touchSlopH = 'touchSlopH', - floatingNavBar = 'floatingNavBar'; + floatingNavBar = 'floatingNavBar', + angleDegrees = 'angleDegrees'; static const String windowSize = 'windowSize', windowPosition = 'windowPosition', diff --git a/lib/utils/storage_pref.dart b/lib/utils/storage_pref.dart index dd8a73149..8ca7e1f2d 100644 --- a/lib/utils/storage_pref.dart +++ b/lib/utils/storage_pref.dart @@ -518,4 +518,7 @@ abstract final class Pref { static bool get floatingNavBar => _setting.get(SettingBoxKey.floatingNavBar, defaultValue: false); + + static int get angleDegrees => + _setting.get(SettingBoxKey.angleDegrees, defaultValue: 30); } diff --git a/pubspec.lock b/pubspec.lock index 4917860de..27e163c41 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1203,7 +1203,7 @@ packages: description: path: "." ref: master - resolved-ref: a987a459f17af0002397e49800ba4f68912b375c + resolved-ref: "2c74f4d534dfd9b8f66382f82b3540f32be9abd9" url: "https://github.com/bggRGjQaUbCoE/flutter_native_device_orientation.git" source: git version: "2.0.5"