feat: custom show related video

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2024-12-23 17:12:43 +08:00
parent c8e89653ed
commit 812170ce38
6 changed files with 49 additions and 19 deletions

View File

@@ -64,6 +64,7 @@ class _MediaPageState extends State<MediaPage>
toolbarHeight: 30,
),
body: SingleChildScrollView(
physics: const AlwaysScrollableScrollPhysics(),
controller: mediaController.scrollController,
child: Column(
children: [
@@ -183,6 +184,9 @@ class _MediaPageState extends State<MediaPage>
height: MediaQuery.textScalerOf(context).scale(200),
child: Obx(() => _buildBody(mediaController.loadingState.value)),
),
SizedBox(
height: MediaQuery.paddingOf(context).bottom + 100,
)
],
);
}

View File

@@ -223,6 +223,12 @@ class _ExtraSettingState extends State<ExtraSetting> {
setKey: SettingBoxKey.showViewPoints,
defaultVal: true,
),
SetSwitchItem(
title: '视频页显示相关视频',
leading: Icon(Icons.recommend_outlined),
setKey: SettingBoxKey.showRelatedVideo,
defaultVal: true,
),
Obx(
() => ListTile(
enableFeedback: true,

View File

@@ -216,6 +216,8 @@ class VideoDetailController extends GetxController
late String cacheSecondDecode;
late int cacheAudioQa;
late final showRelatedVideo = GStorage.showRelatedVideo;
late final bool enableSponsorBlock;
PlayerStatus? playerStatus;
StreamSubscription<Duration>? positionSubscription;
@@ -236,6 +238,8 @@ class VideoDetailController extends GetxController
RxString sourceType = 'normal'.obs;
List<MediaVideoItemModel> mediaList = <MediaVideoItemModel>[];
RxString watchLaterTitle = ''.obs;
bool get isPlayAll =>
sourceType.value == 'watchLater' || sourceType.value == 'fav';
@override
void onInit() {
@@ -366,9 +370,11 @@ class VideoDetailController extends GetxController
..bvid = bvid
..queryVideoIntro();
Get.find<RelatedController>(tag: heroTag)
..bvid = bvid
..onRefresh();
if (showRelatedVideo) {
Get.find<RelatedController>(tag: heroTag)
..bvid = bvid
..onRefresh();
}
} catch (_) {}
}

View File

@@ -550,12 +550,13 @@ class VideoIntroController extends GetxController
videoDetailCtr.danmakuCid.value = cid;
videoDetailCtr.queryVideoUrl();
// 重新请求相关视频
try {
final RelatedController relatedCtr =
Get.find<RelatedController>(tag: heroTag);
relatedCtr.bvid = bvid;
relatedCtr.queryData();
} catch (_) {}
if (videoDetailCtr.showRelatedVideo) {
try {
Get.find<RelatedController>(tag: heroTag)
..bvid = bvid
..queryData();
} catch (_) {}
}
// 重新请求评论
try {
final VideoReplyController videoReplyCtr =
@@ -652,8 +653,7 @@ class VideoIntroController extends GetxController
final VideoDetailController videoDetailCtr =
Get.find<VideoDetailController>(tag: heroTag);
if (videoDetailController.sourceType.value == 'watchLater' ||
videoDetailController.sourceType.value == 'fav') {
if (videoDetailController.isPlayAll) {
episodes.addAll(videoDetailCtr.mediaList);
} else if ((videoDetail.value.pages?.length ?? 0) > 1) {
isPages = true;
@@ -671,7 +671,8 @@ class VideoIntroController extends GetxController
final PlayRepeat platRepeat = videoDetailCtr.plPlayerController.playRepeat;
if (episodes.isEmpty) {
if (platRepeat == PlayRepeat.autoPlayRelated) {
if (platRepeat == PlayRepeat.autoPlayRelated &&
videoDetailCtr.showRelatedVideo) {
return playRelated();
}
return false;
@@ -692,7 +693,8 @@ class VideoIntroController extends GetxController
if (nextIndex >= episodes.length) {
if (platRepeat == PlayRepeat.listCycle) {
nextIndex = 0;
} else if (platRepeat == PlayRepeat.autoPlayRelated) {
} else if (platRepeat == PlayRepeat.autoPlayRelated &&
videoDetailCtr.showRelatedVideo) {
return playRelated();
} else {
return false;

View File

@@ -795,7 +795,8 @@ class _VideoDetailPageState extends State<VideoDetailPage>
SearchType.media_bangumi,
'相关视频',
videoDetailController.videoType ==
SearchType.media_bangumi,
SearchType.media_bangumi ||
videoDetailController.showRelatedVideo.not,
),
Expanded(
child: TabBarView(
@@ -803,7 +804,8 @@ class _VideoDetailPageState extends State<VideoDetailPage>
controller: videoDetailController.tabCtr,
children: <Widget>[
if (videoDetailController.videoType ==
SearchType.video)
SearchType.video &&
videoDetailController.showRelatedVideo)
CustomScrollView(
controller: _introController,
slivers: [
@@ -1296,7 +1298,7 @@ class _VideoDetailPageState extends State<VideoDetailPage>
showIntroDetail: showIntroDetail,
showEpisodes: showEpisodes,
),
if (needRelated) ...[
if (needRelated && videoDetailController.showRelatedVideo) ...[
SliverToBoxAdapter(
child: Padding(
padding: const EdgeInsets.only(
@@ -1323,12 +1325,18 @@ class _VideoDetailPageState extends State<VideoDetailPage>
),
),
SliverToBoxAdapter(
child: SizedBox(height: MediaQuery.paddingOf(context).bottom),
child: SizedBox(
height: MediaQuery.paddingOf(context).bottom +
(videoDetailController.isPlayAll &&
MediaQuery.orientationOf(context) ==
Orientation.landscape
? 75
: 0),
),
)
],
);
if (videoDetailController.sourceType.value == 'watchLater' ||
videoDetailController.sourceType.value == 'fav') {
if (videoDetailController.isPlayAll) {
return Stack(
children: [
introPanel(),

View File

@@ -113,6 +113,9 @@ class GStorage {
static bool get showViewPoints =>
setting.get(SettingBoxKey.showViewPoints, defaultValue: true);
static bool get showRelatedVideo =>
setting.get(SettingBoxKey.showRelatedVideo, defaultValue: true);
static List<double> get dynamicDetailRatio =>
setting.get(SettingBoxKey.dynamicDetailRatio, defaultValue: [60.0, 40.0]);
@@ -306,6 +309,7 @@ class SettingBoxKey {
schemeVariant = 'schemeVariant',
grpcReply = 'grpcReply',
showViewPoints = 'showViewPoints',
showRelatedVideo = 'showRelatedVideo',
// Sponsor Block
enableSponsorBlock = 'enableSponsorBlock',