generated from NOW-SOPT-ANDROID/now-sopt-android-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
32a8c17
commit d91ec8a
Showing
4 changed files
with
36 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,39 @@ | ||
package com.sopt.now.ui | ||
|
||
import SignUpViewModel | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.ViewModelProvider | ||
import com.sopt.now.data.repositoryimpl.AuthRepositoryImpl | ||
import com.sopt.now.data.api.ServicePool | ||
import com.sopt.now.domain.usecase.GetUserInfoUseCase | ||
import com.sopt.now.domain.usecase.LogInUseCase | ||
import com.sopt.now.domain.usecase.SignUpUseCase | ||
import com.sopt.now.ui.login.LoginViewModel | ||
import com.sopt.now.ui.main.MainViewModel | ||
import com.sopt.now.ui.signup.SignUpViewModel | ||
|
||
class ViewModelFactory : ViewModelProvider.Factory { | ||
override fun <T : ViewModel> create(modelClass: Class<T>): T { | ||
if (modelClass.isAssignableFrom(SignUpViewModel::class.java)) { | ||
val repository = AuthRepositoryImpl(ServicePool.authService) | ||
val signUpUseCase = SignUpUseCase(repository) | ||
return SignUpViewModel(signUpUseCase) as T | ||
} else if (modelClass.isAssignableFrom(LoginViewModel::class.java)) { | ||
val repository = AuthRepositoryImpl(ServicePool.authService) | ||
val loginUseCase = LogInUseCase(repository) | ||
return LoginViewModel(loginUseCase) as T | ||
when (modelClass) { | ||
SignUpViewModel::class.java -> { | ||
val repository = AuthRepositoryImpl(ServicePool.authService) | ||
val signUpUseCase = SignUpUseCase(repository) | ||
return SignUpViewModel(signUpUseCase) as T | ||
} | ||
|
||
} else { | ||
throw IllegalArgumentException("Failed to create ViewModel: ${modelClass.name}") | ||
LoginViewModel::class.java -> { | ||
val repository = AuthRepositoryImpl(ServicePool.authService) | ||
val loginUseCase = LogInUseCase(repository) | ||
return LoginViewModel(loginUseCase) as T | ||
} | ||
|
||
MainViewModel::class.java -> { | ||
val repository = AuthRepositoryImpl(ServicePool.authService) | ||
val getUserInfoUseCase = GetUserInfoUseCase(repository) | ||
return MainViewModel(getUserInfoUseCase) as T | ||
} | ||
|
||
else -> throw IllegalArgumentException("Failed to create ViewModel: ${modelClass.name}") | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters