update to 1.2.7

This commit is contained in:
DrKLO 2013-11-04 16:31:01 +04:00
parent 27b74b537e
commit 90d8e8a370
55 changed files with 632 additions and 468 deletions

View file

@ -32,18 +32,18 @@ tasks.withType(Compile) {
dependencies {
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar'
compile 'com.google.android.gms:play-services:3.1.+'
compile 'net.hockeyapp.android:HockeySDK:3.0.0'
compile 'com.android.support:support-v4:18.0.+'
compile 'com.google.android.gms:play-services:4.0.+'
compile 'net.hockeyapp.android:HockeySDK:3.0.1'
compile 'com.android.support:support-v4:19.0.+'
compile fileTree(dir: "$buildDir/native-libs", include: '*.jar')
}
android {
compileSdkVersion 18
buildToolsVersion "17.0.0"
compileSdkVersion 19
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 8
targetSdkVersion 18
targetSdkVersion 19
}
}

View file

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.telegram.messenger"
android:versionCode="91"
android:versionName="1.2.4">
android:versionCode="98"
android:versionName="1.2.7">
<supports-screens android:anyDensity="true"
android:smallScreens="true"
@ -11,7 +11,7 @@
android:resizeable="true"
android:xlargeScreens="true"/>
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="18" />
<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" />
@ -19,6 +19,8 @@
<uses-feature android:name="android.hardware.location.network" android:required="false" />
<uses-feature android:name="android.hardware.location" android:required="false" />
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false" />
<uses-feature android:name="android.hardware.camera" android:required="false" />
<uses-feature android:name="android.hardware.wifi" android:required="false" />
<uses-feature android:name="android.hardware.LOCATION" android:required="false" />
<uses-permission android:name="android.permission.INTERNET" />

View file

@ -228,7 +228,6 @@
31;NL;Netherlands
30;GR;Greece
27;ZA;South Africa
21;DZ;Algeria
20;EG;Egypt
7;KZ;Kazakhstan
7;RU;Russia

View file

@ -24,7 +24,7 @@
package org.telegram.PhoneFormat;
import org.telegram.messenger.Utilities;
import org.telegram.ui.ApplicationLoader;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
@ -78,7 +78,7 @@ public class PhoneFormat {
public void init(String countryCode) {
try {
InputStream stream = Utilities.applicationContext.getAssets().open("PhoneFormats.dat");
InputStream stream = ApplicationLoader.applicationContext.getAssets().open("PhoneFormats.dat");
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] buf = new byte[1024];
int len;

View file

@ -150,7 +150,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
Utilities.stageQueue.postRunnable(new Runnable() {
@Override
public void run() {
File configFile = new File(Utilities.applicationContext.getFilesDir(), "config.dat");
File configFile = new File(ApplicationLoader.applicationContext.getFilesDir(), "config.dat");
if (configFile.exists()) {
try {
SerializedData data = new SerializedData(configFile);
@ -235,7 +235,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
data.writeInt32(0);
}
try {
File configFile = new File(Utilities.applicationContext.getFilesDir(), "config.dat");
File configFile = new File(ApplicationLoader.applicationContext.getFilesDir(), "config.dat");
if (!configFile.exists()) {
configFile.createNewFile();
}
@ -491,7 +491,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
public static boolean isNetworkOnline() {
boolean status = false;
try {
ConnectivityManager cm = (ConnectivityManager)Utilities.applicationContext.getSystemService(Context.CONNECTIVITY_SERVICE);
ConnectivityManager cm = (ConnectivityManager)ApplicationLoader.applicationContext.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getNetworkInfo(0);
if (netInfo != null && netInfo.getState() == NetworkInfo.State.CONNECTED) {
status = true;

View file

@ -27,6 +27,8 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import org.telegram.ui.ApplicationLoader;
public class Emoji {
private static final int[] ROW_SIZES = {27, 29, 33, 34, 34};
private static HashMap<Long, DrawableInfo> rects = new HashMap<Long, DrawableInfo>();
@ -287,7 +289,7 @@ public class Emoji {
0x00000000D83DDD34L, 0x00000000D83DDD35L, 0x00000000D83DDD3BL, 0x00000000D83DDD36L, 0x00000000D83DDD37L, 0x00000000D83DDD38L, 0x00000000D83DDD39L}};
static {
imgSize = Math.min(scale(30), Utilities.applicationContext.getResources().getDisplayMetrics().density < 1.5f ? 28 : 56);
imgSize = Math.min(scale(30), ApplicationLoader.applicationContext.getResources().getDisplayMetrics().density < 1.5f ? 28 : 56);
drawImgSize = scale(20);
bigImgSize = scale(30);
if(Math.abs(imgSize - bigImgSize) < 5) {
@ -306,7 +308,7 @@ public class Emoji {
}
public static int scale(float value) {
return (int)(Utilities.applicationContext.getResources().getDisplayMetrics().density * value);
return (int)(ApplicationLoader.applicationContext.getResources().getDisplayMetrics().density * value);
}
private static Bitmap loadPage(final int page){
@ -317,13 +319,13 @@ public class Emoji {
opts.inPreferredConfig = Bitmap.Config.ARGB_8888;
opts.inDither = false;
if (Utilities.applicationContext.getResources().getDisplayMetrics().density < 1.5f) {
if (ApplicationLoader.applicationContext.getResources().getDisplayMetrics().density < 1.5f) {
opts.inSampleSize = 2;
}
int iw, ih;
InputStream is = Utilities.applicationContext.getAssets().open("emojisprite_" + page + ".png");
InputStream is = ApplicationLoader.applicationContext.getAssets().open("emojisprite_" + page + ".png");
Bitmap color = BitmapFactory.decodeStream(is, null, opts);
is.close();
@ -559,8 +561,8 @@ public class Emoji {
int sz = super.getSize(paint, text, start, end, fm);
int offset = (int)(8 * Utilities.applicationContext.getResources().getDisplayMetrics().density);
int w = (int)(20 * Utilities.applicationContext.getResources().getDisplayMetrics().density / 2);
int offset = (int)(8 * ApplicationLoader.applicationContext.getResources().getDisplayMetrics().density);
int w = (int)(20 * ApplicationLoader.applicationContext.getResources().getDisplayMetrics().density / 2);
fm.top = -w - offset;
fm.bottom = w - offset;
fm.ascent = -w - offset;
@ -586,7 +588,7 @@ public class Emoji {
int sz = super.getSize(paint, text, start, end, fm);
int offset = (int)(6 * Utilities.applicationContext.getResources().getDisplayMetrics().density);
int offset = (int)(6 * ApplicationLoader.applicationContext.getResources().getDisplayMetrics().density);
int w = (fm.bottom - fm.top) / 2;
fm.top = -w - offset;
fm.bottom = w - offset;

View file

@ -18,6 +18,7 @@ import android.view.View;
import android.widget.ImageView;
import org.telegram.TL.TLRPC;
import org.telegram.ui.ApplicationLoader;
import org.telegram.ui.Views.BackupImageView;
import java.io.ByteArrayOutputStream;
@ -247,7 +248,7 @@ public class FileLoader {
public FileLoader() {
int maxMemory = (int)Runtime.getRuntime().maxMemory();
int cacheSize = maxMemory / 10;
density = Utilities.applicationContext.getResources().getDisplayMetrics().density;
density = ApplicationLoader.applicationContext.getResources().getDisplayMetrics().density;
if (Build.VERSION.SDK_INT < 11) {
runtimeHack = new VMRuntimeHack();
cacheSize = 1024 * 1024 * 3;

View file

@ -198,7 +198,7 @@ public class GcmBroadcastReceiver extends BroadcastReceiver {
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
.setContentTitle(Utilities.applicationContext.getString(R.string.AppName))
.setContentTitle(ApplicationLoader.applicationContext.getString(R.string.AppName))
.setSmallIcon(R.drawable.notification)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(msg))

View file

@ -39,6 +39,7 @@ import android.util.SparseArray;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import org.telegram.PhoneFormat.PhoneFormat;
import org.telegram.TL.TLClassStore;
import org.telegram.TL.TLObject;
import org.telegram.TL.TLRPC;
@ -197,7 +198,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
try {
soundPool = new SoundPool(1, AudioManager.STREAM_NOTIFICATION, 0);
sound = soundPool.load(Utilities.applicationContext, R.raw.sound_a, 1);
sound = soundPool.load(ApplicationLoader.applicationContext, R.raw.sound_a, 1);
} catch (Exception e) {
e.printStackTrace();
}
@ -364,7 +365,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}
public void checkAppAccount() {
AccountManager am = AccountManager.get(Utilities.applicationContext);
AccountManager am = AccountManager.get(ApplicationLoader.applicationContext);
Account[] accounts = am.getAccountsByType("org.telegram.messenger.account");
boolean recreateAccount = false;
if (UserConfig.currentUser != null) {
@ -460,7 +461,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
req.peer = new TLRPC.TL_inputPeerChat();
req.peer.chat_id = -lower_part;
} else {
TLRPC.User user = MessagesController.Instance.users.get(uid);
TLRPC.User user = users.get(lower_part);
if (user instanceof TLRPC.TL_userForeign || user instanceof TLRPC.TL_userRequest) {
req.peer = new TLRPC.TL_inputPeerForeign();
req.peer.access_hash = user.access_hash;
@ -518,7 +519,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
req.peer = new TLRPC.TL_inputPeerChat();
req.peer.chat_id = -lower_part;
} else {
TLRPC.User user = MessagesController.Instance.users.get(uid);
TLRPC.User user = users.get(lower_part);
if (user instanceof TLRPC.TL_userForeign || user instanceof TLRPC.TL_userRequest) {
req.peer = new TLRPC.TL_inputPeerForeign();
req.peer.access_hash = user.access_hash;
@ -562,7 +563,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
final HashMap<String, ArrayList<Contact>> sectionsDict = new HashMap<String, ArrayList<Contact>>();
final ArrayList<String> sortedSectionsArray = new ArrayList<String>();
ContentResolver cr = Utilities.applicationContext.getContentResolver();
ContentResolver cr = ApplicationLoader.applicationContext.getContentResolver();
String[] projectioPhones = {
ContactsContract.CommonDataKinds.Phone.CONTACT_ID,
@ -594,23 +595,20 @@ public class MessagesController implements NotificationCenter.NotificationCenter
contactsMap.put(id, contact);
contact.id = id;
}
number = number.replace(" ", "").replace("(", "").replace(")", "").replace("-", "").replace("+", "");
if (number.startsWith("8")) {
number = "7" + number.substring(1);
}
contact.phones.add(number);
if (type == ContactsContract.CommonDataKinds.Phone.TYPE_CUSTOM) {
contact.phoneTypes.add(pCur.getString(3));
} else if (type == ContactsContract.CommonDataKinds.Phone.TYPE_HOME) {
contact.phoneTypes.add(Utilities.applicationContext.getString(R.string.PhoneHome));
contact.phoneTypes.add(ApplicationLoader.applicationContext.getString(R.string.PhoneHome));
} else if (type == ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE) {
contact.phoneTypes.add(Utilities.applicationContext.getString(R.string.PhoneMobile));
contact.phoneTypes.add(ApplicationLoader.applicationContext.getString(R.string.PhoneMobile));
} else if (type == ContactsContract.CommonDataKinds.Phone.TYPE_WORK) {
contact.phoneTypes.add(Utilities.applicationContext.getString(R.string.PhoneWork));
contact.phoneTypes.add(ApplicationLoader.applicationContext.getString(R.string.PhoneWork));
} else if (type == ContactsContract.CommonDataKinds.Phone.TYPE_MAIN) {
contact.phoneTypes.add(Utilities.applicationContext.getString(R.string.PhoneMain));
contact.phoneTypes.add(ApplicationLoader.applicationContext.getString(R.string.PhoneMain));
} else {
contact.phoneTypes.add(Utilities.applicationContext.getString(R.string.PhoneOther));
contact.phoneTypes.add(ApplicationLoader.applicationContext.getString(R.string.PhoneOther));
}
}
}
@ -676,7 +674,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
imp.client_id = id;
imp.first_name = value.first_name;
imp.last_name = value.last_name;
imp.phone = value.phones.get(a);
imp.phone = PhoneFormat.stripExceptNumbers(value.phones.get(a));
toImport.add(imp);
String str = imp.client_id + imp.first_name + imp.last_name + imp.phone;
if (mdEnc != null) {
@ -747,7 +745,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
if (!toImport.isEmpty() && !UserConfig.importHash.equals(importHash)) {
UserConfig.importHash = importHash;
UserConfig.saveConfig();
UserConfig.saveConfig(false);
importContacts(toImport);
} else {
loadContacts(true);
@ -774,7 +772,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
try {
Uri rawContactUri = ContactsContract.RawContacts.CONTENT_URI.buildUpon().appendQueryParameter(ContactsContract.RawContacts.ACCOUNT_NAME, currentAccount.name).appendQueryParameter(
ContactsContract.RawContacts.ACCOUNT_TYPE, currentAccount.type).build();
Cursor c1 = Utilities.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>();
if (c1 != null) {
while (c1.moveToNext()) {
@ -832,7 +830,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
builder.withValue(ContactsContract.Data.DATA4, user.id);
query.add(builder.build());
try {
ContentProviderResult[] result = Utilities.applicationContext.getContentResolver().applyBatch(ContactsContract.AUTHORITY, query);
ContentProviderResult[] result = ApplicationLoader.applicationContext.getContentResolver().applyBatch(ContactsContract.AUTHORITY, query);
return Long.parseLong(result[0].uri.getLastPathSegment());
} catch (Exception e) {
e.printStackTrace();
@ -894,7 +892,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
req.peer = new TLRPC.TL_inputPeerChat();
req.peer.chat_id = -lower_part;
} else {
TLRPC.User user = MessagesController.Instance.users.get(did);
TLRPC.User user = users.get(lower_part);
if (user instanceof TLRPC.TL_userForeign || user instanceof TLRPC.TL_userRequest) {
req.peer = new TLRPC.TL_inputPeerForeign();
req.peer.access_hash = user.access_hash;
@ -911,11 +909,11 @@ public class MessagesController implements NotificationCenter.NotificationCenter
if (res.offset > 0) {
deleteDialog(did, res.offset, onlyHistory);
}
if (UserConfig.lastSeqValue + 1 == res.seq) {
UserConfig.lastSeqValue = res.seq;
UserConfig.lastPtsValue = res.pts;
UserConfig.saveConfig();
} else if (UserConfig.lastSeqValue != res.seq) {
if (MessagesStorage.lastSeqValue + 1 == res.seq) {
MessagesStorage.lastSeqValue = res.seq;
MessagesStorage.lastPtsValue = res.pts;
MessagesStorage.Instance.saveDiffParams(MessagesStorage.lastSeqValue, MessagesStorage.lastPtsValue, MessagesStorage.lastDateValue, MessagesStorage.lastQtsValue);
} else if (MessagesStorage.lastSeqValue != res.seq) {
getDifference();
}
}
@ -1057,13 +1055,13 @@ public class MessagesController implements NotificationCenter.NotificationCenter
ArrayList<Long> keys = new ArrayList<Long>(printingUsers.keySet());
for (Long key : keys) {
if (key > 0) {
newPrintingStrings.put(key, Html.fromHtml(String.format("<font color='#006fc8'>%s</font>", Utilities.applicationContext.getString(R.string.Typing))));
newPrintingStrings.put(key, Html.fromHtml(String.format("<font color='#006fc8'>%s</font>", ApplicationLoader.applicationContext.getString(R.string.Typing))));
} else {
ArrayList<PrintingUser> arr = printingUsers.get(key);
int count = 0;
String label = "";
for (PrintingUser pu : arr) {
TLRPC.User user = MessagesController.Instance.users.get(pu.userId);
TLRPC.User user = users.get(pu.userId);
if (user != null) {
if (label.length() != 0) {
label += ", ";
@ -1078,12 +1076,12 @@ public class MessagesController implements NotificationCenter.NotificationCenter
if (label.length() != 0) {
if (count > 1) {
if (arr.size() > 2) {
newPrintingStrings.put(key, Html.fromHtml(String.format("<font color='#006fc8'>%s %s %s</font>", label, String.format(Utilities.applicationContext.getString(R.string.AndMoreTyping), arr.size() - 2), Utilities.applicationContext.getString(R.string.AreTyping))));
newPrintingStrings.put(key, Html.fromHtml(String.format("<font color='#006fc8'>%s %s %s</font>", label, String.format(ApplicationLoader.applicationContext.getString(R.string.AndMoreTyping), arr.size() - 2), ApplicationLoader.applicationContext.getString(R.string.AreTyping))));
} else {
newPrintingStrings.put(key, Html.fromHtml(String.format("<font color='#006fc8'>%s %s</font>", label, Utilities.applicationContext.getString(R.string.AreTyping))));
newPrintingStrings.put(key, Html.fromHtml(String.format("<font color='#006fc8'>%s %s</font>", label, ApplicationLoader.applicationContext.getString(R.string.AreTyping))));
}
} else {
newPrintingStrings.put(key, Html.fromHtml(String.format("<font color='#006fc8'>%s %s</font>", label, Utilities.applicationContext.getString(R.string.IsTyping))));
newPrintingStrings.put(key, Html.fromHtml(String.format("<font color='#006fc8'>%s %s</font>", label, ApplicationLoader.applicationContext.getString(R.string.IsTyping))));
}
}
}
@ -1127,7 +1125,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
ids += aContactsArr.user_id;
}
UserConfig.contactsHash = Utilities.MD5(ids);
UserConfig.saveConfig();
UserConfig.saveConfig(false);
if (from == 2) {
loadContacts(false);
}
@ -1414,7 +1412,11 @@ public class MessagesController implements NotificationCenter.NotificationCenter
public void run() {
for (TLRPC.User u : messagesRes.users) {
if (isCache) {
users.putIfAbsent(u.id, u);
if (u.id == UserConfig.clientUserId || u.id == 333000) {
users.put(u.id, u);
} else {
users.putIfAbsent(u.id, u);
}
} else {
users.put(u.id, u);
if (u.id == UserConfig.clientUserId) {
@ -1568,7 +1570,11 @@ public class MessagesController implements NotificationCenter.NotificationCenter
public void run() {
for (TLRPC.User u : dialogsRes.users) {
if (isCache) {
users.putIfAbsent(u.id, u);
if (u.id == UserConfig.clientUserId || u.id == 333000) {
users.put(u.id, u);
} else {
users.putIfAbsent(u.id, u);
}
} else {
users.put(u.id, u);
if (u.id == UserConfig.clientUserId) {
@ -1632,7 +1638,11 @@ public class MessagesController implements NotificationCenter.NotificationCenter
public void run() {
for (TLRPC.User u : dialogsRes.users) {
if (isCache) {
users.putIfAbsent(u.id, u);
if (u.id == UserConfig.clientUserId || u.id == 333000) {
users.put(u.id, u);
} else {
users.putIfAbsent(u.id, u);
}
} else {
users.put(u.id, u);
if (u.id == UserConfig.clientUserId) {
@ -1737,7 +1747,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
if (sizes.isEmpty()) {
return null;
} else {
UserConfig.saveConfig();
UserConfig.saveConfig(false);
TLRPC.TL_photo photo = new TLRPC.TL_photo();
photo.user_id = UserConfig.clientUserId;
photo.date = ConnectionsManager.Instance.getCurrentTime();
@ -1784,11 +1794,11 @@ public class MessagesController implements NotificationCenter.NotificationCenter
markDialogAsRead(dialog_id, 0, res.offset, max_date, was);
}
if (UserConfig.lastSeqValue + 1 == res.seq) {
UserConfig.lastSeqValue = res.seq;
UserConfig.lastPtsValue = res.pts;
UserConfig.saveConfig();
} else if (UserConfig.lastSeqValue != res.seq) {
if (MessagesStorage.lastSeqValue + 1 == res.seq) {
MessagesStorage.lastSeqValue = res.seq;
MessagesStorage.lastPtsValue = res.pts;
MessagesStorage.Instance.saveDiffParams(MessagesStorage.lastSeqValue, MessagesStorage.lastPtsValue, MessagesStorage.lastDateValue, MessagesStorage.lastQtsValue);
} else if (MessagesStorage.lastSeqValue != res.seq) {
getDifference();
}
}
@ -1914,7 +1924,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
newMsg.out = true;
newMsg.date = ConnectionsManager.Instance.getCurrentTime();
newMsg.random_id = getNextRandomId();
UserConfig.saveConfig();
UserConfig.saveConfig(false);
final MessageObject newMsgObj = new MessageObject(newMsg, users);
newMsgObj.messageOwner.send_state = MESSAGE_SEND_STATE_SENDING;
@ -2048,7 +2058,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
newMsg.out = true;
newMsg.date = ConnectionsManager.Instance.getCurrentTime();
newMsg.random_id = getNextRandomId();
UserConfig.saveConfig();
UserConfig.saveConfig(false);
final MessageObject newMsgObj = new MessageObject(newMsg, null);
newMsgObj.messageOwner.send_state = MESSAGE_SEND_STATE_SENDING;
@ -2284,6 +2294,9 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}
private void performSendEncryptedRequest(final TLRPC.DecryptedMessage req, final MessageObject newMsgObj, final TLRPC.EncryptedChat chat, final TLRPC.InputEncryptedFile encryptedFile) {
if (req == null) {
return;
}
//TLRPC.decryptedMessageLayer messageLayer = new TLRPC.decryptedMessageLayer();
//messageLayer.layer = 8;
//messageLayer.message = req;
@ -2377,11 +2390,11 @@ public class MessagesController implements NotificationCenter.NotificationCenter
if (response instanceof TLRPC.TL_messages_sentMessage) {
TLRPC.TL_messages_sentMessage res = (TLRPC.TL_messages_sentMessage)response;
newMsgObj.messageOwner.id = res.id;
if(UserConfig.lastSeqValue + 1 == res.seq) {
UserConfig.lastSeqValue = res.seq;
UserConfig.lastDateValue = res.date;
UserConfig.lastPtsValue = res.pts;
UserConfig.saveConfig();
if(MessagesStorage.lastSeqValue + 1 == res.seq) {
MessagesStorage.lastSeqValue = res.seq;
MessagesStorage.lastDateValue = res.date;
MessagesStorage.lastPtsValue = res.pts;
MessagesStorage.Instance.saveDiffParams(MessagesStorage.lastSeqValue, MessagesStorage.lastPtsValue, MessagesStorage.lastDateValue, MessagesStorage.lastQtsValue);
} else {
getDifference();
}
@ -2390,11 +2403,11 @@ public class MessagesController implements NotificationCenter.NotificationCenter
sendedMessages.add(res.message);
newMsgObj.messageOwner.id = res.message.id;
processSendedMessage(newMsgObj.messageOwner, res.message, null, null);
if(UserConfig.lastSeqValue + 1 == res.seq) {
UserConfig.lastSeqValue = res.seq;
UserConfig.lastPtsValue = res.pts;
UserConfig.lastDateValue = res.message.date;
UserConfig.saveConfig();
if(MessagesStorage.lastSeqValue + 1 == res.seq) {
MessagesStorage.lastSeqValue = res.seq;
MessagesStorage.lastPtsValue = res.pts;
MessagesStorage.lastDateValue = res.message.date;
MessagesStorage.Instance.saveDiffParams(MessagesStorage.lastSeqValue, MessagesStorage.lastPtsValue, MessagesStorage.lastDateValue, MessagesStorage.lastQtsValue);
} else {
getDifference();
}
@ -2406,10 +2419,10 @@ public class MessagesController implements NotificationCenter.NotificationCenter
sendedMessages.add(message);
processSendedMessage(newMsgObj.messageOwner, message, null, null);
}
if(UserConfig.lastSeqValue + 1 == res.seq) {
UserConfig.lastSeqValue = res.seq;
UserConfig.lastPtsValue = res.pts;
UserConfig.saveConfig();
if(MessagesStorage.lastSeqValue + 1 == res.seq) {
MessagesStorage.lastSeqValue = res.seq;
MessagesStorage.lastPtsValue = res.pts;
MessagesStorage.Instance.saveDiffParams(MessagesStorage.lastSeqValue, MessagesStorage.lastPtsValue, MessagesStorage.lastDateValue, MessagesStorage.lastQtsValue);
} else {
getDifference();
}
@ -2524,7 +2537,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
newContactBook.phones = new ArrayList<String>();
newContactBook.phones.add(user.phone);
newContactBook.phoneTypes = new ArrayList<String>();
newContactBook.phoneTypes.add(Utilities.applicationContext.getString(R.string.PhoneMobile));
newContactBook.phoneTypes.add(ApplicationLoader.applicationContext.getString(R.string.PhoneMobile));
contactsMapBook.put((int)bookId, newContactBook);
String contactsImportHash = "";
@ -2715,7 +2728,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}
UserConfig.contactsHash = Utilities.MD5(ids);
UserConfig.importHash = importHash;
UserConfig.saveConfig();
UserConfig.saveConfig(false);
MessagesStorage.Instance.putContacts(contactsArr, true);
ArrayList<TLRPC.User> users = new ArrayList<TLRPC.User>();
@ -2816,7 +2829,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
TLRPC.TL_messages_createChat req = new TLRPC.TL_messages_createChat();
req.title = title;
for (Integer uid : selectedContacts) {
TLRPC.User user = MessagesController.Instance.users.get(uid);
TLRPC.User user = users.get(uid);
TLRPC.InputUser inputUser;
if (user instanceof TLRPC.TL_userForeign || user instanceof TLRPC.TL_userRequest) {
inputUser = new TLRPC.TL_inputUserForeign();
@ -2845,11 +2858,11 @@ public class MessagesController implements NotificationCenter.NotificationCenter
final ArrayList<TLRPC.Message> messages = new ArrayList<TLRPC.Message>();
messages.add(res.message);
MessagesStorage.Instance.putMessages(messages, true, true);
if (UserConfig.lastSeqValue + 1 == res.seq) {
UserConfig.lastSeqValue = res.seq;
UserConfig.lastPtsValue = res.pts;
UserConfig.saveConfig();
} else if (UserConfig.lastSeqValue != res.seq) {
if (MessagesStorage.lastSeqValue + 1 == res.seq) {
MessagesStorage.lastSeqValue = res.seq;
MessagesStorage.lastPtsValue = res.pts;
MessagesStorage.Instance.saveDiffParams(MessagesStorage.lastSeqValue, MessagesStorage.lastPtsValue, MessagesStorage.lastDateValue, MessagesStorage.lastQtsValue);
} else if (MessagesStorage.lastSeqValue != res.seq) {
getDifference();
}
Utilities.RunOnUIThread(new Runnable() {
@ -2883,7 +2896,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
TLRPC.TL_messages_addChatUser req = new TLRPC.TL_messages_addChatUser();
req.chat_id = chat_id;
req.fwd_limit = 50;
TLRPC.User user = MessagesController.Instance.users.get(user_id);
TLRPC.User user = users.get(user_id);
if (user instanceof TLRPC.TL_userForeign || user instanceof TLRPC.TL_userRequest) {
req.user_id = new TLRPC.TL_inputUserForeign();
req.user_id.user_id = user.id;
@ -2904,11 +2917,11 @@ public class MessagesController implements NotificationCenter.NotificationCenter
final ArrayList<TLRPC.Message> messages = new ArrayList<TLRPC.Message>();
messages.add(res.message);
MessagesStorage.Instance.putMessages(messages, true, true);
if (UserConfig.lastSeqValue + 1 == res.seq) {
UserConfig.lastSeqValue = res.seq;
UserConfig.lastPtsValue = res.pts;
UserConfig.saveConfig();
} else if (UserConfig.lastSeqValue != res.seq) {
if (MessagesStorage.lastSeqValue + 1 == res.seq) {
MessagesStorage.lastSeqValue = res.seq;
MessagesStorage.lastPtsValue = res.pts;
MessagesStorage.Instance.saveDiffParams(MessagesStorage.lastSeqValue, MessagesStorage.lastPtsValue, MessagesStorage.lastDateValue, MessagesStorage.lastQtsValue);
} else if (MessagesStorage.lastSeqValue != res.seq) {
getDifference();
}
@ -2954,7 +2967,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
public void deleteUserFromChat(int chat_id, final int user_id, final TLRPC.ChatParticipants info) {
TLRPC.TL_messages_deleteChatUser req = new TLRPC.TL_messages_deleteChatUser();
req.chat_id = chat_id;
TLRPC.User user = MessagesController.Instance.users.get(user_id);
TLRPC.User user = users.get(user_id);
if (user instanceof TLRPC.TL_userForeign || user instanceof TLRPC.TL_userRequest) {
req.user_id = new TLRPC.TL_inputUserForeign();
req.user_id.user_id = user.id;
@ -2978,11 +2991,11 @@ public class MessagesController implements NotificationCenter.NotificationCenter
messages.add(res.message);
MessagesStorage.Instance.putMessages(messages, true, true);
}
if (UserConfig.lastSeqValue + 1 == res.seq) {
UserConfig.lastSeqValue = res.seq;
UserConfig.lastPtsValue = res.pts;
UserConfig.saveConfig();
} else if (UserConfig.lastSeqValue != res.seq) {
if (MessagesStorage.lastSeqValue + 1 == res.seq) {
MessagesStorage.lastSeqValue = res.seq;
MessagesStorage.lastPtsValue = res.pts;
MessagesStorage.Instance.saveDiffParams(MessagesStorage.lastSeqValue, MessagesStorage.lastPtsValue, MessagesStorage.lastDateValue, MessagesStorage.lastQtsValue);
} else if (MessagesStorage.lastSeqValue != res.seq) {
getDifference();
}
@ -3042,11 +3055,11 @@ public class MessagesController implements NotificationCenter.NotificationCenter
final ArrayList<TLRPC.Message> messages = new ArrayList<TLRPC.Message>();
messages.add(res.message);
MessagesStorage.Instance.putMessages(messages, true, true);
if (UserConfig.lastSeqValue + 1 == res.seq) {
UserConfig.lastSeqValue = res.seq;
UserConfig.lastPtsValue = res.pts;
UserConfig.saveConfig();
} else if (UserConfig.lastSeqValue != res.seq) {
if (MessagesStorage.lastSeqValue + 1 == res.seq) {
MessagesStorage.lastSeqValue = res.seq;
MessagesStorage.lastPtsValue = res.pts;
MessagesStorage.Instance.saveDiffParams(MessagesStorage.lastSeqValue, MessagesStorage.lastPtsValue, MessagesStorage.lastDateValue, MessagesStorage.lastQtsValue);
} else if (MessagesStorage.lastSeqValue != res.seq) {
getDifference();
}
@ -3095,11 +3108,11 @@ public class MessagesController implements NotificationCenter.NotificationCenter
final ArrayList<TLRPC.Message> messages = new ArrayList<TLRPC.Message>();
messages.add(res.message);
MessagesStorage.Instance.putMessages(messages, true, true);
if (UserConfig.lastSeqValue + 1 == res.seq) {
UserConfig.lastSeqValue = res.seq;
UserConfig.lastPtsValue = res.pts;
UserConfig.saveConfig();
} else if (UserConfig.lastSeqValue != res.seq) {
if (MessagesStorage.lastSeqValue + 1 == res.seq) {
MessagesStorage.lastSeqValue = res.seq;
MessagesStorage.lastPtsValue = res.pts;
MessagesStorage.Instance.saveDiffParams(MessagesStorage.lastSeqValue, MessagesStorage.lastPtsValue, MessagesStorage.lastDateValue, MessagesStorage.lastQtsValue);
} else if (MessagesStorage.lastSeqValue != res.seq) {
getDifference();
}
@ -3168,7 +3181,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
req.device_model = "Android unknown";
}
req.system_version = "SDK " + Build.VERSION.SDK_INT;
PackageInfo pInfo = Utilities.applicationContext.getPackageManager().getPackageInfo(Utilities.applicationContext.getPackageName(), 0);
PackageInfo pInfo = ApplicationLoader.applicationContext.getPackageManager().getPackageInfo(ApplicationLoader.applicationContext.getPackageName(), 0);
req.app_version = pInfo.versionName;
if (req.app_version == null) {
req.app_version = "App version unknown";
@ -3186,7 +3199,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
Log.e("tmessages", "registered for push");
UserConfig.registeredForPush = true;
UserConfig.pushString = regid;
UserConfig.saveConfig();
UserConfig.saveConfig(false);
}
Utilities.RunOnUIThread(new Runnable() {
@Override
@ -3211,11 +3224,11 @@ public class MessagesController implements NotificationCenter.NotificationCenter
updatingState = false;
if (error == null) {
TLRPC.TL_updates_state res = (TLRPC.TL_updates_state)response;
UserConfig.lastDateValue = res.date;
UserConfig.lastPtsValue = res.pts;
UserConfig.lastSeqValue = res.seq;
UserConfig.lastQtsValue = res.qts;
UserConfig.saveConfig();
MessagesStorage.lastDateValue = res.date;
MessagesStorage.lastPtsValue = res.pts;
MessagesStorage.lastSeqValue = res.seq;
MessagesStorage.lastQtsValue = res.qts;
MessagesStorage.Instance.saveDiffParams(MessagesStorage.lastSeqValue, MessagesStorage.lastPtsValue, MessagesStorage.lastDateValue, MessagesStorage.lastQtsValue);
} else {
loadCurrentState();
}
@ -3225,7 +3238,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
public void getDifference() {
registerForPush(UserConfig.pushString);
if (UserConfig.lastDateValue == 0) {
if (MessagesStorage.lastDateValue == 0) {
loadCurrentState();
return;
}
@ -3238,9 +3251,9 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}
gettingDifference = true;
TLRPC.TL_updates_getDifference req = new TLRPC.TL_updates_getDifference();
req.pts = UserConfig.lastPtsValue;
req.date = UserConfig.lastDateValue;
req.qts = UserConfig.lastQtsValue;
req.pts = MessagesStorage.lastPtsValue;
req.date = MessagesStorage.lastDateValue;
req.qts = MessagesStorage.lastQtsValue;
if (ConnectionsManager.Instance.connectionState == 0) {
ConnectionsManager.Instance.connectionState = 3;
final int stateCopy = ConnectionsManager.Instance.connectionState;
@ -3373,10 +3386,10 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}
if (res instanceof TLRPC.TL_updates_difference) {
UserConfig.lastSeqValue = res.state.seq;
UserConfig.lastDateValue = res.state.date;
UserConfig.lastPtsValue = res.state.pts;
UserConfig.lastQtsValue = res.state.qts;
MessagesStorage.lastSeqValue = res.state.seq;
MessagesStorage.lastDateValue = res.state.date;
MessagesStorage.lastPtsValue = res.state.pts;
MessagesStorage.lastQtsValue = res.state.qts;
ConnectionsManager.Instance.connectionState = 0;
final int stateCopy = ConnectionsManager.Instance.connectionState;
Utilities.RunOnUIThread(new Runnable() {
@ -3386,14 +3399,14 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}
});
} else if (res instanceof TLRPC.TL_updates_differenceSlice) {
UserConfig.lastSeqValue = res.intermediate_state.seq;
UserConfig.lastDateValue = res.intermediate_state.date;
UserConfig.lastPtsValue = res.intermediate_state.pts;
UserConfig.lastQtsValue = res.intermediate_state.qts;
MessagesStorage.lastSeqValue = res.intermediate_state.seq;
MessagesStorage.lastDateValue = res.intermediate_state.date;
MessagesStorage.lastPtsValue = res.intermediate_state.pts;
MessagesStorage.lastQtsValue = res.intermediate_state.qts;
getDifference();
} else if (res instanceof TLRPC.TL_updates_differenceEmpty) {
UserConfig.lastSeqValue = res.seq;
UserConfig.lastDateValue = res.date;
MessagesStorage.lastSeqValue = res.seq;
MessagesStorage.lastDateValue = res.date;
ConnectionsManager.Instance.connectionState = 0;
final int stateCopy = ConnectionsManager.Instance.connectionState;
Utilities.RunOnUIThread(new Runnable() {
@ -3403,14 +3416,14 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}
});
}
UserConfig.saveConfig();
MessagesStorage.Instance.saveDiffParams(MessagesStorage.lastSeqValue, MessagesStorage.lastPtsValue, MessagesStorage.lastDateValue, MessagesStorage.lastQtsValue);
}
});
}
});
if (ConnectionsManager.DEBUG_VERSION) {
Log.e("tmessages", "received defference with date = " + UserConfig.lastDateValue + " pts = " + UserConfig.lastPtsValue + " seq = " + UserConfig.lastSeqValue);
Log.e("tmessages", "received defference with date = " + MessagesStorage.lastDateValue + " pts = " + MessagesStorage.lastPtsValue + " seq = " + MessagesStorage.lastSeqValue);
Log.e("tmessages", "messages = " + res.new_messages.size() + " users = " + res.users.size() + " chats = " + res.chats.size() + " other updates = " + res.other_updates.size());
}
} else {
@ -3429,7 +3442,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
arr.add(updates.update);
processUpdateArray(arr, null, null);
} else if (updates instanceof TLRPC.TL_updateShortChatMessage) {
if (UserConfig.lastSeqValue + 1 == updates.seq && chats.get(updates.chat_id) != null && users.get(updates.from_id) != null) {
if (MessagesStorage.lastSeqValue + 1 == updates.seq && chats.get(updates.chat_id) != null && users.get(updates.from_id) != null) {
TLRPC.TL_message message = new TLRPC.TL_message();
message.from_id = updates.from_id;
message.id = updates.id;
@ -3439,8 +3452,8 @@ public class MessagesController implements NotificationCenter.NotificationCenter
message.date = updates.date;
message.unread = true;
message.media = new TLRPC.TL_messageMediaEmpty();
UserConfig.lastSeqValue = updates.seq;
UserConfig.lastPtsValue = updates.pts;
MessagesStorage.lastSeqValue = updates.seq;
MessagesStorage.lastPtsValue = updates.pts;
final MessageObject obj = new MessageObject(message, null);
final ArrayList<MessageObject> objArr = new ArrayList<MessageObject>();
objArr.add(obj);
@ -3477,7 +3490,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
needGetDiff = true;
}
} else if (updates instanceof TLRPC.TL_updateShortMessage) {
if (UserConfig.lastSeqValue + 1 == updates.seq && users.get(updates.from_id) != null) {
if (MessagesStorage.lastSeqValue + 1 == updates.seq && users.get(updates.from_id) != null) {
TLRPC.TL_message message = new TLRPC.TL_message();
message.from_id = updates.from_id;
message.id = updates.id;
@ -3487,9 +3500,9 @@ public class MessagesController implements NotificationCenter.NotificationCenter
message.date = updates.date;
message.unread = true;
message.media = new TLRPC.TL_messageMediaEmpty();
UserConfig.lastSeqValue = updates.seq;
UserConfig.lastPtsValue = updates.pts;
UserConfig.lastDateValue = updates.date;
MessagesStorage.lastSeqValue = updates.seq;
MessagesStorage.lastPtsValue = updates.pts;
MessagesStorage.lastDateValue = updates.date;
final MessageObject obj = new MessageObject(message, null);
final ArrayList<MessageObject> objArr = new ArrayList<MessageObject>();
objArr.add(obj);
@ -3526,18 +3539,18 @@ public class MessagesController implements NotificationCenter.NotificationCenter
needGetDiff = true;
}
} else if (updates instanceof TLRPC.TL_updatesCombined) {
if (UserConfig.lastSeqValue + 1 == updates.seq_start || updates.seq_start == 0 || UserConfig.lastSeqValue == updates.seq_start) {
if (MessagesStorage.lastSeqValue + 1 == updates.seq_start || updates.seq_start == 0 || MessagesStorage.lastSeqValue == updates.seq_start) {
MessagesStorage.Instance.putUsersAndChats(updates.users, updates.chats, true, true);
int lastPtsValue = UserConfig.lastPtsValue;
int lastQtsValue = UserConfig.lastQtsValue;
int lastPtsValue = MessagesStorage.lastPtsValue;
int lastQtsValue = MessagesStorage.lastQtsValue;
if (!processUpdateArray(updates.updates, updates.users, updates.chats)) {
UserConfig.lastPtsValue = lastPtsValue;
UserConfig.lastQtsValue = lastQtsValue;
MessagesStorage.lastPtsValue = lastPtsValue;
MessagesStorage.lastQtsValue = lastQtsValue;
needGetDiff = true;
} else {
UserConfig.lastDateValue = updates.date;
UserConfig.lastSeqValue = updates.seq;
if (UserConfig.lastQtsValue != lastQtsValue) {
MessagesStorage.lastDateValue = updates.date;
MessagesStorage.lastSeqValue = updates.seq;
if (MessagesStorage.lastQtsValue != lastQtsValue) {
needReceivedQueue = true;
}
}
@ -3545,18 +3558,18 @@ public class MessagesController implements NotificationCenter.NotificationCenter
needGetDiff = true;
}
} else if (updates instanceof TLRPC.TL_updates) {
if (UserConfig.lastSeqValue + 1 == updates.seq || updates.seq == 0 || updates.seq == UserConfig.lastSeqValue) {
if (MessagesStorage.lastSeqValue + 1 == updates.seq || updates.seq == 0 || updates.seq == MessagesStorage.lastSeqValue) {
MessagesStorage.Instance.putUsersAndChats(updates.users, updates.chats, true, true);
int lastPtsValue = UserConfig.lastPtsValue;
int lastQtsValue = UserConfig.lastQtsValue;
int lastPtsValue = MessagesStorage.lastPtsValue;
int lastQtsValue = MessagesStorage.lastQtsValue;
if (!processUpdateArray(updates.updates, updates.users, updates.chats)) {
needGetDiff = true;
UserConfig.lastPtsValue = lastPtsValue;
UserConfig.lastQtsValue = lastQtsValue;
MessagesStorage.lastPtsValue = lastPtsValue;
MessagesStorage.lastQtsValue = lastQtsValue;
} else {
UserConfig.lastDateValue = updates.date;
UserConfig.lastSeqValue = updates.seq;
if (UserConfig.lastQtsValue != lastQtsValue) {
MessagesStorage.lastDateValue = updates.date;
MessagesStorage.lastSeqValue = updates.seq;
if (MessagesStorage.lastQtsValue != lastQtsValue) {
needReceivedQueue = true;
}
}
@ -3571,7 +3584,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}
if (needReceivedQueue) {
TLRPC.TL_messages_receivedQueue req = new TLRPC.TL_messages_receivedQueue();
req.max_qts = UserConfig.lastQtsValue;
req.max_qts = MessagesStorage.lastQtsValue;
ConnectionsManager.Instance.performRpc(req, new RPCRequest.RPCRequestDelegate() {
@Override
public void run(TLObject response, TLRPC.TL_error error) {
@ -3579,7 +3592,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}
}, null, true, RPCRequest.RPCRequestClassGeneric);
}
UserConfig.saveConfig();
MessagesStorage.Instance.saveDiffParams(MessagesStorage.lastSeqValue, MessagesStorage.lastPtsValue, MessagesStorage.lastDateValue, MessagesStorage.lastQtsValue);
}
public boolean processUpdateArray(ArrayList<TLRPC.Update> updates, final ArrayList<TLRPC.User> usersArr, final ArrayList<TLRPC.Chat> chatsArr) {
@ -3653,7 +3666,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
messages.put(uid, arr);
}
arr.add(obj);
UserConfig.lastPtsValue = update.pts;
MessagesStorage.lastPtsValue = update.pts;
if (upd.message.from_id != UserConfig.clientUserId && upd.message.to_id != null) {
if (uid != openned_dialog_id) {
lastMessage = obj;
@ -3663,12 +3676,12 @@ public class MessagesController implements NotificationCenter.NotificationCenter
//can't be here
} else if (update instanceof TLRPC.TL_updateReadMessages) {
markAsReadMessages.addAll(update.messages);
UserConfig.lastPtsValue = update.pts;
MessagesStorage.lastPtsValue = update.pts;
} else if (update instanceof TLRPC.TL_updateDeleteMessages) {
deletedMessages.addAll(update.messages);
UserConfig.lastPtsValue = update.pts;
MessagesStorage.lastPtsValue = update.pts;
} else if (update instanceof TLRPC.TL_updateRestoreMessages) {
UserConfig.lastPtsValue = update.pts;
MessagesStorage.lastPtsValue = update.pts;
} else if (update instanceof TLRPC.TL_updateUserTyping || update instanceof TLRPC.TL_updateChatUserTyping) {
if (update.user_id != UserConfig.clientUserId) {
long uid = -update.chat_id;
@ -3727,7 +3740,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
} else if (update instanceof TLRPC.TL_updateNewGeoChatMessage) {
//TODO
} else if (update instanceof TLRPC.TL_updateNewEncryptedMessage) {
UserConfig.lastQtsValue = update.qts;
MessagesStorage.lastQtsValue = update.qts;
TLRPC.Message message = decryptMessage(((TLRPC.TL_updateNewEncryptedMessage)update).message);
if (message != null) {
int cid = ((TLRPC.TL_updateNewEncryptedMessage)update).message.chat_id;
@ -3852,7 +3865,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}
});
MessagesStorage.Instance.putEncryptedChat(newChat, user, dialog);
MessagesController.Instance.acceptSecretChat(newChat);
acceptSecretChat(newChat);
} else if (newChat instanceof TLRPC.TL_encryptedChat) {
if (existingChat != null && existingChat instanceof TLRPC.TL_encryptedChatWaiting && (existingChat.auth_key == null || existingChat.auth_key.length == 1)) {
newChat.a_or_b = existingChat.a_or_b;
@ -4101,7 +4114,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}
private void showInAppNotification(MessageObject messageObject) {
SharedPreferences preferences = Utilities.applicationContext.getSharedPreferences("Notifications", Context.MODE_PRIVATE);
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Context.MODE_PRIVATE);
boolean globalEnabled = preferences.getBoolean("EnableAll", true);
if (!globalEnabled) {
return;
@ -4157,7 +4170,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
NotificationCenter.Instance.postNotificationName(701, messageObject);
}
if (inAppVibrate) {
Vibrator v = (Vibrator)Utilities.applicationContext.getSystemService(Context.VIBRATOR_SERVICE);
Vibrator v = (Vibrator)ApplicationLoader.applicationContext.getSystemService(Context.VIBRATOR_SERVICE);
v.vibrate(100);
}
if (inAppSounds) {
@ -4206,8 +4219,8 @@ public class MessagesController implements NotificationCenter.NotificationCenter
String userSoundPath = null;
String chatSoundPath = null;
NotificationManager mNotificationManager = (NotificationManager)Utilities.applicationContext.getSystemService(Context.NOTIFICATION_SERVICE);
Intent intent = new Intent(Utilities.applicationContext, LaunchActivity.class);
NotificationManager mNotificationManager = (NotificationManager)ApplicationLoader.applicationContext.getSystemService(Context.NOTIFICATION_SERVICE);
Intent intent = new Intent(ApplicationLoader.applicationContext, LaunchActivity.class);
String msg;
if ((int)dialog_id != 0) {
@ -4219,7 +4232,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}
msg = messageObject.messageOwner.message;
} else {
msg = Utilities.applicationContext.getString(R.string.YouHaveNewMessage);
msg = ApplicationLoader.applicationContext.getString(R.string.YouHaveNewMessage);
}
boolean needVibrate = false;
@ -4253,10 +4266,10 @@ public class MessagesController implements NotificationCenter.NotificationCenter
intent.setAction("com.tmessages.openchat" + Math.random() + Integer.MAX_VALUE);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent contentIntent = PendingIntent.getActivity(Utilities.applicationContext, 0, intent, PendingIntent.FLAG_ONE_SHOT);
PendingIntent contentIntent = PendingIntent.getActivity(ApplicationLoader.applicationContext, 0, intent, PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(Utilities.applicationContext)
.setContentTitle(Utilities.applicationContext.getString(R.string.AppName))
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(ApplicationLoader.applicationContext)
.setContentTitle(ApplicationLoader.applicationContext.getString(R.string.AppName))
.setSmallIcon(R.drawable.notification)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(msg))
@ -4486,7 +4499,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
public void processAcceptedSecretChat(final TLRPC.EncryptedChat encryptedChat) {
BigInteger i_authKey = new BigInteger(1, encryptedChat.g_a_or_b);
i_authKey = i_authKey.modPow(new BigInteger(1, encryptedChat.a_or_b), new BigInteger(1, UserConfig.secretPBytes));
i_authKey = i_authKey.modPow(new BigInteger(1, encryptedChat.a_or_b), new BigInteger(1, MessagesStorage.secretPBytes));
byte[] authKey = i_authKey.toByteArray();
if (authKey.length > 256) {
@ -4553,25 +4566,25 @@ public class MessagesController implements NotificationCenter.NotificationCenter
acceptingChats.put(encryptedChat.id, encryptedChat);
TLRPC.TL_messages_getDhConfig req = new TLRPC.TL_messages_getDhConfig();
req.random_length = 256;
req.version = UserConfig.lastSecretVersion;
req.version = MessagesStorage.lastSecretVersion;
ConnectionsManager.Instance.performRpc(req, new RPCRequest.RPCRequestDelegate() {
@Override
public void run(TLObject response, TLRPC.TL_error error) {
if (error == null) {
TLRPC.messages_DhConfig res = (TLRPC.messages_DhConfig)response;
if (response instanceof TLRPC.TL_messages_dhConfig) {
UserConfig.secretPBytes = res.p;
UserConfig.secretG = res.g;
UserConfig.lastSecretVersion = res.version;
UserConfig.saveConfig();
MessagesStorage.secretPBytes = res.p;
MessagesStorage.secretG = res.g;
MessagesStorage.lastSecretVersion = res.version;
MessagesStorage.Instance.saveSecretParams(MessagesStorage.lastSecretVersion, MessagesStorage.secretG, MessagesStorage.secretPBytes);
}
byte[] salt = new byte[256];
for (int a = 0; a < 256; a++) {
salt[a] = (byte)((byte)(random.nextDouble() * 255) ^ res.random[a]);
}
encryptedChat.a_or_b = salt;
BigInteger i_g_b = BigInteger.valueOf(UserConfig.secretG);
i_g_b = i_g_b.modPow(new BigInteger(1, salt), new BigInteger(1, UserConfig.secretPBytes));
BigInteger i_g_b = BigInteger.valueOf(MessagesStorage.secretG);
i_g_b = i_g_b.modPow(new BigInteger(1, salt), new BigInteger(1, MessagesStorage.secretPBytes));
byte[] g_b = i_g_b.toByteArray();
if (g_b.length > 256) {
byte[] correctedAuth = new byte[256];
@ -4580,7 +4593,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}
BigInteger i_authKey = new BigInteger(1, encryptedChat.g_a);
i_authKey = i_authKey.modPow(new BigInteger(1, salt), new BigInteger(1, UserConfig.secretPBytes));
i_authKey = i_authKey.modPow(new BigInteger(1, salt), new BigInteger(1, MessagesStorage.secretPBytes));
byte[] authKey = i_authKey.toByteArray();
if (authKey.length > 256) {
@ -4643,24 +4656,24 @@ public class MessagesController implements NotificationCenter.NotificationCenter
progressDialog.show();
TLRPC.TL_messages_getDhConfig req = new TLRPC.TL_messages_getDhConfig();
req.random_length = 256;
req.version = UserConfig.lastSecretVersion;
req.version = MessagesStorage.lastSecretVersion;
ConnectionsManager.Instance.performRpc(req, new RPCRequest.RPCRequestDelegate() {
@Override
public void run(TLObject response, TLRPC.TL_error error) {
if (error == null) {
TLRPC.messages_DhConfig res = (TLRPC.messages_DhConfig)response;
if (response instanceof TLRPC.TL_messages_dhConfig) {
UserConfig.secretPBytes = res.p;
UserConfig.secretG = res.g;
UserConfig.lastSecretVersion = res.version;
UserConfig.saveConfig();
MessagesStorage.secretPBytes = res.p;
MessagesStorage.secretG = res.g;
MessagesStorage.lastSecretVersion = res.version;
MessagesStorage.Instance.saveSecretParams(MessagesStorage.lastSecretVersion, MessagesStorage.secretG, MessagesStorage.secretPBytes);
}
final byte[] salt = new byte[256];
for (int a = 0; a < 256; a++) {
salt[a] = (byte)((byte)(random.nextDouble() * 255) ^ res.random[a]);
}
BigInteger i_g_a = BigInteger.valueOf(UserConfig.secretG);
i_g_a = i_g_a.modPow(new BigInteger(1, salt), new BigInteger(1, UserConfig.secretPBytes));
BigInteger i_g_a = BigInteger.valueOf(MessagesStorage.secretG);
i_g_a = i_g_a.modPow(new BigInteger(1, salt), new BigInteger(1, MessagesStorage.secretPBytes));
byte[] g_a = i_g_a.toByteArray();
if (g_a.length > 256) {
byte[] correctedAuth = new byte[256];
@ -4668,7 +4681,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
g_a = correctedAuth;
}
final TLRPC.User user = MessagesController.Instance.users.get(user_id);
final TLRPC.User user = users.get(user_id);
TLRPC.InputUser inputUser;
if (user instanceof TLRPC.TL_userForeign || user instanceof TLRPC.TL_userRequest) {
inputUser = new TLRPC.TL_inputUserForeign();
@ -4735,7 +4748,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(context.getString(R.string.AppName));
builder.setMessage(String.format(context.getString(R.string.CreateEncryptedChatOutdatedError), user.first_name, user.first_name));
builder.setPositiveButton(Utilities.applicationContext.getString(R.string.OK), null);
builder.setPositiveButton(ApplicationLoader.applicationContext.getString(R.string.OK), null);
builder.show().setCanceledOnTouchOutside(true);
}
}

View file

@ -17,6 +17,7 @@ import org.telegram.SQLite.SQLitePreparedStatement;
import org.telegram.TL.TLClassStore;
import org.telegram.TL.TLObject;
import org.telegram.TL.TLRPC;
import org.telegram.ui.ApplicationLoader;
import java.io.File;
import java.util.ArrayList;
@ -28,6 +29,13 @@ public class MessagesStorage {
public DispatchQueue storageQueue = new DispatchQueue("storageQueue");
private SQLiteDatabase database;
private File cacheFile;
public static int lastDateValue = 0;
public static int lastPtsValue = 0;
public static int lastQtsValue = 0;
public static int lastSeqValue = 0;
public static int lastSecretVersion = 0;
public static byte[] secretPBytes = null;
public static int secretG = 0;
public static final int wallpapersDidLoaded = 171;
public static MessagesStorage Instance = new MessagesStorage();
@ -38,7 +46,7 @@ public class MessagesStorage {
}
public void openDatabase() {
cacheFile = new File(Utilities.applicationContext.getFilesDir(), "cache4.db");
cacheFile = new File(ApplicationLoader.applicationContext.getFilesDir(), "cache4.db");
boolean createTable = false;
//cacheFile.delete();
if (!cacheFile.exists()) {
@ -60,6 +68,8 @@ public class MessagesStorage {
database.executeFast("CREATE TABLE wallpapers(uid INTEGER PRIMARY KEY, data BLOB)").stepThis().dispose();
database.executeFast("CREATE TABLE randoms(random_id INTEGER PRIMARY KEY, mid INTEGER)").stepThis().dispose();
database.executeFast("CREATE TABLE enc_tasks(date INTEGER, data BLOB)").stepThis().dispose();
database.executeFast("CREATE TABLE params(id INTEGER PRIMARY KEY, seq INTEGER, pts INTEGER, date INTEGER, qts INTEGER, lsv INTEGER, sg INTEGER, pbytes BLOB)").stepThis().dispose();
database.executeFast("INSERT INTO params VALUES(1, 0, 0, 0, 0, 0, 0, NULL)").stepThis().dispose();
database.executeFast("CREATE INDEX IF NOT EXISTS date_idx_dialogs ON dialogs(date);").stepThis().dispose();
database.executeFast("CREATE INDEX IF NOT EXISTS date_idx_enc_tasks ON enc_tasks(date);").stepThis().dispose();
@ -69,6 +79,41 @@ public class MessagesStorage {
database.executeFast("CREATE INDEX IF NOT EXISTS uid_mid_idx_media ON media(uid, mid);").stepThis().dispose();
database.executeFast("CREATE INDEX IF NOT EXISTS ttl_idx_messages ON messages(ttl);").stepThis().dispose();
database.executeFast("CREATE INDEX IF NOT EXISTS read_state_out_idx_messages ON messages(read_state, out);").stepThis().dispose();
} else {
SQLiteCursor cursor = database.queryFinalized("SELECT count(*) FROM sqlite_master WHERE type='table' AND name='params'");
boolean create = false;
if (cursor.next()) {
int count = cursor.intValue(0);
if (count == 0) {
create = true;
}
} else {
create = true;
}
cursor.dispose();
if (create) {
database.executeFast("CREATE TABLE params(id INTEGER PRIMARY KEY, seq INTEGER, pts INTEGER, date INTEGER, qts INTEGER, lsv INTEGER, sg INTEGER, pbytes BLOB)").stepThis().dispose();
database.executeFast("INSERT INTO params VALUES(1, 0, 0, 0, 0, 0, 0, NULL)").stepThis().dispose();
} else {
cursor = database.queryFinalized("SELECT seq, pts, date, qts, lsv, sg, pbytes FROM params WHERE id = 1");
if (cursor.next()) {
lastSeqValue = cursor.intValue(0);
lastPtsValue = cursor.intValue(1);
lastDateValue = cursor.intValue(2);
lastQtsValue = cursor.intValue(3);
lastSecretVersion = cursor.intValue(4);
secretG = cursor.intValue(5);
if (cursor.isNull(6)) {
secretPBytes = null;
} else {
secretPBytes = cursor.byteArrayValue(6);
if (secretPBytes != null && secretPBytes.length == 1) {
secretPBytes = null;
}
}
}
cursor.dispose();
}
}
} catch (Exception e) {
e.printStackTrace();
@ -79,6 +124,13 @@ public class MessagesStorage {
storageQueue.postRunnable(new Runnable() {
@Override
public void run() {
lastDateValue = 0;
lastSeqValue = 0;
lastPtsValue = 0;
lastQtsValue = 0;
lastSecretVersion = 0;
secretPBytes = null;
secretG = 0;
if (database != null) {
database.close();
database = null;
@ -88,15 +140,15 @@ public class MessagesStorage {
cacheFile = null;
}
try {
File old = new File(Utilities.applicationContext.getFilesDir(), "cache.db");
File old = new File(ApplicationLoader.applicationContext.getFilesDir(), "cache.db");
if (old.exists()) {
old.delete();
}
old = new File(Utilities.applicationContext.getFilesDir(), "cache2.db");
old = new File(ApplicationLoader.applicationContext.getFilesDir(), "cache2.db");
if (old.exists()) {
old.delete();
}
old = new File(Utilities.applicationContext.getFilesDir(), "cache3.db");
old = new File(ApplicationLoader.applicationContext.getFilesDir(), "cache3.db");
if (old.exists()) {
old.delete();
}
@ -108,6 +160,47 @@ public class MessagesStorage {
});
}
public void saveSecretParams(final int lsv, final int sg, final byte[] pbytes) {
storageQueue.postRunnable(new Runnable() {
@Override
public void run() {
try {
SQLitePreparedStatement state = database.executeFast("UPDATE params SET lsv = ?, sg = ?, pbytes = ? WHERE id = 1");
state.bindInteger(1, lsv);
state.bindInteger(2, sg);
if (pbytes != null) {
state.bindByteArray(3, pbytes);
} else {
state.bindByteArray(3, new byte[1]);
}
state.step();
state.dispose();
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public void saveDiffParams(final int seq, final int pts, final int date, final int qts) {
storageQueue.postRunnable(new Runnable() {
@Override
public void run() {
try {
SQLitePreparedStatement state = database.executeFast("UPDATE params SET seq = ?, pts = ?, date = ?, qts = ? WHERE id = 1");
state.bindInteger(1, seq);
state.bindInteger(2, pts);
state.bindInteger(3, date);
state.bindInteger(4, qts);
state.step();
state.dispose();
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public void putWallpapers(final ArrayList<TLRPC.WallPaper> wallPapers) {
storageQueue.postRunnable(new Runnable() {
@Override

View file

@ -8,8 +8,12 @@
package org.telegram.messenger;
import android.content.Context;
import android.content.SharedPreferences;
import org.telegram.TL.TLClassStore;
import org.telegram.TL.TLRPC;
import org.telegram.ui.ApplicationLoader;
import java.io.File;
import java.io.FileOutputStream;
@ -18,17 +22,10 @@ public class UserConfig {
public static TLRPC.User currentUser;
public static int clientUserId = 0;
public static boolean clientActivated = false;
public static int lastDateValue = 0;
public static int lastPtsValue = 0;
public static int lastQtsValue = 0;
public static int lastSeqValue = 0;
public static boolean registeredForPush = false;
public static String pushString = "";
public static int lastSendMessageId = -1;
public static int lastLocalId = -1;
public static int lastSecretVersion = 0;
public static byte[] secretPBytes = null;
public static int secretG = 0;
public static String contactsHash = "";
public static String importHash = "";
private final static Integer sync = 1;
@ -43,64 +40,58 @@ public class UserConfig {
return id;
}
public static void saveConfig() {
public static void saveConfig(boolean withFile) {
synchronized (sync) {
SerializedData data = new SerializedData();
if (currentUser != null) {
data.writeInt32(1);
data.writeInt32(2);
currentUser.serializeToStream(data);
clientUserId = currentUser.id;
clientActivated = true;
data.writeInt32(lastDateValue);
data.writeInt32(lastPtsValue);
data.writeInt32(lastSeqValue);
data.writeBool(registeredForPush);
data.writeString(pushString);
data.writeInt32(lastSendMessageId);
data.writeInt32(lastLocalId);
data.writeString(contactsHash);
data.writeString(importHash);
data.writeBool(saveIncomingPhotos);
data.writeInt32(lastQtsValue);
data.writeInt32(lastSecretVersion);
if (secretPBytes != null) {
data.writeInt32(1);
data.writeByteArray(secretPBytes);
} else {
data.writeInt32(0);
}
data.writeInt32(secretG);
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("userconfing", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean("registeredForPush", registeredForPush);
editor.putString("pushString", pushString);
editor.putInt("lastSendMessageId", lastSendMessageId);
editor.putInt("lastLocalId", lastLocalId);
editor.putString("contactsHash", contactsHash);
editor.putString("importHash", importHash);
editor.putBoolean("saveIncomingPhotos", saveIncomingPhotos);
editor.commit();
} else {
data.writeInt32(0);
}
try {
File configFile = new File(Utilities.applicationContext.getFilesDir(), "user.dat");
if (!configFile.exists()) {
configFile.createNewFile();
if (withFile) {
try {
File configFile = new File(ApplicationLoader.applicationContext.getFilesDir(), "user.dat");
if (!configFile.exists()) {
configFile.createNewFile();
}
FileOutputStream stream = new FileOutputStream(configFile);
stream.write(data.toByteArray());
stream.close();
} catch (Exception e) {
e.printStackTrace();
}
FileOutputStream stream = new FileOutputStream(configFile);
stream.write(data.toByteArray());
stream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
public static void loadConfig() {
synchronized (sync) {
File configFile = new File(Utilities.applicationContext.getFilesDir(), "user.dat");
File configFile = new File(ApplicationLoader.applicationContext.getFilesDir(), "user.dat");
if (configFile.exists()) {
try {
SerializedData data = new SerializedData(configFile);
if (data.readInt32() != 0) {
int ver = data.readInt32();
if (ver == 1) {
int constructor = data.readInt32();
currentUser = (TLRPC.TL_userSelf)TLClassStore.Instance().TLdeserialize(data, constructor);
clientUserId = currentUser.id;
clientActivated = true;
lastDateValue = data.readInt32();
lastPtsValue = data.readInt32();
lastSeqValue = data.readInt32();
MessagesStorage.lastDateValue = data.readInt32();
MessagesStorage.lastPtsValue = data.readInt32();
MessagesStorage.lastSeqValue = data.readInt32();
registeredForPush = data.readBool();
pushString = data.readString();
lastSendMessageId = data.readInt32();
@ -115,13 +106,27 @@ public class UserConfig {
currentUser.status.expires = currentUser.status.was_online;
}
}
lastQtsValue = data.readInt32();
lastSecretVersion = data.readInt32();
MessagesStorage.lastQtsValue = data.readInt32();
MessagesStorage.lastSecretVersion = data.readInt32();
int val = data.readInt32();
if (val == 1) {
secretPBytes = data.readByteArray();
MessagesStorage.secretPBytes = data.readByteArray();
}
secretG = data.readInt32();
MessagesStorage.secretG = data.readInt32();
} else if (ver == 2) {
int constructor = data.readInt32();
currentUser = (TLRPC.TL_userSelf)TLClassStore.Instance().TLdeserialize(data, constructor);
clientUserId = currentUser.id;
clientActivated = true;
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("userconfing", Context.MODE_PRIVATE);
registeredForPush = preferences.getBoolean("registeredForPush", false);
pushString = preferences.getString("pushString", "");
lastSendMessageId = preferences.getInt("lastSendMessageId", -1);
lastLocalId = preferences.getInt("lastLocalId", -1);
contactsHash = preferences.getString("contactsHash", "");
importHash = preferences.getString("importHash", "");
saveIncomingPhotos = preferences.getBoolean("saveIncomingPhotos", false);
}
} catch (Exception e) {
e.printStackTrace();
@ -134,15 +139,12 @@ public class UserConfig {
clientUserId = 0;
clientActivated = false;
currentUser = null;
lastDateValue = 0;
lastSeqValue = 0;
lastPtsValue = 0;
registeredForPush = false;
contactsHash = "";
lastLocalId = -1;
importHash = "";
lastSendMessageId = -1;
saveIncomingPhotos = false;
saveConfig();
saveConfig(true);
}
}

View file

@ -18,6 +18,7 @@ import android.os.Environment;
import android.os.Handler;
import android.text.Html;
import android.text.SpannableStringBuilder;
import android.text.format.DateFormat;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
@ -25,6 +26,7 @@ import android.view.inputmethod.InputMethodManager;
import org.telegram.TL.TLClassStore;
import org.telegram.TL.TLObject;
import org.telegram.ui.ApplicationLoader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@ -50,7 +52,6 @@ import java.util.zip.GZIPInputStream;
import javax.crypto.Cipher;
public class Utilities {
public static Context applicationContext;
public static Handler applicationHandler;
private final static Integer lock = 1;
@ -77,10 +78,10 @@ public class Utilities {
public static File getCacheDir() {
if (externalCacheNotAvailableState == 1 || externalCacheNotAvailableState == 0 && Environment.getExternalStorageState().startsWith(Environment.MEDIA_MOUNTED)) {
externalCacheNotAvailableState = 1;
return applicationContext.getExternalCacheDir();
return ApplicationLoader.applicationContext.getExternalCacheDir();
}
externalCacheNotAvailableState = 2;
return applicationContext.getCacheDir();
return ApplicationLoader.applicationContext.getCacheDir();
}
public static TPFactorizedValue getFactorizedValue(long what) {
@ -230,7 +231,7 @@ public class Utilities {
synchronized (cache) {
if (!cache.containsKey(assetPath)) {
try {
Typeface t = Typeface.createFromAsset(applicationContext.getAssets(),
Typeface t = Typeface.createFromAsset(ApplicationLoader.applicationContext.getAssets(),
assetPath);
cache.put(assetPath, t);
} catch (Exception e) {
@ -304,11 +305,19 @@ public class Utilities {
formatterYearMax = FastDateFormat.getInstance("dd.MM.yyyy", locale);
chatDate = FastDateFormat.getInstance("d MMMM", locale);
chatFullDate = FastDateFormat.getInstance("d MMMM yyyy", locale);
if (lang != null && lang.toLowerCase().equals("ar")) {
formatterDay = FastDateFormat.getInstance("h:mm a", locale);
if (lang != null) {
if (DateFormat.is24HourFormat(ApplicationLoader.applicationContext)) {
formatterDay = FastDateFormat.getInstance("HH:mm", locale);
} else {
if (lang.toLowerCase().equals("ar")) {
formatterDay = FastDateFormat.getInstance("h:mm a", locale);
} else {
formatterDay = FastDateFormat.getInstance("h:mm a", Locale.US);
}
}
} else {
formatterDay = FastDateFormat.getInstance("h:mm a", Locale.US);}
formatterDay = FastDateFormat.getInstance("h:mm a", Locale.US);
}
}
public static String formatDateChat(long date) {
@ -335,7 +344,7 @@ public class Utilities {
if (dateDay == day && year == dateYear) {
return formatterDay.format(new Date(date * 1000));
} else if (dateDay + 1 == day && year == dateYear) {
return applicationContext.getResources().getString(R.string.Yesterday);
return ApplicationLoader.applicationContext.getResources().getString(R.string.Yesterday);
} else if (year == dateYear) {
return formatterMonth.format(new Date(date * 1000));
} else {
@ -352,13 +361,13 @@ public class Utilities {
int dateYear = rightNow.get(Calendar.YEAR);
if (dateDay == day && year == dateYear) {
return String.format("%s %s", applicationContext.getResources().getString(R.string.TodayAt), formatterDay.format(new Date(date * 1000)));
return String.format("%s %s", ApplicationLoader.applicationContext.getResources().getString(R.string.TodayAt), formatterDay.format(new Date(date * 1000)));
} else if (dateDay + 1 == day && year == dateYear) {
return String.format("%s %s", applicationContext.getResources().getString(R.string.YesterdayAt), formatterDay.format(new Date(date * 1000)));
return String.format("%s %s", ApplicationLoader.applicationContext.getResources().getString(R.string.YesterdayAt), formatterDay.format(new Date(date * 1000)));
} else if (year == dateYear) {
return String.format("%s %s %s", formatterMonth.format(new Date(date * 1000)), applicationContext.getResources().getString(R.string.OtherAt), formatterDay.format(new Date(date * 1000)));
return String.format("%s %s %s", formatterMonth.format(new Date(date * 1000)), ApplicationLoader.applicationContext.getResources().getString(R.string.OtherAt), formatterDay.format(new Date(date * 1000)));
} else {
return String.format("%s %s %s", formatterYear.format(new Date(date * 1000)), applicationContext.getResources().getString(R.string.OtherAt), formatterDay.format(new Date(date * 1000)));
return String.format("%s %s %s", formatterYear.format(new Date(date * 1000)), ApplicationLoader.applicationContext.getResources().getString(R.string.OtherAt), formatterDay.format(new Date(date * 1000)));
}
}
@ -401,7 +410,7 @@ public class Utilities {
public static void RunOnUIThread(Runnable runnable) {
synchronized (lock) {
if (applicationHandler == null) {
applicationHandler = new Handler(applicationContext.getMainLooper());
applicationHandler = new Handler(ApplicationLoader.applicationContext.getMainLooper());
}
applicationHandler.post(runnable);
}
@ -419,18 +428,25 @@ public class Utilities {
R.drawable.user_placeholder_orange};
public static int[] arrGroupsAvatars = {
R.drawable.group_placeholder_red,
R.drawable.group_placeholder_green,
R.drawable.group_placeholder_yellow,
R.drawable.group_placeholder_red,
R.drawable.group_placeholder_blue,
R.drawable.group_placeholder_purple,
R.drawable.group_placeholder_pink,
R.drawable.group_placeholder_cyan,
R.drawable.group_placeholder_orange};
R.drawable.group_placeholder_yellow};
public static int getColorIndex(int id) {
int[] arr;
if (id >= 0) {
arr = arrUsersAvatars;
} else {
arr = arrGroupsAvatars;
}
try {
String str = String.format(Locale.US, "%d%d", id, UserConfig.clientUserId);
String str;
if (id >= 0) {
str = String.format(Locale.US, "%d%d", id, UserConfig.clientUserId);
} else {
str = String.format(Locale.US, "%d", id);
}
if (str.length() > 15) {
str = str.substring(0, 15);
}
@ -440,11 +456,11 @@ public class Utilities {
if (b < 0) {
b += 256;
}
return Math.abs(b) % arrColors.length;
return Math.abs(b) % arr.length;
} catch (Exception e) {
e.printStackTrace();
}
return id % arrColors.length;
return id % arr.length;
}
public static int getColorForId(int id) {
@ -462,7 +478,7 @@ public class Utilities {
}
public static int getGroupAvatarForId(int id) {
return arrGroupsAvatars[getColorIndex(id)];
return arrGroupsAvatars[getColorIndex(-id)];
}
public static String MD5(String md5) {
@ -488,7 +504,7 @@ public class Utilities {
File f = new File(fromPath);
Uri contentUri = Uri.fromFile(f);
mediaScanIntent.setData(contentUri);
applicationContext.sendBroadcast(mediaScanIntent);
ApplicationLoader.applicationContext.sendBroadcast(mediaScanIntent);
}
public static void addMediaToGallery(Uri uri) {
@ -497,13 +513,13 @@ public class Utilities {
}
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
mediaScanIntent.setData(uri);
applicationContext.sendBroadcast(mediaScanIntent);
ApplicationLoader.applicationContext.sendBroadcast(mediaScanIntent);
}
private static File getAlbumDir() {
File storageDir = null;
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
storageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), applicationContext.getResources().getString(R.string.AppName));
storageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), ApplicationLoader.applicationContext.getResources().getString(R.string.AppName));
if (storageDir != null) {
if (! storageDir.mkdirs()) {
if (! storageDir.exists()){
@ -578,7 +594,7 @@ public class Utilities {
/*
String fileName = "VID" + id + ".mp4";
return new File(Utilities.applicationContext.getCacheDir(), fileName);
return new File(ApplicationLoader.applicationContext.getCacheDir(), fileName);
*/
} catch (Exception e) {
e.printStackTrace();

View file

@ -16,6 +16,7 @@ import org.telegram.messenger.MessagesController;
import org.telegram.messenger.R;
import org.telegram.messenger.UserConfig;
import org.telegram.messenger.Utilities;
import org.telegram.ui.ApplicationLoader;
import java.util.AbstractMap;
import java.util.ArrayList;
@ -42,57 +43,57 @@ public class MessageObject {
fromUser = MessagesController.Instance.users.get(message.from_id);
}
if (message.action instanceof TLRPC.TL_messageActionChatCreate) {
messageText = Utilities.applicationContext.getResources().getString(R.string.ActionCreateGroup).replace("un1", Utilities.formatName(fromUser.first_name, fromUser.last_name));
messageText = ApplicationLoader.applicationContext.getResources().getString(R.string.ActionCreateGroup).replace("un1", Utilities.formatName(fromUser.first_name, fromUser.last_name));
} else if (message.action instanceof TLRPC.TL_messageActionChatDeleteUser) {
if (message.action.user_id == message.from_id) {
messageText = Utilities.applicationContext.getResources().getString(R.string.ActionLeftUser).replace("un1", Utilities.formatName(fromUser.first_name, fromUser.last_name));
messageText = ApplicationLoader.applicationContext.getResources().getString(R.string.ActionLeftUser).replace("un1", Utilities.formatName(fromUser.first_name, fromUser.last_name));
} else {
TLRPC.User who = users.get(message.action.user_id);
String str = Utilities.applicationContext.getResources().getString(R.string.ActionKickUser);
String str = ApplicationLoader.applicationContext.getResources().getString(R.string.ActionKickUser);
messageText = str.replace("un2", Utilities.formatName(who.first_name, who.last_name)).replace("un1", Utilities.formatName(fromUser.first_name, fromUser.last_name));
}
} else if (message.action instanceof TLRPC.TL_messageActionChatAddUser) {
TLRPC.User whoUser = users.get(message.action.user_id);
String str = Utilities.applicationContext.getResources().getString(R.string.ActionAddUser);
String str = ApplicationLoader.applicationContext.getResources().getString(R.string.ActionAddUser);
messageText = str.replace("un2", Utilities.formatName(whoUser.first_name, whoUser.last_name)).replace("un1", Utilities.formatName(fromUser.first_name, fromUser.last_name));
} else if (message.action instanceof TLRPC.TL_messageActionChatEditPhoto) {
photoThumbs = new ArrayList<PhotoObject>();
for (TLRPC.PhotoSize size : message.action.photo.sizes) {
photoThumbs.add(new PhotoObject(size));
}
messageText = Utilities.applicationContext.getResources().getString(R.string.ActionChangedPhoto).replace("un1", Utilities.formatName(fromUser.first_name, fromUser.last_name));
messageText = ApplicationLoader.applicationContext.getResources().getString(R.string.ActionChangedPhoto).replace("un1", Utilities.formatName(fromUser.first_name, fromUser.last_name));
} else if (message.action instanceof TLRPC.TL_messageActionChatEditTitle) {
messageText = Utilities.applicationContext.getResources().getString(R.string.ActionChangedTitle).replace("un1", Utilities.formatName(fromUser.first_name, fromUser.last_name)).replace("un2", message.action.title);
messageText = ApplicationLoader.applicationContext.getResources().getString(R.string.ActionChangedTitle).replace("un1", Utilities.formatName(fromUser.first_name, fromUser.last_name)).replace("un2", message.action.title);
} else if (message.action instanceof TLRPC.TL_messageActionChatDeletePhoto) {
messageText = Utilities.applicationContext.getResources().getString(R.string.ActionRemovedPhoto).replace("un1", Utilities.formatName(fromUser.first_name, fromUser.last_name));
messageText = ApplicationLoader.applicationContext.getResources().getString(R.string.ActionRemovedPhoto).replace("un1", Utilities.formatName(fromUser.first_name, fromUser.last_name));
} else if (message.action instanceof TLRPC.TL_messageActionTTLChange) {
if (message.action.ttl != 0) {
String timeString;
if (message.action.ttl == 2) {
timeString = Utilities.applicationContext.getResources().getString(R.string.MessageLifetime2s);
timeString = ApplicationLoader.applicationContext.getResources().getString(R.string.MessageLifetime2s);
} else if (message.action.ttl == 5) {
timeString = Utilities.applicationContext.getResources().getString(R.string.MessageLifetime5s);
timeString = ApplicationLoader.applicationContext.getResources().getString(R.string.MessageLifetime5s);
} else if (message.action.ttl == 60) {
timeString = Utilities.applicationContext.getResources().getString(R.string.MessageLifetime1m);
timeString = ApplicationLoader.applicationContext.getResources().getString(R.string.MessageLifetime1m);
} else if (message.action.ttl == 60 * 60) {
timeString = Utilities.applicationContext.getResources().getString(R.string.MessageLifetime1h);
timeString = ApplicationLoader.applicationContext.getResources().getString(R.string.MessageLifetime1h);
} else if (message.action.ttl == 60 * 60 * 24) {
timeString = Utilities.applicationContext.getResources().getString(R.string.MessageLifetime1d);
timeString = ApplicationLoader.applicationContext.getResources().getString(R.string.MessageLifetime1d);
} else if (message.action.ttl == 60 * 60 * 24 * 7) {
timeString = Utilities.applicationContext.getResources().getString(R.string.MessageLifetime1w);
timeString = ApplicationLoader.applicationContext.getResources().getString(R.string.MessageLifetime1w);
} else {
timeString = String.format("%d", message.action.ttl);
}
if (message.from_id == UserConfig.clientUserId) {
messageText = String.format(Utilities.applicationContext.getResources().getString(R.string.MessageLifetimeChangedOutgoing), timeString);
messageText = String.format(ApplicationLoader.applicationContext.getResources().getString(R.string.MessageLifetimeChangedOutgoing), timeString);
} else {
messageText = String.format(Utilities.applicationContext.getResources().getString(R.string.MessageLifetimeChanged), fromUser.first_name, timeString);
messageText = String.format(ApplicationLoader.applicationContext.getResources().getString(R.string.MessageLifetimeChanged), fromUser.first_name, timeString);
}
} else {
if (message.from_id == UserConfig.clientUserId) {
messageText = String.format(Utilities.applicationContext.getResources().getString(R.string.MessageLifetimeRemoved), Utilities.applicationContext.getResources().getString(R.string.FromYou));
messageText = String.format(ApplicationLoader.applicationContext.getResources().getString(R.string.MessageLifetimeRemoved), ApplicationLoader.applicationContext.getResources().getString(R.string.FromYou));
} else {
messageText = String.format(Utilities.applicationContext.getResources().getString(R.string.MessageLifetimeRemoved), fromUser.first_name);
messageText = String.format(ApplicationLoader.applicationContext.getResources().getString(R.string.MessageLifetimeRemoved), fromUser.first_name);
}
}
}
@ -107,7 +108,7 @@ public class MessageObject {
imagePreview = obj.image;
}
}
messageText = Utilities.applicationContext.getResources().getString(R.string.AttachPhoto);
messageText = ApplicationLoader.applicationContext.getResources().getString(R.string.AttachPhoto);
} else if (message.media instanceof TLRPC.TL_messageMediaVideo) {
photoThumbs = new ArrayList<PhotoObject>();
PhotoObject obj = new PhotoObject(message.media.video.thumb);
@ -115,11 +116,11 @@ public class MessageObject {
if (imagePreview == null && obj.image != null) {
imagePreview = obj.image;
}
messageText = Utilities.applicationContext.getResources().getString(R.string.AttachVideo);
messageText = ApplicationLoader.applicationContext.getResources().getString(R.string.AttachVideo);
} else if (message.media instanceof TLRPC.TL_messageMediaGeo) {
messageText = Utilities.applicationContext.getResources().getString(R.string.AttachLocation);
messageText = ApplicationLoader.applicationContext.getResources().getString(R.string.AttachLocation);
} else if (message.media instanceof TLRPC.TL_messageMediaContact) {
messageText = Utilities.applicationContext.getResources().getString(R.string.AttachContact);
messageText = ApplicationLoader.applicationContext.getResources().getString(R.string.AttachContact);
}
} else {
messageText = message.message;

View file

@ -76,7 +76,6 @@ public class ApplicationActivity extends SherlockFragmentActivity implements Not
}
}
setContentView(R.layout.application_layout);
notificationView = (NotificationView) getLayoutInflater().inflate(R.layout.notification_layout, null);
shadowView = findViewById(R.id.shadow);
NotificationCenter.Instance.addObserver(this, 1234);
NotificationCenter.Instance.addObserver(this, 658);
@ -342,6 +341,9 @@ public class ApplicationActivity extends SherlockFragmentActivity implements Not
@Override
protected void onResume() {
super.onResume();
if (notificationView == null && getLayoutInflater() != null) {
notificationView = (NotificationView) getLayoutInflater().inflate(R.layout.notification_layout, null);
}
fixLayout();
checkForCrashes();
checkForUpdates();
@ -389,7 +391,7 @@ public class ApplicationActivity extends SherlockFragmentActivity implements Not
WindowManager manager = (WindowManager) getSystemService(WINDOW_SERVICE);
Display display = manager.getDefaultDisplay();
int rotation = display.getRotation();
float density = Utilities.applicationContext.getResources().getDisplayMetrics().density;
float density = ApplicationLoader.applicationContext.getResources().getDisplayMetrics().density;
int height;
int currentActionBarHeight = getSupportActionBar().getHeight();
@ -575,7 +577,7 @@ public class ApplicationActivity extends SherlockFragmentActivity implements Not
ApplicationLoader.fragmentsStack.remove(ApplicationLoader.fragmentsStack.size() - 1);
current.onFragmentDestroy();
}
SharedPreferences preferences = Utilities.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
boolean animations = preferences.getBoolean("view_animations", true);
if (animations) {
if (bySwipe) {
@ -614,7 +616,7 @@ public class ApplicationActivity extends SherlockFragmentActivity implements Not
BaseFragment prev = ApplicationLoader.fragmentsStack.get(ApplicationLoader.fragmentsStack.size() - 2);
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction fTrans = fm.beginTransaction();
SharedPreferences preferences = Utilities.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
boolean animations = preferences.getBoolean("view_animations", true);
if (animations) {
if (bySwipe) {

View file

@ -47,6 +47,7 @@ public class ApplicationLoader extends Application {
private static final int PLAY_SERVICES_RESOLUTION_REQUEST = 9000;
public static long lastPauseTime;
public static Bitmap cachedWallpaper = null;
public static Context applicationContext;
public static ApplicationLoader Instance = null;
@ -60,18 +61,19 @@ public class ApplicationLoader extends Application {
java.lang.System.setProperty("java.net.preferIPv4Stack", "true");
java.lang.System.setProperty("java.net.preferIPv6Addresses", "false");
Utilities.applicationContext = getApplicationContext();
applicationContext = getApplicationContext();
Utilities.getTypeface("fonts/rlight.ttf");
UserConfig.loadConfig();
SharedPreferences preferences = getSharedPreferences("Notifications", MODE_PRIVATE);
if (UserConfig.currentUser != null) {
int value = preferences.getInt("version", 0);
if (value != 15) {
UserConfig.contactsHash = "";
UserConfig.lastDateValue = 0;
UserConfig.lastPtsValue = 0;
UserConfig.lastSeqValue = 0;
UserConfig.lastQtsValue = 0;
UserConfig.saveConfig();
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);
@ -80,6 +82,8 @@ public class ApplicationLoader extends Application {
SharedPreferences.Editor editor = preferences.edit();
editor.putInt("version", 15);
editor.commit();
} else {
MessagesStorage init = MessagesStorage.Instance;
}
MessagesController.Instance.users.put(UserConfig.clientUserId, UserConfig.currentUser);
} else {
@ -102,7 +106,7 @@ public class ApplicationLoader extends Application {
if (checkPlayServices()) {
gcm = GoogleCloudMessaging.getInstance(this);
regid = getRegistrationId(Utilities.applicationContext);
regid = getRegistrationId(applicationContext);
if (regid.length() == 0) {
registerInBackground();
@ -171,11 +175,11 @@ public class ApplicationLoader extends Application {
String msg;
try {
if (gcm == null) {
gcm = GoogleCloudMessaging.getInstance(Utilities.applicationContext);
gcm = GoogleCloudMessaging.getInstance(applicationContext);
}
regid = gcm.register(SENDER_ID);
sendRegistrationIdToBackend(true);
storeRegistrationId(Utilities.applicationContext, regid);
storeRegistrationId(applicationContext, regid);
return true;
} catch (IOException ex) {
ex.printStackTrace();
@ -191,7 +195,7 @@ public class ApplicationLoader extends Application {
public void run() {
UserConfig.pushString = regid;
UserConfig.registeredForPush = !isNew;
UserConfig.saveConfig();
UserConfig.saveConfig(false);
MessagesController.Instance.registerForPush(regid);
}
});

View file

@ -281,7 +281,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
NotificationCenter.Instance.addObserver(this, 997);
loading = true;
MessagesController.Instance.loadMessages(dialog_id, 0, 30, 0, true, 0, classGuid);
SharedPreferences preferences = Utilities.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
fontSize = preferences.getInt("fons_size", 16);
return true;
}
@ -360,7 +360,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
ImageView backgroundImage = (ImageView) fragmentView.findViewById(R.id.background_image);
SharedPreferences preferences = Utilities.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
int selectedBackground = preferences.getInt("selectedBackground", 1000001);
int selectedColor = preferences.getInt("selectedColor", 0);
if (selectedColor != 0) {
@ -371,7 +371,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
if (selectedBackground == 1000001) {
backgroundImage.setImageResource(R.drawable.background_hd);
} else {
File toFile = new File(Utilities.applicationContext.getFilesDir(), "wallpaper.jpg");
File toFile = new File(ApplicationLoader.applicationContext.getFilesDir(), "wallpaper.jpg");
if (toFile.exists()) {
if (ApplicationLoader.cachedWallpaper != null) {
backgroundImage.setImageBitmap(ApplicationLoader.cachedWallpaper);
@ -419,11 +419,11 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
}
if (isCustomTheme) {
centerProgress.setIndeterminateDrawable(Utilities.applicationContext.getResources().getDrawable(R.drawable.loading_custom_animation));
centerProgress.setIndeterminateDrawable(ApplicationLoader.applicationContext.getResources().getDrawable(R.drawable.loading_custom_animation));
emptyView.setBackgroundResource(R.drawable.day_box_custom);
} else {
emptyView.setBackgroundResource(R.drawable.day_box);
centerProgress.setIndeterminateDrawable(Utilities.applicationContext.getResources().getDrawable(R.drawable.loading_animation));
centerProgress.setIndeterminateDrawable(ApplicationLoader.applicationContext.getResources().getDrawable(R.drawable.loading_animation));
}
emptyView.setPadding((int)(10 * displayDensity), (int)(26 * displayDensity), (int)(10 * displayDensity), 0);
@ -681,7 +681,9 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
Utilities.hideKeyboard(parentActivity.getCurrentFocus());
}
}
parentActivity.invalidateOptionsMenu();
if (parentActivity != null) {
parentActivity.invalidateOptionsMenu();
}
}
private void addToLoadingFile(String path, ProgressBar bar) {
@ -833,15 +835,13 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
}
if (currentChat != null) {
currentChat = MessagesController.Instance.chats.get(currentChat.id);
actionBar.setTitle(Html.fromHtml("<font color='#006fc8'>" + currentChat.title + "</font>"));
if (title != null) {
title.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
title.setCompoundDrawablePadding(0);
}
} else if (currentUser != null) {
currentUser = MessagesController.Instance.users.get(currentUser.id);
if (currentUser.id != 333000 && !MessagesController.Instance.contactsByPhones.containsKey(currentUser.phone)) {
if (currentUser.id != 333000 && MessagesController.Instance.contactsDict.get(currentUser.id) == null) {
if (currentUser.phone != null && currentUser.phone.length() != 0) {
actionBar.setTitle(Html.fromHtml("<font color='#006fc8'>" + PhoneFormat.Instance.format("+" + currentUser.phone) + "</font>"));
} else {
@ -1044,12 +1044,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
return;
}
Bitmap thumb = ThumbnailUtils.createVideoThumbnail(videoPath, MediaStore.Video.Thumbnails.MINI_KIND);
TLRPC.PhotoSize size;
if (currentEncryptedChat == null) {
size = FileLoader.scaleAndSaveImage(thumb, 320, 320, 87, false);
} else {
size = FileLoader.scaleAndSaveImage(thumb, 90, 90, 55, true);
}
TLRPC.PhotoSize size = FileLoader.scaleAndSaveImage(thumb, 90, 90, 55, currentEncryptedChat != null);
if (size == null) {
return;
}
@ -1064,7 +1059,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
video.size = (int)temp.length();
}
UserConfig.lastLocalId--;
UserConfig.saveConfig();
UserConfig.saveConfig(false);
MediaPlayer mp = MediaPlayer.create(parentActivity, Uri.fromFile(new File(videoPath)));
video.duration = (int)Math.ceil(mp.getDuration() / 1000.0f);
@ -1293,7 +1288,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
}
}
} else if (id == MessagesController.closeChats) {
if (messsageEditText.isFocused()) {
if (messsageEditText != null && messsageEditText.isFocused()) {
Utilities.hideKeyboard(messsageEditText);
}
removeSelfFromStack();
@ -1481,7 +1476,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
if (currentUser == null) {
topPanel.setVisibility(View.GONE);
} else {
if (currentUser.phone != null && currentUser.phone.length() != 0 && MessagesController.Instance.contactsByPhones.get(currentUser.phone) != null) {
if (currentUser.phone != null && currentUser.phone.length() != 0 && MessagesController.Instance.contactsDict.get(currentUser.id) != null) {
topPanel.setVisibility(View.GONE);
} else {
topPanel.setVisibility(View.VISIBLE);
@ -1657,7 +1652,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
((ApplicationActivity)parentActivity).showActionBar();
((ApplicationActivity)parentActivity).updateActionBar();
fixLayout();
SharedPreferences preferences = Utilities.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
String lastMessageText = preferences.getString("dialog_" + dialog_id, null);
if (lastMessageText != null) {
SharedPreferences.Editor editor = preferences.edit();
@ -1708,7 +1703,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
MessagesController.Instance.openned_dialog_id = 0;
if (messsageEditText != null && messsageEditText.length() != 0) {
SharedPreferences preferences = Utilities.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putString("dialog_" + dialog_id, messsageEditText.getText().toString());
editor.commit();
@ -1725,12 +1720,12 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
chatListView.getViewTreeObserver().removeOnPreDrawListener(this);
return false;
}
WindowManager manager = (WindowManager) Utilities.applicationContext.getSystemService(Activity.WINDOW_SERVICE);
WindowManager manager = (WindowManager) ApplicationLoader.applicationContext.getSystemService(Activity.WINDOW_SERVICE);
Display display = manager.getDefaultDisplay();
int rotation = display.getRotation();
int height;
int currentActionBarHeight = parentActivity.getSupportActionBar().getHeight();
float density = Utilities.applicationContext.getResources().getDisplayMetrics().density;
float density = ApplicationLoader.applicationContext.getResources().getDisplayMetrics().density;
if (currentActionBarHeight != 48 * density && currentActionBarHeight != 40 * density) {
height = currentActionBarHeight;
} else {
@ -2198,7 +2193,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
public boolean isGoogleMapsInstalled() {
try {
ApplicationInfo info = Utilities.applicationContext.getPackageManager().getApplicationInfo("com.google.android.apps.maps", 0 );
ApplicationInfo info = ApplicationLoader.applicationContext.getPackageManager().getApplicationInfo("com.google.android.apps.maps", 0 );
return true;
} catch(PackageManager.NameNotFoundException e) {
AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
@ -2216,9 +2211,9 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
}
});
builder.setNegativeButton(R.string.Cancel, null);
AlertDialog dialog = builder.create();
dialog.setCanceledOnTouchOutside(true);
dialog.show();
visibleDialog = builder.create();
visibleDialog.setCanceledOnTouchOutside(true);
visibleDialog.show();
return false;
}
}
@ -2417,9 +2412,9 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
ProgressBar progressBar = (ProgressBar)view.findViewById(R.id.progress);
progressBar.setIndeterminate(true);
if (isCustomTheme) {
progressBar.setIndeterminateDrawable(Utilities.applicationContext.getResources().getDrawable(R.drawable.loading_custom_animation));
progressBar.setIndeterminateDrawable(ApplicationLoader.applicationContext.getResources().getDrawable(R.drawable.loading_custom_animation));
} else {
progressBar.setIndeterminateDrawable(Utilities.applicationContext.getResources().getDrawable(R.drawable.loading_animation));
progressBar.setIndeterminateDrawable(ApplicationLoader.applicationContext.getResources().getDrawable(R.drawable.loading_animation));
}
}
return view;
@ -2755,7 +2750,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
}
int placeHolderId = Utilities.getUserAvatarForId(contactUser.id);
contactAvatar.setImage(photo, "50_50", placeHolderId);
if (contactUser.id != UserConfig.clientUserId && !MessagesController.Instance.contactsByPhones.containsKey(contactUser.phone)) {
if (contactUser.id != UserConfig.clientUserId && MessagesController.Instance.contactsDict.get(contactUser.id) == null) {
addContactView.setVisibility(View.VISIBLE);
} else {
addContactView.setVisibility(View.GONE);
@ -3234,6 +3229,19 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
if (forwardedUserText != null) {
forwardedUserText.setTypeface(typeface);
forwardedUserText.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
TLRPC.User fwdUser = MessagesController.Instance.users.get(message.messageOwner.fwd_from_id);
if (fwdUser != null && fwdUser.id != UserConfig.clientUserId) {
UserProfileActivity fragment = new UserProfileActivity();
Bundle args = new Bundle();
args.putInt("user_id", fwdUser.id);
fragment.setArguments(args);
((ApplicationActivity)parentActivity).presentFragment(fragment, "user_" + fwdUser.id, false);
}
}
});
}
if (videoTimeText != null) {
videoTimeText.setTypeface(typeface);

View file

@ -225,7 +225,7 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen
((ApplicationActivity)parentActivity).presentFragment(fragment, "user_" + user_id, false);
} else {
if (size + 7 == i) {
if (info.participants.size() < 100) {
if (info.participants.size() < 200) {
openAddMenu();
} else {
kickUser(null);
@ -375,7 +375,7 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen
int rotation = display.getRotation();
int height;
int currentActionBarHeight = parentActivity.getSupportActionBar().getHeight();
float density = Utilities.applicationContext.getResources().getDisplayMetrics().density;
float density = ApplicationLoader.applicationContext.getResources().getDisplayMetrics().density;
if (currentActionBarHeight != 48 * density && currentActionBarHeight != 40 * density) {
height = currentActionBarHeight;
} else {
@ -539,7 +539,7 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen
int count = 6;
if (info != null && !(info instanceof TLRPC.TL_chatParticipantsForbidden)) {
count += info.participants.size() + 2;
if (info.participants.size() < 100) {
if (info.participants.size() < 200) {
count++;
}
}
@ -673,7 +673,7 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen
TextView textView = (TextView)view.findViewById(R.id.settings_row_text);
View divider = view.findViewById(R.id.settings_row_divider);
if (i == 2) {
SharedPreferences preferences = parentActivity.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences preferences = mContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
String key = "notify_" + (-chat_id);
boolean value = preferences.getBoolean(key, true);
ImageView checkButton = (ImageView)view.findViewById(R.id.settings_row_check_button);
@ -696,7 +696,7 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen
detailTextView.setTypeface(typeface);
View divider = view.findViewById(R.id.settings_row_divider);
if (i == 3) {
SharedPreferences preferences = parentActivity.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences preferences = mContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
String name = preferences.getString("sound_chat_" + chat_id, getStringEntry(R.string.Default));
if (name.equals("NoSound")) {
detailTextView.setText(getStringEntry(R.string.NoSound));
@ -836,7 +836,7 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen
return 4;
} else {
if (size + 7 == i) {
if (info != null && info.participants.size() < 100) {
if (info != null && info.participants.size() < 200) {
return 5;
} else {
return 6;

View file

@ -111,7 +111,7 @@ public class ChatProfileChangeNameActivity extends BaseFragment {
int rotation = display.getRotation();
int height;
int currentActionBarHeight = parentActivity.getSupportActionBar().getHeight();
float density = Utilities.applicationContext.getResources().getDisplayMetrics().density;
float density = ApplicationLoader.applicationContext.getResources().getDisplayMetrics().density;
if (currentActionBarHeight != 48 * density && currentActionBarHeight != 40 * density) {
height = currentActionBarHeight;
} else {
@ -173,7 +173,7 @@ public class ChatProfileChangeNameActivity extends BaseFragment {
}
((ApplicationActivity)parentActivity).updateActionBar();
fixLayout();
SharedPreferences preferences = Utilities.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
boolean animations = preferences.getBoolean("view_animations", true);
if (!animations) {
firstNameField.requestFocus();

View file

@ -219,7 +219,7 @@ public class ContactAddActivity extends BaseFragment implements NotificationCent
((ApplicationActivity)parentActivity).updateActionBar();
fixLayout();
SharedPreferences preferences = Utilities.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
boolean animations = preferences.getBoolean("view_animations", true);
if (!animations) {
firstNameField.requestFocus();
@ -245,7 +245,7 @@ public class ContactAddActivity extends BaseFragment implements NotificationCent
int rotation = display.getRotation();
int height;
int currentActionBarHeight = parentActivity.getSupportActionBar().getHeight();
float density = Utilities.applicationContext.getResources().getDisplayMetrics().density;
float density = ApplicationLoader.applicationContext.getResources().getDisplayMetrics().density;
if (currentActionBarHeight != 48 * density && currentActionBarHeight != 40 * density) {
height = currentActionBarHeight;
} else {

View file

@ -34,6 +34,8 @@ import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;
import com.actionbarsherlock.widget.SearchView;
import org.telegram.PhoneFormat.PhoneFormat;
import org.telegram.TL.TLRPC;
import org.telegram.messenger.ConnectionsManager;
import org.telegram.messenger.MessagesController;
@ -231,7 +233,8 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
if (usePhone == null) {
usePhone = phone;
}
TLRPC.TL_contact cLocal = MessagesController.Instance.contactsByPhones.get(phone);
String cleanPhone = PhoneFormat.stripExceptNumbers(usePhone);
TLRPC.TL_contact cLocal = MessagesController.Instance.contactsByPhones.get(cleanPhone);
if (cLocal != null) {
if (cLocal.user_id == UserConfig.clientUserId) {
return;
@ -257,7 +260,7 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
@Override
public void onClick(DialogInterface dialogInterface, int i) {
try {
String number = "+" + arg1;
String number = arg1;
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.fromParts("sms", number, null));
intent.putExtra("sms_body", getStringEntry(R.string.InviteText));
startActivity(intent);
@ -347,7 +350,7 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
int rotation = display.getRotation();
int height;
int currentActionBarHeight = parentActivity.getSupportActionBar().getHeight();
float density = Utilities.applicationContext.getResources().getDisplayMetrics().density;
float density = ApplicationLoader.applicationContext.getResources().getDisplayMetrics().density;
if (currentActionBarHeight != 48 * density && currentActionBarHeight != 40 * density) {
height = currentActionBarHeight;
} else {
@ -529,7 +532,7 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
if (s.length() != 0) {
searchWas = true;
if (listView != null) {
float density = Utilities.applicationContext.getResources().getDisplayMetrics().density;
float density = ApplicationLoader.applicationContext.getResources().getDisplayMetrics().density;
listView.setPadding((int)(density * 16), listView.getPaddingTop(), (int)(density * 16), listView.getPaddingBottom());
listView.setAdapter(searchListViewAdapter);
if(android.os.Build.VERSION.SDK_INT >= 11) {
@ -562,7 +565,7 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
searchWas = false;
ViewGroup group = (ViewGroup)listView.getParent();
listView.setAdapter(listViewAdapter);
float density = Utilities.applicationContext.getResources().getDisplayMetrics().density;
float density = ApplicationLoader.applicationContext.getResources().getDisplayMetrics().density;
if (!isRTL) {
listView.setPadding((int)(density * 16), listView.getPaddingTop(), (int)(density * 30), listView.getPaddingBottom());
} else {

View file

@ -179,7 +179,7 @@ public class GalleryImageViewer extends AbstractGalleryActivity implements Notif
localPagerAdapter = new LocalPagerAdapter(imagesArr, imagesByIds);
}
float density = Utilities.applicationContext.getResources().getDisplayMetrics().density;
float density = ApplicationLoader.applicationContext.getResources().getDisplayMetrics().density;
mViewPager.setPageMargin((int)(20 * density));
mViewPager.setOffscreenPageLimit(1);

View file

@ -161,7 +161,7 @@ public class GroupCreateActivity extends BaseFragment implements NotificationCen
} else {
doneTextView.setText(getStringEntry(R.string.Done) + " (" + selectedContacts.size() + ")");
}
countTextView.setText(selectedContacts.size() + "/100");
countTextView.setText(selectedContacts.size() + "/200");
listView.invalidateViews();
} else {
search = true;
@ -219,7 +219,7 @@ public class GroupCreateActivity extends BaseFragment implements NotificationCen
userSelectEditText.setSelection(text.length());
ignoreChange = false;
} else {
if (selectedContacts.size() == 100) {
if (selectedContacts.size() == 200) {
return;
}
ignoreChange = true;
@ -232,7 +232,7 @@ public class GroupCreateActivity extends BaseFragment implements NotificationCen
} else {
doneTextView.setText(getStringEntry(R.string.Done) + " (" + selectedContacts.size() + ")");
}
countTextView.setText(selectedContacts.size() + "/100");
countTextView.setText(selectedContacts.size() + "/200");
if (searching || searchWas) {
searching = false;
searchWas = false;
@ -280,7 +280,7 @@ public class GroupCreateActivity extends BaseFragment implements NotificationCen
int rotation = display.getRotation();
int height;
int currentActionBarHeight = parentActivity.getSupportActionBar().getHeight();
float density = Utilities.applicationContext.getResources().getDisplayMetrics().density;
float density = ApplicationLoader.applicationContext.getResources().getDisplayMetrics().density;
if (currentActionBarHeight != 48 * density && currentActionBarHeight != 40 * density) {
height = currentActionBarHeight;
} else {

View file

@ -156,7 +156,7 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati
int rotation = display.getRotation();
int height;
int currentActionBarHeight = parentActivity.getSupportActionBar().getHeight();
float density = Utilities.applicationContext.getResources().getDisplayMetrics().density;
float density = ApplicationLoader.applicationContext.getResources().getDisplayMetrics().density;
if (currentActionBarHeight != 48 * density && currentActionBarHeight != 40 * density) {
height = currentActionBarHeight;
} else {

View file

@ -133,7 +133,7 @@ public class IdenticonActivity extends BaseFragment {
int rotation = display.getRotation();
int height;
int currentActionBarHeight = parentActivity.getSupportActionBar().getHeight();
float density = Utilities.applicationContext.getResources().getDisplayMetrics().density;
float density = ApplicationLoader.applicationContext.getResources().getDisplayMetrics().density;
if (currentActionBarHeight != 48 * density && currentActionBarHeight != 40 * density) {
height = currentActionBarHeight;
} else {
@ -154,7 +154,7 @@ public class IdenticonActivity extends BaseFragment {
TextView title = (TextView)parentActivity.findViewById(R.id.abs__action_bar_title);
if (title == null) {
final int subtitleId = Utilities.applicationContext.getResources().getIdentifier("action_bar_title", "id", "android");
final int subtitleId = ApplicationLoader.applicationContext.getResources().getIdentifier("action_bar_title", "id", "android");
title = (TextView)parentActivity.findViewById(subtitleId);
}
if (title != null) {

View file

@ -261,7 +261,7 @@ public class IntroActivity extends SherlockFragmentActivity {
WindowManager manager = (WindowManager)getSystemService(Context.WINDOW_SERVICE);
Display display = manager.getDefaultDisplay();
int rotation = display.getRotation();
density = Utilities.applicationContext.getResources().getDisplayMetrics().density;
density = ApplicationLoader.applicationContext.getResources().getDisplayMetrics().density;
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams)parentSlidingView.getLayoutParams();
FrameLayout.LayoutParams buttonParams = (FrameLayout.LayoutParams)startMessagingButton.getLayoutParams();

View file

@ -54,10 +54,12 @@ public class LaunchActivity extends PausableActivity {
cursor.close();
}
}
if (path.startsWith("file:")) {
path = path.replace("file://", "");
if (path != null) {
if (path.startsWith("file:")) {
path = path.replace("file://", "");
}
NotificationCenter.Instance.addToMemCache(533, path);
}
NotificationCenter.Instance.addToMemCache(533, path);
} else if (intent.getType().startsWith("video/")) {
String path = intent.getParcelableExtra(Intent.EXTRA_STREAM).toString();
if (path.startsWith("content:")) {
@ -68,10 +70,12 @@ public class LaunchActivity extends PausableActivity {
cursor.close();
}
}
if (path.startsWith("file:")) {
path = path.replace("file://", "");
if (path != null) {
if (path.startsWith("file:")) {
path = path.replace("file://", "");
}
NotificationCenter.Instance.addToMemCache(534, path);
}
NotificationCenter.Instance.addToMemCache(534, path);
} else if (intent.getType().equals("text/plain")) {
String text = intent.getStringExtra(Intent.EXTRA_TEXT);
if (text.length() != 0) {

View file

@ -227,7 +227,7 @@ public class LocationActivity extends BaseFragment implements LocationListener,
bottomView = fragmentView.findViewById(R.id.location_bottom_view);
sendButton = (TextView)fragmentView.findViewById(R.id.location_send_button);
getFragmentManager().beginTransaction().replace(R.id.map_view, mapFragment).commit();
getChildFragmentManager().beginTransaction().replace(R.id.map_view, mapFragment).commit();
} else {
ViewGroup parent = (ViewGroup)fragmentView.getParent();
if (parent != null) {
@ -305,14 +305,13 @@ public class LocationActivity extends BaseFragment implements LocationListener,
if (isGPSEnabled || isNetworkEnabled) {
if (isGPSEnabled) {
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000 * 3 * 1, 0, this);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000 * 3 * 1, 1, this);
if (locationManager != null) {
location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
}
}
if (location == null && isNetworkEnabled) {
long MIN_DISTANCE_CHANGE_FOR_UPDATES = 10;
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000 * 3 * 1, 0, this);
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000 * 3 * 1, 1, this);
if (locationManager != null) {
location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
}
@ -341,9 +340,9 @@ public class LocationActivity extends BaseFragment implements LocationListener,
if (userLocation != null && distanceTextView != null) {
float distance = location.distanceTo(userLocation);
if (distance < 1000) {
distanceTextView.setText(String.format("%d %s", (int)(distance), Utilities.applicationContext.getString(R.string.MetersAway)));
distanceTextView.setText(String.format("%d %s", (int)(distance), ApplicationLoader.applicationContext.getString(R.string.MetersAway)));
} else {
distanceTextView.setText(String.format("%.2f %s", distance / 1000.0f, Utilities.applicationContext.getString(R.string.KMetersAway)));
distanceTextView.setText(String.format("%.2f %s", distance / 1000.0f, ApplicationLoader.applicationContext.getString(R.string.KMetersAway)));
}
}
} else {
@ -365,8 +364,13 @@ public class LocationActivity extends BaseFragment implements LocationListener,
}
@Override
public void onLocationChanged(Location location) {
positionMarker(location);
public void onLocationChanged(final Location location) {
Utilities.RunOnUIThread(new Runnable() {
@Override
public void run() {
positionMarker(location);
}
});
}
@Override

View file

@ -76,7 +76,7 @@ public class LoginActivity extends SherlockFragmentActivity implements NonSwipea
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setTitle(LoginActivity.this.getString(R.string.AppName));
builder.setMessage(message);
builder.setPositiveButton(Utilities.applicationContext.getString(R.string.OK), null);
builder.setPositiveButton(ApplicationLoader.applicationContext.getString(R.string.OK), null);
builder.show().setCanceledOnTouchOutside(true);
}
}
@ -160,7 +160,7 @@ public class LoginActivity extends SherlockFragmentActivity implements NonSwipea
super.onCreate(savedInstanceState);
setContentView(R.layout.login_layout);
Utilities.applicationContext = this.getApplicationContext();
ApplicationLoader.applicationContext = this.getApplicationContext();
ConnectionsManager inst = ConnectionsManager.Instance;
Typeface typeface = Utilities.getTypeface("fonts/rlight.ttf");

View file

@ -296,7 +296,7 @@ public class MediaActivity extends BaseFragment implements NotificationCenter.No
int rotation = display.getRotation();
int height;
int currentActionBarHeight = parentActivity.getSupportActionBar().getHeight();
float density = Utilities.applicationContext.getResources().getDisplayMetrics().density;
float density = ApplicationLoader.applicationContext.getResources().getDisplayMetrics().density;
if (currentActionBarHeight != 48 * density && currentActionBarHeight != 40 * density) {
height = currentActionBarHeight;
} else {

View file

@ -92,6 +92,7 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter
NotificationCenter.Instance.addObserver(this, MessagesController.reloadSearchResults);
NotificationCenter.Instance.addObserver(this, MessagesController.userPrintUpdateAll);
NotificationCenter.Instance.addObserver(this, MessagesController.encryptedChatUpdated);
NotificationCenter.Instance.addObserver(this, MessagesController.contactsDidLoaded);
NotificationCenter.Instance.addObserver(this, 1234);
if (getArguments() != null) {
onlySelect = getArguments().getBoolean("onlySelect", false);
@ -109,6 +110,7 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter
NotificationCenter.Instance.removeObserver(this, MessagesController.reloadSearchResults);
NotificationCenter.Instance.removeObserver(this, MessagesController.userPrintUpdateAll);
NotificationCenter.Instance.removeObserver(this, MessagesController.encryptedChatUpdated);
NotificationCenter.Instance.removeObserver(this, MessagesController.contactsDidLoaded);
NotificationCenter.Instance.removeObserver(this, 1234);
delegate = null;
}
@ -328,7 +330,7 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter
view = (ImageView)parentActivity.findViewById(com.actionbarsherlock.R.id.abs__home);
}
if (view != null) {
view.setPadding((int)(Utilities.applicationContext.getResources().getDisplayMetrics().density * 6), 0, (int)(Utilities.applicationContext.getResources().getDisplayMetrics().density * 6), 0);
view.setPadding((int)(ApplicationLoader.applicationContext.getResources().getDisplayMetrics().density * 6), 0, (int)(ApplicationLoader.applicationContext.getResources().getDisplayMetrics().density * 6), 0);
}
actionBar.setHomeButtonEnabled(false);
actionBar.setDisplayShowTitleEnabled(true);
@ -420,6 +422,10 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter
if (messagesListView != null) {
updateVisibleRows();
}
} else if (id == MessagesController.contactsDidLoaded) {
if (messagesListView != null) {
updateVisibleRows();
}
}
}
@ -453,7 +459,7 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter
WindowManager manager = (WindowManager) parentActivity.getSystemService(Context.WINDOW_SERVICE);
Display display = manager.getDefaultDisplay();
int rotation = display.getRotation();
density = Utilities.applicationContext.getResources().getDisplayMetrics().density;
density = ApplicationLoader.applicationContext.getResources().getDisplayMetrics().density;
int height;
int currentActionBarHeight = parentActivity.getSupportActionBar().getHeight();
@ -1043,8 +1049,8 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter
nameTextView.setText(chat.title);
nameTextView.setTextColor(0xff000000);
} else if (user != null) {
if (user.id != 333000 && !MessagesController.Instance.contactsByPhones.containsKey(user.phone)) {
if (MessagesController.Instance.contactsByPhones.isEmpty() && MessagesController.Instance.loadingContacts) {
if (user.id != 333000 && MessagesController.Instance.contactsDict.get(user.id) == null) {
if (MessagesController.Instance.contactsDict.size() == 0 && MessagesController.Instance.loadingContacts) {
nameTextView.setTextColor(0xff000000);
nameTextView.setText(Utilities.formatName(user.first_name, user.last_name));
} else {

View file

@ -183,7 +183,7 @@ public class ScreenSlidePageFragmentPhone extends SlideFragment implements Adapt
}
});
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(Utilities.applicationContext, R.layout.login_country_textview, countriesArray);
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(ApplicationLoader.applicationContext, R.layout.login_country_textview, countriesArray);
dataAdapter.setDropDownViewResource(R.layout.login_country_dropdown);
countrySpinner.setAdapter(dataAdapter);
@ -205,7 +205,7 @@ public class ScreenSlidePageFragmentPhone extends SlideFragment implements Adapt
String country = "RU";
try {
TelephonyManager telephonyManager = (TelephonyManager)Utilities.applicationContext.getSystemService(Context.TELEPHONY_SERVICE);
TelephonyManager telephonyManager = (TelephonyManager)ApplicationLoader.applicationContext.getSystemService(Context.TELEPHONY_SERVICE);
if (telephonyManager != null) {
country = telephonyManager.getSimCountryIso().toUpperCase();
}
@ -215,7 +215,7 @@ public class ScreenSlidePageFragmentPhone extends SlideFragment implements Adapt
if (country == null || country.length() == 0) {
try {
Locale current = Utilities.applicationContext.getResources().getConfiguration().locale;
Locale current = ApplicationLoader.applicationContext.getResources().getConfiguration().locale;
country = current.getCountry().toUpperCase();
} catch (Exception e) {
e.printStackTrace();
@ -299,8 +299,8 @@ public class ScreenSlidePageFragmentPhone extends SlideFragment implements Adapt
TLRPC.TL_auth_sendCode req = new TLRPC.TL_auth_sendCode();
String phone = "" + codeField.getText() + phoneField.getText();
phone = phone.replace("+", "");
req.api_hash = "5bce48dc7d331e62c955669eb7233217";
req.api_id = 2458;
req.api_hash = "eb06d4abfb49dc3eeb1aeb98ae0f581e";
req.api_id = 6;
req.sms_type = 0;
req.phone_number = phone;
req.lang_code = Locale.getDefault().getCountry();
@ -330,11 +330,11 @@ public class ScreenSlidePageFragmentPhone extends SlideFragment implements Adapt
} else {
if (error.text != null) {
if (error.text.contains("PHONE_NUMBER_INVALID")) {
delegate.needShowAlert(Utilities.applicationContext.getString(R.string.InvalidPhoneNumber));
delegate.needShowAlert(ApplicationLoader.applicationContext.getString(R.string.InvalidPhoneNumber));
} else if (error.text.contains("PHONE_CODE_EMPTY") || error.text.contains("PHONE_CODE_INVALID")) {
delegate.needShowAlert(Utilities.applicationContext.getString(R.string.InvalidCode));
delegate.needShowAlert(ApplicationLoader.applicationContext.getString(R.string.InvalidCode));
} else if (error.text.contains("PHONE_CODE_EXPIRED")) {
delegate.needShowAlert(Utilities.applicationContext.getString(R.string.CodeExpired));
delegate.needShowAlert(ApplicationLoader.applicationContext.getString(R.string.CodeExpired));
} else {
delegate.needShowAlert(error.text);
}

View file

@ -196,7 +196,7 @@ public class ScreenSlidePageFragmentRegister extends SlideFragment {
UserConfig.currentUser = user;
UserConfig.clientActivated = true;
UserConfig.clientUserId = user.id;
UserConfig.saveConfig();
UserConfig.saveConfig(true);
ArrayList<TLRPC.User> users = new ArrayList<TLRPC.User>();
users.add(user);
MessagesStorage.Instance.putUsersAndChats(users, null, true, true);
@ -208,15 +208,15 @@ public class ScreenSlidePageFragmentRegister extends SlideFragment {
});
} else {
if (error.text.contains("PHONE_NUMBER_INVALID")) {
delegate.needShowAlert(Utilities.applicationContext.getString(R.string.InvalidPhoneNumber));
delegate.needShowAlert(ApplicationLoader.applicationContext.getString(R.string.InvalidPhoneNumber));
} else if (error.text.contains("PHONE_CODE_EMPTY") || error.text.contains("PHONE_CODE_INVALID")) {
delegate.needShowAlert(Utilities.applicationContext.getString(R.string.InvalidCode));
delegate.needShowAlert(ApplicationLoader.applicationContext.getString(R.string.InvalidCode));
} else if (error.text.contains("PHONE_CODE_EXPIRED")) {
delegate.needShowAlert(Utilities.applicationContext.getString(R.string.CodeExpired));
delegate.needShowAlert(ApplicationLoader.applicationContext.getString(R.string.CodeExpired));
} else if (error.text.contains("FIRSTNAME_INVALID")) {
delegate.needShowAlert(Utilities.applicationContext.getString(R.string.FirstName));
delegate.needShowAlert(ApplicationLoader.applicationContext.getString(R.string.FirstName));
} else if (error.text.contains("LASTNAME_INVALID")) {
delegate.needShowAlert(Utilities.applicationContext.getString(R.string.LastName));
delegate.needShowAlert(ApplicationLoader.applicationContext.getString(R.string.LastName));
} else {
delegate.needShowAlert(error.text);
}

View file

@ -119,7 +119,7 @@ public class ScreenSlidePageFragmentSms extends SlideFragment implements Notific
registered = params.get("registered");
String number = PhoneFormat.Instance.format(phone);
confirmTextView.setText(Html.fromHtml(String.format(Utilities.applicationContext.getResources().getString(R.string.SentSmsCode) + " <b>%s</b>", number)));
confirmTextView.setText(Html.fromHtml(String.format(ApplicationLoader.applicationContext.getResources().getString(R.string.SentSmsCode) + " <b>%s</b>", number)));
Utilities.showKeyboard(codeField);
codeField.requestFocus();
@ -129,7 +129,7 @@ public class ScreenSlidePageFragmentSms extends SlideFragment implements Notific
timeTimer.cancel();
timeTimer = null;
}
timeText.setText(String.format("%s 1:00", Utilities.applicationContext.getResources().getString(R.string.CallText)));
timeText.setText(String.format("%s 1:00", ApplicationLoader.applicationContext.getResources().getString(R.string.CallText)));
lastCurrentTime = System.currentTimeMillis();
timeTimer = new Timer();
timeTimer.schedule(new TimerTask() {
@ -145,9 +145,9 @@ public class ScreenSlidePageFragmentSms extends SlideFragment implements Notific
if (time >= 1000) {
int minutes = time / 1000 / 60;
int seconds = time / 1000 - minutes * 60;
timeText.setText(String.format("%s %d:%02d", Utilities.applicationContext.getResources().getString(R.string.CallText), minutes, seconds));
timeText.setText(String.format("%s %d:%02d", ApplicationLoader.applicationContext.getResources().getString(R.string.CallText), minutes, seconds));
} else {
timeText.setText(Utilities.applicationContext.getResources().getString(R.string.Calling));
timeText.setText(ApplicationLoader.applicationContext.getResources().getString(R.string.Calling));
if (timeTimer != null) {
timeTimer.cancel();
timeTimer = null;
@ -201,7 +201,7 @@ public class ScreenSlidePageFragmentSms extends SlideFragment implements Notific
UserConfig.currentUser = res.user;
UserConfig.clientActivated = true;
UserConfig.clientUserId = res.user.id;
UserConfig.saveConfig();
UserConfig.saveConfig(true);
ArrayList<TLRPC.User> users = new ArrayList<TLRPC.User>();
users.add(UserConfig.currentUser);
MessagesStorage.Instance.putUsersAndChats(users, null, true, true);
@ -229,11 +229,11 @@ public class ScreenSlidePageFragmentSms extends SlideFragment implements Notific
});
} else {
if (error.text.contains("PHONE_NUMBER_INVALID")) {
delegate.needShowAlert(Utilities.applicationContext.getString(R.string.InvalidPhoneNumber));
delegate.needShowAlert(ApplicationLoader.applicationContext.getString(R.string.InvalidPhoneNumber));
} else if (error.text.contains("PHONE_CODE_EMPTY") || error.text.contains("PHONE_CODE_INVALID")) {
delegate.needShowAlert(Utilities.applicationContext.getString(R.string.InvalidCode));
delegate.needShowAlert(ApplicationLoader.applicationContext.getString(R.string.InvalidCode));
} else if (error.text.contains("PHONE_CODE_EXPIRED")) {
delegate.needShowAlert(Utilities.applicationContext.getString(R.string.CodeExpired));
delegate.needShowAlert(ApplicationLoader.applicationContext.getString(R.string.CodeExpired));
} else {
delegate.needShowAlert(error.text);
}

View file

@ -140,7 +140,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
builder.setItems(new CharSequence[]{String.format("%d", 16), String.format("%d", 17), String.format("%d", 18), String.format("%d", 19), String.format("%d", 20)}, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
SharedPreferences preferences = Utilities.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putInt("fons_size", 16 + which);
editor.commit();
@ -152,7 +152,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
builder.setNegativeButton(getStringEntry(R.string.Cancel), null);
builder.show().setCanceledOnTouchOutside(true);
} else if (i == enableAnimationsRow) {
SharedPreferences preferences = Utilities.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
boolean animations = preferences.getBoolean("view_animations", true);
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean("view_animations", !animations);
@ -270,7 +270,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
int rotation = display.getRotation();
int height;
int currentActionBarHeight = parentActivity.getSupportActionBar().getHeight();
float density = Utilities.applicationContext.getResources().getDisplayMetrics().density;
float density = ApplicationLoader.applicationContext.getResources().getDisplayMetrics().density;
if (currentActionBarHeight != 48 * density && currentActionBarHeight != 40 * density) {
height = currentActionBarHeight;
} else {
@ -504,7 +504,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
divider.setVisibility(View.VISIBLE);
ImageView checkButton = (ImageView)view.findViewById(R.id.settings_row_check_button);
SharedPreferences preferences = Utilities.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
boolean animations = preferences.getBoolean("view_animations", true);
if (animations) {
checkButton.setImageResource(R.drawable.btn_check_on);
@ -559,10 +559,10 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
detailTextView.setTypeface(typeface);
View divider = view.findViewById(R.id.settings_row_divider);
if (i == textSizeRow) {
SharedPreferences preferences = Utilities.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
int size = preferences.getInt("fons_size", 16);
detailTextView.setText(String.format("%d", size));
textView.setText(Utilities.applicationContext.getString(R.string.TextSize));
textView.setText(ApplicationLoader.applicationContext.getString(R.string.TextSize));
divider.setVisibility(View.VISIBLE);
}
}

View file

@ -305,7 +305,7 @@ public class SettingsBlockedUsers extends BaseFragment implements NotificationCe
int rotation = display.getRotation();
int height;
int currentActionBarHeight = parentActivity.getSupportActionBar().getHeight();
float density = Utilities.applicationContext.getResources().getDisplayMetrics().density;
float density = ApplicationLoader.applicationContext.getResources().getDisplayMetrics().density;
if (currentActionBarHeight != 48 * density && currentActionBarHeight != 40 * density) {
height = currentActionBarHeight;
} else {

View file

@ -73,7 +73,7 @@ public class SettingsChangeNameActivity extends BaseFragment {
int rotation = display.getRotation();
int height;
int currentActionBarHeight = parentActivity.getSupportActionBar().getHeight();
float density = Utilities.applicationContext.getResources().getDisplayMetrics().density;
float density = ApplicationLoader.applicationContext.getResources().getDisplayMetrics().density;
if (currentActionBarHeight != 48 * density && currentActionBarHeight != 40 * density) {
height = currentActionBarHeight;
} else {
@ -130,7 +130,7 @@ public class SettingsChangeNameActivity extends BaseFragment {
fixLayout();
SharedPreferences preferences = Utilities.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
boolean animations = preferences.getBoolean("view_animations", true);
if (!animations) {
firstNameField.requestFocus();
@ -226,7 +226,7 @@ public class SettingsChangeNameActivity extends BaseFragment {
user.first_name = req.first_name;
user.last_name = req.last_name;
}
UserConfig.saveConfig();
UserConfig.saveConfig(true);
NotificationCenter.Instance.postNotificationName(MessagesController.updateInterfaces, MessagesController.UPDATE_MASK_ALL);
ConnectionsManager.Instance.performRpc(req, new RPCRequest.RPCRequestDelegate() {
@Override

View file

@ -65,7 +65,7 @@ public class SettingsNotificationsActivity extends BaseFragment {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
if (i == 1 || i == 6) {
SharedPreferences preferences = parentActivity.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
boolean enabled = false;
if (i == 1) {
@ -96,7 +96,7 @@ public class SettingsNotificationsActivity extends BaseFragment {
}
ConnectionsManager.Instance.performRpc(req, null, null, true, RPCRequest.RPCRequestClassGeneric);
} else if (i == 2 || i == 7) {
SharedPreferences preferences = parentActivity.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
boolean enabledAll = true;
boolean enabled = true;
@ -130,7 +130,7 @@ public class SettingsNotificationsActivity extends BaseFragment {
}
ConnectionsManager.Instance.performRpc(req, null, null, true, RPCRequest.RPCRequestClassGeneric);
} else if (i == 3 || i == 8) {
SharedPreferences preferences = parentActivity.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
boolean enabled;
if (i == 3) {
@ -143,7 +143,7 @@ public class SettingsNotificationsActivity extends BaseFragment {
editor.commit();
listView.invalidateViews();
} else if (i == 4 || i == 9) {
SharedPreferences preferences = parentActivity.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
Intent tmpIntent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, false);
@ -196,7 +196,7 @@ public class SettingsNotificationsActivity extends BaseFragment {
return;
}
reseting = false;
SharedPreferences preferences = inflaterActivity.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.clear();
editor.commit();
@ -208,21 +208,21 @@ public class SettingsNotificationsActivity extends BaseFragment {
}
}, null, true, RPCRequest.RPCRequestClassGeneric);
} else if (i == 11) {
SharedPreferences preferences = parentActivity.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
boolean enabled = preferences.getBoolean("EnableInAppSounds", true);
editor.putBoolean("EnableInAppSounds", !enabled);
editor.commit();
listView.invalidateViews();
} else if (i == 12) {
SharedPreferences preferences = parentActivity.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
boolean enabled = preferences.getBoolean("EnableInAppVibrate", true);
editor.putBoolean("EnableInAppVibrate", !enabled);
editor.commit();
listView.invalidateViews();
} else if (i == 13) {
SharedPreferences preferences = parentActivity.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
boolean enabled = preferences.getBoolean("EnableInAppPreview", true);
editor.putBoolean("EnableInAppPreview", !enabled);
@ -260,7 +260,7 @@ public class SettingsNotificationsActivity extends BaseFragment {
}
}
SharedPreferences preferences = parentActivity.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
if (requestCode == 4) {
@ -342,7 +342,7 @@ public class SettingsNotificationsActivity extends BaseFragment {
int rotation = display.getRotation();
int height;
int currentActionBarHeight = parentActivity.getSupportActionBar().getHeight();
float density = Utilities.applicationContext.getResources().getDisplayMetrics().density;
float density = ApplicationLoader.applicationContext.getResources().getDisplayMetrics().density;
if (currentActionBarHeight != 48 * density && currentActionBarHeight != 40 * density) {
height = currentActionBarHeight;
} else {
@ -387,7 +387,7 @@ public class SettingsNotificationsActivity extends BaseFragment {
@Override
public boolean isEnabled(int i) {
SharedPreferences preferences = parentActivity.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
boolean enabledAll = preferences.getBoolean("EnableAll", true);
return !(i != 1 && !enabledAll && i != 13) && (i > 0 && i < 5 || i > 5 && i < 10 || i > 10 && i < 14 || i == 15);
}
@ -439,7 +439,7 @@ public class SettingsNotificationsActivity extends BaseFragment {
View divider = view.findViewById(R.id.settings_row_divider);
ImageView checkButton = (ImageView)view.findViewById(R.id.settings_row_check_button);
SharedPreferences preferences = parentActivity.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
boolean enabled = false;
boolean enabledAll = preferences.getBoolean("EnableAll", true);
@ -506,7 +506,7 @@ public class SettingsNotificationsActivity extends BaseFragment {
TextView textView = (TextView)view.findViewById(R.id.settings_row_text);
TextView textViewDetail = (TextView)view.findViewById(R.id.settings_row_text_detail);
View divider = view.findViewById(R.id.settings_row_divider);
SharedPreferences preferences = parentActivity.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
boolean enabledAll = preferences.getBoolean("EnableAll", true);
if (i == 4 || i == 9) {
if (i == 4) {

View file

@ -73,7 +73,7 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica
NotificationCenter.Instance.addObserver(this, FileLoader.FileLoadProgressChanged);
NotificationCenter.Instance.addObserver(this, MessagesStorage.wallpapersDidLoaded);
SharedPreferences preferences = Utilities.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
selectedBackground = preferences.getInt("selectedBackground", 1000001);
selectedColor = preferences.getInt("selectedColor", 0);
MessagesStorage.Instance.getWallpapers();
@ -94,7 +94,7 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica
if (fragmentView == null) {
fragmentView = inflater.inflate(R.layout.settings_wallpapers_layout, container, false);
listAdapter = new ListAdapter(parentActivity);
density = Utilities.applicationContext.getResources().getDisplayMetrics().density;
density = ApplicationLoader.applicationContext.getResources().getDisplayMetrics().density;
progressBar = (ProgressBar)fragmentView.findViewById(R.id.action_progress);
backgroundImage = (ImageView)fragmentView.findViewById(R.id.background_image);
@ -154,7 +154,7 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica
TLRPC.PhotoSize size = PhotoObject.getClosestPhotoSizeWithSize(wallPaper.sizes, (int) (320 * density), (int) (480 * density));
String fileName = size.location.volume_id + "_" + size.location.local_id + ".jpg";
File f = new File(Utilities.getCacheDir(), fileName);
File toFile = new File(Utilities.applicationContext.getFilesDir(), "wallpaper.jpg");
File toFile = new File(ApplicationLoader.applicationContext.getFilesDir(), "wallpaper.jpg");
try {
done = Utilities.copyFile(f, toFile);
} catch (Exception e) {
@ -166,7 +166,7 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica
}
if (done) {
SharedPreferences preferences = Utilities.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putInt("selectedBackground", selectedBackground);
editor.putInt("selectedColor", selectedColor);
@ -195,7 +195,7 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica
Utilities.addMediaToGallery(currentPicturePath);
try {
Bitmap bitmap = FileLoader.loadBitmap(currentPicturePath, (int)(320 * density), (int)(480 * density));
File toFile = new File(Utilities.applicationContext.getFilesDir(), "wallpaper.jpg");
File toFile = new File(ApplicationLoader.applicationContext.getFilesDir(), "wallpaper.jpg");
FileOutputStream stream = new FileOutputStream(toFile);
bitmap.compress(Bitmap.CompressFormat.JPEG, 87, stream);
selectedBackground = -1;
@ -218,7 +218,7 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica
try {
Bitmap bitmap = FileLoader.loadBitmap(imageFilePath, (int)(320 * density), (int)(480 * density));
File toFile = new File(Utilities.applicationContext.getFilesDir(), "wallpaper.jpg");
File toFile = new File(ApplicationLoader.applicationContext.getFilesDir(), "wallpaper.jpg");
FileOutputStream stream = new FileOutputStream(toFile);
bitmap.compress(Bitmap.CompressFormat.JPEG, 87, stream);
selectedBackground = -1;
@ -269,7 +269,7 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica
backgroundImage.setBackgroundColor(0);
selectedColor = 0;
} else if (selectedBackground == -1) {
File toFile = new File(Utilities.applicationContext.getFilesDir(), "wallpaper.jpg");
File toFile = new File(ApplicationLoader.applicationContext.getFilesDir(), "wallpaper.jpg");
if (toFile.exists()) {
backgroundImage.setImageURI(Uri.fromFile(toFile));
} else {

View file

@ -399,7 +399,7 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen
int rotation = display.getRotation();
int height;
int currentActionBarHeight = parentActivity.getSupportActionBar().getHeight();
float density = Utilities.applicationContext.getResources().getDisplayMetrics().density;
float density = ApplicationLoader.applicationContext.getResources().getDisplayMetrics().density;
if (currentActionBarHeight != 48 * density && currentActionBarHeight != 40 * density) {
height = currentActionBarHeight;
} else {
@ -415,7 +415,7 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen
if (dialog_id != 0) {
TextView title = (TextView)parentActivity.findViewById(R.id.abs__action_bar_title);
if (title == null) {
final int subtitleId = Utilities.applicationContext.getResources().getIdentifier("action_bar_title", "id", "android");
final int subtitleId = ApplicationLoader.applicationContext.getResources().getIdentifier("action_bar_title", "id", "android");
title = (TextView)parentActivity.findViewById(subtitleId);
}
if (title != null) {

View file

@ -118,10 +118,15 @@ public class AvatarUpdater implements NotificationCenter.NotificationCenterDeleg
} else if (requestCode == 1) {
Uri imageUri = data.getData();
Cursor cursor = null;
if (parentFragment != null) {
cursor = parentFragment.getSherlockActivity().getContentResolver().query(imageUri, new String[]{android.provider.MediaStore.Images.ImageColumns.DATA}, null, null, null);
} else if (parentActivity != null) {
cursor = parentActivity.getContentResolver().query(imageUri, new String[]{android.provider.MediaStore.Images.ImageColumns.DATA}, null, null, null);
try {
if (parentFragment != null) {
cursor = parentFragment.getSherlockActivity().getContentResolver().query(imageUri, new String[]{android.provider.MediaStore.Images.ImageColumns.DATA}, null, null, null);
} else if (parentActivity != null) {
cursor = parentActivity.getContentResolver().query(imageUri, new String[]{android.provider.MediaStore.Images.ImageColumns.DATA}, null, null, null);
}
} catch (Exception e) {
e.printStackTrace();
return;
}
if (cursor == null) {
return;
@ -149,7 +154,7 @@ public class AvatarUpdater implements NotificationCenter.NotificationCenterDeleg
delegate.didUploadedPhoto(null, smallPhoto, bigPhoto);
}
} else {
UserConfig.saveConfig();
UserConfig.saveConfig(false);
uploadingAvatar = Utilities.getCacheDir() + "/" + bigPhoto.location.volume_id + "_" + bigPhoto.location.local_id + ".jpg";
NotificationCenter.Instance.addObserver(AvatarUpdater.this, FileLoader.FileDidUpload);
NotificationCenter.Instance.addObserver(AvatarUpdater.this, FileLoader.FileDidFailUpload);

View file

@ -17,8 +17,8 @@ import android.view.animation.AnimationUtils;
import com.actionbarsherlock.app.SherlockFragment;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import org.telegram.messenger.ConnectionsManager;
import org.telegram.messenger.Utilities;
import org.telegram.ui.ApplicationActivity;
import org.telegram.ui.ApplicationLoader;
public class BaseFragment extends SherlockFragment {
public int animationType = 0;
@ -90,10 +90,11 @@ public class BaseFragment extends SherlockFragment {
public void onFragmentDestroy() {
ConnectionsManager.Instance.cancelRpcsForClassGuid(classGuid);
removeParentOnDestroy = true;
isFinish = true;
}
public String getStringEntry(int res) {
return Utilities.applicationContext.getString(res);
return ApplicationLoader.applicationContext.getString(res);
}
public void onAnimationStart() {

View file

@ -29,6 +29,7 @@ import org.telegram.messenger.NotificationCenter;
import org.telegram.messenger.R;
import org.telegram.messenger.Utilities;
import org.telegram.objects.MessageObject;
import org.telegram.ui.ApplicationLoader;
import java.util.Locale;
import java.util.Timer;
@ -119,11 +120,11 @@ public class NotificationView extends LinearLayout {
}
});
notificationParentView = new FrameLayout(Utilities.applicationContext);
notificationParentView = new FrameLayout(getContext());
notificationParentView.addView(this);
notificationParentView.setFocusable(false);
setFocusable(false);
WindowManager wm = (WindowManager)Utilities.applicationContext.getSystemService(Context.WINDOW_SERVICE);
final WindowManager wm = (WindowManager) ApplicationLoader.applicationContext.getSystemService(Context.WINDOW_SERVICE);
notificationLayoutParams = new WindowManager.LayoutParams();
notificationLayoutParams.height = 90;
notificationLayoutParams.format = PixelFormat.TRANSLUCENT;
@ -131,11 +132,11 @@ public class NotificationView extends LinearLayout {
notificationLayoutParams.gravity = Gravity.CLIP_HORIZONTAL | Gravity.TOP;
notificationLayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
notificationLayoutParams.flags = WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
notificationLayoutParams.y = -300;
isVisible = false;
wm.addView(notificationParentView, notificationLayoutParams);
notificationParentView.setVisibility(View.INVISIBLE);
animHide = AnimationUtils.loadAnimation(Utilities.applicationContext, R.anim.slide_up);
animHide = AnimationUtils.loadAnimation(ApplicationLoader.applicationContext, R.anim.slide_up);
animHide.setAnimationListener(new Animation.AnimationListener() {
public void onAnimationStart(Animation animation) {
onScreen = false;
@ -147,14 +148,13 @@ public class NotificationView extends LinearLayout {
public void onAnimationEnd(Animation animation) {
setVisibility(GONE);
WindowManager wm = (WindowManager)Utilities.applicationContext.getSystemService(Context.WINDOW_SERVICE);
WindowManager wm = (WindowManager)ApplicationLoader.applicationContext.getSystemService(Context.WINDOW_SERVICE);
isVisible = false;
notificationLayoutParams.y = -300;
wm.updateViewLayout(notificationParentView, notificationLayoutParams);
notificationParentView.setVisibility(View.INVISIBLE);
}
});
animShow = AnimationUtils.loadAnimation(Utilities.applicationContext, R.anim.slide_down);
animShow = AnimationUtils.loadAnimation(ApplicationLoader.applicationContext, R.anim.slide_down);
animShow.setAnimationListener(new Animation.AnimationListener() {
public void onAnimationStart(Animation animation) {
setVisibility(VISIBLE);
@ -237,10 +237,9 @@ public class NotificationView extends LinearLayout {
}
if (!onScreen) {
WindowManager wm = (WindowManager)Utilities.applicationContext.getSystemService(Context.WINDOW_SERVICE);
WindowManager wm = (WindowManager)ApplicationLoader.applicationContext.getSystemService(Context.WINDOW_SERVICE);
isVisible = true;
notificationLayoutParams.y = 0;
wm.updateViewLayout(notificationParentView, notificationLayoutParams);
notificationParentView.setVisibility(View.VISIBLE);
startAnimation(animShow);
}
}
@ -261,10 +260,9 @@ public class NotificationView extends LinearLayout {
onScreen = false;
setVisibility(GONE);
if (notificationParentView != null && notificationParentView.getParent() != null) {
WindowManager wm = (WindowManager)Utilities.applicationContext.getSystemService(Context.WINDOW_SERVICE);
WindowManager wm = (WindowManager)ApplicationLoader.applicationContext.getSystemService(Context.WINDOW_SERVICE);
isVisible = false;
notificationLayoutParams.y = -300;
wm.updateViewLayout(notificationParentView, notificationLayoutParams);
notificationParentView.setVisibility(View.INVISIBLE);
}
}
}
@ -276,7 +274,7 @@ public class NotificationView extends LinearLayout {
notificationParentView.removeView(this);
try {
if (notificationParentView.getParent() != null) {
WindowManager wm = (WindowManager)Utilities.applicationContext.getSystemService(Context.WINDOW_SERVICE);
WindowManager wm = (WindowManager)ApplicationLoader.applicationContext.getSystemService(Context.WINDOW_SERVICE);
wm.removeViewImmediate(notificationParentView);
}
} catch (Exception e) {
@ -322,7 +320,7 @@ public class NotificationView extends LinearLayout {
if (notificationParentView != null) {
notificationLayoutParams.height = height + (int)(2 * density);
if (notificationParentView.getParent() != null) {
WindowManager wm = (WindowManager) Utilities.applicationContext.getSystemService(Context.WINDOW_SERVICE);
WindowManager wm = (WindowManager) ApplicationLoader.applicationContext.getSystemService(Context.WINDOW_SERVICE);
wm.updateViewLayout(notificationParentView, notificationLayoutParams);
}
}

View file

@ -29,7 +29,6 @@
android:gravity="right|center"
android:textSize="15dp"
android:textColor="#000000"
android:text="Nikolay Kudashov"
android:id="@+id/name_text_view"
android:paddingTop="4dp"
android:ellipsize="end"
@ -41,7 +40,6 @@
android:gravity="right|center"
android:textColor="#000000"
android:textSize="15dp"
android:text="Hello"
android:id="@+id/message_text_view"
android:paddingTop="24dp"
android:ellipsize="end"

View file

@ -24,6 +24,7 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="14dp"
android:layout_marginLeft="4dp"
android:layout_marginTop="2dp"
android:layout_weight="1.0"
android:gravity="right">

View file

@ -64,7 +64,7 @@
android:textSize="16dp"
android:linksClickable="false"
android:layout_marginBottom="8dp"
android:autoLink="web"
android:autoLink="web|email"
android:descendantFocusability="afterDescendants"
android:layout_marginTop="53dp"
android:layout_gravity="top"

View file

@ -42,7 +42,7 @@
android:layout_height="wrap_content"
android:textSize="16dp"
android:layout_marginBottom="8dp"
android:autoLink="web"
android:autoLink="web|email"
android:linksClickable="false"
android:layout_marginTop="18dp"
android:textColor="#000000"

View file

@ -42,7 +42,7 @@
android:layout_height="wrap_content"
android:textSize="16dp"
android:layout_marginBottom="8dp"
android:autoLink="web"
android:autoLink="web|email"
android:linksClickable="false"
android:layout_marginTop="34dp"
android:descendantFocusability="afterDescendants"

View file

@ -22,7 +22,7 @@
android:layout_height="wrap_content"
android:textSize="16dp"
android:layout_marginBottom="8dp"
android:autoLink="web"
android:autoLink="web|email"
android:linksClickable="false"
android:layout_gravity="top"
android:textColor="#000000"/>

View file

@ -43,7 +43,7 @@
android:linksClickable="false"
android:layout_marginTop="34dp"
android:layout_marginBottom="8dp"
android:autoLink="web"
android:autoLink="web|email"
android:descendantFocusability="afterDescendants"
android:layout_gravity="top"
android:textColor="#000000"/>

View file

@ -20,7 +20,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16dp"
android:autoLink="web"
android:autoLink="web|email"
android:linksClickable="false"
android:layout_gravity="top"
android:textColor="#000000"

View file

@ -28,7 +28,6 @@
android:gravity="left|center"
android:textSize="15dp"
android:textColor="#000000"
android:text="Nikolay Kudashov"
android:id="@+id/name_text_view"
android:paddingTop="4dp"
android:ellipsize="end"
@ -39,7 +38,6 @@
android:gravity="left|center"
android:textColor="#000000"
android:textSize="15dp"
android:text="Hello"
android:id="@+id/message_text_view"
android:paddingTop="24dp"
android:ellipsize="end"

View file

@ -25,6 +25,7 @@
android:layout_height="wrap_content"
android:layout_marginLeft="14dp"
android:layout_marginTop="2dp"
android:layout_marginRight="4dp"
android:layout_weight="1.0">
<TextView android:textSize="19dp"

View file

@ -89,6 +89,7 @@
<string name="MessageLifetime1h">ساعة</string>
<string name="MessageLifetime1d">يوم</string>
<string name="MessageLifetime1w">أسبوع</string>
<string name="YouHaveNewMessage">لديك رسالة جديدة</string>
<!--contacts view-->
<string name="SearchContactHint">إبحث عن جهات الاتصال</string>

View file

@ -89,6 +89,7 @@
<string name="MessageLifetime1h">1 hour</string>
<string name="MessageLifetime1d">1 day</string>
<string name="MessageLifetime1w">1 week</string>
<string name="YouHaveNewMessage">You have a new message</string>
<!--contacts view-->
<string name="SearchContactHint">Search contacts</string>
@ -265,4 +266,4 @@
<!--Don't change this! Not for localization!-->
<string name="CacheTag">CACHE_TAG</string>
</resources>
</resources>