179 lines
5.4 KiB
Dart
179 lines
5.4 KiB
Dart
import 'package:skywood/global/request/api_const.dart';
|
|
import 'package:skywood/global/request/app_request.dart';
|
|
import 'package:skywood/global/tool/sky_log.dart';
|
|
import 'package:skywood/utils/models/drama/skywood_category.dart';
|
|
import 'package:skywood/utils/models/drama/skywood_detail.dart';
|
|
import 'package:skywood/utils/models/drama/skywood_drama.dart';
|
|
import 'package:skywood/utils/models/drama/skywood_home.dart';
|
|
|
|
class PlayClient {
|
|
static Future<List<SkywoodHome>> getHomeData() {
|
|
return AppRequest.get(ApiStringPlay.getHomeModules).then((value) {
|
|
if (value.isSuccess) {
|
|
List? list = value.data['data']['list'];
|
|
List<SkywoodHome> homeList = [];
|
|
if (list != null) {
|
|
homeList = list.map((e) => SkywoodHome.fromJson(e)).toList();
|
|
}
|
|
return homeList;
|
|
}
|
|
return [];
|
|
});
|
|
}
|
|
|
|
static Future<List<SkywoodCategory>> getCategoriesList() {
|
|
return AppRequest.get(ApiStringPlay.getCategoriesList).then((value) {
|
|
// SkyLog.print('vvvvv: ${value.data}');
|
|
if (!value.isSuccess) return [];
|
|
|
|
Map<String, dynamic> data = value.data['data'];
|
|
List? list = data['list'];
|
|
|
|
List<SkywoodCategory> categoryList = [];
|
|
if (list != null) {
|
|
// id 28 不显示,删除
|
|
categoryList = list.map((e) => SkywoodCategory.fromJson(e)).toList();
|
|
categoryList.removeWhere((element) => element.id == 28);
|
|
categoryList.removeWhere((element) => element.name.length >= 10);
|
|
}
|
|
return categoryList;
|
|
});
|
|
}
|
|
|
|
static Future<List<SkywoodDrama>> getCategoriesDetail({
|
|
required int categoryId,
|
|
int page = 1,
|
|
int pageSize = 20,
|
|
}) {
|
|
return AppRequest.fetchPage<SkywoodDrama>(
|
|
ApiStringPlay.getCategoriesDetail,
|
|
page: page,
|
|
pageSize: pageSize,
|
|
extraParams: {'category_id': categoryId},
|
|
fromJson: (json) => SkywoodDrama.fromJson(json),
|
|
);
|
|
}
|
|
|
|
// getSearchHots
|
|
static Future<List<SkywoodDrama>> getSearchHots() {
|
|
return AppRequest.get(ApiStringPlay.getSearchHots).then((value) {
|
|
if (value.isSuccess) {
|
|
SkyLog.print('getSearchHots: ${value.data}');
|
|
List list = parseDataForList(value.data);
|
|
return list.map((e) => SkywoodDrama.fromJson(e)).toList();
|
|
}
|
|
return [];
|
|
});
|
|
}
|
|
|
|
// search
|
|
static Future<List<SkywoodDrama>> search({required String keyword}) {
|
|
return AppRequest.get(ApiStringPlay.getSearch, queryParameters: {
|
|
'search': keyword,
|
|
}).then((value) {
|
|
if (value.isSuccess) {
|
|
SkyLog.print('getSearchHots: ${value.data}');
|
|
List list = parseDataForList(value.data);
|
|
return list.map((e) => SkywoodDrama.fromJson(e)).toList();
|
|
}
|
|
return [];
|
|
});
|
|
}
|
|
|
|
//getCollections
|
|
static Future<List<SkywoodDrama>> getCollections({
|
|
int page = 1,
|
|
int pageSize = 10,
|
|
}) {
|
|
Map<String, dynamic> params = _setPage(page: page, pageSize: pageSize);
|
|
return AppRequest.get(
|
|
ApiStringPlay.getCollections,
|
|
queryParameters: params,
|
|
).then((value) {
|
|
if (value.isSuccess) {
|
|
SkyLog.print('getCollections: ${value.data}');
|
|
List list = parseDataForList(value.data);
|
|
return list.map((e) => SkywoodDrama.fromJson(e)).toList();
|
|
}
|
|
return [];
|
|
});
|
|
}
|
|
|
|
// getHistory
|
|
static Future<List<SkywoodDrama>> getHistory({
|
|
int page = 1,
|
|
int pageSize = 10,
|
|
}) {
|
|
Map<String, dynamic> params = _setPage(page: page, pageSize: pageSize);
|
|
return AppRequest.get(
|
|
ApiStringPlay.getHistories,
|
|
queryParameters: params,
|
|
).then((value) {
|
|
if (value.isSuccess) {
|
|
SkyLog.print('getHistory: ${value.data}');
|
|
List list = parseDataForList(value.data);
|
|
return list.map((e) => SkywoodDrama.fromJson(e)).toList();
|
|
}
|
|
return [];
|
|
});
|
|
}
|
|
|
|
// getVideoDetail
|
|
static Future<SkywoodDetail?> getVideoDetail({
|
|
required int shortPlayId,
|
|
required int shortPlayVideoId,
|
|
}) {
|
|
Map<String, dynamic> params = {};
|
|
params['short_play_id'] = shortPlayId;
|
|
params['short_play_video_id'] = shortPlayVideoId;
|
|
return AppRequest.get(
|
|
ApiStringPlay.getVideoDetail,
|
|
queryParameters: params,
|
|
).then((value) {
|
|
if (value.isSuccess) {
|
|
SkyLog.print('getVideoDetail: ${value.data['data']}');
|
|
return SkywoodDetail.fromJson(value.data['data']);
|
|
}
|
|
return null;
|
|
});
|
|
}
|
|
|
|
// collect
|
|
static Future<bool> collect({
|
|
required int shortPlayId,
|
|
required int videoId,
|
|
}) {
|
|
Map<String, dynamic> params = {};
|
|
params['short_play_id'] = shortPlayId;
|
|
params['video_id'] = videoId;
|
|
return AppRequest.post(ApiStringPlay.collect, data: params).then((value) {
|
|
SkyLog.print('collecttttt: ${value.data}');
|
|
if (value.isSuccess) {}
|
|
return value.isSuccess;
|
|
});
|
|
}
|
|
|
|
// cancelCollect
|
|
static Future<bool> cancelCollect({required int shortPlayId}) {
|
|
Map<String, dynamic> params = {};
|
|
params['short_play_id'] = shortPlayId;
|
|
return AppRequest.post(ApiStringPlay.cancelCollect, data: params).then((
|
|
value,
|
|
) {
|
|
SkyLog.print('cancelCollectttt: ${value.data}');
|
|
if (value.isSuccess) {}
|
|
return value.isSuccess;
|
|
});
|
|
}
|
|
|
|
static Map<String, dynamic> _setPage({int page = 1, int pageSize = 10}) {
|
|
return {'current_page': page, 'page_size': pageSize};
|
|
}
|
|
|
|
static List parseDataForList(Map<String, dynamic> data) {
|
|
Map<String, dynamic> map = data['data'];
|
|
List? listData = map['list'];
|
|
return listData ?? [];
|
|
}
|
|
}
|