Java Code Examples for org.telegram.messenger.MessageObject#getDocument()

The following examples show how to use org.telegram.messenger.MessageObject#getDocument() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SharedAudioCell.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
public void setMessageObject(MessageObject messageObject, boolean divider) {
    needDivider = divider;
    currentMessageObject = messageObject;
    TLRPC.Document document = messageObject.getDocument();

    TLRPC.PhotoSize thumb = document != null ? FileLoader.getClosestPhotoSizeWithSize(document.thumbs, 240) : null;
    if (thumb instanceof TLRPC.TL_photoSize) {
        radialProgress.setImageOverlay(thumb, document, messageObject);
    } else {
        String artworkUrl = messageObject.getArtworkUrl(true);
        if (!TextUtils.isEmpty(artworkUrl)) {
            radialProgress.setImageOverlay(artworkUrl);
        } else {
            radialProgress.setImageOverlay(null, null, null);
        }
    }
    updateButtonState(false, false);
    requestLayout();
}
 
Example 2
Source File: AudioPlayerCell.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
public void setMessageObject(MessageObject messageObject) {
    currentMessageObject = messageObject;
    TLRPC.Document document = messageObject.getDocument();
    TLRPC.PhotoSize thumb = document != null ? FileLoader.getClosestPhotoSizeWithSize(document.thumbs, 90) : null;
    if (thumb instanceof TLRPC.TL_photoSize) {
        radialProgress.setImageOverlay(thumb, document, messageObject);
    } else {
        String artworkUrl = messageObject.getArtworkUrl(true);
        if (!TextUtils.isEmpty(artworkUrl)) {
            radialProgress.setImageOverlay(artworkUrl);
        } else {
            radialProgress.setImageOverlay(null, null, null);
        }
    }
    requestLayout();
    updateButtonState(false, false);
}
 
Example 3
Source File: SharedAudioCell.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
public void setMessageObject(MessageObject messageObject, boolean divider) {
    needDivider = divider;
    currentMessageObject = messageObject;
    TLRPC.Document document = messageObject.getDocument();

    TLRPC.PhotoSize thumb = document != null ? FileLoader.getClosestPhotoSizeWithSize(document.thumbs, 240) : null;
    if (thumb instanceof TLRPC.TL_photoSize) {
        radialProgress.setImageOverlay(thumb, document, messageObject);
    } else {
        String artworkUrl = messageObject.getArtworkUrl(true);
        if (!TextUtils.isEmpty(artworkUrl)) {
            radialProgress.setImageOverlay(artworkUrl);
        } else {
            radialProgress.setImageOverlay(null, null, null);
        }
    }
    updateButtonState(false, false);
    requestLayout();
}
 
Example 4
Source File: AudioPlayerCell.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
public void setMessageObject(MessageObject messageObject) {
    currentMessageObject = messageObject;
    TLRPC.Document document = messageObject.getDocument();
    TLRPC.PhotoSize thumb = document != null ? FileLoader.getClosestPhotoSizeWithSize(document.thumbs, 90) : null;
    if (thumb instanceof TLRPC.TL_photoSize) {
        radialProgress.setImageOverlay(thumb, document, messageObject);
    } else {
        String artworkUrl = messageObject.getArtworkUrl(true);
        if (!TextUtils.isEmpty(artworkUrl)) {
            radialProgress.setImageOverlay(artworkUrl);
        } else {
            radialProgress.setImageOverlay(null, null, null);
        }
    }
    requestLayout();
    updateButtonState(false, false);
}
 
Example 5
Source File: SharedPhotoVideoCell.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public void setMessageObject(MessageObject messageObject) {
    currentMessageObject = messageObject;
    imageView.getImageReceiver().setVisible(!PhotoViewer.isShowingImage(messageObject), false);
    if (messageObject.isVideo()) {
        videoInfoContainer.setVisibility(VISIBLE);
        videoTextView.setText(AndroidUtilities.formatShortDuration(messageObject.getDuration()));
        TLRPC.Document document = messageObject.getDocument();
        TLRPC.PhotoSize thumb = FileLoader.getClosestPhotoSizeWithSize(document.thumbs, 50);
        TLRPC.PhotoSize qualityThumb = FileLoader.getClosestPhotoSizeWithSize(document.thumbs, 320);
        if (thumb == qualityThumb) {
            qualityThumb = null;
        }
        if (thumb != null) {
            imageView.setImage(ImageLocation.getForDocument(qualityThumb, document), "100_100", ImageLocation.getForDocument(thumb, document), "b", ApplicationLoader.applicationContext.getResources().getDrawable(R.drawable.photo_placeholder_in), null, null, 0, messageObject);
        } else {
            imageView.setImageResource(R.drawable.photo_placeholder_in);
        }
    } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto && messageObject.messageOwner.media.photo != null && !messageObject.photoThumbs.isEmpty()) {
        videoInfoContainer.setVisibility(INVISIBLE);
        TLRPC.PhotoSize currentPhotoObject = FileLoader.getClosestPhotoSizeWithSize(messageObject.photoThumbs, 320);
        TLRPC.PhotoSize currentPhotoObjectThumb = FileLoader.getClosestPhotoSizeWithSize(messageObject.photoThumbs, 50);
        if (messageObject.mediaExists || DownloadController.getInstance(currentAccount).canDownloadMedia(messageObject)) {
            if (currentPhotoObject == currentPhotoObjectThumb) {
                currentPhotoObjectThumb = null;
            }
            imageView.getImageReceiver().setImage(ImageLocation.getForObject(currentPhotoObject, messageObject.photoThumbsObject), "100_100", ImageLocation.getForObject(currentPhotoObjectThumb, messageObject.photoThumbsObject), "b", currentPhotoObject.size, null, messageObject, messageObject.shouldEncryptPhotoOrVideo() ? 2 : 1);
        } else {
            imageView.setImage(null, null, ImageLocation.getForObject(currentPhotoObjectThumb, messageObject.photoThumbsObject), "b", ApplicationLoader.applicationContext.getResources().getDrawable(R.drawable.photo_placeholder_in), null, null, 0, messageObject);
        }
    } else {
        videoInfoContainer.setVisibility(INVISIBLE);
        imageView.setImageResource(R.drawable.photo_placeholder_in);
    }
}
 
Example 6
Source File: OtherDocumentPlaceholderDrawable.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public OtherDocumentPlaceholderDrawable(Context context, View view, MessageObject messageObject) {
    docPaint.setTextSize(AndroidUtilities.dp(14));
    namePaint.setTextSize(AndroidUtilities.dp(19));
    sizePaint.setTextSize(AndroidUtilities.dp(15));
    buttonPaint.setTextSize(AndroidUtilities.dp(15));
    percentPaint.setTextSize(AndroidUtilities.dp(15));
    openPaint.setTextSize(AndroidUtilities.dp(15));
    progressPaint.setStrokeWidth(AndroidUtilities.dp(2));

    parentView = view;
    parentMessageObject = messageObject;
    TAG = DownloadController.getInstance(messageObject.currentAccount).generateObserverTag();

    TLRPC.Document document = messageObject.getDocument();
    if (document != null) {
        fileName = FileLoader.getDocumentFileName(messageObject.getDocument());
        if (TextUtils.isEmpty(fileName)) {
            fileName = "name";
        }
        int idx;
        ext = (idx = fileName.lastIndexOf('.')) == -1 ? "" : fileName.substring(idx + 1).toUpperCase();
        int w = (int) Math.ceil(docPaint.measureText(ext));
        if (w > AndroidUtilities.dp(40)) {
            ext = TextUtils.ellipsize(ext, docPaint, AndroidUtilities.dp(40), TextUtils.TruncateAt.END).toString();
        }
        thumbDrawable = context.getResources().getDrawable(AndroidUtilities.getThumbForNameOrMime(fileName, messageObject.getDocument().mime_type, true)).mutate();
        fileSize = AndroidUtilities.formatFileSize(document.size);
        w = (int) Math.ceil(namePaint.measureText(fileName));
        if (w > AndroidUtilities.dp(320)) {
            fileName = TextUtils.ellipsize(fileName, namePaint, AndroidUtilities.dp(320), TextUtils.TruncateAt.END).toString();
        }
    }
    checkFileExist();
}
 
Example 7
Source File: SharedPhotoVideoCell.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public void setMessageObject(MessageObject messageObject) {
    currentMessageObject = messageObject;
    imageView.getImageReceiver().setVisible(!PhotoViewer.isShowingImage(messageObject), false);
    if (messageObject.isVideo()) {
        videoInfoContainer.setVisibility(VISIBLE);
        videoTextView.setText(AndroidUtilities.formatShortDuration(messageObject.getDuration()));
        TLRPC.Document document = messageObject.getDocument();
        TLRPC.PhotoSize thumb = FileLoader.getClosestPhotoSizeWithSize(document.thumbs, 50);
        TLRPC.PhotoSize qualityThumb = FileLoader.getClosestPhotoSizeWithSize(document.thumbs, 320);
        if (thumb == qualityThumb) {
            qualityThumb = null;
        }
        if (thumb != null) {
            imageView.setImage(ImageLocation.getForDocument(qualityThumb, document), "100_100", ImageLocation.getForDocument(thumb, document), "b", ApplicationLoader.applicationContext.getResources().getDrawable(R.drawable.photo_placeholder_in), null, null, 0, messageObject);
        } else {
            imageView.setImageResource(R.drawable.photo_placeholder_in);
        }
    } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto && messageObject.messageOwner.media.photo != null && !messageObject.photoThumbs.isEmpty()) {
        videoInfoContainer.setVisibility(INVISIBLE);
        TLRPC.PhotoSize currentPhotoObject = FileLoader.getClosestPhotoSizeWithSize(messageObject.photoThumbs, 320);
        TLRPC.PhotoSize currentPhotoObjectThumb = FileLoader.getClosestPhotoSizeWithSize(messageObject.photoThumbs, 50);
        if (messageObject.mediaExists || DownloadController.getInstance(currentAccount).canDownloadMedia(messageObject)) {
            if (currentPhotoObject == currentPhotoObjectThumb) {
                currentPhotoObjectThumb = null;
            }
            imageView.getImageReceiver().setImage(ImageLocation.getForObject(currentPhotoObject, messageObject.photoThumbsObject), "100_100", ImageLocation.getForObject(currentPhotoObjectThumb, messageObject.photoThumbsObject), "b", currentPhotoObject.size, null, messageObject, messageObject.shouldEncryptPhotoOrVideo() ? 2 : 1);
        } else {
            imageView.setImage(null, null, ImageLocation.getForObject(currentPhotoObjectThumb, messageObject.photoThumbsObject), "b", ApplicationLoader.applicationContext.getResources().getDrawable(R.drawable.photo_placeholder_in), null, null, 0, messageObject);
        }
    } else {
        videoInfoContainer.setVisibility(INVISIBLE);
        imageView.setImageResource(R.drawable.photo_placeholder_in);
    }
}
 
Example 8
Source File: OtherDocumentPlaceholderDrawable.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public OtherDocumentPlaceholderDrawable(Context context, View view, MessageObject messageObject) {
    docPaint.setTextSize(AndroidUtilities.dp(14));
    namePaint.setTextSize(AndroidUtilities.dp(19));
    sizePaint.setTextSize(AndroidUtilities.dp(15));
    buttonPaint.setTextSize(AndroidUtilities.dp(15));
    percentPaint.setTextSize(AndroidUtilities.dp(15));
    openPaint.setTextSize(AndroidUtilities.dp(15));
    progressPaint.setStrokeWidth(AndroidUtilities.dp(2));

    parentView = view;
    parentMessageObject = messageObject;
    TAG = DownloadController.getInstance(messageObject.currentAccount).generateObserverTag();

    TLRPC.Document document = messageObject.getDocument();
    if (document != null) {
        fileName = FileLoader.getDocumentFileName(messageObject.getDocument());
        if (TextUtils.isEmpty(fileName)) {
            fileName = "name";
        }
        int idx;
        ext = (idx = fileName.lastIndexOf('.')) == -1 ? "" : fileName.substring(idx + 1).toUpperCase();
        int w = (int) Math.ceil(docPaint.measureText(ext));
        if (w > AndroidUtilities.dp(40)) {
            ext = TextUtils.ellipsize(ext, docPaint, AndroidUtilities.dp(40), TextUtils.TruncateAt.END).toString();
        }
        thumbDrawable = context.getResources().getDrawable(AndroidUtilities.getThumbForNameOrMime(fileName, messageObject.getDocument().mime_type, true)).mutate();
        fileSize = AndroidUtilities.formatFileSize(document.size);
        w = (int) Math.ceil(namePaint.measureText(fileName));
        if (w > AndroidUtilities.dp(320)) {
            fileName = TextUtils.ellipsize(fileName, namePaint, AndroidUtilities.dp(320), TextUtils.TruncateAt.END).toString();
        }
    }
    checkFileExist();
}
 
Example 9
Source File: SharedDocumentCell.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public void setDocument(MessageObject messageObject, boolean divider) {
    needDivider = divider;
    message = messageObject;
    loaded = false;
    loading = false;

    if (messageObject != null && messageObject.getDocument() != null) {
        int idx;
        String name = null;
        if (messageObject.isMusic()) {
            TLRPC.Document document;
            if (messageObject.type == 0) {
                document = messageObject.messageOwner.media.webpage.document;
            } else {
                document = messageObject.messageOwner.media.document;
            }
            for (int a = 0; a < document.attributes.size(); a++) {
                TLRPC.DocumentAttribute attribute = document.attributes.get(a);
                if (attribute instanceof TLRPC.TL_documentAttributeAudio) {
                    if (attribute.performer != null && attribute.performer.length() != 0 || attribute.title != null && attribute.title.length() != 0) {
                        name = messageObject.getMusicAuthor() + " - " + messageObject.getMusicTitle();
                    }
                }
            }
        }
        String fileName = FileLoader.getDocumentFileName(messageObject.getDocument());
        if (name == null) {
            name = fileName;
        }
        nameTextView.setText(name);
        placeholderImageView.setVisibility(VISIBLE);
        extTextView.setVisibility(VISIBLE);
        placeholderImageView.setImageResource(getThumbForNameOrMime(fileName, messageObject.getDocument().mime_type));
        extTextView.setText((idx = fileName.lastIndexOf('.')) == -1 ? "" : fileName.substring(idx + 1).toLowerCase());
        if (messageObject.getDocument().thumb instanceof TLRPC.TL_photoSizeEmpty || messageObject.getDocument().thumb == null) {
            thumbImageView.setVisibility(INVISIBLE);
            thumbImageView.setImageBitmap(null);
        } else {
            thumbImageView.setVisibility(VISIBLE);
            thumbImageView.setImage(messageObject.getDocument().thumb.location, "40_40", (Drawable) null);
        }
        long date = (long) messageObject.messageOwner.date * 1000;
        dateTextView.setText(String.format("%s, %s", AndroidUtilities.formatFileSize(messageObject.getDocument().size), LocaleController.formatString("formatDateAtTime", R.string.formatDateAtTime, LocaleController.getInstance().formatterYear.format(new Date(date)), LocaleController.getInstance().formatterDay.format(new Date(date)))));
    } else {
        nameTextView.setText("");
        extTextView.setText("");
        dateTextView.setText("");
        placeholderImageView.setVisibility(VISIBLE);
        extTextView.setVisibility(VISIBLE);
        thumbImageView.setVisibility(INVISIBLE);
        thumbImageView.setImageBitmap(null);
    }

    setWillNotDraw(!needDivider);
    progressView.setProgress(0, false);
    updateFileExistIcon();
}
 
Example 10
Source File: SharedPhotoVideoCell.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public void setItem(int a, int index, MessageObject messageObject) {
    messageObjects[a] = messageObject;
    indeces[a] = index;

    if (messageObject != null) {
        photoVideoViews[a].setVisibility(VISIBLE);

        PhotoVideoView photoVideoView = photoVideoViews[a];
        photoVideoView.imageView.getImageReceiver().setParentMessageObject(messageObject);
        photoVideoView.imageView.getImageReceiver().setVisible(!PhotoViewer.isShowingImage(messageObject), false);
        if (messageObject.isVideo()) {
            photoVideoView.videoInfoContainer.setVisibility(VISIBLE);
            int duration = 0;
            for (int b = 0; b < messageObject.getDocument().attributes.size(); b++) {
                TLRPC.DocumentAttribute attribute = messageObject.getDocument().attributes.get(b);
                if (attribute instanceof TLRPC.TL_documentAttributeVideo) {
                    duration = attribute.duration;
                    break;
                }
            }
            int minutes = duration / 60;
            int seconds = duration - minutes * 60;
            photoVideoView.videoTextView.setText(String.format("%d:%02d", minutes, seconds));
            if (messageObject.getDocument().thumb != null) {
                TLRPC.FileLocation location = messageObject.getDocument().thumb.location;
                photoVideoView.imageView.setImage(null, null, null, ApplicationLoader.applicationContext.getResources().getDrawable(R.drawable.photo_placeholder_in), null, location, "b", null, 0);
            } else {
                photoVideoView.imageView.setImageResource(R.drawable.photo_placeholder_in);
            }
        } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto && messageObject.messageOwner.media.photo != null && !messageObject.photoThumbs.isEmpty()) {
            photoVideoView.videoInfoContainer.setVisibility(INVISIBLE);
            TLRPC.PhotoSize photoSize = FileLoader.getClosestPhotoSizeWithSize(messageObject.photoThumbs, 80);
            photoVideoView.imageView.setImage(null, null, null, ApplicationLoader.applicationContext.getResources().getDrawable(R.drawable.photo_placeholder_in), null, photoSize.location, "b", null, 0);
        } else {
            photoVideoView.videoInfoContainer.setVisibility(INVISIBLE);
            photoVideoView.imageView.setImageResource(R.drawable.photo_placeholder_in);
        }
    } else {
        photoVideoViews[a].clearAnimation();
        photoVideoViews[a].setVisibility(INVISIBLE);
        messageObjects[a] = null;
    }
}
 
Example 11
Source File: SharedDocumentCell.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public void setDocument(MessageObject messageObject, boolean divider) {
    needDivider = divider;
    message = messageObject;
    loaded = false;
    loading = false;

    if (messageObject != null && messageObject.getDocument() != null) {
        int idx;
        String name = null;
        if (messageObject.isMusic()) {
            TLRPC.Document document;
            if (messageObject.type == 0) {
                document = messageObject.messageOwner.media.webpage.document;
            } else {
                document = messageObject.messageOwner.media.document;
            }
            for (int a = 0; a < document.attributes.size(); a++) {
                TLRPC.DocumentAttribute attribute = document.attributes.get(a);
                if (attribute instanceof TLRPC.TL_documentAttributeAudio) {
                    if (attribute.performer != null && attribute.performer.length() != 0 || attribute.title != null && attribute.title.length() != 0) {
                        name = messageObject.getMusicAuthor() + " - " + messageObject.getMusicTitle();
                    }
                }
            }
        }
        String fileName = FileLoader.getDocumentFileName(messageObject.getDocument());
        if (name == null) {
            name = fileName;
        }
        nameTextView.setText(name);
        placeholderImageView.setVisibility(VISIBLE);
        extTextView.setVisibility(VISIBLE);
        placeholderImageView.setImageResource(getThumbForNameOrMime(fileName, messageObject.getDocument().mime_type));
        extTextView.setText((idx = fileName.lastIndexOf('.')) == -1 ? "" : fileName.substring(idx + 1).toLowerCase());
        if (messageObject.getDocument().thumb instanceof TLRPC.TL_photoSizeEmpty || messageObject.getDocument().thumb == null) {
            thumbImageView.setVisibility(INVISIBLE);
            thumbImageView.setImageBitmap(null);
        } else {
            thumbImageView.setVisibility(VISIBLE);
            thumbImageView.setImage(messageObject.getDocument().thumb.location, "40_40", (Drawable) null);
        }
        long date = (long) messageObject.messageOwner.date * 1000;
        dateTextView.setText(String.format("%s, %s", AndroidUtilities.formatFileSize(messageObject.getDocument().size), LocaleController.formatString("formatDateAtTime", R.string.formatDateAtTime, LocaleController.getInstance().formatterYear.format(new Date(date)), LocaleController.getInstance().formatterDay.format(new Date(date)))));
    } else {
        nameTextView.setText("");
        extTextView.setText("");
        dateTextView.setText("");
        placeholderImageView.setVisibility(VISIBLE);
        extTextView.setVisibility(VISIBLE);
        thumbImageView.setVisibility(INVISIBLE);
        thumbImageView.setImageBitmap(null);
    }

    setWillNotDraw(!needDivider);
    progressView.setProgress(0, false);
    updateFileExistIcon();
}
 
Example 12
Source File: SharedPhotoVideoCell.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public void setItem(int a, int index, MessageObject messageObject) {
    messageObjects[a] = messageObject;
    indeces[a] = index;

    if (messageObject != null) {
        photoVideoViews[a].setVisibility(VISIBLE);

        PhotoVideoView photoVideoView = photoVideoViews[a];
        photoVideoView.imageView.getImageReceiver().setParentMessageObject(messageObject);
        photoVideoView.imageView.getImageReceiver().setVisible(!PhotoViewer.isShowingImage(messageObject), false);
        if (messageObject.isVideo()) {
            photoVideoView.videoInfoContainer.setVisibility(VISIBLE);
            int duration = 0;
            for (int b = 0; b < messageObject.getDocument().attributes.size(); b++) {
                TLRPC.DocumentAttribute attribute = messageObject.getDocument().attributes.get(b);
                if (attribute instanceof TLRPC.TL_documentAttributeVideo) {
                    duration = attribute.duration;
                    break;
                }
            }
            int minutes = duration / 60;
            int seconds = duration - minutes * 60;
            photoVideoView.videoTextView.setText(String.format("%d:%02d", minutes, seconds));
            if (messageObject.getDocument().thumb != null) {
                TLRPC.FileLocation location = messageObject.getDocument().thumb.location;
                photoVideoView.imageView.setImage(null, null, null, ApplicationLoader.applicationContext.getResources().getDrawable(R.drawable.photo_placeholder_in), null, location, "b", null, 0);
            } else {
                photoVideoView.imageView.setImageResource(R.drawable.photo_placeholder_in);
            }
        } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto && messageObject.messageOwner.media.photo != null && !messageObject.photoThumbs.isEmpty()) {
            photoVideoView.videoInfoContainer.setVisibility(INVISIBLE);
            TLRPC.PhotoSize photoSize = FileLoader.getClosestPhotoSizeWithSize(messageObject.photoThumbs, 80);
            photoVideoView.imageView.setImage(null, null, null, ApplicationLoader.applicationContext.getResources().getDrawable(R.drawable.photo_placeholder_in), null, photoSize.location, "b", null, 0);
        } else {
            photoVideoView.videoInfoContainer.setVisibility(INVISIBLE);
            photoVideoView.imageView.setImageResource(R.drawable.photo_placeholder_in);
        }
    } else {
        photoVideoViews[a].clearAnimation();
        photoVideoViews[a].setVisibility(INVISIBLE);
        messageObjects[a] = null;
    }
}
 
Example 13
Source File: SharedDocumentCell.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
public void setDocument(MessageObject messageObject, boolean divider) {
    needDivider = divider;
    message = messageObject;
    loaded = false;
    loading = false;

    TLRPC.Document document = messageObject.getDocument();
    if (messageObject != null && document != null) {
        int idx;
        String name = null;
        if (messageObject.isMusic()) {
            for (int a = 0; a < document.attributes.size(); a++) {
                TLRPC.DocumentAttribute attribute = document.attributes.get(a);
                if (attribute instanceof TLRPC.TL_documentAttributeAudio) {
                    if (attribute.performer != null && attribute.performer.length() != 0 || attribute.title != null && attribute.title.length() != 0) {
                        name = messageObject.getMusicAuthor() + " - " + messageObject.getMusicTitle();
                    }
                }
            }
        }
        String fileName = FileLoader.getDocumentFileName(document);
        if (name == null) {
            name = fileName;
        }
        nameTextView.setText(name);
        placeholderImageView.setVisibility(VISIBLE);
        extTextView.setVisibility(VISIBLE);
        placeholderImageView.setImageResource(AndroidUtilities.getThumbForNameOrMime(fileName, document.mime_type, false));
        extTextView.setText((idx = fileName.lastIndexOf('.')) == -1 ? "" : fileName.substring(idx + 1).toLowerCase());

        TLRPC.PhotoSize bigthumb = FileLoader.getClosestPhotoSizeWithSize(document.thumbs, 320);
        TLRPC.PhotoSize thumb = FileLoader.getClosestPhotoSizeWithSize(document.thumbs, 40);
        if (thumb == bigthumb) {
            bigthumb = null;
        }
        if (thumb instanceof TLRPC.TL_photoSizeEmpty || thumb == null) {
            thumbImageView.setVisibility(INVISIBLE);
            thumbImageView.setImageBitmap(null);
            extTextView.setAlpha(1.0f);
            placeholderImageView.setAlpha(1.0f);
        } else {
            thumbImageView.getImageReceiver().setNeedsQualityThumb(bigthumb == null);
            thumbImageView.getImageReceiver().setShouldGenerateQualityThumb(bigthumb == null);

            thumbImageView.setVisibility(VISIBLE);
            thumbImageView.setImage(ImageLocation.getForDocument(bigthumb, document), "40_40", ImageLocation.getForDocument(thumb, document), "40_40_b", null, 0, 1, messageObject);
        }
        long date = (long) messageObject.messageOwner.date * 1000;
        dateTextView.setText(String.format("%s, %s", AndroidUtilities.formatFileSize(document.size), LocaleController.formatString("formatDateAtTime", R.string.formatDateAtTime, LocaleController.getInstance().formatterYear.format(new Date(date)), LocaleController.getInstance().formatterDay.format(new Date(date)))));
    } else {
        nameTextView.setText("");
        extTextView.setText("");
        dateTextView.setText("");
        placeholderImageView.setVisibility(VISIBLE);
        extTextView.setVisibility(VISIBLE);
        extTextView.setAlpha(1.0f);
        placeholderImageView.setAlpha(1.0f);
        thumbImageView.setVisibility(INVISIBLE);
        thumbImageView.setImageBitmap(null);
    }

    setWillNotDraw(!needDivider);
    progressView.setProgress(0, false);
    updateFileExistIcon();
}
 
Example 14
Source File: SharedDocumentCell.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
public void setDocument(MessageObject messageObject, boolean divider) {
    needDivider = divider;
    message = messageObject;
    loaded = false;
    loading = false;

    TLRPC.Document document = messageObject.getDocument();
    if (messageObject != null && document != null) {
        int idx;
        String name = null;
        if (messageObject.isMusic()) {
            for (int a = 0; a < document.attributes.size(); a++) {
                TLRPC.DocumentAttribute attribute = document.attributes.get(a);
                if (attribute instanceof TLRPC.TL_documentAttributeAudio) {
                    if (attribute.performer != null && attribute.performer.length() != 0 || attribute.title != null && attribute.title.length() != 0) {
                        name = messageObject.getMusicAuthor() + " - " + messageObject.getMusicTitle();
                    }
                }
            }
        }
        String fileName = FileLoader.getDocumentFileName(document);
        if (name == null) {
            name = fileName;
        }
        nameTextView.setText(name);
        placeholderImageView.setVisibility(VISIBLE);
        extTextView.setVisibility(VISIBLE);
        placeholderImageView.setImageResource(AndroidUtilities.getThumbForNameOrMime(fileName, document.mime_type, false));
        extTextView.setText((idx = fileName.lastIndexOf('.')) == -1 ? "" : fileName.substring(idx + 1).toLowerCase());

        TLRPC.PhotoSize bigthumb = FileLoader.getClosestPhotoSizeWithSize(document.thumbs, 320);
        TLRPC.PhotoSize thumb = FileLoader.getClosestPhotoSizeWithSize(document.thumbs, 40);
        if (thumb == bigthumb) {
            bigthumb = null;
        }
        if (thumb instanceof TLRPC.TL_photoSizeEmpty || thumb == null) {
            thumbImageView.setVisibility(INVISIBLE);
            thumbImageView.setImageBitmap(null);
            extTextView.setAlpha(1.0f);
            placeholderImageView.setAlpha(1.0f);
        } else {
            thumbImageView.getImageReceiver().setNeedsQualityThumb(bigthumb == null);
            thumbImageView.getImageReceiver().setShouldGenerateQualityThumb(bigthumb == null);

            thumbImageView.setVisibility(VISIBLE);
            thumbImageView.setImage(ImageLocation.getForDocument(bigthumb, document), "40_40", ImageLocation.getForDocument(thumb, document), "40_40_b", null, 0, 1, messageObject);
        }
        long date = (long) messageObject.messageOwner.date * 1000;
        dateTextView.setText(String.format("%s, %s", AndroidUtilities.formatFileSize(document.size), LocaleController.formatString("formatDateAtTime", R.string.formatDateAtTime, LocaleController.getInstance().formatterYear.format(new Date(date)), LocaleController.getInstance().formatterDay.format(new Date(date)))));
    } else {
        nameTextView.setText("");
        extTextView.setText("");
        dateTextView.setText("");
        placeholderImageView.setVisibility(VISIBLE);
        extTextView.setVisibility(VISIBLE);
        extTextView.setAlpha(1.0f);
        placeholderImageView.setAlpha(1.0f);
        thumbImageView.setVisibility(INVISIBLE);
        thumbImageView.setImageBitmap(null);
    }

    setWillNotDraw(!needDivider);
    progressView.setProgress(0, false);
    updateFileExistIcon();
}