mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
Replace INVERSED/UNDETERMINATE for IGNORE in TriStateCheckBox
This commit is contained in:
parent
4f2bf33b21
commit
c6a9cb32ea
11 changed files with 54 additions and 55 deletions
|
@ -188,7 +188,7 @@ class ManageCategoryDialog(bundle: Bundle? = null) :
|
|||
updateCategories.add(categoryId.toString())
|
||||
excludeUpdateCategories.remove(categoryId.toString())
|
||||
}
|
||||
TriStateCheckBox.State.INVERSED -> {
|
||||
TriStateCheckBox.State.IGNORE -> {
|
||||
updateCategories.remove(categoryId.toString())
|
||||
excludeUpdateCategories.add(categoryId.toString())
|
||||
}
|
||||
|
@ -213,7 +213,7 @@ class ManageCategoryDialog(bundle: Bundle? = null) :
|
|||
box.isVisible = (updateCategories.isNotEmpty() || excludeUpdateCategories.isNotEmpty()) && shouldShow
|
||||
if (shouldShow) box.state = when {
|
||||
updateCategories.any { category?.id == it.toIntOrNull() } -> TriStateCheckBox.State.CHECKED
|
||||
excludeUpdateCategories.any { category?.id == it.toIntOrNull() } -> TriStateCheckBox.State.INVERSED
|
||||
excludeUpdateCategories.any { category?.id == it.toIntOrNull() } -> TriStateCheckBox.State.IGNORE
|
||||
else -> TriStateCheckBox.State.UNCHECKED
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ class AddCategoryItem(val category: Category) : AbstractItem<FastAdapter.ViewHol
|
|||
val binding = AddCategoryItemBinding.bind(view)
|
||||
|
||||
init {
|
||||
binding.categoryCheckbox.useIndeterminateForInverse = true
|
||||
binding.categoryCheckbox.useIndeterminateForIgnore = true
|
||||
}
|
||||
|
||||
override fun bindView(item: AddCategoryItem, payloads: List<Any>) {
|
||||
|
|
|
@ -69,7 +69,7 @@ class SetCategoriesSheet(
|
|||
category.takeIf { preselected[index] == TriStateCheckBox.State.CHECKED }
|
||||
}
|
||||
private val preIndeterminateCategories = categories.mapIndexedNotNull { index, category ->
|
||||
category.takeIf { preselected[index] == TriStateCheckBox.State.INDETERMINATE }
|
||||
category.takeIf { preselected[index] == TriStateCheckBox.State.IGNORE }
|
||||
}
|
||||
private val selectedCategories = preIndeterminateCategories + preCheckedCategories
|
||||
|
||||
|
@ -80,7 +80,7 @@ class SetCategoriesSheet(
|
|||
get() = itemAdapter.adapterItems.filter { it.state == TriStateCheckBox.State.CHECKED }.toSet()
|
||||
|
||||
private val indeterminateItems: Set<AddCategoryItem>
|
||||
get() = itemAdapter.adapterItems.filter { it.state == TriStateCheckBox.State.INDETERMINATE }.toSet()
|
||||
get() = itemAdapter.adapterItems.filter { it.state == TriStateCheckBox.State.IGNORE }.toSet()
|
||||
|
||||
private val uncheckedItems: Set<AddCategoryItem>
|
||||
get() = itemAdapter.adapterItems.filter { !it.isSelected }.toSet()
|
||||
|
@ -135,7 +135,7 @@ class SetCategoriesSheet(
|
|||
itemAdapter.set(
|
||||
categories.mapIndexed { index, category ->
|
||||
AddCategoryItem(category).apply {
|
||||
skipInversed = preselected[index] != TriStateCheckBox.State.INDETERMINATE
|
||||
skipInversed = preselected[index] != TriStateCheckBox.State.IGNORE
|
||||
state = preselected[index]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -540,17 +540,17 @@ class MangaDetailsPresenter(
|
|||
) {
|
||||
manga.readFilter = when (unread) {
|
||||
TriStateCheckBox.State.CHECKED -> Manga.CHAPTER_SHOW_UNREAD
|
||||
TriStateCheckBox.State.INVERSED -> Manga.CHAPTER_SHOW_READ
|
||||
TriStateCheckBox.State.IGNORE -> Manga.CHAPTER_SHOW_READ
|
||||
else -> Manga.SHOW_ALL
|
||||
}
|
||||
manga.downloadedFilter = when (downloaded) {
|
||||
TriStateCheckBox.State.CHECKED -> Manga.CHAPTER_SHOW_DOWNLOADED
|
||||
TriStateCheckBox.State.INVERSED -> Manga.CHAPTER_SHOW_NOT_DOWNLOADED
|
||||
TriStateCheckBox.State.IGNORE -> Manga.CHAPTER_SHOW_NOT_DOWNLOADED
|
||||
else -> Manga.SHOW_ALL
|
||||
}
|
||||
manga.bookmarkedFilter = when (bookmarked) {
|
||||
TriStateCheckBox.State.CHECKED -> Manga.CHAPTER_SHOW_BOOKMARKED
|
||||
TriStateCheckBox.State.INVERSED -> Manga.CHAPTER_SHOW_NOT_BOOKMARKED
|
||||
TriStateCheckBox.State.IGNORE -> Manga.CHAPTER_SHOW_NOT_BOOKMARKED
|
||||
else -> Manga.SHOW_ALL
|
||||
}
|
||||
manga.setFilterToLocal()
|
||||
|
@ -587,21 +587,21 @@ class MangaDetailsPresenter(
|
|||
preferences.filterChapterByRead().set(
|
||||
when (unread) {
|
||||
TriStateCheckBox.State.CHECKED -> Manga.CHAPTER_SHOW_UNREAD
|
||||
TriStateCheckBox.State.INVERSED -> Manga.CHAPTER_SHOW_READ
|
||||
TriStateCheckBox.State.IGNORE -> Manga.CHAPTER_SHOW_READ
|
||||
else -> Manga.SHOW_ALL
|
||||
}
|
||||
)
|
||||
preferences.filterChapterByDownloaded().set(
|
||||
when (downloaded) {
|
||||
TriStateCheckBox.State.CHECKED -> Manga.CHAPTER_SHOW_DOWNLOADED
|
||||
TriStateCheckBox.State.INVERSED -> Manga.CHAPTER_SHOW_NOT_DOWNLOADED
|
||||
TriStateCheckBox.State.IGNORE -> Manga.CHAPTER_SHOW_NOT_DOWNLOADED
|
||||
else -> Manga.SHOW_ALL
|
||||
}
|
||||
)
|
||||
preferences.filterChapterByBookmarked().set(
|
||||
when (bookmarked) {
|
||||
TriStateCheckBox.State.CHECKED -> Manga.CHAPTER_SHOW_BOOKMARKED
|
||||
TriStateCheckBox.State.INVERSED -> Manga.CHAPTER_SHOW_NOT_BOOKMARKED
|
||||
TriStateCheckBox.State.IGNORE -> Manga.CHAPTER_SHOW_NOT_BOOKMARKED
|
||||
else -> Manga.SHOW_ALL
|
||||
}
|
||||
)
|
||||
|
|
|
@ -49,17 +49,17 @@ class ChapterFilterLayout @JvmOverloads constructor(context: Context, attrs: Att
|
|||
fun setCheckboxes(manga: Manga, preferences: PreferencesHelper) {
|
||||
binding.showUnread.state = when (manga.readFilter(preferences)) {
|
||||
Manga.CHAPTER_SHOW_UNREAD -> TriStateCheckBox.State.CHECKED
|
||||
Manga.CHAPTER_SHOW_READ -> TriStateCheckBox.State.INVERSED
|
||||
Manga.CHAPTER_SHOW_READ -> TriStateCheckBox.State.IGNORE
|
||||
else -> TriStateCheckBox.State.UNCHECKED
|
||||
}
|
||||
binding.showDownload.state = when (manga.downloadedFilter(preferences)) {
|
||||
Manga.CHAPTER_SHOW_DOWNLOADED -> TriStateCheckBox.State.CHECKED
|
||||
Manga.CHAPTER_SHOW_NOT_DOWNLOADED -> TriStateCheckBox.State.INVERSED
|
||||
Manga.CHAPTER_SHOW_NOT_DOWNLOADED -> TriStateCheckBox.State.IGNORE
|
||||
else -> TriStateCheckBox.State.UNCHECKED
|
||||
}
|
||||
binding.showBookmark.state = when (manga.bookmarkedFilter(preferences)) {
|
||||
Manga.CHAPTER_SHOW_BOOKMARKED -> TriStateCheckBox.State.CHECKED
|
||||
Manga.CHAPTER_SHOW_NOT_BOOKMARKED -> TriStateCheckBox.State.INVERSED
|
||||
Manga.CHAPTER_SHOW_NOT_BOOKMARKED -> TriStateCheckBox.State.IGNORE
|
||||
else -> TriStateCheckBox.State.UNCHECKED
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ open class TriStateItem(val filter: Filter.TriState) : AbstractFlexibleItem<TriS
|
|||
view.state = when (filter.state) {
|
||||
Filter.TriState.STATE_IGNORE -> TriStateCheckBox.State.UNCHECKED
|
||||
Filter.TriState.STATE_INCLUDE -> TriStateCheckBox.State.CHECKED
|
||||
Filter.TriState.STATE_EXCLUDE -> TriStateCheckBox.State.INVERSED
|
||||
Filter.TriState.STATE_EXCLUDE -> TriStateCheckBox.State.IGNORE
|
||||
else -> throw Exception("Unknown state")
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,7 @@ open class TriStateItem(val filter: Filter.TriState) : AbstractFlexibleItem<TriS
|
|||
filter.state = when (state) {
|
||||
TriStateCheckBox.State.UNCHECKED -> Filter.TriState.STATE_IGNORE
|
||||
TriStateCheckBox.State.CHECKED -> Filter.TriState.STATE_INCLUDE
|
||||
else -> Filter.TriState.STATE_EXCLUDE
|
||||
TriStateCheckBox.State.IGNORE -> Filter.TriState.STATE_EXCLUDE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -89,7 +89,7 @@ fun List<Manga>.moveCategories(
|
|||
categories.map {
|
||||
when (it) {
|
||||
in commonCategories -> TriStateCheckBox.State.CHECKED
|
||||
in mixedCategories -> TriStateCheckBox.State.INDETERMINATE
|
||||
in mixedCategories -> TriStateCheckBox.State.IGNORE
|
||||
else -> TriStateCheckBox.State.UNCHECKED
|
||||
}
|
||||
}.toTypedArray(),
|
||||
|
|
|
@ -118,7 +118,7 @@ internal fun MaterialAlertDialogBuilder.setNegativeStateItems(
|
|||
items = items,
|
||||
initialSelection = initialSelection.map {
|
||||
if (it) {
|
||||
TriStateCheckBox.State.INVERSED.ordinal
|
||||
TriStateCheckBox.State.IGNORE.ordinal
|
||||
} else {
|
||||
TriStateCheckBox.State.UNCHECKED.ordinal
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ internal fun MaterialAlertDialogBuilder.setNegativeStateItems(
|
|||
.toIntArray(),
|
||||
skipChecked = true
|
||||
) { _, _, _, index, state ->
|
||||
listener.onClick(null, index, state == TriStateCheckBox.State.INVERSED.ordinal)
|
||||
listener.onClick(null, index, state == TriStateCheckBox.State.IGNORE.ordinal)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,18 +18,18 @@ import kotlin.math.roundToInt
|
|||
class TriStateCheckBox constructor(context: Context, attrs: AttributeSet?) :
|
||||
FrameLayout(context, attrs) {
|
||||
|
||||
var useIndeterminateForInverse: Boolean = false
|
||||
var useIndeterminateForIgnore: Boolean = false
|
||||
set(value) {
|
||||
field = value
|
||||
if (if (field) state == State.INVERSED else state == State.INDETERMINATE) {
|
||||
state = if (!field) State.INVERSED else State.INDETERMINATE
|
||||
if (state == State.IGNORE) {
|
||||
updateDrawable()
|
||||
}
|
||||
}
|
||||
|
||||
var skipInversed: Boolean = false
|
||||
set(value) {
|
||||
field = value
|
||||
if (field && (state == State.INVERSED || state == State.INDETERMINATE)) {
|
||||
if (field && state == State.IGNORE) {
|
||||
state = State.UNCHECKED
|
||||
}
|
||||
}
|
||||
|
@ -77,6 +77,8 @@ class TriStateCheckBox constructor(context: Context, attrs: AttributeSet?) :
|
|||
private val checkedColor = ColorStateList.valueOf(context.getResourceColor(R.attr.colorSecondary))
|
||||
private val inverseColor = ColorStateList.valueOf(context.getResourceColor(R.attr.colorSecondaryVariant))
|
||||
private val indeterColor = ColorStateList.valueOf(context.getResourceColor(R.attr.colorPrimary))
|
||||
private val ignoreColor get() = if (useIndeterminateForIgnore) indeterColor else inverseColor
|
||||
|
||||
private val disabledColor = ColorStateList.valueOf(
|
||||
ColorUtils.setAlphaComponent(context.getResourceColor(R.attr.colorControlNormal), (disabledAlpha * 255).roundToInt())
|
||||
)
|
||||
|
@ -121,11 +123,7 @@ class TriStateCheckBox constructor(context: Context, attrs: AttributeSet?) :
|
|||
fun goToNextStep() {
|
||||
setState(
|
||||
when (state) {
|
||||
State.CHECKED -> when {
|
||||
skipInversed -> State.UNCHECKED
|
||||
useIndeterminateForInverse -> State.INDETERMINATE
|
||||
else -> State.INVERSED
|
||||
}
|
||||
State.CHECKED -> if (skipInversed) State.UNCHECKED else State.IGNORE
|
||||
State.UNCHECKED -> State.CHECKED
|
||||
else -> State.UNCHECKED
|
||||
},
|
||||
|
@ -172,8 +170,11 @@ class TriStateCheckBox constructor(context: Context, attrs: AttributeSet?) :
|
|||
State.UNCHECKED -> {
|
||||
setAnimVectorCompat(
|
||||
when (oldState) {
|
||||
State.INDETERMINATE -> R.drawable.anim_checkbox_indeterminate_to_blank_24dp
|
||||
State.INVERSED -> R.drawable.anim_check_box_x_to_blank_24dp
|
||||
State.IGNORE -> if (useIndeterminateForIgnore) {
|
||||
R.drawable.anim_checkbox_indeterminate_to_blank_24dp
|
||||
} else {
|
||||
R.drawable.anim_check_box_x_to_blank_24dp
|
||||
}
|
||||
else -> R.drawable.anim_check_box_checked_to_blank_24dp
|
||||
}
|
||||
)
|
||||
|
@ -183,18 +184,15 @@ class TriStateCheckBox constructor(context: Context, attrs: AttributeSet?) :
|
|||
setAnimVectorCompat(R.drawable.anim_check_box_blank_to_checked_24dp)
|
||||
backgroundTintList = checkedColor
|
||||
}
|
||||
State.INVERSED -> {
|
||||
State.IGNORE -> {
|
||||
setAnimVectorCompat(
|
||||
when (oldState) {
|
||||
State.CHECKED -> R.drawable.anim_check_box_checked_to_x_24dp
|
||||
when {
|
||||
useIndeterminateForIgnore -> R.drawable.anim_check_box_checked_to_indeterminate_24dp
|
||||
oldState == State.CHECKED -> R.drawable.anim_check_box_checked_to_x_24dp
|
||||
else -> R.drawable.anim_checkbox_blank_to_x_24dp
|
||||
}
|
||||
)
|
||||
backgroundTintList = inverseColor
|
||||
}
|
||||
State.INDETERMINATE -> {
|
||||
setAnimVectorCompat(R.drawable.anim_check_box_checked_to_indeterminate_24dp)
|
||||
backgroundTintList = indeterColor
|
||||
backgroundTintList = ignoreColor
|
||||
}
|
||||
}
|
||||
if (this@TriStateCheckBox.isEnabled) imageTintList = backgroundTintList
|
||||
|
@ -216,13 +214,15 @@ class TriStateCheckBox constructor(context: Context, attrs: AttributeSet?) :
|
|||
setVectorCompat(R.drawable.ic_check_box_24dp)
|
||||
checkedColor
|
||||
}
|
||||
State.INVERSED -> {
|
||||
setVectorCompat(R.drawable.ic_check_box_x_24dp)
|
||||
inverseColor
|
||||
}
|
||||
State.INDETERMINATE -> {
|
||||
setVectorCompat(R.drawable.ic_check_box_indeterminate_24dp)
|
||||
indeterColor
|
||||
State.IGNORE -> {
|
||||
setVectorCompat(
|
||||
if (useIndeterminateForIgnore) {
|
||||
R.drawable.ic_check_box_indeterminate_24dp
|
||||
} else {
|
||||
R.drawable.ic_check_box_x_24dp
|
||||
}
|
||||
)
|
||||
ignoreColor
|
||||
}
|
||||
}
|
||||
if (this@TriStateCheckBox.isEnabled) imageTintList = backgroundTintList
|
||||
|
@ -232,8 +232,7 @@ class TriStateCheckBox constructor(context: Context, attrs: AttributeSet?) :
|
|||
enum class State {
|
||||
UNCHECKED,
|
||||
CHECKED,
|
||||
INVERSED,
|
||||
INDETERMINATE,
|
||||
IGNORE,
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -32,7 +32,7 @@ internal class TriStateMultiChoiceDialogAdapter(
|
|||
private val states = TriStateCheckBox.State.values()
|
||||
private val defaultOrdinal
|
||||
get() = if (skipChecked) {
|
||||
TriStateCheckBox.State.INVERSED.ordinal
|
||||
TriStateCheckBox.State.IGNORE.ordinal
|
||||
} else {
|
||||
TriStateCheckBox.State.CHECKED.ordinal
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ internal class TriStateMultiChoiceDialogAdapter(
|
|||
// This value was selected
|
||||
notifyItemChanged(index, CheckPayload)
|
||||
}
|
||||
current == TriStateCheckBox.State.INVERSED.ordinal && previous != TriStateCheckBox.State.INVERSED.ordinal -> {
|
||||
current == TriStateCheckBox.State.IGNORE.ordinal && previous != TriStateCheckBox.State.IGNORE.ordinal -> {
|
||||
// This value was inverse selected
|
||||
notifyItemChanged(index, InverseCheckPayload)
|
||||
}
|
||||
|
@ -64,8 +64,8 @@ internal class TriStateMultiChoiceDialogAdapter(
|
|||
internal fun itemClicked(index: Int) {
|
||||
val newSelection = this.currentSelection.toMutableList()
|
||||
newSelection[index] = when (currentSelection[index]) {
|
||||
TriStateCheckBox.State.CHECKED.ordinal -> TriStateCheckBox.State.INVERSED.ordinal
|
||||
TriStateCheckBox.State.INVERSED.ordinal -> TriStateCheckBox.State.UNCHECKED.ordinal
|
||||
TriStateCheckBox.State.CHECKED.ordinal -> TriStateCheckBox.State.IGNORE.ordinal
|
||||
TriStateCheckBox.State.IGNORE.ordinal -> TriStateCheckBox.State.UNCHECKED.ordinal
|
||||
// UNCHECKED
|
||||
else -> defaultOrdinal
|
||||
}
|
||||
|
@ -116,7 +116,7 @@ internal class TriStateMultiChoiceDialogAdapter(
|
|||
return
|
||||
}
|
||||
InverseCheckPayload -> {
|
||||
holder.controlView.setState(TriStateCheckBox.State.INVERSED, true)
|
||||
holder.controlView.setState(TriStateCheckBox.State.IGNORE, true)
|
||||
return
|
||||
}
|
||||
UncheckPayload -> {
|
||||
|
|
|
@ -91,7 +91,7 @@ class TriStateListPreference @JvmOverloads constructor(
|
|||
.map {
|
||||
when (it) {
|
||||
in set -> TriStateCheckBox.State.CHECKED.ordinal
|
||||
in excludedSet -> TriStateCheckBox.State.INVERSED.ordinal
|
||||
in excludedSet -> TriStateCheckBox.State.IGNORE.ordinal
|
||||
else -> TriStateCheckBox.State.UNCHECKED.ordinal
|
||||
}
|
||||
}
|
||||
|
@ -117,7 +117,7 @@ class TriStateListPreference @JvmOverloads constructor(
|
|||
.map { entryValues[it] }
|
||||
.toSet()
|
||||
excludedItems = selections
|
||||
.mapIndexed { index, value -> if (value == TriStateCheckBox.State.INVERSED.ordinal) index else null }
|
||||
.mapIndexed { index, value -> if (value == TriStateCheckBox.State.IGNORE.ordinal) index else null }
|
||||
.filterNotNull()
|
||||
.map { entryValues[it] }
|
||||
.toSet()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue