use of eu.davidea.samples.flexibleadapter.items.ScrollableLayoutItem in project FlexibleAdapter by davideas.
the class OverallAdapter method showLayoutInfo.
/*
* HEADER/FOOTER VIEW
* This method show how to add Header/Footer View as it was for ListView.
* The secret is the position! 0 for Header; itemCount for Footer ;-)
* The view is represented by a custom Item type to better represent any dynamic content.
*/
public void showLayoutInfo(boolean scrollToPosition) {
if (!hasSearchText()) {
//Define Example View
final ScrollableLayoutItem item = new ScrollableLayoutItem("LAY-L");
if (mRecyclerView.getLayoutManager() instanceof StaggeredGridLayoutManager) {
item.setId("LAY-S");
item.setTitle(mRecyclerView.getContext().getString(R.string.staggered_layout));
} else if (mRecyclerView.getLayoutManager() instanceof GridLayoutManager) {
item.setId("LAY-G");
item.setTitle(mRecyclerView.getContext().getString(R.string.grid_layout));
} else {
item.setTitle(mRecyclerView.getContext().getString(R.string.linear_layout));
}
item.setSubtitle(mRecyclerView.getContext().getString(R.string.columns, String.valueOf(eu.davidea.flexibleadapter.utils.Utils.getSpanCount(mRecyclerView.getLayoutManager()))));
addScrollableHeaderWithDelay(item, 500L, scrollToPosition);
removeScrollableHeaderWithDelay(item, 3000L);
}
}
use of eu.davidea.samples.flexibleadapter.items.ScrollableLayoutItem in project FlexibleAdapter by davideas.
the class ExampleAdapter method showLayoutInfo.
/*
* HEADER VIEW
* This method shows how to add Header View as it was for ListView.
* Same Header item is enqueued for removal with a delay.
* The view is represented by a custom Item type to better represent any dynamic content.
*/
public void showLayoutInfo(boolean scrollToPosition) {
if (!hasSearchText()) {
final ScrollableLayoutItem item = new ScrollableLayoutItem("LAY-L");
if (mRecyclerView.getLayoutManager() instanceof StaggeredGridLayoutManager) {
item.setId("LAY-S");
item.setTitle(mRecyclerView.getContext().getString(R.string.staggered_layout));
} else if (mRecyclerView.getLayoutManager() instanceof GridLayoutManager) {
item.setId("LAY-G");
item.setTitle(mRecyclerView.getContext().getString(R.string.grid_layout));
} else {
item.setTitle(mRecyclerView.getContext().getString(R.string.linear_layout));
}
item.setSubtitle(mRecyclerView.getContext().getString(R.string.columns, String.valueOf(Utils.getSpanCount(mRecyclerView.getLayoutManager()))));
// NOTE: If you have to change at runtime the LayoutManager AND add
// Scrollable Headers, consider to add them in post, using a delay >= 0
// otherwise scroll animations on all items will not start correctly.
addScrollableHeaderWithDelay(item, 1200L, scrollToPosition);
removeScrollableHeaderWithDelay(item, 4000L);
}
}
use of eu.davidea.samples.flexibleadapter.items.ScrollableLayoutItem in project FlexibleAdapter by davideas.
the class OverallAdapter method onBindViewHolder.
/**
* METHOD A - NEW! Via Model objects. In this case you don't need to implement this method!
* METHOD B - You override and implement this method as you prefer (don't call super).
*
* Using Method B, some methods need to be called by the user, see bottom of this method!
*/
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position, List payload) {
int viewType = getItemViewType(position);
Context context = holder.itemView.getContext();
if (viewType == R.layout.recycler_scrollable_usecase_item) {
ScrollableUseCaseItem item = (ScrollableUseCaseItem) getItem(position);
ScrollableUseCaseItem.UCViewHolder vHolder = (ScrollableUseCaseItem.UCViewHolder) holder;
assert item != null;
DrawableUtils.setBackgroundCompat(holder.itemView, DrawableUtils.getRippleDrawable(DrawableUtils.getColorDrawable(context.getResources().getColor(R.color.material_color_blue_grey_50)), DrawableUtils.getColorControlHighlight(context)));
vHolder.mTitle.setText(Utils.fromHtmlCompat(item.getTitle()));
vHolder.mSubtitle.setText(Utils.fromHtmlCompat(item.getSubtitle()));
//Support for StaggeredGridLayoutManager
if (holder.itemView.getLayoutParams() instanceof StaggeredGridLayoutManager.LayoutParams) {
((StaggeredGridLayoutManager.LayoutParams) holder.itemView.getLayoutParams()).setFullSpan(true);
Log.d("LayoutItem", "LayoutItem configured fullSpan for StaggeredGridLayout");
}
} else if (viewType == R.layout.recycler_scrollable_layout_item) {
ScrollableLayoutItem item = (ScrollableLayoutItem) getItem(position);
ScrollableLayoutItem.LayoutViewHolder vHolder = (ScrollableLayoutItem.LayoutViewHolder) holder;
assert item != null;
//For marquee
vHolder.mTitle.setSelected(true);
vHolder.mTitle.setText(item.getTitle());
vHolder.mSubtitle.setText(item.getSubtitle());
//Support for StaggeredGridLayoutManager
if (holder.itemView.getLayoutParams() instanceof StaggeredGridLayoutManager.LayoutParams) {
((StaggeredGridLayoutManager.LayoutParams) holder.itemView.getLayoutParams()).setFullSpan(true);
Log.d("LayoutItem", "LayoutItem configured fullSpan for StaggeredGridLayout");
}
} else if (viewType == R.layout.recycler_overall_item) {
OverallItem item = (OverallItem) getItem(position);
OverallItem.LabelViewHolder vHolder = (OverallItem.LabelViewHolder) holder;
assert item != null;
if (item.getTitle() != null) {
vHolder.mTitle.setText(item.getTitle());
vHolder.mTitle.setEnabled(isEnabled(position));
}
if (item.getDescription() != null) {
vHolder.mSubtitle.setText(Utils.fromHtmlCompat(item.getDescription()));
vHolder.mSubtitle.setEnabled(isEnabled(position));
}
if (item.getIcon() != null) {
vHolder.mIcon.setImageDrawable(item.getIcon());
}
}
// IMPORTANT!!!
// With method B, animateView() needs to be called by the user!
// With method A, the call is handled by the Adapter
animateView(holder, position);
// Same concept for EndlessScrolling and View activation:
// - onLoadMore(position);
// - holder.itemView.setActivated(isSelected(position));
}
Aggregations