From 79fe50ee4158ab5dcf56dd800ea01f6a2af34ecf Mon Sep 17 00:00:00 2001 From: machiav3lli Date: Sun, 29 May 2022 03:16:06 +0200 Subject: [PATCH] Update: Replace InstallButton with two ActionButton's --- .../ui/compose/components/ActionButton.kt | 96 +++++++++++++++++++ .../ui/compose/components/InstallButton.kt | 59 ------------ 2 files changed, 96 insertions(+), 59 deletions(-) create mode 100644 src/main/kotlin/com/looker/droidify/ui/compose/components/ActionButton.kt delete mode 100644 src/main/kotlin/com/looker/droidify/ui/compose/components/InstallButton.kt diff --git a/src/main/kotlin/com/looker/droidify/ui/compose/components/ActionButton.kt b/src/main/kotlin/com/looker/droidify/ui/compose/components/ActionButton.kt new file mode 100644 index 00000000..5ad8d53d --- /dev/null +++ b/src/main/kotlin/com/looker/droidify/ui/compose/components/ActionButton.kt @@ -0,0 +1,96 @@ +package com.looker.droidify.ui.compose.components + +import androidx.compose.animation.AnimatedContent +import androidx.compose.animation.ExperimentalAnimationApi +import androidx.compose.animation.SizeTransform +import androidx.compose.animation.fadeIn +import androidx.compose.animation.fadeOut +import androidx.compose.animation.slideInVertically +import androidx.compose.animation.slideOutVertically +import androidx.compose.animation.with +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.defaultMinSize +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.width +import androidx.compose.material3.ButtonDefaults +import androidx.compose.material3.ElevatedButton +import androidx.compose.material3.Icon +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.unit.dp +import com.looker.droidify.entity.PackageState + +@OptIn(ExperimentalAnimationApi::class) +@Composable +fun MainActionButton( + modifier: Modifier = Modifier, + packageState: PackageState, + onClick: (PackageState) -> Unit +) { + ElevatedButton( + modifier = modifier, + onClick = { onClick(packageState) } + ) { + AnimatedContent( + targetState = packageState, + transitionSpec = { + //when (targetState) { + /*is Cancelable -> { + slideInVertically { height -> height } + fadeIn() with + slideOutVertically { height -> -height } + fadeOut() + }*/ + //is ButtonWork -> { + (slideInVertically { height -> -height } + fadeIn() with + slideOutVertically { height -> height } + fadeOut()) + //} + //} + .using(SizeTransform(clip = false)) + } + ) { + Row( + Modifier + .defaultMinSize(minHeight = ButtonDefaults.MinHeight) + .padding(ButtonDefaults.ContentPadding), + horizontalArrangement = Arrangement.Center, + verticalAlignment = Alignment.CenterVertically + ) { + Icon(imageVector = it.icon, contentDescription = null) + Spacer(modifier = Modifier.width(8.dp)) + Text(text = stringResource(id = it.textId)) + } + } + } +} + +@OptIn(ExperimentalAnimationApi::class) +@Composable +fun SecondaryActionButton( + modifier: Modifier = Modifier, + packageState: PackageState?, + onClick: () -> Unit +) { + packageState?.let { + ElevatedButton( + modifier = modifier, + onClick = { onClick() } + ) { + Row( + Modifier + .defaultMinSize(minHeight = ButtonDefaults.MinHeight) + .padding( + vertical = ButtonDefaults.ContentPadding.calculateTopPadding(), + horizontal = 0.dp + ), + horizontalArrangement = Arrangement.Center, + verticalAlignment = Alignment.CenterVertically + ) { + Icon(imageVector = it.icon, contentDescription = null) + } + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/looker/droidify/ui/compose/components/InstallButton.kt b/src/main/kotlin/com/looker/droidify/ui/compose/components/InstallButton.kt deleted file mode 100644 index 59a1002b..00000000 --- a/src/main/kotlin/com/looker/droidify/ui/compose/components/InstallButton.kt +++ /dev/null @@ -1,59 +0,0 @@ -package com.looker.droidify.ui.compose.components - -import androidx.compose.animation.* -import androidx.compose.foundation.layout.* -import androidx.compose.material3.ButtonDefaults -import androidx.compose.material3.ElevatedButton -import androidx.compose.material3.Icon -import androidx.compose.material3.Text -import androidx.compose.runtime.Composable -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.unit.dp -import com.looker.droidify.ui.compose.utils.ButtonStates -import com.looker.droidify.ui.compose.utils.ButtonWork -import com.looker.droidify.ui.compose.utils.Cancelable - -@OptIn(ExperimentalAnimationApi::class) -@Composable -fun InstallButton( - modifier: Modifier = Modifier, - buttonState: ButtonStates, - onClick: (ButtonStates) -> Unit -) { - ElevatedButton( - modifier = modifier, - onClick = { onClick(buttonState) } - ) { - AnimatedContent( - targetState = buttonState, - transitionSpec = { - when (targetState) { - is Cancelable -> { - slideInVertically { height -> height } + fadeIn() with - slideOutVertically { height -> -height } + fadeOut() - } - is ButtonWork -> { - slideInVertically { height -> -height } + fadeIn() with - slideOutVertically { height -> height } + fadeOut() - } - }.using(SizeTransform(clip = false)) - } - ) { - Row( - Modifier - .defaultMinSize( - minWidth = ButtonDefaults.MinWidth, - minHeight = ButtonDefaults.MinHeight - ) - .padding(ButtonDefaults.ContentPadding), - horizontalArrangement = Arrangement.Center, - verticalAlignment = Alignment.CenterVertically - ) { - Icon(imageVector = it.icon, contentDescription = null) - Spacer(modifier = Modifier.width(8.dp)) - Text(text = it.text) - } - } - } -} \ No newline at end of file