use of com.ichi2.anki.multimediacard.glosbe.json.Tuc in project Anki-Android by Ramblurr.
the class TranslationActivity method parseJson.
private static ArrayList<String> parseJson(Response resp, String languageCodeTo) {
ArrayList<String> res = new ArrayList<String>();
/*
* The algorithm below includes the parsing of glosbe results. Glosbe.com returns a list of different phrases in
* source and destination languages. This is done, probably, to improve the reader's understanding. We leave
* here only the translations to the destination language.
*/
List<Tuc> tucs = resp.getTuc();
if (tucs == null) {
return res;
}
for (Tuc tuc : tucs) {
if (tuc == null) {
continue;
}
List<Meaning> meanings = tuc.getMeanings();
if (meanings != null) {
for (Meaning meaning : meanings) {
if (meaning == null) {
continue;
}
if (meaning.getLanguage() == null) {
continue;
}
if (meaning.getLanguage().contentEquals(languageCodeTo)) {
String unescappedString = HtmlUtil.unescape(meaning.getText());
res.add(unescappedString);
}
}
}
Phrase phrase = tuc.getPhrase();
if (phrase != null) {
if (phrase.getLanguageCode() == null) {
continue;
}
if (phrase.getLanguageCode().contentEquals(languageCodeTo)) {
String unescappedString = HtmlUtil.unescape(phrase.getText());
res.add(unescappedString);
}
}
}
return res;
}