mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-08-03 10:46:53 -04:00
Created the TagsView
for showing the books tags.
This commit is contained in:
parent
674ff5b24c
commit
b608b838a3
88
app/src/main/java/org/kiwix/kiwixmobile/ui/TagsView.kt
Normal file
88
app/src/main/java/org/kiwix/kiwixmobile/ui/TagsView.kt
Normal file
@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Kiwix Android
|
||||
* Copyright (c) 2025 Kiwix <android.kiwix.org>
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
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<KiwixTag>, modifier: Modifier = Modifier) {
|
||||
KiwixTheme {
|
||||
FlowRow(
|
||||
modifier = modifier,
|
||||
horizontalArrangement = Arrangement.spacedBy(EIGHT_DP),
|
||||
verticalArrangement = Arrangement.spacedBy(FOUR_DP)
|
||||
) {
|
||||
if (tags.isYesOrNotDefined<PicturesTag>()) {
|
||||
TagChip(text = stringResource(R.string.tag_pic))
|
||||
}
|
||||
if (tags.isYesOrNotDefined<VideoTag>()) {
|
||||
TagChip(text = stringResource(R.string.tag_vid))
|
||||
}
|
||||
val shortTextIsSelected = tags.isDefinedAndNo<DetailsTag>()
|
||||
if (tags.isDefinedAndNo<PicturesTag>() &&
|
||||
tags.isDefinedAndNo<VideoTag>() &&
|
||||
!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 <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 inline fun <reified T : YesNoValueTag> List<KiwixTag>.isDefined() =
|
||||
filterIsInstance<T>().isNotEmpty()
|
@ -126,8 +126,7 @@
|
||||
<fragment
|
||||
android:id="@+id/zimHostFragment"
|
||||
android:name="org.kiwix.kiwixmobile.webserver.ZimHostFragment"
|
||||
android:label="ZimHostFragment"
|
||||
tools:layout="@layout/activity_zim_host" />
|
||||
android:label="ZimHostFragment" />
|
||||
<fragment
|
||||
android:id="@+id/helpFragment"
|
||||
android:name="org.kiwix.kiwixmobile.help.KiwixHelpFragment"
|
||||
|
Loading…
x
Reference in New Issue
Block a user