From cdf2a16731da6c1ffa3dcdeabae6d9d64d2521c0 Mon Sep 17 00:00:00 2001 From: Jay Date: Sat, 2 May 2020 15:17:34 -0400 Subject: [PATCH] Fixed fast scroll not showing emojis closes #256 & #269 --- .../ui/category/CategoryPresenter.kt | 3 +++ .../ui/library/LibraryCategoryAdapter.kt | 22 ++++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryPresenter.kt index a26f321b82..cf56ffa9eb 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryPresenter.kt @@ -119,6 +119,9 @@ class CategoryPresenter( controller.onCategoryExistsError() return false } + if (name.isBlank()) { + return false + } category.name = name db.insertCategory(category).executeAsBlocking() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryAdapter.kt index f9519a8f9e..f964ce354c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryAdapter.kt @@ -1,5 +1,6 @@ package eu.kanade.tachiyomi.ui.library +import android.os.Build import eu.davidea.flexibleadapter.FlexibleAdapter import eu.davidea.flexibleadapter.items.IFlexible import eu.kanade.tachiyomi.R @@ -103,7 +104,7 @@ class LibraryCategoryAdapter(val libraryListener: LibraryListener) : return when (val item: IFlexible<*>? = getItem(position)) { is LibraryHeaderItem -> 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)) is LibraryItem -> { when (sorting) { @@ -154,8 +155,7 @@ class LibraryCategoryAdapter(val libraryListener: LibraryListener) : private fun getFirstLetter(name: String): String { val letter = name.firstOrNull() ?: '#' - return if (letter.isLetter()) letter.toString() - .toUpperCase(Locale.ROOT) else "#" + return if (letter.isLetter()) getFirstChar(name) else "#" } override fun onCreateBubbleText(position: Int): String { @@ -172,9 +172,9 @@ class LibraryCategoryAdapter(val libraryListener: LibraryListener) : LibrarySort.DRAG_AND_DROP -> { if (!preferences.hideCategories().getOrDefault()) { val title = iFlexible.manga.title - if (preferences.removeArticles().getOrDefault()) title.removeArticles() - .substring(0, 1).toUpperCase(Locale.US) - else title.substring(0, 1).toUpperCase(Locale.US) + if (preferences.removeArticles().getOrDefault()) + getFirstChar(title.removeArticles()) + else getFirstChar(title) } else { val category = db.getCategoriesForManga(iFlexible.manga) .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 { return when (value) { in 1..99 -> "< 100"