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

Week4 #8

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from
Open
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
19 changes: 16 additions & 3 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
import java.util.Properties

plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.kotlin.compose)
alias(libs.plugins.kotlin.serialization)
}

val properties = Properties().apply {
load(project.rootProject.file("local.properties").inputStream())
}

android {
namespace = "org.sopt.and"
compileSdk = 34
compileSdk = 35

defaultConfig {
applicationId = "org.sopt.and"
minSdk = 28
targetSdk = 34
targetSdk = 35
versionCode = 1
versionName = "1.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
buildConfigField("String", "BASE_URL", properties["base.url"].toString())
}

buildTypes {
Expand All @@ -37,6 +43,7 @@ android {
}
buildFeatures {
compose = true
buildConfig = true
}
}

Expand Down Expand Up @@ -65,4 +72,10 @@ dependencies {
androidTestImplementation(libs.androidx.ui.test.junit4)
debugImplementation(libs.androidx.ui.tooling)
debugImplementation(libs.androidx.ui.test.manifest)
implementation(platform(libs.okhttp.bom))
implementation(libs.okhttp)
implementation(libs.okhttp.logging.interceptor)
implementation(libs.retrofit)
implementation(libs.retrofit.kotlin.serialization.converter)
implementation(libs.kotlinx.serialization.json)
}
23 changes: 4 additions & 19 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

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

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
Expand All @@ -11,26 +13,9 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.ANDANDROID"
android:usesCleartextTraffic="true"
tools:targetApi="31">
<activity
android:name=".MyActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".HomeActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SearchActivity"
android:exported="false" />

<activity
android:name=".MainActivity"
android:exported="true"
Expand Down
131 changes: 66 additions & 65 deletions app/src/main/java/org/sopt/and/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,93 +5,94 @@ import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SnackbarHostState
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.rememberNavController
import org.sopt.and.ui.theme.ANDANDROIDTheme
import androidx.navigation.compose.composable
import androidx.navigation.toRoute

//๋กœ๊ทธ์ธ ์„ฑ๊ณต ์‹œ ๋กœ๊ทธ์ธํ•œ ์ด๋ฉ”์ผ์„ viewmodel์— ๋‹ด์•„ ์ „์—ญ๋ณ€์ˆ˜๋กœ ๊ด€๋ฆฌ..
class UserViewModel : ViewModel() {

private val _email = MutableLiveData<String>()
val email: LiveData<String> = _email

fun setEmail(newEmail: String) {
_email.value = newEmail
}
}
import org.sopt.and.data.datalocal.datasourceimpl.UserInfoLocalDataSourceImpl
import org.sopt.and.presentation.loginScreen.LoginScreen
import org.sopt.and.presentation.mypageScreen.MypageScreen
import org.sopt.and.presentation.searchScreen.SearchScreen
import org.sopt.and.presentation.signupScreen.SignUpScreen
import org.sopt.and.presentation.homeScreen.HomeScreen
import org.sopt.and.presentation.homeScreen.HomeViewModel
import org.sopt.and.presentation.loginScreen.LoginViewModel
import org.sopt.and.presentation.mypageScreen.MypageViewModel
import org.sopt.and.util.Route

class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContent {
ANDANDROIDTheme {
Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
val navController = rememberNavController()
val userViewModel: UserViewModel = viewModel()
Scaffold(
modifier = Modifier.fillMaxSize(),
content = { it
val navController = rememberNavController()

NavHost(
navController = navController,
startDestination = SignUpScreen,
modifier = Modifier.padding(innerPadding)
){
composable<SignUpScreen> {
SignUpScreen(
navigateToLoginScreen = {
emailText, passwordText -> navController.navigate(LoginScreen(emailText, passwordText))
}
)
}
val context = navController.context
val userInfoLocalDataSource = UserInfoLocalDataSourceImpl(context)

composable<LoginScreen> { backStackEntry ->
val item = backStackEntry.toRoute<LoginScreen>()
val scope = rememberCoroutineScope()
val snackbarHostState = remember { SnackbarHostState() }
LoginScreen(
emailText = item.emailText,
passwordText = item.passwordText,
scope = scope,
snackbarHostState = snackbarHostState,
navigateToHomeScreen = {
navController.navigate("home")
}
)
}
NavHost(
navController = navController,
startDestination = Route.SignUpScreen(userName = "", password = ""),
modifier = Modifier
){
composable<Route.SignUpScreen> { backStackEntry ->
val item = backStackEntry.toRoute<Route.SignUpScreen>()
SignUpScreen(
navigateToLoginScreen = {
navController.navigate(Route.LoginScreen){
popUpTo<Route.SignUpScreen> { inclusive = true }
launchSingleTop = true
}
}
)
}

composable("home") {
HomeScreen(
navController = navController,
)
}
composable<Route.LoginScreen> { backStackEntry ->
val item = backStackEntry.toRoute<Route.LoginScreen>()
LoginScreen(
loginViewModel = LoginViewModel(userInfoLocalDataSource = userInfoLocalDataSource),
navigateToHomeScreen = {
navController.navigate(Route.HomeScreen){
popUpTo<Route.HomeScreen> { inclusive = true}
launchSingleTop = true
}
},
)
}

composable("search") {
SearchScreen(
navController = navController
)
}
composable<Route.HomeScreen> { backStackEntry ->
val item = backStackEntry.toRoute<Route.HomeScreen>()
HomeScreen(
homeViewModel = HomeViewModel(),
navController = navController,
)
}

composable("profile") {
composable<Route.SearchScreen> { backStackEntry ->
val item = backStackEntry.toRoute<Route.SearchScreen>()
SearchScreen(
navController = navController
)
}

MypageScreen(
navController = navController,
userViewModel = userViewModel
)
composable<Route.MypageScreen> { backStackEntry ->
val item = backStackEntry.toRoute<Route.MypageScreen>()
MypageScreen(
mypageViewModel = MypageViewModel(userInfoLocalDataSource = userInfoLocalDataSource),
navController = navController
)
}
}

}
}

})
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.sopt.and.data.datalocal.datasource

interface UserInfoLocalDataSource {
var accessToken: String
var userName: String
fun clear()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.sopt.and.data.datalocal.datasourceimpl

import android.content.Context
import android.content.SharedPreferences
import androidx.core.content.edit
import org.sopt.and.data.datalocal.datasource.UserInfoLocalDataSource

class UserInfoLocalDataSourceImpl(context: Context) : UserInfoLocalDataSource {

private val sharedPreferences: SharedPreferences =
context.getSharedPreferences(PREFERENCES_NAME, Context.MODE_PRIVATE)

override var accessToken: String
get() = sharedPreferences.getString(ACCESSTOKEN, INITIAL_VALUE).toString()
set(value) = sharedPreferences.edit { putString(ACCESSTOKEN, value)}

override var userName: String
get() = sharedPreferences.getString(USERNAME, INITIAL_VALUE).toString()
set(value) = sharedPreferences.edit { putString(USERNAME, value) }

override fun clear() = sharedPreferences.edit { clear() }

companion object {
const val PREFERENCES_NAME = "user_preferences"
const val ACCESSTOKEN = "accesstoken"
const val USERNAME = "userName"
const val INITIAL_VALUE = ""
}
}
12 changes: 12 additions & 0 deletions app/src/main/java/org/sopt/and/data/dto/login/RequestGetUserDto.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.sopt.and.data.dto.login

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class RequestGetUserDto(
@SerialName("username")
val userName: String,
@SerialName("password")
val password: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.sopt.and.data.dto.login

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class ResponseGetUserFailedDto(
@SerialName("code")
val code: String
)

@Serializable
data class ResponseGetUserDto(
@SerialName("result")
val result: UserResult
){
@Serializable
data class UserResult(
@SerialName("token")
val token: String
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.sopt.and.data.dto.mypage

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class ResponseGetUserHobbyFailDto(
@SerialName("code")
val no: Int
)

@Serializable
data class ResponseGetUserHobbyDto(
@SerialName("result")
val result: Result?= null,
){
@Serializable
data class Result(
@SerialName("hobby")
val userHobby: String? = null,
)
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.sopt.and.data.dto.signup

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class RequestCreateUserDto(
@SerialName("username")
val userName: String,
@SerialName("password")
val password: String,
@SerialName("hobby")
val hobby: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.sopt.and.data.dto.signup

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class ResponseCreateUserFailedDto(
@SerialName("code")
val code: String
)

@Serializable
data class ResponseCreateUserSuccessDto(
@SerialName("result")
val result: UserResult
){
@Serializable
data class UserResult(
@SerialName("no")
val no: Int
)
}

Loading