Flipped long press and tap for tapping a category, shrunk distance between collapsed chapters

Added an arrow to show show collasped status
This commit is contained in:
Jay 2020-05-02 14:38:37 -04:00
parent e2152e7f72
commit 9078500b7c
7 changed files with 78 additions and 28 deletions

View File

@ -31,6 +31,7 @@ import eu.kanade.tachiyomi.util.view.invisible
import eu.kanade.tachiyomi.util.view.updateLayoutParams
import eu.kanade.tachiyomi.util.view.visInvisIf
import eu.kanade.tachiyomi.util.view.visible
import kotlinx.android.synthetic.main.library_category_header_item.*
class LibraryHeaderItem(
private val categoryF: (Int) -> Category,
@ -56,7 +57,7 @@ class LibraryHeaderItem(
position: Int,
payloads: MutableList<Any?>?
) {
holder.bind(categoryF(catId))
holder.bind(this)
}
val category: Category
@ -89,69 +90,89 @@ class LibraryHeaderItem(
private val sortText: TextView = view.findViewById(R.id.category_sort)
private val updateButton: ImageView = view.findViewById(R.id.update_button)
private val checkboxImage: ImageView = view.findViewById(R.id.checkbox)
private val expandImage: ImageView = view.findViewById(R.id.collapse_arrow)
private val catProgress: ProgressBar = view.findViewById(R.id.cat_progress)
init {
sortText.updateLayoutParams<ViewGroup.MarginLayoutParams> {
marginEnd = (if (padEnd && adapter.recyclerView.paddingEnd == 0) 12 else 2).dpToPx
}
updateButton.setOnClickListener { addCategoryToUpdate() }
sectionText.setOnClickListener { adapter.libraryListener.manageCategory(adapterPosition) }
sectionText.setOnLongClickListener {
category_header_layout.setOnClickListener {
adapter.libraryListener.toggleCategoryVisibility(adapterPosition)
}
updateButton.setOnClickListener { addCategoryToUpdate() }
sectionText.setOnLongClickListener {
adapter.libraryListener.manageCategory(adapterPosition)
true
}
sectionText.setOnClickListener {
adapter.libraryListener.toggleCategoryVisibility(adapterPosition)
}
sortText.setOnClickListener { it.post { showCatSortOptions() } }
checkboxImage.setOnClickListener { selectAll() }
updateButton.drawable.mutate()
}
fun bind(category: Category) {
sectionText.updateLayoutParams<ConstraintLayout.LayoutParams> {
topMargin =
(if ((adapter.headerItems.firstOrNull() as? LibraryHeaderItem)?.catId == category.id) 2 else 44).dpToPx
fun bind(item: LibraryHeaderItem) {
val index = adapter.headerItems.indexOf(item)
val previousIsCollapsed =
if (index > 0) {
(adapter.headerItems[index - 1] as? LibraryHeaderItem)?.category?.isHidden
?: false
} else {
false
}
val shorterMargin = adapter.headerItems.firstOrNull() == item
sectionText.updateLayoutParams<ConstraintLayout.LayoutParams> {
topMargin = (when {
shorterMargin -> 2
previousIsCollapsed -> 5
else -> 32
}).dpToPx
}
val category = item.category
if (category.isFirst == true && category.isLast == true) sectionText.text = ""
else sectionText.text = category.name
sortText.text = itemView.context.getString(R.string.sort_by_,
itemView.context.getString(category.sortRes())
sortText.text = itemView.context.getString(
R.string.sort_by_, itemView.context.getString(category.sortRes())
)
val isAscending = category.isAscending()
val sortingMode = category.sortingMode()
val sortDrawable = if (category.isHidden) R.drawable.ic_expand_more_white_24dp
else
when {
sortingMode == LibrarySort.DRAG_AND_DROP || sortingMode == null -> R.drawable
.ic_sort_white_24dp
if (sortingMode == LibrarySort.DATE_ADDED ||
sortingMode == LibrarySort.LATEST_CHAPTER ||
sortingMode == LibrarySort.LAST_READ) !isAscending else isAscending ->
R.drawable.ic_arrow_down_white_24dp
val sortDrawable = if (category.isHidden) R.drawable.ic_expand_more_24dp
else when {
sortingMode == LibrarySort.DRAG_AND_DROP || sortingMode == null -> R.drawable.ic_sort_white_24dp
if (sortingMode == LibrarySort.DATE_ADDED || sortingMode == LibrarySort.LATEST_CHAPTER || sortingMode == LibrarySort.LAST_READ) !isAscending else isAscending -> R.drawable.ic_arrow_down_white_24dp
else -> R.drawable.ic_arrow_up_white_24dp
}
sortText.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, sortDrawable, 0)
sortText.setText(if (category.isHidden) R.string.collasped else category.sortRes())
expandImage.setImageResource(
if (category.isHidden) R.drawable.ic_expand_more_24dp
else R.drawable.ic_expand_less_24dp)
when {
adapter.mode == SelectableAdapter.Mode.MULTI -> {
checkboxImage.visible()
expandImage.invisible()
updateButton.gone()
catProgress.gone()
setSelection()
}
category.id == -1 -> {
expandImage.gone()
checkboxImage.gone()
updateButton.gone()
}
LibraryUpdateService.categoryInQueue(category.id) -> {
expandImage.visible()
checkboxImage.gone()
catProgress.visible()
updateButton.invisible()
}
else -> {
expandImage.visible()
catProgress.gone()
checkboxImage.gone()
updateButton.visInvisIf(category.id ?: 0 > -1)

View File

@ -79,8 +79,10 @@ class LibraryListHolder(
subtitle.text = item.manga.author?.trim()
title.post {
if (title.text == item.manga.title) {
subtitle.visibleIf(title.lineCount == 1 && !item.manga.author.isNullOrBlank())
}
}
// Update the cover.
if (item.manga.thumbnail_url == null) Glide.with(view.context).clear(cover_thumbnail)

View File

@ -35,7 +35,7 @@ class GroupItem(val filter: Filter.Group<*>) : AbstractExpandableHeaderItem<Grou
holder.title.text = filter.name
holder.icon.setVectorCompat(if (isExpanded)
R.drawable.ic_expand_more_white_24dp
R.drawable.ic_expand_more_24dp
else
R.drawable.ic_chevron_right_white_24dp)

View File

@ -32,7 +32,7 @@ class SortGroup(val filter: Filter.Sort) : AbstractExpandableHeaderItem<SortGrou
holder.title.text = filter.name
holder.icon.setVectorCompat(if (isExpanded)
R.drawable.ic_expand_more_white_24dp
R.drawable.ic_expand_more_24dp
else
R.drawable.ic_chevron_right_white_24dp)

View File

@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#FFFFFF"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M12,8l-6,6 1.41,1.41L12,10.83l4.59,4.58L18,14z"/>
</vector>

View File

@ -2,15 +2,17 @@
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/category_header_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/list_item_selector"
android:gravity="center_vertical">
<ImageView
android:id="@+id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginStart="2dp"
android:clickable="true"
android:contentDescription="@string/select_all"
android:focusable="true"
@ -18,18 +20,38 @@
android:src="@drawable/ic_check_circle_white_24dp"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="@+id/category_title"
app:layout_constraintEnd_toStartOf="@+id/category_title"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/category_title"
tools:tint="?attr/colorAccent"
tools:visibility="visible" />
<ImageView
android:id="@+id/collapse_arrow"
android:layout_width="14dp"
android:layout_height="wrap_content"
android:layout_marginStart="2dp"
android:contentDescription="@string/select_all"
android:src="@drawable/ic_expand_less_24dp"
android:tint="?android:textColorPrimary"
android:alpha="0.5"
app:layout_constraintBottom_toBottomOf="@+id/category_title"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/category_title" />
<androidx.constraintlayout.widget.Barrier
android:id="@+id/start_barrier"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="right"
app:constraint_referenced_ids="collapse_arrow,checkbox"
/>
<TextView
android:id="@+id/category_title"
style="@style/TextAppearance.MaterialComponents.Headline6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingStart="4dp"
android:paddingStart="0dp"
android:layout_marginStart="4dp"
android:paddingEnd="4dp"
android:paddingTop="4dp"
@ -46,7 +68,7 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/update_button"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="@+id/checkbox"
app:layout_constraintStart_toEndOf="@+id/start_barrier"
app:layout_constraintTop_toTopOf="parent"
tools:text="Title dfdsfsfsfsfsfdsfsfsfs" />