From b3fcde78fff971f4c09e9ecd4ceaa245477e1fe9 Mon Sep 17 00:00:00 2001 From: Sean Mac Gillicuddy Date: Tue, 17 Dec 2019 10:59:00 +0000 Subject: [PATCH 1/2] #1650 Library "Text Only" seems to be wrong - activate short text regardless of pictures - activate text only by nopic+novid - change models to more accuately reflect this - reorder tags --- .../kiwixmobile/core/zim_manager/KiwixTag.kt | 28 +++++++++---------- .../kiwixmobile/core/zim_manager/TagsView.kt | 7 ++--- core/src/main/res/layout/tag_content.xml | 14 +++++----- core/src/main/res/values/strings.xml | 2 +- 4 files changed, 25 insertions(+), 26 deletions(-) diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/zim_manager/KiwixTag.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/zim_manager/KiwixTag.kt index 9cca27f86..eddc84bd6 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/zim_manager/KiwixTag.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/zim_manager/KiwixTag.kt @@ -32,27 +32,27 @@ sealed class KiwixTag { val split = tags.split(":") val value = split.getOrNull(1) when (val tag = split[0]) { - "_ftindex" -> FtIndexTag(value!!) - "_pictures" -> PicturesTag(value!!) - "_videos" -> VideoTag(value!!) - "_details" -> DetailsTag(value!!) - "_category" -> CategoryTag(value!!) + "_ftindex" -> FtIndexTag(value) + "_pictures" -> PicturesTag(value) + "_videos" -> VideoTag(value) + "_details" -> DetailsTag(value) + "_category" -> CategoryTag(value) else -> value?.let { ArbitraryTag(tag, it) } ?: TagOnly(tag) } } ?: emptyList() - data class CategoryTag(val categoryValue: String) : KiwixTag() + data class CategoryTag(val categoryValue: String?) : KiwixTag() data class ArbitraryTag(val tag: String, val value: String) : KiwixTag() data class TagOnly(val tag: String) : KiwixTag() - sealed class YesNoValueTag( - _value: String, - val value: TagValue = if (_value == "yes") YES else NO - ) : KiwixTag() { - class FtIndexTag(value: String) : YesNoValueTag(value) - class PicturesTag(value: String) : YesNoValueTag(value) - class VideoTag(value: String) : YesNoValueTag(value) - class DetailsTag(value: String) : YesNoValueTag(value) + sealed class YesNoValueTag() : KiwixTag() { + abstract val inputValue: String? + val value: TagValue by lazy { if (inputValue == "no") NO else YES } + + data class FtIndexTag(override val inputValue: String?) : YesNoValueTag() + data class PicturesTag(override val inputValue: String?) : YesNoValueTag() + data class VideoTag(override val inputValue: String?) : YesNoValueTag() + data class DetailsTag(override val inputValue: String?) : YesNoValueTag() } } diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/zim_manager/TagsView.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/zim_manager/TagsView.kt index b9012bb07..2ddd9cfa2 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/zim_manager/TagsView.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/zim_manager/TagsView.kt @@ -23,7 +23,7 @@ import android.util.AttributeSet import com.google.android.material.chip.Chip import com.google.android.material.chip.ChipGroup import kotlinx.android.synthetic.main.tag_content.view.tag_picture -import kotlinx.android.synthetic.main.tag_content.view.tag_short_text_only +import kotlinx.android.synthetic.main.tag_content.view.tag_short_text import kotlinx.android.synthetic.main.tag_content.view.tag_text_only import kotlinx.android.synthetic.main.tag_content.view.tag_video import org.kiwix.kiwixmobile.core.R @@ -43,11 +43,10 @@ class TagsView(context: Context, attrs: AttributeSet) : ChipGroup(context, attrs fun render(tags: List) { val pictureTagIsSet = tags.isSet() val videoTagIsSet = tags.isSet() - val detailsTagIsSet = tags.isSet() tag_picture.selectBy(pictureTagIsSet) tag_video.selectBy(videoTagIsSet) - tag_text_only.selectBy(!pictureTagIsSet && !videoTagIsSet && detailsTagIsSet) - tag_short_text_only.selectBy(!pictureTagIsSet && !videoTagIsSet && !detailsTagIsSet) + tag_text_only.selectBy(!pictureTagIsSet && !videoTagIsSet) + tag_short_text.selectBy(!tags.isSet()) } private inline fun List.isSet() = diff --git a/core/src/main/res/layout/tag_content.xml b/core/src/main/res/layout/tag_content.xml index 654c5e4c3..9b68460b0 100644 --- a/core/src/main/res/layout/tag_content.xml +++ b/core/src/main/res/layout/tag_content.xml @@ -17,17 +17,17 @@ android:layout_height="wrap_content" android:text="@string/tag_vid" /> + + - - diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml index 3272e36bf..25f568404 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -288,7 +288,7 @@ Pic Vid Text Only - Short Text Only + Short Text On Off From ada8c5db3cc3b8e5a435b34535fe6747976973eb Mon Sep 17 00:00:00 2001 From: Sean Mac Gillicuddy Date: Tue, 17 Dec 2019 14:12:48 +0000 Subject: [PATCH 2/2] #1650 Library "Text Only" seems to be wrong - fix boolean logic --- .../kiwixmobile/core/zim_manager/TagsView.kt | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/zim_manager/TagsView.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/zim_manager/TagsView.kt index 2ddd9cfa2..7509c6908 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/zim_manager/TagsView.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/zim_manager/TagsView.kt @@ -41,19 +41,26 @@ class TagsView(context: Context, attrs: AttributeSet) : ChipGroup(context, attrs } fun render(tags: List) { - val pictureTagIsSet = tags.isSet() - val videoTagIsSet = tags.isSet() - tag_picture.selectBy(pictureTagIsSet) - tag_video.selectBy(videoTagIsSet) - tag_text_only.selectBy(!pictureTagIsSet && !videoTagIsSet) - tag_short_text.selectBy(!tags.isSet()) + tag_picture.selectBy(tags.isYesOrNotDefined()) + tag_video.selectBy(tags.isYesOrNotDefined()) + tag_text_only.selectBy(tags.isDefinedAndNo() && tags.isDefinedAndNo()) + tag_short_text.selectBy(tags.isDefinedAndNo()) } - private inline fun List.isSet() = + private inline fun List.isYesOrNotDefined() = + isYes() || !isDefined() + + private inline fun List.isDefinedAndNo() = + !isDefined() && !isYes() + + private inline fun List.isYes() = filterIsInstance().getOrNull(0)?.value == YES - private fun Chip.selectBy(isTagSet: Boolean) { - isChecked = isTagSet - isEnabled = isTagSet + private inline fun List.isDefined() = + filterIsInstance().isNotEmpty() + + private fun Chip.selectBy(criteria: Boolean) { + isChecked = criteria + isEnabled = criteria } }