Skip to content

Commit 813d605

Browse files
committed
refactor: Splash 모듈에서 SplashScreen 을 관리합니다
1 parent e892a9d commit 813d605

15 files changed

Lines changed: 225 additions & 105 deletions

File tree

.idea/gradle.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,14 @@ dependencies {
5151
implementation(projects.feature.free)
5252
implementation(projects.feature.myprofile)
5353
implementation(projects.feature.wiki)
54+
implementation(projects.feature.splash)
5455
implementation(projects.feature.myposts)
5556
implementation(projects.feature.settings)
5657
implementation(projects.core.designsystem)
5758
implementation(projects.domain.model)
59+
implementation(projects.domain.repository)
5860

5961
implementation(libs.hilt.android)
60-
implementation(project(":domain:repository"))
6162
ksp(libs.hilt.android.compiler)
6263

6364
implementation(libs.androidx.core.ktx)

core/navigation/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ dependencies {
3434
implementation(libs.hilt.android)
3535
implementation(project(":domain:repository"))
3636
implementation(project(":domain:repository"))
37+
implementation(project(":feature:splash"))
3738
ksp(libs.hilt.android.compiler)
3839

3940
implementation(libs.androidx.navigation.compose)

core/navigation/src/main/java/com/lanpet/core/navigation/AppNavigation.kt

Lines changed: 2 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,9 @@ import androidx.compose.animation.core.FastOutSlowInEasing
55
import androidx.compose.animation.core.tween
66
import androidx.compose.animation.fadeIn
77
import androidx.compose.animation.fadeOut
8-
import androidx.compose.foundation.background
9-
import androidx.compose.foundation.layout.Arrangement
108
import androidx.compose.foundation.layout.Box
119
import androidx.compose.foundation.layout.Column
1210
import androidx.compose.foundation.layout.fillMaxSize
13-
import androidx.compose.material3.MaterialTheme
14-
import androidx.compose.material3.Text
1511
import androidx.compose.runtime.Composable
1612
import androidx.compose.runtime.LaunchedEffect
1713
import androidx.compose.runtime.collectAsState
@@ -23,31 +19,17 @@ import androidx.compose.runtime.setValue
2319
import androidx.compose.runtime.snapshotFlow
2420
import androidx.compose.ui.Alignment
2521
import androidx.compose.ui.Modifier
26-
import androidx.compose.ui.unit.sp
27-
import androidx.hilt.navigation.compose.hiltViewModel
28-
import androidx.lifecycle.ViewModel
29-
import androidx.lifecycle.compose.collectAsStateWithLifecycle
30-
import androidx.navigation.NavController
3122
import androidx.navigation.compose.NavHost
3223
import androidx.navigation.compose.composable
3324
import androidx.navigation.compose.currentBackStackEntryAsState
3425
import androidx.navigation.compose.navigation
3526
import androidx.navigation.compose.rememberNavController
3627
import androidx.navigation.navOptions
37-
import com.lanpet.core.auth.AuthManager
3828
import com.lanpet.core.auth.LocalAuthManager
3929
import com.lanpet.core.common.widget.BottomNavItem
4030
import com.lanpet.core.common.widget.LanPetBottomNavBar
41-
import com.lanpet.core.designsystem.theme.VioletColor
42-
import com.lanpet.core.designsystem.theme.WhiteColor
43-
import com.lanpet.core.designsystem.theme.customTypography
44-
import com.lanpet.domain.model.SocialAuthToken
45-
import com.lanpet.domain.repository.AuthRepository
46-
import com.lanpet.domain.repository.LandingRepository
47-
import com.lanpet.feature.auth.navigation.Login
4831
import com.lanpet.feature.auth.navigation.authNavGraph
4932
import com.lanpet.feature.auth.navigation.navigateToLoginScreen
50-
import com.lanpet.feature.landing.navigation.Landing
5133
import com.lanpet.feature.landing.navigation.landingNavGraph
5234
import com.lanpet.feature.myposts.navigation.myPostsNavGraph
5335
import com.lanpet.feature.myposts.navigation.navigateToMyPosts
@@ -56,6 +38,8 @@ import com.lanpet.feature.settings.navigation.navigateToMemberLeave
5638
import com.lanpet.feature.settings.navigation.navigateToMemberLeaveComplete
5739
import com.lanpet.feature.settings.navigation.navigateToSettings
5840
import com.lanpet.feature.settings.navigation.settingsNavGraph
41+
import com.lanpet.feature.splash.SplashScreen
42+
import com.lanpet.feature.splash.navigation.Splash
5943
import com.lanpet.free.navigation.FreeBoard
6044
import com.lanpet.free.navigation.freeNavGraph
6145
import com.lanpet.free.navigation.navigateToFreeBoardBaseRoute
@@ -86,15 +70,9 @@ import com.lanpet.profile.navigation.profileNavGraph
8670
import com.lanpet.wiki.navigation.Wiki
8771
import com.lanpet.wiki.navigation.navigateToWikiBaseRoute
8872
import com.lanpet.wiki.navigation.wikiNavGraph
89-
import dagger.hilt.android.lifecycle.HiltViewModel
90-
import kotlinx.coroutines.delay
91-
import kotlinx.coroutines.flow.MutableStateFlow
9273
import kotlinx.coroutines.flow.distinctUntilChanged
9374
import kotlinx.coroutines.flow.drop
94-
import kotlinx.coroutines.runBlocking
95-
import kotlinx.serialization.Serializable
9675
import timber.log.Timber
97-
import javax.inject.Inject
9876

9977
@Composable
10078
fun AppNavigation(modifier: Modifier = Modifier) {
@@ -348,83 +326,3 @@ fun AppNavigation(modifier: Modifier = Modifier) {
348326
}
349327
}
350328
}
351-
352-
@Serializable
353-
data object Splash
354-
355-
@Composable
356-
fun SplashScreen(
357-
navController: NavController,
358-
modifier: Modifier = Modifier,
359-
splashViewModel: SplashViewModel = hiltViewModel(),
360-
) {
361-
val startDestination by splashViewModel.startDestination.collectAsStateWithLifecycle()
362-
363-
LaunchedEffect(Unit) {
364-
if (startDestination != null) {
365-
startDestination?.let {
366-
Timber.d("startDestination: $it")
367-
navController.navigate(it)
368-
}
369-
}
370-
}
371-
372-
Column(
373-
modifier =
374-
modifier.then(Modifier).fillMaxSize().background(
375-
color = VioletColor.Violet500,
376-
),
377-
horizontalAlignment = Alignment.CenterHorizontally,
378-
verticalArrangement = Arrangement.Center,
379-
) {
380-
Text(
381-
"랜펫",
382-
style =
383-
MaterialTheme.customTypography().title2SemiBoldMulti.copy(
384-
color = WhiteColor.White,
385-
fontSize = 64.sp,
386-
),
387-
)
388-
}
389-
}
390-
391-
@HiltViewModel
392-
class SplashViewModel
393-
@Inject
394-
constructor(
395-
private val landingRepository: LandingRepository,
396-
private val authRepository: AuthRepository,
397-
private val authManager: AuthManager,
398-
) : ViewModel() {
399-
val startDestination: MutableStateFlow<Any?> = MutableStateFlow(null)
400-
401-
init {
402-
runBlocking {
403-
delay(3_000L)
404-
405-
if (landingRepository.getShouldShowLanding()) {
406-
startDestination.value = Landing
407-
return@runBlocking
408-
}
409-
410-
val token = authRepository.getAuthTokenFromDataStore()
411-
412-
Timber.i("token: $token")
413-
414-
if (token != null) {
415-
authManager.handleAuthentication(
416-
SocialAuthToken(
417-
socialAuthType = token.socialAuthType,
418-
accessToken = token.accessToken,
419-
refreshToken = token.refreshToken,
420-
expiresIn = token.expiresIn,
421-
expireDateTime = token.expireDateTime,
422-
),
423-
)
424-
return@runBlocking
425-
}
426-
427-
startDestination.value = Login
428-
}
429-
}
430-
}

feature/splash/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

feature/splash/build.gradle.kts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
plugins {
2+
alias(libs.plugins.android.library)
3+
alias(libs.plugins.kotlin.android)
4+
alias(libs.plugins.kotlin.compose)
5+
alias(libs.plugins.convention.feature)
6+
alias(libs.plugins.convention.ui.compose)
7+
alias(libs.plugins.convention.lib.build)
8+
alias(libs.plugins.convention.lib.coil)
9+
alias(libs.plugins.convention.lib.junit5)
10+
}
11+
12+
android {
13+
namespace = "com.lanpet.feature.splash"
14+
15+
buildFeatures {
16+
compose = true
17+
}
18+
}
19+
20+
dependencies {
21+
implementation(libs.androidx.core.ktx)
22+
implementation(libs.androidx.appcompat)
23+
implementation(libs.material)
24+
implementation(projects.domain.model)
25+
implementation(projects.domain.repository)
26+
implementation(projects.core.auth)
27+
implementation(projects.feature.auth)
28+
implementation(projects.feature.landing)
29+
testImplementation(libs.junit)
30+
androidTestImplementation(libs.androidx.junit)
31+
androidTestImplementation(libs.androidx.espresso.core)
32+
}

feature/splash/consumer-rules.pro

Whitespace-only changes.

feature/splash/proguard-rules.pro

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.lanpet.feature.splash
2+
3+
import androidx.test.platform.app.InstrumentationRegistry
4+
import androidx.test.ext.junit.runners.AndroidJUnit4
5+
6+
import org.junit.Test
7+
import org.junit.runner.RunWith
8+
9+
import org.junit.Assert.*
10+
11+
/**
12+
* Instrumented test, which will execute on an Android device.
13+
*
14+
* See [testing documentation](http://d.android.com/tools/testing).
15+
*/
16+
@RunWith(AndroidJUnit4::class)
17+
class ExampleInstrumentedTest {
18+
@Test
19+
fun useAppContext() {
20+
// Context of the app under test.
21+
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22+
assertEquals("com.lanpet.feature.splash.test", appContext.packageName)
23+
}
24+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
3+
4+
</manifest>

0 commit comments

Comments
 (0)