#1972 more change request fixes

This commit is contained in:
Frans-Lukas 2020-04-10 16:36:57 +02:00
parent 8aed396a59
commit da211ddf26

View File

@ -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(