aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel@gultsch.de>2016-01-21 17:57:24 +0100
committerDaniel Gultsch <daniel@gultsch.de>2016-01-21 17:57:24 +0100
commiteacc7ed1e6d4be25862e023efe65f52b9158953f (patch)
tree0cb49e6a557cfc6f2a827373bdd091c83ed5e356
parent62a88a4db83d487ecdb64cb6e4d3fa403943062f (diff)
add convenience to get an account object from a spinner
-rw-r--r--src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java34
1 files changed, 19 insertions, 15 deletions
diff --git a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java
index a502a0a2..0bf4178f 100644
--- a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java
@@ -389,7 +389,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
final View dialogView = getLayoutInflater().inflate(R.layout.join_conference_dialog, null);
final Spinner spinner = (Spinner) dialogView.findViewById(R.id.account);
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) {
jid.append(prefilledJid);
}
@@ -409,14 +409,9 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
if (!xmppConnectionServiceBound) {
return;
}
- final Jid accountJid;
- try {
- if (Config.DOMAIN_LOCK != null) {
- accountJid = Jid.fromParts((String) spinner.getSelectedItem(), Config.DOMAIN_LOCK, null);
- } else {
- accountJid = Jid.fromString((String) spinner.getSelectedItem());
- }
- } catch (final InvalidJidException e) {
+ final Account account = getSelectedAccount(spinner);
+ if (account == null) {
+ dialog.dismiss();
return;
}
final Jid conferenceJid;
@@ -426,12 +421,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
jid.setError(getString(R.string.invalid_jid));
return;
}
- final Account account = xmppConnectionService
- .findAccountByJid(accountJid);
- if (account == null) {
- dialog.dismiss();
- return;
- }
+
if (bookmarkCheckBox.isChecked()) {
if (account.hasBookmarkFor(conferenceJid)) {
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) {
Conversation conversation = xmppConnectionService
.findOrCreateConversation(contact.getAccount(),