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 {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
classpath 'com.android.tools.build:gradle:0.8.+'
}
}
apply plugin: 'android'
......@@ -31,7 +31,7 @@ tasks.withType(JavaCompile) {
}
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 'com.android.support:support-v4:19.0.+'
compile 'com.android.support:appcompat-v7:19.0.+'
......@@ -40,7 +40,7 @@ dependencies {
android {
compileSdkVersion 19
buildToolsVersion '19.0.0'
buildToolsVersion '19.0.1'
signingConfigs {
debug {
......
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.telegram.messenger"
android:versionCode="131"
android:versionName="1.3.7">
android:versionCode="148"
android:versionName="1.3.19">
<supports-screens android:anyDensity="true"
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:resizeable="true"
android:xlargeScreens="true"/>
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:resizeable="true"
android:xlargeScreens="true"/>
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="19" />
<uses-feature android:glEsVersion="0x00020000" android:required="true"/>
<uses-feature android:name="android.hardware.telephony" android:required="false" />
<uses-feature android:name="android.hardware.location.gps" android:required="false" />
......@@ -23,7 +23,7 @@
<uses-feature android:name="android.hardware.wifi" android:required="false" />
<uses-feature android:name="android.hardware.LOCATION" android:required="false" />
<uses-feature android:name="android.hardware.screen.PORTRAIT" android:required="false" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
......@@ -49,10 +49,10 @@
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<permission android:name="org.telegram.messenger.permission.MAPS_RECEIVE" android:protectionLevel="signature"/>
<permission android:name="org.telegram.messenger.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
......@@ -61,13 +61,14 @@
android:name="org.telegram.ui.ApplicationLoader"
android:hardwareAccelerated="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.gms.version" android:value="@integer/google_play_services_version" />
<activity
android:name="org.telegram.ui.LaunchActivity"
android:windowSoftInputMode="adjustResize"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
android:name="org.telegram.ui.LaunchActivity"
android:windowSoftInputMode="adjustResize"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
......@@ -124,48 +125,47 @@
android:theme="@style/Theme.TMessages.Gallery"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
</activity>
<activity android:name="net.hockeyapp.android.UpdateActivity" />
<receiver android:name="org.telegram.messenger.SmsListener">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
<receiver
android:name="org.telegram.messenger.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
android:name="org.telegram.messenger.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="org.telegram.messenger" />
</intent-filter>
</receiver>
<service android:name="org.telegram.messenger.AuthenticatorService"
android:exported="true">
<intent-filter>
<action android:name="android.accounts.AccountAuthenticator"/>
</intent-filter>
<meta-data android:name="android.accounts.AccountAuthenticator"
android:resource="@xml/auth"/>
android:resource="@xml/auth"/>
</service>
<service android:name="org.telegram.messenger.ContactsSyncAdapterService"
android:exported="true">
<intent-filter>
<action android:name="android.content.SyncAdapter" />
</intent-filter>
<meta-data android:name="android.content.SyncAdapter"
android:resource="@xml/sync_contacts" />
android:resource="@xml/sync_contacts" />
<meta-data android:name="android.provider.CONTACTS_STRUCTURE"
android:resource="@xml/contacts" />
android:resource="@xml/contacts" />
</service>
<uses-library android:name="com.google.android.maps" android:required="false"/>
</application>
</manifest>
</manifest>
......@@ -32,7 +32,7 @@ public class TLObject {
}
public int layer () {
return 8;
return 11;
}
public void parseVector(TLRPC.Vector vector, SerializedData data) {
......
......@@ -42,10 +42,14 @@ public class DispatchQueue extends Thread {
}
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) {
try {
synchronized (handlerSyncObject) {
......@@ -58,7 +62,11 @@ public class DispatchQueue extends Thread {
if (handler != null) {
if (delay <= 0) {
handler.post(runnable);
if (inFront) {
handler.postAtFrontOfQueue(runnable);
} else {
handler.post(runnable);
}
} else {
handler.postDelayed(runnable, delay);
}
......
......@@ -53,7 +53,7 @@ public class ExportAuthorizationAction extends Action {
public void run() {
beginExport();
}
}, retryCount * 1500);
}, retryCount * 1500, false);
}
}
}
......@@ -84,7 +84,7 @@ public class ExportAuthorizationAction extends Action {
public void run() {
beginExport();
}
}, retryCount * 1500);
}, retryCount * 1500, false);
}
}
}
......
......@@ -420,7 +420,12 @@ public class FileLoadOperation {
if (renamed) {
image = BitmapFactory.decodeStream(new FileInputStream(cacheFileFinal), null, opts);
} else {
image = BitmapFactory.decodeStream(new FileInputStream(cacheFileTemp), null, opts);
try {
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) {
float bitmapW = image.getWidth();
......@@ -440,10 +445,11 @@ public class FileLoadOperation {
if (FileLoader.Instance.runtimeHack != null) {
FileLoader.Instance.runtimeHack.trackFree(image.getRowBytes() * image.getHeight());
}
delegate.didFinishLoadingFile(FileLoadOperation.this);
} catch (Exception e) {
FileLog.e("tmessages", e);
delegate.didFailedLoadingFile(FileLoadOperation.this);
}
delegate.didFinishLoadingFile(FileLoadOperation.this);
}
});
} else {
......
......@@ -118,6 +118,8 @@ public class FileLog {
}
}
});
} else {
e.printStackTrace();
}
}
......
......@@ -109,7 +109,16 @@ public class FileUploadOperation {
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);
readBuffer = new byte[uploadChunkSize];
}
......
......@@ -14,6 +14,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.PowerManager;
import com.google.android.gms.gcm.GoogleCloudMessaging;
......@@ -27,6 +28,10 @@ public class GcmBroadcastReceiver extends BroadcastReceiver {
setResultCode(Activity.RESULT_OK);
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);
boolean globalEnabled = preferences.getBoolean("EnableAll", true);
if (!globalEnabled) {
......@@ -38,12 +43,13 @@ public class GcmBroadcastReceiver extends BroadcastReceiver {
public void run() {
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(context);
String messageType = gcm.getMessageType(intent);
sendNotification(context, intent.getExtras());
ConnectionsManager.Instance.resumeNetworkMaybe();
wl.release();
}
});
thread.setPriority(Thread.MAX_PRIORITY);
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");
if (intent.getStringExtra("error") != null) {
FileLog.e("tmessages", "Registration failed, should try again later.");
......@@ -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,42 +12,41 @@ import java.util.ArrayList;
import java.util.HashMap;
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, Object> memCache = new HashMap<Integer, Object>();
final private HashMap<String, Object> memCacheString = new HashMap<String, Object>();
private boolean broadcasting = false;
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> addAfterBroadcast = new HashMap<Integer, Object>();
private boolean broadcasting = false;
public interface NotificationCenterDelegate {
public abstract void didReceivedNotification(int id, Object... args);
}
public static NotificationCenter Instance = new NotificationCenter();
public void addToMemCache(int id, Object object) {
memCache.put(id, object);
addToMemCache(String.valueOf(id), object);
}
public void addToMemCache(String id, Object object) {
memCacheString.put(id, object);
memCache.put(id, object);
}
public Object getFromMemCache(int id) {
Object obj = memCache.get(id);
if (obj != null) {
memCache.remove(id);
}
return obj;
return getFromMemCache(String.valueOf(id), null);
}
public Object getFromMemCache(String id, Object defaultValue) {
Object obj = memCacheString.get(id);
Object obj = memCache.get(id);
if (obj != null) {
memCacheString.remove(id);
} else {
return defaultValue;
memCache.remove(id);
return obj;
}
return obj;
return defaultValue;
}
public void postNotificationName(int id, Object... args) {
......@@ -66,15 +65,24 @@ public class NotificationCenter {
}
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) {
synchronized (observers) {
if (broadcasting) {
addAfterBroadcast.put(id, observer);
return;
}
ArrayList<Object> objects = observers.get(id);
if (objects == null) {
objects = new ArrayList<Object>();
observers.put(id, objects);
observers.put(id, (objects = new ArrayList<Object>()));
}
if (objects.contains(observer)) {
return;
......@@ -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) {
synchronized (observers) {
if (broadcasting) {
......
......@@ -29,6 +29,7 @@ public class RPCRequest {
public static int RPCRequestClassUploadMedia = 4;
public static int RPCRequestClassEnableUnauthorized = 8;
public static int RPCRequestClassFailOnServerErrors = 16;
public static int RPCRequestClassCanCompress = 32;
static int RPCRequestClassTransportMask = (RPCRequestClassGeneric | RPCRequestClassDownloadMedia | RPCRequestClassUploadMedia);
......@@ -37,6 +38,7 @@ public class RPCRequest {
int serverFailureCount;
int flags;
public int retryCount = 0;
TLObject rawRequest;
TLObject rpcRequest;
......
......@@ -15,8 +15,6 @@ import android.content.SharedPreferences;
import android.os.Bundle;
import android.telephony.SmsMessage;
import org.telegram.messenger.NotificationCenter;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
......@@ -27,6 +25,9 @@ public class SmsListener extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")) {
if (!Utilities.isWaitingForSms()) {
return;
}
Bundle bundle = intent.getExtras();
SmsMessage[] msgs;
if (bundle != null) {
......
......@@ -50,6 +50,7 @@ public class TcpConnection extends PyroClientAdapter {
private boolean hasSomeDataSinceLastConnect = false;
private int willRetryConnectCount = 5;
private boolean isNextPort = false;
private final Integer timerSync = 1;
public int transportRequestClass;
......@@ -86,9 +87,11 @@ public class TcpConnection extends PyroClientAdapter {
connectionState = TcpConnectionState.TcpConnectionStageConnecting;
try {
try {
if (reconnectTimer != null) {
reconnectTimer.cancel();
reconnectTimer = null;
synchronized (timerSync) {
if (reconnectTimer != null) {
reconnectTimer.cancel();
reconnectTimer = null;
}
}
} catch (Exception e2) {
FileLog.e("tmessages", e2);
......@@ -115,19 +118,22 @@ public class TcpConnection extends PyroClientAdapter {
selector.wakeup();
} catch (Exception e) {
try {
if (reconnectTimer != null) {
reconnectTimer.cancel();
reconnectTimer = null;
synchronized (timerSync) {
if (reconnectTimer != null) {
reconnectTimer.cancel();
reconnectTimer = null;
}
}
} catch (Exception e2) {
FileLog.e("tmessages", e2);
}
connectionState = TcpConnectionState.TcpConnectionStageReconnecting;
if (delegate != null) {
final TcpConnectionDelegate finalDelegate = delegate;
Utilities.stageQueue.postRunnable(new Runnable() {
@Override
public void run() {
delegate.tcpConnectionClosed(TcpConnection.this);
finalDelegate.tcpConnectionClosed(TcpConnection.this);
}
});
}
......@@ -160,9 +166,11 @@ public class TcpConnection extends PyroClientAdapter {
@Override
public void run() {
try {
if (reconnectTimer != null) {
reconnectTimer.cancel();
reconnectTimer = null;
synchronized (timerSync) {
if (reconnectTimer != null) {
reconnectTimer.cancel();
reconnectTimer = null;
}
}
} catch (Exception e2) {
FileLog.e("tmessages", e2);
......@@ -181,9 +189,11 @@ public class TcpConnection extends PyroClientAdapter {
}
private void suspendConnectionInternal() {
if (reconnectTimer != null) {
reconnectTimer.cancel();
reconnectTimer = null;
synchronized (timerSync) {
if (reconnectTimer != null) {
reconnectTimer.cancel();
reconnectTimer = null;
}
}
if (connectionState == TcpConnectionState.TcpConnectionStageIdle || connectionState == TcpConnectionState.TcpConnectionStageSuspended) {
return;
......@@ -196,10 +206,11 @@ public class TcpConnection extends PyroClientAdapter {
client = null;
}
if (delegate != null) {
final TcpConnectionDelegate finalDelegate = delegate;
Utilities.stageQueue.postRunnable(new Runnable() {
@Override
public void run() {
delegate.tcpConnectionClosed(TcpConnection.this);
finalDelegate.tcpConnectionClosed(TcpConnection.this);
}
});
}
......@@ -314,10 +325,11 @@ public class TcpConnection extends PyroClientAdapter {
buffer.order(ByteOrder.BIG_ENDIAN);
final int ackId = buffer.getInt() & (~(1 << 31));
if (delegate != null) {
final TcpConnectionDelegate finalDelegate = delegate;
Utilities.stageQueue.postRunnable(new Runnable() {
@Override
public void run() {
delegate.tcpConnectionQuiackAckReceived(TcpConnection.this, ackId);
finalDelegate.tcpConnectionQuiackAckReceived(TcpConnection.this, ackId);
}
});
}
......@@ -360,12 +372,13 @@ public class TcpConnection extends PyroClientAdapter {
}
if (lastMessageId != -1 && lastMessageId != 0) {
if (delegate != null) {
final TcpConnectionDelegate finalDelegate = delegate;
final int arg2 = buffer.remaining();
final int arg3 = currentPacketLength;
Utilities.stageQueue.postRunnable(new Runnable() {
@Override
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 {
buffer.get(packetData);
if (delegate != null) {
final TcpConnectionDelegate finalDelegate = delegate;
Utilities.stageQueue.postRunnable(new Runnable() {
@Override
public void run() {
delegate.tcpConnectionReceivedData(TcpConnection.this, packetData);
finalDelegate.tcpConnectionReceivedData(TcpConnection.this, packetData);
}
});
}
......@@ -394,9 +408,11 @@ public class TcpConnection extends PyroClientAdapter {
}
public void handleDisconnect(PyroClient client, Exception e) {
if (reconnectTimer != null) {
reconnectTimer.cancel();
reconnectTimer = null;
synchronized (timerSync) {
if (reconnectTimer != null) {
reconnectTimer.cancel();
reconnectTimer = null;
}
}
if (e != null) {
FileLog.d("tmessages", "Disconnected " + TcpConnection.this + " with error " + e);
......@@ -410,12 +426,11 @@ public class TcpConnection extends PyroClientAdapter {
connectionState = TcpConnectionState.TcpConnectionStageIdle;
}
if (delegate != null) {
final TcpConnectionDelegate finalDelegate = delegate;
Utilities.stageQueue.postRunnable(new Runnable() {
@Override
public void run() {
if (delegate != null) {
delegate.tcpConnectionClosed(TcpConnection.this);
}
finalDelegate.tcpConnectionClosed(TcpConnection.this);
}
});
}
......@@ -447,9 +462,11 @@ public class TcpConnection extends PyroClientAdapter {
@Override
public void run() {
try {
if (reconnectTimer != null) {
reconnectTimer.cancel();
reconnectTimer = null;
synchronized (timerSync) {
if (reconnectTimer != null) {
reconnectTimer.cancel();
reconnectTimer = null;
}
}
} catch (Exception e2) {
FileLog.e("tmessages", e2);
......@@ -471,10 +488,11 @@ public class TcpConnection extends PyroClientAdapter {
channelToken = generateChannelToken();
FileLog.d("tmessages", String.format(TcpConnection.this + " Connected (%s:%d)", hostAddress, hostPort));
if (delegate != null) {
final TcpConnectionDelegate finalDelegate = delegate;
Utilities.stageQueue.postRunnable(new Runnable() {
@Override
public void run() {
delegate.tcpConnectionConnected(TcpConnection.this);
finalDelegate.tcpConnectionConnected(TcpConnection.this);
}
});
}
......
......@@ -27,7 +27,6 @@ public class UserConfig {
public static int lastSendMessageId = -210000;
public static int lastLocalId = -210000;
public static String contactsHash = "";
public static String importHash = "";
private final static Integer sync = 1;
public static boolean saveIncomingPhotos = false;
......@@ -55,7 +54,6 @@ public class UserConfig {
editor.putInt("lastSendMessageId", lastSendMessageId);
editor.putInt("lastLocalId", lastLocalId);
editor.putString("contactsHash", contactsHash);
editor.putString("importHash", importHash);
editor.putBoolean("saveIncomingPhotos", saveIncomingPhotos);
if (withFile) {
SerializedData data = new SerializedData();
......@@ -71,7 +69,6 @@ public class UserConfig {
editor.putInt("lastSendMessageId", lastSendMessageId);
editor.putInt("lastLocalId", lastLocalId);
editor.putString("contactsHash", contactsHash);
editor.putString("importHash", importHash);
editor.putBoolean("saveIncomingPhotos", saveIncomingPhotos);
editor.remove("user");
}
......@@ -105,7 +102,7 @@ public class UserConfig {
lastSendMessageId = data.readInt32();
lastLocalId = data.readInt32();
contactsHash = data.readString();
importHash = data.readString();
data.readString();
saveIncomingPhotos = data.readBool();
if (currentUser.status != null) {
if (currentUser.status.expires != 0) {
......@@ -139,7 +136,6 @@ public class UserConfig {
lastSendMessageId = preferences.getInt("lastSendMessageId", -210000);
lastLocalId = preferences.getInt("lastLocalId", -210000);
contactsHash = preferences.getString("contactsHash", "");
importHash = preferences.getString("importHash", "");
saveIncomingPhotos = preferences.getBoolean("saveIncomingPhotos", false);
}
if (lastLocalId > -210000) {
......@@ -164,7 +160,6 @@ public class UserConfig {
lastSendMessageId = preferences.getInt("lastSendMessageId", -210000);
lastLocalId = preferences.getInt("lastLocalId", -210000);
contactsHash = preferences.getString("contactsHash", "");
importHash = preferences.getString("importHash", "");
saveIncomingPhotos = preferences.getBoolean("saveIncomingPhotos", false);
String user = preferences.getString("user", null);
if (user != null) {
......@@ -191,7 +186,6 @@ public class UserConfig {
registeredForPush = false;
contactsHash = "";
lastLocalId = -210000;
importHash = "";
lastSendMessageId = -210000;
saveIncomingPhotos = false;
saveConfig(true);
......
......@@ -30,7 +30,7 @@ public class PhotoObject {
opts.outWidth = photo.w;
opts.outHeight = photo.h;
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());
}
}
......@@ -46,7 +46,7 @@ public class PhotoObject {
}
int diffW = Math.abs(obj.photoOwner.w - width);
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;
closestWidth = diffW;
closestHeight = diffH;
......
......@@ -25,6 +25,7 @@ import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.TextView;
import org.telegram.messenger.ConnectionsManager;
......@@ -196,7 +197,7 @@ public class ApplicationActivity extends ActionBarActivity implements Notificati
method.invoke(field.get(getSupportActionBar()), false);
}
} catch (Exception e) {
FileLog.e("tmessages", e);
e.printStackTrace();
}
}
......@@ -333,6 +334,10 @@ public class ApplicationActivity extends ActionBarActivity implements Notificati
if (notificationView != null) {
notificationView.hide(false);
}
View focusView = getCurrentFocus();
if (focusView instanceof EditText) {
focusView.clearFocus();
}
}
@Override
......@@ -581,13 +586,13 @@ public class ApplicationActivity extends ActionBarActivity implements Notificati
try {
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();
statusText.measure(View.MeasureSpec.makeMeasureSpec(800, View.MeasureSpec.AT_MOST), 100);
statusParams.width = (int)(statusText.getMeasuredWidth() + Utilities.dp(54));
statusText.measure(View.MeasureSpec.makeMeasureSpec(800, View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(100, View.MeasureSpec.AT_MOST));
statusParams.width = (statusText.getMeasuredWidth() + Utilities.dp(54));
statusView.setLayoutParams(statusParams);
} else if (statusView.getLayoutParams() instanceof android.app.ActionBar.LayoutParams) {
android.app.ActionBar.LayoutParams statusParams = (android.app.ActionBar.LayoutParams)statusView.getLayoutParams();
statusText.measure(View.MeasureSpec.makeMeasureSpec(800, View.MeasureSpec.AT_MOST), 100);
statusParams.width = (int)(statusText.getMeasuredWidth() + Utilities.dp(54));
statusText.measure(View.MeasureSpec.makeMeasureSpec(800, View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(100, View.MeasureSpec.AT_MOST));
statusParams.width = (statusText.getMeasuredWidth() + Utilities.dp(54));
statusView.setLayoutParams(statusParams);
}
} catch (Exception e) {
......@@ -621,7 +626,7 @@ public class ApplicationActivity extends ActionBarActivity implements Notificati
ApplicationLoader.fragmentsStack.remove(ApplicationLoader.fragmentsStack.size() - 1);
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);
if (animations) {
if (bySwipe) {
......@@ -660,7 +665,7 @@ public class ApplicationActivity extends ActionBarActivity implements Notificati
BaseFragment prev = ApplicationLoader.fragmentsStack.get(ApplicationLoader.fragmentsStack.size() - 2);
FragmentManager fm = getSupportFragmentManager();
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);
if (animations) {
if (bySwipe) {
......
......@@ -8,13 +8,16 @@
package org.telegram.ui;
import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.os.AsyncTask;
import android.os.Handler;
import android.view.ViewConfiguration;
import com.google.android.gms.common.ConnectionResult;
......@@ -22,7 +25,6 @@ import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.gcm.GoogleCloudMessaging;
import org.telegram.PhoneFormat.PhoneFormat;
import org.telegram.TL.TLRPC;
import org.telegram.messenger.ConnectionsManager;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.MessagesController;
......@@ -34,6 +36,7 @@ import org.telegram.ui.Views.BaseFragment;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Locale;
import java.util.concurrent.atomic.AtomicInteger;
public class ApplicationLoader extends Application {
......@@ -48,6 +51,7 @@ public class ApplicationLoader extends Application {
public static long lastPauseTime;
public static Bitmap cachedWallpaper = null;
public static Context applicationContext;
private Locale currentLocale;
public static ApplicationLoader Instance = null;
......@@ -56,42 +60,47 @@ public class ApplicationLoader extends Application {
@Override
public void onCreate() {
super.onCreate();
currentLocale = Locale.getDefault();
Instance = this;
java.lang.System.setProperty("java.net.preferIPv4Stack", "true");
java.lang.System.setProperty("java.net.preferIPv6Addresses", "false");
applicationContext = getApplicationContext();
Utilities.getTypeface("fonts/rmedium.ttf");
Utilities.applicationHandler = new Handler(applicationContext.getMainLooper());
UserConfig.loadConfig();
SharedPreferences preferences = getSharedPreferences("Notifications", MODE_PRIVATE);
if (UserConfig.currentUser != null) {
int value = preferences.getInt("version", 0);
if (value != 15) {
UserConfig.contactsHash = "";
MessagesStorage.lastDateValue = 0;
MessagesStorage.lastPtsValue = 0;
MessagesStorage.lastSeqValue = 0;
MessagesStorage.lastQtsValue = 0;
UserConfig.saveConfig(false);
MessagesStorage.Instance.cleanUp();
ArrayList<TLRPC.User> users = new ArrayList<TLRPC.User>();
users.add(UserConfig.currentUser);
MessagesStorage.Instance.putUsersAndChats(users, null, true, true);
SharedPreferences.Editor editor = preferences.edit();
editor.putInt("version", 15);
boolean changed = false;
SharedPreferences preferences = getSharedPreferences("Notifications", MODE_PRIVATE);
int v = preferences.getInt("v", 0);
if (v != 1) {
SharedPreferences preferences2 = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences2.edit();
if (preferences.contains("view_animations")) {
editor.putBoolean("view_animations", preferences.getBoolean("view_animations", false));
}
if (preferences.contains("selectedBackground")) {
editor.putInt("selectedBackground", preferences.getInt("selectedBackground", 1000001));
}
if (preferences.contains("selectedColor")) {
editor.putInt("selectedColor", preferences.getInt("selectedColor", 0));
}
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();
} else {
MessagesStorage init = MessagesStorage.Instance;
}
MessagesStorage init = MessagesStorage.Instance;
MessagesController.Instance.users.put(UserConfig.clientUserId, UserConfig.currentUser);
} else {
SharedPreferences.Editor editor = preferences.edit();
editor.putInt("version", 15);
editor.commit();
}
MessagesController.Instance.checkAppAccount();
try {
ViewConfiguration config = ViewConfiguration.get(this);
......@@ -101,7 +110,7 @@ public class ApplicationLoader extends Application {
menuKeyField.setBoolean(config, false);
}
} catch (Exception e) {
FileLog.e("tmessages", e);
e.printStackTrace();
}
if (checkPlayServices()) {
......@@ -123,6 +132,20 @@ public class ApplicationLoader extends Application {
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() {
lastPauseTime = 0;
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;
import org.telegram.messenger.R;
import org.telegram.messenger.UserConfig;
import org.telegram.messenger.Utilities;
import org.telegram.ui.Cells.ChatOrUserCell;
import org.telegram.ui.Views.AvatarUpdater;
import org.telegram.ui.Views.BackupImageView;
import org.telegram.ui.Views.BaseFragment;
......@@ -239,8 +240,8 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen
}
@Override
public void didSelectContact(int user_id) {
MessagesController.Instance.addUserToChat(chat_id, user_id, info);
public void didSelectContact(TLRPC.User user) {
MessagesController.Instance.addUserToChat(chat_id, user, info);
}
@Override
......@@ -277,9 +278,12 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen
public void didReceivedNotification(int id, Object... args) {
if (id == MessagesController.updateInterfaces) {
updateOnlineCount();
if (listView != null) {
listView.invalidateViews();
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();
}
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) {
int chatId = (Integer)args[0];
......@@ -355,6 +359,19 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen
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() {
if (info == null) {
return;
......@@ -451,11 +468,11 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen
private void kickUser(TLRPC.TL_chatParticipant user) {
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 {
NotificationCenter.Instance.removeObserver(this, 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);
finishFragment();
}
......@@ -674,60 +691,19 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen
TLRPC.User user = MessagesController.Instance.users.get(part.user_id);
if (view == null) {
LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = li.inflate(R.layout.messages_search_user_layout, viewGroup, false);
view = new ChatOrUserCell(mContext);
((ChatOrUserCell)view).useBoldFont = true;
((ChatOrUserCell)view).usePadding = false;
((ChatOrUserCell)view).useSeparator = true;
}
ContactsActivity.ContactListRowHolder holder = (ContactsActivity.ContactListRowHolder)view.getTag();
if (holder == null) {
holder = new ContactsActivity.ContactListRowHolder(view);
view.setTag(holder);
}
View divider = view.findViewById(R.id.settings_row_divider);
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>"));
}
((ChatOrUserCell)view).setData(user, null, null, null, null);
// if (info.admin_id != UserConfig.clientUserId && part.inviter_id != UserConfig.clientUserId && part.user_id != UserConfig.clientUserId) {
//
// } 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) {
if (view == null) {
LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
......
......@@ -131,7 +131,7 @@ public class ChatProfileChangeNameActivity extends BaseFragment {
}
((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);
if (!animations) {
firstNameField.requestFocus();
......
......@@ -26,6 +26,7 @@ import android.widget.TextView;
import org.telegram.PhoneFormat.PhoneFormat;
import org.telegram.TL.TLRPC;
import org.telegram.messenger.ConnectionsManager;
import org.telegram.messenger.ContactsController;
import org.telegram.messenger.MessagesController;
import org.telegram.messenger.NotificationCenter;
import org.telegram.messenger.R;
......@@ -49,7 +50,8 @@ public class ContactAddActivity extends BaseFragment implements NotificationCent
NotificationCenter.Instance.addObserver(this, MessagesController.updateInterfaces);
user_id = getArguments().getInt("user_id", 0);
phone = getArguments().getString("phone");
return true;
TLRPC.User user = MessagesController.Instance.users.get(user_id);
return user != null;
}
@Override
......@@ -64,8 +66,10 @@ public class ContactAddActivity extends BaseFragment implements NotificationCent
fragmentView = inflater.inflate(R.layout.contact_add_layout, container, false);
TLRPC.User user = MessagesController.Instance.users.get(user_id);
if (phone != null) {
user.phone = PhoneFormat.stripExceptNumbers(phone);
if (user.phone == null) {
if (phone != null) {
user.phone = PhoneFormat.stripExceptNumbers(phone);
}
}
onlineText = (TextView)fragmentView.findViewById(R.id.settings_online);
......@@ -137,7 +141,7 @@ public class ContactAddActivity extends BaseFragment implements NotificationCent
if (value == 0) {
value = user.status.expires;
}
onlineText.setText(String.format("%s %s", getStringEntry(R.string.LastSeen), Utilities.formatDateOnline(value)));
onlineText.setText(Utilities.formatDateOnline(value));
}
}
}
......@@ -151,7 +155,10 @@ public class ContactAddActivity extends BaseFragment implements NotificationCent
public void didReceivedNotification(int id, Object... args) {
if (id == MessagesController.updateInterfaces) {
updateAvatarLayout();
int mask = (Integer)args[0];
if ((mask & MessagesController.UPDATE_MASK_AVATAR) != 0 || (mask & MessagesController.UPDATE_MASK_STATUS) != 0) {
updateAvatarLayout();
}
}
}
......@@ -197,8 +204,9 @@ public class ContactAddActivity extends BaseFragment implements NotificationCent
TLRPC.User user = MessagesController.Instance.users.get(user_id);
user.first_name = firstNameField.getText().toString();
user.last_name = lastNameField.getText().toString();
MessagesController.Instance.addContact(user);
ContactsController.Instance.addContact(user);
finishFragment();
NotificationCenter.Instance.postNotificationName(MessagesController.updateInterfaces, MessagesController.UPDATE_MASK_NAME);
}
}
});
......@@ -212,7 +220,7 @@ public class ContactAddActivity extends BaseFragment implements NotificationCent
}
((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);
if (!animations) {
firstNameField.requestFocus();
......
......@@ -41,7 +41,6 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Locale;
import java.util.Timer;
import java.util.TimerTask;
......@@ -54,7 +53,6 @@ public class CountrySelectActivity extends ActionBarActivity {
private boolean searching;
private BaseAdapter searchListViewAdapter;
private TextView epmtyTextView;
private boolean isRTL;
private HashMap<String, ArrayList<Country>> countries = new HashMap<String, ArrayList<Country>>();
private ArrayList<String> sortedCountries = new ArrayList<String>();
......@@ -71,10 +69,6 @@ public class CountrySelectActivity extends ActionBarActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Locale locale = Locale.getDefault();
String lang = locale.getLanguage();
isRTL = lang != null && lang.toLowerCase().equals("ar");
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(getResources().getAssets().open("countries.txt")));
String line;
......@@ -260,7 +254,7 @@ public class CountrySelectActivity extends ActionBarActivity {
searchWas = false;
ViewGroup group = (ViewGroup) listView.getParent();
listView.setAdapter(listViewAdapter);
if (!isRTL) {
if (!Utilities.isRTL) {
listView.setPadding(Utilities.dp(16), listView.getPaddingTop(), Utilities.dp(30), listView.getPaddingBottom());
} else {
listView.setPadding(Utilities.dp(30), listView.getPaddingTop(), Utilities.dp(16), listView.getPaddingBottom());
......
......@@ -102,8 +102,12 @@ public class DocumentSelectActivity extends BaseFragment {
@Override
public void onFragmentDestroy() {
if (receiverRegistered) {
parentActivity.unregisterReceiver(receiver);
try {
if (receiverRegistered) {
parentActivity.unregisterReceiver(receiver);
}
} catch (Exception e) {
FileLog.e("tmessages", e);
}
super.onFragmentDestroy();
}
......@@ -376,13 +380,17 @@ public class DocumentSelectActivity extends BaseFragment {
if (extDevice != null) {
result.removeAll(aliases.get(extDevice));
for (String path : result) {
boolean isSd = path.toLowerCase().contains("sd");
ListItem item = new ListItem();
item.title = getString(isSd ? R.string.SdCard : R.string.ExternalStorage);
item.icon = R.drawable.ic_external_storage;
item.subtitle = getRootSubtitle(path);
item.file = new File(path);
items.add(item);
try {
boolean isSd = path.toLowerCase().contains("sd");
ListItem item = new ListItem();
item.title = getString(isSd ? R.string.SdCard : R.string.ExternalStorage);
item.icon = R.drawable.ic_external_storage;
item.subtitle = getRootSubtitle(path);
item.file = new File(path);
items.add(item);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
}
} catch (Exception e) {
......
......@@ -9,12 +9,14 @@
package org.telegram.ui;
import android.content.Intent;
import android.graphics.Point;
import android.net.Uri;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBar;
import android.view.Display;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
......@@ -64,6 +66,7 @@ public class GalleryImageViewer extends AbstractGalleryActivity implements Notif
private ProgressBar loadingProgress;
private String currentFileName;
private int user_id = 0;
private Point displaySize = new Point();
private ArrayList<MessageObject> imagesArrTemp = new ArrayList<MessageObject>();
private HashMap<Integer, MessageObject> imagesByIdsTemp = new HashMap<Integer, MessageObject>();
......@@ -80,6 +83,14 @@ public class GalleryImageViewer extends AbstractGalleryActivity implements Notif
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Display display = getWindowManager().getDefaultDisplay();
if(android.os.Build.VERSION.SDK_INT < 13) {
displaySize.set(display.getWidth(), display.getHeight());
} else {
display.getSize(displaySize);
}
classGuid = ConnectionsManager.Instance.generateClassGuid();
setContentView(R.layout.gallery_layout);
......@@ -112,6 +123,7 @@ public class GalleryImageViewer extends AbstractGalleryActivity implements Notif
NotificationCenter.Instance.addObserver(this, MessagesController.mediaCountDidLoaded);
NotificationCenter.Instance.addObserver(this, MessagesController.mediaDidLoaded);
NotificationCenter.Instance.addObserver(this, MessagesController.userPhotosLoaded);
NotificationCenter.Instance.addObserver(this, 658);
Integer index = null;
if (localPagerAdapter == null) {
......@@ -212,6 +224,9 @@ public class GalleryImageViewer extends AbstractGalleryActivity implements Notif
deleteButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (mViewPager == null) {
return;
}
int item = mViewPager.getCurrentItem();
MessageObject obj = localPagerAdapter.imagesArr.get(item);
if (obj.messageOwner.send_state == MessagesController.MESSAGE_SEND_STATE_SENT) {
......@@ -241,6 +256,7 @@ public class GalleryImageViewer extends AbstractGalleryActivity implements Notif
NotificationCenter.Instance.removeObserver(this, MessagesController.mediaCountDidLoaded);
NotificationCenter.Instance.removeObserver(this, MessagesController.mediaDidLoaded);
NotificationCenter.Instance.removeObserver(this, MessagesController.userPhotosLoaded);
NotificationCenter.Instance.removeObserver(this, 658);
ConnectionsManager.Instance.cancelRpcsForClassGuid(classGuid);
}
......@@ -354,7 +370,7 @@ public class GalleryImageViewer extends AbstractGalleryActivity implements Notif
getSupportActionBar().setTitle(String.format("%d %s %d", pos, getString(R.string.Of), totalCount));
if (title != null) {
fakeTitleView.setText(String.format("%d %s %d", pos, getString(R.string.Of), totalCount));
fakeTitleView.measure(View.MeasureSpec.makeMeasureSpec(400, View.MeasureSpec.AT_MOST), 40);
fakeTitleView.measure(View.MeasureSpec.makeMeasureSpec(400, View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(100, View.MeasureSpec.AT_MOST));
title.setWidth(fakeTitleView.getMeasuredWidth() + Utilities.dp(8));
title.setMaxWidth(fakeTitleView.getMeasuredWidth() + Utilities.dp(8));
}
......@@ -450,10 +466,21 @@ public class GalleryImageViewer extends AbstractGalleryActivity implements Notif
}
}
}
} else if (id == 658) {
try {
if (!isFinishing()) {
finish();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
private TLRPC.FileLocation getCurrentFile() {
if (mViewPager == null) {
return null;
}
int item = mViewPager.getCurrentItem();
if (withoutBottom) {
return localPagerAdapter.imagesArrLocations.get(item);
......@@ -775,7 +802,7 @@ public class GalleryImageViewer extends AbstractGalleryActivity implements Notif
getSupportActionBar().setTitle(String.format("%d %s %d", (totalCount - imagesArr.size()) + position + 1, getString(R.string.Of), totalCount));
if (title != null) {
fakeTitleView.setText(String.format("%d %s %d", (totalCount - imagesArr.size()) + position + 1, getString(R.string.Of), totalCount));
fakeTitleView.measure(View.MeasureSpec.makeMeasureSpec(400, View.MeasureSpec.AT_MOST), 40);
fakeTitleView.measure(View.MeasureSpec.makeMeasureSpec(400, View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(100, View.MeasureSpec.AT_MOST));
title.setWidth(fakeTitleView.getMeasuredWidth() + Utilities.dp(8));
title.setMaxWidth(fakeTitleView.getMeasuredWidth() + Utilities.dp(8));
}
......@@ -794,7 +821,7 @@ public class GalleryImageViewer extends AbstractGalleryActivity implements Notif
getSupportActionBar().setTitle(String.format("%d %s %d", position + 1, getString(R.string.Of), imagesArrLocations.size()));
if (title != null) {
fakeTitleView.setText(String.format("%d %s %d", position + 1, getString(R.string.Of), imagesArrLocations.size()));
fakeTitleView.measure(View.MeasureSpec.makeMeasureSpec(400, View.MeasureSpec.AT_MOST), 40);
fakeTitleView.measure(View.MeasureSpec.makeMeasureSpec(400, View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(100, View.MeasureSpec.AT_MOST));
title.setWidth(fakeTitleView.getMeasuredWidth() + Utilities.dp(8));
title.setMaxWidth(fakeTitleView.getMeasuredWidth() + Utilities.dp(8));
}
......@@ -885,7 +912,16 @@ public class GalleryImageViewer extends AbstractGalleryActivity implements Notif
ArrayList<TLRPC.PhotoSize> sizes = message.messageOwner.media.photo.sizes;
iv.isVideo = false;
if (sizes.size() > 0) {
TLRPC.PhotoSize sizeFull = PhotoObject.getClosestPhotoSizeWithSize(sizes, 800, 800);
int width = (int)(Math.min(displaySize.x, displaySize.y) * 0.7f);
int height = width + Utilities.dp(100);
if (width > 800) {
width = 800;
}
if (height > 800) {
height = 800;
}
TLRPC.PhotoSize sizeFull = PhotoObject.getClosestPhotoSizeWithSize(sizes, width, height);
if (message.imagePreview != null) {
iv.setImage(sizeFull.location, null, message.imagePreview, sizeFull.size);
} else {
......
......@@ -37,6 +37,7 @@ import android.widget.TextView;
import org.telegram.TL.TLRPC;
import org.telegram.messenger.ConnectionsManager;
import org.telegram.messenger.ContactsController;
import org.telegram.messenger.Emoji;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.MessagesController;
......@@ -44,6 +45,7 @@ import org.telegram.messenger.NotificationCenter;
import org.telegram.messenger.R;
import org.telegram.messenger.UserConfig;
import org.telegram.messenger.Utilities;
import org.telegram.ui.Views.BackupImageView;
import org.telegram.ui.Views.BaseFragment;
import org.telegram.ui.Views.PinnedHeaderListView;
import org.telegram.ui.Views.SectionedBaseAdapter;
......@@ -198,7 +200,7 @@ public class GroupCreateActivity extends BaseFragment implements NotificationCen
if (searching && searchWas) {
user = searchResult.get(row);
} else {
ArrayList<TLRPC.TL_contact> arr = MessagesController.Instance.usersSectionsDict.get(MessagesController.Instance.sortedUsersSectionsArray.get(section));
ArrayList<TLRPC.TL_contact> arr = ContactsController.Instance.usersSectionsDict.get(ContactsController.Instance.sortedUsersSectionsArray.get(section));
user = MessagesController.Instance.users.get(arr.get(row).user_id);
listView.invalidateViews();
}
......@@ -367,7 +369,7 @@ public class GroupCreateActivity extends BaseFragment implements NotificationCen
ArrayList<CharSequence> resultArrayNames = new ArrayList<CharSequence>();
String q = query.toLowerCase();
for (TLRPC.TL_contact contact : MessagesController.Instance.contacts) {
for (TLRPC.TL_contact contact : ContactsController.Instance.contacts) {
TLRPC.User user = MessagesController.Instance.users.get(contact.user_id);
if (user.first_name.toLowerCase().startsWith(q) || user.last_name.toLowerCase().startsWith(q)) {
if (user.id == UserConfig.clientUserId) {
......@@ -432,8 +434,11 @@ public class GroupCreateActivity extends BaseFragment implements NotificationCen
listViewAdapter.notifyDataSetChanged();
}
} else if (id == MessagesController.updateInterfaces) {
if (listView != null) {
listView.invalidateViews();
int mask = (Integer)args[0];
if ((mask & MessagesController.UPDATE_MASK_AVATAR) != 0 || (mask & MessagesController.UPDATE_MASK_NAME) != 0 || (mask & MessagesController.UPDATE_MASK_STATUS) != 0) {
if (listView != null) {
listView.invalidateViews();
}
}
} else if (id == MessagesController.chatDidCreated) {
Utilities.RunOnUIThread(new Runnable() {
......@@ -467,7 +472,7 @@ public class GroupCreateActivity extends BaseFragment implements NotificationCen
if (searching && searchWas) {
return searchResult == null || searchResult.isEmpty() ? 0 : 1;
}
return MessagesController.Instance.sortedUsersSectionsArray.size();
return ContactsController.Instance.sortedUsersSectionsArray.size();
}
@Override
......@@ -475,7 +480,7 @@ public class GroupCreateActivity extends BaseFragment implements NotificationCen
if (searching && searchWas) {
return searchResult == null ? 0 : searchResult.size();
}
ArrayList<TLRPC.TL_contact> arr = MessagesController.Instance.usersSectionsDict.get(MessagesController.Instance.sortedUsersSectionsArray.get(section));
ArrayList<TLRPC.TL_contact> arr = ContactsController.Instance.usersSectionsDict.get(ContactsController.Instance.sortedUsersSectionsArray.get(section));
return arr.size();
}
......@@ -488,7 +493,7 @@ public class GroupCreateActivity extends BaseFragment implements NotificationCen
user = MessagesController.Instance.users.get(searchResult.get(position).id);
size = searchResult.size();
} else {
ArrayList<TLRPC.TL_contact> arr = MessagesController.Instance.usersSectionsDict.get(MessagesController.Instance.sortedUsersSectionsArray.get(section));
ArrayList<TLRPC.TL_contact> arr = ContactsController.Instance.usersSectionsDict.get(ContactsController.Instance.sortedUsersSectionsArray.get(section));
user = MessagesController.Instance.users.get(arr.get(position).user_id);
size = arr.size();
}
......@@ -497,9 +502,9 @@ public class GroupCreateActivity extends BaseFragment implements NotificationCen
LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = li.inflate(R.layout.group_create_row_layout, parent, false);
}
ContactsActivity.ContactListRowHolder holder = (ContactsActivity.ContactListRowHolder)convertView.getTag();
ContactListRowHolder holder = (ContactListRowHolder)convertView.getTag();
if (holder == null) {
holder = new ContactsActivity.ContactListRowHolder(convertView);
holder = new ContactListRowHolder(convertView);
convertView.setTag(holder);
}
......@@ -552,7 +557,7 @@ public class GroupCreateActivity extends BaseFragment implements NotificationCen
if (value == 0) {
value = user.status.expires;
}
holder.messageTextView.setText(getStringEntry(R.string.LastSeen) + " " + Utilities.formatDateOnline(value));
holder.messageTextView.setText(Utilities.formatDateOnline(value));
}
holder.messageTextView.setTextColor(0xff808080);
}
......@@ -592,9 +597,21 @@ public class GroupCreateActivity extends BaseFragment implements NotificationCen
if (searching && searchWas) {
textView.setText(getStringEntry(R.string.AllContacts));
} else {
textView.setText(MessagesController.Instance.sortedUsersSectionsArray.get(section));
textView.setText(ContactsController.Instance.sortedUsersSectionsArray.get(section));
}
return convertView;
}
}
public static class ContactListRowHolder {
public BackupImageView avatarImage;
public TextView messageTextView;
public TextView nameTextView;
public ContactListRowHolder(View view) {
messageTextView = (TextView)view.findViewById(R.id.messages_list_row_message);
nameTextView = (TextView)view.findViewById(R.id.messages_list_row_name);
avatarImage = (BackupImageView)view.findViewById(R.id.messages_list_row_avatar);
}
}
}
......@@ -15,7 +15,6 @@ import android.content.Intent;
import android.os.Bundle;
import android.support.v4.internal.view.SupportMenuItem;
import android.support.v7.app.ActionBar;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
......@@ -27,12 +26,12 @@ import android.widget.ImageButton;
import android.widget.TextView;
import org.telegram.TL.TLRPC;
import org.telegram.messenger.ConnectionsManager;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.MessagesController;
import org.telegram.messenger.NotificationCenter;
import org.telegram.messenger.R;
import org.telegram.messenger.Utilities;
import org.telegram.ui.Cells.ChatOrUserCell;
import org.telegram.ui.Views.AvatarUpdater;
import org.telegram.ui.Views.BackupImageView;
import org.telegram.ui.Views.BaseFragment;
......@@ -228,8 +227,9 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati
@Override
public void didReceivedNotification(int id, final Object... args) {
if (id == MessagesController.updateInterfaces) {
if (listView != null) {
listView.invalidateViews();
int mask = (Integer)args[0];
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.chatDidFailCreate) {
Utilities.HideProgressDialog(parentActivity);
......@@ -250,6 +250,19 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati
}
}
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 class ListAdapter extends SectionedBaseAdapter {
private Context mContext;
......@@ -295,58 +308,13 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati
TLRPC.User user = MessagesController.Instance.users.get(selectedContacts.get(position));
if (convertView == null) {
LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = li.inflate(R.layout.messages_search_user_layout, parent, false);
}
ContactsActivity.ContactListRowHolder holder = (ContactsActivity.ContactListRowHolder)convertView.getTag();
if (holder == null) {
holder = new ContactsActivity.ContactListRowHolder(convertView);
convertView.setTag(holder);
}
View divider = convertView.findViewById(R.id.settings_row_divider);
if (position == selectedContacts.size() - 1) {
divider.setVisibility(View.INVISIBLE);
} else {
divider.setVisibility(View.VISIBLE);
convertView = new ChatOrUserCell(mContext);
((ChatOrUserCell)convertView).useBoldFont = true;
((ChatOrUserCell)convertView).usePadding = false;
}
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>"));
}
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) {
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(getStringEntry(R.string.LastSeen) + " " + Utilities.formatDateOnline(value));
}
holder.messageTextView.setTextColor(0xff808080);
}
}
((ChatOrUserCell)convertView).setData(user, null, null, null, null);
((ChatOrUserCell) convertView).useSeparator = position != selectedContacts.size() - 1;
return convertView;
}
......
......@@ -23,8 +23,7 @@ import android.widget.ImageView;
import android.widget.TextView;
import org.telegram.messenger.R;
import java.util.Locale;
import org.telegram.messenger.Utilities;
public class IntroActivity extends ActionBarActivity {
private ViewPager viewPager;
......@@ -32,7 +31,6 @@ public class IntroActivity extends ActionBarActivity {
private ImageView topImage2;
private ViewGroup bottomPages;
private int lastPage = 0;
private boolean isRTL = false;
private boolean justCreated = false;
private boolean startPressed = false;
private int[] icons;
......@@ -45,10 +43,7 @@ public class IntroActivity extends ActionBarActivity {
setContentView(R.layout.intro_layout);
Locale locale = Locale.getDefault();
String lang = locale.getLanguage();
if (lang != null && lang.toLowerCase().equals("ar")) {
isRTL = true;
if (Utilities.isRTL) {
icons = new int[] {
R.drawable.intro7,
R.drawable.intro6,
......@@ -212,7 +207,7 @@ public class IntroActivity extends ActionBarActivity {
protected void onResume() {
super.onResume();
if (justCreated) {
if (isRTL) {
if (Utilities.isRTL) {
viewPager.setCurrentItem(6);
lastPage = 6;
} else {
......
......@@ -329,7 +329,10 @@ public class LocationActivity extends BaseFragment implements NotificationCenter
@Override
public void didReceivedNotification(int id, Object... args) {
if (id == MessagesController.updateInterfaces) {
updateUserData();
int mask = (Integer)args[0];
if ((mask & MessagesController.UPDATE_MASK_AVATAR) != 0 || (mask & MessagesController.UPDATE_MASK_NAME) != 0) {
updateUserData();
}
} else if (id == MessagesController.closeChats) {
removeSelfFromStack();
}
......
......@@ -25,7 +25,6 @@ import android.view.animation.AccelerateDecelerateInterpolator;
import android.widget.ImageView;
import android.widget.TextView;
import org.telegram.messenger.ConnectionsManager;
import org.telegram.messenger.R;
import org.telegram.messenger.Utilities;
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