Commit 22a0c2ac authored by DrKLO's avatar DrKLO

Fixes (unstable, don't upload to markets)

parent c6b1a343
......@@ -9,12 +9,11 @@ static inline uint64_t get_colors (const uint8_t *p) {
return p[0] + (p[1] << 16) + ((uint64_t)p[2] << 32);
}
static void fastBlur(int imageWidth, int imageHeight, int imageStride, void *pixels) {
static void fastBlurMore(int imageWidth, int imageHeight, int imageStride, void *pixels, int radius) {
uint8_t *pix = (uint8_t *)pixels;
const int w = imageWidth;
const int h = imageHeight;
const int stride = imageStride;
const int radius = 3;
const int r1 = radius + 1;
const int div = radius * 2 + 1;
......@@ -23,6 +22,98 @@ static void fastBlur(int imageWidth, int imageHeight, int imageStride, void *pix
}
uint64_t *rgb = malloc(imageWidth * imageHeight * sizeof(uint64_t));
if (rgb == NULL) {
return;
}
int x, y, i;
int yw = 0;
const int we = w - r1;
for (y = 0; y < h; y++) {
uint64_t cur = get_colors (&pix[yw]);
uint64_t rgballsum = -radius * cur;
uint64_t rgbsum = cur * ((r1 * (r1 + 1)) >> 1);
for (i = 1; i <= radius; i++) {
uint64_t cur = get_colors (&pix[yw + i * 4]);
rgbsum += cur * (r1 - i);
rgballsum += cur;
}
x = 0;
#define update(start, middle, end) \
rgb[y * w + x] = (rgbsum >> 6) & 0x00FF00FF00FF00FF; \
rgballsum += get_colors (&pix[yw + (start) * 4]) - 2 * get_colors (&pix[yw + (middle) * 4]) + get_colors (&pix[yw + (end) * 4]); \
rgbsum += rgballsum; \
x++; \
while (x < r1) {
update (0, x, x + r1);
}
while (x < we) {
update (x - r1, x, x + r1);
}
while (x < w) {
update (x - r1, x, w - 1);
}
#undef update
yw += stride;
}
const int he = h - r1;
for (x = 0; x < w; x++) {
uint64_t rgballsum = -radius * rgb[x];
uint64_t rgbsum = rgb[x] * ((r1 * (r1 + 1)) >> 1);
for (i = 1; i <= radius; i++) {
rgbsum += rgb[i * w + x] * (r1 - i);
rgballsum += rgb[i * w + x];
}
y = 0;
int yi = x * 4;
#define update(start, middle, end) \
int64_t res = rgbsum >> 6; \
pix[yi] = res; \
pix[yi + 1] = res >> 16; \
pix[yi + 2] = res >> 32; \
rgballsum += rgb[x + (start) * w] - 2 * rgb[x + (middle) * w] + rgb[x + (end) * w]; \
rgbsum += rgballsum; \
y++; \
yi += stride;
while (y < r1) {
update (0, y, y + r1);
}
while (y < he) {
update (y - r1, y, y + r1);
}
while (y < h) {
update (y - r1, y, h - 1);
}
#undef update
}
}
static void fastBlur(int imageWidth, int imageHeight, int imageStride, void *pixels, int radius) {
uint8_t *pix = (uint8_t *)pixels;
const int w = imageWidth;
const int h = imageHeight;
const int stride = imageStride;
const int r1 = radius + 1;
const int div = radius * 2 + 1;
if (radius > 15 || div >= w || div >= h || w * h > 90 * 90 || imageStride > imageWidth * 4) {
return;
}
uint64_t *rgb = malloc(imageWidth * imageHeight * sizeof(uint64_t));
if (rgb == NULL) {
return;
}
int x, y, i;
......@@ -111,7 +202,7 @@ METHODDEF(void) my_error_exit(j_common_ptr cinfo) {
longjmp(myerr->setjmp_buffer, 1);
}
JNIEXPORT void Java_org_telegram_messenger_Utilities_blurBitmap(JNIEnv *env, jclass class, jobject bitmap) {
JNIEXPORT void Java_org_telegram_messenger_Utilities_blurBitmap(JNIEnv *env, jclass class, jobject bitmap, int radius) {
if (!bitmap) {
return;
}
......@@ -130,7 +221,11 @@ JNIEXPORT void Java_org_telegram_messenger_Utilities_blurBitmap(JNIEnv *env, jcl
if (AndroidBitmap_lockPixels(env, bitmap, &pixels) < 0) {
return;
}
fastBlur(info.width, info.height, info.stride, pixels);
if (radius <= 3) {
fastBlur(info.width, info.height, info.stride, pixels, radius);
} else {
fastBlurMore(info.width, info.height, info.stride, pixels, radius);
}
AndroidBitmap_unlockPixels(env, bitmap);
}
......
......@@ -274,6 +274,10 @@ public class AndroidUtilities {
}
}
public static void CancelRunOnUIThread(Runnable runnable) {
ApplicationLoader.applicationHandler.removeCallbacks(runnable);
}
public static boolean isTablet() {
if (isTablet == null) {
isTablet = ApplicationLoader.applicationContext.getResources().getBoolean(R.bool.isTablet);
......
......@@ -28,7 +28,6 @@ import android.provider.MediaStore;
import org.telegram.messenger.DispatchQueue;
import org.telegram.messenger.FileLoader;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.R;
import org.telegram.messenger.TLRPC;
import org.telegram.messenger.UserConfig;
import org.telegram.messenger.Utilities;
......@@ -293,7 +292,7 @@ public class ImageLoader {
}
}
if (image != null && blur && bitmapH < 100 && bitmapW < 100) {
Utilities.blurBitmap(image);
Utilities.blurBitmap(image, 3);
}
}
if (runtimeHack != null) {
......
......@@ -35,6 +35,7 @@ public class ImageReceiver {
private boolean isVisible = true;
private boolean isAspectFit = false;
private boolean lastCacheOnly = false;
private boolean forcePreview = false;
public ImageReceiver() {
......@@ -195,7 +196,7 @@ public class ImageReceiver {
public boolean draw(Canvas canvas, int x, int y, int w, int h) {
try {
Drawable bitmapDrawable = currentImage;
if (bitmapDrawable == null && last_placeholder != null && last_placeholder instanceof BitmapDrawable) {
if (forcePreview || bitmapDrawable == null && last_placeholder != null && last_placeholder instanceof BitmapDrawable) {
bitmapDrawable = last_placeholder;
}
if (bitmapDrawable != null) {
......@@ -371,4 +372,8 @@ public class ImageReceiver {
public String getKey() {
return currentPath;
}
public void setForcePreview(boolean value) {
forcePreview = value;
}
}
......@@ -16,6 +16,7 @@ import android.text.StaticLayout;
import android.text.TextPaint;
import android.text.util.Linkify;
import org.telegram.messenger.ConnectionsManager;
import org.telegram.messenger.FileLoader;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.TLRPC;
......@@ -340,7 +341,7 @@ public class MessageObject {
if (!update) {
photoThumbs = new ArrayList<PhotoObject>();
for (TLRPC.PhotoSize size : messageOwner.action.photo.sizes) {
photoThumbs.add(new PhotoObject(size, preview));
photoThumbs.add(new PhotoObject(size, preview, isSecretMedia()));
}
} else if (photoThumbs != null && !photoThumbs.isEmpty()) {
for (PhotoObject photoObject : photoThumbs) {
......@@ -361,7 +362,7 @@ public class MessageObject {
if (!update) {
photoThumbs = new ArrayList<PhotoObject>();
for (TLRPC.PhotoSize size : messageOwner.media.photo.sizes) {
PhotoObject obj = new PhotoObject(size, preview);
PhotoObject obj = new PhotoObject(size, preview, isSecretMedia());
photoThumbs.add(obj);
if (imagePreview == null && obj.image != null) {
imagePreview = obj.image;
......@@ -383,7 +384,7 @@ public class MessageObject {
} else if (messageOwner.media instanceof TLRPC.TL_messageMediaVideo) {
if (!update) {
photoThumbs = new ArrayList<PhotoObject>();
PhotoObject obj = new PhotoObject(messageOwner.media.video.thumb, preview);
PhotoObject obj = new PhotoObject(messageOwner.media.video.thumb, preview, isSecretMedia());
photoThumbs.add(obj);
if (imagePreview == null && obj.image != null) {
imagePreview = obj.image;
......@@ -396,7 +397,7 @@ public class MessageObject {
if (!(messageOwner.media.document.thumb instanceof TLRPC.TL_photoSizeEmpty)) {
if (!update) {
photoThumbs = new ArrayList<PhotoObject>();
PhotoObject obj = new PhotoObject(messageOwner.media.document.thumb, preview);
PhotoObject obj = new PhotoObject(messageOwner.media.document.thumb, preview, isSecretMedia());
photoThumbs.add(obj);
} else if (photoThumbs != null && !photoThumbs.isEmpty() && messageOwner.media.document.thumb != null) {
PhotoObject photoObject = photoThumbs.get(0);
......@@ -599,15 +600,39 @@ public class MessageObject {
}
public boolean isOut() {
return messageOwner.out;
return (messageOwner.flags & TLRPC.MESSAGE_FLAG_OUT) != 0;
}
public boolean isFromMe() {
return messageOwner.from_id == UserConfig.getClientUserId();
}
public boolean isUnread () {
return messageOwner.unread;
public boolean isUnread() {
return (messageOwner.flags & TLRPC.MESSAGE_FLAG_UNREAD) != 0;
}
public void setIsRead() {
messageOwner.flags &=~ TLRPC.MESSAGE_FLAG_UNREAD;
}
public boolean isSecretMedia() {
return messageOwner.media instanceof TLRPC.TL_messageMediaPhoto && messageOwner.ttl != 0;
}
public static void setIsUnread(TLRPC.Message message, boolean unread) {
if (unread) {
message.flags |= TLRPC.MESSAGE_FLAG_UNREAD;
} else {
message.flags &=~ TLRPC.MESSAGE_FLAG_UNREAD;
}
}
public static boolean isUnread(TLRPC.Message message) {
return (message.flags & TLRPC.MESSAGE_FLAG_UNREAD) != 0;
}
public static boolean isOut(TLRPC.Message message) {
return (message.flags & TLRPC.MESSAGE_FLAG_OUT) != 0;
}
public long getDialogId() {
......@@ -635,4 +660,25 @@ public class MessageObject {
public boolean isSent() {
return messageOwner.send_state == MESSAGE_SEND_STATE_SENT;
}
public String getSecretTimeString() {
if (!isSecretMedia()) {
return null;
}
int secondsLeft = messageOwner.ttl;
if (messageOwner.destroyTime != 0) {
secondsLeft = Math.max(0, messageOwner.destroyTime - ConnectionsManager.getInstance().getCurrentTime());
}
String str;
if (secondsLeft < 60) {
str = secondsLeft + "s";
} else if (secondsLeft < 60 * 60) {
str = secondsLeft / 60 + "m";
} else if (secondsLeft < 60 * 60 * 24) {
str = secondsLeft / 60 / 60 + "h";
} else {
str = secondsLeft / 60 / 60 / 24 + "d";
}
return str;
}
}
......@@ -24,9 +24,9 @@ import java.util.zip.ZipFile;
public class NativeLoader {
private static final long sizes[] = new long[] {
951052, //armeabi
1032992, //armeabi-v7a
1612020, //x86
955148, //armeabi
1041184, //armeabi-v7a
1616116, //x86
0, //mips
};
......
......@@ -21,7 +21,7 @@ public class PhotoObject {
public TLRPC.PhotoSize photoOwner;
public Bitmap image;
public PhotoObject(TLRPC.PhotoSize photo, int preview) {
public PhotoObject(TLRPC.PhotoSize photo, int preview, boolean secret) {
photoOwner = photo;
if (preview != 0 && photo instanceof TLRPC.TL_photoCachedSize) {
......@@ -34,7 +34,13 @@ public class PhotoObject {
image = BitmapFactory.decodeByteArray(photoOwner.bytes, 0, photoOwner.bytes.length, opts);
if (image != null) {
if (preview == 2) {
Utilities.blurBitmap(image);
if (secret) {
Utilities.blurBitmap(image, 7);
Utilities.blurBitmap(image, 7);
Utilities.blurBitmap(image, 7);
} else {
Utilities.blurBitmap(image, 3);
}
}
if (ImageLoader.getInstance().runtimeHack != null) {
ImageLoader.getInstance().runtimeHack.trackFree(image.getRowBytes() * image.getHeight());
......
......@@ -364,6 +364,9 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
private int sendMessage(String message, double lat, double lon, TLRPC.TL_photo photo, TLRPC.TL_video video, MessageObject msgObj, TLRPC.User user, TLRPC.TL_document document, TLRPC.TL_audio audio, String originalPath, long peer, boolean retry, String path) {
TLRPC.Message newMsg = null;
int type = -1;
int lower_id = (int) peer;
int high_id = (int) (peer >> 32);
if (retry) {
newMsg = msgObj.messageOwner;
......@@ -409,12 +412,20 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
}
} else {
if (message != null) {
if (lower_id != 0) {
newMsg = new TLRPC.TL_message();
} else {
newMsg = new TLRPC.TL_message_secret();
}
newMsg.media = new TLRPC.TL_messageMediaEmpty();
type = 0;
newMsg.message = message;
} else if (lat != 0 && lon != 0) {
if (lower_id != 0) {
newMsg = new TLRPC.TL_message();
} else {
newMsg = new TLRPC.TL_message_secret();
}
newMsg.media = new TLRPC.TL_messageMediaGeo();
newMsg.media.geo = new TLRPC.TL_geoPoint();
newMsg.media.geo.lat = lat;
......@@ -422,7 +433,11 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
newMsg.message = "";
type = 1;
} else if (photo != null) {
if (lower_id != 0) {
newMsg = new TLRPC.TL_message();
} else {
newMsg = new TLRPC.TL_message_secret();
}
newMsg.media = new TLRPC.TL_messageMediaPhoto();
newMsg.media.photo = photo;
type = 2;
......@@ -430,7 +445,11 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
TLRPC.FileLocation location1 = photo.sizes.get(photo.sizes.size() - 1).location;
newMsg.attachPath = FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE) + "/" + location1.volume_id + "_" + location1.local_id + ".jpg";
} else if (video != null) {
if (lower_id != 0) {
newMsg = new TLRPC.TL_message();
} else {
newMsg = new TLRPC.TL_message_secret();
}
newMsg.media = new TLRPC.TL_messageMediaVideo();
newMsg.media.video = video;
newMsg.videoEditedInfo = video.videoEditedInfo;
......@@ -461,7 +480,11 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
type = 4;
}
} else if (user != null) {
if (lower_id != 0) {
newMsg = new TLRPC.TL_message();
} else {
newMsg = new TLRPC.TL_message_secret();
}
newMsg.media = new TLRPC.TL_messageMediaContact();
newMsg.media.phone_number = user.phone;
newMsg.media.first_name = user.first_name;
......@@ -470,14 +493,22 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
newMsg.message = "";
type = 6;
} else if (document != null) {
if (lower_id != 0) {
newMsg = new TLRPC.TL_message();
} else {
newMsg = new TLRPC.TL_message_secret();
}
newMsg.media = new TLRPC.TL_messageMediaDocument();
newMsg.media.document = document;
type = 7;
newMsg.message = "-1";
newMsg.attachPath = path;
} else if (audio != null) {
if (lower_id != 0) {
newMsg = new TLRPC.TL_message();
} else {
newMsg = new TLRPC.TL_message_secret();
}
newMsg.media = new TLRPC.TL_messageMediaAudio();
newMsg.media.audio = audio;
type = 8;
......@@ -487,7 +518,6 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
newMsg.local_id = newMsg.id = UserConfig.getNewMessageId();
newMsg.from_id = UserConfig.getClientUserId();
newMsg.flags |= TLRPC.MESSAGE_FLAG_OUT;
newMsg.out = true;
UserConfig.saveConfig(false);
}
if (newMsg.random_id == 0) {
......@@ -495,10 +525,7 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
}
newMsg.date = ConnectionsManager.getInstance().getCurrentTime();
newMsg.flags |= TLRPC.MESSAGE_FLAG_UNREAD;
newMsg.unread = true;
newMsg.dialog_id = peer;
int lower_id = (int) peer;
int high_id = (int) (peer >> 32);
TLRPC.EncryptedChat encryptedChat = null;
TLRPC.InputPeer sendToPeer = null;
ArrayList<TLRPC.InputUser> sendToPeers = null;
......@@ -1405,6 +1432,19 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
}
}
public void sendMessagesReadMessage(ArrayList<Long> random_ids, TLRPC.EncryptedChat encryptedChat) {
if (!(encryptedChat instanceof TLRPC.TL_encryptedChat)) {
return;
}
TLRPC.TL_decryptedMessageService_old reqSend = new TLRPC.TL_decryptedMessageService_old();
reqSend.random_id = getNextRandomId();
reqSend.random_bytes = new byte[Math.max(1, (int)Math.ceil(Utilities.random.nextDouble() * 16))];
Utilities.random.nextBytes(reqSend.random_bytes);
reqSend.action = new TLRPC.TL_decryptedMessageActionReadMessages();
reqSend.action.random_ids = random_ids;
performSendEncryptedRequest(reqSend, null, encryptedChat, null, null);
}
public void sendMessagesDeleteMessage(ArrayList<Long> random_ids, TLRPC.EncryptedChat encryptedChat) {
if (!(encryptedChat instanceof TLRPC.TL_encryptedChat)) {
return;
......@@ -1440,7 +1480,6 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
newMsg.action.ttl = encryptedChat.ttl;
newMsg.local_id = newMsg.id = UserConfig.getNewMessageId();
newMsg.from_id = UserConfig.getClientUserId();
newMsg.unread = true;
newMsg.flags = TLRPC.MESSAGE_FLAG_UNREAD | TLRPC.MESSAGE_FLAG_OUT;
newMsg.dialog_id = ((long)encryptedChat.id) << 32;
newMsg.to_id = new TLRPC.TL_peerUser();
......@@ -1449,7 +1488,6 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
} else {
newMsg.to_id.user_id = encryptedChat.participant_id;
}
newMsg.out = true;
newMsg.date = ConnectionsManager.getInstance().getCurrentTime();
newMsg.random_id = getNextRandomId();
UserConfig.saveConfig(false);
......@@ -1488,7 +1526,6 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
newMsg.local_id = newMsg.id = UserConfig.getNewMessageId();
newMsg.from_id = UserConfig.getClientUserId();
newMsg.unread = true;
newMsg.flags = TLRPC.MESSAGE_FLAG_UNREAD | TLRPC.MESSAGE_FLAG_OUT;
newMsg.dialog_id = ((long)encryptedChat.id) << 32;
newMsg.to_id = new TLRPC.TL_peerUser();
......@@ -1497,7 +1534,6 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
} else {
newMsg.to_id.user_id = encryptedChat.participant_id;
}
newMsg.out = true;
newMsg.date = ConnectionsManager.getInstance().getCurrentTime();
newMsg.random_id = getNextRandomId();
UserConfig.saveConfig(false);
......
......@@ -997,6 +997,10 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
return (int)(System.currentTimeMillis() / 1000) + timeDifference;
}
public int getTimeDifference() {
return timeDifference;
}
private void processRequestQueue(int requestClass, int _datacenterId) {
boolean haveNetwork = true;//isNetworkOnline();
......
......@@ -362,6 +362,7 @@ public class TLClassStore {
classStore.put(TLRPC.TL_messageService_old.constructor, TLRPC.TL_messageService_old.class);
classStore.put(TLRPC.TL_decryptedMessageService_old.constructor, TLRPC.TL_decryptedMessageService_old.class);
classStore.put(TLRPC.TL_decryptedMessage_old.constructor, TLRPC.TL_decryptedMessage_old.class);
classStore.put(TLRPC.TL_message_secret.constructor, TLRPC.TL_message_secret.class);
}
static TLClassStore store = null;
......
......@@ -8769,8 +8769,6 @@ public class TLRPC {
public int fwd_date;
public int from_id;
public Peer to_id;
public boolean out;
public boolean unread;
public int date;
public String message;
public MessageMedia media;
......@@ -8782,6 +8780,7 @@ public class TLRPC {
public int local_id = 0;
public long dialog_id;
public int ttl;
public int destroyTime;
public VideoEditedInfo videoEditedInfo = null;
}
......@@ -8799,8 +8798,6 @@ public class TLRPC {
date = stream.readInt32();
message = stream.readString();
media = (MessageMedia)TLClassStore.Instance().TLdeserialize(stream, stream.readInt32());
out = (flags & MESSAGE_FLAG_OUT) != 0;
unread = (flags & MESSAGE_FLAG_UNREAD) != 0;
if (id < 0) {
fwd_msg_id = stream.readInt32();
}
......@@ -8843,8 +8840,6 @@ public class TLRPC {
date = stream.readInt32();
message = stream.readString();
media = (MessageMedia)TLClassStore.Instance().TLdeserialize(stream, stream.readInt32());
out = (flags & 2) != 0;
unread = (flags & 1) != 0;
if (id < 0 || (media != null && !(media instanceof TL_messageMediaEmpty) && message != null && message.length() != 0 && message.startsWith("-1"))) {
attachPath = stream.readString();
}
......@@ -8878,8 +8873,6 @@ public class TLRPC {
to_id = (Peer)TLClassStore.Instance().TLdeserialize(stream, stream.readInt32());
date = stream.readInt32();
action = (MessageAction)TLClassStore.Instance().TLdeserialize(stream, stream.readInt32());
out = (flags & 2) != 0;
unread = (flags & 1) != 0;
}
public void serializeToStream(AbsSerializedData stream) {
......@@ -8901,8 +8894,8 @@ public class TLRPC {
id = stream.readInt32();
from_id = stream.readInt32();
to_id = (Peer)TLClassStore.Instance().TLdeserialize(stream, stream.readInt32());
out = stream.readBool();
unread = stream.readBool();
flags |= stream.readBool() ? MESSAGE_FLAG_OUT : 0;
flags |= stream.readBool() ? MESSAGE_FLAG_UNREAD : 0;
date = stream.readInt32();
action = (MessageAction)TLClassStore.Instance().TLdeserialize(stream, stream.readInt32());
}
......@@ -8912,8 +8905,8 @@ public class TLRPC {
stream.writeInt32(id);
stream.writeInt32(from_id);
to_id.serializeToStream(stream);
stream.writeBool(out);
stream.writeBool(unread);
stream.writeBool((flags & MESSAGE_FLAG_OUT) != 0);
stream.writeBool((flags & MESSAGE_FLAG_UNREAD) != 0);
stream.writeInt32(date);
action.serializeToStream(stream);
}
......@@ -8929,8 +8922,8 @@ public class TLRPC {
fwd_date = stream.readInt32();
from_id = stream.readInt32();
to_id = (Peer)TLClassStore.Instance().TLdeserialize(stream, stream.readInt32());
out = stream.readBool();
unread = stream.readBool();
flags |= stream.readBool() ? MESSAGE_FLAG_OUT : 0;
flags |= stream.readBool() ? MESSAGE_FLAG_UNREAD : 0;
date = stream.readInt32();
message = stream.readString();
media = (MessageMedia)TLClassStore.Instance().TLdeserialize(stream, stream.readInt32());
......@@ -8953,8 +8946,8 @@ public class TLRPC {
stream.writeInt32(fwd_date);
stream.writeInt32(from_id);
to_id.serializeToStream(stream);
stream.writeBool(out);
stream.writeBool(unread);
stream.writeBool((flags & MESSAGE_FLAG_OUT) != 0);
stream.writeBool((flags & MESSAGE_FLAG_UNREAD) != 0);
stream.writeInt32(date);
stream.writeString(message);
media.serializeToStream(stream);
......@@ -8972,8 +8965,8 @@ public class TLRPC {
id = stream.readInt32();
from_id = stream.readInt32();
to_id = (Peer)TLClassStore.Instance().TLdeserialize(stream, stream.readInt32());
out = stream.readBool();
unread = stream.readBool();
flags |= stream.readBool() ? MESSAGE_FLAG_OUT : 0;
flags |= stream.readBool() ? MESSAGE_FLAG_UNREAD : 0;
date = stream.readInt32();
message = stream.readString();
media = (MessageMedia)TLClassStore.Instance().TLdeserialize(stream, stream.readInt32());
......@@ -8991,8 +8984,8 @@ public class TLRPC {
stream.writeInt32(id);
stream.writeInt32(from_id);
to_id.serializeToStream(stream);
stream.writeBool(out);
stream.writeBool(unread);
stream.writeBool((flags & MESSAGE_FLAG_OUT) != 0);
stream.writeBool((flags & MESSAGE_FLAG_UNREAD) != 0);
stream.writeInt32(date);
stream.writeString(message);
media.serializeToStream(stream);
......@@ -9004,11 +8997,11 @@ public class TLRPC {
public static int constructor = 0x555555F8;
public void readParams(AbsSerializedData stream) {
flags = stream.readInt32();
id = stream.readInt32();
ttl = stream.readInt32();
from_id = stream.readInt32();
to_id = (Peer)TLClassStore.Instance().TLdeserialize(stream, stream.readInt32());
out = stream.readBool();
unread = stream.readBool();
date = stream.readInt32();
message = stream.readString();
media = (MessageMedia)TLClassStore.Instance().TLdeserialize(stream, stream.readInt32());
......@@ -9023,11 +9016,11 @@ public class TLRPC {
public void serializeToStream(AbsSerializedData stream) {
stream.writeInt32(constructor);
stream.writeInt32(flags);
stream.writeInt32(id);
stream.writeInt32(ttl);
stream.writeInt32(from_id);
to_id.serializeToStream(stream);
stream.writeBool(out);
stream.writeBool(unread);
stream.writeInt32(date);
stream.writeString(message);
media.serializeToStream(stream);
......@@ -9773,7 +9766,7 @@ public class TLRPC {
}
public static class TL_decryptedMessageActionScreenshotMessages extends DecryptedMessageAction {
public static int constructor = 0x954bd30;
public static int constructor = 0x8ac1f475;
public void readParams(AbsSerializedData stream) {
......
......@@ -28,7 +28,6 @@ import net.hockeyapp.android.CrashManager;
import net.hockeyapp.android.CrashManagerListener;
import net.hockeyapp.android.UpdateManager;
import org.telegram.android.LocaleController;
import org.telegram.ui.ApplicationLoader;
import java.io.ByteArrayInputStream;
......@@ -112,7 +111,7 @@ public class Utilities {
public native static long doPQNative(long _what);
public native static void loadBitmap(String path, int[] bitmap, int scale, int format, int width, int height);
public native static void blurBitmap(Object bitmap);
public native static void blurBitmap(Object bitmap, int radius);
public native static int convertVideoFrame(ByteBuffer src, ByteBuffer dest, int destFormat, int width, int height, int padding, int swap);
private native static void aesIgeEncryption(ByteBuffer buffer, byte[] key, byte[] iv, boolean encrypt, int offset, int length);
......
......@@ -117,7 +117,6 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
private TypingDotsDrawable typingDotsDrawable;
private View emptyViewContainer;
private ArrayList<View> actionModeViews = new ArrayList<View>();
private Semaphore testSemaphore = new Semaphore(0);
private TextView bottomOverlayText;
......@@ -175,6 +174,8 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
private String startVideoEdit = null;
private Runnable openSecretPhotoRunnable = null;
private final static int copy = 1;
private final static int forward = 2;
private final static int delete = 3;
......@@ -354,12 +355,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
loading = true;
MessagesController.getInstance().loadMessages(dialog_id, AndroidUtilities.isTablet() ? 30 : 20, 0, true, 0, classGuid, true, false, testSemaphore);
try {
testSemaphore.acquire();
} catch (Exception e) {
FileLog.e("tmessages", e);
}
MessagesController.getInstance().loadMessages(dialog_id, AndroidUtilities.isTablet() ? 30 : 20, 0, true, 0, classGuid, true, false, null);
if (currentUser != null) {
userBlocked = MessagesController.getInstance().blockedUsers.contains(currentUser.id);
......@@ -2143,7 +2139,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
}
if (!obj.isOut() && obj.isUnread()) {
if (!paused) {
obj.messageOwner.unread = false;
obj.setIsRead();
}
markAsRead = true;
}
......@@ -2217,7 +2213,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
for (Integer ids : markAsReadMessages) {
MessageObject obj = messagesDict.get(ids);
if (obj != null) {
obj.messageOwner.unread = false;
obj.setIsRead();
updated = true;
}
}
......@@ -2322,11 +2318,11 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
for (MessageObject obj : messages) {
if (!obj.isOut()) {
continue;
} else if (obj.isOut() && !obj.messageOwner.unread) {
} else if (obj.isOut() && !obj.isUnread()) {
break;
}
if (obj.messageOwner.date <= date) {
obj.messageOwner.unread = false;
obj.setIsRead();
}
}
updateVisibleRows();
......@@ -2539,7 +2535,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
break;
}
if (!messageObject.isOut()) {
messageObject.messageOwner.unread = false;
messageObject.setIsRead();
}
}
readWhenResume = false;
......@@ -3354,7 +3350,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
return view;
}
}
MessageObject message = messages.get(messages.size() - i - offset);
final MessageObject message = messages.get(messages.size() - i - offset);
int type = message.contentType;
if (view == null) {
LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
......@@ -3427,7 +3423,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
if (view instanceof ChatMediaCell) {
((ChatMediaCell)view).mediaDelegate = new ChatMediaCell.ChatMediaCellDelegate() {
@Override
public void didPressedImage(ChatMediaCell cell) {
public void didClickedImage(ChatMediaCell cell) {
MessageObject message = cell.getMessageObject();
if (message.isSendError()) {
createMenu(cell, false);
......@@ -3509,6 +3505,43 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
public void didPressedOther(ChatMediaCell cell) {
createMenu(cell, true);
}
@Override
public boolean didPressedImage(final ChatMediaCell cell) {
final MessageObject messageObject = cell.getMessageObject();
if (messageObject == null || !messageObject.isSecretMedia()) {
return false;
}
openSecretPhotoRunnable = new Runnable() {
@Override
public void run() {
if (openSecretPhotoRunnable == null) {
return;
}
chatListView.requestDisallowInterceptTouchEvent(true);
openSecretPhotoRunnable = null;
if (!messageObject.isOut() && messageObject.messageOwner.destroyTime == 0) {
MessagesController.getInstance().markMessageAsRead(dialog_id, message.messageOwner.random_id);
messageObject.messageOwner.destroyTime = messageObject.messageOwner.ttl + ConnectionsManager.getInstance().getCurrentTime();
cell.invalidate();
}
SecretPhotoViewer.getInstance().setParentActivity(getParentActivity());
SecretPhotoViewer.getInstance().openPhoto(messageObject);
}
};
AndroidUtilities.RunOnUIThread(openSecretPhotoRunnable, 100);
return true;
}
@Override
public void didUnpressedImage(ChatMediaCell cell) {
if (openSecretPhotoRunnable != null) {
AndroidUtilities.CancelRunOnUIThread(openSecretPhotoRunnable);
openSecretPhotoRunnable = null;
} else {
SecretPhotoViewer.getInstance().closePhoto();
}
}
};
}
......@@ -3693,7 +3726,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
checkImage.setVisibility(View.INVISIBLE);
}
} else if (message.isSent()) {
if (!message.messageOwner.unread) {
if (!message.isUnread()) {
halfCheckImage.setVisibility(View.VISIBLE);
checkImage.setVisibility(View.VISIBLE);
halfCheckImage.setImageResource(R.drawable.msg_halfcheck);
......
......@@ -836,6 +836,7 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
@Override
protected void onDestroy() {
PhotoViewer.getInstance().destroyPhotoViewer();
SecretPhotoViewer.getInstance().destroyPhotoViewer();
super.onDestroy();
onFinish();
}
......
......@@ -318,7 +318,7 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen
return fragmentView;
}
public void didReceivedNotification(int id, Object... args) {
public void didReceivedNotification(int id, final Object... args) {
if (id == NotificationCenter.updateInterfaces) {
int mask = (Integer)args[0];
if ((mask & MessagesController.UPDATE_MASK_AVATAR) != 0 || (mask & MessagesController.UPDATE_MASK_NAME) != 0) {
......@@ -338,12 +338,17 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen
}
} else if (id == NotificationCenter.encryptedChatCreated) {
if (creatingChat) {
AndroidUtilities.RunOnUIThread(new Runnable() {
@Override
public void run() {
NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats);
TLRPC.EncryptedChat encryptedChat = (TLRPC.EncryptedChat)args[0];
Bundle args2 = new Bundle();
args2.putInt("enc_id", encryptedChat.id);
presentFragment(new ChatActivity(args2), true);
}
});
}
} else if (id == NotificationCenter.encryptedChatUpdated) {
TLRPC.EncryptedChat chat = (TLRPC.EncryptedChat)args[0];
if (currentEncryptedChat != null && chat.id == currentEncryptedChat.id) {
......
......@@ -276,6 +276,7 @@ public class VideoEditorActivity extends BaseFragment implements TextureView.Sur
});
if (Build.VERSION.SDK_INT < 18) {
try {
MediaCodecInfo codecInfo = MediaController.selectCodec(MediaController.MIME_TYPE);
if (codecInfo == null) {
compressVideo.setVisibility(View.GONE);
......@@ -293,6 +294,10 @@ public class VideoEditorActivity extends BaseFragment implements TextureView.Sur
}
}
}
} catch (Exception e) {
compressVideo.setVisibility(View.GONE);
FileLog.e("tmessages", e);
}
}
TextView titleTextView = (TextView) fragmentView.findViewById(R.id.original_title);
......
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