mirror of
https://github.com/Aviortheking/Neo-Store.git
synced 2025-06-08 08:49:55 +00:00
Update: Product compose items and recyclers
This commit is contained in:
parent
19bb3bf4ae
commit
b38dd1b77c
@ -1,6 +1,5 @@
|
|||||||
package com.looker.droidify.ui.compose
|
package com.looker.droidify.ui.compose
|
||||||
|
|
||||||
import android.util.Log
|
|
||||||
import androidx.compose.foundation.layout.Arrangement.Absolute.spacedBy
|
import androidx.compose.foundation.layout.Arrangement.Absolute.spacedBy
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
import androidx.compose.foundation.lazy.LazyRow
|
import androidx.compose.foundation.lazy.LazyRow
|
||||||
@ -8,32 +7,38 @@ import androidx.compose.foundation.lazy.items
|
|||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.looker.droidify.database.entity.Product
|
import com.looker.droidify.database.entity.Product
|
||||||
|
import com.looker.droidify.database.entity.Repository
|
||||||
|
import com.looker.droidify.entity.ProductItem
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ProductsVerticalRecycler(productsList: List<Product>) {
|
fun ProductsVerticalRecycler(
|
||||||
|
productsList: List<Product>,
|
||||||
|
repositories: Map<Long, Repository>,
|
||||||
|
onUserClick: (ProductItem) -> Unit = {}
|
||||||
|
) {
|
||||||
LazyColumn(
|
LazyColumn(
|
||||||
verticalArrangement = spacedBy(2.dp)
|
verticalArrangement = spacedBy(2.dp)
|
||||||
) {
|
) {
|
||||||
items(productsList) { product: Product ->
|
items(productsList) { product ->
|
||||||
product.item?.let { item ->
|
product.item.let { item ->
|
||||||
ProductRow(item.name, item.version, item.summary, onUserClick = {
|
ProductRow(item, repositories[item.repositoryId], onUserClick)
|
||||||
Log.d(this.toString(), "You clicked $it")
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ProductsHorizontalRecycler(productsList: List<Product>) {
|
fun ProductsHorizontalRecycler(
|
||||||
|
productsList: List<Product>,
|
||||||
|
repositories: Map<Long, Repository>,
|
||||||
|
onUserClick: (ProductItem) -> Unit = {}
|
||||||
|
) {
|
||||||
LazyRow(
|
LazyRow(
|
||||||
horizontalArrangement = spacedBy(2.dp)
|
horizontalArrangement = spacedBy(2.dp)
|
||||||
) {
|
) {
|
||||||
items(productsList) { product: Product ->
|
items(productsList) { product ->
|
||||||
product.item?.let { item ->
|
product.item.let { item ->
|
||||||
ProductColumn(item.name, item.version, onUserClick = {
|
ProductColumn(item, repositories[item.repositoryId], onUserClick)
|
||||||
Log.d(this.toString(), "You clicked $it")
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ import androidx.compose.foundation.Image
|
|||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.foundation.shape.CircleShape
|
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
import androidx.compose.material.ContentAlpha
|
import androidx.compose.material.ContentAlpha
|
||||||
import androidx.compose.material.LocalContentAlpha
|
import androidx.compose.material.LocalContentAlpha
|
||||||
@ -21,32 +20,44 @@ import androidx.compose.ui.text.font.FontWeight
|
|||||||
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 coil.compose.rememberImagePainter
|
||||||
import com.looker.droidify.R
|
import com.looker.droidify.R
|
||||||
|
import com.looker.droidify.database.entity.Repository
|
||||||
|
import com.looker.droidify.entity.ProductItem
|
||||||
|
import com.looker.droidify.network.CoilDownloader
|
||||||
|
import com.looker.droidify.ui.compose.theme.AppTheme
|
||||||
|
|
||||||
@Preview
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ProductRow(
|
fun ProductRow(
|
||||||
name: String = "Droid-ify",
|
item: ProductItem,
|
||||||
version: String = "69",
|
repo: Repository? = null,
|
||||||
summary: String = "A great F-Droid client",
|
onUserClick: (ProductItem) -> Unit = {}
|
||||||
onUserClick: (String) -> Unit = {}
|
|
||||||
) {
|
) {
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.clickable(onClick = { onUserClick(name) })
|
|
||||||
.padding(4.dp)
|
.padding(4.dp)
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.background(color = MaterialTheme.colors.surface, shape = RoundedCornerShape(8.dp))
|
.background(color = MaterialTheme.colors.surface, shape = RoundedCornerShape(8.dp))
|
||||||
|
.clip(shape = RoundedCornerShape(8.dp))
|
||||||
|
.clickable(onClick = { onUserClick(item) })
|
||||||
.padding(8.dp)
|
.padding(8.dp)
|
||||||
) {
|
) {
|
||||||
|
// TODO: Fix the issue where coil doesn't fallback to the palceholder
|
||||||
val imagePainter =
|
val imagePainter =
|
||||||
painterResource(id = R.drawable.ic_launcher_foreground)
|
if (repo != null) rememberImagePainter(
|
||||||
// rememberImagePainter(CoilDownloader.createIconUri(item.packageName, item.icon, item.metadataIcon, repo.address, repo.authentication))
|
CoilDownloader.createIconUri(
|
||||||
|
item.packageName,
|
||||||
|
item.icon,
|
||||||
|
item.metadataIcon,
|
||||||
|
repo.address,
|
||||||
|
repo.authentication
|
||||||
|
), builder = { placeholder(R.drawable.ic_application_default) }
|
||||||
|
) else painterResource(id = R.drawable.ic_application_default)
|
||||||
Image(
|
Image(
|
||||||
painter = imagePainter,
|
painter = imagePainter,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.requiredSize(56.dp)
|
.requiredSize(56.dp)
|
||||||
.clip(shape = CircleShape),
|
.clip(shape = RoundedCornerShape(8.dp)),
|
||||||
contentScale = ContentScale.Crop,
|
contentScale = ContentScale.Crop,
|
||||||
contentDescription = null
|
contentDescription = null
|
||||||
)
|
)
|
||||||
@ -64,24 +75,26 @@ fun ProductRow(
|
|||||||
contentAlignment = Alignment.TopEnd
|
contentAlignment = Alignment.TopEnd
|
||||||
) {
|
) {
|
||||||
Text(
|
Text(
|
||||||
text = name,
|
text = item.name,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.align(Alignment.CenterStart),
|
.align(Alignment.CenterStart),
|
||||||
fontWeight = FontWeight.Bold,
|
fontWeight = FontWeight.Bold,
|
||||||
softWrap = true,
|
softWrap = true,
|
||||||
|
overflow = TextOverflow.Ellipsis,
|
||||||
style = MaterialTheme.typography.body1
|
style = MaterialTheme.typography.body1
|
||||||
)
|
)
|
||||||
Text(
|
Text(
|
||||||
text = version,
|
text = item.version,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.align(Alignment.CenterEnd),
|
.align(Alignment.CenterEnd),
|
||||||
|
overflow = TextOverflow.Ellipsis,
|
||||||
style = MaterialTheme.typography.body2
|
style = MaterialTheme.typography.body2
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
CompositionLocalProvider(LocalContentAlpha provides ContentAlpha.medium) {
|
CompositionLocalProvider(LocalContentAlpha provides ContentAlpha.medium) {
|
||||||
Text(
|
Text(
|
||||||
modifier = Modifier.fillMaxHeight(),
|
modifier = Modifier.fillMaxHeight(),
|
||||||
text = summary,
|
text = item.summary,
|
||||||
style = MaterialTheme.typography.body2
|
style = MaterialTheme.typography.body2
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -90,36 +103,45 @@ fun ProductRow(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Preview
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ProductColumn(
|
fun ProductColumn(
|
||||||
name: String = "Droid-iy",
|
item: ProductItem,
|
||||||
version: String = "69",
|
repo: Repository? = null,
|
||||||
onUserClick: (String) -> Unit = {}
|
onUserClick: (ProductItem) -> Unit = {}
|
||||||
) {
|
) {
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.clickable(onClick = { onUserClick(name) })
|
|
||||||
.padding(4.dp)
|
.padding(4.dp)
|
||||||
.requiredSize(72.dp, 96.dp)
|
.requiredSize(72.dp, 96.dp)
|
||||||
.background(color = MaterialTheme.colors.surface, shape = RoundedCornerShape(8.dp))
|
.background(color = MaterialTheme.colors.surface, shape = RoundedCornerShape(8.dp))
|
||||||
|
.clip(shape = RoundedCornerShape(8.dp))
|
||||||
|
.clickable(onClick = { onUserClick(item) })
|
||||||
.padding(4.dp)
|
.padding(4.dp)
|
||||||
) {
|
) {
|
||||||
val imagePainter =
|
// TODO: Fix the issue where coil doesn't fallback to the palceholder
|
||||||
painterResource(id = R.drawable.ic_launcher_foreground)
|
val imagePainter = if (repo != null)
|
||||||
// rememberImagePainter(CoilDownloader.createIconUri(item.packageName, item.icon, item.metadataIcon, repo.address, repo.authentication))
|
rememberImagePainter(
|
||||||
|
CoilDownloader.createIconUri(
|
||||||
|
item.packageName,
|
||||||
|
item.icon,
|
||||||
|
item.metadataIcon,
|
||||||
|
repo.address,
|
||||||
|
repo.authentication
|
||||||
|
), builder = { placeholder(R.drawable.ic_application_default) }
|
||||||
|
)
|
||||||
|
else painterResource(id = R.drawable.ic_application_default)
|
||||||
Image(
|
Image(
|
||||||
painter = imagePainter,
|
painter = imagePainter,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.requiredSize(56.dp)
|
.requiredSize(56.dp)
|
||||||
.clip(shape = CircleShape)
|
.clip(shape = RoundedCornerShape(8.dp))
|
||||||
.align(Alignment.CenterHorizontally),
|
.align(Alignment.CenterHorizontally),
|
||||||
contentScale = ContentScale.Crop,
|
contentScale = ContentScale.Crop,
|
||||||
contentDescription = null
|
contentDescription = null
|
||||||
)
|
)
|
||||||
|
|
||||||
Text(
|
Text(
|
||||||
text = name,
|
text = item.name,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.align(Alignment.CenterHorizontally),
|
.align(Alignment.CenterHorizontally),
|
||||||
fontWeight = FontWeight.Bold,
|
fontWeight = FontWeight.Bold,
|
||||||
@ -129,7 +151,7 @@ fun ProductColumn(
|
|||||||
)
|
)
|
||||||
CompositionLocalProvider(LocalContentAlpha provides ContentAlpha.medium) {
|
CompositionLocalProvider(LocalContentAlpha provides ContentAlpha.medium) {
|
||||||
Text(
|
Text(
|
||||||
text = version,
|
text = item.version,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.align(Alignment.CenterHorizontally),
|
.align(Alignment.CenterHorizontally),
|
||||||
style = MaterialTheme.typography.overline,
|
style = MaterialTheme.typography.overline,
|
||||||
@ -140,3 +162,35 @@ fun ProductColumn(
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Preview
|
||||||
|
@Composable
|
||||||
|
fun ProductColumnPreview() {
|
||||||
|
AppTheme(darkTheme = false) {
|
||||||
|
ProductColumn(ProductItem())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Preview
|
||||||
|
@Composable
|
||||||
|
fun ProductColumnDarkPreview() {
|
||||||
|
AppTheme(darkTheme = true) {
|
||||||
|
ProductColumn(ProductItem())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Preview
|
||||||
|
@Composable
|
||||||
|
fun ProductRowPreview() {
|
||||||
|
AppTheme(darkTheme = false) {
|
||||||
|
ProductRow(ProductItem())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Preview
|
||||||
|
@Composable
|
||||||
|
fun ProductRowDarkPreview() {
|
||||||
|
AppTheme(darkTheme = true) {
|
||||||
|
ProductRow(ProductItem())
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user