8000 Fix juz' look-ahead using stale page bounds in getLastAyahToPlay by m86hussein · Pull Request #4026 · quran/quran_android · GitHub
[go: up one dir, main page]

Skip to content

Fix juz' look-ahead using stale page bounds in getLastAyahToPlay - #4026

Open
m86hussein wants to merge 1 commit into
quran:mainfrom
m86hussein:fix/juz-lookahead-stale-page-bounds
Open

m86hussein wants to merge 1 commit into
quran:mainfrom
m86hussein:fix/juz-lookahead-stale-page-bounds

Conversation

@m86hussein
Copy link
Copy Markdown
Contributor

What

Fix juz' look-ahead in AudioUtils.getLastAyahToPlay reading stale page bounds.

Why

getLastAyahToPlay uses pageLastSura / pageLastAyah in its juz' (LookAheadAmount.JUZ) branch to decide whether the current page already spills into the next juz':

val endJuz = quranInfo.getQuarterByIndex(juz * 8)
if (pageLastSura > endJuz.sura) {
  return getQuarterForNextJuz(juz)
} else if (pageLastSura == endJuz.sura && pageLastAyah > endJuz.ayah) {
  return getQuarterForNextJuz(juz)
}
return SuraAyah(endJuz.sura, endJuz.ayah)

A 2020 refactor (#1386) moved the computation of pageLastSura / pageLastAyah into the page-mode (else) branch only. In juz' mode they therefore kept their initial 114 / 6 defaults, so pageLastSura > endJuz.sura (114 > endJuz.sura) was always true. As a result, selecting "play by juz'" always ran past the current juz' into the following one (getQuarterForNextJuz) instead of stopping at the juz' boundary.

Example: starting on page 5 (juz' 1), playback should stop at the start of juz' 2 (2:142), but it stopped at the start of juz' 3 (2:253).

Change

Compute the page's last sura/ayah (via getVerseRangeForPage, exactly as the page-mode branch already did) before the mode branches, so the juz' branch sees the real page bounds. Page and sura modes are unaffected.

Tests

Added juz' look-ahead tests to AudioUtilsTest:

  • page 5 (juz' 1) stops at 2:142
  • page 50 (juz' 3) stops at 3:93
  • page 600 (juz' 30) stops at 114:6

The first two fail against the previous code and pass with the fix. Full AudioUtilsTest suite (9 tests) passes.

getLastAyahToPlay read pageLastSura/pageLastAyah in its juz' branch, but a 2020 refactor (quran#1386) moved the computation of those values into the page-mode branch only. In juz' mode they stayed at their 114/6 defaults, so 'pageLastSura > endJuz.sura' was always true and playback always jumped to the next juz' (getQuarterForNextJuz) instead of stopping at the current juz' boundary. Compute the page's last sura/ayah before the mode branches, restoring the original behavior. Added juz' look-ahead tests to AudioUtilsTest.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0