diff --git a/app/src/main/java/com/ftw/hometerview/di/ui/CreateReviewFragmentViewModelModule.kt b/app/src/main/java/com/ftw/hometerview/di/ui/CreateReviewFragmentViewModelModule.kt index 8875b89..77eba56 100644 --- a/app/src/main/java/com/ftw/hometerview/di/ui/CreateReviewFragmentViewModelModule.kt +++ b/app/src/main/java/com/ftw/hometerview/di/ui/CreateReviewFragmentViewModelModule.kt @@ -3,6 +3,7 @@ package com.ftw.hometerview.di.ui import com.ftw.domain.usecase.address.GetAddressUseCase import com.ftw.hometerview.dispatcher.Dispatcher import com.ftw.hometerview.ui.review.first.CreateReviewFirstStepViewModel +import com.ftw.hometerview.ui.review.second.CreateReviewSecondStepViewModel import dagger.Module import dagger.Provides import dagger.hilt.InstallIn @@ -24,4 +25,10 @@ class CreateReviewFragmentViewModelModule { getAddressUseCase ) } + + @Provides + @FragmentScoped + fun provideCreateReviewSecondStepViewModel(): CreateReviewSecondStepViewModel { + return CreateReviewSecondStepViewModel() + } } diff --git a/app/src/main/java/com/ftw/hometerview/ui/review/CreateReviewActivity.kt b/app/src/main/java/com/ftw/hometerview/ui/review/CreateReviewActivity.kt index 5cd74ca..349a439 100644 --- a/app/src/main/java/com/ftw/hometerview/ui/review/CreateReviewActivity.kt +++ b/app/src/main/java/com/ftw/hometerview/ui/review/CreateReviewActivity.kt @@ -7,12 +7,14 @@ import androidx.appcompat.app.AppCompatActivity import androidx.databinding.DataBindingUtil import com.ftw.hometerview.R import com.ftw.hometerview.databinding.ActivityCreateReviewBinding +import com.ftw.hometerview.extension.addFragment import com.ftw.hometerview.extension.replaceFragment import com.ftw.hometerview.ui.review.first.CreateReviewFirstStepFragment +import com.ftw.hometerview.ui.review.second.CreateReviewSecondStepFragment import dagger.hilt.android.AndroidEntryPoint @AndroidEntryPoint -class CreateReviewActivity : AppCompatActivity() { +class CreateReviewActivity : AppCompatActivity(), CreateReviewFirstStepFragment.Listener { companion object { fun newIntent(context: Context): Intent = Intent(context, CreateReviewActivity::class.java) } @@ -20,6 +22,10 @@ class CreateReviewActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) DataBindingUtil.setContentView(this, R.layout.activity_create_review) - replaceFragment(R.id.frame_layout, CreateReviewFirstStepFragment.newInstance(), false) + replaceFragment(R.id.fragment_container_view, CreateReviewFirstStepFragment.newInstance(), false) + } + + override fun onClickAddressFromFirstStep(address: String) { + addFragment(R.id.fragment_container_view, CreateReviewSecondStepFragment.newInstance(address), true) } } diff --git a/app/src/main/java/com/ftw/hometerview/ui/review/second/CreateReviewSecondStepFragment.kt b/app/src/main/java/com/ftw/hometerview/ui/review/second/CreateReviewSecondStepFragment.kt new file mode 100644 index 0000000..ec41031 --- /dev/null +++ b/app/src/main/java/com/ftw/hometerview/ui/review/second/CreateReviewSecondStepFragment.kt @@ -0,0 +1,92 @@ +package com.ftw.hometerview.ui.review.second + +import android.os.Bundle +import android.os.Parcelable +import android.util.Log +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.core.os.bundleOf +import androidx.databinding.DataBindingUtil +import androidx.fragment.app.Fragment +import androidx.lifecycle.Lifecycle +import androidx.lifecycle.lifecycleScope +import androidx.lifecycle.repeatOnLifecycle +import com.ftw.hometerview.R +import com.ftw.hometerview.databinding.FragmentCreateReviewSecondStepBinding +import dagger.hilt.android.AndroidEntryPoint +import kotlinx.coroutines.launch +import kotlinx.parcelize.Parcelize +import javax.inject.Inject + +@AndroidEntryPoint +class CreateReviewSecondStepFragment : Fragment() { + companion object { + private const val ARGUMENT_KEY = "CREATE_REVIEW_SECOND_STEP_ARGUMENT_KEY" + fun newInstance(address: String): CreateReviewSecondStepFragment { + return CreateReviewSecondStepFragment().apply { + arguments = bundleOf(ARGUMENT_KEY to Argument(address)) + } + } + } + + private var _binding: FragmentCreateReviewSecondStepBinding? = null + private val binding get() = _binding!! + + @Inject + lateinit var viewModel: CreateReviewSecondStepViewModel + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View { + _binding = DataBindingUtil.inflate( + inflater, + R.layout.fragment_create_review_second_step, + container, + false + ).apply { + this.viewModel = this@CreateReviewSecondStepFragment.viewModel + } + return binding.root + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + arguments?.getParcelable(ARGUMENT_KEY)?.also { argument -> + viewModel.setAddress(argument.address) + } ?: let { + activity?.onBackPressed() + return + } + + observe() + } + + override fun onDestroyView() { + super.onDestroyView() + _binding = null + } + + private fun observe() { + lifecycleScope.launch { + repeatOnLifecycle(Lifecycle.State.STARTED) { + viewModel.event.collect { event -> + when (event) { + CreateReviewSecondStepViewModel.Event.Nothing -> {} + CreateReviewSecondStepViewModel.Event.OnClickResidentialFloor -> showSelectResidentialFloorBottomSheet() + } + } + } + } + } + + private fun showSelectResidentialFloorBottomSheet() { + // TODO 거주층 선택 반팝업 노출 + Log.d("SecondStep", "showSelectResidentialFloorBottomSheet: ") + } + + @Parcelize + data class Argument(val address: String) : Parcelable +} diff --git a/app/src/main/java/com/ftw/hometerview/ui/review/second/CreateReviewSecondStepViewModel.kt b/app/src/main/java/com/ftw/hometerview/ui/review/second/CreateReviewSecondStepViewModel.kt new file mode 100644 index 0000000..a990338 --- /dev/null +++ b/app/src/main/java/com/ftw/hometerview/ui/review/second/CreateReviewSecondStepViewModel.kt @@ -0,0 +1,33 @@ +package com.ftw.hometerview.ui.review.second + +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.asStateFlow + +class CreateReviewSecondStepViewModel { + + sealed class Event { + object Nothing : Event() + object OnClickResidentialFloor : Event() + } + + private val _event: MutableStateFlow = MutableStateFlow(Event.Nothing) + val event: StateFlow = _event.asStateFlow() + + private val _address: MutableStateFlow = MutableStateFlow("") + val address: StateFlow = _address.asStateFlow() + + val residentialFloor: MutableStateFlow = MutableStateFlow("") + + fun setAddress(address: String) { + _address.value = address + } + + fun setResidentialFloor(residentialFloor: String) { + this.residentialFloor.value = residentialFloor + } + + fun onClickResidentialFloor() { + _event.value = Event.OnClickResidentialFloor + } +} diff --git a/app/src/main/res/drawable/icon_next.xml b/app/src/main/res/drawable/icon_next.xml new file mode 100644 index 0000000..939ae69 --- /dev/null +++ b/app/src/main/res/drawable/icon_next.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/layout/activity_create_review.xml b/app/src/main/res/layout/activity_create_review.xml index 5248f9c..f8385e3 100644 --- a/app/src/main/res/layout/activity_create_review.xml +++ b/app/src/main/res/layout/activity_create_review.xml @@ -1,7 +1,7 @@ - diff --git a/app/src/main/res/layout/fragment_create_review_second_step.xml b/app/src/main/res/layout/fragment_create_review_second_step.xml new file mode 100644 index 0000000..71580a2 --- /dev/null +++ b/app/src/main/res/layout/fragment_create_review_second_step.xml @@ -0,0 +1,160 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index eaed82b..a6339bb 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -41,6 +41,7 @@ 예) 분당 주공, 연수동 주공3차 사서함명 + 번호 예) 분당우체국사서함 1~100 + 거주층을 선택해 주세요 저장된 토큰이 없습니다. 나랑 같은 지역으로 출근하는 사람들은 어디에 살고있을까?