From c88c5d4582c91b5a30c629616e493a02c92b76e8 Mon Sep 17 00:00:00 2001 From: SeongHoonC <108349655+SeongHoonC@users.noreply.github.com> Date: Tue, 24 Oct 2023 17:48:42 +0900 Subject: [PATCH] =?UTF-8?q?[AN/USER]=20feat:=20=EB=B2=84=ED=8A=BC=20?= =?UTF-8?q?=EB=8D=94=EB=B8=94=20=ED=81=B4=EB=A6=AD=20=EB=A7=89=EA=B8=B0(#5?= =?UTF-8?q?84)=20(#585)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: SingleClick Util 추가 * feat: 바텀 시트 바깥 클릭 막기 * feat: single 클릭 적용 * refactor: SingleClick 메서드명 변경 * refactor: xml 파일 호출 순서 맞추기 --- .../StudentVerificationActivity.kt | 3 +- .../TicketReserveBottomSheetFragment.kt | 2 +- .../presentation/util/SingleClickUtil.kt | 30 +++++++++++++++++++ .../fragment_ticket_reserve_bottom_sheet.xml | 4 +-- .../main/res/layout/item_ticket_reserve.xml | 4 +-- 5 files changed, 37 insertions(+), 6 deletions(-) create mode 100644 android/festago/app/src/main/java/com/festago/festago/presentation/util/SingleClickUtil.kt diff --git a/android/festago/app/src/main/java/com/festago/festago/presentation/ui/studentverification/StudentVerificationActivity.kt b/android/festago/app/src/main/java/com/festago/festago/presentation/ui/studentverification/StudentVerificationActivity.kt index 349ec05d4..54004bff5 100644 --- a/android/festago/app/src/main/java/com/festago/festago/presentation/ui/studentverification/StudentVerificationActivity.kt +++ b/android/festago/app/src/main/java/com/festago/festago/presentation/ui/studentverification/StudentVerificationActivity.kt @@ -10,6 +10,7 @@ import com.festago.festago.databinding.ActivityStudentVerificationBinding import com.festago.festago.presentation.ui.customview.OkDialogFragment import com.festago.festago.presentation.ui.home.HomeActivity import com.festago.festago.presentation.util.repeatOnStarted +import com.festago.festago.presentation.util.setOnSingleClickListener import dagger.hilt.android.AndroidEntryPoint import java.time.LocalTime import java.time.format.DateTimeFormatter @@ -43,7 +44,7 @@ class StudentVerificationActivity : AppCompatActivity() { } private fun initRequestVerificationCodeBtn(schoolId: Long) { - binding.btnRequestVerificationCode.setOnClickListener { + binding.btnRequestVerificationCode.setOnSingleClickListener { vm.sendVerificationCode(binding.tieUserName.text.toString(), schoolId) } } diff --git a/android/festago/app/src/main/java/com/festago/festago/presentation/ui/ticketreserve/bottomsheet/TicketReserveBottomSheetFragment.kt b/android/festago/app/src/main/java/com/festago/festago/presentation/ui/ticketreserve/bottomsheet/TicketReserveBottomSheetFragment.kt index 6e2aecd0e..9c48dfb6e 100644 --- a/android/festago/app/src/main/java/com/festago/festago/presentation/ui/ticketreserve/bottomsheet/TicketReserveBottomSheetFragment.kt +++ b/android/festago/app/src/main/java/com/festago/festago/presentation/ui/ticketreserve/bottomsheet/TicketReserveBottomSheetFragment.kt @@ -28,7 +28,6 @@ class TicketReserveBottomSheetFragment : BottomSheetDialogFragment() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - val viewModelProvider = ViewModelProvider(requireActivity()) vm = viewModelProvider[TicketReserveViewModel::class.java] } @@ -39,6 +38,7 @@ class TicketReserveBottomSheetFragment : BottomSheetDialogFragment() { savedInstanceState: Bundle?, ): View { _binding = FragmentTicketReserveBottomSheetBinding.inflate(inflater) + dialog?.setCanceledOnTouchOutside(false) binding.lifecycleOwner = viewLifecycleOwner return binding.root } diff --git a/android/festago/app/src/main/java/com/festago/festago/presentation/util/SingleClickUtil.kt b/android/festago/app/src/main/java/com/festago/festago/presentation/util/SingleClickUtil.kt new file mode 100644 index 000000000..ae4b96588 --- /dev/null +++ b/android/festago/app/src/main/java/com/festago/festago/presentation/util/SingleClickUtil.kt @@ -0,0 +1,30 @@ +package com.festago.festago.presentation.util + +import android.os.SystemClock +import android.view.View +import androidx.databinding.BindingAdapter + +class OnSingleClickListener( + private var interval: Int = 600, + private var onSingleClick: (View) -> Unit, +) : View.OnClickListener { + + private var lastClickTime: Long = 0 + + override fun onClick(v: View) { + val elapsedRealtime = SystemClock.elapsedRealtime() + if ((elapsedRealtime - lastClickTime) < interval) { + return + } + lastClickTime = elapsedRealtime + onSingleClick(v) + } +} + +@BindingAdapter("onSingleClick") +fun View.setOnSingleClickListener(onSingleClick: (View) -> Unit) { + val oneClick = OnSingleClickListener { + onSingleClick(it) + } + setOnClickListener(oneClick) +} diff --git a/android/festago/app/src/main/res/layout/fragment_ticket_reserve_bottom_sheet.xml b/android/festago/app/src/main/res/layout/fragment_ticket_reserve_bottom_sheet.xml index 5235b5d9f..384feb9f2 100644 --- a/android/festago/app/src/main/res/layout/fragment_ticket_reserve_bottom_sheet.xml +++ b/android/festago/app/src/main/res/layout/fragment_ticket_reserve_bottom_sheet.xml @@ -93,11 +93,11 @@ android:layout_height="wrap_content" android:layout_marginHorizontal="16dp" android:layout_marginVertical="28dp" - android:onClick="@{() -> onReserve.invoke(selectedTicketTypeId)}" android:text="@string/ticket_reserve_tv_btn_reserve_ticket" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintStart_toStartOf="parent" /> + app:layout_constraintStart_toStartOf="parent" + app:onSingleClick="@{() -> onReserve.invoke(selectedTicketTypeId)}" /> diff --git a/android/festago/app/src/main/res/layout/item_ticket_reserve.xml b/android/festago/app/src/main/res/layout/item_ticket_reserve.xml index c1df86cff..f1835d3db 100644 --- a/android/festago/app/src/main/res/layout/item_ticket_reserve.xml +++ b/android/festago/app/src/main/res/layout/item_ticket_reserve.xml @@ -111,11 +111,11 @@ android:layout_height="wrap_content" android:layout_marginHorizontal="16dp" android:layout_marginTop="28dp" - android:onClick="@{() -> stage.onShowStageTickets.invoke(stage.id, stage.startTime)}" android:text="@string/ticket_reserve_btn_reserve_ticket" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toBottomOf="@id/tvAuthGuideStudent" /> + app:layout_constraintTop_toBottomOf="@id/tvAuthGuideStudent" + app:onSingleClick="@{() -> stage.onShowStageTickets.invoke(stage.id, stage.startTime)}" />