Skip to content

Commit

Permalink
perf: 优化过期方法
Browse files Browse the repository at this point in the history
  • Loading branch information
limuyang2 committed Nov 14, 2021
1 parent 6dcf477 commit a309265
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 14 deletions.
3 changes: 3 additions & 0 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ android {
viewBinding {
enabled = true
}
buildFeatures {
dataBinding = true
}
}

// 打包源码jar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ open class BaseBinderAdapter(list: MutableList<Any>? = null) : BaseQuickAdapter<
//如果没有设置点击监听,则回调给 itemProvider
//Callback to itemProvider if no click listener is set
viewHolder.itemView.setOnClickListener {
var position = viewHolder.adapterPosition
var position = viewHolder.bindingAdapterPosition
if (position == RecyclerView.NO_POSITION) {
return@setOnClickListener
}
Expand All @@ -137,7 +137,7 @@ open class BaseBinderAdapter(list: MutableList<Any>? = null) : BaseQuickAdapter<
//如果没有设置长按监听,则回调给itemProvider
// If you do not set a long press listener, callback to the itemProvider
viewHolder.itemView.setOnLongClickListener {
var position = viewHolder.adapterPosition
var position = viewHolder.bindingAdapterPosition
if (position == RecyclerView.NO_POSITION) {
return@setOnLongClickListener false
}
Expand All @@ -160,7 +160,7 @@ open class BaseBinderAdapter(list: MutableList<Any>? = null) : BaseQuickAdapter<
it.isClickable = true
}
it.setOnClickListener { v ->
var position: Int = viewHolder.adapterPosition
var position: Int = viewHolder.bindingAdapterPosition
if (position == RecyclerView.NO_POSITION) {
return@setOnClickListener
}
Expand All @@ -179,7 +179,7 @@ open class BaseBinderAdapter(list: MutableList<Any>? = null) : BaseQuickAdapter<
it.isLongClickable = true
}
it.setOnLongClickListener { v ->
var position: Int = viewHolder.adapterPosition
var position: Int = viewHolder.bindingAdapterPosition
if (position == RecyclerView.NO_POSITION) {
return@setOnLongClickListener false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ abstract class BaseProviderMultiAdapter<T>(data: MutableList<T>? = null) :
//如果没有设置点击监听,则回调给 itemProvider
//Callback to itemProvider if no click listener is set
viewHolder.itemView.setOnClickListener {
var position = viewHolder.adapterPosition
var position = viewHolder.bindingAdapterPosition
if (position == RecyclerView.NO_POSITION) {
return@setOnClickListener
}
Expand All @@ -110,7 +110,7 @@ abstract class BaseProviderMultiAdapter<T>(data: MutableList<T>? = null) :
//如果没有设置长按监听,则回调给itemProvider
// If you do not set a long press listener, callback to the itemProvider
viewHolder.itemView.setOnLongClickListener {
var position = viewHolder.adapterPosition
var position = viewHolder.bindingAdapterPosition
if (position == RecyclerView.NO_POSITION) {
return@setOnLongClickListener false
}
Expand All @@ -133,7 +133,7 @@ abstract class BaseProviderMultiAdapter<T>(data: MutableList<T>? = null) :
it.isClickable = true
}
it.setOnClickListener { v ->
var position: Int = viewHolder.adapterPosition
var position: Int = viewHolder.bindingAdapterPosition
if (position == RecyclerView.NO_POSITION) {
return@setOnClickListener
}
Expand All @@ -152,7 +152,7 @@ abstract class BaseProviderMultiAdapter<T>(data: MutableList<T>? = null) :
it.isLongClickable = true
}
it.setOnLongClickListener { v ->
var position: Int = viewHolder.adapterPosition
var position: Int = viewHolder.bindingAdapterPosition
if (position == RecyclerView.NO_POSITION) {
return@setOnLongClickListener false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ abstract class BaseQuickAdapter<T, VH : BaseViewHolder>
protected open fun bindViewClickListener(viewHolder: VH, viewType: Int) {
mOnItemClickListener?.let {
viewHolder.itemView.setOnClickListener { v ->
var position = viewHolder.adapterPosition
var position = viewHolder.bindingAdapterPosition
if (position == RecyclerView.NO_POSITION) {
return@setOnClickListener
}
Expand All @@ -502,7 +502,7 @@ abstract class BaseQuickAdapter<T, VH : BaseViewHolder>
}
mOnItemLongClickListener?.let {
viewHolder.itemView.setOnLongClickListener { v ->
var position = viewHolder.adapterPosition
var position = viewHolder.bindingAdapterPosition
if (position == RecyclerView.NO_POSITION) {
return@setOnLongClickListener false
}
Expand All @@ -518,7 +518,7 @@ abstract class BaseQuickAdapter<T, VH : BaseViewHolder>
childView.isClickable = true
}
childView.setOnClickListener { v ->
var position = viewHolder.adapterPosition
var position = viewHolder.bindingAdapterPosition
if (position == RecyclerView.NO_POSITION) {
return@setOnClickListener
}
Expand All @@ -535,7 +535,7 @@ abstract class BaseQuickAdapter<T, VH : BaseViewHolder>
childView.isLongClickable = true
}
childView.setOnLongClickListener { v ->
var position = viewHolder.adapterPosition
var position = viewHolder.bindingAdapterPosition
if (position == RecyclerView.NO_POSITION) {
return@setOnLongClickListener false
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.chad.library.adapter.base

import android.view.ViewGroup
import androidx.annotation.LayoutRes
import com.chad.library.adapter.base.entity.SectionEntity
import com.chad.library.adapter.base.viewholder.BaseViewHolder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.annotation.*
import androidx.core.content.ContextCompat
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.recyclerview.widget.RecyclerView
Expand Down Expand Up @@ -70,7 +71,7 @@ open class BaseViewHolder(view: View) : RecyclerView.ViewHolder(view) {
}

open fun setTextColorRes(@IdRes viewId: Int, @ColorRes colorRes: Int): BaseViewHolder {
getView<TextView>(viewId).setTextColor(itemView.resources.getColor(colorRes))
getView<TextView>(viewId).setTextColor(ContextCompat.getColor(itemView.context, colorRes))
return this
}

Expand Down

0 comments on commit a309265

Please sign in to comment.