mirror of
https://github.com/DrKLO/Telegram.git
synced 2024-12-22 14:35:03 +01:00
Fixed sharing gif files from picasa and G+ albums
This commit is contained in:
parent
c4e113dc67
commit
4beb03dd56
6 changed files with 147 additions and 22 deletions
|
@ -82,7 +82,7 @@ android {
|
|||
defaultConfig {
|
||||
minSdkVersion 8
|
||||
targetSdkVersion 19
|
||||
versionCode 229
|
||||
versionName "1.4.12"
|
||||
versionCode 230
|
||||
versionName "1.4.13"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ import android.media.MediaRecorder;
|
|||
import android.media.audiofx.AutomaticGainControl;
|
||||
import android.net.Uri;
|
||||
import android.os.Environment;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.os.Vibrator;
|
||||
import android.provider.MediaStore;
|
||||
import android.view.View;
|
||||
|
@ -38,6 +39,7 @@ import java.nio.ByteBuffer;
|
|||
import java.nio.channels.FileChannel;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.concurrent.Semaphore;
|
||||
|
@ -1424,4 +1426,81 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
|
|||
currentGifMessageObject = null;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isGif(Uri uri) {
|
||||
ParcelFileDescriptor parcelFD = null;
|
||||
FileInputStream input = null;
|
||||
try {
|
||||
parcelFD = ApplicationLoader.applicationContext.getContentResolver().openFileDescriptor(uri, "r");
|
||||
input = new FileInputStream(parcelFD.getFileDescriptor());
|
||||
if (input.getChannel().size() > 3) {
|
||||
byte[] header = new byte[3];
|
||||
input.read(header, 0, 3);
|
||||
String str = new String(header);
|
||||
if (str != null && str.equalsIgnoreCase("gif")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
} finally {
|
||||
try {
|
||||
if (parcelFD != null) {
|
||||
parcelFD.close();
|
||||
}
|
||||
} catch (Exception e2) {
|
||||
FileLog.e("tmessages", e2);
|
||||
}
|
||||
try {
|
||||
if (input != null) {
|
||||
input.close();
|
||||
}
|
||||
} catch (Exception e2) {
|
||||
FileLog.e("tmessages", e2);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static String copyDocumentToCache(Uri uri) {
|
||||
ParcelFileDescriptor parcelFD = null;
|
||||
FileInputStream input = null;
|
||||
FileOutputStream output = null;
|
||||
try {
|
||||
int id = UserConfig.lastLocalId;
|
||||
UserConfig.lastLocalId--;
|
||||
parcelFD = ApplicationLoader.applicationContext.getContentResolver().openFileDescriptor(uri, "r");
|
||||
input = new FileInputStream(parcelFD.getFileDescriptor());
|
||||
File f = new File(Utilities.getCacheDir(), String.format(Locale.US, "%d.gif", id));
|
||||
output = new FileOutputStream(f);
|
||||
input.getChannel().transferTo(0, input.getChannel().size(), output.getChannel());
|
||||
UserConfig.saveConfig(false);
|
||||
return f.getAbsolutePath();
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
} finally {
|
||||
try {
|
||||
if (parcelFD != null) {
|
||||
parcelFD.close();
|
||||
}
|
||||
} catch (Exception e2) {
|
||||
FileLog.e("tmessages", e2);
|
||||
}
|
||||
try {
|
||||
if (input != null) {
|
||||
input.close();
|
||||
}
|
||||
} catch (Exception e2) {
|
||||
FileLog.e("tmessages", e2);
|
||||
}
|
||||
try {
|
||||
if (output != null) {
|
||||
output.close();
|
||||
}
|
||||
} catch (Exception e2) {
|
||||
FileLog.e("tmessages", e2);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2134,8 +2134,22 @@ public class MessagesController implements NotificationCenter.NotificationCenter
|
|||
size2.location = size.location;
|
||||
}
|
||||
}
|
||||
sentMessage.message = newMsg.message;
|
||||
if (newMsg.attachPath != null && newMsg.attachPath.startsWith(Utilities.getCacheDir().getAbsolutePath())) {
|
||||
File cacheFile = new File(newMsg.attachPath);
|
||||
File cacheFile2 = new File(Utilities.getCacheDir(), MessageObject.getAttachFileName(sentMessage.media.document));
|
||||
boolean result = cacheFile.renameTo(cacheFile2);
|
||||
if (result) {
|
||||
newMsg.attachPath = null;
|
||||
newMsg.media.document.dc_id = sentMessage.media.document.dc_id;
|
||||
newMsg.media.document.id = sentMessage.media.document.id;
|
||||
} else {
|
||||
sentMessage.attachPath = newMsg.attachPath;
|
||||
sentMessage.message = newMsg.message;
|
||||
}
|
||||
} else {
|
||||
sentMessage.attachPath = newMsg.attachPath;
|
||||
sentMessage.message = newMsg.message;
|
||||
}
|
||||
} else if (sentMessage.media instanceof TLRPC.TL_messageMediaAudio && sentMessage.media.audio != null && newMsg.media instanceof TLRPC.TL_messageMediaAudio && newMsg.media.audio != null) {
|
||||
sentMessage.message = newMsg.message;
|
||||
sentMessage.attachPath = newMsg.attachPath;
|
||||
|
@ -2205,6 +2219,13 @@ public class MessagesController implements NotificationCenter.NotificationCenter
|
|||
newMsg.media.document.path = document.path;
|
||||
newMsg.media.document.thumb = document.thumb;
|
||||
newMsg.media.document.dc_id = file.dc_id;
|
||||
|
||||
if (document.path != null && document.path.startsWith(Utilities.getCacheDir().getAbsolutePath())) {
|
||||
File cacheFile = new File(document.path);
|
||||
File cacheFile2 = new File(Utilities.getCacheDir(), MessageObject.getAttachFileName(newMsg.media.document));
|
||||
cacheFile.renameTo(cacheFile2);
|
||||
}
|
||||
|
||||
ArrayList<TLRPC.Message> arr = new ArrayList<TLRPC.Message>();
|
||||
arr.add(newMsg);
|
||||
MessagesStorage.getInstance().putMessages(arr, false, true);
|
||||
|
|
|
@ -34,7 +34,7 @@ public class NativeLoader {
|
|||
File f = null;
|
||||
if (context != null) {
|
||||
try {
|
||||
f = (File) ApplicationInfo.class.getField("nativeLibraryDir").get(context.getApplicationInfo());
|
||||
f = new File((String)ApplicationInfo.class.getField("nativeLibraryDir").get(context.getApplicationInfo()));
|
||||
} catch (Throwable th) {
|
||||
th.printStackTrace();
|
||||
}
|
||||
|
|
|
@ -1556,7 +1556,18 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
|
|||
return;
|
||||
}
|
||||
String tempPath = Utilities.getPath(data.getData());
|
||||
|
||||
boolean isGif = false;
|
||||
if (tempPath != null && tempPath.endsWith(".gif")) {
|
||||
isGif = true;
|
||||
} else if (tempPath == null) {
|
||||
isGif = MediaController.isGif(data.getData());
|
||||
if (isGif) {
|
||||
tempPath = MediaController.copyDocumentToCache(data.getData());
|
||||
}
|
||||
}
|
||||
|
||||
if (tempPath != null && isGif) {
|
||||
processSendingDocument(tempPath);
|
||||
} else {
|
||||
processSendingPhoto(null, data.getData());
|
||||
|
|
|
@ -38,6 +38,7 @@ import org.telegram.PhoneFormat.PhoneFormat;
|
|||
import org.telegram.messenger.BuildVars;
|
||||
import org.telegram.messenger.ConnectionsManager;
|
||||
import org.telegram.messenger.FileLog;
|
||||
import org.telegram.messenger.MediaController;
|
||||
import org.telegram.messenger.MessagesController;
|
||||
import org.telegram.messenger.NotificationCenter;
|
||||
import org.telegram.messenger.R;
|
||||
|
@ -336,22 +337,24 @@ public class LaunchActivity extends ActionBarActivity implements NotificationCen
|
|||
if (!(parcelable instanceof Uri)) {
|
||||
parcelable = Uri.parse(parcelable.toString());
|
||||
}
|
||||
if (parcelable != null && type != null && type.startsWith("image/")) {
|
||||
String tempPath = Utilities.getPath((Uri)parcelable);
|
||||
if (type.equals("image/gif") || tempPath != null && tempPath.endsWith(".gif")) {
|
||||
try {
|
||||
documentPath = Utilities.getPath((Uri)parcelable);
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
Uri uri = (Uri)parcelable;
|
||||
if (uri != null && type != null && type.startsWith("image/")) {
|
||||
String tempPath = Utilities.getPath(uri);
|
||||
boolean isGif = false;
|
||||
if (tempPath != null && tempPath.endsWith(".gif")) {
|
||||
isGif = true;
|
||||
documentPath = tempPath;
|
||||
} else if (tempPath == null) {
|
||||
isGif = MediaController.isGif(uri);
|
||||
if (isGif) {
|
||||
documentPath = MediaController.copyDocumentToCache(uri);
|
||||
}
|
||||
if (documentPath == null) {
|
||||
photoPath = (Uri) parcelable;
|
||||
}
|
||||
if (!isGif || documentPath == null) {
|
||||
photoPath = uri;
|
||||
}
|
||||
} else {
|
||||
photoPath = (Uri) parcelable;
|
||||
}
|
||||
} else {
|
||||
path = Utilities.getPath((Uri)parcelable);
|
||||
path = Utilities.getPath(uri);
|
||||
if (path != null) {
|
||||
if (path.startsWith("file:")) {
|
||||
path = path.replace("file://", "");
|
||||
|
@ -380,13 +383,24 @@ public class LaunchActivity extends ActionBarActivity implements NotificationCen
|
|||
if (!(parcelable instanceof Uri)) {
|
||||
parcelable = Uri.parse(parcelable.toString());
|
||||
}
|
||||
String tempPath = Utilities.getPath((Uri)parcelable);
|
||||
if (type.equals("image/gif") || tempPath != null && tempPath.endsWith(".gif")) {
|
||||
Uri uri = (Uri)parcelable;
|
||||
String tempPath = Utilities.getPath(uri);
|
||||
|
||||
boolean isGif = false;
|
||||
if (tempPath != null && tempPath.endsWith(".gif")) {
|
||||
isGif = true;
|
||||
} else if (tempPath == null) {
|
||||
isGif = MediaController.isGif(uri);
|
||||
if (isGif) {
|
||||
tempPath = MediaController.copyDocumentToCache(uri);
|
||||
}
|
||||
}
|
||||
if (isGif && tempPath != null) {
|
||||
if (documentsPathArray == null) {
|
||||
documentsPathArray = new ArrayList<String>();
|
||||
}
|
||||
try {
|
||||
documentsPathArray.add(Utilities.getPath((Uri) parcelable));
|
||||
documentsPathArray.add(tempPath);
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
|
@ -394,7 +408,7 @@ public class LaunchActivity extends ActionBarActivity implements NotificationCen
|
|||
if (imagesPathArray == null) {
|
||||
imagesPathArray = new ArrayList<Uri>();
|
||||
}
|
||||
imagesPathArray.add((Uri) parcelable);
|
||||
imagesPathArray.add(uri);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue