mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
remove even more dead contact sharing code
This commit is contained in:
@@ -123,10 +123,6 @@ dependencies {
|
||||
compile 'com.codewaves.stickyheadergrid:stickyheadergrid:0.9.4'
|
||||
compile 'com.github.dmytrodanylyk.circular-progress-button:library:1.1.3-S2'
|
||||
compile 'org.signal:android-database-sqlcipher:3.5.9-S3'
|
||||
compile ('com.googlecode.ez-vcard:ez-vcard:0.9.11') {
|
||||
exclude group: 'com.fasterxml.jackson.core'
|
||||
exclude group: 'org.freemarker'
|
||||
}
|
||||
|
||||
testCompile 'junit:junit:4.12'
|
||||
testCompile 'org.assertj:assertj-core:1.7.1'
|
||||
@@ -193,7 +189,6 @@ dependencyVerification {
|
||||
'com.takisoft.fix:colorpicker:f5d0dbabe406a1800498ca9c1faf34db36e021d8488bf10360f29961fe3ab0d1',
|
||||
'com.github.dmytrodanylyk.circular-progress-button:library:8dc6a29a5a8db7b2ad5a9a7fda1dc9ae0893f4c8f0545732b2c63854ea693e8e',
|
||||
'org.signal:android-database-sqlcipher:33d4063336893af00b9d68b418e7b290cace74c20ce8aacffddc0911010d3d73',
|
||||
'com.googlecode.ez-vcard:ez-vcard:7e24ad50b222d2f70ac91bdccfa3c0f6200b078d797cb784837f75e77bb4210f',
|
||||
'com.google.android.gms:play-services-iid:54e919f9957b8b7820da7ee9b83471d00d0cac1cf08ddea8b5b41aea80bb1a70',
|
||||
'com.google.android.gms:play-services-base:0ca636a8fc9a5af45e607cdcd61783bf5d561cbbb0f862021ce69606eee5ad49',
|
||||
'com.google.android.gms:play-services-tasks:69ec265168e601d0203d04cd42e34bb019b2f029aa1e16fabd38a5153eea2086',
|
||||
@@ -223,7 +218,6 @@ dependencyVerification {
|
||||
'com.nineoldandroids:library:68025a14e3e7673d6ad2f95e4b46d78d7d068343aa99256b686fe59de1b3163a',
|
||||
'com.klinkerapps:logger:177e325259a8b111ad6745ec10db5861723c99f402222b80629f576f49408541',
|
||||
'com.google.android:flexbox:a9989fd13ae2ee42765dfc515fe362edf4f326e74925d02a10369df8092a4935',
|
||||
'org.jsoup:jsoup:abeaf34795a4de70f72aed6de5966d2955ec7eb348eeb813324f23c999575473',
|
||||
'org.whispersystems:curve25519-android:82595394422b957d4a5b5f1b27b75ba25cf6dc4db4d312418ca38cd6fff279ca',
|
||||
'org.whispersystems:signal-protocol-java:5152c2b01a25147967d6bf82e540f947901bdfa79260be3eb3e96b03f787d6b5',
|
||||
'com.google.protobuf:protobuf-java:e0c1c64575c005601725e7c6a02cebf9e1285e888f756b2a1d73ffa8d725cc74',
|
||||
@@ -313,7 +307,6 @@ android {
|
||||
'proguard-klinker.pro',
|
||||
'proguard-retrolambda.pro',
|
||||
'proguard-okhttp.pro',
|
||||
'proguard-ez-vcard.pro',
|
||||
'proguard.cfg'
|
||||
testProguardFiles 'proguard-automation.pro',
|
||||
'proguard.cfg'
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
-dontwarn ezvcard.io.html.HCardPage
|
||||
@@ -101,14 +101,6 @@
|
||||
app:quote_colorSecondary="?attr/conversation_item_quote_text_color"
|
||||
tools:visibility="visible"/>
|
||||
|
||||
<ViewStub
|
||||
android:id="@+id/shared_contact_view_stub"
|
||||
android:layout="@layout/conversation_item_received_shared_contact"
|
||||
android:layout_width="@dimen/media_bubble_default_dimens"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/message_bubble_top_padding"
|
||||
android:visibility="gone"/>
|
||||
|
||||
<ViewStub
|
||||
android:id="@+id/image_view_stub"
|
||||
android:layout_width="wrap_content"
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<org.thoughtcrime.securesms.components.SharedContactView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/shared_contact_view"
|
||||
android:layout_width="@dimen/media_bubble_default_dimens"
|
||||
android:layout_height="wrap_content"
|
||||
app:contact_titleColor="?conversation_item_received_text_primary_color"
|
||||
app:contact_captionColor="?conversation_item_received_text_secondary_color"
|
||||
app:contact_footerIconColor="?conversation_item_received_text_secondary_color"
|
||||
app:contact_footerAlpha="0.7"/>
|
||||
@@ -51,14 +51,6 @@
|
||||
app:quote_colorSecondary="?attr/conversation_item_quote_text_color"
|
||||
tools:visibility="visible"/>
|
||||
|
||||
<ViewStub
|
||||
android:id="@+id/shared_contact_view_stub"
|
||||
android:layout="@layout/conversation_item_sent_shared_contact"
|
||||
android:layout_width="@dimen/media_bubble_default_dimens"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/message_bubble_top_padding"
|
||||
android:visibility="gone"/>
|
||||
|
||||
<ViewStub
|
||||
android:id="@+id/image_view_stub"
|
||||
android:layout_width="wrap_content"
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<org.thoughtcrime.securesms.components.SharedContactView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/shared_contact_view"
|
||||
android:layout_width="@dimen/media_bubble_default_dimens"
|
||||
android:layout_height="wrap_content"
|
||||
app:contact_titleColor="?conversation_item_sent_text_primary_color"
|
||||
app:contact_captionColor="?conversation_item_sent_text_secondary_color"
|
||||
app:contact_footerIconColor="?conversation_item_sent_icon_color"/>
|
||||
@@ -1,87 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<merge
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="@dimen/message_bubble_horizontal_padding"
|
||||
android:layout_marginRight="@dimen/message_bubble_horizontal_padding"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/contact_avatar"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginRight="8dp"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical">
|
||||
|
||||
<org.thoughtcrime.securesms.components.emoji.EmojiTextView
|
||||
android:id="@+id/contact_name"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="4dp"
|
||||
style="@style/Signal.Text.Body"
|
||||
android:maxLines="1"
|
||||
android:ellipsize="end"
|
||||
android:fontFamily="sans-serif-medium"
|
||||
android:textSize="16sp"
|
||||
tools:text="Peter Parker"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/contact_number"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/Signal.Text.Caption"
|
||||
android:maxLines="1"
|
||||
android:ellipsize="end"
|
||||
android:textColor="@color/grey_600"
|
||||
tools:text="(610) 555-5555"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<org.thoughtcrime.securesms.components.ConversationItemFooter
|
||||
android:id="@+id/contact_footer"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="@dimen/message_bubble_horizontal_padding"
|
||||
android:layout_marginRight="@dimen/message_bubble_horizontal_padding"
|
||||
android:layout_marginTop="4dp"
|
||||
android:elevation="9dp"
|
||||
android:orientation="horizontal" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/contact_action_button"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/message_bubble_bottom_padding"
|
||||
android:gravity="center"
|
||||
android:padding="10dp"
|
||||
style="@style/Signal.Text.Preview"
|
||||
android:maxLines="1"
|
||||
android:ellipsize="end"
|
||||
android:fontFamily="sans-serif-medium"
|
||||
android:textColor="@color/core_blue"
|
||||
android:background="?attr/shared_contact_item_button_color"
|
||||
android:foreground="?attr/selectableItemBackground"
|
||||
tools:text="Add to Contacts"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</merge>
|
||||
@@ -251,13 +251,6 @@
|
||||
<attr name="quote_colorSecondary" format="color" />
|
||||
</declare-styleable>
|
||||
|
||||
<declare-styleable name="SharedContactView">
|
||||
<attr name="contact_titleColor" format="color" />
|
||||
<attr name="contact_captionColor" format="color" />
|
||||
<attr name="contact_footerIconColor" format="color" />
|
||||
<attr name="contact_footerAlpha" format="float" />
|
||||
</declare-styleable>
|
||||
|
||||
<declare-styleable name="DocumentView">
|
||||
<attr name="doc_titleColor" format="color" />
|
||||
<attr name="doc_captionColor" format="color" />
|
||||
|
||||
@@ -29,7 +29,6 @@ public interface BindableConversationItem extends Unbindable {
|
||||
void setEventListener(@Nullable EventListener listener);
|
||||
|
||||
interface EventListener {
|
||||
void onAddToContactsClicked(@NonNull Contact contact);
|
||||
void onMessageSharedContactClicked(@NonNull List<Recipient> choices);
|
||||
void onInviteSharedContactClicked(@NonNull List<Recipient> choices);
|
||||
}
|
||||
|
||||
@@ -80,7 +80,6 @@ import org.thoughtcrime.securesms.components.camera.QuickAttachmentDrawer;
|
||||
import org.thoughtcrime.securesms.components.camera.QuickAttachmentDrawer.AttachmentDrawerListener;
|
||||
import org.thoughtcrime.securesms.components.camera.QuickAttachmentDrawer.DrawerState;
|
||||
import org.thoughtcrime.securesms.components.emoji.EmojiDrawer;
|
||||
import org.thoughtcrime.securesms.components.emoji.EmojiStrings;
|
||||
import org.thoughtcrime.securesms.components.location.SignalPlace;
|
||||
import org.thoughtcrime.securesms.components.reminder.ExpiredBuildReminder;
|
||||
import org.thoughtcrime.securesms.components.reminder.ReminderView;
|
||||
@@ -88,13 +87,9 @@ import org.thoughtcrime.securesms.connect.ApplicationDcContext;
|
||||
import org.thoughtcrime.securesms.connect.DcHelper;
|
||||
import org.thoughtcrime.securesms.contacts.ContactAccessor;
|
||||
import org.thoughtcrime.securesms.contacts.ContactAccessor.ContactData;
|
||||
import org.thoughtcrime.securesms.contactshare.Contact;
|
||||
import org.thoughtcrime.securesms.contactshare.ContactUtil;
|
||||
import org.thoughtcrime.securesms.database.Address;
|
||||
import org.thoughtcrime.securesms.database.DraftDatabase.Draft;
|
||||
import org.thoughtcrime.securesms.database.DraftDatabase.Drafts;
|
||||
import org.thoughtcrime.securesms.database.model.MessageRecord;
|
||||
import org.thoughtcrime.securesms.database.model.MmsMessageRecord;
|
||||
import org.thoughtcrime.securesms.mms.AttachmentManager;
|
||||
import org.thoughtcrime.securesms.mms.AttachmentManager.MediaType;
|
||||
import org.thoughtcrime.securesms.mms.AudioSlide;
|
||||
@@ -1432,36 +1427,36 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
|
||||
@Override
|
||||
public void handleReplyMessage(MessageRecord messageRecord) {
|
||||
Recipient author;
|
||||
|
||||
if (messageRecord.isOutgoing()) {
|
||||
author = Recipient.from(this, Address.fromSerialized(Prefs.getLocalNumber(this)), true);
|
||||
} else {
|
||||
author = messageRecord.getIndividualRecipient();
|
||||
}
|
||||
|
||||
if (messageRecord.isMms() && !((MmsMessageRecord) messageRecord).getSharedContacts().isEmpty()) {
|
||||
Contact contact = ((MmsMessageRecord) messageRecord).getSharedContacts().get(0);
|
||||
String displayName = ContactUtil.getDisplayName(contact);
|
||||
String body = getString(R.string.ConversationActivity_quoted_contact_message, EmojiStrings.BUST_IN_SILHOUETTE, displayName);
|
||||
SlideDeck slideDeck = new SlideDeck();
|
||||
|
||||
if (contact.getAvatarAttachment() != null) {
|
||||
slideDeck.addSlide(MediaUtil.getSlideForAttachment(this, contact.getAvatarAttachment()));
|
||||
}
|
||||
|
||||
inputPanel.setQuote(GlideApp.with(this),
|
||||
messageRecord.getDateSent(),
|
||||
author,
|
||||
body,
|
||||
slideDeck);
|
||||
} else {
|
||||
inputPanel.setQuote(GlideApp.with(this),
|
||||
messageRecord.getDateSent(),
|
||||
author,
|
||||
messageRecord.getBody(),
|
||||
messageRecord.isMms() ? ((MmsMessageRecord) messageRecord).getSlideDeck() : new SlideDeck());
|
||||
}
|
||||
// Recipient author;
|
||||
//
|
||||
// if (messageRecord.isOutgoing()) {
|
||||
// author = Recipient.from(this, Address.fromSerialized(Prefs.getLocalNumber(this)), true);
|
||||
// } else {
|
||||
// author = messageRecord.getIndividualRecipient();
|
||||
// }
|
||||
//
|
||||
// if (messageRecord.isMms() && !((MmsMessageRecord) messageRecord).getSharedContacts().isEmpty()) {
|
||||
// Contact contact = ((MmsMessageRecord) messageRecord).getSharedContacts().get(0);
|
||||
// String displayName = ContactUtil.getDisplayName(contact);
|
||||
// String body = getString(R.string.ConversationActivity_quoted_contact_message, EmojiStrings.BUST_IN_SILHOUETTE, displayName);
|
||||
// SlideDeck slideDeck = new SlideDeck();
|
||||
//
|
||||
// if (contact.getAvatarAttachment() != null) {
|
||||
// slideDeck.addSlide(MediaUtil.getSlideForAttachment(this, contact.getAvatarAttachment()));
|
||||
// }
|
||||
//
|
||||
// inputPanel.setQuote(GlideApp.with(this),
|
||||
// messageRecord.getDateSent(),
|
||||
// author,
|
||||
// body,
|
||||
// slideDeck);
|
||||
// } else {
|
||||
// inputPanel.setQuote(GlideApp.with(this),
|
||||
// messageRecord.getDateSent(),
|
||||
// author,
|
||||
// messageRecord.getBody(),
|
||||
// messageRecord.isMms() ? ((MmsMessageRecord) messageRecord).getSlideDeck() : new SlideDeck());
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -65,14 +65,11 @@ import org.thoughtcrime.securesms.ConversationAdapter.ItemClickListener;
|
||||
import org.thoughtcrime.securesms.connect.ApplicationDcContext;
|
||||
import org.thoughtcrime.securesms.connect.DcHelper;
|
||||
import org.thoughtcrime.securesms.connect.DcMsgListLoader;
|
||||
import org.thoughtcrime.securesms.contactshare.Contact;
|
||||
import org.thoughtcrime.securesms.contactshare.ContactUtil;
|
||||
import org.thoughtcrime.securesms.database.Address;
|
||||
import org.thoughtcrime.securesms.database.model.MessageRecord;
|
||||
import org.thoughtcrime.securesms.mms.GlideApp;
|
||||
import org.thoughtcrime.securesms.permissions.Permissions;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.util.CommunicationActions;
|
||||
import org.thoughtcrime.securesms.util.SaveAttachmentTask;
|
||||
import org.thoughtcrime.securesms.util.StickyHeaderDecoration;
|
||||
import org.thoughtcrime.securesms.util.ViewUtil;
|
||||
@@ -759,39 +756,22 @@ public class ConversationFragment extends Fragment
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAddToContactsClicked(@NonNull Contact contactWithAvatar) {
|
||||
if (getContext() != null) {
|
||||
new AsyncTask<Void, Void, Intent>() {
|
||||
@Override
|
||||
protected Intent doInBackground(Void... voids) {
|
||||
return ContactUtil.buildAddToContactsIntent(getContext(), contactWithAvatar);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Intent intent) {
|
||||
startActivityForResult(intent, CODE_ADD_EDIT_CONTACT);
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessageSharedContactClicked(@NonNull List<Recipient> choices) {
|
||||
if (getContext() == null) return;
|
||||
|
||||
ContactUtil.selectRecipientThroughDialog(getContext(), choices, locale, recipient -> {
|
||||
CommunicationActions.startConversation(getContext(), recipient, null);
|
||||
});
|
||||
// ContactUtil.selectRecipientThroughDialog(getContext(), choices, locale, recipient -> {
|
||||
// CommunicationActions.startConversation(getContext(), recipient, null);
|
||||
// });
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInviteSharedContactClicked(@NonNull List<Recipient> choices) {
|
||||
if (getContext() == null) return;
|
||||
|
||||
ContactUtil.selectRecipientThroughDialog(getContext(), choices, locale, recipient -> {
|
||||
CommunicationActions.composeSmsThroughDefaultApp(getContext(), recipient.getAddress(), getString(R.string.InviteActivity_lets_switch_to_signal, "https://sgnl.link/1KpeYmF"));
|
||||
});
|
||||
// ContactUtil.selectRecipientThroughDialog(getContext(), choices, locale, recipient -> {
|
||||
// CommunicationActions.composeSmsThroughDefaultApp(getContext(), recipient.getAddress(), getString(R.string.InviteActivity_lets_switch_to_signal, "https://sgnl.link/1KpeYmF"));
|
||||
// });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -48,10 +48,8 @@ import org.thoughtcrime.securesms.components.ConversationItemFooter;
|
||||
import org.thoughtcrime.securesms.components.ConversationItemThumbnail;
|
||||
import org.thoughtcrime.securesms.components.DocumentView;
|
||||
import org.thoughtcrime.securesms.components.QuoteView;
|
||||
import org.thoughtcrime.securesms.components.SharedContactView;
|
||||
import org.thoughtcrime.securesms.connect.ApplicationDcContext;
|
||||
import org.thoughtcrime.securesms.connect.DcHelper;
|
||||
import org.thoughtcrime.securesms.contactshare.Contact;
|
||||
import org.thoughtcrime.securesms.mms.AudioSlide;
|
||||
import org.thoughtcrime.securesms.mms.DocumentSlide;
|
||||
import org.thoughtcrime.securesms.mms.GlideRequests;
|
||||
@@ -67,7 +65,6 @@ import org.thoughtcrime.securesms.util.ViewUtil;
|
||||
import org.thoughtcrime.securesms.util.views.Stub;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -108,15 +105,12 @@ public class ConversationItem extends LinearLayout
|
||||
private @NonNull Stub<ConversationItemThumbnail> mediaThumbnailStub;
|
||||
private @NonNull Stub<AudioView> audioViewStub;
|
||||
private @NonNull Stub<DocumentView> documentViewStub;
|
||||
private @NonNull Stub<SharedContactView> sharedContactStub;
|
||||
private @Nullable EventListener eventListener;
|
||||
|
||||
private int defaultBubbleColor;
|
||||
private int measureCalls;
|
||||
|
||||
private final PassthroughClickListener passthroughClickListener = new PassthroughClickListener();
|
||||
private final SharedContactEventListener sharedContactEventListener = new SharedContactEventListener();
|
||||
private final SharedContactClickListener sharedContactClickListener = new SharedContactClickListener();
|
||||
|
||||
private final Context context;
|
||||
private final ApplicationDcContext dcContext;
|
||||
@@ -151,7 +145,6 @@ public class ConversationItem extends LinearLayout
|
||||
this.mediaThumbnailStub = new Stub<>(findViewById(R.id.image_view_stub));
|
||||
this.audioViewStub = new Stub<>(findViewById(R.id.audio_view_stub));
|
||||
this.documentViewStub = new Stub<>(findViewById(R.id.document_view_stub));
|
||||
this.sharedContactStub = new Stub<>(findViewById(R.id.shared_contact_view_stub));
|
||||
this.groupSenderHolder = findViewById(R.id.group_sender_holder);
|
||||
this.quoteView = findViewById(R.id.quote_view);
|
||||
this.container = findViewById(R.id.container);
|
||||
@@ -389,7 +382,6 @@ public class ConversationItem extends LinearLayout
|
||||
audioViewStub.get().setVisibility(View.VISIBLE);
|
||||
if (mediaThumbnailStub.resolved()) mediaThumbnailStub.get().setVisibility(View.GONE);
|
||||
if (documentViewStub.resolved()) documentViewStub.get().setVisibility(View.GONE);
|
||||
if (sharedContactStub.resolved()) sharedContactStub.get().setVisibility(GONE);
|
||||
|
||||
//noinspection ConstantConditions
|
||||
if(dcChat.getId() == DcChat.DC_CHAT_ID_DEADDROP) { // no audio on dead drops
|
||||
@@ -410,7 +402,6 @@ public class ConversationItem extends LinearLayout
|
||||
documentViewStub.get().setVisibility(View.VISIBLE);
|
||||
if (mediaThumbnailStub.resolved()) mediaThumbnailStub.get().setVisibility(View.GONE);
|
||||
if (audioViewStub.resolved()) audioViewStub.get().setVisibility(View.GONE);
|
||||
if (sharedContactStub.resolved()) sharedContactStub.get().setVisibility(GONE);
|
||||
|
||||
//noinspection ConstantConditions
|
||||
documentViewStub.get().setDocument(new DocumentSlide(context, messageRecord), showControls);
|
||||
@@ -425,7 +416,6 @@ public class ConversationItem extends LinearLayout
|
||||
mediaThumbnailStub.get().setVisibility(View.VISIBLE);
|
||||
if (audioViewStub.resolved()) audioViewStub.get().setVisibility(View.GONE);
|
||||
if (documentViewStub.resolved()) documentViewStub.get().setVisibility(View.GONE);
|
||||
if (sharedContactStub.resolved()) sharedContactStub.get().setVisibility(GONE);
|
||||
|
||||
//noinspection ConstantConditions
|
||||
mediaThumbnailStub.get().setImageResource(glideRequests,
|
||||
@@ -449,7 +439,6 @@ public class ConversationItem extends LinearLayout
|
||||
if (mediaThumbnailStub.resolved()) mediaThumbnailStub.get().setVisibility(View.GONE);
|
||||
if (audioViewStub.resolved()) audioViewStub.get().setVisibility(View.GONE);
|
||||
if (documentViewStub.resolved()) documentViewStub.get().setVisibility(View.GONE);
|
||||
if (sharedContactStub.resolved()) sharedContactStub.get().setVisibility(GONE);
|
||||
|
||||
ViewUtil.updateLayoutParams(bodyText, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
ViewUtil.updateLayoutParams(groupSenderHolder, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
@@ -491,10 +480,6 @@ public class ConversationItem extends LinearLayout
|
||||
mediaThumbnailStub.get().setOutlineCorners(topLeft, topRight, bottomRight, bottomLeft);
|
||||
}
|
||||
|
||||
private void setSharedContactCorners(@NonNull DcMsg current, boolean isGroupThread) {
|
||||
sharedContactStub.get().setSingularStyle();
|
||||
}
|
||||
|
||||
private void setContactPhoto() {
|
||||
if (contactPhoto == null) return;
|
||||
|
||||
@@ -578,7 +563,6 @@ public class ConversationItem extends LinearLayout
|
||||
ViewUtil.updateLayoutParams(footer, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
|
||||
|
||||
footer.setVisibility(GONE);
|
||||
if (sharedContactStub.resolved()) sharedContactStub.get().getFooter().setVisibility(GONE);
|
||||
if (mediaThumbnailStub.resolved()) mediaThumbnailStub.get().getFooter().setVisibility(GONE);
|
||||
|
||||
ConversationItemFooter activeFooter = getActiveFooter(current);
|
||||
@@ -644,46 +628,6 @@ public class ConversationItem extends LinearLayout
|
||||
|
||||
/// Event handlers
|
||||
|
||||
private class SharedContactEventListener implements SharedContactView.EventListener {
|
||||
@Override
|
||||
public void onAddToContactsClicked(@NonNull Contact contact) {
|
||||
if (eventListener != null && batchSelected.isEmpty()) {
|
||||
eventListener.onAddToContactsClicked(contact);
|
||||
} else {
|
||||
passthroughClickListener.onClick(sharedContactStub.get());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInviteClicked(@NonNull List<Recipient> choices) {
|
||||
if (eventListener != null && batchSelected.isEmpty()) {
|
||||
eventListener.onInviteSharedContactClicked(choices);
|
||||
} else {
|
||||
passthroughClickListener.onClick(sharedContactStub.get());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessageClicked(@NonNull List<Recipient> choices) {
|
||||
if (eventListener != null && batchSelected.isEmpty()) {
|
||||
eventListener.onMessageSharedContactClicked(choices);
|
||||
} else {
|
||||
passthroughClickListener.onClick(sharedContactStub.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class SharedContactClickListener implements View.OnClickListener {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
// if (eventListener != null && batchIsEmpty() && messageRecord.isMms() && !((MmsDcMsg) messageRecord).getSharedContacts().isEmpty()) {
|
||||
// eventListener.onSharedContactDetailsClicked(((MmsDcMsg) messageRecord).getSharedContacts().get(0), sharedContactStub.get().getAvatarView());
|
||||
// } else {
|
||||
passthroughClickListener.onClick(view);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
private void handleDeadDropClick() {
|
||||
new AlertDialog.Builder(context)
|
||||
.setPositiveButton(android.R.string.ok, (dialog, which) -> {
|
||||
|
||||
@@ -1,244 +0,0 @@
|
||||
package org.thoughtcrime.securesms.components;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.RequiresApi;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.annimon.stream.Stream;
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
||||
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.contactshare.ContactUtil;
|
||||
import org.thoughtcrime.securesms.contactshare.Contact;
|
||||
import org.thoughtcrime.securesms.database.RecipientDatabase;
|
||||
import org.thoughtcrime.securesms.mms.DecryptableStreamUriLoader.DecryptableUri;
|
||||
import org.thoughtcrime.securesms.mms.GlideRequests;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientModifiedListener;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
public class SharedContactView extends LinearLayout implements RecipientModifiedListener {
|
||||
|
||||
private ImageView avatarView;
|
||||
private TextView nameView;
|
||||
private TextView numberView;
|
||||
private TextView actionButtonView;
|
||||
private ConversationItemFooter footer;
|
||||
|
||||
private Contact contact;
|
||||
private Locale locale;
|
||||
private GlideRequests glideRequests;
|
||||
private EventListener eventListener;
|
||||
private CornerMask cornerMask;
|
||||
private int bigCornerRadius;
|
||||
private int smallCornerRadius;
|
||||
|
||||
private final Map<String, Recipient> activeRecipients = new HashMap<>();
|
||||
|
||||
public SharedContactView(Context context) {
|
||||
super(context);
|
||||
initialize(null);
|
||||
}
|
||||
|
||||
public SharedContactView(Context context, @Nullable AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
initialize(attrs);
|
||||
}
|
||||
|
||||
public SharedContactView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
initialize(attrs);
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
||||
public SharedContactView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
initialize(attrs);
|
||||
}
|
||||
|
||||
private void initialize(@Nullable AttributeSet attrs) {
|
||||
inflate(getContext(), R.layout.shared_contact_view, this);
|
||||
|
||||
avatarView = findViewById(R.id.contact_avatar);
|
||||
nameView = findViewById(R.id.contact_name);
|
||||
numberView = findViewById(R.id.contact_number);
|
||||
actionButtonView = findViewById(R.id.contact_action_button);
|
||||
footer = findViewById(R.id.contact_footer);
|
||||
|
||||
cornerMask = new CornerMask(this);
|
||||
bigCornerRadius = getResources().getDimensionPixelOffset(R.dimen.message_corner_radius);
|
||||
smallCornerRadius = getResources().getDimensionPixelOffset(R.dimen.message_corner_collapse_radius);
|
||||
|
||||
if (attrs != null) {
|
||||
TypedArray typedArray = getContext().getTheme().obtainStyledAttributes(attrs, R.styleable.SharedContactView, 0, 0);
|
||||
int titleColor = typedArray.getInt(R.styleable.SharedContactView_contact_titleColor, Color.BLACK);
|
||||
int captionColor = typedArray.getInt(R.styleable.SharedContactView_contact_captionColor, Color.BLACK);
|
||||
int iconColor = typedArray.getInt(R.styleable.SharedContactView_contact_footerIconColor, Color.BLACK);
|
||||
float footerAlpha = typedArray.getFloat(R.styleable.SharedContactView_contact_footerAlpha, 1);
|
||||
typedArray.recycle();
|
||||
|
||||
nameView.setTextColor(titleColor);
|
||||
numberView.setTextColor(captionColor);
|
||||
footer.setTextColor(captionColor);
|
||||
footer.setIconColor(iconColor);
|
||||
footer.setAlpha(footerAlpha);
|
||||
}
|
||||
|
||||
if (cornerMask.isLegacy()) {
|
||||
setWillNotDraw(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
if (cornerMask.isLegacy()) {
|
||||
cornerMask.mask(canvas);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void dispatchDraw(Canvas canvas) {
|
||||
super.dispatchDraw(canvas);
|
||||
if (!cornerMask.isLegacy()) {
|
||||
cornerMask.mask(canvas);
|
||||
}
|
||||
}
|
||||
|
||||
public void setContact(@NonNull Contact contact, @NonNull GlideRequests glideRequests, @NonNull Locale locale) {
|
||||
this.glideRequests = glideRequests;
|
||||
this.locale = locale;
|
||||
this.contact = contact;
|
||||
|
||||
Stream.of(activeRecipients.values()).forEach(recipient -> recipient.removeListener(this));
|
||||
this.activeRecipients.clear();
|
||||
|
||||
presentContact(contact);
|
||||
presentAvatar(contact.getAvatarAttachment() != null ? contact.getAvatarAttachment().getDataUri() : null);
|
||||
presentActionButtons(ContactUtil.getRecipients(getContext(), contact));
|
||||
}
|
||||
|
||||
public void setSingularStyle() {
|
||||
cornerMask.setBottomLeftRadius(bigCornerRadius);
|
||||
cornerMask.setBottomRightRadius(bigCornerRadius);
|
||||
}
|
||||
|
||||
public void setClusteredIncomingStyle() {
|
||||
cornerMask.setBottomLeftRadius(smallCornerRadius);
|
||||
cornerMask.setBottomRightRadius(bigCornerRadius);
|
||||
}
|
||||
|
||||
public void setClusteredOutgoingStyle() {
|
||||
cornerMask.setBottomLeftRadius(bigCornerRadius);
|
||||
cornerMask.setBottomRightRadius(smallCornerRadius);
|
||||
}
|
||||
|
||||
public void setEventListener(@NonNull EventListener eventListener) {
|
||||
this.eventListener = eventListener;
|
||||
}
|
||||
|
||||
public @NonNull View getAvatarView() {
|
||||
return avatarView;
|
||||
}
|
||||
|
||||
public ConversationItemFooter getFooter() {
|
||||
return footer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onModified(Recipient recipient) {
|
||||
Util.runOnMain(() -> presentActionButtons(Collections.singletonList(recipient)));
|
||||
}
|
||||
|
||||
private void presentContact(@Nullable Contact contact) {
|
||||
if (contact != null) {
|
||||
nameView.setText(ContactUtil.getDisplayName(contact));
|
||||
numberView.setText(ContactUtil.getDisplayNumber(contact, locale));
|
||||
} else {
|
||||
nameView.setText("");
|
||||
numberView.setText("");
|
||||
}
|
||||
}
|
||||
|
||||
private void presentAvatar(@Nullable Uri uri) {
|
||||
if (uri != null) {
|
||||
glideRequests.load(new DecryptableUri(uri))
|
||||
.fallback(R.drawable.ic_contact_picture)
|
||||
.circleCrop()
|
||||
.diskCacheStrategy(DiskCacheStrategy.ALL)
|
||||
.dontAnimate()
|
||||
.into(avatarView);
|
||||
} else {
|
||||
glideRequests.load(R.drawable.ic_contact_picture)
|
||||
.circleCrop()
|
||||
.diskCacheStrategy(DiskCacheStrategy.ALL)
|
||||
.into(avatarView);
|
||||
}
|
||||
}
|
||||
|
||||
private void presentActionButtons(@NonNull List<Recipient> recipients) {
|
||||
for (Recipient recipient : recipients) {
|
||||
activeRecipients.put(recipient.getAddress().serialize(), recipient);
|
||||
}
|
||||
|
||||
List<Recipient> pushUsers = new ArrayList<>(recipients.size());
|
||||
List<Recipient> systemUsers = new ArrayList<>(recipients.size());
|
||||
|
||||
for (Recipient recipient : activeRecipients.values()) {
|
||||
recipient.addListener(this);
|
||||
|
||||
if (recipient.getRegistered() == RecipientDatabase.RegisteredState.REGISTERED) {
|
||||
pushUsers.add(recipient);
|
||||
} else if (recipient.isSystemContact()) {
|
||||
systemUsers.add(recipient);
|
||||
}
|
||||
}
|
||||
|
||||
if (!pushUsers.isEmpty()) {
|
||||
actionButtonView.setText(R.string.SharedContactView_message);
|
||||
actionButtonView.setOnClickListener(v -> {
|
||||
if (eventListener != null) {
|
||||
eventListener.onMessageClicked(pushUsers);
|
||||
}
|
||||
});
|
||||
} else if (!systemUsers.isEmpty()) {
|
||||
actionButtonView.setText(R.string.SharedContactView_invite_to_signal);
|
||||
actionButtonView.setOnClickListener(v -> {
|
||||
if (eventListener != null) {
|
||||
eventListener.onInviteClicked(systemUsers);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
actionButtonView.setText(R.string.SharedContactView_add_to_contacts);
|
||||
actionButtonView.setOnClickListener(v -> {
|
||||
if (eventListener != null && contact != null) {
|
||||
eventListener.onAddToContactsClicked(contact);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public interface EventListener {
|
||||
void onAddToContactsClicked(@NonNull Contact contact);
|
||||
void onInviteClicked(@NonNull List<Recipient> choices);
|
||||
void onMessageClicked(@NonNull List<Recipient> choices);
|
||||
}
|
||||
}
|
||||
@@ -1,138 +0,0 @@
|
||||
package org.thoughtcrime.securesms.contactshare;
|
||||
|
||||
import android.arch.lifecycle.LiveData;
|
||||
import android.arch.lifecycle.MutableLiveData;
|
||||
import android.arch.lifecycle.ViewModel;
|
||||
import android.os.Build;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import static org.thoughtcrime.securesms.contactshare.Contact.*;
|
||||
|
||||
public class ContactNameEditViewModel extends ViewModel {
|
||||
|
||||
private final MutableLiveData<String> displayName;
|
||||
|
||||
private String givenName;
|
||||
private String familyName;
|
||||
private String middleName;
|
||||
private String prefix;
|
||||
private String suffix;
|
||||
|
||||
public ContactNameEditViewModel() {
|
||||
this.displayName = new MutableLiveData<>();
|
||||
}
|
||||
|
||||
void setName(@NonNull Name name) {
|
||||
givenName = name.getGivenName();
|
||||
familyName = name.getFamilyName();
|
||||
middleName = name.getMiddleName();
|
||||
prefix = name.getPrefix();
|
||||
suffix = name.getSuffix();
|
||||
|
||||
displayName.postValue(buildDisplayName());
|
||||
}
|
||||
|
||||
Name getName() {
|
||||
return new Name(displayName.getValue(), givenName, familyName, prefix, suffix, middleName);
|
||||
}
|
||||
|
||||
LiveData<String> getDisplayName() {
|
||||
return displayName;
|
||||
}
|
||||
|
||||
void updateGivenName(@NonNull String givenName) {
|
||||
this.givenName = givenName;
|
||||
displayName.postValue(buildDisplayName());
|
||||
}
|
||||
|
||||
void updateFamilyName(@NonNull String familyName) {
|
||||
this.familyName = familyName;
|
||||
displayName.postValue(buildDisplayName());
|
||||
}
|
||||
|
||||
void updatePrefix(@NonNull String prefix) {
|
||||
this.prefix = prefix;
|
||||
displayName.postValue(buildDisplayName());
|
||||
}
|
||||
|
||||
void updateSuffix(@NonNull String suffix) {
|
||||
this.suffix = suffix;
|
||||
displayName.postValue(buildDisplayName());
|
||||
}
|
||||
|
||||
void updateMiddleName(@NonNull String middleName) {
|
||||
this.middleName = middleName;
|
||||
displayName.postValue(buildDisplayName());
|
||||
}
|
||||
|
||||
private String buildDisplayName() {
|
||||
boolean isCJKV = isCJKV(givenName) && isCJKV(middleName) && isCJKV(familyName) && isCJKV(prefix) && isCJKV(suffix);
|
||||
if (isCJKV) {
|
||||
return joinString(familyName, givenName, prefix, suffix, middleName);
|
||||
}
|
||||
return joinString(prefix, givenName, middleName, familyName, suffix);
|
||||
}
|
||||
|
||||
private String joinString(String... values) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
for (String value : values) {
|
||||
if (!TextUtils.isEmpty(value)) {
|
||||
builder.append(value).append(' ');
|
||||
}
|
||||
}
|
||||
|
||||
return builder.toString().trim();
|
||||
}
|
||||
|
||||
private boolean isCJKV(@Nullable String value) {
|
||||
if (TextUtils.isEmpty(value)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (int offset = 0; offset < value.length(); ) {
|
||||
int codepoint = Character.codePointAt(value, offset);
|
||||
|
||||
if (!isCodepointCJKV(codepoint)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
offset += Character.charCount(codepoint);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean isCodepointCJKV(int codepoint) {
|
||||
if (codepoint == (int)' ') return true;
|
||||
|
||||
Character.UnicodeBlock block = Character.UnicodeBlock.of(codepoint);
|
||||
|
||||
boolean isCJKV = Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS.equals(block) ||
|
||||
Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A.equals(block) ||
|
||||
Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_B.equals(block) ||
|
||||
Character.UnicodeBlock.CJK_COMPATIBILITY.equals(block) ||
|
||||
Character.UnicodeBlock.CJK_COMPATIBILITY_FORMS.equals(block) ||
|
||||
Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS.equals(block) ||
|
||||
Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS_SUPPLEMENT.equals(block) ||
|
||||
Character.UnicodeBlock.CJK_RADICALS_SUPPLEMENT.equals(block) ||
|
||||
Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION.equals(block) ||
|
||||
Character.UnicodeBlock.ENCLOSED_CJK_LETTERS_AND_MONTHS.equals(block) ||
|
||||
Character.UnicodeBlock.KANGXI_RADICALS.equals(block) ||
|
||||
Character.UnicodeBlock.IDEOGRAPHIC_DESCRIPTION_CHARACTERS.equals(block) ||
|
||||
Character.UnicodeBlock.HIRAGANA.equals(block) ||
|
||||
Character.UnicodeBlock.KATAKANA.equals(block) ||
|
||||
Character.UnicodeBlock.KATAKANA_PHONETIC_EXTENSIONS.equals(block) ||
|
||||
Character.UnicodeBlock.HANGUL_JAMO.equals(block) ||
|
||||
Character.UnicodeBlock.HANGUL_COMPATIBILITY_JAMO.equals(block) ||
|
||||
Character.UnicodeBlock.HANGUL_SYLLABLES.equals(block);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 19) {
|
||||
isCJKV |= Character.isIdeographic(codepoint);
|
||||
}
|
||||
|
||||
return isCJKV;
|
||||
}
|
||||
}
|
||||
@@ -1,389 +0,0 @@
|
||||
package org.thoughtcrime.securesms.contactshare;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.provider.ContactsContract;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.WorkerThread;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import org.thoughtcrime.securesms.contacts.ContactsDatabase;
|
||||
import org.thoughtcrime.securesms.contacts.avatars.ContactPhoto;
|
||||
import org.thoughtcrime.securesms.contactshare.Contact.Email;
|
||||
import org.thoughtcrime.securesms.contactshare.Contact.Name;
|
||||
import org.thoughtcrime.securesms.contactshare.Contact.Phone;
|
||||
import org.thoughtcrime.securesms.contactshare.Contact.PostalAddress;
|
||||
import org.thoughtcrime.securesms.database.Address;
|
||||
import org.thoughtcrime.securesms.mms.PartAuthority;
|
||||
import org.thoughtcrime.securesms.providers.PersistentBlobProvider;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import ezvcard.Ezvcard;
|
||||
import ezvcard.VCard;
|
||||
|
||||
import static org.thoughtcrime.securesms.contactshare.Contact.*;
|
||||
|
||||
public class ContactRepository {
|
||||
|
||||
private static final String TAG = ContactRepository.class.getSimpleName();
|
||||
|
||||
private final Context context;
|
||||
private final Executor executor;
|
||||
private final ContactsDatabase contactsDatabase;
|
||||
|
||||
ContactRepository(@NonNull Context context,
|
||||
@NonNull Executor executor,
|
||||
@NonNull ContactsDatabase contactsDatabase)
|
||||
{
|
||||
this.context = context.getApplicationContext();
|
||||
this.executor = executor;
|
||||
this.contactsDatabase = contactsDatabase;
|
||||
}
|
||||
|
||||
void getContacts(@NonNull List<Uri> contactUris, @NonNull ValueCallback<List<Contact>> callback) {
|
||||
executor.execute(() -> {
|
||||
List<Contact> contacts = new ArrayList<>(contactUris.size());
|
||||
for (Uri contactUri : contactUris) {
|
||||
Contact contact;
|
||||
|
||||
if (ContactsContract.AUTHORITY.equals(contactUri.getAuthority())) {
|
||||
contact = getContactFromSystemContacts(ContactUtil.getContactIdFromUri(contactUri));
|
||||
} else {
|
||||
contact = getContactFromVcard(contactUri);
|
||||
}
|
||||
|
||||
if (contact != null) {
|
||||
contacts.add(contact);
|
||||
}
|
||||
}
|
||||
callback.onComplete(contacts);
|
||||
});
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
private @Nullable Contact getContactFromSystemContacts(long contactId) {
|
||||
Name name = getName(contactId);
|
||||
if (name == null) {
|
||||
Log.w(TAG, "Couldn't find a name associated with the provided contact ID.");
|
||||
return null;
|
||||
}
|
||||
|
||||
List<Phone> phoneNumbers = getPhoneNumbers(contactId);
|
||||
AvatarInfo avatarInfo = getAvatarInfo(contactId, phoneNumbers);
|
||||
Avatar avatar = avatarInfo != null ? new Avatar(avatarInfo.uri, avatarInfo.isProfile) : null;
|
||||
|
||||
return new Contact(name, null, phoneNumbers, getEmails(contactId), getPostalAddresses(contactId), avatar);
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
private @Nullable Contact getContactFromVcard(@NonNull Uri uri) {
|
||||
Contact contact = null;
|
||||
|
||||
try (InputStream stream = PartAuthority.getAttachmentStream(context, uri)) {
|
||||
VCard vcard = Ezvcard.parse(stream).first();
|
||||
|
||||
ezvcard.property.StructuredName vName = vcard.getStructuredName();
|
||||
List<ezvcard.property.Telephone> vPhones = vcard.getTelephoneNumbers();
|
||||
List<ezvcard.property.Email> vEmails = vcard.getEmails();
|
||||
List<ezvcard.property.Address> vPostalAddresses = vcard.getAddresses();
|
||||
|
||||
String organization = vcard.getOrganization() != null && !vcard.getOrganization().getValues().isEmpty() ? vcard.getOrganization().getValues().get(0) : null;
|
||||
String displayName = vcard.getFormattedName() != null ? vcard.getFormattedName().getValue() : null;
|
||||
|
||||
if (displayName == null && vName != null) {
|
||||
displayName = vName.getGiven();
|
||||
}
|
||||
|
||||
if (displayName == null && vcard.getOrganization() != null) {
|
||||
displayName = organization;
|
||||
}
|
||||
|
||||
if (displayName == null) {
|
||||
throw new IOException("No valid name.");
|
||||
}
|
||||
|
||||
Name name = new Name(displayName,
|
||||
vName != null ? vName.getGiven() : null,
|
||||
vName != null ? vName.getFamily() : null,
|
||||
vName != null && !vName.getPrefixes().isEmpty() ? vName.getPrefixes().get(0) : null,
|
||||
vName != null && !vName.getSuffixes().isEmpty() ? vName.getSuffixes().get(0) : null,
|
||||
null);
|
||||
|
||||
|
||||
List<Phone> phoneNumbers = new ArrayList<>(vPhones.size());
|
||||
for (ezvcard.property.Telephone vEmail : vPhones) {
|
||||
String label = !vEmail.getTypes().isEmpty() ? getCleanedVcardType(vEmail.getTypes().get(0).getValue()) : null;
|
||||
phoneNumbers.add(new Phone(vEmail.getText(), phoneTypeFromVcardType(label), label));
|
||||
}
|
||||
|
||||
List<Email> emails = new ArrayList<>(vEmails.size());
|
||||
for (ezvcard.property.Email vEmail : vEmails) {
|
||||
String label = !vEmail.getTypes().isEmpty() ? getCleanedVcardType(vEmail.getTypes().get(0).getValue()) : null;
|
||||
emails.add(new Email(vEmail.getValue(), emailTypeFromVcardType(label), label));
|
||||
}
|
||||
|
||||
List<PostalAddress> postalAddresses = new ArrayList<>(vPostalAddresses.size());
|
||||
for (ezvcard.property.Address vPostalAddress : vPostalAddresses) {
|
||||
String label = !vPostalAddress.getTypes().isEmpty() ? getCleanedVcardType(vPostalAddress.getTypes().get(0).getValue()) : null;
|
||||
postalAddresses.add(new PostalAddress(postalAddressTypeFromVcardType(label),
|
||||
label,
|
||||
vPostalAddress.getStreetAddress(),
|
||||
vPostalAddress.getPoBox(),
|
||||
null,
|
||||
vPostalAddress.getLocality(),
|
||||
vPostalAddress.getRegion(),
|
||||
vPostalAddress.getPostalCode(),
|
||||
vPostalAddress.getCountry()));
|
||||
}
|
||||
|
||||
contact = new Contact(name, organization, phoneNumbers, emails, postalAddresses, null);
|
||||
} catch (IOException e) {
|
||||
Log.w(TAG, "Failed to parse the vcard.", e);
|
||||
}
|
||||
|
||||
if (PersistentBlobProvider.AUTHORITY.equals(uri.getAuthority())) {
|
||||
PersistentBlobProvider.getInstance(context).delete(context, uri);
|
||||
}
|
||||
|
||||
return contact;
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
private @Nullable Name getName(long contactId) {
|
||||
try (Cursor cursor = contactsDatabase.getNameDetails(contactId)) {
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
String cursorDisplayName = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME));
|
||||
String cursorGivenName = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME));
|
||||
String cursorFamilyName = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME));
|
||||
String cursorPrefix = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.StructuredName.PREFIX));
|
||||
String cursorSuffix = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.StructuredName.SUFFIX));
|
||||
String cursorMiddleName = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.StructuredName.MIDDLE_NAME));
|
||||
|
||||
Name name = new Name(cursorDisplayName, cursorGivenName, cursorFamilyName, cursorPrefix, cursorSuffix, cursorMiddleName);
|
||||
if (!name.isEmpty()) {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String org = contactsDatabase.getOrganizationName(contactId);
|
||||
if (!TextUtils.isEmpty(org)) {
|
||||
return new Name(org, org, null, null, null, null);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
private @NonNull List<Phone> getPhoneNumbers(long contactId) {
|
||||
Map<String, Phone> numberMap = new HashMap<>();
|
||||
try (Cursor cursor = contactsDatabase.getPhoneDetails(contactId)) {
|
||||
while (cursor != null && cursor.moveToNext()) {
|
||||
String cursorNumber = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.Phone.NUMBER));
|
||||
int cursorType = cursor.getInt(cursor.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.Phone.TYPE));
|
||||
String cursorLabel = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.Phone.LABEL));
|
||||
|
||||
String number = ContactUtil.getNormalizedPhoneNumber(context, cursorNumber);
|
||||
Phone existing = numberMap.get(number);
|
||||
Phone candidate = new Phone(number, phoneTypeFromContactType(cursorType), cursorLabel);
|
||||
|
||||
if (existing == null || (existing.getType() == Phone.Type.CUSTOM && existing.getLabel() == null)) {
|
||||
numberMap.put(number, candidate);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<Phone> numbers = new ArrayList<>(numberMap.size());
|
||||
numbers.addAll(numberMap.values());
|
||||
return numbers;
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
private @NonNull List<Email> getEmails(long contactId) {
|
||||
List<Email> emails = new LinkedList<>();
|
||||
|
||||
try (Cursor cursor = contactsDatabase.getEmailDetails(contactId)) {
|
||||
while (cursor != null && cursor.moveToNext()) {
|
||||
String cursorEmail = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.Email.ADDRESS));
|
||||
int cursorType = cursor.getInt(cursor.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.Email.TYPE));
|
||||
String cursorLabel = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.Email.LABEL));
|
||||
|
||||
emails.add(new Email(cursorEmail, emailTypeFromContactType(cursorType), cursorLabel));
|
||||
}
|
||||
}
|
||||
|
||||
return emails;
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
private @NonNull List<PostalAddress> getPostalAddresses(long contactId) {
|
||||
List<PostalAddress> postalAddresses = new LinkedList<>();
|
||||
|
||||
try (Cursor cursor = contactsDatabase.getPostalAddressDetails(contactId)) {
|
||||
while (cursor != null && cursor.moveToNext()) {
|
||||
int cursorType = cursor.getInt(cursor.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.StructuredPostal.TYPE));
|
||||
String cursorLabel = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.StructuredPostal.LABEL));
|
||||
String cursorStreet = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.StructuredPostal.STREET));
|
||||
String cursorPoBox = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.StructuredPostal.POBOX));
|
||||
String cursorNeighborhood = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.StructuredPostal.NEIGHBORHOOD));
|
||||
String cursorCity = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.StructuredPostal.CITY));
|
||||
String cursorRegion = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.StructuredPostal.REGION));
|
||||
String cursorPostal = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.StructuredPostal.POSTCODE));
|
||||
String cursorCountry = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.StructuredPostal.COUNTRY));
|
||||
|
||||
postalAddresses.add(new PostalAddress(postalAddressTypeFromContactType(cursorType),
|
||||
cursorLabel,
|
||||
cursorStreet,
|
||||
cursorPoBox,
|
||||
cursorNeighborhood,
|
||||
cursorCity,
|
||||
cursorRegion,
|
||||
cursorPostal,
|
||||
cursorCountry));
|
||||
}
|
||||
}
|
||||
|
||||
return postalAddresses;
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
private @Nullable AvatarInfo getAvatarInfo(long contactId, List<Phone> phoneNumbers) {
|
||||
AvatarInfo systemAvatar = getSystemAvatarInfo(contactId);
|
||||
|
||||
if (systemAvatar != null) {
|
||||
return systemAvatar;
|
||||
}
|
||||
|
||||
for (Phone phoneNumber : phoneNumbers) {
|
||||
AvatarInfo recipientAvatar = getRecipientAvatarInfo(Address.fromExternal(context, phoneNumber.getNumber()));
|
||||
if (recipientAvatar != null) {
|
||||
return recipientAvatar;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
private @Nullable AvatarInfo getSystemAvatarInfo(long contactId) {
|
||||
Uri uri = contactsDatabase.getAvatarUri(contactId);
|
||||
if (uri != null) {
|
||||
return new AvatarInfo(uri, false);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
private @Nullable AvatarInfo getRecipientAvatarInfo(@NonNull Address address) {
|
||||
Recipient recipient = Recipient.from(context, address, false);
|
||||
ContactPhoto contactPhoto = recipient.getContactPhoto(context);
|
||||
|
||||
if (contactPhoto != null) {
|
||||
Uri avatarUri = contactPhoto.getUri(context);
|
||||
if (avatarUri != null) {
|
||||
return new AvatarInfo(avatarUri, contactPhoto.isProfilePhoto());
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private Phone.Type phoneTypeFromContactType(int type) {
|
||||
switch (type) {
|
||||
case ContactsContract.CommonDataKinds.Phone.TYPE_HOME:
|
||||
return Phone.Type.HOME;
|
||||
case ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE:
|
||||
return Phone.Type.MOBILE;
|
||||
case ContactsContract.CommonDataKinds.Phone.TYPE_WORK:
|
||||
return Phone.Type.WORK;
|
||||
}
|
||||
return Phone.Type.CUSTOM;
|
||||
}
|
||||
|
||||
private Phone.Type phoneTypeFromVcardType(@Nullable String type) {
|
||||
if ("home".equalsIgnoreCase(type)) return Phone.Type.HOME;
|
||||
else if ("cell".equalsIgnoreCase(type)) return Phone.Type.MOBILE;
|
||||
else if ("work".equalsIgnoreCase(type)) return Phone.Type.WORK;
|
||||
else return Phone.Type.CUSTOM;
|
||||
}
|
||||
|
||||
private Email.Type emailTypeFromContactType(int type) {
|
||||
switch (type) {
|
||||
case ContactsContract.CommonDataKinds.Email.TYPE_HOME:
|
||||
return Email.Type.HOME;
|
||||
case ContactsContract.CommonDataKinds.Email.TYPE_MOBILE:
|
||||
return Email.Type.MOBILE;
|
||||
case ContactsContract.CommonDataKinds.Email.TYPE_WORK:
|
||||
return Email.Type.WORK;
|
||||
}
|
||||
return Email.Type.CUSTOM;
|
||||
}
|
||||
|
||||
private Email.Type emailTypeFromVcardType(@Nullable String type) {
|
||||
if ("home".equalsIgnoreCase(type)) return Email.Type.HOME;
|
||||
else if ("cell".equalsIgnoreCase(type)) return Email.Type.MOBILE;
|
||||
else if ("work".equalsIgnoreCase(type)) return Email.Type.WORK;
|
||||
else return Email.Type.CUSTOM;
|
||||
}
|
||||
|
||||
private PostalAddress.Type postalAddressTypeFromContactType(int type) {
|
||||
switch (type) {
|
||||
case ContactsContract.CommonDataKinds.StructuredPostal.TYPE_HOME:
|
||||
return PostalAddress.Type.HOME;
|
||||
case ContactsContract.CommonDataKinds.StructuredPostal.TYPE_WORK:
|
||||
return PostalAddress.Type.WORK;
|
||||
}
|
||||
return PostalAddress.Type.CUSTOM;
|
||||
}
|
||||
|
||||
private PostalAddress.Type postalAddressTypeFromVcardType(@Nullable String type) {
|
||||
if ("home".equalsIgnoreCase(type)) return PostalAddress.Type.HOME;
|
||||
else if ("work".equalsIgnoreCase(type)) return PostalAddress.Type.WORK;
|
||||
else return PostalAddress.Type.CUSTOM;
|
||||
}
|
||||
|
||||
private String getCleanedVcardType(@Nullable String type) {
|
||||
if (TextUtils.isEmpty(type)) return "";
|
||||
|
||||
if (type.startsWith("x-") && type.length() > 2) {
|
||||
return type.substring(2);
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
interface ValueCallback<T> {
|
||||
void onComplete(@NonNull T value);
|
||||
}
|
||||
|
||||
private static class AvatarInfo {
|
||||
|
||||
private final Uri uri;
|
||||
private final boolean isProfile;
|
||||
|
||||
private AvatarInfo(Uri uri, boolean isProfile) {
|
||||
this.uri = uri;
|
||||
this.isProfile = isProfile;
|
||||
}
|
||||
|
||||
public Uri getUri() {
|
||||
return uri;
|
||||
}
|
||||
|
||||
public boolean isProfile() {
|
||||
return isProfile;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,113 +0,0 @@
|
||||
package org.thoughtcrime.securesms.contactshare;
|
||||
|
||||
import android.arch.lifecycle.LiveData;
|
||||
import android.arch.lifecycle.MutableLiveData;
|
||||
import android.arch.lifecycle.ViewModel;
|
||||
import android.arch.lifecycle.ViewModelProvider;
|
||||
import android.net.Uri;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.annimon.stream.Stream;
|
||||
|
||||
import org.thoughtcrime.securesms.contactshare.Contact.Name;
|
||||
import org.thoughtcrime.securesms.util.SingleLiveEvent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
class ContactShareEditViewModel extends ViewModel {
|
||||
|
||||
private final MutableLiveData<List<Contact>> contacts;
|
||||
private final SingleLiveEvent<Event> events;
|
||||
private final ContactRepository repo;
|
||||
|
||||
ContactShareEditViewModel(@NonNull List<Uri> contactUris,
|
||||
@NonNull ContactRepository contactRepository)
|
||||
{
|
||||
contacts = new MutableLiveData<>();
|
||||
events = new SingleLiveEvent<>();
|
||||
repo = contactRepository;
|
||||
|
||||
repo.getContacts(contactUris, retrieved -> {
|
||||
if (retrieved.isEmpty()) {
|
||||
events.postValue(Event.BAD_CONTACT);
|
||||
} else {
|
||||
contacts.postValue(retrieved);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@NonNull LiveData<List<Contact>> getContacts() {
|
||||
return contacts;
|
||||
}
|
||||
|
||||
@NonNull List<Contact> getFinalizedContacts() {
|
||||
List<Contact> currentContacts = getCurrentContacts();
|
||||
List<Contact> trimmedContacts = new ArrayList<>(currentContacts.size());
|
||||
|
||||
for (Contact contact : currentContacts) {
|
||||
Contact trimmed = new Contact(contact.getName(),
|
||||
contact.getOrganization(),
|
||||
trimSelectables(contact.getPhoneNumbers()),
|
||||
trimSelectables(contact.getEmails()),
|
||||
trimSelectables(contact.getPostalAddresses()),
|
||||
contact.getAvatar() != null && contact.getAvatar().isSelected() ? contact.getAvatar() : null);
|
||||
trimmedContacts.add(trimmed);
|
||||
}
|
||||
|
||||
return trimmedContacts;
|
||||
}
|
||||
|
||||
@NonNull LiveData<Event> getEvents() {
|
||||
return events;
|
||||
}
|
||||
|
||||
void updateContactName(int contactPosition, @NonNull Name name) {
|
||||
if (name.isEmpty()) {
|
||||
events.postValue(Event.BAD_CONTACT);
|
||||
return;
|
||||
}
|
||||
|
||||
List<Contact> currentContacts = getCurrentContacts();
|
||||
Contact original = currentContacts.remove(contactPosition);
|
||||
|
||||
currentContacts.add(new Contact(name,
|
||||
original.getOrganization(),
|
||||
original.getPhoneNumbers(),
|
||||
original.getEmails(),
|
||||
original.getPostalAddresses(),
|
||||
original.getAvatar()));
|
||||
|
||||
contacts.postValue(currentContacts);
|
||||
}
|
||||
|
||||
private <E extends Selectable> List<E> trimSelectables(List<E> selectables) {
|
||||
return Stream.of(selectables).filter(Selectable::isSelected).toList();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private List<Contact> getCurrentContacts() {
|
||||
List<Contact> currentContacts = contacts.getValue();
|
||||
return currentContacts != null ? currentContacts : new ArrayList<>();
|
||||
}
|
||||
|
||||
enum Event {
|
||||
BAD_CONTACT
|
||||
}
|
||||
|
||||
static class Factory extends ViewModelProvider.NewInstanceFactory {
|
||||
|
||||
private final List<Uri> contactUris;
|
||||
private final ContactRepository contactRepository;
|
||||
|
||||
Factory(@NonNull List<Uri> contactUris, @NonNull ContactRepository contactRepository) {
|
||||
this.contactUris = contactUris;
|
||||
this.contactRepository = contactRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
|
||||
return modelClass.cast(new ContactShareEditViewModel(contactUris, contactRepository));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,235 +0,0 @@
|
||||
package org.thoughtcrime.securesms.contactshare;
|
||||
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.provider.ContactsContract;
|
||||
import android.support.annotation.MainThread;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.WorkerThread;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.annimon.stream.Stream;
|
||||
import com.google.i18n.phonenumbers.NumberParseException;
|
||||
import com.google.i18n.phonenumbers.PhoneNumberUtil;
|
||||
import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber;
|
||||
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.components.emoji.EmojiStrings;
|
||||
import org.thoughtcrime.securesms.contactshare.Contact.Email;
|
||||
import org.thoughtcrime.securesms.contactshare.Contact.Phone;
|
||||
import org.thoughtcrime.securesms.contactshare.Contact.PostalAddress;
|
||||
import org.thoughtcrime.securesms.database.Address;
|
||||
import org.thoughtcrime.securesms.mms.PartAuthority;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.util.SpanUtil;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public final class ContactUtil {
|
||||
|
||||
private static final String TAG = ContactUtil.class.getSimpleName();
|
||||
|
||||
public static long getContactIdFromUri(@NonNull Uri uri) {
|
||||
try {
|
||||
return Long.parseLong(uri.getLastPathSegment());
|
||||
} catch (NumberFormatException e) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
public static @NonNull CharSequence getStringSummary(@NonNull Context context, @NonNull Contact contact) {
|
||||
String contactName = ContactUtil.getDisplayName(contact);
|
||||
|
||||
if (!TextUtils.isEmpty(contactName)) {
|
||||
return context.getString(R.string.MessageNotifier_contact_message, EmojiStrings.BUST_IN_SILHOUETTE, contactName);
|
||||
}
|
||||
|
||||
return SpanUtil.italic(context.getString(R.string.MessageNotifier_unknown_contact_message));
|
||||
}
|
||||
|
||||
public static @NonNull String getDisplayName(@Nullable Contact contact) {
|
||||
if (contact == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
if (!TextUtils.isEmpty(contact.getName().getDisplayName())) {
|
||||
return contact.getName().getDisplayName();
|
||||
}
|
||||
|
||||
if (!TextUtils.isEmpty(contact.getOrganization())) {
|
||||
return contact.getOrganization();
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
public static @NonNull String getDisplayNumber(@NonNull Contact contact, @NonNull Locale locale) {
|
||||
Phone displayNumber = getPrimaryNumber(contact);
|
||||
|
||||
if (displayNumber != null) {
|
||||
return ContactUtil.getPrettyPhoneNumber(displayNumber, locale);
|
||||
} else if (contact.getEmails().size() > 0) {
|
||||
return contact.getEmails().get(0).getEmail();
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
private static @Nullable Phone getPrimaryNumber(@NonNull Contact contact) {
|
||||
if (contact.getPhoneNumbers().size() == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<Phone> mobileNumbers = Stream.of(contact.getPhoneNumbers()).filter(number -> number.getType() == Phone.Type.MOBILE).toList();
|
||||
if (mobileNumbers.size() > 0) {
|
||||
return mobileNumbers.get(0);
|
||||
}
|
||||
|
||||
return contact.getPhoneNumbers().get(0);
|
||||
}
|
||||
|
||||
public static @NonNull String getPrettyPhoneNumber(@NonNull Phone phoneNumber, @NonNull Locale fallbackLocale) {
|
||||
return getPrettyPhoneNumber(phoneNumber.getNumber(), fallbackLocale);
|
||||
}
|
||||
|
||||
private static @NonNull String getPrettyPhoneNumber(@NonNull String phoneNumber, @NonNull Locale fallbackLocale) {
|
||||
PhoneNumberUtil util = PhoneNumberUtil.getInstance();
|
||||
try {
|
||||
PhoneNumber parsed = util.parse(phoneNumber, fallbackLocale.getISO3Country());
|
||||
return util.format(parsed, PhoneNumberUtil.PhoneNumberFormat.INTERNATIONAL);
|
||||
} catch (NumberParseException e) {
|
||||
return phoneNumber;
|
||||
}
|
||||
}
|
||||
|
||||
public static @NonNull String getNormalizedPhoneNumber(@NonNull Context context, @NonNull String number) {
|
||||
Address address = Address.fromExternal(context, number);
|
||||
return address.serialize();
|
||||
}
|
||||
|
||||
@MainThread
|
||||
public static void selectRecipientThroughDialog(@NonNull Context context, @NonNull List<Recipient> choices, @NonNull Locale locale, @NonNull RecipientSelectedCallback callback) {
|
||||
if (choices.size() > 1) {
|
||||
CharSequence[] values = new CharSequence[choices.size()];
|
||||
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
values[i] = getPrettyPhoneNumber(choices.get(i).getAddress().toPhoneString(), locale);
|
||||
}
|
||||
|
||||
new AlertDialog.Builder(context)
|
||||
.setItems(values, ((dialog, which) -> callback.onSelected(choices.get(which))))
|
||||
.create()
|
||||
.show();
|
||||
} else {
|
||||
callback.onSelected(choices.get(0));
|
||||
}
|
||||
}
|
||||
|
||||
public static List<Recipient> getRecipients(@NonNull Context context, @NonNull Contact contact) {
|
||||
return Stream.of(contact.getPhoneNumbers()).map(phone -> Recipient.from(context, Address.fromExternal(context, phone.getNumber()), true)).toList();
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
public static @NonNull Intent buildAddToContactsIntent(@NonNull Context context, @NonNull Contact contact) {
|
||||
Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
|
||||
intent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE);
|
||||
|
||||
if (!TextUtils.isEmpty(contact.getName().getDisplayName())) {
|
||||
intent.putExtra(ContactsContract.Intents.Insert.NAME, contact.getName().getDisplayName());
|
||||
}
|
||||
|
||||
if (!TextUtils.isEmpty(contact.getOrganization())) {
|
||||
intent.putExtra(ContactsContract.Intents.Insert.COMPANY, contact.getOrganization());
|
||||
}
|
||||
|
||||
if (contact.getPhoneNumbers().size() > 0) {
|
||||
intent.putExtra(ContactsContract.Intents.Insert.PHONE, contact.getPhoneNumbers().get(0).getNumber());
|
||||
intent.putExtra(ContactsContract.Intents.Insert.PHONE_TYPE, getSystemType(contact.getPhoneNumbers().get(0).getType()));
|
||||
}
|
||||
|
||||
if (contact.getPhoneNumbers().size() > 1) {
|
||||
intent.putExtra(ContactsContract.Intents.Insert.SECONDARY_PHONE, contact.getPhoneNumbers().get(1).getNumber());
|
||||
intent.putExtra(ContactsContract.Intents.Insert.SECONDARY_PHONE_TYPE, getSystemType(contact.getPhoneNumbers().get(1).getType()));
|
||||
}
|
||||
|
||||
if (contact.getPhoneNumbers().size() > 2) {
|
||||
intent.putExtra(ContactsContract.Intents.Insert.TERTIARY_PHONE, contact.getPhoneNumbers().get(2).getNumber());
|
||||
intent.putExtra(ContactsContract.Intents.Insert.TERTIARY_PHONE_TYPE, getSystemType(contact.getPhoneNumbers().get(2).getType()));
|
||||
}
|
||||
|
||||
if (contact.getEmails().size() > 0) {
|
||||
intent.putExtra(ContactsContract.Intents.Insert.EMAIL, contact.getEmails().get(0).getEmail());
|
||||
intent.putExtra(ContactsContract.Intents.Insert.EMAIL_TYPE, getSystemType(contact.getEmails().get(0).getType()));
|
||||
}
|
||||
|
||||
if (contact.getEmails().size() > 1) {
|
||||
intent.putExtra(ContactsContract.Intents.Insert.SECONDARY_EMAIL, contact.getEmails().get(1).getEmail());
|
||||
intent.putExtra(ContactsContract.Intents.Insert.SECONDARY_EMAIL_TYPE, getSystemType(contact.getEmails().get(1).getType()));
|
||||
}
|
||||
|
||||
if (contact.getEmails().size() > 2) {
|
||||
intent.putExtra(ContactsContract.Intents.Insert.TERTIARY_EMAIL, contact.getEmails().get(2).getEmail());
|
||||
intent.putExtra(ContactsContract.Intents.Insert.TERTIARY_EMAIL_TYPE, getSystemType(contact.getEmails().get(2).getType()));
|
||||
}
|
||||
|
||||
if (contact.getPostalAddresses().size() > 0) {
|
||||
intent.putExtra(ContactsContract.Intents.Insert.POSTAL, contact.getPostalAddresses().get(0).toString());
|
||||
intent.putExtra(ContactsContract.Intents.Insert.POSTAL_TYPE, getSystemType(contact.getPostalAddresses().get(0).getType()));
|
||||
}
|
||||
|
||||
if (contact.getAvatarAttachment() != null && contact.getAvatarAttachment().getDataUri() != null) {
|
||||
try {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE);
|
||||
values.put(ContactsContract.CommonDataKinds.Photo.PHOTO, Util.readFully(PartAuthority.getAttachmentStream(context, contact.getAvatarAttachment().getDataUri())));
|
||||
|
||||
ArrayList<ContentValues> valuesArray = new ArrayList<>(1);
|
||||
valuesArray.add(values);
|
||||
|
||||
intent.putParcelableArrayListExtra(ContactsContract.Intents.Insert.DATA, valuesArray);
|
||||
} catch (IOException e) {
|
||||
Log.w(TAG, "Failed to read avatar into a byte array.", e);
|
||||
}
|
||||
}
|
||||
return intent;
|
||||
}
|
||||
|
||||
private static int getSystemType(Phone.Type type) {
|
||||
switch (type) {
|
||||
case HOME: return ContactsContract.CommonDataKinds.Phone.TYPE_HOME;
|
||||
case MOBILE: return ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE;
|
||||
case WORK: return ContactsContract.CommonDataKinds.Phone.TYPE_WORK;
|
||||
default: return ContactsContract.CommonDataKinds.Phone.TYPE_CUSTOM;
|
||||
}
|
||||
}
|
||||
|
||||
private static int getSystemType(Email.Type type) {
|
||||
switch (type) {
|
||||
case HOME: return ContactsContract.CommonDataKinds.Email.TYPE_HOME;
|
||||
case MOBILE: return ContactsContract.CommonDataKinds.Email.TYPE_MOBILE;
|
||||
case WORK: return ContactsContract.CommonDataKinds.Email.TYPE_WORK;
|
||||
default: return ContactsContract.CommonDataKinds.Email.TYPE_CUSTOM;
|
||||
}
|
||||
}
|
||||
|
||||
private static int getSystemType(PostalAddress.Type type) {
|
||||
switch (type) {
|
||||
case HOME: return ContactsContract.CommonDataKinds.StructuredPostal.TYPE_HOME;
|
||||
case WORK: return ContactsContract.CommonDataKinds.StructuredPostal.TYPE_WORK;
|
||||
default: return ContactsContract.CommonDataKinds.StructuredPostal.TYPE_CUSTOM;
|
||||
}
|
||||
}
|
||||
|
||||
public interface RecipientSelectedCallback {
|
||||
void onSelected(@NonNull Recipient recipient);
|
||||
}
|
||||
}
|
||||
@@ -30,22 +30,18 @@ import com.annimon.stream.Stream;
|
||||
|
||||
import net.sqlcipher.database.SQLiteDatabase;
|
||||
|
||||
import org.thoughtcrime.securesms.contactshare.Contact;
|
||||
import org.thoughtcrime.securesms.contactshare.ContactUtil;
|
||||
import org.thoughtcrime.securesms.database.GroupDatabase.GroupRecord;
|
||||
import org.thoughtcrime.securesms.database.MessagingDatabase.MarkedMessageInfo;
|
||||
import org.thoughtcrime.securesms.database.RecipientDatabase.RecipientSettings;
|
||||
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper;
|
||||
import org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord;
|
||||
import org.thoughtcrime.securesms.database.model.MessageRecord;
|
||||
import org.thoughtcrime.securesms.database.model.MmsMessageRecord;
|
||||
import org.thoughtcrime.securesms.database.model.ThreadRecord;
|
||||
import org.thoughtcrime.securesms.mms.Slide;
|
||||
import org.thoughtcrime.securesms.mms.SlideDeck;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.util.DelimiterUtil;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.thoughtcrime.securesms.util.Pair;
|
||||
import org.thoughtcrime.securesms.util.guava.Optional;
|
||||
|
||||
import java.io.Closeable;
|
||||
@@ -467,11 +463,6 @@ public class ThreadDatabase extends Database {
|
||||
}
|
||||
|
||||
private @NonNull String getFormattedBodyFor(@NonNull MessageRecord messageRecord) {
|
||||
if (messageRecord.isMms() && ((MmsMessageRecord) messageRecord).getSharedContacts().size() > 0) {
|
||||
Contact contact = ((MmsMessageRecord) messageRecord).getSharedContacts().get(0);
|
||||
return ContactUtil.getStringSummary(context, contact).toString();
|
||||
}
|
||||
|
||||
return messageRecord.getBody();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user