Skip to content

Commit 1e75041

Browse files
committed
Refactor onOptionsItemSelected behavior.
1. onOptionsItemSelected behavior now conforms to the contract set out in the docs. 2. onOptionsItemSelected for sub-Controllers now delegate to the super class when they have no behavior defined for an item.
1 parent e3d64e9 commit 1e75041

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

todoapp/app/src/main/java/com/example/android/architecture/blueprints/todoapp/BaseController.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ protected void onAttach(@NonNull View view) {
4545
public boolean onOptionsItemSelected(MenuItem item) {
4646
switch (item.getItemId()) {
4747
case android.R.id.home:
48-
// Set the default behavior to be back navigation
49-
getRouter().popCurrentController();
50-
break;
48+
// Set the default behavior to be back navigation.
49+
getRouter().handleBack();
50+
return true;
5151
}
52-
return true;
52+
return false;
5353
}
5454

5555
@Override

todoapp/app/src/main/java/com/example/android/architecture/blueprints/todoapp/statistics/StatisticsController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ public boolean onOptionsItemSelected(MenuItem item) {
7878
case android.R.id.home:
7979
// Open the navigation drawer when the home icon is selected from the toolbar.
8080
getDrawerLayout().openDrawer(GravityCompat.START);
81-
break;
81+
return true;
8282
}
83-
return true;
83+
return super.onOptionsItemSelected(item);
8484
}
8585

8686
@Override

todoapp/app/src/main/java/com/example/android/architecture/blueprints/todoapp/taskdetail/TaskDetailController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
122122
mPresenter.deleteTask();
123123
return true;
124124
}
125-
return false;
125+
return super.onOptionsItemSelected(item);
126126
}
127127

128128
@Override

todoapp/app/src/main/java/com/example/android/architecture/blueprints/todoapp/tasks/TasksController.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,18 +196,18 @@ public boolean onOptionsItemSelected(MenuItem item) {
196196
case android.R.id.home:
197197
// Open the navigation drawer when the home icon is selected from the toolbar.
198198
getDrawerLayout().openDrawer(GravityCompat.START);
199-
break;
199+
return true;
200200
case R.id.menu_clear:
201201
mPresenter.clearCompletedTasks();
202-
break;
202+
return true;
203203
case R.id.menu_filter:
204204
showFilteringPopUpMenu();
205-
break;
205+
return true;
206206
case R.id.menu_refresh:
207207
mPresenter.loadTasks(true);
208-
break;
208+
return true;
209209
}
210-
return true;
210+
return super.onOptionsItemSelected(item);
211211
}
212212

213213
@Override

0 commit comments

Comments
 (0)