Fixed fast scroll not showing emojis

closes #256 & #269
This commit is contained in:
Jay 2020-05-02 15:17:34 -04:00
parent 9078500b7c
commit cdf2a16731
2 changed files with 19 additions and 6 deletions

View File

@ -119,6 +119,9 @@ class CategoryPresenter(
controller.onCategoryExistsError() controller.onCategoryExistsError()
return false return false
} }
if (name.isBlank()) {
return false
}
category.name = name category.name = name
db.insertCategory(category).executeAsBlocking() db.insertCategory(category).executeAsBlocking()

View File

@ -1,5 +1,6 @@
package eu.kanade.tachiyomi.ui.library package eu.kanade.tachiyomi.ui.library
import android.os.Build
import eu.davidea.flexibleadapter.FlexibleAdapter import eu.davidea.flexibleadapter.FlexibleAdapter
import eu.davidea.flexibleadapter.items.IFlexible import eu.davidea.flexibleadapter.items.IFlexible
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
@ -103,7 +104,7 @@ class LibraryCategoryAdapter(val libraryListener: LibraryListener) :
return when (val item: IFlexible<*>? = getItem(position)) { return when (val item: IFlexible<*>? = getItem(position)) {
is LibraryHeaderItem -> is LibraryHeaderItem ->
if (preferences.hideCategories().getOrDefault() || item.category.id == 0) null if (preferences.hideCategories().getOrDefault() || item.category.id == 0) null
else item.category.name.first().toString() + else getFirstChar(item.category.name) +
"\u200B".repeat(max(0, item.category.order)) "\u200B".repeat(max(0, item.category.order))
is LibraryItem -> { is LibraryItem -> {
when (sorting) { when (sorting) {
@ -154,8 +155,7 @@ class LibraryCategoryAdapter(val libraryListener: LibraryListener) :
private fun getFirstLetter(name: String): String { private fun getFirstLetter(name: String): String {
val letter = name.firstOrNull() ?: '#' val letter = name.firstOrNull() ?: '#'
return if (letter.isLetter()) letter.toString() return if (letter.isLetter()) getFirstChar(name) else "#"
.toUpperCase(Locale.ROOT) else "#"
} }
override fun onCreateBubbleText(position: Int): String { override fun onCreateBubbleText(position: Int): String {
@ -172,9 +172,9 @@ class LibraryCategoryAdapter(val libraryListener: LibraryListener) :
LibrarySort.DRAG_AND_DROP -> { LibrarySort.DRAG_AND_DROP -> {
if (!preferences.hideCategories().getOrDefault()) { if (!preferences.hideCategories().getOrDefault()) {
val title = iFlexible.manga.title val title = iFlexible.manga.title
if (preferences.removeArticles().getOrDefault()) title.removeArticles() if (preferences.removeArticles().getOrDefault())
.substring(0, 1).toUpperCase(Locale.US) getFirstChar(title.removeArticles())
else title.substring(0, 1).toUpperCase(Locale.US) else getFirstChar(title)
} else { } else {
val category = db.getCategoriesForManga(iFlexible.manga) val category = db.getCategoriesForManga(iFlexible.manga)
.executeAsBlocking().firstOrNull()?.name .executeAsBlocking().firstOrNull()?.name
@ -215,6 +215,16 @@ class LibraryCategoryAdapter(val libraryListener: LibraryListener) :
} }
} }
private fun getFirstChar(string: String): String {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
val chars = string.codePoints().toArray().firstOrNull() ?: return ""
val char = Character.toChars(chars)
return String(char).toUpperCase(Locale.US)
} else {
return string.toCharArray().firstOrNull()?.toString()?.toUpperCase(Locale.US) ?: ""
}
}
private fun getRange(value: Int): String { private fun getRange(value: Int): String {
return when (value) { return when (value) {
in 1..99 -> "< 100" in 1..99 -> "< 100"