Fixes to theme changes, and other page loading in recents

This commit is contained in:
Jays2Kings 2021-04-07 03:50:25 -04:00
parent 3c10e7975b
commit 40a9b2c421
2 changed files with 24 additions and 16 deletions

View File

@ -121,7 +121,6 @@ class RecentsController(bundle: Bundle? = null) :
adapter.itemTouchHelperCallback.setSwipeFlags( adapter.itemTouchHelperCallback.setSwipeFlags(
ItemTouchHelper.LEFT ItemTouchHelper.LEFT
) )
resetProgressItem()
val attrsArray = intArrayOf(android.R.attr.actionBarSize) val attrsArray = intArrayOf(android.R.attr.actionBarSize)
val array = view.context.obtainStyledAttributes(attrsArray) val array = view.context.obtainStyledAttributes(attrsArray)
val appBarHeight = array.getDimensionPixelSize(0, 0) val appBarHeight = array.getDimensionPixelSize(0, 0)
@ -478,7 +477,7 @@ class RecentsController(bundle: Bundle? = null) :
setOnQueryTextChangeListener(searchView) { setOnQueryTextChangeListener(searchView) {
if (presenter.query != it) { if (presenter.query != it) {
presenter.query = it ?: return@setOnQueryTextChangeListener false presenter.query = it ?: return@setOnQueryTextChangeListener false
resetProgressItem() onAddPageError()
refresh() refresh()
} }
true true
@ -554,17 +553,14 @@ class RecentsController(bundle: Bundle? = null) :
private fun onAddPageError() { private fun onAddPageError() {
adapter.onLoadMoreComplete(null) adapter.onLoadMoreComplete(null)
adapter.endlessTargetCount = 0
adapter.setEndlessScrollListener(null, progressItem!!)
adapter.setEndlessProgressItem(null)
} }
/** /**
* Sets a new progress item and reenables the scroll listener. * Sets a new progress item and reenables the scroll listener.
*/ */
private fun resetProgressItem() { private fun resetProgressItem() {
adapter.onLoadMoreComplete(null)
progressItem = ProgressItem() progressItem = ProgressItem()
adapter.endlessTargetCount = 0
adapter.setEndlessScrollListener(this, progressItem!!) adapter.setEndlessScrollListener(this, progressItem!!)
} }
} }

View File

@ -66,6 +66,17 @@ class RecentsPresenter(
} }
} }
init {
preferences.showReadInAllRecents()
.asFlow()
.drop(1)
.onEach {
page = 0
getRecents()
}
.launchIn(scope)
}
fun onCreate() { fun onCreate() {
downloadManager.addListener(this) downloadManager.addListener(this)
LibraryUpdateService.setListener(this) LibraryUpdateService.setListener(this)
@ -76,13 +87,6 @@ class RecentsPresenter(
lastRecents = null lastRecents = null
} }
getRecents() getRecents()
preferences.showReadInAllRecents()
.asFlow()
.drop(1)
.onEach {
getRecents()
}
.launchIn(scope)
} }
fun getRecents(updatePageCount: Boolean = false, retryCount: Int = 0, itemCount: Int = 0) { fun getRecents(updatePageCount: Boolean = false, retryCount: Int = 0, itemCount: Int = 0) {
@ -137,7 +141,7 @@ class RecentsPresenter(
time = Date() time = Date()
when { when {
query.isNotEmpty() -> add(Calendar.YEAR, -50) query.isNotEmpty() -> add(Calendar.YEAR, -50)
isUngrouped -> add(Calendar.MONTH, -1) isUngrouped -> add(Calendar.MONTH, -(page + 1))
else -> add(Calendar.DAY_OF_YEAR, -1) else -> add(Calendar.DAY_OF_YEAR, -1)
} }
} }
@ -179,6 +183,14 @@ class RecentsPresenter(
it.history.last_read it.history.last_read
}.distinctBy { }.distinctBy {
if (query.isEmpty() && viewType != VIEW_TYPE_ONLY_HISTORY) it.manga.id else it.chapter.id if (query.isEmpty() && viewType != VIEW_TYPE_ONLY_HISTORY) it.manga.id else it.chapter.id
}.filter { mch ->
if (page > 0) {
if (query.isEmpty() && viewType != VIEW_TYPE_ONLY_HISTORY) {
recentItems.none { mch.manga.id == it.mch.manga.id }
} else {
recentItems.none { mch.chapter.id == it.mch.chapter.id }
}
} else true
} }
val pairs = mangaList.mapNotNull { val pairs = mangaList.mapNotNull {
val chapter = when { val chapter = when {
@ -252,9 +264,9 @@ class RecentsPresenter(
} }
val newCount = itemCount + newItems.size val newCount = itemCount + newItems.size
val hasNewItems = newItems.isNotEmpty() val hasNewItems = newItems.isNotEmpty()
if (newCount < 25 && viewType != VIEW_TYPE_GROUP_ALL && query.isEmpty() && !limit) { if (updatePageCount && newCount < 25 && viewType != VIEW_TYPE_GROUP_ALL && query.isEmpty() && !limit) {
page++ page++
getRecents(true, retryCount + (if (hasNewItems) 0 else 1), newCount) runRecents(oldQuery, true, retryCount + (if (hasNewItems) 0 else 1), newCount)
return return
} }
if (!limit) { if (!limit) {