Skip to content

Commit

Permalink
[feat] #200 오픈채팅방 링크 유효성검사
Browse files Browse the repository at this point in the history
  • Loading branch information
DoReMinWoo committed Mar 6, 2024
1 parent 30580e1 commit 56bd2ab
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -85,7 +83,6 @@ class PlanActivity : BindingActivity<ActivityPlanBinding>(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++
}
}
Expand Down Expand Up @@ -163,24 +160,10 @@ class PlanActivity : BindingActivity<ActivityPlanBinding>(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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -16,15 +20,21 @@ 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() {
binding.root.setOnClickListener {
requireActivity().hideKeyboard(it)
}
}

private fun collectData() {
planViewModel.planOpenChattingLink.flowWithLifecycle(lifecycle).onEach { openChattingLink ->
planViewModel.validityOpenChattingLink()
}.launchIn(lifecycleScope)
}
}

0 comments on commit 56bd2ab

Please sign in to comment.