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()
preferences.showRecentsDownloads().register { showDownloads = it }
preferences.showRecentsRemHistory().register { showRemoveHistory = it }
preferences.showTitleFirstInRecents().register { showTitleFirst = it }
}
private fun <T> Preference<T>.register(onChanged: (T) -> Unit) {
asFlow()
.onEach {
showDownloads = it
notifyDataSetChanged()
}
.launchIn(delegate.scope())
preferences.showRecentsRemHistory()
.asFlow()
.onEach {
showRemoveHistory = it
notifyDataSetChanged()
}
.launchIn(delegate.scope())
preferences.showTitleFirstInRecents()
.asFlow()
.onEach {
showTitleFirst = it
onChanged(it)
notifyDataSetChanged()
}
.launchIn(delegate.scope())

View File

@ -149,9 +149,7 @@ class RecentsController(bundle: Bundle? = null) :
presenter.onCreate()
if (presenter.recentItems.isNotEmpty()) {
adapter.updateDataSet(presenter.recentItems)
if (presenter.viewType > 0) {
adapter.addScrollableHeader(presenter.generalHeader)
}
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)