From b374cf0a893679a06c1668b16b40ece8bccf9a63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=80=E1=85=B5=E1=86=B7=E1=84=86=E1=85=A7=E1=86=BC?= =?UTF-8?q?=E1=84=89=E1=85=A5=E1=86=A8?= <75840431+cacaocoffee@users.noreply.github.com> Date: Wed, 19 Jun 2024 16:18:52 +0900 Subject: [PATCH] =?UTF-8?q?[Mod]=20#18=20hilt=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sopt/now/data/repositoryimpl/AuthRepositoryImpl.kt | 8 ++++++-- .../com/sopt/now/domain/usecase/GetUserInfoUseCase.kt | 5 ++++- .../java/com/sopt/now/domain/usecase/LogInUseCase.kt | 7 +++++-- .../java/com/sopt/now/domain/usecase/SignUpUseCase.kt | 7 +++++-- app/src/main/java/com/sopt/now/ui/login/LoginActivity.kt | 5 +++-- .../main/java/com/sopt/now/ui/login/LoginViewModel.kt | 9 +++++++-- app/src/main/java/com/sopt/now/ui/main/MainActivity.kt | 5 +++-- app/src/main/java/com/sopt/now/ui/main/MainViewModel.kt | 7 ++++++- .../main/java/com/sopt/now/ui/signup/SignUpActivity.kt | 5 +++-- .../main/java/com/sopt/now/ui/signup/SignUpViewModel.kt | 9 +++++++-- 10 files changed, 49 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/com/sopt/now/data/repositoryimpl/AuthRepositoryImpl.kt b/app/src/main/java/com/sopt/now/data/repositoryimpl/AuthRepositoryImpl.kt index af437ef..ded6088 100644 --- a/app/src/main/java/com/sopt/now/data/repositoryimpl/AuthRepositoryImpl.kt +++ b/app/src/main/java/com/sopt/now/data/repositoryimpl/AuthRepositoryImpl.kt @@ -9,12 +9,16 @@ import com.sopt.now.data.dto.toUserEntity import com.sopt.now.data.repositoryimpl.extension.getResponseErrorMessage import com.sopt.now.data.repositoryimpl.extension.handleThrowable import com.sopt.now.domain.entity.ApiError -import com.sopt.now.domain.entity.UserEntity import com.sopt.now.domain.entity.BaseResponseEntity +import com.sopt.now.domain.entity.UserEntity import com.sopt.now.domain.repository.AuthRepository import retrofit2.Response +import javax.inject.Inject -class AuthRepositoryImpl(private val authService: AuthService) : AuthRepository { +class AuthRepositoryImpl @Inject constructor( + private val authService: AuthService +) : + AuthRepository { override suspend fun login(authData: UserEntity): Result = runCatching { val response: Response> = diff --git a/app/src/main/java/com/sopt/now/domain/usecase/GetUserInfoUseCase.kt b/app/src/main/java/com/sopt/now/domain/usecase/GetUserInfoUseCase.kt index ecb3947..d2cc6d9 100644 --- a/app/src/main/java/com/sopt/now/domain/usecase/GetUserInfoUseCase.kt +++ b/app/src/main/java/com/sopt/now/domain/usecase/GetUserInfoUseCase.kt @@ -2,8 +2,11 @@ package com.sopt.now.domain.usecase import com.sopt.now.domain.entity.UserEntity import com.sopt.now.domain.repository.AuthRepository +import javax.inject.Inject -class GetUserInfoUseCase(private val authRepository: AuthRepository) { +class GetUserInfoUseCase @Inject constructor( + private val authRepository: AuthRepository +) { suspend operator fun invoke(userid: String): Result = authRepository.getMemberInfo(userid) } \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/domain/usecase/LogInUseCase.kt b/app/src/main/java/com/sopt/now/domain/usecase/LogInUseCase.kt index 55bbb8e..60844fd 100644 --- a/app/src/main/java/com/sopt/now/domain/usecase/LogInUseCase.kt +++ b/app/src/main/java/com/sopt/now/domain/usecase/LogInUseCase.kt @@ -2,9 +2,12 @@ package com.sopt.now.domain.usecase import com.sopt.now.domain.entity.UserEntity import com.sopt.now.domain.repository.AuthRepository +import javax.inject.Inject -class LogInUseCase(private val authRepository: AuthRepository) { +class LogInUseCase @Inject constructor( + private val authRepository: AuthRepository +) { - suspend operator fun invoke(request: UserEntity):Result = + suspend operator fun invoke(request: UserEntity): Result = authRepository.login(request) } \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/domain/usecase/SignUpUseCase.kt b/app/src/main/java/com/sopt/now/domain/usecase/SignUpUseCase.kt index f7c8a00..3189cb8 100644 --- a/app/src/main/java/com/sopt/now/domain/usecase/SignUpUseCase.kt +++ b/app/src/main/java/com/sopt/now/domain/usecase/SignUpUseCase.kt @@ -3,9 +3,12 @@ package com.sopt.now.domain.usecase import com.sopt.now.domain.entity.UserEntity import com.sopt.now.domain.entity.BaseResponseEntity import com.sopt.now.domain.repository.AuthRepository +import javax.inject.Inject -class SignUpUseCase(private val authRepository: AuthRepository) { +class SignUpUseCase @Inject constructor( + private val authRepository: AuthRepository +) { - suspend operator fun invoke(request: UserEntity):Result = + suspend operator fun invoke(request: UserEntity): Result = authRepository.signUp(request) } \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/ui/login/LoginActivity.kt b/app/src/main/java/com/sopt/now/ui/login/LoginActivity.kt index de29d92..1db6f3f 100644 --- a/app/src/main/java/com/sopt/now/ui/login/LoginActivity.kt +++ b/app/src/main/java/com/sopt/now/ui/login/LoginActivity.kt @@ -11,15 +11,16 @@ import com.sopt.now.databinding.ActivityLoginBinding import com.sopt.now.domain.entity.UserEntity import com.sopt.now.ui.main.MainActivity import com.sopt.now.ui.signup.SignUpActivity -import com.sopt.now.ui.ViewModelFactory import com.sopt.now.util.BindingActivity import com.sopt.now.util.UiState import com.sopt.now.util.getSafeParcelable import com.sopt.now.util.toast +import dagger.hilt.android.AndroidEntryPoint +@AndroidEntryPoint class LoginActivity : BindingActivity(R.layout.activity_login) { private lateinit var resultLauncher: ActivityResultLauncher - private val viewModel: LoginViewModel by viewModels { ViewModelFactory() } + private val viewModel: LoginViewModel by viewModels() private lateinit var user: User override fun onCreate(savedInstanceState: Bundle?) { diff --git a/app/src/main/java/com/sopt/now/ui/login/LoginViewModel.kt b/app/src/main/java/com/sopt/now/ui/login/LoginViewModel.kt index 27ecedd..070f498 100644 --- a/app/src/main/java/com/sopt/now/ui/login/LoginViewModel.kt +++ b/app/src/main/java/com/sopt/now/ui/login/LoginViewModel.kt @@ -8,11 +8,16 @@ import com.sopt.now.ui.model.User import com.sopt.now.domain.entity.UserEntity import com.sopt.now.domain.usecase.LogInUseCase import com.sopt.now.util.UiState +import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.launch +import javax.inject.Inject -class LoginViewModel(private val logInUseCase: LogInUseCase) : ViewModel() { +@HiltViewModel +class LoginViewModel @Inject constructor( + private val logInUseCase: LogInUseCase +) : ViewModel() { private val _loginState = MutableLiveData>() - val loginState : LiveData> = _loginState + val loginState: LiveData> = _loginState fun login(request: UserEntity) { _loginState.value = UiState.Loading diff --git a/app/src/main/java/com/sopt/now/ui/main/MainActivity.kt b/app/src/main/java/com/sopt/now/ui/main/MainActivity.kt index 26242fa..c0d601d 100644 --- a/app/src/main/java/com/sopt/now/ui/main/MainActivity.kt +++ b/app/src/main/java/com/sopt/now/ui/main/MainActivity.kt @@ -6,7 +6,6 @@ import androidx.fragment.app.Fragment import com.sopt.now.R import com.sopt.now.ui.model.User import com.sopt.now.databinding.ActivityMainBinding -import com.sopt.now.ui.ViewModelFactory import com.sopt.now.ui.login.LoginActivity.Companion.TAG_USER import com.sopt.now.ui.main.home.MainHomeFragment import com.sopt.now.ui.main.profile.MainProfileFragment @@ -15,9 +14,11 @@ import com.sopt.now.util.BindingActivity import com.sopt.now.util.UiState import com.sopt.now.util.getSafeParcelable import com.sopt.now.util.toast +import dagger.hilt.android.AndroidEntryPoint +@AndroidEntryPoint class MainActivity : BindingActivity(R.layout.activity_main) { - private val viewModel: MainViewModel by viewModels { ViewModelFactory() } + private val viewModel: MainViewModel by viewModels() override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) diff --git a/app/src/main/java/com/sopt/now/ui/main/MainViewModel.kt b/app/src/main/java/com/sopt/now/ui/main/MainViewModel.kt index 611a8c4..492df15 100644 --- a/app/src/main/java/com/sopt/now/ui/main/MainViewModel.kt +++ b/app/src/main/java/com/sopt/now/ui/main/MainViewModel.kt @@ -10,10 +10,15 @@ import com.sopt.now.domain.usecase.GetUserInfoUseCase import com.sopt.now.util.StringNetworkError.FAIL_ERROR import com.sopt.now.util.StringNetworkError.LOGIN import com.sopt.now.util.UiState +import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.launch import retrofit2.HttpException +import javax.inject.Inject -class MainViewModel(private val getUserInfoUseCase: GetUserInfoUseCase) : ViewModel() { +@HiltViewModel +class MainViewModel @Inject constructor( + private val getUserInfoUseCase: GetUserInfoUseCase +) : ViewModel() { private val _userData: MutableLiveData> = MutableLiveData() val userData: LiveData> = _userData diff --git a/app/src/main/java/com/sopt/now/ui/signup/SignUpActivity.kt b/app/src/main/java/com/sopt/now/ui/signup/SignUpActivity.kt index a364ad5..05468fa 100644 --- a/app/src/main/java/com/sopt/now/ui/signup/SignUpActivity.kt +++ b/app/src/main/java/com/sopt/now/ui/signup/SignUpActivity.kt @@ -7,15 +7,16 @@ import com.sopt.now.R import com.sopt.now.ui.model.User import com.sopt.now.databinding.ActivitySignUpBinding import com.sopt.now.domain.entity.UserEntity -import com.sopt.now.ui.ViewModelFactory import com.sopt.now.ui.login.LoginActivity import com.sopt.now.ui.login.LoginActivity.Companion.TAG_USER import com.sopt.now.util.BindingActivity import com.sopt.now.util.UiState import com.sopt.now.util.toast +import dagger.hilt.android.AndroidEntryPoint +@AndroidEntryPoint class SignUpActivity : BindingActivity(R.layout.activity_sign_up) { - private val viewModel by viewModels { ViewModelFactory() } + private val viewModel: SignUpViewModel by viewModels() override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) diff --git a/app/src/main/java/com/sopt/now/ui/signup/SignUpViewModel.kt b/app/src/main/java/com/sopt/now/ui/signup/SignUpViewModel.kt index 2dec148..dba22c3 100644 --- a/app/src/main/java/com/sopt/now/ui/signup/SignUpViewModel.kt +++ b/app/src/main/java/com/sopt/now/ui/signup/SignUpViewModel.kt @@ -8,11 +8,16 @@ import com.sopt.now.domain.entity.UserEntity import com.sopt.now.domain.usecase.SignUpUseCase import com.sopt.now.ui.model.User import com.sopt.now.util.UiState +import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.launch +import javax.inject.Inject -class SignUpViewModel(private val signUpUseCase: SignUpUseCase) : ViewModel() { +@HiltViewModel +class SignUpViewModel @Inject constructor( + private val signUpUseCase: SignUpUseCase +) : ViewModel() { private val _signUpState = MutableLiveData>() - val signUpState:LiveData> = _signUpState + val signUpState: LiveData> = _signUpState fun signUp(request: UserEntity) { _signUpState.value = UiState.Loading