[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 unreadBadge = "display_unread_badge"
const val languageBadge = "display_language_badge"
const val localBadge = "display_local_badge" const val localBadge = "display_local_badge"
const val categoryTabs = "display_category_tabs" 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 unreadBadge() = flowPrefs.getBoolean(Keys.unreadBadge, true)
fun languageBadge() = flowPrefs.getBoolean(Keys.languageBadge, false)
fun categoryTabs() = flowPrefs.getBoolean(Keys.categoryTabs, true) fun categoryTabs() = flowPrefs.getBoolean(Keys.categoryTabs, true)
fun categoryNumberOfItems() = flowPrefs.getBoolean(Keys.categoryNumberOfItems, false) 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 binding.thumbnail.alpha = if (manga.favorite) 0.3f else 1.0f
// For rounded corners // For rounded corners
binding.badges.clipToOutline = true binding.leftBadges.clipToOutline = true
binding.rightBadges.clipToOutline = true
// Set favorite badge // Set favorite badge
binding.favoriteText.isVisible = manga.favorite 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 binding.thumbnail.alpha = if (manga.favorite) 0.3f else 1.0f
// For rounded corners // For rounded corners
binding.badges.clipToOutline = true binding.leftBadges.clipToOutline = true
binding.rightBadges.clipToOutline = true
// Set favorite badge // Set favorite badge
binding.favoriteText.isVisible = manga.favorite binding.favoriteText.isVisible = manga.favorite

View File

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

View File

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

View File

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

View File

@ -46,6 +46,11 @@ class LibraryListHolder(
isVisible = item.downloadCount > 0 isVisible = item.downloadCount > 0
text = "${item.downloadCount}" 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 // show local text badge if local manga
binding.localText.isVisible = item.isLocal binding.localText.isVisible = item.isLocal

View File

@ -200,6 +200,7 @@ class LibraryPresenter(
val showDownloadBadges = preferences.downloadBadge().get() val showDownloadBadges = preferences.downloadBadge().get()
val showUnreadBadges = preferences.unreadBadge().get() val showUnreadBadges = preferences.unreadBadge().get()
val showLocalBadges = preferences.localBadge().get() val showLocalBadges = preferences.localBadge().get()
val showLanguageBadges = preferences.languageBadge().get()
for ((_, itemList) in map) { for ((_, itemList) in map) {
for (item in itemList) { for (item in itemList) {
@ -223,6 +224,13 @@ class LibraryPresenter(
// Hide / Unset local badge if not enabled // Hide / Unset local badge if not enabled
false 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 downloadBadge = Item.CheckboxGroup(R.string.action_display_download_badge, this)
private val unreadBadge = Item.CheckboxGroup(R.string.action_display_unread_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 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 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 val footer = null
override fun initModels() { override fun initModels() {
downloadBadge.checked = preferences.downloadBadge().get() downloadBadge.checked = preferences.downloadBadge().get()
unreadBadge.checked = preferences.unreadBadge().get() unreadBadge.checked = preferences.unreadBadge().get()
localBadge.checked = preferences.localBadge().get() localBadge.checked = preferences.localBadge().get()
languageBadge.checked = preferences.languageBadge().get()
} }
override fun onItemClicked(item: Item) { override fun onItemClicked(item: Item) {
@ -385,6 +387,7 @@ class LibrarySettingsSheet(
downloadBadge -> preferences.downloadBadge().set((item.checked)) downloadBadge -> preferences.downloadBadge().set((item.checked))
unreadBadge -> preferences.unreadBadge().set((item.checked)) unreadBadge -> preferences.unreadBadge().set((item.checked))
localBadge -> preferences.localBadge().set((item.checked)) localBadge -> preferences.localBadge().set((item.checked))
languageBadge -> preferences.languageBadge().set((item.checked))
} }
adapter.notifyItemChanged(item) adapter.notifyItemChanged(item)
} }

View File

@ -37,6 +37,12 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="4dp" android:layout_marginStart="4dp"
android:layout_marginTop="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"> android:background="@drawable/rounded_rectangle">
<TextView <TextView
@ -102,9 +108,38 @@
android:textColor="?attr/colorOnSecondary" android:textColor="?attr/colorOnSecondary"
android:visibility="gone" android:visibility="gone"
tools:visibility="visible" /> tools:visibility="visible" />
</LinearLayout> </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"
style="@style/Widget.Tachiyomi.CircularProgressIndicator.Small" style="@style/Widget.Tachiyomi.CircularProgressIndicator.Small"

View File

@ -36,6 +36,12 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="4dp" android:layout_marginStart="4dp"
android:layout_marginTop="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"> android:background="@drawable/rounded_rectangle">
<TextView <TextView
@ -101,7 +107,35 @@
android:textColor="?attr/colorOnSecondary" android:textColor="?attr/colorOnSecondary"
android:visibility="gone" android:visibility="gone"
tools:visibility="visible" /> 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> </LinearLayout>
<TextView <TextView

View File

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

View File

@ -93,6 +93,7 @@
<string name="action_display_download_badge">Download badges</string> <string name="action_display_download_badge">Download badges</string>
<string name="action_display_unread_badge">Unread badges</string> <string name="action_display_unread_badge">Unread badges</string>
<string name="action_display_local_badge">Local 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_tabs">Show category tabs</string>
<string name="action_display_show_number_of_items">Show number of items</string> <string name="action_display_show_number_of_items">Show number of items</string>
<string name="action_disable">Disable</string> <string name="action_disable">Disable</string>