mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-24 21:45:14 -04:00
Merge pull request #1653 from kiwix/feature/macgills/1650-tag-update
Feature/macgills/1650 tag update
This commit is contained in:
commit
0b5c1a5eac
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
@ -41,20 +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>()
|
||||
val detailsTagIsSet = tags.isSet<DetailsTag>()
|
||||
tag_picture.selectBy(pictureTagIsSet)
|
||||
tag_video.selectBy(videoTagIsSet)
|
||||
tag_text_only.selectBy(!pictureTagIsSet && !videoTagIsSet && detailsTagIsSet)
|
||||
tag_short_text_only.selectBy(!pictureTagIsSet && !videoTagIsSet && !detailsTagIsSet)
|
||||
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
|
||||
}
|
||||
}
|
||||
|
@ -17,17 +17,17 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/tag_vid" />
|
||||
|
||||
<com.google.android.material.chip.Chip
|
||||
android:id="@+id/tag_short_text"
|
||||
style="@style/Widget.KiwixTheme.Chip.Choice.Static"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/tag_short_text" />
|
||||
|
||||
<com.google.android.material.chip.Chip
|
||||
android:id="@+id/tag_text_only"
|
||||
style="@style/Widget.KiwixTheme.Chip.Choice.Static"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/tag_text_only" />
|
||||
|
||||
<com.google.android.material.chip.Chip
|
||||
android:id="@+id/tag_short_text_only"
|
||||
style="@style/Widget.KiwixTheme.Chip.Choice.Static"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/tag_short_text_only" />
|
||||
</merge>
|
||||
|
@ -288,7 +288,7 @@
|
||||
<string name="tag_pic">Pic</string>
|
||||
<string name="tag_vid">Vid</string>
|
||||
<string name="tag_text_only">Text Only</string>
|
||||
<string name="tag_short_text_only">Short Text Only</string>
|
||||
<string name="tag_short_text">Short Text</string>
|
||||
<string-array name="pref_night_modes_entries">
|
||||
<item>On</item>
|
||||
<item>Off</item>
|
||||
|
Loading…
x
Reference in New Issue
Block a user