Search in sources :

Example 1 with SuraAyahIterator

use of com.quran.labs.androidquran.data.SuraAyahIterator 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

NonNull (android.support.annotation.NonNull)1 QuranText (com.quran.labs.androidquran.common.QuranText)1 SuraAyah (com.quran.labs.androidquran.data.SuraAyah)1 SuraAyahIterator (com.quran.labs.androidquran.data.SuraAyahIterator)1