Skip to content

Commit

Permalink
[CHORE]#29: Navigation logic을 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
flash159483 committed Jul 16, 2024
1 parent 497f69c commit 0e1acfe
Show file tree
Hide file tree
Showing 19 changed files with 162 additions and 36 deletions.
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 0 additions & 12 deletions app/src/main/kotlin/com/bff/wespot/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

}
}
}
16 changes: 16 additions & 0 deletions app/src/main/kotlin/com/bff/wespot/NavigatorImpl.kt
Original file line number Diff line number Diff line change
@@ -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<MainActivity>()
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
return intent
}
}
17 changes: 17 additions & 0 deletions app/src/main/kotlin/com/bff/wespot/di/NavigationModule.kt
Original file line number Diff line number Diff line change
@@ -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
}
12 changes: 12 additions & 0 deletions core/common/src/main/kotlin/com/danggeun/common/util/Extension.kt
Original file line number Diff line number Diff line change
@@ -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 <reified T : Activity> Context.buildIntent(
vararg argument: Pair<String, Any?>,
) = Intent(this, T::class.java).apply {
putExtras(bundleOf(*argument))
}
1 change: 1 addition & 0 deletions core/navigation/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
8 changes: 8 additions & 0 deletions core/navigation/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
plugins {
alias(libs.plugins.wespot.android.library)
}


android {
namespace = "com.bff.wespot.navigation"
}
Empty file.
21 changes: 21 additions & 0 deletions core/navigation/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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)
}
}
4 changes: 4 additions & 0 deletions core/navigation/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
10 changes: 10 additions & 0 deletions core/navigation/src/main/java/com/danggeun/navigation/Navigator.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.danggeun.navigation

import android.content.Context
import android.content.Intent

interface Navigator {
fun navigateToMain(
context: Context
) : Intent
}
Original file line number Diff line number Diff line change
@@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ class AuthActivity : ComponentActivity() {
}
}


WeSpotTheme {
Surface(
modifier = Modifier.fillMaxSize(),
Expand All @@ -85,4 +84,4 @@ class AuthActivity : ComponentActivity() {
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ sealed class AuthAction {
data class OnNameChanged(val name: String) : AuthAction()

data class Navigation(val navigate: NavigationAction) : AuthAction()

}

sealed interface NavigationAction {
Expand All @@ -30,4 +29,4 @@ sealed interface NavigationAction {
data class NavigateToNameScreen(val edit: Boolean) : NavigationAction
data object NavigateToEditScreen : NavigationAction
data object NavigateToCompleteScreen : NavigationAction
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ sealed class AuthSideEffect {
data class NavigateToNameScreen(val edit: Boolean) : AuthSideEffect()
data object NavigateToEditScreen : AuthSideEffect()
data object NavigateToCompleteScreen : AuthSideEffect()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ include(":core:model")
include(":core:common")
include(":core:ui")
include(":core:network")
include(":core:navigation")

0 comments on commit 0e1acfe

Please sign in to comment.