diff --git a/TMessagesProj/build.gradle b/TMessagesProj/build.gradle
index a858c665..5473fd2b 100644
--- a/TMessagesProj/build.gradle
+++ b/TMessagesProj/build.gradle
@@ -3,10 +3,10 @@ buildscript {
mavenCentral()
}
dependencies {
- classpath 'com.android.tools.build:gradle:0.11.+'
+ classpath 'com.android.tools.build:gradle:0.12.+'
}
}
-apply plugin: 'android'
+apply plugin: 'com.android.application'
repositories {
mavenCentral()
@@ -26,7 +26,8 @@ android {
compileSdkVersion 19
buildToolsVersion '19.1.0'
- aaptOptions.useAaptPngCruncher = true
+ useAaptPngCruncher = true
+ useOldManifestMerger true
signingConfigs {
debug {
@@ -81,7 +82,7 @@ android {
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
- versionCode 268
- versionName "1.5.7"
+ versionCode 269
+ versionName "1.5.8"
}
}
diff --git a/TMessagesProj/config/debug/AndroidManifest.xml b/TMessagesProj/config/debug/AndroidManifest.xml
index 8a10bfb3..6a08d6c1 100644
--- a/TMessagesProj/config/debug/AndroidManifest.xml
+++ b/TMessagesProj/config/debug/AndroidManifest.xml
@@ -33,7 +33,7 @@
diff --git a/TMessagesProj/config/release/AndroidManifest.xml b/TMessagesProj/config/release/AndroidManifest.xml
index af975145..a1ee70d3 100644
--- a/TMessagesProj/config/release/AndroidManifest.xml
+++ b/TMessagesProj/config/release/AndroidManifest.xml
@@ -33,7 +33,7 @@
diff --git a/TMessagesProj/jni/audio.c b/TMessagesProj/jni/audio.c
index 70b6e2fc..3ca0f1fb 100644
--- a/TMessagesProj/jni/audio.c
+++ b/TMessagesProj/jni/audio.c
@@ -504,7 +504,7 @@ int writeFrame(uint8_t *framePcmBytes, unsigned int frameByteCount) {
return 1;
}
-JNIEXPORT int Java_org_telegram_messenger_MediaController_startRecord(JNIEnv *env, jclass class, jstring path) {
+JNIEXPORT int Java_org_telegram_android_MediaController_startRecord(JNIEnv *env, jclass class, jstring path) {
const char *pathStr = (*env)->GetStringUTFChars(env, path, 0);
int result = initRecorder(pathStr);
@@ -516,12 +516,12 @@ JNIEXPORT int Java_org_telegram_messenger_MediaController_startRecord(JNIEnv *en
return result;
}
-JNIEXPORT int Java_org_telegram_messenger_MediaController_writeFrame(JNIEnv *env, jclass class, jobject frame, jint len) {
+JNIEXPORT int Java_org_telegram_android_MediaController_writeFrame(JNIEnv *env, jclass class, jobject frame, jint len) {
jbyte *frameBytes = (*env)->GetDirectBufferAddress(env, frame);
return writeFrame(frameBytes, len);
}
-JNIEXPORT void Java_org_telegram_messenger_MediaController_stopRecord(JNIEnv *env, jclass class) {
+JNIEXPORT void Java_org_telegram_android_MediaController_stopRecord(JNIEnv *env, jclass class) {
cleanupRecorder();
}
@@ -618,22 +618,22 @@ void fillBuffer(uint8_t *buffer, int capacity, int *args) {
}
}
-JNIEXPORT jlong Java_org_telegram_messenger_MediaController_getTotalPcmDuration(JNIEnv *env, jclass class) {
+JNIEXPORT jlong Java_org_telegram_android_MediaController_getTotalPcmDuration(JNIEnv *env, jclass class) {
return _totalPcmDuration;
}
-JNIEXPORT void Java_org_telegram_messenger_MediaController_readOpusFile(JNIEnv *env, jclass class, jobject buffer, jint capacity, jintArray args) {
+JNIEXPORT void Java_org_telegram_android_MediaController_readOpusFile(JNIEnv *env, jclass class, jobject buffer, jint capacity, jintArray args) {
jint *argsArr = (*env)->GetIntArrayElements(env, args, 0);
jbyte *bufferBytes = (*env)->GetDirectBufferAddress(env, buffer);
fillBuffer(bufferBytes, capacity, argsArr);
(*env)->ReleaseIntArrayElements(env, args, argsArr, 0);
}
-JNIEXPORT int Java_org_telegram_messenger_MediaController_seekOpusFile(JNIEnv *env, jclass class, jfloat position) {
+JNIEXPORT int Java_org_telegram_android_MediaController_seekOpusFile(JNIEnv *env, jclass class, jfloat position) {
return seekPlayer(position);
}
-JNIEXPORT int Java_org_telegram_messenger_MediaController_openOpusFile(JNIEnv *env, jclass class, jstring path) {
+JNIEXPORT int Java_org_telegram_android_MediaController_openOpusFile(JNIEnv *env, jclass class, jstring path) {
const char *pathStr = (*env)->GetStringUTFChars(env, path, 0);
int result = initPlayer(pathStr);
@@ -645,11 +645,11 @@ JNIEXPORT int Java_org_telegram_messenger_MediaController_openOpusFile(JNIEnv *e
return result;
}
-JNIEXPORT void Java_org_telegram_messenger_MediaController_closeOpusFile(JNIEnv *env, jclass class) {
+JNIEXPORT void Java_org_telegram_android_MediaController_closeOpusFile(JNIEnv *env, jclass class) {
cleanupPlayer();
}
-JNIEXPORT int Java_org_telegram_messenger_MediaController_isOpusFile(JNIEnv *env, jclass class, jstring path) {
+JNIEXPORT int Java_org_telegram_android_MediaController_isOpusFile(JNIEnv *env, jclass class, jstring path) {
const char *pathStr = (*env)->GetStringUTFChars(env, path, 0);
int result = 0;
diff --git a/TMessagesProj/jni/jni.c b/TMessagesProj/jni/jni.c
index 66a7976e..4a43f84d 100644
--- a/TMessagesProj/jni/jni.c
+++ b/TMessagesProj/jni/jni.c
@@ -30,67 +30,21 @@ void JNI_OnUnload(JavaVM *vm, void *reserved) {
gifOnJNIUnload(vm, reserved);
}
-JNIEXPORT jbyteArray Java_org_telegram_messenger_Utilities_aesIgeEncryption(JNIEnv *env, jclass class, jbyteArray _what, jbyteArray _key, jbyteArray _iv, jboolean encrypt, jboolean changeIv, jint l) {
- unsigned char *what = (unsigned char *)(*env)->GetByteArrayElements(env, _what, NULL);
- unsigned char *key = (unsigned char *)(*env)->GetByteArrayElements(env, _key, NULL);
- unsigned char *__iv = (unsigned char *)(*env)->GetByteArrayElements(env, _iv, NULL);
- unsigned char *iv = 0;
-
- if (!changeIv) {
- iv = (unsigned char *)malloc((*env)->GetArrayLength(env, _iv));
- memcpy(iv, __iv, (*env)->GetArrayLength(env, _iv));
- } else {
- iv = __iv;
- }
-
- int len = l == 0 ? (*env)->GetArrayLength(env, _what) : l;
- AES_KEY akey;
- if (!encrypt) {
- AES_set_decrypt_key(key, (*env)->GetArrayLength(env, _key) * 8, &akey);
- AES_ige_encrypt(what, what, len, &akey, iv, AES_DECRYPT);
- } else {
- AES_set_encrypt_key(key, (*env)->GetArrayLength(env, _key) * 8, &akey);
- AES_ige_encrypt(what, what, len, &akey, iv, AES_ENCRYPT);
- }
- (*env)->ReleaseByteArrayElements(env, _what, what, 0);
- (*env)->ReleaseByteArrayElements(env, _key, key, JNI_ABORT);
- if (!changeIv) {
- (*env)->ReleaseByteArrayElements(env, _iv, __iv, JNI_ABORT);
- free(iv);
- } else {
- (*env)->ReleaseByteArrayElements(env, _iv, __iv, 0);
- }
- return _what;
-}
-
-JNIEXPORT void Java_org_telegram_messenger_Utilities_aesIgeEncryption2(JNIEnv *env, jclass class, jobject _what, jbyteArray _key, jbyteArray _iv, jboolean encrypt, jboolean changeIv, jint l) {
- jbyte *what = (*env)->GetDirectBufferAddress(env, _what);
- unsigned char *key = (unsigned char *)(*env)->GetByteArrayElements(env, _key, NULL);
- unsigned char *__iv = (unsigned char *)(*env)->GetByteArrayElements(env, _iv, NULL);
- unsigned char *iv = 0;
-
- if (!changeIv) {
- iv = (unsigned char *)malloc((*env)->GetArrayLength(env, _iv));
- memcpy(iv, __iv, (*env)->GetArrayLength(env, _iv));
- } else {
- iv = __iv;
- }
+JNIEXPORT void Java_org_telegram_messenger_Utilities_aesIgeEncryption(JNIEnv *env, jclass class, jobject buffer, jbyteArray key, jbyteArray iv, jboolean encrypt, int offset, int length) {
+ jbyte *what = (*env)->GetDirectBufferAddress(env, buffer) + offset;
+ unsigned char *keyBuff = (unsigned char *)(*env)->GetByteArrayElements(env, key, NULL);
+ unsigned char *ivBuff = (unsigned char *)(*env)->GetByteArrayElements(env, iv, NULL);
AES_KEY akey;
if (!encrypt) {
- AES_set_decrypt_key(key, (*env)->GetArrayLength(env, _key) * 8, &akey);
- AES_ige_encrypt(what, what, l, &akey, iv, AES_DECRYPT);
+ AES_set_decrypt_key(keyBuff, 32 * 8, &akey);
+ AES_ige_encrypt(what, what, length, &akey, ivBuff, AES_DECRYPT);
} else {
- AES_set_encrypt_key(key, (*env)->GetArrayLength(env, _key) * 8, &akey);
- AES_ige_encrypt(what, what, l, &akey, iv, AES_ENCRYPT);
- }
- (*env)->ReleaseByteArrayElements(env, _key, key, JNI_ABORT);
- if (!changeIv) {
- (*env)->ReleaseByteArrayElements(env, _iv, __iv, JNI_ABORT);
- free(iv);
- } else {
- (*env)->ReleaseByteArrayElements(env, _iv, __iv, 0);
+ AES_set_encrypt_key(keyBuff, 32 * 8, &akey);
+ AES_ige_encrypt(what, what, length, &akey, ivBuff, AES_ENCRYPT);
}
+ (*env)->ReleaseByteArrayElements(env, key, keyBuff, JNI_ABORT);
+ (*env)->ReleaseByteArrayElements(env, iv, ivBuff, 0);
}
uint64_t gcd(uint64_t a, uint64_t b){
diff --git a/TMessagesProj/jni/sqlite_cursor.c b/TMessagesProj/jni/sqlite_cursor.c
index 655876d9..de3f7469 100755
--- a/TMessagesProj/jni/sqlite_cursor.c
+++ b/TMessagesProj/jni/sqlite_cursor.c
@@ -48,7 +48,7 @@ jstring Java_org_telegram_SQLite_SQLiteCursor_columnStringValue(JNIEnv *env, job
}
jbyteArray Java_org_telegram_SQLite_SQLiteCursor_columnByteArrayValue(JNIEnv *env, jobject object, int statementHandle, int columnIndex) {
- sqlite3_stmt *handle = (sqlite3_stmt *)statementHandle;
+ sqlite3_stmt *handle = (sqlite3_stmt *)statementHandle;
void *buf = sqlite3_column_blob(handle, columnIndex);
int length = sqlite3_column_bytes(handle, columnIndex);
if (buf != 0 && length > 0) {
@@ -58,3 +58,22 @@ jbyteArray Java_org_telegram_SQLite_SQLiteCursor_columnByteArrayValue(JNIEnv *en
}
return 0;
}
+
+int Java_org_telegram_SQLite_SQLiteCursor_columnByteArrayLength(JNIEnv *env, jobject object, int statementHandle, int columnIndex) {
+ return sqlite3_column_bytes((sqlite3_stmt *)statementHandle, columnIndex);
+}
+
+int Java_org_telegram_SQLite_SQLiteCursor_columnByteBufferValue(JNIEnv *env, jobject object, int statementHandle, int columnIndex, jobject buffer) {
+ if (!buffer) {
+ return 0;
+ }
+ sqlite3_stmt *handle = (sqlite3_stmt *)statementHandle;
+ void *buf = sqlite3_column_blob(handle, columnIndex);
+ int length = sqlite3_column_bytes(handle, columnIndex);
+ if (buf != 0 && length > 0) {
+ jbyte *byteBuff = (*env)->GetDirectBufferAddress(env, buffer);
+ memcpy(byteBuff, buf, length);
+ return length;
+ }
+ return 0;
+}
diff --git a/TMessagesProj/jni/sqlite_statement.c b/TMessagesProj/jni/sqlite_statement.c
index f3d11003..1090de3d 100755
--- a/TMessagesProj/jni/sqlite_statement.c
+++ b/TMessagesProj/jni/sqlite_statement.c
@@ -62,20 +62,14 @@ void Java_org_telegram_SQLite_SQLitePreparedStatement_finalize(JNIEnv *env, jobj
}
}
-void Java_org_telegram_SQLite_SQLitePreparedStatement_bindByteArray(JNIEnv *env, jobject object, int statementHandle, int index, jbyteArray value) {
+void Java_org_telegram_SQLite_SQLitePreparedStatement_bindByteBuffer(JNIEnv *env, jobject object, int statementHandle, int index, jobject value, int length) {
sqlite3_stmt *handle = (sqlite3_stmt *)statementHandle;
-
- const void *buf = (*env)->GetByteArrayElements(env, value, 0);
- int length = (*env)->GetArrayLength(env, value);
-
+ jbyte *buf = (*env)->GetDirectBufferAddress(env, value);
+
int errcode = sqlite3_bind_blob(handle, index, buf, length, SQLITE_STATIC);
if (SQLITE_OK != errcode) {
throw_sqlite3_exception(env, sqlite3_db_handle(handle), errcode);
}
-
- if (buf != 0) {
- (*env)->ReleaseByteArrayElements(env, value, buf, 0);
- }
}
void Java_org_telegram_SQLite_SQLitePreparedStatement_bindString(JNIEnv *env, jobject object, int statementHandle, int index, jstring value) {
diff --git a/TMessagesProj/libs/armeabi-v7a/libtmessages.so b/TMessagesProj/libs/armeabi-v7a/libtmessages.so
index 9d9f7338..078cb27f 100755
Binary files a/TMessagesProj/libs/armeabi-v7a/libtmessages.so and b/TMessagesProj/libs/armeabi-v7a/libtmessages.so differ
diff --git a/TMessagesProj/libs/armeabi/libtmessages.so b/TMessagesProj/libs/armeabi/libtmessages.so
index 13a6c5a3..710cbf15 100755
Binary files a/TMessagesProj/libs/armeabi/libtmessages.so and b/TMessagesProj/libs/armeabi/libtmessages.so differ
diff --git a/TMessagesProj/libs/x86/libtmessages.so b/TMessagesProj/libs/x86/libtmessages.so
index 963e616e..317753d3 100755
Binary files a/TMessagesProj/libs/x86/libtmessages.so and b/TMessagesProj/libs/x86/libtmessages.so differ
diff --git a/TMessagesProj/src/main/AndroidManifest.xml b/TMessagesProj/src/main/AndroidManifest.xml
index 71e7bb9c..894e88ee 100644
--- a/TMessagesProj/src/main/AndroidManifest.xml
+++ b/TMessagesProj/src/main/AndroidManifest.xml
@@ -58,6 +58,7 @@
+
@@ -100,14 +101,23 @@
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:screenOrientation="portrait">
+
+
-
+
-
@@ -116,7 +126,7 @@
android:resource="@xml/auth"/>
-
@@ -127,15 +137,22 @@
android:resource="@xml/contacts" />
-
+
-
+
+
+
+
+
+
+
+
diff --git a/TMessagesProj/src/main/java/org/telegram/SQLite/SQLiteCursor.java b/TMessagesProj/src/main/java/org/telegram/SQLite/SQLiteCursor.java
index d03d52eb..48bd8777 100755
--- a/TMessagesProj/src/main/java/org/telegram/SQLite/SQLiteCursor.java
+++ b/TMessagesProj/src/main/java/org/telegram/SQLite/SQLiteCursor.java
@@ -10,6 +10,8 @@ package org.telegram.SQLite;
import org.telegram.messenger.FileLog;
+import java.nio.ByteBuffer;
+
public class SQLiteCursor {
public static final int FIELD_TYPE_INT = 1;
@@ -55,28 +57,21 @@ public class SQLiteCursor {
return columnByteArrayValue(preparedStatement.getStatementHandle(), columnIndex);
}
+ public int byteArrayLength(int columnIndex) throws SQLiteException {
+ checkRow();
+ return columnByteArrayLength(preparedStatement.getStatementHandle(), columnIndex);
+ }
+
+ public int byteBufferValue(int columnIndex, ByteBuffer buffer) throws SQLiteException {
+ checkRow();
+ return columnByteBufferValue(preparedStatement.getStatementHandle(), columnIndex, buffer);
+ }
+
public int getTypeOf(int columnIndex) throws SQLiteException {
checkRow();
return columnType(preparedStatement.getStatementHandle(), columnIndex);
}
- public Object objectValue(int columnIndex) throws SQLiteException {
- checkRow();
-
- int type = columnType(preparedStatement.getStatementHandle(), columnIndex);
- switch (type) {
- case FIELD_TYPE_INT:
- return intValue(columnIndex);
- case FIELD_TYPE_BYTEARRAY:
- return byteArrayValue(columnIndex);
- case FIELD_TYPE_FLOAT:
- return doubleValue(columnIndex);
- case FIELD_TYPE_STRING:
- return stringValue(columnIndex);
- }
- return null;
- }
-
public boolean next() throws SQLiteException {
int res = preparedStatement.step(preparedStatement.getStatementHandle());
if(res == -1) {
@@ -122,4 +117,6 @@ public class SQLiteCursor {
native double columnDoubleValue(int statementHandle, int columnIndex);
native String columnStringValue(int statementHandle, int columnIndex);
native byte[] columnByteArrayValue(int statementHandle, int columnIndex);
+ native int columnByteArrayLength(int statementHandle, int columnIndex);
+ native int columnByteBufferValue(int statementHandle, int columnIndex, ByteBuffer buffer);
}
diff --git a/TMessagesProj/src/main/java/org/telegram/SQLite/SQLitePreparedStatement.java b/TMessagesProj/src/main/java/org/telegram/SQLite/SQLitePreparedStatement.java
index dc208834..6335d93b 100755
--- a/TMessagesProj/src/main/java/org/telegram/SQLite/SQLitePreparedStatement.java
+++ b/TMessagesProj/src/main/java/org/telegram/SQLite/SQLitePreparedStatement.java
@@ -10,6 +10,8 @@ package org.telegram.SQLite;
import org.telegram.messenger.FileLog;
+import java.nio.ByteBuffer;
+
public class SQLitePreparedStatement {
private boolean isFinalized = false;
private int sqliteStatementHandle;
@@ -26,35 +28,34 @@ public class SQLitePreparedStatement {
sqliteStatementHandle = prepare(db.getSQLiteHandle(), sql);
}
- public SQLiteCursor query(Object[] args) throws SQLiteException {
- if (args == null || args.length != queryArgsCount) {
- throw new IllegalArgumentException();
- }
- checkFinalized();
+ public SQLiteCursor query(Object[] args) throws SQLiteException {
+ if (args == null || args.length != queryArgsCount) {
+ throw new IllegalArgumentException();
+ }
- reset(sqliteStatementHandle);
+ checkFinalized();
- int i = 1;
- for (Object obj : args) {
- if (obj == null) {
- bindNull(sqliteStatementHandle, i);
- } else if (obj instanceof Integer) {
- bindInt(sqliteStatementHandle, i, (Integer)obj);
- } else if (obj instanceof Double) {
- bindDouble(sqliteStatementHandle, i, (Double)obj);
- } else if (obj instanceof String) {
- bindString(sqliteStatementHandle, i, (String)obj);
- } else if (obj instanceof byte[]) {
- bindByteArray(sqliteStatementHandle, i, (byte[])obj);
- } else {
- throw new IllegalArgumentException();
- }
- i++;
- }
+ reset(sqliteStatementHandle);
- return new SQLiteCursor(this);
- }
+ int i = 1;
+ for (Object obj : args) {
+ if (obj == null) {
+ bindNull(sqliteStatementHandle, i);
+ } else if (obj instanceof Integer) {
+ bindInt(sqliteStatementHandle, i, (Integer)obj);
+ } else if (obj instanceof Double) {
+ bindDouble(sqliteStatementHandle, i, (Double)obj);
+ } else if (obj instanceof String) {
+ bindString(sqliteStatementHandle, i, (String)obj);
+ } else {
+ throw new IllegalArgumentException();
+ }
+ i++;
+ }
+
+ return new SQLiteCursor(this);
+ }
public int step() throws SQLiteException {
return step(sqliteStatementHandle);
@@ -102,8 +103,8 @@ public class SQLitePreparedStatement {
bindDouble(sqliteStatementHandle, index, value);
}
- public void bindByteArray(int index, byte[] value) throws SQLiteException {
- bindByteArray(sqliteStatementHandle, index, value);
+ public void bindByteBuffer(int index, ByteBuffer value) throws SQLiteException {
+ bindByteBuffer(sqliteStatementHandle, index, value, value.limit());
}
public void bindString(int index, String value) throws SQLiteException {
@@ -114,7 +115,7 @@ public class SQLitePreparedStatement {
bindLong(sqliteStatementHandle, index, value);
}
- native void bindByteArray(int statementHandle, int index, byte[] value) throws SQLiteException;
+ native void bindByteBuffer(int statementHandle, int index, ByteBuffer value, int length) throws SQLiteException;
native void bindString(int statementHandle, int index, String value) throws SQLiteException;
native void bindInt(int statementHandle, int index, int value) throws SQLiteException;
native void bindLong(int statementHandle, int index, long value) throws SQLiteException;
diff --git a/TMessagesProj/src/main/java/org/telegram/android/AndroidUtilities.java b/TMessagesProj/src/main/java/org/telegram/android/AndroidUtilities.java
new file mode 100644
index 00000000..298e2ad3
--- /dev/null
+++ b/TMessagesProj/src/main/java/org/telegram/android/AndroidUtilities.java
@@ -0,0 +1,216 @@
+/*
+ * This is the source code of Telegram for Android v. 1.4.x.
+ * It is licensed under GNU GPL v. 2 or later.
+ * You should have received a copy of the license in this archive (see LICENSE).
+ *
+ * Copyright Nikolai Kudashov, 2013-2014.
+ */
+
+package org.telegram.android;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.pm.ActivityInfo;
+import android.content.res.Configuration;
+import android.graphics.Point;
+import android.graphics.Typeface;
+import android.os.Build;
+import android.os.Environment;
+import android.view.Display;
+import android.view.Surface;
+import android.view.View;
+import android.view.WindowManager;
+import android.view.inputmethod.InputMethodManager;
+
+import org.telegram.messenger.FileLog;
+import org.telegram.ui.ApplicationLoader;
+
+import java.io.File;
+import java.util.Hashtable;
+
+public class AndroidUtilities {
+ private static final Hashtable typefaceCache = new Hashtable();
+ private static int prevOrientation = -10;
+ private static boolean waitingForSms = false;
+ private static final Integer smsLock = 2;
+ public static int externalCacheNotAvailableState = 0;
+
+ public static int statusBarHeight = 0;
+ public static float density = 1;
+ public static Point displaySize = new Point();
+
+ static {
+ density = ApplicationLoader.applicationContext.getResources().getDisplayMetrics().density;
+ checkDisplaySize();
+ }
+
+ public static void lockOrientation(Activity activity) {
+ if (prevOrientation != -10) {
+ return;
+ }
+ try {
+ prevOrientation = activity.getRequestedOrientation();
+ WindowManager manager = (WindowManager)activity.getSystemService(Activity.WINDOW_SERVICE);
+ if (manager != null && manager.getDefaultDisplay() != null) {
+ int rotation = manager.getDefaultDisplay().getRotation();
+ int orientation = activity.getResources().getConfiguration().orientation;
+
+ if (rotation == Surface.ROTATION_270) {
+ if (orientation == Configuration.ORIENTATION_PORTRAIT) {
+ activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
+ } else {
+ if (Build.VERSION.SDK_INT >= 9) {
+ activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
+ } else {
+ activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
+ }
+ }
+ } else if (rotation == Surface.ROTATION_90) {
+ if (orientation == Configuration.ORIENTATION_PORTRAIT) {
+ if (Build.VERSION.SDK_INT >= 9) {
+ activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
+ } else {
+ activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
+ }
+ } else {
+ activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
+ }
+ } else if (rotation == Surface.ROTATION_0) {
+ if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
+ activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
+ } else {
+ activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
+ }
+ } else {
+ if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
+ if (Build.VERSION.SDK_INT >= 9) {
+ activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
+ } else {
+ activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
+ }
+ } else {
+ if (Build.VERSION.SDK_INT >= 9) {
+ activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
+ } else {
+ activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
+ }
+ }
+ }
+ }
+ } catch (Exception e) {
+ FileLog.e("tmessages", e);
+ }
+ }
+
+ public static void unlockOrientation(Activity activity) {
+ try {
+ if (prevOrientation != -10) {
+ activity.setRequestedOrientation(prevOrientation);
+ prevOrientation = -10;
+ }
+ } catch (Exception e) {
+ FileLog.e("tmessages", e);
+ }
+ }
+
+ public static Typeface getTypeface(String assetPath) {
+ synchronized (typefaceCache) {
+ if (!typefaceCache.containsKey(assetPath)) {
+ try {
+ Typeface t = Typeface.createFromAsset(ApplicationLoader.applicationContext.getAssets(), assetPath);
+ typefaceCache.put(assetPath, t);
+ } catch (Exception e) {
+ FileLog.e("Typefaces", "Could not get typeface '" + assetPath + "' because " + e.getMessage());
+ return null;
+ }
+ }
+ return typefaceCache.get(assetPath);
+ }
+ }
+
+ public static boolean isWaitingForSms() {
+ boolean value = false;
+ synchronized (smsLock) {
+ value = waitingForSms;
+ }
+ return value;
+ }
+
+ public static void setWaitingForSms(boolean value) {
+ synchronized (smsLock) {
+ waitingForSms = value;
+ }
+ }
+
+ public static void showKeyboard(View view) {
+ if (view == null) {
+ return;
+ }
+ InputMethodManager inputManager = (InputMethodManager)view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
+ inputManager.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
+
+ ((InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(view, 0);
+ }
+
+ public static boolean isKeyboardShowed(View view) {
+ if (view == null) {
+ return false;
+ }
+ InputMethodManager inputManager = (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
+ return inputManager.isActive(view);
+ }
+
+ public static void hideKeyboard(View view) {
+ if (view == null) {
+ return;
+ }
+ InputMethodManager imm = (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
+ if (!imm.isActive()) {
+ return;
+ }
+ imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
+ }
+
+ public static File getCacheDir() {
+ if (externalCacheNotAvailableState == 1 || externalCacheNotAvailableState == 0 && Environment.getExternalStorageState().startsWith(Environment.MEDIA_MOUNTED)) {
+ externalCacheNotAvailableState = 1;
+ File file = ApplicationLoader.applicationContext.getExternalCacheDir();
+ if (file != null) {
+ return file;
+ }
+ }
+ externalCacheNotAvailableState = 2;
+ File file = ApplicationLoader.applicationContext.getCacheDir();
+ if (file != null) {
+ return file;
+ }
+ return new File("");
+ }
+
+ public static int dp(int value) {
+ return (int)(Math.max(1, density * value));
+ }
+
+ public static int dpf(float value) {
+ return (int)Math.ceil(density * value);
+ }
+
+ public static void checkDisplaySize() {
+ try {
+ WindowManager manager = (WindowManager)ApplicationLoader.applicationContext.getSystemService(Context.WINDOW_SERVICE);
+ if (manager != null) {
+ Display display = manager.getDefaultDisplay();
+ if (display != null) {
+ if(android.os.Build.VERSION.SDK_INT < 13) {
+ displaySize.set(display.getWidth(), display.getHeight());
+ } else {
+ display.getSize(displaySize);
+ }
+ FileLog.e("tmessages", "display size = " + displaySize.x + " " + displaySize.y);
+ }
+ }
+ } catch (Exception e) {
+ FileLog.e("tmessages", e);
+ }
+ }
+}
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/AppStartReceiver.java b/TMessagesProj/src/main/java/org/telegram/android/AppStartReceiver.java
similarity index 90%
rename from TMessagesProj/src/main/java/org/telegram/messenger/AppStartReceiver.java
rename to TMessagesProj/src/main/java/org/telegram/android/AppStartReceiver.java
index d1048d02..aa630862 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/AppStartReceiver.java
+++ b/TMessagesProj/src/main/java/org/telegram/android/AppStartReceiver.java
@@ -6,12 +6,13 @@
* Copyright Nikolai Kudashov, 2013-2014.
*/
-package org.telegram.messenger;
+package org.telegram.android;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
+import org.telegram.messenger.Utilities;
import org.telegram.ui.ApplicationLoader;
public class AppStartReceiver extends BroadcastReceiver {
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/AuthenticatorService.java b/TMessagesProj/src/main/java/org/telegram/android/AuthenticatorService.java
similarity index 98%
rename from TMessagesProj/src/main/java/org/telegram/messenger/AuthenticatorService.java
rename to TMessagesProj/src/main/java/org/telegram/android/AuthenticatorService.java
index e88d46ed..1d9c4bdc 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/AuthenticatorService.java
+++ b/TMessagesProj/src/main/java/org/telegram/android/AuthenticatorService.java
@@ -6,7 +6,7 @@
* Copyright Nikolai Kudashov, 2013.
*/
-package org.telegram.messenger;
+package org.telegram.android;
import android.accounts.AbstractAccountAuthenticator;
import android.accounts.Account;
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/ContactsController.java b/TMessagesProj/src/main/java/org/telegram/android/ContactsController.java
similarity index 98%
rename from TMessagesProj/src/main/java/org/telegram/messenger/ContactsController.java
rename to TMessagesProj/src/main/java/org/telegram/android/ContactsController.java
index f270ab3b..33d2b4bf 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/ContactsController.java
+++ b/TMessagesProj/src/main/java/org/telegram/android/ContactsController.java
@@ -6,7 +6,7 @@
* Copyright Nikolai Kudashov, 2013.
*/
-package org.telegram.messenger;
+package org.telegram.android;
import android.accounts.Account;
import android.accounts.AccountManager;
@@ -20,6 +20,16 @@ import android.provider.ContactsContract;
import android.util.SparseArray;
import org.telegram.PhoneFormat.PhoneFormat;
+import org.telegram.messenger.BuildVars;
+import org.telegram.messenger.ConnectionsManager;
+import org.telegram.messenger.FileLog;
+import org.telegram.messenger.NotificationCenter;
+import org.telegram.messenger.R;
+import org.telegram.messenger.RPCRequest;
+import org.telegram.messenger.TLObject;
+import org.telegram.messenger.TLRPC;
+import org.telegram.messenger.UserConfig;
+import org.telegram.messenger.Utilities;
import org.telegram.ui.ApplicationLoader;
import java.util.ArrayList;
@@ -151,6 +161,18 @@ public class ContactsController {
}
}
+ public void deleteAllAppAccounts() {
+ try {
+ AccountManager am = AccountManager.get(ApplicationLoader.applicationContext);
+ Account[] accounts = am.getAccountsByType("org.telegram.account");
+ for (Account c : accounts) {
+ am.removeAccount(c, null, null);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
public void checkContacts() {
Utilities.globalQueue.postRunnable(new Runnable() {
@Override
@@ -720,7 +742,7 @@ public class ContactsController {
});
}
}
- }, null, true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassFailOnServerErrors | RPCRequest.RPCRequestClassCanCompress);
+ }, true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassFailOnServerErrors | RPCRequest.RPCRequestClassCanCompress);
}
} else {
Utilities.stageQueue.postRunnable(new Runnable() {
@@ -815,7 +837,7 @@ public class ContactsController {
processLoadedContacts(res.contacts, res.users, 0);
}
}
- }, null, true, RPCRequest.RPCRequestClassGeneric);
+ }, true, RPCRequest.RPCRequestClassGeneric);
}
}
@@ -1540,7 +1562,7 @@ public class ContactsController {
}
});
}
- }, null, true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassFailOnServerErrors | RPCRequest.RPCRequestClassCanCompress);
+ }, true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassFailOnServerErrors | RPCRequest.RPCRequestClassCanCompress);
}
public void deleteContact(final ArrayList users) {
@@ -1607,6 +1629,6 @@ public class ContactsController {
}
});
}
- }, null, true, RPCRequest.RPCRequestClassGeneric);
+ }, true, RPCRequest.RPCRequestClassGeneric);
}
}
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/ContactsSyncAdapterService.java b/TMessagesProj/src/main/java/org/telegram/android/ContactsSyncAdapterService.java
similarity index 96%
rename from TMessagesProj/src/main/java/org/telegram/messenger/ContactsSyncAdapterService.java
rename to TMessagesProj/src/main/java/org/telegram/android/ContactsSyncAdapterService.java
index d6d3ecd3..852a8483 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/ContactsSyncAdapterService.java
+++ b/TMessagesProj/src/main/java/org/telegram/android/ContactsSyncAdapterService.java
@@ -6,7 +6,7 @@
* Copyright Nikolai Kudashov, 2013.
*/
-package org.telegram.messenger;
+package org.telegram.android;
import android.accounts.Account;
import android.accounts.OperationCanceledException;
@@ -19,6 +19,8 @@ import android.content.SyncResult;
import android.os.Bundle;
import android.os.IBinder;
+import org.telegram.messenger.FileLog;
+
public class ContactsSyncAdapterService extends Service {
private static SyncAdapterImpl sSyncAdapter = null;
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/Emoji.java b/TMessagesProj/src/main/java/org/telegram/android/Emoji.java
similarity index 97%
rename from TMessagesProj/src/main/java/org/telegram/messenger/Emoji.java
rename to TMessagesProj/src/main/java/org/telegram/android/Emoji.java
index 5bd32559..3e7b108e 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/Emoji.java
+++ b/TMessagesProj/src/main/java/org/telegram/android/Emoji.java
@@ -6,7 +6,7 @@
* Copyright Nikolai Kudashov, 2013.
*/
-package org.telegram.messenger;
+package org.telegram.android;
import java.io.File;
import java.io.InputStream;
@@ -26,6 +26,9 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
+import org.telegram.messenger.FileLog;
+import org.telegram.messenger.NotificationCenter;
+import org.telegram.messenger.Utilities;
import org.telegram.ui.ApplicationLoader;
public class Emoji {
@@ -202,17 +205,17 @@ public class Emoji {
0x00000000D83DDD34L, 0x00000000D83DDD35L, 0x00000000D83DDD3BL, 0x00000000D83DDD36L, 0x00000000D83DDD37L, 0x00000000D83DDD38L, 0x00000000D83DDD39L}};
static {
- if (Utilities.density <= 1.0f) {
+ if (AndroidUtilities.density <= 1.0f) {
emojiFullSize = 30;
- } else if (Utilities.density <= 1.5f) {
+ } else if (AndroidUtilities.density <= 1.5f) {
emojiFullSize = 45;
- } else if (Utilities.density <= 2.0f) {
+ } else if (AndroidUtilities.density <= 2.0f) {
emojiFullSize = 60;
} else {
emojiFullSize = 90;
}
- drawImgSize = Utilities.dp(20);
- bigImgSize = Utilities.dp(30);
+ drawImgSize = AndroidUtilities.dp(20);
+ bigImgSize = AndroidUtilities.dp(30);
for (int j = 1; j < data.length; j++) {
for (int i = 0; i < data[j].length; i++) {
@@ -228,13 +231,13 @@ public class Emoji {
try {
float scale = 1.0f;
int imageResize = 1;
- if (Utilities.density <= 1.0f) {
+ if (AndroidUtilities.density <= 1.0f) {
scale = 2.0f;
imageResize = 2;
- } else if (Utilities.density <= 1.5f) {
+ } else if (AndroidUtilities.density <= 1.5f) {
scale = 3.0f;
imageResize = 2;
- } else if (Utilities.density <= 2.0f) {
+ } else if (AndroidUtilities.density <= 2.0f) {
scale = 2.0f;
} else {
scale = 3.0f;
@@ -466,7 +469,7 @@ public class Emoji {
public static class EmojiSpan extends ImageSpan {
private Paint.FontMetricsInt fontMetrics = null;
- int size = Utilities.dp(20);
+ int size = AndroidUtilities.dp(20);
public EmojiSpan(Drawable d, int verticalAlignment, int s, Paint.FontMetricsInt original) {
super(d, verticalAlignment);
@@ -474,7 +477,7 @@ public class Emoji {
if (original != null) {
size = Math.abs(fontMetrics.descent) + Math.abs(fontMetrics.ascent);
if (size == 0) {
- size = Utilities.dp(20);
+ size = AndroidUtilities.dp(20);
}
}
}
@@ -488,8 +491,8 @@ public class Emoji {
if (fontMetrics == null) {
int sz = super.getSize(paint, text, start, end, fm);
- int offset = Utilities.dp(8);
- int w = Utilities.dp(10);
+ int offset = AndroidUtilities.dp(8);
+ int w = AndroidUtilities.dp(10);
fm.top = -w - offset;
fm.bottom = w - offset;
fm.ascent = -w - offset;
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/FastDateFormat.java b/TMessagesProj/src/main/java/org/telegram/android/FastDateFormat.java
similarity index 99%
rename from TMessagesProj/src/main/java/org/telegram/messenger/FastDateFormat.java
rename to TMessagesProj/src/main/java/org/telegram/android/FastDateFormat.java
index 91b7d0eb..0d0a029a 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/FastDateFormat.java
+++ b/TMessagesProj/src/main/java/org/telegram/android/FastDateFormat.java
@@ -5,7 +5,7 @@
*
* Copyright Nikolai Kudashov, 2013.
*/
-package org.telegram.messenger;
+package org.telegram.android;
import java.io.IOException;
import java.io.ObjectInputStream;
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/GcmBroadcastReceiver.java b/TMessagesProj/src/main/java/org/telegram/android/GcmBroadcastReceiver.java
similarity index 95%
rename from TMessagesProj/src/main/java/org/telegram/messenger/GcmBroadcastReceiver.java
rename to TMessagesProj/src/main/java/org/telegram/android/GcmBroadcastReceiver.java
index 76326583..291717ae 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/GcmBroadcastReceiver.java
+++ b/TMessagesProj/src/main/java/org/telegram/android/GcmBroadcastReceiver.java
@@ -6,7 +6,7 @@
* Copyright Nikolai Kudashov, 2013.
*/
-package org.telegram.messenger;
+package org.telegram.android;
import android.app.Activity;
import android.content.BroadcastReceiver;
@@ -14,6 +14,9 @@ import android.content.Context;
import android.content.Intent;
import org.json.JSONObject;
+import org.telegram.messenger.ConnectionsManager;
+import org.telegram.messenger.FileLog;
+import org.telegram.messenger.Utilities;
import org.telegram.ui.ApplicationLoader;
public class GcmBroadcastReceiver extends BroadcastReceiver {
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/LocaleController.java b/TMessagesProj/src/main/java/org/telegram/android/LocaleController.java
similarity index 95%
rename from TMessagesProj/src/main/java/org/telegram/messenger/LocaleController.java
rename to TMessagesProj/src/main/java/org/telegram/android/LocaleController.java
index 3b80c2a1..852e6435 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/LocaleController.java
+++ b/TMessagesProj/src/main/java/org/telegram/android/LocaleController.java
@@ -6,7 +6,7 @@
* Copyright Nikolai Kudashov, 2013-2014.
*/
-package org.telegram.messenger;
+package org.telegram.android;
import android.app.Activity;
import android.content.BroadcastReceiver;
@@ -18,6 +18,11 @@ import android.content.res.Configuration;
import android.text.format.DateFormat;
import android.util.Xml;
+import org.telegram.messenger.ConnectionsManager;
+import org.telegram.messenger.FileLog;
+import org.telegram.messenger.R;
+import org.telegram.messenger.TLRPC;
+import org.telegram.messenger.Utilities;
import org.telegram.ui.ApplicationLoader;
import org.xmlpull.v1.XmlPullParser;
@@ -215,6 +220,9 @@ public class LocaleController {
if (currentInfo == null && systemDefaultLocale.getLanguage() != null) {
currentInfo = languagesDict.get(systemDefaultLocale.getLanguage());
}
+ if (currentInfo == null) {
+ currentInfo = languagesDict.get(getLocaleString(systemDefaultLocale));
+ }
if (currentInfo == null) {
currentInfo = languagesDict.get("en");
}
@@ -231,6 +239,29 @@ public class LocaleController {
}
}
+ private String getLocaleString(Locale locale) {
+ if (locale == null) {
+ return "";
+ }
+ String languageCode = locale.getLanguage();
+ String countryCode = locale.getCountry();
+ String variantCode = locale.getVariant();
+ if (languageCode.length() == 0 && countryCode.length() == 0) {
+ return "";
+ }
+ StringBuilder result = new StringBuilder(11);
+ result.append(languageCode);
+ if (countryCode.length() > 0 || variantCode.length() > 0) {
+ result.append('_');
+ }
+ result.append(countryCode);
+ if (variantCode.length() > 0) {
+ result.append('_');
+ }
+ result.append(variantCode);
+ return result.toString();
+ }
+
public boolean applyLanguageFile(File file) {
try {
HashMap stringMap = getLocaleFileStrings(file);
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/MediaController.java b/TMessagesProj/src/main/java/org/telegram/android/MediaController.java
similarity index 98%
rename from TMessagesProj/src/main/java/org/telegram/messenger/MediaController.java
rename to TMessagesProj/src/main/java/org/telegram/android/MediaController.java
index edd741ed..da29c291 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/MediaController.java
+++ b/TMessagesProj/src/main/java/org/telegram/android/MediaController.java
@@ -6,7 +6,7 @@
* Copyright Nikolai Kudashov, 2013-2014.
*/
-package org.telegram.messenger;
+package org.telegram.android;
import android.app.ProgressDialog;
import android.content.Context;
@@ -26,6 +26,15 @@ import android.os.Vibrator;
import android.provider.MediaStore;
import android.view.View;
+import org.telegram.messenger.ConnectionsManager;
+import org.telegram.messenger.DispatchQueue;
+import org.telegram.messenger.FileLoader;
+import org.telegram.messenger.FileLog;
+import org.telegram.messenger.NotificationCenter;
+import org.telegram.messenger.R;
+import org.telegram.messenger.TLRPC;
+import org.telegram.messenger.UserConfig;
+import org.telegram.messenger.Utilities;
import org.telegram.objects.MessageObject;
import org.telegram.ui.ApplicationLoader;
import org.telegram.ui.Cells.ChatMediaCell;
@@ -129,6 +138,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
public final static int recordStopped = 50006;
public final static int screenshotTook = 50007;
public final static int albumsDidLoaded = 50008;
+ public final static int audioDidSent = 50009;
private HashMap>> loadingFileObservers = new HashMap>>();
private HashMap observersByTag = new HashMap();
@@ -497,7 +507,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
Thread.sleep(1000);
}
if (bitmapRegionDecoder != null) {
- Bitmap bitmap = bitmapRegionDecoder.decodeRegion(new Rect(0, 0, Utilities.dp(44), Utilities.dp(44)), null);
+ Bitmap bitmap = bitmapRegionDecoder.decodeRegion(new Rect(0, 0, AndroidUtilities.dp(44), AndroidUtilities.dp(44)), null);
int w = bitmap.getWidth();
int h = bitmap.getHeight();
for (int y = 0; y < h; y++) {
@@ -926,7 +936,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
return true;
}
clenupPlayer(true);
- final File cacheFile = new File(Utilities.getCacheDir(), messageObject.getFileName());
+ final File cacheFile = new File(AndroidUtilities.getCacheDir(), messageObject.getFileName());
if (isOpusFile(cacheFile.getAbsolutePath()) == 1) {
synchronized (playerObjectSync) {
@@ -1144,10 +1154,11 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
recordingAudio.dc_id = Integer.MIN_VALUE;
recordingAudio.id = UserConfig.lastLocalId;
recordingAudio.user_id = UserConfig.getClientUserId();
+ recordingAudio.mime_type = "audio/ogg";
UserConfig.lastLocalId--;
UserConfig.saveConfig(false);
- recordingAudioFile = new File(Utilities.getCacheDir(), MessageObject.getAttachFileName(recordingAudio));
+ recordingAudioFile = new File(AndroidUtilities.getCacheDir(), MessageObject.getAttachFileName(recordingAudio));
try {
if (startRecord(recordingAudioFile.getAbsolutePath()) == 0) {
@@ -1257,6 +1268,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
} else {
recordingAudioFileToSend.delete();
}
+ NotificationCenter.getInstance().postNotificationName(audioDidSent);
}
});
}
@@ -1292,7 +1304,6 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
if (audioRecorder == null) {
return;
}
- //recordTimeCount = System.currentTimeMillis() - recordStartTime;
try {
sendAfterDone = send;
audioRecorder.stop();
@@ -1334,7 +1345,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
}
}
if (file == null) {
- file = new File(Utilities.getCacheDir(), path);
+ file = new File(AndroidUtilities.getCacheDir(), path);
}
final File sourceFile = file;
@@ -1466,7 +1477,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
}
}
if (cacheFile == null) {
- cacheFile = new File(Utilities.getCacheDir(), messageObject.getFileName());
+ cacheFile = new File(AndroidUtilities.getCacheDir(), messageObject.getFileName());
}
try {
currentGifDrawable = new GifDrawable(cacheFile);
@@ -1545,7 +1556,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
UserConfig.lastLocalId--;
parcelFD = ApplicationLoader.applicationContext.getContentResolver().openFileDescriptor(uri, "r");
input = new FileInputStream(parcelFD.getFileDescriptor());
- File f = new File(Utilities.getCacheDir(), String.format(Locale.US, "%d.%s", id, ext));
+ File f = new File(AndroidUtilities.getCacheDir(), String.format(Locale.US, "%d.%s", id, ext));
output = new FileOutputStream(f);
input.getChannel().transferTo(0, input.getChannel().size(), output.getChannel());
UserConfig.saveConfig(false);
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java b/TMessagesProj/src/main/java/org/telegram/android/MessagesController.java
similarity index 87%
rename from TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java
rename to TMessagesProj/src/main/java/org/telegram/android/MessagesController.java
index 0522800f..e514dc6c 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java
+++ b/TMessagesProj/src/main/java/org/telegram/android/MessagesController.java
@@ -6,10 +6,8 @@
* Copyright Nikolai Kudashov, 2013.
*/
-package org.telegram.messenger;
+package org.telegram.android;
-import android.accounts.Account;
-import android.accounts.AccountManager;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Notification;
@@ -23,21 +21,33 @@ import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.graphics.Bitmap;
import android.media.AudioManager;
-import android.media.SoundPool;
import android.net.Uri;
import android.os.Build;
-import android.os.Vibrator;
import android.provider.Settings;
import android.support.v4.app.NotificationCompat;
import android.text.Html;
-import android.util.SparseArray;
import org.json.JSONArray;
import org.json.JSONObject;
+import org.telegram.messenger.BuffersStorage;
+import org.telegram.messenger.ByteBufferDesc;
+import org.telegram.messenger.ConnectionsManager;
+import org.telegram.messenger.FileLoader;
+import org.telegram.messenger.FileLog;
+import org.telegram.messenger.MessageKeyData;
+import org.telegram.messenger.NotificationCenter;
+import org.telegram.messenger.R;
+import org.telegram.messenger.RPCRequest;
+import org.telegram.messenger.TLClassStore;
+import org.telegram.messenger.TLObject;
+import org.telegram.messenger.TLRPC;
+import org.telegram.messenger.UserConfig;
+import org.telegram.messenger.Utilities;
import org.telegram.objects.MessageObject;
import org.telegram.objects.PhotoObject;
-import org.telegram.ui.LaunchActivity;
import org.telegram.ui.ApplicationLoader;
+import org.telegram.ui.LaunchActivity;
+import org.telegram.ui.PopupNotificationActivity;
import java.io.File;
import java.math.BigInteger;
@@ -56,15 +66,15 @@ public class MessagesController implements NotificationCenter.NotificationCenter
public ArrayList dialogs = new ArrayList();
public ArrayList dialogsServerOnly = new ArrayList();
public ConcurrentHashMap dialogs_dict = new ConcurrentHashMap(100, 1.0f, 2);
- public SparseArray dialogMessage = new SparseArray();
+ public HashMap dialogMessage = new HashMap();
public ConcurrentHashMap> printingUsers = new ConcurrentHashMap>(100, 1.0f, 2);
public HashMap printingStrings = new HashMap();
private int lastPrintingStringCount = 0;
private HashMap> delayedMessages = new HashMap>();
- public SparseArray sendingMessages = new SparseArray();
- public SparseArray hidenAddToContacts = new SparseArray();
- private SparseArray acceptingChats = new SparseArray();
+ public HashMap sendingMessages = new HashMap();
+ public HashMap hidenAddToContacts = new HashMap();
+ private HashMap acceptingChats = new HashMap();
private ArrayList updatesQueue = new ArrayList();
private ArrayList pendingEncMessagesToDelete = new ArrayList();
private long updatesStartWaitTime = 0;
@@ -84,18 +94,18 @@ public class MessagesController implements NotificationCenter.NotificationCenter
public boolean updatingState = false;
public boolean firstGettingTask = false;
public boolean registeringForPush = false;
- private long lastSoundPlay = 0;
+
private long lastStatusUpdateTime = 0;
private long statusRequest = 0;
private int statusSettingState = 0;
private boolean offlineSent = false;
private String uploadingAvatar = null;
- private SoundPool soundPool;
- private int sound;
+
public boolean enableJoined = true;
- public int fontSize = Utilities.dp(16);
+ public int fontSize = AndroidUtilities.dp(16);
public MessageObject currentPushMessage;
+ public ArrayList pushMessages = new ArrayList();
private class UserActionUpdates extends TLRPC.Updates {
@@ -168,6 +178,9 @@ public class MessagesController implements NotificationCenter.NotificationCenter
public static final int removeAllMessagesFromDialog = 25;
+ public static final int notificationsSettingsUpdated = 26;
+ public static final int pushMessagesUpdated = 27;
+
private static volatile MessagesController Instance = null;
public static MessagesController getInstance() {
MessagesController localInstance = Instance;
@@ -192,13 +205,6 @@ public class MessagesController implements NotificationCenter.NotificationCenter
enableJoined = preferences.getBoolean("EnableContactJoined", true);
preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
fontSize = preferences.getInt("fons_size", 16);
-
- try {
- soundPool = new SoundPool(1, AudioManager.STREAM_NOTIFICATION, 0);
- sound = soundPool.load(ApplicationLoader.applicationContext, R.raw.sound_a, 1);
- } catch (Exception e) {
- FileLog.e("tmessages", e);
- }
}
public void addSupportUser() {
@@ -233,9 +239,136 @@ public class MessagesController implements NotificationCenter.NotificationCenter
@Override
public void didReceivedNotification(int id, Object... args) {
if (id == FileLoader.FileDidUpload) {
- fileDidUploaded((String)args[0], (TLRPC.InputFile)args[1], (TLRPC.InputEncryptedFile)args[2]);
+ final String location = (String)args[0];
+ final TLRPC.InputFile file = (TLRPC.InputFile)args[1];
+ final TLRPC.InputEncryptedFile encryptedFile = (TLRPC.InputEncryptedFile)args[2];
+
+ if (uploadingAvatar != null && uploadingAvatar.equals(location)) {
+ TLRPC.TL_photos_uploadProfilePhoto req = new TLRPC.TL_photos_uploadProfilePhoto();
+ req.caption = "";
+ req.crop = new TLRPC.TL_inputPhotoCropAuto();
+ req.file = file;
+ req.geo_point = new TLRPC.TL_inputGeoPointEmpty();
+ ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() {
+ @Override
+ public void run(TLObject response, TLRPC.TL_error error) {
+ if (error == null) {
+ TLRPC.User user = users.get(UserConfig.getClientUserId());
+ if (user == null) {
+ user = UserConfig.getCurrentUser();
+ users.put(user.id, user);
+ } else {
+ UserConfig.setCurrentUser(user);
+ }
+ if (user == null) {
+ return;
+ }
+ TLRPC.TL_photos_photo photo = (TLRPC.TL_photos_photo) response;
+ ArrayList sizes = photo.photo.sizes;
+ TLRPC.PhotoSize smallSize = PhotoObject.getClosestPhotoSizeWithSize(sizes, 100, 100);
+ TLRPC.PhotoSize bigSize = PhotoObject.getClosestPhotoSizeWithSize(sizes, 1000, 1000);
+ user.photo = new TLRPC.TL_userProfilePhoto();
+ user.photo.photo_id = photo.photo.id;
+ if (smallSize != null) {
+ user.photo.photo_small = smallSize.location;
+ }
+ if (bigSize != null) {
+ user.photo.photo_big = bigSize.location;
+ } else if (smallSize != null) {
+ user.photo.photo_small = smallSize.location;
+ }
+ MessagesStorage.getInstance().clearUserPhotos(user.id);
+ ArrayList users = new ArrayList();
+ users.add(user);
+ MessagesStorage.getInstance().putUsersAndChats(users, null, false, true);
+ Utilities.RunOnUIThread(new Runnable() {
+ @Override
+ public void run() {
+ NotificationCenter.getInstance().postNotificationName(updateInterfaces, UPDATE_MASK_AVATAR);
+ UserConfig.saveConfig(true);
+ }
+ });
+ }
+ }
+ });
+ } else {
+ Utilities.RunOnUIThread(new Runnable() {
+ @Override
+ public void run() {
+ ArrayList arr = delayedMessages.get(location);
+ if (arr != null) {
+ for (int a = 0; a < arr.size(); a++) {
+ DelayedMessage message = arr.get(a);
+ if (file != null && message.sendRequest != null) {
+ if (message.type == 0) {
+ message.sendRequest.media.file = file;
+ performSendMessageRequest(message.sendRequest, message.obj, message.originalPath);
+ } else if (message.type == 1) {
+ if (message.sendRequest.media.thumb == null) {
+ message.sendRequest.media.thumb = file;
+ performSendDelayedMessage(message);
+ } else {
+ message.sendRequest.media.file = file;
+ performSendMessageRequest(message.sendRequest, message.obj, message.originalPath);
+ }
+ } else if (message.type == 2) {
+ if (message.sendRequest.media.thumb == null && message.location != null) {
+ message.sendRequest.media.thumb = file;
+ performSendDelayedMessage(message);
+ } else {
+ message.sendRequest.media.file = file;
+ performSendMessageRequest(message.sendRequest, message.obj, message.originalPath);
+ }
+ } else if (message.type == 3) {
+ message.sendRequest.media.file = file;
+ performSendMessageRequest(message.sendRequest, message.obj, message.originalPath);
+ }
+ arr.remove(a);
+ a--;
+ } else if (encryptedFile != null && message.sendEncryptedRequest != null) {
+ message.sendEncryptedRequest.media.key = encryptedFile.key;
+ message.sendEncryptedRequest.media.iv = encryptedFile.iv;
+ performSendEncryptedRequest(message.sendEncryptedRequest, message.obj, message.encryptedChat, encryptedFile, message.originalPath);
+ arr.remove(a);
+ a--;
+ }
+ }
+ if (arr.isEmpty()) {
+ delayedMessages.remove(location);
+ }
+ }
+ }
+ });
+ }
} else if (id == FileLoader.FileDidFailUpload) {
- fileDidFailedUpload((String) args[0], (Boolean) args[1]);
+ final String location = (String) args[0];
+ final boolean enc = (Boolean) args[1];
+
+ if (uploadingAvatar != null && uploadingAvatar.equals(location)) {
+ uploadingAvatar = null;
+ } else {
+ Utilities.RunOnUIThread(new Runnable() {
+ @Override
+ public void run() {
+ ArrayList arr = delayedMessages.get(location);
+ if (arr != null) {
+ for (int a = 0; a < arr.size(); a++) {
+ DelayedMessage obj = arr.get(a);
+ if (enc && obj.sendEncryptedRequest != null || !enc && obj.sendRequest != null) {
+ obj.obj.messageOwner.send_state = MESSAGE_SEND_STATE_SEND_ERROR;
+ sendingMessages.remove(obj.obj.messageOwner.id);
+ arr.remove(a);
+ a--;
+ NotificationCenter.getInstance().postNotificationName(messageSendError, obj.obj.messageOwner.id);
+ }
+ }
+ if (arr.isEmpty()) {
+ delayedMessages.remove(location);
+ }
+ }
+ }
+ });
+ }
} else if (id == messageReceivedByServer) {
Integer msgId = (Integer)args[0];
MessageObject obj = dialogMessage.get(msgId);
@@ -315,6 +448,8 @@ public class MessagesController implements NotificationCenter.NotificationCenter
startingSecretChat = false;
statusRequest = 0;
statusSettingState = 0;
+ currentPushMessage = null;
+ pushMessages.clear();
addSupportUser();
}
@@ -382,18 +517,6 @@ public class MessagesController implements NotificationCenter.NotificationCenter
});
}
- public void deleteAllAppAccounts() {
- try {
- AccountManager am = AccountManager.get(ApplicationLoader.applicationContext);
- Account[] accounts = am.getAccountsByType("org.telegram.account");
- for (Account c : accounts) {
- am.removeAccount(c, null, null);
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
public void loadUserPhotos(final int uid, final int offset, final int count, final long max_id, final boolean fromCache, final int classGuid) {
if (fromCache) {
MessagesStorage.getInstance().getUserPhotos(uid, offset, count, max_id, classGuid);
@@ -415,7 +538,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
processLoadedUserPhotos(res, uid, offset, count, max_id, fromCache, classGuid);
}
}
- }, null, true, RPCRequest.RPCRequestClassGeneric);
+ });
ConnectionsManager.getInstance().bindRequestToGuid(reqId, classGuid);
}
}
@@ -518,7 +641,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
processLoadedMedia(res, uid, offset, count, max_id, false, classGuid);
}
}
- }, null, true, RPCRequest.RPCRequestClassGeneric);
+ });
ConnectionsManager.getInstance().bindRequestToGuid(reqId, classGuid);
}
}
@@ -580,14 +703,14 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}
}
}
- }, null, true, RPCRequest.RPCRequestClassGeneric);
+ });
ConnectionsManager.getInstance().bindRequestToGuid(reqId, classGuid);
}
}
public void uploadAndApplyUserAvatar(TLRPC.PhotoSize bigPhoto) {
if (bigPhoto != null) {
- uploadingAvatar = Utilities.getCacheDir() + "/" + bigPhoto.location.volume_id + "_" + bigPhoto.location.local_id + ".jpg";
+ uploadingAvatar = AndroidUtilities.getCacheDir() + "/" + bigPhoto.location.volume_id + "_" + bigPhoto.location.local_id + ".jpg";
FileLoader.getInstance().uploadFile(uploadingAvatar, false);
}
}
@@ -623,7 +746,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
public void run(TLObject response, TLRPC.TL_error error) {
}
- }, null, true, RPCRequest.RPCRequestClassGeneric);
+ });
}
public void deleteDialog(final long did, int offset, final boolean onlyHistory) {
@@ -688,7 +811,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}
}
}
- }, null, true, RPCRequest.RPCRequestClassGeneric);
+ });
} else {
int encId = (int)(did >> 32);
if (onlyHistory) {
@@ -734,7 +857,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}
});
}
- }, null, true, RPCRequest.RPCRequestClassGeneric);
+ });
} else {
Utilities.RunOnUIThread(new Runnable() {
@Override
@@ -761,7 +884,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
checkDeletingTask();
if (UserConfig.isClientActivated()) {
- if (ConnectionsManager.lastPauseTime == 0) {
+ if (ConnectionsManager.getInstance().getPauseTime() == 0 && ApplicationLoader.isScreenOn) {
if (statusSettingState != 1 && (lastStatusUpdateTime == 0 || lastStatusUpdateTime <= System.currentTimeMillis() - 55000 || offlineSent)) {
statusSettingState = 1;
@@ -785,9 +908,9 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}
statusRequest = 0;
}
- }, null, true, RPCRequest.RPCRequestClassGeneric);
+ });
}
- } else if (statusSettingState != 2 && !offlineSent && ConnectionsManager.lastPauseTime <= System.currentTimeMillis() - 2000) {
+ } else if (statusSettingState != 2 && !offlineSent && ConnectionsManager.getInstance().getPauseTime() <= System.currentTimeMillis() - 2000) {
statusSettingState = 2;
if (statusRequest != 0) {
ConnectionsManager.getInstance().cancelRpc(statusRequest, true);
@@ -806,7 +929,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}
statusRequest = 0;
}
- }, null, true, RPCRequest.RPCRequestClassGeneric);
+ });
}
if (updatesStartWaitTime != 0 && updatesStartWaitTime + 1500 < currentTime) {
@@ -927,7 +1050,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
public void run(TLObject response, TLRPC.TL_error error) {
}
- }, null, true, RPCRequest.RPCRequestClassGeneric);
+ });
ConnectionsManager.getInstance().bindRequestToGuid(reqId, classGuid);
} else {
int encId = (int)(dialog_id >> 32);
@@ -943,7 +1066,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
public void run(TLObject response, TLRPC.TL_error error) {
}
- }, null, true, RPCRequest.RPCRequestClassGeneric);
+ });
ConnectionsManager.getInstance().bindRequestToGuid(reqId, classGuid);
}
}
@@ -980,7 +1103,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
processLoadedMessages(res, dialog_id, offset, count, max_id, false, classGuid, 0, 0, 0, 0, false);
}
}
- }, null, true, RPCRequest.RPCRequestClassGeneric);
+ });
ConnectionsManager.getInstance().bindRequestToGuid(reqId, classGuid);
}
}
@@ -1062,7 +1185,29 @@ public class MessagesController implements NotificationCenter.NotificationCenter
processLoadedDialogs(dialogsRes, null, offset, serverOffset, count, false, false);
}
}
- }, null, true, RPCRequest.RPCRequestClassGeneric);
+ });
+ }
+ }
+
+ private void applyDialogsNotificationsSettings(ArrayList dialogs) {
+ SharedPreferences.Editor editor = null;
+ for (TLRPC.TL_dialog dialog : dialogs) {
+ if (dialog.peer != null && dialog.notify_settings instanceof TLRPC.TL_peerNotifySettings) {
+ if (editor == null) {
+ SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
+ editor = preferences.edit();
+ }
+ int dialog_id = dialog.peer.user_id;
+ if (dialog_id == 0) {
+ dialog_id = -dialog.peer.chat_id;
+ }
+ if (dialog.notify_settings.mute_until != 0) {
+ editor.putInt("notify2_" + dialog_id, 2);
+ }
+ }
+ }
+ if (editor != null) {
+ editor.commit();
}
}
@@ -1255,6 +1400,9 @@ public class MessagesController implements NotificationCenter.NotificationCenter
Utilities.RunOnUIThread(new Runnable() {
@Override
public void run() {
+ if (!isCache) {
+ applyDialogsNotificationsSettings(dialogsRes.dialogs);
+ }
for (TLRPC.User u : dialogsRes.users) {
if (isCache) {
if (u.id == UserConfig.getClientUserId() || u.id / 1000 == 333) {
@@ -1360,10 +1508,8 @@ public class MessagesController implements NotificationCenter.NotificationCenter
size.type = "x";
sizes.add(size);
}
- if (Build.VERSION.SDK_INT < 11) {
- if (bitmap != null) {
- bitmap.recycle();
- }
+ if (bitmap != null) {
+ bitmap.recycle();
}
if (sizes.isEmpty()) {
return null;
@@ -1436,7 +1582,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}
}
}
- }, null, true, RPCRequest.RPCRequestClassGeneric);
+ });
}
MessagesStorage.getInstance().storageQueue.postRunnable(new Runnable() {
@@ -1464,7 +1610,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
public void run(TLObject response, TLRPC.TL_error error) {
}
- }, null, true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassFailOnServerErrors);
+ }, true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassFailOnServerErrors);
}
} else {
if (max_date == 0) {
@@ -1484,7 +1630,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
public void run(TLObject response, TLRPC.TL_error error) {
//MessagesStorage.getInstance().processPendingRead(dialog_id, max_id, max_date, true);
}
- }, null, true, RPCRequest.RPCRequestClassGeneric);
+ });
}
MessagesStorage.getInstance().processPendingRead(dialog_id, max_id, max_date, false);
@@ -1732,7 +1878,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
type = 2;
newMsg.message = "-1";
TLRPC.FileLocation location1 = photo.sizes.get(photo.sizes.size() - 1).location;
- newMsg.attachPath = Utilities.getCacheDir() + "/" + location1.volume_id + "_" + location1.local_id + ".jpg";
+ newMsg.attachPath = AndroidUtilities.getCacheDir() + "/" + location1.volume_id + "_" + location1.local_id + ".jpg";
} else if (video != null) {
newMsg = new TLRPC.TL_message();
newMsg.media = new TLRPC.TL_messageMediaVideo();
@@ -1896,6 +2042,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
reqSend.media.duration = video.duration;
reqSend.media.w = video.w;
reqSend.media.h = video.h;
+ reqSend.media.mime_type = video.mime_type;
DelayedMessage delayedMessage = new DelayedMessage();
delayedMessage.originalPath = originalPath;
delayedMessage.sendRequest = reqSend;
@@ -1946,6 +2093,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
} else if (type == 8) {
reqSend.media = new TLRPC.TL_inputMediaUploadedAudio();
reqSend.media.duration = audio.duration;
+ reqSend.media.mime_type = audio.mime_type;
DelayedMessage delayedMessage = new DelayedMessage();
delayedMessage.sendRequest = reqSend;
delayedMessage.type = 3;
@@ -1992,7 +2140,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
performSendEncryptedRequest(reqSend, newMsgObj, encryptedChat, encryptedFile, null);
}
} else if (type == 3) {
- reqSend.media = new TLRPC.TL_decryptedMessageMediaVideo();
+ reqSend.media = new TLRPC.TL_decryptedMessageMediaVideo_old();
reqSend.media.duration = video.duration;
reqSend.media.size = video.size;
reqSend.media.w = video.w;
@@ -2000,6 +2148,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
reqSend.media.thumb = video.thumb.bytes;
reqSend.media.thumb_h = video.thumb.h;
reqSend.media.thumb_w = video.thumb.w;
+ reqSend.media.mime_type = "video/mp4";
if (video.access_hash == 0) {
DelayedMessage delayedMessage = new DelayedMessage();
delayedMessage.originalPath = originalPath;
@@ -2056,9 +2205,10 @@ public class MessagesController implements NotificationCenter.NotificationCenter
performSendEncryptedRequest(reqSend, newMsgObj, encryptedChat, encryptedFile, null);
}
} else if (type == 8) {
- reqSend.media = new TLRPC.TL_decryptedMessageMediaAudio();
+ reqSend.media = new TLRPC.TL_decryptedMessageMediaAudio_old();
reqSend.media.duration = audio.duration;
reqSend.media.size = audio.size;
+ reqSend.media.mime_type = "audio/ogg";
DelayedMessage delayedMessage = new DelayedMessage();
delayedMessage.sendEncryptedRequest = reqSend;
@@ -2098,8 +2248,8 @@ public class MessagesController implements NotificationCenter.NotificationCenter
if (fileName.equals(fileName2)) {
break;
}
- File cacheFile = new File(Utilities.getCacheDir(), fileName + ".jpg");
- File cacheFile2 = new File(Utilities.getCacheDir(), fileName2 + ".jpg");
+ File cacheFile = new File(AndroidUtilities.getCacheDir(), fileName + ".jpg");
+ File cacheFile2 = new File(AndroidUtilities.getCacheDir(), fileName2 + ".jpg");
cacheFile.renameTo(cacheFile2);
FileLoader.getInstance().replaceImageInCache(fileName, fileName2);
size2.location = size.location;
@@ -2118,8 +2268,8 @@ public class MessagesController implements NotificationCenter.NotificationCenter
String fileName = size2.location.volume_id + "_" + size2.location.local_id;
String fileName2 = size.location.volume_id + "_" + size.location.local_id;
if (!fileName.equals(fileName2)) {
- File cacheFile = new File(Utilities.getCacheDir(), fileName + ".jpg");
- File cacheFile2 = new File(Utilities.getCacheDir(), fileName2 + ".jpg");
+ File cacheFile = new File(AndroidUtilities.getCacheDir(), fileName + ".jpg");
+ File cacheFile2 = new File(AndroidUtilities.getCacheDir(), fileName2 + ".jpg");
boolean result = cacheFile.renameTo(cacheFile2);
FileLoader.getInstance().replaceImageInCache(fileName, fileName2);
size2.location = size.location;
@@ -2136,16 +2286,16 @@ public class MessagesController implements NotificationCenter.NotificationCenter
String fileName = size2.location.volume_id + "_" + size2.location.local_id;
String fileName2 = size.location.volume_id + "_" + size.location.local_id;
if (!fileName.equals(fileName2)) {
- File cacheFile = new File(Utilities.getCacheDir(), fileName + ".jpg");
- File cacheFile2 = new File(Utilities.getCacheDir(), fileName2 + ".jpg");
+ File cacheFile = new File(AndroidUtilities.getCacheDir(), fileName + ".jpg");
+ File cacheFile2 = new File(AndroidUtilities.getCacheDir(), fileName2 + ".jpg");
boolean result = cacheFile.renameTo(cacheFile2);
FileLoader.getInstance().replaceImageInCache(fileName, fileName2);
size2.location = size.location;
}
}
- if (newMsg.attachPath != null && newMsg.attachPath.startsWith(Utilities.getCacheDir().getAbsolutePath())) {
+ if (newMsg.attachPath != null && newMsg.attachPath.startsWith(AndroidUtilities.getCacheDir().getAbsolutePath())) {
File cacheFile = new File(newMsg.attachPath);
- File cacheFile2 = new File(Utilities.getCacheDir(), MessageObject.getAttachFileName(sentMessage.media.document));
+ File cacheFile2 = new File(AndroidUtilities.getCacheDir(), MessageObject.getAttachFileName(sentMessage.media.document));
boolean result = cacheFile.renameTo(cacheFile2);
if (result) {
newMsg.attachPath = null;
@@ -2166,8 +2316,8 @@ public class MessagesController implements NotificationCenter.NotificationCenter
String fileName = newMsg.media.audio.dc_id + "_" + newMsg.media.audio.id + ".m4a";
String fileName2 = sentMessage.media.audio.dc_id + "_" + sentMessage.media.audio.id + ".m4a";
if (!fileName.equals(fileName2)) {
- File cacheFile = new File(Utilities.getCacheDir(), fileName);
- File cacheFile2 = new File(Utilities.getCacheDir(), fileName2);
+ File cacheFile = new File(AndroidUtilities.getCacheDir(), fileName);
+ File cacheFile2 = new File(AndroidUtilities.getCacheDir(), fileName2);
cacheFile.renameTo(cacheFile2);
newMsg.media.audio.dc_id = sentMessage.media.audio.dc_id;
newMsg.media.audio.id = sentMessage.media.audio.id;
@@ -2185,8 +2335,8 @@ public class MessagesController implements NotificationCenter.NotificationCenter
size.location.secret = file.access_hash;
size.location.local_id = file.key_fingerprint;
String fileName2 = size.location.volume_id + "_" + size.location.local_id;
- File cacheFile = new File(Utilities.getCacheDir(), fileName + ".jpg");
- File cacheFile2 = new File(Utilities.getCacheDir(), fileName2 + ".jpg");
+ File cacheFile = new File(AndroidUtilities.getCacheDir(), fileName + ".jpg");
+ File cacheFile2 = new File(AndroidUtilities.getCacheDir(), fileName2 + ".jpg");
boolean result = cacheFile.renameTo(cacheFile2);
FileLoader.getInstance().replaceImageInCache(fileName, fileName2);
ArrayList arr = new ArrayList();
@@ -2211,6 +2361,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
newMsg.media.video.key = decryptedMessage.media.key;
newMsg.media.video.iv = decryptedMessage.media.iv;
newMsg.media.video.path = video.path;
+ newMsg.media.video.mime_type = video.mime_type;
ArrayList arr = new ArrayList();
arr.add(newMsg);
MessagesStorage.getInstance().putMessages(arr, false, true);
@@ -2232,9 +2383,9 @@ public class MessagesController implements NotificationCenter.NotificationCenter
newMsg.media.document.thumb = document.thumb;
newMsg.media.document.dc_id = file.dc_id;
- if (document.path != null && document.path.startsWith(Utilities.getCacheDir().getAbsolutePath())) {
+ if (document.path != null && document.path.startsWith(AndroidUtilities.getCacheDir().getAbsolutePath())) {
File cacheFile = new File(document.path);
- File cacheFile2 = new File(Utilities.getCacheDir(), MessageObject.getAttachFileName(newMsg.media.document));
+ File cacheFile2 = new File(AndroidUtilities.getCacheDir(), MessageObject.getAttachFileName(newMsg.media.document));
cacheFile.renameTo(cacheFile2);
}
@@ -2256,12 +2407,13 @@ public class MessagesController implements NotificationCenter.NotificationCenter
newMsg.media.audio.key = decryptedMessage.media.key;
newMsg.media.audio.iv = decryptedMessage.media.iv;
newMsg.media.audio.path = audio.path;
+ newMsg.media.audio.mime_type = audio.mime_type;
String fileName = audio.dc_id + "_" + audio.id + ".m4a";
String fileName2 = newMsg.media.audio.dc_id + "_" + newMsg.media.audio.id + ".m4a";
if (!fileName.equals(fileName2)) {
- File cacheFile = new File(Utilities.getCacheDir(), fileName);
- File cacheFile2 = new File(Utilities.getCacheDir(), fileName2);
+ File cacheFile = new File(AndroidUtilities.getCacheDir(), fileName);
+ File cacheFile2 = new File(AndroidUtilities.getCacheDir(), fileName2);
cacheFile.renameTo(cacheFile2);
}
@@ -2276,44 +2428,44 @@ public class MessagesController implements NotificationCenter.NotificationCenter
if (req == null || chat.auth_key == null || chat instanceof TLRPC.TL_encryptedChatRequested || chat instanceof TLRPC.TL_encryptedChatWaiting) {
return;
}
- //TLRPC.decryptedMessageLayer messageLayer = new TLRPC.decryptedMessageLayer();
- //messageLayer.layer = 8;
- //messageLayer.message = req;
- SerializedData data = new SerializedData();
- req.serializeToStream(data);
+ int len = req.getObjectSize();
+ ByteBufferDesc toEncrypt = BuffersStorage.getInstance().getFreeBuffer(4 + len);
+ toEncrypt.writeInt32(len);
+ req.serializeToStream(toEncrypt);
- SerializedData toEncrypt = new SerializedData();
- toEncrypt.writeInt32(data.length());
- toEncrypt.writeRaw(data.toByteArray());
-
- byte[] innerData = toEncrypt.toByteArray();
-
- byte[] messageKeyFull = Utilities.computeSHA1(innerData);
+ byte[] messageKeyFull = Utilities.computeSHA1(toEncrypt.buffer);
byte[] messageKey = new byte[16];
System.arraycopy(messageKeyFull, messageKeyFull.length - 16, messageKey, 0, 16);
MessageKeyData keyData = Utilities.generateMessageKeyData(chat.auth_key, messageKey, false);
- SerializedData dataForEncryption = new SerializedData();
- dataForEncryption.writeRaw(innerData);
- byte[] b = new byte[1];
- while (dataForEncryption.length() % 16 != 0) {
+ len = toEncrypt.length();
+ int extraLen = len % 16 != 0 ? 16 - len % 16 : 0;
+ ByteBufferDesc dataForEncryption = BuffersStorage.getInstance().getFreeBuffer(len + extraLen);
+ toEncrypt.position(0);
+ dataForEncryption.writeRaw(toEncrypt);
+ if (extraLen != 0) {
+ byte[] b = new byte[extraLen];
Utilities.random.nextBytes(b);
- dataForEncryption.writeByte(b[0]);
+ dataForEncryption.writeRaw(b);
}
+ BuffersStorage.getInstance().reuseFreeBuffer(toEncrypt);
- byte[] encryptedData = Utilities.aesIgeEncryption(dataForEncryption.toByteArray(), keyData.aesKey, keyData.aesIv, true, false, 0);
+ Utilities.aesIgeEncryption(dataForEncryption.buffer, keyData.aesKey, keyData.aesIv, true, false, 0, dataForEncryption.limit());
- data = new SerializedData();
+ ByteBufferDesc data = BuffersStorage.getInstance().getFreeBuffer(8 + messageKey.length + dataForEncryption.length());
+ dataForEncryption.position(0);
data.writeInt64(chat.key_fingerprint);
data.writeRaw(messageKey);
- data.writeRaw(encryptedData);
+ data.writeRaw(dataForEncryption);
+ BuffersStorage.getInstance().reuseFreeBuffer(dataForEncryption);
+ data.position(0);
- TLObject reqToSend;
+ TLObject reqToSend = null;
if (encryptedFile == null) {
TLRPC.TL_messages_sendEncrypted req2 = new TLRPC.TL_messages_sendEncrypted();
- req2.data = data.toByteArray();
+ req2.data = data;
req2.random_id = req.random_id;
req2.peer = new TLRPC.TL_inputEncryptedChat();
req2.peer.chat_id = chat.id;
@@ -2321,7 +2473,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
reqToSend = req2;
} else {
TLRPC.TL_messages_sendEncryptedFile req2 = new TLRPC.TL_messages_sendEncryptedFile();
- req2.data = data.toByteArray();
+ req2.data = data;
req2.random_id = req.random_id;
req2.peer = new TLRPC.TL_inputEncryptedChat();
req2.peer.chat_id = chat.id;
@@ -2365,7 +2517,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}
}
}
- }, null, true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassCanCompress);
+ });
}
private void performSendMessageRequest(TLObject req, final MessageObject newMsgObj, final String originalPath) {
@@ -2477,7 +2629,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
});
}
}
- }, null, (req instanceof TLRPC.TL_messages_forwardMessages ? null : new RPCRequest.RPCQuickAckDelegate() {
+ }, (req instanceof TLRPC.TL_messages_forwardMessages ? null : new RPCRequest.RPCQuickAckDelegate() {
@Override
public void quickAck() {
final int msg_id = newMsgObj.messageOwner.id;
@@ -2503,7 +2655,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
private void performSendDelayedMessage(final DelayedMessage message) {
if (message.type == 0) {
- String location = Utilities.getCacheDir() + "/" + message.location.volume_id + "_" + message.location.local_id + ".jpg";
+ String location = AndroidUtilities.getCacheDir() + "/" + message.location.volume_id + "_" + message.location.local_id + ".jpg";
putToDelayedMessages(location, message);
if (message.sendRequest != null) {
FileLoader.getInstance().uploadFile(location, false);
@@ -2513,13 +2665,13 @@ public class MessagesController implements NotificationCenter.NotificationCenter
} else if (message.type == 1) {
if (message.sendRequest != null) {
if (message.sendRequest.media.thumb == null) {
- String location = Utilities.getCacheDir() + "/" + message.location.volume_id + "_" + message.location.local_id + ".jpg";
+ String location = AndroidUtilities.getCacheDir() + "/" + message.location.volume_id + "_" + message.location.local_id + ".jpg";
putToDelayedMessages(location, message);
FileLoader.getInstance().uploadFile(location, false);
} else {
String location = message.videoLocation.path;
if (location == null) {
- location = Utilities.getCacheDir() + "/" + message.videoLocation.id + ".mp4";
+ location = AndroidUtilities.getCacheDir() + "/" + message.videoLocation.id + ".mp4";
}
putToDelayedMessages(location, message);
FileLoader.getInstance().uploadFile(location, false);
@@ -2527,14 +2679,14 @@ public class MessagesController implements NotificationCenter.NotificationCenter
} else {
String location = message.videoLocation.path;
if (location == null) {
- location = Utilities.getCacheDir() + "/" + message.videoLocation.id + ".mp4";
+ location = AndroidUtilities.getCacheDir() + "/" + message.videoLocation.id + ".mp4";
}
putToDelayedMessages(location, message);
FileLoader.getInstance().uploadFile(location, true);
}
} else if (message.type == 2) {
if (message.sendRequest != null && message.sendRequest.media.thumb == null && message.location != null) {
- String location = Utilities.getCacheDir() + "/" + message.location.volume_id + "_" + message.location.local_id + ".jpg";
+ String location = AndroidUtilities.getCacheDir() + "/" + message.location.volume_id + "_" + message.location.local_id + ".jpg";
putToDelayedMessages(location, message);
FileLoader.getInstance().uploadFile(location, false);
} else {
@@ -2557,134 +2709,6 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}
}
- public void fileDidFailedUpload(final String location, final boolean enc) {
- if (uploadingAvatar != null && uploadingAvatar.equals(location)) {
- uploadingAvatar = null;
- } else {
- Utilities.RunOnUIThread(new Runnable() {
- @Override
- public void run() {
- ArrayList arr = delayedMessages.get(location);
- if (arr != null) {
- for (int a = 0; a < arr.size(); a++) {
- DelayedMessage obj = arr.get(a);
- if (enc && obj.sendEncryptedRequest != null || !enc && obj.sendRequest != null) {
- obj.obj.messageOwner.send_state = MESSAGE_SEND_STATE_SEND_ERROR;
- sendingMessages.remove(obj.obj.messageOwner.id);
- arr.remove(a);
- a--;
- NotificationCenter.getInstance().postNotificationName(messageSendError, obj.obj.messageOwner.id);
- }
- }
- if (arr.isEmpty()) {
- delayedMessages.remove(location);
- }
- }
- }
- });
- }
- }
-
- public void fileDidUploaded(final String location, final TLRPC.InputFile file, final TLRPC.InputEncryptedFile encryptedFile) {
- if (uploadingAvatar != null && uploadingAvatar.equals(location)) {
- TLRPC.TL_photos_uploadProfilePhoto req = new TLRPC.TL_photos_uploadProfilePhoto();
- req.caption = "";
- req.crop = new TLRPC.TL_inputPhotoCropAuto();
- req.file = file;
- req.geo_point = new TLRPC.TL_inputGeoPointEmpty();
- ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() {
- @Override
- public void run(TLObject response, TLRPC.TL_error error) {
- if (error == null) {
- TLRPC.User user = users.get(UserConfig.getClientUserId());
- if (user == null) {
- user = UserConfig.getCurrentUser();
- users.put(user.id, user);
- } else {
- UserConfig.setCurrentUser(user);
- }
- if (user == null) {
- return;
- }
- TLRPC.TL_photos_photo photo = (TLRPC.TL_photos_photo) response;
- ArrayList sizes = photo.photo.sizes;
- TLRPC.PhotoSize smallSize = PhotoObject.getClosestPhotoSizeWithSize(sizes, 100, 100);
- TLRPC.PhotoSize bigSize = PhotoObject.getClosestPhotoSizeWithSize(sizes, 1000, 1000);
- user.photo = new TLRPC.TL_userProfilePhoto();
- user.photo.photo_id = photo.photo.id;
- if (smallSize != null) {
- user.photo.photo_small = smallSize.location;
- }
- if (bigSize != null) {
- user.photo.photo_big = bigSize.location;
- } else if (smallSize != null) {
- user.photo.photo_small = smallSize.location;
- }
- MessagesStorage.getInstance().clearUserPhotos(user.id);
- ArrayList users = new ArrayList();
- users.add(user);
- MessagesStorage.getInstance().putUsersAndChats(users, null, false, true);
- Utilities.RunOnUIThread(new Runnable() {
- @Override
- public void run() {
- NotificationCenter.getInstance().postNotificationName(updateInterfaces, UPDATE_MASK_AVATAR);
- UserConfig.saveConfig(true);
- }
- });
- }
- }
- }, null, true, RPCRequest.RPCRequestClassGeneric);
- } else {
- Utilities.RunOnUIThread(new Runnable() {
- @Override
- public void run() {
- ArrayList arr = delayedMessages.get(location);
- if (arr != null) {
- for (int a = 0; a < arr.size(); a++) {
- DelayedMessage message = arr.get(a);
- if (file != null && message.sendRequest != null) {
- if (message.type == 0) {
- message.sendRequest.media.file = file;
- performSendMessageRequest(message.sendRequest, message.obj, message.originalPath);
- } else if (message.type == 1) {
- if (message.sendRequest.media.thumb == null) {
- message.sendRequest.media.thumb = file;
- performSendDelayedMessage(message);
- } else {
- message.sendRequest.media.file = file;
- performSendMessageRequest(message.sendRequest, message.obj, message.originalPath);
- }
- } else if (message.type == 2) {
- if (message.sendRequest.media.thumb == null && message.location != null) {
- message.sendRequest.media.thumb = file;
- performSendDelayedMessage(message);
- } else {
- message.sendRequest.media.file = file;
- performSendMessageRequest(message.sendRequest, message.obj, message.originalPath);
- }
- } else if (message.type == 3) {
- message.sendRequest.media.file = file;
- performSendMessageRequest(message.sendRequest, message.obj, message.originalPath);
- }
- arr.remove(a);
- a--;
- } else if (encryptedFile != null && message.sendEncryptedRequest != null) {
- message.sendEncryptedRequest.media.key = encryptedFile.key;
- message.sendEncryptedRequest.media.iv = encryptedFile.iv;
- performSendEncryptedRequest(message.sendEncryptedRequest, message.obj, message.encryptedChat, encryptedFile, message.originalPath);
- arr.remove(a);
- a--;
- }
- }
- if (arr.isEmpty()) {
- delayedMessages.remove(location);
- }
- }
- }
- });
- }
- }
-
public long createChat(String title, ArrayList selectedContacts, final TLRPC.InputFile uploadedAvatar) {
TLRPC.TL_messages_createChat req = new TLRPC.TL_messages_createChat();
req.title = title;
@@ -2756,7 +2780,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}
}
}
- }, null, true, RPCRequest.RPCRequestClassGeneric);
+ });
}
public void addUserToChat(int chat_id, final TLRPC.User user, final TLRPC.ChatParticipants info) {
@@ -2838,7 +2862,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}
}
}
- }, null, true, RPCRequest.RPCRequestClassGeneric);
+ });
}
public void deleteUserFromChat(int chat_id, final TLRPC.User user, final TLRPC.ChatParticipants info) {
@@ -2920,7 +2944,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}
}
}
- }, null, true, RPCRequest.RPCRequestClassGeneric);
+ });
}
public void changeChatTitle(int chat_id, String title) {
@@ -2980,7 +3004,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}
}
}
- }, null, true, RPCRequest.RPCRequestClassGeneric);
+ });
}
public void changeChatAvatar(int chat_id, TLRPC.InputFile uploadedAvatar) {
@@ -3046,7 +3070,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}
}
}
- }, null, true, RPCRequest.RPCRequestClassGeneric);
+ });
}
public void unregistedPush() {
@@ -3059,7 +3083,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
public void run(TLObject response, TLRPC.TL_error error) {
}
- }, null, true, RPCRequest.RPCRequestClassGeneric);
+ });
}
}
@@ -3070,7 +3094,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
public void run(TLObject response, TLRPC.TL_error error) {
ConnectionsManager.getInstance().cleanUp();
}
- }, null, true, RPCRequest.RPCRequestClassGeneric);
+ });
}
public void registerForPush(final String regid) {
@@ -3136,7 +3160,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}
});
}
- }, null, true, RPCRequest.RPCRequestClassGeneric);
+ });
}
}
@@ -3163,7 +3187,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}
}
}
- }, null, true, RPCRequest.RPCRequestClassGeneric);
+ });
}
private int getUpdateSeq(TLRPC.Updates updates) {
@@ -3221,7 +3245,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
FileLog.e("tmessages", "UPDATES QUEUE PROCEED - OK");
updatesStartWaitTime = 0;
if (getDifference) {
- final int stateCopy = ConnectionsManager.getInstance().connectionState;
+ final int stateCopy = ConnectionsManager.getInstance().getConnectionState();
Utilities.RunOnUIThread(new Runnable() {
@Override
public void run() {
@@ -3231,7 +3255,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}
} else {
if (getDifference) {
- final int stateCopy = ConnectionsManager.getInstance().connectionState;
+ final int stateCopy = ConnectionsManager.getInstance().getConnectionState();
Utilities.RunOnUIThread(new Runnable() {
@Override
public void run() {
@@ -3263,9 +3287,9 @@ public class MessagesController implements NotificationCenter.NotificationCenter
req.date = MessagesStorage.lastDateValue;
req.qts = MessagesStorage.lastQtsValue;
FileLog.e("tmessages", "start getDifference with date = " + MessagesStorage.lastDateValue + " pts = " + MessagesStorage.lastPtsValue + " seq = " + MessagesStorage.lastSeqValue);
- if (ConnectionsManager.getInstance().connectionState == 0) {
- ConnectionsManager.getInstance().connectionState = 3;
- final int stateCopy = ConnectionsManager.getInstance().connectionState;
+ if (ConnectionsManager.getInstance().getConnectionState() == 0) {
+ ConnectionsManager.getInstance().setConnectionState(3);
+ final int stateCopy = ConnectionsManager.getInstance().getConnectionState();
Utilities.RunOnUIThread(new Runnable() {
@Override
public void run() {
@@ -3315,9 +3339,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}
if (currentPushMessage != null && readMessages.contains(currentPushMessage.messageOwner.id)) {
- NotificationManager mNotificationManager = (NotificationManager) ApplicationLoader.applicationContext.getSystemService(Context.NOTIFICATION_SERVICE);
- mNotificationManager.cancel(1);
- currentPushMessage = null;
+ dismissNotification();
}
}
});
@@ -3375,7 +3397,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}
if (!(res instanceof TLRPC.TL_updates_differenceSlice)) {
- if ((dialog_id != openned_dialog_id || ConnectionsManager.lastPauseTime != 0) && !obj.isOut() && obj.messageOwner.unread && (lastMessage == null || lastMessage.messageOwner.date < obj.messageOwner.date)) {
+ if ((dialog_id != openned_dialog_id || ConnectionsManager.getInstance().getPauseTime() != 0) && !obj.isOut() && obj.messageOwner.unread && (lastMessage == null || lastMessage.messageOwner.date < obj.messageOwner.date)) {
if (!readMessages.contains(obj.messageOwner.id)) {
lastMessage = obj;
}
@@ -3440,7 +3462,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
MessagesStorage.lastDateValue = res.state.date;
MessagesStorage.lastPtsValue = res.state.pts;
MessagesStorage.lastQtsValue = res.state.qts;
- ConnectionsManager.getInstance().connectionState = 0;
+ ConnectionsManager.getInstance().setConnectionState(0);
processUpdatesQueue(true);
} else if (res instanceof TLRPC.TL_updates_differenceSlice) {
MessagesStorage.lastDateValue = res.intermediate_state.date;
@@ -3451,7 +3473,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
} else if (res instanceof TLRPC.TL_updates_differenceEmpty) {
MessagesStorage.lastSeqValue = res.seq;
MessagesStorage.lastDateValue = res.date;
- ConnectionsManager.getInstance().connectionState = 0;
+ ConnectionsManager.getInstance().setConnectionState(0);
processUpdatesQueue(true);
}
MessagesStorage.getInstance().saveDiffParams(MessagesStorage.lastSeqValue, MessagesStorage.lastPtsValue, MessagesStorage.lastDateValue, MessagesStorage.lastQtsValue);
@@ -3463,8 +3485,8 @@ public class MessagesController implements NotificationCenter.NotificationCenter
});
} else {
gettingDifference = false;
- ConnectionsManager.getInstance().connectionState = 0;
- final int stateCopy = ConnectionsManager.getInstance().connectionState;
+ ConnectionsManager.getInstance().setConnectionState(0);
+ final int stateCopy = ConnectionsManager.getInstance().getConnectionState();
Utilities.RunOnUIThread(new Runnable() {
@Override
public void run() {
@@ -3473,7 +3495,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
});
}
}
- }, null, true, RPCRequest.RPCRequestClassGeneric);
+ });
}
public void processUpdates(final TLRPC.Updates updates, boolean fromQueue) {
@@ -3523,7 +3545,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
} else {
dialog_id = obj.messageOwner.to_id.user_id;
}
- if (dialog_id != openned_dialog_id || ConnectionsManager.lastPauseTime != 0 || !ApplicationLoader.isScreenOn) {
+ if (dialog_id != openned_dialog_id || ConnectionsManager.getInstance().getPauseTime() != 0 || !ApplicationLoader.isScreenOn) {
showInAppNotification(obj);
}
}
@@ -3586,7 +3608,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
} else {
dialog_id = obj.messageOwner.to_id.user_id;
}
- if (dialog_id != openned_dialog_id || ConnectionsManager.lastPauseTime != 0 || !ApplicationLoader.isScreenOn) {
+ if (dialog_id != openned_dialog_id || ConnectionsManager.getInstance().getPauseTime() != 0 || !ApplicationLoader.isScreenOn) {
showInAppNotification(obj);
}
}
@@ -3690,7 +3712,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
public void run(TLObject response, TLRPC.TL_error error) {
}
- }, null, true, RPCRequest.RPCRequestClassGeneric);
+ });
}
MessagesStorage.getInstance().saveDiffParams(MessagesStorage.lastSeqValue, MessagesStorage.lastPtsValue, MessagesStorage.lastDateValue, MessagesStorage.lastQtsValue);
}
@@ -3790,12 +3812,10 @@ public class MessagesController implements NotificationCenter.NotificationCenter
arr.add(obj);
MessagesStorage.lastPtsValue = update.pts;
if (upd.message.from_id != UserConfig.getClientUserId() && upd.message.to_id != null) {
- if (uid != openned_dialog_id || ConnectionsManager.lastPauseTime != 0) {
+ if (uid != openned_dialog_id || ConnectionsManager.getInstance().getPauseTime() != 0) {
lastMessage = obj;
}
}
- } else if (update instanceof TLRPC.TL_updateMessageID) {
- //can't be here
} else if (update instanceof TLRPC.TL_updateReadMessages) {
markAsReadMessages.addAll(update.messages);
MessagesStorage.lastPtsValue = update.pts;
@@ -3843,37 +3863,6 @@ public class MessagesController implements NotificationCenter.NotificationCenter
} else if (update instanceof TLRPC.TL_updateUserPhoto) {
interfaceUpdateMask |= UPDATE_MASK_AVATAR;
MessagesStorage.getInstance().clearUserPhotos(update.user_id);
- /*if (!(update.photo instanceof TLRPC.TL_userProfilePhotoEmpty)) { DEPRECATED
- if (usersDict.containsKey(update.user_id)) {
- TLRPC.TL_messageService newMessage = new TLRPC.TL_messageService();
- newMessage.action = new TLRPC.TL_messageActionUserUpdatedPhoto();
- newMessage.action.newUserPhoto = update.photo;
- newMessage.local_id = newMessage.id = UserConfig.getNewMessageId();
- UserConfig.saveConfig(false);
- newMessage.unread = true;
- newMessage.date = update.date;
- newMessage.from_id = update.user_id;
- newMessage.to_id = new TLRPC.TL_peerUser();
- newMessage.to_id.user_id = UserConfig.clientUserId;
- newMessage.out = false;
- newMessage.dialog_id = update.user_id;
-
- messagesArr.add(newMessage);
- MessageObject obj = new MessageObject(newMessage, usersDict);
- ArrayList arr = messages.get(newMessage.dialog_id);
- if (arr == null) {
- arr = new ArrayList();
- messages.put(newMessage.dialog_id, arr);
- }
- arr.add(obj);
- if (newMessage.from_id != UserConfig.clientUserId && newMessage.to_id != null) {
- if (newMessage.dialog_id != openned_dialog_id || ApplicationLoader.lastPauseTime != 0) {
- lastMessage = obj;
- }
- }
- }
- }*/
-
updatesOnMainThread.add(update);
} else if (update instanceof TLRPC.TL_updateContactRegistered) {
if (enableJoined && usersDict.containsKey(update.user_id)) {
@@ -3898,7 +3887,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}
arr.add(obj);
if (newMessage.from_id != UserConfig.getClientUserId() && newMessage.to_id != null) {
- if (newMessage.dialog_id != openned_dialog_id || ConnectionsManager.lastPauseTime != 0) {
+ if (newMessage.dialog_id != openned_dialog_id || ConnectionsManager.getInstance().getPauseTime() != 0) {
lastMessage = obj;
}
}
@@ -3947,7 +3936,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}
arr.add(obj);
if (newMessage.from_id != UserConfig.getClientUserId() && newMessage.to_id != null) {
- if (newMessage.dialog_id != openned_dialog_id || ConnectionsManager.lastPauseTime != 0) {
+ if (newMessage.dialog_id != openned_dialog_id || ConnectionsManager.getInstance().getPauseTime() != 0) {
lastMessage = obj;
}
}
@@ -3968,7 +3957,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}
arr.add(obj);
if (message.from_id != UserConfig.getClientUserId() && message.to_id != null) {
- if (uid != openned_dialog_id || ConnectionsManager.lastPauseTime != 0) {
+ if (uid != openned_dialog_id || ConnectionsManager.getInstance().getPauseTime() != 0) {
lastMessage = obj;
}
}
@@ -4082,6 +4071,10 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}
});
}
+ } else if (update instanceof TLRPC.TL_updateUserBlocked) {
+ //TODO
+ } else if (update instanceof TLRPC.TL_updateNotifySettings) {
+ updatesOnMainThread.add(update);
}
}
if (!messages.isEmpty()) {
@@ -4122,6 +4115,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
if (!updatesOnMainThread.isEmpty()) {
ArrayList dbUsers = new ArrayList();
ArrayList dbUsersStatus = new ArrayList();
+ SharedPreferences.Editor editor = null;
for (TLRPC.Update update : updatesOnMainThread) {
TLRPC.User toDbUser = new TLRPC.User();
toDbUser.id = update.user_id;
@@ -4148,8 +4142,42 @@ public class MessagesController implements NotificationCenter.NotificationCenter
avatarsUpdate = true;
toDbUser.photo = update.photo;
dbUsers.add(toDbUser);
+ } else if (update instanceof TLRPC.TL_updateNotifySettings) {
+ if (update.notify_settings instanceof TLRPC.TL_peerNotifySettings && update.peer instanceof TLRPC.TL_notifyPeer) {
+ if (editor == null) {
+ SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
+ editor = preferences.edit();
+ }
+ int dialog_id = update.peer.peer.user_id;
+ if (dialog_id == 0) {
+ dialog_id = -update.peer.peer.chat_id;
+ }
+ if (update.notify_settings.mute_until != 0) {
+ editor.putInt("notify2_" + dialog_id, 2);
+ } else {
+ editor.remove("notify2_" + dialog_id);
+ }
+ } else if (update.peer instanceof TLRPC.TL_notifyChats) {
+ if (editor == null) {
+ SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
+ editor = preferences.edit();
+ }
+ editor.putBoolean("EnableGroup", update.notify_settings.mute_until == 0);
+ editor.putBoolean("EnablePreviewGroup", update.notify_settings.show_previews);
+ } else if (update.peer instanceof TLRPC.TL_notifyUsers) {
+ if (editor == null) {
+ SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
+ editor = preferences.edit();
+ }
+ editor.putBoolean("EnableAll", update.notify_settings.mute_until == 0);
+ editor.putBoolean("EnablePreviewAll", update.notify_settings.show_previews);
+ }
}
}
+ if (editor != null) {
+ editor.commit();
+ NotificationCenter.getInstance().postNotificationName(notificationsSettingsUpdated);
+ }
MessagesStorage.getInstance().updateUsers(dbUsersStatus, true, true, true);
MessagesStorage.getInstance().updateUsers(dbUsers, false, true, true);
}
@@ -4172,9 +4200,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}
if (currentPushMessage != null && markAsReadMessages.contains(currentPushMessage.messageOwner.id)) {
- NotificationManager mNotificationManager = (NotificationManager)ApplicationLoader.applicationContext.getSystemService(Context.NOTIFICATION_SERVICE);
- mNotificationManager.cancel(1);
- currentPushMessage = null;
+ dismissNotification();
}
}
if (!markAsReadEncrypted.isEmpty()) {
@@ -4297,324 +4323,6 @@ public class MessagesController implements NotificationCenter.NotificationCenter
return false;
}
- private void playNotificationSound() {
- if (lastSoundPlay > System.currentTimeMillis() - 1800) {
- return;
- }
- try {
- lastSoundPlay = System.currentTimeMillis();
- soundPool.play(sound, 1, 1, 1, 0, 1);
- } catch (Exception e) {
- FileLog.e("tmessages", e);
- }
- }
-
- private void showInAppNotification(MessageObject messageObject) {
- if (!UserConfig.isClientActivated()) {
- return;
- }
- if (ConnectionsManager.lastPauseTime != 0) {
- ConnectionsManager.lastPauseTime = System.currentTimeMillis();
- FileLog.e("tmessages", "reset sleep timeout by received message");
- }
- if (messageObject == null) {
- return;
- }
- SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Context.MODE_PRIVATE);
- boolean globalEnabled = preferences.getBoolean("EnableAll", true);
- boolean groupEnabled = preferences.getBoolean("EnableGroup", true);
-
- long dialog_id = messageObject.messageOwner.dialog_id;
- int chat_id = messageObject.messageOwner.to_id.chat_id;
- int user_id = messageObject.messageOwner.to_id.user_id;
- if (user_id == 0) {
- user_id = messageObject.messageOwner.from_id;
- } else if (user_id == UserConfig.getClientUserId()) {
- user_id = messageObject.messageOwner.from_id;
- }
-
- if (dialog_id == 0) {
- if (chat_id != 0) {
- dialog_id = -chat_id;
- } else if (user_id != 0) {
- dialog_id = user_id;
- }
- }
-
- int notify_override = preferences.getInt("notify2_" + dialog_id, 0);
- if (notify_override == 2 || (!globalEnabled || chat_id != 0 && !groupEnabled) && notify_override == 0) {
- return;
- }
-
- TLRPC.User user = users.get(user_id);
- if (user == null) {
- return;
- }
- TLRPC.Chat chat = null;
- if (chat_id != 0) {
- chat = chats.get(chat_id);
- if (chat == null) {
- return;
- }
- }
-
- int vibrate_override = preferences.getInt("vibrate_" + dialog_id, 0);
-
- if (ConnectionsManager.lastPauseTime == 0 && ApplicationLoader.isScreenOn) {
- boolean inAppSounds = preferences.getBoolean("EnableInAppSounds", true);
- boolean inAppVibrate = preferences.getBoolean("EnableInAppVibrate", true);
- boolean inAppPreview = preferences.getBoolean("EnableInAppPreview", true);
-
- if (inAppSounds || inAppVibrate || inAppPreview) {
- if ((int)dialog_id == 0) {
- TLRPC.EncryptedChat encChat = encryptedChats.get((int)(dialog_id >> 32));
- if (encChat == null) {
- return;
- }
- }
-
- if (inAppPreview) {
- NotificationCenter.getInstance().postNotificationName(701, messageObject);
- }
- if (inAppVibrate && vibrate_override == 0 || vibrate_override == 1) {
- Vibrator v = (Vibrator)ApplicationLoader.applicationContext.getSystemService(Context.VIBRATOR_SERVICE);
- v.vibrate(100);
- }
- if (inAppSounds) {
- playNotificationSound();
- }
- }
- } else {
- TLRPC.FileLocation photoPath = null;
- String defaultPath = Settings.System.DEFAULT_NOTIFICATION_URI.getPath();
-
- NotificationManager mNotificationManager = (NotificationManager)ApplicationLoader.applicationContext.getSystemService(Context.NOTIFICATION_SERVICE);
- Intent intent = new Intent(ApplicationLoader.applicationContext, LaunchActivity.class);
- String msg = null;
-
- if ((int)dialog_id != 0) {
- if (chat_id != 0) {
- intent.putExtra("chatId", chat_id);
- } else if (user_id != 0) {
- intent.putExtra("userId", user_id);
- }
-
- if (user.photo != null && user.photo.photo_small != null && user.photo.photo_small.volume_id != 0 && user.photo.photo_small.local_id != 0) {
- photoPath = user.photo.photo_small;
- }
-
- if (chat_id == 0 && user_id != 0) {
- if (preferences.getBoolean("EnablePreviewAll", true)) {
- if (messageObject.messageOwner instanceof TLRPC.TL_messageService) {
- if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionUserJoined) {
- msg = LocaleController.formatString("NotificationContactJoined", R.string.NotificationContactJoined, Utilities.formatName(user.first_name, user.last_name));
- } else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionUserUpdatedPhoto) {
- msg = LocaleController.formatString("NotificationContactNewPhoto", R.string.NotificationContactNewPhoto, Utilities.formatName(user.first_name, user.last_name));
- } else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionLoginUnknownLocation) {
- String date = String.format("%s %s %s", LocaleController.formatterYear.format(((long)messageObject.messageOwner.date) * 1000), LocaleController.getString("OtherAt", R.string.OtherAt), LocaleController.formatterDay.format(((long)messageObject.messageOwner.date) * 1000));
- msg = LocaleController.formatString("NotificationUnrecognizedDevice", R.string.NotificationUnrecognizedDevice, UserConfig.getCurrentUser().first_name, date, messageObject.messageOwner.action.title, messageObject.messageOwner.action.address);
- }
- } else {
- if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaEmpty) {
- if (messageObject.messageOwner.message != null && messageObject.messageOwner.message.length() != 0) {
- msg = LocaleController.formatString("NotificationMessageText", R.string.NotificationMessageText, Utilities.formatName(user.first_name, user.last_name), messageObject.messageOwner.message);
- } else {
- msg = LocaleController.formatString("NotificationMessageNoText", R.string.NotificationMessageNoText, Utilities.formatName(user.first_name, user.last_name));
- }
- } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) {
- msg = LocaleController.formatString("NotificationMessagePhoto", R.string.NotificationMessagePhoto, Utilities.formatName(user.first_name, user.last_name));
- } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaVideo) {
- msg = LocaleController.formatString("NotificationMessageVideo", R.string.NotificationMessageVideo, Utilities.formatName(user.first_name, user.last_name));
- } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaContact) {
- msg = LocaleController.formatString("NotificationMessageContact", R.string.NotificationMessageContact, Utilities.formatName(user.first_name, user.last_name));
- } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaGeo) {
- msg = LocaleController.formatString("NotificationMessageMap", R.string.NotificationMessageMap, Utilities.formatName(user.first_name, user.last_name));
- } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
- msg = LocaleController.formatString("NotificationMessageDocument", R.string.NotificationMessageDocument, Utilities.formatName(user.first_name, user.last_name));
- } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaAudio) {
- msg = LocaleController.formatString("NotificationMessageAudio", R.string.NotificationMessageAudio, Utilities.formatName(user.first_name, user.last_name));
- }
- }
- } else {
- msg = LocaleController.formatString("NotificationMessageNoText", R.string.NotificationMessageNoText, Utilities.formatName(user.first_name, user.last_name));
- }
- } else if (chat_id != 0) {
- if (preferences.getBoolean("EnablePreviewGroup", true)) {
- if (messageObject.messageOwner instanceof TLRPC.TL_messageService) {
- if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChatAddUser) {
- if (messageObject.messageOwner.action.user_id == UserConfig.getClientUserId()) {
- msg = LocaleController.formatString("NotificationInvitedToGroup", R.string.NotificationInvitedToGroup, Utilities.formatName(user.first_name, user.last_name), chat.title);
- } else {
- TLRPC.User u2 = users.get(messageObject.messageOwner.action.user_id);
- if (u2 == null) {
- return;
- }
- msg = LocaleController.formatString("NotificationGroupAddMember", R.string.NotificationGroupAddMember, Utilities.formatName(user.first_name, user.last_name), chat.title, Utilities.formatName(u2.first_name, u2.last_name));
- }
- } else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChatEditTitle) {
- msg = LocaleController.formatString("NotificationEditedGroupName", R.string.NotificationEditedGroupName, Utilities.formatName(user.first_name, user.last_name), messageObject.messageOwner.action.title);
- } else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChatEditPhoto || messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChatDeletePhoto) {
- msg = LocaleController.formatString("NotificationEditedGroupPhoto", R.string.NotificationEditedGroupPhoto, Utilities.formatName(user.first_name, user.last_name), chat.title);
- } else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChatDeleteUser) {
- if (messageObject.messageOwner.action.user_id == UserConfig.getClientUserId()) {
- msg = LocaleController.formatString("NotificationGroupKickYou", R.string.NotificationGroupKickYou, Utilities.formatName(user.first_name, user.last_name), chat.title);
- } else if (messageObject.messageOwner.action.user_id == user.id) {
- msg = LocaleController.formatString("NotificationGroupLeftMember", R.string.NotificationGroupLeftMember, Utilities.formatName(user.first_name, user.last_name), chat.title);
- } else {
- TLRPC.User u2 = users.get(messageObject.messageOwner.action.user_id);
- if (u2 == null) {
- return;
- }
- msg = LocaleController.formatString("NotificationGroupKickMember", R.string.NotificationGroupKickMember, Utilities.formatName(user.first_name, user.last_name), chat.title, Utilities.formatName(u2.first_name, u2.last_name));
- }
- }
- } else {
- if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaEmpty) {
- if (messageObject.messageOwner.message != null && messageObject.messageOwner.message.length() != 0) {
- msg = LocaleController.formatString("NotificationMessageGroupText", R.string.NotificationMessageGroupText, Utilities.formatName(user.first_name, user.last_name), chat.title, messageObject.messageOwner.message);
- } else {
- msg = LocaleController.formatString("NotificationMessageGroupNoText", R.string.NotificationMessageGroupNoText, Utilities.formatName(user.first_name, user.last_name), chat.title);
- }
- } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) {
- msg = LocaleController.formatString("NotificationMessageGroupPhoto", R.string.NotificationMessageGroupPhoto, Utilities.formatName(user.first_name, user.last_name), chat.title);
- } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaVideo) {
- msg = LocaleController.formatString("NotificationMessageGroupVideo", R.string.NotificationMessageGroupVideo, Utilities.formatName(user.first_name, user.last_name), chat.title);
- } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaContact) {
- msg = LocaleController.formatString("NotificationMessageGroupContact", R.string.NotificationMessageGroupContact, Utilities.formatName(user.first_name, user.last_name), chat.title);
- } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaGeo) {
- msg = LocaleController.formatString("NotificationMessageGroupMap", R.string.NotificationMessageGroupMap, Utilities.formatName(user.first_name, user.last_name), chat.title);
- } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
- msg = LocaleController.formatString("NotificationMessageGroupDocument", R.string.NotificationMessageGroupDocument, Utilities.formatName(user.first_name, user.last_name), chat.title);
- } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaAudio) {
- msg = LocaleController.formatString("NotificationMessageGroupAudio", R.string.NotificationMessageGroupAudio, Utilities.formatName(user.first_name, user.last_name), chat.title);
- }
- }
- } else {
- msg = LocaleController.formatString("NotificationMessageGroupNoText", R.string.NotificationMessageGroupNoText, Utilities.formatName(user.first_name, user.last_name), chat.title);
- }
- }
- } else {
- msg = LocaleController.getString("YouHaveNewMessage", R.string.YouHaveNewMessage);
- int enc_id = (int)(dialog_id >> 32);
- intent.putExtra("encId", enc_id);
- }
- if (msg == null) {
- return;
- }
-
- boolean needVibrate = false;
- String choosenSoundPath = null;
- int ledColor = 0xff00ff00;
-
- choosenSoundPath = preferences.getString("sound_path_" + dialog_id, null);
-
- if (chat_id != 0) {
- if (choosenSoundPath != null && choosenSoundPath.equals(defaultPath)) {
- choosenSoundPath = null;
- } else if (choosenSoundPath == null) {
- choosenSoundPath = preferences.getString("GroupSoundPath", defaultPath);
- }
- needVibrate = preferences.getBoolean("EnableVibrateGroup", true);
- ledColor = preferences.getInt("GroupLed", 0xff00ff00);
- } else if (user_id != 0) {
- if (choosenSoundPath != null && choosenSoundPath.equals(defaultPath)) {
- choosenSoundPath = null;
- } else if (choosenSoundPath == null) {
- choosenSoundPath = preferences.getString("GlobalSoundPath", defaultPath);
- }
- needVibrate = preferences.getBoolean("EnableVibrateAll", true);
- ledColor = preferences.getInt("MessagesLed", 0xff00ff00);
- }
- if (preferences.contains("color_" + dialog_id)) {
- ledColor = preferences.getInt("color_" + dialog_id, 0);
- }
-
- if (!needVibrate && vibrate_override == 1) {
- needVibrate = true;
- } else if (needVibrate && vibrate_override == 2) {
- needVibrate = false;
- }
-
- String name = Utilities.formatName(user.first_name, user.last_name);
- if ((int)dialog_id == 0) {
- name = LocaleController.getString("AppName", R.string.AppName);
- }
- String msgShort = msg.replace(name + ": ", "").replace(name + " ", "");
-
- intent.setAction("com.tmessages.openchat" + Math.random() + Integer.MAX_VALUE);
- intent.setFlags(32768);
- PendingIntent contentIntent = PendingIntent.getActivity(ApplicationLoader.applicationContext, 0, intent, PendingIntent.FLAG_ONE_SHOT);
-
- NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(ApplicationLoader.applicationContext)
- .setContentTitle(name)
- .setSmallIcon(R.drawable.notification)
- .setStyle(new NotificationCompat.BigTextStyle().bigText(msgShort))
- .setContentText(msgShort)
- .setAutoCancel(true)
- .setTicker(msg);
-
- if (photoPath != null) {
- Bitmap img = FileLoader.getInstance().getImageFromMemory(photoPath, null, null, "50_50", false);
- if (img != null) {
- mBuilder.setLargeIcon(img);
- }
- }
-
- if (choosenSoundPath != null && !choosenSoundPath.equals("NoSound")) {
- if (choosenSoundPath.equals(defaultPath)) {
- mBuilder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI, AudioManager.STREAM_NOTIFICATION);
- } else {
- mBuilder.setSound(Uri.parse(choosenSoundPath), AudioManager.STREAM_NOTIFICATION);
- }
- }
-
- currentPushMessage = null;
- mBuilder.setContentIntent(contentIntent);
- mNotificationManager.cancel(1);
- Notification notification = mBuilder.build();
- if (ledColor != 0) {
- notification.ledARGB = ledColor;
- }
- notification.ledOnMS = 1000;
- notification.ledOffMS = 1000;
- if (needVibrate) {
- notification.vibrate = new long[]{0, 100, 0, 100};
- } else {
- notification.vibrate = new long[]{0, 0};
- }
- notification.flags |= Notification.FLAG_SHOW_LIGHTS;
- try {
- mNotificationManager.notify(1, notification);
- if (preferences.getBoolean("EnablePebbleNotifications", false)) {
- sendAlertToPebble(msg);
- }
- currentPushMessage = messageObject;
- } catch (Exception e) {
- FileLog.e("tmessages", e);
- }
- }
- }
-
- public void sendAlertToPebble(String message) {
- try {
- final Intent i = new Intent("com.getpebble.action.SEND_NOTIFICATION");
-
- final HashMap data = new HashMap();
- data.put("title", LocaleController.getString("AppName", R.string.AppName));
- data.put("body", message);
- final JSONObject jsonData = new JSONObject(data);
- final String notificationData = new JSONArray().put(jsonData).toString();
-
- i.putExtra("messageType", "PEBBLE_ALERT");
- i.putExtra("sender", LocaleController.formatString("AppName", R.string.AppName));
- i.putExtra("notificationData", notificationData);
-
- ApplicationLoader.applicationContext.sendBroadcast(i);
- } catch (Exception e) {
- FileLog.e("tmessages", e);
- }
- }
-
public void dialogsUnreadCountIncr(final HashMap values) {
Utilities.RunOnUIThread(new Runnable() {
@Override
@@ -4716,18 +4424,19 @@ public class MessagesController implements NotificationCenter.NotificationCenter
if (chat == null) {
return null;
}
- SerializedData is = new SerializedData(message.bytes);
+ ByteBufferDesc is = BuffersStorage.getInstance().getFreeBuffer(message.bytes.length);
+ is.writeRaw(message.bytes);
+ is.position(0);
long fingerprint = is.readInt64();
if (chat.key_fingerprint == fingerprint) {
byte[] messageKey = is.readData(16);
MessageKeyData keyData = Utilities.generateMessageKeyData(chat.auth_key, messageKey, false);
- byte[] messageData = is.readData(message.bytes.length - 24);
- messageData = Utilities.aesIgeEncryption(messageData, keyData.aesKey, keyData.aesIv, false, false, 0);
+ Utilities.aesIgeEncryption(is.buffer, keyData.aesKey, keyData.aesIv, false, false, 24, is.limit() - 24);
- is = new SerializedData(messageData);
int len = is.readInt32();
TLObject object = TLClassStore.Instance().TLdeserialize(is, is.readInt32());
+ BuffersStorage.getInstance().reuseFreeBuffer(is);
if (object != null) {
int from_id = chat.admin_id;
@@ -4825,6 +4534,10 @@ public class MessagesController implements NotificationCenter.NotificationCenter
newMessage.media.video.access_hash = message.file.access_hash;
newMessage.media.video.key = decryptedMessage.media.key;
newMessage.media.video.iv = decryptedMessage.media.iv;
+ newMessage.media.video.mime_type = decryptedMessage.media.mime_type;
+ if (newMessage.media.video.mime_type == null) {
+ newMessage.media.video.mime_type = "video/mp4";
+ }
} else if (decryptedMessage.media instanceof TLRPC.TL_decryptedMessageMediaDocument) {
if (decryptedMessage.media.key == null || decryptedMessage.media.key.length != 32 || decryptedMessage.media.iv == null || decryptedMessage.media.iv.length != 32) {
return null;
@@ -4867,6 +4580,10 @@ public class MessagesController implements NotificationCenter.NotificationCenter
newMessage.media.audio.iv = decryptedMessage.media.iv;
newMessage.media.audio.dc_id = message.file.dc_id;
newMessage.media.audio.duration = decryptedMessage.media.duration;
+ newMessage.media.audio.mime_type = decryptedMessage.media.mime_type;
+ if (newMessage.media.audio.mime_type == null) {
+ newMessage.media.audio.mime_type = "audio/ogg";
+ }
} else {
return null;
}
@@ -4925,6 +4642,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
} else {
FileLog.e("tmessages", "fingerprint mismatch");
}
+ BuffersStorage.getInstance().reuseFreeBuffer(is);
return null;
}
@@ -4991,7 +4709,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
public void run(TLObject response, TLRPC.TL_error error) {
}
- }, null, true, RPCRequest.RPCRequestClassGeneric);
+ });
}
public void acceptSecretChat(final TLRPC.EncryptedChat encryptedChat) {
@@ -5086,12 +4804,12 @@ public class MessagesController implements NotificationCenter.NotificationCenter
});
}
}
- }, null, true, RPCRequest.RPCRequestClassGeneric);
+ });
} else {
acceptingChats.remove(encryptedChat.id);
}
}
- }, null, true, RPCRequest.RPCRequestClassGeneric);
+ });
}
public void startSecretChat(final Context context, final TLRPC.User user) {
@@ -5230,7 +4948,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
});
}
}
- }, null, true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassFailOnServerErrors);
+ }, true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassFailOnServerErrors);
} else {
delayedEncryptedChatUpdates.clear();
Utilities.RunOnUIThread(new Runnable() {
@@ -5248,7 +4966,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
});
}
}
- }, null, true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassFailOnServerErrors);
+ }, true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassFailOnServerErrors);
progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, LocaleController.getString("Cancel", R.string.Cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
@@ -5262,4 +4980,323 @@ public class MessagesController implements NotificationCenter.NotificationCenter
});
progressDialog.show();
}
+
+ private void showInAppNotification(MessageObject messageObject) {
+ if (!UserConfig.isClientActivated()) {
+ return;
+ }
+ ConnectionsManager.getInstance().resumeNetworkMaybe();
+ if (messageObject == null) {
+ return;
+ }
+ SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Context.MODE_PRIVATE);
+ boolean globalEnabled = preferences.getBoolean("EnableAll", true);
+ boolean groupEnabled = preferences.getBoolean("EnableGroup", true);
+
+ long dialog_id = messageObject.messageOwner.dialog_id;
+ int chat_id = messageObject.messageOwner.to_id.chat_id;
+ int user_id = messageObject.messageOwner.to_id.user_id;
+ if (user_id == 0) {
+ user_id = messageObject.messageOwner.from_id;
+ } else if (user_id == UserConfig.getClientUserId()) {
+ user_id = messageObject.messageOwner.from_id;
+ }
+
+ if (dialog_id == 0) {
+ if (chat_id != 0) {
+ dialog_id = -chat_id;
+ } else if (user_id != 0) {
+ dialog_id = user_id;
+ }
+ }
+
+ int notify_override = preferences.getInt("notify2_" + dialog_id, 0);
+ if (notify_override == 2 || (!globalEnabled || chat_id != 0 && !groupEnabled) && notify_override == 0) {
+ return;
+ }
+
+ TLRPC.User user = MessagesController.getInstance().users.get(user_id);
+ if (user == null) {
+ return;
+ }
+ TLRPC.Chat chat = null;
+ if (chat_id != 0) {
+ chat = MessagesController.getInstance().chats.get(chat_id);
+ if (chat == null) {
+ return;
+ }
+ }
+
+ int vibrate_override = preferences.getInt("vibrate_" + dialog_id, 0);
+ boolean inAppSounds = preferences.getBoolean("EnableInAppSounds", true);
+ boolean inAppVibrate = preferences.getBoolean("EnableInAppVibrate", true);
+ boolean inAppPreview = preferences.getBoolean("EnableInAppPreview", true);
+
+ TLRPC.FileLocation photoPath = null;
+ String defaultPath = Settings.System.DEFAULT_NOTIFICATION_URI.getPath();
+
+ NotificationManager mNotificationManager = (NotificationManager)ApplicationLoader.applicationContext.getSystemService(Context.NOTIFICATION_SERVICE);
+ Intent intent = new Intent(ApplicationLoader.applicationContext, LaunchActivity.class);
+ String msg = null;
+
+ if ((int)dialog_id != 0) {
+ if (chat_id != 0) {
+ intent.putExtra("chatId", chat_id);
+ } else if (user_id != 0) {
+ intent.putExtra("userId", user_id);
+ }
+
+ if (user.photo != null && user.photo.photo_small != null && user.photo.photo_small.volume_id != 0 && user.photo.photo_small.local_id != 0) {
+ photoPath = user.photo.photo_small;
+ }
+
+ if (chat_id == 0 && user_id != 0) {
+ if (preferences.getBoolean("EnablePreviewAll", true)) {
+ if (messageObject.messageOwner instanceof TLRPC.TL_messageService) {
+ if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionUserJoined) {
+ msg = LocaleController.formatString("NotificationContactJoined", R.string.NotificationContactJoined, Utilities.formatName(user.first_name, user.last_name));
+ } else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionUserUpdatedPhoto) {
+ msg = LocaleController.formatString("NotificationContactNewPhoto", R.string.NotificationContactNewPhoto, Utilities.formatName(user.first_name, user.last_name));
+ } else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionLoginUnknownLocation) {
+ String date = String.format("%s %s %s", LocaleController.formatterYear.format(((long)messageObject.messageOwner.date) * 1000), LocaleController.getString("OtherAt", R.string.OtherAt), LocaleController.formatterDay.format(((long)messageObject.messageOwner.date) * 1000));
+ msg = LocaleController.formatString("NotificationUnrecognizedDevice", R.string.NotificationUnrecognizedDevice, UserConfig.getCurrentUser().first_name, date, messageObject.messageOwner.action.title, messageObject.messageOwner.action.address);
+ }
+ } else {
+ if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaEmpty) {
+ if (messageObject.messageOwner.message != null && messageObject.messageOwner.message.length() != 0) {
+ msg = LocaleController.formatString("NotificationMessageText", R.string.NotificationMessageText, Utilities.formatName(user.first_name, user.last_name), messageObject.messageOwner.message);
+ } else {
+ msg = LocaleController.formatString("NotificationMessageNoText", R.string.NotificationMessageNoText, Utilities.formatName(user.first_name, user.last_name));
+ }
+ } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) {
+ msg = LocaleController.formatString("NotificationMessagePhoto", R.string.NotificationMessagePhoto, Utilities.formatName(user.first_name, user.last_name));
+ } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaVideo) {
+ msg = LocaleController.formatString("NotificationMessageVideo", R.string.NotificationMessageVideo, Utilities.formatName(user.first_name, user.last_name));
+ } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaContact) {
+ msg = LocaleController.formatString("NotificationMessageContact", R.string.NotificationMessageContact, Utilities.formatName(user.first_name, user.last_name));
+ } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaGeo) {
+ msg = LocaleController.formatString("NotificationMessageMap", R.string.NotificationMessageMap, Utilities.formatName(user.first_name, user.last_name));
+ } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
+ msg = LocaleController.formatString("NotificationMessageDocument", R.string.NotificationMessageDocument, Utilities.formatName(user.first_name, user.last_name));
+ } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaAudio) {
+ msg = LocaleController.formatString("NotificationMessageAudio", R.string.NotificationMessageAudio, Utilities.formatName(user.first_name, user.last_name));
+ }
+ }
+ } else {
+ msg = LocaleController.formatString("NotificationMessageNoText", R.string.NotificationMessageNoText, Utilities.formatName(user.first_name, user.last_name));
+ }
+ } else if (chat_id != 0) {
+ if (preferences.getBoolean("EnablePreviewGroup", true)) {
+ if (messageObject.messageOwner instanceof TLRPC.TL_messageService) {
+ if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChatAddUser) {
+ if (messageObject.messageOwner.action.user_id == UserConfig.getClientUserId()) {
+ msg = LocaleController.formatString("NotificationInvitedToGroup", R.string.NotificationInvitedToGroup, Utilities.formatName(user.first_name, user.last_name), chat.title);
+ } else {
+ TLRPC.User u2 = MessagesController.getInstance().users.get(messageObject.messageOwner.action.user_id);
+ if (u2 == null) {
+ return;
+ }
+ msg = LocaleController.formatString("NotificationGroupAddMember", R.string.NotificationGroupAddMember, Utilities.formatName(user.first_name, user.last_name), chat.title, Utilities.formatName(u2.first_name, u2.last_name));
+ }
+ } else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChatEditTitle) {
+ msg = LocaleController.formatString("NotificationEditedGroupName", R.string.NotificationEditedGroupName, Utilities.formatName(user.first_name, user.last_name), messageObject.messageOwner.action.title);
+ } else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChatEditPhoto || messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChatDeletePhoto) {
+ msg = LocaleController.formatString("NotificationEditedGroupPhoto", R.string.NotificationEditedGroupPhoto, Utilities.formatName(user.first_name, user.last_name), chat.title);
+ } else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChatDeleteUser) {
+ if (messageObject.messageOwner.action.user_id == UserConfig.getClientUserId()) {
+ msg = LocaleController.formatString("NotificationGroupKickYou", R.string.NotificationGroupKickYou, Utilities.formatName(user.first_name, user.last_name), chat.title);
+ } else if (messageObject.messageOwner.action.user_id == user.id) {
+ msg = LocaleController.formatString("NotificationGroupLeftMember", R.string.NotificationGroupLeftMember, Utilities.formatName(user.first_name, user.last_name), chat.title);
+ } else {
+ TLRPC.User u2 = MessagesController.getInstance().users.get(messageObject.messageOwner.action.user_id);
+ if (u2 == null) {
+ return;
+ }
+ msg = LocaleController.formatString("NotificationGroupKickMember", R.string.NotificationGroupKickMember, Utilities.formatName(user.first_name, user.last_name), chat.title, Utilities.formatName(u2.first_name, u2.last_name));
+ }
+ }
+ } else {
+ if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaEmpty) {
+ if (messageObject.messageOwner.message != null && messageObject.messageOwner.message.length() != 0) {
+ msg = LocaleController.formatString("NotificationMessageGroupText", R.string.NotificationMessageGroupText, Utilities.formatName(user.first_name, user.last_name), chat.title, messageObject.messageOwner.message);
+ } else {
+ msg = LocaleController.formatString("NotificationMessageGroupNoText", R.string.NotificationMessageGroupNoText, Utilities.formatName(user.first_name, user.last_name), chat.title);
+ }
+ } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) {
+ msg = LocaleController.formatString("NotificationMessageGroupPhoto", R.string.NotificationMessageGroupPhoto, Utilities.formatName(user.first_name, user.last_name), chat.title);
+ } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaVideo) {
+ msg = LocaleController.formatString("NotificationMessageGroupVideo", R.string.NotificationMessageGroupVideo, Utilities.formatName(user.first_name, user.last_name), chat.title);
+ } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaContact) {
+ msg = LocaleController.formatString("NotificationMessageGroupContact", R.string.NotificationMessageGroupContact, Utilities.formatName(user.first_name, user.last_name), chat.title);
+ } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaGeo) {
+ msg = LocaleController.formatString("NotificationMessageGroupMap", R.string.NotificationMessageGroupMap, Utilities.formatName(user.first_name, user.last_name), chat.title);
+ } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
+ msg = LocaleController.formatString("NotificationMessageGroupDocument", R.string.NotificationMessageGroupDocument, Utilities.formatName(user.first_name, user.last_name), chat.title);
+ } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaAudio) {
+ msg = LocaleController.formatString("NotificationMessageGroupAudio", R.string.NotificationMessageGroupAudio, Utilities.formatName(user.first_name, user.last_name), chat.title);
+ }
+ }
+ } else {
+ msg = LocaleController.formatString("NotificationMessageGroupNoText", R.string.NotificationMessageGroupNoText, Utilities.formatName(user.first_name, user.last_name), chat.title);
+ }
+ }
+ } else {
+ msg = LocaleController.getString("YouHaveNewMessage", R.string.YouHaveNewMessage);
+ intent.putExtra("encId", (int)(dialog_id >> 32));
+ }
+ if (msg == null) {
+ return;
+ }
+
+ boolean needVibrate = false;
+ String choosenSoundPath = null;
+ int ledColor = 0xff00ff00;
+
+ choosenSoundPath = preferences.getString("sound_path_" + dialog_id, null);
+
+ if (chat_id != 0) {
+ if (choosenSoundPath != null && choosenSoundPath.equals(defaultPath)) {
+ choosenSoundPath = null;
+ } else if (choosenSoundPath == null) {
+ choosenSoundPath = preferences.getString("GroupSoundPath", defaultPath);
+ }
+ needVibrate = preferences.getBoolean("EnableVibrateGroup", true);
+ ledColor = preferences.getInt("GroupLed", 0xff00ff00);
+ } else if (user_id != 0) {
+ if (choosenSoundPath != null && choosenSoundPath.equals(defaultPath)) {
+ choosenSoundPath = null;
+ } else if (choosenSoundPath == null) {
+ choosenSoundPath = preferences.getString("GlobalSoundPath", defaultPath);
+ }
+ needVibrate = preferences.getBoolean("EnableVibrateAll", true);
+ ledColor = preferences.getInt("MessagesLed", 0xff00ff00);
+ }
+ if (preferences.contains("color_" + dialog_id)) {
+ ledColor = preferences.getInt("color_" + dialog_id, 0);
+ }
+
+ if (!needVibrate && vibrate_override == 1) {
+ needVibrate = true;
+ } else if (needVibrate && vibrate_override == 2) {
+ needVibrate = false;
+ }
+
+ String name = Utilities.formatName(user.first_name, user.last_name);
+ if ((int)dialog_id == 0) {
+ name = LocaleController.getString("AppName", R.string.AppName);
+ }
+ String msgShort = msg.replace(name + ": ", "").replace(name + " ", "");
+
+ intent.setAction("com.tmessages.openchat" + Math.random() + Integer.MAX_VALUE);
+ intent.setFlags(32768);
+ PendingIntent contentIntent = PendingIntent.getActivity(ApplicationLoader.applicationContext, 0, intent, PendingIntent.FLAG_ONE_SHOT);
+
+ if (!ApplicationLoader.mainInterfacePaused) {
+ if (!inAppSounds) {
+ choosenSoundPath = null;
+ }
+ if (!inAppVibrate) {
+ needVibrate = false;
+ }
+ }
+
+ NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(ApplicationLoader.applicationContext)
+ .setContentTitle(name)
+ .setSmallIcon(R.drawable.notification)
+ .setStyle(new NotificationCompat.BigTextStyle().bigText(msgShort))
+ .setContentText(msgShort)
+ .setAutoCancel(true);
+
+ if (ApplicationLoader.mainInterfacePaused || inAppPreview) {
+ mBuilder.setTicker(msg);
+ }
+
+ if (photoPath != null) {
+ Bitmap img = FileLoader.getInstance().getImageFromMemory(photoPath, null, null, "50_50", false);
+ if (img != null) {
+ mBuilder.setLargeIcon(img);
+ }
+ }
+
+ if (choosenSoundPath != null && !choosenSoundPath.equals("NoSound")) {
+ if (choosenSoundPath.equals(defaultPath)) {
+ mBuilder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI, AudioManager.STREAM_NOTIFICATION);
+ } else {
+ mBuilder.setSound(Uri.parse(choosenSoundPath), AudioManager.STREAM_NOTIFICATION);
+ }
+ }
+
+ long pauseTime = ConnectionsManager.getInstance().getPauseTime();
+ if (ApplicationLoader.mainInterfacePaused || !ApplicationLoader.isScreenOn) {
+ int popup = 0;
+ if (chat != null) {
+ popup = preferences.getInt("popupGroup", 0);
+ } else {
+ popup = preferences.getInt("popupAll", 0);
+ }
+ if (popup == 3 || popup == 1 && ApplicationLoader.isScreenOn || popup == 2 && !ApplicationLoader.isScreenOn) {
+ Intent popupIntent = new Intent(ApplicationLoader.applicationContext, PopupNotificationActivity.class);
+ popupIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_ANIMATION | Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_FROM_BACKGROUND);
+ ApplicationLoader.applicationContext.startActivity(popupIntent);
+ }
+ }
+
+ currentPushMessage = null;
+ mBuilder.setContentIntent(contentIntent);
+ Notification notification = mBuilder.build();
+ if (ledColor != 0) {
+ notification.ledARGB = ledColor;
+ }
+ notification.ledOnMS = 1000;
+ notification.ledOffMS = 1000;
+ if (needVibrate) {
+ notification.vibrate = new long[]{0, 100, 0, 100};
+ } else {
+ notification.vibrate = new long[]{0, 0};
+ }
+ notification.flags |= Notification.FLAG_SHOW_LIGHTS;
+ try {
+ mNotificationManager.notify(1, notification);
+ currentPushMessage = messageObject;
+ pushMessages.add(0, messageObject);
+ NotificationCenter.getInstance().postNotificationName(pushMessagesUpdated);
+ if (preferences.getBoolean("EnablePebbleNotifications", false)) {
+ sendAlertToPebble(msg);
+ }
+ } catch (Exception e) {
+ FileLog.e("tmessages", e);
+ }
+ }
+
+ public void dismissNotification() {
+ try {
+ NotificationManager mNotificationManager = (NotificationManager)ApplicationLoader.applicationContext.getSystemService(Context.NOTIFICATION_SERVICE);
+ mNotificationManager.cancel(1);
+ MessagesController.getInstance().currentPushMessage = null;
+ MessagesController.getInstance().pushMessages.clear();
+ NotificationCenter.getInstance().postNotificationName(pushMessagesUpdated);
+ } catch (Exception e) {
+ FileLog.e("tmessages", e);
+ }
+ }
+
+ public void sendAlertToPebble(String message) {
+ try {
+ final Intent i = new Intent("com.getpebble.action.SEND_NOTIFICATION");
+
+ final HashMap data = new HashMap();
+ data.put("title", LocaleController.getString("AppName", R.string.AppName));
+ data.put("body", message);
+ final JSONObject jsonData = new JSONObject(data);
+ final String notificationData = new JSONArray().put(jsonData).toString();
+
+ i.putExtra("messageType", "PEBBLE_ALERT");
+ i.putExtra("sender", LocaleController.formatString("AppName", R.string.AppName));
+ i.putExtra("notificationData", notificationData);
+
+ ApplicationLoader.applicationContext.sendBroadcast(i);
+ } catch (Exception e) {
+ FileLog.e("tmessages", e);
+ }
+ }
}
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/MessagesStorage.java b/TMessagesProj/src/main/java/org/telegram/android/MessagesStorage.java
similarity index 89%
rename from TMessagesProj/src/main/java/org/telegram/messenger/MessagesStorage.java
rename to TMessagesProj/src/main/java/org/telegram/android/MessagesStorage.java
index 1448f6ff..ab10e432 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/MessagesStorage.java
+++ b/TMessagesProj/src/main/java/org/telegram/android/MessagesStorage.java
@@ -6,7 +6,7 @@
* Copyright Nikolai Kudashov, 2013.
*/
-package org.telegram.messenger;
+package org.telegram.android;
import android.text.Html;
import android.util.SparseArray;
@@ -15,6 +15,17 @@ import org.telegram.PhoneFormat.PhoneFormat;
import org.telegram.SQLite.SQLiteCursor;
import org.telegram.SQLite.SQLiteDatabase;
import org.telegram.SQLite.SQLitePreparedStatement;
+import org.telegram.messenger.BuffersStorage;
+import org.telegram.messenger.ByteBufferDesc;
+import org.telegram.messenger.ConnectionsManager;
+import org.telegram.messenger.DispatchQueue;
+import org.telegram.messenger.FileLog;
+import org.telegram.messenger.NotificationCenter;
+import org.telegram.messenger.TLClassStore;
+import org.telegram.messenger.TLObject;
+import org.telegram.messenger.TLRPC;
+import org.telegram.messenger.UserConfig;
+import org.telegram.messenger.Utilities;
import org.telegram.objects.MessageObject;
import org.telegram.ui.ApplicationLoader;
@@ -28,6 +39,7 @@ public class MessagesStorage {
public DispatchQueue storageQueue = new DispatchQueue("storageQueue");
private SQLiteDatabase database;
private File cacheFile;
+ private BuffersStorage buffersStorage = new BuffersStorage(false);
public static int lastDateValue = 0;
public static int lastPtsValue = 0;
public static int lastQtsValue = 0;
@@ -63,8 +75,6 @@ public class MessagesStorage {
}
public void openDatabase() {
- NativeLoader.initNativeLibs(ApplicationLoader.applicationContext);
-
cacheFile = new File(ApplicationLoader.applicationContext.getFilesDir(), "cache4.db");
boolean createTable = false;
@@ -216,13 +226,14 @@ public class MessagesStorage {
SQLitePreparedStatement state = database.executeFast("UPDATE params SET lsv = ?, sg = ?, pbytes = ? WHERE id = 1");
state.bindInteger(1, lsv);
state.bindInteger(2, sg);
+ ByteBufferDesc data = buffersStorage.getFreeBuffer(pbytes != null ? pbytes.length : 1);
if (pbytes != null) {
- state.bindByteArray(3, pbytes);
- } else {
- state.bindByteArray(3, new byte[1]);
+ data.writeRaw(pbytes);
}
+ state.bindByteBuffer(3, data.buffer);
state.step();
state.dispose();
+ buffersStorage.reuseFreeBuffer(data);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
@@ -261,18 +272,19 @@ public class MessagesStorage {
@Override
public void run() {
try {
+ int num = 0;
database.executeFast("DELETE FROM wallpapers WHERE 1").stepThis().dispose();
database.beginTransaction();
SQLitePreparedStatement state = database.executeFast("REPLACE INTO wallpapers VALUES(?, ?)");
- int num = 0;
for (TLRPC.WallPaper wallPaper : wallPapers) {
state.requery();
- SerializedData data = new SerializedData();
+ ByteBufferDesc data = buffersStorage.getFreeBuffer(wallPaper.getObjectSize());
wallPaper.serializeToStream(data);
state.bindInteger(1, num);
- state.bindByteArray(2, data.toByteArray());
+ state.bindByteBuffer(2, data.buffer);
state.step();
num++;
+ buffersStorage.reuseFreeBuffer(data);
}
state.dispose();
database.commitTransaction();
@@ -291,12 +303,12 @@ public class MessagesStorage {
SQLiteCursor cursor = database.queryFinalized("SELECT data FROM wallpapers WHERE 1");
ArrayList wallPapers = new ArrayList();
while (cursor.next()) {
- byte[] bytes = cursor.byteArrayValue(0);
- if (bytes != null) {
- SerializedData data = new SerializedData(bytes);
- TLRPC.WallPaper wallPaper = (TLRPC.WallPaper)TLClassStore.Instance().TLdeserialize(data, data.readInt32());
+ ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
+ if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
+ TLRPC.WallPaper wallPaper = (TLRPC.WallPaper) TLClassStore.Instance().TLdeserialize(data, data.readInt32());
wallPapers.add(wallPaper);
}
+ buffersStorage.reuseFreeBuffer(data);
}
cursor.dispose();
NotificationCenter.getInstance().postNotificationName(wallpapersDidLoaded, wallPapers);
@@ -342,12 +354,12 @@ public class MessagesStorage {
final TLRPC.photos_Photos res = new TLRPC.photos_Photos();
while (cursor.next()) {
- byte[] messageData = cursor.byteArrayValue(0);
- if (messageData != null) {
- SerializedData data = new SerializedData(messageData);
+ ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
+ if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
TLRPC.Photo photo = (TLRPC.Photo)TLClassStore.Instance().TLdeserialize(data, data.readInt32());
res.photos.add(photo);
}
+ buffersStorage.reuseFreeBuffer(data);
}
cursor.dispose();
@@ -392,13 +404,13 @@ public class MessagesStorage {
continue;
}
state.requery();
- SerializedData data = new SerializedData();
+ ByteBufferDesc data = buffersStorage.getFreeBuffer(photo.getObjectSize());
photo.serializeToStream(data);
state.bindInteger(1, uid);
state.bindLong(2, photo.id);
- byte[] bytes = data.toByteArray();
- state.bindByteArray(3, bytes);
+ state.bindByteBuffer(3, data.buffer);
state.step();
+ buffersStorage.reuseFreeBuffer(data);
}
state.dispose();
} catch (Exception e) {
@@ -423,13 +435,16 @@ public class MessagesStorage {
if (cursor.next()) {
taskId = cursor.longValue(0);
date = cursor.intValue(1);
- byte[] data = cursor.byteArrayValue(2);
- SerializedData serializedData = new SerializedData(data);
- arr = new ArrayList();
- int count = data.length / 4;
- for (int a = 0; a < count; a++) {
- arr.add(serializedData.readInt32());
+
+ int length = 0;
+ ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(2));
+ if ((length = cursor.byteBufferValue(2, data.buffer)) != 0) {
+ arr = new ArrayList();
+ for (int a = 0; a < length / 4; a++) {
+ arr.add(data.readInt32());
+ }
}
+ buffersStorage.reuseFreeBuffer(data);
}
cursor.dispose();
MessagesController.getInstance().processLoadedDeleteTask(taskId, date, arr);
@@ -473,22 +488,22 @@ public class MessagesStorage {
for (int a = 0; a < messages.size(); a++) {
int key = messages.keyAt(a);
ArrayList arr = messages.get(key);
- SerializedData data = new SerializedData();
+ ByteBufferDesc data = buffersStorage.getFreeBuffer(404);
+ int count = 0;
for (int b = 0; b < arr.size(); b++) {
int mid = arr.get(b);
data.writeInt32(mid);
+ count++;
if (b == arr.size() - 1 || b != 0 && b % 100 == 0) {
state.requery();
- byte[] toDb = data.toByteArray();
+ data.limit(count * 4);
state.bindInteger(1, key);
- state.bindByteArray(2, toDb);
+ state.bindByteBuffer(2, data.buffer);
state.step();
-
- if (b != arr.size() - 1) {
- data = new SerializedData();
- }
+ count = 0;
}
}
+ buffersStorage.reuseFreeBuffer(data);
}
state.dispose();
database.commitTransaction();
@@ -613,12 +628,13 @@ public class MessagesStorage {
}
}
SQLitePreparedStatement state = database.executeFast("REPLACE INTO chat_settings VALUES(?, ?)");
- SerializedData data = new SerializedData();
+ ByteBufferDesc data = buffersStorage.getFreeBuffer(info.getObjectSize());
info.serializeToStream(data);
state.bindInteger(1, chat_id);
- state.bindByteArray(2, data.toByteArray());
+ state.bindByteBuffer(2, data.buffer);
state.step();
state.dispose();
+ buffersStorage.reuseFreeBuffer(data);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
@@ -635,11 +651,11 @@ public class MessagesStorage {
TLRPC.ChatParticipants info = null;
ArrayList loadedUsers = new ArrayList();
if (cursor.next()) {
- byte[] userData = cursor.byteArrayValue(0);
- if (userData != null) {
- SerializedData data = new SerializedData(userData);
+ ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
+ if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
info = (TLRPC.ChatParticipants)TLClassStore.Instance().TLdeserialize(data, data.readInt32());
}
+ buffersStorage.reuseFreeBuffer(data);
}
cursor.dispose();
if (info != null) {
@@ -669,12 +685,13 @@ public class MessagesStorage {
});
SQLitePreparedStatement state = database.executeFast("REPLACE INTO chat_settings VALUES(?, ?)");
- SerializedData data = new SerializedData();
+ ByteBufferDesc data = buffersStorage.getFreeBuffer(info.getObjectSize());
info.serializeToStream(data);
state.bindInteger(1, chat_id);
- state.bindByteArray(2, data.toByteArray());
+ state.bindByteBuffer(2, data.buffer);
state.step();
state.dispose();
+ buffersStorage.reuseFreeBuffer(data);
}
} catch (Exception e) {
FileLog.e("tmessages", e);
@@ -692,11 +709,11 @@ public class MessagesStorage {
TLRPC.ChatParticipants info = null;
ArrayList loadedUsers = new ArrayList();
if (cursor.next()) {
- byte[] userData = cursor.byteArrayValue(0);
- if (userData != null) {
- SerializedData data = new SerializedData(userData);
+ ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
+ if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
info = (TLRPC.ChatParticipants)TLClassStore.Instance().TLdeserialize(data, data.readInt32());
}
+ buffersStorage.reuseFreeBuffer(data);
}
cursor.dispose();
@@ -711,15 +728,15 @@ public class MessagesStorage {
if (usersToLoad.length() != 0) {
cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, status FROM users WHERE uid IN(%s)", usersToLoad));
while (cursor.next()) {
- byte[] userData = cursor.byteArrayValue(0);
- if (userData != null) {
- SerializedData data = new SerializedData(userData);
+ ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
+ if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
TLRPC.User user = (TLRPC.User)TLClassStore.Instance().TLdeserialize(data, data.readInt32());
loadedUsers.add(user);
if (user.status != null) {
user.status.expires = cursor.intValue(1);
}
}
+ buffersStorage.reuseFreeBuffer(data);
}
cursor.dispose();
}
@@ -801,19 +818,18 @@ public class MessagesStorage {
String[] args = name.split(" ");
for (String str : args) {
if (str.startsWith(q)) {
- byte[] userData = cursor.byteArrayValue(0);
- if (userData != null) {
- SerializedData data = new SerializedData(userData);
+ ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
+ if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
TLRPC.User user = (TLRPC.User)TLClassStore.Instance().TLdeserialize(data, data.readInt32());
- if (user.id == UserConfig.getClientUserId()) {
- continue;
+ if (user.id != UserConfig.getClientUserId()) {
+ if (user.status != null) {
+ user.status.expires = cursor.intValue(1);
+ }
+ resultArrayNames.add(Utilities.generateSearchName(user.first_name, user.last_name, q));
+ resultArray.add(user);
}
- if (user.status != null) {
- user.status.expires = cursor.intValue(1);
- }
- resultArrayNames.add(Utilities.generateSearchName(user.first_name, user.last_name, q));
- resultArray.add(user);
}
+ buffersStorage.reuseFreeBuffer(data);
break;
}
}
@@ -827,17 +843,15 @@ public class MessagesStorage {
String[] args = name.split(" ");
for (String arg : args) {
if (arg.startsWith(q)) {
- byte[] chatData = cursor.byteArrayValue(0);
- byte[] userData = cursor.byteArrayValue(6);
- if (chatData != null && userData != null) {
- SerializedData data = new SerializedData(chatData);
+ ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
+ ByteBufferDesc data2 = buffersStorage.getFreeBuffer(cursor.byteArrayLength(6));
+ if (data != null && cursor.byteBufferValue(0, data.buffer) != 0 && cursor.byteBufferValue(0, data2.buffer) != 0) {
TLRPC.EncryptedChat chat = (TLRPC.EncryptedChat) TLClassStore.Instance().TLdeserialize(data, data.readInt32());
chat.user_id = cursor.intValue(2);
chat.a_or_b = cursor.byteArrayValue(3);
chat.auth_key = cursor.byteArrayValue(4);
chat.ttl = cursor.intValue(5);
- SerializedData data2 = new SerializedData(userData);
TLRPC.User user = (TLRPC.User)TLClassStore.Instance().TLdeserialize(data2, data2.readInt32());
if (user.status != null) {
user.status.expires = cursor.intValue(7);
@@ -846,6 +860,8 @@ public class MessagesStorage {
resultArray.add(chat);
encUsers.add(user);
}
+ buffersStorage.reuseFreeBuffer(data);
+ buffersStorage.reuseFreeBuffer(data2);
break;
}
}
@@ -859,13 +875,13 @@ public class MessagesStorage {
String[] args = name.split(" ");
for (String arg : args) {
if (arg.startsWith(q)) {
- byte[] chatData = cursor.byteArrayValue(0);
- if (chatData != null) {
- SerializedData data = new SerializedData(chatData);
+ ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
+ if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
TLRPC.Chat chat = (TLRPC.Chat) TLClassStore.Instance().TLdeserialize(data, data.readInt32());
resultArrayNames.add(Utilities.generateSearchName(chat.title, null, q));
resultArray.add(chat);
}
+ buffersStorage.reuseFreeBuffer(data);
break;
}
}
@@ -1059,15 +1075,15 @@ public class MessagesStorage {
if (uids.length() != 0) {
cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, status FROM users WHERE uid IN(%s)", uids));
while (cursor.next()) {
- byte[] userData = cursor.byteArrayValue(0);
- if (userData != null) {
- SerializedData data = new SerializedData(userData);
+ ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
+ if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
TLRPC.User user = (TLRPC.User)TLClassStore.Instance().TLdeserialize(data, data.readInt32());
users.add(user);
if (user.status != null) {
user.status.expires = cursor.intValue(1);
}
}
+ buffersStorage.reuseFreeBuffer(data);
}
cursor.dispose();
}
@@ -1155,15 +1171,15 @@ public class MessagesStorage {
}
while (cursor.next()) {
- byte[] messageData = cursor.byteArrayValue(0);
- if (messageData != null) {
- SerializedData data = new SerializedData(messageData);
+ ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
+ if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
TLRPC.Message message = (TLRPC.Message)TLClassStore.Instance().TLdeserialize(data, data.readInt32());
message.id = cursor.intValue(1);
message.dialog_id = uid;
res.messages.add(message);
fromUser.add(message.from_id);
}
+ buffersStorage.reuseFreeBuffer(data);
}
cursor.dispose();
@@ -1180,9 +1196,8 @@ public class MessagesStorage {
if (usersToLoad.length() != 0) {
cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, status FROM users WHERE uid IN(%s)", usersToLoad));
while (cursor.next()) {
- byte[] userData = cursor.byteArrayValue(0);
- if (userData != null) {
- SerializedData data = new SerializedData(userData);
+ ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
+ if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
TLRPC.User user = (TLRPC.User)TLClassStore.Instance().TLdeserialize(data, data.readInt32());
loadedUsers.add(user.id);
if (user.status != null) {
@@ -1190,6 +1205,7 @@ public class MessagesStorage {
}
res.users.add(user);
}
+ buffersStorage.reuseFreeBuffer(data);
}
cursor.dispose();
}
@@ -1215,13 +1231,14 @@ public class MessagesStorage {
for (TLRPC.Message message : messages) {
if (message.media instanceof TLRPC.TL_messageMediaVideo || message.media instanceof TLRPC.TL_messageMediaPhoto) {
state2.requery();
- SerializedData data = new SerializedData();
+ ByteBufferDesc data = buffersStorage.getFreeBuffer(message.getObjectSize());
message.serializeToStream(data);
state2.bindInteger(1, message.id);
state2.bindLong(2, uid);
state2.bindInteger(3, message.date);
- state2.bindByteArray(4, data.toByteArray());
+ state2.bindByteBuffer(4, data.buffer);
state2.step();
+ buffersStorage.reuseFreeBuffer(data);
}
}
state2.dispose();
@@ -1333,9 +1350,8 @@ public class MessagesStorage {
}
}
while (cursor.next()) {
- byte[] messageData = cursor.byteArrayValue(1);
- if (messageData != null) {
- SerializedData data = new SerializedData(messageData);
+ ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(1));
+ if (data != null && cursor.byteBufferValue(1, data.buffer) != 0) {
TLRPC.Message message = (TLRPC.Message)TLClassStore.Instance().TLdeserialize(data, data.readInt32());
int read_state = cursor.intValue(0);
message.unread = (cursor.intValue(0) != 1);
@@ -1364,6 +1380,7 @@ public class MessagesStorage {
message.random_id = cursor.longValue(5);
}
}
+ buffersStorage.reuseFreeBuffer(data);
}
cursor.dispose();
@@ -1380,9 +1397,8 @@ public class MessagesStorage {
if (usersToLoad.length() != 0) {
cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, status FROM users WHERE uid IN(%s)", usersToLoad));
while (cursor.next()) {
- byte[] userData = cursor.byteArrayValue(0);
- if (userData != null) {
- SerializedData data = new SerializedData(userData);
+ ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
+ if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
TLRPC.User user = (TLRPC.User)TLClassStore.Instance().TLdeserialize(data, data.readInt32());
loadedUsers.add(user.id);
if (user.status != null) {
@@ -1390,6 +1406,7 @@ public class MessagesStorage {
}
res.users.add(user);
}
+ buffersStorage.reuseFreeBuffer(data);
}
cursor.dispose();
}
@@ -1453,14 +1470,14 @@ public class MessagesStorage {
if (id != null) {
SQLiteCursor cursor = database.queryFinalized(String.format(Locale.US, "SELECT data FROM sent_files_v2 WHERE uid = '%s' AND type = %d", id, type));
if (cursor.next()) {
- byte[] fileData = cursor.byteArrayValue(0);
- if (fileData != null) {
- SerializedData data = new SerializedData(fileData);
+ ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
+ if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
TLObject file = TLClassStore.Instance().TLdeserialize(data, data.readInt32());
if (file != null) {
result.add(file);
}
}
+ buffersStorage.reuseFreeBuffer(data);
}
cursor.dispose();
}
@@ -1491,13 +1508,14 @@ public class MessagesStorage {
if (id != null) {
SQLitePreparedStatement state = database.executeFast("REPLACE INTO sent_files_v2 VALUES(?, ?, ?)");
state.requery();
- SerializedData data = new SerializedData();
+ ByteBufferDesc data = buffersStorage.getFreeBuffer(file.getObjectSize());
file.serializeToStream(data);
state.bindString(1, id);
state.bindInteger(2, type);
- state.bindByteArray(3, data.toByteArray());
+ state.bindByteBuffer(3, data.buffer);
state.step();
state.dispose();
+ buffersStorage.reuseFreeBuffer(data);
}
} catch (Exception e) {
FileLog.e("tmessages", e);
@@ -1540,22 +1558,25 @@ public class MessagesStorage {
SQLitePreparedStatement state = null;
try {
state = database.executeFast("UPDATE enc_chats SET data = ?, g = ?, authkey = ?, ttl = ? WHERE uid = ?");
- SerializedData data = new SerializedData();
+ ByteBufferDesc data = buffersStorage.getFreeBuffer(chat.getObjectSize());
+ ByteBufferDesc data2 = buffersStorage.getFreeBuffer(chat.a_or_b != null ? chat.a_or_b.length : 1);
+ ByteBufferDesc data3 = buffersStorage.getFreeBuffer(chat.auth_key != null ? chat.auth_key.length : 1);
chat.serializeToStream(data);
- state.bindByteArray(1, data.toByteArray());
+ state.bindByteBuffer(1, data.buffer);
if (chat.a_or_b != null) {
- state.bindByteArray(2, chat.a_or_b);
- } else {
- state.bindByteArray(2, new byte[1]);
+ data2.writeRaw(chat.a_or_b);
}
if (chat.auth_key != null) {
- state.bindByteArray(3, chat.auth_key);
- } else {
- state.bindByteArray(3, new byte[1]);
+ data3.writeRaw(chat.auth_key);
}
+ state.bindByteBuffer(2, data2.buffer);
+ state.bindByteBuffer(3, data3.buffer);
state.bindInteger(4, chat.ttl);
state.bindInteger(5, chat.id);
state.step();
+ buffersStorage.reuseFreeBuffer(data);
+ buffersStorage.reuseFreeBuffer(data2);
+ buffersStorage.reuseFreeBuffer(data3);
} catch (Exception e) {
FileLog.e("tmessages", e);
} finally {
@@ -1578,9 +1599,8 @@ public class MessagesStorage {
int userToLoad = 0;
SQLiteCursor cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, user, g, authkey, ttl FROM enc_chats WHERE uid = %d", chat_id));
if (cursor.next()) {
- byte[] chatData = cursor.byteArrayValue(0);
- if (chatData != null) {
- SerializedData data = new SerializedData(chatData);
+ ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
+ if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
TLRPC.EncryptedChat chat = (TLRPC.EncryptedChat)TLClassStore.Instance().TLdeserialize(data, data.readInt32());
result.add(chat);
chat.user_id = cursor.intValue(1);
@@ -1589,20 +1609,21 @@ public class MessagesStorage {
chat.auth_key = cursor.byteArrayValue(3);
chat.ttl = cursor.intValue(4);
}
+ buffersStorage.reuseFreeBuffer(data);
}
cursor.dispose();
if (userToLoad != 0) {
cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, status FROM users WHERE uid = %d", userToLoad));
if (cursor.next()) {
- byte[] userData = cursor.byteArrayValue(0);
- if (userData != null) {
- SerializedData data = new SerializedData(userData);
+ ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
+ if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
TLRPC.User user = (TLRPC.User)TLClassStore.Instance().TLdeserialize(data, data.readInt32());
if (user.status != null) {
user.status.expires = cursor.intValue(1);
}
result.add(user);
}
+ buffersStorage.reuseFreeBuffer(data);
}
cursor.dispose();
@@ -1628,7 +1649,10 @@ public class MessagesStorage {
public void run() {
try {
SQLitePreparedStatement state = database.executeFast("REPLACE INTO enc_chats VALUES(?, ?, ?, ?, ?, ?, ?)");
- SerializedData data = new SerializedData();
+ ByteBufferDesc data = buffersStorage.getFreeBuffer(chat.getObjectSize());
+ ByteBufferDesc data2 = buffersStorage.getFreeBuffer(chat.a_or_b != null ? chat.a_or_b.length : 1);
+ ByteBufferDesc data3 = buffersStorage.getFreeBuffer(chat.auth_key != null ? chat.auth_key.length : 1);
+
chat.serializeToStream(data);
state.bindInteger(1, chat.id);
state.bindInteger(2, user.id);
@@ -1638,20 +1662,21 @@ public class MessagesStorage {
} else {
state.bindString(3, "");
}
- state.bindByteArray(4, data.toByteArray());
+ state.bindByteBuffer(4, data.buffer);
if (chat.a_or_b != null) {
- state.bindByteArray(5, chat.a_or_b);
- } else {
- state.bindByteArray(5, new byte[1]);
+ data2.writeRaw(chat.a_or_b);
}
if (chat.auth_key != null) {
- state.bindByteArray(6, chat.auth_key);
- } else {
- state.bindByteArray(6, new byte[1]);
+ data3.writeRaw(chat.auth_key);
}
+ state.bindByteBuffer(5, data2.buffer);
+ state.bindByteBuffer(6, data3.buffer);
state.bindInteger(7, chat.ttl);
state.step();
state.dispose();
+ buffersStorage.reuseFreeBuffer(data);
+ buffersStorage.reuseFreeBuffer(data2);
+ buffersStorage.reuseFreeBuffer(data3);
if (dialog != null) {
state = database.executeFast("REPLACE INTO dialogs VALUES(?, ?, ?, ?)");
@@ -1681,7 +1706,7 @@ public class MessagesStorage {
SQLitePreparedStatement state = database.executeFast("REPLACE INTO users VALUES(?, ?, ?, ?)");
for (TLRPC.User user : users) {
state.requery();
- SerializedData data = new SerializedData();
+ ByteBufferDesc data = buffersStorage.getFreeBuffer(user.getObjectSize());
user.serializeToStream(data);
state.bindInteger(1, user.id);
if (user.first_name != null && user.last_name != null) {
@@ -1695,8 +1720,9 @@ public class MessagesStorage {
} else {
state.bindInteger(3, 0);
}
- state.bindByteArray(4, data.toByteArray());
+ state.bindByteBuffer(4, data.buffer);
state.step();
+ buffersStorage.reuseFreeBuffer(data);
}
state.dispose();
}
@@ -1704,7 +1730,7 @@ public class MessagesStorage {
SQLitePreparedStatement state = database.executeFast("REPLACE INTO chats VALUES(?, ?, ?)");
for (TLRPC.Chat chat : chats) {
state.requery();
- SerializedData data = new SerializedData();
+ ByteBufferDesc data = buffersStorage.getFreeBuffer(chat.getObjectSize());
chat.serializeToStream(data);
state.bindInteger(1, chat.id);
if (chat.title != null) {
@@ -1713,8 +1739,9 @@ public class MessagesStorage {
} else {
state.bindString(2, "");
}
- state.bindByteArray(3, data.toByteArray());
+ state.bindByteBuffer(3, data.buffer);
state.step();
+ buffersStorage.reuseFreeBuffer(data);
}
state.dispose();
}
@@ -1850,7 +1877,7 @@ public class MessagesStorage {
messageId = message.local_id;
}
- SerializedData data = new SerializedData();
+ ByteBufferDesc data = buffersStorage.getFreeBuffer(message.getObjectSize());
message.serializeToStream(data);
TLRPC.Message lastMessage = messagesMap.get(dialog_id);
if (lastMessage == null || message.date > lastMessage.date) {
@@ -1861,8 +1888,7 @@ public class MessagesStorage {
state.bindInteger(3, (message.unread ? 0 : 1));
state.bindInteger(4, message.send_state);
state.bindInteger(5, message.date);
- byte[] bytes = data.toByteArray();
- state.bindByteArray(6, bytes);
+ state.bindByteBuffer(6, data.buffer);
state.bindInteger(7, (message.out ? 1 : 0));
state.bindInteger(8, message.ttl);
state.step();
@@ -1879,9 +1905,10 @@ public class MessagesStorage {
state2.bindInteger(1, messageId);
state2.bindLong(2, dialog_id);
state2.bindInteger(3, message.date);
- state2.bindByteArray(4, bytes);
+ state2.bindByteBuffer(4, data.buffer);
state2.step();
}
+ buffersStorage.reuseFreeBuffer(data);
}
state.dispose();
state2.dispose();
@@ -2094,9 +2121,8 @@ public class MessagesStorage {
ArrayList loadedUsers = new ArrayList();
SQLiteCursor cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, status FROM users WHERE uid IN(%s)", ids));
while (cursor.next()) {
- byte[] userData = cursor.byteArrayValue(0);
- if (userData != null) {
- SerializedData data = new SerializedData(userData);
+ ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
+ if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
TLRPC.User user = (TLRPC.User)TLClassStore.Instance().TLdeserialize(data, data.readInt32());
loadedUsers.add(user);
if (user.status != null) {
@@ -2110,6 +2136,7 @@ public class MessagesStorage {
user.photo = updateUser.photo;
}
}
+ buffersStorage.reuseFreeBuffer(data);
}
cursor.dispose();
if (!loadedUsers.isEmpty()) {
@@ -2119,7 +2146,7 @@ public class MessagesStorage {
SQLitePreparedStatement state = database.executeFast("REPLACE INTO users VALUES(?, ?, ?, ?)");
for (TLRPC.User user : loadedUsers) {
state.requery();
- SerializedData data = new SerializedData();
+ ByteBufferDesc data = buffersStorage.getFreeBuffer(user.getObjectSize());
user.serializeToStream(data);
state.bindInteger(1, user.id);
if (user.first_name != null && user.last_name != null) {
@@ -2133,8 +2160,9 @@ public class MessagesStorage {
} else {
state.bindInteger(3, 0);
}
- state.bindByteArray(4, data.toByteArray());
+ state.bindByteBuffer(4, data.buffer);
state.step();
+ buffersStorage.reuseFreeBuffer(data);
}
state.dispose();
if (withTransaction) {
@@ -2325,9 +2353,8 @@ public class MessagesStorage {
dialog.last_message_date = cursor.intValue(3);
dialogs.dialogs.add(dialog);
- byte[] messageData = cursor.byteArrayValue(4);
- if (messageData != null) {
- SerializedData data = new SerializedData(messageData);
+ ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(4));
+ if (data != null && cursor.byteBufferValue(4, data.buffer) != 0) {
TLRPC.Message message = (TLRPC.Message)TLClassStore.Instance().TLdeserialize(data, data.readInt32());
message.unread = (cursor.intValue(5) != 1);
message.id = cursor.intValue(6);
@@ -2348,6 +2375,7 @@ public class MessagesStorage {
}
}
}
+ buffersStorage.reuseFreeBuffer(data);
int lower_id = (int)dialog.id;
if (lower_id != 0) {
@@ -2379,9 +2407,8 @@ public class MessagesStorage {
}
cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, user, g, authkey, ttl FROM enc_chats WHERE uid IN(%s)", toLoad));
while (cursor.next()) {
- byte[] chatData = cursor.byteArrayValue(0);
- if (chatData != null) {
- SerializedData data = new SerializedData(chatData);
+ ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
+ if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
TLRPC.EncryptedChat chat = (TLRPC.EncryptedChat)TLClassStore.Instance().TLdeserialize(data, data.readInt32());
encryptedChats.add(chat);
chat.user_id = cursor.intValue(1);
@@ -2392,6 +2419,7 @@ public class MessagesStorage {
chat.auth_key = cursor.byteArrayValue(3);
chat.ttl = cursor.intValue(4);
}
+ buffersStorage.reuseFreeBuffer(data);
}
cursor.dispose();
}
@@ -2406,12 +2434,12 @@ public class MessagesStorage {
}
cursor = database.queryFinalized(String.format(Locale.US, "SELECT data FROM chats WHERE uid IN(%s)", toLoad));
while (cursor.next()) {
- byte[] chatData = cursor.byteArrayValue(0);
- if (chatData != null) {
- SerializedData data = new SerializedData(chatData);
+ ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
+ if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
TLRPC.Chat chat = (TLRPC.Chat)TLClassStore.Instance().TLdeserialize(data, data.readInt32());
dialogs.chats.add(chat);
}
+ buffersStorage.reuseFreeBuffer(data);
}
cursor.dispose();
}
@@ -2426,15 +2454,15 @@ public class MessagesStorage {
}
cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, status FROM users WHERE uid IN(%s)", toLoad));
while (cursor.next()) {
- byte[] userData = cursor.byteArrayValue(0);
- if (userData != null) {
- SerializedData data = new SerializedData(userData);
+ ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
+ if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
TLRPC.User user = (TLRPC.User)TLClassStore.Instance().TLdeserialize(data, data.readInt32());
if (user.status != null) {
user.status.expires = cursor.intValue(1);
}
dialogs.users.add(user);
}
+ buffersStorage.reuseFreeBuffer(data);
}
cursor.dispose();
}
@@ -2493,15 +2521,14 @@ public class MessagesStorage {
SQLitePreparedStatement state2 = database.executeFast("REPLACE INTO media VALUES(?, ?, ?, ?)");
for (TLRPC.Message message : messages.messages) {
state.requery();
- SerializedData data = new SerializedData();
+ ByteBufferDesc data = buffersStorage.getFreeBuffer(message.getObjectSize());
message.serializeToStream(data);
state.bindInteger(1, message.id);
state.bindLong(2, dialog_id);
state.bindInteger(3, (message.unread ? 0 : 1));
state.bindInteger(4, message.send_state);
state.bindInteger(5, message.date);
- byte[] bytes = data.toByteArray();
- state.bindByteArray(6, bytes);
+ state.bindByteBuffer(6, data.buffer);
state.bindInteger(7, (message.out ? 1 : 0));
state.bindInteger(8, 0);
state.step();
@@ -2511,9 +2538,10 @@ public class MessagesStorage {
state2.bindInteger(1, message.id);
state2.bindLong(2, dialog_id);
state2.bindInteger(3, message.date);
- state2.bindByteArray(4, bytes);
+ state2.bindByteBuffer(4, data.buffer);
state2.step();
}
+ buffersStorage.reuseFreeBuffer(data);
}
state.dispose();
state2.dispose();
@@ -2522,7 +2550,7 @@ public class MessagesStorage {
SQLitePreparedStatement state = database.executeFast("REPLACE INTO users VALUES(?, ?, ?, ?)");
for (TLRPC.User user : messages.users) {
state.requery();
- SerializedData data = new SerializedData();
+ ByteBufferDesc data = buffersStorage.getFreeBuffer(user.getObjectSize());
user.serializeToStream(data);
state.bindInteger(1, user.id);
if (user.first_name != null && user.last_name != null) {
@@ -2536,8 +2564,9 @@ public class MessagesStorage {
} else {
state.bindInteger(3, 0);
}
- state.bindByteArray(4, data.toByteArray());
+ state.bindByteBuffer(4, data.buffer);
state.step();
+ buffersStorage.reuseFreeBuffer(data);
}
state.dispose();
}
@@ -2545,7 +2574,7 @@ public class MessagesStorage {
SQLitePreparedStatement state = database.executeFast("REPLACE INTO chats VALUES(?, ?, ?)");
for (TLRPC.Chat chat : messages.chats) {
state.requery();
- SerializedData data = new SerializedData();
+ ByteBufferDesc data = buffersStorage.getFreeBuffer(chat.getObjectSize());
chat.serializeToStream(data);
state.bindInteger(1, chat.id);
if (chat.title != null) {
@@ -2554,8 +2583,9 @@ public class MessagesStorage {
} else {
state.bindString(2, "");
}
- state.bindByteArray(3, data.toByteArray());
+ state.bindByteBuffer(3, data.buffer);
state.step();
+ buffersStorage.reuseFreeBuffer(data);
}
state.dispose();
}
@@ -2588,9 +2618,8 @@ public class MessagesStorage {
dialog.last_message_date = cursor.intValue(3);
dialogs.dialogs.add(dialog);
- byte[] messageData = cursor.byteArrayValue(4);
- if (messageData != null) {
- SerializedData data = new SerializedData(messageData);
+ ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(4));
+ if (data != null && cursor.byteBufferValue(4, data.buffer) != 0) {
TLRPC.Message message = (TLRPC.Message)TLClassStore.Instance().TLdeserialize(data, data.readInt32());
if (message != null) {
message.unread = (cursor.intValue(5) != 1);
@@ -2613,6 +2642,7 @@ public class MessagesStorage {
}
}
}
+ buffersStorage.reuseFreeBuffer(data);
int lower_id = (int)dialog.id;
if (lower_id != 0) {
@@ -2645,9 +2675,8 @@ public class MessagesStorage {
cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, user, g, authkey, ttl FROM enc_chats WHERE uid IN(%s)", toLoad));
while (cursor.next()) {
try {
- byte[] chatData = cursor.byteArrayValue(0);
- if (chatData != null) {
- SerializedData data = new SerializedData(chatData);
+ ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
+ if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
TLRPC.EncryptedChat chat = (TLRPC.EncryptedChat)TLClassStore.Instance().TLdeserialize(data, data.readInt32());
if (chat != null) {
encryptedChats.add(chat);
@@ -2660,6 +2689,7 @@ public class MessagesStorage {
chat.ttl = cursor.intValue(4);
}
}
+ buffersStorage.reuseFreeBuffer(data);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
@@ -2678,14 +2708,14 @@ public class MessagesStorage {
cursor = database.queryFinalized(String.format(Locale.US, "SELECT data FROM chats WHERE uid IN(%s)", toLoad));
while (cursor.next()) {
try {
- byte[] chatData = cursor.byteArrayValue(0);
- if (chatData != null) {
- SerializedData data = new SerializedData(chatData);
+ ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
+ if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
TLRPC.Chat chat = (TLRPC.Chat)TLClassStore.Instance().TLdeserialize(data, data.readInt32());
if (chat != null) {
dialogs.chats.add(chat);
}
}
+ buffersStorage.reuseFreeBuffer(data);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
@@ -2704,9 +2734,8 @@ public class MessagesStorage {
cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, status FROM users WHERE uid IN(%s)", toLoad));
while (cursor.next()) {
try {
- byte[] userData = cursor.byteArrayValue(0);
- if (userData != null) {
- SerializedData data = new SerializedData(userData);
+ ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
+ if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
TLRPC.User user = (TLRPC.User)TLClassStore.Instance().TLdeserialize(data, data.readInt32());
if (user != null) {
if (user.status != null) {
@@ -2715,6 +2744,7 @@ public class MessagesStorage {
dialogs.users.add(user);
}
}
+ buffersStorage.reuseFreeBuffer(data);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
@@ -2766,7 +2796,7 @@ public class MessagesStorage {
uid = -dialog.peer.chat_id;
}
TLRPC.Message message = new_dialogMessage.get(dialog.top_message);
- SerializedData data = new SerializedData();
+ ByteBufferDesc data = buffersStorage.getFreeBuffer(message.getObjectSize());
message.serializeToStream(data);
state.bindInteger(1, message.id);
@@ -2774,8 +2804,7 @@ public class MessagesStorage {
state.bindInteger(3, (message.unread ? 0 : 1));
state.bindInteger(4, message.send_state);
state.bindInteger(5, message.date);
- byte[] bytes = data.toByteArray();
- state.bindByteArray(6, bytes);
+ state.bindByteBuffer(6, data.buffer);
state.bindInteger(7, (message.out ? 1 : 0));
state.bindInteger(8, 0);
state.step();
@@ -2791,9 +2820,10 @@ public class MessagesStorage {
state3.bindLong(1, message.id);
state3.bindInteger(2, uid);
state3.bindInteger(3, message.date);
- state3.bindByteArray(4, bytes);
+ state3.bindByteBuffer(4, data.buffer);
state3.step();
}
+ buffersStorage.reuseFreeBuffer(data);
}
state.dispose();
state2.dispose();
@@ -2804,7 +2834,7 @@ public class MessagesStorage {
SQLitePreparedStatement state = database.executeFast("REPLACE INTO users VALUES(?, ?, ?, ?)");
for (TLRPC.User user : dialogs.users) {
state.requery();
- SerializedData data = new SerializedData();
+ ByteBufferDesc data = buffersStorage.getFreeBuffer(user.getObjectSize());
user.serializeToStream(data);
state.bindInteger(1, user.id);
if (user.first_name != null && user.last_name != null) {
@@ -2818,8 +2848,9 @@ public class MessagesStorage {
} else {
state.bindInteger(3, 0);
}
- state.bindByteArray(4, data.toByteArray());
+ state.bindByteBuffer(4, data.buffer);
state.step();
+ buffersStorage.reuseFreeBuffer(data);
}
state.dispose();
}
@@ -2828,7 +2859,7 @@ public class MessagesStorage {
SQLitePreparedStatement state = database.executeFast("REPLACE INTO chats VALUES(?, ?, ?)");
for (TLRPC.Chat chat : dialogs.chats) {
state.requery();
- SerializedData data = new SerializedData();
+ ByteBufferDesc data = buffersStorage.getFreeBuffer(chat.getObjectSize());
chat.serializeToStream(data);
state.bindInteger(1, chat.id);
if (chat.title != null) {
@@ -2837,8 +2868,9 @@ public class MessagesStorage {
} else {
state.bindString(2, "");
}
- state.bindByteArray(3, data.toByteArray());
+ state.bindByteBuffer(3, data.buffer);
state.step();
+ buffersStorage.reuseFreeBuffer(data);
}
state.dispose();
}
@@ -2856,9 +2888,8 @@ public class MessagesStorage {
try {
SQLiteCursor cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, status FROM users WHERE uid = %d", user_id));
if (cursor.next()) {
- byte[] userData = cursor.byteArrayValue(0);
- if (userData != null) {
- SerializedData data = new SerializedData(userData);
+ ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
+ if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
user = (TLRPC.User) TLClassStore.Instance().TLdeserialize(data, data.readInt32());
if (user != null) {
if (user.status != null) {
@@ -2866,6 +2897,7 @@ public class MessagesStorage {
}
}
}
+ buffersStorage.reuseFreeBuffer(data);
}
cursor.dispose();
} catch (Exception e) {
@@ -2888,9 +2920,8 @@ public class MessagesStorage {
SQLiteCursor cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, status FROM users WHERE uid IN (%s)", uidsStr));
while (cursor.next()) {
- byte[] userData = cursor.byteArrayValue(0);
- if (userData != null) {
- SerializedData data = new SerializedData(userData);
+ ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
+ if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
TLRPC.User user = (TLRPC.User) TLClassStore.Instance().TLdeserialize(data, data.readInt32());
if (user != null) {
if (user.status != null) {
@@ -2899,12 +2930,15 @@ public class MessagesStorage {
users.add(user);
} else {
error[0] = true;
+ buffersStorage.reuseFreeBuffer(data);
break;
}
} else {
error[0] = true;
+ buffersStorage.reuseFreeBuffer(data);
break;
}
+ buffersStorage.reuseFreeBuffer(data);
}
cursor.dispose();
} catch (Exception e) {
@@ -2919,11 +2953,11 @@ public class MessagesStorage {
try {
SQLiteCursor cursor = database.queryFinalized(String.format(Locale.US, "SELECT data FROM chats WHERE uid = %d", chat_id));
if (cursor.next()) {
- byte[] chatData = cursor.byteArrayValue(0);
- if (chatData != null) {
- SerializedData data = new SerializedData(chatData);
+ ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
+ if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
chat = (TLRPC.Chat) TLClassStore.Instance().TLdeserialize(data, data.readInt32());
}
+ buffersStorage.reuseFreeBuffer(data);
}
cursor.dispose();
} catch (Exception e) {
@@ -2937,9 +2971,8 @@ public class MessagesStorage {
try {
SQLiteCursor cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, user, g, authkey, ttl FROM enc_chats WHERE uid = %d", chat_id));
if (cursor.next()) {
- byte[] chatData = cursor.byteArrayValue(0);
- if (chatData != null) {
- SerializedData data = new SerializedData(chatData);
+ ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
+ if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
chat = (TLRPC.EncryptedChat) TLClassStore.Instance().TLdeserialize(data, data.readInt32());
if (chat != null) {
chat.user_id = cursor.intValue(1);
@@ -2948,6 +2981,7 @@ public class MessagesStorage {
chat.ttl = cursor.intValue(4);
}
}
+ buffersStorage.reuseFreeBuffer(data);
}
cursor.dispose();
} catch (Exception e) {
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/NativeLoader.java b/TMessagesProj/src/main/java/org/telegram/android/NativeLoader.java
similarity index 98%
rename from TMessagesProj/src/main/java/org/telegram/messenger/NativeLoader.java
rename to TMessagesProj/src/main/java/org/telegram/android/NativeLoader.java
index 58a96607..ab7dc59c 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/NativeLoader.java
+++ b/TMessagesProj/src/main/java/org/telegram/android/NativeLoader.java
@@ -6,12 +6,14 @@
* Copyright Nikolai Kudashov, 2013-2014.
*/
-package org.telegram.messenger;
+package org.telegram.android;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.os.Build;
+import org.telegram.messenger.FileLog;
+
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/NotificationsService.java b/TMessagesProj/src/main/java/org/telegram/android/NotificationsService.java
similarity index 94%
rename from TMessagesProj/src/main/java/org/telegram/messenger/NotificationsService.java
rename to TMessagesProj/src/main/java/org/telegram/android/NotificationsService.java
index 0b8e145d..a790c798 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/NotificationsService.java
+++ b/TMessagesProj/src/main/java/org/telegram/android/NotificationsService.java
@@ -6,13 +6,14 @@
* Copyright Nikolai Kudashov, 2013-2014.
*/
-package org.telegram.messenger;
+package org.telegram.android;
import android.app.Service;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.IBinder;
+import org.telegram.messenger.FileLog;
import org.telegram.ui.ApplicationLoader;
public class NotificationsService extends Service {
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/ScreenReceiver.java b/TMessagesProj/src/main/java/org/telegram/android/ScreenReceiver.java
similarity index 77%
rename from TMessagesProj/src/main/java/org/telegram/messenger/ScreenReceiver.java
rename to TMessagesProj/src/main/java/org/telegram/android/ScreenReceiver.java
index b557d0e5..7a357627 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/ScreenReceiver.java
+++ b/TMessagesProj/src/main/java/org/telegram/android/ScreenReceiver.java
@@ -6,12 +6,14 @@
* Copyright Nikolai Kudashov, 2013-2014.
*/
-package org.telegram.messenger;
+package org.telegram.android;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
+import org.telegram.messenger.ConnectionsManager;
+import org.telegram.messenger.FileLog;
import org.telegram.ui.ApplicationLoader;
public class ScreenReceiver extends BroadcastReceiver {
@@ -19,13 +21,11 @@ public class ScreenReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
FileLog.e("tmessages", "screen off");
- if (ConnectionsManager.lastPauseTime == 0) {
- ConnectionsManager.lastPauseTime = System.currentTimeMillis();
- }
+ ConnectionsManager.getInstance().setAppPaused(true, true);
ApplicationLoader.isScreenOn = false;
} else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
FileLog.e("tmessages", "screen on");
- ConnectionsManager.resetLastPauseTime();
+ ConnectionsManager.getInstance().setAppPaused(false, true);
ApplicationLoader.isScreenOn = true;
}
}
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/SmsListener.java b/TMessagesProj/src/main/java/org/telegram/android/SmsListener.java
similarity index 92%
rename from TMessagesProj/src/main/java/org/telegram/messenger/SmsListener.java
rename to TMessagesProj/src/main/java/org/telegram/android/SmsListener.java
index 1a5a6f46..6489456b 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/SmsListener.java
+++ b/TMessagesProj/src/main/java/org/telegram/android/SmsListener.java
@@ -6,7 +6,7 @@
* Copyright Nikolai Kudashov, 2013.
*/
-package org.telegram.messenger;
+package org.telegram.android;
import android.content.BroadcastReceiver;
import android.content.Context;
@@ -15,6 +15,9 @@ import android.content.SharedPreferences;
import android.os.Bundle;
import android.telephony.SmsMessage;
+import org.telegram.messenger.FileLog;
+import org.telegram.messenger.NotificationCenter;
+
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -25,7 +28,7 @@ public class SmsListener extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")) {
- if (!Utilities.isWaitingForSms()) {
+ if (!AndroidUtilities.isWaitingForSms()) {
return;
}
Bundle bundle = intent.getExtras();
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/Action.java b/TMessagesProj/src/main/java/org/telegram/messenger/Action.java
index 69fdfca6..61ed9b70 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/Action.java
+++ b/TMessagesProj/src/main/java/org/telegram/messenger/Action.java
@@ -25,6 +25,4 @@ public class Action {
public void cancel() {
}
-
- public int state;
}
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/BuffersStorage.java b/TMessagesProj/src/main/java/org/telegram/messenger/BuffersStorage.java
index d0980378..5c39ae07 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/BuffersStorage.java
+++ b/TMessagesProj/src/main/java/org/telegram/messenger/BuffersStorage.java
@@ -18,6 +18,8 @@ public class BuffersStorage {
private final ArrayList freeBuffers16384;
private final ArrayList freeBuffers32768;
private final ArrayList freeBuffersBig;
+ private boolean isThreadSafe;
+ private final static Integer sync = 1;
private static volatile BuffersStorage Instance = null;
public static BuffersStorage getInstance() {
@@ -26,14 +28,15 @@ public class BuffersStorage {
synchronized (BuffersStorage.class) {
localInstance = Instance;
if (localInstance == null) {
- Instance = localInstance = new BuffersStorage();
+ Instance = localInstance = new BuffersStorage(true);
}
}
}
return localInstance;
}
- public BuffersStorage() {
+ public BuffersStorage(boolean threadSafe) {
+ isThreadSafe = threadSafe;
freeBuffers128 = new ArrayList();
freeBuffers1024 = new ArrayList();
freeBuffers4096 = new ArrayList();
@@ -44,91 +47,58 @@ public class BuffersStorage {
for (int a = 0; a < 5; a++) {
freeBuffers128.add(new ByteBufferDesc(128));
}
-// for (int a = 0; a < 5; a++) {
-// freeBuffers1024.add(new ByteBufferDesc(1024 + 200));
-// }
-// for (int a = 0; a < 2; a++) {
-// freeBuffers4096.add(new ByteBufferDesc(4096 + 200));
-// }
-// for (int a = 0; a < 2; a++) {
-// freeBuffers16384.add(new ByteBufferDesc(16384 + 200));
-// }
-// for (int a = 0; a < 2; a++) {
-// freeBuffers32768.add(new ByteBufferDesc(40000));
-// }
}
public ByteBufferDesc getFreeBuffer(int size) {
+ if (size <= 0) {
+ return null;
+ }
+ int byteCount = 0;
+ ArrayList arrayToGetFrom = null;
ByteBufferDesc buffer = null;
if (size <= 128) {
- synchronized (freeBuffers128) {
- if (freeBuffers128.size() > 0) {
- buffer = freeBuffers128.get(0);
- freeBuffers128.remove(0);
- }
- }
- if (buffer == null) {
- buffer = new ByteBufferDesc(128);
- FileLog.e("tmessages", "create new 128 buffer");
- }
+ arrayToGetFrom = freeBuffers128;
+ byteCount = 128;
} else if (size <= 1024 + 200) {
- synchronized (freeBuffers1024) {
- if (freeBuffers1024.size() > 0) {
- buffer = freeBuffers1024.get(0);
- freeBuffers1024.remove(0);
- }
- }
- if (buffer == null) {
- buffer = new ByteBufferDesc(1024 + 200);
- FileLog.e("tmessages", "create new 1024 buffer");
- }
+ arrayToGetFrom = freeBuffers1024;
+ byteCount = 1024 + 200;
} else if (size <= 4096 + 200) {
- synchronized (freeBuffers4096) {
- if (freeBuffers4096.size() > 0) {
- buffer = freeBuffers4096.get(0);
- freeBuffers4096.remove(0);
- }
- }
- if (buffer == null) {
- buffer = new ByteBufferDesc(4096 + 200);
- FileLog.e("tmessages", "create new 4096 buffer");
- }
+ arrayToGetFrom = freeBuffers4096;
+ byteCount = 4096 + 200;
} else if (size <= 16384 + 200) {
- synchronized (freeBuffers16384) {
- if (freeBuffers16384.size() > 0) {
- buffer = freeBuffers16384.get(0);
- freeBuffers16384.remove(0);
- }
- }
- if (buffer == null) {
- buffer = new ByteBufferDesc(16384 + 200);
- FileLog.e("tmessages", "create new 16384 buffer");
- }
+ arrayToGetFrom = freeBuffers16384;
+ byteCount = 16384 + 200;
} else if (size <= 40000) {
- synchronized (freeBuffers32768) {
- if (freeBuffers32768.size() > 0) {
- buffer = freeBuffers32768.get(0);
- freeBuffers32768.remove(0);
- }
- }
- if (buffer == null) {
- buffer = new ByteBufferDesc(40000);
- FileLog.e("tmessages", "create new 40000 buffer");
- }
+ arrayToGetFrom = freeBuffers32768;
+ byteCount = 40000;
} else if (size <= 280000) {
- synchronized (freeBuffersBig) {
- if (freeBuffersBig.size() > 0) {
- buffer = freeBuffersBig.get(0);
- freeBuffersBig.remove(0);
- }
- }
- if (buffer == null) {
- buffer = new ByteBufferDesc(280000);
- FileLog.e("tmessages", "create new big buffer");
- }
+ arrayToGetFrom = freeBuffersBig;
+ byteCount = 280000;
} else {
buffer = new ByteBufferDesc(size);
}
+
+ if (arrayToGetFrom != null) {
+ if (isThreadSafe) {
+ synchronized (sync) {
+ if (arrayToGetFrom.size() > 0) {
+ buffer = arrayToGetFrom.get(0);
+ arrayToGetFrom.remove(0);
+ }
+ }
+ } else {
+ if (arrayToGetFrom.size() > 0) {
+ buffer = arrayToGetFrom.get(0);
+ arrayToGetFrom.remove(0);
+ }
+ }
+
+ if (buffer == null) {
+ buffer = new ByteBufferDesc(byteCount);
+ FileLog.e("tmessages", "create new " + byteCount + " buffer");
+ }
+ }
+
buffer.buffer.limit(size).rewind();
return buffer;
}
@@ -137,40 +107,34 @@ public class BuffersStorage {
if (buffer == null) {
return;
}
+ int maxCount = 10;
+ ArrayList arrayToReuse = null;
if (buffer.buffer.capacity() == 128) {
- synchronized (freeBuffers128) {
- if (freeBuffers128.size() < 10) {
- freeBuffers128.add(buffer);
- }
- }
+ arrayToReuse = freeBuffers128;
} else if (buffer.buffer.capacity() == 1024 + 200) {
- synchronized (freeBuffers1024) {
- if (freeBuffers1024.size() < 10) {
- freeBuffers1024.add(buffer);
- }
- }
- } else if (buffer.buffer.capacity() == 4096 + 200) {
- synchronized (freeBuffers4096) {
- if (freeBuffers4096.size() < 10) {
- freeBuffers4096.add(buffer);
- }
- }
+ arrayToReuse = freeBuffers1024;
+ } if (buffer.buffer.capacity() == 4096 + 200) {
+ arrayToReuse = freeBuffers4096;
} else if (buffer.buffer.capacity() == 16384 + 200) {
- synchronized (freeBuffers16384) {
- if (freeBuffers16384.size() < 10) {
- freeBuffers16384.add(buffer);
- }
- }
+ arrayToReuse = freeBuffers16384;
} else if (buffer.buffer.capacity() == 40000) {
- synchronized (freeBuffers32768) {
- if (freeBuffers32768.size() < 10) {
- freeBuffers32768.add(buffer);
- }
- }
+ arrayToReuse = freeBuffers32768;
} else if (buffer.buffer.capacity() == 280000) {
- synchronized (freeBuffersBig) {
- if (freeBuffersBig.size() < 4) {
- freeBuffersBig.add(buffer);
+ arrayToReuse = freeBuffersBig;
+ maxCount = 10;
+ }
+ if (arrayToReuse != null) {
+ if (isThreadSafe) {
+ synchronized (sync) {
+ if (arrayToReuse.size() < maxCount) {
+ arrayToReuse.add(buffer);
+ } else {
+ FileLog.e("tmessages", "too more");
+ }
+ }
+ } else {
+ if (arrayToReuse.size() < maxCount) {
+ arrayToReuse.add(buffer);
}
}
}
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/ByteBufferDesc.java b/TMessagesProj/src/main/java/org/telegram/messenger/ByteBufferDesc.java
index 03653992..f36049bc 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/ByteBufferDesc.java
+++ b/TMessagesProj/src/main/java/org/telegram/messenger/ByteBufferDesc.java
@@ -25,6 +25,11 @@ public class ByteBufferDesc extends AbsSerializedData {
justCalc = calculate;
}
+ public ByteBufferDesc(byte[] bytes) {
+ buffer = ByteBuffer.wrap(bytes);
+ buffer.order(ByteOrder.LITTLE_ENDIAN);
+ }
+
public int position() {
return buffer.position();
}
@@ -397,11 +402,13 @@ public class ByteBufferDesc extends AbsSerializedData {
sl = 4;
}
ByteBufferDesc b = BuffersStorage.getInstance().getFreeBuffer(l);
- int old = buffer.limit();
- buffer.limit(buffer.position() + l);
- b.buffer.put(buffer);
- buffer.limit(old);
- b.buffer.position(0);
+ if (b != null) {
+ int old = buffer.limit();
+ buffer.limit(buffer.position() + l);
+ b.buffer.put(buffer);
+ buffer.limit(old);
+ b.buffer.position(0);
+ }
int i = sl;
while((l + i) % 4 != 0) {
buffer.get();
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/ConnectionsManager.java b/TMessagesProj/src/main/java/org/telegram/messenger/ConnectionsManager.java
index a35f2570..9d13b642 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/ConnectionsManager.java
+++ b/TMessagesProj/src/main/java/org/telegram/messenger/ConnectionsManager.java
@@ -14,13 +14,15 @@ import android.content.pm.PackageInfo;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build;
+import android.os.PowerManager;
import android.util.Base64;
+import org.telegram.android.ContactsController;
+import org.telegram.android.MessagesController;
import org.telegram.ui.ApplicationLoader;
import java.io.File;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.HashMap;
import java.util.Locale;
import java.util.concurrent.ConcurrentHashMap;
@@ -34,11 +36,10 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
private ArrayList destroyingSessions = new ArrayList();
private HashMap> quickAckIdToRequestIds = new HashMap>();
-
private HashMap pingIdToDate = new HashMap();
private ConcurrentHashMap> requestsByGuids = new ConcurrentHashMap>(100, 1.0f, 2);
private ConcurrentHashMap requestsByClass = new ConcurrentHashMap(100, 1.0f, 2);
- public volatile int connectionState = 2;
+ private volatile int connectionState = 2;
private ArrayList requestQueue = new ArrayList();
private ArrayList runningRequests = new ArrayList();
@@ -47,17 +48,17 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
private ArrayList unknownDatacenterIds = new ArrayList();
private ArrayList neededDatacenterIds = new ArrayList();
private ArrayList unauthorizedDatacenterIds = new ArrayList();
- final HashMap> genericMessagesToDatacenters = new HashMap>();
+ private final HashMap> genericMessagesToDatacenters = new HashMap>();
private TLRPC.TL_auth_exportedAuthorization movingAuthorization;
public static final int DEFAULT_DATACENTER_ID = Integer.MAX_VALUE;
- public static final int DC_UPDATE_TIME = 60 * 60;
- public int currentDatacenterId;
- public int movingToDatacenterId;
+ private static final int DC_UPDATE_TIME = 60 * 60;
+ protected int currentDatacenterId;
+ protected int movingToDatacenterId;
private long lastOutgoingMessageId = 0;
private int isTestBackend = 0;
- public int timeDifference = 0;
- public int currentPingTime;
+ private int timeDifference = 0;
+ private int currentPingTime;
private int lastDestroySessionRequestTime;
private boolean updatingDcSettings = false;
private int updatingDcStartTime = 0;
@@ -69,12 +70,17 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
private boolean paused = false;
private long lastPingTime = System.currentTimeMillis();
private long lastPushPingTime = 0;
+ private boolean pushMessagesReceived = true;
private boolean sendingPushPing = false;
private int nextSleepTimeout = 30000;
private long nextPingId = 0;
- public static long lastPauseTime = System.currentTimeMillis();
- public static boolean appPaused = true;
+ private long lastPauseTime = System.currentTimeMillis();
+ private boolean appPaused = true;
+
+ private volatile long nextCallToken = 1;
+
+ private PowerManager.WakeLock wakeLock = null;
private static volatile ConnectionsManager Instance = null;
public static ConnectionsManager getInstance() {
@@ -90,18 +96,18 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
return localInstance;
}
- static long t = System.currentTimeMillis();
private Runnable stageRunnable = new Runnable() {
@Override
public void run() {
Utilities.stageQueue.handler.removeCallbacks(stageRunnable);
- t = System.currentTimeMillis();
if (datacenters != null) {
- if (sendingPushPing && lastPushPingTime < System.currentTimeMillis() - 30000 || Math.abs(lastPushPingTime - System.currentTimeMillis()) > 60000 * 4) {
+ if (sendingPushPing && lastPushPingTime < System.currentTimeMillis() - 30000 || Math.abs(lastPushPingTime - System.currentTimeMillis()) > 60000 * 3 + 10000) {
lastPushPingTime = 0;
sendingPushPing = false;
+ FileLog.e("tmessages", "push ping timeout");
}
if (lastPushPingTime < System.currentTimeMillis() - 60000 * 3) {
+ FileLog.e("tmessages", "time for push ping");
lastPushPingTime = System.currentTimeMillis();
Datacenter datacenter = datacenterWithId(currentDatacenterId);
if (datacenter != null) {
@@ -112,16 +118,22 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
long currentTime = System.currentTimeMillis();
if (lastPauseTime != 0 && lastPauseTime < currentTime - nextSleepTimeout) {
- boolean dontSleep = false;
- for (RPCRequest request : runningRequests) {
- if (request.retryCount < 10 && (request.runningStartTime + 60 > (int)(currentTime / 1000)) && ((request.flags & RPCRequest.RPCRequestClassDownloadMedia) != 0 || (request.flags & RPCRequest.RPCRequestClassUploadMedia) != 0)) {
- dontSleep = true;
- break;
+ boolean dontSleep = !pushMessagesReceived;
+ if (!dontSleep) {
+ for (RPCRequest request : runningRequests) {
+ if (request.rawRequest instanceof TLRPC.TL_get_future_salts) {
+ dontSleep = true;
+ } else if (request.retryCount < 10 && (request.runningStartTime + 60 > (int) (currentTime / 1000)) && ((request.flags & RPCRequest.RPCRequestClassDownloadMedia) != 0 || (request.flags & RPCRequest.RPCRequestClassUploadMedia) != 0)) {
+ dontSleep = true;
+ break;
+ }
}
}
if (!dontSleep) {
for (RPCRequest request : requestQueue) {
- if ((request.flags & RPCRequest.RPCRequestClassDownloadMedia) != 0 || (request.flags & RPCRequest.RPCRequestClassUploadMedia) != 0) {
+ if (request.rawRequest instanceof TLRPC.TL_get_future_salts) {
+ dontSleep = true;
+ } else if ((request.flags & RPCRequest.RPCRequestClassDownloadMedia) != 0 || (request.flags & RPCRequest.RPCRequestClassUploadMedia) != 0) {
dontSleep = true;
break;
}
@@ -143,7 +155,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
}
} else {
lastPauseTime += 30 * 1000;
- FileLog.e("tmessages", "don't sleep 30 seconds because of upload or download request");
+ FileLog.e("tmessages", "don't sleep 30 seconds because of salt, upload or download request");
}
}
if (paused) {
@@ -199,20 +211,35 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
}
Utilities.stageQueue.postRunnable(stageRunnable, 1000);
+
+ PowerManager pm = (PowerManager)ApplicationLoader.applicationContext.getSystemService(Context.POWER_SERVICE);
+ wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "lock");
+ }
+
+ public int getConnectionState() {
+ return connectionState;
+ }
+
+ public void setConnectionState(int state) {
+ connectionState = state;
+ }
+
+ private void resumeNetworkInternal() {
+ if (paused) {
+ lastPauseTime = System.currentTimeMillis();
+ nextSleepTimeout = 30000;
+ FileLog.e("tmessages", "wakeup network in background");
+ } else if (lastPauseTime != 0) {
+ lastPauseTime = System.currentTimeMillis();
+ FileLog.e("tmessages", "reset sleep timeout");
+ }
}
public void resumeNetworkMaybe() {
Utilities.stageQueue.postRunnable(new Runnable() {
@Override
public void run() {
- if (paused) {
- lastPauseTime = System.currentTimeMillis();
- nextSleepTimeout = 30000;
- FileLog.e("tmessages", "wakeup network in background");
- } else if (lastPauseTime != 0) {
- lastPauseTime = System.currentTimeMillis();
- FileLog.e("tmessages", "reset sleep timeout");
- }
+ resumeNetworkInternal();
}
});
}
@@ -230,26 +257,39 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
});
}
- public static void resetLastPauseTime() {
- if (appPaused) {
- return;
- }
- FileLog.e("tmessages", "reset app pause time");
- if (lastPauseTime != 0 && System.currentTimeMillis() - lastPauseTime > 5000) {
- ContactsController.getInstance().checkContacts();
- }
- lastPauseTime = 0;
- ConnectionsManager.getInstance().applicationMovedToForeground();
+ public void setAppPaused(final boolean value, final boolean byScreenState) {
+ Utilities.stageQueue.postRunnable(new Runnable() {
+ @Override
+ public void run() {
+ if (!byScreenState) {
+ appPaused = value;
+ FileLog.e("tmessages", "app paused = " + value);
+ }
+ if (value) {
+ if (byScreenState) {
+ if (lastPauseTime == 0) {
+ lastPauseTime = System.currentTimeMillis();
+ }
+ } else {
+ lastPauseTime = System.currentTimeMillis();
+ }
+ } else {
+ if (appPaused) {
+ return;
+ }
+ FileLog.e("tmessages", "reset app pause time");
+ if (lastPauseTime != 0 && System.currentTimeMillis() - lastPauseTime > 5000) {
+ ContactsController.getInstance().checkContacts();
+ }
+ lastPauseTime = 0;
+ ConnectionsManager.getInstance().applicationMovedToForeground();
+ }
+ }
+ });
}
- public static void setAppPaused(boolean value) {
- appPaused = value;
- FileLog.e("tmessages", "app paused = " + value);
- if (!appPaused) {
- resetLastPauseTime();
- } else {
- lastPauseTime = System.currentTimeMillis();
- }
+ public long getPauseTime() {
+ return lastPauseTime;
}
//================================================================================
@@ -743,15 +783,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
}, null, true, RPCRequest.RPCRequestClassEnableUnauthorized | RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassWithoutLogin, dcNum == 0 ? currentDatacenterId : dcNum);
}
- public long performRpc(final TLObject rpc, final RPCRequest.RPCRequestDelegate completionBlock, final RPCRequest.RPCProgressDelegate progressBlock, boolean requiresCompletion, int requestClass) {
- return performRpc(rpc, completionBlock, progressBlock, requiresCompletion, requestClass, DEFAULT_DATACENTER_ID);
- }
-
- public long performRpc(final TLObject rpc, final RPCRequest.RPCRequestDelegate completionBlock, final RPCRequest.RPCProgressDelegate progressBlock, boolean requiresCompletion, int requestClass, int datacenterId) {
- return performRpc(rpc, completionBlock, progressBlock, null, requiresCompletion, requestClass, datacenterId);
- }
-
- TLObject wrapInLayer(TLObject object, int datacenterId, RPCRequest request) {
+ private TLObject wrapInLayer(TLObject object, int datacenterId, RPCRequest request) {
if (object.layer() > 0) {
Datacenter datacenter = datacenterWithId(datacenterId);
if (datacenter == null || datacenter.lastInitVersion != currentAppVersion) {
@@ -792,7 +824,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
}
object = invoke;
}
- TLRPC.invokeWithLayer12 invoke = new TLRPC.invokeWithLayer12();
+ TLRPC.invokeWithLayer14 invoke = new TLRPC.invokeWithLayer14();
invoke.query = object;
FileLog.d("wrap in layer", "" + object);
return invoke;
@@ -800,8 +832,19 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
return object;
}
- public static volatile long nextCallToken = 1;
- long performRpc(final TLObject rpc, final RPCRequest.RPCRequestDelegate completionBlock, final RPCRequest.RPCProgressDelegate progressBlock, final RPCRequest.RPCQuickAckDelegate quickAckBlock, final boolean requiresCompletion, final int requestClass, final int datacenterId) {
+ public long performRpc(final TLObject rpc, final RPCRequest.RPCRequestDelegate completionBlock) {
+ return performRpc(rpc, completionBlock, null, true, RPCRequest.RPCRequestClassGeneric, DEFAULT_DATACENTER_ID);
+ }
+
+ public long performRpc(final TLObject rpc, final RPCRequest.RPCRequestDelegate completionBlock, boolean requiresCompletion, int requestClass) {
+ return performRpc(rpc, completionBlock, null, requiresCompletion, requestClass, DEFAULT_DATACENTER_ID, true);
+ }
+
+ public long performRpc(final TLObject rpc, final RPCRequest.RPCRequestDelegate completionBlock, final RPCRequest.RPCQuickAckDelegate quickAckBlock, final boolean requiresCompletion, final int requestClass, final int datacenterId) {
+ return performRpc(rpc, completionBlock, quickAckBlock, requiresCompletion, requestClass, datacenterId, true);
+ }
+
+ public long performRpc(final TLObject rpc, final RPCRequest.RPCRequestDelegate completionBlock, final RPCRequest.RPCQuickAckDelegate quickAckBlock, final boolean requiresCompletion, final int requestClass, final int datacenterId, final boolean runQueue) {
if (!UserConfig.isClientActivated() && (requestClass & RPCRequest.RPCRequestClassWithoutLogin) == 0) {
FileLog.e("tmessages", "can't do request without login " + rpc);
return 0;
@@ -821,19 +864,14 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
request.rawRequest = rpc;
request.rpcRequest = wrapInLayer(rpc, datacenterId, request);
request.completionBlock = completionBlock;
- request.progressBlock = progressBlock;
request.quickAckBlock = quickAckBlock;
request.requiresCompletion = requiresCompletion;
requestQueue.add(request);
- if (paused && ((request.flags & RPCRequest.RPCRequestClassDownloadMedia) != 0 || (request.flags & RPCRequest.RPCRequestClassUploadMedia) != 0)) {
- lastPauseTime = System.currentTimeMillis();
- nextSleepTimeout = 30000;
- FileLog.e("tmessages", "wakeup by download or upload request");
+ if (runQueue) {
+ processRequestQueue(0, 0);
}
-
- processRequestQueue(0, 0);
}
});
@@ -876,7 +914,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
if (notifyServer) {
TLRPC.TL_rpc_drop_answer dropAnswer = new TLRPC.TL_rpc_drop_answer();
dropAnswer.req_msg_id = request.runningMessageId;
- performRpc(dropAnswer, null, null, false, request.flags);
+ performRpc(dropAnswer, null, false, request.flags);
}
}
@@ -1009,8 +1047,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
if ((request.flags & RPCRequest.RPCRequestClassGeneric) != 0) {
connection = requestDatacenter.getGenericConnection(this);
} else if ((request.flags & RPCRequest.RPCRequestClassDownloadMedia) != 0) {
- int num = (request.flags & RPCRequest.RPCRequestClassDownloadMedia2) != 0 ? 1 : 0;
- connection = requestDatacenter.getDownloadConnection(num, this);
+ connection = requestDatacenter.getDownloadConnection(this);
} else if ((request.flags & RPCRequest.RPCRequestClassUploadMedia) != 0 ) {
connection = requestDatacenter.getUploadConnection(this);
}
@@ -1026,7 +1063,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
maxTimeout = 30.0f;
}
- boolean forceThisRequest = (request.flags & requestClass) != 0 && (_datacenterId == Integer.MIN_VALUE || requestDatacenter.datacenterId == _datacenterId);
+ boolean forceThisRequest = (request.flags & requestClass) != 0 && requestDatacenter.datacenterId == _datacenterId;
if (request.rawRequest instanceof TLRPC.TL_get_future_salts || request.rawRequest instanceof TLRPC.TL_destroy_session) {
if (request.runningMessageId != 0) {
@@ -1177,8 +1214,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
if ((request.flags & RPCRequest.RPCRequestClassGeneric) != 0) {
connection = requestDatacenter.getGenericConnection(this);
} else if ((request.flags & RPCRequest.RPCRequestClassDownloadMedia) != 0) {
- int num = (request.flags & RPCRequest.RPCRequestClassDownloadMedia2) != 0 ? 1 : 0;
- connection = requestDatacenter.getDownloadConnection(num, this);
+ connection = requestDatacenter.getDownloadConnection(this);
} else if ((request.flags & RPCRequest.RPCRequestClassUploadMedia) != 0) {
connection = requestDatacenter.getUploadConnection(this);
}
@@ -1341,29 +1377,14 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
}
}
- if (datacenter.connection == null) {
- datacenter.connection = new TcpConnection(datacenter.datacenterId);
- datacenter.connection.delegate = this;
- datacenter.connection.transportRequestClass = RPCRequest.RPCRequestClassGeneric;
- }
-
- proceedToSendingMessages(arr, datacenter.connection, hasSendMessage);
+ proceedToSendingMessages(arr, datacenter.getGenericConnection(this), hasSendMessage);
}
}
if ((requestClass & RPCRequest.RPCRequestClassGeneric) != 0) {
- if (_datacenterId == Integer.MIN_VALUE) {
- for (Datacenter datacenter : datacenters.values()) {
- ArrayList messagesIt = genericMessagesToDatacenters.get(datacenter.datacenterId);
- if (messagesIt == null || messagesIt.size() == 0) {
- generatePing(datacenter, false);
- }
- }
- } else {
- ArrayList messagesIt = genericMessagesToDatacenters.get(_datacenterId);
- if (messagesIt == null || messagesIt.size() == 0) {
- generatePing();
- }
+ ArrayList messagesIt = genericMessagesToDatacenters.get(_datacenterId);
+ if (messagesIt == null || messagesIt.size() == 0) {
+ generatePing();
}
}
@@ -1501,7 +1522,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
}
}
- connection.sendData(null, transportData, reportAck);
+ connection.sendData(transportData, true, reportAck);
} else {
FileLog.e("tmessages", "***** Transport data is nil");
}
@@ -1527,12 +1548,12 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
TLRPC.TL_protoMessage message = networkMessage.protoMessage;
if (BuildVars.DEBUG_VERSION) {
- if (message.body instanceof TLRPC.invokeWithLayer12) {
- FileLog.d("tmessages", connection.getSissionId() + ":DC" + datacenter.datacenterId + "> Send message (" + message.seqno + ", " + message.msg_id + "): " + ((TLRPC.invokeWithLayer12)message.body).query);
+ if (message.body instanceof TLRPC.invokeWithLayer14) {
+ FileLog.d("tmessages", connection.getSissionId() + ":DC" + datacenter.datacenterId + "> Send message (" + message.seqno + ", " + message.msg_id + "): " + ((TLRPC.invokeWithLayer14)message.body).query);
} else if (message.body instanceof TLRPC.initConnection) {
TLRPC.initConnection r = (TLRPC.initConnection)message.body;
- if (r.query instanceof TLRPC.invokeWithLayer12) {
- FileLog.d("tmessages", connection.getSissionId() + ":DC" + datacenter.datacenterId + "> Send message (" + message.seqno + ", " + message.msg_id + "): " + ((TLRPC.invokeWithLayer12)r.query).query);
+ if (r.query instanceof TLRPC.invokeWithLayer14) {
+ FileLog.d("tmessages", connection.getSissionId() + ":DC" + datacenter.datacenterId + "> Send message (" + message.seqno + ", " + message.msg_id + "): " + ((TLRPC.invokeWithLayer14)r.query).query);
} else {
FileLog.d("tmessages", connection.getSissionId() + ":DC" + datacenter.datacenterId + "> Send message (" + message.seqno + ", " + message.msg_id + "): " + r.query);
}
@@ -1567,12 +1588,12 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
TLRPC.TL_protoMessage message = networkMessage.protoMessage;
containerMessages.add(message);
if (BuildVars.DEBUG_VERSION) {
- if (message.body instanceof TLRPC.invokeWithLayer12) {
- FileLog.d("tmessages", connection.getSissionId() + ":DC" + datacenter.datacenterId + "> Send message (" + message.seqno + ", " + message.msg_id + "): " + ((TLRPC.invokeWithLayer12)message.body).query);
+ if (message.body instanceof TLRPC.invokeWithLayer14) {
+ FileLog.d("tmessages", connection.getSissionId() + ":DC" + datacenter.datacenterId + "> Send message (" + message.seqno + ", " + message.msg_id + "): " + ((TLRPC.invokeWithLayer14)message.body).query);
} else if (message.body instanceof TLRPC.initConnection) {
TLRPC.initConnection r = (TLRPC.initConnection)message.body;
- if (r.query instanceof TLRPC.invokeWithLayer12) {
- FileLog.d("tmessages", connection.getSissionId() + ":DC" + datacenter.datacenterId + "> Send message (" + message.seqno + ", " + message.msg_id + "): " + ((TLRPC.invokeWithLayer12)r.query).query);
+ if (r.query instanceof TLRPC.invokeWithLayer14) {
+ FileLog.d("tmessages", connection.getSissionId() + ":DC" + datacenter.datacenterId + "> Send message (" + message.seqno + ", " + message.msg_id + "): " + ((TLRPC.invokeWithLayer14)r.query).query);
} else {
FileLog.d("tmessages", connection.getSissionId() + ":DC" + datacenter.datacenterId + "> Send message (" + message.seqno + ", " + message.msg_id + "): " + r.query);
}
@@ -1625,13 +1646,14 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
ByteBufferDesc dataForEncryption = BuffersStorage.getInstance().getFreeBuffer(innerOs.limit() + zeroCount);
dataForEncryption.writeRaw(innerOs);
BuffersStorage.getInstance().reuseFreeBuffer(innerOs);
- byte[] b = new byte[1];
- for (int a = 0; a < zeroCount; a++) {
+
+ if (zeroCount != 0) {
+ byte[] b = new byte[zeroCount];
Utilities.random.nextBytes(b);
- dataForEncryption.writeByte(b[0]);
+ dataForEncryption.writeRaw(b);
}
- Utilities.aesIgeEncryption2(dataForEncryption.buffer, keyData.aesKey, keyData.aesIv, true, false, dataForEncryption.limit());
+ Utilities.aesIgeEncryption(dataForEncryption.buffer, keyData.aesKey, keyData.aesIv, true, false, 0, dataForEncryption.limit());
ByteBufferDesc data = BuffersStorage.getInstance().getFreeBuffer(8 + messageKey.length + dataForEncryption.limit());
data.writeInt64(datacenter.authKeyId);
@@ -1645,18 +1667,24 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
void refillSaltSet(final Datacenter datacenter) {
for (RPCRequest request : requestQueue) {
if (request.rawRequest instanceof TLRPC.TL_get_future_salts) {
- return;
+ Datacenter requestDatacenter = datacenterWithId(request.runningDatacenterId);
+ if (requestDatacenter.datacenterId == datacenter.datacenterId) {
+ return;
+ }
}
}
for (RPCRequest request : runningRequests) {
if (request.rawRequest instanceof TLRPC.TL_get_future_salts) {
- return;
+ Datacenter requestDatacenter = datacenterWithId(request.runningDatacenterId);
+ if (requestDatacenter.datacenterId == datacenter.datacenterId) {
+ return;
+ }
}
}
TLRPC.TL_get_future_salts getFutureSalts = new TLRPC.TL_get_future_salts();
- getFutureSalts.num = 64;
+ getFutureSalts.num = 32;
performRpc(getFutureSalts, new RPCRequest.RPCRequestDelegate() {
@Override
@@ -1759,7 +1787,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
}
registeringForPush = false;
}
- }, null, true, RPCRequest.RPCRequestClassGeneric);
+ }, true, RPCRequest.RPCRequestClassGeneric);
}
}
@@ -1860,6 +1888,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
pingIdToDate.remove(pid);
}
} else {
+ FileLog.e("tmessages", "received push ping");
sendingPushPing = false;
}
} else if (message instanceof TLRPC.TL_futuresalts) {
@@ -2038,6 +2067,12 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
isError = true;
request.completionBlock.run(null, implicitError != null ? implicitError : (TLRPC.TL_error) resultContainer.result);
} else {
+ if (resultContainer.result instanceof TLRPC.updates_Difference) {
+ pushMessagesReceived = true;
+ if (wakeLock.isHeld()) {
+ wakeLock.release();
+ }
+ }
request.completionBlock.run(resultContainer.result, null);
}
}
@@ -2195,8 +2230,18 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
} else if (message instanceof TLRPC.Updates) {
if ((connection.transportRequestClass & RPCRequest.RPCRequestClassPush) != 0) {
FileLog.e("tmessages", "received internal push");
- resumeNetworkMaybe();
+ if (paused) {
+ pushMessagesReceived = false;
+ }
+ if (!wakeLock.isHeld()) {
+ wakeLock.acquire(20000);
+ }
+ resumeNetworkInternal();
} else {
+ pushMessagesReceived = true;
+ if (wakeLock.isHeld()) {
+ wakeLock.release();
+ }
MessagesController.getInstance().processUpdates((TLRPC.Updates) message, false);
}
} else {
@@ -2255,156 +2300,18 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
ByteBufferDesc transportData = generatePingData(connection);
if (transportData != null) {
if (push) {
+ FileLog.e("tmessages", "send push ping");
sendingPushPing = true;
}
- connection.sendData(null, transportData, false);
+ connection.sendData(transportData, true, false);
}
}
}
- public long needsToDecodeMessageIdFromPartialData(TcpConnection connection, byte[] data) {
- if (data == null) {
- return -1;
- }
-
- Datacenter datacenter = datacenters.get(connection.getDatacenterId());
- SerializedData is = new SerializedData(data);
-
- byte[] keyId = is.readData(8);
- SerializedData keyIdData = new SerializedData(keyId);
- long key = keyIdData.readInt64();
- if (key == 0) {
- return -1;
- } else {
- if (datacenter.authKeyId == 0 || key != datacenter.authKeyId) {
- FileLog.e("tmessages", "Error: invalid auth key id " + connection);
- return -1;
- }
-
- byte[] messageKey = is.readData(16);
- MessageKeyData keyData = Utilities.generateMessageKeyData(datacenter.authKey, messageKey, true);
-
- byte[] messageData = is.readData(data.length - 24);
- messageData = Utilities.aesIgeEncryption(messageData, keyData.aesKey, keyData.aesIv, false, false, 0);
-
- if (messageData == null) {
- return -1;
- }
-
- SerializedData messageIs = new SerializedData(messageData);
- long messageServerSalt = messageIs.readInt64();
- long messageSessionId = messageIs.readInt64();
-
- if (messageSessionId != connection.getSissionId()) {
- FileLog.e("tmessages", String.format("***** Error: invalid message session ID (%d instead of %d)", messageSessionId, connection.getSissionId()));
- finishUpdatingState(connection);
- return -1;
- }
-
- long messageId = messageIs.readInt64();
- int messageSeqNo = messageIs.readInt32();
- int messageLength = messageIs.readInt32();
-
- boolean[] stop = new boolean[1];
- long[] reqMsgId = new long[1];
- stop[0] = false;
- reqMsgId[0] = 0;
-
- while (!stop[0] && reqMsgId[0] == 0) {
- int signature = messageIs.readInt32(stop);
- if (stop[0]) {
- break;
- }
- findReqMsgId(messageIs, signature, reqMsgId, stop);
- }
-
- return reqMsgId[0];
- }
- }
-
- private void findReqMsgId(SerializedData is, int signature, long[] reqMsgId, boolean[] failed) {
- if (signature == 0x73f1f8dc) {
- if (is.length() < 4) {
- failed[0] = true;
- return;
- }
- int count = is.readInt32(failed);
- if (failed[0]) {
- return;
- }
-
- for (int i = 0; i < count; i++) {
- is.readInt64(failed);
- if (failed[0]) {
- return;
- }
- is.readInt32(failed);
- if (failed[0]) {
- return;
- }
- is.readInt32(failed);
- if (failed[0]) {
- return;
- }
-
- int innerSignature = is.readInt32(failed);
- if (failed[0]) {
- return;
- }
-
- findReqMsgId(is, innerSignature, reqMsgId, failed);
- if (failed[0] || reqMsgId[0] != 0) {
- return;
- }
- }
- } else if (signature == 0xf35c6d01) {
- long value = is.readInt64(failed);
- if (failed[0]) {
- return;
- }
- reqMsgId[0] = value;
- } else if (signature == 0x62d6b459) {
- is.readInt32(failed);
- if (failed[0]) {
- return;
- }
-
- int count = is.readInt32(failed);
- if (failed[0]) {
- return;
- }
-
- for (int i = 0; i < count; i++) {
- is.readInt32(failed);
- if (failed[0]) {
- return;
- }
- }
- } else if (signature == 0x347773c5) {
- is.readInt64(failed);
- if (failed[0]) {
- return;
- }
- is.readInt64(failed);
- }
- }
-
//================================================================================
// TCPConnection delegate
//================================================================================
- @Override
- public void tcpConnectionProgressChanged(TcpConnection connection, long messageId, int currentSize, int length) {
- for (RPCRequest request : runningRequests) {
- if (request.respondsToMessageId(messageId)) {
- if (request.progressBlock != null) {
- request.progressBlock.progress(length, currentSize);
- }
- break;
- }
- }
- }
-
@Override
public void tcpConnectionClosed(TcpConnection connection) {
if (connection.getDatacenterId() == currentDatacenterId && (connection.transportRequestClass & RPCRequest.RPCRequestClassGeneric) != 0) {
@@ -2440,7 +2347,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
});
} else if ((connection.transportRequestClass & RPCRequest.RPCRequestClassPush) != 0) {
sendingPushPing = false;
- lastPushPingTime = System.currentTimeMillis() - 60000 * 3 + 5000;
+ lastPushPingTime = System.currentTimeMillis() - 60000 * 3 + 4000;
}
}
@@ -2450,10 +2357,11 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
if (datacenter.authKey != null) {
if ((connection.transportRequestClass & RPCRequest.RPCRequestClassPush) != 0) {
sendingPushPing = false;
- lastPushPingTime = System.currentTimeMillis() - 60000 * 3 + 10000;
+ lastPushPingTime = System.currentTimeMillis() - 60000 * 3 + 4000;
} else {
- if (paused && connection.getDatacenterId() == currentDatacenterId && (connection.transportRequestClass & RPCRequest.RPCRequestClassGeneric) != 0) {
- resumeNetworkMaybe();
+ if (paused && lastPauseTime != 0) {
+ lastPauseTime = System.currentTimeMillis();
+ nextSleepTimeout = 30000;
}
processRequestQueue(connection.transportRequestClass, connection.getDatacenterId());
}
@@ -2541,11 +2449,8 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
byte[] messageKey = data.readData(16);
MessageKeyData keyData = Utilities.generateMessageKeyData(datacenter.authKey, messageKey, true);
- data.compact();
- data.limit(data.position());
- data.position(0);
- Utilities.aesIgeEncryption2(data.buffer, keyData.aesKey, keyData.aesIv, false, false, length - 24);
+ Utilities.aesIgeEncryption(data.buffer, keyData.aesKey, keyData.aesIv, false, false, data.position(), length - 24);
long messageServerSalt = data.readInt64();
long messageSessionId = data.readInt64();
@@ -2570,14 +2475,12 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
connection.addMessageToConfirm(messageId);
}
- byte[] realMessageKeyFull = Utilities.computeSHA1(data.buffer, 0, Math.min(messageLength + 32, data.limit()));
+ byte[] realMessageKeyFull = Utilities.computeSHA1(data.buffer, 24, Math.min(messageLength + 32 + 24, data.limit()));
if (realMessageKeyFull == null) {
return;
}
- byte[] realMessageKey = new byte[16];
- System.arraycopy(realMessageKeyFull, realMessageKeyFull.length - 16, realMessageKey, 0, 16);
- if (!Arrays.equals(messageKey, realMessageKey)) {
+ if (!Utilities.arraysEquals(messageKey, 0, realMessageKeyFull, realMessageKeyFull.length - 16)) {
FileLog.e("tmessages", "***** Error: invalid message key");
connection.suspendConnection(true);
connection.connect();
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/Datacenter.java b/TMessagesProj/src/main/java/org/telegram/messenger/Datacenter.java
index 43fa8428..4c191412 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/Datacenter.java
+++ b/TMessagesProj/src/main/java/org/telegram/messenger/Datacenter.java
@@ -35,7 +35,7 @@ public class Datacenter {
private volatile int currentAddressNum = 0;
public TcpConnection connection;
- private ArrayList downloadConnections = new ArrayList();
+ private TcpConnection downloadConnection;
private TcpConnection uploadConnection;
public TcpConnection pushConnection;
@@ -327,7 +327,7 @@ public class Datacenter {
if (uploadConnection != null) {
uploadConnection.suspendConnection(true);
}
- for (TcpConnection downloadConnection : downloadConnections) {
+ if (downloadConnection != null) {
downloadConnection.suspendConnection(true);
}
}
@@ -339,7 +339,7 @@ public class Datacenter {
if (uploadConnection != null) {
sessions.add(uploadConnection.getSissionId());
}
- for (TcpConnection downloadConnection : downloadConnections) {
+ if (downloadConnection != null) {
sessions.add(downloadConnection.getSissionId());
}
}
@@ -351,26 +351,21 @@ public class Datacenter {
if (uploadConnection != null) {
uploadConnection.recreateSession();
}
- for (TcpConnection downloadConnection : downloadConnections) {
+ if (downloadConnection != null) {
downloadConnection.recreateSession();
}
}
- public TcpConnection getDownloadConnection(int num, TcpConnection.TcpConnectionDelegate delegate) {
- if (num >= 0 && authKey != null) {
- TcpConnection downloadConnection = null;
- if (num < downloadConnections.size()) {
- downloadConnection = downloadConnections.get(num);
- } else {
+ public TcpConnection getDownloadConnection(TcpConnection.TcpConnectionDelegate delegate) {
+ if (authKey != null) {
+ if (downloadConnection == null) {
downloadConnection = new TcpConnection(datacenterId);
downloadConnection.delegate = delegate;
downloadConnection.transportRequestClass = RPCRequest.RPCRequestClassDownloadMedia;
- downloadConnections.add(downloadConnection);
}
downloadConnection.connect();
- return downloadConnection;
}
- return null;
+ return downloadConnection;
}
public TcpConnection getUploadConnection(TcpConnection.TcpConnectionDelegate delegate) {
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/ExportAuthorizationAction.java b/TMessagesProj/src/main/java/org/telegram/messenger/ExportAuthorizationAction.java
index be79765a..51367696 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/ExportAuthorizationAction.java
+++ b/TMessagesProj/src/main/java/org/telegram/messenger/ExportAuthorizationAction.java
@@ -54,7 +54,7 @@ public class ExportAuthorizationAction extends Action {
}
}
}
- }, null, true, RPCRequest.RPCRequestClassGeneric);
+ });
}
void beginImport() {
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/FileLoadOperation.java b/TMessagesProj/src/main/java/org/telegram/messenger/FileLoadOperation.java
index cd577fba..f436b116 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/FileLoadOperation.java
+++ b/TMessagesProj/src/main/java/org/telegram/messenger/FileLoadOperation.java
@@ -10,9 +10,9 @@ package org.telegram.messenger;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
-import android.os.Build;
import android.provider.MediaStore;
+import org.telegram.android.AndroidUtilities;
import org.telegram.ui.ApplicationLoader;
import java.io.RandomAccessFile;
@@ -22,10 +22,19 @@ import java.io.FileInputStream;
import java.io.InputStream;
import java.net.URLConnection;
import java.nio.channels.FileChannel;
+import java.util.ArrayList;
import java.util.Scanner;
public class FileLoadOperation {
- private int downloadChunkSize = 1024 * 256;
+
+ private static class RequestInfo {
+ private long requestToken = 0;
+ private int offset = 0;
+ private TLRPC.TL_upload_file response = null;
+ }
+
+ private final static int downloadChunkSize = 1024 * 32;
+ private final static int maxDownloadRequests = 3;
public int datacenter_id;
public TLRPC.InputFileLocation location;
@@ -37,14 +46,10 @@ public class FileLoadOperation {
public String filter;
private byte[] key;
private byte[] iv;
- private long requestToken = 0;
- private long requestToken2 = 0;
- private int requestProgress = 0;
- private int requestProgress2 = 0;
+
private int nextDownloadOffset = 0;
- private TLRPC.TL_upload_file delayedRes = null;
- private int delayedResOffset = 0;
- private int delayedResTokenNum = 0;
+ private ArrayList requestInfos = new ArrayList(maxDownloadRequests);
+ private ArrayList delayedRequestInfos = new ArrayList(maxDownloadRequests - 1);
private File cacheFileTemp;
private File cacheFileFinal;
@@ -56,7 +61,7 @@ public class FileLoadOperation {
public boolean needBitmapCreate = true;
private InputStream httpConnectionStream;
private RandomAccessFile fileOutputStream;
- RandomAccessFile fiv;
+ private RandomAccessFile fiv;
public static interface FileLoadOperationDelegate {
public abstract void didFinishLoadingFile(FileLoadOperation operation);
@@ -214,7 +219,7 @@ public class FileLoadOperation {
if (isLocalFile) {
cacheFileFinal = new File(fileNameFinal);
} else {
- cacheFileFinal = new File(Utilities.getCacheDir(), fileNameFinal);
+ cacheFileFinal = new File(AndroidUtilities.getCacheDir(), fileNameFinal);
}
final boolean dontDelete = isLocalFile;
final Long mediaIdFinal = mediaId;
@@ -245,8 +250,8 @@ public class FileLoadOperation {
float h_filter = 0;
if (filter != null) {
String args[] = filter.split("_");
- w_filter = Float.parseFloat(args[0]) * Utilities.density;
- h_filter = Float.parseFloat(args[1]) * Utilities.density;
+ w_filter = Float.parseFloat(args[0]) * AndroidUtilities.density;
+ h_filter = Float.parseFloat(args[1]) * AndroidUtilities.density;
opts.inJustDecodeBounds = true;
if (mediaIdFinal != null) {
@@ -289,11 +294,9 @@ public class FileLoadOperation {
float bitmapH = image.getHeight();
if (bitmapW != w_filter && bitmapW > w_filter) {
float scaleFactor = bitmapW / w_filter;
- Bitmap scaledBitmap = Bitmap.createScaledBitmap(image, (int)w_filter, (int)(bitmapH / scaleFactor), false);
+ Bitmap scaledBitmap = Bitmap.createScaledBitmap(image, (int)w_filter, (int)(bitmapH / scaleFactor), true);
if (image != scaledBitmap) {
- if (Build.VERSION.SDK_INT < 11) {
- image.recycle();
- }
+ image.recycle();
image = scaledBitmap;
}
}
@@ -339,13 +342,13 @@ public class FileLoadOperation {
});
return;
}
- cacheFileTemp = new File(Utilities.getCacheDir(), fileNameTemp);
+ cacheFileTemp = new File(AndroidUtilities.getCacheDir(), fileNameTemp);
if (cacheFileTemp.exists()) {
downloadedBytes = (int)cacheFileTemp.length();
nextDownloadOffset = downloadedBytes = downloadedBytes / 1024 * 1024;
}
if (fileNameIv != null) {
- cacheIvTemp = new File(Utilities.getCacheDir(), fileNameIv);
+ cacheIvTemp = new File(AndroidUtilities.getCacheDir(), fileNameIv);
try {
fiv = new RandomAccessFile(cacheIvTemp, "rws");
long len = cacheIvTemp.length();
@@ -383,27 +386,44 @@ public class FileLoadOperation {
if (httpUrl != null) {
startDownloadHTTPRequest();
} else {
- if (totalBytesCount >= 1024 * 1024) {
- downloadChunkSize = 1024 * 256;
- } else {
- downloadChunkSize = 1024 * 32;
- }
- startDownloadRequest();
+ Utilities.stageQueue.postRunnable(new Runnable() {
+ @Override
+ public void run() {
+ if (totalBytesCount != 0 && downloadedBytes == totalBytesCount) {
+ try {
+ onFinishLoadingFile();
+ } catch (Exception e) {
+ delegate.didFailedLoadingFile(FileLoadOperation.this);
+ }
+ } else {
+ startDownloadRequest();
+ }
+ }
+ });
+
}
}
}
public void cancel() {
- if (state != 1) {
- return;
- }
- state = 2;
- cleanup();
- if (httpUrl == null) {
- ConnectionsManager.getInstance().cancelRpc(requestToken, true);
- ConnectionsManager.getInstance().cancelRpc(requestToken2, true);
- }
- delegate.didFailedLoadingFile(FileLoadOperation.this);
+ Utilities.stageQueue.postRunnable(new Runnable() {
+ @Override
+ public void run() {
+ if (state != 1) {
+ return;
+ }
+ state = 2;
+ cleanup();
+ if (httpUrl == null) {
+ for (RequestInfo requestInfo : requestInfos) {
+ if (requestInfo.requestToken != 0) {
+ ConnectionsManager.getInstance().cancelRpc(requestInfo.requestToken, true, true);
+ }
+ }
+ }
+ delegate.didFailedLoadingFile(FileLoadOperation.this);
+ }
+ });
}
private void cleanup() {
@@ -435,11 +455,12 @@ public class FileLoadOperation {
} catch (Exception e) {
FileLog.e("tmessages", e);
}
-
- if (delayedRes != null) {
- delayedRes.disableFree = false;
- delayedRes.freeResources();
- delayedRes = null;
+ for (RequestInfo requestInfo : delayedRequestInfos) {
+ if (requestInfo.response != null) {
+ requestInfo.response.disableFree = false;
+ requestInfo.response.freeResources();
+ requestInfo.response = null;
+ }
}
}
}
@@ -454,7 +475,6 @@ public class FileLoadOperation {
cacheIvTemp.delete();
}
final boolean renamed = cacheFileTemp.renameTo(cacheFileFinal);
-
if (needBitmapCreate) {
FileLoader.cacheOutQueue.postRunnable(new Runnable() {
@Override
@@ -476,8 +496,8 @@ public class FileLoadOperation {
float h_filter;
if (filter != null) {
String args[] = filter.split("_");
- w_filter = Float.parseFloat(args[0]) * Utilities.density;
- h_filter = Float.parseFloat(args[1]) * Utilities.density;
+ w_filter = Float.parseFloat(args[0]) * AndroidUtilities.density;
+ h_filter = Float.parseFloat(args[1]) * AndroidUtilities.density;
opts.inJustDecodeBounds = true;
BitmapFactory.decodeFile(cacheFileFinal.getAbsolutePath(), opts);
@@ -514,11 +534,9 @@ public class FileLoadOperation {
float bitmapH = image.getHeight();
if (bitmapW != w_filter && bitmapW > w_filter) {
float scaleFactor = bitmapW / w_filter;
- Bitmap scaledBitmap = Bitmap.createScaledBitmap(image, (int) w_filter, (int) (bitmapH / scaleFactor), false);
+ Bitmap scaledBitmap = Bitmap.createScaledBitmap(image, (int) w_filter, (int) (bitmapH / scaleFactor), true);
if (image != scaledBitmap) {
- if (Build.VERSION.SDK_INT < 11) {
- image.recycle();
- }
+ image.recycle();
image = scaledBitmap;
}
}
@@ -612,57 +630,49 @@ public class FileLoadOperation {
}
}
- private void processRequestResult(TLRPC.TL_upload_file res, TLRPC.TL_error error, int dowloadOffset, int tokenNum) {
+ private void processRequestResult(RequestInfo requestInfo, TLRPC.TL_error error) {
+ requestInfos.remove(requestInfo);
if (error == null) {
try {
- if (downloadedBytes != dowloadOffset) {
- if (delayedRes != null) {
- FileLog.e("tmessages", "something went wrong!");
- }
- delayedRes = res;
- delayedRes.disableFree = true;
- delayedResOffset = dowloadOffset;
- delayedResTokenNum = tokenNum;
+ if (downloadedBytes != requestInfo.offset) {
+ delayedRequestInfos.add(requestInfo);
+ requestInfo.response.disableFree = true;
return;
- } else {
- if (tokenNum == 0) {
- requestToken = 0;
- } else if (tokenNum == 1) {
- requestToken2 = 0;
- }
}
- if (res.bytes.limit() == 0) {
+ if (requestInfo.response.bytes.limit() == 0) {
onFinishLoadingFile();
return;
}
if (key != null) {
- Utilities.aesIgeEncryption2(res.bytes.buffer, key, iv, false, true, res.bytes.limit());
+ Utilities.aesIgeEncryption(requestInfo.response.bytes.buffer, key, iv, false, true, 0, requestInfo.response.bytes.limit());
}
if (fileOutputStream != null) {
FileChannel channel = fileOutputStream.getChannel();
- channel.write(res.bytes.buffer);
+ channel.write(requestInfo.response.bytes.buffer);
}
if (fiv != null) {
fiv.seek(0);
fiv.write(iv);
}
- downloadedBytes += res.bytes.limit();
+ downloadedBytes += requestInfo.response.bytes.limit();
if (totalBytesCount > 0 && state == 1) {
delegate.didChangedLoadProgress(FileLoadOperation.this, Math.min(1.0f, (float)downloadedBytes / (float)totalBytesCount));
}
- if(delayedRes != null && res != delayedRes) {
- TLRPC.TL_upload_file temp = delayedRes;
- processRequestResult(temp, null, delayedResOffset, delayedResTokenNum);
- if (delayedRes != null) {
- delayedRes.disableFree = false;
- delayedRes.freeResources();
- delayedRes = null;
+ for (int a = 0; a < delayedRequestInfos.size(); a++) {
+ RequestInfo delayedRequestInfo = delayedRequestInfos.get(a);
+ if (downloadedBytes == delayedRequestInfo.offset) {
+ delayedRequestInfos.remove(a);
+ processRequestResult(delayedRequestInfo, null);
+ delayedRequestInfo.response.disableFree = false;
+ delayedRequestInfo.response.freeResources();
+ delayedRequestInfo = null;
+ break;
}
}
- if (downloadedBytes % downloadChunkSize == 0 || totalBytesCount > 0 && totalBytesCount != downloadedBytes) {
+ if (downloadedBytes % downloadChunkSize == 0 || totalBytesCount > 0 && totalBytesCount > downloadedBytes) {
startDownloadRequest();
} else {
onFinishLoadingFile();
@@ -714,69 +724,36 @@ public class FileLoadOperation {
}
}
- private void processRequestProgress() {
- delegate.didChangedLoadProgress(FileLoadOperation.this, Math.min(1.0f, (float) (downloadedBytes + requestProgress + requestProgress2) / (float) totalBytesCount));
- }
-
private void startDownloadRequest() {
- if (state != 1) {
+ if (state != 1 || totalBytesCount > 0 && nextDownloadOffset >= totalBytesCount || requestInfos.size() + delayedRequestInfos.size() >= maxDownloadRequests) {
return;
}
- if (requestToken == 0) {
- requestProgress = 0;
- if (totalBytesCount > 0 && nextDownloadOffset >= totalBytesCount) {
- return;
- }
- final TLRPC.TL_upload_getFile req = new TLRPC.TL_upload_getFile();
- req.location = location;
- req.offset = nextDownloadOffset;
- req.limit = downloadChunkSize;
- nextDownloadOffset += downloadChunkSize;
- final long time = System.currentTimeMillis();
- requestToken = ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() {
- @Override
- public void run(TLObject response, TLRPC.TL_error error) {
- processRequestResult((TLRPC.TL_upload_file) response, error, req.offset, 0);
- }
- }, new RPCRequest.RPCProgressDelegate() {
- @Override
- public void progress(int length, int progress) {
- if (state == 1) {
- requestProgress = progress;
- if (totalBytesCount == -1) {
- delegate.didChangedLoadProgress(FileLoadOperation.this, Math.min(1.0f, (float) (progress) / (float) length));
- } else if (totalBytesCount > 0) {
- processRequestProgress();
- }
- }
- }
- }, null, true, RPCRequest.RPCRequestClassDownloadMedia, datacenter_id);
+ int count = 1;
+ if (totalBytesCount > 0) {
+ count = Math.max(0, maxDownloadRequests - requestInfos.size() - delayedRequestInfos.size());
}
- if (totalBytesCount > 0 && requestToken2 == 0) {
- requestProgress2 = 0;
+
+ for (int a = 0; a < count; a++) {
if (totalBytesCount > 0 && nextDownloadOffset >= totalBytesCount) {
- return;
+ break;
}
- final long time = System.currentTimeMillis();
- final TLRPC.TL_upload_getFile req = new TLRPC.TL_upload_getFile();
+ boolean isLast = totalBytesCount <= 0 || a == count - 1 || totalBytesCount > 0 && nextDownloadOffset + downloadChunkSize >= totalBytesCount;
+ TLRPC.TL_upload_getFile req = new TLRPC.TL_upload_getFile();
req.location = location;
req.offset = nextDownloadOffset;
req.limit = downloadChunkSize;
nextDownloadOffset += downloadChunkSize;
- requestToken2 = ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() {
+
+ final RequestInfo requestInfo = new RequestInfo();
+ requestInfos.add(requestInfo);
+ requestInfo.offset = req.offset;
+ requestInfo.requestToken = ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() {
@Override
public void run(TLObject response, TLRPC.TL_error error) {
- processRequestResult((TLRPC.TL_upload_file) response, error, req.offset, 1);
+ requestInfo.response = (TLRPC.TL_upload_file) response;
+ processRequestResult(requestInfo, error);
}
- }, new RPCRequest.RPCProgressDelegate() {
- @Override
- public void progress(int length, int progress) {
- if (state == 1) {
- requestProgress2 = progress;
- processRequestProgress();
- }
- }
- }, null, true, RPCRequest.RPCRequestClassDownloadMedia | RPCRequest.RPCRequestClassDownloadMedia2, datacenter_id);
+ }, null, true, RPCRequest.RPCRequestClassDownloadMedia, datacenter_id, isLast);
}
}
}
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/FileLoader.java b/TMessagesProj/src/main/java/org/telegram/messenger/FileLoader.java
index 9194bb17..9019f118 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/FileLoader.java
+++ b/TMessagesProj/src/main/java/org/telegram/messenger/FileLoader.java
@@ -18,6 +18,7 @@ import android.net.Uri;
import android.os.Build;
import android.os.ParcelFileDescriptor;
+import org.telegram.android.AndroidUtilities;
import org.telegram.objects.MessageObject;
import org.telegram.ui.ApplicationLoader;
import org.telegram.ui.Views.ImageReceiver;
@@ -291,10 +292,8 @@ public class FileLoader {
if (runtimeHack != null) {
runtimeHack.trackAlloc(oldBitmap.getRowBytes() * oldBitmap.getHeight());
}
- if (Build.VERSION.SDK_INT < 11) {
- if (!oldBitmap.isRecycled()) {
- oldBitmap.recycle();
- }
+ if (!oldBitmap.isRecycled()) {
+ oldBitmap.recycle();
}
}
}
@@ -466,6 +465,7 @@ public class FileLoader {
}
FileLoadOperation operation = loadOperationPaths.get(fileName);
if (operation != null) {
+ loadOperationPaths.remove(fileName);
if (audio != null) {
audioLoadOperationQueue.remove(operation);
} else if (photo != null) {
@@ -1119,7 +1119,7 @@ public class FileLoader {
try {
if (!cache) {
String fileName = location.volume_id + "_" + location.local_id + ".jpg";
- final File cacheFile = new File(Utilities.getCacheDir(), fileName);
+ final File cacheFile = new File(AndroidUtilities.getCacheDir(), fileName);
FileOutputStream stream = new FileOutputStream(cacheFile);
scaledBitmap.compress(Bitmap.CompressFormat.JPEG, quality, stream);
size.size = (int)stream.getChannel().size();
@@ -1129,10 +1129,8 @@ public class FileLoader {
size.bytes = stream.toByteArray();
size.size = size.bytes.length;
}
- if (Build.VERSION.SDK_INT < 11) {
- if (scaledBitmap != bitmap) {
- scaledBitmap.recycle();
- }
+ if (scaledBitmap != bitmap) {
+ scaledBitmap.recycle();
}
return size;
} catch (Exception e) {
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/FileLog.java b/TMessagesProj/src/main/java/org/telegram/messenger/FileLog.java
index 9ba56720..35d460d1 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/FileLog.java
+++ b/TMessagesProj/src/main/java/org/telegram/messenger/FileLog.java
@@ -11,6 +11,7 @@ package org.telegram.messenger;
import android.net.Uri;
import android.util.Log;
+import org.telegram.android.FastDateFormat;
import org.telegram.ui.ApplicationLoader;
import java.io.File;
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/FileUploadOperation.java b/TMessagesProj/src/main/java/org/telegram/messenger/FileUploadOperation.java
index 87e0a1a3..7f8aaadb 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/FileUploadOperation.java
+++ b/TMessagesProj/src/main/java/org/telegram/messenger/FileUploadOperation.java
@@ -31,7 +31,7 @@ public class FileUploadOperation {
private byte[] key;
private byte[] iv;
private byte[] ivChange;
- private int fingerprint;
+ private int fingerprint = 0;
private boolean isBigFile = false;
FileInputStream stream;
MessageDigest mdEnc = null;
@@ -57,11 +57,9 @@ public class FileUploadOperation {
System.arraycopy(key, 0, arr, 0, 32);
System.arraycopy(iv, 0, arr, 32, 32);
byte[] digest = md.digest(arr);
- byte[] fingerprintBytes = new byte[4];
for (int a = 0; a < 4; a++) {
- fingerprintBytes[a] = (byte)(digest[a] ^ digest[a + 4]);
+ fingerprint |= ((digest[a] ^ digest[a + 4]) & 0xFF) << (a * 8);
}
- fingerprint = Utilities.bytesToInt(fingerprintBytes);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
@@ -138,7 +136,7 @@ public class FileUploadOperation {
for (int a = 0; a < toAdd; a++) {
sendBuffer.writeByte(0);
}
- Utilities.aesIgeEncryption2(sendBuffer.buffer, key, ivChange, true, true, readed + toAdd);
+ Utilities.aesIgeEncryption(sendBuffer.buffer, key, ivChange, true, true, 0, readed + toAdd);
}
sendBuffer.rewind();
if (!isBigFile) {
@@ -211,11 +209,6 @@ public class FileUploadOperation {
delegate.didFailedUploadingFile(FileUploadOperation.this);
}
}
- }, new RPCRequest.RPCProgressDelegate() {
- @Override
- public void progress(int length, int progress) {
-
- }
}, null, true, RPCRequest.RPCRequestClassUploadMedia, ConnectionsManager.DEFAULT_DATACENTER_ID);
}
}
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/HandshakeAction.java b/TMessagesProj/src/main/java/org/telegram/messenger/HandshakeAction.java
index e28cbbbc..d2632e96 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/HandshakeAction.java
+++ b/TMessagesProj/src/main/java/org/telegram/messenger/HandshakeAction.java
@@ -12,7 +12,6 @@ import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.HashMap;
import java.util.Locale;
@@ -29,9 +28,9 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
private boolean processedPQRes;
- private byte[] reqPQMsgData;
- private byte[] reqDHMsgData;
- private byte[] setClientDHParamsMsgData;
+ private ByteBufferDesc reqPQMsgData;
+ private ByteBufferDesc reqDHMsgData;
+ private ByteBufferDesc setClientDHParamsMsgData;
private boolean wasDisconnect = false;
private long lastOutgoingMessageId;
@@ -63,9 +62,18 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
authKey = null;
authKeyId = 0;
processedPQRes = false;
- reqPQMsgData = null;
- reqDHMsgData = null;
- setClientDHParamsMsgData = null;
+ if (reqPQMsgData != null) {
+ BuffersStorage.getInstance().reuseFreeBuffer(reqPQMsgData);
+ reqPQMsgData = null;
+ }
+ if (reqDHMsgData != null) {
+ BuffersStorage.getInstance().reuseFreeBuffer(reqDHMsgData);
+ reqDHMsgData = null;
+ }
+ if (setClientDHParamsMsgData != null) {
+ BuffersStorage.getInstance().reuseFreeBuffer(setClientDHParamsMsgData);
+ setClientDHParamsMsgData = null;
+ }
if (dropConnection) {
datacenter.connection.suspendConnection(true);
@@ -165,23 +173,21 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
return messageId;
}
- byte[] sendMessageData(TLObject message, long messageId) {
- byte[] messageData;
- SerializedData innerOs = new SerializedData();
+ ByteBufferDesc sendMessageData(TLObject message, long messageId) {
+ ByteBufferDesc innerOs = BuffersStorage.getInstance().getFreeBuffer(message.getObjectSize());
message.serializeToStream(innerOs);
- messageData = innerOs.toByteArray();
+ message.freeResources();
- SerializedData messageOs = new SerializedData();
+ ByteBufferDesc messageOs = BuffersStorage.getInstance().getFreeBuffer(8 + 8 + 4 + innerOs.length());
messageOs.writeInt64(0);
messageOs.writeInt64(messageId);
- messageOs.writeInt32(messageData.length);
- messageOs.writeRaw(messageData);
+ messageOs.writeInt32(innerOs.length());
+ innerOs.position(0);
+ messageOs.writeRaw(innerOs);
+ BuffersStorage.getInstance().reuseFreeBuffer(innerOs);
- byte[] transportData = messageOs.toByteArray();
-
- datacenter.connection.sendData(transportData, null, false);
-
- return transportData;
+ datacenter.connection.sendData(messageOs, false, false);
+ return messageOs;
}
void processMessage(TLObject message, long messageId) {
@@ -196,7 +202,7 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
processedPQRes = true;
final TLRPC.TL_resPQ resPq = (TLRPC.TL_resPQ)message;
- if (Arrays.equals(authNonce, resPq.nonce)) {
+ if (Utilities.arraysEquals(authNonce, 0, resPq.nonce, 0)) {
final HashMap publicKey = selectPublicKey(resPq.server_public_key_fingerprints);
if (publicKey == null) {
FileLog.e("tmessages", "***** Couldn't find valid server public key");
@@ -276,7 +282,10 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
msgsAck.msg_ids.add(messageIdf);
sendMessageData(msgsAck, generateMessageId());
- reqPQMsgData = null;
+ if (reqPQMsgData != null) {
+ BuffersStorage.getInstance().reuseFreeBuffer(reqPQMsgData);
+ reqPQMsgData = null;
+ }
reqDHMsgData = sendMessageData(reqDH, generateMessageId());
}
});
@@ -322,33 +331,33 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
System.arraycopy(authNewNonce, 0, newNonce0_4, 0, 4);
tmpAesIv.writeRaw(newNonce0_4);
- byte[] answerWithHash = Utilities.aesIgeEncryption(serverDhParams.encrypted_answer, tmpAesKey.toByteArray(), tmpAesIv.toByteArray(), false, false, 0);
- byte[] answerHash = new byte[20];
- System.arraycopy(answerWithHash, 0, answerHash, 0, 20);
+ ByteBufferDesc answerWithHash = BuffersStorage.getInstance().getFreeBuffer(serverDhParams.encrypted_answer.length);
+ answerWithHash.writeRaw(serverDhParams.encrypted_answer);
+ answerWithHash.position(0);
+
+ Utilities.aesIgeEncryption(answerWithHash.buffer, tmpAesKey.toByteArray(), tmpAesIv.toByteArray(), false, false, 0, serverDhParams.encrypted_answer.length);
+ byte[] answerHash = new byte[20];
+ answerWithHash.readRaw(answerHash);
- byte[] answerData = new byte[answerWithHash.length - 20];
- System.arraycopy(answerWithHash, 20, answerData, 0, answerWithHash.length - 20);
boolean hashVerified = false;
for (int i = 0; i < 16; i++) {
- byte[] computedAnswerHash = Utilities.computeSHA1(answerData);
- if (Arrays.equals(computedAnswerHash, answerHash)) {
+ byte[] computedAnswerHash = Utilities.computeSHA1(answerWithHash.buffer, 20, answerWithHash.limit() - i);
+ if (Utilities.arraysEquals(computedAnswerHash, 0, answerHash, 0)) {
hashVerified = true;
break;
}
- byte[] answerData2 = new byte[answerData.length - 1];
- System.arraycopy(answerData, 0, answerData2, 0, answerData.length - 1);
- answerData = answerData2;
}
if (!hashVerified) {
FileLog.e("tmessages", "***** Couldn't decode DH params");
beginHandshake(false);
+ BuffersStorage.getInstance().reuseFreeBuffer(answerWithHash);
return;
}
- SerializedData answerIs = new SerializedData(answerData);
- int constructor = answerIs.readInt32();
- TLRPC.TL_server_DH_inner_data dhInnerData = (TLRPC.TL_server_DH_inner_data)TLClassStore.Instance().TLdeserialize(answerIs, constructor);
+ int constructor = answerWithHash.readInt32();
+ TLRPC.TL_server_DH_inner_data dhInnerData = (TLRPC.TL_server_DH_inner_data)TLClassStore.Instance().TLdeserialize(answerWithHash, constructor);
+ BuffersStorage.getInstance().reuseFreeBuffer(answerWithHash);
if (!(dhInnerData instanceof TLRPC.TL_server_DH_inner_data)) {
FileLog.e("tmessages", "***** Couldn't parse decoded DH params");
@@ -360,12 +369,12 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
throw new RuntimeException("bad prime");
}
- if (!Arrays.equals(authNonce, dhInnerData.nonce)) {
+ if (!Utilities.arraysEquals(authNonce, 0, dhInnerData.nonce, 0)) {
FileLog.e("tmessages", "***** Invalid DH nonce");
beginHandshake(false);
return;
}
- if (!Arrays.equals(authServerNonce, dhInnerData.server_nonce)) {
+ if (!Utilities.arraysEquals(authServerNonce, 0, dhInnerData.server_nonce, 0)) {
FileLog.e("tmessages", "***** Invalid DH server nonce");
beginHandshake(false);
return;
@@ -427,50 +436,66 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
clientInnerData.server_nonce = authServerNonce;
clientInnerData.g_b = g_b.toByteArray();
clientInnerData.retry_id = 0;
- SerializedData os = new SerializedData();
- clientInnerData.serializeToStream(os);
- byte[] clientInnerDataBytes = os.toByteArray();
- SerializedData clientDataWithHash = new SerializedData();
- clientDataWithHash.writeRaw(Utilities.computeSHA1(clientInnerDataBytes));
- clientDataWithHash.writeRaw(clientInnerDataBytes);
- byte[] bb = new byte[1];
- while (clientDataWithHash.length() % 16 != 0) {
+ ByteBufferDesc os = BuffersStorage.getInstance().getFreeBuffer(clientInnerData.getObjectSize());
+ clientInnerData.serializeToStream(os);
+
+ int len = os.length() + 20;
+ int extraLen = len % 16 != 0 ? 16 - len % 16 : 0;
+ ByteBufferDesc clientDataWithHash = BuffersStorage.getInstance().getFreeBuffer(len + extraLen);
+ clientDataWithHash.writeRaw(Utilities.computeSHA1(os.buffer));
+ os.position(0);
+ clientDataWithHash.writeRaw(os);
+ if (extraLen != 0) {
+ byte[] bb = new byte[extraLen];
Utilities.random.nextBytes(bb);
- clientDataWithHash.writeByte(bb[0]);
+ clientDataWithHash.writeRaw(bb);
}
+ BuffersStorage.getInstance().reuseFreeBuffer(os);
TLRPC.TL_set_client_DH_params setClientDhParams = new TLRPC.TL_set_client_DH_params();
setClientDhParams.nonce = authNonce;
setClientDhParams.server_nonce = authServerNonce;
- setClientDhParams.encrypted_data = Utilities.aesIgeEncryption(clientDataWithHash.toByteArray(), tmpAesKey.toByteArray(), tmpAesIv.toByteArray(), true, false, 0);
+ Utilities.aesIgeEncryption(clientDataWithHash.buffer, tmpAesKey.toByteArray(), tmpAesIv.toByteArray(), true, false, 0, clientDataWithHash.length());
+ setClientDhParams.encrypted_data = clientDataWithHash;
TLRPC.TL_msgs_ack msgsAck = new TLRPC.TL_msgs_ack();
msgsAck.msg_ids = new ArrayList();
msgsAck.msg_ids.add(messageId);
sendMessageData(msgsAck, generateMessageId());
- reqDHMsgData = null;
+ if (reqDHMsgData != null) {
+ BuffersStorage.getInstance().reuseFreeBuffer(reqDHMsgData);
+ reqDHMsgData = null;
+ }
setClientDHParamsMsgData = sendMessageData(setClientDhParams, generateMessageId());
} else {
FileLog.e("tmessages", "***** Couldn't set DH params");
beginHandshake(false);
}
} else if (message instanceof TLRPC.Set_client_DH_params_answer) {
+ if (setClientDHParamsMsgData != null) {
+ BuffersStorage.getInstance().reuseFreeBuffer(setClientDHParamsMsgData);
+ setClientDHParamsMsgData = null;
+ }
+
TLRPC.Set_client_DH_params_answer dhAnswer = (TLRPC.Set_client_DH_params_answer)message;
- if (!Arrays.equals(authNonce, dhAnswer.nonce)) {
+ if (!Utilities.arraysEquals(authNonce, 0, dhAnswer.nonce, 0)) {
FileLog.e("tmessages", "***** Invalid DH answer nonce");
beginHandshake(false);
return;
}
- if (!Arrays.equals(authServerNonce, dhAnswer.server_nonce)) {
+ if (!Utilities.arraysEquals(authServerNonce, 0, dhAnswer.server_nonce, 0)) {
FileLog.e("tmessages", "***** Invalid DH answer server nonce");
beginHandshake(false);
return;
}
- reqDHMsgData = null;
+ if (reqDHMsgData != null) {
+ BuffersStorage.getInstance().reuseFreeBuffer(reqDHMsgData);
+ reqDHMsgData = null;
+ }
TLRPC.TL_msgs_ack msgsAck = new TLRPC.TL_msgs_ack();
msgsAck.msg_ids = new ArrayList();
@@ -507,7 +532,7 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
if (message instanceof TLRPC.TL_dh_gen_ok) {
TLRPC.TL_dh_gen_ok dhGenOk = (TLRPC.TL_dh_gen_ok)message;
- if (!Arrays.equals(newNonceHash1, dhGenOk.new_nonce_hash1)) {
+ if (!Utilities.arraysEquals(newNonceHash1, 0, dhGenOk.new_nonce_hash1, 0)) {
FileLog.e("tmessages", "***** Invalid DH answer nonce hash 1");
beginHandshake(false);
return;
@@ -532,7 +557,7 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
});
} else if (message instanceof TLRPC.TL_dh_gen_retry) {
TLRPC.TL_dh_gen_retry dhRetry = (TLRPC.TL_dh_gen_retry)message;
- if (!Arrays.equals(newNonceHash2, dhRetry.new_nonce_hash2)) {
+ if (!Utilities.arraysEquals(newNonceHash2, 0, dhRetry.new_nonce_hash2, 0)) {
FileLog.e("tmessages", "***** Invalid DH answer nonce hash 2");
beginHandshake(false);
return;
@@ -541,7 +566,7 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
beginHandshake(false);
} else if (message instanceof TLRPC.TL_dh_gen_fail) {
TLRPC.TL_dh_gen_fail dhFail = (TLRPC.TL_dh_gen_fail)message;
- if (!Arrays.equals(newNonceHash3, dhFail.new_nonce_hash3)) {
+ if (!Utilities.arraysEquals(newNonceHash3, 0, dhFail.new_nonce_hash3, 0)) {
FileLog.e("tmessages", "***** Invalid DH answer nonce hash 3");
beginHandshake(false);
return;
@@ -560,11 +585,6 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
}
}
- @Override
- public void tcpConnectionProgressChanged(TcpConnection connection, long messageId, int currentSize, int length) {
-
- }
-
@Override
public void tcpConnectionClosed(final TcpConnection connection) {
wasDisconnect = true;
@@ -582,11 +602,11 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
return;
}
if (reqPQMsgData != null) {
- datacenter.connection.sendData(reqPQMsgData, null, false);
+ datacenter.connection.sendData(reqPQMsgData, false, false);
} else if (reqDHMsgData != null) {
- datacenter.connection.sendData(reqDHMsgData, null, false);
+ datacenter.connection.sendData(reqDHMsgData, false, false);
} else if (setClientDHParamsMsgData != null) {
- datacenter.connection.sendData(setClientDHParamsMsgData, null, false);
+ datacenter.connection.sendData(setClientDHParamsMsgData, false, false);
}
}
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/RPCRequest.java b/TMessagesProj/src/main/java/org/telegram/messenger/RPCRequest.java
index ab6162ae..bd8b7898 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/RPCRequest.java
+++ b/TMessagesProj/src/main/java/org/telegram/messenger/RPCRequest.java
@@ -14,9 +14,6 @@ public class RPCRequest {
public interface RPCRequestDelegate {
void run(TLObject response, TLRPC.TL_error error);
}
- public interface RPCProgressDelegate {
- void progress(int length, int progress);
- }
public interface RPCQuickAckDelegate {
void quickAck();
}
@@ -29,7 +26,6 @@ public class RPCRequest {
public static int RPCRequestClassCanCompress = 32;
public static int RPCRequestClassPush = 64;
public static int RPCRequestClassWithoutLogin = 128;
- public static int RPCRequestClassDownloadMedia2 = 256;
static int RPCRequestClassTransportMask = (RPCRequestClassGeneric | RPCRequestClassDownloadMedia | RPCRequestClassUploadMedia);
@@ -45,7 +41,6 @@ public class RPCRequest {
int serializedLength;
RPCRequestDelegate completionBlock;
- RPCProgressDelegate progressBlock;
RPCQuickAckDelegate quickAckBlock;
boolean requiresCompletion;
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/TLClassStore.java b/TMessagesProj/src/main/java/org/telegram/messenger/TLClassStore.java
index 2e1895e5..513417a4 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/TLClassStore.java
+++ b/TMessagesProj/src/main/java/org/telegram/messenger/TLClassStore.java
@@ -412,6 +412,14 @@ public class TLClassStore {
classStore.put(TLRPC.TL_decryptedMessageActionFlushHistory.constructor, TLRPC.TL_decryptedMessageActionFlushHistory.class);
classStore.put(TLRPC.TL_decryptedMessageActionScreenshotMessages.constructor, TLRPC.TL_decryptedMessageActionScreenshotMessages.class);
classStore.put(TLRPC.TL_messageEcryptedAction.constructor, TLRPC.TL_messageEcryptedAction.class);
+ classStore.put(TLRPC.TL_decryptedMessageActionNotifyLayer.constructor, TLRPC.TL_decryptedMessageActionNotifyLayer.class);
+ classStore.put(TLRPC.TL_decryptedMessageActionReadMessages.constructor, TLRPC.TL_decryptedMessageActionReadMessages.class);
+ classStore.put(TLRPC.TL_updateNotifySettings.constructor, TLRPC.TL_updateNotifySettings.class);
+ classStore.put(TLRPC.TL_updateUserBlocked.constructor, TLRPC.TL_updateUserBlocked.class);
+ classStore.put(TLRPC.TL_notifyAll.constructor, TLRPC.TL_notifyAll.class);
+ classStore.put(TLRPC.TL_notifyChats.constructor, TLRPC.TL_notifyChats.class);
+ classStore.put(TLRPC.TL_notifyUsers.constructor, TLRPC.TL_notifyUsers.class);
+ classStore.put(TLRPC.TL_notifyPeer.constructor, TLRPC.TL_notifyPeer.class);
classStore.put(TLRPC.TL_msg_container.constructor, TLRPC.TL_msg_container.class);
classStore.put(TLRPC.TL_fileEncryptedLocation.constructor, TLRPC.TL_fileEncryptedLocation.class);
@@ -427,6 +435,10 @@ public class TLClassStore {
classStore.put(TLRPC.TL_messageActionLoginUnknownLocation.constructor, TLRPC.TL_messageActionLoginUnknownLocation.class);
classStore.put(TLRPC.TL_encryptedChat_old.constructor, TLRPC.TL_encryptedChat_old.class);
classStore.put(TLRPC.TL_encryptedChatRequested_old.constructor, TLRPC.TL_encryptedChatRequested_old.class);
+ classStore.put(TLRPC.TL_decryptedMessageMediaVideo_old.constructor, TLRPC.TL_decryptedMessageMediaVideo_old.class);
+ classStore.put(TLRPC.TL_decryptedMessageMediaAudio_old.constructor, TLRPC.TL_decryptedMessageMediaAudio_old.class);
+ classStore.put(TLRPC.TL_audio_old.constructor, TLRPC.TL_audio_old.class);
+ classStore.put(TLRPC.TL_video_old.constructor, TLRPC.TL_video_old.class);
}
static TLClassStore store = null;
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/TLObject.java b/TMessagesProj/src/main/java/org/telegram/messenger/TLObject.java
index 9c40cb6e..8ee8bc00 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/TLObject.java
+++ b/TMessagesProj/src/main/java/org/telegram/messenger/TLObject.java
@@ -42,4 +42,10 @@ public class TLObject {
public void freeResources() {
}
+
+ public int getObjectSize() {
+ ByteBufferDesc bufferDesc = new ByteBufferDesc(true);
+ serializeToStream(bufferDesc);
+ return bufferDesc.length();
+ }
}
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/TLRPC.java b/TMessagesProj/src/main/java/org/telegram/messenger/TLRPC.java
index 0cbc8368..a2dad78c 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/TLRPC.java
+++ b/TMessagesProj/src/main/java/org/telegram/messenger/TLRPC.java
@@ -140,6 +140,51 @@ public class TLRPC {
}
}
+ public static class NotifyPeer extends TLObject {
+ public Peer peer;
+ }
+
+ public static class TL_notifyAll extends NotifyPeer {
+ public static int constructor = 0x74d07c60;
+
+
+ public void serializeToStream(AbsSerializedData stream) {
+ stream.writeInt32(constructor);
+ }
+ }
+
+ public static class TL_notifyChats extends NotifyPeer {
+ public static int constructor = 0xc007cec3;
+
+
+ public void serializeToStream(AbsSerializedData stream) {
+ stream.writeInt32(constructor);
+ }
+ }
+
+ public static class TL_notifyUsers extends NotifyPeer {
+ public static int constructor = 0xb4c83b4c;
+
+
+ public void serializeToStream(AbsSerializedData stream) {
+ stream.writeInt32(constructor);
+ }
+ }
+
+ public static class TL_notifyPeer extends NotifyPeer {
+ public static int constructor = 0x9fd40bd8;
+
+
+ public void readParams(AbsSerializedData stream) {
+ peer = (Peer)TLClassStore.Instance().TLdeserialize(stream, stream.readInt32());
+ }
+
+ public void serializeToStream(AbsSerializedData stream) {
+ stream.writeInt32(constructor);
+ peer.serializeToStream(stream);
+ }
+ }
+
public static class TL_auth_checkedPhone extends TLObject {
public static int constructor = 0xe300cc3b;
@@ -1245,7 +1290,7 @@ public class TLRPC {
}
public static class TL_audio extends Audio {
- public static int constructor = 0x427425e7;
+ public static int constructor = 0xc7ac6496;
public void readParams(AbsSerializedData stream) {
@@ -1254,6 +1299,7 @@ public class TLRPC {
user_id = stream.readInt32();
date = stream.readInt32();
duration = stream.readInt32();
+ mime_type = stream.readString();
size = stream.readInt32();
dc_id = stream.readInt32();
}
@@ -1265,6 +1311,7 @@ public class TLRPC {
stream.writeInt32(user_id);
stream.writeInt32(date);
stream.writeInt32(duration);
+ stream.writeString(mime_type);
stream.writeInt32(size);
stream.writeInt32(dc_id);
}
@@ -2515,7 +2562,7 @@ public class TLRPC {
}
public static class TL_video extends Video {
- public static int constructor = 0x5a04a49f;
+ public static int constructor = 0x388fa391;
public void readParams(AbsSerializedData stream) {
@@ -2525,6 +2572,7 @@ public class TLRPC {
date = stream.readInt32();
caption = stream.readString();
duration = stream.readInt32();
+ mime_type = stream.readString();
size = stream.readInt32();
thumb = (PhotoSize)TLClassStore.Instance().TLdeserialize(stream, stream.readInt32());
dc_id = stream.readInt32();
@@ -2540,6 +2588,7 @@ public class TLRPC {
stream.writeInt32(date);
stream.writeString(caption);
stream.writeInt32(duration);
+ stream.writeString(mime_type);
stream.writeInt32(size);
thumb.serializeToStream(stream);
stream.writeInt32(dc_id);
@@ -2820,7 +2869,7 @@ public class TLRPC {
}
public static class TL_inputMediaUploadedThumbVideo extends InputMedia {
- public static int constructor = 0xe628a145;
+ public static int constructor = 0x9912dabf;
public void readParams(AbsSerializedData stream) {
@@ -2829,6 +2878,7 @@ public class TLRPC {
duration = stream.readInt32();
w = stream.readInt32();
h = stream.readInt32();
+ mime_type = stream.readString();
}
public void serializeToStream(AbsSerializedData stream) {
@@ -2838,6 +2888,7 @@ public class TLRPC {
stream.writeInt32(duration);
stream.writeInt32(w);
stream.writeInt32(h);
+ stream.writeString(mime_type);
}
}
@@ -2856,23 +2907,25 @@ public class TLRPC {
}
public static class TL_inputMediaUploadedAudio extends InputMedia {
- public static int constructor = 0x61a6d436;
+ public static int constructor = 0x4e498cab;
public void readParams(AbsSerializedData stream) {
file = (InputFile)TLClassStore.Instance().TLdeserialize(stream, stream.readInt32());
duration = stream.readInt32();
+ mime_type = stream.readString();
}
public void serializeToStream(AbsSerializedData stream) {
stream.writeInt32(constructor);
file.serializeToStream(stream);
stream.writeInt32(duration);
+ stream.writeString(mime_type);
}
}
public static class TL_inputMediaUploadedVideo extends InputMedia {
- public static int constructor = 0x4847d92a;
+ public static int constructor = 0x133ad6f6;
public void readParams(AbsSerializedData stream) {
@@ -2880,6 +2933,7 @@ public class TLRPC {
duration = stream.readInt32();
w = stream.readInt32();
h = stream.readInt32();
+ mime_type = stream.readString();
}
public void serializeToStream(AbsSerializedData stream) {
@@ -2888,6 +2942,7 @@ public class TLRPC {
stream.writeInt32(duration);
stream.writeInt32(w);
stream.writeInt32(h);
+ stream.writeString(mime_type);
}
}
@@ -3209,9 +3264,10 @@ public class TLRPC {
}
public static class TL_contacts_importedContacts extends TLObject {
- public static int constructor = 0xd1cd0a4c;
+ public static int constructor = 0xad524315;
public ArrayList imported = new ArrayList();
+ public ArrayList retry_contacts = new ArrayList();
public ArrayList users = new ArrayList();
public void readParams(AbsSerializedData stream) {
@@ -3222,6 +3278,11 @@ public class TLRPC {
}
stream.readInt32();
count = stream.readInt32();
+ for (int a = 0; a < count; a++) {
+ retry_contacts.add(stream.readInt64());
+ }
+ stream.readInt32();
+ count = stream.readInt32();
for (int a = 0; a < count; a++) {
users.add((User)TLClassStore.Instance().TLdeserialize(stream, stream.readInt32()));
}
@@ -3236,6 +3297,12 @@ public class TLRPC {
imported.get(a).serializeToStream(stream);
}
stream.writeInt32(0x1cb5c415);
+ count = retry_contacts.size();
+ stream.writeInt32(count);
+ for (int a = 0; a < count; a++) {
+ stream.writeInt64(retry_contacts.get(a));
+ }
+ stream.writeInt32(0x1cb5c415);
count = users.size();
stream.writeInt32(count);
for (int a = 0; a < count; a++) {
@@ -3275,6 +3342,8 @@ public class TLRPC {
public ArrayList messages = new ArrayList();
public int pts;
public int version;
+ public NotifyPeer peer;
+ public PeerNotifySettings notify_settings;
public String first_name;
public String last_name;
public int qts;
@@ -3283,6 +3352,7 @@ public class TLRPC {
public ArrayList dc_options = new ArrayList();
public ChatParticipants participants;
public EncryptedChat chat;
+ public boolean blocked;
public long auth_key_id;
public String device;
public String location;
@@ -3396,6 +3466,22 @@ public class TLRPC {
}
}
+ public static class TL_updateNotifySettings extends Update {
+ public static int constructor = 0xbec268ef;
+
+
+ public void readParams(AbsSerializedData stream) {
+ peer = (NotifyPeer)TLClassStore.Instance().TLdeserialize(stream, stream.readInt32());
+ notify_settings = (PeerNotifySettings)TLClassStore.Instance().TLdeserialize(stream, stream.readInt32());
+ }
+
+ public void serializeToStream(AbsSerializedData stream) {
+ stream.writeInt32(constructor);
+ peer.serializeToStream(stream);
+ notify_settings.serializeToStream(stream);
+ }
+ }
+
public static class TL_updateUserTyping extends Update {
public static int constructor = 0x6baa8508;
@@ -3586,6 +3672,22 @@ public class TLRPC {
}
}
+ public static class TL_updateUserBlocked extends Update {
+ public static int constructor = 0x80ece81a;
+
+
+ public void readParams(AbsSerializedData stream) {
+ user_id = stream.readInt32();
+ blocked = stream.readBool();
+ }
+
+ public void serializeToStream(AbsSerializedData stream) {
+ stream.writeInt32(constructor);
+ stream.writeInt32(user_id);
+ stream.writeBool(blocked);
+ }
+ }
+
public static class TL_updateActivation extends Update {
public static int constructor = 0x6f690963;
@@ -3847,6 +3949,7 @@ public class TLRPC {
}
public static class DecryptedMessageAction extends TLObject {
+ public int layer;
public int ttl_seconds;
public ArrayList random_ids = new ArrayList();
}
@@ -3872,6 +3975,43 @@ public class TLRPC {
}
}
+ public static class TL_decryptedMessageActionNotifyLayer extends DecryptedMessageAction {
+ public static int constructor = 0xf3048883;
+
+
+ public void readParams(AbsSerializedData stream) {
+ layer = stream.readInt32();
+ }
+
+ public void serializeToStream(AbsSerializedData stream) {
+ stream.writeInt32(constructor);
+ stream.writeInt32(layer);
+ }
+ }
+
+ public static class TL_decryptedMessageActionReadMessages extends DecryptedMessageAction {
+ public static int constructor = 0xc4f40be;
+
+
+ public void readParams(AbsSerializedData stream) {
+ stream.readInt32();
+ int count = stream.readInt32();
+ for (int a = 0; a < count; a++) {
+ random_ids.add(stream.readInt64());
+ }
+ }
+
+ public void serializeToStream(AbsSerializedData stream) {
+ stream.writeInt32(constructor);
+ stream.writeInt32(0x1cb5c415);
+ int count = random_ids.size();
+ stream.writeInt32(count);
+ for (Long random_id : random_ids) {
+ stream.writeInt64(random_id);
+ }
+ }
+ }
+
public static class contacts_MyLink extends TLObject {
public boolean contact;
}
@@ -4497,11 +4637,12 @@ public class TLRPC {
}
public static class TL_decryptedMessageMediaAudio extends DecryptedMessageMedia {
- public static int constructor = 0x6080758f;
+ public static int constructor = 0x57e0a9cb;
public void readParams(AbsSerializedData stream) {
duration = stream.readInt32();
+ mime_type = stream.readString();
size = stream.readInt32();
key = stream.readByteArray();
iv = stream.readByteArray();
@@ -4510,6 +4651,7 @@ public class TLRPC {
public void serializeToStream(AbsSerializedData stream) {
stream.writeInt32(constructor);
stream.writeInt32(duration);
+ stream.writeString(mime_type);
stream.writeInt32(size);
stream.writeByteArray(key);
stream.writeByteArray(iv);
@@ -4517,7 +4659,7 @@ public class TLRPC {
}
public static class TL_decryptedMessageMediaVideo extends DecryptedMessageMedia {
- public static int constructor = 0x4cee6ef3;
+ public static int constructor = 0x524a415d;
public void readParams(AbsSerializedData stream) {
@@ -4525,6 +4667,7 @@ public class TLRPC {
thumb_w = stream.readInt32();
thumb_h = stream.readInt32();
duration = stream.readInt32();
+ mime_type = stream.readString();
w = stream.readInt32();
h = stream.readInt32();
size = stream.readInt32();
@@ -4538,6 +4681,7 @@ public class TLRPC {
stream.writeInt32(thumb_w);
stream.writeInt32(thumb_h);
stream.writeInt32(duration);
+ stream.writeString(mime_type);
stream.writeInt32(w);
stream.writeInt32(h);
stream.writeInt32(size);
@@ -6169,31 +6313,6 @@ public class TLRPC {
}
}
- public static class TL_set_client_DH_params extends TLObject {
- public static int constructor = 0xf5045f1f;
-
- public byte[] nonce;
- public byte[] server_nonce;
- public byte[] encrypted_data;
-
- public Class responseClass () {
- return Set_client_DH_params_answer.class;
- }
-
- public void readParams(AbsSerializedData stream) {
- nonce = stream.readData(16);
- server_nonce = stream.readData(16);
- encrypted_data = stream.readByteArray();
- }
-
- public void serializeToStream(AbsSerializedData stream) {
- stream.writeInt32(constructor);
- stream.writeRaw(nonce);
- stream.writeRaw(server_nonce);
- stream.writeByteArray(encrypted_data);
- }
- }
-
public static class TL_auth_checkPhone extends TLObject {
public static int constructor = 0x6fe51dfb;
@@ -8000,59 +8119,6 @@ public class TLRPC {
}
}
- public static class TL_messages_sendEncrypted extends TLObject {
- public static int constructor = 0xa9776773;
-
- public TL_inputEncryptedChat peer;
- public long random_id;
- public byte[] data;
-
- public Class responseClass () {
- return messages_SentEncryptedMessage.class;
- }
-
- public void readParams(AbsSerializedData stream) {
- peer = (TL_inputEncryptedChat)TLClassStore.Instance().TLdeserialize(stream, stream.readInt32());
- random_id = stream.readInt64();
- data = stream.readByteArray();
- }
-
- public void serializeToStream(AbsSerializedData stream) {
- stream.writeInt32(constructor);
- peer.serializeToStream(stream);
- stream.writeInt64(random_id);
- stream.writeByteArray(data);
- }
- }
-
- public static class TL_messages_sendEncryptedFile extends TLObject {
- public static int constructor = 0x9a901b66;
-
- public TL_inputEncryptedChat peer;
- public long random_id;
- public byte[] data;
- public InputEncryptedFile file;
-
- public Class responseClass () {
- return messages_SentEncryptedMessage.class;
- }
-
- public void readParams(AbsSerializedData stream) {
- peer = (TL_inputEncryptedChat)TLClassStore.Instance().TLdeserialize(stream, stream.readInt32());
- random_id = stream.readInt64();
- data = stream.readByteArray();
- file = (InputEncryptedFile)TLClassStore.Instance().TLdeserialize(stream, stream.readInt32());
- }
-
- public void serializeToStream(AbsSerializedData stream) {
- stream.writeInt32(constructor);
- peer.serializeToStream(stream);
- stream.writeInt64(random_id);
- stream.writeByteArray(data);
- file.serializeToStream(stream);
- }
- }
-
public static class TL_messages_sendEncryptedService extends TLObject {
public static int constructor = 0x32d439a4;
@@ -8080,6 +8146,98 @@ public class TLRPC {
//manually created
+ public static class TL_set_client_DH_params extends TLObject {
+ public static int constructor = 0xf5045f1f;
+
+ public byte[] nonce;
+ public byte[] server_nonce;
+ public ByteBufferDesc encrypted_data;
+
+ public Class responseClass () {
+ return Set_client_DH_params_answer.class;
+ }
+
+ public void serializeToStream(AbsSerializedData stream) {
+ stream.writeInt32(constructor);
+ stream.writeRaw(nonce);
+ stream.writeRaw(server_nonce);
+ stream.writeByteBuffer(encrypted_data);
+ }
+
+ @Override
+ public void freeResources() {
+ if (disableFree) {
+ return;
+ }
+ if (encrypted_data != null) {
+ BuffersStorage.getInstance().reuseFreeBuffer(encrypted_data);
+ encrypted_data = null;
+ }
+ }
+ }
+
+ public static class TL_messages_sendEncrypted extends TLObject {
+ public static int constructor = 0xa9776773;
+
+ public TL_inputEncryptedChat peer;
+ public long random_id;
+ public ByteBufferDesc data;
+
+ public Class responseClass () {
+ return messages_SentEncryptedMessage.class;
+ }
+
+ public void serializeToStream(AbsSerializedData stream) {
+ stream.writeInt32(constructor);
+ peer.serializeToStream(stream);
+ stream.writeInt64(random_id);
+ stream.writeByteBuffer(data);
+ }
+
+ @Override
+ public void freeResources() {
+ if (disableFree) {
+ return;
+ }
+ if (data != null) {
+ BuffersStorage.getInstance().reuseFreeBuffer(data);
+ data = null;
+ }
+ }
+ }
+
+ public static class TL_messages_sendEncryptedFile extends TLObject {
+ public static int constructor = 0x9a901b66;
+
+ public TL_inputEncryptedChat peer;
+ public long random_id;
+ public ByteBufferDesc data;
+ public InputEncryptedFile file;
+
+ public Class responseClass () {
+ return messages_SentEncryptedMessage.class;
+ }
+
+ public void serializeToStream(AbsSerializedData stream) {
+ stream.writeInt32(constructor);
+ peer.serializeToStream(stream);
+ stream.writeInt64(random_id);
+ stream.writeByteBuffer(data);
+ file.serializeToStream(stream);
+ }
+
+ @Override
+ public void freeResources() {
+ if (disableFree) {
+ return;
+ }
+ if (data != null) {
+ BuffersStorage.getInstance().reuseFreeBuffer(data);
+ data = null;
+ }
+ }
+ }
+
public static class UserStatus extends TLObject {
public int expires;
}
@@ -8313,6 +8471,7 @@ public class TLRPC {
for (int a = 0; a < count; a++) {
TL_futureSalt salt = new TL_futureSalt();
salt.readParams(stream);
+ salts.add(salt);
}
}
@@ -8692,11 +8851,12 @@ public class TLRPC {
}
public static class TL_dialog extends TLObject {
- public static int constructor = 0x214a8cdf;
+ public static int constructor = 0xab3a99ac;
public Peer peer;
public int top_message;
public int unread_count;
+ public PeerNotifySettings notify_settings;
public int last_message_date;
public long id;
public int last_read;
@@ -8705,6 +8865,7 @@ public class TLRPC {
peer = (Peer)TLClassStore.Instance().TLdeserialize(stream, stream.readInt32());
top_message = stream.readInt32();
unread_count = stream.readInt32();
+ notify_settings = (PeerNotifySettings)TLClassStore.Instance().TLdeserialize(stream, stream.readInt32());
}
public void serializeToStream(AbsSerializedData stream) {
@@ -8712,6 +8873,7 @@ public class TLRPC {
peer.serializeToStream(stream);
stream.writeInt32(top_message);
stream.writeInt32(unread_count);
+ notify_settings.serializeToStream(stream);
}
}
@@ -8770,6 +8932,7 @@ public class TLRPC {
public int date;
public String caption;
public int duration;
+ public String mime_type;
public int size;
public PhotoSize thumb;
public int dc_id;
@@ -8801,6 +8964,7 @@ public class TLRPC {
public int user_id;
public int date;
public int duration;
+ public String mime_type;
public int size;
public int dc_id;
public String path;
@@ -8974,8 +9138,8 @@ public class TLRPC {
}
}
- public static class invokeWithLayer12 extends TLObject {
- public static int constructor = 0xdda60d3c;
+ public static class invokeWithLayer14 extends TLObject {
+ public static int constructor = 0x2b9b08fa;
public TLObject query;
@@ -9226,4 +9390,114 @@ public class TLRPC {
public byte[] key;
public byte[] iv;
}
+
+ public static class TL_decryptedMessageMediaVideo_old extends TL_decryptedMessageMediaVideo {
+ public static int constructor = 0x4cee6ef3;
+
+
+ public void readParams(AbsSerializedData stream) {
+ thumb = stream.readByteArray();
+ thumb_w = stream.readInt32();
+ thumb_h = stream.readInt32();
+ duration = stream.readInt32();
+ w = stream.readInt32();
+ h = stream.readInt32();
+ size = stream.readInt32();
+ key = stream.readByteArray();
+ iv = stream.readByteArray();
+ }
+
+ public void serializeToStream(AbsSerializedData stream) {
+ stream.writeInt32(constructor);
+ stream.writeByteArray(thumb);
+ stream.writeInt32(thumb_w);
+ stream.writeInt32(thumb_h);
+ stream.writeInt32(duration);
+ stream.writeInt32(w);
+ stream.writeInt32(h);
+ stream.writeInt32(size);
+ stream.writeByteArray(key);
+ stream.writeByteArray(iv);
+ }
+ }
+
+ public static class TL_decryptedMessageMediaAudio_old extends TL_decryptedMessageMediaAudio {
+ public static int constructor = 0x6080758f;
+
+
+ public void readParams(AbsSerializedData stream) {
+ duration = stream.readInt32();
+ size = stream.readInt32();
+ key = stream.readByteArray();
+ iv = stream.readByteArray();
+ }
+
+ public void serializeToStream(AbsSerializedData stream) {
+ stream.writeInt32(constructor);
+ stream.writeInt32(duration);
+ stream.writeInt32(size);
+ stream.writeByteArray(key);
+ stream.writeByteArray(iv);
+ }
+ }
+
+ public static class TL_audio_old extends TL_audio {
+ public static int constructor = 0x427425e7;
+
+
+ public void readParams(AbsSerializedData stream) {
+ id = stream.readInt64();
+ access_hash = stream.readInt64();
+ user_id = stream.readInt32();
+ date = stream.readInt32();
+ duration = stream.readInt32();
+ size = stream.readInt32();
+ dc_id = stream.readInt32();
+ }
+
+ public void serializeToStream(AbsSerializedData stream) {
+ stream.writeInt32(constructor);
+ stream.writeInt64(id);
+ stream.writeInt64(access_hash);
+ stream.writeInt32(user_id);
+ stream.writeInt32(date);
+ stream.writeInt32(duration);
+ stream.writeInt32(size);
+ stream.writeInt32(dc_id);
+ }
+ }
+
+ public static class TL_video_old extends TL_video {
+ public static int constructor = 0x5a04a49f;
+
+
+ public void readParams(AbsSerializedData stream) {
+ id = stream.readInt64();
+ access_hash = stream.readInt64();
+ user_id = stream.readInt32();
+ date = stream.readInt32();
+ caption = stream.readString();
+ duration = stream.readInt32();
+ size = stream.readInt32();
+ thumb = (PhotoSize)TLClassStore.Instance().TLdeserialize(stream, stream.readInt32());
+ dc_id = stream.readInt32();
+ w = stream.readInt32();
+ h = stream.readInt32();
+ }
+
+ public void serializeToStream(AbsSerializedData stream) {
+ stream.writeInt32(constructor);
+ stream.writeInt64(id);
+ stream.writeInt64(access_hash);
+ stream.writeInt32(user_id);
+ stream.writeInt32(date);
+ stream.writeString(caption);
+ stream.writeInt32(duration);
+ stream.writeInt32(size);
+ thumb.serializeToStream(stream);
+ stream.writeInt32(dc_id);
+ stream.writeInt32(w);
+ stream.writeInt32(h);
+ }
+ }
}
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/TcpConnection.java b/TMessagesProj/src/main/java/org/telegram/messenger/TcpConnection.java
index 717cb329..263ed8fd 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/TcpConnection.java
+++ b/TMessagesProj/src/main/java/org/telegram/messenger/TcpConnection.java
@@ -33,7 +33,6 @@ public class TcpConnection extends ConnectionContext {
public abstract void tcpConnectionConnected(TcpConnection connection);
public abstract void tcpConnectionQuiackAckReceived(TcpConnection connection, int ack);
public abstract void tcpConnectionReceivedData(TcpConnection connection, ByteBufferDesc data, int length);
- public abstract void tcpConnectionProgressChanged(TcpConnection connection, long messageId, int currentSize, int length);
}
private static PyroSelector selector;
@@ -46,7 +45,6 @@ public class TcpConnection extends ConnectionContext {
private int failedConnectionCount;
public TcpConnectionDelegate delegate;
private ByteBufferDesc restOfTheData;
- private long lastMessageId = 0;
private boolean hasSomeDataSinceLastConnect = false;
private int willRetryConnectCount = 5;
private boolean isNextPort = false;
@@ -284,8 +282,8 @@ public class TcpConnection extends ConnectionContext {
connect();
}
- public void sendData(final byte[] data, final ByteBufferDesc buff, final boolean reportAck) {
- if (data == null && buff == null) {
+ public void sendData(final ByteBufferDesc buff, final boolean canReuse, final boolean reportAck) {
+ if (buff == null) {
return;
}
selector.scheduleTask(new Runnable() {
@@ -298,16 +296,13 @@ public class TcpConnection extends ConnectionContext {
}
if (client == null || client.isDisconnected()) {
- BuffersStorage.getInstance().reuseFreeBuffer(buff);
+ if (canReuse) {
+ BuffersStorage.getInstance().reuseFreeBuffer(buff);
+ }
return;
}
- int bufferLen = 0;
- if (data != null) {
- bufferLen = data.length;
- } else if (buff != null) {
- bufferLen = buff.limit();
- }
+ int bufferLen = buff.limit();
int packetLength = bufferLen / 4;
if (packetLength < 0x7f) {
@@ -336,10 +331,9 @@ public class TcpConnection extends ConnectionContext {
}
buffer.writeInt32(packetLength);
}
- if (data != null) {
- buffer.writeRaw(data);
- } else {
- buffer.writeRaw(buff);
+
+ buffer.writeRaw(buff);
+ if (canReuse) {
BuffersStorage.getInstance().reuseFreeBuffer(buff);
}
@@ -389,19 +383,6 @@ public class TcpConnection extends ConnectionContext {
buffer.limit(oldLimit);
if (restOfTheData.position() != lastPacketLength) {
//FileLog.e("tmessages", this + " don't get much data to restOfTheData");
- if (lastMessageId != -1 && lastMessageId != 0) {
- if (delegate != null) {
- final TcpConnectionDelegate finalDelegate = delegate;
- final int arg2 = restOfTheData.position();
- final int arg3 = lastPacketLength;
- Utilities.stageQueue.postRunnable(new Runnable() {
- @Override
- public void run() {
- finalDelegate.tcpConnectionProgressChanged(TcpConnection.this, lastMessageId, arg2, arg3);
- }
- });
- }
- }
return;
} else {
//FileLog.e("tmessages", this + " get much data to restOfTheData - OK!");
@@ -424,7 +405,7 @@ public class TcpConnection extends ConnectionContext {
datacenter.storeCurrentAddressAndPortNum();
isNextPort = false;
if ((transportRequestClass & RPCRequest.RPCRequestClassPush) != 0) {
- client.setTimeout(60000 * 3 + 20000);
+ client.setTimeout(60000 * 15);
} else {
client.setTimeout(25000);
}
@@ -497,32 +478,10 @@ public class TcpConnection extends ConnectionContext {
if (currentPacketLength < buffer.remaining()) {
FileLog.d("tmessages", TcpConnection.this + " Received message len " + currentPacketLength + " but packet larger " + buffer.remaining());
- lastMessageId = 0;
} else if (currentPacketLength == buffer.remaining()) {
FileLog.d("tmessages", TcpConnection.this + " Received message len " + currentPacketLength + " equal to packet size");
- lastMessageId = 0;
} else {
FileLog.d("tmessages", TcpConnection.this + " Received packet size less(" + buffer.remaining() + ") then message size(" + currentPacketLength + ")");
- if (buffer.remaining() >= 152 && (transportRequestClass & RPCRequest.RPCRequestClassDownloadMedia) != 0) {
- if (lastMessageId == 0) {
- byte[] temp = new byte[152];
- buffer.get(temp);
- lastMessageId = ConnectionsManager.getInstance().needsToDecodeMessageIdFromPartialData(TcpConnection.this, temp);
- }
- if (lastMessageId != -1 && lastMessageId != 0) {
- if (delegate != null) {
- final TcpConnectionDelegate finalDelegate = delegate;
- final int arg2 = buffer.remaining();
- final int arg3 = currentPacketLength;
- Utilities.stageQueue.postRunnable(new Runnable() {
- @Override
- public void run() {
- finalDelegate.tcpConnectionProgressChanged(TcpConnection.this, lastMessageId, arg2, arg3);
- }
- });
- }
- }
- }
ByteBufferDesc reuseLater = null;
int len = currentPacketLength + (fByte != 0x7f ? 1 : 4);
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/UserConfig.java b/TMessagesProj/src/main/java/org/telegram/messenger/UserConfig.java
index 4869a96f..34b46978 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/UserConfig.java
+++ b/TMessagesProj/src/main/java/org/telegram/messenger/UserConfig.java
@@ -12,6 +12,7 @@ import android.content.Context;
import android.content.SharedPreferences;
import android.util.Base64;
+import org.telegram.android.MessagesStorage;
import org.telegram.ui.ApplicationLoader;
import java.io.File;
@@ -197,6 +198,5 @@ public class UserConfig {
contactsVersion = 1;
saveIncomingPhotos = false;
saveConfig(true);
- MessagesController.getInstance().deleteAllAppAccounts();
}
}
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/Utilities.java b/TMessagesProj/src/main/java/org/telegram/messenger/Utilities.java
index 59b64ffc..90665400 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/Utilities.java
+++ b/TMessagesProj/src/main/java/org/telegram/messenger/Utilities.java
@@ -14,11 +14,8 @@ import android.content.ContentUris;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
-import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.database.Cursor;
-import android.graphics.Point;
-import android.graphics.Typeface;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
@@ -27,16 +24,12 @@ import android.provider.MediaStore;
import android.text.Html;
import android.text.SpannableStringBuilder;
import android.util.Base64;
-import android.view.Display;
-import android.view.Surface;
-import android.view.View;
-import android.view.WindowManager;
-import android.view.inputmethod.InputMethodManager;
import net.hockeyapp.android.CrashManager;
import net.hockeyapp.android.CrashManagerListener;
import net.hockeyapp.android.UpdateManager;
+import org.telegram.android.LocaleController;
import org.telegram.ui.ApplicationLoader;
import java.io.ByteArrayInputStream;
@@ -49,7 +42,6 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.math.BigInteger;
import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
import java.nio.channels.FileChannel;
import java.security.KeyFactory;
import java.security.MessageDigest;
@@ -59,7 +51,6 @@ import java.security.spec.RSAPublicKeySpec;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
-import java.util.Hashtable;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -69,16 +60,9 @@ import java.util.zip.GZIPOutputStream;
import javax.crypto.Cipher;
public class Utilities {
- public static int statusBarHeight = 0;
- public static float density = 1;
- public static Point displaySize = new Point();
public static Pattern pattern = Pattern.compile("[0-9]+");
public static SecureRandom random = new SecureRandom();
private final static Integer lock = 1;
- private static int prevOrientation = -10;
-
- private static boolean waitingForSms = false;
- private static final Integer smsLock = 2;
public static ArrayList goodPrimes = new ArrayList();
@@ -108,12 +92,8 @@ public class Utilities {
R.drawable.group_blue,
R.drawable.group_yellow};
- public static int externalCacheNotAvailableState = 0;
-
final protected static char[] hexArray = "0123456789ABCDEF".toCharArray();
- private static final Hashtable cache = new Hashtable();
-
public static ProgressDialog progressDialog;
static {
@@ -128,7 +108,6 @@ public class Utilities {
FileLog.e("tmessages", e);
}
- density = ApplicationLoader.applicationContext.getResources().getDisplayMetrics().density;
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("primes", Context.MODE_PRIVATE);
String primes = preferences.getString("primes", null);
if (primes == null) {
@@ -149,96 +128,14 @@ public class Utilities {
goodPrimes.add("C71CAEB9C6B1C9048E6C522F70F13F73980D40238E3E21C14934D037563D930F48198A0AA7C14058229493D22530F4DBFA336F6E0AC925139543AED44CCE7C3720FD51F69458705AC68CD4FE6B6B13ABDC9746512969328454F18FAF8C595F642477FE96BB2A941D5BCD1D4AC8CC49880708FA9B378E3C4F3A9060BEE67CF9A4A4A695811051907E162753B56B0F6B410DBA74D8A84B2A14B3144E0EF1284754FD17ED950D5965B4B9DD46582DB1178D169C6BC465B0D6FF9CA3928FEF5B9AE4E418FC15E83EBEA0F87FA9FF5EED70050DED2849F47BF959D956850CE929851F0D8115F635B105EE2E4E15D04B2454BF6F4FADF034B10403119CD8E3B92FCC5B");
}
}
-
- checkDisplaySize();
}
public native static long doPQNative(long _what);
- public native static byte[] aesIgeEncryption(byte[] _what, byte[] _key, byte[] _iv, boolean encrypt, boolean changeIv, int len);
- public native static void aesIgeEncryption2(ByteBuffer _what, byte[] _key, byte[] _iv, boolean encrypt, boolean changeIv, int len);
public native static void loadBitmap(String path, int[] bitmap, int scale, int format, int width, int height);
+ private native static void aesIgeEncryption(ByteBuffer buffer, byte[] key, byte[] iv, boolean encrypt, int offset, int length);
- public static void lockOrientation(Activity activity) {
- if (prevOrientation != -10) {
- return;
- }
- try {
- prevOrientation = activity.getRequestedOrientation();
- WindowManager manager = (WindowManager)activity.getSystemService(Activity.WINDOW_SERVICE);
- if (manager != null && manager.getDefaultDisplay() != null) {
- int rotation = manager.getDefaultDisplay().getRotation();
- int orientation = activity.getResources().getConfiguration().orientation;
-
- if (rotation == Surface.ROTATION_270) {
- if (orientation == Configuration.ORIENTATION_PORTRAIT) {
- activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
- } else {
- if (Build.VERSION.SDK_INT >= 9) {
- activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
- } else {
- activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
- }
- }
- } else if (rotation == Surface.ROTATION_90) {
- if (orientation == Configuration.ORIENTATION_PORTRAIT) {
- if (Build.VERSION.SDK_INT >= 9) {
- activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
- } else {
- activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
- }
- } else {
- activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
- }
- } else if (rotation == Surface.ROTATION_0) {
- if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
- activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
- } else {
- activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
- }
- } else {
- if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
- if (Build.VERSION.SDK_INT >= 9) {
- activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
- } else {
- activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
- }
- } else {
- if (Build.VERSION.SDK_INT >= 9) {
- activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
- } else {
- activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
- }
- }
- }
- }
- } catch (Exception e) {
- FileLog.e("tmessages", e);
- }
- }
-
- public static void unlockOrientation(Activity activity) {
- try {
- if (prevOrientation != -10) {
- activity.setRequestedOrientation(prevOrientation);
- prevOrientation = -10;
- }
- } catch (Exception e) {
- FileLog.e("tmessages", e);
- }
- }
-
- public static boolean isWaitingForSms() {
- boolean value = false;
- synchronized (smsLock) {
- value = waitingForSms;
- }
- return value;
- }
-
- public static void setWaitingForSms(boolean value) {
- synchronized (smsLock) {
- waitingForSms = value;
- }
+ public static void aesIgeEncryption(ByteBuffer buffer, byte[] key, byte[] iv, boolean encrypt, boolean changeIv, int offset, int length) {
+ aesIgeEncryption(buffer, key, changeIv ? iv : iv.clone(), encrypt, offset, length);
}
public static Integer parseInt(String value) {
@@ -259,22 +156,6 @@ public class Utilities {
return null;
}
- public static File getCacheDir() {
- if (externalCacheNotAvailableState == 1 || externalCacheNotAvailableState == 0 && Environment.getExternalStorageState().startsWith(Environment.MEDIA_MOUNTED)) {
- externalCacheNotAvailableState = 1;
- File file = ApplicationLoader.applicationContext.getExternalCacheDir();
- if (file != null) {
- return file;
- }
- }
- externalCacheNotAvailableState = 2;
- File file = ApplicationLoader.applicationContext.getCacheDir();
- if (file != null) {
- return file;
- }
- return new File("");
- }
-
public static String bytesToHex(byte[] bytes) {
char[] hexChars = new char[bytes.length * 2];
int v;
@@ -286,14 +167,6 @@ public class Utilities {
return new String(hexChars);
}
- public static int dp(int value) {
- return (int)(Math.max(1, density * value));
- }
-
- public static int dpf(float value) {
- return (int)Math.ceil(density * value);
- }
-
public static boolean isGoodPrime(byte[] prime, int g) {
if (!(g >= 2 && g <= 7)) {
return false;
@@ -401,6 +274,18 @@ public class Utilities {
}
}
+ public static boolean arraysEquals(byte[] arr1, int offset1, byte[] arr2, int offset2) {
+ if (arr1 == null || arr2 == null || arr1.length - offset1 != arr2.length - offset2 || arr1.length - offset1 < 0) {
+ return false;
+ }
+ for (int a = offset1; a < arr1.length; a++) {
+ if (arr1[a + offset1] != arr2[a + offset2]) {
+ return false;
+ }
+ }
+ return true;
+ }
+
public static byte[] computeSHA1(byte[] convertme, int offset, int len) {
try {
MessageDigest md = MessageDigest.getInstance("SHA-1");
@@ -413,30 +298,29 @@ public class Utilities {
}
public static byte[] computeSHA1(ByteBuffer convertme, int offset, int len) {
+ int oldp = convertme.position();
+ int oldl = convertme.limit();
try {
MessageDigest md = MessageDigest.getInstance("SHA-1");
- int oldp = convertme.position();
- int oldl = convertme.limit();
convertme.position(offset);
convertme.limit(len);
md.update(convertme);
- convertme.position(oldp);
- convertme.limit(oldl);
return md.digest();
} catch (Exception e) {
FileLog.e("tmessages", e);
+ } finally {
+ convertme.limit(oldl);
+ convertme.position(oldp);
}
return null;
}
+ public static byte[] computeSHA1(ByteBuffer convertme) {
+ return computeSHA1(convertme, 0, convertme.limit());
+ }
+
public static byte[] computeSHA1(byte[] convertme) {
- try {
- MessageDigest md = MessageDigest.getInstance("SHA-1");
- return md.digest(convertme);
- } catch (Exception e) {
- FileLog.e("tmessages", e);
- }
- return null;
+ return computeSHA1(convertme, 0, convertme.length);
}
public static byte[] encryptWithRSA(BigInteger[] key, byte[] data) {
@@ -453,26 +337,9 @@ public class Utilities {
return null;
}
- public static byte[] longToBytes(long x) {
- ByteBuffer buffer = ByteBuffer.allocate(8);
- buffer.putLong(x);
- return buffer.array();
- }
-
public static long bytesToLong(byte[] bytes) {
- ByteBuffer buffer = ByteBuffer.allocate(8);
- buffer.order(ByteOrder.LITTLE_ENDIAN);
- buffer.put(bytes);
- buffer.flip();
- return buffer.getLong();
- }
-
- public static int bytesToInt(byte[] bytes) {
- ByteBuffer buffer = ByteBuffer.allocate(4);
- buffer.order(ByteOrder.LITTLE_ENDIAN);
- buffer.put(bytes);
- buffer.flip();
- return buffer.getInt();
+ return ((long) bytes[7] << 56) + (((long) bytes[6] & 0xFF) << 48) + (((long) bytes[5] & 0xFF) << 40) + (((long) bytes[4] & 0xFF) << 32)
+ + (((long) bytes[3] & 0xFF) << 24) + (((long) bytes[2] & 0xFF) << 16) + (((long) bytes[1] & 0xFF) << 8) + ((long) bytes[0] & 0xFF);
}
public static MessageKeyData generateMessageKeyData(byte[] authKey, byte[] messageKey, boolean incoming) {
@@ -562,51 +429,6 @@ public class Utilities {
return packedData;
}
- public static Typeface getTypeface(String assetPath) {
- synchronized (cache) {
- if (!cache.containsKey(assetPath)) {
- try {
- Typeface t = Typeface.createFromAsset(ApplicationLoader.applicationContext.getAssets(),
- assetPath);
- cache.put(assetPath, t);
- } catch (Exception e) {
- FileLog.e("Typefaces", "Could not get typeface '" + assetPath + "' because " + e.getMessage());
- return null;
- }
- }
- return cache.get(assetPath);
- }
- }
-
- public static void showKeyboard(View view) {
- if (view == null) {
- return;
- }
- InputMethodManager inputManager = (InputMethodManager)view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
- inputManager.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
-
- ((InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(view, 0);
- }
-
- public static boolean isKeyboardShowed(View view) {
- if (view == null) {
- return false;
- }
- InputMethodManager inputManager = (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
- return inputManager.isActive(view);
- }
-
- public static void hideKeyboard(View view) {
- if (view == null) {
- return;
- }
- InputMethodManager imm = (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
- if (!imm.isActive()) {
- return;
- }
- imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
- }
-
public static void ShowProgressDialog(final Activity activity, final String message) {
activity.runOnUiThread(new Runnable() {
@Override
@@ -624,25 +446,6 @@ public class Utilities {
});
}
- public static void checkDisplaySize() {
- try {
- WindowManager manager = (WindowManager)ApplicationLoader.applicationContext.getSystemService(Context.WINDOW_SERVICE);
- if (manager != null) {
- Display display = manager.getDefaultDisplay();
- if (display != null) {
- if(android.os.Build.VERSION.SDK_INT < 13) {
- displaySize.set(display.getWidth(), display.getHeight());
- } else {
- display.getSize(displaySize);
- }
- FileLog.e("tmessages", "display size = " + displaySize.x + " " + displaySize.y);
- }
- }
- } catch (Exception e) {
- FileLog.e("tmessages", e);
- }
- }
-
public static void HideProgressDialog(Activity activity) {
activity.runOnUiThread(new Runnable() {
@Override
diff --git a/TMessagesProj/src/main/java/org/telegram/objects/MessageObject.java b/TMessagesProj/src/main/java/org/telegram/objects/MessageObject.java
index c3a28d8a..168ec0a8 100644
--- a/TMessagesProj/src/main/java/org/telegram/objects/MessageObject.java
+++ b/TMessagesProj/src/main/java/org/telegram/objects/MessageObject.java
@@ -16,12 +16,13 @@ import android.text.StaticLayout;
import android.text.TextPaint;
import android.text.util.Linkify;
+import org.telegram.android.AndroidUtilities;
import org.telegram.messenger.FileLog;
-import org.telegram.messenger.LocaleController;
+import org.telegram.android.LocaleController;
import org.telegram.messenger.TLObject;
import org.telegram.messenger.TLRPC;
-import org.telegram.messenger.Emoji;
-import org.telegram.messenger.MessagesController;
+import org.telegram.android.Emoji;
+import org.telegram.android.MessagesController;
import org.telegram.messenger.R;
import org.telegram.messenger.UserConfig;
import org.telegram.messenger.Utilities;
@@ -68,7 +69,7 @@ public class MessageObject {
textPaint.linkColor = 0xff316f9f;
}
- textPaint.setTextSize(Utilities.dp(MessagesController.getInstance().fontSize));
+ textPaint.setTextSize(AndroidUtilities.dp(MessagesController.getInstance().fontSize));
messageOwner = message;
@@ -271,7 +272,7 @@ public class MessageObject {
} else {
messageText = message.message;
}
- messageText = Emoji.replaceEmoji(messageText, textPaint.getFontMetricsInt(), Utilities.dp(20));
+ messageText = Emoji.replaceEmoji(messageText, textPaint.getFontMetricsInt(), AndroidUtilities.dp(20));
if (message instanceof TLRPC.TL_message || (message instanceof TLRPC.TL_messageForwarded && (message.media == null || !(message.media instanceof TLRPC.TL_messageMediaEmpty)))) {
if (message.media == null || message.media instanceof TLRPC.TL_messageMediaEmpty) {
@@ -397,9 +398,9 @@ public class MessageObject {
int maxWidth;
if (messageOwner.to_id.chat_id != 0) {
- maxWidth = Math.min(Utilities.displaySize.x, Utilities.displaySize.y) - Utilities.dp(122);
+ maxWidth = Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) - AndroidUtilities.dp(122);
} else {
- maxWidth = Math.min(Utilities.displaySize.x, Utilities.displaySize.y) - Utilities.dp(80);
+ maxWidth = Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) - AndroidUtilities.dp(80);
}
StaticLayout textLayout = null;
@@ -539,4 +540,18 @@ public class MessageObject {
public boolean isFromMe() {
return messageOwner.from_id == UserConfig.getClientUserId();
}
+
+ public long getDialogId() {
+ if (messageOwner.dialog_id != 0) {
+ return messageOwner.dialog_id;
+ } else {
+ if (messageOwner.to_id.chat_id != 0) {
+ return -messageOwner.to_id.chat_id;
+ } else if (isFromMe()) {
+ return messageOwner.to_id.user_id;
+ } else {
+ return messageOwner.from_id;
+ }
+ }
+ }
}
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Adapters/ContactsActivityAdapter.java b/TMessagesProj/src/main/java/org/telegram/ui/Adapters/ContactsActivityAdapter.java
index f341e93a..190f9998 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/Adapters/ContactsActivityAdapter.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/Adapters/ContactsActivityAdapter.java
@@ -14,10 +14,10 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
-import org.telegram.messenger.LocaleController;
+import org.telegram.android.LocaleController;
import org.telegram.messenger.TLRPC;
-import org.telegram.messenger.ContactsController;
-import org.telegram.messenger.MessagesController;
+import org.telegram.android.ContactsController;
+import org.telegram.android.MessagesController;
import org.telegram.messenger.R;
import org.telegram.ui.Cells.ChatOrUserCell;
import org.telegram.ui.Views.SectionedBaseAdapter;
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Adapters/ContactsActivitySearchAdapter.java b/TMessagesProj/src/main/java/org/telegram/ui/Adapters/ContactsActivitySearchAdapter.java
index 0da5808d..b7436d73 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/Adapters/ContactsActivitySearchAdapter.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/Adapters/ContactsActivitySearchAdapter.java
@@ -13,9 +13,9 @@ import android.view.View;
import android.view.ViewGroup;
import org.telegram.messenger.TLRPC;
-import org.telegram.messenger.ContactsController;
+import org.telegram.android.ContactsController;
import org.telegram.messenger.FileLog;
-import org.telegram.messenger.MessagesController;
+import org.telegram.android.MessagesController;
import org.telegram.messenger.UserConfig;
import org.telegram.messenger.Utilities;
import org.telegram.ui.Cells.ChatOrUserCell;
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ApplicationLoader.java b/TMessagesProj/src/main/java/org/telegram/ui/ApplicationLoader.java
index 52a7660e..f93145ef 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/ApplicationLoader.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/ApplicationLoader.java
@@ -29,14 +29,15 @@ import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.gcm.GoogleCloudMessaging;
-import org.telegram.messenger.NotificationsService;
+import org.telegram.android.AndroidUtilities;
+import org.telegram.android.NotificationsService;
import org.telegram.messenger.BuildVars;
import org.telegram.messenger.ConnectionsManager;
import org.telegram.messenger.FileLog;
-import org.telegram.messenger.LocaleController;
-import org.telegram.messenger.MessagesController;
-import org.telegram.messenger.NativeLoader;
-import org.telegram.messenger.ScreenReceiver;
+import org.telegram.android.LocaleController;
+import org.telegram.android.MessagesController;
+import org.telegram.android.NativeLoader;
+import org.telegram.android.ScreenReceiver;
import org.telegram.messenger.UserConfig;
import org.telegram.messenger.Utilities;
@@ -57,6 +58,7 @@ public class ApplicationLoader extends Application {
private static volatile boolean applicationInited = false;
public static volatile boolean isScreenOn = false;
+ public static volatile boolean mainInterfacePaused = true;
public static void postInitApplication() {
if (applicationInited) {
@@ -65,8 +67,6 @@ public class ApplicationLoader extends Application {
applicationInited = true;
- NativeLoader.initNativeLibs(applicationContext);
-
try {
LocaleController.getInstance();
} catch (Exception e) {
@@ -134,6 +134,7 @@ public class ApplicationLoader extends Application {
public void onCreate() {
super.onCreate();
applicationContext = getApplicationContext();
+ NativeLoader.initNativeLibs(ApplicationLoader.applicationContext);
applicationHandler = new Handler(applicationContext.getMainLooper());
@@ -177,7 +178,7 @@ public class ApplicationLoader extends Application {
super.onConfigurationChanged(newConfig);
try {
LocaleController.getInstance().onDeviceConfigurationChange(newConfig);
- Utilities.checkDisplaySize();
+ AndroidUtilities.checkDisplaySize();
} catch (Exception e) {
e.printStackTrace();
}
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatAudioCell.java b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatAudioCell.java
index 10d5c1cd..0c61b173 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatAudioCell.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatAudioCell.java
@@ -16,12 +16,12 @@ import android.text.StaticLayout;
import android.text.TextPaint;
import android.view.MotionEvent;
import android.view.SoundEffectConstants;
-import android.view.View;
+import org.telegram.android.AndroidUtilities;
import org.telegram.messenger.FileLoader;
-import org.telegram.messenger.MediaController;
+import org.telegram.android.MediaController;
import org.telegram.messenger.TLRPC;
-import org.telegram.messenger.MessagesController;
+import org.telegram.android.MessagesController;
import org.telegram.messenger.R;
import org.telegram.messenger.Utilities;
import org.telegram.objects.MessageObject;
@@ -30,7 +30,6 @@ import org.telegram.ui.Views.ProgressView;
import org.telegram.ui.Views.SeekBar;
import java.io.File;
-import java.lang.ref.WeakReference;
public class ChatAudioCell extends ChatBaseCell implements SeekBar.SeekBarDelegate, MediaController.FileDownloadProgressListener {
@@ -90,7 +89,7 @@ public class ChatAudioCell extends ChatBaseCell implements SeekBar.SeekBarDelega
statesDrawable[7][1] = getResources().getDrawable(R.drawable.audiocancel2_pressed);
timePaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
- timePaint.setTextSize(Utilities.dp(12));
+ timePaint.setTextSize(AndroidUtilities.dp(12));
}
}
@@ -115,7 +114,7 @@ public class ChatAudioCell extends ChatBaseCell implements SeekBar.SeekBarDelega
}
invalidate();
} else {
- int side = Utilities.dp(36);
+ int side = AndroidUtilities.dp(36);
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (x >= buttonX && x <= buttonX + side && y >= buttonY && y <= buttonY + side) {
buttonPressed = 1;
@@ -220,7 +219,7 @@ public class ChatAudioCell extends ChatBaseCell implements SeekBar.SeekBarDelega
public void updateButtonState() {
String fileName = currentMessageObject.getFileName();
- File cacheFile = new File(Utilities.getCacheDir(), fileName);
+ File cacheFile = new File(AndroidUtilities.getCacheDir(), fileName);
if (cacheFile.exists()) {
MediaController.getInstance().removeLoadingFileObserver(this);
boolean playing = MediaController.getInstance().isPlayingAudio(currentMessageObject);
@@ -286,11 +285,11 @@ public class ChatAudioCell extends ChatBaseCell implements SeekBar.SeekBarDelega
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int width = MeasureSpec.getSize(widthMeasureSpec);
- setMeasuredDimension(width, Utilities.dp(68));
+ setMeasuredDimension(width, AndroidUtilities.dp(68));
if (isChat) {
- backgroundWidth = Math.min(width - Utilities.dp(102), Utilities.dp(300));
+ backgroundWidth = Math.min(width - AndroidUtilities.dp(102), AndroidUtilities.dp(300));
} else {
- backgroundWidth = Math.min(width - Utilities.dp(50), Utilities.dp(300));
+ backgroundWidth = Math.min(width - AndroidUtilities.dp(50), AndroidUtilities.dp(300));
}
}
@@ -299,33 +298,33 @@ public class ChatAudioCell extends ChatBaseCell implements SeekBar.SeekBarDelega
super.onLayout(changed, left, top, right, bottom);
if (currentMessageObject.isOut()) {
- avatarImage.imageX = layoutWidth - backgroundWidth + Utilities.dp(9);
- seekBarX = layoutWidth - backgroundWidth + Utilities.dp(97);
- buttonX = layoutWidth - backgroundWidth + Utilities.dp(67);
- timeX = layoutWidth - backgroundWidth + Utilities.dp(71);
+ avatarImage.imageX = layoutWidth - backgroundWidth + AndroidUtilities.dp(9);
+ seekBarX = layoutWidth - backgroundWidth + AndroidUtilities.dp(97);
+ buttonX = layoutWidth - backgroundWidth + AndroidUtilities.dp(67);
+ timeX = layoutWidth - backgroundWidth + AndroidUtilities.dp(71);
} else {
if (isChat) {
- avatarImage.imageX = Utilities.dp(69);
- seekBarX = Utilities.dp(158);
- buttonX = Utilities.dp(128);
- timeX = Utilities.dp(132);
+ avatarImage.imageX = AndroidUtilities.dp(69);
+ seekBarX = AndroidUtilities.dp(158);
+ buttonX = AndroidUtilities.dp(128);
+ timeX = AndroidUtilities.dp(132);
} else {
- avatarImage.imageX = Utilities.dp(16);
- seekBarX = Utilities.dp(106);
- buttonX = Utilities.dp(76);
- timeX = Utilities.dp(80);
+ avatarImage.imageX = AndroidUtilities.dp(16);
+ seekBarX = AndroidUtilities.dp(106);
+ buttonX = AndroidUtilities.dp(76);
+ timeX = AndroidUtilities.dp(80);
}
}
- avatarImage.imageY = Utilities.dp(9);
- avatarImage.imageW = Utilities.dp(50);
- avatarImage.imageH = Utilities.dp(50);
+ avatarImage.imageY = AndroidUtilities.dp(9);
+ avatarImage.imageW = AndroidUtilities.dp(50);
+ avatarImage.imageH = AndroidUtilities.dp(50);
- seekBar.width = backgroundWidth - Utilities.dp(112);
- seekBar.height = Utilities.dp(30);
- progressView.width = backgroundWidth - Utilities.dp(136);
- progressView.height = Utilities.dp(30);
- seekBarY = Utilities.dp(13);
- buttonY = Utilities.dp(10);
+ seekBar.width = backgroundWidth - AndroidUtilities.dp(112);
+ seekBar.height = AndroidUtilities.dp(30);
+ progressView.width = backgroundWidth - AndroidUtilities.dp(136);
+ progressView.height = AndroidUtilities.dp(30);
+ seekBarY = AndroidUtilities.dp(13);
+ buttonY = AndroidUtilities.dp(10);
updateProgress();
}
@@ -380,14 +379,14 @@ public class ChatAudioCell extends ChatBaseCell implements SeekBar.SeekBarDelega
return;
}
- avatarImage.draw(canvas, avatarImage.imageX, avatarImage.imageY, Utilities.dp(50), Utilities.dp(50));
+ avatarImage.draw(canvas, avatarImage.imageX, avatarImage.imageY, AndroidUtilities.dp(50), AndroidUtilities.dp(50));
canvas.save();
if (buttonState == 0 || buttonState == 1) {
canvas.translate(seekBarX, seekBarY);
seekBar.draw(canvas);
} else {
- canvas.translate(seekBarX + Utilities.dp(12), seekBarY);
+ canvas.translate(seekBarX + AndroidUtilities.dp(12), seekBarY);
progressView.draw(canvas);
}
canvas.restore();
@@ -400,14 +399,14 @@ public class ChatAudioCell extends ChatBaseCell implements SeekBar.SeekBarDelega
timePaint.setColor(0xff70b15c);
}
Drawable buttonDrawable = statesDrawable[state][buttonPressed];
- int side = Utilities.dp(36);
+ int side = AndroidUtilities.dp(36);
int x = (side - buttonDrawable.getIntrinsicWidth()) / 2;
int y = (side - buttonDrawable.getIntrinsicHeight()) / 2;
setDrawableBounds(buttonDrawable, x + buttonX, y + buttonY);
buttonDrawable.draw(canvas);
canvas.save();
- canvas.translate(timeX, Utilities.dp(45));
+ canvas.translate(timeX, AndroidUtilities.dp(45));
timeLayout.draw(canvas);
canvas.restore();
}
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatBaseCell.java b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatBaseCell.java
index 552b411f..d8f4aa58 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatBaseCell.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatBaseCell.java
@@ -22,9 +22,10 @@ import android.view.MotionEvent;
import android.view.SoundEffectConstants;
import android.view.ViewConfiguration;
-import org.telegram.messenger.LocaleController;
+import org.telegram.android.AndroidUtilities;
+import org.telegram.android.LocaleController;
import org.telegram.messenger.TLRPC;
-import org.telegram.messenger.MessagesController;
+import org.telegram.android.MessagesController;
import org.telegram.messenger.R;
import org.telegram.messenger.Utilities;
import org.telegram.objects.MessageObject;
@@ -176,22 +177,22 @@ public class ChatBaseCell extends BaseCell {
mediaBackgroundDrawable = getResources().getDrawable(R.drawable.phototime);
timePaintIn = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
- timePaintIn.setTextSize(Utilities.dp(12));
+ timePaintIn.setTextSize(AndroidUtilities.dp(12));
timePaintIn.setColor(0xffa1aab3);
timePaintOut = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
- timePaintOut.setTextSize(Utilities.dp(12));
+ timePaintOut.setTextSize(AndroidUtilities.dp(12));
timePaintOut.setColor(0xff70b15c);
timeMediaPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
- timeMediaPaint.setTextSize(Utilities.dp(12));
+ timeMediaPaint.setTextSize(AndroidUtilities.dp(12));
timeMediaPaint.setColor(0xffffffff);
namePaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
- namePaint.setTextSize(Utilities.dp(15));
+ namePaint.setTextSize(AndroidUtilities.dp(15));
forwardNamePaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
- forwardNamePaint.setTextSize(Utilities.dp(14));
+ forwardNamePaint.setTextSize(AndroidUtilities.dp(14));
}
}
@@ -286,11 +287,11 @@ public class ChatBaseCell extends BaseCell {
currentNameString = Utilities.formatName(currentUser.first_name, currentUser.last_name);
nameWidth = getMaxNameWidth();
- CharSequence nameStringFinal = TextUtils.ellipsize(currentNameString.replace("\n", " "), namePaint, nameWidth - Utilities.dp(12), TextUtils.TruncateAt.END);
+ CharSequence nameStringFinal = TextUtils.ellipsize(currentNameString.replace("\n", " "), namePaint, nameWidth - AndroidUtilities.dp(12), TextUtils.TruncateAt.END);
nameLayout = new StaticLayout(nameStringFinal, namePaint, nameWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
if (nameLayout.getLineCount() > 0) {
nameWidth = (int)Math.ceil(nameLayout.getLineWidth(0));
- namesOffset += Utilities.dp(18);
+ namesOffset += AndroidUtilities.dp(18);
nameOffsetX = nameLayout.getLineLeft(0);
} else {
nameWidth = 0;
@@ -308,12 +309,12 @@ public class ChatBaseCell extends BaseCell {
forwardedNameWidth = getMaxNameWidth();
- CharSequence str = TextUtils.ellipsize(currentForwardNameString.replace("\n", " "), forwardNamePaint, forwardedNameWidth - Utilities.dp(40), TextUtils.TruncateAt.END);
+ CharSequence str = TextUtils.ellipsize(currentForwardNameString.replace("\n", " "), forwardNamePaint, forwardedNameWidth - AndroidUtilities.dp(40), TextUtils.TruncateAt.END);
str = Html.fromHtml(String.format("%s
%s %s", LocaleController.getString("ForwardedMessage", R.string.ForwardedMessage), LocaleController.getString("From", R.string.From), str));
forwardedNameLayout = new StaticLayout(str, forwardNamePaint, forwardedNameWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
if (forwardedNameLayout.getLineCount() > 1) {
forwardedNameWidth = Math.max((int) Math.ceil(forwardedNameLayout.getLineWidth(0)), (int) Math.ceil(forwardedNameLayout.getLineWidth(1)));
- namesOffset += Utilities.dp(36);
+ namesOffset += AndroidUtilities.dp(36);
forwardNameOffsetX = Math.min(forwardedNameLayout.getLineLeft(0), forwardedNameLayout.getLineLeft(1));
} else {
forwardedNameWidth = 0;
@@ -337,7 +338,7 @@ public class ChatBaseCell extends BaseCell {
}
protected int getMaxNameWidth() {
- return backgroundWidth - Utilities.dp(8);
+ return backgroundWidth - AndroidUtilities.dp(8);
}
protected void startCheckLongPress() {
@@ -372,7 +373,7 @@ public class ChatBaseCell extends BaseCell {
avatarPressed = true;
result = true;
} else if (drawForwardedName && forwardedNameLayout != null) {
- if (x >= forwardNameX && x <= forwardNameX + forwardedNameWidth && y >= forwardNameY && y <= forwardNameY + Utilities.dp(32)) {
+ if (x >= forwardNameX && x <= forwardNameX + forwardedNameWidth && y >= forwardNameY && y <= forwardNameY + AndroidUtilities.dp(32)) {
forwardNamePressed = true;
result = true;
}
@@ -409,7 +410,7 @@ public class ChatBaseCell extends BaseCell {
} else if (event.getAction() == MotionEvent.ACTION_CANCEL) {
forwardNamePressed = false;
} else if (event.getAction() == MotionEvent.ACTION_MOVE) {
- if (!(x >= forwardNameX && x <= forwardNameX + forwardedNameWidth && y >= forwardNameY && y <= forwardNameY + Utilities.dp(32))) {
+ if (!(x >= forwardNameX && x <= forwardNameX + forwardedNameWidth && y >= forwardNameY && y <= forwardNameY + AndroidUtilities.dp(32))) {
forwardNamePressed = false;
}
}
@@ -433,23 +434,23 @@ public class ChatBaseCell extends BaseCell {
timeLayout = new StaticLayout(currentTimeString, currentTimePaint, timeWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
if (!media) {
if (!currentMessageObject.isOut()) {
- timeX = backgroundWidth - Utilities.dp(9) - timeWidth + (isChat ? Utilities.dp(52) : 0);
+ timeX = backgroundWidth - AndroidUtilities.dp(9) - timeWidth + (isChat ? AndroidUtilities.dp(52) : 0);
} else {
- timeX = layoutWidth - timeWidth - Utilities.dpf(38.5f);
+ timeX = layoutWidth - timeWidth - AndroidUtilities.dpf(38.5f);
}
} else {
if (!currentMessageObject.isOut()) {
- timeX = backgroundWidth - Utilities.dp(4) - timeWidth + (isChat ? Utilities.dp(52) : 0);
+ timeX = backgroundWidth - AndroidUtilities.dp(4) - timeWidth + (isChat ? AndroidUtilities.dp(52) : 0);
} else {
- timeX = layoutWidth - timeWidth - Utilities.dpf(42.0f);
+ timeX = layoutWidth - timeWidth - AndroidUtilities.dpf(42.0f);
}
}
if (isAvatarVisible) {
- avatarImage.imageX = Utilities.dp(6);
- avatarImage.imageY = layoutHeight - Utilities.dp(45);
- avatarImage.imageW = Utilities.dp(42);
- avatarImage.imageH = Utilities.dp(42);
+ avatarImage.imageX = AndroidUtilities.dp(6);
+ avatarImage.imageY = layoutHeight - AndroidUtilities.dp(45);
+ avatarImage.imageW = AndroidUtilities.dp(42);
+ avatarImage.imageH = AndroidUtilities.dp(42);
}
wasLayout = true;
@@ -473,7 +474,7 @@ public class ChatBaseCell extends BaseCell {
}
if (isAvatarVisible) {
- avatarImage.draw(canvas, Utilities.dp(6), layoutHeight - Utilities.dp(45), Utilities.dp(42), Utilities.dp(42));
+ avatarImage.draw(canvas, AndroidUtilities.dp(6), layoutHeight - AndroidUtilities.dp(45), AndroidUtilities.dp(42), AndroidUtilities.dp(42));
}
Drawable currentBackgroundDrawable = null;
@@ -491,7 +492,7 @@ public class ChatBaseCell extends BaseCell {
currentBackgroundDrawable = backgroundMediaDrawableOut;
}
}
- setDrawableBounds(currentBackgroundDrawable, layoutWidth - backgroundWidth - (!media ? 0 : Utilities.dp(9)), Utilities.dp(1), backgroundWidth, layoutHeight - Utilities.dp(2));
+ setDrawableBounds(currentBackgroundDrawable, layoutWidth - backgroundWidth - (!media ? 0 : AndroidUtilities.dp(9)), AndroidUtilities.dp(1), backgroundWidth, layoutHeight - AndroidUtilities.dp(2));
} else {
if (isPressed() && isCheckPressed || !isCheckPressed && isPressed) {
if (!media) {
@@ -507,9 +508,9 @@ public class ChatBaseCell extends BaseCell {
}
}
if (isChat) {
- setDrawableBounds(currentBackgroundDrawable, Utilities.dp(52 + (!media ? 0 : 9)), Utilities.dp(1), backgroundWidth, layoutHeight - Utilities.dp(2));
+ setDrawableBounds(currentBackgroundDrawable, AndroidUtilities.dp(52 + (!media ? 0 : 9)), AndroidUtilities.dp(1), backgroundWidth, layoutHeight - AndroidUtilities.dp(2));
} else {
- setDrawableBounds(currentBackgroundDrawable, (!media ? 0 : Utilities.dp(9)), Utilities.dp(1), backgroundWidth, layoutHeight - Utilities.dp(2));
+ setDrawableBounds(currentBackgroundDrawable, (!media ? 0 : AndroidUtilities.dp(9)), AndroidUtilities.dp(1), backgroundWidth, layoutHeight - AndroidUtilities.dp(2));
}
}
currentBackgroundDrawable.draw(canvas);
@@ -518,7 +519,7 @@ public class ChatBaseCell extends BaseCell {
if (drawName && nameLayout != null) {
canvas.save();
- canvas.translate(currentBackgroundDrawable.getBounds().left + Utilities.dp(19) - nameOffsetX, Utilities.dp(10));
+ canvas.translate(currentBackgroundDrawable.getBounds().left + AndroidUtilities.dp(19) - nameOffsetX, AndroidUtilities.dp(10));
namePaint.setColor(Utilities.getColorForId(currentUser.id));
nameLayout.draw(canvas);
canvas.restore();
@@ -528,12 +529,12 @@ public class ChatBaseCell extends BaseCell {
canvas.save();
if (currentMessageObject.isOut()) {
forwardNamePaint.setColor(0xff4a923c);
- forwardNameX = currentBackgroundDrawable.getBounds().left + Utilities.dp(10);
- forwardNameY = Utilities.dp(10 + (drawName ? 18 : 0));
+ forwardNameX = currentBackgroundDrawable.getBounds().left + AndroidUtilities.dp(10);
+ forwardNameY = AndroidUtilities.dp(10 + (drawName ? 18 : 0));
} else {
forwardNamePaint.setColor(0xff006fc8);
- forwardNameX = currentBackgroundDrawable.getBounds().left + Utilities.dp(19);
- forwardNameY = Utilities.dp(10 + (drawName ? 18 : 0));
+ forwardNameX = currentBackgroundDrawable.getBounds().left + AndroidUtilities.dp(19);
+ forwardNameY = AndroidUtilities.dp(10 + (drawName ? 18 : 0));
}
canvas.translate(forwardNameX - forwardNameOffsetX, forwardNameY);
forwardedNameLayout.draw(canvas);
@@ -542,16 +543,16 @@ public class ChatBaseCell extends BaseCell {
if (drawTime) {
if (media) {
- setDrawableBounds(mediaBackgroundDrawable, timeX - Utilities.dp(3), layoutHeight - Utilities.dpf(27.5f), timeWidth + Utilities.dp(6 + (currentMessageObject.isOut() ? 20 : 0)), Utilities.dpf(16.5f));
+ setDrawableBounds(mediaBackgroundDrawable, timeX - AndroidUtilities.dp(3), layoutHeight - AndroidUtilities.dpf(27.5f), timeWidth + AndroidUtilities.dp(6 + (currentMessageObject.isOut() ? 20 : 0)), AndroidUtilities.dpf(16.5f));
mediaBackgroundDrawable.draw(canvas);
canvas.save();
- canvas.translate(timeX, layoutHeight - Utilities.dpf(12.0f) - timeLayout.getHeight());
+ canvas.translate(timeX, layoutHeight - AndroidUtilities.dpf(12.0f) - timeLayout.getHeight());
timeLayout.draw(canvas);
canvas.restore();
} else {
canvas.save();
- canvas.translate(timeX, layoutHeight - Utilities.dpf(6.5f) - timeLayout.getHeight());
+ canvas.translate(timeX, layoutHeight - AndroidUtilities.dpf(6.5f) - timeLayout.getHeight());
timeLayout.draw(canvas);
canvas.restore();
}
@@ -586,45 +587,45 @@ public class ChatBaseCell extends BaseCell {
if (drawClock) {
if (!media) {
- setDrawableBounds(clockDrawable, layoutWidth - Utilities.dpf(18.5f) - clockDrawable.getIntrinsicWidth(), layoutHeight - Utilities.dpf(8.5f) - clockDrawable.getIntrinsicHeight());
+ setDrawableBounds(clockDrawable, layoutWidth - AndroidUtilities.dpf(18.5f) - clockDrawable.getIntrinsicWidth(), layoutHeight - AndroidUtilities.dpf(8.5f) - clockDrawable.getIntrinsicHeight());
clockDrawable.draw(canvas);
} else {
- setDrawableBounds(clockMediaDrawable, layoutWidth - Utilities.dpf(22.0f) - clockMediaDrawable.getIntrinsicWidth(), layoutHeight - Utilities.dpf(13.0f) - clockMediaDrawable.getIntrinsicHeight());
+ setDrawableBounds(clockMediaDrawable, layoutWidth - AndroidUtilities.dpf(22.0f) - clockMediaDrawable.getIntrinsicWidth(), layoutHeight - AndroidUtilities.dpf(13.0f) - clockMediaDrawable.getIntrinsicHeight());
clockMediaDrawable.draw(canvas);
}
}
if (drawCheck2) {
if (!media) {
if (drawCheck1) {
- setDrawableBounds(checkDrawable, layoutWidth - Utilities.dpf(22.5f) - checkDrawable.getIntrinsicWidth(), layoutHeight - Utilities.dpf(8.5f) - checkDrawable.getIntrinsicHeight());
+ setDrawableBounds(checkDrawable, layoutWidth - AndroidUtilities.dpf(22.5f) - checkDrawable.getIntrinsicWidth(), layoutHeight - AndroidUtilities.dpf(8.5f) - checkDrawable.getIntrinsicHeight());
} else {
- setDrawableBounds(checkDrawable, layoutWidth - Utilities.dpf(18.5f) - checkDrawable.getIntrinsicWidth(), layoutHeight - Utilities.dpf(8.5f) - checkDrawable.getIntrinsicHeight());
+ setDrawableBounds(checkDrawable, layoutWidth - AndroidUtilities.dpf(18.5f) - checkDrawable.getIntrinsicWidth(), layoutHeight - AndroidUtilities.dpf(8.5f) - checkDrawable.getIntrinsicHeight());
}
checkDrawable.draw(canvas);
} else {
if (drawCheck1) {
- setDrawableBounds(checkMediaDrawable, layoutWidth - Utilities.dpf(26.0f) - checkMediaDrawable.getIntrinsicWidth(), layoutHeight - Utilities.dpf(13.0f) - checkMediaDrawable.getIntrinsicHeight());
+ setDrawableBounds(checkMediaDrawable, layoutWidth - AndroidUtilities.dpf(26.0f) - checkMediaDrawable.getIntrinsicWidth(), layoutHeight - AndroidUtilities.dpf(13.0f) - checkMediaDrawable.getIntrinsicHeight());
} else {
- setDrawableBounds(checkMediaDrawable, layoutWidth - Utilities.dpf(22.0f) - checkMediaDrawable.getIntrinsicWidth(), layoutHeight - Utilities.dpf(13.0f) - checkMediaDrawable.getIntrinsicHeight());
+ setDrawableBounds(checkMediaDrawable, layoutWidth - AndroidUtilities.dpf(22.0f) - checkMediaDrawable.getIntrinsicWidth(), layoutHeight - AndroidUtilities.dpf(13.0f) - checkMediaDrawable.getIntrinsicHeight());
}
checkMediaDrawable.draw(canvas);
}
}
if (drawCheck1) {
if (!media) {
- setDrawableBounds(halfCheckDrawable, layoutWidth - Utilities.dp(18) - halfCheckDrawable.getIntrinsicWidth(), layoutHeight - Utilities.dpf(8.5f) - halfCheckDrawable.getIntrinsicHeight());
+ setDrawableBounds(halfCheckDrawable, layoutWidth - AndroidUtilities.dp(18) - halfCheckDrawable.getIntrinsicWidth(), layoutHeight - AndroidUtilities.dpf(8.5f) - halfCheckDrawable.getIntrinsicHeight());
halfCheckDrawable.draw(canvas);
} else {
- setDrawableBounds(halfCheckMediaDrawable, layoutWidth - Utilities.dpf(20.5f) - halfCheckMediaDrawable.getIntrinsicWidth(), layoutHeight - Utilities.dpf(13.0f) - halfCheckMediaDrawable.getIntrinsicHeight());
+ setDrawableBounds(halfCheckMediaDrawable, layoutWidth - AndroidUtilities.dpf(20.5f) - halfCheckMediaDrawable.getIntrinsicWidth(), layoutHeight - AndroidUtilities.dpf(13.0f) - halfCheckMediaDrawable.getIntrinsicHeight());
halfCheckMediaDrawable.draw(canvas);
}
}
if (drawError) {
if (!media) {
- setDrawableBounds(errorDrawable, layoutWidth - Utilities.dp(18) - errorDrawable.getIntrinsicWidth(), layoutHeight - Utilities.dpf(6.5f) - errorDrawable.getIntrinsicHeight());
+ setDrawableBounds(errorDrawable, layoutWidth - AndroidUtilities.dp(18) - errorDrawable.getIntrinsicWidth(), layoutHeight - AndroidUtilities.dpf(6.5f) - errorDrawable.getIntrinsicHeight());
errorDrawable.draw(canvas);
} else {
- setDrawableBounds(errorDrawable, layoutWidth - Utilities.dpf(20.5f) - errorDrawable.getIntrinsicWidth(), layoutHeight - Utilities.dpf(12.5f) - errorDrawable.getIntrinsicHeight());
+ setDrawableBounds(errorDrawable, layoutWidth - AndroidUtilities.dpf(20.5f) - errorDrawable.getIntrinsicWidth(), layoutHeight - AndroidUtilities.dpf(12.5f) - errorDrawable.getIntrinsicHeight());
errorDrawable.draw(canvas);
}
}
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMediaCell.java b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMediaCell.java
index 708c6f09..a66e3085 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMediaCell.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMediaCell.java
@@ -18,12 +18,12 @@ import android.text.StaticLayout;
import android.text.TextPaint;
import android.view.MotionEvent;
import android.view.SoundEffectConstants;
-import android.view.View;
+import org.telegram.android.AndroidUtilities;
import org.telegram.messenger.ConnectionsManager;
import org.telegram.messenger.FileLoader;
-import org.telegram.messenger.MediaController;
-import org.telegram.messenger.MessagesController;
+import org.telegram.android.MediaController;
+import org.telegram.android.MessagesController;
import org.telegram.messenger.R;
import org.telegram.messenger.Utilities;
import org.telegram.objects.MessageObject;
@@ -34,7 +34,6 @@ import org.telegram.ui.Views.ImageReceiver;
import org.telegram.ui.Views.ProgressView;
import java.io.File;
-import java.lang.ref.WeakReference;
import java.util.Locale;
public class ChatMediaCell extends ChatBaseCell implements MediaController.FileDownloadProgressListener {
@@ -96,7 +95,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
infoPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
infoPaint.setColor(0xffffffff);
- infoPaint.setTextSize(Utilities.dp(12));
+ infoPaint.setTextSize(AndroidUtilities.dp(12));
}
TAG = MediaController.getInstance().generateObserverTag();
@@ -136,7 +135,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
float y = event.getY();
boolean result = false;
- int side = Utilities.dp(44);
+ int side = AndroidUtilities.dp(44);
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (delegate == null || delegate.canPerformActions()) {
if (buttonState != -1 && x >= buttonX && x <= buttonX + side && y >= buttonY && y <= buttonY + side) {
@@ -285,7 +284,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
}
double lat = object.messageOwner.media.geo.lat;
double lon = object.messageOwner.media.geo._long;
- String url = String.format(Locale.US, "https://maps.googleapis.com/maps/api/staticmap?center=%f,%f&zoom=13&size=100x100&maptype=roadmap&scale=%d&markers=color:red|size:big|%f,%f&sensor=false", lat, lon, Math.min(2, (int)Math.ceil(Utilities.density)), lat, lon);
+ String url = String.format(Locale.US, "https://maps.googleapis.com/maps/api/staticmap?center=%f,%f&zoom=13&size=100x100&maptype=roadmap&scale=%d&markers=color:red|size:big|%f,%f&sensor=false", lat, lon, Math.min(2, (int)Math.ceil(AndroidUtilities.density)), lat, lon);
if (!url.equals(currentUrl)) {
return true;
}
@@ -293,7 +292,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
return true;
} else if (currentPhotoObject != null && photoNotSet) {
String fileName = MessageObject.getAttachFileName(currentPhotoObject.photoOwner);
- File cacheFile = new File(Utilities.getCacheDir(), fileName);
+ File cacheFile = new File(AndroidUtilities.getCacheDir(), fileName);
if (cacheFile.exists()) {
return true;
}
@@ -330,7 +329,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
String str = String.format("%d:%02d, %s", minutes, seconds, Utilities.formatFileSize(messageObject.messageOwner.media.video.size));
if (currentInfoString == null || !currentInfoString.equals(str)) {
currentInfoString = str;
- infoOffset = videoIconDrawable.getIntrinsicWidth() + Utilities.dp(4);
+ infoOffset = videoIconDrawable.getIntrinsicWidth() + AndroidUtilities.dp(4);
infoWidth = (int) Math.ceil(infoPaint.measureText(currentInfoString));
infoLayout = new StaticLayout(currentInfoString, infoPaint, infoWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
}
@@ -340,17 +339,17 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
}
if (messageObject.type == 4) {
- photoWidth = Utilities.dp(100);
- photoHeight = Utilities.dp(100);
- backgroundWidth = photoWidth + Utilities.dp(12);
+ photoWidth = AndroidUtilities.dp(100);
+ photoHeight = AndroidUtilities.dp(100);
+ backgroundWidth = photoWidth + AndroidUtilities.dp(12);
double lat = messageObject.messageOwner.media.geo.lat;
double lon = messageObject.messageOwner.media.geo._long;
- currentUrl = String.format(Locale.US, "https://maps.googleapis.com/maps/api/staticmap?center=%f,%f&zoom=13&size=100x100&maptype=roadmap&scale=%d&markers=color:red|size:big|%f,%f&sensor=false", lat, lon, Math.min(2, (int)Math.ceil(Utilities.density)), lat, lon);
+ currentUrl = String.format(Locale.US, "https://maps.googleapis.com/maps/api/staticmap?center=%f,%f&zoom=13&size=100x100&maptype=roadmap&scale=%d&markers=color:red|size:big|%f,%f&sensor=false", lat, lon, Math.min(2, (int)Math.ceil(AndroidUtilities.density)), lat, lon);
photoImage.setImage(currentUrl, null, messageObject.isOut() ? placeholderOutDrawable : placeholderInDrawable);
} else {
- photoWidth = (int) (Math.min(Utilities.displaySize.x, Utilities.displaySize.y) * 0.7f);
- photoHeight = photoWidth + Utilities.dp(100);
+ photoWidth = (int) (Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) * 0.7f);
+ photoHeight = photoWidth + AndroidUtilities.dp(100);
if (photoWidth > 800) {
photoWidth = 800;
@@ -367,35 +366,35 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
int h = (int) (currentPhotoObject.photoOwner.h / scale);
if (w == 0) {
if (messageObject.type == 3) {
- w = infoWidth + infoOffset + Utilities.dp(16);
+ w = infoWidth + infoOffset + AndroidUtilities.dp(16);
} else {
- w = Utilities.dp(100);
+ w = AndroidUtilities.dp(100);
}
}
if (h == 0) {
- h = Utilities.dp(100);
+ h = AndroidUtilities.dp(100);
}
if (h > photoHeight) {
float scale2 = h;
h = photoHeight;
scale2 /= h;
w = (int) (w / scale2);
- } else if (h < Utilities.dp(120)) {
- h = Utilities.dp(120);
+ } else if (h < AndroidUtilities.dp(120)) {
+ h = AndroidUtilities.dp(120);
float hScale = (float) currentPhotoObject.photoOwner.h / h;
if (currentPhotoObject.photoOwner.w / hScale < photoWidth) {
w = (int) (currentPhotoObject.photoOwner.w / hScale);
}
}
- int timeWidthTotal = timeWidth + Utilities.dp(14 + (currentMessageObject.isOut() ? 20 : 0));
+ int timeWidthTotal = timeWidth + AndroidUtilities.dp(14 + (currentMessageObject.isOut() ? 20 : 0));
if (w < timeWidthTotal) {
w = timeWidthTotal;
}
photoWidth = w;
photoHeight = h;
- backgroundWidth = w + Utilities.dp(12);
- currentPhotoFilter = String.format(Locale.US, "%d_%d", (int) (w / Utilities.density), (int) (h / Utilities.density));
+ backgroundWidth = w + AndroidUtilities.dp(12);
+ currentPhotoFilter = String.format(Locale.US, "%d_%d", (int) (w / AndroidUtilities.density), (int) (h / AndroidUtilities.density));
if (currentPhotoObject.image != null) {
photoImage.setImageBitmap(currentPhotoObject.image);
@@ -403,7 +402,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
boolean photoExist = true;
String fileName = MessageObject.getAttachFileName(currentPhotoObject.photoOwner);
if (messageObject.type == 1) {
- File cacheFile = new File(Utilities.getCacheDir(), fileName);
+ File cacheFile = new File(AndroidUtilities.getCacheDir(), fileName);
if (!cacheFile.exists()) {
photoExist = false;
} else {
@@ -447,7 +446,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
return;
}
fileName = MessageObject.getAttachFileName(currentPhotoObject.photoOwner);
- cacheFile = new File(Utilities.getCacheDir(), fileName);
+ cacheFile = new File(AndroidUtilities.getCacheDir(), fileName);
} else if (currentMessageObject.type == 8 || currentMessageObject.type == 3) {
if (currentMessageObject.messageOwner.attachPath != null && currentMessageObject.messageOwner.attachPath.length() != 0) {
File f = new File(currentMessageObject.messageOwner.attachPath);
@@ -458,7 +457,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
}
if (fileName == null) {
fileName = currentMessageObject.getFileName();
- cacheFile = new File(Utilities.getCacheDir(), fileName);
+ cacheFile = new File(AndroidUtilities.getCacheDir(), fileName);
}
}
if (fileName == null) {
@@ -525,7 +524,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
- setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), photoHeight + Utilities.dp(14));
+ setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), photoHeight + AndroidUtilities.dp(14));
}
@Override
@@ -533,23 +532,23 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
super.onLayout(changed, left, top, right, bottom);
if (currentMessageObject.isOut()) {
- photoImage.imageX = layoutWidth - backgroundWidth - Utilities.dp(3);
+ photoImage.imageX = layoutWidth - backgroundWidth - AndroidUtilities.dp(3);
} else {
if (isChat) {
- photoImage.imageX = Utilities.dp(67);
+ photoImage.imageX = AndroidUtilities.dp(67);
} else {
- photoImage.imageX = Utilities.dp(15);
+ photoImage.imageX = AndroidUtilities.dp(15);
}
}
- photoImage.imageY = Utilities.dp(7);
+ photoImage.imageY = AndroidUtilities.dp(7);
photoImage.imageW = photoWidth;
photoImage.imageH = photoHeight;
- progressView.width = timeX - photoImage.imageX - Utilities.dpf(23.0f);
- progressView.height = Utilities.dp(3);
- progressView.progressHeight = Utilities.dp(3);
+ progressView.width = timeX - photoImage.imageX - AndroidUtilities.dpf(23.0f);
+ progressView.height = AndroidUtilities.dp(3);
+ progressView.progressHeight = AndroidUtilities.dp(3);
- int size = Utilities.dp(44);
+ int size = AndroidUtilities.dp(44);
buttonX = (int)(photoImage.imageX + (photoWidth - size) / 2.0f);
buttonY = (int)(photoImage.imageY + (photoHeight - size) / 2.0f);
}
@@ -568,11 +567,11 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
}
if (progressVisible) {
- setDrawableBounds(mediaBackgroundDrawable, photoImage.imageX + Utilities.dp(4), layoutHeight - Utilities.dpf(27.5f), progressView.width + Utilities.dp(12), Utilities.dpf(16.5f));
+ setDrawableBounds(mediaBackgroundDrawable, photoImage.imageX + AndroidUtilities.dp(4), layoutHeight - AndroidUtilities.dpf(27.5f), progressView.width + AndroidUtilities.dp(12), AndroidUtilities.dpf(16.5f));
mediaBackgroundDrawable.draw(canvas);
canvas.save();
- canvas.translate(photoImage.imageX + Utilities.dp(10), layoutHeight - Utilities.dpf(21.0f));
+ canvas.translate(photoImage.imageX + AndroidUtilities.dp(10), layoutHeight - AndroidUtilities.dpf(21.0f));
progressView.draw(canvas);
canvas.restore();
}
@@ -584,16 +583,16 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
}
if (infoLayout != null && (buttonState == 1 || buttonState == 0 || buttonState == 3)) {
- setDrawableBounds(mediaBackgroundDrawable, photoImage.imageX + Utilities.dp(4), photoImage.imageY + Utilities.dp(4), infoWidth + Utilities.dp(8) + infoOffset, Utilities.dpf(16.5f));
+ setDrawableBounds(mediaBackgroundDrawable, photoImage.imageX + AndroidUtilities.dp(4), photoImage.imageY + AndroidUtilities.dp(4), infoWidth + AndroidUtilities.dp(8) + infoOffset, AndroidUtilities.dpf(16.5f));
mediaBackgroundDrawable.draw(canvas);
if (currentMessageObject.type == 3) {
- setDrawableBounds(videoIconDrawable, photoImage.imageX + Utilities.dp(8), photoImage.imageY + Utilities.dpf(7.5f));
+ setDrawableBounds(videoIconDrawable, photoImage.imageX + AndroidUtilities.dp(8), photoImage.imageY + AndroidUtilities.dpf(7.5f));
videoIconDrawable.draw(canvas);
}
canvas.save();
- canvas.translate(photoImage.imageX + Utilities.dp(8) + infoOffset, photoImage.imageY + Utilities.dpf(5.5f));
+ canvas.translate(photoImage.imageX + AndroidUtilities.dp(8) + infoOffset, photoImage.imageY + AndroidUtilities.dpf(5.5f));
infoLayout.draw(canvas);
canvas.restore();
}
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMessageCell.java b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMessageCell.java
index 9396d1ab..77786a70 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMessageCell.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMessageCell.java
@@ -14,8 +14,8 @@ import android.text.Spannable;
import android.text.style.ClickableSpan;
import android.view.MotionEvent;
+import org.telegram.android.AndroidUtilities;
import org.telegram.messenger.FileLog;
-import org.telegram.messenger.Utilities;
import org.telegram.objects.MessageObject;
public class ChatMessageCell extends ChatBaseCell {
@@ -132,10 +132,10 @@ public class ChatMessageCell extends ChatBaseCell {
pressedLink = null;
int maxWidth;
if (isChat && !messageObject.isOut()) {
- maxWidth = Utilities.displaySize.x - Utilities.dp(122);
+ maxWidth = AndroidUtilities.displaySize.x - AndroidUtilities.dp(122);
drawName = true;
} else {
- maxWidth = Utilities.displaySize.x - Utilities.dp(80);
+ maxWidth = AndroidUtilities.displaySize.x - AndroidUtilities.dp(80);
drawName = false;
}
@@ -144,25 +144,25 @@ public class ChatMessageCell extends ChatBaseCell {
super.setMessageObject(messageObject);
backgroundWidth = messageObject.textWidth;
- totalHeight = messageObject.textHeight + Utilities.dpf(19.5f) + namesOffset;
+ totalHeight = messageObject.textHeight + AndroidUtilities.dpf(19.5f) + namesOffset;
int maxChildWidth = Math.max(backgroundWidth, nameWidth);
maxChildWidth = Math.max(maxChildWidth, forwardedNameWidth);
- int timeMore = timeWidth + Utilities.dp(6);
+ int timeMore = timeWidth + AndroidUtilities.dp(6);
if (messageObject.isOut()) {
- timeMore += Utilities.dpf(20.5f);
+ timeMore += AndroidUtilities.dpf(20.5f);
}
if (maxWidth - messageObject.lastLineWidth < timeMore) {
- totalHeight += Utilities.dp(14);
- backgroundWidth = Math.max(maxChildWidth, messageObject.lastLineWidth) + Utilities.dp(29);
+ totalHeight += AndroidUtilities.dp(14);
+ backgroundWidth = Math.max(maxChildWidth, messageObject.lastLineWidth) + AndroidUtilities.dp(29);
} else {
int diff = maxChildWidth - messageObject.lastLineWidth;
if (diff >= 0 && diff <= timeMore) {
- backgroundWidth = maxChildWidth + timeMore - diff + Utilities.dp(29);
+ backgroundWidth = maxChildWidth + timeMore - diff + AndroidUtilities.dp(29);
} else {
- backgroundWidth = Math.max(maxChildWidth, messageObject.lastLineWidth + timeMore) + Utilities.dp(29);
+ backgroundWidth = Math.max(maxChildWidth, messageObject.lastLineWidth + timeMore) + AndroidUtilities.dp(29);
}
}
}
@@ -178,11 +178,11 @@ public class ChatMessageCell extends ChatBaseCell {
super.onLayout(changed, left, top, right, bottom);
if (currentMessageObject.isOut()) {
- textX = layoutWidth - backgroundWidth + Utilities.dp(10);
- textY = Utilities.dp(10) + namesOffset;
+ textX = layoutWidth - backgroundWidth + AndroidUtilities.dp(10);
+ textY = AndroidUtilities.dp(10) + namesOffset;
} else {
- textX = Utilities.dp(19) + (isChat ? Utilities.dp(52) : 0);
- textY = Utilities.dp(10) + namesOffset;
+ textX = AndroidUtilities.dp(19) + (isChat ? AndroidUtilities.dp(52) : 0);
+ textY = AndroidUtilities.dp(10) + namesOffset;
}
}
@@ -194,11 +194,11 @@ public class ChatMessageCell extends ChatBaseCell {
}
if (currentMessageObject.isOut()) {
- textX = layoutWidth - backgroundWidth + Utilities.dp(10);
- textY = Utilities.dp(10) + namesOffset;
+ textX = layoutWidth - backgroundWidth + AndroidUtilities.dp(10);
+ textY = AndroidUtilities.dp(10) + namesOffset;
} else {
- textX = Utilities.dp(19) + (isChat ? Utilities.dp(52) : 0);
- textY = Utilities.dp(10) + namesOffset;
+ textX = AndroidUtilities.dp(19) + (isChat ? AndroidUtilities.dp(52) : 0);
+ textY = AndroidUtilities.dp(10) + namesOffset;
}
for (int a = firstVisibleBlockNum; a <= lastVisibleBlockNum; a++) {
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatOrUserCell.java b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatOrUserCell.java
index 3a656377..1bf92a35 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatOrUserCell.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatOrUserCell.java
@@ -17,11 +17,12 @@ import android.text.StaticLayout;
import android.text.TextPaint;
import android.text.TextUtils;
+import org.telegram.android.AndroidUtilities;
import org.telegram.PhoneFormat.PhoneFormat;
-import org.telegram.messenger.LocaleController;
+import org.telegram.android.LocaleController;
import org.telegram.messenger.TLRPC;
import org.telegram.messenger.ConnectionsManager;
-import org.telegram.messenger.MessagesController;
+import org.telegram.android.MessagesController;
import org.telegram.messenger.R;
import org.telegram.messenger.UserConfig;
import org.telegram.messenger.Utilities;
@@ -61,25 +62,25 @@ public class ChatOrUserCell extends BaseCell {
private void init() {
if (namePaint == null) {
namePaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
- namePaint.setTextSize(Utilities.dp(18));
+ namePaint.setTextSize(AndroidUtilities.dp(18));
namePaint.setColor(0xff222222);
}
if (nameEncryptedPaint == null) {
nameEncryptedPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
- nameEncryptedPaint.setTextSize(Utilities.dp(18));
+ nameEncryptedPaint.setTextSize(AndroidUtilities.dp(18));
nameEncryptedPaint.setColor(0xff00a60e);
}
if (onlinePaint == null) {
onlinePaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
- onlinePaint.setTextSize(Utilities.dp(15));
+ onlinePaint.setTextSize(AndroidUtilities.dp(15));
onlinePaint.setColor(0xff316f9f);
}
if (offlinePaint == null) {
offlinePaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
- offlinePaint.setTextSize(Utilities.dp(15));
+ offlinePaint.setTextSize(AndroidUtilities.dp(15));
offlinePaint.setColor(0xff999999);
}
@@ -122,7 +123,7 @@ public class ChatOrUserCell extends BaseCell {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
- setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), Utilities.dp(64));
+ setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), AndroidUtilities.dp(64));
}
@Override
@@ -243,14 +244,14 @@ public class ChatOrUserCell extends BaseCell {
canvas.restore();
}
- avatarImage.draw(canvas, cellLayout.avatarLeft, cellLayout.avatarTop, Utilities.dp(50), Utilities.dp(50));
+ avatarImage.draw(canvas, cellLayout.avatarLeft, cellLayout.avatarTop, AndroidUtilities.dp(50), AndroidUtilities.dp(50));
if (useSeparator) {
int h = getMeasuredHeight();
if (!usePadding) {
canvas.drawLine(0, h - 1, getMeasuredWidth(), h, linePaint);
} else {
- canvas.drawLine(Utilities.dp(11), h - 1, getMeasuredWidth() - Utilities.dp(11), h, linePaint);
+ canvas.drawLine(AndroidUtilities.dp(11), h - 1, getMeasuredWidth() - AndroidUtilities.dp(11), h, linePaint);
}
}
}
@@ -262,14 +263,14 @@ public class ChatOrUserCell extends BaseCell {
private StaticLayout nameLayout;
private boolean drawNameLock;
private int nameLockLeft;
- private int nameLockTop = Utilities.dp(15);
+ private int nameLockTop = AndroidUtilities.dp(15);
private int onlineLeft;
- private int onlineTop = Utilities.dp(36);
+ private int onlineTop = AndroidUtilities.dp(36);
private int onlineWidth;
private StaticLayout onlineLayout;
- private int avatarTop = Utilities.dp(7);
+ private int avatarTop = AndroidUtilities.dp(7);
private int avatarLeft;
public void build(int width, int height) {
@@ -279,18 +280,18 @@ public class ChatOrUserCell extends BaseCell {
if (encryptedChat != null) {
drawNameLock = true;
if (!LocaleController.isRTL) {
- nameLockLeft = Utilities.dp(61 + (usePadding ? 11 : 0));
- nameLeft = Utilities.dp(65 + (usePadding ? 11 : 0)) + lockDrawable.getIntrinsicWidth();
+ nameLockLeft = AndroidUtilities.dp(61 + (usePadding ? 11 : 0));
+ nameLeft = AndroidUtilities.dp(65 + (usePadding ? 11 : 0)) + lockDrawable.getIntrinsicWidth();
} else {
- nameLockLeft = width - Utilities.dp(63 + (usePadding ? 11 : 0)) - lockDrawable.getIntrinsicWidth();
- nameLeft = usePadding ? Utilities.dp(11) : 0;
+ nameLockLeft = width - AndroidUtilities.dp(63 + (usePadding ? 11 : 0)) - lockDrawable.getIntrinsicWidth();
+ nameLeft = usePadding ? AndroidUtilities.dp(11) : 0;
}
} else {
drawNameLock = false;
if (!LocaleController.isRTL) {
- nameLeft = Utilities.dp(61 + (usePadding ? 11 : 0));
+ nameLeft = AndroidUtilities.dp(61 + (usePadding ? 11 : 0));
} else {
- nameLeft = usePadding ? Utilities.dp(11) : 0;
+ nameLeft = usePadding ? AndroidUtilities.dp(11) : 0;
}
}
@@ -319,22 +320,22 @@ public class ChatOrUserCell extends BaseCell {
}
if (!LocaleController.isRTL) {
- onlineWidth = nameWidth = width - nameLeft - Utilities.dp(3 + (usePadding ? 11 : 0));
+ onlineWidth = nameWidth = width - nameLeft - AndroidUtilities.dp(3 + (usePadding ? 11 : 0));
} else {
- onlineWidth = nameWidth = width - nameLeft - Utilities.dp(61 + (usePadding ? 11 : 0));
+ onlineWidth = nameWidth = width - nameLeft - AndroidUtilities.dp(61 + (usePadding ? 11 : 0));
}
if (drawNameLock) {
- nameWidth -= Utilities.dp(6) + lockDrawable.getIntrinsicWidth();
+ nameWidth -= AndroidUtilities.dp(6) + lockDrawable.getIntrinsicWidth();
}
- CharSequence nameStringFinal = TextUtils.ellipsize(nameString, currentNamePaint, nameWidth - Utilities.dp(12), TextUtils.TruncateAt.END);
+ CharSequence nameStringFinal = TextUtils.ellipsize(nameString, currentNamePaint, nameWidth - AndroidUtilities.dp(12), TextUtils.TruncateAt.END);
nameLayout = new StaticLayout(nameStringFinal, currentNamePaint, nameWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
if (chat == null) {
if (!LocaleController.isRTL) {
- onlineLeft = Utilities.dp(61 + (usePadding ? 11 : 0));
+ onlineLeft = AndroidUtilities.dp(61 + (usePadding ? 11 : 0));
} else {
- onlineLeft = usePadding ? Utilities.dp(11) : 0;
+ onlineLeft = usePadding ? AndroidUtilities.dp(11) : 0;
}
String onlineString = "";
@@ -350,23 +351,23 @@ public class ChatOrUserCell extends BaseCell {
}
}
- CharSequence onlineStringFinal = TextUtils.ellipsize(onlineString, currentOnlinePaint, nameWidth - Utilities.dp(12), TextUtils.TruncateAt.END);
+ CharSequence onlineStringFinal = TextUtils.ellipsize(onlineString, currentOnlinePaint, nameWidth - AndroidUtilities.dp(12), TextUtils.TruncateAt.END);
onlineLayout = new StaticLayout(onlineStringFinal, currentOnlinePaint, nameWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
- nameTop = Utilities.dp(12);
+ nameTop = AndroidUtilities.dp(12);
} else {
onlineLayout = null;
- nameTop = Utilities.dp(22);
+ nameTop = AndroidUtilities.dp(22);
}
if (!LocaleController.isRTL) {
- avatarLeft = usePadding ? Utilities.dp(11) : 0;
+ avatarLeft = usePadding ? AndroidUtilities.dp(11) : 0;
} else {
- avatarLeft = width - Utilities.dp(50 + (usePadding ? 11 : 0));
+ avatarLeft = width - AndroidUtilities.dp(50 + (usePadding ? 11 : 0));
}
avatarImage.imageX = avatarLeft;
avatarImage.imageY = avatarTop;
- avatarImage.imageW = Utilities.dp(50);
- avatarImage.imageH = Utilities.dp(50);
+ avatarImage.imageW = AndroidUtilities.dp(50);
+ avatarImage.imageH = AndroidUtilities.dp(50);
double widthpx = 0;
float left = 0;
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Cells/DialogCell.java b/TMessagesProj/src/main/java/org/telegram/ui/Cells/DialogCell.java
index b7a742c9..25109034 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/Cells/DialogCell.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/Cells/DialogCell.java
@@ -17,12 +17,13 @@ import android.text.StaticLayout;
import android.text.TextPaint;
import android.text.TextUtils;
+import org.telegram.android.AndroidUtilities;
import org.telegram.PhoneFormat.PhoneFormat;
-import org.telegram.messenger.LocaleController;
+import org.telegram.android.LocaleController;
import org.telegram.messenger.TLRPC;
-import org.telegram.messenger.ContactsController;
-import org.telegram.messenger.Emoji;
-import org.telegram.messenger.MessagesController;
+import org.telegram.android.ContactsController;
+import org.telegram.android.Emoji;
+import org.telegram.android.MessagesController;
import org.telegram.messenger.R;
import org.telegram.messenger.UserConfig;
import org.telegram.messenger.Utilities;
@@ -58,46 +59,46 @@ public class DialogCell extends BaseCell {
private void init() {
if (namePaint == null) {
namePaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
- namePaint.setTextSize(Utilities.dp(19));
+ namePaint.setTextSize(AndroidUtilities.dp(19));
namePaint.setColor(0xff222222);
- namePaint.setTypeface(Utilities.getTypeface("fonts/rmedium.ttf"));
+ namePaint.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
}
if (nameEncryptedPaint == null) {
nameEncryptedPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
- nameEncryptedPaint.setTextSize(Utilities.dp(19));
+ nameEncryptedPaint.setTextSize(AndroidUtilities.dp(19));
nameEncryptedPaint.setColor(0xff00a60e);
- nameEncryptedPaint.setTypeface(Utilities.getTypeface("fonts/rmedium.ttf"));
+ nameEncryptedPaint.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
}
if (nameUnknownPaint == null) {
nameUnknownPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
- nameUnknownPaint.setTextSize(Utilities.dp(19));
+ nameUnknownPaint.setTextSize(AndroidUtilities.dp(19));
nameUnknownPaint.setColor(0xff316f9f);
- nameUnknownPaint.setTypeface(Utilities.getTypeface("fonts/rmedium.ttf"));
+ nameUnknownPaint.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
}
if (messagePaint == null) {
messagePaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
- messagePaint.setTextSize(Utilities.dp(16));
+ messagePaint.setTextSize(AndroidUtilities.dp(16));
messagePaint.setColor(0xff808080);
}
if (messagePrintingPaint == null) {
messagePrintingPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
- messagePrintingPaint.setTextSize(Utilities.dp(16));
+ messagePrintingPaint.setTextSize(AndroidUtilities.dp(16));
messagePrintingPaint.setColor(0xff316f9f);
}
if (timePaint == null) {
timePaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
- timePaint.setTextSize(Utilities.dp(14));
+ timePaint.setTextSize(AndroidUtilities.dp(14));
timePaint.setColor(0xff9e9e9e);
}
if (countPaint == null) {
countPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
- countPaint.setTextSize(Utilities.dp(13));
+ countPaint.setTextSize(AndroidUtilities.dp(13));
countPaint.setColor(0xffffffff);
}
@@ -159,7 +160,7 @@ public class DialogCell extends BaseCell {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
- setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), Utilities.dp(70));
+ setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), AndroidUtilities.dp(70));
}
@Override
@@ -309,20 +310,20 @@ public class DialogCell extends BaseCell {
setDrawableBounds(errorDrawable, cellLayout.errorLeft, cellLayout.errorTop);
errorDrawable.draw(canvas);
} else if (cellLayout.drawCount) {
- setDrawableBounds(countDrawable, cellLayout.countLeft - Utilities.dp(5), cellLayout.countTop, cellLayout.countWidth + Utilities.dp(10), countDrawable.getIntrinsicHeight());
+ setDrawableBounds(countDrawable, cellLayout.countLeft - AndroidUtilities.dp(5), cellLayout.countTop, cellLayout.countWidth + AndroidUtilities.dp(10), countDrawable.getIntrinsicHeight());
countDrawable.draw(canvas);
canvas.save();
- canvas.translate(cellLayout.countLeft, cellLayout.countTop + Utilities.dp(3));
+ canvas.translate(cellLayout.countLeft, cellLayout.countTop + AndroidUtilities.dp(3));
cellLayout.countLayout.draw(canvas);
canvas.restore();
}
- avatarImage.draw(canvas, cellLayout.avatarLeft, cellLayout.avatarTop, Utilities.dp(54), Utilities.dp(54));
+ avatarImage.draw(canvas, cellLayout.avatarLeft, cellLayout.avatarTop, AndroidUtilities.dp(54), AndroidUtilities.dp(54));
}
private class DialogCellLayout {
private int nameLeft;
- private int nameTop = Utilities.dp(10);
+ private int nameTop = AndroidUtilities.dp(10);
private int nameWidth;
private StaticLayout nameLayout;
private boolean drawNameLock;
@@ -331,7 +332,7 @@ public class DialogCell extends BaseCell {
private int nameLockTop;
private int timeLeft;
- private int timeTop = Utilities.dp(13);
+ private int timeTop = AndroidUtilities.dp(13);
private int timeWidth;
private StaticLayout timeLayout;
@@ -339,25 +340,25 @@ public class DialogCell extends BaseCell {
private boolean drawCheck2;
private boolean drawClock;
private int checkDrawLeft;
- private int checkDrawTop = Utilities.dp(15);
+ private int checkDrawTop = AndroidUtilities.dp(15);
private int halfCheckDrawLeft;
- private int messageTop = Utilities.dp(40);
+ private int messageTop = AndroidUtilities.dp(40);
private int messageLeft;
private int messageWidth;
private StaticLayout messageLayout;
private boolean drawError;
- private int errorTop = Utilities.dp(37);
+ private int errorTop = AndroidUtilities.dp(37);
private int errorLeft;
private boolean drawCount;
- private int countTop = Utilities.dp(37);
+ private int countTop = AndroidUtilities.dp(37);
private int countLeft;
private int countWidth;
private StaticLayout countLayout;
- private int avatarTop = Utilities.dp(8);
+ private int avatarTop = AndroidUtilities.dp(8);
private int avatarLeft;
public void build(int width, int height) {
@@ -374,32 +375,32 @@ public class DialogCell extends BaseCell {
if (encryptedChat != null) {
drawNameLock = true;
drawNameGroup = false;
- nameLockTop = Utilities.dp(13);
+ nameLockTop = AndroidUtilities.dp(13);
if (!LocaleController.isRTL) {
- nameLockLeft = Utilities.dp(77);
- nameLeft = Utilities.dp(81) + lockDrawable.getIntrinsicWidth();
+ nameLockLeft = AndroidUtilities.dp(77);
+ nameLeft = AndroidUtilities.dp(81) + lockDrawable.getIntrinsicWidth();
} else {
- nameLockLeft = width - Utilities.dp(77) - lockDrawable.getIntrinsicWidth();
- nameLeft = Utilities.dp(14);
+ nameLockLeft = width - AndroidUtilities.dp(77) - lockDrawable.getIntrinsicWidth();
+ nameLeft = AndroidUtilities.dp(14);
}
} else {
drawNameLock = false;
if (chat != null) {
drawNameGroup = true;
- nameLockTop = Utilities.dp(14);
+ nameLockTop = AndroidUtilities.dp(14);
if (!LocaleController.isRTL) {
- nameLockLeft = Utilities.dp(77);
- nameLeft = Utilities.dp(81) + groupDrawable.getIntrinsicWidth();
+ nameLockLeft = AndroidUtilities.dp(77);
+ nameLeft = AndroidUtilities.dp(81) + groupDrawable.getIntrinsicWidth();
} else {
- nameLockLeft = width - Utilities.dp(77) - groupDrawable.getIntrinsicWidth();
- nameLeft = Utilities.dp(14);
+ nameLockLeft = width - AndroidUtilities.dp(77) - groupDrawable.getIntrinsicWidth();
+ nameLeft = AndroidUtilities.dp(14);
}
} else {
drawNameGroup = false;
if (!LocaleController.isRTL) {
- nameLeft = Utilities.dp(77);
+ nameLeft = AndroidUtilities.dp(77);
} else {
- nameLeft = Utilities.dp(14);
+ nameLeft = AndroidUtilities.dp(14);
}
}
}
@@ -476,10 +477,10 @@ public class DialogCell extends BaseCell {
checkMessage = false;
if (message.messageOwner.media != null && !(message.messageOwner.media instanceof TLRPC.TL_messageMediaEmpty)) {
currentMessagePaint = messagePrintingPaint;
- messageString = Emoji.replaceEmoji(Html.fromHtml(String.format("%s: %s", name, message.messageText)), messagePaint.getFontMetricsInt(), Utilities.dp(20));
+ messageString = Emoji.replaceEmoji(Html.fromHtml(String.format("%s: %s", name, message.messageText)), messagePaint.getFontMetricsInt(), AndroidUtilities.dp(20));
} else {
if (message.messageOwner.message != null) {
- messageString = Emoji.replaceEmoji(Html.fromHtml(String.format("%s: %s", name, message.messageOwner.message.replace("\n", " ").replace("<", "<").replace(">", ">"))), messagePaint.getFontMetricsInt(), Utilities.dp(20));
+ messageString = Emoji.replaceEmoji(Html.fromHtml(String.format("%s: %s", name, message.messageOwner.message.replace("\n", " ").replace("<", "<").replace(">", ">"))), messagePaint.getFontMetricsInt(), AndroidUtilities.dp(20));
}
}
} else {
@@ -538,9 +539,9 @@ public class DialogCell extends BaseCell {
timeWidth = (int)Math.ceil(timePaint.measureText(timeString));
timeLayout = new StaticLayout(timeString, timePaint, timeWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
if (!LocaleController.isRTL) {
- timeLeft = width - Utilities.dp(11) - timeWidth;
+ timeLeft = width - AndroidUtilities.dp(11) - timeWidth;
} else {
- timeLeft = Utilities.dp(11);
+ timeLeft = AndroidUtilities.dp(11);
}
if (chat != null) {
@@ -569,81 +570,81 @@ public class DialogCell extends BaseCell {
}
if (!LocaleController.isRTL) {
- nameWidth = width - nameLeft - Utilities.dp(14) - timeWidth;
+ nameWidth = width - nameLeft - AndroidUtilities.dp(14) - timeWidth;
} else {
- nameWidth = width - nameLeft - Utilities.dp(77) - timeWidth;
+ nameWidth = width - nameLeft - AndroidUtilities.dp(77) - timeWidth;
nameLeft += timeWidth;
}
if (drawNameLock) {
- nameWidth -= Utilities.dp(4) + lockDrawable.getIntrinsicWidth();
+ nameWidth -= AndroidUtilities.dp(4) + lockDrawable.getIntrinsicWidth();
} else if (drawNameGroup) {
- nameWidth -= Utilities.dp(4) + groupDrawable.getIntrinsicWidth();
+ nameWidth -= AndroidUtilities.dp(4) + groupDrawable.getIntrinsicWidth();
}
if (drawClock) {
- int w = clockDrawable.getIntrinsicWidth() + Utilities.dp(2);
+ int w = clockDrawable.getIntrinsicWidth() + AndroidUtilities.dp(2);
nameWidth -= w;
if (!LocaleController.isRTL) {
checkDrawLeft = timeLeft - w;
} else {
- checkDrawLeft = timeLeft + timeWidth + Utilities.dp(2);
+ checkDrawLeft = timeLeft + timeWidth + AndroidUtilities.dp(2);
nameLeft += w;
}
} else if (drawCheck2) {
- int w = checkDrawable.getIntrinsicWidth() + Utilities.dp(2);
+ int w = checkDrawable.getIntrinsicWidth() + AndroidUtilities.dp(2);
nameWidth -= w;
if (drawCheck1) {
- nameWidth -= halfCheckDrawable.getIntrinsicWidth() - Utilities.dp(5);
+ nameWidth -= halfCheckDrawable.getIntrinsicWidth() - AndroidUtilities.dp(5);
if (!LocaleController.isRTL) {
halfCheckDrawLeft = timeLeft - w;
- checkDrawLeft = halfCheckDrawLeft - Utilities.dp(5);
+ checkDrawLeft = halfCheckDrawLeft - AndroidUtilities.dp(5);
} else {
- checkDrawLeft = timeLeft + timeWidth + Utilities.dp(2);
- halfCheckDrawLeft = checkDrawLeft + Utilities.dp(5);
- nameLeft += w + halfCheckDrawable.getIntrinsicWidth() - Utilities.dp(5);
+ checkDrawLeft = timeLeft + timeWidth + AndroidUtilities.dp(2);
+ halfCheckDrawLeft = checkDrawLeft + AndroidUtilities.dp(5);
+ nameLeft += w + halfCheckDrawable.getIntrinsicWidth() - AndroidUtilities.dp(5);
}
} else {
if (!LocaleController.isRTL) {
checkDrawLeft = timeLeft - w;
} else {
- checkDrawLeft = timeLeft + timeWidth + Utilities.dp(2);
+ checkDrawLeft = timeLeft + timeWidth + AndroidUtilities.dp(2);
nameLeft += w;
}
}
}
- CharSequence nameStringFinal = TextUtils.ellipsize(nameString.replace("\n", " "), currentNamePaint, nameWidth - Utilities.dp(12), TextUtils.TruncateAt.END);
+ CharSequence nameStringFinal = TextUtils.ellipsize(nameString.replace("\n", " "), currentNamePaint, nameWidth - AndroidUtilities.dp(12), TextUtils.TruncateAt.END);
nameLayout = new StaticLayout(nameStringFinal, currentNamePaint, nameWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
- messageWidth = width - Utilities.dp(88);
+ messageWidth = width - AndroidUtilities.dp(88);
if (!LocaleController.isRTL) {
- messageLeft = Utilities.dp(77);
- avatarLeft = Utilities.dp(11);
+ messageLeft = AndroidUtilities.dp(77);
+ avatarLeft = AndroidUtilities.dp(11);
} else {
- messageLeft = Utilities.dp(11);
- avatarLeft = width - Utilities.dp(65);
+ messageLeft = AndroidUtilities.dp(11);
+ avatarLeft = width - AndroidUtilities.dp(65);
}
avatarImage.imageX = avatarLeft;
avatarImage.imageY = avatarTop;
- avatarImage.imageW = Utilities.dp(54);
- avatarImage.imageH = Utilities.dp(54);
+ avatarImage.imageW = AndroidUtilities.dp(54);
+ avatarImage.imageH = AndroidUtilities.dp(54);
if (drawError) {
- int w = errorDrawable.getIntrinsicWidth() + Utilities.dp(8);
+ int w = errorDrawable.getIntrinsicWidth() + AndroidUtilities.dp(8);
messageWidth -= w;
if (!LocaleController.isRTL) {
- errorLeft = width - errorDrawable.getIntrinsicWidth() - Utilities.dp(11);
+ errorLeft = width - errorDrawable.getIntrinsicWidth() - AndroidUtilities.dp(11);
} else {
- errorLeft = Utilities.dp(11);
+ errorLeft = AndroidUtilities.dp(11);
messageLeft += w;
}
} else if (countString != null) {
- countWidth = Math.max(Utilities.dp(12), (int)Math.ceil(countPaint.measureText(countString)));
+ countWidth = Math.max(AndroidUtilities.dp(12), (int)Math.ceil(countPaint.measureText(countString)));
countLayout = new StaticLayout(countString, countPaint, countWidth, Layout.Alignment.ALIGN_CENTER, 1.0f, 0.0f, false);
- int w = countWidth + Utilities.dp(18);
+ int w = countWidth + AndroidUtilities.dp(18);
messageWidth -= w;
if (!LocaleController.isRTL) {
- countLeft = width - countWidth - Utilities.dp(16);
+ countLeft = width - countWidth - AndroidUtilities.dp(16);
} else {
- countLeft = Utilities.dp(16);
+ countLeft = AndroidUtilities.dp(16);
messageLeft += w;
}
drawCount = true;
@@ -659,10 +660,10 @@ public class DialogCell extends BaseCell {
if (mess.length() > 150) {
mess = mess.substring(0, 150);
}
- messageString = Emoji.replaceEmoji(mess, messagePaint.getFontMetricsInt(), Utilities.dp(20));
+ messageString = Emoji.replaceEmoji(mess, messagePaint.getFontMetricsInt(), AndroidUtilities.dp(20));
}
- CharSequence messageStringFinal = TextUtils.ellipsize(messageString, currentMessagePaint, messageWidth - Utilities.dp(12), TextUtils.TruncateAt.END);
+ CharSequence messageStringFinal = TextUtils.ellipsize(messageString, currentMessagePaint, messageWidth - AndroidUtilities.dp(12), TextUtils.TruncateAt.END);
messageLayout = new StaticLayout(messageStringFinal, currentMessagePaint, messageWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
double widthpx = 0;
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java
index 74f44d1f..712c2cf5 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java
@@ -8,7 +8,6 @@
package org.telegram.ui;
-import android.animation.Animator;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
@@ -26,54 +25,40 @@ import android.media.MediaPlayer;
import android.media.ThumbnailUtils;
import android.net.Uri;
import android.os.Bundle;
-import android.os.PowerManager;
import android.provider.MediaStore;
-import android.text.Editable;
import android.text.Html;
import android.text.TextUtils;
-import android.text.TextWatcher;
-import android.text.style.ImageSpan;
import android.util.TypedValue;
import android.view.Gravity;
-import android.view.KeyEvent;
import android.view.LayoutInflater;
-import android.view.MotionEvent;
-import android.view.Surface;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.ViewTreeObserver;
-import android.view.WindowManager;
-import android.view.animation.AccelerateDecelerateInterpolator;
-import android.view.inputmethod.EditorInfo;
-import android.view.inputmethod.InputMethodManager;
import android.webkit.MimeTypeMap;
import android.widget.AbsListView;
import android.widget.AdapterView;
-import android.widget.EditText;
import android.widget.FrameLayout;
-import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
-import android.widget.PopupWindow;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
+import org.telegram.android.AndroidUtilities;
import org.telegram.PhoneFormat.PhoneFormat;
-import org.telegram.messenger.LocaleController;
-import org.telegram.messenger.MediaController;
-import org.telegram.messenger.MessagesStorage;
+import org.telegram.android.LocaleController;
+import org.telegram.android.MediaController;
+import org.telegram.android.MessagesStorage;
import org.telegram.messenger.TLRPC;
-import org.telegram.messenger.ContactsController;
+import org.telegram.android.ContactsController;
import org.telegram.messenger.FileLog;
import org.telegram.objects.MessageObject;
import org.telegram.objects.PhotoObject;
import org.telegram.messenger.ConnectionsManager;
-import org.telegram.messenger.Emoji;
import org.telegram.messenger.FileLoader;
-import org.telegram.messenger.MessagesController;
+import org.telegram.android.MessagesController;
import org.telegram.messenger.NotificationCenter;
import org.telegram.messenger.R;
import org.telegram.messenger.UserConfig;
@@ -88,7 +73,7 @@ import org.telegram.ui.Views.ActionBar.ActionBarMenu;
import org.telegram.ui.Views.ActionBar.ActionBarMenuItem;
import org.telegram.ui.Views.BackupImageView;
import org.telegram.ui.Views.ActionBar.BaseFragment;
-import org.telegram.ui.Views.EmojiView;
+import org.telegram.ui.Views.ChatActivityEnterView;
import org.telegram.ui.Views.ImageReceiver;
import org.telegram.ui.Views.LayoutListView;
import org.telegram.ui.Views.MessageActionLayout;
@@ -102,11 +87,10 @@ import java.util.Comparator;
import java.util.HashMap;
import java.util.concurrent.Semaphore;
-public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLayout.SizeNotifierRelativeLayoutDelegate,
- NotificationCenter.NotificationCenterDelegate, MessagesActivity.MessagesActivityDelegate,
- DocumentSelectActivity.DocumentSelectActivityDelegate, PhotoViewer.PhotoViewerProvider,
- PhotoPickerActivity.PhotoPickerActivityDelegate {
+public class ChatActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate, MessagesActivity.MessagesActivityDelegate,
+ DocumentSelectActivity.DocumentSelectActivityDelegate, PhotoViewer.PhotoViewerProvider, PhotoPickerActivity.PhotoPickerActivityDelegate {
+ private ChatActivityEnterView chatActivityEnterView;
private View timeItem;
private View menuItem;
private LayoutListView chatListView;
@@ -115,26 +99,15 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
private TLRPC.User currentUser;
private TLRPC.EncryptedChat currentEncryptedChat;
private ChatAdapter chatAdapter;
- private EditText messsageEditText;
- private ImageButton sendButton;
- private PopupWindow emojiPopup;
- private ImageView emojiButton;
- private EmojiView emojiView;
- private View slideText;
- private boolean keyboardVisible;
- private int keyboardHeight = 0;
- private int keyboardHeightLand = 0;
+
private View topPanel;
private View secretChatPlaceholder;
- private View contentView;
private View progressView;
- private boolean ignoreTextChange = false;
private TextView emptyView;
private View bottomOverlay;
- private View recordPanel;
- private TextView recordTimeText;
+
private TextView bottomOverlayText;
- private ImageButton audioSendButton;
+
private MessageObject selectedObject;
private MessageObject forwaringMessage;
private TextView secretViewStatusTextView;
@@ -142,7 +115,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
private TextView selectedMessagesCountTextView;
private boolean paused = true;
private boolean readWhenResume = false;
- private boolean sendByEnter = false;
+
private int readWithDate = 0;
private int readWithMid = 0;
private boolean scrollToTopOnResume = false;
@@ -154,7 +127,6 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
private View pagedownButton;
private TextView topPanelText;
private long dialog_id;
- private SizeNotifierRelativeLayout sizeNotifierRelativeLayout;
private HashMap selectedMessagesIds = new HashMap();
private HashMap selectedMessagesCanCopyIds = new HashMap();
@@ -167,7 +139,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
private boolean endReached = false;
private boolean loading = false;
private boolean cacheEndReaced = false;
- private long lastTypingTimeSend = 0;
+
private int minDate = 0;
private int progressTag = 0;
boolean first = true;
@@ -177,11 +149,6 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
private boolean unread_end_reached = true;
private boolean loadingForward = false;
private MessageObject unreadMessageObject = null;
- private boolean recordingAudio = false;
- private String lastTimeString = null;
- private float startedDraggingX = -1;
- private float distCanMove = Utilities.dp(80);
- private PowerManager.WakeLock mWakeLock = null;
private String currentPicturePath;
@@ -317,6 +284,24 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
} else {
return false;
}
+ chatActivityEnterView = new ChatActivityEnterView();
+ chatActivityEnterView.setDialogId(dialog_id);
+ chatActivityEnterView.setDelegate(new ChatActivityEnterView.ChatActivityEnterViewDelegate() {
+ @Override
+ public void onMessageSend() {
+ chatListView.post(new Runnable() {
+ @Override
+ public void run() {
+ chatListView.setSelectionFromTop(messages.size() - 1, -100000 - chatListView.getPaddingTop());
+ }
+ });
+ }
+
+ @Override
+ public void needSendTyping() {
+ MessagesController.getInstance().sendTyping(dialog_id, classGuid);
+ }
+ });
NotificationCenter.getInstance().addObserver(this, MessagesController.messagesDidLoaded);
NotificationCenter.getInstance().addObserver(this, 999);
NotificationCenter.getInstance().addObserver(this, MessagesController.updateInterfaces);
@@ -338,10 +323,6 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
NotificationCenter.getInstance().addObserver(this, FileLoader.FileLoadProgressChanged);
NotificationCenter.getInstance().addObserver(this, MediaController.audioProgressDidChanged);
NotificationCenter.getInstance().addObserver(this, MediaController.audioDidReset);
- NotificationCenter.getInstance().addObserver(this, MediaController.recordProgressChanged);
- NotificationCenter.getInstance().addObserver(this, MediaController.recordStarted);
- NotificationCenter.getInstance().addObserver(this, MediaController.recordStartError);
- NotificationCenter.getInstance().addObserver(this, MediaController.recordStopped);
NotificationCenter.getInstance().addObserver(this, MediaController.screenshotTook);
NotificationCenter.getInstance().addObserver(this, 997);
@@ -350,7 +331,6 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
loading = true;
MessagesController.getInstance().loadMessages(dialog_id, 0, 30, 0, true, 0, classGuid, true, false);
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
- sendByEnter = preferences.getBoolean("send_by_enter", false);
if (currentChat != null) {
downloadPhotos = preferences.getInt("photo_download_chat2", 0);
@@ -369,6 +349,9 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
@Override
public void onFragmentDestroy() {
super.onFragmentDestroy();
+ if (chatActivityEnterView != null) {
+ chatActivityEnterView.onDestroy();
+ }
NotificationCenter.getInstance().removeObserver(this, MessagesController.messagesDidLoaded);
NotificationCenter.getInstance().removeObserver(this, 999);
NotificationCenter.getInstance().removeObserver(this, MessagesController.updateInterfaces);
@@ -390,29 +373,13 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
NotificationCenter.getInstance().removeObserver(this, MessagesController.contactsDidLoaded);
NotificationCenter.getInstance().removeObserver(this, MediaController.audioProgressDidChanged);
NotificationCenter.getInstance().removeObserver(this, MediaController.audioDidReset);
- NotificationCenter.getInstance().removeObserver(this, MediaController.recordProgressChanged);
- NotificationCenter.getInstance().removeObserver(this, MediaController.recordStarted);
- NotificationCenter.getInstance().removeObserver(this, MediaController.recordStartError);
- NotificationCenter.getInstance().removeObserver(this, MediaController.recordStopped);
NotificationCenter.getInstance().removeObserver(this, MediaController.screenshotTook);
NotificationCenter.getInstance().removeObserver(this, 997);
if (currentEncryptedChat != null) {
MediaController.getInstance().stopMediaObserver();
}
- if (sizeNotifierRelativeLayout != null) {
- sizeNotifierRelativeLayout.delegate = null;
- sizeNotifierRelativeLayout = null;
- }
- if (mWakeLock != null) {
- try {
- mWakeLock.release();
- mWakeLock = null;
- } catch (Exception e) {
- FileLog.e("tmessages", e);
- }
- }
- Utilities.unlockOrientation(getParentActivity());
+ AndroidUtilities.unlockOrientation(getParentActivity());
MediaController.getInstance().stopAudio();
}
@@ -561,7 +528,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
updateSubtitle();
if (currentEncryptedChat != null) {
- actionBarLayer.setTitleIcon(R.drawable.ic_lock_white, Utilities.dp(4));
+ actionBarLayer.setTitleIcon(R.drawable.ic_lock_white, AndroidUtilities.dp(4));
}
ActionBarMenu menu = actionBarLayer.createMenu();
@@ -578,7 +545,6 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
item.addSubItem(attach_location, LocaleController.getString("ChatLocation", R.string.ChatLocation), R.drawable.ic_attach_location);
menuItem = item;
-
ActionBarMenu actionMode = actionBarLayer.createActionMode();
actionMode.addItem(-2, R.drawable.ic_ab_done_gray);
@@ -586,10 +552,10 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
layout.setBackgroundColor(0xffe5e5e5);
actionMode.addView(layout);
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams)layout.getLayoutParams();
- layoutParams.width = Utilities.dp(1);
+ layoutParams.width = AndroidUtilities.dp(1);
layoutParams.height = LinearLayout.LayoutParams.MATCH_PARENT;
- layoutParams.topMargin = Utilities.dp(12);
- layoutParams.bottomMargin = Utilities.dp(12);
+ layoutParams.topMargin = AndroidUtilities.dp(12);
+ layoutParams.bottomMargin = AndroidUtilities.dp(12);
layoutParams.gravity = Gravity.CENTER_VERTICAL;
layout.setLayoutParams(layoutParams);
@@ -599,7 +565,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
selectedMessagesCountTextView.setSingleLine(true);
selectedMessagesCountTextView.setLines(1);
selectedMessagesCountTextView.setEllipsize(TextUtils.TruncateAt.END);
- selectedMessagesCountTextView.setPadding(Utilities.dp(6), 0, 0, 0);
+ selectedMessagesCountTextView.setPadding(AndroidUtilities.dp(6), 0, 0, 0);
selectedMessagesCountTextView.setGravity(Gravity.CENTER_VERTICAL);
actionMode.addView(selectedMessagesCountTextView);
layoutParams = (LinearLayout.LayoutParams)selectedMessagesCountTextView.getLayoutParams();
@@ -625,10 +591,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
fragmentView = inflater.inflate(R.layout.chat_layout, container, false);
- sizeNotifierRelativeLayout = (SizeNotifierRelativeLayout)fragmentView.findViewById(R.id.chat_layout);
- sizeNotifierRelativeLayout.delegate = this;
- contentView = sizeNotifierRelativeLayout;
-
+ View contentView = fragmentView.findViewById(R.id.chat_layout);
emptyView = (TextView)fragmentView.findViewById(R.id.searchEmptyView);
emptyView.setText(LocaleController.getString("NoMessages", R.string.NoMessages));
chatListView = (LayoutListView)fragmentView.findViewById(R.id.chat_list_view);
@@ -641,9 +604,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
View bottomOverlayChat = fragmentView.findViewById(R.id.bottom_overlay_chat);
progressView = fragmentView.findViewById(R.id.progressLayout);
pagedownButton = fragmentView.findViewById(R.id.pagedown_button);
- audioSendButton = (ImageButton)fragmentView.findViewById(R.id.chat_audio_send_button);
- recordPanel = fragmentView.findViewById(R.id.record_panel);
- recordTimeText = (TextView)fragmentView.findViewById(R.id.recording_time_text);
+
View progressViewInner = progressView.findViewById(R.id.progressLayoutInner);
updateContactStatus();
@@ -693,8 +654,8 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
} else {
secretChatPlaceholder.setBackgroundResource(R.drawable.system_blue);
}
- secretViewStatusTextView = (TextView)contentView.findViewById(R.id.invite_text);
- secretChatPlaceholder.setPadding(Utilities.dp(16), Utilities.dp(12), Utilities.dp(16), Utilities.dp(12));
+ secretViewStatusTextView = (TextView) contentView.findViewById(R.id.invite_text);
+ secretChatPlaceholder.setPadding(AndroidUtilities.dp(16), AndroidUtilities.dp(12), AndroidUtilities.dp(16), AndroidUtilities.dp(12));
View v = contentView.findViewById(R.id.secret_placeholder);
v.setVisibility(View.VISIBLE);
@@ -723,7 +684,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
progressViewInner.setBackgroundResource(R.drawable.system_loader1);
emptyView.setBackgroundResource(R.drawable.system_blue);
}
- emptyView.setPadding(Utilities.dp(7), Utilities.dp(1), Utilities.dp(7), Utilities.dp(1));
+ emptyView.setPadding(AndroidUtilities.dp(7), AndroidUtilities.dp(1), AndroidUtilities.dp(7), AndroidUtilities.dp(1));
if (currentUser != null && currentUser.id / 1000 == 333) {
emptyView.setText(LocaleController.getString("GotAQuestion", R.string.GotAQuestion));
@@ -783,12 +744,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
}
});
- messsageEditText = (EditText)fragmentView.findViewById(R.id.chat_text_edit);
- messsageEditText.setHint(LocaleController.getString("TypeMessage", R.string.TypeMessage));
- slideText = fragmentView.findViewById(R.id.slideText);
- TextView textView = (TextView)fragmentView.findViewById(R.id.slideToCancelTextView);
- textView.setText(LocaleController.getString("SlideToCancel", R.string.SlideToCancel));
- textView = (TextView)fragmentView.findViewById(R.id.bottom_overlay_chat_text);
+ TextView textView = (TextView)fragmentView.findViewById(R.id.bottom_overlay_chat_text);
if (currentUser == null) {
textView.setText(LocaleController.getString("DeleteThisGroup", R.string.DeleteThisGroup));
} else {
@@ -805,11 +761,6 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
textView = (TextView)fragmentView.findViewById(R.id.secret_description4);
textView.setText(LocaleController.getString("EncryptedDescription4", R.string.EncryptedDescription4));
- sendButton = (ImageButton)fragmentView.findViewById(R.id.chat_send_button);
- sendButton.setEnabled(false);
- sendButton.setVisibility(View.INVISIBLE);
- emojiButton = (ImageView)fragmentView.findViewById(R.id.chat_smile_button);
-
if (loading && messages.isEmpty()) {
progressView.setVisibility(View.VISIBLE);
chatListView.setEmptyView(null);
@@ -822,123 +773,6 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
}
}
- emojiButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- if (emojiPopup == null) {
- showEmojiPopup(true);
- } else {
- showEmojiPopup(!emojiPopup.isShowing());
- }
- }
- });
-
- messsageEditText.setOnKeyListener(new View.OnKeyListener() {
- @Override
- public boolean onKey(View view, int i, KeyEvent keyEvent) {
- if (i == 4 && !keyboardVisible && emojiPopup != null && emojiPopup.isShowing()) {
- if (keyEvent.getAction() == 1) {
- showEmojiPopup(false);
- }
- return true;
- } else if (i == KeyEvent.KEYCODE_ENTER && sendByEnter && keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
- sendMessage();
- return true;
- }
- return false;
- }
- });
-
- messsageEditText.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- if (emojiPopup != null && emojiPopup.isShowing()) {
- showEmojiPopup(false);
- }
- }
- });
-
- messsageEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
- @Override
- public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
- if (i == EditorInfo.IME_ACTION_SEND) {
- sendMessage();
- return true;
- } else if (sendByEnter) {
- if (keyEvent != null && i == EditorInfo.IME_NULL && keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
- sendMessage();
- return true;
- }
- }
- return false;
- }
- });
-
- sendButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- sendMessage();
- }
- });
-
- audioSendButton.setOnTouchListener(new View.OnTouchListener() {
- @Override
- public boolean onTouch(View view, MotionEvent motionEvent) {
- if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
- startedDraggingX = -1;
- MediaController.getInstance().startRecording(dialog_id);
- updateAudioRecordIntefrace();
- } else if (motionEvent.getAction() == MotionEvent.ACTION_UP || motionEvent.getAction() == MotionEvent.ACTION_CANCEL) {
- startedDraggingX = -1;
- MediaController.getInstance().stopRecording(true);
- recordingAudio = false;
- updateAudioRecordIntefrace();
- } else if (motionEvent.getAction() == MotionEvent.ACTION_MOVE && recordingAudio) {
- float x = motionEvent.getX();
- if (x < -distCanMove) {
- MediaController.getInstance().stopRecording(false);
- recordingAudio = false;
- updateAudioRecordIntefrace();
- }
- if(android.os.Build.VERSION.SDK_INT > 13) {
- x = x + audioSendButton.getX();
- FrameLayout.LayoutParams params = (FrameLayout.LayoutParams)slideText.getLayoutParams();
- if (startedDraggingX != -1) {
- float dist = (x - startedDraggingX);
- params.leftMargin = Utilities.dp(30) + (int)dist;
- slideText.setLayoutParams(params);
- float alpha = 1.0f + dist / distCanMove;
- if (alpha > 1) {
- alpha = 1;
- } else if (alpha < 0) {
- alpha = 0;
- }
- slideText.setAlpha(alpha);
- }
- if (x <= slideText.getX() + slideText.getWidth() + Utilities.dp(30)) {
- if (startedDraggingX == -1) {
- startedDraggingX = x;
- distCanMove = (recordPanel.getMeasuredWidth() - slideText.getMeasuredWidth() - Utilities.dp(48)) / 2.0f;
- if (distCanMove <= 0) {
- distCanMove = Utilities.dp(80);
- } else if (distCanMove > Utilities.dp(80)) {
- distCanMove = Utilities.dp(80);
- }
- }
- }
- if (params.leftMargin > Utilities.dp(30)) {
- params.leftMargin = Utilities.dp(30);
- slideText.setLayoutParams(params);
- slideText.setAlpha(1);
- startedDraggingX = -1;
- }
- }
- }
- view.onTouchEvent(motionEvent);
- return true;
- }
- });
-
pagedownButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
@@ -946,49 +780,6 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
}
});
- checkSendButton();
-
- messsageEditText.addTextChangedListener(new TextWatcher() {
- @Override
- public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
-
- }
-
- @Override
- public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
- String message = getTrimmedString(charSequence.toString());
- sendButton.setEnabled(message.length() != 0);
- checkSendButton();
-
- if (message.length() != 0 && lastTypingTimeSend < System.currentTimeMillis() - 5000 && !ignoreTextChange) {
- int currentTime = ConnectionsManager.getInstance().getCurrentTime();
- if (currentUser != null && currentUser.status != null && currentUser.status.expires < currentTime) {
- return;
- }
- lastTypingTimeSend = System.currentTimeMillis();
- MessagesController.getInstance().sendTyping(dialog_id, classGuid);
- }
- }
-
- @Override
- public void afterTextChanged(Editable editable) {
- if (sendByEnter && editable.length() > 0 && editable.charAt(editable.length() - 1) == '\n') {
- sendMessage();
- }
- int i = 0;
- ImageSpan[] arrayOfImageSpan = editable.getSpans(0, editable.length(), ImageSpan.class);
- int j = arrayOfImageSpan.length;
- while (true) {
- if (i >= j) {
- Emoji.replaceEmoji(editable, messsageEditText.getPaint().getFontMetricsInt(), Utilities.dp(20));
- return;
- }
- editable.removeSpan(arrayOfImageSpan[i]);
- i++;
- }
- }
- });
-
bottomOverlayChat.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
@@ -1027,6 +818,8 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
} else {
bottomOverlayChat.setVisibility(View.GONE);
}
+
+ chatActivityEnterView.setContainerView(getParentActivity(), fragmentView);
} else {
ViewGroup parent = (ViewGroup)fragmentView.getParent();
if (parent != null) {
@@ -1036,125 +829,6 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
return fragmentView;
}
- private String getTrimmedString(String src) {
- String result = src.trim();
- if (result.length() == 0) {
- return result;
- }
- while (src.startsWith("\n")) {
- src = src.substring(1);
- }
- while (src.endsWith("\n")) {
- src = src.substring(0, src.length() - 1);
- }
- return src;
- }
-
- private void checkSendButton() {
- String message = getTrimmedString(messsageEditText.getText().toString());
- if (message.length() > 0) {
- sendButton.setVisibility(View.VISIBLE);
- audioSendButton.setVisibility(View.INVISIBLE);
- } else {
- sendButton.setVisibility(View.INVISIBLE);
- audioSendButton.setVisibility(View.VISIBLE);
- }
- }
-
- private void updateAudioRecordIntefrace() {
- if (recordingAudio) {
- try {
- if (mWakeLock == null) {
- PowerManager pm = (PowerManager) ApplicationLoader.applicationContext.getSystemService(Context.POWER_SERVICE);
- mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "audio record lock");
- mWakeLock.acquire();
- }
- } catch (Exception e) {
- FileLog.e("tmessages", e);
- }
- Utilities.lockOrientation(getParentActivity());
-
- recordPanel.setVisibility(View.VISIBLE);
- recordTimeText.setText("00:00");
- lastTimeString = null;
- if(android.os.Build.VERSION.SDK_INT > 13) {
- FrameLayout.LayoutParams params = (FrameLayout.LayoutParams)slideText.getLayoutParams();
- params.leftMargin = Utilities.dp(30);
- slideText.setLayoutParams(params);
- slideText.setAlpha(1);
- recordPanel.setX(Utilities.displaySize.x);
- recordPanel.animate().setInterpolator(new AccelerateDecelerateInterpolator()).setListener(new Animator.AnimatorListener() {
- @Override
- public void onAnimationStart(Animator animator) {
- }
-
- @Override
- public void onAnimationEnd(Animator animator) {
- recordPanel.setX(0);
- }
-
- @Override
- public void onAnimationCancel(Animator animator) {
- }
-
- @Override
- public void onAnimationRepeat(Animator animator) {
- }
- }).setDuration(300).translationX(0).start();
- }
- } else {
- if (mWakeLock != null) {
- try {
- mWakeLock.release();
- mWakeLock = null;
- } catch (Exception e) {
- FileLog.e("tmessages", e);
- }
- }
- Utilities.unlockOrientation(getParentActivity());
- if(android.os.Build.VERSION.SDK_INT > 13) {
- recordPanel.animate().setInterpolator(new AccelerateDecelerateInterpolator()).setListener(new Animator.AnimatorListener() {
- @Override
- public void onAnimationStart(Animator animator) {
-
- }
-
- @Override
- public void onAnimationEnd(Animator animator) {
- FrameLayout.LayoutParams params = (FrameLayout.LayoutParams)slideText.getLayoutParams();
- params.leftMargin = Utilities.dp(30);
- slideText.setLayoutParams(params);
- slideText.setAlpha(1);
- recordPanel.setVisibility(View.GONE);
- }
-
- @Override
- public void onAnimationCancel(Animator animator) {
- }
-
- @Override
- public void onAnimationRepeat(Animator animator) {
- }
- }).setDuration(300).translationX(Utilities.displaySize.x).start();
- } else {
- recordPanel.setVisibility(View.GONE);
- }
- }
- }
-
- private void sendMessage() {
- if (processSendingText(messsageEditText.getText().toString())) {
- messsageEditText.setText("");
- lastTypingTimeSend = 0;
- chatListView.post(new Runnable() {
- @Override
- public void run() {
- chatListView.setSelectionFromTop(messages.size() - 1, -100000 - chatListView.getPaddingTop());
- }
- });
- }
- }
-
private void scrollToLastMessage() {
if (unread_end_reached || first_unread_id == 0) {
chatListView.setSelectionFromTop(messages.size() - 1, -100000 - chatListView.getPaddingTop());
@@ -1235,8 +909,8 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
bottomOverlay.setVisibility(View.GONE);
}
if (hideKeyboard) {
- hideEmojiPopup();
- Utilities.hideKeyboard(getParentActivity().getCurrentFocus());
+ chatActivityEnterView.hideEmojiPopup();
+ AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
}
checkActionBarMenu();
}
@@ -1393,7 +1067,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
}
}
if (!canSave) {
- File f = new File(Utilities.getCacheDir(), messageObject.getFileName());
+ File f = new File(AndroidUtilities.getCacheDir(), messageObject.getFileName());
if (f.exists()) {
canSave = true;
}
@@ -1437,7 +1111,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
}
}
if (!canSave) {
- File f = new File(Utilities.getCacheDir(), messageObject.getFileName());
+ File f = new File(AndroidUtilities.getCacheDir(), messageObject.getFileName());
if (f.exists()) {
canSave = true;
}
@@ -1584,57 +1258,6 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
}
}
- @Override
- public void onSizeChanged(int height) {
- Rect localRect = new Rect();
- getParentActivity().getWindow().getDecorView().getWindowVisibleDisplayFrame(localRect);
-
- WindowManager manager = (WindowManager) ApplicationLoader.applicationContext.getSystemService(Activity.WINDOW_SERVICE);
- if (manager == null || manager.getDefaultDisplay() == null) {
- return;
- }
- int rotation = manager.getDefaultDisplay().getRotation();
-
- if (height > Utilities.dp(50)) {
- if (rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90) {
- keyboardHeightLand = height;
- ApplicationLoader.applicationContext.getSharedPreferences("emoji", 0).edit().putInt("kbd_height_land3", keyboardHeightLand).commit();
- } else {
- keyboardHeight = height;
- ApplicationLoader.applicationContext.getSharedPreferences("emoji", 0).edit().putInt("kbd_height", keyboardHeight).commit();
- }
- }
-
- if (emojiPopup != null && emojiPopup.isShowing()) {
- WindowManager wm = (WindowManager) ApplicationLoader.applicationContext.getSystemService(Context.WINDOW_SERVICE);
- final WindowManager.LayoutParams layoutParams = (WindowManager.LayoutParams)emojiPopup.getContentView().getLayoutParams();
- layoutParams.width = contentView.getWidth();
- if (rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90) {
- layoutParams.height = keyboardHeightLand;
- } else {
- layoutParams.height = keyboardHeight;
- }
- wm.updateViewLayout(emojiPopup.getContentView(), layoutParams);
- if (!keyboardVisible) {
- contentView.post(new Runnable() {
- @Override
- public void run() {
- contentView.setPadding(0, 0, 0, layoutParams.height);
- contentView.requestLayout();
- }
- });
- }
- }
-
- boolean oldValue = keyboardVisible;
- keyboardVisible = height > 0;
- if (keyboardVisible && contentView.getPaddingBottom() > 0) {
- showEmojiPopup(false);
- } else if (!keyboardVisible && keyboardVisible != oldValue && emojiPopup != null && emojiPopup.isShowing()) {
- showEmojiPopup(false);
- }
- }
-
@Override
public void onActivityResultFragment(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK) {
@@ -1723,16 +1346,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
}
public boolean processSendingText(String text) {
- text = getTrimmedString(text);
- if (text.length() != 0) {
- int count = (int)Math.ceil(text.length() / 2048.0f);
- for (int a = 0; a < count; a++) {
- String mess = text.substring(a * 2048, Math.min((a + 1) * 2048, text.length()));
- MessagesController.getInstance().sendMessage(mess, dialog_id);
- }
- return true;
- }
- return false;
+ return chatActivityEnterView.processSendingText(text);
}
public void processSendingPhoto(String imageFilePath, Uri imageUri) {
@@ -1958,6 +1572,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
video = new TLRPC.TL_video();
video.thumb = size;
video.caption = "";
+ video.mime_type = "video/mp4";
video.id = 0;
File temp = new File(videoPath);
if (temp != null && temp.exists()) {
@@ -2136,18 +1751,20 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
chatAdapter.notifyDataSetChanged();
if (positionToUnread && unreadMessageObject != null) {
if (messages.get(messages.size() - 1) == unreadMessageObject) {
- chatListView.setSelectionFromTop(0, Utilities.dp(-11));
+ chatListView.setSelectionFromTop(0, AndroidUtilities.dp(-11));
} else {
- chatListView.setSelectionFromTop(messages.size() - messages.indexOf(unreadMessageObject), Utilities.dp(-11));
+ chatListView.setSelectionFromTop(messages.size() - messages.indexOf(unreadMessageObject), AndroidUtilities.dp(-11));
}
ViewTreeObserver obs = chatListView.getViewTreeObserver();
obs.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
- if (messages.get(messages.size() - 1) == unreadMessageObject) {
- chatListView.setSelectionFromTop(0, Utilities.dp(-11));
- } else {
- chatListView.setSelectionFromTop(messages.size() - messages.indexOf(unreadMessageObject), Utilities.dp(-11));
+ if (!messages.isEmpty()) {
+ if (messages.get(messages.size() - 1) == unreadMessageObject) {
+ chatListView.setSelectionFromTop(0, AndroidUtilities.dp(-11));
+ } else {
+ chatListView.setSelectionFromTop(messages.size() - messages.indexOf(unreadMessageObject), AndroidUtilities.dp(-11));
+ }
}
chatListView.getViewTreeObserver().removeOnPreDrawListener(this);
return false;
@@ -2212,9 +1829,6 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
if (chatListView != null) {
chatListView.invalidateViews();
}
- if (emojiView != null) {
- emojiView.invalidateViews();
- }
} else if (id == MessagesController.updateInterfaces) {
int updateMask = (Integer)args[0];
if ((updateMask & MessagesController.UPDATE_MASK_NAME) != 0 || (updateMask & MessagesController.UPDATE_MASK_STATUS) != 0 || (updateMask & MessagesController.UPDATE_MASK_CHAT_NAME) != 0 || (updateMask & MessagesController.UPDATE_MASK_CHAT_MEMBERS) != 0) {
@@ -2392,9 +2006,6 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
}
}
} else if (id == MessagesController.closeChats) {
- if (messsageEditText != null && messsageEditText.isFocused()) {
- Utilities.hideKeyboard(messsageEditText);
- }
removeSelfFromStack();
} else if (id == MessagesController.messagesReaded) {
ArrayList markAsReadMessages = (ArrayList)args[0];
@@ -2591,14 +2202,6 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
}
}
}
- } else if (id == MediaController.recordProgressChanged) {
- Long time = (Long)args[0] / 1000;
- String str = String.format("%02d:%02d", time / 60, time % 60);
- if (lastTimeString == null || !lastPrintString.equals(str)) {
- if (recordTimeText != null) {
- recordTimeText.setText(str);
- }
- }
} else if (id == MessagesController.removeAllMessagesFromDialog) {
messages.clear();
messagesByDays.clear();
@@ -2622,16 +2225,6 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
selectedMessagesCanCopyIds.clear();
actionBarLayer.hideActionMode();
chatAdapter.notifyDataSetChanged();
- } else if (id == MediaController.recordStartError || id == MediaController.recordStopped) {
- if (recordingAudio) {
- recordingAudio = false;
- updateAudioRecordIntefrace();
- }
- } else if (id == MediaController.recordStarted) {
- if (!recordingAudio) {
- recordingAudio = true;
- updateAudioRecordIntefrace();
- }
} else if (id == MediaController.screenshotTook) {
updateInformationForScreenshotDetector();
}
@@ -2658,7 +2251,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
topPanel.setVisibility(View.GONE);
} else {
topPanel.setVisibility(View.VISIBLE);
- topPanelText.setShadowLayer(1, 0, Utilities.dp(1), 0xff8797a3);
+ topPanelText.setShadowLayer(1, 0, AndroidUtilities.dp(1), 0xff8797a3);
if (isCustomTheme) {
topPlaneClose.setImageResource(R.drawable.ic_msg_btn_cross_custom);
topPanel.setBackgroundResource(R.drawable.top_pane_custom);
@@ -2727,82 +2320,6 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
}
}
- private void createEmojiPopup() {
- if (getParentActivity() == null) {
- return;
- }
- emojiView = new EmojiView(getParentActivity());
- emojiView.setListener(new EmojiView.Listener() {
- public void onBackspace() {
- messsageEditText.dispatchKeyEvent(new KeyEvent(0, 67));
- }
-
- public void onEmojiSelected(String paramAnonymousString) {
- int i = messsageEditText.getSelectionEnd();
- CharSequence localCharSequence = Emoji.replaceEmoji(paramAnonymousString, messsageEditText.getPaint().getFontMetricsInt(), Utilities.dp(20));
- messsageEditText.setText(messsageEditText.getText().insert(i, localCharSequence));
- int j = i + localCharSequence.length();
- messsageEditText.setSelection(j, j);
- }
- });
- emojiPopup = new PopupWindow(emojiView);
- }
-
- private void showEmojiPopup(boolean show) {
- InputMethodManager localInputMethodManager = (InputMethodManager)ApplicationLoader.applicationContext.getSystemService(Context.INPUT_METHOD_SERVICE);
- if (show) {
- if (emojiPopup == null) {
- createEmojiPopup();
- }
- int currentHeight;
- WindowManager manager = (WindowManager) ApplicationLoader.applicationContext.getSystemService(Activity.WINDOW_SERVICE);
- int rotation = manager.getDefaultDisplay().getRotation();
- if (keyboardHeight <= 0) {
- keyboardHeight = ApplicationLoader.applicationContext.getSharedPreferences("emoji", 0).getInt("kbd_height", Utilities.dp(200));
- }
- if (keyboardHeightLand <= 0) {
- keyboardHeightLand = ApplicationLoader.applicationContext.getSharedPreferences("emoji", 0).getInt("kbd_height_land3", Utilities.dp(200));
- }
- if (rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90) {
- currentHeight = keyboardHeightLand;
- } else {
- currentHeight = keyboardHeight;
- }
- emojiPopup.setHeight(View.MeasureSpec.makeMeasureSpec(currentHeight, View.MeasureSpec.EXACTLY));
- emojiPopup.setWidth(View.MeasureSpec.makeMeasureSpec(contentView.getWidth(), View.MeasureSpec.EXACTLY));
-
- emojiPopup.showAtLocation(getParentActivity().getWindow().getDecorView(), 83, 0, 0);
- if (!keyboardVisible) {
- contentView.setPadding(0, 0, 0, currentHeight);
- emojiButton.setImageResource(R.drawable.ic_msg_panel_hide);
- return;
- }
- emojiButton.setImageResource(R.drawable.ic_msg_panel_kb);
- return;
- }
- if (emojiButton != null) {
- emojiButton.setImageResource(R.drawable.ic_msg_panel_smiles);
- }
- if (emojiPopup != null) {
- emojiPopup.dismiss();
- }
- if (contentView != null) {
- contentView.post(new Runnable() {
- public void run() {
- if (contentView != null) {
- contentView.setPadding(0, 0, 0, 0);
- }
- }
- });
- }
- }
-
- public void hideEmojiPopup() {
- if (emojiPopup != null && emojiPopup.isShowing()) {
- showEmojiPopup(false);
- }
- }
-
@Override
public void onResume() {
super.onResume();
@@ -2815,7 +2332,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
if (scrollToTopOnResume) {
if (scrollToTopUnReadOnResume && unreadMessageObject != null) {
if (chatListView != null) {
- chatListView.setSelectionFromTop(messages.size() - messages.indexOf(unreadMessageObject), -chatListView.getPaddingTop() - Utilities.dp(7));
+ chatListView.setSelectionFromTop(messages.size() - messages.indexOf(unreadMessageObject), -chatListView.getPaddingTop() - AndroidUtilities.dp(7));
}
} else {
if (chatListView != null) {
@@ -2838,21 +2355,9 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
SharedPreferences.Editor editor = preferences.edit();
editor.remove("dialog_" + dialog_id);
editor.commit();
- ignoreTextChange = true;
- messsageEditText.setText(lastMessageText);
- messsageEditText.setSelection(messsageEditText.getText().length());
- ignoreTextChange = false;
- }
- if (messsageEditText != null) {
- messsageEditText.postDelayed(new Runnable() {
- @Override
- public void run() {
- if (messsageEditText != null) {
- messsageEditText.requestFocus();
- }
- }
- }, 400);
+ chatActivityEnterView.setFieldText(lastMessageText);
}
+ chatActivityEnterView.setFieldFocused(true);
if (currentEncryptedChat != null) {
chatEnterTime = System.currentTimeMillis();
chatLeaveTime = 0;
@@ -2878,7 +2383,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
@Override
public void onBeginSlide() {
super.onBeginSlide();
- hideEmojiPopup();
+ chatActivityEnterView.hideEmojiPopup();
}
private void setTypingAnimation(boolean start) {
@@ -2888,9 +2393,9 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
if (start) {
try {
if (currentChat != null) {
- actionBarLayer.setSubTitleIcon(R.drawable.typing_dots_chat, Utilities.dp(4));
+ actionBarLayer.setSubTitleIcon(R.drawable.typing_dots_chat, AndroidUtilities.dp(4));
} else {
- actionBarLayer.setSubTitleIcon(R.drawable.typing_dots, Utilities.dp(4));
+ actionBarLayer.setSubTitleIcon(R.drawable.typing_dots, AndroidUtilities.dp(4));
}
AnimationDrawable mAnim = (AnimationDrawable)actionBarLayer.getSubTitleIcon();
mAnim.setAlpha(200);
@@ -2907,21 +2412,24 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
public void onPause() {
super.onPause();
actionBarLayer.hideActionMode();
- hideEmojiPopup();
+ chatActivityEnterView.hideEmojiPopup();
paused = true;
MessagesController.getInstance().openned_dialog_id = 0;
- if (messsageEditText != null && messsageEditText.length() != 0) {
+ String text = chatActivityEnterView.getFieldText();
+ if (text != null) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
- editor.putString("dialog_" + dialog_id, messsageEditText.getText().toString());
+ editor.putString("dialog_" + dialog_id, text);
editor.commit();
}
- if (currentEncryptedChat != null) {
+ chatActivityEnterView.setFieldFocused(false);
+
+ /*if (currentEncryptedChat != null) { disabled
chatLeaveTime = System.currentTimeMillis();
updateInformationForScreenshotDetector();
- }
+ }*/
}
private void updateInformationForScreenshotDetector() {
@@ -2961,9 +2469,9 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
if (getParentActivity() == null) {
return true;
}
- int height = Utilities.dp(48);
+ int height = AndroidUtilities.dp(48);
if (!Utilities.isTablet(getParentActivity()) && getParentActivity().getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
- height = Utilities.dp(40);
+ height = AndroidUtilities.dp(40);
selectedMessagesCountTextView.setTextSize(16);
} else {
selectedMessagesCountTextView.setTextSize(18);
@@ -3168,7 +2676,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
}
}
if (locFile == null) {
- File f = new File(Utilities.getCacheDir(), selectedObject.getFileName());
+ File f = new File(AndroidUtilities.getCacheDir(), selectedObject.getFileName());
if (f.exists()) {
locFile = f;
}
@@ -3379,8 +2887,8 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
actionBarLayer.hideActionMode();
updateVisibleRows();
return false;
- } else if (emojiPopup != null && emojiPopup.isShowing()) {
- hideEmojiPopup();
+ } else if (chatActivityEnterView.isEmojiPopupShowing()) {
+ chatActivityEnterView.hideEmojiPopup();
return false;
}
return true;
@@ -3469,16 +2977,16 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
if (!disableSelection) {
if (messageType == 12) {
holder.chatBubbleView.setBackgroundResource(R.drawable.chat_outgoing_text_states);
- holder.chatBubbleView.setPadding(Utilities.dp(6), Utilities.dp(6), Utilities.dp(18), 0);
+ holder.chatBubbleView.setPadding(AndroidUtilities.dp(6), AndroidUtilities.dp(6), AndroidUtilities.dp(18), 0);
} else if (messageType == 13) {
holder.chatBubbleView.setBackgroundResource(R.drawable.chat_incoming_text_states);
- holder.chatBubbleView.setPadding(Utilities.dp(15), Utilities.dp(6), Utilities.dp(9), 0);
+ holder.chatBubbleView.setPadding(AndroidUtilities.dp(15), AndroidUtilities.dp(6), AndroidUtilities.dp(9), 0);
} else if (messageType == 8) {
holder.chatBubbleView.setBackgroundResource(R.drawable.chat_outgoing_text_states);
- holder.chatBubbleView.setPadding(Utilities.dp(9), Utilities.dp(9), Utilities.dp(18), 0);
+ holder.chatBubbleView.setPadding(AndroidUtilities.dp(9), AndroidUtilities.dp(9), AndroidUtilities.dp(18), 0);
} else if (messageType == 9) {
holder.chatBubbleView.setBackgroundResource(R.drawable.chat_incoming_text_states);
- holder.chatBubbleView.setPadding(Utilities.dp(18), Utilities.dp(9), Utilities.dp(9), 0);
+ holder.chatBubbleView.setPadding(AndroidUtilities.dp(18), AndroidUtilities.dp(9), AndroidUtilities.dp(9), 0);
}
} else {
if (messageType == 12) {
@@ -3487,28 +2995,28 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
} else {
holder.chatBubbleView.setBackgroundResource(R.drawable.msg_out);
}
- holder.chatBubbleView.setPadding(Utilities.dp(6), Utilities.dp(6), Utilities.dp(18), 0);
+ holder.chatBubbleView.setPadding(AndroidUtilities.dp(6), AndroidUtilities.dp(6), AndroidUtilities.dp(18), 0);
} else if (messageType == 13) {
if (selected) {
holder.chatBubbleView.setBackgroundResource(R.drawable.msg_in_selected);
} else {
holder.chatBubbleView.setBackgroundResource(R.drawable.msg_in);
}
- holder.chatBubbleView.setPadding(Utilities.dp(15), Utilities.dp(6), Utilities.dp(9), 0);
+ holder.chatBubbleView.setPadding(AndroidUtilities.dp(15), AndroidUtilities.dp(6), AndroidUtilities.dp(9), 0);
} else if (messageType == 8) {
if (selected) {
holder.chatBubbleView.setBackgroundResource(R.drawable.msg_out_selected);
} else {
holder.chatBubbleView.setBackgroundResource(R.drawable.msg_out);
}
- holder.chatBubbleView.setPadding(Utilities.dp(9), Utilities.dp(9), Utilities.dp(18), 0);
+ holder.chatBubbleView.setPadding(AndroidUtilities.dp(9), AndroidUtilities.dp(9), AndroidUtilities.dp(18), 0);
} else if (messageType == 9) {
if (selected) {
holder.chatBubbleView.setBackgroundResource(R.drawable.msg_in_selected);
} else {
holder.chatBubbleView.setBackgroundResource(R.drawable.msg_in);
}
- holder.chatBubbleView.setPadding(Utilities.dp(18), Utilities.dp(9), Utilities.dp(9), 0);
+ holder.chatBubbleView.setPadding(AndroidUtilities.dp(18), AndroidUtilities.dp(9), AndroidUtilities.dp(9), 0);
}
}
}
@@ -3563,7 +3071,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
view.getLocationInWindow(coords);
PhotoViewer.PlaceProviderObject object = new PhotoViewer.PlaceProviderObject();
object.viewX = coords[0];
- object.viewY = coords[1] - Utilities.statusBarHeight;
+ object.viewY = coords[1] - AndroidUtilities.statusBarHeight;
object.parentView = chatListView;
object.imageReceiver = imageReceiver;
object.thumb = object.imageReceiver.getBitmap();
@@ -3761,7 +3269,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
f = new File(message.messageOwner.attachPath);
}
if (f == null || f != null && !f.exists()) {
- f = new File(Utilities.getCacheDir(), message.getFileName());
+ f = new File(AndroidUtilities.getCacheDir(), message.getFileName());
}
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(f), "video/mp4");
@@ -3890,7 +3398,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
}
if (type == 11 || type == 10) {
- int width = Utilities.displaySize.x - Utilities.dp(30);
+ int width = AndroidUtilities.displaySize.x - AndroidUtilities.dp(30);
messageTextView.setText(message.messageText);
messageTextView.setMaxWidth(width);
@@ -3898,7 +3406,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
if (message.messageOwner.action instanceof TLRPC.TL_messageActionUserUpdatedPhoto) {
photoImage.setImage(message.messageOwner.action.newUserPhoto.photo_small, "50_50", Utilities.getUserAvatarForId(currentUser.id));
} else {
- PhotoObject photo = PhotoObject.getClosestImageWithSize(message.photoThumbs, Utilities.dp(64), Utilities.dp(64));
+ PhotoObject photo = PhotoObject.getClosestImageWithSize(message.photoThumbs, AndroidUtilities.dp(64), AndroidUtilities.dp(64));
if (photo != null) {
if (photo.image != null) {
photoImage.setImageBitmap(photo.image);
@@ -4093,7 +3601,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
}
if (load && message.messageOwner.attachPath != null && message.messageOwner.attachPath.length() != 0 || !load && (message.messageOwner.attachPath == null || message.messageOwner.attachPath.length() == 0)) {
File cacheFile = null;
- if ((cacheFile = new File(Utilities.getCacheDir(), fileName)).exists()) {
+ if ((cacheFile = new File(AndroidUtilities.getCacheDir(), fileName)).exists()) {
if (actionAttachButton != null) {
actionAttachButton.setVisibility(View.VISIBLE);
if (message.type == 8 || message.type == 9) {
@@ -4141,15 +3649,15 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
int width;
if (currentChat != null && type != 8) {
if (actionView.getVisibility() == View.VISIBLE) {
- width = Utilities.displaySize.x - Utilities.dp(290);
+ width = AndroidUtilities.displaySize.x - AndroidUtilities.dp(290);
} else {
- width = Utilities.displaySize.x - Utilities.dp(270);
+ width = AndroidUtilities.displaySize.x - AndroidUtilities.dp(270);
}
} else {
if (actionView.getVisibility() == View.VISIBLE) {
- width = Utilities.displaySize.x - Utilities.dp(240);
+ width = AndroidUtilities.displaySize.x - AndroidUtilities.dp(240);
} else {
- width = Utilities.displaySize.x - Utilities.dp(220);
+ width = AndroidUtilities.displaySize.x - AndroidUtilities.dp(220);
}
}
nameTextView.setMaxWidth(width);
@@ -4393,7 +3901,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
f = new File(message.messageOwner.attachPath);
}
if (f == null || f != null && !f.exists()) {
- f = new File(Utilities.getCacheDir(), fileName);
+ f = new File(AndroidUtilities.getCacheDir(), fileName);
}
if (f != null && f.exists()) {
String realMimeType = null;
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ChatProfileActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ChatProfileActivity.java
index 5647e0d0..6eb1d792 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/ChatProfileActivity.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/ChatProfileActivity.java
@@ -23,12 +23,13 @@ import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.TextView;
-import org.telegram.messenger.LocaleController;
-import org.telegram.messenger.MessagesStorage;
+import org.telegram.android.AndroidUtilities;
+import org.telegram.android.LocaleController;
+import org.telegram.android.MessagesStorage;
import org.telegram.messenger.TLRPC;
import org.telegram.messenger.ConnectionsManager;
import org.telegram.messenger.FileLog;
-import org.telegram.messenger.MessagesController;
+import org.telegram.android.MessagesController;
import org.telegram.messenger.NotificationCenter;
import org.telegram.messenger.R;
import org.telegram.messenger.UserConfig;
@@ -299,7 +300,7 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen
avatarImage.getLocationInWindow(coords);
PhotoViewer.PlaceProviderObject object = new PhotoViewer.PlaceProviderObject();
object.viewX = coords[0];
- object.viewY = coords[1] - Utilities.statusBarHeight;
+ object.viewY = coords[1] - AndroidUtilities.statusBarHeight;
object.parentView = listView;
object.imageReceiver = avatarImage.imageReceiver;
object.thumb = object.imageReceiver.getBitmap();
@@ -596,7 +597,7 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen
avatarImage = (BackupImageView)view.findViewById(R.id.settings_avatar_image);
avatarImage.processDetach = false;
TextView textView = (TextView)view.findViewById(R.id.settings_name);
- Typeface typeface = Utilities.getTypeface("fonts/rmedium.ttf");
+ Typeface typeface = AndroidUtilities.getTypeface("fonts/rmedium.ttf");
textView.setTypeface(typeface);
textView.setText(chat.title);
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ChatProfileChangeNameActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ChatProfileChangeNameActivity.java
index 1902d8fb..2b204a9d 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/ChatProfileChangeNameActivity.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/ChatProfileChangeNameActivity.java
@@ -20,11 +20,11 @@ import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
-import org.telegram.messenger.LocaleController;
+import org.telegram.android.AndroidUtilities;
+import org.telegram.android.LocaleController;
import org.telegram.messenger.TLRPC;
-import org.telegram.messenger.MessagesController;
+import org.telegram.android.MessagesController;
import org.telegram.messenger.R;
-import org.telegram.messenger.Utilities;
import org.telegram.ui.Views.ActionBar.BaseFragment;
public class ChatProfileChangeNameActivity extends BaseFragment {
@@ -108,14 +108,14 @@ public class ChatProfileChangeNameActivity extends BaseFragment {
boolean animations = preferences.getBoolean("view_animations", true);
if (!animations) {
firstNameField.requestFocus();
- Utilities.showKeyboard(firstNameField);
+ AndroidUtilities.showKeyboard(firstNameField);
}
}
@Override
public void onOpenAnimationEnd() {
firstNameField.requestFocus();
- Utilities.showKeyboard(firstNameField);
+ AndroidUtilities.showKeyboard(firstNameField);
}
private void saveName() {
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ContactAddActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ContactAddActivity.java
index b0ff3c5c..3ffe5163 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/ContactAddActivity.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/ContactAddActivity.java
@@ -21,11 +21,12 @@ import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
+import org.telegram.android.AndroidUtilities;
import org.telegram.PhoneFormat.PhoneFormat;
-import org.telegram.messenger.ContactsController;
-import org.telegram.messenger.LocaleController;
+import org.telegram.android.ContactsController;
+import org.telegram.android.LocaleController;
import org.telegram.messenger.TLRPC;
-import org.telegram.messenger.MessagesController;
+import org.telegram.android.MessagesController;
import org.telegram.messenger.NotificationCenter;
import org.telegram.messenger.R;
import org.telegram.messenger.Utilities;
@@ -104,7 +105,7 @@ public class ContactAddActivity extends BaseFragment implements NotificationCent
avatarImage = (BackupImageView)fragmentView.findViewById(R.id.settings_avatar_image);
avatarImage.processDetach = false;
phoneText = (TextView)fragmentView.findViewById(R.id.settings_name);
- Typeface typeface = Utilities.getTypeface("fonts/rmedium.ttf");
+ Typeface typeface = AndroidUtilities.getTypeface("fonts/rmedium.ttf");
phoneText.setTypeface(typeface);
firstNameField = (EditText)fragmentView.findViewById(R.id.first_name_field);
@@ -183,13 +184,13 @@ public class ContactAddActivity extends BaseFragment implements NotificationCent
boolean animations = preferences.getBoolean("view_animations", true);
if (!animations) {
firstNameField.requestFocus();
- Utilities.showKeyboard(firstNameField);
+ AndroidUtilities.showKeyboard(firstNameField);
}
}
@Override
public void onOpenAnimationEnd() {
firstNameField.requestFocus();
- Utilities.showKeyboard(firstNameField);
+ AndroidUtilities.showKeyboard(firstNameField);
}
}
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ContactsActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ContactsActivity.java
index 5d1e82f1..a67f82d9 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/ContactsActivity.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/ContactsActivity.java
@@ -23,13 +23,14 @@ import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.TextView;
-import org.telegram.messenger.LocaleController;
+import org.telegram.android.AndroidUtilities;
+import org.telegram.android.LocaleController;
import org.telegram.messenger.TLObject;
import org.telegram.messenger.TLRPC;
import org.telegram.messenger.ConnectionsManager;
-import org.telegram.messenger.ContactsController;
+import org.telegram.android.ContactsController;
import org.telegram.messenger.FileLog;
-import org.telegram.messenger.MessagesController;
+import org.telegram.android.MessagesController;
import org.telegram.messenger.NotificationCenter;
import org.telegram.messenger.R;
import org.telegram.messenger.RPCRequest;
@@ -148,9 +149,9 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
listView.setAdapter(listViewAdapter);
listViewAdapter.notifyDataSetChanged();
if (!LocaleController.isRTL) {
- listView.setPadding(Utilities.dp(16), listView.getPaddingTop(), Utilities.dp(30), listView.getPaddingBottom());
+ listView.setPadding(AndroidUtilities.dp(16), listView.getPaddingTop(), AndroidUtilities.dp(30), listView.getPaddingBottom());
} else {
- listView.setPadding(Utilities.dp(30), listView.getPaddingTop(), Utilities.dp(16), listView.getPaddingBottom());
+ listView.setPadding(AndroidUtilities.dp(30), listView.getPaddingTop(), AndroidUtilities.dp(16), listView.getPaddingBottom());
}
if (android.os.Build.VERSION.SDK_INT >= 11) {
listView.setFastScrollAlwaysVisible(true);
@@ -170,7 +171,7 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
if (text.length() != 0) {
searchWas = true;
if (listView != null) {
- listView.setPadding(Utilities.dp(16), listView.getPaddingTop(), Utilities.dp(16), listView.getPaddingBottom());
+ listView.setPadding(AndroidUtilities.dp(16), listView.getPaddingTop(), AndroidUtilities.dp(16), listView.getPaddingBottom());
listView.setAdapter(searchListViewAdapter);
searchListViewAdapter.notifyDataSetChanged();
if(android.os.Build.VERSION.SDK_INT >= 11) {
@@ -320,7 +321,7 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
@Override
public void onScrollStateChanged(AbsListView absListView, int i) {
if (i == SCROLL_STATE_TOUCH_SCROLL && searching && searchWas) {
- Utilities.hideKeyboard(getParentActivity().getCurrentFocus());
+ AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
}
}
@@ -419,7 +420,7 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
}
}
}
- }, null, true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassFailOnServerErrors);
+ }, true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassFailOnServerErrors);
}
}
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/CountrySelectActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/CountrySelectActivity.java
index 86c3d7eb..3303a31b 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/CountrySelectActivity.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/CountrySelectActivity.java
@@ -18,8 +18,9 @@ import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.TextView;
+import org.telegram.android.AndroidUtilities;
import org.telegram.messenger.FileLog;
-import org.telegram.messenger.LocaleController;
+import org.telegram.android.LocaleController;
import org.telegram.messenger.R;
import org.telegram.messenger.Utilities;
import org.telegram.ui.Adapters.BaseFragmentAdapter;
@@ -147,9 +148,9 @@ public class CountrySelectActivity extends BaseFragment {
ViewGroup group = (ViewGroup) listView.getParent();
listView.setAdapter(listViewAdapter);
if (!LocaleController.isRTL) {
- listView.setPadding(Utilities.dp(16), listView.getPaddingTop(), Utilities.dp(30), listView.getPaddingBottom());
+ listView.setPadding(AndroidUtilities.dp(16), listView.getPaddingTop(), AndroidUtilities.dp(30), listView.getPaddingBottom());
} else {
- listView.setPadding(Utilities.dp(30), listView.getPaddingTop(), Utilities.dp(16), listView.getPaddingBottom());
+ listView.setPadding(AndroidUtilities.dp(30), listView.getPaddingTop(), AndroidUtilities.dp(16), listView.getPaddingBottom());
}
if (android.os.Build.VERSION.SDK_INT >= 11) {
listView.setFastScrollAlwaysVisible(true);
@@ -167,7 +168,7 @@ public class CountrySelectActivity extends BaseFragment {
if (text.length() != 0) {
searchWas = true;
if (listView != null) {
- listView.setPadding(Utilities.dp(16), listView.getPaddingTop(), Utilities.dp(16), listView.getPaddingBottom());
+ listView.setPadding(AndroidUtilities.dp(16), listView.getPaddingTop(), AndroidUtilities.dp(16), listView.getPaddingBottom());
listView.setAdapter(searchListViewAdapter);
if(android.os.Build.VERSION.SDK_INT >= 11) {
listView.setFastScrollAlwaysVisible(false);
@@ -228,7 +229,7 @@ public class CountrySelectActivity extends BaseFragment {
@Override
public void onScrollStateChanged(AbsListView absListView, int i) {
if (i == SCROLL_STATE_TOUCH_SCROLL && searching && searchWas) {
- Utilities.hideKeyboard(getParentActivity().getCurrentFocus());
+ AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
}
}
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/DocumentSelectActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/DocumentSelectActivity.java
index a869af45..784963d5 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/DocumentSelectActivity.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/DocumentSelectActivity.java
@@ -24,7 +24,7 @@ import android.widget.ListView;
import android.widget.TextView;
import org.telegram.messenger.FileLog;
-import org.telegram.messenger.LocaleController;
+import org.telegram.android.LocaleController;
import org.telegram.messenger.R;
import org.telegram.messenger.Utilities;
import org.telegram.ui.Adapters.BaseFragmentAdapter;
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/GroupCreateActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/GroupCreateActivity.java
index 1192082d..28e7f77e 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/GroupCreateActivity.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/GroupCreateActivity.java
@@ -32,13 +32,14 @@ import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
+import org.telegram.android.AndroidUtilities;
import org.telegram.PhoneFormat.PhoneFormat;
-import org.telegram.messenger.LocaleController;
+import org.telegram.android.LocaleController;
import org.telegram.messenger.TLRPC;
import org.telegram.messenger.ConnectionsManager;
-import org.telegram.messenger.ContactsController;
+import org.telegram.android.ContactsController;
import org.telegram.messenger.FileLog;
-import org.telegram.messenger.MessagesController;
+import org.telegram.android.MessagesController;
import org.telegram.messenger.NotificationCenter;
import org.telegram.messenger.R;
import org.telegram.messenger.UserConfig;
@@ -72,7 +73,7 @@ public class GroupCreateActivity extends BaseFragment implements NotificationCen
int sz = super.getSize(paint, text, start, end, fm);
- int offset = Utilities.dp(6);
+ int offset = AndroidUtilities.dp(6);
int w = (fm.bottom - fm.top) / 2;
fm.top = -w - offset;
fm.bottom = w - offset;
@@ -293,7 +294,7 @@ public class GroupCreateActivity extends BaseFragment implements NotificationCen
@Override
public void onScrollStateChanged(AbsListView absListView, int i) {
if (i == SCROLL_STATE_TOUCH_SCROLL) {
- Utilities.hideKeyboard(userSelectEditText);
+ AndroidUtilities.hideKeyboard(userSelectEditText);
}
}
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/GroupCreateFinalActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/GroupCreateFinalActivity.java
index da86a814..ff2380ce 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/GroupCreateFinalActivity.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/GroupCreateFinalActivity.java
@@ -22,11 +22,11 @@ import android.widget.ImageButton;
import android.widget.TextView;
import org.telegram.messenger.ConnectionsManager;
-import org.telegram.messenger.LocaleController;
-import org.telegram.messenger.MessagesStorage;
+import org.telegram.android.LocaleController;
+import org.telegram.android.MessagesStorage;
import org.telegram.messenger.TLRPC;
import org.telegram.messenger.FileLog;
-import org.telegram.messenger.MessagesController;
+import org.telegram.android.MessagesController;
import org.telegram.messenger.NotificationCenter;
import org.telegram.messenger.R;
import org.telegram.messenger.Utilities;
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/IdenticonActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/IdenticonActivity.java
index f3010c79..b18e9909 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/IdenticonActivity.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/IdenticonActivity.java
@@ -20,11 +20,11 @@ import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;
-import org.telegram.messenger.LocaleController;
+import org.telegram.android.AndroidUtilities;
+import org.telegram.android.LocaleController;
import org.telegram.messenger.TLRPC;
-import org.telegram.messenger.MessagesController;
+import org.telegram.android.MessagesController;
import org.telegram.messenger.R;
-import org.telegram.messenger.Utilities;
import org.telegram.ui.Views.ActionBar.ActionBarLayer;
import org.telegram.ui.Views.ActionBar.BaseFragment;
import org.telegram.ui.Views.IdenticonView;
@@ -48,7 +48,7 @@ public class IdenticonActivity extends BaseFragment {
actionBarLayer.setDisplayHomeAsUpEnabled(true, R.drawable.ic_ab_back);
actionBarLayer.setBackOverlay(R.layout.updating_state_layout);
actionBarLayer.setTitle(LocaleController.getString("EncryptionKey", R.string.EncryptionKey));
- actionBarLayer.setTitleIcon(R.drawable.ic_lock_white, Utilities.dp(4));
+ actionBarLayer.setTitleIcon(R.drawable.ic_lock_white, AndroidUtilities.dp(4));
actionBarLayer.setActionBarMenuOnItemClick(new ActionBarLayer.ActionBarMenuOnItemClick() {
@Override
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/IntroActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/IntroActivity.java
index 8c7d563a..d8141fda 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/IntroActivity.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/IntroActivity.java
@@ -24,7 +24,7 @@ import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.TextView;
-import org.telegram.messenger.LocaleController;
+import org.telegram.android.LocaleController;
import org.telegram.messenger.R;
import org.telegram.messenger.Utilities;
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/LanguageSelectActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/LanguageSelectActivity.java
index 55961389..dc4e56ae 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/LanguageSelectActivity.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/LanguageSelectActivity.java
@@ -20,8 +20,9 @@ import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
+import org.telegram.android.AndroidUtilities;
import org.telegram.messenger.FileLog;
-import org.telegram.messenger.LocaleController;
+import org.telegram.android.LocaleController;
import org.telegram.messenger.R;
import org.telegram.messenger.Utilities;
import org.telegram.ui.Adapters.BaseFragmentAdapter;
@@ -86,7 +87,7 @@ public class LanguageSelectActivity extends BaseFragment {
if (text.length() != 0) {
searchWas = true;
if (listView != null) {
- listView.setPadding(Utilities.dp(16), listView.getPaddingTop(), Utilities.dp(16), listView.getPaddingBottom());
+ listView.setPadding(AndroidUtilities.dp(16), listView.getPaddingTop(), AndroidUtilities.dp(16), listView.getPaddingBottom());
listView.setAdapter(searchListViewAdapter);
if(android.os.Build.VERSION.SDK_INT >= 11) {
listView.setFastScrollAlwaysVisible(false);
@@ -176,7 +177,7 @@ public class LanguageSelectActivity extends BaseFragment {
@Override
public void onScrollStateChanged(AbsListView absListView, int i) {
if (i == SCROLL_STATE_TOUCH_SCROLL && searching && searchWas) {
- Utilities.hideKeyboard(getParentActivity().getCurrentFocus());
+ AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
}
}
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java
index 23de06c1..e0e7c221 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java
@@ -8,38 +8,31 @@
package org.telegram.ui;
-import android.app.NotificationManager;
import android.content.ContentResolver;
-import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
-import android.content.res.Configuration;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.os.Parcelable;
import android.provider.ContactsContract;
-import android.view.Surface;
import android.view.View;
-import android.view.WindowManager;
-import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
+import org.telegram.android.AndroidUtilities;
import org.telegram.PhoneFormat.PhoneFormat;
import org.telegram.messenger.ConnectionsManager;
import org.telegram.messenger.FileLog;
-import org.telegram.messenger.LocaleController;
-import org.telegram.messenger.MessagesController;
+import org.telegram.android.LocaleController;
+import org.telegram.android.MessagesController;
import org.telegram.messenger.NotificationCenter;
import org.telegram.messenger.R;
import org.telegram.messenger.TLRPC;
import org.telegram.messenger.UserConfig;
import org.telegram.messenger.Utilities;
-import org.telegram.objects.MessageObject;
import org.telegram.ui.Views.ActionBar.ActionBarActivity;
import org.telegram.ui.Views.ActionBar.BaseFragment;
-import org.telegram.ui.Views.NotificationView;
import java.io.BufferedReader;
import java.io.InputStream;
@@ -49,7 +42,6 @@ import java.util.Map;
public class LaunchActivity extends ActionBarActivity implements NotificationCenter.NotificationCenterDelegate, MessagesActivity.MessagesActivityDelegate {
private boolean finished = false;
- private NotificationView notificationView;
private String videoPath = null;
private String sendingText = null;
private ArrayList photoPathsArray = null;
@@ -86,11 +78,11 @@ public class LaunchActivity extends ActionBarActivity implements NotificationCen
int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
- Utilities.statusBarHeight = getResources().getDimensionPixelSize(resourceId);
+ AndroidUtilities.statusBarHeight = getResources().getDimensionPixelSize(resourceId);
}
NotificationCenter.getInstance().postNotificationName(702, this);
- currentConnectionState = ConnectionsManager.getInstance().connectionState;
+ currentConnectionState = ConnectionsManager.getInstance().getConnectionState();
NotificationCenter.getInstance().addObserver(this, 1234);
NotificationCenter.getInstance().addObserver(this, 658);
@@ -504,14 +496,8 @@ public class LaunchActivity extends ActionBarActivity implements NotificationCen
@Override
protected void onPause() {
super.onPause();
- ConnectionsManager.setAppPaused(true);
- if (notificationView != null) {
- notificationView.hide(false);
- }
- View focusView = getCurrentFocus();
- if (focusView instanceof EditText) {
- focusView.clearFocus();
- }
+ ApplicationLoader.mainInterfacePaused = true;
+ ConnectionsManager.getInstance().setAppPaused(true, false);
}
@Override
@@ -523,20 +509,12 @@ public class LaunchActivity extends ActionBarActivity implements NotificationCen
@Override
protected void onResume() {
super.onResume();
- if (notificationView == null && getLayoutInflater() != null) {
- notificationView = (NotificationView) getLayoutInflater().inflate(R.layout.notification_layout, null);
- }
Utilities.checkForCrashes(this);
Utilities.checkForUpdates(this);
- ConnectionsManager.setAppPaused(false);
+ ApplicationLoader.mainInterfacePaused = false;
+ ConnectionsManager.getInstance().setAppPaused(false, false);
actionBar.setBackOverlayVisible(currentConnectionState != 0);
- try {
- NotificationManager mNotificationManager = (NotificationManager)this.getSystemService(Context.NOTIFICATION_SERVICE);
- mNotificationManager.cancel(1);
- MessagesController.getInstance().currentPushMessage = null;
- } catch (Exception e) {
- FileLog.e("tmessages", e);
- }
+ MessagesController.getInstance().dismissNotification();
}
@Override
@@ -550,32 +528,12 @@ public class LaunchActivity extends ActionBarActivity implements NotificationCen
NotificationCenter.getInstance().removeObserver(this, 701);
NotificationCenter.getInstance().removeObserver(this, 702);
NotificationCenter.getInstance().removeObserver(this, 703);
- if (notificationView != null) {
- notificationView.hide(false);
- notificationView.destroy();
- notificationView = null;
- }
}
@Override
public void onConfigurationChanged(android.content.res.Configuration newConfig) {
super.onConfigurationChanged(newConfig);
- Utilities.checkDisplaySize();
- }
-
- @Override
- public void needLayout() {
- super.needLayout();
- if (notificationView != null) {
- WindowManager manager = (WindowManager) getSystemService(WINDOW_SERVICE);
- int rotation = manager.getDefaultDisplay().getRotation();
-
- int height = Utilities.dp(48);
- if (!Utilities.isTablet(this) && getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
- height = Utilities.dp(40);
- }
- notificationView.applyOrientationPaddings(rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90, height);
- }
+ AndroidUtilities.checkDisplaySize();
}
@Override
@@ -614,11 +572,6 @@ public class LaunchActivity extends ActionBarActivity implements NotificationCen
args2.putInt("enc_id", push_enc_id);
presentFragment(new ChatActivity(args2), false, true);
}
- } else if (id == 701) {
- if (notificationView != null) {
- MessageObject message = (MessageObject)args[0];
- notificationView.show(message);
- }
} else if (id == 702) {
if (args[0] != this) {
onFinish();
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/LocationActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/LocationActivity.java
index ddaa3463..c0485467 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/LocationActivity.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/LocationActivity.java
@@ -26,10 +26,10 @@ import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import org.telegram.messenger.FileLog;
-import org.telegram.messenger.LocaleController;
+import org.telegram.android.LocaleController;
import org.telegram.messenger.TLRPC;
import org.telegram.objects.MessageObject;
-import org.telegram.messenger.MessagesController;
+import org.telegram.android.MessagesController;
import org.telegram.messenger.NotificationCenter;
import org.telegram.messenger.R;
import org.telegram.messenger.Utilities;
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/LoginActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/LoginActivity.java
index d19df2b5..aa2495a7 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/LoginActivity.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/LoginActivity.java
@@ -22,8 +22,9 @@ import android.widget.FrameLayout;
import android.widget.ScrollView;
import android.widget.TextView;
+import org.telegram.android.AndroidUtilities;
import org.telegram.messenger.FileLog;
-import org.telegram.messenger.LocaleController;
+import org.telegram.android.LocaleController;
import org.telegram.messenger.R;
import org.telegram.messenger.Utilities;
import org.telegram.ui.Views.ActionBar.ActionBarLayer;
@@ -265,7 +266,7 @@ public class LoginActivity extends BaseFragment implements SlideView.SlideViewDe
newView.setParams(params);
actionBarLayer.setTitle(newView.getHeaderName());
newView.onShow();
- newView.setX(back ? -Utilities.displaySize.x : Utilities.displaySize.x);
+ newView.setX(back ? -AndroidUtilities.displaySize.x : AndroidUtilities.displaySize.x);
outView.animate().setInterpolator(new AccelerateDecelerateInterpolator()).setListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animator) {
@@ -284,7 +285,7 @@ public class LoginActivity extends BaseFragment implements SlideView.SlideViewDe
@Override
public void onAnimationRepeat(Animator animator) {
}
- }).setDuration(300).translationX(back ? Utilities.displaySize.x : -Utilities.displaySize.x).start();
+ }).setDuration(300).translationX(back ? AndroidUtilities.displaySize.x : -AndroidUtilities.displaySize.x).start();
newView.animate().setInterpolator(new AccelerateDecelerateInterpolator()).setListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animator) {
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/LoginActivityPhoneView.java b/TMessagesProj/src/main/java/org/telegram/ui/LoginActivityPhoneView.java
index 6d228ad8..ea07252e 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/LoginActivityPhoneView.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/LoginActivityPhoneView.java
@@ -21,9 +21,10 @@ import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.TextView;
+import org.telegram.android.AndroidUtilities;
import org.telegram.PhoneFormat.PhoneFormat;
import org.telegram.messenger.BuildVars;
-import org.telegram.messenger.LocaleController;
+import org.telegram.android.LocaleController;
import org.telegram.messenger.TLObject;
import org.telegram.messenger.TLRPC;
import org.telegram.messenger.ConnectionsManager;
@@ -250,10 +251,10 @@ public class LoginActivityPhoneView extends SlideView implements AdapterView.OnI
}
if (codeField.length() != 0) {
- Utilities.showKeyboard(phoneField);
+ AndroidUtilities.showKeyboard(phoneField);
phoneField.requestFocus();
} else {
- Utilities.showKeyboard(codeField);
+ AndroidUtilities.showKeyboard(codeField);
codeField.requestFocus();
}
phoneField.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@@ -389,7 +390,7 @@ public class LoginActivityPhoneView extends SlideView implements AdapterView.OnI
}
});
}
- }, null, true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassFailOnServerErrors | RPCRequest.RPCRequestClassWithoutLogin);
+ }, true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassFailOnServerErrors | RPCRequest.RPCRequestClassWithoutLogin);
}
@Override
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/LoginActivityRegisterView.java b/TMessagesProj/src/main/java/org/telegram/ui/LoginActivityRegisterView.java
index 7515aa74..ec2dfd09 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/LoginActivityRegisterView.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/LoginActivityRegisterView.java
@@ -17,13 +17,13 @@ import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.TextView;
-import org.telegram.messenger.LocaleController;
+import org.telegram.android.LocaleController;
import org.telegram.messenger.TLObject;
import org.telegram.messenger.TLRPC;
import org.telegram.messenger.ConnectionsManager;
-import org.telegram.messenger.ContactsController;
-import org.telegram.messenger.MessagesController;
-import org.telegram.messenger.MessagesStorage;
+import org.telegram.android.ContactsController;
+import org.telegram.android.MessagesController;
+import org.telegram.android.MessagesStorage;
import org.telegram.messenger.R;
import org.telegram.messenger.RPCRequest;
import org.telegram.messenger.UserConfig;
@@ -184,7 +184,7 @@ public class LoginActivityRegisterView extends SlideView {
}
});
}
- }, null, true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassWithoutLogin);
+ }, true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassWithoutLogin);
}
@Override
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/LoginActivitySmsView.java b/TMessagesProj/src/main/java/org/telegram/ui/LoginActivitySmsView.java
index 7c80b277..f03db357 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/LoginActivitySmsView.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/LoginActivitySmsView.java
@@ -18,15 +18,16 @@ import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.TextView;
+import org.telegram.android.AndroidUtilities;
import org.telegram.PhoneFormat.PhoneFormat;
-import org.telegram.messenger.LocaleController;
+import org.telegram.android.LocaleController;
import org.telegram.messenger.TLObject;
import org.telegram.messenger.TLRPC;
import org.telegram.messenger.ConnectionsManager;
-import org.telegram.messenger.ContactsController;
+import org.telegram.android.ContactsController;
import org.telegram.messenger.FileLog;
-import org.telegram.messenger.MessagesController;
-import org.telegram.messenger.MessagesStorage;
+import org.telegram.android.MessagesController;
+import org.telegram.android.MessagesStorage;
import org.telegram.messenger.NotificationCenter;
import org.telegram.messenger.R;
import org.telegram.messenger.RPCRequest;
@@ -110,7 +111,7 @@ public class LoginActivitySmsView extends SlideView implements NotificationCente
return;
}
codeField.setText("");
- Utilities.setWaitingForSms(true);
+ AndroidUtilities.setWaitingForSms(true);
NotificationCenter.getInstance().addObserver(this, 998);
currentParams = params;
waitingForSms = true;
@@ -127,7 +128,7 @@ public class LoginActivitySmsView extends SlideView implements NotificationCente
String number = PhoneFormat.getInstance().format(phone);
confirmTextView.setText(Html.fromHtml(String.format(LocaleController.getString("SentSmsCode", R.string.SentSmsCode) + " %s", number)));
- Utilities.showKeyboard(codeField);
+ AndroidUtilities.showKeyboard(codeField);
codeField.requestFocus();
destroyTimer();
@@ -166,7 +167,7 @@ public class LoginActivitySmsView extends SlideView implements NotificationCente
@Override
public void run(TLObject response, TLRPC.TL_error error) {
}
- }, null, true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassFailOnServerErrors | RPCRequest.RPCRequestClassWithoutLogin);
+ }, true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassFailOnServerErrors | RPCRequest.RPCRequestClassWithoutLogin);
}
}
});
@@ -194,7 +195,7 @@ public class LoginActivitySmsView extends SlideView implements NotificationCente
}
nextPressed = true;
waitingForSms = false;
- Utilities.setWaitingForSms(false);
+ AndroidUtilities.setWaitingForSms(false);
NotificationCenter.getInstance().removeObserver(this, 998);
final TLRPC.TL_auth_signIn req = new TLRPC.TL_auth_signIn();
req.phone_number = requestPhone;
@@ -256,14 +257,14 @@ public class LoginActivitySmsView extends SlideView implements NotificationCente
}
});
}
- }, null, true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassFailOnServerErrors | RPCRequest.RPCRequestClassWithoutLogin);
+ }, true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassFailOnServerErrors | RPCRequest.RPCRequestClassWithoutLogin);
}
@Override
public void onBackPressed() {
destroyTimer();
currentParams = null;
- Utilities.setWaitingForSms(false);
+ AndroidUtilities.setWaitingForSms(false);
NotificationCenter.getInstance().removeObserver(this, 998);
waitingForSms = false;
}
@@ -271,7 +272,7 @@ public class LoginActivitySmsView extends SlideView implements NotificationCente
@Override
public void onDestroyActivity() {
super.onDestroyActivity();
- Utilities.setWaitingForSms(false);
+ AndroidUtilities.setWaitingForSms(false);
NotificationCenter.getInstance().removeObserver(this, 998);
destroyTimer();
waitingForSms = false;
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/MediaActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/MediaActivity.java
index 087b7e60..25513bb8 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/MediaActivity.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/MediaActivity.java
@@ -23,11 +23,11 @@ import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.TextView;
-import org.telegram.messenger.LocaleController;
+import org.telegram.android.AndroidUtilities;
+import org.telegram.android.LocaleController;
import org.telegram.messenger.TLRPC;
-import org.telegram.messenger.Utilities;
import org.telegram.objects.MessageObject;
-import org.telegram.messenger.MessagesController;
+import org.telegram.android.MessagesController;
import org.telegram.messenger.NotificationCenter;
import org.telegram.messenger.R;
import org.telegram.objects.PhotoObject;
@@ -284,7 +284,7 @@ public class MediaActivity extends BaseFragment implements NotificationCenter.No
imageView.getLocationInWindow(coords);
PhotoViewer.PlaceProviderObject object = new PhotoViewer.PlaceProviderObject();
object.viewX = coords[0];
- object.viewY = coords[1] - Utilities.statusBarHeight;
+ object.viewY = coords[1] - AndroidUtilities.statusBarHeight;
object.parentView = listView;
object.imageReceiver = imageView.imageReceiver;
object.thumb = object.imageReceiver.getBitmap();
@@ -327,14 +327,14 @@ public class MediaActivity extends BaseFragment implements NotificationCenter.No
if (rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90) {
listView.setNumColumns(6);
- itemWidth = getParentActivity().getResources().getDisplayMetrics().widthPixels / 6 - Utilities.dp(2) * 5;
+ itemWidth = getParentActivity().getResources().getDisplayMetrics().widthPixels / 6 - AndroidUtilities.dp(2) * 5;
listView.setColumnWidth(itemWidth);
} else {
listView.setNumColumns(4);
- itemWidth = getParentActivity().getResources().getDisplayMetrics().widthPixels / 4 - Utilities.dp(2) * 3;
+ itemWidth = getParentActivity().getResources().getDisplayMetrics().widthPixels / 4 - AndroidUtilities.dp(2) * 3;
listView.setColumnWidth(itemWidth);
}
- listView.setPadding(listView.getPaddingLeft(), Utilities.dp(4), listView.getPaddingRight(), listView.getPaddingBottom());
+ listView.setPadding(listView.getPaddingLeft(), AndroidUtilities.dp(4), listView.getPaddingRight(), listView.getPaddingBottom());
listAdapter.notifyDataSetChanged();
if (listView != null) {
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/MessagesActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/MessagesActivity.java
index 0913bfc8..1056bb7b 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/MessagesActivity.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/MessagesActivity.java
@@ -21,13 +21,14 @@ import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
-import org.telegram.messenger.LocaleController;
+import org.telegram.android.AndroidUtilities;
+import org.telegram.android.LocaleController;
import org.telegram.messenger.TLObject;
import org.telegram.messenger.TLRPC;
-import org.telegram.messenger.ContactsController;
+import org.telegram.android.ContactsController;
import org.telegram.messenger.FileLog;
-import org.telegram.messenger.MessagesController;
-import org.telegram.messenger.MessagesStorage;
+import org.telegram.android.MessagesController;
+import org.telegram.android.MessagesStorage;
import org.telegram.messenger.NotificationCenter;
import org.telegram.messenger.R;
import org.telegram.messenger.UserConfig;
@@ -347,7 +348,7 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter
@Override
public void onScrollStateChanged(AbsListView absListView, int i) {
if (i == SCROLL_STATE_TOUCH_SCROLL && searching && searchWas) {
- Utilities.hideKeyboard(getParentActivity().getCurrentFocus());
+ AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
}
}
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/PhotoCropActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/PhotoCropActivity.java
index 22e8395f..a90b2e55 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/PhotoCropActivity.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/PhotoCropActivity.java
@@ -27,11 +27,11 @@ import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.TextView;
+import org.telegram.android.AndroidUtilities;
import org.telegram.messenger.FileLoader;
import org.telegram.messenger.FileLog;
-import org.telegram.messenger.LocaleController;
+import org.telegram.android.LocaleController;
import org.telegram.messenger.R;
-import org.telegram.messenger.Utilities;
import org.telegram.ui.Views.ActionBar.BaseFragment;
import java.io.File;
@@ -72,7 +72,7 @@ public class PhotoCropActivity extends BaseFragment {
private void init() {
rectPaint = new Paint();
rectPaint.setColor(0xfffafafa);
- rectPaint.setStrokeWidth(Utilities.dp(2));
+ rectPaint.setStrokeWidth(AndroidUtilities.dp(2));
rectPaint.setStyle(Paint.Style.STROKE);
circlePaint = new Paint();
circlePaint.setColor(0x7fffffff);
@@ -85,7 +85,7 @@ public class PhotoCropActivity extends BaseFragment {
public boolean onTouch(View view, MotionEvent motionEvent) {
float x = motionEvent.getX();
float y = motionEvent.getY();
- int cornerSide = Utilities.dp(14);
+ int cornerSide = AndroidUtilities.dp(14);
if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
if (rectX - cornerSide < x && rectX + cornerSide > x && rectY - cornerSide < y && rectY + cornerSide > y) {
draggingState = 1;
@@ -270,7 +270,7 @@ public class PhotoCropActivity extends BaseFragment {
canvas.drawRect(rectX, rectY, rectX + rectSize, rectY + rectSize, rectPaint);
- int side = Utilities.dp(7);
+ int side = AndroidUtilities.dp(7);
canvas.drawRect(rectX - side, rectY - side, rectX + side, rectY + side, circlePaint);
canvas.drawRect(rectX + rectSize - side, rectY - side, rectX + rectSize + side, rectY + side, circlePaint);
canvas.drawRect(rectX - side, rectY + rectSize - side, rectX + side, rectY + rectSize + side, circlePaint);
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/PhotoPickerActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/PhotoPickerActivity.java
index 6e17f0ed..ab4777b0 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/PhotoPickerActivity.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/PhotoPickerActivity.java
@@ -23,13 +23,13 @@ import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;
-import org.telegram.messenger.LocaleController;
-import org.telegram.messenger.MediaController;
-import org.telegram.messenger.MessagesController;
+import org.telegram.android.AndroidUtilities;
+import org.telegram.android.LocaleController;
+import org.telegram.android.MediaController;
+import org.telegram.android.MessagesController;
import org.telegram.messenger.NotificationCenter;
import org.telegram.messenger.R;
import org.telegram.messenger.TLRPC;
-import org.telegram.messenger.Utilities;
import org.telegram.objects.MessageObject;
import org.telegram.ui.Adapters.BaseFragmentAdapter;
import org.telegram.ui.Views.ActionBar.ActionBarLayer;
@@ -252,7 +252,7 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
imageView.getLocationInWindow(coords);
PhotoViewer.PlaceProviderObject object = new PhotoViewer.PlaceProviderObject();
object.viewX = coords[0];
- object.viewY = coords[1] - Utilities.statusBarHeight;
+ object.viewY = coords[1] - AndroidUtilities.statusBarHeight;
object.parentView = listView;
object.imageReceiver = imageView.imageReceiver;
object.thumb = object.imageReceiver.getBitmap();
@@ -405,7 +405,7 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
}
}
listView.setNumColumns(columnsCount);
- itemWidth = (getParentActivity().getResources().getDisplayMetrics().widthPixels - ((columnsCount + 1) * Utilities.dp(4))) / columnsCount;
+ itemWidth = (getParentActivity().getResources().getDisplayMetrics().widthPixels - ((columnsCount + 1) * AndroidUtilities.dp(4))) / columnsCount;
listView.setColumnWidth(itemWidth);
listAdapter.notifyDataSetChanged();
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/PhotoViewer.java b/TMessagesProj/src/main/java/org/telegram/ui/PhotoViewer.java
index a4168a8c..668bd25d 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/PhotoViewer.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/PhotoViewer.java
@@ -45,12 +45,13 @@ import android.widget.ProgressBar;
import android.widget.Scroller;
import android.widget.TextView;
+import org.telegram.android.AndroidUtilities;
import org.telegram.messenger.ConnectionsManager;
import org.telegram.messenger.FileLoader;
import org.telegram.messenger.FileLog;
-import org.telegram.messenger.LocaleController;
-import org.telegram.messenger.MediaController;
-import org.telegram.messenger.MessagesController;
+import org.telegram.android.LocaleController;
+import org.telegram.android.MediaController;
+import org.telegram.android.MessagesController;
import org.telegram.messenger.NotificationCenter;
import org.telegram.messenger.R;
import org.telegram.messenger.TLRPC;
@@ -102,6 +103,8 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
private boolean overlayViewVisible = true;
private int animationInProgress = 0;
+ private long transitionAnimationStartTime = 0;
+ private Runnable animationEndRunnable = null;
private PlaceProviderObject showAfterAnimation;
private PlaceProviderObject hideAfterAnimation;
private boolean disableShowCheck = false;
@@ -175,7 +178,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
private final static int gallery_menu_showall = 2;
private final static int gallery_menu_send = 3;
- private final static int PAGE_SPACING = Utilities.dp(30);
+ private final static int PAGE_SPACING = AndroidUtilities.dp(30);
private static class OverlayView extends FrameLayout {
@@ -186,7 +189,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
actionButton = new TextView(context);
actionButton.setBackgroundResource(R.drawable.system_black);
- actionButton.setPadding(Utilities.dp(8), Utilities.dp(2), Utilities.dp(8), Utilities.dp(2));
+ actionButton.setPadding(AndroidUtilities.dp(8), AndroidUtilities.dp(2), AndroidUtilities.dp(8), AndroidUtilities.dp(2));
actionButton.setTextColor(0xffffffff);
actionButton.setTextSize(26);
actionButton.setGravity(Gravity.CENTER);
@@ -298,7 +301,17 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
if (currentFileName != null && currentFileName.equals(location)) {
Float progress = (Float)args[1];
progressBar.setVisibility(View.VISIBLE);
- progressBar.setProgress((int)(progress * 100));
+ if (android.os.Build.VERSION.SDK_INT >= 11) {
+ progressBar.setProgress((int) (progress * 100));
+ AnimatorSet animatorSet = new AnimatorSet();
+ animatorSet.playTogether(
+ ObjectAnimator.ofInt(progressBar, "progress", (int) (progress * 100))
+ );
+ animatorSet.setDuration(400);
+ animatorSet.start();
+ } else {
+ progressBar.setProgress((int) (progress * 100));
+ }
}
} else if (id == MessagesController.userPhotosLoaded) {
int guid = (Integer)args[4];
@@ -530,7 +543,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
@Override
public boolean canOpenMenu() {
if (currentFileName != null) {
- File f = new File(Utilities.getCacheDir(), currentFileName);
+ File f = new File(AndroidUtilities.getCacheDir(), currentFileName);
if (f.exists()) {
return true;
}
@@ -548,7 +561,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
containerView.addView(bottomLayout);
layoutParams = (FrameLayout.LayoutParams)bottomLayout.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
- layoutParams.height = Utilities.dp(48);
+ layoutParams.height = AndroidUtilities.dp(48);
layoutParams.gravity = Gravity.BOTTOM | Gravity.LEFT;
bottomLayout.setLayoutParams(layoutParams);
bottomLayout.setBackgroundColor(0x7F000000);
@@ -559,7 +572,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
shareButton.setBackgroundResource(R.drawable.bar_selector_white);
bottomLayout.addView(shareButton);
layoutParams = (FrameLayout.LayoutParams) shareButton.getLayoutParams();
- layoutParams.width = Utilities.dp(50);
+ layoutParams.width = AndroidUtilities.dp(50);
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
shareButton.setLayoutParams(layoutParams);
shareButton.setOnClickListener(new View.OnClickListener() {
@@ -573,7 +586,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
if (fileName == null) {
return;
}
- File f = new File(Utilities.getCacheDir(), fileName);
+ File f = new File(AndroidUtilities.getCacheDir(), fileName);
if (f.exists()) {
Intent intent = new Intent(Intent.ACTION_SEND);
if (fileName.endsWith("mp4")) {
@@ -596,7 +609,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
deleteButton.setBackgroundResource(R.drawable.bar_selector_white);
bottomLayout.addView(deleteButton);
layoutParams = (FrameLayout.LayoutParams) deleteButton.getLayoutParams();
- layoutParams.width = Utilities.dp(50);
+ layoutParams.width = AndroidUtilities.dp(50);
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.gravity = Gravity.RIGHT;
deleteButton.setLayoutParams(layoutParams);
@@ -628,9 +641,9 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams.gravity = Gravity.TOP;
- layoutParams.leftMargin = Utilities.dp(60);
- layoutParams.rightMargin = Utilities.dp(60);
- layoutParams.topMargin = Utilities.dp(2);
+ layoutParams.leftMargin = AndroidUtilities.dp(60);
+ layoutParams.rightMargin = AndroidUtilities.dp(60);
+ layoutParams.topMargin = AndroidUtilities.dp(2);
nameTextView.setLayoutParams(layoutParams);
dateTextView = new TextView(containerView.getContext());
@@ -645,9 +658,9 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams.gravity = Gravity.TOP;
- layoutParams.leftMargin = Utilities.dp(60);
- layoutParams.rightMargin = Utilities.dp(60);
- layoutParams.topMargin = Utilities.dp(26);
+ layoutParams.leftMargin = AndroidUtilities.dp(60);
+ layoutParams.rightMargin = AndroidUtilities.dp(60);
+ layoutParams.topMargin = AndroidUtilities.dp(26);
dateTextView.setLayoutParams(layoutParams);
pickerView = parentActivity.getLayoutInflater().inflate(R.layout.photo_picker_bottom_layout, null);
@@ -675,7 +688,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
layoutParams = (FrameLayout.LayoutParams)pickerView.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
- layoutParams.height = Utilities.dp(48);
+ layoutParams.height = AndroidUtilities.dp(48);
layoutParams.gravity = Gravity.BOTTOM;
pickerView.setLayoutParams(layoutParams);
@@ -691,11 +704,11 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
containerView.addView(progressBar);
layoutParams = (FrameLayout.LayoutParams)progressBar.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
- layoutParams.height = Utilities.dp(3);
+ layoutParams.height = AndroidUtilities.dp(3);
layoutParams.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL;
- layoutParams.leftMargin = Utilities.dp(6);
- layoutParams.rightMargin = Utilities.dp(6);
- layoutParams.bottomMargin = Utilities.dp(48);
+ layoutParams.leftMargin = AndroidUtilities.dp(6);
+ layoutParams.rightMargin = AndroidUtilities.dp(6);
+ layoutParams.bottomMargin = AndroidUtilities.dp(48);
progressBar.setLayoutParams(layoutParams);
gestureDetector = new GestureDetector(containerView.getContext(), this);
@@ -715,16 +728,16 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
checkImageView.setScaleType(ImageView.ScaleType.CENTER);
checkImageView.setImageResource(R.drawable.selectphoto_large);
layoutParams = (FrameLayout.LayoutParams)checkImageView.getLayoutParams();
- layoutParams.width = Utilities.dp(46);
- layoutParams.height = Utilities.dp(46);
+ layoutParams.width = AndroidUtilities.dp(46);
+ layoutParams.height = AndroidUtilities.dp(46);
layoutParams.gravity = Gravity.RIGHT;
- layoutParams.rightMargin = Utilities.dp(10);
+ layoutParams.rightMargin = AndroidUtilities.dp(10);
WindowManager manager = (WindowManager)ApplicationLoader.applicationContext.getSystemService(Activity.WINDOW_SERVICE);
int rotation = manager.getDefaultDisplay().getRotation();
if (rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90) {
- layoutParams.topMargin = Utilities.dp(48);
+ layoutParams.topMargin = AndroidUtilities.dp(48);
} else {
- layoutParams.topMargin = Utilities.dp(58);
+ layoutParams.topMargin = AndroidUtilities.dp(58);
}
checkImageView.setLayoutParams(layoutParams);
checkImageView.setOnClickListener(new View.OnClickListener() {
@@ -988,7 +1001,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
load = true;
}
} else {
- File cacheFile = new File(Utilities.getCacheDir(), currentFileName);
+ File cacheFile = new File(AndroidUtilities.getCacheDir(), currentFileName);
if (cacheFile.exists()) {
currentOverlay.actionButton.setText(LocaleController.getString("ViewVideo", R.string.ViewVideo));
} else {
@@ -996,10 +1009,13 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
}
}
if (load) {
- Float progress = FileLoader.getInstance().fileProgresses.get(currentFileName);
if (FileLoader.getInstance().isLoadingFile(currentFileName)) {
+ Float progress = FileLoader.getInstance().fileProgresses.get(currentFileName);
currentOverlay.actionButton.setText(LocaleController.getString("CancelDownload", R.string.CancelDownload));
progressBar.setVisibility(View.VISIBLE);
+ if (progress != null) {
+ progressBar.setProgress((int)(progress * 100));
+ }
} else {
currentOverlay.actionButton.setText(String.format("%s %s", LocaleController.getString("DOWNLOAD", R.string.DOWNLOAD), Utilities.formatFileSize(currentMessageObject.messageOwner.media.video.size)));
progressBar.setVisibility(View.GONE);
@@ -1226,7 +1242,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
}
if (currentFileName != null) {
- File f = new File(Utilities.getCacheDir(), currentFileName);
+ File f = new File(AndroidUtilities.getCacheDir(), currentFileName);
if (f.exists()) {
progressBar.setVisibility(View.GONE);
} else {
@@ -1260,7 +1276,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
if (currentThumb != null && imageReceiver == centerImage) {
placeHolder = currentThumb;
}
- int size = (int)(800 / Utilities.density);
+ int size = (int)(800 / AndroidUtilities.density);
imageReceiver.setImage(photoEntry.path, String.format(Locale.US, "%d_%d", size, size), placeHolder != null ? new BitmapDrawable(null, placeHolder) : null);
} else {
imageReceiver.setImageBitmap((Bitmap) null);
@@ -1335,8 +1351,21 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
openPhoto(null, null, null, photos, index, provider);
}
+ private boolean checkAnimation() {
+ if (animationInProgress != 0) {
+ if (Math.abs(transitionAnimationStartTime - System.currentTimeMillis()) >= 500) {
+ if (animationEndRunnable != null) {
+ animationEndRunnable.run();
+ animationEndRunnable = null;
+ }
+ animationInProgress = 0;
+ }
+ }
+ return animationInProgress != 0;
+ }
+
public void openPhoto(final MessageObject messageObject, final TLRPC.FileLocation fileLocation, final ArrayList messages, final ArrayList photos, final int index, final PhotoViewerProvider provider) {
- if (parentActivity == null || isVisible || provider == null || animationInProgress != 0 || messageObject == null && fileLocation == null && messages == null && photos == null) {
+ if (parentActivity == null || isVisible || provider == null || checkAnimation() || messageObject == null && fileLocation == null && messages == null && photos == null) {
return;
}
final PlaceProviderObject object = provider.getPlaceForPhoto(messageObject, fileLocation, index);
@@ -1369,7 +1398,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
overlayViewVisible = true;
if(android.os.Build.VERSION.SDK_INT >= 11) {
- Utilities.lockOrientation(parentActivity);
+ AndroidUtilities.lockOrientation(parentActivity);
animatingImageView.setVisibility(View.VISIBLE);
animatingImageView.setImageBitmap(object.thumb);
@@ -1391,23 +1420,23 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
public boolean onPreDraw() {
containerView.getViewTreeObserver().removeOnPreDrawListener(this);
- float scaleX = (float) Utilities.displaySize.x / layoutParams.width;
- float scaleY = (float) (Utilities.displaySize.y - Utilities.statusBarHeight) / layoutParams.height;
+ float scaleX = (float) AndroidUtilities.displaySize.x / layoutParams.width;
+ float scaleY = (float) (AndroidUtilities.displaySize.y - AndroidUtilities.statusBarHeight) / layoutParams.height;
float scale = scaleX > scaleY ? scaleY : scaleX;
float width = layoutParams.width * scale;
float height = layoutParams.height * scale;
- float xPos = (Utilities.displaySize.x - width) / 2.0f;
- float yPos = (Utilities.displaySize.y - Utilities.statusBarHeight - height) / 2.0f;
+ float xPos = (AndroidUtilities.displaySize.x - width) / 2.0f;
+ float yPos = (AndroidUtilities.displaySize.y - AndroidUtilities.statusBarHeight - height) / 2.0f;
int clipHorizontal = Math.abs(object.imageReceiver.drawRegion.left - object.imageReceiver.imageX);
int clipVertical = Math.abs(object.imageReceiver.drawRegion.top - object.imageReceiver.imageY);
int coords2[] = new int[2];
object.parentView.getLocationInWindow(coords2);
- int clipTop = coords2[1] - Utilities.statusBarHeight - (object.viewY + object.imageReceiver.drawRegion.top);
+ int clipTop = coords2[1] - AndroidUtilities.statusBarHeight - (object.viewY + object.imageReceiver.drawRegion.top);
if (clipTop < 0) {
clipTop = 0;
}
- int clipBottom = (object.viewY + object.imageReceiver.drawRegion.top + layoutParams.height) - (coords2[1] + object.parentView.getHeight() - Utilities.statusBarHeight);
+ int clipBottom = (object.viewY + object.imageReceiver.drawRegion.top + layoutParams.height) - (coords2[1] + object.parentView.getHeight() - AndroidUtilities.statusBarHeight);
if (clipBottom < 0) {
clipBottom = 0;
}
@@ -1428,14 +1457,14 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
ObjectAnimator.ofFloat(currentOverlay, "alpha", 1.0f)
);
- animatorSet.setDuration(250);
- animatorSet.addListener(new AnimatorListenerAdapter() {
+ animationEndRunnable = new Runnable() {
@Override
- public void onAnimationEnd(Animator animation) {
+ public void run() {
animationInProgress = 0;
+ transitionAnimationStartTime = 0;
containerView.invalidate();
animatingImageView.setVisibility(View.GONE);
- Utilities.unlockOrientation(parentActivity);
+ AndroidUtilities.unlockOrientation(parentActivity);
if (showAfterAnimation != null) {
showAfterAnimation.imageReceiver.setVisible(true, true);
}
@@ -1443,7 +1472,24 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
hideAfterAnimation.imageReceiver.setVisible(false, true);
}
}
+ };
+
+ animatorSet.setDuration(250);
+ animatorSet.addListener(new AnimatorListenerAdapter() {
+ @Override
+ public void onAnimationEnd(Animator animation) {
+ if (animationEndRunnable != null) {
+ animationEndRunnable.run();
+ animationEndRunnable = null;
+ }
+ }
+
+ @Override
+ public void onAnimationCancel(Animator animation) {
+ onAnimationEnd(animation);
+ }
});
+ transitionAnimationStartTime = System.currentTimeMillis();
animatorSet.start();
animatingImageView.setOnDrawListener(new ClippingImageView.onDrawListener() {
@@ -1461,6 +1507,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
});
} else {
animationInProgress = 0;
+ transitionAnimationStartTime = 0;
containerView.invalidate();
AnimationSet animationSet = new AnimationSet(true);
AlphaAnimation animation = new AlphaAnimation(0.0f, 1.0f);
@@ -1478,7 +1525,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
}
public void closePhoto(boolean animated) {
- if (parentActivity == null || !isVisible || animationInProgress != 0) {
+ if (parentActivity == null || !isVisible || checkAnimation()) {
return;
}
@@ -1502,7 +1549,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
final PlaceProviderObject object = placeProvider.getPlaceForPhoto(currentMessageObject, currentFileLocation, currentIndex);
if(android.os.Build.VERSION.SDK_INT >= 11 && animated) {
- Utilities.lockOrientation(parentActivity);
+ AndroidUtilities.lockOrientation(parentActivity);
animationInProgress = 1;
animatingImageView.setVisibility(View.VISIBLE);
@@ -1522,13 +1569,13 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
}
animatingImageView.setLayoutParams(layoutParams);
- float scaleX = (float) Utilities.displaySize.x / layoutParams.width;
- float scaleY = (float) (Utilities.displaySize.y - Utilities.statusBarHeight) / layoutParams.height;
+ float scaleX = (float) AndroidUtilities.displaySize.x / layoutParams.width;
+ float scaleY = (float) (AndroidUtilities.displaySize.y - AndroidUtilities.statusBarHeight) / layoutParams.height;
float scale2 = scaleX > scaleY ? scaleY : scaleX;
float width = layoutParams.width * scale * scale2;
float height = layoutParams.height * scale * scale2;
- float xPos = (Utilities.displaySize.x - width) / 2.0f;
- float yPos = (Utilities.displaySize.y - Utilities.statusBarHeight - height) / 2.0f;
+ float xPos = (AndroidUtilities.displaySize.x - width) / 2.0f;
+ float yPos = (AndroidUtilities.displaySize.y - AndroidUtilities.statusBarHeight - height) / 2.0f;
animatingImageView.setTranslationX(xPos + translationX);
animatingImageView.setTranslationY(yPos + translationY);
animatingImageView.setScaleX(scale * scale2);
@@ -1543,11 +1590,11 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
int coords2[] = new int[2];
object.parentView.getLocationInWindow(coords2);
- int clipTop = coords2[1] - Utilities.statusBarHeight - (object.viewY + object.imageReceiver.drawRegion.top);
+ int clipTop = coords2[1] - AndroidUtilities.statusBarHeight - (object.viewY + object.imageReceiver.drawRegion.top);
if (clipTop < 0) {
clipTop = 0;
}
- int clipBottom = (object.viewY + object.imageReceiver.drawRegion.top + (object.imageReceiver.drawRegion.bottom - object.imageReceiver.drawRegion.top)) - (coords2[1] + object.parentView.getHeight() - Utilities.statusBarHeight);
+ int clipBottom = (object.viewY + object.imageReceiver.drawRegion.top + (object.imageReceiver.drawRegion.bottom - object.imageReceiver.drawRegion.top)) - (coords2[1] + object.parentView.getHeight() - AndroidUtilities.statusBarHeight);
if (clipBottom < 0) {
clipBottom = 0;
}
@@ -1570,20 +1617,36 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
animatorSet.playTogether(
ObjectAnimator.ofInt(backgroundDrawable, "alpha", 0),
ObjectAnimator.ofFloat(animatingImageView, "alpha", 0.0f),
- ObjectAnimator.ofFloat(animatingImageView, "translationY", translationY >= 0 ? Utilities.displaySize.y : -Utilities.displaySize.y),
+ ObjectAnimator.ofFloat(animatingImageView, "translationY", translationY >= 0 ? AndroidUtilities.displaySize.y : -AndroidUtilities.displaySize.y),
ObjectAnimator.ofFloat(containerView, "alpha", 0.0f)
);
}
+ animationEndRunnable = new Runnable() {
+ @Override
+ public void run() {
+ AndroidUtilities.unlockOrientation(parentActivity);
+ animationInProgress = 0;
+ onPhotoClosed(object);
+ }
+ };
+
animatorSet.setDuration(250);
animatorSet.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
- Utilities.unlockOrientation(parentActivity);
- animationInProgress = 0;
- onPhotoClosed(object);
+ if (animationEndRunnable != null) {
+ animationEndRunnable.run();
+ animationEndRunnable = null;
+ }
+ }
+
+ @Override
+ public void onAnimationCancel(Animator animation) {
+ onAnimationEnd(animation);
}
});
+ transitionAnimationStartTime = System.currentTimeMillis();
animatorSet.start();
} else {
AnimationSet animationSet = new AnimationSet(true);
@@ -1597,6 +1660,16 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
animationSet.addAnimation(scaleAnimation);
animationSet.setDuration(150);
animationInProgress = 2;
+ animationEndRunnable = new Runnable() {
+ @Override
+ public void run() {
+ if (animationListener != null) {
+ animationInProgress = 0;
+ onPhotoClosed(object);
+ animationListener = null;
+ }
+ }
+ };
animationSet.setAnimationListener(animationListener = new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
@@ -1605,10 +1678,9 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
@Override
public void onAnimationEnd(Animation animation) {
- if (animationListener != null) {
- animationInProgress = 0;
- onPhotoClosed(object);
- animationListener = null;
+ if (animationEndRunnable != null) {
+ animationEndRunnable.run();
+ animationEndRunnable = null;
}
}
@@ -1617,6 +1689,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
}
});
+ transitionAnimationStartTime = System.currentTimeMillis();
containerView.startAnimation(animationSet);
}
}
@@ -1678,7 +1751,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
private boolean onTouchEvent(MotionEvent ev) {
if (animationInProgress != 0 || animationStartTime != 0) {
if (animationStartTime == 0) {
- Utilities.unlockOrientation(parentActivity);
+ AndroidUtilities.unlockOrientation(parentActivity);
}
return false;
}
@@ -1713,7 +1786,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
dragY = moveStartY = ev.getY();
draggingDown = false;
canDragDown = true;
- Utilities.lockOrientation(parentActivity);
+ AndroidUtilities.lockOrientation(parentActivity);
if (velocityTracker != null) {
velocityTracker.clear();
}
@@ -1732,7 +1805,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
}
float dx = Math.abs(ev.getX() - moveStartX);
float dy = Math.abs(ev.getY() - dragY);
- if (canDragDown && !draggingDown && scale == 1 && dy >= Utilities.dp(30) && dy / 2 > dx) {
+ if (canDragDown && !draggingDown && scale == 1 && dy >= AndroidUtilities.dp(30) && dy / 2 > dx) {
draggingDown = true;
moving = false;
dragY = ev.getY();
@@ -1747,7 +1820,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
} else if (!invalidCoords && animationStartTime == 0) {
float moveDx = moveStartX - ev.getX();
float moveDy = moveStartY - ev.getY();
- if (moving || scale == 1 && Math.abs(moveDy) + Utilities.dp(12) < Math.abs(moveDx) || scale != 1) {
+ if (moving || scale == 1 && Math.abs(moveDy) + AndroidUtilities.dp(12) < Math.abs(moveDx) || scale != 1) {
if (!moving) {
moveDx = 0;
moveDy = 0;
@@ -1834,11 +1907,11 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
velocity = velocityTracker.getXVelocity();
}
- if((translationX < minX - containerView.getWidth() / 3 || velocity < -Utilities.dp(650)) && rightImage.hasImage()){
+ if((translationX < minX - containerView.getWidth() / 3 || velocity < -AndroidUtilities.dp(650)) && rightImage.hasImage()){
goToNext();
return true;
}
- if((translationX > maxX + containerView.getWidth() / 3 || velocity > Utilities.dp(650)) && leftImage.hasImage()){
+ if((translationX > maxX + containerView.getWidth() / 3 || velocity > AndroidUtilities.dp(650)) && leftImage.hasImage()){
goToPrev();
return true;
}
@@ -1855,7 +1928,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
}
animateTo(scale, moveToX, moveToY);
} else {
- Utilities.unlockOrientation(parentActivity);
+ AndroidUtilities.unlockOrientation(parentActivity);
}
}
return false;
@@ -1905,7 +1978,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
toggleOverlayView(true);
}
if (scale == newScale && translationX == newTx && translationY == newTy) {
- Utilities.unlockOrientation(parentActivity);
+ AndroidUtilities.unlockOrientation(parentActivity);
return;
}
zoomAnimation = isZoom;
@@ -1915,7 +1988,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
animationStartTime = System.currentTimeMillis();
animationDuration = 250;
containerView.postInvalidate();
- Utilities.lockOrientation(parentActivity);
+ AndroidUtilities.lockOrientation(parentActivity);
}
private void onDraw(Canvas canvas) {
@@ -1962,7 +2035,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
scale = animateToScale;
animationStartTime = 0;
updateMinMax(scale);
- Utilities.unlockOrientation(parentActivity);
+ AndroidUtilities.unlockOrientation(parentActivity);
zoomAnimation = false;
}
if (!scroller.isFinished()) {
@@ -2023,10 +2096,10 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
if (scale >= 1.0f) {
ImageReceiver sideImage = null;
float k = 1;
- if (currentTranslationX > maxX + Utilities.dp(20)) {
+ if (currentTranslationX > maxX + AndroidUtilities.dp(20)) {
k = -1;
sideImage = leftImage;
- } else if (currentTranslationX < minX - Utilities.dp(20)) {
+ } else if (currentTranslationX < minX - AndroidUtilities.dp(20)) {
sideImage = rightImage;
}
@@ -2078,9 +2151,9 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
WindowManager manager = (WindowManager)ApplicationLoader.applicationContext.getSystemService(Activity.WINDOW_SERVICE);
int rotation = manager.getDefaultDisplay().getRotation();
if (rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90) {
- layoutParams.topMargin = Utilities.dp(48);
+ layoutParams.topMargin = AndroidUtilities.dp(48);
} else {
- layoutParams.topMargin = Utilities.dp(58);
+ layoutParams.topMargin = AndroidUtilities.dp(58);
}
checkImageView.setLayoutParams(layoutParams);
return false;
@@ -2105,7 +2178,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
loadFile = true;
}
} else {
- File cacheFile = new File(Utilities.getCacheDir(), currentFileName);
+ File cacheFile = new File(AndroidUtilities.getCacheDir(), currentFileName);
if (cacheFile.exists()) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(cacheFile), "video/mp4");
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/PopupNotificationActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/PopupNotificationActivity.java
new file mode 100644
index 00000000..941870de
--- /dev/null
+++ b/TMessagesProj/src/main/java/org/telegram/ui/PopupNotificationActivity.java
@@ -0,0 +1,418 @@
+/*
+ * This is the source code of Telegram for Android v. 1.4.x.
+ * It is licensed under GNU GPL v. 2 or later.
+ * You should have received a copy of the license in this archive (see LICENSE).
+ *
+ * Copyright Nikolai Kudashov, 2013-2014.
+ */
+
+package org.telegram.ui;
+
+import android.app.Activity;
+import android.app.KeyguardManager;
+import android.content.Context;
+import android.content.Intent;
+import android.graphics.drawable.AnimationDrawable;
+import android.os.Bundle;
+import android.os.PowerManager;
+import android.util.TypedValue;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.WindowManager;
+import android.widget.RelativeLayout;
+import android.widget.TextView;
+
+import org.telegram.android.AndroidUtilities;
+import org.telegram.android.ContactsController;
+import org.telegram.android.LocaleController;
+import org.telegram.android.MessagesController;
+import org.telegram.PhoneFormat.PhoneFormat;
+import org.telegram.messenger.ConnectionsManager;
+import org.telegram.messenger.FileLog;
+import org.telegram.messenger.NotificationCenter;
+import org.telegram.messenger.R;
+import org.telegram.messenger.TLRPC;
+import org.telegram.messenger.Utilities;
+import org.telegram.objects.MessageObject;
+import org.telegram.ui.Views.ActionBar.ActionBar;
+import org.telegram.ui.Views.ActionBar.ActionBarLayer;
+import org.telegram.ui.Views.ActionBar.ActionBarMenu;
+import org.telegram.ui.Views.BackupImageView;
+import org.telegram.ui.Views.ChatActivityEnterView;
+
+public class PopupNotificationActivity extends Activity implements NotificationCenter.NotificationCenterDelegate {
+
+ private ActionBarLayer actionBarLayer;
+ private ChatActivityEnterView chatActivityEnterView;
+ private BackupImageView avatarImageView;
+ private TextView messageText;
+ private TextView countText;
+ private View textScroll;
+
+ private int classGuid;
+ private TLRPC.User currentUser;
+ private TLRPC.Chat currentChat;
+ private boolean finished = false;
+ private CharSequence lastPrintString;
+ private MessageObject currentMessageObject = null;
+ private int currentMessageNum = 0;
+ private PowerManager.WakeLock wakeLock = null;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ classGuid = ConnectionsManager.getInstance().generateClassGuid();
+ NotificationCenter.getInstance().addObserver(this, 1234);
+ NotificationCenter.getInstance().addObserver(this, MessagesController.pushMessagesUpdated);
+ NotificationCenter.getInstance().addObserver(this, MessagesController.updateInterfaces);
+
+ chatActivityEnterView = new ChatActivityEnterView();
+ chatActivityEnterView.setDelegate(new ChatActivityEnterView.ChatActivityEnterViewDelegate() {
+ @Override
+ public void onMessageSend() {
+ MessagesController.getInstance().pushMessages.remove(0);
+ currentMessageObject = null;
+ getNewMessage();
+ //MessagesController.getInstance().markDialogAsRead(dialog_id, messages.get(0).messageOwner.id, minMessageId, 0, maxDate, wasUnread);
+ }
+
+ @Override
+ public void needSendTyping() {
+ if (currentMessageObject != null) {
+ MessagesController.getInstance().sendTyping(currentMessageObject.getDialogId(), classGuid);
+ }
+ }
+ });
+
+ setContentView(R.layout.popup_notification_layout);
+ RelativeLayout popupContainer = (RelativeLayout) findViewById(R.id.popup_container);
+ messageText = (TextView)findViewById(R.id.message_text);
+ View messageContainer = findViewById(R.id.text_container);
+ messageContainer.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ openCurrentMessage();
+ }
+ });
+
+ ActionBar actionBar = new ActionBar(this);
+ popupContainer.addView(actionBar);
+ ViewGroup.LayoutParams layoutParams = actionBar.getLayoutParams();
+ layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
+ actionBar.setLayoutParams(layoutParams);
+
+ actionBarLayer = actionBar.createLayer();
+ actionBarLayer.setDisplayHomeAsUpEnabled(true, R.drawable.ic_ab_back);
+ actionBarLayer.setBackgroundResource(R.color.header);
+ actionBarLayer.setItemsBackground(R.drawable.bar_selector);
+ actionBar.setCurrentActionBarLayer(actionBarLayer);
+
+ ActionBarMenu menu = actionBarLayer.createMenu();
+ View view = menu.addItemResource(2, R.layout.popup_count_layout);
+ countText = (TextView) view.findViewById(R.id.count_text);
+
+ view = menu.addItemResource(1, R.layout.chat_header_layout);
+ avatarImageView = (BackupImageView)view.findViewById(R.id.chat_avatar_image);
+ avatarImageView.processDetach = false;
+
+ actionBarLayer.setActionBarMenuOnItemClick(new ActionBarLayer.ActionBarMenuOnItemClick() {
+ @Override
+ public void onItemClick(int id) {
+ if (id == -1) {
+ finish();
+ } else if (id == 1) {
+ openCurrentMessage();
+ } else if (id == 2) {
+ if (MessagesController.getInstance().pushMessages.size() > 1) {
+ if (currentMessageNum < MessagesController.getInstance().pushMessages.size() - 1) {
+ currentMessageNum++;
+ } else {
+ currentMessageNum = 0;
+ }
+ currentMessageObject = MessagesController.getInstance().pushMessages.get(currentMessageNum);
+ updateInterfaceForCurrentMessage();
+ countText.setText(String.format("%d/%d", currentMessageNum + 1, MessagesController.getInstance().pushMessages.size()));
+ }
+ }
+ }
+ });
+
+ chatActivityEnterView.setContainerView(this, findViewById(R.id.chat_layout));
+
+ PowerManager pm = (PowerManager)ApplicationLoader.applicationContext.getSystemService(Context.POWER_SERVICE);
+ wakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "screen");
+
+ handleIntent(getIntent());
+ }
+
+ @Override
+ protected void onNewIntent(Intent intent) {
+ super.onNewIntent(intent);
+ handleIntent(intent);
+ }
+
+ public void handleIntent(Intent intent) {
+ KeyguardManager km = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
+ if (km.inKeyguardRestrictedInputMode() || !ApplicationLoader.isScreenOn) {
+ getWindow().addFlags(
+ WindowManager.LayoutParams.FLAG_DIM_BEHIND |
+ WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
+ WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON |
+ WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
+ } else {
+ getWindow().addFlags(
+ WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
+ WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON |
+ WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
+ getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
+ }
+
+ if (currentMessageObject == null) {
+ currentMessageNum = 0;
+ getNewMessage();
+ }
+ wakeLock.acquire(7000);
+ }
+
+ private void getNewMessage() {
+ if (MessagesController.getInstance().pushMessages.isEmpty()) {
+ finish();
+ return;
+ }
+
+ boolean found = false;
+ if ((currentMessageNum != 0 || chatActivityEnterView.hasText()) && currentMessageObject != null) {
+ for (int a = 0; a < MessagesController.getInstance().pushMessages.size(); a++) {
+ if (MessagesController.getInstance().pushMessages.get(a).messageOwner.id == currentMessageObject.messageOwner.id) {
+ currentMessageNum = a;
+ found = true;
+ break;
+ }
+ }
+ }
+ if (!found) {
+ currentMessageObject = MessagesController.getInstance().pushMessages.get(0);
+ updateInterfaceForCurrentMessage();
+ }
+ countText.setText(String.format("%d/%d", currentMessageNum + 1, MessagesController.getInstance().pushMessages.size()));
+ }
+
+ private void openCurrentMessage() {
+ if (currentMessageObject == null) {
+ return;
+ }
+ Intent intent = new Intent(ApplicationLoader.applicationContext, LaunchActivity.class);
+ long dialog_id = currentMessageObject.getDialogId();
+ if ((int)dialog_id != 0) {
+ int lower_id = (int)dialog_id;
+ if (lower_id < 0) {
+ intent.putExtra("chatId", -lower_id);
+ } else {
+ intent.putExtra("userId", lower_id);
+ }
+ } else {
+ intent.putExtra("encId", (int)(dialog_id >> 32));
+ }
+ intent.setAction("com.tmessages.openchat" + Math.random() + Integer.MAX_VALUE);
+ intent.setFlags(0x00008000);
+ startActivity(intent);
+ }
+
+ private void updateInterfaceForCurrentMessage() {
+ if (actionBarLayer == null) {
+ return;
+ }
+ currentChat = null;
+ currentUser = null;
+ long dialog_id = currentMessageObject.getDialogId();
+ chatActivityEnterView.setDialogId(dialog_id);
+ if ((int)dialog_id != 0) {
+ int lower_id = (int)dialog_id;
+ if (lower_id > 0) {
+ currentUser = MessagesController.getInstance().users.get(lower_id);
+ } else {
+ currentChat = MessagesController.getInstance().chats.get(-lower_id);
+ currentUser = MessagesController.getInstance().users.get(currentMessageObject.messageOwner.from_id);
+ }
+ } else {
+ TLRPC.EncryptedChat encryptedChat = MessagesController.getInstance().encryptedChats.get((int)(dialog_id >> 32));
+ currentUser = MessagesController.getInstance().users.get(encryptedChat.user_id);
+ }
+
+ if (currentChat != null && currentUser != null) {
+ actionBarLayer.setTitle(currentChat.title);
+ actionBarLayer.setSubtitle(Utilities.formatName(currentUser.first_name, currentUser.last_name));
+ } else if (currentUser != null) {
+ actionBarLayer.setTitle(Utilities.formatName(currentUser.first_name, currentUser.last_name));
+ if ((int)dialog_id == 0) {
+ actionBarLayer.setTitleIcon(R.drawable.ic_lock_white, AndroidUtilities.dp(4));
+ } else {
+ actionBarLayer.setTitleIcon(0, 0);
+ }
+ }
+ messageText.setTextSize(TypedValue.COMPLEX_UNIT_SP, MessagesController.getInstance().fontSize);
+ messageText.setText(currentMessageObject.messageText);
+ updateSubtitle();
+ checkAndUpdateAvatar();
+ }
+
+ private void updateSubtitle() {
+ if (actionBarLayer == null) {
+ return;
+ }
+ if (currentChat != null || currentUser == null) {
+ return;
+ }
+ if (currentUser.id / 1000 != 777 && currentUser.id / 1000 != 333 && ContactsController.getInstance().contactsDict.get(currentUser.id) == null && (ContactsController.getInstance().contactsDict.size() != 0 || !ContactsController.getInstance().isLoadingContacts())) {
+ if (currentUser.phone != null && currentUser.phone.length() != 0) {
+ actionBarLayer.setTitle(PhoneFormat.getInstance().format("+" + currentUser.phone));
+ } else {
+ actionBarLayer.setTitle(Utilities.formatName(currentUser.first_name, currentUser.last_name));
+ }
+ } else {
+ actionBarLayer.setTitle(Utilities.formatName(currentUser.first_name, currentUser.last_name));
+ }
+ CharSequence printString = MessagesController.getInstance().printingStrings.get(currentMessageObject.getDialogId());
+ if (printString == null || printString.length() == 0) {
+ lastPrintString = null;
+ setTypingAnimation(false);
+ TLRPC.User user = MessagesController.getInstance().users.get(currentUser.id);
+ if (user != null) {
+ currentUser = user;
+ }
+ actionBarLayer.setSubtitle(LocaleController.formatUserStatus(currentUser));
+ } else {
+ lastPrintString = printString;
+ actionBarLayer.setSubtitle(printString);
+ setTypingAnimation(true);
+ }
+ }
+
+ private void checkAndUpdateAvatar() {
+ TLRPC.FileLocation newPhoto = null;
+ int placeHolderId = 0;
+ if (currentChat != null) {
+ TLRPC.Chat chat = MessagesController.getInstance().chats.get(currentChat.id);
+ if (chat == null) {
+ return;
+ }
+ currentChat = chat;
+ if (currentChat.photo != null) {
+ newPhoto = currentChat.photo.photo_small;
+ }
+ placeHolderId = Utilities.getGroupAvatarForId(currentChat.id);
+ } else if (currentUser != null) {
+ TLRPC.User user = MessagesController.getInstance().users.get(currentUser.id);
+ if (user == null) {
+ return;
+ }
+ currentUser = user;
+ if (currentUser.photo != null) {
+ newPhoto = currentUser.photo.photo_small;
+ }
+ placeHolderId = Utilities.getUserAvatarForId(currentUser.id);
+ }
+ if (avatarImageView != null) {
+ avatarImageView.setImage(newPhoto, "50_50", placeHolderId);
+ }
+ }
+
+ private void setTypingAnimation(boolean start) {
+ if (actionBarLayer == null) {
+ return;
+ }
+ if (start) {
+ try {
+ actionBarLayer.setSubTitleIcon(R.drawable.typing_dots, AndroidUtilities.dp(4));
+ AnimationDrawable mAnim = (AnimationDrawable)actionBarLayer.getSubTitleIcon();
+ mAnim.setAlpha(200);
+ mAnim.start();
+ } catch (Exception e) {
+ FileLog.e("tmessages", e);
+ }
+ } else {
+ actionBarLayer.setSubTitleIcon(0, 0);
+ }
+ }
+
+ @Override
+ public void onBackPressed() {
+ if (chatActivityEnterView.isEmojiPopupShowing()) {
+ chatActivityEnterView.hideEmojiPopup();
+ return;
+ }
+ super.onBackPressed();
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ if (chatActivityEnterView != null) {
+ chatActivityEnterView.setFieldFocused(true);
+ }
+ ConnectionsManager.getInstance().setAppPaused(false, false);
+ }
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+ overridePendingTransition(0, 0);
+ if (chatActivityEnterView != null) {
+ chatActivityEnterView.hideEmojiPopup();
+ chatActivityEnterView.setFieldFocused(false);
+ }
+ ConnectionsManager.getInstance().setAppPaused(true, false);
+ }
+
+ @Override
+ public void didReceivedNotification(int id, Object... args) {
+ if (id == 1234) {
+ onFinish();
+ finish();
+ } else if (id == MessagesController.pushMessagesUpdated) {
+ getNewMessage();
+ } else if (id == MessagesController.updateInterfaces) {
+ if (currentMessageObject == null) {
+ return;
+ }
+ int updateMask = (Integer)args[0];
+ if ((updateMask & MessagesController.UPDATE_MASK_NAME) != 0 || (updateMask & MessagesController.UPDATE_MASK_STATUS) != 0 || (updateMask & MessagesController.UPDATE_MASK_CHAT_NAME) != 0 || (updateMask & MessagesController.UPDATE_MASK_CHAT_MEMBERS) != 0) {
+ updateSubtitle();
+ }
+ if ((updateMask & MessagesController.UPDATE_MASK_AVATAR) != 0 || (updateMask & MessagesController.UPDATE_MASK_CHAT_AVATAR) != 0) {
+ checkAndUpdateAvatar();
+ }
+ if ((updateMask & MessagesController.UPDATE_MASK_USER_PRINT) != 0) {
+ CharSequence printString = MessagesController.getInstance().printingStrings.get(currentMessageObject.getDialogId());
+ if (lastPrintString != null && printString == null || lastPrintString == null && printString != null || lastPrintString != null && printString != null && !lastPrintString.equals(printString)) {
+ updateSubtitle();
+ }
+ }
+ }
+ }
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ onFinish();
+ if (wakeLock.isHeld()) {
+ wakeLock.release();
+ }
+ }
+
+ protected void onFinish() {
+ if (finished) {
+ return;
+ }
+ finished = true;
+ NotificationCenter.getInstance().removeObserver(this, 1234);
+ NotificationCenter.getInstance().removeObserver(this, MessagesController.pushMessagesUpdated);
+ NotificationCenter.getInstance().removeObserver(this, MessagesController.updateInterfaces);
+ if (chatActivityEnterView != null) {
+ chatActivityEnterView.onDestroy();
+ }
+ if (wakeLock.isHeld()) {
+ wakeLock.release();
+ }
+ }
+}
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ProfileNotificationsActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ProfileNotificationsActivity.java
index 7acc1fbb..506a8770 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/ProfileNotificationsActivity.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/ProfileNotificationsActivity.java
@@ -26,15 +26,21 @@ import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;
+import org.telegram.android.MessagesController;
+import org.telegram.messenger.ConnectionsManager;
import org.telegram.messenger.FileLog;
-import org.telegram.messenger.LocaleController;
+import org.telegram.android.LocaleController;
+import org.telegram.messenger.NotificationCenter;
import org.telegram.messenger.R;
+import org.telegram.messenger.RPCRequest;
+import org.telegram.messenger.TLObject;
+import org.telegram.messenger.TLRPC;
import org.telegram.ui.Adapters.BaseFragmentAdapter;
import org.telegram.ui.Views.ActionBar.ActionBarLayer;
import org.telegram.ui.Views.ActionBar.BaseFragment;
import org.telegram.ui.Views.ColorPickerView;
-public class ProfileNotificationsActivity extends BaseFragment {
+public class ProfileNotificationsActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate {
private ListView listView;
private long dialog_id;
@@ -50,20 +56,22 @@ public class ProfileNotificationsActivity extends BaseFragment {
dialog_id = args.getLong("dialog_id");
}
- @Override
- public void onFragmentDestroy() {
- super.onFragmentDestroy();
- }
-
@Override
public boolean onFragmentCreate() {
settingsNotificationsRow = rowCount++;
settingsVibrateRow = rowCount++;
settingsLedRow = rowCount++;
settingsSoundRow = rowCount++;
+ NotificationCenter.getInstance().addObserver(this, MessagesController.notificationsSettingsUpdated);
return super.onFragmentCreate();
}
+ @Override
+ public void onFragmentDestroy() {
+ super.onFragmentDestroy();
+ NotificationCenter.getInstance().removeObserver(this, MessagesController.notificationsSettingsUpdated);
+ }
+
@Override
public View createView(LayoutInflater inflater, ViewGroup container) {
if (fragmentView == null) {
@@ -112,6 +120,9 @@ public class ProfileNotificationsActivity extends BaseFragment {
if (listView != null) {
listView.invalidateViews();
}
+ if (i == settingsNotificationsRow) {
+ updateServerNotificationsSettings();
+ }
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
@@ -211,6 +222,45 @@ public class ProfileNotificationsActivity extends BaseFragment {
return fragmentView;
}
+ public void updateServerNotificationsSettings() {
+ if ((int)dialog_id == 0) {
+ return;
+ }
+ SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
+ TLRPC.TL_account_updateNotifySettings req = new TLRPC.TL_account_updateNotifySettings();
+ req.settings = new TLRPC.TL_inputPeerNotifySettings();
+ req.settings.sound = "default";
+ req.settings.events_mask = 0;
+ req.settings.mute_until = preferences.getInt("notify2_" + dialog_id, 0) != 2 ? 0 : Integer.MAX_VALUE;
+ req.settings.show_previews = preferences.getBoolean("preview_" + dialog_id, true);
+
+ req.peer = new TLRPC.TL_inputNotifyPeer();
+
+ if ((int)dialog_id < 0) {
+ ((TLRPC.TL_inputNotifyPeer)req.peer).peer = new TLRPC.TL_inputPeerChat();
+ ((TLRPC.TL_inputNotifyPeer)req.peer).peer.chat_id = -(int)dialog_id;
+ } else {
+ TLRPC.User user = MessagesController.getInstance().users.get((int)dialog_id);
+ if (user == null) {
+ return;
+ }
+ if (user instanceof TLRPC.TL_userForeign || user instanceof TLRPC.TL_userRequest) {
+ ((TLRPC.TL_inputNotifyPeer)req.peer).peer = new TLRPC.TL_inputPeerForeign();
+ ((TLRPC.TL_inputNotifyPeer)req.peer).peer.access_hash = user.access_hash;
+ } else {
+ ((TLRPC.TL_inputNotifyPeer)req.peer).peer = new TLRPC.TL_inputPeerContact();
+ }
+ ((TLRPC.TL_inputNotifyPeer)req.peer).peer.user_id = (int)dialog_id;
+ }
+
+ ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() {
+ @Override
+ public void run(TLObject response, TLRPC.TL_error error) {
+
+ }
+ });
+ }
+
@Override
public void onActivityResultFragment(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK) {
@@ -248,6 +298,13 @@ public class ProfileNotificationsActivity extends BaseFragment {
}
}
+ @Override
+ public void didReceivedNotification(int id, Object... args) {
+ if (id == MessagesController.notificationsSettingsUpdated) {
+ listView.invalidateViews();
+ }
+ }
+
private class ListAdapter extends BaseFragmentAdapter {
private Context mContext;
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/SettingsActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/SettingsActivity.java
index 6a86bf07..082a3d66 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/SettingsActivity.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/SettingsActivity.java
@@ -34,17 +34,19 @@ import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
+import org.telegram.android.AndroidUtilities;
+import org.telegram.android.ContactsController;
import org.telegram.PhoneFormat.PhoneFormat;
import org.telegram.messenger.BuildVars;
-import org.telegram.messenger.LocaleController;
+import org.telegram.android.LocaleController;
import org.telegram.messenger.SerializedData;
import org.telegram.messenger.TLClassStore;
import org.telegram.messenger.TLObject;
import org.telegram.messenger.TLRPC;
import org.telegram.messenger.ConnectionsManager;
import org.telegram.messenger.FileLog;
-import org.telegram.messenger.MessagesController;
-import org.telegram.messenger.MessagesStorage;
+import org.telegram.android.MessagesController;
+import org.telegram.android.MessagesStorage;
import org.telegram.messenger.NotificationCenter;
import org.telegram.messenger.R;
import org.telegram.messenger.RPCRequest;
@@ -167,7 +169,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
});
}
}
- }, null, true, RPCRequest.RPCRequestClassGeneric);
+ });
}
};
NotificationCenter.getInstance().addObserver(this, MessagesController.updateInterfaces);
@@ -301,7 +303,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
final TextView message = new TextView(getParentActivity());
message.setText(Html.fromHtml(LocaleController.getString("AskAQuestionInfo", R.string.AskAQuestionInfo)));
message.setTextSize(18);
- message.setPadding(Utilities.dp(8), Utilities.dp(5), Utilities.dp(8), Utilities.dp(6));
+ message.setPadding(AndroidUtilities.dp(8), AndroidUtilities.dp(5), AndroidUtilities.dp(8), AndroidUtilities.dp(6));
message.setMovementMethod(new LinkMovementMethodMy());
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
@@ -362,7 +364,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
MessagesController.getInstance().registerForPush(UserConfig.pushString);
ConnectionsManager.getInstance().initPushConnection();
}
- }, null, true, RPCRequest.RPCRequestClassGeneric);
+ });
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
@@ -479,7 +481,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
avatarImage.getLocationInWindow(coords);
PhotoViewer.PlaceProviderObject object = new PhotoViewer.PlaceProviderObject();
object.viewX = coords[0];
- object.viewY = coords[1] - Utilities.statusBarHeight;
+ object.viewY = coords[1] - AndroidUtilities.statusBarHeight;
object.parentView = listView;
object.imageReceiver = avatarImage.imageReceiver;
object.user_id = UserConfig.getClientUserId();
@@ -528,7 +530,9 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
if (datacentersBytes != null) {
SerializedData data = new SerializedData(datacentersBytes);
supportUser = (TLRPC.User)TLClassStore.Instance().TLdeserialize(data, data.readInt32());
-
+ if (supportUser != null && supportUser.id == 333000) {
+ supportUser = null;
+ }
}
} catch (Exception e) {
FileLog.e("tmessages", e);
@@ -583,7 +587,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
});
}
}
- }, null, true, RPCRequest.RPCRequestClassGeneric);
+ });
} else {
MessagesController.getInstance().users.putIfAbsent(supportUser.id, supportUser);
Bundle args = new Bundle();
@@ -794,7 +798,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
});
}
}
- }, null, true, RPCRequest.RPCRequestClassGeneric);
+ });
}
}
});
@@ -806,7 +810,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
textView.setText(LocaleController.getString("Online", R.string.Online));
textView = (TextView)view.findViewById(R.id.settings_name);
- Typeface typeface = Utilities.getTypeface("fonts/rmedium.ttf");
+ Typeface typeface = AndroidUtilities.getTypeface("fonts/rmedium.ttf");
textView.setTypeface(typeface);
TLRPC.User user = MessagesController.getInstance().users.get(UserConfig.getClientUserId());
if (user == null) {
@@ -950,12 +954,16 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
+ SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
+ SharedPreferences.Editor editor = preferences.edit();
+ editor.clear().commit();
NotificationCenter.getInstance().postNotificationName(1234);
MessagesController.getInstance().unregistedPush();
MessagesController.getInstance().logOut();
UserConfig.clearConfig();
MessagesStorage.getInstance().cleanUp();
MessagesController.getInstance().cleanUp();
+ ContactsController.getInstance().deleteAllAppAccounts();
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/SettingsBlockedUsers.java b/TMessagesProj/src/main/java/org/telegram/ui/SettingsBlockedUsers.java
index 0029f53c..5d590cac 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/SettingsBlockedUsers.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/SettingsBlockedUsers.java
@@ -20,11 +20,11 @@ import android.widget.ListView;
import android.widget.TextView;
import org.telegram.PhoneFormat.PhoneFormat;
-import org.telegram.messenger.LocaleController;
+import org.telegram.android.LocaleController;
import org.telegram.messenger.TLObject;
import org.telegram.messenger.TLRPC;
import org.telegram.messenger.ConnectionsManager;
-import org.telegram.messenger.MessagesController;
+import org.telegram.android.MessagesController;
import org.telegram.messenger.NotificationCenter;
import org.telegram.messenger.R;
import org.telegram.messenger.RPCRequest;
@@ -148,7 +148,7 @@ public class SettingsBlockedUsers extends BaseFragment implements NotificationCe
public void run(TLObject response, TLRPC.TL_error error) {
}
- }, null, true, RPCRequest.RPCRequestClassGeneric);
+ });
}
}
});
@@ -220,7 +220,7 @@ public class SettingsBlockedUsers extends BaseFragment implements NotificationCe
}
});
}
- }, null, true, RPCRequest.RPCRequestClassGeneric);
+ });
ConnectionsManager.getInstance().bindRequestToGuid(requestId, classGuid);
}
@@ -273,7 +273,7 @@ public class SettingsBlockedUsers extends BaseFragment implements NotificationCe
public void run(TLObject response, TLRPC.TL_error error) {
}
- }, null, true, RPCRequest.RPCRequestClassGeneric);
+ });
}
private class ListAdapter extends BaseFragmentAdapter {
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/SettingsChangeNameActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/SettingsChangeNameActivity.java
index 15b8578d..9b1b355f 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/SettingsChangeNameActivity.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/SettingsChangeNameActivity.java
@@ -19,16 +19,16 @@ import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
-import org.telegram.messenger.LocaleController;
+import org.telegram.android.AndroidUtilities;
+import org.telegram.android.LocaleController;
import org.telegram.messenger.TLObject;
import org.telegram.messenger.TLRPC;
import org.telegram.messenger.ConnectionsManager;
-import org.telegram.messenger.MessagesController;
+import org.telegram.android.MessagesController;
import org.telegram.messenger.NotificationCenter;
import org.telegram.messenger.R;
import org.telegram.messenger.RPCRequest;
import org.telegram.messenger.UserConfig;
-import org.telegram.messenger.Utilities;
import org.telegram.ui.Views.ActionBar.BaseFragment;
public class SettingsChangeNameActivity extends BaseFragment {
@@ -120,7 +120,7 @@ public class SettingsChangeNameActivity extends BaseFragment {
boolean animations = preferences.getBoolean("view_animations", true);
if (!animations) {
firstNameField.requestFocus();
- Utilities.showKeyboard(firstNameField);
+ AndroidUtilities.showKeyboard(firstNameField);
}
}
@@ -143,12 +143,12 @@ public class SettingsChangeNameActivity extends BaseFragment {
public void run(TLObject response, TLRPC.TL_error error) {
}
- }, null, true, RPCRequest.RPCRequestClassGeneric);
+ });
}
@Override
public void onOpenAnimationEnd() {
firstNameField.requestFocus();
- Utilities.showKeyboard(firstNameField);
+ AndroidUtilities.showKeyboard(firstNameField);
}
}
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/SettingsNotificationsActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/SettingsNotificationsActivity.java
index c313a3d0..4e504247 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/SettingsNotificationsActivity.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/SettingsNotificationsActivity.java
@@ -27,12 +27,13 @@ import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
-import org.telegram.messenger.LocaleController;
+import org.telegram.android.LocaleController;
+import org.telegram.messenger.NotificationCenter;
import org.telegram.messenger.TLObject;
import org.telegram.messenger.TLRPC;
import org.telegram.messenger.ConnectionsManager;
import org.telegram.messenger.FileLog;
-import org.telegram.messenger.MessagesController;
+import org.telegram.android.MessagesController;
import org.telegram.messenger.R;
import org.telegram.messenger.RPCRequest;
import org.telegram.messenger.Utilities;
@@ -41,7 +42,7 @@ import org.telegram.ui.Views.ActionBar.ActionBarLayer;
import org.telegram.ui.Views.ActionBar.BaseFragment;
import org.telegram.ui.Views.ColorPickerView;
-public class SettingsNotificationsActivity extends BaseFragment {
+public class SettingsNotificationsActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate {
private ListView listView;
private boolean reseting = false;
@@ -52,12 +53,14 @@ public class SettingsNotificationsActivity extends BaseFragment {
private int messageVibrateRow;
private int messageSoundRow;
private int messageLedRow;
+ private int messagePopupNotificationRow;
private int groupSectionRow;
private int groupAlertRow;
private int groupPreviewRow;
private int groupVibrateRow;
private int groupSoundRow;
private int groupLedRow;
+ private int groupPopupNotificationRow;
private int inappSectionRow;
private int inappSoundRow;
private int inappVibrateRow;
@@ -78,12 +81,14 @@ public class SettingsNotificationsActivity extends BaseFragment {
messagePreviewRow = rowCount++;
messageVibrateRow = rowCount++;
messageLedRow = rowCount++;
+ messagePopupNotificationRow = rowCount++;
messageSoundRow = rowCount++;
groupSectionRow = rowCount++;
groupAlertRow = rowCount++;
groupPreviewRow = rowCount++;
groupVibrateRow = rowCount++;
groupLedRow = rowCount++;
+ groupPopupNotificationRow = rowCount++;
groupSoundRow = rowCount++;
inappSectionRow = rowCount++;
inappSoundRow = rowCount++;
@@ -96,9 +101,17 @@ public class SettingsNotificationsActivity extends BaseFragment {
resetSectionRow = rowCount++;
resetNotificationsRow = rowCount++;
+ NotificationCenter.getInstance().addObserver(this, MessagesController.notificationsSettingsUpdated);
+
return super.onFragmentCreate();
}
+ @Override
+ public void onFragmentDestroy() {
+ super.onFragmentDestroy();
+ NotificationCenter.getInstance().removeObserver(this, MessagesController.notificationsSettingsUpdated);
+ }
+
@Override
public View createView(LayoutInflater inflater, ViewGroup container) {
if (fragmentView == null) {
@@ -134,10 +147,10 @@ public class SettingsNotificationsActivity extends BaseFragment {
}
editor.commit();
listView.invalidateViews();
+ updateServerNotificationsSettings(i == groupAlertRow);
} else if (i == messagePreviewRow || i == groupPreviewRow) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
- boolean enabledAll = true;
boolean enabled;
if (i == messagePreviewRow) {
enabled = preferences.getBoolean("EnablePreviewAll", true);
@@ -148,6 +161,7 @@ public class SettingsNotificationsActivity extends BaseFragment {
}
editor.commit();
listView.invalidateViews();
+ updateServerNotificationsSettings(i == groupPreviewRow);
} else if (i == messageVibrateRow || i == groupVibrateRow) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
@@ -228,7 +242,7 @@ public class SettingsNotificationsActivity extends BaseFragment {
}
});
}
- }, null, true, RPCRequest.RPCRequestClassGeneric);
+ });
} else if (i == inappSoundRow) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
@@ -342,6 +356,32 @@ public class SettingsNotificationsActivity extends BaseFragment {
}
});
showAlertDialog(builder);
+ } else if (i == messagePopupNotificationRow || i == groupPopupNotificationRow) {
+ AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
+ builder.setTitle(LocaleController.getString("PopupNotification", R.string.PopupNotification));
+ builder.setItems(new CharSequence[] {
+ LocaleController.getString("NoPopup", R.string.NoPopup),
+ LocaleController.getString("OnlyWhenScreenOn", R.string.OnlyWhenScreenOn),
+ LocaleController.getString("OnlyWhenScreenOff", R.string.OnlyWhenScreenOff),
+ LocaleController.getString("AlwaysShowPopup", R.string.AlwaysShowPopup)
+ }, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
+ SharedPreferences.Editor editor = preferences.edit();
+ if (i == messagePopupNotificationRow) {
+ editor.putInt("popupAll", which);
+ } else if (i == groupPopupNotificationRow) {
+ editor.putInt("popupGroup", which);
+ }
+ editor.commit();
+ if (listView != null) {
+ listView.invalidateViews();
+ }
+ }
+ });
+ builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
+ showAlertDialog(builder);
}
}
});
@@ -354,6 +394,29 @@ public class SettingsNotificationsActivity extends BaseFragment {
return fragmentView;
}
+ public void updateServerNotificationsSettings(boolean group) {
+ SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
+ TLRPC.TL_account_updateNotifySettings req = new TLRPC.TL_account_updateNotifySettings();
+ req.settings = new TLRPC.TL_inputPeerNotifySettings();
+ req.settings.sound = "default";
+ req.settings.events_mask = 0;
+ if (!group) {
+ req.peer = new TLRPC.TL_inputNotifyUsers();
+ req.settings.mute_until = preferences.getBoolean("EnableAll", true) ? 0 : Integer.MAX_VALUE;
+ req.settings.show_previews = preferences.getBoolean("EnablePreviewAll", true);
+ } else {
+ req.peer = new TLRPC.TL_inputNotifyChats();
+ req.settings.mute_until = preferences.getBoolean("EnableGroup", true) ? 0 : Integer.MAX_VALUE;
+ req.settings.show_previews = preferences.getBoolean("EnablePreviewGroup", true);
+ }
+ ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() {
+ @Override
+ public void run(TLObject response, TLRPC.TL_error error) {
+
+ }
+ });
+ }
+
@Override
public void onActivityResultFragment(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK) {
@@ -396,6 +459,13 @@ public class SettingsNotificationsActivity extends BaseFragment {
}
}
+ @Override
+ public void didReceivedNotification(int id, Object... args) {
+ if (id == MessagesController.notificationsSettingsUpdated) {
+ listView.invalidateViews();
+ }
+ }
+
private class ListAdapter extends BaseFragmentAdapter {
private Context mContext;
@@ -553,6 +623,24 @@ public class SettingsNotificationsActivity extends BaseFragment {
textView.setText(LocaleController.getString("ResetAllNotifications", R.string.ResetAllNotifications));
textViewDetail.setText(LocaleController.getString("UndoAllCustom", R.string.UndoAllCustom));
divider.setVisibility(View.INVISIBLE);
+ } else if (i == messagePopupNotificationRow || i == groupPopupNotificationRow) {
+ textView.setText(LocaleController.getString("PopupNotification", R.string.PopupNotification));
+ int option = 0;
+ if (i == messagePopupNotificationRow) {
+ option = preferences.getInt("popupAll", 0);
+ } else if (i == groupPopupNotificationRow) {
+ option = preferences.getInt("popupGroup", 0);
+ }
+ if (option == 0) {
+ textViewDetail.setText(LocaleController.getString("NoPopup", R.string.NoPopup));
+ } else if (option == 1) {
+ textViewDetail.setText(LocaleController.getString("OnlyWhenScreenOn", R.string.OnlyWhenScreenOn));
+ } else if (option == 2) {
+ textViewDetail.setText(LocaleController.getString("OnlyWhenScreenOff", R.string.OnlyWhenScreenOff));
+ } else if (option == 3) {
+ textViewDetail.setText(LocaleController.getString("AlwaysShowPopup", R.string.AlwaysShowPopup));
+ }
+ divider.setVisibility(View.VISIBLE);
}
} else if (type == 3) {
if (view == null) {
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/SettingsWallpapersActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/SettingsWallpapersActivity.java
index 088354b2..b6620d7e 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/SettingsWallpapersActivity.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/SettingsWallpapersActivity.java
@@ -29,13 +29,14 @@ import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
-import org.telegram.messenger.LocaleController;
+import org.telegram.android.AndroidUtilities;
+import org.telegram.android.LocaleController;
import org.telegram.messenger.TLObject;
import org.telegram.messenger.TLRPC;
import org.telegram.messenger.ConnectionsManager;
import org.telegram.messenger.FileLoader;
import org.telegram.messenger.FileLog;
-import org.telegram.messenger.MessagesStorage;
+import org.telegram.android.MessagesStorage;
import org.telegram.messenger.NotificationCenter;
import org.telegram.messenger.R;
import org.telegram.messenger.RPCRequest;
@@ -111,8 +112,8 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica
boolean done;
TLRPC.WallPaper wallPaper = wallpappersByIds.get(selectedBackground);
if (wallPaper != null && wallPaper.id != 1000001 && wallPaper instanceof TLRPC.TL_wallPaper) {
- int width = Utilities.displaySize.x;
- int height = Utilities.displaySize.y;
+ int width = AndroidUtilities.displaySize.x;
+ int height = AndroidUtilities.displaySize.y;
if (width > height) {
int temp = width;
width = height;
@@ -120,7 +121,7 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica
}
TLRPC.PhotoSize size = PhotoObject.getClosestPhotoSizeWithSize(wallPaper.sizes, width, height);
String fileName = size.location.volume_id + "_" + size.location.local_id + ".jpg";
- File f = new File(Utilities.getCacheDir(), fileName);
+ File f = new File(AndroidUtilities.getCacheDir(), fileName);
File toFile = new File(ApplicationLoader.applicationContext.getFilesDir(), "wallpaper.jpg");
try {
done = Utilities.copyFile(f, toFile);
@@ -216,7 +217,7 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica
if (requestCode == 10) {
Utilities.addMediaToGallery(currentPicturePath);
try {
- Bitmap bitmap = FileLoader.loadBitmap(currentPicturePath, null, Utilities.dp(320), Utilities.dp(480));
+ Bitmap bitmap = FileLoader.loadBitmap(currentPicturePath, null, AndroidUtilities.dp(320), AndroidUtilities.dp(480));
File toFile = new File(ApplicationLoader.applicationContext.getFilesDir(), "wallpaper-temp.jpg");
FileOutputStream stream = new FileOutputStream(toFile);
bitmap.compress(Bitmap.CompressFormat.JPEG, 87, stream);
@@ -232,7 +233,7 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica
return;
}
try {
- Bitmap bitmap = FileLoader.loadBitmap(null, data.getData(), Utilities.dp(320), Utilities.dp(480));
+ Bitmap bitmap = FileLoader.loadBitmap(null, data.getData(), AndroidUtilities.dp(320), AndroidUtilities.dp(480));
File toFile = new File(ApplicationLoader.applicationContext.getFilesDir(), "wallpaper-temp.jpg");
FileOutputStream stream = new FileOutputStream(toFile);
bitmap.compress(Bitmap.CompressFormat.JPEG, 87, stream);
@@ -261,8 +262,8 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica
private void processSelectedBackground() {
TLRPC.WallPaper wallPaper = wallpappersByIds.get(selectedBackground);
if (selectedBackground != -1 && selectedBackground != 1000001 && wallPaper != null && wallPaper instanceof TLRPC.TL_wallPaper) {
- int width = Utilities.displaySize.x;
- int height = Utilities.displaySize.y;
+ int width = AndroidUtilities.displaySize.x;
+ int height = AndroidUtilities.displaySize.y;
if (width > height) {
int temp = width;
width = height;
@@ -270,7 +271,7 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica
}
TLRPC.PhotoSize size = PhotoObject.getClosestPhotoSizeWithSize(wallPaper.sizes, width, height);
String fileName = size.location.volume_id + "_" + size.location.local_id + ".jpg";
- File f = new File(Utilities.getCacheDir(), fileName);
+ File f = new File(AndroidUtilities.getCacheDir(), fileName);
if (!f.exists()) {
progressBar.setProgress(0);
loadingFile = fileName;
@@ -413,7 +414,7 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica
}
});
}
- }, null, true, RPCRequest.RPCRequestClassGeneric);
+ });
ConnectionsManager.getInstance().bindRequestToGuid(reqId, classGuid);
}
@@ -528,7 +529,7 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica
BackupImageView image = (BackupImageView)view.findViewById(R.id.image);
View selection = view.findViewById(R.id.selection);
TLRPC.WallPaper wallPaper = wallPapers.get(i - 1);
- TLRPC.PhotoSize size = PhotoObject.getClosestPhotoSizeWithSize(wallPaper.sizes, Utilities.dp(100), Utilities.dp(100));
+ TLRPC.PhotoSize size = PhotoObject.getClosestPhotoSizeWithSize(wallPaper.sizes, AndroidUtilities.dp(100), AndroidUtilities.dp(100));
if (size != null && size.location != null) {
image.setImage(size.location, "100_100", 0);
}
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/UserProfileActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/UserProfileActivity.java
index f2fe5964..63ba93f3 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/UserProfileActivity.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/UserProfileActivity.java
@@ -23,15 +23,16 @@ import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.TextView;
+import org.telegram.android.AndroidUtilities;
import org.telegram.PhoneFormat.PhoneFormat;
-import org.telegram.messenger.LocaleController;
+import org.telegram.android.LocaleController;
import org.telegram.messenger.TLObject;
import org.telegram.messenger.TLRPC;
import org.telegram.messenger.ConnectionsManager;
-import org.telegram.messenger.ContactsController;
+import org.telegram.android.ContactsController;
import org.telegram.messenger.FileLog;
-import org.telegram.messenger.MessagesController;
-import org.telegram.messenger.MessagesStorage;
+import org.telegram.android.MessagesController;
+import org.telegram.android.MessagesStorage;
import org.telegram.messenger.NotificationCenter;
import org.telegram.messenger.R;
import org.telegram.messenger.RPCRequest;
@@ -51,7 +52,6 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen
private ListView listView;
private ListAdapter listAdapter;
private int user_id;
- private String selectedPhone;
private int totalMediaCount = -1;
private boolean creatingChat = false;
private long dialog_id;
@@ -129,7 +129,7 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen
actionBarLayer.setBackOverlay(R.layout.updating_state_layout);
if (dialog_id != 0) {
actionBarLayer.setTitle(LocaleController.getString("SecretTitle", R.string.SecretTitle));
- actionBarLayer.setTitleIcon(R.drawable.ic_lock_white, Utilities.dp(4));
+ actionBarLayer.setTitleIcon(R.drawable.ic_lock_white, AndroidUtilities.dp(4));
} else {
actionBarLayer.setTitle(LocaleController.getString("ContactInfo", R.string.ContactInfo));
}
@@ -159,7 +159,7 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen
public void run(TLObject response, TLRPC.TL_error error) {
}
- }, null, true, RPCRequest.RPCRequestClassGeneric);
+ });
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
@@ -384,7 +384,7 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen
avatarImage.getLocationInWindow(coords);
PhotoViewer.PlaceProviderObject object = new PhotoViewer.PlaceProviderObject();
object.viewX = coords[0];
- object.viewY = coords[1] - Utilities.statusBarHeight;
+ object.viewY = coords[1] - AndroidUtilities.statusBarHeight;
object.parentView = listView;
object.imageReceiver = avatarImage.imageReceiver;
object.user_id = user_id;
@@ -533,7 +533,7 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen
onlineText = (TextView)view.findViewById(R.id.settings_online);
}
TextView textView = (TextView)view.findViewById(R.id.settings_name);
- Typeface typeface = Utilities.getTypeface("fonts/rmedium.ttf");
+ Typeface typeface = AndroidUtilities.getTypeface("fonts/rmedium.ttf");
textView.setTypeface(typeface);
textView.setText(Utilities.formatName(user.first_name, user.last_name));
@@ -572,29 +572,20 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen
if (user.phone == null || user.phone.length() == 0 || getParentActivity() == null) {
return;
}
- selectedPhone = user.phone;
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
- builder.setItems(new CharSequence[] {LocaleController.getString("Copy", R.string.Copy), LocaleController.getString("Call", R.string.Call)}, new DialogInterface.OnClickListener() {
+ builder.setItems(new CharSequence[] {LocaleController.getString("Copy", R.string.Copy)}, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
- if (i == 1) {
- try {
- Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:+" + selectedPhone));
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- getParentActivity().startActivity(intent);
- } catch (Exception e) {
- FileLog.e("tmessages", e);
- }
- } else if (i == 0) {
+ if (i == 0) {
int sdk = android.os.Build.VERSION.SDK_INT;
if(sdk < android.os.Build.VERSION_CODES.HONEYCOMB) {
android.text.ClipboardManager clipboard = (android.text.ClipboardManager)ApplicationLoader.applicationContext.getSystemService(Context.CLIPBOARD_SERVICE);
- clipboard.setText(selectedPhone);
+ clipboard.setText(user.phone);
} else {
android.content.ClipboardManager clipboard = (android.content.ClipboardManager)ApplicationLoader.applicationContext.getSystemService(Context.CLIPBOARD_SERVICE);
- android.content.ClipData clip = android.content.ClipData.newPlainText("label", selectedPhone);
+ android.content.ClipData clip = android.content.ClipData.newPlainText("label", user.phone);
clipboard.setPrimaryClip(clip);
}
}
@@ -603,21 +594,37 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen
showAlertDialog(builder);
}
});
- }
- ImageButton button = (ImageButton)view.findViewById(R.id.settings_edit_name);
- button.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- TLRPC.User user = MessagesController.getInstance().users.get(user_id);
- if (user == null || user instanceof TLRPC.TL_userEmpty) {
- return;
+ ImageButton button = (ImageButton)view.findViewById(R.id.settings_edit_name);
+ button.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ TLRPC.User user = MessagesController.getInstance().users.get(user_id);
+ if (user == null || user instanceof TLRPC.TL_userEmpty) {
+ return;
+ }
+ NotificationCenter.getInstance().postNotificationName(MessagesController.closeChats);
+ Bundle args = new Bundle();
+ args.putInt("user_id", user_id);
+ presentFragment(new ChatActivity(args), true);
}
- NotificationCenter.getInstance().postNotificationName(MessagesController.closeChats);
- Bundle args = new Bundle();
- args.putInt("user_id", user_id);
- presentFragment(new ChatActivity(args), true);
- }
- });
+ });
+ button = (ImageButton)view.findViewById(R.id.settings_call_phone);
+ button.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ try {
+ Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:+" + user.phone));
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ getParentActivity().startActivity(intent);
+ } catch (Exception e) {
+ FileLog.e("tmessages", e);
+ }
+ }
+ });
+ }
+ ImageButton button = (ImageButton)view.findViewById(R.id.settings_call_phone);
+ button.setVisibility(user.phone == null || user.phone.length() == 0 ? View.GONE : View.VISIBLE);
+
TextView textView = (TextView)view.findViewById(R.id.settings_row_text);
TextView detailTextView = (TextView)view.findViewById(R.id.settings_row_text_detail);
View divider = view.findViewById(R.id.settings_row_divider);
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBar.java b/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBar.java
index 76ae5d37..faf729a6 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBar.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBar.java
@@ -19,6 +19,7 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
+import org.telegram.android.AndroidUtilities;
import org.telegram.messenger.R;
import org.telegram.messenger.Utilities;
@@ -52,7 +53,7 @@ public class ActionBar extends FrameLayout {
addView(shadowView);
shadowView.setVisibility(INVISIBLE);
ViewGroup.LayoutParams layoutParams = shadowView.getLayoutParams();
- layoutParams.width = Utilities.dp(2);
+ layoutParams.width = AndroidUtilities.dp(2);
layoutParams.height = LayoutParams.MATCH_PARENT;
shadowView.setLayoutParams(layoutParams);
shadowView.setBackgroundResource(R.drawable.shadow);
@@ -116,7 +117,7 @@ public class ActionBar extends FrameLayout {
layoutParams.width = LayoutParams.MATCH_PARENT;
layoutParams.height = LayoutParams.MATCH_PARENT;
layer.setLayoutParams(layoutParams);
- shadowView.setX(-Utilities.dp(2));
+ shadowView.setX(-AndroidUtilities.dp(2));
shadowView.setVisibility(VISIBLE);
previousLayer.setBackOverlayVisible(isBackOverlayVisible);
}
@@ -143,7 +144,7 @@ public class ActionBar extends FrameLayout {
return;
}
currentLayer.setX(dx);
- shadowView.setX(dx - Utilities.dp(2));
+ shadowView.setX(dx - AndroidUtilities.dp(2));
if (dx != 0) {
if (previousLayer != null) {
previousLayer.setAlpha(Math.min(1, (float) dx / (float) currentLayer.getMeasuredWidth()));
@@ -159,11 +160,11 @@ public class ActionBar extends FrameLayout {
public void setupAnimations(ArrayList animators, boolean back) {
if (back) {
animators.add(ObjectAnimator.ofFloat(currentLayer, "x", 0));
- animators.add(ObjectAnimator.ofFloat(shadowView, "x", -Utilities.dp(2)));
+ animators.add(ObjectAnimator.ofFloat(shadowView, "x", -AndroidUtilities.dp(2)));
animators.add(ObjectAnimator.ofFloat(previousLayer, "alpha", 0));
} else {
animators.add(ObjectAnimator.ofFloat(currentLayer, "x", getMeasuredWidth()));
- animators.add(ObjectAnimator.ofFloat(shadowView, "x", getMeasuredWidth() - Utilities.dp(2)));
+ animators.add(ObjectAnimator.ofFloat(shadowView, "x", getMeasuredWidth() - AndroidUtilities.dp(2)));
animators.add(ObjectAnimator.ofFloat(previousLayer, "alpha", 1.0f));
}
}
@@ -171,9 +172,9 @@ public class ActionBar extends FrameLayout {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
if (!Utilities.isTablet(getContext()) && getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
- super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(Utilities.dp(40), MeasureSpec.EXACTLY));
+ super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(40), MeasureSpec.EXACTLY));
} else {
- super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(Utilities.dp(48), MeasureSpec.EXACTLY));
+ super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(48), MeasureSpec.EXACTLY));
}
}
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBarActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBarActivity.java
index 3cdcd8dd..40b72321 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBarActivity.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBarActivity.java
@@ -32,6 +32,7 @@ import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.FrameLayout;
+import org.telegram.android.AndroidUtilities;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.R;
import org.telegram.messenger.Utilities;
@@ -139,7 +140,7 @@ public class ActionBarActivity extends Activity {
contentView.addView(shadowView);
shadowView.setBackgroundResource(R.drawable.shadow);
ViewGroup.LayoutParams layoutParams = shadowView.getLayoutParams();
- layoutParams.width = Utilities.dp(2);
+ layoutParams.width = AndroidUtilities.dp(2);
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
shadowView.setLayoutParams(layoutParams);
shadowView.setVisibility(View.INVISIBLE);
@@ -202,7 +203,7 @@ public class ActionBarActivity extends Activity {
containerViewBack.setX(0);
actionBar.stopMoving(backAnimation);
shadowView.setVisibility(View.INVISIBLE);
- shadowView.setX(-Utilities.dp(2));
+ shadowView.setX(-AndroidUtilities.dp(2));
if (!backAnimation) {
BaseFragment lastFragment = fragmentsStack.get(fragmentsStack.size() - 1);
lastFragment.onPause();
@@ -229,7 +230,7 @@ public class ActionBarActivity extends Activity {
}
}
containerViewBack.setVisibility(View.GONE);
- Utilities.unlockOrientation(this);
+ AndroidUtilities.unlockOrientation(this);
startedTracking = false;
animationInProgress = false;
}
@@ -239,7 +240,7 @@ public class ActionBarActivity extends Activity {
startedTracking = true;
startedTrackingX = (int) ev.getX();
shadowView.setVisibility(View.VISIBLE);
- shadowView.setX(-Utilities.dp(2));
+ shadowView.setX(-AndroidUtilities.dp(2));
containerViewBack.setVisibility(View.VISIBLE);
beginTrackingSent = false;
@@ -260,7 +261,7 @@ public class ActionBarActivity extends Activity {
}
lastFragment.onResume();
- Utilities.lockOrientation(this);
+ AndroidUtilities.lockOrientation(this);
}
public boolean onTouchEvent(MotionEvent ev) {
@@ -284,12 +285,12 @@ public class ActionBarActivity extends Activity {
int dx = Math.max(0, (int) (ev.getX() - startedTrackingX));
int dy = Math.abs((int)ev.getY() - startedTrackingY);
velocityTracker.addMovement(ev);
- if (maybeStartTracking && !startedTracking && dx >= Utilities.dp(10) && Math.abs(dx) / 3 > dy) {
+ if (maybeStartTracking && !startedTracking && dx >= AndroidUtilities.dp(10) && Math.abs(dx) / 3 > dy) {
prepareForMoving(ev);
} else if (startedTracking) {
if (!beginTrackingSent) {
if (getCurrentFocus() != null) {
- Utilities.hideKeyboard(getCurrentFocus());
+ AndroidUtilities.hideKeyboard(getCurrentFocus());
}
BaseFragment currentFragment = fragmentsStack.get(fragmentsStack.size() - 1);
currentFragment.onBeginSlide();
@@ -297,7 +298,7 @@ public class ActionBarActivity extends Activity {
}
actionBar.moveActionBarByX(dx);
containerView.setX(dx);
- shadowView.setX(dx - Utilities.dp(2));
+ shadowView.setX(dx - AndroidUtilities.dp(2));
}
} else if (ev != null && ev.getPointerId(0) == startedTrackingPointerId && (ev.getAction() == MotionEvent.ACTION_CANCEL || ev.getAction() == MotionEvent.ACTION_UP || ev.getAction() == MotionEvent.ACTION_POINTER_UP)) {
if (velocityTracker == null) {
@@ -321,11 +322,11 @@ public class ActionBarActivity extends Activity {
if (!backAnimation) {
distToMove = containerView.getMeasuredWidth() - x;
animators.add(ObjectAnimator.ofFloat(containerView, "x", containerView.getMeasuredWidth()));
- animators.add(ObjectAnimator.ofFloat(shadowView, "x", containerView.getMeasuredWidth() - Utilities.dp(2)));
+ animators.add(ObjectAnimator.ofFloat(shadowView, "x", containerView.getMeasuredWidth() - AndroidUtilities.dp(2)));
} else {
distToMove = x;
animators.add(ObjectAnimator.ofFloat(containerView, "x", 0));
- animators.add(ObjectAnimator.ofFloat(shadowView, "x", -Utilities.dp(2)));
+ animators.add(ObjectAnimator.ofFloat(shadowView, "x", -AndroidUtilities.dp(2)));
}
actionBar.setupAnimations(animators, backAnimation);
@@ -439,9 +440,9 @@ public class ActionBarActivity extends Activity {
int height = 0;
if (actionBar.getVisibility() == View.VISIBLE) {
if (!Utilities.isTablet(this) && getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
- height = Utilities.dp(40);
+ height = AndroidUtilities.dp(40);
} else {
- height = Utilities.dp(48);
+ height = AndroidUtilities.dp(48);
}
}
@@ -500,7 +501,7 @@ public class ActionBarActivity extends Activity {
return false;
}
if (getCurrentFocus() != null) {
- Utilities.hideKeyboard(getCurrentFocus());
+ AndroidUtilities.hideKeyboard(getCurrentFocus());
}
boolean needAnimation = openAnimation != null && !forceWithoutAnimation && getSharedPreferences("mainconfig", Activity.MODE_PRIVATE).getBoolean("view_animations", true);
@@ -575,7 +576,7 @@ public class ActionBarActivity extends Activity {
return;
}
if (getCurrentFocus() != null) {
- Utilities.hideKeyboard(getCurrentFocus());
+ AndroidUtilities.hideKeyboard(getCurrentFocus());
}
boolean needAnimation = animated && closeAnimation != null && getSharedPreferences("mainconfig", Activity.MODE_PRIVATE).getBoolean("view_animations", true);
final BaseFragment currentFragment = fragmentsStack.get(fragmentsStack.size() - 1);
@@ -634,6 +635,7 @@ public class ActionBarActivity extends Activity {
}
public void removeFragmentFromStack(BaseFragment fragment) {
+ fragment.onPause();
fragment.onFragmentDestroy();
fragment.setParentActivity(null);
fragmentsStack.remove(fragment);
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBarLayer.java b/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBarLayer.java
index 5e8567a1..701624e0 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBarLayer.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBarLayer.java
@@ -21,6 +21,7 @@ import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
+import org.telegram.android.AndroidUtilities;
import org.telegram.messenger.R;
import org.telegram.messenger.Utilities;
@@ -65,7 +66,7 @@ public class ActionBarLayer extends FrameLayout {
layoutParams.height = LayoutParams.FILL_PARENT;
layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
backButtonFrameLayout.setLayoutParams(layoutParams);
- backButtonFrameLayout.setPadding(0, 0, Utilities.dp(4), 0);
+ backButtonFrameLayout.setPadding(0, 0, AndroidUtilities.dp(4), 0);
backButtonFrameLayout.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
@@ -99,7 +100,7 @@ public class ActionBarLayer extends FrameLayout {
layoutParams.width = LayoutParams.WRAP_CONTENT;
layoutParams.height = LayoutParams.WRAP_CONTENT;
layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
- layoutParams.setMargins(Utilities.dp(3), (height - backButtonImageView.getDrawable().getIntrinsicHeight()) / 2, 0, 0);
+ layoutParams.setMargins(AndroidUtilities.dp(3), (height - backButtonImageView.getDrawable().getIntrinsicHeight()) / 2, 0, 0);
backButtonImageView.setLayoutParams(layoutParams);
}
}
@@ -110,11 +111,11 @@ public class ActionBarLayer extends FrameLayout {
if (!Utilities.isTablet(getContext()) && getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
layoutParams.width = (int)(logoImageView.getDrawable().getIntrinsicWidth() / 1.3f);
layoutParams.height = (int)(logoImageView.getDrawable().getIntrinsicHeight() / 1.3f);
- layoutParams.setMargins(Utilities.dp(12), (height - layoutParams.height) / 2, 0, 0);
+ layoutParams.setMargins(AndroidUtilities.dp(12), (height - layoutParams.height) / 2, 0, 0);
} else {
layoutParams.width = logoImageView.getDrawable().getIntrinsicWidth();
layoutParams.height = logoImageView.getDrawable().getIntrinsicHeight();
- layoutParams.setMargins(Utilities.dp(12), (height - layoutParams.width) / 2, 0, 0);
+ layoutParams.setMargins(AndroidUtilities.dp(12), (height - layoutParams.width) / 2, 0, 0);
}
layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
logoImageView.setLayoutParams(layoutParams);
@@ -122,9 +123,9 @@ public class ActionBarLayer extends FrameLayout {
}
private void positionTitle(int width, int height) {
- int offset = Utilities.dp(2);
+ int offset = AndroidUtilities.dp(2);
if (!Utilities.isTablet(getContext()) && getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
- offset = Utilities.dp(1);
+ offset = AndroidUtilities.dp(1);
}
int maxTextWidth = 0;
@@ -163,17 +164,17 @@ public class ActionBarLayer extends FrameLayout {
int x = 0;
if (logoImageView == null || logoImageView.getVisibility() == GONE) {
- x = Utilities.dp(16);
+ x = AndroidUtilities.dp(16);
} else {
if (!Utilities.isTablet(getContext()) && getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
- x = Utilities.dp(22) + (int)(logoImageView.getDrawable().getIntrinsicWidth() / 1.3f);
+ x = AndroidUtilities.dp(22) + (int)(logoImageView.getDrawable().getIntrinsicWidth() / 1.3f);
} else {
- x = Utilities.dp(22) + logoImageView.getDrawable().getIntrinsicWidth();
+ x = AndroidUtilities.dp(22) + logoImageView.getDrawable().getIntrinsicWidth();
}
}
if (menu != null) {
- maxTextWidth = Math.min(maxTextWidth, width - menu.getMeasuredWidth() - Utilities.dp(16));
+ maxTextWidth = Math.min(maxTextWidth, width - menu.getMeasuredWidth() - AndroidUtilities.dp(16));
}
if (titleTextView != null && titleTextView.getVisibility() == VISIBLE) {
@@ -196,7 +197,7 @@ public class ActionBarLayer extends FrameLayout {
}
ViewGroup.LayoutParams layoutParams1 = backButtonFrameLayout.getLayoutParams();
- layoutParams1.width = x + maxTextWidth + (isSearchFieldVisible ? 0 : Utilities.dp(6));
+ layoutParams1.width = x + maxTextWidth + (isSearchFieldVisible ? 0 : AndroidUtilities.dp(6));
backButtonFrameLayout.setLayoutParams(layoutParams1);
}
@@ -206,7 +207,7 @@ public class ActionBarLayer extends FrameLayout {
}
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams)menu.getLayoutParams();
layoutParams.width = isSearchFieldVisible ? LayoutParams.MATCH_PARENT : LayoutParams.WRAP_CONTENT;
- layoutParams.leftMargin = isSearchFieldVisible ? Utilities.dp(26) + logoImageView.getDrawable().getIntrinsicWidth() : 0;
+ layoutParams.leftMargin = isSearchFieldVisible ? AndroidUtilities.dp(26) + logoImageView.getDrawable().getIntrinsicWidth() : 0;
menu.setLayoutParams(layoutParams);
menu.measure(width, height);
}
@@ -402,7 +403,7 @@ public class ActionBarLayer extends FrameLayout {
if (subTitleTextView != null) {
subTitleTextView.setVisibility(visible ? GONE : VISIBLE);
}
- backButtonFrameLayout.setPadding(0, 0, visible ? 0 : Utilities.dp(4), 0);
+ backButtonFrameLayout.setPadding(0, 0, visible ? 0 : AndroidUtilities.dp(4), 0);
if (visible) {
oldUseLogo = logoImageView != null && logoImageView.getVisibility() == VISIBLE;
setDisplayUseLogoEnabled(true, R.drawable.ic_ab_search);
@@ -495,7 +496,7 @@ public class ActionBarLayer extends FrameLayout {
layoutParams.height = LayoutParams.MATCH_PARENT;
actionOverlay.setLayoutParams(layoutParams);
actionOverlay.measure(widthMeasureSpec, heightMeasureSpec);
- layoutParams.width = Math.min(actionOverlay.getMeasuredWidth() + Utilities.dp(4), widthMeasureSpec - (menu != null ? menu.getMeasuredWidth() : 0));
+ layoutParams.width = Math.min(actionOverlay.getMeasuredWidth() + AndroidUtilities.dp(4), widthMeasureSpec - (menu != null ? menu.getMeasuredWidth() : 0));
actionOverlay.setLayoutParams(layoutParams);
}
}
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBarMenu.java b/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBarMenu.java
index 823eb704..b22b439e 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBarMenu.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBarMenu.java
@@ -16,7 +16,7 @@ import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
-import org.telegram.messenger.Utilities;
+import org.telegram.android.AndroidUtilities;
public class ActionBarMenu extends LinearLayout {
@@ -68,7 +68,7 @@ public class ActionBarMenu extends LinearLayout {
addView(menuItem);
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams)menuItem.getLayoutParams();
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
- layoutParams.width = Utilities.dp(56);
+ layoutParams.width = AndroidUtilities.dp(56);
menuItem.setLayoutParams(layoutParams);
menuItem.setOnClickListener(new OnClickListener() {
@Override
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBarMenuItem.java b/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBarMenuItem.java
index a655d93d..e3c1117d 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBarMenuItem.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBarMenuItem.java
@@ -26,6 +26,7 @@ import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
+import org.telegram.android.AndroidUtilities;
import org.telegram.messenger.R;
import org.telegram.messenger.Utilities;
@@ -151,8 +152,8 @@ public class ActionBarMenuItem extends ImageView {
delimeter.setBackgroundColor(0xffdcdcdc);
popupLayout.addView(delimeter);
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams)delimeter.getLayoutParams();
- layoutParams.width = Utilities.dp(196);
- layoutParams.height = Utilities.density >= 3 ? 2 : 1;
+ layoutParams.width = AndroidUtilities.dp(196);
+ layoutParams.height = AndroidUtilities.density >= 3 ? 2 : 1;
delimeter.setLayoutParams(layoutParams);
delimeter.setTag(100 + id);
}
@@ -160,19 +161,19 @@ public class ActionBarMenuItem extends ImageView {
textView.setTextColor(0xff000000);
textView.setBackgroundResource(R.drawable.list_selector);
textView.setGravity(Gravity.CENTER_VERTICAL);
- textView.setPadding(Utilities.dp(16), 0, Utilities.dp(16), 0);
+ textView.setPadding(AndroidUtilities.dp(16), 0, AndroidUtilities.dp(16), 0);
textView.setTextSize(18);
- textView.setMinWidth(Utilities.dp(196));
+ textView.setMinWidth(AndroidUtilities.dp(196));
textView.setTag(id);
textView.setText(text);
if (icon != 0) {
- textView.setCompoundDrawablePadding(Utilities.dp(12));
+ textView.setCompoundDrawablePadding(AndroidUtilities.dp(12));
textView.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(icon), null, null, null);
}
popupLayout.addView(textView);
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams)textView.getLayoutParams();
layoutParams.width = LinearLayout.LayoutParams.WRAP_CONTENT;
- layoutParams.height = Utilities.dp(48);
+ layoutParams.height = AndroidUtilities.dp(48);
textView.setLayoutParams(layoutParams);
textView.setOnClickListener(new OnClickListener() {
@Override
@@ -201,7 +202,7 @@ public class ActionBarMenuItem extends ImageView {
popupWindow.setClippingEnabled(true);
popupWindow.setInputMethodMode(ActionBarPopupWindow.INPUT_METHOD_NOT_NEEDED);
popupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED);
- popupLayout.measure(MeasureSpec.makeMeasureSpec(Utilities.dp(1000), MeasureSpec.AT_MOST), MeasureSpec.makeMeasureSpec(Utilities.dp(1000), MeasureSpec.AT_MOST));
+ popupLayout.measure(MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(1000), MeasureSpec.AT_MOST), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(1000), MeasureSpec.AT_MOST));
}
popupWindow.setFocusable(true);
if (popupLayout.getMeasuredWidth() == 0) {
@@ -219,7 +220,7 @@ public class ActionBarMenuItem extends ImageView {
if (searchField.getVisibility() == VISIBLE) {
searchField.setVisibility(GONE);
setVisibility(VISIBLE);
- Utilities.hideKeyboard(searchField);
+ AndroidUtilities.hideKeyboard(searchField);
if (listener != null) {
listener.onSearchCollapse();
}
@@ -229,7 +230,7 @@ public class ActionBarMenuItem extends ImageView {
setVisibility(GONE);
searchField.setText("");
searchField.requestFocus();
- Utilities.showKeyboard(searchField);
+ AndroidUtilities.showKeyboard(searchField);
if (listener != null) {
listener.onSearchExpand();
}
@@ -254,13 +255,13 @@ public class ActionBarMenuItem extends ImageView {
searchField.setTextColor(0xffffffff);
searchField.setSingleLine(true);
searchField.setBackgroundResource(R.drawable.search_light_states);
- searchField.setPadding(Utilities.dp(6), 0, Utilities.dp(6), 0);
+ searchField.setPadding(AndroidUtilities.dp(6), 0, AndroidUtilities.dp(6), 0);
searchField.setInputType(EditorInfo.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
searchField.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH || event != null && event.getAction() == KeyEvent.ACTION_UP && event.getKeyCode() == KeyEvent.KEYCODE_SEARCH) {
- Utilities.hideKeyboard(searchField);
+ AndroidUtilities.hideKeyboard(searchField);
}
return false;
}
@@ -308,8 +309,8 @@ public class ActionBarMenuItem extends ImageView {
layoutParams.weight = 1;
layoutParams.width = 0;
layoutParams.gravity = Gravity.CENTER_VERTICAL;
- layoutParams.height = Utilities.dp(36);
- layoutParams.rightMargin = Utilities.dp(4);
+ layoutParams.height = AndroidUtilities.dp(36);
+ layoutParams.rightMargin = AndroidUtilities.dp(4);
searchField.setLayoutParams(layoutParams);
searchField.setVisibility(GONE);
}
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Views/AvatarUpdater.java b/TMessagesProj/src/main/java/org/telegram/ui/Views/AvatarUpdater.java
index 0deea122..4c765f8b 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/Views/AvatarUpdater.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/Views/AvatarUpdater.java
@@ -15,6 +15,7 @@ import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
+import org.telegram.android.AndroidUtilities;
import org.telegram.messenger.TLRPC;
import org.telegram.messenger.FileLoader;
import org.telegram.messenger.FileLog;
@@ -126,7 +127,7 @@ public class AvatarUpdater implements NotificationCenter.NotificationCenterDeleg
}
} else {
UserConfig.saveConfig(false);
- uploadingAvatar = Utilities.getCacheDir() + "/" + bigPhoto.location.volume_id + "_" + bigPhoto.location.local_id + ".jpg";
+ uploadingAvatar = AndroidUtilities.getCacheDir() + "/" + bigPhoto.location.volume_id + "_" + bigPhoto.location.local_id + ".jpg";
NotificationCenter.getInstance().addObserver(AvatarUpdater.this, FileLoader.FileDidUpload);
NotificationCenter.getInstance().addObserver(AvatarUpdater.this, FileLoader.FileDidFailUpload);
FileLoader.getInstance().uploadFile(uploadingAvatar, false);
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Views/BackupImageView.java b/TMessagesProj/src/main/java/org/telegram/ui/Views/BackupImageView.java
index 598b4e50..7afc9c1d 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/Views/BackupImageView.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/Views/BackupImageView.java
@@ -18,8 +18,6 @@ import android.view.View;
import org.telegram.messenger.TLRPC;
-import java.lang.ref.WeakReference;
-
public class BackupImageView extends View {
public ImageReceiver imageReceiver;
public boolean processDetach = true;
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Views/ChatActivityEnterView.java b/TMessagesProj/src/main/java/org/telegram/ui/Views/ChatActivityEnterView.java
new file mode 100644
index 00000000..d908907d
--- /dev/null
+++ b/TMessagesProj/src/main/java/org/telegram/ui/Views/ChatActivityEnterView.java
@@ -0,0 +1,643 @@
+/*
+ * This is the source code of Telegram for Android v. 1.4.x.
+ * It is licensed under GNU GPL v. 2 or later.
+ * You should have received a copy of the license in this archive (see LICENSE).
+ *
+ * Copyright Nikolai Kudashov, 2013-2014.
+ */
+
+package org.telegram.ui.Views;
+
+import android.animation.Animator;
+import android.app.Activity;
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.graphics.Rect;
+import android.os.PowerManager;
+import android.text.Editable;
+import android.text.TextWatcher;
+import android.text.style.ImageSpan;
+import android.view.KeyEvent;
+import android.view.MotionEvent;
+import android.view.Surface;
+import android.view.View;
+import android.view.WindowManager;
+import android.view.animation.AccelerateDecelerateInterpolator;
+import android.view.inputmethod.EditorInfo;
+import android.view.inputmethod.InputMethodManager;
+import android.widget.EditText;
+import android.widget.FrameLayout;
+import android.widget.ImageButton;
+import android.widget.ImageView;
+import android.widget.PopupWindow;
+import android.widget.TextView;
+
+import org.telegram.android.AndroidUtilities;
+import org.telegram.android.Emoji;
+import org.telegram.android.LocaleController;
+import org.telegram.android.MediaController;
+import org.telegram.android.MessagesController;
+import org.telegram.messenger.ConnectionsManager;
+import org.telegram.messenger.FileLog;
+import org.telegram.messenger.NotificationCenter;
+import org.telegram.messenger.R;
+import org.telegram.messenger.TLRPC;
+import org.telegram.ui.ApplicationLoader;
+
+public class ChatActivityEnterView implements NotificationCenter.NotificationCenterDelegate, SizeNotifierRelativeLayout.SizeNotifierRelativeLayoutDelegate {
+
+ public static interface ChatActivityEnterViewDelegate {
+ public abstract void onMessageSend();
+ public abstract void needSendTyping();
+ }
+
+ private EditText messsageEditText;
+ private ImageButton sendButton;
+ private PopupWindow emojiPopup;
+ private ImageView emojiButton;
+ private EmojiView emojiView;
+ private TextView recordTimeText;
+ private ImageButton audioSendButton;
+ private View recordPanel;
+ private View slideText;
+ private PowerManager.WakeLock mWakeLock = null;
+ private SizeNotifierRelativeLayout sizeNotifierRelativeLayout;
+
+ private int keyboardHeight = 0;
+ private int keyboardHeightLand = 0;
+ private boolean keyboardVisible;
+ private boolean sendByEnter = false;
+ private long lastTypingTimeSend = 0;
+ private String lastTimeString = null;
+ private float startedDraggingX = -1;
+ private float distCanMove = AndroidUtilities.dp(80);
+ private boolean recordingAudio = false;
+
+ private Activity parentActivity;
+ private long dialog_id;
+ private boolean ignoreTextChange = false;
+ private ChatActivityEnterViewDelegate delegate;
+
+ public ChatActivityEnterView() {
+ NotificationCenter.getInstance().addObserver(this, MediaController.recordStarted);
+ NotificationCenter.getInstance().addObserver(this, MediaController.recordStartError);
+ NotificationCenter.getInstance().addObserver(this, MediaController.recordStopped);
+ NotificationCenter.getInstance().addObserver(this, MediaController.recordProgressChanged);
+ NotificationCenter.getInstance().addObserver(this, MessagesController.closeChats);
+ NotificationCenter.getInstance().addObserver(this, MediaController.audioDidSent);
+ NotificationCenter.getInstance().addObserver(this, 999);
+ SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
+ sendByEnter = preferences.getBoolean("send_by_enter", false);
+ }
+
+ public void onDestroy() {
+ NotificationCenter.getInstance().removeObserver(this, MediaController.recordStarted);
+ NotificationCenter.getInstance().removeObserver(this, MediaController.recordStartError);
+ NotificationCenter.getInstance().removeObserver(this, MediaController.recordStopped);
+ NotificationCenter.getInstance().removeObserver(this, MediaController.recordProgressChanged);
+ NotificationCenter.getInstance().removeObserver(this, MessagesController.closeChats);
+ NotificationCenter.getInstance().removeObserver(this, 999);
+ if (mWakeLock != null) {
+ try {
+ mWakeLock.release();
+ mWakeLock = null;
+ } catch (Exception e) {
+ FileLog.e("tmessages", e);
+ }
+ }
+ if (sizeNotifierRelativeLayout != null) {
+ sizeNotifierRelativeLayout.delegate = null;
+ sizeNotifierRelativeLayout = null;
+ }
+ }
+
+ public void setContainerView(Activity activity, View containerView) {
+ parentActivity = activity;
+
+ sizeNotifierRelativeLayout = (SizeNotifierRelativeLayout)containerView.findViewById(R.id.chat_layout);
+ sizeNotifierRelativeLayout.delegate = this;
+
+ messsageEditText = (EditText)containerView.findViewById(R.id.chat_text_edit);
+ messsageEditText.setHint(LocaleController.getString("TypeMessage", R.string.TypeMessage));
+
+ sendButton = (ImageButton)containerView.findViewById(R.id.chat_send_button);
+ sendButton.setEnabled(false);
+ sendButton.setVisibility(View.INVISIBLE);
+ emojiButton = (ImageView)containerView.findViewById(R.id.chat_smile_button);
+ audioSendButton = (ImageButton)containerView.findViewById(R.id.chat_audio_send_button);
+ recordPanel = containerView.findViewById(R.id.record_panel);
+ recordTimeText = (TextView)containerView.findViewById(R.id.recording_time_text);
+ slideText = containerView.findViewById(R.id.slideText);
+ TextView textView = (TextView)containerView.findViewById(R.id.slideToCancelTextView);
+ textView.setText(LocaleController.getString("SlideToCancel", R.string.SlideToCancel));
+
+ emojiButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ if (emojiPopup == null) {
+ showEmojiPopup(true);
+ } else {
+ showEmojiPopup(!emojiPopup.isShowing());
+ }
+ }
+ });
+
+ messsageEditText.setOnKeyListener(new View.OnKeyListener() {
+ @Override
+ public boolean onKey(View view, int i, KeyEvent keyEvent) {
+ if (i == 4 && !keyboardVisible && emojiPopup != null && emojiPopup.isShowing()) {
+ if (keyEvent.getAction() == 1) {
+ showEmojiPopup(false);
+ }
+ return true;
+ } else if (i == KeyEvent.KEYCODE_ENTER && sendByEnter && keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
+ sendMessage();
+ return true;
+ }
+ return false;
+ }
+ });
+
+ messsageEditText.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ if (emojiPopup != null && emojiPopup.isShowing()) {
+ showEmojiPopup(false);
+ }
+ }
+ });
+
+ messsageEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
+ @Override
+ public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
+ if (i == EditorInfo.IME_ACTION_SEND) {
+ sendMessage();
+ return true;
+ } else if (sendByEnter) {
+ if (keyEvent != null && i == EditorInfo.IME_NULL && keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
+ sendMessage();
+ return true;
+ }
+ }
+ return false;
+ }
+ });
+
+ sendButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ sendMessage();
+ }
+ });
+
+ audioSendButton.setOnTouchListener(new View.OnTouchListener() {
+ @Override
+ public boolean onTouch(View view, MotionEvent motionEvent) {
+ if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
+ startedDraggingX = -1;
+ MediaController.getInstance().startRecording(dialog_id);
+ updateAudioRecordIntefrace();
+ } else if (motionEvent.getAction() == MotionEvent.ACTION_UP || motionEvent.getAction() == MotionEvent.ACTION_CANCEL) {
+ startedDraggingX = -1;
+ MediaController.getInstance().stopRecording(true);
+ recordingAudio = false;
+ updateAudioRecordIntefrace();
+ } else if (motionEvent.getAction() == MotionEvent.ACTION_MOVE && recordingAudio) {
+ float x = motionEvent.getX();
+ if (x < -distCanMove) {
+ MediaController.getInstance().stopRecording(false);
+ recordingAudio = false;
+ updateAudioRecordIntefrace();
+ }
+ if(android.os.Build.VERSION.SDK_INT > 13) {
+ x = x + audioSendButton.getX();
+ FrameLayout.LayoutParams params = (FrameLayout.LayoutParams)slideText.getLayoutParams();
+ if (startedDraggingX != -1) {
+ float dist = (x - startedDraggingX);
+ params.leftMargin = AndroidUtilities.dp(30) + (int)dist;
+ slideText.setLayoutParams(params);
+ float alpha = 1.0f + dist / distCanMove;
+ if (alpha > 1) {
+ alpha = 1;
+ } else if (alpha < 0) {
+ alpha = 0;
+ }
+ slideText.setAlpha(alpha);
+ }
+ if (x <= slideText.getX() + slideText.getWidth() + AndroidUtilities.dp(30)) {
+ if (startedDraggingX == -1) {
+ startedDraggingX = x;
+ distCanMove = (recordPanel.getMeasuredWidth() - slideText.getMeasuredWidth() - AndroidUtilities.dp(48)) / 2.0f;
+ if (distCanMove <= 0) {
+ distCanMove = AndroidUtilities.dp(80);
+ } else if (distCanMove > AndroidUtilities.dp(80)) {
+ distCanMove = AndroidUtilities.dp(80);
+ }
+ }
+ }
+ if (params.leftMargin > AndroidUtilities.dp(30)) {
+ params.leftMargin = AndroidUtilities.dp(30);
+ slideText.setLayoutParams(params);
+ slideText.setAlpha(1);
+ startedDraggingX = -1;
+ }
+ }
+ }
+ view.onTouchEvent(motionEvent);
+ return true;
+ }
+ });
+
+ messsageEditText.addTextChangedListener(new TextWatcher() {
+ @Override
+ public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
+
+ }
+
+ @Override
+ public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
+ String message = getTrimmedString(charSequence.toString());
+ sendButton.setEnabled(message.length() != 0);
+ checkSendButton();
+
+ if (message.length() != 0 && lastTypingTimeSend < System.currentTimeMillis() - 5000 && !ignoreTextChange) {
+ int currentTime = ConnectionsManager.getInstance().getCurrentTime();
+ TLRPC.User currentUser = null;
+ if ((int)dialog_id > 0) {
+ currentUser = MessagesController.getInstance().users.get((int)dialog_id);
+ }
+ if (currentUser != null && currentUser.status != null && currentUser.status.expires < currentTime) {
+ return;
+ }
+ lastTypingTimeSend = System.currentTimeMillis();
+ if (delegate != null) {
+ delegate.needSendTyping();
+ }
+ }
+ }
+
+ @Override
+ public void afterTextChanged(Editable editable) {
+ if (sendByEnter && editable.length() > 0 && editable.charAt(editable.length() - 1) == '\n') {
+ sendMessage();
+ }
+ int i = 0;
+ ImageSpan[] arrayOfImageSpan = editable.getSpans(0, editable.length(), ImageSpan.class);
+ int j = arrayOfImageSpan.length;
+ while (true) {
+ if (i >= j) {
+ Emoji.replaceEmoji(editable, messsageEditText.getPaint().getFontMetricsInt(), AndroidUtilities.dp(20));
+ return;
+ }
+ editable.removeSpan(arrayOfImageSpan[i]);
+ i++;
+ }
+ }
+ });
+
+ checkSendButton();
+ }
+
+ private void sendMessage() {
+ if (processSendingText(messsageEditText.getText().toString())) {
+ messsageEditText.setText("");
+ lastTypingTimeSend = 0;
+ if (delegate != null) {
+ delegate.onMessageSend();
+ }
+ }
+ }
+
+ public boolean processSendingText(String text) {
+ text = getTrimmedString(text);
+ if (text.length() != 0) {
+ int count = (int)Math.ceil(text.length() / 2048.0f);
+ for (int a = 0; a < count; a++) {
+ String mess = text.substring(a * 2048, Math.min((a + 1) * 2048, text.length()));
+ MessagesController.getInstance().sendMessage(mess, dialog_id);
+ }
+ return true;
+ }
+ return false;
+ }
+
+ private String getTrimmedString(String src) {
+ String result = src.trim();
+ if (result.length() == 0) {
+ return result;
+ }
+ while (src.startsWith("\n")) {
+ src = src.substring(1);
+ }
+ while (src.endsWith("\n")) {
+ src = src.substring(0, src.length() - 1);
+ }
+ return src;
+ }
+
+ private void checkSendButton() {
+ String message = getTrimmedString(messsageEditText.getText().toString());
+ if (message.length() > 0) {
+ sendButton.setVisibility(View.VISIBLE);
+ audioSendButton.setVisibility(View.INVISIBLE);
+ } else {
+ sendButton.setVisibility(View.INVISIBLE);
+ audioSendButton.setVisibility(View.VISIBLE);
+ }
+ }
+
+ private void updateAudioRecordIntefrace() {
+ if (recordingAudio) {
+ try {
+ if (mWakeLock == null) {
+ PowerManager pm = (PowerManager) ApplicationLoader.applicationContext.getSystemService(Context.POWER_SERVICE);
+ mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "audio record lock");
+ mWakeLock.acquire();
+ }
+ } catch (Exception e) {
+ FileLog.e("tmessages", e);
+ }
+ AndroidUtilities.lockOrientation(parentActivity);
+
+ recordPanel.setVisibility(View.VISIBLE);
+ recordTimeText.setText("00:00");
+ lastTimeString = null;
+ if(android.os.Build.VERSION.SDK_INT > 13) {
+ FrameLayout.LayoutParams params = (FrameLayout.LayoutParams)slideText.getLayoutParams();
+ params.leftMargin = AndroidUtilities.dp(30);
+ slideText.setLayoutParams(params);
+ slideText.setAlpha(1);
+ recordPanel.setX(AndroidUtilities.displaySize.x);
+ recordPanel.animate().setInterpolator(new AccelerateDecelerateInterpolator()).setListener(new Animator.AnimatorListener() {
+ @Override
+ public void onAnimationStart(Animator animator) {
+ }
+
+ @Override
+ public void onAnimationEnd(Animator animator) {
+ recordPanel.setX(0);
+ }
+
+ @Override
+ public void onAnimationCancel(Animator animator) {
+ }
+
+ @Override
+ public void onAnimationRepeat(Animator animator) {
+ }
+ }).setDuration(300).translationX(0).start();
+ }
+ } else {
+ if (mWakeLock != null) {
+ try {
+ mWakeLock.release();
+ mWakeLock = null;
+ } catch (Exception e) {
+ FileLog.e("tmessages", e);
+ }
+ }
+ AndroidUtilities.unlockOrientation(parentActivity);
+ if(android.os.Build.VERSION.SDK_INT > 13) {
+ recordPanel.animate().setInterpolator(new AccelerateDecelerateInterpolator()).setListener(new Animator.AnimatorListener() {
+ @Override
+ public void onAnimationStart(Animator animator) {
+
+ }
+
+ @Override
+ public void onAnimationEnd(Animator animator) {
+ FrameLayout.LayoutParams params = (FrameLayout.LayoutParams)slideText.getLayoutParams();
+ params.leftMargin = AndroidUtilities.dp(30);
+ slideText.setLayoutParams(params);
+ slideText.setAlpha(1);
+ recordPanel.setVisibility(View.GONE);
+ }
+
+ @Override
+ public void onAnimationCancel(Animator animator) {
+ }
+
+ @Override
+ public void onAnimationRepeat(Animator animator) {
+ }
+ }).setDuration(300).translationX(AndroidUtilities.displaySize.x).start();
+ } else {
+ recordPanel.setVisibility(View.GONE);
+ }
+ }
+ }
+
+ private void showEmojiPopup(boolean show) {
+ InputMethodManager localInputMethodManager = (InputMethodManager)ApplicationLoader.applicationContext.getSystemService(Context.INPUT_METHOD_SERVICE);
+ if (show) {
+ if (emojiPopup == null) {
+ createEmojiPopup();
+ }
+ int currentHeight;
+ WindowManager manager = (WindowManager) ApplicationLoader.applicationContext.getSystemService(Activity.WINDOW_SERVICE);
+ int rotation = manager.getDefaultDisplay().getRotation();
+ if (keyboardHeight <= 0) {
+ keyboardHeight = ApplicationLoader.applicationContext.getSharedPreferences("emoji", 0).getInt("kbd_height", AndroidUtilities.dp(200));
+ }
+ if (keyboardHeightLand <= 0) {
+ keyboardHeightLand = ApplicationLoader.applicationContext.getSharedPreferences("emoji", 0).getInt("kbd_height_land3", AndroidUtilities.dp(200));
+ }
+ if (rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90) {
+ currentHeight = keyboardHeightLand;
+ } else {
+ currentHeight = keyboardHeight;
+ }
+ emojiPopup.setHeight(View.MeasureSpec.makeMeasureSpec(currentHeight, View.MeasureSpec.EXACTLY));
+ emojiPopup.setWidth(View.MeasureSpec.makeMeasureSpec(sizeNotifierRelativeLayout.getWidth(), View.MeasureSpec.EXACTLY));
+
+ emojiPopup.showAtLocation(parentActivity.getWindow().getDecorView(), 83, 0, 0);
+ if (!keyboardVisible) {
+ sizeNotifierRelativeLayout.setPadding(0, 0, 0, currentHeight);
+ emojiButton.setImageResource(R.drawable.ic_msg_panel_hide);
+ return;
+ }
+ emojiButton.setImageResource(R.drawable.ic_msg_panel_kb);
+ return;
+ }
+ if (emojiButton != null) {
+ emojiButton.setImageResource(R.drawable.ic_msg_panel_smiles);
+ }
+ if (emojiPopup != null) {
+ emojiPopup.dismiss();
+ }
+ if (sizeNotifierRelativeLayout != null) {
+ sizeNotifierRelativeLayout.post(new Runnable() {
+ public void run() {
+ if (sizeNotifierRelativeLayout != null) {
+ sizeNotifierRelativeLayout.setPadding(0, 0, 0, 0);
+ }
+ }
+ });
+ }
+ }
+
+ public void hideEmojiPopup() {
+ if (emojiPopup != null && emojiPopup.isShowing()) {
+ showEmojiPopup(false);
+ }
+ }
+
+ private void createEmojiPopup() {
+ if (parentActivity == null) {
+ return;
+ }
+ emojiView = new EmojiView(parentActivity);
+ emojiView.setListener(new EmojiView.Listener() {
+ public void onBackspace() {
+ messsageEditText.dispatchKeyEvent(new KeyEvent(0, 67));
+ }
+
+ public void onEmojiSelected(String paramAnonymousString) {
+ int i = messsageEditText.getSelectionEnd();
+ CharSequence localCharSequence = Emoji.replaceEmoji(paramAnonymousString, messsageEditText.getPaint().getFontMetricsInt(), AndroidUtilities.dp(20));
+ messsageEditText.setText(messsageEditText.getText().insert(i, localCharSequence));
+ int j = i + localCharSequence.length();
+ messsageEditText.setSelection(j, j);
+ }
+ });
+ emojiPopup = new PopupWindow(emojiView);
+ }
+
+ public void setDelegate(ChatActivityEnterViewDelegate delegate) {
+ this.delegate = delegate;
+ }
+
+ public void setDialogId(long id) {
+ dialog_id = id;
+ }
+
+ public void setFieldText(String text) {
+ ignoreTextChange = true;
+ messsageEditText.setText(text);
+ messsageEditText.setSelection(messsageEditText.getText().length());
+ ignoreTextChange = false;
+ }
+
+ public void setFieldFocused(boolean focus) {
+ if (messsageEditText == null) {
+ return;
+ }
+ if (focus) {
+ if (!messsageEditText.isFocused()) {
+ messsageEditText.postDelayed(new Runnable() {
+ @Override
+ public void run() {
+ if (messsageEditText != null) {
+ messsageEditText.requestFocus();
+ }
+ }
+ }, 600);
+ }
+ } else {
+ if (messsageEditText.isFocused() && !keyboardVisible) {
+ messsageEditText.clearFocus();
+ }
+ }
+ }
+
+ public boolean hasText() {
+ return messsageEditText != null && messsageEditText.length() > 0;
+ }
+
+ public String getFieldText() {
+ if (messsageEditText != null && messsageEditText.length() > 0) {
+ return messsageEditText.getText().toString();
+ }
+ return null;
+ }
+
+ public boolean isEmojiPopupShowing() {
+ return emojiPopup != null && emojiPopup.isShowing();
+ }
+
+ @Override
+ public void onSizeChanged(int height) {
+ Rect localRect = new Rect();
+ parentActivity.getWindow().getDecorView().getWindowVisibleDisplayFrame(localRect);
+
+ WindowManager manager = (WindowManager) ApplicationLoader.applicationContext.getSystemService(Activity.WINDOW_SERVICE);
+ if (manager == null || manager.getDefaultDisplay() == null) {
+ return;
+ }
+ int rotation = manager.getDefaultDisplay().getRotation();
+
+ if (height > AndroidUtilities.dp(50)) {
+ if (rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90) {
+ keyboardHeightLand = height;
+ ApplicationLoader.applicationContext.getSharedPreferences("emoji", 0).edit().putInt("kbd_height_land3", keyboardHeightLand).commit();
+ } else {
+ keyboardHeight = height;
+ ApplicationLoader.applicationContext.getSharedPreferences("emoji", 0).edit().putInt("kbd_height", keyboardHeight).commit();
+ }
+ }
+
+ if (emojiPopup != null && emojiPopup.isShowing()) {
+ WindowManager wm = (WindowManager) ApplicationLoader.applicationContext.getSystemService(Context.WINDOW_SERVICE);
+ final WindowManager.LayoutParams layoutParams = (WindowManager.LayoutParams)emojiPopup.getContentView().getLayoutParams();
+ layoutParams.width = sizeNotifierRelativeLayout.getWidth();
+ if (rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90) {
+ layoutParams.height = keyboardHeightLand;
+ } else {
+ layoutParams.height = keyboardHeight;
+ }
+ wm.updateViewLayout(emojiPopup.getContentView(), layoutParams);
+ if (!keyboardVisible) {
+ sizeNotifierRelativeLayout.post(new Runnable() {
+ @Override
+ public void run() {
+ sizeNotifierRelativeLayout.setPadding(0, 0, 0, layoutParams.height);
+ sizeNotifierRelativeLayout.requestLayout();
+ }
+ });
+ }
+ }
+
+ boolean oldValue = keyboardVisible;
+ keyboardVisible = height > 0;
+ if (keyboardVisible && sizeNotifierRelativeLayout.getPaddingBottom() > 0) {
+ showEmojiPopup(false);
+ } else if (!keyboardVisible && keyboardVisible != oldValue && emojiPopup != null && emojiPopup.isShowing()) {
+ showEmojiPopup(false);
+ }
+ }
+
+ @Override
+ public void didReceivedNotification(int id, Object... args) {
+ if (id == 999) {
+ if (emojiView != null) {
+ emojiView.invalidateViews();
+ }
+ } else if (id == MediaController.recordProgressChanged) {
+ Long time = (Long)args[0] / 1000;
+ String str = String.format("%02d:%02d", time / 60, time % 60);
+ if (lastTimeString == null || !lastTimeString.equals(str)) {
+ if (recordTimeText != null) {
+ recordTimeText.setText(str);
+ }
+ }
+ } else if (id == MessagesController.closeChats) {
+ if (messsageEditText != null && messsageEditText.isFocused()) {
+ AndroidUtilities.hideKeyboard(messsageEditText);
+ }
+ } else if (id == MediaController.recordStartError || id == MediaController.recordStopped) {
+ if (recordingAudio) {
+ recordingAudio = false;
+ updateAudioRecordIntefrace();
+ }
+ } else if (id == MediaController.recordStarted) {
+ if (!recordingAudio) {
+ recordingAudio = true;
+ updateAudioRecordIntefrace();
+ }
+ } else if (id == MediaController.audioDidSent) {
+ if (delegate != null) {
+ delegate.onMessageSend();
+ }
+ }
+ }
+}
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Views/ColorPickerView.java b/TMessagesProj/src/main/java/org/telegram/ui/Views/ColorPickerView.java
index 7386dea6..7135cbfb 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/Views/ColorPickerView.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/Views/ColorPickerView.java
@@ -29,7 +29,7 @@ import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
-import org.telegram.messenger.Utilities;
+import org.telegram.android.AndroidUtilities;
public class ColorPickerView extends View {
@@ -105,15 +105,15 @@ public class ColorPickerView extends View {
}
private void init(AttributeSet attrs, int defStyle) {
- mColorWheelThickness = Utilities.dp(8);
- mColorWheelRadius = Utilities.dp(124);
+ mColorWheelThickness = AndroidUtilities.dp(8);
+ mColorWheelRadius = AndroidUtilities.dp(124);
mPreferredColorWheelRadius = mColorWheelRadius;
- mColorCenterRadius = Utilities.dp(54);
+ mColorCenterRadius = AndroidUtilities.dp(54);
mPreferredColorCenterRadius = mColorCenterRadius;
- mColorCenterHaloRadius = Utilities.dp(60);
+ mColorCenterHaloRadius = AndroidUtilities.dp(60);
mPreferredColorCenterHaloRadius = mColorCenterHaloRadius;
- mColorPointerRadius = Utilities.dp(14);
- mColorPointerHaloRadius = Utilities.dp(18);
+ mColorPointerRadius = AndroidUtilities.dp(14);
+ mColorPointerHaloRadius = AndroidUtilities.dp(18);
mAngle = (float) (-Math.PI / 2);
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Views/EmojiView.java b/TMessagesProj/src/main/java/org/telegram/ui/Views/EmojiView.java
index cb162010..b8cb4817 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/Views/EmojiView.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/Views/EmojiView.java
@@ -24,10 +24,10 @@ import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
-import org.telegram.messenger.Emoji;
-import org.telegram.messenger.LocaleController;
+import org.telegram.android.AndroidUtilities;
+import org.telegram.android.Emoji;
+import org.telegram.android.LocaleController;
import org.telegram.messenger.R;
-import org.telegram.messenger.Utilities;
import java.util.ArrayList;
@@ -104,7 +104,7 @@ public class EmojiView extends LinearLayout {
setOrientation(LinearLayout.VERTICAL);
for (int i = 0; i < Emoji.data.length; i++) {
GridView gridView = new GridView(getContext());
- gridView.setColumnWidth(Utilities.dpf(45.0f));
+ gridView.setColumnWidth(AndroidUtilities.dpf(45.0f));
gridView.setNumColumns(-1);
views.add(gridView);
@@ -120,8 +120,8 @@ public class EmojiView extends LinearLayout {
tabs.setViewPager(pager);
tabs.setShouldExpand(true);
tabs.setIndicatorColor(0xff33b5e5);
- tabs.setIndicatorHeight(Utilities.dpf(2.0f));
- tabs.setUnderlineHeight(Utilities.dpf(2.0f));
+ tabs.setIndicatorHeight(AndroidUtilities.dpf(2.0f));
+ tabs.setUnderlineHeight(AndroidUtilities.dpf(2.0f));
tabs.setUnderlineColor(1711276032);
tabs.setTabBackground(0);
LinearLayout localLinearLayout = new LinearLayout(getContext());
@@ -138,7 +138,7 @@ public class EmojiView extends LinearLayout {
}
}
});
- localLinearLayout.addView(localImageView, new LinearLayout.LayoutParams(Utilities.dpf(61.0f), LayoutParams.MATCH_PARENT));
+ localLinearLayout.addView(localImageView, new LinearLayout.LayoutParams(AndroidUtilities.dpf(61.0f), LayoutParams.MATCH_PARENT));
recentsWrap = new FrameLayout(getContext());
recentsWrap.addView(views.get(0));
TextView localTextView = new TextView(getContext());
@@ -148,7 +148,7 @@ public class EmojiView extends LinearLayout {
localTextView.setGravity(17);
recentsWrap.addView(localTextView);
views.get(0).setEmptyView(localTextView);
- addView(localLinearLayout, new LinearLayout.LayoutParams(-1, Utilities.dpf(48.0f)));
+ addView(localLinearLayout, new LinearLayout.LayoutParams(-1, AndroidUtilities.dpf(48.0f)));
addView(pager);
loadRecents();
if (Emoji.data[0] == null || Emoji.data[0].length == 0) {
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Views/ImageReceiver.java b/TMessagesProj/src/main/java/org/telegram/ui/Views/ImageReceiver.java
index 77b73196..9b032264 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/Views/ImageReceiver.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/Views/ImageReceiver.java
@@ -13,7 +13,6 @@ import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
-import android.os.Build;
import android.view.View;
import org.telegram.messenger.TLRPC;
@@ -61,6 +60,9 @@ public class ImageReceiver {
last_size = 0;
currentImage = null;
FileLoader.getInstance().cancelLoadingForImageView(this);
+ if (parentView != null) {
+ parentView.invalidate();
+ }
return;
}
String key;
@@ -92,16 +94,13 @@ public class ImageReceiver {
if (img == null) {
isPlaceholder = true;
FileLoader.getInstance().loadImage(path, httpUrl, this, filter, true, size);
- if (parentView != null) {
- parentView.invalidate();
- }
} else {
selfSetting = true;
setImageBitmap(img, currentPath);
selfSetting = false;
- if (parentView != null) {
- parentView.invalidate();
- }
+ }
+ if (parentView != null) {
+ parentView.invalidate();
}
}
@@ -166,9 +165,7 @@ public class ImageReceiver {
}
if (canDelete) {
currentImage = null;
- if (Build.VERSION.SDK_INT < 11) {
- bitmap.recycle();
- }
+ bitmap.recycle();
}
} else {
currentImage = null;
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Views/MessageActionLayout.java b/TMessagesProj/src/main/java/org/telegram/ui/Views/MessageActionLayout.java
index d0e2e136..793b45f7 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/Views/MessageActionLayout.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/Views/MessageActionLayout.java
@@ -10,8 +10,8 @@ package org.telegram.ui.Views;
import android.widget.FrameLayout;
+import org.telegram.android.AndroidUtilities;
import org.telegram.messenger.R;
-import org.telegram.messenger.Utilities;
public class MessageActionLayout extends FrameLayout {
public TightTextView messageTextView;
@@ -31,7 +31,7 @@ public class MessageActionLayout extends FrameLayout {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
- setMeasuredDimension(messageTextView.linesMaxWidth + Utilities.dp(14), getMeasuredHeight());
+ setMeasuredDimension(messageTextView.linesMaxWidth + AndroidUtilities.dp(14), getMeasuredHeight());
}
@Override
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Views/NotificationView.java b/TMessagesProj/src/main/java/org/telegram/ui/Views/NotificationView.java
deleted file mode 100644
index 3fef3f2a..00000000
--- a/TMessagesProj/src/main/java/org/telegram/ui/Views/NotificationView.java
+++ /dev/null
@@ -1,326 +0,0 @@
-/*
- * This is the source code of Telegram for Android v. 1.3.2.
- * It is licensed under GNU GPL v. 2 or later.
- * You should have received a copy of the license in this archive (see LICENSE).
- *
- * Copyright Nikolai Kudashov, 2013.
- */
-
-package org.telegram.ui.Views;
-
-import android.content.Context;
-import android.graphics.PixelFormat;
-import android.util.AttributeSet;
-import android.util.TypedValue;
-import android.view.Gravity;
-import android.view.View;
-import android.view.ViewGroup;
-import android.view.WindowManager;
-import android.view.animation.Animation;
-import android.view.animation.AnimationUtils;
-import android.widget.FrameLayout;
-import android.widget.ImageView;
-import android.widget.LinearLayout;
-import android.widget.TextView;
-
-import org.telegram.messenger.LocaleController;
-import org.telegram.messenger.TLRPC;
-import org.telegram.messenger.FileLog;
-import org.telegram.messenger.MessagesController;
-import org.telegram.messenger.NotificationCenter;
-import org.telegram.messenger.R;
-import org.telegram.messenger.Utilities;
-import org.telegram.objects.MessageObject;
-import org.telegram.ui.ApplicationLoader;
-
-import java.util.Timer;
-import java.util.TimerTask;
-
-public class NotificationView extends LinearLayout {
- public BackupImageView avatarImage;
- public TextView nameTextView;
- public TextView messageTextView;
- public ImageView closeButton;
- public FrameLayout textLayout;
- private WindowManager.LayoutParams notificationLayoutParams;
- private ViewGroup notificationParentView;
- private boolean onScreen;
- private Animation animShow;
- private Animation animHide;
- private Timer hideTimer;
- private int currentChatId = 0;
- private int currentUserId = 0;
- private int currentEncId = 0;
- private boolean isVisible;
- private final Integer timerSync = 1;
-
- public NotificationView(Context context) {
- super(context);
- }
-
- public NotificationView(Context context, AttributeSet attrs) {
- super(context, attrs);
- }
-
- public NotificationView(Context context, AttributeSet attrs, int defStyle) {
- super(context, attrs, defStyle);
- }
-
- @Override
- protected void onFinishInflate() {
- super.onFinishInflate();
- avatarImage = (BackupImageView)findViewById(R.id.avatar_image);
- nameTextView = (TextView)findViewById(R.id.name_text_view);
- messageTextView = (TextView)findViewById(R.id.message_text_view);
- closeButton = (ImageView)findViewById(R.id.close_button);
- textLayout = (FrameLayout)findViewById(R.id.text_layout);
- closeButton.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- try {
- synchronized (timerSync) {
- if (hideTimer != null) {
- hideTimer.cancel();
- hideTimer = null;
- }
- }
- } catch (Exception e) {
- FileLog.e("tmessages", e);
- }
- hide(true);
- }
- });
-
- this.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- try {
- synchronized (timerSync) {
- if (hideTimer != null) {
- hideTimer.cancel();
- hideTimer = null;
- }
- }
- } catch (Exception e) {
- FileLog.e("tmessages", e);
- }
- hide(true);
-
- NotificationCenter.getInstance().postNotificationName(658, currentChatId, currentUserId, currentEncId);
- }
- });
-
- notificationParentView = new FrameLayout(getContext());
- notificationParentView.addView(this);
- notificationParentView.setFocusable(false);
- setFocusable(false);
- WindowManager wm = (WindowManager) ApplicationLoader.applicationContext.getSystemService(Context.WINDOW_SERVICE);
- notificationLayoutParams = new WindowManager.LayoutParams();
- notificationLayoutParams.height = 90;
- notificationLayoutParams.format = PixelFormat.TRANSLUCENT;
- notificationLayoutParams.width = WindowManager.LayoutParams.FILL_PARENT;
- 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;
- isVisible = false;
- wm.addView(notificationParentView, notificationLayoutParams);
- notificationParentView.setVisibility(View.INVISIBLE);
-
- animHide = AnimationUtils.loadAnimation(ApplicationLoader.applicationContext, R.anim.slide_up);
- animHide.setAnimationListener(new Animation.AnimationListener() {
- public void onAnimationStart(Animation animation) {
- onScreen = false;
- }
-
- public void onAnimationRepeat(Animation animation) {
-
- }
-
- public void onAnimationEnd(Animation animation) {
- setVisibility(GONE);
- WindowManager wm = (WindowManager)ApplicationLoader.applicationContext.getSystemService(Context.WINDOW_SERVICE);
- isVisible = false;
- notificationParentView.setVisibility(View.INVISIBLE);
- }
- });
-
- animShow = AnimationUtils.loadAnimation(ApplicationLoader.applicationContext, R.anim.slide_down);
- animShow.setAnimationListener(new Animation.AnimationListener() {
- public void onAnimationStart(Animation animation) {
- setVisibility(VISIBLE);
- onScreen = true;
- }
-
- public void onAnimationRepeat(Animation animation) {
-
- }
-
- public void onAnimationEnd(Animation animation) {
-
- }
- });
- }
-
- public void show(MessageObject object) {
- TLRPC.User user = MessagesController.getInstance().users.get(object.messageOwner.from_id);
- TLRPC.Chat chat = null;
- long dialog_id = object.messageOwner.dialog_id;
- if (object.messageOwner.to_id.chat_id != 0) {
- chat = MessagesController.getInstance().chats.get(object.messageOwner.to_id.chat_id);
- if (chat == null) {
- return;
- }
- }
- if (user == null) {
- return;
- }
- if (chat != null) {
- currentChatId = chat.id;
- currentUserId = 0;
- currentEncId = 0;
- nameTextView.setText(Utilities.formatName(user.first_name, user.last_name) + " @ " + chat.title);
- } else {
- int lower_id = (int)dialog_id;
- if (lower_id != 0 || dialog_id == 0) {
- currentUserId = user.id;
- currentEncId = 0;
- } else {
- currentUserId = 0;
- currentEncId = (int)(dialog_id >> 32);
- }
- currentChatId = 0;
- nameTextView.setText(Utilities.formatName(user.first_name, user.last_name));
- }
- nameTextView.setTextColor(Utilities.getColorForId(user.id));
- messageTextView.setText(object.messageText);
- TLRPC.FileLocation photo = null;
- if (user.photo != null) {
- photo = user.photo.photo_small;
- }
- avatarImage.setImage(photo, "50_50", Utilities.getUserAvatarForId(user.id));
-
- try {
- synchronized (timerSync) {
- if (hideTimer != null) {
- hideTimer.cancel();
- hideTimer = null;
- }
- }
- hideTimer = new Timer();
- hideTimer.schedule(new TimerTask() {
- @Override
- public void run() {
- Utilities.RunOnUIThread(new Runnable() {
- @Override
- public void run() {
- hide(true);
- }
- });
- try {
- synchronized (timerSync) {
- if (hideTimer != null) {
- hideTimer.cancel();
- hideTimer = null;
- }
- }
- } catch (Exception e) {
- FileLog.e("tmessages", e);
- }
- }
- }, 3000);
- } catch (Exception e) {
- FileLog.e("tmessages", e);
- }
-
- if (!onScreen) {
- WindowManager wm = (WindowManager)ApplicationLoader.applicationContext.getSystemService(Context.WINDOW_SERVICE);
- isVisible = true;
- notificationParentView.setVisibility(View.VISIBLE);
- startAnimation(animShow);
- }
- }
-
- public void hide(boolean animation) {
- if (onScreen) {
- if (animation) {
- startAnimation(animHide);
- } else {
- try {
- synchronized (timerSync) {
- if (hideTimer != null) {
- hideTimer.cancel();
- hideTimer = null;
- }
- }
- } catch (Exception e) {
- FileLog.e("tmessages", e);
- }
- onScreen = false;
- setVisibility(GONE);
- if (notificationParentView != null && notificationParentView.getParent() != null) {
- WindowManager wm = (WindowManager)ApplicationLoader.applicationContext.getSystemService(Context.WINDOW_SERVICE);
- isVisible = false;
- notificationParentView.setVisibility(View.INVISIBLE);
- }
- }
- }
- }
-
- public void destroy() {
- try {
- if (notificationParentView != null) {
- notificationParentView.removeView(this);
- try {
- if (notificationParentView.getParent() != null) {
- WindowManager wm = (WindowManager)ApplicationLoader.applicationContext.getSystemService(Context.WINDOW_SERVICE);
- wm.removeViewImmediate(notificationParentView);
- }
- } catch (Exception e) {
- FileLog.e("tmessages", e);
- }
- }
- notificationParentView = null;
- notificationLayoutParams = null;
- } catch (Exception e) {
- FileLog.e("tmessages", e);
- }
- }
-
- public void applyOrientationPaddings(boolean isLandscape, int height) {
- FrameLayout.LayoutParams params = (FrameLayout.LayoutParams)avatarImage.getLayoutParams();
- params.width = height;
- params.height = height;
- avatarImage.setLayoutParams(params);
- FrameLayout.LayoutParams params1 = (FrameLayout.LayoutParams)textLayout.getLayoutParams();
- if (isLandscape) {
- nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
- messageTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
- nameTextView.setPadding(0, Utilities.dp(2), 0, 0);
- messageTextView.setPadding(0, Utilities.dp(18), 0, 0);
- if (LocaleController.isRTL) {
- params1.setMargins(Utilities.dp(40), 0, height + Utilities.dp(6), 0);
- } else {
- params1.setMargins(height + Utilities.dp(6), 0, Utilities.dp(40), 0);
- }
- } else {
- nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15);
- messageTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15);
- nameTextView.setPadding(0, Utilities.dp(4), 0, 0);
- messageTextView.setPadding(0, Utilities.dp(24), 0, 0);
- if (LocaleController.isRTL) {
- params1.setMargins(Utilities.dp(40), 0, height + Utilities.dp(8), 0);
- } else {
- params1.setMargins(height + Utilities.dp(8), 0, Utilities.dp(40), 0);
- }
- }
- textLayout.setLayoutParams(params1);
-
- if (notificationParentView != null) {
- notificationLayoutParams.height = height;
- if (notificationParentView.getParent() != null) {
- WindowManager wm = (WindowManager) ApplicationLoader.applicationContext.getSystemService(Context.WINDOW_SERVICE);
- wm.updateViewLayout(notificationParentView, notificationLayoutParams);
- }
- }
- }
-}
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Views/ProgressView.java b/TMessagesProj/src/main/java/org/telegram/ui/Views/ProgressView.java
index cc6e9501..671c858f 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/Views/ProgressView.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/Views/ProgressView.java
@@ -11,7 +11,7 @@ package org.telegram.ui.Views;
import android.graphics.Canvas;
import android.graphics.Paint;
-import org.telegram.messenger.Utilities;
+import org.telegram.android.AndroidUtilities;
public class ProgressView {
private Paint innerPaint;
@@ -20,7 +20,7 @@ public class ProgressView {
public float currentProgress = 0;
public int width;
public int height;
- public float progressHeight = Utilities.dpf(2.0f);
+ public float progressHeight = AndroidUtilities.dpf(2.0f);
public ProgressView() {
innerPaint = new Paint();
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Views/SeekBar.java b/TMessagesProj/src/main/java/org/telegram/ui/Views/SeekBar.java
index 268e6173..37543fc2 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/Views/SeekBar.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/Views/SeekBar.java
@@ -14,8 +14,8 @@ import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.view.MotionEvent;
+import org.telegram.android.AndroidUtilities;
import org.telegram.messenger.R;
-import org.telegram.messenger.Utilities;
public class SeekBar {
@@ -121,8 +121,8 @@ public class SeekBar {
outer = outerPaint2;
}
int y = (height - thumbHeight) / 2;
- canvas.drawRect(thumbWidth / 2, height / 2 - Utilities.dp(1), width - thumbWidth / 2, height / 2 + Utilities.dp(1), inner);
- canvas.drawRect(thumbWidth / 2, height / 2 - Utilities.dp(1), thumbWidth / 2 + thumbX, height / 2 + Utilities.dp(1), outer);
+ canvas.drawRect(thumbWidth / 2, height / 2 - AndroidUtilities.dp(1), width - thumbWidth / 2, height / 2 + AndroidUtilities.dp(1), inner);
+ canvas.drawRect(thumbWidth / 2, height / 2 - AndroidUtilities.dp(1), thumbWidth / 2 + thumbX, height / 2 + AndroidUtilities.dp(1), outer);
thumb.setBounds(thumbX, y, thumbX + thumbWidth, y + thumbHeight);
thumb.draw(canvas);
}
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Views/SizeNotifierRelativeLayout.java b/TMessagesProj/src/main/java/org/telegram/ui/Views/SizeNotifierRelativeLayout.java
index 13b594bd..41667658 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/Views/SizeNotifierRelativeLayout.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/Views/SizeNotifierRelativeLayout.java
@@ -14,7 +14,7 @@ import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.widget.RelativeLayout;
-import org.telegram.messenger.Utilities;
+import org.telegram.android.AndroidUtilities;
public class SizeNotifierRelativeLayout extends RelativeLayout {
@@ -50,7 +50,7 @@ public class SizeNotifierRelativeLayout extends RelativeLayout {
protected void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed, l, t, r, b);
if (delegate != null) {
- int usableViewHeight = this.getRootView().getHeight() - Utilities.statusBarHeight;
+ int usableViewHeight = this.getRootView().getHeight() - AndroidUtilities.statusBarHeight;
this.getWindowVisibleDisplayFrame(rect);
int keyboardHeight = usableViewHeight - (rect.bottom - rect.top);
delegate.onSizeChanged(keyboardHeight);
@@ -60,15 +60,17 @@ public class SizeNotifierRelativeLayout extends RelativeLayout {
@Override
protected void onDraw(Canvas canvas) {
if (backgroundDrawable != null) {
- float scaleX = (float)Utilities.displaySize.x / (float)backgroundDrawable.getIntrinsicWidth();
- float scaleY = (float)Utilities.displaySize.y / (float)backgroundDrawable.getIntrinsicHeight();
+ float scaleX = (float)AndroidUtilities.displaySize.x / (float)backgroundDrawable.getIntrinsicWidth();
+ float scaleY = (float)AndroidUtilities.displaySize.y / (float)backgroundDrawable.getIntrinsicHeight();
float scale = scaleX < scaleY ? scaleY : scaleX;
int width = (int)Math.ceil(backgroundDrawable.getIntrinsicWidth() * scale);
int height = (int)Math.ceil(backgroundDrawable.getIntrinsicHeight() * scale);
- int x = (Utilities.displaySize.x - width) / 2;
- int y = (Utilities.displaySize.y - height) / 2;
+ int x = (AndroidUtilities.displaySize.x - width) / 2;
+ int y = (AndroidUtilities.displaySize.y - height) / 2;
backgroundDrawable.setBounds(x, y, x + width, y + height);
backgroundDrawable.draw(canvas);
+ } else {
+ super.onDraw(canvas);
}
}
}
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Views/TimerButton.java b/TMessagesProj/src/main/java/org/telegram/ui/Views/TimerButton.java
index 3bf8abd0..25257a58 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/Views/TimerButton.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/Views/TimerButton.java
@@ -19,9 +19,9 @@ import android.text.TextPaint;
import android.util.AttributeSet;
import android.view.View;
+import org.telegram.android.AndroidUtilities;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.R;
-import org.telegram.messenger.Utilities;
public class TimerButton extends View {
@@ -38,7 +38,7 @@ public class TimerButton extends View {
emptyTimerDrawable = getResources().getDrawable(R.drawable.header_timer);
timerDrawable = getResources().getDrawable(R.drawable.header_timer2);
timePaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
- timePaint.setTextSize(Utilities.dp(10));
+ timePaint.setTextSize(AndroidUtilities.dp(10));
timePaint.setColor(0xffd7e8f7);
timePaint.setTypeface(Typeface.DEFAULT_BOLD);
}
@@ -110,7 +110,7 @@ public class TimerButton extends View {
drawable.draw(canvas);
if (time != 0 && timeLayout != null) {
- canvas.translate((width - timeWidth) / 2, (height - timeHeight) / 2 + Utilities.dp(1));
+ canvas.translate((width - timeWidth) / 2, (height - timeHeight) / 2 + AndroidUtilities.dp(1));
timeLayout.draw(canvas);
}
}
diff --git a/TMessagesProj/src/main/res/layout-ar/user_profile_phone_layout.xml b/TMessagesProj/src/main/res/layout-ar/user_profile_phone_layout.xml
index 86fc6f1b..544b7294 100644
--- a/TMessagesProj/src/main/res/layout-ar/user_profile_phone_layout.xml
+++ b/TMessagesProj/src/main/res/layout-ar/user_profile_phone_layout.xml
@@ -22,6 +22,17 @@
android:layout_gravity="left|center_vertical"
android:layout_marginLeft="48dp"/>
+
+
+
+
+
+
\ No newline at end of file
diff --git a/TMessagesProj/src/main/res/layout/popup_notification_layout.xml b/TMessagesProj/src/main/res/layout/popup_notification_layout.xml
new file mode 100644
index 00000000..4bc0597a
--- /dev/null
+++ b/TMessagesProj/src/main/res/layout/popup_notification_layout.xml
@@ -0,0 +1,187 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/TMessagesProj/src/main/res/layout/user_profile_phone_layout.xml b/TMessagesProj/src/main/res/layout/user_profile_phone_layout.xml
index ff654495..3b8b7559 100644
--- a/TMessagesProj/src/main/res/layout/user_profile_phone_layout.xml
+++ b/TMessagesProj/src/main/res/layout/user_profile_phone_layout.xml
@@ -30,6 +30,17 @@
android:textAllCaps="true"
android:layout_gravity="bottom"/>
+
+
الاسم الأول
اسم العائلة
LED Color
+ Popup Notification
+ No popup
+ Only when screen "on"
+ Only when screen "off"
+ Always show popup
لا توجد وسائط بعد
diff --git a/TMessagesProj/src/main/res/values-de/strings.xml b/TMessagesProj/src/main/res/values-de/strings.xml
index 16e4137e..1f6fdc2c 100644
--- a/TMessagesProj/src/main/res/values-de/strings.xml
+++ b/TMessagesProj/src/main/res/values-de/strings.xml
@@ -274,6 +274,11 @@
Vorname
Nachname
LED Farbe
+ Popup Notification
+ No popup
+ Only when screen "on"
+ Only when screen "off"
+ Always show popup
Noch keine geteilten Medien vorhanden
diff --git a/TMessagesProj/src/main/res/values-es/strings.xml b/TMessagesProj/src/main/res/values-es/strings.xml
index 0b101766..913d7583 100644
--- a/TMessagesProj/src/main/res/values-es/strings.xml
+++ b/TMessagesProj/src/main/res/values-es/strings.xml
@@ -274,6 +274,11 @@
Nombre
Apellido
Color del LED
+ Popup Notification
+ No popup
+ Only when screen "on"
+ Only when screen "off"
+ Always show popup
No hay fotos ni vídeos compartidos aún
diff --git a/TMessagesProj/src/main/res/values-it/strings.xml b/TMessagesProj/src/main/res/values-it/strings.xml
index fcb8cf81..8d1f05d6 100644
--- a/TMessagesProj/src/main/res/values-it/strings.xml
+++ b/TMessagesProj/src/main/res/values-it/strings.xml
@@ -274,6 +274,11 @@
Nome
Cognome
LED Color
+ Popup Notification
+ No popup
+ Only when screen "on"
+ Only when screen "off"
+ Always show popup
Nessun media condiviso
diff --git a/TMessagesProj/src/main/res/values-nl/strings.xml b/TMessagesProj/src/main/res/values-nl/strings.xml
index abe73183..1e027d64 100644
--- a/TMessagesProj/src/main/res/values-nl/strings.xml
+++ b/TMessagesProj/src/main/res/values-nl/strings.xml
@@ -274,6 +274,11 @@
Voornaam
Achternaam
LED Color
+ Popup Notification
+ No popup
+ Only when screen "on"
+ Only when screen "off"
+ Always show popup
Nog geen media gedeeld
diff --git a/TMessagesProj/src/main/res/values-pt-rBR/strings.xml b/TMessagesProj/src/main/res/values-pt-rBR/strings.xml
index 40fcdb90..40f1347a 100644
--- a/TMessagesProj/src/main/res/values-pt-rBR/strings.xml
+++ b/TMessagesProj/src/main/res/values-pt-rBR/strings.xml
@@ -274,6 +274,11 @@
Primeiro nome
Sobrenome
LED Color
+ Popup Notification
+ No popup
+ Only when screen "on"
+ Only when screen "off"
+ Always show popup
Ainda não há mídia compartilhada
diff --git a/TMessagesProj/src/main/res/values-pt-rPT/strings.xml b/TMessagesProj/src/main/res/values-pt-rPT/strings.xml
index 110e2c47..e7739fea 100644
--- a/TMessagesProj/src/main/res/values-pt-rPT/strings.xml
+++ b/TMessagesProj/src/main/res/values-pt-rPT/strings.xml
@@ -274,6 +274,11 @@
Nome
Apelidos
LED Color
+ Popup Notification
+ No popup
+ Only when screen "on"
+ Only when screen "off"
+ Always show popup
Ainda não há multimédia partilhado
diff --git a/TMessagesProj/src/main/res/values/strings.xml b/TMessagesProj/src/main/res/values/strings.xml
index 8030a4c6..e8955b69 100644
--- a/TMessagesProj/src/main/res/values/strings.xml
+++ b/TMessagesProj/src/main/res/values/strings.xml
@@ -274,6 +274,11 @@
First name
Last name
LED Color
+ Popup Notification
+ No popup
+ Only when screen "on"
+ Only when screen "off"
+ Always show popup
No shared media yet
diff --git a/TMessagesProj/src/main/res/values/styles.xml b/TMessagesProj/src/main/res/values/styles.xml
index 2f71635a..247018e3 100644
--- a/TMessagesProj/src/main/res/values/styles.xml
+++ b/TMessagesProj/src/main/res/values/styles.xml
@@ -7,13 +7,14 @@
- @style/ActionBar.Transparent.TMessages.Start
- @android:color/white
- @android:color/white
- - @drawable/shadow
+ - @null
+
+