From b641a72de48687282c8c6efcc0b78fabedb7e2c4 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Sat, 1 Dec 2018 00:49:31 +0100 Subject: [PATCH] remove even more dead contact sharing code --- build.gradle | 7 - proguard-ez-vcard.pro | 1 - res/layout/conversation_item_received.xml | 8 - ...versation_item_received_shared_contact.xml | 11 - res/layout/conversation_item_sent.xml | 8 - .../conversation_item_sent_shared_contact.xml | 10 - res/layout/shared_contact_view.xml | 87 ---- res/values/attrs.xml | 7 - .../securesms/BindableConversationItem.java | 1 - .../securesms/ConversationActivity.java | 65 ++- .../securesms/ConversationFragment.java | 32 +- .../securesms/ConversationItem.java | 56 --- .../components/SharedContactView.java | 244 ----------- .../ContactNameEditViewModel.java | 138 ------- .../contactshare/ContactRepository.java | 389 ------------------ .../ContactShareEditViewModel.java | 113 ----- .../securesms/contactshare/ContactUtil.java | 235 ----------- .../securesms/database/ThreadDatabase.java | 9 - 18 files changed, 36 insertions(+), 1385 deletions(-) delete mode 100644 proguard-ez-vcard.pro delete mode 100644 res/layout/conversation_item_received_shared_contact.xml delete mode 100644 res/layout/conversation_item_sent_shared_contact.xml delete mode 100644 res/layout/shared_contact_view.xml delete mode 100644 src/org/thoughtcrime/securesms/components/SharedContactView.java delete mode 100644 src/org/thoughtcrime/securesms/contactshare/ContactNameEditViewModel.java delete mode 100644 src/org/thoughtcrime/securesms/contactshare/ContactRepository.java delete mode 100644 src/org/thoughtcrime/securesms/contactshare/ContactShareEditViewModel.java delete mode 100644 src/org/thoughtcrime/securesms/contactshare/ContactUtil.java diff --git a/build.gradle b/build.gradle index 139a69f3c..949c714d8 100644 --- a/build.gradle +++ b/build.gradle @@ -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' diff --git a/proguard-ez-vcard.pro b/proguard-ez-vcard.pro deleted file mode 100644 index 39be6827b..000000000 --- a/proguard-ez-vcard.pro +++ /dev/null @@ -1 +0,0 @@ --dontwarn ezvcard.io.html.HCardPage diff --git a/res/layout/conversation_item_received.xml b/res/layout/conversation_item_received.xml index 5c895bbac..ca824585b 100644 --- a/res/layout/conversation_item_received.xml +++ b/res/layout/conversation_item_received.xml @@ -101,14 +101,6 @@ app:quote_colorSecondary="?attr/conversation_item_quote_text_color" tools:visibility="visible"/> - - - diff --git a/res/layout/conversation_item_sent.xml b/res/layout/conversation_item_sent.xml index 257968a56..0200575c6 100644 --- a/res/layout/conversation_item_sent.xml +++ b/res/layout/conversation_item_sent.xml @@ -51,14 +51,6 @@ app:quote_colorSecondary="?attr/conversation_item_quote_text_color" tools:visibility="visible"/> - - - diff --git a/res/layout/shared_contact_view.xml b/res/layout/shared_contact_view.xml deleted file mode 100644 index 993adefa9..000000000 --- a/res/layout/shared_contact_view.xml +++ /dev/null @@ -1,87 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/res/values/attrs.xml b/res/values/attrs.xml index f5c71b15d..db922d0ff 100644 --- a/res/values/attrs.xml +++ b/res/values/attrs.xml @@ -251,13 +251,6 @@ - - - - - - - diff --git a/src/org/thoughtcrime/securesms/BindableConversationItem.java b/src/org/thoughtcrime/securesms/BindableConversationItem.java index 65cf792de..5b22caeaa 100644 --- a/src/org/thoughtcrime/securesms/BindableConversationItem.java +++ b/src/org/thoughtcrime/securesms/BindableConversationItem.java @@ -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 choices); void onInviteSharedContactClicked(@NonNull List choices); } diff --git a/src/org/thoughtcrime/securesms/ConversationActivity.java b/src/org/thoughtcrime/securesms/ConversationActivity.java index 9463d1fe4..e3667b4ac 100644 --- a/src/org/thoughtcrime/securesms/ConversationActivity.java +++ b/src/org/thoughtcrime/securesms/ConversationActivity.java @@ -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 diff --git a/src/org/thoughtcrime/securesms/ConversationFragment.java b/src/org/thoughtcrime/securesms/ConversationFragment.java index 0d1d96136..31e4a56bf 100644 --- a/src/org/thoughtcrime/securesms/ConversationFragment.java +++ b/src/org/thoughtcrime/securesms/ConversationFragment.java @@ -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() { - @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 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 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")); +// }); } } diff --git a/src/org/thoughtcrime/securesms/ConversationItem.java b/src/org/thoughtcrime/securesms/ConversationItem.java index 9e9b78cc6..7444538ce 100644 --- a/src/org/thoughtcrime/securesms/ConversationItem.java +++ b/src/org/thoughtcrime/securesms/ConversationItem.java @@ -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 mediaThumbnailStub; private @NonNull Stub audioViewStub; private @NonNull Stub documentViewStub; - private @NonNull Stub 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 choices) { - if (eventListener != null && batchSelected.isEmpty()) { - eventListener.onInviteSharedContactClicked(choices); - } else { - passthroughClickListener.onClick(sharedContactStub.get()); - } - } - - @Override - public void onMessageClicked(@NonNull List 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) -> { diff --git a/src/org/thoughtcrime/securesms/components/SharedContactView.java b/src/org/thoughtcrime/securesms/components/SharedContactView.java deleted file mode 100644 index 8d9beca37..000000000 --- a/src/org/thoughtcrime/securesms/components/SharedContactView.java +++ /dev/null @@ -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 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 recipients) { - for (Recipient recipient : recipients) { - activeRecipients.put(recipient.getAddress().serialize(), recipient); - } - - List pushUsers = new ArrayList<>(recipients.size()); - List 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 choices); - void onMessageClicked(@NonNull List choices); - } -} diff --git a/src/org/thoughtcrime/securesms/contactshare/ContactNameEditViewModel.java b/src/org/thoughtcrime/securesms/contactshare/ContactNameEditViewModel.java deleted file mode 100644 index a453001f5..000000000 --- a/src/org/thoughtcrime/securesms/contactshare/ContactNameEditViewModel.java +++ /dev/null @@ -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 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 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; - } -} diff --git a/src/org/thoughtcrime/securesms/contactshare/ContactRepository.java b/src/org/thoughtcrime/securesms/contactshare/ContactRepository.java deleted file mode 100644 index df476aca4..000000000 --- a/src/org/thoughtcrime/securesms/contactshare/ContactRepository.java +++ /dev/null @@ -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 contactUris, @NonNull ValueCallback> callback) { - executor.execute(() -> { - List 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 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 vPhones = vcard.getTelephoneNumbers(); - List vEmails = vcard.getEmails(); - List 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 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 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 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 getPhoneNumbers(long contactId) { - Map 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 numbers = new ArrayList<>(numberMap.size()); - numbers.addAll(numberMap.values()); - return numbers; - } - - @WorkerThread - private @NonNull List getEmails(long contactId) { - List 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 getPostalAddresses(long contactId) { - List 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 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 { - 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; - } - } -} diff --git a/src/org/thoughtcrime/securesms/contactshare/ContactShareEditViewModel.java b/src/org/thoughtcrime/securesms/contactshare/ContactShareEditViewModel.java deleted file mode 100644 index 2e76612e9..000000000 --- a/src/org/thoughtcrime/securesms/contactshare/ContactShareEditViewModel.java +++ /dev/null @@ -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> contacts; - private final SingleLiveEvent events; - private final ContactRepository repo; - - ContactShareEditViewModel(@NonNull List 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> getContacts() { - return contacts; - } - - @NonNull List getFinalizedContacts() { - List currentContacts = getCurrentContacts(); - List 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 getEvents() { - return events; - } - - void updateContactName(int contactPosition, @NonNull Name name) { - if (name.isEmpty()) { - events.postValue(Event.BAD_CONTACT); - return; - } - - List 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 List trimSelectables(List selectables) { - return Stream.of(selectables).filter(Selectable::isSelected).toList(); - } - - @NonNull - private List getCurrentContacts() { - List currentContacts = contacts.getValue(); - return currentContacts != null ? currentContacts : new ArrayList<>(); - } - - enum Event { - BAD_CONTACT - } - - static class Factory extends ViewModelProvider.NewInstanceFactory { - - private final List contactUris; - private final ContactRepository contactRepository; - - Factory(@NonNull List contactUris, @NonNull ContactRepository contactRepository) { - this.contactUris = contactUris; - this.contactRepository = contactRepository; - } - - @Override - public @NonNull T create(@NonNull Class modelClass) { - return modelClass.cast(new ContactShareEditViewModel(contactUris, contactRepository)); - } - } -} diff --git a/src/org/thoughtcrime/securesms/contactshare/ContactUtil.java b/src/org/thoughtcrime/securesms/contactshare/ContactUtil.java deleted file mode 100644 index 14426a167..000000000 --- a/src/org/thoughtcrime/securesms/contactshare/ContactUtil.java +++ /dev/null @@ -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 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 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 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 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); - } -} diff --git a/src/org/thoughtcrime/securesms/database/ThreadDatabase.java b/src/org/thoughtcrime/securesms/database/ThreadDatabase.java index bf58f2e5f..fe2ec3a81 100644 --- a/src/org/thoughtcrime/securesms/database/ThreadDatabase.java +++ b/src/org/thoughtcrime/securesms/database/ThreadDatabase.java @@ -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(); }