Skip to content

Instantly share code, notes, and snippets.

@EfeBudak
Created June 28, 2018 14:30
Show Gist options
  • Save EfeBudak/73ff2762fe5a47069e9ca74fc65c90b0 to your computer and use it in GitHub Desktop.
Save EfeBudak/73ff2762fe5a47069e9ca74fc65c90b0 to your computer and use it in GitHub Desktop.
override fun start() {
itemDBObservable = itemDao.getAllItems()
compositeDisposable.clear()
compositeDisposable += itemDBObservable
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.scan { previousList: List<Item>, newList: List<Item> ->
val newItems = newList - previousList
if (previousList.isNotEmpty() && newItems.isNotEmpty()) {
showReturnToTopButton()
}
newList
}
.subscribeBy {
updateItemList(it)
}
}
fun updateItemList(itemList: List<Item>) = itemAdapter.submitList(itemList)
fun showReturnToTopButton() {
showReturnToTopButton = true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment