mirror of
https://github.com/Aviortheking/Neo-Store.git
synced 2025-06-08 00:39:54 +00:00
Update: Revamp AppSheet's header
This commit is contained in:
parent
9102d2845c
commit
8e954246cc
@ -2,31 +2,30 @@ package com.machiav3lli.fdroid.ui.compose.components.appsheet
|
|||||||
|
|
||||||
import androidx.compose.animation.AnimatedVisibility
|
import androidx.compose.animation.AnimatedVisibility
|
||||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||||
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.combinedClickable
|
import androidx.compose.foundation.combinedClickable
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.Spacer
|
import androidx.compose.foundation.layout.Spacer
|
||||||
|
import androidx.compose.foundation.layout.fillMaxHeight
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.height
|
import androidx.compose.foundation.layout.height
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.layout.size
|
import androidx.compose.foundation.layout.size
|
||||||
import androidx.compose.foundation.layout.width
|
import androidx.compose.foundation.layout.width
|
||||||
import androidx.compose.foundation.layout.wrapContentHeight
|
|
||||||
import androidx.compose.material3.LinearProgressIndicator
|
import androidx.compose.material3.LinearProgressIndicator
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.ShapeDefaults
|
import androidx.compose.material3.ShapeDefaults
|
||||||
import androidx.compose.material3.Surface
|
import androidx.compose.material3.Surface
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.material3.surfaceColorAtElevation
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.getValue
|
|
||||||
import androidx.compose.runtime.mutableStateOf
|
|
||||||
import androidx.compose.runtime.remember
|
|
||||||
import androidx.compose.runtime.setValue
|
|
||||||
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.draw.clip
|
||||||
|
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 com.machiav3lli.fdroid.R
|
import com.machiav3lli.fdroid.R
|
||||||
@ -40,8 +39,6 @@ import com.machiav3lli.fdroid.utility.extension.text.formatSize
|
|||||||
@Composable
|
@Composable
|
||||||
fun AppInfoHeader(
|
fun AppInfoHeader(
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
versionCode: String,
|
|
||||||
appSize: String,
|
|
||||||
repoHost: String,
|
repoHost: String,
|
||||||
mainAction: ActionState?,
|
mainAction: ActionState?,
|
||||||
possibleActions: Set<ActionState>,
|
possibleActions: Set<ActionState>,
|
||||||
@ -49,8 +46,6 @@ fun AppInfoHeader(
|
|||||||
onSourceLong: () -> Unit = { },
|
onSourceLong: () -> Unit = { },
|
||||||
onAction: (ActionState?) -> Unit = { }
|
onAction: (ActionState?) -> Unit = { }
|
||||||
) {
|
) {
|
||||||
var isExpanded by remember { mutableStateOf(false) }
|
|
||||||
|
|
||||||
Surface(
|
Surface(
|
||||||
modifier = modifier.fillMaxWidth(),
|
modifier = modifier.fillMaxWidth(),
|
||||||
shape = MaterialTheme.shapes.large,
|
shape = MaterialTheme.shapes.large,
|
||||||
@ -61,28 +56,10 @@ fun AppInfoHeader(
|
|||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
verticalArrangement = Arrangement.spacedBy(8.dp)
|
verticalArrangement = Arrangement.spacedBy(8.dp)
|
||||||
) {
|
) {
|
||||||
HeaderExtra(
|
|
||||||
versionCode = versionCode,
|
|
||||||
appSize = appSize,
|
|
||||||
repoHost = repoHost,
|
|
||||||
onSource = onSource,
|
|
||||||
onSourceLong = onSourceLong
|
|
||||||
)
|
|
||||||
|
|
||||||
Row(
|
Row(
|
||||||
horizontalArrangement = Arrangement.spacedBy(8.dp)
|
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||||
|
verticalAlignment = Alignment.CenterVertically
|
||||||
) {
|
) {
|
||||||
if (possibleActions.size == 1) {
|
|
||||||
SecondaryActionButton(packageState = possibleActions.first(), onClick = {
|
|
||||||
onAction(possibleActions.first())
|
|
||||||
})
|
|
||||||
} else if (possibleActions.size > 1) {
|
|
||||||
SecondaryActionButton(
|
|
||||||
packageState = if (isExpanded) ActionState.Retract else ActionState.Expand,
|
|
||||||
onClick = {
|
|
||||||
isExpanded = !isExpanded
|
|
||||||
})
|
|
||||||
}
|
|
||||||
MainActionButton(
|
MainActionButton(
|
||||||
modifier = Modifier.weight(1f),
|
modifier = Modifier.weight(1f),
|
||||||
actionState = mainAction ?: ActionState.Install,
|
actionState = mainAction ?: ActionState.Install,
|
||||||
@ -90,8 +67,15 @@ fun AppInfoHeader(
|
|||||||
onAction(mainAction)
|
onAction(mainAction)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
SourceCodeCard(
|
||||||
|
modifier = Modifier.padding(vertical = 4.dp),
|
||||||
|
title = stringResource(id = R.string.source_code),
|
||||||
|
text = repoHost,
|
||||||
|
onClick = onSource,
|
||||||
|
onLongClick = onSourceLong
|
||||||
|
)
|
||||||
}
|
}
|
||||||
AnimatedVisibility(visible = isExpanded) {
|
AnimatedVisibility(visible = possibleActions.isNotEmpty()) {
|
||||||
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||||
possibleActions.forEach {
|
possibleActions.forEach {
|
||||||
SecondaryActionButton(packageState = it) {
|
SecondaryActionButton(packageState = it) {
|
||||||
@ -153,46 +137,10 @@ fun TopBarHeader(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun HeaderExtra(
|
|
||||||
modifier: Modifier = Modifier,
|
|
||||||
versionCode: String,
|
|
||||||
appSize: String,
|
|
||||||
repoHost: String,
|
|
||||||
onSource: () -> Unit,
|
|
||||||
onSourceLong: () -> Unit
|
|
||||||
) {
|
|
||||||
Row(
|
|
||||||
modifier = modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.wrapContentHeight(),
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(8.dp)
|
|
||||||
) {
|
|
||||||
HeaderExtrasCard(
|
|
||||||
modifier = Modifier.weight(1f),
|
|
||||||
title = stringResource(id = R.string.version),
|
|
||||||
text = versionCode
|
|
||||||
)
|
|
||||||
HeaderExtrasCard(
|
|
||||||
modifier = Modifier.weight(1f),
|
|
||||||
title = stringResource(id = R.string.size),
|
|
||||||
text = appSize
|
|
||||||
)
|
|
||||||
HeaderExtrasCard(
|
|
||||||
modifier = Modifier.weight(1f),
|
|
||||||
title = stringResource(id = R.string.source_code),
|
|
||||||
text = repoHost,
|
|
||||||
onClick = onSource,
|
|
||||||
onLongClick = onSourceLong
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@OptIn(ExperimentalFoundationApi::class)
|
@OptIn(ExperimentalFoundationApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun HeaderExtrasCard(
|
fun SourceCodeCard(
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
extra: @Composable () -> Unit = {},
|
|
||||||
title: String,
|
title: String,
|
||||||
text: String,
|
text: String,
|
||||||
onClick: () -> Unit = {},
|
onClick: () -> Unit = {},
|
||||||
@ -202,15 +150,27 @@ fun HeaderExtrasCard(
|
|||||||
modifier = modifier
|
modifier = modifier
|
||||||
.clip(MaterialTheme.shapes.medium)
|
.clip(MaterialTheme.shapes.medium)
|
||||||
.combinedClickable(onClick = onClick, onLongClick = onLongClick)
|
.combinedClickable(onClick = onClick, onLongClick = onLongClick)
|
||||||
.padding(12.dp)
|
.background(MaterialTheme.colorScheme.surfaceColorAtElevation(1.dp))
|
||||||
|
.padding(vertical = 8.dp, horizontal = 12.dp)
|
||||||
|
.fillMaxHeight(),
|
||||||
|
color = Color.Transparent
|
||||||
) {
|
) {
|
||||||
Column(
|
Column(
|
||||||
verticalArrangement = Arrangement.SpaceEvenly,
|
verticalArrangement = Arrangement.SpaceEvenly,
|
||||||
horizontalAlignment = Alignment.CenterHorizontally
|
horizontalAlignment = Alignment.CenterHorizontally
|
||||||
) {
|
) {
|
||||||
extra()
|
Text(
|
||||||
Text(text = title, style = MaterialTheme.typography.labelLarge, maxLines = 1)
|
text = title,
|
||||||
Text(text = text, style = MaterialTheme.typography.bodyMedium, maxLines = 1)
|
style = MaterialTheme.typography.labelLarge,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
maxLines = 1
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
text = text,
|
||||||
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
|
color = MaterialTheme.colorScheme.primary,
|
||||||
|
maxLines = 1
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user