opt models

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-06-04 15:20:35 +08:00
parent f50b1d2beb
commit b960359a39
858 changed files with 11000 additions and 12588 deletions

View File

@@ -1,12 +1,15 @@
import 'dart:async';
import 'package:PiliPlus/common/widgets/dialog/dialog.dart';
import 'package:PiliPlus/http/loading_state.dart';
import 'package:PiliPlus/http/search.dart';
import 'package:PiliPlus/models/search/search_trending/trending_data.dart';
import 'package:PiliPlus/models/search/suggest.dart';
import 'package:PiliPlus/models_new/search/search_rcmd/data.dart';
import 'package:PiliPlus/models_new/search/search_trending/data.dart';
import 'package:PiliPlus/utils/storage.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:get/get_rx/src/rx_workers/utils/debouncer.dart';
import 'package:stream_transform/stream_transform.dart';
class SSearchController extends GetxController {
SSearchController(this.tag);
@@ -15,31 +18,32 @@ class SSearchController extends GetxController {
final searchFocusNode = FocusNode();
final controller = TextEditingController();
RxList<String> historyList = <String>[].obs;
RxList<SearchSuggestItem> searchSuggestList = <SearchSuggestItem>[].obs;
String hintText = '搜索';
late bool enableHotKey;
late bool enableSearchRcmd;
Rx<LoadingState<TrendingData>> loadingState =
LoadingState<TrendingData>.loading().obs;
Rx<LoadingState<SearchKeywordData>> recommendData =
LoadingState<SearchKeywordData>.loading().obs;
int initIndex = 0;
// uid
RxBool showUidBtn = false.obs;
final _debouncer = Debouncer(delay: const Duration(milliseconds: 200));
late final searchSuggestion = GStorage.searchSuggestion;
late final RxBool recordSearchHistory = GStorage.recordSearchHistory.obs;
late final digitOnlyRegExp = RegExp(r'^\d+$');
// history
late final RxBool recordSearchHistory;
late final RxList<String> historyList;
// suggestion
late final bool searchSuggestion;
StreamController<String>? _ctr;
StreamSubscription<String>? _sub;
late final RxList<SearchSuggestItem> searchSuggestList;
// trending
late final bool enableHotKey;
late final Rx<LoadingState<SearchTrendingData>> loadingState;
// rcmd
late final bool enableSearchRcmd;
late final Rx<LoadingState<SearchRcmdData>> recommendData;
@override
void onInit() {
super.onInit();
@@ -54,19 +58,33 @@ class SSearchController extends GetxController {
controller.text = Get.parameters['text']!;
}
historyList.value = List.from(GStorage.historyWord.get('cacheList') ?? []);
searchSuggestion = GStorage.searchSuggestion;
enableHotKey =
GStorage.setting.get(SettingBoxKey.enableHotKey, defaultValue: true);
enableSearchRcmd = GStorage.setting
.get(SettingBoxKey.enableSearchRcmd, defaultValue: true);
recordSearchHistory = GStorage.recordSearchHistory.obs;
if (recordSearchHistory.value) {
historyList =
List<String>.from(GStorage.historyWord.get('cacheList') ?? []).obs;
}
if (searchSuggestion) {
_ctr = StreamController<String>();
_sub = _ctr!.stream
.debounce(const Duration(milliseconds: 200), trailing: true)
.listen(querySearchSuggest);
searchSuggestList = <SearchSuggestItem>[].obs;
}
if (enableHotKey) {
loadingState = LoadingState<SearchTrendingData>.loading().obs;
queryHotSearchList();
}
if (enableSearchRcmd) {
recommendData = LoadingState<SearchRcmdData>.loading().obs;
queryRecommendList();
}
}
@@ -77,10 +95,12 @@ class SSearchController extends GetxController {
void onChange(String value) {
validateUid();
if (value.isEmpty) {
searchSuggestList.clear();
} else if (searchSuggestion) {
_debouncer.call(() => querySearchSuggest(value));
if (searchSuggestion) {
if (value.isEmpty) {
searchSuggestList.clear();
} else {
_ctr!.add(value);
}
}
}
@@ -146,15 +166,16 @@ class SSearchController extends GetxController {
}
Future<void> querySearchSuggest(String value) async {
var result = await SearchHttp.searchSuggest(term: value);
if (result['status']) {
if (result['data'] is SearchSuggestModel) {
searchSuggestList.value = result['data'].tag;
var res = await SearchHttp.searchSuggest(term: value);
if (res['status']) {
SearchSuggestModel data = res['data'];
if (data.tag?.isNotEmpty == true) {
searchSuggestList.value = data.tag!;
}
}
}
void onLongSelect(word) {
void onLongSelect(String word) {
historyList.remove(word);
GStorage.historyWord.put('cacheList', historyList);
}
@@ -174,7 +195,8 @@ class SSearchController extends GetxController {
void onClose() {
searchFocusNode.dispose();
controller.dispose();
_debouncer.cancel();
_sub?.cancel();
_ctr?.close();
super.onClose();
}
}