From fb985fd02e16d1a26c4cd6e8787dc2545e17adf4 Mon Sep 17 00:00:00 2001 From: boiledegg Date: Fri, 7 Jun 2024 16:41:59 +0900 Subject: [PATCH 01/31] =?UTF-8?q?CHORE/#19:=20=EC=A0=80=EC=9E=A5=EC=86=8C?= =?UTF-8?q?=20=EA=B4=80=EB=A0=A8=20=ED=8C=8C=EC=9D=BC=EC=B6=94=EA=B0=80,?= =?UTF-8?q?=20=EC=BD=94=EB=93=9C=EC=88=98=EC=A0=95,=20=ED=8C=A8=ED=82=A4?= =?UTF-8?q?=EC=A7=80=EA=B5=AC=EC=A1=B0=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../now/compose/container/AppContainer.kt | 13 ++++++++ .../now/compose/container/SoptAppContainer.kt | 30 +++++++++---------- .../AuthRepositoryImpl.kt} | 13 ++------ .../FollowerRepositoryImpl.kt} | 10 ++----- .../MemberRepositoryImpl.kt} | 14 ++------- .../UserRepositoryImpl.kt} | 19 +++--------- .../container/repository/AuthRepository.kt | 14 +++++++++ .../repository/FollowerRepository.kt | 10 +++++++ .../container/repository/MemberRepository.kt | 13 ++++++++ .../container/repository/UserRepository.kt | 14 +++++++++ .../compose/ui/screens/home/HomeViewModel.kt | 13 ++------ .../ui/screens/login/LoginViewModel.kt | 8 ++--- .../ui/screens/profile/ProfileViewModel.kt | 4 +-- .../ui/screens/signup/SignUpViewModel.kt | 4 +-- 14 files changed, 102 insertions(+), 77 deletions(-) create mode 100644 app/src/main/java/com/sopt/now/compose/container/AppContainer.kt rename app/src/main/java/com/sopt/now/compose/container/{AuthRepository.kt => impl/AuthRepositoryImpl.kt} (62%) rename app/src/main/java/com/sopt/now/compose/container/{FollowerRepository.kt => impl/FollowerRepositoryImpl.kt} (60%) rename app/src/main/java/com/sopt/now/compose/container/{MemberRepository.kt => impl/MemberRepositoryImpl.kt} (72%) rename app/src/main/java/com/sopt/now/compose/container/{UserRepository.kt => impl/UserRepositoryImpl.kt} (74%) create mode 100644 app/src/main/java/com/sopt/now/compose/container/repository/AuthRepository.kt create mode 100644 app/src/main/java/com/sopt/now/compose/container/repository/FollowerRepository.kt create mode 100644 app/src/main/java/com/sopt/now/compose/container/repository/MemberRepository.kt create mode 100644 app/src/main/java/com/sopt/now/compose/container/repository/UserRepository.kt diff --git a/app/src/main/java/com/sopt/now/compose/container/AppContainer.kt b/app/src/main/java/com/sopt/now/compose/container/AppContainer.kt new file mode 100644 index 0000000..1fd26ef --- /dev/null +++ b/app/src/main/java/com/sopt/now/compose/container/AppContainer.kt @@ -0,0 +1,13 @@ +package com.sopt.now.compose.container + +import com.sopt.now.compose.container.impl.AuthRepositoryImpl +import com.sopt.now.compose.container.impl.FollowerRepositoryImpl +import com.sopt.now.compose.container.impl.MemberRepositoryImpl +import com.sopt.now.compose.container.impl.UserRepositoryImpl + +interface AppContainer{ + val userRepository: UserRepositoryImpl + val followRepository: FollowerRepositoryImpl + val memberRepository: MemberRepositoryImpl + val authRepository: AuthRepositoryImpl +} \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/compose/container/SoptAppContainer.kt b/app/src/main/java/com/sopt/now/compose/container/SoptAppContainer.kt index 07fe611..d67ecf7 100644 --- a/app/src/main/java/com/sopt/now/compose/container/SoptAppContainer.kt +++ b/app/src/main/java/com/sopt/now/compose/container/SoptAppContainer.kt @@ -3,7 +3,11 @@ package com.sopt.now.compose.container import android.content.Context import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory import com.sopt.now.compose.BuildConfig -import com.sopt.now.compose.container.PreferenceUserRepository.Companion.USER_ID_KEY +import com.sopt.now.compose.container.impl.UserRepositoryImpl.Companion.USER_ID_KEY +import com.sopt.now.compose.container.impl.AuthRepositoryImpl +import com.sopt.now.compose.container.impl.FollowerRepositoryImpl +import com.sopt.now.compose.container.impl.MemberRepositoryImpl +import com.sopt.now.compose.container.impl.UserRepositoryImpl import com.sopt.now.compose.network.FollowService import com.sopt.now.compose.network.AuthService import kotlinx.serialization.json.Json @@ -11,32 +15,26 @@ import okhttp3.Interceptor import okhttp3.MediaType.Companion.toMediaType import okhttp3.OkHttpClient import retrofit2.Retrofit -import retrofit2.create -interface AppContainer{ - val userRepository: PreferenceUserRepository - val followRepository: NetworkFollowerRepository - val memberRepository: NetworkMemberRepository - val authRepository: NetworkAuthRepository -} + class SoptAppContainer(context: Context): AppContainer { - override val userRepository: PreferenceUserRepository by lazy { - PreferenceUserRepository(context.getSharedPreferences(PREFERENCE_ID, Context.MODE_PRIVATE)) + override val userRepository: UserRepositoryImpl by lazy { + UserRepositoryImpl(context.getSharedPreferences(PREFERENCE_ID, Context.MODE_PRIVATE)) } - override val followRepository: NetworkFollowerRepository by lazy { - NetworkFollowerRepository(followService = retrofitFollower.create(FollowService::class.java)) + override val followRepository: FollowerRepositoryImpl by lazy { + FollowerRepositoryImpl(followService = retrofitFollower.create(FollowService::class.java)) } - override val memberRepository: NetworkMemberRepository by lazy { - NetworkMemberRepository(authService = retrofitUser.create(AuthService::class.java)) + override val memberRepository: MemberRepositoryImpl by lazy { + MemberRepositoryImpl(authService = retrofitUser.create(AuthService::class.java)) } - override val authRepository: NetworkAuthRepository by lazy { - NetworkAuthRepository(authService = retrofitLogin.create(AuthService::class.java)) + override val authRepository: AuthRepositoryImpl by lazy { + AuthRepositoryImpl(authService = retrofitLogin.create(AuthService::class.java)) } val retrofitLogin: Retrofit by lazy { diff --git a/app/src/main/java/com/sopt/now/compose/container/AuthRepository.kt b/app/src/main/java/com/sopt/now/compose/container/impl/AuthRepositoryImpl.kt similarity index 62% rename from app/src/main/java/com/sopt/now/compose/container/AuthRepository.kt rename to app/src/main/java/com/sopt/now/compose/container/impl/AuthRepositoryImpl.kt index fea7063..6420171 100644 --- a/app/src/main/java/com/sopt/now/compose/container/AuthRepository.kt +++ b/app/src/main/java/com/sopt/now/compose/container/impl/AuthRepositoryImpl.kt @@ -1,21 +1,14 @@ -package com.sopt.now.compose.container +package com.sopt.now.compose.container.impl +import com.sopt.now.compose.container.repository.AuthRepository import com.sopt.now.compose.network.AuthService import com.sopt.now.compose.network.dto.RequestLoginDto import com.sopt.now.compose.network.dto.RequestSignUpDto import com.sopt.now.compose.network.dto.ResponseLoginDto import com.sopt.now.compose.network.dto.ResponseSignUpDto -import com.sopt.now.compose.ui.screens.login.LoginViewModel -import kotlinx.serialization.json.Json -import kotlinx.serialization.json.jsonObject import retrofit2.Response -interface AuthRepository { - suspend fun postLogin(request: RequestLoginDto): Result> - suspend fun postSignUp(request: RequestSignUpDto): Result> -} - -class NetworkAuthRepository( +class AuthRepositoryImpl( private val authService: AuthService ) : AuthRepository { override suspend fun postLogin(request: RequestLoginDto): Result> = diff --git a/app/src/main/java/com/sopt/now/compose/container/FollowerRepository.kt b/app/src/main/java/com/sopt/now/compose/container/impl/FollowerRepositoryImpl.kt similarity index 60% rename from app/src/main/java/com/sopt/now/compose/container/FollowerRepository.kt rename to app/src/main/java/com/sopt/now/compose/container/impl/FollowerRepositoryImpl.kt index e5f0879..2cecddc 100644 --- a/app/src/main/java/com/sopt/now/compose/container/FollowerRepository.kt +++ b/app/src/main/java/com/sopt/now/compose/container/impl/FollowerRepositoryImpl.kt @@ -1,15 +1,11 @@ -package com.sopt.now.compose.container +package com.sopt.now.compose.container.impl -import com.sopt.now.compose.models.Follower +import com.sopt.now.compose.container.repository.FollowerRepository import com.sopt.now.compose.network.FollowService import com.sopt.now.compose.network.dto.ResponseFollowListDto import retrofit2.Response -interface FollowerRepository{ - suspend fun getFollowers(page: Int = 2): Result> -} - -class NetworkFollowerRepository( +class FollowerRepositoryImpl( private val followService: FollowService ): FollowerRepository { override suspend fun getFollowers(page: Int): Result> = runCatching { diff --git a/app/src/main/java/com/sopt/now/compose/container/MemberRepository.kt b/app/src/main/java/com/sopt/now/compose/container/impl/MemberRepositoryImpl.kt similarity index 72% rename from app/src/main/java/com/sopt/now/compose/container/MemberRepository.kt rename to app/src/main/java/com/sopt/now/compose/container/impl/MemberRepositoryImpl.kt index 50b8d2d..12bceeb 100644 --- a/app/src/main/java/com/sopt/now/compose/container/MemberRepository.kt +++ b/app/src/main/java/com/sopt/now/compose/container/impl/MemberRepositoryImpl.kt @@ -1,21 +1,13 @@ -package com.sopt.now.compose.container +package com.sopt.now.compose.container.impl +import com.sopt.now.compose.container.repository.MemberRepository import com.sopt.now.compose.models.User import com.sopt.now.compose.network.AuthService import com.sopt.now.compose.network.dto.RequestChangePasswordDto import com.sopt.now.compose.network.dto.ResponseChangePasswordDto import retrofit2.Response -private const val TAG = "AuthRepository" - -interface MemberRepository { - suspend fun getUserInfo(): Result - suspend fun patchUserPassword( - request: RequestChangePasswordDto - ): Response -} - -class NetworkMemberRepository( +class MemberRepositoryImpl( private val authService: AuthService ) : MemberRepository { override suspend fun getUserInfo(): Result = runCatching { diff --git a/app/src/main/java/com/sopt/now/compose/container/UserRepository.kt b/app/src/main/java/com/sopt/now/compose/container/impl/UserRepositoryImpl.kt similarity index 74% rename from app/src/main/java/com/sopt/now/compose/container/UserRepository.kt rename to app/src/main/java/com/sopt/now/compose/container/impl/UserRepositoryImpl.kt index 591ba61..ccfe51c 100644 --- a/app/src/main/java/com/sopt/now/compose/container/UserRepository.kt +++ b/app/src/main/java/com/sopt/now/compose/container/impl/UserRepositoryImpl.kt @@ -1,21 +1,11 @@ -package com.sopt.now.compose.container +package com.sopt.now.compose.container.impl import android.content.SharedPreferences -import android.util.Log +import com.sopt.now.compose.container.repository.UserRepository import com.sopt.now.compose.models.User -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.withContext -interface UserRepository { - suspend fun getUserProfile(): User? - suspend fun setUserProfile(user: User) - - suspend fun getUserId(): String - suspend fun setUserId(userId: String) -} - -class PreferenceUserRepository( - val sharedPreferences: SharedPreferences +class UserRepositoryImpl( + private val sharedPreferences: SharedPreferences ) : UserRepository { override suspend fun getUserProfile(): User { sharedPreferences.run { @@ -43,7 +33,6 @@ class PreferenceUserRepository( } override suspend fun setUserId(userId: String) { - Log.d(TAG, "userId: $userId") val edit = sharedPreferences.edit() edit.putString(USER_ID_KEY, userId).apply() diff --git a/app/src/main/java/com/sopt/now/compose/container/repository/AuthRepository.kt b/app/src/main/java/com/sopt/now/compose/container/repository/AuthRepository.kt new file mode 100644 index 0000000..b997f17 --- /dev/null +++ b/app/src/main/java/com/sopt/now/compose/container/repository/AuthRepository.kt @@ -0,0 +1,14 @@ +package com.sopt.now.compose.container.repository + +import com.sopt.now.compose.network.AuthService +import com.sopt.now.compose.network.dto.RequestLoginDto +import com.sopt.now.compose.network.dto.RequestSignUpDto +import com.sopt.now.compose.network.dto.ResponseLoginDto +import com.sopt.now.compose.network.dto.ResponseSignUpDto +import retrofit2.Response + +interface AuthRepository { + suspend fun postLogin(request: RequestLoginDto): Result> + suspend fun postSignUp(request: RequestSignUpDto): Result> +} + diff --git a/app/src/main/java/com/sopt/now/compose/container/repository/FollowerRepository.kt b/app/src/main/java/com/sopt/now/compose/container/repository/FollowerRepository.kt new file mode 100644 index 0000000..8230473 --- /dev/null +++ b/app/src/main/java/com/sopt/now/compose/container/repository/FollowerRepository.kt @@ -0,0 +1,10 @@ +package com.sopt.now.compose.container.repository + +import com.sopt.now.compose.network.FollowService +import com.sopt.now.compose.network.dto.ResponseFollowListDto +import retrofit2.Response + +interface FollowerRepository{ + suspend fun getFollowers(page: Int = 2): Result> +} + diff --git a/app/src/main/java/com/sopt/now/compose/container/repository/MemberRepository.kt b/app/src/main/java/com/sopt/now/compose/container/repository/MemberRepository.kt new file mode 100644 index 0000000..6d5ebd6 --- /dev/null +++ b/app/src/main/java/com/sopt/now/compose/container/repository/MemberRepository.kt @@ -0,0 +1,13 @@ +package com.sopt.now.compose.container.repository + +import com.sopt.now.compose.models.User +import com.sopt.now.compose.network.dto.RequestChangePasswordDto +import com.sopt.now.compose.network.dto.ResponseChangePasswordDto +import retrofit2.Response + +interface MemberRepository { + suspend fun getUserInfo(): Result + suspend fun patchUserPassword( + request: RequestChangePasswordDto + ): Response +} \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/compose/container/repository/UserRepository.kt b/app/src/main/java/com/sopt/now/compose/container/repository/UserRepository.kt new file mode 100644 index 0000000..ed52578 --- /dev/null +++ b/app/src/main/java/com/sopt/now/compose/container/repository/UserRepository.kt @@ -0,0 +1,14 @@ +package com.sopt.now.compose.container.repository + +import android.content.SharedPreferences +import android.util.Log +import com.sopt.now.compose.models.User + +interface UserRepository { + suspend fun getUserProfile(): User? + suspend fun setUserProfile(user: User) + + suspend fun getUserId(): String + suspend fun setUserId(userId: String) +} + diff --git a/app/src/main/java/com/sopt/now/compose/ui/screens/home/HomeViewModel.kt b/app/src/main/java/com/sopt/now/compose/ui/screens/home/HomeViewModel.kt index 42c2793..9c62fbe 100644 --- a/app/src/main/java/com/sopt/now/compose/ui/screens/home/HomeViewModel.kt +++ b/app/src/main/java/com/sopt/now/compose/ui/screens/home/HomeViewModel.kt @@ -1,21 +1,14 @@ package com.sopt.now.compose.ui.screens.home import android.util.Log -import androidx.compose.runtime.MutableState -import androidx.compose.runtime.mutableStateOf import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewmodel.initializer import androidx.lifecycle.viewmodel.viewModelFactory -import androidx.navigation.NavHostController -import com.sopt.now.compose.MainActivity.Companion.NAVIGATE_BACK_PRESSED_KEY -import com.sopt.now.compose.MainActivity.Companion.NAVIGATE_LOGIN_KEY import com.sopt.now.compose.SoptApplication -import com.sopt.now.compose.container.FollowerRepository -import com.sopt.now.compose.container.NetworkMemberRepository -import com.sopt.now.compose.models.Follower -import com.sopt.now.compose.models.User +import com.sopt.now.compose.container.repository.FollowerRepository +import com.sopt.now.compose.container.impl.MemberRepositoryImpl import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow @@ -25,7 +18,7 @@ private const val TAG = "HomeViewModel" class HomeViewModel( private val followerRepository: FollowerRepository, - private val authRepository: NetworkMemberRepository + private val authRepository: MemberRepositoryImpl ) : ViewModel() { private val _uiState = MutableStateFlow(HomeUiState.Loading()) diff --git a/app/src/main/java/com/sopt/now/compose/ui/screens/login/LoginViewModel.kt b/app/src/main/java/com/sopt/now/compose/ui/screens/login/LoginViewModel.kt index 17b5151..5620750 100644 --- a/app/src/main/java/com/sopt/now/compose/ui/screens/login/LoginViewModel.kt +++ b/app/src/main/java/com/sopt/now/compose/ui/screens/login/LoginViewModel.kt @@ -7,8 +7,8 @@ import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewmodel.initializer import androidx.lifecycle.viewmodel.viewModelFactory import com.sopt.now.compose.SoptApplication -import com.sopt.now.compose.container.NetworkAuthRepository -import com.sopt.now.compose.container.PreferenceUserRepository +import com.sopt.now.compose.container.impl.AuthRepositoryImpl +import com.sopt.now.compose.container.impl.UserRepositoryImpl import com.sopt.now.compose.network.dto.RequestLoginDto import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow @@ -19,8 +19,8 @@ import kotlinx.serialization.json.Json import kotlinx.serialization.json.jsonObject class LoginViewModel( - private val userRepository: PreferenceUserRepository, - private val authRepository: NetworkAuthRepository + private val userRepository: UserRepositoryImpl, + private val authRepository: AuthRepositoryImpl ): ViewModel() { private val _uiState = MutableStateFlow(LoginUiState()) val uiState: StateFlow = _uiState.asStateFlow() diff --git a/app/src/main/java/com/sopt/now/compose/ui/screens/profile/ProfileViewModel.kt b/app/src/main/java/com/sopt/now/compose/ui/screens/profile/ProfileViewModel.kt index 49af2f2..6568107 100644 --- a/app/src/main/java/com/sopt/now/compose/ui/screens/profile/ProfileViewModel.kt +++ b/app/src/main/java/com/sopt/now/compose/ui/screens/profile/ProfileViewModel.kt @@ -7,7 +7,7 @@ import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewmodel.initializer import androidx.lifecycle.viewmodel.viewModelFactory import com.sopt.now.compose.SoptApplication -import com.sopt.now.compose.container.NetworkMemberRepository +import com.sopt.now.compose.container.impl.MemberRepositoryImpl import com.sopt.now.compose.models.User import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow @@ -15,7 +15,7 @@ import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.launch class ProfileViewModel( - private val authRepository: NetworkMemberRepository + private val authRepository: MemberRepositoryImpl ): ViewModel() { private val _uiState = MutableStateFlow(ProfileUiState.Loading) val uiState: StateFlow = _uiState.asStateFlow() diff --git a/app/src/main/java/com/sopt/now/compose/ui/screens/signup/SignUpViewModel.kt b/app/src/main/java/com/sopt/now/compose/ui/screens/signup/SignUpViewModel.kt index 80ca7d4..9da4b38 100644 --- a/app/src/main/java/com/sopt/now/compose/ui/screens/signup/SignUpViewModel.kt +++ b/app/src/main/java/com/sopt/now/compose/ui/screens/signup/SignUpViewModel.kt @@ -6,7 +6,7 @@ import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewmodel.initializer import androidx.lifecycle.viewmodel.viewModelFactory import com.sopt.now.compose.SoptApplication -import com.sopt.now.compose.container.NetworkAuthRepository +import com.sopt.now.compose.container.impl.AuthRepositoryImpl import com.sopt.now.compose.network.dto.RequestSignUpDto import com.sopt.now.compose.ui.screens.login.LoginViewModel import kotlinx.coroutines.flow.MutableStateFlow @@ -18,7 +18,7 @@ import kotlinx.serialization.json.Json import kotlinx.serialization.json.jsonObject class SignUpViewModel( - private val authRepository: NetworkAuthRepository + private val authRepository: AuthRepositoryImpl ): ViewModel() { private val _uiState = MutableStateFlow(SignUpState()) val uiState: StateFlow = _uiState.asStateFlow() From 812a7dbd4ca8671c1e2465bcf789d14fc25536bd Mon Sep 17 00:00:00 2001 From: boiledegg Date: Fri, 7 Jun 2024 16:51:05 +0900 Subject: [PATCH 02/31] =?UTF-8?q?MOD/#19:=20=EC=82=AC=EC=9A=A9=EC=9E=90?= =?UTF-8?q?=EC=A0=80=EC=9E=A5=EC=86=8C=20=EA=B4=80=EB=A0=A8=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/sopt/now/compose/container/SoptAppContainer.kt | 7 +------ .../now/compose/container/impl/UserRepositoryImpl.kt | 8 ++++---- .../now/compose/container/repository/UserRepository.kt | 9 ++++----- .../sopt/now/compose/ui/screens/login/LoginViewModel.kt | 2 +- 4 files changed, 10 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/com/sopt/now/compose/container/SoptAppContainer.kt b/app/src/main/java/com/sopt/now/compose/container/SoptAppContainer.kt index d67ecf7..df24a06 100644 --- a/app/src/main/java/com/sopt/now/compose/container/SoptAppContainer.kt +++ b/app/src/main/java/com/sopt/now/compose/container/SoptAppContainer.kt @@ -59,10 +59,7 @@ class SoptAppContainer(context: Context): AppContainer { } private val okHttpClientWithInterceptor: OkHttpClient.Builder by lazy { - val memberId = context - .getSharedPreferences(PREFERENCE_ID, Context.MODE_PRIVATE) - .getString(USER_ID_KEY, "") - .orEmpty() + val memberId = userRepository.getUserId() OkHttpClient.Builder().apply { addInterceptor(Interceptor { chain -> @@ -78,7 +75,5 @@ class SoptAppContainer(context: Context): AppContainer { companion object{ const val BASE_URL = BuildConfig.AUTH_BASE_URL const val PREFERENCE_ID = "SOPT" - - private const val TAG = "SoptAppContainer" } } \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/compose/container/impl/UserRepositoryImpl.kt b/app/src/main/java/com/sopt/now/compose/container/impl/UserRepositoryImpl.kt index ccfe51c..9b80b36 100644 --- a/app/src/main/java/com/sopt/now/compose/container/impl/UserRepositoryImpl.kt +++ b/app/src/main/java/com/sopt/now/compose/container/impl/UserRepositoryImpl.kt @@ -7,7 +7,7 @@ import com.sopt.now.compose.models.User class UserRepositoryImpl( private val sharedPreferences: SharedPreferences ) : UserRepository { - override suspend fun getUserProfile(): User { + override fun getUserProfile(): User { sharedPreferences.run { val id = getString(ID_KEY, "") ?: "" val pw = getString(PW_KEY, "") ?: "" @@ -17,7 +17,7 @@ class UserRepositoryImpl( } } - override suspend fun setUserProfile(user: User) { + override fun setUserProfile(user: User) { val edit = sharedPreferences.edit() edit.run { putString(ID_KEY, user.id) @@ -28,11 +28,11 @@ class UserRepositoryImpl( } } - override suspend fun getUserId(): String { + override fun getUserId(): String { return sharedPreferences.getString(USER_ID_KEY, "").orEmpty() } - override suspend fun setUserId(userId: String) { + override fun setUserId(userId: String) { val edit = sharedPreferences.edit() edit.putString(USER_ID_KEY, userId).apply() diff --git a/app/src/main/java/com/sopt/now/compose/container/repository/UserRepository.kt b/app/src/main/java/com/sopt/now/compose/container/repository/UserRepository.kt index ed52578..737bc77 100644 --- a/app/src/main/java/com/sopt/now/compose/container/repository/UserRepository.kt +++ b/app/src/main/java/com/sopt/now/compose/container/repository/UserRepository.kt @@ -5,10 +5,9 @@ import android.util.Log import com.sopt.now.compose.models.User interface UserRepository { - suspend fun getUserProfile(): User? - suspend fun setUserProfile(user: User) - - suspend fun getUserId(): String - suspend fun setUserId(userId: String) + fun getUserProfile(): User? + fun setUserProfile(user: User) + fun getUserId(): String + fun setUserId(userId: String) } diff --git a/app/src/main/java/com/sopt/now/compose/ui/screens/login/LoginViewModel.kt b/app/src/main/java/com/sopt/now/compose/ui/screens/login/LoginViewModel.kt index 5620750..0631c5b 100644 --- a/app/src/main/java/com/sopt/now/compose/ui/screens/login/LoginViewModel.kt +++ b/app/src/main/java/com/sopt/now/compose/ui/screens/login/LoginViewModel.kt @@ -80,7 +80,7 @@ class LoginViewModel( password = _uiState.value.pw ) - private fun setUserIdInPreference(userId: String) = viewModelScope.launch { + private fun setUserIdInPreference(userId: String) { userRepository.setUserId(userId) } From f36823d601052f5488344cd23101c85cdc1292e3 Mon Sep 17 00:00:00 2001 From: boiledegg Date: Fri, 7 Jun 2024 17:02:55 +0900 Subject: [PATCH 03/31] =?UTF-8?q?ADD/#19:=20collectAsStateWithLifecyle=20?= =?UTF-8?q?=EB=A7=88=EC=9D=B4=EA=B7=B8=EB=A0=88=EC=9D=B4=EC=85=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 19 +++++++++++-------- .../now/compose/ui/screens/home/HomeScreen.kt | 3 ++- .../compose/ui/screens/login/LoginScreen.kt | 3 ++- .../ui/screens/profile/ProfileScreen.kt | 3 ++- .../compose/ui/screens/signup/SignUpScreen.kt | 3 ++- 5 files changed, 19 insertions(+), 12 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 08de33e..1853774 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -55,10 +55,10 @@ android { } dependencies { - implementation 'androidx.core:core-ktx:1.12.0' - implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.7.0' - implementation 'androidx.activity:activity-compose:1.8.2' - implementation platform('androidx.compose:compose-bom:2024.03.00') + implementation 'androidx.core:core-ktx:1.13.1' + implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.8.1' + implementation 'androidx.activity:activity-compose:1.9.0' + implementation platform('androidx.compose:compose-bom:2024.05.00') implementation 'androidx.compose.ui:ui' implementation 'androidx.compose.ui:ui-graphics' implementation 'androidx.compose.ui:ui-tooling-preview' @@ -66,7 +66,7 @@ dependencies { testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.5' androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' - androidTestImplementation platform('androidx.compose:compose-bom:2024.03.00') + androidTestImplementation platform('androidx.compose:compose-bom:2024.05.00') androidTestImplementation 'androidx.compose.ui:ui-test-junit4' debugImplementation 'androidx.compose.ui:ui-tooling' debugImplementation 'androidx.compose.ui:ui-test-manifest' @@ -76,16 +76,19 @@ dependencies { //Retrofit implementation 'com.squareup.retrofit2:retrofit:2.9.0' - implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.1' + implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.3' implementation 'com.jakewharton.retrofit:retrofit2-kotlinx-serialization-converter:1.0.0' // define a BOM and its version - implementation(platform("com.squareup.okhttp3:okhttp-bom:4.10.0")) + implementation(platform("com.squareup.okhttp3:okhttp-bom:4.11.0")) // define any required OkHttp artifacts without version implementation("com.squareup.okhttp3:okhttp") implementation("com.squareup.okhttp3:logging-interceptor") // Coil - implementation("io.coil-kt:coil-compose:2.4.0") + implementation("io.coil-kt:coil-compose:2.6.0") + + + implementation ("androidx.lifecycle:lifecycle-runtime-compose:2.8.1") } \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/compose/ui/screens/home/HomeScreen.kt b/app/src/main/java/com/sopt/now/compose/ui/screens/home/HomeScreen.kt index dbdd296..a340dd8 100644 --- a/app/src/main/java/com/sopt/now/compose/ui/screens/home/HomeScreen.kt +++ b/app/src/main/java/com/sopt/now/compose/ui/screens/home/HomeScreen.kt @@ -31,6 +31,7 @@ import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.TextUnit import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp +import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.lifecycle.viewmodel.compose.viewModel import androidx.navigation.NavHostController import androidx.navigation.compose.rememberNavController @@ -65,7 +66,7 @@ fun HomeScreen( Scaffold( bottomBar = { SoptBottomNavigation(navController = navController) } ) { paddingValue -> - when (val uiState = viewModel.uiState.collectAsState().value) { + when (val uiState = viewModel.uiState.collectAsStateWithLifecycle().value) { is HomeUiState.Success -> { HomeScreen( uiState = uiState, diff --git a/app/src/main/java/com/sopt/now/compose/ui/screens/login/LoginScreen.kt b/app/src/main/java/com/sopt/now/compose/ui/screens/login/LoginScreen.kt index 54f6008..67c9d7c 100644 --- a/app/src/main/java/com/sopt/now/compose/ui/screens/login/LoginScreen.kt +++ b/app/src/main/java/com/sopt/now/compose/ui/screens/login/LoginScreen.kt @@ -25,6 +25,7 @@ import androidx.compose.ui.text.input.KeyboardType import androidx.compose.ui.text.input.PasswordVisualTransformation import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp +import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.lifecycle.viewmodel.compose.viewModel import androidx.navigation.NavHostController import androidx.navigation.compose.rememberNavController @@ -41,7 +42,7 @@ fun LoginScreen( viewModel: LoginViewModel = viewModel(factory = LoginViewModel.Factory), ) { val context = LocalContext.current - val uiState by viewModel.uiState.collectAsState() + val uiState by viewModel.uiState.collectAsStateWithLifecycle() LaunchedEffect(uiState.message) { diff --git a/app/src/main/java/com/sopt/now/compose/ui/screens/profile/ProfileScreen.kt b/app/src/main/java/com/sopt/now/compose/ui/screens/profile/ProfileScreen.kt index b41ee2f..fbbc1b5 100644 --- a/app/src/main/java/com/sopt/now/compose/ui/screens/profile/ProfileScreen.kt +++ b/app/src/main/java/com/sopt/now/compose/ui/screens/profile/ProfileScreen.kt @@ -18,6 +18,7 @@ import androidx.compose.ui.res.painterResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp +import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.lifecycle.viewmodel.compose.viewModel import androidx.navigation.NavHostController import androidx.navigation.compose.rememberNavController @@ -55,7 +56,7 @@ fun ProfileScreen( Scaffold( bottomBar = { SoptBottomNavigation(navController = navController) } ) { paddingValue -> - when (val uiState = viewModel.uiState.collectAsState().value) { + when (val uiState = viewModel.uiState.collectAsStateWithLifecycle().value) { is ProfileUiState.Success -> { ProfileScreen( uiState = uiState, diff --git a/app/src/main/java/com/sopt/now/compose/ui/screens/signup/SignUpScreen.kt b/app/src/main/java/com/sopt/now/compose/ui/screens/signup/SignUpScreen.kt index 2f80ff4..c1d8eaf 100644 --- a/app/src/main/java/com/sopt/now/compose/ui/screens/signup/SignUpScreen.kt +++ b/app/src/main/java/com/sopt/now/compose/ui/screens/signup/SignUpScreen.kt @@ -19,6 +19,7 @@ import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp +import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.lifecycle.viewmodel.compose.viewModel import androidx.navigation.NavHostController import androidx.navigation.compose.rememberNavController @@ -34,7 +35,7 @@ fun SignUpScreen( ) { val context = LocalContext.current - val uiState by viewModel.uiState.collectAsState() + val uiState by viewModel.uiState.collectAsStateWithLifecycle() LaunchedEffect(uiState.message) { if(uiState.message.isNotEmpty()){ if(uiState.isSuccess) { From 8d3d47f3ee7cba1316228033d8f36aafe19f9e43 Mon Sep 17 00:00:00 2001 From: boiledegg Date: Fri, 7 Jun 2024 17:07:13 +0900 Subject: [PATCH 04/31] =?UTF-8?q?REFACTOR/#19:=20week4=20=EB=A6=AC?= =?UTF-8?q?=EB=B7=B0=EA=B8=B0=EB=B0=98=20=EC=BD=94=EB=93=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../now/compose/network/dto/ResponseFollowListDto.kt | 4 ++-- .../sopt/now/compose/ui/screens/login/LoginScreen.kt | 4 +--- .../now/compose/ui/screens/login/LoginUiState.kt | 2 +- .../now/compose/ui/screens/login/LoginViewModel.kt | 12 +++++++----- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/com/sopt/now/compose/network/dto/ResponseFollowListDto.kt b/app/src/main/java/com/sopt/now/compose/network/dto/ResponseFollowListDto.kt index aa2b49a..d9d8967 100644 --- a/app/src/main/java/com/sopt/now/compose/network/dto/ResponseFollowListDto.kt +++ b/app/src/main/java/com/sopt/now/compose/network/dto/ResponseFollowListDto.kt @@ -9,11 +9,11 @@ data class ResponseFollowListDto( @SerialName("page") val page:Int, @SerialName("per_page") - val per_page:Int, + val perPage:Int, @SerialName("total") val total:Int, @SerialName("total_pages") - val total_pages:Int, + val totalPages:Int, @SerialName("data") val data:List, @SerialName("support") diff --git a/app/src/main/java/com/sopt/now/compose/ui/screens/login/LoginScreen.kt b/app/src/main/java/com/sopt/now/compose/ui/screens/login/LoginScreen.kt index 67c9d7c..5b23794 100644 --- a/app/src/main/java/com/sopt/now/compose/ui/screens/login/LoginScreen.kt +++ b/app/src/main/java/com/sopt/now/compose/ui/screens/login/LoginScreen.kt @@ -2,7 +2,6 @@ package com.sopt.now.compose.ui.screens.login import android.app.Activity import android.content.Context -import android.util.Log import android.widget.Toast import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column @@ -13,7 +12,6 @@ import androidx.compose.foundation.layout.padding import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect -import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier @@ -104,7 +102,7 @@ private fun LoginScreen( TextFieldWithTitleComposable( title = R.string.title_pw, label = R.string.login_label_pw, - textFieldText = uiState.pw, + textFieldText = uiState.password, onValueChange = onPwTextFieldChanged, keyboardType = KeyboardType.Password, imeAction = ImeAction.Done, diff --git a/app/src/main/java/com/sopt/now/compose/ui/screens/login/LoginUiState.kt b/app/src/main/java/com/sopt/now/compose/ui/screens/login/LoginUiState.kt index b7a8b1c..27e9ed8 100644 --- a/app/src/main/java/com/sopt/now/compose/ui/screens/login/LoginUiState.kt +++ b/app/src/main/java/com/sopt/now/compose/ui/screens/login/LoginUiState.kt @@ -2,7 +2,7 @@ package com.sopt.now.compose.ui.screens.login data class LoginUiState( val id: String = "", - val pw: String = "", + val password: String = "", val isSuccess: Boolean = false, val message:String = "" ) diff --git a/app/src/main/java/com/sopt/now/compose/ui/screens/login/LoginViewModel.kt b/app/src/main/java/com/sopt/now/compose/ui/screens/login/LoginViewModel.kt index 0631c5b..d44691e 100644 --- a/app/src/main/java/com/sopt/now/compose/ui/screens/login/LoginViewModel.kt +++ b/app/src/main/java/com/sopt/now/compose/ui/screens/login/LoginViewModel.kt @@ -9,6 +9,8 @@ import androidx.lifecycle.viewmodel.viewModelFactory import com.sopt.now.compose.SoptApplication import com.sopt.now.compose.container.impl.AuthRepositoryImpl import com.sopt.now.compose.container.impl.UserRepositoryImpl +import com.sopt.now.compose.container.repository.AuthRepository +import com.sopt.now.compose.container.repository.UserRepository import com.sopt.now.compose.network.dto.RequestLoginDto import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow @@ -19,15 +21,15 @@ import kotlinx.serialization.json.Json import kotlinx.serialization.json.jsonObject class LoginViewModel( - private val userRepository: UserRepositoryImpl, - private val authRepository: AuthRepositoryImpl + private val userRepository: UserRepository, + private val authRepository: AuthRepository ): ViewModel() { private val _uiState = MutableStateFlow(LoginUiState()) val uiState: StateFlow = _uiState.asStateFlow() fun updateUiState( id: String = _uiState.value.id, - pw: String = _uiState.value.pw, + pw: String = _uiState.value.password, isSuccess:Boolean = _uiState.value.isSuccess, message: String = _uiState.value.message @@ -35,7 +37,7 @@ class LoginViewModel( _uiState.update { currentState -> currentState.copy( id = id, - pw = pw, + password = pw, isSuccess = isSuccess, message = message ) @@ -77,7 +79,7 @@ class LoginViewModel( private fun getRequestLoginDto(): RequestLoginDto = RequestLoginDto( authenticationId = _uiState.value.id, - password = _uiState.value.pw + password = _uiState.value.password ) private fun setUserIdInPreference(userId: String) { From 5cda495fcf81ea4f0c38e118f764d54e0f8fde35 Mon Sep 17 00:00:00 2001 From: boiledegg Date: Fri, 7 Jun 2024 17:12:21 +0900 Subject: [PATCH 05/31] =?UTF-8?q?REFACTOR/#19:=20import=20=EC=A0=95?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sopt/now/compose/ExampleInstrumentedTest.kt | 6 ++---- .../java/com/sopt/now/compose/MainActivity.kt | 17 ----------------- .../com/sopt/now/compose/SoptApplication.kt | 2 -- .../now/compose/container/SoptAppContainer.kt | 5 +---- .../container/repository/AuthRepository.kt | 1 - .../container/repository/FollowerRepository.kt | 1 - .../container/repository/UserRepository.kt | 2 -- .../com/sopt/now/compose/network/AuthService.kt | 1 - .../sopt/now/compose/network/FollowService.kt | 1 - .../ui/navigation/ApplicationNavigation.kt | 4 ---- .../ui/navigation/NavigationDestination.kt | 1 - .../now/compose/ui/screens/home/HomeScreen.kt | 1 - .../compose/ui/screens/home/HomeViewModel.kt | 2 +- .../compose/ui/screens/login/LoginViewModel.kt | 2 -- .../compose/ui/screens/profile/ProfileScreen.kt | 2 -- .../compose/ui/screens/signup/SignUpScreen.kt | 1 - .../compose/ui/screens/signup/SignUpState.kt | 2 -- .../com/sopt/now/compose/ExampleUnitTest.kt | 3 +-- 18 files changed, 5 insertions(+), 49 deletions(-) diff --git a/app/src/androidTest/java/com/sopt/now/compose/ExampleInstrumentedTest.kt b/app/src/androidTest/java/com/sopt/now/compose/ExampleInstrumentedTest.kt index 72ca219..df74362 100644 --- a/app/src/androidTest/java/com/sopt/now/compose/ExampleInstrumentedTest.kt +++ b/app/src/androidTest/java/com/sopt/now/compose/ExampleInstrumentedTest.kt @@ -1,13 +1,11 @@ package com.sopt.now.compose -import androidx.test.platform.app.InstrumentationRegistry import androidx.test.ext.junit.runners.AndroidJUnit4 - +import androidx.test.platform.app.InstrumentationRegistry +import org.junit.Assert.assertEquals import org.junit.Test import org.junit.runner.RunWith -import org.junit.Assert.* - /** * Instrumented test, which will execute on an Android device. * diff --git a/app/src/main/java/com/sopt/now/compose/MainActivity.kt b/app/src/main/java/com/sopt/now/compose/MainActivity.kt index 3324d5a..581b114 100644 --- a/app/src/main/java/com/sopt/now/compose/MainActivity.kt +++ b/app/src/main/java/com/sopt/now/compose/MainActivity.kt @@ -1,32 +1,15 @@ package com.sopt.now.compose import android.content.Context -import android.os.Build import android.os.Bundle import android.widget.Toast import androidx.activity.ComponentActivity import androidx.activity.compose.setContent -import androidx.compose.foundation.Image -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.padding import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Surface -import androidx.compose.material3.Text -import androidx.compose.runtime.Composable -import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import androidx.compose.ui.res.painterResource -import androidx.compose.ui.res.stringResource -import androidx.compose.ui.text.font.FontWeight -import androidx.compose.ui.tooling.preview.Preview -import androidx.compose.ui.unit.dp -import androidx.compose.ui.unit.sp -import com.sopt.now.compose.models.User import com.sopt.now.compose.ui.SoptApp -import com.sopt.now.compose.ui.composables.TitleAndContentTextComposable import com.sopt.now.compose.ui.theme.NOWSOPTAndroidTheme class MainActivity : ComponentActivity() { diff --git a/app/src/main/java/com/sopt/now/compose/SoptApplication.kt b/app/src/main/java/com/sopt/now/compose/SoptApplication.kt index aeeadab..2f48d3e 100644 --- a/app/src/main/java/com/sopt/now/compose/SoptApplication.kt +++ b/app/src/main/java/com/sopt/now/compose/SoptApplication.kt @@ -1,8 +1,6 @@ package com.sopt.now.compose import android.app.Application -import android.content.Context -import android.widget.Toast import com.sopt.now.compose.container.AppContainer import com.sopt.now.compose.container.SoptAppContainer diff --git a/app/src/main/java/com/sopt/now/compose/container/SoptAppContainer.kt b/app/src/main/java/com/sopt/now/compose/container/SoptAppContainer.kt index df24a06..00996ba 100644 --- a/app/src/main/java/com/sopt/now/compose/container/SoptAppContainer.kt +++ b/app/src/main/java/com/sopt/now/compose/container/SoptAppContainer.kt @@ -3,13 +3,12 @@ package com.sopt.now.compose.container import android.content.Context import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory import com.sopt.now.compose.BuildConfig -import com.sopt.now.compose.container.impl.UserRepositoryImpl.Companion.USER_ID_KEY import com.sopt.now.compose.container.impl.AuthRepositoryImpl import com.sopt.now.compose.container.impl.FollowerRepositoryImpl import com.sopt.now.compose.container.impl.MemberRepositoryImpl import com.sopt.now.compose.container.impl.UserRepositoryImpl -import com.sopt.now.compose.network.FollowService import com.sopt.now.compose.network.AuthService +import com.sopt.now.compose.network.FollowService import kotlinx.serialization.json.Json import okhttp3.Interceptor import okhttp3.MediaType.Companion.toMediaType @@ -17,8 +16,6 @@ import okhttp3.OkHttpClient import retrofit2.Retrofit - - class SoptAppContainer(context: Context): AppContainer { override val userRepository: UserRepositoryImpl by lazy { diff --git a/app/src/main/java/com/sopt/now/compose/container/repository/AuthRepository.kt b/app/src/main/java/com/sopt/now/compose/container/repository/AuthRepository.kt index b997f17..ad1ab28 100644 --- a/app/src/main/java/com/sopt/now/compose/container/repository/AuthRepository.kt +++ b/app/src/main/java/com/sopt/now/compose/container/repository/AuthRepository.kt @@ -1,6 +1,5 @@ package com.sopt.now.compose.container.repository -import com.sopt.now.compose.network.AuthService import com.sopt.now.compose.network.dto.RequestLoginDto import com.sopt.now.compose.network.dto.RequestSignUpDto import com.sopt.now.compose.network.dto.ResponseLoginDto diff --git a/app/src/main/java/com/sopt/now/compose/container/repository/FollowerRepository.kt b/app/src/main/java/com/sopt/now/compose/container/repository/FollowerRepository.kt index 8230473..ccf5c68 100644 --- a/app/src/main/java/com/sopt/now/compose/container/repository/FollowerRepository.kt +++ b/app/src/main/java/com/sopt/now/compose/container/repository/FollowerRepository.kt @@ -1,6 +1,5 @@ package com.sopt.now.compose.container.repository -import com.sopt.now.compose.network.FollowService import com.sopt.now.compose.network.dto.ResponseFollowListDto import retrofit2.Response diff --git a/app/src/main/java/com/sopt/now/compose/container/repository/UserRepository.kt b/app/src/main/java/com/sopt/now/compose/container/repository/UserRepository.kt index 737bc77..b2dec37 100644 --- a/app/src/main/java/com/sopt/now/compose/container/repository/UserRepository.kt +++ b/app/src/main/java/com/sopt/now/compose/container/repository/UserRepository.kt @@ -1,7 +1,5 @@ package com.sopt.now.compose.container.repository -import android.content.SharedPreferences -import android.util.Log import com.sopt.now.compose.models.User interface UserRepository { diff --git a/app/src/main/java/com/sopt/now/compose/network/AuthService.kt b/app/src/main/java/com/sopt/now/compose/network/AuthService.kt index 09496b2..a96b30c 100644 --- a/app/src/main/java/com/sopt/now/compose/network/AuthService.kt +++ b/app/src/main/java/com/sopt/now/compose/network/AuthService.kt @@ -7,7 +7,6 @@ import com.sopt.now.compose.network.dto.ResponseChangePasswordDto import com.sopt.now.compose.network.dto.ResponseLoginDto import com.sopt.now.compose.network.dto.ResponseMemberInfoDto import com.sopt.now.compose.network.dto.ResponseSignUpDto -import retrofit2.Call import retrofit2.Response import retrofit2.http.Body import retrofit2.http.GET diff --git a/app/src/main/java/com/sopt/now/compose/network/FollowService.kt b/app/src/main/java/com/sopt/now/compose/network/FollowService.kt index 97aed9d..374ceb0 100644 --- a/app/src/main/java/com/sopt/now/compose/network/FollowService.kt +++ b/app/src/main/java/com/sopt/now/compose/network/FollowService.kt @@ -1,7 +1,6 @@ package com.sopt.now.compose.network import com.sopt.now.compose.network.dto.ResponseFollowListDto -import retrofit2.Call import retrofit2.Response import retrofit2.http.GET import retrofit2.http.Query diff --git a/app/src/main/java/com/sopt/now/compose/ui/navigation/ApplicationNavigation.kt b/app/src/main/java/com/sopt/now/compose/ui/navigation/ApplicationNavigation.kt index 28b2fbc..59e1b01 100644 --- a/app/src/main/java/com/sopt/now/compose/ui/navigation/ApplicationNavigation.kt +++ b/app/src/main/java/com/sopt/now/compose/ui/navigation/ApplicationNavigation.kt @@ -2,15 +2,11 @@ package com.sopt.now.compose.ui.navigation import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier -import androidx.lifecycle.viewmodel.compose.viewModel import androidx.navigation.NavHostController -import androidx.navigation.NavType import androidx.navigation.compose.NavHost import androidx.navigation.compose.composable -import androidx.navigation.navArgument import com.sopt.now.compose.ui.screens.home.HomeScreen import com.sopt.now.compose.ui.screens.login.LoginScreen -import com.sopt.now.compose.ui.screens.login.LoginViewModel import com.sopt.now.compose.ui.screens.profile.ProfileScreen import com.sopt.now.compose.ui.screens.search.SearchScreen import com.sopt.now.compose.ui.screens.signup.SignUpScreen diff --git a/app/src/main/java/com/sopt/now/compose/ui/navigation/NavigationDestination.kt b/app/src/main/java/com/sopt/now/compose/ui/navigation/NavigationDestination.kt index d0f431e..9490881 100644 --- a/app/src/main/java/com/sopt/now/compose/ui/navigation/NavigationDestination.kt +++ b/app/src/main/java/com/sopt/now/compose/ui/navigation/NavigationDestination.kt @@ -1,6 +1,5 @@ package com.sopt.now.compose.ui.navigation -import androidx.annotation.StringRes import androidx.compose.ui.graphics.vector.ImageVector interface NavigationDestination { diff --git a/app/src/main/java/com/sopt/now/compose/ui/screens/home/HomeScreen.kt b/app/src/main/java/com/sopt/now/compose/ui/screens/home/HomeScreen.kt index a340dd8..bdef6e0 100644 --- a/app/src/main/java/com/sopt/now/compose/ui/screens/home/HomeScreen.kt +++ b/app/src/main/java/com/sopt/now/compose/ui/screens/home/HomeScreen.kt @@ -17,7 +17,6 @@ import androidx.compose.material3.Scaffold import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect -import androidx.compose.runtime.collectAsState import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip diff --git a/app/src/main/java/com/sopt/now/compose/ui/screens/home/HomeViewModel.kt b/app/src/main/java/com/sopt/now/compose/ui/screens/home/HomeViewModel.kt index 9c62fbe..1c21a0d 100644 --- a/app/src/main/java/com/sopt/now/compose/ui/screens/home/HomeViewModel.kt +++ b/app/src/main/java/com/sopt/now/compose/ui/screens/home/HomeViewModel.kt @@ -7,8 +7,8 @@ import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewmodel.initializer import androidx.lifecycle.viewmodel.viewModelFactory import com.sopt.now.compose.SoptApplication -import com.sopt.now.compose.container.repository.FollowerRepository import com.sopt.now.compose.container.impl.MemberRepositoryImpl +import com.sopt.now.compose.container.repository.FollowerRepository import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow diff --git a/app/src/main/java/com/sopt/now/compose/ui/screens/login/LoginViewModel.kt b/app/src/main/java/com/sopt/now/compose/ui/screens/login/LoginViewModel.kt index d44691e..590fd56 100644 --- a/app/src/main/java/com/sopt/now/compose/ui/screens/login/LoginViewModel.kt +++ b/app/src/main/java/com/sopt/now/compose/ui/screens/login/LoginViewModel.kt @@ -7,8 +7,6 @@ import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewmodel.initializer import androidx.lifecycle.viewmodel.viewModelFactory import com.sopt.now.compose.SoptApplication -import com.sopt.now.compose.container.impl.AuthRepositoryImpl -import com.sopt.now.compose.container.impl.UserRepositoryImpl import com.sopt.now.compose.container.repository.AuthRepository import com.sopt.now.compose.container.repository.UserRepository import com.sopt.now.compose.network.dto.RequestLoginDto diff --git a/app/src/main/java/com/sopt/now/compose/ui/screens/profile/ProfileScreen.kt b/app/src/main/java/com/sopt/now/compose/ui/screens/profile/ProfileScreen.kt index fbbc1b5..0c57e3d 100644 --- a/app/src/main/java/com/sopt/now/compose/ui/screens/profile/ProfileScreen.kt +++ b/app/src/main/java/com/sopt/now/compose/ui/screens/profile/ProfileScreen.kt @@ -11,7 +11,6 @@ import androidx.compose.material3.Scaffold import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect -import androidx.compose.runtime.collectAsState import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.painterResource @@ -25,7 +24,6 @@ import androidx.navigation.compose.rememberNavController import com.sopt.now.compose.MainActivity import com.sopt.now.compose.MainActivity.Companion.NAVIGATE_BACK_PRESSED_KEY import com.sopt.now.compose.R -import com.sopt.now.compose.models.User import com.sopt.now.compose.ui.SoptBottomNavigation import com.sopt.now.compose.ui.composables.ButtonComposable import com.sopt.now.compose.ui.composables.ScreenWithImage diff --git a/app/src/main/java/com/sopt/now/compose/ui/screens/signup/SignUpScreen.kt b/app/src/main/java/com/sopt/now/compose/ui/screens/signup/SignUpScreen.kt index c1d8eaf..b31b541 100644 --- a/app/src/main/java/com/sopt/now/compose/ui/screens/signup/SignUpScreen.kt +++ b/app/src/main/java/com/sopt/now/compose/ui/screens/signup/SignUpScreen.kt @@ -8,7 +8,6 @@ import androidx.compose.foundation.layout.padding import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect -import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier diff --git a/app/src/main/java/com/sopt/now/compose/ui/screens/signup/SignUpState.kt b/app/src/main/java/com/sopt/now/compose/ui/screens/signup/SignUpState.kt index 7fa9846..78c440f 100644 --- a/app/src/main/java/com/sopt/now/compose/ui/screens/signup/SignUpState.kt +++ b/app/src/main/java/com/sopt/now/compose/ui/screens/signup/SignUpState.kt @@ -1,7 +1,5 @@ package com.sopt.now.compose.ui.screens.signup -import com.sopt.now.compose.models.User - data class SignUpState( val isSuccess: Boolean = false, val message: String = "", diff --git a/app/src/test/java/com/sopt/now/compose/ExampleUnitTest.kt b/app/src/test/java/com/sopt/now/compose/ExampleUnitTest.kt index 87e6766..178278c 100644 --- a/app/src/test/java/com/sopt/now/compose/ExampleUnitTest.kt +++ b/app/src/test/java/com/sopt/now/compose/ExampleUnitTest.kt @@ -1,9 +1,8 @@ package com.sopt.now.compose +import org.junit.Assert.assertEquals import org.junit.Test -import org.junit.Assert.* - /** * Example local unit test, which will execute on the development machine (host). * From 3066e974e2d2a50c17e9bebbc156e87f63066107 Mon Sep 17 00:00:00 2001 From: boiledegg Date: Fri, 7 Jun 2024 17:17:54 +0900 Subject: [PATCH 06/31] =?UTF-8?q?CHORE/#19:=20lifecycleowner=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/sopt/now/compose/ui/screens/home/HomeScreen.kt | 3 ++- .../java/com/sopt/now/compose/ui/screens/login/LoginScreen.kt | 3 ++- .../com/sopt/now/compose/ui/screens/profile/ProfileScreen.kt | 3 ++- .../com/sopt/now/compose/ui/screens/signup/SignUpScreen.kt | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/sopt/now/compose/ui/screens/home/HomeScreen.kt b/app/src/main/java/com/sopt/now/compose/ui/screens/home/HomeScreen.kt index bdef6e0..6c63e25 100644 --- a/app/src/main/java/com/sopt/now/compose/ui/screens/home/HomeScreen.kt +++ b/app/src/main/java/com/sopt/now/compose/ui/screens/home/HomeScreen.kt @@ -23,6 +23,7 @@ import androidx.compose.ui.draw.clip import androidx.compose.ui.graphics.Color import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.platform.LocalLifecycleOwner import androidx.compose.ui.res.painterResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.tooling.preview.Preview @@ -65,7 +66,7 @@ fun HomeScreen( Scaffold( bottomBar = { SoptBottomNavigation(navController = navController) } ) { paddingValue -> - when (val uiState = viewModel.uiState.collectAsStateWithLifecycle().value) { + when (val uiState = viewModel.uiState.collectAsStateWithLifecycle(LocalLifecycleOwner.current).value) { is HomeUiState.Success -> { HomeScreen( uiState = uiState, diff --git a/app/src/main/java/com/sopt/now/compose/ui/screens/login/LoginScreen.kt b/app/src/main/java/com/sopt/now/compose/ui/screens/login/LoginScreen.kt index 5b23794..daf15af 100644 --- a/app/src/main/java/com/sopt/now/compose/ui/screens/login/LoginScreen.kt +++ b/app/src/main/java/com/sopt/now/compose/ui/screens/login/LoginScreen.kt @@ -17,6 +17,7 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.platform.LocalLifecycleOwner import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.text.input.KeyboardType @@ -40,7 +41,7 @@ fun LoginScreen( viewModel: LoginViewModel = viewModel(factory = LoginViewModel.Factory), ) { val context = LocalContext.current - val uiState by viewModel.uiState.collectAsStateWithLifecycle() + val uiState by viewModel.uiState.collectAsStateWithLifecycle(LocalLifecycleOwner.current) LaunchedEffect(uiState.message) { diff --git a/app/src/main/java/com/sopt/now/compose/ui/screens/profile/ProfileScreen.kt b/app/src/main/java/com/sopt/now/compose/ui/screens/profile/ProfileScreen.kt index 0c57e3d..1fafb39 100644 --- a/app/src/main/java/com/sopt/now/compose/ui/screens/profile/ProfileScreen.kt +++ b/app/src/main/java/com/sopt/now/compose/ui/screens/profile/ProfileScreen.kt @@ -13,6 +13,7 @@ import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalLifecycleOwner import androidx.compose.ui.res.painterResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.dp @@ -54,7 +55,7 @@ fun ProfileScreen( Scaffold( bottomBar = { SoptBottomNavigation(navController = navController) } ) { paddingValue -> - when (val uiState = viewModel.uiState.collectAsStateWithLifecycle().value) { + when (val uiState = viewModel.uiState.collectAsStateWithLifecycle(LocalLifecycleOwner.current).value) { is ProfileUiState.Success -> { ProfileScreen( uiState = uiState, diff --git a/app/src/main/java/com/sopt/now/compose/ui/screens/signup/SignUpScreen.kt b/app/src/main/java/com/sopt/now/compose/ui/screens/signup/SignUpScreen.kt index b31b541..d46b804 100644 --- a/app/src/main/java/com/sopt/now/compose/ui/screens/signup/SignUpScreen.kt +++ b/app/src/main/java/com/sopt/now/compose/ui/screens/signup/SignUpScreen.kt @@ -13,6 +13,7 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.platform.LocalLifecycleOwner import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.tooling.preview.Preview @@ -34,7 +35,7 @@ fun SignUpScreen( ) { val context = LocalContext.current - val uiState by viewModel.uiState.collectAsStateWithLifecycle() + val uiState by viewModel.uiState.collectAsStateWithLifecycle(LocalLifecycleOwner.current) LaunchedEffect(uiState.message) { if(uiState.message.isNotEmpty()){ if(uiState.isSuccess) { From 26fdc3afded9c9ef6ffd62ad040ec289c5cee939 Mon Sep 17 00:00:00 2001 From: boiledegg Date: Tue, 25 Jun 2024 15:36:08 +0900 Subject: [PATCH 07/31] =?UTF-8?q?ADD/#21:=20Hilt=20=EB=9D=BC=EC=9D=B4?= =?UTF-8?q?=EB=B8=8C=EB=9F=AC=EB=A6=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 7 +++++++ build.gradle | 5 +++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 1853774..bdc1d22 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -2,6 +2,9 @@ plugins { id 'com.android.application' id 'org.jetbrains.kotlin.android' id 'org.jetbrains.kotlin.plugin.serialization' version '1.9.0' + id 'com.google.dagger.hilt.android' + id 'kotlin-android' + id 'kotlin-kapt' } Properties properties = new Properties() @@ -89,6 +92,10 @@ dependencies { // Coil implementation("io.coil-kt:coil-compose:2.6.0") + //Dagger & Hilt + implementation 'com.google.dagger:hilt-android:2.51' + kapt 'com.google.dagger:hilt-compiler:2.51.1' + implementation ("androidx.lifecycle:lifecycle-runtime-compose:2.8.1") } \ No newline at end of file diff --git a/build.gradle b/build.gradle index be6601c..bce5569 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,7 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. plugins { - id 'com.android.application' version '8.3.1' apply false - id 'com.android.library' version '8.3.1' apply false + id 'com.android.application' version '8.3.2' apply false + id 'com.android.library' version '8.3.2' apply false id 'org.jetbrains.kotlin.android' version '1.9.0' apply false + id 'com.google.dagger.hilt.android' version '2.51' apply false } \ No newline at end of file From f006e2e6fef9cd54a7bb9e60e9da87899d007312 Mon Sep 17 00:00:00 2001 From: boiledegg Date: Wed, 26 Jun 2024 14:22:57 +0900 Subject: [PATCH 08/31] =?UTF-8?q?CHORE/#21=20CHORE/#21:=20URL=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/build.gradle b/app/build.gradle index bdc1d22..2ec19e2 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -27,6 +27,8 @@ android { } buildConfigField "String", "AUTH_BASE_URL", properties["base.url"] + buildConfigField "String", "REQRES_URL", properties["reqres.url"] + } buildTypes { From 56e4345dcda6c1030218b6cf9159e915c929c788 Mon Sep 17 00:00:00 2001 From: boiledegg Date: Wed, 26 Jun 2024 14:24:24 +0900 Subject: [PATCH 09/31] =?UTF-8?q?FEAT/#21:=20Hilt=20Module=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/sopt/now/compose/MainActivity.kt | 2 + .../com/sopt/now/compose/SoptApplication.kt | 2 + .../java/com/sopt/now/compose/di/ApiModule.kt | 76 +++++++++++++++++++ .../sopt/now/compose/di/HeaderInterceptor.kt | 24 ++++++ .../sopt/now/compose/di/RepositoryModule.kt | 36 +++++++++ .../com/sopt/now/compose/di/ServiceModule.kt | 35 +++++++++ .../now/compose/di/SharedPreferenceModule.kt | 15 ++++ .../compose/di/qualifier/RetrofitQualifier.kt | 15 ++++ .../sopt/now/compose/network/HomeService.kt | 24 ++++++ 9 files changed, 229 insertions(+) create mode 100644 app/src/main/java/com/sopt/now/compose/di/ApiModule.kt create mode 100644 app/src/main/java/com/sopt/now/compose/di/HeaderInterceptor.kt create mode 100644 app/src/main/java/com/sopt/now/compose/di/RepositoryModule.kt create mode 100644 app/src/main/java/com/sopt/now/compose/di/ServiceModule.kt create mode 100644 app/src/main/java/com/sopt/now/compose/di/SharedPreferenceModule.kt create mode 100644 app/src/main/java/com/sopt/now/compose/di/qualifier/RetrofitQualifier.kt create mode 100644 app/src/main/java/com/sopt/now/compose/network/HomeService.kt diff --git a/app/src/main/java/com/sopt/now/compose/MainActivity.kt b/app/src/main/java/com/sopt/now/compose/MainActivity.kt index 581b114..dc28a68 100644 --- a/app/src/main/java/com/sopt/now/compose/MainActivity.kt +++ b/app/src/main/java/com/sopt/now/compose/MainActivity.kt @@ -11,7 +11,9 @@ import androidx.compose.material3.Surface import androidx.compose.ui.Modifier import com.sopt.now.compose.ui.SoptApp import com.sopt.now.compose.ui.theme.NOWSOPTAndroidTheme +import dagger.hilt.android.AndroidEntryPoint +@AndroidEntryPoint class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) diff --git a/app/src/main/java/com/sopt/now/compose/SoptApplication.kt b/app/src/main/java/com/sopt/now/compose/SoptApplication.kt index 2f48d3e..8997e8f 100644 --- a/app/src/main/java/com/sopt/now/compose/SoptApplication.kt +++ b/app/src/main/java/com/sopt/now/compose/SoptApplication.kt @@ -3,7 +3,9 @@ package com.sopt.now.compose import android.app.Application import com.sopt.now.compose.container.AppContainer import com.sopt.now.compose.container.SoptAppContainer +import dagger.hilt.android.HiltAndroidApp +@HiltAndroidApp class SoptApplication: Application() { lateinit var appContainer: AppContainer diff --git a/app/src/main/java/com/sopt/now/compose/di/ApiModule.kt b/app/src/main/java/com/sopt/now/compose/di/ApiModule.kt new file mode 100644 index 0000000..a7a0310 --- /dev/null +++ b/app/src/main/java/com/sopt/now/compose/di/ApiModule.kt @@ -0,0 +1,76 @@ +package com.sopt.now.compose.di + +import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory +import com.sopt.now.compose.BuildConfig +import com.sopt.now.compose.di.qualifier.AUTH +import com.sopt.now.compose.di.qualifier.HEADER +import com.sopt.now.compose.di.qualifier.REQRES +import dagger.Module +import dagger.Provides +import dagger.hilt.InstallIn +import dagger.hilt.components.SingletonComponent +import kotlinx.serialization.json.Json +import okhttp3.Interceptor +import okhttp3.MediaType.Companion.toMediaType +import okhttp3.OkHttpClient +import retrofit2.Converter +import retrofit2.Retrofit +import javax.inject.Singleton + +@Module +@InstallIn(SingletonComponent::class) +object ApiModule { + private const val CONTENT_TYPE = "application/json" + + @Singleton + @Provides + fun provideJsonConverter(): Converter.Factory { + return Json.asConverterFactory(CONTENT_TYPE.toMediaType()) + } + + @Singleton + @Provides + @HEADER + fun provideHeaderOkHttpClient( + headerInterceptor: HeaderInterceptor + ): OkHttpClient = OkHttpClient.Builder() + .addInterceptor(headerInterceptor) + .build() + + @Singleton + @Provides + @AUTH + fun provideAuthRetrofit( + converter: Converter.Factory + ): Retrofit { + return Retrofit.Builder() + .baseUrl(BuildConfig.AUTH_BASE_URL) + .addConverterFactory(converter) + .build() + } + + @Singleton + @Provides + @HEADER + fun provideHeaderRetrofit( + client: OkHttpClient, + converter: Converter.Factory + ): Retrofit = Retrofit.Builder() + .baseUrl(BuildConfig.AUTH_BASE_URL) + .addConverterFactory(converter) + .client(client) + .build() + + @Singleton + @Provides + @REQRES + fun provideReqresRetrofit( + converter: Converter.Factory + ): Retrofit { + return Retrofit.Builder() + .baseUrl(BuildConfig.AUTH_BASE_URL) + .addConverterFactory(converter) + .build() + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/compose/di/HeaderInterceptor.kt b/app/src/main/java/com/sopt/now/compose/di/HeaderInterceptor.kt new file mode 100644 index 0000000..812828d --- /dev/null +++ b/app/src/main/java/com/sopt/now/compose/di/HeaderInterceptor.kt @@ -0,0 +1,24 @@ +package com.sopt.now.compose.di + +import android.content.SharedPreferences +import okhttp3.Interceptor +import okhttp3.OkHttpClient +import okhttp3.Response +import javax.inject.Inject + +class HeaderInterceptor @Inject constructor( + private val sharedPreferences: SharedPreferences +): Interceptor { + override fun intercept(chain: Interceptor.Chain): Response { + val request = chain.request().newBuilder().addHeader( + name = MEMBER_ID, + value = sharedPreferences.getString(MEMBER_ID, DEFAULT_VALUE).orEmpty() + ).build() + return chain.proceed(request) + } + + companion object { + const val MEMBER_ID = "memberId" + const val DEFAULT_VALUE = "" + } +} diff --git a/app/src/main/java/com/sopt/now/compose/di/RepositoryModule.kt b/app/src/main/java/com/sopt/now/compose/di/RepositoryModule.kt new file mode 100644 index 0000000..129df8a --- /dev/null +++ b/app/src/main/java/com/sopt/now/compose/di/RepositoryModule.kt @@ -0,0 +1,36 @@ +package com.sopt.now.compose.di + +import com.sopt.now.compose.container.impl.AuthRepositoryImpl +import com.sopt.now.compose.container.impl.FollowerRepositoryImpl +import com.sopt.now.compose.container.impl.MemberRepositoryImpl +import com.sopt.now.compose.container.impl.UserRepositoryImpl +import com.sopt.now.compose.container.repository.AuthRepository +import com.sopt.now.compose.container.repository.FollowerRepository +import com.sopt.now.compose.container.repository.MemberRepository +import com.sopt.now.compose.container.repository.UserRepository +import dagger.Binds +import dagger.Module +import dagger.hilt.InstallIn +import dagger.hilt.components.SingletonComponent +import javax.inject.Singleton + +@Module +@InstallIn(SingletonComponent::class) +abstract class RepositoryModule { + + @Binds + @Singleton + abstract fun bindAuthRepository(authRepositoryImpl: AuthRepositoryImpl): AuthRepository + + @Binds + @Singleton + abstract fun bindFollowRepository(followerRepositoryImpl: FollowerRepositoryImpl): FollowerRepository + + @Binds + @Singleton + abstract fun bindMemberRepository(memberRepositoryImpl: MemberRepositoryImpl): MemberRepository + + @Binds + @Singleton + abstract fun bindUserRepository(userRepositoryImpl: UserRepositoryImpl): UserRepository +} \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/compose/di/ServiceModule.kt b/app/src/main/java/com/sopt/now/compose/di/ServiceModule.kt new file mode 100644 index 0000000..1ccf127 --- /dev/null +++ b/app/src/main/java/com/sopt/now/compose/di/ServiceModule.kt @@ -0,0 +1,35 @@ +package com.sopt.now.compose.di + +import com.sopt.now.compose.di.qualifier.AUTH +import com.sopt.now.compose.di.qualifier.HEADER +import com.sopt.now.compose.di.qualifier.REQRES +import com.sopt.now.compose.network.AuthService +import com.sopt.now.compose.network.FollowService +import com.sopt.now.compose.network.HomeService +import dagger.Module +import dagger.Provides +import dagger.hilt.InstallIn +import dagger.hilt.components.SingletonComponent +import retrofit2.Retrofit +import javax.inject.Singleton + +@Module +@InstallIn(SingletonComponent::class) +object ServiceModule { + + @Provides + @Singleton + fun provideAuthService(@AUTH retrofit: Retrofit): AuthService = + retrofit.create(AuthService::class.java) + + @Provides + @Singleton + fun provideHomeService(@HEADER retrofit: Retrofit): HomeService = + retrofit.create(HomeService::class.java) + + @Provides + @Singleton + fun provideReqresService(@REQRES retrofit: Retrofit): FollowService = + retrofit.create(FollowService::class.java) + +} \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/compose/di/SharedPreferenceModule.kt b/app/src/main/java/com/sopt/now/compose/di/SharedPreferenceModule.kt new file mode 100644 index 0000000..4daa59e --- /dev/null +++ b/app/src/main/java/com/sopt/now/compose/di/SharedPreferenceModule.kt @@ -0,0 +1,15 @@ +package com.sopt.now.compose.di + +import android.content.Context +import android.content.SharedPreferences +import dagger.Module +import dagger.hilt.InstallIn +import dagger.hilt.android.qualifiers.ApplicationContext +import dagger.hilt.components.SingletonComponent + +@Module +@InstallIn(SingletonComponent::class) +object SharedPreferenceModule { + fun provideSharedPreference(@ApplicationContext context: Context): SharedPreferences = + context.getSharedPreferences(context.packageName, Context.MODE_PRIVATE) +} \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/compose/di/qualifier/RetrofitQualifier.kt b/app/src/main/java/com/sopt/now/compose/di/qualifier/RetrofitQualifier.kt new file mode 100644 index 0000000..bfab237 --- /dev/null +++ b/app/src/main/java/com/sopt/now/compose/di/qualifier/RetrofitQualifier.kt @@ -0,0 +1,15 @@ +package com.sopt.now.compose.di.qualifier + +import javax.inject.Qualifier + +@Qualifier +@Retention(AnnotationRetention.BINARY) +annotation class AUTH + +@Qualifier +@Retention(AnnotationRetention.BINARY) +annotation class HEADER + +@Qualifier +@Retention(AnnotationRetention.BINARY) +annotation class REQRES diff --git a/app/src/main/java/com/sopt/now/compose/network/HomeService.kt b/app/src/main/java/com/sopt/now/compose/network/HomeService.kt new file mode 100644 index 0000000..1d45eae --- /dev/null +++ b/app/src/main/java/com/sopt/now/compose/network/HomeService.kt @@ -0,0 +1,24 @@ +package com.sopt.now.compose.network + +import com.sopt.now.compose.network.dto.RequestChangePasswordDto +import com.sopt.now.compose.network.dto.RequestLoginDto +import com.sopt.now.compose.network.dto.RequestSignUpDto +import com.sopt.now.compose.network.dto.ResponseChangePasswordDto +import com.sopt.now.compose.network.dto.ResponseLoginDto +import com.sopt.now.compose.network.dto.ResponseMemberInfoDto +import com.sopt.now.compose.network.dto.ResponseSignUpDto +import retrofit2.Response +import retrofit2.http.Body +import retrofit2.http.GET +import retrofit2.http.PATCH +import retrofit2.http.POST + +interface HomeService { + @GET("member/info") + suspend fun getMemberInfo(): Response + + @PATCH("member/password") + suspend fun changePassword( + @Body request: RequestChangePasswordDto + ): Response +} \ No newline at end of file From 5f092918902c26e4bca35c9332abd8f666cd759b Mon Sep 17 00:00:00 2001 From: boiledegg Date: Wed, 26 Jun 2024 14:26:24 +0900 Subject: [PATCH 10/31] =?UTF-8?q?DEL/#21:=20Import=20=EC=A0=95=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/sopt/now/compose/di/ApiModule.kt | 1 - app/src/main/java/com/sopt/now/compose/di/HeaderInterceptor.kt | 1 - 2 files changed, 2 deletions(-) diff --git a/app/src/main/java/com/sopt/now/compose/di/ApiModule.kt b/app/src/main/java/com/sopt/now/compose/di/ApiModule.kt index a7a0310..b593d02 100644 --- a/app/src/main/java/com/sopt/now/compose/di/ApiModule.kt +++ b/app/src/main/java/com/sopt/now/compose/di/ApiModule.kt @@ -10,7 +10,6 @@ import dagger.Provides import dagger.hilt.InstallIn import dagger.hilt.components.SingletonComponent import kotlinx.serialization.json.Json -import okhttp3.Interceptor import okhttp3.MediaType.Companion.toMediaType import okhttp3.OkHttpClient import retrofit2.Converter diff --git a/app/src/main/java/com/sopt/now/compose/di/HeaderInterceptor.kt b/app/src/main/java/com/sopt/now/compose/di/HeaderInterceptor.kt index 812828d..d48a737 100644 --- a/app/src/main/java/com/sopt/now/compose/di/HeaderInterceptor.kt +++ b/app/src/main/java/com/sopt/now/compose/di/HeaderInterceptor.kt @@ -2,7 +2,6 @@ package com.sopt.now.compose.di import android.content.SharedPreferences import okhttp3.Interceptor -import okhttp3.OkHttpClient import okhttp3.Response import javax.inject.Inject From 66b07601c27922cc802fa9f03fd8f11149f4504e Mon Sep 17 00:00:00 2001 From: boiledegg Date: Wed, 26 Jun 2024 15:00:47 +0900 Subject: [PATCH 11/31] =?UTF-8?q?ADD/#21:=20Hilt=20=EB=9D=BC=EC=9D=B4?= =?UTF-8?q?=EB=B8=8C=EB=9F=AC=EB=A6=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/app/build.gradle b/app/build.gradle index 2ec19e2..ae5209d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -97,6 +97,7 @@ dependencies { //Dagger & Hilt implementation 'com.google.dagger:hilt-android:2.51' kapt 'com.google.dagger:hilt-compiler:2.51.1' + implementation 'androidx.hilt:hilt-navigation-compose:1.2.0' implementation ("androidx.lifecycle:lifecycle-runtime-compose:2.8.1") From 02cb1aeb40fbc484b73d63a61e6c72e12f5e8ebe Mon Sep 17 00:00:00 2001 From: boiledegg Date: Wed, 26 Jun 2024 15:04:31 +0900 Subject: [PATCH 12/31] =?UTF-8?q?CHORE/#21:=20=EB=A1=9C=EC=BB=AC=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=84=B0=EB=B2=A0=EC=9D=B4=EC=8A=A4=20=EB=AA=A8?= =?UTF-8?q?=EB=93=88=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/sopt/now/compose/di/SharedPreferenceModule.kt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/src/main/java/com/sopt/now/compose/di/SharedPreferenceModule.kt b/app/src/main/java/com/sopt/now/compose/di/SharedPreferenceModule.kt index 4daa59e..5b347ca 100644 --- a/app/src/main/java/com/sopt/now/compose/di/SharedPreferenceModule.kt +++ b/app/src/main/java/com/sopt/now/compose/di/SharedPreferenceModule.kt @@ -3,13 +3,18 @@ package com.sopt.now.compose.di import android.content.Context import android.content.SharedPreferences import dagger.Module +import dagger.Provides import dagger.hilt.InstallIn import dagger.hilt.android.qualifiers.ApplicationContext import dagger.hilt.components.SingletonComponent +import javax.inject.Singleton @Module @InstallIn(SingletonComponent::class) object SharedPreferenceModule { + + @Provides + @Singleton fun provideSharedPreference(@ApplicationContext context: Context): SharedPreferences = context.getSharedPreferences(context.packageName, Context.MODE_PRIVATE) } \ No newline at end of file From 71894618440fc0c4ed32223fb096d05768afb6ba Mon Sep 17 00:00:00 2001 From: boiledegg Date: Wed, 26 Jun 2024 15:05:46 +0900 Subject: [PATCH 13/31] =?UTF-8?q?FEAT/#21:=20=EB=A0=88=ED=8F=AC=EC=A7=80?= =?UTF-8?q?=ED=86=A0=EB=A6=AC=20=EC=83=9D=EC=84=B1=EC=9E=90=20=EC=A3=BC?= =?UTF-8?q?=EC=9E=85=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/sopt/now/compose/container/impl/AuthRepositoryImpl.kt | 3 ++- .../sopt/now/compose/container/impl/FollowerRepositoryImpl.kt | 3 ++- .../sopt/now/compose/container/impl/MemberRepositoryImpl.kt | 3 ++- .../com/sopt/now/compose/container/impl/UserRepositoryImpl.kt | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/sopt/now/compose/container/impl/AuthRepositoryImpl.kt b/app/src/main/java/com/sopt/now/compose/container/impl/AuthRepositoryImpl.kt index 6420171..8d9a77f 100644 --- a/app/src/main/java/com/sopt/now/compose/container/impl/AuthRepositoryImpl.kt +++ b/app/src/main/java/com/sopt/now/compose/container/impl/AuthRepositoryImpl.kt @@ -7,8 +7,9 @@ import com.sopt.now.compose.network.dto.RequestSignUpDto import com.sopt.now.compose.network.dto.ResponseLoginDto import com.sopt.now.compose.network.dto.ResponseSignUpDto import retrofit2.Response +import javax.inject.Inject -class AuthRepositoryImpl( +class AuthRepositoryImpl @Inject constructor( private val authService: AuthService ) : AuthRepository { override suspend fun postLogin(request: RequestLoginDto): Result> = diff --git a/app/src/main/java/com/sopt/now/compose/container/impl/FollowerRepositoryImpl.kt b/app/src/main/java/com/sopt/now/compose/container/impl/FollowerRepositoryImpl.kt index 2cecddc..a5cb0de 100644 --- a/app/src/main/java/com/sopt/now/compose/container/impl/FollowerRepositoryImpl.kt +++ b/app/src/main/java/com/sopt/now/compose/container/impl/FollowerRepositoryImpl.kt @@ -4,8 +4,9 @@ import com.sopt.now.compose.container.repository.FollowerRepository import com.sopt.now.compose.network.FollowService import com.sopt.now.compose.network.dto.ResponseFollowListDto import retrofit2.Response +import javax.inject.Inject -class FollowerRepositoryImpl( +class FollowerRepositoryImpl @Inject constructor( private val followService: FollowService ): FollowerRepository { override suspend fun getFollowers(page: Int): Result> = runCatching { diff --git a/app/src/main/java/com/sopt/now/compose/container/impl/MemberRepositoryImpl.kt b/app/src/main/java/com/sopt/now/compose/container/impl/MemberRepositoryImpl.kt index 12bceeb..d216103 100644 --- a/app/src/main/java/com/sopt/now/compose/container/impl/MemberRepositoryImpl.kt +++ b/app/src/main/java/com/sopt/now/compose/container/impl/MemberRepositoryImpl.kt @@ -6,8 +6,9 @@ import com.sopt.now.compose.network.AuthService import com.sopt.now.compose.network.dto.RequestChangePasswordDto import com.sopt.now.compose.network.dto.ResponseChangePasswordDto import retrofit2.Response +import javax.inject.Inject -class MemberRepositoryImpl( +class MemberRepositoryImpl @Inject constructor( private val authService: AuthService ) : MemberRepository { override suspend fun getUserInfo(): Result = runCatching { diff --git a/app/src/main/java/com/sopt/now/compose/container/impl/UserRepositoryImpl.kt b/app/src/main/java/com/sopt/now/compose/container/impl/UserRepositoryImpl.kt index 9b80b36..b9927b4 100644 --- a/app/src/main/java/com/sopt/now/compose/container/impl/UserRepositoryImpl.kt +++ b/app/src/main/java/com/sopt/now/compose/container/impl/UserRepositoryImpl.kt @@ -3,8 +3,9 @@ package com.sopt.now.compose.container.impl import android.content.SharedPreferences import com.sopt.now.compose.container.repository.UserRepository import com.sopt.now.compose.models.User +import javax.inject.Inject -class UserRepositoryImpl( +class UserRepositoryImpl @Inject constructor( private val sharedPreferences: SharedPreferences ) : UserRepository { override fun getUserProfile(): User { From ccb9c47448a06fe083f2584e8ac3271652a2ce46 Mon Sep 17 00:00:00 2001 From: boiledegg Date: Wed, 26 Jun 2024 15:06:07 +0900 Subject: [PATCH 14/31] =?UTF-8?q?FEAT/#21:=20=EB=B7=B0=EB=AA=A8=EB=8D=B8?= =?UTF-8?q?=20=EC=9E=90=EB=8F=99=20=EC=83=9D=EC=84=B1=EC=9E=90=20=EC=A3=BC?= =?UTF-8?q?=EC=9E=85=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../compose/ui/screens/home/HomeViewModel.kt | 23 +++++-------------- .../ui/screens/login/LoginViewModel.kt | 14 ++++------- .../ui/screens/profile/ProfileViewModel.kt | 13 ++++------- .../ui/screens/signup/SignUpViewModel.kt | 16 ++++--------- 4 files changed, 18 insertions(+), 48 deletions(-) diff --git a/app/src/main/java/com/sopt/now/compose/ui/screens/home/HomeViewModel.kt b/app/src/main/java/com/sopt/now/compose/ui/screens/home/HomeViewModel.kt index 1c21a0d..ae46b2c 100644 --- a/app/src/main/java/com/sopt/now/compose/ui/screens/home/HomeViewModel.kt +++ b/app/src/main/java/com/sopt/now/compose/ui/screens/home/HomeViewModel.kt @@ -9,16 +9,20 @@ import androidx.lifecycle.viewmodel.viewModelFactory import com.sopt.now.compose.SoptApplication import com.sopt.now.compose.container.impl.MemberRepositoryImpl import com.sopt.now.compose.container.repository.FollowerRepository +import com.sopt.now.compose.container.repository.MemberRepository +import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.launch +import javax.inject.Inject private const val TAG = "HomeViewModel" -class HomeViewModel( +@HiltViewModel +class HomeViewModel @Inject constructor( private val followerRepository: FollowerRepository, - private val authRepository: MemberRepositoryImpl + private val authRepository: MemberRepository ) : ViewModel() { private val _uiState = MutableStateFlow(HomeUiState.Loading()) @@ -84,19 +88,4 @@ class HomeViewModel( } ) } - - companion object { - val Factory: ViewModelProvider.Factory = viewModelFactory { - initializer { - val application = - (this[ViewModelProvider.AndroidViewModelFactory.APPLICATION_KEY] as SoptApplication) - val followRepository = application.appContainer.followRepository - val authRepository = application.appContainer.memberRepository - HomeViewModel( - followerRepository = followRepository, - authRepository = authRepository - ) - } - } - } } \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/compose/ui/screens/login/LoginViewModel.kt b/app/src/main/java/com/sopt/now/compose/ui/screens/login/LoginViewModel.kt index 590fd56..7fc2459 100644 --- a/app/src/main/java/com/sopt/now/compose/ui/screens/login/LoginViewModel.kt +++ b/app/src/main/java/com/sopt/now/compose/ui/screens/login/LoginViewModel.kt @@ -10,6 +10,7 @@ import com.sopt.now.compose.SoptApplication import com.sopt.now.compose.container.repository.AuthRepository import com.sopt.now.compose.container.repository.UserRepository import com.sopt.now.compose.network.dto.RequestLoginDto +import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow @@ -17,8 +18,10 @@ import kotlinx.coroutines.flow.update import kotlinx.coroutines.launch import kotlinx.serialization.json.Json import kotlinx.serialization.json.jsonObject +import javax.inject.Inject -class LoginViewModel( +@HiltViewModel +class LoginViewModel @Inject constructor( private val userRepository: UserRepository, private val authRepository: AuthRepository ): ViewModel() { @@ -87,14 +90,5 @@ class LoginViewModel( companion object { const val HEADER_NAME = "location" const val JSON_NAME = "message" - - val Factory: ViewModelProvider.Factory = viewModelFactory { - initializer { - val application = (this[APPLICATION_KEY] as SoptApplication) - val userRepository = application.appContainer.userRepository - val authRepository = application.appContainer.authRepository - LoginViewModel(userRepository = userRepository, authRepository = authRepository) - } - } } } \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/compose/ui/screens/profile/ProfileViewModel.kt b/app/src/main/java/com/sopt/now/compose/ui/screens/profile/ProfileViewModel.kt index 6568107..f2bb733 100644 --- a/app/src/main/java/com/sopt/now/compose/ui/screens/profile/ProfileViewModel.kt +++ b/app/src/main/java/com/sopt/now/compose/ui/screens/profile/ProfileViewModel.kt @@ -9,12 +9,15 @@ import androidx.lifecycle.viewmodel.viewModelFactory import com.sopt.now.compose.SoptApplication import com.sopt.now.compose.container.impl.MemberRepositoryImpl import com.sopt.now.compose.models.User +import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.launch +import javax.inject.Inject -class ProfileViewModel( +@HiltViewModel +class ProfileViewModel @Inject constructor( private val authRepository: MemberRepositoryImpl ): ViewModel() { private val _uiState = MutableStateFlow(ProfileUiState.Loading) @@ -50,13 +53,5 @@ class ProfileViewModel( companion object{ private const val TAG = "ProfileViewModel" - - val Factory: ViewModelProvider.Factory = viewModelFactory { - initializer { - val application = (this[ViewModelProvider.AndroidViewModelFactory.APPLICATION_KEY] as SoptApplication) - val authRepository = application.appContainer.memberRepository - ProfileViewModel(authRepository) - } - } } } \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/compose/ui/screens/signup/SignUpViewModel.kt b/app/src/main/java/com/sopt/now/compose/ui/screens/signup/SignUpViewModel.kt index 9da4b38..f256336 100644 --- a/app/src/main/java/com/sopt/now/compose/ui/screens/signup/SignUpViewModel.kt +++ b/app/src/main/java/com/sopt/now/compose/ui/screens/signup/SignUpViewModel.kt @@ -9,6 +9,7 @@ import com.sopt.now.compose.SoptApplication import com.sopt.now.compose.container.impl.AuthRepositoryImpl import com.sopt.now.compose.network.dto.RequestSignUpDto import com.sopt.now.compose.ui.screens.login.LoginViewModel +import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow @@ -16,8 +17,10 @@ import kotlinx.coroutines.flow.update import kotlinx.coroutines.launch import kotlinx.serialization.json.Json import kotlinx.serialization.json.jsonObject +import javax.inject.Inject -class SignUpViewModel( +@HiltViewModel +class SignUpViewModel @Inject constructor( private val authRepository: AuthRepositoryImpl ): ViewModel() { private val _uiState = MutableStateFlow(SignUpState()) @@ -80,15 +83,4 @@ class SignUpViewModel( phone = this.phone ) } - - companion object{ - val Factory: ViewModelProvider.Factory = viewModelFactory { - initializer { - val application = (this[ViewModelProvider.AndroidViewModelFactory.APPLICATION_KEY] as SoptApplication) - val authRepository = application.appContainer.authRepository - SignUpViewModel(authRepository = authRepository) - } - } - } - } \ No newline at end of file From 6289d4d0ee202766a139a27e9d7a39c96da1eb7b Mon Sep 17 00:00:00 2001 From: boiledegg Date: Wed, 26 Jun 2024 15:06:36 +0900 Subject: [PATCH 15/31] =?UTF-8?q?FEAT/#21:=20hiltViewModel()=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/sopt/now/compose/ui/screens/home/HomeScreen.kt | 4 +--- .../java/com/sopt/now/compose/ui/screens/login/LoginScreen.kt | 3 ++- .../com/sopt/now/compose/ui/screens/profile/ProfileScreen.kt | 3 ++- .../com/sopt/now/compose/ui/screens/signup/SignUpScreen.kt | 3 ++- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/sopt/now/compose/ui/screens/home/HomeScreen.kt b/app/src/main/java/com/sopt/now/compose/ui/screens/home/HomeScreen.kt index 6c63e25..d77037d 100644 --- a/app/src/main/java/com/sopt/now/compose/ui/screens/home/HomeScreen.kt +++ b/app/src/main/java/com/sopt/now/compose/ui/screens/home/HomeScreen.kt @@ -42,12 +42,10 @@ import com.sopt.now.compose.R import com.sopt.now.compose.ui.SoptBottomNavigation import com.sopt.now.compose.ui.composables.ScreenWithImage -private const val TAG = "HomeScreen" - @Composable fun HomeScreen( navController: NavHostController = rememberNavController(), - viewModel: HomeViewModel = viewModel(factory = HomeViewModel.Factory), + viewModel: HomeViewModel = viewModel(), ) { LaunchedEffect(null) { viewModel.fetchNetworkData() diff --git a/app/src/main/java/com/sopt/now/compose/ui/screens/login/LoginScreen.kt b/app/src/main/java/com/sopt/now/compose/ui/screens/login/LoginScreen.kt index daf15af..b7ad0f7 100644 --- a/app/src/main/java/com/sopt/now/compose/ui/screens/login/LoginScreen.kt +++ b/app/src/main/java/com/sopt/now/compose/ui/screens/login/LoginScreen.kt @@ -24,6 +24,7 @@ import androidx.compose.ui.text.input.KeyboardType import androidx.compose.ui.text.input.PasswordVisualTransformation import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp +import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.lifecycle.viewmodel.compose.viewModel import androidx.navigation.NavHostController @@ -38,7 +39,7 @@ import com.sopt.now.compose.ui.navigation.SignUpDestination @Composable fun LoginScreen( navController: NavHostController = rememberNavController(), - viewModel: LoginViewModel = viewModel(factory = LoginViewModel.Factory), + viewModel: LoginViewModel = hiltViewModel(), ) { val context = LocalContext.current val uiState by viewModel.uiState.collectAsStateWithLifecycle(LocalLifecycleOwner.current) diff --git a/app/src/main/java/com/sopt/now/compose/ui/screens/profile/ProfileScreen.kt b/app/src/main/java/com/sopt/now/compose/ui/screens/profile/ProfileScreen.kt index 1fafb39..d011d97 100644 --- a/app/src/main/java/com/sopt/now/compose/ui/screens/profile/ProfileScreen.kt +++ b/app/src/main/java/com/sopt/now/compose/ui/screens/profile/ProfileScreen.kt @@ -18,6 +18,7 @@ import androidx.compose.ui.res.painterResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp +import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.lifecycle.viewmodel.compose.viewModel import androidx.navigation.NavHostController @@ -35,7 +36,7 @@ private const val TAG = "ProfileScreen" @Composable fun ProfileScreen( navController: NavHostController = rememberNavController(), - viewModel: ProfileViewModel = viewModel(factory = ProfileViewModel.Factory), + viewModel: ProfileViewModel = hiltViewModel(), ) { LaunchedEffect(navController) { val memberId = navController.previousBackStackEntry?.savedStateHandle diff --git a/app/src/main/java/com/sopt/now/compose/ui/screens/signup/SignUpScreen.kt b/app/src/main/java/com/sopt/now/compose/ui/screens/signup/SignUpScreen.kt index d46b804..98a881b 100644 --- a/app/src/main/java/com/sopt/now/compose/ui/screens/signup/SignUpScreen.kt +++ b/app/src/main/java/com/sopt/now/compose/ui/screens/signup/SignUpScreen.kt @@ -19,6 +19,7 @@ import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp +import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.lifecycle.viewmodel.compose.viewModel import androidx.navigation.NavHostController @@ -31,7 +32,7 @@ import com.sopt.now.compose.ui.composables.TextFieldWithTitleComposable fun SignUpScreen( modifier: Modifier = Modifier, navController: NavHostController = rememberNavController(), - viewModel: SignUpViewModel = viewModel(factory = SignUpViewModel.Factory) + viewModel: SignUpViewModel = hiltViewModel() ) { val context = LocalContext.current From 6bf7c5e7c32a5ef571d3e993848d7930775bfb79 Mon Sep 17 00:00:00 2001 From: boiledegg Date: Wed, 26 Jun 2024 15:07:43 +0900 Subject: [PATCH 16/31] =?UTF-8?q?REFACTOR/#21:=20=EC=A0=84=EC=B2=B4=20impo?= =?UTF-8?q?rt=20=EC=A0=95=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/sopt/now/compose/ui/screens/home/HomeViewModel.kt | 5 ----- .../com/sopt/now/compose/ui/screens/login/LoginScreen.kt | 1 - .../com/sopt/now/compose/ui/screens/login/LoginViewModel.kt | 5 ----- .../com/sopt/now/compose/ui/screens/profile/ProfileScreen.kt | 1 - .../sopt/now/compose/ui/screens/profile/ProfileViewModel.kt | 4 ---- .../com/sopt/now/compose/ui/screens/signup/SignUpScreen.kt | 1 - .../sopt/now/compose/ui/screens/signup/SignUpViewModel.kt | 4 ---- 7 files changed, 21 deletions(-) diff --git a/app/src/main/java/com/sopt/now/compose/ui/screens/home/HomeViewModel.kt b/app/src/main/java/com/sopt/now/compose/ui/screens/home/HomeViewModel.kt index ae46b2c..57c4796 100644 --- a/app/src/main/java/com/sopt/now/compose/ui/screens/home/HomeViewModel.kt +++ b/app/src/main/java/com/sopt/now/compose/ui/screens/home/HomeViewModel.kt @@ -2,12 +2,7 @@ package com.sopt.now.compose.ui.screens.home import android.util.Log import androidx.lifecycle.ViewModel -import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.viewModelScope -import androidx.lifecycle.viewmodel.initializer -import androidx.lifecycle.viewmodel.viewModelFactory -import com.sopt.now.compose.SoptApplication -import com.sopt.now.compose.container.impl.MemberRepositoryImpl import com.sopt.now.compose.container.repository.FollowerRepository import com.sopt.now.compose.container.repository.MemberRepository import dagger.hilt.android.lifecycle.HiltViewModel diff --git a/app/src/main/java/com/sopt/now/compose/ui/screens/login/LoginScreen.kt b/app/src/main/java/com/sopt/now/compose/ui/screens/login/LoginScreen.kt index b7ad0f7..7be6c81 100644 --- a/app/src/main/java/com/sopt/now/compose/ui/screens/login/LoginScreen.kt +++ b/app/src/main/java/com/sopt/now/compose/ui/screens/login/LoginScreen.kt @@ -26,7 +26,6 @@ import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.collectAsStateWithLifecycle -import androidx.lifecycle.viewmodel.compose.viewModel import androidx.navigation.NavHostController import androidx.navigation.compose.rememberNavController import com.sopt.now.compose.MainActivity diff --git a/app/src/main/java/com/sopt/now/compose/ui/screens/login/LoginViewModel.kt b/app/src/main/java/com/sopt/now/compose/ui/screens/login/LoginViewModel.kt index 7fc2459..24b18c7 100644 --- a/app/src/main/java/com/sopt/now/compose/ui/screens/login/LoginViewModel.kt +++ b/app/src/main/java/com/sopt/now/compose/ui/screens/login/LoginViewModel.kt @@ -1,12 +1,7 @@ package com.sopt.now.compose.ui.screens.login import androidx.lifecycle.ViewModel -import androidx.lifecycle.ViewModelProvider -import androidx.lifecycle.ViewModelProvider.AndroidViewModelFactory.Companion.APPLICATION_KEY import androidx.lifecycle.viewModelScope -import androidx.lifecycle.viewmodel.initializer -import androidx.lifecycle.viewmodel.viewModelFactory -import com.sopt.now.compose.SoptApplication import com.sopt.now.compose.container.repository.AuthRepository import com.sopt.now.compose.container.repository.UserRepository import com.sopt.now.compose.network.dto.RequestLoginDto diff --git a/app/src/main/java/com/sopt/now/compose/ui/screens/profile/ProfileScreen.kt b/app/src/main/java/com/sopt/now/compose/ui/screens/profile/ProfileScreen.kt index d011d97..7d754f8 100644 --- a/app/src/main/java/com/sopt/now/compose/ui/screens/profile/ProfileScreen.kt +++ b/app/src/main/java/com/sopt/now/compose/ui/screens/profile/ProfileScreen.kt @@ -20,7 +20,6 @@ import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.collectAsStateWithLifecycle -import androidx.lifecycle.viewmodel.compose.viewModel import androidx.navigation.NavHostController import androidx.navigation.compose.rememberNavController import com.sopt.now.compose.MainActivity diff --git a/app/src/main/java/com/sopt/now/compose/ui/screens/profile/ProfileViewModel.kt b/app/src/main/java/com/sopt/now/compose/ui/screens/profile/ProfileViewModel.kt index f2bb733..2e3585a 100644 --- a/app/src/main/java/com/sopt/now/compose/ui/screens/profile/ProfileViewModel.kt +++ b/app/src/main/java/com/sopt/now/compose/ui/screens/profile/ProfileViewModel.kt @@ -2,11 +2,7 @@ package com.sopt.now.compose.ui.screens.profile import android.util.Log import androidx.lifecycle.ViewModel -import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.viewModelScope -import androidx.lifecycle.viewmodel.initializer -import androidx.lifecycle.viewmodel.viewModelFactory -import com.sopt.now.compose.SoptApplication import com.sopt.now.compose.container.impl.MemberRepositoryImpl import com.sopt.now.compose.models.User import dagger.hilt.android.lifecycle.HiltViewModel diff --git a/app/src/main/java/com/sopt/now/compose/ui/screens/signup/SignUpScreen.kt b/app/src/main/java/com/sopt/now/compose/ui/screens/signup/SignUpScreen.kt index 98a881b..a35f088 100644 --- a/app/src/main/java/com/sopt/now/compose/ui/screens/signup/SignUpScreen.kt +++ b/app/src/main/java/com/sopt/now/compose/ui/screens/signup/SignUpScreen.kt @@ -21,7 +21,6 @@ import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.collectAsStateWithLifecycle -import androidx.lifecycle.viewmodel.compose.viewModel import androidx.navigation.NavHostController import androidx.navigation.compose.rememberNavController import com.sopt.now.compose.R diff --git a/app/src/main/java/com/sopt/now/compose/ui/screens/signup/SignUpViewModel.kt b/app/src/main/java/com/sopt/now/compose/ui/screens/signup/SignUpViewModel.kt index f256336..e0ae835 100644 --- a/app/src/main/java/com/sopt/now/compose/ui/screens/signup/SignUpViewModel.kt +++ b/app/src/main/java/com/sopt/now/compose/ui/screens/signup/SignUpViewModel.kt @@ -1,11 +1,7 @@ package com.sopt.now.compose.ui.screens.signup import androidx.lifecycle.ViewModel -import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.viewModelScope -import androidx.lifecycle.viewmodel.initializer -import androidx.lifecycle.viewmodel.viewModelFactory -import com.sopt.now.compose.SoptApplication import com.sopt.now.compose.container.impl.AuthRepositoryImpl import com.sopt.now.compose.network.dto.RequestSignUpDto import com.sopt.now.compose.ui.screens.login.LoginViewModel From c828b5c9fe6c318dae5b087ea7c0313429f4c48f Mon Sep 17 00:00:00 2001 From: boiledegg Date: Wed, 26 Jun 2024 15:09:52 +0900 Subject: [PATCH 17/31] =?UTF-8?q?REFACTOR/#21:=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=A0=95=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/sopt/now/compose/ui/screens/home/HomeViewModel.kt | 2 -- .../com/sopt/now/compose/ui/screens/profile/ProfileScreen.kt | 2 -- .../java/com/sopt/now/compose/ui/screens/signup/SignUpScreen.kt | 1 - 3 files changed, 5 deletions(-) diff --git a/app/src/main/java/com/sopt/now/compose/ui/screens/home/HomeViewModel.kt b/app/src/main/java/com/sopt/now/compose/ui/screens/home/HomeViewModel.kt index 57c4796..3344c49 100644 --- a/app/src/main/java/com/sopt/now/compose/ui/screens/home/HomeViewModel.kt +++ b/app/src/main/java/com/sopt/now/compose/ui/screens/home/HomeViewModel.kt @@ -74,8 +74,6 @@ class HomeViewModel @Inject constructor( follower = followers.orEmpty() ) updateUiState() - } else { - } }, onFailure = { diff --git a/app/src/main/java/com/sopt/now/compose/ui/screens/profile/ProfileScreen.kt b/app/src/main/java/com/sopt/now/compose/ui/screens/profile/ProfileScreen.kt index 7d754f8..f0a7c14 100644 --- a/app/src/main/java/com/sopt/now/compose/ui/screens/profile/ProfileScreen.kt +++ b/app/src/main/java/com/sopt/now/compose/ui/screens/profile/ProfileScreen.kt @@ -30,8 +30,6 @@ import com.sopt.now.compose.ui.composables.ButtonComposable import com.sopt.now.compose.ui.composables.ScreenWithImage import com.sopt.now.compose.ui.composables.TitleAndContentTextComposable -private const val TAG = "ProfileScreen" - @Composable fun ProfileScreen( navController: NavHostController = rememberNavController(), diff --git a/app/src/main/java/com/sopt/now/compose/ui/screens/signup/SignUpScreen.kt b/app/src/main/java/com/sopt/now/compose/ui/screens/signup/SignUpScreen.kt index a35f088..a4653d4 100644 --- a/app/src/main/java/com/sopt/now/compose/ui/screens/signup/SignUpScreen.kt +++ b/app/src/main/java/com/sopt/now/compose/ui/screens/signup/SignUpScreen.kt @@ -29,7 +29,6 @@ import com.sopt.now.compose.ui.composables.TextFieldWithTitleComposable @Composable fun SignUpScreen( - modifier: Modifier = Modifier, navController: NavHostController = rememberNavController(), viewModel: SignUpViewModel = hiltViewModel() ) { From 6f4fe22f3796578b52f6ebc538b20410e248814f Mon Sep 17 00:00:00 2001 From: boiledegg Date: Wed, 26 Jun 2024 16:32:31 +0900 Subject: [PATCH 18/31] =?UTF-8?q?ADD/#21:=20=EB=A9=80=ED=8B=B0=20=EB=AA=A8?= =?UTF-8?q?=EB=93=88=20=ED=99=98=EA=B2=BD=20=EA=B5=AC=EC=B6=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 4 ++ data/.gitignore | 1 + data/build.gradle | 42 +++++++++++++++++++ data/consumer-rules.pro | 0 data/proguard-rules.pro | 21 ++++++++++ .../compose/data/ExampleInstrumentedTest.kt | 24 +++++++++++ data/src/main/AndroidManifest.xml | 4 ++ .../sopt/now/compose/data/ExampleUnitTest.kt | 17 ++++++++ domain/.gitignore | 1 + domain/build.gradle | 41 ++++++++++++++++++ domain/consumer-rules.pro | 0 domain/proguard-rules.pro | 21 ++++++++++ .../compose/domain/ExampleInstrumentedTest.kt | 24 +++++++++++ domain/src/main/AndroidManifest.xml | 4 ++ .../now/compose/domain/ExampleUnitTest.kt | 17 ++++++++ presentation/.gitignore | 1 + presentation/build.gradle | 42 +++++++++++++++++++ presentation/consumer-rules.pro | 0 presentation/proguard-rules.pro | 21 ++++++++++ .../presentation/ExampleInstrumentedTest.kt | 24 +++++++++++ presentation/src/main/AndroidManifest.xml | 4 ++ .../compose/presentation/ExampleUnitTest.kt | 17 ++++++++ settings.gradle | 3 ++ 23 files changed, 333 insertions(+) create mode 100644 data/.gitignore create mode 100644 data/build.gradle create mode 100644 data/consumer-rules.pro create mode 100644 data/proguard-rules.pro create mode 100644 data/src/androidTest/java/com/sopt/now/compose/data/ExampleInstrumentedTest.kt create mode 100644 data/src/main/AndroidManifest.xml create mode 100644 data/src/test/java/com/sopt/now/compose/data/ExampleUnitTest.kt create mode 100644 domain/.gitignore create mode 100644 domain/build.gradle create mode 100644 domain/consumer-rules.pro create mode 100644 domain/proguard-rules.pro create mode 100644 domain/src/androidTest/java/com/sopt/now/compose/domain/ExampleInstrumentedTest.kt create mode 100644 domain/src/main/AndroidManifest.xml create mode 100644 domain/src/test/java/com/sopt/now/compose/domain/ExampleUnitTest.kt create mode 100644 presentation/.gitignore create mode 100644 presentation/build.gradle create mode 100644 presentation/consumer-rules.pro create mode 100644 presentation/proguard-rules.pro create mode 100644 presentation/src/androidTest/java/com/sopt/now/compose/presentation/ExampleInstrumentedTest.kt create mode 100644 presentation/src/main/AndroidManifest.xml create mode 100644 presentation/src/test/java/com/sopt/now/compose/presentation/ExampleUnitTest.kt diff --git a/app/build.gradle b/app/build.gradle index ae5209d..e14db79 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -101,4 +101,8 @@ dependencies { implementation ("androidx.lifecycle:lifecycle-runtime-compose:2.8.1") + + implementation project(path: ':data') + implementation project(path: ':domain') + implementation project(path: ':presentation') } \ No newline at end of file diff --git a/data/.gitignore b/data/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/data/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/data/build.gradle b/data/build.gradle new file mode 100644 index 0000000..3021f1a --- /dev/null +++ b/data/build.gradle @@ -0,0 +1,42 @@ +plugins { + id 'com.android.library' + id 'org.jetbrains.kotlin.android' +} + +android { + namespace 'com.sopt.now.compose.data' + compileSdk 34 + + defaultConfig { + minSdk 28 + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + consumerProguardFiles "consumer-rules.pro" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + kotlinOptions { + jvmTarget = '1.8' + } +} + +dependencies { + + implementation 'androidx.core:core-ktx:1.13.1' + implementation 'androidx.appcompat:appcompat:1.7.0' + implementation 'com.google.android.material:material:1.12.0' + testImplementation 'junit:junit:4.13.2' + androidTestImplementation 'androidx.test.ext:junit:1.2.0' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.0' + + implementation project(path: ':domain') +} \ No newline at end of file diff --git a/data/consumer-rules.pro b/data/consumer-rules.pro new file mode 100644 index 0000000..e69de29 diff --git a/data/proguard-rules.pro b/data/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/data/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/data/src/androidTest/java/com/sopt/now/compose/data/ExampleInstrumentedTest.kt b/data/src/androidTest/java/com/sopt/now/compose/data/ExampleInstrumentedTest.kt new file mode 100644 index 0000000..bcab636 --- /dev/null +++ b/data/src/androidTest/java/com/sopt/now/compose/data/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package com.sopt.now.compose.data + +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.sopt.now.compose.data.test", appContext.packageName) + } +} \ No newline at end of file diff --git a/data/src/main/AndroidManifest.xml b/data/src/main/AndroidManifest.xml new file mode 100644 index 0000000..a5918e6 --- /dev/null +++ b/data/src/main/AndroidManifest.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/data/src/test/java/com/sopt/now/compose/data/ExampleUnitTest.kt b/data/src/test/java/com/sopt/now/compose/data/ExampleUnitTest.kt new file mode 100644 index 0000000..2b9d39f --- /dev/null +++ b/data/src/test/java/com/sopt/now/compose/data/ExampleUnitTest.kt @@ -0,0 +1,17 @@ +package com.sopt.now.compose.data + +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/domain/.gitignore b/domain/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/domain/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/domain/build.gradle b/domain/build.gradle new file mode 100644 index 0000000..71d3579 --- /dev/null +++ b/domain/build.gradle @@ -0,0 +1,41 @@ +plugins { + id 'com.android.library' + id 'org.jetbrains.kotlin.android' +} + +android { + namespace 'com.sopt.now.compose.domain' + compileSdk 34 + + defaultConfig { + minSdk 28 + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + consumerProguardFiles "consumer-rules.pro" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + kotlinOptions { + jvmTarget = '1.8' + } +} + +dependencies { + + implementation 'androidx.core:core-ktx:1.13.1' + implementation 'androidx.appcompat:appcompat:1.7.0' + implementation 'com.google.android.material:material:1.12.0' + testImplementation 'junit:junit:4.13.2' + androidTestImplementation 'androidx.test.ext:junit:1.2.0' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.0' + +} \ No newline at end of file diff --git a/domain/consumer-rules.pro b/domain/consumer-rules.pro new file mode 100644 index 0000000..e69de29 diff --git a/domain/proguard-rules.pro b/domain/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/domain/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/domain/src/androidTest/java/com/sopt/now/compose/domain/ExampleInstrumentedTest.kt b/domain/src/androidTest/java/com/sopt/now/compose/domain/ExampleInstrumentedTest.kt new file mode 100644 index 0000000..0d1955b --- /dev/null +++ b/domain/src/androidTest/java/com/sopt/now/compose/domain/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package com.sopt.now.compose.domain + +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.sopt.now.compose.domain.test", appContext.packageName) + } +} \ No newline at end of file diff --git a/domain/src/main/AndroidManifest.xml b/domain/src/main/AndroidManifest.xml new file mode 100644 index 0000000..a5918e6 --- /dev/null +++ b/domain/src/main/AndroidManifest.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/domain/src/test/java/com/sopt/now/compose/domain/ExampleUnitTest.kt b/domain/src/test/java/com/sopt/now/compose/domain/ExampleUnitTest.kt new file mode 100644 index 0000000..be2ffd4 --- /dev/null +++ b/domain/src/test/java/com/sopt/now/compose/domain/ExampleUnitTest.kt @@ -0,0 +1,17 @@ +package com.sopt.now.compose.domain + +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/presentation/.gitignore b/presentation/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/presentation/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/presentation/build.gradle b/presentation/build.gradle new file mode 100644 index 0000000..76b09fc --- /dev/null +++ b/presentation/build.gradle @@ -0,0 +1,42 @@ +plugins { + id 'com.android.library' + id 'org.jetbrains.kotlin.android' +} + +android { + namespace 'com.sopt.now.compose.presentation' + compileSdk 34 + + defaultConfig { + minSdk 28 + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + consumerProguardFiles "consumer-rules.pro" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + kotlinOptions { + jvmTarget = '1.8' + } +} + +dependencies { + + implementation 'androidx.core:core-ktx:1.13.1' + implementation 'androidx.appcompat:appcompat:1.7.0' + implementation 'com.google.android.material:material:1.12.0' + testImplementation 'junit:junit:4.13.2' + androidTestImplementation 'androidx.test.ext:junit:1.2.0' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.0' + + implementation project(path: ':domain') +} \ No newline at end of file diff --git a/presentation/consumer-rules.pro b/presentation/consumer-rules.pro new file mode 100644 index 0000000..e69de29 diff --git a/presentation/proguard-rules.pro b/presentation/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/presentation/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/presentation/src/androidTest/java/com/sopt/now/compose/presentation/ExampleInstrumentedTest.kt b/presentation/src/androidTest/java/com/sopt/now/compose/presentation/ExampleInstrumentedTest.kt new file mode 100644 index 0000000..f20aa5c --- /dev/null +++ b/presentation/src/androidTest/java/com/sopt/now/compose/presentation/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package com.sopt.now.compose.presentation + +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.sopt.now.compose.presentation.test", appContext.packageName) + } +} \ No newline at end of file diff --git a/presentation/src/main/AndroidManifest.xml b/presentation/src/main/AndroidManifest.xml new file mode 100644 index 0000000..a5918e6 --- /dev/null +++ b/presentation/src/main/AndroidManifest.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/presentation/src/test/java/com/sopt/now/compose/presentation/ExampleUnitTest.kt b/presentation/src/test/java/com/sopt/now/compose/presentation/ExampleUnitTest.kt new file mode 100644 index 0000000..54ae4c8 --- /dev/null +++ b/presentation/src/test/java/com/sopt/now/compose/presentation/ExampleUnitTest.kt @@ -0,0 +1,17 @@ +package com.sopt.now.compose.presentation + +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/settings.gradle b/settings.gradle index b09754c..e7a0492 100644 --- a/settings.gradle +++ b/settings.gradle @@ -21,3 +21,6 @@ dependencyResolutionManagement { rootProject.name = "NOW SOPT Android" include ':app' +include ':data' +include ':presentation' +include ':domain' From 8413a0a48cc55dae282973612b422bc917e3392d Mon Sep 17 00:00:00 2001 From: boiledegg Date: Wed, 26 Jun 2024 18:33:44 +0900 Subject: [PATCH 19/31] =?UTF-8?q?ADD/#21:=20=EB=B2=84=EC=A0=84=20=EC=B9=B4?= =?UTF-8?q?=ED=83=88=EB=A1=9C=EA=B7=B8=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 76 ++++++++++++++++----------------------- build.gradle | 8 ++--- gradle/libs.versions.toml | 60 +++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+), 49 deletions(-) create mode 100644 gradle/libs.versions.toml diff --git a/app/build.gradle b/app/build.gradle index e14db79..fad6521 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,8 +1,8 @@ plugins { - id 'com.android.application' - id 'org.jetbrains.kotlin.android' - id 'org.jetbrains.kotlin.plugin.serialization' version '1.9.0' - id 'com.google.dagger.hilt.android' + alias(libs.plugins.android.application) + alias(libs.plugins.jetbrains.kotlin.android) + alias(libs.plugins.jetbrains.kotlin.serialization) + alias(libs.plugins.google.dagger.hilt.android) id 'kotlin-android' id 'kotlin-kapt' } @@ -60,47 +60,33 @@ android { } dependencies { - implementation 'androidx.core:core-ktx:1.13.1' - implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.8.1' - implementation 'androidx.activity:activity-compose:1.9.0' - implementation platform('androidx.compose:compose-bom:2024.05.00') - implementation 'androidx.compose.ui:ui' - implementation 'androidx.compose.ui:ui-graphics' - implementation 'androidx.compose.ui:ui-tooling-preview' - implementation 'androidx.compose.material3:material3' - testImplementation 'junit:junit:4.13.2' - androidTestImplementation 'androidx.test.ext:junit:1.1.5' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' - androidTestImplementation platform('androidx.compose:compose-bom:2024.05.00') - androidTestImplementation 'androidx.compose.ui:ui-test-junit4' - debugImplementation 'androidx.compose.ui:ui-tooling' - debugImplementation 'androidx.compose.ui:ui-test-manifest' - - //navigation dependency - implementation("androidx.navigation:navigation-compose:2.7.7") - - //Retrofit - implementation 'com.squareup.retrofit2:retrofit:2.9.0' - implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.3' - implementation 'com.jakewharton.retrofit:retrofit2-kotlinx-serialization-converter:1.0.0' - - // define a BOM and its version - implementation(platform("com.squareup.okhttp3:okhttp-bom:4.11.0")) - - // define any required OkHttp artifacts without version - implementation("com.squareup.okhttp3:okhttp") - implementation("com.squareup.okhttp3:logging-interceptor") - - // Coil - implementation("io.coil-kt:coil-compose:2.6.0") - - //Dagger & Hilt - implementation 'com.google.dagger:hilt-android:2.51' - kapt 'com.google.dagger:hilt-compiler:2.51.1' - implementation 'androidx.hilt:hilt-navigation-compose:1.2.0' - - - implementation ("androidx.lifecycle:lifecycle-runtime-compose:2.8.1") + implementation(libs.core.ktx) + implementation(libs.lifecycle.runtime.ktx) + implementation(libs.activity.compose) + implementation(platform(libs.compose.bom)) + implementation(libs.compose.ui) + implementation(libs.compose.ui.graphics) + implementation(libs.compose.ui.tooling) + implementation(libs.compose.material3) + testImplementation(libs.junit) + androidTestImplementation(libs.test.ext.junit) + androidTestImplementation(libs.test.espresso.eore) + androidTestImplementation(platform(libs.compose.bom)) + androidTestImplementation(libs.compose.ui.test.junit4) + androidTestImplementation(libs.compose.ui.tooling) + debugImplementation(libs.compose.ui.test.manifest) + implementation(libs.navigation.compose) + implementation(libs.retrofit2.retrofit) + implementation(libs.serialization.json) + implementation(libs.retrofit2.serialization.converter) + implementation(platform(libs.okhttp.bom)) + implementation(libs.okhttp) + implementation(libs.okhttp.logging.interceptor) + implementation(libs.coil.compose) + implementation(libs.hiltAndroid) + kapt(libs.hiltCompiler) + implementation(libs.hiltNavigation) + implementation(libs.lifecycle.runtime.compose) implementation project(path: ':data') implementation project(path: ':domain') diff --git a/build.gradle b/build.gradle index bce5569..6d9eabd 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,7 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. plugins { - id 'com.android.application' version '8.3.2' apply false - id 'com.android.library' version '8.3.2' apply false - id 'org.jetbrains.kotlin.android' version '1.9.0' apply false - id 'com.google.dagger.hilt.android' version '2.51' apply false + alias(libs.plugins.android.application) apply false + alias(libs.plugins.android.library) apply false + alias(libs.plugins.jetbrains.kotlin.android) apply false + alias(libs.plugins.google.dagger.hilt.android) apply false } \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 0000000..1ed1fb7 --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,60 @@ +[versions] +android = '8.3.2' +androidLibrary = '8.3.2' +jetbrainsKotlinAndroid = '1.9.0' +jetbrainsKotlinSerialization = '1.9.0' +hiltAndroid = '2.51' +ksp = "1.8.10-1.0.9" +coreKtx = '1.13.1' +lifecycleRuntimeKtx = '2.8.1' +activityCompose = '1.9.0' +composeBom = '2024.05.00' +junit = '4.13.2' +testJunit = '1.1.5' +espressoCore = '3.5.1' +navigationCompose = '2.7.7' +retrofit = '2.9.0' +serializationJson = '1.6.3' +serializationConverter = '1.0.0' +okhttpBom = '4.11.0' +coilCompose = '2.6.0' +hiltCompiler = '2.51.1' +hiltNavigation = '1.2.0' +lifecycleRunTime = '2.8.1' + +[libraries] +core-ktx = {group = "androidx.core", name = "core-ktx", version.ref = "coreKtx"} +lifecycle-runtime-ktx = {group = "androidx.lifecycle", name = "lifecycle-runtime-ktx", version.ref = "lifecycleRuntimeKtx"} +activity-compose = {group = "androidx.activity", name = "activity-compose", version.ref = "activityCompose"} +compose-bom = {group = "androidx.compose", name = "compose-bom", version.ref = "composeBom"} +compose-ui = {group = "androidx.compose.ui", name = "ui"} +compose-ui-graphics = {group = "androidx.compose.ui", name = "ui-graphics"} +compose-material3 = {group = "androidx.compose.material3", name = "material3"} +junit = {group = "junit", name = "junit", version.ref = "junit"} +test-ext-junit = {group = "androidx.test.ext", name = "junit", version.ref = "testJunit"} +test-espresso-eore = {group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore"} +compose-ui-test-junit4 = {group = "androidx.compose.ui", name = "ui-test-junit4"} +compose-ui-tooling = {group = "androidx.compose.ui", name = "ui-tooling"} +compose-ui-test-manifest = {group = "androidx.compose.ui", name = "ui-test-manifest"} +navigation-compose = {group = "androidx.navigation", name = "navigation-compose", version.ref = "navigationCompose"} +retrofit2-retrofit = {group = "com.squareup.retrofit2", name = "retrofit", version.ref = "retrofit"} +serialization-json = {group = "org.jetbrains.kotlinx", name = "kotlinx-serialization-json", version.ref = "serializationJson"} +retrofit2-serialization-converter = {group = "com.jakewharton.retrofit", name = "retrofit2-kotlinx-serialization-converter",version.ref = "serializationConverter"} +okhttp-bom = {group = "com.squareup.okhttp3", name = "okhttp-bom", version.ref = "okhttpBom"} +okhttp = {group = "com.squareup.okhttp3", name = "okhttp"} +okhttp-logging-interceptor = {group = "com.squareup.okhttp3", name = "okhttp-logging-interceptor"} + +coil-compose = {group = "io.coil-kt", name = "coil-compose", version.ref = "coilCompose"} + +hiltAndroid = {group = "com.google.dagger", name = "hilt-android", version.ref = "hiltAndroid"} +hiltCompiler = {group = "com.google.dagger", name = "hilt-compiler", version.ref = "hiltCompiler"} +hiltNavigation = {group = "androidx.hilt", name = "hilt-navigation-compose", version.ref = "hiltNavigation"} + +lifecycle-runtime-compose = {group = "androidx.lifecycle", name = "lifecycle-runtime-compose", version.ref = "lifecycleRunTime"} + +[plugins] +android-application = { id = "com.android.application", version.ref = "android" } +android-library = { id = "com.android.library", version.ref = "androidLibrary"} +jetbrains-kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "jetbrainsKotlinAndroid"} +jetbrains-kotlin-serialization = {id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "jetbrainsKotlinSerialization" } +google-dagger-hilt-android = {id = "com.google.dagger.hilt.android", version.ref = "hiltAndroid"} From b512f94186acd96173ad276edd0c66fbcf93271f Mon Sep 17 00:00:00 2001 From: boiledegg Date: Thu, 27 Jun 2024 23:51:37 +0900 Subject: [PATCH 20/31] =?UTF-8?q?FEAT/#21:=20Domain=20=EB=AA=A8=EB=93=88?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80,=20Repository=20=EB=B0=8F=20Entity=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 --- .../container/repository/AuthRepository.kt | 13 --------- .../repository/FollowerRepository.kt | 9 ------ domain/build.gradle | 29 +++++++++++++------ .../entity/request/FollowerRequestEntity.kt | 5 ++++ .../entity/request/LoginRequestEntity.kt | 6 ++++ .../entity/request/SignupRequestEntity.kt | 8 +++++ .../entity/response/FollowerResponseEntity.kt | 11 +++++++ .../entity/response/LoginResponseEntity.kt | 6 ++++ .../entity/response/SignupResponseEntity.kt | 6 ++++ .../entity/response/UserResponseEntity.kt | 7 +++++ .../domain/repository/AuthRepository.kt | 12 ++++++++ .../domain/repository/FollowerRepository.kt | 10 +++++++ .../domain/repository/HomeRepository.kt | 7 +++++ 13 files changed, 98 insertions(+), 31 deletions(-) delete mode 100644 app/src/main/java/com/sopt/now/compose/container/repository/AuthRepository.kt delete mode 100644 app/src/main/java/com/sopt/now/compose/container/repository/FollowerRepository.kt create mode 100644 domain/src/main/java/com/sopt/now/compose/domain/entity/request/FollowerRequestEntity.kt create mode 100644 domain/src/main/java/com/sopt/now/compose/domain/entity/request/LoginRequestEntity.kt create mode 100644 domain/src/main/java/com/sopt/now/compose/domain/entity/request/SignupRequestEntity.kt create mode 100644 domain/src/main/java/com/sopt/now/compose/domain/entity/response/FollowerResponseEntity.kt create mode 100644 domain/src/main/java/com/sopt/now/compose/domain/entity/response/LoginResponseEntity.kt create mode 100644 domain/src/main/java/com/sopt/now/compose/domain/entity/response/SignupResponseEntity.kt create mode 100644 domain/src/main/java/com/sopt/now/compose/domain/entity/response/UserResponseEntity.kt create mode 100644 domain/src/main/java/com/sopt/now/compose/domain/repository/AuthRepository.kt create mode 100644 domain/src/main/java/com/sopt/now/compose/domain/repository/FollowerRepository.kt create mode 100644 domain/src/main/java/com/sopt/now/compose/domain/repository/HomeRepository.kt diff --git a/app/src/main/java/com/sopt/now/compose/container/repository/AuthRepository.kt b/app/src/main/java/com/sopt/now/compose/container/repository/AuthRepository.kt deleted file mode 100644 index ad1ab28..0000000 --- a/app/src/main/java/com/sopt/now/compose/container/repository/AuthRepository.kt +++ /dev/null @@ -1,13 +0,0 @@ -package com.sopt.now.compose.container.repository - -import com.sopt.now.compose.network.dto.RequestLoginDto -import com.sopt.now.compose.network.dto.RequestSignUpDto -import com.sopt.now.compose.network.dto.ResponseLoginDto -import com.sopt.now.compose.network.dto.ResponseSignUpDto -import retrofit2.Response - -interface AuthRepository { - suspend fun postLogin(request: RequestLoginDto): Result> - suspend fun postSignUp(request: RequestSignUpDto): Result> -} - diff --git a/app/src/main/java/com/sopt/now/compose/container/repository/FollowerRepository.kt b/app/src/main/java/com/sopt/now/compose/container/repository/FollowerRepository.kt deleted file mode 100644 index ccf5c68..0000000 --- a/app/src/main/java/com/sopt/now/compose/container/repository/FollowerRepository.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.sopt.now.compose.container.repository - -import com.sopt.now.compose.network.dto.ResponseFollowListDto -import retrofit2.Response - -interface FollowerRepository{ - suspend fun getFollowers(page: Int = 2): Result> -} - diff --git a/domain/build.gradle b/domain/build.gradle index 71d3579..aa90ae8 100644 --- a/domain/build.gradle +++ b/domain/build.gradle @@ -1,6 +1,10 @@ plugins { - id 'com.android.library' - id 'org.jetbrains.kotlin.android' + alias(libs.plugins.android.application) + alias(libs.plugins.jetbrains.kotlin.android) + alias(libs.plugins.jetbrains.kotlin.serialization) + alias(libs.plugins.google.dagger.hilt.android) + id 'kotlin-android' + id 'kotlin-kapt' } android { @@ -30,12 +34,19 @@ android { } dependencies { + implementation(libs.core.ktx) + implementation(libs.androidx.appcompat) + implementation(libs.android.material) + testImplementation(libs.junit) + androidTestImplementation(libs.test.ext.junit) + androidTestImplementation(libs.test.espresso.eore) + implementation(libs.hiltAndroid) + kapt(libs.hiltCompiler) - implementation 'androidx.core:core-ktx:1.13.1' - implementation 'androidx.appcompat:appcompat:1.7.0' - implementation 'com.google.android.material:material:1.12.0' - testImplementation 'junit:junit:4.13.2' - androidTestImplementation 'androidx.test.ext:junit:1.2.0' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.0' - + implementation(libs.retrofit2.retrofit) + implementation(libs.serialization.json) + implementation(libs.retrofit2.serialization.converter) + implementation(platform(libs.okhttp.bom)) + implementation(libs.okhttp) + implementation(libs.okhttp.logging.interceptor) } \ No newline at end of file diff --git a/domain/src/main/java/com/sopt/now/compose/domain/entity/request/FollowerRequestEntity.kt b/domain/src/main/java/com/sopt/now/compose/domain/entity/request/FollowerRequestEntity.kt new file mode 100644 index 0000000..35e9205 --- /dev/null +++ b/domain/src/main/java/com/sopt/now/compose/domain/entity/request/FollowerRequestEntity.kt @@ -0,0 +1,5 @@ +package com.sopt.now.compose.domain.entity.request + +data class FollowerRequestEntity ( + val page: Int +) \ No newline at end of file diff --git a/domain/src/main/java/com/sopt/now/compose/domain/entity/request/LoginRequestEntity.kt b/domain/src/main/java/com/sopt/now/compose/domain/entity/request/LoginRequestEntity.kt new file mode 100644 index 0000000..2c76777 --- /dev/null +++ b/domain/src/main/java/com/sopt/now/compose/domain/entity/request/LoginRequestEntity.kt @@ -0,0 +1,6 @@ +package com.sopt.now.compose.domain.entity.request + +data class LoginRequestEntity ( + val authenticationId: String, + val password: String +) \ No newline at end of file diff --git a/domain/src/main/java/com/sopt/now/compose/domain/entity/request/SignupRequestEntity.kt b/domain/src/main/java/com/sopt/now/compose/domain/entity/request/SignupRequestEntity.kt new file mode 100644 index 0000000..9e56798 --- /dev/null +++ b/domain/src/main/java/com/sopt/now/compose/domain/entity/request/SignupRequestEntity.kt @@ -0,0 +1,8 @@ +package com.sopt.now.compose.domain.entity.request + +data class SignupRequestEntity ( + val authenticationId: String, + val password: String, + val nickname: String, + val phone: String +) \ No newline at end of file diff --git a/domain/src/main/java/com/sopt/now/compose/domain/entity/response/FollowerResponseEntity.kt b/domain/src/main/java/com/sopt/now/compose/domain/entity/response/FollowerResponseEntity.kt new file mode 100644 index 0000000..f703de3 --- /dev/null +++ b/domain/src/main/java/com/sopt/now/compose/domain/entity/response/FollowerResponseEntity.kt @@ -0,0 +1,11 @@ +package com.sopt.now.compose.domain.entity.response + +data class FollowerResponseEntity( + val id:Int, + val email:String, + val firstName:String, + val lastName:String, + val avatar:String +) + + diff --git a/domain/src/main/java/com/sopt/now/compose/domain/entity/response/LoginResponseEntity.kt b/domain/src/main/java/com/sopt/now/compose/domain/entity/response/LoginResponseEntity.kt new file mode 100644 index 0000000..98be4f6 --- /dev/null +++ b/domain/src/main/java/com/sopt/now/compose/domain/entity/response/LoginResponseEntity.kt @@ -0,0 +1,6 @@ +package com.sopt.now.compose.domain.entity.response + +data class LoginResponseEntity ( + val code: Int, + val memberId: String +) \ No newline at end of file diff --git a/domain/src/main/java/com/sopt/now/compose/domain/entity/response/SignupResponseEntity.kt b/domain/src/main/java/com/sopt/now/compose/domain/entity/response/SignupResponseEntity.kt new file mode 100644 index 0000000..bd16d26 --- /dev/null +++ b/domain/src/main/java/com/sopt/now/compose/domain/entity/response/SignupResponseEntity.kt @@ -0,0 +1,6 @@ +package com.sopt.now.compose.domain.entity.response + +data class SignupResponseEntity ( + val code: Int, + val memberId: String +) \ No newline at end of file diff --git a/domain/src/main/java/com/sopt/now/compose/domain/entity/response/UserResponseEntity.kt b/domain/src/main/java/com/sopt/now/compose/domain/entity/response/UserResponseEntity.kt new file mode 100644 index 0000000..7ca262b --- /dev/null +++ b/domain/src/main/java/com/sopt/now/compose/domain/entity/response/UserResponseEntity.kt @@ -0,0 +1,7 @@ +package com.sopt.now.compose.domain.entity.response + +data class UserResponseEntity( + val authenticationId: String, + val nickname: String, + val phone: String +) \ No newline at end of file diff --git a/domain/src/main/java/com/sopt/now/compose/domain/repository/AuthRepository.kt b/domain/src/main/java/com/sopt/now/compose/domain/repository/AuthRepository.kt new file mode 100644 index 0000000..38b7216 --- /dev/null +++ b/domain/src/main/java/com/sopt/now/compose/domain/repository/AuthRepository.kt @@ -0,0 +1,12 @@ +package com.sopt.now.compose.domain.repository + +import com.sopt.now.compose.domain.entity.request.LoginRequestEntity +import com.sopt.now.compose.domain.entity.request.SignupRequestEntity +import com.sopt.now.compose.domain.entity.response.LoginResponseEntity +import com.sopt.now.compose.domain.entity.response.SignupResponseEntity + +interface AuthRepository { + suspend fun postLogin(request: LoginRequestEntity): Result + suspend fun postSignUp(request: SignupRequestEntity): Result +} + diff --git a/domain/src/main/java/com/sopt/now/compose/domain/repository/FollowerRepository.kt b/domain/src/main/java/com/sopt/now/compose/domain/repository/FollowerRepository.kt new file mode 100644 index 0000000..da8d80f --- /dev/null +++ b/domain/src/main/java/com/sopt/now/compose/domain/repository/FollowerRepository.kt @@ -0,0 +1,10 @@ +package com.sopt.now.compose.domain.repository + +import com.sopt.now.compose.domain.entity.request.FollowerRequestEntity +import com.sopt.now.compose.domain.entity.response.FollowerResponseEntity +import retrofit2.Response + +interface FollowerRepository{ + suspend fun getFollowers(request: FollowerRequestEntity): Result> +} + diff --git a/domain/src/main/java/com/sopt/now/compose/domain/repository/HomeRepository.kt b/domain/src/main/java/com/sopt/now/compose/domain/repository/HomeRepository.kt new file mode 100644 index 0000000..6b3701a --- /dev/null +++ b/domain/src/main/java/com/sopt/now/compose/domain/repository/HomeRepository.kt @@ -0,0 +1,7 @@ +package com.sopt.now.compose.domain.repository + +import com.sopt.now.compose.domain.entity.response.UserResponseEntity + +interface HomeRepository { + suspend fun getUser(): Result +} \ No newline at end of file From e4f50d9f9bb1fa89b8e20c732a1dfebbf2d011dd Mon Sep 17 00:00:00 2001 From: boiledegg Date: Thu, 27 Jun 2024 23:52:25 +0900 Subject: [PATCH 21/31] =?UTF-8?q?FEAT/#21:=20Data=20=EB=AA=A8=EB=93=88=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80,=20Service=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sopt/now/compose/network/AuthService.kt | 34 ------------------- .../sopt/now/compose/network/HomeService.kt | 24 ------------- data/build.gradle | 34 ++++++++++++++----- .../now/compose/data/service/AuthService.kt | 21 ++++++++++++ .../compose/data/service/FollowerService.kt | 6 ++-- .../now/compose/data/service/HomeService.kt | 11 ++++++ 6 files changed, 61 insertions(+), 69 deletions(-) delete mode 100644 app/src/main/java/com/sopt/now/compose/network/AuthService.kt delete mode 100644 app/src/main/java/com/sopt/now/compose/network/HomeService.kt create mode 100644 data/src/main/java/com/sopt/now/compose/data/service/AuthService.kt rename app/src/main/java/com/sopt/now/compose/network/FollowService.kt => data/src/main/java/com/sopt/now/compose/data/service/FollowerService.kt (60%) create mode 100644 data/src/main/java/com/sopt/now/compose/data/service/HomeService.kt diff --git a/app/src/main/java/com/sopt/now/compose/network/AuthService.kt b/app/src/main/java/com/sopt/now/compose/network/AuthService.kt deleted file mode 100644 index a96b30c..0000000 --- a/app/src/main/java/com/sopt/now/compose/network/AuthService.kt +++ /dev/null @@ -1,34 +0,0 @@ -package com.sopt.now.compose.network - -import com.sopt.now.compose.network.dto.RequestChangePasswordDto -import com.sopt.now.compose.network.dto.RequestLoginDto -import com.sopt.now.compose.network.dto.RequestSignUpDto -import com.sopt.now.compose.network.dto.ResponseChangePasswordDto -import com.sopt.now.compose.network.dto.ResponseLoginDto -import com.sopt.now.compose.network.dto.ResponseMemberInfoDto -import com.sopt.now.compose.network.dto.ResponseSignUpDto -import retrofit2.Response -import retrofit2.http.Body -import retrofit2.http.GET -import retrofit2.http.PATCH -import retrofit2.http.POST - -interface AuthService { - @POST("member/join") - suspend fun signUp( - @Body request: RequestSignUpDto, - ): Response - - @POST("member/login") - suspend fun login( - @Body request: RequestLoginDto - ): Response - - @GET("member/info") - suspend fun getMemberInfo(): Response - - @PATCH("member/password") - suspend fun changePassword( - @Body request: RequestChangePasswordDto - ): Response -} \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/compose/network/HomeService.kt b/app/src/main/java/com/sopt/now/compose/network/HomeService.kt deleted file mode 100644 index 1d45eae..0000000 --- a/app/src/main/java/com/sopt/now/compose/network/HomeService.kt +++ /dev/null @@ -1,24 +0,0 @@ -package com.sopt.now.compose.network - -import com.sopt.now.compose.network.dto.RequestChangePasswordDto -import com.sopt.now.compose.network.dto.RequestLoginDto -import com.sopt.now.compose.network.dto.RequestSignUpDto -import com.sopt.now.compose.network.dto.ResponseChangePasswordDto -import com.sopt.now.compose.network.dto.ResponseLoginDto -import com.sopt.now.compose.network.dto.ResponseMemberInfoDto -import com.sopt.now.compose.network.dto.ResponseSignUpDto -import retrofit2.Response -import retrofit2.http.Body -import retrofit2.http.GET -import retrofit2.http.PATCH -import retrofit2.http.POST - -interface HomeService { - @GET("member/info") - suspend fun getMemberInfo(): Response - - @PATCH("member/password") - suspend fun changePassword( - @Body request: RequestChangePasswordDto - ): Response -} \ No newline at end of file diff --git a/data/build.gradle b/data/build.gradle index 3021f1a..453071c 100644 --- a/data/build.gradle +++ b/data/build.gradle @@ -1,8 +1,14 @@ plugins { - id 'com.android.library' - id 'org.jetbrains.kotlin.android' + alias(libs.plugins.android.application) + alias(libs.plugins.jetbrains.kotlin.android) + alias(libs.plugins.jetbrains.kotlin.serialization) + alias(libs.plugins.google.dagger.hilt.android) + id 'kotlin-android' + id 'kotlin-kapt' } +Properties properties = new Properties() +properties.load(project.rootProject.file('local.properties').newDataInputStream()) android { namespace 'com.sopt.now.compose.data' compileSdk 34 @@ -12,6 +18,9 @@ android { testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" consumerProguardFiles "consumer-rules.pro" + + buildConfigField "String", "AUTH_BASE_URL", properties["base.url"] + buildConfigField "String", "REQRES_URL", properties["reqres.url"] } buildTypes { @@ -31,12 +40,21 @@ android { dependencies { - implementation 'androidx.core:core-ktx:1.13.1' - implementation 'androidx.appcompat:appcompat:1.7.0' - implementation 'com.google.android.material:material:1.12.0' - testImplementation 'junit:junit:4.13.2' - androidTestImplementation 'androidx.test.ext:junit:1.2.0' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.0' + implementation(libs.core.ktx) + implementation(libs.androidx.appcompat) + implementation(libs.android.material) + testImplementation(libs.junit) + androidTestImplementation(libs.test.ext.junit) + androidTestImplementation(libs.test.espresso.eore) + implementation(libs.hiltAndroid) + kapt(libs.hiltCompiler) + + implementation(libs.retrofit2.retrofit) + implementation(libs.serialization.json) + implementation(libs.retrofit2.serialization.converter) + implementation(platform(libs.okhttp.bom)) + implementation(libs.okhttp) + implementation(libs.okhttp.logging.interceptor) implementation project(path: ':domain') } \ No newline at end of file diff --git a/data/src/main/java/com/sopt/now/compose/data/service/AuthService.kt b/data/src/main/java/com/sopt/now/compose/data/service/AuthService.kt new file mode 100644 index 0000000..c212272 --- /dev/null +++ b/data/src/main/java/com/sopt/now/compose/data/service/AuthService.kt @@ -0,0 +1,21 @@ +package com.sopt.now.compose.data.service + +import com.sopt.now.compose.data.dto.request.RequestLoginDto +import com.sopt.now.compose.data.dto.request.RequestSignUpDto +import com.sopt.now.compose.data.dto.response.ResponseLoginDto +import com.sopt.now.compose.data.dto.response.ResponseSignUpDto +import retrofit2.Response +import retrofit2.http.Body +import retrofit2.http.POST + +interface AuthService { + @POST("member/join") + suspend fun postSignup( + @Body request: RequestSignUpDto, + ): Response + + @POST("member/login") + suspend fun postLogin( + @Body request: RequestLoginDto + ): Response +} \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/compose/network/FollowService.kt b/data/src/main/java/com/sopt/now/compose/data/service/FollowerService.kt similarity index 60% rename from app/src/main/java/com/sopt/now/compose/network/FollowService.kt rename to data/src/main/java/com/sopt/now/compose/data/service/FollowerService.kt index 374ceb0..106c9c0 100644 --- a/app/src/main/java/com/sopt/now/compose/network/FollowService.kt +++ b/data/src/main/java/com/sopt/now/compose/data/service/FollowerService.kt @@ -1,11 +1,11 @@ -package com.sopt.now.compose.network +package com.sopt.now.compose.data.service -import com.sopt.now.compose.network.dto.ResponseFollowListDto +import com.sopt.now.compose.data.dto.response.ResponseFollowListDto import retrofit2.Response import retrofit2.http.GET import retrofit2.http.Query -interface FollowService { +interface FollowerService { @GET("/api/users") suspend fun getFollow( @Query("page") page:Int = 2 diff --git a/data/src/main/java/com/sopt/now/compose/data/service/HomeService.kt b/data/src/main/java/com/sopt/now/compose/data/service/HomeService.kt new file mode 100644 index 0000000..b6ce710 --- /dev/null +++ b/data/src/main/java/com/sopt/now/compose/data/service/HomeService.kt @@ -0,0 +1,11 @@ +package com.sopt.now.compose.data.service + + +import com.sopt.now.compose.data.dto.response.ResponseUserDto +import retrofit2.Response +import retrofit2.http.GET + +interface HomeService { + @GET("member/info") + suspend fun getMemberInfo(): Response +} \ No newline at end of file From 05287d129266ba21933a2f64bc5fbab65e1ccc94 Mon Sep 17 00:00:00 2001 From: boiledegg Date: Thu, 27 Jun 2024 23:53:11 +0900 Subject: [PATCH 22/31] =?UTF-8?q?FEAT/#21:=20DTO=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/dto/request/RequestFollowerDto.kt | 10 ++++++++++ .../data/dto/request}/RequestLoginDto.kt | 2 +- .../data/dto/request}/RequestSignUpDto.kt | 2 +- .../data/dto/response}/ResponseFollowListDto.kt | 17 +++++++++++++++-- .../data/dto/response}/ResponseLoginDto.kt | 2 +- .../data/dto/response}/ResponseSignUpDto.kt | 2 +- .../data/dto/response/ResponseUserDto.kt | 4 ++-- 7 files changed, 31 insertions(+), 8 deletions(-) create mode 100644 data/src/main/java/com/sopt/now/compose/data/dto/request/RequestFollowerDto.kt rename {app/src/main/java/com/sopt/now/compose/network/dto => data/src/main/java/com/sopt/now/compose/data/dto/request}/RequestLoginDto.kt (84%) rename {app/src/main/java/com/sopt/now/compose/network/dto => data/src/main/java/com/sopt/now/compose/data/dto/request}/RequestSignUpDto.kt (88%) rename {app/src/main/java/com/sopt/now/compose/network/dto => data/src/main/java/com/sopt/now/compose/data/dto/response}/ResponseFollowListDto.kt (60%) rename {app/src/main/java/com/sopt/now/compose/network/dto => data/src/main/java/com/sopt/now/compose/data/dto/response}/ResponseLoginDto.kt (82%) rename {app/src/main/java/com/sopt/now/compose/network/dto => data/src/main/java/com/sopt/now/compose/data/dto/response}/ResponseSignUpDto.kt (82%) rename app/src/main/java/com/sopt/now/compose/network/dto/ResponseMemberInfoDto.kt => data/src/main/java/com/sopt/now/compose/data/dto/response/ResponseUserDto.kt (86%) diff --git a/data/src/main/java/com/sopt/now/compose/data/dto/request/RequestFollowerDto.kt b/data/src/main/java/com/sopt/now/compose/data/dto/request/RequestFollowerDto.kt new file mode 100644 index 0000000..56e8ed7 --- /dev/null +++ b/data/src/main/java/com/sopt/now/compose/data/dto/request/RequestFollowerDto.kt @@ -0,0 +1,10 @@ +package com.sopt.now.compose.data.dto.request + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class RequestFollowerDto ( + @SerialName("page") + val page: Int +) \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/compose/network/dto/RequestLoginDto.kt b/data/src/main/java/com/sopt/now/compose/data/dto/request/RequestLoginDto.kt similarity index 84% rename from app/src/main/java/com/sopt/now/compose/network/dto/RequestLoginDto.kt rename to data/src/main/java/com/sopt/now/compose/data/dto/request/RequestLoginDto.kt index 19f2b2e..edc8e42 100644 --- a/app/src/main/java/com/sopt/now/compose/network/dto/RequestLoginDto.kt +++ b/data/src/main/java/com/sopt/now/compose/data/dto/request/RequestLoginDto.kt @@ -1,4 +1,4 @@ -package com.sopt.now.compose.network.dto +package com.sopt.now.compose.data.dto.request import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/app/src/main/java/com/sopt/now/compose/network/dto/RequestSignUpDto.kt b/data/src/main/java/com/sopt/now/compose/data/dto/request/RequestSignUpDto.kt similarity index 88% rename from app/src/main/java/com/sopt/now/compose/network/dto/RequestSignUpDto.kt rename to data/src/main/java/com/sopt/now/compose/data/dto/request/RequestSignUpDto.kt index e14d3b6..c225397 100644 --- a/app/src/main/java/com/sopt/now/compose/network/dto/RequestSignUpDto.kt +++ b/data/src/main/java/com/sopt/now/compose/data/dto/request/RequestSignUpDto.kt @@ -1,4 +1,4 @@ -package com.sopt.now.compose.network.dto +package com.sopt.now.compose.data.dto.request import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/app/src/main/java/com/sopt/now/compose/network/dto/ResponseFollowListDto.kt b/data/src/main/java/com/sopt/now/compose/data/dto/response/ResponseFollowListDto.kt similarity index 60% rename from app/src/main/java/com/sopt/now/compose/network/dto/ResponseFollowListDto.kt rename to data/src/main/java/com/sopt/now/compose/data/dto/response/ResponseFollowListDto.kt index d9d8967..69cf70e 100644 --- a/app/src/main/java/com/sopt/now/compose/network/dto/ResponseFollowListDto.kt +++ b/data/src/main/java/com/sopt/now/compose/data/dto/response/ResponseFollowListDto.kt @@ -1,6 +1,5 @@ -package com.sopt.now.compose.network.dto +package com.sopt.now.compose.data.dto.response -import com.sopt.now.compose.models.Follower import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -20,6 +19,20 @@ data class ResponseFollowListDto( val support: Support ){ + @Serializable + data class Follower( + @SerialName("id") + val id:Int, + @SerialName("email") + val email:String, + @SerialName("first_name") + val firstName:String, + @SerialName("last_name") + val lastName:String, + @SerialName("avatar") + val avatar:String + ) + @Serializable data class Support( @SerialName("url") diff --git a/app/src/main/java/com/sopt/now/compose/network/dto/ResponseLoginDto.kt b/data/src/main/java/com/sopt/now/compose/data/dto/response/ResponseLoginDto.kt similarity index 82% rename from app/src/main/java/com/sopt/now/compose/network/dto/ResponseLoginDto.kt rename to data/src/main/java/com/sopt/now/compose/data/dto/response/ResponseLoginDto.kt index 604c902..cf0e463 100644 --- a/app/src/main/java/com/sopt/now/compose/network/dto/ResponseLoginDto.kt +++ b/data/src/main/java/com/sopt/now/compose/data/dto/response/ResponseLoginDto.kt @@ -1,4 +1,4 @@ -package com.sopt.now.compose.network.dto +package com.sopt.now.compose.data.dto.response import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/app/src/main/java/com/sopt/now/compose/network/dto/ResponseSignUpDto.kt b/data/src/main/java/com/sopt/now/compose/data/dto/response/ResponseSignUpDto.kt similarity index 82% rename from app/src/main/java/com/sopt/now/compose/network/dto/ResponseSignUpDto.kt rename to data/src/main/java/com/sopt/now/compose/data/dto/response/ResponseSignUpDto.kt index e18a780..e38457f 100644 --- a/app/src/main/java/com/sopt/now/compose/network/dto/ResponseSignUpDto.kt +++ b/data/src/main/java/com/sopt/now/compose/data/dto/response/ResponseSignUpDto.kt @@ -1,4 +1,4 @@ -package com.sopt.now.compose.network.dto +package com.sopt.now.compose.data.dto.response import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/app/src/main/java/com/sopt/now/compose/network/dto/ResponseMemberInfoDto.kt b/data/src/main/java/com/sopt/now/compose/data/dto/response/ResponseUserDto.kt similarity index 86% rename from app/src/main/java/com/sopt/now/compose/network/dto/ResponseMemberInfoDto.kt rename to data/src/main/java/com/sopt/now/compose/data/dto/response/ResponseUserDto.kt index 714f718..3dfe242 100644 --- a/app/src/main/java/com/sopt/now/compose/network/dto/ResponseMemberInfoDto.kt +++ b/data/src/main/java/com/sopt/now/compose/data/dto/response/ResponseUserDto.kt @@ -1,10 +1,10 @@ -package com.sopt.now.compose.network.dto +package com.sopt.now.compose.data.dto.response import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @Serializable -data class ResponseMemberInfoDto( +data class ResponseUserDto( @SerialName("code") val code: Int, @SerialName("message") From b43383899f900125f9bc1380362ee8bc679caa45 Mon Sep 17 00:00:00 2001 From: boiledegg Date: Thu, 27 Jun 2024 23:53:56 +0900 Subject: [PATCH 23/31] =?UTF-8?q?FEAT/#21:=20DataSource=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../compose/data/datasource/AuthDataSource.kt | 12 +++++++++++ .../data/datasource/FollowerDataSource.kt | 9 ++++++++ .../compose/data/datasource/HomeDataSource.kt | 8 +++++++ .../data/datasourceimpl/AuthDataSourceImpl.kt | 21 +++++++++++++++++++ .../datasourceimpl/FollowerDataSourceImpl.kt | 16 ++++++++++++++ .../data/datasourceimpl/HomeDataSourceImpl.kt | 13 ++++++++++++ 6 files changed, 79 insertions(+) create mode 100644 data/src/main/java/com/sopt/now/compose/data/datasource/AuthDataSource.kt create mode 100644 data/src/main/java/com/sopt/now/compose/data/datasource/FollowerDataSource.kt create mode 100644 data/src/main/java/com/sopt/now/compose/data/datasource/HomeDataSource.kt create mode 100644 data/src/main/java/com/sopt/now/compose/data/datasourceimpl/AuthDataSourceImpl.kt create mode 100644 data/src/main/java/com/sopt/now/compose/data/datasourceimpl/FollowerDataSourceImpl.kt create mode 100644 data/src/main/java/com/sopt/now/compose/data/datasourceimpl/HomeDataSourceImpl.kt diff --git a/data/src/main/java/com/sopt/now/compose/data/datasource/AuthDataSource.kt b/data/src/main/java/com/sopt/now/compose/data/datasource/AuthDataSource.kt new file mode 100644 index 0000000..5dfddb1 --- /dev/null +++ b/data/src/main/java/com/sopt/now/compose/data/datasource/AuthDataSource.kt @@ -0,0 +1,12 @@ +package com.sopt.now.compose.data.datasource + +import com.sopt.now.compose.data.dto.request.RequestLoginDto +import com.sopt.now.compose.data.dto.request.RequestSignUpDto +import com.sopt.now.compose.data.dto.response.ResponseLoginDto +import com.sopt.now.compose.data.dto.response.ResponseSignUpDto +import retrofit2.Response + +interface AuthDataSource { + suspend fun postLogin(request: RequestLoginDto): Response + suspend fun postSignUp(request: RequestSignUpDto): Response +} \ No newline at end of file diff --git a/data/src/main/java/com/sopt/now/compose/data/datasource/FollowerDataSource.kt b/data/src/main/java/com/sopt/now/compose/data/datasource/FollowerDataSource.kt new file mode 100644 index 0000000..cc0335c --- /dev/null +++ b/data/src/main/java/com/sopt/now/compose/data/datasource/FollowerDataSource.kt @@ -0,0 +1,9 @@ +package com.sopt.now.compose.data.datasource + +import com.sopt.now.compose.data.dto.request.RequestFollowerDto +import com.sopt.now.compose.data.dto.response.ResponseFollowListDto +import retrofit2.Response + +interface FollowerDataSource { + suspend fun getFollowerList(request: RequestFollowerDto): Response +} \ No newline at end of file diff --git a/data/src/main/java/com/sopt/now/compose/data/datasource/HomeDataSource.kt b/data/src/main/java/com/sopt/now/compose/data/datasource/HomeDataSource.kt new file mode 100644 index 0000000..46f63f8 --- /dev/null +++ b/data/src/main/java/com/sopt/now/compose/data/datasource/HomeDataSource.kt @@ -0,0 +1,8 @@ +package com.sopt.now.compose.data.datasource + +import com.sopt.now.compose.data.dto.response.ResponseUserDto +import retrofit2.Response + +interface HomeDataSource { + suspend fun getUserInfo(): Response +} \ No newline at end of file diff --git a/data/src/main/java/com/sopt/now/compose/data/datasourceimpl/AuthDataSourceImpl.kt b/data/src/main/java/com/sopt/now/compose/data/datasourceimpl/AuthDataSourceImpl.kt new file mode 100644 index 0000000..3233967 --- /dev/null +++ b/data/src/main/java/com/sopt/now/compose/data/datasourceimpl/AuthDataSourceImpl.kt @@ -0,0 +1,21 @@ +package com.sopt.now.compose.data.datasourceimpl + +import com.sopt.now.compose.data.datasource.AuthDataSource +import com.sopt.now.compose.data.dto.request.RequestLoginDto +import com.sopt.now.compose.data.dto.request.RequestSignUpDto +import com.sopt.now.compose.data.dto.response.ResponseLoginDto +import com.sopt.now.compose.data.dto.response.ResponseSignUpDto +import com.sopt.now.compose.data.service.AuthService +import retrofit2.Response +import javax.inject.Inject + +class AuthDataSourceImpl @Inject constructor( + private val authService: AuthService +): AuthDataSource { + + override suspend fun postLogin(request: RequestLoginDto): Response = + authService.postLogin(request) + + override suspend fun postSignUp(request: RequestSignUpDto): Response = + authService.postSignup(request) +} \ No newline at end of file diff --git a/data/src/main/java/com/sopt/now/compose/data/datasourceimpl/FollowerDataSourceImpl.kt b/data/src/main/java/com/sopt/now/compose/data/datasourceimpl/FollowerDataSourceImpl.kt new file mode 100644 index 0000000..e7c9a89 --- /dev/null +++ b/data/src/main/java/com/sopt/now/compose/data/datasourceimpl/FollowerDataSourceImpl.kt @@ -0,0 +1,16 @@ +package com.sopt.now.compose.data.datasourceimpl + +import com.sopt.now.compose.data.datasource.FollowerDataSource +import com.sopt.now.compose.data.dto.request.RequestFollowerDto +import com.sopt.now.compose.data.dto.response.ResponseFollowListDto +import com.sopt.now.compose.data.service.FollowerService +import retrofit2.Response +import javax.inject.Inject + +class FollowerDataSourceImpl @Inject constructor( + private val followerService: FollowerService +): FollowerDataSource { + + override suspend fun getFollowerList(request: RequestFollowerDto): Response = + followerService.getFollow(request.page) +} \ No newline at end of file diff --git a/data/src/main/java/com/sopt/now/compose/data/datasourceimpl/HomeDataSourceImpl.kt b/data/src/main/java/com/sopt/now/compose/data/datasourceimpl/HomeDataSourceImpl.kt new file mode 100644 index 0000000..780daa2 --- /dev/null +++ b/data/src/main/java/com/sopt/now/compose/data/datasourceimpl/HomeDataSourceImpl.kt @@ -0,0 +1,13 @@ +package com.sopt.now.compose.data.datasourceimpl + +import com.sopt.now.compose.data.dto.response.ResponseUserDto +import com.sopt.now.compose.data.service.HomeService +import retrofit2.Response +import javax.inject.Inject + +class HomeDataSourceImpl @Inject constructor( + private val homeService: HomeService +){ + suspend fun getUserInfo():Response = + homeService.getMemberInfo() +} \ No newline at end of file From e15b56a09f0f9eb87ef0b40a79e4120bdcb74532 Mon Sep 17 00:00:00 2001 From: boiledegg Date: Thu, 27 Jun 2024 23:54:14 +0900 Subject: [PATCH 24/31] =?UTF-8?q?FEAT/#21:=20Repository=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84=EC=B2=B4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/repositoryimpl/AuthRepositoryImpl.kt | 69 +++++++++++++++++++ .../repositoryimpl/FollowerRepositoryImpl.kt | 43 ++++++++++++ .../data/repositoryimpl/HomeRepositoryImpl.kt | 36 ++++++++++ 3 files changed, 148 insertions(+) create mode 100644 data/src/main/java/com/sopt/now/compose/data/repositoryimpl/AuthRepositoryImpl.kt create mode 100644 data/src/main/java/com/sopt/now/compose/data/repositoryimpl/FollowerRepositoryImpl.kt create mode 100644 data/src/main/java/com/sopt/now/compose/data/repositoryimpl/HomeRepositoryImpl.kt diff --git a/data/src/main/java/com/sopt/now/compose/data/repositoryimpl/AuthRepositoryImpl.kt b/data/src/main/java/com/sopt/now/compose/data/repositoryimpl/AuthRepositoryImpl.kt new file mode 100644 index 0000000..3534d6e --- /dev/null +++ b/data/src/main/java/com/sopt/now/compose/data/repositoryimpl/AuthRepositoryImpl.kt @@ -0,0 +1,69 @@ +package com.sopt.now.compose.data.repositoryimpl + +import com.sopt.now.compose.data.datasource.AuthDataSource +import com.sopt.now.compose.data.dto.request.RequestLoginDto +import com.sopt.now.compose.data.dto.request.RequestSignUpDto +import com.sopt.now.compose.domain.entity.request.LoginRequestEntity +import com.sopt.now.compose.domain.entity.request.SignupRequestEntity +import com.sopt.now.compose.domain.entity.response.LoginResponseEntity +import com.sopt.now.compose.domain.entity.response.SignupResponseEntity +import com.sopt.now.compose.domain.entity.response.UserResponseEntity +import com.sopt.now.compose.domain.repository.AuthRepository +import org.json.JSONObject +import javax.inject.Inject + +class AuthRepositoryImpl @Inject constructor( + private val authDataSource: AuthDataSource +) : AuthRepository { + + override suspend fun postLogin(request: LoginRequestEntity): Result = + runCatching { + val response = authDataSource.postLogin( + request = RequestLoginDto( + authenticationId = request.authenticationId, + password = request.password + ) + ) + if (response.isSuccessful) { + LoginResponseEntity( + code = response.code(), + memberId = response.headers()[LOCATION] ?: throw Exception(response.message()) + ) + } else { + throw Exception( + JSONObject( + response.errorBody()?.string().orEmpty() + ).getString(MESSAGE) + ) + } + } + + override suspend fun postSignUp(request: SignupRequestEntity): Result = + runCatching { + val response = authDataSource.postSignUp( + request = RequestSignUpDto( + authenticationId = request.authenticationId, + password = request.password, + nickname = request.nickname, + phone = request.phone + ) + ) + if (response.isSuccessful) { + SignupResponseEntity( + code = response.code(), + memberId = response.headers()[LOCATION] ?: throw Exception(response.message()) + ) + } else { + throw Exception( + JSONObject( + response.errorBody()?.string().orEmpty() + ).getString(MESSAGE) + ) + } + } + + companion object { + private const val MESSAGE = "message" + private const val LOCATION = "location" + } +} \ No newline at end of file diff --git a/data/src/main/java/com/sopt/now/compose/data/repositoryimpl/FollowerRepositoryImpl.kt b/data/src/main/java/com/sopt/now/compose/data/repositoryimpl/FollowerRepositoryImpl.kt new file mode 100644 index 0000000..e3d9fd2 --- /dev/null +++ b/data/src/main/java/com/sopt/now/compose/data/repositoryimpl/FollowerRepositoryImpl.kt @@ -0,0 +1,43 @@ +package com.sopt.now.compose.data.repositoryimpl + +import com.sopt.now.compose.data.datasource.FollowerDataSource +import com.sopt.now.compose.data.dto.request.RequestFollowerDto +import com.sopt.now.compose.domain.entity.request.FollowerRequestEntity +import com.sopt.now.compose.domain.entity.response.FollowerResponseEntity +import com.sopt.now.compose.domain.repository.FollowerRepository +import org.json.JSONObject +import javax.inject.Inject + +class FollowerRepositoryImpl @Inject constructor( + private val followerDataSource: FollowerDataSource +) : FollowerRepository { + + override suspend fun getFollowers(request: FollowerRequestEntity): Result> = + runCatching { + val dto = RequestFollowerDto(page = request.page) + val response = followerDataSource.getFollowerList(dto) + if (response.isSuccessful) { + with(response.body()?.data!!) { + map { + FollowerResponseEntity( + id = it.id, + email = it.email, + firstName = it.firstName, + lastName = it.lastName, + avatar = it.avatar + ) + } + } + } else { + throw Exception( + JSONObject( + response.errorBody()?.string().orEmpty() + ).getString(MESSAGE) + ) + } + } + + companion object { + private const val MESSAGE = "message" + } +} \ No newline at end of file diff --git a/data/src/main/java/com/sopt/now/compose/data/repositoryimpl/HomeRepositoryImpl.kt b/data/src/main/java/com/sopt/now/compose/data/repositoryimpl/HomeRepositoryImpl.kt new file mode 100644 index 0000000..4c7ab2b --- /dev/null +++ b/data/src/main/java/com/sopt/now/compose/data/repositoryimpl/HomeRepositoryImpl.kt @@ -0,0 +1,36 @@ +package com.sopt.now.compose.data.repositoryimpl + +import com.sopt.now.compose.data.datasource.HomeDataSource +import com.sopt.now.compose.domain.entity.response.UserResponseEntity +import com.sopt.now.compose.domain.repository.HomeRepository +import org.json.JSONObject +import javax.inject.Inject + +class HomeRepositoryImpl @Inject constructor( + private val homeDataSource: HomeDataSource +) : HomeRepository { + + override suspend fun getUser(): Result = + runCatching { + val response = homeDataSource.getUserInfo() + if (response.isSuccessful) { + with(response.body()!!.data) { + UserResponseEntity( + authenticationId = authenticationId, + nickname = nickname, + phone = phone + ) + } + } else { + throw Exception( + JSONObject( + response.errorBody()?.string().orEmpty() + ).getString(MESSAGE) + ) + } + } + + companion object { + private const val MESSAGE = "message" + } +} \ No newline at end of file From f0b6d4307adffd96a24a4d676777bad961b1a324 Mon Sep 17 00:00:00 2001 From: boiledegg Date: Thu, 27 Jun 2024 23:56:43 +0900 Subject: [PATCH 25/31] =?UTF-8?q?FEAT/#21:=20=EB=B2=84=EC=A0=84=20?= =?UTF-8?q?=EC=B9=B4=ED=83=88=EB=A1=9C=EA=B7=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gradle/libs.versions.toml | 7 ++++--- presentation/build.gradle | 37 ++++++++++++++++++++++++++++++------- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 1ed1fb7..4f1f66e 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -21,6 +21,8 @@ coilCompose = '2.6.0' hiltCompiler = '2.51.1' hiltNavigation = '1.2.0' lifecycleRunTime = '2.8.1' +appcompat = '1.7.0' +androidMaterial = '1.12.0' [libraries] core-ktx = {group = "androidx.core", name = "core-ktx", version.ref = "coreKtx"} @@ -43,14 +45,13 @@ retrofit2-serialization-converter = {group = "com.jakewharton.retrofit", name = okhttp-bom = {group = "com.squareup.okhttp3", name = "okhttp-bom", version.ref = "okhttpBom"} okhttp = {group = "com.squareup.okhttp3", name = "okhttp"} okhttp-logging-interceptor = {group = "com.squareup.okhttp3", name = "okhttp-logging-interceptor"} - coil-compose = {group = "io.coil-kt", name = "coil-compose", version.ref = "coilCompose"} - hiltAndroid = {group = "com.google.dagger", name = "hilt-android", version.ref = "hiltAndroid"} hiltCompiler = {group = "com.google.dagger", name = "hilt-compiler", version.ref = "hiltCompiler"} hiltNavigation = {group = "androidx.hilt", name = "hilt-navigation-compose", version.ref = "hiltNavigation"} - lifecycle-runtime-compose = {group = "androidx.lifecycle", name = "lifecycle-runtime-compose", version.ref = "lifecycleRunTime"} +androidx-appcompat = {group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat"} +android-material = {group = "com.google.android.material", name = "material", version.ref = "androidMaterial"} [plugins] android-application = { id = "com.android.application", version.ref = "android" } diff --git a/presentation/build.gradle b/presentation/build.gradle index 76b09fc..2bff465 100644 --- a/presentation/build.gradle +++ b/presentation/build.gradle @@ -1,6 +1,9 @@ plugins { id 'com.android.library' id 'org.jetbrains.kotlin.android' + id 'com.google.dagger.hilt.android' + id 'kotlin-android' + id 'kotlin-kapt' } android { @@ -30,13 +33,33 @@ android { } dependencies { - - implementation 'androidx.core:core-ktx:1.13.1' - implementation 'androidx.appcompat:appcompat:1.7.0' - implementation 'com.google.android.material:material:1.12.0' - testImplementation 'junit:junit:4.13.2' - androidTestImplementation 'androidx.test.ext:junit:1.2.0' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.0' + implementation(libs.core.ktx) + implementation(libs.lifecycle.runtime.ktx) + implementation(libs.activity.compose) + implementation(platform(libs.compose.bom)) + implementation(libs.compose.ui) + implementation(libs.compose.ui.graphics) + implementation(libs.compose.ui.tooling) + implementation(libs.compose.material3) + testImplementation(libs.junit) + androidTestImplementation(libs.test.ext.junit) + androidTestImplementation(libs.test.espresso.eore) + androidTestImplementation(platform(libs.compose.bom)) + androidTestImplementation(libs.compose.ui.test.junit4) + androidTestImplementation(libs.compose.ui.tooling) + debugImplementation(libs.compose.ui.test.manifest) + implementation(libs.navigation.compose) + implementation(libs.retrofit2.retrofit) + implementation(libs.serialization.json) + implementation(libs.retrofit2.serialization.converter) + implementation(platform(libs.okhttp.bom)) + implementation(libs.okhttp) + implementation(libs.okhttp.logging.interceptor) + implementation(libs.coil.compose) + implementation(libs.hiltAndroid) + kapt(libs.hiltCompiler) + implementation(libs.hiltNavigation) + implementation(libs.lifecycle.runtime.compose) implementation project(path: ':domain') } \ No newline at end of file From 23e78de5ff0a2e4893a79259cec7420c6ad78674 Mon Sep 17 00:00:00 2001 From: boiledegg Date: Sun, 30 Jun 2024 19:44:13 +0900 Subject: [PATCH 26/31] =?UTF-8?q?CHORE/#21:=20Gradle=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 3 +-- data/build.gradle | 15 ++++++++++----- domain/build.gradle | 20 +++++++++++++++----- gradle/libs.versions.toml | 4 ++-- gradle/wrapper/gradle-wrapper.properties | 2 +- presentation/build.gradle | 21 ++++++++++++++------- 6 files changed, 43 insertions(+), 22 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index fad6521..ff1d0f6 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -53,7 +53,7 @@ android { } packaging { resources { - excludes += '/META-INF/{AL2.0,LGPL2.1}' + it.excludes += '/META-INF/{AL2.0,LGPL2.1}' } } @@ -81,7 +81,6 @@ dependencies { implementation(libs.retrofit2.serialization.converter) implementation(platform(libs.okhttp.bom)) implementation(libs.okhttp) - implementation(libs.okhttp.logging.interceptor) implementation(libs.coil.compose) implementation(libs.hiltAndroid) kapt(libs.hiltCompiler) diff --git a/data/build.gradle b/data/build.gradle index 453071c..60832bc 100644 --- a/data/build.gradle +++ b/data/build.gradle @@ -1,5 +1,5 @@ plugins { - alias(libs.plugins.android.application) + alias(libs.plugins.android.library) alias(libs.plugins.jetbrains.kotlin.android) alias(libs.plugins.jetbrains.kotlin.serialization) alias(libs.plugins.google.dagger.hilt.android) @@ -30,11 +30,17 @@ android { } } compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 } kotlinOptions { - jvmTarget = '1.8' + jvmTarget = '17' + } + buildFeatures { + buildConfig true + } + composeOptions { + kotlinCompilerExtensionVersion '1.5.1' } } @@ -54,7 +60,6 @@ dependencies { implementation(libs.retrofit2.serialization.converter) implementation(platform(libs.okhttp.bom)) implementation(libs.okhttp) - implementation(libs.okhttp.logging.interceptor) implementation project(path: ':domain') } \ No newline at end of file diff --git a/domain/build.gradle b/domain/build.gradle index aa90ae8..0a44d00 100644 --- a/domain/build.gradle +++ b/domain/build.gradle @@ -1,5 +1,5 @@ plugins { - alias(libs.plugins.android.application) + alias(libs.plugins.android.library) alias(libs.plugins.jetbrains.kotlin.android) alias(libs.plugins.jetbrains.kotlin.serialization) alias(libs.plugins.google.dagger.hilt.android) @@ -16,6 +16,9 @@ android { testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" consumerProguardFiles "consumer-rules.pro" + vectorDrawables { + useSupportLibrary true + } } buildTypes { @@ -25,11 +28,19 @@ android { } } compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 } kotlinOptions { - jvmTarget = '1.8' + jvmTarget = '17' + } + composeOptions { + kotlinCompilerExtensionVersion '1.5.1' + } + packaging { + resources { + excludes += '/META-INF/{AL2.0,LGPL2.1}' + } } } @@ -48,5 +59,4 @@ dependencies { implementation(libs.retrofit2.serialization.converter) implementation(platform(libs.okhttp.bom)) implementation(libs.okhttp) - implementation(libs.okhttp.logging.interceptor) } \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 4f1f66e..a5f0cfc 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,6 +1,6 @@ [versions] -android = '8.3.2' -androidLibrary = '8.3.2' +android = "8.5.0" +androidLibrary = "8.5.0" jetbrainsKotlinAndroid = '1.9.0' jetbrainsKotlinSerialization = '1.9.0' hiltAndroid = '2.51' diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 119c6d4..402a85e 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ #Wed Mar 27 09:57:11 JST 2024 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/presentation/build.gradle b/presentation/build.gradle index 2bff465..6ee8e30 100644 --- a/presentation/build.gradle +++ b/presentation/build.gradle @@ -1,7 +1,8 @@ plugins { - id 'com.android.library' - id 'org.jetbrains.kotlin.android' - id 'com.google.dagger.hilt.android' + alias(libs.plugins.android.library) + alias(libs.plugins.jetbrains.kotlin.android) + alias(libs.plugins.jetbrains.kotlin.serialization) + alias(libs.plugins.google.dagger.hilt.android) id 'kotlin-android' id 'kotlin-kapt' } @@ -24,11 +25,18 @@ android { } } compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 } kotlinOptions { - jvmTarget = '1.8' + jvmTarget = '17' + } + + buildFeatures{ + compose = true + } + composeOptions { + kotlinCompilerExtensionVersion '1.5.1' } } @@ -54,7 +62,6 @@ dependencies { implementation(libs.retrofit2.serialization.converter) implementation(platform(libs.okhttp.bom)) implementation(libs.okhttp) - implementation(libs.okhttp.logging.interceptor) implementation(libs.coil.compose) implementation(libs.hiltAndroid) kapt(libs.hiltCompiler) From 7dda32fcecfccfd1431c18d67381ec888320dfdf Mon Sep 17 00:00:00 2001 From: boiledegg Date: Sun, 30 Jun 2024 19:44:49 +0900 Subject: [PATCH 27/31] =?UTF-8?q?FEAT/#21:=20Presentation=20=EB=A0=88?= =?UTF-8?q?=EC=9D=B4=EC=96=B4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../compose/ui/screens/home/HomeUiState.kt | 18 -- .../compose/ui/screens/home/HomeViewModel.kt | 84 --------- .../ui/screens/login/LoginViewModel.kt | 89 --------- .../ui/screens/signup/SignUpViewModel.kt | 82 --------- .../composables/ButtonComposable.kt | 2 +- .../composables/ScreenWithImage.kt | 2 +- .../TextFieldWithTitleComposable.kt | 2 +- .../TitleAndContentTextComposable.kt | 2 +- .../presentation}/ext/NavigationExt.kt | 2 +- .../navigation/ApplicationNavigation.kt | 12 +- .../navigation/NavigationDestination.kt | 2 +- .../navigation/ScreenDestinations.kt | 4 +- .../screens/home/FollowerUiState.kt | 14 ++ .../presentation}/screens/home/HomeScreen.kt | 76 ++++++-- .../presentation/screens/home/HomeUiState.kt | 17 ++ .../screens/home/HomeViewModel.kt | 75 ++++++++ .../screens/login/LoginScreen.kt | 32 ++-- .../screens/login/LoginUiState.kt | 2 +- .../screens/login/LoginViewModel.kt | 68 +++++++ .../screens/profile/ProfileScreen.kt | 32 ++-- .../screens/profile/ProfileUiState.kt | 13 ++ .../screens/profile/ProfileViewModel.kt | 40 ++--- .../screens/search/SearchScreen.kt | 6 +- .../screens/search/SearchViewModel.kt | 19 ++ .../screens/signup/SignUpScreen.kt | 10 +- .../screens/signup/SignUpState.kt | 2 +- .../screens/signup/SignUpViewModel.kt | 64 +++++++ .../compose/presentation/ui/theme/Color.kt | 11 ++ .../compose/presentation/ui/theme}/SoptApp.kt | 14 +- .../compose/presentation/ui/theme/Theme.kt | 70 ++++++++ .../now/compose/presentation/ui/theme/Type.kt | 34 ++++ .../src/main/res/drawable/ic_broken_image.xml | 25 +++ .../res/drawable/ic_launcher_background.xml | 170 ++++++++++++++++++ .../res/drawable/ic_launcher_foreground.xml | 30 ++++ .../src/main/res/drawable/loading_img.xml | 94 ++++++++++ presentation/src/main/res/values/colors.xml | 10 ++ presentation/src/main/res/values/strings.xml | 65 +++++++ presentation/src/main/res/values/themes.xml | 5 + 38 files changed, 927 insertions(+), 372 deletions(-) delete mode 100644 app/src/main/java/com/sopt/now/compose/ui/screens/home/HomeUiState.kt delete mode 100644 app/src/main/java/com/sopt/now/compose/ui/screens/home/HomeViewModel.kt delete mode 100644 app/src/main/java/com/sopt/now/compose/ui/screens/login/LoginViewModel.kt delete mode 100644 app/src/main/java/com/sopt/now/compose/ui/screens/signup/SignUpViewModel.kt rename {app/src/main/java/com/sopt/now/compose/ui => presentation/src/main/java/com/sopt/now/compose/presentation}/composables/ButtonComposable.kt (94%) rename {app/src/main/java/com/sopt/now/compose/ui => presentation/src/main/java/com/sopt/now/compose/presentation}/composables/ScreenWithImage.kt (91%) rename {app/src/main/java/com/sopt/now/compose/ui => presentation/src/main/java/com/sopt/now/compose/presentation}/composables/TextFieldWithTitleComposable.kt (96%) rename {app/src/main/java/com/sopt/now/compose/ui => presentation/src/main/java/com/sopt/now/compose/presentation}/composables/TitleAndContentTextComposable.kt (94%) rename {app/src/main/java/com/sopt/now/compose => presentation/src/main/java/com/sopt/now/compose/presentation}/ext/NavigationExt.kt (87%) rename {app/src/main/java/com/sopt/now/compose/ui => presentation/src/main/java/com/sopt/now/compose/presentation}/navigation/ApplicationNavigation.kt (75%) rename {app/src/main/java/com/sopt/now/compose/ui => presentation/src/main/java/com/sopt/now/compose/presentation}/navigation/NavigationDestination.kt (82%) rename {app/src/main/java/com/sopt/now/compose/ui => presentation/src/main/java/com/sopt/now/compose/presentation}/navigation/ScreenDestinations.kt (93%) create mode 100644 presentation/src/main/java/com/sopt/now/compose/presentation/screens/home/FollowerUiState.kt rename {app/src/main/java/com/sopt/now/compose/ui => presentation/src/main/java/com/sopt/now/compose/presentation}/screens/home/HomeScreen.kt (70%) create mode 100644 presentation/src/main/java/com/sopt/now/compose/presentation/screens/home/HomeUiState.kt create mode 100644 presentation/src/main/java/com/sopt/now/compose/presentation/screens/home/HomeViewModel.kt rename {app/src/main/java/com/sopt/now/compose/ui => presentation/src/main/java/com/sopt/now/compose/presentation}/screens/login/LoginScreen.kt (81%) rename {app/src/main/java/com/sopt/now/compose/ui => presentation/src/main/java/com/sopt/now/compose/presentation}/screens/login/LoginUiState.kt (71%) create mode 100644 presentation/src/main/java/com/sopt/now/compose/presentation/screens/login/LoginViewModel.kt rename {app/src/main/java/com/sopt/now/compose/ui => presentation/src/main/java/com/sopt/now/compose/presentation}/screens/profile/ProfileScreen.kt (79%) create mode 100644 presentation/src/main/java/com/sopt/now/compose/presentation/screens/profile/ProfileUiState.kt rename {app/src/main/java/com/sopt/now/compose/ui => presentation/src/main/java/com/sopt/now/compose/presentation}/screens/profile/ProfileViewModel.kt (51%) rename {app/src/main/java/com/sopt/now/compose/ui => presentation/src/main/java/com/sopt/now/compose/presentation}/screens/search/SearchScreen.kt (78%) create mode 100644 presentation/src/main/java/com/sopt/now/compose/presentation/screens/search/SearchViewModel.kt rename {app/src/main/java/com/sopt/now/compose/ui => presentation/src/main/java/com/sopt/now/compose/presentation}/screens/signup/SignUpScreen.kt (93%) rename {app/src/main/java/com/sopt/now/compose/ui => presentation/src/main/java/com/sopt/now/compose/presentation}/screens/signup/SignUpState.kt (79%) create mode 100644 presentation/src/main/java/com/sopt/now/compose/presentation/screens/signup/SignUpViewModel.kt create mode 100644 presentation/src/main/java/com/sopt/now/compose/presentation/ui/theme/Color.kt rename {app/src/main/java/com/sopt/now/compose/ui => presentation/src/main/java/com/sopt/now/compose/presentation/ui/theme}/SoptApp.kt (81%) create mode 100644 presentation/src/main/java/com/sopt/now/compose/presentation/ui/theme/Theme.kt create mode 100644 presentation/src/main/java/com/sopt/now/compose/presentation/ui/theme/Type.kt create mode 100644 presentation/src/main/res/drawable/ic_broken_image.xml create mode 100644 presentation/src/main/res/drawable/ic_launcher_background.xml create mode 100644 presentation/src/main/res/drawable/ic_launcher_foreground.xml create mode 100644 presentation/src/main/res/drawable/loading_img.xml create mode 100644 presentation/src/main/res/values/colors.xml create mode 100644 presentation/src/main/res/values/strings.xml create mode 100644 presentation/src/main/res/values/themes.xml diff --git a/app/src/main/java/com/sopt/now/compose/ui/screens/home/HomeUiState.kt b/app/src/main/java/com/sopt/now/compose/ui/screens/home/HomeUiState.kt deleted file mode 100644 index d0304a3..0000000 --- a/app/src/main/java/com/sopt/now/compose/ui/screens/home/HomeUiState.kt +++ /dev/null @@ -1,18 +0,0 @@ -package com.sopt.now.compose.ui.screens.home - -import com.sopt.now.compose.models.Follower -import com.sopt.now.compose.models.User - -sealed interface HomeUiState { - data class Success( - val user: User, - val follower: List - ) : HomeUiState - data class Loading( - val isUserSuccess: Boolean = false, - val isFollowerSuccess: Boolean = false, - var user: User = User(), - var follower: List = listOf() - ): HomeUiState - data object Error: HomeUiState -} \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/compose/ui/screens/home/HomeViewModel.kt b/app/src/main/java/com/sopt/now/compose/ui/screens/home/HomeViewModel.kt deleted file mode 100644 index 3344c49..0000000 --- a/app/src/main/java/com/sopt/now/compose/ui/screens/home/HomeViewModel.kt +++ /dev/null @@ -1,84 +0,0 @@ -package com.sopt.now.compose.ui.screens.home - -import android.util.Log -import androidx.lifecycle.ViewModel -import androidx.lifecycle.viewModelScope -import com.sopt.now.compose.container.repository.FollowerRepository -import com.sopt.now.compose.container.repository.MemberRepository -import dagger.hilt.android.lifecycle.HiltViewModel -import kotlinx.coroutines.flow.MutableStateFlow -import kotlinx.coroutines.flow.StateFlow -import kotlinx.coroutines.flow.asStateFlow -import kotlinx.coroutines.launch -import javax.inject.Inject - -private const val TAG = "HomeViewModel" - -@HiltViewModel -class HomeViewModel @Inject constructor( - private val followerRepository: FollowerRepository, - private val authRepository: MemberRepository -) : ViewModel() { - - private val _uiState = MutableStateFlow(HomeUiState.Loading()) - val uiState: StateFlow = _uiState.asStateFlow() - - private fun updateUiState( - state: HomeUiState.Loading = _uiState.value as HomeUiState.Loading - ) { - if (state.isUserSuccess && state.isFollowerSuccess) { - _uiState.value = HomeUiState.Success( - user = state.user, - follower = state.follower - ) - } else { - _uiState.value = HomeUiState.Error - } - } - - fun fetchNetworkData() { - fetchUserInfo() - } - - private fun fetchUserInfo() { - viewModelScope.launch { - val result = authRepository.getUserInfo() - result.fold( - onSuccess = { - val state = _uiState.value as HomeUiState.Loading - _uiState.value = HomeUiState.Loading( - isUserSuccess = true, - user = it, - isFollowerSuccess = state.isFollowerSuccess, - follower = state.follower - ) - fetchFollowers() - }, - onFailure = { - Log.d(TAG, it.message.toString()) - } - ) - } - } - - private fun fetchFollowers() = viewModelScope.launch { - followerRepository.getFollowers().fold( - onSuccess = { - val followers = it.body()?.data - if(it.isSuccessful) { - val state = _uiState.value as HomeUiState.Loading - _uiState.value = HomeUiState.Loading( - isUserSuccess = state.isUserSuccess, - isFollowerSuccess = true, - user = state.user, - follower = followers.orEmpty() - ) - updateUiState() - } - }, - onFailure = { - Log.d(TAG, it.message.toString()) - } - ) - } -} \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/compose/ui/screens/login/LoginViewModel.kt b/app/src/main/java/com/sopt/now/compose/ui/screens/login/LoginViewModel.kt deleted file mode 100644 index 24b18c7..0000000 --- a/app/src/main/java/com/sopt/now/compose/ui/screens/login/LoginViewModel.kt +++ /dev/null @@ -1,89 +0,0 @@ -package com.sopt.now.compose.ui.screens.login - -import androidx.lifecycle.ViewModel -import androidx.lifecycle.viewModelScope -import com.sopt.now.compose.container.repository.AuthRepository -import com.sopt.now.compose.container.repository.UserRepository -import com.sopt.now.compose.network.dto.RequestLoginDto -import dagger.hilt.android.lifecycle.HiltViewModel -import kotlinx.coroutines.flow.MutableStateFlow -import kotlinx.coroutines.flow.StateFlow -import kotlinx.coroutines.flow.asStateFlow -import kotlinx.coroutines.flow.update -import kotlinx.coroutines.launch -import kotlinx.serialization.json.Json -import kotlinx.serialization.json.jsonObject -import javax.inject.Inject - -@HiltViewModel -class LoginViewModel @Inject constructor( - private val userRepository: UserRepository, - private val authRepository: AuthRepository -): ViewModel() { - private val _uiState = MutableStateFlow(LoginUiState()) - val uiState: StateFlow = _uiState.asStateFlow() - - fun updateUiState( - id: String = _uiState.value.id, - pw: String = _uiState.value.password, - isSuccess:Boolean = _uiState.value.isSuccess, - message: String = _uiState.value.message - - ) { - _uiState.update { currentState -> - currentState.copy( - id = id, - password = pw, - isSuccess = isSuccess, - message = message - ) - } - } - - fun postLogin(request: RequestLoginDto = getRequestLoginDto()) { - viewModelScope.launch { - authRepository.postLogin(request).fold( - onSuccess = { - if(it.isSuccessful){ - val userId = it.headers()[HEADER_NAME] - updateUiState( - isSuccess = true, - message = userId.toString() - ) - setUserIdInPreference(userId = userId.toString()) - } else { - val error = it.errorBody()?.string() - if (error != null) { - val jsonMessage = Json.parseToJsonElement(error) - - updateUiState( - isSuccess = false, - message = jsonMessage.jsonObject[JSON_NAME].toString() - ) - } - } - }, - onFailure = { - updateUiState( - isSuccess = false, - message = "서버 에러" - ) - } - ) - } - } - - private fun getRequestLoginDto(): RequestLoginDto = RequestLoginDto( - authenticationId = _uiState.value.id, - password = _uiState.value.password - ) - - private fun setUserIdInPreference(userId: String) { - userRepository.setUserId(userId) - } - - companion object { - const val HEADER_NAME = "location" - const val JSON_NAME = "message" - } -} \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/compose/ui/screens/signup/SignUpViewModel.kt b/app/src/main/java/com/sopt/now/compose/ui/screens/signup/SignUpViewModel.kt deleted file mode 100644 index e0ae835..0000000 --- a/app/src/main/java/com/sopt/now/compose/ui/screens/signup/SignUpViewModel.kt +++ /dev/null @@ -1,82 +0,0 @@ -package com.sopt.now.compose.ui.screens.signup - -import androidx.lifecycle.ViewModel -import androidx.lifecycle.viewModelScope -import com.sopt.now.compose.container.impl.AuthRepositoryImpl -import com.sopt.now.compose.network.dto.RequestSignUpDto -import com.sopt.now.compose.ui.screens.login.LoginViewModel -import dagger.hilt.android.lifecycle.HiltViewModel -import kotlinx.coroutines.flow.MutableStateFlow -import kotlinx.coroutines.flow.StateFlow -import kotlinx.coroutines.flow.asStateFlow -import kotlinx.coroutines.flow.update -import kotlinx.coroutines.launch -import kotlinx.serialization.json.Json -import kotlinx.serialization.json.jsonObject -import javax.inject.Inject - -@HiltViewModel -class SignUpViewModel @Inject constructor( - private val authRepository: AuthRepositoryImpl -): ViewModel() { - private val _uiState = MutableStateFlow(SignUpState()) - val uiState: StateFlow = _uiState.asStateFlow() - - fun updateUiState( - isSuccess: Boolean = _uiState.value.isSuccess, - message: String = _uiState.value.message, - authenticationId: String = _uiState.value.authenticationId, - password: String = _uiState.value.password, - nickName: String = _uiState.value.nickName, - phone: String = _uiState.value.phone, - ) { - _uiState.update {currentState -> - currentState.copy( - isSuccess = isSuccess, - message = message, - authenticationId = authenticationId, - password = password, - nickName = nickName, - phone = phone) - } - } - fun patchSignUp(request: RequestSignUpDto = getRequestSignUpDto()) { - viewModelScope.launch { - authRepository.postSignUp(request).fold( - onSuccess = { - if(it.isSuccessful){ - val userId = it.headers()["location"] - updateUiState( - isSuccess = true, - message = userId.toString() - ) - } else { - val error = it.errorBody()?.string() - if (error != null) { - val jsonMessage = Json.parseToJsonElement(error) - updateUiState( - isSuccess = false, - message = jsonMessage.jsonObject[LoginViewModel.JSON_NAME].toString() - ) - } - } - }, - onFailure = { - updateUiState( - isSuccess = false, - message = "서버에러" - ) - } - ) - } - } - - private fun getRequestSignUpDto(): RequestSignUpDto = with(_uiState.value) { - RequestSignUpDto( - authenticationId = this.authenticationId, - password = this.password, - nickname = this.nickName, - phone = this.phone - ) - } -} \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/compose/ui/composables/ButtonComposable.kt b/presentation/src/main/java/com/sopt/now/compose/presentation/composables/ButtonComposable.kt similarity index 94% rename from app/src/main/java/com/sopt/now/compose/ui/composables/ButtonComposable.kt rename to presentation/src/main/java/com/sopt/now/compose/presentation/composables/ButtonComposable.kt index 26ae4a7..cf9708a 100644 --- a/app/src/main/java/com/sopt/now/compose/ui/composables/ButtonComposable.kt +++ b/presentation/src/main/java/com/sopt/now/compose/presentation/composables/ButtonComposable.kt @@ -1,4 +1,4 @@ -package com.sopt.now.compose.ui.composables +package com.sopt.now.compose.presentation.composables import androidx.annotation.StringRes import androidx.compose.foundation.layout.fillMaxWidth diff --git a/app/src/main/java/com/sopt/now/compose/ui/composables/ScreenWithImage.kt b/presentation/src/main/java/com/sopt/now/compose/presentation/composables/ScreenWithImage.kt similarity index 91% rename from app/src/main/java/com/sopt/now/compose/ui/composables/ScreenWithImage.kt rename to presentation/src/main/java/com/sopt/now/compose/presentation/composables/ScreenWithImage.kt index c869749..5849164 100644 --- a/app/src/main/java/com/sopt/now/compose/ui/composables/ScreenWithImage.kt +++ b/presentation/src/main/java/com/sopt/now/compose/presentation/composables/ScreenWithImage.kt @@ -1,4 +1,4 @@ -package com.sopt.now.compose.ui.composables +package com.sopt.now.compose.presentation.composables import androidx.annotation.DrawableRes import androidx.compose.foundation.Image diff --git a/app/src/main/java/com/sopt/now/compose/ui/composables/TextFieldWithTitleComposable.kt b/presentation/src/main/java/com/sopt/now/compose/presentation/composables/TextFieldWithTitleComposable.kt similarity index 96% rename from app/src/main/java/com/sopt/now/compose/ui/composables/TextFieldWithTitleComposable.kt rename to presentation/src/main/java/com/sopt/now/compose/presentation/composables/TextFieldWithTitleComposable.kt index c911098..0637a77 100644 --- a/app/src/main/java/com/sopt/now/compose/ui/composables/TextFieldWithTitleComposable.kt +++ b/presentation/src/main/java/com/sopt/now/compose/presentation/composables/TextFieldWithTitleComposable.kt @@ -1,4 +1,4 @@ -package com.sopt.now.compose.ui.composables +package com.sopt.now.compose.presentation.composables import androidx.annotation.StringRes import androidx.compose.foundation.layout.Column diff --git a/app/src/main/java/com/sopt/now/compose/ui/composables/TitleAndContentTextComposable.kt b/presentation/src/main/java/com/sopt/now/compose/presentation/composables/TitleAndContentTextComposable.kt similarity index 94% rename from app/src/main/java/com/sopt/now/compose/ui/composables/TitleAndContentTextComposable.kt rename to presentation/src/main/java/com/sopt/now/compose/presentation/composables/TitleAndContentTextComposable.kt index 2fe9f26..ce57373 100644 --- a/app/src/main/java/com/sopt/now/compose/ui/composables/TitleAndContentTextComposable.kt +++ b/presentation/src/main/java/com/sopt/now/compose/presentation/composables/TitleAndContentTextComposable.kt @@ -1,4 +1,4 @@ -package com.sopt.now.compose.ui.composables +package com.sopt.now.compose.presentation.composables import androidx.annotation.StringRes import androidx.compose.foundation.layout.Column diff --git a/app/src/main/java/com/sopt/now/compose/ext/NavigationExt.kt b/presentation/src/main/java/com/sopt/now/compose/presentation/ext/NavigationExt.kt similarity index 87% rename from app/src/main/java/com/sopt/now/compose/ext/NavigationExt.kt rename to presentation/src/main/java/com/sopt/now/compose/presentation/ext/NavigationExt.kt index 8a46466..8b98703 100644 --- a/app/src/main/java/com/sopt/now/compose/ext/NavigationExt.kt +++ b/presentation/src/main/java/com/sopt/now/compose/presentation/ext/NavigationExt.kt @@ -1,4 +1,4 @@ -package com.sopt.now.compose.ext +package com.sopt.now.compose.presentation.ext import androidx.navigation.NavHostController import androidx.navigation.NavOptionsBuilder diff --git a/app/src/main/java/com/sopt/now/compose/ui/navigation/ApplicationNavigation.kt b/presentation/src/main/java/com/sopt/now/compose/presentation/navigation/ApplicationNavigation.kt similarity index 75% rename from app/src/main/java/com/sopt/now/compose/ui/navigation/ApplicationNavigation.kt rename to presentation/src/main/java/com/sopt/now/compose/presentation/navigation/ApplicationNavigation.kt index 59e1b01..bd440cc 100644 --- a/app/src/main/java/com/sopt/now/compose/ui/navigation/ApplicationNavigation.kt +++ b/presentation/src/main/java/com/sopt/now/compose/presentation/navigation/ApplicationNavigation.kt @@ -1,15 +1,15 @@ -package com.sopt.now.compose.ui.navigation +package com.sopt.now.compose.presentation.navigation import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.navigation.NavHostController import androidx.navigation.compose.NavHost import androidx.navigation.compose.composable -import com.sopt.now.compose.ui.screens.home.HomeScreen -import com.sopt.now.compose.ui.screens.login.LoginScreen -import com.sopt.now.compose.ui.screens.profile.ProfileScreen -import com.sopt.now.compose.ui.screens.search.SearchScreen -import com.sopt.now.compose.ui.screens.signup.SignUpScreen +import com.sopt.now.compose.presentation.screens.home.HomeScreen +import com.sopt.now.compose.presentation.ui.screens.login.LoginScreen +import com.sopt.now.compose.presentation.screens.profile.ProfileScreen +import com.sopt.now.compose.presentation.screens.search.SearchScreen +import com.sopt.now.compose.presentation.screens.signup.SignUpScreen @Composable fun ApplicationNavHost( diff --git a/app/src/main/java/com/sopt/now/compose/ui/navigation/NavigationDestination.kt b/presentation/src/main/java/com/sopt/now/compose/presentation/navigation/NavigationDestination.kt similarity index 82% rename from app/src/main/java/com/sopt/now/compose/ui/navigation/NavigationDestination.kt rename to presentation/src/main/java/com/sopt/now/compose/presentation/navigation/NavigationDestination.kt index 9490881..fab0dab 100644 --- a/app/src/main/java/com/sopt/now/compose/ui/navigation/NavigationDestination.kt +++ b/presentation/src/main/java/com/sopt/now/compose/presentation/navigation/NavigationDestination.kt @@ -1,4 +1,4 @@ -package com.sopt.now.compose.ui.navigation +package com.sopt.now.compose.presentation.navigation import androidx.compose.ui.graphics.vector.ImageVector diff --git a/app/src/main/java/com/sopt/now/compose/ui/navigation/ScreenDestinations.kt b/presentation/src/main/java/com/sopt/now/compose/presentation/navigation/ScreenDestinations.kt similarity index 93% rename from app/src/main/java/com/sopt/now/compose/ui/navigation/ScreenDestinations.kt rename to presentation/src/main/java/com/sopt/now/compose/presentation/navigation/ScreenDestinations.kt index bae7f54..63c691c 100644 --- a/app/src/main/java/com/sopt/now/compose/ui/navigation/ScreenDestinations.kt +++ b/presentation/src/main/java/com/sopt/now/compose/presentation/navigation/ScreenDestinations.kt @@ -1,11 +1,11 @@ -package com.sopt.now.compose.ui.navigation +package com.sopt.now.compose.presentation.navigation import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Home import androidx.compose.material.icons.filled.Person import androidx.compose.material.icons.filled.Search import androidx.compose.ui.graphics.vector.ImageVector -import com.sopt.now.compose.R +import com.sopt.now.compose.presentation.R object LoginDestination: NavigationDestination { override val route: String = "login" diff --git a/presentation/src/main/java/com/sopt/now/compose/presentation/screens/home/FollowerUiState.kt b/presentation/src/main/java/com/sopt/now/compose/presentation/screens/home/FollowerUiState.kt new file mode 100644 index 0000000..4ef62d4 --- /dev/null +++ b/presentation/src/main/java/com/sopt/now/compose/presentation/screens/home/FollowerUiState.kt @@ -0,0 +1,14 @@ +package com.sopt.now.compose.presentation.screens.home + +import com.sopt.now.compose.domain.entity.response.FollowerResponseEntity +import com.sopt.now.compose.domain.entity.response.UserResponseEntity + +sealed interface FollowerUiState { + data class Success( + val follower: List + ) : FollowerUiState + data object Loading: FollowerUiState + data class Error( + val errorMessage: String + ): FollowerUiState +} \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/compose/ui/screens/home/HomeScreen.kt b/presentation/src/main/java/com/sopt/now/compose/presentation/screens/home/HomeScreen.kt similarity index 70% rename from app/src/main/java/com/sopt/now/compose/ui/screens/home/HomeScreen.kt rename to presentation/src/main/java/com/sopt/now/compose/presentation/screens/home/HomeScreen.kt index d77037d..8f5aef1 100644 --- a/app/src/main/java/com/sopt/now/compose/ui/screens/home/HomeScreen.kt +++ b/presentation/src/main/java/com/sopt/now/compose/presentation/screens/home/HomeScreen.kt @@ -1,4 +1,4 @@ -package com.sopt.now.compose.ui.screens.home +package com.sopt.now.compose.presentation.screens.home import androidx.activity.compose.BackHandler import androidx.compose.foundation.background @@ -31,31 +31,32 @@ import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.TextUnit import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp +import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.lifecycle.viewmodel.compose.viewModel import androidx.navigation.NavHostController import androidx.navigation.compose.rememberNavController import coil.compose.AsyncImage import coil.request.ImageRequest -import com.sopt.now.compose.MainActivity -import com.sopt.now.compose.R -import com.sopt.now.compose.ui.SoptBottomNavigation -import com.sopt.now.compose.ui.composables.ScreenWithImage +import com.sopt.now.compose.presentation.R +import com.sopt.now.compose.presentation.composables.ScreenWithImage +import com.sopt.now.compose.presentation.screens.search.SearchViewModel.Companion.NAVIGATE_BACK_PRESSED_KEY +import com.sopt.now.compose.presentation.ui.theme.SoptBottomNavigation @Composable fun HomeScreen( navController: NavHostController = rememberNavController(), - viewModel: HomeViewModel = viewModel(), + viewModel: HomeViewModel = hiltViewModel(), ) { LaunchedEffect(null) { - viewModel.fetchNetworkData() + viewModel.getNetworkData() } BackHandler { navController.run { previousBackStackEntry?.savedStateHandle?.set( - MainActivity.NAVIGATE_BACK_PRESSED_KEY, - MainActivity.NAVIGATE_BACK_PRESSED_KEY + NAVIGATE_BACK_PRESSED_KEY, + NAVIGATE_BACK_PRESSED_KEY ) navigateUp() } @@ -64,19 +65,24 @@ fun HomeScreen( Scaffold( bottomBar = { SoptBottomNavigation(navController = navController) } ) { paddingValue -> - when (val uiState = viewModel.uiState.collectAsStateWithLifecycle(LocalLifecycleOwner.current).value) { - is HomeUiState.Success -> { + val uiState = viewModel.uiState.collectAsStateWithLifecycle(LocalLifecycleOwner.current).value + val uiStateFollower = viewModel.uiStateFollower.collectAsStateWithLifecycle(LocalLifecycleOwner.current).value + + + when { + uiState is HomeUiState.Success && uiStateFollower is FollowerUiState.Success -> { HomeScreen( uiState = uiState, + uiStateFollower = uiStateFollower, modifier = Modifier.padding(paddingValue) ) } - is HomeUiState.Loading -> { + uiState is HomeUiState.Loading || uiStateFollower is FollowerUiState.Loading -> { ScreenWithImage(imageRes = R.drawable.loading_img, contentDescription = "Loading") } - is HomeUiState.Error -> { + uiState is HomeUiState.Error || uiStateFollower is FollowerUiState.Error -> { ScreenWithImage(imageRes = R.drawable.ic_broken_image, contentDescription = "Error") } } @@ -86,7 +92,8 @@ fun HomeScreen( @Composable fun HomeScreen( modifier: Modifier = Modifier, - uiState: HomeUiState.Success + uiState: HomeUiState.Success, + uiStateFollower: FollowerUiState.Success ) { LazyColumn( modifier = modifier.padding(horizontal = 20.dp) @@ -99,8 +106,8 @@ fun HomeScreen( imageUrl = "https://developer.android.com/codelabs/basic-android-kotlin-compose-amphibians-app/img/roraima-bush-toad.png", contentDescription = "", imageSize = 80.dp, - name = uiState.user.nickName, - selfDescription = uiState.user.phone, + name = uiState.nickname, + selfDescription = uiState.phone, nameFontSize = 20.sp, selfDescriptionFontSize = 15.sp ) @@ -113,7 +120,7 @@ fun HomeScreen( .background(color = Color.LightGray) ) } - items(uiState.follower) { follow -> + items(uiStateFollower.follower) { follow -> ItemComposable( modifier = Modifier .padding(bottom = 10.dp) @@ -127,6 +134,34 @@ fun HomeScreen( } } +@Composable +internal fun UserInfoComposable( + uiState: HomeUiState.Success +) { + Column { + ItemComposable( + modifier = Modifier + .fillMaxWidth() + .padding(top = 10.dp), + imageUrl = "https://developer.android.com/codelabs/basic-android-kotlin-compose-amphibians-app/img/roraima-bush-toad.png", + contentDescription = "", + imageSize = 80.dp, + name = uiState.nickname, + selfDescription = uiState.phone, + nameFontSize = 20.sp, + selfDescriptionFontSize = 15.sp + ) + + Spacer( + modifier = Modifier + .height(21.dp) + .fillMaxWidth() + .padding(vertical = 10.dp) + .background(color = Color.LightGray) + ) + } +} + @Composable fun ItemComposable( modifier: Modifier, @@ -173,6 +208,13 @@ fun ItemComposable( } } +@Composable +internal fun FollowerComposable( + +) { + +} + @Preview(showBackground = true) @Composable diff --git a/presentation/src/main/java/com/sopt/now/compose/presentation/screens/home/HomeUiState.kt b/presentation/src/main/java/com/sopt/now/compose/presentation/screens/home/HomeUiState.kt new file mode 100644 index 0000000..6fe4711 --- /dev/null +++ b/presentation/src/main/java/com/sopt/now/compose/presentation/screens/home/HomeUiState.kt @@ -0,0 +1,17 @@ +package com.sopt.now.compose.presentation.screens.home + +import com.sopt.now.compose.domain.entity.response.FollowerResponseEntity +import com.sopt.now.compose.domain.entity.response.UserResponseEntity + +sealed interface HomeUiState { + data class Success( + val isSuccess: Boolean, + val authenticationId: String, + val nickname: String, + val phone: String + ) : HomeUiState + data object Loading: HomeUiState + data class Error( + val errorMessage: String + ): HomeUiState +} \ No newline at end of file diff --git a/presentation/src/main/java/com/sopt/now/compose/presentation/screens/home/HomeViewModel.kt b/presentation/src/main/java/com/sopt/now/compose/presentation/screens/home/HomeViewModel.kt new file mode 100644 index 0000000..c0f0810 --- /dev/null +++ b/presentation/src/main/java/com/sopt/now/compose/presentation/screens/home/HomeViewModel.kt @@ -0,0 +1,75 @@ +package com.sopt.now.compose.presentation.screens.home + +import android.util.Log +import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +import com.sopt.now.compose.domain.entity.request.FollowerRequestEntity +import com.sopt.now.compose.domain.repository.FollowerRepository +import com.sopt.now.compose.domain.repository.HomeRepository +import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.asStateFlow +import kotlinx.coroutines.launch +import javax.inject.Inject + +@HiltViewModel +class HomeViewModel @Inject constructor( + private val followerRepository: FollowerRepository, + private val homeRepository: HomeRepository +) : ViewModel() { + + private val _uiState = MutableStateFlow(HomeUiState.Loading) + private val _uiStateFollower = MutableStateFlow(FollowerUiState.Loading) + val uiState: StateFlow = _uiState.asStateFlow() + val uiStateFollower: StateFlow = _uiStateFollower.asStateFlow() + + fun getNetworkData() { + //getUserInfo() + _uiState.value = HomeUiState.Success( + isSuccess = true, + authenticationId = "seokjun", + nickname = "seokjun", + phone = "010-0000-0000" + ) + getFollowerList() + } + + private fun getUserInfo() = viewModelScope.launch { + homeRepository.getUser().fold( + onSuccess = { + _uiState.value = HomeUiState.Success( + isSuccess = true, + authenticationId = it.authenticationId, + nickname = it.nickname, + phone = it.phone + ) + }, + onFailure = { + _uiState.value = HomeUiState.Error( + errorMessage = it.message.toString() + ) + } + ) + } + + private fun getFollowerList() = viewModelScope.launch { + Log.d("HomeViewModel", "getFollowerList()") + followerRepository.getFollowers( + FollowerRequestEntity(page = 2) + ).fold( + onSuccess = { + _uiStateFollower.value = FollowerUiState.Success( + follower = it + ) + Log.d("HomeViewModel", "successful call") + }, + onFailure = { + _uiState.value = HomeUiState.Error( + errorMessage = it.message.toString() + ) + Log.d("HomeViewModel", "error: ${it.message.toString()}") + } + ) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/compose/ui/screens/login/LoginScreen.kt b/presentation/src/main/java/com/sopt/now/compose/presentation/screens/login/LoginScreen.kt similarity index 81% rename from app/src/main/java/com/sopt/now/compose/ui/screens/login/LoginScreen.kt rename to presentation/src/main/java/com/sopt/now/compose/presentation/screens/login/LoginScreen.kt index 7be6c81..edde3ab 100644 --- a/app/src/main/java/com/sopt/now/compose/ui/screens/login/LoginScreen.kt +++ b/presentation/src/main/java/com/sopt/now/compose/presentation/screens/login/LoginScreen.kt @@ -1,4 +1,4 @@ -package com.sopt.now.compose.ui.screens.login +package com.sopt.now.compose.presentation.ui.screens.login import android.app.Activity import android.content.Context @@ -28,12 +28,14 @@ import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.navigation.NavHostController import androidx.navigation.compose.rememberNavController -import com.sopt.now.compose.MainActivity -import com.sopt.now.compose.R -import com.sopt.now.compose.ui.composables.ButtonComposable -import com.sopt.now.compose.ui.composables.TextFieldWithTitleComposable -import com.sopt.now.compose.ui.navigation.HomeDestination -import com.sopt.now.compose.ui.navigation.SignUpDestination +import com.sopt.now.compose.presentation.R +import com.sopt.now.compose.presentation.composables.ButtonComposable +import com.sopt.now.compose.presentation.composables.TextFieldWithTitleComposable +import com.sopt.now.compose.presentation.navigation.HomeDestination +import com.sopt.now.compose.presentation.navigation.SignUpDestination +import com.sopt.now.compose.presentation.screens.login.LoginViewModel +import com.sopt.now.compose.presentation.screens.search.SearchViewModel.Companion.NAVIGATE_BACK_PRESSED_KEY +import com.sopt.now.compose.presentation.screens.search.SearchViewModel.Companion.NAVIGATE_LOGIN_KEY @Composable fun LoginScreen( @@ -47,13 +49,10 @@ fun LoginScreen( LaunchedEffect(uiState.message) { checkCurrentStack(context = context, navController = navController) + if(uiState.message.isNotEmpty()){ if(uiState.isSuccess) { Toast.makeText(context, "로그인 성공 ${uiState.message}", Toast.LENGTH_SHORT).show() - navController.currentBackStackEntry?.savedStateHandle?.set( - key = MainActivity.NAVIGATE_LOGIN_KEY, - value = uiState.message - ) navController.navigate(HomeDestination.route) viewModel.updateUiState(id = "", pw = "", message = "", isSuccess = false) } else { @@ -64,7 +63,12 @@ fun LoginScreen( LoginScreen( uiState = uiState, - onLoginButtonClick = {viewModel.postLogin()}, + onLoginButtonClick = { + /*테스트*/ + navController.navigate(HomeDestination.route) + viewModel.updateUiState(id = "", pw = "", message = "", isSuccess = false) + //viewModel.postLogin() + }, onSignUpButtonClick = {navController.navigate(SignUpDestination.route)}, onIdTextFieldChanged = {viewModel.updateUiState(id = it)}, onPwTextFieldChanged = {viewModel.updateUiState(pw = it)} @@ -129,8 +133,8 @@ private fun LoginScreen( private fun checkCurrentStack(context: Context, navController: NavHostController) { navController.currentBackStackEntry?.savedStateHandle?.run { - getLiveData(MainActivity.NAVIGATE_BACK_PRESSED_KEY).value?.run{ - if(this == MainActivity.NAVIGATE_BACK_PRESSED_KEY) { + getLiveData(NAVIGATE_BACK_PRESSED_KEY).value?.run{ + if(this == NAVIGATE_BACK_PRESSED_KEY) { if (context is Activity) { context.finish() } diff --git a/app/src/main/java/com/sopt/now/compose/ui/screens/login/LoginUiState.kt b/presentation/src/main/java/com/sopt/now/compose/presentation/screens/login/LoginUiState.kt similarity index 71% rename from app/src/main/java/com/sopt/now/compose/ui/screens/login/LoginUiState.kt rename to presentation/src/main/java/com/sopt/now/compose/presentation/screens/login/LoginUiState.kt index 27e9ed8..4b61441 100644 --- a/app/src/main/java/com/sopt/now/compose/ui/screens/login/LoginUiState.kt +++ b/presentation/src/main/java/com/sopt/now/compose/presentation/screens/login/LoginUiState.kt @@ -1,4 +1,4 @@ -package com.sopt.now.compose.ui.screens.login +package com.sopt.now.compose.presentation.ui.screens.login data class LoginUiState( val id: String = "", diff --git a/presentation/src/main/java/com/sopt/now/compose/presentation/screens/login/LoginViewModel.kt b/presentation/src/main/java/com/sopt/now/compose/presentation/screens/login/LoginViewModel.kt new file mode 100644 index 0000000..d31a6bd --- /dev/null +++ b/presentation/src/main/java/com/sopt/now/compose/presentation/screens/login/LoginViewModel.kt @@ -0,0 +1,68 @@ +package com.sopt.now.compose.presentation.screens.login + +import android.util.Log +import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +import com.sopt.now.compose.domain.entity.request.LoginRequestEntity +import com.sopt.now.compose.domain.repository.AuthRepository +import com.sopt.now.compose.domain.repository.HomeRepository +import com.sopt.now.compose.presentation.ui.screens.login.LoginUiState +import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.asStateFlow +import kotlinx.coroutines.flow.update +import kotlinx.coroutines.launch +import javax.inject.Inject + +@HiltViewModel +class LoginViewModel @Inject constructor( + private val authRepository: AuthRepository +) : ViewModel() { + private val _uiState = MutableStateFlow(LoginUiState()) + val uiState: StateFlow = _uiState.asStateFlow() + + fun updateUiState( + id: String = _uiState.value.id, + pw: String = _uiState.value.password, + isSuccess: Boolean = _uiState.value.isSuccess, + message: String = _uiState.value.message + + ) { + _uiState.update { currentState -> + currentState.copy( + id = id, + password = pw, + isSuccess = isSuccess, + message = message + ) + } + } + + fun postLogin() = viewModelScope.launch { + authRepository.postLogin( + LoginRequestEntity( + authenticationId = _uiState.value.id, + password = _uiState.value.password + ) + ).fold( + onSuccess = { + updateUiState( + isSuccess = true, + message = it.memberId + ) + putUserIdInPreference(userId = it.memberId) + }, + onFailure = { + updateUiState( + isSuccess = false, + message = it.message.toString() + ) + } + ) + } + + private fun putUserIdInPreference(userId: String) { + authRepository.putUserIdInPreference(userId) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/compose/ui/screens/profile/ProfileScreen.kt b/presentation/src/main/java/com/sopt/now/compose/presentation/screens/profile/ProfileScreen.kt similarity index 79% rename from app/src/main/java/com/sopt/now/compose/ui/screens/profile/ProfileScreen.kt rename to presentation/src/main/java/com/sopt/now/compose/presentation/screens/profile/ProfileScreen.kt index f0a7c14..afe602c 100644 --- a/app/src/main/java/com/sopt/now/compose/ui/screens/profile/ProfileScreen.kt +++ b/presentation/src/main/java/com/sopt/now/compose/presentation/screens/profile/ProfileScreen.kt @@ -1,4 +1,4 @@ -package com.sopt.now.compose.ui.screens.profile +package com.sopt.now.compose.presentation.screens.profile import androidx.activity.compose.BackHandler import androidx.compose.foundation.Image @@ -22,13 +22,13 @@ import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.navigation.NavHostController import androidx.navigation.compose.rememberNavController -import com.sopt.now.compose.MainActivity -import com.sopt.now.compose.MainActivity.Companion.NAVIGATE_BACK_PRESSED_KEY -import com.sopt.now.compose.R -import com.sopt.now.compose.ui.SoptBottomNavigation -import com.sopt.now.compose.ui.composables.ButtonComposable -import com.sopt.now.compose.ui.composables.ScreenWithImage -import com.sopt.now.compose.ui.composables.TitleAndContentTextComposable +import com.sopt.now.compose.presentation.R +import com.sopt.now.compose.presentation.composables.ButtonComposable +import com.sopt.now.compose.presentation.composables.ScreenWithImage +import com.sopt.now.compose.presentation.composables.TitleAndContentTextComposable +import com.sopt.now.compose.presentation.screens.search.SearchViewModel.Companion.NAVIGATE_BACK_PRESSED_KEY +import com.sopt.now.compose.presentation.screens.search.SearchViewModel.Companion.NAVIGATE_LOGIN_KEY +import com.sopt.now.compose.presentation.ui.theme.SoptBottomNavigation @Composable fun ProfileScreen( @@ -36,11 +36,13 @@ fun ProfileScreen( viewModel: ProfileViewModel = hiltViewModel(), ) { LaunchedEffect(navController) { - val memberId = navController.previousBackStackEntry?.savedStateHandle - ?.getLiveData(MainActivity.NAVIGATE_LOGIN_KEY)?.value + //이 부분을 SharedPreference를 확인하는 코드로 수정 + /*val memberId = navController.previousBackStackEntry?.savedStateHandle + ?.getLiveData(NAVIGATE_LOGIN_KEY)?.value if(memberId != null) { - viewModel.fetchUserInfo() - } + viewModel.getUserInfo() + }*/ + viewModel.getUserInfo() } BackHandler { @@ -100,7 +102,7 @@ private fun ProfileScreen( ) } Text( - text = uiState.user.nickName, + text = uiState.nickname, fontSize = 20.sp, fontWeight = FontWeight.Bold, modifier = Modifier @@ -111,12 +113,12 @@ private fun ProfileScreen( TitleAndContentTextComposable( title = R.string.title_id, - content = uiState.user.id, + content = uiState.authenticationId, modifier = Modifier.padding(top = 70.dp) ) TitleAndContentTextComposable( title = R.string.title_phone, - content = uiState.user.phone, + content = uiState.phone, modifier = Modifier.padding(top = 70.dp) ) diff --git a/presentation/src/main/java/com/sopt/now/compose/presentation/screens/profile/ProfileUiState.kt b/presentation/src/main/java/com/sopt/now/compose/presentation/screens/profile/ProfileUiState.kt new file mode 100644 index 0000000..2046766 --- /dev/null +++ b/presentation/src/main/java/com/sopt/now/compose/presentation/screens/profile/ProfileUiState.kt @@ -0,0 +1,13 @@ +package com.sopt.now.compose.presentation.screens.profile + +import com.sopt.now.compose.domain.entity.response.UserResponseEntity + +sealed interface ProfileUiState { + data class Success( + val authenticationId: String, + val nickname: String, + val phone: String + ) : ProfileUiState + data object Loading: ProfileUiState + data object Error: ProfileUiState +} \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/compose/ui/screens/profile/ProfileViewModel.kt b/presentation/src/main/java/com/sopt/now/compose/presentation/screens/profile/ProfileViewModel.kt similarity index 51% rename from app/src/main/java/com/sopt/now/compose/ui/screens/profile/ProfileViewModel.kt rename to presentation/src/main/java/com/sopt/now/compose/presentation/screens/profile/ProfileViewModel.kt index 2e3585a..88c11ef 100644 --- a/app/src/main/java/com/sopt/now/compose/ui/screens/profile/ProfileViewModel.kt +++ b/presentation/src/main/java/com/sopt/now/compose/presentation/screens/profile/ProfileViewModel.kt @@ -1,10 +1,11 @@ -package com.sopt.now.compose.ui.screens.profile +package com.sopt.now.compose.presentation.screens.profile import android.util.Log import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope -import com.sopt.now.compose.container.impl.MemberRepositoryImpl -import com.sopt.now.compose.models.User +import com.sopt.now.compose.domain.entity.response.UserResponseEntity +import com.sopt.now.compose.domain.repository.HomeRepository +import com.sopt.now.compose.presentation.screens.home.HomeUiState import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow @@ -14,37 +15,32 @@ import javax.inject.Inject @HiltViewModel class ProfileViewModel @Inject constructor( - private val authRepository: MemberRepositoryImpl + private val homeRepository: HomeRepository ): ViewModel() { private val _uiState = MutableStateFlow(ProfileUiState.Loading) val uiState: StateFlow = _uiState.asStateFlow() - private fun updateUiState(user: User?) { - if(user != null) { - _uiState.value = ProfileUiState.Success(user) - } else { - _uiState.value = ProfileUiState.Error - } - } - - fun fetchUserInfo() { - viewModelScope.launch { - val result = authRepository.getUserInfo() + fun getUserInfo() { + _uiState.value = ProfileUiState.Success( + authenticationId = "seokjun", + nickname = "seokjun", + phone = "010-0000-0000" + ) + /*viewModelScope.launch { + val result = homeRepository.getUser() result.fold( onSuccess = { - updateUiState( - user = User( - id = it.id, - nickName = it.nickName, - phone = it.phone - ) + _uiState.value = ProfileUiState.Success( + authenticationId = it.authenticationId, + nickname = it.nickname, + phone = it.phone" ) }, onFailure = { Log.d(TAG, it.message.toString()) } ) - } + }*/ } companion object{ diff --git a/app/src/main/java/com/sopt/now/compose/ui/screens/search/SearchScreen.kt b/presentation/src/main/java/com/sopt/now/compose/presentation/screens/search/SearchScreen.kt similarity index 78% rename from app/src/main/java/com/sopt/now/compose/ui/screens/search/SearchScreen.kt rename to presentation/src/main/java/com/sopt/now/compose/presentation/screens/search/SearchScreen.kt index 1c09852..3448c0c 100644 --- a/app/src/main/java/com/sopt/now/compose/ui/screens/search/SearchScreen.kt +++ b/presentation/src/main/java/com/sopt/now/compose/presentation/screens/search/SearchScreen.kt @@ -1,4 +1,4 @@ -package com.sopt.now.compose.ui.screens.search +package com.sopt.now.compose.presentation.screens.search import androidx.activity.compose.BackHandler import androidx.compose.foundation.layout.Column @@ -8,8 +8,8 @@ import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.navigation.NavHostController -import com.sopt.now.compose.MainActivity.Companion.NAVIGATE_BACK_PRESSED_KEY -import com.sopt.now.compose.ui.SoptBottomNavigation +import com.sopt.now.compose.presentation.screens.search.SearchViewModel.Companion.NAVIGATE_BACK_PRESSED_KEY +import com.sopt.now.compose.presentation.ui.theme.SoptBottomNavigation /** diff --git a/presentation/src/main/java/com/sopt/now/compose/presentation/screens/search/SearchViewModel.kt b/presentation/src/main/java/com/sopt/now/compose/presentation/screens/search/SearchViewModel.kt new file mode 100644 index 0000000..e9b18b4 --- /dev/null +++ b/presentation/src/main/java/com/sopt/now/compose/presentation/screens/search/SearchViewModel.kt @@ -0,0 +1,19 @@ +package com.sopt.now.compose.presentation.screens.search + +import android.content.Context +import android.widget.Toast + +class SearchViewModel { + + companion object { + const val NAVIGATE_SIGNUP_KEY = "user" + const val NAVIGATE_LOGIN_KEY = "login" + + const val NAVIGATE_BACK_PRESSED_KEY = "back" + + fun printToastMessage(context: Context, messageRes: Int) { + Toast.makeText(context, messageRes, Toast.LENGTH_SHORT).show() + } + + } +} \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/compose/ui/screens/signup/SignUpScreen.kt b/presentation/src/main/java/com/sopt/now/compose/presentation/screens/signup/SignUpScreen.kt similarity index 93% rename from app/src/main/java/com/sopt/now/compose/ui/screens/signup/SignUpScreen.kt rename to presentation/src/main/java/com/sopt/now/compose/presentation/screens/signup/SignUpScreen.kt index a4653d4..803f582 100644 --- a/app/src/main/java/com/sopt/now/compose/ui/screens/signup/SignUpScreen.kt +++ b/presentation/src/main/java/com/sopt/now/compose/presentation/screens/signup/SignUpScreen.kt @@ -1,4 +1,4 @@ -package com.sopt.now.compose.ui.screens.signup +package com.sopt.now.compose.presentation.screens.signup import android.widget.Toast import androidx.compose.foundation.layout.Box @@ -23,9 +23,9 @@ import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.navigation.NavHostController import androidx.navigation.compose.rememberNavController -import com.sopt.now.compose.R -import com.sopt.now.compose.ui.composables.ButtonComposable -import com.sopt.now.compose.ui.composables.TextFieldWithTitleComposable +import com.sopt.now.compose.presentation.R +import com.sopt.now.compose.presentation.composables.ButtonComposable +import com.sopt.now.compose.presentation.composables.TextFieldWithTitleComposable @Composable fun SignUpScreen( @@ -52,7 +52,7 @@ fun SignUpScreen( onPwTextFieldChange = { viewModel.updateUiState(password = it) }, onNickNameTextFieldChange = { viewModel.updateUiState(nickName = it) }, onPhoneTextFieldChange = { viewModel.updateUiState(phone = it) }, - onSignUpButtonClick = { viewModel.patchSignUp() } + onSignUpButtonClick = { viewModel.postSignup() } ) } diff --git a/app/src/main/java/com/sopt/now/compose/ui/screens/signup/SignUpState.kt b/presentation/src/main/java/com/sopt/now/compose/presentation/screens/signup/SignUpState.kt similarity index 79% rename from app/src/main/java/com/sopt/now/compose/ui/screens/signup/SignUpState.kt rename to presentation/src/main/java/com/sopt/now/compose/presentation/screens/signup/SignUpState.kt index 78c440f..b1d3d90 100644 --- a/app/src/main/java/com/sopt/now/compose/ui/screens/signup/SignUpState.kt +++ b/presentation/src/main/java/com/sopt/now/compose/presentation/screens/signup/SignUpState.kt @@ -1,4 +1,4 @@ -package com.sopt.now.compose.ui.screens.signup +package com.sopt.now.compose.presentation.screens.signup data class SignUpState( val isSuccess: Boolean = false, diff --git a/presentation/src/main/java/com/sopt/now/compose/presentation/screens/signup/SignUpViewModel.kt b/presentation/src/main/java/com/sopt/now/compose/presentation/screens/signup/SignUpViewModel.kt new file mode 100644 index 0000000..cb8a92e --- /dev/null +++ b/presentation/src/main/java/com/sopt/now/compose/presentation/screens/signup/SignUpViewModel.kt @@ -0,0 +1,64 @@ +package com.sopt.now.compose.presentation.screens.signup + +import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +import com.sopt.now.compose.domain.entity.request.SignupRequestEntity +import com.sopt.now.compose.domain.repository.AuthRepository +import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.asStateFlow +import kotlinx.coroutines.flow.update +import kotlinx.coroutines.launch +import javax.inject.Inject + +@HiltViewModel +class SignUpViewModel @Inject constructor( + private val authRepository: AuthRepository +): ViewModel() { + private val _uiState = MutableStateFlow(SignUpState()) + val uiState: StateFlow = _uiState.asStateFlow() + + fun updateUiState( + isSuccess: Boolean = _uiState.value.isSuccess, + message: String = _uiState.value.message, + authenticationId: String = _uiState.value.authenticationId, + password: String = _uiState.value.password, + nickName: String = _uiState.value.nickName, + phone: String = _uiState.value.phone, + ) { + _uiState.update {currentState -> + currentState.copy( + isSuccess = isSuccess, + message = message, + authenticationId = authenticationId, + password = password, + nickName = nickName, + phone = phone) + } + } + + fun postSignup() = viewModelScope.launch { + authRepository.postSignUp( + SignupRequestEntity( + authenticationId = _uiState.value.authenticationId, + password = _uiState.value.password, + nickname = _uiState.value.nickName, + phone = _uiState.value.phone + ) + ).fold( + onSuccess = { + updateUiState( + isSuccess = true, + message = it.memberId + ) + }, + onFailure = { + updateUiState( + isSuccess = false, + message = it.message.toString() + ) + } + ) + } +} \ No newline at end of file diff --git a/presentation/src/main/java/com/sopt/now/compose/presentation/ui/theme/Color.kt b/presentation/src/main/java/com/sopt/now/compose/presentation/ui/theme/Color.kt new file mode 100644 index 0000000..1456086 --- /dev/null +++ b/presentation/src/main/java/com/sopt/now/compose/presentation/ui/theme/Color.kt @@ -0,0 +1,11 @@ +package com.sopt.now.compose.presentation.ui.theme + +import androidx.compose.ui.graphics.Color + +val Purple80 = Color(0xFFD0BCFF) +val PurpleGrey80 = Color(0xFFCCC2DC) +val Pink80 = Color(0xFFEFB8C8) + +val Purple40 = Color(0xFF6650a4) +val PurpleGrey40 = Color(0xFF625b71) +val Pink40 = Color(0xFF7D5260) \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/compose/ui/SoptApp.kt b/presentation/src/main/java/com/sopt/now/compose/presentation/ui/theme/SoptApp.kt similarity index 81% rename from app/src/main/java/com/sopt/now/compose/ui/SoptApp.kt rename to presentation/src/main/java/com/sopt/now/compose/presentation/ui/theme/SoptApp.kt index ed3bf92..9910e8b 100644 --- a/app/src/main/java/com/sopt/now/compose/ui/SoptApp.kt +++ b/presentation/src/main/java/com/sopt/now/compose/presentation/ui/theme/SoptApp.kt @@ -1,4 +1,4 @@ -package com.sopt.now.compose.ui +package com.sopt.now.compose.presentation.ui.theme import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize @@ -14,12 +14,12 @@ import androidx.compose.ui.res.stringResource import androidx.navigation.NavHostController import androidx.navigation.compose.currentBackStackEntryAsState import androidx.navigation.compose.rememberNavController -import com.sopt.now.compose.ext.removePreviousBackStacks -import com.sopt.now.compose.ui.navigation.ApplicationNavHost -import com.sopt.now.compose.ui.navigation.HomeDestination -import com.sopt.now.compose.ui.navigation.NavigationDestination -import com.sopt.now.compose.ui.navigation.ProfileDestination -import com.sopt.now.compose.ui.navigation.SearchDestination +import com.sopt.now.compose.presentation.ext.removePreviousBackStacks +import com.sopt.now.compose.presentation.navigation.ApplicationNavHost +import com.sopt.now.compose.presentation.navigation.HomeDestination +import com.sopt.now.compose.presentation.navigation.NavigationDestination +import com.sopt.now.compose.presentation.navigation.ProfileDestination +import com.sopt.now.compose.presentation.navigation.SearchDestination @Composable fun SoptApp() { diff --git a/presentation/src/main/java/com/sopt/now/compose/presentation/ui/theme/Theme.kt b/presentation/src/main/java/com/sopt/now/compose/presentation/ui/theme/Theme.kt new file mode 100644 index 0000000..eaaa71b --- /dev/null +++ b/presentation/src/main/java/com/sopt/now/compose/presentation/ui/theme/Theme.kt @@ -0,0 +1,70 @@ +package com.sopt.now.compose.presentation.ui.theme + +import android.app.Activity +import android.os.Build +import androidx.compose.foundation.isSystemInDarkTheme +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.darkColorScheme +import androidx.compose.material3.dynamicDarkColorScheme +import androidx.compose.material3.dynamicLightColorScheme +import androidx.compose.material3.lightColorScheme +import androidx.compose.runtime.Composable +import androidx.compose.runtime.SideEffect +import androidx.compose.ui.graphics.toArgb +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.platform.LocalView +import androidx.core.view.WindowCompat + +private val DarkColorScheme = darkColorScheme( + primary = Purple80, + secondary = PurpleGrey80, + tertiary = Pink80 +) + +private val LightColorScheme = lightColorScheme( + primary = Purple40, + secondary = PurpleGrey40, + tertiary = Pink40 + + /* Other default colors to override + background = Color(0xFFFFFBFE), + surface = Color(0xFFFFFBFE), + onPrimary = Color.White, + onSecondary = Color.White, + onTertiary = Color.White, + onBackground = Color(0xFF1C1B1F), + onSurface = Color(0xFF1C1B1F), + */ +) + +@Composable +fun NOWSOPTAndroidTheme( + darkTheme: Boolean = isSystemInDarkTheme(), + // Dynamic color is available on Android 12+ + dynamicColor: Boolean = true, + content: @Composable () -> Unit +) { + val colorScheme = when { + dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> { + val context = LocalContext.current + if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context) + } + + darkTheme -> DarkColorScheme + else -> LightColorScheme + } + val view = LocalView.current + if (!view.isInEditMode) { + SideEffect { + val window = (view.context as Activity).window + window.statusBarColor = colorScheme.primary.toArgb() + WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = darkTheme + } + } + + MaterialTheme( + colorScheme = colorScheme, + typography = Typography, + content = content + ) +} \ No newline at end of file diff --git a/presentation/src/main/java/com/sopt/now/compose/presentation/ui/theme/Type.kt b/presentation/src/main/java/com/sopt/now/compose/presentation/ui/theme/Type.kt new file mode 100644 index 0000000..77133d2 --- /dev/null +++ b/presentation/src/main/java/com/sopt/now/compose/presentation/ui/theme/Type.kt @@ -0,0 +1,34 @@ +package com.sopt.now.compose.presentation.ui.theme + +import androidx.compose.material3.Typography +import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.font.FontFamily +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.unit.sp + +// Set of Material typography styles to start with +val Typography = Typography( + bodyLarge = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Normal, + fontSize = 16.sp, + lineHeight = 24.sp, + letterSpacing = 0.5.sp + ) + /* Other default text styles to override + titleLarge = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Normal, + fontSize = 22.sp, + lineHeight = 28.sp, + letterSpacing = 0.sp + ), + labelSmall = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Medium, + fontSize = 11.sp, + lineHeight = 16.sp, + letterSpacing = 0.5.sp + ) + */ +) \ No newline at end of file diff --git a/presentation/src/main/res/drawable/ic_broken_image.xml b/presentation/src/main/res/drawable/ic_broken_image.xml new file mode 100644 index 0000000..c3b995b --- /dev/null +++ b/presentation/src/main/res/drawable/ic_broken_image.xml @@ -0,0 +1,25 @@ + + + + diff --git a/presentation/src/main/res/drawable/ic_launcher_background.xml b/presentation/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/presentation/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/presentation/src/main/res/drawable/ic_launcher_foreground.xml b/presentation/src/main/res/drawable/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/presentation/src/main/res/drawable/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/presentation/src/main/res/drawable/loading_img.xml b/presentation/src/main/res/drawable/loading_img.xml new file mode 100644 index 0000000..0b64932 --- /dev/null +++ b/presentation/src/main/res/drawable/loading_img.xml @@ -0,0 +1,94 @@ + + + + + + + + + + + + + + + + diff --git a/presentation/src/main/res/values/colors.xml b/presentation/src/main/res/values/colors.xml new file mode 100644 index 0000000..f8c6127 --- /dev/null +++ b/presentation/src/main/res/values/colors.xml @@ -0,0 +1,10 @@ + + + #FFBB86FC + #FF6200EE + #FF3700B3 + #FF03DAC5 + #FF018786 + #FF000000 + #FFFFFFFF + \ No newline at end of file diff --git a/presentation/src/main/res/values/strings.xml b/presentation/src/main/res/values/strings.xml new file mode 100644 index 0000000..f5bd242 --- /dev/null +++ b/presentation/src/main/res/values/strings.xml @@ -0,0 +1,65 @@ + + NOW SOPT Android + Welcome To SOPT + 회원가입 + + + signup + main + + + login + signup + home + search + profile + + + login + signup + home + + + ID + 비밀번호 + 전화번호 + 닉네임 + MBTI + + + 로그인 + 회원가입 + 회원가입하기 + + + 사용자 ID 입력 + 비밀번호 입력 + + + + 회원가입을 완료했습니다. + 로그인에 성공했습니다 + 아이디를 입력해주세요 + 비밀번호를 입력해주세요 + 아이디를 다시 확인하세요 + 비밀번호를 다시 확인하세요 + + + 아이디를 입력해주세요 + 비밀번호를 입력해주세요 + 닉네임을 입력해주세요 + MBTI를 입력해주세요 + 전화번호를 입력해주세요 + + + ID는 6~10 글자 + 비밀번호는 8~12 글자 + 닉네임은 한 글자 이상, 공백 불가 + MBTI 공백 불가 + + + 제 MBTI는 %s입니다!! + + + 로그아웃 + \ No newline at end of file diff --git a/presentation/src/main/res/values/themes.xml b/presentation/src/main/res/values/themes.xml new file mode 100644 index 0000000..73b3902 --- /dev/null +++ b/presentation/src/main/res/values/themes.xml @@ -0,0 +1,5 @@ + + + +