Skip to content

Commit

Permalink
* allow to define the stateManagement of the FastAdapter via the Mate…
Browse files Browse the repository at this point in the history
…rialDrawer
  • Loading branch information
mikepenz committed Jun 6, 2016
1 parent 7a8842d commit 40a401c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public Materialize getMaterialize() {
*/
public MiniDrawer getMiniDrawer() {
if (mDrawerBuilder.mMiniDrawer == null) {
mDrawerBuilder.mMiniDrawer = new MiniDrawer().withDrawer(this).withAccountHeader(mDrawerBuilder.mAccountHeader);
mDrawerBuilder.mMiniDrawer = new MiniDrawer().withDrawer(this).withAccountHeader(mDrawerBuilder.mAccountHeader).withPositionBasedStateManagement(mDrawerBuilder.mPositionBasedStateManagement);
}
return mDrawerBuilder.mMiniDrawer;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -863,11 +863,24 @@ public DrawerBuilder withHasStableIds(boolean hasStableIds) {
}

// an adapter to use for the list
protected boolean mPositionBasedStateManagement = true;
protected FastAdapter<IDrawerItem> mAdapter;
protected HeaderAdapter<IDrawerItem> mHeaderAdapter = new HeaderAdapter<>();
protected ItemAdapter<IDrawerItem> mItemAdapter = new ItemAdapter<>();
protected FooterAdapter<IDrawerItem> mFooterAdapter = new FooterAdapter<>();

/**
* This allows to disable the default position based statemanagment of the FastAdapter and switch to the
* new identifier based state managment
*
* @param positionBasedStateManagement enable / disable the positionBasedStateManagement
* @return this
*/
public DrawerBuilder withPositionBasedStateManagement(boolean positionBasedStateManagement) {
this.mPositionBasedStateManagement = positionBasedStateManagement;
return this;
}

/**
* Define a custom Adapter which will be used in the drawer
* NOTE: this is not recommender
Expand All @@ -894,6 +907,7 @@ protected FastAdapter<IDrawerItem> getAdapter() {
mAdapter.withSelectable(true);
mAdapter.withAllowDeselection(false);
mAdapter.setHasStableIds(mHasStableIds);
mAdapter.withPositionBasedStateManagement(mPositionBasedStateManagement);

//we wrap our main Adapter with the item hosting adapter
mHeaderAdapter.wrap(mItemAdapter.wrap(mFooterAdapter.wrap(mAdapter)));
Expand Down Expand Up @@ -1485,7 +1499,7 @@ public Drawer buildView() {
//we only want to hook a Drawer to the MiniDrawer if it is the main drawer, not the appended one
if (!mAppended && mGenerateMiniDrawer) {
// if we should create a MiniDrawer we have to do this now
mMiniDrawer = new MiniDrawer().withDrawer(result).withAccountHeader(mAccountHeader);
mMiniDrawer = new MiniDrawer().withDrawer(result).withAccountHeader(mAccountHeader).withPositionBasedStateManagement(mPositionBasedStateManagement);
}

//forget the reference to the activity
Expand Down
16 changes: 16 additions & 0 deletions library/src/main/java/com/mikepenz/materialdrawer/MiniDrawer.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,21 @@ public MiniDrawer withInRTL(boolean inRTL) {
return this;
}


protected boolean mPositionBasedStateManagement = true;

/**
* This allows to disable the default position based statemanagment of the FastAdapter and switch to the
* new identifier based state managment
*
* @param positionBasedStateManagement enable / disable the positionBasedStateManagement
* @return this
*/
public MiniDrawer withPositionBasedStateManagement(boolean positionBasedStateManagement) {
this.mPositionBasedStateManagement = positionBasedStateManagement;
return this;
}

private boolean mIncludeSecondaryDrawerItems = false;

/**
Expand Down Expand Up @@ -298,6 +313,7 @@ public View build(Context ctx) {
mAdapter = new FastItemAdapter<>();
mAdapter.withSelectable(true);
mAdapter.withAllowDeselection(false);
mAdapter.withPositionBasedStateManagement(mPositionBasedStateManagement);
mRecyclerView.setAdapter(mAdapter);

//if the activity with the drawer should be fullscreen add the padding for the statusbar
Expand Down

0 comments on commit 40a401c

Please sign in to comment.