Merge branch 'main' into design

This commit is contained in:
guozhigq
2024-12-08 14:45:12 +08:00
11 changed files with 500 additions and 345 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;
@ -337,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或番剧分集
@ -568,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

@ -18,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';
@ -458,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 ? '保存至默认分组' : '保存'),
),
],
),
),
],
);
}
}