Search in sources :

Example 1 with ImageQuality

use of io.swagger.client.model.ImageQuality in project android-client by GenesisVision.

the class SocialPostView method setImages.

private void setImages(Post post) {
    if (post != null && post.getImages() != null && !post.getImages().isEmpty()) {
        int pos = 0;
        int col = 1;
        int row = 1;
        int newWidth;
        WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
        Display display = wm.getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);
        int width = 0;
        if (isRepostMode) {
            width = this.getWidth();
        }
        if (width == 0) {
            width = size.x;
        }
        flexbox.removeAllViews();
        ImageQuality requiredQuality = post.getImages().size() <= 3 ? ImageQuality.ORIGINAL : ImageQuality.LOW;
        for (PostImage image : post.getImages()) {
            String logoUrl = image.getResizes().get(image.getResizes().size() - 1).getLogoUrl();
            for (PostImageResize resize : image.getResizes()) {
                if (resize.getQuality().equals(requiredQuality)) {
                    logoUrl = resize.getLogoUrl();
                    break;
                }
            }
            int maxImagesToAdd = post.getImages().size() < MAX_IMAGES ? post.getImages().size() : MAX_IMAGES;
            if (post.getImages().size() > 1 && pos == Math.round(maxImagesToAdd / 2)) {
                newWidth = (width - 10 * (Math.round(maxImagesToAdd / 2) - 1)) / pos;
                setNewSize(row, newWidth);
                col = 1;
                row++;
            }
            if (pos == maxImagesToAdd - 1) {
                int count = post.getImages().size() - pos;
                if (count == 1) {
                    count = 0;
                }
                addNewPostImageView(logoUrl, pos, count, col, row, post.getId());
                newWidth = (width - 10 * (maxImagesToAdd - Math.round(maxImagesToAdd / 2) - 1)) / (maxImagesToAdd - Math.round(maxImagesToAdd / 2));
                setNewSize(row, newWidth);
                break;
            }
            addNewPostImageView(logoUrl, pos, 0, col, row, post.getId());
            col++;
            pos++;
        }
        this.flexbox.setVisibility(View.VISIBLE);
    } else {
        this.flexbox.setVisibility(View.GONE);
    }
}
Also used : ImageQuality(io.swagger.client.model.ImageQuality) PostImage(io.swagger.client.model.PostImage) Point(android.graphics.Point) SpannableString(android.text.SpannableString) TextPaint(android.text.TextPaint) Point(android.graphics.Point) PostImageResize(io.swagger.client.model.PostImageResize) WindowManager(android.view.WindowManager) Display(android.view.Display)

Example 2 with ImageQuality

use of io.swagger.client.model.ImageQuality in project android-client by GenesisVision.

the class SocialCommentView method setImages.

private void setImages(Post comment) {
    if (comment.getImages() != null && !comment.getImages().isEmpty()) {
        int pos = 0;
        int col = 1;
        int row = 1;
        int newWidth = 100;
        WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
        Display display = wm.getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);
        flexbox.removeAllViews();
        ImageQuality requiredQuality = comment.getImages().size() <= 3 ? ImageQuality.ORIGINAL : ImageQuality.LOW;
        for (PostImage image : comment.getImages()) {
            String logoUrl = image.getResizes().get(image.getResizes().size() - 1).getLogoUrl();
            for (PostImageResize resize : image.getResizes()) {
                if (resize.getQuality().equals(requiredQuality)) {
                    logoUrl = resize.getLogoUrl();
                    break;
                }
            }
            int maxImagesToAdd = comment.getImages().size() < MAX_IMAGES ? comment.getImages().size() : MAX_IMAGES;
            if (comment.getImages().size() > 1 && pos == Math.round(maxImagesToAdd / 2)) {
                newWidth = (int) ((size.x - 10 * (Math.round(maxImagesToAdd / 2) - 1)) / pos);
                setNewSize(row, newWidth);
                col = 1;
                row++;
            }
            if (pos == maxImagesToAdd - 1) {
                int count = comment.getImages().size() - pos;
                if (count == 1) {
                    count = 0;
                }
                addNewPostImageView(logoUrl, pos, count, col, row, comment.getId());
                newWidth = (int) ((size.x - 10 * (maxImagesToAdd - Math.round(maxImagesToAdd / 2) - 1)) / (maxImagesToAdd - Math.round(maxImagesToAdd / 2)));
                setNewSize(row, newWidth);
                break;
            }
            addNewPostImageView(logoUrl, pos, 0, col, row, comment.getId());
            col++;
            pos++;
        }
        this.flexbox.setVisibility(View.VISIBLE);
    } else {
        this.flexbox.setVisibility(View.GONE);
    }
}
Also used : ImageQuality(io.swagger.client.model.ImageQuality) PostImage(io.swagger.client.model.PostImage) Point(android.graphics.Point) SpannableString(android.text.SpannableString) TextPaint(android.text.TextPaint) Point(android.graphics.Point) PostImageResize(io.swagger.client.model.PostImageResize) WindowManager(android.view.WindowManager) Display(android.view.Display)

Aggregations

Point (android.graphics.Point)2 SpannableString (android.text.SpannableString)2 TextPaint (android.text.TextPaint)2 Display (android.view.Display)2 WindowManager (android.view.WindowManager)2 ImageQuality (io.swagger.client.model.ImageQuality)2 PostImage (io.swagger.client.model.PostImage)2 PostImageResize (io.swagger.client.model.PostImageResize)2