mirror of
https://github.com/oxen-io/session-android.git
synced 2025-10-25 08:28:57 +00:00
Consistent Recipient to add contact Intent export.
This commit is contained in:
@@ -4,12 +4,12 @@ import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.AsyncTask;
|
||||
import android.provider.ContactsContract;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientExporter;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
|
||||
import java.util.LinkedList;
|
||||
@@ -70,14 +70,7 @@ public class GroupMembersDialog extends AsyncTask<Void, Void, List<Recipient>> {
|
||||
|
||||
context.startActivity(intent);
|
||||
} else {
|
||||
final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
|
||||
if (recipient.getAddress().isEmail()) {
|
||||
intent.putExtra(ContactsContract.Intents.Insert.EMAIL, recipient.getAddress().toEmailString());
|
||||
} else {
|
||||
intent.putExtra(ContactsContract.Intents.Insert.PHONE, recipient.getAddress().toPhoneString());
|
||||
}
|
||||
intent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE);
|
||||
context.startActivity(intent);
|
||||
context.startActivity(RecipientExporter.export(recipient).asAddContactIntent());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package org.thoughtcrime.securesms.components;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
@@ -11,16 +10,15 @@ import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.widget.AppCompatImageView;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
||||
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.contacts.avatars.ContactColors;
|
||||
import org.thoughtcrime.securesms.contacts.avatars.GeneratedContactPhoto;
|
||||
import org.thoughtcrime.securesms.contacts.avatars.ResourceContactPhoto;
|
||||
import org.thoughtcrime.securesms.mms.GlideRequests;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientExporter;
|
||||
import org.thoughtcrime.securesms.util.ThemeUtil;
|
||||
|
||||
public class AvatarImageView extends AppCompatImageView {
|
||||
@@ -110,14 +108,7 @@ public class AvatarImageView extends AppCompatImageView {
|
||||
if (recipient.getContactUri() != null) {
|
||||
ContactsContract.QuickContact.showQuickContact(getContext(), AvatarImageView.this, recipient.getContactUri(), ContactsContract.QuickContact.MODE_LARGE, null);
|
||||
} else {
|
||||
final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
|
||||
if (recipient.getAddress().isEmail()) {
|
||||
intent.putExtra(ContactsContract.Intents.Insert.EMAIL, recipient.getAddress().toEmailString());
|
||||
} else {
|
||||
intent.putExtra(ContactsContract.Intents.Insert.PHONE, recipient.getAddress().toPhoneString());
|
||||
}
|
||||
intent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE);
|
||||
getContext().startActivity(intent);
|
||||
getContext().startActivity(RecipientExporter.export(recipient).asAddContactIntent());
|
||||
}
|
||||
});
|
||||
} else {
|
||||
|
||||
@@ -181,6 +181,7 @@ import org.thoughtcrime.securesms.providers.BlobProvider;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientFormattingException;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientModifiedListener;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientExporter;
|
||||
import org.thoughtcrime.securesms.scribbles.ScribbleActivity;
|
||||
import org.thoughtcrime.securesms.search.model.MessageResult;
|
||||
import org.thoughtcrime.securesms.service.KeyCachingService;
|
||||
@@ -1110,14 +1111,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
if (recipient.getAddress().isGroup()) return;
|
||||
|
||||
try {
|
||||
final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
|
||||
if (recipient.getAddress().isEmail()) {
|
||||
intent.putExtra(ContactsContract.Intents.Insert.EMAIL, recipient.getAddress().toEmailString());
|
||||
} else {
|
||||
intent.putExtra(ContactsContract.Intents.Insert.PHONE, recipient.getAddress().toPhoneString());
|
||||
}
|
||||
intent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE);
|
||||
startActivityForResult(intent, ADD_CONTACT);
|
||||
startActivityForResult(RecipientExporter.export(recipient).asAddContactIntent(), ADD_CONTACT);
|
||||
} catch (ActivityNotFoundException e) {
|
||||
Log.w(TAG, e);
|
||||
}
|
||||
|
||||
@@ -1,20 +1,16 @@
|
||||
package org.thoughtcrime.securesms.profiles;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.AsyncTask;
|
||||
import android.provider.ContactsContract;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientExporter;
|
||||
import org.thoughtcrime.securesms.util.ViewUtil;
|
||||
|
||||
public class UnknownSenderView extends FrameLayout {
|
||||
@@ -61,22 +57,7 @@ public class UnknownSenderView extends FrameLayout {
|
||||
}
|
||||
|
||||
private void handleAdd() {
|
||||
Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
|
||||
intent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE);
|
||||
|
||||
if (!TextUtils.isEmpty(recipient.getProfileName())) {
|
||||
intent.putExtra(ContactsContract.Intents.Insert.NAME, recipient.getProfileName());
|
||||
}
|
||||
|
||||
if (recipient.getAddress().isEmail()) {
|
||||
intent.putExtra(ContactsContract.Intents.Insert.EMAIL, recipient.getAddress().toEmailString());
|
||||
}
|
||||
|
||||
if (recipient.getAddress().isPhone()) {
|
||||
intent.putExtra(ContactsContract.Intents.Insert.PHONE, recipient.getAddress().toPhoneString());
|
||||
}
|
||||
|
||||
getContext().startActivity(intent);
|
||||
getContext().startActivity(RecipientExporter.export(recipient).asAddContactIntent());
|
||||
if (threadId != -1) DatabaseFactory.getThreadDatabase(getContext()).setHasSent(threadId, true);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package org.thoughtcrime.securesms.recipients;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.provider.ContactsContract;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import org.thoughtcrime.securesms.database.Address;
|
||||
|
||||
import static android.content.Intent.ACTION_INSERT_OR_EDIT;
|
||||
|
||||
public final class RecipientExporter {
|
||||
|
||||
public static RecipientExporter export(Recipient recipient) {
|
||||
return new RecipientExporter(recipient);
|
||||
}
|
||||
|
||||
private final Recipient recipient;
|
||||
|
||||
private RecipientExporter(Recipient recipient) {
|
||||
this.recipient = recipient;
|
||||
}
|
||||
|
||||
public Intent asAddContactIntent() {
|
||||
Intent intent = new Intent(ACTION_INSERT_OR_EDIT);
|
||||
intent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE);
|
||||
addNameToIntent(intent, recipient.getProfileName());
|
||||
addAddressToIntent(intent, recipient.getAddress());
|
||||
return intent;
|
||||
}
|
||||
|
||||
private static void addNameToIntent(Intent intent, String profileName) {
|
||||
if (!TextUtils.isEmpty(profileName)) {
|
||||
intent.putExtra(ContactsContract.Intents.Insert.NAME, profileName);
|
||||
}
|
||||
}
|
||||
|
||||
private static void addAddressToIntent(Intent intent, Address address) {
|
||||
if (address.isPhone()) {
|
||||
intent.putExtra(ContactsContract.Intents.Insert.PHONE, address.toPhoneString());
|
||||
} else if (address.isEmail()) {
|
||||
intent.putExtra(ContactsContract.Intents.Insert.EMAIL, address.toEmailString());
|
||||
} else {
|
||||
throw new RuntimeException("Cannot export Recipient with neither phone nor email");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user