diff --git a/android/app/src/main/java/com/zzang/chongdae/presentation/view/detail/OfferingDetailActivity.kt b/android/app/src/main/java/com/zzang/chongdae/presentation/view/detail/OfferingDetailActivity.kt index c8ebfaac1..33dc360a1 100644 --- a/android/app/src/main/java/com/zzang/chongdae/presentation/view/detail/OfferingDetailActivity.kt +++ b/android/app/src/main/java/com/zzang/chongdae/presentation/view/detail/OfferingDetailActivity.kt @@ -20,7 +20,7 @@ class OfferingDetailActivity : AppCompatActivity() { obtainOfferingId() } private val viewModel: OfferingDetailViewModel by viewModels { - OfferingDetailViewModelFactory( + OfferingDetailViewModel.getFactory( offeringId, OfferingDetailRepositoryImpl( OfferingDetailDataSourceImpl(NetworkManager.offeringDetailService()), diff --git a/android/app/src/main/java/com/zzang/chongdae/presentation/view/detail/OfferingDetailViewModel.kt b/android/app/src/main/java/com/zzang/chongdae/presentation/view/detail/OfferingDetailViewModel.kt index eb6ba9f24..e275f3bc4 100644 --- a/android/app/src/main/java/com/zzang/chongdae/presentation/view/detail/OfferingDetailViewModel.kt +++ b/android/app/src/main/java/com/zzang/chongdae/presentation/view/detail/OfferingDetailViewModel.kt @@ -4,7 +4,9 @@ import android.util.Log import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel +import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.viewModelScope +import androidx.lifecycle.viewmodel.CreationExtras import com.zzang.chongdae.BuildConfig import com.zzang.chongdae.domain.model.OfferingCondition import com.zzang.chongdae.domain.model.OfferingCondition.Companion.isAvailable @@ -71,7 +73,7 @@ class OfferingDetailViewModel( ).onSuccess { _isParticipated.value = true _isAvailable.value = false - _commentDetailEvent.setValue(offeringDetail.value?.title ?: "") + _commentDetailEvent.setValue(offeringDetail.value?.title ?: DEFAULT_TITLE) }.onFailure { Log.e("Error", it.message.toString()) } @@ -88,5 +90,21 @@ class OfferingDetailViewModel( companion object { private const val DEFAULT_TITLE = "" + + @Suppress("UNCHECKED_CAST") + fun getFactory( + articleId: Long, + offeringDetailRepository: OfferingDetailRepository, + ) = object : ViewModelProvider.Factory { + override fun create( + modelClass: Class, + extras: CreationExtras, + ): T { + return OfferingDetailViewModel( + articleId, + offeringDetailRepository, + ) as T + } + } } } diff --git a/android/app/src/main/java/com/zzang/chongdae/presentation/view/detail/OfferingDetailViewModelFactory.kt b/android/app/src/main/java/com/zzang/chongdae/presentation/view/detail/OfferingDetailViewModelFactory.kt deleted file mode 100644 index a92071b9e..000000000 --- a/android/app/src/main/java/com/zzang/chongdae/presentation/view/detail/OfferingDetailViewModelFactory.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.zzang.chongdae.presentation.view.detail - -import androidx.lifecycle.ViewModel -import androidx.lifecycle.ViewModelProvider -import com.zzang.chongdae.domain.repository.OfferingDetailRepository - -class OfferingDetailViewModelFactory( - private val articleId: Long, - private val offeringDetailRepository: OfferingDetailRepository, -) : ViewModelProvider.Factory { - override fun create(modelClass: Class): T { - return OfferingDetailViewModel( - articleId, - offeringDetailRepository, - ) as T - } -} diff --git a/android/app/src/main/java/com/zzang/chongdae/presentation/view/home/HomeFragment.kt b/android/app/src/main/java/com/zzang/chongdae/presentation/view/home/HomeFragment.kt index 045d67ac8..6c4ba5bbf 100644 --- a/android/app/src/main/java/com/zzang/chongdae/presentation/view/home/HomeFragment.kt +++ b/android/app/src/main/java/com/zzang/chongdae/presentation/view/home/HomeFragment.kt @@ -21,7 +21,7 @@ class HomeFragment : Fragment(), OnArticleClickListener { private val binding get() = _binding!! private lateinit var offeringAdapter: OfferingAdapter private val viewModel: OfferingViewModel by viewModels { - OfferingViewModeFactory( + OfferingViewModel.getFactory( OfferingsRepositoryImpl( OfferingsDataSourceImpl(NetworkManager.offeringsService()), ), diff --git a/android/app/src/main/java/com/zzang/chongdae/presentation/view/home/OfferingViewModeFactory.kt b/android/app/src/main/java/com/zzang/chongdae/presentation/view/home/OfferingViewModeFactory.kt deleted file mode 100644 index a1efb21b6..000000000 --- a/android/app/src/main/java/com/zzang/chongdae/presentation/view/home/OfferingViewModeFactory.kt +++ /dev/null @@ -1,13 +0,0 @@ -package com.zzang.chongdae.presentation.view.home - -import androidx.lifecycle.ViewModel -import androidx.lifecycle.ViewModelProvider -import com.zzang.chongdae.domain.repository.OfferingsRepository - -class OfferingViewModeFactory( - private val offeringsRepository: OfferingsRepository, -) : ViewModelProvider.Factory { - override fun create(modelClass: Class): T { - return OfferingViewModel(offeringsRepository) as T - } -} diff --git a/android/app/src/main/java/com/zzang/chongdae/presentation/view/home/OfferingViewModel.kt b/android/app/src/main/java/com/zzang/chongdae/presentation/view/home/OfferingViewModel.kt index 959c4bff3..fc8bf0e4f 100644 --- a/android/app/src/main/java/com/zzang/chongdae/presentation/view/home/OfferingViewModel.kt +++ b/android/app/src/main/java/com/zzang/chongdae/presentation/view/home/OfferingViewModel.kt @@ -2,7 +2,9 @@ package com.zzang.chongdae.presentation.view.home import androidx.lifecycle.LiveData import androidx.lifecycle.ViewModel +import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.viewModelScope +import androidx.lifecycle.viewmodel.CreationExtras import androidx.paging.Pager import androidx.paging.PagingConfig import androidx.paging.PagingData @@ -24,5 +26,18 @@ class OfferingViewModel( companion object { private const val PAGE_SIZE = 10 + + @Suppress("UNCHECKED_CAST") + fun getFactory(offeringsRepository: OfferingsRepository) = + object : ViewModelProvider.Factory { + override fun create( + modelClass: Class, + extras: CreationExtras, + ): T { + return OfferingViewModel( + offeringsRepository, + ) as T + } + } } }