mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-24 18:41:51 +01:00
Total chapter count shown when sorting by total chapters
This commit is contained in:
parent
8e8cbbca3b
commit
3940d42185
@ -4,6 +4,7 @@ import android.content.Context
|
|||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
import com.google.android.material.card.MaterialCardView
|
import com.google.android.material.card.MaterialCardView
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.util.system.dpToPx
|
import eu.kanade.tachiyomi.util.system.dpToPx
|
||||||
@ -14,14 +15,18 @@ import kotlinx.android.synthetic.main.unread_download_badge.view.*
|
|||||||
class LibraryBadge @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null):
|
class LibraryBadge @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null):
|
||||||
MaterialCardView(context, attrs) {
|
MaterialCardView(context, attrs) {
|
||||||
|
|
||||||
fun setUnreadDownload(unread: Int, downloads: Int) {
|
fun setUnreadDownload(unread: Int, downloads: Int, showTotalChapters: Boolean) {
|
||||||
// Update the unread count and its visibility.
|
// Update the unread count and its visibility.
|
||||||
with(unread_text) {
|
with(unread_text) {
|
||||||
text = if (unread == -1) "0" else unread.toString()
|
text = if (unread == -1) "0" else unread.toString()
|
||||||
setTextColor(if (unread == -1) context.getResourceColor(android.R.attr.colorAccent)
|
setTextColor(if (unread == -1 && !showTotalChapters)
|
||||||
|
context.getResourceColor(android.R.attr.colorAccent)
|
||||||
else Color.WHITE)
|
else Color.WHITE)
|
||||||
|
setBackgroundColor(
|
||||||
|
if (showTotalChapters) ContextCompat.getColor(context, R.color.md_red_500)
|
||||||
|
else context.getResourceColor(android.R.attr.colorAccent))
|
||||||
visibility = when {
|
visibility = when {
|
||||||
unread > 0 || unread == -1 -> View.VISIBLE
|
unread > 0 || unread == -1 || showTotalChapters -> View.VISIBLE
|
||||||
else -> View.GONE
|
else -> View.GONE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -41,7 +46,9 @@ class LibraryBadge @JvmOverloads constructor(context: Context, attrs: AttributeS
|
|||||||
// Show the angles divider if both unread and downloads exists
|
// Show the angles divider if both unread and downloads exists
|
||||||
unread_angle.visibility = if (download_text.visibility == View.VISIBLE && unread_text
|
unread_angle.visibility = if (download_text.visibility == View.VISIBLE && unread_text
|
||||||
.visibility != View.GONE) View.VISIBLE else View.GONE
|
.visibility != View.GONE) View.VISIBLE else View.GONE
|
||||||
|
unread_angle.setColorFilter(
|
||||||
|
if (showTotalChapters) ContextCompat.getColor(context, R.color.md_red_500)
|
||||||
|
else context.getResourceColor(android.R.attr.colorAccent))
|
||||||
if (unread_angle.visibility == View.VISIBLE) {
|
if (unread_angle.visibility == View.VISIBLE) {
|
||||||
download_text.updatePaddingRelative(end = 8.dpToPx)
|
download_text.updatePaddingRelative(end = 8.dpToPx)
|
||||||
unread_text.updatePaddingRelative(start = 2.dpToPx)
|
unread_text.updatePaddingRelative(start = 2.dpToPx)
|
||||||
|
@ -7,7 +7,6 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy
|
|||||||
import com.bumptech.glide.signature.ObjectKey
|
import com.bumptech.glide.signature.ObjectKey
|
||||||
import eu.kanade.tachiyomi.data.database.models.MangaImpl
|
import eu.kanade.tachiyomi.data.database.models.MangaImpl
|
||||||
import eu.kanade.tachiyomi.data.glide.GlideApp
|
import eu.kanade.tachiyomi.data.glide.GlideApp
|
||||||
import eu.kanade.tachiyomi.source.LocalSource
|
|
||||||
import eu.kanade.tachiyomi.util.view.gone
|
import eu.kanade.tachiyomi.util.view.gone
|
||||||
import kotlinx.android.synthetic.main.catalogue_grid_item.*
|
import kotlinx.android.synthetic.main.catalogue_grid_item.*
|
||||||
import kotlinx.android.synthetic.main.unread_download_badge.*
|
import kotlinx.android.synthetic.main.unread_download_badge.*
|
||||||
@ -80,17 +79,7 @@ class LibraryGridHolder(
|
|||||||
|
|
||||||
compact_title.text = title.text
|
compact_title.text = title.text
|
||||||
|
|
||||||
badge_view.setUnreadDownload(
|
setUnreadBadge(badge_view, item)
|
||||||
when (item.unreadType) {
|
|
||||||
1 -> item.manga.unread
|
|
||||||
0 -> if (item.manga.unread > 0) -1 else -2
|
|
||||||
else -> -2
|
|
||||||
},
|
|
||||||
when {
|
|
||||||
item.downloadCount == -1 -> -1
|
|
||||||
item.manga.source == LocalSource.ID -> -2
|
|
||||||
else -> item.downloadCount
|
|
||||||
})
|
|
||||||
play_layout.visibility = if (item.manga.unread > 0 && item.unreadType > -1)
|
play_layout.visibility = if (item.manga.unread > 0 && item.unreadType > -1)
|
||||||
View.VISIBLE else View.GONE
|
View.VISIBLE else View.GONE
|
||||||
|
|
||||||
|
@ -1,11 +1,8 @@
|
|||||||
package eu.kanade.tachiyomi.ui.library
|
package eu.kanade.tachiyomi.ui.library
|
||||||
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.core.content.ContextCompat
|
import eu.kanade.tachiyomi.source.LocalSource
|
||||||
import eu.davidea.flexibleadapter.FlexibleAdapter
|
|
||||||
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
|
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
|
||||||
import eu.davidea.flexibleadapter.items.IFlexible
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generic class used to hold the displayed data of a manga in the library.
|
* Generic class used to hold the displayed data of a manga in the library.
|
||||||
@ -28,6 +25,22 @@ abstract class LibraryHolder(
|
|||||||
abstract fun onSetValues(item: LibraryItem)
|
abstract fun onSetValues(item: LibraryItem)
|
||||||
|
|
||||||
|
|
||||||
|
fun setUnreadBadge(badge: LibraryBadge, item: LibraryItem) {
|
||||||
|
badge.setUnreadDownload(
|
||||||
|
when {
|
||||||
|
item.chapterCount > -1 -> item.chapterCount
|
||||||
|
item.unreadType == 1 -> item.manga.unread
|
||||||
|
item.unreadType == 0 -> if (item.manga.unread > 0) -1 else -2
|
||||||
|
else -> -2
|
||||||
|
},
|
||||||
|
when {
|
||||||
|
item.downloadCount == -1 -> -1
|
||||||
|
item.manga.source == LocalSource.ID -> -2
|
||||||
|
else -> item.downloadCount
|
||||||
|
},
|
||||||
|
item.chapterCount > -1)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when an item is released.
|
* Called when an item is released.
|
||||||
*
|
*
|
||||||
|
@ -28,6 +28,7 @@ class LibraryItem(val manga: LibraryManga,
|
|||||||
|
|
||||||
var downloadCount = -1
|
var downloadCount = -1
|
||||||
var unreadType = 1
|
var unreadType = 1
|
||||||
|
var chapterCount = -1
|
||||||
|
|
||||||
override fun getLayoutRes(): Int {
|
override fun getLayoutRes(): Int {
|
||||||
return if (libraryLayout.getOrDefault() == 0)
|
return if (libraryLayout.getOrDefault() == 0)
|
||||||
|
@ -7,7 +7,6 @@ import com.bumptech.glide.signature.ObjectKey
|
|||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.data.database.models.MangaImpl
|
import eu.kanade.tachiyomi.data.database.models.MangaImpl
|
||||||
import eu.kanade.tachiyomi.data.glide.GlideApp
|
import eu.kanade.tachiyomi.data.glide.GlideApp
|
||||||
import eu.kanade.tachiyomi.source.LocalSource
|
|
||||||
import kotlinx.android.synthetic.main.catalogue_list_item.*
|
import kotlinx.android.synthetic.main.catalogue_list_item.*
|
||||||
import kotlinx.android.synthetic.main.catalogue_list_item.view.*
|
import kotlinx.android.synthetic.main.catalogue_list_item.view.*
|
||||||
import kotlinx.android.synthetic.main.unread_download_badge.*
|
import kotlinx.android.synthetic.main.unread_download_badge.*
|
||||||
@ -36,18 +35,7 @@ class LibraryListHolder(
|
|||||||
override fun onSetValues(item: LibraryItem) {
|
override fun onSetValues(item: LibraryItem) {
|
||||||
// Update the title of the manga.
|
// Update the title of the manga.
|
||||||
title.text = item.manga.currentTitle()
|
title.text = item.manga.currentTitle()
|
||||||
|
setUnreadBadge(badge_view, item)
|
||||||
badge_view.setUnreadDownload(
|
|
||||||
when (item.unreadType) {
|
|
||||||
1 -> item.manga.unread
|
|
||||||
0 -> if (item.manga.unread > 0) -1 else -2
|
|
||||||
else -> -2
|
|
||||||
},
|
|
||||||
when {
|
|
||||||
item.downloadCount == -1 -> -1
|
|
||||||
item.manga.source == LocalSource.ID -> -2
|
|
||||||
else -> item.downloadCount
|
|
||||||
})
|
|
||||||
|
|
||||||
subtitle.text = item.manga.originalAuthor()?.trim()
|
subtitle.text = item.manga.originalAuthor()?.trim()
|
||||||
subtitle.visibility = if (!item.manga.originalAuthor().isNullOrBlank()) View.VISIBLE
|
subtitle.visibility = if (!item.manga.originalAuthor().isNullOrBlank()) View.VISIBLE
|
||||||
|
@ -79,6 +79,8 @@ class LibraryPresenter(
|
|||||||
|
|
||||||
private var currentMangaMap:LibraryMap? = null
|
private var currentMangaMap:LibraryMap? = null
|
||||||
|
|
||||||
|
private var totalChapters:Map<Long, Int>? = null
|
||||||
|
|
||||||
fun isDownloading() = downloadManager.hasQueue()
|
fun isDownloading() = downloadManager.hasQueue()
|
||||||
|
|
||||||
fun onDestroy() {
|
fun onDestroy() {
|
||||||
@ -94,6 +96,7 @@ class LibraryPresenter(
|
|||||||
|
|
||||||
fun getLibrary() {
|
fun getLibrary() {
|
||||||
launchUI {
|
launchUI {
|
||||||
|
totalChapters = null
|
||||||
val freshStart = !preferences.libraryAsSingleList().getOrDefault()
|
val freshStart = !preferences.libraryAsSingleList().getOrDefault()
|
||||||
&& (currentMangaMap?.values?.firstOrNull()?.firstOrNull()?.header != null)
|
&& (currentMangaMap?.values?.firstOrNull()?.firstOrNull()?.header != null)
|
||||||
val mangaMap = withContext(Dispatchers.IO) {
|
val mangaMap = withContext(Dispatchers.IO) {
|
||||||
@ -107,6 +110,9 @@ class LibraryPresenter(
|
|||||||
}
|
}
|
||||||
currentMangaMap = mangaMap
|
currentMangaMap = mangaMap
|
||||||
updateView(categories, mangaMap, freshStart)
|
updateView(categories, mangaMap, freshStart)
|
||||||
|
withContext(Dispatchers.IO) {
|
||||||
|
setTotalChapters()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -254,6 +260,8 @@ class LibraryPresenter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val sortFn: (LibraryItem, LibraryItem) -> Int = { i1, i2 ->
|
val sortFn: (LibraryItem, LibraryItem) -> Int = { i1, i2 ->
|
||||||
|
i1.chapterCount = -1
|
||||||
|
i2.chapterCount = -1
|
||||||
sortCategory(i1, i2, lastReadManga, category)
|
sortCategory(i1, i2, lastReadManga, category)
|
||||||
}
|
}
|
||||||
val comparator = Comparator(sortFn)
|
val comparator = Comparator(sortFn)
|
||||||
@ -273,16 +281,14 @@ class LibraryPresenter(
|
|||||||
var counter = 0
|
var counter = 0
|
||||||
db.getLastReadManga().executeAsBlocking().associate { it.id!! to counter++ }
|
db.getLastReadManga().executeAsBlocking().associate { it.id!! to counter++ }
|
||||||
}
|
}
|
||||||
val totalChapterManga by lazy {
|
|
||||||
var counter = 0
|
|
||||||
db.getTotalChapterManga().executeAsBlocking().associate { it.id!! to counter++ }
|
|
||||||
}
|
|
||||||
|
|
||||||
val ascending = preferences.librarySortingAscending().getOrDefault()
|
val ascending = preferences.librarySortingAscending().getOrDefault()
|
||||||
val useDnD = preferences.libraryAsSingleList().getOrDefault() && !preferences
|
val useDnD = preferences.libraryAsSingleList().getOrDefault() && !preferences
|
||||||
.hideCategories().getOrDefault()
|
.hideCategories().getOrDefault()
|
||||||
|
|
||||||
val sortFn: (LibraryItem, LibraryItem) -> Int = { i1, i2 ->
|
val sortFn: (LibraryItem, LibraryItem) -> Int = { i1, i2 ->
|
||||||
|
i1.chapterCount = -1
|
||||||
|
i2.chapterCount = -1
|
||||||
val compare = when {
|
val compare = when {
|
||||||
sortingMode == LibrarySort.DRAG_AND_DROP || useDnD ->
|
sortingMode == LibrarySort.DRAG_AND_DROP || useDnD ->
|
||||||
sortCategory(i1, i2, lastReadManga)
|
sortCategory(i1, i2, lastReadManga)
|
||||||
@ -303,8 +309,11 @@ class LibraryPresenter(
|
|||||||
else -> i1.manga.unread.compareTo(i2.manga.unread)
|
else -> i1.manga.unread.compareTo(i2.manga.unread)
|
||||||
}
|
}
|
||||||
sortingMode == LibrarySort.TOTAL -> {
|
sortingMode == LibrarySort.TOTAL -> {
|
||||||
val manga1TotalChapter = totalChapterManga[i1.manga.id!!] ?: 0
|
setTotalChapters()
|
||||||
val mange2TotalChapter = totalChapterManga[i2.manga.id!!] ?: 0
|
val manga1TotalChapter = totalChapters!![i1.manga.id!!] ?: 0
|
||||||
|
val mange2TotalChapter = totalChapters!![i2.manga.id!!] ?: 0
|
||||||
|
i1.chapterCount = totalChapters!![i1.manga.id!!] ?: 0
|
||||||
|
i2.chapterCount = totalChapters!![i2.manga.id!!] ?: 0
|
||||||
manga1TotalChapter.compareTo(mange2TotalChapter)
|
manga1TotalChapter.compareTo(mange2TotalChapter)
|
||||||
}
|
}
|
||||||
else -> 0
|
else -> 0
|
||||||
@ -324,11 +333,23 @@ class LibraryPresenter(
|
|||||||
return map.mapValues { entry -> entry.value.sortedWith(comparator) }
|
return map.mapValues { entry -> entry.value.sortedWith(comparator) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun setTotalChapters() {
|
||||||
|
if (totalChapters != null) return
|
||||||
|
val mangaMap = rawMangaMap ?: return
|
||||||
|
totalChapters = mangaMap.flatMap{
|
||||||
|
it.value
|
||||||
|
}.associate {
|
||||||
|
it.manga.id!! to db.getChapters(it.manga).executeAsBlocking().size
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun sortCategory(i1: LibraryItem, i2: LibraryItem,
|
private fun sortCategory(i1: LibraryItem, i2: LibraryItem,
|
||||||
lastReadManga: Map<Long, Int>, initCat: Category? = null): Int {
|
lastReadManga: Map<Long, Int>,
|
||||||
|
initCat: Category? = null):
|
||||||
|
Int {
|
||||||
return if (initCat != null || i1.manga.category == i2.manga.category) {
|
return if (initCat != null || i1.manga.category == i2.manga.category) {
|
||||||
val category = initCat ?: allCategories.find { it.id == i1.manga.category }
|
val category = initCat ?: allCategories.find { it.id == i1.manga.category }
|
||||||
when {
|
val compare = when {
|
||||||
category?.mangaSort != null -> {
|
category?.mangaSort != null -> {
|
||||||
var sort = when (category.sortingMode()) {
|
var sort = when (category.sortingMode()) {
|
||||||
LibrarySort.ALPHA -> sortAlphabetical(i1, i2)
|
LibrarySort.ALPHA -> sortAlphabetical(i1, i2)
|
||||||
@ -344,6 +365,14 @@ class LibraryPresenter(
|
|||||||
val manga2LastRead = lastReadManga[i2.manga.id!!] ?: lastReadManga.size
|
val manga2LastRead = lastReadManga[i2.manga.id!!] ?: lastReadManga.size
|
||||||
manga1LastRead.compareTo(manga2LastRead)
|
manga1LastRead.compareTo(manga2LastRead)
|
||||||
}
|
}
|
||||||
|
LibrarySort.TOTAL -> {
|
||||||
|
setTotalChapters()
|
||||||
|
val manga1TotalChapter = totalChapters!![i1.manga.id!!] ?: 0
|
||||||
|
val mange2TotalChapter = totalChapters!![i2.manga.id!!] ?: 0
|
||||||
|
i1.chapterCount = totalChapters!![i1.manga.id!!] ?: 0
|
||||||
|
i2.chapterCount = totalChapters!![i2.manga.id!!] ?: 0
|
||||||
|
manga1TotalChapter.compareTo(mange2TotalChapter)
|
||||||
|
}
|
||||||
else -> sortAlphabetical(i1, i2)
|
else -> sortAlphabetical(i1, i2)
|
||||||
}
|
}
|
||||||
if (!category.isAscending())
|
if (!category.isAscending())
|
||||||
@ -363,6 +392,11 @@ class LibraryPresenter(
|
|||||||
}
|
}
|
||||||
else -> 0
|
else -> 0
|
||||||
}
|
}
|
||||||
|
if (compare == 0) {
|
||||||
|
if (category?.isAscending() != false) sortAlphabetical(i1, i2)
|
||||||
|
else sortAlphabetical(i2, i1)
|
||||||
|
}
|
||||||
|
else compare
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
val category = allCategories.find { it.id == i1.manga.category }?.order ?: -1
|
val category = allCategories.find { it.id == i1.manga.category }?.order ?: -1
|
||||||
@ -620,9 +654,7 @@ class LibraryPresenter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rawMangaMap = rawMap
|
getLibrary()
|
||||||
currentMangaMap = currentMap
|
|
||||||
requestSortUpdate()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -516,6 +516,7 @@ class SortFilterBottomSheet @JvmOverloads constructor(context: Context, attrs: A
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
val order = when (menuId) {
|
val order = when (menuId) {
|
||||||
|
R.id.action_total_chaps -> 4
|
||||||
R.id.action_last_read -> 3
|
R.id.action_last_read -> 3
|
||||||
R.id.action_unread -> 2
|
R.id.action_unread -> 2
|
||||||
R.id.action_update -> 1
|
R.id.action_update -> 1
|
||||||
|
@ -16,8 +16,14 @@
|
|||||||
android:id="@+id/action_update"
|
android:id="@+id/action_update"
|
||||||
android:title="@string/action_sort_last_updated"
|
android:title="@string/action_sort_last_updated"
|
||||||
android:icon="@drawable/ic_blank_24dp"/>
|
android:icon="@drawable/ic_blank_24dp"/>
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_unread"
|
android:id="@+id/action_unread"
|
||||||
android:title="@string/action_filter_unread"
|
android:title="@string/action_filter_unread"
|
||||||
android:icon="@drawable/ic_blank_24dp"/>
|
android:icon="@drawable/ic_blank_24dp"/>
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_total_chaps"
|
||||||
|
android:title="@string/action_sort_total"
|
||||||
|
android:icon="@drawable/ic_blank_24dp"/>
|
||||||
</menu>
|
</menu>
|
Loading…
Reference in New Issue
Block a user