From 748582e3aba7f4feb931dd266de0b6b0e1f3206d Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Thu, 13 Mar 2014 18:18:41 +0100 Subject: [PATCH] start converstaion from address book (sendto) --- AndroidManifest.xml | 26 ++++--- .../ui/NewConversationActivity.java | 74 ++++++++++++++----- 2 files changed, 72 insertions(+), 28 deletions(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 25e79a778..4e5042c13 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -11,10 +11,10 @@ - + - + - + @@ -40,14 +40,6 @@ - - - - - - - - + + + + + + + + + + + + diff --git a/src/eu/siacs/conversations/ui/NewConversationActivity.java b/src/eu/siacs/conversations/ui/NewConversationActivity.java index 0ad830ece..e275cea76 100644 --- a/src/eu/siacs/conversations/ui/NewConversationActivity.java +++ b/src/eu/siacs/conversations/ui/NewConversationActivity.java @@ -1,9 +1,12 @@ package eu.siacs.conversations.ui; +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; +import java.util.Locale; import eu.siacs.conversations.R; import eu.siacs.conversations.entities.Account; @@ -15,6 +18,7 @@ import android.net.Uri; import android.os.Bundle; import android.text.Editable; import android.text.TextWatcher; +import android.util.Log; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; @@ -151,23 +155,14 @@ public class NewConversationActivity extends XmppActivity { final Contact clickedContact = aggregatedContacts.get(pos); if ((clickedContact.getAccount()==null)&&(accounts.size()>1)) { - String[] accountList = new String[accounts.size()]; - for (int i = 0; i < accounts.size(); ++i) { - accountList[i] = accounts.get(i).getJid(); - } + getAccountChooser(new OnClickListener() { - AlertDialog.Builder accountChooser = new AlertDialog.Builder( - activity); - accountChooser.setTitle("Choose account"); - accountChooser.setItems(accountList, new OnClickListener() { - - @Override - public void onClick(DialogInterface dialog, int which) { - clickedContact.setAccount(accounts.get(which)); - showIsMucDialogIfNeeded(clickedContact); - } - }); - accountChooser.create().show(); + @Override + public void onClick(DialogInterface dialog, int which) { + clickedContact.setAccount(accounts.get(which)); + showIsMucDialogIfNeeded(clickedContact); + } + }).show(); } else { if (clickedContact.getAccount()==null) { clickedContact.setAccount(accounts.get(0)); @@ -190,6 +185,19 @@ public class NewConversationActivity extends XmppActivity { }); } + protected AlertDialog getAccountChooser(OnClickListener listener) { + String[] accountList = new String[accounts.size()]; + for (int i = 0; i < accounts.size(); ++i) { + accountList[i] = accounts.get(i).getJid(); + } + + AlertDialog.Builder accountChooser = new AlertDialog.Builder( + this); + accountChooser.setTitle("Choose account"); + accountChooser.setItems(accountList, listener); + return accountChooser.create(); + } + public void showIsMucDialogIfNeeded(final Contact clickedContact) { if (clickedContact.couldBeMuc()) { AlertDialog.Builder dialog = new AlertDialog.Builder(this); @@ -222,6 +230,10 @@ public class NewConversationActivity extends XmppActivity { Conversation conversation = xmppConnectionService .findOrCreateConversation(account, contact.getJid(), muc); + switchToConversation(conversation); + } + + public void switchToConversation(Conversation conversation) { Intent viewConversationIntent = new Intent(this, ConversationActivity.class); viewConversationIntent.setAction(Intent.ACTION_VIEW); @@ -235,11 +247,39 @@ public class NewConversationActivity extends XmppActivity { @Override void onBackendConnected() { + this.accounts = xmppConnectionService.getAccounts(); + if (Intent.ACTION_SENDTO.equals(getIntent().getAction())) { + getActionBar().setDisplayHomeAsUpEnabled(false); + getActionBar().setHomeButtonEnabled(false); + String jid; + try { + jid = URLDecoder.decode(getIntent().getData().getEncodedPath(),"UTF-8").split("/")[1]; + } catch (UnsupportedEncodingException e) { + jid = null; + } + if (jid!=null) { + final String finalJid = jid; + if (this.accounts.size() > 1) { + getAccountChooser(new OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, int which) { + Conversation conversation = xmppConnectionService.findOrCreateConversation(accounts.get(which), finalJid, false); + switchToConversation(conversation); + } + }).show(); + } else { + Conversation conversation = xmppConnectionService.findOrCreateConversation(this.accounts.get(0), jid, false); + switchToConversation(conversation); + } + } + } + + if (xmppConnectionService.getConversationCount() == 0) { getActionBar().setDisplayHomeAsUpEnabled(false); getActionBar().setHomeButtonEnabled(false); } - this.accounts = xmppConnectionService.getAccounts(); this.rosterContacts.clear(); for (int i = 0; i < accounts.size(); ++i) { xmppConnectionService.getRoster(accounts.get(i),