mirror of
https://github.com/Aviortheking/Neo-Store.git
synced 2025-04-23 19:32:16 +00:00
Update: Revamp LinkItem to use the new LinkType
This commit is contained in:
parent
1920820f1d
commit
3c80cbea13
@ -1,58 +1,63 @@
|
|||||||
package com.looker.droidify.ui.compose.pages.app_detail.components
|
package com.looker.droidify.ui.compose.pages.app_detail.components
|
||||||
|
|
||||||
import androidx.annotation.DrawableRes
|
import android.net.Uri
|
||||||
import androidx.annotation.StringRes
|
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.combinedClickable
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.layout.wrapContentSize
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.clip
|
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.res.stringResource
|
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.looker.droidify.R
|
import com.looker.droidify.R
|
||||||
|
import com.looker.droidify.entity.LinkType
|
||||||
import com.looker.droidify.ui.compose.theme.AppTheme
|
import com.looker.droidify.ui.compose.theme.AppTheme
|
||||||
|
|
||||||
|
@OptIn(ExperimentalFoundationApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun LinkItem(
|
fun LinkItem(
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
linkType: LinkType,
|
linkType: LinkType,
|
||||||
onClick: (String) -> Unit = {}
|
onClick: (Uri?) -> Unit = {},
|
||||||
|
onLongClick: (Uri?) -> Unit = {}
|
||||||
) {
|
) {
|
||||||
Row(
|
Row(
|
||||||
modifier = modifier
|
modifier = modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.clickable { onClick(linkType.text) }
|
.combinedClickable(
|
||||||
.clip(MaterialTheme.shapes.large)
|
onClick = { onClick(linkType.link) },
|
||||||
.background(MaterialTheme.colorScheme.surface)
|
onLongClick = { onLongClick(linkType.link) })
|
||||||
.padding(8.dp),
|
.padding(vertical = 8.dp),
|
||||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||||
verticalAlignment = Alignment.CenterVertically
|
verticalAlignment = Alignment.CenterVertically
|
||||||
) {
|
) {
|
||||||
Icon(
|
Icon(
|
||||||
painter = painterResource(id = linkType.iconResId),
|
painter = painterResource(id = linkType.iconResId),
|
||||||
contentDescription = stringResource(id = linkType.titleResId)
|
contentDescription = linkType.title
|
||||||
)
|
)
|
||||||
|
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier.wrapContentSize()
|
modifier = Modifier.wrapContentSize()
|
||||||
) {
|
) {
|
||||||
Text(
|
Text(
|
||||||
text = stringResource(id = linkType.titleResId),
|
text = linkType.title,
|
||||||
softWrap = true,
|
softWrap = true,
|
||||||
overflow = TextOverflow.Ellipsis,
|
overflow = TextOverflow.Ellipsis,
|
||||||
maxLines = 1,
|
maxLines = 1,
|
||||||
style = MaterialTheme.typography.titleMedium
|
style = MaterialTheme.typography.titleMedium
|
||||||
)
|
)
|
||||||
Text(
|
Text(
|
||||||
text = linkType.text,
|
text = linkType.link.toString(),
|
||||||
style = MaterialTheme.typography.bodySmall,
|
style = MaterialTheme.typography.bodySmall,
|
||||||
overflow = TextOverflow.Ellipsis,
|
overflow = TextOverflow.Ellipsis,
|
||||||
maxLines = 2,
|
maxLines = 2,
|
||||||
@ -62,16 +67,12 @@ fun LinkItem(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data class LinkType(
|
|
||||||
@DrawableRes val iconResId: Int, @StringRes val titleResId: Int, val text: String = ""
|
|
||||||
)
|
|
||||||
|
|
||||||
@Preview
|
@Preview
|
||||||
@Composable
|
@Composable
|
||||||
fun LinkItemPreview() {
|
fun LinkItemPreview() {
|
||||||
AppTheme(blackTheme = false) {
|
AppTheme(blackTheme = false) {
|
||||||
LinkItem(
|
LinkItem(
|
||||||
linkType = LinkType(R.drawable.ic_email, R.string.author_email, "Looker")
|
linkType = LinkType(R.drawable.ic_email, "R.string.author_email")
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user