Get updated BetterLinearLayoutManager to compile again

Change-Id: I93ec0f70defddd0f5df9e50909dfbc591f9bce11
This commit is contained in:
SpiritCroc 2022-09-29 14:19:23 +02:00
parent 4b32e30cff
commit 1b8d2d2e4f
3 changed files with 53 additions and 9 deletions

View File

@ -0,0 +1,25 @@
package de.spiritcroc.recyclerview.widget
import android.content.Context
import android.util.AttributeSet
import androidx.recyclerview.widget.RecyclerView
/**
* A recyclerview to use with BetterLinearLayoutManager.
* Exposes some things that androidx' LinearLayoutManager would use but is package-private in androidx' RecyclerView.
*/
class BLLRecyclerView : RecyclerView {
constructor(context: Context): super(context)
constructor(context: Context, attrs: AttributeSet?): super(context, attrs)
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int): super(context, attrs, defStyleAttr)
override fun onMeasure(widthSpec: Int, heightSpec: Int) {
super.onMeasure(widthSpec, heightSpec)
(layoutManager as? BetterLinearLayoutManager)?.setPreviousMeasure(measuredWidth, measuredHeight)
}
override fun setLayoutManager(layout: LayoutManager?) {
super.setLayoutManager(layout)
(layoutManager as? BetterLinearLayoutManager)?.setIsBLLRecyclerView()
}
}

View File

@ -258,6 +258,18 @@ public class BetterLinearLayoutManager extends LinearLayoutManager implements
return true;
}
// Moved from androidx' State in RecyclerView.java, so we can access it
private int mPreviousMeasuredWidth = 0;
private int mPreviousMeasuredHeight = 0;
private boolean isBLLRecyclerView = false;
public void setPreviousMeasure(int width, int height) {
mPreviousMeasuredWidth = width;
mPreviousMeasuredHeight = height;
}
public void setIsBLLRecyclerView() {
isBLLRecyclerView = true;
}
/**
* {@inheritDoc}
*/
@ -646,15 +658,22 @@ public class BetterLinearLayoutManager extends LinearLayoutManager implements
// The 2 booleans below are necessary because if we are laying out from the end, and the
// previous measured dimension is different from the new measured value, then any
// previously calculated anchor will be incorrect.
boolean reCalcAnchorDueToVertical = layoutFromEnd
&& getOrientation() == RecyclerView.VERTICAL
&& state.getPreviousMeasuredHeight() != getHeight();
boolean reCalcAnchorDueToHorizontal = layoutFromEnd
&& getOrientation() == RecyclerView.HORIZONTAL
&& state.getPreviousMeasuredWidth() != getWidth();
boolean reCalcAnchor;
if (isBLLRecyclerView) {
boolean reCalcAnchorDueToVertical = layoutFromEnd
&& getOrientation() == RecyclerView.VERTICAL
&& /*state.getPreviousMeasuredHeight()*/ mPreviousMeasuredHeight != getHeight();
boolean reCalcAnchorDueToHorizontal = layoutFromEnd
&& getOrientation() == RecyclerView.HORIZONTAL
&& /*state.getPreviousMeasuredWidth()*/ mPreviousMeasuredWidth != getWidth();
boolean reCalcAnchor = reCalcAnchorDueToVertical || reCalcAnchorDueToHorizontal
|| mPendingScrollPosition != RecyclerView.NO_POSITION || mPendingSavedState != null;
reCalcAnchor = reCalcAnchorDueToVertical || reCalcAnchorDueToHorizontal
|| mPendingScrollPosition != RecyclerView.NO_POSITION || mPendingSavedState != null;
} else {
Timber.w("Using legacy layouting method without BLLRecyclerView");
// Legacy fallback for 0815 RecyclerViews without exposed previous measured width/height
reCalcAnchor = mPendingScrollPosition != RecyclerView.NO_POSITION || mPendingSavedState != null;
}
final View focused = getFocusedChild();
if (!mAnchorInfo.mValid || reCalcAnchor) {

View File

@ -79,7 +79,7 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/liveLocationStatusIndicator" />
<androidx.recyclerview.widget.RecyclerView
<de.spiritcroc.recyclerview.widget.BLLRecyclerView
android:id="@+id/timelineRecyclerView"
android:layout_width="0dp"
android:layout_height="0dp"