Skip to content

Commit b12c574

Browse files
0.8.1 fix, extended search results, overflow fix and better results for tap to search
1 parent 40434aa commit b12c574

File tree

3 files changed

+354
-200
lines changed

3 files changed

+354
-200
lines changed

lib/player.dart

+119-35
Original file line numberDiff line numberDiff line change
@@ -535,11 +535,10 @@ class _VideoPlayerState extends State<VideoPlayer> {
535535
// }
536536
// }
537537
// }
538-
539538
Widget buildDictionaryLoading(String clipboard) {
540539
String lookupText;
541540
if (globalSelectMode.value) {
542-
lookupText = "Looking up \"$clipboard\"...";
541+
lookupText = "Looking up$clipboard...";
543542
} else {
544543
lookupText = "Looking up definition...";
545544
}
@@ -672,56 +671,141 @@ class _VideoPlayerState extends State<VideoPlayer> {
672671
);
673672
}
674673

675-
Widget buildDictionaryMatch(DictionaryEntry results) {
674+
Widget buildDictionaryMatch(List<DictionaryEntry> results) {
676675
_subtitleFocusNode.unfocus();
676+
ValueNotifier<int> selectedIndex = ValueNotifier<int>(0);
677677

678-
return Column(
679-
children: [
680-
Padding(
681-
padding: EdgeInsets.all(16.0),
682-
child: GestureDetector(
683-
onTap: () {
684-
_clipboard.value = "";
685-
_currentDictionaryEntry.value = DictionaryEntry(
686-
word: "",
687-
reading: "",
688-
meaning: "",
689-
);
690-
},
691-
child: SingleChildScrollView(
692-
child: Container(
693-
padding: EdgeInsets.all(16.0),
694-
color: Colors.grey[800].withOpacity(0.6),
678+
return ValueListenableBuilder(
679+
valueListenable: selectedIndex,
680+
builder: (BuildContext context, int _, Widget widget) {
681+
_currentDictionaryEntry.value = results[selectedIndex.value];
682+
683+
return Container(
684+
padding: EdgeInsets.all(16.0),
685+
alignment: Alignment.topCenter,
686+
child: Container(
687+
padding: EdgeInsets.all(16),
688+
margin: EdgeInsets.only(bottom: 84),
689+
color: Colors.grey[800].withOpacity(0.6),
690+
child: GestureDetector(
691+
onHorizontalDragEnd: (details) {
692+
if (details.primaryVelocity == 0) return;
693+
694+
if (details.primaryVelocity.compareTo(0) == -1) {
695+
if (selectedIndex.value == results.length - 1) {
696+
selectedIndex.value = 0;
697+
} else {
698+
selectedIndex.value += 1;
699+
}
700+
} else {
701+
if (selectedIndex.value == 0) {
702+
selectedIndex.value = results.length - 1;
703+
} else {
704+
selectedIndex.value -= 1;
705+
}
706+
}
707+
},
708+
onTap: () {
709+
_clipboard.value = "";
710+
_currentDictionaryEntry.value = DictionaryEntry(
711+
word: "",
712+
reading: "",
713+
meaning: "",
714+
);
715+
},
695716
child: Column(
717+
mainAxisSize: MainAxisSize.min,
696718
children: [
697719
Text(
698-
results.word,
720+
results[selectedIndex.value].word,
699721
style: TextStyle(
700722
fontWeight: FontWeight.bold,
701723
fontSize: 20,
702724
),
703725
),
704-
Text(results.reading),
705-
SelectableText("\n${results.meaning}\n"),
726+
Text(results[selectedIndex.value].reading),
727+
Flexible(
728+
child: SingleChildScrollView(
729+
child:
730+
Text("\n${results[selectedIndex.value].meaning}\n"),
731+
),
732+
),
733+
Row(
734+
mainAxisSize: MainAxisSize.min,
735+
crossAxisAlignment: CrossAxisAlignment.end,
736+
mainAxisAlignment: MainAxisAlignment.center,
737+
children: [
738+
Text(
739+
"Showing search result ",
740+
style: TextStyle(
741+
fontSize: 11,
742+
),
743+
textAlign: TextAlign.center,
744+
),
745+
Text(
746+
"${selectedIndex.value + 1} ",
747+
style: TextStyle(
748+
fontWeight: FontWeight.bold,
749+
fontSize: 11,
750+
),
751+
textAlign: TextAlign.center,
752+
),
753+
Text(
754+
"out of ",
755+
style: TextStyle(
756+
fontSize: 11,
757+
),
758+
textAlign: TextAlign.center,
759+
),
760+
Text(
761+
"${results.length} ",
762+
style: TextStyle(
763+
fontWeight: FontWeight.bold,
764+
fontSize: 11,
765+
),
766+
textAlign: TextAlign.center,
767+
),
768+
Text(
769+
"found for",
770+
style: TextStyle(
771+
fontSize: 11,
772+
),
773+
textAlign: TextAlign.center,
774+
),
775+
Text(
776+
"『${results[selectedIndex.value].searchTerm}』",
777+
style: TextStyle(
778+
fontWeight: FontWeight.bold,
779+
fontSize: 11,
780+
),
781+
textAlign: TextAlign.center,
782+
),
783+
],
784+
)
706785
],
707786
),
708787
),
709788
),
710-
),
711-
),
712-
Expanded(child: Container()),
713-
],
714-
);
789+
);
790+
});
715791
}
716792

717793
Widget buildDictionary() {
718794
return ValueListenableBuilder(
719795
valueListenable: _clipboard,
720796
builder: (context, clipboard, widget) {
797+
Future<List<DictionaryEntry>> getDictionaryFuture;
798+
if (globalSelectMode.value) {
799+
getDictionaryFuture = getWordDetails(clipboard);
800+
} else {
801+
getDictionaryFuture = getJishoSegmentAndSearch(
802+
_clipboard.value, _currentSubtitle.value.text);
803+
}
804+
721805
return FutureBuilder(
722-
future: getWordDetails(clipboard),
723-
builder:
724-
(BuildContext context, AsyncSnapshot<DictionaryEntry> snapshot) {
806+
future: getDictionaryFuture,
807+
builder: (BuildContext context,
808+
AsyncSnapshot<List<DictionaryEntry>> snapshot) {
725809
if (_clipboard.value == "&<&>export&<&>") {
726810
return buildDictionaryExporting(clipboard);
727811
}
@@ -738,11 +822,11 @@ class _VideoPlayerState extends State<VideoPlayer> {
738822
case ConnectionState.waiting:
739823
return buildDictionaryLoading(clipboard);
740824
default:
741-
DictionaryEntry entry = snapshot.data;
825+
List<DictionaryEntry> entries = snapshot.data;
742826

743-
if (snapshot.hasData) {
744-
_currentDictionaryEntry.value = entry;
745-
return buildDictionaryMatch(entry);
827+
if (snapshot.hasData && snapshot.data.isNotEmpty) {
828+
_currentDictionaryEntry.value = entries.first;
829+
return buildDictionaryMatch(entries);
746830
} else {
747831
return buildDictionaryNoMatch(clipboard);
748832
}

0 commit comments

Comments
 (0)