Commit 0c49c206 authored by DrKLO's avatar DrKLO

New photo viewer(close by swipe down, not tested on 2.x), optimize emoji load,...

New photo viewer(close by swipe down, not tested on 2.x), optimize emoji load, fixed audio notes and typing in secret chats

https://github.com/DrKLO/Telegram/pull/443
parent 92e1b050
...@@ -3,7 +3,7 @@ buildscript { ...@@ -3,7 +3,7 @@ buildscript {
mavenCentral() mavenCentral()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:0.10.+' classpath 'com.android.tools.build:gradle:0.11.+'
} }
} }
apply plugin: 'android' apply plugin: 'android'
...@@ -18,7 +18,6 @@ tasks.withType(JavaCompile) { ...@@ -18,7 +18,6 @@ tasks.withType(JavaCompile) {
dependencies { dependencies {
compile 'com.android.support:support-v4:19.0.+' compile 'com.android.support:support-v4:19.0.+'
compile 'com.android.support:appcompat-v7:19.0.+'
compile 'com.google.android.gms:play-services:4.1.+' compile 'com.google.android.gms:play-services:4.1.+'
compile 'net.hockeyapp.android:HockeySDK:3.0.1' compile 'net.hockeyapp.android:HockeySDK:3.0.1'
} }
...@@ -82,7 +81,7 @@ android { ...@@ -82,7 +81,7 @@ android {
defaultConfig { defaultConfig {
minSdkVersion 8 minSdkVersion 8
targetSdkVersion 19 targetSdkVersion 19
versionCode 240 versionCode 243
versionName "1.4.15" versionName "1.4.15"
} }
} }
...@@ -100,11 +100,6 @@ ...@@ -100,11 +100,6 @@
android:configChanges="keyboard|keyboardHidden|orientation|screenSize" android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:screenOrientation="portrait"> android:screenOrientation="portrait">
</activity> </activity>
<activity
android:name="org.telegram.ui.GalleryImageViewer"
android:theme="@style/Theme.TMessages.Gallery"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
</activity>
<receiver android:name="org.telegram.messenger.SmsListener"> <receiver android:name="org.telegram.messenger.SmsListener">
<intent-filter> <intent-filter>
......
This diff is collapsed.
...@@ -184,10 +184,10 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection. ...@@ -184,10 +184,10 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
if (paused) { if (paused) {
ApplicationLoader.lastPauseTime = System.currentTimeMillis(); ApplicationLoader.lastPauseTime = System.currentTimeMillis();
nextSleepTimeout = 30000; nextSleepTimeout = 30000;
FileLog.e("tmessages", "wakeup network in background by recieved push"); FileLog.e("tmessages", "wakeup network in background by received push");
} else if (ApplicationLoader.lastPauseTime != 0) { } else if (ApplicationLoader.lastPauseTime != 0) {
ApplicationLoader.lastPauseTime = System.currentTimeMillis(); ApplicationLoader.lastPauseTime = System.currentTimeMillis();
FileLog.e("tmessages", "reset sleep timeout by recieved push"); FileLog.e("tmessages", "reset sleep timeout by received push");
} }
} }
}); });
...@@ -849,7 +849,16 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection. ...@@ -849,7 +849,16 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
public static boolean isNetworkOnline() { public static boolean isNetworkOnline() {
try { try {
ConnectivityManager cm = (ConnectivityManager)ApplicationLoader.applicationContext.getSystemService(Context.CONNECTIVITY_SERVICE); ConnectivityManager cm = (ConnectivityManager)ApplicationLoader.applicationContext.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); NetworkInfo netInfo = cm.getActiveNetworkInfo();
if (netInfo != null && netInfo.isConnected()) {
return true;
}
netInfo = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
if (netInfo.isConnected()) {
return true;
}
if (netInfo != null && netInfo.getState() == NetworkInfo.State.CONNECTED) { if (netInfo != null && netInfo.getState() == NetworkInfo.State.CONNECTED) {
return true; return true;
} else { } else {
......
...@@ -34,8 +34,12 @@ public class Emoji { ...@@ -34,8 +34,12 @@ public class Emoji {
private static int drawImgSize, bigImgSize; private static int drawImgSize, bigImgSize;
private static boolean inited = false; private static boolean inited = false;
private static Paint placeholderPaint; private static Paint placeholderPaint;
private static Bitmap emojiBmp = null; private static Bitmap emojiBmp[] = new Bitmap[5];
private static boolean loadingEmoji = false; private static boolean loadingEmoji[] = new boolean[5];
private static final int[] cols = {
13, 10, 15, 10, 14
};
private static final char[] emojiChars = { private static final char[] emojiChars = {
0x00A9, 0x00AE, 0x203C, 0x2049, 0x2122, 0x2139, 0x2194, 0x2195, 0x2196, 0x2197, 0x00A9, 0x00AE, 0x203C, 0x2049, 0x2122, 0x2139, 0x2194, 0x2195, 0x2196, 0x2197,
...@@ -199,19 +203,17 @@ public class Emoji { ...@@ -199,19 +203,17 @@ public class Emoji {
drawImgSize = Utilities.dp(20); drawImgSize = Utilities.dp(20);
bigImgSize = Utilities.dp(30); bigImgSize = Utilities.dp(30);
int num = 0;
for (int j = 1; j < data.length; j++) { for (int j = 1; j < data.length; j++) {
for (int i = 0; i < data[j].length; i++) { for (int i = 0; i < data[j].length; i++) {
Rect rect = new Rect((num % 29) * imgSize, (num / 29) * imgSize, (num % 29 + 1) * imgSize, (num / 29 + 1) * imgSize); Rect rect = new Rect((i % cols[j - 1]) * imgSize, (i / cols[j - 1]) * imgSize, (i % cols[j - 1] + 1) * imgSize, (i / cols[j - 1] + 1) * imgSize);
rects.put(data[j][i], new DrawableInfo(rect)); rects.put(data[j][i], new DrawableInfo(rect, (byte)(j - 1)));
num++;
} }
} }
placeholderPaint = new Paint(); placeholderPaint = new Paint();
placeholderPaint.setColor(0x55000000); placeholderPaint.setColor(0x00000000);
} }
private static Bitmap loadEmoji() { private static Bitmap loadEmoji(final int page) {
try { try {
float scale = 1.0f; float scale = 1.0f;
int imageResize = 1; int imageResize = 1;
...@@ -227,7 +229,7 @@ public class Emoji { ...@@ -227,7 +229,7 @@ public class Emoji {
scale = 3.0f; scale = 3.0f;
} }
String imageName = String.format(Locale.US, "emoji%.01fx.jpg", scale); String imageName = String.format(Locale.US, "emoji%.01fx_%d.jpg", scale, page);
File imageFile = ApplicationLoader.applicationContext.getFileStreamPath(imageName); File imageFile = ApplicationLoader.applicationContext.getFileStreamPath(imageName);
if (!imageFile.exists()) { if (!imageFile.exists()) {
InputStream is = ApplicationLoader.applicationContext.getAssets().open("emoji/" + imageName); InputStream is = ApplicationLoader.applicationContext.getAssets().open("emoji/" + imageName);
...@@ -242,7 +244,7 @@ public class Emoji { ...@@ -242,7 +244,7 @@ public class Emoji {
final Bitmap colorsBitmap = Bitmap.createBitmap(opts.outWidth / imageResize, opts.outHeight / imageResize, Bitmap.Config.ARGB_8888); final Bitmap colorsBitmap = Bitmap.createBitmap(opts.outWidth / imageResize, opts.outHeight / imageResize, Bitmap.Config.ARGB_8888);
Utilities.loadBitmap(imageFile.getAbsolutePath(), colorsBitmap, imageResize); Utilities.loadBitmap(imageFile.getAbsolutePath(), colorsBitmap, imageResize);
imageName = String.format(Locale.US, "emoji%.01fx_a.jpg", scale); imageName = String.format(Locale.US, "emoji%.01fx_a_%d.jpg", scale, page);
imageFile = ApplicationLoader.applicationContext.getFileStreamPath(imageName); imageFile = ApplicationLoader.applicationContext.getFileStreamPath(imageName);
if (!imageFile.exists()) { if (!imageFile.exists()) {
InputStream is = ApplicationLoader.applicationContext.getAssets().open("emoji/" + imageName); InputStream is = ApplicationLoader.applicationContext.getAssets().open("emoji/" + imageName);
...@@ -255,7 +257,7 @@ public class Emoji { ...@@ -255,7 +257,7 @@ public class Emoji {
Utilities.RunOnUIThread(new Runnable() { Utilities.RunOnUIThread(new Runnable() {
@Override @Override
public void run() { public void run() {
emojiBmp = colorsBitmap; emojiBmp[page] = colorsBitmap;
NotificationCenter.getInstance().postNotificationName(999); NotificationCenter.getInstance().postNotificationName(999);
} }
}); });
...@@ -267,15 +269,15 @@ public class Emoji { ...@@ -267,15 +269,15 @@ public class Emoji {
return null; return null;
} }
private static void loadEmojiAsync() { private static void loadEmojiAsync(final int page) {
if (loadingEmoji) { if (loadingEmoji[page]) {
return; return;
} }
loadingEmoji = true; loadingEmoji[page] = true;
new Thread(new Runnable() { new Thread(new Runnable() {
public void run() { public void run() {
loadEmoji(); loadEmoji(page);
loadingEmoji = false; loadingEmoji[page] = false;
} }
}).start(); }).start();
} }
...@@ -313,7 +315,7 @@ public class Emoji { ...@@ -313,7 +315,7 @@ public class Emoji {
} }
public static class EmojiDrawable extends Drawable { public static class EmojiDrawable extends Drawable {
Rect rect; private DrawableInfo info;
boolean fullSize = false; boolean fullSize = false;
private static Paint paint; private static Paint paint;
...@@ -322,14 +324,14 @@ public class Emoji { ...@@ -322,14 +324,14 @@ public class Emoji {
paint.setFlags(Paint.FILTER_BITMAP_FLAG | Paint.ANTI_ALIAS_FLAG); paint.setFlags(Paint.FILTER_BITMAP_FLAG | Paint.ANTI_ALIAS_FLAG);
} }
public EmojiDrawable(DrawableInfo info) { public EmojiDrawable(DrawableInfo i) {
rect = info.rect; info = i;
} }
@Override @Override
public void draw(Canvas canvas) { public void draw(Canvas canvas) {
if (emojiBmp == null) { if (emojiBmp[info.page] == null) {
loadEmojiAsync(); loadEmojiAsync(info.page);
canvas.drawRect(getBounds(), placeholderPaint); canvas.drawRect(getBounds(), placeholderPaint);
return; return;
} }
...@@ -340,7 +342,7 @@ public class Emoji { ...@@ -340,7 +342,7 @@ public class Emoji {
b.top = cY - (fullSize ? bigImgSize : drawImgSize) / 2; b.top = cY - (fullSize ? bigImgSize : drawImgSize) / 2;
b.bottom = cY + (fullSize ? bigImgSize : drawImgSize) / 2; b.bottom = cY + (fullSize ? bigImgSize : drawImgSize) / 2;
if (!canvas.quickReject(b.left, b.top, b.right, b.bottom, Canvas.EdgeType.AA)) { if (!canvas.quickReject(b.left, b.top, b.right, b.bottom, Canvas.EdgeType.AA)) {
canvas.drawBitmap(emojiBmp, rect, b, paint); canvas.drawBitmap(emojiBmp[info.page], info.rect, b, paint);
} }
} }
...@@ -361,9 +363,12 @@ public class Emoji { ...@@ -361,9 +363,12 @@ public class Emoji {
} }
private static class DrawableInfo { private static class DrawableInfo {
Rect rect; public Rect rect;
public DrawableInfo(Rect rect) { public byte page;
this.rect = rect;
public DrawableInfo(Rect r, byte p) {
rect = r;
page = p;
} }
} }
......
...@@ -93,12 +93,7 @@ public class FileLoadOperation { ...@@ -93,12 +93,7 @@ public class FileLoadOperation {
} }
public FileLoadOperation(TLRPC.Audio audioLocation) { public FileLoadOperation(TLRPC.Audio audioLocation) {
if (audioLocation instanceof TLRPC.TL_audio) { if (audioLocation instanceof TLRPC.TL_audioEncrypted) {
location = new TLRPC.TL_inputAudioFileLocation();
datacenter_id = audioLocation.dc_id;
location.id = audioLocation.id;
location.access_hash = audioLocation.access_hash;
} else if (audioLocation instanceof TLRPC.TL_audioEncrypted) {
location = new TLRPC.TL_inputEncryptedFileLocation(); location = new TLRPC.TL_inputEncryptedFileLocation();
location.id = audioLocation.id; location.id = audioLocation.id;
location.access_hash = audioLocation.access_hash; location.access_hash = audioLocation.access_hash;
...@@ -106,6 +101,11 @@ public class FileLoadOperation { ...@@ -106,6 +101,11 @@ public class FileLoadOperation {
iv = new byte[32]; iv = new byte[32];
System.arraycopy(audioLocation.iv, 0, iv, 0, iv.length); System.arraycopy(audioLocation.iv, 0, iv, 0, iv.length);
key = audioLocation.key; key = audioLocation.key;
} else if (audioLocation instanceof TLRPC.TL_audio) {
location = new TLRPC.TL_inputAudioFileLocation();
datacenter_id = audioLocation.dc_id;
location.id = audioLocation.id;
location.access_hash = audioLocation.access_hash;
} }
ext = ".m4a"; ext = ".m4a";
} }
......
...@@ -20,7 +20,6 @@ import android.os.ParcelFileDescriptor; ...@@ -20,7 +20,6 @@ import android.os.ParcelFileDescriptor;
import org.telegram.objects.MessageObject; import org.telegram.objects.MessageObject;
import org.telegram.ui.ApplicationLoader; import org.telegram.ui.ApplicationLoader;
import org.telegram.ui.Views.BackupImageView;
import org.telegram.ui.Views.ImageReceiver; import org.telegram.ui.Views.ImageReceiver;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
...@@ -34,6 +33,7 @@ import java.util.HashMap; ...@@ -34,6 +33,7 @@ import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.Queue; import java.util.Queue;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Semaphore;
public class FileLoader { public class FileLoader {
public LruCache memCache; public LruCache memCache;
...@@ -132,10 +132,10 @@ public class FileLoader { ...@@ -132,10 +132,10 @@ public class FileLoader {
private class CacheImage { private class CacheImage {
public String key; public String key;
final public ArrayList<Object> imageViewArray = new ArrayList<Object>(); final public ArrayList<ImageReceiver> imageViewArray = new ArrayList<ImageReceiver>();
public FileLoadOperation loadOperation; public FileLoadOperation loadOperation;
public void addImageView(Object imageView) { public void addImageView(ImageReceiver imageView) {
synchronized (imageViewArray) { synchronized (imageViewArray) {
boolean exist = false; boolean exist = false;
for (Object v : imageViewArray) { for (Object v : imageViewArray) {
...@@ -166,9 +166,7 @@ public class FileLoader { ...@@ -166,9 +166,7 @@ public class FileLoader {
synchronized (imageViewArray) { synchronized (imageViewArray) {
if (image != null) { if (image != null) {
for (Object imgView : imageViewArray) { for (Object imgView : imageViewArray) {
if (imgView instanceof BackupImageView) { if (imgView instanceof ImageReceiver) {
((BackupImageView)imgView).setImageBitmap(image, key);
} else if (imgView instanceof ImageReceiver) {
((ImageReceiver)imgView).setImageBitmap(image, key); ((ImageReceiver)imgView).setImageBitmap(image, key);
} }
} }
...@@ -481,8 +479,22 @@ public class FileLoader { ...@@ -481,8 +479,22 @@ public class FileLoader {
}); });
} }
public boolean isLoadingFile(String fileName) { public boolean isLoadingFile(final String fileName) {
return loadOperationPaths.containsKey(fileName); final Semaphore semaphore = new Semaphore(0);
final Boolean[] result = new Boolean[1];
fileLoaderQueue.postRunnable(new Runnable() {
@Override
public void run() {
result[0] = loadOperationPaths.containsKey(fileName);
semaphore.release();
}
});
try {
semaphore.acquire();
} catch (Exception e) {
FileLog.e("tmessages", e);
}
return result[0];
} }
public void loadFile(final TLRPC.Video video, final TLRPC.PhotoSize photo, final TLRPC.Document document, final TLRPC.Audio audio) { public void loadFile(final TLRPC.Video video, final TLRPC.PhotoSize photo, final TLRPC.Document document, final TLRPC.Audio audio) {
...@@ -676,34 +688,16 @@ public class FileLoader { ...@@ -676,34 +688,16 @@ public class FileLoader {
memCache.evictAll(); memCache.evictAll();
} }
private Integer getTag(Object obj) { public void cancelLoadingForImageView(final ImageReceiver imageView) {
if (obj instanceof BackupImageView) {
return (Integer)((BackupImageView)obj).getTag(R.string.CacheTag);
} else if (obj instanceof ImageReceiver) {
return ((ImageReceiver)obj).TAG;
}
return 0;
}
private void setTag(Object obj, Integer tag) {
if (obj instanceof BackupImageView) {
((BackupImageView)obj).setTag(R.string.CacheTag, tag);
} else if (obj instanceof ImageReceiver) {
((ImageReceiver)obj).TAG = tag;
}
}
public void cancelLoadingForImageView(final Object imageView) {
if (imageView == null) { if (imageView == null) {
return; return;
} }
fileLoaderQueue.postRunnable(new Runnable() { fileLoaderQueue.postRunnable(new Runnable() {
@Override @Override
public void run() { public void run() {
Integer TAG = getTag(imageView); Integer TAG = imageView.TAG;
if (TAG == null) { if (TAG == null) {
TAG = lastImageNum; imageView.TAG = TAG = lastImageNum;
setTag(imageView, TAG);
lastImageNum++; lastImageNum++;
if (lastImageNum == Integer.MAX_VALUE) { if (lastImageNum == Integer.MAX_VALUE) {
lastImageNum = 0; lastImageNum = 0;
...@@ -723,15 +717,15 @@ public class FileLoader { ...@@ -723,15 +717,15 @@ public class FileLoader {
}); });
} }
public Bitmap getImageFromMemory(TLRPC.FileLocation url, Object imageView, String filter, boolean cancel) { public Bitmap getImageFromMemory(TLRPC.FileLocation url, ImageReceiver imageView, String filter, boolean cancel) {
return getImageFromMemory(url, null, imageView, filter, cancel); return getImageFromMemory(url, null, imageView, filter, cancel);
} }
public Bitmap getImageFromMemory(String url, Object imageView, String filter, boolean cancel) { public Bitmap getImageFromMemory(String url, ImageReceiver imageView, String filter, boolean cancel) {
return getImageFromMemory(null, url, imageView, filter, cancel); return getImageFromMemory(null, url, imageView, filter, cancel);
} }
public Bitmap getImageFromMemory(TLRPC.FileLocation url, String httpUrl, Object imageView, String filter, boolean cancel) { public Bitmap getImageFromMemory(TLRPC.FileLocation url, String httpUrl, ImageReceiver imageView, String filter, boolean cancel) {
if (url == null && httpUrl == null) { if (url == null && httpUrl == null) {
return null; return null;
} }
...@@ -783,19 +777,19 @@ public class FileLoader { ...@@ -783,19 +777,19 @@ public class FileLoader {
}); });
} }
public void loadImage(final String url, final Object imageView, final String filter, final boolean cancel) { public void loadImage(final String url, final ImageReceiver imageView, final String filter, final boolean cancel) {
loadImage(null, url, imageView, filter, cancel, 0); loadImage(null, url, imageView, filter, cancel, 0);
} }
public void loadImage(final TLRPC.FileLocation url, final Object imageView, final String filter, final boolean cancel) { public void loadImage(final TLRPC.FileLocation url, final ImageReceiver imageView, final String filter, final boolean cancel) {
loadImage(url, null, imageView, filter, cancel, 0); loadImage(url, null, imageView, filter, cancel, 0);
} }
public void loadImage(final TLRPC.FileLocation url, final Object imageView, final String filter, final boolean cancel, final int size) { public void loadImage(final TLRPC.FileLocation url, final ImageReceiver imageView, final String filter, final boolean cancel, final int size) {
loadImage(url, null, imageView, filter, cancel, size); loadImage(url, null, imageView, filter, cancel, size);
} }
public void loadImage(final TLRPC.FileLocation url, final String httpUrl, final Object imageView, final String filter, final boolean cancel, final int size) { public void loadImage(final TLRPC.FileLocation url, final String httpUrl, final ImageReceiver imageView, final String filter, final boolean cancel, final int size) {
if ((url == null && httpUrl == null) || imageView == null || (url != null && !(url instanceof TLRPC.TL_fileLocation) && !(url instanceof TLRPC.TL_fileEncryptedLocation))) { if ((url == null && httpUrl == null) || imageView == null || (url != null && !(url instanceof TLRPC.TL_fileLocation) && !(url instanceof TLRPC.TL_fileEncryptedLocation))) {
return; return;
} }
...@@ -814,10 +808,9 @@ public class FileLoader { ...@@ -814,10 +808,9 @@ public class FileLoader {
key += "@" + filter; key += "@" + filter;
} }
Integer TAG = getTag(imageView); Integer TAG = imageView.TAG;
if (TAG == null) { if (TAG == null) {
TAG = lastImageNum; TAG = imageView.TAG = lastImageNum;
setTag(imageView, TAG);
lastImageNum++; lastImageNum++;
if (lastImageNum == Integer.MAX_VALUE) if (lastImageNum == Integer.MAX_VALUE)
lastImageNum = 0; lastImageNum = 0;
...@@ -878,8 +871,8 @@ public class FileLoader { ...@@ -878,8 +871,8 @@ public class FileLoader {
if (arg3 != null) { if (arg3 != null) {
loadOperationPaths.remove(arg3); loadOperationPaths.remove(arg3);
} }
for (Object v : img.imageViewArray) { for (ImageReceiver v : img.imageViewArray) {
imageLoadingByKeys.remove(getTag(v)); imageLoadingByKeys.remove(v.TAG);
} }
checkOperationsAndClear(img.loadOperation); checkOperationsAndClear(img.loadOperation);
imageLoading.remove(arg2); imageLoading.remove(arg2);
...@@ -906,8 +899,8 @@ public class FileLoader { ...@@ -906,8 +899,8 @@ public class FileLoader {
if (arg3 != null) { if (arg3 != null) {
loadOperationPaths.remove(arg3); loadOperationPaths.remove(arg3);
} }
for (Object view : img.imageViewArray) { for (ImageReceiver view : img.imageViewArray) {
imageLoadingByKeys.remove(getTag(view)); imageLoadingByKeys.remove(view.TAG);
imageLoading.remove(arg2); imageLoading.remove(arg2);
checkOperationsAndClear(operation); checkOperationsAndClear(operation);
} }
......
...@@ -852,7 +852,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter ...@@ -852,7 +852,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
ArrayList<Long> keys = new ArrayList<Long>(printingUsers.keySet()); ArrayList<Long> keys = new ArrayList<Long>(printingUsers.keySet());
for (Long key : keys) { for (Long key : keys) {
if (key > 0) { if (key > 0 || key.intValue() == 0) {
newPrintingStrings.put(key, LocaleController.getString("Typing", R.string.Typing)); newPrintingStrings.put(key, LocaleController.getString("Typing", R.string.Typing));
} else { } else {
ArrayList<PrintingUser> arr = printingUsers.get(key); ArrayList<PrintingUser> arr = printingUsers.get(key);
...@@ -3937,26 +3937,30 @@ public class MessagesController implements NotificationCenter.NotificationCenter ...@@ -3937,26 +3937,30 @@ public class MessagesController implements NotificationCenter.NotificationCenter
} }
} }
} else if (update instanceof TLRPC.TL_updateEncryptedChatTyping) { } else if (update instanceof TLRPC.TL_updateEncryptedChatTyping) {
long uid = ((long)update.chat_id) << 32; TLRPC.EncryptedChat encryptedChat = getEncryptedChat(update.chat_id);
ArrayList<PrintingUser> arr = printingUsers.get(uid); if (encryptedChat != null) {
if (arr == null) { update.user_id = encryptedChat.user_id;
arr = new ArrayList<PrintingUser>(); long uid = ((long) update.chat_id) << 32;
printingUsers.put(uid, arr); ArrayList<PrintingUser> arr = printingUsers.get(uid);
} if (arr == null) {
boolean exist = false; arr = new ArrayList<PrintingUser>();
for (PrintingUser u : arr) { printingUsers.put(uid, arr);
if (u.userId == update.user_id) { }
exist = true; boolean exist = false;
u.lastTime = currentTime; for (PrintingUser u : arr) {
break; if (u.userId == update.user_id) {
exist = true;
u.lastTime = currentTime;
break;
}
}
if (!exist) {
PrintingUser newUser = new PrintingUser();
newUser.userId = update.user_id;
newUser.lastTime = currentTime;
arr.add(newUser);
printChanged = true;
} }
}
if (!exist) {
PrintingUser newUser = new PrintingUser();
newUser.userId = update.user_id;
newUser.lastTime = currentTime;
arr.add(newUser);
printChanged = true;
} }
} else if (update instanceof TLRPC.TL_updateEncryptedMessagesRead) { } else if (update instanceof TLRPC.TL_updateEncryptedMessagesRead) {
markAsReadEncrypted.put(update.chat_id, Math.max(update.max_date, update.date)); markAsReadEncrypted.put(update.chat_id, Math.max(update.max_date, update.date));
...@@ -3970,22 +3974,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter ...@@ -3970,22 +3974,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
} else if (update instanceof TLRPC.TL_updateEncryption) { } else if (update instanceof TLRPC.TL_updateEncryption) {
final TLRPC.EncryptedChat newChat = update.chat; final TLRPC.EncryptedChat newChat = update.chat;
long dialog_id = ((long)newChat.id) << 32; long dialog_id = ((long)newChat.id) << 32;
TLRPC.EncryptedChat existingChat = encryptedChats.get(newChat.id); TLRPC.EncryptedChat existingChat = getEncryptedChat(newChat.id);
if (existingChat == null) {
Semaphore semaphore = new Semaphore(0);
ArrayList<TLObject> result = new ArrayList<TLObject>();
MessagesStorage.getInstance().getEncryptedChat(newChat.id, semaphore, result);
try {
semaphore.acquire();
} catch (Exception e) {
FileLog.e("tmessages", e);
}
if (result.size() == 2) {
existingChat = (TLRPC.EncryptedChat)result.get(0);
TLRPC.User user = (TLRPC.User)result.get(1);
users.putIfAbsent(user.id, user);
}
}
if (newChat instanceof TLRPC.TL_encryptedChatRequested && existingChat == null) { if (newChat instanceof TLRPC.TL_encryptedChatRequested && existingChat == null) {
int user_id = newChat.participant_id; int user_id = newChat.participant_id;
...@@ -4289,7 +4278,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter ...@@ -4289,7 +4278,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
} }
if (ApplicationLoader.lastPauseTime != 0) { if (ApplicationLoader.lastPauseTime != 0) {
ApplicationLoader.lastPauseTime = System.currentTimeMillis(); ApplicationLoader.lastPauseTime = System.currentTimeMillis();
FileLog.e("tmessages", "reset sleep timeout by recieved message"); FileLog.e("tmessages", "reset sleep timeout by received message");
} }
if (messageObject == null) { if (messageObject == null) {
return; return;
...@@ -4654,12 +4643,12 @@ public class MessagesController implements NotificationCenter.NotificationCenter ...@@ -4654,12 +4643,12 @@ public class MessagesController implements NotificationCenter.NotificationCenter
} }
} }
public TLRPC.Message decryptMessage(TLRPC.EncryptedMessage message) { public TLRPC.EncryptedChat getEncryptedChat(int chat_id) {
TLRPC.EncryptedChat chat = encryptedChats.get(message.chat_id); TLRPC.EncryptedChat chat = encryptedChats.get(chat_id);
if (chat == null) { if (chat == null) {
Semaphore semaphore = new Semaphore(0); Semaphore semaphore = new Semaphore(0);
ArrayList<TLObject> result = new ArrayList<TLObject>(); ArrayList<TLObject> result = new ArrayList<TLObject>();
MessagesStorage.getInstance().getEncryptedChat(message.chat_id, semaphore, result); MessagesStorage.getInstance().getEncryptedChat(chat_id, semaphore, result);
try { try {
semaphore.acquire(); semaphore.acquire();
} catch (Exception e) { } catch (Exception e) {
...@@ -4672,6 +4661,11 @@ public class MessagesController implements NotificationCenter.NotificationCenter ...@@ -4672,6 +4661,11 @@ public class MessagesController implements NotificationCenter.NotificationCenter
users.putIfAbsent(user.id, user); users.putIfAbsent(user.id, user);
} }
} }
return chat;
}
public TLRPC.Message decryptMessage(TLRPC.EncryptedMessage message) {
TLRPC.EncryptedChat chat = getEncryptedChat(message.chat_id);
if (chat == null) { if (chat == null) {
return null; return null;
} }
......
...@@ -15,8 +15,6 @@ public class NotificationCenter { ...@@ -15,8 +15,6 @@ public class NotificationCenter {
final private HashMap<Integer, ArrayList<Object>> observers = new HashMap<Integer, ArrayList<Object>>(); final private HashMap<Integer, ArrayList<Object>> observers = new HashMap<Integer, ArrayList<Object>>();
final private HashMap<String, Object> memCache = new HashMap<String, Object>();
final private HashMap<Integer, Object> removeAfterBroadcast = new HashMap<Integer, Object>(); final private HashMap<Integer, Object> removeAfterBroadcast = new HashMap<Integer, Object>();
final private HashMap<Integer, Object> addAfterBroadcast = new HashMap<Integer, Object>(); final private HashMap<Integer, Object> addAfterBroadcast = new HashMap<Integer, Object>();
...@@ -40,27 +38,6 @@ public class NotificationCenter { ...@@ -40,27 +38,6 @@ public class NotificationCenter {
public abstract void didReceivedNotification(int id, Object... args); public abstract void didReceivedNotification(int id, Object... args);
} }
public void addToMemCache(int id, Object object) {
addToMemCache(String.valueOf(id), object);
}
public void addToMemCache(String id, Object object) {
memCache.put(id, object);
}
public Object getFromMemCache(int id) {
return getFromMemCache(String.valueOf(id), null);
}
public Object getFromMemCache(String id, Object defaultValue) {
Object obj = memCache.get(id);
if (obj != null) {
memCache.remove(id);
return obj;
}
return defaultValue;
}
public void postNotificationName(int id, Object... args) { public void postNotificationName(int id, Object... args) {
synchronized (observers) { synchronized (observers) {
broadcasting = true; broadcasting = true;
......
...@@ -59,7 +59,6 @@ public class TcpConnection extends ConnectionContext { ...@@ -59,7 +59,6 @@ public class TcpConnection extends ConnectionContext {
private boolean firstPacket; private boolean firstPacket;
private Timer reconnectTimer; private Timer reconnectTimer;
private boolean tryWithNoNetworkAnyway = false;
public TcpConnection(int did) { public TcpConnection(int did) {
if (selector == null) { if (selector == null) {
...@@ -81,6 +80,43 @@ public class TcpConnection extends ConnectionContext { ...@@ -81,6 +80,43 @@ public class TcpConnection extends ConnectionContext {
} }
public void connect() { public void connect() {
if (!ConnectionsManager.isNetworkOnline()) {
synchronized (timerSync) {
reconnectTimer = new Timer();
reconnectTimer.schedule(new TimerTask() {
@Override
public void run() {
selector.scheduleTask(new Runnable() {
@Override
public void run() {
try {
synchronized (timerSync) {
if (reconnectTimer != null) {
reconnectTimer.cancel();
reconnectTimer = null;
}
}
} catch (Exception e2) {
FileLog.e("tmessages", e2);
}
connect();
}
});
}
}, 500);
}
if (delegate != null) {
final TcpConnectionDelegate finalDelegate = delegate;
Utilities.stageQueue.postRunnable(new Runnable() {
@Override
public void run() {
finalDelegate.tcpConnectionClosed(TcpConnection.this);
}
});
}
return;
}
selector.scheduleTask(new Runnable() { selector.scheduleTask(new Runnable() {
@Override @Override
public void run() { public void run() {
...@@ -94,14 +130,6 @@ public class TcpConnection extends ConnectionContext { ...@@ -94,14 +130,6 @@ public class TcpConnection extends ConnectionContext {
hostAddress = datacenter.getCurrentAddress(); hostAddress = datacenter.getCurrentAddress();
hostPort = datacenter.getCurrentPort(); hostPort = datacenter.getCurrentPort();
if(android.os.Build.VERSION.SDK_INT < 11) {
if (!ConnectionsManager.isNetworkOnline() && !tryWithNoNetworkAnyway) {
handleConnectionError(null);
tryWithNoNetworkAnyway = true;
return;
}
tryWithNoNetworkAnyway = false;
}
try { try {
synchronized (timerSync) { synchronized (timerSync) {
if (reconnectTimer != null) { if (reconnectTimer != null) {
...@@ -637,28 +665,30 @@ public class TcpConnection extends ConnectionContext { ...@@ -637,28 +665,30 @@ public class TcpConnection extends ConnectionContext {
} }
FileLog.d("tmessages", "Reconnect " + hostAddress + ":" + hostPort + " " + TcpConnection.this); FileLog.d("tmessages", "Reconnect " + hostAddress + ":" + hostPort + " " + TcpConnection.this);
try { try {
reconnectTimer = new Timer(); synchronized (timerSync) {
reconnectTimer.schedule(new TimerTask() { reconnectTimer = new Timer();
@Override reconnectTimer.schedule(new TimerTask() {
public void run() { @Override
selector.scheduleTask(new Runnable() { public void run() {
@Override selector.scheduleTask(new Runnable() {
public void run() { @Override
try { public void run() {
synchronized (timerSync) { try {
if (reconnectTimer != null) { synchronized (timerSync) {
reconnectTimer.cancel(); if (reconnectTimer != null) {
reconnectTimer = null; reconnectTimer.cancel();
reconnectTimer = null;
}
} }
} catch (Exception e2) {
FileLog.e("tmessages", e2);
} }
} catch (Exception e2) { connect();
FileLog.e("tmessages", e2);
} }
connect(); });
} }
}); }, failedConnectionCount > 3 ? 500 : 300, failedConnectionCount > 3 ? 500 : 300);
} }
}, failedConnectionCount > 3 ? 500 : 300, failedConnectionCount > 3 ? 500 : 300);
} catch (Exception e3) { } catch (Exception e3) {
FileLog.e("tmessages", e3); FileLog.e("tmessages", e3);
} }
......
...@@ -14,6 +14,7 @@ import android.content.ContentUris; ...@@ -14,6 +14,7 @@ import android.content.ContentUris;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.database.Cursor; import android.database.Cursor;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Point; import android.graphics.Point;
...@@ -27,6 +28,7 @@ import android.text.Html; ...@@ -27,6 +28,7 @@ import android.text.Html;
import android.text.SpannableStringBuilder; import android.text.SpannableStringBuilder;
import android.util.Base64; import android.util.Base64;
import android.view.Display; import android.view.Display;
import android.view.Surface;
import android.view.View; import android.view.View;
import android.view.WindowManager; import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
...@@ -72,6 +74,7 @@ public class Utilities { ...@@ -72,6 +74,7 @@ public class Utilities {
public static Pattern pattern = Pattern.compile("[0-9]+"); public static Pattern pattern = Pattern.compile("[0-9]+");
public static SecureRandom random = new SecureRandom(); public static SecureRandom random = new SecureRandom();
private final static Integer lock = 1; private final static Integer lock = 1;
private static int prevOrientation = -10;
private static boolean waitingForSms = false; private static boolean waitingForSms = false;
private static final Integer smsLock = 2; private static final Integer smsLock = 2;
...@@ -152,6 +155,47 @@ public class Utilities { ...@@ -152,6 +155,47 @@ public class Utilities {
public native static void aesIgeEncryption2(ByteBuffer _what, byte[] _key, byte[] _iv, boolean encrypt, boolean changeIv, int len); public native static void aesIgeEncryption2(ByteBuffer _what, byte[] _key, byte[] _iv, boolean encrypt, boolean changeIv, int len);
public native static void loadBitmap(String path, Bitmap bitmap, int scale); public native static void loadBitmap(String path, Bitmap bitmap, int scale);
public static void lockOrientation(Activity activity) {
if (prevOrientation != -10) {
return;
}
try {
prevOrientation = activity.getRequestedOrientation();
WindowManager manager = (WindowManager)activity.getSystemService(Activity.WINDOW_SERVICE);
if (manager != null && manager.getDefaultDisplay() != null) {
int rotation = manager.getDefaultDisplay().getRotation();
if (rotation == Surface.ROTATION_270) {
if (Build.VERSION.SDK_INT >= 9) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
} else {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
} else if (rotation == Surface.ROTATION_90) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
} else if (rotation == Surface.ROTATION_0) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
} else {
if (Build.VERSION.SDK_INT >= 9) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
}
}
}
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
public static void unlockOrientation(Activity activity) {
try {
if (prevOrientation != -10) {
activity.setRequestedOrientation(prevOrientation);
prevOrientation = -10;
}
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
public static boolean isWaitingForSms() { public static boolean isWaitingForSms() {
boolean value = false; boolean value = false;
synchronized (smsLock) { synchronized (smsLock) {
......
...@@ -152,10 +152,12 @@ public class ApplicationLoader extends Application { ...@@ -152,10 +152,12 @@ public class ApplicationLoader extends Application {
if (preferences.getBoolean("pushService", true)) { if (preferences.getBoolean("pushService", true)) {
applicationContext.startService(new Intent(applicationContext, NotificationsService.class)); applicationContext.startService(new Intent(applicationContext, NotificationsService.class));
Calendar cal = Calendar.getInstance(); if (android.os.Build.VERSION.SDK_INT >= 19) {
PendingIntent pintent = PendingIntent.getService(applicationContext, 0, new Intent(applicationContext, NotificationsService.class), 0); Calendar cal = Calendar.getInstance();
AlarmManager alarm = (AlarmManager) applicationContext.getSystemService(Context.ALARM_SERVICE); PendingIntent pintent = PendingIntent.getService(applicationContext, 0, new Intent(applicationContext, NotificationsService.class), 0);
alarm.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 30000, pintent); AlarmManager alarm = (AlarmManager) applicationContext.getSystemService(Context.ALARM_SERVICE);
alarm.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 30000, pintent);
}
} else { } else {
stopPushService(); stopPushService();
} }
......
...@@ -28,6 +28,7 @@ import org.telegram.messenger.R; ...@@ -28,6 +28,7 @@ import org.telegram.messenger.R;
import org.telegram.messenger.Utilities; import org.telegram.messenger.Utilities;
import org.telegram.objects.MessageObject; import org.telegram.objects.MessageObject;
import org.telegram.objects.PhotoObject; import org.telegram.objects.PhotoObject;
import org.telegram.ui.PhotoViewer;
import org.telegram.ui.Views.GifDrawable; import org.telegram.ui.Views.GifDrawable;
import org.telegram.ui.Views.ImageReceiver; import org.telegram.ui.Views.ImageReceiver;
import org.telegram.ui.Views.ProgressView; import org.telegram.ui.Views.ProgressView;
...@@ -39,7 +40,7 @@ import java.util.Locale; ...@@ -39,7 +40,7 @@ import java.util.Locale;
public class ChatMediaCell extends ChatBaseCell implements MediaController.FileDownloadProgressListener { public class ChatMediaCell extends ChatBaseCell implements MediaController.FileDownloadProgressListener {
public static interface ChatMediaCellDelegate { public static interface ChatMediaCellDelegate {
public abstract void didPressedImage(ChatMediaCell cell, ImageReceiver imageReceiver); public abstract void didPressedImage(ChatMediaCell cell);
} }
private static Drawable placeholderInDrawable; private static Drawable placeholderInDrawable;
...@@ -196,7 +197,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD ...@@ -196,7 +197,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
if (currentMessageObject.type == 1) { if (currentMessageObject.type == 1) {
if (buttonState == -1) { if (buttonState == -1) {
if (mediaDelegate != null) { if (mediaDelegate != null) {
mediaDelegate.didPressedImage(this, photoImage); mediaDelegate.didPressedImage(this);
} }
} else if (buttonState == 0) { } else if (buttonState == 0) {
didPressedButton(); didPressedButton();
...@@ -217,7 +218,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD ...@@ -217,7 +218,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
} }
} else if (currentMessageObject.type == 4) { } else if (currentMessageObject.type == 4) {
if (mediaDelegate != null) { if (mediaDelegate != null) {
mediaDelegate.didPressedImage(this, photoImage); mediaDelegate.didPressedImage(this);
} }
} }
} }
...@@ -271,7 +272,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD ...@@ -271,7 +272,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
} }
} else if (buttonState == 3) { } else if (buttonState == 3) {
if (mediaDelegate != null) { if (mediaDelegate != null) {
mediaDelegate.didPressedImage(this, photoImage); mediaDelegate.didPressedImage(this);
} }
} }
} }
...@@ -421,6 +422,10 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD ...@@ -421,6 +422,10 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
updateButtonState(); updateButtonState();
} }
public ImageReceiver getPhotoImage() {
return photoImage;
}
public void updateButtonState() { public void updateButtonState() {
String fileName = null; String fileName = null;
File cacheFile = null; File cacheFile = null;
...@@ -544,6 +549,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD ...@@ -544,6 +549,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
gifDrawable.draw(canvas); gifDrawable.draw(canvas);
canvas.restore(); canvas.restore();
} else { } else {
photoImage.setVisible(!PhotoViewer.getInstance().isShowingImage(currentMessageObject), false);
photoImage.draw(canvas, photoImage.imageX, photoImage.imageY, photoWidth, photoHeight); photoImage.draw(canvas, photoImage.imageX, photoImage.imageY, photoWidth, photoHeight);
drawTime = photoImage.getVisible(); drawTime = photoImage.getVisible();
} }
......
...@@ -39,6 +39,7 @@ import org.telegram.messenger.NotificationCenter; ...@@ -39,6 +39,7 @@ import org.telegram.messenger.NotificationCenter;
import org.telegram.messenger.R; import org.telegram.messenger.R;
import org.telegram.messenger.UserConfig; import org.telegram.messenger.UserConfig;
import org.telegram.messenger.Utilities; import org.telegram.messenger.Utilities;
import org.telegram.objects.MessageObject;
import org.telegram.ui.Cells.ChatOrUserCell; import org.telegram.ui.Cells.ChatOrUserCell;
import org.telegram.ui.Views.ActionBar.ActionBarLayer; import org.telegram.ui.Views.ActionBar.ActionBarLayer;
import org.telegram.ui.Views.ActionBar.ActionBarMenu; import org.telegram.ui.Views.ActionBar.ActionBarMenu;
...@@ -51,7 +52,7 @@ import java.util.Collections; ...@@ -51,7 +52,7 @@ import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
public class ChatProfileActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate, ContactsActivity.ContactsActivityDelegate { public class ChatProfileActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate, ContactsActivity.ContactsActivityDelegate, PhotoViewer.PhotoViewerProvider {
private ListView listView; private ListView listView;
private ListAdapter listViewAdapter; private ListAdapter listViewAdapter;
private int chat_id; private int chat_id;
...@@ -90,7 +91,6 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen ...@@ -90,7 +91,6 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen
NotificationCenter.getInstance().addObserver(this, MessagesController.closeChats); NotificationCenter.getInstance().addObserver(this, MessagesController.closeChats);
chat_id = getArguments().getInt("chat_id", 0); chat_id = getArguments().getInt("chat_id", 0);
info = (TLRPC.ChatParticipants)NotificationCenter.getInstance().getFromMemCache(5);
updateOnlineCount(); updateOnlineCount();
MessagesController.getInstance().getMediaCount(-chat_id, classGuid, true); MessagesController.getInstance().getMediaCount(-chat_id, classGuid, true);
avatarUpdater.delegate = new AvatarUpdater.AvatarUpdaterDelegate() { avatarUpdater.delegate = new AvatarUpdater.AvatarUpdaterDelegate() {
...@@ -336,6 +336,37 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen ...@@ -336,6 +336,37 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen
} }
} }
@Override
public PhotoViewer.PlaceProviderObject getPlaceForPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation) {
if (fileLocation == null) {
return null;
}
TLRPC.Chat chat = MessagesController.getInstance().chats.get(chat_id);
if (chat != null && chat.photo != null && chat.photo.photo_big != null) {
TLRPC.FileLocation photoBig = chat.photo.photo_big;
if (photoBig.local_id == fileLocation.local_id && photoBig.volume_id == fileLocation.volume_id && photoBig.dc_id == fileLocation.dc_id) {
int count = listView.getChildCount();
for (int a = 0; a < count; a++) {
View view = listView.getChildAt(a);
BackupImageView avatarImage = (BackupImageView)view.findViewById(R.id.settings_avatar_image);
if (avatarImage != null) {
int coords[] = new int[2];
avatarImage.getLocationInWindow(coords);
PhotoViewer.PlaceProviderObject object = new PhotoViewer.PlaceProviderObject();
object.viewX = coords[0];
object.viewY = coords[1] - Utilities.statusBarHeight;
object.parentView = listView;
object.imageReceiver = avatarImage.imageReceiver;
object.thumb = object.imageReceiver.getBitmap();
object.size = -1;
return object;
}
}
}
}
return null;
}
public void didReceivedNotification(int id, Object... args) { public void didReceivedNotification(int id, Object... args) {
if (id == MessagesController.updateInterfaces) { if (id == MessagesController.updateInterfaces) {
int mask = (Integer)args[0]; int mask = (Integer)args[0];
...@@ -377,6 +408,10 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen ...@@ -377,6 +408,10 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen
} }
} }
public void setChatInfo(TLRPC.ChatParticipants chatParticipants) {
info = chatParticipants;
}
private void updateVisibleRows(int mask) { private void updateVisibleRows(int mask) {
if (listView == null) { if (listView == null) {
return; return;
...@@ -441,9 +476,7 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen ...@@ -441,9 +476,7 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen
if (action == 0) { if (action == 0) {
TLRPC.Chat chat = MessagesController.getInstance().chats.get(chat_id); TLRPC.Chat chat = MessagesController.getInstance().chats.get(chat_id);
if (chat.photo != null && chat.photo.photo_big != null) { if (chat.photo != null && chat.photo.photo_big != null) {
NotificationCenter.getInstance().addToMemCache(53, chat.photo.photo_big); PhotoViewer.getInstance().openPhoto(chat.photo.photo_big, this);
Intent intent = new Intent(getParentActivity(), GalleryImageViewer.class);
getParentActivity().startActivity(intent);
} }
} else if (action == 1) { } else if (action == 1) {
avatarUpdater.openCamera(); avatarUpdater.openCamera();
...@@ -606,10 +639,13 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen ...@@ -606,10 +639,13 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen
} }
TLRPC.FileLocation photo = null; TLRPC.FileLocation photo = null;
TLRPC.FileLocation photoBig = null;
if (chat.photo != null) { if (chat.photo != null) {
photo = chat.photo.photo_small; photo = chat.photo.photo_small;
photoBig = chat.photo.photo_big;
} }
avatarImage.setImage(photo, "50_50", Utilities.getGroupAvatarForId(chat.id)); avatarImage.setImage(photo, "50_50", Utilities.getGroupAvatarForId(chat.id));
avatarImage.imageReceiver.setVisible(!PhotoViewer.getInstance().isShowingImage(photoBig), false);
return view; return view;
} else if (type == 1) { } else if (type == 1) {
if (view == null) { if (view == null) {
......
...@@ -21,7 +21,6 @@ import android.view.View; ...@@ -21,7 +21,6 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.BaseAdapter; import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView; import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
...@@ -423,12 +422,10 @@ public class DocumentSelectActivity extends BaseFragment { ...@@ -423,12 +422,10 @@ public class DocumentSelectActivity extends BaseFragment {
imageView.setImageBitmap(null); imageView.setImageBitmap(null);
typeTextView.setText(item.ext.toUpperCase().substring(0, Math.min(item.ext.length(), 4))); typeTextView.setText(item.ext.toUpperCase().substring(0, Math.min(item.ext.length(), 4)));
imageView.setImage(item.thumb, "55_42", 0); imageView.setImage(item.thumb, "55_42", 0);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setVisibility(View.VISIBLE); imageView.setVisibility(View.VISIBLE);
typeTextView.setVisibility(View.VISIBLE); typeTextView.setVisibility(View.VISIBLE);
} else if (item.icon != 0) { } else if (item.icon != 0) {
imageView.setImageResource(item.icon); imageView.setImageResource(item.icon);
imageView.setScaleType(ImageView.ScaleType.CENTER);
imageView.setVisibility(View.VISIBLE); imageView.setVisibility(View.VISIBLE);
typeTextView.setVisibility(View.GONE); typeTextView.setVisibility(View.GONE);
} else { } else {
......
...@@ -103,7 +103,6 @@ public class LaunchActivity extends ActionBarActivity implements NotificationCen ...@@ -103,7 +103,6 @@ public class LaunchActivity extends ActionBarActivity implements NotificationCen
NotificationCenter.getInstance().addObserver(this, 701); NotificationCenter.getInstance().addObserver(this, 701);
NotificationCenter.getInstance().addObserver(this, 702); NotificationCenter.getInstance().addObserver(this, 702);
NotificationCenter.getInstance().addObserver(this, 703); NotificationCenter.getInstance().addObserver(this, 703);
NotificationCenter.getInstance().addObserver(this, GalleryImageViewer.needShowAllMedia);
statusView = getLayoutInflater().inflate(R.layout.updating_state_layout, null); statusView = getLayoutInflater().inflate(R.layout.updating_state_layout, null);
statusBackground = statusView.findViewById(R.id.back_button_background); statusBackground = statusView.findViewById(R.id.back_button_background);
...@@ -601,7 +600,6 @@ public class LaunchActivity extends ActionBarActivity implements NotificationCen ...@@ -601,7 +600,6 @@ public class LaunchActivity extends ActionBarActivity implements NotificationCen
NotificationCenter.getInstance().removeObserver(this, 701); NotificationCenter.getInstance().removeObserver(this, 701);
NotificationCenter.getInstance().removeObserver(this, 702); NotificationCenter.getInstance().removeObserver(this, 702);
NotificationCenter.getInstance().removeObserver(this, 703); NotificationCenter.getInstance().removeObserver(this, 703);
NotificationCenter.getInstance().removeObserver(this, GalleryImageViewer.needShowAllMedia);
if (notificationView != null) { if (notificationView != null) {
notificationView.hide(false); notificationView.hide(false);
notificationView.destroy(); notificationView.destroy();
...@@ -642,17 +640,13 @@ public class LaunchActivity extends ActionBarActivity implements NotificationCen ...@@ -642,17 +640,13 @@ public class LaunchActivity extends ActionBarActivity implements NotificationCen
startActivity(intent2); startActivity(intent2);
onFinish(); onFinish();
finish(); finish();
} else if (id == GalleryImageViewer.needShowAllMedia) {
long dialog_id = (Long)args[0];
if (dialog_id != 0) {
Bundle args2 = new Bundle();
args2.putLong("dialog_id", dialog_id);
presentFragment(new MediaActivity(args2), false, true);
}
} else if (id == 658) { } else if (id == 658) {
Integer push_user_id = (Integer)NotificationCenter.getInstance().getFromMemCache("push_user_id", 0); if (PhotoViewer.getInstance().isVisible()) {
Integer push_chat_id = (Integer)NotificationCenter.getInstance().getFromMemCache("push_chat_id", 0); PhotoViewer.getInstance().closePhoto(false);
Integer push_enc_id = (Integer)NotificationCenter.getInstance().getFromMemCache("push_enc_id", 0); }
Integer push_chat_id = (Integer)args[0];
Integer push_user_id = (Integer)args[1];
Integer push_enc_id = (Integer)args[2];
if (push_user_id != 0) { if (push_user_id != 0) {
NotificationCenter.getInstance().postNotificationName(MessagesController.closeChats); NotificationCenter.getInstance().postNotificationName(MessagesController.closeChats);
...@@ -750,7 +744,7 @@ public class LaunchActivity extends ActionBarActivity implements NotificationCen ...@@ -750,7 +744,7 @@ public class LaunchActivity extends ActionBarActivity implements NotificationCen
@Override @Override
public void onBackPressed() { public void onBackPressed() {
if (PhotoViewer.getInstance().isVisible()) { if (PhotoViewer.getInstance().isVisible()) {
PhotoViewer.getInstance().closePhoto(); PhotoViewer.getInstance().closePhoto(true);
} else { } else {
super.onBackPressed(); super.onBackPressed();
} }
...@@ -759,7 +753,7 @@ public class LaunchActivity extends ActionBarActivity implements NotificationCen ...@@ -759,7 +753,7 @@ public class LaunchActivity extends ActionBarActivity implements NotificationCen
@Override @Override
public boolean onPreIme() { public boolean onPreIme() {
if (PhotoViewer.getInstance().isVisible()) { if (PhotoViewer.getInstance().isVisible()) {
PhotoViewer.getInstance().closePhoto(); PhotoViewer.getInstance().closePhoto(true);
return true; return true;
} }
return super.onPreIme(); return super.onPreIme();
......
...@@ -60,7 +60,6 @@ public class LocationActivity extends BaseFragment implements NotificationCenter ...@@ -60,7 +60,6 @@ public class LocationActivity extends BaseFragment implements NotificationCenter
@Override @Override
public boolean onFragmentCreate() { public boolean onFragmentCreate() {
super.onFragmentCreate(); super.onFragmentCreate();
messageObject = (MessageObject)NotificationCenter.getInstance().getFromMemCache(0);
NotificationCenter.getInstance().addObserver(this, MessagesController.closeChats); NotificationCenter.getInstance().addObserver(this, MessagesController.closeChats);
if (messageObject != null) { if (messageObject != null) {
NotificationCenter.getInstance().addObserver(this, MessagesController.updateInterfaces); NotificationCenter.getInstance().addObserver(this, MessagesController.updateInterfaces);
...@@ -294,6 +293,10 @@ public class LocationActivity extends BaseFragment implements NotificationCenter ...@@ -294,6 +293,10 @@ public class LocationActivity extends BaseFragment implements NotificationCenter
} }
} }
public void setMessageObject(MessageObject message) {
messageObject = message;
}
@Override @Override
public void didReceivedNotification(int id, Object... args) { public void didReceivedNotification(int id, Object... args) {
if (id == MessagesController.updateInterfaces) { if (id == MessagesController.updateInterfaces) {
......
...@@ -10,7 +10,6 @@ package org.telegram.ui; ...@@ -10,7 +10,6 @@ package org.telegram.ui;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
...@@ -32,6 +31,7 @@ import org.telegram.objects.MessageObject; ...@@ -32,6 +31,7 @@ import org.telegram.objects.MessageObject;
import org.telegram.messenger.MessagesController; import org.telegram.messenger.MessagesController;
import org.telegram.messenger.NotificationCenter; import org.telegram.messenger.NotificationCenter;
import org.telegram.messenger.R; import org.telegram.messenger.R;
import org.telegram.objects.PhotoObject;
import org.telegram.ui.Views.ActionBar.ActionBarLayer; import org.telegram.ui.Views.ActionBar.ActionBarLayer;
import org.telegram.ui.Views.BackupImageView; import org.telegram.ui.Views.BackupImageView;
import org.telegram.ui.Views.ActionBar.BaseFragment; import org.telegram.ui.Views.ActionBar.BaseFragment;
...@@ -39,7 +39,7 @@ import org.telegram.ui.Views.ActionBar.BaseFragment; ...@@ -39,7 +39,7 @@ import org.telegram.ui.Views.ActionBar.BaseFragment;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
public class MediaActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate { public class MediaActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate, PhotoViewer.PhotoViewerProvider {
private GridView listView; private GridView listView;
private ListAdapter listAdapter; private ListAdapter listAdapter;
private ArrayList<MessageObject> messages = new ArrayList<MessageObject>(); private ArrayList<MessageObject> messages = new ArrayList<MessageObject>();
...@@ -114,10 +114,7 @@ public class MediaActivity extends BaseFragment implements NotificationCenter.No ...@@ -114,10 +114,7 @@ public class MediaActivity extends BaseFragment implements NotificationCenter.No
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override @Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
NotificationCenter.getInstance().addToMemCache(54, messages); PhotoViewer.getInstance().openPhoto(messages, i, MediaActivity.this);
NotificationCenter.getInstance().addToMemCache(55, i);
Intent intent = new Intent(getParentActivity(), GalleryImageViewer.class);
getParentActivity().startActivity(intent);
} }
}); });
if (loading && messages.isEmpty()) { if (loading && messages.isEmpty()) {
...@@ -266,6 +263,41 @@ public class MediaActivity extends BaseFragment implements NotificationCenter.No ...@@ -266,6 +263,41 @@ public class MediaActivity extends BaseFragment implements NotificationCenter.No
fixLayout(); fixLayout();
} }
@Override
public PhotoViewer.PlaceProviderObject getPlaceForPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation) {
if (messageObject == null) {
return null;
}
int count = listView.getChildCount();
for (int a = 0; a < count; a++) {
View view = listView.getChildAt(a);
BackupImageView imageView = (BackupImageView)view.findViewById(R.id.media_photo_image);
if (imageView != null) {
int num = (Integer)imageView.getTag();
if (num < 0 || num >= messages.size()) {
continue;
}
MessageObject message = messages.get(num);
if (message != null && message.messageOwner.id == messageObject.messageOwner.id) {
int coords[] = new int[2];
imageView.getLocationInWindow(coords);
PhotoViewer.PlaceProviderObject object = new PhotoViewer.PlaceProviderObject();
object.viewX = coords[0];
object.viewY = coords[1] - Utilities.statusBarHeight;
object.parentView = listView;
object.imageReceiver = imageView.imageReceiver;
object.thumb = object.imageReceiver.getBitmap();
return object;
}
}
}
return null;
// NotificationCenter.getInstance().addToMemCache(54, messages); TODO
// NotificationCenter.getInstance().addToMemCache(55, i);
}
private void fixLayout() { private void fixLayout() {
if (listView != null) { if (listView != null) {
ViewTreeObserver obs = listView.getViewTreeObserver(); ViewTreeObserver obs = listView.getViewTreeObserver();
...@@ -351,20 +383,20 @@ public class MediaActivity extends BaseFragment implements NotificationCenter.No ...@@ -351,20 +383,20 @@ public class MediaActivity extends BaseFragment implements NotificationCenter.No
view.setLayoutParams(params); view.setLayoutParams(params);
BackupImageView imageView = (BackupImageView)view.findViewById(R.id.media_photo_image); BackupImageView imageView = (BackupImageView)view.findViewById(R.id.media_photo_image);
imageView.setTag(i);
if (message.messageOwner.media != null && message.messageOwner.media.photo != null && !message.messageOwner.media.photo.sizes.isEmpty()) { if (message.messageOwner.media != null && message.messageOwner.media.photo != null && !message.messageOwner.media.photo.sizes.isEmpty()) {
ArrayList<TLRPC.PhotoSize> sizes = message.messageOwner.media.photo.sizes; ArrayList<TLRPC.PhotoSize> sizes = message.messageOwner.media.photo.sizes;
boolean set = false; if (message.imagePreview != null) {
if (!set) { imageView.setImageBitmap(message.imagePreview);
if (message.imagePreview != null) { } else {
imageView.setImageBitmap(message.imagePreview); TLRPC.PhotoSize photoSize = PhotoObject.getClosestPhotoSizeWithSize(message.messageOwner.media.photo.sizes, 80, 80);
} else { imageView.setImage(photoSize.location, null, R.drawable.photo_placeholder_in);
imageView.setImage(message.messageOwner.media.photo.sizes.get(0).location, null, R.drawable.photo_placeholder_in);
}
} }
} else { } else {
imageView.setImageResource(R.drawable.photo_placeholder_in); imageView.setImageResource(R.drawable.photo_placeholder_in);
} }
imageView.imageReceiver.setVisible(!PhotoViewer.getInstance().isShowingImage(message), false);
} else if (type == 1) { } else if (type == 1) {
MessageObject message = messages.get(i); MessageObject message = messages.get(i);
if (view == null) { if (view == null) {
...@@ -378,6 +410,7 @@ public class MediaActivity extends BaseFragment implements NotificationCenter.No ...@@ -378,6 +410,7 @@ public class MediaActivity extends BaseFragment implements NotificationCenter.No
TextView textView = (TextView)view.findViewById(R.id.chat_video_time); TextView textView = (TextView)view.findViewById(R.id.chat_video_time);
BackupImageView imageView = (BackupImageView)view.findViewById(R.id.media_photo_image); BackupImageView imageView = (BackupImageView)view.findViewById(R.id.media_photo_image);
imageView.setTag(i);
if (message.messageOwner.media.video != null && message.messageOwner.media.video.thumb != null) { if (message.messageOwner.media.video != null && message.messageOwner.media.video.thumb != null) {
int duration = message.messageOwner.media.video.duration; int duration = message.messageOwner.media.video.duration;
...@@ -394,6 +427,7 @@ public class MediaActivity extends BaseFragment implements NotificationCenter.No ...@@ -394,6 +427,7 @@ public class MediaActivity extends BaseFragment implements NotificationCenter.No
textView.setVisibility(View.GONE); textView.setVisibility(View.GONE);
imageView.setImageResource(R.drawable.photo_placeholder_in); imageView.setImageResource(R.drawable.photo_placeholder_in);
} }
imageView.imageReceiver.setVisible(!PhotoViewer.getInstance().isShowingImage(message), false);
} else if (type == 2) { } else if (type == 2) {
if (view == null) { if (view == null) {
LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
......
...@@ -51,6 +51,7 @@ import org.telegram.messenger.R; ...@@ -51,6 +51,7 @@ import org.telegram.messenger.R;
import org.telegram.messenger.RPCRequest; import org.telegram.messenger.RPCRequest;
import org.telegram.messenger.UserConfig; import org.telegram.messenger.UserConfig;
import org.telegram.messenger.Utilities; import org.telegram.messenger.Utilities;
import org.telegram.objects.MessageObject;
import org.telegram.objects.PhotoObject; import org.telegram.objects.PhotoObject;
import org.telegram.ui.Views.ActionBar.ActionBarLayer; import org.telegram.ui.Views.ActionBar.ActionBarLayer;
import org.telegram.ui.Views.AvatarUpdater; import org.telegram.ui.Views.AvatarUpdater;
...@@ -61,7 +62,7 @@ import java.io.File; ...@@ -61,7 +62,7 @@ import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Locale; import java.util.Locale;
public class SettingsActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate { public class SettingsActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate, PhotoViewer.PhotoViewerProvider {
private ListView listView; private ListView listView;
private ListAdapter listAdapter; private ListAdapter listAdapter;
private AvatarUpdater avatarUpdater = new AvatarUpdater(); private AvatarUpdater avatarUpdater = new AvatarUpdater();
...@@ -411,6 +412,38 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter ...@@ -411,6 +412,38 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
return fragmentView; return fragmentView;
} }
@Override
public PhotoViewer.PlaceProviderObject getPlaceForPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation) {
if (fileLocation == null) {
return null;
}
TLRPC.User user = MessagesController.getInstance().users.get(UserConfig.clientUserId);
if (user != null && user.photo != null && user.photo.photo_big != null) {
TLRPC.FileLocation photoBig = user.photo.photo_big;
if (photoBig.local_id == fileLocation.local_id && photoBig.volume_id == fileLocation.volume_id && photoBig.dc_id == fileLocation.dc_id) {
int count = listView.getChildCount();
for (int a = 0; a < count; a++) {
View view = listView.getChildAt(a);
BackupImageView avatarImage = (BackupImageView)view.findViewById(R.id.settings_avatar_image);
if (avatarImage != null) {
int coords[] = new int[2];
avatarImage.getLocationInWindow(coords);
PhotoViewer.PlaceProviderObject object = new PhotoViewer.PlaceProviderObject();
object.viewX = coords[0];
object.viewY = coords[1] - Utilities.statusBarHeight;
object.parentView = listView;
object.imageReceiver = avatarImage.imageReceiver;
object.user_id = UserConfig.clientUserId;
object.thumb = object.imageReceiver.getBitmap();
object.size = -1;
return object;
}
}
}
}
return null;
}
public void performAskAQuestion() { public void performAskAQuestion() {
final SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); final SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
int uid = preferences.getInt("support_id", 0); int uid = preferences.getInt("support_id", 0);
...@@ -638,10 +671,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter ...@@ -638,10 +671,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
if (i == 0 && full) { if (i == 0 && full) {
TLRPC.User user = MessagesController.getInstance().users.get(UserConfig.clientUserId); TLRPC.User user = MessagesController.getInstance().users.get(UserConfig.clientUserId);
if (user != null && user.photo != null && user.photo.photo_big != null) { if (user != null && user.photo != null && user.photo.photo_big != null) {
NotificationCenter.getInstance().addToMemCache(56, user.id); PhotoViewer.getInstance().openPhoto(user.photo.photo_big, SettingsActivity.this);
NotificationCenter.getInstance().addToMemCache(53, user.photo.photo_big);
Intent intent = new Intent(getParentActivity(), GalleryImageViewer.class);
getParentActivity().startActivity(intent);
} }
} else if (i == 0 && !full || i == 1 && full) { } else if (i == 0 && !full || i == 1 && full) {
avatarUpdater.openCamera(); avatarUpdater.openCamera();
...@@ -714,10 +744,13 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter ...@@ -714,10 +744,13 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
BackupImageView avatarImage = (BackupImageView)view.findViewById(R.id.settings_avatar_image); BackupImageView avatarImage = (BackupImageView)view.findViewById(R.id.settings_avatar_image);
avatarImage.processDetach = false; avatarImage.processDetach = false;
TLRPC.FileLocation photo = null; TLRPC.FileLocation photo = null;
TLRPC.FileLocation photoBig = null;
if (user.photo != null) { if (user.photo != null) {
photo = user.photo.photo_small; photo = user.photo.photo_small;
photoBig = user.photo.photo_big;
} }
avatarImage.setImage(photo, null, Utilities.getUserAvatarForId(user.id)); avatarImage.setImage(photo, "50_50", Utilities.getUserAvatarForId(user.id));
avatarImage.imageReceiver.setVisible(!PhotoViewer.getInstance().isShowingImage(photoBig), false);
} }
return view; return view;
} else if (type == 1) { } else if (type == 1) {
......
...@@ -184,10 +184,8 @@ public class SettingsBlockedUsers extends BaseFragment implements NotificationCe ...@@ -184,10 +184,8 @@ public class SettingsBlockedUsers extends BaseFragment implements NotificationCe
if (progressView != null) { if (progressView != null) {
progressView.setVisibility(View.GONE); progressView.setVisibility(View.GONE);
} }
if (listView != null) { if (listView != null && listView.getEmptyView() == null) {
if (listView.getEmptyView() == null) { listView.setEmptyView(emptyView);
listView.setEmptyView(emptyView);
}
} }
if (listViewAdapter != null) { if (listViewAdapter != null) {
listViewAdapter.notifyDataSetChanged(); listViewAdapter.notifyDataSetChanged();
...@@ -212,10 +210,8 @@ public class SettingsBlockedUsers extends BaseFragment implements NotificationCe ...@@ -212,10 +210,8 @@ public class SettingsBlockedUsers extends BaseFragment implements NotificationCe
if (progressView != null) { if (progressView != null) {
progressView.setVisibility(View.GONE); progressView.setVisibility(View.GONE);
} }
if (listView != null) { if (listView != null && listView.getEmptyView() == null) {
if (listView.getEmptyView() == null) { listView.setEmptyView(emptyView);
listView.setEmptyView(emptyView);
}
} }
if (listViewAdapter != null) { if (listViewAdapter != null) {
listViewAdapter.notifyDataSetChanged(); listViewAdapter.notifyDataSetChanged();
......
...@@ -212,9 +212,13 @@ public class SettingsNotificationsActivity extends BaseFragment { ...@@ -212,9 +212,13 @@ public class SettingsNotificationsActivity extends BaseFragment {
SharedPreferences.Editor editor = preferences.edit(); SharedPreferences.Editor editor = preferences.edit();
editor.clear(); editor.clear();
editor.commit(); editor.commit();
listView.invalidateViews(); if (listView != null) {
Toast toast = Toast.makeText(getParentActivity(), R.string.ResetNotificationsText, Toast.LENGTH_SHORT); listView.invalidateViews();
toast.show(); }
if (getParentActivity() != null) {
Toast toast = Toast.makeText(getParentActivity(), R.string.ResetNotificationsText, Toast.LENGTH_SHORT);
toast.show();
}
} }
}); });
} }
......
...@@ -42,6 +42,7 @@ import org.telegram.messenger.NotificationCenter; ...@@ -42,6 +42,7 @@ import org.telegram.messenger.NotificationCenter;
import org.telegram.messenger.R; import org.telegram.messenger.R;
import org.telegram.messenger.RPCRequest; import org.telegram.messenger.RPCRequest;
import org.telegram.messenger.Utilities; import org.telegram.messenger.Utilities;
import org.telegram.objects.MessageObject;
import org.telegram.ui.Views.ActionBar.ActionBarLayer; import org.telegram.ui.Views.ActionBar.ActionBarLayer;
import org.telegram.ui.Views.ActionBar.ActionBarMenu; import org.telegram.ui.Views.ActionBar.ActionBarMenu;
import org.telegram.ui.Views.ActionBar.ActionBarMenuItem; import org.telegram.ui.Views.ActionBar.ActionBarMenuItem;
...@@ -51,7 +52,7 @@ import org.telegram.ui.Views.IdenticonView; ...@@ -51,7 +52,7 @@ import org.telegram.ui.Views.IdenticonView;
import java.util.ArrayList; import java.util.ArrayList;
public class UserProfileActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate, MessagesActivity.MessagesActivityDelegate { public class UserProfileActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate, MessagesActivity.MessagesActivityDelegate, PhotoViewer.PhotoViewerProvider {
private ListView listView; private ListView listView;
private ListAdapter listAdapter; private ListAdapter listAdapter;
private int user_id; private int user_id;
...@@ -452,6 +453,38 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen ...@@ -452,6 +453,38 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen
} }
} }
@Override
public PhotoViewer.PlaceProviderObject getPlaceForPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation) {
if (fileLocation == null) {
return null;
}
TLRPC.User user = MessagesController.getInstance().users.get(user_id);
if (user != null && user.photo != null && user.photo.photo_big != null) {
TLRPC.FileLocation photoBig = user.photo.photo_big;
if (photoBig.local_id == fileLocation.local_id && photoBig.volume_id == fileLocation.volume_id && photoBig.dc_id == fileLocation.dc_id) {
int count = listView.getChildCount();
for (int a = 0; a < count; a++) {
View view = listView.getChildAt(a);
BackupImageView avatarImage = (BackupImageView)view.findViewById(R.id.settings_avatar_image);
if (avatarImage != null) {
int coords[] = new int[2];
avatarImage.getLocationInWindow(coords);
PhotoViewer.PlaceProviderObject object = new PhotoViewer.PlaceProviderObject();
object.viewX = coords[0];
object.viewY = coords[1] - Utilities.statusBarHeight;
object.parentView = listView;
object.imageReceiver = avatarImage.imageReceiver;
object.user_id = user_id;
object.thumb = object.imageReceiver.getBitmap();
object.size = -1;
return object;
}
}
}
}
return null;
}
private void createActionBarMenu() { private void createActionBarMenu() {
ActionBarMenu menu = actionBarLayer.createMenu(); ActionBarMenu menu = actionBarLayer.createMenu();
menu.clearItems(); menu.clearItems();
...@@ -557,10 +590,7 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen ...@@ -557,10 +590,7 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen
public void onClick(View view) { public void onClick(View view) {
TLRPC.User user = MessagesController.getInstance().users.get(user_id); TLRPC.User user = MessagesController.getInstance().users.get(user_id);
if (user.photo != null && user.photo.photo_big != null) { if (user.photo != null && user.photo.photo_big != null) {
NotificationCenter.getInstance().addToMemCache(56, user_id); PhotoViewer.getInstance().openPhoto(user.photo.photo_big, UserProfileActivity.this);
NotificationCenter.getInstance().addToMemCache(53, user.photo.photo_big);
Intent intent = new Intent(getParentActivity(), GalleryImageViewer.class);
getParentActivity().startActivity(intent);
} }
} }
}); });
...@@ -576,10 +606,13 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen ...@@ -576,10 +606,13 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen
onlineText.setText(LocaleController.formatUserStatus(user)); onlineText.setText(LocaleController.formatUserStatus(user));
TLRPC.FileLocation photo = null; TLRPC.FileLocation photo = null;
TLRPC.FileLocation photoBig = null;
if (user.photo != null) { if (user.photo != null) {
photo = user.photo.photo_small; photo = user.photo.photo_small;
photoBig = user.photo.photo_big;
} }
avatarImage.setImage(photo, "50_50", Utilities.getUserAvatarForId(user.id)); avatarImage.setImage(photo, "50_50", Utilities.getUserAvatarForId(user.id));
avatarImage.imageReceiver.setVisible(!PhotoViewer.getInstance().isShowingImage(photoBig), false);
return view; return view;
} else if (type == 1) { } else if (type == 1) {
if (view == null) { if (view == null) {
......
/*
* This is the source code of Telegram for Android v. 1.3.2.
* It is licensed under GNU GPL v. 2 or later.
* You should have received a copy of the license in this archive (see LICENSE).
*
* Copyright Nikolai Kudashov, 2013.
*/
package org.telegram.ui.Views;
import org.telegram.objects.MessageObject;
public abstract class AbstractGalleryActivity extends PausableActivity {
public abstract void topBtn();
public abstract void didShowMessageObject(MessageObject obj);
}
\ No newline at end of file
...@@ -111,12 +111,13 @@ public class ActionBar extends FrameLayout { ...@@ -111,12 +111,13 @@ public class ActionBar extends FrameLayout {
currentLayer.setBackLayoutVisible(currentLayer.isSearchFieldVisible || currentBackOverlay == null ? VISIBLE : INVISIBLE); currentLayer.setBackLayoutVisible(currentLayer.isSearchFieldVisible || currentBackOverlay == null ? VISIBLE : INVISIBLE);
} }
if (currentBackOverlay != null) { if (currentBackOverlay != null) {
currentBackOverlay.setVisibility(currentLayer.isSearchFieldVisible ? GONE : VISIBLE);
ViewGroup.LayoutParams layoutParams = currentBackOverlay.getLayoutParams(); ViewGroup.LayoutParams layoutParams = currentBackOverlay.getLayoutParams();
if (currentLayer != null) { if (currentLayer != null) {
currentBackOverlay.setVisibility(currentLayer.isSearchFieldVisible ? GONE : VISIBLE);
currentLayer.measure(widthMeasureSpec, heightMeasureSpec); currentLayer.measure(widthMeasureSpec, heightMeasureSpec);
layoutParams.width = Math.min(currentBackOverlayWidth, currentLayer.getBackLayoutWidth()); layoutParams.width = Math.min(currentBackOverlayWidth, currentLayer.getBackLayoutWidth());
} else { } else {
currentBackOverlay.setVisibility(VISIBLE);
layoutParams.width = LayoutParams.WRAP_CONTENT; layoutParams.width = LayoutParams.WRAP_CONTENT;
} }
if (layoutParams.width != 0) { if (layoutParams.width != 0) {
......
...@@ -13,7 +13,6 @@ import android.animation.AnimatorSet; ...@@ -13,7 +13,6 @@ import android.animation.AnimatorSet;
import android.animation.ObjectAnimator; import android.animation.ObjectAnimator;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
...@@ -21,7 +20,6 @@ import android.view.ActionMode; ...@@ -21,7 +20,6 @@ import android.view.ActionMode;
import android.view.Gravity; import android.view.Gravity;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.Surface;
import android.view.VelocityTracker; import android.view.VelocityTracker;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
...@@ -51,7 +49,6 @@ public class ActionBarActivity extends Activity { ...@@ -51,7 +49,6 @@ public class ActionBarActivity extends Activity {
private boolean maybeStartTracking = false; private boolean maybeStartTracking = false;
protected boolean startedTracking = false; protected boolean startedTracking = false;
private int startedTrackingX; private int startedTrackingX;
private int prevOrientation = -10;
protected boolean animationInProgress = false; protected boolean animationInProgress = false;
private VelocityTracker velocityTracker = null; private VelocityTracker velocityTracker = null;
private boolean beginTrackingSent = false; private boolean beginTrackingSent = false;
...@@ -206,14 +203,7 @@ public class ActionBarActivity extends Activity { ...@@ -206,14 +203,7 @@ public class ActionBarActivity extends Activity {
} }
} }
containerViewBack.setVisibility(View.GONE); containerViewBack.setVisibility(View.GONE);
try { Utilities.unlockOrientation(this);
if (prevOrientation != -10) {
setRequestedOrientation(prevOrientation);
prevOrientation = -10;
}
} catch (Exception e) {
FileLog.e("tmessages", e);
}
startedTracking = false; startedTracking = false;
animationInProgress = false; animationInProgress = false;
} }
...@@ -244,30 +234,7 @@ public class ActionBarActivity extends Activity { ...@@ -244,30 +234,7 @@ public class ActionBarActivity extends Activity {
} }
lastFragment.onResume(); lastFragment.onResume();
try { Utilities.lockOrientation(this);
prevOrientation = getRequestedOrientation();
WindowManager manager = (WindowManager)getSystemService(Activity.WINDOW_SERVICE);
if (manager != null && manager.getDefaultDisplay() != null) {
int rotation = manager.getDefaultDisplay().getRotation();
if (rotation == Surface.ROTATION_270) {
if (Build.VERSION.SDK_INT >= 9) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
} else {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
} else if (rotation == Surface.ROTATION_90) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
} else if (rotation == Surface.ROTATION_0) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
} else {
if (Build.VERSION.SDK_INT >= 9) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
}
}
}
} catch (Exception e) {
FileLog.e("tmessages", e);
}
} }
public boolean onTouchEvent(MotionEvent ev) { public boolean onTouchEvent(MotionEvent ev) {
......
...@@ -26,8 +26,14 @@ import org.telegram.messenger.Utilities; ...@@ -26,8 +26,14 @@ import org.telegram.messenger.Utilities;
public class ActionBarLayer extends FrameLayout { public class ActionBarLayer extends FrameLayout {
public interface ActionBarMenuOnItemClick { public static class ActionBarMenuOnItemClick {
public abstract void onItemClick(int id); public void onItemClick(int id) {
}
public boolean canOpenMenu() {
return true;
}
} }
private FrameLayout backButtonFrameLayout; private FrameLayout backButtonFrameLayout;
......
...@@ -75,7 +75,9 @@ public class ActionBarMenu extends LinearLayout { ...@@ -75,7 +75,9 @@ public class ActionBarMenu extends LinearLayout {
public void onClick(View view) { public void onClick(View view) {
ActionBarMenuItem item = (ActionBarMenuItem)view; ActionBarMenuItem item = (ActionBarMenuItem)view;
if (item.hasSubMenu()) { if (item.hasSubMenu()) {
item.toggleSubMenu(); if (parentActionBarLayer.actionBarMenuOnItemClick.canOpenMenu()) {
item.toggleSubMenu();
}
} else if (item.isSearchField()) { } else if (item.isSearchField()) {
parentActionBarLayer.onSearchFieldVisibilityChanged(item.toggleSearch()); parentActionBarLayer.onSearchFieldVisibilityChanged(item.toggleSearch());
} else { } else {
......
...@@ -79,6 +79,7 @@ public class ActionBarMenuItem extends ImageView { ...@@ -79,6 +79,7 @@ public class ActionBarMenuItem extends ImageView {
layoutParams.width = Utilities.dp(196); layoutParams.width = Utilities.dp(196);
layoutParams.height = Utilities.density >= 3 ? 2 : 1; layoutParams.height = Utilities.density >= 3 ? 2 : 1;
delimeter.setLayoutParams(layoutParams); delimeter.setLayoutParams(layoutParams);
delimeter.setTag(100 + id);
} }
TextView textView = new TextView(getContext()); TextView textView = new TextView(getContext());
textView.setTextColor(0xff000000); textView.setTextColor(0xff000000);
...@@ -255,4 +256,26 @@ public class ActionBarMenuItem extends ImageView { ...@@ -255,4 +256,26 @@ public class ActionBarMenuItem extends ImageView {
popupWindow.update(this, parentActionBar.getMeasuredWidth() - popupLayout.getMeasuredWidth() - getLeft() - parentMenu.getLeft(), 0, -1, -1); popupWindow.update(this, parentActionBar.getMeasuredWidth() - popupLayout.getMeasuredWidth() - getLeft() - parentMenu.getLeft(), 0, -1, -1);
} }
} }
public void hideSubItem(int id) {
View view = popupLayout.findViewWithTag(id);
if (view != null) {
view.setVisibility(GONE);
}
view = popupLayout.findViewWithTag(100 + id);
if (view != null) {
view.setVisibility(GONE);
}
}
public void showSubItem(int id) {
View view = popupLayout.findViewWithTag(id);
if (view != null) {
view.setVisibility(VISIBLE);
}
view = popupLayout.findViewWithTag(100 + id);
if (view != null) {
view.setVisibility(VISIBLE);
}
}
} }
/*
* This is the source code of Telegram for Android v. 1.4.x.
* It is licensed under GNU GPL v. 2 or later.
* You should have received a copy of the license in this archive (see LICENSE).
*
* Copyright Nikolai Kudashov, 2013-2014.
*/
package org.telegram.ui.Views;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.view.View;
public class ClippingImageView extends View {
private int clipBottom;
private int clipLeft;
private int clipRight;
private int clipTop;
private Rect drawRect;
private Paint paint;
private Bitmap bmp;
private onDrawListener drawListener;
public static interface onDrawListener {
public abstract void onDraw();
}
public ClippingImageView(Context context) {
super(context);
paint = new Paint();
paint.setFilterBitmap(true);
drawRect = new Rect();
}
public int getClipBottom() {
return clipBottom;
}
public int getClipHorizontal() {
return clipRight;
}
public int getClipLeft() {
return clipLeft;
}
public int getClipRight() {
return clipRight;
}
public int getClipTop() {
return clipTop;
}
public void onDraw(Canvas canvas) {
if (bmp != null) {
if (drawListener != null && getScaleY() != 1) {
drawListener.onDraw();
}
canvas.save();
canvas.clipRect(clipLeft / getScaleY(), clipTop / getScaleY(), getWidth() - clipRight / getScaleY(), getHeight() - clipBottom / getScaleY());
drawRect.set(0, 0, getWidth(), getHeight());
canvas.drawBitmap(this.bmp, null, drawRect, this.paint);
canvas.restore();
}
}
public void setClipBottom(int value) {
clipBottom = value;
invalidate();
}
public void setClipHorizontal(int value) {
clipRight = value;
clipLeft = value;
invalidate();
}
public void setClipLeft(int value) {
clipLeft = value;
invalidate();
}
public void setClipRight(int value) {
clipRight = value;
invalidate();
}
public void setClipTop(int value) {
clipTop = value;
invalidate();
}
public void setClipVertical(int value) {
clipBottom = value;
clipTop = value;
invalidate();
}
public void setImageBitmap(Bitmap bitmap) {
bmp = bitmap;
invalidate();
}
public void setOnDrawListener(onDrawListener listener) {
drawListener = listener;
}
}
...@@ -106,16 +106,7 @@ public class NotificationView extends LinearLayout { ...@@ -106,16 +106,7 @@ public class NotificationView extends LinearLayout {
} }
hide(true); hide(true);
if (currentChatId != 0) { NotificationCenter.getInstance().postNotificationName(658, currentChatId, currentUserId, currentEncId);
NotificationCenter.getInstance().addToMemCache("push_chat_id", currentChatId);
}
if (currentUserId != 0) {
NotificationCenter.getInstance().addToMemCache("push_user_id", currentUserId);
}
if (currentEncId != 0) {
NotificationCenter.getInstance().addToMemCache("push_enc_id", currentEncId);
}
NotificationCenter.getInstance().postNotificationName(658);
} }
}); });
......
<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#dd000000" />
</shape>
\ 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:drawable="@drawable/photocancel_pressed"
android:state_pressed="true" />
<item android:drawable="@drawable/photocancel" />
</selector>
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
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