Optimize files upload, gif auto play after download, crash and bug fixes

This commit is contained in:
DrKLO 2014-04-04 01:18:54 +04:00
parent 51aa4141a4
commit ec533c5fff
41 changed files with 695 additions and 1119 deletions

View File

@ -82,7 +82,7 @@ android {
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
versionCode 219
versionName "1.4.9"
versionCode 220
versionName "1.4.10"
}
}

View File

@ -18,38 +18,29 @@
package jawnae.pyronet;
import org.telegram.messenger.BuffersStorage;
import org.telegram.messenger.ByteBufferDesc;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
public class ByteStream {
private final List<ByteBuffer> queue;
private final ArrayList<ByteBufferDesc> queue;
public ByteStream() {
// the queue is expected to be relatively small, and iterated often.
// hence removing the first element will be fast, even when using an
// ArrayList
this.queue = new ArrayList<ByteBuffer>();
this.queue = new ArrayList<ByteBufferDesc>();
}
/**
* Appends the ByteBuffer instance to the ByteStream. The bytes are not
* copied, so do not modify the contents of the ByteBuffer.
*/
public void append(ByteBuffer buf) {
if (buf == null)
public void append(ByteBufferDesc buf) {
if (buf == null) {
throw new NullPointerException();
}
this.queue.add(buf);
}
/**
* Returns whether there are any bytes pending in this stream
*/
public boolean hasData() {
int size = this.queue.size();
for (ByteBuffer aQueue : this.queue) {
for (ByteBufferDesc aQueue : this.queue) {
if (aQueue.hasRemaining()) {
return true;
}
@ -57,29 +48,13 @@ public class ByteStream {
return false;
}
public int getByteCount() {
int size = this.queue.size();
int sum = 0;
for (ByteBuffer aQueue : this.queue) {
sum += aQueue.remaining();
}
return sum;
}
/**
* Fills the specified buffer with as much bytes as possible. When N bytes
* are read, the buffer position will be increased by N
*/
public void get(ByteBuffer dst) {
if (dst == null) {
throw new NullPointerException();
}
for (ByteBuffer data: this.queue) {
// data pos/lim must not be modified
data = data.slice();
for (ByteBufferDesc bufferDesc : this.queue) {
ByteBuffer data = bufferDesc.buffer.slice();
if (data.remaining() > dst.remaining()) {
data.limit(dst.remaining());
@ -95,48 +70,25 @@ public class ByteStream {
}
}
/**
* Discards the specified amount of bytes from the stream.
*
* @throws PyroException
* if it failed to discard the specified number of bytes
*/
public void discard(int count) {
int original = count;
while (count > 0) {
// peek at the first buffer
ByteBuffer data = this.queue.get(0);
ByteBufferDesc data = this.queue.get(0);
if (count < data.remaining()) {
// discarding less bytes than remaining in buffer
if (count < data.buffer.remaining()) {
data.position(data.position() + count);
count = 0;
break;
}
// discard the first buffer
this.queue.remove(0);
count -= data.remaining();
BuffersStorage.getInstance().reuseFreeBuffer(data);
count -= data.buffer.remaining();
}
if (count != 0) {
// apparantly we cannot discard the amount of bytes
// the user demanded, this is a bug in other code
throw new PyroException("discarded " + (original - count) + "/"
+ original + " bytes");
throw new PyroException("discarded " + (original - count) + "/" + original + " bytes");
}
}
public byte read() {
ByteBuffer data = this.queue.get(0);
byte result = data.get();
if (!data.hasRemaining()) {
// discard the first buffer
this.queue.remove(0);
}
return result;
}
}

View File

@ -18,6 +18,8 @@
package jawnae.pyronet;
import org.telegram.messenger.ByteBufferDesc;
import java.io.EOFException;
import java.io.IOException;
import java.net.ConnectException;
@ -167,12 +169,6 @@ public class PyroClient {
this.doEagerWrite = enabled;
}
//
public void writeCopy(ByteBuffer data) throws PyroException {
this.write(this.selector.copy(data));
}
/**
* Will enqueue the bytes to send them<br>
* 1. when the selector is ready to write, if eagerWrite is disabled
@ -185,7 +181,7 @@ public class PyroClient {
* when shutdown() has been called.
*/
public void write(ByteBuffer data) throws PyroException {
public void write(ByteBufferDesc data) throws PyroException {
this.selector.checkThread();
if (!this.key.isValid()) {

View File

@ -56,25 +56,6 @@ public class PyroSelector {
//
public ByteBuffer malloc(int size) {
return ByteBuffer.allocate(size);
}
public ByteBuffer malloc(byte[] array) {
ByteBuffer copy = this.malloc(array.length);
copy.put(array);
copy.flip();
return copy;
}
public ByteBuffer copy(ByteBuffer buffer) {
ByteBuffer copy = this.malloc(buffer.remaining());
copy.put(buffer);
buffer.position(buffer.position() - copy.remaining());
copy.flip();
return copy;
}
public final boolean isNetworkThread() {
return DO_NOT_CHECK_NETWORK_THREAD || networkThread == Thread.currentThread();
}

View File

@ -30,6 +30,7 @@ public abstract class AbsSerializedData {
public abstract String readString();
public abstract byte[] readByteArray();
public abstract ByteBufferDesc readByteBuffer();
public abstract void writeByteBuffer(ByteBufferDesc buffer);
public abstract double readDouble();
public abstract int length();
}

View File

@ -78,7 +78,7 @@ public class ByteBufferDesc extends AbsSerializedData {
if (!justCalc) {
buffer.putLong(x);
} else {
len += 4;
len += 8;
}
} catch(Exception e) {
FileLog.e("tmessages", "write int64 error");
@ -227,6 +227,54 @@ public class ByteBufferDesc extends AbsSerializedData {
}
}
public void writeByteBuffer(ByteBufferDesc b) {
try {
int l = b.limit();
if (l <= 253) {
if (!justCalc) {
buffer.put((byte) l);
} else {
len += 1;
}
} else {
if (!justCalc) {
buffer.put((byte) 254);
buffer.put((byte) l);
buffer.put((byte) (l >> 8));
buffer.put((byte) (l >> 16));
} else {
len += 4;
}
}
if (!justCalc) {
b.rewind();
buffer.put(b.buffer);
} else {
len += l;
}
int i = l <= 253 ? 1 : 4;
while((l + i) % 4 != 0) {
if (!justCalc) {
buffer.put((byte) 0);
} else {
len += 1;
}
i++;
}
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
public void writeRaw(ByteBufferDesc b) {
if (justCalc) {
len += b.limit();
} else {
b.rewind();
buffer.put(b.buffer);
}
}
public int readInt32() {
return readInt32(null);
}

View File

@ -489,6 +489,8 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
public void run() {
Datacenter datacenter = datacenterWithId(currentDatacenterId);
recreateSession(datacenter.authSessionId, datacenter);
recreateSession(datacenter.authDownloadSessionId, datacenter);
recreateSession(datacenter.authUploadSessionId, datacenter);
}
});
}
@ -503,6 +505,14 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
clearRequestsForRequestClass(RPCRequest.RPCRequestClassGeneric, datacenter);
FileLog.d("tmessages", "***** Recreate generic session");
datacenter.authSessionId = getNewSessionId();
} else if (sessionId == datacenter.authDownloadSessionId) {
clearRequestsForRequestClass(RPCRequest.RPCRequestClassDownloadMedia, datacenter);
FileLog.d("tmessages", "***** Recreate download session");
datacenter.authDownloadSessionId = getNewSessionId();
} else if (sessionId == datacenter.authUploadSessionId) {
clearRequestsForRequestClass(RPCRequest.RPCRequestClassUploadMedia, datacenter);
FileLog.d("tmessages", "***** Recreate upload session");
datacenter.authUploadSessionId = getNewSessionId();
}
}
@ -850,6 +860,8 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
}
request.cancelled = true;
request.rawRequest.freeResources();
request.rpcRequest.freeResources();
runningRequests.remove(i);
break;
}
@ -1025,7 +1037,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
Datacenter requestDatacenter = datacenterWithId(datacenterId);
if (!request.initRequest && requestDatacenter.lastInitVersion != currentAppVersion) {
request.rpcRequest = wrapInLayer(request.rawRequest, requestDatacenter.datacenterId, request);
SerializedData os = new SerializedData(true);
ByteBufferDesc os = new ByteBufferDesc(true);
request.rpcRequest.serializeToStream(os);
request.serializedLength = os.length();
}
@ -1520,7 +1532,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
}
TLRPC.TL_protoMessage wrapMessage(TLObject message, long sessionId, boolean meaningful) {
SerializedData os = new SerializedData(true);
ByteBufferDesc os = new ByteBufferDesc(true);
message.serializeToStream(os);
if (os.length() != 0) {
@ -1552,7 +1564,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
msgAck.msg_ids = new ArrayList<Long>();
msgAck.msg_ids.addAll(arr);
SerializedData os = new SerializedData(true);
ByteBufferDesc os = new ByteBufferDesc(true);
msgAck.serializeToStream(os);
if (os.length() != 0) {
@ -1599,7 +1611,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
if (currentSize >= 3 * 1024 || a == messagesToSend.size() - 1) {
ArrayList<Integer> quickAckId = new ArrayList<Integer>();
byte[] transportData = createConnectionData(currentMessages, sessionId, quickAckId, connection);
ByteBufferDesc transportData = createConnectionData(currentMessages, sessionId, quickAckId, connection);
if (transportData != null) {
if (reportAck && quickAckId.size() != 0) {
@ -1622,7 +1634,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
}
}
connection.sendData(transportData, reportAck, requestShortTimeout);
connection.sendData(null, transportData, reportAck, requestShortTimeout);
} else {
FileLog.e("tmessages", "***** Transport data is nil");
}
@ -1634,7 +1646,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
}
@SuppressWarnings("unused")
byte[] createConnectionData(ArrayList<NetworkMessage> messages, long sessionId, ArrayList<Integer> quickAckId, TcpConnection connection) {
ByteBufferDesc createConnectionData(ArrayList<NetworkMessage> messages, long sessionId, ArrayList<Integer> quickAckId, TcpConnection connection) {
Datacenter datacenter = datacenterWithId(connection.getDatacenterId());
if (datacenter.authKey == null) {
return null;
@ -1711,11 +1723,11 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
messageSeqNo = generateMessageSeqNo(sessionId, false);
}
SerializedData innerMessageOs = new SerializedData();
messageBody.serializeToStream(innerMessageOs);
byte[] messageData = innerMessageOs.toByteArray();
ByteBufferDesc sizeBuffer = new ByteBufferDesc(true);
messageBody.serializeToStream(sizeBuffer);
ByteBufferDesc innerOs = BuffersStorage.getInstance().getFreeBuffer(8 + 8 + 8 + 4 + 4 + sizeBuffer.length());
SerializedData innerOs = new SerializedData(8 + 8 + 8 + 4 + 4 + messageData.length);
long serverSalt = datacenter.selectServerSalt(getCurrentTime());
if (serverSalt == 0) {
innerOs.writeInt64(0);
@ -1725,11 +1737,10 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
innerOs.writeInt64(sessionId);
innerOs.writeInt64(messageId);
innerOs.writeInt32(messageSeqNo);
innerOs.writeInt32(messageData.length);
innerOs.writeRaw(messageData);
byte[] innerData = innerOs.toByteArray();
innerOs.writeInt32(sizeBuffer.length());
messageBody.serializeToStream(innerOs);
byte[] messageKeyFull = Utilities.computeSHA1(innerData);
byte[] messageKeyFull = Utilities.computeSHA1(innerOs.buffer, 0, innerOs.limit());
byte[] messageKey = new byte[16];
System.arraycopy(messageKeyFull, messageKeyFull.length - 16, messageKey, 0, 16);
@ -1740,35 +1751,29 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
MessageKeyData keyData = Utilities.generateMessageKeyData(datacenter.authKey, messageKey, false);
SerializedData dataForEncryption = new SerializedData(innerData.length + (innerData.length % 16));
dataForEncryption.writeRaw(innerData);
int zeroCount = 0;
if (innerOs.limit() % 16 != 0) {
zeroCount = 16 - innerOs.limit() % 16;
}
ByteBufferDesc dataForEncryption = BuffersStorage.getInstance().getFreeBuffer(innerOs.limit() + zeroCount);
dataForEncryption.writeRaw(innerOs);
BuffersStorage.getInstance().reuseFreeBuffer(innerOs);
byte[] b = new byte[1];
while (dataForEncryption.length() % 16 != 0) {
for (int a = 0; a < zeroCount; a++) {
MessagesController.random.nextBytes(b);
dataForEncryption.writeByte(b[0]);
}
byte[] encryptedData = Utilities.aesIgeEncryption(dataForEncryption.toByteArray(), keyData.aesKey, keyData.aesIv, true, false, 0);
Utilities.aesIgeEncryption2(dataForEncryption.buffer, keyData.aesKey, keyData.aesIv, true, false, dataForEncryption.limit());
try {
SerializedData data = new SerializedData(8 + messageKey.length + encryptedData.length);
data.writeInt64(datacenter.authKeyId);
data.writeRaw(messageKey);
data.writeRaw(encryptedData);
ByteBufferDesc data = BuffersStorage.getInstance().getFreeBuffer(8 + messageKey.length + dataForEncryption.limit());
data.writeInt64(datacenter.authKeyId);
data.writeRaw(messageKey);
data.writeRaw(dataForEncryption);
BuffersStorage.getInstance().reuseFreeBuffer(dataForEncryption);
return data.toByteArray();
} catch (Exception e) {
FileLog.e("tmessages", e);
innerData = null;
messageData = null;
System.gc();
SerializedData data = new SerializedData();
data.writeInt64(datacenter.authKeyId);
data.writeRaw(messageKey);
data.writeRaw(encryptedData);
return data.toByteArray();
}
return data;
}
void refillSaltSet(final Datacenter datacenter) {
@ -1821,6 +1826,8 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
RPCRequest request = runningRequests.get(i);
removeRequestInClass(request.token);
if (request.respondsToMessageId(requestMsgId)) {
request.rawRequest.freeResources();
request.rpcRequest.freeResources();
runningRequests.remove(i);
i--;
}
@ -2188,6 +2195,9 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
}
recreateSession(datacenter.authSessionId, datacenter);
recreateSession(datacenter.authDownloadSessionId, datacenter);
recreateSession(datacenter.authUploadSessionId, datacenter);
saveSession();
lastOutgoingMessageId = 0;
@ -2273,7 +2283,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
}
static long nextPingId = 0;
byte[] generatePingData(Datacenter datacenter, boolean recordTime) {
ByteBufferDesc generatePingData(Datacenter datacenter, boolean recordTime) {
long sessionId = datacenter.authSessionId;
if (sessionId == 0) {
return null;
@ -2300,9 +2310,9 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
return;
}
byte[] transportData = generatePingData(datacenter, true);
ByteBufferDesc transportData = generatePingData(datacenter, true);
if (transportData != null) {
datacenter.connection.sendData(transportData, false, true);
datacenter.connection.sendData(null, transportData, false, true);
}
}
@ -2698,6 +2708,8 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
}
recreateSession(datacenter.authSessionId, datacenter);
recreateSession(datacenter.authDownloadSessionId, datacenter);
recreateSession(datacenter.authUploadSessionId, datacenter);
if (datacenter.authKey == null) {
datacenter.clearServerSalts();
@ -2766,6 +2778,8 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
timeDifference = (Integer)params.get("timeDifference");
recreateSession(eactor.datacenter.authSessionId, eactor.datacenter);
recreateSession(eactor.datacenter.authDownloadSessionId, eactor.datacenter);
recreateSession(eactor.datacenter.authUploadSessionId, eactor.datacenter);
}
processRequestQueue(RPCRequest.RPCRequestClassTransportMask, eactor.datacenter.datacenterId);
} else if (action instanceof ExportAuthorizationAction) {

View File

@ -125,15 +125,21 @@ public class FileUploadOperation {
if (key != null && readed % 16 != 0) {
toAdd += 16 - readed % 16;
}
byte[] sendBuffer = new byte[readed + toAdd];
ByteBufferDesc sendBuffer = BuffersStorage.getInstance().getFreeBuffer(readed + toAdd);
if (readed != uploadChunkSize) {
isLastPart = true;
}
System.arraycopy(readBuffer, 0, sendBuffer, 0, readed);
sendBuffer.writeRaw(readBuffer, 0, readed);
sendBuffer.rewind();
if (key != null) {
sendBuffer = Utilities.aesIgeEncryption(sendBuffer, key, iv, true, true, 0);
for (int a = 0; a < toAdd; a++) {
sendBuffer.writeByte(0);
}
Utilities.aesIgeEncryption2(sendBuffer.buffer, key, iv, true, true, readed + toAdd);
}
if (!isBigFile) {
mdEnc.update(sendBuffer.buffer);
}
mdEnc.update(sendBuffer, 0, readed + toAdd);
if (isBigFile) {
TLRPC.TL_upload_saveBigFilePart req = new TLRPC.TL_upload_saveBigFilePart();
req.file_part = currentPartNum;

View File

@ -179,7 +179,7 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
byte[] transportData = messageOs.toByteArray();
datacenter.connection.sendData(transportData, false, false);
datacenter.connection.sendData(transportData, null, false, false);
return transportData;
}
@ -576,11 +576,11 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
return;
}
if (reqPQMsgData != null) {
datacenter.connection.sendData(reqPQMsgData, false, false);
datacenter.connection.sendData(reqPQMsgData, null, false, false);
} else if (reqDHMsgData != null) {
datacenter.connection.sendData(reqDHMsgData, false, false);
datacenter.connection.sendData(reqDHMsgData, null, false, false);
} else if (setClientDHParamsMsgData != null) {
datacenter.connection.sendData(setClientDHParamsMsgData, false, false);
datacenter.connection.sendData(setClientDHParamsMsgData, null, false, false);
}
}

View File

@ -1016,8 +1016,23 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
});
}
public static void saveFile(String path, Context context, final int type, final String name) {
final File sourceFile = new File(Utilities.getCacheDir(), path);
public static void saveFile(String path, String fullPath, Context context, final int type, final String name) {
if (path == null && fullPath == null) {
return;
}
File file = null;
if (fullPath != null && fullPath.length() != 0) {
file = new File(fullPath);
if (!file.exists()) {
file = null;
}
}
if (file == null) {
file = new File(Utilities.getCacheDir(), path);
}
final File sourceFile = file;
if (sourceFile.exists()) {
ProgressDialog progressDialog = null;
if (context != null) {
@ -1121,7 +1136,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
return null;
}
if (currentGifMessageObject != null && messageObject.messageOwner.id == currentGifMessageObject.messageOwner.id) {
if (currentGifDrawable != null && currentGifMessageObject != null && messageObject.messageOwner.id == currentGifMessageObject.messageOwner.id) {
currentMediaCell = cell;
currentGifDrawable.parentView = new WeakReference<View>(cell);
return currentGifDrawable;

View File

@ -3274,7 +3274,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}
if (!(res instanceof TLRPC.TL_updates_differenceSlice)) {
if ((dialog_id != openned_dialog_id || ApplicationLoader.lastPauseTime != 0) && !obj.messageOwner.out && obj.messageOwner.unread && (lastMessage == null || lastMessage.messageOwner.date < obj.messageOwner.date)) {
if ((dialog_id != openned_dialog_id || ApplicationLoader.lastPauseTime != 0) && !obj.isOut() && obj.messageOwner.unread && (lastMessage == null || lastMessage.messageOwner.date < obj.messageOwner.date)) {
if (!readMessages.contains(obj.messageOwner.id)) {
lastMessage = obj;
}
@ -3342,7 +3342,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
ConnectionsManager.getInstance().connectionState = 0;
processUpdatesQueue(true);
} else if (res instanceof TLRPC.TL_updates_differenceSlice) {
MessagesStorage.lastSeqValue = res.intermediate_state.seq;
//MessagesStorage.lastSeqValue = res.intermediate_state.seq;
MessagesStorage.lastDateValue = res.intermediate_state.date;
MessagesStorage.lastPtsValue = res.intermediate_state.pts;
MessagesStorage.lastQtsValue = res.intermediate_state.qts;
@ -3380,123 +3380,131 @@ public class MessagesController implements NotificationCenter.NotificationCenter
processUpdateArray(arr, null, null);
} else if (updates instanceof TLRPC.TL_updateShortChatMessage) {
boolean missingData = chats.get(updates.chat_id) == null || users.get(updates.from_id) == null;
if (MessagesStorage.lastSeqValue + 1 == updates.seq && !missingData) {
TLRPC.TL_message message = new TLRPC.TL_message();
message.from_id = updates.from_id;
message.id = updates.id;
message.to_id = new TLRPC.TL_peerChat();
message.to_id.chat_id = updates.chat_id;
message.message = updates.message;
message.date = updates.date;
message.unread = true;
message.media = new TLRPC.TL_messageMediaEmpty();
MessagesStorage.lastSeqValue = updates.seq;
MessagesStorage.lastPtsValue = updates.pts;
final MessageObject obj = new MessageObject(message, null);
final ArrayList<MessageObject> objArr = new ArrayList<MessageObject>();
objArr.add(obj);
ArrayList<TLRPC.Message> arr = new ArrayList<TLRPC.Message>();
arr.add(message);
final boolean printUpdate = updatePrintingUsersWithNewMessages(-updates.chat_id, objArr);
if (printUpdate) {
updatePrintingStrings();
}
Utilities.RunOnUIThread(new Runnable() {
@Override
public void run() {
if (printUpdate) {
NotificationCenter.getInstance().postNotificationName(updateInterfaces, UPDATE_MASK_USER_PRINT);
}
if (obj.messageOwner.from_id != UserConfig.clientUserId) {
long dialog_id;
if (obj.messageOwner.to_id.chat_id != 0) {
dialog_id = -obj.messageOwner.to_id.chat_id;
} else {
dialog_id = obj.messageOwner.to_id.user_id;
}
if (dialog_id != openned_dialog_id || ApplicationLoader.lastPauseTime != 0 || !ApplicationLoader.isScreenOn) {
showInAppNotification(obj);
}
}
updateInterfaceWithMessages(-updates.chat_id, objArr);
NotificationCenter.getInstance().postNotificationName(dialogsNeedReload);
if (missingData) {
needGetDiff = true;
} else {
if (MessagesStorage.lastSeqValue + 1 == updates.seq && !gettingDifference) {
TLRPC.TL_message message = new TLRPC.TL_message();
message.from_id = updates.from_id;
message.id = updates.id;
message.to_id = new TLRPC.TL_peerChat();
message.to_id.chat_id = updates.chat_id;
message.message = updates.message;
message.date = updates.date;
message.unread = true;
message.media = new TLRPC.TL_messageMediaEmpty();
MessagesStorage.lastSeqValue = updates.seq;
MessagesStorage.lastPtsValue = updates.pts;
final MessageObject obj = new MessageObject(message, null);
final ArrayList<MessageObject> objArr = new ArrayList<MessageObject>();
objArr.add(obj);
ArrayList<TLRPC.Message> arr = new ArrayList<TLRPC.Message>();
arr.add(message);
final boolean printUpdate = updatePrintingUsersWithNewMessages(-updates.chat_id, objArr);
if (printUpdate) {
updatePrintingStrings();
}
});
MessagesStorage.getInstance().putMessages(arr, false, true);
} else if (!missingData && MessagesStorage.lastSeqValue != updates.seq) {
FileLog.e("tmessages", "need get diff TL_updateShortChatMessage, seq: " + MessagesStorage.lastSeqValue + " " + updates.seq);
if (gettingDifference || updatesStartWaitTime == 0 || updatesStartWaitTime != 0 && updatesStartWaitTime + 1500 > System.currentTimeMillis()) {
if (updatesStartWaitTime == 0) {
updatesStartWaitTime = System.currentTimeMillis();
Utilities.RunOnUIThread(new Runnable() {
@Override
public void run() {
if (printUpdate) {
NotificationCenter.getInstance().postNotificationName(updateInterfaces, UPDATE_MASK_USER_PRINT);
}
if (obj.messageOwner.from_id != UserConfig.clientUserId) {
long dialog_id;
if (obj.messageOwner.to_id.chat_id != 0) {
dialog_id = -obj.messageOwner.to_id.chat_id;
} else {
dialog_id = obj.messageOwner.to_id.user_id;
}
if (dialog_id != openned_dialog_id || ApplicationLoader.lastPauseTime != 0 || !ApplicationLoader.isScreenOn) {
showInAppNotification(obj);
}
}
updateInterfaceWithMessages(-updates.chat_id, objArr);
NotificationCenter.getInstance().postNotificationName(dialogsNeedReload);
}
});
MessagesStorage.getInstance().putMessages(arr, false, true);
} else if (MessagesStorage.lastSeqValue != updates.seq) {
FileLog.e("tmessages", "need get diff TL_updateShortChatMessage, seq: " + MessagesStorage.lastSeqValue + " " + updates.seq);
if (gettingDifference || updatesStartWaitTime == 0 || updatesStartWaitTime != 0 && updatesStartWaitTime + 1500 > System.currentTimeMillis()) {
if (updatesStartWaitTime == 0) {
updatesStartWaitTime = System.currentTimeMillis();
}
FileLog.e("tmessages", "add TL_updateShortChatMessage to queue");
updatesQueue.add(updates);
addedToQueue = true;
} else {
needGetDiff = true;
}
FileLog.e("tmessages", "add TL_updateShortChatMessage to queue");
updatesQueue.add(updates);
addedToQueue = true;
} else {
needGetDiff = true;
}
}
} else if (updates instanceof TLRPC.TL_updateShortMessage) {
boolean missingData = users.get(updates.from_id) == null;
if (MessagesStorage.lastSeqValue + 1 == updates.seq && !missingData) {
TLRPC.TL_message message = new TLRPC.TL_message();
message.from_id = updates.from_id;
message.id = updates.id;
message.to_id = new TLRPC.TL_peerUser();
message.to_id.user_id = updates.from_id;
message.message = updates.message;
message.date = updates.date;
message.unread = true;
message.media = new TLRPC.TL_messageMediaEmpty();
MessagesStorage.lastSeqValue = updates.seq;
MessagesStorage.lastPtsValue = updates.pts;
MessagesStorage.lastDateValue = updates.date;
final MessageObject obj = new MessageObject(message, null);
final ArrayList<MessageObject> objArr = new ArrayList<MessageObject>();
objArr.add(obj);
ArrayList<TLRPC.Message> arr = new ArrayList<TLRPC.Message>();
arr.add(message);
final boolean printUpdate = updatePrintingUsersWithNewMessages(updates.from_id, objArr);
if (printUpdate) {
updatePrintingStrings();
}
Utilities.RunOnUIThread(new Runnable() {
@Override
public void run() {
if (printUpdate) {
NotificationCenter.getInstance().postNotificationName(updateInterfaces, UPDATE_MASK_USER_PRINT);
}
if (obj.messageOwner.from_id != UserConfig.clientUserId) {
long dialog_id;
if (obj.messageOwner.to_id.chat_id != 0) {
dialog_id = -obj.messageOwner.to_id.chat_id;
} else {
dialog_id = obj.messageOwner.to_id.user_id;
}
if (dialog_id != openned_dialog_id || ApplicationLoader.lastPauseTime != 0 || !ApplicationLoader.isScreenOn) {
showInAppNotification(obj);
}
}
updateInterfaceWithMessages(updates.from_id, objArr);
NotificationCenter.getInstance().postNotificationName(dialogsNeedReload);
if (missingData) {
needGetDiff = true;
} else {
if (MessagesStorage.lastSeqValue + 1 == updates.seq && !gettingDifference) {
TLRPC.TL_message message = new TLRPC.TL_message();
message.from_id = updates.from_id;
message.id = updates.id;
message.to_id = new TLRPC.TL_peerUser();
message.to_id.user_id = updates.from_id;
message.message = updates.message;
message.date = updates.date;
message.unread = true;
message.media = new TLRPC.TL_messageMediaEmpty();
MessagesStorage.lastSeqValue = updates.seq;
MessagesStorage.lastPtsValue = updates.pts;
MessagesStorage.lastDateValue = updates.date;
final MessageObject obj = new MessageObject(message, null);
final ArrayList<MessageObject> objArr = new ArrayList<MessageObject>();
objArr.add(obj);
ArrayList<TLRPC.Message> arr = new ArrayList<TLRPC.Message>();
arr.add(message);
final boolean printUpdate = updatePrintingUsersWithNewMessages(updates.from_id, objArr);
if (printUpdate) {
updatePrintingStrings();
}
});
MessagesStorage.getInstance().putMessages(arr, false, true);
} else if (!missingData && MessagesStorage.lastSeqValue != updates.seq) {
FileLog.e("tmessages", "need get diff TL_updateShortMessage, seq: " + MessagesStorage.lastSeqValue + " " + updates.seq);
if (gettingDifference || updatesStartWaitTime == 0 || updatesStartWaitTime != 0 && updatesStartWaitTime + 1500 > System.currentTimeMillis()) {
if (updatesStartWaitTime == 0) {
updatesStartWaitTime = System.currentTimeMillis();
Utilities.RunOnUIThread(new Runnable() {
@Override
public void run() {
if (printUpdate) {
NotificationCenter.getInstance().postNotificationName(updateInterfaces, UPDATE_MASK_USER_PRINT);
}
if (obj.messageOwner.from_id != UserConfig.clientUserId) {
long dialog_id;
if (obj.messageOwner.to_id.chat_id != 0) {
dialog_id = -obj.messageOwner.to_id.chat_id;
} else {
dialog_id = obj.messageOwner.to_id.user_id;
}
if (dialog_id != openned_dialog_id || ApplicationLoader.lastPauseTime != 0 || !ApplicationLoader.isScreenOn) {
showInAppNotification(obj);
}
}
updateInterfaceWithMessages(updates.from_id, objArr);
NotificationCenter.getInstance().postNotificationName(dialogsNeedReload);
}
});
MessagesStorage.getInstance().putMessages(arr, false, true);
} else if (MessagesStorage.lastSeqValue != updates.seq) {
FileLog.e("tmessages", "need get diff TL_updateShortMessage, seq: " + MessagesStorage.lastSeqValue + " " + updates.seq);
if (gettingDifference || updatesStartWaitTime == 0 || updatesStartWaitTime != 0 && updatesStartWaitTime + 1500 > System.currentTimeMillis()) {
if (updatesStartWaitTime == 0) {
updatesStartWaitTime = System.currentTimeMillis();
}
FileLog.e("tmessages", "add TL_updateShortMessage to queue");
updatesQueue.add(updates);
addedToQueue = true;
} else {
needGetDiff = true;
}
FileLog.e("tmessages", "add TL_updateShortMessage to queue");
updatesQueue.add(updates);
addedToQueue = true;
} else {
needGetDiff = true;
}
}
} else if (updates instanceof TLRPC.TL_updatesCombined) {
if (MessagesStorage.lastSeqValue + 1 == updates.seq_start || MessagesStorage.lastSeqValue == updates.seq_start) {
if ((MessagesStorage.lastSeqValue + 1 == updates.seq_start || MessagesStorage.lastSeqValue == updates.seq_start) && !gettingDifference) {
MessagesStorage.getInstance().putUsersAndChats(updates.users, updates.chats, true, true);
int lastPtsValue = MessagesStorage.lastPtsValue;
int lastQtsValue = MessagesStorage.lastQtsValue;
@ -3526,7 +3534,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}
}
} else if (updates instanceof TLRPC.TL_updates) {
if (MessagesStorage.lastSeqValue + 1 == updates.seq || updates.seq == 0 || updates.seq == MessagesStorage.lastSeqValue) {
if ((MessagesStorage.lastSeqValue + 1 == updates.seq || updates.seq == 0 || updates.seq == MessagesStorage.lastSeqValue) && !gettingDifference) {
MessagesStorage.getInstance().putUsersAndChats(updates.users, updates.chats, true, true);
int lastPtsValue = MessagesStorage.lastPtsValue;
int lastQtsValue = MessagesStorage.lastQtsValue;

View File

@ -34,7 +34,7 @@ public class NativeLoader {
return;
}
if (Build.VERSION.SDK_INT > 10) {
if (Build.VERSION.SDK_INT >= 9) {
try {
String folder = null;
long libSize = 0;

View File

@ -119,6 +119,25 @@ public class SerializedData extends AbsSerializedData {
}
}
public void writeByteBuffer(ByteBufferDesc buffer) {
if (!justCalc) {
//TODO ?
} else {
int l = buffer.limit();
if (l <= 253) {
len += 1;
} else {
len += 4;
}
len += l;
int i = l <= 253 ? 1 : 4;
while((l + i) % 4 != 0) {
len += 1;
i++;
}
}
}
public int readInt32() {
return readInt32(null);
}

View File

@ -7360,31 +7360,6 @@ public class TLRPC {
}
}
public static class TL_upload_saveFilePart extends TLObject {
public static int constructor = 0xb304a621;
public long file_id;
public int file_part;
public byte[] bytes;
public Class responseClass () {
return Bool.class;
}
public void readParams(AbsSerializedData stream) {
file_id = stream.readInt64();
file_part = stream.readInt32();
bytes = stream.readByteArray();
}
public void serializeToStream(AbsSerializedData stream) {
stream.writeInt32(constructor);
stream.writeInt64(file_id);
stream.writeInt32(file_part);
stream.writeByteArray(bytes);
}
}
public static class TL_upload_getFile extends TLObject {
public static int constructor = 0xe3a6cfb5;
@ -8111,34 +8086,6 @@ public class TLRPC {
}
}
public static class TL_upload_saveBigFilePart extends TLObject {
public static int constructor = 0xde7b673d;
public long file_id;
public int file_part;
public int file_total_parts;
public byte[] bytes;
public Class responseClass () {
return Bool.class;
}
public void readParams(AbsSerializedData stream) {
file_id = stream.readInt64();
file_part = stream.readInt32();
file_total_parts = stream.readInt32();
bytes = stream.readByteArray();
}
public void serializeToStream(AbsSerializedData stream) {
stream.writeInt32(constructor);
stream.writeInt64(file_id);
stream.writeInt32(file_part);
stream.writeInt32(file_total_parts);
stream.writeByteArray(bytes);
}
}
//manually created
public static class UserStatus extends TLObject {
@ -9162,4 +9109,60 @@ public class TLRPC {
}
}
}
public static class TL_upload_saveBigFilePart extends TLObject {
public static int constructor = 0xde7b673d;
public long file_id;
public int file_part;
public int file_total_parts;
public ByteBufferDesc bytes;
public Class responseClass () {
return Bool.class;
}
public void serializeToStream(AbsSerializedData stream) {
stream.writeInt32(constructor);
stream.writeInt64(file_id);
stream.writeInt32(file_part);
stream.writeInt32(file_total_parts);
stream.writeByteBuffer(bytes);
}
@Override
public void freeResources() {
if (bytes != null) {
BuffersStorage.getInstance().reuseFreeBuffer(bytes);
bytes = null;
}
}
}
public static class TL_upload_saveFilePart extends TLObject {
public static int constructor = 0xb304a621;
public long file_id;
public int file_part;
public ByteBufferDesc bytes;
public Class responseClass () {
return Bool.class;
}
public void serializeToStream(AbsSerializedData stream) {
stream.writeInt32(constructor);
stream.writeInt64(file_id);
stream.writeInt32(file_part);
stream.writeByteBuffer(bytes);
}
@Override
public void freeResources() {
if (bytes != null) {
BuffersStorage.getInstance().reuseFreeBuffer(bytes);
bytes = null;
}
}
}
}

View File

@ -271,7 +271,10 @@ public class TcpConnection extends PyroClientAdapter {
connect();
}
public void sendData(final byte[] data, final boolean reportAck, final boolean startResponseTimeout) {
public void sendData(final byte[] data, final ByteBufferDesc buff, final boolean reportAck, final boolean startResponseTimeout) {
if (data == null && buff == null) {
return;
}
selector.scheduleTask(new Runnable() {
@Override
public void run() {
@ -285,9 +288,28 @@ public class TcpConnection extends PyroClientAdapter {
return;
}
int packetLength = data.length / 4;
int bufferLen = 0;
if (data != null) {
bufferLen = data.length;
} else if (buff != null) {
bufferLen = buff.limit();
}
int packetLength = bufferLen / 4;
SerializedData buffer = new SerializedData();
if (packetLength < 0x7f) {
bufferLen++;
} else {
bufferLen += 4;
}
if (firstPacket) {
bufferLen++;
}
ByteBufferDesc buffer = BuffersStorage.getInstance().getFreeBuffer(bufferLen);
if (firstPacket) {
buffer.writeByte((byte)0xef);
firstPacket = false;
}
if (packetLength < 0x7f) {
if (reportAck) {
packetLength |= (1 << 7);
@ -300,20 +322,16 @@ public class TcpConnection extends PyroClientAdapter {
}
buffer.writeInt32(packetLength);
}
buffer.writeRaw(data);
final byte[] packet = buffer.toByteArray();
ByteBuffer sendBuffer = ByteBuffer.allocate((firstPacket ? 1 : 0) + packet.length);
sendBuffer.rewind();
sendBuffer.order(ByteOrder.LITTLE_ENDIAN);
if (firstPacket) {
sendBuffer.put((byte)0xef);
firstPacket = false;
if (data != null) {
buffer.writeRaw(data);
} else {
buffer.writeRaw(buff);
BuffersStorage.getInstance().reuseFreeBuffer(buff);
}
sendBuffer.put(packet);
sendBuffer.rewind();
client.write(sendBuffer);
buffer.rewind();
client.write(buffer);
}
});
}

View File

@ -77,7 +77,7 @@ public class MessageObject {
fromUser = MessagesController.getInstance().users.get(message.from_id);
}
if (message.action instanceof TLRPC.TL_messageActionChatCreate) {
if (message.from_id == UserConfig.clientUserId) {
if (isFromMe()) {
messageText = LocaleController.getString("ActionYouCreateGroup", R.string.ActionYouCreateGroup);
} else {
if (fromUser != null) {
@ -88,7 +88,7 @@ public class MessageObject {
}
} else if (message.action instanceof TLRPC.TL_messageActionChatDeleteUser) {
if (message.action.user_id == message.from_id) {
if (message.from_id == UserConfig.clientUserId) {
if (isFromMe()) {
messageText = LocaleController.getString("ActionYouLeftUser", R.string.ActionYouLeftUser);
} else {
if (fromUser != null) {
@ -103,7 +103,7 @@ public class MessageObject {
MessagesController.getInstance().users.get(message.action.user_id);
}
if (who != null && fromUser != null) {
if (message.from_id == UserConfig.clientUserId) {
if (isFromMe()) {
messageText = LocaleController.getString("ActionYouKickUser", R.string.ActionYouKickUser).replace("un2", Utilities.formatName(who.first_name, who.last_name));
} else if (message.action.user_id == UserConfig.clientUserId) {
messageText = LocaleController.getString("ActionKickUserYou", R.string.ActionKickUserYou).replace("un1", Utilities.formatName(fromUser.first_name, fromUser.last_name));
@ -120,7 +120,7 @@ public class MessageObject {
MessagesController.getInstance().users.get(message.action.user_id);
}
if (whoUser != null && fromUser != null) {
if (message.from_id == UserConfig.clientUserId) {
if (isFromMe()) {
messageText = LocaleController.getString("ActionYouAddUser", R.string.ActionYouAddUser).replace("un2", Utilities.formatName(whoUser.first_name, whoUser.last_name));
} else if (message.action.user_id == UserConfig.clientUserId) {
messageText = LocaleController.getString("ActionAddUserYou", R.string.ActionAddUserYou).replace("un1", Utilities.formatName(fromUser.first_name, fromUser.last_name));
@ -135,7 +135,7 @@ public class MessageObject {
for (TLRPC.PhotoSize size : message.action.photo.sizes) {
photoThumbs.add(new PhotoObject(size));
}
if (message.from_id == UserConfig.clientUserId) {
if (isFromMe()) {
messageText = LocaleController.getString("ActionYouChangedPhoto", R.string.ActionYouChangedPhoto);
} else {
if (fromUser != null) {
@ -145,7 +145,7 @@ public class MessageObject {
}
}
} else if (message.action instanceof TLRPC.TL_messageActionChatEditTitle) {
if (message.from_id == UserConfig.clientUserId) {
if (isFromMe()) {
messageText = LocaleController.getString("ActionYouChangedTitle", R.string.ActionYouChangedTitle).replace("un2", message.action.title);
} else {
if (fromUser != null) {
@ -155,7 +155,7 @@ public class MessageObject {
}
}
} else if (message.action instanceof TLRPC.TL_messageActionChatDeletePhoto) {
if (message.from_id == UserConfig.clientUserId) {
if (isFromMe()) {
messageText = LocaleController.getString("ActionYouRemovedPhoto", R.string.ActionYouRemovedPhoto);
} else {
if (fromUser != null) {
@ -182,7 +182,7 @@ public class MessageObject {
} else {
timeString = String.format("%d", message.action.ttl);
}
if (message.from_id == UserConfig.clientUserId) {
if (isFromMe()) {
messageText = LocaleController.formatString("MessageLifetimeChangedOutgoing", R.string.MessageLifetimeChangedOutgoing, timeString);
} else {
if (fromUser != null) {
@ -192,7 +192,7 @@ public class MessageObject {
}
}
} else {
if (message.from_id == UserConfig.clientUserId) {
if (isFromMe()) {
messageText = LocaleController.getString("MessageLifetimeYouRemoved", R.string.MessageLifetimeYouRemoved);
} else {
if (fromUser != null) {
@ -265,22 +265,18 @@ public class MessageObject {
} else if (message.media != null && message.media instanceof TLRPC.TL_messageMediaPhoto) {
contentType = type = 1;
} else if (message.media != null && message.media instanceof TLRPC.TL_messageMediaGeo) {
if (message.from_id == UserConfig.clientUserId) {
contentType = type = 4;
} else {
contentType = type = 5;
}
contentType = 1;
type = 4;
} else if (message.media != null && message.media instanceof TLRPC.TL_messageMediaVideo) {
if (message.from_id == UserConfig.clientUserId) {
contentType = type = 6;
} else {
contentType = type = 7;
}
contentType = 1;
type = 3;
} else if (message.media != null && message.media instanceof TLRPC.TL_messageMediaContact) {
if (message.from_id == UserConfig.clientUserId) {
contentType = type = 12;
if (isFromMe()) {
contentType = 4;
type = 12;
} else {
contentType = type = 13;
contentType = 5;
type = 13;
}
} else if (message.media != null && message.media instanceof TLRPC.TL_messageMediaUnsupported) {
contentType = type = 0;
@ -289,7 +285,7 @@ public class MessageObject {
contentType = 1;
type = 8;
} else {
if (message.from_id == UserConfig.clientUserId) {
if (isFromMe()) {
contentType = type = 8;
} else {
contentType = type = 9;
@ -525,4 +521,12 @@ public class MessageObject {
linesOffset += currentBlockLinesCount;
}
}
public boolean isOut() {
return messageOwner.out;
}
public boolean isFromMe() {
return messageOwner.from_id == UserConfig.clientUserId;
}
}

View File

@ -37,6 +37,9 @@ public class PhotoObject {
}
public static PhotoObject getClosestImageWithSize(ArrayList<PhotoObject> arr, int width, int height) {
if (arr == null) {
return null;
}
int closestWidth = 9999;
int closestHeight = 9999;
PhotoObject closestObject = null;
@ -56,6 +59,9 @@ public class PhotoObject {
}
public static TLRPC.PhotoSize getClosestPhotoSizeWithSize(ArrayList<TLRPC.PhotoSize> sizes, int width, int height) {
if (sizes == null) {
return null;
}
int closestWidth = 9999;
int closestHeight = 9999;
TLRPC.PhotoSize closestObject = null;

View File

@ -298,7 +298,7 @@ public class ChatAudioCell extends ChatBaseCell implements SeekBar.SeekBarDelega
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
if (currentMessageObject.messageOwner.out) {
if (currentMessageObject.isOut()) {
avatarImage.imageX = layoutWidth - backgroundWidth + Utilities.dp(9);
seekBarX = layoutWidth - backgroundWidth + Utilities.dp(97);
buttonX = layoutWidth - backgroundWidth + Utilities.dp(67);
@ -359,7 +359,7 @@ public class ChatAudioCell extends ChatBaseCell implements SeekBar.SeekBarDelega
avatarImage.setImage((TLRPC.FileLocation)null, "50_50", getResources().getDrawable(Utilities.getUserAvatarForId(uid)));
}
if (messageObject.messageOwner.out) {
if (messageObject.isOut()) {
seekBar.type = 0;
progressView.setProgressColors(0xffb4e396, 0xff6ac453);
} else {
@ -393,7 +393,7 @@ public class ChatAudioCell extends ChatBaseCell implements SeekBar.SeekBarDelega
canvas.restore();
int state = buttonState;
if (!currentMessageObject.messageOwner.out) {
if (!currentMessageObject.isOut()) {
state += 4;
timePaint.setColor(0xffa1aab3);
} else {

View File

@ -38,7 +38,7 @@ public class ChatBaseCell extends BaseCell {
public static interface ChatBaseCellDelegate {
public abstract void didPressedUserAvatar(ChatBaseCell cell, TLRPC.User user);
public abstract void didPressedCanceSendButton(ChatBaseCell cell);
public abstract void didPressedCancelSendButton(ChatBaseCell cell);
public abstract void didLongPressed(ChatBaseCell cell);
public abstract boolean canPerformActions();
public boolean onSwipeLeft();
@ -246,7 +246,7 @@ public class ChatBaseCell extends BaseCell {
}
String newNameString = null;
if (drawName && isChat && newUser != null && !currentMessageObject.messageOwner.out) {
if (drawName && isChat && newUser != null && !currentMessageObject.isOut()) {
newNameString = Utilities.formatName(newUser.first_name, newUser.last_name);
}
@ -276,7 +276,7 @@ public class ChatBaseCell extends BaseCell {
}
currentUser = MessagesController.getInstance().users.get(messageObject.messageOwner.from_id);
if (isChat && !messageObject.messageOwner.out) {
if (isChat && !messageObject.isOut()) {
isAvatarVisible = true;
if (currentUser != null) {
if (currentUser.photo != null) {
@ -289,7 +289,7 @@ public class ChatBaseCell extends BaseCell {
}
if (!media) {
if (currentMessageObject.messageOwner.out) {
if (currentMessageObject.isOut()) {
currentTimePaint = timePaintOut;
} else {
currentTimePaint = timePaintIn;
@ -303,7 +303,7 @@ public class ChatBaseCell extends BaseCell {
namesOffset = 0;
if (drawName && isChat && currentUser != null && !currentMessageObject.messageOwner.out) {
if (drawName && isChat && currentUser != null && !currentMessageObject.isOut()) {
currentNameString = Utilities.formatName(currentUser.first_name, currentUser.last_name);
nameWidth = getMaxNameWidth();
@ -457,13 +457,13 @@ public class ChatBaseCell extends BaseCell {
timeLayout = new StaticLayout(currentTimeString, currentTimePaint, timeWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
if (!media) {
if (!currentMessageObject.messageOwner.out) {
if (!currentMessageObject.isOut()) {
timeX = backgroundWidth - Utilities.dp(9) - timeWidth + (isChat ? Utilities.dp(52) : 0);
} else {
timeX = layoutWidth - timeWidth - Utilities.dpf(38.5f);
}
} else {
if (!currentMessageObject.messageOwner.out) {
if (!currentMessageObject.isOut()) {
timeX = backgroundWidth - Utilities.dp(4) - timeWidth + (isChat ? Utilities.dp(52) : 0);
} else {
timeX = layoutWidth - timeWidth - Utilities.dpf(42.0f);
@ -502,7 +502,7 @@ public class ChatBaseCell extends BaseCell {
}
Drawable currentBackgroundDrawable = null;
if (currentMessageObject.messageOwner.out) {
if (currentMessageObject.isOut()) {
if (isPressed() && isCheckPressed || !isCheckPressed && isPressed) {
if (!media) {
currentBackgroundDrawable = backgroundDrawableOutSelected;
@ -551,7 +551,7 @@ public class ChatBaseCell extends BaseCell {
if (drawForwardedName && forwardedNameLayout != null) {
canvas.save();
if (currentMessageObject.messageOwner.out) {
if (currentMessageObject.isOut()) {
forwardNamePaint.setColor(0xff4a923c);
forwardNameX = currentBackgroundDrawable.getBounds().left + Utilities.dp(10);
forwardNameY = Utilities.dp(10 + (drawName ? 18 : 0));
@ -566,7 +566,7 @@ public class ChatBaseCell extends BaseCell {
}
if (media) {
setDrawableBounds(mediaBackgroundDrawable, timeX - Utilities.dp(3), layoutHeight - Utilities.dpf(27.5f), timeWidth + Utilities.dp(6 + (currentMessageObject.messageOwner.out ? 20 : 0)), Utilities.dpf(16.5f));
setDrawableBounds(mediaBackgroundDrawable, timeX - Utilities.dp(3), layoutHeight - Utilities.dpf(27.5f), timeWidth + Utilities.dp(6 + (currentMessageObject.isOut() ? 20 : 0)), Utilities.dpf(16.5f));
mediaBackgroundDrawable.draw(canvas);
canvas.save();
@ -580,7 +580,7 @@ public class ChatBaseCell extends BaseCell {
canvas.restore();
}
if (currentMessageObject.messageOwner.out) {
if (currentMessageObject.isOut()) {
boolean drawCheck1 = false;
boolean drawCheck2 = false;
boolean drawClock = false;

View File

@ -43,8 +43,10 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
private static Drawable placeholderInDrawable;
private static Drawable placeholderOutDrawable;
private static Drawable[][] buttonStatesDrawables = new Drawable[3][2];
private static Drawable videoIconDrawable;
private static Drawable[][] buttonStatesDrawables = new Drawable[4][2];
private static TextPaint infoPaint;
private static MessageObject lastDownloadedGifMessage = null;
private GifDrawable gifDrawable = null;
@ -66,7 +68,8 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
private int buttonY;
private StaticLayout infoLayout;
protected int infoWidth;
private int infoWidth;
private int infoOffset = 0;
private String currentInfoString;
public ChatMediaCellDelegate mediaDelegate = null;
@ -83,6 +86,9 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
buttonStatesDrawables[1][1] = getResources().getDrawable(R.drawable.photocancel_pressed);
buttonStatesDrawables[2][0] = getResources().getDrawable(R.drawable.photogif);
buttonStatesDrawables[2][1] = getResources().getDrawable(R.drawable.photogif_pressed);
buttonStatesDrawables[3][0] = getResources().getDrawable(R.drawable.playvideo);
buttonStatesDrawables[3][1] = getResources().getDrawable(R.drawable.playvideo_pressed);
videoIconDrawable = getResources().getDrawable(R.drawable.ic_video);
infoPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
infoPaint.setColor(0xffffffff);
@ -187,10 +193,8 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
private void didPressedImage() {
if (currentMessageObject.type == 1) {
if (buttonState == -1) {
if (currentMessageObject.type == 1) {
if (mediaDelegate != null) {
mediaDelegate.didPressedImage(this);
}
if (mediaDelegate != null) {
mediaDelegate.didPressedImage(this);
}
} else if (buttonState == 0) {
didPressedButton();
@ -205,6 +209,14 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
} else if (buttonState == 2 || buttonState == 0) {
didPressedButton();
}
} else if (currentMessageObject.type == 3) {
if (buttonState == 0 || buttonState == 3) {
didPressedButton();
}
} else if (currentMessageObject.type == 4) {
if (mediaDelegate != null) {
mediaDelegate.didPressedImage(this);
}
}
}
@ -214,24 +226,32 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
if (currentMessageObject.imagePreview != null) {
photoImage.setImage(currentPhotoObject.photoOwner.location, currentPhotoFilter, new BitmapDrawable(currentMessageObject.imagePreview), currentPhotoObject.photoOwner.size);
} else {
photoImage.setImage(currentPhotoObject.photoOwner.location, currentPhotoFilter, currentMessageObject.messageOwner.out ? placeholderOutDrawable : placeholderInDrawable, currentPhotoObject.photoOwner.size);
photoImage.setImage(currentPhotoObject.photoOwner.location, currentPhotoFilter, currentMessageObject.isOut() ? placeholderOutDrawable : placeholderInDrawable, currentPhotoObject.photoOwner.size);
}
} else if (currentMessageObject.type == 8) {
FileLoader.getInstance().loadFile(null, null, currentMessageObject.messageOwner.media.document, null);
lastDownloadedGifMessage = currentMessageObject;
} else if (currentMessageObject.type == 3) {
FileLoader.getInstance().loadFile(currentMessageObject.messageOwner.media.video, null, null, null);
}
progressVisible = true;
buttonState = 1;
invalidate();
} else if (buttonState == 1) {
if (currentMessageObject.messageOwner.out && currentMessageObject.messageOwner.send_state == MessagesController.MESSAGE_SEND_STATE_SENDING) {
if (currentMessageObject.isOut() && currentMessageObject.messageOwner.send_state == MessagesController.MESSAGE_SEND_STATE_SENDING) {
if (delegate != null) {
delegate.didPressedCanceSendButton(this);
delegate.didPressedCancelSendButton(this);
}
} else {
if (currentMessageObject.type == 1) {
FileLoader.getInstance().cancelLoadingForImageView(photoImage);
} else if (currentMessageObject.type == 8) {
FileLoader.getInstance().cancelLoadFile(null, null, currentMessageObject.messageOwner.media.document, null);
if (lastDownloadedGifMessage.messageOwner.id == currentMessageObject.messageOwner.id) {
lastDownloadedGifMessage = null;
}
} else if (currentMessageObject.type == 3) {
FileLoader.getInstance().cancelLoadFile(currentMessageObject.messageOwner.media.video, null, null, null);
}
progressVisible = false;
buttonState = 0;
@ -247,6 +267,10 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
buttonState = -1;
invalidate();
}
} else if (buttonState == 3) {
if (mediaDelegate != null) {
mediaDelegate.didPressedImage(this);
}
}
}
@ -270,6 +294,18 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
String str = Utilities.formatFileSize(messageObject.messageOwner.media.document.size);
if (currentInfoString == null || !currentInfoString.equals(str)) {
currentInfoString = str;
infoOffset = 0;
infoWidth = (int) Math.ceil(infoPaint.measureText(currentInfoString));
infoLayout = new StaticLayout(currentInfoString, infoPaint, infoWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
}
} else if (messageObject.type == 3) {
int duration = messageObject.messageOwner.media.video.duration;
int minutes = duration / 60;
int seconds = duration - minutes * 60;
String str = String.format("%d:%02d, %s", minutes, seconds, Utilities.formatFileSize(messageObject.messageOwner.media.video.size));
if (currentInfoString == null || !currentInfoString.equals(str)) {
currentInfoString = str;
infoOffset = videoIconDrawable.getIntrinsicWidth() + Utilities.dp(4);
infoWidth = (int) Math.ceil(infoPaint.measureText(currentInfoString));
infoLayout = new StaticLayout(currentInfoString, infoPaint, infoWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
}
@ -278,81 +314,83 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
infoLayout = null;
}
photoWidth = (int) (Math.min(Utilities.displaySize.x, Utilities.displaySize.y) * 0.7f);
photoHeight = photoWidth + Utilities.dp(100);
if (messageObject.type == 6 || messageObject.type == 7) {
photoWidth = (int) (Math.min(Utilities.displaySize.x, Utilities.displaySize.y) / 2.5f);
photoHeight = photoWidth + 100;
}
if (photoWidth > 800) {
photoWidth = 800;
}
if (photoHeight > 800) {
photoHeight = 800;
}
if (messageObject.type == 4) {
photoWidth = Utilities.dp(100);
photoHeight = Utilities.dp(100);
backgroundWidth = photoWidth + Utilities.dp(12);
currentPhotoObject = PhotoObject.getClosestImageWithSize(messageObject.photoThumbs, photoWidth, photoHeight);
if (currentPhotoObject != null) {
float scale = (float) currentPhotoObject.photoOwner.w / (float) photoWidth;
int w = (int) (currentPhotoObject.photoOwner.w / scale);
int h = (int) (currentPhotoObject.photoOwner.h / scale);
if (h > photoHeight) {
float scale2 = h;
h = photoHeight;
scale2 /= h;
w = (int) (w / scale2);
} else if (h < Utilities.dp(120)) {
h = Utilities.dp(120);
float hScale = (float) currentPhotoObject.photoOwner.h / h;
if (currentPhotoObject.photoOwner.w / hScale < photoWidth) {
w = (int) (currentPhotoObject.photoOwner.w / hScale);
}
}
photoWidth = w;
photoHeight = h;
backgroundWidth = w + Utilities.dp(12);
currentPhotoFilter = String.format(Locale.US, "%d_%d", (int) (w / Utilities.density), (int) (h / Utilities.density));
if (currentPhotoObject.image != null) {
photoImage.setImageBitmap(currentPhotoObject.image);
} else {
boolean photoExist = true;
String fileName = MessageObject.getAttachFileName(currentPhotoObject.photoOwner);
if (messageObject.type == 1) {
File cacheFile = new File(Utilities.getCacheDir(), fileName);
if (!cacheFile.exists()) {
photoExist = false;
} else {
MediaController.getInstance().removeLoadingFileObserver(this);
}
}
if (photoExist || downloadPhotos) {
if (messageObject.imagePreview != null) {
photoImage.setImage(currentPhotoObject.photoOwner.location, currentPhotoFilter, new BitmapDrawable(messageObject.imagePreview), currentPhotoObject.photoOwner.size);
} else {
photoImage.setImage(currentPhotoObject.photoOwner.location, currentPhotoFilter, messageObject.messageOwner.out ? placeholderOutDrawable : placeholderInDrawable, currentPhotoObject.photoOwner.size);
}
} else {
if (messageObject.imagePreview != null) {
photoImage.setImageBitmap(messageObject.imagePreview);
} else {
photoImage.setImageBitmap(messageObject.messageOwner.out ? placeholderOutDrawable : placeholderInDrawable);
}
}
}
double lat = messageObject.messageOwner.media.geo.lat;
double lon = messageObject.messageOwner.media.geo._long;
String url = String.format(Locale.US, "https://maps.googleapis.com/maps/api/staticmap?center=%f,%f&zoom=13&size=100x100&maptype=roadmap&scale=%d&markers=color:red|size:big|%f,%f&sensor=false", lat, lon, Math.min(2, (int)Math.ceil(Utilities.density)), lat, lon);
photoImage.setImage(url, null, messageObject.isOut() ? placeholderOutDrawable : placeholderInDrawable);
} else {
photoImage.setImageBitmap(messageObject.messageOwner.out ? placeholderOutDrawable : placeholderInDrawable);
photoWidth = (int) (Math.min(Utilities.displaySize.x, Utilities.displaySize.y) * 0.7f);
photoHeight = photoWidth + Utilities.dp(100);
if (photoWidth > 800) {
photoWidth = 800;
}
if (photoHeight > 800) {
photoHeight = 800;
}
currentPhotoObject = PhotoObject.getClosestImageWithSize(messageObject.photoThumbs, photoWidth, photoHeight);
if (currentPhotoObject != null) {
float scale = (float) currentPhotoObject.photoOwner.w / (float) photoWidth;
int w = (int) (currentPhotoObject.photoOwner.w / scale);
int h = (int) (currentPhotoObject.photoOwner.h / scale);
if (h > photoHeight) {
float scale2 = h;
h = photoHeight;
scale2 /= h;
w = (int) (w / scale2);
} else if (h < Utilities.dp(120)) {
h = Utilities.dp(120);
float hScale = (float) currentPhotoObject.photoOwner.h / h;
if (currentPhotoObject.photoOwner.w / hScale < photoWidth) {
w = (int) (currentPhotoObject.photoOwner.w / hScale);
}
}
photoWidth = w;
photoHeight = h;
backgroundWidth = w + Utilities.dp(12);
currentPhotoFilter = String.format(Locale.US, "%d_%d", (int) (w / Utilities.density), (int) (h / Utilities.density));
if (currentPhotoObject.image != null) {
photoImage.setImageBitmap(currentPhotoObject.image);
} else {
boolean photoExist = true;
String fileName = MessageObject.getAttachFileName(currentPhotoObject.photoOwner);
if (messageObject.type == 1) {
File cacheFile = new File(Utilities.getCacheDir(), fileName);
if (!cacheFile.exists()) {
photoExist = false;
} else {
MediaController.getInstance().removeLoadingFileObserver(this);
}
}
if (photoExist || downloadPhotos) {
if (messageObject.imagePreview != null) {
photoImage.setImage(currentPhotoObject.photoOwner.location, currentPhotoFilter, new BitmapDrawable(messageObject.imagePreview), currentPhotoObject.photoOwner.size);
} else {
photoImage.setImage(currentPhotoObject.photoOwner.location, currentPhotoFilter, messageObject.isOut() ? placeholderOutDrawable : placeholderInDrawable, currentPhotoObject.photoOwner.size);
}
} else {
if (messageObject.imagePreview != null) {
photoImage.setImageBitmap(messageObject.imagePreview);
} else {
photoImage.setImageBitmap(messageObject.isOut() ? placeholderOutDrawable : placeholderInDrawable);
}
}
}
} else {
photoImage.setImageBitmap(messageObject.isOut() ? placeholderOutDrawable : placeholderInDrawable);
}
}
invalidate();
/*if ((type == 6 || type == 7) && videoTimeText != null) {
int duration = message.messageOwner.media.video.duration;
int minutes = duration / 60;
int seconds = duration - minutes * 60;
videoTimeText.setText(String.format("%d:%02d", minutes, seconds));
}*/
}
updateButtonState();
}
@ -366,7 +404,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
}
fileName = MessageObject.getAttachFileName(currentPhotoObject.photoOwner);
cacheFile = new File(Utilities.getCacheDir(), fileName);
} else if (currentMessageObject.type == 8) {
} else if (currentMessageObject.type == 8 || currentMessageObject.type == 3) {
if (currentMessageObject.messageOwner.attachPath != null && currentMessageObject.messageOwner.attachPath.length() != 0) {
File f = new File(currentMessageObject.messageOwner.attachPath);
if (f.exists()) {
@ -381,7 +419,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
if (fileName == null) {
return;
}
if (currentMessageObject.messageOwner.out && currentMessageObject.messageOwner.send_state == MessagesController.MESSAGE_SEND_STATE_SENDING) {
if (currentMessageObject.isOut() && currentMessageObject.messageOwner.send_state == MessagesController.MESSAGE_SEND_STATE_SENDING) {
if (currentMessageObject.messageOwner.attachPath != null) {
MediaController.getInstance().addLoadingFileObserver(currentMessageObject.messageOwner.attachPath, this);
progressVisible = true;
@ -430,6 +468,8 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
progressVisible = false;
if (currentMessageObject.type == 8 && (gifDrawable == null || gifDrawable != null && !gifDrawable.isRunning())) {
buttonState = 2;
} else if (currentMessageObject.type == 3) {
buttonState = 3;
} else {
buttonState = -1;
}
@ -447,7 +487,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
if (currentMessageObject.messageOwner.out) {
if (currentMessageObject.isOut()) {
photoImage.imageX = layoutWidth - backgroundWidth - Utilities.dp(3);
} else {
if (isChat) {
@ -490,18 +530,23 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
canvas.restore();
}
if (buttonState >= 0 && buttonState < 3) {
if (buttonState >= 0 && buttonState < 4) {
Drawable currentButtonDrawable = buttonStatesDrawables[buttonState][buttonPressed];
setDrawableBounds(currentButtonDrawable, buttonX, buttonY);
currentButtonDrawable.draw(canvas);
}
if (infoLayout != null && (buttonState == 1 || buttonState == 0)) {
setDrawableBounds(mediaBackgroundDrawable, photoImage.imageX + Utilities.dp(4), photoImage.imageY + Utilities.dp(4), infoWidth + Utilities.dp(8), Utilities.dpf(16.5f));
if (infoLayout != null && (buttonState == 1 || buttonState == 0 || buttonState == 3)) {
setDrawableBounds(mediaBackgroundDrawable, photoImage.imageX + Utilities.dp(4), photoImage.imageY + Utilities.dp(4), infoWidth + Utilities.dp(8) + infoOffset, Utilities.dpf(16.5f));
mediaBackgroundDrawable.draw(canvas);
if (currentMessageObject.type == 3) {
setDrawableBounds(videoIconDrawable, photoImage.imageX + Utilities.dp(8), photoImage.imageY + Utilities.dpf(7.5f));
videoIconDrawable.draw(canvas);
}
canvas.save();
canvas.translate(photoImage.imageX + Utilities.dp(8), photoImage.imageY + Utilities.dpf(5.5f));
canvas.translate(photoImage.imageX + Utilities.dp(8) + infoOffset, photoImage.imageY + Utilities.dpf(5.5f));
infoLayout.draw(canvas);
canvas.restore();
}
@ -515,6 +560,9 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
@Override
public void onSuccessDownload(String fileName) {
updateButtonState();
if (currentMessageObject.type == 8 && lastDownloadedGifMessage != null && lastDownloadedGifMessage.messageOwner.id == currentMessageObject.messageOwner.id && buttonState == 2) {
didPressedButton();
}
}
@Override

View File

@ -131,7 +131,7 @@ public class ChatMessageCell extends ChatBaseCell {
}
pressedLink = null;
int maxWidth;
if (isChat && !messageObject.messageOwner.out) {
if (isChat && !messageObject.isOut()) {
maxWidth = Utilities.displaySize.x - Utilities.dp(122);
drawName = true;
} else {
@ -149,7 +149,7 @@ public class ChatMessageCell extends ChatBaseCell {
maxChildWidth = Math.max(maxChildWidth, forwardedNameWidth);
int timeMore = timeWidth + Utilities.dp(6);
if (messageObject.messageOwner.out) {
if (messageObject.isOut()) {
timeMore += Utilities.dpf(20.5f);
}
@ -176,7 +176,7 @@ public class ChatMessageCell extends ChatBaseCell {
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
if (currentMessageObject.messageOwner.out) {
if (currentMessageObject.isOut()) {
textX = layoutWidth - backgroundWidth + Utilities.dp(10);
textY = Utilities.dp(10) + namesOffset;
} else {
@ -192,7 +192,7 @@ public class ChatMessageCell extends ChatBaseCell {
return;
}
if (currentMessageObject.messageOwner.out) {
if (currentMessageObject.isOut()) {
textX = layoutWidth - backgroundWidth + Utilities.dp(10);
textY = Utilities.dp(10) + namesOffset;
} else {

View File

@ -465,7 +465,7 @@ public class DialogCell extends BaseCell {
} else {
if (chat != null) {
String name = "";
if (message.messageOwner.from_id == UserConfig.clientUserId) {
if (message.isFromMe()) {
name = LocaleController.getString("FromYou", R.string.FromYou);
} else {
if (fromUser != null) {
@ -507,7 +507,7 @@ public class DialogCell extends BaseCell {
}
}
if (message.messageOwner.from_id == UserConfig.clientUserId) {
if (message.isFromMe()) {
if (message.messageOwner.send_state == MessagesController.MESSAGE_SEND_STATE_SENDING) {
drawCheck1 = false;
drawCheck2 = false;

View File

@ -64,7 +64,6 @@ import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
@ -105,7 +104,6 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Locale;
import java.util.concurrent.Semaphore;
public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLayout.SizeNotifierRelativeLayoutDelegate, NotificationCenter.NotificationCenterDelegate, MessagesActivity.MessagesActivityDelegate, DocumentSelectActivity.DocumentSelectActivityDelegate {
@ -1230,14 +1228,14 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
private int getMessageType(MessageObject messageObject) {
if (currentEncryptedChat == null) {
if (messageObject.messageOwner.id <= 0 && messageObject.messageOwner.out) {
if (messageObject.messageOwner.id <= 0 && messageObject.isOut()) {
if (messageObject.messageOwner.send_state == MessagesController.MESSAGE_SEND_STATE_SEND_ERROR) {
return 0;
} else {
return -1;
}
} else {
if (messageObject.type == 15) {
if (messageObject.type == 7) {
return -1;
} else if (messageObject.type == 10 || messageObject.type == 11) {
if (messageObject.messageOwner.id == 0) {
@ -1279,7 +1277,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
}
}
} else {
if (messageObject.type == 15) {
if (messageObject.type == 7) {
return -1;
} else if (messageObject.messageOwner.send_state == MessagesController.MESSAGE_SEND_STATE_SEND_ERROR) {
return 0;
@ -1767,7 +1765,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
if (minDate == 0 || obj.messageOwner.date < minDate) {
minDate = obj.messageOwner.date;
}
if (!obj.messageOwner.out && obj.messageOwner.unread) {
if (!obj.isOut() && obj.messageOwner.unread) {
wasUnread = true;
}
messagesDict.put(obj.messageOwner.id, obj);
@ -1804,7 +1802,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
dateMsg.message = "";
dateMsg.id = 0;
MessageObject dateObj = new MessageObject(dateMsg, null);
dateObj.contentType = dateObj.type = 15;
dateObj.contentType = dateObj.type = 7;
boolean dateAdded = true;
if (a != messArr.size() - 1) {
MessageObject next = messArr.get(a + 1);
@ -1981,7 +1979,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
if (currentEncryptedChat != null && obj.messageOwner.action != null && obj.messageOwner.action instanceof TLRPC.TL_messageActionTTLChange && timerButton != null) {
timerButton.setTime(obj.messageOwner.action.ttl);
}
if (obj.messageOwner.out && obj.messageOwner.send_state == MessagesController.MESSAGE_SEND_STATE_SENDING) {
if (obj.isOut() && obj.messageOwner.send_state == MessagesController.MESSAGE_SEND_STATE_SENDING) {
scrollToLastMessage();
return;
}
@ -1995,7 +1993,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
currentMinMsgId = Math.min(obj.messageOwner.id, currentMinMsgId);
}
if (!obj.messageOwner.out && obj.messageOwner.unread) {
if (!obj.isOut() && obj.messageOwner.unread) {
unread_to_load++;
currentMarkAsRead = true;
}
@ -2033,11 +2031,11 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
progressBarMap.put(obj.messageOwner.attachPath, null);
}
if (obj.messageOwner.out) {
if (obj.isOut()) {
removeUnreadPlane(false);
}
if (!obj.messageOwner.out && unreadMessageObject != null) {
if (!obj.isOut() && unreadMessageObject != null) {
unread_to_load++;
}
@ -2062,7 +2060,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
dateObj.contentType = dateObj.type = 10;
messages.add(0, dateObj);
}
if (!obj.messageOwner.out && obj.messageOwner.unread) {
if (!obj.isOut() && obj.messageOwner.unread) {
obj.messageOwner.unread = false;
markAsRead = true;
}
@ -2316,9 +2314,9 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
int date = (Integer)args[1];
boolean started = false;
for (MessageObject obj : messages) {
if (!obj.messageOwner.out) {
if (!obj.isOut()) {
continue;
} else if (obj.messageOwner.out && !obj.messageOwner.unread) {
} else if (obj.isOut() && !obj.messageOwner.unread) {
break;
}
if (obj.messageOwner.date <= date) {
@ -3014,12 +3012,12 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
if (currentEncryptedChat == null) {
if (i == 0) {
String fileName = selectedObject.getFileName();
if (selectedObject.type == 6 || selectedObject.type == 7) {
MediaController.saveFile(fileName, parentActivity, 1, null);
if (selectedObject.type == 3) {
MediaController.saveFile(fileName, selectedObject.messageOwner.attachPath, parentActivity, 1, null);
} else if (selectedObject.type == 1) {
MediaController.saveFile(fileName, parentActivity, 0, null);
MediaController.saveFile(fileName, selectedObject.messageOwner.attachPath, parentActivity, 0, null);
} else if (selectedObject.type == 8 || selectedObject.type == 9) {
MediaController.saveFile(fileName, parentActivity, 2, selectedObject.messageOwner.media.document.file_name);
MediaController.saveFile(fileName, selectedObject.messageOwner.attachPath, parentActivity, 2, selectedObject.messageOwner.media.document.file_name);
}
} else if (i == 1) {
processSelectedOption(2);
@ -3037,12 +3035,12 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
if (currentEncryptedChat == null) {
if (i == 1) {
String fileName = selectedObject.getFileName();
if (selectedObject.type == 6 || selectedObject.type == 7) {
MediaController.saveFile(fileName, parentActivity, 1, null);
if (selectedObject.type == 3) {
MediaController.saveFile(fileName, selectedObject.messageOwner.attachPath, parentActivity, 1, null);
} else if (selectedObject.type == 1) {
MediaController.saveFile(fileName, parentActivity, 0, null);
MediaController.saveFile(fileName, selectedObject.messageOwner.attachPath, parentActivity, 0, null);
} else if (selectedObject.type == 8 || selectedObject.type == 9) {
MediaController.saveFile(fileName, parentActivity, 2, selectedObject.messageOwner.media.document.file_name);
MediaController.saveFile(fileName, selectedObject.messageOwner.attachPath, parentActivity, 2, selectedObject.messageOwner.media.document.file_name);
}
} else if (i == 2) {
processSelectedOption(2);
@ -3120,7 +3118,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
} else {
MessagesController.getInstance().sendMessage(selectedObject.messageOwner.message, dialog_id);
}
} else if (selectedObject.type == 4 || selectedObject.type == 5) {
} else if (selectedObject.type == 4) {
MessagesController.getInstance().sendMessage(selectedObject.messageOwner.media.geo.lat, selectedObject.messageOwner.media.geo._long, dialog_id);
} else if (selectedObject.type == 1) {
if (selectedObject.messageOwner instanceof TLRPC.TL_messageForwarded) {
@ -3129,7 +3127,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
TLRPC.TL_photo photo = (TLRPC.TL_photo)selectedObject.messageOwner.media.photo;
MessagesController.getInstance().sendMessage(photo, dialog_id);
}
} else if (selectedObject.type == 6 || selectedObject.type == 7) {
} else if (selectedObject.type == 3) {
if (selectedObject.messageOwner instanceof TLRPC.TL_messageForwarded) {
MessagesController.getInstance().sendMessage(selectedObject, dialog_id);
} else {
@ -3481,11 +3479,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
private void updateRowBackground(ChatListRowHolderEx holder, boolean disableSelection, boolean selected) {
int messageType = holder.message.type;
if (!disableSelection) {
if (messageType == 4 || messageType == 6) {
holder.chatBubbleView.setBackgroundResource(R.drawable.chat_outgoing_photo_states);
} else if (messageType == 5 || messageType == 7) {
holder.chatBubbleView.setBackgroundResource(R.drawable.chat_incoming_photo_states);
} else if (messageType == 12) {
if (messageType == 12) {
holder.chatBubbleView.setBackgroundResource(R.drawable.chat_outgoing_text_states);
holder.chatBubbleView.setPadding(Utilities.dp(6), Utilities.dp(6), Utilities.dp(18), 0);
} else if (messageType == 13) {
@ -3499,19 +3493,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
holder.chatBubbleView.setPadding(Utilities.dp(18), Utilities.dp(9), Utilities.dp(9), 0);
}
} else {
if (messageType == 4 || messageType == 6) {
if (selected) {
holder.chatBubbleView.setBackgroundResource(R.drawable.msg_out_photo_selected);
} else {
holder.chatBubbleView.setBackgroundResource(R.drawable.msg_out_photo);
}
} else if (messageType == 5 || messageType == 7) {
if (selected) {
holder.chatBubbleView.setBackgroundResource(R.drawable.msg_in_photo_selected);
} else {
holder.chatBubbleView.setBackgroundResource(R.drawable.msg_in_photo);
}
} else if (messageType == 12) {
if (messageType == 12) {
if (selected) {
holder.chatBubbleView.setBackgroundResource(R.drawable.msg_out_selected);
} else {
@ -3543,6 +3525,26 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
}
}
private void alertUserOpenError(MessageObject message) {
AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
builder.setPositiveButton(R.string.OK, null);
if (message.type == 3) {
builder.setMessage(R.string.NoPlayerInstalled);
} else {
builder.setMessage(LocaleController.formatString("NoHandleAppInstalled", R.string.NoHandleAppInstalled, message.messageOwner.media.document.mime_type));
}
visibleDialog = builder.show();
visibleDialog.setCanceledOnTouchOutside(true);
visibleDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
visibleDialog = null;
}
});
}
private class ChatAdapter extends BaseAdapter {
private Context mContext;
@ -3617,38 +3619,22 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (type == 0) {
view = new ChatMessageCell(mContext);
} else if (type == 4) {
view = li.inflate(R.layout.chat_outgoing_location_layout, viewGroup, false);
} else if (type == 5) {
if (currentChat != null) {
view = li.inflate(R.layout.chat_group_incoming_location_layout, viewGroup, false);
} else {
view = li.inflate(R.layout.chat_incoming_location_layout, viewGroup, false);
}
} else if (type == 1) {
} if (type == 1) {
view = new ChatMediaCell(mContext);
((ChatMediaCell)view).downloadPhotos = downloadPhotos;
} else if (type == 6) {
view = li.inflate(R.layout.chat_outgoing_video_layout, viewGroup, false);
} else if (type == 7) {
if (currentChat != null) {
view = li.inflate(R.layout.chat_group_incoming_video_layout, viewGroup, false);
} else {
view = li.inflate(R.layout.chat_incoming_video_layout, viewGroup, false);
}
} else if (type == 10) {
view = li.inflate(R.layout.chat_action_message_layout, viewGroup, false);
} else if (type == 11) {
view = li.inflate(R.layout.chat_action_change_photo_layout, viewGroup, false);
} else if (type == 12) {
} else if (type == 4) {
view = li.inflate(R.layout.chat_outgoing_contact_layout, viewGroup, false);
} else if (type == 13) {
} else if (type == 5) {
if (currentChat != null) {
view = li.inflate(R.layout.chat_group_incoming_contact_layout, viewGroup, false);
} else {
view = li.inflate(R.layout.chat_incoming_contact_layout, viewGroup, false);
}
} else if (type == 15) {
} else if (type == 7) {
view = li.inflate(R.layout.chat_unread_layout, viewGroup, false);
} else if (type == 8) {
view = li.inflate(R.layout.chat_outgoing_document_layout, viewGroup, false);
@ -3691,7 +3677,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
}
@Override
public void didPressedCanceSendButton(ChatBaseCell cell) {
public void didPressedCancelSendButton(ChatBaseCell cell) {
MessageObject message = cell.getMessageObject();
if (message.messageOwner.send_state != 0) {
MessagesController.getInstance().cancelSendingMessage(message);
@ -3722,9 +3708,40 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
((ChatMediaCell)view).mediaDelegate = new ChatMediaCell.ChatMediaCellDelegate() {
@Override
public void didPressedImage(ChatBaseCell cell) {
NotificationCenter.getInstance().addToMemCache(51, cell.getMessageObject());
Intent intent = new Intent(parentActivity, GalleryImageViewer.class);
startActivity(intent);
MessageObject message = cell.getMessageObject();
if (message.messageOwner.send_state == MessagesController.MESSAGE_SEND_STATE_SEND_ERROR) {
createMenu(cell, false);
return;
} else if (message.messageOwner.send_state == MessagesController.MESSAGE_SEND_STATE_SENDING) {
return;
}
if (message.type == 1) {
NotificationCenter.getInstance().addToMemCache(51, message);
Intent intent = new Intent(parentActivity, GalleryImageViewer.class);
startActivity(intent);
} else if (message.type == 3) {
try {
File f = null;
if (message.messageOwner.attachPath != null && message.messageOwner.attachPath.length() != 0) {
f = new File(message.messageOwner.attachPath);
}
if (f == null || f != null && !f.exists()) {
f = new File(Utilities.getCacheDir(), message.getFileName());
}
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(f), "video/mp4");
startActivity(intent);
} catch (Exception e) {
alertUserOpenError(message);
}
} else if (message.type == 4) {
if (!isGoogleMapsInstalled()) {
return;
}
NotificationCenter.getInstance().addToMemCache(0, message);
LocationActivity fragment = new LocationActivity();
((LaunchActivity)parentActivity).presentFragment(fragment, "location_view", false);
}
}
};
}
@ -3757,11 +3774,11 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
if (!endReached && messages.size() != 0) {
offset = 0;
if (i == 0) {
return 14;
return 6;
}
}
if (!unread_end_reached && i == (messages.size() + 1 - offset)) {
return 14;
return 6;
}
MessageObject message = messages.get(messages.size() - i - offset);
return message.contentType;
@ -3769,7 +3786,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
@Override
public int getViewTypeCount() {
return 16;
return 12;
}
@Override
@ -3838,91 +3855,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
nameTextView.setTextColor(Utilities.getColorForId(message.messageOwner.from_id));
}
if (type == 6 || type == 7) {
int width = (int)(Math.min(displaySize.x, displaySize.y) * 0.7f);
int height = width + Utilities.dp(100);
if (type == 6 || type == 7) {
width = (int)(Math.min(displaySize.x, displaySize.y) / 2.5f);
height = width + 100;
}
if (width > 800) {
width = 800;
}
if (height > 800) {
height = 800;
}
PhotoObject photo = PhotoObject.getClosestImageWithSize(message.photoThumbs, width, height);
if (photo != null) {
float scale = (float)photo.photoOwner.w / (float)width;
int w = (int)(photo.photoOwner.w / scale);
int h = (int)(photo.photoOwner.h / scale);
if (h > height) {
float scale2 = h;
h = height;
scale2 /= h;
w = (int)(w / scale2);
} else if (h < Utilities.dp(120)) {
h = Utilities.dp(120);
float hScale = (float)photo.photoOwner.h / h;
if (photo.photoOwner.w / hScale < width) {
w = (int)(photo.photoOwner.w / hScale);
}
}
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams)photoImage.getLayoutParams();
params.width = w;
params.height = h;
photoImage.setLayoutParams(params);
LinearLayout.LayoutParams params2 = (LinearLayout.LayoutParams)chatBubbleView.getLayoutParams();
params2.width = w + Utilities.dp(12);
params2.height = h + Utilities.dp(12);
chatBubbleView.setLayoutParams(params2);
if (photo.image != null) {
photoImage.setImageBitmap(photo.image);
} else {
if (photoFileName == null) {
if (message.imagePreview != null) {
photoImage.setImage(photo.photoOwner.location, String.format(Locale.US, "%d_%d", (int)(w / Utilities.density), (int)(h / Utilities.density)), message.imagePreview);
} else {
photoImage.setImage(photo.photoOwner.location, String.format(Locale.US, "%d_%d", (int)(w / Utilities.density), (int)(h / Utilities.density)), message.messageOwner.out ? R.drawable.photo_placeholder_out : R.drawable.photo_placeholder_in);
}
} else {
if (downloadPhotos) {
addToLoadingFile(photoFileName, actionProgress);
if (message.imagePreview != null) {
photoImage.setImage(photo.photoOwner.location, String.format(Locale.US, "%d_%d", (int)(w / Utilities.density), (int)(h / Utilities.density)), message.imagePreview, photo.photoOwner.size);
} else {
photoImage.setImage(photo.photoOwner.location, String.format(Locale.US, "%d_%d", (int)(w / Utilities.density), (int)(h / Utilities.density)), message.messageOwner.out ? R.drawable.photo_placeholder_out : R.drawable.photo_placeholder_in, photo.photoOwner.size);
}
photoObjectToSet = null;
photoFilter = null;
} else {
photoFilter = String.format(Locale.US, "%d_%d", (int)(w / Utilities.density), (int)(h / Utilities.density));
photoObjectToSet = photo;
photoImage.setImageBitmap(message.imagePreview);
}
}
}
}
if ((type == 6 || type == 7) && videoTimeText != null) {
int duration = message.messageOwner.media.video.duration;
int minutes = duration / 60;
int seconds = duration - minutes * 60;
videoTimeText.setText(String.format("%d:%02d", minutes, seconds));
}
} else if (type == 4 || type == 5) {
double lat = message.messageOwner.media.geo.lat;
double lon = message.messageOwner.media.geo._long;
String url = String.format(Locale.US, "https://maps.googleapis.com/maps/api/staticmap?center=%f,%f&zoom=13&size=100x100&maptype=roadmap&scale=%d&markers=color:red|size:big|%f,%f&sensor=false", lat, lon, Math.min(2, (int)Math.ceil(Utilities.density)), lat, lon);
photoImage.setImage(url, null, message.messageOwner.out ? R.drawable.photo_placeholder_out : R.drawable.photo_placeholder_in);
actionAttachButton.setText(LocaleController.getString("ViewLocation", R.string.ViewLocation));
} else if (type == 11 || type == 10) {
if (type == 11 || type == 10) {
int width = displaySize.x - Utilities.dp(30);
messageTextView.setText(message.messageText);
messageTextView.setMaxWidth(width);
@ -3979,7 +3912,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
contactAvatar.setImageResource(Utilities.getUserAvatarForId(message.messageOwner.media.user_id));
addContactView.setVisibility(View.GONE);
}
} else if (type == 15) {
} else if (type == 7) {
if (unread_to_load == 1) {
messageTextView.setText(LocaleController.formatString("OneNewMessage", R.string.OneNewMessage, unread_to_load));
} else {
@ -4035,15 +3968,11 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
}
}
if (message.messageOwner.from_id == UserConfig.clientUserId) {
if (message.isFromMe()) {
if (halfCheckImage != null) {
if (message.messageOwner.send_state == MessagesController.MESSAGE_SEND_STATE_SENDING) {
checkImage.setVisibility(View.INVISIBLE);
if (type == 6 || type == 4) {
halfCheckImage.setImageResource(R.drawable.msg_clock_photo);
} else {
halfCheckImage.setImageResource(R.drawable.msg_clock);
}
halfCheckImage.setImageResource(R.drawable.msg_clock);
halfCheckImage.setVisibility(View.VISIBLE);
if (actionView != null) {
if (actionView != null) {
@ -4077,19 +4006,11 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
if (!message.messageOwner.unread) {
halfCheckImage.setVisibility(View.VISIBLE);
checkImage.setVisibility(View.VISIBLE);
if (type == 6 || type == 4) {
halfCheckImage.setImageResource(R.drawable.msg_halfcheck_w);
} else {
halfCheckImage.setImageResource(R.drawable.msg_halfcheck);
}
halfCheckImage.setImageResource(R.drawable.msg_halfcheck);
} else {
halfCheckImage.setVisibility(View.VISIBLE);
checkImage.setVisibility(View.INVISIBLE);
if (type == 6 || type == 4) {
halfCheckImage.setImageResource(R.drawable.msg_check_w);
} else {
halfCheckImage.setImageResource(R.drawable.msg_check);
}
halfCheckImage.setImageResource(R.drawable.msg_check);
}
if (actionView != null) {
actionView.setVisibility(View.GONE);
@ -4100,7 +4021,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
}
}
}
if (message.type == 6 || message.type == 7 || message.type == 8 || message.type == 9) {
if (message.type == 8 || message.type == 9) {
Integer tag = (Integer)actionProgress.getTag();
String file = progressByTag.get(tag);
if (file != null) {
@ -4122,9 +4043,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
if (f.exists()) {
if (actionAttachButton != null) {
actionAttachButton.setVisibility(View.VISIBLE);
if (message.type == 6 || message.type == 7) {
actionAttachButton.setText(LocaleController.getString("ViewVideo", R.string.ViewVideo));
} else if (message.type == 8 || message.type == 9) {
if (message.type == 8 || message.type == 9) {
actionAttachButton.setText(LocaleController.getString("Open", R.string.Open));
}
}
@ -4140,9 +4059,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
if ((cacheFile = new File(Utilities.getCacheDir(), fileName)).exists()) {
if (actionAttachButton != null) {
actionAttachButton.setVisibility(View.VISIBLE);
if (message.type == 6 || message.type == 7) {
actionAttachButton.setText(LocaleController.getString("ViewVideo", R.string.ViewVideo));
} else if (message.type == 8 || message.type == 9) {
if (message.type == 8 || message.type == 9) {
actionAttachButton.setText(LocaleController.getString("Open", R.string.Open));
}
}
@ -4179,9 +4096,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
}
if (actionAttachButton != null) {
actionAttachButton.setVisibility(View.VISIBLE);
if (message.type == 6 || message.type == 7) {
actionAttachButton.setText(String.format("%s %.1f MB", LocaleController.getString("DOWNLOAD", R.string.DOWNLOAD), message.messageOwner.media.video.size / 1024.0f / 1024.0f));
} else if (message.type == 8 || message.type == 9) {
if (message.type == 8 || message.type == 9) {
actionAttachButton.setText(LocaleController.getString("DOWNLOAD", R.string.DOWNLOAD));
}
}
@ -4412,13 +4327,11 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
if (file != null) {
progressBarMap.remove(file);
}
} else if (message.type == 6 || message.type == 7 || message.type == 8 || message.type == 9) {
} else if (message.type == 8 || message.type == 9) {
String file = progressByTag.get(tag);
if (file != null) {
loadingFile.remove(file);
if (message.type == 6 || message.type == 7) {
FileLoader.getInstance().cancelLoadFile(message.messageOwner.media.video, null, null, null);
} else if (message.type == 8 || message.type == 9) {
if (message.type == 8 || message.type == 9) {
FileLoader.getInstance().cancelLoadFile(null, null, message.messageOwner.media.document, null);
}
updateVisibleRows();
@ -4447,44 +4360,17 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
}
}
private void alertUserOpenError() {
AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
builder.setPositiveButton(R.string.OK, null);
if (message.type == 6 || message.type == 7) {
builder.setMessage(R.string.NoPlayerInstalled);
} else {
builder.setMessage(LocaleController.formatString("NoHandleAppInstalled", R.string.NoHandleAppInstalled, message.messageOwner.media.document.mime_type));
}
visibleDialog = builder.show();
visibleDialog.setCanceledOnTouchOutside(true);
visibleDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
visibleDialog = null;
}
});
}
private void processOnClick(View view) {
if (mActionMode != null) {
processRowSelect(view);
return;
}
if (message != null) {
if (message.type == 4 || message.type == 5) {
if (!isGoogleMapsInstalled()) {
return;
}
NotificationCenter.getInstance().addToMemCache(0, message);
LocationActivity fragment = new LocationActivity();
((LaunchActivity)parentActivity).presentFragment(fragment, "location_view", false);
} else if (message.type == 11) {
if (message.type == 11) {
NotificationCenter.getInstance().addToMemCache(51, message);
Intent intent = new Intent(parentActivity, GalleryImageViewer.class);
startActivity(intent);
} else if (message.type == 6 || message.type == 7 || message.type == 8 || message.type == 9) {
} else if (message.type == 8 || message.type == 9) {
File f = null;
String fileName = message.getFileName();
if (message.messageOwner.attachPath != null && message.messageOwner.attachPath.length() != 0) {
@ -4497,9 +4383,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
String realMimeType = null;
try {
Intent intent = new Intent(Intent.ACTION_VIEW);
if (message.type == 6 || message.type == 7) {
intent.setDataAndType(Uri.fromFile(f), "video/mp4");
} else if (message.type == 8 || message.type == 9) {
if (message.type == 8 || message.type == 9) {
MimeTypeMap myMime = MimeTypeMap.getSingleton();
int idx = fileName.lastIndexOf(".");
if (idx != -1) {
@ -4525,16 +4409,14 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
startActivity(intent);
}
} catch (Exception e) {
alertUserOpenError();
alertUserOpenError(message);
}
} else {
if (message.messageOwner.send_state != MessagesController.MESSAGE_SEND_STATE_SEND_ERROR && message.messageOwner.send_state != MessagesController.MESSAGE_SEND_STATE_SENDING || !message.messageOwner.out) {
if (message.messageOwner.send_state != MessagesController.MESSAGE_SEND_STATE_SEND_ERROR && message.messageOwner.send_state != MessagesController.MESSAGE_SEND_STATE_SENDING || !message.isOut()) {
if (!loadingFile.containsKey(fileName)) {
progressByTag.put((Integer)actionProgress.getTag(), fileName);
addToLoadingFile(fileName, actionProgress);
if (message.type == 6 || message.type == 7) {
FileLoader.getInstance().loadFile(message.messageOwner.media.video, null, null, null);
} else if (message.type == 8 || message.type == 9) {
if (message.type == 8 || message.type == 9) {
FileLoader.getInstance().loadFile(null, null, message.messageOwner.media.document, null);
}
updateVisibleRows();

View File

@ -726,9 +726,9 @@ public class GalleryImageViewer extends AbstractGalleryActivity implements Notif
return;
}
if (isVideo) {
MediaController.saveFile(currentFileName, this, 1, null);
MediaController.saveFile(currentFileName, null, this, 1, null);
} else {
MediaController.saveFile(currentFileName, this, 0, null);
MediaController.saveFile(currentFileName, null, this, 0, null);
}
break;
// case R.id.gallery_menu_send: {

View File

@ -182,7 +182,7 @@ public class PhotoCropActivity extends BaseFragment {
}
private void updateBitmapSize() {
if (viewWidth == 0 || viewHeight == 0) {
if (viewWidth == 0 || viewHeight == 0 || imageToCrop == null) {
return;
}
float percX = (rectX - bitmapX) / bitmapWidth;

View File

@ -21,10 +21,12 @@ import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.text.Html;
import android.text.Spannable;
import android.text.method.LinkMovementMethod;
import android.util.Base64;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
@ -93,6 +95,18 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
private int telegramFaqRow;
private int languageRow;
private static class LinkMovementMethodMy extends LinkMovementMethod {
@Override
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
try {
return super.onTouchEvent(widget, buffer, event);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
return false;
}
}
@Override
public boolean onFragmentCreate() {
super.onFragmentCreate();
@ -252,7 +266,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
message.setText(Html.fromHtml(LocaleController.getString("AskAQuestionInfo", R.string.AskAQuestionInfo)));
message.setTextSize(18);
message.setPadding(Utilities.dp(8), Utilities.dp(5), Utilities.dp(8), Utilities.dp(6));
message.setMovementMethod(LinkMovementMethod.getInstance());
message.setMovementMethod(new LinkMovementMethodMy());
AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
builder.setView(message);
@ -642,6 +656,9 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (parentActivity == null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 785 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 793 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

View File

@ -1,7 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:drawable="@drawable/msg_in_photo_selected" />
<item android:state_checked="true" android:drawable="@drawable/msg_in_photo_selected" />
<item android:state_pressed="true" android:drawable="@drawable/msg_in_photo_selected" />
<item android:drawable="@drawable/msg_in_photo" />
</selector>

View File

@ -1,7 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:drawable="@drawable/msg_out_photo_selected" />
<item android:state_checked="true" android:drawable="@drawable/msg_out_photo_selected" />
<item android:state_pressed="true" android:drawable="@drawable/msg_out_photo_selected" />
<item android:drawable="@drawable/msg_out_photo"/>
</selector>

View File

@ -1,142 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="1dp"
android:paddingTop="1dp"
android:layout_gravity="top">
<org.telegram.ui.Views.BackupImageView
android:layout_width="42dp"
android:layout_height="42dp"
android:layout_marginLeft="6dp"
android:id="@+id/chat_group_avatar_image"
android:scaleType="fitCenter"
android:layout_marginBottom="2dp"
android:layout_gravity="bottom"/>
<org.telegram.ui.Views.FrameLayoutFixed
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="13dp"
android:layout_gravity="top"
android:id="@+id/chat_bubble_layout"
android:addStatesFromChildren="true">
<org.telegram.ui.Views.BackupImageView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_margin="6dp"
android:layout_gravity="top"
android:scaleType="centerCrop"
android:minHeight="100dp"
android:minWidth="100dp"
android:id="@+id/chat_photo_image"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="16dp"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_gravity="top"
android:background="@drawable/phototime"
android:orientation="horizontal"
android:gravity="center_vertical">
<ImageView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="@drawable/ic_video"/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="#ffffff"
android:textSize="12dp"
android:layout_marginLeft="4dp"
android:gravity="center_vertical"
android:layout_gravity="center_vertical"
android:layout_marginBottom="1dp"
android:id="@+id/chat_video_time"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="16dp"
android:id="@+id/chat_time_layout"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
android:layout_gravity="right|bottom"
android:background="@drawable/phototime">
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="#ffffff"
android:textSize="12dp"
android:layout_gravity="bottom"
android:layout_marginBottom="1dp"
android:id="@+id/chat_time_text"/>
</LinearLayout>
</org.telegram.ui.Views.FrameLayoutFixed>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#54759e"
android:background="@drawable/chat_incoming_media_states"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:id="@+id/chat_view_action_button"
android:textSize="14dp"
android:layout_gravity="center"
android:descendantFocusability="blocksDescendants"
android:clickable="true"
android:gravity="center"
android:textStyle="bold"
android:layout_marginLeft="10dp"
android:visibility="gone"/>
<org.telegram.ui.Views.FrameLayoutFixed
android:layout_height="wrap_content"
android:layout_width="140dp"
android:layout_marginLeft="10dp"
android:layout_gravity="center_vertical"
android:id="@+id/chat_view_action_layout"
android:visibility="gone">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:scaleType="centerInside"
android:layout_marginRight="4dp"
android:layout_gravity="right|center"
android:id="@+id/chat_view_action_cancel_button"
android:src="@drawable/ic_msg_btn_cross_custom"
android:clickable="true"/>
<ProgressBar
android:layout_width="fill_parent"
android:layout_height="3dp"
android:layout_gravity="left|center_vertical"
android:progressDrawable="@drawable/progress_chat"
style="?android:attr/progressBarStyleHorizontal"
android:progress="50"
android:layout_marginLeft="12dp"
android:layout_marginRight="36dp"
android:id="@+id/chat_view_action_progress"
android:max="100"/>
</org.telegram.ui.Views.FrameLayoutFixed>
</LinearLayout>

View File

@ -1,133 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="1dp"
android:paddingTop="1dp"
android:layout_gravity="top">
<org.telegram.ui.Views.FrameLayoutFixed
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="9dp"
android:id="@+id/chat_bubble_layout"
android:layout_gravity="top"
android:addStatesFromChildren="true">
<org.telegram.ui.Views.BackupImageView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_margin="6dp"
android:layout_gravity="top"
android:scaleType="centerCrop"
android:minHeight="100dp"
android:minWidth="100dp"
android:id="@+id/chat_photo_image"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="16dp"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_gravity="top"
android:background="@drawable/phototime"
android:orientation="horizontal"
android:gravity="center_vertical">
<ImageView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="@drawable/ic_video"/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="#ffffff"
android:textSize="12dp"
android:layout_marginLeft="4dp"
android:gravity="center_vertical"
android:layout_gravity="center_vertical"
android:layout_marginBottom="1dp"
android:id="@+id/chat_video_time"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="16dp"
android:id="@+id/chat_time_layout"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
android:layout_gravity="right|bottom"
android:background="@drawable/phototime">
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="#ffffff"
android:textSize="12dp"
android:layout_gravity="bottom"
android:layout_marginBottom="1dp"
android:id="@+id/chat_time_text"/>
</LinearLayout>
</org.telegram.ui.Views.FrameLayoutFixed>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#54759e"
android:background="@drawable/chat_incoming_media_states"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:id="@+id/chat_view_action_button"
android:textSize="14dp"
android:layout_gravity="center"
android:descendantFocusability="blocksDescendants"
android:clickable="true"
android:gravity="center"
android:visibility="gone"
android:textStyle="bold"
android:layout_marginLeft="10dp"/>
<org.telegram.ui.Views.FrameLayoutFixed
android:layout_height="wrap_content"
android:layout_width="140dp"
android:layout_marginLeft="10dp"
android:layout_gravity="center_vertical"
android:id="@+id/chat_view_action_layout"
android:visibility="gone">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:scaleType="centerInside"
android:layout_marginRight="4dp"
android:layout_gravity="right|center"
android:id="@+id/chat_view_action_cancel_button"
android:src="@drawable/ic_msg_btn_cross_custom"
android:clickable="true"/>
<ProgressBar
android:layout_width="fill_parent"
android:layout_height="3dp"
android:layout_gravity="left|center_vertical"
android:progressDrawable="@drawable/progress_chat"
style="?android:attr/progressBarStyleHorizontal"
android:progress="50"
android:layout_marginLeft="12dp"
android:layout_marginRight="36dp"
android:id="@+id/chat_view_action_progress"
android:max="100"/>
</org.telegram.ui.Views.FrameLayoutFixed>
</LinearLayout>

View File

@ -1,153 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:paddingBottom="1dp"
android:paddingTop="1dp">
<org.telegram.ui.Views.FrameLayoutFixed
android:layout_height="wrap_content"
android:layout_width="140dp"
android:layout_marginRight="10dp"
android:id="@+id/chat_view_action_layout"
android:layout_gravity="center"
android:visibility="gone">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:scaleType="centerInside"
android:layout_marginLeft="4dp"
android:id="@+id/chat_view_action_cancel_button"
android:src="@drawable/ic_msg_btn_cross_custom"
android:layout_gravity="left|center"
android:clickable="true"/>
<ProgressBar
android:layout_width="fill_parent"
android:layout_height="3dp"
android:layout_gravity="right|center_vertical"
android:progressDrawable="@drawable/progress_chat"
style="?android:attr/progressBarStyleHorizontal"
android:progress="50"
android:layout_marginLeft="36dp"
android:layout_marginRight="12dp"
android:id="@+id/chat_view_action_progress"
android:max="100"/>
</org.telegram.ui.Views.FrameLayoutFixed>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#54759e"
android:background="@drawable/chat_incoming_media_states"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:id="@+id/chat_view_action_button"
android:textSize="14dp"
android:layout_marginRight="10dp"
android:descendantFocusability="blocksDescendants"
android:clickable="true"
android:gravity="center"
android:visibility="gone"
android:textStyle="bold"
android:layout_gravity="center"/>
<org.telegram.ui.Views.FrameLayoutFixed
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="9dp"
android:id="@+id/chat_bubble_layout"
android:layout_gravity="top"
android:addStatesFromChildren="true">
<org.telegram.ui.Views.BackupImageView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_margin="6dp"
android:layout_gravity="top"
android:scaleType="centerCrop"
android:minHeight="100dp"
android:minWidth="100dp"
android:id="@+id/chat_photo_image"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="16dp"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_gravity="top"
android:background="@drawable/phototime"
android:orientation="horizontal"
android:gravity="center_vertical">
<ImageView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="@drawable/ic_video"/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="#ffffff"
android:textSize="12dp"
android:layout_marginLeft="4dp"
android:gravity="center_vertical"
android:layout_gravity="center_vertical"
android:layout_marginBottom="1dp"
android:id="@+id/chat_video_time"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="16dp"
android:id="@+id/chat_time_layout"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
android:layout_gravity="right|bottom"
android:background="@drawable/phototime">
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="#ffffff"
android:textSize="12dp"
android:layout_gravity="bottom"
android:id="@+id/chat_time_text"
android:layout_marginBottom="1dp"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/msg_check_w"
android:layout_marginTop="1dp"
android:layout_marginLeft="3dp"
android:layout_marginRight="-8dp"
android:id="@+id/chat_row_check"
android:visibility="visible"
android:layout_gravity="top"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="1dp"
android:id="@+id/chat_row_halfcheck"
android:visibility="visible"
android:src="@drawable/msg_halfcheck_w"
android:layout_gravity="top"/>
</LinearLayout>
</org.telegram.ui.Views.FrameLayoutFixed>
</LinearLayout>