From 0e1acfeccd8e656c08fc0dc35bfd9d0e43e8e69b Mon Sep 17 00:00:00 2001 From: flash159483 Date: Mon, 15 Jul 2024 21:46:12 +0900 Subject: [PATCH] =?UTF-8?q?[CHORE]#29:=20Navigation=20logic=EC=9D=84=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle.kts | 1 + .../kotlin/com/bff/wespot/MainActivity.kt | 12 ------- .../kotlin/com/bff/wespot/NavigatorImpl.kt | 16 +++++++++ .../com/bff/wespot/di/NavigationModule.kt | 17 +++++++++ .../com/danggeun/common/util/Extension.kt | 12 +++++++ core/navigation/.gitignore | 1 + core/navigation/build.gradle.kts | 8 +++++ core/navigation/consumer-rules.pro | 0 core/navigation/proguard-rules.pro | 21 +++++++++++ .../navigation/ExampleInstrumentedTest.kt | 24 +++++++++++++ core/navigation/src/main/AndroidManifest.xml | 4 +++ .../java/com/danggeun/navigation/Navigator.kt | 10 ++++++ .../danggeun/navigation/ExampleUnitTest.kt | 17 +++++++++ .../com/bff/wespot/auth/AuthActivity.kt | 3 +- .../com/bff/wespot/auth/screen/NameScreen.kt | 36 +++++++++++-------- .../com/bff/wespot/auth/state/AuthAction.kt | 3 +- .../bff/wespot/auth/state/AuthSideEffect.kt | 2 +- .../wespot/auth/viewmodel/AuthViewModel.kt | 10 +++--- settings.gradle.kts | 1 + 19 files changed, 162 insertions(+), 36 deletions(-) create mode 100644 app/src/main/kotlin/com/bff/wespot/NavigatorImpl.kt create mode 100644 app/src/main/kotlin/com/bff/wespot/di/NavigationModule.kt create mode 100644 core/common/src/main/kotlin/com/danggeun/common/util/Extension.kt create mode 100644 core/navigation/.gitignore create mode 100644 core/navigation/build.gradle.kts create mode 100644 core/navigation/consumer-rules.pro create mode 100644 core/navigation/proguard-rules.pro create mode 100644 core/navigation/src/androidTest/java/com/danggeun/navigation/ExampleInstrumentedTest.kt create mode 100644 core/navigation/src/main/AndroidManifest.xml create mode 100644 core/navigation/src/main/java/com/danggeun/navigation/Navigator.kt create mode 100644 core/navigation/src/test/java/com/danggeun/navigation/ExampleUnitTest.kt diff --git a/app/build.gradle.kts b/app/build.gradle.kts index d7f8de38..f7b16cf5 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -33,6 +33,7 @@ dependencies { implementation(project(":core:ui")) implementation(project(":core:common")) implementation(project(":feature:auth")) + implementation(project(":core:navigation")) implementation(libs.kakao.sdk) implementation(libs.androidx.appcompat) diff --git a/app/src/main/kotlin/com/bff/wespot/MainActivity.kt b/app/src/main/kotlin/com/bff/wespot/MainActivity.kt index 066592fc..fcfb4563 100644 --- a/app/src/main/kotlin/com/bff/wespot/MainActivity.kt +++ b/app/src/main/kotlin/com/bff/wespot/MainActivity.kt @@ -3,24 +3,12 @@ package com.bff.wespot import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent -import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.material3.Surface -import androidx.compose.ui.Modifier -import androidx.lifecycle.viewmodel.compose.viewModel -import androidx.navigation.compose.rememberNavController -import com.bff.wespot.auth.screen.NavGraphs -import com.bff.wespot.auth.viewmodel.AuthViewModel -import com.bff.wespot.designsystem.theme.WeSpotTheme -import com.ramcosta.composedestinations.DestinationsNavHost -import com.ramcosta.composedestinations.navigation.dependency -import com.ramcosta.composedestinations.rememberNavHostEngine class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { - } } } diff --git a/app/src/main/kotlin/com/bff/wespot/NavigatorImpl.kt b/app/src/main/kotlin/com/bff/wespot/NavigatorImpl.kt new file mode 100644 index 00000000..de4d9bb3 --- /dev/null +++ b/app/src/main/kotlin/com/bff/wespot/NavigatorImpl.kt @@ -0,0 +1,16 @@ +package com.bff.wespot + +import android.content.Context +import android.content.Intent +import com.danggeun.common.util.buildIntent +import com.danggeun.navigation.Navigator + +class NavigatorImpl : Navigator { + override fun navigateToMain( + context: Context, + ): Intent { + val intent = context.buildIntent() + intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK + return intent + } +} diff --git a/app/src/main/kotlin/com/bff/wespot/di/NavigationModule.kt b/app/src/main/kotlin/com/bff/wespot/di/NavigationModule.kt new file mode 100644 index 00000000..f0013814 --- /dev/null +++ b/app/src/main/kotlin/com/bff/wespot/di/NavigationModule.kt @@ -0,0 +1,17 @@ +package com.bff.wespot.di + +import com.bff.wespot.NavigatorImpl +import com.danggeun.navigation.Navigator +import dagger.Binds +import dagger.Module +import dagger.hilt.InstallIn +import dagger.hilt.components.SingletonComponent +import javax.inject.Singleton + +@Module +@InstallIn(SingletonComponent::class) +interface NavigationModule { + @Binds + @Singleton + fun provideNavigator(navigator: NavigatorImpl): Navigator +} diff --git a/core/common/src/main/kotlin/com/danggeun/common/util/Extension.kt b/core/common/src/main/kotlin/com/danggeun/common/util/Extension.kt new file mode 100644 index 00000000..8874cc72 --- /dev/null +++ b/core/common/src/main/kotlin/com/danggeun/common/util/Extension.kt @@ -0,0 +1,12 @@ +package com.danggeun.common.util + +import android.app.Activity +import android.content.Context +import android.content.Intent +import androidx.core.os.bundleOf + +inline fun Context.buildIntent( + vararg argument: Pair, +) = Intent(this, T::class.java).apply { + putExtras(bundleOf(*argument)) +} \ No newline at end of file diff --git a/core/navigation/.gitignore b/core/navigation/.gitignore new file mode 100644 index 00000000..42afabfd --- /dev/null +++ b/core/navigation/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/core/navigation/build.gradle.kts b/core/navigation/build.gradle.kts new file mode 100644 index 00000000..22de8bd8 --- /dev/null +++ b/core/navigation/build.gradle.kts @@ -0,0 +1,8 @@ +plugins { + alias(libs.plugins.wespot.android.library) +} + + +android { + namespace = "com.bff.wespot.navigation" +} diff --git a/core/navigation/consumer-rules.pro b/core/navigation/consumer-rules.pro new file mode 100644 index 00000000..e69de29b diff --git a/core/navigation/proguard-rules.pro b/core/navigation/proguard-rules.pro new file mode 100644 index 00000000..481bb434 --- /dev/null +++ b/core/navigation/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/core/navigation/src/androidTest/java/com/danggeun/navigation/ExampleInstrumentedTest.kt b/core/navigation/src/androidTest/java/com/danggeun/navigation/ExampleInstrumentedTest.kt new file mode 100644 index 00000000..dcd2d135 --- /dev/null +++ b/core/navigation/src/androidTest/java/com/danggeun/navigation/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package com.danggeun.navigation + +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.ext.junit.runners.AndroidJUnit4 + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("com.danggeun.navigation.test", appContext.packageName) + } +} \ No newline at end of file diff --git a/core/navigation/src/main/AndroidManifest.xml b/core/navigation/src/main/AndroidManifest.xml new file mode 100644 index 00000000..a5918e68 --- /dev/null +++ b/core/navigation/src/main/AndroidManifest.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/core/navigation/src/main/java/com/danggeun/navigation/Navigator.kt b/core/navigation/src/main/java/com/danggeun/navigation/Navigator.kt new file mode 100644 index 00000000..21754b04 --- /dev/null +++ b/core/navigation/src/main/java/com/danggeun/navigation/Navigator.kt @@ -0,0 +1,10 @@ +package com.danggeun.navigation + +import android.content.Context +import android.content.Intent + +interface Navigator { + fun navigateToMain( + context: Context + ) : Intent +} \ No newline at end of file diff --git a/core/navigation/src/test/java/com/danggeun/navigation/ExampleUnitTest.kt b/core/navigation/src/test/java/com/danggeun/navigation/ExampleUnitTest.kt new file mode 100644 index 00000000..4958aff8 --- /dev/null +++ b/core/navigation/src/test/java/com/danggeun/navigation/ExampleUnitTest.kt @@ -0,0 +1,17 @@ +package com.danggeun.navigation + +import org.junit.Test + +import org.junit.Assert.* + +/** + * Example local unit test, which will execute on the development machine (host). + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +class ExampleUnitTest { + @Test + fun addition_isCorrect() { + assertEquals(4, 2 + 2) + } +} \ No newline at end of file diff --git a/feature/auth/src/main/kotlin/com/bff/wespot/auth/AuthActivity.kt b/feature/auth/src/main/kotlin/com/bff/wespot/auth/AuthActivity.kt index 4bfc136e..960b0f8e 100644 --- a/feature/auth/src/main/kotlin/com/bff/wespot/auth/AuthActivity.kt +++ b/feature/auth/src/main/kotlin/com/bff/wespot/auth/AuthActivity.kt @@ -68,7 +68,6 @@ class AuthActivity : ComponentActivity() { } } - WeSpotTheme { Surface( modifier = Modifier.fillMaxSize(), @@ -85,4 +84,4 @@ class AuthActivity : ComponentActivity() { } } } -} \ No newline at end of file +} diff --git a/feature/auth/src/main/kotlin/com/bff/wespot/auth/screen/NameScreen.kt b/feature/auth/src/main/kotlin/com/bff/wespot/auth/screen/NameScreen.kt index bbbcbe4d..755704d7 100644 --- a/feature/auth/src/main/kotlin/com/bff/wespot/auth/screen/NameScreen.kt +++ b/feature/auth/src/main/kotlin/com/bff/wespot/auth/screen/NameScreen.kt @@ -3,6 +3,7 @@ package com.bff.wespot.auth.screen import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding @@ -67,7 +68,9 @@ fun NameScreen( }, ) { Column( - modifier = Modifier.padding(it).padding(horizontal = 20.dp), + modifier = Modifier + .padding(it) + .padding(horizontal = 20.dp), verticalArrangement = Arrangement.spacedBy(12.dp), ) { Text( @@ -95,20 +98,25 @@ fun NameScreen( focusRequester = focusRequester, ) - if (error) { - Text( - text = stringResource(id = R.string.name_error), - color = WeSpotThemeManager.colors.dangerColor, - style = StaticTypeScale.Default.body6, - ) - } + Row( + modifier = Modifier.fillMaxWidth(), + horizontalArrangement = Arrangement.SpaceBetween, + ) { + if (error) { + Text( + text = stringResource(id = R.string.name_error), + color = WeSpotThemeManager.colors.dangerColor, + style = StaticTypeScale.Default.body6, + ) + } - Box(modifier = Modifier.fillMaxWidth(), contentAlignment = Alignment.TopEnd) { - Text( - text = "${state.name.length} / 5", - color = Color(0xFF7A7A7A), - style = StaticTypeScale.Default.body7, - ) + Box(modifier = Modifier.fillMaxWidth(), contentAlignment = Alignment.TopEnd) { + Text( + text = "${state.name.length} / 5", + color = Color(0xFF7A7A7A), + style = StaticTypeScale.Default.body7, + ) + } } } } diff --git a/feature/auth/src/main/kotlin/com/bff/wespot/auth/state/AuthAction.kt b/feature/auth/src/main/kotlin/com/bff/wespot/auth/state/AuthAction.kt index 9ab656e9..6ff5d05b 100644 --- a/feature/auth/src/main/kotlin/com/bff/wespot/auth/state/AuthAction.kt +++ b/feature/auth/src/main/kotlin/com/bff/wespot/auth/state/AuthAction.kt @@ -18,7 +18,6 @@ sealed class AuthAction { data class OnNameChanged(val name: String) : AuthAction() data class Navigation(val navigate: NavigationAction) : AuthAction() - } sealed interface NavigationAction { @@ -30,4 +29,4 @@ sealed interface NavigationAction { data class NavigateToNameScreen(val edit: Boolean) : NavigationAction data object NavigateToEditScreen : NavigationAction data object NavigateToCompleteScreen : NavigationAction -} \ No newline at end of file +} diff --git a/feature/auth/src/main/kotlin/com/bff/wespot/auth/state/AuthSideEffect.kt b/feature/auth/src/main/kotlin/com/bff/wespot/auth/state/AuthSideEffect.kt index f5792fbc..1b681121 100644 --- a/feature/auth/src/main/kotlin/com/bff/wespot/auth/state/AuthSideEffect.kt +++ b/feature/auth/src/main/kotlin/com/bff/wespot/auth/state/AuthSideEffect.kt @@ -9,4 +9,4 @@ sealed class AuthSideEffect { data class NavigateToNameScreen(val edit: Boolean) : AuthSideEffect() data object NavigateToEditScreen : AuthSideEffect() data object NavigateToCompleteScreen : AuthSideEffect() -} \ No newline at end of file +} diff --git a/feature/auth/src/main/kotlin/com/bff/wespot/auth/viewmodel/AuthViewModel.kt b/feature/auth/src/main/kotlin/com/bff/wespot/auth/viewmodel/AuthViewModel.kt index b6add375..a3f7a052 100644 --- a/feature/auth/src/main/kotlin/com/bff/wespot/auth/viewmodel/AuthViewModel.kt +++ b/feature/auth/src/main/kotlin/com/bff/wespot/auth/viewmodel/AuthViewModel.kt @@ -109,19 +109,19 @@ class AuthViewModel @Inject constructor( val sideEffect = when (navigate) { NavigationAction.PopBackStack -> AuthSideEffect.PopBackStack is NavigationAction.NavigateToGradeScreen -> AuthSideEffect.NavigateToGradeScreen( - navigate.edit + navigate.edit, ) is NavigationAction.NavigateToSchoolScreen -> AuthSideEffect.NavigateToSchoolScreen( - navigate.edit + navigate.edit, ) is NavigationAction.NavigateToClassScreen -> AuthSideEffect.NavigateToClassScreen( - navigate.edit + navigate.edit, ) is NavigationAction.NavigateToGenderScreen -> AuthSideEffect.NavigateToGenderScreen( - navigate.edit + navigate.edit, ) is NavigationAction.NavigateToNameScreen -> AuthSideEffect.NavigateToNameScreen( - navigate.edit + navigate.edit, ) NavigationAction.NavigateToEditScreen -> AuthSideEffect.NavigateToEditScreen NavigationAction.NavigateToCompleteScreen -> AuthSideEffect.NavigateToCompleteScreen diff --git a/settings.gradle.kts b/settings.gradle.kts index e05d91ee..5eea5344 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -33,3 +33,4 @@ include(":core:model") include(":core:common") include(":core:ui") include(":core:network") +include(":core:navigation")