Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AN/USER] feat: 버튼 더블 클릭 막기(#584) #585

Merged
merged 5 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

특별히 600 밀리세컨드인 이유가 있을까요??

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0.6초인 이유는 딱히 없습니다. 여러 코드를 찾아본 결과 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>