diff --git a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/DevaToolsProvider.kt b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/DevaToolsProvider.kt index f483cb7346..df0a033bb4 100644 --- a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/DevaToolsProvider.kt +++ b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/DevaToolsProvider.kt @@ -3,7 +3,7 @@ package com.zhjt.mogo_core_function_devatools import android.annotation.SuppressLint import android.app.Activity import android.content.Context -import android.view.View +import android.view.* import com.alibaba.android.arouter.facade.annotation.Route import com.mogo.eagle.core.data.constants.MogoServicePaths import com.mogo.eagle.core.data.deva.chain.ChainLogParam @@ -102,12 +102,12 @@ class DevaToolsProvider : IDevaToolsProvider { upgradeManager.downLoadPackage(mContext!!, downloadKey,downloadUrl) } - override fun showStatusBar(ctx: Context, anchor: View) { - StatusManager.init(ctx, anchor) - StatusManager.show() + override fun showStatusBar(ctx: Context, container: ViewGroup) { + StatusManager.init(ctx) + StatusManager.show(container) } - override fun hideStatusBar() { - StatusManager.hide() + override fun hideStatusBar(container: ViewGroup) { + StatusManager.hide(container) } } \ No newline at end of file diff --git a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/StatusManager.kt b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/StatusManager.kt index 177854b555..f9cd867849 100644 --- a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/StatusManager.kt +++ b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/StatusManager.kt @@ -1,10 +1,9 @@ +@file:Suppress("COMPATIBILITY_WARNING") + package com.zhjt.mogo_core_function_devatools.status import android.content.* import android.view.* -import android.view.WindowManager.LayoutParams -import android.widget.* -import androidx.core.view.* import androidx.lifecycle.* import androidx.lifecycle.Lifecycle.Event import androidx.lifecycle.Lifecycle.Event.ON_CREATE @@ -13,7 +12,6 @@ import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotStatusListener import com.mogo.eagle.core.function.call.autopilot.* import com.mogo.eagle.core.utilcode.kotlin.* import com.mogo.eagle.core.utilcode.util.* -import com.zhjt.mogo_core_function_devatools.ext.* import com.zhjt.mogo_core_function_devatools.status.entity.CanStatus import com.zhjt.mogo_core_function_devatools.status.entity.GpsStatus import com.zhjt.mogo_core_function_devatools.status.entity.IpcStatus @@ -29,11 +27,12 @@ import com.zhjt.mogo_core_function_devatools.status.flow.ipc.IpcImpl import com.zhjt.mogo_core_function_devatools.status.flow.nets.NetsImpl import com.zhjt.mogo_core_function_devatools.status.flow.rtk.RTKImpl import com.zhjt.mogo_core_function_devatools.status.flow.trace.TracingImpl -import com.zhjt.mogo_core_function_devatools.status.ui.* +import com.zhjt.mogo_core_function_devatools.status.ui.StatusView import kotlinx.coroutines.* import kotlinx.coroutines.flow.* import mogo_msg.MogoReportMsg -import java.lang.ref.* +import java.util.concurrent.* + object StatusManager { @@ -41,18 +40,13 @@ object StatusManager { private lateinit var model: StatusModel - private var pop: PopupWindow? = null - private var timer: Job? = null - private var context: WeakReference? = null - - private var anchor: WeakReference? = null private var hasInit = false - private var oldX = 0 - private var oldY = 0 + private val listeners by lazy { CopyOnWriteArrayList() } + private val listener = object : IMoGoAutopilotStatusListener { override fun onAutopilotGuardian(guardianInfo: MogoReportMsg.MogoReportMessage?) { @@ -93,7 +87,7 @@ object StatusManager { } } - fun init(ctx: Context, anchor: View) { + fun init(ctx: Context) { if (hasInit) { return } @@ -110,26 +104,6 @@ object StatusManager { } } }) - context = WeakReference(ctx) - anchor.viewTreeObserver.addOnGlobalLayoutListener { - anchor.getLocationInWindow(IntArray(2).also { - val currentX = it[0] - val currentY = it[1] - var changed = false - if (oldX != currentX) { - oldX = currentX - changed = true - } - if (oldY != currentY) { - changed = true - oldY = currentY - } - if (changed && pop?.isShowing == true) { - pop?.update(getOffsetX(currentX), currentY + 130.PX, -1, -1) - } - }) - } - this.anchor = WeakReference(anchor) } private fun onCreate(ctx: Context) { @@ -153,35 +127,42 @@ object StatusManager { model.update(it) } } + f.onCreate() } - } - fun show() { - val anchor = this.anchor?.get() ?: return - context?.get()?.also { ctx -> - pop?.takeIf { it.isShowing }?.dismiss() - val content = StatusView(model, ctx) - content.doOnAttach { - for (f in flows) { - f.onCreate() - } - } - val out = IntArray(2) - anchor.getLocationInWindow(out) - ctx.normalPop(content, width = LayoutParams.WRAP_CONTENT, height = LayoutParams.WRAP_CONTENT, gravity = Gravity.END or Gravity.TOP, startX = getOffsetX(out[0]), startY = out[1] + 130.PX , isFocusable = false)?.also { - pop = it + model.status.observe(ctx.lifeCycleOwner) { + listeners.forEach { itx -> + itx.onStatusChanged(it.second, it.first != null) } } } - private fun getOffsetX(anchorX: Int): Int { - return ScreenUtils.getScreenWidth() - anchorX + 40.PX + + fun registerListener(listener: IStatusListener) { + listeners.add(listener) } - fun hide() { - pop?.takeIf { it.isShowing }?.dismiss() + + fun unRegisterListener(listener: IStatusListener) { + listeners.remove(listener) } + fun show(container: ViewGroup) { + if (container.childCount > 0) { + if (container.visibility != View.VISIBLE) { + container.visibility = View.VISIBLE + } + return + } + val child = StatusView(model, container.context) + container.addView(child, ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)) + } + + fun hide(container: ViewGroup) { + container.visibility = View.GONE + } + + private fun onDestroy(ctx: Context) { hasInit = false CallerAutoPilotStatusListenerManager.removeListener(TAG) @@ -190,7 +171,12 @@ object StatusManager { flows.forEach { it.onDestroy() } + listeners.clear() flows.clear() - pop?.takeIf { it.isShowing }?.dismiss() + } + + interface IStatusListener { + + fun onStatusChanged(data: List, hasException: Boolean) } } \ No newline at end of file diff --git a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/entity/Status.kt b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/entity/Status.kt index 562722debe..ff949723fb 100644 --- a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/entity/Status.kt +++ b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/entity/Status.kt @@ -3,12 +3,12 @@ package com.zhjt.mogo_core_function_devatools.status.entity import com.zhjt.mogo_core_function_devatools.status.entity.TracingStatus.Tracing import com.zhjt.mogo_core_function_devatools.status.entity.TracingStatus.Tracing.* -internal sealed class Status +sealed class Status /** * 工控机 */ -internal class IpcStatus(val enabled: Boolean = false): Status() { +class IpcStatus(val enabled: Boolean = false): Status() { override fun equals(other: Any?): Boolean { if (javaClass != other?.javaClass) return false @@ -26,7 +26,7 @@ internal class IpcStatus(val enabled: Boolean = false): Status() { } } -internal class NetStatus(val enabled: Boolean = false, var name: String? = null, val speed: Speed? = null): Status() { +class NetStatus(val enabled: Boolean = false, var name: String? = null, val speed: Speed? = null): Status() { class Speed(val tx: Int, val rx: Int) { override fun toString(): String { @@ -56,7 +56,7 @@ internal class NetStatus(val enabled: Boolean = false, var name: String? = null, /** * android系统定位状态 */ -internal class GpsStatus(val enabled: Boolean = false, val isGranted: Boolean = false): Status() { +class GpsStatus(val enabled: Boolean = false, val isGranted: Boolean = false): Status() { override fun equals(other: Any?): Boolean { if (javaClass != other?.javaClass) return false @@ -81,7 +81,7 @@ internal class GpsStatus(val enabled: Boolean = false, val isGranted: Boolean = /** * RTK/GNSS定位状态 */ -internal class RTKStatus(var enabled: Boolean = false, var desc: String = "RTK"): Status() { +class RTKStatus(var enabled: Boolean = false, var desc: String = "RTK"): Status() { override fun equals(other: Any?): Boolean { if (javaClass != other?.javaClass) return false @@ -102,7 +102,7 @@ internal class RTKStatus(var enabled: Boolean = false, var desc: String = "RTK") /** * Can总线 */ -internal class CanStatus(var enabled: Boolean = false): Status() { +class CanStatus(var enabled: Boolean = false): Status() { override fun equals(other: Any?): Boolean { if (javaClass != other?.javaClass) return false @@ -125,7 +125,7 @@ internal class CanStatus(var enabled: Boolean = false): Status() { /** * 寻迹/算路/未知 */ -internal class TracingStatus(var state: Tracing = UNKNOWN): Status() { +class TracingStatus(var state: Tracing = UNKNOWN): Status() { enum class Tracing(val code: String? = "") { /** @@ -188,7 +188,7 @@ internal class TracingStatus(var state: Tracing = UNKNOWN): Status() { } } -internal fun String.toState(): Tracing? { +fun String.toState(): Tracing? { return when(this) { "IMAP_TRA_EXIST" -> TRACK_FINDED "IMAP_TRA_LOADED" -> TRACK_LOADED diff --git a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/ui/StatusView.kt b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/ui/StatusView.kt index 0adf523bb6..1eebcf28e9 100644 --- a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/ui/StatusView.kt +++ b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/ui/StatusView.kt @@ -5,6 +5,7 @@ import android.content.* import android.graphics.* import android.graphics.drawable.* import android.transition.* +import android.util.* import android.view.* import androidx.appcompat.widget.* import androidx.constraintlayout.widget.* @@ -42,7 +43,6 @@ internal class StatusView(private val model: StatusModel, ctx: Context): Constra } private fun init() { - isClickable = true dot.background = shape(solid = Color.parseColor("#F33F1D"), shape = GradientDrawable.OVAL, width = 30.PX, height = 30.PX) iv.also { it.background = ContextCompat.getDrawable(context, R.drawable.icon_dev_status_un_fold) @@ -59,13 +59,14 @@ internal class StatusView(private val model: StatusModel, ctx: Context): Constra moveDuration = 0 removeDuration = 0 } - itx.layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false) + itx.layoutManager = GridLayoutManager(context,4, GridLayoutManager.VERTICAL, false) itx.background = shape(solid = Color.parseColor("#80000000"), radius = 40.PX) itx.addItemDecoration( CommonDividerItemDecoration.Builder() .horizontalExternalSpace(38.PX) .verticalExternalSpace(30.PX) - .spanCountLRCare(false) + .verticalInnerSpace(20.PX) + .spanCountTBCare(false) .horizontalInnerSpace(50.PX) .build() ) @@ -90,6 +91,17 @@ internal class StatusView(private val model: StatusModel, ctx: Context): Constra } } + override fun onVisibilityChanged(changedView: View, visibility: Int) { + super.onVisibilityChanged(changedView, visibility) + if (changedView != this) { + if (visibility == View.VISIBLE) { + observer?.also { model.status.observeForever(it) } + } else { + observer?.also { model.status.removeObserver(it) } + } + } + } + private fun animate(expand: Boolean) { TransitionManager.beginDelayedTransition(this, AutoTransition().setDuration(200)) rv.visibility = if (expand) View.VISIBLE else View.INVISIBLE diff --git a/core/function-impl/mogo-core-function-devatools/src/main/res/layout/layout_status_bar.xml b/core/function-impl/mogo-core-function-devatools/src/main/res/layout/layout_status_bar.xml index baecaea7f1..ac03487212 100644 --- a/core/function-impl/mogo-core-function-devatools/src/main/res/layout/layout_status_bar.xml +++ b/core/function-impl/mogo-core-function-devatools/src/main/res/layout/layout_status_bar.xml @@ -8,13 +8,12 @@ @@ -24,7 +23,7 @@ android:layout_height="107px" android:layout_marginBottom="20px" app:layout_constraintTop_toTopOf="parent" - app:layout_constraintBottom_toBottomOf="parent" + android:layout_marginTop="12px" app:layout_constraintStart_toEndOf="@+id/rv" app:layout_constraintEnd_toEndOf="parent" android:background="@drawable/icon_dev_status_un_fold"/> diff --git a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/MoGoHmiFragment.kt b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/MoGoHmiFragment.kt index 6922a189c9..901e32a7bb 100644 --- a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/MoGoHmiFragment.kt +++ b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/MoGoHmiFragment.kt @@ -207,7 +207,7 @@ import java.util.* setProxyLimitingSpeedView(viewLimitingVelocity) setViewNotificationProvider(this) context?.also { - CallerDevaToolsManager.showStatusBar(it, vs_status_bar) + CallerDevaToolsManager.showStatusBar(it, statusBarContainer) } } @@ -1214,7 +1214,7 @@ import java.util.* } override fun showSmallFragment() { - CallerDevaToolsManager.hideStatusBar() + CallerDevaToolsManager.hideStatusBar(statusBarContainer) // 加载全览模式图层 val fragmentOverview = ARouter.getInstance().build(MoGoFragmentPaths.PATH_FRAGMENT_OVERVIEW) .navigation() as BaseFragment @@ -1229,7 +1229,7 @@ import java.util.* } override fun hideSmallFragment() { - context?.let { CallerDevaToolsManager.showStatusBar(it, vs_status_bar) } + context?.let { CallerDevaToolsManager.showStatusBar(it, statusBarContainer) } val fragmentOverview = ARouter.getInstance().build(MoGoFragmentPaths.PATH_FRAGMENT_OVERVIEW) .navigation() as BaseFragment activity?.supportFragmentManager?.beginTransaction() diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/layout/fragment_hmi.xml b/core/function-impl/mogo-core-function-hmi/src/main/res/layout/fragment_hmi.xml index ed3b74663e..64c1661753 100644 --- a/core/function-impl/mogo-core-function-hmi/src/main/res/layout/fragment_hmi.xml +++ b/core/function-impl/mogo-core-function-hmi/src/main/res/layout/fragment_hmi.xml @@ -147,6 +147,7 @@ android:layout_height="120px" android:layout_marginTop="30px" android:layout_marginEnd="40px" + android:background="@drawable/bg_waring_limiting_velocity" android:elevation="@dimen/dp_10" android:gravity="center" @@ -158,7 +159,7 @@ app:layout_constraintTop_toBottomOf="@+id/ivCameraIcon" app:layout_goneMarginEnd="40px" app:layout_goneMarginTop="40px" - tools:visibility="visible" /> + tools:visibility="gone" /> - + app:layout_goneMarginTop="30px" + app:layout_goneMarginEnd="40px"/> diff --git a/core/mogo-core-function-api/src/main/java/com/mogo/eagle/core/function/api/devatools/IDevaToolsProvider.kt b/core/mogo-core-function-api/src/main/java/com/mogo/eagle/core/function/api/devatools/IDevaToolsProvider.kt index fcbafafc21..e5328f0dec 100644 --- a/core/mogo-core-function-api/src/main/java/com/mogo/eagle/core/function/api/devatools/IDevaToolsProvider.kt +++ b/core/mogo-core-function-api/src/main/java/com/mogo/eagle/core/function/api/devatools/IDevaToolsProvider.kt @@ -2,7 +2,7 @@ package com.mogo.eagle.core.function.api.devatools import android.app.Activity import android.content.Context -import android.view.View +import android.view.* import com.alibaba.android.arouter.facade.template.IProvider import com.mogo.eagle.core.data.deva.chain.ChainLogParam import com.mogo.eagle.core.data.deva.scene.SceneModule @@ -107,10 +107,10 @@ interface IDevaToolsProvider : IProvider { /** * 展示状态栏 */ - fun showStatusBar(ctx: Context, anchor: View) + fun showStatusBar(ctx: Context, container: ViewGroup) /** * 隐藏状态栏 */ - fun hideStatusBar() + fun hideStatusBar(container: ViewGroup) } \ No newline at end of file diff --git a/core/mogo-core-function-call/src/main/java/com/mogo/eagle/core/function/call/devatools/CallerDevaToolsManager.kt b/core/mogo-core-function-call/src/main/java/com/mogo/eagle/core/function/call/devatools/CallerDevaToolsManager.kt index 509a611781..71cc263d5c 100644 --- a/core/mogo-core-function-call/src/main/java/com/mogo/eagle/core/function/call/devatools/CallerDevaToolsManager.kt +++ b/core/mogo-core-function-call/src/main/java/com/mogo/eagle/core/function/call/devatools/CallerDevaToolsManager.kt @@ -150,27 +150,18 @@ object CallerDevaToolsManager { /** * 展示状态栏 */ - fun showStatusBar(ctx: Context, anchor: View) { + fun showStatusBar(ctx: Context, container: ViewGroup) { if (!AppIdentityModeUtils.isPassenger(FunctionBuildConfig.appIdentityMode)) { - if (anchor.isLaidOut) { - devaToolsProviderApi?.showStatusBar(ctx, anchor) - } else { - anchor.viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener { - override fun onGlobalLayout() { - devaToolsProviderApi?.showStatusBar(ctx, anchor) - anchor.viewTreeObserver.removeOnGlobalLayoutListener(this) - } - }) - } + devaToolsProviderApi?.showStatusBar(ctx, container) } } /** * 隐藏状态栏 */ - fun hideStatusBar() { + fun hideStatusBar(container: ViewGroup) { if (!AppIdentityModeUtils.isPassenger(FunctionBuildConfig.appIdentityMode)) { - devaToolsProviderApi?.hideStatusBar() + devaToolsProviderApi?.hideStatusBar(container) } } } \ No newline at end of file diff --git a/core/mogo-core-utils/src/main/java/com/mogo/eagle/core/utilcode/rv/divider/CommonDividerItemDecoration.kt b/core/mogo-core-utils/src/main/java/com/mogo/eagle/core/utilcode/rv/divider/CommonDividerItemDecoration.kt index 62a5dfd1d2..f1234c0b90 100644 --- a/core/mogo-core-utils/src/main/java/com/mogo/eagle/core/utilcode/rv/divider/CommonDividerItemDecoration.kt +++ b/core/mogo-core-utils/src/main/java/com/mogo/eagle/core/utilcode/rv/divider/CommonDividerItemDecoration.kt @@ -31,12 +31,15 @@ class CommonDividerItemDecoration internal constructor(builder: Builder) : ItemD 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? = null private var mVerticalDelta: Pair? = null + private var mRightCache: HashMap = HashMap() + private var mLeftCache: HashMap = HashMap() + private var mBottomCache: HashMap = HashMap() + private var mTopCache: HashMap = HashMap() + /** * 外部间隔结束位置是否需要 */ @@ -84,23 +87,28 @@ class CommonDividerItemDecoration internal constructor(builder: Builder) : ItemD } } else { val averageDistance = (((spanCount - 1) * mHorizontalInnerSpace + 2 * mHorizontalExternalSpace + deltaHL + deltaHR) * 1.0f / spanCount).toInt() - Log.d("UUUU", "step::0::$averageDistance: lastRight: $mLastRight : state: $state " ) if (spanIndex == 0) { outRect.left = mHorizontalExternalSpace + deltaHL outRect.right = averageDistance - outRect.left - mLastRight = outRect.right - Log.d("UUUU", "step::1::$averageDistance: lastRight: $mLastRight" ) + if (state.didStructureChange()) { + mRightCache[position] = outRect.right + } + Log.d("UUUU", "step::1::$averageDistance: outRect.right: ${outRect.right} ::outRect.left: ${outRect.left}:: position: $position :: state: $state" ) } else if (spanIndex == spanCount - 1) { outRect.right = mHorizontalExternalSpace + deltaHR outRect.left = averageDistance - outRect.right - Log.d("UUUU", "step::2::$averageDistance: lastRight: $mLastRight ::outRect.left: ${outRect.left}" ) + Log.d("UUUU", "step::2::$averageDistance: outRect.right: ${outRect.right} ::outRect.left: ${outRect.left} :: position: $position :: state: $state" ) } else { - outRect.left = mHorizontalInnerSpace - mLastRight - outRect.right = averageDistance - outRect.left if (state.didStructureChange()) { - mLastRight = outRect.right + outRect.left = mHorizontalInnerSpace - (mRightCache[position - 1] ?: 0) + outRect.right = averageDistance - outRect.left + mLeftCache[position] = outRect.left + mRightCache[position] = outRect.right + } else { + outRect.left = mLeftCache[position]!! + outRect.right = mRightCache[position]!! } - Log.d("UUUU", "step::2::$averageDistance: lastRight: $mLastRight ::outRect.left: ${outRect.left}" ) + Log.d("UUUU", "step::2::$averageDistance: outRect.right: ${outRect.right} ::outRect.left: ${outRect.left} :: position: $position :: state: $state" ) } } //所在的行数 if (lookUp.getSpanGroupIndex(childPosition, spanCount) == lookUp.getSpanGroupIndex(mFromPosition, spanCount)) { @@ -130,15 +138,21 @@ class CommonDividerItemDecoration internal constructor(builder: Builder) : ItemD if (spanIndex == 0) { outRect.top = mVerticalExternalSpace + deltaVT outRect.bottom = averageDistance - outRect.top - mLastBottom = outRect.bottom + if (state.didStructureChange()) { + mBottomCache[position] = 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 if (state.didStructureChange()) { - mLastBottom = outRect.bottom + outRect.top = mVerticalInnerSpace - (mBottomCache[position - 1] ?: 0 ) + outRect.bottom = averageDistance - outRect.top + mBottomCache[position] = outRect.bottom + mTopCache[position] = outRect.top + } else { + outRect.top = mTopCache[position]!! + outRect.bottom = mBottomCache[position]!! } } } @@ -223,15 +237,21 @@ class CommonDividerItemDecoration internal constructor(builder: Builder) : ItemD if (spanIndex == 0) { outRect.left = mHorizontalExternalSpace + deltaHL outRect.right = averageDistance - outRect.left - mLastRight = outRect.right + if (state.didStructureChange()) { + mRightCache[position] = 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 if (state.didStructureChange()) { - mLastRight = outRect.right + outRect.left = mHorizontalInnerSpace - (mRightCache[position - 1] ?: 0) + outRect.right = averageDistance - outRect.left + mLeftCache[position] = outRect.left + mRightCache[position] = outRect.right + } else { + outRect.left = mLeftCache[position]!! + outRect.right = mRightCache[position]!! } } } @@ -282,15 +302,22 @@ class CommonDividerItemDecoration internal constructor(builder: Builder) : ItemD if (spanIndex == 0) { outRect.top = mVerticalExternalSpace + deltaVT outRect.bottom = averageDistance - outRect.top - mLastBottom = outRect.bottom + if (state.didStructureChange()) { + mBottomCache[position] = 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 + if (state.didStructureChange()) { - mLastBottom = outRect.bottom + outRect.top = mVerticalInnerSpace - (mBottomCache[position - 1] ?: 0) + outRect.bottom = averageDistance - outRect.top + mBottomCache[position] = outRect.bottom + mTopCache[position] = outRect.top + } else { + outRect.top = mTopCache[position]!! + outRect.bottom = mBottomCache[position]!! } } }