mirror of
				https://github.com/mihonapp/mihon.git
				synced 2025-10-30 22:07:57 +01:00 
			
		
		
		
	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 <micaela.gimenez@ext.prosegur.com>
This commit is contained in:
		| @@ -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 | ||||
|     } | ||||
|   | ||||
| @@ -22,9 +22,9 @@ class SourceItem(val manga: Manga, private val displayMode: Preference<DisplayMo | ||||
|  | ||||
|     override fun getLayoutRes(): Int { | ||||
|         return when (displayMode.get()) { | ||||
|             DisplayModeSetting.COMPACT_GRID -> 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<DisplayMo | ||||
|         adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>> | ||||
|     ): 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<DisplayMo | ||||
|                 } | ||||
|                 SourceCompactGridHolder(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) | ||||
|             } | ||||
|             DisplayModeSetting.LIST -> { | ||||
|                 SourceListHolder(view, adapter) | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -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<IFlexible<RecyclerView.ViewHolder>> | ||||
| ) : LibraryHolder<SourceCoverOnlyGridItemBinding>(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 | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -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) | ||||
|             } | ||||
|   | ||||
| @@ -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") | ||||
|                 } | ||||
|   | ||||
| @@ -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() | ||||
|   | ||||
		Reference in New Issue
	
	Block a user