Skip to content

Commit

Permalink
Use application index in menu items
Browse files Browse the repository at this point in the history
  • Loading branch information
jmattheis committed Jul 15, 2020
1 parent b3b1e47 commit 85d20e1
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions app/src/main/java/com/github/gotify/messages/MessagesActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,9 @@ protected void onUpdateApps(List<Application> applications) {
menu.removeGroup(R.id.apps);
targetReferences.clear();
updateMessagesAndStopLoading(messages.get(appId));
for (Application app : applications) {
MenuItem item =
menu.add(
R.id.apps,
Utils.longToInt(app.getId()),
APPLICATION_ORDER,
app.getName());
for (int i = 0; i < applications.size(); i++) {
Application app = applications.get(i);
MenuItem item = menu.add(R.id.apps, i, APPLICATION_ORDER, app.getName());
item.setCheckable(true);
Target t = Utils.toDrawable(getResources(), item::setIcon);
targetReferences.add(t);
Expand Down Expand Up @@ -289,7 +285,8 @@ public boolean onNavigationItemSelected(MenuItem item) {
int id = item.getItemId();

if (item.getGroupId() == R.id.apps) {
selectAppIdOnDrawerClose = (long) id;
Application app = appsHolder.get().get(id);
selectAppIdOnDrawerClose = app != null ? app.getId() : MessageState.ALL_MESSAGES;
startLoading();
toolbar.setSubtitle(item.getTitle());
} else if (id == R.id.nav_all_messages) {
Expand Down Expand Up @@ -343,13 +340,17 @@ protected void onResume() {
filter.addAction(WebSocketService.NEW_MESSAGE_BROADCAST);
registerReceiver(receiver, filter);
new UpdateMissedMessages().execute(messages.getLastReceivedMessage());
navigationView
.getMenu()
.findItem(
appId == MessageState.ALL_MESSAGES
? R.id.nav_all_messages
: Utils.longToInt(appId))
.setChecked(true);

int selectedIndex = R.id.nav_all_messages;
if (appId != MessageState.ALL_MESSAGES) {
for (int i = 0; i < appsHolder.get().size(); i++) {
if (appsHolder.get().get(i).getId() == appId) {
selectedIndex = i;
}
}
}

navigationView.getMenu().findItem(selectedIndex).setChecked(true);
super.onResume();
}

Expand Down

0 comments on commit 85d20e1

Please sign in to comment.