Skip to content

Commit

Permalink
Fix: Scroll state in retained in the partial translation mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ikerfah committed Mar 30, 2024
1 parent 149bdbb commit 089106c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class InlineTranslationPresenter @Inject constructor(
) {
private val scope = MainScope()
private var cachedTranslations = emptyList<LocalTranslation>()
private var lastVerseRange: VerseRange? = null

init {
translationListPresenter.translations()
Expand All @@ -39,10 +40,12 @@ class InlineTranslationPresenter @Inject constructor(
}

suspend fun refresh(verseRange: VerseRange) {
val ayahHasBeenChanged = verseRange != lastVerseRange
val result = withContext(Dispatchers.IO) {
getVerses(false, getTranslations(quranSettings), verseRange)
}
translationScreen?.setVerses(result.translations, result.ayahInformation)
translationScreen?.setVerses(result.translations, result.ayahInformation, ayahHasBeenChanged)
lastVerseRange = verseRange
}

override fun bind(what: TranslationScreen) {
Expand All @@ -52,7 +55,7 @@ class InlineTranslationPresenter @Inject constructor(
}

interface TranslationScreen {
fun setVerses(translations: Array<LocalTranslation>, verses: List<QuranAyahInfo>)
fun setVerses(translations: Array<LocalTranslation>, verses: List<QuranAyahInfo>, ayahHasBeenChanged: Boolean)
fun onTranslationsUpdated(translations: List<LocalTranslation>)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,17 @@ class AyahTranslationFragment : AyahActionFragment(), TranslationScreen {
}
}

override fun setVerses(translations: Array<LocalTranslation>, verses: List<QuranAyahInfo>) {
override fun setVerses(translations: Array<LocalTranslation>, verses: List<QuranAyahInfo>, ayahHasBeenChanged: Boolean) {
progressBar.visibility = View.GONE
if (verses.isNotEmpty()) {
emptyState.visibility = View.GONE
translationControls.visibility = View.VISIBLE
translator.visibility = View.VISIBLE
translationView.visibility = View.VISIBLE
translationView.setAyahs(translations, verses)
if (ayahHasBeenChanged) {
translationView.resetScroll()
}
} else {
emptyState.visibility = View.VISIBLE
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,13 @@ class InlineTranslationView @JvmOverloads constructor(
i++
}
addFooterSpacer()
scrollTo(0, 0)
}
}

fun resetScroll() {
scrollTo(0, 0)
}

private fun addFooterSpacer() {
val params = LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT, footerSpacerHeight
Expand Down

0 comments on commit 089106c

Please sign in to comment.