Skip to content

Commit

Permalink
Reader template
Browse files Browse the repository at this point in the history
  • Loading branch information
arianneorpilla committed Jun 12, 2021
1 parent 290c35a commit 125837e
Show file tree
Hide file tree
Showing 6 changed files with 173 additions and 46 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<p align="center">A mobile video player and card creation toolkit tailored for language learners.</p>

<p align="center" style="margin:0"><b>Latest GitHub Release:<br>
<a href="https://github.com/lrorpilla/jidoujisho/releases/tag/0.20.0-beta">0.20.0-beta 🇯🇵 → 🇬🇧</a><br>
<a href="https://github.com/lrorpilla/jidoujisho/releases/tag/0.20.1-beta">0.20.1-beta 🇯🇵 → 🇬🇧</a><br>
<a href="https://github.com/lrorpilla/jidoujisho/releases/tag/0.16.7-beta-kren">0.16.7-beta 🇰🇷 → 🇬🇧</a></b><br>

<p align="center" style="margin:0"><b>Release Archive:<br>
Expand All @@ -28,7 +28,7 @@
<a href="https://github.com/lrorpilla/jidoujisho/releases/tag/0.17.4-beta">0.17</a> ·
<a href="https://github.com/lrorpilla/jidoujisho/releases/tag/0.18.1-beta">0.18</a> ·
<a href="https://github.com/lrorpilla/jidoujisho/releases/tag/0.19.1-beta">0.19</a> ·
<a href="https://github.com/lrorpilla/jidoujisho/releases/tag/0.20.0-beta">0.20</a>
<a href="https://github.com/lrorpilla/jidoujisho/releases/tag/0.20.1-beta">0.20</a>
</b></p>

# 📚 Uninterrupted language immersion at your fingertips
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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[] {"<div class=\"image\">{{Image}}</div><br><p id=\"sentence\">{{Sentence}}</p>"},
new String[] {"<div class=\"image\">{{Image}}</div><br><p id=\"sentence\">{{Sentence}}</p>" +
"{{Audio}}<br><hr id=reading><p id=\"reading\">{{Reading}}</p><h2 id=\"word\">{{Word}}</h2><br><p><small id=\"meaning\">{{Meaning}}</small></p><br>"},
new String[] {"{{Audio}}<div class=\"image\">{{Image}}</div><br><p id=\"sentence\">{{Sentence}}</p><div id=\"word\">{{Word}}</div>"},
new String[] {"{{Audio}}<div class=\"image\">{{Image}}</div><br><p id=\"sentence\">{{Sentence}}</p><div id=\"word\">{{Word}}</div>" +
"<hr><p id=\"reading\">{{Reading}}</p><h2 id=\"word\">{{Word}}</h2><br><p><small id=\"meaning\">{{Meaning}}</small></p><br>"},
"p {\n" +
" margin: 0px\n" +
"}\n" +
Expand Down Expand Up @@ -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" +
Expand Down Expand Up @@ -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[] {"<p id=\"sentence\">{{Sentence}}</p>"},
new String[] {"<p id=\"sentence\">{{Sentence}}</p><br>{{Audio}}<br>{{Image}}<br><br>" +
new String[] {"<p id=\"sentence\">{{Sentence}}</p><div id=\"word\">{{Word}}</div>"},
new String[] {"<p id=\"sentence\">{{Sentence}}</p><div id=\"word\">{{Word}}</div><br>{{Audio}}<div class=\"image\">{{Image}}</div>" +
"<hr id=reading><p id=\"reading\">{{Reading}}</p><h2 id=\"word\">{{Word}}</h2><br><p><small id=\"meaning\">{{Meaning}}</small></p>"},
"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<String> 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[] {"<p id=\"sentence\">{{Sentence}}</p><div id=\"word\">{{Word}}</div>"},
new String[] {"<p id=\"sentence\">{{Sentence}}</p><div id=\"word\">{{Word}}</div><br>{{Audio}}<div class=\"image\">{{Image}}</div>" +
"<hr id=reading><p id=\"reading\">{{Reading}}</p><h2 id=\"word\">{{Word}}</h2><br><p><small id=\"meaning\">{{Meaning}}</small></p>"},
"p {\n" +
" margin: 0px\n" +
Expand Down Expand Up @@ -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" +
Expand Down Expand Up @@ -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":
Expand Down
38 changes: 35 additions & 3 deletions lib/anki.dart
Original file line number Diff line number Diff line change
Expand Up @@ -578,11 +578,14 @@ Future<void> 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', <String, dynamic>{
await platform.invokeMethod(method, <String, dynamic>{
'deck': deck,
'image': image,
'audio': audio,
Expand Down Expand Up @@ -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);
Expand All @@ -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,
);
}
61 changes: 37 additions & 24 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3414,18 +3414,18 @@ class _CreatorState extends State<Creator> {
_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;
}
}

Expand Down Expand Up @@ -3708,17 +3708,17 @@ class _CreatorState extends State<Creator> {
_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);

Expand Down Expand Up @@ -4293,6 +4293,18 @@ class _CreatorState extends State<Creator> {
}
}

bool isReader() {
return initialSentence.isNotEmpty;
}

String isReaderText() {
if (isReader()) {
return "Reader";
} else {
return "Creator";
}
}

Widget showExportButton() {
return ValueListenableBuilder(
valueListenable: _justExported,
Expand All @@ -4317,8 +4329,8 @@ class _CreatorState extends State<Creator> {
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,
Expand Down Expand Up @@ -4358,6 +4370,7 @@ class _CreatorState extends State<Creator> {
_readingController.text,
_meaningController.text,
_fileImage,
isReader(),
);

setState(() {
Expand Down
3 changes: 2 additions & 1 deletion lib/util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ String stripLatinCharactersFromText(String subtitleText) {
subtitleText =
subtitleText.replaceAll(RegExp(r'(?![×])[A-zÀ-ú\u0160-\u0161œû]'), "○");
subtitleText = subtitleText.replaceAll(
RegExp(r"[-!%^&*_+|~=`;'?,.\/"
RegExp(r"[-!%^&*_+|=`;'?,.\/"
'"'
"]"),
"○");
Expand All @@ -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("«", " ");
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 125837e

Please sign in to comment.