use of android.support.v7.widget.RecyclerView.Adapter in project MaterialDrawer by mikepenz.
the class DrawerBuilder method createContent.
/**
* the helper method to create the content for the drawer
*/
private void createContent() {
//if we have a customView use this
if (mCustomView != null) {
LinearLayout.LayoutParams contentParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
contentParams.weight = 1f;
mSliderLayout.addView(mCustomView, contentParams);
return;
}
//set the shadow for the drawer
if (Build.VERSION.SDK_INT < 21 && mDrawerLayout != null) {
if (ViewCompat.getLayoutDirection(mRootView) == ViewCompat.LAYOUT_DIRECTION_LTR) {
mDrawerLayout.setDrawerShadow(mDrawerGravity == GravityCompat.START ? R.drawable.material_drawer_shadow_right : R.drawable.material_drawer_shadow_left, mDrawerGravity);
} else {
mDrawerLayout.setDrawerShadow(mDrawerGravity == GravityCompat.START ? R.drawable.material_drawer_shadow_left : R.drawable.material_drawer_shadow_right, mDrawerGravity);
}
}
// if we have an adapter (either by defining a custom one or the included one add a list :D
View contentView;
if (mRecyclerView == null) {
contentView = LayoutInflater.from(mActivity).inflate(R.layout.material_drawer_recycler_view, mSliderLayout, false);
mRecyclerView = (RecyclerView) contentView.findViewById(R.id.material_drawer_recycler_view);
//set the itemAnimator
mRecyclerView.setItemAnimator(mItemAnimator);
//some style improvements on older devices
mRecyclerView.setFadingEdgeLength(0);
//set the drawing cache background to the same color as the slider to improve performance
//mRecyclerView.setDrawingCacheBackgroundColor(UIUtils.getThemeColorFromAttrOrRes(mActivity, R.attr.material_drawer_background, R.color.material_drawer_background));
mRecyclerView.setClipToPadding(false);
//additional stuff
mRecyclerView.setLayoutManager(mLayoutManager);
int paddingTop = 0;
if ((mDisplayBelowStatusBar == null || mDisplayBelowStatusBar) && !mSystemUIHidden) {
paddingTop = UIUtils.getStatusBarHeight(mActivity);
}
int paddingBottom = 0;
int orientation = mActivity.getResources().getConfiguration().orientation;
if (((mTranslucentNavigationBar || mFullscreen) && Build.VERSION.SDK_INT >= 21) && !mSystemUIHidden && (orientation == Configuration.ORIENTATION_PORTRAIT || (orientation == Configuration.ORIENTATION_LANDSCAPE && DrawerUIUtils.isSystemBarOnBottom(mActivity)))) {
paddingBottom = UIUtils.getNavigationBarHeight(mActivity);
}
mRecyclerView.setPadding(0, paddingTop, 0, paddingBottom);
} else {
contentView = mRecyclerView;
}
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
params.weight = 1f;
mSliderLayout.addView(contentView, params);
if (mInnerShadow) {
View innerShadow = mSliderLayout.findViewById(R.id.material_drawer_inner_shadow);
innerShadow.setVisibility(View.VISIBLE);
innerShadow.bringToFront();
if (mDrawerGravity == GravityCompat.START) {
innerShadow.setBackgroundResource(R.drawable.material_drawer_shadow_left);
} else {
innerShadow.setBackgroundResource(R.drawable.material_drawer_shadow_right);
}
}
// set the background
if (mSliderBackgroundColor != 0) {
mSliderLayout.setBackgroundColor(mSliderBackgroundColor);
} else if (mSliderBackgroundColorRes != -1) {
mSliderLayout.setBackgroundColor(ContextCompat.getColor(mActivity, mSliderBackgroundColorRes));
} else if (mSliderBackgroundDrawable != null) {
UIUtils.setBackground(mSliderLayout, mSliderBackgroundDrawable);
} else if (mSliderBackgroundDrawableRes != -1) {
UIUtils.setBackground(mSliderLayout, mSliderBackgroundDrawableRes);
}
//handle the header
DrawerUtils.handleHeaderView(this);
//handle the footer
DrawerUtils.handleFooterView(this, new View.OnClickListener() {
@Override
public void onClick(View v) {
IDrawerItem drawerItem = (IDrawerItem) v.getTag();
DrawerUtils.onFooterDrawerItemClick(DrawerBuilder.this, drawerItem, v, true);
}
});
//if MultiSelect is possible
mAdapter.withMultiSelect(mMultiSelect);
if (mMultiSelect) {
mAdapter.withSelectOnLongClick(false);
mAdapter.withAllowDeselection(true);
}
//set the adapter on the listView
if (mAdapterWrapper == null) {
mRecyclerView.setAdapter(mAdapter);
} else {
mRecyclerView.setAdapter(mAdapterWrapper);
}
//predefine selection (should be the first element
if (mSelectedItemPosition == 0 && mSelectedItemIdentifier != 0L) {
mSelectedItemPosition = DrawerUtils.getPositionByIdentifier(this, mSelectedItemIdentifier);
}
if (mHeaderView != null && mSelectedItemPosition == 0) {
mSelectedItemPosition = 1;
}
mAdapter.deselect();
mAdapter.select(mSelectedItemPosition);
// add the onDrawerItemClickListener if set
mAdapter.withOnClickListener(new FastAdapter.OnClickListener<IDrawerItem>() {
@Override
public boolean onClick(final View view, IAdapter<IDrawerItem> adapter, final IDrawerItem item, final int position) {
if (!(item != null && item instanceof Selectable && !item.isSelectable())) {
resetStickyFooterSelection();
mCurrentStickyFooterSelection = -1;
}
//call the listener
boolean consumed = false;
//call the item specific listener
if (item instanceof AbstractDrawerItem && ((AbstractDrawerItem) item).getOnDrawerItemClickListener() != null) {
consumed = ((AbstractDrawerItem) item).getOnDrawerItemClickListener().onItemClick(view, position, item);
}
//call the drawer listener
if (mOnDrawerItemClickListener != null) {
if (mDelayDrawerClickEvent > 0) {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
mOnDrawerItemClickListener.onItemClick(view, position, item);
}
}, mDelayDrawerClickEvent);
} else {
consumed = mOnDrawerItemClickListener.onItemClick(view, position, item);
}
}
//we have to notify the miniDrawer if existing, and if the event was not consumed yet
if (!consumed && mMiniDrawer != null) {
consumed = mMiniDrawer.onItemClick(item);
}
//if we were a expandable item we consume the event closing makes no sense
if (item instanceof IExpandable && ((IExpandable) item).getSubItems() != null) {
//we consume the event and want no further handling
return true;
}
if (!consumed) {
//close the drawer after click
closeDrawerDelayed();
}
return consumed;
}
});
// add the onDrawerItemLongClickListener if set
mAdapter.withOnLongClickListener(new FastAdapter.OnLongClickListener<IDrawerItem>() {
@Override
public boolean onLongClick(View view, IAdapter<IDrawerItem> adapter, final IDrawerItem item, final int position) {
if (mOnDrawerItemLongClickListener != null) {
return mOnDrawerItemLongClickListener.onItemLongClick(view, position, getDrawerItem(position));
}
return false;
}
});
if (mRecyclerView != null) {
mRecyclerView.scrollToPosition(0);
}
// try to restore all saved values again
if (mSavedInstance != null) {
if (!mAppended) {
mAdapter.withSavedInstanceState(mSavedInstance, Drawer.BUNDLE_SELECTION);
DrawerUtils.setStickyFooterSelection(this, mSavedInstance.getInt(Drawer.BUNDLE_STICKY_FOOTER_SELECTION, -1), null);
} else {
mAdapter.withSavedInstanceState(mSavedInstance, Drawer.BUNDLE_SELECTION_APPENDED);
DrawerUtils.setStickyFooterSelection(this, mSavedInstance.getInt(Drawer.BUNDLE_STICKY_FOOTER_SELECTION_APPENDED, -1), null);
}
}
// call initial onClick event to allow the dev to init the first view
if (mFireInitialOnClick && mOnDrawerItemClickListener != null) {
int selection = mAdapter.getSelections().size() == 0 ? -1 : mAdapter.getSelections().iterator().next();
mOnDrawerItemClickListener.onItemClick(null, selection, getDrawerItem(selection));
}
}
use of android.support.v7.widget.RecyclerView.Adapter in project MaterialDrawer by mikepenz.
the class MiniDrawer method build.
/**
* build the MiniDrawer
*
* @param ctx
* @return
*/
public View build(Context ctx) {
mContainer = new LinearLayout(ctx);
if (mInnerShadow) {
if (!mInRTL) {
mContainer.setBackgroundResource(R.drawable.material_drawer_shadow_left);
} else {
mContainer.setBackgroundResource(R.drawable.material_drawer_shadow_right);
}
}
//create and append recyclerView
mRecyclerView = new RecyclerView(ctx);
mContainer.addView(mRecyclerView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
//set the itemAnimator
mRecyclerView.setItemAnimator(new DefaultItemAnimator());
//some style improvements on older devices
mRecyclerView.setFadingEdgeLength(0);
//set the drawing cache background to the same color as the slider to improve performance
//mRecyclerView.setDrawingCacheBackgroundColor(UIUtils.getThemeColorFromAttrOrRes(mActivity, R.attr.material_drawer_background, R.color.material_drawer_background));
mRecyclerView.setClipToPadding(false);
//additional stuff
mRecyclerView.setLayoutManager(new LinearLayoutManager(ctx));
//adapter
mAdapter = new FastAdapter<>();
mItemAdapter = new ItemAdapter<>();
mAdapter.withSelectable(true);
mAdapter.withAllowDeselection(false);
mAdapter.withPositionBasedStateManagement(mPositionBasedStateManagement);
mRecyclerView.setAdapter(mItemAdapter.wrap(mAdapter));
//if the activity with the drawer should be fullscreen add the padding for the statusbar
if (mDrawer != null && mDrawer.mDrawerBuilder != null && (mDrawer.mDrawerBuilder.mFullscreen || mDrawer.mDrawerBuilder.mTranslucentStatusBar)) {
mRecyclerView.setPadding(mRecyclerView.getPaddingLeft(), UIUtils.getStatusBarHeight(ctx), mRecyclerView.getPaddingRight(), mRecyclerView.getPaddingBottom());
}
//if the activity with the drawer should be fullscreen add the padding for the navigationBar
if (mDrawer != null && mDrawer.mDrawerBuilder != null && (mDrawer.mDrawerBuilder.mFullscreen || mDrawer.mDrawerBuilder.mTranslucentNavigationBar) && ctx.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
mRecyclerView.setPadding(mRecyclerView.getPaddingLeft(), mRecyclerView.getPaddingTop(), mRecyclerView.getPaddingRight(), UIUtils.getNavigationBarHeight(ctx));
}
//set the adapter with the items
createItems();
return mContainer;
}
use of android.support.v7.widget.RecyclerView.Adapter in project MaterialDrawer by mikepenz.
the class MiniDrawer method createItems.
/**
* creates the items for the MiniDrawer
*/
public void createItems() {
mItemAdapter.clear();
int profileOffset = 0;
if (mAccountHeader != null && mAccountHeader.getAccountHeaderBuilder().mProfileImagesVisible) {
IProfile profile = mAccountHeader.getActiveProfile();
if (profile instanceof IDrawerItem) {
mItemAdapter.add(generateMiniDrawerItem((IDrawerItem) profile));
profileOffset = 1;
}
}
int select = -1;
if (mDrawer != null) {
if (getDrawerItems() != null) {
//migrate to miniDrawerItems
int length = getDrawerItems().size();
int position = 0;
for (int i = 0; i < length; i++) {
IDrawerItem miniDrawerItem = generateMiniDrawerItem(getDrawerItems().get(i));
if (miniDrawerItem != null) {
if (miniDrawerItem.isSelected()) {
select = position;
}
mItemAdapter.add(miniDrawerItem);
position = position + 1;
}
}
if (select >= 0) {
//+1 because of the profile
mAdapter.select(select + profileOffset);
}
}
}
//listener
if (mOnMiniDrawerItemOnClickListener != null) {
mAdapter.withOnClickListener(mOnMiniDrawerItemOnClickListener);
} else {
mAdapter.withOnClickListener(new FastAdapter.OnClickListener<IDrawerItem>() {
@Override
public boolean onClick(View v, IAdapter<IDrawerItem> adapter, final IDrawerItem item, final int position) {
int type = getMiniDrawerType(item);
//if a listener is defined and we consume the event return
if (mOnMiniDrawerItemClickListener != null && mOnMiniDrawerItemClickListener.onItemClick(v, position, item, type)) {
return false;
}
if (type == ITEM) {
//fire the onClickListener also if the specific drawerItem is not Selectable
if (item.isSelectable()) {
//make sure we are on the original drawerItemList
if (mAccountHeader != null && mAccountHeader.isSelectionListShown()) {
mAccountHeader.toggleSelectionList(v.getContext());
}
if (!mDrawer.getDrawerItem(item.getIdentifier()).isSelected()) {
//set the selection
mDrawer.setSelection(item, true);
}
} else if (mDrawer.getOnDrawerItemClickListener() != null) {
//get the original `DrawerItem` from the Drawer as this one will contain all information
mDrawer.getOnDrawerItemClickListener().onItemClick(v, position, DrawerUtils.getDrawerItem(getDrawerItems(), item.getIdentifier()));
}
} else if (type == PROFILE) {
if (mAccountHeader != null && !mAccountHeader.isSelectionListShown()) {
mAccountHeader.toggleSelectionList(v.getContext());
}
if (mCrossFader != null) {
mCrossFader.crossfade();
}
}
return false;
}
});
}
mAdapter.withOnLongClickListener(mOnMiniDrawerItemLongClickListener);
mRecyclerView.scrollToPosition(0);
}
use of android.support.v7.widget.RecyclerView.Adapter in project android-oss by kickstarter.
the class ThanksActivity method onCreate.
@Override
protected void onCreate(@Nullable final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.thanks_layout);
ButterKnife.bind(this);
((KSApplication) getApplication()).component().inject(this);
shareDialog = new ShareDialog(this);
final LinearLayoutManager layoutManager = new LinearLayoutManager(this);
layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
recommendedProjectsRecyclerView.setLayoutManager(layoutManager);
adapter = new ThanksAdapter(viewModel);
recommendedProjectsRecyclerView.setAdapter(adapter);
Observable.timer(500L, TimeUnit.MILLISECONDS, Schedulers.newThread()).compose(ignoreValues()).compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(__ -> animateBackground());
RxView.clicks(shareButton).compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(__ -> viewModel.inputs.shareClick());
RxView.clicks(shareOnFacebookButton).compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(__ -> viewModel.inputs.shareOnFacebookClick());
RxView.clicks(shareOnTwitterButton).compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(__ -> viewModel.inputs.shareOnTwitterClick());
viewModel.outputs.projectName().compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(this::showBackedProject);
viewModel.outputs.showConfirmGamesNewsletterDialog().compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(__ -> showConfirmGamesNewsletterDialog());
viewModel.outputs.showGamesNewsletterDialog().compose(bindToLifecycle()).take(1).delay(700L, TimeUnit.MILLISECONDS).observeOn(AndroidSchedulers.mainThread()).subscribe(__ -> showGamesNewsletterDialog());
viewModel.outputs.showRatingDialog().compose(bindToLifecycle()).take(1).delay(700L, TimeUnit.MILLISECONDS).observeOn(AndroidSchedulers.mainThread()).subscribe(__ -> showRatingDialog());
viewModel.outputs.showRecommendations().compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(this::showRecommendations);
viewModel.outputs.startDiscovery().compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(this::startDiscovery);
viewModel.outputs.startProject().compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(this::startProject);
viewModel.outputs.startShare().compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(this::startShare);
viewModel.outputs.startShareOnFacebook().compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(this::startShareOnFacebook);
viewModel.outputs.startShareOnTwitter().compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(this::startShareOnTwitter);
}
use of android.support.v7.widget.RecyclerView.Adapter in project android-oss by kickstarter.
the class ProjectActivity method onCreate.
@Override
protected void onCreate(@Nullable final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.project_layout);
ButterKnife.bind(this);
((KSApplication) getApplication()).component().inject(this);
final int bottomButtonVisibility = ViewUtils.isLandscape(this) ? View.GONE : View.VISIBLE;
projectActionButtonsViewGroup.setVisibility(bottomButtonVisibility);
adapter = new ProjectAdapter(viewModel);
projectRecyclerView.setAdapter(adapter);
projectRecyclerView.setLayoutManager(new LinearLayoutManager(this));
this.viewModel.outputs.projectAndUserCountry().compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(pc -> this.renderProject(pc.first, pc.second));
this.viewModel.outputs.startCampaignWebViewActivity().compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(this::startCampaignWebViewActivity);
this.viewModel.outputs.startCommentsActivity().compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(this::startCommentsActivity);
this.viewModel.outputs.startCreatorBioWebViewActivity().compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(this::startCreatorBioWebViewActivity);
this.viewModel.outputs.showShareSheet().compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(this::startShareIntent);
this.viewModel.outputs.startProjectUpdatesActivity().compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(this::startProjectUpdatesActivity);
this.viewModel.outputs.startVideoActivity().compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(this::startVideoActivity);
this.viewModel.outputs.startCheckoutActivity().compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(this::startCheckoutActivity);
this.viewModel.outputs.startManagePledgeActivity().compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(this::startManagePledge);
this.viewModel.outputs.startViewPledgeActivity().compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(this::startViewPledgeActivity);
this.viewModel.outputs.showStarredPrompt().compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(__ -> this.showStarToast());
this.viewModel.outputs.startLoginToutActivity().compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(__ -> this.startLoginToutActivity());
}
Aggregations