-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from MoyeoRun/feature/debounce-click
[#11] 각종 편의 확장함수 추가 - DebounceClick
- Loading branch information
Showing
1 changed file
with
19 additions
and
0 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
app/src/main/java/com/moyerun/moyeorun_android/common/extension/ViewExtension.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |