mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
Support chapter length in filtered library/stats
All that leaves is category, which I wont bother with Also show "x chapters" in the length Also part of last commit: show a star beside score in details page
This commit is contained in:
parent
f75c3d7acf
commit
0b9cf41c75
6 changed files with 56 additions and 23 deletions
|
@ -26,6 +26,8 @@ class FilteredLibraryController(bundle: Bundle? = null) : LibraryController(bund
|
||||||
private set
|
private set
|
||||||
var filterStartYear: Int = 0
|
var filterStartYear: Int = 0
|
||||||
private set
|
private set
|
||||||
|
var filterLength: IntRange? = null
|
||||||
|
private set
|
||||||
|
|
||||||
private var customTitle: String? = null
|
private var customTitle: String? = null
|
||||||
|
|
||||||
|
@ -44,6 +46,7 @@ class FilteredLibraryController(bundle: Bundle? = null) : LibraryController(bund
|
||||||
filterTrackerName: String? = null,
|
filterTrackerName: String? = null,
|
||||||
filterTrackingScore: Int = 0,
|
filterTrackingScore: Int = 0,
|
||||||
filterStartYear: Int = 0,
|
filterStartYear: Int = 0,
|
||||||
|
filterLength: IntRange? = null,
|
||||||
) : this() {
|
) : this() {
|
||||||
customTitle = title
|
customTitle = title
|
||||||
this.filterStatus = filterStatus
|
this.filterStatus = filterStatus
|
||||||
|
@ -56,6 +59,7 @@ class FilteredLibraryController(bundle: Bundle? = null) : LibraryController(bund
|
||||||
}
|
}
|
||||||
this.filterTrackingScore = filterTrackingScore
|
this.filterTrackingScore = filterTrackingScore
|
||||||
this.filterStartYear = filterStartYear
|
this.filterStartYear = filterStartYear
|
||||||
|
this.filterLength = filterLength
|
||||||
this.queryText = queryText
|
this.queryText = queryText
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -427,6 +427,10 @@ class LibraryPresenter(
|
||||||
val mangaStartingYear = item.manga.getStartYear()
|
val mangaStartingYear = item.manga.getStartYear()
|
||||||
if (mangaStartingYear != startingYear) return false
|
if (mangaStartingYear != startingYear) return false
|
||||||
}
|
}
|
||||||
|
val mangaLength = customFilters.filterLength
|
||||||
|
if (mangaLength != null) {
|
||||||
|
if (item.manga.totalChapters !in mangaLength) return false
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -70,14 +70,14 @@ object StatsHelper {
|
||||||
)
|
)
|
||||||
|
|
||||||
val STATS_LENGTH = arrayListOf(
|
val STATS_LENGTH = arrayListOf(
|
||||||
0 to 0,
|
0..0,
|
||||||
1 to 1,
|
1..1,
|
||||||
2 to 10,
|
2..10,
|
||||||
11 to 25,
|
11..25,
|
||||||
26 to 50,
|
26..50,
|
||||||
51 to 100,
|
51..100,
|
||||||
101 to 200,
|
101..200,
|
||||||
201 to null,
|
201..Int.MAX_VALUE,
|
||||||
)
|
)
|
||||||
|
|
||||||
fun Long.getReadDuration(blankValue: String = "0"): String {
|
fun Long.getReadDuration(blankValue: String = "0"): String {
|
||||||
|
|
|
@ -64,17 +64,7 @@ class StatsDetailsAdapter(
|
||||||
holder.itemView.setOnClickListener {
|
holder.itemView.setOnClickListener {
|
||||||
list[position].let { item -> listener?.onItemClicked(item.id, item.label) }
|
list[position].let { item -> listener?.onItemClicked(item.id, item.label) }
|
||||||
}
|
}
|
||||||
holder.itemView.isClickable = stat in arrayOf(
|
holder.itemView.isClickable = stat != Stats.CATEGORY
|
||||||
Stats.SERIES_TYPE,
|
|
||||||
Stats.STATUS,
|
|
||||||
Stats.READ_DURATION,
|
|
||||||
Stats.SCORE,
|
|
||||||
Stats.LANGUAGE,
|
|
||||||
Stats.SOURCE,
|
|
||||||
Stats.TRACKER,
|
|
||||||
Stats.TAG,
|
|
||||||
Stats.START_YEAR,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getItemCount(): Int {
|
override fun getItemCount(): Int {
|
||||||
|
@ -92,7 +82,15 @@ class StatsDetailsAdapter(
|
||||||
statsLabelText.setTextColor(
|
statsLabelText.setTextColor(
|
||||||
item.color ?: context.getResourceColor(R.attr.colorOnBackground),
|
item.color ?: context.getResourceColor(R.attr.colorOnBackground),
|
||||||
)
|
)
|
||||||
statsLabelText.text = item.label?.uppercase()
|
val label = item.label?.let {
|
||||||
|
if (stat == Stats.LENGTH) {
|
||||||
|
val max = item.id?.toInt() ?: 0
|
||||||
|
root.resources.getQuantityString(R.plurals.chapters_plural, max, it)
|
||||||
|
} else {
|
||||||
|
it
|
||||||
|
}
|
||||||
|
} ?: ""
|
||||||
|
statsLabelText.text = label.uppercase()
|
||||||
if (item.iconRes != null) {
|
if (item.iconRes != null) {
|
||||||
logoContainer.isVisible = true
|
logoContainer.isVisible = true
|
||||||
item.iconBGColor?.let { logoContainer.setCardBackgroundColor(it) }
|
item.iconBGColor?.let { logoContainer.setCardBackgroundColor(it) }
|
||||||
|
|
|
@ -602,7 +602,11 @@ class StatsDetailsController :
|
||||||
Stats.SOURCE, Stats.TAG, Stats.STATUS, Stats.SERIES_TYPE, Stats.SCORE, Stats.START_YEAR, Stats.LANGUAGE -> {
|
Stats.SOURCE, Stats.TAG, Stats.STATUS, Stats.SERIES_TYPE, Stats.SCORE, Stats.START_YEAR, Stats.LANGUAGE -> {
|
||||||
router.pushController(
|
router.pushController(
|
||||||
FilteredLibraryController(
|
FilteredLibraryController(
|
||||||
name,
|
if (selectedStat == Stats.SCORE) {
|
||||||
|
name + if (name.toIntOrNull() != null) "★" else ""
|
||||||
|
} else {
|
||||||
|
name
|
||||||
|
},
|
||||||
queryText = if (selectedStat == Stats.TAG) name else null,
|
queryText = if (selectedStat == Stats.TAG) name else null,
|
||||||
filterMangaType = when (selectedStat) {
|
filterMangaType = when (selectedStat) {
|
||||||
Stats.SERIES_TYPE -> arrayOf(presenter.seriesTypeStats.indexOf(name) + 1)
|
Stats.SERIES_TYPE -> arrayOf(presenter.seriesTypeStats.indexOf(name) + 1)
|
||||||
|
@ -653,6 +657,27 @@ class StatsDetailsController :
|
||||||
).withFadeTransaction(),
|
).withFadeTransaction(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Stats.LENGTH -> {
|
||||||
|
val range: IntRange = if (name.contains("-")) {
|
||||||
|
val values = name.split("-").map { it.toInt() }
|
||||||
|
IntRange(values.min(), values.max())
|
||||||
|
} else if (name.contains("+")) {
|
||||||
|
val values = name.split("+").mapNotNull { it.toIntOrNull() }
|
||||||
|
IntRange(values[0], Int.MAX_VALUE)
|
||||||
|
} else {
|
||||||
|
IntRange(name.toInt(), name.toInt())
|
||||||
|
}
|
||||||
|
router.pushController(
|
||||||
|
FilteredLibraryController(
|
||||||
|
binding.root.resources.getQuantityString(R.plurals.chapters_plural, range.last, name),
|
||||||
|
filterMangaType = seriesTypes,
|
||||||
|
filterStatus = statuses,
|
||||||
|
filterSources = sources,
|
||||||
|
filterLanguages = languages,
|
||||||
|
filterLength = range,
|
||||||
|
).withFadeTransaction(),
|
||||||
|
)
|
||||||
|
}
|
||||||
Stats.READ_DURATION -> {
|
Stats.READ_DURATION -> {
|
||||||
id?.let {
|
id?.let {
|
||||||
router.pushController(MangaDetailsController(id).withFadeTransaction())
|
router.pushController(MangaDetailsController(id).withFadeTransaction())
|
||||||
|
|
|
@ -219,8 +219,9 @@ class StatsDetailsPresenter(
|
||||||
private fun setupLength() {
|
private fun setupLength() {
|
||||||
currentStats = ArrayList()
|
currentStats = ArrayList()
|
||||||
var mangaFiltered = mangasDistinct.filterByChip()
|
var mangaFiltered = mangasDistinct.filterByChip()
|
||||||
StatsHelper.STATS_LENGTH.forEach { (min, max) ->
|
StatsHelper.STATS_LENGTH.forEach { range ->
|
||||||
val (match, unmatch) = mangaFiltered.partition { it.totalChapters >= min && (max == null || it.totalChapters <= max) }
|
val (min, max) = range.first to range.last.takeIf { it != Int.MAX_VALUE }
|
||||||
|
val (match, unmatch) = mangaFiltered.partition { it.totalChapters in range }
|
||||||
mangaFiltered = unmatch
|
mangaFiltered = unmatch
|
||||||
currentStats?.add(
|
currentStats?.add(
|
||||||
StatsData(
|
StatsData(
|
||||||
|
@ -236,6 +237,7 @@ class StatsDetailsPresenter(
|
||||||
.replace("-null", "+")
|
.replace("-null", "+")
|
||||||
},
|
},
|
||||||
readDuration = match.getReadDuration(),
|
readDuration = match.getReadDuration(),
|
||||||
|
id = range.last.toLong(),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue