mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
refa: query data (#659)
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -1,14 +1,15 @@
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/models/bangumi/list.dart';
|
||||
import 'package:PiliPlus/models/common/tab_type.dart';
|
||||
import 'package:PiliPlus/pages/common/common_controller.dart';
|
||||
import 'package:PiliPlus/pages/common/common_list_controller.dart';
|
||||
import 'package:PiliPlus/utils/extension.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:PiliPlus/http/bangumi.dart';
|
||||
import 'package:PiliPlus/utils/storage.dart';
|
||||
|
||||
class BangumiController extends CommonController {
|
||||
class BangumiController extends CommonListController<
|
||||
List<BangumiListItemModel>?, BangumiListItemModel> {
|
||||
BangumiController({required this.tabType});
|
||||
final TabType tabType;
|
||||
|
||||
@@ -75,7 +76,8 @@ class BangumiController extends CommonController {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<LoadingState> customGetData() => BangumiHttp.bangumiList(
|
||||
Future<LoadingState<List<BangumiListItemModel>?>> customGetData() =>
|
||||
BangumiHttp.bangumiList(
|
||||
page: currentPage,
|
||||
indexType: tabType == TabType.cinema ? 102 : null, // TODO: sort
|
||||
);
|
||||
|
||||
@@ -3,7 +3,7 @@ import 'dart:convert';
|
||||
import 'package:PiliPlus/http/init.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/http/user.dart';
|
||||
import 'package:PiliPlus/pages/common/common_controller.dart';
|
||||
import 'package:PiliPlus/pages/common/common_data_controller.dart';
|
||||
import 'package:PiliPlus/pages/dynamics/repost_dyn_panel.dart';
|
||||
import 'package:PiliPlus/pages/video/detail/introduction/controller.dart';
|
||||
import 'package:PiliPlus/pages/video/detail/introduction/pay_coins_page.dart';
|
||||
@@ -26,7 +26,8 @@ import 'package:PiliPlus/utils/storage.dart';
|
||||
import 'package:html/parser.dart' as html_parser;
|
||||
import 'package:html/dom.dart' as dom;
|
||||
|
||||
class BangumiIntroController extends CommonController {
|
||||
class BangumiIntroController
|
||||
extends CommonDataController<BangumiInfoModel, BangumiInfoModel> {
|
||||
// 视频bvid
|
||||
String bvid = Get.parameters['bvid'] ?? '';
|
||||
var seasonId = Get.parameters['seasonId'] != null
|
||||
@@ -125,14 +126,15 @@ class BangumiIntroController extends CommonController {
|
||||
}
|
||||
|
||||
@override
|
||||
bool customHandleResponse(Success response) {
|
||||
epId ??= response.response.episodes!.first.id;
|
||||
bool customHandleResponse(
|
||||
bool isRefresh, Success<BangumiInfoModel> response) {
|
||||
epId ??= response.response.episodes?.firstOrNull?.id;
|
||||
loadingState.value = response;
|
||||
return true;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<LoadingState> customGetData() =>
|
||||
Future<LoadingState<BangumiInfoModel>> customGetData() =>
|
||||
SearchHttp.bangumiInfoNew(seasonId: seasonId, epId: epId);
|
||||
|
||||
// 获取点赞/投币/收藏状态
|
||||
@@ -147,40 +149,15 @@ class BangumiIntroController extends CommonController {
|
||||
}
|
||||
}
|
||||
|
||||
// 获取点赞状态
|
||||
// Future queryHasLikeVideo() async {
|
||||
// var result = await VideoHttp.hasLikeVideo(bvid: bvid);
|
||||
// // data num 被点赞标志 0:未点赞 1:已点赞
|
||||
// hasLike.value = result["data"] == 1 ? true : false;
|
||||
// }
|
||||
|
||||
// 获取投币状态
|
||||
// Future queryHasCoinVideo() async {
|
||||
// var result = await VideoHttp.hasCoinVideo(bvid: bvid);
|
||||
// hasCoin.value = result["data"]['multiply'] == 0 ? false : true;
|
||||
// }
|
||||
|
||||
// 获取收藏状态
|
||||
// Future queryHasFavVideo() async {
|
||||
// var result = await VideoHttp.hasFavVideo(aid: IdUtils.bv2av(bvid));
|
||||
// if (result['status']) {
|
||||
// hasFav.value = result["data"]['favoured'];
|
||||
// } else {
|
||||
// hasFav.value = false;
|
||||
// }
|
||||
// }
|
||||
|
||||
// (取消)点赞
|
||||
Future actionLikeVideo() async {
|
||||
var result = await VideoHttp.likeVideo(bvid: bvid, type: !hasLike.value);
|
||||
if (result['status']) {
|
||||
SmartDialog.showToast(!hasLike.value ? result['data']['toast'] : '取消赞');
|
||||
hasLike.value = !hasLike.value;
|
||||
dynamic bangumiDetail = (loadingState.value as Success).response;
|
||||
BangumiInfoModel bangumiDetail = (loadingState.value as Success).response;
|
||||
bangumiDetail.stat!['likes'] =
|
||||
bangumiDetail.stat!['likes'] + (!hasLike.value ? 1 : -1);
|
||||
loadingState.value = LoadingState.success(bangumiDetail);
|
||||
hasLike.refresh();
|
||||
hasLike.value = !hasLike.value;
|
||||
} else {
|
||||
SmartDialog.showToast(result['msg']);
|
||||
}
|
||||
@@ -194,14 +171,13 @@ class BangumiIntroController extends CommonController {
|
||||
);
|
||||
if (res['status']) {
|
||||
SmartDialog.showToast('投币成功');
|
||||
hasCoin.value = true;
|
||||
dynamic bangumiDetail = (loadingState.value as Success).response;
|
||||
BangumiInfoModel bangumiDetail = (loadingState.value as Success).response;
|
||||
bangumiDetail.stat!['coins'] = bangumiDetail.stat!['coins'] + coin;
|
||||
if (selectLike && hasLike.value.not) {
|
||||
hasLike.value = true;
|
||||
bangumiDetail.stat!['likes'] = bangumiDetail.stat!['likes'] + 1;
|
||||
}
|
||||
loadingState.value = LoadingState.success(bangumiDetail);
|
||||
hasCoin.value = true;
|
||||
} else {
|
||||
SmartDialog.showToast(res['msg']);
|
||||
}
|
||||
@@ -236,60 +212,6 @@ class BangumiIntroController extends CommonController {
|
||||
},
|
||||
),
|
||||
);
|
||||
// showDialog(
|
||||
// context: Get.context!,
|
||||
// builder: (context) {
|
||||
// return AlertDialog(
|
||||
// title: const Text('选择投币个数'),
|
||||
// contentPadding: const EdgeInsets.fromLTRB(0, 12, 0, 12),
|
||||
// content: StatefulBuilder(builder: (context, StateSetter setState) {
|
||||
// return Column(
|
||||
// mainAxisSize: MainAxisSize.min,
|
||||
// children: [
|
||||
// RadioListTile(
|
||||
// value: 1,
|
||||
// title: const Text('1枚'),
|
||||
// groupValue: _tempThemeValue,
|
||||
// onChanged: (value) {
|
||||
// _tempThemeValue = value!;
|
||||
// Get.appUpdate();
|
||||
// },
|
||||
// ),
|
||||
// RadioListTile(
|
||||
// value: 2,
|
||||
// title: const Text('2枚'),
|
||||
// groupValue: _tempThemeValue,
|
||||
// onChanged: (value) {
|
||||
// _tempThemeValue = value!;
|
||||
// Get.appUpdate();
|
||||
// },
|
||||
// ),
|
||||
// ],
|
||||
// );
|
||||
// }),
|
||||
// actions: [
|
||||
// TextButton(onPressed: () => Get.back(), child: const Text('取消')),
|
||||
// TextButton(
|
||||
// onPressed: () async {
|
||||
// var res = await VideoHttp.coinVideo(
|
||||
// bvid: bvid, multiply: _tempThemeValue);
|
||||
// if (res['status']) {
|
||||
// SmartDialog.showToast('投币成功');
|
||||
// hasCoin.value = true;
|
||||
// dynamic bangumiDetail =
|
||||
// (loadingState.value as Success).response;
|
||||
// bangumiDetail.stat!['coins'] =
|
||||
// bangumiDetail.stat!['coins'] + _tempThemeValue;
|
||||
// loadingState.value = LoadingState.success(bangumiDetail);
|
||||
// } else {
|
||||
// SmartDialog.showToast(res['msg']);
|
||||
// }
|
||||
// Get.back();
|
||||
// },
|
||||
// child: const Text('确定'))
|
||||
// ],
|
||||
// );
|
||||
// });
|
||||
}
|
||||
|
||||
// (取消)收藏 bangumi
|
||||
@@ -582,8 +504,11 @@ class BangumiIntroController extends CommonController {
|
||||
Get.find<VideoDetailController>(tag: Get.arguments['heroTag']);
|
||||
PlayRepeat playRepeat = videoDetailCtr.plPlayerController.playRepeat;
|
||||
|
||||
if ((loadingState.value as Success).response.episodes != null) {
|
||||
episodes = (loadingState.value as Success).response.episodes!;
|
||||
if ((loadingState.value as Success<BangumiInfoModel>).response.episodes !=
|
||||
null) {
|
||||
episodes = (loadingState.value as Success<BangumiInfoModel>)
|
||||
.response
|
||||
.episodes!;
|
||||
} else {
|
||||
if (playRepeat == PlayRepeat.autoPlayRelated) {
|
||||
return playRelated();
|
||||
|
||||
@@ -131,8 +131,7 @@ class BangumiInfo extends StatefulWidget {
|
||||
State<BangumiInfo> createState() => _BangumiInfoState();
|
||||
}
|
||||
|
||||
class _BangumiInfoState extends State<BangumiInfo>
|
||||
with TickerProviderStateMixin {
|
||||
class _BangumiInfoState extends State<BangumiInfo> {
|
||||
late final BangumiIntroController bangumiIntroController;
|
||||
late final VideoDetailController videoDetailCtr;
|
||||
late final BangumiInfoModel? bangumiItem;
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import 'package:PiliPlus/http/bangumi.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/models/bangumi/pgc_index/condition.dart';
|
||||
import 'package:PiliPlus/pages/common/common_controller.dart';
|
||||
import 'package:PiliPlus/utils/extension.dart';
|
||||
import 'package:PiliPlus/pages/common/common_list_controller.dart';
|
||||
import 'package:get/get.dart' hide Condition;
|
||||
|
||||
class PgcIndexController extends CommonController {
|
||||
class PgcIndexController extends CommonListController {
|
||||
PgcIndexController(this.indexType);
|
||||
int? indexType;
|
||||
Rx<LoadingState> conditionState = LoadingState.loading().obs;
|
||||
@@ -51,20 +50,16 @@ class PgcIndexController extends CommonController {
|
||||
);
|
||||
|
||||
@override
|
||||
bool customHandleResponse(Success response) {
|
||||
List? getDataList(response) {
|
||||
return response['list'];
|
||||
}
|
||||
|
||||
@override
|
||||
bool customHandleResponse(bool isRefresh, Success response) {
|
||||
if (response.response['has_next'] == null ||
|
||||
response.response['has_next'] == 0) {
|
||||
isEnd = true;
|
||||
}
|
||||
if (isEnd.not && (response.response['list'] as List?).isNullOrEmpty) {
|
||||
isEnd = true;
|
||||
}
|
||||
if (currentPage != 1 && loadingState.value is Success) {
|
||||
response.response['list'] ??= [];
|
||||
response.response['list']!
|
||||
.insertAll(0, (loadingState.value as Success).response);
|
||||
}
|
||||
loadingState.value = LoadingState.success(response.response['list']);
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -207,10 +207,10 @@ class _PgcIndexPageState extends State<PgcIndexPage>
|
||||
],
|
||||
);
|
||||
|
||||
Widget _buildList(LoadingState loadingState) {
|
||||
Widget _buildList(LoadingState<List<dynamic>?> loadingState) {
|
||||
return switch (loadingState) {
|
||||
Loading() => HttpError(errMsg: '加载中'),
|
||||
Success() => (loadingState.response as List?)?.isNotEmpty == true
|
||||
Success() => loadingState.response?.isNotEmpty == true
|
||||
? SliverGrid(
|
||||
gridDelegate: SliverGridDelegateWithExtentAndRatio(
|
||||
mainAxisSpacing: StyleString.cardSpace,
|
||||
@@ -221,13 +221,13 @@ class _PgcIndexPageState extends State<PgcIndexPage>
|
||||
),
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(BuildContext context, int index) {
|
||||
if (index == loadingState.response.length - 1) {
|
||||
if (index == loadingState.response!.length - 1) {
|
||||
_ctr.onLoadMore();
|
||||
}
|
||||
return BangumiCardVPgcIndex(
|
||||
bangumiItem: loadingState.response[index]);
|
||||
bangumiItem: loadingState.response![index]);
|
||||
},
|
||||
childCount: loadingState.response.length,
|
||||
childCount: loadingState.response!.length,
|
||||
),
|
||||
)
|
||||
: HttpError(callback: _ctr.onReload),
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'dart:async';
|
||||
import 'package:PiliPlus/common/widgets/loading_widget.dart';
|
||||
import 'package:PiliPlus/common/widgets/refresh_indicator.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/models/bangumi/list.dart';
|
||||
import 'package:PiliPlus/models/common/tab_type.dart';
|
||||
import 'package:PiliPlus/pages/bangumi/pgc_index/pgc_index_page.dart';
|
||||
import 'package:PiliPlus/pages/common/common_page.dart';
|
||||
@@ -230,10 +231,10 @@ class _BangumiPageState extends CommonPageState<BangumiPage, BangumiController>
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBody(LoadingState loadingState) {
|
||||
Widget _buildBody(LoadingState<List<BangumiListItemModel>?> loadingState) {
|
||||
return switch (loadingState) {
|
||||
Loading() => const SliverToBoxAdapter(),
|
||||
Success() => (loadingState.response as List?)?.isNotEmpty == true
|
||||
Success() => loadingState.response?.isNotEmpty == true
|
||||
? SliverGrid(
|
||||
gridDelegate: SliverGridDelegateWithExtentAndRatio(
|
||||
// 行间距
|
||||
@@ -247,13 +248,13 @@ class _BangumiPageState extends CommonPageState<BangumiPage, BangumiController>
|
||||
),
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(BuildContext context, int index) {
|
||||
if (index == loadingState.response.length - 1) {
|
||||
if (index == loadingState.response!.length - 1) {
|
||||
controller.onLoadMore();
|
||||
}
|
||||
return BangumiCardV(
|
||||
bangumiItem: loadingState.response[index]);
|
||||
bangumiItem: loadingState.response![index]);
|
||||
},
|
||||
childCount: loadingState.response.length,
|
||||
childCount: loadingState.response!.length,
|
||||
),
|
||||
)
|
||||
: HttpError(
|
||||
|
||||
Reference in New Issue
Block a user