start converstaion from address book (sendto)
This commit is contained in:
parent
678dbd37c6
commit
748582e3ab
|
@ -40,14 +40,6 @@
|
|||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.SENDTO" />
|
||||
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
|
||||
<data android:scheme="imto" />
|
||||
<data android:host="jabber" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name="eu.siacs.conversations.ui.SettingsActivity"
|
||||
|
@ -77,6 +69,18 @@
|
|||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value="de.gultsch.chat.ui.ConversationActivity" />
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.SEND" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<data android:mimeType="text/plain" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.SENDTO" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<data android:scheme="imto" />
|
||||
<data android:host="jabber" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
AlertDialog.Builder accountChooser = new AlertDialog.Builder(
|
||||
activity);
|
||||
accountChooser.setTitle("Choose account");
|
||||
accountChooser.setItems(accountList, new OnClickListener() {
|
||||
getAccountChooser(new OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
clickedContact.setAccount(accounts.get(which));
|
||||
showIsMucDialogIfNeeded(clickedContact);
|
||||
}
|
||||
});
|
||||
accountChooser.create().show();
|
||||
}).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),
|
||||
|
|
Loading…
Reference in a new issue