Skip to content

Commit

Permalink
* properly trigger onDrawerItemClickListener of the item when the `se…
Browse files Browse the repository at this point in the history
…tSelection` method is called
  • Loading branch information
mikepenz committed Aug 22, 2016
1 parent b2260bf commit 823a5cc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
13 changes: 11 additions & 2 deletions library/src/main/java/com/mikepenz/materialdrawer/Drawer.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.mikepenz.materialdrawer.holder.DimenHolder;
import com.mikepenz.materialdrawer.holder.ImageHolder;
import com.mikepenz.materialdrawer.holder.StringHolder;
import com.mikepenz.materialdrawer.model.AbstractDrawerItem;
import com.mikepenz.materialdrawer.model.ContainerDrawerItem;
import com.mikepenz.materialdrawer.model.interfaces.Badgeable;
import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem;
Expand Down Expand Up @@ -554,8 +555,16 @@ public boolean setSelectionAtPosition(int position, boolean fireOnClick) {
if (mDrawerBuilder.mRecyclerView != null) {
mDrawerBuilder.mAdapter.deselect();
mDrawerBuilder.mAdapter.select(position, false);
if (mDrawerBuilder.mOnDrawerItemClickListener != null && fireOnClick && position >= 0) {
mDrawerBuilder.mOnDrawerItemClickListener.onItemClick(null, position, mDrawerBuilder.mAdapter.getItem(position));
if (fireOnClick && position >= 0) {
IDrawerItem item = mDrawerBuilder.mAdapter.getItem(position);

if (item instanceof AbstractDrawerItem && ((AbstractDrawerItem) item).getOnDrawerItemClickListener() != null) {
((AbstractDrawerItem) item).getOnDrawerItemClickListener().onItemClick(null, position, item);
}

if (mDrawerBuilder.mOnDrawerItemClickListener != null) {
mDrawerBuilder.mOnDrawerItemClickListener.onItemClick(null, position, item);
}
}

//we set the selection on a normal item in the drawer so we have to deselect the items in the StickyDrawer
Expand Down
14 changes: 11 additions & 3 deletions library/src/main/java/com/mikepenz/materialdrawer/DrawerUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.mikepenz.materialdrawer.model.AbstractDrawerItem;
import com.mikepenz.materialdrawer.model.ContainerDrawerItem;
import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem;
import com.mikepenz.materialdrawer.model.interfaces.Selectable;
Expand All @@ -30,7 +31,7 @@ class DrawerUtils {
* @param fireOnClick true if we should call the listener, false if not, null to not call the listener and not close the drawer
*/
public static void onFooterDrawerItemClick(DrawerBuilder drawer, IDrawerItem drawerItem, View v, Boolean fireOnClick) {
boolean checkable = !(drawerItem != null && drawerItem instanceof Selectable && !((Selectable) drawerItem).isSelectable());
boolean checkable = !(drawerItem != null && drawerItem instanceof Selectable && !drawerItem.isSelectable());
if (checkable) {
drawer.resetStickyFooterSelection();

Expand All @@ -55,8 +56,15 @@ public static void onFooterDrawerItemClick(DrawerBuilder drawer, IDrawerItem dra

if (fireOnClick != null) {
boolean consumed = false;
if (fireOnClick && drawer.mOnDrawerItemClickListener != null) {
consumed = drawer.mOnDrawerItemClickListener.onItemClick(v, -1, drawerItem);

if (fireOnClick) {
if (drawerItem instanceof AbstractDrawerItem && ((AbstractDrawerItem) drawerItem).getOnDrawerItemClickListener() != null) {
consumed = ((AbstractDrawerItem) drawerItem).getOnDrawerItemClickListener().onItemClick(null, -1, drawerItem);
}

if (drawer.mOnDrawerItemClickListener != null) {
consumed = drawer.mOnDrawerItemClickListener.onItemClick(v, -1, drawerItem);
}
}

if (!consumed) {
Expand Down

0 comments on commit 823a5cc

Please sign in to comment.