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