Refactoring RecentMangaAdapter + removing recents header while searching

This commit is contained in:
Jays2Kings 2021-04-06 21:51:50 -04:00
parent 0545780ae9
commit f264a69626
2 changed files with 12 additions and 22 deletions

View File

@ -1,6 +1,7 @@
package eu.kanade.tachiyomi.ui.recents
import androidx.recyclerview.widget.ItemTouchHelper
import com.tfcporciuncula.flow.Preference
import eu.davidea.flexibleadapter.items.IFlexible
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.ui.manga.chapter.BaseChapterAdapter
@ -32,24 +33,15 @@ class RecentMangaAdapter(val delegate: RecentsInterface) :
init {
setDisplayHeadersAtStartUp(true)
preferences.showRecentsDownloads()
.asFlow()
.onEach {
showDownloads = it
notifyDataSetChanged()
preferences.showRecentsDownloads().register { showDownloads = it }
preferences.showRecentsRemHistory().register { showRemoveHistory = it }
preferences.showTitleFirstInRecents().register { showTitleFirst = it }
}
.launchIn(delegate.scope())
preferences.showRecentsRemHistory()
.asFlow()
private fun <T> Preference<T>.register(onChanged: (T) -> Unit) {
asFlow()
.onEach {
showRemoveHistory = it
notifyDataSetChanged()
}
.launchIn(delegate.scope())
preferences.showTitleFirstInRecents()
.asFlow()
.onEach {
showTitleFirst = it
onChanged(it)
notifyDataSetChanged()
}
.launchIn(delegate.scope())

View File

@ -149,10 +149,8 @@ class RecentsController(bundle: Bundle? = null) :
presenter.onCreate()
if (presenter.recentItems.isNotEmpty()) {
adapter.updateDataSet(presenter.recentItems)
if (presenter.viewType > 0) {
adapter.addScrollableHeader(presenter.generalHeader)
}
}
binding.downloadBottomSheet.dlBottomSheet.onCreate(this)
@ -305,11 +303,11 @@ class RecentsController(bundle: Bundle? = null) :
binding.swipeRefresh.isRefreshing = LibraryUpdateService.isRunning()
adapter.updateItems(recents)
adapter.headerItems.forEach {
if (it != presenter.generalHeader) {
if (it != presenter.generalHeader || presenter.query.isNotEmpty()) {
adapter.removeScrollableHeader(it)
}
}
if (!adapter.headerItems.any { it === presenter.generalHeader }) {
if (presenter.query.isEmpty() && !adapter.headerItems.any { it === presenter.generalHeader }) {
adapter.addScrollableHeader(presenter.generalHeader)
}
adapter.onLoadMoreComplete(null)