add convenience to get an account object from a spinner

This commit is contained in:
Daniel Gultsch 2016-01-21 17:57:24 +01:00
parent 62a88a4db8
commit eacc7ed1e6

View file

@ -389,7 +389,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
final View dialogView = getLayoutInflater().inflate(R.layout.join_conference_dialog, null); final View dialogView = getLayoutInflater().inflate(R.layout.join_conference_dialog, null);
final Spinner spinner = (Spinner) dialogView.findViewById(R.id.account); final Spinner spinner = (Spinner) dialogView.findViewById(R.id.account);
final AutoCompleteTextView jid = (AutoCompleteTextView) dialogView.findViewById(R.id.jid); final AutoCompleteTextView jid = (AutoCompleteTextView) dialogView.findViewById(R.id.jid);
jid.setAdapter(new KnownHostsAdapter(this,android.R.layout.simple_list_item_1, mKnownConferenceHosts)); jid.setAdapter(new KnownHostsAdapter(this, android.R.layout.simple_list_item_1, mKnownConferenceHosts));
if (prefilledJid != null) { if (prefilledJid != null) {
jid.append(prefilledJid); jid.append(prefilledJid);
} }
@ -409,14 +409,9 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
if (!xmppConnectionServiceBound) { if (!xmppConnectionServiceBound) {
return; return;
} }
final Jid accountJid; final Account account = getSelectedAccount(spinner);
try { if (account == null) {
if (Config.DOMAIN_LOCK != null) { dialog.dismiss();
accountJid = Jid.fromParts((String) spinner.getSelectedItem(), Config.DOMAIN_LOCK, null);
} else {
accountJid = Jid.fromString((String) spinner.getSelectedItem());
}
} catch (final InvalidJidException e) {
return; return;
} }
final Jid conferenceJid; final Jid conferenceJid;
@ -426,12 +421,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
jid.setError(getString(R.string.invalid_jid)); jid.setError(getString(R.string.invalid_jid));
return; return;
} }
final Account account = xmppConnectionService
.findAccountByJid(accountJid);
if (account == null) {
dialog.dismiss();
return;
}
if (bookmarkCheckBox.isChecked()) { if (bookmarkCheckBox.isChecked()) {
if (account.hasBookmarkFor(conferenceJid)) { if (account.hasBookmarkFor(conferenceJid)) {
jid.setError(getString(R.string.bookmark_already_exists)); jid.setError(getString(R.string.bookmark_already_exists));
@ -468,6 +458,20 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
}); });
} }
private Account getSelectedAccount(Spinner spinner) {
Jid jid;
try {
if (Config.DOMAIN_LOCK != null) {
jid = Jid.fromParts((String) spinner.getSelectedItem(), Config.DOMAIN_LOCK, null);
} else {
jid = Jid.fromString((String) spinner.getSelectedItem());
}
} catch (final InvalidJidException e) {
return null;
}
return xmppConnectionService.findAccountByJid(jid);
}
protected void switchToConversation(Contact contact) { protected void switchToConversation(Contact contact) {
Conversation conversation = xmppConnectionService Conversation conversation = xmppConnectionService
.findOrCreateConversation(contact.getAccount(), .findOrCreateConversation(contact.getAccount(),