feat: don't allow expanding without content

This commit is contained in:
Ushie 2022-12-18 03:54:34 +03:00
parent 7e1f829e3c
commit a161467457
No known key found for this signature in database
GPG Key ID: 0EF73F1CA38B2D5F
2 changed files with 70 additions and 54 deletions

View File

@ -12,17 +12,22 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.rotate import androidx.compose.ui.draw.rotate
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.compositeOver
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import app.revanced.manager.R import app.revanced.manager.R
import app.revanced.manager.ui.navigation.AppDestination
import dev.olshevski.navigation.reimagined.navController
import dev.olshevski.navigation.reimagined.navigate
@Composable @Composable
fun ApplicationItem( fun ApplicationItem(
appName: String, appName: String,
appIcon: @Composable () -> Unit, appIcon: @Composable () -> Unit,
releaseAgo: String, appVersion: String,
expandedContent: @Composable () -> Unit, onClick: () -> Unit,
expandedContent: (@Composable () -> Unit)? = null,
) { ) {
var expandedState by remember { mutableStateOf(false) } var expandedState by remember { mutableStateOf(false) }
val rotateState by animateFloatAsState(targetValue = if (expandedState) 180f else 0f) val rotateState by animateFloatAsState(targetValue = if (expandedState) 180f else 0f)
@ -62,13 +67,14 @@ fun ApplicationItem(
maxLines = 1 maxLines = 1
) )
Text( Text(
text = releaseAgo, text = appVersion,
style = MaterialTheme.typography.bodySmall, style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant, color = MaterialTheme.colorScheme.onSurfaceVariant,
) )
} }
} }
Row { Row {
if (expandedContent != null) {
IconButton( IconButton(
modifier = Modifier.rotate(rotateState), modifier = Modifier.rotate(rotateState),
onClick = { expandedState = !expandedState }, onClick = { expandedState = !expandedState },
@ -78,11 +84,13 @@ fun ApplicationItem(
contentDescription = stringResource(R.string.expand) contentDescription = stringResource(R.string.expand)
) )
} }
OutlinedButton(onClick = {}) { }
Text(stringResource(R.string.update)) OutlinedButton(onClick = onClick) {
Text(stringResource(R.string.info))
} }
} }
} }
if (expandedContent != null) {
AnimatedVisibility( AnimatedVisibility(
visible = expandedState visible = expandedState
) { ) {
@ -97,24 +105,23 @@ fun ApplicationItem(
} }
} }
} }
}
@Composable @Composable
fun ApplicationItemDualTint( fun ApplicationItemDualTint(
appName: String, appName: String,
appIcon: @Composable () -> Unit, appIcon: @Composable () -> Unit,
releaseAgo: String, appVersion: String,
expandedContent: @Composable () -> Unit, onClick: () -> Unit,
expandedContent: (@Composable () -> Unit)? = null,
) { ) {
var expandedState by remember { mutableStateOf(false) } var expandedState by remember { mutableStateOf(false) }
val rotateState by animateFloatAsState(targetValue = if (expandedState) 180f else 0f) val rotateState by animateFloatAsState(targetValue = if (expandedState) 180f else 0f)
Card( ElevatedCard(
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.defaultMinSize(minHeight = 68.dp), .defaultMinSize(minHeight = 68.dp)
colors = CardDefaults.cardColors(
containerColor = Color(0xFF1E2630)
)
) { ) {
Column( Column(
modifier = Modifier modifier = Modifier
@ -132,8 +139,7 @@ fun ApplicationItemDualTint(
modifier = Modifier modifier = Modifier
.height(68.dp) .height(68.dp)
.weight(1f), .weight(1f),
verticalAlignment = Alignment.CenterVertically, verticalAlignment = Alignment.CenterVertically
horizontalArrangement = Arrangement.SpaceBetween,
) { ) {
appIcon() appIcon()
Column(modifier = Modifier.padding(start = 8.dp)) { Column(modifier = Modifier.padding(start = 8.dp)) {
@ -143,13 +149,14 @@ fun ApplicationItemDualTint(
maxLines = 1 maxLines = 1
) )
Text( Text(
text = releaseAgo, text = appVersion,
style = MaterialTheme.typography.bodySmall, style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant, color = MaterialTheme.colorScheme.onSurfaceVariant,
) )
} }
} }
Row(verticalAlignment = Alignment.CenterVertically) { Row(verticalAlignment = Alignment.CenterVertically) {
if (expandedContent != null) {
IconButton( IconButton(
modifier = Modifier.rotate(rotateState), modifier = Modifier.rotate(rotateState),
onClick = { expandedState = !expandedState }, onClick = { expandedState = !expandedState },
@ -159,19 +166,23 @@ fun ApplicationItemDualTint(
contentDescription = stringResource(R.string.expand) contentDescription = stringResource(R.string.expand)
) )
} }
OutlinedButton(onClick = { /*TODO*/ }) { }
Text(stringResource(R.string.update)) Button(onClick = onClick) {
Text(stringResource(R.string.info))
} }
} }
} }
} }
if (expandedContent != null) {
AnimatedVisibility( AnimatedVisibility(
visible = expandedState visible = expandedState
) { ) {
Box( Box(
modifier = Modifier modifier = Modifier
.fillMaxSize() .fillMaxSize()
.background(color = Color(0xFF11161C)) .background(color = MaterialTheme.colorScheme.surface.copy(alpha = .4f).compositeOver(
MaterialTheme.colorScheme.surfaceColorAtElevation(10.dp)
))
.padding(14.dp, 10.dp), .padding(14.dp, 10.dp),
) { ) {
expandedContent() expandedContent()
@ -180,3 +191,4 @@ fun ApplicationItemDualTint(
} }
} }
} }
}

View File

@ -1,6 +1,7 @@
package app.revanced.manager.ui.viewmodel package app.revanced.manager.ui.viewmodel
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.os.Parcelable
import android.text.format.DateUtils import android.text.format.DateUtils
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
@ -15,6 +16,7 @@ import app.revanced.manager.util.ghManager
import app.revanced.manager.util.ghPatcher import app.revanced.manager.util.ghPatcher
import io.ktor.http.* import io.ktor.http.*
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.parcelize.Parcelize
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.* import java.util.*
@ -67,10 +69,12 @@ class DashboardViewModel(
} }
} }
@Parcelize
@Serializable @Serializable
class PatchedApp( data class PatchedApp(
val appName: String, val appName: String,
val pkgName: String, val pkgName: String,
val version: String, val appVersion: String,
val appliedPatches: List<String> val appliedPatches: List<String>,
) val patchedDate: String
) : Parcelable