diff --git a/app/src/main/java/org/sopt/pingle/presentation/ui/plan/PlanActivity.kt b/app/src/main/java/org/sopt/pingle/presentation/ui/plan/PlanActivity.kt index 3b9ef04f7..b7997a59f 100644 --- a/app/src/main/java/org/sopt/pingle/presentation/ui/plan/PlanActivity.kt +++ b/app/src/main/java/org/sopt/pingle/presentation/ui/plan/PlanActivity.kt @@ -25,8 +25,6 @@ import org.sopt.pingle.presentation.ui.plan.plansummaryconfirmation.PlanSummaryC import org.sopt.pingle.presentation.ui.plan.plantitle.PlanTitleFragment import org.sopt.pingle.util.base.BindingActivity import org.sopt.pingle.util.component.AllModalDialogFragment -import org.sopt.pingle.util.component.PingleSnackbar -import org.sopt.pingle.util.context.stringOf import org.sopt.pingle.util.view.PingleFragmentStateAdapter import org.sopt.pingle.util.view.UiState @@ -85,7 +83,6 @@ class PlanActivity : BindingActivity(R.layout.activity_plan binding.btnPlan.setOnClickListener { when (binding.vpPlan.currentItem) { fragmentList.size - SUB_LIST_SIZE -> planViewModel.postPlanMeeting() - PLAN_OPEN_CHATTING_FRAGMENT_INDEX -> validationOpenChattingLink() else -> binding.vpPlan.currentItem++ } } @@ -163,24 +160,10 @@ class PlanActivity : BindingActivity(R.layout.activity_plan onBackPressedDispatcher.addCallback(this, onBackPressed) } - private fun validationOpenChattingLink() { - if (planViewModel.validityOpenChattingLink()) { - binding.vpPlan.currentItem++ - } else { - PingleSnackbar.makeSnackbar( - binding.root, - stringOf(R.string.plan_open_chatting_snackbar), - SNACKBAR_BOTTOM_MARGIN - ) - } - } - companion object { private const val EXIT_MODAL = "exitModal" const val FIRST_PAGE = 0 const val DEFAULT_PROGRESSBAR = 1f const val SUB_LIST_SIZE = 1 - const val PLAN_OPEN_CHATTING_FRAGMENT_INDEX = 5 - const val SNACKBAR_BOTTOM_MARGIN = 126 } } diff --git a/app/src/main/java/org/sopt/pingle/presentation/ui/plan/PlanViewModel.kt b/app/src/main/java/org/sopt/pingle/presentation/ui/plan/PlanViewModel.kt index ec4a874f8..a9447cef9 100644 --- a/app/src/main/java/org/sopt/pingle/presentation/ui/plan/PlanViewModel.kt +++ b/app/src/main/java/org/sopt/pingle/presentation/ui/plan/PlanViewModel.kt @@ -97,9 +97,8 @@ class PlanViewModel @Inject constructor( (currentPage == PlanType.DATETIME.position && planDate.isNotBlank() && startTime.isNotBlank() && endTime.isNotBlank()) || (currentPage == PlanType.LOCATION.position && selectedLocation != null) || ( - currentPage == PlanType.RECRUITMENT.position && selectedRecruitment.isNotBlank() && checkRecruitment( - selectedRecruitment - ) + currentPage == PlanType.RECRUITMENT.position && selectedRecruitment.isNotBlank() && + checkRecruitment(selectedRecruitment) ) || (currentPage == PlanType.OPENCHATTING.position && planOpenChattingLink.isNotBlank()) || (currentPage == PlanType.SUMMARY.position) @@ -245,7 +244,11 @@ class PlanViewModel @Inject constructor( } } - fun validityOpenChattingLink() = planOpenChattingLink.value.startsWith(OPEN_CHATTING_LINK_VALIDITY) + fun validityOpenChattingLink() { + openChattingLinkRegexPattern.find(planOpenChattingLink.value)?.value?.let { matchedString -> + planOpenChattingLink.value = matchedString + } + } companion object { const val FIRST_PAGE_POSITION = 0 @@ -254,6 +257,7 @@ class PlanViewModel @Inject constructor( const val START_RECRUITMENT = 2 const val END_RECRUITMENT = 99 const val BLANK_STRING = " " - const val OPEN_CHATTING_LINK_VALIDITY = "https://open.kakao.com/" + val openChattingLinkRegexPattern = + """https://open.kakao.com/o/[A-Za-z0-9]+""".toRegex() } } diff --git a/app/src/main/java/org/sopt/pingle/presentation/ui/plan/planopenchatting/PlanOpenChattingFragment.kt b/app/src/main/java/org/sopt/pingle/presentation/ui/plan/planopenchatting/PlanOpenChattingFragment.kt index 677a6a4d1..10515655c 100644 --- a/app/src/main/java/org/sopt/pingle/presentation/ui/plan/planopenchatting/PlanOpenChattingFragment.kt +++ b/app/src/main/java/org/sopt/pingle/presentation/ui/plan/planopenchatting/PlanOpenChattingFragment.kt @@ -3,7 +3,11 @@ package org.sopt.pingle.presentation.ui.plan.planopenchatting 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.FragmentPlanOpenChattingBinding import org.sopt.pingle.presentation.ui.plan.PlanViewModel @@ -16,10 +20,10 @@ class PlanOpenChattingFragment : private val planViewModel: PlanViewModel by activityViewModels() override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - binding.viewModel = planViewModel addListeners() + collectData() } private fun addListeners() { @@ -27,4 +31,10 @@ class PlanOpenChattingFragment : requireActivity().hideKeyboard(it) } } + + private fun collectData() { + planViewModel.planOpenChattingLink.flowWithLifecycle(lifecycle).onEach { openChattingLink -> + planViewModel.validityOpenChattingLink() + }.launchIn(lifecycleScope) + } }