This commit is contained in:
2025-01-06 10:55:26 +08:00
parent a747179cc4
commit 99a3788f4a
5 changed files with 74 additions and 9 deletions

View File

@@ -45,8 +45,9 @@ class _SearchResultPageState extends State<SearchResultPage> {
if (suggestionsController.entry != null) {
suggestionsController.remove();
}
text = checkAutoLanguage(text);
setState(() {
this.text = text;
this.text = text!;
});
appdata.addSearchHistory(text);
controller.currentText = text;
@@ -92,13 +93,33 @@ class _SearchResultPageState extends State<SearchResultPage> {
super.dispose();
}
String checkAutoLanguage(String text) {
var setting = appdata.settings["autoAddLanguageFilter"] ?? 'none';
if (setting == 'none') {
return text;
}
var searchSource = sourceKey;
// TODO: Move it to a better place
const enabledSources = [
'nhentai',
'ehentai',
];
if (!enabledSources.contains(searchSource)) {
return text;
}
if (!text.contains('language:')) {
return '$text language:$setting';
}
return text;
}
@override
void initState() {
sourceKey = widget.sourceKey;
controller = SearchBarController(
currentText: widget.text,
currentText: checkAutoLanguage(widget.text),
onSearch: search,
);
sourceKey = widget.sourceKey;
options = widget.options ?? const [];
validateOptions();
text = widget.text;
@@ -162,6 +183,12 @@ class _SearchResultPageState extends State<SearchResultPage> {
child: IconButton(
icon: const Icon(Icons.tune),
onPressed: () async {
if (suggestionOverlay != null) {
suggestionsController.remove();
}
var previousOptions = options;
var previousSourceKey = sourceKey;
await showDialog(
context: context,
useRootNavigator: true,
@@ -169,7 +196,11 @@ class _SearchResultPageState extends State<SearchResultPage> {
return _SearchSettingsDialog(state: this);
},
);
setState(() {});
if (previousOptions != options || previousSourceKey != sourceKey) {
text = checkAutoLanguage(controller.text);
controller.currentText = text;
setState(() {});
}
},
),
);