I'm using this MaterialDrawer for notification. So, unseen notification will be highlighted and will be back to normal after being seen. I want to unhighlight them when the user close the notification drawer (in any way including swiping, tapping outside the drawer, back button).
Overriding the onDrawerClosed method doesn't seem possible to me since it's in DrawerBuilder. So, is there a way to do it? thanks!
@christiandennis you can provide a OnDrawerListener (for getting notified if the drawer is closed/opened) or a OnDrawerNavigationListener (if you want to extend the behavior of closing/opening the drawer).
Thanks! However, this works if i .Build() the drawer not doesn't work when I .append(...) the drawer.
This is the case, I have 2 drawers, one on the left (with accountHeader) and one on the right. First, I add the left_drawer using .Build() then add the right_drawer using .append(left_drawer) but the OnDrawerListener didn't work. So I do .Build() for both of the drawers. It worked perfectly except that the system bar changed color to white and wasn't fixable with withStatusBarColor(...).
So again, I changed to .append(). This time I switched the order. I do right_drawer.Build() then right_drawer.append(left_drawer). It worked fine but the OnDrawerListener applies to both left and right drawer but I found a workaround to make it work only for one of them. But just now I realized that my accountHeader on the left_drawer isn't clickable... I believe this issue comes from the .append(...) or .build(). Is there any way I could do this? Thanks
@christiandennis there was a problem with this in v3.1.2 i think i fixed this already in v4.0.0 but this version is still in beta. you can try it, but it will have some changed apis
Does it fix the .Build() on both drawer or does it allow the .OnDrawerListener(...) to work even if i put it on the secondary drawer?
@christiandennis you can only build the first. the second one has to be appended. and the OnDrawerListener can only be used on the first one as the first one manages the ActionBarDrawerToggle.
If you want to manage it all on your own. just don't pass the toolbar to the first and then open / close it with your own logic ;)
should work this way
Do you mind looking at my code? I removed withOnDrawerItemClickListener to make it more readable
sliderNotification = new DrawerBuilder()
.withActivity(this)
.withStickyHeader(v)
.withOnDrawerListener(new Drawer.OnDrawerListener() {
@Override
public void onDrawerOpened(View view) {
if ((int) Paper.get("NotificationCount") > 0) {
if(sliderNotification.isDrawerOpen()) {
Paper.put("NotificationCount", 0);
//PUT notifications.json/open_all
RestClient.requestPutOpenAll(new RestClient.RestClientListener() {
@Override
public void onStart() {
Log.e("requestPutOpenAll", "Start");
}
@Override
public void onSuccess(int statusCode, Header[] headers, JSONObject response) throws JSONException, ParseException {
Log.e("requestPutOpenAll", "Success");
}
@Override
public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) throws JSONException {
Log.e("requestPutOpenAll", "Failed");
if (errorResponse.getInt("status") == 403) {
Intent toLogin = new Intent(activity, LoginActivity.class);
toLogin.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(toLogin);
}
}
@Override
public void onRetry(int retryNo) {
Log.e("requestPutOpenAll", "Retried");
}
});
notificationBadge.setVisible(false);
notificationNoBadge.setVisible(true);
}
}
}
@Override
public void onDrawerClosed(View view) {
}
@Override
public void onDrawerSlide(View view, float v) {
if(sliderNotification.isDrawerOpen()){
new java.util.Timer().schedule(
new java.util.TimerTask() {
@Override
public void run() {
// your code here, and if you have to refresh UI put this code:
Utilities.openAllNotification();
}
},
500
);
}
}
})
.withDrawerGravity(Gravity.RIGHT)
.withCloseOnClick(false)
.build();
sliderMenu = new DrawerBuilder()
.withActivity(this)
.withToolbar(toolbar)
.withAccountHeader(headerMenu)
.withDrawerGravity(Gravity.LEFT)
.withSavedInstance(savedInstanceState)
.withFireOnInitialOnClick(true)
.append(sliderNotification);
This is what I actually do right now. I do not pass toolbar to the first drawer and the open/close works just fine except I need to add a navigation button on the toolbar to open the left drawer(appended one). What do you mean by "manage it all on your own" ?? Thanks. Really appreciate it
@christiandennis if you do not pass the toolbar, the MaterialDrawer won't manage the ActionBarDrawerToggle neither the Listener for you. This means you have to add the logic as you would in any normal application without this lib. Then you can manage how and when to open the drawer on your own, and it won't depend on the libs logic.
In general i would just suggest that you keep the original logic with the Drawer managing the ActionBarDrawerToggle and have the listener on the main drawer. (you have to see it as the first you add with .build() managing the whole drawer, and the second only be a child of this one. so the one you create with build is always the one which contains the logic for the DrawerLayout, and the second one is just the slider panel)
Thanks a lot!! it works very well now.
Love your library and great support!
@christiandennis great ;).
I used the following code to track when the right navigation drawer is closed:
//Create the drawer
mLeftNavigaitonDrawer = new DrawerBuilder()
.withActivity(this)
.withToolbar(toolbar)
.withOnDrawerListener(new Drawer.OnDrawerListener() {
@Override
public void onDrawerOpened(View drawerView) {
if (mRightNavigationDrawer.isDrawerOpen())
mHandleFilter = true;
else
mHandleFilter = false;
}
@Override
public void onDrawerClosed(View drawerView) {
if (mHandleFilter)
Toast.makeText(MainActivityGoRace.this, "Right Drawer Closed!", Toast.LENGTH_SHORT).show();
}
@Override
public void onDrawerSlide(View drawerView, float slideOffset) {
}
})
Most helpful comment
I used the following code to track when the right navigation drawer is closed: