From a3c598a3e1758c00d00ad3a804d8dbb7e24ab2ac Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 26 Sep 2020 19:03:46 -0400 Subject: [PATCH] Remove card backgrounds from browse lists --- app/build.gradle | 1 - .../tachiyomi/ui/base/holder/SlicedHolder.kt | 70 -------- .../ui/browse/SourceDividerItemDecoration.kt | 48 ------ .../tachiyomi/ui/browse/SourceListItem.kt | 5 - .../browse/extension/ExtensionController.kt | 2 - .../ui/browse/extension/ExtensionHolder.kt | 18 +- .../manga/MigrationMangaController.kt | 2 - .../sources/MigrationSourcesController.kt | 2 - .../browse/migration/sources/SourceHolder.kt | 18 +- .../ui/browse/source/SourceController.kt | 2 - .../ui/browse/source/SourceHolder.kt | 18 +- .../main/res/layout/extension_card_item.xml | 158 +++++++++--------- .../source_main_controller_card_header.xml | 4 +- .../source_main_controller_card_item.xml | 124 +++++++------- app/src/main/res/values/styles.xml | 6 +- 15 files changed, 144 insertions(+), 334 deletions(-) delete mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/base/holder/SlicedHolder.kt delete mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/browse/SourceDividerItemDecoration.kt delete mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/browse/SourceListItem.kt diff --git a/app/build.gradle b/app/build.gradle index c31d594822..a3bb3e5202 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -234,7 +234,6 @@ dependencies { implementation 'eu.davidea:flexible-adapter-ui:1.0.0' implementation 'com.nononsenseapps:filepicker:2.5.2' implementation 'com.nightlynexus.viewstatepageradapter:viewstatepageradapter:1.1.0' - implementation 'com.github.mthli:Slice:v1.3' implementation 'com.github.chrisbanes:PhotoView:2.3.0' implementation 'com.github.carlosesco:DirectionalViewPager:a844dbca0a' 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 3acb98558c..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, topRect = false, bottomRect = false, topShadow = true, bottomShadow = true) - // First item of the card - position == 0 -> applySlice(2f, topRect = false, bottomRect = true, topShadow = true, bottomShadow = false) - // Last item of the card - position == count - 1 -> applySlice(2f, topRect = true, bottomRect = false, topShadow = false, bottomShadow = true) - // Middle item - else -> applySlice(0f, topRect = false, bottomRect = false, topShadow = false, bottomShadow = 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/browse/SourceDividerItemDecoration.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/SourceDividerItemDecoration.kt deleted file mode 100644 index 6cc3670a19..0000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/SourceDividerItemDecoration.kt +++ /dev/null @@ -1,48 +0,0 @@ -package eu.kanade.tachiyomi.ui.browse - -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 SourceDividerItemDecoration(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 SourceListItem && - parent.getChildViewHolder(parent.getChildAt(i + 1)) is SourceListItem - ) { - 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/SourceListItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/SourceListItem.kt deleted file mode 100644 index e17571d522..0000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/SourceListItem.kt +++ /dev/null @@ -1,5 +0,0 @@ -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 2f15872d00..1673eb7e1b 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,7 +18,6 @@ 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 @@ -76,7 +75,6 @@ open class ExtensionController : // Create recycler and set adapter. binding.recycler.layoutManager = LinearLayoutManager(view.context) binding.recycler.adapter = adapter - binding.recycler.addItemDecoration(SourceDividerItemDecoration(view.context)) adapter?.fastScroller = binding.fastScroller } 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 12167abdbe..bd64e17445 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 @@ -6,11 +6,7 @@ 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.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 import kotlinx.android.synthetic.main.extension_card_item.ext_button import kotlinx.android.synthetic.main.extension_card_item.ext_title import kotlinx.android.synthetic.main.extension_card_item.image @@ -18,17 +14,8 @@ import kotlinx.android.synthetic.main.extension_card_item.lang import kotlinx.android.synthetic.main.extension_card_item.version 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 { - setColor(adapter.cardBackground) - } - - override val viewToSlice: View - get() = card +class ExtensionHolder(view: View, val adapter: ExtensionAdapter) : + BaseFlexibleViewHolder(view, adapter) { init { ext_button.setOnClickListener { @@ -38,7 +25,6 @@ class ExtensionHolder(view: View, override val adapter: ExtensionAdapter) : fun bind(item: ExtensionItem) { val extension = item.extension - setCardEdges(item) ext_title.text = extension.name version.text = extension.versionName 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 538cf5244a..62d8596ac7 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,7 +10,6 @@ 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 class MigrationMangaController : @@ -54,7 +53,6 @@ class MigrationMangaController : adapter = FlexibleAdapter>(null, this) binding.recycler.layoutManager = LinearLayoutManager(view.context) binding.recycler.adapter = adapter - binding.recycler.addItemDecoration(SourceDividerItemDecoration(view.context)) adapter?.fastScroller = binding.fastScroller } 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 faf8b6b64f..862e6b9411 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,7 +8,6 @@ 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 class MigrationSourcesController : @@ -32,7 +31,6 @@ class MigrationSourcesController : adapter = SourceAdapter(this) binding.recycler.layoutManager = LinearLayoutManager(view.context) binding.recycler.adapter = adapter - binding.recycler.addItemDecoration(SourceDividerItemDecoration(view.context)) adapter?.fastScroller = binding.fastScroller } 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 8f14ff117f..6f77f1594d 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 @@ -3,28 +3,14 @@ package eu.kanade.tachiyomi.ui.browse.migration.sources 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 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 { - setColor(adapter.cardBackground) - } - - override val viewToSlice: View - get() = card +class SourceHolder(view: View, val adapter: SourceAdapter) : + BaseFlexibleViewHolder(view, adapter) { 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/browse/source/SourceController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourceController.kt index 14dbae471c..72ce7529c9 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,7 +30,6 @@ 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 @@ -93,7 +92,6 @@ class SourceController : // Create recycler and set adapter. binding.recycler.layoutManager = LinearLayoutManager(view.context) binding.recycler.adapter = adapter - binding.recycler.addItemDecoration(SourceDividerItemDecoration(view.context)) adapter?.fastScroller = binding.fastScroller requestPermissionsSafe(arrayOf(WRITE_EXTERNAL_STORAGE), 301) 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 dd85b29fb7..df5833b537 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 @@ -6,28 +6,15 @@ import eu.kanade.tachiyomi.R 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 -import kotlinx.android.synthetic.main.source_main_controller_card_item.card import kotlinx.android.synthetic.main.source_main_controller_card_item.image import kotlinx.android.synthetic.main.source_main_controller_card_item.pin import kotlinx.android.synthetic.main.source_main_controller_card_item.source_latest 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 { - setColor(adapter.cardBackground) - } - - override val viewToSlice: View - get() = card +class SourceHolder(private val view: View, val adapter: SourceAdapter) : + BaseFlexibleViewHolder(view, adapter) { init { source_latest.setOnClickListener { @@ -41,7 +28,6 @@ class SourceHolder(private val view: View, override val adapter: SourceAdapter) fun bind(item: SourceItem) { val source = item.source - setCardEdges(item) // Set source name title.text = source.name diff --git a/app/src/main/res/layout/extension_card_item.xml b/app/src/main/res/layout/extension_card_item.xml index a96f142df4..8f0beb3902 100644 --- a/app/src/main/res/layout/extension_card_item.xml +++ b/app/src/main/res/layout/extension_card_item.xml @@ -1,94 +1,86 @@ - + android:layout_height="64dp" + android:background="@drawable/list_item_selector_background"> - + - + - + - + - + - - -