mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-09 07:16:04 -04:00
#1972 more change request fixes
This commit is contained in:
parent
8aed396a59
commit
da211ddf26
@ -20,7 +20,6 @@ package org.kiwix.kiwixmobile.core.history
|
|||||||
import android.util.Log
|
import android.util.Log
|
||||||
import io.reactivex.Observable
|
import io.reactivex.Observable
|
||||||
import io.reactivex.Scheduler
|
import io.reactivex.Scheduler
|
||||||
import io.reactivex.disposables.Disposable
|
|
||||||
import org.kiwix.kiwixmobile.core.base.BasePresenter
|
import org.kiwix.kiwixmobile.core.base.BasePresenter
|
||||||
import org.kiwix.kiwixmobile.core.data.DataSource
|
import org.kiwix.kiwixmobile.core.data.DataSource
|
||||||
import org.kiwix.kiwixmobile.core.di.qualifiers.Computation
|
import org.kiwix.kiwixmobile.core.di.qualifiers.Computation
|
||||||
@ -37,23 +36,23 @@ internal class HistoryPresenter @Inject constructor(
|
|||||||
@param:Computation private val computation: Scheduler
|
@param:Computation private val computation: Scheduler
|
||||||
) : BasePresenter<View>(), Presenter {
|
) : BasePresenter<View>(), Presenter {
|
||||||
|
|
||||||
private var disposable: Disposable? = null
|
|
||||||
|
|
||||||
override fun loadHistory(showHistoryCurrentBook: Boolean) {
|
override fun loadHistory(showHistoryCurrentBook: Boolean) {
|
||||||
val immutableDisposable = dataSource.getDateCategorizedHistory(showHistoryCurrentBook).subscribe(
|
dataSource.getDateCategorizedHistory(showHistoryCurrentBook)
|
||||||
|
.subscribe(
|
||||||
{ histories: List<HistoryListItem> -> view?.updateHistoryList(histories) },
|
{ histories: List<HistoryListItem> -> view?.updateHistoryList(histories) },
|
||||||
{ e: Throwable -> Log.e("HistoryPresenter", "Failed to load history.", e) }
|
{ e: Throwable -> Log.e("HistoryPresenter", "Failed to load history.", e) }
|
||||||
)
|
).let {
|
||||||
disposable?.takeIf { !it.isDisposed }?.dispose()
|
it.takeIf { !it.isDisposed }?.dispose()
|
||||||
compositeDisposable.add(immutableDisposable)
|
compositeDisposable.add(it)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun filterHistory(historyList: List<HistoryListItem>, newText: String) {
|
override fun filterHistory(historyList: List<HistoryListItem>, newText: String) {
|
||||||
compositeDisposable.add(Observable.fromCallable{ historyList.filter { item ->
|
compositeDisposable.add(Observable.fromCallable {
|
||||||
item is HistoryItem &&
|
historyList.filterIsInstance<HistoryItem>().filter { item ->
|
||||||
item.historyTitle.toLowerCase(Locale.getDefault())
|
item.historyTitle.toLowerCase(Locale.getDefault())
|
||||||
.contains(newText.toLowerCase(Locale.getDefault()))
|
.contains(newText.toLowerCase(Locale.getDefault()))
|
||||||
}}
|
} }
|
||||||
.subscribeOn(computation)
|
.subscribeOn(computation)
|
||||||
.observeOn(mainThread)
|
.observeOn(mainThread)
|
||||||
.subscribe(
|
.subscribe(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user