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
|
||||
var filterStartYear: Int = 0
|
||||
private set
|
||||
var filterLength: IntRange? = null
|
||||
private set
|
||||
|
||||
private var customTitle: String? = null
|
||||
|
||||
|
@ -44,6 +46,7 @@ class FilteredLibraryController(bundle: Bundle? = null) : LibraryController(bund
|
|||
filterTrackerName: String? = null,
|
||||
filterTrackingScore: Int = 0,
|
||||
filterStartYear: Int = 0,
|
||||
filterLength: IntRange? = null,
|
||||
) : this() {
|
||||
customTitle = title
|
||||
this.filterStatus = filterStatus
|
||||
|
@ -56,6 +59,7 @@ class FilteredLibraryController(bundle: Bundle? = null) : LibraryController(bund
|
|||
}
|
||||
this.filterTrackingScore = filterTrackingScore
|
||||
this.filterStartYear = filterStartYear
|
||||
this.filterLength = filterLength
|
||||
this.queryText = queryText
|
||||
}
|
||||
|
||||
|
|
|
@ -427,6 +427,10 @@ class LibraryPresenter(
|
|||
val mangaStartingYear = item.manga.getStartYear()
|
||||
if (mangaStartingYear != startingYear) return false
|
||||
}
|
||||
val mangaLength = customFilters.filterLength
|
||||
if (mangaLength != null) {
|
||||
if (item.manga.totalChapters !in mangaLength) return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
|
|
|
@ -70,14 +70,14 @@ object StatsHelper {
|
|||
)
|
||||
|
||||
val STATS_LENGTH = arrayListOf(
|
||||
0 to 0,
|
||||
1 to 1,
|
||||
2 to 10,
|
||||
11 to 25,
|
||||
26 to 50,
|
||||
51 to 100,
|
||||
101 to 200,
|
||||
201 to null,
|
||||
0..0,
|
||||
1..1,
|
||||
2..10,
|
||||
11..25,
|
||||
26..50,
|
||||
51..100,
|
||||
101..200,
|
||||
201..Int.MAX_VALUE,
|
||||
)
|
||||
|
||||
fun Long.getReadDuration(blankValue: String = "0"): String {
|
||||
|
|
|
@ -64,17 +64,7 @@ class StatsDetailsAdapter(
|
|||
holder.itemView.setOnClickListener {
|
||||
list[position].let { item -> listener?.onItemClicked(item.id, item.label) }
|
||||
}
|
||||
holder.itemView.isClickable = stat in arrayOf(
|
||||
Stats.SERIES_TYPE,
|
||||
Stats.STATUS,
|
||||
Stats.READ_DURATION,
|
||||
Stats.SCORE,
|
||||
Stats.LANGUAGE,
|
||||
Stats.SOURCE,
|
||||
Stats.TRACKER,
|
||||
Stats.TAG,
|
||||
Stats.START_YEAR,
|
||||
)
|
||||
holder.itemView.isClickable = stat != Stats.CATEGORY
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
|
@ -92,7 +82,15 @@ class StatsDetailsAdapter(
|
|||
statsLabelText.setTextColor(
|
||||
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) {
|
||||
logoContainer.isVisible = true
|
||||
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 -> {
|
||||
router.pushController(
|
||||
FilteredLibraryController(
|
||||
name,
|
||||
if (selectedStat == Stats.SCORE) {
|
||||
name + if (name.toIntOrNull() != null) "★" else ""
|
||||
} else {
|
||||
name
|
||||
},
|
||||
queryText = if (selectedStat == Stats.TAG) name else null,
|
||||
filterMangaType = when (selectedStat) {
|
||||
Stats.SERIES_TYPE -> arrayOf(presenter.seriesTypeStats.indexOf(name) + 1)
|
||||
|
@ -653,6 +657,27 @@ class StatsDetailsController :
|
|||
).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 -> {
|
||||
id?.let {
|
||||
router.pushController(MangaDetailsController(id).withFadeTransaction())
|
||||
|
|
|
@ -219,8 +219,9 @@ class StatsDetailsPresenter(
|
|||
private fun setupLength() {
|
||||
currentStats = ArrayList()
|
||||
var mangaFiltered = mangasDistinct.filterByChip()
|
||||
StatsHelper.STATS_LENGTH.forEach { (min, max) ->
|
||||
val (match, unmatch) = mangaFiltered.partition { it.totalChapters >= min && (max == null || it.totalChapters <= max) }
|
||||
StatsHelper.STATS_LENGTH.forEach { range ->
|
||||
val (min, max) = range.first to range.last.takeIf { it != Int.MAX_VALUE }
|
||||
val (match, unmatch) = mangaFiltered.partition { it.totalChapters in range }
|
||||
mangaFiltered = unmatch
|
||||
currentStats?.add(
|
||||
StatsData(
|
||||
|
@ -236,6 +237,7 @@ class StatsDetailsPresenter(
|
|||
.replace("-null", "+")
|
||||
},
|
||||
readDuration = match.getReadDuration(),
|
||||
id = range.last.toLong(),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue