mirror of
https://github.com/Aviortheking/Neo-Store.git
synced 2025-04-23 11:22:12 +00:00
ReleaseItem.kt almost ready
This commit is contained in:
parent
10e8485f20
commit
0beed03cb5
@ -2,18 +2,19 @@ package com.looker.droidify.ui.compose.pages.app_detail.components
|
|||||||
|
|
||||||
import androidx.compose.animation.AnimatedVisibility
|
import androidx.compose.animation.AnimatedVisibility
|
||||||
import androidx.compose.animation.core.animateDpAsState
|
import androidx.compose.animation.core.animateDpAsState
|
||||||
|
import androidx.compose.animation.fadeIn
|
||||||
|
import androidx.compose.animation.fadeOut
|
||||||
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.rounded.Download
|
import androidx.compose.material.icons.rounded.Download
|
||||||
import androidx.compose.material3.*
|
import androidx.compose.material3.*
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.*
|
||||||
import androidx.compose.runtime.getValue
|
|
||||||
import androidx.compose.runtime.mutableStateOf
|
|
||||||
import androidx.compose.runtime.remember
|
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.unit.Dp
|
||||||
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.database.entity.Release
|
import com.looker.droidify.database.entity.Release
|
||||||
@ -27,76 +28,122 @@ fun ReleaseItem(
|
|||||||
release: Release,
|
release: Release,
|
||||||
onDownloadClick: (Release) -> Unit = {}
|
onDownloadClick: (Release) -> Unit = {}
|
||||||
) {
|
) {
|
||||||
val highlight by animateDpAsState(targetValue = if (isSuggested or isInstalled) 12.dp else 0.dp)
|
|
||||||
val currentRelease by remember { mutableStateOf(release) }
|
val currentRelease by remember { mutableStateOf(release) }
|
||||||
|
val highlight by animateDpAsState(targetValue = if (isSuggested or isInstalled) 8.dp else 0.dp)
|
||||||
|
|
||||||
Surface(
|
Surface(
|
||||||
modifier = modifier.fillMaxWidth(),
|
modifier = modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.wrapContentHeight(),
|
||||||
shape = MaterialTheme.shapes.large,
|
shape = MaterialTheme.shapes.large,
|
||||||
tonalElevation = highlight
|
tonalElevation = highlight
|
||||||
) {
|
) {
|
||||||
Row(
|
ReleaseItemContent(
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
release = currentRelease,
|
||||||
horizontalArrangement = Arrangement.Start
|
isSuggested = isSuggested,
|
||||||
|
isInstalled = isInstalled,
|
||||||
|
onDownloadClick = onDownloadClick
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun ReleaseItemContent(
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
|
isSuggested: Boolean = false,
|
||||||
|
isInstalled: Boolean = false,
|
||||||
|
release: Release,
|
||||||
|
onDownloadClick: (Release) -> Unit = {}
|
||||||
|
) {
|
||||||
|
Row(
|
||||||
|
modifier = Modifier.padding(end = 16.dp),
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
horizontalArrangement = Arrangement.Start
|
||||||
|
) {
|
||||||
|
IconButton(onClick = { onDownloadClick(release) }) {
|
||||||
|
Icon(
|
||||||
|
imageVector = Icons.Rounded.Download,
|
||||||
|
contentDescription = "Download this version"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Box(
|
||||||
|
modifier = modifier
|
||||||
|
.height(74.dp)
|
||||||
|
.fillMaxWidth()
|
||||||
) {
|
) {
|
||||||
IconButton(onClick = { onDownloadClick(currentRelease) }) {
|
ReleaseTitleWithBadge(
|
||||||
Icon(
|
modifier = Modifier.align(Alignment.CenterStart),
|
||||||
imageVector = Icons.Rounded.Download,
|
version = release.version,
|
||||||
contentDescription = "Download Release"
|
repository = release.targetSdkVersion.toString()
|
||||||
)
|
) {
|
||||||
}
|
AnimatedVisibility(
|
||||||
Box {
|
visible = isSuggested or isInstalled,
|
||||||
ReleaseTitleWithBadge(
|
enter = fadeIn(),
|
||||||
modifier = Modifier.align(Alignment.CenterStart),
|
exit = fadeOut()
|
||||||
title = release.version,
|
|
||||||
subtitle = release.targetSdkVersion.toString()
|
|
||||||
) {
|
) {
|
||||||
AnimatedVisibility(visible = isSuggested) {
|
val badgeText = remember { mutableStateOf(R.string.suggested) }
|
||||||
ReleaseBadge(text = stringResource(id = R.string.suggested))
|
LaunchedEffect(isInstalled, isSuggested) {
|
||||||
|
badgeText.value =
|
||||||
|
if (isSuggested && isInstalled) R.string.installed else R.string.suggested
|
||||||
}
|
}
|
||||||
|
ReleaseBadge(
|
||||||
|
modifier = Modifier.padding(top = 8.dp),
|
||||||
|
text = stringResource(id = badgeText.value)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
ReleaseItemEndText(
|
|
||||||
modifier = Modifier.align(Alignment.CenterEnd),
|
|
||||||
title = release.added.toString(),
|
|
||||||
subtitle = release.size.formatSize()
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
ReleaseItemEndText(
|
||||||
|
modifier = Modifier.align(Alignment.CenterEnd),
|
||||||
|
title = release.added.toString(),
|
||||||
|
subtitle = release.size.formatSize()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun BoxScope.ReleaseTitleWithBadge(
|
fun ReleaseTitleWithBadge(
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
title: String,
|
version: String,
|
||||||
subtitle: String,
|
repository: String,
|
||||||
badges: @Composable RowScope.() -> Unit = {}
|
badges: @Composable RowScope.() -> Unit = {}
|
||||||
) {
|
) {
|
||||||
Column(
|
Row(
|
||||||
modifier = modifier.matchParentSize(),
|
verticalAlignment = Alignment.Top,
|
||||||
verticalArrangement = Arrangement.SpaceEvenly,
|
horizontalArrangement = Arrangement.spacedBy(16.dp)
|
||||||
horizontalAlignment = Alignment.Start
|
|
||||||
) {
|
) {
|
||||||
Row(horizontalArrangement = Arrangement.spacedBy(16.dp)) {
|
Column(
|
||||||
Text(text = title, style = MaterialTheme.typography.bodyMedium)
|
modifier = modifier.fillMaxHeight(),
|
||||||
badges()
|
verticalArrangement = Arrangement.SpaceEvenly,
|
||||||
|
horizontalAlignment = Alignment.Start
|
||||||
|
) {
|
||||||
|
Spacer(modifier = Modifier.width(Dp.Hairline))
|
||||||
|
Text(text = version, style = MaterialTheme.typography.titleMedium)
|
||||||
|
Text(
|
||||||
|
text = stringResource(id = R.string.provided_by_FORMAT, repository),
|
||||||
|
style = MaterialTheme.typography.labelMedium
|
||||||
|
)
|
||||||
|
Spacer(modifier = Modifier.width(Dp.Hairline))
|
||||||
}
|
}
|
||||||
Text(text = subtitle, style = MaterialTheme.typography.labelMedium)
|
badges()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun BoxScope.ReleaseItemEndText(
|
fun ReleaseItemEndText(
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
title: String,
|
title: String,
|
||||||
subtitle: String
|
subtitle: String
|
||||||
) {
|
) {
|
||||||
Column(
|
Column(
|
||||||
modifier = modifier.matchParentSize(),
|
modifier = modifier.fillMaxHeight(),
|
||||||
verticalArrangement = Arrangement.SpaceEvenly,
|
verticalArrangement = Arrangement.SpaceBetween,
|
||||||
horizontalAlignment = Alignment.Start
|
horizontalAlignment = Alignment.Start
|
||||||
) {
|
) {
|
||||||
|
Spacer(modifier = Modifier.width(Dp.Hairline))
|
||||||
Text(text = title, style = MaterialTheme.typography.bodySmall)
|
Text(text = title, style = MaterialTheme.typography.bodySmall)
|
||||||
Text(text = subtitle, style = MaterialTheme.typography.labelSmall)
|
Text(text = subtitle, style = MaterialTheme.typography.labelSmall)
|
||||||
|
Spacer(modifier = Modifier.width(Dp.Hairline))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,9 +155,10 @@ fun ReleaseBadge(
|
|||||||
onColor: Color = MaterialTheme.colorScheme.onSecondaryContainer
|
onColor: Color = MaterialTheme.colorScheme.onSecondaryContainer
|
||||||
) {
|
) {
|
||||||
Surface(
|
Surface(
|
||||||
modifier = modifier.padding(8.dp),
|
modifier = modifier
|
||||||
color = color,
|
.background(color, Shapes.Full)
|
||||||
shape = Shapes.Full
|
.padding(8.dp),
|
||||||
|
color = color
|
||||||
) {
|
) {
|
||||||
Text(text = text, color = onColor)
|
Text(text = text, color = onColor)
|
||||||
}
|
}
|
||||||
|
32
src/main/kotlin/com/looker/droidify/utility/SampleData.kt
Normal file
32
src/main/kotlin/com/looker/droidify/utility/SampleData.kt
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
package com.looker.droidify.utility
|
||||||
|
|
||||||
|
import com.looker.droidify.database.entity.Release
|
||||||
|
|
||||||
|
object SampleData {
|
||||||
|
val demoRelease = Release(
|
||||||
|
packageName = "com.looker.droidify",
|
||||||
|
selected = false,
|
||||||
|
version = "v0.2.3",
|
||||||
|
versionCode = 1234,
|
||||||
|
added = 12345,
|
||||||
|
size = 12345,
|
||||||
|
maxSdkVersion = 32,
|
||||||
|
minSdkVersion = 29,
|
||||||
|
targetSdkVersion = 32,
|
||||||
|
source = "",
|
||||||
|
release = "",
|
||||||
|
hash = "",
|
||||||
|
hashType = "",
|
||||||
|
signature = "",
|
||||||
|
obbPatchHashType = "",
|
||||||
|
obbPatchHash = "",
|
||||||
|
obbPatch = "",
|
||||||
|
obbMainHashType = "",
|
||||||
|
obbMainHash = "",
|
||||||
|
obbMain = "",
|
||||||
|
permissions = listOf(),
|
||||||
|
features = listOf(),
|
||||||
|
platforms = listOf(),
|
||||||
|
incompatibilities = listOf()
|
||||||
|
)
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user