mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-24 16:57:50 +00:00
Fix StickyHeader measuring.
It didn't re-measure when pulling an item from the cache, screwing stuff up after a phone rotation. Had a workaround for it for specific screens, but this fixes the problem at the source. Fixes #8583
This commit is contained in:
parent
c9a0a66f18
commit
a3768c7d74
@ -121,16 +121,6 @@ public class SearchFragment extends Fragment implements SearchListAdapter.EventL
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onConfigurationChanged(Configuration newConfig) {
|
|
||||||
super.onConfigurationChanged(newConfig);
|
|
||||||
|
|
||||||
if (listDecoration != null) {
|
|
||||||
listDecoration.invalidateLayouts();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onConversationClicked(@NonNull ThreadRecord threadRecord) {
|
public void onConversationClicked(@NonNull ThreadRecord threadRecord) {
|
||||||
ConversationListActivity conversationList = (ConversationListActivity) getActivity();
|
ConversationListActivity conversationList = (ConversationListActivity) getActivity();
|
||||||
|
@ -76,30 +76,30 @@ public class StickyHeaderDecoration extends RecyclerView.ItemDecoration {
|
|||||||
protected ViewHolder getHeader(RecyclerView parent, StickyHeaderAdapter adapter, int position) {
|
protected ViewHolder getHeader(RecyclerView parent, StickyHeaderAdapter adapter, int position) {
|
||||||
final long key = adapter.getHeaderId(position);
|
final long key = adapter.getHeaderId(position);
|
||||||
|
|
||||||
if (headerCache.containsKey(key)) {
|
ViewHolder headerHolder = headerCache.get(key);
|
||||||
return headerCache.get(key);
|
if (headerHolder == null) {
|
||||||
} else {
|
headerHolder = adapter.onCreateHeaderViewHolder(parent);
|
||||||
final ViewHolder holder = adapter.onCreateHeaderViewHolder(parent);
|
|
||||||
final View header = holder.itemView;
|
|
||||||
|
|
||||||
//noinspection unchecked
|
//noinspection unchecked
|
||||||
adapter.onBindHeaderViewHolder(holder, position);
|
adapter.onBindHeaderViewHolder(headerHolder, position);
|
||||||
|
|
||||||
int widthSpec = View.MeasureSpec.makeMeasureSpec(parent.getWidth(), View.MeasureSpec.EXACTLY);
|
headerCache.put(key, headerHolder);
|
||||||
int heightSpec = View.MeasureSpec.makeMeasureSpec(parent.getHeight(), View.MeasureSpec.UNSPECIFIED);
|
|
||||||
|
|
||||||
int childWidth = ViewGroup.getChildMeasureSpec(widthSpec,
|
|
||||||
parent.getPaddingLeft() + parent.getPaddingRight(), header.getLayoutParams().width);
|
|
||||||
int childHeight = ViewGroup.getChildMeasureSpec(heightSpec,
|
|
||||||
parent.getPaddingTop() + parent.getPaddingBottom(), header.getLayoutParams().height);
|
|
||||||
|
|
||||||
header.measure(childWidth, childHeight);
|
|
||||||
header.layout(0, 0, header.getMeasuredWidth(), header.getMeasuredHeight());
|
|
||||||
|
|
||||||
headerCache.put(key, holder);
|
|
||||||
|
|
||||||
return holder;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final View header = headerHolder.itemView;
|
||||||
|
|
||||||
|
int widthSpec = View.MeasureSpec.makeMeasureSpec(parent.getWidth(), View.MeasureSpec.EXACTLY);
|
||||||
|
int heightSpec = View.MeasureSpec.makeMeasureSpec(parent.getHeight(), View.MeasureSpec.UNSPECIFIED);
|
||||||
|
|
||||||
|
int childWidth = ViewGroup.getChildMeasureSpec(widthSpec,
|
||||||
|
parent.getPaddingLeft() + parent.getPaddingRight(), header.getLayoutParams().width);
|
||||||
|
int childHeight = ViewGroup.getChildMeasureSpec(heightSpec,
|
||||||
|
parent.getPaddingTop() + parent.getPaddingBottom(), header.getLayoutParams().height);
|
||||||
|
|
||||||
|
header.measure(childWidth, childHeight);
|
||||||
|
header.layout(0, 0, header.getMeasuredWidth(), header.getMeasuredHeight());
|
||||||
|
|
||||||
|
return headerHolder;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -180,10 +180,6 @@ public class StickyHeaderDecoration extends RecyclerView.ItemDecoration {
|
|||||||
((LinearLayoutManager)parent.getLayoutManager()).getReverseLayout();
|
((LinearLayoutManager)parent.getLayoutManager()).getReverseLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void invalidateLayouts() {
|
|
||||||
headerCache.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The adapter to assist the {@link StickyHeaderDecoration} in creating and binding the header views.
|
* The adapter to assist the {@link StickyHeaderDecoration} in creating and binding the header views.
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user