From 43ed43dc369685a882a9b787142dfc01cb10a20c Mon Sep 17 00:00:00 2001 From: inseonyun Date: Tue, 21 Nov 2023 12:31:01 +0900 Subject: [PATCH 01/21] refactor: DataBinding -> ViewBinding --- .../createStudy/CreateStudyActivity.kt | 9 +- .../main/res/layout/activity_create_study.xml | 107 ++++++++---------- 2 files changed, 52 insertions(+), 64 deletions(-) diff --git a/android/app/src/main/java/com/created/team201/presentation/createStudy/CreateStudyActivity.kt b/android/app/src/main/java/com/created/team201/presentation/createStudy/CreateStudyActivity.kt index 18e06559..c5ec6e30 100644 --- a/android/app/src/main/java/com/created/team201/presentation/createStudy/CreateStudyActivity.kt +++ b/android/app/src/main/java/com/created/team201/presentation/createStudy/CreateStudyActivity.kt @@ -16,7 +16,7 @@ import androidx.lifecycle.lifecycleScope import androidx.lifecycle.repeatOnLifecycle import com.created.team201.R import com.created.team201.databinding.ActivityCreateStudyBinding -import com.created.team201.presentation.common.BindingActivity +import com.created.team201.presentation.common.BindingViewActivity import com.created.team201.presentation.createStudy.model.CreateStudyUiState.Fail import com.created.team201.presentation.createStudy.model.CreateStudyUiState.Idle import com.created.team201.presentation.createStudy.model.CreateStudyUiState.Success @@ -32,13 +32,12 @@ import kotlinx.coroutines.launch @AndroidEntryPoint class CreateStudyActivity : - BindingActivity(R.layout.activity_create_study) { + BindingViewActivity(ActivityCreateStudyBinding::inflate) { private val createStudyViewModel: CreateStudyViewModel by viewModels() override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - initBinding() initActionBar() setupCollectCreateStudyState() setupCollectCreateStudyUiState() @@ -51,10 +50,6 @@ class CreateStudyActivity : return super.dispatchTouchEvent(ev) } - private fun initBinding() { - binding.lifecycleOwner = this - } - private fun initActionBar() { setSupportActionBar(binding.tbCreateStudy) supportActionBar?.setHomeActionContentDescription(R.string.toolbar_back_text) diff --git a/android/app/src/main/res/layout/activity_create_study.xml b/android/app/src/main/res/layout/activity_create_study.xml index 354e2169..0d4c90eb 100644 --- a/android/app/src/main/res/layout/activity_create_study.xml +++ b/android/app/src/main/res/layout/activity_create_study.xml @@ -1,59 +1,52 @@ - - - - - - - - - - - - - - - - - - + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="match_parent"> + + + + + + + + + + From bdcf283f763bbc68790a4ababd0f9e20d4e1efdd Mon Sep 17 00:00:00 2001 From: inseonyun Date: Tue, 21 Nov 2023 12:33:21 +0900 Subject: [PATCH 02/21] =?UTF-8?q?refactor:=20flow=20collect=20=ED=99=95?= =?UTF-8?q?=EC=9E=A5=ED=95=A8=EC=88=98=20=EC=82=AC=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../createStudy/CreateStudyActivity.kt | 58 ++++++++----------- 1 file changed, 24 insertions(+), 34 deletions(-) diff --git a/android/app/src/main/java/com/created/team201/presentation/createStudy/CreateStudyActivity.kt b/android/app/src/main/java/com/created/team201/presentation/createStudy/CreateStudyActivity.kt index c5ec6e30..79fa946d 100644 --- a/android/app/src/main/java/com/created/team201/presentation/createStudy/CreateStudyActivity.kt +++ b/android/app/src/main/java/com/created/team201/presentation/createStudy/CreateStudyActivity.kt @@ -11,9 +11,6 @@ import androidx.activity.viewModels import androidx.annotation.StringRes import androidx.fragment.app.Fragment import androidx.fragment.app.commit -import androidx.lifecycle.Lifecycle -import androidx.lifecycle.lifecycleScope -import androidx.lifecycle.repeatOnLifecycle import com.created.team201.R import com.created.team201.databinding.ActivityCreateStudyBinding import com.created.team201.presentation.common.BindingViewActivity @@ -26,9 +23,9 @@ import com.created.team201.presentation.createStudy.model.FragmentType import com.created.team201.presentation.createStudy.model.FragmentType.FIRST import com.created.team201.presentation.createStudy.model.FragmentType.SECOND import com.created.team201.presentation.studyDetail.StudyDetailActivity +import com.created.team201.util.collectLatestOnStarted +import com.created.team201.util.collectOnStarted import dagger.hilt.android.AndroidEntryPoint -import kotlinx.coroutines.flow.collectLatest -import kotlinx.coroutines.launch @AndroidEntryPoint class CreateStudyActivity : @@ -79,32 +76,29 @@ class CreateStudyActivity : } private fun setupCollectCreateStudyUiState() { - lifecycleScope.launch { - createStudyViewModel.createStudyUiState.collectLatest { createStudyUiState -> - lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) { - when (createStudyUiState) { - is Success -> { - showToast(R.string.create_study_toast_create_study_success) - startActivity( - StudyDetailActivity.getIntent( - this@CreateStudyActivity, - createStudyUiState.studyId - ), - ) - - finish() - } - - is Fail -> { - showToast(R.string.create_study_toast_create_study_fail) - finish() - } - - is Idle -> throw IllegalArgumentException() + createStudyViewModel.createStudyUiState + .collectLatestOnStarted(this) { createStudyUiState -> + when (createStudyUiState) { + is Success -> { + showToast(R.string.create_study_toast_create_study_success) + startActivity( + StudyDetailActivity.getIntent( + this@CreateStudyActivity, + createStudyUiState.studyId + ), + ) + + finish() } + + is Fail -> { + showToast(R.string.create_study_toast_create_study_fail) + finish() + } + + is Idle -> throw IllegalArgumentException() } } - } } private fun showToast(@StringRes messageRes: Int) { @@ -112,12 +106,8 @@ class CreateStudyActivity : } private fun setupCollectCreateStudyState() { - lifecycleScope.launch { - lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) { - createStudyViewModel.fragmentState.collect { fragmentState -> - showFragment(fragmentState.type) - } - } + createStudyViewModel.fragmentState.collectOnStarted(this) { fragmentState -> + showFragment(fragmentState.type) } } From 602a632d754e17d517b0e87d160d01981c8afc39 Mon Sep 17 00:00:00 2001 From: inseonyun Date: Tue, 21 Nov 2023 13:28:05 +0900 Subject: [PATCH 03/21] refactor: FirstFragment DataBinding -> ViewBinding --- .../createStudy/FirstCreateStudyFragment.kt | 86 +++-- .../layout/fragment_first_create_study.xml | 310 ++++++++---------- android/app/src/main/res/values/strings.xml | 4 - 3 files changed, 206 insertions(+), 194 deletions(-) diff --git a/android/app/src/main/java/com/created/team201/presentation/createStudy/FirstCreateStudyFragment.kt b/android/app/src/main/java/com/created/team201/presentation/createStudy/FirstCreateStudyFragment.kt index 3a24afae..c0628c2e 100644 --- a/android/app/src/main/java/com/created/team201/presentation/createStudy/FirstCreateStudyFragment.kt +++ b/android/app/src/main/java/com/created/team201/presentation/createStudy/FirstCreateStudyFragment.kt @@ -9,34 +9,79 @@ import androidx.lifecycle.lifecycleScope import androidx.lifecycle.repeatOnLifecycle import com.created.team201.R import com.created.team201.databinding.FragmentFirstCreateStudyBinding -import com.created.team201.presentation.common.BindingFragment +import com.created.team201.presentation.common.BindingViewFragment import com.created.team201.presentation.createStudy.bottomSheet.CycleBottomSheetFragment import com.created.team201.presentation.createStudy.bottomSheet.PeopleCountBottomSheetFragment import com.created.team201.presentation.createStudy.bottomSheet.StudyDateBottomSheetFragment +import com.created.team201.util.collectOnStarted import com.google.android.material.bottomsheet.BottomSheetDialogFragment import dagger.hilt.android.AndroidEntryPoint import kotlinx.coroutines.launch @AndroidEntryPoint class FirstCreateStudyFragment : - BindingFragment(R.layout.fragment_first_create_study) { + BindingViewFragment(FragmentFirstCreateStudyBinding::inflate) { private val createStudyViewModel: CreateStudyViewModel by activityViewModels() override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - initBinding() + setupPeopleCount() + setupStudyDate() + setupStudyCycle() + setupNextClick() setupCollectEnableNext() } - private fun initBinding() { - binding.lifecycleOwner = viewLifecycleOwner - binding.viewModel = createStudyViewModel - binding.onInputClickListener = ::setOnInputClick + private fun setupPeopleCount() { + createStudyViewModel.peopleCount.collectOnStarted(viewLifecycleOwner) { peopleCount -> + if (peopleCount == -1) return@collectOnStarted + + binding.tvFirstCreateStudyPeopleCount.text = + getString( + R.string.first_create_study_formatter_information_people_count, + peopleCount + ) + } + + binding.tvFirstCreateStudyPeopleCount.setOnClickListener( + setOnInputClick(TAG_CREATE_STUDY_PEOPLE_COUNT) + ) + } + + private fun setupStudyDate() { + createStudyViewModel.studyDate.collectOnStarted(viewLifecycleOwner) { studyDate -> + if (studyDate == -1) return@collectOnStarted + + binding.tvFirstCreateStudyStudyDate.text = + getString(R.string.first_create_study_formatter_information_study_date, studyDate) + } + + binding.tvFirstCreateStudyStudyDate.setOnClickListener( + setOnInputClick(TAG_CREATE_STUDY_STUDY_DATE) + ) + } + + private fun setupStudyCycle() { + createStudyViewModel.cycle.collectOnStarted(viewLifecycleOwner) { cycle -> + if (cycle == -1) return@collectOnStarted + + binding.tvFirstCreateStudyCycle.text = + getString(R.string.first_create_study_formatter_information_cycle, cycle) + } + + binding.tvFirstCreateStudyCycle.setOnClickListener( + setOnInputClick(TAG_CREATE_STUDY_CYCLE) + ) } + private fun setupNextClick() { + binding.tvFirstCreateStudyBtnNext.setOnClickListener { + createStudyViewModel.navigateToNext() + } + } - private fun setOnInputClick(tag: String) { + private fun setOnInputClick(tag: String): View.OnClickListener = View.OnClickListener { removeAllFragment() createBottomSheetFragment(tag)?.show(childFragmentManager, tag) } @@ -51,21 +96,10 @@ class FirstCreateStudyFragment : private fun createBottomSheetFragment(tag: String): BottomSheetDialogFragment? { return when (tag) { - getString(R.string.create_study_tag_people_count) -> { - PeopleCountBottomSheetFragment() - } - - getString(R.string.create_study_tag_study_date) -> { - StudyDateBottomSheetFragment() - } - - getString(R.string.create_study_tag_cycle) -> { - CycleBottomSheetFragment() - } - - else -> { - null - } + TAG_CREATE_STUDY_PEOPLE_COUNT -> PeopleCountBottomSheetFragment() + TAG_CREATE_STUDY_STUDY_DATE -> StudyDateBottomSheetFragment() + TAG_CREATE_STUDY_CYCLE -> CycleBottomSheetFragment() + else -> null } } @@ -78,4 +112,10 @@ class FirstCreateStudyFragment : } } } + + companion object { + private const val TAG_CREATE_STUDY_PEOPLE_COUNT = "TAG_CREATE_STUDY_PEOPLE_COUNT" + private const val TAG_CREATE_STUDY_STUDY_DATE = "TAG_CREATE_STUDY_STUDY_DATE" + private const val TAG_CREATE_STUDY_CYCLE = "TAG_CREATE_STUDY_CYCLE" + } } diff --git a/android/app/src/main/res/layout/fragment_first_create_study.xml b/android/app/src/main/res/layout/fragment_first_create_study.xml index aa4da490..821c6fdc 100644 --- a/android/app/src/main/res/layout/fragment_first_create_study.xml +++ b/android/app/src/main/res/layout/fragment_first_create_study.xml @@ -1,179 +1,155 @@ - + - + - + - - + - + - + - + - + - + - + - + - - - - - - - - - - + diff --git a/android/app/src/main/res/values/strings.xml b/android/app/src/main/res/values/strings.xml index a6f254fb..fe577110 100644 --- a/android/app/src/main/res/values/strings.xml +++ b/android/app/src/main/res/values/strings.xml @@ -170,10 +170,6 @@ 스터디 개설에 성공했습니다 스터디 개설에 실패했습니다 - TAG_CREATE_STUDY_PEOPLE_COUNT - TAG_CREATE_STUDY_STUDY_DATE - TAG_CREATE_STUDY_CYCLE - 스터디는 몇 명과 함께하시나요? 모집인원을 알려주세요!\n최소 2명, 최대 8명까지 함께할 수 있습니다. From 23511e3ce08c8ea7226006d6639f96f7213d6b2d Mon Sep 17 00:00:00 2001 From: inseonyun Date: Tue, 21 Nov 2023 13:28:45 +0900 Subject: [PATCH 04/21] =?UTF-8?q?refactor:=20=EC=8A=A4=ED=84=B0=EB=94=94?= =?UTF-8?q?=EA=B0=9C=EC=84=A4=20=EB=B7=B0=20=EB=B0=94=EC=9D=B8=EB=94=A9=20?= =?UTF-8?q?=EC=96=B4=EB=8C=91=ED=84=B0=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/createStudy/util/BindingAdapter.kt | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 android/app/src/main/java/com/created/team201/presentation/createStudy/util/BindingAdapter.kt diff --git a/android/app/src/main/java/com/created/team201/presentation/createStudy/util/BindingAdapter.kt b/android/app/src/main/java/com/created/team201/presentation/createStudy/util/BindingAdapter.kt deleted file mode 100644 index 2761f348..00000000 --- a/android/app/src/main/java/com/created/team201/presentation/createStudy/util/BindingAdapter.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.created.team201.presentation.createStudy.util - -import android.widget.TextView -import androidx.databinding.BindingAdapter - -@BindingAdapter("app:textIntValue", "app:textFormatter") -fun TextView.setTextValue(value: Int, formatter: String) { - if (value == -1 || formatter.isEmpty()) return - text = formatter.format(value) -} From 50f79509fe0dcd0743c5c369df314e40b9a222fa Mon Sep 17 00:00:00 2001 From: inseonyun Date: Tue, 21 Nov 2023 13:38:55 +0900 Subject: [PATCH 05/21] refactor: SecondFragment DataBinding -> ViewBinding --- .../createStudy/SecondCreateStudyFragment.kt | 22 +- .../layout/fragment_second_create_study.xml | 219 ++++++++---------- 2 files changed, 117 insertions(+), 124 deletions(-) diff --git a/android/app/src/main/java/com/created/team201/presentation/createStudy/SecondCreateStudyFragment.kt b/android/app/src/main/java/com/created/team201/presentation/createStudy/SecondCreateStudyFragment.kt index f6c2b5bb..bb713963 100644 --- a/android/app/src/main/java/com/created/team201/presentation/createStudy/SecondCreateStudyFragment.kt +++ b/android/app/src/main/java/com/created/team201/presentation/createStudy/SecondCreateStudyFragment.kt @@ -2,27 +2,35 @@ package com.created.team201.presentation.createStudy import android.os.Bundle import android.view.View +import androidx.core.widget.doOnTextChanged import androidx.fragment.app.activityViewModels import androidx.lifecycle.Lifecycle import androidx.lifecycle.lifecycleScope import androidx.lifecycle.repeatOnLifecycle -import com.created.team201.R import com.created.team201.databinding.FragmentSecondCreateStudyBinding -import com.created.team201.presentation.common.BindingFragment +import com.created.team201.presentation.common.BindingViewFragment import kotlinx.coroutines.launch class SecondCreateStudyFragment : - BindingFragment(R.layout.fragment_second_create_study) { + BindingViewFragment(FragmentSecondCreateStudyBinding::inflate) { private val createStudyViewModel: CreateStudyViewModel by activityViewModels() override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - initBinding() + setupStudyNameTitleChanged() + setupStudyIntroductionChanged() setupCollectEnableNext() } - private fun initBinding() { - binding.lifecycleOwner = viewLifecycleOwner - binding.viewModel = createStudyViewModel + private fun setupStudyNameTitleChanged() { + binding.tvSecondCreateStudyStudyNameTitle.doOnTextChanged { text, _, _, _ -> + createStudyViewModel.setStudyName(text.toString()) + } + } + + private fun setupStudyIntroductionChanged() { + binding.etSecondCreateStudyStudyIntroduction.doOnTextChanged { text, _, _, _ -> + createStudyViewModel.setStudyIntroduction(text.toString()) + } } private fun setupCollectEnableNext() { diff --git a/android/app/src/main/res/layout/fragment_second_create_study.xml b/android/app/src/main/res/layout/fragment_second_create_study.xml index 0091a3f9..4db5acba 100644 --- a/android/app/src/main/res/layout/fragment_second_create_study.xml +++ b/android/app/src/main/res/layout/fragment_second_create_study.xml @@ -1,127 +1,112 @@ - + - + - - + - - + - + + - + - + - - - - - - - - + From 7f3ba5d3db156cbb5e858f168de00290cdd5ae18 Mon Sep 17 00:00:00 2001 From: inseonyun Date: Tue, 21 Nov 2023 13:39:54 +0900 Subject: [PATCH 06/21] =?UTF-8?q?refactor:=20flow=20collect=20=ED=99=95?= =?UTF-8?q?=EC=9E=A5=ED=95=A8=EC=88=98=20=EC=82=AC=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../createStudy/FirstCreateStudyFragment.kt | 12 ++---------- .../createStudy/SecondCreateStudyFragment.kt | 13 +++---------- 2 files changed, 5 insertions(+), 20 deletions(-) diff --git a/android/app/src/main/java/com/created/team201/presentation/createStudy/FirstCreateStudyFragment.kt b/android/app/src/main/java/com/created/team201/presentation/createStudy/FirstCreateStudyFragment.kt index c0628c2e..4883113e 100644 --- a/android/app/src/main/java/com/created/team201/presentation/createStudy/FirstCreateStudyFragment.kt +++ b/android/app/src/main/java/com/created/team201/presentation/createStudy/FirstCreateStudyFragment.kt @@ -4,9 +4,6 @@ import android.os.Bundle import android.view.View import androidx.fragment.app.activityViewModels import androidx.fragment.app.commit -import androidx.lifecycle.Lifecycle -import androidx.lifecycle.lifecycleScope -import androidx.lifecycle.repeatOnLifecycle import com.created.team201.R import com.created.team201.databinding.FragmentFirstCreateStudyBinding import com.created.team201.presentation.common.BindingViewFragment @@ -16,7 +13,6 @@ import com.created.team201.presentation.createStudy.bottomSheet.StudyDateBottomS import com.created.team201.util.collectOnStarted import com.google.android.material.bottomsheet.BottomSheetDialogFragment import dagger.hilt.android.AndroidEntryPoint -import kotlinx.coroutines.launch @AndroidEntryPoint class FirstCreateStudyFragment : @@ -104,12 +100,8 @@ class FirstCreateStudyFragment : } private fun setupCollectEnableNext() { - viewLifecycleOwner.lifecycleScope.launch { - viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) { - createStudyViewModel.isEnableFirstCreateStudyNext.collect { isEnable -> - binding.tvFirstCreateStudyBtnNext.isEnabled = isEnable - } - } + createStudyViewModel.isEnableFirstCreateStudyNext.collectOnStarted(viewLifecycleOwner) { isEnable -> + binding.tvFirstCreateStudyBtnNext.isEnabled = isEnable } } diff --git a/android/app/src/main/java/com/created/team201/presentation/createStudy/SecondCreateStudyFragment.kt b/android/app/src/main/java/com/created/team201/presentation/createStudy/SecondCreateStudyFragment.kt index bb713963..e17e37ef 100644 --- a/android/app/src/main/java/com/created/team201/presentation/createStudy/SecondCreateStudyFragment.kt +++ b/android/app/src/main/java/com/created/team201/presentation/createStudy/SecondCreateStudyFragment.kt @@ -4,12 +4,9 @@ import android.os.Bundle import android.view.View import androidx.core.widget.doOnTextChanged import androidx.fragment.app.activityViewModels -import androidx.lifecycle.Lifecycle -import androidx.lifecycle.lifecycleScope -import androidx.lifecycle.repeatOnLifecycle import com.created.team201.databinding.FragmentSecondCreateStudyBinding import com.created.team201.presentation.common.BindingViewFragment -import kotlinx.coroutines.launch +import com.created.team201.util.collectOnStarted class SecondCreateStudyFragment : BindingViewFragment(FragmentSecondCreateStudyBinding::inflate) { @@ -34,12 +31,8 @@ class SecondCreateStudyFragment : } private fun setupCollectEnableNext() { - viewLifecycleOwner.lifecycleScope.launch { - viewLifecycleOwner.lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) { - createStudyViewModel.isEnableSecondCreateStudyNext.collect { isEnable -> - binding.tvSecondCreateStudyBtnNext.isEnabled = isEnable - } - } + createStudyViewModel.isEnableSecondCreateStudyNext.collectOnStarted(viewLifecycleOwner) { isEnable -> + binding.tvSecondCreateStudyBtnNext.isEnabled = isEnable } } } From 26d6b1fe90e4bd1315b4bf79b985471776b26f8a Mon Sep 17 00:00:00 2001 From: inseonyun Date: Tue, 21 Nov 2023 13:46:47 +0900 Subject: [PATCH 07/21] =?UTF-8?q?refactor:=20=EC=8A=A4=ED=84=B0=EB=94=94?= =?UTF-8?q?=20=EA=B0=9C=EC=84=A4=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../createStudy/SecondCreateStudyFragment.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/android/app/src/main/java/com/created/team201/presentation/createStudy/SecondCreateStudyFragment.kt b/android/app/src/main/java/com/created/team201/presentation/createStudy/SecondCreateStudyFragment.kt index e17e37ef..f07328bd 100644 --- a/android/app/src/main/java/com/created/team201/presentation/createStudy/SecondCreateStudyFragment.kt +++ b/android/app/src/main/java/com/created/team201/presentation/createStudy/SecondCreateStudyFragment.kt @@ -15,11 +15,12 @@ class SecondCreateStudyFragment : override fun onViewCreated(view: View, savedInstanceState: Bundle?) { setupStudyNameTitleChanged() setupStudyIntroductionChanged() + setupNextClick() setupCollectEnableNext() } private fun setupStudyNameTitleChanged() { - binding.tvSecondCreateStudyStudyNameTitle.doOnTextChanged { text, _, _, _ -> + binding.etSecondCreateStudyStudyName.doOnTextChanged { text, _, _, _ -> createStudyViewModel.setStudyName(text.toString()) } } @@ -30,6 +31,12 @@ class SecondCreateStudyFragment : } } + private fun setupNextClick() { + binding.tvSecondCreateStudyBtnNext.setOnClickListener { + createStudyViewModel.createStudy() + } + } + private fun setupCollectEnableNext() { createStudyViewModel.isEnableSecondCreateStudyNext.collectOnStarted(viewLifecycleOwner) { isEnable -> binding.tvSecondCreateStudyBtnNext.isEnabled = isEnable From a9143f97243793ebbe787fd56427b6f6708bb603 Mon Sep 17 00:00:00 2001 From: inseonyun Date: Tue, 21 Nov 2023 13:54:52 +0900 Subject: [PATCH 08/21] =?UTF-8?q?refactor:=20BindingViewBottomSheetFragmen?= =?UTF-8?q?t=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/BindingViewBottomSheetFragment.kt | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 android/app/src/main/java/com/created/team201/presentation/common/BindingViewBottomSheetFragment.kt diff --git a/android/app/src/main/java/com/created/team201/presentation/common/BindingViewBottomSheetFragment.kt b/android/app/src/main/java/com/created/team201/presentation/common/BindingViewBottomSheetFragment.kt new file mode 100644 index 00000000..bdcc863c --- /dev/null +++ b/android/app/src/main/java/com/created/team201/presentation/common/BindingViewBottomSheetFragment.kt @@ -0,0 +1,30 @@ +package com.created.team201.presentation.common + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.viewbinding.ViewBinding +import com.created.team201.R +import com.google.android.material.bottomsheet.BottomSheetDialogFragment + +abstract class BindingViewBottomSheetFragment( + private val bindingInflater: (LayoutInflater) -> VB +) : BottomSheetDialogFragment() { + private var _binding: VB? = null + val binding get() = _binding ?: error(R.string.error_baseFragment) + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle?, + ): View { + _binding = bindingInflater(inflater) + return binding.root + } + + override fun onDestroyView() { + super.onDestroyView() + _binding = null + } +} From 4c712f750ed06a287d132ff548f069ab42c3a67f Mon Sep 17 00:00:00 2001 From: inseonyun Date: Tue, 21 Nov 2023 13:55:05 +0900 Subject: [PATCH 09/21] refactor: CycleBottomSheetFragment DataBinding -> ViewBinding --- .../bottomSheet/CycleBottomSheetFragment.kt | 50 +++-- .../layout/fragment_cycle_bottom_sheet.xml | 176 ++++++++---------- 2 files changed, 114 insertions(+), 112 deletions(-) diff --git a/android/app/src/main/java/com/created/team201/presentation/createStudy/bottomSheet/CycleBottomSheetFragment.kt b/android/app/src/main/java/com/created/team201/presentation/createStudy/bottomSheet/CycleBottomSheetFragment.kt index d4420c34..a5554510 100644 --- a/android/app/src/main/java/com/created/team201/presentation/createStudy/bottomSheet/CycleBottomSheetFragment.kt +++ b/android/app/src/main/java/com/created/team201/presentation/createStudy/bottomSheet/CycleBottomSheetFragment.kt @@ -1,34 +1,58 @@ package com.created.team201.presentation.createStudy.bottomSheet import android.os.Bundle +import android.view.LayoutInflater import android.view.View +import android.view.ViewGroup import androidx.fragment.app.activityViewModels -import com.created.team201.R import com.created.team201.databinding.FragmentCycleBottomSheetBinding -import com.created.team201.presentation.common.BindingBottomSheetFragment +import com.created.team201.presentation.common.BindingViewBottomSheetFragment import com.created.team201.presentation.createStudy.CreateStudyViewModel +import com.created.team201.util.collectOnStarted +import com.google.android.material.bottomsheet.BottomSheetBehavior +import com.google.android.material.bottomsheet.BottomSheetDialog class CycleBottomSheetFragment : - BindingBottomSheetFragment( - R.layout.fragment_cycle_bottom_sheet, + BindingViewBottomSheetFragment( + FragmentCycleBottomSheetBinding::inflate, ) { private val createStudyViewModel: CreateStudyViewModel by activityViewModels() + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View { + dialog?.let { + val behavior = (it as BottomSheetDialog).behavior + behavior.state = BottomSheetBehavior.STATE_EXPANDED + it.setCanceledOnTouchOutside(false) + } + return super.onCreateView(inflater, container, savedInstanceState) + } + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - initBinding() + setupSaveButtonClick() + setupCancelButtonClick() + collectCycle() + } + + private fun setupSaveButtonClick() { + binding.tvCycleBottomSheetBtnSave.setOnClickListener { + createStudyViewModel.setCycle(binding.spCycle.value) + dismiss() + } } - private fun initBinding() { - binding.viewModel = createStudyViewModel - binding.onCancelClickListener = { dismiss() } - binding.onSaveClickListener = ::onSaveButtonClick - binding.lifecycleOwner = viewLifecycleOwner + private fun setupCancelButtonClick() { + binding.tvCycleBottomSheetBtnCancel.setOnClickListener { dismiss() } } - private fun onSaveButtonClick() { - createStudyViewModel.setCycle(binding.spCycle.value) - dismiss() + private fun collectCycle() { + createStudyViewModel.cycle.collectOnStarted(viewLifecycleOwner) { cycle -> + binding.spCycle.setValue(cycle) + } } } diff --git a/android/app/src/main/res/layout/fragment_cycle_bottom_sheet.xml b/android/app/src/main/res/layout/fragment_cycle_bottom_sheet.xml index 803fd993..c75c386e 100644 --- a/android/app/src/main/res/layout/fragment_cycle_bottom_sheet.xml +++ b/android/app/src/main/res/layout/fragment_cycle_bottom_sheet.xml @@ -1,107 +1,85 @@ - + - + - - - - - - - - - - - - + android:layout_marginVertical="20dp" + android:text="@string/bottom_sheet_fragment_cycle_title_text" + android:textAlignment="center" + android:textAppearance="@style/picker_sb18" + android:textColor="@color/white" + app:layout_constraintBottom_toTopOf="@id/sp_cycle" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@id/view_create_study_cycle" /> - - - + - + - + - + From 2c9120ef15804bb7f06b71a0d18dea11e5df4bbf Mon Sep 17 00:00:00 2001 From: inseonyun Date: Tue, 21 Nov 2023 13:58:10 +0900 Subject: [PATCH 10/21] refactor: PeopleCountBottomSheetFragment DataBinding -> ViewBinding --- .../PeopleCountBottomSheetFragment.kt | 50 +++-- .../fragment_people_count_bottom_sheet.xml | 176 ++++++++---------- 2 files changed, 114 insertions(+), 112 deletions(-) diff --git a/android/app/src/main/java/com/created/team201/presentation/createStudy/bottomSheet/PeopleCountBottomSheetFragment.kt b/android/app/src/main/java/com/created/team201/presentation/createStudy/bottomSheet/PeopleCountBottomSheetFragment.kt index 39006fe4..26704576 100644 --- a/android/app/src/main/java/com/created/team201/presentation/createStudy/bottomSheet/PeopleCountBottomSheetFragment.kt +++ b/android/app/src/main/java/com/created/team201/presentation/createStudy/bottomSheet/PeopleCountBottomSheetFragment.kt @@ -1,34 +1,58 @@ package com.created.team201.presentation.createStudy.bottomSheet import android.os.Bundle +import android.view.LayoutInflater import android.view.View +import android.view.ViewGroup import androidx.fragment.app.activityViewModels -import com.created.team201.R import com.created.team201.databinding.FragmentPeopleCountBottomSheetBinding -import com.created.team201.presentation.common.BindingBottomSheetFragment +import com.created.team201.presentation.common.BindingViewBottomSheetFragment import com.created.team201.presentation.createStudy.CreateStudyViewModel +import com.created.team201.util.collectOnStarted +import com.google.android.material.bottomsheet.BottomSheetBehavior +import com.google.android.material.bottomsheet.BottomSheetDialog class PeopleCountBottomSheetFragment : - BindingBottomSheetFragment( - R.layout.fragment_people_count_bottom_sheet, + BindingViewBottomSheetFragment( + FragmentPeopleCountBottomSheetBinding::inflate, ) { private val createStudyViewModel: CreateStudyViewModel by activityViewModels() + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View { + dialog?.let { + val behavior = (it as BottomSheetDialog).behavior + behavior.state = BottomSheetBehavior.STATE_EXPANDED + it.setCanceledOnTouchOutside(false) + } + return super.onCreateView(inflater, container, savedInstanceState) + } + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - initBinding() + setupSaveButtonClick() + setupCancelButtonClick() + collectPeopleCount() + } + + private fun setupSaveButtonClick() { + binding.tvPeopleCountBottomSheetBtnSave.setOnClickListener { + createStudyViewModel.setPeopleCount(binding.spPeopleCount.value) + dismiss() + } } - private fun initBinding() { - binding.viewModel = createStudyViewModel - binding.onCancelClickListener = { dismiss() } - binding.onSaveClickListener = ::onSaveButtonClick - binding.lifecycleOwner = viewLifecycleOwner + private fun setupCancelButtonClick() { + binding.tvPeopleCountBottomSheetBtnCancel.setOnClickListener { dismiss() } } - private fun onSaveButtonClick() { - createStudyViewModel.setPeopleCount(binding.spPeopleCount.value) - dismiss() + private fun collectPeopleCount() { + createStudyViewModel.peopleCount.collectOnStarted(viewLifecycleOwner) { peopleCount -> + binding.spPeopleCount.setValue(peopleCount) + } } } diff --git a/android/app/src/main/res/layout/fragment_people_count_bottom_sheet.xml b/android/app/src/main/res/layout/fragment_people_count_bottom_sheet.xml index 43b79a4d..11b48b61 100644 --- a/android/app/src/main/res/layout/fragment_people_count_bottom_sheet.xml +++ b/android/app/src/main/res/layout/fragment_people_count_bottom_sheet.xml @@ -1,107 +1,85 @@ - + - + - - - - - - - - - - - - + android:layout_marginVertical="20dp" + android:text="@string/bottom_sheet_fragment_people_count_title_text" + android:textAlignment="center" + android:textAppearance="@style/picker_sb18" + android:textColor="@color/white" + app:layout_constraintBottom_toTopOf="@id/sp_people_count" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@id/view_create_study_people_count" /> - - - + - + - + - + From e9b0b526a99194d43afc38295fe11bb541b63ed8 Mon Sep 17 00:00:00 2001 From: inseonyun Date: Tue, 21 Nov 2023 14:00:26 +0900 Subject: [PATCH 11/21] refactor: StudyDateBottomSheetFragment DataBinding -> ViewBinding --- .../StudyDateBottomSheetFragment.kt | 50 +++-- .../fragment_study_date_bottom_sheet.xml | 176 ++++++++---------- 2 files changed, 114 insertions(+), 112 deletions(-) diff --git a/android/app/src/main/java/com/created/team201/presentation/createStudy/bottomSheet/StudyDateBottomSheetFragment.kt b/android/app/src/main/java/com/created/team201/presentation/createStudy/bottomSheet/StudyDateBottomSheetFragment.kt index 7d3ca7a4..fc4f52e2 100644 --- a/android/app/src/main/java/com/created/team201/presentation/createStudy/bottomSheet/StudyDateBottomSheetFragment.kt +++ b/android/app/src/main/java/com/created/team201/presentation/createStudy/bottomSheet/StudyDateBottomSheetFragment.kt @@ -1,34 +1,58 @@ package com.created.team201.presentation.createStudy.bottomSheet import android.os.Bundle +import android.view.LayoutInflater import android.view.View +import android.view.ViewGroup import androidx.fragment.app.activityViewModels -import com.created.team201.R import com.created.team201.databinding.FragmentStudyDateBottomSheetBinding -import com.created.team201.presentation.common.BindingBottomSheetFragment +import com.created.team201.presentation.common.BindingViewBottomSheetFragment import com.created.team201.presentation.createStudy.CreateStudyViewModel +import com.created.team201.util.collectOnStarted +import com.google.android.material.bottomsheet.BottomSheetBehavior +import com.google.android.material.bottomsheet.BottomSheetDialog class StudyDateBottomSheetFragment : - BindingBottomSheetFragment( - R.layout.fragment_study_date_bottom_sheet, + BindingViewBottomSheetFragment( + FragmentStudyDateBottomSheetBinding::inflate, ) { private val createStudyViewModel: CreateStudyViewModel by activityViewModels() + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View { + dialog?.let { + val behavior = (it as BottomSheetDialog).behavior + behavior.state = BottomSheetBehavior.STATE_EXPANDED + it.setCanceledOnTouchOutside(false) + } + return super.onCreateView(inflater, container, savedInstanceState) + } + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - initBinding() + setupSaveButtonClick() + setupCancelButtonClick() + collectPeopleCount() + } + + private fun setupSaveButtonClick() { + binding.tvStudyDateBottomSheetBtnSave.setOnClickListener { + createStudyViewModel.setStudyDate(binding.spStudyDate.value) + dismiss() + } } - private fun initBinding() { - binding.viewModel = createStudyViewModel - binding.onCancelClickListener = { dismiss() } - binding.onSaveClickListener = ::onSaveButtonClick - binding.lifecycleOwner = viewLifecycleOwner + private fun setupCancelButtonClick() { + binding.tvStudyDateBottomSheetBtnCancel.setOnClickListener { dismiss() } } - private fun onSaveButtonClick() { - createStudyViewModel.setStudyDate(binding.spStudyDate.value) - dismiss() + private fun collectPeopleCount() { + createStudyViewModel.studyDate.collectOnStarted(viewLifecycleOwner) { studyDate -> + binding.spStudyDate.setValue(studyDate) + } } } diff --git a/android/app/src/main/res/layout/fragment_study_date_bottom_sheet.xml b/android/app/src/main/res/layout/fragment_study_date_bottom_sheet.xml index 199d2c39..640dd5fc 100644 --- a/android/app/src/main/res/layout/fragment_study_date_bottom_sheet.xml +++ b/android/app/src/main/res/layout/fragment_study_date_bottom_sheet.xml @@ -1,107 +1,85 @@ - + - + - - - - - - - - - - - - + android:layout_marginVertical="20dp" + android:text="@string/bottom_sheet_fragment_study_date_title_text" + android:textAlignment="center" + android:textAppearance="@style/picker_sb18" + android:textColor="@color/white" + app:layout_constraintBottom_toTopOf="@id/sp_study_date" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@id/view_create_study_study_date" /> - - - + - + - + - + From d109ec5b949e9d610f6999e183fe52b490dbd100 Mon Sep 17 00:00:00 2001 From: inseonyun Date: Tue, 21 Nov 2023 14:39:28 +0900 Subject: [PATCH 12/21] =?UTF-8?q?refactor:=20collect=20=ED=95=A8=EC=88=98?= =?UTF-8?q?=EB=AA=85=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/createStudy/CreateStudyActivity.kt | 8 ++++---- .../presentation/createStudy/FirstCreateStudyFragment.kt | 4 ++-- .../presentation/createStudy/SecondCreateStudyFragment.kt | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/android/app/src/main/java/com/created/team201/presentation/createStudy/CreateStudyActivity.kt b/android/app/src/main/java/com/created/team201/presentation/createStudy/CreateStudyActivity.kt index 79fa946d..8b5bfe78 100644 --- a/android/app/src/main/java/com/created/team201/presentation/createStudy/CreateStudyActivity.kt +++ b/android/app/src/main/java/com/created/team201/presentation/createStudy/CreateStudyActivity.kt @@ -36,8 +36,8 @@ class CreateStudyActivity : super.onCreate(savedInstanceState) initActionBar() - setupCollectCreateStudyState() - setupCollectCreateStudyUiState() + collectCreateStudyState() + collectCreateStudyUiState() } override fun dispatchTouchEvent(ev: MotionEvent): Boolean { @@ -75,7 +75,7 @@ class CreateStudyActivity : } } - private fun setupCollectCreateStudyUiState() { + private fun collectCreateStudyUiState() { createStudyViewModel.createStudyUiState .collectLatestOnStarted(this) { createStudyUiState -> when (createStudyUiState) { @@ -105,7 +105,7 @@ class CreateStudyActivity : Toast.makeText(this, getString(messageRes), Toast.LENGTH_SHORT).show() } - private fun setupCollectCreateStudyState() { + private fun collectCreateStudyState() { createStudyViewModel.fragmentState.collectOnStarted(this) { fragmentState -> showFragment(fragmentState.type) } diff --git a/android/app/src/main/java/com/created/team201/presentation/createStudy/FirstCreateStudyFragment.kt b/android/app/src/main/java/com/created/team201/presentation/createStudy/FirstCreateStudyFragment.kt index 4883113e..a28ad73c 100644 --- a/android/app/src/main/java/com/created/team201/presentation/createStudy/FirstCreateStudyFragment.kt +++ b/android/app/src/main/java/com/created/team201/presentation/createStudy/FirstCreateStudyFragment.kt @@ -26,7 +26,7 @@ class FirstCreateStudyFragment : setupStudyDate() setupStudyCycle() setupNextClick() - setupCollectEnableNext() + collectEnableNext() } private fun setupPeopleCount() { @@ -99,7 +99,7 @@ class FirstCreateStudyFragment : } } - private fun setupCollectEnableNext() { + private fun collectEnableNext() { createStudyViewModel.isEnableFirstCreateStudyNext.collectOnStarted(viewLifecycleOwner) { isEnable -> binding.tvFirstCreateStudyBtnNext.isEnabled = isEnable } diff --git a/android/app/src/main/java/com/created/team201/presentation/createStudy/SecondCreateStudyFragment.kt b/android/app/src/main/java/com/created/team201/presentation/createStudy/SecondCreateStudyFragment.kt index f07328bd..fd63ff01 100644 --- a/android/app/src/main/java/com/created/team201/presentation/createStudy/SecondCreateStudyFragment.kt +++ b/android/app/src/main/java/com/created/team201/presentation/createStudy/SecondCreateStudyFragment.kt @@ -16,7 +16,7 @@ class SecondCreateStudyFragment : setupStudyNameTitleChanged() setupStudyIntroductionChanged() setupNextClick() - setupCollectEnableNext() + collectEnableNext() } private fun setupStudyNameTitleChanged() { @@ -37,7 +37,7 @@ class SecondCreateStudyFragment : } } - private fun setupCollectEnableNext() { + private fun collectEnableNext() { createStudyViewModel.isEnableSecondCreateStudyNext.collectOnStarted(viewLifecycleOwner) { isEnable -> binding.tvSecondCreateStudyBtnNext.isEnabled = isEnable } From e2221ad6caa16e1b9e817cb54c9e9a8891cb52ba Mon Sep 17 00:00:00 2001 From: inseonyun Date: Tue, 21 Nov 2023 14:41:51 +0900 Subject: [PATCH 13/21] =?UTF-8?q?refactor:=20Combine=20Flow=20->=20StateFl?= =?UTF-8?q?ow=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/createStudy/CreateStudyViewModel.kt | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/android/app/src/main/java/com/created/team201/presentation/createStudy/CreateStudyViewModel.kt b/android/app/src/main/java/com/created/team201/presentation/createStudy/CreateStudyViewModel.kt index 440a17bd..75e5d508 100644 --- a/android/app/src/main/java/com/created/team201/presentation/createStudy/CreateStudyViewModel.kt +++ b/android/app/src/main/java/com/created/team201/presentation/createStudy/CreateStudyViewModel.kt @@ -9,14 +9,15 @@ import com.created.team201.presentation.createStudy.model.FragmentState import com.created.team201.presentation.createStudy.model.FragmentState.FirstFragment import com.created.team201.presentation.createStudy.model.FragmentState.SecondFragment import dagger.hilt.android.lifecycle.HiltViewModel -import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharedFlow +import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asSharedFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.combine +import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch import javax.inject.Inject @@ -44,15 +45,15 @@ class CreateStudyViewModel @Inject constructor( MutableStateFlow(DEFAULT_STRING_VALUE) val studyIntroduction: StateFlow get() = _studyIntroduction.asStateFlow() - val isEnableFirstCreateStudyNext: Flow = + val isEnableFirstCreateStudyNext: StateFlow = combine(peopleCount, studyDate, cycle) { peopleCount, studyDate, cycle -> return@combine peopleCount != DEFAULT_INT_VALUE && studyDate != DEFAULT_INT_VALUE && cycle != DEFAULT_INT_VALUE - } + }.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), false) - val isEnableSecondCreateStudyNext: Flow = + val isEnableSecondCreateStudyNext: StateFlow = combine(studyName, studyIntroduction) { studyName, studyIntroduction -> return@combine studyName.isNotBlankAndEmpty() && studyIntroduction.isNotBlankAndEmpty() - } + }.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), false) private val _createStudyUiState: MutableSharedFlow = MutableSharedFlow() val createStudyUiState: SharedFlow get() = _createStudyUiState.asSharedFlow() From 0fa5b4f59b1776cc67956000e64544eca039a76b Mon Sep 17 00:00:00 2001 From: inseonyun Date: Tue, 21 Nov 2023 16:39:49 +0900 Subject: [PATCH 14/21] =?UTF-8?q?refactor:=20CreateStudyEvent=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../createStudy/CreateStudyActivity.kt | 58 ++++++++++++------- .../createStudy/CreateStudyViewModel.kt | 36 ++++++++---- 2 files changed, 60 insertions(+), 34 deletions(-) diff --git a/android/app/src/main/java/com/created/team201/presentation/createStudy/CreateStudyActivity.kt b/android/app/src/main/java/com/created/team201/presentation/createStudy/CreateStudyActivity.kt index 8b5bfe78..4dfb61b3 100644 --- a/android/app/src/main/java/com/created/team201/presentation/createStudy/CreateStudyActivity.kt +++ b/android/app/src/main/java/com/created/team201/presentation/createStudy/CreateStudyActivity.kt @@ -14,9 +14,14 @@ import androidx.fragment.app.commit import com.created.team201.R import com.created.team201.databinding.ActivityCreateStudyBinding import com.created.team201.presentation.common.BindingViewActivity +import com.created.team201.presentation.createStudy.CreateStudyViewModel.Event.CreateStudyFailure +import com.created.team201.presentation.createStudy.CreateStudyViewModel.Event.CreateStudySuccess +import com.created.team201.presentation.createStudy.CreateStudyViewModel.Event.NavigateToBefore +import com.created.team201.presentation.createStudy.CreateStudyViewModel.Event.NavigateToNext import com.created.team201.presentation.createStudy.model.CreateStudyUiState.Fail import com.created.team201.presentation.createStudy.model.CreateStudyUiState.Idle import com.created.team201.presentation.createStudy.model.CreateStudyUiState.Success +import com.created.team201.presentation.createStudy.model.FragmentState import com.created.team201.presentation.createStudy.model.FragmentState.FirstFragment import com.created.team201.presentation.createStudy.model.FragmentState.SecondFragment import com.created.team201.presentation.createStudy.model.FragmentType @@ -36,8 +41,9 @@ class CreateStudyActivity : super.onCreate(savedInstanceState) initActionBar() - collectCreateStudyState() + showFragment(createStudyViewModel.fragmentState.value.type) collectCreateStudyUiState() + collectCreateStudyEvent() } override fun dispatchTouchEvent(ev: MotionEvent): Boolean { @@ -47,6 +53,11 @@ class CreateStudyActivity : return super.dispatchTouchEvent(ev) } + override fun onOptionsItemSelected(item: MenuItem): Boolean { + createStudyViewModel.navigateToBefore() + return true + } + private fun initActionBar() { setSupportActionBar(binding.tbCreateStudy) supportActionBar?.setHomeActionContentDescription(R.string.toolbar_back_text) @@ -54,24 +65,35 @@ class CreateStudyActivity : supportActionBar?.setHomeAsUpIndicator(R.drawable.ic_back) } - override fun onOptionsItemSelected(item: MenuItem): Boolean { - return when (createStudyViewModel.fragmentState.value) { - is FirstFragment -> { - finish() - true - } + private fun setProgressIndicator(type: FragmentType) { + binding.lpiCreateStudyProgress.progress = when (type) { + FIRST -> PROGRESS_FIRST + SECOND -> PROGRESS_SECOND + } + } - is SecondFragment -> { - createStudyViewModel.navigateToBefore() - true + private fun collectCreateStudyEvent() { + createStudyViewModel.createStudyEvent.collectOnStarted(this) { event -> + when (event) { + CreateStudySuccess -> showToast(R.string.create_study_toast_create_study_success) + CreateStudyFailure -> showToast(R.string.create_study_toast_create_study_fail) + is NavigateToBefore -> navigateToBefore(event.fragmentState) + is NavigateToNext -> navigateToNext(event.fragmentState) } } } - private fun setProgressIndicator(type: FragmentType) { - binding.lpiCreateStudyProgress.progress = when (type) { - FIRST -> PROGRESS_FIRST - SECOND -> PROGRESS_SECOND + private fun navigateToBefore(fragmentState: FragmentState) { + when (fragmentState) { + FirstFragment -> finish() + SecondFragment -> showFragment(FirstFragment.type) + } + } + + private fun navigateToNext(fragmentState: FragmentState) { + when (fragmentState) { + FirstFragment -> showFragment(SecondFragment.type) + SecondFragment -> Unit } } @@ -80,7 +102,6 @@ class CreateStudyActivity : .collectLatestOnStarted(this) { createStudyUiState -> when (createStudyUiState) { is Success -> { - showToast(R.string.create_study_toast_create_study_success) startActivity( StudyDetailActivity.getIntent( this@CreateStudyActivity, @@ -92,7 +113,6 @@ class CreateStudyActivity : } is Fail -> { - showToast(R.string.create_study_toast_create_study_fail) finish() } @@ -105,12 +125,6 @@ class CreateStudyActivity : Toast.makeText(this, getString(messageRes), Toast.LENGTH_SHORT).show() } - private fun collectCreateStudyState() { - createStudyViewModel.fragmentState.collectOnStarted(this) { fragmentState -> - showFragment(fragmentState.type) - } - } - private fun showFragment(type: FragmentType) { setProgressIndicator(type) diff --git a/android/app/src/main/java/com/created/team201/presentation/createStudy/CreateStudyViewModel.kt b/android/app/src/main/java/com/created/team201/presentation/createStudy/CreateStudyViewModel.kt index 75e5d508..171499fd 100644 --- a/android/app/src/main/java/com/created/team201/presentation/createStudy/CreateStudyViewModel.kt +++ b/android/app/src/main/java/com/created/team201/presentation/createStudy/CreateStudyViewModel.kt @@ -58,6 +58,9 @@ class CreateStudyViewModel @Inject constructor( private val _createStudyUiState: MutableSharedFlow = MutableSharedFlow() val createStudyUiState: SharedFlow get() = _createStudyUiState.asSharedFlow() + private val _createStudyEvent: MutableSharedFlow = MutableSharedFlow() + val createStudyEvent: SharedFlow get() = _createStudyEvent.asSharedFlow() + private var isOpenStudy: Boolean = false fun setPeopleCount(peopleCount: Int) { @@ -81,22 +84,22 @@ class CreateStudyViewModel @Inject constructor( } fun navigateToNext() { - when (_fragmentState.value) { - is FirstFragment -> { - _fragmentState.value = SecondFragment - } + viewModelScope.launch { + when (_fragmentState.value) { + is FirstFragment -> { + _createStudyEvent.emit(Event.NavigateToNext(fragmentState.value)) + _fragmentState.value = SecondFragment + } - else -> Unit + else -> Unit + } } } fun navigateToBefore() { - when (_fragmentState.value) { - is SecondFragment -> { - _fragmentState.value = FirstFragment - } - - else -> Unit + viewModelScope.launch { + _createStudyEvent.emit(Event.NavigateToBefore(fragmentState.value)) + _fragmentState.value = FirstFragment } } @@ -113,15 +116,24 @@ class CreateStudyViewModel @Inject constructor( ) createStudyRepository.createStudy(study) .onSuccess { studyId -> + _createStudyEvent.emit(Event.CreateStudySuccess) _createStudyUiState.emit(CreateStudyUiState.Success(studyId)) } .onFailure { + _createStudyEvent.emit(Event.CreateStudyFailure) _createStudyUiState.emit(CreateStudyUiState.Fail) } } } - private fun String.isNotBlankAndEmpty(): Boolean = isNotBlank().and(isNotEmpty()) + private fun String.isNotBlankAndEmpty(): Boolean = isNotBlank() and isNotEmpty() + + sealed interface Event { + object CreateStudySuccess : Event + object CreateStudyFailure : Event + data class NavigateToBefore(val fragmentState: FragmentState) : Event + data class NavigateToNext(val fragmentState: FragmentState) : Event + } companion object { private const val DEFAULT_INT_VALUE = -1 From 5964bead5a7e6355e4b1616b518c4c15102a98ba Mon Sep 17 00:00:00 2001 From: inseonyun Date: Tue, 21 Nov 2023 16:54:13 +0900 Subject: [PATCH 15/21] =?UTF-8?q?refactor:=20CreateStudyState=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../createStudy/CreateStudyActivity.kt | 26 ++++++++----------- .../createStudy/CreateStudyViewModel.kt | 22 +++++++++------- .../createStudy/model/CreateStudyUiState.kt | 9 ------- 3 files changed, 24 insertions(+), 33 deletions(-) delete mode 100644 android/app/src/main/java/com/created/team201/presentation/createStudy/model/CreateStudyUiState.kt diff --git a/android/app/src/main/java/com/created/team201/presentation/createStudy/CreateStudyActivity.kt b/android/app/src/main/java/com/created/team201/presentation/createStudy/CreateStudyActivity.kt index 4dfb61b3..ced6ff59 100644 --- a/android/app/src/main/java/com/created/team201/presentation/createStudy/CreateStudyActivity.kt +++ b/android/app/src/main/java/com/created/team201/presentation/createStudy/CreateStudyActivity.kt @@ -14,13 +14,13 @@ import androidx.fragment.app.commit import com.created.team201.R import com.created.team201.databinding.ActivityCreateStudyBinding import com.created.team201.presentation.common.BindingViewActivity +import com.created.team201.presentation.createStudy.CreateStudyViewModel.CreateStudyState.Failure +import com.created.team201.presentation.createStudy.CreateStudyViewModel.CreateStudyState.Loading +import com.created.team201.presentation.createStudy.CreateStudyViewModel.CreateStudyState.Success import com.created.team201.presentation.createStudy.CreateStudyViewModel.Event.CreateStudyFailure import com.created.team201.presentation.createStudy.CreateStudyViewModel.Event.CreateStudySuccess import com.created.team201.presentation.createStudy.CreateStudyViewModel.Event.NavigateToBefore import com.created.team201.presentation.createStudy.CreateStudyViewModel.Event.NavigateToNext -import com.created.team201.presentation.createStudy.model.CreateStudyUiState.Fail -import com.created.team201.presentation.createStudy.model.CreateStudyUiState.Idle -import com.created.team201.presentation.createStudy.model.CreateStudyUiState.Success import com.created.team201.presentation.createStudy.model.FragmentState import com.created.team201.presentation.createStudy.model.FragmentState.FirstFragment import com.created.team201.presentation.createStudy.model.FragmentState.SecondFragment @@ -42,7 +42,7 @@ class CreateStudyActivity : initActionBar() showFragment(createStudyViewModel.fragmentState.value.type) - collectCreateStudyUiState() + collectCreateStudyState() collectCreateStudyEvent() } @@ -97,26 +97,22 @@ class CreateStudyActivity : } } - private fun collectCreateStudyUiState() { - createStudyViewModel.createStudyUiState - .collectLatestOnStarted(this) { createStudyUiState -> - when (createStudyUiState) { + private fun collectCreateStudyState() { + createStudyViewModel.createStudyState + .collectLatestOnStarted(this) { createStudyState -> + when (createStudyState) { is Success -> { startActivity( StudyDetailActivity.getIntent( this@CreateStudyActivity, - createStudyUiState.studyId + createStudyState.studyId ), ) - - finish() - } - - is Fail -> { finish() } - is Idle -> throw IllegalArgumentException() + Loading -> Unit + Failure -> finish() } } } diff --git a/android/app/src/main/java/com/created/team201/presentation/createStudy/CreateStudyViewModel.kt b/android/app/src/main/java/com/created/team201/presentation/createStudy/CreateStudyViewModel.kt index 171499fd..93069098 100644 --- a/android/app/src/main/java/com/created/team201/presentation/createStudy/CreateStudyViewModel.kt +++ b/android/app/src/main/java/com/created/team201/presentation/createStudy/CreateStudyViewModel.kt @@ -4,7 +4,6 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.created.domain.model.CreateStudy import com.created.team201.data.repository.CreateStudyRepository -import com.created.team201.presentation.createStudy.model.CreateStudyUiState import com.created.team201.presentation.createStudy.model.FragmentState import com.created.team201.presentation.createStudy.model.FragmentState.FirstFragment import com.created.team201.presentation.createStudy.model.FragmentState.SecondFragment @@ -55,14 +54,13 @@ class CreateStudyViewModel @Inject constructor( return@combine studyName.isNotBlankAndEmpty() && studyIntroduction.isNotBlankAndEmpty() }.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), false) - private val _createStudyUiState: MutableSharedFlow = MutableSharedFlow() - val createStudyUiState: SharedFlow get() = _createStudyUiState.asSharedFlow() + private val _createStudyState: MutableStateFlow = + MutableStateFlow(CreateStudyState.Loading) + val createStudyState: StateFlow get() = _createStudyState.asStateFlow() private val _createStudyEvent: MutableSharedFlow = MutableSharedFlow() val createStudyEvent: SharedFlow get() = _createStudyEvent.asSharedFlow() - private var isOpenStudy: Boolean = false - fun setPeopleCount(peopleCount: Int) { _peopleCount.value = peopleCount } @@ -104,8 +102,6 @@ class CreateStudyViewModel @Inject constructor( } fun createStudy() { - if (isOpenStudy) return - isOpenStudy = true viewModelScope.launch { val study = CreateStudy( name = studyName.value.trim(), @@ -117,11 +113,11 @@ class CreateStudyViewModel @Inject constructor( createStudyRepository.createStudy(study) .onSuccess { studyId -> _createStudyEvent.emit(Event.CreateStudySuccess) - _createStudyUiState.emit(CreateStudyUiState.Success(studyId)) + _createStudyState.emit(CreateStudyState.Success(studyId)) } .onFailure { _createStudyEvent.emit(Event.CreateStudyFailure) - _createStudyUiState.emit(CreateStudyUiState.Fail) + _createStudyState.emit(CreateStudyState.Failure) } } } @@ -135,6 +131,14 @@ class CreateStudyViewModel @Inject constructor( data class NavigateToNext(val fragmentState: FragmentState) : Event } + sealed interface CreateStudyState { + class Success(val studyId: Long) : CreateStudyState + + object Loading : CreateStudyState + + object Failure : CreateStudyState + } + companion object { private const val DEFAULT_INT_VALUE = -1 private const val DEFAULT_STRING_VALUE = "" diff --git a/android/app/src/main/java/com/created/team201/presentation/createStudy/model/CreateStudyUiState.kt b/android/app/src/main/java/com/created/team201/presentation/createStudy/model/CreateStudyUiState.kt deleted file mode 100644 index 473fb61c..00000000 --- a/android/app/src/main/java/com/created/team201/presentation/createStudy/model/CreateStudyUiState.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.created.team201.presentation.createStudy.model - -sealed interface CreateStudyUiState { - class Success(val studyId: Long) : CreateStudyUiState - - object Fail : CreateStudyUiState - - object Idle : CreateStudyUiState -} From e6e10bfa92a73a4ffa862d9adbacae3ed05a2798 Mon Sep 17 00:00:00 2001 From: inseonyun Date: Tue, 21 Nov 2023 16:57:01 +0900 Subject: [PATCH 16/21] =?UTF-8?q?refactor:=20=ED=95=A8=EC=88=98=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../createStudy/CreateStudyActivity.kt | 49 ++++++++++--------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/android/app/src/main/java/com/created/team201/presentation/createStudy/CreateStudyActivity.kt b/android/app/src/main/java/com/created/team201/presentation/createStudy/CreateStudyActivity.kt index ced6ff59..51cdc8ed 100644 --- a/android/app/src/main/java/com/created/team201/presentation/createStudy/CreateStudyActivity.kt +++ b/android/app/src/main/java/com/created/team201/presentation/createStudy/CreateStudyActivity.kt @@ -72,6 +72,27 @@ class CreateStudyActivity : } } + private fun collectCreateStudyState() { + createStudyViewModel.createStudyState + .collectLatestOnStarted(this) { createStudyState -> + when (createStudyState) { + is Success -> navigateToStudyDetail(createStudyState.studyId) + Loading -> Unit + Failure -> finish() + } + } + } + + private fun navigateToStudyDetail(studyId: Long) { + startActivity( + StudyDetailActivity.getIntent( + this@CreateStudyActivity, + studyId + ), + ) + finish() + } + private fun collectCreateStudyEvent() { createStudyViewModel.createStudyEvent.collectOnStarted(this) { event -> when (event) { @@ -83,6 +104,10 @@ class CreateStudyActivity : } } + private fun showToast(@StringRes messageRes: Int) { + Toast.makeText(this, getString(messageRes), Toast.LENGTH_SHORT).show() + } + private fun navigateToBefore(fragmentState: FragmentState) { when (fragmentState) { FirstFragment -> finish() @@ -97,30 +122,6 @@ class CreateStudyActivity : } } - private fun collectCreateStudyState() { - createStudyViewModel.createStudyState - .collectLatestOnStarted(this) { createStudyState -> - when (createStudyState) { - is Success -> { - startActivity( - StudyDetailActivity.getIntent( - this@CreateStudyActivity, - createStudyState.studyId - ), - ) - finish() - } - - Loading -> Unit - Failure -> finish() - } - } - } - - private fun showToast(@StringRes messageRes: Int) { - Toast.makeText(this, getString(messageRes), Toast.LENGTH_SHORT).show() - } - private fun showFragment(type: FragmentType) { setProgressIndicator(type) From 345c394581b0e610d10c82bc326c70963d515e76 Mon Sep 17 00:00:00 2001 From: inseonyun Date: Tue, 21 Nov 2023 17:24:34 +0900 Subject: [PATCH 17/21] =?UTF-8?q?refactor:=20CreateStudy=20State=20Idle=20?= =?UTF-8?q?=EC=83=81=ED=83=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/createStudy/CreateStudyActivity.kt | 2 ++ .../presentation/createStudy/CreateStudyViewModel.kt | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/android/app/src/main/java/com/created/team201/presentation/createStudy/CreateStudyActivity.kt b/android/app/src/main/java/com/created/team201/presentation/createStudy/CreateStudyActivity.kt index 51cdc8ed..bc97359a 100644 --- a/android/app/src/main/java/com/created/team201/presentation/createStudy/CreateStudyActivity.kt +++ b/android/app/src/main/java/com/created/team201/presentation/createStudy/CreateStudyActivity.kt @@ -15,6 +15,7 @@ import com.created.team201.R import com.created.team201.databinding.ActivityCreateStudyBinding import com.created.team201.presentation.common.BindingViewActivity import com.created.team201.presentation.createStudy.CreateStudyViewModel.CreateStudyState.Failure +import com.created.team201.presentation.createStudy.CreateStudyViewModel.CreateStudyState.Idle import com.created.team201.presentation.createStudy.CreateStudyViewModel.CreateStudyState.Loading import com.created.team201.presentation.createStudy.CreateStudyViewModel.CreateStudyState.Success import com.created.team201.presentation.createStudy.CreateStudyViewModel.Event.CreateStudyFailure @@ -78,6 +79,7 @@ class CreateStudyActivity : when (createStudyState) { is Success -> navigateToStudyDetail(createStudyState.studyId) Loading -> Unit + Idle -> Unit Failure -> finish() } } diff --git a/android/app/src/main/java/com/created/team201/presentation/createStudy/CreateStudyViewModel.kt b/android/app/src/main/java/com/created/team201/presentation/createStudy/CreateStudyViewModel.kt index 93069098..7af0e21a 100644 --- a/android/app/src/main/java/com/created/team201/presentation/createStudy/CreateStudyViewModel.kt +++ b/android/app/src/main/java/com/created/team201/presentation/createStudy/CreateStudyViewModel.kt @@ -55,7 +55,7 @@ class CreateStudyViewModel @Inject constructor( }.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), false) private val _createStudyState: MutableStateFlow = - MutableStateFlow(CreateStudyState.Loading) + MutableStateFlow(CreateStudyState.Idle) val createStudyState: StateFlow get() = _createStudyState.asStateFlow() private val _createStudyEvent: MutableSharedFlow = MutableSharedFlow() @@ -102,6 +102,9 @@ class CreateStudyViewModel @Inject constructor( } fun createStudy() { + if (createStudyState.value == CreateStudyState.Loading) + return + _createStudyState.value = CreateStudyState.Loading viewModelScope.launch { val study = CreateStudy( name = studyName.value.trim(), @@ -137,6 +140,8 @@ class CreateStudyViewModel @Inject constructor( object Loading : CreateStudyState object Failure : CreateStudyState + + object Idle : CreateStudyState } companion object { From 771d091b59a982bf3431c2a173c8c618bef8f365 Mon Sep 17 00:00:00 2001 From: inseonyun Date: Tue, 21 Nov 2023 17:54:17 +0900 Subject: [PATCH 18/21] =?UTF-8?q?refactor:=20ScrollView=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../layout/fragment_first_create_study.xml | 288 +++++++++--------- .../layout/fragment_second_create_study.xml | 207 +++++++------ 2 files changed, 258 insertions(+), 237 deletions(-) diff --git a/android/app/src/main/res/layout/fragment_first_create_study.xml b/android/app/src/main/res/layout/fragment_first_create_study.xml index 821c6fdc..9466ab0d 100644 --- a/android/app/src/main/res/layout/fragment_first_create_study.xml +++ b/android/app/src/main/res/layout/fragment_first_create_study.xml @@ -1,155 +1,165 @@ - + android:fillViewport="true"> - + android:padding="20dp"> - + - + - + - + - + - + - + - + - + + + + + - + diff --git a/android/app/src/main/res/layout/fragment_second_create_study.xml b/android/app/src/main/res/layout/fragment_second_create_study.xml index 4db5acba..7fd2dfc7 100644 --- a/android/app/src/main/res/layout/fragment_second_create_study.xml +++ b/android/app/src/main/res/layout/fragment_second_create_study.xml @@ -1,112 +1,123 @@ - + android:fillViewport="true"> - - + android:padding="20dp"> + - + - - + - + - + + + + + + + - + From eb5c46517d38a38bce0aba46c9e8834059c86dce Mon Sep 17 00:00:00 2001 From: inseonyun Date: Thu, 23 Nov 2023 10:48:09 +0900 Subject: [PATCH 19/21] refactor: StateFlow Emit -> setValue --- .../team201/presentation/createStudy/CreateStudyViewModel.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/android/app/src/main/java/com/created/team201/presentation/createStudy/CreateStudyViewModel.kt b/android/app/src/main/java/com/created/team201/presentation/createStudy/CreateStudyViewModel.kt index 7af0e21a..5e27b966 100644 --- a/android/app/src/main/java/com/created/team201/presentation/createStudy/CreateStudyViewModel.kt +++ b/android/app/src/main/java/com/created/team201/presentation/createStudy/CreateStudyViewModel.kt @@ -116,11 +116,11 @@ class CreateStudyViewModel @Inject constructor( createStudyRepository.createStudy(study) .onSuccess { studyId -> _createStudyEvent.emit(Event.CreateStudySuccess) - _createStudyState.emit(CreateStudyState.Success(studyId)) + _createStudyState.value = CreateStudyState.Success(studyId) } .onFailure { _createStudyEvent.emit(Event.CreateStudyFailure) - _createStudyState.emit(CreateStudyState.Failure) + _createStudyState.value = CreateStudyState.Failure } } } From 773d28cdc63964f52a78e64a156b56ab53de41d3 Mon Sep 17 00:00:00 2001 From: inseonyun Date: Thu, 23 Nov 2023 10:54:57 +0900 Subject: [PATCH 20/21] =?UTF-8?q?refactor:=20combine=20=EB=B6=88=ED=95=84?= =?UTF-8?q?=EC=9A=94=ED=95=9C=20return=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../team201/presentation/createStudy/CreateStudyViewModel.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/android/app/src/main/java/com/created/team201/presentation/createStudy/CreateStudyViewModel.kt b/android/app/src/main/java/com/created/team201/presentation/createStudy/CreateStudyViewModel.kt index 5e27b966..27e151c0 100644 --- a/android/app/src/main/java/com/created/team201/presentation/createStudy/CreateStudyViewModel.kt +++ b/android/app/src/main/java/com/created/team201/presentation/createStudy/CreateStudyViewModel.kt @@ -46,12 +46,12 @@ class CreateStudyViewModel @Inject constructor( val isEnableFirstCreateStudyNext: StateFlow = combine(peopleCount, studyDate, cycle) { peopleCount, studyDate, cycle -> - return@combine peopleCount != DEFAULT_INT_VALUE && studyDate != DEFAULT_INT_VALUE && cycle != DEFAULT_INT_VALUE + peopleCount != DEFAULT_INT_VALUE && studyDate != DEFAULT_INT_VALUE && cycle != DEFAULT_INT_VALUE }.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), false) val isEnableSecondCreateStudyNext: StateFlow = combine(studyName, studyIntroduction) { studyName, studyIntroduction -> - return@combine studyName.isNotBlankAndEmpty() && studyIntroduction.isNotBlankAndEmpty() + studyName.isNotBlankAndEmpty() && studyIntroduction.isNotBlankAndEmpty() }.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), false) private val _createStudyState: MutableStateFlow = From 77cc089f195b94e88cf61b9633b28d47ea925f41 Mon Sep 17 00:00:00 2001 From: inseonyun Date: Thu, 23 Nov 2023 10:56:28 +0900 Subject: [PATCH 21/21] =?UTF-8?q?refactor:=20=EB=A7=A4=EC=A7=81=EB=84=98?= =?UTF-8?q?=EB=B2=84=20=EC=83=81=EC=88=98=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/createStudy/CreateStudyViewModel.kt | 2 +- .../presentation/createStudy/FirstCreateStudyFragment.kt | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/android/app/src/main/java/com/created/team201/presentation/createStudy/CreateStudyViewModel.kt b/android/app/src/main/java/com/created/team201/presentation/createStudy/CreateStudyViewModel.kt index 27e151c0..aaf15b36 100644 --- a/android/app/src/main/java/com/created/team201/presentation/createStudy/CreateStudyViewModel.kt +++ b/android/app/src/main/java/com/created/team201/presentation/createStudy/CreateStudyViewModel.kt @@ -145,7 +145,7 @@ class CreateStudyViewModel @Inject constructor( } companion object { - private const val DEFAULT_INT_VALUE = -1 + const val DEFAULT_INT_VALUE = -1 private const val DEFAULT_STRING_VALUE = "" } } diff --git a/android/app/src/main/java/com/created/team201/presentation/createStudy/FirstCreateStudyFragment.kt b/android/app/src/main/java/com/created/team201/presentation/createStudy/FirstCreateStudyFragment.kt index a28ad73c..60aa3595 100644 --- a/android/app/src/main/java/com/created/team201/presentation/createStudy/FirstCreateStudyFragment.kt +++ b/android/app/src/main/java/com/created/team201/presentation/createStudy/FirstCreateStudyFragment.kt @@ -7,6 +7,7 @@ import androidx.fragment.app.commit import com.created.team201.R import com.created.team201.databinding.FragmentFirstCreateStudyBinding import com.created.team201.presentation.common.BindingViewFragment +import com.created.team201.presentation.createStudy.CreateStudyViewModel.Companion.DEFAULT_INT_VALUE import com.created.team201.presentation.createStudy.bottomSheet.CycleBottomSheetFragment import com.created.team201.presentation.createStudy.bottomSheet.PeopleCountBottomSheetFragment import com.created.team201.presentation.createStudy.bottomSheet.StudyDateBottomSheetFragment @@ -31,7 +32,7 @@ class FirstCreateStudyFragment : private fun setupPeopleCount() { createStudyViewModel.peopleCount.collectOnStarted(viewLifecycleOwner) { peopleCount -> - if (peopleCount == -1) return@collectOnStarted + if (peopleCount == DEFAULT_INT_VALUE) return@collectOnStarted binding.tvFirstCreateStudyPeopleCount.text = getString( @@ -47,7 +48,7 @@ class FirstCreateStudyFragment : private fun setupStudyDate() { createStudyViewModel.studyDate.collectOnStarted(viewLifecycleOwner) { studyDate -> - if (studyDate == -1) return@collectOnStarted + if (studyDate == DEFAULT_INT_VALUE) return@collectOnStarted binding.tvFirstCreateStudyStudyDate.text = getString(R.string.first_create_study_formatter_information_study_date, studyDate) @@ -60,7 +61,7 @@ class FirstCreateStudyFragment : private fun setupStudyCycle() { createStudyViewModel.cycle.collectOnStarted(viewLifecycleOwner) { cycle -> - if (cycle == -1) return@collectOnStarted + if (cycle == DEFAULT_INT_VALUE) return@collectOnStarted binding.tvFirstCreateStudyCycle.text = getString(R.string.first_create_study_formatter_information_cycle, cycle)