Commit ec533c5f authored by DrKLO's avatar DrKLO

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

parent 51aa4141
...@@ -82,7 +82,7 @@ android { ...@@ -82,7 +82,7 @@ android {
defaultConfig { defaultConfig {
minSdkVersion 8 minSdkVersion 8
targetSdkVersion 19 targetSdkVersion 19
versionCode 219 versionCode 220
versionName "1.4.9" versionName "1.4.10"
} }
} }
...@@ -18,38 +18,29 @@ ...@@ -18,38 +18,29 @@
package jawnae.pyronet; package jawnae.pyronet;
import org.telegram.messenger.BuffersStorage;
import org.telegram.messenger.ByteBufferDesc;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
public class ByteStream { public class ByteStream {
private final List<ByteBuffer> queue; private final ArrayList<ByteBufferDesc> queue;
public ByteStream() { public ByteStream() {
// the queue is expected to be relatively small, and iterated often. this.queue = new ArrayList<ByteBufferDesc>();
// hence removing the first element will be fast, even when using an
// ArrayList
this.queue = new ArrayList<ByteBuffer>();
} }
/** public void append(ByteBufferDesc buf) {
* Appends the ByteBuffer instance to the ByteStream. The bytes are not if (buf == null) {
* copied, so do not modify the contents of the ByteBuffer.
*/
public void append(ByteBuffer buf) {
if (buf == null)
throw new NullPointerException(); throw new NullPointerException();
}
this.queue.add(buf); this.queue.add(buf);
} }
/**
* Returns whether there are any bytes pending in this stream
*/
public boolean hasData() { public boolean hasData() {
int size = this.queue.size(); int size = this.queue.size();
for (ByteBuffer aQueue : this.queue) { for (ByteBufferDesc aQueue : this.queue) {
if (aQueue.hasRemaining()) { if (aQueue.hasRemaining()) {
return true; return true;
} }
...@@ -57,29 +48,13 @@ public class ByteStream { ...@@ -57,29 +48,13 @@ public class ByteStream {
return false; 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) { public void get(ByteBuffer dst) {
if (dst == null) { if (dst == null) {
throw new NullPointerException(); throw new NullPointerException();
} }
for (ByteBuffer data: this.queue) { for (ByteBufferDesc bufferDesc : this.queue) {
// data pos/lim must not be modified ByteBuffer data = bufferDesc.buffer.slice();
data = data.slice();
if (data.remaining() > dst.remaining()) { if (data.remaining() > dst.remaining()) {
data.limit(dst.remaining()); data.limit(dst.remaining());
...@@ -95,48 +70,25 @@ public class ByteStream { ...@@ -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) { public void discard(int count) {
int original = count; int original = count;
while (count > 0) { while (count > 0) {
// peek at the first buffer ByteBufferDesc data = this.queue.get(0);
ByteBuffer data = this.queue.get(0);
if (count < data.remaining()) { if (count < data.buffer.remaining()) {
// discarding less bytes than remaining in buffer
data.position(data.position() + count); data.position(data.position() + count);
count = 0; count = 0;
break; break;
} }
// discard the first buffer
this.queue.remove(0); this.queue.remove(0);
count -= data.remaining(); BuffersStorage.getInstance().reuseFreeBuffer(data);
count -= data.buffer.remaining();
} }
if (count != 0) { if (count != 0) {
// apparantly we cannot discard the amount of bytes throw new PyroException("discarded " + (original - count) + "/" + original + " bytes");
// the user demanded, this is a bug in other code
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;
} }
} }
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
package jawnae.pyronet; package jawnae.pyronet;
import org.telegram.messenger.ByteBufferDesc;
import java.io.EOFException; import java.io.EOFException;
import java.io.IOException; import java.io.IOException;
import java.net.ConnectException; import java.net.ConnectException;
...@@ -167,12 +169,6 @@ public class PyroClient { ...@@ -167,12 +169,6 @@ public class PyroClient {
this.doEagerWrite = enabled; this.doEagerWrite = enabled;
} }
//
public void writeCopy(ByteBuffer data) throws PyroException {
this.write(this.selector.copy(data));
}
/** /**
* Will enqueue the bytes to send them<br> * Will enqueue the bytes to send them<br>
* 1. when the selector is ready to write, if eagerWrite is disabled * 1. when the selector is ready to write, if eagerWrite is disabled
...@@ -185,7 +181,7 @@ public class PyroClient { ...@@ -185,7 +181,7 @@ public class PyroClient {
* when shutdown() has been called. * when shutdown() has been called.
*/ */
public void write(ByteBuffer data) throws PyroException { public void write(ByteBufferDesc data) throws PyroException {
this.selector.checkThread(); this.selector.checkThread();
if (!this.key.isValid()) { if (!this.key.isValid()) {
......
...@@ -56,25 +56,6 @@ public class PyroSelector { ...@@ -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() { public final boolean isNetworkThread() {
return DO_NOT_CHECK_NETWORK_THREAD || networkThread == Thread.currentThread(); return DO_NOT_CHECK_NETWORK_THREAD || networkThread == Thread.currentThread();
} }
......
...@@ -30,6 +30,7 @@ public abstract class AbsSerializedData { ...@@ -30,6 +30,7 @@ public abstract class AbsSerializedData {
public abstract String readString(); public abstract String readString();
public abstract byte[] readByteArray(); public abstract byte[] readByteArray();
public abstract ByteBufferDesc readByteBuffer(); public abstract ByteBufferDesc readByteBuffer();
public abstract void writeByteBuffer(ByteBufferDesc buffer);
public abstract double readDouble(); public abstract double readDouble();
public abstract int length(); public abstract int length();
} }
...@@ -78,7 +78,7 @@ public class ByteBufferDesc extends AbsSerializedData { ...@@ -78,7 +78,7 @@ public class ByteBufferDesc extends AbsSerializedData {
if (!justCalc) { if (!justCalc) {
buffer.putLong(x); buffer.putLong(x);
} else { } else {
len += 4; len += 8;
} }
} catch(Exception e) { } catch(Exception e) {
FileLog.e("tmessages", "write int64 error"); FileLog.e("tmessages", "write int64 error");
...@@ -227,6 +227,54 @@ public class ByteBufferDesc extends AbsSerializedData { ...@@ -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() { public int readInt32() {
return readInt32(null); return readInt32(null);
} }
......
...@@ -489,6 +489,8 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection. ...@@ -489,6 +489,8 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
public void run() { public void run() {
Datacenter datacenter = datacenterWithId(currentDatacenterId); Datacenter datacenter = datacenterWithId(currentDatacenterId);
recreateSession(datacenter.authSessionId, datacenter); recreateSession(datacenter.authSessionId, datacenter);
recreateSession(datacenter.authDownloadSessionId, datacenter);
recreateSession(datacenter.authUploadSessionId, datacenter);
} }
}); });
} }
...@@ -503,6 +505,14 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection. ...@@ -503,6 +505,14 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
clearRequestsForRequestClass(RPCRequest.RPCRequestClassGeneric, datacenter); clearRequestsForRequestClass(RPCRequest.RPCRequestClassGeneric, datacenter);
FileLog.d("tmessages", "***** Recreate generic session"); FileLog.d("tmessages", "***** Recreate generic session");
datacenter.authSessionId = getNewSessionId(); 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. ...@@ -850,6 +860,8 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
} }
request.cancelled = true; request.cancelled = true;
request.rawRequest.freeResources();
request.rpcRequest.freeResources();
runningRequests.remove(i); runningRequests.remove(i);
break; break;
} }
...@@ -1025,7 +1037,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection. ...@@ -1025,7 +1037,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
Datacenter requestDatacenter = datacenterWithId(datacenterId); Datacenter requestDatacenter = datacenterWithId(datacenterId);
if (!request.initRequest && requestDatacenter.lastInitVersion != currentAppVersion) { if (!request.initRequest && requestDatacenter.lastInitVersion != currentAppVersion) {
request.rpcRequest = wrapInLayer(request.rawRequest, requestDatacenter.datacenterId, request); request.rpcRequest = wrapInLayer(request.rawRequest, requestDatacenter.datacenterId, request);
SerializedData os = new SerializedData(true); ByteBufferDesc os = new ByteBufferDesc(true);
request.rpcRequest.serializeToStream(os); request.rpcRequest.serializeToStream(os);
request.serializedLength = os.length(); request.serializedLength = os.length();
} }
...@@ -1520,7 +1532,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection. ...@@ -1520,7 +1532,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
} }
TLRPC.TL_protoMessage wrapMessage(TLObject message, long sessionId, boolean meaningful) { TLRPC.TL_protoMessage wrapMessage(TLObject message, long sessionId, boolean meaningful) {
SerializedData os = new SerializedData(true); ByteBufferDesc os = new ByteBufferDesc(true);
message.serializeToStream(os); message.serializeToStream(os);
if (os.length() != 0) { if (os.length() != 0) {
...@@ -1552,7 +1564,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection. ...@@ -1552,7 +1564,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
msgAck.msg_ids = new ArrayList<Long>(); msgAck.msg_ids = new ArrayList<Long>();
msgAck.msg_ids.addAll(arr); msgAck.msg_ids.addAll(arr);
SerializedData os = new SerializedData(true); ByteBufferDesc os = new ByteBufferDesc(true);
msgAck.serializeToStream(os); msgAck.serializeToStream(os);
if (os.length() != 0) { if (os.length() != 0) {
...@@ -1599,7 +1611,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection. ...@@ -1599,7 +1611,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
if (currentSize >= 3 * 1024 || a == messagesToSend.size() - 1) { if (currentSize >= 3 * 1024 || a == messagesToSend.size() - 1) {
ArrayList<Integer> quickAckId = new ArrayList<Integer>(); ArrayList<Integer> quickAckId = new ArrayList<Integer>();
byte[] transportData = createConnectionData(currentMessages, sessionId, quickAckId, connection); ByteBufferDesc transportData = createConnectionData(currentMessages, sessionId, quickAckId, connection);
if (transportData != null) { if (transportData != null) {
if (reportAck && quickAckId.size() != 0) { if (reportAck && quickAckId.size() != 0) {
...@@ -1622,7 +1634,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection. ...@@ -1622,7 +1634,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
} }
} }
connection.sendData(transportData, reportAck, requestShortTimeout); connection.sendData(null, transportData, reportAck, requestShortTimeout);
} else { } else {
FileLog.e("tmessages", "***** Transport data is nil"); FileLog.e("tmessages", "***** Transport data is nil");
} }
...@@ -1634,7 +1646,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection. ...@@ -1634,7 +1646,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
} }
@SuppressWarnings("unused") @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()); Datacenter datacenter = datacenterWithId(connection.getDatacenterId());
if (datacenter.authKey == null) { if (datacenter.authKey == null) {
return null; return null;
...@@ -1711,11 +1723,11 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection. ...@@ -1711,11 +1723,11 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
messageSeqNo = generateMessageSeqNo(sessionId, false); messageSeqNo = generateMessageSeqNo(sessionId, false);
} }
SerializedData innerMessageOs = new SerializedData(); ByteBufferDesc sizeBuffer = new ByteBufferDesc(true);
messageBody.serializeToStream(innerMessageOs); messageBody.serializeToStream(sizeBuffer);
byte[] messageData = innerMessageOs.toByteArray();
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()); long serverSalt = datacenter.selectServerSalt(getCurrentTime());
if (serverSalt == 0) { if (serverSalt == 0) {
innerOs.writeInt64(0); innerOs.writeInt64(0);
...@@ -1725,11 +1737,10 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection. ...@@ -1725,11 +1737,10 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
innerOs.writeInt64(sessionId); innerOs.writeInt64(sessionId);
innerOs.writeInt64(messageId); innerOs.writeInt64(messageId);
innerOs.writeInt32(messageSeqNo); innerOs.writeInt32(messageSeqNo);
innerOs.writeInt32(messageData.length); innerOs.writeInt32(sizeBuffer.length());
innerOs.writeRaw(messageData); messageBody.serializeToStream(innerOs);
byte[] innerData = innerOs.toByteArray();
byte[] messageKeyFull = Utilities.computeSHA1(innerData); byte[] messageKeyFull = Utilities.computeSHA1(innerOs.buffer, 0, innerOs.limit());
byte[] messageKey = new byte[16]; byte[] messageKey = new byte[16];
System.arraycopy(messageKeyFull, messageKeyFull.length - 16, messageKey, 0, 16); System.arraycopy(messageKeyFull, messageKeyFull.length - 16, messageKey, 0, 16);
...@@ -1740,35 +1751,29 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection. ...@@ -1740,35 +1751,29 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
MessageKeyData keyData = Utilities.generateMessageKeyData(datacenter.authKey, messageKey, false); MessageKeyData keyData = Utilities.generateMessageKeyData(datacenter.authKey, messageKey, false);
SerializedData dataForEncryption = new SerializedData(innerData.length + (innerData.length % 16)); int zeroCount = 0;
dataForEncryption.writeRaw(innerData); 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]; byte[] b = new byte[1];
while (dataForEncryption.length() % 16 != 0) { for (int a = 0; a < zeroCount; a++) {
MessagesController.random.nextBytes(b); MessagesController.random.nextBytes(b);
dataForEncryption.writeByte(b[0]); 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);
return data.toByteArray(); ByteBufferDesc data = BuffersStorage.getInstance().getFreeBuffer(8 + messageKey.length + dataForEncryption.limit());
} catch (Exception e) { data.writeInt64(datacenter.authKeyId);
FileLog.e("tmessages", e); data.writeRaw(messageKey);
innerData = null; data.writeRaw(dataForEncryption);
messageData = null; BuffersStorage.getInstance().reuseFreeBuffer(dataForEncryption);
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) { void refillSaltSet(final Datacenter datacenter) {
...@@ -1821,6 +1826,8 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection. ...@@ -1821,6 +1826,8 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
RPCRequest request = runningRequests.get(i); RPCRequest request = runningRequests.get(i);
removeRequestInClass(request.token); removeRequestInClass(request.token);
if (request.respondsToMessageId(requestMsgId)) { if (request.respondsToMessageId(requestMsgId)) {
request.rawRequest.freeResources();
request.rpcRequest.freeResources();
runningRequests.remove(i); runningRequests.remove(i);
i--; i--;
} }
...@@ -2188,6 +2195,9 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection. ...@@ -2188,6 +2195,9 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
} }
recreateSession(datacenter.authSessionId, datacenter); recreateSession(datacenter.authSessionId, datacenter);
recreateSession(datacenter.authDownloadSessionId, datacenter);
recreateSession(datacenter.authUploadSessionId, datacenter);
saveSession(); saveSession();
lastOutgoingMessageId = 0; lastOutgoingMessageId = 0;
...@@ -2273,7 +2283,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection. ...@@ -2273,7 +2283,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
} }
static long nextPingId = 0; static long nextPingId = 0;
byte[] generatePingData(Datacenter datacenter, boolean recordTime) { ByteBufferDesc generatePingData(Datacenter datacenter, boolean recordTime) {
long sessionId = datacenter.authSessionId; long sessionId = datacenter.authSessionId;
if (sessionId == 0) { if (sessionId == 0) {
return null; return null;
...@@ -2300,9 +2310,9 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection. ...@@ -2300,9 +2310,9 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
return; return;
} }
byte[] transportData = generatePingData(datacenter, true); ByteBufferDesc transportData = generatePingData(datacenter, true);
if (transportData != null) { 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. ...@@ -2698,6 +2708,8 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
} }
recreateSession(datacenter.authSessionId, datacenter); recreateSession(datacenter.authSessionId, datacenter);
recreateSession(datacenter.authDownloadSessionId, datacenter);
recreateSession(datacenter.authUploadSessionId, datacenter);
if (datacenter.authKey == null) { if (datacenter.authKey == null) {
datacenter.clearServerSalts(); datacenter.clearServerSalts();
...@@ -2766,6 +2778,8 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection. ...@@ -2766,6 +2778,8 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
timeDifference = (Integer)params.get("timeDifference"); timeDifference = (Integer)params.get("timeDifference");
recreateSession(eactor.datacenter.authSessionId, eactor.datacenter); recreateSession(eactor.datacenter.authSessionId, eactor.datacenter);
recreateSession(eactor.datacenter.authDownloadSessionId, eactor.datacenter);
recreateSession(eactor.datacenter.authUploadSessionId, eactor.datacenter);
} }
processRequestQueue(RPCRequest.RPCRequestClassTransportMask, eactor.datacenter.datacenterId); processRequestQueue(RPCRequest.RPCRequestClassTransportMask, eactor.datacenter.datacenterId);
} else if (action instanceof ExportAuthorizationAction) { } else if (action instanceof ExportAuthorizationAction) {
......
...@@ -125,15 +125,21 @@ public class FileUploadOperation { ...@@ -125,15 +125,21 @@ public class FileUploadOperation {
if (key != null && readed % 16 != 0) { if (key != null && readed % 16 != 0) {
toAdd += 16 - readed % 16; toAdd += 16 - readed % 16;
} }
byte[] sendBuffer = new byte[readed + toAdd]; ByteBufferDesc sendBuffer = BuffersStorage.getInstance().getFreeBuffer(readed + toAdd);
if (readed != uploadChunkSize) { if (readed != uploadChunkSize) {
isLastPart = true; isLastPart = true;
} }
System.arraycopy(readBuffer, 0, sendBuffer, 0, readed); sendBuffer.writeRaw(readBuffer, 0, readed);
sendBuffer.rewind();
if (key != null) { 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) { if (isBigFile) {
TLRPC.TL_upload_saveBigFilePart req = new TLRPC.TL_upload_saveBigFilePart(); TLRPC.TL_upload_saveBigFilePart req = new TLRPC.TL_upload_saveBigFilePart();
req.file_part = currentPartNum; req.file_part = currentPartNum;
......
...@@ -179,7 +179,7 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti ...@@ -179,7 +179,7 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
byte[] transportData = messageOs.toByteArray(); byte[] transportData = messageOs.toByteArray();
datacenter.connection.sendData(transportData, false, false); datacenter.connection.sendData(transportData, null, false, false);
return transportData; return transportData;
} }
...@@ -576,11 +576,11 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti ...@@ -576,11 +576,11 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
return; return;
} }
if (reqPQMsgData != null) { if (reqPQMsgData != null) {
datacenter.connection.sendData(reqPQMsgData, false, false); datacenter.connection.sendData(reqPQMsgData, null, false, false);
} else if (reqDHMsgData != null) { } else if (reqDHMsgData != null) {
datacenter.connection.sendData(reqDHMsgData, false, false); datacenter.connection.sendData(reqDHMsgData, null, false, false);
} else if (setClientDHParamsMsgData != null) { } else if (setClientDHParamsMsgData != null) {
datacenter.connection.sendData(setClientDHParamsMsgData, false, false); datacenter.connection.sendData(setClientDHParamsMsgData, null, false, false);
} }
} }
......
...@@ -1016,8 +1016,23 @@ public class MediaController implements NotificationCenter.NotificationCenterDel ...@@ -1016,8 +1016,23 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
}); });
} }
public static void saveFile(String path, Context context, final int type, final String name) { public static void saveFile(String path, String fullPath, Context context, final int type, final String name) {
final File sourceFile = new File(Utilities.getCacheDir(), path); 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()) { if (sourceFile.exists()) {
ProgressDialog progressDialog = null; ProgressDialog progressDialog = null;
if (context != null) { if (context != null) {
...@@ -1121,7 +1136,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel ...@@ -1121,7 +1136,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
return null; return null;
} }
if (currentGifMessageObject != null && messageObject.messageOwner.id == currentGifMessageObject.messageOwner.id) { if (currentGifDrawable != null && currentGifMessageObject != null && messageObject.messageOwner.id == currentGifMessageObject.messageOwner.id) {
currentMediaCell = cell; currentMediaCell = cell;
currentGifDrawable.parentView = new WeakReference<View>(cell); currentGifDrawable.parentView = new WeakReference<View>(cell);
return currentGifDrawable; return currentGifDrawable;
......
...@@ -3274,7 +3274,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter ...@@ -3274,7 +3274,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
} }
if (!(res instanceof TLRPC.TL_updates_differenceSlice)) { 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)) { if (!readMessages.contains(obj.messageOwner.id)) {
lastMessage = obj; lastMessage = obj;
} }
...@@ -3342,7 +3342,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter ...@@ -3342,7 +3342,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
ConnectionsManager.getInstance().connectionState = 0; ConnectionsManager.getInstance().connectionState = 0;
processUpdatesQueue(true); processUpdatesQueue(true);
} else if (res instanceof TLRPC.TL_updates_differenceSlice) { } 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.lastDateValue = res.intermediate_state.date;
MessagesStorage.lastPtsValue = res.intermediate_state.pts; MessagesStorage.lastPtsValue = res.intermediate_state.pts;
MessagesStorage.lastQtsValue = res.intermediate_state.qts; MessagesStorage.lastQtsValue = res.intermediate_state.qts;
...@@ -3380,123 +3380,131 @@ public class MessagesController implements NotificationCenter.NotificationCenter ...@@ -3380,123 +3380,131 @@ public class MessagesController implements NotificationCenter.NotificationCenter
processUpdateArray(arr, null, null); processUpdateArray(arr, null, null);
} else if (updates instanceof TLRPC.TL_updateShortChatMessage) { } else if (updates instanceof TLRPC.TL_updateShortChatMessage) {
boolean missingData = chats.get(updates.chat_id) == null || users.get(updates.from_id) == null; boolean missingData = chats.get(updates.chat_id) == null || users.get(updates.from_id) == null;
if (MessagesStorage.lastSeqValue + 1 == updates.seq && !missingData) { if (missingData) {
TLRPC.TL_message message = new TLRPC.TL_message(); needGetDiff = true;
message.from_id = updates.from_id; } else {
message.id = updates.id; if (MessagesStorage.lastSeqValue + 1 == updates.seq && !gettingDifference) {
message.to_id = new TLRPC.TL_peerChat(); TLRPC.TL_message message = new TLRPC.TL_message();
message.to_id.chat_id = updates.chat_id; message.from_id = updates.from_id;
message.message = updates.message; message.id = updates.id;
message.date = updates.date; message.to_id = new TLRPC.TL_peerChat();
message.unread = true; message.to_id.chat_id = updates.chat_id;
message.media = new TLRPC.TL_messageMediaEmpty(); message.message = updates.message;
MessagesStorage.lastSeqValue = updates.seq; message.date = updates.date;
MessagesStorage.lastPtsValue = updates.pts; message.unread = true;
final MessageObject obj = new MessageObject(message, null); message.media = new TLRPC.TL_messageMediaEmpty();
final ArrayList<MessageObject> objArr = new ArrayList<MessageObject>(); MessagesStorage.lastSeqValue = updates.seq;
objArr.add(obj); MessagesStorage.lastPtsValue = updates.pts;
ArrayList<TLRPC.Message> arr = new ArrayList<TLRPC.Message>(); final MessageObject obj = new MessageObject(message, null);
arr.add(message); final ArrayList<MessageObject> objArr = new ArrayList<MessageObject>();
final boolean printUpdate = updatePrintingUsersWithNewMessages(-updates.chat_id, objArr); objArr.add(obj);
if (printUpdate) { ArrayList<TLRPC.Message> arr = new ArrayList<TLRPC.Message>();
updatePrintingStrings(); arr.add(message);
} final boolean printUpdate = updatePrintingUsersWithNewMessages(-updates.chat_id, objArr);
Utilities.RunOnUIThread(new Runnable() { if (printUpdate) {
@Override updatePrintingStrings();
public void run() { }
if (printUpdate) { Utilities.RunOnUIThread(new Runnable() {
NotificationCenter.getInstance().postNotificationName(updateInterfaces, UPDATE_MASK_USER_PRINT); @Override
} public void run() {
if (obj.messageOwner.from_id != UserConfig.clientUserId) { if (printUpdate) {
long dialog_id; NotificationCenter.getInstance().postNotificationName(updateInterfaces, UPDATE_MASK_USER_PRINT);
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) { if (obj.messageOwner.from_id != UserConfig.clientUserId) {
showInAppNotification(obj); 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);
} }
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);
MessagesStorage.getInstance().putMessages(arr, false, true); if (gettingDifference || updatesStartWaitTime == 0 || updatesStartWaitTime != 0 && updatesStartWaitTime + 1500 > System.currentTimeMillis()) {
} else if (!missingData && MessagesStorage.lastSeqValue != updates.seq) { if (updatesStartWaitTime == 0) {
FileLog.e("tmessages", "need get diff TL_updateShortChatMessage, seq: " + MessagesStorage.lastSeqValue + " " + updates.seq); updatesStartWaitTime = System.currentTimeMillis();
if (gettingDifference || updatesStartWaitTime == 0 || updatesStartWaitTime != 0 && updatesStartWaitTime + 1500 > System.currentTimeMillis()) { }
if (updatesStartWaitTime == 0) { FileLog.e("tmessages", "add TL_updateShortChatMessage to queue");
updatesStartWaitTime = System.currentTimeMillis(); 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) { } else if (updates instanceof TLRPC.TL_updateShortMessage) {
boolean missingData = users.get(updates.from_id) == null; boolean missingData = users.get(updates.from_id) == null;
if (MessagesStorage.lastSeqValue + 1 == updates.seq && !missingData) { if (missingData) {
TLRPC.TL_message message = new TLRPC.TL_message(); needGetDiff = true;
message.from_id = updates.from_id; } else {
message.id = updates.id; if (MessagesStorage.lastSeqValue + 1 == updates.seq && !gettingDifference) {
message.to_id = new TLRPC.TL_peerUser(); TLRPC.TL_message message = new TLRPC.TL_message();
message.to_id.user_id = updates.from_id; message.from_id = updates.from_id;
message.message = updates.message; message.id = updates.id;
message.date = updates.date; message.to_id = new TLRPC.TL_peerUser();
message.unread = true; message.to_id.user_id = updates.from_id;
message.media = new TLRPC.TL_messageMediaEmpty(); message.message = updates.message;
MessagesStorage.lastSeqValue = updates.seq; message.date = updates.date;
MessagesStorage.lastPtsValue = updates.pts; message.unread = true;
MessagesStorage.lastDateValue = updates.date; message.media = new TLRPC.TL_messageMediaEmpty();
final MessageObject obj = new MessageObject(message, null); MessagesStorage.lastSeqValue = updates.seq;
final ArrayList<MessageObject> objArr = new ArrayList<MessageObject>(); MessagesStorage.lastPtsValue = updates.pts;
objArr.add(obj); MessagesStorage.lastDateValue = updates.date;
ArrayList<TLRPC.Message> arr = new ArrayList<TLRPC.Message>(); final MessageObject obj = new MessageObject(message, null);
arr.add(message); final ArrayList<MessageObject> objArr = new ArrayList<MessageObject>();
final boolean printUpdate = updatePrintingUsersWithNewMessages(updates.from_id, objArr); objArr.add(obj);
if (printUpdate) { ArrayList<TLRPC.Message> arr = new ArrayList<TLRPC.Message>();
updatePrintingStrings(); arr.add(message);
} final boolean printUpdate = updatePrintingUsersWithNewMessages(updates.from_id, objArr);
Utilities.RunOnUIThread(new Runnable() { if (printUpdate) {
@Override updatePrintingStrings();
public void run() { }
if (printUpdate) { Utilities.RunOnUIThread(new Runnable() {
NotificationCenter.getInstance().postNotificationName(updateInterfaces, UPDATE_MASK_USER_PRINT); @Override
} public void run() {
if (obj.messageOwner.from_id != UserConfig.clientUserId) { if (printUpdate) {
long dialog_id; NotificationCenter.getInstance().postNotificationName(updateInterfaces, UPDATE_MASK_USER_PRINT);
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) { if (obj.messageOwner.from_id != UserConfig.clientUserId) {
showInAppNotification(obj); 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);
} }
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);
MessagesStorage.getInstance().putMessages(arr, false, true); if (gettingDifference || updatesStartWaitTime == 0 || updatesStartWaitTime != 0 && updatesStartWaitTime + 1500 > System.currentTimeMillis()) {
} else if (!missingData && MessagesStorage.lastSeqValue != updates.seq) { if (updatesStartWaitTime == 0) {
FileLog.e("tmessages", "need get diff TL_updateShortMessage, seq: " + MessagesStorage.lastSeqValue + " " + updates.seq); updatesStartWaitTime = System.currentTimeMillis();
if (gettingDifference || updatesStartWaitTime == 0 || updatesStartWaitTime != 0 && updatesStartWaitTime + 1500 > System.currentTimeMillis()) { }
if (updatesStartWaitTime == 0) { FileLog.e("tmessages", "add TL_updateShortMessage to queue");
updatesStartWaitTime = System.currentTimeMillis(); 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) { } 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); MessagesStorage.getInstance().putUsersAndChats(updates.users, updates.chats, true, true);
int lastPtsValue = MessagesStorage.lastPtsValue; int lastPtsValue = MessagesStorage.lastPtsValue;
int lastQtsValue = MessagesStorage.lastQtsValue; int lastQtsValue = MessagesStorage.lastQtsValue;
...@@ -3526,7 +3534,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter ...@@ -3526,7 +3534,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
} }
} }
} else if (updates instanceof TLRPC.TL_updates) { } 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); MessagesStorage.getInstance().putUsersAndChats(updates.users, updates.chats, true, true);
int lastPtsValue = MessagesStorage.lastPtsValue; int lastPtsValue = MessagesStorage.lastPtsValue;
int lastQtsValue = MessagesStorage.lastQtsValue; int lastQtsValue = MessagesStorage.lastQtsValue;
......
...@@ -34,7 +34,7 @@ public class NativeLoader { ...@@ -34,7 +34,7 @@ public class NativeLoader {
return; return;
} }
if (Build.VERSION.SDK_INT > 10) { if (Build.VERSION.SDK_INT >= 9) {
try { try {
String folder = null; String folder = null;
long libSize = 0; long libSize = 0;
......
...@@ -119,6 +119,25 @@ public class SerializedData extends AbsSerializedData { ...@@ -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() { public int readInt32() {
return readInt32(null); return readInt32(null);
} }
......
...@@ -7360,31 +7360,6 @@ public class TLRPC { ...@@ -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 class TL_upload_getFile extends TLObject {
public static int constructor = 0xe3a6cfb5; public static int constructor = 0xe3a6cfb5;
...@@ -8111,34 +8086,6 @@ public class TLRPC { ...@@ -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 //manually created
public static class UserStatus extends TLObject { public static class UserStatus extends TLObject {
...@@ -9162,4 +9109,60 @@ public class TLRPC { ...@@ -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;
}
}
}
} }
...@@ -271,7 +271,10 @@ public class TcpConnection extends PyroClientAdapter { ...@@ -271,7 +271,10 @@ public class TcpConnection extends PyroClientAdapter {
connect(); 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() { selector.scheduleTask(new Runnable() {
@Override @Override
public void run() { public void run() {
...@@ -285,9 +288,28 @@ public class TcpConnection extends PyroClientAdapter { ...@@ -285,9 +288,28 @@ public class TcpConnection extends PyroClientAdapter {
return; 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 (packetLength < 0x7f) {
if (reportAck) { if (reportAck) {
packetLength |= (1 << 7); packetLength |= (1 << 7);
...@@ -300,20 +322,16 @@ public class TcpConnection extends PyroClientAdapter { ...@@ -300,20 +322,16 @@ public class TcpConnection extends PyroClientAdapter {
} }
buffer.writeInt32(packetLength); buffer.writeInt32(packetLength);
} }
buffer.writeRaw(data); if (data != null) {
buffer.writeRaw(data);
} else {
buffer.writeRaw(buff);
BuffersStorage.getInstance().reuseFreeBuffer(buff);
}
final byte[] packet = buffer.toByteArray(); buffer.rewind();
ByteBuffer sendBuffer = ByteBuffer.allocate((firstPacket ? 1 : 0) + packet.length); client.write(buffer);
sendBuffer.rewind();
sendBuffer.order(ByteOrder.LITTLE_ENDIAN);
if (firstPacket) {
sendBuffer.put((byte)0xef);
firstPacket = false;
}
sendBuffer.put(packet);
sendBuffer.rewind();
client.write(sendBuffer);
} }
}); });
} }
......
...@@ -77,7 +77,7 @@ public class MessageObject { ...@@ -77,7 +77,7 @@ public class MessageObject {
fromUser = MessagesController.getInstance().users.get(message.from_id); fromUser = MessagesController.getInstance().users.get(message.from_id);
} }
if (message.action instanceof TLRPC.TL_messageActionChatCreate) { if (message.action instanceof TLRPC.TL_messageActionChatCreate) {
if (message.from_id == UserConfig.clientUserId) { if (isFromMe()) {
messageText = LocaleController.getString("ActionYouCreateGroup", R.string.ActionYouCreateGroup); messageText = LocaleController.getString("ActionYouCreateGroup", R.string.ActionYouCreateGroup);
} else { } else {
if (fromUser != null) { if (fromUser != null) {
...@@ -88,7 +88,7 @@ public class MessageObject { ...@@ -88,7 +88,7 @@ public class MessageObject {
} }
} else if (message.action instanceof TLRPC.TL_messageActionChatDeleteUser) { } else if (message.action instanceof TLRPC.TL_messageActionChatDeleteUser) {
if (message.action.user_id == message.from_id) { if (message.action.user_id == message.from_id) {
if (message.from_id == UserConfig.clientUserId) { if (isFromMe()) {
messageText = LocaleController.getString("ActionYouLeftUser", R.string.ActionYouLeftUser); messageText = LocaleController.getString("ActionYouLeftUser", R.string.ActionYouLeftUser);
} else { } else {
if (fromUser != null) { if (fromUser != null) {
...@@ -103,7 +103,7 @@ public class MessageObject { ...@@ -103,7 +103,7 @@ public class MessageObject {
MessagesController.getInstance().users.get(message.action.user_id); MessagesController.getInstance().users.get(message.action.user_id);
} }
if (who != null && fromUser != null) { 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)); 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) { } 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)); messageText = LocaleController.getString("ActionKickUserYou", R.string.ActionKickUserYou).replace("un1", Utilities.formatName(fromUser.first_name, fromUser.last_name));
...@@ -120,7 +120,7 @@ public class MessageObject { ...@@ -120,7 +120,7 @@ public class MessageObject {
MessagesController.getInstance().users.get(message.action.user_id); MessagesController.getInstance().users.get(message.action.user_id);
} }
if (whoUser != null && fromUser != null) { 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)); 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) { } 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)); messageText = LocaleController.getString("ActionAddUserYou", R.string.ActionAddUserYou).replace("un1", Utilities.formatName(fromUser.first_name, fromUser.last_name));
...@@ -135,7 +135,7 @@ public class MessageObject { ...@@ -135,7 +135,7 @@ public class MessageObject {
for (TLRPC.PhotoSize size : message.action.photo.sizes) { for (TLRPC.PhotoSize size : message.action.photo.sizes) {
photoThumbs.add(new PhotoObject(size)); photoThumbs.add(new PhotoObject(size));
} }
if (message.from_id == UserConfig.clientUserId) { if (isFromMe()) {
messageText = LocaleController.getString("ActionYouChangedPhoto", R.string.ActionYouChangedPhoto); messageText = LocaleController.getString("ActionYouChangedPhoto", R.string.ActionYouChangedPhoto);
} else { } else {
if (fromUser != null) { if (fromUser != null) {
...@@ -145,7 +145,7 @@ public class MessageObject { ...@@ -145,7 +145,7 @@ public class MessageObject {
} }
} }
} else if (message.action instanceof TLRPC.TL_messageActionChatEditTitle) { } 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); messageText = LocaleController.getString("ActionYouChangedTitle", R.string.ActionYouChangedTitle).replace("un2", message.action.title);
} else { } else {
if (fromUser != null) { if (fromUser != null) {
...@@ -155,7 +155,7 @@ public class MessageObject { ...@@ -155,7 +155,7 @@ public class MessageObject {
} }
} }
} else if (message.action instanceof TLRPC.TL_messageActionChatDeletePhoto) { } else if (message.action instanceof TLRPC.TL_messageActionChatDeletePhoto) {
if (message.from_id == UserConfig.clientUserId) { if (isFromMe()) {
messageText = LocaleController.getString("ActionYouRemovedPhoto", R.string.ActionYouRemovedPhoto); messageText = LocaleController.getString("ActionYouRemovedPhoto", R.string.ActionYouRemovedPhoto);
} else { } else {
if (fromUser != null) { if (fromUser != null) {
...@@ -182,7 +182,7 @@ public class MessageObject { ...@@ -182,7 +182,7 @@ public class MessageObject {
} else { } else {
timeString = String.format("%d", message.action.ttl); timeString = String.format("%d", message.action.ttl);
} }
if (message.from_id == UserConfig.clientUserId) { if (isFromMe()) {
messageText = LocaleController.formatString("MessageLifetimeChangedOutgoing", R.string.MessageLifetimeChangedOutgoing, timeString); messageText = LocaleController.formatString("MessageLifetimeChangedOutgoing", R.string.MessageLifetimeChangedOutgoing, timeString);
} else { } else {
if (fromUser != null) { if (fromUser != null) {
...@@ -192,7 +192,7 @@ public class MessageObject { ...@@ -192,7 +192,7 @@ public class MessageObject {
} }
} }
} else { } else {
if (message.from_id == UserConfig.clientUserId) { if (isFromMe()) {
messageText = LocaleController.getString("MessageLifetimeYouRemoved", R.string.MessageLifetimeYouRemoved); messageText = LocaleController.getString("MessageLifetimeYouRemoved", R.string.MessageLifetimeYouRemoved);
} else { } else {
if (fromUser != null) { if (fromUser != null) {
...@@ -265,22 +265,18 @@ public class MessageObject { ...@@ -265,22 +265,18 @@ public class MessageObject {
} else if (message.media != null && message.media instanceof TLRPC.TL_messageMediaPhoto) { } else if (message.media != null && message.media instanceof TLRPC.TL_messageMediaPhoto) {
contentType = type = 1; contentType = type = 1;
} else if (message.media != null && message.media instanceof TLRPC.TL_messageMediaGeo) { } else if (message.media != null && message.media instanceof TLRPC.TL_messageMediaGeo) {
if (message.from_id == UserConfig.clientUserId) { contentType = 1;
contentType = type = 4; type = 4;
} else {
contentType = type = 5;
}
} else if (message.media != null && message.media instanceof TLRPC.TL_messageMediaVideo) { } else if (message.media != null && message.media instanceof TLRPC.TL_messageMediaVideo) {
if (message.from_id == UserConfig.clientUserId) { contentType = 1;
contentType = type = 6; type = 3;
} else {
contentType = type = 7;
}
} else if (message.media != null && message.media instanceof TLRPC.TL_messageMediaContact) { } else if (message.media != null && message.media instanceof TLRPC.TL_messageMediaContact) {
if (message.from_id == UserConfig.clientUserId) { if (isFromMe()) {
contentType = type = 12; contentType = 4;
type = 12;
} else { } else {
contentType = type = 13; contentType = 5;
type = 13;
} }
} else if (message.media != null && message.media instanceof TLRPC.TL_messageMediaUnsupported) { } else if (message.media != null && message.media instanceof TLRPC.TL_messageMediaUnsupported) {
contentType = type = 0; contentType = type = 0;
...@@ -289,7 +285,7 @@ public class MessageObject { ...@@ -289,7 +285,7 @@ public class MessageObject {
contentType = 1; contentType = 1;
type = 8; type = 8;
} else { } else {
if (message.from_id == UserConfig.clientUserId) { if (isFromMe()) {
contentType = type = 8; contentType = type = 8;
} else { } else {
contentType = type = 9; contentType = type = 9;
...@@ -525,4 +521,12 @@ public class MessageObject { ...@@ -525,4 +521,12 @@ public class MessageObject {
linesOffset += currentBlockLinesCount; linesOffset += currentBlockLinesCount;
} }
} }
public boolean isOut() {
return messageOwner.out;
}
public boolean isFromMe() {
return messageOwner.from_id == UserConfig.clientUserId;
}
} }
...@@ -37,6 +37,9 @@ public class PhotoObject { ...@@ -37,6 +37,9 @@ public class PhotoObject {
} }
public static PhotoObject getClosestImageWithSize(ArrayList<PhotoObject> arr, int width, int height) { public static PhotoObject getClosestImageWithSize(ArrayList<PhotoObject> arr, int width, int height) {
if (arr == null) {
return null;
}
int closestWidth = 9999; int closestWidth = 9999;
int closestHeight = 9999; int closestHeight = 9999;
PhotoObject closestObject = null; PhotoObject closestObject = null;
...@@ -56,6 +59,9 @@ public class PhotoObject { ...@@ -56,6 +59,9 @@ public class PhotoObject {
} }
public static TLRPC.PhotoSize getClosestPhotoSizeWithSize(ArrayList<TLRPC.PhotoSize> sizes, int width, int height) { public static TLRPC.PhotoSize getClosestPhotoSizeWithSize(ArrayList<TLRPC.PhotoSize> sizes, int width, int height) {
if (sizes == null) {
return null;
}
int closestWidth = 9999; int closestWidth = 9999;
int closestHeight = 9999; int closestHeight = 9999;
TLRPC.PhotoSize closestObject = null; TLRPC.PhotoSize closestObject = null;
......
...@@ -298,7 +298,7 @@ public class ChatAudioCell extends ChatBaseCell implements SeekBar.SeekBarDelega ...@@ -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) { protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom); super.onLayout(changed, left, top, right, bottom);
if (currentMessageObject.messageOwner.out) { if (currentMessageObject.isOut()) {
avatarImage.imageX = layoutWidth - backgroundWidth + Utilities.dp(9); avatarImage.imageX = layoutWidth - backgroundWidth + Utilities.dp(9);
seekBarX = layoutWidth - backgroundWidth + Utilities.dp(97); seekBarX = layoutWidth - backgroundWidth + Utilities.dp(97);
buttonX = layoutWidth - backgroundWidth + Utilities.dp(67); buttonX = layoutWidth - backgroundWidth + Utilities.dp(67);
...@@ -359,7 +359,7 @@ public class ChatAudioCell extends ChatBaseCell implements SeekBar.SeekBarDelega ...@@ -359,7 +359,7 @@ public class ChatAudioCell extends ChatBaseCell implements SeekBar.SeekBarDelega
avatarImage.setImage((TLRPC.FileLocation)null, "50_50", getResources().getDrawable(Utilities.getUserAvatarForId(uid))); avatarImage.setImage((TLRPC.FileLocation)null, "50_50", getResources().getDrawable(Utilities.getUserAvatarForId(uid)));
} }
if (messageObject.messageOwner.out) { if (messageObject.isOut()) {
seekBar.type = 0; seekBar.type = 0;
progressView.setProgressColors(0xffb4e396, 0xff6ac453); progressView.setProgressColors(0xffb4e396, 0xff6ac453);
} else { } else {
...@@ -393,7 +393,7 @@ public class ChatAudioCell extends ChatBaseCell implements SeekBar.SeekBarDelega ...@@ -393,7 +393,7 @@ public class ChatAudioCell extends ChatBaseCell implements SeekBar.SeekBarDelega
canvas.restore(); canvas.restore();
int state = buttonState; int state = buttonState;
if (!currentMessageObject.messageOwner.out) { if (!currentMessageObject.isOut()) {
state += 4; state += 4;
timePaint.setColor(0xffa1aab3); timePaint.setColor(0xffa1aab3);
} else { } else {
......
...@@ -38,7 +38,7 @@ public class ChatBaseCell extends BaseCell { ...@@ -38,7 +38,7 @@ public class ChatBaseCell extends BaseCell {
public static interface ChatBaseCellDelegate { public static interface ChatBaseCellDelegate {
public abstract void didPressedUserAvatar(ChatBaseCell cell, TLRPC.User user); 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 void didLongPressed(ChatBaseCell cell);
public abstract boolean canPerformActions(); public abstract boolean canPerformActions();
public boolean onSwipeLeft(); public boolean onSwipeLeft();
...@@ -246,7 +246,7 @@ public class ChatBaseCell extends BaseCell { ...@@ -246,7 +246,7 @@ public class ChatBaseCell extends BaseCell {
} }
String newNameString = null; 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); newNameString = Utilities.formatName(newUser.first_name, newUser.last_name);
} }
...@@ -276,7 +276,7 @@ public class ChatBaseCell extends BaseCell { ...@@ -276,7 +276,7 @@ public class ChatBaseCell extends BaseCell {
} }
currentUser = MessagesController.getInstance().users.get(messageObject.messageOwner.from_id); currentUser = MessagesController.getInstance().users.get(messageObject.messageOwner.from_id);
if (isChat && !messageObject.messageOwner.out) { if (isChat && !messageObject.isOut()) {
isAvatarVisible = true; isAvatarVisible = true;
if (currentUser != null) { if (currentUser != null) {
if (currentUser.photo != null) { if (currentUser.photo != null) {
...@@ -289,7 +289,7 @@ public class ChatBaseCell extends BaseCell { ...@@ -289,7 +289,7 @@ public class ChatBaseCell extends BaseCell {
} }
if (!media) { if (!media) {
if (currentMessageObject.messageOwner.out) { if (currentMessageObject.isOut()) {
currentTimePaint = timePaintOut; currentTimePaint = timePaintOut;
} else { } else {
currentTimePaint = timePaintIn; currentTimePaint = timePaintIn;
...@@ -303,7 +303,7 @@ public class ChatBaseCell extends BaseCell { ...@@ -303,7 +303,7 @@ public class ChatBaseCell extends BaseCell {
namesOffset = 0; 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); currentNameString = Utilities.formatName(currentUser.first_name, currentUser.last_name);
nameWidth = getMaxNameWidth(); nameWidth = getMaxNameWidth();
...@@ -457,13 +457,13 @@ public class ChatBaseCell extends BaseCell { ...@@ -457,13 +457,13 @@ public class ChatBaseCell extends BaseCell {
timeLayout = new StaticLayout(currentTimeString, currentTimePaint, timeWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false); timeLayout = new StaticLayout(currentTimeString, currentTimePaint, timeWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
if (!media) { if (!media) {
if (!currentMessageObject.messageOwner.out) { if (!currentMessageObject.isOut()) {
timeX = backgroundWidth - Utilities.dp(9) - timeWidth + (isChat ? Utilities.dp(52) : 0); timeX = backgroundWidth - Utilities.dp(9) - timeWidth + (isChat ? Utilities.dp(52) : 0);
} else { } else {
timeX = layoutWidth - timeWidth - Utilities.dpf(38.5f); timeX = layoutWidth - timeWidth - Utilities.dpf(38.5f);
} }
} else { } else {
if (!currentMessageObject.messageOwner.out) { if (!currentMessageObject.isOut()) {
timeX = backgroundWidth - Utilities.dp(4) - timeWidth + (isChat ? Utilities.dp(52) : 0); timeX = backgroundWidth - Utilities.dp(4) - timeWidth + (isChat ? Utilities.dp(52) : 0);
} else { } else {
timeX = layoutWidth - timeWidth - Utilities.dpf(42.0f); timeX = layoutWidth - timeWidth - Utilities.dpf(42.0f);
...@@ -502,7 +502,7 @@ public class ChatBaseCell extends BaseCell { ...@@ -502,7 +502,7 @@ public class ChatBaseCell extends BaseCell {
} }
Drawable currentBackgroundDrawable = null; Drawable currentBackgroundDrawable = null;
if (currentMessageObject.messageOwner.out) { if (currentMessageObject.isOut()) {
if (isPressed() && isCheckPressed || !isCheckPressed && isPressed) { if (isPressed() && isCheckPressed || !isCheckPressed && isPressed) {
if (!media) { if (!media) {
currentBackgroundDrawable = backgroundDrawableOutSelected; currentBackgroundDrawable = backgroundDrawableOutSelected;
...@@ -551,7 +551,7 @@ public class ChatBaseCell extends BaseCell { ...@@ -551,7 +551,7 @@ public class ChatBaseCell extends BaseCell {
if (drawForwardedName && forwardedNameLayout != null) { if (drawForwardedName && forwardedNameLayout != null) {
canvas.save(); canvas.save();
if (currentMessageObject.messageOwner.out) { if (currentMessageObject.isOut()) {
forwardNamePaint.setColor(0xff4a923c); forwardNamePaint.setColor(0xff4a923c);
forwardNameX = currentBackgroundDrawable.getBounds().left + Utilities.dp(10); forwardNameX = currentBackgroundDrawable.getBounds().left + Utilities.dp(10);
forwardNameY = Utilities.dp(10 + (drawName ? 18 : 0)); forwardNameY = Utilities.dp(10 + (drawName ? 18 : 0));
...@@ -566,7 +566,7 @@ public class ChatBaseCell extends BaseCell { ...@@ -566,7 +566,7 @@ public class ChatBaseCell extends BaseCell {
} }
if (media) { 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); mediaBackgroundDrawable.draw(canvas);
canvas.save(); canvas.save();
...@@ -580,7 +580,7 @@ public class ChatBaseCell extends BaseCell { ...@@ -580,7 +580,7 @@ public class ChatBaseCell extends BaseCell {
canvas.restore(); canvas.restore();
} }
if (currentMessageObject.messageOwner.out) { if (currentMessageObject.isOut()) {
boolean drawCheck1 = false; boolean drawCheck1 = false;
boolean drawCheck2 = false; boolean drawCheck2 = false;
boolean drawClock = false; boolean drawClock = false;
......
...@@ -43,8 +43,10 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD ...@@ -43,8 +43,10 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
private static Drawable placeholderInDrawable; private static Drawable placeholderInDrawable;
private static Drawable placeholderOutDrawable; 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 TextPaint infoPaint;
private static MessageObject lastDownloadedGifMessage = null;
private GifDrawable gifDrawable = null; private GifDrawable gifDrawable = null;
...@@ -66,7 +68,8 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD ...@@ -66,7 +68,8 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
private int buttonY; private int buttonY;
private StaticLayout infoLayout; private StaticLayout infoLayout;
protected int infoWidth; private int infoWidth;
private int infoOffset = 0;
private String currentInfoString; private String currentInfoString;
public ChatMediaCellDelegate mediaDelegate = null; public ChatMediaCellDelegate mediaDelegate = null;
...@@ -83,6 +86,9 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD ...@@ -83,6 +86,9 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
buttonStatesDrawables[1][1] = getResources().getDrawable(R.drawable.photocancel_pressed); buttonStatesDrawables[1][1] = getResources().getDrawable(R.drawable.photocancel_pressed);
buttonStatesDrawables[2][0] = getResources().getDrawable(R.drawable.photogif); buttonStatesDrawables[2][0] = getResources().getDrawable(R.drawable.photogif);
buttonStatesDrawables[2][1] = getResources().getDrawable(R.drawable.photogif_pressed); 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 = new TextPaint(Paint.ANTI_ALIAS_FLAG);
infoPaint.setColor(0xffffffff); infoPaint.setColor(0xffffffff);
...@@ -187,10 +193,8 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD ...@@ -187,10 +193,8 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
private void didPressedImage() { private void didPressedImage() {
if (currentMessageObject.type == 1) { if (currentMessageObject.type == 1) {
if (buttonState == -1) { if (buttonState == -1) {
if (currentMessageObject.type == 1) { if (mediaDelegate != null) {
if (mediaDelegate != null) { mediaDelegate.didPressedImage(this);
mediaDelegate.didPressedImage(this);
}
} }
} else if (buttonState == 0) { } else if (buttonState == 0) {
didPressedButton(); didPressedButton();
...@@ -205,6 +209,14 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD ...@@ -205,6 +209,14 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
} else if (buttonState == 2 || buttonState == 0) { } else if (buttonState == 2 || buttonState == 0) {
didPressedButton(); 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 ...@@ -214,24 +226,32 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
if (currentMessageObject.imagePreview != null) { if (currentMessageObject.imagePreview != null) {
photoImage.setImage(currentPhotoObject.photoOwner.location, currentPhotoFilter, new BitmapDrawable(currentMessageObject.imagePreview), currentPhotoObject.photoOwner.size); photoImage.setImage(currentPhotoObject.photoOwner.location, currentPhotoFilter, new BitmapDrawable(currentMessageObject.imagePreview), currentPhotoObject.photoOwner.size);
} else { } 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) { } else if (currentMessageObject.type == 8) {
FileLoader.getInstance().loadFile(null, null, currentMessageObject.messageOwner.media.document, null); 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; progressVisible = true;
buttonState = 1; buttonState = 1;
invalidate(); invalidate();
} else if (buttonState == 1) { } 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) { if (delegate != null) {
delegate.didPressedCanceSendButton(this); delegate.didPressedCancelSendButton(this);
} }
} else { } else {
if (currentMessageObject.type == 1) { if (currentMessageObject.type == 1) {
FileLoader.getInstance().cancelLoadingForImageView(photoImage); FileLoader.getInstance().cancelLoadingForImageView(photoImage);
} else if (currentMessageObject.type == 8) { } else if (currentMessageObject.type == 8) {
FileLoader.getInstance().cancelLoadFile(null, null, currentMessageObject.messageOwner.media.document, null); 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; progressVisible = false;
buttonState = 0; buttonState = 0;
...@@ -247,6 +267,10 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD ...@@ -247,6 +267,10 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
buttonState = -1; buttonState = -1;
invalidate(); invalidate();
} }
} else if (buttonState == 3) {
if (mediaDelegate != null) {
mediaDelegate.didPressedImage(this);
}
} }
} }
...@@ -270,6 +294,18 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD ...@@ -270,6 +294,18 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
String str = Utilities.formatFileSize(messageObject.messageOwner.media.document.size); String str = Utilities.formatFileSize(messageObject.messageOwner.media.document.size);
if (currentInfoString == null || !currentInfoString.equals(str)) { if (currentInfoString == null || !currentInfoString.equals(str)) {
currentInfoString = 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)); infoWidth = (int) Math.ceil(infoPaint.measureText(currentInfoString));
infoLayout = new StaticLayout(currentInfoString, infoPaint, infoWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false); 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 ...@@ -278,81 +314,83 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
infoLayout = null; infoLayout = null;
} }
photoWidth = (int) (Math.min(Utilities.displaySize.x, Utilities.displaySize.y) * 0.7f); if (messageObject.type == 4) {
photoHeight = photoWidth + Utilities.dp(100); photoWidth = Utilities.dp(100);
if (messageObject.type == 6 || messageObject.type == 7) { photoHeight = Utilities.dp(100);
photoWidth = (int) (Math.min(Utilities.displaySize.x, Utilities.displaySize.y) / 2.5f); backgroundWidth = photoWidth + Utilities.dp(12);
photoHeight = photoWidth + 100;
}
if (photoWidth > 800) {
photoWidth = 800;
}
if (photoHeight > 800) {
photoHeight = 800;
}
currentPhotoObject = PhotoObject.getClosestImageWithSize(messageObject.photoThumbs, photoWidth, photoHeight); double lat = messageObject.messageOwner.media.geo.lat;
if (currentPhotoObject != null) { double lon = messageObject.messageOwner.media.geo._long;
float scale = (float) currentPhotoObject.photoOwner.w / (float) photoWidth; 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);
int w = (int) (currentPhotoObject.photoOwner.w / scale); } else {
int h = (int) (currentPhotoObject.photoOwner.h / scale); photoWidth = (int) (Math.min(Utilities.displaySize.x, Utilities.displaySize.y) * 0.7f);
if (h > photoHeight) { photoHeight = photoWidth + Utilities.dp(100);
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; if (photoWidth > 800) {
photoHeight = h; photoWidth = 800;
backgroundWidth = w + Utilities.dp(12); }
currentPhotoFilter = String.format(Locale.US, "%d_%d", (int) (w / Utilities.density), (int) (h / Utilities.density)); if (photoHeight > 800) {
photoHeight = 800;
}
if (currentPhotoObject.image != null) { currentPhotoObject = PhotoObject.getClosestImageWithSize(messageObject.photoThumbs, photoWidth, photoHeight);
photoImage.setImageBitmap(currentPhotoObject.image); if (currentPhotoObject != null) {
} else { float scale = (float) currentPhotoObject.photoOwner.w / (float) photoWidth;
boolean photoExist = true;
String fileName = MessageObject.getAttachFileName(currentPhotoObject.photoOwner); int w = (int) (currentPhotoObject.photoOwner.w / scale);
if (messageObject.type == 1) { int h = (int) (currentPhotoObject.photoOwner.h / scale);
File cacheFile = new File(Utilities.getCacheDir(), fileName); if (h > photoHeight) {
if (!cacheFile.exists()) { float scale2 = h;
photoExist = false; h = photoHeight;
} else { scale2 /= h;
MediaController.getInstance().removeLoadingFileObserver(this); 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);
} }
} }
if (photoExist || downloadPhotos) {
if (messageObject.imagePreview != null) { photoWidth = w;
photoImage.setImage(currentPhotoObject.photoOwner.location, currentPhotoFilter, new BitmapDrawable(messageObject.imagePreview), currentPhotoObject.photoOwner.size); photoHeight = h;
} else { backgroundWidth = w + Utilities.dp(12);
photoImage.setImage(currentPhotoObject.photoOwner.location, currentPhotoFilter, messageObject.messageOwner.out ? placeholderOutDrawable : placeholderInDrawable, currentPhotoObject.photoOwner.size); currentPhotoFilter = String.format(Locale.US, "%d_%d", (int) (w / Utilities.density), (int) (h / Utilities.density));
}
if (currentPhotoObject.image != null) {
photoImage.setImageBitmap(currentPhotoObject.image);
} else { } else {
if (messageObject.imagePreview != null) { boolean photoExist = true;
photoImage.setImageBitmap(messageObject.imagePreview); 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 { } else {
photoImage.setImageBitmap(messageObject.messageOwner.out ? placeholderOutDrawable : placeholderInDrawable); if (messageObject.imagePreview != null) {
photoImage.setImageBitmap(messageObject.imagePreview);
} else {
photoImage.setImageBitmap(messageObject.isOut() ? placeholderOutDrawable : placeholderInDrawable);
}
} }
} }
} else {
photoImage.setImageBitmap(messageObject.isOut() ? placeholderOutDrawable : placeholderInDrawable);
} }
} else {
photoImage.setImageBitmap(messageObject.messageOwner.out ? placeholderOutDrawable : placeholderInDrawable);
} }
invalidate(); 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(); updateButtonState();
} }
...@@ -366,7 +404,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD ...@@ -366,7 +404,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
} }
fileName = MessageObject.getAttachFileName(currentPhotoObject.photoOwner); fileName = MessageObject.getAttachFileName(currentPhotoObject.photoOwner);
cacheFile = new File(Utilities.getCacheDir(), fileName); 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) { if (currentMessageObject.messageOwner.attachPath != null && currentMessageObject.messageOwner.attachPath.length() != 0) {
File f = new File(currentMessageObject.messageOwner.attachPath); File f = new File(currentMessageObject.messageOwner.attachPath);
if (f.exists()) { if (f.exists()) {
...@@ -381,7 +419,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD ...@@ -381,7 +419,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
if (fileName == null) { if (fileName == null) {
return; 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) { if (currentMessageObject.messageOwner.attachPath != null) {
MediaController.getInstance().addLoadingFileObserver(currentMessageObject.messageOwner.attachPath, this); MediaController.getInstance().addLoadingFileObserver(currentMessageObject.messageOwner.attachPath, this);
progressVisible = true; progressVisible = true;
...@@ -430,6 +468,8 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD ...@@ -430,6 +468,8 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
progressVisible = false; progressVisible = false;
if (currentMessageObject.type == 8 && (gifDrawable == null || gifDrawable != null && !gifDrawable.isRunning())) { if (currentMessageObject.type == 8 && (gifDrawable == null || gifDrawable != null && !gifDrawable.isRunning())) {
buttonState = 2; buttonState = 2;
} else if (currentMessageObject.type == 3) {
buttonState = 3;
} else { } else {
buttonState = -1; buttonState = -1;
} }
...@@ -447,7 +487,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD ...@@ -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) { protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom); super.onLayout(changed, left, top, right, bottom);
if (currentMessageObject.messageOwner.out) { if (currentMessageObject.isOut()) {
photoImage.imageX = layoutWidth - backgroundWidth - Utilities.dp(3); photoImage.imageX = layoutWidth - backgroundWidth - Utilities.dp(3);
} else { } else {
if (isChat) { if (isChat) {
...@@ -490,18 +530,23 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD ...@@ -490,18 +530,23 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
canvas.restore(); canvas.restore();
} }
if (buttonState >= 0 && buttonState < 3) { if (buttonState >= 0 && buttonState < 4) {
Drawable currentButtonDrawable = buttonStatesDrawables[buttonState][buttonPressed]; Drawable currentButtonDrawable = buttonStatesDrawables[buttonState][buttonPressed];
setDrawableBounds(currentButtonDrawable, buttonX, buttonY); setDrawableBounds(currentButtonDrawable, buttonX, buttonY);
currentButtonDrawable.draw(canvas); currentButtonDrawable.draw(canvas);
} }
if (infoLayout != null && (buttonState == 1 || buttonState == 0)) { 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), Utilities.dpf(16.5f)); setDrawableBounds(mediaBackgroundDrawable, photoImage.imageX + Utilities.dp(4), photoImage.imageY + Utilities.dp(4), infoWidth + Utilities.dp(8) + infoOffset, Utilities.dpf(16.5f));
mediaBackgroundDrawable.draw(canvas); 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.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); infoLayout.draw(canvas);
canvas.restore(); canvas.restore();
} }
...@@ -515,6 +560,9 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD ...@@ -515,6 +560,9 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
@Override @Override
public void onSuccessDownload(String fileName) { public void onSuccessDownload(String fileName) {
updateButtonState(); updateButtonState();
if (currentMessageObject.type == 8 && lastDownloadedGifMessage != null && lastDownloadedGifMessage.messageOwner.id == currentMessageObject.messageOwner.id && buttonState == 2) {
didPressedButton();
}
} }
@Override @Override
......
...@@ -131,7 +131,7 @@ public class ChatMessageCell extends ChatBaseCell { ...@@ -131,7 +131,7 @@ public class ChatMessageCell extends ChatBaseCell {
} }
pressedLink = null; pressedLink = null;
int maxWidth; int maxWidth;
if (isChat && !messageObject.messageOwner.out) { if (isChat && !messageObject.isOut()) {
maxWidth = Utilities.displaySize.x - Utilities.dp(122); maxWidth = Utilities.displaySize.x - Utilities.dp(122);
drawName = true; drawName = true;
} else { } else {
...@@ -149,7 +149,7 @@ public class ChatMessageCell extends ChatBaseCell { ...@@ -149,7 +149,7 @@ public class ChatMessageCell extends ChatBaseCell {
maxChildWidth = Math.max(maxChildWidth, forwardedNameWidth); maxChildWidth = Math.max(maxChildWidth, forwardedNameWidth);
int timeMore = timeWidth + Utilities.dp(6); int timeMore = timeWidth + Utilities.dp(6);
if (messageObject.messageOwner.out) { if (messageObject.isOut()) {
timeMore += Utilities.dpf(20.5f); timeMore += Utilities.dpf(20.5f);
} }
...@@ -176,7 +176,7 @@ public class ChatMessageCell extends ChatBaseCell { ...@@ -176,7 +176,7 @@ public class ChatMessageCell extends ChatBaseCell {
protected void onLayout(boolean changed, int left, int top, int right, int bottom) { protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom); super.onLayout(changed, left, top, right, bottom);
if (currentMessageObject.messageOwner.out) { if (currentMessageObject.isOut()) {
textX = layoutWidth - backgroundWidth + Utilities.dp(10); textX = layoutWidth - backgroundWidth + Utilities.dp(10);
textY = Utilities.dp(10) + namesOffset; textY = Utilities.dp(10) + namesOffset;
} else { } else {
...@@ -192,7 +192,7 @@ public class ChatMessageCell extends ChatBaseCell { ...@@ -192,7 +192,7 @@ public class ChatMessageCell extends ChatBaseCell {
return; return;
} }
if (currentMessageObject.messageOwner.out) { if (currentMessageObject.isOut()) {
textX = layoutWidth - backgroundWidth + Utilities.dp(10); textX = layoutWidth - backgroundWidth + Utilities.dp(10);
textY = Utilities.dp(10) + namesOffset; textY = Utilities.dp(10) + namesOffset;
} else { } else {
......
...@@ -465,7 +465,7 @@ public class DialogCell extends BaseCell { ...@@ -465,7 +465,7 @@ public class DialogCell extends BaseCell {
} else { } else {
if (chat != null) { if (chat != null) {
String name = ""; String name = "";
if (message.messageOwner.from_id == UserConfig.clientUserId) { if (message.isFromMe()) {
name = LocaleController.getString("FromYou", R.string.FromYou); name = LocaleController.getString("FromYou", R.string.FromYou);
} else { } else {
if (fromUser != null) { if (fromUser != null) {
...@@ -507,7 +507,7 @@ public class DialogCell extends BaseCell { ...@@ -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) { if (message.messageOwner.send_state == MessagesController.MESSAGE_SEND_STATE_SENDING) {
drawCheck1 = false; drawCheck1 = false;
drawCheck2 = false; drawCheck2 = false;
......
...@@ -64,7 +64,6 @@ import android.widget.EditText; ...@@ -64,7 +64,6 @@ import android.widget.EditText;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow; import android.widget.PopupWindow;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
...@@ -105,7 +104,6 @@ import java.util.ArrayList; ...@@ -105,7 +104,6 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.Locale;
import java.util.concurrent.Semaphore; import java.util.concurrent.Semaphore;
public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLayout.SizeNotifierRelativeLayoutDelegate, NotificationCenter.NotificationCenterDelegate, MessagesActivity.MessagesActivityDelegate, DocumentSelectActivity.DocumentSelectActivityDelegate { 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 ...@@ -1230,14 +1228,14 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
private int getMessageType(MessageObject messageObject) { private int getMessageType(MessageObject messageObject) {
if (currentEncryptedChat == null) { 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) { if (messageObject.messageOwner.send_state == MessagesController.MESSAGE_SEND_STATE_SEND_ERROR) {
return 0; return 0;
} else { } else {
return -1; return -1;
} }
} else { } else {
if (messageObject.type == 15) { if (messageObject.type == 7) {
return -1; return -1;
} else if (messageObject.type == 10 || messageObject.type == 11) { } else if (messageObject.type == 10 || messageObject.type == 11) {
if (messageObject.messageOwner.id == 0) { if (messageObject.messageOwner.id == 0) {
...@@ -1279,7 +1277,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa ...@@ -1279,7 +1277,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
} }
} }
} else { } else {
if (messageObject.type == 15) { if (messageObject.type == 7) {
return -1; return -1;
} else if (messageObject.messageOwner.send_state == MessagesController.MESSAGE_SEND_STATE_SEND_ERROR) { } else if (messageObject.messageOwner.send_state == MessagesController.MESSAGE_SEND_STATE_SEND_ERROR) {
return 0; return 0;
...@@ -1767,7 +1765,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa ...@@ -1767,7 +1765,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
if (minDate == 0 || obj.messageOwner.date < minDate) { if (minDate == 0 || obj.messageOwner.date < minDate) {
minDate = obj.messageOwner.date; minDate = obj.messageOwner.date;
} }
if (!obj.messageOwner.out && obj.messageOwner.unread) { if (!obj.isOut() && obj.messageOwner.unread) {
wasUnread = true; wasUnread = true;
} }
messagesDict.put(obj.messageOwner.id, obj); messagesDict.put(obj.messageOwner.id, obj);
...@@ -1804,7 +1802,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa ...@@ -1804,7 +1802,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
dateMsg.message = ""; dateMsg.message = "";
dateMsg.id = 0; dateMsg.id = 0;
MessageObject dateObj = new MessageObject(dateMsg, null); MessageObject dateObj = new MessageObject(dateMsg, null);
dateObj.contentType = dateObj.type = 15; dateObj.contentType = dateObj.type = 7;
boolean dateAdded = true; boolean dateAdded = true;
if (a != messArr.size() - 1) { if (a != messArr.size() - 1) {
MessageObject next = messArr.get(a + 1); MessageObject next = messArr.get(a + 1);
...@@ -1981,7 +1979,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa ...@@ -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) { if (currentEncryptedChat != null && obj.messageOwner.action != null && obj.messageOwner.action instanceof TLRPC.TL_messageActionTTLChange && timerButton != null) {
timerButton.setTime(obj.messageOwner.action.ttl); 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(); scrollToLastMessage();
return; return;
} }
...@@ -1995,7 +1993,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa ...@@ -1995,7 +1993,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
currentMinMsgId = Math.min(obj.messageOwner.id, currentMinMsgId); currentMinMsgId = Math.min(obj.messageOwner.id, currentMinMsgId);
} }
if (!obj.messageOwner.out && obj.messageOwner.unread) { if (!obj.isOut() && obj.messageOwner.unread) {
unread_to_load++; unread_to_load++;
currentMarkAsRead = true; currentMarkAsRead = true;
} }
...@@ -2033,11 +2031,11 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa ...@@ -2033,11 +2031,11 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
progressBarMap.put(obj.messageOwner.attachPath, null); progressBarMap.put(obj.messageOwner.attachPath, null);
} }
if (obj.messageOwner.out) { if (obj.isOut()) {
removeUnreadPlane(false); removeUnreadPlane(false);
} }
if (!obj.messageOwner.out && unreadMessageObject != null) { if (!obj.isOut() && unreadMessageObject != null) {
unread_to_load++; unread_to_load++;
} }
...@@ -2062,7 +2060,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa ...@@ -2062,7 +2060,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
dateObj.contentType = dateObj.type = 10; dateObj.contentType = dateObj.type = 10;
messages.add(0, dateObj); messages.add(0, dateObj);
} }
if (!obj.messageOwner.out && obj.messageOwner.unread) { if (!obj.isOut() && obj.messageOwner.unread) {
obj.messageOwner.unread = false; obj.messageOwner.unread = false;
markAsRead = true; markAsRead = true;
} }
...@@ -2316,9 +2314,9 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa ...@@ -2316,9 +2314,9 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
int date = (Integer)args[1]; int date = (Integer)args[1];
boolean started = false; boolean started = false;
for (MessageObject obj : messages) { for (MessageObject obj : messages) {
if (!obj.messageOwner.out) { if (!obj.isOut()) {
continue; continue;
} else if (obj.messageOwner.out && !obj.messageOwner.unread) { } else if (obj.isOut() && !obj.messageOwner.unread) {
break; break;
} }
if (obj.messageOwner.date <= date) { if (obj.messageOwner.date <= date) {
...@@ -3014,12 +3012,12 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa ...@@ -3014,12 +3012,12 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
if (currentEncryptedChat == null) { if (currentEncryptedChat == null) {
if (i == 0) { if (i == 0) {
String fileName = selectedObject.getFileName(); String fileName = selectedObject.getFileName();
if (selectedObject.type == 6 || selectedObject.type == 7) { if (selectedObject.type == 3) {
MediaController.saveFile(fileName, parentActivity, 1, null); MediaController.saveFile(fileName, selectedObject.messageOwner.attachPath, parentActivity, 1, null);
} else if (selectedObject.type == 1) { } 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) { } 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) { } else if (i == 1) {
processSelectedOption(2); processSelectedOption(2);
...@@ -3037,12 +3035,12 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa ...@@ -3037,12 +3035,12 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
if (currentEncryptedChat == null) { if (currentEncryptedChat == null) {
if (i == 1) { if (i == 1) {
String fileName = selectedObject.getFileName(); String fileName = selectedObject.getFileName();
if (selectedObject.type == 6 || selectedObject.type == 7) { if (selectedObject.type == 3) {
MediaController.saveFile(fileName, parentActivity, 1, null); MediaController.saveFile(fileName, selectedObject.messageOwner.attachPath, parentActivity, 1, null);
} else if (selectedObject.type == 1) { } 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) { } 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) { } else if (i == 2) {
processSelectedOption(2); processSelectedOption(2);
...@@ -3120,7 +3118,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa ...@@ -3120,7 +3118,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
} else { } else {
MessagesController.getInstance().sendMessage(selectedObject.messageOwner.message, dialog_id); 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); MessagesController.getInstance().sendMessage(selectedObject.messageOwner.media.geo.lat, selectedObject.messageOwner.media.geo._long, dialog_id);
} else if (selectedObject.type == 1) { } else if (selectedObject.type == 1) {
if (selectedObject.messageOwner instanceof TLRPC.TL_messageForwarded) { if (selectedObject.messageOwner instanceof TLRPC.TL_messageForwarded) {
...@@ -3129,7 +3127,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa ...@@ -3129,7 +3127,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
TLRPC.TL_photo photo = (TLRPC.TL_photo)selectedObject.messageOwner.media.photo; TLRPC.TL_photo photo = (TLRPC.TL_photo)selectedObject.messageOwner.media.photo;
MessagesController.getInstance().sendMessage(photo, dialog_id); 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) { if (selectedObject.messageOwner instanceof TLRPC.TL_messageForwarded) {
MessagesController.getInstance().sendMessage(selectedObject, dialog_id); MessagesController.getInstance().sendMessage(selectedObject, dialog_id);
} else { } else {
...@@ -3481,11 +3479,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa ...@@ -3481,11 +3479,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
private void updateRowBackground(ChatListRowHolderEx holder, boolean disableSelection, boolean selected) { private void updateRowBackground(ChatListRowHolderEx holder, boolean disableSelection, boolean selected) {
int messageType = holder.message.type; int messageType = holder.message.type;
if (!disableSelection) { if (!disableSelection) {
if (messageType == 4 || messageType == 6) { if (messageType == 12) {
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) {
holder.chatBubbleView.setBackgroundResource(R.drawable.chat_outgoing_text_states); holder.chatBubbleView.setBackgroundResource(R.drawable.chat_outgoing_text_states);
holder.chatBubbleView.setPadding(Utilities.dp(6), Utilities.dp(6), Utilities.dp(18), 0); holder.chatBubbleView.setPadding(Utilities.dp(6), Utilities.dp(6), Utilities.dp(18), 0);
} else if (messageType == 13) { } else if (messageType == 13) {
...@@ -3499,19 +3493,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa ...@@ -3499,19 +3493,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
holder.chatBubbleView.setPadding(Utilities.dp(18), Utilities.dp(9), Utilities.dp(9), 0); holder.chatBubbleView.setPadding(Utilities.dp(18), Utilities.dp(9), Utilities.dp(9), 0);
} }
} else { } else {
if (messageType == 4 || messageType == 6) { if (messageType == 12) {
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 (selected) { if (selected) {
holder.chatBubbleView.setBackgroundResource(R.drawable.msg_out_selected); holder.chatBubbleView.setBackgroundResource(R.drawable.msg_out_selected);
} else { } else {
...@@ -3543,6 +3525,26 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa ...@@ -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 class ChatAdapter extends BaseAdapter {
private Context mContext; private Context mContext;
...@@ -3617,38 +3619,22 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa ...@@ -3617,38 +3619,22 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (type == 0) { if (type == 0) {
view = new ChatMessageCell(mContext); view = new ChatMessageCell(mContext);
} else if (type == 4) { } if (type == 1) {
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) {
view = new ChatMediaCell(mContext); view = new ChatMediaCell(mContext);
((ChatMediaCell)view).downloadPhotos = downloadPhotos; ((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) { } else if (type == 10) {
view = li.inflate(R.layout.chat_action_message_layout, viewGroup, false); view = li.inflate(R.layout.chat_action_message_layout, viewGroup, false);
} else if (type == 11) { } else if (type == 11) {
view = li.inflate(R.layout.chat_action_change_photo_layout, viewGroup, false); 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); view = li.inflate(R.layout.chat_outgoing_contact_layout, viewGroup, false);
} else if (type == 13) { } else if (type == 5) {
if (currentChat != null) { if (currentChat != null) {
view = li.inflate(R.layout.chat_group_incoming_contact_layout, viewGroup, false); view = li.inflate(R.layout.chat_group_incoming_contact_layout, viewGroup, false);
} else { } else {
view = li.inflate(R.layout.chat_incoming_contact_layout, viewGroup, false); 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); view = li.inflate(R.layout.chat_unread_layout, viewGroup, false);
} else if (type == 8) { } else if (type == 8) {
view = li.inflate(R.layout.chat_outgoing_document_layout, viewGroup, false); view = li.inflate(R.layout.chat_outgoing_document_layout, viewGroup, false);
...@@ -3691,7 +3677,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa ...@@ -3691,7 +3677,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
} }
@Override @Override
public void didPressedCanceSendButton(ChatBaseCell cell) { public void didPressedCancelSendButton(ChatBaseCell cell) {
MessageObject message = cell.getMessageObject(); MessageObject message = cell.getMessageObject();
if (message.messageOwner.send_state != 0) { if (message.messageOwner.send_state != 0) {
MessagesController.getInstance().cancelSendingMessage(message); MessagesController.getInstance().cancelSendingMessage(message);
...@@ -3722,9 +3708,40 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa ...@@ -3722,9 +3708,40 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
((ChatMediaCell)view).mediaDelegate = new ChatMediaCell.ChatMediaCellDelegate() { ((ChatMediaCell)view).mediaDelegate = new ChatMediaCell.ChatMediaCellDelegate() {
@Override @Override
public void didPressedImage(ChatBaseCell cell) { public void didPressedImage(ChatBaseCell cell) {
NotificationCenter.getInstance().addToMemCache(51, cell.getMessageObject()); MessageObject message = cell.getMessageObject();
Intent intent = new Intent(parentActivity, GalleryImageViewer.class); if (message.messageOwner.send_state == MessagesController.MESSAGE_SEND_STATE_SEND_ERROR) {
startActivity(intent); 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 ...@@ -3757,11 +3774,11 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
if (!endReached && messages.size() != 0) { if (!endReached && messages.size() != 0) {
offset = 0; offset = 0;
if (i == 0) { if (i == 0) {
return 14; return 6;
} }
} }
if (!unread_end_reached && i == (messages.size() + 1 - offset)) { if (!unread_end_reached && i == (messages.size() + 1 - offset)) {
return 14; return 6;
} }
MessageObject message = messages.get(messages.size() - i - offset); MessageObject message = messages.get(messages.size() - i - offset);
return message.contentType; return message.contentType;
...@@ -3769,7 +3786,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa ...@@ -3769,7 +3786,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
@Override @Override
public int getViewTypeCount() { public int getViewTypeCount() {
return 16; return 12;
} }
@Override @Override
...@@ -3838,91 +3855,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa ...@@ -3838,91 +3855,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
nameTextView.setTextColor(Utilities.getColorForId(message.messageOwner.from_id)); nameTextView.setTextColor(Utilities.getColorForId(message.messageOwner.from_id));
} }
if (type == 6 || type == 7) { if (type == 11 || type == 10) {
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) {
int width = displaySize.x - Utilities.dp(30); int width = displaySize.x - Utilities.dp(30);
messageTextView.setText(message.messageText); messageTextView.setText(message.messageText);
messageTextView.setMaxWidth(width); messageTextView.setMaxWidth(width);
...@@ -3979,7 +3912,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa ...@@ -3979,7 +3912,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
contactAvatar.setImageResource(Utilities.getUserAvatarForId(message.messageOwner.media.user_id)); contactAvatar.setImageResource(Utilities.getUserAvatarForId(message.messageOwner.media.user_id));
addContactView.setVisibility(View.GONE); addContactView.setVisibility(View.GONE);
} }
} else if (type == 15) { } else if (type == 7) {
if (unread_to_load == 1) { if (unread_to_load == 1) {
messageTextView.setText(LocaleController.formatString("OneNewMessage", R.string.OneNewMessage, unread_to_load)); messageTextView.setText(LocaleController.formatString("OneNewMessage", R.string.OneNewMessage, unread_to_load));
} else { } else {
...@@ -4035,15 +3968,11 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa ...@@ -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 (halfCheckImage != null) {
if (message.messageOwner.send_state == MessagesController.MESSAGE_SEND_STATE_SENDING) { if (message.messageOwner.send_state == MessagesController.MESSAGE_SEND_STATE_SENDING) {
checkImage.setVisibility(View.INVISIBLE); checkImage.setVisibility(View.INVISIBLE);
if (type == 6 || type == 4) { halfCheckImage.setImageResource(R.drawable.msg_clock);
halfCheckImage.setImageResource(R.drawable.msg_clock_photo);
} else {
halfCheckImage.setImageResource(R.drawable.msg_clock);
}
halfCheckImage.setVisibility(View.VISIBLE); halfCheckImage.setVisibility(View.VISIBLE);
if (actionView != null) { if (actionView != null) {
if (actionView != null) { if (actionView != null) {
...@@ -4077,19 +4006,11 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa ...@@ -4077,19 +4006,11 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
if (!message.messageOwner.unread) { if (!message.messageOwner.unread) {
halfCheckImage.setVisibility(View.VISIBLE); halfCheckImage.setVisibility(View.VISIBLE);
checkImage.setVisibility(View.VISIBLE); checkImage.setVisibility(View.VISIBLE);
if (type == 6 || type == 4) { halfCheckImage.setImageResource(R.drawable.msg_halfcheck);
halfCheckImage.setImageResource(R.drawable.msg_halfcheck_w);
} else {
halfCheckImage.setImageResource(R.drawable.msg_halfcheck);
}
} else { } else {
halfCheckImage.setVisibility(View.VISIBLE); halfCheckImage.setVisibility(View.VISIBLE);
checkImage.setVisibility(View.INVISIBLE); checkImage.setVisibility(View.INVISIBLE);
if (type == 6 || type == 4) { halfCheckImage.setImageResource(R.drawable.msg_check);
halfCheckImage.setImageResource(R.drawable.msg_check_w);
} else {
halfCheckImage.setImageResource(R.drawable.msg_check);
}
} }
if (actionView != null) { if (actionView != null) {
actionView.setVisibility(View.GONE); actionView.setVisibility(View.GONE);
...@@ -4100,7 +4021,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa ...@@ -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(); Integer tag = (Integer)actionProgress.getTag();
String file = progressByTag.get(tag); String file = progressByTag.get(tag);
if (file != null) { if (file != null) {
...@@ -4122,9 +4043,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa ...@@ -4122,9 +4043,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
if (f.exists()) { if (f.exists()) {
if (actionAttachButton != null) { if (actionAttachButton != null) {
actionAttachButton.setVisibility(View.VISIBLE); actionAttachButton.setVisibility(View.VISIBLE);
if (message.type == 6 || message.type == 7) { if (message.type == 8 || message.type == 9) {
actionAttachButton.setText(LocaleController.getString("ViewVideo", R.string.ViewVideo));
} else if (message.type == 8 || message.type == 9) {
actionAttachButton.setText(LocaleController.getString("Open", R.string.Open)); actionAttachButton.setText(LocaleController.getString("Open", R.string.Open));
} }
} }
...@@ -4140,9 +4059,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa ...@@ -4140,9 +4059,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
if ((cacheFile = new File(Utilities.getCacheDir(), fileName)).exists()) { if ((cacheFile = new File(Utilities.getCacheDir(), fileName)).exists()) {
if (actionAttachButton != null) { if (actionAttachButton != null) {
actionAttachButton.setVisibility(View.VISIBLE); actionAttachButton.setVisibility(View.VISIBLE);
if (message.type == 6 || message.type == 7) { if (message.type == 8 || message.type == 9) {
actionAttachButton.setText(LocaleController.getString("ViewVideo", R.string.ViewVideo));
} else if (message.type == 8 || message.type == 9) {
actionAttachButton.setText(LocaleController.getString("Open", R.string.Open)); actionAttachButton.setText(LocaleController.getString("Open", R.string.Open));
} }
} }
...@@ -4179,9 +4096,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa ...@@ -4179,9 +4096,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
} }
if (actionAttachButton != null) { if (actionAttachButton != null) {
actionAttachButton.setVisibility(View.VISIBLE); actionAttachButton.setVisibility(View.VISIBLE);
if (message.type == 6 || message.type == 7) { if (message.type == 8 || message.type == 9) {
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) {
actionAttachButton.setText(LocaleController.getString("DOWNLOAD", R.string.DOWNLOAD)); actionAttachButton.setText(LocaleController.getString("DOWNLOAD", R.string.DOWNLOAD));
} }
} }
...@@ -4412,13 +4327,11 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa ...@@ -4412,13 +4327,11 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
if (file != null) { if (file != null) {
progressBarMap.remove(file); 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); String file = progressByTag.get(tag);
if (file != null) { if (file != null) {
loadingFile.remove(file); loadingFile.remove(file);
if (message.type == 6 || message.type == 7) { if (message.type == 8 || message.type == 9) {
FileLoader.getInstance().cancelLoadFile(message.messageOwner.media.video, null, null, null);
} else if (message.type == 8 || message.type == 9) {
FileLoader.getInstance().cancelLoadFile(null, null, message.messageOwner.media.document, null); FileLoader.getInstance().cancelLoadFile(null, null, message.messageOwner.media.document, null);
} }
updateVisibleRows(); updateVisibleRows();
...@@ -4447,44 +4360,17 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa ...@@ -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) { private void processOnClick(View view) {
if (mActionMode != null) { if (mActionMode != null) {
processRowSelect(view); processRowSelect(view);
return; return;
} }
if (message != null) { if (message != null) {
if (message.type == 4 || message.type == 5) { if (message.type == 11) {
if (!isGoogleMapsInstalled()) {
return;
}
NotificationCenter.getInstance().addToMemCache(0, message);
LocationActivity fragment = new LocationActivity();
((LaunchActivity)parentActivity).presentFragment(fragment, "location_view", false);
} else if (message.type == 11) {
NotificationCenter.getInstance().addToMemCache(51, message); NotificationCenter.getInstance().addToMemCache(51, message);
Intent intent = new Intent(parentActivity, GalleryImageViewer.class); Intent intent = new Intent(parentActivity, GalleryImageViewer.class);
startActivity(intent); 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; File f = null;
String fileName = message.getFileName(); String fileName = message.getFileName();
if (message.messageOwner.attachPath != null && message.messageOwner.attachPath.length() != 0) { if (message.messageOwner.attachPath != null && message.messageOwner.attachPath.length() != 0) {
...@@ -4497,9 +4383,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa ...@@ -4497,9 +4383,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
String realMimeType = null; String realMimeType = null;
try { try {
Intent intent = new Intent(Intent.ACTION_VIEW); Intent intent = new Intent(Intent.ACTION_VIEW);
if (message.type == 6 || message.type == 7) { if (message.type == 8 || message.type == 9) {
intent.setDataAndType(Uri.fromFile(f), "video/mp4");
} else if (message.type == 8 || message.type == 9) {
MimeTypeMap myMime = MimeTypeMap.getSingleton(); MimeTypeMap myMime = MimeTypeMap.getSingleton();
int idx = fileName.lastIndexOf("."); int idx = fileName.lastIndexOf(".");
if (idx != -1) { if (idx != -1) {
...@@ -4525,16 +4409,14 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa ...@@ -4525,16 +4409,14 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
startActivity(intent); startActivity(intent);
} }
} catch (Exception e) { } catch (Exception e) {
alertUserOpenError(); alertUserOpenError(message);
} }
} else { } 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)) { if (!loadingFile.containsKey(fileName)) {
progressByTag.put((Integer)actionProgress.getTag(), fileName); progressByTag.put((Integer)actionProgress.getTag(), fileName);
addToLoadingFile(fileName, actionProgress); addToLoadingFile(fileName, actionProgress);
if (message.type == 6 || message.type == 7) { if (message.type == 8 || message.type == 9) {
FileLoader.getInstance().loadFile(message.messageOwner.media.video, null, null, null);
} else if (message.type == 8 || message.type == 9) {
FileLoader.getInstance().loadFile(null, null, message.messageOwner.media.document, null); FileLoader.getInstance().loadFile(null, null, message.messageOwner.media.document, null);
} }
updateVisibleRows(); updateVisibleRows();
......
...@@ -726,9 +726,9 @@ public class GalleryImageViewer extends AbstractGalleryActivity implements Notif ...@@ -726,9 +726,9 @@ public class GalleryImageViewer extends AbstractGalleryActivity implements Notif
return; return;
} }
if (isVideo) { if (isVideo) {
MediaController.saveFile(currentFileName, this, 1, null); MediaController.saveFile(currentFileName, null, this, 1, null);
} else { } else {
MediaController.saveFile(currentFileName, this, 0, null); MediaController.saveFile(currentFileName, null, this, 0, null);
} }
break; break;
// case R.id.gallery_menu_send: { // case R.id.gallery_menu_send: {
......
...@@ -182,7 +182,7 @@ public class PhotoCropActivity extends BaseFragment { ...@@ -182,7 +182,7 @@ public class PhotoCropActivity extends BaseFragment {
} }
private void updateBitmapSize() { private void updateBitmapSize() {
if (viewWidth == 0 || viewHeight == 0) { if (viewWidth == 0 || viewHeight == 0 || imageToCrop == null) {
return; return;
} }
float percX = (rectX - bitmapX) / bitmapWidth; float percX = (rectX - bitmapX) / bitmapWidth;
......
...@@ -21,10 +21,12 @@ import android.os.Bundle; ...@@ -21,10 +21,12 @@ import android.os.Bundle;
import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity; import android.support.v7.app.ActionBarActivity;
import android.text.Html; import android.text.Html;
import android.text.Spannable;
import android.text.method.LinkMovementMethod; import android.text.method.LinkMovementMethod;
import android.util.Base64; import android.util.Base64;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.AdapterView; import android.widget.AdapterView;
...@@ -93,6 +95,18 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter ...@@ -93,6 +95,18 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
private int telegramFaqRow; private int telegramFaqRow;
private int languageRow; 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 @Override
public boolean onFragmentCreate() { public boolean onFragmentCreate() {
super.onFragmentCreate(); super.onFragmentCreate();
...@@ -252,7 +266,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter ...@@ -252,7 +266,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
message.setText(Html.fromHtml(LocaleController.getString("AskAQuestionInfo", R.string.AskAQuestionInfo))); message.setText(Html.fromHtml(LocaleController.getString("AskAQuestionInfo", R.string.AskAQuestionInfo)));
message.setTextSize(18); message.setTextSize(18);
message.setPadding(Utilities.dp(8), Utilities.dp(5), Utilities.dp(8), Utilities.dp(6)); 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); AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
builder.setView(message); builder.setView(message);
...@@ -642,6 +656,9 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter ...@@ -642,6 +656,9 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
button2.setOnClickListener(new View.OnClickListener() { button2.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
if (parentActivity == null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity); AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
......
<?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>
\ No newline at end of file
<?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>
\ No newline at end of file
<?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>
\ No newline at end of file
<?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>
\ No newline at end of file
<?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>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment