use of org.telegram.ui.Components.OtherDocumentPlaceholderDrawable in project Telegram-FOSS by Telegram-FOSS-Team.
the class PhotoViewer method onActionClick.
private void onActionClick(boolean download) {
if (currentMessageObject == null && currentBotInlineResult == null && pageBlocksAdapter == null || currentFileNames[0] == null) {
return;
}
Uri uri = null;
File file = null;
isStreaming = false;
if (currentMessageObject != null) {
if (currentMessageObject.messageOwner.attachPath != null && currentMessageObject.messageOwner.attachPath.length() != 0) {
file = new File(currentMessageObject.messageOwner.attachPath);
if (!file.exists()) {
file = null;
}
}
if (file == null) {
file = FileLoader.getPathToMessage(currentMessageObject.messageOwner);
if (!file.exists()) {
file = null;
if (SharedConfig.streamMedia && !DialogObject.isEncryptedDialog(currentMessageObject.getDialogId()) && currentMessageObject.isVideo() && currentMessageObject.canStreamVideo()) {
try {
int reference = FileLoader.getInstance(currentMessageObject.currentAccount).getFileReference(currentMessageObject);
FileLoader.getInstance(currentAccount).loadFile(currentMessageObject.getDocument(), currentMessageObject, 1, 0);
TLRPC.Document document = currentMessageObject.getDocument();
String params = "?account=" + currentMessageObject.currentAccount + "&id=" + document.id + "&hash=" + document.access_hash + "&dc=" + document.dc_id + "&size=" + document.size + "&mime=" + URLEncoder.encode(document.mime_type, "UTF-8") + "&rid=" + reference + "&name=" + URLEncoder.encode(FileLoader.getDocumentFileName(document), "UTF-8") + "&reference=" + Utilities.bytesToHex(document.file_reference != null ? document.file_reference : new byte[0]);
uri = Uri.parse("tg://" + currentMessageObject.getFileName() + params);
isStreaming = true;
checkProgress(0, false, false);
} catch (Exception ignore) {
}
}
}
}
} else if (currentBotInlineResult != null) {
if (currentBotInlineResult.document != null) {
file = FileLoader.getPathToAttach(currentBotInlineResult.document);
if (!file.exists()) {
file = null;
}
} else if (currentBotInlineResult.content instanceof TLRPC.TL_webDocument) {
file = new File(FileLoader.getDirectory(FileLoader.MEDIA_DIR_CACHE), Utilities.MD5(currentBotInlineResult.content.url) + "." + ImageLoader.getHttpUrlExtension(currentBotInlineResult.content.url, "mp4"));
if (!file.exists()) {
file = null;
}
}
} else if (pageBlocksAdapter != null) {
TLObject media = pageBlocksAdapter.getMedia(currentIndex);
if (!(media instanceof TLRPC.Document)) {
return;
}
file = pageBlocksAdapter.getFile(currentIndex);
if (file != null && !file.exists()) {
file = null;
}
}
if (file != null && uri == null) {
uri = Uri.fromFile(file);
}
if (uri == null) {
if (download) {
if (currentMessageObject != null) {
if (!FileLoader.getInstance(currentAccount).isLoadingFile(currentFileNames[0])) {
FileLoader.getInstance(currentAccount).loadFile(currentMessageObject.getDocument(), currentMessageObject, 1, 0);
} else {
FileLoader.getInstance(currentAccount).cancelLoadFile(currentMessageObject.getDocument());
}
} else if (currentBotInlineResult != null) {
if (currentBotInlineResult.document != null) {
if (!FileLoader.getInstance(currentAccount).isLoadingFile(currentFileNames[0])) {
FileLoader.getInstance(currentAccount).loadFile(currentBotInlineResult.document, currentMessageObject, 1, 0);
} else {
FileLoader.getInstance(currentAccount).cancelLoadFile(currentBotInlineResult.document);
}
} else if (currentBotInlineResult.content instanceof TLRPC.TL_webDocument) {
if (!ImageLoader.getInstance().isLoadingHttpFile(currentBotInlineResult.content.url)) {
ImageLoader.getInstance().loadHttpFile(currentBotInlineResult.content.url, "mp4", currentAccount);
} else {
ImageLoader.getInstance().cancelLoadHttpFile(currentBotInlineResult.content.url);
}
}
} else if (pageBlocksAdapter != null) {
if (!FileLoader.getInstance(currentAccount).isLoadingFile(currentFileNames[0])) {
FileLoader.getInstance(currentAccount).loadFile((TLRPC.Document) pageBlocksAdapter.getMedia(currentIndex), pageBlocksAdapter.getParentObject(), 1, 1);
} else {
FileLoader.getInstance(currentAccount).cancelLoadFile((TLRPC.Document) pageBlocksAdapter.getMedia(currentIndex));
}
}
Drawable drawable = centerImage.getStaticThumb();
if (drawable instanceof OtherDocumentPlaceholderDrawable) {
((OtherDocumentPlaceholderDrawable) drawable).checkFileExist();
}
}
} else {
if (sharedMediaType == MediaDataController.MEDIA_FILE && !currentMessageObject.canPreviewDocument()) {
AndroidUtilities.openDocument(currentMessageObject, parentActivity, null);
return;
}
preparePlayer(uri, true, false);
}
}
use of org.telegram.ui.Components.OtherDocumentPlaceholderDrawable in project Telegram-FOSS by Telegram-FOSS-Team.
the class PhotoViewer method setIndexToImage.
private void setIndexToImage(ImageReceiver imageReceiver, int index) {
imageReceiver.setOrientation(0, false);
if (!secureDocuments.isEmpty()) {
if (index >= 0 && index < secureDocuments.size()) {
Object object = secureDocuments.get(index);
int size = (int) (AndroidUtilities.getPhotoSize() / AndroidUtilities.density);
ImageReceiver.BitmapHolder placeHolder = null;
if (currentThumb != null && imageReceiver == centerImage) {
placeHolder = currentThumb;
}
if (placeHolder == null) {
placeHolder = placeProvider.getThumbForPhoto(null, null, index);
}
SecureDocument document = secureDocuments.get(index);
int imageSize = document.secureFile.size;
imageReceiver.setImage(ImageLocation.getForSecureDocument(document), "d", null, null, placeHolder != null ? new BitmapDrawable(placeHolder.bitmap) : null, imageSize, null, null, 0);
}
} else if (!imagesArrLocals.isEmpty()) {
if (index >= 0 && index < imagesArrLocals.size()) {
Object object = imagesArrLocals.get(index);
int size = (int) (AndroidUtilities.getPhotoSize() / AndroidUtilities.density);
ImageReceiver.BitmapHolder placeHolder = null;
if (currentThumb != null && imageReceiver == centerImage) {
placeHolder = currentThumb;
}
if (placeHolder == null) {
placeHolder = placeProvider.getThumbForPhoto(null, null, index);
}
String path = null;
TLRPC.Document document = null;
WebFile webDocument = null;
ImageLocation videoThumb = null;
TLRPC.PhotoSize photo = null;
TLObject photoObject = null;
int imageSize = 0;
String filter = null;
boolean isVideo = false;
int cacheType = 0;
if (object instanceof MediaController.PhotoEntry) {
MediaController.PhotoEntry photoEntry = (MediaController.PhotoEntry) object;
isVideo = photoEntry.isVideo;
if (photoEntry.isVideo) {
if (photoEntry.thumbPath != null) {
if (fromCamera) {
Bitmap b = BitmapFactory.decodeFile(photoEntry.thumbPath);
if (b != null) {
placeHolder = new ImageReceiver.BitmapHolder(b);
photoEntry.thumbPath = null;
}
} else {
path = photoEntry.thumbPath;
}
} else {
path = "vthumb://" + photoEntry.imageId + ":" + photoEntry.path;
}
} else {
if (photoEntry.filterPath != null) {
path = photoEntry.filterPath;
} else {
imageReceiver.setOrientation(photoEntry.orientation, false);
path = photoEntry.path;
}
filter = String.format(Locale.US, "%d_%d", size, size);
}
} else if (object instanceof TLRPC.BotInlineResult) {
cacheType = 1;
TLRPC.BotInlineResult botInlineResult = ((TLRPC.BotInlineResult) object);
if (botInlineResult.type.equals("video") || MessageObject.isVideoDocument(botInlineResult.document)) {
if (botInlineResult.document != null) {
photo = FileLoader.getClosestPhotoSizeWithSize(botInlineResult.document.thumbs, 90);
photoObject = botInlineResult.document;
} else if (botInlineResult.thumb instanceof TLRPC.TL_webDocument) {
webDocument = WebFile.createWithWebDocument(botInlineResult.thumb);
}
} else if (botInlineResult.type.equals("gif") && botInlineResult.document != null) {
document = botInlineResult.document;
imageSize = botInlineResult.document.size;
TLRPC.VideoSize videoSize = MessageObject.getDocumentVideoThumb(botInlineResult.document);
if (videoSize != null) {
videoThumb = ImageLocation.getForDocument(videoSize, document);
}
filter = "d";
} else if (botInlineResult.photo != null) {
TLRPC.PhotoSize sizeFull = FileLoader.getClosestPhotoSizeWithSize(botInlineResult.photo.sizes, AndroidUtilities.getPhotoSize());
photo = sizeFull;
photoObject = botInlineResult.photo;
imageSize = sizeFull.size;
filter = String.format(Locale.US, "%d_%d", size, size);
} else if (botInlineResult.content instanceof TLRPC.TL_webDocument) {
if (botInlineResult.type.equals("gif")) {
filter = "d";
if (botInlineResult.thumb instanceof TLRPC.TL_webDocument && "video/mp4".equals(botInlineResult.thumb.mime_type)) {
videoThumb = ImageLocation.getForWebFile(WebFile.createWithWebDocument(botInlineResult.thumb));
}
} else {
filter = String.format(Locale.US, "%d_%d", size, size);
}
webDocument = WebFile.createWithWebDocument(botInlineResult.content);
}
} else if (object instanceof MediaController.SearchImage) {
cacheType = 1;
MediaController.SearchImage photoEntry = (MediaController.SearchImage) object;
if (photoEntry.photoSize != null) {
photo = photoEntry.photoSize;
photoObject = photoEntry.photo;
imageSize = photoEntry.photoSize.size;
} else if (photoEntry.filterPath != null) {
path = photoEntry.filterPath;
} else if (photoEntry.document != null) {
document = photoEntry.document;
imageSize = photoEntry.document.size;
} else {
path = photoEntry.imageUrl;
imageSize = photoEntry.size;
}
filter = "d";
}
if (document != null) {
TLRPC.PhotoSize thumb = FileLoader.getClosestPhotoSizeWithSize(document.thumbs, 90);
if (videoThumb != null) {
imageReceiver.setImage(ImageLocation.getForDocument(document), "d", videoThumb, null, placeHolder == null ? ImageLocation.getForDocument(thumb, document) : null, String.format(Locale.US, "%d_%d", size, size), placeHolder != null ? new BitmapDrawable(placeHolder.bitmap) : null, imageSize, null, object, cacheType);
} else {
imageReceiver.setImage(ImageLocation.getForDocument(document), "d", placeHolder == null ? ImageLocation.getForDocument(thumb, document) : null, String.format(Locale.US, "%d_%d", size, size), placeHolder != null ? new BitmapDrawable(placeHolder.bitmap) : null, imageSize, null, object, cacheType);
}
} else if (photo != null) {
imageReceiver.setImage(ImageLocation.getForObject(photo, photoObject), filter, placeHolder != null ? new BitmapDrawable(placeHolder.bitmap) : null, imageSize, null, object, cacheType);
} else if (webDocument != null) {
if (videoThumb != null) {
imageReceiver.setImage(ImageLocation.getForWebFile(webDocument), filter, videoThumb, null, (Drawable) null, object, cacheType);
} else {
imageReceiver.setImage(ImageLocation.getForWebFile(webDocument), filter, placeHolder != null ? new BitmapDrawable(placeHolder.bitmap) : (isVideo && parentActivity != null ? parentActivity.getResources().getDrawable(R.drawable.nophotos) : null), null, object, cacheType);
}
} else {
imageReceiver.setImage(path, filter, placeHolder != null ? new BitmapDrawable(placeHolder.bitmap) : (isVideo && parentActivity != null ? parentActivity.getResources().getDrawable(R.drawable.nophotos) : null), null, imageSize);
}
} else {
imageReceiver.setImageBitmap((Bitmap) null);
}
} else if (pageBlocksAdapter != null) {
int[] size = new int[1];
TLObject media = pageBlocksAdapter.getMedia(index);
TLRPC.PhotoSize fileLocation = pageBlocksAdapter.getFileLocation(media, size);
if (fileLocation != null) {
if (media instanceof TLRPC.Photo) {
TLRPC.Photo photo = (TLRPC.Photo) media;
ImageReceiver.BitmapHolder placeHolder = null;
if (currentThumb != null && imageReceiver == centerImage) {
placeHolder = currentThumb;
}
if (size[0] == 0) {
size[0] = -1;
}
TLRPC.PhotoSize thumbLocation = FileLoader.getClosestPhotoSizeWithSize(photo.sizes, 80);
imageReceiver.setImage(ImageLocation.getForPhoto(fileLocation, photo), null, ImageLocation.getForPhoto(thumbLocation, photo), "b", placeHolder != null ? new BitmapDrawable(placeHolder.bitmap) : null, size[0], null, pageBlocksAdapter.getParentObject(), 1);
} else if (pageBlocksAdapter.isVideo(index)) {
if (!(fileLocation.location instanceof TLRPC.TL_fileLocationUnavailable)) {
ImageReceiver.BitmapHolder placeHolder = null;
if (currentThumb != null && imageReceiver == centerImage) {
placeHolder = currentThumb;
}
imageReceiver.setImage(null, null, placeHolder == null ? ImageLocation.getForDocument(fileLocation, (TLRPC.Document) media) : null, "b", placeHolder != null ? new BitmapDrawable(placeHolder.bitmap) : null, 0, null, pageBlocksAdapter.getParentObject(), 1);
} else {
imageReceiver.setImageBitmap(parentActivity.getResources().getDrawable(R.drawable.photoview_placeholder));
}
} else if (currentAnimation != null) {
imageReceiver.setImageBitmap(currentAnimation);
currentAnimation.addSecondParentView(containerView);
}
} else {
if (size[0] == 0) {
imageReceiver.setImageBitmap((Bitmap) null);
} else {
imageReceiver.setImageBitmap(parentActivity.getResources().getDrawable(R.drawable.photoview_placeholder));
}
}
} else {
MessageObject messageObject;
if (!imagesArr.isEmpty() && index >= 0 && index < imagesArr.size()) {
messageObject = imagesArr.get(index);
imageReceiver.setShouldGenerateQualityThumb(true);
} else {
messageObject = null;
}
if (messageObject != null) {
String restrictionReason = MessagesController.getRestrictionReason(messageObject.messageOwner.restriction_reason);
if (!TextUtils.isEmpty(restrictionReason)) {
imageReceiver.setImageBitmap(parentActivity.getResources().getDrawable(R.drawable.photoview_placeholder));
return;
} else if (messageObject.isVideo()) {
if (messageObject.photoThumbs != null && !messageObject.photoThumbs.isEmpty()) {
ImageReceiver.BitmapHolder placeHolder = null;
if (currentThumb != null && imageReceiver == centerImage) {
placeHolder = currentThumb;
}
TLRPC.PhotoSize thumbLocation = FileLoader.getClosestPhotoSizeWithSize(messageObject.photoThumbs, 320);
imageReceiver.setNeedsQualityThumb(thumbLocation.w < 100 && thumbLocation.h < 100);
imageReceiver.setImage(null, null, placeHolder == null ? ImageLocation.getForObject(thumbLocation, messageObject.photoThumbsObject) : null, "b", placeHolder != null ? new BitmapDrawable(placeHolder.bitmap) : null, 0, null, messageObject, 1);
if (currentThumb != null) {
imageReceiver.setOrientation(currentThumb.orientation, false);
}
} else {
imageReceiver.setImageBitmap(parentActivity.getResources().getDrawable(R.drawable.photoview_placeholder));
}
return;
} else if (currentAnimation != null) {
currentAnimation.addSecondParentView(containerView);
imageReceiver.setImageBitmap(currentAnimation);
return;
} else if (sharedMediaType == MediaDataController.MEDIA_FILE) {
if (messageObject.canPreviewDocument()) {
TLRPC.Document document = messageObject.getDocument();
imageReceiver.setNeedsQualityThumb(true);
ImageReceiver.BitmapHolder placeHolder = null;
if (currentThumb != null && imageReceiver == centerImage) {
placeHolder = currentThumb;
}
TLRPC.PhotoSize thumbLocation = FileLoader.getClosestPhotoSizeWithSize(messageObject.photoThumbs, 100);
int size = (int) (2048 / AndroidUtilities.density);
imageReceiver.setImage(ImageLocation.getForDocument(document), String.format(Locale.US, "%d_%d", size, size), placeHolder == null ? ImageLocation.getForDocument(thumbLocation, document) : null, "b", placeHolder != null ? new BitmapDrawable(placeHolder.bitmap) : null, document.size, null, messageObject, 0);
} else {
OtherDocumentPlaceholderDrawable drawable = new OtherDocumentPlaceholderDrawable(parentActivity, containerView, messageObject);
imageReceiver.setImageBitmap(drawable);
}
return;
}
}
int[] size = new int[1];
ImageLocation imageLocation = getImageLocation(index, size);
TLObject fileLocation = getFileLocation(index, size);
imageReceiver.setNeedsQualityThumb(true);
if (imageLocation != null) {
ImageReceiver.BitmapHolder placeHolder = null;
if (currentThumb != null && imageReceiver == centerImage) {
placeHolder = currentThumb;
}
if (size[0] == 0) {
size[0] = -1;
}
TLRPC.PhotoSize thumbLocation;
TLObject photoObject;
if (messageObject != null) {
thumbLocation = FileLoader.getClosestPhotoSizeWithSize(messageObject.photoThumbs, 100);
photoObject = messageObject.photoThumbsObject;
} else {
thumbLocation = null;
photoObject = null;
}
if (thumbLocation != null && thumbLocation == fileLocation) {
thumbLocation = null;
}
boolean cacheOnly = messageObject != null && messageObject.isWebpage() || avatarsDialogId != 0 || isEvent;
Object parentObject;
ImageLocation videoThumb = null;
if (messageObject != null) {
parentObject = messageObject;
if (sharedMediaType == MediaDataController.MEDIA_GIF) {
TLRPC.Document document = messageObject.getDocument();
TLRPC.VideoSize videoSize = MessageObject.getDocumentVideoThumb(document);
if (videoSize != null) {
videoThumb = ImageLocation.getForDocument(videoSize, document);
}
}
} else if (avatarsDialogId != 0) {
if (avatarsDialogId > 0) {
parentObject = MessagesController.getInstance(currentAccount).getUser(avatarsDialogId);
} else {
parentObject = MessagesController.getInstance(currentAccount).getChat(-avatarsDialogId);
}
} else {
parentObject = null;
}
if (videoThumb != null) {
imageReceiver.setImage(imageLocation, null, videoThumb, null, placeHolder == null ? ImageLocation.getForObject(thumbLocation, photoObject) : null, "b", placeHolder != null ? new BitmapDrawable(placeHolder.bitmap) : null, size[0], null, parentObject, cacheOnly ? 1 : 0);
} else {
String filter;
if (avatarsDialogId != 0) {
filter = imageLocation.imageType == FileLoader.IMAGE_TYPE_ANIMATION ? ImageLoader.AUTOPLAY_FILTER : null;
} else {
filter = null;
}
imageReceiver.setImage(imageLocation, filter, placeHolder == null ? ImageLocation.getForObject(thumbLocation, photoObject) : null, "b", placeHolder != null ? new BitmapDrawable(placeHolder.bitmap) : null, size[0], null, parentObject, cacheOnly ? 1 : 0);
}
} else {
if (size[0] == 0) {
imageReceiver.setImageBitmap((Bitmap) null);
} else {
imageReceiver.setImageBitmap(parentActivity.getResources().getDrawable(R.drawable.photoview_placeholder));
}
}
}
}
Aggregations