update action bar with conversations updates as well

This commit is contained in:
iNPUTmice 2014-11-21 20:02:13 +01:00
parent 97344c079a
commit 81a1a48b8d
2 changed files with 45 additions and 52 deletions

View file

@ -22,30 +22,15 @@ public class PresenceParser extends AbstractParser implements
public void parseConferencePresence(PresencePacket packet, Account account) { public void parseConferencePresence(PresencePacket packet, Account account) {
PgpEngine mPgpEngine = mXmppConnectionService.getPgpEngine(); PgpEngine mPgpEngine = mXmppConnectionService.getPgpEngine();
if (packet.hasChild("x", "http://jabber.org/protocol/muc#user")) { final Conversation conversation = packet.getFrom() == null ? null : mXmppConnectionService.find(account, packet.getFrom().toBareJid());
final Conversation muc = packet.getFrom() == null ? null : mXmppConnectionService.find( if (conversation != null) {
account, final MucOptions mucOptions = conversation.getMucOptions();
packet.getFrom().toBareJid()); boolean before = mucOptions.online();
if (muc != null) { int count = mucOptions.getUsers().size();
boolean before = muc.getMucOptions().online(); mucOptions.processPacket(packet, mPgpEngine);
muc.getMucOptions().processPacket(packet, mPgpEngine); mXmppConnectionService.getAvatarService().clear(conversation);
if (before != muc.getMucOptions().online()) { if (before != mucOptions.online() || (mucOptions.online() && count != mucOptions.getUsers().size())) {
mXmppConnectionService.updateConversationUi(); mXmppConnectionService.updateConversationUi();
}
mXmppConnectionService.getAvatarService().clear(muc);
}
} else if (packet.hasChild("x", "http://jabber.org/protocol/muc")) {
final Conversation conversation = mXmppConnectionService.find(account,
packet.getFrom().toBareJid());
if (conversation != null) {
final MucOptions mucOptions = conversation.getMucOptions();
boolean before = mucOptions.online();
int count = mucOptions.getUsers().size();
mucOptions.processPacket(packet, mPgpEngine);
mXmppConnectionService.getAvatarService().clear(conversation);
if (before != mucOptions.online() || (mucOptions.online() && count != mucOptions.getUsers().size())) {
mXmppConnectionService.updateConversationUi();
}
} }
} }
} }
@ -56,7 +41,7 @@ public class PresenceParser extends AbstractParser implements
if (packet.getFrom() == null) { if (packet.getFrom() == null) {
return; return;
} }
final Jid from = packet.getFrom(); final Jid from = packet.getFrom();
String type = packet.getAttribute("type"); String type = packet.getAttribute("type");
if (from.toBareJid().equals(account.getJid().toBareJid())) { if (from.toBareJid().equals(account.getJid().toBareJid())) {
if (!from.isBareJid()) { if (!from.isBareJid()) {

View file

@ -181,7 +181,6 @@ public class ConversationActivity extends XmppActivity implements
hideConversationsOverview(); hideConversationsOverview();
} }
}); });
//registerForContextMenu(listView);
mContentView = findViewById(R.id.content_view_spl); mContentView = findViewById(R.id.content_view_spl);
if (mContentView == null) { if (mContentView == null) {
mContentView = findViewById(R.id.content_view_ll); mContentView = findViewById(R.id.content_view_ll);
@ -196,12 +195,7 @@ public class ConversationActivity extends XmppActivity implements
@Override @Override
public void onPanelOpened(View arg0) { public void onPanelOpened(View arg0) {
ActionBar ab = getActionBar(); updateActionBarTitle();
if (ab != null) {
ab.setDisplayHomeAsUpEnabled(false);
ab.setHomeButtonEnabled(false);
ab.setTitle(R.string.app_name);
}
invalidateOptionsMenu(); invalidateOptionsMenu();
hideKeyboard(); hideKeyboard();
if (xmppConnectionServiceBound) { if (xmppConnectionServiceBound) {
@ -237,20 +231,32 @@ public class ConversationActivity extends XmppActivity implements
}); });
} }
public void openConversation() { private void updateActionBarTitle() {
updateActionBarTitle(isConversationsOverviewHideable() && !isConversationsOverviewVisable());
}
private void updateActionBarTitle(boolean titleShouldBeName) {
ActionBar ab = getActionBar(); ActionBar ab = getActionBar();
if (ab != null) { if (ab != null) {
ab.setDisplayHomeAsUpEnabled(true); if (titleShouldBeName) {
ab.setHomeButtonEnabled(true); ab.setDisplayHomeAsUpEnabled(true);
if (getSelectedConversation().getMode() == Conversation.MODE_SINGLE ab.setHomeButtonEnabled(true);
|| ConversationActivity.this if (getSelectedConversation().getMode() == Conversation.MODE_SINGLE || useSubjectToIdentifyConference()) {
.useSubjectToIdentifyConference()) { ab.setTitle(getSelectedConversation().getName());
ab.setTitle(getSelectedConversation().getName()); } else {
ab.setTitle(getSelectedConversation().getContactJid().toBareJid().toString());
}
} else { } else {
ab.setTitle(getSelectedConversation().getContactJid().toBareJid().toString()); ab.setDisplayHomeAsUpEnabled(false);
ab.setHomeButtonEnabled(false);
ab.setTitle(R.string.app_name);
} }
} }
invalidateOptionsMenu(); }
private void openConversation() {
this.updateActionBarTitle();
this.invalidateOptionsMenu();
if (xmppConnectionServiceBound) { if (xmppConnectionServiceBound) {
xmppConnectionService.getNotificationService().setOpenConversation(getSelectedConversation()); xmppConnectionService.getNotificationService().setOpenConversation(getSelectedConversation());
if (!getSelectedConversation().isRead()) { if (!getSelectedConversation().isRead()) {
@ -739,8 +745,9 @@ public class ConversationActivity extends XmppActivity implements
this.mConversationFragment.appendText(text); this.mConversationFragment.appendText(text);
} }
hideConversationsOverview(); hideConversationsOverview();
openConversation();
if (mContentView instanceof SlidingPaneLayout) { if (mContentView instanceof SlidingPaneLayout) {
openConversation(); updateActionBarTitle(true); //fixes bug where slp isn't properly closed yet
} }
} }
@ -928,17 +935,15 @@ public class ConversationActivity extends XmppActivity implements
@Override @Override
public void onAccountUpdate() { public void onAccountUpdate() {
final ConversationFragment fragment = (ConversationFragment) getFragmentManager() runOnUiThread(new Runnable() {
.findFragmentByTag("conversation");
if (fragment != null) {
runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
fragment.updateMessages(); updateConversationList();
} ConversationActivity.this.mConversationFragment.updateMessages();
}); updateActionBarTitle();
} }
});
} }
@Override @Override
@ -954,6 +959,7 @@ public class ConversationActivity extends XmppActivity implements
finish(); finish();
} }
ConversationActivity.this.mConversationFragment.updateMessages(); ConversationActivity.this.mConversationFragment.updateMessages();
updateActionBarTitle();
} }
}); });
} }
@ -964,7 +970,9 @@ public class ConversationActivity extends XmppActivity implements
@Override @Override
public void run() { public void run() {
updateConversationList();
ConversationActivity.this.mConversationFragment.updateMessages(); ConversationActivity.this.mConversationFragment.updateMessages();
updateActionBarTitle();
} }
}); });
} }