Search in sources :

Example 1 with LinkPreviewViewModel

use of org.thoughtcrime.securesms.linkpreview.LinkPreviewViewModel in project Signal-Android by WhisperSystems.

the class ShareInterstitialActivity method initializeViews.

private void initializeViews(@NonNull MultiShareArgs args) {
    confirm = findViewById(R.id.share_confirm);
    toolbar = findViewById(R.id.toolbar);
    preview = findViewById(R.id.link_preview);
    confirm.setOnClickListener(unused -> onConfirm());
    SelectionAwareEmojiEditText text = findViewById(R.id.text);
    toolbar.setNavigationOnClickListener(unused -> finish());
    text.addTextChangedListener(new AfterTextChanged(editable -> {
        linkPreviewViewModel.onTextChanged(this, editable.toString(), text.getSelectionStart(), text.getSelectionEnd());
        viewModel.onDraftTextChanged(editable.toString());
    }));
    // noinspection CodeBlock2Expr
    text.setOnSelectionChangedListener(((selStart, selEnd) -> {
        linkPreviewViewModel.onTextChanged(this, text.getText().toString(), text.getSelectionStart(), text.getSelectionEnd());
    }));
    preview.setCloseClickedListener(linkPreviewViewModel::onUserCancel);
    int defaultRadius = getResources().getDimensionPixelSize(R.dimen.thumbnail_default_radius);
    preview.setCorners(defaultRadius, defaultRadius);
    text.setText(args.getDraftText());
    ViewUtil.focusAndMoveCursorToEndAndOpenKeyboard(text);
    contactsRecycler = findViewById(R.id.selected_list);
    contactsRecycler.setAdapter(adapter);
    RecyclerView.ItemAnimator itemAnimator = Objects.requireNonNull(contactsRecycler.getItemAnimator());
    ShareFlowConstants.applySelectedContactsRecyclerAnimationSpeeds(itemAnimator);
    confirm.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
        int pad = Math.abs(v.getWidth() + ViewUtil.dpToPx(16));
        ViewUtil.setPaddingEnd(contactsRecycler, pad);
    });
}
Also used : Context(android.content.Context) Bundle(android.os.Bundle) Stream(com.annimon.stream.Stream) NonNull(androidx.annotation.NonNull) Intent(android.content.Intent) ViewUtil(org.thoughtcrime.securesms.util.ViewUtil) R(org.thoughtcrime.securesms.R) DynamicTheme(org.thoughtcrime.securesms.util.DynamicTheme) View(android.view.View) ViewModelProviders(androidx.lifecycle.ViewModelProviders) Recipient(org.thoughtcrime.securesms.recipients.Recipient) RecyclerView(androidx.recyclerview.widget.RecyclerView) LinkPreviewView(org.thoughtcrime.securesms.components.LinkPreviewView) CircularProgressButton(com.dd.CircularProgressButton) AfterTextChanged(org.thoughtcrime.securesms.util.text.AfterTextChanged) LinkPreviewViewModel(org.thoughtcrime.securesms.linkpreview.LinkPreviewViewModel) DefaultItemAnimator(androidx.recyclerview.widget.DefaultItemAnimator) Objects(java.util.Objects) PassphraseRequiredActivity(org.thoughtcrime.securesms.PassphraseRequiredActivity) SelectionAwareEmojiEditText(org.thoughtcrime.securesms.components.SelectionAwareEmojiEditText) LinkPreviewRepository(org.thoughtcrime.securesms.linkpreview.LinkPreviewRepository) DynamicNoActionBarTheme(org.thoughtcrime.securesms.util.DynamicNoActionBarTheme) MultiShareArgs(org.thoughtcrime.securesms.sharing.MultiShareArgs) MultiShareDialogs(org.thoughtcrime.securesms.sharing.MultiShareDialogs) Toolbar(androidx.appcompat.widget.Toolbar) ShareFlowConstants(org.thoughtcrime.securesms.sharing.ShareFlowConstants) GlideApp(org.thoughtcrime.securesms.mms.GlideApp) RecyclerView(androidx.recyclerview.widget.RecyclerView) AfterTextChanged(org.thoughtcrime.securesms.util.text.AfterTextChanged) SelectionAwareEmojiEditText(org.thoughtcrime.securesms.components.SelectionAwareEmojiEditText)

Example 2 with LinkPreviewViewModel

use of org.thoughtcrime.securesms.linkpreview.LinkPreviewViewModel in project Signal-Android by WhisperSystems.

the class ShareInterstitialActivity method initializeViewModels.

private void initializeViewModels(@NonNull MultiShareArgs args) {
    ShareInterstitialRepository repository = new ShareInterstitialRepository();
    ShareInterstitialViewModel.Factory factory = new ShareInterstitialViewModel.Factory(args, repository);
    viewModel = ViewModelProviders.of(this, factory).get(ShareInterstitialViewModel.class);
    LinkPreviewRepository linkPreviewRepository = new LinkPreviewRepository();
    LinkPreviewViewModel.Factory linkPreviewViewModelFactory = new LinkPreviewViewModel.Factory(linkPreviewRepository);
    linkPreviewViewModel = ViewModelProviders.of(this, linkPreviewViewModelFactory).get(LinkPreviewViewModel.class);
    boolean hasSms = Stream.of(args.getShareContactAndThreads()).anyMatch(c -> {
        Recipient recipient = Recipient.resolved(c.getRecipientId());
        return !recipient.isRegistered() || recipient.isForceSmsSelection();
    });
    if (hasSms) {
        linkPreviewViewModel.onTransportChanged(hasSms);
    }
}
Also used : LinkPreviewViewModel(org.thoughtcrime.securesms.linkpreview.LinkPreviewViewModel) LinkPreviewRepository(org.thoughtcrime.securesms.linkpreview.LinkPreviewRepository) Recipient(org.thoughtcrime.securesms.recipients.Recipient)

Example 3 with LinkPreviewViewModel

use of org.thoughtcrime.securesms.linkpreview.LinkPreviewViewModel in project Signal-Android by signalapp.

the class ShareInterstitialActivity method initializeViews.

private void initializeViews(@NonNull MultiShareArgs args) {
    confirm = findViewById(R.id.share_confirm);
    toolbar = findViewById(R.id.toolbar);
    preview = findViewById(R.id.link_preview);
    confirm.setOnClickListener(unused -> onConfirm());
    SelectionAwareEmojiEditText text = findViewById(R.id.text);
    toolbar.setNavigationOnClickListener(unused -> finish());
    text.addTextChangedListener(new AfterTextChanged(editable -> {
        linkPreviewViewModel.onTextChanged(this, editable.toString(), text.getSelectionStart(), text.getSelectionEnd());
        viewModel.onDraftTextChanged(editable.toString());
    }));
    // noinspection CodeBlock2Expr
    text.setOnSelectionChangedListener(((selStart, selEnd) -> {
        linkPreviewViewModel.onTextChanged(this, text.getText().toString(), text.getSelectionStart(), text.getSelectionEnd());
    }));
    preview.setCloseClickedListener(linkPreviewViewModel::onUserCancel);
    int defaultRadius = getResources().getDimensionPixelSize(R.dimen.thumbnail_default_radius);
    preview.setCorners(defaultRadius, defaultRadius);
    text.setText(args.getDraftText());
    ViewUtil.focusAndMoveCursorToEndAndOpenKeyboard(text);
    contactsRecycler = findViewById(R.id.selected_list);
    contactsRecycler.setAdapter(adapter);
    RecyclerView.ItemAnimator itemAnimator = Objects.requireNonNull(contactsRecycler.getItemAnimator());
    ShareFlowConstants.applySelectedContactsRecyclerAnimationSpeeds(itemAnimator);
    confirm.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
        int pad = Math.abs(v.getWidth() + ViewUtil.dpToPx(16));
        ViewUtil.setPaddingEnd(contactsRecycler, pad);
    });
}
Also used : Context(android.content.Context) Bundle(android.os.Bundle) Stream(com.annimon.stream.Stream) NonNull(androidx.annotation.NonNull) Intent(android.content.Intent) ViewUtil(org.thoughtcrime.securesms.util.ViewUtil) R(org.thoughtcrime.securesms.R) DynamicTheme(org.thoughtcrime.securesms.util.DynamicTheme) View(android.view.View) ViewModelProviders(androidx.lifecycle.ViewModelProviders) Recipient(org.thoughtcrime.securesms.recipients.Recipient) RecyclerView(androidx.recyclerview.widget.RecyclerView) LinkPreviewView(org.thoughtcrime.securesms.components.LinkPreviewView) CircularProgressButton(com.dd.CircularProgressButton) AfterTextChanged(org.thoughtcrime.securesms.util.text.AfterTextChanged) LinkPreviewViewModel(org.thoughtcrime.securesms.linkpreview.LinkPreviewViewModel) DefaultItemAnimator(androidx.recyclerview.widget.DefaultItemAnimator) Objects(java.util.Objects) PassphraseRequiredActivity(org.thoughtcrime.securesms.PassphraseRequiredActivity) SelectionAwareEmojiEditText(org.thoughtcrime.securesms.components.SelectionAwareEmojiEditText) LinkPreviewRepository(org.thoughtcrime.securesms.linkpreview.LinkPreviewRepository) DynamicNoActionBarTheme(org.thoughtcrime.securesms.util.DynamicNoActionBarTheme) MultiShareArgs(org.thoughtcrime.securesms.sharing.MultiShareArgs) MultiShareDialogs(org.thoughtcrime.securesms.sharing.MultiShareDialogs) Toolbar(androidx.appcompat.widget.Toolbar) ShareFlowConstants(org.thoughtcrime.securesms.sharing.ShareFlowConstants) GlideApp(org.thoughtcrime.securesms.mms.GlideApp) RecyclerView(androidx.recyclerview.widget.RecyclerView) AfterTextChanged(org.thoughtcrime.securesms.util.text.AfterTextChanged) SelectionAwareEmojiEditText(org.thoughtcrime.securesms.components.SelectionAwareEmojiEditText)

Example 4 with LinkPreviewViewModel

use of org.thoughtcrime.securesms.linkpreview.LinkPreviewViewModel in project Signal-Android by signalapp.

the class ShareInterstitialActivity method initializeViewModels.

private void initializeViewModels(@NonNull MultiShareArgs args) {
    ShareInterstitialRepository repository = new ShareInterstitialRepository();
    ShareInterstitialViewModel.Factory factory = new ShareInterstitialViewModel.Factory(args, repository);
    viewModel = ViewModelProviders.of(this, factory).get(ShareInterstitialViewModel.class);
    LinkPreviewRepository linkPreviewRepository = new LinkPreviewRepository();
    LinkPreviewViewModel.Factory linkPreviewViewModelFactory = new LinkPreviewViewModel.Factory(linkPreviewRepository);
    linkPreviewViewModel = ViewModelProviders.of(this, linkPreviewViewModelFactory).get(LinkPreviewViewModel.class);
    boolean hasSms = Stream.of(args.getShareContactAndThreads()).anyMatch(c -> {
        Recipient recipient = Recipient.resolved(c.getRecipientId());
        return !recipient.isRegistered() || recipient.isForceSmsSelection();
    });
    if (hasSms) {
        linkPreviewViewModel.onTransportChanged(hasSms);
    }
}
Also used : LinkPreviewViewModel(org.thoughtcrime.securesms.linkpreview.LinkPreviewViewModel) LinkPreviewRepository(org.thoughtcrime.securesms.linkpreview.LinkPreviewRepository) Recipient(org.thoughtcrime.securesms.recipients.Recipient)

Aggregations

LinkPreviewRepository (org.thoughtcrime.securesms.linkpreview.LinkPreviewRepository)4 LinkPreviewViewModel (org.thoughtcrime.securesms.linkpreview.LinkPreviewViewModel)4 Recipient (org.thoughtcrime.securesms.recipients.Recipient)4 Context (android.content.Context)2 Intent (android.content.Intent)2 Bundle (android.os.Bundle)2 View (android.view.View)2 NonNull (androidx.annotation.NonNull)2 Toolbar (androidx.appcompat.widget.Toolbar)2 ViewModelProviders (androidx.lifecycle.ViewModelProviders)2 DefaultItemAnimator (androidx.recyclerview.widget.DefaultItemAnimator)2 RecyclerView (androidx.recyclerview.widget.RecyclerView)2 Stream (com.annimon.stream.Stream)2 CircularProgressButton (com.dd.CircularProgressButton)2 Objects (java.util.Objects)2 PassphraseRequiredActivity (org.thoughtcrime.securesms.PassphraseRequiredActivity)2 R (org.thoughtcrime.securesms.R)2 LinkPreviewView (org.thoughtcrime.securesms.components.LinkPreviewView)2 SelectionAwareEmojiEditText (org.thoughtcrime.securesms.components.SelectionAwareEmojiEditText)2 GlideApp (org.thoughtcrime.securesms.mms.GlideApp)2