Commit 507d05aa authored by DrKLO's avatar DrKLO

update to 1.3.21

Ability to delete add rename contacts, proper handling of new contacts
in phone book
New photo crop
Ability to disable automatic photo download
Ability to disable notifications about new registered contacts
Updated Spanish localization
Bug fixes
parent 9814a6e9
<?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="148" android:versionCode="160"
android:versionName="1.3.19"> android:versionName="1.3.21">
<supports-screens android:anyDensity="true" <supports-screens android:anyDensity="true"
android:smallScreens="true" android:smallScreens="true"
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
<uses-feature android:name="android.hardware.screen.PORTRAIT" 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.INTERNET" />
<!--<uses-permission android:name="android.permission.RECORD_AUDIO" />-->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.RECEIVE_SMS" /> <uses-permission android:name="android.permission.RECEIVE_SMS" />
...@@ -165,6 +166,9 @@ ...@@ -165,6 +166,9 @@
android:resource="@xml/contacts" /> android:resource="@xml/contacts" />
</service> </service>
<service android:name="org.telegram.messenger.GcmService" android:enabled="true" android:exported="true"/>
<service android:name=".BackgroundService" android:enabled="true" android:stopWithTask="false"/>
<uses-library android:name="com.google.android.maps" android:required="false"/> <uses-library android:name="com.google.android.maps" android:required="false"/>
</application> </application>
......
...@@ -414,6 +414,7 @@ public class TLClassStore { ...@@ -414,6 +414,7 @@ public class TLClassStore {
classStore.put(TLRPC.TL_messageActionTTLChange.constructor, TLRPC.TL_messageActionTTLChange.class); classStore.put(TLRPC.TL_messageActionTTLChange.constructor, TLRPC.TL_messageActionTTLChange.class);
classStore.put(TLRPC.TL_videoEncrypted.constructor, TLRPC.TL_videoEncrypted.class); classStore.put(TLRPC.TL_videoEncrypted.constructor, TLRPC.TL_videoEncrypted.class);
classStore.put(TLRPC.TL_documentEncrypted.constructor, TLRPC.TL_documentEncrypted.class); classStore.put(TLRPC.TL_documentEncrypted.constructor, TLRPC.TL_documentEncrypted.class);
classStore.put(TLRPC.TL_audioEncrypted.constructor, TLRPC.TL_audioEncrypted.class);
classStore.put(TLRPC.TL_gzip_packed.constructor, TLRPC.TL_gzip_packed.class); classStore.put(TLRPC.TL_gzip_packed.constructor, TLRPC.TL_gzip_packed.class);
classStore.put(TLRPC.Vector.constructor, TLRPC.Vector.class); classStore.put(TLRPC.Vector.constructor, TLRPC.Vector.class);
classStore.put(TLRPC.TL_userProfilePhotoOld.constructor, TLRPC.TL_userProfilePhotoOld.class); classStore.put(TLRPC.TL_userProfilePhotoOld.constructor, TLRPC.TL_userProfilePhotoOld.class);
......
...@@ -1227,16 +1227,6 @@ public class TLRPC { ...@@ -1227,16 +1227,6 @@ public class TLRPC {
} }
} }
public static class Audio extends TLObject {
public long id;
public long access_hash;
public int user_id;
public int date;
public int duration;
public int size;
public int dc_id;
}
public static class TL_audioEmpty extends Audio { public static class TL_audioEmpty extends Audio {
public static int constructor = 0x586988d8; public static int constructor = 0x586988d8;
...@@ -8776,6 +8766,19 @@ public class TLRPC { ...@@ -8776,6 +8766,19 @@ public class TLRPC {
public byte[] iv; public byte[] iv;
} }
public static class Audio extends TLObject {
public long id;
public long access_hash;
public int user_id;
public int date;
public int duration;
public int size;
public int dc_id;
public String path;
public byte[] key;
public byte[] iv;
}
public static class MessageAction extends TLObject { public static class MessageAction extends TLObject {
public Photo photo; public Photo photo;
public UserProfilePhoto newUserPhoto; public UserProfilePhoto newUserPhoto;
...@@ -8871,6 +8874,36 @@ public class TLRPC { ...@@ -8871,6 +8874,36 @@ public class TLRPC {
} }
} }
public static class TL_audioEncrypted extends Audio {
public static int constructor = 0x555555F6;
public void readParams(SerializedData stream) {
id = stream.readInt64();
access_hash = stream.readInt64();
user_id = stream.readInt32();
date = stream.readInt32();
duration = stream.readInt32();
size = stream.readInt32();
dc_id = stream.readInt32();
key = stream.readByteArray();
iv = stream.readByteArray();
}
public void serializeToStream(SerializedData stream) {
stream.writeInt32(constructor);
stream.writeInt64(id);
stream.writeInt64(access_hash);
stream.writeInt32(user_id);
stream.writeInt32(date);
stream.writeInt32(duration);
stream.writeInt32(size);
stream.writeInt32(dc_id);
stream.writeByteArray(key);
stream.writeByteArray(iv);
}
}
public static class TL_messageActionUserUpdatedPhoto extends MessageAction { public static class TL_messageActionUserUpdatedPhoto extends MessageAction {
public static int constructor = 0x55555551; public static int constructor = 0x55555551;
......
/*
* 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.messenger;
import android.app.Service;
import android.content.Intent;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.util.Log;
public class BackgroundService extends Service {
private Handler handler = new Handler(Looper.getMainLooper());
private Runnable checkRunnable = new Runnable() {
@Override
public void run() {
check();
}
};
public BackgroundService() {
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {
super.onCreate();
check();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
super.onStartCommand(intent, flags, startId);
Log.e("tmessages", "onStartCommand");
return START_STICKY;
}
private void check() {
handler.removeCallbacks(checkRunnable);
handler.postDelayed(checkRunnable, 1500);
ConnectionsManager connectionsManager = ConnectionsManager.Instance;
}
@Override
public void onDestroy() {
super.onDestroy();
Log.e("tmessages", "onDestroy");
}
}
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -183,6 +183,7 @@ public class ContactsController { ...@@ -183,6 +183,7 @@ public class ContactsController {
private HashMap<Integer, Contact> readContactsFromPhoneBook() { private HashMap<Integer, Contact> readContactsFromPhoneBook() {
HashMap<Integer, Contact> contactsMap = new HashMap<Integer, Contact>(); HashMap<Integer, Contact> contactsMap = new HashMap<Integer, Contact>();
try {
ContentResolver cr = ApplicationLoader.applicationContext.getContentResolver(); ContentResolver cr = ApplicationLoader.applicationContext.getContentResolver();
String ids = ""; String ids = "";
Cursor pCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, projectioPhones, null, null, null); Cursor pCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, projectioPhones, null, null, null);
...@@ -283,6 +284,10 @@ public class ContactsController { ...@@ -283,6 +284,10 @@ public class ContactsController {
} }
pCur.close(); pCur.close();
} }
} catch (Exception e) {
FileLog.e("tmessages", e);
contactsMap.clear();
}
return contactsMap; return contactsMap;
} }
...@@ -303,18 +308,42 @@ public class ContactsController { ...@@ -303,18 +308,42 @@ public class ContactsController {
return ret; return ret;
} }
public void performSyncPhoneBook(final HashMap<Integer, Contact> contactHashMap, final boolean request, final boolean first) { public void performSyncPhoneBook(final HashMap<Integer, Contact> contactHashMap, final boolean requ, final boolean first) {
Utilities.globalQueue.postRunnable(new Runnable() { Utilities.globalQueue.postRunnable(new Runnable() {
@Override @Override
public void run() { public void run() {
boolean request = requ;
if (request && first) {
if (UserConfig.contactsHash != null && UserConfig.contactsHash.length() != 0) {
UserConfig.contactsHash = "";
UserConfig.saveConfig(false);
request = false;
}
}
FileLog.e("tmessages", "start read contacts from phone"); FileLog.e("tmessages", "start read contacts from phone");
final HashMap<Integer, Contact> contactsMap = readContactsFromPhoneBook(); final HashMap<Integer, Contact> contactsMap = readContactsFromPhoneBook();
final HashMap<String, Contact> contactsBookShort = new HashMap<String, Contact>(); final HashMap<String, Contact> contactsBookShort = new HashMap<String, Contact>();
int oldCount = contactHashMap.size(); int oldCount = contactHashMap.size();
if (ConnectionsManager.disableContactsImport) {
if (requ && first) {
Utilities.stageQueue.postRunnable(new Runnable() {
@Override
public void run() {
contactsBookSPhones = contactsBookShort;
contactsBook = contactsMap;
contactsSyncInProgress = false;
contactsBookLoaded = true;
loadContacts(true);
}
});
}
return;
}
ArrayList<TLRPC.TL_inputPhoneContact> toImport = new ArrayList<TLRPC.TL_inputPhoneContact>(); ArrayList<TLRPC.TL_inputPhoneContact> toImport = new ArrayList<TLRPC.TL_inputPhoneContact>();
if (!contactHashMap.isEmpty()) { if (!contactHashMap.isEmpty()) {
HashMap<Integer, Contact> contactsMapCopy = new HashMap<Integer, Contact>(contactsMap);
for (HashMap.Entry<Integer, Contact> pair : contactsMap.entrySet()) { for (HashMap.Entry<Integer, Contact> pair : contactsMap.entrySet()) {
Integer id = pair.getKey(); Integer id = pair.getKey();
Contact value = pair.getValue(); Contact value = pair.getValue();
...@@ -413,7 +442,7 @@ public class ContactsController { ...@@ -413,7 +442,7 @@ public class ContactsController {
} }
}); });
FileLog.e("tmessages", "done procrssing contacts"); FileLog.e("tmessages", "done processing contacts");
if (request) { if (request) {
if (!toImport.isEmpty()) { if (!toImport.isEmpty()) {
...@@ -426,7 +455,9 @@ public class ContactsController { ...@@ -426,7 +455,9 @@ public class ContactsController {
public void run(TLObject response, TLRPC.TL_error error) { public void run(TLObject response, TLRPC.TL_error error) {
if (error == null) { if (error == null) {
FileLog.e("tmessages", "contacts imported"); FileLog.e("tmessages", "contacts imported");
if (!contactsMap.isEmpty()) {
MessagesStorage.Instance.putCachedPhoneBook(contactsMap); MessagesStorage.Instance.putCachedPhoneBook(contactsMap);
}
TLRPC.TL_contacts_importedContacts res = (TLRPC.TL_contacts_importedContacts)response; TLRPC.TL_contacts_importedContacts res = (TLRPC.TL_contacts_importedContacts)response;
MessagesStorage.Instance.putUsersAndChats(res.users, null, true, true); MessagesStorage.Instance.putUsersAndChats(res.users, null, true, true);
ArrayList<TLRPC.TL_contact> cArr = new ArrayList<TLRPC.TL_contact>(); ArrayList<TLRPC.TL_contact> cArr = new ArrayList<TLRPC.TL_contact>();
...@@ -462,8 +493,18 @@ public class ContactsController { ...@@ -462,8 +493,18 @@ public class ContactsController {
}); });
} }
} else { } else {
if (!contactsMap.isEmpty()) {
MessagesStorage.Instance.putCachedPhoneBook(contactsMap); MessagesStorage.Instance.putCachedPhoneBook(contactsMap);
} }
if (first) {
Utilities.stageQueue.postRunnable(new Runnable() {
@Override
public void run() {
loadContacts(true);
}
});
}
}
} }
}); });
} }
...@@ -890,6 +931,9 @@ public class ContactsController { ...@@ -890,6 +931,9 @@ public class ContactsController {
@Override @Override
public void run() { public void run() {
try { try {
if (ConnectionsManager.disableContactsImport) {
return;
}
Uri rawContactUri = ContactsContract.RawContacts.CONTENT_URI.buildUpon().appendQueryParameter(ContactsContract.RawContacts.ACCOUNT_NAME, currentAccount.name).appendQueryParameter(ContactsContract.RawContacts.ACCOUNT_TYPE, currentAccount.type).build(); Uri rawContactUri = ContactsContract.RawContacts.CONTENT_URI.buildUpon().appendQueryParameter(ContactsContract.RawContacts.ACCOUNT_NAME, currentAccount.name).appendQueryParameter(ContactsContract.RawContacts.ACCOUNT_TYPE, currentAccount.type).build();
Cursor c1 = ApplicationLoader.applicationContext.getContentResolver().query(rawContactUri, new String[]{BaseColumns._ID, ContactsContract.RawContacts.SYNC2}, null, null, null); Cursor c1 = ApplicationLoader.applicationContext.getContentResolver().query(rawContactUri, new String[]{BaseColumns._ID, ContactsContract.RawContacts.SYNC2}, null, null, null);
HashMap<Integer, Long> bookContacts = new HashMap<Integer, Long>(); HashMap<Integer, Long> bookContacts = new HashMap<Integer, Long>();
...@@ -922,20 +966,8 @@ public class ContactsController { ...@@ -922,20 +966,8 @@ public class ContactsController {
TLRPC.TL_contact contact = new TLRPC.TL_contact(); TLRPC.TL_contact contact = new TLRPC.TL_contact();
contact.user_id = uid; contact.user_id = uid;
newC.add(contact); newC.add(contact);
if (!delayedContactsUpdate.isEmpty()) {
int idx = delayedContactsUpdate.indexOf(-uid);
if (idx != -1) {
delayedContactsUpdate.remove(idx);
}
}
} else if (uid < 0) { } else if (uid < 0) {
contactsTD.add(-uid); contactsTD.add(-uid);
if (!delayedContactsUpdate.isEmpty()) {
int idx = delayedContactsUpdate.indexOf(-uid);
if (idx != -1) {
delayedContactsUpdate.remove(idx);
}
}
} }
} }
} }
...@@ -952,8 +984,10 @@ public class ContactsController { ...@@ -952,8 +984,10 @@ public class ContactsController {
} }
if (user == null) { if (user == null) {
user = MessagesController.Instance.users.get(newContact.user_id); user = MessagesController.Instance.users.get(newContact.user_id);
} else {
MessagesController.Instance.users.putIfAbsent(user.id, user);
} }
if (user == null || user.phone == null && user.phone.length() == 0) { if (user == null || user.phone == null || user.phone.length() == 0) {
reloadContacts = true; reloadContacts = true;
continue; continue;
} }
...@@ -989,6 +1023,8 @@ public class ContactsController { ...@@ -989,6 +1023,8 @@ public class ContactsController {
} }
if (user == null) { if (user == null) {
user = MessagesController.Instance.users.get(uid); user = MessagesController.Instance.users.get(uid);
} else {
MessagesController.Instance.users.putIfAbsent(user.id, user);
} }
if (user == null) { if (user == null) {
reloadContacts = true; reloadContacts = true;
...@@ -1095,7 +1131,7 @@ public class ContactsController { ...@@ -1095,7 +1131,7 @@ public class ContactsController {
} }
public long addContactToPhoneBook(TLRPC.User user) { public long addContactToPhoneBook(TLRPC.User user) {
if (currentAccount == null || user == null || user.phone == null || user.phone.length() == 0) { if (currentAccount == null || user == null || user.phone == null || user.phone.length() == 0 || ConnectionsManager.disableContactsImport) {
return -1; return -1;
} }
long res = -1; long res = -1;
...@@ -1146,6 +1182,9 @@ public class ContactsController { ...@@ -1146,6 +1182,9 @@ public class ContactsController {
} }
private void deleteContactFromPhoneBook(int uid) { private void deleteContactFromPhoneBook(int uid) {
if (ConnectionsManager.disableContactsImport) {
return;
}
ContentResolver contentResolver = ApplicationLoader.applicationContext.getContentResolver(); ContentResolver contentResolver = ApplicationLoader.applicationContext.getContentResolver();
synchronized (observerLock) { synchronized (observerLock) {
ignoreChanges = true; ignoreChanges = true;
......
...@@ -42,14 +42,10 @@ public class DispatchQueue extends Thread { ...@@ -42,14 +42,10 @@ public class DispatchQueue extends Thread {
} }
public void postRunnable(Runnable runnable) { public void postRunnable(Runnable runnable) {
postRunnable(runnable, 0, false); postRunnable(runnable, 0);
} }
public void postRunnable(Runnable runnable, boolean inFront) { public void postRunnable(Runnable runnable, int delay) {
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) {
...@@ -62,11 +58,7 @@ public class DispatchQueue extends Thread { ...@@ -62,11 +58,7 @@ 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, false); }, retryCount * 1500);
} }
} }
} }
...@@ -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, false); }, retryCount * 1500);
} }
} }
} }
......
...@@ -94,6 +94,24 @@ public class FileLoadOperation { ...@@ -94,6 +94,24 @@ public class FileLoadOperation {
ext = ".mp4"; ext = ".mp4";
} }
public FileLoadOperation(TLRPC.Audio audioLocation) {
if (audioLocation instanceof TLRPC.TL_audio) {
location = new TLRPC.TL_inputAudioFileLocation();
datacenter_id = audioLocation.dc_id;
location.id = audioLocation.id;
location.access_hash = audioLocation.access_hash;
} else if (audioLocation instanceof TLRPC.TL_audioEncrypted) {
location = new TLRPC.TL_inputEncryptedFileLocation();
location.id = audioLocation.id;
location.access_hash = audioLocation.access_hash;
datacenter_id = audioLocation.dc_id;
iv = new byte[32];
System.arraycopy(audioLocation.iv, 0, iv, 0, iv.length);
key = audioLocation.key;
}
ext = ".m4a";
}
public FileLoadOperation(TLRPC.Document documentLocation) { public FileLoadOperation(TLRPC.Document documentLocation) {
if (documentLocation instanceof TLRPC.TL_document) { if (documentLocation instanceof TLRPC.TL_document) {
location = new TLRPC.TL_inputDocumentFileLocation(); location = new TLRPC.TL_inputDocumentFileLocation();
...@@ -220,14 +238,14 @@ public class FileLoadOperation { ...@@ -220,14 +238,14 @@ public class FileLoadOperation {
opts.inSampleSize = (int)scaleFactor; opts.inSampleSize = (int)scaleFactor;
} }
opts.inPreferredConfig = Bitmap.Config.RGB_565; opts.inPreferredConfig = Bitmap.Config.ARGB_8888;
opts.inDither = false; opts.inDither = false;
image = BitmapFactory.decodeStream(is, null, opts); image = BitmapFactory.decodeStream(is, null, opts);
is.close(); is.close();
if (image == null) { if (image == null) {
if (!dontDelete) { //if (!dontDelete) {
cacheFileFinal.delete(); // cacheFileFinal.delete();
} //}
} else { } else {
if (filter != null && image != null) { if (filter != null && image != null) {
float bitmapW = image.getWidth(); float bitmapW = image.getWidth();
...@@ -252,13 +270,17 @@ public class FileLoadOperation { ...@@ -252,13 +270,17 @@ public class FileLoadOperation {
Utilities.stageQueue.postRunnable(new Runnable() { Utilities.stageQueue.postRunnable(new Runnable() {
@Override @Override
public void run() { public void run() {
if (image == null) {
delegate.didFailedLoadingFile(FileLoadOperation.this);
} else {
delegate.didFinishLoadingFile(FileLoadOperation.this); delegate.didFinishLoadingFile(FileLoadOperation.this);
} }
}
}); });
} catch (Exception e) { } catch (Exception e) {
if (!dontDelete) { //if (!dontDelete) {
cacheFileFinal.delete(); // cacheFileFinal.delete();
} //}
FileLog.e("tmessages", e); FileLog.e("tmessages", e);
} }
} }
...@@ -414,7 +436,7 @@ public class FileLoadOperation { ...@@ -414,7 +436,7 @@ public class FileLoadOperation {
opts.inSampleSize = (int) scaleFactor; opts.inSampleSize = (int) scaleFactor;
} }
opts.inPreferredConfig = Bitmap.Config.RGB_565; opts.inPreferredConfig = Bitmap.Config.ARGB_8888;
opts.inDither = false; opts.inDither = false;
try { try {
if (renamed) { if (renamed) {
...@@ -442,10 +464,14 @@ public class FileLoadOperation { ...@@ -442,10 +464,14 @@ public class FileLoadOperation {
} }
} }
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());
} }
if (image != null) {
delegate.didFinishLoadingFile(FileLoadOperation.this); delegate.didFinishLoadingFile(FileLoadOperation.this);
} else {
delegate.didFailedLoadingFile(FileLoadOperation.this);
}
} catch (Exception e) { } catch (Exception e) {
FileLog.e("tmessages", e); FileLog.e("tmessages", e);
delegate.didFailedLoadingFile(FileLoadOperation.this); delegate.didFailedLoadingFile(FileLoadOperation.this);
......
...@@ -391,8 +391,8 @@ public class FileLoader { ...@@ -391,8 +391,8 @@ public class FileLoader {
}); });
} }
public void cancelLoadFile(final TLRPC.Video video, final TLRPC.PhotoSize photo, final TLRPC.Document document) { public void cancelLoadFile(final TLRPC.Video video, final TLRPC.PhotoSize photo, final TLRPC.Document document, final TLRPC.Audio audio) {
if (video == null && photo == null && document == null) { if (video == null && photo == null && document == null && audio == null) {
return; return;
} }
Utilities.fileUploadQueue.postRunnable(new Runnable() { Utilities.fileUploadQueue.postRunnable(new Runnable() {
...@@ -405,6 +405,8 @@ public class FileLoader { ...@@ -405,6 +405,8 @@ public class FileLoader {
fileName = MessageObject.getAttachFileName(photo); fileName = MessageObject.getAttachFileName(photo);
} else if (document != null) { } else if (document != null) {
fileName = MessageObject.getAttachFileName(document); fileName = MessageObject.getAttachFileName(document);
} else if (audio != null) {
fileName = MessageObject.getAttachFileName(audio);
} }
if (fileName == null) { if (fileName == null) {
return; return;
...@@ -422,7 +424,7 @@ public class FileLoader { ...@@ -422,7 +424,7 @@ public class FileLoader {
return loadOperationPaths.containsKey(fileName); return loadOperationPaths.containsKey(fileName);
} }
public void loadFile(final TLRPC.Video video, final TLRPC.PhotoSize photo, final TLRPC.Document document) { public void loadFile(final TLRPC.Video video, final TLRPC.PhotoSize photo, final TLRPC.Document document, final TLRPC.Audio audio) {
Utilities.fileUploadQueue.postRunnable(new Runnable() { Utilities.fileUploadQueue.postRunnable(new Runnable() {
@Override @Override
public void run() { public void run() {
...@@ -433,6 +435,8 @@ public class FileLoader { ...@@ -433,6 +435,8 @@ public class FileLoader {
fileName = MessageObject.getAttachFileName(photo); fileName = MessageObject.getAttachFileName(photo);
} else if (document != null) { } else if (document != null) {
fileName = MessageObject.getAttachFileName(document); fileName = MessageObject.getAttachFileName(document);
} else if (audio != null) {
fileName = MessageObject.getAttachFileName(audio);
} }
if (fileName == null) { if (fileName == null) {
return; return;
...@@ -451,6 +455,9 @@ public class FileLoader { ...@@ -451,6 +455,9 @@ public class FileLoader {
} else if (document != null) { } else if (document != null) {
operation = new FileLoadOperation(document); operation = new FileLoadOperation(document);
operation.totalBytesCount = document.size; operation.totalBytesCount = document.size;
} else if (audio != null) {
operation = new FileLoadOperation(audio);
operation.totalBytesCount = audio.size;
} }
final String arg1 = fileName; final String arg1 = fileName;
...@@ -888,7 +895,7 @@ public class FileLoader { ...@@ -888,7 +895,7 @@ public class FileLoader {
} }
void enqueueImageProcessingOperationWithImage(final Bitmap image, final String filter, final String key, final CacheImage img) { void enqueueImageProcessingOperationWithImage(final Bitmap image, final String filter, final String key, final CacheImage img) {
if (image == null || key == null) { if (key == null) {
return; return;
} }
...@@ -907,7 +914,7 @@ public class FileLoader { ...@@ -907,7 +914,7 @@ public class FileLoader {
@Override @Override
public void run() { public void run() {
img.callAndClear(image); img.callAndClear(image);
if (memCache.get(key) == null) { if (image != null && memCache.get(key) == null) {
memCache.put(key, image); memCache.put(key, image);
} }
} }
......
...@@ -9,55 +9,20 @@ ...@@ -9,55 +9,20 @@
package org.telegram.messenger; package org.telegram.messenger;
import android.app.Activity; import android.app.Activity;
import android.content.BroadcastReceiver; import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.support.v4.content.WakefulBroadcastReceiver;
import android.os.Bundle;
import android.os.PowerManager;
import com.google.android.gms.gcm.GoogleCloudMessaging; public class GcmBroadcastReceiver extends WakefulBroadcastReceiver {
public class GcmBroadcastReceiver extends BroadcastReceiver {
public static final int NOTIFICATION_ID = 1; public static final int NOTIFICATION_ID = 1;
@Override @Override
public void onReceive(final Context context, final Intent intent) { public void onReceive(final Context context, final Intent intent) {
FileLog.d("tmessages", "GCM received intent: " + intent); FileLog.d("tmessages", "GCM received intent: " + intent);
ComponentName comp = new ComponentName(context.getPackageName(), GcmService.class.getName());
startWakefulService(context, (intent.setComponent(comp)));
setResultCode(Activity.RESULT_OK); 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) {
FileLog.d("tmessages", "GCM disabled");
return;
}
Thread thread = new Thread(new Runnable() {
public void run() {
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(context);
String messageType = gcm.getMessageType(intent);
ConnectionsManager.Instance.resumeNetworkMaybe();
wl.release();
}
});
thread.setPriority(Thread.MAX_PRIORITY);
thread.start();
} 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.");
} else if (intent.getStringExtra("unregistered") != null) {
FileLog.e("tmessages", "unregistration done, new messages from the authorized sender will be rejected");
} else if (registration != null) {
FileLog.e("tmessages", "registration id = " + registration);
}
}
} }
} }
/*
* 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.messenger;
import android.app.IntentService;
import android.content.Intent;
public class GcmService extends IntentService {
public GcmService() {
super("GcmService");
}
@Override
protected void onHandleIntent(Intent intent) {
if (intent.getAction().equals("com.google.android.c2dm.intent.RECEIVE")) {
// SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Context.MODE_PRIVATE);
// boolean globalEnabled = preferences.getBoolean("EnableAll", true);
// if (!globalEnabled) {
// FileLog.d("tmessages", "GCM disabled");
// return;
// }
ConnectionsManager.Instance.resumeNetworkMaybe();
} 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.");
} else if (intent.getStringExtra("unregistered") != null) {
FileLog.e("tmessages", "unregistration done, new messages from the authorized sender will be rejected");
} else if (registration != null) {
FileLog.e("tmessages", "registration id = " + registration);
}
}
GcmBroadcastReceiver.completeWakefulIntent(intent);
}
}
...@@ -334,7 +334,7 @@ public class MessagesStorage { ...@@ -334,7 +334,7 @@ public class MessagesStorage {
FileLog.e("tmessages", e); FileLog.e("tmessages", e);
} }
} }
}, true); });
} }
public void clearUserPhotos(final int uid) { public void clearUserPhotos(final int uid) {
...@@ -967,7 +967,7 @@ public class MessagesStorage { ...@@ -967,7 +967,7 @@ public class MessagesStorage {
FileLog.e("tmessages", e); FileLog.e("tmessages", e);
} }
} }
}, true); });
} }
public void putContacts(final ArrayList<TLRPC.TL_contact> contacts, final boolean deleteAll) { public void putContacts(final ArrayList<TLRPC.TL_contact> contacts, final boolean deleteAll) {
...@@ -1102,21 +1102,21 @@ public class MessagesStorage { ...@@ -1102,21 +1102,21 @@ public class MessagesStorage {
} }
cursor.dispose(); cursor.dispose();
} catch (Exception e) { } catch (Exception e) {
contactHashMap.clear();
FileLog.e("tmessages", e); FileLog.e("tmessages", e);
} finally {
ContactsController.Instance.performSyncPhoneBook(contactHashMap, true, true);
} }
ContactsController.Instance.performSyncPhoneBook(contactHashMap, true, true);
} }
}, true); });
} }
public void getContacts() { public void getContacts() {
storageQueue.postRunnable(new Runnable() { storageQueue.postRunnable(new Runnable() {
@Override @Override
public void run() { public void run() {
try {
ArrayList<TLRPC.TL_contact> contacts = new ArrayList<TLRPC.TL_contact>(); ArrayList<TLRPC.TL_contact> contacts = new ArrayList<TLRPC.TL_contact>();
ArrayList<TLRPC.User> users = new ArrayList<TLRPC.User>(); ArrayList<TLRPC.User> users = new ArrayList<TLRPC.User>();
try {
SQLiteCursor cursor = database.queryFinalized("SELECT * FROM contacts WHERE 1"); SQLiteCursor cursor = database.queryFinalized("SELECT * FROM contacts WHERE 1");
String uids = ""; String uids = "";
while (cursor.next()) { while (cursor.next()) {
...@@ -1150,12 +1150,14 @@ public class MessagesStorage { ...@@ -1150,12 +1150,14 @@ public class MessagesStorage {
} }
cursor.dispose(); cursor.dispose();
} }
ContactsController.Instance.processLoadedContacts(contacts, users, 1);
} catch (Exception e) { } catch (Exception e) {
contacts.clear();
users.clear();
FileLog.e("tmessages", e); FileLog.e("tmessages", e);
} }
ContactsController.Instance.processLoadedContacts(contacts, users, 1);
} }
}, true); });
} }
public void putMediaCount(final long uid, final int count) { public void putMediaCount(final long uid, final int count) {
...@@ -1203,7 +1205,7 @@ public class MessagesStorage { ...@@ -1203,7 +1205,7 @@ public class MessagesStorage {
FileLog.e("tmessages", e); FileLog.e("tmessages", e);
} }
} }
}, true); });
} }
public void loadMedia(final long uid, final int offset, final int count, final int max_id, final int classGuid) { public void loadMedia(final long uid, final int offset, final int count, final int max_id, final int classGuid) {
...@@ -1279,7 +1281,7 @@ public class MessagesStorage { ...@@ -1279,7 +1281,7 @@ public class MessagesStorage {
MessagesController.Instance.processLoadedMedia(res, uid, offset, count, max_id, true, classGuid); MessagesController.Instance.processLoadedMedia(res, uid, offset, count, max_id, true, classGuid);
} }
} }
}, true); });
} }
public void putMedia(final long uid, final ArrayList<TLRPC.Message> messages) { public void putMedia(final long uid, final ArrayList<TLRPC.Message> messages) {
...@@ -1469,7 +1471,7 @@ public class MessagesStorage { ...@@ -1469,7 +1471,7 @@ public class MessagesStorage {
MessagesController.Instance.processLoadedMessages(res, dialog_id, offset, count_query, max_id, true, classGuid, min_unread_id, max_unread_id, count_unread, max_unread_date, forward); MessagesController.Instance.processLoadedMessages(res, dialog_id, offset, count_query, max_id, true, classGuid, min_unread_id, max_unread_id, count_unread, max_unread_date, forward);
} }
} }
}, true); });
} }
public void startTransaction(boolean useQueue) { public void startTransaction(boolean useQueue) {
...@@ -2691,7 +2693,7 @@ public class MessagesStorage { ...@@ -2691,7 +2693,7 @@ public class MessagesStorage {
MessagesController.Instance.processLoadedDialogs(dialogs, encryptedChats, 0, 0, 100, true, true); MessagesController.Instance.processLoadedDialogs(dialogs, encryptedChats, 0, 0, 100, true, true);
} }
} }
}, true); });
} }
public void putDialogs(final TLRPC.messages_Dialogs dialogs) { public void putDialogs(final TLRPC.messages_Dialogs dialogs) {
......
...@@ -22,12 +22,23 @@ public class SerializedData { ...@@ -22,12 +22,23 @@ public class SerializedData {
private DataOutputStream out; private DataOutputStream out;
private ByteArrayInputStream inbuf; private ByteArrayInputStream inbuf;
private DataInputStream in; private DataInputStream in;
private boolean justCalc = false;
private int len;
public SerializedData() { public SerializedData() {
outbuf = new ByteArrayOutputStream(); outbuf = new ByteArrayOutputStream();
out = new DataOutputStream(outbuf); out = new DataOutputStream(outbuf);
} }
public SerializedData(boolean calculate) {
if (!calculate) {
outbuf = new ByteArrayOutputStream();
out = new DataOutputStream(outbuf);
}
justCalc = calculate;
len = 0;
}
public SerializedData(int size) { public SerializedData(int size) {
outbuf = new ByteArrayOutputStream(size); outbuf = new ByteArrayOutputStream(size);
out = new DataOutputStream(outbuf); out = new DataOutputStream(outbuf);
...@@ -50,13 +61,17 @@ public class SerializedData { ...@@ -50,13 +61,17 @@ public class SerializedData {
in = new DataInputStream(inbuf); in = new DataInputStream(inbuf);
} }
public void writeInt32(int x){ public void writeInt32(int x) {
if (!justCalc) {
writeInt32(x, out); writeInt32(x, out);
} else {
len += 4;
}
} }
protected void writeInt32(int x, DataOutputStream out){ private void writeInt32(int x, DataOutputStream out) {
try { try {
for(int i = 0; i < 4; i++){ for(int i = 0; i < 4; i++) {
out.write(x >> (i * 8)); out.write(x >> (i * 8));
} }
} catch(IOException gfdsgd) { } catch(IOException gfdsgd) {
...@@ -65,10 +80,14 @@ public class SerializedData { ...@@ -65,10 +80,14 @@ public class SerializedData {
} }
public void writeInt64(long i) { public void writeInt64(long i) {
if (!justCalc) {
writeInt64(i, out); writeInt64(i, out);
} else {
len += 8;
}
} }
protected void writeInt64(long x, DataOutputStream out){ private void writeInt64(long x, DataOutputStream out) {
try { try {
for(int i = 0; i < 8; i++){ for(int i = 0; i < 8; i++){
out.write((int)(x >> (i * 8))); out.write((int)(x >> (i * 8)));
...@@ -90,11 +109,15 @@ public class SerializedData { ...@@ -90,11 +109,15 @@ public class SerializedData {
} }
public void writeBool(boolean value) { public void writeBool(boolean value) {
if (!justCalc) {
if (value) { if (value) {
writeInt32(0x997275b5); writeInt32(0x997275b5);
} else { } else {
writeInt32(0xbc799737); writeInt32(0xbc799737);
} }
} else {
len += 4;
}
} }
public int readInt32() { public int readInt32() {
...@@ -143,9 +166,13 @@ public class SerializedData { ...@@ -143,9 +166,13 @@ public class SerializedData {
return 0; return 0;
} }
public void writeRaw(byte[] b){ public void writeRaw(byte[] b) {
try { try {
if (!justCalc) {
out.write(b); out.write(b);
} else {
len += b.length;
}
} catch(Exception x) { } catch(Exception x) {
FileLog.e("tmessages", "write raw error"); FileLog.e("tmessages", "write raw error");
} }
...@@ -153,7 +180,11 @@ public class SerializedData { ...@@ -153,7 +180,11 @@ public class SerializedData {
public void writeRaw(byte[] b, int offset, int count) { public void writeRaw(byte[] b, int offset, int count) {
try { try {
if (!justCalc) {
out.write(b, offset, count); out.write(b, offset, count);
} else {
len += count;
}
} catch(Exception x) { } catch(Exception x) {
FileLog.e("tmessages", "write raw error"); FileLog.e("tmessages", "write raw error");
} }
...@@ -161,7 +192,11 @@ public class SerializedData { ...@@ -161,7 +192,11 @@ public class SerializedData {
public void writeByte(int i) { public void writeByte(int i) {
try { try {
if (!justCalc) {
out.writeByte((byte)i); out.writeByte((byte)i);
} else {
len += 1;
}
} catch (Exception e) { } catch (Exception e) {
FileLog.e("tmessages", "write byte error"); FileLog.e("tmessages", "write byte error");
} }
...@@ -169,13 +204,17 @@ public class SerializedData { ...@@ -169,13 +204,17 @@ public class SerializedData {
public void writeByte(byte b) { public void writeByte(byte b) {
try { try {
if (!justCalc) {
out.writeByte(b); out.writeByte(b);
} else {
len += 1;
}
} catch (Exception e) { } catch (Exception e) {
FileLog.e("tmessages", "write byte error"); FileLog.e("tmessages", "write byte error");
} }
} }
public void readRaw(byte[] b){ public void readRaw(byte[] b) {
try { try {
in.read(b); in.read(b);
} catch(Exception x) { } catch(Exception x) {
...@@ -189,7 +228,7 @@ public class SerializedData { ...@@ -189,7 +228,7 @@ public class SerializedData {
return arr; return arr;
} }
public String readString(){ public String readString() {
try { try {
int sl = 1; int sl = 1;
int l = in.read(); int l = in.read();
...@@ -233,20 +272,36 @@ public class SerializedData { ...@@ -233,20 +272,36 @@ public class SerializedData {
return null; return null;
} }
public void writeByteArray(byte[] b){ public void writeByteArray(byte[] b) {
try { try {
if (b.length <= 253){ if (b.length <= 253){
if (!justCalc) {
out.write(b.length); out.write(b.length);
} else { } else {
len += 1;
}
} else {
if (!justCalc) {
out.write(254); out.write(254);
out.write(b.length); out.write(b.length);
out.write(b.length >> 8); out.write(b.length >> 8);
out.write(b.length >> 16); out.write(b.length >> 16);
} else {
len += 4;
}
} }
if (!justCalc) {
out.write(b); out.write(b);
} else {
len += b.length;
}
int i = b.length <= 253 ? 1 : 4; int i = b.length <= 253 ? 1 : 4;
while((b.length + i) % 4 != 0){ while((b.length + i) % 4 != 0){
if (!justCalc) {
out.write(0); out.write(0);
} else {
len += 1;
}
i++; i++;
} }
} catch(Exception x) { } catch(Exception x) {
...@@ -265,17 +320,33 @@ public class SerializedData { ...@@ -265,17 +320,33 @@ public class SerializedData {
public void writeByteArray(byte[] b, int offset, int count) { public void writeByteArray(byte[] b, int offset, int count) {
try { try {
if(count <= 253){ if(count <= 253){
if (!justCalc) {
out.write(count); out.write(count);
} else { } else {
len += 1;
}
} else {
if (!justCalc) {
out.write(254); out.write(254);
out.write(count); out.write(count);
out.write(count >> 8); out.write(count >> 8);
out.write(count >> 16); out.write(count >> 16);
} else {
len += 4;
} }
}
if (!justCalc) {
out.write(b, offset, count); out.write(b, offset, count);
} else {
len += count;
}
int i = count <= 253 ? 1 : 4; int i = count <= 253 ? 1 : 4;
while ((count + i) % 4 != 0){ while ((count + i) % 4 != 0){
if (!justCalc) {
out.write(0); out.write(0);
} else {
len += 1;
}
i++; i++;
} }
} catch(Exception x) { } catch(Exception x) {
...@@ -292,7 +363,7 @@ public class SerializedData { ...@@ -292,7 +363,7 @@ public class SerializedData {
return 0; return 0;
} }
public void writeDouble(double d){ public void writeDouble(double d) {
try { try {
writeInt64(Double.doubleToRawLongBits(d)); writeInt64(Double.doubleToRawLongBits(d));
} catch(Exception x) { } catch(Exception x) {
...@@ -301,8 +372,11 @@ public class SerializedData { ...@@ -301,8 +372,11 @@ public class SerializedData {
} }
public int length() { public int length() {
if (!justCalc) {
return isOut ? outbuf.size() : inbuf.available(); return isOut ? outbuf.size() : inbuf.available();
} }
return len;
}
protected void set(byte[] newData) { protected void set(byte[] newData) {
isOut = false; isOut = false;
......
...@@ -10,6 +10,7 @@ package org.telegram.messenger; ...@@ -10,6 +10,7 @@ package org.telegram.messenger;
import java.io.IOException; import java.io.IOException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.SocketTimeoutException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.ByteOrder; import java.nio.ByteOrder;
import java.util.Timer; import java.util.Timer;
...@@ -51,6 +52,7 @@ public class TcpConnection extends PyroClientAdapter { ...@@ -51,6 +52,7 @@ public class TcpConnection extends PyroClientAdapter {
private int willRetryConnectCount = 5; private int willRetryConnectCount = 5;
private boolean isNextPort = false; private boolean isNextPort = false;
private final Integer timerSync = 1; private final Integer timerSync = 1;
private boolean wasConnected;
public int transportRequestClass; public int transportRequestClass;
...@@ -102,6 +104,7 @@ public class TcpConnection extends PyroClientAdapter { ...@@ -102,6 +104,7 @@ public class TcpConnection extends PyroClientAdapter {
FileLog.d("tmessages", String.format(TcpConnection.this + " Connecting (%s:%d)", hostAddress, hostPort)); FileLog.d("tmessages", String.format(TcpConnection.this + " Connecting (%s:%d)", hostAddress, hostPort));
firstPacket = true; firstPacket = true;
restOfTheData = null; restOfTheData = null;
wasConnected = false;
hasSomeDataSinceLastConnect = false; hasSomeDataSinceLastConnect = false;
if (client != null) { if (client != null) {
client.removeListener(TcpConnection.this); client.removeListener(TcpConnection.this);
...@@ -113,7 +116,7 @@ public class TcpConnection extends PyroClientAdapter { ...@@ -113,7 +116,7 @@ public class TcpConnection extends PyroClientAdapter {
if (isNextPort) { if (isNextPort) {
client.setTimeout(8000); client.setTimeout(8000);
} else { } else {
client.setTimeout(35000); client.setTimeout(15000);
} }
selector.wakeup(); selector.wakeup();
} catch (Exception e) { } catch (Exception e) {
...@@ -141,7 +144,7 @@ public class TcpConnection extends PyroClientAdapter { ...@@ -141,7 +144,7 @@ public class TcpConnection extends PyroClientAdapter {
failedConnectionCount++; failedConnectionCount++;
if (failedConnectionCount == 1) { if (failedConnectionCount == 1) {
if (hasSomeDataSinceLastConnect) { if (hasSomeDataSinceLastConnect) {
willRetryConnectCount = 5; willRetryConnectCount = 3;
} else { } else {
willRetryConnectCount = 1; willRetryConnectCount = 1;
} }
...@@ -217,6 +220,7 @@ public class TcpConnection extends PyroClientAdapter { ...@@ -217,6 +220,7 @@ public class TcpConnection extends PyroClientAdapter {
firstPacket = true; firstPacket = true;
restOfTheData = null; restOfTheData = null;
channelToken = 0; channelToken = 0;
wasConnected = false;
} }
public void suspendConnection(boolean task) { public void suspendConnection(boolean task) {
...@@ -306,7 +310,7 @@ public class TcpConnection extends PyroClientAdapter { ...@@ -306,7 +310,7 @@ public class TcpConnection extends PyroClientAdapter {
Datacenter datacenter = ConnectionsManager.Instance.datacenterWithId(datacenterId); Datacenter datacenter = ConnectionsManager.Instance.datacenterWithId(datacenterId);
datacenter.storeCurrentAddressAndPortNum(); datacenter.storeCurrentAddressAndPortNum();
isNextPort = false; isNextPort = false;
client.setTimeout(35000); client.setTimeout(20000);
} }
hasSomeDataSinceLastConnect = true; hasSomeDataSinceLastConnect = true;
...@@ -407,7 +411,7 @@ public class TcpConnection extends PyroClientAdapter { ...@@ -407,7 +411,7 @@ public class TcpConnection extends PyroClientAdapter {
} }
} }
public void handleDisconnect(PyroClient client, Exception e) { public void handleDisconnect(PyroClient client, Exception e, boolean timedout) {
synchronized (timerSync) { synchronized (timerSync) {
if (reconnectTimer != null) { if (reconnectTimer != null) {
reconnectTimer.cancel(); reconnectTimer.cancel();
...@@ -419,9 +423,11 @@ public class TcpConnection extends PyroClientAdapter { ...@@ -419,9 +423,11 @@ public class TcpConnection extends PyroClientAdapter {
} else { } else {
FileLog.d("tmessages", "Disconnected " + TcpConnection.this); FileLog.d("tmessages", "Disconnected " + TcpConnection.this);
} }
boolean swirchToNextPort = wasConnected && hasSomeDataSinceLastConnect;
firstPacket = true; firstPacket = true;
restOfTheData = null; restOfTheData = null;
channelToken = 0; channelToken = 0;
wasConnected = false;
if (connectionState != TcpConnectionState.TcpConnectionStageSuspended && connectionState != TcpConnectionState.TcpConnectionStageIdle) { if (connectionState != TcpConnectionState.TcpConnectionStageSuspended && connectionState != TcpConnectionState.TcpConnectionStageIdle) {
connectionState = TcpConnectionState.TcpConnectionStageIdle; connectionState = TcpConnectionState.TcpConnectionStageIdle;
} }
...@@ -446,7 +452,7 @@ public class TcpConnection extends PyroClientAdapter { ...@@ -446,7 +452,7 @@ public class TcpConnection extends PyroClientAdapter {
} }
if (ConnectionsManager.isNetworkOnline()) { if (ConnectionsManager.isNetworkOnline()) {
isNextPort = true; isNextPort = true;
if (failedConnectionCount > willRetryConnectCount) { if (failedConnectionCount > willRetryConnectCount || swirchToNextPort) {
Datacenter datacenter = ConnectionsManager.Instance.datacenterWithId(datacenterId); Datacenter datacenter = ConnectionsManager.Instance.datacenterWithId(datacenterId);
datacenter.nextAddressOrPort(); datacenter.nextAddressOrPort();
failedConnectionCount = 0; failedConnectionCount = 0;
...@@ -486,6 +492,7 @@ public class TcpConnection extends PyroClientAdapter { ...@@ -486,6 +492,7 @@ public class TcpConnection extends PyroClientAdapter {
public void connectedClient(PyroClient client) { public void connectedClient(PyroClient client) {
connectionState = TcpConnectionState.TcpConnectionStageConnected; connectionState = TcpConnectionState.TcpConnectionStageConnected;
channelToken = generateChannelToken(); channelToken = generateChannelToken();
wasConnected = true;
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; final TcpConnectionDelegate finalDelegate = delegate;
...@@ -500,18 +507,18 @@ public class TcpConnection extends PyroClientAdapter { ...@@ -500,18 +507,18 @@ public class TcpConnection extends PyroClientAdapter {
@Override @Override
public void unconnectableClient(PyroClient client, Exception cause) { public void unconnectableClient(PyroClient client, Exception cause) {
handleDisconnect(client, cause); handleDisconnect(client, cause, false);
} }
@Override @Override
public void droppedClient(PyroClient client, IOException cause) { public void droppedClient(PyroClient client, IOException cause) {
super.droppedClient(client, cause); super.droppedClient(client, cause);
handleDisconnect(client, cause); handleDisconnect(client, cause, (cause instanceof SocketTimeoutException));
} }
@Override @Override
public void disconnectedClient(PyroClient client) { public void disconnectedClient(PyroClient client) {
handleDisconnect(client, null); handleDisconnect(client, null, false);
} }
@Override @Override
...@@ -527,7 +534,5 @@ public class TcpConnection extends PyroClientAdapter { ...@@ -527,7 +534,5 @@ public class TcpConnection extends PyroClientAdapter {
@Override @Override
public void sentData(PyroClient client, int bytes) { public void sentData(PyroClient client, int bytes) {
failedConnectionCount = 0;
FileLog.d("tmessages", TcpConnection.this + " bytes sent " + bytes);
} }
} }
...@@ -27,6 +27,7 @@ public class UserConfig { ...@@ -27,6 +27,7 @@ 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;
...@@ -54,6 +55,7 @@ public class UserConfig { ...@@ -54,6 +55,7 @@ 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();
...@@ -69,6 +71,7 @@ public class UserConfig { ...@@ -69,6 +71,7 @@ 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");
} }
...@@ -102,7 +105,7 @@ public class UserConfig { ...@@ -102,7 +105,7 @@ public class UserConfig {
lastSendMessageId = data.readInt32(); lastSendMessageId = data.readInt32();
lastLocalId = data.readInt32(); lastLocalId = data.readInt32();
contactsHash = data.readString(); contactsHash = data.readString();
data.readString(); importHash = 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) {
...@@ -136,6 +139,7 @@ public class UserConfig { ...@@ -136,6 +139,7 @@ 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) {
...@@ -160,6 +164,7 @@ public class UserConfig { ...@@ -160,6 +164,7 @@ 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) {
...@@ -185,6 +190,7 @@ public class UserConfig { ...@@ -185,6 +190,7 @@ public class UserConfig {
currentUser = null; currentUser = null;
registeredForPush = false; registeredForPush = false;
contactsHash = ""; contactsHash = "";
importHash = "";
lastLocalId = -210000; lastLocalId = -210000;
lastSendMessageId = -210000; lastSendMessageId = -210000;
saveIncomingPhotos = false; saveIncomingPhotos = false;
......
...@@ -749,9 +749,9 @@ public class Utilities { ...@@ -749,9 +749,9 @@ public class Utilities {
return storageDir; return storageDir;
} }
public static String getPath(final Context context, final Uri uri) { public static String getPath(final Uri uri) {
final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT; final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) { if (isKitKat && DocumentsContract.isDocumentUri(ApplicationLoader.applicationContext, uri)) {
if (isExternalStorageDocument(uri)) { if (isExternalStorageDocument(uri)) {
final String docId = DocumentsContract.getDocumentId(uri); final String docId = DocumentsContract.getDocumentId(uri);
final String[] split = docId.split(":"); final String[] split = docId.split(":");
...@@ -762,7 +762,7 @@ public class Utilities { ...@@ -762,7 +762,7 @@ public class Utilities {
} else if (isDownloadsDocument(uri)) { } else if (isDownloadsDocument(uri)) {
final String id = DocumentsContract.getDocumentId(uri); final String id = DocumentsContract.getDocumentId(uri);
final Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(id)); final Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
return getDataColumn(context, contentUri, null, null); return getDataColumn(ApplicationLoader.applicationContext, contentUri, null, null);
} else if (isMediaDocument(uri)) { } else if (isMediaDocument(uri)) {
final String docId = DocumentsContract.getDocumentId(uri); final String docId = DocumentsContract.getDocumentId(uri);
final String[] split = docId.split(":"); final String[] split = docId.split(":");
...@@ -782,10 +782,10 @@ public class Utilities { ...@@ -782,10 +782,10 @@ public class Utilities {
split[1] split[1]
}; };
return getDataColumn(context, contentUri, selection, selectionArgs); return getDataColumn(ApplicationLoader.applicationContext, contentUri, selection, selectionArgs);
} }
} else if ("content".equalsIgnoreCase(uri.getScheme())) { } else if ("content".equalsIgnoreCase(uri.getScheme())) {
return getDataColumn(context, uri, null, null); return getDataColumn(ApplicationLoader.applicationContext, uri, null, null);
} else if ("file".equalsIgnoreCase(uri.getScheme())) { } else if ("file".equalsIgnoreCase(uri.getScheme())) {
return uri.getPath(); return uri.getPath();
} }
......
...@@ -22,7 +22,6 @@ import org.telegram.ui.ApplicationLoader; ...@@ -22,7 +22,6 @@ import org.telegram.ui.ApplicationLoader;
import java.util.AbstractMap; import java.util.AbstractMap;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
public class MessageObject { public class MessageObject {
...@@ -303,6 +302,8 @@ public class MessageObject { ...@@ -303,6 +302,8 @@ public class MessageObject {
return getAttachFileName(messageOwner.media.video); return getAttachFileName(messageOwner.media.video);
} else if (messageOwner.media instanceof TLRPC.TL_messageMediaDocument) { } else if (messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
return getAttachFileName(messageOwner.media.document); return getAttachFileName(messageOwner.media.document);
} else if (messageOwner.media instanceof TLRPC.TL_messageMediaAudio) {
return getAttachFileName(messageOwner.media.audio);
} }
return ""; return "";
} }
...@@ -328,6 +329,9 @@ public class MessageObject { ...@@ -328,6 +329,9 @@ public class MessageObject {
} else if (attach instanceof TLRPC.PhotoSize) { } else if (attach instanceof TLRPC.PhotoSize) {
TLRPC.PhotoSize photo = (TLRPC.PhotoSize)attach; TLRPC.PhotoSize photo = (TLRPC.PhotoSize)attach;
return photo.location.volume_id + "_" + photo.location.local_id + ".jpg"; return photo.location.volume_id + "_" + photo.location.local_id + ".jpg";
} else if (attach instanceof TLRPC.Audio) {
TLRPC.Audio audio = (TLRPC.Audio)attach;
return audio.dc_id + "_" + audio.id + ".m4a";
} }
return ""; return "";
} }
......
...@@ -11,6 +11,7 @@ package org.telegram.ui; ...@@ -11,6 +11,7 @@ package org.telegram.ui;
import android.app.Activity; import android.app.Activity;
import android.app.Application; import android.app.Application;
import android.content.Context; import android.content.Context;
import android.content.Intent;
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;
...@@ -25,6 +26,7 @@ import com.google.android.gms.common.GooglePlayServicesUtil; ...@@ -25,6 +26,7 @@ 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.messenger.BackgroundService;
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;
...@@ -60,6 +62,7 @@ public class ApplicationLoader extends Application { ...@@ -60,6 +62,7 @@ public class ApplicationLoader extends Application {
@Override @Override
public void onCreate() { public void onCreate() {
super.onCreate(); super.onCreate();
currentLocale = Locale.getDefault(); currentLocale = Locale.getDefault();
Instance = this; Instance = this;
...@@ -130,6 +133,8 @@ public class ApplicationLoader extends Application { ...@@ -130,6 +133,8 @@ public class ApplicationLoader extends Application {
lastPauseTime = System.currentTimeMillis(); lastPauseTime = System.currentTimeMillis();
FileLog.e("tmessages", "start application with time " + lastPauseTime); FileLog.e("tmessages", "start application with time " + lastPauseTime);
startService(new Intent(this, BackgroundService.class));
} }
@Override @Override
......
/*
* 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.util.AttributeSet;
public class ChatMessageCell extends BaseCell {
public ChatMessageCell(Context context) {
super(context);
}
public ChatMessageCell(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ChatMessageCell(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
}
...@@ -393,7 +393,7 @@ public class ChatOrUserCell extends BaseCell { ...@@ -393,7 +393,7 @@ public class ChatOrUserCell extends BaseCell {
if (value == 0) { if (value == 0) {
value = user.status.expires; value = user.status.expires;
} }
onlineString = getResources().getString(R.string.LastSeen) + " " + Utilities.formatDateOnline(value); onlineString = Utilities.formatDateOnline(value);
} }
} }
} }
......
...@@ -394,18 +394,22 @@ public class DialogCell extends BaseCell { ...@@ -394,18 +394,22 @@ public class DialogCell extends BaseCell {
if (encryptedChat instanceof TLRPC.TL_encryptedChatRequested) { if (encryptedChat instanceof TLRPC.TL_encryptedChatRequested) {
messageString = ApplicationLoader.applicationContext.getString(R.string.EncryptionProcessing); messageString = ApplicationLoader.applicationContext.getString(R.string.EncryptionProcessing);
} else if (encryptedChat instanceof TLRPC.TL_encryptedChatWaiting) { } else if (encryptedChat instanceof TLRPC.TL_encryptedChatWaiting) {
if (user != null && user.first_name != null) {
messageString = String.format(ApplicationLoader.applicationContext.getString(R.string.AwaitingEncryption), user.first_name); messageString = String.format(ApplicationLoader.applicationContext.getString(R.string.AwaitingEncryption), user.first_name);
} else {
messageString = String.format(ApplicationLoader.applicationContext.getString(R.string.AwaitingEncryption), "");
}
} else if (encryptedChat instanceof TLRPC.TL_encryptedChatDiscarded) { } else if (encryptedChat instanceof TLRPC.TL_encryptedChatDiscarded) {
messageString = ApplicationLoader.applicationContext.getString(R.string.EncryptionRejected); messageString = ApplicationLoader.applicationContext.getString(R.string.EncryptionRejected);
} else if (encryptedChat instanceof TLRPC.TL_encryptedChat) { } else if (encryptedChat instanceof TLRPC.TL_encryptedChat) {
if (encryptedChat.admin_id == UserConfig.clientUserId) { if (encryptedChat.admin_id == UserConfig.clientUserId) {
if (user != null) { if (user != null && user.first_name != null) {
messageString = String.format(ApplicationLoader.applicationContext.getString(R.string.EncryptedChatStartedOutgoing), user.first_name); messageString = String.format(ApplicationLoader.applicationContext.getString(R.string.EncryptedChatStartedOutgoing), user.first_name);
}
} else { } else {
if (user != null) { messageString = String.format(ApplicationLoader.applicationContext.getString(R.string.EncryptedChatStartedOutgoing), "");
messageString = String.format(ApplicationLoader.applicationContext.getString(R.string.EncryptedChatStartedIncoming), user.first_name);
} }
} else {
messageString = ApplicationLoader.applicationContext.getString(R.string.EncryptedChatStartedIncoming);
} }
} }
} }
......
...@@ -8,10 +8,12 @@ ...@@ -8,10 +8,12 @@
package org.telegram.ui; package org.telegram.ui;
import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.internal.view.SupportMenuItem; import android.support.v4.internal.view.SupportMenuItem;
...@@ -30,12 +32,15 @@ import android.widget.BaseAdapter; ...@@ -30,12 +32,15 @@ import android.widget.BaseAdapter;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import org.telegram.TL.TLObject;
import org.telegram.TL.TLRPC; import org.telegram.TL.TLRPC;
import org.telegram.messenger.ConnectionsManager;
import org.telegram.messenger.ContactsController; import org.telegram.messenger.ContactsController;
import org.telegram.messenger.FileLog; import org.telegram.messenger.FileLog;
import org.telegram.messenger.MessagesController; import org.telegram.messenger.MessagesController;
import org.telegram.messenger.NotificationCenter; import org.telegram.messenger.NotificationCenter;
import org.telegram.messenger.R; import org.telegram.messenger.R;
import org.telegram.messenger.RPCRequest;
import org.telegram.messenger.UserConfig; import org.telegram.messenger.UserConfig;
import org.telegram.messenger.Utilities; import org.telegram.messenger.Utilities;
import org.telegram.ui.Cells.ChatOrUserCell; import org.telegram.ui.Cells.ChatOrUserCell;
...@@ -48,6 +53,7 @@ import java.lang.reflect.Field; ...@@ -48,6 +53,7 @@ import java.lang.reflect.Field;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Locale;
import java.util.Timer; import java.util.Timer;
import java.util.TimerTask; import java.util.TimerTask;
...@@ -70,6 +76,8 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter ...@@ -70,6 +76,8 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
private SupportMenuItem searchItem; private SupportMenuItem searchItem;
private Timer searchDialogsTimer; private Timer searchDialogsTimer;
private String inviteText;
private boolean updatingInviteText = false;
public ArrayList<TLRPC.User> searchResult; public ArrayList<TLRPC.User> searchResult;
public ArrayList<CharSequence> searchResultNames; public ArrayList<CharSequence> searchResultNames;
public ContactsActivityDelegate delegate; public ContactsActivityDelegate delegate;
...@@ -95,6 +103,15 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter ...@@ -95,6 +103,15 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
ignoreUsers = (HashMap<Integer, TLRPC.User>)NotificationCenter.Instance.getFromMemCache(7); ignoreUsers = (HashMap<Integer, TLRPC.User>)NotificationCenter.Instance.getFromMemCache(7);
} }
} }
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
inviteText = preferences.getString("invitetext", null);
int time = preferences.getInt("invitetexttime", 0);
if (inviteText == null || time + 86400 < (int)(System.currentTimeMillis() / 1000)) {
updateInviteText();
}
return true; return true;
} }
...@@ -165,14 +182,20 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter ...@@ -165,14 +182,20 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
} else { } else {
int section = listViewAdapter.getSectionForPosition(i); int section = listViewAdapter.getSectionForPosition(i);
int row = listViewAdapter.getPositionInSectionForPosition(i); int row = listViewAdapter.getPositionInSectionForPosition(i);
if (row < 0 || section < 0) {
return;
}
TLRPC.User user = null; TLRPC.User user = null;
if (usersAsSections) { if (usersAsSections) {
if (section < ContactsController.Instance.sortedUsersSectionsArray.size()) { if (section < ContactsController.Instance.sortedUsersSectionsArray.size()) {
ArrayList<TLRPC.TL_contact> arr = ContactsController.Instance.usersSectionsDict.get(ContactsController.Instance.sortedUsersSectionsArray.get(section)); ArrayList<TLRPC.TL_contact> arr = ContactsController.Instance.usersSectionsDict.get(ContactsController.Instance.sortedUsersSectionsArray.get(section));
if (row >= arr.size()) { if (row < arr.size()) {
TLRPC.TL_contact contact = arr.get(row);
user = MessagesController.Instance.users.get(contact.user_id);
} else {
return; return;
} }
user = MessagesController.Instance.users.get(arr.get(row).user_id);
} }
} else { } else {
if (section == 0) { if (section == 0) {
...@@ -180,7 +203,7 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter ...@@ -180,7 +203,7 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
try { try {
Intent intent = new Intent(Intent.ACTION_SEND); Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain"); intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, getStringEntry(R.string.InviteText)); intent.putExtra(Intent.EXTRA_TEXT, inviteText != null ? inviteText : getStringEntry(R.string.InviteText));
startActivity(intent); startActivity(intent);
} catch (Exception e) { } catch (Exception e) {
FileLog.e("tmessages", e); FileLog.e("tmessages", e);
...@@ -554,6 +577,41 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter ...@@ -554,6 +577,41 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
} }
} }
private void updateInviteText() {
if (updatingInviteText) {
return;
}
updatingInviteText = true;
TLRPC.TL_help_getInviteText req = new TLRPC.TL_help_getInviteText();
req.lang_code = Locale.getDefault().getCountry();
if (req.lang_code == null || req.lang_code.length() == 0) {
req.lang_code = "en";
}
ConnectionsManager.Instance.performRpc(req, new RPCRequest.RPCRequestDelegate() {
@Override
public void run(TLObject response, TLRPC.TL_error error) {
if (error != null) {
return;
}
final TLRPC.TL_help_inviteText res = (TLRPC.TL_help_inviteText)response;
if (res.message.length() == 0) {
return;
}
Utilities.RunOnUIThread(new Runnable() {
@Override
public void run() {
updatingInviteText = false;
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putString("invitetext", res.message);
editor.putInt("invitetexttime", (int) (System.currentTimeMillis() / 1000));
editor.commit();
}
});
}
}, null, true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassFailOnServerErrors);
}
private void updateVisibleRows(int mask) { private void updateVisibleRows(int mask) {
if (listView == null) { if (listView == null) {
return; return;
......
...@@ -67,6 +67,7 @@ public class GalleryImageViewer extends AbstractGalleryActivity implements Notif ...@@ -67,6 +67,7 @@ public class GalleryImageViewer extends AbstractGalleryActivity implements Notif
private String currentFileName; private String currentFileName;
private int user_id = 0; private int user_id = 0;
private Point displaySize = new Point(); private Point displaySize = new Point();
private boolean cancelRunning = false;
private ArrayList<MessageObject> imagesArrTemp = new ArrayList<MessageObject>(); private ArrayList<MessageObject> imagesArrTemp = new ArrayList<MessageObject>();
private HashMap<Integer, MessageObject> imagesByIdsTemp = new HashMap<Integer, MessageObject>(); private HashMap<Integer, MessageObject> imagesByIdsTemp = new HashMap<Integer, MessageObject>();
...@@ -224,7 +225,7 @@ public class GalleryImageViewer extends AbstractGalleryActivity implements Notif ...@@ -224,7 +225,7 @@ public class GalleryImageViewer extends AbstractGalleryActivity implements Notif
deleteButton.setOnClickListener(new View.OnClickListener() { deleteButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
if (mViewPager == null) { if (mViewPager == null || localPagerAdapter == null || localPagerAdapter.imagesArr == null) {
return; return;
} }
int item = mViewPager.getCurrentItem(); int item = mViewPager.getCurrentItem();
...@@ -645,9 +646,20 @@ public class GalleryImageViewer extends AbstractGalleryActivity implements Notif ...@@ -645,9 +646,20 @@ public class GalleryImageViewer extends AbstractGalleryActivity implements Notif
} }
} }
@Override
public void onBackPressed() {
super.onBackPressed();
cancelRunning = true;
mViewPager.setAdapter(null);
localPagerAdapter = null;
finish();
System.gc();
}
private void processSelectedMenu(int itemId) { private void processSelectedMenu(int itemId) {
switch (itemId) { switch (itemId) {
case android.R.id.home: case android.R.id.home:
cancelRunning = true;
mViewPager.setAdapter(null); mViewPager.setAdapter(null);
localPagerAdapter = null; localPagerAdapter = null;
finish(); finish();
...@@ -958,9 +970,9 @@ public class GalleryImageViewer extends AbstractGalleryActivity implements Notif ...@@ -958,9 +970,9 @@ public class GalleryImageViewer extends AbstractGalleryActivity implements Notif
} }
if (loadFile) { if (loadFile) {
if (!FileLoader.Instance.isLoadingFile(fileName)) { if (!FileLoader.Instance.isLoadingFile(fileName)) {
FileLoader.Instance.loadFile(message.messageOwner.media.video, null, null); FileLoader.Instance.loadFile(message.messageOwner.media.video, null, null, null);
} else { } else {
FileLoader.Instance.cancelLoadFile(message.messageOwner.media.video, null, null); FileLoader.Instance.cancelLoadFile(message.messageOwner.media.video, null, null, null);
} }
checkCurrentFile(); checkCurrentFile();
processViews(playButton, message); processViews(playButton, message);
...@@ -988,7 +1000,9 @@ public class GalleryImageViewer extends AbstractGalleryActivity implements Notif ...@@ -988,7 +1000,9 @@ public class GalleryImageViewer extends AbstractGalleryActivity implements Notif
public void destroyItem(View collection, int position, Object view) { public void destroyItem(View collection, int position, Object view) {
((ViewPager)collection).removeView((View)view); ((ViewPager)collection).removeView((View)view);
PZSImageView iv = (PZSImageView)((View)view).findViewById(R.id.page_image); PZSImageView iv = (PZSImageView)((View)view).findViewById(R.id.page_image);
if (cancelRunning) {
FileLoader.Instance.cancelLoadingForImageView(iv); FileLoader.Instance.cancelLoadingForImageView(iv);
}
iv.clearImage(); iv.clearImage();
} }
......
...@@ -54,7 +54,7 @@ public class LaunchActivity extends PausableActivity { ...@@ -54,7 +54,7 @@ public class LaunchActivity extends PausableActivity {
} }
String path = null; String path = null;
if (parcelable instanceof Uri) { if (parcelable instanceof Uri) {
path = Utilities.getPath(this, (Uri)parcelable); path = Utilities.getPath((Uri)parcelable);
} else { } else {
path = intent.getParcelableExtra(Intent.EXTRA_STREAM).toString(); path = intent.getParcelableExtra(Intent.EXTRA_STREAM).toString();
if (path.startsWith("content:")) { if (path.startsWith("content:")) {
...@@ -79,7 +79,7 @@ public class LaunchActivity extends PausableActivity { ...@@ -79,7 +79,7 @@ public class LaunchActivity extends PausableActivity {
} }
String path = null; String path = null;
if (parcelable instanceof Uri) { if (parcelable instanceof Uri) {
path = Utilities.getPath(this, (Uri)parcelable); path = Utilities.getPath((Uri)parcelable);
} else { } else {
path = parcelable.toString(); path = parcelable.toString();
if (path.startsWith("content:")) { if (path.startsWith("content:")) {
......
...@@ -253,7 +253,9 @@ public class LoginActivityPhoneView extends SlideView implements AdapterView.OnI ...@@ -253,7 +253,9 @@ public class LoginActivityPhoneView extends SlideView implements AdapterView.OnI
public void selectCountry(String name) { public void selectCountry(String name) {
int index = countriesArray.indexOf(name); int index = countriesArray.indexOf(name);
if (index != -1) { if (index != -1) {
ignoreOnTextChange = true;
codeField.setText(countriesMap.get(name)); codeField.setText(countriesMap.get(name));
countryButton.setText(name);
} }
} }
......
...@@ -246,11 +246,11 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica ...@@ -246,11 +246,11 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica
progressBar.setVisibility(View.VISIBLE); progressBar.setVisibility(View.VISIBLE);
loadingSize = size; loadingSize = size;
selectedColor = 0; selectedColor = 0;
FileLoader.Instance.loadFile(null, size, null); FileLoader.Instance.loadFile(null, size, null, null);
backgroundImage.setBackgroundColor(0); backgroundImage.setBackgroundColor(0);
} else { } else {
if (loadingFile != null) { if (loadingFile != null) {
FileLoader.Instance.cancelLoadFile(null, loadingSize, null); FileLoader.Instance.cancelLoadFile(null, loadingSize, null, null);
} }
loadingFileObject = null; loadingFileObject = null;
loadingFile = null; loadingFile = null;
...@@ -263,7 +263,7 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica ...@@ -263,7 +263,7 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica
} }
} else { } else {
if (loadingFile != null) { if (loadingFile != null) {
FileLoader.Instance.cancelLoadFile(null, loadingSize, null); FileLoader.Instance.cancelLoadFile(null, loadingSize, null, null);
} }
if (selectedBackground == 1000001) { if (selectedBackground == 1000001) {
backgroundImage.setImageResource(R.drawable.background_hd); backgroundImage.setImageResource(R.drawable.background_hd);
......
...@@ -78,7 +78,7 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen ...@@ -78,7 +78,7 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen
if (dialog_id != 0) { if (dialog_id != 0) {
currentEncryptedChat = MessagesController.Instance.encryptedChats.get((int)(dialog_id >> 32)); currentEncryptedChat = MessagesController.Instance.encryptedChats.get((int)(dialog_id >> 32));
} }
return true; return MessagesController.Instance.users.get(user_id) != null;
} }
@Override @Override
...@@ -471,16 +471,10 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen ...@@ -471,16 +471,10 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen
builder.setPositiveButton(getStringEntry(R.string.OK), new DialogInterface.OnClickListener() { builder.setPositiveButton(getStringEntry(R.string.OK), new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialogInterface, int i) { public void onClick(DialogInterface dialogInterface, int i) {
TLRPC.TL_auth_resetAuthorizations req = new TLRPC.TL_auth_resetAuthorizations();
ConnectionsManager.Instance.performRpc(req, new RPCRequest.RPCRequestDelegate() {
@Override
public void run(TLObject response, TLRPC.TL_error error) {
ArrayList<TLRPC.User> arrayList = new ArrayList<TLRPC.User>(); ArrayList<TLRPC.User> arrayList = new ArrayList<TLRPC.User>();
arrayList.add(user); arrayList.add(user);
ContactsController.Instance.deleteContact(arrayList); ContactsController.Instance.deleteContact(arrayList);
} }
}, null, true, RPCRequest.RPCRequestClassGeneric);
}
}); });
builder.setNegativeButton(getStringEntry(R.string.Cancel), null); builder.setNegativeButton(getStringEntry(R.string.Cancel), null);
builder.show().setCanceledOnTouchOutside(true); builder.show().setCanceledOnTouchOutside(true);
......
...@@ -10,11 +10,10 @@ package org.telegram.ui.Views; ...@@ -10,11 +10,10 @@ package org.telegram.ui.Views;
import android.app.Activity; import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore; import android.provider.MediaStore;
import android.support.v4.app.Fragment;
import org.telegram.TL.TLRPC; import org.telegram.TL.TLRPC;
import org.telegram.messenger.FileLoader; import org.telegram.messenger.FileLoader;
...@@ -22,17 +21,19 @@ import org.telegram.messenger.FileLog; ...@@ -22,17 +21,19 @@ import org.telegram.messenger.FileLog;
import org.telegram.messenger.NotificationCenter; import org.telegram.messenger.NotificationCenter;
import org.telegram.messenger.UserConfig; import org.telegram.messenger.UserConfig;
import org.telegram.messenger.Utilities; import org.telegram.messenger.Utilities;
import org.telegram.ui.ApplicationActivity;
import org.telegram.ui.PhotoCropActivity;
import java.io.File; import java.io.File;
public class AvatarUpdater implements NotificationCenter.NotificationCenterDelegate { public class AvatarUpdater implements NotificationCenter.NotificationCenterDelegate, PhotoCropActivity.PhotoCropActivityDelegate {
public String currentPicturePath; public String currentPicturePath;
private TLRPC.PhotoSize smallPhoto; private TLRPC.PhotoSize smallPhoto;
private TLRPC.PhotoSize bigPhoto; private TLRPC.PhotoSize bigPhoto;
public String uploadingAvatar = null; public String uploadingAvatar = null;
File picturePath = null; File picturePath = null;
public Activity parentActivity = null; public Activity parentActivity = null;
public Fragment parentFragment = null; public BaseFragment parentFragment = null;
public AvatarUpdaterDelegate delegate; public AvatarUpdaterDelegate delegate;
private boolean clearAfterUpdate = false; private boolean clearAfterUpdate = false;
public boolean returnOnly = false; public boolean returnOnly = false;
...@@ -85,6 +86,21 @@ public class AvatarUpdater implements NotificationCenter.NotificationCenterDeleg ...@@ -85,6 +86,21 @@ public class AvatarUpdater implements NotificationCenter.NotificationCenterDeleg
private void startCrop(String path) { private void startCrop(String path) {
try { try {
if (parentFragment != null) {
ApplicationActivity activity = (ApplicationActivity)parentFragment.parentActivity;
if (activity == null) {
activity = (ApplicationActivity)parentFragment.getActivity();
}
if (activity == null) {
return;
}
Bundle params = new Bundle();
params.putString("photoPath", path);
PhotoCropActivity photoCropActivity = new PhotoCropActivity();
photoCropActivity.delegate = this;
photoCropActivity.setArguments(params);
activity.presentFragment(photoCropActivity, "crop", false);
} else {
Intent cropIntent = new Intent("com.android.camera.action.CROP"); Intent cropIntent = new Intent("com.android.camera.action.CROP");
cropIntent.setDataAndType(Uri.fromFile(new File(path)), "image/*"); cropIntent.setDataAndType(Uri.fromFile(new File(path)), "image/*");
cropIntent.putExtra("crop", "true"); cropIntent.putExtra("crop", "true");
...@@ -102,6 +118,7 @@ public class AvatarUpdater implements NotificationCenter.NotificationCenterDeleg ...@@ -102,6 +118,7 @@ public class AvatarUpdater implements NotificationCenter.NotificationCenterDeleg
} else if (parentActivity != null) { } else if (parentActivity != null) {
parentActivity.startActivityForResult(cropIntent, 2); parentActivity.startActivityForResult(cropIntent, 2);
} }
}
} catch (Exception e) { } catch (Exception e) {
FileLog.e("tmessages", e); FileLog.e("tmessages", e);
Bitmap bitmap = FileLoader.loadBitmap(path, 800, 800); Bitmap bitmap = FileLoader.loadBitmap(path, 800, 800);
...@@ -120,26 +137,15 @@ public class AvatarUpdater implements NotificationCenter.NotificationCenterDeleg ...@@ -120,26 +137,15 @@ public class AvatarUpdater implements NotificationCenter.NotificationCenterDeleg
if (data == null) { if (data == null) {
return; return;
} }
Uri imageUri = data.getData();
Cursor cursor = null;
try { try {
if (parentFragment != null) { Uri imageUri = data.getData();
cursor = parentFragment.getActivity().getContentResolver().query(imageUri, new String[]{android.provider.MediaStore.Images.ImageColumns.DATA}, null, null, null); if (imageUri != null) {
} else if (parentActivity != null) { String imageFilePath = Utilities.getPath(imageUri);
cursor = parentActivity.getContentResolver().query(imageUri, new String[]{android.provider.MediaStore.Images.ImageColumns.DATA}, null, null, null); startCrop(imageFilePath);
} }
} catch (Exception e) { } catch (Exception e) {
FileLog.e("tmessages", e); FileLog.e("tmessages", e);
return;
}
if (cursor == null) {
return;
}
if (cursor.moveToFirst()) {
String imageFilePath = cursor.getString(0);
startCrop(imageFilePath);
} }
cursor.close();
} else if (requestCode == 2) { } else if (requestCode == 2) {
Bitmap bitmap = FileLoader.loadBitmap(picturePath.getAbsolutePath(), 800, 800); Bitmap bitmap = FileLoader.loadBitmap(picturePath.getAbsolutePath(), 800, 800);
processBitmap(bitmap); processBitmap(bitmap);
...@@ -168,6 +174,11 @@ public class AvatarUpdater implements NotificationCenter.NotificationCenterDeleg ...@@ -168,6 +174,11 @@ public class AvatarUpdater implements NotificationCenter.NotificationCenterDeleg
} }
} }
@Override
public void didFinishCrop(Bitmap bitmap) {
processBitmap(bitmap);
}
@Override @Override
public void didReceivedNotification(int id, final Object... args) { public void didReceivedNotification(int id, final Object... args) {
if (id == FileLoader.FileDidUpload) { if (id == FileLoader.FileDidUpload) {
......
...@@ -40,11 +40,19 @@ public class LayoutListView extends ListView { ...@@ -40,11 +40,19 @@ public class LayoutListView extends ListView {
post(new Runnable() { post(new Runnable() {
@Override @Override
public void run() { public void run() {
try {
setSelectionFromTop(scrollTo, offset - getPaddingTop()); setSelectionFromTop(scrollTo, offset - getPaddingTop());
} catch (Exception e) {
e.printStackTrace();
}
} }
}); });
} else { } else {
try {
super.onLayout(changed, left, top, right, bottom); super.onLayout(changed, left, top, right, bottom);
} catch (Exception e) {
e.printStackTrace();
}
} }
height = (bottom - top); height = (bottom - top);
} }
......
/*
* 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.Views;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import org.telegram.messenger.R;
import org.telegram.messenger.Utilities;
public class SeekBar extends View {
Drawable thumbDrawable1;
Drawable thumbDrawablePressed1;
Drawable thumbDrawable2;
Drawable thumbDrawablePressed2;
static Paint innerPaint1 = new Paint();
static Paint outerPaint1 = new Paint();
static Paint innerPaint2 = new Paint();
static Paint outerPaint2 = new Paint();
public int type;
public int thumbX = 0;
public int thumbDX = 0;
private boolean pressed = false;
private boolean dragging = false;
private int thumbWidth;
private int thumbHeight;
public SeekBar(Context context) {
super(context);
init();
}
public SeekBar(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public SeekBar(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
private void init() {
if (thumbDrawable1 == null) {
thumbDrawable1 = getResources().getDrawable(R.drawable.player1);
thumbDrawablePressed1 = getResources().getDrawable(R.drawable.player1_pressed);
thumbDrawable2 = getResources().getDrawable(R.drawable.player2);
thumbDrawablePressed2 = getResources().getDrawable(R.drawable.player2_pressed);
innerPaint1.setColor(0xffb4e396);
outerPaint1.setColor(0xff6ac453);
innerPaint2.setColor(0xffd9e2eb);
outerPaint2.setColor(0xff86c5f8);
thumbWidth = thumbDrawable1.getIntrinsicWidth();
thumbHeight = thumbDrawable1.getIntrinsicHeight();
}
setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
float x = motionEvent.getX();
float y = motionEvent.getY();
if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
int additionWidth = (getMeasuredHeight() - thumbWidth) / 2;
if (thumbX - additionWidth <= x && x <= thumbX + thumbWidth + additionWidth && y >= 0 && y <= getMeasuredHeight()) {
pressed = true;
thumbDX = (int)(x - thumbX);
invalidate();
getParent().requestDisallowInterceptTouchEvent(true);
return true;
}
} else if (motionEvent.getAction() == MotionEvent.ACTION_UP || motionEvent.getAction() == MotionEvent.ACTION_CANCEL) {
if (pressed) {
pressed = false;
invalidate();
return true;
}
} else if (motionEvent.getAction() == MotionEvent.ACTION_MOVE) {
if (pressed) {
thumbX = (int)(x - thumbDX);
if (thumbX < 0) {
thumbX = 0;
} else if (thumbX > getMeasuredWidth() - thumbWidth) {
thumbX = getMeasuredWidth() - thumbWidth;
}
invalidate();
return true;
}
}
return false;
}
});
}
@Override
protected void onDraw(Canvas canvas) {
Drawable thumb = null;
Paint inner = null;
Paint outer = null;
if (type == 0) {
if (!pressed) {
thumb = thumbDrawable1;
} else {
thumb = thumbDrawablePressed1;
}
inner = innerPaint1;
outer = outerPaint1;
} else if (type == 1) {
if (!pressed) {
thumb = thumbDrawable2;
} else {
thumb = thumbDrawablePressed2;
}
inner = innerPaint2;
outer = outerPaint2;
}
int height = getMeasuredHeight();
int width = getMeasuredWidth();
int y = (height - thumbHeight) / 2;
canvas.drawRect(thumbWidth / 2, height / 2 - Utilities.dp(1), width - thumbWidth / 2, height / 2 + Utilities.dp(1), inner);
canvas.drawRect(thumbWidth / 2, height / 2 - Utilities.dp(1), thumbWidth / 2 + thumbX, height / 2 + Utilities.dp(1), outer);
thumb.setBounds(thumbX, y, thumbX + thumbWidth, y + thumbHeight);
thumb.draw(canvas);
}
}
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.
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