-
Notifications
You must be signed in to change notification settings - Fork 892
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Observe stream of translations in PagerActivity
This patch updates PagerActivity and the InlineTranslations functionality to observe the list of translations as they are updated from the database. This solves issues like translations not showing up right when they are added without returning to the menu and coming back. Fixes #2460.
- Loading branch information
Showing
12 changed files
with
157 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 0 additions & 60 deletions
60
...in/java/com/quran/labs/androidquran/presenter/translation/InlineTranslationPresenter.java
This file was deleted.
Oops, something went wrong.
66 changes: 66 additions & 0 deletions
66
...main/java/com/quran/labs/androidquran/presenter/translation/InlineTranslationPresenter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.quran.labs.androidquran.presenter.translation | ||
|
||
import com.quran.data.core.QuranInfo | ||
import com.quran.data.model.VerseRange | ||
import com.quran.labs.androidquran.common.QuranAyahInfo | ||
import com.quran.labs.androidquran.database.TranslationsDBAdapter | ||
import com.quran.labs.androidquran.model.translation.TranslationModel | ||
import com.quran.labs.androidquran.presenter.translationlist.TranslationListPresenter | ||
import com.quran.labs.androidquran.util.QuranSettings | ||
import com.quran.labs.androidquran.util.TranslationUtil | ||
import com.quran.mobile.translation.model.LocalTranslation | ||
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers | ||
import io.reactivex.rxjava3.observers.DisposableSingleObserver | ||
import kotlinx.coroutines.MainScope | ||
import kotlinx.coroutines.flow.launchIn | ||
import kotlinx.coroutines.flow.onEach | ||
import javax.inject.Inject | ||
|
||
class InlineTranslationPresenter @Inject constructor( | ||
translationModel: TranslationModel, | ||
dbAdapter: TranslationsDBAdapter, | ||
translationUtil: TranslationUtil, | ||
private val quranSettings: QuranSettings, | ||
private val translationListPresenter: TranslationListPresenter, | ||
quranInfo: QuranInfo | ||
) : BaseTranslationPresenter<InlineTranslationPresenter.TranslationScreen>( | ||
translationModel, dbAdapter, translationUtil, quranInfo | ||
) { | ||
private val scope = MainScope() | ||
private var cachedTranslations = emptyList<LocalTranslation>() | ||
|
||
init { | ||
translationListPresenter.translations() | ||
.onEach { translations -> | ||
cachedTranslations = translations | ||
translationScreen?.onTranslationsUpdated(translations) | ||
} | ||
.launchIn(scope) | ||
} | ||
|
||
fun refresh(verseRange: VerseRange) { | ||
disposable?.dispose() | ||
disposable = getVerses(false, getTranslations(quranSettings), verseRange) | ||
.observeOn(AndroidSchedulers.mainThread()) | ||
.subscribeWith(object : DisposableSingleObserver<ResultHolder>() { | ||
override fun onSuccess(result: ResultHolder) { | ||
translationScreen?.setVerses(result.translations, result.ayahInformation) | ||
} | ||
|
||
override fun onError(e: Throwable) {} | ||
}) | ||
} | ||
|
||
override fun bind(what: TranslationScreen) { | ||
super.bind(what) | ||
val translations = cachedTranslations | ||
if (translations.isNotEmpty()) { | ||
what.onTranslationsUpdated(translations) | ||
} | ||
} | ||
|
||
interface TranslationScreen { | ||
fun setVerses(translations: Array<LocalTranslation>, verses: List<QuranAyahInfo>) | ||
fun onTranslationsUpdated(translations: List<LocalTranslation>) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.