Skip to content

Commit

Permalink
Double Click Listener
Browse files Browse the repository at this point in the history
  • Loading branch information
JayantGoel001 committed Jul 30, 2020
1 parent 094453b commit be412f6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,4 +1,34 @@
package com.example.doubleclicklistner

class DoubleClickListener {
import android.view.View

class DoubleClickListener(private val callback: Callback,private val doubleClickTimeLimit:Long=1000) :
View.OnClickListener {
private var lastClicked:Long = -1L
override fun onClick(v: View?) {
lastClicked = when{
lastClicked == -1L ->{
System.currentTimeMillis()
}
isDoubleClicked()->{
callback.doubleClicked()
-1L
}
else->{
System.currentTimeMillis()
}

}
}
private fun getTimeDifference(from:Long,to:Long):Long{
return to-from
}
private fun isDoubleClicked():Boolean{
return getTimeDifference(lastClicked,System.currentTimeMillis())<=doubleClickTimeLimit
}
interface Callback{
fun doubleClicked()
}


}

0 comments on commit be412f6

Please sign in to comment.