Commit 9814a6e9 authored by DrKLO's avatar DrKLO

update to 1.3.19

Spanish localization by Borja Campina
Applied pull request by Yuri Orlov
(https://github.com/DrKLO/Telegram/pull/27)
parent 1a4d0786
...@@ -3,7 +3,7 @@ buildscript { ...@@ -3,7 +3,7 @@ buildscript {
mavenCentral() mavenCentral()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:0.7.+' classpath 'com.android.tools.build:gradle:0.8.+'
} }
} }
apply plugin: 'android' apply plugin: 'android'
...@@ -31,7 +31,7 @@ tasks.withType(JavaCompile) { ...@@ -31,7 +31,7 @@ tasks.withType(JavaCompile) {
} }
dependencies { dependencies {
compile 'com.google.android.gms:play-services:4.0.+' 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'
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.android.support:appcompat-v7:19.0.+'
...@@ -40,7 +40,7 @@ dependencies { ...@@ -40,7 +40,7 @@ dependencies {
android { android {
compileSdkVersion 19 compileSdkVersion 19
buildToolsVersion '19.0.0' buildToolsVersion '19.0.1'
signingConfigs { signingConfigs {
debug { debug {
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.telegram.messenger" package="org.telegram.messenger"
android:versionCode="131" android:versionCode="148"
android:versionName="1.3.7"> android:versionName="1.3.19">
<supports-screens android:anyDensity="true" <supports-screens android:anyDensity="true"
android:smallScreens="true" android:smallScreens="true"
...@@ -63,6 +63,7 @@ ...@@ -63,6 +63,7 @@
android:largeHeap="true"> android:largeHeap="true">
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="your-google-maps-api-key-here" /> <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="your-google-maps-api-key-here" />
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
<activity <activity
android:name="org.telegram.ui.LaunchActivity" android:name="org.telegram.ui.LaunchActivity"
...@@ -168,4 +169,3 @@ ...@@ -168,4 +169,3 @@
</application> </application>
</manifest> </manifest>
...@@ -32,7 +32,7 @@ public class TLObject { ...@@ -32,7 +32,7 @@ public class TLObject {
} }
public int layer () { public int layer () {
return 8; return 11;
} }
public void parseVector(TLRPC.Vector vector, SerializedData data) { public void parseVector(TLRPC.Vector vector, SerializedData data) {
......
...@@ -42,10 +42,14 @@ public class DispatchQueue extends Thread { ...@@ -42,10 +42,14 @@ public class DispatchQueue extends Thread {
} }
public void postRunnable(Runnable runnable) { public void postRunnable(Runnable runnable) {
postRunnable(runnable, 0); postRunnable(runnable, 0, false);
} }
public void postRunnable(Runnable runnable, int delay) { public void postRunnable(Runnable runnable, boolean inFront) {
postRunnable(runnable, 0, true);
}
public void postRunnable(Runnable runnable, int delay, boolean inFront) {
if (handler == null) { if (handler == null) {
try { try {
synchronized (handlerSyncObject) { synchronized (handlerSyncObject) {
...@@ -58,7 +62,11 @@ public class DispatchQueue extends Thread { ...@@ -58,7 +62,11 @@ public class DispatchQueue extends Thread {
if (handler != null) { if (handler != null) {
if (delay <= 0) { if (delay <= 0) {
if (inFront) {
handler.postAtFrontOfQueue(runnable);
} else {
handler.post(runnable); handler.post(runnable);
}
} else { } else {
handler.postDelayed(runnable, delay); handler.postDelayed(runnable, delay);
} }
......
...@@ -53,7 +53,7 @@ public class ExportAuthorizationAction extends Action { ...@@ -53,7 +53,7 @@ public class ExportAuthorizationAction extends Action {
public void run() { public void run() {
beginExport(); beginExport();
} }
}, retryCount * 1500); }, retryCount * 1500, false);
} }
} }
} }
...@@ -84,7 +84,7 @@ public class ExportAuthorizationAction extends Action { ...@@ -84,7 +84,7 @@ public class ExportAuthorizationAction extends Action {
public void run() { public void run() {
beginExport(); beginExport();
} }
}, retryCount * 1500); }, retryCount * 1500, false);
} }
} }
} }
......
...@@ -420,7 +420,12 @@ public class FileLoadOperation { ...@@ -420,7 +420,12 @@ public class FileLoadOperation {
if (renamed) { if (renamed) {
image = BitmapFactory.decodeStream(new FileInputStream(cacheFileFinal), null, opts); image = BitmapFactory.decodeStream(new FileInputStream(cacheFileFinal), null, opts);
} else { } else {
try {
image = BitmapFactory.decodeStream(new FileInputStream(cacheFileTemp), null, opts); image = BitmapFactory.decodeStream(new FileInputStream(cacheFileTemp), null, opts);
} catch (Exception e) {
FileLog.e("tmessages", e);
image = BitmapFactory.decodeStream(new FileInputStream(cacheFileFinal), null, opts);
}
} }
if (filter != null && image != null) { if (filter != null && image != null) {
float bitmapW = image.getWidth(); float bitmapW = image.getWidth();
...@@ -440,10 +445,11 @@ public class FileLoadOperation { ...@@ -440,10 +445,11 @@ public class FileLoadOperation {
if (FileLoader.Instance.runtimeHack != null) { if (FileLoader.Instance.runtimeHack != null) {
FileLoader.Instance.runtimeHack.trackFree(image.getRowBytes() * image.getHeight()); FileLoader.Instance.runtimeHack.trackFree(image.getRowBytes() * image.getHeight());
} }
delegate.didFinishLoadingFile(FileLoadOperation.this);
} catch (Exception e) { } catch (Exception e) {
FileLog.e("tmessages", e); FileLog.e("tmessages", e);
delegate.didFailedLoadingFile(FileLoadOperation.this);
} }
delegate.didFinishLoadingFile(FileLoadOperation.this);
} }
}); });
} else { } else {
......
...@@ -118,6 +118,8 @@ public class FileLog { ...@@ -118,6 +118,8 @@ public class FileLog {
} }
} }
}); });
} else {
e.printStackTrace();
} }
} }
......
...@@ -109,7 +109,16 @@ public class FileUploadOperation { ...@@ -109,7 +109,16 @@ public class FileUploadOperation {
isBigFile = true; isBigFile = true;
} }
uploadChunkSize = (int)Math.max(32, Math.ceil(totalFileSize / (1024.0f * 3000))) * 1024; uploadChunkSize = (int)Math.max(32, Math.ceil(totalFileSize / (1024.0f * 3000)));
if (1024 % uploadChunkSize != 0) {
int chunkSize = 64;
while (uploadChunkSize > chunkSize) {
chunkSize *= 2;
}
uploadChunkSize = chunkSize;
}
uploadChunkSize *= 1024;
totalPartsCount = (int)Math.ceil((float)totalFileSize / (float)uploadChunkSize); totalPartsCount = (int)Math.ceil((float)totalFileSize / (float)uploadChunkSize);
readBuffer = new byte[uploadChunkSize]; readBuffer = new byte[uploadChunkSize];
} }
......
...@@ -14,6 +14,7 @@ import android.content.Context; ...@@ -14,6 +14,7 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.os.PowerManager;
import com.google.android.gms.gcm.GoogleCloudMessaging; import com.google.android.gms.gcm.GoogleCloudMessaging;
...@@ -27,6 +28,10 @@ public class GcmBroadcastReceiver extends BroadcastReceiver { ...@@ -27,6 +28,10 @@ public class GcmBroadcastReceiver extends BroadcastReceiver {
setResultCode(Activity.RESULT_OK); setResultCode(Activity.RESULT_OK);
if (intent.getAction().equals("com.google.android.c2dm.intent.RECEIVE")) { if (intent.getAction().equals("com.google.android.c2dm.intent.RECEIVE")) {
PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
final PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "lock");
wl.acquire();
SharedPreferences preferences = context.getSharedPreferences("Notifications", Context.MODE_PRIVATE); SharedPreferences preferences = context.getSharedPreferences("Notifications", Context.MODE_PRIVATE);
boolean globalEnabled = preferences.getBoolean("EnableAll", true); boolean globalEnabled = preferences.getBoolean("EnableAll", true);
if (!globalEnabled) { if (!globalEnabled) {
...@@ -38,12 +43,13 @@ public class GcmBroadcastReceiver extends BroadcastReceiver { ...@@ -38,12 +43,13 @@ public class GcmBroadcastReceiver extends BroadcastReceiver {
public void run() { public void run() {
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(context); GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(context);
String messageType = gcm.getMessageType(intent); String messageType = gcm.getMessageType(intent);
sendNotification(context, intent.getExtras()); ConnectionsManager.Instance.resumeNetworkMaybe();
wl.release();
} }
}); });
thread.setPriority(Thread.MAX_PRIORITY); thread.setPriority(Thread.MAX_PRIORITY);
thread.start(); thread.start();
} else if (intent.getAction().equals("com.google.android.c2dm.intent.RECEIVE")) { } else if (intent.getAction().equals("com.google.android.c2dm.intent.REGISTRATION")) {
String registration = intent.getStringExtra("registration_id"); String registration = intent.getStringExtra("registration_id");
if (intent.getStringExtra("error") != null) { if (intent.getStringExtra("error") != null) {
FileLog.e("tmessages", "Registration failed, should try again later."); FileLog.e("tmessages", "Registration failed, should try again later.");
...@@ -54,157 +60,4 @@ public class GcmBroadcastReceiver extends BroadcastReceiver { ...@@ -54,157 +60,4 @@ public class GcmBroadcastReceiver extends BroadcastReceiver {
} }
} }
} }
private void sendNotification(Context context, Bundle extras) {
ConnectionsManager.Instance.resumeNetworkMaybe();
/*if (!UserConfig.clientActivated || context == null || extras == null) {
return;
}
SharedPreferences preferences = context.getSharedPreferences("Notifications", Context.MODE_PRIVATE);
boolean groupEnabled = preferences.getBoolean("EnableGroup", true);
boolean globalVibrate = preferences.getBoolean("EnableVibrateAll", true);
boolean groupVibrate = preferences.getBoolean("EnableVibrateGroup", true);
if (ApplicationLoader.Instance != null && (ApplicationLoader.lastPauseTime == 0 || ApplicationLoader.lastPauseTime > System.currentTimeMillis() - 200)) {
return;
}
String defaultPath = null;
Uri defaultUri = Settings.System.DEFAULT_NOTIFICATION_URI;
if (defaultUri != null) {
defaultPath = defaultUri.getPath();
}
String globalSound = preferences.getString("GlobalSoundPath", defaultPath);
String chatSound = preferences.getString("GroupSoundPath", defaultPath);
String userSoundPath = null;
String chatSoundPath = null;
NotificationManager mNotificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
Intent intent = new Intent(context, LaunchActivity.class);
String msg = extras.getString("message");
try {
String to_id = extras.getString("user_id");
int to = Integer.parseInt(to_id);
if (to != UserConfig.clientUserId) {
return;
}
} catch (Exception e) {
FileLog.e("tmessages", e);
}
int chat_id = 0;
int user_id = 0;
String custom = extras.getString("custom");
try {
if (custom != null) {
JSONObject obj = new JSONObject(custom);
if (obj.has("chat_id")) {
Object object = obj.get("chat_id");
if (object instanceof Integer) {
chat_id = (Integer)object;
} else if (object instanceof String) {
chat_id = Integer.parseInt((String)object);
}
if (chat_id != 0) {
intent.putExtra("chatId", chat_id);
}
} else if (obj.has("from_id")) {
Object object = obj.get("from_id");
if (object instanceof Integer) {
user_id = (Integer)object;
} else if (object instanceof String) {
user_id = Integer.parseInt((String)object);
}
if (user_id != 0) {
intent.putExtra("userId", user_id);
}
}
}
} catch (Exception e) {
FileLog.e("tmessages", e);
}
if (user_id != 0) {
String key = "notify_" + user_id;
boolean value = preferences.getBoolean(key, true);
if (!value) {
return;
}
userSoundPath = preferences.getString("sound_path_" + user_id, null);
}
if (chat_id != 0) {
if (!groupEnabled) {
return;
}
String key = "notify_" + (-chat_id);
boolean value = preferences.getBoolean(key, true);
if (!value) {
return;
}
chatSoundPath = preferences.getString("sound_chat_path_" + chat_id, null);
}
boolean needVibrate;
String choosenSoundPath = null;
if (chat_id != 0) {
needVibrate = groupVibrate;
} else {
needVibrate = globalVibrate;
}
if (user_id != 0) {
if (userSoundPath != null) {
choosenSoundPath = userSoundPath;
} else if (globalSound != null) {
choosenSoundPath = globalSound;
}
} else if (chat_id != 0) {
if (chatSoundPath != null) {
choosenSoundPath = chatSoundPath;
} else if (chatSound != null) {
choosenSoundPath = chatSound;
}
} else {
choosenSoundPath = globalSound;
}
intent.setAction("com.tmessages.openchat" + Math.random() + Integer.MAX_VALUE);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
//intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
.setContentTitle(ApplicationLoader.applicationContext.getString(R.string.AppName))
.setSmallIcon(R.drawable.notification)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(msg))
.setContentText(msg)
.setAutoCancel(true)
.setTicker(msg);
if (needVibrate) {
mBuilder.setVibrate(new long[]{0, 100, 0, 100});
}
if (choosenSoundPath != null && !choosenSoundPath.equals("NoSound")) {
if (choosenSoundPath.equals(defaultPath)) {
mBuilder.setSound(defaultUri);
} else {
mBuilder.setSound(Uri.parse(choosenSoundPath));
}
}
mBuilder.setContentIntent(contentIntent);
mNotificationManager.cancel(NOTIFICATION_ID);
Notification notification = mBuilder.build();
notification.ledARGB = 0xff00ff00;
notification.ledOnMS = 1000;
notification.ledOffMS = 1000;
notification.flags |= Notification.FLAG_SHOW_LIGHTS;
mNotificationManager.notify(NOTIFICATION_ID, notification);*/
}
} }
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -12,43 +12,42 @@ import java.util.ArrayList; ...@@ -12,43 +12,42 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
public class NotificationCenter { public class NotificationCenter {
public static NotificationCenter Instance = new 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<Integer, Object> memCache = new HashMap<Integer, Object>();
final private HashMap<String, Object> memCacheString = new HashMap<String, Object>(); final private HashMap<String, Object> memCache = new HashMap<String, Object>();
private boolean broadcasting = false;
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>();
private boolean broadcasting = false;
public interface NotificationCenterDelegate { public interface NotificationCenterDelegate {
public abstract void didReceivedNotification(int id, Object... args); public abstract void didReceivedNotification(int id, Object... args);
} }
public static NotificationCenter Instance = new NotificationCenter();
public void addToMemCache(int id, Object object) { public void addToMemCache(int id, Object object) {
memCache.put(id, object); addToMemCache(String.valueOf(id), object);
} }
public void addToMemCache(String id, Object object) { public void addToMemCache(String id, Object object) {
memCacheString.put(id, object); memCache.put(id, object);
} }
public Object getFromMemCache(int id) { public Object getFromMemCache(int id) {
return getFromMemCache(String.valueOf(id), null);
}
public Object getFromMemCache(String id, Object defaultValue) {
Object obj = memCache.get(id); Object obj = memCache.get(id);
if (obj != null) { if (obj != null) {
memCache.remove(id); memCache.remove(id);
}
return obj; return obj;
} }
public Object getFromMemCache(String id, Object defaultValue) {
Object obj = memCacheString.get(id);
if (obj != null) {
memCacheString.remove(id);
} else {
return defaultValue; return defaultValue;
} }
return obj;
}
public void postNotificationName(int id, Object... args) { public void postNotificationName(int id, Object... args) {
synchronized (observers) { synchronized (observers) {
...@@ -66,15 +65,24 @@ public class NotificationCenter { ...@@ -66,15 +65,24 @@ public class NotificationCenter {
} }
removeAfterBroadcast.clear(); removeAfterBroadcast.clear();
} }
if (!addAfterBroadcast.isEmpty()) {
for (HashMap.Entry<Integer, Object> entry : addAfterBroadcast.entrySet()) {
addObserver(entry.getValue(), entry.getKey());
}
addAfterBroadcast.clear();
}
} }
} }
public void addObserver(Object observer, int id) { public void addObserver(Object observer, int id) {
synchronized (observers) { synchronized (observers) {
if (broadcasting) {
addAfterBroadcast.put(id, observer);
return;
}
ArrayList<Object> objects = observers.get(id); ArrayList<Object> objects = observers.get(id);
if (objects == null) { if (objects == null) {
objects = new ArrayList<Object>(); observers.put(id, (objects = new ArrayList<Object>()));
observers.put(id, objects);
} }
if (objects.contains(observer)) { if (objects.contains(observer)) {
return; return;
...@@ -83,25 +91,6 @@ public class NotificationCenter { ...@@ -83,25 +91,6 @@ public class NotificationCenter {
} }
} }
// public void removeObserver(Object observer) {
// synchronized (observers) {
// if (broadcasting) {
// removeAfterBroadcast.put(-1, observer);
// return;
// }
// Integer[] keyArr = (Integer[])observers.keySet().toArray();
// for (int a = 0; a < observers.size(); a++) {
// Integer id = keyArr[a];
// ArrayList<Object> objects = observers.get(id);
// objects.remove(observer);
// if (objects.size() == 0) {
// observers.remove(id);
// a--;
// }
// }
// }
// }
public void removeObserver(Object observer, int id) { public void removeObserver(Object observer, int id) {
synchronized (observers) { synchronized (observers) {
if (broadcasting) { if (broadcasting) {
......
...@@ -29,6 +29,7 @@ public class RPCRequest { ...@@ -29,6 +29,7 @@ public class RPCRequest {
public static int RPCRequestClassUploadMedia = 4; public static int RPCRequestClassUploadMedia = 4;
public static int RPCRequestClassEnableUnauthorized = 8; public static int RPCRequestClassEnableUnauthorized = 8;
public static int RPCRequestClassFailOnServerErrors = 16; public static int RPCRequestClassFailOnServerErrors = 16;
public static int RPCRequestClassCanCompress = 32;
static int RPCRequestClassTransportMask = (RPCRequestClassGeneric | RPCRequestClassDownloadMedia | RPCRequestClassUploadMedia); static int RPCRequestClassTransportMask = (RPCRequestClassGeneric | RPCRequestClassDownloadMedia | RPCRequestClassUploadMedia);
...@@ -37,6 +38,7 @@ public class RPCRequest { ...@@ -37,6 +38,7 @@ public class RPCRequest {
int serverFailureCount; int serverFailureCount;
int flags; int flags;
public int retryCount = 0;
TLObject rawRequest; TLObject rawRequest;
TLObject rpcRequest; TLObject rpcRequest;
......
...@@ -15,8 +15,6 @@ import android.content.SharedPreferences; ...@@ -15,8 +15,6 @@ import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.telephony.SmsMessage; import android.telephony.SmsMessage;
import org.telegram.messenger.NotificationCenter;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
...@@ -27,6 +25,9 @@ public class SmsListener extends BroadcastReceiver { ...@@ -27,6 +25,9 @@ public class SmsListener extends BroadcastReceiver {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")) { if(intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")) {
if (!Utilities.isWaitingForSms()) {
return;
}
Bundle bundle = intent.getExtras(); Bundle bundle = intent.getExtras();
SmsMessage[] msgs; SmsMessage[] msgs;
if (bundle != null) { if (bundle != null) {
......
...@@ -50,6 +50,7 @@ public class TcpConnection extends PyroClientAdapter { ...@@ -50,6 +50,7 @@ public class TcpConnection extends PyroClientAdapter {
private boolean hasSomeDataSinceLastConnect = false; private boolean hasSomeDataSinceLastConnect = false;
private int willRetryConnectCount = 5; private int willRetryConnectCount = 5;
private boolean isNextPort = false; private boolean isNextPort = false;
private final Integer timerSync = 1;
public int transportRequestClass; public int transportRequestClass;
...@@ -86,10 +87,12 @@ public class TcpConnection extends PyroClientAdapter { ...@@ -86,10 +87,12 @@ public class TcpConnection extends PyroClientAdapter {
connectionState = TcpConnectionState.TcpConnectionStageConnecting; connectionState = TcpConnectionState.TcpConnectionStageConnecting;
try { try {
try { try {
synchronized (timerSync) {
if (reconnectTimer != null) { if (reconnectTimer != null) {
reconnectTimer.cancel(); reconnectTimer.cancel();
reconnectTimer = null; reconnectTimer = null;
} }
}
} catch (Exception e2) { } catch (Exception e2) {
FileLog.e("tmessages", e2); FileLog.e("tmessages", e2);
} }
...@@ -115,19 +118,22 @@ public class TcpConnection extends PyroClientAdapter { ...@@ -115,19 +118,22 @@ public class TcpConnection extends PyroClientAdapter {
selector.wakeup(); selector.wakeup();
} catch (Exception e) { } catch (Exception e) {
try { try {
synchronized (timerSync) {
if (reconnectTimer != null) { if (reconnectTimer != null) {
reconnectTimer.cancel(); reconnectTimer.cancel();
reconnectTimer = null; reconnectTimer = null;
} }
}
} catch (Exception e2) { } catch (Exception e2) {
FileLog.e("tmessages", e2); FileLog.e("tmessages", e2);
} }
connectionState = TcpConnectionState.TcpConnectionStageReconnecting; connectionState = TcpConnectionState.TcpConnectionStageReconnecting;
if (delegate != null) { if (delegate != null) {
final TcpConnectionDelegate finalDelegate = delegate;
Utilities.stageQueue.postRunnable(new Runnable() { Utilities.stageQueue.postRunnable(new Runnable() {
@Override @Override
public void run() { public void run() {
delegate.tcpConnectionClosed(TcpConnection.this); finalDelegate.tcpConnectionClosed(TcpConnection.this);
} }
}); });
} }
...@@ -160,10 +166,12 @@ public class TcpConnection extends PyroClientAdapter { ...@@ -160,10 +166,12 @@ public class TcpConnection extends PyroClientAdapter {
@Override @Override
public void run() { public void run() {
try { try {
synchronized (timerSync) {
if (reconnectTimer != null) { if (reconnectTimer != null) {
reconnectTimer.cancel(); reconnectTimer.cancel();
reconnectTimer = null; reconnectTimer = null;
} }
}
} catch (Exception e2) { } catch (Exception e2) {
FileLog.e("tmessages", e2); FileLog.e("tmessages", e2);
} }
...@@ -181,10 +189,12 @@ public class TcpConnection extends PyroClientAdapter { ...@@ -181,10 +189,12 @@ public class TcpConnection extends PyroClientAdapter {
} }
private void suspendConnectionInternal() { private void suspendConnectionInternal() {
synchronized (timerSync) {
if (reconnectTimer != null) { if (reconnectTimer != null) {
reconnectTimer.cancel(); reconnectTimer.cancel();
reconnectTimer = null; reconnectTimer = null;
} }
}
if (connectionState == TcpConnectionState.TcpConnectionStageIdle || connectionState == TcpConnectionState.TcpConnectionStageSuspended) { if (connectionState == TcpConnectionState.TcpConnectionStageIdle || connectionState == TcpConnectionState.TcpConnectionStageSuspended) {
return; return;
} }
...@@ -196,10 +206,11 @@ public class TcpConnection extends PyroClientAdapter { ...@@ -196,10 +206,11 @@ public class TcpConnection extends PyroClientAdapter {
client = null; client = null;
} }
if (delegate != null) { if (delegate != null) {
final TcpConnectionDelegate finalDelegate = delegate;
Utilities.stageQueue.postRunnable(new Runnable() { Utilities.stageQueue.postRunnable(new Runnable() {
@Override @Override
public void run() { public void run() {
delegate.tcpConnectionClosed(TcpConnection.this); finalDelegate.tcpConnectionClosed(TcpConnection.this);
} }
}); });
} }
...@@ -314,10 +325,11 @@ public class TcpConnection extends PyroClientAdapter { ...@@ -314,10 +325,11 @@ public class TcpConnection extends PyroClientAdapter {
buffer.order(ByteOrder.BIG_ENDIAN); buffer.order(ByteOrder.BIG_ENDIAN);
final int ackId = buffer.getInt() & (~(1 << 31)); final int ackId = buffer.getInt() & (~(1 << 31));
if (delegate != null) { if (delegate != null) {
final TcpConnectionDelegate finalDelegate = delegate;
Utilities.stageQueue.postRunnable(new Runnable() { Utilities.stageQueue.postRunnable(new Runnable() {
@Override @Override
public void run() { public void run() {
delegate.tcpConnectionQuiackAckReceived(TcpConnection.this, ackId); finalDelegate.tcpConnectionQuiackAckReceived(TcpConnection.this, ackId);
} }
}); });
} }
...@@ -360,12 +372,13 @@ public class TcpConnection extends PyroClientAdapter { ...@@ -360,12 +372,13 @@ public class TcpConnection extends PyroClientAdapter {
} }
if (lastMessageId != -1 && lastMessageId != 0) { if (lastMessageId != -1 && lastMessageId != 0) {
if (delegate != null) { if (delegate != null) {
final TcpConnectionDelegate finalDelegate = delegate;
final int arg2 = buffer.remaining(); final int arg2 = buffer.remaining();
final int arg3 = currentPacketLength; final int arg3 = currentPacketLength;
Utilities.stageQueue.postRunnable(new Runnable() { Utilities.stageQueue.postRunnable(new Runnable() {
@Override @Override
public void run() { public void run() {
delegate.tcpConnectionProgressChanged(TcpConnection.this, lastMessageId, arg2, arg3); finalDelegate.tcpConnectionProgressChanged(TcpConnection.this, lastMessageId, arg2, arg3);
} }
}); });
} }
...@@ -383,10 +396,11 @@ public class TcpConnection extends PyroClientAdapter { ...@@ -383,10 +396,11 @@ public class TcpConnection extends PyroClientAdapter {
buffer.get(packetData); buffer.get(packetData);
if (delegate != null) { if (delegate != null) {
final TcpConnectionDelegate finalDelegate = delegate;
Utilities.stageQueue.postRunnable(new Runnable() { Utilities.stageQueue.postRunnable(new Runnable() {
@Override @Override
public void run() { public void run() {
delegate.tcpConnectionReceivedData(TcpConnection.this, packetData); finalDelegate.tcpConnectionReceivedData(TcpConnection.this, packetData);
} }
}); });
} }
...@@ -394,10 +408,12 @@ public class TcpConnection extends PyroClientAdapter { ...@@ -394,10 +408,12 @@ public class TcpConnection extends PyroClientAdapter {
} }
public void handleDisconnect(PyroClient client, Exception e) { public void handleDisconnect(PyroClient client, Exception e) {
synchronized (timerSync) {
if (reconnectTimer != null) { if (reconnectTimer != null) {
reconnectTimer.cancel(); reconnectTimer.cancel();
reconnectTimer = null; reconnectTimer = null;
} }
}
if (e != null) { if (e != null) {
FileLog.d("tmessages", "Disconnected " + TcpConnection.this + " with error " + e); FileLog.d("tmessages", "Disconnected " + TcpConnection.this + " with error " + e);
} else { } else {
...@@ -410,12 +426,11 @@ public class TcpConnection extends PyroClientAdapter { ...@@ -410,12 +426,11 @@ public class TcpConnection extends PyroClientAdapter {
connectionState = TcpConnectionState.TcpConnectionStageIdle; connectionState = TcpConnectionState.TcpConnectionStageIdle;
} }
if (delegate != null) { if (delegate != null) {
final TcpConnectionDelegate finalDelegate = delegate;
Utilities.stageQueue.postRunnable(new Runnable() { Utilities.stageQueue.postRunnable(new Runnable() {
@Override @Override
public void run() { public void run() {
if (delegate != null) { finalDelegate.tcpConnectionClosed(TcpConnection.this);
delegate.tcpConnectionClosed(TcpConnection.this);
}
} }
}); });
} }
...@@ -447,10 +462,12 @@ public class TcpConnection extends PyroClientAdapter { ...@@ -447,10 +462,12 @@ public class TcpConnection extends PyroClientAdapter {
@Override @Override
public void run() { public void run() {
try { try {
synchronized (timerSync) {
if (reconnectTimer != null) { if (reconnectTimer != null) {
reconnectTimer.cancel(); reconnectTimer.cancel();
reconnectTimer = null; reconnectTimer = null;
} }
}
} catch (Exception e2) { } catch (Exception e2) {
FileLog.e("tmessages", e2); FileLog.e("tmessages", e2);
} }
...@@ -471,10 +488,11 @@ public class TcpConnection extends PyroClientAdapter { ...@@ -471,10 +488,11 @@ public class TcpConnection extends PyroClientAdapter {
channelToken = generateChannelToken(); channelToken = generateChannelToken();
FileLog.d("tmessages", String.format(TcpConnection.this + " Connected (%s:%d)", hostAddress, hostPort)); FileLog.d("tmessages", String.format(TcpConnection.this + " Connected (%s:%d)", hostAddress, hostPort));
if (delegate != null) { if (delegate != null) {
final TcpConnectionDelegate finalDelegate = delegate;
Utilities.stageQueue.postRunnable(new Runnable() { Utilities.stageQueue.postRunnable(new Runnable() {
@Override @Override
public void run() { public void run() {
delegate.tcpConnectionConnected(TcpConnection.this); finalDelegate.tcpConnectionConnected(TcpConnection.this);
} }
}); });
} }
......
...@@ -27,7 +27,6 @@ public class UserConfig { ...@@ -27,7 +27,6 @@ public class UserConfig {
public static int lastSendMessageId = -210000; public static int lastSendMessageId = -210000;
public static int lastLocalId = -210000; public static int lastLocalId = -210000;
public static String contactsHash = ""; public static String contactsHash = "";
public static String importHash = "";
private final static Integer sync = 1; private final static Integer sync = 1;
public static boolean saveIncomingPhotos = false; public static boolean saveIncomingPhotos = false;
...@@ -55,7 +54,6 @@ public class UserConfig { ...@@ -55,7 +54,6 @@ public class UserConfig {
editor.putInt("lastSendMessageId", lastSendMessageId); editor.putInt("lastSendMessageId", lastSendMessageId);
editor.putInt("lastLocalId", lastLocalId); editor.putInt("lastLocalId", lastLocalId);
editor.putString("contactsHash", contactsHash); editor.putString("contactsHash", contactsHash);
editor.putString("importHash", importHash);
editor.putBoolean("saveIncomingPhotos", saveIncomingPhotos); editor.putBoolean("saveIncomingPhotos", saveIncomingPhotos);
if (withFile) { if (withFile) {
SerializedData data = new SerializedData(); SerializedData data = new SerializedData();
...@@ -71,7 +69,6 @@ public class UserConfig { ...@@ -71,7 +69,6 @@ public class UserConfig {
editor.putInt("lastSendMessageId", lastSendMessageId); editor.putInt("lastSendMessageId", lastSendMessageId);
editor.putInt("lastLocalId", lastLocalId); editor.putInt("lastLocalId", lastLocalId);
editor.putString("contactsHash", contactsHash); editor.putString("contactsHash", contactsHash);
editor.putString("importHash", importHash);
editor.putBoolean("saveIncomingPhotos", saveIncomingPhotos); editor.putBoolean("saveIncomingPhotos", saveIncomingPhotos);
editor.remove("user"); editor.remove("user");
} }
...@@ -105,7 +102,7 @@ public class UserConfig { ...@@ -105,7 +102,7 @@ public class UserConfig {
lastSendMessageId = data.readInt32(); lastSendMessageId = data.readInt32();
lastLocalId = data.readInt32(); lastLocalId = data.readInt32();
contactsHash = data.readString(); contactsHash = data.readString();
importHash = data.readString(); data.readString();
saveIncomingPhotos = data.readBool(); saveIncomingPhotos = data.readBool();
if (currentUser.status != null) { if (currentUser.status != null) {
if (currentUser.status.expires != 0) { if (currentUser.status.expires != 0) {
...@@ -139,7 +136,6 @@ public class UserConfig { ...@@ -139,7 +136,6 @@ public class UserConfig {
lastSendMessageId = preferences.getInt("lastSendMessageId", -210000); lastSendMessageId = preferences.getInt("lastSendMessageId", -210000);
lastLocalId = preferences.getInt("lastLocalId", -210000); lastLocalId = preferences.getInt("lastLocalId", -210000);
contactsHash = preferences.getString("contactsHash", ""); contactsHash = preferences.getString("contactsHash", "");
importHash = preferences.getString("importHash", "");
saveIncomingPhotos = preferences.getBoolean("saveIncomingPhotos", false); saveIncomingPhotos = preferences.getBoolean("saveIncomingPhotos", false);
} }
if (lastLocalId > -210000) { if (lastLocalId > -210000) {
...@@ -164,7 +160,6 @@ public class UserConfig { ...@@ -164,7 +160,6 @@ public class UserConfig {
lastSendMessageId = preferences.getInt("lastSendMessageId", -210000); lastSendMessageId = preferences.getInt("lastSendMessageId", -210000);
lastLocalId = preferences.getInt("lastLocalId", -210000); lastLocalId = preferences.getInt("lastLocalId", -210000);
contactsHash = preferences.getString("contactsHash", ""); contactsHash = preferences.getString("contactsHash", "");
importHash = preferences.getString("importHash", "");
saveIncomingPhotos = preferences.getBoolean("saveIncomingPhotos", false); saveIncomingPhotos = preferences.getBoolean("saveIncomingPhotos", false);
String user = preferences.getString("user", null); String user = preferences.getString("user", null);
if (user != null) { if (user != null) {
...@@ -191,7 +186,6 @@ public class UserConfig { ...@@ -191,7 +186,6 @@ public class UserConfig {
registeredForPush = false; registeredForPush = false;
contactsHash = ""; contactsHash = "";
lastLocalId = -210000; lastLocalId = -210000;
importHash = "";
lastSendMessageId = -210000; lastSendMessageId = -210000;
saveIncomingPhotos = false; saveIncomingPhotos = false;
saveConfig(true); saveConfig(true);
......
...@@ -30,7 +30,7 @@ public class PhotoObject { ...@@ -30,7 +30,7 @@ public class PhotoObject {
opts.outWidth = photo.w; opts.outWidth = photo.w;
opts.outHeight = photo.h; opts.outHeight = photo.h;
image = BitmapFactory.decodeByteArray(photoOwner.bytes, 0, photoOwner.bytes.length, opts); image = BitmapFactory.decodeByteArray(photoOwner.bytes, 0, photoOwner.bytes.length, opts);
if (FileLoader.Instance.runtimeHack != null) { if (image != null && FileLoader.Instance.runtimeHack != null) {
FileLoader.Instance.runtimeHack.trackFree(image.getRowBytes() * image.getHeight()); FileLoader.Instance.runtimeHack.trackFree(image.getRowBytes() * image.getHeight());
} }
} }
...@@ -46,7 +46,7 @@ public class PhotoObject { ...@@ -46,7 +46,7 @@ public class PhotoObject {
} }
int diffW = Math.abs(obj.photoOwner.w - width); int diffW = Math.abs(obj.photoOwner.w - width);
int diffH = Math.abs(obj.photoOwner.h - height); int diffH = Math.abs(obj.photoOwner.h - height);
if (closestObject == null || closestWidth > diffW && closestHeight > diffH || closestObject.photoOwner instanceof TLRPC.TL_photoCachedSize) { if (closestObject == null || closestWidth > diffW || closestHeight > diffH || closestObject.photoOwner instanceof TLRPC.TL_photoCachedSize) {
closestObject = obj; closestObject = obj;
closestWidth = diffW; closestWidth = diffW;
closestHeight = diffH; closestHeight = diffH;
......
...@@ -25,6 +25,7 @@ import android.view.View; ...@@ -25,6 +25,7 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.ViewTreeObserver; import android.view.ViewTreeObserver;
import android.view.WindowManager; import android.view.WindowManager;
import android.widget.EditText;
import android.widget.TextView; import android.widget.TextView;
import org.telegram.messenger.ConnectionsManager; import org.telegram.messenger.ConnectionsManager;
...@@ -196,7 +197,7 @@ public class ApplicationActivity extends ActionBarActivity implements Notificati ...@@ -196,7 +197,7 @@ public class ApplicationActivity extends ActionBarActivity implements Notificati
method.invoke(field.get(getSupportActionBar()), false); method.invoke(field.get(getSupportActionBar()), false);
} }
} catch (Exception e) { } catch (Exception e) {
FileLog.e("tmessages", e); e.printStackTrace();
} }
} }
...@@ -333,6 +334,10 @@ public class ApplicationActivity extends ActionBarActivity implements Notificati ...@@ -333,6 +334,10 @@ public class ApplicationActivity extends ActionBarActivity implements Notificati
if (notificationView != null) { if (notificationView != null) {
notificationView.hide(false); notificationView.hide(false);
} }
View focusView = getCurrentFocus();
if (focusView instanceof EditText) {
focusView.clearFocus();
}
} }
@Override @Override
...@@ -581,13 +586,13 @@ public class ApplicationActivity extends ActionBarActivity implements Notificati ...@@ -581,13 +586,13 @@ public class ApplicationActivity extends ActionBarActivity implements Notificati
try { try {
if (statusView.getLayoutParams() instanceof android.support.v7.app.ActionBar.LayoutParams) { if (statusView.getLayoutParams() instanceof android.support.v7.app.ActionBar.LayoutParams) {
android.support.v7.app.ActionBar.LayoutParams statusParams = (android.support.v7.app.ActionBar.LayoutParams)statusView.getLayoutParams(); android.support.v7.app.ActionBar.LayoutParams statusParams = (android.support.v7.app.ActionBar.LayoutParams)statusView.getLayoutParams();
statusText.measure(View.MeasureSpec.makeMeasureSpec(800, View.MeasureSpec.AT_MOST), 100); statusText.measure(View.MeasureSpec.makeMeasureSpec(800, View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(100, View.MeasureSpec.AT_MOST));
statusParams.width = (int)(statusText.getMeasuredWidth() + Utilities.dp(54)); statusParams.width = (statusText.getMeasuredWidth() + Utilities.dp(54));
statusView.setLayoutParams(statusParams); statusView.setLayoutParams(statusParams);
} else if (statusView.getLayoutParams() instanceof android.app.ActionBar.LayoutParams) { } else if (statusView.getLayoutParams() instanceof android.app.ActionBar.LayoutParams) {
android.app.ActionBar.LayoutParams statusParams = (android.app.ActionBar.LayoutParams)statusView.getLayoutParams(); android.app.ActionBar.LayoutParams statusParams = (android.app.ActionBar.LayoutParams)statusView.getLayoutParams();
statusText.measure(View.MeasureSpec.makeMeasureSpec(800, View.MeasureSpec.AT_MOST), 100); statusText.measure(View.MeasureSpec.makeMeasureSpec(800, View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(100, View.MeasureSpec.AT_MOST));
statusParams.width = (int)(statusText.getMeasuredWidth() + Utilities.dp(54)); statusParams.width = (statusText.getMeasuredWidth() + Utilities.dp(54));
statusView.setLayoutParams(statusParams); statusView.setLayoutParams(statusParams);
} }
} catch (Exception e) { } catch (Exception e) {
...@@ -621,7 +626,7 @@ public class ApplicationActivity extends ActionBarActivity implements Notificati ...@@ -621,7 +626,7 @@ public class ApplicationActivity extends ActionBarActivity implements Notificati
ApplicationLoader.fragmentsStack.remove(ApplicationLoader.fragmentsStack.size() - 1); ApplicationLoader.fragmentsStack.remove(ApplicationLoader.fragmentsStack.size() - 1);
current.onFragmentDestroy(); current.onFragmentDestroy();
} }
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE); SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
boolean animations = preferences.getBoolean("view_animations", true); boolean animations = preferences.getBoolean("view_animations", true);
if (animations) { if (animations) {
if (bySwipe) { if (bySwipe) {
...@@ -660,7 +665,7 @@ public class ApplicationActivity extends ActionBarActivity implements Notificati ...@@ -660,7 +665,7 @@ public class ApplicationActivity extends ActionBarActivity implements Notificati
BaseFragment prev = ApplicationLoader.fragmentsStack.get(ApplicationLoader.fragmentsStack.size() - 2); BaseFragment prev = ApplicationLoader.fragmentsStack.get(ApplicationLoader.fragmentsStack.size() - 2);
FragmentManager fm = getSupportFragmentManager(); FragmentManager fm = getSupportFragmentManager();
FragmentTransaction fTrans = fm.beginTransaction(); FragmentTransaction fTrans = fm.beginTransaction();
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE); SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
boolean animations = preferences.getBoolean("view_animations", true); boolean animations = preferences.getBoolean("view_animations", true);
if (animations) { if (animations) {
if (bySwipe) { if (bySwipe) {
......
...@@ -8,13 +8,16 @@ ...@@ -8,13 +8,16 @@
package org.telegram.ui; package org.telegram.ui;
import android.app.Activity;
import android.app.Application; import android.app.Application;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.pm.PackageInfo; import android.content.pm.PackageInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Handler;
import android.view.ViewConfiguration; import android.view.ViewConfiguration;
import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.ConnectionResult;
...@@ -22,7 +25,6 @@ import com.google.android.gms.common.GooglePlayServicesUtil; ...@@ -22,7 +25,6 @@ import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.gcm.GoogleCloudMessaging; import com.google.android.gms.gcm.GoogleCloudMessaging;
import org.telegram.PhoneFormat.PhoneFormat; import org.telegram.PhoneFormat.PhoneFormat;
import org.telegram.TL.TLRPC;
import org.telegram.messenger.ConnectionsManager; import org.telegram.messenger.ConnectionsManager;
import org.telegram.messenger.FileLog; import org.telegram.messenger.FileLog;
import org.telegram.messenger.MessagesController; import org.telegram.messenger.MessagesController;
...@@ -34,6 +36,7 @@ import org.telegram.ui.Views.BaseFragment; ...@@ -34,6 +36,7 @@ import org.telegram.ui.Views.BaseFragment;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Locale;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
public class ApplicationLoader extends Application { public class ApplicationLoader extends Application {
...@@ -48,6 +51,7 @@ public class ApplicationLoader extends Application { ...@@ -48,6 +51,7 @@ public class ApplicationLoader extends Application {
public static long lastPauseTime; public static long lastPauseTime;
public static Bitmap cachedWallpaper = null; public static Bitmap cachedWallpaper = null;
public static Context applicationContext; public static Context applicationContext;
private Locale currentLocale;
public static ApplicationLoader Instance = null; public static ApplicationLoader Instance = null;
...@@ -56,42 +60,47 @@ public class ApplicationLoader extends Application { ...@@ -56,42 +60,47 @@ public class ApplicationLoader extends Application {
@Override @Override
public void onCreate() { public void onCreate() {
super.onCreate(); super.onCreate();
currentLocale = Locale.getDefault();
Instance = this; Instance = this;
java.lang.System.setProperty("java.net.preferIPv4Stack", "true"); java.lang.System.setProperty("java.net.preferIPv4Stack", "true");
java.lang.System.setProperty("java.net.preferIPv6Addresses", "false"); java.lang.System.setProperty("java.net.preferIPv6Addresses", "false");
applicationContext = getApplicationContext(); applicationContext = getApplicationContext();
Utilities.getTypeface("fonts/rmedium.ttf"); Utilities.applicationHandler = new Handler(applicationContext.getMainLooper());
UserConfig.loadConfig(); UserConfig.loadConfig();
SharedPreferences preferences = getSharedPreferences("Notifications", MODE_PRIVATE);
if (UserConfig.currentUser != null) { if (UserConfig.currentUser != null) {
int value = preferences.getInt("version", 0); boolean changed = false;
if (value != 15) { SharedPreferences preferences = getSharedPreferences("Notifications", MODE_PRIVATE);
UserConfig.contactsHash = ""; int v = preferences.getInt("v", 0);
MessagesStorage.lastDateValue = 0; if (v != 1) {
MessagesStorage.lastPtsValue = 0; SharedPreferences preferences2 = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
MessagesStorage.lastSeqValue = 0; SharedPreferences.Editor editor = preferences2.edit();
MessagesStorage.lastQtsValue = 0; if (preferences.contains("view_animations")) {
UserConfig.saveConfig(false); editor.putBoolean("view_animations", preferences.getBoolean("view_animations", false));
MessagesStorage.Instance.cleanUp(); }
ArrayList<TLRPC.User> users = new ArrayList<TLRPC.User>(); if (preferences.contains("selectedBackground")) {
users.add(UserConfig.currentUser); editor.putInt("selectedBackground", preferences.getInt("selectedBackground", 1000001));
MessagesStorage.Instance.putUsersAndChats(users, null, true, true); }
if (preferences.contains("selectedColor")) {
SharedPreferences.Editor editor = preferences.edit(); editor.putInt("selectedColor", preferences.getInt("selectedColor", 0));
editor.putInt("version", 15); }
if (preferences.contains("fons_size")) {
editor.putInt("fons_size", preferences.getInt("fons_size", 16));
}
editor.commit();
editor = preferences.edit();
editor.putInt("v", 1);
editor.remove("view_animations");
editor.remove("selectedBackground");
editor.remove("selectedColor");
editor.remove("fons_size");
editor.commit(); editor.commit();
} else {
MessagesStorage init = MessagesStorage.Instance;
} }
MessagesStorage init = MessagesStorage.Instance;
MessagesController.Instance.users.put(UserConfig.clientUserId, UserConfig.currentUser); MessagesController.Instance.users.put(UserConfig.clientUserId, UserConfig.currentUser);
} else {
SharedPreferences.Editor editor = preferences.edit();
editor.putInt("version", 15);
editor.commit();
} }
MessagesController.Instance.checkAppAccount();
try { try {
ViewConfiguration config = ViewConfiguration.get(this); ViewConfiguration config = ViewConfiguration.get(this);
...@@ -101,7 +110,7 @@ public class ApplicationLoader extends Application { ...@@ -101,7 +110,7 @@ public class ApplicationLoader extends Application {
menuKeyField.setBoolean(config, false); menuKeyField.setBoolean(config, false);
} }
} catch (Exception e) { } catch (Exception e) {
FileLog.e("tmessages", e); e.printStackTrace();
} }
if (checkPlayServices()) { if (checkPlayServices()) {
...@@ -123,6 +132,20 @@ public class ApplicationLoader extends Application { ...@@ -123,6 +132,20 @@ public class ApplicationLoader extends Application {
FileLog.e("tmessages", "start application with time " + lastPauseTime); FileLog.e("tmessages", "start application with time " + lastPauseTime);
} }
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
Locale newLocale = newConfig.locale;
if (newLocale != null) {
String d1 = newLocale.getDisplayName();
String d2 = currentLocale.getDisplayName();
if (d1 != null && d2 != null && !d1.equals(d2)) {
Utilities.recreateFormatters();
}
currentLocale = newLocale;
}
}
public static void resetLastPauseTime() { public static void resetLastPauseTime() {
lastPauseTime = 0; lastPauseTime = 0;
ConnectionsManager.Instance.applicationMovedToForeground(); ConnectionsManager.Instance.applicationMovedToForeground();
......
/*
* This is the source code of Telegram for Android v. 1.3.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.
*/
package org.telegram.ui.Cells;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.View;
public class BaseCell extends View {
public BaseCell(Context context) {
super(context);
}
public BaseCell(Context context, AttributeSet attrs) {
super(context, attrs);
}
public BaseCell(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
protected void setDrawableBounds(Drawable drawable, int x, int y) {
setDrawableBounds(drawable, x, y, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
}
protected void setDrawableBounds(Drawable drawable, int x, int y, int w, int h) {
drawable.setBounds(x, y, x + w, y + h);
}
}
...@@ -44,6 +44,7 @@ import org.telegram.messenger.NotificationCenter; ...@@ -44,6 +44,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.ui.Cells.ChatOrUserCell;
import org.telegram.ui.Views.AvatarUpdater; import org.telegram.ui.Views.AvatarUpdater;
import org.telegram.ui.Views.BackupImageView; import org.telegram.ui.Views.BackupImageView;
import org.telegram.ui.Views.BaseFragment; import org.telegram.ui.Views.BaseFragment;
...@@ -239,8 +240,8 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen ...@@ -239,8 +240,8 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen
} }
@Override @Override
public void didSelectContact(int user_id) { public void didSelectContact(TLRPC.User user) {
MessagesController.Instance.addUserToChat(chat_id, user_id, info); MessagesController.Instance.addUserToChat(chat_id, user, info);
} }
@Override @Override
...@@ -277,9 +278,12 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen ...@@ -277,9 +278,12 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen
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];
if ((mask & MessagesController.UPDATE_MASK_CHAT_AVATAR) != 0 || (mask & MessagesController.UPDATE_MASK_CHAT_NAME) != 0 || (mask & MessagesController.UPDATE_MASK_CHAT_MEMBERS) != 0) {
updateOnlineCount(); updateOnlineCount();
if (listView != null) { }
listView.invalidateViews(); if ((mask & MessagesController.UPDATE_MASK_AVATAR) != 0 || (mask & MessagesController.UPDATE_MASK_NAME) != 0 || (mask & MessagesController.UPDATE_MASK_STATUS) != 0) {
updateVisibleRows(mask);
} }
} else if (id == MessagesController.chatInfoDidLoaded) { } else if (id == MessagesController.chatInfoDidLoaded) {
int chatId = (Integer)args[0]; int chatId = (Integer)args[0];
...@@ -355,6 +359,19 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen ...@@ -355,6 +359,19 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen
return true; return true;
} }
private void updateVisibleRows(int mask) {
if (listView == null) {
return;
}
int count = listView.getChildCount();
for (int a = 0; a < count; a++) {
View child = listView.getChildAt(a);
if (child instanceof ChatOrUserCell) {
((ChatOrUserCell) child).update(mask);
}
}
}
private void updateOnlineCount() { private void updateOnlineCount() {
if (info == null) { if (info == null) {
return; return;
...@@ -451,11 +468,11 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen ...@@ -451,11 +468,11 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen
private void kickUser(TLRPC.TL_chatParticipant user) { private void kickUser(TLRPC.TL_chatParticipant user) {
if (user != null) { if (user != null) {
MessagesController.Instance.deleteUserFromChat(chat_id, user.user_id, info); MessagesController.Instance.deleteUserFromChat(chat_id, MessagesController.Instance.users.get(user.user_id), info);
} else { } else {
NotificationCenter.Instance.removeObserver(this, MessagesController.closeChats); NotificationCenter.Instance.removeObserver(this, MessagesController.closeChats);
NotificationCenter.Instance.postNotificationName(MessagesController.closeChats); NotificationCenter.Instance.postNotificationName(MessagesController.closeChats);
MessagesController.Instance.deleteUserFromChat(chat_id, UserConfig.clientUserId, info); MessagesController.Instance.deleteUserFromChat(chat_id, MessagesController.Instance.users.get(UserConfig.clientUserId), info);
MessagesController.Instance.deleteDialog(-chat_id, 0, false); MessagesController.Instance.deleteDialog(-chat_id, 0, false);
finishFragment(); finishFragment();
} }
...@@ -674,60 +691,19 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen ...@@ -674,60 +691,19 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen
TLRPC.User user = MessagesController.Instance.users.get(part.user_id); TLRPC.User user = MessagesController.Instance.users.get(part.user_id);
if (view == null) { if (view == null) {
LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); view = new ChatOrUserCell(mContext);
view = li.inflate(R.layout.messages_search_user_layout, viewGroup, false); ((ChatOrUserCell)view).useBoldFont = true;
} ((ChatOrUserCell)view).usePadding = false;
ContactsActivity.ContactListRowHolder holder = (ContactsActivity.ContactListRowHolder)view.getTag(); ((ChatOrUserCell)view).useSeparator = true;
if (holder == null) {
holder = new ContactsActivity.ContactListRowHolder(view);
view.setTag(holder);
} }
View divider = view.findViewById(R.id.settings_row_divider); ((ChatOrUserCell)view).setData(user, null, null, null, null);
divider.setVisibility(View.VISIBLE);
if (user.first_name.length() != 0 && user.last_name.length() != 0) {
holder.nameTextView.setText(Html.fromHtml(user.first_name + " <b>" + user.last_name + "</b>"));
} else if (user.first_name.length() != 0) {
holder.nameTextView.setText(Html.fromHtml("<b>" + user.first_name + "</b>"));
} else {
holder.nameTextView.setText(Html.fromHtml("<b>" + user.last_name + "</b>"));
}
// if (info.admin_id != UserConfig.clientUserId && part.inviter_id != UserConfig.clientUserId && part.user_id != UserConfig.clientUserId) { // if (info.admin_id != UserConfig.clientUserId && part.inviter_id != UserConfig.clientUserId && part.user_id != UserConfig.clientUserId) {
// //
// } else { // } else {
// //
// } // }
TLRPC.FileLocation photo = null;
if (user.photo != null) {
photo = user.photo.photo_small;
}
int placeHolderId = Utilities.getUserAvatarForId(user.id);
holder.avatarImage.setImage(photo, "50_50", placeHolderId);
if (user.status == null) {
holder.messageTextView.setTextColor(0xff808080);
holder.messageTextView.setText(getStringEntry(R.string.Offline));
} else {
int currentTime = ConnectionsManager.Instance.getCurrentTime();
if ((user.status.expires > currentTime || user.status.was_online > currentTime || user.id == UserConfig.clientUserId) && user.status.expires != 0) {
holder.messageTextView.setTextColor(0xff357aa8);
holder.messageTextView.setText(getStringEntry(R.string.Online));
} else {
if (user.status.was_online <= 10000 && user.status.expires <= 10000) {
holder.messageTextView.setText(getStringEntry(R.string.Invisible));
} else {
int value = user.status.was_online;
if (value == 0) {
value = user.status.expires;
}
holder.messageTextView.setText(String.format("%s %s", getStringEntry(R.string.LastSeen), Utilities.formatDateOnline(value)));
}
holder.messageTextView.setTextColor(0xff808080);
}
}
} else if (type == 5) { } else if (type == 5) {
if (view == null) { if (view == null) {
LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
......
...@@ -131,7 +131,7 @@ public class ChatProfileChangeNameActivity extends BaseFragment { ...@@ -131,7 +131,7 @@ public class ChatProfileChangeNameActivity extends BaseFragment {
} }
((ApplicationActivity)parentActivity).updateActionBar(); ((ApplicationActivity)parentActivity).updateActionBar();
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE); SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
boolean animations = preferences.getBoolean("view_animations", true); boolean animations = preferences.getBoolean("view_animations", true);
if (!animations) { if (!animations) {
firstNameField.requestFocus(); firstNameField.requestFocus();
......
...@@ -26,6 +26,7 @@ import android.widget.TextView; ...@@ -26,6 +26,7 @@ import android.widget.TextView;
import org.telegram.PhoneFormat.PhoneFormat; import org.telegram.PhoneFormat.PhoneFormat;
import org.telegram.TL.TLRPC; import org.telegram.TL.TLRPC;
import org.telegram.messenger.ConnectionsManager; import org.telegram.messenger.ConnectionsManager;
import org.telegram.messenger.ContactsController;
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;
...@@ -49,7 +50,8 @@ public class ContactAddActivity extends BaseFragment implements NotificationCent ...@@ -49,7 +50,8 @@ public class ContactAddActivity extends BaseFragment implements NotificationCent
NotificationCenter.Instance.addObserver(this, MessagesController.updateInterfaces); NotificationCenter.Instance.addObserver(this, MessagesController.updateInterfaces);
user_id = getArguments().getInt("user_id", 0); user_id = getArguments().getInt("user_id", 0);
phone = getArguments().getString("phone"); phone = getArguments().getString("phone");
return true; TLRPC.User user = MessagesController.Instance.users.get(user_id);
return user != null;
} }
@Override @Override
...@@ -64,9 +66,11 @@ public class ContactAddActivity extends BaseFragment implements NotificationCent ...@@ -64,9 +66,11 @@ public class ContactAddActivity extends BaseFragment implements NotificationCent
fragmentView = inflater.inflate(R.layout.contact_add_layout, container, false); fragmentView = inflater.inflate(R.layout.contact_add_layout, container, false);
TLRPC.User user = MessagesController.Instance.users.get(user_id); TLRPC.User user = MessagesController.Instance.users.get(user_id);
if (user.phone == null) {
if (phone != null) { if (phone != null) {
user.phone = PhoneFormat.stripExceptNumbers(phone); user.phone = PhoneFormat.stripExceptNumbers(phone);
} }
}
onlineText = (TextView)fragmentView.findViewById(R.id.settings_online); onlineText = (TextView)fragmentView.findViewById(R.id.settings_online);
avatarImage = (BackupImageView)fragmentView.findViewById(R.id.settings_avatar_image); avatarImage = (BackupImageView)fragmentView.findViewById(R.id.settings_avatar_image);
...@@ -137,7 +141,7 @@ public class ContactAddActivity extends BaseFragment implements NotificationCent ...@@ -137,7 +141,7 @@ public class ContactAddActivity extends BaseFragment implements NotificationCent
if (value == 0) { if (value == 0) {
value = user.status.expires; value = user.status.expires;
} }
onlineText.setText(String.format("%s %s", getStringEntry(R.string.LastSeen), Utilities.formatDateOnline(value))); onlineText.setText(Utilities.formatDateOnline(value));
} }
} }
} }
...@@ -151,9 +155,12 @@ public class ContactAddActivity extends BaseFragment implements NotificationCent ...@@ -151,9 +155,12 @@ public class ContactAddActivity extends BaseFragment implements NotificationCent
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];
if ((mask & MessagesController.UPDATE_MASK_AVATAR) != 0 || (mask & MessagesController.UPDATE_MASK_STATUS) != 0) {
updateAvatarLayout(); updateAvatarLayout();
} }
} }
}
@Override @Override
public boolean canApplyUpdateStatus() { public boolean canApplyUpdateStatus() {
...@@ -197,8 +204,9 @@ public class ContactAddActivity extends BaseFragment implements NotificationCent ...@@ -197,8 +204,9 @@ public class ContactAddActivity extends BaseFragment implements NotificationCent
TLRPC.User user = MessagesController.Instance.users.get(user_id); TLRPC.User user = MessagesController.Instance.users.get(user_id);
user.first_name = firstNameField.getText().toString(); user.first_name = firstNameField.getText().toString();
user.last_name = lastNameField.getText().toString(); user.last_name = lastNameField.getText().toString();
MessagesController.Instance.addContact(user); ContactsController.Instance.addContact(user);
finishFragment(); finishFragment();
NotificationCenter.Instance.postNotificationName(MessagesController.updateInterfaces, MessagesController.UPDATE_MASK_NAME);
} }
} }
}); });
...@@ -212,7 +220,7 @@ public class ContactAddActivity extends BaseFragment implements NotificationCent ...@@ -212,7 +220,7 @@ public class ContactAddActivity extends BaseFragment implements NotificationCent
} }
((ApplicationActivity)parentActivity).updateActionBar(); ((ApplicationActivity)parentActivity).updateActionBar();
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE); SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
boolean animations = preferences.getBoolean("view_animations", true); boolean animations = preferences.getBoolean("view_animations", true);
if (!animations) { if (!animations) {
firstNameField.requestFocus(); firstNameField.requestFocus();
......
...@@ -329,7 +329,10 @@ public class LocationActivity extends BaseFragment implements NotificationCenter ...@@ -329,7 +329,10 @@ public class LocationActivity extends BaseFragment implements NotificationCenter
@Override @Override
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];
if ((mask & MessagesController.UPDATE_MASK_AVATAR) != 0 || (mask & MessagesController.UPDATE_MASK_NAME) != 0) {
updateUserData(); updateUserData();
}
} else if (id == MessagesController.closeChats) { } else if (id == MessagesController.closeChats) {
removeSelfFromStack(); removeSelfFromStack();
} }
......
...@@ -25,7 +25,6 @@ import android.view.animation.AccelerateDecelerateInterpolator; ...@@ -25,7 +25,6 @@ import android.view.animation.AccelerateDecelerateInterpolator;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import org.telegram.messenger.ConnectionsManager;
import org.telegram.messenger.R; import org.telegram.messenger.R;
import org.telegram.messenger.Utilities; import org.telegram.messenger.Utilities;
import org.telegram.ui.Views.SlideView; import org.telegram.ui.Views.SlideView;
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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