mirror of
https://github.com/Aviortheking/Neo-Store.git
synced 2025-04-23 11:22:12 +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
|
||||
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.*
|
||||
import android.net.Uri
|
||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||
import androidx.compose.foundation.combinedClickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
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.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.looker.droidify.R
|
||||
import com.looker.droidify.entity.LinkType
|
||||
import com.looker.droidify.ui.compose.theme.AppTheme
|
||||
|
||||
@OptIn(ExperimentalFoundationApi::class)
|
||||
@Composable
|
||||
fun LinkItem(
|
||||
modifier: Modifier = Modifier,
|
||||
linkType: LinkType,
|
||||
onClick: (String) -> Unit = {}
|
||||
onClick: (Uri?) -> Unit = {},
|
||||
onLongClick: (Uri?) -> Unit = {}
|
||||
) {
|
||||
Row(
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.clickable { onClick(linkType.text) }
|
||||
.clip(MaterialTheme.shapes.large)
|
||||
.background(MaterialTheme.colorScheme.surface)
|
||||
.padding(8.dp),
|
||||
.combinedClickable(
|
||||
onClick = { onClick(linkType.link) },
|
||||
onLongClick = { onLongClick(linkType.link) })
|
||||
.padding(vertical = 8.dp),
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Icon(
|
||||
painter = painterResource(id = linkType.iconResId),
|
||||
contentDescription = stringResource(id = linkType.titleResId)
|
||||
contentDescription = linkType.title
|
||||
)
|
||||
|
||||
Column(
|
||||
modifier = Modifier.wrapContentSize()
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(id = linkType.titleResId),
|
||||
text = linkType.title,
|
||||
softWrap = true,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
maxLines = 1,
|
||||
style = MaterialTheme.typography.titleMedium
|
||||
)
|
||||
Text(
|
||||
text = linkType.text,
|
||||
text = linkType.link.toString(),
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
maxLines = 2,
|
||||
@ -62,16 +67,12 @@ fun LinkItem(
|
||||
}
|
||||
}
|
||||
|
||||
data class LinkType(
|
||||
@DrawableRes val iconResId: Int, @StringRes val titleResId: Int, val text: String = ""
|
||||
)
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
fun LinkItemPreview() {
|
||||
AppTheme(blackTheme = false) {
|
||||
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