From abc4d85201e50bd59c73c8e99001e7a28b852aed Mon Sep 17 00:00:00 2001 From: Moonsu Kang Date: Fri, 7 Jun 2024 23:52:24 +0900 Subject: [PATCH] =?UTF-8?q?[FEAT/#17]=20Factory=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../screen/auth/signup/SignUpViewModelFactory.kt | 15 +++++++++++++++ .../screen/main/mypage/MyPageViewModelFactory.kt | 15 +++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 app/src/main/java/com/sopt/now/compose/screen/auth/signup/SignUpViewModelFactory.kt create mode 100644 app/src/main/java/com/sopt/now/compose/screen/main/mypage/MyPageViewModelFactory.kt diff --git a/app/src/main/java/com/sopt/now/compose/screen/auth/signup/SignUpViewModelFactory.kt b/app/src/main/java/com/sopt/now/compose/screen/auth/signup/SignUpViewModelFactory.kt new file mode 100644 index 0000000..535bd69 --- /dev/null +++ b/app/src/main/java/com/sopt/now/compose/screen/auth/signup/SignUpViewModelFactory.kt @@ -0,0 +1,15 @@ +package com.sopt.now.compose.screen.auth.signup + +import androidx.lifecycle.ViewModel +import androidx.lifecycle.ViewModelProvider +import com.sopt.now.compose.repository.SignUpRepository + +class SignUpViewModelFactory(private val signUpRepository: SignUpRepository) : ViewModelProvider.Factory { + override fun create(modelClass: Class): T { + if (modelClass.isAssignableFrom(SignUpViewModel::class.java)) { + @Suppress("UNCHECKED_CAST") + return SignUpViewModel(signUpRepository) as T + } + throw IllegalArgumentException("알 수 없는 ViewModel 클래스") + } +} \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/compose/screen/main/mypage/MyPageViewModelFactory.kt b/app/src/main/java/com/sopt/now/compose/screen/main/mypage/MyPageViewModelFactory.kt new file mode 100644 index 0000000..709afc8 --- /dev/null +++ b/app/src/main/java/com/sopt/now/compose/screen/main/mypage/MyPageViewModelFactory.kt @@ -0,0 +1,15 @@ +package com.sopt.now.compose.screen.main.mypage + +import androidx.lifecycle.ViewModel +import androidx.lifecycle.ViewModelProvider +import com.sopt.now.compose.repository.UserInfoRepository + +class MyPageViewModelFactory(private val userInfoRepository: UserInfoRepository) : ViewModelProvider.Factory { + override fun create(modelClass: Class): T { + if (modelClass.isAssignableFrom(MyPageViewModel::class.java)) { + @Suppress("UNCHECKED_CAST") + return MyPageViewModel(userInfoRepository) as T + } + throw IllegalArgumentException("알 수 없는 ViewModel 클래스") + } +} \ No newline at end of file