Skip to content

Commit

Permalink
[AN/USER] feat: 버튼 더블 클릭 막기(#584) (#585)
Browse files Browse the repository at this point in the history
* feat: SingleClick Util 추가

* feat: 바텀 시트 바깥 클릭 막기

* feat: single 클릭 적용

* refactor: SingleClick 메서드명 변경

* refactor: xml 파일 호출 순서 맞추기
  • Loading branch information
SeongHoonC authored Oct 24, 2023
1 parent 8550e89 commit c88c5d4
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class TicketReserveBottomSheetFragment : BottomSheetDialogFragment() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

val viewModelProvider = ViewModelProvider(requireActivity())
vm = viewModelProvider[TicketReserveViewModel::class.java]
}
Expand All @@ -39,6 +38,7 @@ class TicketReserveBottomSheetFragment : BottomSheetDialogFragment() {
savedInstanceState: Bundle?,
): View {
_binding = FragmentTicketReserveBottomSheetBinding.inflate(inflater)
dialog?.setCanceledOnTouchOutside(false)
binding.lifecycleOwner = viewLifecycleOwner
return binding.root
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)}" />

</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
Original file line number Diff line number Diff line change
Expand Up @@ -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)}" />

</androidx.constraintlayout.widget.ConstraintLayout>
</layout>

0 comments on commit c88c5d4

Please sign in to comment.