mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-23 19:51:50 +01:00
Fast scroll bubble now shows sorting of manga beside the category name
This commit is contained in:
parent
1aede09d35
commit
27b68f5afb
@ -8,12 +8,10 @@ import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
|||||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||||
|
import eu.kanade.tachiyomi.util.lang.chop
|
||||||
import eu.kanade.tachiyomi.util.lang.removeArticles
|
import eu.kanade.tachiyomi.util.lang.removeArticles
|
||||||
import eu.kanade.tachiyomi.util.system.timeSpanFromNow
|
import eu.kanade.tachiyomi.util.system.timeSpanFromNow
|
||||||
import uy.kohesive.injekt.injectLazy
|
import uy.kohesive.injekt.injectLazy
|
||||||
import java.text.SimpleDateFormat
|
|
||||||
import java.util.Calendar
|
|
||||||
import java.util.Date
|
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -103,6 +101,16 @@ class LibraryCategoryAdapter(val controller: LibraryController) :
|
|||||||
return if (letter.isLetter()) getFirstChar(name) else "#"
|
return if (letter.isLetter()) getFirstChar(name) else "#"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) ?: ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onCreateBubbleText(position: Int): String {
|
override fun onCreateBubbleText(position: Int): String {
|
||||||
val preferences: PreferencesHelper by injectLazy()
|
val preferences: PreferencesHelper by injectLazy()
|
||||||
val db: DatabaseHelper by injectLazy()
|
val db: DatabaseHelper by injectLazy()
|
||||||
@ -112,16 +120,14 @@ class LibraryCategoryAdapter(val controller: LibraryController) :
|
|||||||
if (!preferences.hideCategories().getOrDefault()) item.category.name
|
if (!preferences.hideCategories().getOrDefault()) item.category.name
|
||||||
else recyclerView.context.getString(R.string.top)
|
else recyclerView.context.getString(R.string.top)
|
||||||
is LibraryItem -> {
|
is LibraryItem -> {
|
||||||
if (!isSingleCategory) {
|
val text = if (item.manga.isBlank()) ""
|
||||||
item.header?.category?.name.orEmpty()
|
else when (getSort(position)) {
|
||||||
} else if (item.manga.isBlank()) ""
|
|
||||||
else when (getSort()) {
|
|
||||||
LibrarySort.DRAG_AND_DROP -> {
|
LibrarySort.DRAG_AND_DROP -> {
|
||||||
if (!preferences.hideCategories().getOrDefault()) {
|
if (!preferences.hideCategories().getOrDefault()) {
|
||||||
val title = item.manga.title
|
val title = item.manga.title
|
||||||
if (preferences.removeArticles().getOrDefault())
|
if (preferences.removeArticles().getOrDefault())
|
||||||
getFirstChar(title.removeArticles())
|
title.removeArticles().chop(15)
|
||||||
else getFirstChar(title)
|
else title.take(10)
|
||||||
} else {
|
} else {
|
||||||
val category = db.getCategoriesForManga(item.manga)
|
val category = db.getCategoriesForManga(item.manga)
|
||||||
.executeAsBlocking().firstOrNull()?.name
|
.executeAsBlocking().firstOrNull()?.name
|
||||||
@ -137,18 +143,18 @@ class LibraryCategoryAdapter(val controller: LibraryController) :
|
|||||||
}
|
}
|
||||||
LibrarySort.UNREAD -> {
|
LibrarySort.UNREAD -> {
|
||||||
val unread = item.manga.unread
|
val unread = item.manga.unread
|
||||||
if (unread > 0) unread.toString()
|
if (unread > 0) recyclerView.context.getString(R.string._unread, unread)
|
||||||
else recyclerView.context.getString(R.string.read)
|
else recyclerView.context.getString(R.string.read)
|
||||||
}
|
}
|
||||||
LibrarySort.TOTAL -> {
|
LibrarySort.TOTAL -> {
|
||||||
val total = item.chapterCount
|
val total = item.chapterCount
|
||||||
if (total > 0) total.toString()
|
if (total > 0) recyclerView.resources.getQuantityString(R.plurals
|
||||||
|
.chapters, total, total)
|
||||||
else "N/A"
|
else "N/A"
|
||||||
}
|
}
|
||||||
LibrarySort.LATEST_CHAPTER -> {
|
LibrarySort.LATEST_CHAPTER -> {
|
||||||
val lastUpdate = item.manga.last_update
|
val lastUpdate = item.manga.last_update
|
||||||
if (lastUpdate > 0) lastUpdate.timeSpanFromNow
|
if (lastUpdate > 0) lastUpdate.timeSpanFromNow
|
||||||
// getShortDate(Date(lastUpdate))
|
|
||||||
else "N/A"
|
else "N/A"
|
||||||
}
|
}
|
||||||
LibrarySort.DATE_ADDED -> {
|
LibrarySort.DATE_ADDED -> {
|
||||||
@ -164,62 +170,34 @@ class LibraryCategoryAdapter(val controller: LibraryController) :
|
|||||||
getFirstLetter(title)
|
getFirstLetter(title)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (isSingleCategory) {
|
||||||
|
text
|
||||||
|
} else {
|
||||||
|
item.header?.category?.name.orEmpty() + ": " + text
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else -> ""
|
else -> ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getSort(): Int {
|
private fun getSort(position: Int? = null): Int {
|
||||||
val preferences: PreferencesHelper by injectLazy()
|
val preferences: PreferencesHelper by injectLazy()
|
||||||
return if (!preferences.showAllCategories().get() && !preferences.hideCategories().getOrDefault()) {
|
return if (position != null) {
|
||||||
|
val header = (getItem(position) as? LibraryItem)?.header
|
||||||
|
if (header != null) {
|
||||||
|
header.category.sortingMode() ?: LibrarySort.DRAG_AND_DROP
|
||||||
|
} else {
|
||||||
|
LibrarySort.DRAG_AND_DROP
|
||||||
|
}
|
||||||
|
} else if (!preferences.showAllCategories().get() && !preferences.hideCategories()
|
||||||
|
.getOrDefault()
|
||||||
|
) {
|
||||||
controller.presenter.getCurrentCategory()?.sortingMode() ?: LibrarySort.DRAG_AND_DROP
|
controller.presenter.getCurrentCategory()?.sortingMode() ?: LibrarySort.DRAG_AND_DROP
|
||||||
} else {
|
} else {
|
||||||
preferences.librarySortingMode().getOrDefault()
|
preferences.librarySortingMode().getOrDefault()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 getShortRange(value: Int): String {
|
|
||||||
return when (value) {
|
|
||||||
1 -> "1"
|
|
||||||
2 -> "2"
|
|
||||||
3 -> "3"
|
|
||||||
4 -> "4"
|
|
||||||
5 -> "5"
|
|
||||||
in 6..10 -> "6"
|
|
||||||
in 11..50 -> "10"
|
|
||||||
in 51..100 -> "50"
|
|
||||||
in 101..500 -> "1+"
|
|
||||||
in 499..899 -> "4+"
|
|
||||||
in 901..Int.MAX_VALUE -> "9+"
|
|
||||||
else -> "0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getShorterDate(date: Date): String {
|
|
||||||
val cal = Calendar.getInstance()
|
|
||||||
cal.time = Date()
|
|
||||||
|
|
||||||
val yearNow = cal.get(Calendar.YEAR)
|
|
||||||
val cal2 = Calendar.getInstance()
|
|
||||||
cal2.time = date
|
|
||||||
val yearThen = cal2.get(Calendar.YEAR)
|
|
||||||
|
|
||||||
return if (yearNow == yearThen)
|
|
||||||
SimpleDateFormat("M", Locale.getDefault()).format(date)
|
|
||||||
else
|
|
||||||
SimpleDateFormat("''yy", Locale.getDefault()).format(date)
|
|
||||||
}
|
|
||||||
|
|
||||||
interface LibraryListener {
|
interface LibraryListener {
|
||||||
fun startReading(position: Int)
|
fun startReading(position: Int)
|
||||||
fun onItemReleased(position: Int)
|
fun onItemReleased(position: Int)
|
||||||
|
@ -118,6 +118,7 @@
|
|||||||
<string name="expand_all_categories">Expand all categories</string>
|
<string name="expand_all_categories">Expand all categories</string>
|
||||||
<string name="collapse_all_categories">Collapse all categories</string>
|
<string name="collapse_all_categories">Collapse all categories</string>
|
||||||
<string name="reorder_filters">Reorder filters</string>
|
<string name="reorder_filters">Reorder filters</string>
|
||||||
|
<string name="_unread">%d unread</string>
|
||||||
|
|
||||||
<string name="read_progress">Read progress</string>
|
<string name="read_progress">Read progress</string>
|
||||||
<string name="series_type">Series type</string>
|
<string name="series_type">Series type</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user