Don't calculate date header item for adapter header

Fixes #6098
// FREEBIE
This commit is contained in:
Moxie Marlinspike 2017-01-25 18:00:26 -08:00
parent d46d3b72c8
commit 15a389c171
5 changed files with 25 additions and 15 deletions

View File

@ -6,6 +6,13 @@
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"> xmlns:tools="http://schemas.android.com/tools">
<android.support.v7.widget.RecyclerView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
android:cacheColorHint="?conversation_background" />
<TextView android:id="@+id/scroll_date_header" <TextView android:id="@+id/scroll_date_header"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -22,13 +29,6 @@
android:visibility="gone" android:visibility="gone"
tools:text="March 1, 2015" /> tools:text="March 1, 2015" />
<android.support.v7.widget.RecyclerView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
android:cacheColorHint="?conversation_background" />
<View android:id="@+id/compose_divider" <View android:id="@+id/compose_divider"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="2dp" android:layout_height="2dp"

View File

@ -289,6 +289,9 @@ public class ConversationAdapter <V extends View & BindableConversationItem>
@Override @Override
public long getHeaderId(int position) { public long getHeaderId(int position) {
if (!isActiveCursor()) return -1; if (!isActiveCursor()) return -1;
if (isHeaderPosition(position)) return -1;
if (isFooterPosition(position)) return -1;
if (position >= getItemCount()) return -1;
Cursor cursor = getCursorAtPositionOrThrow(position); Cursor cursor = getCursorAtPositionOrThrow(position);
MessageRecord record = getMessageRecord(cursor); MessageRecord record = getMessageRecord(cursor);

View File

@ -488,7 +488,9 @@ public class ConversationFragment extends Fragment
} }
private void bindScrollHeader(HeaderViewHolder headerViewHolder, int positionId) { private void bindScrollHeader(HeaderViewHolder headerViewHolder, int positionId) {
((ConversationAdapter)list.getAdapter()).onBindHeaderViewHolder(headerViewHolder, positionId); if (((ConversationAdapter)list.getAdapter()).getHeaderId(positionId) != -1) {
((ConversationAdapter) list.getAdapter()).onBindHeaderViewHolder(headerViewHolder, positionId);
}
} }
} }

View File

@ -187,11 +187,11 @@ public abstract class CursorRecyclerViewAdapter<VH extends RecyclerView.ViewHold
return valid && cursor != null; return valid && cursor != null;
} }
private boolean isFooterPosition(int position) { protected boolean isFooterPosition(int position) {
return hasFooterView() && position == getItemCount() - 1; return hasFooterView() && position == getItemCount() - 1;
} }
private boolean isHeaderPosition(int position) { protected boolean isHeaderPosition(int position) {
return hasHeaderView() && position == 0; return hasHeaderView() && position == 0;
} }

View File

@ -7,6 +7,7 @@ import android.support.v4.view.ViewCompat;
import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.ViewHolder; import android.support.v7.widget.RecyclerView.ViewHolder;
import android.util.Log;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -58,15 +59,19 @@ public class StickyHeaderDecoration extends RecyclerView.ItemDecoration {
private boolean hasHeader(RecyclerView parent, StickyHeaderAdapter adapter, int adapterPos) { private boolean hasHeader(RecyclerView parent, StickyHeaderAdapter adapter, int adapterPos) {
boolean isReverse = isReverseLayout(parent); boolean isReverse = isReverseLayout(parent);
int itemCount = ((RecyclerView.Adapter)adapter).getItemCount();
if (isReverse && adapterPos == ((RecyclerView.Adapter)adapter).getItemCount() - 1 || !isReverse && adapterPos == 0) { if ((isReverse && adapterPos == itemCount - 1 && adapter.getHeaderId(adapterPos) != -1) ||
(!isReverse && adapterPos == 0))
{
return true; return true;
} }
int previous = adapterPos + (isReverse ? 1 : -1); int previous = adapterPos + (isReverse ? 1 : -1);
long headerId = adapter.getHeaderId(adapterPos); long headerId = adapter.getHeaderId(adapterPos);
long previousHeaderId = adapter.getHeaderId(previous);
return headerId != NO_HEADER_ID && (headerId != adapter.getHeaderId(previous)); return headerId != NO_HEADER_ID && previousHeaderId != NO_HEADER_ID && headerId != previousHeaderId;
} }
private ViewHolder getHeader(RecyclerView parent, StickyHeaderAdapter adapter, int position) { private ViewHolder getHeader(RecyclerView parent, StickyHeaderAdapter adapter, int position) {