diff --git a/app/src/main/java/org/sopt/pingle/presentation/ui/main/plan/PlanViewModel.kt b/app/src/main/java/org/sopt/pingle/presentation/ui/main/plan/PlanViewModel.kt index de7860ba..d471a7c4 100644 --- a/app/src/main/java/org/sopt/pingle/presentation/ui/main/plan/PlanViewModel.kt +++ b/app/src/main/java/org/sopt/pingle/presentation/ui/main/plan/PlanViewModel.kt @@ -16,7 +16,9 @@ import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch import org.sopt.pingle.domain.model.PlanLocationEntity import org.sopt.pingle.domain.model.PlanMeetingEntity +import org.sopt.pingle.domain.model.UserInfoEntity import org.sopt.pingle.domain.usecase.GetPlanLocationListUseCase +import org.sopt.pingle.domain.usecase.GetUserInfoUseCase import org.sopt.pingle.domain.usecase.PostPlanMeetingUseCase import org.sopt.pingle.presentation.type.CategoryType import org.sopt.pingle.presentation.type.PlanType @@ -26,7 +28,8 @@ import org.sopt.pingle.util.view.UiState @HiltViewModel class PlanViewModel @Inject constructor( private val getPlanLocationListUseCase: GetPlanLocationListUseCase, - private val postPlanMeetingUseCase: PostPlanMeetingUseCase + private val postPlanMeetingUseCase: PostPlanMeetingUseCase, + private val getUserInfoUseCase: GetUserInfoUseCase ) : ViewModel() { private val _currentPage = MutableStateFlow(FIRST_PAGE_POSITION) val currentPage get() = _currentPage.asStateFlow() @@ -61,6 +64,9 @@ class PlanViewModel @Inject constructor( private val _planMeetingState = MutableSharedFlow>() val planMeetingState get() = _planMeetingState.asSharedFlow() + private val _userInfoState = MutableStateFlow>(UiState.Empty) + val userInfoState get() = _userInfoState.asStateFlow() + val isPlanBtnEnabled: StateFlow = listOf( currentPage, selectedCategory, @@ -220,6 +226,19 @@ class PlanViewModel @Inject constructor( } } + fun getUserInfo() { + viewModelScope.launch { + _userInfoState.value = UiState.Loading + runCatching { + getUserInfoUseCase().collect() { userInfo -> + _userInfoState.value = UiState.Success(userInfo) + } + }.onFailure { exception: Throwable -> + _userInfoState.value = UiState.Error(exception.message) + } + } + } + companion object { const val FIRST_PAGE_POSITION = 0 const val DEFAULT_OLD_POSITION = -1 diff --git a/app/src/main/java/org/sopt/pingle/presentation/ui/main/plan/planlocation/PlanLocationFragment.kt b/app/src/main/java/org/sopt/pingle/presentation/ui/main/plan/planlocation/PlanLocationFragment.kt index ab73d563..ae6f4440 100644 --- a/app/src/main/java/org/sopt/pingle/presentation/ui/main/plan/planlocation/PlanLocationFragment.kt +++ b/app/src/main/java/org/sopt/pingle/presentation/ui/main/plan/planlocation/PlanLocationFragment.kt @@ -78,7 +78,7 @@ class PlanLocationFragment : } override fun onDestroyView() { - super.onDestroyView() binding.rvPlanLocationList.adapter = null + super.onDestroyView() } } diff --git a/app/src/main/java/org/sopt/pingle/presentation/ui/main/plan/plansummaryconfirmation/PlanSummaryConfirmationFragment.kt b/app/src/main/java/org/sopt/pingle/presentation/ui/main/plan/plansummaryconfirmation/PlanSummaryConfirmationFragment.kt index af638e26..1a184734 100644 --- a/app/src/main/java/org/sopt/pingle/presentation/ui/main/plan/plansummaryconfirmation/PlanSummaryConfirmationFragment.kt +++ b/app/src/main/java/org/sopt/pingle/presentation/ui/main/plan/plansummaryconfirmation/PlanSummaryConfirmationFragment.kt @@ -3,12 +3,17 @@ package org.sopt.pingle.presentation.ui.main.plan.plansummaryconfirmation import android.os.Bundle import android.view.View import androidx.fragment.app.activityViewModels +import androidx.lifecycle.flowWithLifecycle +import androidx.lifecycle.lifecycleScope import dagger.hilt.android.AndroidEntryPoint +import kotlinx.coroutines.flow.launchIn +import kotlinx.coroutines.flow.onEach import org.sopt.pingle.R import org.sopt.pingle.databinding.FragmentPlanSummaryConfirmationBinding import org.sopt.pingle.presentation.ui.main.plan.PlanViewModel import org.sopt.pingle.util.base.BindingFragment import org.sopt.pingle.util.fragment.colorOf +import org.sopt.pingle.util.view.UiState @AndroidEntryPoint class PlanSummaryConfirmationFragment : @@ -18,30 +23,45 @@ class PlanSummaryConfirmationFragment : super.onViewCreated(view, savedInstanceState) initLayout() + collectData() } private fun initLayout() { - viewModel.selectedCategory.value?.let { category -> - with(binding) { + viewModel.getUserInfo() + + with(binding) { + viewModel.selectedCategory.value?.let { category -> badgePlanSummaryConfirmationCategory.setBadgeCategoryType(category) tvPlanSummaryConfirmationName.setTextColor(colorOf((category.textColor))) - tvPlanSummaryConfirmationName.text = viewModel.planTitle.value - // TODO API연결해서 개최자명 넣기 - tvPlanSummaryConfirmationOwnerName.text = "개최자" - tvPlanSummaryConfirmationCalenderDetail.text = - convertDateFormat(viewModel.planDate.value) + "\n" + convertTimeFormat(viewModel.startTime.value) + " ~ " + convertTimeFormat( - viewModel.endTime.value - ) - tvPlanSummaryConfirmationMapDetail.text = viewModel.selectedLocation.value?.location - tvPlanSummaryConfirmationRecruitmentDetail.text = getString( - R.string.plan_summary_confirmation_recruitment_number, - viewModel.selectedRecruitment.value - ) } + tvPlanSummaryConfirmationName.text = viewModel.planTitle.value + tvPlanSummaryConfirmationCalenderDetail.text = + convertDateFormat(viewModel.planDate.value) + "\n" + convertTimeFormat(viewModel.startTime.value) + " ~ " + convertTimeFormat( + viewModel.endTime.value + ) + tvPlanSummaryConfirmationMapDetail.text = viewModel.selectedLocation.value?.location + tvPlanSummaryConfirmationRecruitmentDetail.text = getString( + R.string.plan_summary_confirmation_recruitment_number, + viewModel.selectedRecruitment.value + ) } } - private fun convertTimeFormat(time: String): String = time.substring(TIME_START_INDEX, TIME_END_INDEX) + private fun collectData() { + viewModel.userInfoState.flowWithLifecycle(lifecycle).onEach { userInfoState -> + when (userInfoState) { + is UiState.Success -> + binding.tvPlanSummaryConfirmationOwnerName.text = + userInfoState.data.name + + else -> Unit + } + }.launchIn(lifecycleScope) + } + + private fun convertTimeFormat(time: String): String = + time.substring(TIME_START_INDEX, TIME_END_INDEX) + private fun convertDateFormat(date: String): String { val year = date.substring(YEAR_START_INDEX, YEAR_END_INDEX) val month = date.substring(MONTH_START_INDEX, MONTH_END_INDEX)