diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/history/HistoryPresenter.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/history/HistoryPresenter.kt index 4139156df..54b67d8f6 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/history/HistoryPresenter.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/history/HistoryPresenter.kt @@ -20,6 +20,7 @@ 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 @@ -27,7 +28,6 @@ import org.kiwix.kiwixmobile.core.di.qualifiers.MainThread import org.kiwix.kiwixmobile.core.history.HistoryContract.Presenter import org.kiwix.kiwixmobile.core.history.HistoryContract.View import org.kiwix.kiwixmobile.core.history.HistoryListItem.HistoryItem -import java.util.Locale import javax.inject.Inject internal class HistoryPresenter @Inject constructor( @@ -35,24 +35,27 @@ internal class HistoryPresenter @Inject constructor( @param:MainThread private val mainThread: Scheduler, @param:Computation private val computation: Scheduler ) : BasePresenter(), Presenter { + private var disposable: Disposable? = null override fun loadHistory(showHistoryCurrentBook: Boolean) { + disposable?.takeIf { !it.isDisposed }?.dispose() dataSource.getDateCategorizedHistory(showHistoryCurrentBook) .subscribe( { histories: List -> view?.updateHistoryList(histories) }, { e: Throwable -> Log.e("HistoryPresenter", "Failed to load history.", e) } ).let { - it.takeIf { !it.isDisposed }?.dispose() compositeDisposable.add(it) + disposable = it } } override fun filterHistory(historyList: List, newText: String) { compositeDisposable.add(Observable.fromCallable { - historyList.filterIsInstance().filter { item -> - item.historyTitle.toLowerCase(Locale.getDefault()) - .contains(newText.toLowerCase(Locale.getDefault())) - } } + historyList + .filterIsInstance().filter { item -> + item.historyTitle.contains(newText, true) + } + } .subscribeOn(computation) .observeOn(mainThread) .subscribe(