Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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