mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
refa: split fav search page
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -1,69 +1,43 @@
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/http/member.dart';
|
||||
import 'package:PiliPlus/models/model_hot_video_item.dart';
|
||||
import 'package:PiliPlus/pages/common/common_list_controller.dart';
|
||||
import 'package:PiliPlus/pages/fav_search/view.dart' show SearchType;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:PiliPlus/http/video.dart';
|
||||
import 'package:PiliPlus/models/user/fav_detail.dart';
|
||||
import 'package:PiliPlus/pages/common/common_search_controller.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:PiliPlus/http/user.dart';
|
||||
|
||||
import '../../http/video.dart';
|
||||
|
||||
class FavSearchController extends CommonListController {
|
||||
final controller = TextEditingController();
|
||||
final searchFocusNode = FocusNode();
|
||||
|
||||
int? type;
|
||||
int? mediaId;
|
||||
int? mid;
|
||||
late SearchType searchType;
|
||||
final bool? isOwner = Get.arguments['isOwner'];
|
||||
class FavSearchController
|
||||
extends CommonSearchController<FavDetailData, FavDetailItemData> {
|
||||
int type = Get.arguments['type'];
|
||||
int mediaId = Get.arguments['mediaId'];
|
||||
bool isOwner = Get.arguments['isOwner'];
|
||||
dynamic count = Get.arguments['count'];
|
||||
dynamic title = Get.arguments['title'];
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
type = Get.arguments['type'];
|
||||
mediaId = Get.arguments['mediaId'];
|
||||
mid = Get.arguments['mid'];
|
||||
searchType = Get.arguments['searchType'];
|
||||
}
|
||||
|
||||
// 清空搜索
|
||||
void onClear() {
|
||||
if (controller.text.isNotEmpty) {
|
||||
controller.clear();
|
||||
} else {
|
||||
Get.back();
|
||||
}
|
||||
}
|
||||
Future<LoadingState<FavDetailData>> customGetData() =>
|
||||
UserHttp.userFavFolderDetail(
|
||||
pn: currentPage,
|
||||
ps: 20,
|
||||
mediaId: mediaId,
|
||||
keyword: editController.text,
|
||||
type: type,
|
||||
);
|
||||
|
||||
@override
|
||||
Future onRefresh() {
|
||||
if (controller.value.text.isEmpty) {
|
||||
return Future.value();
|
||||
}
|
||||
return super.onRefresh();
|
||||
}
|
||||
|
||||
@override
|
||||
List? getDataList(response) {
|
||||
if (searchType == SearchType.later) {
|
||||
return response['list'];
|
||||
}
|
||||
List<FavDetailItemData>? getDataList(FavDetailData response) {
|
||||
return response.list;
|
||||
}
|
||||
|
||||
@override
|
||||
bool customHandleResponse(bool isRefresh, Success response) {
|
||||
if (searchType == SearchType.fav && response.response.hasMore == false) {
|
||||
bool customHandleResponse(bool isRefresh, Success<FavDetailData> response) {
|
||||
if (response.response.hasMore == false) {
|
||||
isEnd = true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
onCancelFav(int index, int id, int type) async {
|
||||
onCancelFav(int index, int id, int? type) async {
|
||||
var result = await VideoHttp.favVideo(
|
||||
aid: id,
|
||||
addIds: '',
|
||||
@@ -71,69 +45,11 @@ class FavSearchController extends CommonListController {
|
||||
type: type,
|
||||
);
|
||||
if (result['status']) {
|
||||
List dataList = (loadingState.value as Success).response;
|
||||
List<FavDetailItemData> dataList =
|
||||
(loadingState.value as Success).response;
|
||||
dataList.removeAt(index);
|
||||
loadingState.refresh();
|
||||
SmartDialog.showToast('取消收藏');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<LoadingState> customGetData() => switch (searchType) {
|
||||
SearchType.fav => UserHttp.userFavFolderDetail(
|
||||
pn: currentPage,
|
||||
ps: 20,
|
||||
mediaId: mediaId!,
|
||||
keyword: controller.text,
|
||||
type: type!,
|
||||
),
|
||||
SearchType.follow => MemberHttp.getfollowSearch(
|
||||
mid: mid!,
|
||||
ps: 20,
|
||||
pn: currentPage,
|
||||
name: controller.value.text,
|
||||
),
|
||||
SearchType.history => UserHttp.searchHistory(
|
||||
pn: currentPage,
|
||||
keyword: controller.value.text,
|
||||
),
|
||||
SearchType.later => UserHttp.seeYouLater(
|
||||
page: currentPage,
|
||||
keyword: controller.value.text,
|
||||
),
|
||||
};
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
searchFocusNode.dispose();
|
||||
controller.dispose();
|
||||
super.onClose();
|
||||
}
|
||||
|
||||
Future onDelHistory(index, kid, business) async {
|
||||
String resKid = 'archive_$kid';
|
||||
if (business == 'live') {
|
||||
resKid = 'live_$kid';
|
||||
} else if (business.contains('article')) {
|
||||
resKid = 'article_$kid';
|
||||
}
|
||||
|
||||
var res = await UserHttp.delHistory([resKid]);
|
||||
if (res['status']) {
|
||||
List historyList = (loadingState.value as Success).response;
|
||||
historyList.removeAt(index);
|
||||
loadingState.refresh();
|
||||
SmartDialog.showToast(res['msg']);
|
||||
}
|
||||
}
|
||||
|
||||
Future toViewDel(BuildContext context, int index, aid) async {
|
||||
var res = await UserHttp.toViewDel(aids: [aid]);
|
||||
if (res['status']) {
|
||||
List<HotVideoItemModel> list = (loadingState.value as Success).response;
|
||||
list.removeAt(index);
|
||||
loadingState.refresh();
|
||||
}
|
||||
SmartDialog.showToast(res['msg']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
library fav_search;
|
||||
|
||||
export './controller.dart';
|
||||
export './view.dart';
|
||||
@@ -1,10 +1,5 @@
|
||||
import 'package:PiliPlus/common/constants.dart';
|
||||
import 'package:PiliPlus/common/widgets/icon_button.dart';
|
||||
import 'package:PiliPlus/common/widgets/loading_widget.dart';
|
||||
import 'package:PiliPlus/common/widgets/video_card_h.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/pages/follow/widgets/follow_item.dart';
|
||||
import 'package:PiliPlus/pages/history/widgets/item.dart';
|
||||
import 'package:PiliPlus/models/user/fav_detail.dart';
|
||||
import 'package:PiliPlus/pages/common/common_search_page.dart';
|
||||
import 'package:PiliPlus/utils/grid.dart';
|
||||
import 'package:PiliPlus/utils/page_utils.dart';
|
||||
import 'package:PiliPlus/utils/utils.dart';
|
||||
@@ -14,269 +9,72 @@ import 'package:PiliPlus/pages/fav_detail/widget/fav_video_card.dart';
|
||||
|
||||
import 'controller.dart';
|
||||
|
||||
enum SearchType { fav, follow, history, later }
|
||||
|
||||
class FavSearchPage extends StatefulWidget {
|
||||
class FavSearchPage extends CommonSearchPage {
|
||||
const FavSearchPage({super.key});
|
||||
|
||||
@override
|
||||
State<FavSearchPage> createState() => _FavSearchPageState();
|
||||
}
|
||||
|
||||
class _FavSearchPageState extends State<FavSearchPage> {
|
||||
final FavSearchController _favSearchCtr = Get.put(
|
||||
class _FavSearchPageState extends CommonSearchPageState<FavSearchPage,
|
||||
FavDetailData, FavDetailItemData> {
|
||||
@override
|
||||
final FavSearchController controller = Get.put(
|
||||
FavSearchController(),
|
||||
tag: Utils.generateRandomString(8),
|
||||
);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
resizeToAvoidBottomInset: false,
|
||||
appBar: AppBar(
|
||||
actions: [
|
||||
IconButton(
|
||||
tooltip: '搜索',
|
||||
onPressed: _favSearchCtr.onRefresh,
|
||||
icon: const Icon(Icons.search_outlined, size: 22),
|
||||
Widget buildList(List<FavDetailItemData> list) {
|
||||
return CustomScrollView(
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
controller: controller.scrollController,
|
||||
slivers: [
|
||||
SliverPadding(
|
||||
padding: EdgeInsets.only(
|
||||
bottom: MediaQuery.of(context).padding.bottom + 80,
|
||||
),
|
||||
const SizedBox(width: 10)
|
||||
],
|
||||
title: TextField(
|
||||
autofocus: true,
|
||||
focusNode: _favSearchCtr.searchFocusNode,
|
||||
controller: _favSearchCtr.controller,
|
||||
textInputAction: TextInputAction.search,
|
||||
textAlignVertical: TextAlignVertical.center,
|
||||
decoration: InputDecoration(
|
||||
hintText: '搜索',
|
||||
border: InputBorder.none,
|
||||
suffixIcon: IconButton(
|
||||
tooltip: '清空',
|
||||
icon: const Icon(Icons.clear, size: 22),
|
||||
onPressed: () {
|
||||
_favSearchCtr
|
||||
..loadingState.value = LoadingState.loading()
|
||||
..onClear()
|
||||
..searchFocusNode.requestFocus();
|
||||
sliver: SliverGrid(
|
||||
gridDelegate: Grid.videoCardHDelegate(context, minHeight: 110),
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(context, index) {
|
||||
if (index == list.length - 1) {
|
||||
controller.onLoadMore();
|
||||
}
|
||||
final item = list[index];
|
||||
return FavVideoCardH(
|
||||
videoItem: item,
|
||||
onDelFav: controller.isOwner == true
|
||||
? () {
|
||||
controller.onCancelFav(
|
||||
index,
|
||||
item.id!,
|
||||
item.type,
|
||||
);
|
||||
}
|
||||
: null,
|
||||
onViewFav: () {
|
||||
PageUtils.toVideoPage(
|
||||
'bvid=${item.bvid}&cid=${item.cid}',
|
||||
arguments: {
|
||||
'videoItem': item,
|
||||
'heroTag': Utils.makeHeroTag(item.bvid),
|
||||
'sourceType': 'fav',
|
||||
'mediaId': controller.mediaId,
|
||||
'oid': item.id,
|
||||
'favTitle': controller.title,
|
||||
'count': controller.count,
|
||||
'desc': true,
|
||||
'isContinuePlaying': true,
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
onSubmitted: (value) => _favSearchCtr.onReload(),
|
||||
),
|
||||
),
|
||||
body: Obx(() => _buildBody(_favSearchCtr.loadingState.value)),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBody(LoadingState<List<dynamic>?> loadingState) {
|
||||
return switch (loadingState) {
|
||||
Loading() => errorWidget(),
|
||||
Success() => loadingState.response?.isNotEmpty == true
|
||||
? switch (_favSearchCtr.searchType) {
|
||||
SearchType.fav ||
|
||||
SearchType.history ||
|
||||
SearchType.later =>
|
||||
CustomScrollView(
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
controller: _favSearchCtr.scrollController,
|
||||
slivers: [
|
||||
SliverPadding(
|
||||
padding: EdgeInsets.only(
|
||||
bottom: MediaQuery.of(context).padding.bottom + 80,
|
||||
),
|
||||
sliver: SliverGrid(
|
||||
gridDelegate: _favSearchCtr.searchType == SearchType.fav
|
||||
? Grid.videoCardHDelegate(context, minHeight: 110)
|
||||
: Grid.videoCardHDelegate(context),
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(context, index) {
|
||||
if (index == loadingState.response!.length - 1) {
|
||||
_favSearchCtr.onLoadMore();
|
||||
}
|
||||
final item = loadingState.response![index];
|
||||
if (_favSearchCtr.searchType == SearchType.fav) {
|
||||
return FavVideoCardH(
|
||||
videoItem: item,
|
||||
onDelFav: _favSearchCtr.isOwner == true
|
||||
? () {
|
||||
_favSearchCtr.onCancelFav(
|
||||
index,
|
||||
item.id!,
|
||||
item.type,
|
||||
);
|
||||
}
|
||||
: null,
|
||||
onViewFav: () {
|
||||
PageUtils.toVideoPage(
|
||||
'bvid=${item.bvid}&cid=${item.cid}',
|
||||
arguments: {
|
||||
'videoItem': item,
|
||||
'heroTag': Utils.makeHeroTag(item.bvid),
|
||||
'sourceType': 'fav',
|
||||
'mediaId': Get.arguments['mediaId'],
|
||||
'oid': item.id,
|
||||
'favTitle': Get.arguments['title'],
|
||||
'count': Get.arguments['count'],
|
||||
'desc': true,
|
||||
'isContinuePlaying': true,
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
if (_favSearchCtr.searchType ==
|
||||
SearchType.history) {
|
||||
return HistoryItem(
|
||||
videoItem: item,
|
||||
ctr: _favSearchCtr,
|
||||
onChoose: null,
|
||||
onDelete: (kid, business) {
|
||||
_favSearchCtr.onDelHistory(
|
||||
index, kid, business);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
return Stack(
|
||||
children: [
|
||||
VideoCardH(
|
||||
videoItem: item,
|
||||
source: 'later',
|
||||
onViewLater: (cid) {
|
||||
PageUtils.toVideoPage(
|
||||
'bvid=${item.bvid}&cid=$cid',
|
||||
arguments: {
|
||||
'videoItem': item,
|
||||
'oid': item.aid,
|
||||
'heroTag': Utils.makeHeroTag(item.bvid),
|
||||
'sourceType': 'watchLater',
|
||||
'count': Get.arguments['count'],
|
||||
'favTitle': '稍后再看',
|
||||
'mediaId': _favSearchCtr.mid,
|
||||
'desc': false,
|
||||
'isContinuePlaying': index != 0,
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
Positioned(
|
||||
top: 5,
|
||||
left: 12,
|
||||
bottom: 5,
|
||||
child: IgnorePointer(
|
||||
child: LayoutBuilder(
|
||||
builder: (context, constraints) =>
|
||||
AnimatedOpacity(
|
||||
opacity: item.checked == true ? 1 : 0,
|
||||
duration:
|
||||
const Duration(milliseconds: 200),
|
||||
child: Container(
|
||||
alignment: Alignment.center,
|
||||
height: constraints.maxHeight,
|
||||
width: constraints.maxHeight *
|
||||
StyleString.aspectRatio,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius:
|
||||
BorderRadius.circular(10),
|
||||
color:
|
||||
Colors.black.withOpacity(0.6),
|
||||
),
|
||||
child: SizedBox(
|
||||
width: 34,
|
||||
height: 34,
|
||||
child: AnimatedScale(
|
||||
scale:
|
||||
item.checked == true ? 1 : 0,
|
||||
duration: const Duration(
|
||||
milliseconds: 250),
|
||||
curve: Curves.easeInOut,
|
||||
child: IconButton(
|
||||
tooltip: '取消选择',
|
||||
style: ButtonStyle(
|
||||
padding:
|
||||
WidgetStateProperty.all(
|
||||
EdgeInsets.zero),
|
||||
backgroundColor:
|
||||
WidgetStateProperty
|
||||
.resolveWith(
|
||||
(states) {
|
||||
return Theme.of(context)
|
||||
.colorScheme
|
||||
.surface
|
||||
.withOpacity(0.8);
|
||||
},
|
||||
),
|
||||
),
|
||||
onPressed: null,
|
||||
icon: Icon(
|
||||
Icons.done_all_outlined,
|
||||
color: Theme.of(context)
|
||||
.colorScheme
|
||||
.primary,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
right: 12,
|
||||
bottom: 0,
|
||||
child: iconButton(
|
||||
tooltip: '移除',
|
||||
context: context,
|
||||
onPressed: () {
|
||||
_favSearchCtr.toViewDel(
|
||||
context,
|
||||
index,
|
||||
item.aid,
|
||||
);
|
||||
},
|
||||
icon: Icons.clear,
|
||||
iconColor: Theme.of(context)
|
||||
.colorScheme
|
||||
.onSurfaceVariant,
|
||||
bgColor: Colors.transparent,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
childCount: loadingState.response!.length,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
SearchType.follow => ListView.builder(
|
||||
padding: EdgeInsets.only(
|
||||
bottom: MediaQuery.of(context).padding.bottom + 80,
|
||||
),
|
||||
controller: _favSearchCtr.scrollController,
|
||||
itemCount: loadingState.response!.length,
|
||||
itemBuilder: ((context, index) {
|
||||
if (index == loadingState.response!.length - 1) {
|
||||
_favSearchCtr.onLoadMore();
|
||||
}
|
||||
return FollowItem(
|
||||
item: loadingState.response![index],
|
||||
);
|
||||
}),
|
||||
),
|
||||
}
|
||||
: errorWidget(
|
||||
callback: _favSearchCtr.onReload,
|
||||
),
|
||||
Error() => errorWidget(
|
||||
errMsg: loadingState.errMsg,
|
||||
callback: _favSearchCtr.onReload,
|
||||
),
|
||||
LoadingState() => throw UnimplementedError(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user