ReleaseItem.kt almost ready

This commit is contained in:
Iamlooker 2022-04-21 01:07:12 +05:30
parent 10e8485f20
commit 0beed03cb5
2 changed files with 124 additions and 44 deletions

View File

@ -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,31 +28,68 @@ 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
) { ) {
ReleaseItemContent(
release = currentRelease,
isSuggested = isSuggested,
isInstalled = isInstalled,
onDownloadClick = onDownloadClick
)
}
}
@Composable
fun ReleaseItemContent(
modifier: Modifier = Modifier,
isSuggested: Boolean = false,
isInstalled: Boolean = false,
release: Release,
onDownloadClick: (Release) -> Unit = {}
) {
Row( Row(
modifier = Modifier.padding(end = 16.dp),
verticalAlignment = Alignment.CenterVertically, verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.Start horizontalArrangement = Arrangement.Start
) { ) {
IconButton(onClick = { onDownloadClick(currentRelease) }) { IconButton(onClick = { onDownloadClick(release) }) {
Icon( Icon(
imageVector = Icons.Rounded.Download, imageVector = Icons.Rounded.Download,
contentDescription = "Download Release" contentDescription = "Download this version"
) )
} }
Box { Box(
modifier = modifier
.height(74.dp)
.fillMaxWidth()
) {
ReleaseTitleWithBadge( ReleaseTitleWithBadge(
modifier = Modifier.align(Alignment.CenterStart), modifier = Modifier.align(Alignment.CenterStart),
title = release.version, version = release.version,
subtitle = release.targetSdkVersion.toString() repository = release.targetSdkVersion.toString()
) { ) {
AnimatedVisibility(visible = isSuggested) { AnimatedVisibility(
ReleaseBadge(text = stringResource(id = R.string.suggested)) visible = isSuggested or isInstalled,
enter = fadeIn(),
exit = fadeOut()
) {
val badgeText = remember { mutableStateOf(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( ReleaseItemEndText(
@ -61,42 +99,51 @@ fun ReleaseItem(
) )
} }
} }
}
} }
@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 = {}
) { ) {
Row(
verticalAlignment = Alignment.Top,
horizontalArrangement = Arrangement.spacedBy(16.dp)
) {
Column( Column(
modifier = modifier.matchParentSize(), modifier = modifier.fillMaxHeight(),
verticalArrangement = Arrangement.SpaceEvenly, verticalArrangement = Arrangement.SpaceEvenly,
horizontalAlignment = Alignment.Start horizontalAlignment = Alignment.Start
) { ) {
Row(horizontalArrangement = Arrangement.spacedBy(16.dp)) { Spacer(modifier = Modifier.width(Dp.Hairline))
Text(text = title, style = MaterialTheme.typography.bodyMedium) Text(text = version, style = MaterialTheme.typography.titleMedium)
badges() 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)
} }

View 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()
)
}