Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.0.4 rxbinding #3220

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Tue Feb 25 13:08:15 CST 2020
#Thu Jun 11 10:01:00 CST 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
Expand Down
1 change: 1 addition & 0 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'com.jakewharton.rxbinding4:rxbinding:4.0.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ import com.chad.library.adapter.base.listener.*
import com.chad.library.adapter.base.module.*
import com.chad.library.adapter.base.util.getItemView
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.jakewharton.rxbinding4.view.clicks
import java.lang.ref.WeakReference
import java.lang.reflect.Constructor
import java.lang.reflect.InvocationTargetException
import java.lang.reflect.Modifier
import java.lang.reflect.ParameterizedType
import java.util.*
import java.util.concurrent.TimeUnit
import kotlin.collections.ArrayList

/**
Expand Down Expand Up @@ -173,6 +175,7 @@ abstract class BaseQuickAdapter<T, VH : BaseViewHolder>
private var mUpFetchModule: BaseUpFetchModule? = null
private var mDraggableModule: BaseDraggableModule? = null
internal var mLoadMoreModule: BaseLoadMoreModule? = null
private var throttleTime: Long = 1000

protected lateinit var context: Context
private set
Expand Down Expand Up @@ -523,20 +526,41 @@ abstract class BaseQuickAdapter<T, VH : BaseViewHolder>
}
}

/**
* set a millisecond,itemClick or itemChildClick Execute only once in tTime millisecond
*
* 设置一个毫秒时间tTime ,是的在改时间诶点击事件只响应一次
*/
fun addThrottleTime(@NonNull tTime: Long) {
throttleTime = tTime
}

/**
* 绑定 item 点击事件
* @param viewHolder VH
*/
protected open fun bindViewClickListener(viewHolder: VH, viewType: Int) {
mOnItemClickListener?.let {
viewHolder.itemView.setOnClickListener { v ->
var position = viewHolder.adapterPosition
if (position == RecyclerView.NO_POSITION) {
return@setOnClickListener
}
position -= headerLayoutCount
setOnItemClick(v, position)
with(viewHolder.itemView) {
clicks()
.throttleFirst(throttleTime, TimeUnit.MILLISECONDS)
.subscribe {
var position = viewHolder.adapterPosition
if (position == RecyclerView.NO_POSITION) {
return@subscribe
}
position -= headerLayoutCount
setOnItemClick(this, position)
}
}
// viewHolder.itemView.setOnClickListener { v ->
// var position = viewHolder.adapterPosition
// if (position == RecyclerView.NO_POSITION) {
// return@setOnClickListener
// }
// position -= headerLayoutCount
// setOnItemClick(v, position)
// }
}
mOnItemLongClickListener?.let {
viewHolder.itemView.setOnLongClickListener { v ->
Expand All @@ -555,14 +579,25 @@ abstract class BaseQuickAdapter<T, VH : BaseViewHolder>
if (!childView.isClickable) {
childView.isClickable = true
}
childView.setOnClickListener { v ->
var position = viewHolder.adapterPosition
if (position == RecyclerView.NO_POSITION) {
return@setOnClickListener
}
position -= headerLayoutCount
setOnItemChildClick(v, position)
}
childView.clicks()
.throttleFirst(throttleTime, TimeUnit.MILLISECONDS)
.subscribe {
var position = viewHolder.adapterPosition
if (position == RecyclerView.NO_POSITION) {
return@subscribe
}
position -= headerLayoutCount
setOnItemChildClick(childView, position)
}

// .setOnClickListener { v ->
// var position = viewHolder.adapterPosition
// if (position == RecyclerView.NO_POSITION) {
// return@setOnClickListener
// }
// position -= headerLayoutCount
// setOnItemChildClick(v, position)
// }
}
}
}
Expand Down