From 44b055c01986b6b4952ab4658e04cf236f922fa0 Mon Sep 17 00:00:00 2001 From: Mica <58011910+micaelagimenez@users.noreply.github.com> Date: Sat, 12 Feb 2022 15:03:22 -0300 Subject: [PATCH] Cover only grid added to library (#6528) * No title grid added to library and source * Else added to display title in case image is null or empty * No title grid renamed and now only available in library * Spanish strings about cover only grid removed Co-authored-by: micaelagimenez --- .../source/browse/BrowseSourceController.kt | 6 +- .../ui/browse/source/browse/SourceItem.kt | 36 +++++----- .../ui/library/LibraryCoverOnlyGridHolder.kt | 60 ++++++++++++++++ .../tachiyomi/ui/library/LibraryItem.kt | 14 ++++ .../ui/library/LibrarySettingsSheet.kt | 5 +- .../ui/library/setting/DisplayModeSetting.kt | 5 +- .../layout/source_cover_only_grid_item.xml | 68 +++++++++++++++++++ app/src/main/res/values/strings.xml | 1 + 8 files changed, 171 insertions(+), 24 deletions(-) create mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCoverOnlyGridHolder.kt create mode 100644 app/src/main/res/layout/source_cover_only_grid_item.xml diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceController.kt index b82f8b6dc1..b91126a177 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceController.kt @@ -222,7 +222,7 @@ open class BrowseSourceController(bundle: Bundle) : (layoutManager as GridLayoutManager).spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() { override fun getSpanSize(position: Int): Int { return when (adapter?.getItemViewType(position)) { - R.layout.source_compact_grid_item, R.layout.source_comfortable_grid_item, null -> 1 + R.layout.source_compact_grid_item, R.layout.source_comfortable_grid_item -> 1 else -> spanCount } } @@ -273,9 +273,9 @@ open class BrowseSourceController(bundle: Bundle) : ) val displayItem = when (preferences.sourceDisplayMode().get()) { - DisplayModeSetting.COMPACT_GRID -> R.id.action_compact_grid - DisplayModeSetting.COMFORTABLE_GRID -> R.id.action_comfortable_grid DisplayModeSetting.LIST -> R.id.action_list + DisplayModeSetting.COMFORTABLE_GRID -> R.id.action_comfortable_grid + else -> R.id.action_compact_grid } menu.findItem(displayItem).isChecked = true } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/SourceItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/SourceItem.kt index 83666ff69e..a107cd33a5 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/SourceItem.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/SourceItem.kt @@ -22,9 +22,9 @@ class SourceItem(val manga: Manga, private val displayMode: Preference R.layout.source_compact_grid_item - DisplayModeSetting.COMFORTABLE_GRID -> R.layout.source_comfortable_grid_item DisplayModeSetting.LIST -> R.layout.source_list_item + DisplayModeSetting.COMFORTABLE_GRID -> R.layout.source_comfortable_grid_item + else -> R.layout.source_compact_grid_item } } @@ -33,7 +33,22 @@ class SourceItem(val manga: Manga, private val displayMode: Preference> ): SourceHolder<*> { return when (displayMode.get()) { - DisplayModeSetting.COMPACT_GRID -> { + DisplayModeSetting.LIST -> { + SourceListHolder(view, adapter) + } + DisplayModeSetting.COMFORTABLE_GRID -> { + val binding = SourceComfortableGridItemBinding.bind(view) + val parent = adapter.recyclerView as AutofitRecyclerView + val coverHeight = parent.itemWidth / 3 * 4 + view.apply { + binding.card.layoutParams = ConstraintLayout.LayoutParams( + MATCH_PARENT, + coverHeight + ) + } + SourceComfortableGridHolder(view, adapter) + } + else -> { val binding = SourceCompactGridItemBinding.bind(view) val parent = adapter.recyclerView as AutofitRecyclerView val coverHeight = parent.itemWidth / 3 * 4 @@ -50,21 +65,6 @@ class SourceItem(val manga: Manga, private val displayMode: Preference { - val binding = SourceComfortableGridItemBinding.bind(view) - val parent = adapter.recyclerView as AutofitRecyclerView - val coverHeight = parent.itemWidth / 3 * 4 - view.apply { - binding.card.layoutParams = ConstraintLayout.LayoutParams( - MATCH_PARENT, - coverHeight - ) - } - SourceComfortableGridHolder(view, adapter) - } - DisplayModeSetting.LIST -> { - SourceListHolder(view, adapter) - } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCoverOnlyGridHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCoverOnlyGridHolder.kt new file mode 100644 index 0000000000..b99e386365 --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCoverOnlyGridHolder.kt @@ -0,0 +1,60 @@ +package eu.kanade.tachiyomi.ui.library + +import android.view.View +import androidx.core.view.isVisible +import androidx.recyclerview.widget.RecyclerView +import coil.clear +import eu.davidea.flexibleadapter.FlexibleAdapter +import eu.davidea.flexibleadapter.items.IFlexible +import eu.kanade.tachiyomi.databinding.SourceCoverOnlyGridItemBinding +import eu.kanade.tachiyomi.util.view.loadAnyAutoPause + +class LibraryCoverOnlyGridHolder( + view: View, + adapter: FlexibleAdapter> +) : LibraryHolder(view, adapter) { + + override val binding = SourceCoverOnlyGridItemBinding.bind(view) + + /** + * Method called from [LibraryCategoryAdapter.onBindViewHolder]. It updates the data for this + * holder with the given manga. + * + * @param item the manga item to bind. + */ + override fun onSetValues(item: LibraryItem) { + // For rounded corners + binding.badges.leftBadges.clipToOutline = true + binding.badges.rightBadges.clipToOutline = true + + // Update the unread count and its visibility. + with(binding.badges.unreadText) { + isVisible = item.unreadCount > 0 + text = item.unreadCount.toString() + } + // Update the download count and its visibility. + with(binding.badges.downloadText) { + isVisible = item.downloadCount > 0 + text = item.downloadCount.toString() + } + // Update the source language and its visibility + with(binding.badges.languageText) { + isVisible = item.sourceLanguage.isNotEmpty() + text = item.sourceLanguage + } + // set local visibility if its local manga + binding.badges.localText.isVisible = item.isLocal + + // For rounded corners + binding.card.clipToOutline = true + + // Update the cover. + binding.thumbnail.clear() + if (!item.manga.thumbnail_url.isNullOrEmpty()) { + binding.thumbnail.loadAnyAutoPause(item.manga) + } else { + // Set manga title + binding.title.text = item.manga.title + } + } +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt index e9bc4a9712..ba6db87b1b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt @@ -15,6 +15,7 @@ import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.LibraryManga import eu.kanade.tachiyomi.databinding.SourceComfortableGridItemBinding import eu.kanade.tachiyomi.databinding.SourceCompactGridItemBinding +import eu.kanade.tachiyomi.databinding.SourceCoverOnlyGridItemBinding import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.ui.library.setting.DisplayModeSetting import eu.kanade.tachiyomi.widget.AutofitRecyclerView @@ -48,6 +49,7 @@ class LibraryItem( return when (getDisplayMode()) { DisplayModeSetting.COMPACT_GRID -> R.layout.source_compact_grid_item DisplayModeSetting.COMFORTABLE_GRID -> R.layout.source_comfortable_grid_item + DisplayModeSetting.COVER_ONLY_GRID -> R.layout.source_cover_only_grid_item DisplayModeSetting.LIST -> R.layout.source_list_item } } @@ -80,6 +82,18 @@ class LibraryItem( } LibraryComfortableGridHolder(view, adapter) } + DisplayModeSetting.COVER_ONLY_GRID -> { + val binding = SourceCoverOnlyGridItemBinding.bind(view) + val parent = adapter.recyclerView as AutofitRecyclerView + val coverHeight = parent.itemWidth / 3 * 4 + view.apply { + binding.card.layoutParams = ConstraintLayout.LayoutParams( + MATCH_PARENT, + coverHeight + ) + } + LibraryCoverOnlyGridHolder(view, adapter) + } DisplayModeSetting.LIST -> { LibraryListHolder(view, adapter) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySettingsSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySettingsSheet.kt index 44671f68fb..661a8611bc 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySettingsSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySettingsSheet.kt @@ -315,10 +315,11 @@ class LibrarySettingsSheet( private val compactGrid = Item.Radio(R.string.action_display_grid, this) private val comfortableGrid = Item.Radio(R.string.action_display_comfortable_grid, this) + private val coverOnlyGrid = Item.Radio(R.string.action_display_cover_only_grid, this) private val list = Item.Radio(R.string.action_display_list, this) override val header = Item.Header(R.string.action_display_mode) - override val items = listOf(compactGrid, comfortableGrid, list) + override val items = listOf(compactGrid, comfortableGrid, coverOnlyGrid, list) override val footer = null override fun initModels() { @@ -342,6 +343,7 @@ class LibrarySettingsSheet( fun setGroupSelections(mode: DisplayModeSetting) { compactGrid.checked = mode == DisplayModeSetting.COMPACT_GRID comfortableGrid.checked = mode == DisplayModeSetting.COMFORTABLE_GRID + coverOnlyGrid.checked = mode == DisplayModeSetting.COVER_ONLY_GRID list.checked = mode == DisplayModeSetting.LIST } @@ -349,6 +351,7 @@ class LibrarySettingsSheet( val flag = when (item) { compactGrid -> DisplayModeSetting.COMPACT_GRID comfortableGrid -> DisplayModeSetting.COMFORTABLE_GRID + coverOnlyGrid -> DisplayModeSetting.COVER_ONLY_GRID list -> DisplayModeSetting.LIST else -> throw NotImplementedError("Unknown display mode") } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/setting/DisplayModeSetting.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/setting/DisplayModeSetting.kt index dca6a744ae..a45765e2c2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/setting/DisplayModeSetting.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/setting/DisplayModeSetting.kt @@ -3,10 +3,11 @@ package eu.kanade.tachiyomi.ui.library.setting enum class DisplayModeSetting(val flag: Int) { COMPACT_GRID(0b00000000), COMFORTABLE_GRID(0b00000001), - LIST(0b00000010); + LIST(0b00000010), + COVER_ONLY_GRID(0b00000100); companion object { - const val MASK = 0b00000011 + const val MASK = 0b00000111 fun fromFlag(flag: Int?): DisplayModeSetting { return values() diff --git a/app/src/main/res/layout/source_cover_only_grid_item.xml b/app/src/main/res/layout/source_cover_only_grid_item.xml new file mode 100644 index 0000000000..dafe664520 --- /dev/null +++ b/app/src/main/res/layout/source_cover_only_grid_item.xml @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d1bc5181f2..00af9edbbe 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -91,6 +91,7 @@ Compact grid Comfortable grid List + Cover only grid Downloaded chapters Unread chapters Local manga