Merge branch 'main' into opt-videoPlayerControl

This commit is contained in:
guozhigq
2024-12-08 18:17:15 +08:00
25 changed files with 735 additions and 482 deletions

View File

@ -17,6 +17,7 @@ import 'package:pilipala/pages/video/detail/controller.dart';
import 'package:pilipala/pages/video/detail/reply/index.dart';
import 'package:pilipala/plugin/pl_player/models/play_repeat.dart';
import 'package:pilipala/utils/feed_back.dart';
import 'package:pilipala/utils/follow.dart';
import 'package:pilipala/utils/global_data_cache.dart';
import 'package:pilipala/utils/id_utils.dart';
import 'package:pilipala/utils/storage.dart';
@ -26,7 +27,6 @@ import '../../../../common/pages_bottom_sheet.dart';
import '../../../../models/common/video_episode_type.dart';
import '../../../../utils/drawer.dart';
import '../related/index.dart';
import 'widgets/group_panel.dart';
class VideoIntroController extends GetxController {
VideoIntroController({required this.bvid});
@ -50,7 +50,7 @@ class VideoIntroController extends GetxController {
List addMediaIdsNew = [];
List delMediaIdsNew = [];
// 关注状态 默认未关注
RxMap followStatus = {}.obs;
RxInt followStatus = (-1).obs;
RxInt lastPlayCid = 0.obs;
UserInfoData? userInfo;
RxList<VideoTagItem> videoTags = <VideoTagItem>[].obs;
@ -66,6 +66,8 @@ class VideoIntroController extends GetxController {
late bool enableRelatedVideo;
UgcSeason? ugcSeason;
RxList<Part> pages = <Part>[].obs;
// 默认原创视频
int copyright = 1;
@override
void onInit() {
@ -94,6 +96,7 @@ class VideoIntroController extends GetxController {
videoDetail.value = result['data']!;
ugcSeason = result['data']!.ugcSeason;
pages.value = result['data']!.pages!;
copyright = result['data']!.copyright!;
if (type == null) {
lastPlayCid.value = cid ?? videoDetail.value.cid!;
}
@ -215,7 +218,7 @@ class VideoIntroController extends GetxController {
contentPadding: const EdgeInsets.fromLTRB(0, 12, 0, 24),
content: Column(
mainAxisSize: MainAxisSize.min,
children: [1, 2]
children: (copyright == 2 ? [1] : [1, 2])
.map(
(e) => ListTile(
title: Padding(
@ -334,113 +337,23 @@ class VideoIntroController extends GetxController {
}
var result = await VideoHttp.hasFollow(mid: videoDetail.value.owner!.mid!);
if (result['status']) {
followStatus.value = result['data'];
followStatus.value = result['data']['attribute'];
}
return result;
}
// 关注/取关up
Future actionRelationMod() async {
Future actionRelationMod(BuildContext context) async {
feedBack();
if (userInfo == null) {
SmartDialog.showToast('账号未登录');
return;
}
final int currentStatus = followStatus['attribute'];
if (currentStatus == 128) {
modifyRelation('block', currentStatus);
} else {
modifyRelation('follow', currentStatus);
}
}
// 操作用户关系
Future modifyRelation(String actionType, int currentStatus) async {
final int mid = videoDetail.value.owner!.mid!;
String contentText;
int act;
if (actionType == 'follow') {
contentText = currentStatus != 0 ? '确定取消关注UP主?' : '确定关注UP主?';
act = currentStatus != 0 ? 2 : 1;
} else if (actionType == 'block') {
contentText = '确定从黑名单移除UP主?';
act = 6;
} else {
return;
}
showDialog(
context: Get.context!,
builder: (BuildContext context) {
final Color outline = Theme.of(Get.context!).colorScheme.outline;
return AlertDialog(
title: const Text('提示'),
content: Text(contentText),
actions: [
TextButton(
onPressed: Navigator.of(context).pop,
child: Text('点错了', style: TextStyle(color: outline)),
),
TextButton(
onPressed: () => modifyRelationFetch(
context,
mid,
act,
currentStatus,
actionType,
),
child: const Text('确定'),
)
],
);
},
);
}
// 操作用户关系Future
Future modifyRelationFetch(
BuildContext context,
mid,
act,
currentStatus,
actionType,
) async {
var res = await VideoHttp.relationMod(mid: mid, act: act, reSrc: 11);
if (context.mounted) {
Navigator.of(context).pop();
}
if (res['status']) {
if (actionType == 'follow') {
final Map<int, int> statusMap = {
0: 2,
2: 0,
};
late int actionStatus;
actionStatus = statusMap[currentStatus] ?? 0;
followStatus['attribute'] = actionStatus;
if (currentStatus == 0 && Get.context!.mounted) {
ScaffoldMessenger.of(Get.context!).showSnackBar(
SnackBar(
content: const Text('关注成功'),
duration: const Duration(seconds: 2),
action: SnackBarAction(
label: '设置分组',
onPressed: setFollowGroup,
),
showCloseIcon: true,
),
);
} else {
SmartDialog.showToast('取消关注成功');
}
} else if (actionType == 'block') {
followStatus['attribute'] = 0;
SmartDialog.showToast('取消拉黑成功');
}
followStatus.refresh();
} else {
SmartDialog.showToast(res['msg']);
}
followStatus.value = await FollowUtils(
context: context,
followStatus: followStatus.value,
mid: videoDetail.value.owner!.mid!,
).showFollowSheet();
}
// 修改分P或番剧分集
@ -565,33 +478,33 @@ class VideoIntroController extends GetxController {
}
// 设置关注分组
void setFollowGroup() async {
final mediaQueryData = MediaQuery.of(Get.context!);
final contentHeight = mediaQueryData.size.height - kToolbarHeight;
final double initialChildSize =
(contentHeight - Get.width * 9 / 16) / contentHeight;
await showModalBottomSheet(
context: Get.context!,
useSafeArea: true,
isScrollControlled: true,
builder: (BuildContext context) {
return DraggableScrollableSheet(
initialChildSize: initialChildSize,
minChildSize: 0,
maxChildSize: 1,
snap: true,
expand: false,
snapSizes: [initialChildSize],
builder: (BuildContext context, ScrollController scrollController) {
return GroupPanel(
mid: videoDetail.value.owner!.mid!,
scrollController: scrollController,
);
},
);
},
);
}
// void setFollowGroup() async {
// final mediaQueryData = MediaQuery.of(Get.context!);
// final contentHeight = mediaQueryData.size.height - kToolbarHeight;
// final double initialChildSize =
// (contentHeight - Get.width * 9 / 16) / contentHeight;
// await showModalBottomSheet(
// context: Get.context!,
// useSafeArea: true,
// isScrollControlled: true,
// builder: (BuildContext context) {
// return DraggableScrollableSheet(
// initialChildSize: initialChildSize,
// minChildSize: 0,
// maxChildSize: 1,
// snap: true,
// expand: false,
// snapSizes: [initialChildSize],
// builder: (BuildContext context, ScrollController scrollController) {
// return GroupPanel(
// mid: videoDetail.value.owner!.mid!,
// scrollController: scrollController,
// );
// },
// );
// },
// );
// }
// ai总结
Future aiConclusion() async {

View File

@ -8,6 +8,7 @@ import 'package:flutter/material.dart';
import 'package:hive/hive.dart';
import 'package:pilipala/common/constants.dart';
import 'package:pilipala/common/skeleton/video_intro.dart';
import 'package:pilipala/common/widgets/badge.dart';
import 'package:pilipala/common/widgets/http_error.dart';
import 'package:pilipala/pages/video/detail/index.dart';
import 'package:pilipala/common/widgets/network_img_layer.dart';
@ -17,6 +18,7 @@ import 'package:pilipala/models/video_detail_res.dart';
import 'package:pilipala/pages/video/detail/introduction/controller.dart';
import 'package:pilipala/pages/video/detail/widgets/ai_detail.dart';
import 'package:pilipala/utils/feed_back.dart';
import 'package:pilipala/utils/follow.dart';
import 'package:pilipala/utils/global_data_cache.dart';
import 'package:pilipala/utils/storage.dart';
import 'package:pilipala/utils/utils.dart';
@ -264,6 +266,26 @@ class _VideoInfoState extends State<VideoInfo> with TickerProviderStateMixin {
Widget build(BuildContext context) {
final ThemeData t = Theme.of(context);
final Color outline = t.colorScheme.outline;
const TextStyle titleStyle = TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
);
TextSpan titltWidget = TextSpan(
children: [
WidgetSpan(
child: Visibility(
visible: widget.videoDetail!.copyright == 2,
child: const PBadge(text: '转载', type: 'color'),
),
),
const TextSpan(text: ' '),
TextSpan(
text: widget.videoDetail!.title!,
style: titleStyle,
),
],
);
return SliverPadding(
padding: const EdgeInsets.only(
left: StyleString.safeSpace,
@ -285,25 +307,8 @@ class _VideoInfoState extends State<VideoInfo> with TickerProviderStateMixin {
},
child: ExpandablePanel(
controller: _expandableCtr,
collapsed: Text(
widget.videoDetail!.title!,
softWrap: true,
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
expanded: Text(
widget.videoDetail!.title!,
softWrap: true,
maxLines: 10,
style: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
collapsed: Text.rich(softWrap: true, maxLines: 2, titltWidget),
expanded: Text.rich(softWrap: true, maxLines: 10, titltWidget),
theme: const ExpandableThemeData(
animationDuration: Duration(milliseconds: 300),
scrollAnimationDuration: Duration(milliseconds: 300),
@ -454,14 +459,14 @@ class _VideoInfoState extends State<VideoInfo> with TickerProviderStateMixin {
Obx(
() {
final int attr =
videoIntroController.followStatus['attribute'] ?? 0;
return videoIntroController.followStatus.isEmpty
videoIntroController.followStatus.value;
return attr == -1
? const SizedBox()
: SizedBox(
height: 32,
child: TextButton(
onPressed:
videoIntroController.actionRelationMod,
onPressed: () => videoIntroController
.actionRelationMod(context),
style: TextButton.styleFrom(
padding: const EdgeInsets.only(
left: 8,

View File

@ -1,161 +0,0 @@
import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'package:hive/hive.dart';
import 'package:pilipala/common/widgets/http_error.dart';
import 'package:pilipala/http/member.dart';
import 'package:pilipala/models/member/tags.dart';
import 'package:pilipala/utils/feed_back.dart';
import 'package:pilipala/utils/storage.dart';
class GroupPanel extends StatefulWidget {
final int? mid;
final ScrollController scrollController;
const GroupPanel({super.key, this.mid, required this.scrollController});
@override
State<GroupPanel> createState() => _GroupPanelState();
}
class _GroupPanelState extends State<GroupPanel> {
final Box<dynamic> localCache = GStorage.localCache;
late Future _futureBuilderFuture;
late List<MemberTagItemModel> tagsList;
bool showDefault = true;
@override
void initState() {
super.initState();
_futureBuilderFuture = MemberHttp.followUpTags();
}
void onSave() async {
feedBack();
// 是否有选中的 有选中的带id没选使用默认0
final bool anyHasChecked =
tagsList.any((MemberTagItemModel e) => e.checked == true);
late String tagids;
if (anyHasChecked) {
final List<MemberTagItemModel> checkedList =
tagsList.where((MemberTagItemModel e) => e.checked == true).toList();
final List<int> tagidList =
checkedList.map<int>((e) => e.tagid!).toList();
tagids = tagidList.join(',');
} else {
tagids = '0';
}
// 保存
final res = await MemberHttp.addUsers(widget.mid, tagids);
SmartDialog.showToast(res['msg']);
if (res['status']) {
Get.back();
}
}
@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
AppBar(
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(
top: Radius.circular(20),
),
),
leading: IconButton(
onPressed: () => Get.back(),
icon: const Icon(Icons.close_outlined)),
title: Text('设置关注分组',
style: Theme.of(context)
.textTheme
.titleMedium!
.copyWith(fontWeight: FontWeight.bold)),
),
Expanded(
child: Material(
child: FutureBuilder(
future: _futureBuilderFuture,
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
Map data = snapshot.data as Map;
if (data['status']) {
tagsList = data['data'];
return ListView.builder(
controller: widget.scrollController,
itemCount: data['data'].length,
itemBuilder: (context, index) {
return ListTile(
onTap: () {
data['data'][index].checked =
!data['data'][index].checked;
showDefault =
!data['data'].any((e) => e.checked == true);
setState(() {});
},
dense: true,
leading: const Icon(Icons.group_outlined),
minLeadingWidth: 0,
title: Text(data['data'][index].name),
subtitle: data['data'][index].tip != ''
? Text(data['data'][index].tip)
: null,
trailing: Transform.scale(
scale: 0.9,
child: Checkbox(
value: data['data'][index].checked,
onChanged: (bool? checkValue) {
data['data'][index].checked = checkValue;
showDefault =
!data['data'].any((e) => e.checked == true);
setState(() {});
},
),
),
);
},
);
} else {
return HttpError(
errMsg: data['msg'],
fn: () => setState(() {}),
);
}
} else {
// 骨架屏
return const Center(child: Text('请求中'));
}
},
),
),
),
Divider(
height: 1,
color: Theme.of(context).disabledColor.withOpacity(0.08),
),
Padding(
padding: EdgeInsets.only(
left: 20,
right: 20,
top: 12,
bottom: MediaQuery.of(context).padding.bottom + 12,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
TextButton(
onPressed: () => onSave(),
style: TextButton.styleFrom(
padding: const EdgeInsets.only(left: 30, right: 30),
foregroundColor: Theme.of(context).colorScheme.onPrimary,
backgroundColor:
Theme.of(context).colorScheme.primary, // 设置按钮背景色
),
child: Text(showDefault ? '保存至默认分组' : '保存'),
),
],
),
),
],
);
}
}

View File

@ -1,5 +1,6 @@
import 'dart:async';
import 'dart:io';
import 'dart:math';
import 'package:extended_nested_scroll_view/extended_nested_scroll_view.dart';
import 'package:floating/floating.dart';
@ -76,7 +77,7 @@ class _VideoDetailPageState extends State<VideoDetailPage>
getStatusHeight();
heroTag = Get.arguments['heroTag'];
vdCtr = Get.put(VideoDetailController(), tag: heroTag);
vdCtr.sheetHeight.value = localCache.get('sheetHeight');
vdCtr.sheetHeight.value = GlobalDataCache.sheetHeight;
videoIntroController = Get.put(
VideoIntroController(bvid: Get.parameters['bvid']!),
tag: heroTag);
@ -223,8 +224,8 @@ class _VideoDetailPageState extends State<VideoDetailPage>
void _extendNestCtrListener() {
final double offset = _extendNestCtr.position.pixels;
if (vdCtr.videoDirection.value == 'horizontal') {
vdCtr.sheetHeight.value =
Get.size.height - videoHeight - statusBarHeight + offset;
vdCtr.sheetHeight.value = max(GlobalDataCache.sheetHeight,
Get.size.height - videoHeight - statusBarHeight + offset);
appbarStream.add(offset);
} else {
if (offset > (Get.size.width * 22 / 16 - videoHeight)) {
@ -502,7 +503,7 @@ class _VideoDetailPageState extends State<VideoDetailPage>
@override
Widget build(BuildContext context) {
final sizeContext = MediaQuery.sizeOf(context);
final _context = MediaQuery.of(context);
final orientation = MediaQuery.orientationOf(context);
late final double verticalHeight = sizeContext.width * 22 / 16;
late double defaultVideoHeight = vdCtr.videoDirection.value == 'vertical'
? verticalHeight
@ -517,12 +518,12 @@ class _VideoDetailPageState extends State<VideoDetailPage>
});
// 竖屏
final bool isPortrait = _context.orientation == Orientation.portrait;
final bool isPortrait = orientation == Orientation.portrait;
// 横屏
final bool isLandscape = _context.orientation == Orientation.landscape;
final bool isLandscape = orientation == Orientation.landscape;
final Rx<bool> isFullScreen = plPlayerController?.isFullScreen ?? false.obs;
// 全屏时高度撑满
if (isLandscape || isFullScreen.value == true) {
if (isLandscape || isFullScreen.value) {
videoHeight.value = Get.size.height;
enterFullScreen();
} else {
@ -634,10 +635,8 @@ class _VideoDetailPageState extends State<VideoDetailPage>
}
Widget childWhenDisabled = SafeArea(
top: MediaQuery.of(context).orientation == Orientation.portrait &&
plPlayerController?.isFullScreen.value == true,
bottom: MediaQuery.of(context).orientation == Orientation.portrait &&
plPlayerController?.isFullScreen.value == true,
top: isPortrait && isFullScreen.value,
bottom: isPortrait && isFullScreen.value,
left: false,
right: false,
child: Stack(
@ -660,22 +659,25 @@ class _VideoDetailPageState extends State<VideoDetailPage>
return <Widget>[
Obx(
() {
final Orientation orientation =
MediaQuery.of(context).orientation;
final bool isLandscape =
MediaQuery.orientationOf(context) ==
Orientation.landscape;
final bool isFullScreen =
plPlayerController?.isFullScreen.value == true;
final double expandedHeight =
orientation == Orientation.landscape || isFullScreen
? (MediaQuery.sizeOf(context).height -
(orientation == Orientation.landscape
? 0
: MediaQuery.of(context).padding.top))
: videoHeight.value;
if (orientation == Orientation.landscape ||
isFullScreen) {
plPlayerController?.isFullScreen.value ?? false;
late double expandedHeight;
if (isLandscape || isFullScreen) {
enterFullScreen();
expandedHeight = (MediaQuery.sizeOf(context).height -
(isLandscape
? 0
: MediaQuery.paddingOf(context).top));
} else {
exitFullScreen();
if (vdCtr.videoDirection.value == 'vertical') {
videoHeight.value = verticalHeight;
}
expandedHeight = videoHeight.value;
}
return SliverAppBar(
automaticallyImplyLeading: false,
@ -687,21 +689,24 @@ class _VideoDetailPageState extends State<VideoDetailPage>
backgroundColor: Colors.black,
flexibleSpace: SizedBox.expand(
child: PopScope(
canPop:
plPlayerController?.isFullScreen.value != true,
canPop: !isFullScreen,
onPopInvoked: (bool didPop) {
if (plPlayerController?.controlsLock.value ==
true) {
plPlayerController?.onLockControl(false);
return;
if (plPlayerController != null) {
if (plPlayerController!.controlsLock.value) {
plPlayerController!.onLockControl(false);
return;
}
if (isFullScreen) {
plPlayerController!
.triggerFullScreen(status: false);
if (vdCtr.videoDirection.value ==
'vertical') {
videoHeight.value = verticalHeight;
}
}
}
if (plPlayerController?.isFullScreen.value ==
true) {
plPlayerController!
.triggerFullScreen(status: false);
}
if (MediaQuery.of(context).orientation ==
Orientation.landscape) {
if (isLandscape) {
verticalScreen();
}
},
@ -746,9 +751,7 @@ class _VideoDetailPageState extends State<VideoDetailPage>
/// 不收回
pinnedHeaderSliverHeightBuilder: () {
return MediaQuery.of(context).orientation ==
Orientation.landscape ||
plPlayerController?.isFullScreen.value == true
return isLandscape || isFullScreen.value
? MediaQuery.sizeOf(context).height
: playerStatus.value != PlayerStatus.playing
? kToolbarHeight