More fixes to category header

This commit is contained in:
Jay 2020-02-22 02:24:20 -08:00
parent 747fa81fcd
commit 5339eccb3f
6 changed files with 61 additions and 39 deletions

View File

@ -52,7 +52,7 @@ class LibraryCategoryAdapter(val libraryListener: LibraryListener) :
*/ */
fun indexOf(categoryOrder: Int): Int { fun indexOf(categoryOrder: Int): Int {
return currentItems.indexOfFirst { return currentItems.indexOfFirst {
if (it is LibraryHeaderItem) it.category.order == categoryOrder if (it is LibraryHeaderItem) it.gCategory().order == categoryOrder
else false } else false }
} }

View File

@ -23,7 +23,8 @@ import eu.kanade.tachiyomi.util.view.invisible
import eu.kanade.tachiyomi.util.view.visible import eu.kanade.tachiyomi.util.view.visible
import kotlinx.android.synthetic.main.library_category_header_item.view.* 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 { override fun getLayoutRes(): Int {
return R.layout.library_category_header_item return R.layout.library_category_header_item
@ -42,13 +43,16 @@ class LibraryHeaderItem(val category: Category) : AbstractHeaderItem<LibraryHead
position: Int, position: Int,
payloads: MutableList<Any?>? 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 { override fun equals(other: Any?): Boolean {
if (this === other) return true if (this === other) return true
if (other is LibraryHeaderItem) { if (other is LibraryHeaderItem) {
return category.id == other.category.id return gCategory().id == other.gCategory().id
} }
return false return false
} }
@ -62,7 +66,7 @@ class LibraryHeaderItem(val category: Category) : AbstractHeaderItem<LibraryHead
} }
override fun hashCode(): Int { override fun hashCode(): Int {
return -(category.id!!) return -(gCategory().id!!)
} }
class Holder(val view: View, private val adapter: LibraryCategoryAdapter) : class Holder(val view: View, private val adapter: LibraryCategoryAdapter) :
@ -78,10 +82,10 @@ class LibraryHeaderItem(val category: Category) : AbstractHeaderItem<LibraryHead
sortText.setOnClickListener { showCatSortOptions() } sortText.setOnClickListener { showCatSortOptions() }
} }
fun bind(item: LibraryHeaderItem) { fun bind(category: Category) {
sectionText.text = item.category.name sectionText.text = category.name
sortText.text = itemView.context.getString( sortText.text = itemView.context.getString(
when (item.category.sortingMode()) { when (category.sortingMode()) {
LibrarySort.LAST_UPDATED -> R.string.action_sort_last_updated LibrarySort.LAST_UPDATED -> R.string.action_sort_last_updated
LibrarySort.DRAG_AND_DROP -> R.string.action_sort_drag_and_drop LibrarySort.DRAG_AND_DROP -> R.string.action_sort_drag_and_drop
LibrarySort.TOTAL -> R.string.action_sort_total LibrarySort.TOTAL -> R.string.action_sort_total
@ -93,11 +97,11 @@ class LibraryHeaderItem(val category: Category) : AbstractHeaderItem<LibraryHead
) )
when { when {
item.category.id == -1 -> { category.id == -1 -> {
catProgress.gone() catProgress.gone()
updateButton.invisible() updateButton.invisible()
} }
LibraryUpdateService.categoryInQueue(item.category.id) -> { LibraryUpdateService.categoryInQueue(category.id) -> {
catProgress.visible() catProgress.visible()
updateButton.invisible() updateButton.invisible()
} }
@ -118,7 +122,7 @@ class LibraryHeaderItem(val category: Category) : AbstractHeaderItem<LibraryHead
} }
private fun showCatSortOptions() { private fun showCatSortOptions() {
val category = 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 // Create a PopupMenu, giving it the clicked view for an anchor
val popup = PopupMenu(itemView.context, view.category_sort) val popup = PopupMenu(itemView.context, view.category_sort)

View File

@ -81,7 +81,7 @@ class LibraryListController(bundle: Bundle? = null) : LibraryController(bundle),
val position = val position =
(recycler.layoutManager as LinearLayoutManager).findFirstVisibleItemPosition() (recycler.layoutManager as LinearLayoutManager).findFirstVisibleItemPosition()
val order = when (val item = adapter.getItem(position)) { 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 is LibraryItem -> presenter.categories.find { it.id == item.manga.category }?.order
else -> null 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?) { override fun onDestroyActionMode(mode: ActionMode?) {
super.onDestroyActionMode(mode) super.onDestroyActionMode(mode)
adapter.mode = SelectableAdapter.Mode.SINGLE adapter.mode = SelectableAdapter.Mode.SINGLE

View File

@ -248,7 +248,8 @@ class LibraryPresenter(
private fun applySort(map: LibraryMap, catId: Int?): LibraryMap { private fun applySort(map: LibraryMap, catId: Int?): LibraryMap {
if (catId == null) return map 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 { allCategories.find { it.id == catId }?.apply {
mangaOrder = category.mangaOrder mangaOrder = category.mangaOrder
mangaSort = category.mangaSort 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, private fun sortCategory(i1: LibraryItem, i2: LibraryItem,
lastReadManga: Map<Long, Int>, lastReadManga: Map<Long, Int>,
initCat: Category? = null): initCat: Category? = null):
@ -430,9 +435,10 @@ class LibraryPresenter(
}.groupBy { }.groupBy {
if (showCategories) it.manga.category else 0 if (showCategories) it.manga.category else 0
}*/ }*/
val catItemAll = LibraryHeaderItem(Category.createAll(context, val categoryAll = Category.createAll(context,
preferences.librarySortingMode().getOrDefault(), preferences.librarySortingMode().getOrDefault(),
preferences.librarySortingAscending().getOrDefault())) preferences.librarySortingAscending().getOrDefault())
val catItemAll = LibraryHeaderItem({ categoryAll }, -1)
val libraryMap = val libraryMap =
if (!preferences.libraryAsSingleList().getOrDefault()) { if (!preferences.libraryAsSingleList().getOrDefault()) {
libraryManga.map { manga -> libraryManga.map { manga ->
@ -448,8 +454,7 @@ class LibraryPresenter(
}.map { entry -> }.map { entry ->
val categoryItem = val categoryItem =
if (!showCategories) catItemAll else if (!showCategories) catItemAll else
(LibraryHeaderItem(categories.find { entry.key == it.id } (LibraryHeaderItem({ getCategory(it) }, entry.key))
?: createDefaultCategory()))
entry.value.map { entry.value.map {
LibraryItem( LibraryItem(
it, libraryLayout, categoryItem it, libraryLayout, categoryItem
@ -465,7 +470,7 @@ class LibraryPresenter(
categories.add(0, createDefaultCategory()) categories.add(0, createDefaultCategory())
this.allCategories = categories this.allCategories = categories
this.categories = if (!showCategories) arrayListOf(catItemAll.category) this.categories = if (!showCategories) arrayListOf(categoryAll)
else categories else categories
return Library(this.categories, libraryMap) return Library(this.categories, libraryMap)
@ -786,7 +791,7 @@ class LibraryPresenter(
} }
else { else {
if (category.id == 0) preferences.defaultMangaOrder().set(category.mangaSort.toString()) 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!!) requestCatSortUpdate(category.id!!)
} }
} }

View File

@ -13,38 +13,54 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_marginStart="8dp" android:layout_marginStart="8dp"
android:layout_marginBottom="4dp" android:layout_marginBottom="4dp"
android:ellipsize="end"
android:gravity="center|start" android:gravity="center|start"
android:inputType="none" android:inputType="none"
android:maxLines="1" android:maxLines="1"
app:layout_constrainedWidth="true"
app:layout_constraintBottom_toBottomOf="@id/update_button" 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_constraintStart_toStartOf="parent"
app:layout_constraintWidth_default="wrap" app:layout_constraintWidth_default="wrap"
tools:text="Title" /> tools:text="Title dfdsfsfsfsfsfsfs" />
<TextView <TextView
android:id="@+id/category_sort" android:id="@+id/category_sort"
android:padding="6dp" android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_marginBottom="4dp"
android:layout_height="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:background="@drawable/square_ripple"
android:clickable="true" android:clickable="true"
android:layout_marginEnd="10dp"
android:drawableTint="@color/gray_button"
android:drawableEnd="@drawable/ic_sort_white_24dp" android:drawableEnd="@drawable/ic_sort_white_24dp"
android:drawablePadding="6dp" android:drawablePadding="6dp"
android:drawableTint="@color/gray_button"
android:ellipsize="none"
android:focusable="true" android:focusable="true"
android:gravity="start|center" android:gravity="start|center"
android:maxLines="3"
android:padding="6dp"
android:textAppearance="@style/TextAppearance.MaterialComponents.Body2" android:textAppearance="@style/TextAppearance.MaterialComponents.Body2"
android:textColor="?android:attr/textColorPrimary" android:textColor="?android:attr/textColorPrimary"
android:textSize="12sp" android:textSize="12sp"
android:textStyle="normal" android:textStyle="normal"
app:layout_constrainedWidth="true"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0" 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" app:layout_constraintStart_toEndOf="@id/update_button"
tools:text="Sort by: Recent" /> app:layout_constraintWidth_min="1dp" />
<com.google.android.material.button.MaterialButton <com.google.android.material.button.MaterialButton
android:id="@+id/update_button" android:id="@+id/update_button"
@ -58,20 +74,21 @@
android:text="@string/ext_update" android:text="@string/ext_update"
android:textColor="?android:attr/colorAccent" android:textColor="?android:attr/colorAccent"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/space"
app:layout_constraintStart_toEndOf="@+id/category_title" app:layout_constraintStart_toEndOf="@+id/category_title"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_default="wrap"
app:rippleColor="@color/fullRippleColor" /> app:rippleColor="@color/fullRippleColor" />
<ProgressBar <ProgressBar
android:id="@+id/cat_progress" android:id="@+id/cat_progress"
android:layout_width="30dp" android:layout_width="30dp"
android:indeterminate="true"
android:layout_height="30dp" 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_constraintHorizontal_bias="0.0"
app:layout_constraintBottom_toBottomOf="@+id/update_button" app:layout_constraintStart_toEndOf="@+id/category_title"
app:layout_constraintStart_toStartOf="@+id/update_button" app:layout_constraintTop_toTopOf="@+id/category_title" />
app:layout_constraintEnd_toEndOf="@id/update_button"
app:layout_constraintTop_toTopOf="@+id/update_button" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -5,6 +5,8 @@
style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title" style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:maxLines="1"
android:ellipsize="end"
android:gravity="start" android:gravity="start"
android:textSize="20sp" android:textSize="20sp"
android:textColor="?attr/actionBarTintColor" android:textColor="?attr/actionBarTintColor"