Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Scroll state in retained in the partial translation mode #2643

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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