Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 17 additions & 21 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ plugins {
}

android {
compileSdkVersion 30
buildToolsVersion "30.0.2"
compileSdkVersion 33

defaultConfig {
applicationId "com.bruno.aybar.composechallenges"
minSdkVersion 21
targetSdkVersion 30
targetSdkVersion 33
versionCode 1
versionName "1.0"

Expand All @@ -29,33 +28,30 @@ android {
}
kotlinOptions {
jvmTarget = '1.8'
useIR = true
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion compose_version
kotlinCompilerVersion '1.4.30'
}
}

dependencies {

implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.1'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.0'
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.runtime:runtime-livedata:$compose_version"
implementation "androidx.compose.ui:ui-tooling:$compose_version"
implementation "androidx.constraintlayout:constraintlayout-compose:1.0.0-alpha03"
implementation "androidx.activity:activity-compose:1.3.0-alpha03"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.0'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.0'
implementation platform('androidx.compose:compose-bom:2022.10.00')
implementation 'androidx.core:core-ktx:1.9.0'
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.6.0'
implementation "androidx.compose.ui:ui"
implementation "androidx.compose.material:material"
implementation "androidx.compose.runtime:runtime-livedata"
implementation "androidx.compose.ui:ui-tooling"
implementation "androidx.constraintlayout:constraintlayout-compose:1.0.1"
implementation "androidx.activity:activity-compose"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.1'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.5.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0'
}
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<activity
android:name=".backup.BackupActivity"
android:label="@string/app_name"
android:exported="true"
android:theme="@style/Theme.ComposeChallenges.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.bruno.aybar.composechallenges.backup

import android.annotation.SuppressLint
import androidx.compose.animation.core.*
import androidx.compose.animation.core.AnimationConstants.DefaultDurationMillis
import androidx.compose.foundation.layout.*
Expand Down Expand Up @@ -120,9 +121,10 @@ private fun buildUiProperties(state: ButtonsState): ButtonsUiProperties {
tween(easing = LinearEasing)
}
},
targetValueByState = { if(it == ButtonsState.CreateBackup) 1f else 0f }
targetValueByState = { if(it == ButtonsState.CreateBackup) 1f else 0f }, label = ""
)

@SuppressLint("UnusedTransitionTargetStateParameter")
val backupButtonSizeMultiplier = transition.animateFloat(
transitionSpec = {
if(ButtonsState.CreateBackup isTransitioningTo ButtonsState.Cancel) {
Expand All @@ -131,7 +133,7 @@ private fun buildUiProperties(state: ButtonsState): ButtonsUiProperties {
keyframes { 1.05f at animationDuration / 2 }
}
},
targetValueByState = { 1f }
targetValueByState = { 1f }, label = "backupButtonSizeMultiplier"
)

val cancelButtonAlpha = transition.animateFloat(
Expand All @@ -142,7 +144,7 @@ private fun buildUiProperties(state: ButtonsState): ButtonsUiProperties {
tween(easing = LinearEasing)
}
},
targetValueByState = { if(it == ButtonsState.CreateBackup) 0f else 0.6f }
targetValueByState = { if(it == ButtonsState.CreateBackup) 0f else 0.6f }, label = "cancelButtonAlpha"
)

val cancelButtonWidth = transition.animateInt(
Expand All @@ -153,7 +155,7 @@ private fun buildUiProperties(state: ButtonsState): ButtonsUiProperties {
tween()
}
},
targetValueByState = { if(it == ButtonsState.CreateBackup) 180 else 150 }
targetValueByState = { if(it == ButtonsState.CreateBackup) 180 else 150 }, label = "cancelButtonWidth"
)

return ButtonsUiProperties(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ private fun buildUiProperties(state: BodyState): BackupBodyUiProperties {
BodyState.LAST_BACKUP -> 1f
BodyState.UPLOADING -> 0f
}
}
}, label = "lastBackupAlpha"
)
val lastBackupHintOffset: Int by transition.animateInt(
transitionSpec = {
Expand All @@ -131,7 +131,7 @@ private fun buildUiProperties(state: BodyState): BackupBodyUiProperties {
BodyState.LAST_BACKUP -> 0
BodyState.UPLOADING -> 15
}
}
}, label = "lastBackupHintOffset"
)
val lastBackupDateOffset: Int by transition.animateInt(
transitionSpec = {
Expand All @@ -145,7 +145,7 @@ private fun buildUiProperties(state: BodyState): BackupBodyUiProperties {
BodyState.LAST_BACKUP -> 0
BodyState.UPLOADING -> 40
}
}
}, label = "lastBackupDateOffset"
)
val uploadingAlpha: Float by transition.animateFloat(
transitionSpec = {
Expand All @@ -159,7 +159,7 @@ private fun buildUiProperties(state: BodyState): BackupBodyUiProperties {
BodyState.LAST_BACKUP -> 0f
BodyState.UPLOADING -> 1f
}
}
}, label = "uploadingAlpha"
)
val uploadingOffset: Int by transition.animateInt(
transitionSpec = {
Expand All @@ -173,7 +173,7 @@ private fun buildUiProperties(state: BodyState): BackupBodyUiProperties {
BodyState.LAST_BACKUP -> 30
BodyState.UPLOADING -> 0
}
}
}, label = "uploadingOffset"
)
return BackupBodyUiProperties(
lastBackupAlpha = lastBackupAlpha,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ data class Bubble(

@Composable
private fun buildUiProperties(stateHolder: AnimatedCloudState): CloudUiProperties {
val transition: Transition<CloudState> = updateTransition(stateHolder.state)
val transition: Transition<CloudState> = updateTransition(stateHolder.state, label = "cloudTransition")
val defaultDuration = 1000
val circleSize = transition.animateFloat(
transitionSpec = {
Expand All @@ -246,7 +246,7 @@ private fun buildUiProperties(stateHolder: AnimatedCloudState): CloudUiPropertie
CloudState.MERGED -> 1.5f
CloudState.COVERING -> 10F
}
}
}, label = "circleSize"
)

val sideCloudsOffset = transition.animateFloat(
Expand All @@ -263,7 +263,7 @@ private fun buildUiProperties(stateHolder: AnimatedCloudState): CloudUiPropertie
CloudState.MERGED -> 1f
else -> 1f
}
}
}, label = "sideCloudsOffset"
)

val exitBubblesProgress = transition.animateFloat(
Expand All @@ -279,7 +279,7 @@ private fun buildUiProperties(stateHolder: AnimatedCloudState): CloudUiPropertie
CloudState.COVERING -> 0.8f
else -> 0f
}
}
}, label = "exitBubblesProgress"
)

return CloudUiProperties(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ private fun AnimatedCheck(progress: Float, modifier: Modifier) {
}
}

@Suppress("UnnecessaryVariable")
private fun DrawScope.drawAnimatedCheck(progress: Float, stroke: Stroke, color: Color) {
val w1 = 20f
val w2 = 55f
Expand Down Expand Up @@ -160,26 +161,33 @@ private fun DrawScope.drawAnimatedCheck(progress: Float, stroke: Stroke, color:

@Composable
private fun buildUiProperties(state: BackupCompletedState): BackupCompletedUiProperties{
val transition: Transition<BackupCompletedState> = updateTransition(targetState = state)
val transition: Transition<BackupCompletedState> = updateTransition(
targetState = state,
label = "backupTransition"
)

val floatSpec = AnimationSpecBuilder<Float>()
val intSpec = AnimationSpecBuilder<Int>()

val completedProgress: Float by transition.animateFloat(
transitionSpec = { with(floatSpec) { buildAnimationSpec() } },
targetValueByState = { if(it == BackupCompletedState.HIDDEN) 0f else 1f }
targetValueByState = { if(it == BackupCompletedState.HIDDEN) 0f else 1f },
label = "completedProgress"
)
val topSpacing: Int by transition.animateInt(
transitionSpec = { with(intSpec) { buildAnimationSpec() } },
targetValueByState = { if(it == BackupCompletedState.HIDDEN) 36 else 20 }
targetValueByState = { if(it == BackupCompletedState.HIDDEN) 36 else 20 },
label = "topSpacing"
)
val textSeparation: Int by transition.animateInt(
transitionSpec = { with(intSpec) { buildAnimationSpec() } },
targetValueByState = { if(it == BackupCompletedState.HIDDEN) 16 else 4 }
targetValueByState = { if(it == BackupCompletedState.HIDDEN) 16 else 4 },
label = "textSeparation"
)
val buttonBottom: Int by transition.animateInt(
transitionSpec = { with(intSpec) { buildAnimationSpec() } },
targetValueByState = { if(it == BackupCompletedState.HIDDEN) 8 else 24 }
targetValueByState = { if(it == BackupCompletedState.HIDDEN) 8 else 24 },
label = "buttonBottom"
)

return BackupCompletedUiProperties(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,38 +107,54 @@ private data class BatmanUiProperties(

@Composable
private fun buildUiProperties(transitionState: MutableTransitionState<BatmanPageState>, maxHeight: Float): BatmanUiProperties {
val transition = updateTransition(transitionState)
val transition = updateTransition(transitionState, label = "batmanTransition")
val tweenWithSimpleDelay = tween<Float>(durationMillis = 1000, delayMillis = 500)
val batmanLogoHeight: Float by transition.animateFloat( { tweenWithSimpleDelay }) {
when(transition.currentState) {
val batmanLogoHeight: Float by transition.animateFloat( { tweenWithSimpleDelay }, label = "batmanLogoHeight") {
when(it) {
BatmanPageState.LogoCovering -> maxHeight
else -> 40f
}
}
val batmanLogoVerticalBias: Float by transition.animateFloat( { tweenWithSimpleDelay }) {
when(transition.currentState) {
BatmanPageState.LogoCovering, BatmanPageState.LogoCentered -> 0f
BatmanPageState.LogoAndHint, BatmanPageState.Completed -> -0.3f
val batmanLogoVerticalBias: Float by transition.animateFloat(
transitionSpec = { tweenWithSimpleDelay },
label = "batmanLogoVerticalBias",
targetValueByState = { targetState ->
when(targetState) {
BatmanPageState.LogoCovering, BatmanPageState.LogoCentered -> 0f
BatmanPageState.LogoAndHint, BatmanPageState.Completed -> -0.3f
}
}
}
val welcomeAlpha: Float by transition.animateFloat( { tween(durationMillis = 800, delayMillis = 700) }) {
when(transition.currentState) {
BatmanPageState.LogoCovering, BatmanPageState.LogoCentered -> 0f
BatmanPageState.LogoAndHint, BatmanPageState.Completed -> 1f
)
val welcomeAlpha: Float by transition.animateFloat(
transitionSpec = { tween(durationMillis = 800, delayMillis = 700) },
label = "welcomeAlpha",
targetValueByState = { targetState ->
when(targetState) {
BatmanPageState.LogoCovering, BatmanPageState.LogoCentered -> 0f
BatmanPageState.LogoAndHint, BatmanPageState.Completed -> 1f
}
}
}
val batmanSizeProgress: Float by transition.animateFloat( { tweenWithSimpleDelay }) {
when(transition.currentState) {
BatmanPageState.Completed -> 1f
else -> 3f
)
val batmanSizeProgress: Float by transition.animateFloat(
transitionSpec = { tweenWithSimpleDelay },
label = "batmanSizeProgress",
targetValueByState = { targetState ->
when(targetState) {
BatmanPageState.Completed -> 1f
else -> 3f
}
}
}
val batmanButtonsAlpha: Float by transition.animateFloat( { tweenWithSimpleDelay }) {
when(transition.currentState) {
BatmanPageState.Completed -> 1f
else -> 0f
)
val batmanButtonsAlpha: Float by transition.animateFloat(
transitionSpec = { tweenWithSimpleDelay },
label = "batmanButtonsAlpha",
targetValueByState = { targetState ->
when(targetState) {
BatmanPageState.Completed -> 1f
else -> 0f
}
}
}
)

return BatmanUiProperties(
batmanLogoHeight = batmanLogoHeight,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class FlappyBirdViewModel: ViewModel() {
when(it) {
is FlappyGameUi.Playing -> updateScore(it)
is FlappyGameUi.Finished -> hasStarted = false
is FlappyGameUi.NotStarted -> Unit // do nothing
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ fun FlappyBirdTheme(content: @Composable() () -> Unit) {
surface = skyColor,
background = brown,
onPrimary = Color.White,
onSecondary = Color.White,
onBackground = Color.White,
onSurface = Color.White
)
Expand Down
Loading