Show chapters count for branches
This commit is contained in:
@@ -9,5 +9,6 @@ fun ListFilterOption.toChipModel(isChecked: Boolean) = ChipsView.ChipModel(
|
||||
icon = iconResId,
|
||||
iconData = getIconData(),
|
||||
isChecked = isChecked,
|
||||
counter = if (this is ListFilterOption.Branch) chaptersCount else 0,
|
||||
data = this,
|
||||
)
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
package org.koitharu.kotatsu.core.ui.widgets
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
import android.text.style.ForegroundColorSpan
|
||||
import android.text.style.RelativeSizeSpan
|
||||
import android.util.AttributeSet
|
||||
import android.view.View
|
||||
import androidx.annotation.ColorRes
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.text.buildSpannedString
|
||||
import androidx.core.text.inSpans
|
||||
import androidx.core.view.children
|
||||
import androidx.lifecycle.findViewTreeLifecycleOwner
|
||||
import coil3.ImageLoader
|
||||
@@ -27,6 +32,7 @@ import dagger.hilt.android.AndroidEntryPoint
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.core.ui.image.ChipIconTarget
|
||||
import org.koitharu.kotatsu.core.util.ext.enqueueWith
|
||||
import org.koitharu.kotatsu.core.util.ext.getThemeColor
|
||||
import org.koitharu.kotatsu.core.util.ext.setProgressIcon
|
||||
import org.koitharu.kotatsu.parsers.util.ifZero
|
||||
import javax.inject.Inject
|
||||
@@ -116,6 +122,7 @@ class ChipsView @JvmOverloads constructor(
|
||||
@DrawableRes val icon: Int = 0,
|
||||
val iconData: Any? = null,
|
||||
@ColorRes val tint: Int = 0,
|
||||
val counter: Int = 0,
|
||||
val isChecked: Boolean = false,
|
||||
val isLoading: Boolean = false,
|
||||
val isDropdown: Boolean = false,
|
||||
@@ -147,7 +154,28 @@ class ChipsView @JvmOverloads constructor(
|
||||
}
|
||||
this.model = model
|
||||
|
||||
if (model.titleResId == 0) {
|
||||
if (model.counter > 0) {
|
||||
text = buildSpannedString {
|
||||
if (model.titleResId == 0) {
|
||||
append(model.title)
|
||||
} else {
|
||||
append(context.getString(model.titleResId))
|
||||
}
|
||||
append(' ')
|
||||
append(' ')
|
||||
inSpans(
|
||||
ForegroundColorSpan(
|
||||
context.getThemeColor(
|
||||
android.R.attr.textColorSecondary,
|
||||
Color.LTGRAY,
|
||||
),
|
||||
),
|
||||
RelativeSizeSpan(0.74f),
|
||||
) {
|
||||
append(model.counter.toString())
|
||||
}
|
||||
}
|
||||
} else if (model.titleResId == 0) {
|
||||
text = model.title
|
||||
} else {
|
||||
setText(model.titleResId)
|
||||
|
||||
@@ -134,9 +134,14 @@ abstract class ChaptersPagesViewModel(
|
||||
mangaDetails,
|
||||
selectedBranch,
|
||||
) { details, branch ->
|
||||
val branches = details?.chapters?.keys?.sortedWithSafe(LocaleStringComparator()).orEmpty()
|
||||
val branches = details?.chapters?.toList()?.sortedWithSafe(
|
||||
compareBy(LocaleStringComparator()) { it.first },
|
||||
).orEmpty()
|
||||
if (branches.size > 1) {
|
||||
branches.map { ListFilterOption.Branch(it).toChipModel(it == branch) }
|
||||
branches.map {
|
||||
val option = ListFilterOption.Branch(titleText = it.first, chaptersCount = it.second.size)
|
||||
option.toChipModel(isChecked = it.first == branch)
|
||||
}
|
||||
} else {
|
||||
emptyList()
|
||||
}
|
||||
|
||||
@@ -62,6 +62,7 @@ sealed interface ListFilterOption {
|
||||
|
||||
data class Branch(
|
||||
override val titleText: String?,
|
||||
val chaptersCount: Int,
|
||||
) : ListFilterOption {
|
||||
|
||||
override val titleResId: Int
|
||||
|
||||
Reference in New Issue
Block a user