Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

consider expand/collapse icon button, then make text selectable #1066

Open
github-actions bot opened this issue Aug 18, 2024 · 0 comments
Open

consider expand/collapse icon button, then make text selectable #1066

github-actions bot opened this issue Aug 18, 2024 · 0 comments
Labels

Comments

@github-actions
Copy link
Contributor

// TODO: consider expand/collapse icon button, then make text selectable


package ly.david.musicsearch.ui.common.wikimedia

import androidx.compose.animation.animateContentSize
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.material.Text
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import ly.david.musicsearch.shared.domain.listitem.RelationListItemModel
import ly.david.musicsearch.shared.domain.network.MusicBrainzEntity
import ly.david.musicsearch.shared.domain.wikimedia.WikipediaExtract
import ly.david.musicsearch.ui.common.relation.RelationListItem
import ly.david.musicsearch.ui.core.LocalStrings
import ly.david.musicsearch.ui.core.theme.TextStyles

@Composable
fun WikipediaSection(
    extract: WikipediaExtract?,
    modifier: Modifier = Modifier,
    filterText: String = "",
) {
    if (extract != null) {
        Column(
            modifier = modifier,
        ) {
            if (extract.extract.isNotBlank() && extract.extract.contains(filterText)) {
                var expanded by remember { mutableStateOf(false) }

                // TODO: consider expand/collapse icon button, then make text selectable
                Text(
                    text = extract.extract,
                    modifier = Modifier
                        .clickable { expanded = !expanded }
                        .padding(horizontal = 16.dp, vertical = 8.dp)
                        .animateContentSize(),
                    maxLines = if (expanded) Int.MAX_VALUE else 4,
                    overflow = TextOverflow.Ellipsis,
                    color = MaterialTheme.colorScheme.onBackground,
                    style = TextStyles.getCardBodyTextStyle(),
                )
            }

            if (extract.wikipediaUrl.isNotBlank() && extract.wikipediaUrl.contains(filterText)) {
                val uriHandler = LocalUriHandler.current
                val strings = LocalStrings.current

                RelationListItem(
                    relation = RelationListItemModel(
                        id = "doesn't matter",
                        label = strings.wikipedia,
                        linkedEntity = MusicBrainzEntity.URL,
                        name = extract.wikipediaUrl,
                        linkedEntityId = "doesn't matter",
                    ),
                    onItemClick = { _, _, _ ->
                        uriHandler.openUri(extract.wikipediaUrl)
                    },
                )
            }
        }
    }
}

@github-actions github-actions bot added the todo label Aug 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

0 participants