[5893] - Implemented Language Badge (#6050)

* Implemented language badge on library items

* Added left margin for better viewing the badge on list view

* Adjusting borders on badges, cleaning string interpolation and cleaning code

* Improving readability on Holders and removing unused background and text on grid items
This commit is contained in:
Platiplus 2021-10-09 12:10:36 -03:00 committed by GitHub
parent f32f1eeaa5
commit 918502742d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 244 additions and 123 deletions

View file

@ -197,6 +197,8 @@ object PreferenceKeys {
const val unreadBadge = "display_unread_badge"
const val languageBadge = "display_language_badge"
const val localBadge = "display_local_badge"
const val categoryTabs = "display_category_tabs"

View file

@ -253,6 +253,8 @@ class PreferencesHelper(val context: Context) {
fun unreadBadge() = flowPrefs.getBoolean(Keys.unreadBadge, true)
fun languageBadge() = flowPrefs.getBoolean(Keys.languageBadge, false)
fun categoryTabs() = flowPrefs.getBoolean(Keys.categoryTabs, true)
fun categoryNumberOfItems() = flowPrefs.getBoolean(Keys.categoryNumberOfItems, false)

View file

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

View file

@ -39,7 +39,8 @@ open class SourceGridHolder(private val view: View, private val adapter: Flexibl
binding.thumbnail.alpha = if (manga.favorite) 0.3f else 1.0f
// For rounded corners
binding.badges.clipToOutline = true
binding.leftBadges.clipToOutline = true
binding.rightBadges.clipToOutline = true
// Set favorite badge
binding.favoriteText.isVisible = manga.favorite

View file

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

View file

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

View file

@ -34,6 +34,7 @@ class LibraryItem(
var downloadCount = -1
var unreadCount = -1
var isLocal = false
var sourceLanguage = ""
private fun getDisplayMode(): DisplayModeSetting {
return if (shouldSetFromCategory.get() && manga.category != 0) {

View file

@ -46,6 +46,11 @@ class LibraryListHolder(
isVisible = item.downloadCount > 0
text = "${item.downloadCount}"
}
// Update the source language and its visibility
with(binding.languageText) {
isVisible = item.sourceLanguage.isNotEmpty()
text = item.sourceLanguage
}
// show local text badge if local manga
binding.localText.isVisible = item.isLocal

View file

@ -200,6 +200,7 @@ class LibraryPresenter(
val showDownloadBadges = preferences.downloadBadge().get()
val showUnreadBadges = preferences.unreadBadge().get()
val showLocalBadges = preferences.localBadge().get()
val showLanguageBadges = preferences.languageBadge().get()
for ((_, itemList) in map) {
for (item in itemList) {
@ -223,6 +224,13 @@ class LibraryPresenter(
// Hide / Unset local badge if not enabled
false
}
item.sourceLanguage = if (showLanguageBadges) {
sourceManager.getOrStub(item.manga.source).lang.uppercase()
} else {
// Unset source language if not enabled
""
}
}
}
}

View file

@ -367,15 +367,17 @@ class LibrarySettingsSheet(
private val downloadBadge = Item.CheckboxGroup(R.string.action_display_download_badge, this)
private val unreadBadge = Item.CheckboxGroup(R.string.action_display_unread_badge, this)
private val localBadge = Item.CheckboxGroup(R.string.action_display_local_badge, this)
private val languageBadge = Item.CheckboxGroup(R.string.action_display_language_badge, this)
override val header = Item.Header(R.string.badges_header)
override val items = listOf(downloadBadge, unreadBadge, localBadge)
override val items = listOf(downloadBadge, unreadBadge, localBadge, languageBadge)
override val footer = null
override fun initModels() {
downloadBadge.checked = preferences.downloadBadge().get()
unreadBadge.checked = preferences.unreadBadge().get()
localBadge.checked = preferences.localBadge().get()
languageBadge.checked = preferences.languageBadge().get()
}
override fun onItemClicked(item: Item) {
@ -385,6 +387,7 @@ class LibrarySettingsSheet(
downloadBadge -> preferences.downloadBadge().set((item.checked))
unreadBadge -> preferences.unreadBadge().set((item.checked))
localBadge -> preferences.localBadge().set((item.checked))
languageBadge -> preferences.languageBadge().set((item.checked))
}
adapter.notifyItemChanged(item)
}

View file

@ -37,74 +37,109 @@
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginTop="4dp"
android:background="@drawable/rounded_rectangle">
android:layout_marginEnd="4dp">
<TextView
android:id="@+id/local_text"
<LinearLayout
android:id="@+id/left_badges"
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" />
android:background="@drawable/rounded_rectangle">
<TextView
android:id="@+id/download_text"
<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="?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" />
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
android:id="@+id/progress"
style="@style/Widget.Tachiyomi.CircularProgressIndicator.Small"

View file

@ -36,72 +36,106 @@
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginTop="4dp"
android:background="@drawable/rounded_rectangle">
android:layout_marginEnd="4dp">
<TextView
android:id="@+id/local_text"
<LinearLayout
android:id="@+id/left_badges"
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" />
android:background="@drawable/rounded_rectangle">
<TextView
android:id="@+id/download_text"
<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="?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" />
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

View file

@ -112,6 +112,22 @@
android:visibility="gone"
tools:visibility="visible" />
<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>
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -93,6 +93,7 @@
<string name="action_display_download_badge">Download badges</string>
<string name="action_display_unread_badge">Unread badges</string>
<string name="action_display_local_badge">Local badges</string>
<string name="action_display_language_badge">Language badges</string>
<string name="action_display_show_tabs">Show category tabs</string>
<string name="action_display_show_number_of_items">Show number of items</string>
<string name="action_disable">Disable</string>