diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/holder/SlicedHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/holder/SlicedHolder.kt deleted file mode 100644 index d31e6062d1..0000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/holder/SlicedHolder.kt +++ /dev/null @@ -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> - - 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 -} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionDividerItemDecoration.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionDividerItemDecoration.kt index c843626a92..00b7e3afc5 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionDividerItemDecoration.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionDividerItemDecoration.kt @@ -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) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionHolder.kt index 8e4a8039e4..515f6a7590 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionHolder.kt @@ -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 diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsController.kt index 0792f48ad5..3f60957ee1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsController.kt @@ -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) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsDivider.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsDivider.kt new file mode 100644 index 0000000000..fdef6387ef --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsDivider.kt @@ -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) + } +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/SourceHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/SourceHolder.kt index 995739c2e9..323f597603 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/SourceHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/SourceHolder.kt @@ -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 diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentMangaDivider.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentMangaDivider.kt new file mode 100644 index 0000000000..e074a4d73f --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentMangaDivider.kt @@ -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) + } +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsController.kt index 94b7050dce..3f3f94e9c7 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsController.kt @@ -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 diff --git a/app/src/main/res/layout/recent_manga_item.xml b/app/src/main/res/layout/recent_manga_item.xml index 23704a22d1..02aee83bd7 100644 --- a/app/src/main/res/layout/recent_manga_item.xml +++ b/app/src/main/res/layout/recent_manga_item.xml @@ -173,14 +173,5 @@ android:layout_height="6dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintTop_toBottomOf="@+id/bottom_line" /> - - \ No newline at end of file diff --git a/app/src/main/res/menu/recents.xml b/app/src/main/res/menu/recents.xml index d2431b4811..1c9f121c92 100644 --- a/app/src/main/res/menu/recents.xml +++ b/app/src/main/res/menu/recents.xml @@ -12,7 +12,7 @@