diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourceDividerItemDecoration.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/SourceDividerItemDecoration.kt similarity index 93% rename from app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourceDividerItemDecoration.kt rename to app/src/main/java/eu/kanade/tachiyomi/ui/browse/SourceDividerItemDecoration.kt index 8ef13d840..6cc3670a1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourceDividerItemDecoration.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/SourceDividerItemDecoration.kt @@ -1,4 +1,4 @@ -package eu.kanade.tachiyomi.ui.browse.source +package eu.kanade.tachiyomi.ui.browse import android.content.Context import android.graphics.Canvas @@ -23,8 +23,8 @@ class SourceDividerItemDecoration(context: Context) : RecyclerView.ItemDecoratio for (i in 0 until childCount - 1) { val child = parent.getChildAt(i) val holder = parent.getChildViewHolder(child) - if (holder is SourceHolder && - parent.getChildViewHolder(parent.getChildAt(i + 1)) is SourceHolder + if (holder is SourceListItem && + parent.getChildViewHolder(parent.getChildAt(i + 1)) is SourceListItem ) { val top = child.bottom + child.marginBottom val bottom = top + divider.intrinsicHeight diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/SourceListItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/SourceListItem.kt new file mode 100644 index 000000000..e17571d52 --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/SourceListItem.kt @@ -0,0 +1,5 @@ +package eu.kanade.tachiyomi.ui.browse + +import eu.kanade.tachiyomi.ui.base.holder.SlicedHolder + +interface SourceListItem : SlicedHolder diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionController.kt index 58798a2ee..2f15872d0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionController.kt @@ -18,6 +18,7 @@ import eu.kanade.tachiyomi.extension.model.Extension import eu.kanade.tachiyomi.ui.base.controller.NucleusController import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction import eu.kanade.tachiyomi.ui.browse.BrowseController +import eu.kanade.tachiyomi.ui.browse.SourceDividerItemDecoration import eu.kanade.tachiyomi.ui.browse.extension.details.ExtensionDetailsController import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.launchIn @@ -75,7 +76,7 @@ open class ExtensionController : // Create recycler and set adapter. binding.recycler.layoutManager = LinearLayoutManager(view.context) binding.recycler.adapter = adapter - binding.recycler.addItemDecoration(ExtensionDividerItemDecoration(view.context)) + binding.recycler.addItemDecoration(SourceDividerItemDecoration(view.context)) adapter?.fastScroller = binding.fastScroller } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionDividerItemDecoration.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionDividerItemDecoration.kt deleted file mode 100644 index ff936f9b7..000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionDividerItemDecoration.kt +++ /dev/null @@ -1,48 +0,0 @@ -package eu.kanade.tachiyomi.ui.browse.extension - -import android.content.Context -import android.graphics.Canvas -import android.graphics.Rect -import android.graphics.drawable.Drawable -import android.view.View -import androidx.core.view.marginBottom -import androidx.recyclerview.widget.RecyclerView - -class ExtensionDividerItemDecoration(context: Context) : 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: RecyclerView, state: 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 ExtensionHolder && - parent.getChildViewHolder(parent.getChildAt(i + 1)) is ExtensionHolder - ) { - val top = child.bottom + child.marginBottom - val bottom = top + divider.intrinsicHeight - val left = parent.paddingStart + holder.margin - val right = parent.width - parent.paddingEnd - holder.margin - - divider.setBounds(left, top, right, bottom) - divider.draw(c) - } - } - } - - override fun getItemOffsets( - outRect: Rect, - view: View, - parent: RecyclerView, - state: RecyclerView.State - ) { - outRect.set(0, 0, 0, divider.intrinsicHeight) - } -} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionHolder.kt index 4abd865c4..c3a9cbb74 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionHolder.kt @@ -7,6 +7,7 @@ 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.ui.browse.SourceListItem import eu.kanade.tachiyomi.util.system.LocaleHelper import io.github.mthli.slice.Slice import kotlinx.android.synthetic.main.extension_card_item.card @@ -19,6 +20,7 @@ import kotlinx.android.synthetic.main.extension_card_item.warning class ExtensionHolder(view: View, override val adapter: ExtensionAdapter) : BaseFlexibleViewHolder(view, adapter), + SourceListItem, SlicedHolder { override val slice = Slice(card).apply { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/manga/MigrationMangaController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/manga/MigrationMangaController.kt index d34c7e92c..538cf5244 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/manga/MigrationMangaController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/manga/MigrationMangaController.kt @@ -10,8 +10,8 @@ import eu.davidea.flexibleadapter.items.IFlexible import eu.kanade.tachiyomi.databinding.MigrationMangaControllerBinding import eu.kanade.tachiyomi.ui.base.controller.NucleusController import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction +import eu.kanade.tachiyomi.ui.browse.SourceDividerItemDecoration import eu.kanade.tachiyomi.ui.browse.migration.search.SearchController -import eu.kanade.tachiyomi.ui.browse.source.SourceDividerItemDecoration class MigrationMangaController : NucleusController, diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/sources/MigrationSourcesController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/sources/MigrationSourcesController.kt index b458bb93e..faf8b6b64 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/sources/MigrationSourcesController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/sources/MigrationSourcesController.kt @@ -8,8 +8,8 @@ import eu.davidea.flexibleadapter.FlexibleAdapter import eu.kanade.tachiyomi.databinding.MigrationSourcesControllerBinding import eu.kanade.tachiyomi.ui.base.controller.NucleusController import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction +import eu.kanade.tachiyomi.ui.browse.SourceDividerItemDecoration import eu.kanade.tachiyomi.ui.browse.migration.manga.MigrationMangaController -import eu.kanade.tachiyomi.ui.browse.source.SourceDividerItemDecoration class MigrationSourcesController : NucleusController(), diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/sources/SourceHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/sources/SourceHolder.kt index 65e75ce44..8f14ff117 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/sources/SourceHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/sources/SourceHolder.kt @@ -4,6 +4,7 @@ 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.ui.browse.SourceListItem import io.github.mthli.slice.Slice import kotlinx.android.synthetic.main.source_main_controller_card_item.card import kotlinx.android.synthetic.main.source_main_controller_card_item.image @@ -11,6 +12,7 @@ import kotlinx.android.synthetic.main.source_main_controller_card_item.title class SourceHolder(view: View, override val adapter: SourceAdapter) : BaseFlexibleViewHolder(view, adapter), + SourceListItem, SlicedHolder { override val slice = Slice(card).apply { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourceController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourceController.kt index 1dcee82f2..4f83f5ec6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourceController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourceController.kt @@ -30,6 +30,7 @@ import eu.kanade.tachiyomi.ui.base.controller.NucleusController import eu.kanade.tachiyomi.ui.base.controller.requestPermissionsSafe import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction import eu.kanade.tachiyomi.ui.browse.BrowseController +import eu.kanade.tachiyomi.ui.browse.SourceDividerItemDecoration import eu.kanade.tachiyomi.ui.browse.source.browse.BrowseSourceController import eu.kanade.tachiyomi.ui.browse.source.globalsearch.GlobalSearchController import eu.kanade.tachiyomi.ui.browse.source.latest.LatestUpdatesController diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourceHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourceHolder.kt index 79e69d179..dd85b29fb 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourceHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourceHolder.kt @@ -7,6 +7,7 @@ import eu.kanade.tachiyomi.source.LocalSource 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.ui.browse.SourceListItem import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.util.view.setVectorCompat import io.github.mthli.slice.Slice @@ -18,6 +19,7 @@ import kotlinx.android.synthetic.main.source_main_controller_card_item.title class SourceHolder(private val view: View, override val adapter: SourceAdapter) : BaseFlexibleViewHolder(view, adapter), + SourceListItem, SlicedHolder { override val slice = Slice(card).apply {