Branch selection in chapters list
parent
8c79df3d35
commit
ee10b013a1
@ -0,0 +1,13 @@
|
|||||||
|
package org.koitharu.kotatsu.core.model
|
||||||
|
|
||||||
|
import org.koitharu.kotatsu.core.ui.widgets.ChipsView
|
||||||
|
import org.koitharu.kotatsu.list.domain.ListFilterOption
|
||||||
|
|
||||||
|
fun ListFilterOption.toChipModel(isChecked: Boolean) = ChipsView.ChipModel(
|
||||||
|
title = titleText,
|
||||||
|
titleResId = titleResId,
|
||||||
|
icon = iconResId,
|
||||||
|
iconData = getIconData(),
|
||||||
|
isChecked = isChecked,
|
||||||
|
data = this,
|
||||||
|
)
|
||||||
@ -0,0 +1,35 @@
|
|||||||
|
package org.koitharu.kotatsu.core.util
|
||||||
|
|
||||||
|
import androidx.core.os.LocaleListCompat
|
||||||
|
import org.koitharu.kotatsu.core.util.ext.iterator
|
||||||
|
|
||||||
|
class LocaleStringComparator : Comparator<String?> {
|
||||||
|
|
||||||
|
private val deviceLocales: List<String?>
|
||||||
|
|
||||||
|
init {
|
||||||
|
val localeList = LocaleListCompat.getAdjustedDefault()
|
||||||
|
deviceLocales = buildList(localeList.size() + 1) {
|
||||||
|
add(null)
|
||||||
|
val set = HashSet<String?>(localeList.size() + 1)
|
||||||
|
set.add(null)
|
||||||
|
for (locale in localeList) {
|
||||||
|
val lang = locale.getDisplayLanguage(locale).lowercase()
|
||||||
|
if (set.add(lang)) {
|
||||||
|
add(lang)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun compare(a: String?, b: String?): Int {
|
||||||
|
val indexA = deviceLocales.indexOf(a?.lowercase())
|
||||||
|
val indexB = deviceLocales.indexOf(b?.lowercase())
|
||||||
|
return when {
|
||||||
|
indexA < 0 && indexB < 0 -> compareValues(a, b)
|
||||||
|
indexA < 0 -> 1
|
||||||
|
indexB < 0 -> -1
|
||||||
|
else -> compareValues(indexA, indexB)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,8 +1,11 @@
|
|||||||
package org.koitharu.kotatsu.details.domain
|
package org.koitharu.kotatsu.details.domain
|
||||||
|
|
||||||
|
import org.koitharu.kotatsu.core.util.LocaleStringComparator
|
||||||
import org.koitharu.kotatsu.details.ui.model.MangaBranch
|
import org.koitharu.kotatsu.details.ui.model.MangaBranch
|
||||||
|
|
||||||
class BranchComparator : Comparator<MangaBranch> {
|
class BranchComparator : Comparator<MangaBranch> {
|
||||||
|
|
||||||
override fun compare(o1: MangaBranch, o2: MangaBranch): Int = compareValues(o1.name, o2.name)
|
private val delegate = LocaleStringComparator()
|
||||||
|
|
||||||
|
override fun compare(o1: MangaBranch, o2: MangaBranch): Int = delegate.compare(o1.name, o2.name)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,16 @@
|
|||||||
|
package org.koitharu.kotatsu.details.ui
|
||||||
|
|
||||||
|
import android.view.View
|
||||||
|
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||||
|
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
||||||
|
|
||||||
|
class DetailsBottomSheetCallback(
|
||||||
|
private val swipeRefreshLayout: SwipeRefreshLayout,
|
||||||
|
) : BottomSheetBehavior.BottomSheetCallback() {
|
||||||
|
|
||||||
|
override fun onStateChanged(bottomSheet: View, newState: Int) {
|
||||||
|
swipeRefreshLayout.isEnabled = newState == BottomSheetBehavior.STATE_COLLAPSED
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onSlide(bottomSheet: View, slideOffset: Float) = Unit
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue