Search in sources :

Example 1 with QuranAyahInfo

use of com.quran.labs.androidquran.common.QuranAyahInfo 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 QuranAyahInfo

use of com.quran.labs.androidquran.common.QuranAyahInfo 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 QuranAyahInfo

use of com.quran.labs.androidquran.common.QuranAyahInfo 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 QuranAyahInfo

use of com.quran.labs.androidquran.common.QuranAyahInfo 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 QuranAyahInfo

use of com.quran.labs.androidquran.common.QuranAyahInfo in project quran_android by quran.

the class TranslationPresenter method getPage.

private int getPage(List<QuranAyahInfo> result) {
    final int page;
    if (pages.length == 1) {
        page = pages[0];
    } else {
        QuranAyahInfo ayahInfo = result.get(0);
        page = quranInfo.getPageFromSuraAyah(ayahInfo.sura, ayahInfo.ayah);
    }
    return page;
}
Also used : QuranAyahInfo(com.quran.labs.androidquran.common.QuranAyahInfo)

Aggregations

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