[BadCase]增加case间的间距
This commit is contained in:
@@ -20,6 +20,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.mogo.eagle.core.data.autopilot.AutoPilotRecordResult
|
||||
import com.mogo.eagle.core.utilcode.kotlin.*
|
||||
import com.mogo.eagle.core.utilcode.rv.divider.CommonDividerItemDecoration
|
||||
import com.zhjt.mogo_core_function_devatools.R
|
||||
import com.zhjt.mogo_core_function_devatools.badcase.api.entity.BadCaseResponse.Reason
|
||||
import com.zhjt.mogo_core_function_devatools.badcase.repository.db.entity.AutoPilotRecord
|
||||
@@ -97,6 +98,11 @@ internal class BadCaseView: ConstraintLayout {
|
||||
cases = causes
|
||||
rv_take_over?.let {
|
||||
it.layoutManager = LinearLayoutManager(it.context, LinearLayoutManager.VERTICAL, false)
|
||||
it.addItemDecoration(
|
||||
CommonDividerItemDecoration
|
||||
.Builder()
|
||||
.verticalInnerSpace(50.toPixels().toInt())
|
||||
.build())
|
||||
it.adapter = object : RecyclerView.Adapter<BadCaseViewHolder>() {
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BadCaseViewHolder = BadCaseViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.layout_badcase_item, parent, false))
|
||||
override fun onBindViewHolder(holder: BadCaseViewHolder, position: Int) {
|
||||
|
||||
@@ -55,7 +55,7 @@
|
||||
android:id="@+id/rv_take_over"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginTop="72px"
|
||||
android:layout_marginTop="101px"
|
||||
android:overScrollMode="never"
|
||||
app:layout_constraintBottom_toTopOf="@+id/ok"
|
||||
android:layout_marginBottom="20px"
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="@dimen/dp_10"
|
||||
android:paddingTop="@dimen/dp_10"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<ImageView
|
||||
|
||||
@@ -104,9 +104,9 @@ object Reminder {
|
||||
return
|
||||
}
|
||||
enqueued += key
|
||||
attaches.getOrPut(attachTo, {
|
||||
attaches.getOrPut(attachTo) {
|
||||
mutableListOf()
|
||||
}).also {
|
||||
}.also {
|
||||
it.add(WeakReference(reminder))
|
||||
}
|
||||
listener?.let {
|
||||
|
||||
@@ -0,0 +1,435 @@
|
||||
package com.mogo.eagle.core.utilcode.rv.divider
|
||||
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Rect
|
||||
import android.util.Pair
|
||||
import android.view.View
|
||||
import androidx.annotation.IntRange
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import androidx.recyclerview.widget.GridLayoutManager.LayoutParams
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.recyclerview.widget.RecyclerView.ItemDecoration
|
||||
import androidx.recyclerview.widget.RecyclerView.State
|
||||
import androidx.recyclerview.widget.StaggeredGridLayoutManager
|
||||
import java.util.ArrayList
|
||||
|
||||
/**
|
||||
* @Description: 针对RecyclerView的通用分隔线
|
||||
*/
|
||||
class CommonDividerItemDecoration internal constructor(builder: Builder) : ItemDecoration() {
|
||||
/**
|
||||
* 水平方向-item间的距离-不包括最左边或最右边的Item距离RecyclerView最左边或最右边的距离
|
||||
*/
|
||||
private val mHorizontalInnerSpace: Int
|
||||
|
||||
/**
|
||||
* 竖直方向-item间的距离-不包括最上边或最下边的Item距离RecyclerView最上边或最右边的距离
|
||||
*/
|
||||
private val mVerticalInnerSpace: Int
|
||||
private var mSpanCountLRCare = false
|
||||
private var mSpanCountTBCare = false
|
||||
private val mHorizontalExternalSpace: Int
|
||||
private val mVerticalExternalSpace: Int
|
||||
private var mLastRight = 0
|
||||
private var mLastBottom = 0
|
||||
private var mFromPosition = 0
|
||||
private var mHorizontalDelta: Pair<Int, Int>? = null
|
||||
private var mVerticalDelta: Pair<Int, Int>? = null
|
||||
|
||||
/**
|
||||
* 外部间隔结束位置是否需要
|
||||
*/
|
||||
private val mExternalSpaceEndEnable: Boolean
|
||||
private val mItemDecorationHandlers: List<ItemDecorationHandler>?
|
||||
|
||||
|
||||
override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: State) {
|
||||
val layoutManager = parent.layoutManager
|
||||
val adapter = parent.adapter ?: return
|
||||
var viewType = Int.MIN_VALUE
|
||||
var position = Int.MIN_VALUE
|
||||
val itemCount = adapter.itemCount
|
||||
var deltaHL = 0
|
||||
var deltaHR = 0
|
||||
var deltaVT = 0
|
||||
var deltaVB = 0
|
||||
val horizontalDelta = mHorizontalDelta
|
||||
if (horizontalDelta != null) {
|
||||
deltaHL = horizontalDelta.first
|
||||
deltaHR = horizontalDelta.second
|
||||
}
|
||||
val verticalDelta = mVerticalDelta
|
||||
if (verticalDelta != null) {
|
||||
deltaVT = verticalDelta.first
|
||||
deltaVB = verticalDelta.second
|
||||
}
|
||||
if (layoutManager is LinearLayoutManager) {
|
||||
if (layoutManager is GridLayoutManager) {
|
||||
val childPosition = parent.getChildAdapterPosition(view)
|
||||
if (childPosition < mFromPosition) {
|
||||
return
|
||||
}
|
||||
position = childPosition
|
||||
viewType = adapter.getItemViewType(childPosition)
|
||||
val lp = view.layoutParams as LayoutParams
|
||||
val spanCount = layoutManager.spanCount
|
||||
val lookUp = layoutManager.spanSizeLookup
|
||||
val spanIndex = lp.spanIndex
|
||||
if (layoutManager.orientation == GridLayoutManager.VERTICAL) {
|
||||
if (lp.spanSize == spanCount) { //铺满一行
|
||||
if (!mSpanCountLRCare) {
|
||||
outRect.left = mHorizontalExternalSpace + deltaHL
|
||||
outRect.right = mHorizontalExternalSpace + deltaHR
|
||||
}
|
||||
} else {
|
||||
val averageDistance = (((spanCount - 1) * mHorizontalInnerSpace + 2 * mHorizontalExternalSpace + deltaHL + deltaHR) * 1.0f / spanCount).toInt()
|
||||
if (spanIndex == 0) {
|
||||
outRect.left = mHorizontalExternalSpace + deltaHL
|
||||
outRect.right = averageDistance - outRect.left
|
||||
mLastRight = outRect.right
|
||||
} else if (spanIndex == spanCount - 1) {
|
||||
outRect.right = mHorizontalExternalSpace + deltaHR
|
||||
outRect.left = averageDistance - outRect.right
|
||||
} else {
|
||||
outRect.left = mHorizontalInnerSpace - mLastRight
|
||||
outRect.right = averageDistance - outRect.left
|
||||
mLastRight = outRect.right
|
||||
}
|
||||
} //所在的行数
|
||||
if (lookUp.getSpanGroupIndex(childPosition, spanCount) == lookUp.getSpanGroupIndex(mFromPosition, spanCount)) {
|
||||
if (!mSpanCountTBCare) {
|
||||
outRect.top = mVerticalExternalSpace + deltaVT
|
||||
}
|
||||
}
|
||||
val rowIndex = lookUp.getSpanGroupIndex(childPosition, spanCount)
|
||||
val lastRowIndex = lookUp.getSpanGroupIndex(itemCount - 1, spanCount)
|
||||
if (rowIndex != lastRowIndex) {
|
||||
outRect.bottom = mVerticalInnerSpace
|
||||
} else {
|
||||
var delta = 0
|
||||
if (mExternalSpaceEndEnable) {
|
||||
delta = mVerticalExternalSpace
|
||||
}
|
||||
outRect.bottom = delta + deltaVB
|
||||
}
|
||||
} else {
|
||||
if (lp.spanSize == spanCount) { //铺满一行
|
||||
if (!mSpanCountTBCare) {
|
||||
outRect.top = mVerticalExternalSpace + deltaVT
|
||||
outRect.bottom = mVerticalExternalSpace + deltaVB
|
||||
}
|
||||
} else {
|
||||
val averageDistance = (((spanCount - 1) * mVerticalInnerSpace + 2 * mVerticalExternalSpace + deltaVT + deltaVB) * 1.0f / spanCount).toInt()
|
||||
if (spanIndex == 0) {
|
||||
outRect.top = mVerticalExternalSpace + deltaVT
|
||||
outRect.bottom = averageDistance - outRect.top
|
||||
mLastBottom = outRect.bottom
|
||||
} else if (spanIndex == spanCount - 1) {
|
||||
outRect.top = mVerticalExternalSpace + deltaVB
|
||||
outRect.bottom = averageDistance - outRect.top
|
||||
} else {
|
||||
outRect.top = mVerticalInnerSpace - mLastBottom
|
||||
outRect.bottom = averageDistance - outRect.top
|
||||
mLastBottom = outRect.bottom
|
||||
}
|
||||
}
|
||||
if (lookUp.getSpanGroupIndex(childPosition, spanCount) == lookUp.getSpanGroupIndex(mFromPosition, spanCount)) { //第一列
|
||||
if (!mSpanCountLRCare) {
|
||||
outRect.left = mHorizontalExternalSpace + deltaHL
|
||||
}
|
||||
}
|
||||
val colIndex = lookUp.getSpanGroupIndex(childPosition, spanCount)
|
||||
val lastColIndex = lookUp.getSpanGroupIndex(itemCount - 1, spanCount)
|
||||
if (colIndex != lastColIndex) {
|
||||
outRect.right = mHorizontalInnerSpace
|
||||
} else {
|
||||
var delta = 0
|
||||
if (mExternalSpaceEndEnable) {
|
||||
delta = mHorizontalExternalSpace
|
||||
}
|
||||
outRect.right = delta + deltaHR
|
||||
}
|
||||
}
|
||||
doCallHandlersOnFinally(outRect, viewType, position)
|
||||
return
|
||||
}
|
||||
val childPosition = parent.getChildAdapterPosition(view)
|
||||
if (childPosition < mFromPosition) {
|
||||
return
|
||||
}
|
||||
position = childPosition
|
||||
viewType = adapter.getItemViewType(childPosition)
|
||||
if (layoutManager.orientation == LinearLayoutManager.VERTICAL) {
|
||||
outRect.left = mHorizontalExternalSpace + deltaHL
|
||||
outRect.right = mHorizontalExternalSpace + deltaHR
|
||||
if (childPosition == 0) {
|
||||
if (!mSpanCountTBCare) {
|
||||
outRect.top = mVerticalExternalSpace + deltaVT
|
||||
}
|
||||
outRect.bottom = mVerticalInnerSpace
|
||||
} else if (childPosition < itemCount - 1) {
|
||||
outRect.bottom = mVerticalInnerSpace
|
||||
} else {
|
||||
var delta = 0
|
||||
if (mExternalSpaceEndEnable) {
|
||||
delta = mVerticalExternalSpace
|
||||
}
|
||||
outRect.bottom = delta + deltaVB
|
||||
}
|
||||
} else {
|
||||
outRect.top = mVerticalExternalSpace + deltaVT
|
||||
outRect.bottom = mVerticalExternalSpace + deltaVB
|
||||
if (childPosition == 0) {
|
||||
if (!mSpanCountLRCare) {
|
||||
outRect.left = mHorizontalExternalSpace + deltaHL
|
||||
}
|
||||
outRect.right = mHorizontalInnerSpace
|
||||
} else if (childPosition < itemCount - 1) {
|
||||
outRect.right = mHorizontalInnerSpace
|
||||
} else {
|
||||
if (mExternalSpaceEndEnable) {
|
||||
outRect.right = mHorizontalExternalSpace
|
||||
}
|
||||
outRect.right = outRect.right + deltaHR
|
||||
}
|
||||
}
|
||||
} else if (layoutManager is StaggeredGridLayoutManager) {
|
||||
val childPosition = parent.getChildAdapterPosition(view)
|
||||
if (childPosition < mFromPosition) {
|
||||
return
|
||||
}
|
||||
position = childPosition
|
||||
viewType = adapter.getItemViewType(childPosition)
|
||||
val lp = view.layoutParams as StaggeredGridLayoutManager.LayoutParams
|
||||
val spanCount = layoutManager.spanCount
|
||||
val spanIndex = lp.spanIndex
|
||||
if (layoutManager.orientation == StaggeredGridLayoutManager.VERTICAL) {
|
||||
if (lp.isFullSpan) { //铺满一行
|
||||
if (!mSpanCountLRCare) {
|
||||
outRect.left = mHorizontalExternalSpace + deltaHL
|
||||
outRect.right = mHorizontalExternalSpace + deltaHR
|
||||
}
|
||||
} else {
|
||||
val averageDistance = (((spanCount - 1) * mHorizontalInnerSpace + 2 * mHorizontalExternalSpace + deltaHL + deltaHR) * 1.0f / spanCount).toInt()
|
||||
if (spanIndex == 0) {
|
||||
outRect.left = mHorizontalExternalSpace + deltaHL
|
||||
outRect.right = averageDistance - outRect.left
|
||||
mLastRight = outRect.right
|
||||
} else if (spanIndex == spanCount - 1) {
|
||||
outRect.right = mHorizontalExternalSpace + deltaHR
|
||||
outRect.left = averageDistance - outRect.right
|
||||
} else {
|
||||
outRect.left = mHorizontalInnerSpace - mLastRight
|
||||
outRect.right = averageDistance - outRect.left
|
||||
mLastRight = outRect.right
|
||||
}
|
||||
}
|
||||
if (childPosition == mFromPosition) {
|
||||
if (lp.isFullSpan) {
|
||||
if (!mSpanCountTBCare) {
|
||||
outRect.top = mVerticalExternalSpace + deltaVT
|
||||
}
|
||||
} else {
|
||||
outRect.top = mVerticalExternalSpace + deltaVT
|
||||
}
|
||||
} else if (childPosition == spanIndex) {
|
||||
if (!lp.isFullSpan) {
|
||||
var isPreviousViewFullSpan = false
|
||||
if (childPosition - 1 == mFromPosition) {
|
||||
val previousView = layoutManager.findViewByPosition(childPosition - 1)
|
||||
if (previousView != null && previousView.layoutParams is StaggeredGridLayoutManager.LayoutParams) {
|
||||
val lastViewParams = previousView.layoutParams as StaggeredGridLayoutManager.LayoutParams
|
||||
isPreviousViewFullSpan = lastViewParams.isFullSpan
|
||||
}
|
||||
}
|
||||
val compareValue = if (isPreviousViewFullSpan) spanCount - 1 else spanCount
|
||||
if (childPosition - mFromPosition < compareValue) {
|
||||
outRect.top = mVerticalExternalSpace + deltaVT
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//所在的行数
|
||||
if (childPosition < itemCount - 1) {
|
||||
outRect.bottom = mVerticalInnerSpace
|
||||
}
|
||||
if (childPosition == itemCount - 1) {
|
||||
var delta = 0
|
||||
if (mExternalSpaceEndEnable) {
|
||||
delta = mVerticalExternalSpace
|
||||
}
|
||||
outRect.bottom = delta + deltaVB
|
||||
}
|
||||
} else {
|
||||
if (lp.isFullSpan) { //铺满一行
|
||||
if (!mSpanCountTBCare) {
|
||||
outRect.top = mVerticalExternalSpace + deltaVT
|
||||
outRect.bottom = mVerticalExternalSpace + deltaVB
|
||||
}
|
||||
} else {
|
||||
val averageDistance = (((spanCount - 1) * mVerticalInnerSpace + 2 * mVerticalExternalSpace + deltaVT + deltaVB) * 1.0f / spanCount).toInt()
|
||||
if (spanIndex == 0) {
|
||||
outRect.top = mVerticalExternalSpace + deltaVT
|
||||
outRect.bottom = averageDistance - outRect.top
|
||||
mLastBottom = outRect.bottom
|
||||
} else if (spanIndex == spanCount - 1) {
|
||||
outRect.top = mVerticalExternalSpace + deltaVB
|
||||
outRect.bottom = averageDistance - outRect.top
|
||||
} else {
|
||||
outRect.top = mVerticalInnerSpace - mLastBottom
|
||||
outRect.bottom = averageDistance - outRect.top
|
||||
mLastBottom = outRect.bottom
|
||||
}
|
||||
}
|
||||
if (childPosition == mFromPosition) {
|
||||
if (lp.isFullSpan) {
|
||||
if (!mSpanCountLRCare) {
|
||||
outRect.left = mHorizontalExternalSpace + deltaHL
|
||||
}
|
||||
} else {
|
||||
outRect.left = mHorizontalExternalSpace + deltaHL
|
||||
}
|
||||
} else if (childPosition == spanIndex) {
|
||||
if (!lp.isFullSpan) {
|
||||
var isPreviousViewFullSpan = false
|
||||
if (childPosition - 1 == mFromPosition) {
|
||||
val previousView = layoutManager.findViewByPosition(childPosition - 1)
|
||||
if (previousView != null && previousView.layoutParams is StaggeredGridLayoutManager.LayoutParams) {
|
||||
val lastViewParams = previousView.layoutParams as StaggeredGridLayoutManager.LayoutParams
|
||||
isPreviousViewFullSpan = lastViewParams.isFullSpan
|
||||
}
|
||||
}
|
||||
val compareValue = if (isPreviousViewFullSpan) spanCount - 1 else spanCount
|
||||
if (childPosition - mFromPosition < compareValue) {
|
||||
outRect.left = mHorizontalExternalSpace + deltaHL
|
||||
}
|
||||
}
|
||||
}
|
||||
if (childPosition < itemCount - 1) {
|
||||
outRect.right = mHorizontalInnerSpace
|
||||
}
|
||||
if (childPosition == itemCount - 1) {
|
||||
var delta = 0
|
||||
if (mExternalSpaceEndEnable) {
|
||||
delta = mHorizontalExternalSpace
|
||||
}
|
||||
outRect.right = delta + deltaHR
|
||||
}
|
||||
}
|
||||
}
|
||||
doCallHandlersOnFinally(outRect, viewType, position)
|
||||
}
|
||||
|
||||
private fun doCallHandlersOnFinally(outRect: Rect, viewType: Int, position: Int) {
|
||||
var out = outRect
|
||||
if (viewType != Int.MIN_VALUE && position != Int.MIN_VALUE && mItemDecorationHandlers != null && !mItemDecorationHandlers.isEmpty()) {
|
||||
for (handler in mItemDecorationHandlers) {
|
||||
out = handler.handle(position, viewType, out)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDraw(c: Canvas, parent: RecyclerView, state: State) {
|
||||
super.onDraw(c, parent, state)
|
||||
}
|
||||
|
||||
class Builder {
|
||||
var mHorizontalInnerSpace = 0
|
||||
var mVerticalInnerSpace = 0
|
||||
var mHorizontalExternalSpace = 0
|
||||
var mVerticalExternalSpace = 0
|
||||
var mFromPosition = 0
|
||||
var mSpanCountLRCare = true
|
||||
var mSpanCountTBCare = true
|
||||
var mHorizontalDelta: Pair<Int, Int>? = null
|
||||
var mVerticalDelta: Pair<Int, Int>? = null
|
||||
var mItemDecorationHandlers: MutableList<ItemDecorationHandler>? = null
|
||||
|
||||
/**
|
||||
* 外部间隔结束位置是否需要
|
||||
*/
|
||||
var mExternalSpaceEndEnable = true
|
||||
fun horizontalInnerSpace(horizontalInnerSpace: Int): Builder {
|
||||
mHorizontalInnerSpace = horizontalInnerSpace
|
||||
return this
|
||||
}
|
||||
|
||||
fun verticalInnerSpace(verticalInnerSpace: Int): Builder {
|
||||
mVerticalInnerSpace = verticalInnerSpace
|
||||
return this
|
||||
}
|
||||
|
||||
fun horizontalExternalSpace(horizontalExternalSpace: Int): Builder {
|
||||
mHorizontalExternalSpace = horizontalExternalSpace
|
||||
return this
|
||||
}
|
||||
|
||||
fun verticalExternalSpace(verticalExternalSpace: Int): Builder {
|
||||
mVerticalExternalSpace = verticalExternalSpace
|
||||
return this
|
||||
}
|
||||
|
||||
fun fromPosition(@IntRange(from = 0) position: Int): Builder {
|
||||
mFromPosition = position
|
||||
return this
|
||||
}
|
||||
|
||||
fun verticalDelta(delta: Pair<Int, Int>?): Builder {
|
||||
mVerticalDelta = delta
|
||||
return this
|
||||
}
|
||||
|
||||
fun horizontalDelta(delta: Pair<Int, Int>?): Builder {
|
||||
mHorizontalDelta = delta
|
||||
return this
|
||||
}
|
||||
|
||||
fun externalSpaceEnd(enable: Boolean): Builder {
|
||||
mExternalSpaceEndEnable = enable
|
||||
return this
|
||||
}
|
||||
|
||||
fun spanCountLRCare(care: Boolean): Builder {
|
||||
mSpanCountLRCare = care
|
||||
return this
|
||||
}
|
||||
|
||||
fun spanCountTBCare(care: Boolean): Builder {
|
||||
mSpanCountTBCare = care
|
||||
return this
|
||||
}
|
||||
|
||||
fun itemDecorationHandler(handler: ItemDecorationHandler): Builder {
|
||||
if (mItemDecorationHandlers == null) {
|
||||
mItemDecorationHandlers = ArrayList()
|
||||
}
|
||||
if (!mItemDecorationHandlers!!.contains(handler)) {
|
||||
mItemDecorationHandlers!!.add(handler)
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
||||
fun build(): CommonDividerItemDecoration {
|
||||
return CommonDividerItemDecoration(this)
|
||||
}
|
||||
}
|
||||
|
||||
interface ItemDecorationHandler {
|
||||
fun handle(position: Int, viewType: Int, old: Rect): Rect
|
||||
}
|
||||
|
||||
init {
|
||||
mHorizontalInnerSpace = builder.mHorizontalInnerSpace
|
||||
mVerticalInnerSpace = builder.mVerticalInnerSpace
|
||||
mHorizontalExternalSpace = builder.mHorizontalExternalSpace
|
||||
mVerticalExternalSpace = builder.mVerticalExternalSpace
|
||||
mSpanCountLRCare = builder.mSpanCountLRCare
|
||||
mSpanCountTBCare = builder.mSpanCountTBCare
|
||||
mFromPosition = builder.mFromPosition
|
||||
mHorizontalDelta = builder.mHorizontalDelta
|
||||
mVerticalDelta = builder.mVerticalDelta
|
||||
mExternalSpaceEndEnable = builder.mExternalSpaceEndEnable
|
||||
mItemDecorationHandlers = builder.mItemDecorationHandlers
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user