mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
opt: merge fav,follow,history search
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import 'package:PiliPalaX/http/loading_state.dart';
|
||||
|
||||
import '../models/dynamics/result.dart';
|
||||
import '../models/follow/result.dart';
|
||||
import '../models/member/archive.dart';
|
||||
@@ -386,7 +388,7 @@ class MemberHttp {
|
||||
}
|
||||
|
||||
// 搜索follow
|
||||
static Future getfollowSearch({
|
||||
static Future<LoadingState> getfollowSearch({
|
||||
required int mid,
|
||||
required int ps,
|
||||
required int pn,
|
||||
@@ -409,16 +411,9 @@ class MemberHttp {
|
||||
'wts': params['wts'],
|
||||
});
|
||||
if (res.data['code'] == 0) {
|
||||
return {
|
||||
'status': true,
|
||||
'data': FollowDataModel.fromJson(res.data['data'])
|
||||
};
|
||||
return LoadingState.success(FollowDataModel.fromJson(res.data['data']));
|
||||
} else {
|
||||
return {
|
||||
'status': false,
|
||||
'data': [],
|
||||
'msg': res.data['message'],
|
||||
};
|
||||
return LoadingState.error(res.data['message']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -286,7 +286,7 @@ class UserHttp {
|
||||
// }
|
||||
|
||||
// 搜索历史记录
|
||||
static Future searchHistory(
|
||||
static Future<LoadingState> searchHistory(
|
||||
{required int pn, required String keyword}) async {
|
||||
var res = await Request().get(
|
||||
Api.searchHistory,
|
||||
@@ -297,9 +297,9 @@ class UserHttp {
|
||||
},
|
||||
);
|
||||
if (res.data['code'] == 0) {
|
||||
return {'status': true, 'data': HistoryData.fromJson(res.data['data'])};
|
||||
return LoadingState.success(HistoryData.fromJson(res.data['data']));
|
||||
} else {
|
||||
return {'status': false, 'msg': res.data['message']};
|
||||
return LoadingState.error(res.data['message']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:PiliPalaX/common/skeleton/video_card_h.dart';
|
||||
import 'package:PiliPalaX/http/loading_state.dart';
|
||||
import 'package:PiliPalaX/pages/fav_search/view.dart';
|
||||
import 'package:easy_debounce/easy_throttle.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
@@ -55,8 +56,14 @@ class _FavPageState extends State<FavPage> {
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
if (_favController.loadingState.value is Success) {
|
||||
Get.toNamed(
|
||||
'/favSearch?searchType=1&mediaId=${(_favController.loadingState.value as Success).response.first.id}');
|
||||
Get.toNamed('/favSearch', arguments: {
|
||||
'type': 1,
|
||||
'mediaId': (_favController.loadingState.value as Success)
|
||||
.response
|
||||
.first
|
||||
.id,
|
||||
'searchType': SearchType.fav,
|
||||
});
|
||||
}
|
||||
},
|
||||
icon: const Icon(Icons.search_outlined),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:PiliPalaX/http/loading_state.dart';
|
||||
import 'package:PiliPalaX/pages/fav_search/view.dart' show SearchType;
|
||||
import 'package:easy_debounce/easy_throttle.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
@@ -99,8 +100,11 @@ class _FavDetailPageState extends State<FavDetailPage> {
|
||||
actions: [
|
||||
IconButton(
|
||||
tooltip: '搜索',
|
||||
onPressed: () =>
|
||||
Get.toNamed('/favSearch?searchType=0&mediaId=$mediaId'),
|
||||
onPressed: () => Get.toNamed('/favSearch', arguments: {
|
||||
'type': 0,
|
||||
'mediaId': int.parse(mediaId),
|
||||
'searchType': SearchType.fav,
|
||||
}),
|
||||
icon: const Icon(Icons.search_outlined),
|
||||
),
|
||||
// IconButton(
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import 'package:PiliPalaX/http/loading_state.dart';
|
||||
import 'package:PiliPalaX/http/member.dart';
|
||||
import 'package:PiliPalaX/pages/common/common_controller.dart';
|
||||
import 'package:PiliPalaX/pages/fav_search/view.dart' show SearchType;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get.dart';
|
||||
@@ -11,19 +13,24 @@ class FavSearchController extends CommonController {
|
||||
Rx<TextEditingController> controller = TextEditingController().obs;
|
||||
final FocusNode searchFocusNode = FocusNode();
|
||||
RxString searchKeyWord = ''.obs; // 搜索词
|
||||
String hintText = '请输入已收藏视频名称'; // 默认
|
||||
String hintText = '搜索'; // 默认
|
||||
RxString loadingText = '加载中...'.obs; // 加载提示
|
||||
bool hasMore = false;
|
||||
late int searchType;
|
||||
late int mediaId;
|
||||
int? type;
|
||||
int? mediaId;
|
||||
int? mid;
|
||||
late SearchType searchType;
|
||||
RxBool enableMultiple = false.obs;
|
||||
|
||||
int count = 0; // 总数
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
searchType = int.parse(Get.parameters['searchType']!);
|
||||
mediaId = int.parse(Get.parameters['mediaId']!);
|
||||
type = Get.arguments['type'];
|
||||
mediaId = Get.arguments['mediaId'];
|
||||
mid = Get.arguments['mid'];
|
||||
searchType = Get.arguments['searchType'];
|
||||
}
|
||||
|
||||
// 清空搜索
|
||||
@@ -38,6 +45,9 @@ class FavSearchController extends CommonController {
|
||||
|
||||
@override
|
||||
Future onRefresh() {
|
||||
if (controller.value.text.isEmpty) {
|
||||
return Future.value();
|
||||
}
|
||||
hasMore = true;
|
||||
return super.onRefresh();
|
||||
}
|
||||
@@ -59,11 +69,17 @@ class FavSearchController extends CommonController {
|
||||
List currentList = loadingState.value is Success
|
||||
? (loadingState.value as Success).response
|
||||
: [];
|
||||
List dataList = currentPage == 1
|
||||
? response.response.medias
|
||||
: currentList + response.response.medias;
|
||||
List dataList = searchType == SearchType.fav
|
||||
? (currentPage == 1
|
||||
? response.response.medias
|
||||
: currentList + response.response.medias)
|
||||
: (currentPage == 1
|
||||
? response.response.list
|
||||
: currentList + response.response.list);
|
||||
loadingState.value = LoadingState.success(dataList);
|
||||
hasMore = response.response.hasMore;
|
||||
hasMore = searchType == SearchType.fav
|
||||
? response.response.hasMore
|
||||
: response.response.list.isNotEmpty;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -79,17 +95,46 @@ class FavSearchController extends CommonController {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<LoadingState> customGetData() => UserHttp.userFavFolderDetail(
|
||||
pn: currentPage,
|
||||
ps: 20,
|
||||
mediaId: mediaId,
|
||||
keyword: searchKeyWord.value,
|
||||
type: searchType,
|
||||
);
|
||||
Future<LoadingState> customGetData() => searchType == SearchType.fav
|
||||
? UserHttp.userFavFolderDetail(
|
||||
pn: currentPage,
|
||||
ps: 20,
|
||||
mediaId: mediaId!,
|
||||
keyword: searchKeyWord.value,
|
||||
type: type!,
|
||||
)
|
||||
: searchType == SearchType.follow
|
||||
? MemberHttp.getfollowSearch(
|
||||
mid: mid!,
|
||||
ps: 20,
|
||||
pn: currentPage,
|
||||
name: controller.value.text,
|
||||
)
|
||||
: UserHttp.searchHistory(
|
||||
pn: currentPage,
|
||||
keyword: controller.value.text,
|
||||
);
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
searchFocusNode.dispose();
|
||||
super.onClose();
|
||||
}
|
||||
|
||||
Future delHistory(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.removeWhere((e) => e.kid == kid);
|
||||
loadingState.value = LoadingState.success(historyList);
|
||||
SmartDialog.showToast(res['msg']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
import 'package:PiliPalaX/common/constants.dart';
|
||||
import 'package:PiliPalaX/common/widgets/http_error.dart';
|
||||
import 'package:PiliPalaX/http/loading_state.dart';
|
||||
import 'package:PiliPalaX/pages/follow/widgets/follow_item.dart';
|
||||
import 'package:PiliPalaX/pages/history/widgets/item.dart';
|
||||
import 'package:PiliPalaX/utils/grid.dart';
|
||||
import 'package:easy_debounce/easy_throttle.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
@@ -8,6 +12,8 @@ import 'package:PiliPalaX/pages/fav_detail/widget/fav_video_card.dart';
|
||||
|
||||
import 'controller.dart';
|
||||
|
||||
enum SearchType { fav, follow, history }
|
||||
|
||||
class FavSearchPage extends StatefulWidget {
|
||||
const FavSearchPage({super.key});
|
||||
|
||||
@@ -17,12 +23,10 @@ class FavSearchPage extends StatefulWidget {
|
||||
|
||||
class _FavSearchPageState extends State<FavSearchPage> {
|
||||
final FavSearchController _favSearchCtr = Get.put(FavSearchController());
|
||||
late int searchType;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
searchType = int.parse(Get.parameters['searchType']!);
|
||||
_favSearchCtr.scrollController.addListener(
|
||||
() {
|
||||
if (_favSearchCtr.scrollController.position.pixels >=
|
||||
@@ -89,29 +93,65 @@ class _FavSearchPageState extends State<FavSearchPage> {
|
||||
),
|
||||
],
|
||||
)
|
||||
: 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!)
|
||||
: {},
|
||||
);
|
||||
}
|
||||
},
|
||||
)
|
||||
: _favSearchCtr.searchType == SearchType.fav
|
||||
? 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: _favSearchCtr.type,
|
||||
callFn: () => _favSearchCtr.type != 1
|
||||
? _favSearchCtr
|
||||
.onCancelFav(loadingState.response[index].id!)
|
||||
: {},
|
||||
);
|
||||
}
|
||||
},
|
||||
)
|
||||
: _favSearchCtr.searchType == SearchType.follow
|
||||
? ListView.builder(
|
||||
controller: _favSearchCtr.scrollController,
|
||||
itemCount: loadingState.response.length,
|
||||
itemBuilder: ((context, index) {
|
||||
return FollowItem(
|
||||
item: loadingState.response[index],
|
||||
);
|
||||
}),
|
||||
)
|
||||
: CustomScrollView(
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
controller: _favSearchCtr.scrollController,
|
||||
slivers: [
|
||||
SliverGrid(
|
||||
gridDelegate: SliverGridDelegateWithExtentAndRatio(
|
||||
mainAxisSpacing: StyleString.cardSpace,
|
||||
crossAxisSpacing: StyleString.safeSpace,
|
||||
maxCrossAxisExtent: Grid.maxRowWidth * 2,
|
||||
childAspectRatio: StyleString.aspectRatio * 2.4,
|
||||
mainAxisExtent: 0),
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(context, index) {
|
||||
return HistoryItem(
|
||||
videoItem: loadingState.response[index],
|
||||
ctr: _favSearchCtr,
|
||||
onChoose: null,
|
||||
onUpdateMultiple: () => null,
|
||||
);
|
||||
},
|
||||
childCount: loadingState.response.length,
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
: loadingState is Error
|
||||
? CustomScrollView(
|
||||
slivers: <Widget>[
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'package:PiliPalaX/pages/fav_search/view.dart' show SearchType;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'controller.dart';
|
||||
@@ -38,7 +39,10 @@ class _FollowPageState extends State<FollowPage> {
|
||||
),
|
||||
actions: [
|
||||
IconButton(
|
||||
onPressed: () => Get.toNamed('/followSearch?mid=$mid'),
|
||||
onPressed: () => Get.toNamed('/favSearch', arguments: {
|
||||
'mid': int.parse(mid),
|
||||
'searchType': SearchType.follow,
|
||||
}),
|
||||
icon: const Icon(Icons.search_outlined),
|
||||
tooltip: '搜索'),
|
||||
PopupMenuButton(
|
||||
|
||||
@@ -1,73 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:PiliPalaX/http/member.dart';
|
||||
|
||||
import '../../models/follow/result.dart';
|
||||
|
||||
class FollowSearchController extends GetxController {
|
||||
Rx<TextEditingController> controller = TextEditingController().obs;
|
||||
final FocusNode searchFocusNode = FocusNode();
|
||||
RxString searchKeyWord = ''.obs;
|
||||
String hintText = '搜索';
|
||||
RxString loadingStatus = 'init'.obs;
|
||||
late int mid = 1;
|
||||
RxString uname = ''.obs;
|
||||
int ps = 20;
|
||||
int pn = 1;
|
||||
RxList<FollowItemModel> followList = <FollowItemModel>[].obs;
|
||||
RxInt total = 0.obs;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
mid = int.parse(Get.parameters['mid']!);
|
||||
}
|
||||
|
||||
// 清空搜索
|
||||
void onClear() {
|
||||
if (searchKeyWord.value.isNotEmpty && controller.value.text != '') {
|
||||
controller.value.clear();
|
||||
searchKeyWord.value = '';
|
||||
} else {
|
||||
Get.back();
|
||||
}
|
||||
}
|
||||
|
||||
void onChange(value) {
|
||||
searchKeyWord.value = value;
|
||||
}
|
||||
|
||||
// 提交搜索内容
|
||||
void submit() {
|
||||
loadingStatus.value = 'loading';
|
||||
searchFollow();
|
||||
}
|
||||
|
||||
Future searchFollow({type = 'init'}) async {
|
||||
if (controller.value.text == '') {
|
||||
return {'status': true, 'data': <FollowItemModel>[].obs};
|
||||
}
|
||||
if (type == 'init') {
|
||||
ps = 1;
|
||||
}
|
||||
var res = await MemberHttp.getfollowSearch(
|
||||
mid: mid,
|
||||
ps: ps,
|
||||
pn: pn,
|
||||
name: controller.value.text,
|
||||
);
|
||||
if (res['status']) {
|
||||
if (type == 'init') {
|
||||
followList.value = res['data'].list;
|
||||
} else {
|
||||
followList.addAll(res['data'].list);
|
||||
}
|
||||
total.value = res['data'].total;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void onLoad() {
|
||||
searchFollow(type: 'onLoad');
|
||||
}
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
library follow_search;
|
||||
|
||||
export './controller.dart';
|
||||
export './view.dart';
|
||||
@@ -1,127 +0,0 @@
|
||||
import 'package:easy_debounce/easy_throttle.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:PiliPalaX/common/widgets/http_error.dart';
|
||||
import 'package:PiliPalaX/pages/follow_search/index.dart';
|
||||
|
||||
import '../follow/widgets/follow_item.dart';
|
||||
|
||||
class FollowSearchPage extends StatefulWidget {
|
||||
const FollowSearchPage({super.key});
|
||||
|
||||
@override
|
||||
State<FollowSearchPage> createState() => _FollowSearchPageState();
|
||||
}
|
||||
|
||||
class _FollowSearchPageState extends State<FollowSearchPage> {
|
||||
final FollowSearchController _followSearchController =
|
||||
Get.put(FollowSearchController());
|
||||
late Future? _futureBuilder;
|
||||
final ScrollController scrollController = ScrollController();
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_followSearchController.searchFocusNode.dispose();
|
||||
scrollController.removeListener(() {});
|
||||
scrollController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_futureBuilder = _followSearchController.searchFollow();
|
||||
scrollController.addListener(
|
||||
() {
|
||||
if (scrollController.position.pixels >=
|
||||
scrollController.position.maxScrollExtent - 200) {
|
||||
EasyThrottle.throttle(
|
||||
'my-throttler', const Duration(milliseconds: 500), () {
|
||||
_followSearchController.onLoad();
|
||||
});
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
void reRequest() {
|
||||
setState(() {
|
||||
_futureBuilder = _followSearchController.searchFollow();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
titleSpacing: 0,
|
||||
actions: [
|
||||
IconButton(
|
||||
tooltip: '搜索',
|
||||
onPressed: reRequest,
|
||||
icon: const Icon(Icons.search, size: 22),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
],
|
||||
title: TextField(
|
||||
autofocus: true,
|
||||
focusNode: _followSearchController.searchFocusNode,
|
||||
controller: _followSearchController.controller.value,
|
||||
textInputAction: TextInputAction.search,
|
||||
onChanged: (value) => _followSearchController.onChange(value),
|
||||
textAlignVertical: TextAlignVertical.center,
|
||||
decoration: InputDecoration(
|
||||
hintText: _followSearchController.hintText,
|
||||
border: InputBorder.none,
|
||||
suffixIcon: IconButton(
|
||||
tooltip: '清空',
|
||||
icon: const Icon(Icons.clear, size: 22),
|
||||
onPressed: () => _followSearchController.onClear(),
|
||||
),
|
||||
),
|
||||
onSubmitted: (String value) => reRequest(),
|
||||
),
|
||||
),
|
||||
body: FutureBuilder(
|
||||
future: _futureBuilder,
|
||||
builder: (BuildContext context, AsyncSnapshot snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.done) {
|
||||
var data = snapshot.data;
|
||||
if (data == null) {
|
||||
return CustomScrollView(
|
||||
slivers: [
|
||||
HttpError(errMsg: snapshot.data['msg'], fn: reRequest)
|
||||
],
|
||||
);
|
||||
}
|
||||
if (data['status']) {
|
||||
RxList followList = _followSearchController.followList;
|
||||
return Obx(
|
||||
() => followList.isNotEmpty
|
||||
? ListView.builder(
|
||||
controller: scrollController,
|
||||
itemCount: followList.length,
|
||||
itemBuilder: ((context, index) {
|
||||
return FollowItem(
|
||||
item: followList[index],
|
||||
);
|
||||
}),
|
||||
)
|
||||
: CustomScrollView(
|
||||
slivers: [HttpError(errMsg: '未搜索到结果', fn: reRequest)],
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return CustomScrollView(
|
||||
slivers: [
|
||||
HttpError(errMsg: snapshot.data['msg'], fn: reRequest)
|
||||
],
|
||||
);
|
||||
}
|
||||
} else {
|
||||
return const SizedBox();
|
||||
}
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'package:PiliPalaX/pages/fav_search/view.dart' show SearchType;
|
||||
import 'package:easy_debounce/easy_throttle.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
@@ -80,7 +81,9 @@ class _HistoryPageState extends State<HistoryPage> {
|
||||
actions: [
|
||||
IconButton(
|
||||
tooltip: '搜索',
|
||||
onPressed: () => Get.toNamed('/historySearch'),
|
||||
onPressed: () => Get.toNamed('/favSearch', arguments: {
|
||||
'searchType': SearchType.history,
|
||||
}),
|
||||
icon: const Icon(Icons.search_outlined),
|
||||
),
|
||||
PopupMenuButton<String>(
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'package:PiliPalaX/pages/fav_search/controller.dart';
|
||||
import 'package:PiliPalaX/utils/app_scheme.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
@@ -12,7 +13,6 @@ import 'package:PiliPalaX/models/bangumi/info.dart';
|
||||
import 'package:PiliPalaX/models/common/business_type.dart';
|
||||
import 'package:PiliPalaX/models/common/search_type.dart';
|
||||
import 'package:PiliPalaX/models/live/item.dart';
|
||||
import 'package:PiliPalaX/pages/history_search/index.dart';
|
||||
import 'package:PiliPalaX/utils/feed_back.dart';
|
||||
import 'package:PiliPalaX/utils/id_utils.dart';
|
||||
import 'package:PiliPalaX/utils/utils.dart';
|
||||
@@ -145,7 +145,7 @@ class HistoryItem extends StatelessWidget {
|
||||
}
|
||||
},
|
||||
onLongPress: () {
|
||||
if (ctr is HistorySearchController) {
|
||||
if (ctr is FavSearchController) {
|
||||
return;
|
||||
}
|
||||
if (!ctr!.enableMultiple.value) {
|
||||
|
||||
@@ -1,88 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:PiliPalaX/http/user.dart';
|
||||
import 'package:PiliPalaX/models/user/history.dart';
|
||||
|
||||
class HistorySearchController extends GetxController {
|
||||
final ScrollController scrollController = ScrollController();
|
||||
Rx<TextEditingController> controller = TextEditingController().obs;
|
||||
final FocusNode searchFocusNode = FocusNode();
|
||||
RxString searchKeyWord = ''.obs;
|
||||
String hintText = '搜索';
|
||||
RxString loadingStatus = 'init'.obs;
|
||||
RxString loadingText = '加载中...'.obs;
|
||||
late int mid;
|
||||
RxString uname = ''.obs;
|
||||
int pn = 1;
|
||||
int count = 0;
|
||||
RxList<HisListItem> historyList = <HisListItem>[].obs;
|
||||
RxBool enableMultiple = false.obs;
|
||||
|
||||
// 清空搜索
|
||||
void onClear() {
|
||||
if (searchKeyWord.value.isNotEmpty && controller.value.text != '') {
|
||||
controller.value.clear();
|
||||
searchKeyWord.value = '';
|
||||
} else {
|
||||
Get.back();
|
||||
}
|
||||
}
|
||||
|
||||
void onChange(value) {
|
||||
searchKeyWord.value = value;
|
||||
}
|
||||
|
||||
// 提交搜索内容
|
||||
void submit() {
|
||||
loadingStatus.value = 'loading';
|
||||
pn = 1;
|
||||
searchHistories();
|
||||
}
|
||||
|
||||
// 搜索视频
|
||||
Future searchHistories({type = 'init'}) async {
|
||||
if (type == 'onLoad' && loadingText.value == '没有更多了') {
|
||||
return;
|
||||
}
|
||||
var res = await UserHttp.searchHistory(
|
||||
pn: pn,
|
||||
keyword: controller.value.text,
|
||||
);
|
||||
if (res['status']) {
|
||||
if (type == 'init' && pn == 1) {
|
||||
historyList.value = res['data'].list;
|
||||
} else {
|
||||
historyList.addAll(res['data'].list);
|
||||
}
|
||||
historyList.refresh();
|
||||
count = res['data'].page['total'];
|
||||
if (historyList.length == count) {
|
||||
loadingText.value = '没有更多了';
|
||||
}
|
||||
}
|
||||
loadingStatus.value = 'finish';
|
||||
// return res;
|
||||
}
|
||||
|
||||
onLoad() {
|
||||
pn += 1;
|
||||
searchHistories(type: 'onLoad');
|
||||
}
|
||||
|
||||
Future delHistory(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']) {
|
||||
historyList.removeWhere((e) => e.kid == kid);
|
||||
SmartDialog.showToast(res['msg']);
|
||||
}
|
||||
loadingStatus.value = 'finish';
|
||||
}
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
library history_search;
|
||||
|
||||
export './controller.dart';
|
||||
export './view.dart';
|
||||
@@ -1,108 +0,0 @@
|
||||
import 'package:easy_debounce/easy_throttle.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:PiliPalaX/pages/history/widgets/item.dart';
|
||||
|
||||
import '../../common/constants.dart';
|
||||
import '../../utils/grid.dart';
|
||||
import 'controller.dart';
|
||||
|
||||
class HistorySearchPage extends StatefulWidget {
|
||||
const HistorySearchPage({super.key});
|
||||
|
||||
@override
|
||||
State<HistorySearchPage> createState() => _HistorySearchPageState();
|
||||
}
|
||||
|
||||
class _HistorySearchPageState extends State<HistorySearchPage> {
|
||||
final HistorySearchController _historySearchCtr =
|
||||
Get.put(HistorySearchController());
|
||||
late ScrollController scrollController;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
scrollController = _historySearchCtr.scrollController;
|
||||
scrollController.addListener(
|
||||
() {
|
||||
if (scrollController.position.pixels >=
|
||||
scrollController.position.maxScrollExtent - 300) {
|
||||
EasyThrottle.throttle('history', const Duration(seconds: 1), () {
|
||||
_historySearchCtr.onLoad();
|
||||
});
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
scrollController.removeListener(() {});
|
||||
scrollController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
titleSpacing: 0,
|
||||
actions: [
|
||||
IconButton(
|
||||
tooltip: '搜索',
|
||||
onPressed: () => _historySearchCtr.submit(),
|
||||
icon: const Icon(Icons.search_outlined, size: 22)),
|
||||
const SizedBox(width: 10)
|
||||
],
|
||||
title: Obx(
|
||||
() => TextField(
|
||||
autofocus: true,
|
||||
focusNode: _historySearchCtr.searchFocusNode,
|
||||
controller: _historySearchCtr.controller.value,
|
||||
textInputAction: TextInputAction.search,
|
||||
onChanged: (value) => _historySearchCtr.onChange(value),
|
||||
textAlignVertical: TextAlignVertical.center,
|
||||
decoration: InputDecoration(
|
||||
hintText: _historySearchCtr.hintText,
|
||||
border: InputBorder.none,
|
||||
suffixIcon: IconButton(
|
||||
tooltip: '清空',
|
||||
icon: const Icon(Icons.clear, size: 22),
|
||||
onPressed: () => _historySearchCtr.onClear(),
|
||||
),
|
||||
),
|
||||
onSubmitted: (String value) => _historySearchCtr.submit(),
|
||||
),
|
||||
),
|
||||
),
|
||||
body: Obx(
|
||||
() => _historySearchCtr.loadingStatus.value == 'init'
|
||||
? const SizedBox()
|
||||
: CustomScrollView(
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
controller: scrollController,
|
||||
slivers: [
|
||||
Obx(() => SliverGrid(
|
||||
gridDelegate: SliverGridDelegateWithExtentAndRatio(
|
||||
mainAxisSpacing: StyleString.cardSpace,
|
||||
crossAxisSpacing: StyleString.safeSpace,
|
||||
maxCrossAxisExtent: Grid.maxRowWidth * 2,
|
||||
childAspectRatio: StyleString.aspectRatio * 2.4,
|
||||
mainAxisExtent: 0),
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(context, index) {
|
||||
return HistoryItem(
|
||||
videoItem: _historySearchCtr.historyList[index],
|
||||
ctr: _historySearchCtr,
|
||||
onChoose: null,
|
||||
onUpdateMultiple: () => null,
|
||||
);
|
||||
},
|
||||
childCount: _historySearchCtr.historyList.length,
|
||||
)))
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@ import 'package:hive/hive.dart';
|
||||
import 'package:PiliPalaX/pages/msg_feed_top/at_me/view.dart';
|
||||
import 'package:PiliPalaX/pages/msg_feed_top/reply_me/view.dart';
|
||||
import 'package:PiliPalaX/pages/msg_feed_top/like_me/view.dart';
|
||||
import 'package:PiliPalaX/pages/follow_search/view.dart';
|
||||
import 'package:PiliPalaX/pages/setting/pages/logs.dart';
|
||||
|
||||
import '../pages/about/index.dart';
|
||||
@@ -21,7 +20,6 @@ import '../pages/fav_detail/index.dart';
|
||||
import '../pages/fav_search/index.dart';
|
||||
import '../pages/follow/index.dart';
|
||||
import '../pages/history/index.dart';
|
||||
import '../pages/history_search/index.dart';
|
||||
import '../pages/home/index.dart';
|
||||
import '../pages/hot/index.dart';
|
||||
import '../pages/html/index.dart';
|
||||
@@ -145,8 +143,6 @@ class Routes {
|
||||
//
|
||||
CustomGetPage(name: '/htmlRender', page: () => const HtmlRenderPage()),
|
||||
// 历史记录搜索
|
||||
CustomGetPage(
|
||||
name: '/historySearch', page: () => const HistorySearchPage()),
|
||||
|
||||
CustomGetPage(name: '/playSpeedSet', page: () => const PlaySpeedPage()),
|
||||
// 收藏搜索
|
||||
@@ -181,8 +177,6 @@ class Routes {
|
||||
name: '/memberSeasons', page: () => const MemberSeasonsPage()),
|
||||
// 日志
|
||||
CustomGetPage(name: '/logs', page: () => const LogsPage()),
|
||||
// 搜索关注
|
||||
CustomGetPage(name: '/followSearch', page: () => const FollowSearchPage()),
|
||||
// 订阅
|
||||
CustomGetPage(name: '/subscription', page: () => const SubPage()),
|
||||
// 订阅详情
|
||||
|
||||
Reference in New Issue
Block a user