refa: vertical video page (#328)

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
dom
2025-02-26 17:21:24 +08:00
committed by GitHub
parent 41f251ad50
commit 8434c488da
30 changed files with 2534 additions and 224 deletions

View File

@@ -27,6 +27,7 @@ import 'package:PiliPlus/utils/extension.dart';
import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:dio/dio.dart';
import 'package:easy_debounce/easy_throttle.dart';
import 'package:extended_nested_scroll_view/extended_nested_scroll_view.dart';
import 'package:floating/floating.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
@@ -126,6 +127,9 @@ class VideoDetailController extends GetxController
PlayerStatus? playerStatus;
StreamSubscription<Duration>? positionSubscription;
late final scrollKey = GlobalKey<ExtendedNestedScrollViewState>();
late final RxString direction = 'horizontal'.obs;
bool imageStatus = false;
void onViewImage() {
@@ -1082,6 +1086,11 @@ class VideoDetailController extends GetxController
baseUrl: videoUrl,
codecs: 'avc1',
quality: VideoQualityCode.fromCode(data.quality!)!);
direction.value = firstVideo.width != null && firstVideo.height != null
? firstVideo.width! > firstVideo.height!
? 'horizontal'
: 'vertical'
: 'horizontal';
currentDecodeFormats = VideoDecodeFormatsCode.fromString('avc1')!;
currentVideoQa = VideoQualityCode.fromCode(data.quality!)!;
if (autoPlay.value) {
@@ -1152,6 +1161,11 @@ class VideoDetailController extends GetxController
firstVideo = videosList.firstWhere(
(e) => e.codecs!.startsWith(currentDecodeFormats.code),
orElse: () => videosList.first);
direction.value = firstVideo.width != null && firstVideo.height != null
? firstVideo.width! > firstVideo.height!
? 'horizontal'
: 'vertical'
: 'horizontal';
// videoUrl = enableCDN
// ? VideoUtils.getCdnUrl(firstVideo)

View File

@@ -821,13 +821,6 @@ class VideoIntroController extends GetxController
(relatedCtr.loadingState.value as Success).response[0];
try {
if (videoItem.cid != null) {
// Get.offNamed(
// '/video?bvid=${videoItem.bvid}&cid=${videoItem.cid}',
// arguments: {
// 'videoItem': videoItem,
// 'heroTag': heroTag,
// },
// );
changeSeasonOrbangu(
null,
videoItem.bvid,
@@ -837,12 +830,14 @@ class VideoIntroController extends GetxController
);
} else {
SearchHttp.ab2c(aid: videoItem.aid, bvid: videoItem.bvid).then(
(cid) => Get.offNamed(
'/video?bvid=${videoItem.bvid}&cid=${videoItem.cid}',
arguments: {
'videoItem': videoItem,
'heroTag': heroTag,
}),
(cid) => Utils.toViewPage(
'bvid=${videoItem.bvid}&cid=${videoItem.cid}',
arguments: {
'videoItem': videoItem,
'heroTag': heroTag,
},
off: true,
),
);
}
} catch (err) {

View File

@@ -305,8 +305,9 @@ class _VideoInfoState extends State<VideoInfo> with TickerProviderStateMixin {
final ThemeData t = Theme.of(context);
return SliverLayoutBuilder(
builder: (BuildContext context, SliverConstraints constraints) {
bool isHorizontal = constraints.crossAxisExtent >
constraints.viewportMainAxisExtent * 1.25;
// bool isHorizontal = constraints.crossAxisExtent >
// constraints.viewportMainAxisExtent * 1.25;
bool isHorizontal = context.orientation == Orientation.landscape;
return SliverPadding(
padding: const EdgeInsets.only(
left: StyleString.safeSpace,

View File

@@ -6,8 +6,11 @@ import 'package:PiliPlus/http/reply.dart';
import 'package:PiliPlus/utils/global_data.dart';
import 'package:PiliPlus/utils/id_utils.dart';
import 'package:fixnum/fixnum.dart' as $fixnum;
import 'package:flutter/material.dart';
import 'package:get/get_state_manager/src/rx_flutter/rx_ticket_provider_mixin.dart';
class VideoReplyController extends ReplyController {
class VideoReplyController extends ReplyController
with GetTickerProviderStateMixin {
VideoReplyController({required this.aid});
// 视频aid 请求时使用的oid
int aid;
@@ -15,6 +18,25 @@ class VideoReplyController extends ReplyController {
@override
dynamic get sourceId => IdUtils.av2bv(aid);
bool _isFabVisible = true;
late final AnimationController fabAnimationCtr = AnimationController(
vsync: this, duration: const Duration(milliseconds: 100))
..forward();
void showFab() {
if (!_isFabVisible) {
_isFabVisible = true;
fabAnimationCtr.forward();
}
}
void hideFab() {
if (_isFabVisible) {
_isFabVisible = false;
fabAnimationCtr.reverse();
}
}
@override
Future<LoadingState> customGetData() => GlobalData().grpcReply
? ReplyHttp.replyListGrpc(
@@ -34,4 +56,10 @@ class VideoReplyController extends ReplyController {
page: currentPage,
antiGoodsReply: antiGoodsReply,
);
@override
void onClose() {
fabAnimationCtr.dispose();
super.onClose();
}
}

View File

@@ -26,6 +26,7 @@ class VideoReplyPanel extends StatefulWidget {
final VoidCallback? onViewImage;
final ValueChanged<int>? onDismissed;
final Function(List<String>, int)? callback;
final bool? needController;
const VideoReplyPanel({
super.key,
@@ -38,6 +39,7 @@ class VideoReplyPanel extends StatefulWidget {
this.onViewImage,
this.onDismissed,
this.callback,
this.needController,
});
@override
@@ -47,9 +49,7 @@ class VideoReplyPanel extends StatefulWidget {
class _VideoReplyPanelState extends State<VideoReplyPanel>
with AutomaticKeepAliveClientMixin, TickerProviderStateMixin {
late VideoReplyController _videoReplyController;
late AnimationController fabAnimationCtr;
bool _isFabVisible = true;
String replyLevel = '1';
late String heroTag;
@@ -66,52 +66,33 @@ class _VideoReplyPanelState extends State<VideoReplyPanel>
replyLevel = widget.replyLevel ?? '1';
_videoReplyController = Get.find<VideoReplyController>(tag: heroTag);
fabAnimationCtr = AnimationController(
vsync: this, duration: const Duration(milliseconds: 100));
fabAnimationCtr.forward();
scrollListener();
if (widget.needController != false) {
_videoReplyController.scrollController.addListener(listener);
}
}
@override
void dispose() {
_videoReplyController.scrollController.removeListener(listener);
fabAnimationCtr.dispose();
if (widget.needController != false) {
_videoReplyController.scrollController.removeListener(listener);
}
super.dispose();
}
void scrollListener() {
_videoReplyController.scrollController.addListener(listener);
}
void listener() {
final ScrollDirection direction =
_videoReplyController.scrollController.position.userScrollDirection;
if (direction == ScrollDirection.forward) {
if (mounted) {
_showFab();
_videoReplyController.showFab();
}
} else if (direction == ScrollDirection.reverse) {
if (mounted) {
_hideFab();
_videoReplyController.hideFab();
}
}
}
void _showFab() {
if (!_isFabVisible) {
_isFabVisible = true;
fabAnimationCtr.forward();
}
}
void _hideFab() {
if (_isFabVisible) {
_isFabVisible = false;
fabAnimationCtr.reverse();
}
}
@override
Widget build(BuildContext context) {
super.build(context);
@@ -122,8 +103,14 @@ class _VideoReplyPanelState extends State<VideoReplyPanel>
child: Stack(
children: [
CustomScrollView(
controller: _videoReplyController.scrollController,
physics: const AlwaysScrollableScrollPhysics(),
controller: widget.needController == false
? null
: _videoReplyController.scrollController,
physics: widget.needController == false
? const NeverScrollableScrollPhysics(
parent: ClampingScrollPhysics(),
)
: const AlwaysScrollableScrollPhysics(),
// key: const PageStorageKey<String>('评论'),
slivers: <Widget>[
SliverPersistentHeader(
@@ -182,7 +169,7 @@ class _VideoReplyPanelState extends State<VideoReplyPanel>
begin: const Offset(0, 2),
end: const Offset(0, 0),
).animate(CurvedAnimation(
parent: fabAnimationCtr,
parent: _videoReplyController.fabAnimationCtr,
curve: Curves.easeInOut,
)),
child: FloatingActionButton(

File diff suppressed because it is too large Load Diff