Skip to content

Commit

Permalink
Merge pull request #41 from Nexters/feature/start-flow
Browse files Browse the repository at this point in the history
μ‹œμž‘ ν”Œλ‘œμš° μˆ˜μ •
  • Loading branch information
yxnsx authored Sep 14, 2023
2 parents 8d0de55 + f2129fa commit a6803f9
Show file tree
Hide file tree
Showing 56 changed files with 493 additions and 379 deletions.
32 changes: 29 additions & 3 deletions app/src/main/java/com/keyme/app/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
package com.keyme.app

import android.animation.ObjectAnimator
import android.content.pm.PackageManager
import android.os.Build
import android.os.Bundle
import android.view.View
import android.view.animation.AnticipateInterpolator
import android.widget.Toast
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.result.contract.ActivityResultContracts
import androidx.core.animation.doOnEnd
import androidx.core.content.ContextCompat
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import com.keyme.app.ui.KeymeApp
import com.keyme.domain.entity.onSuccess
import com.keyme.domain.usecase.GetMyUserInfoUseCase
import com.keyme.domain.usecase.GetPushTokenSavedStateUseCase
import com.keyme.domain.usecase.GetUserAuthUseCase
import com.keyme.domain.usecase.InsertPushTokenUseCase
import com.keyme.domain.usecase.SetPushTokenSavedStateUseCase
import com.keyme.presentation.UiEvent
Expand All @@ -31,7 +35,7 @@ import javax.inject.Inject
class MainActivity : ComponentActivity() {

@Inject
lateinit var getUserAuthUseCase: GetUserAuthUseCase
lateinit var getMyUserInfoUseCase: GetMyUserInfoUseCase

@Inject
lateinit var uiEventManager: UiEventManager
Expand All @@ -47,6 +51,9 @@ class MainActivity : ComponentActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

setSplashScreen()

setContent {
KeymeApp()
}
Expand All @@ -60,6 +67,25 @@ class MainActivity : ComponentActivity() {
}
}

private fun setSplashScreen() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
splashScreen.setOnExitAnimationListener { splashScreenView ->
val slideUp = ObjectAnimator.ofFloat(
splashScreenView,
View.TRANSLATION_Y,
0f,
-splashScreenView.height.toFloat(),
)
slideUp.interpolator = AnticipateInterpolator()
slideUp.duration = 200L

slideUp.doOnEnd { splashScreenView.remove() }

slideUp.start()
}
}
}

private fun handleUiEvent() {
lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
Expand Down Expand Up @@ -100,7 +126,7 @@ class MainActivity : ComponentActivity() {

private fun checkUnsavedPushTokenExistence() {
lifecycleScope.launch {
if (!getUserAuthUseCase.getUserAuth().first()?.accessToken.isNullOrBlank()) {
if (!getMyUserInfoUseCase().first()?.accessToken.isNullOrBlank()) {
val isPushTokenSaved = getPushTokenSavedStateUseCase.invoke()
if (!isPushTokenSaved) {
FcmUtil.getToken()?.let {
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/com/keyme/app/MyFcmService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.google.firebase.messaging.FirebaseMessagingService
import com.google.firebase.messaging.RemoteMessage
import com.keyme.domain.entity.onFailure
import com.keyme.domain.entity.onSuccess
import com.keyme.domain.usecase.GetUserAuthUseCase
import com.keyme.domain.usecase.GetMyUserInfoUseCase
import com.keyme.domain.usecase.InsertPushTokenUseCase
import com.keyme.domain.usecase.SetPushTokenSavedStateUseCase
import dagger.hilt.android.AndroidEntryPoint
Expand All @@ -19,7 +19,7 @@ import javax.inject.Inject
class MyFcmService : FirebaseMessagingService() {

@Inject
lateinit var getUserAuthUseCase: GetUserAuthUseCase
lateinit var getMyUserInfoUseCase: GetMyUserInfoUseCase

@Inject
lateinit var insertPushTokenUseCase: InsertPushTokenUseCase
Expand All @@ -37,7 +37,7 @@ class MyFcmService : FirebaseMessagingService() {
super.onNewToken(token)
Timber.d("newToken: $token")
CoroutineScope(insertPushTokenJob).launch {
if (!getUserAuthUseCase.getUserAuth().first()?.accessToken.isNullOrBlank()) {
if (!getMyUserInfoUseCase().first()?.accessToken.isNullOrBlank()) {
insertPushTokenUseCase.invoke(token)
.onSuccess {
setPushTokenSavedStateUseCase.invoke(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ val keymeTopLevelDestinations = listOf(
TopLevelDestination(
route = DailyKeymeTestDestination.route,
destination = DailyKeymeTestDestination.destination,
selectedIconResId = com.keyme.presentation.R.drawable.icon_tab_feed,
unselectedIconResId = com.keyme.presentation.R.drawable.icon_tab_feed_unselected,
selectedIconResId = com.keyme.presentation.R.drawable.icon_tab_home,
unselectedIconResId = com.keyme.presentation.R.drawable.icon_tab_home_unselected,
),
TopLevelDestination(
route = MyProfileDestination.route,
Expand Down
29 changes: 18 additions & 11 deletions app/src/main/java/com/keyme/app/ui/KeymeApp.kt
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
package com.keyme.app.ui

import androidx.compose.foundation.border
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Icon
import androidx.compose.material3.NavigationBar
import androidx.compose.material3.NavigationBarItem
import androidx.compose.material3.NavigationBarItemDefaults
import androidx.compose.material3.Scaffold
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import androidx.navigation.NavDestination
import androidx.navigation.NavDestination.Companion.hierarchy
import androidx.navigation.compose.NavHost
import com.keyme.app.navigation.TopLevelDestination
import com.keyme.app.navigation.keymeTopLevelDestinations
import com.keyme.presentation.dailykeymetest.DailyKeymeTestDestination
import com.keyme.presentation.dailykeymetest.dailyKeymeTestGraph
import com.keyme.presentation.designsystem.theme.KeymeTheme
import com.keyme.presentation.myprofile.ui.KeymeQuestionResultDestination
import com.keyme.presentation.myprofile.ui.keymeQuestionResultGraph
import com.keyme.presentation.myprofile.ui.myProfileGraph
import com.keyme.presentation.onboarding.OnboardingDestination
import com.keyme.presentation.onboarding.onboardingGraph
import com.keyme.presentation.takekeymetest.TakeKeymeTestDestination
import com.keyme.presentation.takekeymetest.takeKeymeTestGraph
Expand Down Expand Up @@ -49,20 +51,21 @@ fun KeymeApp() {
) {
onboardingGraph(
navigateToOnboardingKeymeTest = { appState.navigate(TakeKeymeTestDestination, it) },
navigateToMyDaily = {
appState.onBackClick()
appState.navigate(DailyKeymeTestDestination)
navigateToMain = {
// todo μ½”λ“œ 정리 ν•„μš”
appState.startDestination = keymeTopLevelDestinations[0]
navigateToMain(appState)
},
nestedGraphs = {
takeKeymeTestGraph(
onBackClick = appState::onBackClick,
onTestSolved = {
appState.onBackClick()
appState.navigate(DailyKeymeTestDestination)
navigateToMain(appState)
},
)
},
)

dailyKeymeTestGraph(
navigateToTakeKeymeTest = { appState.navigate(TakeKeymeTestDestination, it) },
nestedGraphs = {
Expand All @@ -72,7 +75,6 @@ fun KeymeApp() {
)
},
)
// takeKeymeTestGraph -> 문제 풀이, κ²°κ³Ό 확인

myProfileGraph(
navigateToQuestionResult = { question ->
Expand All @@ -90,16 +92,20 @@ fun KeymeApp() {
}
}

private fun NavDestination?.isOnBoarding(): Boolean {
return this?.hierarchy?.any { it.route == OnboardingDestination.route } == true
private fun navigateToMain(appState: KeymeAppState) {
appState.navigate(keymeTopLevelDestinations[0])
}

@Composable
fun KeymeBottomBar(
currentDestination: NavDestination?,
onNavigateToDestination: (TopLevelDestination) -> Unit,
) {
NavigationBar {
NavigationBar(
modifier = Modifier.border(width = 1.dp, color = Color(0xFF363636)),
containerColor = Color(0x80232323),
tonalElevation = 4.dp,
) {
keymeTopLevelDestinations.forEach { destination ->
val isSelected = currentDestination?.hierarchy?.any { it.route == destination.route } == true

Expand All @@ -113,6 +119,7 @@ fun KeymeBottomBar(
if (isSelected) destination.selectedIconResId else destination.unselectedIconResId
Icon(painter = painterResource(id = iconResId), contentDescription = "")
},
colors = NavigationBarItemDefaults.colors(indicatorColor = Color.Transparent),
)
}
}
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/com/keyme/app/ui/KeymeAppState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.keyme.app.ui
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Stable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
Expand Down Expand Up @@ -39,7 +40,7 @@ class KeymeAppState(
val currentDestination: NavDestination?
@Composable get() = navController.currentBackStackEntryAsState().value?.destination

val startDestination = OnboardingDestination
var startDestination by mutableStateOf<KeymeNavigationDestination>(OnboardingDestination)

val showBottomBar: Boolean
@Composable get() = currentDestination?.route.showBottomBar()
Expand Down
30 changes: 0 additions & 30 deletions app/src/main/res/drawable-v24/ic_launcher_foreground.xml

This file was deleted.

74 changes: 0 additions & 74 deletions app/src/main/res/drawable/ic_launcher_background.xml

This file was deleted.

5 changes: 4 additions & 1 deletion app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@
<color name="teal_700">#FF018786</color>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
</resources>


<color name="keyme_black">#FF171717</color>
</resources>
7 changes: 5 additions & 2 deletions app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<resources xmlns:tools="http://schemas.android.com/tools">

<style name="Theme.Keymeandroid" parent="android:Theme.Material.Light.NoActionBar" />
<style name="Theme.Keymeandroid" parent="android:Theme.Material.Light.NoActionBar" >
<item name="android:windowSplashScreenBackground" tools:targetApi="s">@color/keyme_black</item>
<item name="android:windowSplashScreenAnimatedIcon" tools:targetApi="s">@mipmap/ic_launcher_round</item>
</style>
</resources>
7 changes: 7 additions & 0 deletions buildSrc/src/main/java/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ object Dependencies {
private val roomCompiler = "androidx.room:room-compiler:${Versions.ROOM}"
private val roomTesting = "androidx.room:room-testing:${Versions.ROOM}"

// DataStore
private val datastore = "androidx.datastore:datastore-preferences:${Versions.DATASTORE}"

// Dependency injection
private val hilt = "com.google.dagger:hilt-android:${Versions.HILT}"
private val hiltCompose = "androidx.hilt:hilt-navigation-compose:1.0.0"
Expand Down Expand Up @@ -168,6 +171,10 @@ object Dependencies {
testImplementation(roomTesting)
}

fun DependencyHandler.setDataStoreDependencies() {
implementation(datastore)
}

fun DependencyHandler.setHiltDependencies() {
kapt(hiltCompiler)
implementation(hilt)
Expand Down
3 changes: 3 additions & 0 deletions buildSrc/src/main/java/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ object Versions {
// Database
const val ROOM = "2.4.2"

// DataStore
const val DATASTORE = "1.0.0"

// Dependency injection
const val HILT = "2.44"
const val JAVA_X_INJECT = "1"
Expand Down
Loading

0 comments on commit a6803f9

Please sign in to comment.