-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
34ff307
commit aaef14c
Showing
6 changed files
with
78 additions
and
23 deletions.
There are no files selected for viewing
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
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
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
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
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
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,37 @@ | ||
package com.zj.singclick | ||
|
||
import android.view.View | ||
|
||
/** | ||
* 版权:渤海新能 版权所有 | ||
* @author zhujiang | ||
* 版本:1.5 | ||
* 创建日期:2020/4/29 | ||
* 描述:AndroidAOP | ||
* | ||
*/ | ||
|
||
|
||
inline fun View.setSafeListener(crossinline action:()->Unit){ | ||
var lastClick=0L | ||
setOnClickListener { | ||
val gap = System.currentTimeMillis() - lastClick | ||
lastClick=System.currentTimeMillis() | ||
if(gap<1500) return@setOnClickListener | ||
action.invoke() | ||
} | ||
} | ||
|
||
|
||
var _viewClickFlag = false | ||
var _clickRunnable = Runnable { _viewClickFlag = false } | ||
fun View.click(action: (view: View) -> Unit) { | ||
setOnClickListener { | ||
if (!_viewClickFlag) { | ||
_viewClickFlag = true | ||
action(it) | ||
} | ||
removeCallbacks(_clickRunnable) | ||
postDelayed(_clickRunnable, 1000) | ||
} | ||
} |