Skip to content

Commit

Permalink
Merge branch 'feature-hiddenRelateVideo'
Browse files Browse the repository at this point in the history
  • Loading branch information
guozhigq committed Mar 13, 2024
2 parents 73693c5 + 99e6abd commit a5558de
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 103 deletions.
1 change: 0 additions & 1 deletion lib/pages/live_room/widgets/bottom_control.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class BottomControl extends StatefulWidget implements PreferredSizeWidget {

class _BottomControlState extends State<BottomControl> {
late PlayUrlModel videoInfo;
List<PlaySpeed> playSpeed = PlaySpeed.values;
TextStyle subTitleStyle = const TextStyle(fontSize: 12);
TextStyle titleStyle = const TextStyle(fontSize: 14);
Size get preferredSize => const Size(double.infinity, kToolbarHeight);
Expand Down
6 changes: 6 additions & 0 deletions lib/pages/setting/extra_setting.dart
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ class _ExtraSettingState extends State<ExtraSetting> {
setKey: SettingBoxKey.enableAi,
defaultVal: true,
),
const SetSwitchItem(
title: '相关视频推荐',
subTitle: '视频详情页推荐相关视频',
setKey: SettingBoxKey.enableRelatedVideo,
defaultVal: true,
),
ListTile(
dense: false,
title: Text('评论展示', style: titleStyle),
Expand Down
101 changes: 53 additions & 48 deletions lib/pages/setting/pages/play_speed_set.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class _PlaySpeedPageState extends State<PlaySpeedPage> {
Box videoStorage = GStrorage.video;
Box settingStorage = GStrorage.setting;
late double playSpeedDefault;
late List<double> playSpeedSystem;
late double longPressSpeedDefault;
late List customSpeedsList;
late bool enableAutoLongPressSpeed;
Expand Down Expand Up @@ -53,6 +54,9 @@ class _PlaySpeedPageState extends State<PlaySpeedPage> {
@override
void initState() {
super.initState();
// 系统预设倍速
playSpeedSystem =
videoStorage.get(VideoBoxKey.playSpeedSystem, defaultValue: playSpeed);
// 默认倍速
playSpeedDefault =
videoStorage.get(VideoBoxKey.playSpeedDefault, defaultValue: 1.0);
Expand All @@ -64,6 +68,7 @@ class _PlaySpeedPageState extends State<PlaySpeedPage> {
videoStorage.get(VideoBoxKey.customSpeedsList, defaultValue: []);
enableAutoLongPressSpeed = settingStorage
.get(SettingBoxKey.enableAutoLongPressSpeed, defaultValue: false);
// 开启动态长按倍速时不展示
if (enableAutoLongPressSpeed) {
Map newItem = sheetMenu[1];
newItem['show'] = false;
Expand Down Expand Up @@ -123,7 +128,7 @@ class _PlaySpeedPageState extends State<PlaySpeedPage> {
}

// 设定倍速弹窗
void showBottomSheet(type, i) {
void showBottomSheet(String type, int i) {
showModalBottomSheet<void>(
context: context,
isScrollControlled: true,
Expand Down Expand Up @@ -159,18 +164,11 @@ class _PlaySpeedPageState extends State<PlaySpeedPage> {
}

//
void menuAction(type, index, id) async {
void menuAction(type, int index, id) async {
double chooseSpeed = 1.0;
if (type == 'system' && id == -1) {
SmartDialog.showToast('系统预设倍速不支持删除');
return;
}
// 获取当前选中的倍速值
if (type == 'system') {
chooseSpeed = PlaySpeed.values[index].value;
} else {
chooseSpeed = customSpeedsList[index];
}
chooseSpeed =
type == 'system' ? playSpeedSystem[index] : customSpeedsList[index];
// 设置
if (id == 1) {
// 设置默认倍速
Expand All @@ -182,17 +180,22 @@ class _PlaySpeedPageState extends State<PlaySpeedPage> {
videoStorage.put(
VideoBoxKey.longPressSpeedDefault, longPressSpeedDefault);
} else if (id == -1) {
if (customSpeedsList[index] == playSpeedDefault) {
playSpeedDefault = 1.0;
videoStorage.put(VideoBoxKey.playSpeedDefault, playSpeedDefault);
late List speedsList =
type == 'system' ? playSpeedSystem : customSpeedsList;
if (speedsList[index] == playSpeedDefault) {
SmartDialog.showToast('默认倍速不可删除');
}
if (customSpeedsList[index] == longPressSpeedDefault) {
if (speedsList[index] == longPressSpeedDefault) {
longPressSpeedDefault = 2.0;
videoStorage.put(
VideoBoxKey.longPressSpeedDefault, longPressSpeedDefault);
}
customSpeedsList.removeAt(index);
await videoStorage.put(VideoBoxKey.customSpeedsList, customSpeedsList);
speedsList.removeAt(index);
await videoStorage.put(
type == 'system'
? VideoBoxKey.playSpeedSystem
: VideoBoxKey.customSpeedsList,
speedsList);
}
setState(() {});
SmartDialog.showToast('操作成功');
Expand Down Expand Up @@ -249,38 +252,40 @@ class _PlaySpeedPageState extends State<PlaySpeedPage> {
subtitle: Text(longPressSpeedDefault.toString()),
)
: const SizedBox(),
Padding(
padding: const EdgeInsets.only(
left: 14,
right: 14,
bottom: 10,
top: 20,
),
child: Text(
'系统预设倍速',
style: Theme.of(context).textTheme.titleMedium,
),
),
Padding(
padding: const EdgeInsets.only(
left: 18,
right: 18,
bottom: 30,
),
child: Wrap(
alignment: WrapAlignment.start,
spacing: 8,
runSpacing: 2,
children: [
for (var i in PlaySpeed.values) ...[
FilledButton.tonal(
onPressed: () => showBottomSheet('system', i.index),
child: Text(i.description),
),
]
],
if (playSpeedSystem.isNotEmpty) ...[
Padding(
padding: const EdgeInsets.only(
left: 14,
right: 14,
bottom: 10,
top: 20,
),
child: Text(
'系统预设倍速',
style: Theme.of(context).textTheme.titleMedium,
),
),
),
Padding(
padding: const EdgeInsets.only(
left: 18,
right: 18,
bottom: 30,
),
child: Wrap(
alignment: WrapAlignment.start,
spacing: 8,
runSpacing: 2,
children: [
for (int i = 0; i < playSpeedSystem.length; i++) ...[
FilledButton.tonal(
onPressed: () => showBottomSheet('system', i),
child: Text(playSpeedSystem[i].toString()),
),
]
],
),
)
],
Padding(
padding: const EdgeInsets.only(
left: 14,
Expand Down
4 changes: 3 additions & 1 deletion lib/pages/video/detail/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class VideoDetailController extends GetxController
late int cacheAudioQa;

PersistentBottomSheetController? replyReplyBottomSheetCtr;
late bool enableRelatedVideo;

@override
void onInit() {
Expand All @@ -115,7 +116,8 @@ class VideoDetailController extends GetxController
autoPlay.value =
setting.get(SettingBoxKey.autoPlayEnable, defaultValue: true);
enableHA.value = setting.get(SettingBoxKey.enableHA, defaultValue: true);

enableRelatedVideo =
setting.get(SettingBoxKey.enableRelatedVideo, defaultValue: true);
if (userInfo == null ||
localCache.get(LocalCacheKey.historyPause) == true) {
enableHeart = false;
Expand Down
5 changes: 4 additions & 1 deletion lib/pages/video/detail/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,10 @@ class _VideoDetailPageState extends State<VideoDetailPage>
.withOpacity(0.06),
),
),
const RelatedVideoPanel(),
if (videoDetailController.videoType ==
SearchType.video &&
videoDetailController.enableRelatedVideo)
const RelatedVideoPanel(),
],
);
},
Expand Down
1 change: 0 additions & 1 deletion lib/pages/video/detail/widgets/header_control.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class HeaderControl extends StatefulWidget implements PreferredSizeWidget {

class _HeaderControlState extends State<HeaderControl> {
late PlayUrlModel videoInfo;
List<PlaySpeed> playSpeed = PlaySpeed.values;
static const TextStyle subTitleStyle = TextStyle(fontSize: 12);
static const TextStyle titleStyle = TextStyle(fontSize: 14);
Size get preferredSize => const Size(double.infinity, kToolbarHeight);
Expand Down
26 changes: 11 additions & 15 deletions lib/plugin/pl_player/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,19 @@ class PlPlayerController {
_longPressSpeed.value = videoStorage
.get(VideoBoxKey.longPressSpeedDefault, defaultValue: 2.0);
}
// 自定义倍速集合
speedsList = List<double>.from(videoStorage
.get(VideoBoxKey.customSpeedsList, defaultValue: <double>[]));
for (final PlaySpeed i in PlaySpeed.values) {
speedsList.add(i.value);
}
// 默认倍速
speedsList = List<double>.from(videoStorage
.get(VideoBoxKey.customSpeedsList, defaultValue: <double>[]));
//playSpeedSystem
final List<double> playSpeedSystem =
videoStorage.get(VideoBoxKey.playSpeedSystem, defaultValue: playSpeed);

// for (final PlaySpeed i in PlaySpeed.values) {
speedsList.addAll(playSpeedSystem);
// }

// _playerEventSubs = onPlayerStatusChanged.listen((PlayerStatus status) {
// if (status == PlayerStatus.playing) {
Expand Down Expand Up @@ -676,18 +684,6 @@ class PlPlayerController {
_playbackSpeed.value = speed;
}

/// 设置倍速
// Future<void> togglePlaybackSpeed() async {
// List<double> allowedSpeeds =
// PlaySpeed.values.map<double>((e) => e.value).toList();
// int index = allowedSpeeds.indexOf(_playbackSpeed.value);
// if (index < allowedSpeeds.length - 1) {
// setPlaybackSpeed(allowedSpeeds[index + 1]);
// } else {
// setPlaybackSpeed(allowedSpeeds[0]);
// }
// }

/// 播放视频
/// TODO _duration.value丢失
Future<void> play(
Expand Down
46 changes: 11 additions & 35 deletions lib/plugin/pl_player/models/play_speed.dart
Original file line number Diff line number Diff line change
@@ -1,39 +1,15 @@
enum PlaySpeed {
pointTwoFive,
pointFive,
pointSevenFive,
List<double> generatePlaySpeedList() {
List<double> playSpeed = [];
double startSpeed = 0.25;
double endSpeed = 2.0;
double increment = 0.25;

one,
onePointTwoFive,
onePointFive,
onePointSevenFive,
for (double speed = startSpeed; speed <= endSpeed; speed += increment) {
playSpeed.add(speed);
}

two,
return playSpeed;
}

extension PlaySpeedExtension on PlaySpeed {
static final List<String> _descList = [
'0.25',
'0.5',
'0.75',
'正常',
'1.25',
'1.5',
'1.75',
'2.0',
];
String get description => _descList[index];

static final List<double> _valueList = [
0.25,
0.5,
0.75,
1.0,
1.25,
1.5,
1.75,
2.0,
];
double get value => _valueList[index];
double get defaultValue => _valueList[3];
}
// 导出 playSpeed 列表
List<double> playSpeed = generatePlaySpeedList();
5 changes: 4 additions & 1 deletion lib/utils/storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ class SettingBoxKey {
enableSearchWord = 'enableSearchWord',
enableSystemProxy = 'enableSystemProxy',
enableAi = 'enableAi',
defaultHomePage = 'defaultHomePage';
defaultHomePage = 'defaultHomePage',
enableRelatedVideo = 'enableRelatedVideo';

/// 外观
static const String themeMode = 'themeMode',
Expand Down Expand Up @@ -181,6 +182,8 @@ class VideoBoxKey {
videoSpeed = 'videoSpeed',
// 播放顺序
playRepeat = 'playRepeat',
// 系统预设倍速
playSpeedSystem = 'playSpeedSystem',
// 默认倍速
playSpeedDefault = 'playSpeedDefault',
// 默认长按倍速
Expand Down

0 comments on commit a5558de

Please sign in to comment.