Search in sources :

Example 6 with Submission

use of net.dean.jraw.models.Submission in project Slide by ccrama.

the class SubredditPosts method loadPhotos.

public void loadPhotos(List<Submission> submissions) {
    for (Submission submission : submissions) {
        String url;
        ContentType.Type type = ContentType.getContentType(submission);
        if (submission.getThumbnails() != null) {
            if (type == ContentType.Type.IMAGE || type == ContentType.Type.SELF || (submission.getThumbnailType() == Submission.ThumbnailType.URL)) {
                if (type == ContentType.Type.IMAGE) {
                    if (((!NetworkUtil.isConnectedWifi(c) && SettingValues.lowResMobile) || SettingValues.lowResAlways) && submission.getThumbnails() != null && submission.getThumbnails().getVariations() != null && submission.getThumbnails().getVariations().length > 0) {
                        int length = submission.getThumbnails().getVariations().length;
                        if (SettingValues.lqLow && length >= 3) {
                            url = Html.fromHtml(submission.getThumbnails().getVariations()[2].getUrl()).toString();
                        } else if (SettingValues.lqMid && length >= 4) {
                            url = Html.fromHtml(submission.getThumbnails().getVariations()[3].getUrl()).toString();
                        } else if (length >= 5) {
                            url = Html.fromHtml(submission.getThumbnails().getVariations()[length - 1].getUrl()).toString();
                        } else {
                            url = Html.fromHtml(submission.getThumbnails().getSource().getUrl()).toString();
                        }
                    } else {
                        if (submission.getDataNode().has("preview") && submission.getDataNode().get("preview").get("images").get(0).get("source").has("height")) {
                            // Load the preview image which has probably already been cached in memory instead of the direct link
                            url = submission.getDataNode().get("preview").get("images").get(0).get("source").get("url").asText();
                        } else {
                            url = submission.getUrl();
                        }
                    }
                    ((Reddit) c.getApplicationContext()).getImageLoader().loadImage(url, new ImageLoadingListener() {

                        @Override
                        public void onLoadingStarted(String imageUri, View view) {
                        }

                        @Override
                        public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
                        }

                        @Override
                        public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                        }

                        @Override
                        public void onLoadingCancelled(String imageUri, View view) {
                        }
                    });
                } else if (submission.getThumbnails() != null) {
                    if (((!NetworkUtil.isConnectedWifi(c) && SettingValues.lowResMobile) || SettingValues.lowResAlways) && submission.getThumbnails().getVariations().length != 0) {
                        int length = submission.getThumbnails().getVariations().length;
                        if (SettingValues.lqLow && length >= 3) {
                            url = Html.fromHtml(submission.getThumbnails().getVariations()[2].getUrl()).toString();
                        } else if (SettingValues.lqMid && length >= 4) {
                            url = Html.fromHtml(submission.getThumbnails().getVariations()[3].getUrl()).toString();
                        } else if (length >= 5) {
                            url = Html.fromHtml(submission.getThumbnails().getVariations()[length - 1].getUrl()).toString();
                        } else {
                            url = Html.fromHtml(submission.getThumbnails().getSource().getUrl()).toString();
                        }
                    } else {
                        url = Html.fromHtml(submission.getThumbnails().getSource().getUrl()).toString();
                    }
                    ((Reddit) c.getApplicationContext()).getImageLoader().loadImage(url, new ImageLoadingListener() {

                        @Override
                        public void onLoadingStarted(String imageUri, View view) {
                        }

                        @Override
                        public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
                        }

                        @Override
                        public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                        }

                        @Override
                        public void onLoadingCancelled(String imageUri, View view) {
                        }
                    });
                } else if (submission.getThumbnail() != null && (submission.getThumbnailType() == Submission.ThumbnailType.URL || submission.getThumbnailType() == Submission.ThumbnailType.NSFW)) {
                    ((Reddit) c.getApplicationContext()).getImageLoader().loadImage(submission.getUrl(), new ImageLoadingListener() {

                        @Override
                        public void onLoadingStarted(String imageUri, View view) {
                        }

                        @Override
                        public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
                        }

                        @Override
                        public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                        }

                        @Override
                        public void onLoadingCancelled(String imageUri, View view) {
                        }
                    });
                }
            }
        }
    }
}
Also used : Bitmap(android.graphics.Bitmap) Submission(net.dean.jraw.models.Submission) ContentType(me.ccrama.redditslide.ContentType) ImageLoadingListener(com.nostra13.universalimageloader.core.listener.ImageLoadingListener) Reddit(me.ccrama.redditslide.Reddit) FailReason(com.nostra13.universalimageloader.core.assist.FailReason) SubmissionsView(me.ccrama.redditslide.Fragments.SubmissionsView) SubredditView(me.ccrama.redditslide.Activities.SubredditView) View(android.view.View)

Example 7 with Submission

use of net.dean.jraw.models.Submission in project Slide by ccrama.

the class ContributionAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final RecyclerView.ViewHolder firstHolder, final int pos) {
    int i = pos != 0 ? pos - 1 : pos;
    if (firstHolder instanceof SubmissionViewHolder) {
        final SubmissionViewHolder holder = (SubmissionViewHolder) firstHolder;
        final Submission submission = (Submission) dataSet.posts.get(i);
        CreateCardView.resetColorCard(holder.itemView);
        if (submission.getSubredditName() != null)
            CreateCardView.colorCard(submission.getSubredditName().toLowerCase(Locale.ENGLISH), holder.itemView, "no_subreddit", false);
        holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {

            @Override
            public boolean onLongClick(View v) {
                LayoutInflater inflater = mContext.getLayoutInflater();
                final View dialoglayout = inflater.inflate(R.layout.postmenu, null);
                AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(mContext);
                final TextView title = (TextView) dialoglayout.findViewById(R.id.title);
                title.setText(Html.fromHtml(submission.getTitle()));
                ((TextView) dialoglayout.findViewById(R.id.userpopup)).setText("/u/" + submission.getAuthor());
                ((TextView) dialoglayout.findViewById(R.id.subpopup)).setText("/r/" + submission.getSubredditName());
                dialoglayout.findViewById(R.id.sidebar).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        Intent i = new Intent(mContext, Profile.class);
                        i.putExtra(Profile.EXTRA_PROFILE, submission.getAuthor());
                        mContext.startActivity(i);
                    }
                });
                dialoglayout.findViewById(R.id.wiki).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        Intent i = new Intent(mContext, SubredditView.class);
                        i.putExtra(SubredditView.EXTRA_SUBREDDIT, submission.getSubredditName());
                        mContext.startActivity(i);
                    }
                });
                dialoglayout.findViewById(R.id.save).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        if (submission.isSaved()) {
                            ((TextView) dialoglayout.findViewById(R.id.savedtext)).setText(R.string.submission_save);
                        } else {
                            ((TextView) dialoglayout.findViewById(R.id.savedtext)).setText(R.string.submission_post_saved);
                        }
                        new AsyncSave(firstHolder.itemView).execute(submission);
                    }
                });
                dialoglayout.findViewById(R.id.copy).setVisibility(View.GONE);
                if (submission.isSaved()) {
                    ((TextView) dialoglayout.findViewById(R.id.savedtext)).setText(R.string.submission_post_saved);
                }
                dialoglayout.findViewById(R.id.gild).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        String urlString = "https://reddit.com" + submission.getPermalink();
                        Intent i = new Intent(mContext, Website.class);
                        i.putExtra(Website.EXTRA_URL, urlString);
                        mContext.startActivity(i);
                    }
                });
                dialoglayout.findViewById(R.id.share).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        if (submission.isSelfPost()) {
                            if (SettingValues.shareLongLink) {
                                Reddit.defaultShareText("", "htts://reddit.com" + submission.getPermalink(), mContext);
                            } else {
                                Reddit.defaultShareText("", "https://redd.it/" + submission.getId(), mContext);
                            }
                        } else {
                            new BottomSheet.Builder(mContext).title(R.string.submission_share_title).grid().sheet(R.menu.share_menu).listener(new DialogInterface.OnClickListener() {

                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    switch(which) {
                                        case R.id.reddit_url:
                                            if (SettingValues.shareLongLink) {
                                                Reddit.defaultShareText(submission.getTitle(), "htts://reddit.com" + submission.getPermalink(), mContext);
                                            } else {
                                                Reddit.defaultShareText(submission.getTitle(), "https://redd.it/" + submission.getId(), mContext);
                                            }
                                            break;
                                        case R.id.link_url:
                                            Reddit.defaultShareText(submission.getTitle(), submission.getUrl(), mContext);
                                            break;
                                    }
                                }
                            }).show();
                        }
                    }
                });
                if (!Authentication.isLoggedIn || !Authentication.didOnline) {
                    dialoglayout.findViewById(R.id.save).setVisibility(View.GONE);
                    dialoglayout.findViewById(R.id.gild).setVisibility(View.GONE);
                }
                title.setBackgroundColor(Palette.getColor(submission.getSubredditName()));
                builder.setView(dialoglayout);
                final Dialog d = builder.show();
                dialoglayout.findViewById(R.id.hide).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        final int pos = dataSet.posts.indexOf(submission);
                        final Contribution old = dataSet.posts.get(pos);
                        dataSet.posts.remove(submission);
                        notifyItemRemoved(pos + 1);
                        d.dismiss();
                        Hidden.setHidden(old);
                        Snackbar s = Snackbar.make(listView, R.string.submission_info_hidden, Snackbar.LENGTH_LONG).setAction(R.string.btn_undo, new View.OnClickListener() {

                            @Override
                            public void onClick(View v) {
                                dataSet.posts.add(pos, old);
                                notifyItemInserted(pos + 1);
                                Hidden.undoHidden(old);
                            }
                        });
                        View view = s.getView();
                        TextView tv = (TextView) view.findViewById(android.support.design.R.id.snackbar_text);
                        tv.setTextColor(Color.WHITE);
                        s.show();
                    }
                });
                return true;
            }
        });
        new PopulateSubmissionViewHolder().populateSubmissionViewHolder(holder, submission, mContext, false, false, dataSet.posts, listView, false, false, null, null);
        final ImageView hideButton = (ImageView) holder.itemView.findViewById(R.id.hide);
        if (hideButton != null && isHiddenPost) {
            hideButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    final int pos = dataSet.posts.indexOf(submission);
                    final Contribution old = dataSet.posts.get(pos);
                    dataSet.posts.remove(submission);
                    notifyItemRemoved(pos + 1);
                    Hidden.undoHidden(old);
                }
            });
        }
        holder.itemView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                String url = "www.reddit.com" + submission.getPermalink();
                url = url.replace("?ref=search_posts", "");
                new OpenRedditLink(mContext, url);
                if (SettingValues.storeHistory) {
                    if (SettingValues.storeNSFWHistory && submission.isNsfw() || !submission.isNsfw())
                        HasSeen.addSeen(submission.getFullName());
                }
                notifyItemChanged(pos);
            }
        });
    } else if (firstHolder instanceof ProfileCommentViewHolder) {
        // IS COMMENT
        ProfileCommentViewHolder holder = (ProfileCommentViewHolder) firstHolder;
        final Comment comment = (Comment) dataSet.posts.get(i);
        String scoreText;
        if (comment.isScoreHidden()) {
            scoreText = "[" + mContext.getString(R.string.misc_score_hidden).toUpperCase() + "]";
        } else {
            scoreText = String.format(Locale.getDefault(), "%d", comment.getScore());
        }
        SpannableStringBuilder score = new SpannableStringBuilder(scoreText);
        if (score == null || score.toString().isEmpty()) {
            score = new SpannableStringBuilder("0");
        }
        if (!scoreText.contains("[")) {
            score.append(String.format(Locale.getDefault(), " %s", mContext.getResources().getQuantityString(R.plurals.points, comment.getScore())));
        }
        holder.score.setText(score);
        if (Authentication.isLoggedIn) {
            if (ActionStates.getVoteDirection(comment) == VoteDirection.UPVOTE) {
                holder.score.setTextColor(mContext.getResources().getColor(R.color.md_orange_500));
            } else if (ActionStates.getVoteDirection(comment) == VoteDirection.DOWNVOTE) {
                holder.score.setTextColor(mContext.getResources().getColor(R.color.md_blue_500));
            } else {
                holder.score.setTextColor(holder.time.getCurrentTextColor());
            }
        }
        String spacer = mContext.getString(R.string.submission_properties_seperator);
        SpannableStringBuilder titleString = new SpannableStringBuilder();
        String timeAgo = TimeUtils.getTimeAgo(comment.getCreated().getTime(), mContext);
        // some users were crashing here
        String time = ((timeAgo == null || timeAgo.isEmpty()) ? "just now" : timeAgo);
        time = time + (((comment.getEditDate() != null) ? " (edit " + TimeUtils.getTimeAgo(comment.getEditDate().getTime(), mContext) + ")" : ""));
        titleString.append(time);
        titleString.append(spacer);
        if (comment.getSubredditName() != null) {
            String subname = comment.getSubredditName();
            SpannableStringBuilder subreddit = new SpannableStringBuilder("/r/" + subname);
            if ((SettingValues.colorSubName && Palette.getColor(subname) != Palette.getDefaultColor())) {
                subreddit.setSpan(new ForegroundColorSpan(Palette.getColor(subname)), 0, subreddit.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                subreddit.setSpan(new StyleSpan(Typeface.BOLD), 0, subreddit.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
            titleString.append(subreddit);
        }
        holder.time.setText(titleString);
        setViews(comment.getDataNode().get("body_html").asText(), comment.getSubredditName(), holder);
        int type = new FontPreferences(mContext).getFontTypeComment().getTypeface();
        Typeface typeface;
        if (type >= 0) {
            typeface = RobotoTypefaces.obtainTypeface(mContext, type);
        } else {
            typeface = Typeface.DEFAULT;
        }
        holder.content.setTypeface(typeface);
        if (comment.getTimesGilded() > 0) {
            final String timesGilded = (comment.getTimesGilded() == 1) ? "" : "\u200Ax" + Integer.toString(comment.getTimesGilded());
            SpannableStringBuilder gilded = new SpannableStringBuilder("\u00A0★" + timesGilded + "\u00A0");
            TypedArray a = mContext.obtainStyledAttributes(new FontPreferences(mContext).getPostFontStyle().getResId(), R.styleable.FontStyle);
            int fontsize = (int) (a.getDimensionPixelSize(R.styleable.FontStyle_font_cardtitle, -1) * .75);
            a.recycle();
            Bitmap image = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.gold);
            float aspectRatio = (float) (1.00 * image.getWidth() / image.getHeight());
            image = Bitmap.createScaledBitmap(image, (int) Math.ceil(fontsize * aspectRatio), (int) Math.ceil(fontsize), true);
            gilded.setSpan(new ImageSpan(mContext, image, ImageSpan.ALIGN_BASELINE), 0, 2, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            gilded.setSpan(new RelativeSizeSpan(0.75f), 3, gilded.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            holder.gild.setVisibility(View.VISIBLE);
            ((TextView) holder.gild).setText(gilded);
        } else if (holder.gild.getVisibility() == View.VISIBLE)
            holder.gild.setVisibility(View.GONE);
        if (comment.getSubmissionTitle() != null)
            holder.title.setText(Html.fromHtml(comment.getSubmissionTitle()));
        else
            holder.title.setText(Html.fromHtml(comment.getAuthor()));
        holder.itemView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                new OpenRedditLink(mContext, comment.getSubmissionId(), comment.getSubredditName(), comment.getId());
            }
        });
        holder.content.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                new OpenRedditLink(mContext, comment.getSubmissionId(), comment.getSubredditName(), comment.getId());
            }
        });
    } else if (firstHolder instanceof SpacerViewHolder) {
        firstHolder.itemView.setLayoutParams(new LinearLayout.LayoutParams(firstHolder.itemView.getWidth(), mContext.findViewById(R.id.header).getHeight()));
        if (listView.getLayoutManager() instanceof CatchStaggeredGridLayoutManager) {
            CatchStaggeredGridLayoutManager.LayoutParams layoutParams = new CatchStaggeredGridLayoutManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, mContext.findViewById(R.id.header).getHeight());
            layoutParams.setFullSpan(true);
            firstHolder.itemView.setLayoutParams(layoutParams);
        }
    }
}
Also used : CatchStaggeredGridLayoutManager(me.ccrama.redditslide.Views.CatchStaggeredGridLayoutManager) DialogInterface(android.content.DialogInterface) SpannableStringBuilder(android.text.SpannableStringBuilder) RelativeSizeSpan(android.text.style.RelativeSizeSpan) Bitmap(android.graphics.Bitmap) AlertDialogWrapper(com.afollestad.materialdialogs.AlertDialogWrapper) Dialog(android.app.Dialog) TypedArray(android.content.res.TypedArray) TextView(android.widget.TextView) PopulateSubmissionViewHolder(me.ccrama.redditslide.SubmissionViews.PopulateSubmissionViewHolder) ImageView(android.widget.ImageView) Comment(net.dean.jraw.models.Comment) Submission(net.dean.jraw.models.Submission) ForegroundColorSpan(android.text.style.ForegroundColorSpan) PopulateSubmissionViewHolder(me.ccrama.redditslide.SubmissionViews.PopulateSubmissionViewHolder) Typeface(android.graphics.Typeface) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) SubredditView(me.ccrama.redditslide.Activities.SubredditView) RecyclerView(android.support.v7.widget.RecyclerView) CreateCardView(me.ccrama.redditslide.Views.CreateCardView) FontPreferences(me.ccrama.redditslide.Visuals.FontPreferences) LayoutInflater(android.view.LayoutInflater) StyleSpan(android.text.style.StyleSpan) BottomSheet(com.cocosw.bottomsheet.BottomSheet) Contribution(net.dean.jraw.models.Contribution) SpannableStringBuilder(android.text.SpannableStringBuilder) LinearLayout(android.widget.LinearLayout) Snackbar(android.support.design.widget.Snackbar) OpenRedditLink(me.ccrama.redditslide.OpenRedditLink) ImageSpan(android.text.style.ImageSpan)

Example 8 with Submission

use of net.dean.jraw.models.Submission in project Slide by ccrama.

the class GalleryView method onBindViewHolder.

@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder2, final int i) {
    if (holder2 instanceof AlbumViewHolder) {
        final AlbumViewHolder holder = (AlbumViewHolder) holder2;
        final Submission submission = posts.get(i);
        if (submission.getThumbnails() != null && submission.getThumbnails().getSource() != null) {
            ((Reddit) main.getApplicationContext()).getImageLoader().displayImage(submission.getThumbnails().getSource().getUrl(), holder.image, ImageGridAdapter.options);
        } else {
            ((Reddit) main.getApplicationContext()).getImageLoader().displayImage(submission.getUrl(), holder.image, ImageGridAdapter.options);
        }
        double h = 0;
        int height = 0;
        if (submission.getThumbnails() != null) {
            Thumbnails.Image source = submission.getThumbnails().getSource();
            if (source != null) {
                h = getHeightFromAspectRatio(source.getHeight(), source.getWidth(), holder.image.getWidth());
                height = source.getHeight();
            }
        }
        holder.type.setVisibility(View.VISIBLE);
        switch(ContentType.getContentType(submission)) {
            case ALBUM:
                holder.type.setImageResource(R.drawable.album);
                break;
            case EXTERNAL:
            case LINK:
            case REDDIT:
                holder.type.setImageResource(R.drawable.world);
                break;
            case SELF:
                holder.type.setImageResource(R.drawable.fontsizedarker);
                break;
            case EMBEDDED:
            case GIF:
            case STREAMABLE:
            case VIDEO:
            case VID_ME:
                holder.type.setImageResource(R.drawable.play);
                break;
            default:
                holder.type.setVisibility(View.GONE);
                break;
        }
        if (h != 0) {
            if (h > 3200) {
                holder.image.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, 3200));
            } else {
                holder.image.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, (int) h));
            }
        } else {
            if (height > 3200) {
                holder.image.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, 3200));
            } else {
                holder.image.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT));
            }
        }
        holder.comments.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                v.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
                Intent i2 = new Intent(main, CommentsScreen.class);
                i2.putExtra(CommentsScreen.EXTRA_PAGE, main.subredditPosts.getPosts().indexOf(submission));
                i2.putExtra(CommentsScreen.EXTRA_SUBREDDIT, subreddit);
                i2.putExtra("fullname", submission.getFullName());
                main.startActivity(i2);
            }
        });
        holder.image.setOnLongClickListener(new View.OnLongClickListener() {

            @Override
            public boolean onLongClick(View v) {
                if (main != null) {
                    BottomSheet.Builder b = new BottomSheet.Builder(main).title(submission.getUrl()).grid();
                    int[] attrs = new int[] { R.attr.tintColor };
                    TypedArray ta = main.obtainStyledAttributes(attrs);
                    int color = ta.getColor(0, Color.WHITE);
                    Drawable open = main.getResources().getDrawable(R.drawable.ic_open_in_browser);
                    open.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
                    Drawable share = main.getResources().getDrawable(R.drawable.ic_share);
                    share.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
                    Drawable copy = main.getResources().getDrawable(R.drawable.ic_content_copy);
                    copy.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
                    ta.recycle();
                    b.sheet(R.id.open_link, open, main.getResources().getString(R.string.submission_link_extern));
                    b.sheet(R.id.share_link, share, main.getResources().getString(R.string.share_link));
                    b.sheet(R.id.copy_link, copy, main.getResources().getString(R.string.submission_link_copy));
                    b.listener(new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            switch(which) {
                                case R.id.open_link:
                                    LinkUtil.openExternally(submission.getUrl(), main);
                                    break;
                                case R.id.share_link:
                                    Reddit.defaultShareText("", submission.getUrl(), main);
                                    break;
                                case R.id.copy_link:
                                    LinkUtil.copyUrl(submission.getUrl(), main);
                                    break;
                            }
                        }
                    }).show();
                    return true;
                }
                return true;
            }
        });
        holder.image.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                ContentType.Type type = ContentType.getContentType(submission);
                if (!PostMatch.openExternal(submission.getUrl()) || type == ContentType.Type.VIDEO) {
                    switch(type) {
                        case VID_ME:
                        case STREAMABLE:
                            if (SettingValues.video) {
                                Intent myIntent = new Intent(main, MediaView.class);
                                myIntent.putExtra(MediaView.SUBREDDIT, subreddit);
                                myIntent.putExtra(MediaView.EXTRA_URL, submission.getUrl());
                                main.startActivity(myIntent);
                            } else {
                                LinkUtil.openExternally(submission.getUrl(), main);
                            }
                            break;
                        case IMGUR:
                            PopulateSubmissionViewHolder.openImage(type, main, submission, null, holder.getAdapterPosition());
                            break;
                        case EMBEDDED:
                            if (SettingValues.video) {
                                String data = Html.fromHtml(submission.getDataNode().get("media_embed").get("content").asText()).toString();
                                {
                                    Intent i = new Intent(main, FullscreenVideo.class);
                                    i.putExtra(FullscreenVideo.EXTRA_HTML, data);
                                    main.startActivity(i);
                                }
                            } else {
                                LinkUtil.openExternally(submission.getUrl(), main);
                            }
                            break;
                        case REDDIT:
                            PopulateSubmissionViewHolder.openRedditContent(submission.getUrl(), main);
                            break;
                        case LINK:
                            LinkUtil.openUrl(submission.getUrl(), Palette.getColor(submission.getSubredditName()), main);
                            break;
                        case ALBUM:
                            if (SettingValues.album) {
                                if (SettingValues.albumSwipe) {
                                    Intent i = new Intent(main, AlbumPager.class);
                                    i.putExtra(AlbumPager.SUBREDDIT, subreddit);
                                    i.putExtra(Album.EXTRA_URL, submission.getUrl());
                                    main.startActivity(i);
                                } else {
                                    Intent i = new Intent(main, Album.class);
                                    i.putExtra(Album.SUBREDDIT, subreddit);
                                    i.putExtra(Album.EXTRA_URL, submission.getUrl());
                                    main.startActivity(i);
                                }
                            } else {
                                LinkUtil.openExternally(submission.getUrl(), main);
                            }
                            break;
                        case TUMBLR:
                            if (SettingValues.image) {
                                if (SettingValues.albumSwipe) {
                                    Intent i = new Intent(main, TumblrPager.class);
                                    i.putExtra(TumblrPager.SUBREDDIT, subreddit);
                                    i.putExtra(Album.EXTRA_URL, submission.getUrl());
                                    main.startActivity(i);
                                } else {
                                    Intent i = new Intent(main, Tumblr.class);
                                    i.putExtra(Tumblr.SUBREDDIT, subreddit);
                                    i.putExtra(Album.EXTRA_URL, submission.getUrl());
                                    main.startActivity(i);
                                }
                            } else {
                                LinkUtil.openExternally(submission.getUrl(), main);
                            }
                            break;
                        case DEVIANTART:
                        case XKCD:
                        case IMAGE:
                            PopulateSubmissionViewHolder.openImage(type, main, submission, null, holder.getAdapterPosition());
                            break;
                        case GIF:
                            PopulateSubmissionViewHolder.openGif(main, submission, holder.getAdapterPosition());
                            break;
                        case NONE:
                        case SELF:
                            holder.comments.callOnClick();
                            break;
                        case VIDEO:
                            if (Reddit.videoPlugin) {
                                try {
                                    Intent sharingIntent = new Intent(Intent.ACTION_SEND);
                                    sharingIntent.setClassName("ccrama.me.slideyoutubeplugin", "ccrama.me.slideyoutubeplugin.YouTubeView");
                                    sharingIntent.putExtra("url", submission.getUrl());
                                    main.startActivity(sharingIntent);
                                } catch (Exception e) {
                                    LinkUtil.openExternally(submission.getUrl(), main);
                                }
                            } else {
                                LinkUtil.openExternally(submission.getUrl(), main);
                            }
                            break;
                    }
                } else {
                    LinkUtil.openExternally(submission.getUrl(), main);
                }
            }
        });
    }
}
Also used : DialogInterface(android.content.DialogInterface) Tumblr(me.ccrama.redditslide.Activities.Tumblr) Album(me.ccrama.redditslide.Activities.Album) MediaView(me.ccrama.redditslide.Activities.MediaView) TypedArray(android.content.res.TypedArray) TumblrPager(me.ccrama.redditslide.Activities.TumblrPager) CommentsScreen(me.ccrama.redditslide.Activities.CommentsScreen) Submission(net.dean.jraw.models.Submission) Drawable(android.graphics.drawable.Drawable) Thumbnails(net.dean.jraw.models.Thumbnails) Intent(android.content.Intent) MediaView(me.ccrama.redditslide.Activities.MediaView) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) ContentType(me.ccrama.redditslide.ContentType) AlbumPager(me.ccrama.redditslide.Activities.AlbumPager) RelativeLayout(android.widget.RelativeLayout) BottomSheet(com.cocosw.bottomsheet.BottomSheet)

Example 9 with Submission

use of net.dean.jraw.models.Submission in project Slide by ccrama.

the class MultiredditPosts method loadPhotos.

public void loadPhotos(List<Submission> submissions) {
    for (Submission submission : submissions) {
        String url;
        ContentType.Type type = ContentType.getContentType(submission);
        if (submission.getThumbnails() != null) {
            if (type == ContentType.Type.IMAGE || type == ContentType.Type.SELF || (submission.getThumbnailType() == Submission.ThumbnailType.URL)) {
                if (type == ContentType.Type.IMAGE) {
                    if (((!NetworkUtil.isConnectedWifi(c) && SettingValues.lowResMobile) || SettingValues.lowResAlways) && submission.getThumbnails() != null && submission.getThumbnails().getVariations() != null && submission.getThumbnails().getVariations().length > 0) {
                        int length = submission.getThumbnails().getVariations().length;
                        if (SettingValues.lqLow && length >= 3) {
                            url = Html.fromHtml(submission.getThumbnails().getVariations()[2].getUrl()).toString();
                        } else if (SettingValues.lqMid && length >= 4) {
                            url = Html.fromHtml(submission.getThumbnails().getVariations()[3].getUrl()).toString();
                        } else if (length >= 5) {
                            url = Html.fromHtml(submission.getThumbnails().getVariations()[length - 1].getUrl()).toString();
                        } else {
                            url = Html.fromHtml(submission.getThumbnails().getSource().getUrl()).toString();
                        }
                    } else {
                        if (submission.getDataNode().has("preview") && submission.getDataNode().get("preview").get("images").get(0).get("source").has("height")) {
                            // Load the preview image which has probably already been cached in memory instead of the direct link
                            url = submission.getDataNode().get("preview").get("images").get(0).get("source").get("url").asText();
                        } else {
                            url = submission.getUrl();
                        }
                    }
                    ((Reddit) c.getApplicationContext()).getImageLoader().loadImage(url, new ImageLoadingListener() {

                        @Override
                        public void onLoadingStarted(String imageUri, View view) {
                        }

                        @Override
                        public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
                        }

                        @Override
                        public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                        }

                        @Override
                        public void onLoadingCancelled(String imageUri, View view) {
                        }
                    });
                } else if (submission.getThumbnails() != null) {
                    if (((!NetworkUtil.isConnectedWifi(c) && SettingValues.lowResMobile) || SettingValues.lowResAlways) && submission.getThumbnails().getVariations().length != 0) {
                        int length = submission.getThumbnails().getVariations().length;
                        if (SettingValues.lqLow && length >= 3) {
                            url = Html.fromHtml(submission.getThumbnails().getVariations()[2].getUrl()).toString();
                        } else if (SettingValues.lqMid && length >= 4) {
                            url = Html.fromHtml(submission.getThumbnails().getVariations()[3].getUrl()).toString();
                        } else if (length >= 5) {
                            url = Html.fromHtml(submission.getThumbnails().getVariations()[length - 1].getUrl()).toString();
                        } else {
                            url = Html.fromHtml(submission.getThumbnails().getSource().getUrl()).toString();
                        }
                    } else {
                        url = Html.fromHtml(submission.getThumbnails().getSource().getUrl()).toString();
                    }
                    ((Reddit) c.getApplicationContext()).getImageLoader().loadImage(url, new ImageLoadingListener() {

                        @Override
                        public void onLoadingStarted(String imageUri, View view) {
                        }

                        @Override
                        public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
                        }

                        @Override
                        public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                        }

                        @Override
                        public void onLoadingCancelled(String imageUri, View view) {
                        }
                    });
                } else if (submission.getThumbnail() != null && (submission.getThumbnailType() == Submission.ThumbnailType.URL || submission.getThumbnailType() == Submission.ThumbnailType.NSFW)) {
                    ((Reddit) c.getApplicationContext()).getImageLoader().loadImage(submission.getUrl(), new ImageLoadingListener() {

                        @Override
                        public void onLoadingStarted(String imageUri, View view) {
                        }

                        @Override
                        public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
                        }

                        @Override
                        public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                        }

                        @Override
                        public void onLoadingCancelled(String imageUri, View view) {
                        }
                    });
                }
            }
        }
    }
}
Also used : Bitmap(android.graphics.Bitmap) Submission(net.dean.jraw.models.Submission) ContentType(me.ccrama.redditslide.ContentType) ImageLoadingListener(com.nostra13.universalimageloader.core.listener.ImageLoadingListener) MultiReddit(net.dean.jraw.models.MultiReddit) Reddit(me.ccrama.redditslide.Reddit) FailReason(com.nostra13.universalimageloader.core.assist.FailReason) View(android.view.View)

Example 10 with Submission

use of net.dean.jraw.models.Submission in project Slide by ccrama.

the class MultiredditView method clearSeenPosts.

private List<Submission> clearSeenPosts(boolean forever) {
    if (posts.posts != null) {
        List<Submission> originalDataSetPosts = posts.posts;
        OfflineSubreddit o = OfflineSubreddit.getSubreddit("multi" + posts.multiReddit.getDisplayName().toLowerCase(Locale.ENGLISH), false, getActivity());
        for (int i = posts.posts.size(); i > -1; i--) {
            try {
                if (HasSeen.getSeen(posts.posts.get(i))) {
                    if (forever) {
                        Hidden.setHidden(posts.posts.get(i));
                    }
                    o.clearPost(posts.posts.get(i));
                    posts.posts.remove(i);
                    if (posts.posts.isEmpty()) {
                        adapter.notifyDataSetChanged();
                    } else {
                        rv.setItemAnimator(new AlphaInAnimator());
                        adapter.notifyItemRemoved(i + 1);
                    }
                }
            } catch (IndexOutOfBoundsException e) {
            // Let the loop reset itself
            }
        }
        o.writeToMemoryNoStorage();
        rv.setItemAnimator(new SlideUpAlphaAnimator());
        return originalDataSetPosts;
    }
    return null;
}
Also used : AlphaInAnimator(com.mikepenz.itemanimators.AlphaInAnimator) Submission(net.dean.jraw.models.Submission) OfflineSubreddit(me.ccrama.redditslide.OfflineSubreddit) SlideUpAlphaAnimator(com.mikepenz.itemanimators.SlideUpAlphaAnimator)

Aggregations

Submission (net.dean.jraw.models.Submission)32 Intent (android.content.Intent)15 View (android.view.View)14 DialogInterface (android.content.DialogInterface)10 Snackbar (android.support.design.widget.Snackbar)10 TextView (android.widget.TextView)10 AlertDialogWrapper (com.afollestad.materialdialogs.AlertDialogWrapper)10 ArrayList (java.util.ArrayList)10 RecyclerView (android.support.v7.widget.RecyclerView)9 SubmissionsView (me.ccrama.redditslide.Fragments.SubmissionsView)9 ImageView (android.widget.ImageView)8 SubredditView (me.ccrama.redditslide.Activities.SubredditView)8 OfflineSubreddit (me.ccrama.redditslide.OfflineSubreddit)8 CreateCardView (me.ccrama.redditslide.Views.CreateCardView)7 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)6 TypedArray (android.content.res.TypedArray)5 LinearLayout (android.widget.LinearLayout)5 DialogAction (com.afollestad.materialdialogs.DialogAction)5 BottomSheet (com.cocosw.bottomsheet.BottomSheet)5 CommentsScreen (me.ccrama.redditslide.Activities.CommentsScreen)5