#1972 implemented some change requests

This commit is contained in:
Frans-Lukas 2020-04-10 16:09:14 +02:00
parent 6d82885f3c
commit 8aed396a59

View File

@ -40,25 +40,20 @@ internal class HistoryPresenter @Inject constructor(
private var disposable: Disposable? = null private var disposable: Disposable? = null
override fun loadHistory(showHistoryCurrentBook: Boolean) { override fun loadHistory(showHistoryCurrentBook: Boolean) {
val d = dataSource.getDateCategorizedHistory(showHistoryCurrentBook).subscribe( val immutableDisposable = 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) }
) )
disposable?.takeIf { !it.isDisposed }?.dispose() disposable?.takeIf { !it.isDisposed }?.dispose()
disposable = d compositeDisposable.add(immutableDisposable)
compositeDisposable.add(d)
} }
override fun filterHistory(historyList: List<HistoryListItem>, newText: String) { override fun filterHistory(historyList: List<HistoryListItem>, newText: String) {
compositeDisposable.add(Observable.just(historyList) compositeDisposable.add(Observable.fromCallable{ historyList.filter { item ->
.flatMapIterable { flatHistoryList: List<HistoryListItem> -> item is HistoryItem &&
flatHistoryList.filter { item -> item.historyTitle.toLowerCase(Locale.getDefault())
item is HistoryItem && .contains(newText.toLowerCase(Locale.getDefault()))
item.historyTitle.toLowerCase(Locale.getDefault()) }}
.contains(newText.toLowerCase(Locale.getDefault()))
}
}
.toList()
.subscribeOn(computation) .subscribeOn(computation)
.observeOn(mainThread) .observeOn(mainThread)
.subscribe( .subscribe(