Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CAT-297] 온보딩 RIVE 애니메이션 적용 액션 변경 / RIVE Version Upgrade #97

Merged
merged 7 commits into from
Aug 24, 2024
12 changes: 10 additions & 2 deletions app/src/main/java/com/pomonyang/mohanyang/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withTimeout
import timber.log.Timber

@OptIn(DelicateCoroutinesApi::class)
Expand Down Expand Up @@ -95,7 +96,7 @@ class MainActivity : ComponentActivity() {
getTokenByDeviceIdUseCase()
.onSuccess {
userRepository.fetchMyInfo().onSuccess {
if (it.cat.no == -1) isNewUser = true
isNewUser = it.cat.no == -1
}
pomodoroSettingRepository.fetchPomodoroSettingList()
showDialog = false
Expand All @@ -104,7 +105,14 @@ class MainActivity : ComponentActivity() {
}
}

runBlocking { initializeInfo() }
runBlocking {
try {
withTimeout(SPLASH_DELAY) {
initializeInfo()
}
} catch (ignored: Exception) {
}
}

MnTheme {
val mohaNyangAppState = rememberMohaNyangAppState(
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ google-services = "4.4.2"
permission = "0.35.1-alpha"
startup = "1.1.1"
lottie = "6.0.0"
rive = "8.7.0"
rive = "9.6.4"

[libraries]
# Compose
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.viewinterop.AndroidView
import androidx.compose.ui.zIndex
import app.rive.runtime.kotlin.RiveAnimationView
import app.rive.runtime.kotlin.core.ExperimentalAssetLoader
import com.pomonyang.mohanyang.presentation.designsystem.token.MnSpacing
import com.pomonyang.mohanyang.presentation.designsystem.tooltip.MnTooltipDefaults
import com.pomonyang.mohanyang.presentation.designsystem.tooltip.TooltipAnchor
Expand All @@ -35,7 +34,6 @@ import com.pomonyang.mohanyang.presentation.util.clickableSingle
import kotlin.time.Duration.Companion.seconds
import kotlinx.coroutines.delay

@OptIn(ExperimentalAssetLoader::class)
@Composable
fun CatRive(
@RawRes riveResource: Int,
Expand All @@ -45,6 +43,7 @@ fun CatRive(
riveAnimationName: String? = null,
stateMachineName: String? = null,
stateMachineInput: String? = null,
fireState: String? = null,
onRiveClick: (RiveAnimationView) -> Unit = {}
) {
val catRiveModifier = if (tooltipMessage != null) {
Expand All @@ -58,25 +57,25 @@ fun CatRive(
RiveAnimationView(context)
}

LaunchedEffect(stateMachineInput, riveAnimationName) {
if (stateMachineName != null
) {
LaunchedEffect(riveAnimationName) {
riveView.setRiveResource(
resId = riveResource,
stateMachineName = stateMachineName,
autoplay = isAutoPlay,
animationName = riveAnimationName
)
}

LaunchedEffect(stateMachineInput) {
if (stateMachineName != null && stateMachineInput != null) {
riveView.reset()
riveView.apply {
setRiveResource(
resId = riveResource,
stateMachineName = stateMachineName,
autoplay = isAutoPlay,
animationName = riveAnimationName
)
}
if (stateMachineInput != null) riveView.setBooleanState(stateMachineName, stateMachineInput, true)
riveView.setBooleanState(stateMachineName, stateMachineInput, true)
}
}

if (riveAnimationName != null) {
riveView.play(riveAnimationName)
} else {
riveView.play()
}
LaunchedEffect(fireState) {
if (stateMachineName != null && fireState != null) {
riveView.fireState(stateMachineName, fireState)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ enum class CatType(
val restEndPushContent: Int,
val backgroundPushContent: Int,
val messages: List<String>,
val onBoardingRiveCat: String,
val pomodoroRiveCat: String,
val catFireInput: String
) {
Expand All @@ -22,7 +21,6 @@ enum class CatType(
timerEndPushContent = R.string.cat_cheese_timer_end_push,
restEndPushContent = R.string.cat_cheese_rest_end_push,
backgroundPushContent = R.string.cat_cheese_background_push,
onBoardingRiveCat = "stretch_Cheese Cat",
pomodoroRiveCat = "cheeseCat",
messages = listOf(
"나랑 함께할 시간이다냥!",
Expand All @@ -37,7 +35,6 @@ enum class CatType(
timerEndPushContent = R.string.cat_black_timer_end_push,
restEndPushContent = R.string.cat_black_rest_end_push,
backgroundPushContent = R.string.cat_black_background_push,
onBoardingRiveCat = "stretch_Black Cat",
pomodoroRiveCat = "blackCat",
messages = listOf(
"나랑 함께할 시간이다냥!",
Expand All @@ -52,7 +49,6 @@ enum class CatType(
timerEndPushContent = R.string.cat_three_timer_end_push,
restEndPushContent = R.string.cat_cheese_rest_end_push,
backgroundPushContent = R.string.cat_three_background_push,
onBoardingRiveCat = "stretch_Calico Cat",
pomodoroRiveCat = "calicoCat",
messages = listOf(
"“시간이 없어서\"는 변명이다냥",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import app.rive.runtime.kotlin.core.ExperimentalAssetLoader
import com.mohanyang.presentation.R
import com.pomonyang.mohanyang.presentation.component.CatRive
import com.pomonyang.mohanyang.presentation.designsystem.button.box.MnBoxButton
Expand Down Expand Up @@ -68,7 +66,6 @@ internal fun CatProfileRoute(
)
}

@OptIn(ExperimentalAssetLoader::class)
@Composable
private fun CatProfileScreen(
state: CatProfileState,
Expand Down Expand Up @@ -112,14 +109,9 @@ private fun CatProfileScreen(
isAutoPlay = false,
modifier = Modifier.fillMaxWidth(),
tooltipMessage = stringResource(id = R.string.cat_profile_tooltip),
riveResource = R.raw.cat_rest,
stateMachineName = "State Machine_Home",
stateMachineInput = state.catType.pomodoroRiveCat,
onRiveClick = remember {
{
it.fireState("State Machine_Home", state.catType.catFireInput)
}
}
riveResource = R.raw.cat_rename_2,
stateMachineName = "State Machine_Rename",
stateMachineInput = state.catType.pomodoroRiveCat
)

Row(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,14 @@ fun OnboardingNamingCatScreen(
.imePadding()

) {
MnTopAppBar(navigationIcon = {
MnIconButton(
onClick = onBackClick,
iconResourceId = R.drawable.ic_chevron_left
)
})
MnTopAppBar(
navigationIcon = {
MnIconButton(
onClick = onBackClick,
iconResourceId = R.drawable.ic_chevron_left
)
}
)

LazyColumn(
state = listState,
Expand All @@ -120,15 +122,10 @@ fun OnboardingNamingCatScreen(
.padding(top = 130.dp)
.fillMaxWidth(),
isAutoPlay = false,
riveAnimationName = catType.onBoardingRiveCat,
stateMachineName = "State Machine_selectCat",
riveResource = R.raw.cat_select,
tooltipMessage = stringResource(id = R.string.naming_cat_tooltip),
onRiveClick = remember {
{
it.fireState("State Machine_Home", catType.catFireInput)
}
}
stateMachineInput = catType.pomodoroRiveCat,
stateMachineName = "State Machine_Rename",
riveResource = R.raw.cat_rename_2,
tooltipMessage = stringResource(id = R.string.naming_cat_tooltip)
)
Text(
modifier = Modifier.padding(
Expand All @@ -146,7 +143,7 @@ fun OnboardingNamingCatScreen(
errorMessage = nameValidationResult.message,
backgroundColor = MnColor.White,
onValueChange = { value -> name = value },
hint = catName ?: ""
hint = catName
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
Expand Down Expand Up @@ -152,16 +151,9 @@ fun OnboardingSelectCatScreen(
bottom = 42.dp
)
.fillMaxWidth(),
riveResource = R.raw.cat_select,
riveAnimationName = state.selectedType?.onBoardingRiveCat,
riveResource = R.raw.cat_select_2,
stateMachineName = "State Machine_selectCat",
onRiveClick = remember {
{ view ->
state.selectedType?.let {
view.fireState("State Machine_selectCat", it.catFireInput)
}
}
}
fireState = state.selectedType?.catFireInput
)

CatCategory(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
@file:OptIn(ExperimentalAssetLoader::class)

package com.pomonyang.mohanyang.presentation.screen.pomodoro

import androidx.activity.compose.BackHandler
Expand All @@ -24,7 +22,6 @@ import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.compose.LifecycleEventEffect
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import app.rive.runtime.kotlin.core.ExperimentalAssetLoader
import com.mohanyang.presentation.R
import com.pomonyang.mohanyang.presentation.component.CatRive
import com.pomonyang.mohanyang.presentation.component.CategoryBox
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
@file:OptIn(ExperimentalAssetLoader::class)

package com.pomonyang.mohanyang.presentation.screen.pomodoro.rest

import androidx.activity.compose.BackHandler
Expand All @@ -23,7 +21,6 @@ import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import app.rive.runtime.kotlin.core.ExperimentalAssetLoader
import com.mohanyang.presentation.R
import com.pomonyang.mohanyang.presentation.component.CatRive
import com.pomonyang.mohanyang.presentation.component.CategoryBox
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
@file:OptIn(ExperimentalAssetLoader::class)

package com.pomonyang.mohanyang.presentation.screen.pomodoro.setting

import android.annotation.SuppressLint
Expand Down Expand Up @@ -39,7 +37,6 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import app.rive.runtime.kotlin.core.ExperimentalAssetLoader
import com.mohanyang.presentation.R
import com.pomonyang.mohanyang.presentation.component.CatRive
import com.pomonyang.mohanyang.presentation.component.CategoryBox
Expand Down
Binary file added presentation/src/main/res/raw/cat_rename_2.riv
Binary file not shown.