Skip to content

Commit

Permalink
Fix incorrect ayah highlight during selection
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmedre committed Mar 2, 2022
1 parent d6bc037 commit ff106ea
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,17 +173,12 @@ class QuranDisplayData @Inject constructor(private val quranInfo: QuranInfo) {
return context.getString(R.string.quran_sura_title, getSuraNameFromPage(context, page))
}

fun getAyahKeysOnPage(page: Int, lowerBound: SuraAyah?, upperBound: SuraAyah?): Set<String> {
fun getAyahKeysOnPage(page: Int): Set<String> {
val ayahKeys: MutableSet<String> = LinkedHashSet()
val bounds = quranInfo.getPageBounds(page)
var start = SuraAyah(bounds[0], bounds[1])
var end = SuraAyah(bounds[2], bounds[3])
if (lowerBound != null) {
start = SuraAyah.max(start, lowerBound)
}
if (upperBound != null) {
end = SuraAyah.min(end, upperBound)
}
val start = SuraAyah(bounds[0], bounds[1])
val end = SuraAyah(bounds[2], bounds[3])

val iterator = SuraAyahIterator(quranInfo, start, end)
while (iterator.next()) {
ayahKeys.add(iterator.sura.toString() + ":" + iterator.ayah.toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,12 @@ class SuraAyahIterator(
}
return true
}

fun asSet(): Set<String> {
val suraAyahSet = mutableSetOf<String>()
while (next()) {
suraAyahSet.add("$sura:$ayah")
}
return suraAyahSet
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import com.quran.data.model.selection.startSuraAyah
import com.quran.labs.androidquran.common.LocalTranslation
import com.quran.labs.androidquran.common.QuranAyahInfo
import com.quran.labs.androidquran.data.QuranDisplayData
import com.quran.labs.androidquran.data.SuraAyahIterator
import com.quran.labs.androidquran.presenter.Presenter
import com.quran.labs.androidquran.presenter.quran.ayahtracker.AyahTrackerPresenter.AyahInteractionHandler
import com.quran.labs.androidquran.ui.PagerActivity
Expand Down Expand Up @@ -111,13 +112,15 @@ class AyahTrackerPresenter @Inject constructor(
highlightAyah(suraAyah.sura, suraAyah.ayah, -1, HighlightTypes.SELECTION, false)
}
is AyahSelection.AyahRange -> {
val highlightAyatIterator =
SuraAyahIterator(quranInfo, ayahSelection.startSuraAyah, ayahSelection.endSuraAyah)
val highlightedAyat = highlightAyatIterator.asSet()
items.forEach {
val elements = quranDisplayData.getAyahKeysOnPage(
it.page,
ayahSelection.startSuraAyah,
ayahSelection.endSuraAyah
)
it.onHighlightAyat(it.page, elements, HighlightTypes.SELECTION)
val pageAyat = quranDisplayData.getAyahKeysOnPage(it.page)
val elements = pageAyat.intersect(highlightedAyat)
if (elements.isNotEmpty()) {
it.onHighlightAyat(it.page, elements, HighlightTypes.SELECTION)
}
}
}
else -> { /* nothing is selected, and we already cleared */ }
Expand Down

0 comments on commit ff106ea

Please sign in to comment.