From 125837e5c8fdf1353c6d9dcf82eb81051cdf2ec4 Mon Sep 17 00:00:00 2001 From: ArtisanLRO Date: Sat, 12 Jun 2021 14:45:22 +1000 Subject: [PATCH] Reader template --- README.md | 4 +- .../lrorpilla/jidoujisho/MainActivity.java | 111 +++++++++++++++--- lib/anki.dart | 38 +++++- lib/main.dart | 61 ++++++---- lib/util.dart | 3 +- pubspec.yaml | 2 +- 6 files changed, 173 insertions(+), 46 deletions(-) diff --git a/README.md b/README.md index edd1cdbfc..ccce08303 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@

A mobile video player and card creation toolkit tailored for language learners.

Latest GitHub Release:
-0.20.0-beta πŸ‡―πŸ‡΅ β†’ πŸ‡¬πŸ‡§
+0.20.1-beta πŸ‡―πŸ‡΅ β†’ πŸ‡¬πŸ‡§
0.16.7-beta πŸ‡°πŸ‡· β†’ πŸ‡¬πŸ‡§

Release Archive:
@@ -28,7 +28,7 @@ 0.17 Β· 0.18 Β· 0.19 Β· - 0.20 + 0.20

# πŸ“š Uninterrupted language immersion at your fingertips diff --git a/android/app/src/main/java/io/flutter/plugins/com/lrorpilla/jidoujisho/MainActivity.java b/android/app/src/main/java/io/flutter/plugins/com/lrorpilla/jidoujisho/MainActivity.java index 35540ebb8..c0c9a1143 100644 --- a/android/app/src/main/java/io/flutter/plugins/com/lrorpilla/jidoujisho/MainActivity.java +++ b/android/app/src/main/java/io/flutter/plugins/com/lrorpilla/jidoujisho/MainActivity.java @@ -77,9 +77,9 @@ private void addCreatorNote(String deck, String image, String audio, String sent modelId = api.addNewCustomModel("jidoujisho (Creator)", new String[] {"Image", "Audio", "Sentence", "Word", "Meaning", "Reading"}, new String[] {"jidoujisho (Creator) Default"}, - new String[] {"
{{Image}}

{{Sentence}}

"}, - new String[] {"
{{Image}}

{{Sentence}}

" + - "{{Audio}}

{{Reading}}

{{Word}}


{{Meaning}}


"}, + new String[] {"{{Audio}}
{{Image}}

{{Sentence}}

{{Word}}
"}, + new String[] {"{{Audio}}
{{Image}}

{{Sentence}}

{{Word}}
" + + "

{{Reading}}

{{Word}}


{{Meaning}}


"}, "p {\n" + " margin: 0px\n" + "}\n" + @@ -109,17 +109,17 @@ private void addCreatorNote(String deck, String image, String audio, String sent " position: static;\n" + " height: auto;\n" + " width: auto;\n" + - " max-height: 300px;\n" + + " max-height: 400px;\n" + "}\n" + ".pitch{\n" + - " border-top: solid red 1px;\n" + + " border-top: solid red 2px;\n" + " padding-top: 1px;\n" + "}\n" + "\n" + ".pitch_end{\n" + " border-color: red;\n" + - " border-right: solid red 1px;\n" + - " border-top: solid red 1px; \n" + + " border-right: solid red 2px;\n" + + " border-top: solid red 2px; \n" + " line-height: 1px;\n" + " margin-right: 1px;\n" + " padding-right: 1px;\n" + @@ -156,8 +156,87 @@ private void addNote(String deck, String image, String audio, String sentence, S modelId = api.addNewCustomModel("jidoujisho", new String[] {"Image", "Audio", "Sentence", "Word", "Meaning", "Reading"}, new String[] {"jidoujisho Default"}, - new String[] {"

{{Sentence}}

"}, - new String[] {"

{{Sentence}}


{{Audio}}
{{Image}}

" + + new String[] {"

{{Sentence}}

{{Word}}
"}, + new String[] {"

{{Sentence}}

{{Word}}

{{Audio}}
{{Image}}
" + + "

{{Reading}}

{{Word}}


{{Meaning}}

"}, + "p {\n" + + " margin: 0px\n" + + "}\n" + + "\n" + + "h2 {\n" + + " margin: 0px\n" + + "}\n" + + "\n" + + "small {\n" + + " margin: 0px\n" + + "}\n" + + "\n" + + ".card {\n" + + " font-family: arial;\n" + + " font-size: 20px;\n" + + " white-space: pre-line;\n" + + " text-align: center;\n" + + " color: black;\n" + + " background-color: white;\n" + + "}\n" + + "\n" + + "#sentence {\n" + + " font-size: 30px\n" + + "}\n" + + "\n" + + ".image img {\n" + + " position: static;\n" + + " height: auto;\n" + + " width: auto;\n" + + " max-height: 250px;\n" + + "}\n" + + ".pitch{\n" + + " border-top: solid red 2px;\n" + + " padding-top: 1px;\n" + + "}\n" + + "\n" + + ".pitch_end{\n" + + " border-color: red;\n" + + " border-right: solid red 2px;\n" + + " border-top: solid red 2px; \n" + + " line-height: 1px;\n" + + " margin-right: 1px;\n" + + " padding-right: 1px;\n" + + " padding-top:1px;\n" + + "}", + null, + null + ); + } + + Set tags = new HashSet<>(Arrays.asList("jidoujisho")); + + api.addNote(modelId, deckId, new String[] {image, audio, sentence, word, meaning, reading}, tags); + + System.out.println("Added note via flutter_ankidroid_api"); + System.out.println("Model: " + modelId); + System.out.println("Deck: " + deckId); + } + + private void addReaderNote(String deck, String image, String audio, String sentence, String word, String meaning, String reading) { + final AddContentApi api = new AddContentApi(context); + + long deckId; + if (deckExists(deck)) { + deckId = mAnkiDroid.findDeckIdByName(deck); + } else { + deckId = api.addNewDeck(deck); + } + + long modelId; + if (modelExists("jidoujisho (Reader)")) { + modelId = mAnkiDroid.findModelIdByName("jidoujisho (Reader)", 6); + } else { + modelId = api.addNewCustomModel("jidoujisho (Reader)", + new String[] {"Image", "Audio", "Sentence", "Word", "Meaning", "Reading"}, + new String[] {"jidoujisho (Reader) Default"}, + new String[] {"

{{Sentence}}

{{Word}}
"}, + new String[] {"

{{Sentence}}

{{Word}}

{{Audio}}
{{Image}}
" + "

{{Reading}}

{{Word}}


{{Meaning}}

"}, "p {\n" + " margin: 0px\n" + @@ -188,17 +267,17 @@ private void addNote(String deck, String image, String audio, String sentence, S " position: static;\n" + " height: auto;\n" + " width: auto;\n" + - " max-height: 300px;\n" + + " max-height: 250px;\n" + "}\n" + ".pitch{\n" + - " border-top: solid red 1px;\n" + + " border-top: solid red 2px;\n" + " padding-top: 1px;\n" + "}\n" + "\n" + ".pitch_end{\n" + " border-color: red;\n" + - " border-right: solid red 1px;\n" + - " border-top: solid red 1px; \n" + + " border-right: solid red 2px;\n" + + " border-top: solid red 2px; \n" + " line-height: 1px;\n" + " margin-right: 1px;\n" + " padding-right: 1px;\n" + @@ -269,17 +348,19 @@ public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) { final String answer = call.argument("answer"); final String meaning = call.argument("meaning"); final String reading = call.argument("reading"); + final AddContentApi api = new AddContentApi(context); switch (call.method) { case "addNote": addNote(deck, image, audio, sentence, answer, meaning, reading); break; case "addCreatorNote": - addCreatorNote(deck, image, audio, sentence, answer, meaning, reading); break; + case "addReaderNote": + addReaderNote(deck, image, audio, sentence, answer, meaning, reading); + break; case "getDecks": - final AddContentApi api = new AddContentApi(context); result.success(api.getDeckList()); break; case "requestPermissions": diff --git a/lib/anki.dart b/lib/anki.dart index 3843f239a..7300acf86 100644 --- a/lib/anki.dart +++ b/lib/anki.dart @@ -578,11 +578,14 @@ Future addCreatorNote( String answer, String meaning, String reading, + bool isReader, ) async { const platform = const MethodChannel('com.lrorpilla.api/ankidroid'); + String method = (isReader) ? "addReaderNote" : "addCreatorNote"; + try { - await platform.invokeMethod('addCreatorNote', { + await platform.invokeMethod(method, { 'deck': deck, 'image': image, 'audio': audio, @@ -682,12 +685,22 @@ void exportAnkiCard(String deck, String sentence, String answer, String reading, if (answer == "") { answer = "​"; } + if (sentence == "") { + sentence = "​"; + } + if (meaning == "") { + meaning = "​"; + } + if (reading == "") { + reading = "​"; + } + requestAnkiDroidPermissions(); addNote(deck, addImage, addAudio, sentence, answer, meaning, reading); } void exportCreatorAnkiCard(String deck, String sentence, String answer, - String reading, String meaning, File imageFile) { + String reading, String meaning, File imageFile, bool isReader) { DateTime now = DateTime.now(); String newFileName = "jidoujisho-" + intl.DateFormat('yyyyMMddTkkmmss').format(now); @@ -708,6 +721,25 @@ void exportCreatorAnkiCard(String deck, String sentence, String answer, if (answer == "") { answer = "​"; } + if (isReader && sentence == "") { + sentence = "​"; + } + if (meaning == "") { + meaning = "​"; + } + if (reading == "") { + reading = "​"; + } requestAnkiDroidPermissions(); - addCreatorNote(deck, addImage, addAudio, sentence, answer, meaning, reading); + + addCreatorNote( + deck, + addImage, + addAudio, + sentence, + answer, + meaning, + reading, + isReader, + ); } diff --git a/lib/main.dart b/lib/main.dart index d6a1d0ac9..4931dd8a9 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -3414,18 +3414,18 @@ class _CreatorState extends State { _sentenceController = TextEditingController(text: ""); _wordController = TextEditingController(text: initialSentence); } - } else { - if (_fileImage == null) { - _isFileImage = false; - if (_selectedEntry.value.word.contains(";")) { - searchTerm = _selectedEntry.value.word.split(";").first; - } else if (_selectedEntry.value.word.contains("/")) { - searchTerm = _selectedEntry.value.word.split("/").first; - } else { - searchTerm = _selectedEntry.value.word; - } - _selectedIndex.value = 0; + } + + if (_fileImage == null) { + _isFileImage = false; + if (_selectedEntry.value.word.contains(";")) { + searchTerm = _selectedEntry.value.word.split(";").first; + } else if (_selectedEntry.value.word.contains("/")) { + searchTerm = _selectedEntry.value.word.split("/").first; + } else { + searchTerm = _selectedEntry.value.word; } + _selectedIndex.value = 0; } } @@ -3708,17 +3708,17 @@ class _CreatorState extends State { _meaningController = TextEditingController(text: _selectedEntry.value.meaning); - // if (_fileImage == null) { - // _isFileImage = false; - // if (_selectedEntry.value.word.contains(";")) { - // searchTerm = _selectedEntry.value.word.split(";").first; - // } else if (_selectedEntry.value.word.contains("/")) { - // searchTerm = _selectedEntry.value.word.split("/").first; - // } else { - // searchTerm = _selectedEntry.value.word; - // } - // _selectedIndex.value = 0; - // } + if (_fileImage == null) { + _isFileImage = false; + if (_selectedEntry.value.word.contains(";")) { + searchTerm = _selectedEntry.value.word.split(";").first; + } else if (_selectedEntry.value.word.contains("/")) { + searchTerm = _selectedEntry.value.word.split("/").first; + } else { + searchTerm = _selectedEntry.value.word; + } + _selectedIndex.value = 0; + } print(searchTerm); @@ -4293,6 +4293,18 @@ class _CreatorState extends State { } } + bool isReader() { + return initialSentence.isNotEmpty; + } + + String isReaderText() { + if (isReader()) { + return "Reader"; + } else { + return "Creator"; + } + } + Widget showExportButton() { return ValueListenableBuilder( valueListenable: _justExported, @@ -4317,8 +4329,8 @@ class _CreatorState extends State { exported ? "Card Exported" : isShared - ? "Export Card and Return" - : "Export Card", + ? "Export ${isReaderText()} Card and Return" + : "Export ${isReaderText()} Card", style: TextStyle( color: exported ? Colors.grey : Colors.white, fontSize: 16, @@ -4358,6 +4370,7 @@ class _CreatorState extends State { _readingController.text, _meaningController.text, _fileImage, + isReader(), ); setState(() { diff --git a/lib/util.dart b/lib/util.dart index a5a183061..6c5605def 100644 --- a/lib/util.dart +++ b/lib/util.dart @@ -484,7 +484,7 @@ String stripLatinCharactersFromText(String subtitleText) { subtitleText = subtitleText.replaceAll(RegExp(r'(?![Γ—])[A-zΓ€-ΓΊ\u0160-\u0161Ε“Γ»]'), "β—‹"); subtitleText = subtitleText.replaceAll( - RegExp(r"[-!%^&*_+|~=`;'?,.\/" + RegExp(r"[-!%^&*_+|=`;'?,.\/" '"' "]"), "β—‹"); @@ -502,6 +502,7 @@ String stripLatinCharactersFromText(String subtitleText) { line = line.replaceAll(">", " "); line = line.replaceAll("\$", " "); line = line.replaceAll("…", " "); + line = line.replaceAll("~", " "); line = line.replaceAll("’", " "); line = line.replaceAll("β—‹", " "); line = line.replaceAll("Β«", " "); diff --git a/pubspec.yaml b/pubspec.yaml index 4bd360ab0..532904a62 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -2,7 +2,7 @@ name: jidoujisho description: A mobile video player tailored for Japanese language learners. publish_to: none -version: 0.20.0+40 +version: 0.20.1+41 environment: sdk: ">=2.7.0 <3.0.0"