diff --git a/lib/pages/setting/pages/play_speed_set.dart b/lib/pages/setting/pages/play_speed_set.dart index c5eb70e6..ceff07ed 100644 --- a/lib/pages/setting/pages/play_speed_set.dart +++ b/lib/pages/setting/pages/play_speed_set.dart @@ -1,6 +1,8 @@ import 'package:flutter/material.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:hive/hive.dart'; +import 'package:pilipala/pages/setting/widgets/switch_item.dart'; +import 'package:pilipala/plugin/pl_player/index.dart'; import 'package:pilipala/plugin/pl_player/models/play_speed.dart'; import 'package:pilipala/utils/storage.dart'; @@ -13,9 +15,11 @@ class PlaySpeedPage extends StatefulWidget { class _PlaySpeedPageState extends State { Box videoStorage = GStrorage.video; + Box settingStorage = GStrorage.setting; late double playSpeedDefault; late double longPressSpeedDefault; late List customSpeedsList; + late bool enableAutoLongPressSpeed; List> sheetMenu = [ { 'id': 1, @@ -24,6 +28,7 @@ class _PlaySpeedPageState extends State { Icons.speed, size: 21, ), + 'show': true, }, { 'id': 2, @@ -32,6 +37,7 @@ class _PlaySpeedPageState extends State { Icons.speed_sharp, size: 21, ), + 'show': true, }, { 'id': -1, @@ -40,6 +46,7 @@ class _PlaySpeedPageState extends State { Icons.delete_outline, size: 21, ), + 'show': true, }, ]; @@ -55,6 +62,15 @@ class _PlaySpeedPageState extends State { // 自定义倍速 customSpeedsList = videoStorage.get(VideoBoxKey.customSpeedsList, defaultValue: []); + enableAutoLongPressSpeed = settingStorage + .get(SettingBoxKey.enableAutoLongPressSpeed, defaultValue: false); + if (enableAutoLongPressSpeed) { + Map newItem = sheetMenu[1]; + newItem['show'] = false; + setState(() { + sheetMenu[1] = newItem; + }); + } } // 添加自定义倍速 @@ -120,19 +136,21 @@ class _PlaySpeedPageState extends State { //重要 itemCount: sheetMenu.length, itemBuilder: (BuildContext context, int index) { - return ListTile( - onTap: () { - Navigator.pop(context); - menuAction(type, i, sheetMenu[index]['id']); - }, - minLeadingWidth: 0, - iconColor: Theme.of(context).colorScheme.onSurface, - leading: sheetMenu[index]['leading'], - title: Text( - sheetMenu[index]['title'], - style: Theme.of(context).textTheme.titleSmall, - ), - ); + return sheetMenu[index]['show'] + ? ListTile( + onTap: () { + Navigator.pop(context); + menuAction(type, i, sheetMenu[index]['id']); + }, + minLeadingWidth: 0, + iconColor: Theme.of(context).colorScheme.onSurface, + leading: sheetMenu[index]['leading'], + title: Text( + sheetMenu[index]['title'], + style: Theme.of(context).textTheme.titleSmall, + ), + ) + : const SizedBox(); }, ), ); @@ -210,11 +228,27 @@ class _PlaySpeedPageState extends State { title: const Text('默认倍速'), subtitle: Text(playSpeedDefault.toString()), ), - ListTile( - dense: false, - title: const Text('默认长按倍速'), - subtitle: Text(longPressSpeedDefault.toString()), + SetSwitchItem( + title: '动态长按倍速', + subTitle: '根据默认倍速长按时自动双倍', + setKey: SettingBoxKey.enableAutoLongPressSpeed, + defaultVal: enableAutoLongPressSpeed, + callFn: (val) { + Map newItem = sheetMenu[1]; + val ? newItem['show'] = false : newItem['show'] = true; + setState(() { + sheetMenu[1] = newItem; + enableAutoLongPressSpeed = val; + }); + }, ), + !enableAutoLongPressSpeed + ? ListTile( + dense: false, + title: const Text('默认长按倍速'), + subtitle: Text(longPressSpeedDefault.toString()), + ) + : const SizedBox(), Padding( padding: const EdgeInsets.only( left: 14, diff --git a/lib/plugin/pl_player/controller.dart b/lib/plugin/pl_player/controller.dart index 05280e75..5ba1ccfb 100644 --- a/lib/plugin/pl_player/controller.dart +++ b/lib/plugin/pl_player/controller.dart @@ -220,6 +220,7 @@ class PlPlayerController { late List speedsList; // 缓存 double? defaultDuration; + late bool enableAutoLongPressSpeed = false; // 播放顺序相关 PlayRepeat playRepeat = PlayRepeat.pause; @@ -249,8 +250,12 @@ class PlPlayerController { ); _playbackSpeed.value = videoStorage.get(VideoBoxKey.playSpeedDefault, defaultValue: 1.0); - _longPressSpeed.value = - videoStorage.get(VideoBoxKey.longPressSpeedDefault, defaultValue: 2.0); + enableAutoLongPressSpeed = setting + .get(SettingBoxKey.enableAutoLongPressSpeed, defaultValue: false); + if (!enableAutoLongPressSpeed) { + _longPressSpeed.value = videoStorage + .get(VideoBoxKey.longPressSpeedDefault, defaultValue: 2.0); + } List speedsListTemp = videoStorage.get(VideoBoxKey.customSpeedsList, defaultValue: []); speedsList = List.from(speedsListTemp); @@ -858,7 +863,8 @@ class PlPlayerController { } _doubleSpeedStatus.value = val; if (val) { - setPlaybackSpeed(longPressSpeed); + setPlaybackSpeed( + enableAutoLongPressSpeed ? playbackSpeed * 2 : longPressSpeed); } else { print(playbackSpeed); setPlaybackSpeed(playbackSpeed); diff --git a/lib/utils/storage.dart b/lib/utils/storage.dart index 4e92c1ff..3f187638 100644 --- a/lib/utils/storage.dart +++ b/lib/utils/storage.dart @@ -107,6 +107,7 @@ class SettingBoxKey { static const String p1080 = 'p1080'; static const String enableCDN = 'enableCDN'; static const String autoPiP = 'autoPiP'; + static const String enableAutoLongPressSpeed = 'enableAutoLongPressSpeed'; // youtube 双击快进快退 static const String enableQuickDouble = 'enableQuickDouble';