Search in sources :

Example 6 with QuranAyahInfo

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

the class TranslationAdapter method highlightAyah.

private void highlightAyah(int ayahId, boolean notify) {
    if (ayahId != highlightedAyah) {
        int count = 0;
        int startPosition = -1;
        for (int i = 0, size = this.data.size(); i < size; i++) {
            QuranAyahInfo item = this.data.get(i).ayahInfo;
            if (item.ayahId == ayahId) {
                if (count == 0) {
                    startPosition = i;
                }
                count++;
            } else if (count > 0) {
                break;
            }
        }
        // highlight the newly highlighted ayah
        if (count > 0 && notify) {
            int startChangeCount = count;
            int startChangeRange = startPosition;
            if (highlightedRowCount > 0) {
                // merge the requests for notifyItemRangeChanged when we're either the next ayah
                if (highlightedStartPosition + highlightedRowCount + 1 == startPosition) {
                    startChangeRange = highlightedStartPosition;
                    startChangeCount = startChangeCount + highlightedRowCount;
                } else if (highlightedStartPosition - 1 == startPosition + count) {
                    // ... or when we're the previous ayah
                    startChangeCount = startChangeCount + highlightedRowCount;
                } else {
                    // otherwise, unhighlight
                    notifyItemRangeChanged(highlightedStartPosition, highlightedRowCount, HIGHLIGHT_CHANGE);
                }
            }
            // and update rows to be highlighted
            notifyItemRangeChanged(startChangeRange, startChangeCount, HIGHLIGHT_CHANGE);
            recyclerView.smoothScrollToPosition(startPosition + count);
        }
        highlightedAyah = ayahId;
        highlightedStartPosition = startPosition;
        highlightedRowCount = count;
    }
}
Also used : QuranAyahInfo(com.quran.labs.androidquran.common.QuranAyahInfo)

Example 7 with QuranAyahInfo

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

the class TranslationView method setVerses.

public void setVerses(@NonNull QuranInfo quranInfo, @NonNull String[] translations, @NonNull List<QuranAyahInfo> verses) {
    this.translations = translations;
    List<TranslationViewRow> rows = new ArrayList<>();
    int currentSura = -1;
    boolean wantTranslationHeaders = translations.length > 1;
    for (int i = 0, size = verses.size(); i < size; i++) {
        QuranAyahInfo verse = verses.get(i);
        int sura = verse.sura;
        if (sura != currentSura) {
            rows.add(new TranslationViewRow(TranslationViewRow.Type.SURA_HEADER, verse, quranInfo.getSuraName(getContext(), sura, true)));
            currentSura = sura;
        }
        if (verse.ayah == 1 && sura != 1 && sura != 9) {
            rows.add(new TranslationViewRow(TranslationViewRow.Type.BASMALLAH, verse));
        }
        rows.add(new TranslationViewRow(TranslationViewRow.Type.VERSE_NUMBER, verse));
        if (verse.arabicText != null) {
            rows.add(new TranslationViewRow(TranslationViewRow.Type.QURAN_TEXT, verse));
        }
        // added this to guard against a crash that happened when verse.texts was empty
        int verseTexts = verse.texts.size();
        for (int j = 0; j < translations.length; j++) {
            String text = verseTexts > j ? verse.texts.get(j) : "";
            if (!TextUtils.isEmpty(text)) {
                if (wantTranslationHeaders) {
                    rows.add(new TranslationViewRow(TranslationViewRow.Type.TRANSLATOR, verse, translations[j]));
                }
                rows.add(new TranslationViewRow(TranslationViewRow.Type.TRANSLATION_TEXT, verse, text));
            }
        }
        rows.add(new TranslationViewRow(TranslationViewRow.Type.SPACER, verse));
    }
    translationAdapter.setData(rows);
    translationAdapter.notifyDataSetChanged();
}
Also used : QuranAyahInfo(com.quran.labs.androidquran.common.QuranAyahInfo) ArrayList(java.util.ArrayList)

Example 8 with QuranAyahInfo

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

the class TranslationAdapter method selectVerseRows.

private boolean selectVerseRows(View view) {
    int position = recyclerView.getChildAdapterPosition(view);
    if (position != RecyclerView.NO_POSITION && onVerseSelectedListener != null) {
        QuranAyahInfo ayahInfo = data.get(position).ayahInfo;
        highlightAyah(ayahInfo.ayahId, true);
        onVerseSelectedListener.onVerseSelected(ayahInfo);
        return true;
    }
    return false;
}
Also used : QuranAyahInfo(com.quran.labs.androidquran.common.QuranAyahInfo)

Example 9 with QuranAyahInfo

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

the class BaseTranslationPresenterTest method testCombineAyahDataArabicEmptyTranslations.

@Test
public void testCombineAyahDataArabicEmptyTranslations() {
    VerseRange verseRange = new VerseRange(1, 1, 1, 2, 2);
    List<QuranText> arabic = Arrays.asList(new QuranText(1, 1, "first ayah"), new QuranText(1, 2, "second ayah"));
    List<QuranAyahInfo> info = presenter.combineAyahData(verseRange, arabic, new ArrayList<>());
    assertThat(info).hasSize(2);
    assertThat(info.get(0).sura).isEqualTo(1);
    assertThat(info.get(0).ayah).isEqualTo(1);
    assertThat(info.get(0).texts).hasSize(0);
    assertThat(info.get(0).arabicText).isEqualTo("first ayah");
    assertThat(info.get(1).sura).isEqualTo(1);
    assertThat(info.get(1).ayah).isEqualTo(2);
    assertThat(info.get(1).texts).hasSize(0);
    assertThat(info.get(1).arabicText).isEqualTo("second ayah");
}
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)

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