mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2025-01-11 15:39:08 +01:00
More fixes to category header
This commit is contained in:
parent
747fa81fcd
commit
5339eccb3f
@ -52,7 +52,7 @@ class LibraryCategoryAdapter(val libraryListener: LibraryListener) :
|
||||
*/
|
||||
fun indexOf(categoryOrder: Int): Int {
|
||||
return currentItems.indexOfFirst {
|
||||
if (it is LibraryHeaderItem) it.category.order == categoryOrder
|
||||
if (it is LibraryHeaderItem) it.gCategory().order == categoryOrder
|
||||
else false }
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,8 @@ import eu.kanade.tachiyomi.util.view.invisible
|
||||
import eu.kanade.tachiyomi.util.view.visible
|
||||
import kotlinx.android.synthetic.main.library_category_header_item.view.*
|
||||
|
||||
class LibraryHeaderItem(val category: Category) : AbstractHeaderItem<LibraryHeaderItem.Holder>() {
|
||||
class LibraryHeaderItem(private val categoryF: (Int) -> Category, val catId: Int) :
|
||||
AbstractHeaderItem<LibraryHeaderItem.Holder>() {
|
||||
|
||||
override fun getLayoutRes(): Int {
|
||||
return R.layout.library_category_header_item
|
||||
@ -42,13 +43,16 @@ class LibraryHeaderItem(val category: Category) : AbstractHeaderItem<LibraryHead
|
||||
position: Int,
|
||||
payloads: MutableList<Any?>?
|
||||
) {
|
||||
holder.bind(this)
|
||||
holder.bind(categoryF(catId))
|
||||
}
|
||||
|
||||
var category:Category = categoryF(catId)
|
||||
fun gCategory():Category = categoryF(catId)
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (other is LibraryHeaderItem) {
|
||||
return category.id == other.category.id
|
||||
return gCategory().id == other.gCategory().id
|
||||
}
|
||||
return false
|
||||
}
|
||||
@ -62,7 +66,7 @@ class LibraryHeaderItem(val category: Category) : AbstractHeaderItem<LibraryHead
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
return -(category.id!!)
|
||||
return -(gCategory().id!!)
|
||||
}
|
||||
|
||||
class Holder(val view: View, private val adapter: LibraryCategoryAdapter) :
|
||||
@ -78,10 +82,10 @@ class LibraryHeaderItem(val category: Category) : AbstractHeaderItem<LibraryHead
|
||||
sortText.setOnClickListener { showCatSortOptions() }
|
||||
}
|
||||
|
||||
fun bind(item: LibraryHeaderItem) {
|
||||
sectionText.text = item.category.name
|
||||
fun bind(category: Category) {
|
||||
sectionText.text = category.name
|
||||
sortText.text = itemView.context.getString(
|
||||
when (item.category.sortingMode()) {
|
||||
when (category.sortingMode()) {
|
||||
LibrarySort.LAST_UPDATED -> R.string.action_sort_last_updated
|
||||
LibrarySort.DRAG_AND_DROP -> R.string.action_sort_drag_and_drop
|
||||
LibrarySort.TOTAL -> R.string.action_sort_total
|
||||
@ -93,11 +97,11 @@ class LibraryHeaderItem(val category: Category) : AbstractHeaderItem<LibraryHead
|
||||
)
|
||||
|
||||
when {
|
||||
item.category.id == -1 -> {
|
||||
category.id == -1 -> {
|
||||
catProgress.gone()
|
||||
updateButton.invisible()
|
||||
}
|
||||
LibraryUpdateService.categoryInQueue(item.category.id) -> {
|
||||
LibraryUpdateService.categoryInQueue(category.id) -> {
|
||||
catProgress.visible()
|
||||
updateButton.invisible()
|
||||
}
|
||||
@ -118,7 +122,7 @@ class LibraryHeaderItem(val category: Category) : AbstractHeaderItem<LibraryHead
|
||||
}
|
||||
private fun showCatSortOptions() {
|
||||
val category =
|
||||
(adapter.getItem(adapterPosition) as? LibraryHeaderItem)?.category ?: return
|
||||
(adapter.getItem(adapterPosition) as? LibraryHeaderItem)?.gCategory() ?: return
|
||||
// Create a PopupMenu, giving it the clicked view for an anchor
|
||||
val popup = PopupMenu(itemView.context, view.category_sort)
|
||||
|
||||
|
@ -81,7 +81,7 @@ class LibraryListController(bundle: Bundle? = null) : LibraryController(bundle),
|
||||
val position =
|
||||
(recycler.layoutManager as LinearLayoutManager).findFirstVisibleItemPosition()
|
||||
val order = when (val item = adapter.getItem(position)) {
|
||||
is LibraryHeaderItem -> item.category.order
|
||||
is LibraryHeaderItem -> item.gCategory().order
|
||||
is LibraryItem -> presenter.categories.find { it.id == item.manga.category }?.order
|
||||
else -> null
|
||||
}
|
||||
@ -249,12 +249,6 @@ class LibraryListController(bundle: Bundle? = null) : LibraryController(bundle),
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCatSortChanged(id: Int?) {
|
||||
val catId = (id ?: presenter.categories.find { it.order == activeCategory }?.id)
|
||||
?: return
|
||||
presenter.requestCatSortUpdate(catId)
|
||||
}
|
||||
|
||||
override fun onDestroyActionMode(mode: ActionMode?) {
|
||||
super.onDestroyActionMode(mode)
|
||||
adapter.mode = SelectableAdapter.Mode.SINGLE
|
||||
|
@ -248,7 +248,8 @@ class LibraryPresenter(
|
||||
|
||||
private fun applySort(map: LibraryMap, catId: Int?): LibraryMap {
|
||||
if (catId == null) return map
|
||||
val category = db.getCategories().executeAsBlocking().find { it.id == catId } ?: return map
|
||||
val category = if (catId == 0) createDefaultCategory() else
|
||||
db.getCategories().executeAsBlocking().find { it.id == catId } ?: return map
|
||||
allCategories.find { it.id == catId }?.apply {
|
||||
mangaOrder = category.mangaOrder
|
||||
mangaSort = category.mangaSort
|
||||
@ -343,6 +344,10 @@ class LibraryPresenter(
|
||||
}
|
||||
}
|
||||
|
||||
fun getCategory(categoryId: Int): Category {
|
||||
return categories.find { it.id == categoryId } ?: createDefaultCategory()
|
||||
}
|
||||
|
||||
private fun sortCategory(i1: LibraryItem, i2: LibraryItem,
|
||||
lastReadManga: Map<Long, Int>,
|
||||
initCat: Category? = null):
|
||||
@ -430,9 +435,10 @@ class LibraryPresenter(
|
||||
}.groupBy {
|
||||
if (showCategories) it.manga.category else 0
|
||||
}*/
|
||||
val catItemAll = LibraryHeaderItem(Category.createAll(context,
|
||||
val categoryAll = Category.createAll(context,
|
||||
preferences.librarySortingMode().getOrDefault(),
|
||||
preferences.librarySortingAscending().getOrDefault()))
|
||||
preferences.librarySortingAscending().getOrDefault())
|
||||
val catItemAll = LibraryHeaderItem({ categoryAll }, -1)
|
||||
val libraryMap =
|
||||
if (!preferences.libraryAsSingleList().getOrDefault()) {
|
||||
libraryManga.map { manga ->
|
||||
@ -448,8 +454,7 @@ class LibraryPresenter(
|
||||
}.map { entry ->
|
||||
val categoryItem =
|
||||
if (!showCategories) catItemAll else
|
||||
(LibraryHeaderItem(categories.find { entry.key == it.id }
|
||||
?: createDefaultCategory()))
|
||||
(LibraryHeaderItem({ getCategory(it) }, entry.key))
|
||||
entry.value.map {
|
||||
LibraryItem(
|
||||
it, libraryLayout, categoryItem
|
||||
@ -465,7 +470,7 @@ class LibraryPresenter(
|
||||
categories.add(0, createDefaultCategory())
|
||||
|
||||
this.allCategories = categories
|
||||
this.categories = if (!showCategories) arrayListOf(catItemAll.category)
|
||||
this.categories = if (!showCategories) arrayListOf(categoryAll)
|
||||
else categories
|
||||
|
||||
return Library(this.categories, libraryMap)
|
||||
@ -786,7 +791,7 @@ class LibraryPresenter(
|
||||
}
|
||||
else {
|
||||
if (category.id == 0) preferences.defaultMangaOrder().set(category.mangaSort.toString())
|
||||
else Injekt.get<DatabaseHelper>().insertCategory(category).asRxObservable().subscribe()
|
||||
else Injekt.get<DatabaseHelper>().insertCategory(category).executeAsBlocking()
|
||||
requestCatSortUpdate(category.id!!)
|
||||
}
|
||||
}
|
||||
|
@ -13,38 +13,54 @@
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginBottom="4dp"
|
||||
android:ellipsize="end"
|
||||
android:gravity="center|start"
|
||||
android:inputType="none"
|
||||
android:maxLines="1"
|
||||
app:layout_constrainedWidth="true"
|
||||
app:layout_constraintBottom_toBottomOf="@id/update_button"
|
||||
app:layout_constraintEnd_toStartOf="@id/update_button"
|
||||
app:layout_constraintHorizontal_bias="0.0"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintWidth_default="wrap"
|
||||
tools:text="Title" />
|
||||
tools:text="Title dfdsfsfsfsfsfsfs" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/category_sort"
|
||||
android:padding="6dp"
|
||||
android:layout_width="0dp"
|
||||
android:layout_marginBottom="4dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintWidth_default="wrap"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:layout_marginBottom="4dp"
|
||||
android:background="@drawable/square_ripple"
|
||||
android:clickable="true"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:drawableTint="@color/gray_button"
|
||||
android:drawableEnd="@drawable/ic_sort_white_24dp"
|
||||
android:drawablePadding="6dp"
|
||||
android:drawableTint="@color/gray_button"
|
||||
android:ellipsize="none"
|
||||
android:focusable="true"
|
||||
android:gravity="start|center"
|
||||
android:maxLines="3"
|
||||
android:padding="6dp"
|
||||
android:textAppearance="@style/TextAppearance.MaterialComponents.Body2"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:textSize="12sp"
|
||||
android:textStyle="normal"
|
||||
app:layout_constrainedWidth="true"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="1.0"
|
||||
app:layout_constraintStart_toEndOf="@id/space"
|
||||
app:layout_constraintWidth_min="20dp"
|
||||
tools:text="Drag wddf Drop" />
|
||||
|
||||
<Space
|
||||
android:id="@+id/space"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="20dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@id/category_sort"
|
||||
app:layout_constraintStart_toEndOf="@id/update_button"
|
||||
tools:text="Sort by: Recent" />
|
||||
app:layout_constraintWidth_min="1dp" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/update_button"
|
||||
@ -58,20 +74,21 @@
|
||||
android:text="@string/ext_update"
|
||||
android:textColor="?android:attr/colorAccent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@id/space"
|
||||
app:layout_constraintStart_toEndOf="@+id/category_title"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintWidth_default="wrap"
|
||||
app:rippleColor="@color/fullRippleColor" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/cat_progress"
|
||||
android:layout_width="30dp"
|
||||
android:indeterminate="true"
|
||||
android:layout_height="30dp"
|
||||
android:layout_marginStart="0dp"
|
||||
android:layout_marginStart="10dp"
|
||||
android:indeterminate="true"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/category_title"
|
||||
app:layout_constraintHorizontal_bias="0.0"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/update_button"
|
||||
app:layout_constraintStart_toStartOf="@+id/update_button"
|
||||
app:layout_constraintEnd_toEndOf="@id/update_button"
|
||||
app:layout_constraintTop_toTopOf="@+id/update_button" />
|
||||
app:layout_constraintStart_toEndOf="@+id/category_title"
|
||||
app:layout_constraintTop_toTopOf="@+id/category_title" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
@ -5,6 +5,8 @@
|
||||
style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:maxLines="1"
|
||||
android:ellipsize="end"
|
||||
android:gravity="start"
|
||||
android:textSize="20sp"
|
||||
android:textColor="?attr/actionBarTintColor"
|
||||
|
Loading…
x
Reference in New Issue
Block a user