mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
refactor: fav search
This commit is contained in:
@@ -89,7 +89,7 @@ class UserHttp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<LoadingState> userFavFolderDetailNew(
|
static Future<LoadingState> userFavFolderDetail(
|
||||||
{required int mediaId,
|
{required int mediaId,
|
||||||
required int pn,
|
required int pn,
|
||||||
required int ps,
|
required int ps,
|
||||||
@@ -113,31 +113,6 @@ class UserHttp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<dynamic> userFavFolderDetail(
|
|
||||||
{required int mediaId,
|
|
||||||
required int pn,
|
|
||||||
required int ps,
|
|
||||||
String keyword = '',
|
|
||||||
String order = 'mtime',
|
|
||||||
int type = 0}) async {
|
|
||||||
var res = await Request().get(Api.userFavFolderDetail, data: {
|
|
||||||
'media_id': mediaId,
|
|
||||||
'pn': pn,
|
|
||||||
'ps': ps,
|
|
||||||
'keyword': keyword,
|
|
||||||
'order': order,
|
|
||||||
'type': type,
|
|
||||||
'tid': 0,
|
|
||||||
'platform': 'web'
|
|
||||||
});
|
|
||||||
if (res.data['code'] == 0) {
|
|
||||||
FavDetailData data = FavDetailData.fromJson(res.data['data']);
|
|
||||||
return {'status': true, 'data': data};
|
|
||||||
} else {
|
|
||||||
return {'status': false, 'data': [], 'msg': res.data['message']};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 稍后再看
|
// 稍后再看
|
||||||
static Future<dynamic> seeYouLater() async {
|
static Future<dynamic> seeYouLater() async {
|
||||||
var res = await Request().get(Api.seeYouLater);
|
var res = await Request().get(Api.seeYouLater);
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ class FavDetailController extends CommonController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<LoadingState> customGetData() => UserHttp.userFavFolderDetailNew(
|
Future<LoadingState> customGetData() => UserHttp.userFavFolderDetail(
|
||||||
pn: currentPage,
|
pn: currentPage,
|
||||||
ps: 20,
|
ps: 20,
|
||||||
mediaId: mediaId!,
|
mediaId: mediaId!,
|
||||||
|
|||||||
@@ -1,26 +1,23 @@
|
|||||||
|
import 'package:PiliPalaX/http/loading_state.dart';
|
||||||
|
import 'package:PiliPalaX/pages/common/common_controller.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:PiliPalaX/http/user.dart';
|
import 'package:PiliPalaX/http/user.dart';
|
||||||
import 'package:PiliPalaX/models/user/fav_detail.dart';
|
|
||||||
|
|
||||||
import '../../http/video.dart';
|
import '../../http/video.dart';
|
||||||
|
|
||||||
class FavSearchController extends GetxController {
|
class FavSearchController extends CommonController {
|
||||||
final ScrollController scrollController = ScrollController();
|
|
||||||
Rx<TextEditingController> controller = TextEditingController().obs;
|
Rx<TextEditingController> controller = TextEditingController().obs;
|
||||||
final FocusNode searchFocusNode = FocusNode();
|
final FocusNode searchFocusNode = FocusNode();
|
||||||
RxString searchKeyWord = ''.obs; // 搜索词
|
RxString searchKeyWord = ''.obs; // 搜索词
|
||||||
String hintText = '请输入已收藏视频名称'; // 默认
|
String hintText = '请输入已收藏视频名称'; // 默认
|
||||||
RxBool loadingStatus = false.obs; // 加载状态
|
|
||||||
RxString loadingText = '加载中...'.obs; // 加载提示
|
RxString loadingText = '加载中...'.obs; // 加载提示
|
||||||
bool hasMore = false;
|
bool hasMore = false;
|
||||||
late int searchType;
|
late int searchType;
|
||||||
late int mediaId;
|
late int mediaId;
|
||||||
|
|
||||||
int currentPage = 1; // 当前页
|
|
||||||
int count = 0; // 总数
|
int count = 0; // 总数
|
||||||
RxList<FavDetailItemData> favList = <FavDetailItemData>[].obs;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onInit() {
|
void onInit() {
|
||||||
@@ -39,55 +36,60 @@ class FavSearchController extends GetxController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future onRefresh() {
|
||||||
|
hasMore = true;
|
||||||
|
return super.onRefresh();
|
||||||
|
}
|
||||||
|
|
||||||
void onChange(value) {
|
void onChange(value) {
|
||||||
searchKeyWord.value = value;
|
searchKeyWord.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 提交搜索内容
|
@override
|
||||||
void submit() {
|
Future queryData([bool isRefresh = true]) {
|
||||||
loadingStatus.value = true;
|
if (!hasMore) {
|
||||||
currentPage = 1;
|
return Future.value();
|
||||||
searchFav();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 搜索收藏夹视频
|
|
||||||
Future searchFav({type = 'init'}) async {
|
|
||||||
var res = await await UserHttp.userFavFolderDetail(
|
|
||||||
pn: currentPage,
|
|
||||||
ps: 20,
|
|
||||||
mediaId: mediaId,
|
|
||||||
keyword: searchKeyWord.value,
|
|
||||||
type: searchType,
|
|
||||||
);
|
|
||||||
if (res['status']) {
|
|
||||||
if (currentPage == 1 && type == 'init') {
|
|
||||||
favList.value = res['data'].medias;
|
|
||||||
} else if (type == 'onLoad') {
|
|
||||||
favList.addAll(res['data'].medias);
|
|
||||||
}
|
|
||||||
hasMore = res['data'].hasMore;
|
|
||||||
}
|
}
|
||||||
currentPage += 1;
|
return super.queryData(isRefresh);
|
||||||
loadingStatus.value = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onLoad() {
|
@override
|
||||||
if (!hasMore) return;
|
bool customHandleResponse(Success response) {
|
||||||
searchFav(type: 'onLoad');
|
List currentList = loadingState.value is Success
|
||||||
|
? (loadingState.value as Success).response
|
||||||
|
: [];
|
||||||
|
List dataList = currentPage == 1
|
||||||
|
? response.response.medias
|
||||||
|
: currentList + response.response.medias;
|
||||||
|
loadingState.value = LoadingState.success(dataList);
|
||||||
|
hasMore = response.response.hasMore;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
onCancelFav(int id) async {
|
onCancelFav(int id) async {
|
||||||
var result = await VideoHttp.favVideo(
|
var result = await VideoHttp.favVideo(
|
||||||
aid: id, addIds: '', delIds: mediaId.toString());
|
aid: id, addIds: '', delIds: mediaId.toString());
|
||||||
if (result['status']) {
|
if (result['status']) {
|
||||||
List dataList = favList;
|
List dataList = (loadingState.value as Success).response;
|
||||||
for (var i in dataList) {
|
dataList = dataList.where((item) => item.id != id).toList();
|
||||||
if (i.id == id) {
|
loadingState.value = LoadingState.success(dataList);
|
||||||
dataList.remove(i);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
SmartDialog.showToast('取消收藏');
|
SmartDialog.showToast('取消收藏');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<LoadingState> customGetData() => UserHttp.userFavFolderDetail(
|
||||||
|
pn: currentPage,
|
||||||
|
ps: 20,
|
||||||
|
mediaId: mediaId,
|
||||||
|
keyword: searchKeyWord.value,
|
||||||
|
type: searchType,
|
||||||
|
);
|
||||||
|
|
||||||
|
@override
|
||||||
|
void onClose() {
|
||||||
|
searchFocusNode.dispose();
|
||||||
|
super.onClose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
|
import 'package:PiliPalaX/common/widgets/http_error.dart';
|
||||||
|
import 'package:PiliPalaX/http/loading_state.dart';
|
||||||
import 'package:easy_debounce/easy_throttle.dart';
|
import 'package:easy_debounce/easy_throttle.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:PiliPalaX/common/skeleton/video_card_h.dart';
|
|
||||||
import 'package:PiliPalaX/common/widgets/no_data.dart';
|
import 'package:PiliPalaX/common/widgets/no_data.dart';
|
||||||
import 'package:PiliPalaX/pages/fav_detail/widget/fav_video_card.dart';
|
import 'package:PiliPalaX/pages/fav_detail/widget/fav_video_card.dart';
|
||||||
|
|
||||||
@@ -27,7 +28,7 @@ class _FavSearchPageState extends State<FavSearchPage> {
|
|||||||
if (_favSearchCtr.scrollController.position.pixels >=
|
if (_favSearchCtr.scrollController.position.pixels >=
|
||||||
_favSearchCtr.scrollController.position.maxScrollExtent - 300) {
|
_favSearchCtr.scrollController.position.maxScrollExtent - 300) {
|
||||||
EasyThrottle.throttle('fav', const Duration(seconds: 1), () {
|
EasyThrottle.throttle('fav', const Duration(seconds: 1), () {
|
||||||
_favSearchCtr.onLoad();
|
_favSearchCtr.onLoadMore();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -36,9 +37,7 @@ class _FavSearchPageState extends State<FavSearchPage> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
_favSearchCtr.searchFocusNode.dispose();
|
|
||||||
_favSearchCtr.scrollController.removeListener(() {});
|
_favSearchCtr.scrollController.removeListener(() {});
|
||||||
_favSearchCtr.scrollController.dispose();
|
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,7 +49,7 @@ class _FavSearchPageState extends State<FavSearchPage> {
|
|||||||
actions: [
|
actions: [
|
||||||
IconButton(
|
IconButton(
|
||||||
tooltip: '搜索',
|
tooltip: '搜索',
|
||||||
onPressed: () => _favSearchCtr.submit(),
|
onPressed: _favSearchCtr.onRefresh,
|
||||||
icon: const Icon(Icons.search_outlined, size: 22)),
|
icon: const Icon(Icons.search_outlined, size: 22)),
|
||||||
const SizedBox(width: 10)
|
const SizedBox(width: 10)
|
||||||
],
|
],
|
||||||
@@ -71,47 +70,61 @@ class _FavSearchPageState extends State<FavSearchPage> {
|
|||||||
onPressed: () => _favSearchCtr.onClear(),
|
onPressed: () => _favSearchCtr.onClear(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
onSubmitted: (String value) => _favSearchCtr.submit(),
|
onSubmitted: (String value) => _favSearchCtr.onRefresh(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
body: Obx(
|
body: Obx(() => _buildBody(_favSearchCtr.loadingState.value)),
|
||||||
() => _favSearchCtr.loadingStatus.value && _favSearchCtr.favList.isEmpty
|
|
||||||
? ListView.builder(
|
|
||||||
itemCount: 10,
|
|
||||||
itemBuilder: (context, index) {
|
|
||||||
return const VideoCardHSkeleton();
|
|
||||||
},
|
|
||||||
)
|
|
||||||
: _favSearchCtr.favList.isNotEmpty
|
|
||||||
? ListView.builder(
|
|
||||||
controller: _favSearchCtr.scrollController,
|
|
||||||
itemCount: _favSearchCtr.favList.length + 1,
|
|
||||||
itemBuilder: (context, index) {
|
|
||||||
if (index == _favSearchCtr.favList.length) {
|
|
||||||
return Container(
|
|
||||||
height: MediaQuery.of(context).padding.bottom + 60,
|
|
||||||
padding: EdgeInsets.only(
|
|
||||||
bottom: MediaQuery.of(context).padding.bottom),
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
return FavVideoCardH(
|
|
||||||
videoItem: _favSearchCtr.favList[index],
|
|
||||||
searchType: searchType,
|
|
||||||
callFn: () => searchType != 1
|
|
||||||
? _favSearchCtr
|
|
||||||
.onCancelFav(_favSearchCtr.favList[index].id!)
|
|
||||||
: {},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
)
|
|
||||||
: const CustomScrollView(
|
|
||||||
slivers: <Widget>[
|
|
||||||
NoData(),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget _buildBody(LoadingState loadingState) {
|
||||||
|
return loadingState is Success
|
||||||
|
? loadingState.response.isEmpty
|
||||||
|
? CustomScrollView(
|
||||||
|
slivers: <Widget>[
|
||||||
|
HttpError(
|
||||||
|
errMsg: '没有数据',
|
||||||
|
fn: _favSearchCtr.onReload,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
: ListView.builder(
|
||||||
|
controller: _favSearchCtr.scrollController,
|
||||||
|
itemCount: loadingState.response.length + 1,
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
if (index == loadingState.response.length) {
|
||||||
|
return Container(
|
||||||
|
height: MediaQuery.of(context).padding.bottom + 60,
|
||||||
|
padding: EdgeInsets.only(
|
||||||
|
bottom: MediaQuery.of(context).padding.bottom,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return FavVideoCardH(
|
||||||
|
videoItem: loadingState.response[index],
|
||||||
|
searchType: searchType,
|
||||||
|
callFn: () => searchType != 1
|
||||||
|
? _favSearchCtr
|
||||||
|
.onCancelFav(loadingState.response[index].id!)
|
||||||
|
: {},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
: loadingState is Error
|
||||||
|
? CustomScrollView(
|
||||||
|
slivers: <Widget>[
|
||||||
|
HttpError(
|
||||||
|
errMsg: loadingState.errMsg,
|
||||||
|
fn: _favSearchCtr.onReload,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
: const CustomScrollView(
|
||||||
|
slivers: <Widget>[
|
||||||
|
NoData(),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user