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 b82f8b6dc..b91126a17 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 83666ff69..a107cd33a 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 000000000..b99e38636 --- /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 e9bc4a971..ba6db87b1 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 44671f68f..661a8611b 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 dca6a744a..a45765e2c 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 000000000..dafe66452 --- /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 d1bc5181f..00af9edbb 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