Search in sources :

Example 1 with QuranText

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");
}
Also used : VerseRange(com.quran.labs.androidquran.data.VerseRange) QuranAyahInfo(com.quran.labs.androidquran.common.QuranAyahInfo) QuranText(com.quran.labs.androidquran.common.QuranText) Test(org.junit.Test)

Example 2 with QuranText

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");
}
Also used : VerseRange(com.quran.labs.androidquran.data.VerseRange) QuranAyahInfo(com.quran.labs.androidquran.common.QuranAyahInfo) QuranText(com.quran.labs.androidquran.common.QuranText) Test(org.junit.Test)

Example 3 with QuranText

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);
}
Also used : VerseRange(com.quran.labs.androidquran.data.VerseRange) QuranAyahInfo(com.quran.labs.androidquran.common.QuranAyahInfo) QuranText(com.quran.labs.androidquran.common.QuranText) Test(org.junit.Test)

Example 4 with QuranText

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;
}
Also used : QuranAyahInfo(com.quran.labs.androidquran.common.QuranAyahInfo) ArrayList(java.util.ArrayList) QuranText(com.quran.labs.androidquran.common.QuranText) NonNull(android.support.annotation.NonNull)

Example 5 with QuranText

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;
}
Also used : SuraAyahIterator(com.quran.labs.androidquran.data.SuraAyahIterator) SuraAyah(com.quran.labs.androidquran.data.SuraAyah) QuranText(com.quran.labs.androidquran.common.QuranText) NonNull(android.support.annotation.NonNull)

Aggregations

QuranText (com.quran.labs.androidquran.common.QuranText)9 QuranAyahInfo (com.quran.labs.androidquran.common.QuranAyahInfo)5 VerseRange (com.quran.labs.androidquran.data.VerseRange)5 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)3 NonNull (android.support.annotation.NonNull)2 Cursor (android.database.Cursor)1 SuraAyah (com.quran.labs.androidquran.data.SuraAyah)1 SuraAyahIterator (com.quran.labs.androidquran.data.SuraAyahIterator)1