Update dividers

This commit is contained in:
Jay 2020-04-19 17:41:50 -04:00
parent 541b026fa8
commit 732b7c3414
10 changed files with 111 additions and 117 deletions

View File

@ -1,70 +0,0 @@
package eu.kanade.tachiyomi.ui.base.holder
import android.view.View
import android.view.ViewGroup
import eu.davidea.flexibleadapter.FlexibleAdapter
import eu.davidea.flexibleadapter.items.IFlexible
import eu.davidea.flexibleadapter.items.ISectionable
import eu.kanade.tachiyomi.util.system.dpToPx
import io.github.mthli.slice.Slice
interface SlicedHolder {
val slice: Slice
val adapter: FlexibleAdapter<IFlexible<*>>
val viewToSlice: View
fun setCardEdges(item: ISectionable<*, *>) {
// Position of this item in its header. Defaults to 0 when header is null.
var position = 0
// Number of items in the header of this item. Defaults to 1 when header is null.
var count = 1
if (item.header != null) {
val sectionItems = adapter.getSectionItems(item.header)
position = sectionItems.indexOf(item)
count = sectionItems.size
}
when {
// Only one item in the card
count == 1 -> applySlice(2f, false, false, true, true)
// First item of the card
position == 0 -> applySlice(2f, false, true, true, false)
// Last item of the card
position == count - 1 -> applySlice(2f, true, false, false, true)
// Middle item
else -> applySlice(0f, false, false, false, false)
}
}
private fun applySlice(
radius: Float,
topRect: Boolean,
bottomRect: Boolean,
topShadow: Boolean,
bottomShadow: Boolean
) {
val margin = margin
slice.setRadius(radius)
slice.showLeftTopRect(topRect)
slice.showRightTopRect(topRect)
slice.showLeftBottomRect(bottomRect)
slice.showRightBottomRect(bottomRect)
setMargins(margin, if (topShadow) margin else 0, margin, if (bottomShadow) margin else 0)
}
private fun setMargins(left: Int, top: Int, right: Int, bottom: Int) {
if (viewToSlice.layoutParams is ViewGroup.MarginLayoutParams) {
val p = viewToSlice.layoutParams as ViewGroup.MarginLayoutParams
p.setMargins(left, top, right, bottom)
}
}
val margin
get() = 8.dpToPx
}

View File

@ -5,6 +5,7 @@ import android.graphics.Canvas
import android.graphics.Rect
import android.graphics.drawable.Drawable
import android.view.View
import eu.kanade.tachiyomi.util.system.dpToPx
class ExtensionDividerItemDecoration(context: Context) : androidx.recyclerview.widget.RecyclerView.ItemDecoration() {
@ -26,8 +27,8 @@ class ExtensionDividerItemDecoration(context: Context) : androidx.recyclerview.w
val params = child.layoutParams as androidx.recyclerview.widget.RecyclerView.LayoutParams
val top = child.bottom + params.bottomMargin
val bottom = top + divider.intrinsicHeight
val left = parent.paddingStart + holder.margin
val right = parent.width - parent.paddingEnd - holder.margin
val left = parent.paddingStart + 12.dpToPx
val right = parent.width - parent.paddingEnd
divider.setBounds(left, top, right, bottom)
divider.draw(c)

View File

@ -9,23 +9,13 @@ import eu.kanade.tachiyomi.data.glide.GlideApp
import eu.kanade.tachiyomi.extension.model.Extension
import eu.kanade.tachiyomi.extension.model.InstallStep
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
import eu.kanade.tachiyomi.ui.base.holder.SlicedHolder
import eu.kanade.tachiyomi.util.system.LocaleHelper
import eu.kanade.tachiyomi.util.system.getResourceColor
import eu.kanade.tachiyomi.util.view.resetStrokeColor
import io.github.mthli.slice.Slice
import kotlinx.android.synthetic.main.extension_card_item.*
class ExtensionHolder(view: View, override val adapter: ExtensionAdapter) :
BaseFlexibleViewHolder(view, adapter),
SlicedHolder {
override val slice = Slice(card).apply {
setColor(adapter.cardBackground)
}
override val viewToSlice: View
get() = card
class ExtensionHolder(view: View, val adapter: ExtensionAdapter) :
BaseFlexibleViewHolder(view, adapter) {
init {
ext_button.setOnClickListener {
@ -35,7 +25,6 @@ class ExtensionHolder(view: View, override val adapter: ExtensionAdapter) :
fun bind(item: ExtensionItem) {
val extension = item.extension
setCardEdges(item)
// Set source name
ext_title.text = extension.name

View File

@ -41,7 +41,6 @@ import androidx.core.graphics.ColorUtils
import androidx.core.graphics.drawable.IconCompat
import androidx.core.math.MathUtils
import androidx.palette.graphics.Palette
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
@ -249,10 +248,7 @@ class MangaDetailsController : BaseController,
adapter?.isSwipeEnabled = true
recycler.layoutManager = LinearLayoutManager(view.context)
recycler.addItemDecoration(
DividerItemDecoration(
view.context,
DividerItemDecoration.VERTICAL
)
MangaDetailsDivider(view.context)
)
recycler.setHasFixedSize(true)
val attrsArray = intArrayOf(android.R.attr.actionBarSize)

View File

@ -0,0 +1,48 @@
package eu.kanade.tachiyomi.ui.manga
import android.content.Context
import android.graphics.Canvas
import android.graphics.Rect
import android.graphics.drawable.Drawable
import android.view.View
import eu.kanade.tachiyomi.util.system.dpToPx
class MangaDetailsDivider(context: Context) : androidx.recyclerview.widget.RecyclerView.ItemDecoration() {
private val divider: Drawable
init {
val a = context.obtainStyledAttributes(intArrayOf(android.R.attr.listDivider))
divider = a.getDrawable(0)!!
a.recycle()
}
override fun onDraw(
c: Canvas,
parent: androidx.recyclerview.widget.RecyclerView,
state: androidx.recyclerview.widget.RecyclerView.State
) {
val childCount = parent.childCount
for (i in 0 until childCount - 1) {
val child = parent.getChildAt(i)
val params =
child.layoutParams as androidx.recyclerview.widget.RecyclerView.LayoutParams
val top = child.bottom + params.bottomMargin
val bottom = top + divider.intrinsicHeight
val left = parent.paddingStart + 12.dpToPx
val right = parent.width - parent.paddingEnd
divider.setBounds(left, top, right, bottom)
divider.draw(c)
}
}
override fun getItemOffsets(
outRect: Rect,
view: View,
parent: androidx.recyclerview.widget.RecyclerView,
state: androidx.recyclerview.widget.RecyclerView.State
) {
outRect.set(0, 0, 0, divider.intrinsicHeight)
}
}

View File

@ -3,37 +3,25 @@ package eu.kanade.tachiyomi.ui.migration
import android.view.View
import eu.kanade.tachiyomi.source.icon
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
import eu.kanade.tachiyomi.ui.base.holder.SlicedHolder
import eu.kanade.tachiyomi.util.view.roundTextIcon
import io.github.mthli.slice.Slice
import kotlinx.android.synthetic.main.source_item.card
import kotlinx.android.synthetic.main.migration_card_item.*
import kotlinx.android.synthetic.main.source_item.edit_button
import kotlinx.android.synthetic.main.source_item.title
import kotlinx.android.synthetic.main.migration_card_item.*
class SourceHolder(view: View, override val adapter: SourceAdapter) :
BaseFlexibleViewHolder(view, adapter),
SlicedHolder {
override val slice = Slice(card).apply {
setColor(adapter.cardBackground)
}
override val viewToSlice: View
get() = card
class SourceHolder(view: View, val adapter: SourceAdapter) :
BaseFlexibleViewHolder(view, adapter) {
init {
migration_auto.setOnClickListener {
adapter.selectClickListener?.onSelectClick(adapterPosition)
adapter.autoClickListener?.onAutoClick(adapterPosition)
}
migration_select.setOnClickListener {
adapter.autoClickListener?.onAutoClick(adapterPosition)
adapter.selectClickListener?.onSelectClick(adapterPosition)
}
}
fun bind(item: SourceItem) {
val source = item.source
setCardEdges(item)
// Set source name
title.text = source.name

View File

@ -0,0 +1,48 @@
package eu.kanade.tachiyomi.ui.recents
import android.content.Context
import android.graphics.Canvas
import android.graphics.Rect
import android.graphics.drawable.Drawable
import android.view.View
import eu.kanade.tachiyomi.util.system.dpToPx
class RecentMangaDivider(context: Context) : androidx.recyclerview.widget.RecyclerView.ItemDecoration() {
private val divider: Drawable
init {
val a = context.obtainStyledAttributes(intArrayOf(android.R.attr.listDivider))
divider = a.getDrawable(0)!!
a.recycle()
}
override fun onDraw(c: Canvas, parent: androidx.recyclerview.widget.RecyclerView, state: androidx.recyclerview.widget.RecyclerView.State) {
val childCount = parent.childCount
for (i in 0 until childCount - 1) {
val child = parent.getChildAt(i)
val holder = parent.getChildViewHolder(child)
if (holder is RecentMangaHolder &&
parent.getChildViewHolder(parent.getChildAt(i + 1)) is RecentMangaHolder
) {
val params = child.layoutParams as androidx.recyclerview.widget.RecyclerView.LayoutParams
val top = child.bottom + params.bottomMargin
val bottom = top + divider.intrinsicHeight
val left = parent.paddingStart + 12.dpToPx
val right = parent.width - parent.paddingEnd
divider.setBounds(left, top, right, bottom)
divider.draw(c)
}
}
}
override fun getItemOffsets(
outRect: Rect,
view: View,
parent: androidx.recyclerview.widget.RecyclerView,
state: androidx.recyclerview.widget.RecyclerView.State
) {
outRect.set(0, 0, 0, divider.intrinsicHeight)
}
}

View File

@ -105,6 +105,9 @@ class RecentsController(bundle: Bundle? = null) : BaseController(bundle),
recycler.layoutManager = LinearLayoutManager(view.context)
recycler.setHasFixedSize(true)
recycler.recycledViewPool.setMaxRecycledViews(0, 0)
recycler.addItemDecoration(
RecentMangaDivider(view.context)
)
adapter.isSwipeEnabled = true
adapter.itemTouchHelperCallback.setSwipeFlags(
ItemTouchHelper.LEFT

View File

@ -173,14 +173,5 @@
android:layout_height="6dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/bottom_line" />
<View
android:layout_width="0dp"
android:layout_height="1dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginStart="10dp"
android:background="?android:attr/divider"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</FrameLayout>

View File

@ -12,7 +12,7 @@
<item
android:id="@+id/action_filter"
android:icon="@drawable/ic_filter_list_white_24dp"
android:title="@string/group_all"
android:title="@string/filter"
app:showAsAction="ifRoom">
<menu>
<group android:checkableBehavior="single">