mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-18 11:55:38 -04:00
#1650 Library "Text Only" seems to be wrong - fix boolean logic
This commit is contained in:
parent
b3fcde78ff
commit
ada8c5db3c
@ -41,19 +41,26 @@ class TagsView(context: Context, attrs: AttributeSet) : ChipGroup(context, attrs
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun render(tags: List<KiwixTag>) {
|
fun render(tags: List<KiwixTag>) {
|
||||||
val pictureTagIsSet = tags.isSet<PicturesTag>()
|
tag_picture.selectBy(tags.isYesOrNotDefined<PicturesTag>())
|
||||||
val videoTagIsSet = tags.isSet<VideoTag>()
|
tag_video.selectBy(tags.isYesOrNotDefined<VideoTag>())
|
||||||
tag_picture.selectBy(pictureTagIsSet)
|
tag_text_only.selectBy(tags.isDefinedAndNo<PicturesTag>() && tags.isDefinedAndNo<VideoTag>())
|
||||||
tag_video.selectBy(videoTagIsSet)
|
tag_short_text.selectBy(tags.isDefinedAndNo<DetailsTag>())
|
||||||
tag_text_only.selectBy(!pictureTagIsSet && !videoTagIsSet)
|
|
||||||
tag_short_text.selectBy(!tags.isSet<DetailsTag>())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private inline fun <reified T : YesNoValueTag> List<KiwixTag>.isSet() =
|
private inline fun <reified T : YesNoValueTag> List<KiwixTag>.isYesOrNotDefined() =
|
||||||
|
isYes<T>() || !isDefined<T>()
|
||||||
|
|
||||||
|
private inline fun <reified T : YesNoValueTag> List<KiwixTag>.isDefinedAndNo() =
|
||||||
|
!isDefined<T>() && !isYes<T>()
|
||||||
|
|
||||||
|
private inline fun <reified T : YesNoValueTag> List<KiwixTag>.isYes() =
|
||||||
filterIsInstance<T>().getOrNull(0)?.value == YES
|
filterIsInstance<T>().getOrNull(0)?.value == YES
|
||||||
|
|
||||||
private fun Chip.selectBy(isTagSet: Boolean) {
|
private inline fun <reified T : YesNoValueTag> List<KiwixTag>.isDefined() =
|
||||||
isChecked = isTagSet
|
filterIsInstance<T>().isNotEmpty()
|
||||||
isEnabled = isTagSet
|
|
||||||
|
private fun Chip.selectBy(criteria: Boolean) {
|
||||||
|
isChecked = criteria
|
||||||
|
isEnabled = criteria
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user