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

#29: AuthActivity를 만들어 회원가입을 진행해요 #34

Merged
merged 6 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
9 changes: 7 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET" />

<application
android:name=".application.WeSpotApplication"
android:allowBackup="true"
Expand All @@ -14,8 +13,9 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.WeSpot">

<activity
android:name=".MainActivity"
android:name=".auth.AuthActivity"
android:exported="true"
android:label="@string/app_name"
android:theme="@style/Theme.WeSpot"
Expand All @@ -27,6 +27,11 @@
</intent-filter>
</activity>

<activity
android:name=".MainActivity"
android:exported="false" />


<activity
android:name="com.kakao.sdk.auth.AuthCodeHandlerActivity"
android:launchMode="singleTask"
Expand Down
29 changes: 0 additions & 29 deletions app/src/main/kotlin/com/bff/wespot/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +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 {
val navController = rememberNavController()
val engine = rememberNavHostEngine()
val viewModel: AuthViewModel = viewModel()

WeSpotTheme {
Surface(
modifier = Modifier.fillMaxSize(),
) {
DestinationsNavHost(
navGraph = NavGraphs.root,
navController = navController,
engine = engine,
dependenciesContainerBuilder = {
dependency(viewModel)
},
)
}
}
}
}
}
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.navigation.Navigator
import com.danggeun.navigation.util.buildIntent

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
}
Comment on lines +11 to +17
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오호~ 이거 동작하는거죠 ?

제가 알기로 abstract class만 @BINDS 지원해주는 줄 알았는데, interface도 가능하군요

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

binds는 interface 아니면 abstract class에 동작해요

1 change: 1 addition & 0 deletions core/navigation/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
9 changes: 9 additions & 0 deletions core/navigation/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
plugins {
alias(libs.plugins.wespot.android.library)
alias(libs.plugins.wespot.android.hilt)
}


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
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,12 @@
package com.danggeun.navigation.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))
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.bff.wespot.domain.repository.usecase
package com.bff.wespot.domain.usecase

import com.bff.wespot.domain.repository.auth.KakaoLoginManager
import javax.inject.Inject
Expand Down
87 changes: 87 additions & 0 deletions feature/auth/src/main/kotlin/com/bff/wespot/auth/AuthActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package com.bff.wespot.auth

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.screen.destinations.ClassScreenDestination
import com.bff.wespot.auth.screen.destinations.CompleteScreenDestination
import com.bff.wespot.auth.screen.destinations.EditScreenDestination
import com.bff.wespot.auth.screen.destinations.GenderScreenDestination
import com.bff.wespot.auth.screen.destinations.GradeScreenDestination
import com.bff.wespot.auth.screen.destinations.NameScreenDestination
import com.bff.wespot.auth.screen.destinations.SchoolScreenDestination
import com.bff.wespot.auth.state.AuthSideEffect
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.navigation.navigate
import com.ramcosta.composedestinations.rememberNavHostEngine
import org.orbitmvi.orbit.compose.collectSideEffect

class AuthActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
val navController = rememberNavController()
val engine = rememberNavHostEngine()
val viewModel: AuthViewModel = viewModel()

viewModel.collectSideEffect {
when (it) {
AuthSideEffect.PopBackStack -> navController.popBackStack()
is AuthSideEffect.NavigateToGradeScreen -> {
navController.navigate(GradeScreenDestination(it.edit))
}

is AuthSideEffect.NavigateToSchoolScreen -> {
navController.navigate(SchoolScreenDestination(it.edit))
}

is AuthSideEffect.NavigateToClassScreen -> {
navController.navigate(ClassScreenDestination(it.edit))
}

is AuthSideEffect.NavigateToGenderScreen -> {
navController.navigate(GenderScreenDestination(it.edit))
}

is AuthSideEffect.NavigateToNameScreen -> {
navController.navigate(NameScreenDestination(it.edit))
}

AuthSideEffect.NavigateToEditScreen -> {
navController.navigate(EditScreenDestination)
}

AuthSideEffect.NavigateToCompleteScreen -> {
navController.navigate(CompleteScreenDestination, navOptionsBuilder = {
popUpTo(SchoolScreenDestination.route) { inclusive = true }
})
flash159483 marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

WeSpotTheme {
Surface(
modifier = Modifier.fillMaxSize(),
) {
DestinationsNavHost(
navGraph = NavGraphs.root,
navController = navController,
engine = engine,
dependenciesContainerBuilder = {
dependency(viewModel)
},
)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,15 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.unit.dp
import com.bff.wespot.auth.R
import com.bff.wespot.auth.screen.destinations.GenderScreenDestination
import com.bff.wespot.auth.state.AuthAction
import com.bff.wespot.auth.state.NavigationAction
import com.bff.wespot.auth.viewmodel.AuthViewModel
import com.bff.wespot.designsystem.component.button.WSButton
import com.bff.wespot.designsystem.component.header.WSTopBar
import com.bff.wespot.designsystem.component.input.WsTextField
import com.bff.wespot.designsystem.theme.StaticTypeScale
import com.bff.wespot.designsystem.theme.WeSpotThemeManager
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
import kotlinx.coroutines.delay
import org.orbitmvi.orbit.compose.collectAsState

Expand All @@ -42,7 +41,6 @@ import org.orbitmvi.orbit.compose.collectAsState
fun ClassScreen(
viewModel: AuthViewModel,
edit: Boolean,
navigator: DestinationsNavigator,
) {
val keyboard = LocalSoftwareKeyboardController.current

Expand All @@ -56,7 +54,7 @@ fun ClassScreen(
title = stringResource(id = R.string.register),
canNavigateBack = true,
navigateUp = {
navigator.navigateUp()
action(AuthAction.Navigation(NavigationAction.PopBackStack))
},
)
},
Expand Down Expand Up @@ -120,10 +118,10 @@ fun ClassScreen(
WSButton(
onClick = {
if (edit) {
navigator.popBackStack()
action(AuthAction.Navigation(NavigationAction.PopBackStack))
return@WSButton
}
navigator.navigate(GenderScreenDestination(edit = false))
action(AuthAction.Navigation(NavigationAction.NavigateToGenderScreen(false)))
},
text = stringResource(
id = if (edit) {
Expand Down
Loading
Loading