mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-15 10:26:53 -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>) {
|
||||
val pictureTagIsSet = tags.isSet<PicturesTag>()
|
||||
val videoTagIsSet = tags.isSet<VideoTag>()
|
||||
tag_picture.selectBy(pictureTagIsSet)
|
||||
tag_video.selectBy(videoTagIsSet)
|
||||
tag_text_only.selectBy(!pictureTagIsSet && !videoTagIsSet)
|
||||
tag_short_text.selectBy(!tags.isSet<DetailsTag>())
|
||||
tag_picture.selectBy(tags.isYesOrNotDefined<PicturesTag>())
|
||||
tag_video.selectBy(tags.isYesOrNotDefined<VideoTag>())
|
||||
tag_text_only.selectBy(tags.isDefinedAndNo<PicturesTag>() && tags.isDefinedAndNo<VideoTag>())
|
||||
tag_short_text.selectBy(tags.isDefinedAndNo<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
|
||||
|
||||
private fun Chip.selectBy(isTagSet: Boolean) {
|
||||
isChecked = isTagSet
|
||||
isEnabled = isTagSet
|
||||
private inline fun <reified T : YesNoValueTag> List<KiwixTag>.isDefined() =
|
||||
filterIsInstance<T>().isNotEmpty()
|
||||
|
||||
private fun Chip.selectBy(criteria: Boolean) {
|
||||
isChecked = criteria
|
||||
isEnabled = criteria
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user