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;
}
}
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();
}
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;
}
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");
}
Aggregations