-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Up vs Back #6
Comments
What we did in our project is to create a module in your main public interface OptionsItemSelectedHandler {
boolean onOptionsItemSelected(MenuItem item);
// other toolbar stuff for example boolean onCreateOptionsMenu(Menu menu)
} The Activity presenter implements this interface, so in the Activity you simply override the method and call the presenter: @Override
public boolean onOptionsItemSelected(MenuItem item) {
return mActivityPresenter.onOptionsItemSelected(item);
} The presenter holds a reference to a @Override
public boolean onOptionsItemSelected(MenuItem item) {
if (mOptionsItemSelectedHandler != null) {
return mOptionsItemSelectedHandler.onOptionsItemSelected(item);
} else {
return false;
}
} If for a view you are interested in handling the options selected events, the presenter has to implement the Normally we would set the That being said, if you only want to handle the "up" menu button, it's much easier. You simply have to call boolean onOptionsItemSelected(MenuItem item);
switch (item.getItemId()) {
case android.R.id.home:
mNavigator.delegate().onBackPressed();
return true;
default:
return super.onOptionsItemSelected(item);
}
} |
I know how to handle the button from the activity. Just wanted to know if the library provided any framework to provide a history corresponding to up navigation from a screen. UP and BACK are two different navigation patterns, and most of the time, UP should not be treated the same as BACK (official documentation). When working with activities, the pattern is to specify the parent task either via XML in the manifest or from code SDK docs:
Then when navigating up, you have to rebuilt a back stack corresponding to the new application state after up navigation SDK docs:
If we transpose all that to the mortar architect components, presenters are responsible for building the new back stack instead of activities. Just like we have PS : just like for activity result and all such common use cases, because mortar architect is all about killing boiler plate code, it would be nice to have these common use cases wired with just the presenter implementing some interfaces and a single line in the activity code. |
ah ok I get your point now. I agree it would be worth adding it! |
@cartierjf I know this is very descriptive but I still have not been able to make this work, Do you have a gist of the full classes where this is implemented? Cheers. |
Hi,
how do you handle "up" navigation with architect navigators?
The text was updated successfully, but these errors were encountered: