Search in sources :

Example 1 with TransparentTagTextView

use of me.ccrama.redditslide.Views.TransparentTagTextView in project Slide by ccrama.

the class HeaderImageLinkView method doImageAndText.

public void doImageAndText(final Submission submission, boolean full, String baseSub, boolean news) {
    boolean fullImage = ContentType.fullImage(type);
    thumbUsed = false;
    setVisibility(View.VISIBLE);
    String url = "";
    boolean forceThumb = false;
    thumbImage2.setImageResource(android.R.color.transparent);
    boolean loadLq = (((!NetworkUtil.isConnectedWifi(getContext()) && SettingValues.lowResMobile) || SettingValues.lowResAlways));
    if (type == ContentType.Type.SELF && SettingValues.hideSelftextLeadImage || SettingValues.noImages && submission.isSelfPost()) {
        setVisibility(View.GONE);
        if (wrapArea != null)
            wrapArea.setVisibility(View.GONE);
        thumbImage2.setVisibility(View.GONE);
    } else {
        if (submission.getThumbnails() != null) {
            int height = submission.getThumbnails().getSource().getHeight();
            int width = submission.getThumbnails().getSource().getWidth();
            if (full) {
                if (!fullImage && height < dpToPx(50) && type != ContentType.Type.SELF) {
                    forceThumb = true;
                } else if (SettingValues.cropImage) {
                    backdrop.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, dpToPx(200)));
                } else {
                    double h = getHeightFromAspectRatio(height, width);
                    if (h != 0) {
                        if (h > 3200) {
                            backdrop.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, 3200));
                        } else {
                            backdrop.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, (int) h));
                        }
                    } else {
                        backdrop.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
                    }
                }
            } else if (SettingValues.bigPicCropped) {
                if (!fullImage && height < dpToPx(50)) {
                    forceThumb = true;
                } else {
                    backdrop.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, dpToPx(200)));
                }
            } else if (fullImage || height >= dpToPx(50)) {
                double h = getHeightFromAspectRatio(height, width);
                if (h != 0) {
                    if (h > 3200) {
                        backdrop.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, 3200));
                    } else {
                        backdrop.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, (int) h));
                    }
                } else {
                    backdrop.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
                }
            } else {
                forceThumb = true;
            }
        }
        JsonNode thumbnail = submission.getDataNode().get("thumbnail");
        Submission.ThumbnailType thumbnailType;
        if (!submission.getDataNode().get("thumbnail").isNull()) {
            thumbnailType = submission.getThumbnailType();
        } else {
            thumbnailType = Submission.ThumbnailType.NONE;
        }
        JsonNode node = submission.getDataNode();
        if (!SettingValues.ignoreSubSetting && node != null && node.has("sr_detail") && node.get("sr_detail").has("show_media") && !node.get("sr_detail").get("show_media").asBoolean()) {
            thumbnailType = Submission.ThumbnailType.NONE;
        }
        if (SettingValues.noImages && loadLq) {
            setVisibility(View.GONE);
            if (!full && !submission.isSelfPost()) {
                thumbImage2.setVisibility(View.VISIBLE);
            } else {
                if (full && !submission.isSelfPost())
                    wrapArea.setVisibility(View.VISIBLE);
            }
            thumbImage2.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.web));
            thumbUsed = true;
        } else if (submission.isNsfw() && SettingValues.getIsNSFWEnabled() || (baseSub != null && submission.isNsfw() && SettingValues.hideNSFWCollection && (baseSub.equals("frontpage") || baseSub.equals("all") || baseSub.contains("+") || baseSub.equals("popular")))) {
            setVisibility(View.GONE);
            if (!full || forceThumb) {
                thumbImage2.setVisibility(View.VISIBLE);
            } else {
                wrapArea.setVisibility(View.VISIBLE);
            }
            if (submission.isSelfPost() && full) {
                wrapArea.setVisibility(View.GONE);
            } else {
                thumbImage2.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.nsfw));
                thumbUsed = true;
            }
            loadedUrl = submission.getUrl();
        } else if (submission.getDataNode().get("spoiler").asBoolean()) {
            setVisibility(View.GONE);
            if (!full || forceThumb) {
                thumbImage2.setVisibility(View.VISIBLE);
            } else {
                wrapArea.setVisibility(View.VISIBLE);
            }
            if (submission.isSelfPost() && full) {
                wrapArea.setVisibility(View.GONE);
            } else {
                thumbImage2.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.spoiler));
                thumbUsed = true;
            }
            loadedUrl = submission.getUrl();
        } else if (type != ContentType.Type.IMAGE && type != ContentType.Type.SELF && (!thumbnail.isNull() && (thumbnailType != Submission.ThumbnailType.URL)) || thumbnail.asText().isEmpty() && !submission.isSelfPost()) {
            setVisibility(View.GONE);
            if (!full) {
                thumbImage2.setVisibility(View.VISIBLE);
            } else {
                wrapArea.setVisibility(View.VISIBLE);
            }
            thumbImage2.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.web));
            thumbUsed = true;
            loadedUrl = submission.getUrl();
        } else if (type == ContentType.Type.IMAGE && !thumbnail.isNull() && !thumbnail.asText().isEmpty()) {
            if (loadLq && submission.getThumbnails() != null && submission.getThumbnails().getVariations() != null && submission.getThumbnails().getVariations().length > 0) {
                if (ContentType.isImgurImage(submission.getUrl())) {
                    url = submission.getUrl();
                    url = url.substring(0, url.lastIndexOf(".")) + (SettingValues.lqLow ? "m" : (SettingValues.lqMid ? "l" : "h")) + url.substring(url.lastIndexOf("."), url.length());
                } else {
                    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();
                    }
                }
                lq = true;
            } 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();
                }
            }
            if (!full && !SettingValues.isPicsEnabled(baseSub) || forceThumb) {
                if (!submission.isSelfPost() || full) {
                    if (!full) {
                        thumbImage2.setVisibility(View.VISIBLE);
                    } else {
                        wrapArea.setVisibility(View.VISIBLE);
                    }
                    loadedUrl = url;
                    if (!full) {
                        ((Reddit) getContext().getApplicationContext()).getImageLoader().displayImage(url, thumbImage2);
                    } else {
                        ((Reddit) getContext().getApplicationContext()).getImageLoader().displayImage(url, thumbImage2, bigOptions);
                    }
                } else {
                    thumbImage2.setVisibility(View.GONE);
                }
                setVisibility(View.GONE);
            } else {
                loadedUrl = url;
                if (!full) {
                    ((Reddit) getContext().getApplicationContext()).getImageLoader().displayImage(url, backdrop);
                } else {
                    ((Reddit) getContext().getApplicationContext()).getImageLoader().displayImage(url, backdrop, bigOptions);
                }
                setVisibility(View.VISIBLE);
                if (!full) {
                    thumbImage2.setVisibility(View.GONE);
                } else {
                    wrapArea.setVisibility(View.GONE);
                }
            }
        } else if (submission.getThumbnails() != null) {
            if (loadLq && submission.getThumbnails().getVariations().length != 0) {
                if (ContentType.isImgurImage(submission.getUrl())) {
                    url = submission.getUrl();
                    url = url.substring(0, url.lastIndexOf(".")) + (SettingValues.lqLow ? "m" : (SettingValues.lqMid ? "l" : "h")) + url.substring(url.lastIndexOf("."), url.length());
                } else {
                    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();
                    }
                }
                lq = true;
            } else {
                url = Html.fromHtml(submission.getThumbnails().getSource().getUrl()).toString();
            }
            if (!SettingValues.isPicsEnabled(baseSub) && !full || forceThumb || (news && submission.getScore() < 5000)) {
                if (!full) {
                    thumbImage2.setVisibility(View.VISIBLE);
                } else {
                    wrapArea.setVisibility(View.VISIBLE);
                }
                loadedUrl = url;
                ((Reddit) getContext().getApplicationContext()).getImageLoader().displayImage(url, thumbImage2);
                setVisibility(View.GONE);
            } else {
                loadedUrl = url;
                if (!full) {
                    ((Reddit) getContext().getApplicationContext()).getImageLoader().displayImage(url, backdrop);
                } else {
                    ((Reddit) getContext().getApplicationContext()).getImageLoader().displayImage(url, backdrop, bigOptions);
                }
                setVisibility(View.VISIBLE);
                if (!full) {
                    thumbImage2.setVisibility(View.GONE);
                } else {
                    wrapArea.setVisibility(View.GONE);
                }
            }
        } else if (!thumbnail.isNull() && submission.getThumbnail() != null && (submission.getThumbnailType() == Submission.ThumbnailType.URL || (!thumbnail.isNull() && submission.isNsfw() && SettingValues.getIsNSFWEnabled()))) {
            if (!full) {
                thumbImage2.setVisibility(View.VISIBLE);
            } else {
                wrapArea.setVisibility(View.VISIBLE);
            }
            loadedUrl = url;
            ((Reddit) getContext().getApplicationContext()).getImageLoader().displayImage(url, thumbImage2);
            setVisibility(View.GONE);
        } else {
            if (!full) {
                thumbImage2.setVisibility(View.GONE);
            } else {
                wrapArea.setVisibility(View.GONE);
            }
            setVisibility(View.GONE);
        }
        if (full) {
            if (wrapArea.getVisibility() == View.VISIBLE) {
                title = secondTitle;
                info = secondSubTitle;
                setBottomSheet(wrapArea, submission, full);
            } else {
                title = findViewById(R.id.textimage);
                info = findViewById(R.id.subtextimage);
                if (forceThumb || (submission.isNsfw() && submission.getThumbnailType() == Submission.ThumbnailType.NSFW || type != ContentType.Type.IMAGE && type != ContentType.Type.SELF && !submission.getDataNode().get("thumbnail").isNull() && (submission.getThumbnailType() != Submission.ThumbnailType.URL))) {
                    setBottomSheet(thumbImage2, submission, full);
                } else {
                    setBottomSheet(this, submission, full);
                }
            }
        } else {
            title = findViewById(R.id.textimage);
            info = findViewById(R.id.subtextimage);
            setBottomSheet(thumbImage2, submission, full);
            setBottomSheet(this, submission, full);
        }
        if (SettingValues.smallTag && !full && !news) {
            title = (TextView) findViewById(R.id.tag);
            findViewById(R.id.tag).setVisibility(View.VISIBLE);
            info = null;
        } else {
            findViewById(R.id.tag).setVisibility(View.GONE);
            title.setVisibility(View.VISIBLE);
            info.setVisibility(View.VISIBLE);
        }
        if (SettingValues.smallTag && !full && !news) {
            ((TransparentTagTextView) title).init(getContext());
        }
        title.setText(ContentType.getContentDescription(submission, getContext()));
        if (info != null)
            info.setText(submission.getDomain());
    }
}
Also used : Submission(net.dean.jraw.models.Submission) Reddit(me.ccrama.redditslide.Reddit) RelativeLayout(android.widget.RelativeLayout) JsonNode(com.fasterxml.jackson.databind.JsonNode) TransparentTagTextView(me.ccrama.redditslide.Views.TransparentTagTextView)

Aggregations

RelativeLayout (android.widget.RelativeLayout)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Reddit (me.ccrama.redditslide.Reddit)1 TransparentTagTextView (me.ccrama.redditslide.Views.TransparentTagTextView)1 Submission (net.dean.jraw.models.Submission)1