diff --git a/app/src/main/java/com/moyerun/moyeorun_android/common/extension/ViewExtension.kt b/app/src/main/java/com/moyerun/moyeorun_android/common/extension/ViewExtension.kt new file mode 100644 index 0000000..bb0e66e --- /dev/null +++ b/app/src/main/java/com/moyerun/moyeorun_android/common/extension/ViewExtension.kt @@ -0,0 +1,19 @@ +package com.moyerun.moyeorun_android.common.extension + +import android.view.View + +fun View.setOnDebounceClickListener(interval: Long = 1000L, action: (View?) -> Unit) { + val debounceClickListener = object : View.OnClickListener { + private var lastClickedMillis = 0L + + override fun onClick(view: View?) { + val now = System.currentTimeMillis() + if (now - lastClickedMillis < interval) { + return + } + lastClickedMillis = now + action.invoke(view) + } + } + setOnClickListener(debounceClickListener) +} \ No newline at end of file