Recent Read Controller is no longer Rx

Unfortunately to fix #72, an rx observer is needed since the reader adds to the db after the recents is back in view
This commit is contained in:
Jay 2020-02-09 22:16:08 -08:00
parent 01039219bc
commit 9e36dccf4d
2 changed files with 7 additions and 6 deletions

View file

@ -105,16 +105,18 @@ class RecentlyReadController(bundle: Bundle? = null) : BaseController(bundle),
* *
* @param mangaHistory list of manga history * @param mangaHistory list of manga history
*/ */
fun onNextManga(mangaHistory: List<RecentlyReadItem>) { fun onNextManga(mangaHistory: List<RecentlyReadItem>, freshList:Boolean = false) {
val adapter = adapter ?: return val adapter = adapter ?: return
adapter.updateDataSet(mangaHistory) adapter.updateDataSet(mangaHistory)
adapter.onLoadMoreComplete(null) adapter.onLoadMoreComplete(null)
if (recentItems == null) if (recentItems == null || adapter.endlessTargetCount == 1)
resetProgressItem() resetProgressItem()
else if (freshList && mangaHistory.size == recentItems!!.size)
onAddPageError()
recentItems = mangaHistory.toMutableList() recentItems = mangaHistory.toMutableList()
} }
fun onAddPageError() { private fun onAddPageError() {
adapter?.onLoadMoreComplete(null) adapter?.onLoadMoreComplete(null)
adapter?.endlessTargetCount = 1 adapter?.endlessTargetCount = 1
} }

View file

@ -55,14 +55,13 @@ class RecentlyReadPresenter(private val view: RecentlyReadController) {
} }
fun observe() { fun observe() {
readerSubscription?.unsubscribe()
val cal = Calendar.getInstance() val cal = Calendar.getInstance()
cal.time = Date() cal.time = Date()
cal.add(Calendar.YEAR, -50) cal.add(Calendar.YEAR, -50)
readerSubscription = db.getRecentMangaLimit(cal.time, lastCount, "").asRxObservable().map { db.getRecentMangaLimit(cal.time, lastCount, "").asRxObservable().map {
val items = it.map(::RecentlyReadItem) val items = it.map(::RecentlyReadItem)
launchUI { launchUI {
view.onNextManga(items) view.onNextManga(items, false)
} }
}.observeOn(Schedulers.io()).skip(1).take(1).subscribe() }.observeOn(Schedulers.io()).skip(1).take(1).subscribe()
} }