Skip to content

Commit

Permalink
Merge pull request #29 from MoyeoRun/feature/debounce-click
Browse files Browse the repository at this point in the history
[#11] 각종 편의 확장함수 추가 - DebounceClick
  • Loading branch information
ethan-223 authored Apr 13, 2022
2 parents bbf2b9e + 8e6d2a1 commit a9f2a16
Showing 1 changed file with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit a9f2a16

Please sign in to comment.