mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-23 15:41:52 +01:00
Refactoring RecentMangaAdapter + removing recents header while searching
This commit is contained in:
parent
0545780ae9
commit
f264a69626
@ -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())
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user