Skip to content

Commit 641a317

Browse files
committed
updated fluhbar to reflect search sort priorities
1 parent 548e8e1 commit 641a317

File tree

2 files changed

+34
-37
lines changed

2 files changed

+34
-37
lines changed

lib/widgets/dictionary/dictionary_alt_search_flushbar.dart

+6-15
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,18 @@ import 'package:easy_localization/easy_localization.dart';
1111
class DictionaryAltSearchFlushbar {
1212

1313
/// the search term text
14-
final String text;
15-
/// the search term text converted to kana (if possible)
16-
final String? queryKana;
17-
/// the search term text converted to kana and deconjugated (if possible)
18-
final List<String>? deconjugated;
14+
final List<String> queries;
1915
/// Callback that is executed when the user taps on a search text as
2016
/// alternative search
2117
final Function(String text) onTapped;
2218

2319
DictionaryAltSearchFlushbar(
24-
this.text,
25-
this.queryKana,
26-
this.deconjugated,
20+
this.queries,
2721
this.onTapped,
2822
);
2923

3024
Flushbar build(BuildContext context) {
3125

32-
List<String> options = [text, queryKana, ...(deconjugated ?? <String>[])]
33-
.nonNulls.toList();
34-
3526
return Flushbar(
3627
backgroundColor: Colors.white,
3728
messageText: Row(
@@ -45,17 +36,17 @@ class DictionaryAltSearchFlushbar {
4536
color: Colors.black
4637
),
4738
children: [
48-
for (int i=0; i<options.length; i++)
39+
for (int i=0; i<queries.length; i++)
4940
...[
5041
TextSpan(
51-
text: options[i],
42+
text: "${i+1}. ${queries[i]}",
5243
style: TextStyle(
5344
color: Theme.of(context).highlightColor
5445
),
5546
recognizer: TapGestureRecognizer()..onTap =
56-
() => onTapped(options[i]),
47+
() => onTapped(queries[i]),
5748
),
58-
if(i < options.length-1)
49+
if(i < queries.length-1)
5950
const TextSpan(
6051
text: "; ",
6152
style: TextStyle(

lib/widgets/dictionary/dictionary_search_widget.dart

+28-22
Original file line numberDiff line numberDiff line change
@@ -648,15 +648,14 @@ class DictionarySearchWidgetState extends State<DictionarySearchWidget>
648648
deconjugated.remove(queryKana);
649649
deconjugated.remove(query);
650650
}
651+
deconjugated.removeWhere((e) => e.isEmpty);
651652

652653
// if the search query was changed show a snackbar and give the option to
653654
// use the original search
654655
if(queryKana != query || deconjugated.isNotEmpty){
655656

656657
deconjugationFlushbar = DictionaryAltSearchFlushbar(
657-
query,
658-
queryKana != query ? queryKana : null,
659-
deconjugated,
658+
selectedSortPrioritiesToActualQueries(query, queryKana, deconjugated),
660659
onAltSearchTapped
661660
)
662661
.build(context)..show(context).then((value) {
@@ -672,25 +671,7 @@ class DictionarySearchWidgetState extends State<DictionarySearchWidget>
672671
widget.context.read<DictSearch>().currentAlternativeSearches = deconjugated;
673672
widget.context.read<DictSearch>().searchResults =
674673
await GetIt.I<DictionarySearch>().search(
675-
query,
676-
() {
677-
List<String> allQueries = [];
678-
679-
List<String> sel = context.read<Settings>().dictionary.selectedSearchResultSortPriorities;
680-
for (var i = 0; i < sel.length; i++) {
681-
if(sel[i] == LocaleKeys.SettingsScreen_dict_term){
682-
allQueries.add(query);
683-
}
684-
else if(sel[i] == LocaleKeys.SettingsScreen_dict_convert_to_kana && queryKana != null){
685-
allQueries.add(queryKana);
686-
}
687-
else if(sel[i] == LocaleKeys.SettingsScreen_dict_base_form){
688-
allQueries.addAll(deconjugated);
689-
}
690-
}
691-
692-
return allQueries;
693-
} ()
674+
query, selectedSortPrioritiesToActualQueries(query, queryKana, deconjugated)
694675
) ?? [];
695676
}
696677

@@ -702,5 +683,30 @@ class DictionarySearchWidgetState extends State<DictionarySearchWidget>
702683
deconjugationFlushbar?.dismiss();
703684

704685
}
686+
687+
/// Based on the selected search result sort priorities, returns a list of
688+
/// the actual search terms following the user'spriorities
689+
List<String> selectedSortPrioritiesToActualQueries(
690+
String query, String? queryKana, List<String> deconjugated
691+
){
692+
693+
List<String> allQueries = [];
694+
695+
List<String> sel = context.read<Settings>().dictionary.selectedSearchResultSortPriorities;
696+
for (var i = 0; i < sel.length; i++) {
697+
if(sel[i] == LocaleKeys.SettingsScreen_dict_term){
698+
allQueries.add(query);
699+
}
700+
else if(sel[i] == LocaleKeys.SettingsScreen_dict_convert_to_kana && queryKana != null){
701+
allQueries.add(queryKana);
702+
}
703+
else if(sel[i] == LocaleKeys.SettingsScreen_dict_base_form){
704+
allQueries.addAll(deconjugated);
705+
}
706+
}
707+
708+
return allQueries;
709+
710+
}
705711
}
706712

0 commit comments

Comments
 (0)