Skip to content

Commit

Permalink
日常提交:2022-10-14。
Browse files Browse the repository at this point in the history
Signed-off-by: 王朋飞 <walgr1010>
  • Loading branch information
王朋飞 committed Oct 14, 2022
1 parent 042166b commit e1d3dfa
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import com.wpf.app.quick.widgets.selectview.data.QuickChildSelectData
import com.wpf.app.quick.widgets.selectview.data.QuickParentSelectData
import com.wpf.app.quick.widgets.selectview.helper.ParentChildDataHelper
import com.wpf.app.quick.widgets.selectview.helper.QuickStickyView
import com.wpf.app.quickutil.LogUtil
import com.wpf.app.quickutil.recyclerview.StickyItemDecoration

/**
Expand Down Expand Up @@ -61,14 +62,15 @@ open class QuickMultistageSelectView @JvmOverloads constructor(
}

private fun addListener() {
selectViewList[selectViewList.size - 1].addItemDecoration(StickyItemDecoration(QuickStickyView()))
// selectViewList[selectViewList.size - 1].addItemDecoration(StickyItemDecoration(QuickStickyView()))
selectViewList[selectViewList.size - 1].setOnSelectChangeListener(object :
OnSelectOnChange {
override fun onSelectChange() {
mOnSelectCallback?.onSelectResult(getSelectList())
}
})
selectViewList[selectViewList.size - 1].addOnScrollListener(object : OnScrollListener() {

override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
super.onScrollStateChanged(recyclerView, newState)
val selectAdapter: QuickSelectAdapter =
Expand Down Expand Up @@ -120,9 +122,14 @@ open class QuickMultistageSelectView @JvmOverloads constructor(
selectViewList[0].getSelectAdapter().curClickData = dataList[0]
selectViewList[0].getSelectAdapter().notifyItemChanged(0)
if (childInOne) {
selectViewList[1].setNewData(dataList.flatMap {
val allChildList = dataList.flatMap {
it.childList ?: arrayListOf()
})
}
val hasSuspension = allChildList.find { it.isSuspension } != null
selectViewList[1].setNewData(allChildList)
if (hasSuspension) {
selectViewList[1].addItemDecoration(StickyItemDecoration(QuickStickyView()))
}
} else {
selectViewList[1].setNewData(dataList[0].childList)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.wpf.app.quick.widgets.recyclerview.QuickSelectAdapter
import com.wpf.app.quick.widgets.recyclerview.data.QuickBindData
import com.wpf.app.quick.widgets.recyclerview.holder.QuickViewHolder
import com.wpf.app.quickbind.interfaces.RunItemClickWithSelf
import com.wpf.app.quickutil.recyclerview.scrollToPositionAndOffset

/**
* Created by 王朋飞 on 2022/7/13.
Expand Down Expand Up @@ -64,7 +65,7 @@ open class QuickParentSelectData(
}
}
if (findPos >= 0) {
childAdapter.mRecyclerView?.scrollToPosition(findPos)
childAdapter.mRecyclerView?.scrollToPositionAndOffset(findPos)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import android.view.View
import androidx.recyclerview.widget.RecyclerView
import com.wpf.app.quick.widgets.recyclerview.QuickAdapter
import com.wpf.app.quick.widgets.recyclerview.data.QuickItemData
import com.wpf.app.quick.widgets.selectview.data.QuickChildSelectData
import com.wpf.app.quickutil.LogUtil
import com.wpf.app.quickutil.recyclerview.StickyView

class QuickStickyView: StickyView {
class QuickStickyView : StickyView {

override fun isStickyView(recyclerView: RecyclerView, view: View?): Boolean {
val viewData = getViewData(recyclerView, view)
Expand All @@ -16,6 +18,15 @@ class QuickStickyView: StickyView {
return view?.tag == "true"
}

override fun getLastStickyView(adapter: RecyclerView.Adapter<RecyclerView.ViewHolder>?, curViewPos: Int): Int {
(0 until curViewPos).reversed().forEach { i ->
if (getViewData(adapter, i)?.isSuspension == true) {
return i
}
}
return -1
}

override fun getStickViewType(recyclerView: RecyclerView, view: View?): Int {
val viewData = getViewData(recyclerView, view)
if (viewData is QuickItemData) {
Expand All @@ -30,4 +41,9 @@ class QuickStickyView: StickyView {
val quickAdapter = recyclerView.adapter as? QuickAdapter
return quickAdapter?.mDataList?.getOrNull(viewPos)
}

private fun getViewData(adapter: RecyclerView.Adapter<RecyclerView.ViewHolder>?, viewPos: Int): QuickItemData? {
val quickAdapter = adapter as? QuickAdapter
return quickAdapter?.mDataList?.getOrNull(viewPos)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import androidx.recyclerview.widget.RecyclerView
* Created by 王朋飞 on 2022/6/22.
*/


fun RecyclerView.isScrollBottom(): Boolean {
return !canScrollVertically(1)
}
Expand All @@ -16,7 +15,7 @@ import androidx.recyclerview.widget.RecyclerView
return !canScrollVertically(-1)
}

fun RecyclerView.scrollToPosition(position: Int) {
fun RecyclerView.scrollToPositionAndOffset(position: Int) {
if (position != -1) {
scrollToPosition(position)
val mLayoutManager = layoutManager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.wpf.app.quickutil.LogUtil


class StickyItemDecoration(
Expand Down Expand Up @@ -181,6 +182,14 @@ class StickyItemDecoration(
if (!mStickyPositionList.contains(position)) {
mStickyPositionList.add(position)
}
//不能用上一次缓存的position,需要根据当前位置查询上一个可吸附的View
if (mStickyPositionList.size > 1) {
val lastPos = mStickyView.getLastStickyView(mAdapter, position)
if (lastPos != -1 && lastPos != position && !mStickyPositionList.contains(lastPos)) {
mStickyPositionList.add(mStickyPositionList.size - 2, lastPos)
mStickyPositionList.sort()
}
}
}

/**
Expand All @@ -189,7 +198,7 @@ class StickyItemDecoration(
* @return
*/
private fun getStickyViewPositionOfRecyclerView(m: Int): Int {
return mLayoutManager!!.findFirstVisibleItemPosition() + m
return (mLayoutManager?.findFirstVisibleItemPosition() ?: 0) + m
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@ import androidx.recyclerview.widget.RecyclerView
interface StickyView {
/**
* 是否是吸附view
* @param view
* @param curView
* @return
*/
fun isStickyView(recyclerView: RecyclerView, view: View?): Boolean
fun isStickyView(recyclerView: RecyclerView, curView: View?): Boolean

/**
* 得到上一个吸附View
*/
fun getLastStickyView(adapter: RecyclerView.Adapter<RecyclerView.ViewHolder>?, curViewPos: Int): Int

/**
* 得到吸附view的itemType
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ android.nonTransitiveRClass=true

IS_REMOTE=true
GROUP=com.wpf.app.quick
VERSION_NAME=0.4.4
VERSION_NAME=0.4.5

POM_DESCRIPTION=Quick Android.

Expand Down

0 comments on commit e1d3dfa

Please sign in to comment.