-
Notifications
You must be signed in to change notification settings - Fork 554
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed #117 - ViewHolder for sticky headers has to be a type of Flexib…
…leViewHolder. As consequence IHeader item interface and its Abstract implementation have now the signature changed with FlexibleViewHolder. This assure that StickyHeaderHelper will receive the correct ViewHolder type without failures. Also IExpandable item interface and its abstract implementation have ExpandableViewHolder in the signature.
- Loading branch information
Showing
12 changed files
with
217 additions
and
116 deletions.
There are no files selected for viewing
5 changes: 2 additions & 3 deletions
5
...dapter-app/src/main/java/eu/davidea/samples/flexibleadapter/models/AbstractModelItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
flexible-adapter/src/main/java/eu/davidea/viewholders/ContentViewHolder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package eu.davidea.viewholders; | ||
|
||
import android.support.v7.widget.RecyclerView; | ||
import android.view.View; | ||
import android.widget.FrameLayout; | ||
|
||
import eu.davidea.flexibleadapter.FlexibleAdapter; | ||
|
||
/** | ||
* This Class separates the initialization of an eventual StickyHeader ViewHolder from a Normal | ||
* ViewHolder. It improves code readability of FlexibleViewHolder. | ||
* | ||
* @author Davide Steduto | ||
* @since 18/06/2016 Created | ||
*/ | ||
abstract class ContentViewHolder extends RecyclerView.ViewHolder { | ||
|
||
private int mBackupPosition = RecyclerView.NO_POSITION; | ||
private View contentView; | ||
|
||
public ContentViewHolder(View view, FlexibleAdapter adapter, boolean stickyHeader) { | ||
//Since itemView is declared "final", the split is done before the View is initialized | ||
super(stickyHeader ? new FrameLayout(view.getContext()) : view); | ||
|
||
if (stickyHeader) { | ||
itemView.setLayoutParams(adapter.getRecyclerView().getLayoutManager() | ||
.generateLayoutParams(view.getLayoutParams())); | ||
((FrameLayout) itemView).addView(view);//Add View after setLayoutParams | ||
contentView = view; | ||
} | ||
} | ||
|
||
/*-----------------------*/ | ||
/* STICKY HEADER METHODS */ | ||
/*-----------------------*/ | ||
|
||
/** | ||
* In case this ViewHolder represents a Header Item, this method returns the contentView of the | ||
* FrameLayout, otherwise it returns the basic itemView. | ||
* | ||
* @return the real contentView | ||
*/ | ||
public View getContentView() { | ||
return contentView != null ? contentView : itemView; | ||
} | ||
|
||
/** | ||
* Overcomes the situation of returning an unknown position (-1) of ViewHolders created out of | ||
* the LayoutManager (ex. StickyHeaders). | ||
* <p><b>NOTE:</b> Always call this method, instead of {@code getAdapterPosition()}, in case | ||
* of StickyHeaders use case.</p> | ||
* | ||
* @return the Adapter position result of {@link #getAdapterPosition()} OR the backup position | ||
* preset and known, if the previous result was {@link RecyclerView#NO_POSITION}. | ||
* @see #setBackupPosition(int) | ||
*/ | ||
public int getFlexibleAdapterPosition() { | ||
int position = getAdapterPosition(); | ||
if (position == RecyclerView.NO_POSITION) { | ||
position = mBackupPosition; | ||
} | ||
return position; | ||
} | ||
|
||
/** | ||
* Restore the Adapter position if the original Adapter position is unknown. | ||
* <p>Called by StickyHeaderHelper to support the clickListeners events.</p> | ||
* | ||
* @param backupPosition the known position of this ViewHolder | ||
*/ | ||
public void setBackupPosition(int backupPosition) { | ||
mBackupPosition = backupPosition; | ||
} | ||
|
||
} |
Oops, something went wrong.