Search in sources :

Example 6 with LiveRecipient

use of org.thoughtcrime.securesms.recipients.LiveRecipient in project Signal-Android by WhisperSystems.

the class SharedContactDetailsActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState, boolean ready) {
    setContentView(R.layout.activity_shared_contact_details);
    if (getIntent() == null) {
        throw new IllegalStateException("You must supply arguments to this activity. Please use the #getIntent() method.");
    }
    contact = getIntent().getParcelableExtra(KEY_CONTACT);
    if (contact == null) {
        throw new IllegalStateException("You must supply a contact to this activity. Please use the #getIntent() method.");
    }
    initToolbar();
    initViews();
    presentContact(contact);
    presentActionButtons(ContactUtil.getRecipients(this, contact));
    presentAvatar(contact.getAvatarAttachment() != null ? contact.getAvatarAttachment().getUri() : null);
    for (LiveRecipient recipient : activeRecipients.values()) {
        recipient.observe(this, r -> presentActionButtons(Collections.singletonList(r.getId())));
    }
}
Also used : LiveRecipient(org.thoughtcrime.securesms.recipients.LiveRecipient)

Example 7 with LiveRecipient

use of org.thoughtcrime.securesms.recipients.LiveRecipient in project Signal-Android by WhisperSystems.

the class SharedContactDetailsActivity method presentActionButtons.

private void presentActionButtons(@NonNull List<RecipientId> recipients) {
    for (RecipientId recipientId : recipients) {
        activeRecipients.put(recipientId, Recipient.live(recipientId));
    }
    List<Recipient> pushUsers = new ArrayList<>(recipients.size());
    List<Recipient> systemUsers = new ArrayList<>(recipients.size());
    for (LiveRecipient recipient : activeRecipients.values()) {
        if (recipient.get().getRegistered() == RecipientDatabase.RegisteredState.REGISTERED) {
            pushUsers.add(recipient.get());
        } else if (recipient.get().isSystemContact()) {
            systemUsers.add(recipient.get());
        }
    }
    if (!pushUsers.isEmpty()) {
        engageContainerView.setVisibility(View.VISIBLE);
        inviteButtonView.setVisibility(View.GONE);
        messageButtonView.setOnClickListener(v -> {
            ContactUtil.selectRecipientThroughDialog(this, pushUsers, dynamicLanguage.getCurrentLocale(), recipient -> {
                CommunicationActions.startConversation(this, recipient, null);
            });
        });
        callButtonView.setOnClickListener(v -> {
            ContactUtil.selectRecipientThroughDialog(this, pushUsers, dynamicLanguage.getCurrentLocale(), recipient -> CommunicationActions.startVoiceCall(this, recipient));
        });
    } else if (!systemUsers.isEmpty()) {
        inviteButtonView.setVisibility(View.VISIBLE);
        engageContainerView.setVisibility(View.GONE);
        inviteButtonView.setOnClickListener(v -> {
            ContactUtil.selectRecipientThroughDialog(this, systemUsers, dynamicLanguage.getCurrentLocale(), recipient -> {
                CommunicationActions.composeSmsThroughDefaultApp(this, recipient, getString(R.string.InviteActivity_lets_switch_to_signal, getString(R.string.install_url)));
            });
        });
    } else {
        inviteButtonView.setVisibility(View.GONE);
        engageContainerView.setVisibility(View.GONE);
    }
}
Also used : Context(android.content.Context) Bundle(android.os.Bundle) NonNull(androidx.annotation.NonNull) DynamicLanguage(org.thoughtcrime.securesms.util.DynamicLanguage) Uri(android.net.Uri) ImageView(android.widget.ImageView) Intent(android.content.Intent) HashMap(java.util.HashMap) R(org.thoughtcrime.securesms.R) RecipientDatabase(org.thoughtcrime.securesms.database.RecipientDatabase) ArrayList(java.util.ArrayList) DynamicTheme(org.thoughtcrime.securesms.util.DynamicTheme) SuppressLint(android.annotation.SuppressLint) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) DiskCacheStrategy(com.bumptech.glide.load.engine.DiskCacheStrategy) Map(java.util.Map) View(android.view.View) Recipient(org.thoughtcrime.securesms.recipients.Recipient) RecyclerView(androidx.recyclerview.widget.RecyclerView) ContextCompat(androidx.core.content.ContextCompat) LiveRecipient(org.thoughtcrime.securesms.recipients.LiveRecipient) DirectoryRefreshJob(org.thoughtcrime.securesms.jobs.DirectoryRefreshJob) AsyncTask(android.os.AsyncTask) ApplicationDependencies(org.thoughtcrime.securesms.dependencies.ApplicationDependencies) CommunicationActions(org.thoughtcrime.securesms.util.CommunicationActions) ViewGroup(android.view.ViewGroup) WindowUtil(org.thoughtcrime.securesms.util.WindowUtil) List(java.util.List) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) PassphraseRequiredActivity(org.thoughtcrime.securesms.PassphraseRequiredActivity) DynamicNoActionBarTheme(org.thoughtcrime.securesms.util.DynamicNoActionBarTheme) DecryptableUri(org.thoughtcrime.securesms.mms.DecryptableStreamUriLoader.DecryptableUri) Toolbar(androidx.appcompat.widget.Toolbar) GlideRequests(org.thoughtcrime.securesms.mms.GlideRequests) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) GlideApp(org.thoughtcrime.securesms.mms.GlideApp) Collections(java.util.Collections) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) LiveRecipient(org.thoughtcrime.securesms.recipients.LiveRecipient) ArrayList(java.util.ArrayList) Recipient(org.thoughtcrime.securesms.recipients.Recipient) LiveRecipient(org.thoughtcrime.securesms.recipients.LiveRecipient)

Example 8 with LiveRecipient

use of org.thoughtcrime.securesms.recipients.LiveRecipient in project Signal-Android by WhisperSystems.

the class MessageRequestRepository method blockMessageRequest.

void blockMessageRequest(@NonNull LiveRecipient liveRecipient, @NonNull Runnable onMessageRequestBlocked, @NonNull GroupChangeErrorCallback error) {
    executor.execute(() -> {
        Recipient recipient = liveRecipient.resolve();
        try {
            RecipientUtil.block(context, recipient);
        } catch (GroupChangeException | IOException e) {
            Log.w(TAG, e);
            error.onError(GroupChangeFailureReason.fromException(e));
            return;
        }
        liveRecipient.refresh();
        if (TextSecurePreferences.isMultiDevice(context)) {
            ApplicationDependencies.getJobManager().add(MultiDeviceMessageRequestResponseJob.forBlock(liveRecipient.getId()));
        }
        onMessageRequestBlocked.run();
    });
}
Also used : GroupChangeException(org.thoughtcrime.securesms.groups.GroupChangeException) Recipient(org.thoughtcrime.securesms.recipients.Recipient) LiveRecipient(org.thoughtcrime.securesms.recipients.LiveRecipient) IOException(java.io.IOException)

Aggregations

LiveRecipient (org.thoughtcrime.securesms.recipients.LiveRecipient)8 Recipient (org.thoughtcrime.securesms.recipients.Recipient)6 IOException (java.io.IOException)3 GroupChangeException (org.thoughtcrime.securesms.groups.GroupChangeException)3 Context (android.content.Context)2 Uri (android.net.Uri)2 View (android.view.View)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 NonNull (androidx.annotation.NonNull)2 Nullable (androidx.annotation.Nullable)2 DiskCacheStrategy (com.bumptech.glide.load.engine.DiskCacheStrategy)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 R (org.thoughtcrime.securesms.R)2 RecipientDatabase (org.thoughtcrime.securesms.database.RecipientDatabase)2 DecryptableUri (org.thoughtcrime.securesms.mms.DecryptableStreamUriLoader.DecryptableUri)2