Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Commit

Permalink
fix a different header height issue
Browse files Browse the repository at this point in the history
  • Loading branch information
shuhart committed Apr 3, 2018
1 parent 2ed7e86 commit 2fe8104
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 22 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Usage
-----

1. Add jcenter() to repositories block in your gradle file.
2. Add `implementation 'com.shuhart.stickyheader:stickyheader:1.0.2` to your dependencies.
2. Add `implementation 'com.shuhart.stickyheader:stickyheader:1.0.3` to your dependencies.
3. Look into the sample for additional details on how to use and configure the library.

You should provide an adapter that extends [StickyAdapter](https://github.com/shuhart/StickyHeader/blob/master/stickyheader/src/main/java/com/shuhart/stickyheader/StickyAdapter.java) to the StickyHeaderItemDecorator that is used to create and bind sticky headers.
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.android.tools.build:gradle:3.1.0'


// NOTE: Do not place your application dependencies here; they belong
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Fri Feb 16 16:06:40 ALMT 2018
#Tue Apr 03 14:19:21 ALMT 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.shuhart.stickyheader;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.ViewGroup;

public class BigSectionAdapter extends SectionAdapter {
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
if (viewType == Section.HEADER) {
RecyclerView.ViewHolder holder =
new HeaderViewholder(inflater.inflate(R.layout.recycler_view_header_item, parent, false));
ViewGroup.LayoutParams lp = holder.itemView.getLayoutParams();
lp.height = lp.height * 2;
holder.itemView.setLayoutParams(lp);
return holder;
}
return super.onCreateViewHolder(parent, viewType);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.shuhart.stickyheader;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;

public class SmallSectionAdapter extends SectionAdapter {
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
if (viewType == Section.HEADER) {
RecyclerView.ViewHolder holder =
new HeaderViewholder(inflater.inflate(R.layout.recycler_view_header_item, parent, false));
ViewGroup.LayoutParams lp = holder.itemView.getLayoutParams();
lp.height = lp.height / 2;
holder.itemView.setLayoutParams(lp);
return holder;
}
return super.onCreateViewHolder(parent, viewType);
}
}
2 changes: 1 addition & 1 deletion stickyheader/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ ext {
siteUrl = 'https://github.com/shuhart/StickyHeader'
gitUrl = 'https://github.com/shuhart/StickyHeader.git'

libraryVersion = '1.0.2'
libraryVersion = '1.0.3'

developerId = 'shuhart'
developerName = 'Redrick Shuhart'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,28 +66,18 @@ public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state)
return;
}

RecyclerView.ViewHolder viewHolder = parent.findViewHolderForAdapterPosition(topChildPosition);
if (viewHolder == null || viewHolder.itemView.getLayoutParams().width == 0) {
View viewOverlappedByHeader = getChildInContact(parent, currentStickyHolder.itemView.getBottom());
if (viewOverlappedByHeader == null) {
return;
}

int contactPoint = viewHolder.itemView.getBottom();
View childInContact = getChildInContact(parent, contactPoint);
if (childInContact == null) {
return;
}

int childPosition = parent.getChildAdapterPosition(childInContact);

if (adapter.getHeaderPositionForItem(childPosition) == childPosition) {
updateStickyHeader(topChildPosition, childPosition);
moveHeader(c, childInContact);
return;
int overlappedByHeaderPosition = parent.getChildAdapterPosition(viewOverlappedByHeader);
if (adapter.getHeaderPositionForItem(overlappedByHeaderPosition) == overlappedByHeaderPosition) {
updateStickyHeader(topChildPosition, overlappedByHeaderPosition);
moveHeader(c, viewOverlappedByHeader);
} else {
updateStickyHeader(topChildPosition, RecyclerView.NO_POSITION);
drawHeader(c);
}

drawHeader(c);
}

@SuppressWarnings("unchecked")
Expand Down

0 comments on commit 2fe8104

Please sign in to comment.