From 610df2eddc06d9b7cbe0157a2f101eb9eaef76d0 Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Fri, 11 Jul 2014 19:48:41 +0200 Subject: [PATCH] added join conference dialog --- res/layout/create_contact_dialog.xml | 5 +- res/layout/join_conference_dialog.xml | 46 +++++++++++++++++++ res/menu/start_conversation.xml | 4 +- res/values/strings.xml | 6 ++- .../services/XmppConnectionService.java | 13 ++++++ .../conversations/ui/StartConversation.java | 39 +++++++++++++++- .../siacs/conversations/ui/XmppActivity.java | 4 ++ 7 files changed, 110 insertions(+), 7 deletions(-) create mode 100644 res/layout/join_conference_dialog.xml diff --git a/res/layout/create_contact_dialog.xml b/res/layout/create_contact_dialog.xml index 93248b40e..4b5b9a04a 100644 --- a/res/layout/create_contact_dialog.xml +++ b/res/layout/create_contact_dialog.xml @@ -19,7 +19,7 @@ diff --git a/res/layout/join_conference_dialog.xml b/res/layout/join_conference_dialog.xml new file mode 100644 index 000000000..2a0e300a2 --- /dev/null +++ b/res/layout/join_conference_dialog.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + diff --git a/res/menu/start_conversation.xml b/res/menu/start_conversation.xml index 12109d7b6..907fbdede 100644 --- a/res/menu/start_conversation.xml +++ b/res/menu/start_conversation.xml @@ -14,10 +14,10 @@ android:showAsAction="always" android:title="@string/create_contact"/> + android:title="@string/join_conference"/> Conferences Search Create Contact - Create Conference + Join Conference Delete Contact View contact details Create The contact already exists + Join + Conference address + room@conference.example.com + Save as bookmark \ No newline at end of file diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java index dcdd21ddf..259a2b801 100644 --- a/src/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/eu/siacs/conversations/services/XmppConnectionService.java @@ -1529,4 +1529,17 @@ public class XmppConnectionService extends Service { } return hosts; } + + public List getKnownConferenceHosts() { + ArrayList mucServers = new ArrayList(); + for (Account account : accounts) { + if (account.getXmppConnection() != null) { + String server = account.getXmppConnection().getMucServer(); + if (server != null) { + mucServers.add(server); + } + } + } + return mucServers; + } } diff --git a/src/eu/siacs/conversations/ui/StartConversation.java b/src/eu/siacs/conversations/ui/StartConversation.java index 3986929f2..a105acd76 100644 --- a/src/eu/siacs/conversations/ui/StartConversation.java +++ b/src/eu/siacs/conversations/ui/StartConversation.java @@ -60,6 +60,7 @@ public class StartConversation extends XmppActivity { private List mActivatedAccounts = new ArrayList(); private List mKnownHosts; + private List mKnownConferenceHosts; private TabListener mTabListener = new TabListener() { @@ -207,9 +208,39 @@ public class StartConversation extends XmppActivity { } + protected void showJoinConferenceDialog() { + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setTitle(R.string.join_conference); + 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)); + populateAccountSpinner(spinner); + builder.setView(dialogView); + builder.setNegativeButton(R.string.cancel, null); + builder.setPositiveButton(R.string.join, null); + final AlertDialog dialog = builder.create(); + dialog.show(); + dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() { + + @Override + public void onClick(View v) { + if (Validator.isValidJid(jid.getText().toString())) { + String accountJid = (String) spinner.getSelectedItem(); + String conferenceJid = jid.getText().toString(); + Account account = xmppConnectionService.findAccountByJid(accountJid); + Conversation conversation = xmppConnectionService.findOrCreateConversation(account, conferenceJid, true); + switchToConversation(conversation); + } else { + jid.setError(getString(R.string.invalid_jid)); + } + } + }); + } + protected void switchToConversation(Contact contact) { Conversation conversation = xmppConnectionService.findOrCreateConversation(contact.getAccount(), contact.getJid(), false); - switchToConversation(conversation, null, false); + switchToConversation(conversation); } private void populateAccountSpinner(Spinner spinner) { @@ -224,7 +255,7 @@ public class StartConversation extends XmppActivity { MenuItem menuCreateContact = (MenuItem) menu .findItem(R.id.action_create_contact); MenuItem menuCreateConference = (MenuItem) menu - .findItem(R.id.action_create_conference); + .findItem(R.id.action_join_conference); MenuItem menuSearch = (MenuItem) menu.findItem(R.id.action_search); if (getActionBar().getSelectedNavigationIndex() == 0) { menuCreateConference.setVisible(false); @@ -246,6 +277,9 @@ public class StartConversation extends XmppActivity { case R.id.action_create_contact: showCreateContactDialog(); break; + case R.id.action_join_conference: + showJoinConferenceDialog(); + break; } return super.onOptionsItemSelected(item); } @@ -260,6 +294,7 @@ public class StartConversation extends XmppActivity { } } this.mKnownHosts = xmppConnectionService.getKnownHosts(); + this.mKnownConferenceHosts = xmppConnectionService.getKnownConferenceHosts(); } protected void filterContacts(String needle) { diff --git a/src/eu/siacs/conversations/ui/XmppActivity.java b/src/eu/siacs/conversations/ui/XmppActivity.java index 96278a6d7..7abb2cefb 100644 --- a/src/eu/siacs/conversations/ui/XmppActivity.java +++ b/src/eu/siacs/conversations/ui/XmppActivity.java @@ -149,6 +149,10 @@ public abstract class XmppActivity extends Activity { ExceptionHelper.init(getApplicationContext()); } + public void switchToConversation(Conversation conversation) { + switchToConversation(conversation, null, false); + } + public void switchToConversation(Conversation conversation, String text, boolean newTask) { Intent viewConversationIntent = new Intent(this,