Skip to content

Commit

Permalink
Improve monolingual, fix some UI bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
arianneorpilla committed May 8, 2021
1 parent 2906f1f commit edd34f6
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 36 deletions.
7 changes: 7 additions & 0 deletions chewie/lib/src/material_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:chewie/src/chewie_progress_colors.dart';
import 'package:chewie/src/material_progress_bar.dart';
import 'package:chewie/src/utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_vlc_player/flutter_vlc_player.dart';

import 'package:share/share.dart';
Expand Down Expand Up @@ -413,6 +414,8 @@ class _MaterialControlsState extends State<MaterialControls>
);

if (chosenOption != null) {
chewieController.clipboard.value = "";

await gSharedPrefs.setString(
"lastPlayedQuality", qualityTags[chosenOption]);
final Duration position = await controller.getPosition();
Expand Down Expand Up @@ -637,6 +640,7 @@ class _MaterialControlsState extends State<MaterialControls>
}

void _cancelAndRestartTimer() {
SystemChrome.setEnabledSystemUIOverlays([]);
_hideTimer?.cancel();
_startHideTimer();

Expand Down Expand Up @@ -680,6 +684,8 @@ class _MaterialControlsState extends State<MaterialControls>
}

void _playPause() {
SystemChrome.setEnabledSystemUIOverlays([]);

final isFinished = controller.value.isEnded;
chewieController.wasPlaying.value = false;

Expand All @@ -699,6 +705,7 @@ class _MaterialControlsState extends State<MaterialControls>
});
} else {
if (isFinished) {
chewieController.clipboard.value = "";
controller.stop();
}
playPauseIconAnimationController.forward();
Expand Down
31 changes: 21 additions & 10 deletions lib/dictionary.dart
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,10 @@ DictionaryEntry getEntryFromJishoResult(JishoResult result, String searchTerm) {
definitions = removeLastNewline(definitions);
}

exportMeanings = "$exportMeanings$i) $definitions -$partsOfSpeech \n";
String numberTag = getBetterNumberTag("$i)");

exportMeanings =
"$exportMeanings$numberTag $definitions -$partsOfSpeech \n";
},
);
exportMeanings = removeLastNewline(exportMeanings);
Expand Down Expand Up @@ -331,7 +334,6 @@ Future<DictionaryHistoryEntry> getWordDetails(String searchTerm) async {

for (DictionaryEntry entry in entries) {
entry.searchTerm = searchTerm;
entry.meaning = getBetterNumberTag(entry.meaning);
}

return DictionaryHistoryEntry(
Expand Down Expand Up @@ -406,7 +408,7 @@ Future<DictionaryHistoryEntry> getMonolingualWordDetails(
}

for (int i = 0; i < meaningElements.length; i++) {
if (entries.length >= 10) {
if (entries.length >= 20) {
return DictionaryHistoryEntry(
entries: entries,
searchTerm: searchTerm,
Expand Down Expand Up @@ -483,14 +485,23 @@ DictionaryEntry getEntryFromGooElement(
reading = wordAndReadingRaw.substring(0, wordAndReadingRaw.indexOf("【"));
}

String meaningRaw =
meaningElement.innerHtml.replaceAll(RegExp(r"<[^>]*>"), "");
List<String> meaningLines = meaningRaw.split("\n");
for (int i = 0; i < meaningLines.length; i++) {
meaningLines[i] = meaningLines[i].trim();
List<dom.Element> meaningChildren = meaningElement.children.first.children;
List<String> meaningChildrenLines = [];
for (int i = 0; i < meaningChildren.length; i++) {
meaningChildrenLines.add(
meaningChildren[i].innerHtml.replaceAll(RegExp(r"<[^>]*>"), "").trim());
}
meaningLines.removeWhere((line) => line.trim().isEmpty);
meaning = meaningLines.join("\n");
meaningChildrenLines.removeWhere((line) => line.isEmpty);
meaning = meaningChildrenLines.join("\n\n");

// String meaningRaw =
// meaningElement.innerHtml.replaceAll(RegExp(r"<[^>]*>"), "");
// List<String> meaningLines = meaningRaw.split("\n");
// for (int i = 0; i < meaningLines.length; i++) {
// meaningLines[i] = meaningLines[i].trim();
// }
// meaningLines.removeWhere((line) => line.trim().isEmpty);
// meaning = meaningLines.join("\n");

word = word.trim();
reading = reading.trim();
Expand Down
25 changes: 22 additions & 3 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,11 @@ class AudioPlayerTask extends BackgroundAudioTask {

void unlockLandscape() {
Wakelock.disable();

SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]);

SystemChrome.setEnabledSystemUIOverlays(
[SystemUiOverlay.bottom, SystemUiOverlay.top]);
}
Expand Down Expand Up @@ -2727,6 +2725,7 @@ class _ClipboardHistoryItemState extends State<ClipboardHistoryItem> {
"Selecting search result ",
style: TextStyle(
fontSize: 11,
color: Colors.grey[400],
),
textAlign: TextAlign.center,
),
Expand All @@ -2742,6 +2741,7 @@ class _ClipboardHistoryItemState extends State<ClipboardHistoryItem> {
"out of ",
style: TextStyle(
fontSize: 11,
color: Colors.grey[400],
),
textAlign: TextAlign.center,
),
Expand All @@ -2757,14 +2757,33 @@ class _ClipboardHistoryItemState extends State<ClipboardHistoryItem> {
"found for",
style: TextStyle(
fontSize: 11,
color: Colors.grey[400],
),
textAlign: TextAlign.center,
),
Text(
"『",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 11,
color: Colors.grey[400],
),
textAlign: TextAlign.center,
),
Text(
"${results.entries[_dialogIndex.value].searchTerm}",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 11,
),
textAlign: TextAlign.center,
),
Text(
"『${results.entries[_dialogIndex.value].searchTerm}』",
"』",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 11,
color: Colors.grey[400],
),
textAlign: TextAlign.center,
),
Expand Down
71 changes: 48 additions & 23 deletions lib/player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class Player extends StatelessWidget {
final Video video;

void lockLandscape() {
Wakelock.enable();
AutoOrientation.landscapeAutoMode(forceSensor: true);

SystemChrome.setEnabledSystemUIOverlays([]);
}

Expand Down Expand Up @@ -506,6 +506,7 @@ class _VideoPlayerState extends State<VideoPlayer> {
},
),
buildSubTrackChanger(),
Container(),
buildDictionary(),
],
),
Expand Down Expand Up @@ -850,9 +851,9 @@ class _VideoPlayerState extends State<VideoPlayer> {
child: Container(
padding: EdgeInsets.all(16.0),
color: Colors.grey[800].withOpacity(0.6),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
child: Wrap(
alignment: WrapAlignment.center,
crossAxisAlignment: WrapCrossAlignment.center,
children: [
Text(
"Looking up",
Expand All @@ -861,14 +862,17 @@ class _VideoPlayerState extends State<VideoPlayer> {
Text(
"『",
style: TextStyle(
color: Colors.grey[350],
color: Colors.grey[300],
),
),
Text(clipboard),
Text(
clipboard,
style: TextStyle(fontWeight: FontWeight.bold),
),
Text(
"』",
style: TextStyle(
color: Colors.grey[350],
color: Colors.grey[300],
),
),
Text(
Expand Down Expand Up @@ -1033,13 +1037,6 @@ class _VideoPlayerState extends State<VideoPlayer> {
}

Widget buildDictionaryNoMatch(String clipboard) {
String lookupText;
if (gIsSelectMode.value) {
lookupText = "No matches for \"$clipboard\" could be queried.";
} else {
lookupText = "No matches for the selection could be queried.";
}

_subtitleFocusNode.unfocus();

return Column(
Expand All @@ -1061,10 +1058,38 @@ class _VideoPlayerState extends State<VideoPlayer> {
);
},
child: Container(
padding: EdgeInsets.all(16.0),
color: Colors.grey[800].withOpacity(0.6),
child: Text(lookupText),
),
padding: EdgeInsets.all(16.0),
color: Colors.grey[800].withOpacity(0.6),
child: Wrap(
alignment: WrapAlignment.center,
crossAxisAlignment: WrapCrossAlignment.center,
children: [
Text(
"No matches for",
style: TextStyle(),
),
Text(
"『",
style: TextStyle(
color: Colors.grey[300],
),
),
Text(
clipboard,
style: TextStyle(fontWeight: FontWeight.bold),
),
Text(
"』",
style: TextStyle(
color: Colors.grey[300],
),
),
Text(
"could be queried.",
style: TextStyle(),
),
],
)),
),
),
Expanded(child: Container()),
Expand Down Expand Up @@ -1155,7 +1180,7 @@ class _VideoPlayerState extends State<VideoPlayer> {
"Selecting search result ",
style: TextStyle(
fontSize: 11,
color: Colors.grey[350],
color: Colors.grey[300],
),
textAlign: TextAlign.center,
),
Expand All @@ -1171,7 +1196,7 @@ class _VideoPlayerState extends State<VideoPlayer> {
"out of ",
style: TextStyle(
fontSize: 11,
color: Colors.grey[350],
color: Colors.grey[300],
),
textAlign: TextAlign.center,
),
Expand All @@ -1187,7 +1212,7 @@ class _VideoPlayerState extends State<VideoPlayer> {
"found for",
style: TextStyle(
fontSize: 11,
color: Colors.grey[350],
color: Colors.grey[300],
),
textAlign: TextAlign.center,
),
Expand All @@ -1196,7 +1221,7 @@ class _VideoPlayerState extends State<VideoPlayer> {
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 11,
color: Colors.grey[350],
color: Colors.grey[300],
),
textAlign: TextAlign.center,
),
Expand All @@ -1213,7 +1238,7 @@ class _VideoPlayerState extends State<VideoPlayer> {
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 11,
color: Colors.grey[350],
color: Colors.grey[300],
),
textAlign: TextAlign.center,
),
Expand Down
18 changes: 18 additions & 0 deletions lib/util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,24 @@ String getBetterNumberTag(String text) {
return text;
}

// bool isCharacterFullWidthNumber(String number) {
// switch (number.substring(0, 0)) {
// case "1":
// case "2":
// case "3":
// case "4":
// case "5":
// case "6":
// case "7":
// case "8":
// case "9":
// case "0":
// return true;
// default:
// return false;
// }
// }

Future<List<String>> scrapeBingImages(String searchTerm) async {
List<String> entries = [];

Expand Down

0 comments on commit edd34f6

Please sign in to comment.