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

View File

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