use of com.quran.labs.androidquran.common.QuranText in project quran_android by quran.
the class BaseTranslationPresenterTest method testCombineAyahDataOneVerseNoArabic.
@Test
public void testCombineAyahDataOneVerseNoArabic() {
VerseRange verseRange = new VerseRange(1, 1, 1, 1, 1);
List<QuranText> arabic = Collections.emptyList();
List<QuranAyahInfo> info = presenter.combineAyahData(verseRange, arabic, Collections.singletonList(Collections.singletonList(new QuranText(1, 1, "translation"))));
assertThat(info).hasSize(1);
QuranAyahInfo first = info.get(0);
assertThat(first.sura).isEqualTo(1);
assertThat(first.ayah).isEqualTo(1);
assertThat(first.texts).hasSize(1);
assertThat(first.arabicText).isNull();
assertThat(first.texts.get(0)).isEqualTo("translation");
}
use of com.quran.labs.androidquran.common.QuranText in project quran_android by quran.
the class BaseTranslationPresenterTest method testCombineAyahDataOneVerse.
@Test
public void testCombineAyahDataOneVerse() {
VerseRange verseRange = new VerseRange(1, 1, 1, 1, 1);
List<QuranText> arabic = Collections.singletonList(new QuranText(1, 1, "first ayah"));
List<QuranAyahInfo> info = presenter.combineAyahData(verseRange, arabic, Collections.singletonList(Collections.singletonList(new QuranText(1, 1, "translation"))));
assertThat(info).hasSize(1);
QuranAyahInfo first = info.get(0);
assertThat(first.sura).isEqualTo(1);
assertThat(first.ayah).isEqualTo(1);
assertThat(first.texts).hasSize(1);
assertThat(first.arabicText).isEqualTo("first ayah");
assertThat(first.texts.get(0)).isEqualTo("translation");
}
use of com.quran.labs.androidquran.common.QuranText in project quran_android by quran.
the class BaseTranslationPresenterTest method testCombineAyahDataOneVerseEmpty.
@Test
public void testCombineAyahDataOneVerseEmpty() {
VerseRange verseRange = new VerseRange(1, 1, 1, 1, 1);
List<QuranText> arabic = Collections.emptyList();
List<QuranAyahInfo> info = presenter.combineAyahData(verseRange, arabic, Collections.emptyList());
assertThat(info).hasSize(0);
}
use of com.quran.labs.androidquran.common.QuranText in project quran_android by quran.
the class BaseTranslationPresenter method combineAyahData.
@NonNull
List<QuranAyahInfo> combineAyahData(@NonNull VerseRange verseRange, @NonNull List<QuranText> arabic, @NonNull List<List<QuranText>> texts) {
final int arabicSize = arabic.size();
final int translationCount = texts.size();
List<QuranAyahInfo> result = new ArrayList<>();
if (translationCount > 0) {
final int verses = arabicSize == 0 ? verseRange.versesInRange : arabicSize;
for (int i = 0; i < verses; i++) {
QuranText element = arabicSize == 0 ? null : arabic.get(i);
final List<String> ayahTranslations = new ArrayList<>();
for (int j = 0; j < translationCount; j++) {
QuranText item = texts.get(j).size() > i ? texts.get(j).get(i) : null;
if (item != null) {
ayahTranslations.add(texts.get(j).get(i).text);
element = item;
} else {
// this keeps the translations aligned with their translators
// even when a particular translator doesn't load.
ayahTranslations.add("");
}
}
if (element != null) {
String arabicText = arabicSize == 0 ? null : arabic.get(i).text;
result.add(new QuranAyahInfo(element.sura, element.ayah, arabicText, ayahTranslations, quranInfo.getAyahId(element.sura, element.ayah)));
}
}
} else if (arabicSize > 0) {
for (int i = 0; i < arabicSize; i++) {
QuranText arabicItem = arabic.get(i);
result.add(new QuranAyahInfo(arabicItem.sura, arabicItem.ayah, arabicItem.text, Collections.emptyList(), quranInfo.getAyahId(arabicItem.sura, arabicItem.ayah)));
}
}
return result;
}
use of com.quran.labs.androidquran.common.QuranText in project quran_android by quran.
the class BaseTranslationPresenter method ensureProperTranslations.
/**
* Ensures that the list of translations is valid
* In this case, valid means that the number of verses that we have translations for is either
* the same as the verse range, or that it's 0 (i.e. due to an error querying the database). If
* the list has a non-zero length that is less than what the verseRange says, it adds empty
* entries for those.
*
* @param verseRange the range of verses we're trying to get
* @param texts the data we got back from the database
* @return a list of QuranText with a length of either 0 or the verse range
*/
@NonNull
List<QuranText> ensureProperTranslations(@NonNull VerseRange verseRange, @NonNull List<QuranText> texts) {
int expectedVerses = verseRange.versesInRange;
int textSize = texts.size();
if (textSize == 0 || textSize == expectedVerses) {
return texts;
}
// missing some entries for some ayat - this is a work around for bad data in some databases
// ex. ibn katheer is missing 3 records, 1 in each of suras 5, 17, and 87.
SuraAyah start = new SuraAyah(verseRange.startSura, verseRange.startAyah);
SuraAyah end = new SuraAyah(verseRange.endingSura, verseRange.endingAyah);
SuraAyahIterator iterator = new SuraAyahIterator(quranInfo, start, end);
int i = 0;
while (iterator.next()) {
QuranText item = texts.size() > i ? texts.get(i) : null;
if (item == null || item.sura != iterator.getSura() || item.ayah != iterator.getAyah()) {
texts.add(i, new QuranText(iterator.getSura(), iterator.getAyah(), ""));
}
i++;
}
return texts;
}
Aggregations