From 5bbfba2092139b41bdd80ba4bf7e89961cff7bd7 Mon Sep 17 00:00:00 2001 From: DrKLO Date: Fri, 17 Oct 2014 00:02:44 +0400 Subject: [PATCH] UI improvements --- TMessagesProj/build.gradle | 2 +- .../telegram/android/MessagesController.java | 16 +- .../org/telegram/android/MessagesStorage.java | 67 ++- .../telegram/android/SendMessagesHelper.java | 353 ++++++++++++- .../java/org/telegram/messenger/TLRPC.java | 2 + .../org/telegram/ui/Cells/ChatAudioCell.java | 33 +- .../org/telegram/ui/Cells/ChatBaseCell.java | 2 +- .../telegram/ui/Cells/ChatContactCell.java | 491 +++++++++--------- .../org/telegram/ui/Cells/ChatMediaCell.java | 6 +- .../java/org/telegram/ui/ChatActivity.java | 408 +++------------ .../java/org/telegram/ui/LaunchActivity.java | 8 +- .../org/telegram/ui/SettingsActivity.java | 2 +- .../ui/SettingsBlockedUsersActivity.java | 2 +- .../org/telegram/ui/UserProfileActivity.java | 2 +- .../chat_group_incoming_contact_layout.xml | 95 ---- .../layout/chat_incoming_contact_layout.xml | 87 ---- .../layout/chat_outgoing_contact_layout.xml | 117 ----- .../src/main/res/values-ar/strings.xml | 1 + .../src/main/res/values-de/strings.xml | 1 + .../src/main/res/values-es/strings.xml | 1 + .../src/main/res/values-it/strings.xml | 1 + .../src/main/res/values-ko/strings.xml | 1 + .../src/main/res/values-nl/strings.xml | 1 + .../src/main/res/values-pt-rBR/strings.xml | 1 + .../src/main/res/values-pt-rPT/strings.xml | 1 + TMessagesProj/src/main/res/values/strings.xml | 1 + 26 files changed, 777 insertions(+), 925 deletions(-) delete mode 100644 TMessagesProj/src/main/res/layout/chat_group_incoming_contact_layout.xml delete mode 100644 TMessagesProj/src/main/res/layout/chat_incoming_contact_layout.xml delete mode 100644 TMessagesProj/src/main/res/layout/chat_outgoing_contact_layout.xml diff --git a/TMessagesProj/build.gradle b/TMessagesProj/build.gradle index 7f216ab84..235ad19bf 100644 --- a/TMessagesProj/build.gradle +++ b/TMessagesProj/build.gradle @@ -80,7 +80,7 @@ android { defaultConfig { minSdkVersion 8 targetSdkVersion 19 - versionCode 357 + versionCode 358 versionName "1.9.5" } } diff --git a/TMessagesProj/src/main/java/org/telegram/android/MessagesController.java b/TMessagesProj/src/main/java/org/telegram/android/MessagesController.java index f11d4fc5f..b4e1a6f42 100644 --- a/TMessagesProj/src/main/java/org/telegram/android/MessagesController.java +++ b/TMessagesProj/src/main/java/org/telegram/android/MessagesController.java @@ -3551,7 +3551,15 @@ public class MessagesController implements NotificationCenter.NotificationCenter } if (object instanceof TLRPC.TL_decryptedMessageLayer) { - object = ((TLRPC.TL_decryptedMessageLayer) object).message; + final TLRPC.TL_decryptedMessageLayer layer = (TLRPC.TL_decryptedMessageLayer)object; + AndroidUtilities.RunOnUIThread(new Runnable() { + @Override + public void run() { + chat.seq_in = layer.out_seq_no; + MessagesStorage.getInstance().updateEncryptedChatSeq(chat); + } + }); + object = layer.message; } if (object instanceof TLRPC.TL_decryptedMessage) { @@ -3890,6 +3898,8 @@ public class MessagesController implements NotificationCenter.NotificationCenter salt[a] = (byte) ((byte) (Utilities.random.nextDouble() * 256) ^ res.random[a]); } encryptedChat.a_or_b = salt; + encryptedChat.seq_in = 1; + encryptedChat.seq_out = 0; BigInteger p = new BigInteger(1, MessagesStorage.secretPBytes); BigInteger g_b = BigInteger.valueOf(MessagesStorage.secretG); g_b = g_b.modPow(new BigInteger(1, salt), p); @@ -4033,8 +4043,10 @@ public class MessagesController implements NotificationCenter.NotificationCenter } TLRPC.EncryptedChat chat = (TLRPC.EncryptedChat) response; chat.user_id = chat.participant_id; - putEncryptedChat(chat, false); + chat.seq_in = 0; + chat.seq_out = 1; chat.a_or_b = salt; + putEncryptedChat(chat, false); TLRPC.TL_dialog dialog = new TLRPC.TL_dialog(); dialog.id = ((long) chat.id) << 32; dialog.unread_count = 0; diff --git a/TMessagesProj/src/main/java/org/telegram/android/MessagesStorage.java b/TMessagesProj/src/main/java/org/telegram/android/MessagesStorage.java index abbec5234..09dffff17 100644 --- a/TMessagesProj/src/main/java/org/telegram/android/MessagesStorage.java +++ b/TMessagesProj/src/main/java/org/telegram/android/MessagesStorage.java @@ -93,7 +93,7 @@ public class MessagesStorage { database.executeFast("CREATE TABLE users(uid INTEGER PRIMARY KEY, name TEXT, status INTEGER, data BLOB)").stepThis().dispose(); database.executeFast("CREATE TABLE messages(mid INTEGER PRIMARY KEY, uid INTEGER, read_state INTEGER, send_state INTEGER, date INTEGER, data BLOB, out INTEGER, ttl INTEGER, media INTEGER)").stepThis().dispose(); database.executeFast("CREATE TABLE chats(uid INTEGER PRIMARY KEY, name TEXT, data BLOB)").stepThis().dispose(); - database.executeFast("CREATE TABLE enc_chats(uid INTEGER PRIMARY KEY, user INTEGER, name TEXT, data BLOB, g BLOB, authkey BLOB, ttl INTEGER, layer INTEGER)").stepThis().dispose(); + database.executeFast("CREATE TABLE enc_chats(uid INTEGER PRIMARY KEY, user INTEGER, name TEXT, data BLOB, g BLOB, authkey BLOB, ttl INTEGER, layer INTEGER, seq_in INTEGER, seq_out INTEGER)").stepThis().dispose(); database.executeFast("CREATE TABLE dialogs(did INTEGER PRIMARY KEY, date INTEGER, unread_count INTEGER, last_mid INTEGER)").stepThis().dispose(); database.executeFast("CREATE TABLE chat_settings(uid INTEGER PRIMARY KEY, participants BLOB)").stepThis().dispose(); database.executeFast("CREATE TABLE contacts(uid INTEGER PRIMARY KEY, mutual INTEGER)").stepThis().dispose(); @@ -291,6 +291,8 @@ public class MessagesStorage { } if (version == 6 && version < 7) { database.executeFast("ALTER TABLE enc_chats ADD COLUMN layer INTEGER default 0").stepThis().dispose(); + database.executeFast("ALTER TABLE enc_chats ADD COLUMN seq_in INTEGER default 0").stepThis().dispose(); + database.executeFast("ALTER TABLE enc_chats ADD COLUMN seq_out INTEGER default 0").stepThis().dispose(); database.executeFast("PRAGMA user_version = 7").stepThis().dispose(); version = 7; } @@ -491,7 +493,7 @@ public class MessagesStorage { if (!encryptedChatIds.isEmpty()) { String stringToLoad = TextUtils.join(",", encryptedChatIds); - cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, user, g, authkey, ttl, layer FROM enc_chats WHERE uid IN(%s)", stringToLoad)); + cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, user, g, authkey, ttl, layer, seq_in, seq_out FROM enc_chats WHERE uid IN(%s)", stringToLoad)); while (cursor.next()) { ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0)); if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) { @@ -505,6 +507,8 @@ public class MessagesStorage { chat.auth_key = cursor.byteArrayValue(3); chat.ttl = cursor.intValue(4); chat.layer = cursor.intValue(5); + chat.seq_in = cursor.intValue(6); + chat.seq_out = cursor.intValue(7); } buffersStorage.reuseFreeBuffer(data); } @@ -1232,7 +1236,7 @@ public class MessagesStorage { cursor.dispose(); if (needEncrypted) { - cursor = database.queryFinalized("SELECT q.data, u.name, q.user, q.g, q.authkey, q.ttl, u.data, u.status, q.layer FROM enc_chats as q INNER JOIN dialogs as d ON (q.uid << 32) = d.did INNER JOIN users as u ON q.user = u.uid"); + cursor = database.queryFinalized("SELECT q.data, u.name, q.user, q.g, q.authkey, q.ttl, u.data, u.status, q.layer, q.seq_in, q.seq_out FROM enc_chats as q INNER JOIN dialogs as d ON (q.uid << 32) = d.did INNER JOIN users as u ON q.user = u.uid"); while (cursor.next()) { String name = cursor.stringValue(1); if (name.startsWith(q) || name.contains(" " + q)) { @@ -1245,6 +1249,8 @@ public class MessagesStorage { chat.auth_key = cursor.byteArrayValue(4); chat.ttl = cursor.intValue(5); chat.layer = cursor.intValue(8); + chat.seq_in = cursor.intValue(9); + chat.seq_out = cursor.intValue(10); TLRPC.User user = (TLRPC.User)TLClassStore.Instance().TLdeserialize(data2, data2.readInt32()); if (user.status != null) { @@ -1720,7 +1726,7 @@ public class MessagesStorage { if (!encryptedChatIds.isEmpty()) { String stringToLoad = TextUtils.join(",", encryptedChatIds); - cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, user, g, authkey, ttl, layer FROM enc_chats WHERE uid IN(%s)", stringToLoad)); + cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, user, g, authkey, ttl, layer, seq_in, seq_out FROM enc_chats WHERE uid IN(%s)", stringToLoad)); while (cursor.next()) { ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0)); if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) { @@ -1734,6 +1740,8 @@ public class MessagesStorage { chat.auth_key = cursor.byteArrayValue(3); chat.ttl = cursor.intValue(4); chat.layer = cursor.intValue(5); + chat.seq_in = cursor.intValue(6); + chat.seq_out = cursor.intValue(7); } buffersStorage.reuseFreeBuffer(data); } @@ -2126,6 +2134,31 @@ public class MessagesStorage { }); } + public void updateEncryptedChatSeq(final TLRPC.EncryptedChat chat) { + if (chat == null) { + return; + } + storageQueue.postRunnable(new Runnable() { + @Override + public void run() { + SQLitePreparedStatement state = null; + try { + state = database.executeFast("UPDATE enc_chats SET seq_in = ?, seq_out = ? WHERE uid = ?"); + state.bindInteger(1, chat.seq_in); + state.bindInteger(2, chat.seq_out); + state.bindInteger(3, chat.id); + state.step(); + } catch (Exception e) { + FileLog.e("tmessages", e); + } finally { + if (state != null) { + state.dispose(); + } + } + } + }); + } + public void updateEncryptedChatTTL(final TLRPC.EncryptedChat chat) { if (chat == null) { return; @@ -2183,7 +2216,7 @@ public class MessagesStorage { public void run() { SQLitePreparedStatement state = null; try { - state = database.executeFast("UPDATE enc_chats SET data = ?, g = ?, authkey = ?, ttl = ?, layer = ? WHERE uid = ?"); + state = database.executeFast("UPDATE enc_chats SET data = ?, g = ?, authkey = ?, ttl = ?, layer = ?, seq_in = ?, seq_out = ? WHERE uid = ?"); ByteBufferDesc data = buffersStorage.getFreeBuffer(chat.getObjectSize()); ByteBufferDesc data2 = buffersStorage.getFreeBuffer(chat.a_or_b != null ? chat.a_or_b.length : 1); ByteBufferDesc data3 = buffersStorage.getFreeBuffer(chat.auth_key != null ? chat.auth_key.length : 1); @@ -2199,7 +2232,9 @@ public class MessagesStorage { state.bindByteBuffer(3, data3.buffer); state.bindInteger(4, chat.ttl); state.bindInteger(5, chat.layer); - state.bindInteger(6, chat.id); + state.bindInteger(6, chat.seq_in); + state.bindInteger(7, chat.seq_out); + state.bindInteger(8, chat.id); state.step(); buffersStorage.reuseFreeBuffer(data); buffersStorage.reuseFreeBuffer(data2); @@ -2224,7 +2259,7 @@ public class MessagesStorage { public void run() { try { int userToLoad = 0; - SQLiteCursor cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, user, g, authkey, ttl, layer FROM enc_chats WHERE uid = %d", chat_id)); + SQLiteCursor cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, user, g, authkey, ttl, layer, seq_in, seq_out FROM enc_chats WHERE uid = %d", chat_id)); if (cursor.next()) { ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0)); if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) { @@ -2236,6 +2271,8 @@ public class MessagesStorage { chat.auth_key = cursor.byteArrayValue(3); chat.ttl = cursor.intValue(4); chat.layer = cursor.intValue(5); + chat.seq_in = cursor.intValue(6); + chat.seq_out = cursor.intValue(7); } buffersStorage.reuseFreeBuffer(data); } @@ -2276,7 +2313,7 @@ public class MessagesStorage { @Override public void run() { try { - SQLitePreparedStatement state = database.executeFast("REPLACE INTO enc_chats VALUES(?, ?, ?, ?, ?, ?, ?, ?)"); + SQLitePreparedStatement state = database.executeFast("REPLACE INTO enc_chats VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); ByteBufferDesc data = buffersStorage.getFreeBuffer(chat.getObjectSize()); ByteBufferDesc data2 = buffersStorage.getFreeBuffer(chat.a_or_b != null ? chat.a_or_b.length : 1); ByteBufferDesc data3 = buffersStorage.getFreeBuffer(chat.auth_key != null ? chat.auth_key.length : 1); @@ -2301,6 +2338,8 @@ public class MessagesStorage { state.bindByteBuffer(6, data3.buffer); state.bindInteger(7, chat.ttl); state.bindInteger(8, chat.layer); + state.bindInteger(9, chat.seq_in); + state.bindInteger(10, chat.seq_out); state.step(); state.dispose(); buffersStorage.reuseFreeBuffer(data); @@ -3160,7 +3199,7 @@ public class MessagesStorage { if (!encryptedToLoad.isEmpty()) { String toLoad = TextUtils.join(",", encryptedToLoad); - cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, user, g, authkey, ttl, layer FROM enc_chats WHERE uid IN(%s)", toLoad)); + cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, user, g, authkey, ttl, layer, seq_in, seq_out FROM enc_chats WHERE uid IN(%s)", toLoad)); while (cursor.next()) { ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0)); if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) { @@ -3174,6 +3213,8 @@ public class MessagesStorage { chat.auth_key = cursor.byteArrayValue(3); chat.ttl = cursor.intValue(4); chat.layer = cursor.intValue(5); + chat.seq_in = cursor.intValue(6); + chat.seq_out = cursor.intValue(7); } buffersStorage.reuseFreeBuffer(data); } @@ -3417,7 +3458,7 @@ public class MessagesStorage { if (!encryptedToLoad.isEmpty()) { String toLoad = TextUtils.join(",", encryptedToLoad); - cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, user, g, authkey, ttl, layer FROM enc_chats WHERE uid IN(%s)", toLoad)); + cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, user, g, authkey, ttl, layer, seq_in, seq_out FROM enc_chats WHERE uid IN(%s)", toLoad)); while (cursor.next()) { try { ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0)); @@ -3433,6 +3474,8 @@ public class MessagesStorage { chat.auth_key = cursor.byteArrayValue(3); chat.ttl = cursor.intValue(4); chat.layer = cursor.intValue(5); + chat.seq_in = cursor.intValue(6); + chat.seq_out = cursor.intValue(7); } } buffersStorage.reuseFreeBuffer(data); @@ -3706,7 +3749,7 @@ public class MessagesStorage { public TLRPC.EncryptedChat getEncryptedChat(final int chat_id) { TLRPC.EncryptedChat chat = null; try { - SQLiteCursor cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, user, g, authkey, ttl, layer FROM enc_chats WHERE uid = %d", chat_id)); + SQLiteCursor cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, user, g, authkey, ttl, layer, seq_in, seq_out FROM enc_chats WHERE uid = %d", chat_id)); if (cursor.next()) { ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0)); if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) { @@ -3717,6 +3760,8 @@ public class MessagesStorage { chat.auth_key = cursor.byteArrayValue(3); chat.ttl = cursor.intValue(4); chat.layer = cursor.intValue(5); + chat.seq_in = cursor.intValue(6); + chat.seq_out = cursor.intValue(7); } } buffersStorage.reuseFreeBuffer(data); diff --git a/TMessagesProj/src/main/java/org/telegram/android/SendMessagesHelper.java b/TMessagesProj/src/main/java/org/telegram/android/SendMessagesHelper.java index b98618c52..d37614a02 100644 --- a/TMessagesProj/src/main/java/org/telegram/android/SendMessagesHelper.java +++ b/TMessagesProj/src/main/java/org/telegram/android/SendMessagesHelper.java @@ -9,7 +9,13 @@ package org.telegram.android; import android.graphics.Bitmap; +import android.media.MediaMetadataRetriever; +import android.media.MediaPlayer; +import android.media.ThumbnailUtils; import android.net.Uri; +import android.os.Build; +import android.provider.MediaStore; +import android.webkit.MimeTypeMap; import org.telegram.messenger.BuffersStorage; import org.telegram.messenger.ByteBufferDesc; @@ -22,6 +28,7 @@ import org.telegram.messenger.TLObject; import org.telegram.messenger.TLRPC; import org.telegram.messenger.UserConfig; import org.telegram.messenger.Utilities; +import org.telegram.ui.ApplicationLoader; import java.io.File; import java.util.ArrayList; @@ -616,10 +623,16 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter performSendMessageRequest(reqSend, newMsgObj, null); } } else { - TLRPC.TL_decryptedMessage_old reqSend = new TLRPC.TL_decryptedMessage_old(); + TLRPC.TL_decryptedMessage reqSend; + if (AndroidUtilities.getPeerLayerVersion(encryptedChat.layer) >= 17) { + reqSend = new TLRPC.TL_decryptedMessage(); + reqSend.ttl = encryptedChat.ttl; + } else { + reqSend = new TLRPC.TL_decryptedMessage_old(); + reqSend.random_bytes = new byte[Math.max(1, (int) Math.ceil(Utilities.random.nextDouble() * 16))]; + Utilities.random.nextBytes(reqSend.random_bytes); + } reqSend.random_id = newMsg.random_id; - reqSend.random_bytes = new byte[Math.max(1, (int) Math.ceil(Utilities.random.nextDouble() * 16))]; - Utilities.random.nextBytes(reqSend.random_bytes); reqSend.message = message; reqSend.media = new TLRPC.TL_decryptedMessageMediaEmpty(); performSendEncryptedRequest(reqSend, newMsgObj, encryptedChat, null, null, null); @@ -768,10 +781,16 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter } } } else { - TLRPC.TL_decryptedMessage_old reqSend = new TLRPC.TL_decryptedMessage_old(); + TLRPC.TL_decryptedMessage reqSend; + if (AndroidUtilities.getPeerLayerVersion(encryptedChat.layer) >= 17) { + reqSend = new TLRPC.TL_decryptedMessage(); + reqSend.ttl = encryptedChat.ttl; + } else { + reqSend = new TLRPC.TL_decryptedMessage_old(); + reqSend.random_bytes = new byte[Math.max(1, (int) Math.ceil(Utilities.random.nextDouble() * 16))]; + Utilities.random.nextBytes(reqSend.random_bytes); + } reqSend.random_id = newMsg.random_id; - reqSend.random_bytes = new byte[Math.max(1, (int) Math.ceil(Utilities.random.nextDouble() * 16))]; - Utilities.random.nextBytes(reqSend.random_bytes); reqSend.message = ""; if (type == 1) { reqSend.media = new TLRPC.TL_decryptedMessageMediaGeoPoint(); @@ -1124,12 +1143,15 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter if (AndroidUtilities.getPeerLayerVersion(chat.layer) >= 17) { TLRPC.TL_decryptedMessageLayer layer = new TLRPC.TL_decryptedMessageLayer(); layer.layer = CURRENT_SECRET_CHAT_LAYER; - layer.in_seq_no = 0; //TODO - layer.out_seq_no = 0; + layer.in_seq_no = chat.seq_in; + layer.out_seq_no = chat.seq_out; layer.message = req; layer.random_bytes = new byte[Math.max(1, (int) Math.ceil(Utilities.random.nextDouble() * 16))]; Utilities.random.nextBytes(layer.random_bytes); toEncryptObject = layer; + + chat.seq_out += 2; + MessagesStorage.getInstance().updateEncryptedChatSeq(chat); } else { toEncryptObject = req; } @@ -1715,4 +1737,319 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter return photo; } } + + private static void prepareSendingDocumentInternal(final String path, String originalPath, final long dialog_id) { + if (path == null || path.length() == 0) { + return; + } + final File f = new File(path); + if (!f.exists() || f.length() == 0) { + return; + } + + boolean isEncrypted = (int)dialog_id == 0; + + String name = f.getName(); + if (name == null) { + name = "noname"; + } + String ext = ""; + int idx = path.lastIndexOf("."); + if (idx != -1) { + ext = path.substring(idx + 1); + } + if (originalPath != null) { + originalPath += "" + f.length(); + } + + TLRPC.TL_document document = (TLRPC.TL_document)MessagesStorage.getInstance().getSentFile(originalPath, !isEncrypted ? 1 : 4); + if (document == null && !path.equals(originalPath)) { + document = (TLRPC.TL_document)MessagesStorage.getInstance().getSentFile(path + f.length(), !isEncrypted ? 1 : 4); + } + if (document == null) { + document = new TLRPC.TL_document(); + document.id = 0; + document.user_id = UserConfig.getClientUserId(); + document.date = ConnectionsManager.getInstance().getCurrentTime(); + document.file_name = name; + document.size = (int)f.length(); + document.dc_id = 0; + if (ext.length() != 0) { + MimeTypeMap myMime = MimeTypeMap.getSingleton(); + String mimeType = myMime.getMimeTypeFromExtension(ext.toLowerCase()); + if (mimeType != null) { + document.mime_type = mimeType; + } else { + document.mime_type = "application/octet-stream"; + } + } else { + document.mime_type = "application/octet-stream"; + } + if (document.mime_type.equals("image/gif")) { + try { + Bitmap bitmap = ImageLoader.loadBitmap(f.getAbsolutePath(), null, 90, 90); + if (bitmap != null) { + document.thumb = ImageLoader.scaleAndSaveImage(bitmap, 90, 90, 55, isEncrypted); + } + } catch (Exception e) { + FileLog.e("tmessages", e); + } + } + if (document.thumb == null) { + document.thumb = new TLRPC.TL_photoSizeEmpty(); + document.thumb.type = "s"; + } + } + + final TLRPC.TL_document documentFinal = document; + final String originalPathFinal = originalPath; + AndroidUtilities.RunOnUIThread(new Runnable() { + @Override + public void run() { + SendMessagesHelper.getInstance().sendMessage(documentFinal, originalPathFinal, path, dialog_id); + } + }); + } + + public static void prepareSendingDocument(String path, String originalPath, long dialog_id) { + if (path == null || originalPath == null) { + return; + } + ArrayList paths = new ArrayList(); + ArrayList originalPaths = new ArrayList(); + paths.add(path); + originalPaths.add(originalPath); + prepareSendingDocuments(paths, originalPaths, dialog_id); + } + + public static void prepareSendingDocuments(final ArrayList paths, final ArrayList originalPaths, final long dialog_id) { + if (paths == null && originalPaths == null || paths != null && originalPaths != null && paths.size() != originalPaths.size()) { + return; + } + new Thread(new Runnable() { + @Override + public void run() { + for (int a = 0; a < paths.size(); a++) { + prepareSendingDocumentInternal(paths.get(a), originalPaths.get(a), dialog_id); + } + } + }).start(); + } + + public static void prepareSendingPhoto(String imageFilePath, Uri imageUri, long dialog_id) { + ArrayList paths = null; + ArrayList uris = null; + if (imageFilePath != null && imageFilePath.length() != 0) { + paths = new ArrayList(); + paths.add(imageFilePath); + } + if (imageUri != null) { + uris = new ArrayList(); + uris.add(imageUri); + } + prepareSendingPhotos(paths, uris, dialog_id); + } + + public static void prepareSendingPhotos(ArrayList paths, ArrayList uris, final long dialog_id) { + if (paths == null && uris == null || paths != null && paths.isEmpty() || uris != null && uris.isEmpty()) { + return; + } + final ArrayList pathsCopy = new ArrayList(); + final ArrayList urisCopy = new ArrayList(); + if (paths != null) { + pathsCopy.addAll(paths); + } + if (uris != null) { + urisCopy.addAll(uris); + } + new Thread(new Runnable() { + @Override + public void run() { + boolean isEncrypted = (int)dialog_id == 0; + + ArrayList sendAsDocuments = null; + ArrayList sendAsDocumentsOriginal = null; + int count = !pathsCopy.isEmpty() ? pathsCopy.size() : urisCopy.size(); + String path = null; + Uri uri = null; + for (int a = 0; a < count; a++) { + if (!pathsCopy.isEmpty()) { + path = pathsCopy.get(a); + } else if (!urisCopy.isEmpty()) { + uri = urisCopy.get(a); + } + + String originalPath = path; + String tempPath = path; + if (tempPath == null && uri != null) { + tempPath = Utilities.getPath(uri); + originalPath = uri.toString(); + } + + boolean isGif = false; + if (tempPath != null && tempPath.endsWith(".gif")) { + isGif = true; + } else if (tempPath == null && uri != null) { + isGif = MediaController.isGif(uri); + if (isGif) { + originalPath = uri.toString(); + tempPath = MediaController.copyDocumentToCache(uri, "gif"); + } + } + + if (isGif) { + if (sendAsDocuments == null) { + sendAsDocuments = new ArrayList(); + sendAsDocumentsOriginal = new ArrayList(); + } + sendAsDocuments.add(tempPath); + sendAsDocumentsOriginal.add(originalPath); + } else { + if (tempPath != null) { + File temp = new File(tempPath); + originalPath += temp.length() + "_" + temp.lastModified(); + } else { + originalPath = null; + } + TLRPC.TL_photo photo = (TLRPC.TL_photo)MessagesStorage.getInstance().getSentFile(originalPath, !isEncrypted ? 0 : 3); + if (photo == null && uri != null) { + photo = (TLRPC.TL_photo)MessagesStorage.getInstance().getSentFile(Utilities.getPath(uri), !isEncrypted ? 0 : 3); + } + if (photo == null) { + photo = SendMessagesHelper.getInstance().generatePhotoSizes(path, uri); + } + if (photo != null) { + final String originalPathFinal = originalPath; + final TLRPC.TL_photo photoFinal = photo; + AndroidUtilities.RunOnUIThread(new Runnable() { + @Override + public void run() { + SendMessagesHelper.getInstance().sendMessage(photoFinal, originalPathFinal, dialog_id); + } + }); + } + } + } + if (sendAsDocuments != null && !sendAsDocuments.isEmpty()) { + for (int a = 0; a < sendAsDocuments.size(); a++) { + prepareSendingDocumentInternal(sendAsDocuments.get(a), sendAsDocumentsOriginal.get(a), dialog_id); + } + } + } + }).start(); + } + + public static void prepareSendingVideo(final String videoPath, final long estimatedSize, final long duration, final int width, final int height, final TLRPC.VideoEditedInfo videoEditedInfo, final long dialog_id) { + if (videoPath == null || videoPath.length() == 0) { + return; + } + new Thread(new Runnable() { + @Override + public void run() { + boolean isEncrypted = (int)dialog_id == 0; + + String path = videoPath; + String originalPath = videoPath; + File temp = new File(originalPath); + originalPath += temp.length() + "_" + temp.lastModified(); + if (videoEditedInfo != null) { + originalPath += duration + "_" + videoEditedInfo.startTime + "_" + videoEditedInfo.endTime; + } + TLRPC.TL_video video = (TLRPC.TL_video)MessagesStorage.getInstance().getSentFile(originalPath, !isEncrypted ? 2 : 5); + if (video == null) { + Bitmap thumb = ThumbnailUtils.createVideoThumbnail(videoPath, MediaStore.Video.Thumbnails.MINI_KIND); + TLRPC.PhotoSize size = ImageLoader.scaleAndSaveImage(thumb, 90, 90, 55, isEncrypted); + video = new TLRPC.TL_video(); + video.thumb = size; + if (video.thumb == null) { + video.thumb = new TLRPC.TL_photoSizeEmpty(); + video.thumb.type = "s"; + } else { + video.thumb.type = "s"; + } + video.caption = ""; + video.mime_type = "video/mp4"; + video.id = 0; + UserConfig.saveConfig(false); + + if (videoEditedInfo != null) { + video.duration = (int)(duration / 1000); + if (videoEditedInfo.rotationValue == 90 || videoEditedInfo.rotationValue == 270) { + video.w = height; + video.h = width; + } else { + video.w = width; + video.h = height; + } + video.size = (int)estimatedSize; + video.videoEditedInfo = videoEditedInfo; + String fileName = Integer.MIN_VALUE + "_" + UserConfig.lastLocalId + ".mp4"; + UserConfig.lastLocalId--; + File cacheFile = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName); + UserConfig.saveConfig(false); + path = cacheFile.getAbsolutePath(); + } else { + if (temp != null && temp.exists()) { + video.size = (int) temp.length(); + } + boolean infoObtained = false; + if (Build.VERSION.SDK_INT >= 14) { + MediaMetadataRetriever mediaMetadataRetriever = null; + try { + mediaMetadataRetriever = new MediaMetadataRetriever(); + mediaMetadataRetriever.setDataSource(videoPath); + String width = mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH); + if (width != null) { + video.w = Integer.parseInt(width); + } + String height = mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT); + if (height != null) { + video.h = Integer.parseInt(height); + } + String duration = mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION); + if (duration != null) { + video.duration = (int) Math.ceil(Long.parseLong(duration) / 1000.0f); + } + infoObtained = true; + } catch (Exception e) { + FileLog.e("tmessages", e); + } finally { + try { + if (mediaMetadataRetriever != null) { + mediaMetadataRetriever.release(); + mediaMetadataRetriever = null; + } + } catch (Exception e) { + FileLog.e("tmessages", e); + } + } + } + if (!infoObtained) { + try { + MediaPlayer mp = MediaPlayer.create(ApplicationLoader.applicationContext, Uri.fromFile(new File(videoPath))); + if (mp != null) { + video.duration = (int) Math.ceil(mp.getDuration() / 1000.0f); + video.w = mp.getVideoWidth(); + video.h = mp.getVideoHeight(); + mp.release(); + } + } catch (Exception e) { + FileLog.e("tmessages", e); + } + } + } + } + + final TLRPC.TL_video videoFinal = video; + final String originalPathFinal = originalPath; + final String finalPath = path; + AndroidUtilities.RunOnUIThread(new Runnable() { + @Override + public void run() { + SendMessagesHelper.getInstance().sendMessage(videoFinal, originalPathFinal, finalPath, dialog_id); + } + }); + } + }).start(); + } } diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/TLRPC.java b/TMessagesProj/src/main/java/org/telegram/messenger/TLRPC.java index 1de7d7df0..f985df2ce 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/TLRPC.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/TLRPC.java @@ -9330,6 +9330,8 @@ public class TLRPC { public int user_id; public int ttl; public int layer; + public int seq_in; + public int seq_out; } public static class FileLocation extends TLObject { diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatAudioCell.java b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatAudioCell.java index febf68909..b6041c688 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatAudioCell.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatAudioCell.java @@ -44,9 +44,9 @@ public class ChatAudioCell extends ChatBaseCell implements SeekBar.SeekBarDelega private int buttonState = 0; private int buttonX; private int buttonY; - private int buttonPressed = 0; + private boolean buttonPressed = false; - private int avatarPressed = 0; + private boolean avatarPressed = false; private StaticLayout timeLayout; private int timeX; @@ -56,7 +56,6 @@ public class ChatAudioCell extends ChatBaseCell implements SeekBar.SeekBarDelega public TLRPC.User audioUser; private TLRPC.FileLocation currentPhoto; - private String currentNameString; public ChatAudioCell(Context context) { super(context); @@ -115,40 +114,40 @@ public class ChatAudioCell extends ChatBaseCell implements SeekBar.SeekBarDelega int side = AndroidUtilities.dp(36); if (event.getAction() == MotionEvent.ACTION_DOWN) { if (x >= buttonX && x <= buttonX + side && y >= buttonY && y <= buttonY + side) { - buttonPressed = 1; + buttonPressed = true; invalidate(); result = true; } else if (avatarImage.isInsideImage(x, y)) { - avatarPressed = 1; + avatarPressed = true; result = true; } - } else if (buttonPressed == 1) { + } else if (buttonPressed) { if (event.getAction() == MotionEvent.ACTION_UP) { - buttonPressed = 0; + buttonPressed = false; playSoundEffect(SoundEffectConstants.CLICK); didPressedButton(); invalidate(); } else if (event.getAction() == MotionEvent.ACTION_CANCEL) { - buttonPressed = 0; + buttonPressed = false; invalidate(); } else if (event.getAction() == MotionEvent.ACTION_MOVE) { if (!(x >= buttonX && x <= buttonX + side && y >= buttonY && y <= buttonY + side)) { - buttonPressed = 0; + buttonPressed = false; invalidate(); } } - } else if (avatarPressed == 1) { + } else if (avatarPressed) { if (event.getAction() == MotionEvent.ACTION_UP) { - avatarPressed = 0; + avatarPressed = false; playSoundEffect(SoundEffectConstants.CLICK); if (delegate != null) { delegate.didPressedUserAvatar(this, audioUser); } } else if (event.getAction() == MotionEvent.ACTION_CANCEL) { - avatarPressed = 0; + avatarPressed = false; } else if (event.getAction() == MotionEvent.ACTION_MOVE) { if (!avatarImage.isInsideImage(x, y)) { - avatarPressed = 0; + avatarPressed = false; } } } @@ -301,7 +300,7 @@ public class ChatAudioCell extends ChatBaseCell implements SeekBar.SeekBarDelega int x; if (currentMessageObject.isOut()) { - x = layoutWidth - backgroundWidth + AndroidUtilities.dp(9); + x = layoutWidth - backgroundWidth + AndroidUtilities.dp(8); seekBarX = layoutWidth - backgroundWidth + AndroidUtilities.dp(97); buttonX = layoutWidth - backgroundWidth + AndroidUtilities.dp(67); timeX = layoutWidth - backgroundWidth + AndroidUtilities.dp(71); @@ -356,7 +355,7 @@ public class ChatAudioCell extends ChatBaseCell implements SeekBar.SeekBarDelega } avatarImage.setImage(currentPhoto, "50_50", getResources().getDrawable(AndroidUtilities.getUserAvatarForId(uid)), false); } else { - avatarImage.setImage((TLRPC.FileLocation)null, "50_50", getResources().getDrawable(AndroidUtilities.getUserAvatarForId(uid)), false); + avatarImage.setImage(null, "50_50", getResources().getDrawable(AndroidUtilities.getUserAvatarForId(uid)), false); } if (messageObject.isOut()) { @@ -380,7 +379,7 @@ public class ChatAudioCell extends ChatBaseCell implements SeekBar.SeekBarDelega return; } - avatarImage.draw(canvas, avatarImage.getImageX(), avatarImage.getImageY(), AndroidUtilities.dp(50), AndroidUtilities.dp(50)); + avatarImage.draw(canvas, avatarImage.getImageX(), avatarImage.getImageY(), avatarImage.getImageHeight(), avatarImage.getImageHeight()); canvas.save(); if (buttonState == 0 || buttonState == 1) { @@ -399,7 +398,7 @@ public class ChatAudioCell extends ChatBaseCell implements SeekBar.SeekBarDelega } else { timePaint.setColor(0xff70b15c); } - Drawable buttonDrawable = statesDrawable[state][buttonPressed]; + Drawable buttonDrawable = statesDrawable[state][buttonPressed ? 1 : 0]; int side = AndroidUtilities.dp(36); int x = (side - buttonDrawable.getIntrinsicWidth()) / 2; int y = (side - buttonDrawable.getIntrinsicHeight()) / 2; diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatBaseCell.java b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatBaseCell.java index e3e55f582..ebc90b2ce 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatBaseCell.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatBaseCell.java @@ -94,7 +94,7 @@ public class ChatBaseCell extends BaseCell { private StaticLayout timeLayout; protected int timeWidth; - protected int timeX; + private int timeX; private TextPaint currentTimePaint; private String currentTimeString; protected boolean drawTime = true; diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatContactCell.java b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatContactCell.java index 19d7da810..7b0f14d2d 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatContactCell.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatContactCell.java @@ -9,263 +9,280 @@ package org.telegram.ui.Cells; import android.content.Context; +import android.graphics.Canvas; +import android.graphics.Paint; +import android.graphics.drawable.Drawable; +import android.text.Layout; +import android.text.StaticLayout; +import android.text.TextPaint; +import android.text.TextUtils; +import android.view.MotionEvent; +import android.view.SoundEffectConstants; + +import org.telegram.PhoneFormat.PhoneFormat; +import org.telegram.android.AndroidUtilities; +import org.telegram.android.ContactsController; +import org.telegram.android.ImageReceiver; +import org.telegram.android.LocaleController; +import org.telegram.android.MessageObject; +import org.telegram.android.MessagesController; +import org.telegram.messenger.R; +import org.telegram.messenger.TLRPC; +import org.telegram.messenger.UserConfig; public class ChatContactCell extends ChatBaseCell { + public static interface ChatContactCellDelegate { + public abstract void didClickAddButton(ChatContactCell cell, TLRPC.User user); + public abstract void didClickPhone(ChatContactCell cell); + } + + private static TextPaint namePaint; + private static TextPaint phonePaint; + private static Drawable addContactDrawable; + private static Paint linePaint; + + private ImageReceiver avatarImage; + + private StaticLayout nameLayout; + private StaticLayout phoneLayout; + + private TLRPC.User contactUser; + private TLRPC.FileLocation currentPhoto; + + private boolean avatarPressed = false; + private boolean buttonPressed = false; + private boolean drawAddButton = false; + private int namesWidth = 0; + + private ChatContactCellDelegate contactDelegate = null; + public ChatContactCell(Context context) { super(context); + if (namePaint == null) { + namePaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG); + namePaint.setTextSize(AndroidUtilities.dp(15)); + + phonePaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG); + phonePaint.setTextSize(AndroidUtilities.dp(15)); + phonePaint.setColor(0xff000000); + + addContactDrawable = getResources().getDrawable(R.drawable.ic_ab_add_member); + + linePaint = new Paint(); + linePaint.setStrokeWidth(AndroidUtilities.dp(1)); + } + avatarImage = new ImageReceiver(this); } - /* - public class ChatListRowHolderEx { - public BackupImageView avatarImageView; - public TextView nameTextView; - public TextView messageTextView; - public TextView timeTextView; - public ImageView halfCheckImage; - public ImageView checkImage; - public MessageObject message; - public TextView phoneTextView; - public BackupImageView contactAvatar; - public View contactView; - public ImageView addContactButton; - public View addContactView; - public View chatBubbleView; + public void setContactDelegate(ChatContactCellDelegate delegate) { + this.contactDelegate = delegate; + } - public void update() { - TLRPC.User fromUser = MessagesController.getInstance().getUser(message.messageOwner.from_id); + @Override + protected boolean isUserDataChanged() { + if (currentMessageObject == null) { + return false; + } - int type = message.type; + contactUser = MessagesController.getInstance().getUser(currentMessageObject.messageOwner.media.user_id); - if (timeTextView != null) { - timeTextView.setText(LocaleController.formatterDay.format((long) (message.messageOwner.date) * 1000)); + TLRPC.FileLocation newPhoto = null; + if (contactUser != null && contactUser.photo != null) { + newPhoto = contactUser.photo.photo_small; + } + + return currentPhoto == null && newPhoto != null || currentPhoto != null && newPhoto == null || currentPhoto != null && newPhoto != null && (currentPhoto.local_id != newPhoto.local_id || currentPhoto.volume_id != newPhoto.volume_id) || super.isUserDataChanged(); + } + + @Override + public boolean onTouchEvent(MotionEvent event) { + float x = event.getX(); + float y = event.getY(); + + boolean result = false; + int side = AndroidUtilities.dp(36); + if (event.getAction() == MotionEvent.ACTION_DOWN) { + if (x >= avatarImage.getImageX() && x <= avatarImage.getImageX() + namesWidth && y >= avatarImage.getImageY() && y <= avatarImage.getImageY() + avatarImage.getImageHeight()) { + avatarPressed = true; + result = true; + } else if (x >= avatarImage.getImageX() - AndroidUtilities.dp(44) && y >= AndroidUtilities.dp(20) && x <= avatarImage.getImageX() - AndroidUtilities.dp(10) && y <= AndroidUtilities.dp(52)) { + buttonPressed = true; + result = true; } - - if (avatarImageView != null && fromUser != null) { - TLRPC.FileLocation photo = null; - if (fromUser.photo != null) { - photo = fromUser.photo.photo_small; + if (result) { + startCheckLongPress(); + } + } else { + if (event.getAction() != MotionEvent.ACTION_MOVE) { + cancelCheckLongPress(); + } + if (avatarPressed) { + if (event.getAction() == MotionEvent.ACTION_UP) { + avatarPressed = false; + playSoundEffect(SoundEffectConstants.CLICK); + if (contactUser != null) { + if (delegate != null) { + delegate.didPressedUserAvatar(this, contactUser); + } + } else { + if (contactDelegate != null) { + contactDelegate.didClickPhone(this); + } + } + } else if (event.getAction() == MotionEvent.ACTION_CANCEL) { + avatarPressed = false; + } else if (event.getAction() == MotionEvent.ACTION_MOVE) { + if (!avatarImage.isInsideImage(x, y)) { + avatarPressed = false; + } } - int placeHolderId = AndroidUtilities.getUserAvatarForId(fromUser.id); - avatarImageView.setImage(photo, "50_50", placeHolderId); - } - - if (type != 12 && type != 13 && nameTextView != null && fromUser != null && type != 8 && type != 9) { - nameTextView.setText(ContactsController.formatName(fromUser.first_name, fromUser.last_name)); - nameTextView.setTextColor(AndroidUtilities.getColorForId(message.messageOwner.from_id)); - } - - if (type == 12 || type == 13) { - TLRPC.User contactUser = MessagesController.getInstance().getUser(message.messageOwner.media.user_id); - if (contactUser != null) { - nameTextView.setText(ContactsController.formatName(message.messageOwner.media.first_name, message.messageOwner.media.last_name)); - nameTextView.setTextColor(AndroidUtilities.getColorForId(contactUser.id)); - String phone = message.messageOwner.media.phone_number; - if (phone != null && phone.length() != 0) { - if (!phone.startsWith("+")) { - phone = "+" + phone; - } - phoneTextView.setText(PhoneFormat.getInstance().format(phone)); - } else { - phoneTextView.setText("Unknown"); + } else if (buttonPressed) { + if (event.getAction() == MotionEvent.ACTION_UP) { + buttonPressed = false; + playSoundEffect(SoundEffectConstants.CLICK); + if (contactUser != null && contactDelegate != null) { + contactDelegate.didClickAddButton(this, contactUser); } - TLRPC.FileLocation photo = null; - if (contactUser.photo != null) { - photo = contactUser.photo.photo_small; - } - int placeHolderId = AndroidUtilities.getUserAvatarForId(contactUser.id); - contactAvatar.setImage(photo, "50_50", placeHolderId); - if (contactUser.id != UserConfig.getClientUserId() && ContactsController.getInstance().contactsDict.get(contactUser.id) == null) { - addContactView.setVisibility(View.VISIBLE); - } else { - addContactView.setVisibility(View.GONE); - } - } else { - nameTextView.setText(ContactsController.formatName(message.messageOwner.media.first_name, message.messageOwner.media.last_name)); - nameTextView.setTextColor(AndroidUtilities.getColorForId(message.messageOwner.media.user_id)); - String phone = message.messageOwner.media.phone_number; - if (phone != null && phone.length() != 0) { - if (message.messageOwner.media.user_id != 0 && !phone.startsWith("+")) { - phone = "+" + phone; - } - phoneTextView.setText(PhoneFormat.getInstance().format(phone)); - } else { - phoneTextView.setText("Unknown"); - } - contactAvatar.setImageResource(AndroidUtilities.getUserAvatarForId(message.messageOwner.media.user_id)); - addContactView.setVisibility(View.GONE); - } - } else if (type == 6) { - messageTextView.setTextSize(16); - messageTextView.setText(LocaleController.formatPluralString("NewMessages", unread_to_load)); - } - - if (message.isFromMe()) { - if (halfCheckImage != null) { - if (message.isSending()) { - checkImage.setVisibility(View.INVISIBLE); - halfCheckImage.setImageResource(R.drawable.msg_clock); - halfCheckImage.setVisibility(View.VISIBLE); - } else if (message.isSendError()) { - halfCheckImage.setVisibility(View.VISIBLE); - halfCheckImage.setImageResource(R.drawable.msg_warning); - if (checkImage != null) { - checkImage.setVisibility(View.INVISIBLE); - } - } else if (message.isSent()) { - if (!message.isUnread()) { - halfCheckImage.setVisibility(View.VISIBLE); - checkImage.setVisibility(View.VISIBLE); - halfCheckImage.setImageResource(R.drawable.msg_halfcheck); - } else { - halfCheckImage.setVisibility(View.VISIBLE); - checkImage.setVisibility(View.INVISIBLE); - halfCheckImage.setImageResource(R.drawable.msg_check); - } + } else if (event.getAction() == MotionEvent.ACTION_CANCEL) { + buttonPressed = false; + } else if (event.getAction() == MotionEvent.ACTION_MOVE) { + if (!(x >= avatarImage.getImageX() - AndroidUtilities.dp(44) && y >= AndroidUtilities.dp(20) && x <= avatarImage.getImageX() - AndroidUtilities.dp(10) && y <= AndroidUtilities.dp(52))) { + buttonPressed = false; } } } } - - public ChatListRowHolderEx(View view, int type) { - avatarImageView = (BackupImageView)view.findViewById(R.id.chat_group_avatar_image); - nameTextView = (TextView)view.findViewById(R.id.chat_user_group_name); - timeTextView = (TextView)view.findViewById(R.id.chat_time_text); - halfCheckImage = (ImageView)view.findViewById(R.id.chat_row_halfcheck); - checkImage = (ImageView)view.findViewById(R.id.chat_row_check); - messageTextView = (TextView)view.findViewById(R.id.chat_message_text); - phoneTextView = (TextView)view.findViewById(R.id.phone_text_view); - contactAvatar = (BackupImageView)view.findViewById(R.id.contact_avatar); - contactView = view.findViewById(R.id.shared_layout); - addContactButton = (ImageView)view.findViewById(R.id.add_contact_button); - addContactView = view.findViewById(R.id.add_contact_view); - chatBubbleView = view.findViewById(R.id.chat_bubble_layout); - if (messageTextView != null) { - messageTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, MessagesController.getInstance().fontSize); - } - - if (addContactButton != null) { - addContactButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - if (actionBarLayer.isActionModeShowed()) { - processRowSelect(view); - return; - } - Bundle args = new Bundle(); - args.putInt("user_id", message.messageOwner.media.user_id); - args.putString("phone", message.messageOwner.media.phone_number); - presentFragment(new ContactAddActivity(args)); - } - }); - - addContactButton.setOnLongClickListener(new View.OnLongClickListener() { - @Override - public boolean onLongClick(View v) { - createMenu(v, false); - return true; - } - }); - } - - if (contactView != null) { - contactView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - if (message.type == 12 || message.type == 13) { - if (actionBarLayer.isActionModeShowed()) { - processRowSelect(view); - return; - } - if (message.messageOwner.media.user_id != UserConfig.getClientUserId()) { - TLRPC.User user = null; - if (message.messageOwner.media.user_id != 0) { - user = MessagesController.getInstance().getUser(message.messageOwner.media.user_id); - } - if (user != null) { - Bundle args = new Bundle(); - args.putInt("user_id", message.messageOwner.media.user_id); - presentFragment(new UserProfileActivity(args)); - } else { - if (message.messageOwner.media.phone_number == null || message.messageOwner.media.phone_number.length() == 0) { - return; - } - if (getParentActivity() == null) { - return; - } - AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); - builder.setItems(new CharSequence[] {LocaleController.getString("Copy", R.string.Copy), LocaleController.getString("Call", R.string.Call)}, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialogInterface, int i) { - if (i == 1) { - try { - Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + message.messageOwner.media.phone_number)); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - getParentActivity().startActivity(intent); - } catch (Exception e) { - FileLog.e("tmessages", e); - } - } else if (i == 0) { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { - android.text.ClipboardManager clipboard = (android.text.ClipboardManager) ApplicationLoader.applicationContext.getSystemService(Context.CLIPBOARD_SERVICE); - clipboard.setText(message.messageOwner.media.phone_number); - } else { - android.content.ClipboardManager clipboard = (android.content.ClipboardManager) ApplicationLoader.applicationContext.getSystemService(Context.CLIPBOARD_SERVICE); - android.content.ClipData clip = android.content.ClipData.newPlainText("label", message.messageOwner.media.phone_number); - clipboard.setPrimaryClip(clip); - } - } - } - } - ); - showAlertDialog(builder); - } - } - } - } - }); - - contactView.setOnLongClickListener(new View.OnLongClickListener() { - @Override - public boolean onLongClick(View v) { - createMenu(v, false); - return true; - } - }); - } - - if (contactAvatar != null) { - contactAvatar.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - - } - }); - } - - if (avatarImageView != null) { - avatarImageView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - if (actionBarLayer.isActionModeShowed()) { - processRowSelect(view); - return; - } - if (message != null) { - Bundle args = new Bundle(); - args.putInt("user_id", message.messageOwner.from_id); - presentFragment(new UserProfileActivity(args)); - } - } - }); - } + if (!result) { + result = super.onTouchEvent(event); } - private void processOnClick(View view) { - if (actionBarLayer.isActionModeShowed()) { - processRowSelect(view); + return result; + } + + @Override + public void setMessageObject(MessageObject messageObject) { + if (currentMessageObject != messageObject || isUserDataChanged()) { + + int uid = messageObject.messageOwner.media.user_id; + contactUser = MessagesController.getInstance().getUser(uid); + + drawAddButton = contactUser != null && uid != UserConfig.getClientUserId() && ContactsController.getInstance().contactsDict.get(uid) == null; + + int maxWidth; + if (AndroidUtilities.isTablet()) { + maxWidth = (int) (AndroidUtilities.getMinTabletSide() * 0.7f); + } else { + maxWidth = (int) (Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) * 0.7f); } + maxWidth -= AndroidUtilities.dp(58 + (drawAddButton ? 52 : 0)); + + if (contactUser != null) { + if (contactUser.photo != null) { + currentPhoto = contactUser.photo.photo_small; + } + avatarImage.setImage(currentPhoto, "50_50", getResources().getDrawable(AndroidUtilities.getUserAvatarForId(uid)), false); + } else { + avatarImage.setImage(null, "50_50", getResources().getDrawable(AndroidUtilities.getUserAvatarForId(uid)), false); + } + + String currentNameString = ContactsController.formatName(messageObject.messageOwner.media.first_name, messageObject.messageOwner.media.last_name); + int nameWidth = Math.min((int) Math.ceil(namePaint.measureText(currentNameString)), maxWidth); + + CharSequence stringFinal = TextUtils.ellipsize(currentNameString.replace("\n", " "), namePaint, nameWidth, TextUtils.TruncateAt.END); + nameLayout = new StaticLayout(stringFinal, namePaint, nameWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false); + if (nameLayout.getLineCount() > 0) { + nameWidth = (int)Math.ceil(nameLayout.getLineWidth(0)); + } else { + nameWidth = 0; + } + + String phone = messageObject.messageOwner.media.phone_number; + if (phone != null && phone.length() != 0) { + if (!phone.startsWith("+")) { + phone = "+" + phone; + } + phone = PhoneFormat.getInstance().format(phone); + } else { + phone = LocaleController.getString("Unknown", R.string.Unknown); + } + int phoneWidth = Math.min((int) Math.ceil(phonePaint.measureText(phone)), maxWidth); + stringFinal = TextUtils.ellipsize(phone.replace("\n", " "), phonePaint, phoneWidth, TextUtils.TruncateAt.END); + phoneLayout = new StaticLayout(stringFinal, phonePaint, phoneWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false); + if (phoneLayout.getLineCount() > 0) { + phoneWidth = (int)Math.ceil(phoneLayout.getLineWidth(0)); + } else { + phoneWidth = 0; + } + + namesWidth = Math.max(nameWidth, phoneWidth); + backgroundWidth = AndroidUtilities.dp(75 + (drawAddButton ? 52 : 0)) + namesWidth; + + super.setMessageObject(messageObject); + } + } + + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), AndroidUtilities.dp(71)); + } + + @Override + protected void onLayout(boolean changed, int left, int top, int right, int bottom) { + super.onLayout(changed, left, top, right, bottom); + + if (currentMessageObject == null) { + return; + } + + int x; + + if (currentMessageObject.isOut()) { + x = layoutWidth - backgroundWidth + AndroidUtilities.dp(6); + } else { + if (isChat) { + x = AndroidUtilities.dp(67); + } else { + x = AndroidUtilities.dp(14); + } + } + avatarImage.setImageCoords(x + (drawAddButton ? AndroidUtilities.dp(52) : 0), AndroidUtilities.dp(7), AndroidUtilities.dp(42), AndroidUtilities.dp(42)); + } + + @Override + protected void onDraw(Canvas canvas) { + super.onDraw(canvas); + + if (currentMessageObject == null) { + return; + } + + avatarImage.draw(canvas, avatarImage.getImageX(), avatarImage.getImageY(), avatarImage.getImageWidth(), avatarImage.getImageWidth()); + + if (nameLayout != null) { + canvas.save(); + canvas.translate(avatarImage.getImageX() + avatarImage.getImageWidth() + AndroidUtilities.dp(9), AndroidUtilities.dp(8)); + namePaint.setColor(AndroidUtilities.getColorForId(currentMessageObject.messageOwner.media.user_id)); + nameLayout.draw(canvas); + canvas.restore(); + } + if (phoneLayout != null) { + canvas.save(); + canvas.translate(avatarImage.getImageX() + avatarImage.getImageWidth() + AndroidUtilities.dp(9), AndroidUtilities.dp(29)); + phoneLayout.draw(canvas); + canvas.restore(); + } + + if (drawAddButton) { + if (currentMessageObject.isOut()) { + linePaint.setColor(0x9670b15c); + } else { + linePaint.setColor(0xffe8e8e8); + } + canvas.drawLine(avatarImage.getImageX() - AndroidUtilities.dp(4), avatarImage.getImageY(), avatarImage.getImageX() - AndroidUtilities.dp(4), AndroidUtilities.dp(62), linePaint); + + setDrawableBounds(addContactDrawable, avatarImage.getImageX() - AndroidUtilities.dp(44), AndroidUtilities.dp(20)); + addContactDrawable.draw(canvas); } } - */ } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMediaCell.java b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMediaCell.java index f73109553..8952b629b 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMediaCell.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMediaCell.java @@ -569,7 +569,11 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD } if (currentMessageObject.isSecretMedia()) { - w = h = (int) (Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) * 0.5f); + if (AndroidUtilities.isTablet()) { + w = h = (int) (AndroidUtilities.getMinTabletSide() * 0.5f); + } else { + w = h = (int) (Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) * 0.5f); + } } photoWidth = w; diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java index 2096f86d8..ac0fd5fcb 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java @@ -20,12 +20,8 @@ import android.content.SharedPreferences; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.res.Configuration; -import android.graphics.Bitmap; import android.graphics.Rect; import android.graphics.drawable.Drawable; -import android.media.MediaMetadataRetriever; -import android.media.MediaPlayer; -import android.media.ThumbnailUtils; import android.net.Uri; import android.os.Build; import android.os.Bundle; @@ -51,7 +47,6 @@ import android.widget.Toast; import org.telegram.android.AndroidUtilities; import org.telegram.PhoneFormat.PhoneFormat; -import org.telegram.android.ImageLoader; import org.telegram.android.LocaleController; import org.telegram.android.MediaController; import org.telegram.android.MessagesStorage; @@ -470,7 +465,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not fragment.setDelegate(new PhotoPickerActivity.PhotoPickerActivityDelegate() { @Override public void didSelectPhotos(ArrayList photos) { - processSendingPhotos(photos, null); + SendMessagesHelper.prepareSendingPhotos(photos, null, dialog_id); } @Override @@ -531,7 +526,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not @Override public void didSelectFile(DocumentSelectActivity activity, String path) { activity.finishFragment(); - processSendingDocument(path, path); + SendMessagesHelper.prepareSendingDocument(path, path, dialog_id); } @Override @@ -1480,11 +1475,11 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not videoEditedInfo.resultWidth = resultWidth; videoEditedInfo.resultHeight = resultHeight; videoEditedInfo.originalPath = videoPath; - processSendingVideo(videoPath, estimatedSize, estimatedDuration, resultWidth, resultHeight, videoEditedInfo); + SendMessagesHelper.prepareSendingVideo(videoPath, estimatedSize, estimatedDuration, resultWidth, resultHeight, videoEditedInfo, dialog_id); } }); if (parentLayout == null || !parentLayout.presentFragment(fragment, removeLast, true, true)) { - processSendingVideo(videoPath, 0, 0, 0, 0, null); + SendMessagesHelper.prepareSendingVideo(videoPath, 0, 0, 0, 0, null, dialog_id); return false; } return true; @@ -1503,14 +1498,14 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not if (resultCode == Activity.RESULT_OK) { if (requestCode == 0) { Utilities.addMediaToGallery(currentPicturePath); - processSendingPhoto(currentPicturePath, null); + SendMessagesHelper.prepareSendingPhoto(currentPicturePath, null, dialog_id); currentPicturePath = null; } else if (requestCode == 1) { if (data == null || data.getData() == null) { showAttachmentError(); return; } - processSendingPhoto(null, data.getData()); + SendMessagesHelper.prepareSendingPhoto(null, data.getData(), dialog_id); } else if (requestCode == 2) { String videoPath = null; if (data != null) { @@ -1551,7 +1546,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not openVideoEditor(videoPath, false, parentLayout); } } else { - processSendingVideo(videoPath, 0, 0, 0, 0, null); + SendMessagesHelper.prepareSendingVideo(videoPath, 0, 0, 0, 0, null, dialog_id); } } else if (requestCode == 21) { if (data == null || data.getData() == null) { @@ -1568,7 +1563,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not showAttachmentError(); return; } - processSendingDocument(tempPath, originalPath); + SendMessagesHelper.prepareSendingDocument(tempPath, originalPath, dialog_id); } } } @@ -1603,333 +1598,6 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not return chatActivityEnterView.processSendingText(text); } - public void processSendingPhoto(String imageFilePath, Uri imageUri) { - ArrayList paths = null; - ArrayList uris = null; - if (imageFilePath != null && imageFilePath.length() != 0) { - paths = new ArrayList(); - paths.add(imageFilePath); - } - if (imageUri != null) { - uris = new ArrayList(); - uris.add(imageUri); - } - processSendingPhotos(paths, uris); - } - - public void processSendingPhotos(ArrayList paths, ArrayList uris) { - if (paths == null && uris == null || paths != null && paths.isEmpty() || uris != null && uris.isEmpty()) { - return; - } - final ArrayList pathsCopy = new ArrayList(); - final ArrayList urisCopy = new ArrayList(); - if (paths != null) { - pathsCopy.addAll(paths); - } - if (uris != null) { - urisCopy.addAll(uris); - } - new Thread(new Runnable() { - @Override - public void run() { - ArrayList sendAsDocuments = null; - ArrayList sendAsDocumentsOriginal = null; - int count = !pathsCopy.isEmpty() ? pathsCopy.size() : urisCopy.size(); - String path = null; - Uri uri = null; - for (int a = 0; a < count; a++) { - if (!pathsCopy.isEmpty()) { - path = pathsCopy.get(a); - } else if (!urisCopy.isEmpty()) { - uri = urisCopy.get(a); - } - - String originalPath = path; - String tempPath = path; - if (tempPath == null && uri != null) { - tempPath = Utilities.getPath(uri); - originalPath = uri.toString(); - } - - boolean isGif = false; - if (tempPath != null && tempPath.endsWith(".gif")) { - isGif = true; - } else if (tempPath == null && uri != null) { - isGif = MediaController.isGif(uri); - if (isGif) { - originalPath = uri.toString(); - tempPath = MediaController.copyDocumentToCache(uri, "gif"); - } - } - - if (isGif) { - if (sendAsDocuments == null) { - sendAsDocuments = new ArrayList(); - sendAsDocumentsOriginal = new ArrayList(); - } - sendAsDocuments.add(tempPath); - sendAsDocumentsOriginal.add(originalPath); - } else { - if (tempPath != null) { - File temp = new File(tempPath); - originalPath += temp.length() + "_" + temp.lastModified(); - } else { - originalPath = null; - } - TLRPC.TL_photo photo = (TLRPC.TL_photo)MessagesStorage.getInstance().getSentFile(originalPath, currentEncryptedChat == null ? 0 : 3); - if (photo == null && uri != null) { - photo = (TLRPC.TL_photo)MessagesStorage.getInstance().getSentFile(Utilities.getPath(uri), currentEncryptedChat == null ? 0 : 3); - } - if (photo == null) { - photo = SendMessagesHelper.getInstance().generatePhotoSizes(path, uri); - } - if (photo != null) { - final String originalPathFinal = originalPath; - final TLRPC.TL_photo photoFinal = photo; - AndroidUtilities.RunOnUIThread(new Runnable() { - @Override - public void run() { - SendMessagesHelper.getInstance().sendMessage(photoFinal, originalPathFinal, dialog_id); - if (chatListView != null) { - chatListView.setSelectionFromTop(messages.size() - 1, -100000 - chatListView.getPaddingTop()); - } - if (paused) { - scrollToTopOnResume = true; - } - } - }); - } - } - } - if (sendAsDocuments != null && !sendAsDocuments.isEmpty()) { - for (int a = 0; a < sendAsDocuments.size(); a++) { - processSendingDocumentInternal(sendAsDocuments.get(a), sendAsDocumentsOriginal.get(a)); - } - } - } - }).start(); - } - - private void processSendingDocumentInternal(final String path, String originalPath) { - if (path == null || path.length() == 0) { - return; - } - final File f = new File(path); - if (!f.exists() || f.length() == 0) { - return; - } - - String name = f.getName(); - if (name == null) { - name = "noname"; - } - String ext = ""; - int idx = path.lastIndexOf("."); - if (idx != -1) { - ext = path.substring(idx + 1); - } - if (originalPath != null) { - originalPath += "" + f.length(); - } - - TLRPC.TL_document document = (TLRPC.TL_document)MessagesStorage.getInstance().getSentFile(originalPath, currentEncryptedChat == null ? 1 : 4); - if (document == null && !path.equals(originalPath)) { - document = (TLRPC.TL_document)MessagesStorage.getInstance().getSentFile(path + f.length(), currentEncryptedChat == null ? 1 : 4); - } - if (document == null) { - document = new TLRPC.TL_document(); - document.id = 0; - document.user_id = UserConfig.getClientUserId(); - document.date = ConnectionsManager.getInstance().getCurrentTime(); - document.file_name = name; - document.size = (int)f.length(); - document.dc_id = 0; - if (ext.length() != 0) { - MimeTypeMap myMime = MimeTypeMap.getSingleton(); - String mimeType = myMime.getMimeTypeFromExtension(ext.toLowerCase()); - if (mimeType != null) { - document.mime_type = mimeType; - } else { - document.mime_type = "application/octet-stream"; - } - } else { - document.mime_type = "application/octet-stream"; - } - if (document.mime_type.equals("image/gif")) { - try { - Bitmap bitmap = ImageLoader.loadBitmap(f.getAbsolutePath(), null, 90, 90); - if (bitmap != null) { - document.thumb = ImageLoader.scaleAndSaveImage(bitmap, 90, 90, 55, currentEncryptedChat != null); - } - } catch (Exception e) { - FileLog.e("tmessages", e); - } - } - if (document.thumb == null) { - document.thumb = new TLRPC.TL_photoSizeEmpty(); - document.thumb.type = "s"; - } - } - - final TLRPC.TL_document documentFinal = document; - final String originalPathFinal = originalPath; - AndroidUtilities.RunOnUIThread(new Runnable() { - @Override - public void run() { - SendMessagesHelper.getInstance().sendMessage(documentFinal, originalPathFinal, path, dialog_id); - if (chatListView != null) { - chatListView.setSelectionFromTop(messages.size() - 1, -100000 - chatListView.getPaddingTop()); - } - if (paused) { - scrollToTopOnResume = true; - } - } - }); - } - - public void processSendingDocument(String path, String originalPath) { - if (path == null || originalPath == null) { - return; - } - ArrayList paths = new ArrayList(); - ArrayList originalPaths = new ArrayList(); - paths.add(path); - originalPaths.add(originalPath); - processSendingDocuments(paths, originalPaths); - } - - public void processSendingDocuments(final ArrayList paths, final ArrayList originalPaths) { - if (paths == null && originalPaths == null || paths != null && originalPaths != null && paths.size() != originalPaths.size()) { - return; - } - new Thread(new Runnable() { - @Override - public void run() { - for (int a = 0; a < paths.size(); a++) { - processSendingDocumentInternal(paths.get(a), originalPaths.get(a)); - } - } - }).start(); - } - - public void processSendingVideo(final String videoPath, final long estimatedSize, final long duration, final int width, final int height, final TLRPC.VideoEditedInfo videoEditedInfo) { - if (videoPath == null || videoPath.length() == 0) { - return; - } - new Thread(new Runnable() { - @Override - public void run() { - String path = videoPath; - String originalPath = videoPath; - File temp = new File(originalPath); - originalPath += temp.length() + "_" + temp.lastModified(); - if (videoEditedInfo != null) { - originalPath += duration + "_" + videoEditedInfo.startTime + "_" + videoEditedInfo.endTime; - } - TLRPC.TL_video video = (TLRPC.TL_video)MessagesStorage.getInstance().getSentFile(originalPath, currentEncryptedChat == null ? 2 : 5); - if (video == null) { - Bitmap thumb = ThumbnailUtils.createVideoThumbnail(videoPath, MediaStore.Video.Thumbnails.MINI_KIND); - TLRPC.PhotoSize size = ImageLoader.scaleAndSaveImage(thumb, 90, 90, 55, currentEncryptedChat != null); - video = new TLRPC.TL_video(); - video.thumb = size; - if (video.thumb == null) { - video.thumb = new TLRPC.TL_photoSizeEmpty(); - video.thumb.type = "s"; - } else { - video.thumb.type = "s"; - } - video.caption = ""; - video.mime_type = "video/mp4"; - video.id = 0; - UserConfig.saveConfig(false); - - if (videoEditedInfo != null) { - video.duration = (int)(duration / 1000); - if (videoEditedInfo.rotationValue == 90 || videoEditedInfo.rotationValue == 270) { - video.w = height; - video.h = width; - } else { - video.w = width; - video.h = height; - } - video.size = (int)estimatedSize; - video.videoEditedInfo = videoEditedInfo; - String fileName = Integer.MIN_VALUE + "_" + UserConfig.lastLocalId + ".mp4"; - UserConfig.lastLocalId--; - File cacheFile = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName); - UserConfig.saveConfig(false); - path = cacheFile.getAbsolutePath(); - } else { - if (temp != null && temp.exists()) { - video.size = (int) temp.length(); - } - boolean infoObtained = false; - if (Build.VERSION.SDK_INT >= 14) { - MediaMetadataRetriever mediaMetadataRetriever = null; - try { - mediaMetadataRetriever = new MediaMetadataRetriever(); - mediaMetadataRetriever.setDataSource(videoPath); - String width = mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH); - if (width != null) { - video.w = Integer.parseInt(width); - } - String height = mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT); - if (height != null) { - video.h = Integer.parseInt(height); - } - String duration = mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION); - if (duration != null) { - video.duration = (int) Math.ceil(Long.parseLong(duration) / 1000.0f); - } - infoObtained = true; - } catch (Exception e) { - FileLog.e("tmessages", e); - } finally { - try { - if (mediaMetadataRetriever != null) { - mediaMetadataRetriever.release(); - mediaMetadataRetriever = null; - } - } catch (Exception e) { - FileLog.e("tmessages", e); - } - } - } - if (!infoObtained) { - try { - MediaPlayer mp = MediaPlayer.create(ApplicationLoader.applicationContext, Uri.fromFile(new File(videoPath))); - if (mp != null) { - video.duration = (int) Math.ceil(mp.getDuration() / 1000.0f); - video.w = mp.getVideoWidth(); - video.h = mp.getVideoHeight(); - mp.release(); - } - } catch (Exception e) { - FileLog.e("tmessages", e); - } - } - } - } - - final TLRPC.TL_video videoFinal = video; - final String originalPathFinal = originalPath; - final String finalPath = path; - AndroidUtilities.RunOnUIThread(new Runnable() { - @Override - public void run() { - SendMessagesHelper.getInstance().sendMessage(videoFinal, originalPathFinal, finalPath, dialog_id); - if (chatListView != null) { - chatListView.setSelectionFromTop(messages.size() - 1, -100000 - chatListView.getPaddingTop()); - } - if (paused) { - scrollToTopOnResume = true; - } - } - }); - } - }).start(); - } - @SuppressWarnings("unchecked") @Override public void didReceivedNotification(int id, final Object... args) { @@ -2180,6 +1848,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not if (did == dialog_id) { boolean updateChat = false; + boolean hasFromMe = false; ArrayList arr = (ArrayList)args[1]; if (!unread_end_reached) { @@ -2245,6 +1914,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not if (obj.isOut()) { removeUnreadPlane(false); + hasFromMe = true; } if (!obj.isOut() && unreadMessageObject != null) { @@ -2299,7 +1969,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not if (endReached) { lastVisible++; } - if (lastVisible == oldCount) { + if (lastVisible == oldCount || hasFromMe) { if (!firstLoading) { if (paused) { scrollToTopOnResume = true; @@ -3385,6 +3055,10 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not ((ChatBaseCell)view).setDelegate(new ChatBaseCell.ChatBaseCellDelegate() { @Override public void didPressedUserAvatar(ChatBaseCell cell, TLRPC.User user) { + if (actionBarLayer.isActionModeShowed()) { + processRowSelect(cell); + return; + } if (user != null && user.id != UserConfig.getClientUserId()) { Bundle args = new Bundle(); args.putInt("user_id", user.id); @@ -3496,6 +3170,58 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not createMenu(cell, true); } }); + } else if (view instanceof ChatContactCell) { + ((ChatContactCell)view).setContactDelegate(new ChatContactCell.ChatContactCellDelegate() { + @Override + public void didClickAddButton(ChatContactCell cell, TLRPC.User user) { + if (actionBarLayer.isActionModeShowed()) { + processRowSelect(cell); + return; + } + Bundle args = new Bundle(); + args.putInt("user_id", message.messageOwner.media.user_id); + args.putString("phone", message.messageOwner.media.phone_number); + presentFragment(new ContactAddActivity(args)); + } + + @Override + public void didClickPhone(ChatContactCell cell) { + if (actionBarLayer.isActionModeShowed()) { + processRowSelect(cell); + return; + } + final MessageObject messageObject = cell.getMessageObject(); + if (getParentActivity() == null || messageObject.messageOwner.media.phone_number == null || messageObject.messageOwner.media.phone_number.length() == 0) { + return; + } + AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); + builder.setItems(new CharSequence[] {LocaleController.getString("Copy", R.string.Copy), LocaleController.getString("Call", R.string.Call)}, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + if (i == 1) { + try { + Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + messageObject.messageOwner.media.phone_number)); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + getParentActivity().startActivity(intent); + } catch (Exception e) { + FileLog.e("tmessages", e); + } + } else if (i == 0) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { + android.text.ClipboardManager clipboard = (android.text.ClipboardManager) ApplicationLoader.applicationContext.getSystemService(Context.CLIPBOARD_SERVICE); + clipboard.setText(messageObject.messageOwner.media.phone_number); + } else { + android.content.ClipboardManager clipboard = (android.content.ClipboardManager) ApplicationLoader.applicationContext.getSystemService(Context.CLIPBOARD_SERVICE); + android.content.ClipData clip = android.content.ClipData.newPlainText("label", messageObject.messageOwner.media.phone_number); + clipboard.setPrimaryClip(clip); + } + } + } + } + ); + showAlertDialog(builder); + } + }); } } else if (view instanceof ChatActionCell) { ((ChatActionCell)view).setDelegate(new ChatActionCell.ChatActionCellDelegate() { diff --git a/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java index 11817f092..f61b30d5f 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java @@ -670,7 +670,7 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa } } else { actionBarLayout.presentFragment(fragment, true); - fragment.processSendingVideo(videoPath, 0, 0, 0, 0, null); + SendMessagesHelper.prepareSendingVideo(videoPath, 0, 0, 0, 0, null, dialog_id); } } else { actionBarLayout.presentFragment(fragment, true); @@ -678,10 +678,10 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa fragment.processSendingText(sendingText); } if (photoPathsArray != null) { - fragment.processSendingPhotos(null, photoPathsArray); + SendMessagesHelper.prepareSendingPhotos(null, photoPathsArray, dialog_id); } if (documentsPathsArray != null) { - fragment.processSendingDocuments(documentsPathsArray, documentsOriginalPathsArray); + SendMessagesHelper.prepareSendingDocuments(documentsPathsArray, documentsOriginalPathsArray, dialog_id); } if (contactsToSend != null && !contactsToSend.isEmpty()) { for (TLRPC.User user : contactsToSend) { @@ -1190,7 +1190,7 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa buttonLayoutTablet.setVisibility(View.VISIBLE); backgroundTablet.setVisibility(View.VISIBLE); } - } else if (layout == layersActionBarLayout && actionBarLayout.fragmentsStack.isEmpty()) { + } else if (layout == layersActionBarLayout && actionBarLayout.fragmentsStack.isEmpty() && layersActionBarLayout.fragmentsStack.size() == 1) { onFinish(); finish(); return false; diff --git a/TMessagesProj/src/main/java/org/telegram/ui/SettingsActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/SettingsActivity.java index 8a0b4e9ee..ce0c21d93 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/SettingsActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/SettingsActivity.java @@ -853,7 +853,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter if (user != null && user.phone != null && user.phone.length() != 0) { textView.setText(PhoneFormat.getInstance().format("+" + user.phone)); } else { - textView.setText("Unknown"); + textView.setText(LocaleController.getString("Unknown", R.string.Unknown)); } divider.setVisibility(View.INVISIBLE); } else if (i == notificationRow) { diff --git a/TMessagesProj/src/main/java/org/telegram/ui/SettingsBlockedUsersActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/SettingsBlockedUsersActivity.java index b1f888cad..b2e169a63 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/SettingsBlockedUsersActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/SettingsBlockedUsersActivity.java @@ -249,7 +249,7 @@ public class SettingsBlockedUsersActivity extends BaseFragment implements Notifi ((ChatOrUserCell)view).useSeparator = true; } TLRPC.User user = MessagesController.getInstance().getUser(MessagesController.getInstance().blockedUsers.get(i)); - ((ChatOrUserCell)view).setData(user, null, null, null, user.phone != null && user.phone.length() != 0 ? PhoneFormat.getInstance().format("+" + user.phone) : "Unknown"); + ((ChatOrUserCell)view).setData(user, null, null, null, user.phone != null && user.phone.length() != 0 ? PhoneFormat.getInstance().format("+" + user.phone) : LocaleController.getString("Unknown", R.string.Unknown)); } else if (type == 1) { if (view == null) { LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/UserProfileActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/UserProfileActivity.java index 84a121a0e..0d41355fd 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/UserProfileActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/UserProfileActivity.java @@ -608,7 +608,7 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen if (user.phone != null && user.phone.length() != 0) { textView.setText(PhoneFormat.getInstance().format("+" + user.phone)); } else { - textView.setText("Unknown"); + textView.setText(LocaleController.getString("Unknown", R.string.Unknown)); } divider.setVisibility(View.INVISIBLE); detailTextView.setText(LocaleController.getString("PhoneMobile", R.string.PhoneMobile)); diff --git a/TMessagesProj/src/main/res/layout/chat_group_incoming_contact_layout.xml b/TMessagesProj/src/main/res/layout/chat_group_incoming_contact_layout.xml deleted file mode 100644 index 0445491b5..000000000 --- a/TMessagesProj/src/main/res/layout/chat_group_incoming_contact_layout.xml +++ /dev/null @@ -1,95 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/TMessagesProj/src/main/res/layout/chat_incoming_contact_layout.xml b/TMessagesProj/src/main/res/layout/chat_incoming_contact_layout.xml deleted file mode 100644 index d7643a8a3..000000000 --- a/TMessagesProj/src/main/res/layout/chat_incoming_contact_layout.xml +++ /dev/null @@ -1,87 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/TMessagesProj/src/main/res/layout/chat_outgoing_contact_layout.xml b/TMessagesProj/src/main/res/layout/chat_outgoing_contact_layout.xml deleted file mode 100644 index f047bc8b6..000000000 --- a/TMessagesProj/src/main/res/layout/chat_outgoing_contact_layout.xml +++ /dev/null @@ -1,117 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/TMessagesProj/src/main/res/values-ar/strings.xml b/TMessagesProj/src/main/res/values-ar/strings.xml index 31cc29bef..f0367e4e4 100644 --- a/TMessagesProj/src/main/res/values-ar/strings.xml +++ b/TMessagesProj/src/main/res/values-ar/strings.xml @@ -197,6 +197,7 @@ عداد التدمير الذاتي إيقاف هذه الصورة هي تصور لمفتاح التشفير لهذه المحادثة السرية مع ]]>%1$s]]>.
]]>إذا كانت مطابقة للصورة التي في جهاز ]]>%2$s]]>, فمحادثتكم آمنة ٢٠٠٪.
]]>للمزيد نرجو الذهاب إلى telegram.org
+ Unknown تم تعيين كافة الإشعارات افتراضيا حجم نص الرسائل diff --git a/TMessagesProj/src/main/res/values-de/strings.xml b/TMessagesProj/src/main/res/values-de/strings.xml index 1f5e3ecec..478d7458f 100644 --- a/TMessagesProj/src/main/res/values-de/strings.xml +++ b/TMessagesProj/src/main/res/values-de/strings.xml @@ -197,6 +197,7 @@ Selbstzerstörungs-Timer Aus Das ist eine Darstellung des Schlüssels für den Geheimen Chat mit ]]>%1$s]]>.
]]>Wenn dieses Bild auf ]]>%2$s\s]]>s Telefon genau so aussieht, ist euer Chat zu 200%% sicher.
]]>Erfahre mehr auf telegram.org
+ Unknown Alle Einstellungen für Mitteilungen zurücksetzen Textgröße für Nachrichten diff --git a/TMessagesProj/src/main/res/values-es/strings.xml b/TMessagesProj/src/main/res/values-es/strings.xml index a305a69f1..920f5533a 100644 --- a/TMessagesProj/src/main/res/values-es/strings.xml +++ b/TMessagesProj/src/main/res/values-es/strings.xml @@ -197,6 +197,7 @@ Autodestrucción Apagada Esta imagen es una visualización de la clave de cifrado para el chat secreto con ]]>%1$s]]>.
]]>Si esta imagen se ve igual en el teléfono de ]]>%2$s]]>, tu chat es seguro en un 200%%.
]]>Aprende más en telegram.org
+ Unknown Restablecer las notificaciones Tamaño del texto diff --git a/TMessagesProj/src/main/res/values-it/strings.xml b/TMessagesProj/src/main/res/values-it/strings.xml index ab97be9d1..581b0807d 100644 --- a/TMessagesProj/src/main/res/values-it/strings.xml +++ b/TMessagesProj/src/main/res/values-it/strings.xml @@ -197,6 +197,7 @@ Timer di autodistruzione Spento Questa immagine è una visualizzazione della chiave di cifratura per questa chat segreta con ]]>%1$s]]>.
]]>Se questa immagine è uguale sul telefono di ]]>%2$s]]>, la chat è sicura al 200%%.
]]>Per saperne di più, visita Telegram.org
+ Unknown Ripristina tutte le impostazioni di notifica predefinite Dimensione testo messaggi diff --git a/TMessagesProj/src/main/res/values-ko/strings.xml b/TMessagesProj/src/main/res/values-ko/strings.xml index b17838d1f..e44c83b9a 100644 --- a/TMessagesProj/src/main/res/values-ko/strings.xml +++ b/TMessagesProj/src/main/res/values-ko/strings.xml @@ -197,6 +197,7 @@ 자동삭제 타이머 해제 이 이미지는 ]]>%1$s]]>님과의 비밀대화에 사용 중인 암호화 키의 모습입니다.
]]>이 이미지가 ]]>%2$s]]>님의 암호화 키와 똑같다면 대화는 200%% 안전합니다.
]]>더 자세한 사항은 telegram.org 를 참고해 주세요.
+ Unknown 모든 알림 설정이 초기화되었습니다 채팅 글자 크기 diff --git a/TMessagesProj/src/main/res/values-nl/strings.xml b/TMessagesProj/src/main/res/values-nl/strings.xml index a14614570..eb9299974 100644 --- a/TMessagesProj/src/main/res/values-nl/strings.xml +++ b/TMessagesProj/src/main/res/values-nl/strings.xml @@ -197,6 +197,7 @@ Zelfvernietigingstimer Uit Dit is een weergave van de encryptiesleutel voor deze geheime chat met ]]>%1$s]]>.
]]>Als deze afbeelding er bij ]]>%2$s]]> hetzelfde uitziet, is jullie gesprek 200%% beveiligd.
]]>Lees meer op telegram.org.
+ Unknown Alle meldingsinstellingen herstellen Tekstgrootte berichten diff --git a/TMessagesProj/src/main/res/values-pt-rBR/strings.xml b/TMessagesProj/src/main/res/values-pt-rBR/strings.xml index ae5634e1a..8a04e1e61 100644 --- a/TMessagesProj/src/main/res/values-pt-rBR/strings.xml +++ b/TMessagesProj/src/main/res/values-pt-rBR/strings.xml @@ -197,6 +197,7 @@ Tempo de autodestruição Desativado Esta imagem é uma visualização da chave criptográfica para esta conversa secreta com ]]>%1$s]]>.
]]>Se esta imagem aparecer da mesma forma no telefone de ]]>%2$s\'s]]>, sua conversa é 200%% segura.
]]>Saiba mais em telegram.org
+ Unknown Restaurar todas as configurações de notificação Tamanho do texto nas mensagens diff --git a/TMessagesProj/src/main/res/values-pt-rPT/strings.xml b/TMessagesProj/src/main/res/values-pt-rPT/strings.xml index 90d884f2b..844c59259 100644 --- a/TMessagesProj/src/main/res/values-pt-rPT/strings.xml +++ b/TMessagesProj/src/main/res/values-pt-rPT/strings.xml @@ -197,6 +197,7 @@ Tempo de autodestruição Desativado Esta imagem é uma visualização da chave criptográfica para esta conversa secreta com ]]>%1$s]]>.
]]>Se esta imagem aparecer da mesma forma no telefone de ]]>%2$s\'s]]>, sua conversa é 200%% segura.
]]>Saiba mais em telegram.org
+ Unknown Restaurar todas as configurações de notificação Tamanho do texto nas mensagens diff --git a/TMessagesProj/src/main/res/values/strings.xml b/TMessagesProj/src/main/res/values/strings.xml index 3dce45bef..67d833a25 100644 --- a/TMessagesProj/src/main/res/values/strings.xml +++ b/TMessagesProj/src/main/res/values/strings.xml @@ -197,6 +197,7 @@ Self-Destruct Timer Off This image is a visualization of the encryption key for this secret chat with ]]>%1$s]]>.
]]>If this image looks the same on ]]>%2$s\'s]]> phone, your chat is 200%% secure.
]]>Learn more at telegram.org
+ Unknown Reset all notification settings to default Messages Text Size