Search in sources :

Example 1 with WebContentMeta

use of chat.rocket.core.models.WebContentMeta in project Rocket.Chat.Android by RocketChat.

the class RocketChatMessageUrlsLayout method appendUrlView.

private void appendUrlView(WebContent webContent, boolean autoloadImages) {
    final String url = webContent.getUrl();
    addMessageInlineImage(webContent, autoloadImages, url);
    // see Rocket.Chat:packages/rocketchat-oembed/client/oembedUrlWidget.coffee
    final Map<WebContentMeta.Type, WebContentMeta> webContentMetaMap = webContent.getMetaMap();
    if (webContentMetaMap == null || webContentMetaMap.size() == 0) {
        return;
    }
    final String imageURL = webContent.getMetaImage();
    WebContentParsedUrl parsedUrl = webContent.getParsedUrl();
    String host = parsedUrl != null ? parsedUrl.getHost() : null;
    View embedUrl = inflater.inflate(R.layout.message_inline_embed_url, this, false);
    ((TextView) embedUrl.findViewById(R.id.hostname)).setText(host);
    ((TextView) embedUrl.findViewById(R.id.title)).setText(webContent.getMetaTitle());
    ((TextView) embedUrl.findViewById(R.id.description)).setText(removeQuote(webContent.getMetaDescription()));
    final SimpleDraweeView image = (SimpleDraweeView) embedUrl.findViewById(R.id.image);
    if (TextUtils.isEmpty(imageURL)) {
        image.setVisibility(View.GONE);
    } else {
        FrescoHelper.setupDraweeAndLoadImage(imageURL, image);
        image.setVisibility(View.VISIBLE);
    }
    embedUrl.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            getContext().startActivity(intent);
        }
    });
    addView(embedUrl);
}
Also used : SimpleDraweeView(com.facebook.drawee.view.SimpleDraweeView) WebContentParsedUrl(chat.rocket.core.models.WebContentParsedUrl) TextView(android.widget.TextView) Intent(android.content.Intent) WebContentMeta(chat.rocket.core.models.WebContentMeta) TextView(android.widget.TextView) SimpleDraweeView(com.facebook.drawee.view.SimpleDraweeView) View(android.view.View)

Aggregations

Intent (android.content.Intent)1 View (android.view.View)1 TextView (android.widget.TextView)1 WebContentMeta (chat.rocket.core.models.WebContentMeta)1 WebContentParsedUrl (chat.rocket.core.models.WebContentParsedUrl)1 SimpleDraweeView (com.facebook.drawee.view.SimpleDraweeView)1