From 0ae56f14c0478c366d07acf6cf1448a1e53e2f6f Mon Sep 17 00:00:00 2001 From: jihyunniiii Date: Fri, 12 Jan 2024 21:29:55 +0900 Subject: [PATCH 1/3] =?UTF-8?q?[feat]=20#115=20=EA=B0=9C=EC=B5=9C=20?= =?UTF-8?q?=ED=94=84=EB=A1=9C=EC=84=B8=EC=8A=A4=20=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=20=EB=B6=88=EB=9F=AC=EC=98=A4=EA=B8=B0=20API?= =?UTF-8?q?=20=EC=97=B0=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/main/plan/PlanViewModel.kt | 21 ++++++++- .../PlanSummaryConfirmationFragment.kt | 47 +++++++++++++------ 2 files changed, 53 insertions(+), 15 deletions(-) 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..5d205ef3 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/plansummaryconfirmation/PlanSummaryConfirmationFragment.kt b/app/src/main/java/org/sopt/pingle/presentation/ui/main/plan/plansummaryconfirmation/PlanSummaryConfirmationFragment.kt index af638e26..a535d066 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,44 @@ 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( + } + 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 - ) - } + 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) From 32e22f98e06512c0d9a2a45a25d381f8c42c69a2 Mon Sep 17 00:00:00 2001 From: jihyunniiii Date: Fri, 12 Jan 2024 21:36:27 +0900 Subject: [PATCH 2/3] [chore] #115 ktlintFormat --- .../pingle/presentation/ui/main/plan/PlanViewModel.kt | 2 +- .../PlanSummaryConfirmationFragment.kt | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) 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 5d205ef3..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 @@ -228,7 +228,7 @@ class PlanViewModel @Inject constructor( fun getUserInfo() { viewModelScope.launch { - _userInfoState.value =UiState.Loading + _userInfoState.value = UiState.Loading runCatching { getUserInfoUseCase().collect() { userInfo -> _userInfoState.value = UiState.Success(userInfo) 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 a535d066..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 @@ -37,8 +37,8 @@ class PlanSummaryConfirmationFragment : tvPlanSummaryConfirmationName.text = viewModel.planTitle.value tvPlanSummaryConfirmationCalenderDetail.text = convertDateFormat(viewModel.planDate.value) + "\n" + convertTimeFormat(viewModel.startTime.value) + " ~ " + convertTimeFormat( - viewModel.endTime.value - ) + viewModel.endTime.value + ) tvPlanSummaryConfirmationMapDetail.text = viewModel.selectedLocation.value?.location tvPlanSummaryConfirmationRecruitmentDetail.text = getString( R.string.plan_summary_confirmation_recruitment_number, @@ -50,8 +50,9 @@ class PlanSummaryConfirmationFragment : private fun collectData() { viewModel.userInfoState.flowWithLifecycle(lifecycle).onEach { userInfoState -> when (userInfoState) { - is UiState.Success -> binding.tvPlanSummaryConfirmationOwnerName.text = - userInfoState.data.name + is UiState.Success -> + binding.tvPlanSummaryConfirmationOwnerName.text = + userInfoState.data.name else -> Unit } From b0885ce887076bab20bedb0e5ce9eacc0c9a5f94 Mon Sep 17 00:00:00 2001 From: jihyunniiii Date: Fri, 12 Jan 2024 21:52:17 +0900 Subject: [PATCH 3/3] =?UTF-8?q?[chore]=20#115=20onDestroyView=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 --- .../ui/main/plan/planlocation/PlanLocationFragment.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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() } }