From fbaba7c8764c7c4c762751686da1b13b975e847d Mon Sep 17 00:00:00 2001 From: Namyunsuk Date: Tue, 30 Jul 2024 10:56:38 +0900 Subject: [PATCH 1/2] =?UTF-8?q?refactor:=20=EB=B7=B0=EB=AA=A8=EB=8D=B8=20?= =?UTF-8?q?=ED=8C=A9=ED=86=A0=EB=A6=AC=EB=A5=BC=20=EB=B7=B0=EB=AA=A8?= =?UTF-8?q?=EB=8D=B8=EC=9D=98=20=EB=8F=99=EB=B0=98=EA=B0=9D=EC=B2=B4?= =?UTF-8?q?=EB=A1=9C=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../view/detail/OfferingDetailActivity.kt | 2 +- .../view/detail/OfferingDetailViewModel.kt | 21 ++++++++++++++++++- .../detail/OfferingDetailViewModelFactory.kt | 17 --------------- .../presentation/view/home/HomeFragment.kt | 2 +- .../view/home/OfferingViewModeFactory.kt | 13 ------------ .../view/home/OfferingViewModel.kt | 16 ++++++++++++++ 6 files changed, 38 insertions(+), 33 deletions(-) delete mode 100644 android/app/src/main/java/com/zzang/chongdae/presentation/view/detail/OfferingDetailViewModelFactory.kt delete mode 100644 android/app/src/main/java/com/zzang/chongdae/presentation/view/home/OfferingViewModeFactory.kt 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..c5cc7af1b 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,22 @@ 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..cb12d4e3b 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,19 @@ 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 + } + } } } From 378208351477c494344c1d0a6a1e6ed21f8bc6a8 Mon Sep 17 00:00:00 2001 From: Namyunsuk Date: Tue, 30 Jul 2024 10:57:06 +0900 Subject: [PATCH 2/2] =?UTF-8?q?style:=20lint=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../view/detail/OfferingDetailViewModel.kt | 3 +-- .../view/home/OfferingViewModel.kt | 21 +++++++++---------- 2 files changed, 11 insertions(+), 13 deletions(-) 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 c5cc7af1b..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 @@ -102,10 +102,9 @@ class OfferingDetailViewModel( ): T { return OfferingDetailViewModel( articleId, - offeringDetailRepository + offeringDetailRepository, ) 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 cb12d4e3b..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 @@ -28,17 +28,16 @@ class OfferingViewModel( 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 + fun getFactory(offeringsRepository: OfferingsRepository) = + object : ViewModelProvider.Factory { + override fun create( + modelClass: Class, + extras: CreationExtras, + ): T { + return OfferingViewModel( + offeringsRepository, + ) as T + } } - } } }