Skip to content

Commit

Permalink
[feat]#7 유저등록 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
angryPodo committed Nov 15, 2024
1 parent 1e6859c commit 289ec59
Show file tree
Hide file tree
Showing 10 changed files with 369 additions and 289 deletions.
20 changes: 12 additions & 8 deletions app/src/main/java/org/sopt/and/Route.kt
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
package org.sopt.and

import kotlinx.serialization.Serializable


@Serializable
sealed class Route(val route: String) {
@Serializable
data object Home : Route("home")

data class SignIn(val email: String = "", val password: String = "") :
Route("signIn?email={email}&password={password}") {
fun createRoute(email: String = "", password: String = "") =
"signIn?email=$email&password=$password"
}
@Serializable
data object SignIn : Route("signIn")

@Serializable
data object SignUp : Route("signUp")

@Serializable
data object Search : Route("search")

data class MyPage(val email: String) : Route("myPage?email={email}") {
fun createRoute(email: String) = "myPage?email=$email"
}
@Serializable
data object MyPage : Route("myPage")
}
32 changes: 32 additions & 0 deletions app/src/main/java/org/sopt/and/data/ServicePool.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// data/ServicePool.kt
package org.sopt.and.data

import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory
import kotlinx.serialization.json.Json
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import org.sopt.and.BuildConfig
import org.sopt.and.data.service.AuthService
import retrofit2.Retrofit

object ServicePool {
private val json = Json {
ignoreUnknownKeys = true
coerceInputValues = true
}

private val okHttpClient = OkHttpClient.Builder()
.addInterceptor(HttpLoggingInterceptor().apply {
level = HttpLoggingInterceptor.Level.BODY
})
.build()

private val retrofit: Retrofit = Retrofit.Builder()
.baseUrl(BuildConfig.BASE_URL)
.addConverterFactory(json.asConverterFactory("application/json".toMediaType()))
.client(okHttpClient)
.build()

val authService: AuthService by lazy { retrofit.create(AuthService::class.java) }
}
5 changes: 3 additions & 2 deletions app/src/main/java/org/sopt/and/domain/User.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.sopt.and.domain

data class User(
var email: String = "",
var password: String = ""
val username: String = "",
val password: String = "",
val hobby: String = "" // hobby 필드 추가
)
Original file line number Diff line number Diff line change
Expand Up @@ -19,59 +19,6 @@ import androidx.compose.ui.text.input.VisualTransformation
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp

@Composable
fun EmailInputField(
value: String,
placeholder: String,
onValueChange: (String) -> Unit,
modifier: Modifier = Modifier,
isError: Boolean = false,
errorMessage: String? = null
) {
val containerColor by animateColorAsState(
targetValue = if (isError) Color.DarkGray.copy(red = 0.4f) else Color.DarkGray,
label = "containerColor"
)

Column {
TextField(
value = value,
onValueChange = onValueChange,
modifier = modifier
.fillMaxWidth()
.height(60.dp),
placeholder = {
Text(
text = placeholder,
color = Color.Gray
)
},
colors = TextFieldDefaults.colors(
focusedContainerColor = containerColor,
unfocusedContainerColor = containerColor,
focusedTextColor = Color.White,
unfocusedTextColor = Color.White,
focusedIndicatorColor = if (isError) Color.Red.copy(alpha = 0.5f) else Color.Transparent,
unfocusedIndicatorColor = if (isError) Color.Red.copy(alpha = 0.5f) else Color.Transparent,
errorContainerColor = containerColor,
errorIndicatorColor = Color.Red.copy(alpha = 0.5f)
),
shape = RoundedCornerShape(5.dp),
singleLine = true,
isError = isError
)

if (isError && errorMessage != null) {
Text(
text = errorMessage,
color = Color.Red.copy(alpha = 0.8f),
fontSize = 12.sp,
modifier = Modifier.padding(start = 4.dp, top = 4.dp)
)
}
}
}

@Composable
fun PasswordInputField(
value: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// presentation/component/TextInputField.kt
package org.sopt.and.presentation.component

import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Text
import androidx.compose.material3.TextField
import androidx.compose.material3.TextFieldDefaults
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp

@Composable
fun TextInputField(
value: String,
onValueChange: (String) -> Unit,
modifier: Modifier = Modifier,
placeholder: String = "",
isError: Boolean = false,
maxLength: Int = 8,
singleLine: Boolean = true
) {
TextField(
value = value,
onValueChange = {
if (it.length <= maxLength) {
onValueChange(it)
}
},
modifier = modifier
.fillMaxWidth()
.height(60.dp),
placeholder = {
Text(
text = placeholder,
color = Color.Gray
)
},
colors = TextFieldDefaults.colors(
focusedContainerColor = Color.DarkGray,
unfocusedContainerColor = Color.DarkGray,
focusedTextColor = Color.White,
unfocusedTextColor = Color.White,
focusedIndicatorColor = if (isError) Color.Red.copy(alpha = 0.5f) else Color.Transparent,
unfocusedIndicatorColor = if (isError) Color.Red.copy(alpha = 0.5f) else Color.Transparent,
errorContainerColor = Color.DarkGray,
errorIndicatorColor = Color.Red.copy(alpha = 0.5f)
),
shape = RoundedCornerShape(5.dp),
singleLine = singleLine,
isError = isError
)
}
62 changes: 14 additions & 48 deletions app/src/main/java/org/sopt/and/presentation/navigation/NavGraph.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,21 @@ package org.sopt.and.presentation.navigation
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.navigation.NavHostController
import androidx.navigation.NavType
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.navArgument
import org.sopt.and.Route
import org.sopt.and.presentation.home.HomeScreen
import org.sopt.and.presentation.mypage.MyPageScreen
import org.sopt.and.presentation.search.SearchScreen
import org.sopt.and.presentation.signin.SignInScreen
import org.sopt.and.presentation.signup.SignUpScreen


@Composable
fun NavGraph(
navController: NavHostController,
modifier: Modifier = Modifier,
startDestination: String = Route.SignIn().route,
isLogined: (Boolean) -> Unit = {},
onEmailUpdated: (String) -> Unit = {}
startDestination: String = Route.SignIn.route,
isLoggedIn: (Boolean) -> Unit = {}
) {
NavHost(
navController = navController,
Expand All @@ -32,55 +28,34 @@ fun NavGraph(
HomeScreen()
}

composable(
route = Route.SignIn().route,
arguments = listOf(
navArgument("email") {
type = NavType.StringType
defaultValue = ""
},
navArgument("password") {
type = NavType.StringType
defaultValue = ""
}
)
) { backStackEntry ->
val email = backStackEntry.arguments?.getString("email") ?: ""
val password = backStackEntry.arguments?.getString("password") ?: ""
composable(route = Route.SignIn.route) {
SignInScreen(
email = email,
password = password,
navigateToMyPage = { userEmail ->
onEmailUpdated(userEmail)
onLoginSuccess = {
navController.navigate(Route.Home.route) {
popUpTo(navController.graph.startDestinationId) {
inclusive = true
}
launchSingleTop = true
}
isLogined(true)
isLoggedIn(true)
},
navigateToSignUp = {
navController.navigate(Route.SignUp.route) {
popUpTo(Route.SignIn().route) {
saveState = true
}
launchSingleTop = true
restoreState = true
}
onSignUpClick = {
navController.navigate(Route.SignUp.route)
}
)
}

composable(route = Route.SignUp.route) {
SignUpScreen(
navigateToSignIn = { user ->
navController.navigate(Route.SignIn(user.email, user.password).createRoute(user.email, user.password)) {
onSignUpSuccess = {
navController.navigate(Route.SignIn.route) {
popUpTo(Route.SignUp.route) {
inclusive = true
}
launchSingleTop = true
}
},
onBackClick = {
navController.popBackStack()
}
)
}
Expand All @@ -89,17 +64,8 @@ fun NavGraph(
SearchScreen()
}

composable(
route = Route.MyPage("").route,
arguments = listOf(
navArgument("email") {
type = NavType.StringType
defaultValue = ""
}
)
) { backStackEntry ->
val email = backStackEntry.arguments?.getString("email") ?: ""
MyPageScreen(email = email)
composable(route = Route.MyPage.route) {
MyPageScreen()
}
}
}
Loading

0 comments on commit 289ec59

Please sign in to comment.