Use single layout for grid badges

This commit is contained in:
arkon 2021-10-09 17:26:53 -04:00
parent 98c0e5271f
commit c95a269460
8 changed files with 138 additions and 236 deletions

View File

@ -39,11 +39,11 @@ class SourceComfortableGridHolder(private val view: View, private val adapter: F
binding.thumbnail.alpha = if (manga.favorite) 0.3f else 1.0f binding.thumbnail.alpha = if (manga.favorite) 0.3f else 1.0f
// For rounded corners // For rounded corners
binding.leftBadges.clipToOutline = true binding.badges.leftBadges.clipToOutline = true
binding.rightBadges.clipToOutline = true binding.badges.rightBadges.clipToOutline = true
// Set favorite badge // Set favorite badge
binding.favoriteText.isVisible = manga.favorite binding.badges.favoriteText.isVisible = manga.favorite
setImage(manga) setImage(manga)
} }

View File

@ -9,7 +9,7 @@ import coil.transition.CrossfadeTransition
import eu.davidea.flexibleadapter.FlexibleAdapter import eu.davidea.flexibleadapter.FlexibleAdapter
import eu.kanade.tachiyomi.data.coil.MangaCoverFetcher import eu.kanade.tachiyomi.data.coil.MangaCoverFetcher
import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.databinding.SourceComfortableGridItemBinding import eu.kanade.tachiyomi.databinding.SourceCompactGridItemBinding
import eu.kanade.tachiyomi.widget.StateImageViewTarget import eu.kanade.tachiyomi.widget.StateImageViewTarget
/** /**
@ -20,10 +20,10 @@ import eu.kanade.tachiyomi.widget.StateImageViewTarget
* @param adapter the adapter handling this holder. * @param adapter the adapter handling this holder.
* @constructor creates a new catalogue holder. * @constructor creates a new catalogue holder.
*/ */
open class SourceGridHolder(private val view: View, private val adapter: FlexibleAdapter<*>) : open class SourceCompactGridHolder(private val view: View, private val adapter: FlexibleAdapter<*>) :
SourceHolder<SourceComfortableGridItemBinding>(view, adapter) { SourceHolder<SourceCompactGridItemBinding>(view, adapter) {
override val binding = SourceComfortableGridItemBinding.bind(view) override val binding = SourceCompactGridItemBinding.bind(view)
/** /**
* Method called from [CatalogueAdapter.onBindViewHolder]. It updates the data for this * Method called from [CatalogueAdapter.onBindViewHolder]. It updates the data for this
@ -39,11 +39,11 @@ open class SourceGridHolder(private val view: View, private val adapter: Flexibl
binding.thumbnail.alpha = if (manga.favorite) 0.3f else 1.0f binding.thumbnail.alpha = if (manga.favorite) 0.3f else 1.0f
// For rounded corners // For rounded corners
binding.leftBadges.clipToOutline = true binding.badges.leftBadges.clipToOutline = true
binding.rightBadges.clipToOutline = true binding.badges.rightBadges.clipToOutline = true
// Set favorite badge // Set favorite badge
binding.favoriteText.isVisible = manga.favorite binding.badges.favoriteText.isVisible = manga.favorite
setImage(manga) setImage(manga)
} }

View File

@ -48,7 +48,7 @@ class SourceItem(val manga: Manga, private val displayMode: Preference<DisplayMo
Gravity.BOTTOM Gravity.BOTTOM
) )
} }
SourceGridHolder(view, adapter) SourceCompactGridHolder(view, adapter)
} }
DisplayModeSetting.COMFORTABLE_GRID -> { DisplayModeSetting.COMFORTABLE_GRID -> {
val binding = SourceComfortableGridItemBinding.bind(view) val binding = SourceComfortableGridItemBinding.bind(view)

View File

@ -36,26 +36,26 @@ class LibraryComfortableGridHolder(
binding.title.text = item.manga.title binding.title.text = item.manga.title
// For rounded corners // For rounded corners
binding.leftBadges.clipToOutline = true binding.badges.leftBadges.clipToOutline = true
binding.rightBadges.clipToOutline = true binding.badges.rightBadges.clipToOutline = true
// Update the unread count and its visibility. // Update the unread count and its visibility.
with(binding.unreadText) { with(binding.badges.unreadText) {
isVisible = item.unreadCount > 0 isVisible = item.unreadCount > 0
text = item.unreadCount.toString() text = item.unreadCount.toString()
} }
// Update the download count and its visibility. // Update the download count and its visibility.
with(binding.downloadText) { with(binding.badges.downloadText) {
isVisible = item.downloadCount > 0 isVisible = item.downloadCount > 0
text = item.downloadCount.toString() text = item.downloadCount.toString()
} }
// Update the source language and its visibility // Update the source language and its visibility
with(binding.languageText) { with(binding.badges.languageText) {
isVisible = item.sourceLanguage.isNotEmpty() isVisible = item.sourceLanguage.isNotEmpty()
text = item.sourceLanguage text = item.sourceLanguage
} }
// set local visibility if its local manga // set local visibility if its local manga
binding.localText.isVisible = item.isLocal binding.badges.localText.isVisible = item.isLocal
// For rounded corners // For rounded corners
binding.card.clipToOutline = true binding.card.clipToOutline = true

View File

@ -34,26 +34,26 @@ open class LibraryCompactGridHolder(
binding.title.text = item.manga.title binding.title.text = item.manga.title
// For rounded corners // For rounded corners
binding.leftBadges.clipToOutline = true binding.badges.leftBadges.clipToOutline = true
binding.rightBadges.clipToOutline = true binding.badges.rightBadges.clipToOutline = true
// Update the unread count and its visibility. // Update the unread count and its visibility.
with(binding.unreadText) { with(binding.badges.unreadText) {
isVisible = item.unreadCount > 0 isVisible = item.unreadCount > 0
text = item.unreadCount.toString() text = item.unreadCount.toString()
} }
// Update the download count and its visibility. // Update the download count and its visibility.
with(binding.downloadText) { with(binding.badges.downloadText) {
isVisible = item.downloadCount > 0 isVisible = item.downloadCount > 0
text = item.downloadCount.toString() text = item.downloadCount.toString()
} }
// Update the source language and its visibility // Update the source language and its visibility
with(binding.languageText) { with(binding.badges.languageText) {
isVisible = item.sourceLanguage.isNotEmpty() isVisible = item.sourceLanguage.isNotEmpty()
text = item.sourceLanguage text = item.sourceLanguage
} }
// set local visibility if its local manga // set local visibility if its local manga
binding.localText.isVisible = item.isLocal binding.badges.localText.isVisible = item.isLocal
// For rounded corners // For rounded corners
binding.card.clipToOutline = true binding.card.clipToOutline = true

View File

@ -31,114 +31,9 @@
tools:ignore="ContentDescription" tools:ignore="ContentDescription"
tools:src="@mipmap/ic_launcher" /> tools:src="@mipmap/ic_launcher" />
<LinearLayout <include
android:id="@+id/badges" android:id="@+id/badges"
android:layout_width="wrap_content" layout="@layout/source_grid_item_badges" />
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginTop="4dp"
android:layout_marginEnd="4dp">
<LinearLayout
android:id="@+id/left_badges"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/rounded_rectangle">
<TextView
android:id="@+id/local_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/colorTertiary"
android:paddingStart="3dp"
android:paddingTop="1dp"
android:maxLines="1"
android:paddingEnd="3dp"
android:paddingBottom="1dp"
android:text="@string/local_source_badge"
android:textAppearance="?attr/textAppearanceCaption"
android:textColor="?attr/colorOnTertiary"
android:visibility="gone"
tools:visibility="visible" />
<TextView
android:id="@+id/download_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/colorTertiary"
android:paddingStart="3dp"
android:paddingTop="1dp"
android:maxLines="1"
android:paddingEnd="3dp"
android:paddingBottom="1dp"
android:textAppearance="?attr/textAppearanceCaption"
android:textColor="?attr/colorOnTertiary"
android:visibility="gone"
tools:text="120"
tools:visibility="visible" />
<TextView
android:id="@+id/unread_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/colorSecondary"
android:paddingStart="3dp"
android:paddingTop="1dp"
android:paddingEnd="3dp"
android:maxLines="1"
android:paddingBottom="1dp"
android:textAppearance="?attr/textAppearanceCaption"
android:textColor="?attr/colorOnSecondary"
android:visibility="gone"
tools:text="120"
tools:visibility="visible" />
<TextView
android:id="@+id/favorite_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/colorSecondary"
android:maxLines="1"
android:paddingStart="3dp"
android:paddingTop="1dp"
android:paddingEnd="3dp"
android:paddingBottom="1dp"
android:text="@string/in_library"
android:textAppearance="?attr/textAppearanceCaption"
android:textColor="?attr/colorOnSecondary"
android:visibility="gone"
tools:visibility="visible" />
</LinearLayout>
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<LinearLayout
android:id="@+id/right_badges"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/rounded_rectangle">
<TextView
android:id="@+id/language_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/colorTertiary"
android:maxLines="1"
android:paddingStart="3dp"
android:paddingTop="1dp"
android:paddingEnd="3dp"
android:paddingBottom="1dp"
tools:text="EN"
android:textAppearance="?attr/textAppearanceCaption"
android:textColor="?attr/colorOnTertiary"
android:visibility="gone"
tools:visibility="visible" />
</LinearLayout>
</LinearLayout>
<com.google.android.material.progressindicator.CircularProgressIndicator <com.google.android.material.progressindicator.CircularProgressIndicator
android:id="@+id/progress" android:id="@+id/progress"

View File

@ -30,113 +30,9 @@
android:layout_gravity="bottom" android:layout_gravity="bottom"
android:background="@drawable/gradient_shape" /> android:background="@drawable/gradient_shape" />
<LinearLayout <include
android:id="@+id/badges" android:id="@+id/badges"
android:layout_width="wrap_content" layout="@layout/source_grid_item_badges" />
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginTop="4dp"
android:layout_marginEnd="4dp">
<LinearLayout
android:id="@+id/left_badges"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/rounded_rectangle">
<TextView
android:id="@+id/local_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/colorTertiary"
android:paddingStart="3dp"
android:paddingTop="1dp"
android:paddingEnd="3dp"
android:paddingBottom="1dp"
android:maxLines="1"
android:text="@string/local_source_badge"
android:textAppearance="?attr/textAppearanceCaption"
android:textColor="?attr/colorOnTertiary"
android:visibility="gone"
tools:visibility="visible" />
<TextView
android:id="@+id/download_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/colorTertiary"
android:paddingStart="3dp"
android:paddingTop="1dp"
android:maxLines="1"
android:paddingEnd="3dp"
android:paddingBottom="1dp"
android:textAppearance="?attr/textAppearanceCaption"
android:textColor="?attr/colorOnTertiary"
android:visibility="gone"
tools:text="120"
tools:visibility="visible" />
<TextView
android:id="@+id/unread_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/colorSecondary"
android:paddingStart="3dp"
android:paddingTop="1dp"
android:paddingEnd="3dp"
android:paddingBottom="1dp"
android:maxLines="1"
android:textAppearance="?attr/textAppearanceCaption"
android:textColor="?attr/colorOnSecondary"
android:visibility="gone"
tools:text="120"
tools:visibility="visible" />
<TextView
android:id="@+id/favorite_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/colorSecondary"
android:maxLines="1"
android:paddingStart="3dp"
android:paddingTop="1dp"
android:paddingEnd="3dp"
android:paddingBottom="1dp"
android:text="@string/in_library"
android:textAppearance="?attr/textAppearanceCaption"
android:textColor="?attr/colorOnSecondary"
android:visibility="gone"
tools:visibility="visible" />
</LinearLayout>
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<LinearLayout
android:id="@+id/right_badges"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/rounded_rectangle">
<TextView
android:id="@+id/language_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/colorTertiary"
android:maxLines="1"
android:paddingStart="3dp"
android:paddingTop="1dp"
android:paddingEnd="3dp"
android:paddingBottom="1dp"
tools:text="EN"
android:textAppearance="?attr/textAppearanceCaption"
android:textColor="?attr/colorOnTertiary"
android:visibility="gone"
tools:visibility="visible" />
</LinearLayout>
</LinearLayout>
<TextView <TextView
android:id="@+id/title" android:id="@+id/title"

View File

@ -0,0 +1,111 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginTop="4dp"
android:layout_marginEnd="4dp">
<LinearLayout
android:id="@+id/left_badges"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/rounded_rectangle">
<TextView
android:id="@+id/local_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/colorTertiary"
android:maxLines="1"
android:paddingStart="3dp"
android:paddingTop="1dp"
android:paddingEnd="3dp"
android:paddingBottom="1dp"
android:text="@string/local_source_badge"
android:textAppearance="?attr/textAppearanceCaption"
android:textColor="?attr/colorOnTertiary"
android:visibility="gone"
tools:visibility="visible" />
<TextView
android:id="@+id/download_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/colorTertiary"
android:maxLines="1"
android:paddingStart="3dp"
android:paddingTop="1dp"
android:paddingEnd="3dp"
android:paddingBottom="1dp"
android:textAppearance="?attr/textAppearanceCaption"
android:textColor="?attr/colorOnTertiary"
android:visibility="gone"
tools:text="120"
tools:visibility="visible" />
<TextView
android:id="@+id/unread_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/colorSecondary"
android:maxLines="1"
android:paddingStart="3dp"
android:paddingTop="1dp"
android:paddingEnd="3dp"
android:paddingBottom="1dp"
android:textAppearance="?attr/textAppearanceCaption"
android:textColor="?attr/colorOnSecondary"
android:visibility="gone"
tools:text="120"
tools:visibility="visible" />
<TextView
android:id="@+id/favorite_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/colorSecondary"
android:maxLines="1"
android:paddingStart="3dp"
android:paddingTop="1dp"
android:paddingEnd="3dp"
android:paddingBottom="1dp"
android:text="@string/in_library"
android:textAppearance="?attr/textAppearanceCaption"
android:textColor="?attr/colorOnSecondary"
android:visibility="gone"
tools:visibility="visible" />
</LinearLayout>
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<LinearLayout
android:id="@+id/right_badges"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/rounded_rectangle">
<TextView
android:id="@+id/language_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/colorTertiary"
android:maxLines="1"
android:paddingStart="3dp"
android:paddingTop="1dp"
android:paddingEnd="3dp"
android:paddingBottom="1dp"
android:textAppearance="?attr/textAppearanceCaption"
android:textColor="?attr/colorOnTertiary"
android:visibility="gone"
tools:text="EN"
tools:visibility="visible" />
</LinearLayout>
</LinearLayout>