1
0
mirror of https://github.com/MGislv/NekoX.git synced 2024-06-30 10:14:04 +00:00

Perfect forward secrecy in secret chats, phone change, telegram.me links support

This commit is contained in:
DrKLO 2014-12-01 09:56:31 -08:00
parent 95de265e1a
commit 8233e89daa
142 changed files with 4842 additions and 2334 deletions

View File

@ -80,7 +80,7 @@ android {
defaultConfig {
minSdkVersion 8
targetSdkVersion 21
versionCode 397
versionName "2.0.5"
versionCode 403
versionName "2.1.0"
}
}

View File

@ -23,7 +23,7 @@
android:icon="@drawable/ic_launcher"
android:label="@string/AppName"
android:theme="@style/Theme.TMessages.Start"
android:name="org.telegram.ui.ApplicationLoader"
android:name=".ApplicationLoader"
android:hardwareAccelerated="true"
android:largeHeap="true">

View File

@ -8,7 +8,7 @@
android:icon="@drawable/ic_launcher"
android:label="@string/AppName"
android:theme="@style/Theme.TMessages.Start"
android:name="org.telegram.ui.ApplicationLoader"
android:name=".ApplicationLoader"
android:hardwareAccelerated="true"
android:largeHeap="true">

View File

@ -23,7 +23,7 @@
android:icon="@drawable/ic_launcher"
android:label="@string/AppName"
android:theme="@style/Theme.TMessages.Start"
android:name="org.telegram.ui.ApplicationLoader"
android:name=".ApplicationLoader"
android:hardwareAccelerated="true"
android:largeHeap="true">

View File

@ -2,7 +2,7 @@ LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_PRELINK_MODULE := false
LOCAL_MODULE := tmessages.3
LOCAL_MODULE := tmessages.4
LOCAL_CFLAGS := -w -std=gnu99 -O2 -DNULL=0 -DSOCKLEN_T=socklen_t -DLOCALE_NOT_USED -D_LARGEFILE_SOURCE=1 -D_FILE_OFFSET_BITS=64
LOCAL_CFLAGS += -Drestrict='' -D__EMX__ -DOPUS_BUILD -DFIXED_POINT -DUSE_ALLOCA -DHAVE_LRINT -DHAVE_LRINTF -fno-math-errno
LOCAL_CFLAGS += -DANDROID_NDK -DDISABLE_IMPORTGL -fno-strict-aliasing -fprefetch-loop-arrays -DAVOID_TABLES -DANDROID_TILE_BASED_DECODE -DANDROID_ARMV6_IDCT -DHAVE_STRCHRNUL=0

View File

@ -589,7 +589,7 @@ static jint open(GifFileType *GifFileIn, int Error, int startPos, JNIEnv *env, j
return (jint)(Error == 0 ? info : NULL);
}
JNIEXPORT jlong JNICALL Java_org_telegram_ui_Views_GifDrawable_getAllocationByteCount(JNIEnv *env, jclass class, jobject gifInfo) {
JNIEXPORT jlong JNICALL Java_org_telegram_ui_Components_GifDrawable_getAllocationByteCount(JNIEnv *env, jclass class, jobject gifInfo) {
GifInfo *info = (GifInfo *)gifInfo;
if (info == NULL) {
return 0;
@ -602,7 +602,7 @@ JNIEXPORT jlong JNICALL Java_org_telegram_ui_Views_GifDrawable_getAllocationByte
return sum;
}
JNIEXPORT void JNICALL Java_org_telegram_ui_Views_GifDrawable_reset(JNIEnv *env, jclass class, jobject gifInfo) {
JNIEXPORT void JNICALL Java_org_telegram_ui_Components_GifDrawable_reset(JNIEnv *env, jclass class, jobject gifInfo) {
GifInfo *info = (GifInfo *)gifInfo;
if (info == NULL) {
return;
@ -610,7 +610,7 @@ JNIEXPORT void JNICALL Java_org_telegram_ui_Views_GifDrawable_reset(JNIEnv *env,
reset(info);
}
JNIEXPORT void JNICALL Java_org_telegram_ui_Views_GifDrawable_setSpeedFactor(JNIEnv *env, jclass class, jobject gifInfo, jfloat factor) {
JNIEXPORT void JNICALL Java_org_telegram_ui_Components_GifDrawable_setSpeedFactor(JNIEnv *env, jclass class, jobject gifInfo, jfloat factor) {
GifInfo *info = (GifInfo *)gifInfo;
if (info == NULL) {
return;
@ -618,7 +618,7 @@ JNIEXPORT void JNICALL Java_org_telegram_ui_Views_GifDrawable_setSpeedFactor(JNI
info->speedFactor = factor;
}
JNIEXPORT void JNICALL Java_org_telegram_ui_Views_GifDrawable_seekToTime(JNIEnv *env, jclass class, jobject gifInfo, jint desiredPos, jintArray jPixels) {
JNIEXPORT void JNICALL Java_org_telegram_ui_Components_GifDrawable_seekToTime(JNIEnv *env, jclass class, jobject gifInfo, jint desiredPos, jintArray jPixels) {
GifInfo *info = (GifInfo *)gifInfo;
if (info == NULL || jPixels == NULL) {
return;
@ -665,7 +665,7 @@ JNIEXPORT void JNICALL Java_org_telegram_ui_Views_GifDrawable_seekToTime(JNIEnv
}
}
JNIEXPORT void JNICALL Java_org_telegram_ui_Views_GifDrawable_seekToFrame(JNIEnv *env, jclass class, jobject gifInfo, jint desiredIdx, jintArray jPixels) {
JNIEXPORT void JNICALL Java_org_telegram_ui_Components_GifDrawable_seekToFrame(JNIEnv *env, jclass class, jobject gifInfo, jint desiredIdx, jintArray jPixels) {
GifInfo *info = (GifInfo *)gifInfo;
if (info == NULL|| jPixels==NULL) {
return;
@ -701,7 +701,7 @@ JNIEXPORT void JNICALL Java_org_telegram_ui_Views_GifDrawable_seekToFrame(JNIEnv
}
}
JNIEXPORT void JNICALL Java_org_telegram_ui_Views_GifDrawable_renderFrame(JNIEnv *env, jclass class, jintArray jPixels, jobject gifInfo, jintArray metaData) {
JNIEXPORT void JNICALL Java_org_telegram_ui_Components_GifDrawable_renderFrame(JNIEnv *env, jclass class, jintArray jPixels, jobject gifInfo, jintArray metaData) {
GifInfo *info = (GifInfo *)gifInfo;
if (info == NULL || jPixels == NULL) {
return;
@ -752,7 +752,7 @@ JNIEXPORT void JNICALL Java_org_telegram_ui_Views_GifDrawable_renderFrame(JNIEnv
(*env)->ReleaseIntArrayElements(env, metaData, rawMetaData, 0);
}
JNIEXPORT void JNICALL Java_org_telegram_ui_Views_GifDrawable_free(JNIEnv *env, jclass class, jobject gifInfo) {
JNIEXPORT void JNICALL Java_org_telegram_ui_Components_GifDrawable_free(JNIEnv *env, jclass class, jobject gifInfo) {
if (gifInfo == NULL) {
return;
}
@ -765,7 +765,7 @@ JNIEXPORT void JNICALL Java_org_telegram_ui_Views_GifDrawable_free(JNIEnv *env,
cleanUp(info);
}
JNIEXPORT jstring JNICALL Java_org_telegram_ui_Views_GifDrawable_getComment(JNIEnv *env, jclass class, jobject gifInfo) {
JNIEXPORT jstring JNICALL Java_org_telegram_ui_Components_GifDrawable_getComment(JNIEnv *env, jclass class, jobject gifInfo) {
if (gifInfo == NULL) {
return NULL;
}
@ -773,14 +773,14 @@ JNIEXPORT jstring JNICALL Java_org_telegram_ui_Views_GifDrawable_getComment(JNIE
return (*env)->NewStringUTF(env, info->comment);
}
JNIEXPORT jint JNICALL Java_org_telegram_ui_Views_GifDrawable_getLoopCount(JNIEnv *env, jclass class, jobject gifInfo) {
JNIEXPORT jint JNICALL Java_org_telegram_ui_Components_GifDrawable_getLoopCount(JNIEnv *env, jclass class, jobject gifInfo) {
if (gifInfo == NULL) {
return 0;
}
return ((GifInfo *)gifInfo)->loopCount;
}
JNIEXPORT jint JNICALL Java_org_telegram_ui_Views_GifDrawable_getDuration(JNIEnv *env, jclass class, jobject gifInfo) {
JNIEXPORT jint JNICALL Java_org_telegram_ui_Components_GifDrawable_getDuration(JNIEnv *env, jclass class, jobject gifInfo) {
GifInfo *info = (GifInfo *)gifInfo;
if (info == NULL) {
return 0;
@ -793,7 +793,7 @@ JNIEXPORT jint JNICALL Java_org_telegram_ui_Views_GifDrawable_getDuration(JNIEnv
return sum;
}
JNIEXPORT jint JNICALL Java_org_telegram_ui_Views_GifDrawable_getCurrentPosition(JNIEnv *env, jclass class, jobject gifInfo) {
JNIEXPORT jint JNICALL Java_org_telegram_ui_Components_GifDrawable_getCurrentPosition(JNIEnv *env, jclass class, jobject gifInfo) {
GifInfo *info = (GifInfo *)gifInfo;
if (info == NULL) {
return 0;
@ -811,7 +811,7 @@ JNIEXPORT jint JNICALL Java_org_telegram_ui_Views_GifDrawable_getCurrentPosition
return (int) (sum + remainder);
}
JNIEXPORT void JNICALL Java_org_telegram_ui_Views_GifDrawable_saveRemainder(JNIEnv *env, jclass class, jobject gifInfo) {
JNIEXPORT void JNICALL Java_org_telegram_ui_Components_GifDrawable_saveRemainder(JNIEnv *env, jclass class, jobject gifInfo) {
GifInfo *info = (GifInfo *)gifInfo;
if (info == NULL) {
return;
@ -819,7 +819,7 @@ JNIEXPORT void JNICALL Java_org_telegram_ui_Views_GifDrawable_saveRemainder(JNIE
info->lastFrameReaminder = getRealTime() - info->nextStartTime;
}
JNIEXPORT void JNICALL Java_org_telegram_ui_Views_GifDrawable_restoreRemainder(JNIEnv *env, jclass class, jobject gifInfo) {
JNIEXPORT void JNICALL Java_org_telegram_ui_Components_GifDrawable_restoreRemainder(JNIEnv *env, jclass class, jobject gifInfo) {
GifInfo *info = (GifInfo *)gifInfo;
if (info == NULL || info->lastFrameReaminder == ULONG_MAX) {
return;
@ -828,7 +828,7 @@ JNIEXPORT void JNICALL Java_org_telegram_ui_Views_GifDrawable_restoreRemainder(J
info->lastFrameReaminder = ULONG_MAX;
}
JNIEXPORT jint JNICALL Java_org_telegram_ui_Views_GifDrawable_openFile(JNIEnv *env, jclass class, jintArray metaData, jstring jfname) {
JNIEXPORT jint JNICALL Java_org_telegram_ui_Components_GifDrawable_openFile(JNIEnv *env, jclass class, jintArray metaData, jstring jfname) {
if (jfname == NULL) {
setMetaData(0, 0, 0, D_GIF_ERR_OPEN_FAILED, env, metaData);
return (jint) NULL;

View File

@ -4,10 +4,10 @@
android:installLocation="auto">
<supports-screens android:anyDensity="true"
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:normalScreens="true"
android:resizeable="true"
android:smallScreens="true"
android:xlargeScreens="true"/>
<uses-feature android:glEsVersion="0x00020000" android:required="false"/>
@ -41,20 +41,20 @@
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:name=".ApplicationLoader"
android:allowBackup="false"
android:hardwareAccelerated="true"
android:icon="@drawable/ic_launcher"
android:label="@string/AppName"
android:theme="@style/Theme.TMessages.Start"
android:name="org.telegram.ui.ApplicationLoader"
android:hardwareAccelerated="true"
android:largeHeap="true">
android:largeHeap="true"
android:theme="@style/Theme.TMessages.Start">
<activity
android:name="org.telegram.ui.LaunchActivity"
android:windowSoftInputMode="adjustPan"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:hardwareAccelerated="true"
android:launchMode="singleTask"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
android:windowSoftInputMode="adjustPan">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
@ -95,6 +95,19 @@
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="vnd.android.cursor.item/vnd.org.telegram.messenger.android.profile"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:host="telegram.me" android:scheme="http" />
<data android:host="telegram.me" android:scheme="https" />
</intent-filter>
<intent-filter android:icon="@drawable/ic_launcher" android:priority="1">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="tg" />
</intent-filter>
</activity>
<activity
android:name="org.telegram.ui.IntroActivity"
@ -105,9 +118,9 @@
android:configChanges="keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:excludeFromRecents="true"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize|stateHidden"
android:taskAffinity=""
android:theme="@style/Theme.TMessages.PopupNotification">
android:theme="@style/Theme.TMessages.PopupNotification"
android:windowSoftInputMode="adjustResize|stateHidden">
</activity>
<receiver android:name="org.telegram.android.SmsListener">
@ -116,8 +129,7 @@
</intent-filter>
</receiver>
<service android:name="org.telegram.android.AuthenticatorService"
android:exported="true">
<service android:name="org.telegram.android.AuthenticatorService" android:exported="true">
<intent-filter>
<action android:name="android.accounts.AccountAuthenticator"/>
</intent-filter>
@ -125,8 +137,7 @@
android:resource="@xml/auth"/>
</service>
<service android:name="org.telegram.android.ContactsSyncAdapterService"
android:exported="true">
<service android:name="org.telegram.android.ContactsSyncAdapterService" android:exported="true">
<intent-filter>
<action android:name="android.content.SyncAdapter" />
</intent-filter>

View File

@ -24,7 +24,7 @@
package org.telegram.PhoneFormat;
import org.telegram.ui.ApplicationLoader;
import org.telegram.messenger.ApplicationLoader;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;

View File

@ -9,7 +9,7 @@
package org.telegram.SQLite;
import org.telegram.messenger.FileLog;
import org.telegram.ui.ApplicationLoader;
import org.telegram.messenger.ApplicationLoader;
public class SQLiteDatabase {
private final int sqliteHandle;

View File

@ -20,6 +20,9 @@ import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Environment;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.util.StateSet;
import android.view.Display;
import android.view.Surface;
@ -35,12 +38,14 @@ import android.widget.TextView;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.R;
import org.telegram.messenger.TLRPC;
import org.telegram.ui.ApplicationLoader;
import org.telegram.ui.Views.NumberPicker;
import org.telegram.messenger.ApplicationLoader;
import org.telegram.ui.Components.NumberPicker;
import org.telegram.ui.Components.TypefaceSpan;
import java.io.File;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Hashtable;
public class AndroidUtilities {
@ -389,7 +394,7 @@ public class AndroidUtilities {
encryptedChat.ttl = 60 * 60 * 24 * 7;
}
if (oldValue != encryptedChat.ttl) {
SendMessagesHelper.getInstance().sendTTLMessage(encryptedChat, null);
SecretChatHelper.getInstance().sendTTLMessage(encryptedChat, null);
MessagesStorage.getInstance().updateEncryptedChatTTL(encryptedChat);
}
}
@ -502,4 +507,21 @@ public class AndroidUtilities {
}
}
}
public static Spannable replaceBold(String str) {
int start;
ArrayList<Integer> bolds = new ArrayList<Integer>();
while ((start = str.indexOf("<b>")) != -1) {
int end = str.indexOf("</b>") - 3;
str = str.replaceFirst("<b>", "").replaceFirst("</b>", "");
bolds.add(start);
bolds.add(end);
}
SpannableStringBuilder stringBuilder = new SpannableStringBuilder(str);
for (int a = 0; a < bolds.size() / 2; a++) {
TypefaceSpan span = new TypefaceSpan(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
stringBuilder.setSpan(span, bolds.get(a * 2), bolds.get(a * 2 + 1), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
}
return stringBuilder;
}
}

View File

@ -12,7 +12,7 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import org.telegram.ui.ApplicationLoader;
import org.telegram.messenger.ApplicationLoader;
public class AppStartReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {

View File

@ -31,7 +31,7 @@ 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 org.telegram.messenger.ApplicationLoader;
import java.util.ArrayList;
import java.util.Collections;

View File

@ -29,7 +29,7 @@ import android.widget.TextView;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.Utilities;
import org.telegram.ui.ApplicationLoader;
import org.telegram.messenger.ApplicationLoader;
public class Emoji {
private static HashMap<Long, DrawableInfo> rects = new HashMap<Long, DrawableInfo>();

View File

@ -16,7 +16,7 @@ import android.content.Intent;
import org.json.JSONObject;
import org.telegram.messenger.ConnectionsManager;
import org.telegram.messenger.FileLog;
import org.telegram.ui.ApplicationLoader;
import org.telegram.messenger.ApplicationLoader;
public class GcmBroadcastReceiver extends BroadcastReceiver {

View File

@ -31,7 +31,7 @@ import org.telegram.messenger.FileLog;
import org.telegram.messenger.TLRPC;
import org.telegram.messenger.UserConfig;
import org.telegram.messenger.Utilities;
import org.telegram.ui.ApplicationLoader;
import org.telegram.messenger.ApplicationLoader;
import java.io.ByteArrayOutputStream;
import java.io.File;

View File

@ -24,7 +24,7 @@ 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.telegram.messenger.ApplicationLoader;
import org.xmlpull.v1.XmlPullParser;
import java.io.File;

View File

@ -52,9 +52,9 @@ import org.telegram.messenger.R;
import org.telegram.messenger.TLRPC;
import org.telegram.messenger.UserConfig;
import org.telegram.messenger.Utilities;
import org.telegram.ui.ApplicationLoader;
import org.telegram.messenger.ApplicationLoader;
import org.telegram.ui.Cells.ChatMediaCell;
import org.telegram.ui.Views.GifDrawable;
import org.telegram.ui.Components.GifDrawable;
import java.io.File;
import java.io.FileInputStream;
@ -809,7 +809,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
}
}
if (send) {
SendMessagesHelper.getInstance().sendScreenshotMessage(lastSecretChat, lastSecretChatVisibleMessages, null);
SecretChatHelper.getInstance().sendScreenshotMessage(lastSecretChat, lastSecretChatVisibleMessages, null);
}
}

View File

@ -25,7 +25,7 @@ import org.telegram.messenger.FileLog;
import org.telegram.messenger.TLRPC;
import org.telegram.messenger.R;
import org.telegram.messenger.UserConfig;
import org.telegram.ui.Views.URLSpanNoUnderline;
import org.telegram.ui.Components.URLSpanNoUnderline;
import java.util.AbstractMap;
import java.util.ArrayList;
@ -452,6 +452,60 @@ public class MessageObject {
return "";
}
private boolean containsUrls(String message) {
if (message == null || message.length() < 3 || message.length() > 1024 * 20) {
return false;
}
boolean containsSomething = false;
int length = message.length();
int digitsInRow = 0;
int schemeSequence = 0;
int dotSequence = 0;
char lastChar = 0;
for (int i = 0; i < length; i++) {
char c = message.charAt(i);
if (c >= '0' && c <= '9') {
digitsInRow++;
if (digitsInRow >= 6) {
return true;
}
schemeSequence = 0;
dotSequence = 0;
} else if (c == ':') {
if (schemeSequence == 0) {
schemeSequence = 1;
} else {
schemeSequence = 0;
}
} else if (c == '/') {
if (schemeSequence == 2) {
return true;
}
if (schemeSequence == 1) {
schemeSequence++;
} else {
schemeSequence = 0;
}
} else if (c == '.') {
if (dotSequence == 0 && lastChar != ' ') {
dotSequence++;
} else {
dotSequence = 0;
}
} else if (c != ' ' && lastChar == '.' && dotSequence == 1) {
return true;
}
lastChar = c;
}
return false;
}
private void generateLayout() {
if (type != 0 || messageOwner.to_id == null || messageText == null || messageText.length() == 0) {
return;
@ -459,11 +513,11 @@ public class MessageObject {
textLayoutBlocks = new ArrayList<TextLayoutBlock>();
if (messageText instanceof Spannable) {
if (messageOwner.message != null && messageOwner.message.contains(".") && (messageOwner.message.contains(".com") || messageOwner.message.contains("http") || messageOwner.message.contains(".ru") || messageOwner.message.contains(".org") || messageOwner.message.contains(".net"))) {
Linkify.addLinks((Spannable)messageText, Linkify.WEB_URLS);
} else if (messageText.length() < 100) {
Linkify.addLinks((Spannable)messageText, Linkify.WEB_URLS | Linkify.EMAIL_ADDRESSES | Linkify.PHONE_NUMBERS);
if (messageText instanceof Spannable && containsUrls(messageOwner.message)) {
if (messageOwner.message.length() < 100) {
Linkify.addLinks((Spannable) messageText, Linkify.WEB_URLS | Linkify.PHONE_NUMBERS);
} else {
Linkify.addLinks((Spannable) messageText, Linkify.WEB_URLS);
}
}
@ -576,10 +630,7 @@ public class MessageObject {
}
if (lineWidth > maxWidth + 100) {
int start = block.textLayout.getLineStart(n);
int end = block.textLayout.getLineEnd(n);
CharSequence text = block.textLayout.getText().subSequence(start, end);
continue;
lineWidth = maxWidth;
}
try {

View File

@ -28,7 +28,7 @@ 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 org.telegram.messenger.ApplicationLoader;
import java.io.File;
import java.util.ArrayList;
@ -104,7 +104,7 @@ public class MessagesStorage {
database.executeFast("CREATE TABLE users(uid INTEGER PRIMARY KEY, name TEXT, status INTEGER, data BLOB)").stepThis().dispose();
database.executeFast("CREATE TABLE messages(mid INTEGER PRIMARY KEY, uid INTEGER, read_state INTEGER, send_state INTEGER, date INTEGER, data BLOB, out INTEGER, ttl INTEGER, media INTEGER)").stepThis().dispose();
database.executeFast("CREATE TABLE chats(uid INTEGER PRIMARY KEY, name TEXT, data BLOB)").stepThis().dispose();
database.executeFast("CREATE TABLE enc_chats(uid INTEGER PRIMARY KEY, user INTEGER, name TEXT, data BLOB, g BLOB, authkey BLOB, ttl INTEGER, layer INTEGER, seq_in INTEGER, seq_out INTEGER)").stepThis().dispose();
database.executeFast("CREATE TABLE enc_chats(uid INTEGER PRIMARY KEY, user INTEGER, name TEXT, data BLOB, g BLOB, authkey BLOB, ttl INTEGER, layer INTEGER, seq_in INTEGER, seq_out INTEGER, use_count INTEGER, exchange_id INTEGER, key_date INTEGER, fprint INTEGER, fauthkey BLOB, khash BLOB)").stepThis().dispose();
database.executeFast("CREATE TABLE dialogs(did INTEGER PRIMARY KEY, date INTEGER, unread_count INTEGER, last_mid INTEGER)").stepThis().dispose();
database.executeFast("CREATE TABLE chat_settings(uid INTEGER PRIMARY KEY, participants BLOB)").stepThis().dispose();
database.executeFast("CREATE TABLE contacts(uid INTEGER PRIMARY KEY, mutual INTEGER)").stepThis().dispose();
@ -156,7 +156,7 @@ public class MessagesStorage {
database.executeFast("CREATE INDEX IF NOT EXISTS seq_idx_messages_seq ON messages_seq(seq_in, seq_out);").stepThis().dispose();
database.executeFast("PRAGMA user_version = 7").stepThis().dispose();
database.executeFast("PRAGMA user_version = 10").stepThis().dispose();
} else {
try {
SQLiteCursor cursor = database.queryFinalized("SELECT seq, pts, date, qts, lsv, sg, pbytes FROM params WHERE id = 1");
@ -188,7 +188,7 @@ public class MessagesStorage {
}
int version = database.executeInt("PRAGMA user_version");
if (version < 9) {
if (version < 10) {
updateDbToLastVersion(version);
}
}
@ -329,6 +329,16 @@ public class MessagesStorage {
database.executeFast("PRAGMA user_version = 9").stepThis().dispose();
version = 9;
}*/
if ((version == 7 || version == 8 || version == 9) && version < 10) {
database.executeFast("ALTER TABLE enc_chats ADD COLUMN use_count INTEGER default 0").stepThis().dispose();
database.executeFast("ALTER TABLE enc_chats ADD COLUMN exchange_id INTEGER default 0").stepThis().dispose();
database.executeFast("ALTER TABLE enc_chats ADD COLUMN key_date INTEGER default 0").stepThis().dispose();
database.executeFast("ALTER TABLE enc_chats ADD COLUMN fprint INTEGER default 0").stepThis().dispose();
database.executeFast("ALTER TABLE enc_chats ADD COLUMN fauthkey BLOB default NULL").stepThis().dispose();
database.executeFast("ALTER TABLE enc_chats ADD COLUMN khash BLOB default NULL").stepThis().dispose();
database.executeFast("PRAGMA user_version = 10").stepThis().dispose();
version = 10;
}
} catch (Exception e) {
FileLog.e("tmessages", e);
}
@ -1329,9 +1339,6 @@ public class MessagesStorage {
StringBuilder uids = new StringBuilder();
while (cursor.next()) {
int user_id = cursor.intValue(0);
if (user_id == UserConfig.getClientUserId()) {
continue;
}
TLRPC.TL_contact contact = new TLRPC.TL_contact();
contact.user_id = user_id;
contact.mutual = cursor.intValue(1) == 1;
@ -2008,10 +2015,11 @@ public class MessagesStorage {
public void run() {
SQLitePreparedStatement state = null;
try {
state = database.executeFast("UPDATE enc_chats SET seq_in = ?, seq_out = ? WHERE uid = ?");
state = database.executeFast("UPDATE enc_chats SET seq_in = ?, seq_out = ?, use_count = ? WHERE uid = ?");
state.bindInteger(1, chat.seq_in);
state.bindInteger(2, chat.seq_out);
state.bindInteger(3, chat.id);
state.bindInteger(3, (int)chat.key_use_count_in << 16 | chat.key_use_count_out);
state.bindInteger(4, chat.id);
state.step();
} catch (Exception e) {
FileLog.e("tmessages", e);
@ -2081,10 +2089,18 @@ public class MessagesStorage {
public void run() {
SQLitePreparedStatement state = null;
try {
state = database.executeFast("UPDATE enc_chats SET data = ?, g = ?, authkey = ?, ttl = ?, layer = ?, seq_in = ?, seq_out = ? WHERE uid = ?");
if ((chat.key_hash == null || chat.key_hash.length != 16) && chat.auth_key != null) {
byte[] sha1 = Utilities.computeSHA1(chat.auth_key);
chat.key_hash = new byte[16];
System.arraycopy(sha1, 0, chat.key_hash, 0, chat.key_hash.length);
}
state = database.executeFast("UPDATE enc_chats SET data = ?, g = ?, authkey = ?, ttl = ?, layer = ?, seq_in = ?, seq_out = ?, use_count = ?, exchange_id = ?, key_date = ?, fprint = ?, fauthkey = ?, khash = ? WHERE uid = ?");
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);
ByteBufferDesc data4 = buffersStorage.getFreeBuffer(chat.future_auth_key != null ? chat.future_auth_key.length : 1);
ByteBufferDesc data5 = buffersStorage.getFreeBuffer(chat.key_hash != null ? chat.key_hash.length : 1);
chat.serializeToStream(data);
state.bindByteBuffer(1, data.buffer);
if (chat.a_or_b != null) {
@ -2093,17 +2109,32 @@ public class MessagesStorage {
if (chat.auth_key != null) {
data3.writeRaw(chat.auth_key);
}
if (chat.future_auth_key != null) {
data4.writeRaw(chat.future_auth_key);
}
if (chat.key_hash != null) {
data5.writeRaw(chat.key_hash);
}
state.bindByteBuffer(2, data2.buffer);
state.bindByteBuffer(3, data3.buffer);
state.bindInteger(4, chat.ttl);
state.bindInteger(5, chat.layer);
state.bindInteger(6, chat.seq_in);
state.bindInteger(7, chat.seq_out);
state.bindInteger(8, chat.id);
state.bindInteger(8, (int)chat.key_use_count_in << 16 | chat.key_use_count_out);
state.bindLong(9, chat.exchange_id);
state.bindInteger(10, chat.key_create_date);
state.bindLong(11, chat.future_key_fingerprint);
state.bindByteBuffer(12, data4.buffer);
state.bindByteBuffer(13, data5.buffer);
state.bindInteger(14, chat.id);
state.step();
buffersStorage.reuseFreeBuffer(data);
buffersStorage.reuseFreeBuffer(data2);
buffersStorage.reuseFreeBuffer(data3);
buffersStorage.reuseFreeBuffer(data4);
buffersStorage.reuseFreeBuffer(data5);
} catch (Exception e) {
FileLog.e("tmessages", e);
} finally {
@ -2151,10 +2182,17 @@ public class MessagesStorage {
@Override
public void run() {
try {
SQLitePreparedStatement state = database.executeFast("REPLACE INTO enc_chats VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
if ((chat.key_hash == null || chat.key_hash.length != 16) && chat.auth_key != null) {
byte[] sha1 = Utilities.computeSHA1(chat.auth_key);
chat.key_hash = new byte[16];
System.arraycopy(sha1, 0, chat.key_hash, 0, chat.key_hash.length);
}
SQLitePreparedStatement state = database.executeFast("REPLACE INTO enc_chats VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
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);
ByteBufferDesc data4 = buffersStorage.getFreeBuffer(chat.future_auth_key != null ? chat.future_auth_key.length : 1);
ByteBufferDesc data5 = buffersStorage.getFreeBuffer(chat.key_hash != null ? chat.key_hash.length : 1);
chat.serializeToStream(data);
state.bindInteger(1, chat.id);
@ -2167,17 +2205,32 @@ public class MessagesStorage {
if (chat.auth_key != null) {
data3.writeRaw(chat.auth_key);
}
if (chat.future_auth_key != null) {
data4.writeRaw(chat.future_auth_key);
}
if (chat.key_hash != null) {
data5.writeRaw(chat.key_hash);
}
state.bindByteBuffer(5, data2.buffer);
state.bindByteBuffer(6, data3.buffer);
state.bindInteger(7, chat.ttl);
state.bindInteger(8, chat.layer);
state.bindInteger(9, chat.seq_in);
state.bindInteger(10, chat.seq_out);
state.bindInteger(11, (int)chat.key_use_count_in << 16 | chat.key_use_count_out);
state.bindLong(12, chat.exchange_id);
state.bindInteger(13, chat.key_create_date);
state.bindLong(14, chat.future_key_fingerprint);
state.bindByteBuffer(15, data4.buffer);
state.bindByteBuffer(16, data5.buffer);
state.step();
state.dispose();
buffersStorage.reuseFreeBuffer(data);
buffersStorage.reuseFreeBuffer(data2);
buffersStorage.reuseFreeBuffer(data3);
buffersStorage.reuseFreeBuffer(data4);
buffersStorage.reuseFreeBuffer(data5);
if (dialog != null) {
state = database.executeFast("REPLACE INTO dialogs(did, date, unread_count, last_mid) VALUES(?, ?, ?, ?)");
@ -2317,8 +2370,8 @@ public class MessagesStorage {
if (chatsToLoad == null || chatsToLoad.length() == 0 || result == null) {
return;
}
SQLiteCursor cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, user, g, authkey, ttl, layer, seq_in, seq_out FROM enc_chats WHERE uid IN(%s)", chatsToLoad));
//use_count INTEGER, exchange_id INTEGER, key_date INTEGER, fprint INTEGER, fauthkey BLOB
SQLiteCursor cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, user, g, authkey, ttl, layer, seq_in, seq_out, use_count, exchange_id, key_date, fprint, fauthkey, khash FROM enc_chats WHERE uid IN(%s)", chatsToLoad));
while (cursor.next()) {
try {
ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
@ -2335,6 +2388,14 @@ public class MessagesStorage {
chat.layer = cursor.intValue(5);
chat.seq_in = cursor.intValue(6);
chat.seq_out = cursor.intValue(7);
int use_count = cursor.intValue(8);
chat.key_use_count_in = (short)(use_count >> 16);
chat.key_use_count_out = (short)(use_count);
chat.exchange_id = cursor.longValue(9);
chat.key_create_date = cursor.intValue(10);
chat.future_key_fingerprint = cursor.longValue(11);
chat.future_auth_key = cursor.byteArrayValue(12);
chat.key_hash = cursor.byteArrayValue(13);
result.add(chat);
}
}
@ -2994,6 +3055,8 @@ public class MessagesStorage {
user.username = updateUser.username;
} else if (updateUser.photo != null) {
user.photo = updateUser.photo;
} else if (updateUser.phone != null) {
user.phone = updateUser.phone;
}
}
}

View File

@ -23,7 +23,7 @@ import java.util.zip.ZipFile;
public class NativeLoader {
private final static int LIB_VERSION = 3;
private final static int LIB_VERSION = 4;
private final static String LIB_NAME = "tmessages." + LIB_VERSION;
private final static String LIB_SO_NAME = "lib" + LIB_NAME + ".so";
private final static String LOCALE_LIB_SO_NAME = "lib" + LIB_NAME + "loc.so";

View File

@ -33,7 +33,7 @@ import org.telegram.messenger.FileLog;
import org.telegram.messenger.R;
import org.telegram.messenger.TLRPC;
import org.telegram.messenger.UserConfig;
import org.telegram.ui.ApplicationLoader;
import org.telegram.messenger.ApplicationLoader;
import org.telegram.ui.LaunchActivity;
import org.telegram.ui.PopupNotificationActivity;

View File

@ -14,7 +14,7 @@ import android.content.SharedPreferences;
import android.os.IBinder;
import org.telegram.messenger.FileLog;
import org.telegram.ui.ApplicationLoader;
import org.telegram.messenger.ApplicationLoader;
public class NotificationsService extends Service {

View File

@ -14,7 +14,7 @@ import android.content.Intent;
import org.telegram.messenger.ConnectionsManager;
import org.telegram.messenger.FileLog;
import org.telegram.ui.ApplicationLoader;
import org.telegram.messenger.ApplicationLoader;
public class ScreenReceiver extends BroadcastReceiver {
@Override

File diff suppressed because it is too large Load Diff

View File

@ -18,19 +18,16 @@ import android.provider.MediaStore;
import android.webkit.MimeTypeMap;
import android.widget.Toast;
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.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 org.telegram.messenger.ApplicationLoader;
import java.io.File;
import java.util.ArrayList;
@ -38,12 +35,9 @@ import java.util.HashMap;
public class SendMessagesHelper implements NotificationCenter.NotificationCenterDelegate {
public static final int CURRENT_SECRET_CHAT_LAYER = 17;
private TLRPC.ChatParticipants currentChatInfo = null;
private HashMap<String, ArrayList<DelayedMessage>> delayedMessages = new HashMap<String, ArrayList<DelayedMessage>>();
private HashMap<Integer, MessageObject> unsentMessages = new HashMap<Integer, MessageObject>();
private ArrayList<Integer> sendingNotifyLayer = new ArrayList<Integer>();
private class DelayedMessage {
public TLObject sendRequest;
@ -82,7 +76,6 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
public void cleanUp() {
delayedMessages.clear();
sendingNotifyLayer.clear();
unsentMessages.clear();
currentChatInfo = null;
}
@ -149,7 +142,7 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
} else if (encryptedFile != null && message.sendEncryptedRequest != null) {
message.sendEncryptedRequest.media.key = encryptedFile.key;
message.sendEncryptedRequest.media.iv = encryptedFile.iv;
performSendEncryptedRequest(message.sendEncryptedRequest, message.obj.messageOwner, message.encryptedChat, encryptedFile, message.originalPath);
SecretChatHelper.getInstance().performSendEncryptedRequest(message.sendEncryptedRequest, message.obj.messageOwner, message.encryptedChat, encryptedFile, message.originalPath);
arr.remove(a);
a--;
}
@ -301,17 +294,17 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
return false;
}
if (messageObject.messageOwner.action.encryptedAction instanceof TLRPC.TL_decryptedMessageActionSetMessageTTL) {
sendTTLMessage(encryptedChat, messageObject.messageOwner);
SecretChatHelper.getInstance().sendTTLMessage(encryptedChat, messageObject.messageOwner);
} else if (messageObject.messageOwner.action.encryptedAction instanceof TLRPC.TL_decryptedMessageActionDeleteMessages) {
sendMessagesDeleteMessage(encryptedChat, null, messageObject.messageOwner);
SecretChatHelper.getInstance().sendMessagesDeleteMessage(encryptedChat, null, messageObject.messageOwner);
} else if (messageObject.messageOwner.action.encryptedAction instanceof TLRPC.TL_decryptedMessageActionFlushHistory) {
sendClearHistoryMessage(encryptedChat, messageObject.messageOwner);
SecretChatHelper.getInstance().sendClearHistoryMessage(encryptedChat, messageObject.messageOwner);
} else if (messageObject.messageOwner.action.encryptedAction instanceof TLRPC.TL_decryptedMessageActionNotifyLayer) {
sendNotifyLayerMessage(encryptedChat, messageObject.messageOwner);
SecretChatHelper.getInstance().sendNotifyLayerMessage(encryptedChat, messageObject.messageOwner);
} else if (messageObject.messageOwner.action.encryptedAction instanceof TLRPC.TL_decryptedMessageActionReadMessages) {
sendMessagesReadMessage(encryptedChat, null, messageObject.messageOwner);
SecretChatHelper.getInstance().sendMessagesReadMessage(encryptedChat, null, messageObject.messageOwner);
} else if (messageObject.messageOwner.action.encryptedAction instanceof TLRPC.TL_decryptedMessageActionScreenshotMessages) {
sendScreenshotMessage(encryptedChat, null, messageObject.messageOwner);
SecretChatHelper.getInstance().sendScreenshotMessage(encryptedChat, null, messageObject.messageOwner);
} else if (messageObject.messageOwner.action.encryptedAction instanceof TLRPC.TL_decryptedMessageActionTyping) {
} else if (messageObject.messageOwner.action.encryptedAction instanceof TLRPC.TL_decryptedMessageActionResend) {
@ -326,7 +319,7 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
return true;
}
public void processSentMessage(int id) {
protected void processSentMessage(int id) {
int prevSize = unsentMessages.size();
unsentMessages.remove(id);
if (prevSize != 0 && unsentMessages.size() == 0) {
@ -677,7 +670,7 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
reqSend.random_id = newMsg.random_id;
reqSend.message = message;
reqSend.media = new TLRPC.TL_decryptedMessageMediaEmpty();
performSendEncryptedRequest(reqSend, newMsgObj.messageOwner, encryptedChat, null, null);
SecretChatHelper.getInstance().performSendEncryptedRequest(reqSend, newMsgObj.messageOwner, encryptedChat, null, null);
}
} else if (type >= 1 && type <= 3 || type >= 5 && type <= 8) {
if (encryptedChat == null) {
@ -838,7 +831,7 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
reqSend.media = new TLRPC.TL_decryptedMessageMediaGeoPoint();
reqSend.media.lat = lat;
reqSend.media._long = lon;
performSendEncryptedRequest(reqSend, newMsgObj.messageOwner, encryptedChat, null, null);
SecretChatHelper.getInstance().performSendEncryptedRequest(reqSend, newMsgObj.messageOwner, encryptedChat, null, null);
} else if (type == 2) {
TLRPC.PhotoSize small = photo.sizes.get(0);
TLRPC.PhotoSize big = photo.sizes.get(photo.sizes.size() - 1);
@ -864,7 +857,7 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
encryptedFile.access_hash = big.location.secret;
reqSend.media.key = big.location.key;
reqSend.media.iv = big.location.iv;
performSendEncryptedRequest(reqSend, newMsgObj.messageOwner, encryptedChat, encryptedFile, null);
SecretChatHelper.getInstance().performSendEncryptedRequest(reqSend, newMsgObj.messageOwner, encryptedChat, encryptedFile, null);
}
} else if (type == 3) {
if (AndroidUtilities.getPeerLayerVersion(encryptedChat.layer) >= 17) {
@ -895,7 +888,7 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
encryptedFile.access_hash = video.access_hash;
reqSend.media.key = video.key;
reqSend.media.iv = video.iv;
performSendEncryptedRequest(reqSend, newMsgObj.messageOwner, encryptedChat, encryptedFile, null);
SecretChatHelper.getInstance().performSendEncryptedRequest(reqSend, newMsgObj.messageOwner, encryptedChat, encryptedFile, null);
}
} else if (type == 6) {
reqSend.media = new TLRPC.TL_decryptedMessageMediaContact();
@ -903,7 +896,7 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
reqSend.media.first_name = user.first_name;
reqSend.media.last_name = user.last_name;
reqSend.media.user_id = user.id;
performSendEncryptedRequest(reqSend, newMsgObj.messageOwner, encryptedChat, null, null);
SecretChatHelper.getInstance().performSendEncryptedRequest(reqSend, newMsgObj.messageOwner, encryptedChat, null, null);
} else if (type == 7) {
reqSend.media = new TLRPC.TL_decryptedMessageMediaDocument();
reqSend.media.size = document.size;
@ -933,7 +926,7 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
encryptedFile.access_hash = document.access_hash;
reqSend.media.key = document.key;
reqSend.media.iv = document.iv;
performSendEncryptedRequest(reqSend, newMsgObj.messageOwner, encryptedChat, encryptedFile, null);
SecretChatHelper.getInstance().performSendEncryptedRequest(reqSend, newMsgObj.messageOwner, encryptedChat, encryptedFile, null);
}
} else if (type == 8) {
if (AndroidUtilities.getPeerLayerVersion(encryptedChat.layer) >= 17) {
@ -1065,7 +1058,7 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
}
}
private void stopVideoService(final String path) {
protected void stopVideoService(final String path) {
MessagesStorage.getInstance().getStorageQueue().postRunnable(new Runnable() {
@Override
public void run() {
@ -1098,7 +1091,7 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
TLRPC.messages_StatedMessage res = (TLRPC.messages_StatedMessage) response;
sentMessages.add(res.message);
newMsgObj.id = res.message.id;
processSentMessage(newMsgObj, res.message, null, null, originalPath);
processSentMessage(newMsgObj, res.message, originalPath);
MessagesController.getInstance().processNewDifferenceParams(res.seq, res.pts, res.message.date);
} else if (response instanceof TLRPC.messages_StatedMessages) {
TLRPC.messages_StatedMessages res = (TLRPC.messages_StatedMessages) response;
@ -1108,7 +1101,7 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
if (!isBroadcast) {
newMsgObj.id = message.id;
}
processSentMessage(newMsgObj, message, null, null, originalPath);
processSentMessage(newMsgObj, message, originalPath);
}
MessagesController.getInstance().processNewDifferenceParams(res.seq, res.pts, -1);
}
@ -1175,621 +1168,125 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
}), true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassCanCompress, ConnectionsManager.DEFAULT_DATACENTER_ID);
}
private void performSendEncryptedRequest(final TLRPC.DecryptedMessage req, final TLRPC.Message newMsgObj, final TLRPC.EncryptedChat chat, final TLRPC.InputEncryptedFile encryptedFile, final String originalPath) {
if (req == null || chat.auth_key == null || chat instanceof TLRPC.TL_encryptedChatRequested || chat instanceof TLRPC.TL_encryptedChatWaiting) {
private void processSentMessage(TLRPC.Message newMsg, TLRPC.Message sentMessage, String originalPath) {
if (sentMessage == null) {
return;
}
Utilities.stageQueue.postRunnable(new Runnable() {
@Override
public void run() {
TLObject toEncryptObject = null;
if (AndroidUtilities.getPeerLayerVersion(chat.layer) >= 17) {
TLRPC.TL_decryptedMessageLayer layer = new TLRPC.TL_decryptedMessageLayer();
layer.layer = CURRENT_SECRET_CHAT_LAYER;
layer.message = req;
layer.random_bytes = new byte[Math.max(1, (int) Math.ceil(Utilities.random.nextDouble() * 16))];
Utilities.random.nextBytes(layer.random_bytes);
toEncryptObject = layer;
if (sentMessage.media instanceof TLRPC.TL_messageMediaPhoto && sentMessage.media.photo != null && newMsg.media instanceof TLRPC.TL_messageMediaPhoto && newMsg.media.photo != null) {
MessagesStorage.getInstance().putSentFile(originalPath, sentMessage.media.photo, 0);
if (chat.seq_in == 0 && chat.seq_out == 0) {
if (chat.admin_id == UserConfig.getClientUserId()) {
chat.seq_out = 1;
} else {
chat.seq_in = 1;
}
}
if (newMsgObj.seq_in == 0 && newMsgObj.seq_out == 0) {
layer.in_seq_no = chat.seq_in;
layer.out_seq_no = chat.seq_out;
chat.seq_out += 2;
MessagesStorage.getInstance().updateEncryptedChatSeq(chat);
if (newMsgObj != null) {
newMsgObj.seq_in = layer.in_seq_no;
newMsgObj.seq_out = layer.out_seq_no;
MessagesStorage.getInstance().setMessageSeq(newMsgObj.id, newMsgObj.seq_in, newMsgObj.seq_out);
}
} else {
layer.in_seq_no = newMsgObj.seq_in;
layer.out_seq_no = newMsgObj.seq_out;
}
} else {
toEncryptObject = req;
for (TLRPC.PhotoSize size : sentMessage.media.photo.sizes) {
if (size instanceof TLRPC.TL_photoSizeEmpty) {
continue;
}
int len = toEncryptObject.getObjectSize();
ByteBufferDesc toEncrypt = BuffersStorage.getInstance().getFreeBuffer(4 + len);
toEncrypt.writeInt32(len);
toEncryptObject.serializeToStream(toEncrypt);
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);
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.writeRaw(b);
}
BuffersStorage.getInstance().reuseFreeBuffer(toEncrypt);
Utilities.aesIgeEncryption(dataForEncryption.buffer, keyData.aesKey, keyData.aesIv, true, false, 0, dataForEncryption.limit());
ByteBufferDesc data = BuffersStorage.getInstance().getFreeBuffer(8 + messageKey.length + dataForEncryption.length());
dataForEncryption.position(0);
data.writeInt64(chat.key_fingerprint);
data.writeRaw(messageKey);
data.writeRaw(dataForEncryption);
BuffersStorage.getInstance().reuseFreeBuffer(dataForEncryption);
data.position(0);
TLObject reqToSend = null;
if (encryptedFile == null) {
if (req instanceof TLRPC.TL_decryptedMessageService) {
TLRPC.TL_messages_sendEncryptedService req2 = new TLRPC.TL_messages_sendEncryptedService();
req2.data = data;
req2.random_id = req.random_id;
req2.peer = new TLRPC.TL_inputEncryptedChat();
req2.peer.chat_id = chat.id;
req2.peer.access_hash = chat.access_hash;
reqToSend = req2;
} else {
TLRPC.TL_messages_sendEncrypted req2 = new TLRPC.TL_messages_sendEncrypted();
req2.data = data;
req2.random_id = req.random_id;
req2.peer = new TLRPC.TL_inputEncryptedChat();
req2.peer.chat_id = chat.id;
req2.peer.access_hash = chat.access_hash;
reqToSend = req2;
}
} else {
TLRPC.TL_messages_sendEncryptedFile req2 = new TLRPC.TL_messages_sendEncryptedFile();
req2.data = data;
req2.random_id = req.random_id;
req2.peer = new TLRPC.TL_inputEncryptedChat();
req2.peer.chat_id = chat.id;
req2.peer.access_hash = chat.access_hash;
req2.file = encryptedFile;
reqToSend = req2;
}
ConnectionsManager.getInstance().performRpc(reqToSend, new RPCRequest.RPCRequestDelegate() {
@Override
public void run(TLObject response, TLRPC.TL_error error) {
if (error == null) {
if (req.action instanceof TLRPC.TL_decryptedMessageActionNotifyLayer) {
TLRPC.EncryptedChat currentChat = MessagesController.getInstance().getEncryptedChat(chat.id);
sendingNotifyLayer.remove((Integer)currentChat.id);
currentChat.layer = AndroidUtilities.setMyLayerVersion(currentChat.layer, CURRENT_SECRET_CHAT_LAYER);
MessagesStorage.getInstance().updateEncryptedChatLayer(currentChat);
}
}
if (newMsgObj != null) {
if (error == null) {
final String attachPath = newMsgObj.attachPath;
final TLRPC.messages_SentEncryptedMessage res = (TLRPC.messages_SentEncryptedMessage) response;
if (newMsgObj.action instanceof TLRPC.TL_messageEncryptedAction) {
if (newMsgObj.action.encryptedAction instanceof TLRPC.TL_decryptedMessageActionScreenshotMessages || newMsgObj.action.encryptedAction instanceof TLRPC.TL_decryptedMessageActionSetMessageTTL) {
newMsgObj.date = res.date;
}
}
if (res.file instanceof TLRPC.TL_encryptedFile) {
processSentMessage(newMsgObj, null, res.file, req, originalPath);
}
MessagesStorage.getInstance().getStorageQueue().postRunnable(new Runnable() {
@Override
public void run() {
if (newMsgObj.action instanceof TLRPC.TL_messageEncryptedAction) {
if (!(newMsgObj.action.encryptedAction instanceof TLRPC.TL_decryptedMessageActionScreenshotMessages || newMsgObj.action.encryptedAction instanceof TLRPC.TL_decryptedMessageActionSetMessageTTL)) {
res.date = 0;
}
}
MessagesStorage.getInstance().updateMessageStateAndId(newMsgObj.random_id, newMsgObj.id, newMsgObj.id, res.date, false);
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
newMsgObj.send_state = MessageObject.MESSAGE_SEND_STATE_SENT;
NotificationCenter.getInstance().postNotificationName(NotificationCenter.messageReceivedByServer, newMsgObj.id, newMsgObj.id, newMsgObj);
processSentMessage(newMsgObj.id);
if (newMsgObj.media instanceof TLRPC.TL_messageMediaVideo) {
stopVideoService(attachPath);
}
}
});
}
});
} else {
MessagesStorage.getInstance().markMessageAsSendError(newMsgObj.id);
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
newMsgObj.send_state = MessageObject.MESSAGE_SEND_STATE_SEND_ERROR;
NotificationCenter.getInstance().postNotificationName(NotificationCenter.messageSendError, newMsgObj.id);
processSentMessage(newMsgObj.id);
if (newMsgObj.media instanceof TLRPC.TL_messageMediaVideo) {
stopVideoService(newMsgObj.attachPath);
}
}
});
}
}
}
});
}
});
}
private void processSentMessage(TLRPC.Message newMsg, TLRPC.Message sentMessage, TLRPC.EncryptedFile file, TLRPC.DecryptedMessage decryptedMessage, String originalPath) {
if (sentMessage != null) {
if (sentMessage.media instanceof TLRPC.TL_messageMediaPhoto && sentMessage.media.photo != null && newMsg.media instanceof TLRPC.TL_messageMediaPhoto && newMsg.media.photo != null) {
MessagesStorage.getInstance().putSentFile(originalPath, sentMessage.media.photo, 0);
for (TLRPC.PhotoSize size : sentMessage.media.photo.sizes) {
if (size instanceof TLRPC.TL_photoSizeEmpty) {
continue;
}
for (TLRPC.PhotoSize size2 : newMsg.media.photo.sizes) {
if (size.type.equals(size2.type)) {
String fileName = size2.location.volume_id + "_" + size2.location.local_id;
String fileName2 = size.location.volume_id + "_" + size.location.local_id;
if (fileName.equals(fileName2)) {
break;
}
File cacheFile = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName + ".jpg");
File cacheFile2 = null;
if (sentMessage.media.photo.sizes.size() == 1 || size.w > 80 || size.h > 80) {
cacheFile2 = FileLoader.getPathToAttach(size);
} else {
cacheFile2 = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName2 + ".jpg");
}
cacheFile.renameTo(cacheFile2);
ImageLoader.getInstance().replaceImageInCache(fileName, fileName2);
size2.location = size.location;
for (TLRPC.PhotoSize size2 : newMsg.media.photo.sizes) {
if (size.type.equals(size2.type)) {
String fileName = size2.location.volume_id + "_" + size2.location.local_id;
String fileName2 = size.location.volume_id + "_" + size.location.local_id;
if (fileName.equals(fileName2)) {
break;
}
}
}
sentMessage.message = newMsg.message;
sentMessage.attachPath = newMsg.attachPath;
newMsg.media.photo.id = sentMessage.media.photo.id;
newMsg.media.photo.access_hash = sentMessage.media.photo.access_hash;
} else if (sentMessage.media instanceof TLRPC.TL_messageMediaVideo && sentMessage.media.video != null && newMsg.media instanceof TLRPC.TL_messageMediaVideo && newMsg.media.video != null) {
MessagesStorage.getInstance().putSentFile(originalPath, sentMessage.media.video, 2);
TLRPC.PhotoSize size2 = newMsg.media.video.thumb;
TLRPC.PhotoSize size = sentMessage.media.video.thumb;
if (size2.location != null && size.location != null && !(size instanceof TLRPC.TL_photoSizeEmpty) && !(size2 instanceof TLRPC.TL_photoSizeEmpty)) {
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(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName + ".jpg");
File cacheFile2 = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName2 + ".jpg");
File cacheFile2 = null;
if (sentMessage.media.photo.sizes.size() == 1 || size.w > 80 || size.h > 80) {
cacheFile2 = FileLoader.getPathToAttach(size);
} else {
cacheFile2 = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName2 + ".jpg");
}
cacheFile.renameTo(cacheFile2);
ImageLoader.getInstance().replaceImageInCache(fileName, fileName2);
size2.location = size.location;
break;
}
}
}
sentMessage.message = newMsg.message;
sentMessage.attachPath = newMsg.attachPath;
newMsg.media.photo.id = sentMessage.media.photo.id;
newMsg.media.photo.access_hash = sentMessage.media.photo.access_hash;
} else if (sentMessage.media instanceof TLRPC.TL_messageMediaVideo && sentMessage.media.video != null && newMsg.media instanceof TLRPC.TL_messageMediaVideo && newMsg.media.video != null) {
MessagesStorage.getInstance().putSentFile(originalPath, sentMessage.media.video, 2);
sentMessage.message = newMsg.message;
newMsg.media.video.dc_id = sentMessage.media.video.dc_id;
newMsg.media.video.id = sentMessage.media.video.id;
newMsg.media.video.access_hash = sentMessage.media.video.access_hash;
TLRPC.PhotoSize size2 = newMsg.media.video.thumb;
TLRPC.PhotoSize size = sentMessage.media.video.thumb;
if (size2.location != null && size.location != null && !(size instanceof TLRPC.TL_photoSizeEmpty) && !(size2 instanceof TLRPC.TL_photoSizeEmpty)) {
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(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName + ".jpg");
File cacheFile2 = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName2 + ".jpg");
cacheFile.renameTo(cacheFile2);
ImageLoader.getInstance().replaceImageInCache(fileName, fileName2);
size2.location = size.location;
}
}
if (newMsg.attachPath != null && newMsg.attachPath.startsWith(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE).getAbsolutePath())) {
File cacheFile = new File(newMsg.attachPath);
File cacheFile2 = FileLoader.getPathToAttach(newMsg.media.video);
if (!cacheFile.renameTo(cacheFile2)) {
sentMessage.attachPath = newMsg.attachPath;
}
} else {
sentMessage.message = newMsg.message;
newMsg.media.video.dc_id = sentMessage.media.video.dc_id;
newMsg.media.video.id = sentMessage.media.video.id;
newMsg.media.video.access_hash = sentMessage.media.video.access_hash;
if (newMsg.attachPath != null && newMsg.attachPath.startsWith(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE).getAbsolutePath())) {
File cacheFile = new File(newMsg.attachPath);
File cacheFile2 = FileLoader.getPathToAttach(newMsg.media.video);
if (!cacheFile.renameTo(cacheFile2)) {
sentMessage.attachPath = newMsg.attachPath;
}
} else if (sentMessage.media instanceof TLRPC.TL_messageMediaDocument && sentMessage.media.document != null && newMsg.media instanceof TLRPC.TL_messageMediaDocument && newMsg.media.document != null) {
MessagesStorage.getInstance().putSentFile(originalPath, sentMessage.media.document, 1);
} else {
sentMessage.attachPath = newMsg.attachPath;
}
} else if (sentMessage.media instanceof TLRPC.TL_messageMediaDocument && sentMessage.media.document != null && newMsg.media instanceof TLRPC.TL_messageMediaDocument && newMsg.media.document != null) {
MessagesStorage.getInstance().putSentFile(originalPath, sentMessage.media.document, 1);
TLRPC.PhotoSize size2 = newMsg.media.document.thumb;
TLRPC.PhotoSize size = sentMessage.media.document.thumb;
if (size2.location != null && size.location != null && !(size instanceof TLRPC.TL_photoSizeEmpty) && !(size2 instanceof TLRPC.TL_photoSizeEmpty)) {
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(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName + ".jpg");
File cacheFile2 = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName2 + ".jpg");
cacheFile.renameTo(cacheFile2);
ImageLoader.getInstance().replaceImageInCache(fileName, fileName2);
size2.location = size.location;
}
TLRPC.PhotoSize size2 = newMsg.media.document.thumb;
TLRPC.PhotoSize size = sentMessage.media.document.thumb;
if (size2.location != null && size.location != null && !(size instanceof TLRPC.TL_photoSizeEmpty) && !(size2 instanceof TLRPC.TL_photoSizeEmpty)) {
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(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName + ".jpg");
File cacheFile2 = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName2 + ".jpg");
cacheFile.renameTo(cacheFile2);
ImageLoader.getInstance().replaceImageInCache(fileName, fileName2);
size2.location = size.location;
}
}
newMsg.media.document.dc_id = sentMessage.media.document.dc_id;
newMsg.media.document.id = sentMessage.media.document.id;
newMsg.media.document.access_hash = sentMessage.media.document.access_hash;
newMsg.media.document.dc_id = sentMessage.media.document.dc_id;
newMsg.media.document.id = sentMessage.media.document.id;
newMsg.media.document.access_hash = sentMessage.media.document.access_hash;
if (newMsg.attachPath != null && newMsg.attachPath.startsWith(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE).getAbsolutePath())) {
File cacheFile = new File(newMsg.attachPath);
File cacheFile2 = FileLoader.getPathToAttach(sentMessage.media.document);
if (!cacheFile.renameTo(cacheFile2)) {
sentMessage.attachPath = newMsg.attachPath;
sentMessage.message = newMsg.message;
} else {
newMsg.attachPath = "";
}
} else {
if (newMsg.attachPath != null && newMsg.attachPath.startsWith(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE).getAbsolutePath())) {
File cacheFile = new File(newMsg.attachPath);
File cacheFile2 = FileLoader.getPathToAttach(sentMessage.media.document);
if (!cacheFile.renameTo(cacheFile2)) {
sentMessage.attachPath = newMsg.attachPath;
sentMessage.message = newMsg.message;
} else {
newMsg.attachPath = "";
}
} else if (sentMessage.media instanceof TLRPC.TL_messageMediaAudio && sentMessage.media.audio != null && newMsg.media instanceof TLRPC.TL_messageMediaAudio && newMsg.media.audio != null) {
} else {
sentMessage.attachPath = newMsg.attachPath;
sentMessage.message = newMsg.message;
}
} else if (sentMessage.media instanceof TLRPC.TL_messageMediaAudio && sentMessage.media.audio != null && newMsg.media instanceof TLRPC.TL_messageMediaAudio && newMsg.media.audio != null) {
sentMessage.message = newMsg.message;
String fileName = newMsg.media.audio.dc_id + "_" + newMsg.media.audio.id + ".ogg";
newMsg.media.audio.dc_id = sentMessage.media.audio.dc_id;
newMsg.media.audio.id = sentMessage.media.audio.id;
newMsg.media.audio.access_hash = sentMessage.media.audio.access_hash;
String fileName2 = sentMessage.media.audio.dc_id + "_" + sentMessage.media.audio.id + ".ogg";
if (!fileName.equals(fileName2)) {
File cacheFile = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName);
File cacheFile2 = FileLoader.getPathToAttach(sentMessage.media.audio);
if (!cacheFile.renameTo(cacheFile2)) {
sentMessage.attachPath = newMsg.attachPath;
}
String fileName = newMsg.media.audio.dc_id + "_" + newMsg.media.audio.id + ".ogg";
newMsg.media.audio.dc_id = sentMessage.media.audio.dc_id;
newMsg.media.audio.id = sentMessage.media.audio.id;
newMsg.media.audio.access_hash = sentMessage.media.audio.access_hash;
String fileName2 = sentMessage.media.audio.dc_id + "_" + sentMessage.media.audio.id + ".ogg";
if (!fileName.equals(fileName2)) {
File cacheFile = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName);
File cacheFile2 = FileLoader.getPathToAttach(sentMessage.media.audio);
if (!cacheFile.renameTo(cacheFile2)) {
sentMessage.attachPath = newMsg.attachPath;
}
}
} else if (file != null) {
if (newMsg.media instanceof TLRPC.TL_messageMediaPhoto && newMsg.media.photo != null) {
TLRPC.PhotoSize size = newMsg.media.photo.sizes.get(newMsg.media.photo.sizes.size() - 1);
String fileName = size.location.volume_id + "_" + size.location.local_id;
size.location = new TLRPC.TL_fileEncryptedLocation();
size.location.key = decryptedMessage.media.key;
size.location.iv = decryptedMessage.media.iv;
size.location.dc_id = file.dc_id;
size.location.volume_id = file.id;
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(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName + ".jpg");
File cacheFile2 = FileLoader.getPathToAttach(size);
cacheFile.renameTo(cacheFile2);
ImageLoader.getInstance().replaceImageInCache(fileName, fileName2);
ArrayList<TLRPC.Message> arr = new ArrayList<TLRPC.Message>();
arr.add(newMsg);
MessagesStorage.getInstance().putMessages(arr, false, true, false, 0);
MessagesStorage.getInstance().putSentFile(originalPath, newMsg.media.photo, 3);
} else if (newMsg.media instanceof TLRPC.TL_messageMediaVideo && newMsg.media.video != null) {
TLRPC.Video video = newMsg.media.video;
newMsg.media.video = new TLRPC.TL_videoEncrypted();
newMsg.media.video.duration = video.duration;
newMsg.media.video.thumb = video.thumb;
newMsg.media.video.dc_id = file.dc_id;
newMsg.media.video.w = video.w;
newMsg.media.video.h = video.h;
newMsg.media.video.date = video.date;
newMsg.media.video.caption = "";
newMsg.media.video.user_id = video.user_id;
newMsg.media.video.size = file.size;
newMsg.media.video.id = file.id;
newMsg.media.video.access_hash = file.access_hash;
newMsg.media.video.key = decryptedMessage.media.key;
newMsg.media.video.iv = decryptedMessage.media.iv;
newMsg.media.video.mime_type = video.mime_type;
if (newMsg.attachPath != null && newMsg.attachPath.startsWith(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE).getAbsolutePath())) {
File cacheFile = new File(newMsg.attachPath);
File cacheFile2 = FileLoader.getPathToAttach(newMsg.media.video);
if (cacheFile.renameTo(cacheFile2)) {
newMsg.attachPath = "";
}
}
ArrayList<TLRPC.Message> arr = new ArrayList<TLRPC.Message>();
arr.add(newMsg);
MessagesStorage.getInstance().putMessages(arr, false, true, false, 0);
MessagesStorage.getInstance().putSentFile(originalPath, newMsg.media.video, 5);
} else if (newMsg.media instanceof TLRPC.TL_messageMediaDocument && newMsg.media.document != null) {
TLRPC.Document document = newMsg.media.document;
newMsg.media.document = new TLRPC.TL_documentEncrypted();
newMsg.media.document.id = file.id;
newMsg.media.document.access_hash = file.access_hash;
newMsg.media.document.user_id = document.user_id;
newMsg.media.document.date = document.date;
newMsg.media.document.file_name = document.file_name;
newMsg.media.document.mime_type = document.mime_type;
newMsg.media.document.size = file.size;
newMsg.media.document.key = decryptedMessage.media.key;
newMsg.media.document.iv = decryptedMessage.media.iv;
newMsg.media.document.thumb = document.thumb;
newMsg.media.document.dc_id = file.dc_id;
if (newMsg.attachPath != null && newMsg.attachPath.startsWith(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE).getAbsolutePath())) {
File cacheFile = new File(newMsg.attachPath);
File cacheFile2 = FileLoader.getPathToAttach(newMsg.media.document);
if (cacheFile.renameTo(cacheFile2)) {
newMsg.attachPath = "";
}
}
ArrayList<TLRPC.Message> arr = new ArrayList<TLRPC.Message>();
arr.add(newMsg);
MessagesStorage.getInstance().putMessages(arr, false, true, false, 0);
MessagesStorage.getInstance().putSentFile(originalPath, newMsg.media.document, 4);
} else if (newMsg.media instanceof TLRPC.TL_messageMediaAudio && newMsg.media.audio != null) {
TLRPC.Audio audio = newMsg.media.audio;
newMsg.media.audio = new TLRPC.TL_audioEncrypted();
newMsg.media.audio.id = file.id;
newMsg.media.audio.access_hash = file.access_hash;
newMsg.media.audio.user_id = audio.user_id;
newMsg.media.audio.date = audio.date;
newMsg.media.audio.duration = audio.duration;
newMsg.media.audio.size = file.size;
newMsg.media.audio.dc_id = file.dc_id;
newMsg.media.audio.key = decryptedMessage.media.key;
newMsg.media.audio.iv = decryptedMessage.media.iv;
newMsg.media.audio.mime_type = audio.mime_type;
String fileName = audio.dc_id + "_" + audio.id + ".ogg";
String fileName2 = newMsg.media.audio.dc_id + "_" + newMsg.media.audio.id + ".ogg";
if (!fileName.equals(fileName2)) {
File cacheFile = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName);
File cacheFile2 = FileLoader.getPathToAttach(newMsg.media.audio);
if (cacheFile.renameTo(cacheFile2)) {
newMsg.attachPath = "";
}
}
ArrayList<TLRPC.Message> arr = new ArrayList<TLRPC.Message>();
arr.add(newMsg);
MessagesStorage.getInstance().putMessages(arr, false, true, false, 0);
}
}
}
private TLRPC.TL_messageService createServiceSecretMessage(final TLRPC.EncryptedChat encryptedChat, TLRPC.DecryptedMessageAction decryptedMessage) {
TLRPC.TL_messageService newMsg = new TLRPC.TL_messageService();
newMsg.action = new TLRPC.TL_messageEncryptedAction();
newMsg.action.encryptedAction = decryptedMessage;
newMsg.local_id = newMsg.id = UserConfig.getNewMessageId();
newMsg.from_id = UserConfig.getClientUserId();
newMsg.flags = TLRPC.MESSAGE_FLAG_UNREAD | TLRPC.MESSAGE_FLAG_OUT;
newMsg.dialog_id = ((long)encryptedChat.id) << 32;
newMsg.to_id = new TLRPC.TL_peerUser();
newMsg.send_state = MessageObject.MESSAGE_SEND_STATE_SENDING;
if (encryptedChat.participant_id == UserConfig.getClientUserId()) {
newMsg.to_id.user_id = encryptedChat.admin_id;
} else {
newMsg.to_id.user_id = encryptedChat.participant_id;
}
if (decryptedMessage instanceof TLRPC.TL_decryptedMessageActionScreenshotMessages || decryptedMessage instanceof TLRPC.TL_decryptedMessageActionSetMessageTTL) {
newMsg.date = ConnectionsManager.getInstance().getCurrentTime();
} else {
newMsg.date = 0;
}
newMsg.random_id = getNextRandomId();
UserConfig.saveConfig(false);
ArrayList<TLRPC.Message> arr = new ArrayList<TLRPC.Message>();
arr.add(newMsg);
MessagesStorage.getInstance().putMessages(arr, false, true, true, 0);
return newMsg;
}
public void sendMessagesReadMessage(TLRPC.EncryptedChat encryptedChat, ArrayList<Long> random_ids, TLRPC.Message resendMessage) {
if (!(encryptedChat instanceof TLRPC.TL_encryptedChat)) {
return;
}
TLRPC.TL_decryptedMessageService reqSend = null;
if (AndroidUtilities.getPeerLayerVersion(encryptedChat.layer) >= 17) {
reqSend = new TLRPC.TL_decryptedMessageService();
} else {
reqSend = new TLRPC.TL_decryptedMessageService_old();
reqSend.random_bytes = new byte[Math.max(1, (int) Math.ceil(Utilities.random.nextDouble() * 16))];
Utilities.random.nextBytes(reqSend.random_bytes);
}
TLRPC.Message message = null;
if (resendMessage != null) {
message = resendMessage;
reqSend.action = message.action.encryptedAction;
} else {
reqSend.action = new TLRPC.TL_decryptedMessageActionReadMessages();
reqSend.action.random_ids = random_ids;
message = createServiceSecretMessage(encryptedChat, reqSend.action);
}
reqSend.random_id = message.random_id;
performSendEncryptedRequest(reqSend, message, encryptedChat, null, null);
}
public void sendMessagesDeleteMessage(TLRPC.EncryptedChat encryptedChat, ArrayList<Long> random_ids, TLRPC.Message resendMessage) {
if (!(encryptedChat instanceof TLRPC.TL_encryptedChat)) {
return;
}
TLRPC.TL_decryptedMessageService reqSend = null;
if (AndroidUtilities.getPeerLayerVersion(encryptedChat.layer) >= 17) {
reqSend = new TLRPC.TL_decryptedMessageService();
} else {
reqSend = new TLRPC.TL_decryptedMessageService_old();
reqSend.random_bytes = new byte[Math.max(1, (int) Math.ceil(Utilities.random.nextDouble() * 16))];
Utilities.random.nextBytes(reqSend.random_bytes);
}
TLRPC.Message message = null;
if (resendMessage != null) {
message = resendMessage;
reqSend.action = message.action.encryptedAction;
} else {
reqSend.action = new TLRPC.TL_decryptedMessageActionDeleteMessages();
reqSend.action.random_ids = random_ids;
message = createServiceSecretMessage(encryptedChat, reqSend.action);
}
reqSend.random_id = message.random_id;
performSendEncryptedRequest(reqSend, message, encryptedChat, null, null);
}
public void sendClearHistoryMessage(TLRPC.EncryptedChat encryptedChat, TLRPC.Message resendMessage) {
if (!(encryptedChat instanceof TLRPC.TL_encryptedChat)) {
return;
}
TLRPC.TL_decryptedMessageService reqSend = null;
if (AndroidUtilities.getPeerLayerVersion(encryptedChat.layer) >= 17) {
reqSend = new TLRPC.TL_decryptedMessageService();
} else {
reqSend = new TLRPC.TL_decryptedMessageService_old();
reqSend.random_bytes = new byte[Math.max(1, (int) Math.ceil(Utilities.random.nextDouble() * 16))];
Utilities.random.nextBytes(reqSend.random_bytes);
}
TLRPC.Message message = null;
if (resendMessage != null) {
message = resendMessage;
reqSend.action = message.action.encryptedAction;
} else {
reqSend.action = new TLRPC.TL_decryptedMessageActionFlushHistory();
message = createServiceSecretMessage(encryptedChat, reqSend.action);
}
reqSend.random_id = message.random_id;
performSendEncryptedRequest(reqSend, message, encryptedChat, null, null);
}
public void sendNotifyLayerMessage(final TLRPC.EncryptedChat encryptedChat, TLRPC.Message resendMessage) {
if (!(encryptedChat instanceof TLRPC.TL_encryptedChat)) {
return;
}
if (sendingNotifyLayer.contains(encryptedChat.id)) {
return;
}
sendingNotifyLayer.add(encryptedChat.id);
TLRPC.TL_decryptedMessageService reqSend = null;
if (AndroidUtilities.getPeerLayerVersion(encryptedChat.layer) >= 17) {
reqSend = new TLRPC.TL_decryptedMessageService();
} else {
reqSend = new TLRPC.TL_decryptedMessageService_old();
reqSend.random_bytes = new byte[Math.max(1, (int) Math.ceil(Utilities.random.nextDouble() * 16))];
Utilities.random.nextBytes(reqSend.random_bytes);
}
TLRPC.Message message = null;
if (resendMessage != null) {
message = resendMessage;
reqSend.action = message.action.encryptedAction;
} else {
reqSend.action = new TLRPC.TL_decryptedMessageActionNotifyLayer();
reqSend.action.layer = CURRENT_SECRET_CHAT_LAYER;
message = createServiceSecretMessage(encryptedChat, reqSend.action);
}
reqSend.random_id = message.random_id;
performSendEncryptedRequest(reqSend, message, encryptedChat, null, null);
}
public void sendTTLMessage(TLRPC.EncryptedChat encryptedChat, TLRPC.Message resendMessage) {
if (!(encryptedChat instanceof TLRPC.TL_encryptedChat)) {
return;
}
TLRPC.TL_decryptedMessageService reqSend = null;
if (AndroidUtilities.getPeerLayerVersion(encryptedChat.layer) >= 17) {
reqSend = new TLRPC.TL_decryptedMessageService();
} else {
reqSend = new TLRPC.TL_decryptedMessageService_old();
reqSend.random_bytes = new byte[Math.max(1, (int) Math.ceil(Utilities.random.nextDouble() * 16))];
Utilities.random.nextBytes(reqSend.random_bytes);
}
TLRPC.Message message = null;
if (resendMessage != null) {
message = resendMessage;
reqSend.action = message.action.encryptedAction;
} else {
reqSend.action = new TLRPC.TL_decryptedMessageActionSetMessageTTL();
reqSend.action.ttl_seconds = encryptedChat.ttl;
message = createServiceSecretMessage(encryptedChat, reqSend.action);
MessageObject newMsgObj = new MessageObject(message, null);
newMsgObj.messageOwner.send_state = MessageObject.MESSAGE_SEND_STATE_SENDING;
ArrayList<MessageObject> objArr = new ArrayList<MessageObject>();
objArr.add(newMsgObj);
MessagesController.getInstance().updateInterfaceWithMessages(message.dialog_id, objArr);
NotificationCenter.getInstance().postNotificationName(NotificationCenter.dialogsNeedReload);
}
reqSend.random_id = message.random_id;
performSendEncryptedRequest(reqSend, message, encryptedChat, null, null);
}
public void sendScreenshotMessage(TLRPC.EncryptedChat encryptedChat, ArrayList<Long> random_ids, TLRPC.Message resendMessage) {
if (!(encryptedChat instanceof TLRPC.TL_encryptedChat)) {
return;
}
TLRPC.TL_decryptedMessageService reqSend = null;
if (AndroidUtilities.getPeerLayerVersion(encryptedChat.layer) >= 17) {
reqSend = new TLRPC.TL_decryptedMessageService();
} else {
reqSend = new TLRPC.TL_decryptedMessageService_old();
reqSend.random_bytes = new byte[Math.max(1, (int) Math.ceil(Utilities.random.nextDouble() * 16))];
Utilities.random.nextBytes(reqSend.random_bytes);
}
TLRPC.Message message = null;
if (resendMessage != null) {
message = resendMessage;
reqSend.action = message.action.encryptedAction;
} else {
reqSend.action = new TLRPC.TL_decryptedMessageActionScreenshotMessages();
reqSend.action.random_ids = random_ids;
message = createServiceSecretMessage(encryptedChat, reqSend.action);
MessageObject newMsgObj = new MessageObject(message, null);
newMsgObj.messageOwner.send_state = MessageObject.MESSAGE_SEND_STATE_SENDING;
ArrayList<MessageObject> objArr = new ArrayList<MessageObject>();
objArr.add(newMsgObj);
MessagesController.getInstance().updateInterfaceWithMessages(message.dialog_id, objArr);
NotificationCenter.getInstance().postNotificationName(NotificationCenter.dialogsNeedReload);
}
reqSend.random_id = message.random_id;
performSendEncryptedRequest(reqSend, message, encryptedChat, null, null);
}
private void putToDelayedMessages(String location, DelayedMessage message) {
ArrayList<DelayedMessage> arrayList = delayedMessages.get(location);
if (arrayList == null) {
@ -1799,7 +1296,7 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
arrayList.add(message);
}
private long getNextRandomId() {
protected long getNextRandomId() {
long val = 0;
while (val == 0) {
val = Utilities.random.nextLong();

View File

@ -16,7 +16,7 @@ import android.support.v4.app.NotificationManagerCompat;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.R;
import org.telegram.ui.ApplicationLoader;
import org.telegram.messenger.ApplicationLoader;
public class VideoEncodingService extends Service implements NotificationCenter.NotificationCenterDelegate {

View File

@ -6,7 +6,7 @@
* Copyright Nikolai Kudashov, 2013.
*/
package org.telegram.ui;
package org.telegram.messenger;
import android.app.AlarmManager;
import android.app.Application;
@ -34,15 +34,10 @@ import org.telegram.android.ContactsController;
import org.telegram.android.MediaController;
import org.telegram.android.NotificationsService;
import org.telegram.android.SendMessagesHelper;
import org.telegram.messenger.BuildVars;
import org.telegram.messenger.ConnectionsManager;
import org.telegram.messenger.FileLog;
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;
import java.util.concurrent.atomic.AtomicInteger;

View File

@ -21,7 +21,6 @@ import org.telegram.android.ContactsController;
import org.telegram.android.LocaleController;
import org.telegram.android.MessagesController;
import org.telegram.android.NotificationCenter;
import org.telegram.ui.ApplicationLoader;
import java.io.File;
import java.util.ArrayList;
@ -418,7 +417,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
pushSessionId = Utilities.random.nextLong();
}
if (currentDatacenterId == 0) {
currentDatacenterId = 1;
currentDatacenterId = 2;
}
saveSession();
}
@ -432,12 +431,12 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
if (isTestBackend == 0) {
Datacenter datacenter = new Datacenter();
datacenter.datacenterId = 1;
datacenter.addAddressAndPort("173.240.5.1", 443);
datacenter.addAddressAndPort("149.154.175.50", 443);
datacenters.put(datacenter.datacenterId, datacenter);
datacenter = new Datacenter();
datacenter.datacenterId = 2;
datacenter.addAddressAndPort("149.154.167.50", 443);
datacenter.addAddressAndPort("149.154.167.51", 443);
datacenters.put(datacenter.datacenterId, datacenter);
datacenter = new Datacenter();
@ -447,7 +446,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
datacenter = new Datacenter();
datacenter.datacenterId = 4;
datacenter.addAddressAndPort("149.154.167.90", 443);
datacenter.addAddressAndPort("149.154.167.91", 443);
datacenters.put(datacenter.datacenterId, datacenter);
datacenter = new Datacenter();
@ -473,7 +472,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
} else if (datacenters.size() == 1) {
Datacenter datacenter = new Datacenter();
datacenter.datacenterId = 2;
datacenter.addAddressAndPort("149.154.167.50", 443);
datacenter.addAddressAndPort("149.154.167.51", 443);
datacenters.put(datacenter.datacenterId, datacenter);
datacenter = new Datacenter();
@ -483,12 +482,12 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
datacenter = new Datacenter();
datacenter.datacenterId = 4;
datacenter.addAddressAndPort("31.210.235.12", 443);
datacenter.addAddressAndPort("149.154.167.91", 443);
datacenters.put(datacenter.datacenterId, datacenter);
datacenter = new Datacenter();
datacenter.datacenterId = 5;
datacenter.addAddressAndPort("116.51.22.2", 443);
datacenter.addAddressAndPort("149.154.171.5", 443);
datacenters.put(datacenter.datacenterId, datacenter);
}
}
@ -1113,13 +1112,13 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
request.retryCount++;
if ((request.flags & RPCRequest.RPCRequestClassDownloadMedia) != 0) {
if (!request.salt && (request.flags & RPCRequest.RPCRequestClassDownloadMedia) != 0) {
int retryMax = 10;
if ((request.flags & RPCRequest.RPCRequestClassForceDownload) == 0) {
if (request.wait) {
retryMax = 1;
} else {
retryMax = 3;
retryMax = 6;
}
}
if (request.retryCount >= retryMax) {
@ -2244,6 +2243,8 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
}
if (request.respondsToMessageId(resultMid)) {
request.retryCount = 0;
request.salt = true;
break;
}
}
}
@ -2568,7 +2569,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
if (message == null) {
FileLog.e("tmessages", "***** Error parsing message: " + constructor);
} else {
FileLog.e("tmessages", "received object " + message);
FileLog.d("tmessages", "received object " + message);
processMessage(message, messageId, messageSeqNo, messageServerSalt, connection, 0, 0);
connection.addProcessedMessageId(messageId);

View File

@ -11,8 +11,6 @@ package org.telegram.messenger;
import android.content.Context;
import android.content.SharedPreferences;
import org.telegram.ui.ApplicationLoader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

View File

@ -12,7 +12,6 @@ import android.net.Uri;
import android.util.Log;
import org.telegram.android.time.FastDateFormat;
import org.telegram.ui.ApplicationLoader;
import java.io.File;
import java.io.FileOutputStream;

View File

@ -11,8 +11,6 @@ package org.telegram.messenger;
import android.app.Activity;
import android.content.SharedPreferences;
import org.telegram.ui.ApplicationLoader;
import java.io.File;
import java.io.FileInputStream;
import java.math.BigInteger;

View File

@ -37,6 +37,7 @@ public class RPCRequest {
int serverFailureCount;
int flags;
boolean wait = false;
boolean salt = false;
protected int retryCount = 0;
protected int lastResendTime = 0;
protected boolean completed = false;

View File

@ -359,6 +359,13 @@ public class TLClassStore {
classStore.put(TLRPC.TL_inputPhotoCrop.constructor, TLRPC.TL_inputPhotoCrop.class);
classStore.put(TLRPC.TL_messages_dialogs.constructor, TLRPC.TL_messages_dialogs.class);
classStore.put(TLRPC.TL_messages_dialogsSlice.constructor, TLRPC.TL_messages_dialogsSlice.class);
classStore.put(TLRPC.TL_account_sentChangePhoneCode.constructor, TLRPC.TL_account_sentChangePhoneCode.class);
classStore.put(TLRPC.TL_updateUserPhone.constructor, TLRPC.TL_updateUserPhone.class);
classStore.put(TLRPC.TL_decryptedMessageActionRequestKey.constructor, TLRPC.TL_decryptedMessageActionRequestKey.class);
classStore.put(TLRPC.TL_decryptedMessageActionAcceptKey.constructor, TLRPC.TL_decryptedMessageActionAcceptKey.class);
classStore.put(TLRPC.TL_decryptedMessageActionCommitKey.constructor, TLRPC.TL_decryptedMessageActionCommitKey.class);
classStore.put(TLRPC.TL_decryptedMessageActionAbortKey.constructor, TLRPC.TL_decryptedMessageActionAbortKey.class);
classStore.put(TLRPC.TL_decryptedMessageActionNoop.constructor, TLRPC.TL_decryptedMessageActionNoop.class);
classStore.put(TLRPC.TL_msg_container.constructor, TLRPC.TL_msg_container.class);
classStore.put(TLRPC.TL_fileEncryptedLocation.constructor, TLRPC.TL_fileEncryptedLocation.class);

View File

@ -3675,6 +3675,7 @@ public class TLRPC {
public long random_id;
public ArrayList<TL_dcOption> dc_options = new ArrayList<TL_dcOption>();
public ChatParticipants participants;
public String phone;
public TL_privacyKeyStatusTimestamp key;
public ArrayList<PrivacyRule> rules = new ArrayList<PrivacyRule>();
public EncryptedChat chat;
@ -4009,6 +4010,22 @@ public class TLRPC {
}
}
public static class TL_updateUserPhone extends Update {
public static int constructor = 0x12b9417b;
public void readParams(AbsSerializedData stream) {
user_id = stream.readInt32();
phone = stream.readString();
}
public void serializeToStream(AbsSerializedData stream) {
stream.writeInt32(constructor);
stream.writeInt32(user_id);
stream.writeString(phone);
}
}
public static class TL_updatePrivacy extends Update {
public static int constructor = 0xee3b272a;
@ -4329,10 +4346,14 @@ public class TLRPC {
public static class DecryptedMessageAction extends TLObject {
public int start_seq_no;
public int end_seq_no;
public int layer;
public int ttl_seconds;
public int layer;
public ArrayList<Long> random_ids = new ArrayList<Long>();
public long exchange_id;
public long key_fingerprint;
public byte[] g_b;
public SendMessageAction action;
public byte[] g_a;
}
public static class TL_decryptedMessageActionSetMessageTTL extends DecryptedMessageAction {
@ -4356,6 +4377,24 @@ public class TLRPC {
}
}
public static class TL_decryptedMessageActionAcceptKey extends DecryptedMessageAction {
public static int constructor = 0x6fe1735b;
public void readParams(AbsSerializedData stream) {
exchange_id = stream.readInt64();
g_b = stream.readByteArray();
key_fingerprint = stream.readInt64();
}
public void serializeToStream(AbsSerializedData stream) {
stream.writeInt32(constructor);
stream.writeInt64(exchange_id);
stream.writeByteArray(g_b);
stream.writeInt64(key_fingerprint);
}
}
public static class TL_decryptedMessageActionResend extends DecryptedMessageAction {
public static int constructor = 0x511110b0;
@ -4409,6 +4448,22 @@ public class TLRPC {
}
}
public static class TL_decryptedMessageActionRequestKey extends DecryptedMessageAction {
public static int constructor = 0xf3c9611b;
public void readParams(AbsSerializedData stream) {
exchange_id = stream.readInt64();
g_a = stream.readByteArray();
}
public void serializeToStream(AbsSerializedData stream) {
stream.writeInt32(constructor);
stream.writeInt64(exchange_id);
stream.writeByteArray(g_a);
}
}
public static class TL_decryptedMessageActionTyping extends DecryptedMessageAction {
public static int constructor = 0xccb27641;
@ -5019,6 +5074,69 @@ public class TLRPC {
}
}
public static class TL_contacts_resolveUsername extends TLObject {
public static int constructor = 0xbf0131c;
public String username;
public Class responseClass () {
return User.class;
}
public void readParams(AbsSerializedData stream) {
username = stream.readString();
}
public void serializeToStream(AbsSerializedData stream) {
stream.writeInt32(constructor);
stream.writeString(username);
}
}
public static class TL_account_sendChangePhoneCode extends TLObject {
public static int constructor = 0xa407a8f4;
public String phone_number;
public Class responseClass () {
return TL_account_sentChangePhoneCode.class;
}
public void readParams(AbsSerializedData stream) {
phone_number = stream.readString();
}
public void serializeToStream(AbsSerializedData stream) {
stream.writeInt32(constructor);
stream.writeString(phone_number);
}
}
public static class TL_account_changePhone extends TLObject {
public static int constructor = 0x70c32edb;
public String phone_number;
public String phone_code_hash;
public String phone_code;
public Class responseClass () {
return User.class;
}
public void readParams(AbsSerializedData stream) {
phone_number = stream.readString();
phone_code_hash = stream.readString();
phone_code = stream.readString();
}
public void serializeToStream(AbsSerializedData stream) {
stream.writeInt32(constructor);
stream.writeString(phone_number);
stream.writeString(phone_code_hash);
stream.writeString(phone_code);
}
}
public static class InputAudio extends TLObject {
public long id;
public long access_hash;
@ -5900,6 +6018,24 @@ public class TLRPC {
}
}
public static class TL_account_sentChangePhoneCode extends TLObject {
public static int constructor = 0xa4f58c4c;
public String phone_code_hash;
public int send_call_timeout;
public void readParams(AbsSerializedData stream) {
phone_code_hash = stream.readString();
send_call_timeout = stream.readInt32();
}
public void serializeToStream(AbsSerializedData stream) {
stream.writeInt32(constructor);
stream.writeString(phone_code_hash);
stream.writeInt32(send_call_timeout);
}
}
public static class InputFile extends TLObject {
public long id;
public int parts;
@ -8819,6 +8955,7 @@ public class TLRPC {
public int date;
public TL_decryptedMessageLayer layer;
public EncryptedFile file;
public boolean new_key_used;
public void readParams(AbsSerializedData stream) {
random_id = stream.readInt64();
@ -8827,6 +8964,7 @@ public class TLRPC {
if (stream.readBool()) {
file = (EncryptedFile) TLClassStore.Instance().TLdeserialize(stream, stream.readInt32());
}
new_key_used = stream.readBool();
}
public void serializeToStream(AbsSerializedData stream) {
@ -8838,6 +8976,7 @@ public class TLRPC {
if (file != null) {
file.serializeToStream(stream);
}
stream.writeBool(new_key_used);
}
}
@ -9990,6 +10129,13 @@ public class TLRPC {
public int layer;
public int seq_in;
public int seq_out;
public byte[] key_hash;
public short key_use_count_in;
public short key_use_count_out;
public long exchange_id;
public int key_create_date;
public long future_key_fingerprint;
public byte[] future_auth_key;
}
public static class FileLocation extends TLObject {
@ -10290,7 +10436,7 @@ public class TLRPC {
public static class invokeWithLayer extends TLObject {
public static int constructor = 0xda9b0d0d;
public int layer = 19;
public int layer = 20;
public TLObject query;
public void serializeToStream(AbsSerializedData stream) {
@ -10406,6 +10552,45 @@ public class TLRPC {
}
}
public static class TL_decryptedMessageActionCommitKey extends DecryptedMessageAction {
public static int constructor = 0xec2e0b9b;
public void readParams(AbsSerializedData stream) {
exchange_id = stream.readInt64();
key_fingerprint = stream.readInt64();
}
public void serializeToStream(AbsSerializedData stream) {
stream.writeInt32(constructor);
stream.writeInt64(exchange_id);
stream.writeInt64(key_fingerprint);
}
}
public static class TL_decryptedMessageActionAbortKey extends DecryptedMessageAction {
public static int constructor = 0xdd05ec6b;
public void readParams(AbsSerializedData stream) {
exchange_id = stream.readInt64();
}
public void serializeToStream(AbsSerializedData stream) {
stream.writeInt32(constructor);
stream.writeInt64(exchange_id);
}
}
public static class TL_decryptedMessageActionNoop extends DecryptedMessageAction {
public static int constructor = 0xa82fdd63;
public void serializeToStream(AbsSerializedData stream) {
stream.writeInt32(constructor);
}
}
public static class TL_decryptedMessageActionScreenshotMessages extends DecryptedMessageAction {
public static int constructor = 0x8ac1f475;

View File

@ -13,7 +13,6 @@ import android.content.SharedPreferences;
import android.util.Base64;
import org.telegram.android.MessagesStorage;
import org.telegram.ui.ApplicationLoader;
import java.io.File;

View File

@ -28,8 +28,6 @@ import net.hockeyapp.android.CrashManager;
import net.hockeyapp.android.CrashManagerListener;
import net.hockeyapp.android.UpdateManager;
import org.telegram.ui.ApplicationLoader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;

View File

@ -55,6 +55,7 @@ public class ActionBarMenuItem extends ImageView {
private Runnable showMenuRunnable;
private boolean showFromBottom;
private int menuHeight = AndroidUtilities.dp(16);
private boolean needOffset = Build.VERSION.SDK_INT >= 21;
public ActionBarMenuItem(Context context, ActionBarMenu menu, int background) {
super(context);
@ -135,6 +136,10 @@ public class ActionBarMenuItem extends ImageView {
showFromBottom = value;
}
public void setNeedOffset(boolean value) {
needOffset = Build.VERSION.SDK_INT >= 21 && value;
}
public TextView addSubItem(int id, String text, int icon) {
if (popupLayout == null) {
rect = new Rect();
@ -247,29 +252,33 @@ public class ActionBarMenuItem extends ImageView {
popupWindow.setFocusable(true);
if (popupLayout.getMeasuredWidth() == 0) {
if (showFromBottom) {
popupWindow.showAsDropDown(this, -popupLayout.getMeasuredWidth() + getMeasuredWidth() + AndroidUtilities.dp(14), getBottomOffsetY());
popupWindow.update(this, -popupLayout.getMeasuredWidth() + getMeasuredWidth() + AndroidUtilities.dp(14), getBottomOffsetY(), -1, -1);
popupWindow.showAsDropDown(this, -popupLayout.getMeasuredWidth() + getMeasuredWidth() + AndroidUtilities.dp(14), getOffsetY());
popupWindow.update(this, -popupLayout.getMeasuredWidth() + getMeasuredWidth() + AndroidUtilities.dp(14), getOffsetY(), -1, -1);
} else {
popupWindow.showAsDropDown(this, parentMenu.parentActionBar.getMeasuredWidth() - popupLayout.getMeasuredWidth() - getLeft() - parentMenu.getLeft(), -getMeasuredHeight());
popupWindow.update(this, parentMenu.parentActionBar.getMeasuredWidth() - popupLayout.getMeasuredWidth() - getLeft() - parentMenu.getLeft(), -getMeasuredHeight(), -1, -1);
popupWindow.showAsDropDown(this, parentMenu.parentActionBar.getMeasuredWidth() - popupLayout.getMeasuredWidth() - getLeft() - parentMenu.getLeft(), getOffsetY());
popupWindow.update(this, parentMenu.parentActionBar.getMeasuredWidth() - popupLayout.getMeasuredWidth() - getLeft() - parentMenu.getLeft(), getOffsetY(), -1, -1);
}
} else {
if (showFromBottom) {
popupWindow.showAsDropDown(this, -popupLayout.getMeasuredWidth() + getMeasuredWidth() + AndroidUtilities.dp(14), getBottomOffsetY());
popupWindow.showAsDropDown(this, -popupLayout.getMeasuredWidth() + getMeasuredWidth() + AndroidUtilities.dp(14), getOffsetY());
} else {
popupWindow.showAsDropDown(this, parentMenu.parentActionBar.getMeasuredWidth() - popupLayout.getMeasuredWidth() - getLeft() - parentMenu.getLeft(), -getMeasuredHeight());
popupWindow.showAsDropDown(this, parentMenu.parentActionBar.getMeasuredWidth() - popupLayout.getMeasuredWidth() - getLeft() - parentMenu.getLeft(), getOffsetY());
}
}
}
private int getBottomOffsetY() {
getLocationOnScreen(location);
int diff = location[1] - AndroidUtilities.statusBarHeight + getMeasuredHeight() - menuHeight;
int y = AndroidUtilities.dp(8) - menuHeight;
if (diff < 0) {
y -= diff;
private int getOffsetY() {
if (showFromBottom) {
getLocationOnScreen(location);
int diff = location[1] - AndroidUtilities.statusBarHeight + getMeasuredHeight() - menuHeight;
int y = AndroidUtilities.dp(8) - menuHeight;
if (diff < 0) {
y -= diff;
}
return y - (needOffset ? AndroidUtilities.statusBarHeight : 0);
} else {
return -getMeasuredHeight() - (needOffset ? AndroidUtilities.statusBarHeight : 0);
}
return y;
}
public boolean toggleSearch() {
@ -415,9 +424,9 @@ public class ActionBarMenuItem extends ImageView {
super.onLayout(changed, left, top, right, bottom);
if (popupWindow != null && popupWindow.isShowing()) {
if (showFromBottom) {
popupWindow.update(this, -popupLayout.getMeasuredWidth() + getMeasuredWidth() + AndroidUtilities.dp(14), getBottomOffsetY(), -1, -1);
popupWindow.update(this, -popupLayout.getMeasuredWidth() + getMeasuredWidth() + AndroidUtilities.dp(14), getOffsetY(), -1, -1);
} else {
popupWindow.update(this, parentMenu.parentActionBar.getMeasuredWidth() - popupLayout.getMeasuredWidth() - getLeft() - parentMenu.getLeft(), -getMeasuredHeight(), -1, -1);
popupWindow.update(this, parentMenu.parentActionBar.getMeasuredWidth() - popupLayout.getMeasuredWidth() - getLeft() - parentMenu.getLeft(), getOffsetY(), -1, -1);
}
}
}

View File

@ -11,10 +11,12 @@
package org.telegram.ui.ActionBar;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewTreeObserver;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
@ -23,6 +25,7 @@ import org.telegram.messenger.FileLog;
import java.lang.reflect.Field;
public class ActionBarPopupWindow extends PopupWindow {
private static final Field superListenerField;
static {
Field f = null;
@ -132,6 +135,15 @@ public class ActionBarPopupWindow extends PopupWindow {
mSuperScrollListener = null;
}
}
if (Build.VERSION.SDK_INT >= 21) {
try {
Field field = PopupWindow.class.getDeclaredField("mWindowLayoutType");
field.setAccessible(true);
field.set(this, WindowManager.LayoutParams.TYPE_SYSTEM_ERROR);
} catch (Exception e) {
/* ignored */
}
}
}
private void unregisterListener() {

View File

@ -34,7 +34,7 @@ public class DrawerLayoutContainer extends FrameLayout {
private static final int MIN_DRAWER_MARGIN = 64;
private View drawerLayout;
private ViewGroup drawerLayout;
private ActionBarLayout parentActionBarLayout;
private boolean maybeStartTracking = false;
@ -55,7 +55,7 @@ public class DrawerLayoutContainer extends FrameLayout {
private Drawable shadowLeft;
private boolean allowOpenDrawer;
private int drawerPosition = 0;
private float drawerPosition = 0;
private boolean drawerOpened = false;
public DrawerLayoutContainer(Context context) {
@ -125,7 +125,7 @@ public class DrawerLayoutContainer extends FrameLayout {
requestLayout();
}
public void setDrawerLayout(View layout) {
public void setDrawerLayout(ViewGroup layout) {
drawerLayout = layout;
addView(drawerLayout);
if (Build.VERSION.SDK_INT >= 21) {
@ -133,11 +133,11 @@ public class DrawerLayoutContainer extends FrameLayout {
}
}
public void moveDrawerByX(int dx) {
public void moveDrawerByX(float dx) {
setDrawerPosition(drawerPosition + dx);
}
public void setDrawerPosition(int value) {
public void setDrawerPosition(float value) {
drawerPosition = value;
if (drawerPosition > drawerLayout.getMeasuredWidth()) {
drawerPosition = drawerLayout.getMeasuredWidth();
@ -150,10 +150,10 @@ public class DrawerLayoutContainer extends FrameLayout {
if (drawerLayout.getVisibility() != newVisibility) {
drawerLayout.setVisibility(newVisibility);
}
setScrimOpacity((float)drawerPosition / (float)drawerLayout.getMeasuredWidth());
setScrimOpacity(drawerPosition / (float)drawerLayout.getMeasuredWidth());
}
public int getDrawerPosition() {
public float getDrawerPosition() {
return drawerPosition;
}
@ -171,7 +171,7 @@ public class DrawerLayoutContainer extends FrameLayout {
cancelCurrentAnimation();
AnimatorSetProxy animatorSet = new AnimatorSetProxy();
animatorSet.playTogether(
ObjectAnimatorProxy.ofInt(this, "drawerPosition", drawerLayout.getMeasuredWidth())
ObjectAnimatorProxy.ofFloat(this, "drawerPosition", drawerLayout.getMeasuredWidth())
);
animatorSet.setInterpolator(new DecelerateInterpolator());
if (fast) {
@ -198,7 +198,7 @@ public class DrawerLayoutContainer extends FrameLayout {
cancelCurrentAnimation();
AnimatorSetProxy animatorSet = new AnimatorSetProxy();
animatorSet.playTogether(
ObjectAnimatorProxy.ofInt(this, "drawerPosition", 0)
ObjectAnimatorProxy.ofFloat(this, "drawerPosition", 0)
);
animatorSet.setInterpolator(new DecelerateInterpolator());
if (fast) {
@ -291,12 +291,13 @@ public class DrawerLayoutContainer extends FrameLayout {
if (velocityTracker == null) {
velocityTracker = VelocityTracker.obtain();
}
int dx = (int) (ev.getX() - startedTrackingX);
int dy = Math.abs((int) ev.getY() - startedTrackingY);
float dx = (int) (ev.getX() - startedTrackingX);
float dy = Math.abs((int) ev.getY() - startedTrackingY);
velocityTracker.addMovement(ev);
if (maybeStartTracking && !startedTracking && Math.abs(dx) / 3 > Math.abs(dy) && (dx < 0 || dx > 0 && dx > AndroidUtilities.dp(10))) {
if (maybeStartTracking && !startedTracking && (dx > 0 && dx / 3.0f > Math.abs(dy) || dx < 0 && Math.abs(dx) >= Math.abs(dy) && Math.abs(dx) >= AndroidUtilities.dp(10))) {
prepareForDrawerOpen(ev);
startedTrackingX = (int) ev.getX();
requestDisallowInterceptTouchEvent(true);
} else if (startedTracking) {
if (!beginTrackingSent) {
if (((Activity)getContext()).getCurrentFocus() != null) {
@ -312,10 +313,10 @@ public class DrawerLayoutContainer extends FrameLayout {
velocityTracker = VelocityTracker.obtain();
}
velocityTracker.computeCurrentVelocity(1000);
if (!startedTracking) {
/*if (!startedTracking) {
float velX = velocityTracker.getXVelocity();
float velY = velocityTracker.getYVelocity();
if (Math.abs(velX) >= 1500 && Math.abs(velX) > Math.abs(velY)) {
if (Math.abs(velX) >= 3500 && Math.abs(velX) > Math.abs(velY)) {
prepareForDrawerOpen(ev);
if (!beginTrackingSent) {
if (((Activity)getContext()).getCurrentFocus() != null) {
@ -324,15 +325,15 @@ public class DrawerLayoutContainer extends FrameLayout {
beginTrackingSent = true;
}
}
}
}*/
if (startedTracking || drawerPosition != 0 && drawerPosition != drawerLayout.getMeasuredWidth()) {
float velX = velocityTracker.getXVelocity();
float velY = velocityTracker.getYVelocity();
boolean backAnimation = drawerPosition < drawerLayout.getMeasuredWidth() / 2.0f && (velX < 1500 || Math.abs(velX) < Math.abs(velY)) || velX < 0 && Math.abs(velX) >= 1500;
boolean backAnimation = drawerPosition < drawerLayout.getMeasuredWidth() / 2.0f && (velX < 3500 || Math.abs(velX) < Math.abs(velY)) || velX < 0 && Math.abs(velX) >= 3500;
if (!backAnimation) {
openDrawer(!drawerOpened && Math.abs(velX) >= 1500);
openDrawer(!drawerOpened && Math.abs(velX) >= 3500);
} else {
closeDrawer(drawerOpened && Math.abs(velX) >= 1500);
closeDrawer(drawerOpened && Math.abs(velX) >= 3500);
}
startedTracking = false;
} else {
@ -357,7 +358,9 @@ public class DrawerLayoutContainer extends FrameLayout {
@Override
public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) {
onTouchEvent(null);
if (maybeStartTracking && !startedTracking) {
onTouchEvent(null);
}
super.requestDisallowInterceptTouchEvent(disallowIntercept);
}
@ -378,7 +381,7 @@ public class DrawerLayoutContainer extends FrameLayout {
if (drawerLayout != child) {
child.layout(lp.leftMargin, lp.topMargin, lp.leftMargin + child.getMeasuredWidth(), lp.topMargin + child.getMeasuredHeight());
} else {
child.layout(-child.getMeasuredWidth() + drawerPosition, lp.topMargin, drawerPosition, lp.topMargin + child.getMeasuredHeight());
child.layout(-child.getMeasuredWidth() + (int)drawerPosition, lp.topMargin, (int)drawerPosition, lp.topMargin + child.getMeasuredHeight());
}
}
inLayout = false;
@ -462,9 +465,9 @@ public class DrawerLayoutContainer extends FrameLayout {
scrimPaint.setColor((int) (((0x99000000 & 0xff000000) >>> 24) * scrimOpacity) << 24);
canvas.drawRect(clipLeft, 0, clipRight, getHeight(), scrimPaint);
} else if (shadowLeft != null) {
final float alpha = Math.max(0, Math.min((float) drawerPosition / AndroidUtilities.dp(20), 1.0f));
final float alpha = Math.max(0, Math.min(drawerPosition / AndroidUtilities.dp(20), 1.0f));
if (alpha != 0) {
shadowLeft.setBounds(drawerPosition, child.getTop(), drawerPosition + shadowLeft.getIntrinsicWidth(), child.getBottom());
shadowLeft.setBounds((int)drawerPosition, child.getTop(), (int)drawerPosition + shadowLeft.getIntrinsicWidth(), child.getBottom());
shadowLeft.setAlpha((int) (0xff * alpha));
shadowLeft.draw(canvas);
}

View File

@ -15,7 +15,7 @@ import android.view.ViewGroup;
import org.telegram.android.AndroidUtilities;
import org.telegram.android.LocaleController;
import org.telegram.messenger.FileLog;
import org.telegram.ui.ApplicationLoader;
import org.telegram.messenger.ApplicationLoader;
import org.telegram.ui.Cells.DividerCell;
import org.telegram.ui.Cells.LetterSectionCell;
import org.telegram.ui.Cells.TextSettingsCell;

View File

@ -10,6 +10,7 @@ package org.telegram.ui.Adapters;
import android.content.Context;
import android.text.Html;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
@ -36,10 +37,15 @@ import org.telegram.ui.Cells.LoadingCell;
import org.telegram.ui.Cells.ProfileSearchCell;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Locale;
import java.util.Timer;
import java.util.TimerTask;
public class DialogsSearchAdapter extends BaseContactsSearchAdapter {
private Context mContext;
private Timer searchTimer;
private ArrayList<TLObject> searchResult = new ArrayList<TLObject>();
@ -54,6 +60,12 @@ public class DialogsSearchAdapter extends BaseContactsSearchAdapter {
private String lastMessagesSearchString;
private int lastSearchId = 0;
private class DialogSearchResult {
public TLObject object;
public int date;
public CharSequence name;
}
public static interface MessagesActivitySearchAdapterDelegate {
public abstract void searchStateChanged(boolean searching);
}
@ -143,19 +155,211 @@ public class DialogsSearchAdapter extends BaseContactsSearchAdapter {
@Override
public void run() {
try {
FileLog.e("tmessages", "trigger search");
ArrayList<TLRPC.User> encUsers = new ArrayList<TLRPC.User>();
String q = query.trim().toLowerCase();
if (q.length() == 0) {
lastSearchId = -1;
updateSearchResults(new ArrayList<TLObject>(), new ArrayList<CharSequence>(), new ArrayList<TLRPC.User>(), lastSearchId);
return;
}
ArrayList<Integer> usersToLoad = new ArrayList<Integer>();
ArrayList<Integer> chatsToLoad = new ArrayList<Integer>();
ArrayList<Integer> encryptedToLoad = new ArrayList<Integer>();
ArrayList<TLRPC.User> encUsers = new ArrayList<TLRPC.User>();
int resultCount = 0;
HashMap<Long, DialogSearchResult> dialogsResult = new HashMap<Long, DialogSearchResult>();
SQLiteCursor cursor = MessagesStorage.getInstance().getDatabase().queryFinalized(String.format(Locale.US, "SELECT did, date FROM dialogs ORDER BY date DESC LIMIT 200"));
while (cursor.next()) {
long id = cursor.longValue(0);
DialogSearchResult dialogSearchResult = new DialogSearchResult();
dialogSearchResult.date = cursor.intValue(1);
dialogsResult.put(id, dialogSearchResult);
int lower_id = (int)id;
int high_id = (int)(id >> 32);
if (lower_id != 0) {
if (high_id == 1) {
if (!serverOnly && !chatsToLoad.contains(lower_id)) {
chatsToLoad.add(lower_id);
}
} else {
if (lower_id > 0) {
if (!usersToLoad.contains(lower_id)) {
usersToLoad.add(lower_id);
}
} else {
if (!chatsToLoad.contains(-lower_id)) {
chatsToLoad.add(-lower_id);
}
}
}
} else if (!serverOnly) {
if (!encryptedToLoad.contains(high_id)) {
encryptedToLoad.add(high_id);
}
}
}
cursor.dispose();
if (!usersToLoad.isEmpty()) {
cursor = MessagesStorage.getInstance().getDatabase().queryFinalized(String.format(Locale.US, "SELECT data, status, name FROM users WHERE uid IN(%s)", TextUtils.join(",", usersToLoad)));
while (cursor.next()) {
String name = cursor.stringValue(2);
String username = null;
int usernamePos = name.lastIndexOf(";;;");
if (usernamePos != -1) {
username = name.substring(usernamePos + 3);
}
int found = 0;
if (name.startsWith(q) || name.contains(" " + q)) {
found = 1;
} else if (username != null && username.startsWith(q)) {
found = 2;
}
if (found != 0) {
ByteBufferDesc data = MessagesStorage.getInstance().getBuffersStorage().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()) {
DialogSearchResult dialogSearchResult = dialogsResult.get((long)user.id);
if (user.status != null) {
user.status.expires = cursor.intValue(1);
}
if (found == 1) {
dialogSearchResult.name = Utilities.generateSearchName(user.first_name, user.last_name, q);
} else {
dialogSearchResult.name = Utilities.generateSearchName("@" + user.username, null, "@" + q);
}
dialogSearchResult.object = user;
resultCount++;
}
}
MessagesStorage.getInstance().getBuffersStorage().reuseFreeBuffer(data);
}
}
cursor.dispose();
}
if (!chatsToLoad.isEmpty()) {
cursor = MessagesStorage.getInstance().getDatabase().queryFinalized(String.format(Locale.US, "SELECT data, name FROM chats WHERE uid IN(%s)", TextUtils.join(",", chatsToLoad)));
while (cursor.next()) {
String name = cursor.stringValue(1);
String[] args = name.split(" ");
if (name.startsWith(q) || name.contains(" " + q)) {
ByteBufferDesc data = MessagesStorage.getInstance().getBuffersStorage().getFreeBuffer(cursor.byteArrayLength(0));
if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
TLRPC.Chat chat = (TLRPC.Chat) TLClassStore.Instance().TLdeserialize(data, data.readInt32());
long dialog_id;
if (chat.id > 0) {
dialog_id = -chat.id;
} else {
dialog_id = AndroidUtilities.makeBroadcastId(chat.id);
}
DialogSearchResult dialogSearchResult = dialogsResult.get(dialog_id);
dialogSearchResult.name = Utilities.generateSearchName(chat.title, null, q);
dialogSearchResult.object = chat;
resultCount++;
}
MessagesStorage.getInstance().getBuffersStorage().reuseFreeBuffer(data);
}
}
cursor.dispose();
}
if (!encryptedToLoad.isEmpty()) {
cursor = MessagesStorage.getInstance().getDatabase().queryFinalized(String.format(Locale.US, "SELECT q.data, u.name, q.user, q.g, q.authkey, q.ttl, u.data, u.status, q.layer, q.seq_in, q.seq_out, q.use_count, q.exchange_id, q.key_date, q.fprint, q.fauthkey, q.khash FROM enc_chats as q INNER JOIN users as u ON q.user = u.uid WHERE q.uid IN(%s)", TextUtils.join(",", encryptedToLoad)));
while (cursor.next()) {
String name = cursor.stringValue(1);
String username = null;
int usernamePos = name.lastIndexOf(";;;");
if (usernamePos != -1) {
username = name.substring(usernamePos + 2);
}
int found = 0;
if (name.startsWith(q) || name.contains(" " + q)) {
found = 1;
} else if (username != null && username.startsWith(q)) {
found = 2;
}
if (found != 0) {
ByteBufferDesc data = MessagesStorage.getInstance().getBuffersStorage().getFreeBuffer(cursor.byteArrayLength(0));
ByteBufferDesc data2 = MessagesStorage.getInstance().getBuffersStorage().getFreeBuffer(cursor.byteArrayLength(6));
if (data != null && cursor.byteBufferValue(0, data.buffer) != 0 && cursor.byteBufferValue(6, data2.buffer) != 0) {
TLRPC.EncryptedChat chat = (TLRPC.EncryptedChat) TLClassStore.Instance().TLdeserialize(data, data.readInt32());
DialogSearchResult dialogSearchResult = dialogsResult.get((long)chat.id << 32);
chat.user_id = cursor.intValue(2);
chat.a_or_b = cursor.byteArrayValue(3);
chat.auth_key = cursor.byteArrayValue(4);
chat.ttl = cursor.intValue(5);
chat.layer = cursor.intValue(8);
chat.seq_in = cursor.intValue(9);
chat.seq_out = cursor.intValue(10);
int use_count = cursor.intValue(11);
chat.key_use_count_in = (short)(use_count >> 16);
chat.key_use_count_out = (short)(use_count);
chat.exchange_id = cursor.longValue(12);
chat.key_create_date = cursor.intValue(13);
chat.future_key_fingerprint = cursor.longValue(14);
chat.future_auth_key = cursor.byteArrayValue(15);
chat.key_hash = cursor.byteArrayValue(16);
TLRPC.User user = (TLRPC.User)TLClassStore.Instance().TLdeserialize(data2, data2.readInt32());
if (user.status != null) {
user.status.expires = cursor.intValue(7);
}
if (found == 1) {
dialogSearchResult.name = Html.fromHtml("<font color=\"#00a60e\">" + ContactsController.formatName(user.first_name, user.last_name) + "</font>");
} else {
dialogSearchResult.name = Utilities.generateSearchName("@" + user.username, null, "@" + q);
}
dialogSearchResult.object = chat;
encUsers.add(user);
resultCount++;
}
MessagesStorage.getInstance().getBuffersStorage().reuseFreeBuffer(data);
MessagesStorage.getInstance().getBuffersStorage().reuseFreeBuffer(data2);
}
}
cursor.dispose();
}
ArrayList<DialogSearchResult> searchResults = new ArrayList<DialogSearchResult>(resultCount);
for (DialogSearchResult dialogSearchResult : dialogsResult.values()) {
if (dialogSearchResult.object != null && dialogSearchResult.name != null) {
searchResults.add(dialogSearchResult);
}
}
Collections.sort(searchResults, new Comparator<DialogSearchResult>() {
@Override
public int compare(DialogSearchResult lhs, DialogSearchResult rhs) {
if (lhs.date < rhs.date) {
return 1;
} else if (lhs.date > rhs.date) {
return -1;
}
return 0;
}
});
ArrayList<TLObject> resultArray = new ArrayList<TLObject>();
ArrayList<CharSequence> resultArrayNames = new ArrayList<CharSequence>();
SQLiteCursor cursor = MessagesStorage.getInstance().getDatabase().queryFinalized("SELECT u.data, u.status, u.name FROM users as u INNER JOIN contacts as c ON u.uid = c.uid");
for (DialogSearchResult dialogSearchResult : searchResults) {
resultArray.add(dialogSearchResult.object);
resultArrayNames.add(dialogSearchResult.name);
}
cursor = MessagesStorage.getInstance().getDatabase().queryFinalized("SELECT u.data, u.status, u.name, u.uid FROM users as u INNER JOIN contacts as c ON u.uid = c.uid");
while (cursor.next()) {
int uid = cursor.intValue(3);
if (dialogsResult.containsKey((long)uid)) {
continue;
}
String name = cursor.stringValue(2);
String username = null;
int usernamePos = name.lastIndexOf(";;;");
@ -189,73 +393,6 @@ public class DialogsSearchAdapter extends BaseContactsSearchAdapter {
}
cursor.dispose();
if (!serverOnly) {
cursor = MessagesStorage.getInstance().getDatabase().queryFinalized("SELECT q.data, u.name, q.user, q.g, q.authkey, q.ttl, u.data, u.status, q.layer, q.seq_in, q.seq_out FROM enc_chats as q INNER JOIN dialogs as d ON (q.uid << 32) = d.did INNER JOIN users as u ON q.user = u.uid");
while (cursor.next()) {
String name = cursor.stringValue(1);
String username = null;
int usernamePos = name.lastIndexOf(";;;");
if (usernamePos != -1) {
username = name.substring(usernamePos + 2);
}
int found = 0;
if (name.startsWith(q) || name.contains(" " + q)) {
found = 1;
} else if (username != null && username.startsWith(q)) {
found = 2;
}
if (found != 0) {
ByteBufferDesc data = MessagesStorage.getInstance().getBuffersStorage().getFreeBuffer(cursor.byteArrayLength(0));
ByteBufferDesc data2 = MessagesStorage.getInstance().getBuffersStorage().getFreeBuffer(cursor.byteArrayLength(6));
if (data != null && cursor.byteBufferValue(0, data.buffer) != 0 && cursor.byteBufferValue(6, 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);
chat.layer = cursor.intValue(8);
chat.seq_in = cursor.intValue(9);
chat.seq_out = cursor.intValue(10);
TLRPC.User user = (TLRPC.User)TLClassStore.Instance().TLdeserialize(data2, data2.readInt32());
if (user.status != null) {
user.status.expires = cursor.intValue(7);
}
if (found == 1) {
resultArrayNames.add(Html.fromHtml("<font color=\"#00a60e\">" + ContactsController.formatName(user.first_name, user.last_name) + "</font>"));
} else {
resultArrayNames.add(Utilities.generateSearchName("@" + user.username, null, "@" + q));
}
resultArray.add(chat);
encUsers.add(user);
}
MessagesStorage.getInstance().getBuffersStorage().reuseFreeBuffer(data);
MessagesStorage.getInstance().getBuffersStorage().reuseFreeBuffer(data2);
}
}
cursor.dispose();
}
cursor = MessagesStorage.getInstance().getDatabase().queryFinalized("SELECT data, name FROM chats");
while (cursor.next()) {
String name = cursor.stringValue(1);
String[] args = name.split(" ");
if (name.startsWith(q) || name.contains(" " + q)) {
ByteBufferDesc data = MessagesStorage.getInstance().getBuffersStorage().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 (serverOnly && chat.id < 0) {
continue;
}
resultArrayNames.add(Utilities.generateSearchName(chat.title, null, q));
resultArray.add(chat);
}
MessagesStorage.getInstance().getBuffersStorage().reuseFreeBuffer(data);
}
}
cursor.dispose();
updateSearchResults(resultArray, resultArrayNames, encUsers, searchId);
} catch (Exception e) {
FileLog.e("tmessages", e);

View File

@ -31,7 +31,7 @@ import org.telegram.messenger.R;
import org.telegram.messenger.TLRPC;
import org.telegram.messenger.UserConfig;
import org.telegram.ui.PhotoViewer;
import org.telegram.ui.Views.AvatarDrawable;
import org.telegram.ui.Components.AvatarDrawable;
public class ChatActionCell extends BaseCell {

View File

@ -25,9 +25,9 @@ import org.telegram.android.MessagesController;
import org.telegram.messenger.R;
import org.telegram.android.MessageObject;
import org.telegram.android.ImageReceiver;
import org.telegram.ui.Views.AvatarDrawable;
import org.telegram.ui.Views.ProgressView;
import org.telegram.ui.Views.SeekBar;
import org.telegram.ui.Components.AvatarDrawable;
import org.telegram.ui.Components.ProgressView;
import org.telegram.ui.Components.SeekBar;
import java.io.File;

View File

@ -28,7 +28,7 @@ import org.telegram.android.MessagesController;
import org.telegram.messenger.R;
import org.telegram.android.MessageObject;
import org.telegram.android.ImageReceiver;
import org.telegram.ui.Views.AvatarDrawable;
import org.telegram.ui.Components.AvatarDrawable;
public class ChatBaseCell extends BaseCell {
@ -482,7 +482,7 @@ public class ChatBaseCell extends BaseCell {
if (drawName && nameLayout != null) {
canvas.save();
canvas.translate(currentBackgroundDrawable.getBounds().left + AndroidUtilities.dp(19) - nameOffsetX, AndroidUtilities.dp(10));
namePaint.setColor(AvatarDrawable.getColorForId(currentUser.id));
namePaint.setColor(AvatarDrawable.getNameColorForId(currentUser.id));
nameLayout.draw(canvas);
canvas.restore();
}

View File

@ -28,7 +28,7 @@ import org.telegram.android.MessagesController;
import org.telegram.messenger.R;
import org.telegram.messenger.TLRPC;
import org.telegram.messenger.UserConfig;
import org.telegram.ui.Views.AvatarDrawable;
import org.telegram.ui.Components.AvatarDrawable;
public class ChatContactCell extends ChatBaseCell {

View File

@ -21,7 +21,6 @@ import android.text.TextPaint;
import android.text.TextUtils;
import android.view.MotionEvent;
import android.view.SoundEffectConstants;
import android.view.animation.DecelerateInterpolator;
import org.telegram.android.AndroidUtilities;
import org.telegram.android.ImageLoader;
@ -33,8 +32,9 @@ import org.telegram.messenger.R;
import org.telegram.messenger.Utilities;
import org.telegram.android.MessageObject;
import org.telegram.android.PhotoObject;
import org.telegram.ui.Components.RadialProgress;
import org.telegram.ui.PhotoViewer;
import org.telegram.ui.Views.GifDrawable;
import org.telegram.ui.Components.GifDrawable;
import org.telegram.android.ImageReceiver;
import java.io.File;
@ -58,11 +58,10 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
private static MessageObject lastDownloadedGifMessage = null;
private static TextPaint namePaint;
private static Paint docBackPaint;
private static Paint progressPaint;
private static Paint deleteProgressPaint;
private static DecelerateInterpolator decelerateInterpolator;
private GifDrawable gifDrawable = null;
private RadialProgress radialProgress;
private int photoWidth;
private int photoHeight;
@ -71,7 +70,6 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
private String currentUrl;
private String currentPhotoFilter;
private ImageReceiver photoImage;
private boolean progressVisible = false;
private boolean photoNotSet = false;
private boolean cancelLoading = false;
@ -96,17 +94,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
private String currentNameString;
private ChatMediaCellDelegate mediaDelegate = null;
private float currentProgress = 0;
private RectF progressRect = new RectF();
private long lastUpdateTime = 0;
private boolean animationStarted = false;
private float radOffset = 0;
private float animatedProgressValue = 0;
private long currentProgressTime = 0;
private float animationProgressStart = 0;
private RectF deleteProgressRect = new RectF();
private int lastSecretSecondsLeft = 0;
public ChatMediaCell(Context context) {
super(context);
@ -141,26 +129,21 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
docBackPaint = new Paint();
progressPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
progressPaint.setStyle(Paint.Style.STROKE);
progressPaint.setStrokeCap(Paint.Cap.ROUND);
progressPaint.setStrokeWidth(AndroidUtilities.dp(2));
deleteProgressPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
deleteProgressPaint.setColor(0xffe4e2e0);
decelerateInterpolator = new DecelerateInterpolator();
}
TAG = MediaController.getInstance().generateObserverTag();
photoImage = new ImageReceiver(this);
radialProgress = new RadialProgress(this);
}
public void clearGifImage() {
if (currentMessageObject != null && currentMessageObject.type == 8) {
gifDrawable = null;
buttonState = 2;
radialProgress.setBackground(getDrawableForCurrentState(), false, false);
invalidate();
}
}
@ -228,7 +211,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
if (event.getAction() == MotionEvent.ACTION_UP) {
buttonPressed = 0;
playSoundEffect(SoundEffectConstants.CLICK);
didPressedButton();
didPressedButton(false);
invalidate();
} else if (event.getAction() == MotionEvent.ACTION_CANCEL) {
buttonPressed = 0;
@ -295,7 +278,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
mediaDelegate.didClickedImage(this);
}
} else if (buttonState == 0) {
didPressedButton();
didPressedButton(false);
}
} else if (currentMessageObject.type == 8) {
if (buttonState == -1) {
@ -303,13 +286,14 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
if (gifDrawable != null) {
gifDrawable.pause();
}
radialProgress.setBackground(getDrawableForCurrentState(), false, false);
invalidate();
} else if (buttonState == 2 || buttonState == 0) {
didPressedButton();
didPressedButton(false);
}
} else if (currentMessageObject.type == 3) {
if (buttonState == 0 || buttonState == 3) {
didPressedButton();
didPressedButton(false);
}
} else if (currentMessageObject.type == 4) {
if (mediaDelegate != null) {
@ -324,7 +308,31 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
}
}
private void didPressedButton() {
private Drawable getDrawableForCurrentState() {
if (buttonState >= 0 && buttonState < 4) {
Drawable currentButtonDrawable = null;
if (currentMessageObject.type == 9 && gifDrawable == null) {
if (buttonState == 1 && !currentMessageObject.isSending()) {
return buttonStatesDrawablesDoc[2][currentMessageObject.isOut() ? 1 : 0];
} else {
return buttonStatesDrawablesDoc[buttonState][currentMessageObject.isOut() ? 1 : 0];
}
} else {
if (buttonState == 1 && !currentMessageObject.isSending()) {
return buttonStatesDrawables[4];
} else {
return buttonStatesDrawables[buttonState];
}
}
} else if (buttonState == -1) {
if (currentMessageObject.type == 9 && gifDrawable == null) {
return currentMessageObject.isOut() ? placeholderDocOutDrawable : placeholderDocInDrawable;
}
}
return null;
}
private void didPressedButton(boolean animated) {
if (buttonState == 0) {
cancelLoading = false;
if (currentMessageObject.type == 1) {
@ -339,9 +347,8 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
} else if (currentMessageObject.type == 3) {
FileLoader.getInstance().loadFile(currentMessageObject.messageOwner.media.video, true);
}
progressVisible = true;
startAnimation();
buttonState = 1;
radialProgress.setBackground(getDrawableForCurrentState(), true, animated);
invalidate();
} else if (buttonState == 1) {
if (currentMessageObject.isOut() && currentMessageObject.isSending()) {
@ -360,9 +367,8 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
} else if (currentMessageObject.type == 3) {
FileLoader.getInstance().cancelLoadFile(currentMessageObject.messageOwner.media.video);
}
progressVisible = false;
stopAnimation();
buttonState = 0;
radialProgress.setBackground(getDrawableForCurrentState(), false, animated);
invalidate();
}
} else if (buttonState == 2) {
@ -373,7 +379,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
gifDrawable.start();
gifDrawable.invalidateSelf();
buttonState = -1;
invalidate();
radialProgress.setBackground(getDrawableForCurrentState(), false, animated);
}
} else if (buttonState == 3) {
if (mediaDelegate != null) {
@ -407,11 +413,11 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
@Override
public void setMessageObject(MessageObject messageObject) {
media = messageObject.type != 9;
if (currentMessageObject != messageObject || isPhotoDataChanged(messageObject) || isUserDataChanged()) {
boolean dataChanged = currentMessageObject == messageObject && (isUserDataChanged() || photoNotSet);
if (currentMessageObject != messageObject || isPhotoDataChanged(messageObject) || dataChanged) {
super.setMessageObject(messageObject);
cancelLoading = false;
progressVisible = false;
buttonState = -1;
gifDrawable = null;
currentPhotoObject = null;
@ -630,14 +636,14 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
invalidate();
}
updateButtonState();
updateButtonState(dataChanged);
}
public ImageReceiver getPhotoImage() {
return photoImage;
}
public void updateButtonState() {
public void updateButtonState(boolean animated) {
String fileName = null;
File cacheFile = null;
if (currentMessageObject.type == 1) {
@ -660,16 +666,16 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
}
}
if (fileName == null) {
radialProgress.setBackground(null, false, false);
return;
}
if (currentMessageObject.isOut() && currentMessageObject.isSending()) {
if (currentMessageObject.messageOwner.attachPath != null) {
MediaController.getInstance().addLoadingFileObserver(currentMessageObject.messageOwner.attachPath, this);
progressVisible = true;
startAnimation();
buttonState = 1;
radialProgress.setBackground(getDrawableForCurrentState(), true, animated);
Float progress = FileLoader.getInstance().getFileProgress(currentMessageObject.messageOwner.attachPath);
setProgress(progress != null ? progress : 0, false);
radialProgress.setProgress(progress != null ? progress : 0, false);
invalidate();
}
} else {
@ -681,29 +687,26 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
}
if (!cacheFile.exists()) {
MediaController.getInstance().addLoadingFileObserver(fileName, this);
float setProgress = 0;
boolean progressVisible = false;
if (!FileLoader.getInstance().isLoadingFile(fileName)) {
if (cancelLoading || currentMessageObject.type != 1 || !MediaController.getInstance().canDownloadMedia(MediaController.AUTODOWNLOAD_MASK_PHOTO)) {
buttonState = 0;
progressVisible = false;
stopAnimation();
} else {
buttonState = 1;
progressVisible = true;
startAnimation();
buttonState = 1;
}
setProgress(0, false);
} else {
buttonState = 1;
progressVisible = true;
startAnimation();
buttonState = 1;
Float progress = FileLoader.getInstance().getFileProgress(fileName);
setProgress(progress != null ? progress : 0, false);
setProgress = progress != null ? progress : 0;
}
radialProgress.setBackground(getDrawableForCurrentState(), progressVisible, animated);
radialProgress.setProgress(setProgress, false);
invalidate();
} else {
MediaController.getInstance().removeLoadingFileObserver(this);
progressVisible = false;
stopAnimation();
if (currentMessageObject.type == 8 && (gifDrawable == null || gifDrawable != null && !gifDrawable.isRunning())) {
buttonState = 2;
} else if (currentMessageObject.type == 3) {
@ -711,59 +714,12 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
} else {
buttonState = -1;
}
radialProgress.setBackground(getDrawableForCurrentState(), false, animated);
invalidate();
}
}
}
private void updateAnimation() {
long newTime = System.currentTimeMillis();
long dt = newTime - lastUpdateTime;
lastUpdateTime = newTime;
radOffset += 360 * dt / 3000.0f;
float progressDiff = currentProgress - animationProgressStart;
if (progressDiff > 0) {
currentProgressTime += dt;
if (currentProgressTime >= 300) {
animatedProgressValue = currentProgress;
animationProgressStart = currentProgress;
currentProgressTime = 0;
} else {
animatedProgressValue = animationProgressStart + progressDiff * decelerateInterpolator.getInterpolation(currentProgressTime / 300.0f);
}
}
invalidateProgress();
}
private void startAnimation() {
lastUpdateTime = System.currentTimeMillis();
animationStarted = true;
invalidateProgress();
}
private void setProgress(float value, boolean animated) {
if (!animated) {
animatedProgressValue = value;
animationProgressStart = value;
} else {
animationProgressStart = animatedProgressValue;
}
currentProgress = value;
currentProgressTime = 0;
}
private void invalidateProgress() {
int offset = AndroidUtilities.dp(2);
invalidate((int)progressRect.left - offset, (int)progressRect.top - offset, (int)progressRect.right + offset * 2, (int)progressRect.bottom + offset * 2);
}
private void stopAnimation() {
radOffset = 0;
animationStarted = false;
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), photoHeight + AndroidUtilities.dp(14));
@ -791,7 +747,8 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
int size = AndroidUtilities.dp(48);
buttonX = (int)(x + (photoWidth - size) / 2.0f);
buttonY = (int)(AndroidUtilities.dp(7) + (photoHeight - size) / 2.0f);
progressRect.set(buttonX + AndroidUtilities.dp(1), buttonY + AndroidUtilities.dp(1), buttonX + AndroidUtilities.dp(47), buttonY + AndroidUtilities.dp(47));
radialProgress.setProgressRect(buttonX, buttonY, buttonX + AndroidUtilities.dp(48), buttonY + AndroidUtilities.dp(48));
deleteProgressRect.set(buttonX + AndroidUtilities.dp(3), buttonY + AndroidUtilities.dp(3), buttonX + AndroidUtilities.dp(45), buttonY + AndroidUtilities.dp(45));
}
@ -841,6 +798,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
drawTime = photoImage.getVisible();
}
radialProgress.setHideCurrentDrawable(false);
if (currentMessageObject.type == 9) {
Drawable menuDrawable = null;
@ -857,44 +815,37 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
setDrawableBounds(menuDrawable, photoImage.getImageX() + backgroundWidth - AndroidUtilities.dp(44), AndroidUtilities.dp(10));
menuDrawable.draw(canvas);
if (buttonState >= 0 && buttonState < 4) {
if (!imageDrawn) {
if (buttonState == 1 && !currentMessageObject.isSending()) {
radialProgress.swapBackground(buttonStatesDrawablesDoc[2][currentMessageObject.isOut() ? 1 : 0]);
} else {
radialProgress.swapBackground(buttonStatesDrawablesDoc[buttonState][currentMessageObject.isOut() ? 1 : 0]);
}
} else {
if (buttonState == 1 && !currentMessageObject.isSending()) {
radialProgress.swapBackground(buttonStatesDrawables[4]);
} else {
radialProgress.swapBackground(buttonStatesDrawables[buttonState]);
}
}
}
if (!imageDrawn) {
canvas.drawRect(photoImage.getImageX(), photoImage.getImageY(), photoImage.getImageX() + photoImage.getImageWidth(), photoImage.getImageY() + photoImage.getImageHeight(), docBackPaint);
if (buttonState == -1) {
Drawable drawable = currentMessageObject.isOut() ? placeholderDocOutDrawable : placeholderDocInDrawable;
setDrawableBounds(drawable, photoImage.getImageX() + AndroidUtilities.dp(19), photoImage.getImageY() + AndroidUtilities.dp(19));
drawable.draw(canvas);
}
if (currentMessageObject.isOut()) {
progressPaint.setColor(0xff81bd72);
radialProgress.setProgressColor(0xff81bd72);
} else {
progressPaint.setColor(0xffadbdcc);
radialProgress.setProgressColor(0xffadbdcc);
}
} else {
progressPaint.setColor(0xffffffff);
if (buttonState == -1) {
radialProgress.setHideCurrentDrawable(true);
}
radialProgress.setProgressColor(0xffffffff);
}
} else {
progressPaint.setColor(0xffffffff);
}
if (buttonState >= 0 && buttonState < 4) {
Drawable currentButtonDrawable = null;
if (currentMessageObject.type == 9 && !imageDrawn) {
if (buttonState == 1 && !currentMessageObject.isSending()) {
currentButtonDrawable = buttonStatesDrawablesDoc[2][currentMessageObject.isOut() ? 1 : 0];
} else {
currentButtonDrawable = buttonStatesDrawablesDoc[buttonState][currentMessageObject.isOut() ? 1 : 0];
}
} else {
if (buttonState == 1 && !currentMessageObject.isSending()) {
currentButtonDrawable = buttonStatesDrawables[4];
} else {
currentButtonDrawable = buttonStatesDrawables[buttonState];
}
}
setDrawableBounds(currentButtonDrawable, buttonX, buttonY);
currentButtonDrawable.draw(canvas);
radialProgress.setProgressColor(0xffffffff);
}
if (buttonState == -1 && currentMessageObject.isSecretPhoto()) {
@ -920,9 +871,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
}
}
if (progressVisible) {
canvas.drawArc(progressRect, -90 + radOffset, Math.max(4, 360 * animatedProgressValue), false, progressPaint);
}
radialProgress.onDraw(canvas);
if (nameLayout != null) {
canvas.save();
@ -951,22 +900,21 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
infoLayout.draw(canvas);
canvas.restore();
}
if (animationStarted) {
updateAnimation();
}
}
@Override
public void onFailedDownload(String fileName) {
updateButtonState();
updateButtonState(false);
}
@Override
public void onSuccessDownload(String fileName) {
updateButtonState();
if (currentMessageObject.type == 8 && lastDownloadedGifMessage != null && lastDownloadedGifMessage.messageOwner.id == currentMessageObject.messageOwner.id && buttonState == 2) {
didPressedButton();
radialProgress.setProgress(1, true);
if (currentMessageObject.type == 8 && lastDownloadedGifMessage != null && lastDownloadedGifMessage.messageOwner.id == currentMessageObject.messageOwner.id) {
buttonState = 2;
didPressedButton(true);
} else if (!photoNotSet) {
updateButtonState(true);
}
if (photoNotSet) {
setMessageObject(currentMessageObject);
@ -975,18 +923,15 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
@Override
public void onProgressDownload(String fileName, float progress) {
progressVisible = true;
setProgress(progress, true);
radialProgress.setProgress(progress, true);
if (buttonState != 1) {
updateButtonState();
updateButtonState(true);
}
invalidateProgress();
}
@Override
public void onProgressUpload(String fileName, float progress, boolean isEncrypted) {
setProgress(progress, true);
invalidateProgress();
radialProgress.setProgress(progress, true);
}
@Override

View File

@ -147,10 +147,10 @@ public class ChatMessageCell extends ChatBaseCell {
}
} else {
if (isChat && !messageObject.isOut()) {
maxWidth = AndroidUtilities.displaySize.x - AndroidUtilities.dp(122);
maxWidth = Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) - AndroidUtilities.dp(122);
drawName = true;
} else {
maxWidth = AndroidUtilities.displaySize.x - AndroidUtilities.dp(80);
maxWidth = Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) - AndroidUtilities.dp(80);
drawName = false;
}
}

View File

@ -30,7 +30,7 @@ import org.telegram.android.MessagesController;
import org.telegram.messenger.R;
import org.telegram.messenger.UserConfig;
import org.telegram.android.ImageReceiver;
import org.telegram.ui.Views.AvatarDrawable;
import org.telegram.ui.Components.AvatarDrawable;
public class DialogCell extends BaseCell {

View File

@ -19,8 +19,8 @@ import org.telegram.PhoneFormat.PhoneFormat;
import org.telegram.android.AndroidUtilities;
import org.telegram.android.ContactsController;
import org.telegram.messenger.TLRPC;
import org.telegram.ui.Views.AvatarDrawable;
import org.telegram.ui.Views.BackupImageView;
import org.telegram.ui.Components.AvatarDrawable;
import org.telegram.ui.Components.BackupImageView;
public class DrawerProfileCell extends FrameLayout {

View File

@ -27,7 +27,7 @@ import org.telegram.messenger.ConnectionsManager;
import org.telegram.messenger.R;
import org.telegram.messenger.TLRPC;
import org.telegram.messenger.UserConfig;
import org.telegram.ui.Views.AvatarDrawable;
import org.telegram.ui.Components.AvatarDrawable;
public class ProfileSearchCell extends BaseCell {
private static TextPaint namePaint;

View File

@ -18,8 +18,8 @@ import android.widget.TextView;
import org.telegram.android.AndroidUtilities;
import org.telegram.android.LocaleController;
import org.telegram.ui.Views.FrameLayoutFixed;
import org.telegram.ui.Views.Switch;
import org.telegram.ui.Components.FrameLayoutFixed;
import org.telegram.ui.Components.Switch;
public class TextCheckCell extends FrameLayoutFixed {

View File

@ -18,8 +18,8 @@ import android.widget.TextView;
import org.telegram.android.AndroidUtilities;
import org.telegram.android.LocaleController;
import org.telegram.ui.Views.BackupImageView;
import org.telegram.ui.Views.CheckBox;
import org.telegram.ui.Components.BackupImageView;
import org.telegram.ui.Components.CheckBox;
public class TextDetailDocumentsCell extends FrameLayout {

View File

@ -17,7 +17,7 @@ import android.widget.TextView;
import org.telegram.android.AndroidUtilities;
import org.telegram.android.LocaleController;
import org.telegram.ui.Views.FrameLayoutFixed;
import org.telegram.ui.Components.FrameLayoutFixed;
public class TextDetailSettingsCell extends FrameLayoutFixed {

View File

@ -24,9 +24,9 @@ import org.telegram.messenger.ConnectionsManager;
import org.telegram.messenger.R;
import org.telegram.messenger.TLRPC;
import org.telegram.messenger.UserConfig;
import org.telegram.ui.Views.AvatarDrawable;
import org.telegram.ui.Views.BackupImageView;
import org.telegram.ui.Views.CheckBox;
import org.telegram.ui.Components.AvatarDrawable;
import org.telegram.ui.Components.BackupImageView;
import org.telegram.ui.Components.CheckBox;
public class UserCell extends FrameLayout {

View File

@ -26,6 +26,7 @@ import android.widget.TextView;
import org.telegram.android.AndroidUtilities;
import org.telegram.android.LocaleController;
import org.telegram.messenger.ApplicationLoader;
import org.telegram.messenger.TLRPC;
import org.telegram.android.MessagesController;
import org.telegram.messenger.R;
@ -79,7 +80,7 @@ public class ChangeChatNameActivity extends BaseFragment {
TLRPC.Chat currentChat = MessagesController.getInstance().getChat(chat_id);
fragmentView = new LinearLayout(inflater.getContext());
fragmentView = new LinearLayout(getParentActivity());
fragmentView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
((LinearLayout) fragmentView).setOrientation(LinearLayout.VERTICAL);
fragmentView.setOnTouchListener(new View.OnTouchListener() {
@ -89,7 +90,7 @@ public class ChangeChatNameActivity extends BaseFragment {
}
});
firstNameField = new EditText(inflater.getContext());
firstNameField = new EditText(getParentActivity());
firstNameField.setText(currentChat.title);
firstNameField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
firstNameField.setHintTextColor(0xff979797);

View File

@ -25,6 +25,7 @@ import android.widget.TextView;
import org.telegram.android.AndroidUtilities;
import org.telegram.android.LocaleController;
import org.telegram.messenger.ApplicationLoader;
import org.telegram.messenger.TLObject;
import org.telegram.messenger.TLRPC;
import org.telegram.messenger.ConnectionsManager;
@ -74,7 +75,7 @@ public class ChangeNameActivity extends BaseFragment {
user = UserConfig.getCurrentUser();
}
fragmentView = new LinearLayout(inflater.getContext());
fragmentView = new LinearLayout(getParentActivity());
fragmentView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
((LinearLayout) fragmentView).setOrientation(LinearLayout.VERTICAL);
fragmentView.setOnTouchListener(new View.OnTouchListener() {
@ -84,7 +85,7 @@ public class ChangeNameActivity extends BaseFragment {
}
});
firstNameField = new EditText(inflater.getContext());
firstNameField = new EditText(getParentActivity());
firstNameField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
firstNameField.setHintTextColor(0xff979797);
firstNameField.setTextColor(0xff212121);
@ -116,7 +117,7 @@ public class ChangeNameActivity extends BaseFragment {
}
});
lastNameField = new EditText(inflater.getContext());
lastNameField = new EditText(getParentActivity());
lastNameField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
lastNameField.setHintTextColor(0xff979797);
lastNameField.setTextColor(0xff212121);

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,163 @@
/*
* This is the source code of Telegram for Android v. 1.7.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.AlertDialog;
import android.content.DialogInterface;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import org.telegram.PhoneFormat.PhoneFormat;
import org.telegram.android.AndroidUtilities;
import org.telegram.android.LocaleController;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.R;
import org.telegram.messenger.TLRPC;
import org.telegram.messenger.UserConfig;
import org.telegram.ui.ActionBar.ActionBar;
import org.telegram.ui.ActionBar.BaseFragment;
public class ChangePhoneHelpActivity extends BaseFragment {
@Override
public View createView(LayoutInflater inflater, ViewGroup container) {
if (fragmentView == null) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
TLRPC.User user = UserConfig.getCurrentUser();
String value;
if (user != null && user.phone != null && user.phone.length() != 0) {
value = PhoneFormat.getInstance().format("+" + user.phone);
} else {
value = LocaleController.getString("NumberUnknown", R.string.NumberUnknown);
}
actionBar.setTitle(value);
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
}
}
});
fragmentView = new RelativeLayout(getParentActivity());
fragmentView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
RelativeLayout relativeLayout = (RelativeLayout) fragmentView;
ScrollView scrollView = new ScrollView(getParentActivity());
relativeLayout.addView(scrollView);
RelativeLayout.LayoutParams layoutParams3 = (RelativeLayout.LayoutParams) scrollView.getLayoutParams();
layoutParams3.width = RelativeLayout.LayoutParams.MATCH_PARENT;
layoutParams3.height = RelativeLayout.LayoutParams.WRAP_CONTENT;
layoutParams3.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
scrollView.setLayoutParams(layoutParams3);
LinearLayout linearLayout = new LinearLayout(getParentActivity());
linearLayout.setOrientation(LinearLayout.VERTICAL);
linearLayout.setPadding(0, AndroidUtilities.dp(20), 0, AndroidUtilities.dp(20));
scrollView.addView(linearLayout);
ScrollView.LayoutParams layoutParams = (ScrollView.LayoutParams) linearLayout.getLayoutParams();
layoutParams.width = ScrollView.LayoutParams.MATCH_PARENT;
layoutParams.height = ScrollView.LayoutParams.WRAP_CONTENT;
linearLayout.setLayoutParams(layoutParams);
ImageView imageView = new ImageView(getParentActivity());
imageView.setImageResource(R.drawable.phone_change);
linearLayout.addView(imageView);
LinearLayout.LayoutParams layoutParams2 = (LinearLayout.LayoutParams)imageView.getLayoutParams();
layoutParams2.width = LinearLayout.LayoutParams.WRAP_CONTENT;
layoutParams2.height = LinearLayout.LayoutParams.WRAP_CONTENT;
layoutParams2.gravity = Gravity.CENTER_HORIZONTAL;
imageView.setLayoutParams(layoutParams2);
TextView textView = new TextView(getParentActivity());
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
textView.setGravity(Gravity.CENTER_HORIZONTAL);
textView.setTextColor(0xff212121);
try {
textView.setText(AndroidUtilities.replaceBold(LocaleController.getString("PhoneNumberHelp", R.string.PhoneNumberHelp)));
} catch (Exception e) {
FileLog.e("tmessages", e);
textView.setText(LocaleController.getString("PhoneNumberHelp", R.string.PhoneNumberHelp));
}
linearLayout.addView(textView);
layoutParams2 = (LinearLayout.LayoutParams)textView.getLayoutParams();
layoutParams2.width = LinearLayout.LayoutParams.WRAP_CONTENT;
layoutParams2.height = LinearLayout.LayoutParams.WRAP_CONTENT;
layoutParams2.gravity = Gravity.CENTER_HORIZONTAL;
layoutParams2.leftMargin = AndroidUtilities.dp(20);
layoutParams2.rightMargin = AndroidUtilities.dp(20);
layoutParams2.topMargin = AndroidUtilities.dp(56);
textView.setLayoutParams(layoutParams2);
textView = new TextView(getParentActivity());
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
textView.setGravity(Gravity.CENTER_HORIZONTAL);
textView.setTextColor(0xff4d83b3);
textView.setText(LocaleController.getString("PhoneNumberChange", R.string.PhoneNumberChange));
textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
textView.setPadding(0, AndroidUtilities.dp(10), 0, AndroidUtilities.dp(10));
linearLayout.addView(textView);
layoutParams2 = (LinearLayout.LayoutParams)textView.getLayoutParams();
layoutParams2.width = LinearLayout.LayoutParams.WRAP_CONTENT;
layoutParams2.height = LinearLayout.LayoutParams.WRAP_CONTENT;
layoutParams2.gravity = Gravity.CENTER_HORIZONTAL;
layoutParams2.leftMargin = AndroidUtilities.dp(20);
layoutParams2.rightMargin = AndroidUtilities.dp(20);
layoutParams2.topMargin = AndroidUtilities.dp(46);
textView.setLayoutParams(layoutParams2);
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (getParentActivity() == null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
builder.setMessage(LocaleController.getString("PhoneNumberAlert", R.string.PhoneNumberAlert));
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
presentFragment(new ChangePhoneActivity(), true);
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
}
});
} else {
ViewGroup parent = (ViewGroup)fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
}
}
return fragmentView;
}
}

View File

@ -34,6 +34,7 @@ import org.telegram.android.LocaleController;
import org.telegram.android.MessagesController;
import org.telegram.android.MessagesStorage;
import org.telegram.android.NotificationCenter;
import org.telegram.messenger.ApplicationLoader;
import org.telegram.messenger.ConnectionsManager;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.R;
@ -84,7 +85,7 @@ public class ChangeUsernameActivity extends BaseFragment {
user = UserConfig.getCurrentUser();
}
fragmentView = new LinearLayout(inflater.getContext());
fragmentView = new LinearLayout(getParentActivity());
fragmentView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
((LinearLayout) fragmentView).setOrientation(LinearLayout.VERTICAL);
fragmentView.setOnTouchListener(new View.OnTouchListener() {
@ -94,7 +95,7 @@ public class ChangeUsernameActivity extends BaseFragment {
}
});
firstNameField = new EditText(inflater.getContext());
firstNameField = new EditText(getParentActivity());
firstNameField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
firstNameField.setHintTextColor(0xff979797);
firstNameField.setTextColor(0xff212121);
@ -132,7 +133,7 @@ public class ChangeUsernameActivity extends BaseFragment {
firstNameField.setSelection(firstNameField.length());
}
checkTextView = new TextView(inflater.getContext());
checkTextView = new TextView(getParentActivity());
checkTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
checkTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
((LinearLayout) fragmentView).addView(checkTextView);
@ -145,7 +146,7 @@ public class ChangeUsernameActivity extends BaseFragment {
layoutParams.rightMargin = AndroidUtilities.dp(24);
checkTextView.setLayoutParams(layoutParams);
TextView helpTextView = new TextView(inflater.getContext());
TextView helpTextView = new TextView(getParentActivity());
helpTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
helpTextView.setTextColor(0xff6d6d72);
helpTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);

View File

@ -49,7 +49,9 @@ import org.telegram.android.LocaleController;
import org.telegram.android.MediaController;
import org.telegram.android.MessagesStorage;
import org.telegram.android.NotificationsController;
import org.telegram.android.SecretChatHelper;
import org.telegram.android.SendMessagesHelper;
import org.telegram.messenger.ApplicationLoader;
import org.telegram.messenger.FileLoader;
import org.telegram.messenger.TLRPC;
import org.telegram.android.ContactsController;
@ -75,16 +77,16 @@ import org.telegram.ui.Cells.ChatMessageCell;
import org.telegram.ui.ActionBar.ActionBar;
import org.telegram.ui.ActionBar.ActionBarMenu;
import org.telegram.ui.ActionBar.ActionBarMenuItem;
import org.telegram.ui.Views.AvatarDrawable;
import org.telegram.ui.Views.BackupImageView;
import org.telegram.ui.Components.AvatarDrawable;
import org.telegram.ui.Components.BackupImageView;
import org.telegram.ui.ActionBar.BaseFragment;
import org.telegram.ui.Views.ChatActivityEnterView;
import org.telegram.ui.Components.ChatActivityEnterView;
import org.telegram.android.ImageReceiver;
import org.telegram.ui.Views.FrameLayoutFixed;
import org.telegram.ui.Views.LayoutListView;
import org.telegram.ui.Views.SizeNotifierRelativeLayout;
import org.telegram.ui.Views.TimerDrawable;
import org.telegram.ui.Views.TypingDotsDrawable;
import org.telegram.ui.Components.FrameLayoutFixed;
import org.telegram.ui.Components.LayoutListView;
import org.telegram.ui.Components.SizeNotifierRelativeLayout;
import org.telegram.ui.Components.TimerDrawable;
import org.telegram.ui.Components.TypingDotsDrawable;
import java.io.File;
import java.util.ArrayList;
@ -429,8 +431,8 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
typingDotsDrawable = new TypingDotsDrawable();
typingDotsDrawable.setIsChat(currentChat != null);
if (currentEncryptedChat != null && AndroidUtilities.getMyLayerVersion(currentEncryptedChat.layer) != SendMessagesHelper.CURRENT_SECRET_CHAT_LAYER) {
SendMessagesHelper.getInstance().sendNotifyLayerMessage(currentEncryptedChat, null);
if (currentEncryptedChat != null && AndroidUtilities.getMyLayerVersion(currentEncryptedChat.layer) != SecretChatHelper.CURRENT_SECRET_CHAT_LAYER) {
SecretChatHelper.getInstance().sendNotifyLayerMessage(currentEncryptedChat, null);
}
return true;
@ -2431,7 +2433,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
} else if (obj.isOut() && !obj.isUnread()) {
break;
}
if (obj.messageOwner.date <= date) {
if (obj.messageOwner.date - 1 <= date) {
obj.setIsRead();
}
}

View File

@ -6,7 +6,7 @@
* Copyright Nikolai Kudashov, 2013-2014.
*/
package org.telegram.ui.Views;
package org.telegram.ui.Components;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
@ -22,7 +22,7 @@ import org.telegram.messenger.FileLog;
import org.telegram.messenger.R;
import org.telegram.messenger.TLRPC;
import org.telegram.messenger.UserConfig;
import org.telegram.ui.ApplicationLoader;
import org.telegram.messenger.ApplicationLoader;
import java.util.Locale;
@ -34,9 +34,12 @@ public class AvatarDrawable extends Drawable {
private static int[] arrColorsProfiles = {0xffd86f65, 0xfff69d61, 0xfffabb3c, 0xff67b35d, 0xff56a2bb, 0xff5c98cd, 0xff8c79d2, 0xfff37fa6};
private static int[] arrColorsProfilesBack = {0xffca6056, 0xfff18944, 0xfff2b02c, 0xff56a14c, 0xff4492ac, 0xff4c84b6, 0xff7d6ac4, 0xffe66b94};
private static int[] arrColorsProfilesText = {0xfff9cbc5, 0xfffdddc8, 0xfffce5bb, 0xffc0edba, 0xffb8e2f0, 0xffb3d7f7, 0xffcdc4ed, 0xfffed1e0};
private static int[] arrColorsNames = {0xffca5650, 0xffd87b29, 0xffc7a21c, 0xff50b232, 0xff42b1a8, 0xff4e92cc, 0xff4e92cc, 0xffdb5b9d};
private static int[] arrColorsButtons = {R.drawable.bar_selector_red, R.drawable.bar_selector_orange, R.drawable.bar_selector_yellow,
R.drawable.bar_selector_green, R.drawable.bar_selector_cyan, R.drawable.bar_selector_blue, R.drawable.bar_selector_violet, R.drawable.bar_selector_pink};
private static Drawable broadcastDrawable;
private static Drawable photoDrawable;
@ -132,6 +135,10 @@ public class AvatarDrawable extends Drawable {
return arrColorsProfilesBack[getColorIndex(id)];
}
public static int getNameColorForId(int id) {
return arrColorsNames[getColorIndex(id)];
}
public void setInfo(TLRPC.User user) {
if (user != null) {
setInfo(user.id, user.first_name, user.last_name, false);

View File

@ -6,7 +6,7 @@
* Copyright Nikolai Kudashov, 2013.
*/
package org.telegram.ui.Views;
package org.telegram.ui.Components;
import android.app.Activity;
import android.content.Intent;

View File

@ -6,7 +6,7 @@
* Copyright Nikolai Kudashov, 2013.
*/
package org.telegram.ui.Views;
package org.telegram.ui.Components;
import android.content.Context;
import android.graphics.Bitmap;

View File

@ -6,12 +6,13 @@
* Copyright Nikolai Kudashov, 2013-2014.
*/
package org.telegram.ui.Views;
package org.telegram.ui.Components;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Rect;
import android.os.Build;
import android.os.PowerManager;
import android.text.Editable;
import android.text.TextWatcher;
@ -29,7 +30,6 @@ 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;
@ -43,11 +43,12 @@ import org.telegram.messenger.FileLog;
import org.telegram.android.NotificationCenter;
import org.telegram.messenger.R;
import org.telegram.messenger.TLRPC;
import org.telegram.messenger.UserConfig;
import org.telegram.ui.AnimationCompat.AnimatorListenerAdapterProxy;
import org.telegram.ui.AnimationCompat.AnimatorSetProxy;
import org.telegram.ui.AnimationCompat.ObjectAnimatorProxy;
import org.telegram.ui.AnimationCompat.ViewProxy;
import org.telegram.ui.ApplicationLoader;
import org.telegram.messenger.ApplicationLoader;
public class ChatActivityEnterView implements NotificationCenter.NotificationCenterDelegate, SizeNotifierRelativeLayout.SizeNotifierRelativeLayoutDelegate {
@ -60,7 +61,6 @@ public class ChatActivityEnterView implements NotificationCenter.NotificationCen
private EditText messsageEditText;
private ImageButton sendButton;
private PopupWindow emojiPopup;
private ImageView emojiButton;
private EmojiView emojiView;
private TextView recordTimeText;
@ -76,6 +76,9 @@ public class ChatActivityEnterView implements NotificationCenter.NotificationCen
private int runningAnimationType;
private int audioInterfaceState;
private WindowManager.LayoutParams windowLayoutParams;
private boolean showingEmoji;
private int keyboardHeight;
private int keyboardHeightLand;
private boolean keyboardVisible;
@ -124,6 +127,7 @@ public class ChatActivityEnterView implements NotificationCenter.NotificationCen
if (sizeNotifierRelativeLayout != null) {
sizeNotifierRelativeLayout.delegate = null;
}
removeEmojiWindow();
}
public void setContainerView(Activity activity, View containerView) {
@ -160,18 +164,14 @@ public class ChatActivityEnterView implements NotificationCenter.NotificationCen
emojiButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (emojiPopup == null) {
showEmojiPopup(true);
} else {
showEmojiPopup(!emojiPopup.isShowing());
}
showEmojiPopup(!showingEmoji);
}
});
messsageEditText.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View view, int i, KeyEvent keyEvent) {
if (i == 4 && !keyboardVisible && emojiPopup != null && emojiPopup.isShowing()) {
if (i == 4 && !keyboardVisible && showingEmoji) {
if (keyEvent.getAction() == 1) {
showEmojiPopup(false);
}
@ -187,7 +187,7 @@ public class ChatActivityEnterView implements NotificationCenter.NotificationCen
messsageEditText.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (emojiPopup != null && emojiPopup.isShowing()) {
if (showingEmoji) {
showEmojiPopup(false);
}
}
@ -291,7 +291,7 @@ public class ChatActivityEnterView implements NotificationCenter.NotificationCen
if ((int) dialog_id > 0) {
currentUser = MessagesController.getInstance().getUser((int) dialog_id);
}
if (currentUser != null && currentUser.status != null && currentUser.status.expires < currentTime) {
if (currentUser != null && (currentUser.id == UserConfig.getClientUserId() || currentUser.status != null && currentUser.status.expires < currentTime)) {
return;
}
lastTypingTimeSend = System.currentTimeMillis();
@ -609,13 +609,47 @@ public class ChatActivityEnterView implements NotificationCenter.NotificationCen
}
private void showEmojiPopup(boolean show) {
showingEmoji = show;
if (show) {
if (emojiPopup == null) {
createEmojiPopup();
if (emojiView == null) {
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 symbol) {
int i = messsageEditText.getSelectionEnd();
if (i < 0) {
i = 0;
}
try {
CharSequence localCharSequence = Emoji.replaceEmoji(symbol, messsageEditText.getPaint().getFontMetricsInt(), AndroidUtilities.dp(20));
messsageEditText.setText(messsageEditText.getText().insert(i, localCharSequence));
int j = i + localCharSequence.length();
messsageEditText.setSelection(j, j);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
});
windowLayoutParams = new WindowManager.LayoutParams();
windowLayoutParams.gravity = Gravity.BOTTOM | Gravity.LEFT;
if (Build.VERSION.SDK_INT >= 21) {
windowLayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
} else {
windowLayoutParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_PANEL;
windowLayoutParams.token = parentActivity.getWindow().getDecorView().getWindowToken();
}
windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
}
int currentHeight;
WindowManager manager = (WindowManager) ApplicationLoader.applicationContext.getSystemService(Activity.WINDOW_SERVICE);
int rotation = manager.getDefaultDisplay().getRotation();
WindowManager wm = (WindowManager) ApplicationLoader.applicationContext.getSystemService(Activity.WINDOW_SERVICE);
int rotation = wm.getDefaultDisplay().getRotation();
if (keyboardHeight <= 0) {
keyboardHeight = ApplicationLoader.applicationContext.getSharedPreferences("emoji", 0).getInt("kbd_height", AndroidUtilities.dp(200));
}
@ -627,16 +661,24 @@ public class ChatActivityEnterView implements NotificationCenter.NotificationCen
} else {
currentHeight = keyboardHeight;
}
emojiPopup.setHeight(View.MeasureSpec.makeMeasureSpec(currentHeight, View.MeasureSpec.EXACTLY));
if (sizeNotifierRelativeLayout != null) {
emojiPopup.setWidth(View.MeasureSpec.makeMeasureSpec(AndroidUtilities.displaySize.x, View.MeasureSpec.EXACTLY));
}
windowLayoutParams.height = currentHeight;
windowLayoutParams.width = AndroidUtilities.displaySize.x;
try {
emojiPopup.showAtLocation(parentActivity.getWindow().getDecorView(), Gravity.BOTTOM | Gravity.LEFT, 0, 0);
if (emojiView.getParent() != null) {
wm.removeViewImmediate(emojiView);
}
} catch (Exception e) {
FileLog.e("tmessages", e);
}
try {
wm.addView(emojiView, windowLayoutParams);
} catch (Exception e) {
FileLog.e("tmessages", e);
return;
}
if (!keyboardVisible) {
if (sizeNotifierRelativeLayout != null) {
sizeNotifierRelativeLayout.setPadding(0, 0, 0, currentHeight);
@ -650,9 +692,7 @@ public class ChatActivityEnterView implements NotificationCenter.NotificationCen
if (emojiButton != null) {
emojiButton.setImageResource(R.drawable.ic_msg_panel_smiles);
}
if (emojiPopup != null) {
emojiPopup.dismiss();
}
removeEmojiWindow();
if (sizeNotifierRelativeLayout != null) {
sizeNotifierRelativeLayout.post(new Runnable() {
public void run() {
@ -664,38 +704,24 @@ public class ChatActivityEnterView implements NotificationCenter.NotificationCen
}
}
public void hideEmojiPopup() {
if (emojiPopup != null && emojiPopup.isShowing()) {
showEmojiPopup(false);
private void removeEmojiWindow() {
if (emojiView == null) {
return;
}
try {
if (emojiView.getParent() != null) {
WindowManager wm = (WindowManager) ApplicationLoader.applicationContext.getSystemService(Context.WINDOW_SERVICE);
wm.removeViewImmediate(emojiView);
}
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
private void createEmojiPopup() {
if (parentActivity == null) {
return;
public void hideEmojiPopup() {
if (showingEmoji) {
showEmojiPopup(false);
}
emojiView = new EmojiView(parentActivity);
emojiView.setListener(new EmojiView.Listener() {
public void onBackspace() {
messsageEditText.dispatchKeyEvent(new KeyEvent(0, 67));
}
public void onEmojiSelected(String symbol) {
int i = messsageEditText.getSelectionEnd();
if (i < 0) {
i = 0;
}
try {
CharSequence localCharSequence = Emoji.replaceEmoji(symbol, messsageEditText.getPaint().getFontMetricsInt(), AndroidUtilities.dp(20));
messsageEditText.setText(messsageEditText.getText().insert(i, localCharSequence));
int j = i + localCharSequence.length();
messsageEditText.setSelection(j, j);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
});
emojiPopup = new PopupWindow(emojiView);
}
public void setDelegate(ChatActivityEnterViewDelegate delegate) {
@ -754,7 +780,7 @@ public class ChatActivityEnterView implements NotificationCenter.NotificationCen
}
public boolean isEmojiPopupShowing() {
return emojiPopup != null && emojiPopup.isShowing();
return showingEmoji;
}
public void addToAttachLayout(View view) {
@ -778,11 +804,11 @@ public class ChatActivityEnterView implements NotificationCenter.NotificationCen
Rect localRect = new Rect();
parentActivity.getWindow().getDecorView().getWindowVisibleDisplayFrame(localRect);
WindowManager manager = (WindowManager) ApplicationLoader.applicationContext.getSystemService(Activity.WINDOW_SERVICE);
if (manager == null || manager.getDefaultDisplay() == null) {
WindowManager wm = (WindowManager) ApplicationLoader.applicationContext.getSystemService(Activity.WINDOW_SERVICE);
if (wm == null || wm.getDefaultDisplay() == null) {
return;
}
int rotation = manager.getDefaultDisplay().getRotation();
int rotation = wm.getDefaultDisplay().getRotation();
if (height > AndroidUtilities.dp(50) && keyboardVisible) {
if (rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90) {
@ -794,25 +820,23 @@ public class ChatActivityEnterView implements NotificationCenter.NotificationCen
}
}
if (emojiPopup != null && emojiPopup.isShowing()) {
if (showingEmoji) {
int newHeight = 0;
if (rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90) {
newHeight = keyboardHeightLand;
} else {
newHeight = keyboardHeight;
}
final WindowManager.LayoutParams layoutParams = (WindowManager.LayoutParams) emojiPopup.getContentView().getLayoutParams();
if (layoutParams.width != AndroidUtilities.displaySize.x || layoutParams.height != newHeight) {
WindowManager wm = (WindowManager) ApplicationLoader.applicationContext.getSystemService(Context.WINDOW_SERVICE);
layoutParams.width = AndroidUtilities.displaySize.x;
layoutParams.height = newHeight;
wm.updateViewLayout(emojiPopup.getContentView(), layoutParams);
if (windowLayoutParams.width != AndroidUtilities.displaySize.x || windowLayoutParams.height != newHeight) {
windowLayoutParams.width = AndroidUtilities.displaySize.x;
windowLayoutParams.height = newHeight;
wm.updateViewLayout(emojiView, windowLayoutParams);
if (!keyboardVisible) {
sizeNotifierRelativeLayout.post(new Runnable() {
@Override
public void run() {
if (sizeNotifierRelativeLayout != null) {
sizeNotifierRelativeLayout.setPadding(0, 0, 0, layoutParams.height);
sizeNotifierRelativeLayout.setPadding(0, 0, 0, windowLayoutParams.height);
sizeNotifierRelativeLayout.requestLayout();
}
}
@ -825,7 +849,7 @@ public class ChatActivityEnterView implements NotificationCenter.NotificationCen
keyboardVisible = height > 0;
if (keyboardVisible && sizeNotifierRelativeLayout.getPaddingBottom() > 0) {
showEmojiPopup(false);
} else if (!keyboardVisible && keyboardVisible != oldValue && emojiPopup != null && emojiPopup.isShowing()) {
} else if (!keyboardVisible && keyboardVisible != oldValue && showingEmoji) {
showEmojiPopup(false);
}
}

View File

@ -6,7 +6,7 @@
* Copyright Nikolai Kudashov, 2013-2014.
*/
package org.telegram.ui.Views;
package org.telegram.ui.Components;
import android.content.Context;
import android.graphics.Bitmap;

View File

@ -6,7 +6,7 @@
* Copyright Nikolai Kudashov, 2013-2014.
*/
package org.telegram.ui.Views;
package org.telegram.ui.Components;
import android.content.Context;
import android.graphics.Bitmap;

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.telegram.ui.Views;
package org.telegram.ui.Components;
import android.content.Context;
import android.graphics.Canvas;

View File

@ -6,7 +6,7 @@
* Copyright Nikolai Kudashov, 2013.
*/
package org.telegram.ui.Views;
package org.telegram.ui.Components;
import android.content.Context;
import android.database.DataSetObserver;

View File

@ -6,7 +6,7 @@
* Copyright Nikolai Kudashov, 2013.
*/
package org.telegram.ui.Views;
package org.telegram.ui.Components;
import android.content.Context;
import android.graphics.drawable.Drawable;

View File

@ -22,7 +22,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
package org.telegram.ui.Views;
package org.telegram.ui.Components;
import android.graphics.Bitmap;
import android.graphics.Canvas;

View File

@ -5,7 +5,7 @@
*
* Copyright Nikolai Kudashov, 2013.
*/
package org.telegram.ui.Views;
package org.telegram.ui.Components;
import java.util.HashMap;
import java.util.LinkedList;

View File

@ -6,7 +6,7 @@
* Copyright Nikolai Kudashov, 2013-2014.
*/
package org.telegram.ui.Views;
package org.telegram.ui.Components;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
@ -14,9 +14,11 @@ import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import org.telegram.android.AndroidUtilities;
import org.telegram.messenger.TLRPC;
import org.telegram.messenger.Utilities;
public class IdenticonDrawable extends Drawable {
private byte[] data;
private Paint paint = new Paint();
private int colors[] = {
@ -26,23 +28,16 @@ public class IdenticonDrawable extends Drawable {
0xff2f99c9
};
int get_bits(int bitOffset, int numBits) {
numBits = (int)Math.pow(2, numBits) - 1;
int offset = bitOffset / 8;
bitOffset %= 8;
int val = data[offset + 3] << 24 | data[offset + 2] << 16 | data[offset + 1] << 8 | data[offset];
return (val >> bitOffset) & numBits;
private int getBits(int bitOffset) {
return (data[bitOffset / 8] >> (bitOffset % 8)) & 0x3;
}
public void setBytes(byte[] bytes) {
if (bytes == null) {
return;
}
data = Utilities.computeSHA1(bytes);
if (data.length < 128) {
byte[] temp = new byte[128];
System.arraycopy(data, 0, temp, 0, data.length);
data = temp;
public void setEncryptedChat(TLRPC.EncryptedChat encryptedChat) {
data = encryptedChat.key_hash;
if (data == null) {
byte[] sha1 = Utilities.computeSHA1(encryptedChat.auth_key);
encryptedChat.key_hash = data = new byte[16];
System.arraycopy(sha1, 0, data, 0, data.length);
}
invalidateSelf();
}
@ -59,7 +54,7 @@ public class IdenticonDrawable extends Drawable {
float yOffset = Math.max(0, (getBounds().height() - rectSize * 8) / 2);
for (int iy = 0; iy < 8; iy++) {
for (int ix = 0; ix < 8; ix++) {
int byteValue = get_bits(bitPointer, 2);
int byteValue = getBits(bitPointer);
bitPointer += 2;
int colorIndex = Math.abs(byteValue) % 4;
paint.setColor(colors[colorIndex]);

View File

@ -6,7 +6,7 @@
* Copyright Nikolai Kudashov, 2013.
*/
package org.telegram.ui.Views;
package org.telegram.ui.Components;
import android.content.Context;
import android.util.AttributeSet;

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.telegram.ui.Views;
package org.telegram.ui.Components;
import android.content.Context;
import android.content.res.ColorStateList;

View File

@ -6,7 +6,7 @@
* Copyright Nikolai Kudashov, 2013.
*/
package org.telegram.ui.Views;
package org.telegram.ui.Components;
import java.util.Locale;

View File

@ -6,7 +6,7 @@
* Copyright Nikolai Kudashov, 2013-2014.
*/
package org.telegram.ui.Views;
package org.telegram.ui.Components;
import android.content.Context;
import android.graphics.Canvas;

View File

@ -6,7 +6,7 @@
* Copyright Nikolai Kudashov, 2013-2014.
*/
package org.telegram.ui.Views;
package org.telegram.ui.Components;
import android.graphics.Canvas;
import android.graphics.Paint;

View File

@ -0,0 +1,163 @@
/*
* This is the source code of Telegram for Android v. 2.0.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.Components;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.animation.DecelerateInterpolator;
import org.telegram.android.AndroidUtilities;
public class RadialProgress {
private long lastUpdateTime = 0;
private float radOffset = 0;
private float currentProgress = 0;
private float animationProgressStart = 0;
private long currentProgressTime = 0;
private float animatedProgressValue = 0;
private RectF progressRect = new RectF();
private RectF cicleRect = new RectF();
private View parent = null;
private float animatedAlphaValue = 1.0f;
private boolean currentWithRound;
private boolean previousWithRound;
private Drawable currentDrawable;
private Drawable previousDrawable;
private boolean hideCurrentDrawable;
private static DecelerateInterpolator decelerateInterpolator = null;
private static Paint progressPaint = null;
public RadialProgress(View parentView) {
if (decelerateInterpolator == null) {
decelerateInterpolator = new DecelerateInterpolator();
progressPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
progressPaint.setStyle(Paint.Style.STROKE);
progressPaint.setStrokeCap(Paint.Cap.ROUND);
progressPaint.setStrokeWidth(AndroidUtilities.dp(2));
progressPaint.setColor(0xffffffff);
}
parent = parentView;
}
public void setProgressRect(int left, int top, int right, int bottom) {
progressRect.set(left, top, right, bottom);
}
private void updateAnimation() {
long newTime = System.currentTimeMillis();
long dt = newTime - lastUpdateTime;
lastUpdateTime = newTime;
if (animatedProgressValue != 1) {
radOffset += 360 * dt / 3000.0f;
float progressDiff = currentProgress - animationProgressStart;
if (progressDiff > 0) {
currentProgressTime += dt;
if (currentProgressTime >= 300) {
animatedProgressValue = currentProgress;
animationProgressStart = currentProgress;
currentProgressTime = 0;
} else {
animatedProgressValue = animationProgressStart + progressDiff * decelerateInterpolator.getInterpolation(currentProgressTime / 300.0f);
}
}
invalidateParent();
}
if (animatedProgressValue >= 1 && previousDrawable != null) {
animatedAlphaValue -= dt / 200.0f;
if (animatedAlphaValue <= 0) {
animatedAlphaValue = 0.0f;
previousDrawable = null;
}
invalidateParent();
}
}
public void setProgressColor(int color) {
progressPaint.setColor(color);
}
public void setHideCurrentDrawable(boolean value) {
hideCurrentDrawable = value;
}
public void setProgress(float value, boolean animated) {
if (!animated) {
animatedProgressValue = value;
animationProgressStart = value;
} else {
animationProgressStart = animatedProgressValue;
}
currentProgress = value;
currentProgressTime = 0;
invalidateParent();
}
private void invalidateParent() {
int offset = AndroidUtilities.dp(2);
parent.invalidate((int)progressRect.left - offset, (int)progressRect.top - offset, (int)progressRect.right + offset * 2, (int)progressRect.bottom + offset * 2);
}
public void setBackground(Drawable drawable, boolean withRound, boolean animated) {
lastUpdateTime = System.currentTimeMillis();
if (animated && currentDrawable != drawable) {
setProgress(1, animated);
previousDrawable = currentDrawable;
previousWithRound = currentWithRound;
animatedAlphaValue = 1.0f;
} else {
previousDrawable = null;
previousWithRound = false;
}
currentWithRound = withRound;
currentDrawable = drawable;
invalidateParent();
}
public void swapBackground(Drawable drawable) {
currentDrawable = drawable;
}
public void onDraw(Canvas canvas) {
if (previousDrawable != null) {
previousDrawable.setAlpha((int)(255 * animatedAlphaValue));
previousDrawable.setBounds((int)progressRect.left, (int)progressRect.top, (int)progressRect.right, (int)progressRect.bottom);
previousDrawable.draw(canvas);
}
if (!hideCurrentDrawable && currentDrawable != null) {
if (previousDrawable != null) {
currentDrawable.setAlpha((int)(255 * (1.0f - animatedAlphaValue)));
} else {
currentDrawable.setAlpha(255);
}
currentDrawable.setBounds((int)progressRect.left, (int)progressRect.top, (int)progressRect.right, (int)progressRect.bottom);
currentDrawable.draw(canvas);
}
if (currentWithRound || previousWithRound) {
int diff = AndroidUtilities.dp(1);
if (previousWithRound) {
progressPaint.setAlpha((int)(255 * animatedAlphaValue));
} else {
progressPaint.setAlpha(255);
}
cicleRect.set(progressRect.left + diff, progressRect.top + diff, progressRect.right - diff, progressRect.bottom - diff);
canvas.drawArc(cicleRect, -90 + radOffset, Math.max(4, 360 * animatedProgressValue), false, progressPaint);
updateAnimation();
}
}
}

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.telegram.ui.Views;
package org.telegram.ui.Components;
import android.content.Context;
import android.hardware.SensorManager;

View File

@ -6,7 +6,7 @@
* Copyright Nikolai Kudashov, 2013-2014.
*/
package org.telegram.ui.Views;
package org.telegram.ui.Components;
import android.content.Context;
import android.graphics.Canvas;

View File

@ -6,7 +6,7 @@
* Copyright Nikolai Kudashov, 2013.
*/
package org.telegram.ui.Views;
package org.telegram.ui.Components;
import android.content.Context;
import android.graphics.Canvas;

View File

@ -6,7 +6,7 @@
* Copyright Nikolai Kudashov, 2013.
*/
package org.telegram.ui.Views;
package org.telegram.ui.Components;
import android.content.Context;
import android.graphics.Canvas;

View File

@ -0,0 +1,52 @@
/*
* This is the source code of Telegram for Android v. 2.0.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.Components;
import android.content.Context;
import android.os.Bundle;
import android.widget.LinearLayout;
public class SlideView extends LinearLayout {
public SlideView(Context context) {
super(context);
}
public String getHeaderName() {
return "";
}
public void setParams(Bundle params) {
}
public void onBackPressed() {
}
public void onShow() {
}
public void onDestroyActivity() {
}
public void onNextPressed() {
}
public void saveStateParams(Bundle bundle) {
}
public void restoreStateParams(Bundle bundle) {
}
}

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.telegram.ui.Views;
package org.telegram.ui.Components;
import android.content.Context;
import android.graphics.Canvas;

View File

@ -6,7 +6,7 @@
* Copyright Nikolai Kudashov, 2013-2014.
*/
package org.telegram.ui.Views;
package org.telegram.ui.Components;
import android.content.Context;
import android.graphics.Canvas;

View File

@ -0,0 +1,35 @@
/*
* This is the source code of Telegram for Android v. 1.7.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.Components;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.text.TextPaint;
import android.text.style.MetricAffectingSpan;
public class TypefaceSpan extends MetricAffectingSpan {
private Typeface mTypeface;
public TypefaceSpan(Typeface typeface) {
mTypeface = typeface;
}
@Override
public void updateMeasureState(TextPaint p) {
p.setTypeface(mTypeface);
p.setFlags(p.getFlags() | Paint.SUBPIXEL_TEXT_FLAG);
}
@Override
public void updateDrawState(TextPaint tp) {
tp.setTypeface(mTypeface);
tp.setFlags(tp.getFlags() | Paint.SUBPIXEL_TEXT_FLAG);
}
}

View File

@ -6,7 +6,7 @@
* Copyright Nikolai Kudashov, 2013-2014.
*/
package org.telegram.ui.Views;
package org.telegram.ui.Components;
import android.graphics.Canvas;
import android.graphics.ColorFilter;

View File

@ -6,7 +6,7 @@
* Copyright Nikolai Kudashov, 2013-2014.
*/
package org.telegram.ui.Views;
package org.telegram.ui.Components;
import android.text.TextPaint;
import android.text.style.URLSpan;

View File

@ -6,7 +6,7 @@
* Copyright Nikolai Kudashov, 2013-2014.
*/
package org.telegram.ui.Views;
package org.telegram.ui.Components;
import android.content.Context;
import android.graphics.Canvas;

View File

@ -6,7 +6,7 @@
* Copyright Nikolai Kudashov, 2013-2014.
*/
package org.telegram.ui.Views;
package org.telegram.ui.Components;
import android.annotation.TargetApi;
import android.content.Context;

View File

@ -31,14 +31,15 @@ import org.telegram.android.AndroidUtilities;
import org.telegram.PhoneFormat.PhoneFormat;
import org.telegram.android.ContactsController;
import org.telegram.android.LocaleController;
import org.telegram.messenger.ApplicationLoader;
import org.telegram.messenger.TLRPC;
import org.telegram.android.MessagesController;
import org.telegram.android.NotificationCenter;
import org.telegram.messenger.R;
import org.telegram.ui.ActionBar.ActionBar;
import org.telegram.ui.ActionBar.ActionBarMenu;
import org.telegram.ui.Views.AvatarDrawable;
import org.telegram.ui.Views.BackupImageView;
import org.telegram.ui.Components.AvatarDrawable;
import org.telegram.ui.Components.BackupImageView;
import org.telegram.ui.ActionBar.BaseFragment;
public class ContactAddActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate {
@ -107,53 +108,6 @@ public class ContactAddActivity extends BaseFragment implements NotificationCent
ActionBarMenu menu = actionBar.createMenu();
doneButton = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));
/*
<LinearLayout
android:gravity="center_vertical"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="12dp"
android:paddingBottom="12dp">
<org.telegram.ui.Views.BackupImageView
android:id="@+id/settings_avatar_image"
android:layout_width="64dp"
android:layout_height="64dp"/>
<LinearLayout
android:layout_gravity="center_vertical"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="13dp"
android:layout_marginBottom="1dp">
<TextView
android:textSize="21dp"
android:textColor="#333333"
android:ellipsize="end"
android:id="@+id/settings_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:lines="1"
android:singleLine="true"/>
<TextView
android:textSize="14dp"
android:textColor="#999999"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:id="@+id/settings_online"/>
</LinearLayout>
</LinearLayout>
*/
fragmentView = new ScrollView(getParentActivity());
LinearLayout linearLayout = new LinearLayout(getParentActivity());
@ -227,7 +181,7 @@ public class ContactAddActivity extends BaseFragment implements NotificationCent
layoutParams3.gravity = (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP;
onlineTextView.setLayoutParams(layoutParams3);
firstNameField = new EditText(inflater.getContext());
firstNameField = new EditText(getParentActivity());
firstNameField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
firstNameField.setHintTextColor(0xff979797);
firstNameField.setTextColor(0xff212121);
@ -259,7 +213,7 @@ public class ContactAddActivity extends BaseFragment implements NotificationCent
}
});
lastNameField = new EditText(inflater.getContext());
lastNameField = new EditText(getParentActivity());
lastNameField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
lastNameField.setHintTextColor(0xff979797);
lastNameField.setTextColor(0xff212121);

View File

@ -32,6 +32,7 @@ import android.widget.TextView;
import org.telegram.android.AndroidUtilities;
import org.telegram.android.LocaleController;
import org.telegram.android.MessagesStorage;
import org.telegram.android.SecretChatHelper;
import org.telegram.messenger.TLRPC;
import org.telegram.android.ContactsController;
import org.telegram.messenger.FileLog;
@ -47,7 +48,7 @@ import org.telegram.ui.ActionBar.ActionBar;
import org.telegram.ui.ActionBar.ActionBarMenu;
import org.telegram.ui.ActionBar.ActionBarMenuItem;
import org.telegram.ui.ActionBar.BaseFragment;
import org.telegram.ui.Views.SectionsListView;
import org.telegram.ui.Components.SectionsListView;
import java.util.ArrayList;
import java.util.HashMap;
@ -268,7 +269,7 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
} else {
if (createSecretChat) {
creatingChat = true;
MessagesController.getInstance().startSecretChat(getParentActivity(), user);
SecretChatHelper.getInstance().startSecretChat(getParentActivity(), user);
} else {
Bundle args = new Bundle();
args.putInt("user_id", user.id);
@ -324,7 +325,7 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
} else {
if (createSecretChat) {
creatingChat = true;
MessagesController.getInstance().startSecretChat(getParentActivity(), user);
SecretChatHelper.getInstance().startSecretChat(getParentActivity(), user);
} else {
Bundle args = new Bundle();
args.putInt("user_id", user.id);

View File

@ -32,7 +32,7 @@ import org.telegram.ui.ActionBar.ActionBar;
import org.telegram.ui.ActionBar.ActionBarMenu;
import org.telegram.ui.ActionBar.ActionBarMenuItem;
import org.telegram.ui.ActionBar.BaseFragment;
import org.telegram.ui.Views.SectionsListView;
import org.telegram.ui.Components.SectionsListView;
public class CountrySelectActivity extends BaseFragment {

View File

@ -41,6 +41,7 @@ import android.widget.TextView;
import org.telegram.android.AndroidUtilities;
import org.telegram.PhoneFormat.PhoneFormat;
import org.telegram.android.LocaleController;
import org.telegram.messenger.ApplicationLoader;
import org.telegram.messenger.TLRPC;
import org.telegram.android.ContactsController;
import org.telegram.messenger.FileLog;
@ -53,7 +54,7 @@ import org.telegram.ui.ActionBar.ActionBar;
import org.telegram.ui.ActionBar.ActionBarMenu;
import org.telegram.ui.ActionBar.BaseFragment;
import org.telegram.ui.Cells.UserCell;
import org.telegram.ui.Views.SectionsListView;
import org.telegram.ui.Components.SectionsListView;
import java.util.ArrayList;
import java.util.HashMap;
@ -514,7 +515,7 @@ public class GroupCreateActivity extends BaseFragment implements NotificationCen
}
private XImageSpan createAndPutChipForUser(TLRPC.User user) {
LayoutInflater lf = (LayoutInflater)ApplicationLoader.applicationContext.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
LayoutInflater lf = (LayoutInflater) ApplicationLoader.applicationContext.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
View textView = lf.inflate(R.layout.group_create_bubble, null);
TextView text = (TextView)textView.findViewById(R.id.bubble_text_view);
String name = ContactsController.formatName(user.first_name, user.last_name);

View File

@ -42,11 +42,11 @@ import org.telegram.ui.Cells.GreySectionCell;
import org.telegram.ui.Cells.UserCell;
import org.telegram.ui.ActionBar.ActionBar;
import org.telegram.ui.ActionBar.ActionBarMenu;
import org.telegram.ui.Views.AvatarDrawable;
import org.telegram.ui.Views.AvatarUpdater;
import org.telegram.ui.Views.BackupImageView;
import org.telegram.ui.Components.AvatarDrawable;
import org.telegram.ui.Components.AvatarUpdater;
import org.telegram.ui.Components.BackupImageView;
import org.telegram.ui.ActionBar.BaseFragment;
import org.telegram.ui.Views.FrameLayoutFixed;
import org.telegram.ui.Components.FrameLayoutFixed;
import java.util.ArrayList;
import java.util.concurrent.Semaphore;

View File

@ -23,12 +23,13 @@ import android.widget.LinearLayout;
import android.widget.TextView;
import org.telegram.android.LocaleController;
import org.telegram.messenger.ApplicationLoader;
import org.telegram.messenger.TLRPC;
import org.telegram.android.MessagesController;
import org.telegram.messenger.R;
import org.telegram.ui.ActionBar.ActionBar;
import org.telegram.ui.ActionBar.BaseFragment;
import org.telegram.ui.Views.IdenticonDrawable;
import org.telegram.ui.Components.IdenticonDrawable;
public class IdenticonActivity extends BaseFragment {
private int chat_id;
@ -66,7 +67,7 @@ public class IdenticonActivity extends BaseFragment {
if (encryptedChat != null) {
IdenticonDrawable drawable = new IdenticonDrawable();
identiconView.setImageDrawable(drawable);
drawable.setBytes(encryptedChat.auth_key);
drawable.setEncryptedChat(encryptedChat);
TLRPC.User user = MessagesController.getInstance().getUser(encryptedChat.user_id);
textView.setText(Html.fromHtml(LocaleController.formatString("EncryptionKeyDescription", R.string.EncryptionKeyDescription, user.first_name, user.first_name)));
}
@ -110,7 +111,7 @@ public class IdenticonActivity extends BaseFragment {
return true;
}
LinearLayout layout = (LinearLayout)fragmentView;
WindowManager manager = (WindowManager)ApplicationLoader.applicationContext.getSystemService(Context.WINDOW_SERVICE);
WindowManager manager = (WindowManager) ApplicationLoader.applicationContext.getSystemService(Context.WINDOW_SERVICE);
int rotation = manager.getDefaultDisplay().getRotation();
if (rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90) {

Some files were not shown because too many files have changed in this diff Show More