diff --git a/Quick/src/main/java/com/wpf/app/quick/widgets/selectview/data/QuickChildSelectData.kt b/Quick/src/main/java/com/wpf/app/quick/widgets/selectview/data/QuickChildSelectData.kt index 06aea221..f8824bb6 100644 --- a/Quick/src/main/java/com/wpf/app/quick/widgets/selectview/data/QuickChildSelectData.kt +++ b/Quick/src/main/java/com/wpf/app/quick/widgets/selectview/data/QuickChildSelectData.kt @@ -2,11 +2,7 @@ package com.wpf.app.quick.widgets.selectview.data import android.view.View import androidx.annotation.LayoutRes -import com.wpf.app.quick.annotations.BindData2View -import com.wpf.app.quickbind.helper.binddatahelper.ItemClick import com.wpf.app.quickbind.interfaces.RunItemClickWithSelf -import com.wpf.app.quickbind.interfaces.itemClickRun -import com.wpf.app.quickbind.interfaces.itemClickWithSelf /** * Created by 王朋飞 on 2022/7/13. @@ -17,7 +13,7 @@ open class QuickChildSelectData( open var parent: QuickParentSelectData? = null, override val isSuspension: Boolean = false, //View是否悬浮置顶 open var childList: MutableList? = null, - onChildClick: RunItemClickWithSelf? = null, + open val onChildClick: RunItemClickWithSelf? = null, override var id: String? = null, override var name: String? = null, override var defaultSelect: Boolean = false, @@ -30,11 +26,7 @@ open class QuickChildSelectData( override val maxLimitListener: MaxLimitListener? = null, //超出反馈 @LayoutRes override val layoutId: Int = 0, override val layoutView: View? = null, -) : QuickMultiSelectData( - layoutId = layoutId, - layoutView = layoutView, - isSuspension = isSuspension -) { +) : QuickMultiSelectData() { fun getChildSelectSize(): Int { return getChildSelectList()?.size ?: 0 @@ -44,29 +36,28 @@ open class QuickChildSelectData( return childList?.filter { it.isSelect } } - private val childClick = itemClickWithSelf { self -> - itemClickRun { - onClick() - if (self is QuickParentSelectData) { - if (!self.canClick) { - return@itemClickRun - } - getAdapter()?.onChildClick(self) - getAdapter()?.onParentChild(self) - } else { - getAdapter()?.onChildClick(self) + override fun onClick() { + super.onClick() + onItemClick() + if (this is QuickParentSelectData) { + if (!canClick) { + return } + getAdapter()?.onChildClick(this) + getAdapter()?.onParentChild(this) + } else { + getAdapter()?.onChildClick(this) + } + getViewHolder()?.itemView?.let { + onChildClick?.run(it, this)?.onClick(it) } } - @BindData2View(helper = ItemClick::class) - open val itemClick = onChildClick ?: childClick - - override fun onSelectChange(isSelect: Boolean) { + open fun onItemClick() { } - fun performClick() { - childClick.run(this) + override fun onSelectChange(isSelect: Boolean) { + } } \ No newline at end of file diff --git a/Quick/src/main/java/com/wpf/app/quick/widgets/selectview/data/QuickMultiSelectData.kt b/Quick/src/main/java/com/wpf/app/quick/widgets/selectview/data/QuickMultiSelectData.kt index ef57bee5..79a68508 100644 --- a/Quick/src/main/java/com/wpf/app/quick/widgets/selectview/data/QuickMultiSelectData.kt +++ b/Quick/src/main/java/com/wpf/app/quick/widgets/selectview/data/QuickMultiSelectData.kt @@ -27,11 +27,7 @@ open class QuickMultiSelectData( @LayoutRes override val layoutId: Int = 0, override val layoutView: View? = null, override val isSuspension: Boolean = false, //View是否悬浮置顶 -) : QuickSelectData( - layoutId = layoutId, - layoutView = layoutView, - isSuspension = isSuspension -) +) : QuickSelectData() interface MaxLimitListener { fun beyondLimit(limitSize: Int) diff --git a/Quick/src/main/java/com/wpf/app/quick/widgets/selectview/data/QuickParentSelectData.kt b/Quick/src/main/java/com/wpf/app/quick/widgets/selectview/data/QuickParentSelectData.kt index 1a8f0ff6..0cb2efee 100644 --- a/Quick/src/main/java/com/wpf/app/quick/widgets/selectview/data/QuickParentSelectData.kt +++ b/Quick/src/main/java/com/wpf/app/quick/widgets/selectview/data/QuickParentSelectData.kt @@ -33,13 +33,10 @@ open class QuickParentSelectData( override val layoutView: View? = null, ) : QuickChildSelectData( onChildClick = onParentClick as? RunItemClickWithSelf, - layoutId = layoutId, - layoutView = layoutView, - isSuspension = isSuspension ) { @SuppressLint("NotifyDataSetChanged") - override fun onClick() { + override fun onItemClick() { if (getView() != null) { if (getAdapter()?.curClickData != this) { val oldClickPos = getAdapter()?.getDataPos(getAdapter()?.curClickData) ?: -1 diff --git a/Quick/src/main/java/com/wpf/app/quick/widgets/selectview/data/QuickSelectData.kt b/Quick/src/main/java/com/wpf/app/quick/widgets/selectview/data/QuickSelectData.kt index aef4690f..ee17cef3 100644 --- a/Quick/src/main/java/com/wpf/app/quick/widgets/selectview/data/QuickSelectData.kt +++ b/Quick/src/main/java/com/wpf/app/quick/widgets/selectview/data/QuickSelectData.kt @@ -6,6 +6,8 @@ import androidx.annotation.LayoutRes import com.wpf.app.quick.widgets.selectview.QuickSelectAdapter import com.wpf.app.quickrecyclerview.QuickAdapter import com.wpf.app.quickrecyclerview.data.QuickBindData +import com.wpf.app.quickrecyclerview.data.QuickClickData +import com.wpf.app.quickrecyclerview.data.QuickStateData import com.wpf.app.quickrecyclerview.holder.QuickViewHolder /** @@ -20,7 +22,10 @@ open class QuickSelectData( @LayoutRes override val layoutId: Int = 0, override val layoutView: View? = null, override val isSuspension: Boolean = false, //View是否悬浮置顶 -) : QuickBindData(layoutId, layoutView, isSuspension = isSuspension) { +) : QuickClickData() { + override fun onClick() { + + } @CallSuper override fun onBindViewHolder( @@ -44,13 +49,6 @@ open class QuickSelectData( return super.getAdapter() as? QuickSelectAdapter } - /** - * 当前点击 - */ - open fun onClick() { - - } - /** * 选择状态变化 */ diff --git a/QuickRecyclerView/src/main/java/com/wpf/app/quickrecyclerview/data/QuickBindData.kt b/QuickRecyclerView/src/main/java/com/wpf/app/quickrecyclerview/data/QuickBindData.kt index 4067354e..52bd3483 100644 --- a/QuickRecyclerView/src/main/java/com/wpf/app/quickrecyclerview/data/QuickBindData.kt +++ b/QuickRecyclerView/src/main/java/com/wpf/app/quickrecyclerview/data/QuickBindData.kt @@ -76,6 +76,10 @@ open class QuickBindData( return getAdapter()?.getData()?.indexOf(this) ?: 0 } + open fun getViewPos(): Int { + return getViewHolder()?.bindingAdapterPosition ?: 0 + } + override fun getView(): View? { return mView } diff --git a/Quick/src/main/java/com/wpf/app/quick/widgets/selectview/data/QuickClickData.kt b/QuickRecyclerView/src/main/java/com/wpf/app/quickrecyclerview/data/QuickClickData.kt similarity index 91% rename from Quick/src/main/java/com/wpf/app/quick/widgets/selectview/data/QuickClickData.kt rename to QuickRecyclerView/src/main/java/com/wpf/app/quickrecyclerview/data/QuickClickData.kt index b4530d2a..ebd40bb1 100644 --- a/Quick/src/main/java/com/wpf/app/quick/widgets/selectview/data/QuickClickData.kt +++ b/QuickRecyclerView/src/main/java/com/wpf/app/quickrecyclerview/data/QuickClickData.kt @@ -1,4 +1,4 @@ -package com.wpf.app.quick.widgets.selectview.data +package com.wpf.app.quickrecyclerview.data import android.view.View import com.wpf.app.quick.annotations.BindData2View diff --git a/QuickRecyclerView/src/main/java/com/wpf/app/quickrecyclerview/data/QuickStateData.kt b/QuickRecyclerView/src/main/java/com/wpf/app/quickrecyclerview/data/QuickStateData.kt new file mode 100644 index 00000000..d0a9379f --- /dev/null +++ b/QuickRecyclerView/src/main/java/com/wpf/app/quickrecyclerview/data/QuickStateData.kt @@ -0,0 +1,18 @@ +package com.wpf.app.quickrecyclerview.data + +import android.view.View + +abstract class QuickStateData( + open var state: Boolean = false, + override val layoutId: Int = 0, + override val layoutView: View? = null, + override val isSuspension: Boolean = false, +): QuickClickData() { + + override fun onClick() { + state = !state + stateChange(state) + } + + abstract fun stateChange(state: Boolean) +} \ No newline at end of file diff --git a/app/src/main/java/com/wpf/app/quick/demo/model/BindDataTestModel.kt b/app/src/main/java/com/wpf/app/quick/demo/model/BindDataTestModel.kt index 9a3b9d19..cb78696d 100644 --- a/app/src/main/java/com/wpf/app/quick/demo/model/BindDataTestModel.kt +++ b/app/src/main/java/com/wpf/app/quick/demo/model/BindDataTestModel.kt @@ -3,14 +3,15 @@ package com.wpf.app.quick.demo.model import android.annotation.SuppressLint import com.wpf.app.quick.demo.R import com.wpf.app.quick.annotations.BindData2View +import com.wpf.app.quickrecyclerview.data.QuickClickData import com.wpf.app.quickbind.helper.binddatahelper.Url2ImageView -import com.wpf.app.quickrecyclerview.data.QuickBindData import com.wpf.app.quickbind.interfaces.runOnHolder +import com.wpf.app.quickutil.LogUtil /** * Created by 王朋飞 on 2022/7/5. */ -class BindDataTestModel : QuickBindData(R.layout.holder_test_bind_data) { +class BindDataTestModel : QuickClickData(R.layout.holder_test_bind_data) { @SuppressLint("NonConstantResourceId") @BindData2View(id = R.id.img, helper = Url2ImageView::class) var img = @@ -19,4 +20,8 @@ class BindDataTestModel : QuickBindData(R.layout.holder_test_bind_data) { val title = runOnHolder { "Title:${getViewHolder()?.bindingAdapterPosition}" } + + override fun onClick() { + LogUtil.e("点击了第${getViewPos() + 1}个") + } } \ No newline at end of file diff --git a/app/src/main/java/com/wpf/app/quick/demo/model/SelectResultItem.kt b/app/src/main/java/com/wpf/app/quick/demo/model/SelectResultItem.kt index 49e62176..a8165cb2 100644 --- a/app/src/main/java/com/wpf/app/quick/demo/model/SelectResultItem.kt +++ b/app/src/main/java/com/wpf/app/quick/demo/model/SelectResultItem.kt @@ -23,9 +23,8 @@ class SelectResultItem( onChildClick = itemClickWithSelf { self -> itemClickRun { self.isSelect = false - val index = self.getAdapter()?.getData()?.indexOf(self) ?: 0 self.getAdapter()?.getData()?.remove(self) - self.getAdapter()?.notifyItemRemoved(index) + self.getAdapter()?.notifyItemRemoved(self.getDataPos()) self.getAdapter()?.getOnSelectChangeListener()?.onSelectChange() } }) {