Search in sources :

Example 1 with MediaEntity

use of twitter4j.MediaEntity in project Talon-for-Twitter by klinker24.

the class DMDataSource method createSentDirectMessage.

public synchronized void createSentDirectMessage(DirectMessageEvent status, User recipient, AppSettings settings, int account) {
    ContentValues values = new ContentValues();
    long time = status.getCreatedTimestamp().getTime();
    String[] html = TweetLinkUtils.getLinksInStatus(status);
    String text = html[0];
    String media = html[1];
    String url = html[2];
    String hashtags = html[3];
    String users = html[4];
    values.put(DMSQLiteHelper.COLUMN_ACCOUNT, account);
    values.put(DMSQLiteHelper.COLUMN_TEXT, text);
    values.put(DMSQLiteHelper.COLUMN_TWEET_ID, status.getId());
    values.put(DMSQLiteHelper.COLUMN_NAME, settings.myName);
    values.put(DMSQLiteHelper.COLUMN_PRO_PIC, settings.myProfilePicUrl);
    values.put(DMSQLiteHelper.COLUMN_SCREEN_NAME, settings.myScreenName);
    values.put(DMSQLiteHelper.COLUMN_TIME, time);
    values.put(DMSQLiteHelper.COLUMN_RETWEETER, recipient.getScreenName());
    values.put(DMSQLiteHelper.COLUMN_EXTRA_ONE, recipient.getOriginalProfileImageURL());
    values.put(DMSQLiteHelper.COLUMN_EXTRA_TWO, recipient.getName());
    values.put(HomeSQLiteHelper.COLUMN_PIC_URL, media);
    values.put(DMSQLiteHelper.COLUMN_EXTRA_THREE, TweetLinkUtils.getGIFUrl(status.getMediaEntities(), url));
    MediaEntity[] entities = status.getMediaEntities();
    if (entities.length > 0) {
        values.put(DMSQLiteHelper.COLUMN_PIC_URL, entities[0].getMediaURL());
    }
    URLEntity[] urls = status.getUrlEntities();
    for (URLEntity u : urls) {
        Log.v("inserting_dm", "url here: " + u.getExpandedURL());
        values.put(DMSQLiteHelper.COLUMN_URL, u.getExpandedURL());
    }
    try {
        database.insert(DMSQLiteHelper.TABLE_DM, null, values);
    } catch (Exception e) {
        open();
        database.insert(DMSQLiteHelper.TABLE_DM, null, values);
    }
}
Also used : ContentValues(android.content.ContentValues) URLEntity(twitter4j.URLEntity) MediaEntity(twitter4j.MediaEntity) SQLException(android.database.SQLException)

Example 2 with MediaEntity

use of twitter4j.MediaEntity in project Talon-for-Twitter by klinker24.

the class TweetLinkUtils method getGIFUrl.

public static String getGIFUrl(MediaEntity[] entities, String otherUrls) {
    for (MediaEntity e : entities) {
        if (e.getType().contains("gif")) {
            if (e.getVideoVariants().length > 0) {
                String url = "";
                MediaEntity.Variant[] variants = e.getVideoVariants();
                if (variants.length == 0) {
                    return url;
                }
                for (int i = variants.length - 1; i >= 0; i--) {
                    MediaEntity.Variant v = variants[i];
                    if (v.getUrl().contains(".mp4") || v.getUrl().contains(".m3u8")) {
                        url = v.getUrl();
                    }
                }
                return url;
            }
            return e.getMediaURL().replace("tweet_video_thumb", "tweet_video").replace(".png", ".mp4").replace(".jpg", ".mp4").replace(".jpeg", ".mp4");
        } else if (e.getType().equals("surfaceView") || e.getType().equals("video")) {
            if (e.getVideoVariants().length > 0) {
                String url = "";
                MediaEntity.Variant[] variants = e.getVideoVariants();
                if (variants.length == 0) {
                    return url;
                }
                for (int i = variants.length - 1; i >= 0; i--) {
                    MediaEntity.Variant v = variants[i];
                    if (v.getUrl().contains(".mp4")) {
                        url = v.getUrl();
                    }
                }
                if (url.isEmpty()) {
                    for (int i = variants.length - 1; i >= 0; i--) {
                        MediaEntity.Variant v = variants[i];
                        if (v.getUrl().contains(".m3u8")) {
                            url = v.getUrl();
                        }
                    }
                }
                return url;
            }
        }
    }
    // otherwise, lets just go with a blank string
    return "";
}
Also used : MediaEntity(twitter4j.MediaEntity)

Example 3 with MediaEntity

use of twitter4j.MediaEntity in project twicalico by moko256.

the class StatusView method updateView.

private void updateView() {
    final Status item = status.isRetweet() ? status.getRetweetedStatus() : status;
    if (status.isRetweet()) {
        if (retweetUserName.getVisibility() != View.VISIBLE) {
            retweetUserName.setVisibility(View.VISIBLE);
        }
        retweetUserName.setText(getContext().getString(R.string.repeat_by, status.getUser().getName()));
    } else {
        if (retweetUserName.getVisibility() != View.GONE) {
            retweetUserName.setVisibility(View.GONE);
        }
    }
    boolean isReply = item.getInReplyToScreenName() != null;
    if (isReply) {
        if (replyUserName.getVisibility() != View.VISIBLE) {
            replyUserName.setVisibility(View.VISIBLE);
        }
        replyUserName.setText(getContext().getString((item.getInReplyToStatusId() != -1) ? R.string.reply_to : R.string.mention_to, item.getInReplyToScreenName()));
    } else {
        if (replyUserName.getVisibility() != View.GONE) {
            replyUserName.setVisibility(View.GONE);
        }
    }
    if (status.isRetweet() || isReply) {
        if (headerBottomMargin.getVisibility() != VISIBLE) {
            headerBottomMargin.setVisibility(VISIBLE);
        }
    } else {
        if (headerBottomMargin.getVisibility() != GONE) {
            headerBottomMargin.setVisibility(GONE);
        }
    }
    if (GlobalApplication.configuration.isTimelineImageLoad) {
        glideRequests.load(item.getUser().get400x400ProfileImageURLHttps()).circleCrop().into(userImage);
    } else {
        userImage.setImageResource(R.drawable.border_frame_round);
    }
    userName.setText(item.getUser().getName());
    userId.setText(TwitterStringUtils.plusAtMark(item.getUser().getScreenName()));
    TwitterStringUtils.setLinkedSequenceTo(item, tweetContext);
    if (!tweetContext.getText().toString().trim().isEmpty()) {
        tweetContext.setMovementMethod(LinkMovementMethod.getInstance());
        if (tweetContext.getVisibility() != VISIBLE) {
            tweetContext.setVisibility(VISIBLE);
        }
    } else {
        tweetContext.setMovementMethod(null);
        if (tweetContext.getVisibility() != GONE) {
            tweetContext.setVisibility(GONE);
        }
    }
    timeStampText.setText(DateUtils.getRelativeTimeSpanString(item.getCreatedAt().getTime(), System.currentTimeMillis(), 0));
    userImage.setOnClickListener(v -> {
        ActivityOptionsCompat animation = ActivityOptionsCompat.makeSceneTransitionAnimation(((Activity) getContext()), v, "icon_image");
        getContext().startActivity(ShowUserActivity.getIntent(getContext(), item.getUser().getId()), animation.toBundle());
    });
    setOnClickListener(v -> {
        ActivityOptionsCompat animation = ActivityOptionsCompat.makeSceneTransitionAnimation(((Activity) getContext()), userImage, "icon_image");
        getContext().startActivity(ShowTweetActivity.getIntent(getContext(), item.getId()), animation.toBundle());
    });
    Status quotedStatus = item.getQuotedStatus();
    if (quotedStatus != null) {
        if (quoteTweetLayout.getVisibility() != View.VISIBLE) {
            quoteTweetLayout.setVisibility(View.VISIBLE);
        }
        quoteTweetLayout.setOnClickListener(v -> getContext().startActivity(ShowTweetActivity.getIntent(getContext(), quotedStatus.getId())));
        quoteTweetUserName.setText(quotedStatus.getUser().getName());
        quoteTweetUserId.setText(TwitterStringUtils.plusAtMark(quotedStatus.getUser().getScreenName()));
        quoteTweetContext.setText(quotedStatus.getText());
    } else {
        if (quoteTweetLayout.getVisibility() != View.GONE) {
            quoteTweetLayout.setVisibility(View.GONE);
        }
    }
    MediaEntity[] mediaEntities = item.getMediaEntities();
    if (mediaEntities.length != 0) {
        imageTableView.setVisibility(View.VISIBLE);
        imageTableView.setMediaEntities(mediaEntities, item.isPossiblySensitive());
    } else {
        imageTableView.setVisibility(View.GONE);
    }
    likeButton.setOnCheckedChangeListener((compoundButton, b) -> Single.create(subscriber -> {
        try {
            if (b && (!item.isFavorited())) {
                subscriber.onSuccess(GlobalApplication.twitter.createFavorite(item.getId()));
            } else if ((!b) && item.isFavorited()) {
                subscriber.onSuccess(GlobalApplication.twitter.destroyFavorite(item.getId()));
            }
        } catch (TwitterException e) {
            subscriber.onError(e);
        }
    }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(result -> {
        Status status = (Status) result;
        GlobalApplication.statusCache.add(status);
        setStatus(GlobalApplication.statusCache.get(this.status.getId()));
        Toast.makeText(getContext(), R.string.succeeded, Toast.LENGTH_SHORT).show();
    }, throwable -> {
        throwable.printStackTrace();
        Toast.makeText(getContext(), R.string.error_occurred, Toast.LENGTH_SHORT).show();
    }));
    likeButton.setChecked(item.isFavorited());
    retweetButton.setOnCheckedChangeListener((compoundButton, b) -> Single.create(subscriber -> {
        try {
            if (b && (!item.isRetweeted())) {
                subscriber.onSuccess(GlobalApplication.twitter.retweetStatus(item.getId()));
            } else if ((!b) && item.isRetweeted()) {
                subscriber.onSuccess(GlobalApplication.twitter.unRetweetStatus(item.getId()));
            }
        } catch (TwitterException e) {
            subscriber.onError(e);
        }
    }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(result -> {
        Status status = (Status) result;
        GlobalApplication.statusCache.add(status);
        setStatus(GlobalApplication.statusCache.get(this.status.getId()));
        Toast.makeText(getContext(), R.string.succeeded, Toast.LENGTH_SHORT).show();
    }, throwable -> {
        throwable.printStackTrace();
        Toast.makeText(getContext(), R.string.error_occurred, Toast.LENGTH_SHORT).show();
    }));
    retweetButton.setChecked(item.isRetweeted());
    retweetButton.setEnabled(GlobalApplication.clientType == Type.MASTODON || !(item.getUser().isProtected()) || item.getUser().getId() == GlobalApplication.userId);
    replyButton.setOnClickListener(v -> getContext().startActivity(PostActivity.getIntent(getContext(), item.getId(), TwitterStringUtils.convertToReplyTopString(GlobalApplication.userCache.get(GlobalApplication.userId).getScreenName(), item.getUser().getScreenName(), item.getUserMentionEntities()).toString())));
    likeCount.setText((item.getFavoriteCount() != 0) ? TwitterStringUtils.convertToSIUnitString(item.getFavoriteCount()) : "");
    retweetCount.setText((item.getRetweetCount() != 0) ? TwitterStringUtils.convertToSIUnitString(item.getRetweetCount()) : "");
}
Also used : Status(twitter4j.Status) Context(android.content.Context) ImageButton(android.widget.ImageButton) Type(com.github.moko256.twicalico.entity.Type) DateUtils(android.text.format.DateUtils) Space(android.widget.Space) FrameLayout(android.widget.FrameLayout) ImageView(android.widget.ImageView) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) LinkMovementMethod(android.text.method.LinkMovementMethod) TwitterStringUtils(com.github.moko256.twicalico.text.TwitterStringUtils) MediaEntity(twitter4j.MediaEntity) Single(rx.Single) AttributeSet(android.util.AttributeSet) CheckBox(android.widget.CheckBox) Toast(android.widget.Toast) Schedulers(rx.schedulers.Schedulers) View(android.view.View) TwitterException(twitter4j.TwitterException) LayoutInflater(android.view.LayoutInflater) TweetImageTableView(com.github.moko256.twicalico.widget.TweetImageTableView) ActivityOptionsCompat(android.support.v4.app.ActivityOptionsCompat) TextView(android.widget.TextView) Status(twitter4j.Status) RelativeLayout(android.widget.RelativeLayout) Activity(android.app.Activity) Activity(android.app.Activity) ActivityOptionsCompat(android.support.v4.app.ActivityOptionsCompat) TwitterException(twitter4j.TwitterException) MediaEntity(twitter4j.MediaEntity)

Example 4 with MediaEntity

use of twitter4j.MediaEntity in project Talon-for-Twitter by klinker24.

the class DMDataSource method createDirectMessage.

public synchronized void createDirectMessage(DirectMessage status, int account) {
    ContentValues values = new ContentValues();
    long time = status.getCreatedAt().getTime();
    values.put(DMSQLiteHelper.COLUMN_ACCOUNT, account);
    values.put(DMSQLiteHelper.COLUMN_TEXT, TweetLinkUtils.getLinksInStatus(status)[0]);
    values.put(DMSQLiteHelper.COLUMN_TWEET_ID, status.getId());
    values.put(DMSQLiteHelper.COLUMN_NAME, status.getSender().getName());
    values.put(DMSQLiteHelper.COLUMN_PRO_PIC, status.getSender().getOriginalProfileImageURL());
    values.put(DMSQLiteHelper.COLUMN_SCREEN_NAME, status.getSender().getScreenName());
    values.put(DMSQLiteHelper.COLUMN_TIME, time);
    values.put(DMSQLiteHelper.COLUMN_RETWEETER, status.getRecipientScreenName());
    values.put(DMSQLiteHelper.COLUMN_EXTRA_ONE, status.getRecipient().getOriginalProfileImageURL());
    values.put(DMSQLiteHelper.COLUMN_EXTRA_TWO, status.getRecipient().getName());
    values.put(HomeSQLiteHelper.COLUMN_PIC_URL, TweetLinkUtils.getLinksInStatus(status)[1]);
    MediaEntity[] entities = status.getMediaEntities();
    if (entities.length > 0) {
        values.put(DMSQLiteHelper.COLUMN_PIC_URL, entities[0].getMediaURL());
    }
    URLEntity[] urls = status.getURLEntities();
    for (URLEntity url : urls) {
        Log.v("inserting_dm", "url here: " + url.getExpandedURL());
        values.put(DMSQLiteHelper.COLUMN_URL, url.getExpandedURL());
    }
    try {
        database.insert(DMSQLiteHelper.TABLE_DM, null, values);
    } catch (Exception e) {
        open();
        database.insert(DMSQLiteHelper.TABLE_DM, null, values);
    }
}
Also used : ContentValues(android.content.ContentValues) URLEntity(twitter4j.URLEntity) MediaEntity(twitter4j.MediaEntity) SQLException(android.database.SQLException)

Example 5 with MediaEntity

use of twitter4j.MediaEntity in project Talon-for-Twitter by klinker24.

the class TweetLinkUtils method getAllExternalPictures.

public static ArrayList<String> getAllExternalPictures(Status status) {
    URLEntity[] urls = status.getURLEntities();
    String expandedUrls = "";
    String compressedUrls = "";
    for (URLEntity entity : urls) {
        String url = entity.getExpandedURL();
        if (url.length() > 1) {
            expandedUrls += url + "  ";
            compressedUrls += entity.getURL() + "  ";
        }
    }
    MediaEntity[] medias = status.getMediaEntities();
    String mediaExp = "";
    String mediaComp = "";
    for (MediaEntity e : medias) {
        String url = e.getURL();
        if (url.length() > 1) {
            mediaComp += url + "  ";
            mediaExp += e.getExpandedURL() + "  ";
        }
    }
    String[] sExpandedUrls;
    String[] sCompressedUrls;
    String[] sMediaExp;
    String[] sMediaComp;
    try {
        sCompressedUrls = compressedUrls.split("  ");
    } catch (Exception e) {
        sCompressedUrls = new String[0];
    }
    try {
        sExpandedUrls = expandedUrls.split("  ");
    } catch (Exception e) {
        sExpandedUrls = new String[0];
    }
    try {
        sMediaComp = mediaComp.split("  ");
    } catch (Exception e) {
        sMediaComp = new String[0];
    }
    try {
        sMediaExp = mediaExp.split("  ");
    } catch (Exception e) {
        sMediaExp = new String[0];
    }
    ArrayList<String> images = new ArrayList<String>();
    for (int i = 0; i < sCompressedUrls.length; i++) {
        String comp = sCompressedUrls[i];
        String exp = sExpandedUrls[i];
        if (comp.length() > 1 && exp.length() > 1) {
            String str = exp.toLowerCase();
            if (str.contains("instag") && !str.contains("blog.insta")) {
                images.add(exp + "media/?size=m");
            } else if (exp.toLowerCase().contains("youtub") && !(str.contains("channel") || str.contains("user") || str.contains("playlist"))) {
                // first get the youtube surfaceView code
                int start = exp.indexOf("v=") + 2;
                int end = exp.length();
                if (exp.substring(start).contains("&")) {
                    end = exp.indexOf("&");
                } else if (exp.substring(start).contains("?")) {
                    end = exp.indexOf("?");
                }
                try {
                    images.add("http://img.youtube.com/vi/" + exp.substring(start, end) + "/hqdefault.jpg");
                } catch (Exception e) {
                    images.add("http://img.youtube.com/vi/" + exp.substring(start, exp.length() - 1) + "/hqdefault.jpg");
                }
            } else if (str.contains("youtu.be")) {
                // first get the youtube surfaceView code
                int start = exp.indexOf(".be/") + 4;
                int end = exp.length();
                if (exp.substring(start).contains("&")) {
                    end = exp.indexOf("&");
                } else if (exp.substring(start).contains("?")) {
                    end = exp.indexOf("?");
                }
                try {
                    images.add("http://img.youtube.com/vi/" + exp.substring(start, end) + "/hqdefault.jpg");
                } catch (Exception e) {
                    images.add("http://img.youtube.com/vi/" + exp.substring(start, exp.length() - 1) + "/mqefault.jpg");
                }
            } else if (str.contains("twitpic")) {
                int start = exp.indexOf(".com/") + 5;
                images.add("http://twitpic.com/show/full/" + exp.substring(start).replace("/", ""));
            } else if (str.contains("i.imgur") && !str.contains("/a/")) {
                images.add(("http://i.imgur.com/" + exp.replace("http://i.imgur.com/", "").replace(".jpg", "") + "m.jpg").replace("gallery/", ""));
            } else if (str.contains("imgur") && !str.contains("/a/")) {
                images.add(("http://i.imgur.com/" + exp.replace("http://imgur.com/", "").replace(".jpg", "") + "m.jpg").replace("gallery/", "").replace("a/", ""));
            } else if (str.contains("pbs.twimg.com")) {
                images.add(exp);
            } else if (str.contains("ow.ly/i/")) {
                images.add("http://static.ow.ly/photos/original/" + exp.substring(exp.lastIndexOf("/")).replaceAll("/", "") + ".jpg");
            } else if (str.contains("p.twipple.jp")) {
                images.add("http://p.twipple.jp/show/large/" + exp.replace("p.twipple.jp/", "").replace("http://", "").replace("https://", "").replace("www.", ""));
            } else if (str.contains(".jpg") || str.contains(".png")) {
                images.add(exp);
            } else if (str.contains("img.ly")) {
                images.add(exp.replace("https", "http").replace("http://img.ly/", "http://img.ly/show/large/"));
            }
        }
    }
    for (int i = 0; i < sMediaComp.length; i++) {
        String comp = sMediaComp[i];
        String exp = sMediaExp[i];
        if (comp.length() > 1 && exp.length() > 1) {
            images.add(status.getMediaEntities()[0].getMediaURL());
        }
    }
    return images;
}
Also used : URLEntity(twitter4j.URLEntity) ArrayList(java.util.ArrayList) MediaEntity(twitter4j.MediaEntity)

Aggregations

MediaEntity (twitter4j.MediaEntity)11 URLEntity (twitter4j.URLEntity)5 ContentValues (android.content.ContentValues)2 SQLException (android.database.SQLException)2 SuppressLint (android.annotation.SuppressLint)1 Activity (android.app.Activity)1 DownloadManager (android.app.DownloadManager)1 Context (android.content.Context)1 Handler (android.os.Handler)1 Nullable (android.support.annotation.Nullable)1 ActivityOptionsCompat (android.support.v4.app.ActivityOptionsCompat)1 ActionBar (android.support.v7.app.ActionBar)1 SpannableStringBuilder (android.text.SpannableStringBuilder)1 DateUtils (android.text.format.DateUtils)1 LinkMovementMethod (android.text.method.LinkMovementMethod)1 AttributeSet (android.util.AttributeSet)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 CheckBox (android.widget.CheckBox)1 FrameLayout (android.widget.FrameLayout)1