diff --git a/app/src/main/java/org/kiwix/kiwixmobile/ui/TagsView.kt b/app/src/main/java/org/kiwix/kiwixmobile/ui/TagsView.kt new file mode 100644 index 000000000..5c365cfb8 --- /dev/null +++ b/app/src/main/java/org/kiwix/kiwixmobile/ui/TagsView.kt @@ -0,0 +1,88 @@ +/* + * Kiwix Android + * Copyright (c) 2025 Kiwix + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package org.kiwix.kiwixmobile.ui + +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.ExperimentalLayoutApi +import androidx.compose.foundation.layout.FlowRow +import androidx.compose.material3.AssistChip +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource +import org.kiwix.kiwixmobile.core.utils.ComposeDimens.EIGHT_DP +import org.kiwix.kiwixmobile.core.utils.ComposeDimens.FOUR_DP +import org.kiwix.kiwixmobile.core.zim_manager.KiwixTag +import org.kiwix.kiwixmobile.core.zim_manager.KiwixTag.Companion.YesNoValueTag +import org.kiwix.kiwixmobile.core.zim_manager.KiwixTag.Companion.YesNoValueTag.PicturesTag +import org.kiwix.kiwixmobile.core.zim_manager.KiwixTag.Companion.YesNoValueTag.VideoTag +import org.kiwix.kiwixmobile.core.zim_manager.KiwixTag.Companion.YesNoValueTag.DetailsTag +import org.kiwix.kiwixmobile.core.zim_manager.KiwixTag.TagValue.YES +import org.kiwix.kiwixmobile.core.R +import org.kiwix.kiwixmobile.core.ui.theme.KiwixTheme + +@OptIn(ExperimentalLayoutApi::class) +@Composable +fun TagsView(tags: List, modifier: Modifier = Modifier) { + KiwixTheme { + FlowRow( + modifier = modifier, + horizontalArrangement = Arrangement.spacedBy(EIGHT_DP), + verticalArrangement = Arrangement.spacedBy(FOUR_DP) + ) { + if (tags.isYesOrNotDefined()) { + TagChip(text = stringResource(R.string.tag_pic)) + } + if (tags.isYesOrNotDefined()) { + TagChip(text = stringResource(R.string.tag_vid)) + } + val shortTextIsSelected = tags.isDefinedAndNo() + if (tags.isDefinedAndNo() && + tags.isDefinedAndNo() && + !shortTextIsSelected + ) { + TagChip(text = stringResource(R.string.tag_text_only)) + } + if (shortTextIsSelected) { + TagChip(text = stringResource(R.string.tag_short_text)) + } + } + } +} + +@Composable +private fun TagChip(text: String) { + AssistChip( + onClick = {}, + label = { Text(text) }, + enabled = false + ) +} + +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 inline fun List.isDefined() = + filterIsInstance().isNotEmpty() diff --git a/app/src/main/res/navigation/kiwix_nav_graph.xml b/app/src/main/res/navigation/kiwix_nav_graph.xml index 067bbf5e2..f3f8455d3 100644 --- a/app/src/main/res/navigation/kiwix_nav_graph.xml +++ b/app/src/main/res/navigation/kiwix_nav_graph.xml @@ -126,8 +126,7 @@ + android:label="ZimHostFragment" />