Use application index in menu items

This commit is contained in:
Jannis Mattheis
2020-07-15 18:35:30 +02:00
parent b3b1e47cff
commit 85d20e1f9e

View File

@@ -222,13 +222,9 @@ public class MessagesActivity extends AppCompatActivity
menu.removeGroup(R.id.apps); menu.removeGroup(R.id.apps);
targetReferences.clear(); targetReferences.clear();
updateMessagesAndStopLoading(messages.get(appId)); updateMessagesAndStopLoading(messages.get(appId));
for (Application app : applications) { for (int i = 0; i < applications.size(); i++) {
MenuItem item = Application app = applications.get(i);
menu.add( MenuItem item = menu.add(R.id.apps, i, APPLICATION_ORDER, app.getName());
R.id.apps,
Utils.longToInt(app.getId()),
APPLICATION_ORDER,
app.getName());
item.setCheckable(true); item.setCheckable(true);
Target t = Utils.toDrawable(getResources(), item::setIcon); Target t = Utils.toDrawable(getResources(), item::setIcon);
targetReferences.add(t); targetReferences.add(t);
@@ -289,7 +285,8 @@ public class MessagesActivity extends AppCompatActivity
int id = item.getItemId(); int id = item.getItemId();
if (item.getGroupId() == R.id.apps) { if (item.getGroupId() == R.id.apps) {
selectAppIdOnDrawerClose = (long) id; Application app = appsHolder.get().get(id);
selectAppIdOnDrawerClose = app != null ? app.getId() : MessageState.ALL_MESSAGES;
startLoading(); startLoading();
toolbar.setSubtitle(item.getTitle()); toolbar.setSubtitle(item.getTitle());
} else if (id == R.id.nav_all_messages) { } else if (id == R.id.nav_all_messages) {
@@ -343,13 +340,17 @@ public class MessagesActivity extends AppCompatActivity
filter.addAction(WebSocketService.NEW_MESSAGE_BROADCAST); filter.addAction(WebSocketService.NEW_MESSAGE_BROADCAST);
registerReceiver(receiver, filter); registerReceiver(receiver, filter);
new UpdateMissedMessages().execute(messages.getLastReceivedMessage()); new UpdateMissedMessages().execute(messages.getLastReceivedMessage());
navigationView
.getMenu() int selectedIndex = R.id.nav_all_messages;
.findItem( if (appId != MessageState.ALL_MESSAGES) {
appId == MessageState.ALL_MESSAGES for (int i = 0; i < appsHolder.get().size(); i++) {
? R.id.nav_all_messages if (appsHolder.get().get(i).getId() == appId) {
: Utils.longToInt(appId)) selectedIndex = i;
.setChecked(true); }
}
}
navigationView.getMenu().findItem(selectedIndex).setChecked(true);
super.onResume(); super.onResume();
} }