Updating logic of hopper
Also empty categories now show catergory is empty, even if filter is on
This commit is contained in:
parent
6f9a437bb9
commit
45fc923f34
@ -175,16 +175,8 @@ class LibraryController(
|
||||
category_hopper_frame.translationY += dy
|
||||
category_hopper_frame.translationY =
|
||||
category_hopper_frame.translationY.coerceIn(0f, 60f.dpToPx)
|
||||
up_category.alpha = if (!recycler.canScrollVertically(-1)) {
|
||||
0.25f
|
||||
} else {
|
||||
1f
|
||||
}
|
||||
down_category.alpha = if (!recycler.canScrollVertically(1)) {
|
||||
0.25f
|
||||
} else {
|
||||
1f
|
||||
}
|
||||
up_category.alpha = if (isAtTop()) 0.25f else 1f
|
||||
down_category.alpha = if (isAtBottom()) 0.25f else 1f
|
||||
}
|
||||
if (!filter_bottom_sheet.sheetBehavior.isHidden()) {
|
||||
scrollDistance += abs(dy)
|
||||
@ -249,6 +241,22 @@ class LibraryController(
|
||||
}
|
||||
}
|
||||
|
||||
fun isAtTop(): Boolean {
|
||||
return if (presenter.showAllCategories) {
|
||||
getVisibleHeader() == adapter.headerItems.firstOrNull()
|
||||
} else {
|
||||
getVisibleHeader()?.category?.id == presenter.categories.firstOrNull()?.id
|
||||
}
|
||||
}
|
||||
|
||||
fun isAtBottom(): Boolean {
|
||||
return if (presenter.showAllCategories) {
|
||||
getVisibleHeader() == adapter.headerItems.lastOrNull()
|
||||
} else {
|
||||
getVisibleHeader()?.category?.id == presenter.categories.lastOrNull()?.id
|
||||
}
|
||||
}
|
||||
|
||||
private fun showFilterTip() {
|
||||
if (preferences.shownFilterTutorial().get()) return
|
||||
val activity = activity ?: return
|
||||
@ -381,24 +389,10 @@ class LibraryController(
|
||||
|
||||
category_hopper_frame.gone()
|
||||
down_category.setOnClickListener {
|
||||
val position = getVisibleHeader() ?: return@setOnClickListener
|
||||
val newOffset = adapter.headerItems.indexOf(position) + 1
|
||||
if (newOffset < presenter.categories.size) {
|
||||
val newOrder = (adapter.headerItems[newOffset] as LibraryHeaderItem).category.order
|
||||
scrollToHeader(newOrder)
|
||||
} else {
|
||||
recycler.scrollToPosition(adapter.itemCount - 1)
|
||||
}
|
||||
jumpToNextCategory(true)
|
||||
}
|
||||
up_category.setOnClickListener {
|
||||
val position = getVisibleHeader() ?: return@setOnClickListener
|
||||
val newOffset = adapter.headerItems.indexOf(position) - 1
|
||||
if (newOffset > -1) {
|
||||
val newOrder = (adapter.headerItems[newOffset] as LibraryHeaderItem).category.order
|
||||
scrollToHeader(newOrder)
|
||||
} else {
|
||||
recycler.scrollToPosition(0)
|
||||
}
|
||||
jumpToNextCategory(false)
|
||||
}
|
||||
down_category.setOnLongClickListener {
|
||||
recycler.scrollToPosition(adapter.itemCount - 1)
|
||||
@ -506,6 +500,37 @@ class LibraryController(
|
||||
}
|
||||
}
|
||||
|
||||
private fun jumpToNextCategory(next: Boolean) {
|
||||
val category = getVisibleHeader() ?: return
|
||||
if (presenter.showAllCategories) {
|
||||
val newOffset = adapter.headerItems.indexOf(category) + (if (next) 1 else -1)
|
||||
if (if (!next) {
|
||||
newOffset > -1
|
||||
} else {
|
||||
newOffset < adapter.headerItems.size
|
||||
}) {
|
||||
val newOrder =
|
||||
(adapter.headerItems[newOffset] as LibraryHeaderItem).category.order
|
||||
scrollToHeader(newOrder)
|
||||
} else {
|
||||
recycler.scrollToPosition(if (next) adapter.itemCount - 1 else 0)
|
||||
}
|
||||
} else {
|
||||
val newOffset =
|
||||
presenter.categories.indexOfFirst { presenter.currentCategory == it.id } +
|
||||
(if (next) 1 else -1)
|
||||
if (if (!next) {
|
||||
newOffset > -1
|
||||
} else {
|
||||
newOffset < presenter.categories.size
|
||||
}
|
||||
) {
|
||||
val newOrder = presenter.categories[newOffset].order
|
||||
scrollToHeader(newOrder)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getHeader(): LibraryHeaderItem? {
|
||||
val position =
|
||||
(recycler.layoutManager as LinearLayoutManager).findFirstCompletelyVisibleItemPosition()
|
||||
|
@ -16,11 +16,11 @@ import eu.kanade.tachiyomi.source.SourceManager
|
||||
import eu.kanade.tachiyomi.source.model.SManga
|
||||
import eu.kanade.tachiyomi.source.online.HttpSource
|
||||
import eu.kanade.tachiyomi.ui.library.filter.FilterBottomSheet
|
||||
import eu.kanade.tachiyomi.util.lang.removeArticles
|
||||
import eu.kanade.tachiyomi.util.system.executeOnIO
|
||||
import eu.kanade.tachiyomi.ui.library.filter.FilterBottomSheet.Companion.STATE_EXCLUDE
|
||||
import eu.kanade.tachiyomi.ui.library.filter.FilterBottomSheet.Companion.STATE_IGNORE
|
||||
import eu.kanade.tachiyomi.ui.library.filter.FilterBottomSheet.Companion.STATE_INCLUDE
|
||||
import eu.kanade.tachiyomi.util.lang.removeArticles
|
||||
import eu.kanade.tachiyomi.util.system.executeOnIO
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
@ -110,7 +110,21 @@ class LibraryPresenter(
|
||||
preferences.lastUsedCategory().set(order)
|
||||
val category = categories.find { it.order == order }?.id ?: return
|
||||
currentCategory = category
|
||||
view.onNextLibraryUpdate(sectionedLibraryItems[currentCategory] ?: emptyList())
|
||||
view.onNextLibraryUpdate(
|
||||
sectionedLibraryItems[currentCategory] ?: blankItem()
|
||||
)
|
||||
}
|
||||
|
||||
private fun blankItem(id: Int = currentCategory): List<LibraryItem> {
|
||||
return listOf(
|
||||
LibraryItem(
|
||||
LibraryManga.createBlank(id), LibraryHeaderItem(
|
||||
{ getCategory(id) },
|
||||
id,
|
||||
preferences.alwaysShowSeeker()
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
fun restoreLibrary() {
|
||||
@ -124,7 +138,7 @@ class LibraryPresenter(
|
||||
}
|
||||
view.onNextLibraryUpdate(
|
||||
if (!show) sectionedLibraryItems[currentCategory]
|
||||
?: sectionedLibraryItems[categories.first().id] ?: emptyList()
|
||||
?: sectionedLibraryItems[categories.first().id] ?: blankItem()
|
||||
else libraryItems, true
|
||||
)
|
||||
}
|
||||
@ -141,7 +155,7 @@ class LibraryPresenter(
|
||||
withContext(Dispatchers.Main) {
|
||||
view.onNextLibraryUpdate(
|
||||
if (!show) sectionedLibraryItems[currentCategory]
|
||||
?: sectionedLibraryItems[categories.first().id] ?: emptyList()
|
||||
?: sectionedLibraryItems[categories.first().id] ?: blankItem()
|
||||
else libraryItems, freshStart
|
||||
)
|
||||
}
|
||||
@ -168,15 +182,32 @@ class LibraryPresenter(
|
||||
return items.filter f@{ item ->
|
||||
if (item.manga.status == -1) {
|
||||
return@f sectionedLibraryItems[item.manga.category]?.any {
|
||||
matchesFilters(it, filterDownloaded, filterUnread, filterCompleted,
|
||||
filterTracked, filterMangaType, filterTrackers)
|
||||
matchesFilters(
|
||||
it,
|
||||
filterDownloaded,
|
||||
filterUnread,
|
||||
filterCompleted,
|
||||
filterTracked,
|
||||
filterMangaType,
|
||||
filterTrackers
|
||||
)
|
||||
} ?: false
|
||||
} else if (item.manga.isBlank()) {
|
||||
return@f filterDownloaded == 0 && filterUnread == 0 && filterCompleted == 0 &&
|
||||
filterTracked == 0 && filterMangaType == 0
|
||||
return@f if (showAllCategories) {
|
||||
filterDownloaded == 0 && filterUnread == 0 && filterCompleted == 0 && filterTracked == 0 && filterMangaType == 0
|
||||
} else {
|
||||
true
|
||||
}
|
||||
matchesFilters(item, filterDownloaded, filterUnread, filterCompleted, filterTracked,
|
||||
filterMangaType, filterTrackers)
|
||||
}
|
||||
matchesFilters(
|
||||
item,
|
||||
filterDownloaded,
|
||||
filterUnread,
|
||||
filterCompleted,
|
||||
filterTracked,
|
||||
filterMangaType,
|
||||
filterTrackers
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user