diff --git a/app/src/main/java/com/quran/labs/androidquran/presenter/translation/InlineTranslationPresenter.kt b/app/src/main/java/com/quran/labs/androidquran/presenter/translation/InlineTranslationPresenter.kt index 390b38220a..9fb839adc4 100644 --- a/app/src/main/java/com/quran/labs/androidquran/presenter/translation/InlineTranslationPresenter.kt +++ b/app/src/main/java/com/quran/labs/androidquran/presenter/translation/InlineTranslationPresenter.kt @@ -28,6 +28,7 @@ class InlineTranslationPresenter @Inject constructor( ) { private val scope = MainScope() private var cachedTranslations = emptyList() + private var lastVerseRange: VerseRange? = null init { translationListPresenter.translations() @@ -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) { @@ -52,7 +55,7 @@ class InlineTranslationPresenter @Inject constructor( } interface TranslationScreen { - fun setVerses(translations: Array, verses: List) + fun setVerses(translations: Array, verses: List, ayahHasBeenChanged: Boolean) fun onTranslationsUpdated(translations: List) } } diff --git a/app/src/main/java/com/quran/labs/androidquran/ui/fragment/AyahTranslationFragment.kt b/app/src/main/java/com/quran/labs/androidquran/ui/fragment/AyahTranslationFragment.kt index 5e4ec0da1b..ac13ad1256 100644 --- a/app/src/main/java/com/quran/labs/androidquran/ui/fragment/AyahTranslationFragment.kt +++ b/app/src/main/java/com/quran/labs/androidquran/ui/fragment/AyahTranslationFragment.kt @@ -163,7 +163,7 @@ class AyahTranslationFragment : AyahActionFragment(), TranslationScreen { } } - override fun setVerses(translations: Array, verses: List) { + override fun setVerses(translations: Array, verses: List, ayahHasBeenChanged: Boolean) { progressBar.visibility = View.GONE if (verses.isNotEmpty()) { emptyState.visibility = View.GONE @@ -171,6 +171,9 @@ class AyahTranslationFragment : AyahActionFragment(), TranslationScreen { translator.visibility = View.VISIBLE translationView.visibility = View.VISIBLE translationView.setAyahs(translations, verses) + if (ayahHasBeenChanged) { + translationView.resetScroll() + } } else { emptyState.visibility = View.VISIBLE } diff --git a/app/src/main/java/com/quran/labs/androidquran/view/InlineTranslationView.kt b/app/src/main/java/com/quran/labs/androidquran/view/InlineTranslationView.kt index dd394e6436..8f447b24e1 100644 --- a/app/src/main/java/com/quran/labs/androidquran/view/InlineTranslationView.kt +++ b/app/src/main/java/com/quran/labs/androidquran/view/InlineTranslationView.kt @@ -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