feat: season fav
This commit is contained in:
@ -3,7 +3,9 @@ import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
|||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:pilipala/common/constants.dart';
|
import 'package:pilipala/common/constants.dart';
|
||||||
import 'package:pilipala/common/widgets/network_img_layer.dart';
|
import 'package:pilipala/common/widgets/network_img_layer.dart';
|
||||||
|
import 'package:pilipala/http/video.dart';
|
||||||
import 'package:pilipala/models/video_detail_res.dart';
|
import 'package:pilipala/models/video_detail_res.dart';
|
||||||
|
import 'package:pilipala/pages/video/detail/index.dart';
|
||||||
import 'package:pilipala/utils/utils.dart';
|
import 'package:pilipala/utils/utils.dart';
|
||||||
import 'package:scrollview_observer/scrollview_observer.dart';
|
import 'package:scrollview_observer/scrollview_observer.dart';
|
||||||
import '../models/common/video_episode_type.dart';
|
import '../models/common/video_episode_type.dart';
|
||||||
@ -101,6 +103,9 @@ class _PagesBottomSheetState extends State<PagesBottomSheet>
|
|||||||
TabController? tabController;
|
TabController? tabController;
|
||||||
List<ListObserverController>? _listObserverControllerList;
|
List<ListObserverController>? _listObserverControllerList;
|
||||||
List<ScrollController>? _listScrollControllerList;
|
List<ScrollController>? _listScrollControllerList;
|
||||||
|
final String heroTag = Get.arguments['heroTag'];
|
||||||
|
VideoDetailController? _videoDetailController;
|
||||||
|
late RxInt isSubscribe = (-1).obs;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@ -109,6 +114,10 @@ class _PagesBottomSheetState extends State<PagesBottomSheet>
|
|||||||
widget.episodes.indexWhere((dynamic e) => e.cid == widget.currentCid);
|
widget.episodes.indexWhere((dynamic e) => e.cid == widget.currentCid);
|
||||||
_scrollToInit();
|
_scrollToInit();
|
||||||
_scrollPositionInit();
|
_scrollPositionInit();
|
||||||
|
if (widget.dataType == VideoEpidoesType.videoEpisode) {
|
||||||
|
_videoDetailController = Get.find<VideoDetailController>(tag: heroTag);
|
||||||
|
_getSubscribeStatus();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String prefix() {
|
String prefix() {
|
||||||
@ -189,6 +198,32 @@ class _PagesBottomSheetState extends State<PagesBottomSheet>
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取订阅状态
|
||||||
|
void _getSubscribeStatus() async {
|
||||||
|
var res =
|
||||||
|
await VideoHttp.getSubscribeStatus(bvid: _videoDetailController!.bvid);
|
||||||
|
if (res['status']) {
|
||||||
|
isSubscribe.value = res['data']['season_fav'] ? 1 : 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更改订阅状态
|
||||||
|
void _changeSubscribeStatus() async {
|
||||||
|
if (isSubscribe.value == -1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
dynamic result = await VideoHttp.seasonFav(
|
||||||
|
isFav: isSubscribe.value == 1,
|
||||||
|
seasonId: widget.ugcSeason!.id,
|
||||||
|
);
|
||||||
|
if (result['status']) {
|
||||||
|
SmartDialog.showToast(isSubscribe.value == 1 ? '取消订阅成功' : '订阅成功');
|
||||||
|
isSubscribe.value = isSubscribe.value == 1 ? 0 : 1;
|
||||||
|
} else {
|
||||||
|
SmartDialog.showToast(result['msg']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
try {
|
try {
|
||||||
@ -217,7 +252,11 @@ class _PagesBottomSheetState extends State<PagesBottomSheet>
|
|||||||
isFullScreen: widget.isFullScreen,
|
isFullScreen: widget.isFullScreen,
|
||||||
),
|
),
|
||||||
if (widget.ugcSeason != null) ...[
|
if (widget.ugcSeason != null) ...[
|
||||||
UgcSeasonBuild(ugcSeason: widget.ugcSeason!),
|
UgcSeasonBuild(
|
||||||
|
ugcSeason: widget.ugcSeason!,
|
||||||
|
isSubscribe: isSubscribe,
|
||||||
|
changeFucCall: _changeSubscribeStatus,
|
||||||
|
),
|
||||||
],
|
],
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Material(
|
child: Material(
|
||||||
@ -638,14 +677,20 @@ class EpisodeGridItem extends StatelessWidget {
|
|||||||
|
|
||||||
class UgcSeasonBuild extends StatelessWidget {
|
class UgcSeasonBuild extends StatelessWidget {
|
||||||
final UgcSeason ugcSeason;
|
final UgcSeason ugcSeason;
|
||||||
|
final RxInt isSubscribe;
|
||||||
|
final Function changeFucCall;
|
||||||
|
|
||||||
const UgcSeasonBuild({
|
const UgcSeasonBuild({
|
||||||
Key? key,
|
Key? key,
|
||||||
required this.ugcSeason,
|
required this.ugcSeason,
|
||||||
|
required this.isSubscribe,
|
||||||
|
required this.changeFucCall,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
final ThemeData t = Theme.of(context);
|
||||||
|
final Color outline = t.colorScheme.outline;
|
||||||
return Container(
|
return Container(
|
||||||
padding: const EdgeInsets.fromLTRB(12, 0, 12, 0),
|
padding: const EdgeInsets.fromLTRB(12, 0, 12, 0),
|
||||||
color: Theme.of(context).colorScheme.surface,
|
color: Theme.of(context).colorScheme.surface,
|
||||||
@ -673,17 +718,30 @@ class UgcSeasonBuild extends StatelessWidget {
|
|||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: Theme.of(context).colorScheme.outline)),
|
color: Theme.of(context).colorScheme.outline)),
|
||||||
),
|
),
|
||||||
// SizedBox(
|
Obx(
|
||||||
// height: 32,
|
() => isSubscribe.value == -1
|
||||||
// child: FilledButton.tonal(
|
? const SizedBox(height: 32)
|
||||||
// onPressed: () {},
|
: SizedBox(
|
||||||
// style: ButtonStyle(
|
height: 32,
|
||||||
// padding: MaterialStateProperty.all(EdgeInsets.zero),
|
child: FilledButton.tonal(
|
||||||
// ),
|
onPressed: () => changeFucCall.call(),
|
||||||
// child: const Text('订阅'),
|
style: TextButton.styleFrom(
|
||||||
// ),
|
padding: const EdgeInsets.only(
|
||||||
// ),
|
left: 8,
|
||||||
// const SizedBox(width: 6),
|
right: 8,
|
||||||
|
),
|
||||||
|
foregroundColor: isSubscribe.value == 1
|
||||||
|
? outline
|
||||||
|
: t.colorScheme.onPrimary,
|
||||||
|
backgroundColor: isSubscribe.value == 1
|
||||||
|
? t.colorScheme.onInverseSurface
|
||||||
|
: t.colorScheme.primary, // 设置按钮背景色
|
||||||
|
),
|
||||||
|
child: Text(isSubscribe.value == 1 ? '已订阅' : '订阅'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 6),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
@ -609,4 +609,10 @@ class Api {
|
|||||||
|
|
||||||
/// @我的
|
/// @我的
|
||||||
static const String messageAtAPi = '/x/msgfeed/at?';
|
static const String messageAtAPi = '/x/msgfeed/at?';
|
||||||
|
|
||||||
|
/// 订阅
|
||||||
|
static const String confirmSub = '/x/v3/fav/season/fav';
|
||||||
|
|
||||||
|
/// 订阅状态
|
||||||
|
static const String videoRelation = '/x/web-interface/archive/relation';
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ import 'dart:convert';
|
|||||||
import 'dart:developer';
|
import 'dart:developer';
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive/hive.dart';
|
||||||
|
import 'package:pilipala/utils/id_utils.dart';
|
||||||
import '../common/constants.dart';
|
import '../common/constants.dart';
|
||||||
import '../models/common/reply_type.dart';
|
import '../models/common/reply_type.dart';
|
||||||
import '../models/home/rcmd/result.dart';
|
import '../models/home/rcmd/result.dart';
|
||||||
@ -560,4 +561,50 @@ class VideoHttp {
|
|||||||
final List body = res.data['body'];
|
final List body = res.data['body'];
|
||||||
return {'content': content, 'body': body};
|
return {'content': content, 'body': body};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Future<Map<String, dynamic>> getSubscribeStatus(
|
||||||
|
{required dynamic bvid}) async {
|
||||||
|
var res = await Request().get(
|
||||||
|
Api.videoRelation,
|
||||||
|
data: {
|
||||||
|
'aid': IdUtils.bv2av(bvid),
|
||||||
|
'bvid': bvid,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
if (res.data['code'] == 0) {
|
||||||
|
return {
|
||||||
|
'status': true,
|
||||||
|
'data': res.data['data'],
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
'status': false,
|
||||||
|
'msg': res.data['message'],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future seasonFav({
|
||||||
|
required bool isFav,
|
||||||
|
required dynamic seasonId,
|
||||||
|
}) async {
|
||||||
|
var res = await Request().post(
|
||||||
|
isFav ? Api.cancelSub : Api.confirmSub,
|
||||||
|
data: {
|
||||||
|
'platform': 'web',
|
||||||
|
'season_id': seasonId,
|
||||||
|
'csrf': await Request.getCsrf(),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
if (res.data['code'] == 0) {
|
||||||
|
return {
|
||||||
|
'status': true,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
'status': false,
|
||||||
|
'msg': res.data['message'],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user