Play GIFs.

This commit is contained in:
B. Petersen
2017-04-22 14:09:40 +02:00
parent 37f401f2cd
commit 1add172770
11 changed files with 25 additions and 57 deletions
@@ -972,7 +972,7 @@ public class AndroidUtilities {
// get destination path
File destPath = null;
boolean add_to_download_manager = false;
if (msg_type == MrMsg.MR_MSG_IMAGE || msg_type == MrMsg.MR_MSG_VIDEO) {
if (msg_type == MrMsg.MR_MSG_IMAGE || msg_type == MrMsg.MR_MSG_GIF || msg_type == MrMsg.MR_MSG_VIDEO) {
destPath = AndroidUtilities.getAlbumDir();
} else if (msg_type == MrMsg.MR_MSG_FILE) {
destPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
@@ -37,7 +37,6 @@ import android.media.ThumbnailUtils;
import android.net.Uri;
import android.os.Build;
import android.provider.MediaStore;
import android.util.Log;
import com.b44t.ui.Components.AnimatedFileDrawable;
@@ -51,7 +50,6 @@ import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;
public class ImageLoader {
@@ -140,7 +140,7 @@ public class ImageReceiver implements NotificationCenter.NotificationCenterDeleg
setImage(path, null, filter, thumb, null, null, size, ext, cacheOnly);
}
public void setImage(String httpUrl, String filter, Drawable thumb, String ext, int size) {
public void setImageByPath(String httpUrl, String filter, Drawable thumb, String ext, int size) {
setImage(null, httpUrl, filter, thumb, null, null, size, ext, true);
}
@@ -161,18 +161,7 @@ public class MessageObject {
}
public static boolean isGifDocument(TLRPC.Document document) {
return document != null && document.thumb != null && document.mime_type != null && (document.mime_type.equals("image/gif") || isNewGifDocument(document));
}
public static boolean isNewGifDocument(TLRPC.Document document) {
if (document != null && document.mime_type != null && document.mime_type.equals("video/mp4")) {
for (int a = 0; a < document.attributes.size(); a++) {
if (document.attributes.get(a) instanceof TLRPC.TL_documentAttributeAnimated) {
return true;
}
}
}
return false;
return document != null && document.thumb != null && document.mime_type != null && document.mime_type.equals("image/gif");
}
private void generateThumbs(boolean update) {
@@ -720,10 +709,6 @@ public class MessageObject {
return messageOwner.media instanceof TLRPC.TL_messageMediaDocument && isGifDocument(messageOwner.media.document);
}
public boolean isNewGif() {
return messageOwner.media != null && isNewGifDocument(messageOwner.media.document);
}
public int getDuration() {
TLRPC.Document document;
document = messageOwner.media.document;
@@ -326,6 +326,7 @@ public class MrMailbox {
case 20: s = ApplicationLoader.applicationContext.getString(R.string.Error); break;
case 21: s = ApplicationLoader.applicationContext.getString(R.string.ErrSelfNotInGroup); break;
case 22: s = ApplicationLoader.applicationContext.getString(R.string.NoNetwork); break;
case 23: s = ApplicationLoader.applicationContext.getString(R.string.AttachGif); break;
}
return String2CPtr(s);
@@ -41,6 +41,7 @@ public class MrMsg {
public final static int MR_MSG_UNDEFINED = 0;
public final static int MR_MSG_TEXT = 10;
public final static int MR_MSG_IMAGE = 20;
public final static int MR_MSG_GIF = 21;
public final static int MR_MSG_AUDIO = 40;
public final static int MR_MSG_VOICE = 41;
public final static int MR_MSG_VIDEO = 50;
@@ -195,7 +196,7 @@ public class MrMsg {
ret.message = "<cannot load image>";
}
}
else if( type == MR_MSG_AUDIO || type == MR_MSG_VOICE || type == MR_MSG_VIDEO || type == MR_MSG_FILE ) {
else if( type == MR_MSG_GIF || type == MR_MSG_AUDIO || type == MR_MSG_VOICE || type == MR_MSG_VIDEO || type == MR_MSG_FILE ) {
String path = getParam('f', "");
if( !path.isEmpty()) {
ret.message = "-1"; // may be misused for video editing information
@@ -205,7 +206,18 @@ public class MrMsg {
ret.media.document.file_name = getFilename();
ret.media.document.mr_path = path;
ret.media.document.size = getBytes();
if( type == MR_MSG_AUDIO || type == MR_MSG_VOICE ) {
if( type == MR_MSG_GIF ) {
ret.media.document.mime_type = getParam('m', "image/gif");
TLRPC.PhotoSize size = new TLRPC.PhotoSize();
size.location = new TLRPC.TL_fileLocation();
size.location.mr_path = path;
size.location.local_id = -ret.id;
size.w = getParamInt('w', 320);
size.h = getParamInt('h', 240);
size.type = "s";
ret.media.document.thumb = size;
}
else if( type == MR_MSG_AUDIO || type == MR_MSG_VOICE ) {
TLRPC.TL_documentAttributeAudio attr = new TLRPC.TL_documentAttributeAudio();
attr.voice = type == MR_MSG_VOICE;
attr.duration = getParamInt('d', 0) / 1000;
@@ -540,7 +540,7 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
String originalPath = path;
String tempPath = path;
if (tempPath == null && uri != null) {
tempPath = AndroidUtilities.getPath(uri);
tempPath = AndroidUtilities.getPath(uri); // convert uri to path, this may fail
originalPath = uri.toString();
}
@@ -553,6 +553,7 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
}
isDocument = true;
} else if (tempPath == null && uri != null) {
// if conversion from uri to path fails above, we have a look at the content of the file
if (MediaController.isGif(uri)) {
isDocument = true;
originalPath = uri.toString();
@@ -66,7 +66,6 @@ import com.b44t.ui.Components.StaticLayoutEx;
import com.b44t.ui.ActionBar.Theme;
import com.b44t.ui.PhotoViewer;
import java.io.File;
import java.util.ArrayList;
import java.util.Locale;
@@ -137,7 +136,6 @@ public class ChatMessageCell extends BaseCell implements SeekBar.SeekBarDelegate
private int buttonPressed;
private boolean imagePressed;
private boolean photoNotSet;
private RectF deleteProgressRect = new RectF();
private RectF rect = new RectF();
private TLRPC.PhotoSize currentPhotoObject;
@@ -868,11 +866,6 @@ public class ChatMessageCell extends BaseCell implements SeekBar.SeekBarDelegate
}
if (currentPhotoObject == null || currentPhotoObject.location instanceof TLRPC.TL_fileLocationUnavailable) {
return true;
} else if (currentMessageObject != null && photoNotSet) {
File cacheFile = FileLoader.getPathToMessage(currentMessageObject.messageOwner);
if (cacheFile.exists()) { //TODO
return true;
}
}
return false;
}
@@ -1214,7 +1207,7 @@ public class ChatMessageCell extends BaseCell implements SeekBar.SeekBarDelegate
public void setMessageObject(MessageObject messageObject) {
boolean messageChanged = currentMessageObject != messageObject || messageObject.forceUpdate;
boolean dataChanged = currentMessageObject == messageObject && (isUserDataChanged() || photoNotSet);
boolean dataChanged = currentMessageObject == messageObject && isUserDataChanged();
if (messageChanged || dataChanged || isPhotoDataChanged(messageObject)) {
currentMessageObject = messageObject;
lastSendState = messageObject.messageOwner.send_state;
@@ -1244,7 +1237,6 @@ public class ChatMessageCell extends BaseCell implements SeekBar.SeekBarDelegate
currentPhotoFilter = null;
infoLayout = null;
buttonState = -1;
photoNotSet = false;
drawBackground = true;
drawName = false;
useSeekBarWaveform = false;
@@ -1596,7 +1588,6 @@ public class ChatMessageCell extends BaseCell implements SeekBar.SeekBarDelegate
if (photoExist /*|| MediaController.getInstance().canDownloadMedia(MediaController.AUTODOWNLOAD_MASK_PHOTO) || FileLoader.getInstance().isLoadingFile(fileName)*/) {
photoImage.setImage(currentPhotoObject.location, currentPhotoFilter, currentPhotoObjectThumb != null ? currentPhotoObjectThumb.location : null, currentPhotoFilter, noSize ? 0 : currentPhotoObject.size, null, false);
} else {
photoNotSet = true;
if (currentPhotoObjectThumb != null) {
photoImage.setImage(null, null, currentPhotoObjectThumb.location, currentPhotoFilter, 0, null, false);
} else {
@@ -1607,23 +1598,7 @@ public class ChatMessageCell extends BaseCell implements SeekBar.SeekBarDelegate
photoImage.setImageBitmap((BitmapDrawable) null);
}
} else if (messageObject.type == MessageObject.MO_TYPE8_GIF) {
String fileName = FileLoader.getAttachFileName(messageObject.messageOwner.media.document);
int localFile = 0;
if (messageObject.attachPathExists) {
localFile = 1;
} else if (messageObject.mediaExists) {
localFile = 2;
}
if (!messageObject.isSending() && (localFile != 0 /*|| MediaController.getInstance().canDownloadMedia(MediaController.AUTODOWNLOAD_MASK_GIF) && MessageObject.isNewGifDocument(messageObject.messageOwner.media.document)*/ || FileLoader.getInstance().isLoadingFile(fileName))) {
if (localFile == 1) {
photoImage.setImage(null, messageObject.isSendError() ? null : messageObject.messageOwner.attachPath, null, null, currentPhotoObject != null ? currentPhotoObject.location : null, currentPhotoFilter, 0, null, false);
} else {
photoImage.setImage(messageObject.messageOwner.media.document, null, currentPhotoObject != null ? currentPhotoObject.location : null, currentPhotoFilter, messageObject.messageOwner.media.document.size, null, false);
}
} else {
photoNotSet = true;
photoImage.setImage(null, null, currentPhotoObject != null ? currentPhotoObject.location : null, currentPhotoFilter, 0, null, false);
}
photoImage.setImageByPath(currentPhotoObject.location.mr_path, null, null, null, 0);
} else {
photoImage.setImage(null, null, currentPhotoObject != null ? currentPhotoObject.location : null, currentPhotoFilter, 0, null, false);
}
@@ -2042,10 +2017,6 @@ public class ChatMessageCell extends BaseCell implements SeekBar.SeekBarDelegate
} else {
buttonState = -1;
}
if (photoNotSet) {
setMessageObject(currentMessageObject);
}
invalidate();
}
}
@@ -1556,7 +1556,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
hasAttachment = true;
m_saveToXXMenuItem.setText(R.string.SaveToMusic);
}
if( type==MrMsg.MR_MSG_IMAGE || type == MrMsg.MR_MSG_VIDEO ) {
if( type==MrMsg.MR_MSG_IMAGE || type==MrMsg.MR_MSG_GIF || type == MrMsg.MR_MSG_VIDEO ) {
hasAttachment = true;
m_saveToXXMenuItem.setText(R.string.SaveToGallery);
}
@@ -2796,7 +2796,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
if (document != null) {
imageReceiver.setImage(document, null, "d", placeHolder != null ? new BitmapDrawable(null, placeHolder) : null, placeHolder == null ? document.thumb.location : null, String.format(Locale.US, "%d_%d", size, size), imageSize, null, false);
} else {
imageReceiver.setImage(path, filter, placeHolder != null ? new BitmapDrawable(null, placeHolder) : null, null, imageSize);
imageReceiver.setImageByPath(path, filter, placeHolder != null ? new BitmapDrawable(null, placeHolder) : null, null, imageSize);
}
} else {
imageReceiver.setImageBitmap((Bitmap) null);