Merge branch 'master' of https://github.com/DrKLO/Telegram
5
.gitignore
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
.idea/
|
||||
.gradle/
|
||||
build/
|
||||
*.iml
|
||||
local.properties
|
|
@ -1,15 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="false">
|
||||
<output url="file://$MODULE_DIR$/build/classes/main" />
|
||||
<output-test url="file://$MODULE_DIR$/build/classes/test" />
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
|
|
@ -1,81 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" type="JAVA_MODULE" version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="android" name="Android">
|
||||
<configuration>
|
||||
<option name="SELECTED_BUILD_VARIANT" value="debug" />
|
||||
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
|
||||
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugJava" />
|
||||
<option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugTest" />
|
||||
<option name="SOURCE_GEN_TASK_NAME" value="generateDebugSources" />
|
||||
<option name="ALLOW_USER_CONFIGURATION" value="false" />
|
||||
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
|
||||
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
|
||||
<option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res" />
|
||||
<option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
|
||||
<option name="APK_PATH" value="/build/apk/TMessagesProj-debug-unaligned.apk" />
|
||||
</configuration>
|
||||
</facet>
|
||||
<facet type="android-gradle" name="Android-Gradle">
|
||||
<configuration>
|
||||
<option name="GRADLE_PROJECT_PATH" value=":TMessagesProj" />
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="false">
|
||||
<output url="file://$MODULE_DIR$/build/classes/debug" />
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/source/r/debug" isTestSource="false" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/source/aidl/debug" isTestSource="false" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/source/buildConfig/debug" isTestSource="false" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/source/rs/debug" isTestSource="false" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/res/rs/debug" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/source/r/test/debug" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/source/aidl/test/debug" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/source/buildConfig/test/debug" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/source/rs/test/debug" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/res/rs/test/debug" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/instrumentTest/aidl" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/instrumentTest/assets" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/instrumentTest/java" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/instrumentTest/jni" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/instrumentTest/rs" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/instrumentTest/res" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/instrumentTest/resources" type="java-test-resource" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/apk" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/assets" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/bundles" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/classes" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/dependency-cache" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/incremental" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/libs" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/manifests" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/res" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/symbols" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="Android API 19 Platform" jdkType="Android SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" exported="" name="HockeySDK-3.0.1" level="project" />
|
||||
<orderEntry type="library" exported="" name="ComGoogleAndroidGmsPlayServices4030.aar" level="project" />
|
||||
<orderEntry type="library" exported="" name="native-libs" level="project" />
|
||||
<orderEntry type="library" exported="" name="support-v4-19.0.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="ComAndroidSupportAppcompatV71900.aar" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
|
|
@ -3,7 +3,7 @@ buildscript {
|
|||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:0.7.+'
|
||||
classpath 'com.android.tools.build:gradle:0.8.+'
|
||||
}
|
||||
}
|
||||
apply plugin: 'android'
|
||||
|
@ -31,7 +31,7 @@ tasks.withType(JavaCompile) {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
compile 'com.google.android.gms:play-services:4.0.+'
|
||||
compile 'com.google.android.gms:play-services:4.1.+'
|
||||
compile 'net.hockeyapp.android:HockeySDK:3.0.1'
|
||||
compile 'com.android.support:support-v4:19.0.+'
|
||||
compile 'com.android.support:appcompat-v7:19.0.+'
|
||||
|
@ -40,7 +40,7 @@ dependencies {
|
|||
|
||||
android {
|
||||
compileSdkVersion 19
|
||||
buildToolsVersion '19.0.0'
|
||||
buildToolsVersion '19.0.1'
|
||||
|
||||
signingConfigs {
|
||||
debug {
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.telegram.messenger"
|
||||
android:versionCode="131"
|
||||
android:versionName="1.3.7">
|
||||
|
||||
android:versionCode="160"
|
||||
android:versionName="1.3.21">
|
||||
|
||||
<supports-screens android:anyDensity="true"
|
||||
android:smallScreens="true"
|
||||
android:normalScreens="true"
|
||||
android:largeScreens="true"
|
||||
android:resizeable="true"
|
||||
android:xlargeScreens="true"/>
|
||||
|
||||
android:smallScreens="true"
|
||||
android:normalScreens="true"
|
||||
android:largeScreens="true"
|
||||
android:resizeable="true"
|
||||
android:xlargeScreens="true"/>
|
||||
|
||||
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="19" />
|
||||
|
||||
|
||||
<uses-feature android:glEsVersion="0x00020000" android:required="true"/>
|
||||
<uses-feature android:name="android.hardware.telephony" android:required="false" />
|
||||
<uses-feature android:name="android.hardware.location.gps" android:required="false" />
|
||||
|
@ -23,8 +23,9 @@
|
|||
<uses-feature android:name="android.hardware.wifi" android:required="false" />
|
||||
<uses-feature android:name="android.hardware.LOCATION" android:required="false" />
|
||||
<uses-feature android:name="android.hardware.screen.PORTRAIT" android:required="false" />
|
||||
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<!--<uses-permission android:name="android.permission.RECORD_AUDIO" />-->
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||
<uses-permission android:name="android.permission.RECEIVE_SMS" />
|
||||
|
@ -49,10 +50,10 @@
|
|||
<uses-permission android:name="android.permission.VIBRATE" />
|
||||
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
|
||||
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
||||
|
||||
|
||||
<permission android:name="org.telegram.messenger.permission.MAPS_RECEIVE" android:protectionLevel="signature"/>
|
||||
<permission android:name="org.telegram.messenger.permission.C2D_MESSAGE" android:protectionLevel="signature" />
|
||||
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@drawable/ic_launcher"
|
||||
|
@ -61,13 +62,14 @@
|
|||
android:name="org.telegram.ui.ApplicationLoader"
|
||||
android:hardwareAccelerated="true"
|
||||
android:largeHeap="true">
|
||||
|
||||
|
||||
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="your-google-maps-api-key-here" />
|
||||
|
||||
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
|
||||
|
||||
<activity
|
||||
android:name="org.telegram.ui.LaunchActivity"
|
||||
android:windowSoftInputMode="adjustResize"
|
||||
android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
|
||||
android:name="org.telegram.ui.LaunchActivity"
|
||||
android:windowSoftInputMode="adjustResize"
|
||||
android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
|
@ -124,48 +126,50 @@
|
|||
android:theme="@style/Theme.TMessages.Gallery"
|
||||
android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
|
||||
</activity>
|
||||
|
||||
|
||||
|
||||
|
||||
<activity android:name="net.hockeyapp.android.UpdateActivity" />
|
||||
|
||||
|
||||
<receiver android:name="org.telegram.messenger.SmsListener">
|
||||
<intent-filter>
|
||||
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
|
||||
<receiver
|
||||
android:name="org.telegram.messenger.GcmBroadcastReceiver"
|
||||
android:permission="com.google.android.c2dm.permission.SEND" >
|
||||
android:name="org.telegram.messenger.GcmBroadcastReceiver"
|
||||
android:permission="com.google.android.c2dm.permission.SEND" >
|
||||
<intent-filter>
|
||||
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
|
||||
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
|
||||
<category android:name="org.telegram.messenger" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
|
||||
<service android:name="org.telegram.messenger.AuthenticatorService"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.accounts.AccountAuthenticator"/>
|
||||
</intent-filter>
|
||||
<meta-data android:name="android.accounts.AccountAuthenticator"
|
||||
android:resource="@xml/auth"/>
|
||||
android:resource="@xml/auth"/>
|
||||
</service>
|
||||
|
||||
|
||||
<service android:name="org.telegram.messenger.ContactsSyncAdapterService"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.content.SyncAdapter" />
|
||||
</intent-filter>
|
||||
<meta-data android:name="android.content.SyncAdapter"
|
||||
android:resource="@xml/sync_contacts" />
|
||||
android:resource="@xml/sync_contacts" />
|
||||
<meta-data android:name="android.provider.CONTACTS_STRUCTURE"
|
||||
android:resource="@xml/contacts" />
|
||||
android:resource="@xml/contacts" />
|
||||
</service>
|
||||
|
||||
<service android:name="org.telegram.messenger.GcmService" android:enabled="true" android:exported="true"/>
|
||||
<service android:name=".BackgroundService" android:enabled="true" android:stopWithTask="false"/>
|
||||
|
||||
<uses-library android:name="com.google.android.maps" android:required="false"/>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
||||
</manifest>
|
||||
|
|
|
@ -414,6 +414,7 @@ public class TLClassStore {
|
|||
classStore.put(TLRPC.TL_messageActionTTLChange.constructor, TLRPC.TL_messageActionTTLChange.class);
|
||||
classStore.put(TLRPC.TL_videoEncrypted.constructor, TLRPC.TL_videoEncrypted.class);
|
||||
classStore.put(TLRPC.TL_documentEncrypted.constructor, TLRPC.TL_documentEncrypted.class);
|
||||
classStore.put(TLRPC.TL_audioEncrypted.constructor, TLRPC.TL_audioEncrypted.class);
|
||||
classStore.put(TLRPC.TL_gzip_packed.constructor, TLRPC.TL_gzip_packed.class);
|
||||
classStore.put(TLRPC.Vector.constructor, TLRPC.Vector.class);
|
||||
classStore.put(TLRPC.TL_userProfilePhotoOld.constructor, TLRPC.TL_userProfilePhotoOld.class);
|
||||
|
|
|
@ -32,7 +32,7 @@ public class TLObject {
|
|||
}
|
||||
|
||||
public int layer () {
|
||||
return 8;
|
||||
return 11;
|
||||
}
|
||||
|
||||
public void parseVector(TLRPC.Vector vector, SerializedData data) {
|
||||
|
|
|
@ -1227,16 +1227,6 @@ public class TLRPC {
|
|||
}
|
||||
}
|
||||
|
||||
public static class Audio extends TLObject {
|
||||
public long id;
|
||||
public long access_hash;
|
||||
public int user_id;
|
||||
public int date;
|
||||
public int duration;
|
||||
public int size;
|
||||
public int dc_id;
|
||||
}
|
||||
|
||||
public static class TL_audioEmpty extends Audio {
|
||||
public static int constructor = 0x586988d8;
|
||||
|
||||
|
@ -8776,6 +8766,19 @@ public class TLRPC {
|
|||
public byte[] iv;
|
||||
}
|
||||
|
||||
public static class Audio extends TLObject {
|
||||
public long id;
|
||||
public long access_hash;
|
||||
public int user_id;
|
||||
public int date;
|
||||
public int duration;
|
||||
public int size;
|
||||
public int dc_id;
|
||||
public String path;
|
||||
public byte[] key;
|
||||
public byte[] iv;
|
||||
}
|
||||
|
||||
public static class MessageAction extends TLObject {
|
||||
public Photo photo;
|
||||
public UserProfilePhoto newUserPhoto;
|
||||
|
@ -8871,6 +8874,36 @@ public class TLRPC {
|
|||
}
|
||||
}
|
||||
|
||||
public static class TL_audioEncrypted extends Audio {
|
||||
public static int constructor = 0x555555F6;
|
||||
|
||||
|
||||
public void readParams(SerializedData stream) {
|
||||
id = stream.readInt64();
|
||||
access_hash = stream.readInt64();
|
||||
user_id = stream.readInt32();
|
||||
date = stream.readInt32();
|
||||
duration = stream.readInt32();
|
||||
size = stream.readInt32();
|
||||
dc_id = stream.readInt32();
|
||||
key = stream.readByteArray();
|
||||
iv = stream.readByteArray();
|
||||
}
|
||||
|
||||
public void serializeToStream(SerializedData stream) {
|
||||
stream.writeInt32(constructor);
|
||||
stream.writeInt64(id);
|
||||
stream.writeInt64(access_hash);
|
||||
stream.writeInt32(user_id);
|
||||
stream.writeInt32(date);
|
||||
stream.writeInt32(duration);
|
||||
stream.writeInt32(size);
|
||||
stream.writeInt32(dc_id);
|
||||
stream.writeByteArray(key);
|
||||
stream.writeByteArray(iv);
|
||||
}
|
||||
}
|
||||
|
||||
public static class TL_messageActionUserUpdatedPhoto extends MessageAction {
|
||||
public static int constructor = 0x55555551;
|
||||
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* This is the source code of Telegram for Android v. 1.3.x.
|
||||
* It is licensed under GNU GPL v. 2 or later.
|
||||
* You should have received a copy of the license in this archive (see LICENSE).
|
||||
*
|
||||
* Copyright Nikolai Kudashov, 2013.
|
||||
*/
|
||||
|
||||
package org.telegram.messenger;
|
||||
|
||||
import android.app.Service;
|
||||
import android.content.Intent;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
|
||||
public class BackgroundService extends Service {
|
||||
|
||||
private Handler handler = new Handler(Looper.getMainLooper());
|
||||
private Runnable checkRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
check();
|
||||
}
|
||||
};
|
||||
|
||||
public BackgroundService() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
check();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
super.onStartCommand(intent, flags, startId);
|
||||
Log.e("tmessages", "onStartCommand");
|
||||
return START_STICKY;
|
||||
}
|
||||
|
||||
private void check() {
|
||||
handler.removeCallbacks(checkRunnable);
|
||||
handler.postDelayed(checkRunnable, 1500);
|
||||
ConnectionsManager connectionsManager = ConnectionsManager.Instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
Log.e("tmessages", "onDestroy");
|
||||
}
|
||||
}
|
|
@ -33,10 +33,11 @@ import java.util.regex.Matcher;
|
|||
import java.util.regex.Pattern;
|
||||
|
||||
public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.TcpConnectionDelegate {
|
||||
public static boolean DEBUG_VERSION = false;
|
||||
public static boolean DEBUG_VERSION = true;
|
||||
public static int APP_ID = 2458;
|
||||
public static String APP_HASH = "5bce48dc7d331e62c955669eb7233217";
|
||||
public static String HOCKEY_APP_HASH = "your-hockeyapp-api-key-here";
|
||||
public static boolean disableContactsImport = false;
|
||||
|
||||
private HashMap<Integer, Datacenter> datacenters = new HashMap<Integer, Datacenter>();
|
||||
private HashMap<Long, ArrayList<Long>> processedMessageIdsSet = new HashMap<Long, ArrayList<Long>>();
|
||||
|
@ -100,35 +101,55 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
|||
public void run() {
|
||||
long currentTime = System.currentTimeMillis();
|
||||
if (ApplicationLoader.lastPauseTime != 0 && ApplicationLoader.lastPauseTime < currentTime - nextSleepTimeout) {
|
||||
if (!paused) {
|
||||
FileLog.e("tmessages", "pausing network and timers by sleep time = " + nextSleepTimeout);
|
||||
for (Datacenter datacenter : datacenters.values()) {
|
||||
if (datacenter.connection != null) {
|
||||
datacenter.connection.suspendConnection(true);
|
||||
}
|
||||
if (datacenter.uploadConnection != null) {
|
||||
datacenter.uploadConnection.suspendConnection(true);
|
||||
}
|
||||
if (datacenter.downloadConnection != null) {
|
||||
datacenter.downloadConnection.suspendConnection(true);
|
||||
boolean dontSleep = false;
|
||||
for (RPCRequest request : runningRequests) {
|
||||
if (request.retryCount < 10 && (request.runningStartTime + 60 > (int)(currentTime / 1000)) && ((request.flags & RPCRequest.RPCRequestClassDownloadMedia) != 0 || (request.flags & RPCRequest.RPCRequestClassUploadMedia) != 0)) {
|
||||
dontSleep = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!dontSleep) {
|
||||
for (RPCRequest request : requestQueue) {
|
||||
if ((request.flags & RPCRequest.RPCRequestClassDownloadMedia) != 0 || (request.flags & RPCRequest.RPCRequestClassUploadMedia) != 0) {
|
||||
dontSleep = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
try {
|
||||
paused = true;
|
||||
if (ApplicationLoader.lastPauseTime < currentTime - nextSleepTimeout - nextWakeUpTimeout) {
|
||||
ApplicationLoader.lastPauseTime = currentTime;
|
||||
nextSleepTimeout = 30000;
|
||||
FileLog.e("tmessages", "wakeup network in background by wakeup time = " + nextWakeUpTimeout);
|
||||
if (nextWakeUpTimeout < 30 * 60 * 1000) {
|
||||
nextWakeUpTimeout *= 2;
|
||||
if (!dontSleep) {
|
||||
if (!paused) {
|
||||
FileLog.e("tmessages", "pausing network and timers by sleep time = " + nextSleepTimeout);
|
||||
for (Datacenter datacenter : datacenters.values()) {
|
||||
if (datacenter.connection != null) {
|
||||
datacenter.connection.suspendConnection(true);
|
||||
}
|
||||
if (datacenter.uploadConnection != null) {
|
||||
datacenter.uploadConnection.suspendConnection(true);
|
||||
}
|
||||
if (datacenter.downloadConnection != null) {
|
||||
datacenter.downloadConnection.suspendConnection(true);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Thread.sleep(500);
|
||||
return;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
try {
|
||||
paused = true;
|
||||
if (ApplicationLoader.lastPauseTime < currentTime - nextSleepTimeout - nextWakeUpTimeout) {
|
||||
ApplicationLoader.lastPauseTime = currentTime;
|
||||
nextSleepTimeout = 30000;
|
||||
FileLog.e("tmessages", "wakeup network in background by wakeup time = " + nextWakeUpTimeout);
|
||||
if (nextWakeUpTimeout < 30 * 60 * 1000) {
|
||||
nextWakeUpTimeout *= 2;
|
||||
}
|
||||
} else {
|
||||
Thread.sleep(500);
|
||||
return;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
} else {
|
||||
ApplicationLoader.lastPauseTime += 30 * 1000;
|
||||
FileLog.e("tmessages", "don't sleep 30 seconds because of upload or download request");
|
||||
}
|
||||
}
|
||||
if (paused) {
|
||||
|
@ -139,7 +160,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
|||
if (datacenters != null) {
|
||||
MessagesController.Instance.updateTimerProc();
|
||||
if (datacenterWithId(currentDatacenterId).authKey != null) {
|
||||
if (lastPingTime < System.currentTimeMillis() - 30000) {
|
||||
if (lastPingTime < System.currentTimeMillis() - 19000) {
|
||||
lastPingTime = System.currentTimeMillis();
|
||||
generatePing();
|
||||
}
|
||||
|
@ -240,8 +261,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
|||
if (datacenterSetId == useDifferentBackend) {
|
||||
currentDatacenterId = preferences.getInt("currentDatacenterId", 0);
|
||||
timeDifference = preferences.getInt("timeDifference", 0);
|
||||
lastDcUpdateTime = preferences.getInt("lastDcUpdateTime", 0); //TODO uncomment
|
||||
//lastDcUpdateTime = 0;
|
||||
lastDcUpdateTime = preferences.getInt("lastDcUpdateTime", 0);
|
||||
try {
|
||||
sessionsToDestroy.clear();
|
||||
String sessionsString = preferences.getString("sessionsToDestroy", null);
|
||||
|
@ -635,7 +655,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
|||
TLObject wrapInLayer(TLObject object, int datacenterId, RPCRequest request) {
|
||||
if (object.layer() > 0) {
|
||||
Datacenter datacenter = datacenterWithId(datacenterId);
|
||||
if (datacenter.lastInitVersion != currentAppVersion) {
|
||||
if (datacenter == null || datacenter.lastInitVersion != currentAppVersion) {
|
||||
request.initRequest = true;
|
||||
TLRPC.initConnection invoke = new TLRPC.initConnection();
|
||||
invoke.query = object;
|
||||
|
@ -704,6 +724,12 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
|||
|
||||
requestQueue.add(request);
|
||||
|
||||
if (paused && ((request.flags & RPCRequest.RPCRequestClassDownloadMedia) != 0 || (request.flags & RPCRequest.RPCRequestClassUploadMedia) != 0)) {
|
||||
ApplicationLoader.lastPauseTime = System.currentTimeMillis();
|
||||
nextSleepTimeout = 30000;
|
||||
FileLog.e("tmessages", "wakeup by download or upload request");
|
||||
}
|
||||
|
||||
processRequestQueue(0, 0);
|
||||
}
|
||||
});
|
||||
|
@ -921,6 +947,10 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
|||
}
|
||||
|
||||
Datacenter requestDatacenter = datacenterWithId(datacenterId);
|
||||
if (!request.initRequest && requestDatacenter.lastInitVersion != currentAppVersion) {
|
||||
request.rpcRequest = wrapInLayer(request.rawRequest, requestDatacenter.datacenterId, request);
|
||||
}
|
||||
|
||||
if (requestDatacenter == null) {
|
||||
if (!unknownDatacenterIds.contains(datacenterId)) {
|
||||
unknownDatacenterIds.add(datacenterId);
|
||||
|
@ -941,6 +971,12 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
|||
Integer tokenIt = activeTransportTokens.get(requestDatacenter.datacenterId);
|
||||
int datacenterTransportToken = tokenIt != null ? tokenIt : 0;
|
||||
|
||||
Integer uploadTokenIt = activeUploadTransportTokens.get(requestDatacenter.datacenterId);
|
||||
int datacenterUploadTransportToken = uploadTokenIt != null ? uploadTokenIt : 0;
|
||||
|
||||
Integer downloadTokenIt = activeDownloadTransportTokens.get(requestDatacenter.datacenterId);
|
||||
int datacenterDownloadTransportToken = downloadTokenIt != null ? downloadTokenIt : 0;
|
||||
|
||||
double maxTimeout = 8.0;
|
||||
|
||||
if ((request.flags & RPCRequest.RPCRequestClassGeneric) != 0) {
|
||||
|
@ -952,12 +988,18 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
|||
FileLog.d("tmessages", "Don't have any network connection, skipping download request");
|
||||
continue;
|
||||
}
|
||||
if (datacenterDownloadTransportToken == 0) {
|
||||
continue;
|
||||
}
|
||||
maxTimeout = 40.0;
|
||||
} else if ((request.flags & RPCRequest.RPCRequestClassUploadMedia) != 0) {
|
||||
if (!haveNetwork) {
|
||||
FileLog.d("tmessages", "Don't have any network connection, skipping upload request");
|
||||
continue;
|
||||
}
|
||||
if (datacenterUploadTransportToken == 0) {
|
||||
continue;
|
||||
}
|
||||
maxTimeout = 30.0;
|
||||
}
|
||||
|
||||
|
@ -988,20 +1030,19 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
|||
FileLog.d("tmessages", "Request token is valid, not retrying " + request.rawRequest);
|
||||
continue;
|
||||
} else if ((request.flags & RPCRequest.RPCRequestClassDownloadMedia) != 0) {
|
||||
int downloadToken = requestDatacenter.downloadConnection.channelToken;
|
||||
if (downloadToken != 0 && request.transportChannelToken == downloadToken) {
|
||||
if (datacenterDownloadTransportToken != 0 && request.transportChannelToken == datacenterDownloadTransportToken) {
|
||||
FileLog.d("tmessages", "Request download token is valid, not retrying " + request.rawRequest);
|
||||
continue;
|
||||
}
|
||||
} else if ((request.flags & RPCRequest.RPCRequestClassUploadMedia) != 0) {
|
||||
int uploadToken = requestDatacenter.uploadConnection.channelToken;
|
||||
if (uploadToken != 0 && request.transportChannelToken == uploadToken) {
|
||||
if (datacenterUploadTransportToken != 0 && request.transportChannelToken == datacenterUploadTransportToken) {
|
||||
FileLog.d("tmessages", "Request upload token is valid, not retrying " + request.rawRequest);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
request.retryCount++;
|
||||
NetworkMessage networkMessage = new NetworkMessage();
|
||||
networkMessage.protoMessage = new TLRPC.TL_protoMessage();
|
||||
|
||||
|
@ -1022,10 +1063,12 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
|||
request.transportChannelToken = datacenterTransportToken;
|
||||
addMessageToDatacenter(genericMessagesToDatacenters, requestDatacenter.datacenterId, networkMessage);
|
||||
} else if ((request.flags & RPCRequest.RPCRequestClassDownloadMedia) != 0) {
|
||||
request.transportChannelToken = datacenterDownloadTransportToken;
|
||||
ArrayList<NetworkMessage> arr = new ArrayList<NetworkMessage>();
|
||||
arr.add(networkMessage);
|
||||
proceedToSendingMessages(arr, sessionId, requestDatacenter.downloadConnection, false, false);
|
||||
} else if ((request.flags & RPCRequest.RPCRequestClassUploadMedia) != 0) {
|
||||
request.transportChannelToken = datacenterUploadTransportToken;
|
||||
ArrayList<NetworkMessage> arr = new ArrayList<NetworkMessage>();
|
||||
arr.add(networkMessage);
|
||||
proceedToSendingMessages(arr, sessionId, requestDatacenter.uploadConnection, false, false);
|
||||
|
@ -1106,6 +1149,10 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
|||
}
|
||||
|
||||
Datacenter requestDatacenter = datacenterWithId(datacenterId);
|
||||
if (!request.initRequest && requestDatacenter.lastInitVersion != currentAppVersion) {
|
||||
request.rpcRequest = wrapInLayer(request.rawRequest, requestDatacenter.datacenterId, request);
|
||||
}
|
||||
|
||||
if (requestDatacenter == null) {
|
||||
unknownDatacenterIds.add(datacenterId);
|
||||
continue;
|
||||
|
@ -1147,6 +1194,9 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
|||
continue;
|
||||
}
|
||||
|
||||
Integer uploadTokenIt = activeUploadTransportTokens.get(requestDatacenter.datacenterId);
|
||||
request.transportChannelToken = uploadTokenIt != null ? uploadTokenIt : 0;
|
||||
|
||||
uploadRunningRequestCount++;
|
||||
} else if ((request.flags & RPCRequest.RPCRequestClassDownloadMedia) != 0) {
|
||||
if (!haveNetwork) {
|
||||
|
@ -1158,16 +1208,22 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
|||
continue;
|
||||
}
|
||||
|
||||
Integer downloadTokenIt = activeDownloadTransportTokens.get(requestDatacenter.datacenterId);
|
||||
request.transportChannelToken = downloadTokenIt != null ? downloadTokenIt : 0;
|
||||
|
||||
downloadRunningRequestCount++;
|
||||
}
|
||||
}
|
||||
|
||||
long messageId = generateMessageId();
|
||||
|
||||
SerializedData os = new SerializedData();
|
||||
request.rpcRequest.serializeToStream(os);
|
||||
boolean canCompress = (request.flags & RPCRequest.RPCRequestClassCanCompress) != 0;
|
||||
|
||||
if (os.length() != 0) {
|
||||
SerializedData os = new SerializedData(!canCompress);
|
||||
request.rpcRequest.serializeToStream(os);
|
||||
int requestLength = os.length();
|
||||
|
||||
if (requestLength != 0) {
|
||||
long sessionId = 0;
|
||||
if ((request.flags & RPCRequest.RPCRequestClassGeneric) != 0) {
|
||||
sessionId = requestDatacenter.authSessionId;
|
||||
|
@ -1177,18 +1233,34 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
|||
sessionId = requestDatacenter.authUploadSessionId;
|
||||
}
|
||||
|
||||
if (canCompress) {
|
||||
try {
|
||||
byte[] data = Utilities.compress(os.toByteArray());
|
||||
if (data.length < requestLength) {
|
||||
TLRPC.TL_gzip_packed packed = new TLRPC.TL_gzip_packed();
|
||||
packed.packed_data = data;
|
||||
request.rpcRequest = packed;
|
||||
os = new SerializedData(true);
|
||||
packed.serializeToStream(os);
|
||||
requestLength = os.length();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
}
|
||||
|
||||
NetworkMessage networkMessage = new NetworkMessage();
|
||||
networkMessage.protoMessage = new TLRPC.TL_protoMessage();
|
||||
networkMessage.protoMessage.msg_id = messageId;
|
||||
networkMessage.protoMessage.seqno = generateMessageSeqNo(sessionId, true);
|
||||
networkMessage.protoMessage.bytes = os.length();
|
||||
networkMessage.protoMessage.bytes = requestLength;
|
||||
networkMessage.protoMessage.body = request.rpcRequest;
|
||||
networkMessage.rawRequest = request.rawRequest;
|
||||
networkMessage.requestId = request.token;
|
||||
|
||||
request.runningMessageId = messageId;
|
||||
request.runningMessageSeqNo = networkMessage.protoMessage.seqno;
|
||||
request.serializedLength = os.length();
|
||||
request.serializedLength = requestLength;
|
||||
request.runningStartTime = (int)(System.currentTimeMillis() / 1000);
|
||||
if (request.requiresCompletion) {
|
||||
runningRequests.add(request);
|
||||
|
@ -1372,7 +1444,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
|||
}
|
||||
|
||||
TLRPC.TL_protoMessage wrapMessage(TLObject message, long sessionId, boolean meaningful) {
|
||||
SerializedData os = new SerializedData();
|
||||
SerializedData os = new SerializedData(true);
|
||||
message.serializeToStream(os);
|
||||
|
||||
if (os.length() != 0) {
|
||||
|
@ -1404,7 +1476,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
|||
msgAck.msg_ids = new ArrayList<Long>();
|
||||
msgAck.msg_ids.addAll(arr);
|
||||
|
||||
SerializedData os = new SerializedData();
|
||||
SerializedData os = new SerializedData(true);
|
||||
msgAck.serializeToStream(os);
|
||||
|
||||
if (os.length() != 0) {
|
||||
|
@ -1454,8 +1526,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
|||
byte[] transportData = createConnectionData(currentMessages, sessionId, quickAckId, connection);
|
||||
|
||||
if (transportData != null) {
|
||||
if (reportAck && quickAckId.size() != 0)
|
||||
{
|
||||
if (reportAck && quickAckId.size() != 0) {
|
||||
ArrayList<Long> requestIds = new ArrayList<Long>();
|
||||
|
||||
for (NetworkMessage message : messagesToSend) {
|
||||
|
@ -1501,7 +1572,20 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
|||
NetworkMessage networkMessage = messages.get(0);
|
||||
TLRPC.TL_protoMessage message = networkMessage.protoMessage;
|
||||
|
||||
FileLog.d("tmessages", sessionId + ":Send message " + datacenter.datacenterId + "> Send message (" + message.seqno + ", " + message.msg_id + "): " + message.body);
|
||||
if (DEBUG_VERSION) {
|
||||
if (message.body instanceof TLRPC.invokeWithLayer11) {
|
||||
FileLog.d("tmessages", sessionId + ":DC" + datacenter.datacenterId + "> Send message (" + message.seqno + ", " + message.msg_id + "): " + ((TLRPC.invokeWithLayer11)message.body).query);
|
||||
} else if (message.body instanceof TLRPC.initConnection) {
|
||||
TLRPC.initConnection r = (TLRPC.initConnection)message.body;
|
||||
if (r.query instanceof TLRPC.invokeWithLayer11) {
|
||||
FileLog.d("tmessages", sessionId + ":DC" + datacenter.datacenterId + "> Send message (" + message.seqno + ", " + message.msg_id + "): " + ((TLRPC.invokeWithLayer11)r.query).query);
|
||||
} else {
|
||||
FileLog.d("tmessages", sessionId + ":DC" + datacenter.datacenterId + "> Send message (" + message.seqno + ", " + message.msg_id + "): " + r.query);
|
||||
}
|
||||
} else {
|
||||
FileLog.d("tmessages", sessionId + ":DC" + datacenter.datacenterId + "> Send message (" + message.seqno + ", " + message.msg_id + "): " + message.body);
|
||||
}
|
||||
}
|
||||
|
||||
long msg_time = getTimeFromMsgId(message.msg_id);
|
||||
long currentTime = System.currentTimeMillis() + ((long)timeDifference) * 1000;
|
||||
|
@ -1528,7 +1612,20 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
|||
for (NetworkMessage networkMessage : messages) {
|
||||
TLRPC.TL_protoMessage message = networkMessage.protoMessage;
|
||||
containerMessages.add(message);
|
||||
FileLog.d("tmessages", sessionId + ":DC" + datacenter.datacenterId + "> Send message (" + message.seqno + ", " + message.msg_id + "): " + message.body);
|
||||
if (DEBUG_VERSION) {
|
||||
if (message.body instanceof TLRPC.invokeWithLayer11) {
|
||||
FileLog.d("tmessages", sessionId + ":DC" + datacenter.datacenterId + "> Send message (" + message.seqno + ", " + message.msg_id + "): " + ((TLRPC.invokeWithLayer11)message.body).query);
|
||||
} else if (message.body instanceof TLRPC.initConnection) {
|
||||
TLRPC.initConnection r = (TLRPC.initConnection)message.body;
|
||||
if (r.query instanceof TLRPC.invokeWithLayer11) {
|
||||
FileLog.d("tmessages", sessionId + ":DC" + datacenter.datacenterId + "> Send message (" + message.seqno + ", " + message.msg_id + "): " + ((TLRPC.invokeWithLayer11)r.query).query);
|
||||
} else {
|
||||
FileLog.d("tmessages", sessionId + ":DC" + datacenter.datacenterId + "> Send message (" + message.seqno + ", " + message.msg_id + "): " + r.query);
|
||||
}
|
||||
} else {
|
||||
FileLog.d("tmessages", sessionId + ":DC" + datacenter.datacenterId + "> Send message (" + message.seqno + ", " + message.msg_id + "): " + message.body);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
messageContainer.messages = containerMessages;
|
||||
|
@ -1933,13 +2030,15 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
|||
isError = true;
|
||||
if (datacenter.datacenterId == currentDatacenterId || datacenter.datacenterId == movingToDatacenterId) {
|
||||
if ((request.flags & RPCRequest.RPCRequestClassGeneric) != 0) {
|
||||
Utilities.RunOnUIThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
NotificationCenter.Instance.postNotificationName(1234);
|
||||
UserConfig.clearConfig();
|
||||
}
|
||||
});
|
||||
if (UserConfig.clientActivated) {
|
||||
UserConfig.clearConfig();
|
||||
Utilities.RunOnUIThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
NotificationCenter.Instance.postNotificationName(1234);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
datacenter.authorized = false;
|
||||
|
@ -2078,7 +2177,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
|||
TLObject result = Utilities.decompress(packet.packed_data, getRequestWithMessageId(messageId));
|
||||
processMessage(result, messageId, messageSeqNo, messageSalt, connection, sessionId, innerMsgId, containerMessageId);
|
||||
} else if (message instanceof TLRPC.Updates) {
|
||||
MessagesController.Instance.processUpdates((TLRPC.Updates)message);
|
||||
MessagesController.Instance.processUpdates((TLRPC.Updates)message, false);
|
||||
} else {
|
||||
FileLog.e("tmessages", "***** Error: unknown message class " + message);
|
||||
}
|
||||
|
@ -2275,6 +2374,24 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
|||
} else {
|
||||
connectionState = 1;
|
||||
}
|
||||
if (DEBUG_VERSION) {
|
||||
try {
|
||||
ConnectivityManager cm = (ConnectivityManager)ApplicationLoader.applicationContext.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
NetworkInfo[] networkInfos = cm.getAllNetworkInfo();
|
||||
for (int a = 0; a < 2; a++) {
|
||||
if (a >= networkInfos.length) {
|
||||
break;
|
||||
}
|
||||
NetworkInfo info = networkInfos[a];
|
||||
FileLog.e("tmessages", "Network: " + info.getTypeName() + " status: " + info.getState() + " info: " + info.getExtraInfo() + " object: " + info.getDetailedState() + " other: " + info);
|
||||
}
|
||||
if (networkInfos.length == 0) {
|
||||
FileLog.e("tmessages", "no network available");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", "NETWORK STATE GET ERROR");
|
||||
}
|
||||
}
|
||||
final int stateCopy = connectionState;
|
||||
Utilities.RunOnUIThread(new Runnable() {
|
||||
@Override
|
||||
|
@ -2364,6 +2481,8 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
|||
} else {
|
||||
if (datacenter.authKeyId == null || !Arrays.equals(keyId, datacenter.authKeyId)) {
|
||||
FileLog.e("tmessages", "Error: invalid auth key id " + connection);
|
||||
connection.suspendConnection(true);
|
||||
connection.connect();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -2375,6 +2494,8 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
|||
messageData = Utilities.aesIgeEncryption(messageData, keyData.aesKey, keyData.aesIv, false, false);
|
||||
if (messageData == null) {
|
||||
FileLog.e("tmessages", "Error: can't decrypt message data " + connection);
|
||||
connection.suspendConnection(true);
|
||||
connection.connect();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -2416,6 +2537,8 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
|||
|
||||
if (!Arrays.equals(messageKey, realMessageKey)) {
|
||||
FileLog.e("tmessages", "***** Error: invalid message key");
|
||||
connection.suspendConnection(true);
|
||||
connection.connect();
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -94,6 +94,24 @@ public class FileLoadOperation {
|
|||
ext = ".mp4";
|
||||
}
|
||||
|
||||
public FileLoadOperation(TLRPC.Audio audioLocation) {
|
||||
if (audioLocation instanceof TLRPC.TL_audio) {
|
||||
location = new TLRPC.TL_inputAudioFileLocation();
|
||||
datacenter_id = audioLocation.dc_id;
|
||||
location.id = audioLocation.id;
|
||||
location.access_hash = audioLocation.access_hash;
|
||||
} else if (audioLocation instanceof TLRPC.TL_audioEncrypted) {
|
||||
location = new TLRPC.TL_inputEncryptedFileLocation();
|
||||
location.id = audioLocation.id;
|
||||
location.access_hash = audioLocation.access_hash;
|
||||
datacenter_id = audioLocation.dc_id;
|
||||
iv = new byte[32];
|
||||
System.arraycopy(audioLocation.iv, 0, iv, 0, iv.length);
|
||||
key = audioLocation.key;
|
||||
}
|
||||
ext = ".m4a";
|
||||
}
|
||||
|
||||
public FileLoadOperation(TLRPC.Document documentLocation) {
|
||||
if (documentLocation instanceof TLRPC.TL_document) {
|
||||
location = new TLRPC.TL_inputDocumentFileLocation();
|
||||
|
@ -220,14 +238,14 @@ public class FileLoadOperation {
|
|||
opts.inSampleSize = (int)scaleFactor;
|
||||
}
|
||||
|
||||
opts.inPreferredConfig = Bitmap.Config.RGB_565;
|
||||
opts.inPreferredConfig = Bitmap.Config.ARGB_8888;
|
||||
opts.inDither = false;
|
||||
image = BitmapFactory.decodeStream(is, null, opts);
|
||||
is.close();
|
||||
if (image == null) {
|
||||
if (!dontDelete) {
|
||||
cacheFileFinal.delete();
|
||||
}
|
||||
//if (!dontDelete) {
|
||||
// cacheFileFinal.delete();
|
||||
//}
|
||||
} else {
|
||||
if (filter != null && image != null) {
|
||||
float bitmapW = image.getWidth();
|
||||
|
@ -252,13 +270,17 @@ public class FileLoadOperation {
|
|||
Utilities.stageQueue.postRunnable(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
delegate.didFinishLoadingFile(FileLoadOperation.this);
|
||||
if (image == null) {
|
||||
delegate.didFailedLoadingFile(FileLoadOperation.this);
|
||||
} else {
|
||||
delegate.didFinishLoadingFile(FileLoadOperation.this);
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
if (!dontDelete) {
|
||||
cacheFileFinal.delete();
|
||||
}
|
||||
//if (!dontDelete) {
|
||||
// cacheFileFinal.delete();
|
||||
//}
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
}
|
||||
|
@ -414,13 +436,18 @@ public class FileLoadOperation {
|
|||
opts.inSampleSize = (int) scaleFactor;
|
||||
}
|
||||
|
||||
opts.inPreferredConfig = Bitmap.Config.RGB_565;
|
||||
opts.inPreferredConfig = Bitmap.Config.ARGB_8888;
|
||||
opts.inDither = false;
|
||||
try {
|
||||
if (renamed) {
|
||||
image = BitmapFactory.decodeStream(new FileInputStream(cacheFileFinal), null, opts);
|
||||
} else {
|
||||
image = BitmapFactory.decodeStream(new FileInputStream(cacheFileTemp), null, opts);
|
||||
try {
|
||||
image = BitmapFactory.decodeStream(new FileInputStream(cacheFileTemp), null, opts);
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
image = BitmapFactory.decodeStream(new FileInputStream(cacheFileFinal), null, opts);
|
||||
}
|
||||
}
|
||||
if (filter != null && image != null) {
|
||||
float bitmapW = image.getWidth();
|
||||
|
@ -437,13 +464,18 @@ public class FileLoadOperation {
|
|||
}
|
||||
|
||||
}
|
||||
if (FileLoader.Instance.runtimeHack != null) {
|
||||
if (image != null && FileLoader.Instance.runtimeHack != null) {
|
||||
FileLoader.Instance.runtimeHack.trackFree(image.getRowBytes() * image.getHeight());
|
||||
}
|
||||
if (image != null) {
|
||||
delegate.didFinishLoadingFile(FileLoadOperation.this);
|
||||
} else {
|
||||
delegate.didFailedLoadingFile(FileLoadOperation.this);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
delegate.didFailedLoadingFile(FileLoadOperation.this);
|
||||
}
|
||||
delegate.didFinishLoadingFile(FileLoadOperation.this);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
|
|
|
@ -15,13 +15,12 @@ import android.graphics.BitmapFactory;
|
|||
import android.graphics.Matrix;
|
||||
import android.media.ExifInterface;
|
||||
import android.os.Build;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import org.telegram.TL.TLRPC;
|
||||
import org.telegram.objects.MessageObject;
|
||||
import org.telegram.ui.ApplicationLoader;
|
||||
import org.telegram.ui.Views.BackupImageView;
|
||||
import org.telegram.ui.Views.ImageReceiver;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
|
@ -134,29 +133,28 @@ public class FileLoader {
|
|||
|
||||
private class CacheImage {
|
||||
public String key;
|
||||
public ArrayList<View> imageViewArray;
|
||||
final public ArrayList<Object> imageViewArray = new ArrayList<Object>();
|
||||
public FileLoadOperation loadOperation;
|
||||
|
||||
public void addImageView(View imageView) {
|
||||
if (imageViewArray == null) {
|
||||
imageViewArray = new ArrayList<View>();
|
||||
}
|
||||
boolean exist = false;
|
||||
for (View v : imageViewArray) {
|
||||
if (v == imageView) {
|
||||
exist = true;
|
||||
break;
|
||||
public void addImageView(Object imageView) {
|
||||
synchronized (imageViewArray) {
|
||||
boolean exist = false;
|
||||
for (Object v : imageViewArray) {
|
||||
if (v == imageView) {
|
||||
exist = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!exist) {
|
||||
imageViewArray.add(imageView);
|
||||
}
|
||||
}
|
||||
if (!exist) {
|
||||
imageViewArray.add(imageView);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeImageView(View imageView) {
|
||||
if (imageViewArray != null) {
|
||||
public void removeImageView(Object imageView) {
|
||||
synchronized (imageViewArray) {
|
||||
for (int a = 0; a < imageViewArray.size(); a++) {
|
||||
View obj = imageViewArray.get(a);
|
||||
Object obj = imageViewArray.get(a);
|
||||
if (obj == null || obj == imageView) {
|
||||
imageViewArray.remove(a);
|
||||
a--;
|
||||
|
@ -166,19 +164,23 @@ public class FileLoader {
|
|||
}
|
||||
|
||||
public void callAndClear(Bitmap image) {
|
||||
if (image != null) {
|
||||
for (View imgView : imageViewArray) {
|
||||
if (imgView instanceof BackupImageView) {
|
||||
((BackupImageView)imgView).setImageBitmap(image, key);
|
||||
} else if (imgView instanceof ImageView) {
|
||||
((ImageView)imgView).setImageBitmap(image);
|
||||
synchronized (imageViewArray) {
|
||||
if (image != null) {
|
||||
for (Object imgView : imageViewArray) {
|
||||
if (imgView instanceof BackupImageView) {
|
||||
((BackupImageView)imgView).setImageBitmap(image, key);
|
||||
} else if (imgView instanceof ImageReceiver) {
|
||||
((ImageReceiver)imgView).setImageBitmap(image, key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Utilities.imageLoadQueue.postRunnable(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
imageViewArray.clear();
|
||||
synchronized (imageViewArray) {
|
||||
imageViewArray.clear();
|
||||
}
|
||||
loadOperation = null;
|
||||
}
|
||||
});
|
||||
|
@ -189,7 +191,9 @@ public class FileLoader {
|
|||
loadOperation.cancel();
|
||||
loadOperation = null;
|
||||
}
|
||||
imageViewArray.clear();
|
||||
synchronized (imageViewArray) {
|
||||
imageViewArray.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -387,8 +391,8 @@ public class FileLoader {
|
|||
});
|
||||
}
|
||||
|
||||
public void cancelLoadFile(final TLRPC.Video video, final TLRPC.PhotoSize photo, final TLRPC.Document document) {
|
||||
if (video == null && photo == null && document == null) {
|
||||
public void cancelLoadFile(final TLRPC.Video video, final TLRPC.PhotoSize photo, final TLRPC.Document document, final TLRPC.Audio audio) {
|
||||
if (video == null && photo == null && document == null && audio == null) {
|
||||
return;
|
||||
}
|
||||
Utilities.fileUploadQueue.postRunnable(new Runnable() {
|
||||
|
@ -401,6 +405,8 @@ public class FileLoader {
|
|||
fileName = MessageObject.getAttachFileName(photo);
|
||||
} else if (document != null) {
|
||||
fileName = MessageObject.getAttachFileName(document);
|
||||
} else if (audio != null) {
|
||||
fileName = MessageObject.getAttachFileName(audio);
|
||||
}
|
||||
if (fileName == null) {
|
||||
return;
|
||||
|
@ -418,7 +424,7 @@ public class FileLoader {
|
|||
return loadOperationPaths.containsKey(fileName);
|
||||
}
|
||||
|
||||
public void loadFile(final TLRPC.Video video, final TLRPC.PhotoSize photo, final TLRPC.Document document) {
|
||||
public void loadFile(final TLRPC.Video video, final TLRPC.PhotoSize photo, final TLRPC.Document document, final TLRPC.Audio audio) {
|
||||
Utilities.fileUploadQueue.postRunnable(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
@ -429,6 +435,8 @@ public class FileLoader {
|
|||
fileName = MessageObject.getAttachFileName(photo);
|
||||
} else if (document != null) {
|
||||
fileName = MessageObject.getAttachFileName(document);
|
||||
} else if (audio != null) {
|
||||
fileName = MessageObject.getAttachFileName(audio);
|
||||
}
|
||||
if (fileName == null) {
|
||||
return;
|
||||
|
@ -447,6 +455,9 @@ public class FileLoader {
|
|||
} else if (document != null) {
|
||||
operation = new FileLoadOperation(document);
|
||||
operation.totalBytesCount = document.size;
|
||||
} else if (audio != null) {
|
||||
operation = new FileLoadOperation(audio);
|
||||
operation.totalBytesCount = audio.size;
|
||||
}
|
||||
|
||||
final String arg1 = fileName;
|
||||
|
@ -548,25 +559,42 @@ public class FileLoader {
|
|||
memCache.evictAll();
|
||||
}
|
||||
|
||||
public void cancelLoadingForImageView(final View imageView) {
|
||||
private Integer getTag(Object obj) {
|
||||
if (obj instanceof BackupImageView) {
|
||||
return (Integer)((BackupImageView)obj).getTag(R.string.CacheTag);
|
||||
} else if (obj instanceof ImageReceiver) {
|
||||
return ((ImageReceiver)obj).TAG;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private void setTag(Object obj, Integer tag) {
|
||||
if (obj instanceof BackupImageView) {
|
||||
((BackupImageView)obj).setTag(R.string.CacheTag, tag);
|
||||
} else if (obj instanceof ImageReceiver) {
|
||||
((ImageReceiver)obj).TAG = tag;
|
||||
}
|
||||
}
|
||||
|
||||
public void cancelLoadingForImageView(final Object imageView) {
|
||||
if (imageView == null) {
|
||||
return;
|
||||
}
|
||||
Utilities.imageLoadQueue.postRunnable(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Integer num = (Integer)imageView.getTag(R.string.CacheTag);
|
||||
if (num == null) {
|
||||
num = lastImageNum;
|
||||
imageView.setTag(R.string.CacheTag, num);
|
||||
Integer TAG = getTag(imageView);
|
||||
if (TAG == null) {
|
||||
TAG = lastImageNum;
|
||||
setTag(imageView, TAG);
|
||||
lastImageNum++;
|
||||
if (lastImageNum == Integer.MAX_VALUE) {
|
||||
lastImageNum = 0;
|
||||
}
|
||||
}
|
||||
CacheImage ei = imageLoadingByKeys.get(num);
|
||||
CacheImage ei = imageLoadingByKeys.get(TAG);
|
||||
if (ei != null) {
|
||||
imageLoadingByKeys.remove(num);
|
||||
imageLoadingByKeys.remove(TAG);
|
||||
ei.removeImageView(imageView);
|
||||
if (ei.imageViewArray.size() == 0) {
|
||||
checkOperationsAndClear(ei.loadOperation);
|
||||
|
@ -578,17 +606,18 @@ public class FileLoader {
|
|||
});
|
||||
}
|
||||
|
||||
public Bitmap getImageFromMemory(TLRPC.FileLocation url, View imageView, String filter, boolean cancel) {
|
||||
public Bitmap getImageFromMemory(TLRPC.FileLocation url, Object imageView, String filter, boolean cancel) {
|
||||
return getImageFromMemory(url, null, imageView, filter, cancel);
|
||||
}
|
||||
|
||||
public Bitmap getImageFromMemory(String url, View imageView, String filter, boolean cancel) {
|
||||
public Bitmap getImageFromMemory(String url, Object imageView, String filter, boolean cancel) {
|
||||
return getImageFromMemory(null, url, imageView, filter, cancel);
|
||||
}
|
||||
|
||||
public Bitmap getImageFromMemory(TLRPC.FileLocation url, String httpUrl, View imageView, String filter, boolean cancel) {
|
||||
if ((url == null && httpUrl == null) || imageView == null)
|
||||
public Bitmap getImageFromMemory(TLRPC.FileLocation url, String httpUrl, Object imageView, String filter, boolean cancel) {
|
||||
if (url == null && httpUrl == null) {
|
||||
return null;
|
||||
}
|
||||
String key;
|
||||
if (httpUrl != null) {
|
||||
key = Utilities.MD5(httpUrl);
|
||||
|
@ -600,7 +629,7 @@ public class FileLoader {
|
|||
}
|
||||
|
||||
Bitmap img = imageFromKey(key);
|
||||
if (img != null && cancel) {
|
||||
if (imageView != null && img != null && cancel) {
|
||||
cancelLoadingForImageView(imageView);
|
||||
}
|
||||
return img;
|
||||
|
@ -637,19 +666,19 @@ public class FileLoader {
|
|||
});
|
||||
}
|
||||
|
||||
public void loadImage(final String url, final View imageView, final String filter, final boolean cancel) {
|
||||
public void loadImage(final String url, final Object imageView, final String filter, final boolean cancel) {
|
||||
loadImage(null, url, imageView, filter, cancel, 0);
|
||||
}
|
||||
|
||||
public void loadImage(final TLRPC.FileLocation url, final View imageView, final String filter, final boolean cancel) {
|
||||
public void loadImage(final TLRPC.FileLocation url, final Object imageView, final String filter, final boolean cancel) {
|
||||
loadImage(url, null, imageView, filter, cancel, 0);
|
||||
}
|
||||
|
||||
public void loadImage(final TLRPC.FileLocation url, final View imageView, final String filter, final boolean cancel, final int size) {
|
||||
public void loadImage(final TLRPC.FileLocation url, final Object imageView, final String filter, final boolean cancel, final int size) {
|
||||
loadImage(url, null, imageView, filter, cancel, size);
|
||||
}
|
||||
|
||||
public void loadImage(final TLRPC.FileLocation url, final String httpUrl, final View imageView, final String filter, final boolean cancel, final int size) {
|
||||
public void loadImage(final TLRPC.FileLocation url, final String httpUrl, final Object imageView, final String filter, final boolean cancel, final int size) {
|
||||
if ((url == null && httpUrl == null) || imageView == null || (url != null && !(url instanceof TLRPC.TL_fileLocation) && !(url instanceof TLRPC.TL_fileEncryptedLocation))) {
|
||||
return;
|
||||
}
|
||||
|
@ -666,10 +695,10 @@ public class FileLoader {
|
|||
key += "@" + filter;
|
||||
}
|
||||
|
||||
Integer num = (Integer)imageView.getTag(R.string.CacheTag);
|
||||
if (num == null) {
|
||||
num = lastImageNum;
|
||||
imageView.setTag(R.string.CacheTag, num);
|
||||
Integer TAG = getTag(imageView);
|
||||
if (TAG == null) {
|
||||
TAG = lastImageNum;
|
||||
setTag(imageView, TAG);
|
||||
lastImageNum++;
|
||||
if (lastImageNum == Integer.MAX_VALUE)
|
||||
lastImageNum = 0;
|
||||
|
@ -679,7 +708,7 @@ public class FileLoader {
|
|||
boolean addToByKeys = true;
|
||||
CacheImage alreadyLoadingImage = imageLoading.get(key);
|
||||
if (cancel) {
|
||||
CacheImage ei = imageLoadingByKeys.get(num);
|
||||
CacheImage ei = imageLoadingByKeys.get(TAG);
|
||||
if (ei != null) {
|
||||
if (ei != alreadyLoadingImage) {
|
||||
ei.removeImageView(imageView);
|
||||
|
@ -697,7 +726,7 @@ public class FileLoader {
|
|||
|
||||
if (alreadyLoadingImage != null && addToByKeys) {
|
||||
alreadyLoadingImage.addImageView(imageView);
|
||||
imageLoadingByKeys.put(num, alreadyLoadingImage);
|
||||
imageLoadingByKeys.put(TAG, alreadyLoadingImage);
|
||||
added = true;
|
||||
}
|
||||
|
||||
|
@ -705,7 +734,7 @@ public class FileLoader {
|
|||
final CacheImage img = new CacheImage();
|
||||
img.key = key;
|
||||
img.addImageView(imageView);
|
||||
imageLoadingByKeys.put(num, img);
|
||||
imageLoadingByKeys.put(TAG, img);
|
||||
imageLoading.put(key, img);
|
||||
|
||||
final String arg2 = key;
|
||||
|
@ -744,9 +773,8 @@ public class FileLoader {
|
|||
Utilities.imageLoadQueue.postRunnable(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (View view : img.imageViewArray) {
|
||||
Integer num = (Integer)view.getTag(R.string.CacheTag);
|
||||
imageLoadingByKeys.remove(num);
|
||||
for (Object view : img.imageViewArray) {
|
||||
imageLoadingByKeys.remove(getTag(view));
|
||||
imageLoading.remove(arg2);
|
||||
checkOperationsAndClear(operation);
|
||||
}
|
||||
|
@ -814,15 +842,16 @@ public class FileLoader {
|
|||
}
|
||||
}
|
||||
|
||||
public void processImage(Bitmap image, View imageView, String filter, boolean cancel) {
|
||||
public void processImage(Bitmap image, Object imageView, String filter, boolean cancel) {
|
||||
if (filter == null || imageView == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Integer num = (Integer)imageView.getTag(R.string.CacheTag);
|
||||
if (num == null) {
|
||||
num = lastImageNum;
|
||||
imageView.setTag(R.string.CacheTag, num);
|
||||
|
||||
Integer TAG = getTag(imageView);
|
||||
if (TAG == null) {
|
||||
TAG = lastImageNum;
|
||||
setTag(image, TAG);
|
||||
lastImageNum++;
|
||||
if (lastImageNum == Integer.MAX_VALUE)
|
||||
lastImageNum = 0;
|
||||
|
@ -832,7 +861,7 @@ public class FileLoader {
|
|||
boolean addToByKeys = true;
|
||||
CacheImage alreadyLoadingImage = imageLoading.get(filter);
|
||||
if (cancel) {
|
||||
CacheImage ei = imageLoadingByKeys.get(num);
|
||||
CacheImage ei = imageLoadingByKeys.get(TAG);
|
||||
if (ei != null) {
|
||||
if (ei != alreadyLoadingImage) {
|
||||
ei.removeImageView(imageView);
|
||||
|
@ -850,7 +879,7 @@ public class FileLoader {
|
|||
|
||||
if (alreadyLoadingImage != null && addToByKeys) {
|
||||
alreadyLoadingImage.addImageView(imageView);
|
||||
imageLoadingByKeys.put(num, alreadyLoadingImage);
|
||||
imageLoadingByKeys.put(TAG, alreadyLoadingImage);
|
||||
added = true;
|
||||
}
|
||||
|
||||
|
@ -858,7 +887,7 @@ public class FileLoader {
|
|||
CacheImage img = new CacheImage();
|
||||
img.key = filter;
|
||||
img.addImageView(imageView);
|
||||
imageLoadingByKeys.put(num, img);
|
||||
imageLoadingByKeys.put(TAG, img);
|
||||
imageLoading.put(filter, img);
|
||||
|
||||
enqueueImageProcessingOperationWithImage(image, filter, filter, img);
|
||||
|
@ -866,16 +895,15 @@ public class FileLoader {
|
|||
}
|
||||
|
||||
void enqueueImageProcessingOperationWithImage(final Bitmap image, final String filter, final String key, final CacheImage img) {
|
||||
if (image == null || key == null) {
|
||||
if (key == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Utilities.imageLoadQueue.postRunnable(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (View v : img.imageViewArray) {
|
||||
Integer num = (Integer)v.getTag(R.string.CacheTag);
|
||||
imageLoadingByKeys.remove(num);
|
||||
for (Object v : img.imageViewArray) {
|
||||
imageLoadingByKeys.remove(getTag(v));
|
||||
}
|
||||
checkOperationsAndClear(img.loadOperation);
|
||||
imageLoading.remove(key);
|
||||
|
@ -886,7 +914,7 @@ public class FileLoader {
|
|||
@Override
|
||||
public void run() {
|
||||
img.callAndClear(image);
|
||||
if (memCache.get(key) == null) {
|
||||
if (image != null && memCache.get(key) == null) {
|
||||
memCache.put(key, image);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -118,6 +118,8 @@ public class FileLog {
|
|||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -109,7 +109,16 @@ public class FileUploadOperation {
|
|||
isBigFile = true;
|
||||
}
|
||||
|
||||
uploadChunkSize = (int)Math.max(32, Math.ceil(totalFileSize / (1024.0f * 3000))) * 1024;
|
||||
uploadChunkSize = (int)Math.max(32, Math.ceil(totalFileSize / (1024.0f * 3000)));
|
||||
if (1024 % uploadChunkSize != 0) {
|
||||
int chunkSize = 64;
|
||||
while (uploadChunkSize > chunkSize) {
|
||||
chunkSize *= 2;
|
||||
}
|
||||
uploadChunkSize = chunkSize;
|
||||
}
|
||||
|
||||
uploadChunkSize *= 1024;
|
||||
totalPartsCount = (int)Math.ceil((float)totalFileSize / (float)uploadChunkSize);
|
||||
readBuffer = new byte[uploadChunkSize];
|
||||
}
|
||||
|
|
|
@ -9,202 +9,20 @@
|
|||
package org.telegram.messenger;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.content.WakefulBroadcastReceiver;
|
||||
|
||||
import com.google.android.gms.gcm.GoogleCloudMessaging;
|
||||
|
||||
public class GcmBroadcastReceiver extends BroadcastReceiver {
|
||||
public class GcmBroadcastReceiver extends WakefulBroadcastReceiver {
|
||||
|
||||
public static final int NOTIFICATION_ID = 1;
|
||||
|
||||
@Override
|
||||
public void onReceive(final Context context, final Intent intent) {
|
||||
FileLog.d("tmessages", "GCM received intent: " + intent);
|
||||
ComponentName comp = new ComponentName(context.getPackageName(), GcmService.class.getName());
|
||||
startWakefulService(context, (intent.setComponent(comp)));
|
||||
setResultCode(Activity.RESULT_OK);
|
||||
|
||||
if (intent.getAction().equals("com.google.android.c2dm.intent.RECEIVE")) {
|
||||
SharedPreferences preferences = context.getSharedPreferences("Notifications", Context.MODE_PRIVATE);
|
||||
boolean globalEnabled = preferences.getBoolean("EnableAll", true);
|
||||
if (!globalEnabled) {
|
||||
FileLog.d("tmessages", "GCM disabled");
|
||||
return;
|
||||
}
|
||||
|
||||
Thread thread = new Thread(new Runnable() {
|
||||
public void run() {
|
||||
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(context);
|
||||
String messageType = gcm.getMessageType(intent);
|
||||
sendNotification(context, intent.getExtras());
|
||||
}
|
||||
});
|
||||
thread.setPriority(Thread.MAX_PRIORITY);
|
||||
thread.start();
|
||||
} else if (intent.getAction().equals("com.google.android.c2dm.intent.RECEIVE")) {
|
||||
String registration = intent.getStringExtra("registration_id");
|
||||
if (intent.getStringExtra("error") != null) {
|
||||
FileLog.e("tmessages", "Registration failed, should try again later.");
|
||||
} else if (intent.getStringExtra("unregistered") != null) {
|
||||
FileLog.e("tmessages", "unregistration done, new messages from the authorized sender will be rejected");
|
||||
} else if (registration != null) {
|
||||
FileLog.e("tmessages", "registration id = " + registration);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void sendNotification(Context context, Bundle extras) {
|
||||
ConnectionsManager.Instance.resumeNetworkMaybe();
|
||||
/*if (!UserConfig.clientActivated || context == null || extras == null) {
|
||||
return;
|
||||
}
|
||||
SharedPreferences preferences = context.getSharedPreferences("Notifications", Context.MODE_PRIVATE);
|
||||
|
||||
boolean groupEnabled = preferences.getBoolean("EnableGroup", true);
|
||||
boolean globalVibrate = preferences.getBoolean("EnableVibrateAll", true);
|
||||
boolean groupVibrate = preferences.getBoolean("EnableVibrateGroup", true);
|
||||
|
||||
|
||||
if (ApplicationLoader.Instance != null && (ApplicationLoader.lastPauseTime == 0 || ApplicationLoader.lastPauseTime > System.currentTimeMillis() - 200)) {
|
||||
return;
|
||||
}
|
||||
|
||||
String defaultPath = null;
|
||||
Uri defaultUri = Settings.System.DEFAULT_NOTIFICATION_URI;
|
||||
if (defaultUri != null) {
|
||||
defaultPath = defaultUri.getPath();
|
||||
}
|
||||
|
||||
String globalSound = preferences.getString("GlobalSoundPath", defaultPath);
|
||||
String chatSound = preferences.getString("GroupSoundPath", defaultPath);
|
||||
String userSoundPath = null;
|
||||
String chatSoundPath = null;
|
||||
|
||||
NotificationManager mNotificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
Intent intent = new Intent(context, LaunchActivity.class);
|
||||
String msg = extras.getString("message");
|
||||
|
||||
try {
|
||||
String to_id = extras.getString("user_id");
|
||||
int to = Integer.parseInt(to_id);
|
||||
if (to != UserConfig.clientUserId) {
|
||||
return;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
|
||||
int chat_id = 0;
|
||||
int user_id = 0;
|
||||
String custom = extras.getString("custom");
|
||||
try {
|
||||
if (custom != null) {
|
||||
JSONObject obj = new JSONObject(custom);
|
||||
if (obj.has("chat_id")) {
|
||||
Object object = obj.get("chat_id");
|
||||
if (object instanceof Integer) {
|
||||
chat_id = (Integer)object;
|
||||
} else if (object instanceof String) {
|
||||
chat_id = Integer.parseInt((String)object);
|
||||
}
|
||||
if (chat_id != 0) {
|
||||
intent.putExtra("chatId", chat_id);
|
||||
}
|
||||
} else if (obj.has("from_id")) {
|
||||
Object object = obj.get("from_id");
|
||||
if (object instanceof Integer) {
|
||||
user_id = (Integer)object;
|
||||
} else if (object instanceof String) {
|
||||
user_id = Integer.parseInt((String)object);
|
||||
}
|
||||
if (user_id != 0) {
|
||||
intent.putExtra("userId", user_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
|
||||
if (user_id != 0) {
|
||||
String key = "notify_" + user_id;
|
||||
boolean value = preferences.getBoolean(key, true);
|
||||
if (!value) {
|
||||
return;
|
||||
}
|
||||
userSoundPath = preferences.getString("sound_path_" + user_id, null);
|
||||
}
|
||||
if (chat_id != 0) {
|
||||
if (!groupEnabled) {
|
||||
return;
|
||||
}
|
||||
String key = "notify_" + (-chat_id);
|
||||
boolean value = preferences.getBoolean(key, true);
|
||||
if (!value) {
|
||||
return;
|
||||
}
|
||||
chatSoundPath = preferences.getString("sound_chat_path_" + chat_id, null);
|
||||
}
|
||||
|
||||
boolean needVibrate;
|
||||
String choosenSoundPath = null;
|
||||
|
||||
if (chat_id != 0) {
|
||||
needVibrate = groupVibrate;
|
||||
} else {
|
||||
needVibrate = globalVibrate;
|
||||
}
|
||||
|
||||
if (user_id != 0) {
|
||||
if (userSoundPath != null) {
|
||||
choosenSoundPath = userSoundPath;
|
||||
} else if (globalSound != null) {
|
||||
choosenSoundPath = globalSound;
|
||||
}
|
||||
} else if (chat_id != 0) {
|
||||
if (chatSoundPath != null) {
|
||||
choosenSoundPath = chatSoundPath;
|
||||
} else if (chatSound != null) {
|
||||
choosenSoundPath = chatSound;
|
||||
}
|
||||
} else {
|
||||
choosenSoundPath = globalSound;
|
||||
}
|
||||
|
||||
intent.setAction("com.tmessages.openchat" + Math.random() + Integer.MAX_VALUE);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
//intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_ONE_SHOT);
|
||||
|
||||
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
|
||||
.setContentTitle(ApplicationLoader.applicationContext.getString(R.string.AppName))
|
||||
.setSmallIcon(R.drawable.notification)
|
||||
.setStyle(new NotificationCompat.BigTextStyle()
|
||||
.bigText(msg))
|
||||
.setContentText(msg)
|
||||
.setAutoCancel(true)
|
||||
.setTicker(msg);
|
||||
|
||||
if (needVibrate) {
|
||||
mBuilder.setVibrate(new long[]{0, 100, 0, 100});
|
||||
}
|
||||
if (choosenSoundPath != null && !choosenSoundPath.equals("NoSound")) {
|
||||
if (choosenSoundPath.equals(defaultPath)) {
|
||||
mBuilder.setSound(defaultUri);
|
||||
} else {
|
||||
mBuilder.setSound(Uri.parse(choosenSoundPath));
|
||||
}
|
||||
}
|
||||
|
||||
mBuilder.setContentIntent(contentIntent);
|
||||
mNotificationManager.cancel(NOTIFICATION_ID);
|
||||
Notification notification = mBuilder.build();
|
||||
notification.ledARGB = 0xff00ff00;
|
||||
notification.ledOnMS = 1000;
|
||||
notification.ledOffMS = 1000;
|
||||
notification.flags |= Notification.FLAG_SHOW_LIGHTS;
|
||||
mNotificationManager.notify(NOTIFICATION_ID, notification);*/
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* This is the source code of Telegram for Android v. 1.3.x.
|
||||
* It is licensed under GNU GPL v. 2 or later.
|
||||
* You should have received a copy of the license in this archive (see LICENSE).
|
||||
*
|
||||
* Copyright Nikolai Kudashov, 2013.
|
||||
*/
|
||||
|
||||
package org.telegram.messenger;
|
||||
|
||||
import android.app.IntentService;
|
||||
import android.content.Intent;
|
||||
|
||||
public class GcmService extends IntentService {
|
||||
|
||||
public GcmService() {
|
||||
super("GcmService");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onHandleIntent(Intent intent) {
|
||||
if (intent.getAction().equals("com.google.android.c2dm.intent.RECEIVE")) {
|
||||
// SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Context.MODE_PRIVATE);
|
||||
// boolean globalEnabled = preferences.getBoolean("EnableAll", true);
|
||||
// if (!globalEnabled) {
|
||||
// FileLog.d("tmessages", "GCM disabled");
|
||||
// return;
|
||||
// }
|
||||
ConnectionsManager.Instance.resumeNetworkMaybe();
|
||||
} else if (intent.getAction().equals("com.google.android.c2dm.intent.REGISTRATION")) {
|
||||
String registration = intent.getStringExtra("registration_id");
|
||||
if (intent.getStringExtra("error") != null) {
|
||||
FileLog.e("tmessages", "Registration failed, should try again later.");
|
||||
} else if (intent.getStringExtra("unregistered") != null) {
|
||||
FileLog.e("tmessages", "unregistration done, new messages from the authorized sender will be rejected");
|
||||
} else if (registration != null) {
|
||||
FileLog.e("tmessages", "registration id = " + registration);
|
||||
}
|
||||
}
|
||||
GcmBroadcastReceiver.completeWakefulIntent(intent);
|
||||
}
|
||||
}
|
|
@ -9,7 +9,6 @@
|
|||
package org.telegram.messenger;
|
||||
|
||||
import android.text.Html;
|
||||
import android.util.Log;
|
||||
import android.util.SparseArray;
|
||||
|
||||
import org.telegram.SQLite.SQLiteCursor;
|
||||
|
@ -74,6 +73,11 @@ public class MessagesStorage {
|
|||
database.executeFast("INSERT INTO params VALUES(1, 0, 0, 0, 0, 0, 0, NULL)").stepThis().dispose();
|
||||
database.executeFast("CREATE TABLE user_photos(uid INTEGER, id INTEGER, data BLOB, PRIMARY KEY (uid, id))").stepThis().dispose();
|
||||
|
||||
database.executeFast("CREATE TABLE user_contacts_v6(uid INTEGER PRIMARY KEY, fname TEXT, sname TEXT)").stepThis().dispose();
|
||||
database.executeFast("CREATE TABLE user_phones_v6(uid INTEGER, phone TEXT, sphone TEXT, deleted INTEGER, PRIMARY KEY (uid, phone))").stepThis().dispose();
|
||||
|
||||
database.executeFast("CREATE INDEX IF NOT EXISTS sphone_deleted_idx_user_phones ON user_phones_v6(sphone, deleted);").stepThis().dispose();
|
||||
|
||||
database.executeFast("CREATE INDEX IF NOT EXISTS date_idx_dialogs ON dialogs(date);").stepThis().dispose();
|
||||
database.executeFast("CREATE INDEX IF NOT EXISTS date_idx_enc_tasks ON enc_tasks(date);").stepThis().dispose();
|
||||
database.executeFast("CREATE INDEX IF NOT EXISTS last_mid_idx_dialogs ON dialogs(last_mid);").stepThis().dispose();
|
||||
|
@ -133,6 +137,10 @@ public class MessagesStorage {
|
|||
database.executeFast("CREATE INDEX IF NOT EXISTS mid_out_idx_messages ON messages(mid, out);").stepThis().dispose();
|
||||
database.executeFast("CREATE INDEX IF NOT EXISTS task_idx_messages ON messages(uid, out, read_state, ttl, date, send_state);").stepThis().dispose();
|
||||
database.executeFast("CREATE INDEX IF NOT EXISTS uid_date_mid_idx_messages ON messages(uid, date, mid);").stepThis().dispose();
|
||||
|
||||
database.executeFast("CREATE TABLE IF NOT EXISTS user_contacts_v6(uid INTEGER PRIMARY KEY, fname TEXT, sname TEXT)").stepThis().dispose();
|
||||
database.executeFast("CREATE TABLE IF NOT EXISTS user_phones_v6(uid INTEGER, phone TEXT, sphone TEXT, deleted INTEGER, PRIMARY KEY (uid, phone))").stepThis().dispose();
|
||||
database.executeFast("CREATE INDEX IF NOT EXISTS sphone_deleted_idx_user_phones ON user_phones_v6(sphone, deleted);").stepThis().dispose();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
|
@ -291,37 +299,55 @@ public class MessagesStorage {
|
|||
}
|
||||
|
||||
public void getUserPhotos(final int uid, final int offset, final int count, final long max_id, final int classGuid) {
|
||||
try {
|
||||
SQLiteCursor cursor;
|
||||
storageQueue.postRunnable(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
SQLiteCursor cursor;
|
||||
|
||||
if (max_id != 0) {
|
||||
cursor = database.queryFinalized(String.format(Locale.US, "SELECT data FROM user_photos WHERE uid = %d AND id < %d ORDER BY id DESC LIMIT %d", uid, max_id, count));
|
||||
} else {
|
||||
cursor = database.queryFinalized(String.format(Locale.US, "SELECT data FROM user_photos WHERE uid = %d ORDER BY id DESC LIMIT %d,%d", uid, offset, count));
|
||||
}
|
||||
if (max_id != 0) {
|
||||
cursor = database.queryFinalized(String.format(Locale.US, "SELECT data FROM user_photos WHERE uid = %d AND id < %d ORDER BY id DESC LIMIT %d", uid, max_id, count));
|
||||
} else {
|
||||
cursor = database.queryFinalized(String.format(Locale.US, "SELECT data FROM user_photos WHERE uid = %d ORDER BY id DESC LIMIT %d,%d", uid, offset, count));
|
||||
}
|
||||
|
||||
final TLRPC.photos_Photos res = new TLRPC.photos_Photos();
|
||||
final TLRPC.photos_Photos res = new TLRPC.photos_Photos();
|
||||
|
||||
while (cursor.next()) {
|
||||
byte[] messageData = cursor.byteArrayValue(0);
|
||||
if (messageData != null) {
|
||||
SerializedData data = new SerializedData(messageData);
|
||||
TLRPC.Photo photo = (TLRPC.Photo)TLClassStore.Instance().TLdeserialize(data, data.readInt32());
|
||||
res.photos.add(photo);
|
||||
while (cursor.next()) {
|
||||
byte[] messageData = cursor.byteArrayValue(0);
|
||||
if (messageData != null) {
|
||||
SerializedData data = new SerializedData(messageData);
|
||||
TLRPC.Photo photo = (TLRPC.Photo)TLClassStore.Instance().TLdeserialize(data, data.readInt32());
|
||||
res.photos.add(photo);
|
||||
}
|
||||
}
|
||||
cursor.dispose();
|
||||
|
||||
Utilities.stageQueue.postRunnable(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MessagesController.Instance.processLoadedUserPhotos(res, uid, offset, count, max_id, true, classGuid);
|
||||
}
|
||||
});
|
||||
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
}
|
||||
cursor.dispose();
|
||||
});
|
||||
}
|
||||
|
||||
Utilities.stageQueue.postRunnable(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MessagesController.Instance.processLoadedUserPhotos(res, uid, offset, count, max_id, true, classGuid);
|
||||
public void clearUserPhotos(final int uid) {
|
||||
storageQueue.postRunnable(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
database.executeFast("DELETE FROM user_photos WHERE uid = " + uid).stepThis().dispose();
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
});
|
||||
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void putUserPhotos(final int uid, final TLRPC.photos_Photos photos) {
|
||||
|
@ -394,10 +420,11 @@ public class MessagesStorage {
|
|||
int minDate = Integer.MAX_VALUE;
|
||||
SparseArray<ArrayList<Integer>> messages = new SparseArray<ArrayList<Integer>>();
|
||||
String mids = "";
|
||||
SQLiteCursor cursor = database.queryFinalized(String.format(Locale.US, "SELECT mid, ttl FROM messages WHERE uid = %d AND out = %d AND read_state = 1 AND ttl > 0 AND date <= %d AND send_state = 0", ((long)chat_id) << 32, isOut, time));
|
||||
SQLiteCursor cursor = database.queryFinalized(String.format(Locale.US, "SELECT mid, ttl, read_state FROM messages WHERE uid = %d AND out = %d AND ttl > 0 AND date <= %d AND send_state = 0", ((long)chat_id) << 32, isOut, time));
|
||||
while (cursor.next()) {
|
||||
int mid = cursor.intValue(0);
|
||||
int ttl = cursor.intValue(1);
|
||||
int read_state = cursor.intValue(2);
|
||||
int date = readTime + ttl;
|
||||
minDate = Math.min(minDate, date);
|
||||
ArrayList<Integer> arr = messages.get(date);
|
||||
|
@ -690,6 +717,63 @@ public class MessagesStorage {
|
|||
});
|
||||
}
|
||||
|
||||
public void updateChatInfo(final int chat_id, final int user_id, final boolean deleted, final int invited_id, final int version) {
|
||||
storageQueue.postRunnable(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
SQLiteCursor cursor = database.queryFinalized("SELECT participants FROM chat_settings WHERE uid = " + chat_id);
|
||||
TLRPC.ChatParticipants info = null;
|
||||
ArrayList<TLRPC.User> loadedUsers = new ArrayList<TLRPC.User>();
|
||||
if (cursor.next()) {
|
||||
byte[] userData = cursor.byteArrayValue(0);
|
||||
if (userData != null) {
|
||||
SerializedData data = new SerializedData(userData);
|
||||
info = (TLRPC.ChatParticipants)TLClassStore.Instance().TLdeserialize(data, data.readInt32());
|
||||
}
|
||||
}
|
||||
cursor.dispose();
|
||||
if (info != null) {
|
||||
if (deleted) {
|
||||
for (int a = 0; a < info.participants.size(); a++) {
|
||||
TLRPC.TL_chatParticipant participant = info.participants.get(a);
|
||||
if (participant.user_id == user_id) {
|
||||
info.participants.remove(a);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
TLRPC.TL_chatParticipant participant = new TLRPC.TL_chatParticipant();
|
||||
participant.user_id = user_id;
|
||||
participant.inviter_id = invited_id;
|
||||
participant.date = ConnectionsManager.Instance.getCurrentTime();
|
||||
info.participants.add(participant);
|
||||
}
|
||||
info.version = version;
|
||||
|
||||
final TLRPC.ChatParticipants finalInfo = info;
|
||||
Utilities.RunOnUIThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
NotificationCenter.Instance.postNotificationName(MessagesController.chatInfoDidLoaded, finalInfo.chat_id, finalInfo);
|
||||
}
|
||||
});
|
||||
|
||||
SQLitePreparedStatement state = database.executeFast("REPLACE INTO chat_settings VALUES(?, ?)");
|
||||
SerializedData data = new SerializedData();
|
||||
info.serializeToStream(data);
|
||||
state.bindInteger(1, chat_id);
|
||||
state.bindByteArray(2, data.toByteArray());
|
||||
state.step();
|
||||
state.dispose();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void loadChatInfo(final int chat_id) {
|
||||
storageQueue.postRunnable(new Runnable() {
|
||||
@Override
|
||||
|
@ -914,13 +998,125 @@ public class MessagesStorage {
|
|||
});
|
||||
}
|
||||
|
||||
public void getContacts() {
|
||||
public void deleteContacts(final ArrayList<Integer> uids) {
|
||||
if (uids == null || uids.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
storageQueue.postRunnable(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
ArrayList<TLRPC.TL_contact> contacts = new ArrayList<TLRPC.TL_contact>();
|
||||
ArrayList<TLRPC.User> users = new ArrayList<TLRPC.User>();
|
||||
String ids = "";
|
||||
for (Integer uid : uids) {
|
||||
if (ids.length() != 0) {
|
||||
ids += ",";
|
||||
}
|
||||
ids += "" + uid;
|
||||
}
|
||||
database.executeFast("DELETE FROM contacts WHERE uid IN (" + ids + ")").stepThis().dispose();
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void applyPhoneBookUpdates(final String adds, final String deletes) {
|
||||
if (adds.length() == 0 && deletes.length() == 0) {
|
||||
return;
|
||||
}
|
||||
storageQueue.postRunnable(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
if (adds.length() != 0) {
|
||||
database.executeFast(String.format(Locale.US, "UPDATE user_phones_v6 SET deleted = 0 WHERE sphone IN (%s)", adds)).stepThis().dispose();
|
||||
}
|
||||
if (deletes.length() != 0) {
|
||||
database.executeFast(String.format(Locale.US, "UPDATE user_phones_v6 SET deleted = 1 WHERE sphone IN (%s)", deletes)).stepThis().dispose();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void putCachedPhoneBook(final HashMap<Integer, ContactsController.Contact> contactHashMap) {
|
||||
storageQueue.postRunnable(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
database.executeFast("DELETE FROM user_contacts_v6 WHERE 1").stepThis().dispose();
|
||||
database.executeFast("DELETE FROM user_phones_v6 WHERE 1").stepThis().dispose();
|
||||
database.beginTransaction();
|
||||
SQLitePreparedStatement state = database.executeFast("REPLACE INTO user_contacts_v6 VALUES(?, ?, ?)");
|
||||
SQLitePreparedStatement state2 = database.executeFast("REPLACE INTO user_phones_v6 VALUES(?, ?, ?, ?)");
|
||||
for (HashMap.Entry<Integer, ContactsController.Contact> entry : contactHashMap.entrySet()) {
|
||||
ContactsController.Contact contact = entry.getValue();
|
||||
state.requery();
|
||||
state.bindInteger(1, contact.id);
|
||||
state.bindString(2, contact.first_name);
|
||||
state.bindString(3, contact.last_name);
|
||||
state.step();
|
||||
for (int a = 0; a < contact.phones.size(); a++) {
|
||||
state2.requery();
|
||||
state2.bindInteger(1, contact.id);
|
||||
state2.bindString(2, contact.phones.get(a));
|
||||
state2.bindString(3, contact.shortPhones.get(a));
|
||||
state2.bindInteger(4, contact.phoneDeleted.get(a));
|
||||
state2.step();
|
||||
}
|
||||
}
|
||||
state.dispose();
|
||||
state2.dispose();
|
||||
database.commitTransaction();
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void getCachedPhoneBook() {
|
||||
storageQueue.postRunnable(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
HashMap<Integer, ContactsController.Contact> contactHashMap = new HashMap<Integer, ContactsController.Contact>();
|
||||
try {
|
||||
SQLiteCursor cursor = database.queryFinalized("SELECT us.uid, us.fname, us.sname, up.phone, up.sphone, up.deleted FROM user_contacts_v6 as us LEFT JOIN user_phones_v6 as up ON us.uid = up.uid WHERE 1");
|
||||
while (cursor.next()) {
|
||||
int uid = cursor.intValue(0);
|
||||
ContactsController.Contact contact = contactHashMap.get(uid);
|
||||
if (contact == null) {
|
||||
contact = new ContactsController.Contact();
|
||||
contact.first_name = cursor.stringValue(1);
|
||||
contact.last_name = cursor.stringValue(2);
|
||||
contact.id = uid;
|
||||
contactHashMap.put(uid, contact);
|
||||
}
|
||||
contact.phones.add(cursor.stringValue(3));
|
||||
contact.shortPhones.add(cursor.stringValue(4));
|
||||
contact.phoneDeleted.add(cursor.intValue(5));
|
||||
contact.phoneTypes.add("");
|
||||
}
|
||||
cursor.dispose();
|
||||
} catch (Exception e) {
|
||||
contactHashMap.clear();
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
ContactsController.Instance.performSyncPhoneBook(contactHashMap, true, true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void getContacts() {
|
||||
storageQueue.postRunnable(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ArrayList<TLRPC.TL_contact> contacts = new ArrayList<TLRPC.TL_contact>();
|
||||
ArrayList<TLRPC.User> users = new ArrayList<TLRPC.User>();
|
||||
try {
|
||||
SQLiteCursor cursor = database.queryFinalized("SELECT * FROM contacts WHERE 1");
|
||||
String uids = "";
|
||||
while (cursor.next()) {
|
||||
|
@ -954,10 +1150,12 @@ public class MessagesStorage {
|
|||
}
|
||||
cursor.dispose();
|
||||
}
|
||||
MessagesController.Instance.processLoadedContacts(contacts, users, 1);
|
||||
} catch (Exception e) {
|
||||
contacts.clear();
|
||||
users.clear();
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
ContactsController.Instance.processLoadedContacts(contacts, users, 1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -1103,8 +1301,6 @@ public class MessagesStorage {
|
|||
state2.bindInteger(3, message.date);
|
||||
state2.bindByteArray(4, data.toByteArray());
|
||||
state2.step();
|
||||
} else {
|
||||
Log.e("tmessages", "test");
|
||||
}
|
||||
}
|
||||
state2.dispose();
|
||||
|
@ -1136,7 +1332,7 @@ public class MessagesStorage {
|
|||
|
||||
if (lower_id != 0) {
|
||||
if (forward) {
|
||||
cursor = database.queryFinalized(String.format(Locale.US, "SELECT read_state, data, send_state, mid, date FROM messages WHERE uid = %d AND mid > %d ORDER BY date ASC, mid ASC LIMIT %d", dialog_id, max_id, count_query));
|
||||
cursor = database.queryFinalized(String.format(Locale.US, "SELECT read_state, data, send_state, mid, date FROM messages WHERE uid = %d AND date >= %d AND mid > %d ORDER BY date ASC, mid ASC LIMIT %d", dialog_id, minDate, max_id, count_query));
|
||||
} else if (minDate != 0) {
|
||||
if (max_id != 0) {
|
||||
cursor = database.queryFinalized(String.format(Locale.US, "SELECT read_state, data, send_state, mid, date FROM messages WHERE uid = %d AND date < %d AND mid < %d ORDER BY date DESC, mid DESC LIMIT %d", dialog_id, minDate, max_id, count_query));
|
||||
|
@ -1559,9 +1755,87 @@ public class MessagesStorage {
|
|||
HashMap<Long, TLRPC.Message> messagesMap = new HashMap<Long, TLRPC.Message>();
|
||||
HashMap<Long, Integer> messagesCounts = new HashMap<Long, Integer>();
|
||||
HashMap<Long, Integer> mediaCounts = new HashMap<Long, Integer>();
|
||||
HashMap<Integer, Long> messagesIdsMap = new HashMap<Integer, Long>();
|
||||
HashMap<Integer, Long> messagesMediaIdsMap = new HashMap<Integer, Long>();
|
||||
String messageIds = "";
|
||||
String messageMediaIds = "";
|
||||
SQLitePreparedStatement state = database.executeFast("REPLACE INTO messages VALUES(?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
SQLitePreparedStatement state2 = database.executeFast("REPLACE INTO media VALUES(?, ?, ?, ?)");
|
||||
SQLitePreparedStatement state3 = database.executeFast("REPLACE INTO randoms VALUES(?, ?)");
|
||||
|
||||
for (TLRPC.Message message : messages) {
|
||||
long dialog_id = 0;
|
||||
if (message.unread && !message.out) {
|
||||
if (messageIds.length() > 0) {
|
||||
messageIds += ",";
|
||||
}
|
||||
messageIds += message.id;
|
||||
|
||||
dialog_id = message.dialog_id;
|
||||
if (dialog_id == 0) {
|
||||
if (message.to_id.chat_id != 0) {
|
||||
dialog_id = -message.to_id.chat_id;
|
||||
} else if (message.to_id.user_id != 0) {
|
||||
dialog_id = message.to_id.user_id;
|
||||
}
|
||||
}
|
||||
|
||||
messagesIdsMap.put(message.id, dialog_id);
|
||||
}
|
||||
|
||||
if (message.media instanceof TLRPC.TL_messageMediaVideo || message.media instanceof TLRPC.TL_messageMediaPhoto) {
|
||||
if (dialog_id == 0) {
|
||||
dialog_id = message.dialog_id;
|
||||
if (dialog_id == 0) {
|
||||
if (message.to_id.chat_id != 0) {
|
||||
dialog_id = -message.to_id.chat_id;
|
||||
} else if (message.to_id.user_id != 0) {
|
||||
dialog_id = message.to_id.user_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (messageMediaIds.length() > 0) {
|
||||
messageMediaIds += ",";
|
||||
}
|
||||
messageMediaIds += message.id;
|
||||
messagesMediaIdsMap.put(message.id, dialog_id);
|
||||
}
|
||||
}
|
||||
|
||||
if (messageIds.length() > 0) {
|
||||
SQLiteCursor cursor = database.queryFinalized("SELECT mid FROM messages WHERE mid IN(" + messageIds + ")");
|
||||
while (cursor.next()) {
|
||||
int mid = cursor.intValue(0);
|
||||
messagesIdsMap.remove(mid);
|
||||
}
|
||||
cursor.dispose();
|
||||
for (Long dialog_id : messagesIdsMap.values()) {
|
||||
Integer count = messagesCounts.get(dialog_id);
|
||||
if (count == null) {
|
||||
count = 0;
|
||||
}
|
||||
count++;
|
||||
messagesCounts.put(dialog_id, count);
|
||||
}
|
||||
}
|
||||
|
||||
if (messageMediaIds.length() > 0) {
|
||||
SQLiteCursor cursor = database.queryFinalized("SELECT mid FROM media WHERE mid IN(" + messageMediaIds + ")");
|
||||
while (cursor.next()) {
|
||||
int mid = cursor.intValue(0);
|
||||
messagesMediaIdsMap.remove(mid);
|
||||
}
|
||||
cursor.dispose();
|
||||
for (Long dialog_id : messagesMediaIdsMap.values()) {
|
||||
Integer count = mediaCounts.get(dialog_id);
|
||||
if (count == null) {
|
||||
count = 0;
|
||||
}
|
||||
count++;
|
||||
mediaCounts.put(dialog_id, count);
|
||||
}
|
||||
}
|
||||
|
||||
for (TLRPC.Message message : messages) {
|
||||
long dialog_id = message.dialog_id;
|
||||
if (dialog_id == 0) {
|
||||
|
@ -1584,14 +1858,6 @@ public class MessagesStorage {
|
|||
if (lastMessage == null || message.date > lastMessage.date) {
|
||||
messagesMap.put(dialog_id, message);
|
||||
}
|
||||
if (message.unread && !message.out) {
|
||||
Integer count = messagesCounts.get(dialog_id);
|
||||
if (count == null) {
|
||||
count = 0;
|
||||
}
|
||||
count++;
|
||||
messagesCounts.put(dialog_id, count);
|
||||
}
|
||||
state.bindInteger(1, messageId);
|
||||
state.bindLong(2, dialog_id);
|
||||
state.bindInteger(3, (message.unread ? 0 : 1));
|
||||
|
@ -1611,28 +1877,12 @@ public class MessagesStorage {
|
|||
}
|
||||
|
||||
if (message.media instanceof TLRPC.TL_messageMediaVideo || message.media instanceof TLRPC.TL_messageMediaPhoto) {
|
||||
boolean exist = false;
|
||||
SQLiteCursor cursor = database.queryFinalized(String.format(Locale.US, "SELECT mid FROM media WHERE mid = %d LIMIT 1", message.id));
|
||||
if (cursor.next()) {
|
||||
exist = true;
|
||||
}
|
||||
cursor.dispose();
|
||||
|
||||
state2.requery();
|
||||
state2.bindInteger(1, messageId);
|
||||
state2.bindLong(2, dialog_id);
|
||||
state2.bindInteger(3, message.date);
|
||||
state2.bindByteArray(4, bytes);
|
||||
state2.step();
|
||||
|
||||
if (!exist) {
|
||||
Integer count = mediaCounts.get(dialog_id);
|
||||
if (count == null) {
|
||||
count = 0;
|
||||
}
|
||||
count++;
|
||||
mediaCounts.put(dialog_id, count);
|
||||
}
|
||||
}
|
||||
}
|
||||
state.dispose();
|
||||
|
@ -1662,6 +1912,7 @@ public class MessagesStorage {
|
|||
if (withTransaction) {
|
||||
database.commitTransaction();
|
||||
}
|
||||
MessagesController.Instance.dialogsUnreadCountIncr(messagesCounts);
|
||||
|
||||
if (!mediaCounts.isEmpty()) {
|
||||
state = database.executeFast("REPLACE INTO media_counts VALUES(?, ?)");
|
||||
|
|
|
@ -12,42 +12,41 @@ import java.util.ArrayList;
|
|||
import java.util.HashMap;
|
||||
|
||||
public class NotificationCenter {
|
||||
|
||||
public static NotificationCenter Instance = new NotificationCenter();
|
||||
|
||||
final private HashMap<Integer, ArrayList<Object>> observers = new HashMap<Integer, ArrayList<Object>>();
|
||||
final private HashMap<Integer, Object> memCache = new HashMap<Integer, Object>();
|
||||
final private HashMap<String, Object> memCacheString = new HashMap<String, Object>();
|
||||
private boolean broadcasting = false;
|
||||
|
||||
final private HashMap<String, Object> memCache = new HashMap<String, Object>();
|
||||
|
||||
final private HashMap<Integer, Object> removeAfterBroadcast = new HashMap<Integer, Object>();
|
||||
final private HashMap<Integer, Object> addAfterBroadcast = new HashMap<Integer, Object>();
|
||||
|
||||
private boolean broadcasting = false;
|
||||
|
||||
public interface NotificationCenterDelegate {
|
||||
public abstract void didReceivedNotification(int id, Object... args);
|
||||
}
|
||||
|
||||
public static NotificationCenter Instance = new NotificationCenter();
|
||||
|
||||
public void addToMemCache(int id, Object object) {
|
||||
memCache.put(id, object);
|
||||
addToMemCache(String.valueOf(id), object);
|
||||
}
|
||||
|
||||
public void addToMemCache(String id, Object object) {
|
||||
memCacheString.put(id, object);
|
||||
memCache.put(id, object);
|
||||
}
|
||||
|
||||
public Object getFromMemCache(int id) {
|
||||
Object obj = memCache.get(id);
|
||||
if (obj != null) {
|
||||
memCache.remove(id);
|
||||
}
|
||||
return obj;
|
||||
return getFromMemCache(String.valueOf(id), null);
|
||||
}
|
||||
|
||||
public Object getFromMemCache(String id, Object defaultValue) {
|
||||
Object obj = memCacheString.get(id);
|
||||
Object obj = memCache.get(id);
|
||||
if (obj != null) {
|
||||
memCacheString.remove(id);
|
||||
} else {
|
||||
return defaultValue;
|
||||
memCache.remove(id);
|
||||
return obj;
|
||||
}
|
||||
return obj;
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public void postNotificationName(int id, Object... args) {
|
||||
|
@ -66,15 +65,24 @@ public class NotificationCenter {
|
|||
}
|
||||
removeAfterBroadcast.clear();
|
||||
}
|
||||
if (!addAfterBroadcast.isEmpty()) {
|
||||
for (HashMap.Entry<Integer, Object> entry : addAfterBroadcast.entrySet()) {
|
||||
addObserver(entry.getValue(), entry.getKey());
|
||||
}
|
||||
addAfterBroadcast.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addObserver(Object observer, int id) {
|
||||
synchronized (observers) {
|
||||
if (broadcasting) {
|
||||
addAfterBroadcast.put(id, observer);
|
||||
return;
|
||||
}
|
||||
ArrayList<Object> objects = observers.get(id);
|
||||
if (objects == null) {
|
||||
objects = new ArrayList<Object>();
|
||||
observers.put(id, objects);
|
||||
observers.put(id, (objects = new ArrayList<Object>()));
|
||||
}
|
||||
if (objects.contains(observer)) {
|
||||
return;
|
||||
|
@ -83,25 +91,6 @@ public class NotificationCenter {
|
|||
}
|
||||
}
|
||||
|
||||
// public void removeObserver(Object observer) {
|
||||
// synchronized (observers) {
|
||||
// if (broadcasting) {
|
||||
// removeAfterBroadcast.put(-1, observer);
|
||||
// return;
|
||||
// }
|
||||
// Integer[] keyArr = (Integer[])observers.keySet().toArray();
|
||||
// for (int a = 0; a < observers.size(); a++) {
|
||||
// Integer id = keyArr[a];
|
||||
// ArrayList<Object> objects = observers.get(id);
|
||||
// objects.remove(observer);
|
||||
// if (objects.size() == 0) {
|
||||
// observers.remove(id);
|
||||
// a--;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
public void removeObserver(Object observer, int id) {
|
||||
synchronized (observers) {
|
||||
if (broadcasting) {
|
||||
|
|
|
@ -29,6 +29,7 @@ public class RPCRequest {
|
|||
public static int RPCRequestClassUploadMedia = 4;
|
||||
public static int RPCRequestClassEnableUnauthorized = 8;
|
||||
public static int RPCRequestClassFailOnServerErrors = 16;
|
||||
public static int RPCRequestClassCanCompress = 32;
|
||||
|
||||
static int RPCRequestClassTransportMask = (RPCRequestClassGeneric | RPCRequestClassDownloadMedia | RPCRequestClassUploadMedia);
|
||||
|
||||
|
@ -37,6 +38,7 @@ public class RPCRequest {
|
|||
|
||||
int serverFailureCount;
|
||||
int flags;
|
||||
public int retryCount = 0;
|
||||
|
||||
TLObject rawRequest;
|
||||
TLObject rpcRequest;
|
||||
|
|
|
@ -22,12 +22,23 @@ public class SerializedData {
|
|||
private DataOutputStream out;
|
||||
private ByteArrayInputStream inbuf;
|
||||
private DataInputStream in;
|
||||
private boolean justCalc = false;
|
||||
private int len;
|
||||
|
||||
public SerializedData() {
|
||||
outbuf = new ByteArrayOutputStream();
|
||||
out = new DataOutputStream(outbuf);
|
||||
}
|
||||
|
||||
public SerializedData(boolean calculate) {
|
||||
if (!calculate) {
|
||||
outbuf = new ByteArrayOutputStream();
|
||||
out = new DataOutputStream(outbuf);
|
||||
}
|
||||
justCalc = calculate;
|
||||
len = 0;
|
||||
}
|
||||
|
||||
public SerializedData(int size) {
|
||||
outbuf = new ByteArrayOutputStream(size);
|
||||
out = new DataOutputStream(outbuf);
|
||||
|
@ -50,13 +61,17 @@ public class SerializedData {
|
|||
in = new DataInputStream(inbuf);
|
||||
}
|
||||
|
||||
public void writeInt32(int x){
|
||||
writeInt32(x, out);
|
||||
public void writeInt32(int x) {
|
||||
if (!justCalc) {
|
||||
writeInt32(x, out);
|
||||
} else {
|
||||
len += 4;
|
||||
}
|
||||
}
|
||||
|
||||
protected void writeInt32(int x, DataOutputStream out){
|
||||
private void writeInt32(int x, DataOutputStream out) {
|
||||
try {
|
||||
for(int i = 0; i < 4; i++){
|
||||
for(int i = 0; i < 4; i++) {
|
||||
out.write(x >> (i * 8));
|
||||
}
|
||||
} catch(IOException gfdsgd) {
|
||||
|
@ -65,10 +80,14 @@ public class SerializedData {
|
|||
}
|
||||
|
||||
public void writeInt64(long i) {
|
||||
writeInt64(i, out);
|
||||
if (!justCalc) {
|
||||
writeInt64(i, out);
|
||||
} else {
|
||||
len += 8;
|
||||
}
|
||||
}
|
||||
|
||||
protected void writeInt64(long x, DataOutputStream out){
|
||||
private void writeInt64(long x, DataOutputStream out) {
|
||||
try {
|
||||
for(int i = 0; i < 8; i++){
|
||||
out.write((int)(x >> (i * 8)));
|
||||
|
@ -90,10 +109,14 @@ public class SerializedData {
|
|||
}
|
||||
|
||||
public void writeBool(boolean value) {
|
||||
if (value) {
|
||||
writeInt32(0x997275b5);
|
||||
if (!justCalc) {
|
||||
if (value) {
|
||||
writeInt32(0x997275b5);
|
||||
} else {
|
||||
writeInt32(0xbc799737);
|
||||
}
|
||||
} else {
|
||||
writeInt32(0xbc799737);
|
||||
len += 4;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -143,9 +166,13 @@ public class SerializedData {
|
|||
return 0;
|
||||
}
|
||||
|
||||
public void writeRaw(byte[] b){
|
||||
public void writeRaw(byte[] b) {
|
||||
try {
|
||||
out.write(b);
|
||||
if (!justCalc) {
|
||||
out.write(b);
|
||||
} else {
|
||||
len += b.length;
|
||||
}
|
||||
} catch(Exception x) {
|
||||
FileLog.e("tmessages", "write raw error");
|
||||
}
|
||||
|
@ -153,7 +180,11 @@ public class SerializedData {
|
|||
|
||||
public void writeRaw(byte[] b, int offset, int count) {
|
||||
try {
|
||||
out.write(b, offset, count);
|
||||
if (!justCalc) {
|
||||
out.write(b, offset, count);
|
||||
} else {
|
||||
len += count;
|
||||
}
|
||||
} catch(Exception x) {
|
||||
FileLog.e("tmessages", "write raw error");
|
||||
}
|
||||
|
@ -161,7 +192,11 @@ public class SerializedData {
|
|||
|
||||
public void writeByte(int i) {
|
||||
try {
|
||||
out.writeByte((byte)i);
|
||||
if (!justCalc) {
|
||||
out.writeByte((byte)i);
|
||||
} else {
|
||||
len += 1;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", "write byte error");
|
||||
}
|
||||
|
@ -169,13 +204,17 @@ public class SerializedData {
|
|||
|
||||
public void writeByte(byte b) {
|
||||
try {
|
||||
out.writeByte(b);
|
||||
if (!justCalc) {
|
||||
out.writeByte(b);
|
||||
} else {
|
||||
len += 1;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", "write byte error");
|
||||
}
|
||||
}
|
||||
|
||||
public void readRaw(byte[] b){
|
||||
public void readRaw(byte[] b) {
|
||||
try {
|
||||
in.read(b);
|
||||
} catch(Exception x) {
|
||||
|
@ -189,7 +228,7 @@ public class SerializedData {
|
|||
return arr;
|
||||
}
|
||||
|
||||
public String readString(){
|
||||
public String readString() {
|
||||
try {
|
||||
int sl = 1;
|
||||
int l = in.read();
|
||||
|
@ -233,20 +272,36 @@ public class SerializedData {
|
|||
return null;
|
||||
}
|
||||
|
||||
public void writeByteArray(byte[] b){
|
||||
public void writeByteArray(byte[] b) {
|
||||
try {
|
||||
if (b.length <= 253){
|
||||
out.write(b.length);
|
||||
if (!justCalc) {
|
||||
out.write(b.length);
|
||||
} else {
|
||||
len += 1;
|
||||
}
|
||||
} else {
|
||||
out.write(254);
|
||||
out.write(b.length);
|
||||
out.write(b.length >> 8);
|
||||
out.write(b.length >> 16);
|
||||
if (!justCalc) {
|
||||
out.write(254);
|
||||
out.write(b.length);
|
||||
out.write(b.length >> 8);
|
||||
out.write(b.length >> 16);
|
||||
} else {
|
||||
len += 4;
|
||||
}
|
||||
}
|
||||
if (!justCalc) {
|
||||
out.write(b);
|
||||
} else {
|
||||
len += b.length;
|
||||
}
|
||||
out.write(b);
|
||||
int i = b.length <= 253 ? 1 : 4;
|
||||
while((b.length + i) % 4 != 0){
|
||||
out.write(0);
|
||||
if (!justCalc) {
|
||||
out.write(0);
|
||||
} else {
|
||||
len += 1;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
} catch(Exception x) {
|
||||
|
@ -265,17 +320,33 @@ public class SerializedData {
|
|||
public void writeByteArray(byte[] b, int offset, int count) {
|
||||
try {
|
||||
if(count <= 253){
|
||||
out.write(count);
|
||||
if (!justCalc) {
|
||||
out.write(count);
|
||||
} else {
|
||||
len += 1;
|
||||
}
|
||||
} else {
|
||||
out.write(254);
|
||||
out.write(count);
|
||||
out.write(count >> 8);
|
||||
out.write(count >> 16);
|
||||
if (!justCalc) {
|
||||
out.write(254);
|
||||
out.write(count);
|
||||
out.write(count >> 8);
|
||||
out.write(count >> 16);
|
||||
} else {
|
||||
len += 4;
|
||||
}
|
||||
}
|
||||
if (!justCalc) {
|
||||
out.write(b, offset, count);
|
||||
} else {
|
||||
len += count;
|
||||
}
|
||||
out.write(b, offset, count);
|
||||
int i = count <= 253 ? 1 : 4;
|
||||
while ((count + i) % 4 != 0){
|
||||
out.write(0);
|
||||
if (!justCalc) {
|
||||
out.write(0);
|
||||
} else {
|
||||
len += 1;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
} catch(Exception x) {
|
||||
|
@ -292,7 +363,7 @@ public class SerializedData {
|
|||
return 0;
|
||||
}
|
||||
|
||||
public void writeDouble(double d){
|
||||
public void writeDouble(double d) {
|
||||
try {
|
||||
writeInt64(Double.doubleToRawLongBits(d));
|
||||
} catch(Exception x) {
|
||||
|
@ -301,7 +372,10 @@ public class SerializedData {
|
|||
}
|
||||
|
||||
public int length() {
|
||||
return isOut ? outbuf.size() : inbuf.available();
|
||||
if (!justCalc) {
|
||||
return isOut ? outbuf.size() : inbuf.available();
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
protected void set(byte[] newData) {
|
||||
|
|
|
@ -15,8 +15,6 @@ import android.content.SharedPreferences;
|
|||
import android.os.Bundle;
|
||||
import android.telephony.SmsMessage;
|
||||
|
||||
import org.telegram.messenger.NotificationCenter;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
@ -27,6 +25,9 @@ public class SmsListener extends BroadcastReceiver {
|
|||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if(intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")) {
|
||||
if (!Utilities.isWaitingForSms()) {
|
||||
return;
|
||||
}
|
||||
Bundle bundle = intent.getExtras();
|
||||
SmsMessage[] msgs;
|
||||
if (bundle != null) {
|
||||
|
|
|
@ -10,6 +10,7 @@ package org.telegram.messenger;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.util.Timer;
|
||||
|
@ -50,6 +51,8 @@ public class TcpConnection extends PyroClientAdapter {
|
|||
private boolean hasSomeDataSinceLastConnect = false;
|
||||
private int willRetryConnectCount = 5;
|
||||
private boolean isNextPort = false;
|
||||
private final Integer timerSync = 1;
|
||||
private boolean wasConnected;
|
||||
|
||||
public int transportRequestClass;
|
||||
|
||||
|
@ -86,9 +89,11 @@ public class TcpConnection extends PyroClientAdapter {
|
|||
connectionState = TcpConnectionState.TcpConnectionStageConnecting;
|
||||
try {
|
||||
try {
|
||||
if (reconnectTimer != null) {
|
||||
reconnectTimer.cancel();
|
||||
reconnectTimer = null;
|
||||
synchronized (timerSync) {
|
||||
if (reconnectTimer != null) {
|
||||
reconnectTimer.cancel();
|
||||
reconnectTimer = null;
|
||||
}
|
||||
}
|
||||
} catch (Exception e2) {
|
||||
FileLog.e("tmessages", e2);
|
||||
|
@ -99,6 +104,7 @@ public class TcpConnection extends PyroClientAdapter {
|
|||
FileLog.d("tmessages", String.format(TcpConnection.this + " Connecting (%s:%d)", hostAddress, hostPort));
|
||||
firstPacket = true;
|
||||
restOfTheData = null;
|
||||
wasConnected = false;
|
||||
hasSomeDataSinceLastConnect = false;
|
||||
if (client != null) {
|
||||
client.removeListener(TcpConnection.this);
|
||||
|
@ -110,24 +116,27 @@ public class TcpConnection extends PyroClientAdapter {
|
|||
if (isNextPort) {
|
||||
client.setTimeout(8000);
|
||||
} else {
|
||||
client.setTimeout(35000);
|
||||
client.setTimeout(15000);
|
||||
}
|
||||
selector.wakeup();
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
if (reconnectTimer != null) {
|
||||
reconnectTimer.cancel();
|
||||
reconnectTimer = null;
|
||||
synchronized (timerSync) {
|
||||
if (reconnectTimer != null) {
|
||||
reconnectTimer.cancel();
|
||||
reconnectTimer = null;
|
||||
}
|
||||
}
|
||||
} catch (Exception e2) {
|
||||
FileLog.e("tmessages", e2);
|
||||
}
|
||||
connectionState = TcpConnectionState.TcpConnectionStageReconnecting;
|
||||
if (delegate != null) {
|
||||
final TcpConnectionDelegate finalDelegate = delegate;
|
||||
Utilities.stageQueue.postRunnable(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
delegate.tcpConnectionClosed(TcpConnection.this);
|
||||
finalDelegate.tcpConnectionClosed(TcpConnection.this);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -135,7 +144,7 @@ public class TcpConnection extends PyroClientAdapter {
|
|||
failedConnectionCount++;
|
||||
if (failedConnectionCount == 1) {
|
||||
if (hasSomeDataSinceLastConnect) {
|
||||
willRetryConnectCount = 5;
|
||||
willRetryConnectCount = 3;
|
||||
} else {
|
||||
willRetryConnectCount = 1;
|
||||
}
|
||||
|
@ -160,9 +169,11 @@ public class TcpConnection extends PyroClientAdapter {
|
|||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
if (reconnectTimer != null) {
|
||||
reconnectTimer.cancel();
|
||||
reconnectTimer = null;
|
||||
synchronized (timerSync) {
|
||||
if (reconnectTimer != null) {
|
||||
reconnectTimer.cancel();
|
||||
reconnectTimer = null;
|
||||
}
|
||||
}
|
||||
} catch (Exception e2) {
|
||||
FileLog.e("tmessages", e2);
|
||||
|
@ -181,9 +192,11 @@ public class TcpConnection extends PyroClientAdapter {
|
|||
}
|
||||
|
||||
private void suspendConnectionInternal() {
|
||||
if (reconnectTimer != null) {
|
||||
reconnectTimer.cancel();
|
||||
reconnectTimer = null;
|
||||
synchronized (timerSync) {
|
||||
if (reconnectTimer != null) {
|
||||
reconnectTimer.cancel();
|
||||
reconnectTimer = null;
|
||||
}
|
||||
}
|
||||
if (connectionState == TcpConnectionState.TcpConnectionStageIdle || connectionState == TcpConnectionState.TcpConnectionStageSuspended) {
|
||||
return;
|
||||
|
@ -196,16 +209,18 @@ public class TcpConnection extends PyroClientAdapter {
|
|||
client = null;
|
||||
}
|
||||
if (delegate != null) {
|
||||
final TcpConnectionDelegate finalDelegate = delegate;
|
||||
Utilities.stageQueue.postRunnable(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
delegate.tcpConnectionClosed(TcpConnection.this);
|
||||
finalDelegate.tcpConnectionClosed(TcpConnection.this);
|
||||
}
|
||||
});
|
||||
}
|
||||
firstPacket = true;
|
||||
restOfTheData = null;
|
||||
channelToken = 0;
|
||||
wasConnected = false;
|
||||
}
|
||||
|
||||
public void suspendConnection(boolean task) {
|
||||
|
@ -295,7 +310,7 @@ public class TcpConnection extends PyroClientAdapter {
|
|||
Datacenter datacenter = ConnectionsManager.Instance.datacenterWithId(datacenterId);
|
||||
datacenter.storeCurrentAddressAndPortNum();
|
||||
isNextPort = false;
|
||||
client.setTimeout(35000);
|
||||
client.setTimeout(20000);
|
||||
}
|
||||
hasSomeDataSinceLastConnect = true;
|
||||
|
||||
|
@ -314,10 +329,11 @@ public class TcpConnection extends PyroClientAdapter {
|
|||
buffer.order(ByteOrder.BIG_ENDIAN);
|
||||
final int ackId = buffer.getInt() & (~(1 << 31));
|
||||
if (delegate != null) {
|
||||
final TcpConnectionDelegate finalDelegate = delegate;
|
||||
Utilities.stageQueue.postRunnable(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
delegate.tcpConnectionQuiackAckReceived(TcpConnection.this, ackId);
|
||||
finalDelegate.tcpConnectionQuiackAckReceived(TcpConnection.this, ackId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -360,12 +376,13 @@ public class TcpConnection extends PyroClientAdapter {
|
|||
}
|
||||
if (lastMessageId != -1 && lastMessageId != 0) {
|
||||
if (delegate != null) {
|
||||
final TcpConnectionDelegate finalDelegate = delegate;
|
||||
final int arg2 = buffer.remaining();
|
||||
final int arg3 = currentPacketLength;
|
||||
Utilities.stageQueue.postRunnable(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
delegate.tcpConnectionProgressChanged(TcpConnection.this, lastMessageId, arg2, arg3);
|
||||
finalDelegate.tcpConnectionProgressChanged(TcpConnection.this, lastMessageId, arg2, arg3);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -383,39 +400,43 @@ public class TcpConnection extends PyroClientAdapter {
|
|||
buffer.get(packetData);
|
||||
|
||||
if (delegate != null) {
|
||||
final TcpConnectionDelegate finalDelegate = delegate;
|
||||
Utilities.stageQueue.postRunnable(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
delegate.tcpConnectionReceivedData(TcpConnection.this, packetData);
|
||||
finalDelegate.tcpConnectionReceivedData(TcpConnection.this, packetData);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void handleDisconnect(PyroClient client, Exception e) {
|
||||
if (reconnectTimer != null) {
|
||||
reconnectTimer.cancel();
|
||||
reconnectTimer = null;
|
||||
public void handleDisconnect(PyroClient client, Exception e, boolean timedout) {
|
||||
synchronized (timerSync) {
|
||||
if (reconnectTimer != null) {
|
||||
reconnectTimer.cancel();
|
||||
reconnectTimer = null;
|
||||
}
|
||||
}
|
||||
if (e != null) {
|
||||
FileLog.d("tmessages", "Disconnected " + TcpConnection.this + " with error " + e);
|
||||
} else {
|
||||
FileLog.d("tmessages", "Disconnected " + TcpConnection.this);
|
||||
}
|
||||
boolean switchToNextPort = wasConnected && !hasSomeDataSinceLastConnect && timedout;
|
||||
firstPacket = true;
|
||||
restOfTheData = null;
|
||||
channelToken = 0;
|
||||
wasConnected = false;
|
||||
if (connectionState != TcpConnectionState.TcpConnectionStageSuspended && connectionState != TcpConnectionState.TcpConnectionStageIdle) {
|
||||
connectionState = TcpConnectionState.TcpConnectionStageIdle;
|
||||
}
|
||||
if (delegate != null) {
|
||||
final TcpConnectionDelegate finalDelegate = delegate;
|
||||
Utilities.stageQueue.postRunnable(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (delegate != null) {
|
||||
delegate.tcpConnectionClosed(TcpConnection.this);
|
||||
}
|
||||
finalDelegate.tcpConnectionClosed(TcpConnection.this);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -431,7 +452,7 @@ public class TcpConnection extends PyroClientAdapter {
|
|||
}
|
||||
if (ConnectionsManager.isNetworkOnline()) {
|
||||
isNextPort = true;
|
||||
if (failedConnectionCount > willRetryConnectCount) {
|
||||
if (failedConnectionCount > willRetryConnectCount || switchToNextPort) {
|
||||
Datacenter datacenter = ConnectionsManager.Instance.datacenterWithId(datacenterId);
|
||||
datacenter.nextAddressOrPort();
|
||||
failedConnectionCount = 0;
|
||||
|
@ -447,9 +468,11 @@ public class TcpConnection extends PyroClientAdapter {
|
|||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
if (reconnectTimer != null) {
|
||||
reconnectTimer.cancel();
|
||||
reconnectTimer = null;
|
||||
synchronized (timerSync) {
|
||||
if (reconnectTimer != null) {
|
||||
reconnectTimer.cancel();
|
||||
reconnectTimer = null;
|
||||
}
|
||||
}
|
||||
} catch (Exception e2) {
|
||||
FileLog.e("tmessages", e2);
|
||||
|
@ -469,12 +492,14 @@ public class TcpConnection extends PyroClientAdapter {
|
|||
public void connectedClient(PyroClient client) {
|
||||
connectionState = TcpConnectionState.TcpConnectionStageConnected;
|
||||
channelToken = generateChannelToken();
|
||||
wasConnected = true;
|
||||
FileLog.d("tmessages", String.format(TcpConnection.this + " Connected (%s:%d)", hostAddress, hostPort));
|
||||
if (delegate != null) {
|
||||
final TcpConnectionDelegate finalDelegate = delegate;
|
||||
Utilities.stageQueue.postRunnable(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
delegate.tcpConnectionConnected(TcpConnection.this);
|
||||
finalDelegate.tcpConnectionConnected(TcpConnection.this);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -482,18 +507,18 @@ public class TcpConnection extends PyroClientAdapter {
|
|||
|
||||
@Override
|
||||
public void unconnectableClient(PyroClient client, Exception cause) {
|
||||
handleDisconnect(client, cause);
|
||||
handleDisconnect(client, cause, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void droppedClient(PyroClient client, IOException cause) {
|
||||
super.droppedClient(client, cause);
|
||||
handleDisconnect(client, cause);
|
||||
handleDisconnect(client, cause, (cause instanceof SocketTimeoutException));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnectedClient(PyroClient client) {
|
||||
handleDisconnect(client, null);
|
||||
handleDisconnect(client, null, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -509,7 +534,5 @@ public class TcpConnection extends PyroClientAdapter {
|
|||
|
||||
@Override
|
||||
public void sentData(PyroClient client, int bytes) {
|
||||
failedConnectionCount = 0;
|
||||
FileLog.d("tmessages", TcpConnection.this + " bytes sent " + bytes);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -190,8 +190,8 @@ public class UserConfig {
|
|||
currentUser = null;
|
||||
registeredForPush = false;
|
||||
contactsHash = "";
|
||||
lastLocalId = -210000;
|
||||
importHash = "";
|
||||
lastLocalId = -210000;
|
||||
lastSendMessageId = -210000;
|
||||
saveIncomingPhotos = false;
|
||||
saveConfig(true);
|
||||
|
|
|
@ -10,13 +10,18 @@ package org.telegram.messenger;
|
|||
|
||||
import android.app.Activity;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.ContentUris;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.Typeface;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Environment;
|
||||
import android.os.Handler;
|
||||
import android.provider.DocumentsContract;
|
||||
import android.provider.MediaStore;
|
||||
import android.text.Html;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.text.format.DateFormat;
|
||||
|
@ -49,7 +54,10 @@ import java.util.Calendar;
|
|||
import java.util.Date;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Locale;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
|
||||
|
@ -57,8 +65,13 @@ public class Utilities {
|
|||
public static Handler applicationHandler;
|
||||
public static int statusBarHeight = 0;
|
||||
public static float density = 1;
|
||||
public static boolean isRTL = false;
|
||||
public static Pattern pattern = Pattern.compile("[0-9]+");
|
||||
private final static Integer lock = 1;
|
||||
|
||||
private static boolean waitingForSms = false;
|
||||
private static final Integer smsLock = 2;
|
||||
|
||||
public static ArrayList<String> goodPrimes = new ArrayList<String>();
|
||||
|
||||
public static class TPFactorizedValue {
|
||||
|
@ -74,6 +87,30 @@ public class Utilities {
|
|||
public native static long doPQNative(long _what);
|
||||
public native static byte[] aesIgeEncryption(byte[] _what, byte[] _key, byte[] _iv, boolean encrypt, boolean changeIv);
|
||||
|
||||
public static boolean isWaitingForSms() {
|
||||
boolean value = false;
|
||||
synchronized (smsLock) {
|
||||
value = waitingForSms;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public static void setWaitingForSms(boolean value) {
|
||||
synchronized (smsLock) {
|
||||
waitingForSms = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static Integer parseInt(String value) {
|
||||
Integer val = 0;
|
||||
Matcher matcher = pattern.matcher(value);
|
||||
if (matcher.find()) {
|
||||
String num = matcher.group(0);
|
||||
val = Integer.parseInt(num);
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
static {
|
||||
density = ApplicationLoader.applicationContext.getResources().getDisplayMetrics().density;
|
||||
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("primes", Context.MODE_PRIVATE);
|
||||
|
@ -360,6 +397,25 @@ public class Utilities {
|
|||
return null;
|
||||
}
|
||||
|
||||
public static byte[] compress(byte[] data) {
|
||||
if (data == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
byte[] packedData = null;
|
||||
ByteArrayOutputStream bytesStream = new ByteArrayOutputStream();
|
||||
try {
|
||||
GZIPOutputStream zip = new GZIPOutputStream(bytesStream);
|
||||
zip.write(data);
|
||||
zip.close();
|
||||
packedData = bytesStream.toByteArray();
|
||||
} catch (IOException e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
return packedData;
|
||||
}
|
||||
|
||||
|
||||
private static final String TAG = "Typefaces";
|
||||
private static final Hashtable<String, Typeface> cache = new Hashtable<String, Typeface>();
|
||||
|
||||
|
@ -434,15 +490,25 @@ public class Utilities {
|
|||
public static FastDateFormat chatDate;
|
||||
public static FastDateFormat chatFullDate;
|
||||
|
||||
static {
|
||||
public static void recreateFormatters() {
|
||||
Locale locale = Locale.getDefault();
|
||||
String lang = locale.getLanguage();
|
||||
if (lang == null) {
|
||||
lang = "en";
|
||||
}
|
||||
isRTL = lang.toLowerCase().equals("ar");
|
||||
if (lang.equals("en")) {
|
||||
formatterMonth = FastDateFormat.getInstance("MMM dd", locale);
|
||||
formatterYear = FastDateFormat.getInstance("dd.MM.yy", locale);
|
||||
formatterYearMax = FastDateFormat.getInstance("dd.MM.yyyy", locale);
|
||||
chatDate = FastDateFormat.getInstance("MMMM d", locale);
|
||||
chatFullDate = FastDateFormat.getInstance("MMMM d, yyyy", locale);
|
||||
} else if (lang.startsWith("es")) {
|
||||
formatterMonth = FastDateFormat.getInstance("dd 'de' MMM", locale);
|
||||
formatterYear = FastDateFormat.getInstance("dd.MM.yy", locale);
|
||||
formatterYearMax = FastDateFormat.getInstance("dd.MM.yyyy", locale);
|
||||
chatDate = FastDateFormat.getInstance("d 'de' MMMM", locale);
|
||||
chatFullDate = FastDateFormat.getInstance("d 'de' MMMM 'de' yyyy", locale);
|
||||
} else {
|
||||
formatterMonth = FastDateFormat.getInstance("dd MMM", locale);
|
||||
formatterYear = FastDateFormat.getInstance("dd.MM.yy", locale);
|
||||
|
@ -467,6 +533,10 @@ public class Utilities {
|
|||
}
|
||||
}
|
||||
|
||||
static {
|
||||
recreateFormatters();
|
||||
}
|
||||
|
||||
public static String formatDateChat(long date) {
|
||||
Calendar rightNow = Calendar.getInstance();
|
||||
int year = rightNow.get(Calendar.YEAR);
|
||||
|
@ -508,13 +578,13 @@ public class Utilities {
|
|||
int dateYear = rightNow.get(Calendar.YEAR);
|
||||
|
||||
if (dateDay == day && year == dateYear) {
|
||||
return String.format("%s %s", ApplicationLoader.applicationContext.getResources().getString(R.string.TodayAt), formatterDay.format(new Date(date * 1000)));
|
||||
return String.format("%s %s %s", ApplicationLoader.applicationContext.getString(R.string.LastSeen), ApplicationLoader.applicationContext.getString(R.string.TodayAt), formatterDay.format(new Date(date * 1000)));
|
||||
} else if (dateDay + 1 == day && year == dateYear) {
|
||||
return String.format("%s %s", ApplicationLoader.applicationContext.getResources().getString(R.string.YesterdayAt), formatterDay.format(new Date(date * 1000)));
|
||||
return String.format("%s %s %s", ApplicationLoader.applicationContext.getString(R.string.LastSeen), ApplicationLoader.applicationContext.getString(R.string.YesterdayAt), formatterDay.format(new Date(date * 1000)));
|
||||
} else if (year == dateYear) {
|
||||
return String.format("%s %s %s", formatterMonth.format(new Date(date * 1000)), ApplicationLoader.applicationContext.getResources().getString(R.string.OtherAt), formatterDay.format(new Date(date * 1000)));
|
||||
return String.format("%s %s %s %s", ApplicationLoader.applicationContext.getString(R.string.LastSeenDate), formatterMonth.format(new Date(date * 1000)), ApplicationLoader.applicationContext.getString(R.string.OtherAt), formatterDay.format(new Date(date * 1000)));
|
||||
} else {
|
||||
return String.format("%s %s %s", formatterYear.format(new Date(date * 1000)), ApplicationLoader.applicationContext.getResources().getString(R.string.OtherAt), formatterDay.format(new Date(date * 1000)));
|
||||
return String.format("%s %s %s %s", ApplicationLoader.applicationContext.getString(R.string.LastSeenDate), formatterYear.format(new Date(date * 1000)), ApplicationLoader.applicationContext.getString(R.string.OtherAt), formatterDay.format(new Date(date * 1000)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -556,9 +626,6 @@ public class Utilities {
|
|||
|
||||
public static void RunOnUIThread(Runnable runnable) {
|
||||
synchronized (lock) {
|
||||
if (applicationHandler == null) {
|
||||
applicationHandler = new Handler(ApplicationLoader.applicationContext.getMainLooper());
|
||||
}
|
||||
applicationHandler.post(runnable);
|
||||
}
|
||||
}
|
||||
|
@ -682,6 +749,83 @@ public class Utilities {
|
|||
return storageDir;
|
||||
}
|
||||
|
||||
public static String getPath(final Uri uri) {
|
||||
final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
|
||||
if (isKitKat && DocumentsContract.isDocumentUri(ApplicationLoader.applicationContext, uri)) {
|
||||
if (isExternalStorageDocument(uri)) {
|
||||
final String docId = DocumentsContract.getDocumentId(uri);
|
||||
final String[] split = docId.split(":");
|
||||
final String type = split[0];
|
||||
if ("primary".equalsIgnoreCase(type)) {
|
||||
return Environment.getExternalStorageDirectory() + "/" + split[1];
|
||||
}
|
||||
} else if (isDownloadsDocument(uri)) {
|
||||
final String id = DocumentsContract.getDocumentId(uri);
|
||||
final Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
|
||||
return getDataColumn(ApplicationLoader.applicationContext, contentUri, null, null);
|
||||
} else if (isMediaDocument(uri)) {
|
||||
final String docId = DocumentsContract.getDocumentId(uri);
|
||||
final String[] split = docId.split(":");
|
||||
final String type = split[0];
|
||||
|
||||
Uri contentUri = null;
|
||||
if ("image".equals(type)) {
|
||||
contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
|
||||
} else if ("video".equals(type)) {
|
||||
contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
|
||||
} else if ("audio".equals(type)) {
|
||||
contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
|
||||
}
|
||||
|
||||
final String selection = "_id=?";
|
||||
final String[] selectionArgs = new String[] {
|
||||
split[1]
|
||||
};
|
||||
|
||||
return getDataColumn(ApplicationLoader.applicationContext, contentUri, selection, selectionArgs);
|
||||
}
|
||||
} else if ("content".equalsIgnoreCase(uri.getScheme())) {
|
||||
return getDataColumn(ApplicationLoader.applicationContext, uri, null, null);
|
||||
} else if ("file".equalsIgnoreCase(uri.getScheme())) {
|
||||
return uri.getPath();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) {
|
||||
|
||||
Cursor cursor = null;
|
||||
final String column = "_data";
|
||||
final String[] projection = {
|
||||
column
|
||||
};
|
||||
|
||||
try {
|
||||
cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null);
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
final int column_index = cursor.getColumnIndexOrThrow(column);
|
||||
return cursor.getString(column_index);
|
||||
}
|
||||
} finally {
|
||||
if (cursor != null)
|
||||
cursor.close();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean isExternalStorageDocument(Uri uri) {
|
||||
return "com.android.externalstorage.documents".equals(uri.getAuthority());
|
||||
}
|
||||
|
||||
public static boolean isDownloadsDocument(Uri uri) {
|
||||
return "com.android.providers.downloads.documents".equals(uri.getAuthority());
|
||||
}
|
||||
|
||||
public static boolean isMediaDocument(Uri uri) {
|
||||
return "com.android.providers.media.documents".equals(uri.getAuthority());
|
||||
}
|
||||
|
||||
public static File generatePicturePath() {
|
||||
try {
|
||||
File storageDir = getAlbumDir();
|
||||
|
|
|
@ -33,6 +33,7 @@ public class MessageObject {
|
|||
public PhotoObject previewPhoto;
|
||||
public String dateKey;
|
||||
public boolean deleted = false;
|
||||
public Object TAG;
|
||||
|
||||
public MessageObject(TLRPC.Message message, AbstractMap<Integer, TLRPC.User> users) {
|
||||
messageOwner = message;
|
||||
|
@ -45,7 +46,7 @@ public class MessageObject {
|
|||
}
|
||||
if (message.action instanceof TLRPC.TL_messageActionChatCreate) {
|
||||
if (message.from_id == UserConfig.clientUserId) {
|
||||
messageText = ApplicationLoader.applicationContext.getString(R.string.ActionCreateGroup).replace("un1", ApplicationLoader.applicationContext.getString(R.string.FromYou));
|
||||
messageText = ApplicationLoader.applicationContext.getString(R.string.ActionYouCreateGroup);
|
||||
} else {
|
||||
if (fromUser != null) {
|
||||
messageText = ApplicationLoader.applicationContext.getString(R.string.ActionCreateGroup).replace("un1", Utilities.formatName(fromUser.first_name, fromUser.last_name));
|
||||
|
@ -56,7 +57,7 @@ public class MessageObject {
|
|||
} else if (message.action instanceof TLRPC.TL_messageActionChatDeleteUser) {
|
||||
if (message.action.user_id == message.from_id) {
|
||||
if (message.from_id == UserConfig.clientUserId) {
|
||||
messageText = ApplicationLoader.applicationContext.getString(R.string.ActionLeftUser).replace("un1", ApplicationLoader.applicationContext.getString(R.string.FromYou));
|
||||
messageText = ApplicationLoader.applicationContext.getString(R.string.ActionYouLeftUser);
|
||||
} else {
|
||||
if (fromUser != null) {
|
||||
messageText = ApplicationLoader.applicationContext.getString(R.string.ActionLeftUser).replace("un1", Utilities.formatName(fromUser.first_name, fromUser.last_name));
|
||||
|
@ -69,17 +70,16 @@ public class MessageObject {
|
|||
if (who == null) {
|
||||
MessagesController.Instance.users.get(message.action.user_id);
|
||||
}
|
||||
String str = ApplicationLoader.applicationContext.getString(R.string.ActionKickUser);
|
||||
if (who != null && fromUser != null) {
|
||||
if (message.from_id == UserConfig.clientUserId) {
|
||||
messageText = str.replace("un2", Utilities.formatName(who.first_name, who.last_name)).replace("un1", ApplicationLoader.applicationContext.getString(R.string.FromYou));
|
||||
messageText = ApplicationLoader.applicationContext.getString(R.string.ActionYouKickUser).replace("un2", Utilities.formatName(who.first_name, who.last_name));
|
||||
} else if (message.action.user_id == UserConfig.clientUserId) {
|
||||
messageText = str.replace("un2", ApplicationLoader.applicationContext.getString(R.string.FromYou)).replace("un1", Utilities.formatName(fromUser.first_name, fromUser.last_name));
|
||||
messageText = ApplicationLoader.applicationContext.getString(R.string.ActionKickUserYou).replace("un1", Utilities.formatName(fromUser.first_name, fromUser.last_name));
|
||||
} else {
|
||||
messageText = str.replace("un2", Utilities.formatName(who.first_name, who.last_name)).replace("un1", Utilities.formatName(fromUser.first_name, fromUser.last_name));
|
||||
messageText = ApplicationLoader.applicationContext.getString(R.string.ActionKickUser).replace("un2", Utilities.formatName(who.first_name, who.last_name)).replace("un1", Utilities.formatName(fromUser.first_name, fromUser.last_name));
|
||||
}
|
||||
} else {
|
||||
messageText = str.replace("un2", "").replace("un1", "");
|
||||
messageText = ApplicationLoader.applicationContext.getString(R.string.ActionKickUser).replace("un2", "").replace("un1", "");
|
||||
}
|
||||
}
|
||||
} else if (message.action instanceof TLRPC.TL_messageActionChatAddUser) {
|
||||
|
@ -87,17 +87,16 @@ public class MessageObject {
|
|||
if (whoUser == null) {
|
||||
MessagesController.Instance.users.get(message.action.user_id);
|
||||
}
|
||||
String str = ApplicationLoader.applicationContext.getString(R.string.ActionAddUser);
|
||||
if (whoUser != null && fromUser != null) {
|
||||
if (message.from_id == UserConfig.clientUserId) {
|
||||
messageText = str.replace("un2", Utilities.formatName(whoUser.first_name, whoUser.last_name)).replace("un1", ApplicationLoader.applicationContext.getString(R.string.FromYou));
|
||||
messageText = ApplicationLoader.applicationContext.getString(R.string.ActionYouAddUser).replace("un2", Utilities.formatName(whoUser.first_name, whoUser.last_name));
|
||||
} else if (message.action.user_id == UserConfig.clientUserId) {
|
||||
messageText = str.replace("un2", ApplicationLoader.applicationContext.getString(R.string.FromYou)).replace("un1", Utilities.formatName(fromUser.first_name, fromUser.last_name));
|
||||
messageText = ApplicationLoader.applicationContext.getString(R.string.ActionAddUserYou).replace("un1", Utilities.formatName(fromUser.first_name, fromUser.last_name));
|
||||
} else {
|
||||
messageText = str.replace("un2", Utilities.formatName(whoUser.first_name, whoUser.last_name)).replace("un1", Utilities.formatName(fromUser.first_name, fromUser.last_name));
|
||||
messageText = ApplicationLoader.applicationContext.getString(R.string.ActionAddUser).replace("un2", Utilities.formatName(whoUser.first_name, whoUser.last_name)).replace("un1", Utilities.formatName(fromUser.first_name, fromUser.last_name));
|
||||
}
|
||||
} else {
|
||||
messageText = str.replace("un2", "").replace("un1", "");
|
||||
messageText = ApplicationLoader.applicationContext.getString(R.string.ActionAddUser).replace("un2", "").replace("un1", "");
|
||||
}
|
||||
} else if (message.action instanceof TLRPC.TL_messageActionChatEditPhoto) {
|
||||
photoThumbs = new ArrayList<PhotoObject>();
|
||||
|
@ -105,7 +104,7 @@ public class MessageObject {
|
|||
photoThumbs.add(new PhotoObject(size));
|
||||
}
|
||||
if (message.from_id == UserConfig.clientUserId) {
|
||||
messageText = ApplicationLoader.applicationContext.getString(R.string.ActionChangedPhoto).replace("un1", ApplicationLoader.applicationContext.getString(R.string.FromYou));
|
||||
messageText = ApplicationLoader.applicationContext.getString(R.string.ActionYouChangedPhoto);
|
||||
} else {
|
||||
if (fromUser != null) {
|
||||
messageText = ApplicationLoader.applicationContext.getString(R.string.ActionChangedPhoto).replace("un1", Utilities.formatName(fromUser.first_name, fromUser.last_name));
|
||||
|
@ -115,7 +114,7 @@ public class MessageObject {
|
|||
}
|
||||
} else if (message.action instanceof TLRPC.TL_messageActionChatEditTitle) {
|
||||
if (message.from_id == UserConfig.clientUserId) {
|
||||
messageText = ApplicationLoader.applicationContext.getString(R.string.ActionChangedTitle).replace("un1", ApplicationLoader.applicationContext.getString(R.string.FromYou)).replace("un2", message.action.title);
|
||||
messageText = ApplicationLoader.applicationContext.getString(R.string.ActionYouChangedTitle).replace("un2", message.action.title);
|
||||
} else {
|
||||
if (fromUser != null) {
|
||||
messageText = ApplicationLoader.applicationContext.getString(R.string.ActionChangedTitle).replace("un1", Utilities.formatName(fromUser.first_name, fromUser.last_name)).replace("un2", message.action.title);
|
||||
|
@ -125,7 +124,7 @@ public class MessageObject {
|
|||
}
|
||||
} else if (message.action instanceof TLRPC.TL_messageActionChatDeletePhoto) {
|
||||
if (message.from_id == UserConfig.clientUserId) {
|
||||
messageText = ApplicationLoader.applicationContext.getString(R.string.ActionRemovedPhoto).replace("un1", ApplicationLoader.applicationContext.getString(R.string.FromYou));
|
||||
messageText = ApplicationLoader.applicationContext.getString(R.string.ActionYouRemovedPhoto);
|
||||
} else {
|
||||
if (fromUser != null) {
|
||||
messageText = ApplicationLoader.applicationContext.getString(R.string.ActionRemovedPhoto).replace("un1", Utilities.formatName(fromUser.first_name, fromUser.last_name));
|
||||
|
@ -162,7 +161,7 @@ public class MessageObject {
|
|||
}
|
||||
} else {
|
||||
if (message.from_id == UserConfig.clientUserId) {
|
||||
messageText = String.format(ApplicationLoader.applicationContext.getString(R.string.MessageLifetimeRemoved), ApplicationLoader.applicationContext.getString(R.string.FromYou));
|
||||
messageText = String.format(ApplicationLoader.applicationContext.getString(R.string.MessageLifetimeYouRemoved));
|
||||
} else {
|
||||
if (fromUser != null) {
|
||||
messageText = String.format(ApplicationLoader.applicationContext.getString(R.string.MessageLifetimeRemoved), fromUser.first_name);
|
||||
|
@ -172,7 +171,8 @@ public class MessageObject {
|
|||
}
|
||||
}
|
||||
} else if (message.action instanceof TLRPC.TL_messageActionLoginUnknownLocation) {
|
||||
messageText = ApplicationLoader.applicationContext.getString(R.string.NotificationUnrecognizedDevice, message.action.title, message.action.address);
|
||||
String date = String.format("%s %s %s", Utilities.formatterYear.format(((long)message.date) * 1000), ApplicationLoader.applicationContext.getString(R.string.OtherAt), Utilities.formatterDay.format(((long)message.date) * 1000));
|
||||
messageText = ApplicationLoader.applicationContext.getString(R.string.NotificationUnrecognizedDevice, UserConfig.currentUser.first_name, date, message.action.title, message.action.address);
|
||||
} else if (message.action instanceof TLRPC.TL_messageActionUserJoined) {
|
||||
if (fromUser != null) {
|
||||
messageText = ApplicationLoader.applicationContext.getString(R.string.NotificationContactJoined, Utilities.formatName(fromUser.first_name, fromUser.last_name));
|
||||
|
@ -266,9 +266,17 @@ public class MessageObject {
|
|||
} else {
|
||||
type = 17;
|
||||
}
|
||||
} else if (message.media != null && message.media instanceof TLRPC.TL_messageMediaAudio) {
|
||||
if (message.from_id == UserConfig.clientUserId) {
|
||||
type = 0;
|
||||
} else {
|
||||
type = 1;
|
||||
}
|
||||
}
|
||||
} else if (message instanceof TLRPC.TL_messageService) {
|
||||
if (message.action instanceof TLRPC.TL_messageActionChatEditPhoto || message.action instanceof TLRPC.TL_messageActionUserUpdatedPhoto) {
|
||||
if (message.action instanceof TLRPC.TL_messageActionLoginUnknownLocation) {
|
||||
type = 1;
|
||||
} else if (message.action instanceof TLRPC.TL_messageActionChatEditPhoto || message.action instanceof TLRPC.TL_messageActionUserUpdatedPhoto) {
|
||||
type = 11;
|
||||
} else {
|
||||
type = 10;
|
||||
|
@ -294,6 +302,8 @@ public class MessageObject {
|
|||
return getAttachFileName(messageOwner.media.video);
|
||||
} else if (messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
|
||||
return getAttachFileName(messageOwner.media.document);
|
||||
} else if (messageOwner.media instanceof TLRPC.TL_messageMediaAudio) {
|
||||
return getAttachFileName(messageOwner.media.audio);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
@ -319,6 +329,9 @@ public class MessageObject {
|
|||
} else if (attach instanceof TLRPC.PhotoSize) {
|
||||
TLRPC.PhotoSize photo = (TLRPC.PhotoSize)attach;
|
||||
return photo.location.volume_id + "_" + photo.location.local_id + ".jpg";
|
||||
} else if (attach instanceof TLRPC.Audio) {
|
||||
TLRPC.Audio audio = (TLRPC.Audio)attach;
|
||||
return audio.dc_id + "_" + audio.id + ".m4a";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ public class PhotoObject {
|
|||
opts.outWidth = photo.w;
|
||||
opts.outHeight = photo.h;
|
||||
image = BitmapFactory.decodeByteArray(photoOwner.bytes, 0, photoOwner.bytes.length, opts);
|
||||
if (FileLoader.Instance.runtimeHack != null) {
|
||||
if (image != null && FileLoader.Instance.runtimeHack != null) {
|
||||
FileLoader.Instance.runtimeHack.trackFree(image.getRowBytes() * image.getHeight());
|
||||
}
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ public class PhotoObject {
|
|||
}
|
||||
int diffW = Math.abs(obj.photoOwner.w - width);
|
||||
int diffH = Math.abs(obj.photoOwner.h - height);
|
||||
if (closestObject == null || closestWidth > diffW && closestHeight > diffH || closestObject.photoOwner instanceof TLRPC.TL_photoCachedSize) {
|
||||
if (closestObject == null || closestWidth > diffW || closestHeight > diffH || closestObject.photoOwner instanceof TLRPC.TL_photoCachedSize) {
|
||||
closestObject = obj;
|
||||
closestWidth = diffW;
|
||||
closestHeight = diffH;
|
||||
|
|
|
@ -25,6 +25,7 @@ import android.view.View;
|
|||
import android.view.ViewGroup;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.telegram.messenger.ConnectionsManager;
|
||||
|
@ -196,7 +197,7 @@ public class ApplicationActivity extends ActionBarActivity implements Notificati
|
|||
method.invoke(field.get(getSupportActionBar()), false);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -333,6 +334,10 @@ public class ApplicationActivity extends ActionBarActivity implements Notificati
|
|||
if (notificationView != null) {
|
||||
notificationView.hide(false);
|
||||
}
|
||||
View focusView = getCurrentFocus();
|
||||
if (focusView instanceof EditText) {
|
||||
focusView.clearFocus();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -581,13 +586,13 @@ public class ApplicationActivity extends ActionBarActivity implements Notificati
|
|||
try {
|
||||
if (statusView.getLayoutParams() instanceof android.support.v7.app.ActionBar.LayoutParams) {
|
||||
android.support.v7.app.ActionBar.LayoutParams statusParams = (android.support.v7.app.ActionBar.LayoutParams)statusView.getLayoutParams();
|
||||
statusText.measure(View.MeasureSpec.makeMeasureSpec(800, View.MeasureSpec.AT_MOST), 100);
|
||||
statusParams.width = (int)(statusText.getMeasuredWidth() + Utilities.dp(54));
|
||||
statusText.measure(View.MeasureSpec.makeMeasureSpec(800, View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(100, View.MeasureSpec.AT_MOST));
|
||||
statusParams.width = (statusText.getMeasuredWidth() + Utilities.dp(54));
|
||||
statusView.setLayoutParams(statusParams);
|
||||
} else if (statusView.getLayoutParams() instanceof android.app.ActionBar.LayoutParams) {
|
||||
android.app.ActionBar.LayoutParams statusParams = (android.app.ActionBar.LayoutParams)statusView.getLayoutParams();
|
||||
statusText.measure(View.MeasureSpec.makeMeasureSpec(800, View.MeasureSpec.AT_MOST), 100);
|
||||
statusParams.width = (int)(statusText.getMeasuredWidth() + Utilities.dp(54));
|
||||
statusText.measure(View.MeasureSpec.makeMeasureSpec(800, View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(100, View.MeasureSpec.AT_MOST));
|
||||
statusParams.width = (statusText.getMeasuredWidth() + Utilities.dp(54));
|
||||
statusView.setLayoutParams(statusParams);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
@ -621,7 +626,7 @@ public class ApplicationActivity extends ActionBarActivity implements Notificati
|
|||
ApplicationLoader.fragmentsStack.remove(ApplicationLoader.fragmentsStack.size() - 1);
|
||||
current.onFragmentDestroy();
|
||||
}
|
||||
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
|
||||
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
||||
boolean animations = preferences.getBoolean("view_animations", true);
|
||||
if (animations) {
|
||||
if (bySwipe) {
|
||||
|
@ -660,7 +665,7 @@ public class ApplicationActivity extends ActionBarActivity implements Notificati
|
|||
BaseFragment prev = ApplicationLoader.fragmentsStack.get(ApplicationLoader.fragmentsStack.size() - 2);
|
||||
FragmentManager fm = getSupportFragmentManager();
|
||||
FragmentTransaction fTrans = fm.beginTransaction();
|
||||
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
|
||||
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
||||
boolean animations = preferences.getBoolean("view_animations", true);
|
||||
if (animations) {
|
||||
if (bySwipe) {
|
||||
|
|
|
@ -8,13 +8,17 @@
|
|||
|
||||
package org.telegram.ui;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Handler;
|
||||
import android.view.ViewConfiguration;
|
||||
|
||||
import com.google.android.gms.common.ConnectionResult;
|
||||
|
@ -22,7 +26,7 @@ import com.google.android.gms.common.GooglePlayServicesUtil;
|
|||
import com.google.android.gms.gcm.GoogleCloudMessaging;
|
||||
|
||||
import org.telegram.PhoneFormat.PhoneFormat;
|
||||
import org.telegram.TL.TLRPC;
|
||||
import org.telegram.messenger.BackgroundService;
|
||||
import org.telegram.messenger.ConnectionsManager;
|
||||
import org.telegram.messenger.FileLog;
|
||||
import org.telegram.messenger.MessagesController;
|
||||
|
@ -34,6 +38,7 @@ import org.telegram.ui.Views.BaseFragment;
|
|||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class ApplicationLoader extends Application {
|
||||
|
@ -48,6 +53,7 @@ public class ApplicationLoader extends Application {
|
|||
public static long lastPauseTime;
|
||||
public static Bitmap cachedWallpaper = null;
|
||||
public static Context applicationContext;
|
||||
private Locale currentLocale;
|
||||
|
||||
public static ApplicationLoader Instance = null;
|
||||
|
||||
|
@ -56,42 +62,48 @@ public class ApplicationLoader extends Application {
|
|||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
|
||||
currentLocale = Locale.getDefault();
|
||||
Instance = this;
|
||||
|
||||
java.lang.System.setProperty("java.net.preferIPv4Stack", "true");
|
||||
java.lang.System.setProperty("java.net.preferIPv6Addresses", "false");
|
||||
|
||||
applicationContext = getApplicationContext();
|
||||
Utilities.getTypeface("fonts/rmedium.ttf");
|
||||
UserConfig.loadConfig();
|
||||
SharedPreferences preferences = getSharedPreferences("Notifications", MODE_PRIVATE);
|
||||
if (UserConfig.currentUser != null) {
|
||||
int value = preferences.getInt("version", 0);
|
||||
if (value != 15) {
|
||||
UserConfig.contactsHash = "";
|
||||
MessagesStorage.lastDateValue = 0;
|
||||
MessagesStorage.lastPtsValue = 0;
|
||||
MessagesStorage.lastSeqValue = 0;
|
||||
MessagesStorage.lastQtsValue = 0;
|
||||
UserConfig.saveConfig(false);
|
||||
MessagesStorage.Instance.cleanUp();
|
||||
ArrayList<TLRPC.User> users = new ArrayList<TLRPC.User>();
|
||||
users.add(UserConfig.currentUser);
|
||||
MessagesStorage.Instance.putUsersAndChats(users, null, true, true);
|
||||
Utilities.applicationHandler = new Handler(applicationContext.getMainLooper());
|
||||
|
||||
SharedPreferences.Editor editor = preferences.edit();
|
||||
editor.putInt("version", 15);
|
||||
UserConfig.loadConfig();
|
||||
if (UserConfig.currentUser != null) {
|
||||
boolean changed = false;
|
||||
SharedPreferences preferences = getSharedPreferences("Notifications", MODE_PRIVATE);
|
||||
int v = preferences.getInt("v", 0);
|
||||
if (v != 1) {
|
||||
SharedPreferences preferences2 = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = preferences2.edit();
|
||||
if (preferences.contains("view_animations")) {
|
||||
editor.putBoolean("view_animations", preferences.getBoolean("view_animations", false));
|
||||
}
|
||||
if (preferences.contains("selectedBackground")) {
|
||||
editor.putInt("selectedBackground", preferences.getInt("selectedBackground", 1000001));
|
||||
}
|
||||
if (preferences.contains("selectedColor")) {
|
||||
editor.putInt("selectedColor", preferences.getInt("selectedColor", 0));
|
||||
}
|
||||
if (preferences.contains("fons_size")) {
|
||||
editor.putInt("fons_size", preferences.getInt("fons_size", 16));
|
||||
}
|
||||
editor.commit();
|
||||
editor = preferences.edit();
|
||||
editor.putInt("v", 1);
|
||||
editor.remove("view_animations");
|
||||
editor.remove("selectedBackground");
|
||||
editor.remove("selectedColor");
|
||||
editor.remove("fons_size");
|
||||
editor.commit();
|
||||
} else {
|
||||
MessagesStorage init = MessagesStorage.Instance;
|
||||
}
|
||||
MessagesStorage init = MessagesStorage.Instance;
|
||||
MessagesController.Instance.users.put(UserConfig.clientUserId, UserConfig.currentUser);
|
||||
} else {
|
||||
SharedPreferences.Editor editor = preferences.edit();
|
||||
editor.putInt("version", 15);
|
||||
editor.commit();
|
||||
}
|
||||
MessagesController.Instance.checkAppAccount();
|
||||
|
||||
try {
|
||||
ViewConfiguration config = ViewConfiguration.get(this);
|
||||
|
@ -101,7 +113,7 @@ public class ApplicationLoader extends Application {
|
|||
menuKeyField.setBoolean(config, false);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (checkPlayServices()) {
|
||||
|
@ -121,6 +133,22 @@ public class ApplicationLoader extends Application {
|
|||
|
||||
lastPauseTime = System.currentTimeMillis();
|
||||
FileLog.e("tmessages", "start application with time " + lastPauseTime);
|
||||
|
||||
startService(new Intent(this, BackgroundService.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged(Configuration newConfig) {
|
||||
super.onConfigurationChanged(newConfig);
|
||||
Locale newLocale = newConfig.locale;
|
||||
if (newLocale != null) {
|
||||
String d1 = newLocale.getDisplayName();
|
||||
String d2 = currentLocale.getDisplayName();
|
||||
if (d1 != null && d2 != null && !d1.equals(d2)) {
|
||||
Utilities.recreateFormatters();
|
||||
}
|
||||
currentLocale = newLocale;
|
||||
}
|
||||
}
|
||||
|
||||
public static void resetLastPauseTime() {
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* This is the source code of Telegram for Android v. 1.3.x.
|
||||
* It is licensed under GNU GPL v. 2 or later.
|
||||
* You should have received a copy of the license in this archive (see LICENSE).
|
||||
*
|
||||
* Copyright Nikolai Kudashov, 2013.
|
||||
*/
|
||||
|
||||
package org.telegram.ui.Cells;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
|
||||
public class BaseCell extends View {
|
||||
public BaseCell(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public BaseCell(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public BaseCell(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
protected void setDrawableBounds(Drawable drawable, int x, int y) {
|
||||
setDrawableBounds(drawable, x, y, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
|
||||
}
|
||||
|
||||
protected void setDrawableBounds(Drawable drawable, int x, int y, int w, int h) {
|
||||
drawable.setBounds(x, y, x + w, y + h);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* This is the source code of Telegram for Android v. 1.3.x.
|
||||
* It is licensed under GNU GPL v. 2 or later.
|
||||
* You should have received a copy of the license in this archive (see LICENSE).
|
||||
*
|
||||
* Copyright Nikolai Kudashov, 2013.
|
||||
*/
|
||||
|
||||
package org.telegram.ui.Cells;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
public class ChatMessageCell extends BaseCell {
|
||||
public ChatMessageCell(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public ChatMessageCell(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public ChatMessageCell(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,464 @@
|
|||
/*
|
||||
* This is the source code of Telegram for Android v. 1.3.x.
|
||||
* It is licensed under GNU GPL v. 2 or later.
|
||||
* You should have received a copy of the license in this archive (see LICENSE).
|
||||
*
|
||||
* Copyright Nikolai Kudashov, 2013.
|
||||
*/
|
||||
|
||||
package org.telegram.ui.Cells;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.text.Html;
|
||||
import android.text.Layout;
|
||||
import android.text.StaticLayout;
|
||||
import android.text.TextPaint;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
|
||||
import org.telegram.PhoneFormat.PhoneFormat;
|
||||
import org.telegram.TL.TLRPC;
|
||||
import org.telegram.messenger.ConnectionsManager;
|
||||
import org.telegram.messenger.ContactsController;
|
||||
import org.telegram.messenger.MessagesController;
|
||||
import org.telegram.messenger.R;
|
||||
import org.telegram.messenger.UserConfig;
|
||||
import org.telegram.messenger.Utilities;
|
||||
import org.telegram.ui.ApplicationLoader;
|
||||
import org.telegram.ui.Views.ImageReceiver;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
public class ChatOrUserCell extends BaseCell {
|
||||
private static TextPaint namePaint;
|
||||
private static TextPaint nameEncryptedPaint;
|
||||
private static TextPaint onlinePaint;
|
||||
private static TextPaint offlinePaint;
|
||||
|
||||
private static Drawable lockDrawable;
|
||||
private static Paint linePaint;
|
||||
|
||||
private CharSequence currentName;
|
||||
private ImageReceiver avatarImage;
|
||||
private String subLabel;
|
||||
|
||||
private ChatOrUserCellLayout cellLayout;
|
||||
private TLRPC.User user = null;
|
||||
private TLRPC.Chat chat = null;
|
||||
private TLRPC.EncryptedChat encryptedChat = null;
|
||||
|
||||
private String lastName = null;
|
||||
private int lastStatus = 0;
|
||||
private TLRPC.FileLocation lastAvatar = null;
|
||||
|
||||
public boolean usePadding = true;
|
||||
public boolean useBoldFont = false;
|
||||
public boolean useSeparator = false;
|
||||
public float drawAlpha = 1;
|
||||
|
||||
public ChatOrUserCell(Context context) {
|
||||
super(context);
|
||||
init();
|
||||
}
|
||||
|
||||
public ChatOrUserCell(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init();
|
||||
}
|
||||
|
||||
public ChatOrUserCell(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
if (namePaint == null) {
|
||||
namePaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
|
||||
namePaint.setTextSize(Utilities.dp(18));
|
||||
namePaint.setColor(0xff222222);
|
||||
}
|
||||
|
||||
if (nameEncryptedPaint == null) {
|
||||
nameEncryptedPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
|
||||
nameEncryptedPaint.setTextSize(Utilities.dp(18));
|
||||
nameEncryptedPaint.setColor(0xff00a60e);
|
||||
}
|
||||
|
||||
if (onlinePaint == null) {
|
||||
onlinePaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
|
||||
onlinePaint.setTextSize(Utilities.dp(15));
|
||||
onlinePaint.setColor(0xff316f9f);
|
||||
}
|
||||
|
||||
if (offlinePaint == null) {
|
||||
offlinePaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
|
||||
offlinePaint.setTextSize(Utilities.dp(15));
|
||||
offlinePaint.setColor(0xff999999);
|
||||
}
|
||||
|
||||
if (lockDrawable == null) {
|
||||
lockDrawable = getResources().getDrawable(R.drawable.ic_lock_green);
|
||||
}
|
||||
|
||||
if (linePaint == null) {
|
||||
linePaint = new Paint();
|
||||
linePaint.setColor(0xffdcdcdc);
|
||||
}
|
||||
|
||||
if (avatarImage == null) {
|
||||
avatarImage = new ImageReceiver();
|
||||
avatarImage.parentView = new WeakReference<View>(this);
|
||||
}
|
||||
|
||||
if (cellLayout == null) {
|
||||
cellLayout = new ChatOrUserCellLayout();
|
||||
}
|
||||
}
|
||||
|
||||
public void setData(TLRPC.User u, TLRPC.Chat c, TLRPC.EncryptedChat ec, CharSequence n, String s) {
|
||||
currentName = n;
|
||||
user = u;
|
||||
chat = c;
|
||||
encryptedChat = ec;
|
||||
subLabel = s;
|
||||
update(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), Utilities.dp(64));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
||||
if (user == null && chat == null && encryptedChat == null) {
|
||||
super.onLayout(changed, left, top, right, bottom);
|
||||
return;
|
||||
}
|
||||
if (changed) {
|
||||
buildLayout();
|
||||
}
|
||||
}
|
||||
|
||||
public void buildLayout() {
|
||||
cellLayout.build(getMeasuredWidth(), getMeasuredHeight());
|
||||
}
|
||||
|
||||
public void update(int mask) {
|
||||
int placeHolderId = 0;
|
||||
TLRPC.FileLocation photo = null;
|
||||
if (user != null) {
|
||||
if (user.photo != null) {
|
||||
photo = user.photo.photo_small;
|
||||
}
|
||||
placeHolderId = Utilities.getUserAvatarForId(user.id);
|
||||
} else if (chat != null) {
|
||||
if (chat.photo != null) {
|
||||
photo = chat.photo.photo_small;
|
||||
}
|
||||
placeHolderId = Utilities.getGroupAvatarForId(chat.id);
|
||||
}
|
||||
|
||||
if (mask != 0) {
|
||||
boolean continueUpdate = false;
|
||||
if ((mask & MessagesController.UPDATE_MASK_AVATAR) != 0 && user != null || (mask & MessagesController.UPDATE_MASK_CHAT_AVATAR) != 0 && chat != null) {
|
||||
if (lastAvatar != null && photo == null || lastAvatar == null && photo != null && lastAvatar != null && photo != null && (lastAvatar.volume_id != photo.volume_id || lastAvatar.local_id != photo.local_id)) {
|
||||
continueUpdate = true;
|
||||
}
|
||||
}
|
||||
if (!continueUpdate && (mask & MessagesController.UPDATE_MASK_STATUS) != 0 && user != null) {
|
||||
int newStatus = 0;
|
||||
if (user.status != null) {
|
||||
newStatus = user.status.expires;
|
||||
if (lastStatus == 0) {
|
||||
lastStatus = user.status.was_online;
|
||||
}
|
||||
}
|
||||
if (newStatus != lastStatus) {
|
||||
continueUpdate = true;
|
||||
}
|
||||
}
|
||||
if (!continueUpdate && ((mask & MessagesController.UPDATE_MASK_NAME) != 0 && user != null) || (mask & MessagesController.UPDATE_MASK_CHAT_NAME) != 0 && chat != null) {
|
||||
String newName;
|
||||
if (user != null) {
|
||||
newName = user.first_name + user.last_name;
|
||||
} else {
|
||||
newName = chat.title;
|
||||
}
|
||||
if (!newName.equals(lastName)) {
|
||||
continueUpdate = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!continueUpdate) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (user != null) {
|
||||
if (user.status != null) {
|
||||
lastStatus = user.status.expires;
|
||||
if (lastStatus == 0) {
|
||||
lastStatus = user.status.was_online;
|
||||
}
|
||||
} else {
|
||||
lastStatus = 0;
|
||||
}
|
||||
lastName = user.first_name + user.last_name;
|
||||
} else if (chat != null) {
|
||||
lastName = chat.title;
|
||||
}
|
||||
|
||||
|
||||
lastAvatar = photo;
|
||||
avatarImage.setImage(photo, "50_50", placeHolderId == 0 ? null : getResources().getDrawable(placeHolderId));
|
||||
|
||||
if (getMeasuredWidth() != 0 || getMeasuredHeight() != 0) {
|
||||
buildLayout();
|
||||
} else {
|
||||
requestLayout();
|
||||
}
|
||||
postInvalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
if (user == null && chat == null && encryptedChat == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (cellLayout == null) {
|
||||
requestLayout();
|
||||
return;
|
||||
}
|
||||
|
||||
if (drawAlpha != 1) {
|
||||
canvas.saveLayerAlpha(0, 0, canvas.getWidth(), canvas.getHeight(), (int)(255 * drawAlpha), Canvas.HAS_ALPHA_LAYER_SAVE_FLAG);
|
||||
}
|
||||
|
||||
if (cellLayout.drawNameLock) {
|
||||
setDrawableBounds(lockDrawable, cellLayout.nameLockLeft, cellLayout.nameLockTop);
|
||||
lockDrawable.draw(canvas);
|
||||
}
|
||||
|
||||
canvas.save();
|
||||
canvas.translate(cellLayout.nameLeft, cellLayout.nameTop);
|
||||
cellLayout.nameLayout.draw(canvas);
|
||||
canvas.restore();
|
||||
|
||||
if (cellLayout.onlineLayout != null) {
|
||||
canvas.save();
|
||||
canvas.translate(cellLayout.onlineLeft, cellLayout.onlineTop);
|
||||
cellLayout.onlineLayout.draw(canvas);
|
||||
canvas.restore();
|
||||
}
|
||||
|
||||
avatarImage.draw(canvas, cellLayout.avatarLeft, cellLayout.avatarTop, Utilities.dp(50), Utilities.dp(50));
|
||||
|
||||
if (useSeparator) {
|
||||
int h = getMeasuredHeight();
|
||||
if (!usePadding) {
|
||||
canvas.drawLine(0, h - 1, getMeasuredWidth(), h, linePaint);
|
||||
} else {
|
||||
canvas.drawLine(Utilities.dp(11), h - 1, getMeasuredWidth() - Utilities.dp(11), h, linePaint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class ChatOrUserCellLayout {
|
||||
private int nameLeft;
|
||||
private int nameTop;
|
||||
private int nameWidth;
|
||||
private StaticLayout nameLayout;
|
||||
private boolean drawNameLock;
|
||||
private int nameLockLeft;
|
||||
private int nameLockTop = Utilities.dp(15);
|
||||
|
||||
private int onlineLeft;
|
||||
private int onlineTop = Utilities.dp(36);
|
||||
private int onlineWidth;
|
||||
private StaticLayout onlineLayout;
|
||||
|
||||
private int avatarTop = Utilities.dp(7);
|
||||
private int avatarLeft;
|
||||
|
||||
public void build(int width, int height) {
|
||||
CharSequence nameString = "";
|
||||
TextPaint currentNamePaint;
|
||||
|
||||
if (encryptedChat != null) {
|
||||
drawNameLock = true;
|
||||
if (!Utilities.isRTL) {
|
||||
nameLockLeft = Utilities.dp(61 + (usePadding ? 11 : 0));
|
||||
nameLeft = Utilities.dp(65 + (usePadding ? 11 : 0)) + lockDrawable.getIntrinsicWidth();
|
||||
} else {
|
||||
nameLockLeft = width - Utilities.dp(63 + (usePadding ? 11 : 0)) - lockDrawable.getIntrinsicWidth();
|
||||
nameLeft = usePadding ? Utilities.dp(11) : 0;
|
||||
}
|
||||
} else {
|
||||
drawNameLock = false;
|
||||
if (!Utilities.isRTL) {
|
||||
nameLeft = Utilities.dp(61 + (usePadding ? 11 : 0));
|
||||
} else {
|
||||
nameLeft = usePadding ? Utilities.dp(11) : 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (currentName != null) {
|
||||
nameString = currentName;
|
||||
} else {
|
||||
if (useBoldFont) {
|
||||
if (user != null) {
|
||||
if (user.first_name.length() != 0 && user.last_name.length() != 0) {
|
||||
nameString = Html.fromHtml(user.first_name + " <b>" + user.last_name + "</b>");
|
||||
} else if (user.first_name.length() != 0) {
|
||||
nameString = Html.fromHtml("<b>" + user.first_name + "</b>");
|
||||
} else {
|
||||
nameString = Html.fromHtml("<b>" + user.last_name + "</b>");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
String nameString2 = "";
|
||||
if (chat != null) {
|
||||
nameString2 = chat.title;
|
||||
} else if (user != null) {
|
||||
if (user.id != 333000 && ContactsController.Instance.contactsDict.get(user.id) == null) {
|
||||
if (ContactsController.Instance.contactsDict.size() == 0 && ContactsController.Instance.loadingContacts) {
|
||||
nameString2 = Utilities.formatName(user.first_name, user.last_name);
|
||||
} else {
|
||||
if (user.phone != null && user.phone.length() != 0) {
|
||||
nameString2 = PhoneFormat.Instance.format("+" + user.phone);
|
||||
} else {
|
||||
nameString2 = Utilities.formatName(user.first_name, user.last_name);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
nameString2 = Utilities.formatName(user.first_name, user.last_name);
|
||||
}
|
||||
}
|
||||
nameString = nameString2.replace("\n", " ");
|
||||
}
|
||||
}
|
||||
if (nameString.length() == 0) {
|
||||
nameString = ApplicationLoader.applicationContext.getString(R.string.HiddenName);
|
||||
}
|
||||
if (encryptedChat != null) {
|
||||
currentNamePaint = nameEncryptedPaint;
|
||||
} else {
|
||||
currentNamePaint = namePaint;
|
||||
}
|
||||
|
||||
if (!Utilities.isRTL) {
|
||||
onlineWidth = nameWidth = width - nameLeft - Utilities.dp(3 + (usePadding ? 11 : 0));
|
||||
} else {
|
||||
onlineWidth = nameWidth = width - nameLeft - Utilities.dp(61 + (usePadding ? 11 : 0));
|
||||
}
|
||||
if (drawNameLock) {
|
||||
nameWidth -= Utilities.dp(6) + lockDrawable.getIntrinsicWidth();
|
||||
}
|
||||
|
||||
CharSequence nameStringFinal = TextUtils.ellipsize(nameString, currentNamePaint, nameWidth - Utilities.dp(12), TextUtils.TruncateAt.END);
|
||||
nameLayout = new StaticLayout(nameStringFinal, currentNamePaint, nameWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
|
||||
|
||||
if (chat == null) {
|
||||
if (!Utilities.isRTL) {
|
||||
onlineLeft = Utilities.dp(61 + (usePadding ? 11 : 0));
|
||||
} else {
|
||||
onlineLeft = usePadding ? Utilities.dp(11) : 0;
|
||||
}
|
||||
|
||||
String onlineString = "";
|
||||
TextPaint currentOnlinePaint = offlinePaint;
|
||||
|
||||
if (subLabel != null) {
|
||||
onlineString = subLabel;
|
||||
} else {
|
||||
if (user != null) {
|
||||
if (user.status == null) {
|
||||
onlineString = getResources().getString(R.string.Offline);
|
||||
} else {
|
||||
int currentTime = ConnectionsManager.Instance.getCurrentTime();
|
||||
if (user.id == UserConfig.clientUserId || user.status.expires > currentTime || user.status.was_online > currentTime) {
|
||||
currentOnlinePaint = onlinePaint;
|
||||
onlineString = getResources().getString(R.string.Online);
|
||||
} else {
|
||||
if (user.status.was_online <= 10000 && user.status.expires <= 10000) {
|
||||
onlineString = getResources().getString(R.string.Invisible);
|
||||
} else {
|
||||
int value = user.status.was_online;
|
||||
if (value == 0) {
|
||||
value = user.status.expires;
|
||||
}
|
||||
onlineString = Utilities.formatDateOnline(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CharSequence onlineStringFinal = TextUtils.ellipsize(onlineString, currentOnlinePaint, nameWidth - Utilities.dp(12), TextUtils.TruncateAt.END);
|
||||
onlineLayout = new StaticLayout(onlineStringFinal, currentOnlinePaint, nameWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
|
||||
nameTop = Utilities.dp(12);
|
||||
} else {
|
||||
onlineLayout = null;
|
||||
nameTop = Utilities.dp(22);
|
||||
}
|
||||
|
||||
if (!Utilities.isRTL) {
|
||||
avatarLeft = usePadding ? Utilities.dp(11) : 0;
|
||||
} else {
|
||||
avatarLeft = width - Utilities.dp(50 + (usePadding ? 11 : 0));
|
||||
}
|
||||
avatarImage.imageX = avatarLeft;
|
||||
avatarImage.imageY = avatarTop;
|
||||
avatarImage.imageW = Utilities.dp(50);
|
||||
avatarImage.imageH = Utilities.dp(50);
|
||||
|
||||
double widthpx = 0;
|
||||
float left = 0;
|
||||
if (Utilities.isRTL) {
|
||||
if (nameLayout.getLineCount() > 0) {
|
||||
left = nameLayout.getLineLeft(0);
|
||||
if (left == 0) {
|
||||
widthpx = Math.ceil(nameLayout.getLineWidth(0));
|
||||
if (widthpx < nameWidth) {
|
||||
nameLeft += (nameWidth - widthpx);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (onlineLayout != null && onlineLayout.getLineCount() > 0) {
|
||||
left = onlineLayout.getLineLeft(0);
|
||||
if (left == 0) {
|
||||
widthpx = Math.ceil(onlineLayout.getLineWidth(0));
|
||||
if (widthpx < onlineWidth) {
|
||||
onlineLeft += (onlineWidth - widthpx);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (nameLayout.getLineCount() > 0) {
|
||||
left = nameLayout.getLineRight(0);
|
||||
if (left == nameWidth) {
|
||||
widthpx = Math.ceil(nameLayout.getLineWidth(0));
|
||||
if (widthpx < nameWidth) {
|
||||
nameLeft -= (nameWidth - widthpx);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (onlineLayout != null && onlineLayout.getLineCount() > 0) {
|
||||
left = onlineLayout.getLineRight(0);
|
||||
if (left == onlineWidth) {
|
||||
widthpx = Math.ceil(onlineLayout.getLineWidth(0));
|
||||
if (widthpx < onlineWidth) {
|
||||
onlineLeft -= (onlineWidth - widthpx);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,688 @@
|
|||
/*
|
||||
* This is the source code of Telegram for Android v. 1.3.x.
|
||||
* It is licensed under GNU GPL v. 2 or later.
|
||||
* You should have received a copy of the license in this archive (see LICENSE).
|
||||
*
|
||||
* Copyright Nikolai Kudashov, 2013.
|
||||
*/
|
||||
|
||||
package org.telegram.ui.Cells;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.text.Html;
|
||||
import android.text.Layout;
|
||||
import android.text.StaticLayout;
|
||||
import android.text.TextPaint;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
|
||||
import org.telegram.PhoneFormat.PhoneFormat;
|
||||
import org.telegram.TL.TLRPC;
|
||||
import org.telegram.messenger.ContactsController;
|
||||
import org.telegram.messenger.Emoji;
|
||||
import org.telegram.messenger.MessagesController;
|
||||
import org.telegram.messenger.R;
|
||||
import org.telegram.messenger.UserConfig;
|
||||
import org.telegram.messenger.Utilities;
|
||||
import org.telegram.objects.MessageObject;
|
||||
import org.telegram.ui.ApplicationLoader;
|
||||
import org.telegram.ui.Views.ImageReceiver;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
public class DialogCell extends BaseCell {
|
||||
private static TextPaint namePaint;
|
||||
private static TextPaint nameEncryptedPaint;
|
||||
private static TextPaint nameUnknownPaint;
|
||||
private static TextPaint messagePaint;
|
||||
private static TextPaint messagePrintingPaint;
|
||||
private static TextPaint timePaint;
|
||||
private static TextPaint countPaint;
|
||||
|
||||
private static Drawable checkDrawable;
|
||||
private static Drawable halfCheckDrawable;
|
||||
private static Drawable clockDrawable;
|
||||
private static Drawable errorDrawable;
|
||||
private static Drawable lockDrawable;
|
||||
private static Drawable countDrawable;
|
||||
|
||||
private TLRPC.TL_dialog currentDialog;
|
||||
private ImageReceiver avatarImage;
|
||||
|
||||
private DialogCellLayout cellLayout;
|
||||
private TLRPC.User user = null;
|
||||
private TLRPC.Chat chat = null;
|
||||
private TLRPC.EncryptedChat encryptedChat = null;
|
||||
private CharSequence lastPrintString = null;
|
||||
|
||||
private void init() {
|
||||
if (namePaint == null) {
|
||||
namePaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
|
||||
namePaint.setTextSize(Utilities.dp(19));
|
||||
namePaint.setColor(0xff222222);
|
||||
namePaint.setTypeface(Utilities.getTypeface("fonts/rmedium.ttf"));
|
||||
}
|
||||
|
||||
if (nameEncryptedPaint == null) {
|
||||
nameEncryptedPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
|
||||
nameEncryptedPaint.setTextSize(Utilities.dp(19));
|
||||
nameEncryptedPaint.setColor(0xff00a60e);
|
||||
nameEncryptedPaint.setTypeface(Utilities.getTypeface("fonts/rmedium.ttf"));
|
||||
}
|
||||
|
||||
if (nameUnknownPaint == null) {
|
||||
nameUnknownPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
|
||||
nameUnknownPaint.setTextSize(Utilities.dp(19));
|
||||
nameUnknownPaint.setColor(0xff316f9f);
|
||||
nameUnknownPaint.setTypeface(Utilities.getTypeface("fonts/rmedium.ttf"));
|
||||
}
|
||||
|
||||
if (messagePaint == null) {
|
||||
messagePaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
|
||||
messagePaint.setTextSize(Utilities.dp(16));
|
||||
messagePaint.setColor(0xff808080);
|
||||
}
|
||||
|
||||
if (messagePrintingPaint == null) {
|
||||
messagePrintingPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
|
||||
messagePrintingPaint.setTextSize(Utilities.dp(16));
|
||||
messagePrintingPaint.setColor(0xff316f9f);
|
||||
}
|
||||
|
||||
if (timePaint == null) {
|
||||
timePaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
|
||||
timePaint.setTextSize(Utilities.dp(14));
|
||||
timePaint.setColor(0xff9e9e9e);
|
||||
}
|
||||
|
||||
if (countPaint == null) {
|
||||
countPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
|
||||
countPaint.setTextSize(Utilities.dp(13));
|
||||
countPaint.setColor(0xffffffff);
|
||||
}
|
||||
|
||||
if (lockDrawable == null) {
|
||||
lockDrawable = getResources().getDrawable(R.drawable.ic_lock_green);
|
||||
}
|
||||
|
||||
if (checkDrawable == null) {
|
||||
checkDrawable = getResources().getDrawable(R.drawable.dialogs_check);
|
||||
}
|
||||
|
||||
if (halfCheckDrawable == null) {
|
||||
halfCheckDrawable = getResources().getDrawable(R.drawable.dialogs_halfcheck);
|
||||
}
|
||||
|
||||
if (clockDrawable == null) {
|
||||
clockDrawable = getResources().getDrawable(R.drawable.msg_clock);
|
||||
}
|
||||
|
||||
if (errorDrawable == null) {
|
||||
errorDrawable = getResources().getDrawable(R.drawable.dialogs_warning);
|
||||
}
|
||||
|
||||
if (countDrawable == null) {
|
||||
countDrawable = getResources().getDrawable(R.drawable.dialogs_badge);
|
||||
}
|
||||
|
||||
if (avatarImage == null) {
|
||||
avatarImage = new ImageReceiver();
|
||||
avatarImage.parentView = new WeakReference<View>(this);
|
||||
}
|
||||
|
||||
if (cellLayout == null) {
|
||||
cellLayout = new DialogCellLayout();
|
||||
}
|
||||
}
|
||||
|
||||
public DialogCell(Context context) {
|
||||
super(context);
|
||||
init();
|
||||
}
|
||||
|
||||
public DialogCell(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init();
|
||||
}
|
||||
|
||||
public DialogCell(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init();
|
||||
}
|
||||
|
||||
public void setDialog(TLRPC.TL_dialog dialog) {
|
||||
currentDialog = dialog;
|
||||
update(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), Utilities.dp(70));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
||||
if (currentDialog == null) {
|
||||
super.onLayout(changed, left, top, right, bottom);
|
||||
return;
|
||||
}
|
||||
if (changed) {
|
||||
buildLayout();
|
||||
}
|
||||
}
|
||||
|
||||
public void buildLayout() {
|
||||
cellLayout.build(getMeasuredWidth(), getMeasuredHeight());
|
||||
}
|
||||
|
||||
public void update(int mask) {
|
||||
if (mask != 0) {
|
||||
boolean continueUpdate = false;
|
||||
if ((mask & MessagesController.UPDATE_MASK_USER_PRINT) != 0) {
|
||||
CharSequence printString = MessagesController.Instance.printingStrings.get(currentDialog.id);
|
||||
if (lastPrintString != null && printString == null || lastPrintString == null && printString != null || lastPrintString != null && printString != null && !lastPrintString.equals(printString)) {
|
||||
continueUpdate = true;
|
||||
}
|
||||
}
|
||||
if ((mask & MessagesController.UPDATE_MASK_AVATAR) != 0) {
|
||||
if (chat == null) {
|
||||
continueUpdate = true;
|
||||
}
|
||||
}
|
||||
if ((mask & MessagesController.UPDATE_MASK_NAME) != 0) {
|
||||
if (chat == null) {
|
||||
continueUpdate = true;
|
||||
}
|
||||
}
|
||||
if ((mask & MessagesController.UPDATE_MASK_CHAT_AVATAR) != 0) {
|
||||
if (user == null) {
|
||||
continueUpdate = true;
|
||||
}
|
||||
}
|
||||
if ((mask & MessagesController.UPDATE_MASK_CHAT_NAME) != 0) {
|
||||
if (user == null) {
|
||||
continueUpdate = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!continueUpdate) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
user = null;
|
||||
chat = null;
|
||||
encryptedChat = null;
|
||||
|
||||
int lower_id = (int)currentDialog.id;
|
||||
if (lower_id != 0) {
|
||||
if (lower_id < 0) {
|
||||
chat = MessagesController.Instance.chats.get(-lower_id);
|
||||
} else {
|
||||
user = MessagesController.Instance.users.get(lower_id);
|
||||
}
|
||||
} else {
|
||||
encryptedChat = MessagesController.Instance.encryptedChats.get((int)(currentDialog.id >> 32));
|
||||
if (encryptedChat != null) {
|
||||
user = MessagesController.Instance.users.get(encryptedChat.user_id);
|
||||
}
|
||||
}
|
||||
|
||||
int placeHolderId = 0;
|
||||
TLRPC.FileLocation photo = null;
|
||||
if (user != null) {
|
||||
if (user.photo != null) {
|
||||
photo = user.photo.photo_small;
|
||||
}
|
||||
placeHolderId = Utilities.getUserAvatarForId(user.id);
|
||||
} else if (chat != null) {
|
||||
if (chat.photo != null) {
|
||||
photo = chat.photo.photo_small;
|
||||
}
|
||||
placeHolderId = Utilities.getGroupAvatarForId(chat.id);
|
||||
}
|
||||
avatarImage.setImage(photo, "50_50", placeHolderId == 0 ? null : getResources().getDrawable(placeHolderId));
|
||||
|
||||
if (getMeasuredWidth() != 0 || getMeasuredHeight() != 0) {
|
||||
buildLayout();
|
||||
} else {
|
||||
requestLayout();
|
||||
}
|
||||
|
||||
invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
if (currentDialog == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (cellLayout == null) {
|
||||
requestLayout();
|
||||
return;
|
||||
}
|
||||
|
||||
if (cellLayout.drawNameLock) {
|
||||
setDrawableBounds(lockDrawable, cellLayout.nameLockLeft, cellLayout.nameLockTop);
|
||||
lockDrawable.draw(canvas);
|
||||
}
|
||||
|
||||
canvas.save();
|
||||
canvas.translate(cellLayout.nameLeft, cellLayout.nameTop);
|
||||
cellLayout.nameLayout.draw(canvas);
|
||||
canvas.restore();
|
||||
|
||||
canvas.save();
|
||||
canvas.translate(cellLayout.timeLeft, cellLayout.timeTop);
|
||||
cellLayout.timeLayout.draw(canvas);
|
||||
canvas.restore();
|
||||
|
||||
canvas.save();
|
||||
canvas.translate(cellLayout.messageLeft, cellLayout.messageTop);
|
||||
cellLayout.messageLayout.draw(canvas);
|
||||
canvas.restore();
|
||||
|
||||
if (cellLayout.drawClock) {
|
||||
setDrawableBounds(clockDrawable, cellLayout.checkDrawLeft, cellLayout.checkDrawTop);
|
||||
clockDrawable.draw(canvas);
|
||||
} else if (cellLayout.drawCheck2) {
|
||||
if (cellLayout.drawCheck1) {
|
||||
setDrawableBounds(halfCheckDrawable, cellLayout.halfCheckDrawLeft, cellLayout.checkDrawTop);
|
||||
halfCheckDrawable.draw(canvas);
|
||||
setDrawableBounds(checkDrawable, cellLayout.checkDrawLeft, cellLayout.checkDrawTop);
|
||||
checkDrawable.draw(canvas);
|
||||
} else {
|
||||
setDrawableBounds(checkDrawable, cellLayout.checkDrawLeft, cellLayout.checkDrawTop);
|
||||
checkDrawable.draw(canvas);
|
||||
}
|
||||
}
|
||||
|
||||
if (cellLayout.drawError) {
|
||||
setDrawableBounds(errorDrawable, cellLayout.errorLeft, cellLayout.errorTop);
|
||||
errorDrawable.draw(canvas);
|
||||
} else if (cellLayout.drawCount) {
|
||||
setDrawableBounds(countDrawable, cellLayout.countLeft - Utilities.dp(5), cellLayout.countTop, cellLayout.countWidth + Utilities.dp(10), countDrawable.getIntrinsicHeight());
|
||||
countDrawable.draw(canvas);
|
||||
canvas.save();
|
||||
canvas.translate(cellLayout.countLeft, cellLayout.countTop + Utilities.dp(3));
|
||||
cellLayout.countLayout.draw(canvas);
|
||||
canvas.restore();
|
||||
}
|
||||
|
||||
avatarImage.draw(canvas, cellLayout.avatarLeft, cellLayout.avatarTop, Utilities.dp(54), Utilities.dp(54));
|
||||
}
|
||||
|
||||
private class DialogCellLayout {
|
||||
private int nameLeft;
|
||||
private int nameTop = Utilities.dp(10);
|
||||
private int nameWidth;
|
||||
private StaticLayout nameLayout;
|
||||
private boolean drawNameLock;
|
||||
private int nameLockLeft;
|
||||
private int nameLockTop = Utilities.dp(13);
|
||||
|
||||
private int timeLeft;
|
||||
private int timeTop = Utilities.dp(13);
|
||||
private int timeWidth;
|
||||
private StaticLayout timeLayout;
|
||||
|
||||
private boolean drawCheck1;
|
||||
private boolean drawCheck2;
|
||||
private boolean drawClock;
|
||||
private int checkDrawLeft;
|
||||
private int checkDrawTop = Utilities.dp(15);
|
||||
private int halfCheckDrawLeft;
|
||||
|
||||
private int messageTop = Utilities.dp(40);
|
||||
private int messageLeft;
|
||||
private int messageWidth;
|
||||
private StaticLayout messageLayout;
|
||||
|
||||
private boolean drawError;
|
||||
private int errorTop = Utilities.dp(37);
|
||||
private int errorLeft;
|
||||
|
||||
private boolean drawCount;
|
||||
private int countTop = Utilities.dp(37);
|
||||
private int countLeft;
|
||||
private int countWidth;
|
||||
private StaticLayout countLayout;
|
||||
|
||||
private int avatarTop = Utilities.dp(8);
|
||||
private int avatarLeft;
|
||||
|
||||
public void build(int width, int height) {
|
||||
MessageObject message = MessagesController.Instance.dialogMessage.get(currentDialog.top_message);
|
||||
String nameString = "";
|
||||
String timeString = "";
|
||||
String countString = null;
|
||||
CharSequence messageString = "";
|
||||
CharSequence printingString = MessagesController.Instance.printingStrings.get(currentDialog.id);
|
||||
TextPaint currentNamePaint = namePaint;
|
||||
TextPaint currentMessagePaint = messagePaint;
|
||||
boolean checkMessage = true;
|
||||
|
||||
if (encryptedChat != null) {
|
||||
drawNameLock = true;
|
||||
if (!Utilities.isRTL) {
|
||||
nameLockLeft = Utilities.dp(77);
|
||||
nameLeft = Utilities.dp(81) + lockDrawable.getIntrinsicWidth();
|
||||
} else {
|
||||
nameLockLeft = width - Utilities.dp(77) - lockDrawable.getIntrinsicWidth();
|
||||
nameLeft = Utilities.dp(14);
|
||||
}
|
||||
} else {
|
||||
drawNameLock = false;
|
||||
if (!Utilities.isRTL) {
|
||||
nameLeft = Utilities.dp(77);
|
||||
} else {
|
||||
nameLeft = Utilities.dp(14);
|
||||
}
|
||||
}
|
||||
|
||||
if (message == null) {
|
||||
if (printingString != null) {
|
||||
lastPrintString = messageString = printingString;
|
||||
currentMessagePaint = messagePrintingPaint;
|
||||
} else {
|
||||
lastPrintString = null;
|
||||
if (encryptedChat != null) {
|
||||
currentMessagePaint = messagePrintingPaint;
|
||||
if (encryptedChat instanceof TLRPC.TL_encryptedChatRequested) {
|
||||
messageString = ApplicationLoader.applicationContext.getString(R.string.EncryptionProcessing);
|
||||
} else if (encryptedChat instanceof TLRPC.TL_encryptedChatWaiting) {
|
||||
if (user != null && user.first_name != null) {
|
||||
messageString = String.format(ApplicationLoader.applicationContext.getString(R.string.AwaitingEncryption), user.first_name);
|
||||
} else {
|
||||
messageString = String.format(ApplicationLoader.applicationContext.getString(R.string.AwaitingEncryption), "");
|
||||
}
|
||||
} else if (encryptedChat instanceof TLRPC.TL_encryptedChatDiscarded) {
|
||||
messageString = ApplicationLoader.applicationContext.getString(R.string.EncryptionRejected);
|
||||
} else if (encryptedChat instanceof TLRPC.TL_encryptedChat) {
|
||||
if (encryptedChat.admin_id == UserConfig.clientUserId) {
|
||||
if (user != null && user.first_name != null) {
|
||||
messageString = String.format(ApplicationLoader.applicationContext.getString(R.string.EncryptedChatStartedOutgoing), user.first_name);
|
||||
} else {
|
||||
messageString = String.format(ApplicationLoader.applicationContext.getString(R.string.EncryptedChatStartedOutgoing), "");
|
||||
}
|
||||
} else {
|
||||
messageString = ApplicationLoader.applicationContext.getString(R.string.EncryptedChatStartedIncoming);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (currentDialog.last_message_date != 0) {
|
||||
timeString = Utilities.stringForMessageListDate(currentDialog.last_message_date);
|
||||
}
|
||||
drawCheck1 = false;
|
||||
drawCheck2 = false;
|
||||
drawClock = false;
|
||||
drawCount = false;
|
||||
drawError = false;
|
||||
} else {
|
||||
TLRPC.User fromUser = MessagesController.Instance.users.get(message.messageOwner.from_id);
|
||||
|
||||
if (currentDialog.last_message_date != 0) {
|
||||
timeString = Utilities.stringForMessageListDate(currentDialog.last_message_date);
|
||||
} else {
|
||||
timeString = Utilities.stringForMessageListDate(message.messageOwner.date);
|
||||
}
|
||||
if (printingString != null) {
|
||||
lastPrintString = messageString = printingString;
|
||||
currentMessagePaint = messagePrintingPaint;
|
||||
} else {
|
||||
lastPrintString = null;
|
||||
if (message.messageOwner instanceof TLRPC.TL_messageService) {
|
||||
messageString = message.messageText;
|
||||
currentMessagePaint = messagePrintingPaint;
|
||||
} else {
|
||||
if (chat != null) {
|
||||
String name = "";
|
||||
if (message.messageOwner.from_id == UserConfig.clientUserId) {
|
||||
name = ApplicationLoader.applicationContext.getString(R.string.FromYou);
|
||||
} else {
|
||||
if (fromUser != null) {
|
||||
if (fromUser.first_name.length() > 0) {
|
||||
name = fromUser.first_name;
|
||||
} else {
|
||||
name = fromUser.last_name;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (message.messageOwner.media != null && !(message.messageOwner.media instanceof TLRPC.TL_messageMediaEmpty)) {
|
||||
messageString = message.messageText;
|
||||
currentMessagePaint = messagePrintingPaint;
|
||||
} else {
|
||||
checkMessage = false;
|
||||
if (message.messageOwner.message != null) {
|
||||
messageString = Emoji.replaceEmoji(Html.fromHtml(String.format("<font color=#316f9f>%s:</font> <font color=#808080>%s</font>", name, message.messageOwner.message.replace("\n", " "))));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
messageString = message.messageText;
|
||||
if (message.messageOwner.media != null && !(message.messageOwner.media instanceof TLRPC.TL_messageMediaEmpty)) {
|
||||
currentMessagePaint = messagePrintingPaint;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (currentDialog.unread_count != 0) {
|
||||
drawCount = true;
|
||||
countString = String.format("%d", currentDialog.unread_count);
|
||||
} else {
|
||||
drawCount = false;
|
||||
}
|
||||
|
||||
if (message.messageOwner.id < 0 && message.messageOwner.send_state != MessagesController.MESSAGE_SEND_STATE_SENT) {
|
||||
if (MessagesController.Instance.sendingMessages.get(message.messageOwner.id) == null) {
|
||||
message.messageOwner.send_state = MessagesController.MESSAGE_SEND_STATE_SEND_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
if (message.messageOwner.from_id == UserConfig.clientUserId) {
|
||||
if (message.messageOwner.send_state == MessagesController.MESSAGE_SEND_STATE_SENDING) {
|
||||
drawCheck1 = false;
|
||||
drawCheck2 = false;
|
||||
drawClock = true;
|
||||
drawError = false;
|
||||
} else if (message.messageOwner.send_state == MessagesController.MESSAGE_SEND_STATE_SEND_ERROR) {
|
||||
drawCheck1 = false;
|
||||
drawCheck2 = false;
|
||||
drawClock = false;
|
||||
drawError = true;
|
||||
drawCount = false;
|
||||
} else if (message.messageOwner.send_state == MessagesController.MESSAGE_SEND_STATE_SENT) {
|
||||
if (!message.messageOwner.unread) {
|
||||
drawCheck1 = true;
|
||||
drawCheck2 = true;
|
||||
} else {
|
||||
drawCheck1 = false;
|
||||
drawCheck2 = true;
|
||||
}
|
||||
drawClock = false;
|
||||
drawError = false;
|
||||
}
|
||||
} else {
|
||||
drawCheck1 = false;
|
||||
drawCheck2 = false;
|
||||
drawClock = false;
|
||||
drawError = false;
|
||||
}
|
||||
}
|
||||
|
||||
timeWidth = (int)Math.ceil(timePaint.measureText(timeString));
|
||||
timeLayout = new StaticLayout(timeString, timePaint, timeWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
|
||||
if (!Utilities.isRTL) {
|
||||
timeLeft = width - Utilities.dp(11) - timeWidth;
|
||||
} else {
|
||||
timeLeft = Utilities.dp(11);
|
||||
}
|
||||
|
||||
if (chat != null) {
|
||||
nameString = chat.title;
|
||||
} else if (user != null) {
|
||||
if (user.id != 333000 && ContactsController.Instance.contactsDict.get(user.id) == null) {
|
||||
if (ContactsController.Instance.contactsDict.size() == 0 && (!ContactsController.Instance.contactsLoaded || ContactsController.Instance.loadingContacts)) {
|
||||
nameString = Utilities.formatName(user.first_name, user.last_name);
|
||||
} else {
|
||||
if (user.phone != null && user.phone.length() != 0) {
|
||||
nameString = PhoneFormat.Instance.format("+" + user.phone);
|
||||
} else {
|
||||
currentNamePaint = nameUnknownPaint;
|
||||
nameString = Utilities.formatName(user.first_name, user.last_name);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
nameString = Utilities.formatName(user.first_name, user.last_name);
|
||||
}
|
||||
if (encryptedChat != null) {
|
||||
currentNamePaint = nameEncryptedPaint;
|
||||
}
|
||||
}
|
||||
if (nameString.length() == 0) {
|
||||
nameString = ApplicationLoader.applicationContext.getString(R.string.HiddenName);
|
||||
}
|
||||
|
||||
if (!Utilities.isRTL) {
|
||||
nameWidth = width - nameLeft - Utilities.dp(14) - timeWidth;
|
||||
} else {
|
||||
nameWidth = width - nameLeft - Utilities.dp(77) - timeWidth;
|
||||
nameLeft += timeWidth;
|
||||
}
|
||||
if (drawNameLock) {
|
||||
nameWidth -= Utilities.dp(4) + lockDrawable.getIntrinsicWidth();
|
||||
}
|
||||
if (drawClock) {
|
||||
int w = clockDrawable.getIntrinsicWidth() + Utilities.dp(2);
|
||||
nameWidth -= w;
|
||||
if (!Utilities.isRTL) {
|
||||
checkDrawLeft = timeLeft - w;
|
||||
} else {
|
||||
checkDrawLeft = timeLeft + timeWidth + Utilities.dp(2);
|
||||
nameLeft += w;
|
||||
}
|
||||
} else if (drawCheck2) {
|
||||
int w = checkDrawable.getIntrinsicWidth() + Utilities.dp(2);
|
||||
nameWidth -= w;
|
||||
if (drawCheck1) {
|
||||
nameWidth -= halfCheckDrawable.getIntrinsicWidth() - Utilities.dp(5);
|
||||
if (!Utilities.isRTL) {
|
||||
halfCheckDrawLeft = timeLeft - w;
|
||||
checkDrawLeft = halfCheckDrawLeft - Utilities.dp(5);
|
||||
} else {
|
||||
checkDrawLeft = timeLeft + timeWidth + Utilities.dp(2);
|
||||
halfCheckDrawLeft = checkDrawLeft + Utilities.dp(5);
|
||||
nameLeft += w + halfCheckDrawable.getIntrinsicWidth() - Utilities.dp(5);
|
||||
}
|
||||
} else {
|
||||
if (!Utilities.isRTL) {
|
||||
checkDrawLeft = timeLeft - w;
|
||||
} else {
|
||||
checkDrawLeft = timeLeft + timeWidth + Utilities.dp(2);
|
||||
nameLeft += w;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CharSequence nameStringFinal = TextUtils.ellipsize(nameString.replace("\n", " "), currentNamePaint, nameWidth - Utilities.dp(12), TextUtils.TruncateAt.END);
|
||||
nameLayout = new StaticLayout(nameStringFinal, currentNamePaint, nameWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
|
||||
|
||||
messageWidth = width - Utilities.dp(88);
|
||||
if (!Utilities.isRTL) {
|
||||
messageLeft = Utilities.dp(77);
|
||||
avatarLeft = Utilities.dp(11);
|
||||
} else {
|
||||
messageLeft = Utilities.dp(11);
|
||||
avatarLeft = width - Utilities.dp(65);
|
||||
}
|
||||
avatarImage.imageX = avatarLeft;
|
||||
avatarImage.imageY = avatarTop;
|
||||
avatarImage.imageW = Utilities.dp(54);
|
||||
avatarImage.imageH = Utilities.dp(54);
|
||||
if (drawError) {
|
||||
int w = errorDrawable.getIntrinsicWidth() + Utilities.dp(8);
|
||||
messageWidth -= w;
|
||||
if (!Utilities.isRTL) {
|
||||
errorLeft = width - errorDrawable.getIntrinsicWidth() - Utilities.dp(11);
|
||||
} else {
|
||||
errorLeft = Utilities.dp(11);
|
||||
messageLeft += w;
|
||||
}
|
||||
} else if (countString != null) {
|
||||
countWidth = Math.max(Utilities.dp(12), (int)Math.ceil(countPaint.measureText(countString)));
|
||||
countLayout = new StaticLayout(countString, countPaint, countWidth, Layout.Alignment.ALIGN_CENTER, 1.0f, 0.0f, false);
|
||||
int w = countWidth + Utilities.dp(18);
|
||||
messageWidth -= w;
|
||||
if (!Utilities.isRTL) {
|
||||
countLeft = width - countWidth - Utilities.dp(16);
|
||||
} else {
|
||||
countLeft = Utilities.dp(16);
|
||||
messageLeft += w;
|
||||
}
|
||||
drawCount = true;
|
||||
} else {
|
||||
drawCount = false;
|
||||
}
|
||||
|
||||
if (checkMessage) {
|
||||
if (messageString == null) {
|
||||
messageString = "";
|
||||
}
|
||||
String mess = messageString.toString().replace("\n", " ");
|
||||
if (mess.length() > 150) {
|
||||
mess = mess.substring(0, 150);
|
||||
}
|
||||
messageString = Emoji.replaceEmoji(mess);
|
||||
}
|
||||
|
||||
CharSequence messageStringFinal = TextUtils.ellipsize(messageString, currentMessagePaint, messageWidth - Utilities.dp(12), TextUtils.TruncateAt.END);
|
||||
messageLayout = new StaticLayout(messageStringFinal, currentMessagePaint, messageWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
|
||||
|
||||
double widthpx = 0;
|
||||
float left = 0;
|
||||
if (Utilities.isRTL) {
|
||||
if (nameLayout.getLineCount() > 0) {
|
||||
left = nameLayout.getLineLeft(0);
|
||||
if (left == 0) {
|
||||
widthpx = Math.ceil(nameLayout.getLineWidth(0));
|
||||
if (widthpx < nameWidth) {
|
||||
nameLeft += (nameWidth - widthpx);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (messageLayout.getLineCount() > 0) {
|
||||
left = messageLayout.getLineLeft(0);
|
||||
if (left == 0) {
|
||||
widthpx = Math.ceil(messageLayout.getLineWidth(0));
|
||||
if (widthpx < messageWidth) {
|
||||
messageLeft += (messageWidth - widthpx);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (nameLayout.getLineCount() > 0) {
|
||||
left = nameLayout.getLineRight(0);
|
||||
if (left == nameWidth) {
|
||||
widthpx = Math.ceil(nameLayout.getLineWidth(0));
|
||||
if (widthpx < nameWidth) {
|
||||
nameLeft -= (nameWidth - widthpx);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (messageLayout.getLineCount() > 0) {
|
||||
left = messageLayout.getLineRight(0);
|
||||
if (left == messageWidth) {
|
||||
widthpx = Math.ceil(messageLayout.getLineWidth(0));
|
||||
if (widthpx < messageWidth) {
|
||||
messageLeft -= (messageWidth - widthpx);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -44,6 +44,7 @@ import org.telegram.messenger.NotificationCenter;
|
|||
import org.telegram.messenger.R;
|
||||
import org.telegram.messenger.UserConfig;
|
||||
import org.telegram.messenger.Utilities;
|
||||
import org.telegram.ui.Cells.ChatOrUserCell;
|
||||
import org.telegram.ui.Views.AvatarUpdater;
|
||||
import org.telegram.ui.Views.BackupImageView;
|
||||
import org.telegram.ui.Views.BaseFragment;
|
||||
|
@ -239,8 +240,8 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen
|
|||
}
|
||||
|
||||
@Override
|
||||
public void didSelectContact(int user_id) {
|
||||
MessagesController.Instance.addUserToChat(chat_id, user_id, info);
|
||||
public void didSelectContact(TLRPC.User user) {
|
||||
MessagesController.Instance.addUserToChat(chat_id, user, info);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -277,9 +278,12 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen
|
|||
|
||||
public void didReceivedNotification(int id, Object... args) {
|
||||
if (id == MessagesController.updateInterfaces) {
|
||||
updateOnlineCount();
|
||||
if (listView != null) {
|
||||
listView.invalidateViews();
|
||||
int mask = (Integer)args[0];
|
||||
if ((mask & MessagesController.UPDATE_MASK_CHAT_AVATAR) != 0 || (mask & MessagesController.UPDATE_MASK_CHAT_NAME) != 0 || (mask & MessagesController.UPDATE_MASK_CHAT_MEMBERS) != 0) {
|
||||
updateOnlineCount();
|
||||
}
|
||||
if ((mask & MessagesController.UPDATE_MASK_AVATAR) != 0 || (mask & MessagesController.UPDATE_MASK_NAME) != 0 || (mask & MessagesController.UPDATE_MASK_STATUS) != 0) {
|
||||
updateVisibleRows(mask);
|
||||
}
|
||||
} else if (id == MessagesController.chatInfoDidLoaded) {
|
||||
int chatId = (Integer)args[0];
|
||||
|
@ -355,6 +359,19 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen
|
|||
return true;
|
||||
}
|
||||
|
||||
private void updateVisibleRows(int mask) {
|
||||
if (listView == null) {
|
||||
return;
|
||||
}
|
||||
int count = listView.getChildCount();
|
||||
for (int a = 0; a < count; a++) {
|
||||
View child = listView.getChildAt(a);
|
||||
if (child instanceof ChatOrUserCell) {
|
||||
((ChatOrUserCell) child).update(mask);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateOnlineCount() {
|
||||
if (info == null) {
|
||||
return;
|
||||
|
@ -451,11 +468,11 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen
|
|||
|
||||
private void kickUser(TLRPC.TL_chatParticipant user) {
|
||||
if (user != null) {
|
||||
MessagesController.Instance.deleteUserFromChat(chat_id, user.user_id, info);
|
||||
MessagesController.Instance.deleteUserFromChat(chat_id, MessagesController.Instance.users.get(user.user_id), info);
|
||||
} else {
|
||||
NotificationCenter.Instance.removeObserver(this, MessagesController.closeChats);
|
||||
NotificationCenter.Instance.postNotificationName(MessagesController.closeChats);
|
||||
MessagesController.Instance.deleteUserFromChat(chat_id, UserConfig.clientUserId, info);
|
||||
MessagesController.Instance.deleteUserFromChat(chat_id, MessagesController.Instance.users.get(UserConfig.clientUserId), info);
|
||||
MessagesController.Instance.deleteDialog(-chat_id, 0, false);
|
||||
finishFragment();
|
||||
}
|
||||
|
@ -674,60 +691,19 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen
|
|||
TLRPC.User user = MessagesController.Instance.users.get(part.user_id);
|
||||
|
||||
if (view == null) {
|
||||
LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
view = li.inflate(R.layout.messages_search_user_layout, viewGroup, false);
|
||||
}
|
||||
ContactsActivity.ContactListRowHolder holder = (ContactsActivity.ContactListRowHolder)view.getTag();
|
||||
if (holder == null) {
|
||||
holder = new ContactsActivity.ContactListRowHolder(view);
|
||||
view.setTag(holder);
|
||||
view = new ChatOrUserCell(mContext);
|
||||
((ChatOrUserCell)view).useBoldFont = true;
|
||||
((ChatOrUserCell)view).usePadding = false;
|
||||
((ChatOrUserCell)view).useSeparator = true;
|
||||
}
|
||||
|
||||
View divider = view.findViewById(R.id.settings_row_divider);
|
||||
divider.setVisibility(View.VISIBLE);
|
||||
|
||||
if (user.first_name.length() != 0 && user.last_name.length() != 0) {
|
||||
holder.nameTextView.setText(Html.fromHtml(user.first_name + " <b>" + user.last_name + "</b>"));
|
||||
} else if (user.first_name.length() != 0) {
|
||||
holder.nameTextView.setText(Html.fromHtml("<b>" + user.first_name + "</b>"));
|
||||
} else {
|
||||
holder.nameTextView.setText(Html.fromHtml("<b>" + user.last_name + "</b>"));
|
||||
}
|
||||
((ChatOrUserCell)view).setData(user, null, null, null, null);
|
||||
|
||||
// if (info.admin_id != UserConfig.clientUserId && part.inviter_id != UserConfig.clientUserId && part.user_id != UserConfig.clientUserId) {
|
||||
//
|
||||
// } else {
|
||||
//
|
||||
// }
|
||||
|
||||
TLRPC.FileLocation photo = null;
|
||||
if (user.photo != null) {
|
||||
photo = user.photo.photo_small;
|
||||
}
|
||||
int placeHolderId = Utilities.getUserAvatarForId(user.id);
|
||||
holder.avatarImage.setImage(photo, "50_50", placeHolderId);
|
||||
|
||||
if (user.status == null) {
|
||||
holder.messageTextView.setTextColor(0xff808080);
|
||||
holder.messageTextView.setText(getStringEntry(R.string.Offline));
|
||||
} else {
|
||||
int currentTime = ConnectionsManager.Instance.getCurrentTime();
|
||||
if ((user.status.expires > currentTime || user.status.was_online > currentTime || user.id == UserConfig.clientUserId) && user.status.expires != 0) {
|
||||
holder.messageTextView.setTextColor(0xff357aa8);
|
||||
holder.messageTextView.setText(getStringEntry(R.string.Online));
|
||||
} else {
|
||||
if (user.status.was_online <= 10000 && user.status.expires <= 10000) {
|
||||
holder.messageTextView.setText(getStringEntry(R.string.Invisible));
|
||||
} else {
|
||||
int value = user.status.was_online;
|
||||
if (value == 0) {
|
||||
value = user.status.expires;
|
||||
}
|
||||
holder.messageTextView.setText(String.format("%s %s", getStringEntry(R.string.LastSeen), Utilities.formatDateOnline(value)));
|
||||
}
|
||||
holder.messageTextView.setTextColor(0xff808080);
|
||||
}
|
||||
}
|
||||
} else if (type == 5) {
|
||||
if (view == null) {
|
||||
LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
|
|
|
@ -131,7 +131,7 @@ public class ChatProfileChangeNameActivity extends BaseFragment {
|
|||
}
|
||||
((ApplicationActivity)parentActivity).updateActionBar();
|
||||
|
||||
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
|
||||
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
||||
boolean animations = preferences.getBoolean("view_animations", true);
|
||||
if (!animations) {
|
||||
firstNameField.requestFocus();
|
||||
|
|
|
@ -26,6 +26,7 @@ import android.widget.TextView;
|
|||
import org.telegram.PhoneFormat.PhoneFormat;
|
||||
import org.telegram.TL.TLRPC;
|
||||
import org.telegram.messenger.ConnectionsManager;
|
||||
import org.telegram.messenger.ContactsController;
|
||||
import org.telegram.messenger.MessagesController;
|
||||
import org.telegram.messenger.NotificationCenter;
|
||||
import org.telegram.messenger.R;
|
||||
|
@ -49,7 +50,8 @@ public class ContactAddActivity extends BaseFragment implements NotificationCent
|
|||
NotificationCenter.Instance.addObserver(this, MessagesController.updateInterfaces);
|
||||
user_id = getArguments().getInt("user_id", 0);
|
||||
phone = getArguments().getString("phone");
|
||||
return true;
|
||||
TLRPC.User user = MessagesController.Instance.users.get(user_id);
|
||||
return user != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -64,8 +66,10 @@ public class ContactAddActivity extends BaseFragment implements NotificationCent
|
|||
fragmentView = inflater.inflate(R.layout.contact_add_layout, container, false);
|
||||
|
||||
TLRPC.User user = MessagesController.Instance.users.get(user_id);
|
||||
if (phone != null) {
|
||||
user.phone = PhoneFormat.stripExceptNumbers(phone);
|
||||
if (user.phone == null) {
|
||||
if (phone != null) {
|
||||
user.phone = PhoneFormat.stripExceptNumbers(phone);
|
||||
}
|
||||
}
|
||||
|
||||
onlineText = (TextView)fragmentView.findViewById(R.id.settings_online);
|
||||
|
@ -137,7 +141,7 @@ public class ContactAddActivity extends BaseFragment implements NotificationCent
|
|||
if (value == 0) {
|
||||
value = user.status.expires;
|
||||
}
|
||||
onlineText.setText(String.format("%s %s", getStringEntry(R.string.LastSeen), Utilities.formatDateOnline(value)));
|
||||
onlineText.setText(Utilities.formatDateOnline(value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -151,7 +155,10 @@ public class ContactAddActivity extends BaseFragment implements NotificationCent
|
|||
|
||||
public void didReceivedNotification(int id, Object... args) {
|
||||
if (id == MessagesController.updateInterfaces) {
|
||||
updateAvatarLayout();
|
||||
int mask = (Integer)args[0];
|
||||
if ((mask & MessagesController.UPDATE_MASK_AVATAR) != 0 || (mask & MessagesController.UPDATE_MASK_STATUS) != 0) {
|
||||
updateAvatarLayout();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -197,8 +204,9 @@ public class ContactAddActivity extends BaseFragment implements NotificationCent
|
|||
TLRPC.User user = MessagesController.Instance.users.get(user_id);
|
||||
user.first_name = firstNameField.getText().toString();
|
||||
user.last_name = lastNameField.getText().toString();
|
||||
MessagesController.Instance.addContact(user);
|
||||
ContactsController.Instance.addContact(user);
|
||||
finishFragment();
|
||||
NotificationCenter.Instance.postNotificationName(MessagesController.updateInterfaces, MessagesController.UPDATE_MASK_NAME);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -212,7 +220,7 @@ public class ContactAddActivity extends BaseFragment implements NotificationCent
|
|||
}
|
||||
((ApplicationActivity)parentActivity).updateActionBar();
|
||||
|
||||
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
|
||||
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
||||
boolean animations = preferences.getBoolean("view_animations", true);
|
||||
if (!animations) {
|
||||
firstNameField.requestFocus();
|
||||
|
|
|
@ -8,10 +8,12 @@
|
|||
|
||||
package org.telegram.ui;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.internal.view.SupportMenuItem;
|
||||
|
@ -30,16 +32,18 @@ import android.widget.BaseAdapter;
|
|||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.telegram.PhoneFormat.PhoneFormat;
|
||||
import org.telegram.TL.TLObject;
|
||||
import org.telegram.TL.TLRPC;
|
||||
import org.telegram.messenger.ConnectionsManager;
|
||||
import org.telegram.messenger.ContactsController;
|
||||
import org.telegram.messenger.FileLog;
|
||||
import org.telegram.messenger.MessagesController;
|
||||
import org.telegram.messenger.NotificationCenter;
|
||||
import org.telegram.messenger.R;
|
||||
import org.telegram.messenger.RPCRequest;
|
||||
import org.telegram.messenger.UserConfig;
|
||||
import org.telegram.messenger.Utilities;
|
||||
import org.telegram.ui.Views.BackupImageView;
|
||||
import org.telegram.ui.Cells.ChatOrUserCell;
|
||||
import org.telegram.ui.Views.BaseFragment;
|
||||
import org.telegram.ui.Views.OnSwipeTouchListener;
|
||||
import org.telegram.ui.Views.PinnedHeaderListView;
|
||||
|
@ -70,22 +74,22 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
|
|||
private TextView epmtyTextView;
|
||||
private HashMap<Integer, TLRPC.User> ignoreUsers;
|
||||
private SupportMenuItem searchItem;
|
||||
private boolean isRTL;
|
||||
|
||||
private Timer searchDialogsTimer;
|
||||
private String inviteText;
|
||||
private boolean updatingInviteText = false;
|
||||
public ArrayList<TLRPC.User> searchResult;
|
||||
public ArrayList<CharSequence> searchResultNames;
|
||||
public ContactsActivityDelegate delegate;
|
||||
|
||||
public static interface ContactsActivityDelegate {
|
||||
public abstract void didSelectContact(int user_id);
|
||||
public abstract void didSelectContact(TLRPC.User user);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public boolean onFragmentCreate() {
|
||||
super.onFragmentCreate();
|
||||
NotificationCenter.Instance.addObserver(this, MessagesController.contactsBookDidLoaded);
|
||||
NotificationCenter.Instance.addObserver(this, MessagesController.contactsDidLoaded);
|
||||
NotificationCenter.Instance.addObserver(this, MessagesController.updateInterfaces);
|
||||
NotificationCenter.Instance.addObserver(this, MessagesController.encryptedChatCreated);
|
||||
|
@ -99,13 +103,21 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
|
|||
ignoreUsers = (HashMap<Integer, TLRPC.User>)NotificationCenter.Instance.getFromMemCache(7);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
||||
inviteText = preferences.getString("invitetext", null);
|
||||
int time = preferences.getInt("invitetexttime", 0);
|
||||
if (inviteText == null || time + 86400 < (int)(System.currentTimeMillis() / 1000)) {
|
||||
updateInviteText();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFragmentDestroy() {
|
||||
super.onFragmentDestroy();
|
||||
NotificationCenter.Instance.removeObserver(this, MessagesController.contactsBookDidLoaded);
|
||||
NotificationCenter.Instance.removeObserver(this, MessagesController.contactsDidLoaded);
|
||||
NotificationCenter.Instance.removeObserver(this, MessagesController.updateInterfaces);
|
||||
NotificationCenter.Instance.removeObserver(this, MessagesController.encryptedChatCreated);
|
||||
|
@ -132,10 +144,6 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
|
|||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
if (fragmentView == null) {
|
||||
|
||||
Locale locale = Locale.getDefault();
|
||||
String lang = locale.getLanguage();
|
||||
isRTL = lang != null && lang.toLowerCase().equals("ar");
|
||||
|
||||
fragmentView = inflater.inflate(R.layout.contacts_layout, container, false);
|
||||
|
||||
epmtyTextView = (TextView)fragmentView.findViewById(R.id.searchEmptyView);
|
||||
|
@ -150,23 +158,23 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
|
|||
@Override
|
||||
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
|
||||
if (searching && searchWas) {
|
||||
int user_id = searchResult.get(i).id;
|
||||
if (user_id == UserConfig.clientUserId) {
|
||||
TLRPC.User user = searchResult.get(i);
|
||||
if (user.id == UserConfig.clientUserId) {
|
||||
return;
|
||||
}
|
||||
if (returnAsResult) {
|
||||
if (ignoreUsers != null && ignoreUsers.containsKey(user_id)) {
|
||||
if (ignoreUsers != null && ignoreUsers.containsKey(user.id)) {
|
||||
return;
|
||||
}
|
||||
didSelectResult(user_id, true);
|
||||
didSelectResult(user, true);
|
||||
} else {
|
||||
if (createSecretChat) {
|
||||
creatingChat = true;
|
||||
MessagesController.Instance.startSecretChat(parentActivity, user_id);
|
||||
MessagesController.Instance.startSecretChat(parentActivity, user);
|
||||
} else {
|
||||
ChatActivity fragment = new ChatActivity();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt("user_id", user_id);
|
||||
bundle.putInt("user_id", user.id);
|
||||
fragment.setArguments(bundle);
|
||||
((ApplicationActivity)parentActivity).presentFragment(fragment, "chat" + Math.random(), destroyAfterSelect, false);
|
||||
}
|
||||
|
@ -174,11 +182,20 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
|
|||
} else {
|
||||
int section = listViewAdapter.getSectionForPosition(i);
|
||||
int row = listViewAdapter.getPositionInSectionForPosition(i);
|
||||
int uid = 0;
|
||||
if (row < 0 || section < 0) {
|
||||
return;
|
||||
}
|
||||
TLRPC.User user = null;
|
||||
if (usersAsSections) {
|
||||
if (section < MessagesController.Instance.sortedUsersSectionsArray.size()) {
|
||||
ArrayList<TLRPC.TL_contact> arr = MessagesController.Instance.usersSectionsDict.get(MessagesController.Instance.sortedUsersSectionsArray.get(section));
|
||||
uid = arr.get(row).user_id;
|
||||
if (section < ContactsController.Instance.sortedUsersSectionsArray.size()) {
|
||||
ArrayList<TLRPC.TL_contact> arr = ContactsController.Instance.usersSectionsDict.get(ContactsController.Instance.sortedUsersSectionsArray.get(section));
|
||||
if (row < arr.size()) {
|
||||
TLRPC.TL_contact contact = arr.get(row);
|
||||
user = MessagesController.Instance.users.get(contact.user_id);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
if (section == 0) {
|
||||
|
@ -186,15 +203,15 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
|
|||
try {
|
||||
Intent intent = new Intent(Intent.ACTION_SEND);
|
||||
intent.setType("text/plain");
|
||||
intent.putExtra(Intent.EXTRA_TEXT, getStringEntry(R.string.InviteText));
|
||||
intent.putExtra(Intent.EXTRA_TEXT, inviteText != null ? inviteText : getStringEntry(R.string.InviteText));
|
||||
startActivity(intent);
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
if (row - 1 < MessagesController.Instance.contacts.size()) {
|
||||
uid = MessagesController.Instance.contacts.get(row - 1).user_id;
|
||||
if (row - 1 < ContactsController.Instance.contacts.size()) {
|
||||
user = MessagesController.Instance.users.get(ContactsController.Instance.contacts.get(row - 1).user_id);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
@ -202,53 +219,36 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
|
|||
}
|
||||
}
|
||||
|
||||
if (uid != 0) {
|
||||
if (uid == UserConfig.clientUserId) {
|
||||
if (user != null) {
|
||||
if (user.id == UserConfig.clientUserId) {
|
||||
return;
|
||||
}
|
||||
if (returnAsResult) {
|
||||
if (ignoreUsers != null && ignoreUsers.containsKey(uid)) {
|
||||
if (ignoreUsers != null && ignoreUsers.containsKey(user.id)) {
|
||||
return;
|
||||
}
|
||||
didSelectResult(uid, true);
|
||||
didSelectResult(user, true);
|
||||
} else {
|
||||
if (createSecretChat) {
|
||||
creatingChat = true;
|
||||
MessagesController.Instance.startSecretChat(parentActivity, uid);
|
||||
MessagesController.Instance.startSecretChat(parentActivity, user);
|
||||
} else {
|
||||
ChatActivity fragment = new ChatActivity();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt("user_id", uid);
|
||||
bundle.putInt("user_id", user.id);
|
||||
fragment.setArguments(bundle);
|
||||
((ApplicationActivity)parentActivity).presentFragment(fragment, "chat" + Math.random(), destroyAfterSelect, false);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ArrayList<MessagesController.Contact> arr = MessagesController.Instance.contactsSectionsDict.get(MessagesController.Instance.sortedContactsSectionsArray.get(section - 1));
|
||||
MessagesController.Contact contact = arr.get(row);
|
||||
ArrayList<ContactsController.Contact> arr = ContactsController.Instance.contactsSectionsDict.get(ContactsController.Instance.sortedContactsSectionsArray.get(section - 1));
|
||||
ContactsController.Contact contact = arr.get(row);
|
||||
String usePhone = null;
|
||||
for (String phone : contact.phones) {
|
||||
if (usePhone == null) {
|
||||
usePhone = phone;
|
||||
}
|
||||
String cleanPhone = PhoneFormat.stripExceptNumbers(usePhone);
|
||||
TLRPC.TL_contact cLocal = MessagesController.Instance.contactsByPhones.get(cleanPhone);
|
||||
if (cLocal != null) {
|
||||
if (cLocal.user_id == UserConfig.clientUserId) {
|
||||
return;
|
||||
}
|
||||
if (createSecretChat) {
|
||||
creatingChat = true;
|
||||
MessagesController.Instance.startSecretChat(parentActivity, cLocal.user_id);
|
||||
} else {
|
||||
ChatActivity fragment = new ChatActivity();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt("user_id", cLocal.user_id);
|
||||
fragment.setArguments(bundle);
|
||||
((ApplicationActivity)parentActivity).presentFragment(fragment, "chat" + Math.random(), destroyAfterSelect, false);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!contact.phones.isEmpty()) {
|
||||
usePhone = contact.phones.get(0);
|
||||
}
|
||||
if (usePhone == null) {
|
||||
return;
|
||||
}
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
|
||||
builder.setMessage(getStringEntry(R.string.InviteUser));
|
||||
|
@ -302,23 +302,22 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
|
|||
return fragmentView;
|
||||
}
|
||||
|
||||
private void didSelectResult(final int user_id, boolean useAlert) {
|
||||
private void didSelectResult(final TLRPC.User user, boolean useAlert) {
|
||||
if (useAlert && selectAlertString != 0) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
|
||||
builder.setTitle(R.string.AppName);
|
||||
TLRPC.User user = MessagesController.Instance.users.get(user_id);
|
||||
builder.setMessage(String.format(getStringEntry(selectAlertString), Utilities.formatName(user.first_name, user.last_name)));
|
||||
builder.setPositiveButton(R.string.OK, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
didSelectResult(user_id, false);
|
||||
didSelectResult(user, false);
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton(R.string.Cancel, null);
|
||||
builder.show().setCanceledOnTouchOutside(true);
|
||||
} else {
|
||||
if (delegate != null) {
|
||||
delegate.didSelectContact(user_id);
|
||||
delegate.didSelectContact(user);
|
||||
delegate = null;
|
||||
}
|
||||
finishFragment();
|
||||
|
@ -422,7 +421,7 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
|
|||
ArrayList<TLRPC.User> resultArray = new ArrayList<TLRPC.User>();
|
||||
ArrayList<CharSequence> resultArrayNames = new ArrayList<CharSequence>();
|
||||
|
||||
for (TLRPC.TL_contact contact : MessagesController.Instance.contacts) {
|
||||
for (TLRPC.TL_contact contact : ContactsController.Instance.contacts) {
|
||||
TLRPC.User user = MessagesController.Instance.users.get(contact.user_id);
|
||||
if (user.first_name != null && user.first_name.toLowerCase().startsWith(q) || user.last_name != null && user.last_name.toLowerCase().startsWith(q)) {
|
||||
if (user.id == UserConfig.clientUserId) {
|
||||
|
@ -537,7 +536,7 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
|
|||
searchWas = false;
|
||||
ViewGroup group = (ViewGroup) listView.getParent();
|
||||
listView.setAdapter(listViewAdapter);
|
||||
if (!isRTL) {
|
||||
if (!Utilities.isRTL) {
|
||||
listView.setPadding(Utilities.dp(16), listView.getPaddingTop(), Utilities.dp(30), listView.getPaddingBottom());
|
||||
} else {
|
||||
listView.setPadding(Utilities.dp(30), listView.getPaddingTop(), Utilities.dp(16), listView.getPaddingBottom());
|
||||
|
@ -557,13 +556,14 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
|
|||
|
||||
@Override
|
||||
public void didReceivedNotification(int id, Object... args) {
|
||||
if (id == MessagesController.contactsDidLoaded || id == MessagesController.contactsBookDidLoaded) {
|
||||
if (id == MessagesController.contactsDidLoaded) {
|
||||
if (listViewAdapter != null) {
|
||||
listViewAdapter.notifyDataSetChanged();
|
||||
}
|
||||
} else if (id == MessagesController.updateInterfaces) {
|
||||
if (listView != null) {
|
||||
listView.invalidateViews();
|
||||
int mask = (Integer)args[0];
|
||||
if ((mask & MessagesController.UPDATE_MASK_AVATAR) != 0 || (mask & MessagesController.UPDATE_MASK_NAME) != 0 || (mask & MessagesController.UPDATE_MASK_STATUS) != 0) {
|
||||
updateVisibleRows(mask);
|
||||
}
|
||||
} else if (id == MessagesController.encryptedChatCreated) {
|
||||
if (createSecretChat && creatingChat) {
|
||||
|
@ -577,6 +577,54 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
|
|||
}
|
||||
}
|
||||
|
||||
private void updateInviteText() {
|
||||
if (updatingInviteText) {
|
||||
return;
|
||||
}
|
||||
updatingInviteText = true;
|
||||
TLRPC.TL_help_getInviteText req = new TLRPC.TL_help_getInviteText();
|
||||
req.lang_code = Locale.getDefault().getCountry();
|
||||
if (req.lang_code == null || req.lang_code.length() == 0) {
|
||||
req.lang_code = "en";
|
||||
}
|
||||
ConnectionsManager.Instance.performRpc(req, new RPCRequest.RPCRequestDelegate() {
|
||||
@Override
|
||||
public void run(TLObject response, TLRPC.TL_error error) {
|
||||
if (error != null) {
|
||||
return;
|
||||
}
|
||||
final TLRPC.TL_help_inviteText res = (TLRPC.TL_help_inviteText)response;
|
||||
if (res.message.length() == 0) {
|
||||
return;
|
||||
}
|
||||
Utilities.RunOnUIThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
updatingInviteText = false;
|
||||
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = preferences.edit();
|
||||
editor.putString("invitetext", res.message);
|
||||
editor.putInt("invitetexttime", (int) (System.currentTimeMillis() / 1000));
|
||||
editor.commit();
|
||||
}
|
||||
});
|
||||
}
|
||||
}, null, true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassFailOnServerErrors);
|
||||
}
|
||||
|
||||
private void updateVisibleRows(int mask) {
|
||||
if (listView == null) {
|
||||
return;
|
||||
}
|
||||
int count = listView.getChildCount();
|
||||
for (int a = 0; a < count; a++) {
|
||||
View child = listView.getChildAt(a);
|
||||
if (child instanceof ChatOrUserCell) {
|
||||
((ChatOrUserCell) child).update(mask);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class SearchAdapter extends BaseAdapter {
|
||||
private Context mContext;
|
||||
|
||||
|
@ -619,76 +667,24 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
|
|||
|
||||
@Override
|
||||
public View getView(int i, View view, ViewGroup viewGroup) {
|
||||
int type = getItemViewType(i);
|
||||
if (view == null) {
|
||||
LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
if (type == 0) {
|
||||
view = li.inflate(R.layout.messages_search_user_layout, viewGroup, false);
|
||||
} else {
|
||||
view = li.inflate(R.layout.messages_search_chat_layout, viewGroup, false);
|
||||
}
|
||||
}
|
||||
ContactListRowHolder holder = (ContactListRowHolder)view.getTag();
|
||||
if (holder == null) {
|
||||
holder = new ContactListRowHolder(view);
|
||||
view.setTag(holder);
|
||||
}
|
||||
View divider = view.findViewById(R.id.settings_row_divider);
|
||||
if (i == searchResult.size() - 1) {
|
||||
divider.setVisibility(View.INVISIBLE);
|
||||
} else {
|
||||
divider.setVisibility(View.VISIBLE);
|
||||
view = new ChatOrUserCell(mContext);
|
||||
((ChatOrUserCell)view).usePadding = false;
|
||||
}
|
||||
|
||||
((ChatOrUserCell) view).useSeparator = i != searchResult.size() - 1;
|
||||
|
||||
Object obj = searchResult.get(i);
|
||||
CharSequence name = searchResultNames.get(i);
|
||||
|
||||
TLRPC.User user = MessagesController.Instance.users.get(((TLRPC.User)obj).id);
|
||||
|
||||
holder.nameTextView.setText(name);
|
||||
|
||||
if (user != null) {
|
||||
((ChatOrUserCell)view).setData(user, null, null, searchResultNames.get(i), null);
|
||||
|
||||
if (ignoreUsers != null) {
|
||||
if (ignoreUsers.containsKey(user.id)) {
|
||||
if(android.os.Build.VERSION.SDK_INT >= 11) {
|
||||
holder.avatarImage.setAlpha(0.5f);
|
||||
holder.messageTextView.setAlpha(0.5f);
|
||||
holder.nameTextView.setAlpha(0.5f);
|
||||
}
|
||||
((ChatOrUserCell)view).drawAlpha = 0.5f;
|
||||
} else {
|
||||
if(android.os.Build.VERSION.SDK_INT >= 11) {
|
||||
holder.avatarImage.setAlpha(1.0f);
|
||||
holder.messageTextView.setAlpha(1.0f);
|
||||
holder.nameTextView.setAlpha(1.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
TLRPC.FileLocation photo = null;
|
||||
if (user.photo != null) {
|
||||
photo = user.photo.photo_small;
|
||||
}
|
||||
int placeHolderId = Utilities.getUserAvatarForId(user.id);
|
||||
holder.avatarImage.setImage(photo, "50_50", placeHolderId);
|
||||
|
||||
if (user.status == null) {
|
||||
holder.messageTextView.setTextColor(0xff808080);
|
||||
holder.messageTextView.setText(getStringEntry(R.string.Offline));
|
||||
} else {
|
||||
int currentTime = ConnectionsManager.Instance.getCurrentTime();
|
||||
if (user.status.expires > currentTime || user.status.was_online > currentTime) {
|
||||
holder.messageTextView.setTextColor(0xff357aa8);
|
||||
holder.messageTextView.setText(getStringEntry(R.string.Online));
|
||||
} else {
|
||||
if (user.status.was_online <= 10000 && user.status.expires <= 10000) {
|
||||
holder.messageTextView.setText(getStringEntry(R.string.Invisible));
|
||||
} else {
|
||||
int value = user.status.was_online;
|
||||
if (value == 0) {
|
||||
value = user.status.expires;
|
||||
}
|
||||
holder.messageTextView.setText(getStringEntry(R.string.LastSeen) + " " + Utilities.formatDateOnline(value));
|
||||
}
|
||||
holder.messageTextView.setTextColor(0xff808080);
|
||||
((ChatOrUserCell)view).drawAlpha = 1.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -697,17 +693,12 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
|
|||
|
||||
@Override
|
||||
public int getItemViewType(int i) {
|
||||
Object obj = searchResult.get(i);
|
||||
if (obj instanceof TLRPC.User) {
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getViewTypeCount() {
|
||||
return 2;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -737,12 +728,12 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
|
|||
public int getSectionCount() {
|
||||
int count = 0;
|
||||
if (usersAsSections) {
|
||||
count += MessagesController.Instance.sortedUsersSectionsArray.size();
|
||||
count += ContactsController.Instance.sortedUsersSectionsArray.size();
|
||||
} else {
|
||||
count++;
|
||||
}
|
||||
if (!onlyUsers) {
|
||||
count += MessagesController.Instance.sortedContactsSectionsArray.size();
|
||||
count += ContactsController.Instance.sortedContactsSectionsArray.size();
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
@ -750,16 +741,16 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
|
|||
@Override
|
||||
public int getCountForSection(int section) {
|
||||
if (usersAsSections) {
|
||||
if (section < MessagesController.Instance.sortedUsersSectionsArray.size()) {
|
||||
ArrayList<TLRPC.TL_contact> arr = MessagesController.Instance.usersSectionsDict.get(MessagesController.Instance.sortedUsersSectionsArray.get(section));
|
||||
if (section < ContactsController.Instance.sortedUsersSectionsArray.size()) {
|
||||
ArrayList<TLRPC.TL_contact> arr = ContactsController.Instance.usersSectionsDict.get(ContactsController.Instance.sortedUsersSectionsArray.get(section));
|
||||
return arr.size();
|
||||
}
|
||||
} else {
|
||||
if (section == 0) {
|
||||
return MessagesController.Instance.contacts.size() + 1;
|
||||
return ContactsController.Instance.contacts.size() + 1;
|
||||
}
|
||||
}
|
||||
ArrayList<MessagesController.Contact> arr = MessagesController.Instance.contactsSectionsDict.get(MessagesController.Instance.sortedContactsSectionsArray.get(section - 1));
|
||||
ArrayList<ContactsController.Contact> arr = ContactsController.Instance.contactsSectionsDict.get(ContactsController.Instance.sortedContactsSectionsArray.get(section - 1));
|
||||
return arr.size();
|
||||
}
|
||||
|
||||
|
@ -769,8 +760,8 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
|
|||
TLRPC.User user = null;
|
||||
int count = 0;
|
||||
if (usersAsSections) {
|
||||
if (section < MessagesController.Instance.sortedUsersSectionsArray.size()) {
|
||||
ArrayList<TLRPC.TL_contact> arr = MessagesController.Instance.usersSectionsDict.get(MessagesController.Instance.sortedUsersSectionsArray.get(section));
|
||||
if (section < ContactsController.Instance.sortedUsersSectionsArray.size()) {
|
||||
ArrayList<TLRPC.TL_contact> arr = ContactsController.Instance.usersSectionsDict.get(ContactsController.Instance.sortedUsersSectionsArray.get(section));
|
||||
user = MessagesController.Instance.users.get(arr.get(position).user_id);
|
||||
count = arr.size();
|
||||
}
|
||||
|
@ -782,86 +773,36 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
|
|||
convertView = li.inflate(R.layout.contacts_invite_row_layout, parent, false);
|
||||
}
|
||||
View divider = convertView.findViewById(R.id.settings_row_divider);
|
||||
if (MessagesController.Instance.contacts.isEmpty()) {
|
||||
if (ContactsController.Instance.contacts.isEmpty()) {
|
||||
divider.setVisibility(View.INVISIBLE);
|
||||
} else {
|
||||
divider.setVisibility(View.VISIBLE);
|
||||
}
|
||||
return convertView;
|
||||
}
|
||||
user = MessagesController.Instance.users.get(MessagesController.Instance.contacts.get(position - 1).user_id);
|
||||
count = MessagesController.Instance.contacts.size();
|
||||
user = MessagesController.Instance.users.get(ContactsController.Instance.contacts.get(position - 1).user_id);
|
||||
count = ContactsController.Instance.contacts.size();
|
||||
}
|
||||
}
|
||||
if (user != null) {
|
||||
if (convertView == null) {
|
||||
LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
convertView = li.inflate(R.layout.messages_search_user_layout, parent, false);
|
||||
}
|
||||
ContactListRowHolder holder = (ContactListRowHolder)convertView.getTag();
|
||||
if (holder == null) {
|
||||
holder = new ContactListRowHolder(convertView);
|
||||
convertView.setTag(holder);
|
||||
convertView = new ChatOrUserCell(mContext);
|
||||
((ChatOrUserCell)convertView).useBoldFont = true;
|
||||
((ChatOrUserCell)convertView).usePadding = false;
|
||||
}
|
||||
|
||||
((ChatOrUserCell)convertView).setData(user, null, null, null, null);
|
||||
|
||||
if (ignoreUsers != null) {
|
||||
if (ignoreUsers.containsKey(user.id)) {
|
||||
if(android.os.Build.VERSION.SDK_INT >= 11) {
|
||||
holder.avatarImage.setAlpha(0.5f);
|
||||
holder.messageTextView.setAlpha(0.5f);
|
||||
holder.nameTextView.setAlpha(0.5f);
|
||||
}
|
||||
((ChatOrUserCell)convertView).drawAlpha = 0.5f;
|
||||
} else {
|
||||
if(android.os.Build.VERSION.SDK_INT >= 11) {
|
||||
holder.avatarImage.setAlpha(1.0f);
|
||||
holder.messageTextView.setAlpha(1.0f);
|
||||
holder.nameTextView.setAlpha(1.0f);
|
||||
}
|
||||
((ChatOrUserCell)convertView).drawAlpha = 1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
View divider = convertView.findViewById(R.id.settings_row_divider);
|
||||
if (position == count - 1) {
|
||||
divider.setVisibility(View.INVISIBLE);
|
||||
} else {
|
||||
divider.setVisibility(View.VISIBLE);
|
||||
}
|
||||
((ChatOrUserCell) convertView).useSeparator = position != count - 1;
|
||||
|
||||
TLRPC.FileLocation photo = null;
|
||||
if (user.first_name.length() != 0 && user.last_name.length() != 0) {
|
||||
holder.nameTextView.setText(Html.fromHtml(user.first_name + " <b>" + user.last_name + "</b>"));
|
||||
} else if (user.first_name.length() != 0) {
|
||||
holder.nameTextView.setText(Html.fromHtml("<b>" + user.first_name + "</b>"));
|
||||
} else {
|
||||
holder.nameTextView.setText(Html.fromHtml("<b>" + user.last_name + "</b>"));
|
||||
}
|
||||
if (user.photo != null) {
|
||||
photo = user.photo.photo_small;
|
||||
}
|
||||
int placeHolderId = Utilities.getUserAvatarForId(user.id);
|
||||
holder.avatarImage.setImage(photo, "50_50", placeHolderId);
|
||||
|
||||
if (user.status == null) {
|
||||
holder.messageTextView.setText(getStringEntry(R.string.Offline));
|
||||
holder.messageTextView.setTextColor(0xff808080);
|
||||
} else {
|
||||
int currentTime = ConnectionsManager.Instance.getCurrentTime();
|
||||
if (user.status.expires > currentTime || user.status.was_online > currentTime) {
|
||||
holder.messageTextView.setTextColor(0xff357aa8);
|
||||
holder.messageTextView.setText(getStringEntry(R.string.Online));
|
||||
} else {
|
||||
if (user.status.was_online <= 10000 && user.status.expires <= 10000) {
|
||||
holder.messageTextView.setText(getStringEntry(R.string.Invisible));
|
||||
} else {
|
||||
int value = user.status.was_online;
|
||||
if (value == 0) {
|
||||
value = user.status.expires;
|
||||
}
|
||||
holder.messageTextView.setText(getStringEntry(R.string.LastSeen) + " " + Utilities.formatDateOnline(value));
|
||||
}
|
||||
holder.messageTextView.setTextColor(0xff808080);
|
||||
}
|
||||
}
|
||||
return convertView;
|
||||
}
|
||||
|
||||
|
@ -873,13 +814,16 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
|
|||
} else {
|
||||
textView = (TextView)convertView.findViewById(R.id.settings_row_text);
|
||||
}
|
||||
|
||||
View divider = convertView.findViewById(R.id.settings_row_divider);
|
||||
ArrayList<MessagesController.Contact> arr = MessagesController.Instance.contactsSectionsDict.get(MessagesController.Instance.sortedContactsSectionsArray.get(section - 1));
|
||||
MessagesController.Contact contact = arr.get(position);
|
||||
if (position == arr.size() - 1) {
|
||||
divider.setVisibility(View.INVISIBLE);
|
||||
} else {
|
||||
divider.setVisibility(View.VISIBLE);
|
||||
ArrayList<ContactsController.Contact> arr = ContactsController.Instance.contactsSectionsDict.get(ContactsController.Instance.sortedContactsSectionsArray.get(section - 1));
|
||||
ContactsController.Contact contact = arr.get(position);
|
||||
if (divider != null) {
|
||||
if (position == arr.size() - 1) {
|
||||
divider.setVisibility(View.INVISIBLE);
|
||||
} else {
|
||||
divider.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
if (contact.first_name != null && contact.last_name != null) {
|
||||
textView.setText(Html.fromHtml(contact.first_name + " <b>" + contact.last_name + "</b>"));
|
||||
|
@ -894,7 +838,7 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
|
|||
@Override
|
||||
public int getItemViewType(int section, int position) {
|
||||
if (usersAsSections) {
|
||||
if (section < MessagesController.Instance.sortedUsersSectionsArray.size()) {
|
||||
if (section < ContactsController.Instance.sortedUsersSectionsArray.size()) {
|
||||
return 0;
|
||||
}
|
||||
} else if (section == 0) {
|
||||
|
@ -914,7 +858,7 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
|
|||
@Override
|
||||
public int getSectionHeaderViewType(int section) {
|
||||
if (usersAsSections) {
|
||||
if (section < MessagesController.Instance.sortedUsersSectionsArray.size()) {
|
||||
if (section < ContactsController.Instance.sortedUsersSectionsArray.size()) {
|
||||
return 1;
|
||||
}
|
||||
} else if (section == 0) {
|
||||
|
@ -931,14 +875,14 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
|
|||
@Override
|
||||
public View getSectionHeaderView(int section, View convertView, ViewGroup parent) {
|
||||
if (usersAsSections) {
|
||||
if (section < MessagesController.Instance.sortedUsersSectionsArray.size()) {
|
||||
if (section < ContactsController.Instance.sortedUsersSectionsArray.size()) {
|
||||
if (convertView == null) {
|
||||
LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
convertView = li.inflate(R.layout.settings_section_layout, parent, false);
|
||||
convertView.setBackgroundColor(0xffffffff);
|
||||
}
|
||||
TextView textView = (TextView)convertView.findViewById(R.id.settings_section_text);
|
||||
textView.setText(MessagesController.Instance.sortedUsersSectionsArray.get(section));
|
||||
textView.setText(ContactsController.Instance.sortedUsersSectionsArray.get(section));
|
||||
return convertView;
|
||||
}
|
||||
} else {
|
||||
|
@ -957,20 +901,8 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
|
|||
convertView.setBackgroundColor(0xffffffff);
|
||||
}
|
||||
TextView textView = (TextView)convertView.findViewById(R.id.settings_section_text);
|
||||
textView.setText(MessagesController.Instance.sortedContactsSectionsArray.get(section - 1));
|
||||
textView.setText(ContactsController.Instance.sortedContactsSectionsArray.get(section - 1));
|
||||
return convertView;
|
||||
}
|
||||
}
|
||||
|
||||
public static class ContactListRowHolder {
|
||||
public BackupImageView avatarImage;
|
||||
public TextView messageTextView;
|
||||
public TextView nameTextView;
|
||||
|
||||
public ContactListRowHolder(View view) {
|
||||
messageTextView = (TextView)view.findViewById(R.id.messages_list_row_message);
|
||||
nameTextView = (TextView)view.findViewById(R.id.messages_list_row_name);
|
||||
avatarImage = (BackupImageView)view.findViewById(R.id.messages_list_row_avatar);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,7 +41,6 @@ import java.util.ArrayList;
|
|||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
|
@ -54,7 +53,6 @@ public class CountrySelectActivity extends ActionBarActivity {
|
|||
private boolean searching;
|
||||
private BaseAdapter searchListViewAdapter;
|
||||
private TextView epmtyTextView;
|
||||
private boolean isRTL;
|
||||
private HashMap<String, ArrayList<Country>> countries = new HashMap<String, ArrayList<Country>>();
|
||||
private ArrayList<String> sortedCountries = new ArrayList<String>();
|
||||
|
||||
|
@ -71,10 +69,6 @@ public class CountrySelectActivity extends ActionBarActivity {
|
|||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
Locale locale = Locale.getDefault();
|
||||
String lang = locale.getLanguage();
|
||||
isRTL = lang != null && lang.toLowerCase().equals("ar");
|
||||
|
||||
try {
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(getResources().getAssets().open("countries.txt")));
|
||||
String line;
|
||||
|
@ -260,7 +254,7 @@ public class CountrySelectActivity extends ActionBarActivity {
|
|||
searchWas = false;
|
||||
ViewGroup group = (ViewGroup) listView.getParent();
|
||||
listView.setAdapter(listViewAdapter);
|
||||
if (!isRTL) {
|
||||
if (!Utilities.isRTL) {
|
||||
listView.setPadding(Utilities.dp(16), listView.getPaddingTop(), Utilities.dp(30), listView.getPaddingBottom());
|
||||
} else {
|
||||
listView.setPadding(Utilities.dp(30), listView.getPaddingTop(), Utilities.dp(16), listView.getPaddingBottom());
|
||||
|
|
|
@ -102,8 +102,12 @@ public class DocumentSelectActivity extends BaseFragment {
|
|||
|
||||
@Override
|
||||
public void onFragmentDestroy() {
|
||||
if (receiverRegistered) {
|
||||
parentActivity.unregisterReceiver(receiver);
|
||||
try {
|
||||
if (receiverRegistered) {
|
||||
parentActivity.unregisterReceiver(receiver);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
super.onFragmentDestroy();
|
||||
}
|
||||
|
@ -376,13 +380,17 @@ public class DocumentSelectActivity extends BaseFragment {
|
|||
if (extDevice != null) {
|
||||
result.removeAll(aliases.get(extDevice));
|
||||
for (String path : result) {
|
||||
boolean isSd = path.toLowerCase().contains("sd");
|
||||
ListItem item = new ListItem();
|
||||
item.title = getString(isSd ? R.string.SdCard : R.string.ExternalStorage);
|
||||
item.icon = R.drawable.ic_external_storage;
|
||||
item.subtitle = getRootSubtitle(path);
|
||||
item.file = new File(path);
|
||||
items.add(item);
|
||||
try {
|
||||
boolean isSd = path.toLowerCase().contains("sd");
|
||||
ListItem item = new ListItem();
|
||||
item.title = getString(isSd ? R.string.SdCard : R.string.ExternalStorage);
|
||||
item.icon = R.drawable.ic_external_storage;
|
||||
item.subtitle = getRootSubtitle(path);
|
||||
item.file = new File(path);
|
||||
items.add(item);
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
|
|
@ -9,12 +9,14 @@
|
|||
package org.telegram.ui;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.graphics.Point;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcelable;
|
||||
import android.support.v4.view.PagerAdapter;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.view.Display;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
|
@ -64,6 +66,8 @@ public class GalleryImageViewer extends AbstractGalleryActivity implements Notif
|
|||
private ProgressBar loadingProgress;
|
||||
private String currentFileName;
|
||||
private int user_id = 0;
|
||||
private Point displaySize = new Point();
|
||||
private boolean cancelRunning = false;
|
||||
|
||||
private ArrayList<MessageObject> imagesArrTemp = new ArrayList<MessageObject>();
|
||||
private HashMap<Integer, MessageObject> imagesByIdsTemp = new HashMap<Integer, MessageObject>();
|
||||
|
@ -80,6 +84,14 @@ public class GalleryImageViewer extends AbstractGalleryActivity implements Notif
|
|||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
Display display = getWindowManager().getDefaultDisplay();
|
||||
if(android.os.Build.VERSION.SDK_INT < 13) {
|
||||
displaySize.set(display.getWidth(), display.getHeight());
|
||||
} else {
|
||||
display.getSize(displaySize);
|
||||
}
|
||||
|
||||
classGuid = ConnectionsManager.Instance.generateClassGuid();
|
||||
setContentView(R.layout.gallery_layout);
|
||||
|
||||
|
@ -112,6 +124,7 @@ public class GalleryImageViewer extends AbstractGalleryActivity implements Notif
|
|||
NotificationCenter.Instance.addObserver(this, MessagesController.mediaCountDidLoaded);
|
||||
NotificationCenter.Instance.addObserver(this, MessagesController.mediaDidLoaded);
|
||||
NotificationCenter.Instance.addObserver(this, MessagesController.userPhotosLoaded);
|
||||
NotificationCenter.Instance.addObserver(this, 658);
|
||||
|
||||
Integer index = null;
|
||||
if (localPagerAdapter == null) {
|
||||
|
@ -212,6 +225,9 @@ public class GalleryImageViewer extends AbstractGalleryActivity implements Notif
|
|||
deleteButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (mViewPager == null || localPagerAdapter == null || localPagerAdapter.imagesArr == null) {
|
||||
return;
|
||||
}
|
||||
int item = mViewPager.getCurrentItem();
|
||||
MessageObject obj = localPagerAdapter.imagesArr.get(item);
|
||||
if (obj.messageOwner.send_state == MessagesController.MESSAGE_SEND_STATE_SENT) {
|
||||
|
@ -241,6 +257,7 @@ public class GalleryImageViewer extends AbstractGalleryActivity implements Notif
|
|||
NotificationCenter.Instance.removeObserver(this, MessagesController.mediaCountDidLoaded);
|
||||
NotificationCenter.Instance.removeObserver(this, MessagesController.mediaDidLoaded);
|
||||
NotificationCenter.Instance.removeObserver(this, MessagesController.userPhotosLoaded);
|
||||
NotificationCenter.Instance.removeObserver(this, 658);
|
||||
ConnectionsManager.Instance.cancelRpcsForClassGuid(classGuid);
|
||||
}
|
||||
|
||||
|
@ -354,7 +371,7 @@ public class GalleryImageViewer extends AbstractGalleryActivity implements Notif
|
|||
getSupportActionBar().setTitle(String.format("%d %s %d", pos, getString(R.string.Of), totalCount));
|
||||
if (title != null) {
|
||||
fakeTitleView.setText(String.format("%d %s %d", pos, getString(R.string.Of), totalCount));
|
||||
fakeTitleView.measure(View.MeasureSpec.makeMeasureSpec(400, View.MeasureSpec.AT_MOST), 40);
|
||||
fakeTitleView.measure(View.MeasureSpec.makeMeasureSpec(400, View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(100, View.MeasureSpec.AT_MOST));
|
||||
title.setWidth(fakeTitleView.getMeasuredWidth() + Utilities.dp(8));
|
||||
title.setMaxWidth(fakeTitleView.getMeasuredWidth() + Utilities.dp(8));
|
||||
}
|
||||
|
@ -450,10 +467,21 @@ public class GalleryImageViewer extends AbstractGalleryActivity implements Notif
|
|||
}
|
||||
}
|
||||
}
|
||||
} else if (id == 658) {
|
||||
try {
|
||||
if (!isFinishing()) {
|
||||
finish();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private TLRPC.FileLocation getCurrentFile() {
|
||||
if (mViewPager == null) {
|
||||
return null;
|
||||
}
|
||||
int item = mViewPager.getCurrentItem();
|
||||
if (withoutBottom) {
|
||||
return localPagerAdapter.imagesArrLocations.get(item);
|
||||
|
@ -618,9 +646,20 @@ public class GalleryImageViewer extends AbstractGalleryActivity implements Notif
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
super.onBackPressed();
|
||||
cancelRunning = true;
|
||||
mViewPager.setAdapter(null);
|
||||
localPagerAdapter = null;
|
||||
finish();
|
||||
System.gc();
|
||||
}
|
||||
|
||||
private void processSelectedMenu(int itemId) {
|
||||
switch (itemId) {
|
||||
case android.R.id.home:
|
||||
cancelRunning = true;
|
||||
mViewPager.setAdapter(null);
|
||||
localPagerAdapter = null;
|
||||
finish();
|
||||
|
@ -775,7 +814,7 @@ public class GalleryImageViewer extends AbstractGalleryActivity implements Notif
|
|||
getSupportActionBar().setTitle(String.format("%d %s %d", (totalCount - imagesArr.size()) + position + 1, getString(R.string.Of), totalCount));
|
||||
if (title != null) {
|
||||
fakeTitleView.setText(String.format("%d %s %d", (totalCount - imagesArr.size()) + position + 1, getString(R.string.Of), totalCount));
|
||||
fakeTitleView.measure(View.MeasureSpec.makeMeasureSpec(400, View.MeasureSpec.AT_MOST), 40);
|
||||
fakeTitleView.measure(View.MeasureSpec.makeMeasureSpec(400, View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(100, View.MeasureSpec.AT_MOST));
|
||||
title.setWidth(fakeTitleView.getMeasuredWidth() + Utilities.dp(8));
|
||||
title.setMaxWidth(fakeTitleView.getMeasuredWidth() + Utilities.dp(8));
|
||||
}
|
||||
|
@ -794,7 +833,7 @@ public class GalleryImageViewer extends AbstractGalleryActivity implements Notif
|
|||
getSupportActionBar().setTitle(String.format("%d %s %d", position + 1, getString(R.string.Of), imagesArrLocations.size()));
|
||||
if (title != null) {
|
||||
fakeTitleView.setText(String.format("%d %s %d", position + 1, getString(R.string.Of), imagesArrLocations.size()));
|
||||
fakeTitleView.measure(View.MeasureSpec.makeMeasureSpec(400, View.MeasureSpec.AT_MOST), 40);
|
||||
fakeTitleView.measure(View.MeasureSpec.makeMeasureSpec(400, View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(100, View.MeasureSpec.AT_MOST));
|
||||
title.setWidth(fakeTitleView.getMeasuredWidth() + Utilities.dp(8));
|
||||
title.setMaxWidth(fakeTitleView.getMeasuredWidth() + Utilities.dp(8));
|
||||
}
|
||||
|
@ -885,7 +924,16 @@ public class GalleryImageViewer extends AbstractGalleryActivity implements Notif
|
|||
ArrayList<TLRPC.PhotoSize> sizes = message.messageOwner.media.photo.sizes;
|
||||
iv.isVideo = false;
|
||||
if (sizes.size() > 0) {
|
||||
TLRPC.PhotoSize sizeFull = PhotoObject.getClosestPhotoSizeWithSize(sizes, 800, 800);
|
||||
int width = (int)(Math.min(displaySize.x, displaySize.y) * 0.7f);
|
||||
int height = width + Utilities.dp(100);
|
||||
if (width > 800) {
|
||||
width = 800;
|
||||
}
|
||||
if (height > 800) {
|
||||
height = 800;
|
||||
}
|
||||
|
||||
TLRPC.PhotoSize sizeFull = PhotoObject.getClosestPhotoSizeWithSize(sizes, width, height);
|
||||
if (message.imagePreview != null) {
|
||||
iv.setImage(sizeFull.location, null, message.imagePreview, sizeFull.size);
|
||||
} else {
|
||||
|
@ -922,9 +970,9 @@ public class GalleryImageViewer extends AbstractGalleryActivity implements Notif
|
|||
}
|
||||
if (loadFile) {
|
||||
if (!FileLoader.Instance.isLoadingFile(fileName)) {
|
||||
FileLoader.Instance.loadFile(message.messageOwner.media.video, null, null);
|
||||
FileLoader.Instance.loadFile(message.messageOwner.media.video, null, null, null);
|
||||
} else {
|
||||
FileLoader.Instance.cancelLoadFile(message.messageOwner.media.video, null, null);
|
||||
FileLoader.Instance.cancelLoadFile(message.messageOwner.media.video, null, null, null);
|
||||
}
|
||||
checkCurrentFile();
|
||||
processViews(playButton, message);
|
||||
|
@ -952,7 +1000,9 @@ public class GalleryImageViewer extends AbstractGalleryActivity implements Notif
|
|||
public void destroyItem(View collection, int position, Object view) {
|
||||
((ViewPager)collection).removeView((View)view);
|
||||
PZSImageView iv = (PZSImageView)((View)view).findViewById(R.id.page_image);
|
||||
FileLoader.Instance.cancelLoadingForImageView(iv);
|
||||
if (cancelRunning) {
|
||||
FileLoader.Instance.cancelLoadingForImageView(iv);
|
||||
}
|
||||
iv.clearImage();
|
||||
}
|
||||
|
||||
|
|
|
@ -37,6 +37,7 @@ import android.widget.TextView;
|
|||
|
||||
import org.telegram.TL.TLRPC;
|
||||
import org.telegram.messenger.ConnectionsManager;
|
||||
import org.telegram.messenger.ContactsController;
|
||||
import org.telegram.messenger.Emoji;
|
||||
import org.telegram.messenger.FileLog;
|
||||
import org.telegram.messenger.MessagesController;
|
||||
|
@ -44,6 +45,7 @@ import org.telegram.messenger.NotificationCenter;
|
|||
import org.telegram.messenger.R;
|
||||
import org.telegram.messenger.UserConfig;
|
||||
import org.telegram.messenger.Utilities;
|
||||
import org.telegram.ui.Views.BackupImageView;
|
||||
import org.telegram.ui.Views.BaseFragment;
|
||||
import org.telegram.ui.Views.PinnedHeaderListView;
|
||||
import org.telegram.ui.Views.SectionedBaseAdapter;
|
||||
|
@ -198,7 +200,7 @@ public class GroupCreateActivity extends BaseFragment implements NotificationCen
|
|||
if (searching && searchWas) {
|
||||
user = searchResult.get(row);
|
||||
} else {
|
||||
ArrayList<TLRPC.TL_contact> arr = MessagesController.Instance.usersSectionsDict.get(MessagesController.Instance.sortedUsersSectionsArray.get(section));
|
||||
ArrayList<TLRPC.TL_contact> arr = ContactsController.Instance.usersSectionsDict.get(ContactsController.Instance.sortedUsersSectionsArray.get(section));
|
||||
user = MessagesController.Instance.users.get(arr.get(row).user_id);
|
||||
listView.invalidateViews();
|
||||
}
|
||||
|
@ -367,7 +369,7 @@ public class GroupCreateActivity extends BaseFragment implements NotificationCen
|
|||
ArrayList<CharSequence> resultArrayNames = new ArrayList<CharSequence>();
|
||||
String q = query.toLowerCase();
|
||||
|
||||
for (TLRPC.TL_contact contact : MessagesController.Instance.contacts) {
|
||||
for (TLRPC.TL_contact contact : ContactsController.Instance.contacts) {
|
||||
TLRPC.User user = MessagesController.Instance.users.get(contact.user_id);
|
||||
if (user.first_name.toLowerCase().startsWith(q) || user.last_name.toLowerCase().startsWith(q)) {
|
||||
if (user.id == UserConfig.clientUserId) {
|
||||
|
@ -432,8 +434,11 @@ public class GroupCreateActivity extends BaseFragment implements NotificationCen
|
|||
listViewAdapter.notifyDataSetChanged();
|
||||
}
|
||||
} else if (id == MessagesController.updateInterfaces) {
|
||||
if (listView != null) {
|
||||
listView.invalidateViews();
|
||||
int mask = (Integer)args[0];
|
||||
if ((mask & MessagesController.UPDATE_MASK_AVATAR) != 0 || (mask & MessagesController.UPDATE_MASK_NAME) != 0 || (mask & MessagesController.UPDATE_MASK_STATUS) != 0) {
|
||||
if (listView != null) {
|
||||
listView.invalidateViews();
|
||||
}
|
||||
}
|
||||
} else if (id == MessagesController.chatDidCreated) {
|
||||
Utilities.RunOnUIThread(new Runnable() {
|
||||
|
@ -467,7 +472,7 @@ public class GroupCreateActivity extends BaseFragment implements NotificationCen
|
|||
if (searching && searchWas) {
|
||||
return searchResult == null || searchResult.isEmpty() ? 0 : 1;
|
||||
}
|
||||
return MessagesController.Instance.sortedUsersSectionsArray.size();
|
||||
return ContactsController.Instance.sortedUsersSectionsArray.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -475,7 +480,7 @@ public class GroupCreateActivity extends BaseFragment implements NotificationCen
|
|||
if (searching && searchWas) {
|
||||
return searchResult == null ? 0 : searchResult.size();
|
||||
}
|
||||
ArrayList<TLRPC.TL_contact> arr = MessagesController.Instance.usersSectionsDict.get(MessagesController.Instance.sortedUsersSectionsArray.get(section));
|
||||
ArrayList<TLRPC.TL_contact> arr = ContactsController.Instance.usersSectionsDict.get(ContactsController.Instance.sortedUsersSectionsArray.get(section));
|
||||
return arr.size();
|
||||
}
|
||||
|
||||
|
@ -488,7 +493,7 @@ public class GroupCreateActivity extends BaseFragment implements NotificationCen
|
|||
user = MessagesController.Instance.users.get(searchResult.get(position).id);
|
||||
size = searchResult.size();
|
||||
} else {
|
||||
ArrayList<TLRPC.TL_contact> arr = MessagesController.Instance.usersSectionsDict.get(MessagesController.Instance.sortedUsersSectionsArray.get(section));
|
||||
ArrayList<TLRPC.TL_contact> arr = ContactsController.Instance.usersSectionsDict.get(ContactsController.Instance.sortedUsersSectionsArray.get(section));
|
||||
user = MessagesController.Instance.users.get(arr.get(position).user_id);
|
||||
size = arr.size();
|
||||
}
|
||||
|
@ -497,9 +502,9 @@ public class GroupCreateActivity extends BaseFragment implements NotificationCen
|
|||
LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
convertView = li.inflate(R.layout.group_create_row_layout, parent, false);
|
||||
}
|
||||
ContactsActivity.ContactListRowHolder holder = (ContactsActivity.ContactListRowHolder)convertView.getTag();
|
||||
ContactListRowHolder holder = (ContactListRowHolder)convertView.getTag();
|
||||
if (holder == null) {
|
||||
holder = new ContactsActivity.ContactListRowHolder(convertView);
|
||||
holder = new ContactListRowHolder(convertView);
|
||||
convertView.setTag(holder);
|
||||
}
|
||||
|
||||
|
@ -552,7 +557,7 @@ public class GroupCreateActivity extends BaseFragment implements NotificationCen
|
|||
if (value == 0) {
|
||||
value = user.status.expires;
|
||||
}
|
||||
holder.messageTextView.setText(getStringEntry(R.string.LastSeen) + " " + Utilities.formatDateOnline(value));
|
||||
holder.messageTextView.setText(Utilities.formatDateOnline(value));
|
||||
}
|
||||
holder.messageTextView.setTextColor(0xff808080);
|
||||
}
|
||||
|
@ -592,9 +597,21 @@ public class GroupCreateActivity extends BaseFragment implements NotificationCen
|
|||
if (searching && searchWas) {
|
||||
textView.setText(getStringEntry(R.string.AllContacts));
|
||||
} else {
|
||||
textView.setText(MessagesController.Instance.sortedUsersSectionsArray.get(section));
|
||||
textView.setText(ContactsController.Instance.sortedUsersSectionsArray.get(section));
|
||||
}
|
||||
return convertView;
|
||||
}
|
||||
}
|
||||
|
||||
public static class ContactListRowHolder {
|
||||
public BackupImageView avatarImage;
|
||||
public TextView messageTextView;
|
||||
public TextView nameTextView;
|
||||
|
||||
public ContactListRowHolder(View view) {
|
||||
messageTextView = (TextView)view.findViewById(R.id.messages_list_row_message);
|
||||
nameTextView = (TextView)view.findViewById(R.id.messages_list_row_name);
|
||||
avatarImage = (BackupImageView)view.findViewById(R.id.messages_list_row_avatar);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,6 @@ import android.content.Intent;
|
|||
import android.os.Bundle;
|
||||
import android.support.v4.internal.view.SupportMenuItem;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.text.Html;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
|
@ -27,12 +26,12 @@ import android.widget.ImageButton;
|
|||
import android.widget.TextView;
|
||||
|
||||
import org.telegram.TL.TLRPC;
|
||||
import org.telegram.messenger.ConnectionsManager;
|
||||
import org.telegram.messenger.FileLog;
|
||||
import org.telegram.messenger.MessagesController;
|
||||
import org.telegram.messenger.NotificationCenter;
|
||||
import org.telegram.messenger.R;
|
||||
import org.telegram.messenger.Utilities;
|
||||
import org.telegram.ui.Cells.ChatOrUserCell;
|
||||
import org.telegram.ui.Views.AvatarUpdater;
|
||||
import org.telegram.ui.Views.BackupImageView;
|
||||
import org.telegram.ui.Views.BaseFragment;
|
||||
|
@ -228,8 +227,9 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati
|
|||
@Override
|
||||
public void didReceivedNotification(int id, final Object... args) {
|
||||
if (id == MessagesController.updateInterfaces) {
|
||||
if (listView != null) {
|
||||
listView.invalidateViews();
|
||||
int mask = (Integer)args[0];
|
||||
if ((mask & MessagesController.UPDATE_MASK_AVATAR) != 0 || (mask & MessagesController.UPDATE_MASK_NAME) != 0 || (mask & MessagesController.UPDATE_MASK_STATUS) != 0) {
|
||||
updateVisibleRows(mask);
|
||||
}
|
||||
} else if (id == MessagesController.chatDidFailCreate) {
|
||||
Utilities.HideProgressDialog(parentActivity);
|
||||
|
@ -250,6 +250,19 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati
|
|||
}
|
||||
}
|
||||
|
||||
private void updateVisibleRows(int mask) {
|
||||
if (listView == null) {
|
||||
return;
|
||||
}
|
||||
int count = listView.getChildCount();
|
||||
for (int a = 0; a < count; a++) {
|
||||
View child = listView.getChildAt(a);
|
||||
if (child instanceof ChatOrUserCell) {
|
||||
((ChatOrUserCell) child).update(mask);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class ListAdapter extends SectionedBaseAdapter {
|
||||
private Context mContext;
|
||||
|
||||
|
@ -295,58 +308,13 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati
|
|||
TLRPC.User user = MessagesController.Instance.users.get(selectedContacts.get(position));
|
||||
|
||||
if (convertView == null) {
|
||||
LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
convertView = li.inflate(R.layout.messages_search_user_layout, parent, false);
|
||||
}
|
||||
ContactsActivity.ContactListRowHolder holder = (ContactsActivity.ContactListRowHolder)convertView.getTag();
|
||||
if (holder == null) {
|
||||
holder = new ContactsActivity.ContactListRowHolder(convertView);
|
||||
convertView.setTag(holder);
|
||||
convertView = new ChatOrUserCell(mContext);
|
||||
((ChatOrUserCell)convertView).useBoldFont = true;
|
||||
((ChatOrUserCell)convertView).usePadding = false;
|
||||
}
|
||||
|
||||
View divider = convertView.findViewById(R.id.settings_row_divider);
|
||||
if (position == selectedContacts.size() - 1) {
|
||||
divider.setVisibility(View.INVISIBLE);
|
||||
} else {
|
||||
divider.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
if (user.first_name.length() != 0 && user.last_name.length() != 0) {
|
||||
holder.nameTextView.setText(Html.fromHtml(user.first_name + " <b>" + user.last_name + "</b>"));
|
||||
} else if (user.first_name.length() != 0) {
|
||||
holder.nameTextView.setText(Html.fromHtml("<b>" + user.first_name + "</b>"));
|
||||
} else {
|
||||
holder.nameTextView.setText(Html.fromHtml("<b>" + user.last_name + "</b>"));
|
||||
}
|
||||
|
||||
TLRPC.FileLocation photo = null;
|
||||
if (user.photo != null) {
|
||||
photo = user.photo.photo_small;
|
||||
}
|
||||
int placeHolderId = Utilities.getUserAvatarForId(user.id);
|
||||
holder.avatarImage.setImage(photo, "50_50", placeHolderId);
|
||||
|
||||
if (user.status == null) {
|
||||
holder.messageTextView.setTextColor(0xff808080);
|
||||
holder.messageTextView.setText(getStringEntry(R.string.Offline));
|
||||
} else {
|
||||
int currentTime = ConnectionsManager.Instance.getCurrentTime();
|
||||
if (user.status.expires > currentTime || user.status.was_online > currentTime) {
|
||||
holder.messageTextView.setTextColor(0xff357aa8);
|
||||
holder.messageTextView.setText(getStringEntry(R.string.Online));
|
||||
} else {
|
||||
if (user.status.was_online <= 10000 && user.status.expires <= 10000) {
|
||||
holder.messageTextView.setText(getStringEntry(R.string.Invisible));
|
||||
} else {
|
||||
int value = user.status.was_online;
|
||||
if (value == 0) {
|
||||
value = user.status.expires;
|
||||
}
|
||||
holder.messageTextView.setText(getStringEntry(R.string.LastSeen) + " " + Utilities.formatDateOnline(value));
|
||||
}
|
||||
holder.messageTextView.setTextColor(0xff808080);
|
||||
}
|
||||
}
|
||||
((ChatOrUserCell)convertView).setData(user, null, null, null, null);
|
||||
((ChatOrUserCell) convertView).useSeparator = position != selectedContacts.size() - 1;
|
||||
|
||||
return convertView;
|
||||
}
|
||||
|
|
|
@ -23,8 +23,7 @@ import android.widget.ImageView;
|
|||
import android.widget.TextView;
|
||||
|
||||
import org.telegram.messenger.R;
|
||||
|
||||
import java.util.Locale;
|
||||
import org.telegram.messenger.Utilities;
|
||||
|
||||
public class IntroActivity extends ActionBarActivity {
|
||||
private ViewPager viewPager;
|
||||
|
@ -32,7 +31,6 @@ public class IntroActivity extends ActionBarActivity {
|
|||
private ImageView topImage2;
|
||||
private ViewGroup bottomPages;
|
||||
private int lastPage = 0;
|
||||
private boolean isRTL = false;
|
||||
private boolean justCreated = false;
|
||||
private boolean startPressed = false;
|
||||
private int[] icons;
|
||||
|
@ -45,10 +43,7 @@ public class IntroActivity extends ActionBarActivity {
|
|||
|
||||
setContentView(R.layout.intro_layout);
|
||||
|
||||
Locale locale = Locale.getDefault();
|
||||
String lang = locale.getLanguage();
|
||||
if (lang != null && lang.toLowerCase().equals("ar")) {
|
||||
isRTL = true;
|
||||
if (Utilities.isRTL) {
|
||||
icons = new int[] {
|
||||
R.drawable.intro7,
|
||||
R.drawable.intro6,
|
||||
|
@ -212,7 +207,7 @@ public class IntroActivity extends ActionBarActivity {
|
|||
protected void onResume() {
|
||||
super.onResume();
|
||||
if (justCreated) {
|
||||
if (isRTL) {
|
||||
if (Utilities.isRTL) {
|
||||
viewPager.setCurrentItem(6);
|
||||
lastPage = 6;
|
||||
} else {
|
||||
|
|
|
@ -14,6 +14,7 @@ import android.content.Intent;
|
|||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import org.telegram.TL.TLRPC;
|
||||
import org.telegram.messenger.FileLog;
|
||||
|
@ -21,6 +22,7 @@ import org.telegram.messenger.MessagesController;
|
|||
import org.telegram.messenger.NotificationCenter;
|
||||
import org.telegram.messenger.R;
|
||||
import org.telegram.messenger.UserConfig;
|
||||
import org.telegram.messenger.Utilities;
|
||||
import org.telegram.ui.Views.PausableActivity;
|
||||
|
||||
public class LaunchActivity extends PausableActivity {
|
||||
|
@ -46,13 +48,22 @@ public class LaunchActivity extends PausableActivity {
|
|||
if (Intent.ACTION_SEND.equals(intent.getAction())) {
|
||||
if (intent.getType() != null) {
|
||||
if (intent.getType().startsWith("image/")) {
|
||||
String path = intent.getParcelableExtra(Intent.EXTRA_STREAM).toString();
|
||||
if (path.startsWith("content:")) {
|
||||
Cursor cursor = getContentResolver().query(Uri.parse(path), new String[]{android.provider.MediaStore.Images.ImageColumns.DATA}, null, null, null);
|
||||
if (cursor != null) {
|
||||
cursor.moveToFirst();
|
||||
path = cursor.getString(0);
|
||||
cursor.close();
|
||||
Parcelable parcelable = intent.getParcelableExtra(Intent.EXTRA_STREAM);
|
||||
if (parcelable == null) {
|
||||
return;
|
||||
}
|
||||
String path = null;
|
||||
if (parcelable instanceof Uri) {
|
||||
path = Utilities.getPath((Uri)parcelable);
|
||||
} else {
|
||||
path = intent.getParcelableExtra(Intent.EXTRA_STREAM).toString();
|
||||
if (path.startsWith("content:")) {
|
||||
Cursor cursor = getContentResolver().query(Uri.parse(path), new String[]{android.provider.MediaStore.Images.ImageColumns.DATA}, null, null, null);
|
||||
if (cursor != null) {
|
||||
cursor.moveToFirst();
|
||||
path = cursor.getString(0);
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (path != null) {
|
||||
|
@ -62,13 +73,22 @@ public class LaunchActivity extends PausableActivity {
|
|||
NotificationCenter.Instance.addToMemCache(533, path);
|
||||
}
|
||||
} else if (intent.getType().startsWith("video/")) {
|
||||
String path = intent.getParcelableExtra(Intent.EXTRA_STREAM).toString();
|
||||
if (path.startsWith("content:")) {
|
||||
Cursor cursor = getContentResolver().query(Uri.parse(path), new String[]{android.provider.MediaStore.Images.ImageColumns.DATA}, null, null, null);
|
||||
if (cursor != null) {
|
||||
cursor.moveToFirst();
|
||||
path = cursor.getString(0);
|
||||
cursor.close();
|
||||
Parcelable parcelable = intent.getParcelableExtra(Intent.EXTRA_STREAM);
|
||||
if (parcelable == null) {
|
||||
return;
|
||||
}
|
||||
String path = null;
|
||||
if (parcelable instanceof Uri) {
|
||||
path = Utilities.getPath((Uri)parcelable);
|
||||
} else {
|
||||
path = parcelable.toString();
|
||||
if (path.startsWith("content:")) {
|
||||
Cursor cursor = getContentResolver().query(Uri.parse(path), new String[]{android.provider.MediaStore.Images.ImageColumns.DATA}, null, null, null);
|
||||
if (cursor != null) {
|
||||
cursor.moveToFirst();
|
||||
path = cursor.getString(0);
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (path != null) {
|
||||
|
@ -79,17 +99,24 @@ public class LaunchActivity extends PausableActivity {
|
|||
}
|
||||
} else if (intent.getType().equals("text/plain")) {
|
||||
String text = intent.getStringExtra(Intent.EXTRA_TEXT);
|
||||
if (text.length() != 0) {
|
||||
if (text != null && text.length() != 0) {
|
||||
NotificationCenter.Instance.addToMemCache(535, text);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (Intent.ACTION_VIEW.equals(intent.getAction())) {
|
||||
Cursor cursor = getContentResolver().query(intent.getData(), null, null, null, null);
|
||||
if (cursor.moveToFirst()) {
|
||||
int userId = cursor.getInt(cursor.getColumnIndex("DATA4"));
|
||||
NotificationCenter.Instance.postNotificationName(MessagesController.closeChats);
|
||||
NotificationCenter.Instance.addToMemCache("push_user_id", userId);
|
||||
try {
|
||||
Cursor cursor = getContentResolver().query(intent.getData(), null, null, null, null);
|
||||
if (cursor != null) {
|
||||
if (cursor.moveToFirst()) {
|
||||
int userId = cursor.getInt(cursor.getColumnIndex("DATA4"));
|
||||
NotificationCenter.Instance.postNotificationName(MessagesController.closeChats);
|
||||
NotificationCenter.Instance.addToMemCache("push_user_id", userId);
|
||||
}
|
||||
cursor.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
} else if (intent.getAction().equals("org.telegram.messenger.OPEN_ACCOUNT")) {
|
||||
NotificationCenter.Instance.addToMemCache("open_settings", 1);
|
||||
|
@ -115,6 +142,7 @@ public class LaunchActivity extends PausableActivity {
|
|||
}
|
||||
int chatId = getIntent().getIntExtra("chatId", 0);
|
||||
int userId = getIntent().getIntExtra("userId", 0);
|
||||
int encId = getIntent().getIntExtra("encId", 0);
|
||||
if (chatId != 0) {
|
||||
TLRPC.Chat chat = MessagesController.Instance.chats.get(chatId);
|
||||
if (chat != null) {
|
||||
|
@ -127,6 +155,12 @@ public class LaunchActivity extends PausableActivity {
|
|||
NotificationCenter.Instance.postNotificationName(MessagesController.closeChats);
|
||||
NotificationCenter.Instance.addToMemCache("push_user_id", userId);
|
||||
}
|
||||
} else if (encId != 0) {
|
||||
TLRPC.EncryptedChat chat = MessagesController.Instance.encryptedChats.get(encId);
|
||||
if (chat != null) {
|
||||
NotificationCenter.Instance.postNotificationName(MessagesController.closeChats);
|
||||
NotificationCenter.Instance.addToMemCache("push_enc_id", encId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -329,7 +329,10 @@ public class LocationActivity extends BaseFragment implements NotificationCenter
|
|||
@Override
|
||||
public void didReceivedNotification(int id, Object... args) {
|
||||
if (id == MessagesController.updateInterfaces) {
|
||||
updateUserData();
|
||||
int mask = (Integer)args[0];
|
||||
if ((mask & MessagesController.UPDATE_MASK_AVATAR) != 0 || (mask & MessagesController.UPDATE_MASK_NAME) != 0) {
|
||||
updateUserData();
|
||||
}
|
||||
} else if (id == MessagesController.closeChats) {
|
||||
removeSelfFromStack();
|
||||
}
|
||||
|
|
|
@ -25,7 +25,6 @@ import android.view.animation.AccelerateDecelerateInterpolator;
|
|||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.telegram.messenger.ConnectionsManager;
|
||||
import org.telegram.messenger.R;
|
||||
import org.telegram.messenger.Utilities;
|
||||
import org.telegram.ui.Views.SlideView;
|
||||
|
|
|
@ -253,7 +253,9 @@ public class LoginActivityPhoneView extends SlideView implements AdapterView.OnI
|
|||
public void selectCountry(String name) {
|
||||
int index = countriesArray.indexOf(name);
|
||||
if (index != -1) {
|
||||
ignoreOnTextChange = true;
|
||||
codeField.setText(countriesMap.get(name));
|
||||
countryButton.setText(name);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -299,6 +301,10 @@ public class LoginActivityPhoneView extends SlideView implements AdapterView.OnI
|
|||
|
||||
@Override
|
||||
public void onNextPressed() {
|
||||
if (codeField.length() == 0 || phoneField.length() == 0) {
|
||||
delegate.needShowAlert(ApplicationLoader.applicationContext.getString(R.string.InvalidPhoneNumber));
|
||||
return;
|
||||
}
|
||||
TLRPC.TL_auth_sendCode req = new TLRPC.TL_auth_sendCode();
|
||||
String phone = PhoneFormat.stripExceptNumbers("" + codeField.getText() + phoneField.getText());
|
||||
req.api_hash = ConnectionsManager.APP_HASH;
|
||||
|
@ -327,25 +333,31 @@ public class LoginActivityPhoneView extends SlideView implements AdapterView.OnI
|
|||
Utilities.RunOnUIThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
delegate.setPage(1, true, params, false);
|
||||
if (delegate != null) {
|
||||
delegate.setPage(1, true, params, false);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if (error.text != null) {
|
||||
if (error.text.contains("PHONE_NUMBER_INVALID")) {
|
||||
delegate.needShowAlert(ApplicationLoader.applicationContext.getString(R.string.InvalidPhoneNumber));
|
||||
} else if (error.text.contains("PHONE_CODE_EMPTY") || error.text.contains("PHONE_CODE_INVALID")) {
|
||||
delegate.needShowAlert(ApplicationLoader.applicationContext.getString(R.string.InvalidCode));
|
||||
} else if (error.text.contains("PHONE_CODE_EXPIRED")) {
|
||||
delegate.needShowAlert(ApplicationLoader.applicationContext.getString(R.string.CodeExpired));
|
||||
} else if (error.text.contains("FLOOD_WAIT")) {
|
||||
delegate.needShowAlert(ApplicationLoader.applicationContext.getString(R.string.FloodWait));
|
||||
} else {
|
||||
delegate.needShowAlert(error.text);
|
||||
if (delegate != null) {
|
||||
if (error.text != null) {
|
||||
if (error.text.contains("PHONE_NUMBER_INVALID")) {
|
||||
delegate.needShowAlert(ApplicationLoader.applicationContext.getString(R.string.InvalidPhoneNumber));
|
||||
} else if (error.text.contains("PHONE_CODE_EMPTY") || error.text.contains("PHONE_CODE_INVALID")) {
|
||||
delegate.needShowAlert(ApplicationLoader.applicationContext.getString(R.string.InvalidCode));
|
||||
} else if (error.text.contains("PHONE_CODE_EXPIRED")) {
|
||||
delegate.needShowAlert(ApplicationLoader.applicationContext.getString(R.string.CodeExpired));
|
||||
} else if (error.text.contains("FLOOD_WAIT")) {
|
||||
delegate.needShowAlert(ApplicationLoader.applicationContext.getString(R.string.FloodWait));
|
||||
} else {
|
||||
delegate.needShowAlert(error.text);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
delegate.needHideProgress();
|
||||
if (delegate != null) {
|
||||
delegate.needHideProgress();
|
||||
}
|
||||
}
|
||||
}, null, true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassFailOnServerErrors);
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ import android.widget.TextView;
|
|||
import org.telegram.TL.TLObject;
|
||||
import org.telegram.TL.TLRPC;
|
||||
import org.telegram.messenger.ConnectionsManager;
|
||||
import org.telegram.messenger.ContactsController;
|
||||
import org.telegram.messenger.MessagesController;
|
||||
import org.telegram.messenger.MessagesStorage;
|
||||
import org.telegram.messenger.R;
|
||||
|
@ -191,7 +192,9 @@ public class LoginActivityRegisterView extends SlideView {
|
|||
ConnectionsManager.Instance.performRpc(req, new RPCRequest.RPCRequestDelegate() {
|
||||
@Override
|
||||
public void run(TLObject response, TLRPC.TL_error error) {
|
||||
delegate.needHideProgress();
|
||||
if (delegate != null) {
|
||||
delegate.needHideProgress();
|
||||
}
|
||||
if (error == null) {
|
||||
final TLRPC.TL_auth_authorization res = (TLRPC.TL_auth_authorization)response;
|
||||
Utilities.RunOnUIThread(new Runnable() {
|
||||
|
@ -211,23 +214,27 @@ public class LoginActivityRegisterView extends SlideView {
|
|||
MessagesStorage.Instance.putUsersAndChats(users, null, true, true);
|
||||
//MessagesController.Instance.uploadAndApplyUserAvatar(avatarPhotoBig);
|
||||
MessagesController.Instance.users.put(res.user.id, res.user);
|
||||
MessagesController.Instance.checkAppAccount();
|
||||
delegate.needFinishActivity();
|
||||
ContactsController.Instance.checkAppAccount();
|
||||
if (delegate != null) {
|
||||
delegate.needFinishActivity();
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if (error.text.contains("PHONE_NUMBER_INVALID")) {
|
||||
delegate.needShowAlert(ApplicationLoader.applicationContext.getString(R.string.InvalidPhoneNumber));
|
||||
} else if (error.text.contains("PHONE_CODE_EMPTY") || error.text.contains("PHONE_CODE_INVALID")) {
|
||||
delegate.needShowAlert(ApplicationLoader.applicationContext.getString(R.string.InvalidCode));
|
||||
} else if (error.text.contains("PHONE_CODE_EXPIRED")) {
|
||||
delegate.needShowAlert(ApplicationLoader.applicationContext.getString(R.string.CodeExpired));
|
||||
} else if (error.text.contains("FIRSTNAME_INVALID")) {
|
||||
delegate.needShowAlert(ApplicationLoader.applicationContext.getString(R.string.InvalidFirstName));
|
||||
} else if (error.text.contains("LASTNAME_INVALID")) {
|
||||
delegate.needShowAlert(ApplicationLoader.applicationContext.getString(R.string.InvalidLastName));
|
||||
} else {
|
||||
delegate.needShowAlert(error.text);
|
||||
if (delegate != null) {
|
||||
if (error.text.contains("PHONE_NUMBER_INVALID")) {
|
||||
delegate.needShowAlert(ApplicationLoader.applicationContext.getString(R.string.InvalidPhoneNumber));
|
||||
} else if (error.text.contains("PHONE_CODE_EMPTY") || error.text.contains("PHONE_CODE_INVALID")) {
|
||||
delegate.needShowAlert(ApplicationLoader.applicationContext.getString(R.string.InvalidCode));
|
||||
} else if (error.text.contains("PHONE_CODE_EXPIRED")) {
|
||||
delegate.needShowAlert(ApplicationLoader.applicationContext.getString(R.string.CodeExpired));
|
||||
} else if (error.text.contains("FIRSTNAME_INVALID")) {
|
||||
delegate.needShowAlert(ApplicationLoader.applicationContext.getString(R.string.InvalidFirstName));
|
||||
} else if (error.text.contains("LASTNAME_INVALID")) {
|
||||
delegate.needShowAlert(ApplicationLoader.applicationContext.getString(R.string.InvalidLastName));
|
||||
} else {
|
||||
delegate.needShowAlert(error.text);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,8 @@ import org.telegram.PhoneFormat.PhoneFormat;
|
|||
import org.telegram.TL.TLObject;
|
||||
import org.telegram.TL.TLRPC;
|
||||
import org.telegram.messenger.ConnectionsManager;
|
||||
import org.telegram.messenger.ContactsController;
|
||||
import org.telegram.messenger.FileLog;
|
||||
import org.telegram.messenger.MessagesController;
|
||||
import org.telegram.messenger.MessagesStorage;
|
||||
import org.telegram.messenger.NotificationCenter;
|
||||
|
@ -47,6 +49,7 @@ public class LoginActivitySmsView extends SlideView implements NotificationCente
|
|||
private Bundle currentParams;
|
||||
|
||||
private Timer timeTimer;
|
||||
private final Integer timerSync = 1;
|
||||
private int time = 60000;
|
||||
private double lastCurrentTime;
|
||||
private boolean waitingForSms = false;
|
||||
|
@ -102,6 +105,7 @@ public class LoginActivitySmsView extends SlideView implements NotificationCente
|
|||
@Override
|
||||
public void setParams(Bundle params) {
|
||||
codeField.setText("");
|
||||
Utilities.setWaitingForSms(true);
|
||||
NotificationCenter.Instance.addObserver(this, 998);
|
||||
currentParams = params;
|
||||
waitingForSms = true;
|
||||
|
@ -117,9 +121,15 @@ public class LoginActivitySmsView extends SlideView implements NotificationCente
|
|||
codeField.requestFocus();
|
||||
|
||||
time = 60000;
|
||||
if (timeTimer != null) {
|
||||
timeTimer.cancel();
|
||||
timeTimer = null;
|
||||
try {
|
||||
synchronized(timerSync) {
|
||||
if (timeTimer != null) {
|
||||
timeTimer.cancel();
|
||||
timeTimer = null;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
timeText.setText(String.format("%s 1:00", ApplicationLoader.applicationContext.getResources().getString(R.string.CallText)));
|
||||
lastCurrentTime = System.currentTimeMillis();
|
||||
|
@ -140,9 +150,11 @@ public class LoginActivitySmsView extends SlideView implements NotificationCente
|
|||
timeText.setText(String.format("%s %d:%02d", ApplicationLoader.applicationContext.getResources().getString(R.string.CallText), minutes, seconds));
|
||||
} else {
|
||||
timeText.setText(ApplicationLoader.applicationContext.getResources().getString(R.string.Calling));
|
||||
if (timeTimer != null) {
|
||||
timeTimer.cancel();
|
||||
timeTimer = null;
|
||||
synchronized(timerSync) {
|
||||
if (timeTimer != null) {
|
||||
timeTimer.cancel();
|
||||
timeTimer = null;
|
||||
}
|
||||
}
|
||||
TLRPC.TL_auth_sendCall req = new TLRPC.TL_auth_sendCall();
|
||||
req.phone_number = requestPhone;
|
||||
|
@ -162,12 +174,25 @@ public class LoginActivitySmsView extends SlideView implements NotificationCente
|
|||
@Override
|
||||
public void onNextPressed() {
|
||||
waitingForSms = false;
|
||||
Utilities.setWaitingForSms(false);
|
||||
NotificationCenter.Instance.removeObserver(this, 998);
|
||||
final TLRPC.TL_auth_signIn req = new TLRPC.TL_auth_signIn();
|
||||
req.phone_number = requestPhone;
|
||||
req.phone_code = codeField.getText().toString();
|
||||
req.phone_code_hash = phoneHash;
|
||||
delegate.needShowProgress();
|
||||
try {
|
||||
synchronized(timerSync) {
|
||||
if (timeTimer != null) {
|
||||
timeTimer.cancel();
|
||||
timeTimer = null;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
if (delegate != null) {
|
||||
delegate.needShowProgress();
|
||||
}
|
||||
ConnectionsManager.Instance.performRpc(req, new RPCRequest.RPCRequestDelegate() {
|
||||
@Override
|
||||
public void run(TLObject response, TLRPC.TL_error error) {
|
||||
|
@ -182,9 +207,15 @@ public class LoginActivitySmsView extends SlideView implements NotificationCente
|
|||
if (delegate == null) {
|
||||
return;
|
||||
}
|
||||
if (timeTimer != null) {
|
||||
timeTimer.cancel();
|
||||
timeTimer = null;
|
||||
try {
|
||||
synchronized(timerSync) {
|
||||
if (timeTimer != null) {
|
||||
timeTimer.cancel();
|
||||
timeTimer = null;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
UserConfig.clearConfig();
|
||||
MessagesStorage.Instance.cleanUp();
|
||||
|
@ -198,8 +229,10 @@ public class LoginActivitySmsView extends SlideView implements NotificationCente
|
|||
users.add(UserConfig.currentUser);
|
||||
MessagesStorage.Instance.putUsersAndChats(users, null, true, true);
|
||||
MessagesController.Instance.users.put(res.user.id, res.user);
|
||||
MessagesController.Instance.checkAppAccount();
|
||||
delegate.needFinishActivity();
|
||||
ContactsController.Instance.checkAppAccount();
|
||||
if (delegate != null) {
|
||||
delegate.needFinishActivity();
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
|
@ -212,21 +245,67 @@ public class LoginActivitySmsView extends SlideView implements NotificationCente
|
|||
params.putString("phoneHash", phoneHash);
|
||||
params.putString("code", req.phone_code);
|
||||
delegate.setPage(2, true, params, false);
|
||||
if (timeTimer != null) {
|
||||
timeTimer.cancel();
|
||||
timeTimer = null;
|
||||
try {
|
||||
synchronized(timerSync) {
|
||||
if (timeTimer != null) {
|
||||
timeTimer.cancel();
|
||||
timeTimer = null;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if (error.text.contains("PHONE_NUMBER_INVALID")) {
|
||||
delegate.needShowAlert(ApplicationLoader.applicationContext.getString(R.string.InvalidPhoneNumber));
|
||||
} else if (error.text.contains("PHONE_CODE_EMPTY") || error.text.contains("PHONE_CODE_INVALID")) {
|
||||
delegate.needShowAlert(ApplicationLoader.applicationContext.getString(R.string.InvalidCode));
|
||||
} else if (error.text.contains("PHONE_CODE_EXPIRED")) {
|
||||
delegate.needShowAlert(ApplicationLoader.applicationContext.getString(R.string.CodeExpired));
|
||||
} else {
|
||||
delegate.needShowAlert(error.text);
|
||||
if (timeTimer == null) {
|
||||
timeTimer = new Timer();
|
||||
timeTimer.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
double currentTime = System.currentTimeMillis();
|
||||
double diff = currentTime - lastCurrentTime;
|
||||
time -= diff;
|
||||
lastCurrentTime = currentTime;
|
||||
Utilities.RunOnUIThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (time >= 1000) {
|
||||
int minutes = time / 1000 / 60;
|
||||
int seconds = time / 1000 - minutes * 60;
|
||||
timeText.setText(String.format("%s %d:%02d", ApplicationLoader.applicationContext.getResources().getString(R.string.CallText), minutes, seconds));
|
||||
} else {
|
||||
timeText.setText(ApplicationLoader.applicationContext.getResources().getString(R.string.Calling));
|
||||
synchronized(timerSync) {
|
||||
if (timeTimer != null) {
|
||||
timeTimer.cancel();
|
||||
timeTimer = null;
|
||||
}
|
||||
}
|
||||
TLRPC.TL_auth_sendCall req = new TLRPC.TL_auth_sendCall();
|
||||
req.phone_number = requestPhone;
|
||||
req.phone_code_hash = phoneHash;
|
||||
ConnectionsManager.Instance.performRpc(req, new RPCRequest.RPCRequestDelegate() {
|
||||
@Override
|
||||
public void run(TLObject response, TLRPC.TL_error error) {
|
||||
}
|
||||
}, null, true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassFailOnServerErrors);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}, 0, 1000);
|
||||
}
|
||||
if (delegate != null) {
|
||||
if (error.text.contains("PHONE_NUMBER_INVALID")) {
|
||||
delegate.needShowAlert(ApplicationLoader.applicationContext.getString(R.string.InvalidPhoneNumber));
|
||||
} else if (error.text.contains("PHONE_CODE_EMPTY") || error.text.contains("PHONE_CODE_INVALID")) {
|
||||
delegate.needShowAlert(ApplicationLoader.applicationContext.getString(R.string.InvalidCode));
|
||||
} else if (error.text.contains("PHONE_CODE_EXPIRED")) {
|
||||
delegate.needShowAlert(ApplicationLoader.applicationContext.getString(R.string.CodeExpired));
|
||||
} else {
|
||||
delegate.needShowAlert(error.text);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -236,11 +315,18 @@ public class LoginActivitySmsView extends SlideView implements NotificationCente
|
|||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (timeTimer != null) {
|
||||
timeTimer.cancel();
|
||||
timeTimer = null;
|
||||
try {
|
||||
synchronized(timerSync) {
|
||||
if (timeTimer != null) {
|
||||
timeTimer.cancel();
|
||||
timeTimer = null;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
currentParams = null;
|
||||
Utilities.setWaitingForSms(false);
|
||||
NotificationCenter.Instance.removeObserver(this, 998);
|
||||
waitingForSms = false;
|
||||
}
|
||||
|
@ -248,10 +334,17 @@ public class LoginActivitySmsView extends SlideView implements NotificationCente
|
|||
@Override
|
||||
public void onDestroyActivity() {
|
||||
super.onDestroyActivity();
|
||||
Utilities.setWaitingForSms(false);
|
||||
NotificationCenter.Instance.removeObserver(this, 998);
|
||||
if (timeTimer != null) {
|
||||
timeTimer.cancel();
|
||||
timeTimer = null;
|
||||
try {
|
||||
synchronized(timerSync) {
|
||||
if (timeTimer != null) {
|
||||
timeTimer.cancel();
|
||||
timeTimer = null;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
waitingForSms = false;
|
||||
}
|
||||
|
|
|
@ -11,15 +11,12 @@ package org.telegram.ui;
|
|||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.graphics.Typeface;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.internal.view.SupportMenuItem;
|
||||
import android.support.v4.view.MenuItemCompat;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.widget.SearchView;
|
||||
import android.text.Html;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
|
@ -33,25 +30,22 @@ import android.widget.ImageView;
|
|||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.telegram.PhoneFormat.PhoneFormat;
|
||||
import org.telegram.TL.TLObject;
|
||||
import org.telegram.TL.TLRPC;
|
||||
import org.telegram.messenger.Emoji;
|
||||
import org.telegram.messenger.ContactsController;
|
||||
import org.telegram.messenger.FileLog;
|
||||
import org.telegram.objects.MessageObject;
|
||||
import org.telegram.messenger.ConnectionsManager;
|
||||
import org.telegram.messenger.MessagesController;
|
||||
import org.telegram.messenger.MessagesStorage;
|
||||
import org.telegram.messenger.NotificationCenter;
|
||||
import org.telegram.messenger.R;
|
||||
import org.telegram.messenger.UserConfig;
|
||||
import org.telegram.messenger.Utilities;
|
||||
import org.telegram.ui.Views.BackupImageView;
|
||||
import org.telegram.ui.Cells.ChatOrUserCell;
|
||||
import org.telegram.ui.Cells.DialogCell;
|
||||
import org.telegram.ui.Views.BaseFragment;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Locale;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
|
@ -65,7 +59,6 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter
|
|||
private SearchView searchView;
|
||||
public int selectAlertString = 0;
|
||||
private boolean serverOnly = false;
|
||||
private boolean isRTL;
|
||||
|
||||
private static boolean dialogsLoaded = false;
|
||||
private boolean searching = false;
|
||||
|
@ -91,7 +84,6 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter
|
|||
NotificationCenter.Instance.addObserver(this, 999);
|
||||
NotificationCenter.Instance.addObserver(this, MessagesController.updateInterfaces);
|
||||
NotificationCenter.Instance.addObserver(this, MessagesController.reloadSearchResults);
|
||||
NotificationCenter.Instance.addObserver(this, MessagesController.userPrintUpdateAll);
|
||||
NotificationCenter.Instance.addObserver(this, MessagesController.encryptedChatUpdated);
|
||||
NotificationCenter.Instance.addObserver(this, MessagesController.contactsDidLoaded);
|
||||
NotificationCenter.Instance.addObserver(this, 1234);
|
||||
|
@ -100,8 +92,8 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter
|
|||
serverOnly = getArguments().getBoolean("serverOnly", false);
|
||||
}
|
||||
if (!dialogsLoaded) {
|
||||
MessagesController.Instance.readContacts();
|
||||
MessagesController.Instance.loadDialogs(0, 0, 100, true);
|
||||
ContactsController.Instance.checkAppAccount();
|
||||
dialogsLoaded = true;
|
||||
}
|
||||
return true;
|
||||
|
@ -114,7 +106,6 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter
|
|||
NotificationCenter.Instance.removeObserver(this, 999);
|
||||
NotificationCenter.Instance.removeObserver(this, MessagesController.updateInterfaces);
|
||||
NotificationCenter.Instance.removeObserver(this, MessagesController.reloadSearchResults);
|
||||
NotificationCenter.Instance.removeObserver(this, MessagesController.userPrintUpdateAll);
|
||||
NotificationCenter.Instance.removeObserver(this, MessagesController.encryptedChatUpdated);
|
||||
NotificationCenter.Instance.removeObserver(this, MessagesController.contactsDidLoaded);
|
||||
NotificationCenter.Instance.removeObserver(this, 1234);
|
||||
|
@ -133,9 +124,6 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter
|
|||
fragmentView = inflater.inflate(R.layout.messages_list, container, false);
|
||||
|
||||
messagesListViewAdapter = new MessagesAdapter(parentActivity);
|
||||
Locale locale = Locale.getDefault();
|
||||
String lang = locale.getLanguage();
|
||||
isRTL = lang != null && lang.toLowerCase().equals("ar");
|
||||
|
||||
messagesListView = (ListView)fragmentView.findViewById(R.id.messages_list_view);
|
||||
messagesListView.setAdapter(messagesListViewAdapter);
|
||||
|
@ -248,7 +236,7 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter
|
|||
if (which == 0) {
|
||||
MessagesController.Instance.deleteDialog(selectedDialog, 0, true);
|
||||
} else if (which == 1) {
|
||||
MessagesController.Instance.deleteUserFromChat((int) -selectedDialog, UserConfig.clientUserId, null);
|
||||
MessagesController.Instance.deleteUserFromChat((int) -selectedDialog, MessagesController.Instance.users.get(UserConfig.clientUserId), null);
|
||||
MessagesController.Instance.deleteDialog(selectedDialog, 0, false);
|
||||
}
|
||||
}
|
||||
|
@ -314,7 +302,7 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter
|
|||
actionBar.setDisplayShowCustomEnabled(false);
|
||||
actionBar.setSubtitle(null);
|
||||
actionBar.setCustomView(null);
|
||||
actionBar.setTitle(getStringEntry(R.string.AppName));
|
||||
actionBar.setTitle(getStringEntry(R.string.SelectChat));
|
||||
((ApplicationActivity)parentActivity).fixBackButton();
|
||||
} else {
|
||||
ImageView view = (ImageView)parentActivity.findViewById(16908332);
|
||||
|
@ -392,12 +380,10 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter
|
|||
}
|
||||
} else if (id == 999) {
|
||||
if (messagesListView != null) {
|
||||
updateVisibleRows();
|
||||
updateVisibleRows(0);
|
||||
}
|
||||
} else if (id == MessagesController.updateInterfaces) {
|
||||
if (messagesListViewAdapter != null) {
|
||||
messagesListViewAdapter.notifyDataSetChanged();
|
||||
}
|
||||
updateVisibleRows((Integer)args[0]);
|
||||
} else if (id == MessagesController.reloadSearchResults) {
|
||||
int token = (Integer)args[0];
|
||||
if (token == activityToken) {
|
||||
|
@ -405,32 +391,24 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter
|
|||
}
|
||||
} else if (id == 1234) {
|
||||
dialogsLoaded = false;
|
||||
} else if (id == MessagesController.userPrintUpdateAll) {
|
||||
if (messagesListView != null) {
|
||||
updateVisibleRows();
|
||||
}
|
||||
} else if (id == MessagesController.encryptedChatUpdated) {
|
||||
if (messagesListView != null) {
|
||||
updateVisibleRows();
|
||||
}
|
||||
updateVisibleRows(0);
|
||||
} else if (id == MessagesController.contactsDidLoaded) {
|
||||
if (messagesListView != null) {
|
||||
updateVisibleRows();
|
||||
}
|
||||
updateVisibleRows(0);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateVisibleRows() {
|
||||
if (searching && searchWas) {
|
||||
messagesListView.invalidate();
|
||||
} else {
|
||||
int count = messagesListView.getChildCount();
|
||||
for (int a = 0; a < count; a++) {
|
||||
View child = messagesListView.getChildAt(a);
|
||||
Object tag = child.getTag();
|
||||
if (tag instanceof MessagesListRowHolder) {
|
||||
((MessagesListRowHolder) tag).update();
|
||||
}
|
||||
private void updateVisibleRows(int mask) {
|
||||
if (messagesListView == null) {
|
||||
return;
|
||||
}
|
||||
int count = messagesListView.getChildCount();
|
||||
for (int a = 0; a < count; a++) {
|
||||
View child = messagesListView.getChildAt(a);
|
||||
if (child instanceof DialogCell) {
|
||||
((DialogCell) child).update(mask);
|
||||
} else if (child instanceof ChatOrUserCell) {
|
||||
((ChatOrUserCell) child).update(mask);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -452,15 +430,24 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter
|
|||
if (lower_part != 0) {
|
||||
if (lower_part > 0) {
|
||||
TLRPC.User user = MessagesController.Instance.users.get(lower_part);
|
||||
if (user == null) {
|
||||
return;
|
||||
}
|
||||
builder.setMessage(String.format(getStringEntry(selectAlertString), Utilities.formatName(user.first_name, user.last_name)));
|
||||
} else if (lower_part < 0) {
|
||||
TLRPC.Chat chat = MessagesController.Instance.chats.get(-lower_part);
|
||||
if (chat == null) {
|
||||
return;
|
||||
}
|
||||
builder.setMessage(String.format(getStringEntry(selectAlertString), chat.title));
|
||||
}
|
||||
} else {
|
||||
int chat_id = (int)(dialog_id >> 32);
|
||||
TLRPC.EncryptedChat chat = MessagesController.Instance.encryptedChats.get(chat_id);
|
||||
TLRPC.User user = MessagesController.Instance.users.get(chat.user_id);
|
||||
if (user == null) {
|
||||
return;
|
||||
}
|
||||
builder.setMessage(String.format(getStringEntry(selectAlertString), Utilities.formatName(user.first_name, user.last_name)));
|
||||
}
|
||||
builder.setPositiveButton(R.string.OK, new DialogInterface.OnClickListener() {
|
||||
|
@ -740,29 +727,14 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter
|
|||
@Override
|
||||
public View getView(int i, View view, ViewGroup viewGroup) {
|
||||
if (searching && searchWas) {
|
||||
int type = getItemViewType(i);
|
||||
if (view == null) {
|
||||
LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
if (type == 2) {
|
||||
view = li.inflate(R.layout.messages_search_user_layout, viewGroup, false);
|
||||
} else {
|
||||
view = li.inflate(R.layout.messages_search_chat_layout, viewGroup, false);
|
||||
}
|
||||
View v = view.findViewById(R.id.settings_row_divider);
|
||||
v.setVisibility(View.VISIBLE);
|
||||
view.setPadding(Utilities.dp(11), 0, Utilities.dp(11), 0);
|
||||
}
|
||||
MessagesListSearchRowHolder holder = (MessagesListSearchRowHolder)view.getTag();
|
||||
if (holder == null) {
|
||||
holder = new MessagesListSearchRowHolder(view);
|
||||
view.setTag(holder);
|
||||
view = new ChatOrUserCell(mContext);
|
||||
}
|
||||
TLRPC.User user = null;
|
||||
TLRPC.Chat chat = null;
|
||||
TLRPC.EncryptedChat encryptedChat = null;
|
||||
|
||||
TLObject obj = searchResult.get(i);
|
||||
CharSequence name = searchResultNames.get(i);
|
||||
if (obj instanceof TLRPC.User) {
|
||||
user = MessagesController.Instance.users.get(((TLRPC.User)obj).id);
|
||||
} else if (obj instanceof TLRPC.Chat) {
|
||||
|
@ -772,57 +744,7 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter
|
|||
user = MessagesController.Instance.users.get(encryptedChat.user_id);
|
||||
}
|
||||
|
||||
holder.nameTextView.setText(name);
|
||||
if (encryptedChat != null) {
|
||||
if (!isRTL) {
|
||||
holder.nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_lock_green, 0, 0, 0);
|
||||
} else {
|
||||
holder.nameTextView.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_lock_green, 0);
|
||||
}
|
||||
holder.nameTextView.setCompoundDrawablePadding(Utilities.dp(4));
|
||||
} else {
|
||||
holder.nameTextView.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
|
||||
holder.nameTextView.setCompoundDrawablePadding(0);
|
||||
}
|
||||
|
||||
TLRPC.FileLocation photo = null;
|
||||
int placeHolderId = 0;
|
||||
if (user != null) {
|
||||
if (user.photo != null) {
|
||||
photo = user.photo.photo_small;
|
||||
}
|
||||
placeHolderId = Utilities.getUserAvatarForId(user.id);
|
||||
} else if (chat != null) {
|
||||
if (chat.photo != null) {
|
||||
photo = chat.photo.photo_small;
|
||||
}
|
||||
placeHolderId = Utilities.getGroupAvatarForId(chat.id);
|
||||
}
|
||||
holder.avatarImage.setImage(photo, "50_50", placeHolderId);
|
||||
|
||||
if (user != null) {
|
||||
if (user.status == null) {
|
||||
holder.messageTextView.setTextColor(0xff808080);
|
||||
holder.messageTextView.setText(getStringEntry(R.string.Offline));
|
||||
} else {
|
||||
int currentTime = ConnectionsManager.Instance.getCurrentTime();
|
||||
if (user.status.expires > currentTime || user.status.was_online > currentTime) {
|
||||
holder.messageTextView.setTextColor(0xff316f9f);
|
||||
holder.messageTextView.setText(getStringEntry(R.string.Online));
|
||||
} else {
|
||||
if (user.status.was_online <= 10000 && user.status.expires <= 10000) {
|
||||
holder.messageTextView.setText(getStringEntry(R.string.Invisible));
|
||||
} else {
|
||||
int value = user.status.was_online;
|
||||
if (value == 0) {
|
||||
value = user.status.expires;
|
||||
}
|
||||
holder.messageTextView.setText(getStringEntry(R.string.LastSeen) + " " + Utilities.formatDateOnline(value));
|
||||
}
|
||||
holder.messageTextView.setTextColor(0xff808080);
|
||||
}
|
||||
}
|
||||
}
|
||||
((ChatOrUserCell)view).setData(user, chat, encryptedChat, searchResultNames.get(i), null);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
@ -836,21 +758,13 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter
|
|||
}
|
||||
|
||||
if (view == null) {
|
||||
LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
view = li.inflate(R.layout.messages_list_row, viewGroup, false);
|
||||
}
|
||||
|
||||
MessagesListRowHolder holder = (MessagesListRowHolder)view.getTag();
|
||||
if (holder == null) {
|
||||
holder = new MessagesListRowHolder(view);
|
||||
view.setTag(holder);
|
||||
view = new DialogCell(mContext);
|
||||
}
|
||||
if (serverOnly) {
|
||||
holder.dialog = MessagesController.Instance.dialogsServerOnly.get(i);
|
||||
((DialogCell)view).setDialog(MessagesController.Instance.dialogsServerOnly.get(i));
|
||||
} else {
|
||||
holder.dialog = MessagesController.Instance.dialogs.get(i);
|
||||
((DialogCell)view).setDialog(MessagesController.Instance.dialogs.get(i));
|
||||
}
|
||||
holder.update();
|
||||
|
||||
return view;
|
||||
}
|
||||
|
@ -865,14 +779,8 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter
|
|||
return 3;
|
||||
}
|
||||
}
|
||||
if (serverOnly) {
|
||||
if (i == MessagesController.Instance.dialogsServerOnly.size()) {
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
if (i == MessagesController.Instance.dialogs.size()) {
|
||||
return 1;
|
||||
}
|
||||
if (serverOnly && i == MessagesController.Instance.dialogsServerOnly.size() || !serverOnly && i == MessagesController.Instance.dialogs.size()) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -905,250 +813,4 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter
|
|||
return count == 0;
|
||||
}
|
||||
}
|
||||
|
||||
private class MessagesListSearchRowHolder {
|
||||
public BackupImageView avatarImage;
|
||||
public TextView messageTextView;
|
||||
public TextView nameTextView;
|
||||
|
||||
public MessagesListSearchRowHolder(View view) {
|
||||
messageTextView = (TextView)view.findViewById(R.id.messages_list_row_message);
|
||||
nameTextView = (TextView)view.findViewById(R.id.messages_list_row_name);
|
||||
avatarImage = (BackupImageView)view.findViewById(R.id.messages_list_row_avatar);
|
||||
}
|
||||
}
|
||||
|
||||
private class MessagesListRowHolder {
|
||||
public ImageView errorImage;
|
||||
public TextView messagesCountImage;
|
||||
public BackupImageView avatarImage;
|
||||
public TextView timeTextView;
|
||||
public TextView messageTextView;
|
||||
public TextView nameTextView;
|
||||
public ImageView check1Image;
|
||||
public ImageView check2Image;
|
||||
public ImageView clockImage;
|
||||
public TLRPC.TL_dialog dialog;
|
||||
|
||||
public MessagesListRowHolder(View view) {
|
||||
messageTextView = (TextView)view.findViewById(R.id.messages_list_row_message);
|
||||
nameTextView = (TextView)view.findViewById(R.id.messages_list_row_name);
|
||||
if (nameTextView != null) {
|
||||
Typeface typeface = Utilities.getTypeface("fonts/rmedium.ttf");
|
||||
nameTextView.setTypeface(typeface);
|
||||
}
|
||||
timeTextView = (TextView)view.findViewById(R.id.messages_list_row_time);
|
||||
avatarImage = (BackupImageView)view.findViewById(R.id.messages_list_row_avatar);
|
||||
messagesCountImage = (TextView)view.findViewById(R.id.messages_list_row_badge);
|
||||
errorImage = (ImageView)view.findViewById(R.id.messages_list_row_error);
|
||||
check1Image = (ImageView)view.findViewById(R.id.messages_list_row_check_half);
|
||||
check2Image = (ImageView)view.findViewById(R.id.messages_list_row_check);
|
||||
clockImage = (ImageView)view.findViewById(R.id.messages_list_row_clock);
|
||||
}
|
||||
|
||||
public void update() {
|
||||
MessageObject message = MessagesController.Instance.dialogMessage.get(dialog.top_message);
|
||||
TLRPC.User user = null;
|
||||
TLRPC.Chat chat = null;
|
||||
TLRPC.EncryptedChat encryptedChat = null;
|
||||
|
||||
int lower_id = (int)dialog.id;
|
||||
if (lower_id != 0) {
|
||||
if (lower_id < 0) {
|
||||
chat = MessagesController.Instance.chats.get(-lower_id);
|
||||
} else {
|
||||
user = MessagesController.Instance.users.get(lower_id);
|
||||
}
|
||||
nameTextView.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
|
||||
nameTextView.setCompoundDrawablePadding(0);
|
||||
} else {
|
||||
encryptedChat = MessagesController.Instance.encryptedChats.get((int)(dialog.id >> 32));
|
||||
if (encryptedChat != null) {
|
||||
user = MessagesController.Instance.users.get(encryptedChat.user_id);
|
||||
if (!isRTL) {
|
||||
nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_lock_green, 0, 0, 0);
|
||||
} else {
|
||||
nameTextView.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_lock_green, 0);
|
||||
}
|
||||
nameTextView.setCompoundDrawablePadding(Utilities.dp(4));
|
||||
} else {
|
||||
Log.e("test", "tda");
|
||||
}
|
||||
}
|
||||
|
||||
if (chat != null) {
|
||||
nameTextView.setText(chat.title);
|
||||
nameTextView.setTextColor(0xff000000);
|
||||
} else if (user != null) {
|
||||
if (user.id != 333000 && MessagesController.Instance.contactsDict.get(user.id) == null) {
|
||||
if (MessagesController.Instance.contactsDict.size() == 0 && MessagesController.Instance.loadingContacts) {
|
||||
nameTextView.setTextColor(0xff000000);
|
||||
nameTextView.setText(Utilities.formatName(user.first_name, user.last_name));
|
||||
} else {
|
||||
if (user.phone != null && user.phone.length() != 0) {
|
||||
nameTextView.setTextColor(0xff000000);
|
||||
nameTextView.setText(PhoneFormat.Instance.format("+" + user.phone));
|
||||
} else {
|
||||
nameTextView.setTextColor(0xff316f9f);
|
||||
nameTextView.setText(Utilities.formatName(user.first_name, user.last_name));
|
||||
}
|
||||
}
|
||||
if (encryptedChat != null) {
|
||||
nameTextView.setTextColor(0xff00a60e);
|
||||
}
|
||||
} else {
|
||||
if (encryptedChat != null) {
|
||||
nameTextView.setTextColor(0xff00a60e);
|
||||
} else {
|
||||
nameTextView.setTextColor(0xff000000);
|
||||
}
|
||||
nameTextView.setText(Utilities.formatName(user.first_name, user.last_name));
|
||||
}
|
||||
}
|
||||
TLRPC.FileLocation photo = null;
|
||||
int placeHolderId = 0;
|
||||
if (user != null) {
|
||||
if (user.photo != null) {
|
||||
photo = user.photo.photo_small;
|
||||
}
|
||||
placeHolderId = Utilities.getUserAvatarForId(user.id);
|
||||
} else if (chat != null) {
|
||||
if (chat.photo != null) {
|
||||
photo = chat.photo.photo_small;
|
||||
}
|
||||
placeHolderId = Utilities.getGroupAvatarForId(chat.id);
|
||||
}
|
||||
CharSequence printingString = MessagesController.Instance.printingStrings.get(dialog.id);
|
||||
|
||||
avatarImage.setImage(photo, "50_50", placeHolderId);
|
||||
|
||||
if (message == null) {
|
||||
if (printingString != null) {
|
||||
messageTextView.setText(printingString);
|
||||
messageTextView.setTextColor(0xff316f9f);
|
||||
} else {
|
||||
if (encryptedChat != null) {
|
||||
messageTextView.setTextColor(0xff316f9f);
|
||||
if (encryptedChat instanceof TLRPC.TL_encryptedChatRequested) {
|
||||
messageTextView.setText(getStringEntry(R.string.EncryptionProcessing));
|
||||
} else if (encryptedChat instanceof TLRPC.TL_encryptedChatWaiting) {
|
||||
messageTextView.setText(String.format(getStringEntry(R.string.AwaitingEncryption), user.first_name));
|
||||
} else if (encryptedChat instanceof TLRPC.TL_encryptedChatDiscarded) {
|
||||
messageTextView.setText(getStringEntry(R.string.EncryptionRejected));
|
||||
} else if (encryptedChat instanceof TLRPC.TL_encryptedChat) {
|
||||
if (encryptedChat.admin_id == UserConfig.clientUserId) {
|
||||
if (user != null) {
|
||||
messageTextView.setText(String.format(getStringEntry(R.string.EncryptedChatStartedOutgoing), user.first_name));
|
||||
}
|
||||
} else {
|
||||
if (user != null) {
|
||||
messageTextView.setText(String.format(getStringEntry(R.string.EncryptedChatStartedIncoming), user.first_name));
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
messageTextView.setText("");
|
||||
}
|
||||
}
|
||||
if (dialog.last_message_date != 0) {
|
||||
timeTextView.setText(Utilities.stringForMessageListDate(dialog.last_message_date));
|
||||
} else {
|
||||
timeTextView.setText("");
|
||||
}
|
||||
messagesCountImage.setVisibility(View.GONE);
|
||||
check1Image.setVisibility(View.GONE);
|
||||
check2Image.setVisibility(View.GONE);
|
||||
errorImage.setVisibility(View.GONE);
|
||||
clockImage.setVisibility(View.GONE);
|
||||
} else {
|
||||
TLRPC.User fromUser = MessagesController.Instance.users.get(message.messageOwner.from_id);
|
||||
|
||||
if (dialog.last_message_date != 0) {
|
||||
timeTextView.setText(Utilities.stringForMessageListDate(dialog.last_message_date));
|
||||
} else {
|
||||
timeTextView.setText(Utilities.stringForMessageListDate(message.messageOwner.date));
|
||||
}
|
||||
if (printingString != null) {
|
||||
messageTextView.setTextColor(0xff316f9f);
|
||||
messageTextView.setText(printingString);
|
||||
} else {
|
||||
if (message.messageOwner instanceof TLRPC.TL_messageService) {
|
||||
messageTextView.setText(message.messageText);
|
||||
messageTextView.setTextColor(0xff316f9f);
|
||||
} else {
|
||||
if (chat != null) {
|
||||
String name = "";
|
||||
if (message.messageOwner.from_id == UserConfig.clientUserId) {
|
||||
name = getStringEntry(R.string.FromYou);
|
||||
} else {
|
||||
if (fromUser != null) {
|
||||
if (fromUser.first_name.length() > 0) {
|
||||
name = fromUser.first_name;
|
||||
} else {
|
||||
name = fromUser.last_name;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (message.messageOwner.media != null && !(message.messageOwner.media instanceof TLRPC.TL_messageMediaEmpty)) {
|
||||
messageTextView.setTextColor(0xff316f9f);
|
||||
messageTextView.setText(message.messageText);
|
||||
} else {
|
||||
messageTextView.setText(Emoji.replaceEmoji(Html.fromHtml(String.format("<font color=#316f9f>%s:</font> <font color=#808080>%s</font>", name, message.messageOwner.message))));
|
||||
}
|
||||
} else {
|
||||
messageTextView.setText(message.messageText);
|
||||
if (message.messageOwner.media != null && !(message.messageOwner.media instanceof TLRPC.TL_messageMediaEmpty)) {
|
||||
messageTextView.setTextColor(0xff316f9f);
|
||||
} else {
|
||||
messageTextView.setTextColor(0xff808080);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (dialog.unread_count != 0) {
|
||||
messagesCountImage.setVisibility(View.VISIBLE);
|
||||
messagesCountImage.setText(String.format("%d", dialog.unread_count));
|
||||
} else {
|
||||
messagesCountImage.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if (message.messageOwner.id < 0 && message.messageOwner.send_state != MessagesController.MESSAGE_SEND_STATE_SENT) {
|
||||
if (MessagesController.Instance.sendingMessages.get(message.messageOwner.id) == null) {
|
||||
message.messageOwner.send_state = MessagesController.MESSAGE_SEND_STATE_SEND_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
if (message.messageOwner.from_id == UserConfig.clientUserId) {
|
||||
if (message.messageOwner.send_state == MessagesController.MESSAGE_SEND_STATE_SENDING) {
|
||||
check1Image.setVisibility(View.GONE);
|
||||
check2Image.setVisibility(View.GONE);
|
||||
clockImage.setVisibility(View.VISIBLE);
|
||||
errorImage.setVisibility(View.GONE);
|
||||
} else if (message.messageOwner.send_state == MessagesController.MESSAGE_SEND_STATE_SEND_ERROR) {
|
||||
check1Image.setVisibility(View.GONE);
|
||||
check2Image.setVisibility(View.GONE);
|
||||
clockImage.setVisibility(View.GONE);
|
||||
errorImage.setVisibility(View.VISIBLE);
|
||||
messagesCountImage.setVisibility(View.GONE);
|
||||
} else if (message.messageOwner.send_state == MessagesController.MESSAGE_SEND_STATE_SENT) {
|
||||
if (!message.messageOwner.unread) {
|
||||
check1Image.setVisibility(View.VISIBLE);
|
||||
check2Image.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
check1Image.setVisibility(View.GONE);
|
||||
check2Image.setVisibility(View.VISIBLE);
|
||||
}
|
||||
clockImage.setVisibility(View.GONE);
|
||||
errorImage.setVisibility(View.GONE);
|
||||
}
|
||||
} else {
|
||||
check1Image.setVisibility(View.GONE);
|
||||
check2Image.setVisibility(View.GONE);
|
||||
errorImage.setVisibility(View.GONE);
|
||||
clockImage.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,381 @@
|
|||
/*
|
||||
* This is the source code of Telegram for Android v. 1.3.x.
|
||||
* It is licensed under GNU GPL v. 2 or later.
|
||||
* You should have received a copy of the license in this archive (see LICENSE).
|
||||
*
|
||||
* Copyright Nikolai Kudashov, 2013.
|
||||
*/
|
||||
|
||||
package org.telegram.ui;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.Display;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import org.telegram.messenger.FileLoader;
|
||||
import org.telegram.messenger.FileLog;
|
||||
import org.telegram.messenger.R;
|
||||
import org.telegram.messenger.Utilities;
|
||||
import org.telegram.ui.Views.BaseFragment;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class PhotoCropActivity extends BaseFragment {
|
||||
|
||||
public interface PhotoCropActivityDelegate {
|
||||
public abstract void didFinishCrop(Bitmap bitmap);
|
||||
}
|
||||
|
||||
private class PhotoCropView extends FrameLayout {
|
||||
|
||||
Paint rectPaint = null;
|
||||
Paint circlePaint = null;
|
||||
Paint halfPaint = null;
|
||||
float rectSize = 600;
|
||||
float rectX = -1, rectY = -1;
|
||||
int draggingState = 0;
|
||||
float oldX = 0, oldY = 0;
|
||||
int bitmapWidth, bitmapHeight, bitmapX, bitmapY;
|
||||
int viewWidth, viewHeight;
|
||||
|
||||
public PhotoCropView(Context context) {
|
||||
super(context);
|
||||
init();
|
||||
}
|
||||
|
||||
public PhotoCropView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init();
|
||||
}
|
||||
|
||||
public PhotoCropView(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
rectPaint = new Paint();
|
||||
rectPaint.setColor(0xfffafafa);
|
||||
rectPaint.setStrokeWidth(Utilities.dp(2));
|
||||
rectPaint.setStyle(Paint.Style.STROKE);
|
||||
circlePaint = new Paint();
|
||||
circlePaint.setColor(0x7fffffff);
|
||||
halfPaint = new Paint();
|
||||
halfPaint.setColor(0x3f000000);
|
||||
setBackgroundColor(0xff000000);
|
||||
|
||||
setOnTouchListener(new OnTouchListener() {
|
||||
@Override
|
||||
public boolean onTouch(View view, MotionEvent motionEvent) {
|
||||
float x = motionEvent.getX();
|
||||
float y = motionEvent.getY();
|
||||
int cornerSide = Utilities.dp(14);
|
||||
if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
|
||||
if (rectX - cornerSide < x && rectX + cornerSide > x && rectY - cornerSide < y && rectY + cornerSide > y) {
|
||||
draggingState = 1;
|
||||
} else if (rectX - cornerSide + rectSize < x && rectX + cornerSide + rectSize > x && rectY - cornerSide < y && rectY + cornerSide > y) {
|
||||
draggingState = 2;
|
||||
} else if (rectX - cornerSide < x && rectX + cornerSide > x && rectY - cornerSide + rectSize < y && rectY + cornerSide + rectSize > y) {
|
||||
draggingState = 3;
|
||||
} else if (rectX - cornerSide + rectSize < x && rectX + cornerSide + rectSize > x && rectY - cornerSide + rectSize < y && rectY + cornerSide + rectSize > y) {
|
||||
draggingState = 4;
|
||||
} else if (rectX < x && rectX + rectSize > x && rectY < y && rectY + rectSize > y) {
|
||||
draggingState = 5;
|
||||
} else {
|
||||
draggingState = 0;
|
||||
}
|
||||
oldX = x;
|
||||
oldY = y;
|
||||
} else if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
|
||||
draggingState = 0;
|
||||
} else if (motionEvent.getAction() == MotionEvent.ACTION_MOVE && draggingState != 0) {
|
||||
float diffX = x - oldX;
|
||||
float diffY = y - oldY;
|
||||
if (draggingState == 5) {
|
||||
rectX += diffX;
|
||||
rectY += diffY;
|
||||
|
||||
if (rectX < bitmapX) {
|
||||
rectX = bitmapX;
|
||||
} else if (rectX + rectSize > bitmapX + bitmapWidth) {
|
||||
rectX = bitmapX + bitmapWidth - rectSize;
|
||||
}
|
||||
if (rectY < bitmapY) {
|
||||
rectY = bitmapY;
|
||||
} else if (rectY + rectSize > bitmapY + bitmapHeight) {
|
||||
rectY = bitmapY + bitmapHeight - rectSize;
|
||||
}
|
||||
} else if (draggingState == 1) {
|
||||
if (rectSize - diffX < 160) {
|
||||
diffX = rectSize - 160;
|
||||
}
|
||||
if (rectX + diffX < bitmapX) {
|
||||
diffX = bitmapX - rectX;
|
||||
}
|
||||
if (rectY + diffX < bitmapY) {
|
||||
diffX = bitmapY - rectY;
|
||||
}
|
||||
rectX += diffX;
|
||||
rectY += diffX;
|
||||
rectSize -= diffX;
|
||||
} else if (draggingState == 2) {
|
||||
if (rectSize + diffX < 160) {
|
||||
diffX = -(rectSize - 160);
|
||||
}
|
||||
if (rectX + rectSize + diffX > bitmapX + bitmapWidth) {
|
||||
diffX = bitmapX + bitmapWidth - rectX - rectSize;
|
||||
}
|
||||
if (rectY - diffX < bitmapY) {
|
||||
diffX = rectY - bitmapY;
|
||||
}
|
||||
rectY -= diffX;
|
||||
rectSize += diffX;
|
||||
} else if (draggingState == 3) {
|
||||
if (rectSize - diffX < 160) {
|
||||
diffX = rectSize - 160;
|
||||
}
|
||||
if (rectX + diffX < bitmapX) {
|
||||
diffX = bitmapX - rectX;
|
||||
}
|
||||
if (rectY + rectSize - diffX > bitmapY + bitmapHeight) {
|
||||
diffX = rectY + rectSize - bitmapY - bitmapHeight;
|
||||
}
|
||||
rectX += diffX;
|
||||
rectSize -= diffX;
|
||||
} else if (draggingState == 4) {
|
||||
if (rectX + rectSize + diffX > bitmapX + bitmapWidth) {
|
||||
diffX = bitmapX + bitmapWidth - rectX - rectSize;
|
||||
}
|
||||
if (rectY + rectSize + diffX > bitmapY + bitmapHeight) {
|
||||
diffX = bitmapY + bitmapHeight - rectY - rectSize;
|
||||
}
|
||||
rectSize += diffX;
|
||||
if (rectSize < 160) {
|
||||
rectSize = 160;
|
||||
}
|
||||
}
|
||||
|
||||
oldX = x;
|
||||
oldY = y;
|
||||
invalidate();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void updateBitmapSize() {
|
||||
if (viewWidth == 0 || viewHeight == 0) {
|
||||
return;
|
||||
}
|
||||
float percX = (rectX - bitmapX) / bitmapWidth;
|
||||
float percY = (rectY - bitmapY) / bitmapHeight;
|
||||
float percSize = rectSize / bitmapWidth;
|
||||
float w = imageToCrop.getWidth();
|
||||
float h = imageToCrop.getHeight();
|
||||
float scaleX = viewWidth / w;
|
||||
float scaleY = viewHeight / h;
|
||||
if (scaleX > scaleY) {
|
||||
bitmapHeight = viewHeight;
|
||||
bitmapWidth = (int)Math.ceil(w * scaleY);
|
||||
} else {
|
||||
bitmapWidth = viewWidth;
|
||||
bitmapHeight = (int)Math.ceil(h * scaleX);
|
||||
}
|
||||
bitmapX = (viewWidth - bitmapWidth) / 2;
|
||||
bitmapY = (viewHeight - bitmapHeight) / 2;
|
||||
|
||||
if (rectX == -1 && rectY == -1) {
|
||||
if (bitmapWidth > bitmapHeight) {
|
||||
rectY = bitmapY;
|
||||
rectX = (viewWidth - bitmapHeight) / 2;
|
||||
rectSize = bitmapHeight;
|
||||
} else {
|
||||
rectX = bitmapX;
|
||||
rectY = (viewHeight - bitmapWidth) / 2;
|
||||
rectSize = bitmapWidth;
|
||||
}
|
||||
} else {
|
||||
rectX = percX * bitmapWidth + bitmapX;
|
||||
rectY = percY * bitmapHeight + bitmapY;
|
||||
rectSize = percSize * bitmapWidth;
|
||||
}
|
||||
invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
||||
super.onLayout(changed, left, top, right, bottom);
|
||||
viewWidth = right - left;
|
||||
viewHeight = bottom - top;
|
||||
updateBitmapSize();
|
||||
}
|
||||
|
||||
public Bitmap getBitmap() {
|
||||
float percX = (rectX - bitmapX) / bitmapWidth;
|
||||
float percY = (rectY - bitmapY) / bitmapHeight;
|
||||
float percSize = rectSize / bitmapWidth;
|
||||
int x = (int)(percX * imageToCrop.getWidth());
|
||||
int y = (int)(percY * imageToCrop.getHeight());
|
||||
int size = (int)(percSize * imageToCrop.getWidth());
|
||||
try {
|
||||
return Bitmap.createBitmap(imageToCrop, x, y, size, size);
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessags", e);
|
||||
System.gc();
|
||||
try {
|
||||
return Bitmap.createBitmap(imageToCrop, x, y, size, size);
|
||||
} catch (Exception e2) {
|
||||
FileLog.e("tmessages", e2);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
if (drawable != null) {
|
||||
drawable.setBounds(bitmapX, bitmapY, bitmapX + bitmapWidth, bitmapY + bitmapHeight);
|
||||
drawable.draw(canvas);
|
||||
}
|
||||
canvas.drawRect(bitmapX, bitmapY, bitmapX + bitmapWidth, rectY, halfPaint);
|
||||
canvas.drawRect(bitmapX, rectY, rectX, rectY + rectSize, halfPaint);
|
||||
canvas.drawRect(rectX + rectSize, rectY, bitmapX + bitmapWidth, rectY + rectSize, halfPaint);
|
||||
canvas.drawRect(bitmapX, rectY + rectSize, bitmapX + bitmapWidth, bitmapY + bitmapHeight, halfPaint);
|
||||
|
||||
canvas.drawRect(rectX, rectY, rectX + rectSize, rectY + rectSize, rectPaint);
|
||||
|
||||
int side = Utilities.dp(7);
|
||||
canvas.drawRect(rectX - side, rectY - side, rectX + side, rectY + side, circlePaint);
|
||||
canvas.drawRect(rectX + rectSize - side, rectY - side, rectX + rectSize + side, rectY + side, circlePaint);
|
||||
canvas.drawRect(rectX - side, rectY + rectSize - side, rectX + side, rectY + rectSize + side, circlePaint);
|
||||
canvas.drawRect(rectX + rectSize - side, rectY + rectSize - side, rectX + rectSize + side, rectY + rectSize + side, circlePaint);
|
||||
}
|
||||
}
|
||||
|
||||
private Bitmap imageToCrop;
|
||||
private BitmapDrawable drawable;
|
||||
public PhotoCropActivityDelegate delegate = null;
|
||||
private PhotoCropView view;
|
||||
private boolean sameBitmap = false;
|
||||
private boolean doneButtonPressed = false;
|
||||
|
||||
@Override
|
||||
public boolean onFragmentCreate() {
|
||||
super.onFragmentCreate();
|
||||
String photoPath = getArguments().getString("photoPath");
|
||||
if (photoPath == null) {
|
||||
return false;
|
||||
}
|
||||
File f = new File(photoPath);
|
||||
if (!f.exists()) {
|
||||
return false;
|
||||
}
|
||||
Point displaySize = new Point();
|
||||
Display display = ((WindowManager)ApplicationLoader.applicationContext.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
|
||||
if(android.os.Build.VERSION.SDK_INT < 13) {
|
||||
displaySize.set(display.getWidth(), display.getHeight());
|
||||
} else {
|
||||
display.getSize(displaySize);
|
||||
}
|
||||
int size = Math.max(displaySize.x, displaySize.y);
|
||||
imageToCrop = FileLoader.loadBitmap(photoPath, size, size);
|
||||
if (imageToCrop == null) {
|
||||
return false;
|
||||
}
|
||||
drawable = new BitmapDrawable(imageToCrop);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFragmentDestroy() {
|
||||
super.onFragmentDestroy();
|
||||
drawable = null;
|
||||
if (imageToCrop != null && !sameBitmap) {
|
||||
imageToCrop.recycle();
|
||||
imageToCrop = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
if (fragmentView == null) {
|
||||
fragmentView = view = new PhotoCropView(this.getActivity());
|
||||
fragmentView.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
|
||||
} else {
|
||||
ViewGroup parent = (ViewGroup)fragmentView.getParent();
|
||||
if (parent != null) {
|
||||
parent.removeView(fragmentView);
|
||||
}
|
||||
}
|
||||
return fragmentView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canApplyUpdateStatus() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applySelfActionBar() {
|
||||
if (parentActivity == null) {
|
||||
return;
|
||||
}
|
||||
ActionBar actionBar = parentActivity.getSupportActionBar();
|
||||
actionBar.setDisplayShowCustomEnabled(true);
|
||||
actionBar.setDisplayShowHomeEnabled(false);
|
||||
actionBar.setDisplayShowTitleEnabled(false);
|
||||
actionBar.setDisplayHomeAsUpEnabled(false);
|
||||
|
||||
actionBar.setCustomView(R.layout.settings_do_action_layout);
|
||||
View cancelButton = actionBar.getCustomView().findViewById(R.id.cancel_button);
|
||||
cancelButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
finishFragment();
|
||||
}
|
||||
});
|
||||
View doneButton = actionBar.getCustomView().findViewById(R.id.done_button);
|
||||
doneButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (delegate != null && !doneButtonPressed) {
|
||||
Bitmap bitmap = view.getBitmap();
|
||||
if (bitmap == imageToCrop) {
|
||||
sameBitmap = true;
|
||||
}
|
||||
delegate.didFinishCrop(bitmap);
|
||||
doneButtonPressed = true;
|
||||
}
|
||||
finishFragment();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if (getActivity() == null) {
|
||||
return;
|
||||
}
|
||||
((ApplicationActivity)parentActivity).updateActionBar();
|
||||
}
|
||||
}
|
|
@ -18,6 +18,7 @@ import android.graphics.Typeface;
|
|||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
|
@ -28,6 +29,7 @@ import android.widget.ImageButton;
|
|||
import android.widget.ImageView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.telegram.PhoneFormat.PhoneFormat;
|
||||
import org.telegram.TL.TLObject;
|
||||
|
@ -35,11 +37,13 @@ import org.telegram.TL.TLRPC;
|
|||
import org.telegram.messenger.ConnectionsManager;
|
||||
import org.telegram.messenger.FileLog;
|
||||
import org.telegram.messenger.MessagesController;
|
||||
import org.telegram.messenger.MessagesStorage;
|
||||
import org.telegram.messenger.NotificationCenter;
|
||||
import org.telegram.messenger.R;
|
||||
import org.telegram.messenger.RPCRequest;
|
||||
import org.telegram.messenger.UserConfig;
|
||||
import org.telegram.messenger.Utilities;
|
||||
import org.telegram.objects.PhotoObject;
|
||||
import org.telegram.ui.Views.AvatarUpdater;
|
||||
import org.telegram.ui.Views.BackupImageView;
|
||||
import org.telegram.ui.Views.BaseFragment;
|
||||
|
@ -67,6 +71,12 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
|
|||
int logoutRow;
|
||||
int sendLogsRow;
|
||||
int rowCount;
|
||||
int messagesSectionRow;
|
||||
int sendByEnterRow;
|
||||
int terminateSessionsRow;
|
||||
int photoDownloadSection;
|
||||
int photoDownloadChatRow;
|
||||
int photoDownloadPrivateRow;
|
||||
|
||||
@Override
|
||||
public boolean onFragmentCreate() {
|
||||
|
@ -83,7 +93,46 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
|
|||
ConnectionsManager.Instance.performRpc(req, new RPCRequest.RPCRequestDelegate() {
|
||||
@Override
|
||||
public void run(TLObject response, TLRPC.TL_error error) {
|
||||
|
||||
if (error == null) {
|
||||
TLRPC.User user = MessagesController.Instance.users.get(UserConfig.clientUserId);
|
||||
if (user == null) {
|
||||
user = UserConfig.currentUser;
|
||||
if (user == null) {
|
||||
return;
|
||||
}
|
||||
MessagesController.Instance.users.put(user.id, user);
|
||||
} else {
|
||||
UserConfig.currentUser = user;
|
||||
}
|
||||
if (user == null) {
|
||||
return;
|
||||
}
|
||||
TLRPC.TL_photos_photo photo = (TLRPC.TL_photos_photo)response;
|
||||
ArrayList<TLRPC.PhotoSize> sizes = photo.photo.sizes;
|
||||
TLRPC.PhotoSize smallSize = PhotoObject.getClosestPhotoSizeWithSize(sizes, 100, 100);
|
||||
TLRPC.PhotoSize bigSize = PhotoObject.getClosestPhotoSizeWithSize(sizes, 1000, 1000);
|
||||
user.photo = new TLRPC.TL_userProfilePhoto();
|
||||
user.photo.photo_id = photo.photo.id;
|
||||
if (smallSize != null) {
|
||||
user.photo.photo_small = smallSize.location;
|
||||
}
|
||||
if (bigSize != null) {
|
||||
user.photo.photo_big = bigSize.location;
|
||||
} else if (smallSize != null) {
|
||||
user.photo.photo_small = smallSize.location;
|
||||
}
|
||||
MessagesStorage.Instance.clearUserPhotos(user.id);
|
||||
ArrayList<TLRPC.User> users = new ArrayList<TLRPC.User>();
|
||||
users.add(user);
|
||||
MessagesStorage.Instance.putUsersAndChats(users, null, false, true);
|
||||
Utilities.RunOnUIThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
NotificationCenter.Instance.postNotificationName(MessagesController.updateInterfaces, MessagesController.UPDATE_MASK_ALL);
|
||||
UserConfig.saveConfig(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}, null, true, RPCRequest.RPCRequestClassGeneric);
|
||||
}
|
||||
|
@ -96,11 +145,17 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
|
|||
numberSectionRow = rowCount++;
|
||||
numberRow = rowCount++;
|
||||
settingsSectionRow = rowCount++;
|
||||
textSizeRow = rowCount++;
|
||||
enableAnimationsRow = rowCount++;
|
||||
notificationRow = rowCount++;
|
||||
blockedRow = rowCount++;
|
||||
backgroundRow = rowCount++;
|
||||
terminateSessionsRow = rowCount++;
|
||||
photoDownloadSection = rowCount++;
|
||||
photoDownloadChatRow = rowCount++;
|
||||
photoDownloadPrivateRow = rowCount++;
|
||||
messagesSectionRow = rowCount++;
|
||||
textSizeRow = rowCount++;
|
||||
sendByEnterRow = rowCount++;
|
||||
supportSectionRow = rowCount++;
|
||||
if (ConnectionsManager.DEBUG_VERSION) {
|
||||
sendLogsRow = rowCount++;
|
||||
|
@ -140,7 +195,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
|
|||
builder.setItems(new CharSequence[]{String.format("%d", 12), String.format("%d", 13), String.format("%d", 14), String.format("%d", 15), String.format("%d", 16), String.format("%d", 17), String.format("%d", 18), String.format("%d", 19), String.format("%d", 20)}, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
|
||||
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = preferences.edit();
|
||||
editor.putInt("fons_size", 12 + which);
|
||||
editor.commit();
|
||||
|
@ -152,7 +207,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
|
|||
builder.setNegativeButton(getStringEntry(R.string.Cancel), null);
|
||||
builder.show().setCanceledOnTouchOutside(true);
|
||||
} else if (i == enableAnimationsRow) {
|
||||
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
|
||||
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
||||
boolean animations = preferences.getBoolean("view_animations", true);
|
||||
SharedPreferences.Editor editor = preferences.edit();
|
||||
editor.putBoolean("view_animations", !animations);
|
||||
|
@ -174,6 +229,66 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
|
|||
((ApplicationActivity)parentActivity).presentFragment(fragment, "chat" + Math.random(), false);
|
||||
} else if (i == sendLogsRow) {
|
||||
sendLogs();
|
||||
} else if (i == sendByEnterRow) {
|
||||
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
||||
boolean send = preferences.getBoolean("send_by_enter", false);
|
||||
SharedPreferences.Editor editor = preferences.edit();
|
||||
editor.putBoolean("send_by_enter", !send);
|
||||
editor.commit();
|
||||
if (listView != null) {
|
||||
listView.invalidateViews();
|
||||
}
|
||||
} else if (i == terminateSessionsRow) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
|
||||
builder.setMessage(getStringEntry(R.string.AreYouSure));
|
||||
builder.setTitle(getStringEntry(R.string.AppName));
|
||||
builder.setPositiveButton(getStringEntry(R.string.OK), new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
TLRPC.TL_auth_resetAuthorizations req = new TLRPC.TL_auth_resetAuthorizations();
|
||||
ConnectionsManager.Instance.performRpc(req, new RPCRequest.RPCRequestDelegate() {
|
||||
@Override
|
||||
public void run(TLObject response, TLRPC.TL_error error) {
|
||||
ActionBarActivity inflaterActivity = parentActivity;
|
||||
if (inflaterActivity == null) {
|
||||
inflaterActivity = (ActionBarActivity)getActivity();
|
||||
}
|
||||
if (inflaterActivity == null) {
|
||||
return;
|
||||
}
|
||||
if (error == null && response instanceof TLRPC.TL_boolTrue) {
|
||||
Toast toast = Toast.makeText(inflaterActivity, R.string.TerminateAllSessions, Toast.LENGTH_SHORT);
|
||||
toast.show();
|
||||
} else {
|
||||
Toast toast = Toast.makeText(inflaterActivity, R.string.UnknownError, Toast.LENGTH_SHORT);
|
||||
toast.show();
|
||||
}
|
||||
UserConfig.registeredForPush = false;
|
||||
MessagesController.Instance.registerForPush(UserConfig.pushString);
|
||||
}
|
||||
}, null, true, RPCRequest.RPCRequestClassGeneric);
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton(getStringEntry(R.string.Cancel), null);
|
||||
builder.show().setCanceledOnTouchOutside(true);
|
||||
} else if (i == photoDownloadChatRow) {
|
||||
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
||||
boolean value = preferences.getBoolean("photo_download_chat", true);
|
||||
SharedPreferences.Editor editor = preferences.edit();
|
||||
editor.putBoolean("photo_download_chat", !value);
|
||||
editor.commit();
|
||||
if (listView != null) {
|
||||
listView.invalidateViews();
|
||||
}
|
||||
} else if (i == photoDownloadPrivateRow) {
|
||||
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
||||
boolean value = preferences.getBoolean("photo_download_user", true);
|
||||
SharedPreferences.Editor editor = preferences.edit();
|
||||
editor.putBoolean("photo_download_user", !value);
|
||||
editor.commit();
|
||||
if (listView != null) {
|
||||
listView.invalidateViews();
|
||||
}
|
||||
}
|
||||
// else if (i == 6) {
|
||||
// UserConfig.saveIncomingPhotos = !UserConfig.saveIncomingPhotos;
|
||||
|
@ -209,8 +324,11 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
|
|||
@Override
|
||||
public void didReceivedNotification(int id, Object... args) {
|
||||
if (id == MessagesController.updateInterfaces) {
|
||||
if (listView != null) {
|
||||
listView.invalidateViews();
|
||||
int mask = (Integer)args[0];
|
||||
if ((mask & MessagesController.UPDATE_MASK_AVATAR) != 0 || (mask & MessagesController.UPDATE_MASK_NAME) != 0) {
|
||||
if (listView != null) {
|
||||
listView.invalidateViews();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -307,7 +425,9 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
|
|||
|
||||
@Override
|
||||
public boolean isEnabled(int i) {
|
||||
return i == textSizeRow || i == enableAnimationsRow || i == blockedRow || i == notificationRow || i == backgroundRow || i == askQuestionRow || i == sendLogsRow;
|
||||
return i == textSizeRow || i == enableAnimationsRow || i == blockedRow || i == notificationRow || i == backgroundRow ||
|
||||
i == askQuestionRow || i == sendLogsRow || i == sendByEnterRow || i == terminateSessionsRow || i == photoDownloadPrivateRow ||
|
||||
i == photoDownloadChatRow;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -405,7 +525,30 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
|
|||
ConnectionsManager.Instance.performRpc(req, new RPCRequest.RPCRequestDelegate() {
|
||||
@Override
|
||||
public void run(TLObject response, TLRPC.TL_error error) {
|
||||
|
||||
if (error == null) {
|
||||
TLRPC.User user = MessagesController.Instance.users.get(UserConfig.clientUserId);
|
||||
if (user == null) {
|
||||
user = UserConfig.currentUser;
|
||||
MessagesController.Instance.users.put(user.id, user);
|
||||
} else {
|
||||
UserConfig.currentUser = user;
|
||||
}
|
||||
if (user == null) {
|
||||
return;
|
||||
}
|
||||
MessagesStorage.Instance.clearUserPhotos(user.id);
|
||||
ArrayList<TLRPC.User> users = new ArrayList<TLRPC.User>();
|
||||
users.add(user);
|
||||
MessagesStorage.Instance.putUsersAndChats(users, null, false, true);
|
||||
user.photo = (TLRPC.UserProfilePhoto)response;
|
||||
Utilities.RunOnUIThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
NotificationCenter.Instance.postNotificationName(MessagesController.updateInterfaces, MessagesController.UPDATE_MASK_ALL);
|
||||
UserConfig.saveConfig(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}, null, true, RPCRequest.RPCRequestClassGeneric);
|
||||
}
|
||||
|
@ -444,6 +587,10 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
|
|||
textView.setText(getStringEntry(R.string.SETTINGS));
|
||||
} else if (i == supportSectionRow) {
|
||||
textView.setText(getStringEntry(R.string.Support));
|
||||
} else if (i == messagesSectionRow) {
|
||||
textView.setText(getStringEntry(R.string.MessagesSettings));
|
||||
} else if (i == photoDownloadSection) {
|
||||
textView.setText(getStringEntry(R.string.AutomaticPhotoDownload));
|
||||
}
|
||||
} else if (type == 2) {
|
||||
if (view == null) {
|
||||
|
@ -468,13 +615,16 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
|
|||
divider.setVisibility(backgroundRow != 0 ? View.VISIBLE : View.INVISIBLE);
|
||||
} else if (i == backgroundRow) {
|
||||
textView.setText(getStringEntry(R.string.ChatBackground));
|
||||
divider.setVisibility(View.INVISIBLE);
|
||||
divider.setVisibility(View.VISIBLE);
|
||||
} else if (i == sendLogsRow) {
|
||||
textView.setText("Send Logs");
|
||||
divider.setVisibility(View.VISIBLE);
|
||||
} else if (i == askQuestionRow) {
|
||||
textView.setText(getStringEntry(R.string.AskAQuestion));
|
||||
divider.setVisibility(View.INVISIBLE);
|
||||
} else if (i == terminateSessionsRow) {
|
||||
textView.setText(getStringEntry(R.string.TerminateAllSessions));
|
||||
divider.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
} else if (type == 3) {
|
||||
if (view == null) {
|
||||
|
@ -483,14 +633,40 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
|
|||
}
|
||||
TextView textView = (TextView)view.findViewById(R.id.settings_row_text);
|
||||
View divider = view.findViewById(R.id.settings_row_divider);
|
||||
ImageView checkButton = (ImageView)view.findViewById(R.id.settings_row_check_button);
|
||||
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
||||
if (i == enableAnimationsRow) {
|
||||
textView.setText(getStringEntry(R.string.EnableAnimations));
|
||||
divider.setVisibility(View.VISIBLE);
|
||||
|
||||
ImageView checkButton = (ImageView)view.findViewById(R.id.settings_row_check_button);
|
||||
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
|
||||
boolean animations = preferences.getBoolean("view_animations", true);
|
||||
if (animations) {
|
||||
boolean enabled = preferences.getBoolean("view_animations", true);
|
||||
if (enabled) {
|
||||
checkButton.setImageResource(R.drawable.btn_check_on);
|
||||
} else {
|
||||
checkButton.setImageResource(R.drawable.btn_check_off);
|
||||
}
|
||||
} else if (i == sendByEnterRow) {
|
||||
textView.setText(getStringEntry(R.string.SendByEnter));
|
||||
divider.setVisibility(View.INVISIBLE);
|
||||
boolean enabled = preferences.getBoolean("send_by_enter", false);
|
||||
if (enabled) {
|
||||
checkButton.setImageResource(R.drawable.btn_check_on);
|
||||
} else {
|
||||
checkButton.setImageResource(R.drawable.btn_check_off);
|
||||
}
|
||||
} else if (i == photoDownloadChatRow) {
|
||||
textView.setText(getStringEntry(R.string.AutomaticPhotoDownloadGroups));
|
||||
divider.setVisibility(View.VISIBLE);
|
||||
boolean enabled = preferences.getBoolean("photo_download_chat", true);
|
||||
if (enabled) {
|
||||
checkButton.setImageResource(R.drawable.btn_check_on);
|
||||
} else {
|
||||
checkButton.setImageResource(R.drawable.btn_check_off);
|
||||
}
|
||||
} else if (i == photoDownloadPrivateRow) {
|
||||
textView.setText(getStringEntry(R.string.AutomaticPhotoDownloadPrivateChats));
|
||||
divider.setVisibility(View.INVISIBLE);
|
||||
boolean enabled = preferences.getBoolean("photo_download_user", true);
|
||||
if (enabled) {
|
||||
checkButton.setImageResource(R.drawable.btn_check_on);
|
||||
} else {
|
||||
checkButton.setImageResource(R.drawable.btn_check_off);
|
||||
|
@ -541,7 +717,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
|
|||
TextView detailTextView = (TextView)view.findViewById(R.id.settings_row_text_detail);
|
||||
View divider = view.findViewById(R.id.settings_row_divider);
|
||||
if (i == textSizeRow) {
|
||||
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
|
||||
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
||||
int size = preferences.getInt("fons_size", 16);
|
||||
detailTextView.setText(String.format("%d", size));
|
||||
textView.setText(ApplicationLoader.applicationContext.getString(R.string.TextSize));
|
||||
|
@ -556,13 +732,13 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
|
|||
public int getItemViewType(int i) {
|
||||
if (i == profileRow) {
|
||||
return 0;
|
||||
} else if (i == numberSectionRow || i == settingsSectionRow || i == supportSectionRow) {
|
||||
} else if (i == numberSectionRow || i == settingsSectionRow || i == supportSectionRow || i == messagesSectionRow || i == photoDownloadSection) {
|
||||
return 1;
|
||||
} else if (i == textSizeRow) {
|
||||
return 5;
|
||||
} else if (i == enableAnimationsRow) {
|
||||
} else if (i == enableAnimationsRow || i == sendByEnterRow || i == photoDownloadChatRow || i == photoDownloadPrivateRow) {
|
||||
return 3;
|
||||
} else if (i == numberRow || i == notificationRow || i == blockedRow || i == backgroundRow || i == askQuestionRow || i == sendLogsRow) {
|
||||
} else if (i == numberRow || i == notificationRow || i == blockedRow || i == backgroundRow || i == askQuestionRow || i == sendLogsRow || i == terminateSessionsRow) {
|
||||
return 2;
|
||||
} else if (i == logoutRow) {
|
||||
return 4;
|
||||
|
|
|
@ -13,7 +13,6 @@ import android.content.Context;
|
|||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.text.Html;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
|
@ -34,6 +33,7 @@ import org.telegram.messenger.NotificationCenter;
|
|||
import org.telegram.messenger.R;
|
||||
import org.telegram.messenger.RPCRequest;
|
||||
import org.telegram.messenger.Utilities;
|
||||
import org.telegram.ui.Cells.ChatOrUserCell;
|
||||
import org.telegram.ui.Views.BaseFragment;
|
||||
import org.telegram.ui.Views.OnSwipeTouchListener;
|
||||
|
||||
|
@ -118,14 +118,10 @@ public class SettingsBlockedUsers extends BaseFragment implements NotificationCe
|
|||
if (i == 0) {
|
||||
TLRPC.TL_contacts_unblock req = new TLRPC.TL_contacts_unblock();
|
||||
TLRPC.User user = MessagesController.Instance.users.get(selectedUserId);
|
||||
if (user instanceof TLRPC.TL_userForeign || user instanceof TLRPC.TL_userRequest) {
|
||||
req.id = new TLRPC.TL_inputUserForeign();
|
||||
req.id.user_id = selectedUserId;
|
||||
req.id.access_hash = user.access_hash;
|
||||
} else {
|
||||
req.id = new TLRPC.TL_inputUserContact();
|
||||
req.id.user_id = selectedUserId;
|
||||
if (user == null) {
|
||||
return;
|
||||
}
|
||||
req.id = MessagesController.getInputUser(user);
|
||||
TLRPC.TL_contactBlocked blocked = blockedContactsDict.get(selectedUserId);
|
||||
blockedContactsDict.remove(selectedUserId);
|
||||
blockedContacts.remove(blocked);
|
||||
|
@ -229,8 +225,22 @@ public class SettingsBlockedUsers extends BaseFragment implements NotificationCe
|
|||
@Override
|
||||
public void didReceivedNotification(int id, Object... args) {
|
||||
if (id == MessagesController.updateInterfaces) {
|
||||
if (listView != null) {
|
||||
listView.invalidateViews();
|
||||
int mask = (Integer)args[0];
|
||||
if ((mask & MessagesController.UPDATE_MASK_AVATAR) != 0 || (mask & MessagesController.UPDATE_MASK_NAME) != 0) {
|
||||
updateVisibleRows(mask);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateVisibleRows(int mask) {
|
||||
if (listView == null) {
|
||||
return;
|
||||
}
|
||||
int count = listView.getChildCount();
|
||||
for (int a = 0; a < count; a++) {
|
||||
View child = listView.getChildAt(a);
|
||||
if (child instanceof ChatOrUserCell) {
|
||||
((ChatOrUserCell) child).update(mask);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -307,22 +317,14 @@ public class SettingsBlockedUsers extends BaseFragment implements NotificationCe
|
|||
}
|
||||
|
||||
@Override
|
||||
public void didSelectContact(int user_id) {
|
||||
if (blockedContactsDict.containsKey(user_id)) {
|
||||
public void didSelectContact(TLRPC.User user) {
|
||||
if (user == null || blockedContactsDict.containsKey(user.id)) {
|
||||
return;
|
||||
}
|
||||
TLRPC.TL_contacts_block req = new TLRPC.TL_contacts_block();
|
||||
TLRPC.User user = MessagesController.Instance.users.get(selectedUserId);
|
||||
if (user instanceof TLRPC.TL_userForeign || user instanceof TLRPC.TL_userRequest) {
|
||||
req.id = new TLRPC.TL_inputUserForeign();
|
||||
req.id.access_hash = user.access_hash;
|
||||
req.id.user_id = user_id;
|
||||
} else {
|
||||
req.id = new TLRPC.TL_inputUserContact();
|
||||
req.id.user_id = user_id;
|
||||
}
|
||||
req.id = MessagesController.getInputUser(user);
|
||||
TLRPC.TL_contactBlocked blocked = new TLRPC.TL_contactBlocked();
|
||||
blocked.user_id = user_id;
|
||||
blocked.user_id = user.id;
|
||||
blocked.date = (int)(System.currentTimeMillis() / 1000);
|
||||
blockedContactsDict.put(blocked.user_id, blocked);
|
||||
blockedContacts.add(blocked);
|
||||
|
@ -380,41 +382,13 @@ public class SettingsBlockedUsers extends BaseFragment implements NotificationCe
|
|||
int type = getItemViewType(i);
|
||||
if (type == 0) {
|
||||
if (view == null) {
|
||||
LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
view = li.inflate(R.layout.messages_search_user_layout, viewGroup, false);
|
||||
view = new ChatOrUserCell(mContext);
|
||||
((ChatOrUserCell)view).useBoldFont = true;
|
||||
((ChatOrUserCell)view).usePadding = false;
|
||||
((ChatOrUserCell)view).useSeparator = true;
|
||||
}
|
||||
ContactsActivity.ContactListRowHolder holder = (ContactsActivity.ContactListRowHolder)view.getTag();
|
||||
if (holder == null) {
|
||||
holder = new ContactsActivity.ContactListRowHolder(view);
|
||||
view.setTag(holder);
|
||||
}
|
||||
|
||||
View divider = view.findViewById(R.id.settings_row_divider);
|
||||
divider.setVisibility(View.VISIBLE);
|
||||
|
||||
TLRPC.User user = MessagesController.Instance.users.get(blockedContacts.get(i).user_id);
|
||||
|
||||
TLRPC.FileLocation photo = null;
|
||||
if (user.first_name.length() != 0 && user.last_name.length() != 0) {
|
||||
holder.nameTextView.setText(Html.fromHtml(user.first_name + " <b>" + user.last_name + "</b>"));
|
||||
} else if (user.first_name.length() != 0) {
|
||||
holder.nameTextView.setText(Html.fromHtml("<b>" + user.first_name + "</b>"));
|
||||
} else {
|
||||
holder.nameTextView.setText(Html.fromHtml("<b>" + user.last_name + "</b>"));
|
||||
}
|
||||
if (user.photo != null) {
|
||||
photo = user.photo.photo_small;
|
||||
}
|
||||
int placeHolderId = Utilities.getUserAvatarForId(user.id);
|
||||
holder.avatarImage.setImage(photo, "50_50", placeHolderId);
|
||||
|
||||
holder.messageTextView.setTextColor(0xff808080);
|
||||
|
||||
if (user.phone != null && user.phone.length() != 0) {
|
||||
holder.messageTextView.setText(PhoneFormat.Instance.format("+" + user.phone));
|
||||
} else {
|
||||
holder.messageTextView.setText("Unknown");
|
||||
}
|
||||
((ChatOrUserCell)view).setData(user, null, null, null, user.phone != null && user.phone.length() != 0 ? PhoneFormat.Instance.format("+" + user.phone) : "Unknown");
|
||||
} else if (type == 1) {
|
||||
if (view == null) {
|
||||
LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
|
|
|
@ -82,7 +82,7 @@ public class SettingsChangeNameActivity extends BaseFragment {
|
|||
}
|
||||
});
|
||||
|
||||
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
|
||||
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
||||
boolean animations = preferences.getBoolean("view_animations", true);
|
||||
if (!animations) {
|
||||
firstNameField.requestFocus();
|
||||
|
@ -171,6 +171,9 @@ public class SettingsChangeNameActivity extends BaseFragment {
|
|||
|
||||
private void saveName() {
|
||||
TLRPC.TL_account_updateProfile req = new TLRPC.TL_account_updateProfile();
|
||||
if (UserConfig.currentUser == null || lastNameField.getText() == null || firstNameField.getText() == null) {
|
||||
return;
|
||||
}
|
||||
UserConfig.currentUser.first_name = req.first_name = firstNameField.getText().toString();
|
||||
UserConfig.currentUser.last_name = req.last_name = lastNameField.getText().toString();
|
||||
TLRPC.User user = MessagesController.Instance.users.get(UserConfig.clientUserId);
|
||||
|
@ -179,7 +182,7 @@ public class SettingsChangeNameActivity extends BaseFragment {
|
|||
user.last_name = req.last_name;
|
||||
}
|
||||
UserConfig.saveConfig(true);
|
||||
NotificationCenter.Instance.postNotificationName(MessagesController.updateInterfaces, MessagesController.UPDATE_MASK_ALL);
|
||||
NotificationCenter.Instance.postNotificationName(MessagesController.updateInterfaces, MessagesController.UPDATE_MASK_NAME);
|
||||
ConnectionsManager.Instance.performRpc(req, new RPCRequest.RPCRequestDelegate() {
|
||||
@Override
|
||||
public void run(TLObject response, TLRPC.TL_error error) {
|
||||
|
|
|
@ -34,6 +34,7 @@ import org.telegram.TL.TLObject;
|
|||
import org.telegram.TL.TLRPC;
|
||||
import org.telegram.messenger.ConnectionsManager;
|
||||
import org.telegram.messenger.FileLog;
|
||||
import org.telegram.messenger.MessagesController;
|
||||
import org.telegram.messenger.R;
|
||||
import org.telegram.messenger.RPCRequest;
|
||||
import org.telegram.messenger.Utilities;
|
||||
|
@ -138,7 +139,7 @@ public class SettingsNotificationsActivity extends BaseFragment {
|
|||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
} else if (i == 15) {
|
||||
} else if (i == 17) {
|
||||
if (reseting) {
|
||||
return;
|
||||
}
|
||||
|
@ -150,6 +151,7 @@ public class SettingsNotificationsActivity extends BaseFragment {
|
|||
Utilities.RunOnUIThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MessagesController.Instance.enableJoined = true;
|
||||
ActionBarActivity inflaterActivity = parentActivity;
|
||||
if (inflaterActivity == null) {
|
||||
inflaterActivity = (ActionBarActivity)getActivity();
|
||||
|
@ -190,6 +192,14 @@ public class SettingsNotificationsActivity extends BaseFragment {
|
|||
editor.putBoolean("EnableInAppPreview", !enabled);
|
||||
editor.commit();
|
||||
listView.invalidateViews();
|
||||
} else if (i == 15) {
|
||||
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = preferences.edit();
|
||||
boolean enabled = preferences.getBoolean("EnableContactJoined", true);
|
||||
MessagesController.Instance.enableJoined = !enabled;
|
||||
editor.putBoolean("EnableContactJoined", !enabled);
|
||||
editor.commit();
|
||||
listView.invalidateViews();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -318,12 +328,15 @@ public class SettingsNotificationsActivity extends BaseFragment {
|
|||
public boolean isEnabled(int i) {
|
||||
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
|
||||
boolean enabledAll = preferences.getBoolean("EnableAll", true);
|
||||
return !(i != 1 && !enabledAll && i != 13) && (i > 0 && i < 5 || i > 5 && i < 10 || i > 10 && i < 14 || i == 15);
|
||||
if (i == 17 || i == 15) {
|
||||
return true;
|
||||
}
|
||||
return !(i != 1 && !enabledAll && i != 13) && (i > 0 && i < 5 || i > 5 && i < 10 || i > 10 && i < 14);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return 16;
|
||||
return 18;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -357,6 +370,8 @@ public class SettingsNotificationsActivity extends BaseFragment {
|
|||
} else if (i == 10) {
|
||||
textView.setText(getStringEntry(R.string.InAppNotifications));
|
||||
} else if (i == 14) {
|
||||
textView.setText(getStringEntry(R.string.Events));
|
||||
} else if (i == 16) {
|
||||
textView.setText(getStringEntry(R.string.Reset));
|
||||
}
|
||||
} if (type == 1) {
|
||||
|
@ -408,13 +423,17 @@ public class SettingsNotificationsActivity extends BaseFragment {
|
|||
enabled = preferences.getBoolean("EnableInAppPreview", true);
|
||||
textView.setText(getStringEntry(R.string.InAppPreview));
|
||||
divider.setVisibility(View.INVISIBLE);
|
||||
} else if (i == 15) {
|
||||
enabled = preferences.getBoolean("EnableContactJoined", true);
|
||||
textView.setText(getStringEntry(R.string.ContactJoined));
|
||||
divider.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
if (enabled) {
|
||||
checkButton.setImageResource(R.drawable.btn_check_on);
|
||||
} else {
|
||||
checkButton.setImageResource(R.drawable.btn_check_off);
|
||||
}
|
||||
if (i != 1 && !enabledAll) {
|
||||
if (i != 1 && !enabledAll && i != 15) {
|
||||
view.setEnabled(false);
|
||||
if(android.os.Build.VERSION.SDK_INT >= 11) {
|
||||
checkButton.setAlpha(0.3f);
|
||||
|
@ -455,12 +474,12 @@ public class SettingsNotificationsActivity extends BaseFragment {
|
|||
}
|
||||
textView.setText(getStringEntry(R.string.Sound));
|
||||
divider.setVisibility(View.INVISIBLE);
|
||||
} else if (i == 15) {
|
||||
} else if (i == 17) {
|
||||
textView.setText(getStringEntry(R.string.ResetAllNotifications));
|
||||
textViewDetail.setText(getStringEntry(R.string.UndoAllCustom));
|
||||
divider.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
if (i != 15 && !enabledAll) {
|
||||
if (i != 17 && !enabledAll) {
|
||||
view.setEnabled(false);
|
||||
if(android.os.Build.VERSION.SDK_INT >= 11) {
|
||||
textView.setAlpha(0.3f);
|
||||
|
@ -482,9 +501,9 @@ public class SettingsNotificationsActivity extends BaseFragment {
|
|||
|
||||
@Override
|
||||
public int getItemViewType(int i) {
|
||||
if (i == 0 || i == 5 || i == 10 || i == 14) {
|
||||
if (i == 0 || i == 5 || i == 10 || i == 14 || i == 16) {
|
||||
return 0;
|
||||
} else if (i > 0 && i < 4 || i > 5 && i < 9 || i > 10 && i < 14) {
|
||||
} else if (i > 0 && i < 4 || i > 5 && i < 9 || i > 10 && i < 14 || i == 15) {
|
||||
return 1;
|
||||
} else {
|
||||
return 2;
|
||||
|
|
|
@ -73,7 +73,7 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica
|
|||
NotificationCenter.Instance.addObserver(this, FileLoader.FileLoadProgressChanged);
|
||||
NotificationCenter.Instance.addObserver(this, MessagesStorage.wallpapersDidLoaded);
|
||||
|
||||
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
|
||||
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
||||
selectedBackground = preferences.getInt("selectedBackground", 1000001);
|
||||
selectedColor = preferences.getInt("selectedColor", 0);
|
||||
MessagesStorage.Instance.getWallpapers();
|
||||
|
@ -165,7 +165,7 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica
|
|||
}
|
||||
|
||||
if (done) {
|
||||
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
|
||||
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = preferences.edit();
|
||||
editor.putInt("selectedBackground", selectedBackground);
|
||||
editor.putInt("selectedColor", selectedColor);
|
||||
|
@ -246,11 +246,11 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica
|
|||
progressBar.setVisibility(View.VISIBLE);
|
||||
loadingSize = size;
|
||||
selectedColor = 0;
|
||||
FileLoader.Instance.loadFile(null, size, null);
|
||||
FileLoader.Instance.loadFile(null, size, null, null);
|
||||
backgroundImage.setBackgroundColor(0);
|
||||
} else {
|
||||
if (loadingFile != null) {
|
||||
FileLoader.Instance.cancelLoadFile(null, loadingSize, null);
|
||||
FileLoader.Instance.cancelLoadFile(null, loadingSize, null, null);
|
||||
}
|
||||
loadingFileObject = null;
|
||||
loadingFile = null;
|
||||
|
@ -263,7 +263,7 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica
|
|||
}
|
||||
} else {
|
||||
if (loadingFile != null) {
|
||||
FileLoader.Instance.cancelLoadFile(null, loadingSize, null);
|
||||
FileLoader.Instance.cancelLoadFile(null, loadingSize, null, null);
|
||||
}
|
||||
if (selectedBackground == 1000001) {
|
||||
backgroundImage.setImageResource(R.drawable.background_hd);
|
||||
|
|
|
@ -21,6 +21,7 @@ import android.net.Uri;
|
|||
import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
|
@ -39,6 +40,7 @@ import org.telegram.PhoneFormat.PhoneFormat;
|
|||
import org.telegram.TL.TLObject;
|
||||
import org.telegram.TL.TLRPC;
|
||||
import org.telegram.messenger.ConnectionsManager;
|
||||
import org.telegram.messenger.ContactsController;
|
||||
import org.telegram.messenger.FileLog;
|
||||
import org.telegram.messenger.MessagesController;
|
||||
import org.telegram.messenger.MessagesStorage;
|
||||
|
@ -51,6 +53,8 @@ import org.telegram.ui.Views.BaseFragment;
|
|||
import org.telegram.ui.Views.IdenticonView;
|
||||
import org.telegram.ui.Views.OnSwipeTouchListener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class UserProfileActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate, MessagesActivity.MessagesActivityDelegate {
|
||||
private ListView listView;
|
||||
private ListAdapter listAdapter;
|
||||
|
@ -74,7 +78,7 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen
|
|||
if (dialog_id != 0) {
|
||||
currentEncryptedChat = MessagesController.Instance.encryptedChats.get((int)(dialog_id >> 32));
|
||||
}
|
||||
return true;
|
||||
return MessagesController.Instance.users.get(user_id) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -104,7 +108,7 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen
|
|||
@Override
|
||||
public void onClick(View view) {
|
||||
creatingChat = true;
|
||||
MessagesController.Instance.startSecretChat(parentActivity, user_id);
|
||||
MessagesController.Instance.startSecretChat(parentActivity, MessagesController.Instance.users.get(user_id));
|
||||
}
|
||||
});
|
||||
if (dialog_id == 0) {
|
||||
|
@ -282,8 +286,11 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen
|
|||
|
||||
public void didReceivedNotification(int id, Object... args) {
|
||||
if (id == MessagesController.updateInterfaces) {
|
||||
if (listView != null) {
|
||||
listView.invalidateViews();
|
||||
int mask = (Integer)args[0];
|
||||
if ((mask & MessagesController.UPDATE_MASK_AVATAR) != 0 || (mask & MessagesController.UPDATE_MASK_NAME) != 0) {
|
||||
if (listView != null) {
|
||||
listView.invalidateViews();
|
||||
}
|
||||
}
|
||||
} else if (id == MessagesController.contactsDidLoaded) {
|
||||
if (parentActivity != null) {
|
||||
|
@ -409,16 +416,12 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen
|
|||
finishFragment();
|
||||
break;
|
||||
case R.id.block_contact: {
|
||||
TLRPC.TL_contacts_block req = new TLRPC.TL_contacts_block();
|
||||
TLRPC.User user = MessagesController.Instance.users.get(user_id);
|
||||
if (user instanceof TLRPC.TL_userForeign || user instanceof TLRPC.TL_userRequest) {
|
||||
req.id = new TLRPC.TL_inputUserForeign();
|
||||
req.id.access_hash = user.access_hash;
|
||||
req.id.user_id = user_id;
|
||||
} else {
|
||||
req.id = new TLRPC.TL_inputUserContact();
|
||||
req.id.user_id = user_id;
|
||||
if (user == null) {
|
||||
break;
|
||||
}
|
||||
TLRPC.TL_contacts_block req = new TLRPC.TL_contacts_block();
|
||||
req.id = MessagesController.getInputUser(user);
|
||||
TLRPC.TL_contactBlocked blocked = new TLRPC.TL_contactBlocked();
|
||||
blocked.user_id = user_id;
|
||||
blocked.date = (int)(System.currentTimeMillis() / 1000);
|
||||
|
@ -449,14 +452,45 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen
|
|||
((ApplicationActivity)parentActivity).presentFragment(fragment, "chat_select", false);
|
||||
break;
|
||||
}
|
||||
case R.id.edit_contact: {
|
||||
ContactAddActivity fragment = new ContactAddActivity();
|
||||
Bundle args = new Bundle();
|
||||
args.putInt("user_id", user_id);
|
||||
fragment.setArguments(args);
|
||||
((ApplicationActivity)parentActivity).presentFragment(fragment, "add_contact_" + user_id, false);
|
||||
break;
|
||||
}
|
||||
case R.id.delete_contact: {
|
||||
final TLRPC.User user = MessagesController.Instance.users.get(user_id);
|
||||
if (user == null) {
|
||||
break;
|
||||
}
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
|
||||
builder.setMessage(getStringEntry(R.string.AreYouSure));
|
||||
builder.setTitle(getStringEntry(R.string.AppName));
|
||||
builder.setPositiveButton(getStringEntry(R.string.OK), new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
ArrayList<TLRPC.User> arrayList = new ArrayList<TLRPC.User>();
|
||||
arrayList.add(user);
|
||||
ContactsController.Instance.deleteContact(arrayList);
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton(getStringEntry(R.string.Cancel), null);
|
||||
builder.show().setCanceledOnTouchOutside(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
if (MessagesController.Instance.contactsDict.get(user_id) == null) {
|
||||
if (ContactsController.Instance.contactsDict.get(user_id) == null) {
|
||||
TLRPC.User user = MessagesController.Instance.users.get(user_id);
|
||||
if (user == null) {
|
||||
return;
|
||||
}
|
||||
if (user.phone != null && user.phone.length() != 0) {
|
||||
inflater.inflate(R.menu.user_profile_menu, menu);
|
||||
} else {
|
||||
|
@ -608,7 +642,7 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen
|
|||
if (value == 0) {
|
||||
value = user.status.expires;
|
||||
}
|
||||
onlineText.setText(String.format("%s %s", getStringEntry(R.string.LastSeen), Utilities.formatDateOnline(value)));
|
||||
onlineText.setText(Utilities.formatDateOnline(value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -661,12 +695,19 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen
|
|||
FileLog.e("tmessages", e);
|
||||
}
|
||||
} else if (i == 0) {
|
||||
ActionBarActivity inflaterActivity = parentActivity;
|
||||
if (inflaterActivity == null) {
|
||||
inflaterActivity = (ActionBarActivity)getActivity();
|
||||
}
|
||||
if (inflaterActivity == null) {
|
||||
return;
|
||||
}
|
||||
int sdk = android.os.Build.VERSION.SDK_INT;
|
||||
if(sdk < android.os.Build.VERSION_CODES.HONEYCOMB) {
|
||||
android.text.ClipboardManager clipboard = (android.text.ClipboardManager)parentActivity.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
android.text.ClipboardManager clipboard = (android.text.ClipboardManager)inflaterActivity.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
clipboard.setText(selectedPhone);
|
||||
} else {
|
||||
android.content.ClipboardManager clipboard = (android.content.ClipboardManager)parentActivity.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
android.content.ClipboardManager clipboard = (android.content.ClipboardManager)inflaterActivity.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
android.content.ClipData clip = android.content.ClipData.newPlainText("label", selectedPhone);
|
||||
clipboard.setPrimaryClip(clip);
|
||||
}
|
||||
|
|
|
@ -10,11 +10,10 @@ package org.telegram.ui.Views;
|
|||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.Bitmap;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.provider.MediaStore;
|
||||
import android.support.v4.app.Fragment;
|
||||
|
||||
import org.telegram.TL.TLRPC;
|
||||
import org.telegram.messenger.FileLoader;
|
||||
|
@ -22,17 +21,19 @@ import org.telegram.messenger.FileLog;
|
|||
import org.telegram.messenger.NotificationCenter;
|
||||
import org.telegram.messenger.UserConfig;
|
||||
import org.telegram.messenger.Utilities;
|
||||
import org.telegram.ui.ApplicationActivity;
|
||||
import org.telegram.ui.PhotoCropActivity;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class AvatarUpdater implements NotificationCenter.NotificationCenterDelegate {
|
||||
public class AvatarUpdater implements NotificationCenter.NotificationCenterDelegate, PhotoCropActivity.PhotoCropActivityDelegate {
|
||||
public String currentPicturePath;
|
||||
private TLRPC.PhotoSize smallPhoto;
|
||||
private TLRPC.PhotoSize bigPhoto;
|
||||
public String uploadingAvatar = null;
|
||||
File picturePath = null;
|
||||
public Activity parentActivity = null;
|
||||
public Fragment parentFragment = null;
|
||||
public BaseFragment parentFragment = null;
|
||||
public AvatarUpdaterDelegate delegate;
|
||||
private boolean clearAfterUpdate = false;
|
||||
public boolean returnOnly = false;
|
||||
|
@ -85,22 +86,38 @@ public class AvatarUpdater implements NotificationCenter.NotificationCenterDeleg
|
|||
|
||||
private void startCrop(String path) {
|
||||
try {
|
||||
Intent cropIntent = new Intent("com.android.camera.action.CROP");
|
||||
cropIntent.setDataAndType(Uri.fromFile(new File(path)), "image/*");
|
||||
cropIntent.putExtra("crop", "true");
|
||||
cropIntent.putExtra("aspectX", 1);
|
||||
cropIntent.putExtra("aspectY", 1);
|
||||
cropIntent.putExtra("outputX", 800);
|
||||
cropIntent.putExtra("outputY", 800);
|
||||
cropIntent.putExtra("scale", true);
|
||||
cropIntent.putExtra("return-data", false);
|
||||
picturePath = Utilities.generatePicturePath();
|
||||
cropIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(picturePath));
|
||||
cropIntent.putExtra("output", Uri.fromFile(picturePath));
|
||||
if (parentFragment != null) {
|
||||
parentFragment.startActivityForResult(cropIntent, 2);
|
||||
} else if (parentActivity != null) {
|
||||
parentActivity.startActivityForResult(cropIntent, 2);
|
||||
ApplicationActivity activity = (ApplicationActivity)parentFragment.parentActivity;
|
||||
if (activity == null) {
|
||||
activity = (ApplicationActivity)parentFragment.getActivity();
|
||||
}
|
||||
if (activity == null) {
|
||||
return;
|
||||
}
|
||||
Bundle params = new Bundle();
|
||||
params.putString("photoPath", path);
|
||||
PhotoCropActivity photoCropActivity = new PhotoCropActivity();
|
||||
photoCropActivity.delegate = this;
|
||||
photoCropActivity.setArguments(params);
|
||||
activity.presentFragment(photoCropActivity, "crop", false);
|
||||
} else {
|
||||
Intent cropIntent = new Intent("com.android.camera.action.CROP");
|
||||
cropIntent.setDataAndType(Uri.fromFile(new File(path)), "image/*");
|
||||
cropIntent.putExtra("crop", "true");
|
||||
cropIntent.putExtra("aspectX", 1);
|
||||
cropIntent.putExtra("aspectY", 1);
|
||||
cropIntent.putExtra("outputX", 800);
|
||||
cropIntent.putExtra("outputY", 800);
|
||||
cropIntent.putExtra("scale", true);
|
||||
cropIntent.putExtra("return-data", false);
|
||||
picturePath = Utilities.generatePicturePath();
|
||||
cropIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(picturePath));
|
||||
cropIntent.putExtra("output", Uri.fromFile(picturePath));
|
||||
if (parentFragment != null) {
|
||||
parentFragment.startActivityForResult(cropIntent, 2);
|
||||
} else if (parentActivity != null) {
|
||||
parentActivity.startActivityForResult(cropIntent, 2);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
|
@ -120,26 +137,15 @@ public class AvatarUpdater implements NotificationCenter.NotificationCenterDeleg
|
|||
if (data == null) {
|
||||
return;
|
||||
}
|
||||
Uri imageUri = data.getData();
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
if (parentFragment != null) {
|
||||
cursor = parentFragment.getActivity().getContentResolver().query(imageUri, new String[]{android.provider.MediaStore.Images.ImageColumns.DATA}, null, null, null);
|
||||
} else if (parentActivity != null) {
|
||||
cursor = parentActivity.getContentResolver().query(imageUri, new String[]{android.provider.MediaStore.Images.ImageColumns.DATA}, null, null, null);
|
||||
Uri imageUri = data.getData();
|
||||
if (imageUri != null) {
|
||||
String imageFilePath = Utilities.getPath(imageUri);
|
||||
startCrop(imageFilePath);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
return;
|
||||
}
|
||||
if (cursor == null) {
|
||||
return;
|
||||
}
|
||||
if (cursor.moveToFirst()) {
|
||||
String imageFilePath = cursor.getString(0);
|
||||
startCrop(imageFilePath);
|
||||
}
|
||||
cursor.close();
|
||||
} else if (requestCode == 2) {
|
||||
Bitmap bitmap = FileLoader.loadBitmap(picturePath.getAbsolutePath(), 800, 800);
|
||||
processBitmap(bitmap);
|
||||
|
@ -168,6 +174,11 @@ public class AvatarUpdater implements NotificationCenter.NotificationCenterDeleg
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void didFinishCrop(Bitmap bitmap) {
|
||||
processBitmap(bitmap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void didReceivedNotification(int id, final Object... args) {
|
||||
if (id == FileLoader.FileDidUpload) {
|
||||
|
|
|
@ -0,0 +1,169 @@
|
|||
/*
|
||||
* This is the source code of Telegram for Android v. 1.3.x.
|
||||
* It is licensed under GNU GPL v. 2 or later.
|
||||
* You should have received a copy of the license in this archive (see LICENSE).
|
||||
*
|
||||
* Copyright Nikolai Kudashov, 2013.
|
||||
*/
|
||||
|
||||
package org.telegram.ui.Views;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.view.View;
|
||||
|
||||
import org.telegram.TL.TLRPC;
|
||||
import org.telegram.messenger.FileLoader;
|
||||
import org.telegram.messenger.FileLog;
|
||||
import org.telegram.messenger.Utilities;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
public class ImageReceiver {
|
||||
private TLRPC.FileLocation last_path = null;
|
||||
private String last_httpUrl = null;
|
||||
private String last_filter = null;
|
||||
private Drawable last_placeholder = null;
|
||||
private int last_size = 0;
|
||||
private String currentPath = null;
|
||||
private boolean isPlaceholder = false;
|
||||
private Drawable currentImage = null;
|
||||
public Integer TAG = null;
|
||||
public WeakReference<View> parentView = null;
|
||||
public int imageX = 0, imageY = 0, imageW = 0, imageH = 0;
|
||||
|
||||
public void setImage(TLRPC.FileLocation path, String filter, Drawable placeholder) {
|
||||
setImage(path, null, filter, placeholder, 0);
|
||||
}
|
||||
|
||||
public void setImage(TLRPC.FileLocation path, String filter, Drawable placeholder, int size) {
|
||||
setImage(path, null, filter, placeholder, size);
|
||||
}
|
||||
|
||||
public void setImage(String path, String filter, Drawable placeholder) {
|
||||
setImage(null, path, filter, placeholder, 0);
|
||||
}
|
||||
|
||||
public void setImage(TLRPC.FileLocation path, String httpUrl, String filter, Drawable placeholder, int size) {
|
||||
if ((path == null && httpUrl == null) || (path != null && !(path instanceof TLRPC.TL_fileLocation) && !(path instanceof TLRPC.TL_fileEncryptedLocation))) {
|
||||
recycleBitmap(null);
|
||||
currentPath = null;
|
||||
isPlaceholder = true;
|
||||
last_path = null;
|
||||
last_httpUrl = null;
|
||||
last_filter = null;
|
||||
last_placeholder = placeholder;
|
||||
last_size = 0;
|
||||
currentImage = null;
|
||||
FileLoader.Instance.cancelLoadingForImageView(this);
|
||||
return;
|
||||
}
|
||||
String key;
|
||||
if (path != null) {
|
||||
key = path.volume_id + "_" + path.local_id;
|
||||
} else {
|
||||
key = Utilities.MD5(httpUrl);
|
||||
}
|
||||
if (filter != null) {
|
||||
key += "@" + filter;
|
||||
}
|
||||
Bitmap img;
|
||||
if (currentPath != null) {
|
||||
if (currentPath.equals(key)) {
|
||||
return;
|
||||
} else {
|
||||
img = FileLoader.Instance.getImageFromMemory(path, httpUrl, this, filter, true);
|
||||
recycleBitmap(img);
|
||||
}
|
||||
} else {
|
||||
img = FileLoader.Instance.getImageFromMemory(path, httpUrl, this, filter, true);
|
||||
}
|
||||
currentPath = key;
|
||||
last_path = path;
|
||||
last_httpUrl = httpUrl;
|
||||
last_filter = filter;
|
||||
last_placeholder = placeholder;
|
||||
last_size = size;
|
||||
if (img == null) {
|
||||
isPlaceholder = true;
|
||||
FileLoader.Instance.loadImage(path, httpUrl, this, filter, true, size);
|
||||
} else {
|
||||
setImageBitmap(img, currentPath);
|
||||
}
|
||||
}
|
||||
|
||||
public void setImageBitmap(Bitmap bitmap, String imgKey) {
|
||||
if (currentPath == null || !imgKey.equals(currentPath)) {
|
||||
return;
|
||||
}
|
||||
isPlaceholder = false;
|
||||
FileLoader.Instance.incrementUseCount(currentPath);
|
||||
currentImage = new BitmapDrawable(null, bitmap);
|
||||
if (parentView.get() != null) {
|
||||
if (imageW != 0) {
|
||||
parentView.get().invalidate(imageX, imageY, imageX + imageW, imageY + imageH);
|
||||
} else {
|
||||
parentView.get().invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void clearImage() {
|
||||
recycleBitmap(null);
|
||||
}
|
||||
|
||||
private void recycleBitmap(Bitmap newBitmap) {
|
||||
if (currentImage == null || isPlaceholder) {
|
||||
return;
|
||||
}
|
||||
if (currentImage instanceof BitmapDrawable) {
|
||||
Bitmap bitmap = ((BitmapDrawable)currentImage).getBitmap();
|
||||
if (bitmap != null && bitmap != newBitmap) {
|
||||
if (currentPath != null) {
|
||||
boolean canDelete = FileLoader.Instance.decrementUseCount(currentPath);
|
||||
if (!FileLoader.Instance.isInCache(currentPath)) {
|
||||
if (FileLoader.Instance.runtimeHack != null) {
|
||||
FileLoader.Instance.runtimeHack.trackAlloc(bitmap.getRowBytes() * bitmap.getHeight());
|
||||
}
|
||||
if (canDelete) {
|
||||
currentImage = null;
|
||||
if (Build.VERSION.SDK_INT < 11) {
|
||||
bitmap.recycle();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
currentImage = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void draw(Canvas canvas, int x, int y, int w, int h) {
|
||||
try {
|
||||
if (currentImage != null) {
|
||||
currentImage.setBounds(x, y, x + w, y + h);
|
||||
currentImage.draw(canvas);
|
||||
} else if (last_placeholder != null) {
|
||||
last_placeholder.setBounds(x, y, x + w, y + h);
|
||||
last_placeholder.draw(canvas);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (currentPath != null) {
|
||||
FileLoader.Instance.removeImage(currentPath);
|
||||
currentPath = null;
|
||||
}
|
||||
setImage(last_path, last_httpUrl, last_filter, last_placeholder, last_size);
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void finalize() throws Throwable {
|
||||
recycleBitmap(null);
|
||||
super.finalize();
|
||||
}
|
||||
}
|
|
@ -40,11 +40,19 @@ public class LayoutListView extends ListView {
|
|||
post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
setSelectionFromTop(scrollTo, offset - getPaddingTop());
|
||||
try {
|
||||
setSelectionFromTop(scrollTo, offset - getPaddingTop());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
super.onLayout(changed, left, top, right, bottom);
|
||||
try {
|
||||
super.onLayout(changed, left, top, right, bottom);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
height = (bottom - top);
|
||||
}
|
||||
|
|
|
@ -32,7 +32,6 @@ import org.telegram.messenger.Utilities;
|
|||
import org.telegram.objects.MessageObject;
|
||||
import org.telegram.ui.ApplicationLoader;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
|
@ -52,7 +51,7 @@ public class NotificationView extends LinearLayout {
|
|||
private int currentUserId = 0;
|
||||
private int currentEncId = 0;
|
||||
private boolean isVisible;
|
||||
private boolean isRTL = false;
|
||||
private final Integer timerSync = 1;
|
||||
|
||||
public NotificationView(Context context) {
|
||||
super(context);
|
||||
|
@ -78,9 +77,11 @@ public class NotificationView extends LinearLayout {
|
|||
@Override
|
||||
public void onClick(View v) {
|
||||
try {
|
||||
if (hideTimer != null) {
|
||||
hideTimer.cancel();
|
||||
hideTimer = null;
|
||||
synchronized (timerSync) {
|
||||
if (hideTimer != null) {
|
||||
hideTimer.cancel();
|
||||
hideTimer = null;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
|
@ -89,19 +90,15 @@ public class NotificationView extends LinearLayout {
|
|||
}
|
||||
});
|
||||
|
||||
Locale locale = Locale.getDefault();
|
||||
String lang = locale.getLanguage();
|
||||
if (lang != null && lang.toLowerCase().equals("ar")) {
|
||||
isRTL = true;
|
||||
}
|
||||
|
||||
this.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
try {
|
||||
if (hideTimer != null) {
|
||||
hideTimer.cancel();
|
||||
hideTimer = null;
|
||||
synchronized (timerSync) {
|
||||
if (hideTimer != null) {
|
||||
hideTimer.cancel();
|
||||
hideTimer = null;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
|
@ -211,9 +208,11 @@ public class NotificationView extends LinearLayout {
|
|||
avatarImage.setImage(photo, "50_50", Utilities.getUserAvatarForId(user.id));
|
||||
|
||||
try {
|
||||
if (hideTimer != null) {
|
||||
hideTimer.cancel();
|
||||
hideTimer = null;
|
||||
synchronized (timerSync) {
|
||||
if (hideTimer != null) {
|
||||
hideTimer.cancel();
|
||||
hideTimer = null;
|
||||
}
|
||||
}
|
||||
hideTimer = new Timer();
|
||||
hideTimer.schedule(new TimerTask() {
|
||||
|
@ -226,8 +225,12 @@ public class NotificationView extends LinearLayout {
|
|||
}
|
||||
});
|
||||
try {
|
||||
hideTimer.cancel();
|
||||
hideTimer = null;
|
||||
synchronized (timerSync) {
|
||||
if (hideTimer != null) {
|
||||
hideTimer.cancel();
|
||||
hideTimer = null;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
|
@ -251,9 +254,11 @@ public class NotificationView extends LinearLayout {
|
|||
startAnimation(animHide);
|
||||
} else {
|
||||
try {
|
||||
if (hideTimer != null) {
|
||||
hideTimer.cancel();
|
||||
hideTimer = null;
|
||||
synchronized (timerSync) {
|
||||
if (hideTimer != null) {
|
||||
hideTimer.cancel();
|
||||
hideTimer = null;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
|
@ -300,7 +305,7 @@ public class NotificationView extends LinearLayout {
|
|||
messageTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
|
||||
nameTextView.setPadding(0, Utilities.dp(2), 0, 0);
|
||||
messageTextView.setPadding(0, Utilities.dp(18), 0, 0);
|
||||
if (isRTL) {
|
||||
if (Utilities.isRTL) {
|
||||
params1.setMargins(Utilities.dp(40), 0, height + Utilities.dp(6), 0);
|
||||
} else {
|
||||
params1.setMargins(height + Utilities.dp(6), 0, Utilities.dp(40), 0);
|
||||
|
@ -310,7 +315,7 @@ public class NotificationView extends LinearLayout {
|
|||
messageTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15);
|
||||
nameTextView.setPadding(0, Utilities.dp(4), 0, 0);
|
||||
messageTextView.setPadding(0, Utilities.dp(24), 0, 0);
|
||||
if (isRTL) {
|
||||
if (Utilities.isRTL) {
|
||||
params1.setMargins(Utilities.dp(40), 0, height + Utilities.dp(8), 0);
|
||||
} else {
|
||||
params1.setMargins(height + Utilities.dp(8), 0, Utilities.dp(40), 0);
|
||||
|
|
|
@ -256,7 +256,7 @@ public class PagerSlidingTabStrip extends HorizontalScrollView {
|
|||
});
|
||||
|
||||
tabsContainer.addView(tab);
|
||||
|
||||
tab.setSelected(position == currentPosition);
|
||||
}
|
||||
|
||||
private void updateExpanded() {
|
||||
|
@ -309,21 +309,6 @@ public class PagerSlidingTabStrip extends HorizontalScrollView {
|
|||
|
||||
int myWidth = getMeasuredWidth();
|
||||
tabsContainer.measure(MeasureSpec.EXACTLY | myWidth, heightMeasureSpec);
|
||||
/*int childWidth = 0;
|
||||
for (int i = 0; i < tabCount; i++) {
|
||||
childWidth += tabsContainer.getChildAt(i).getMeasuredWidth();
|
||||
}
|
||||
|
||||
if (!checkedTabWidths && childWidth > 0 && myWidth > 0) {
|
||||
|
||||
if (childWidth <= myWidth) {
|
||||
for (int i = 0; i < tabCount; i++) {
|
||||
tabsContainer.getChildAt(i).setLayoutParams(expandedTabLayoutParams);
|
||||
}
|
||||
}
|
||||
|
||||
checkedTabWidths = true;
|
||||
}*/
|
||||
}
|
||||
|
||||
private void scrollToChild(int position, int offset) {
|
||||
|
|
135
TMessagesProj/src/main/java/org/telegram/ui/Views/SeekBar.java
Normal file
|
@ -0,0 +1,135 @@
|
|||
/*
|
||||
* This is the source code of Telegram for Android v. 1.3.x.
|
||||
* It is licensed under GNU GPL v. 2 or later.
|
||||
* You should have received a copy of the license in this archive (see LICENSE).
|
||||
*
|
||||
* Copyright Nikolai Kudashov, 2013.
|
||||
*/
|
||||
|
||||
package org.telegram.ui.Views;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
|
||||
import org.telegram.messenger.R;
|
||||
import org.telegram.messenger.Utilities;
|
||||
|
||||
public class SeekBar extends View {
|
||||
Drawable thumbDrawable1;
|
||||
Drawable thumbDrawablePressed1;
|
||||
Drawable thumbDrawable2;
|
||||
Drawable thumbDrawablePressed2;
|
||||
static Paint innerPaint1 = new Paint();
|
||||
static Paint outerPaint1 = new Paint();
|
||||
static Paint innerPaint2 = new Paint();
|
||||
static Paint outerPaint2 = new Paint();
|
||||
public int type;
|
||||
public int thumbX = 0;
|
||||
public int thumbDX = 0;
|
||||
private boolean pressed = false;
|
||||
private boolean dragging = false;
|
||||
private int thumbWidth;
|
||||
private int thumbHeight;
|
||||
|
||||
public SeekBar(Context context) {
|
||||
super(context);
|
||||
init();
|
||||
}
|
||||
|
||||
public SeekBar(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init();
|
||||
}
|
||||
|
||||
public SeekBar(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
if (thumbDrawable1 == null) {
|
||||
thumbDrawable1 = getResources().getDrawable(R.drawable.player1);
|
||||
thumbDrawablePressed1 = getResources().getDrawable(R.drawable.player1_pressed);
|
||||
thumbDrawable2 = getResources().getDrawable(R.drawable.player2);
|
||||
thumbDrawablePressed2 = getResources().getDrawable(R.drawable.player2_pressed);
|
||||
innerPaint1.setColor(0xffb4e396);
|
||||
outerPaint1.setColor(0xff6ac453);
|
||||
innerPaint2.setColor(0xffd9e2eb);
|
||||
outerPaint2.setColor(0xff86c5f8);
|
||||
thumbWidth = thumbDrawable1.getIntrinsicWidth();
|
||||
thumbHeight = thumbDrawable1.getIntrinsicHeight();
|
||||
}
|
||||
|
||||
setOnTouchListener(new OnTouchListener() {
|
||||
@Override
|
||||
public boolean onTouch(View view, MotionEvent motionEvent) {
|
||||
float x = motionEvent.getX();
|
||||
float y = motionEvent.getY();
|
||||
if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
|
||||
int additionWidth = (getMeasuredHeight() - thumbWidth) / 2;
|
||||
if (thumbX - additionWidth <= x && x <= thumbX + thumbWidth + additionWidth && y >= 0 && y <= getMeasuredHeight()) {
|
||||
pressed = true;
|
||||
thumbDX = (int)(x - thumbX);
|
||||
invalidate();
|
||||
getParent().requestDisallowInterceptTouchEvent(true);
|
||||
return true;
|
||||
}
|
||||
} else if (motionEvent.getAction() == MotionEvent.ACTION_UP || motionEvent.getAction() == MotionEvent.ACTION_CANCEL) {
|
||||
if (pressed) {
|
||||
pressed = false;
|
||||
invalidate();
|
||||
return true;
|
||||
}
|
||||
} else if (motionEvent.getAction() == MotionEvent.ACTION_MOVE) {
|
||||
if (pressed) {
|
||||
thumbX = (int)(x - thumbDX);
|
||||
if (thumbX < 0) {
|
||||
thumbX = 0;
|
||||
} else if (thumbX > getMeasuredWidth() - thumbWidth) {
|
||||
thumbX = getMeasuredWidth() - thumbWidth;
|
||||
}
|
||||
invalidate();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
Drawable thumb = null;
|
||||
Paint inner = null;
|
||||
Paint outer = null;
|
||||
if (type == 0) {
|
||||
if (!pressed) {
|
||||
thumb = thumbDrawable1;
|
||||
} else {
|
||||
thumb = thumbDrawablePressed1;
|
||||
}
|
||||
inner = innerPaint1;
|
||||
outer = outerPaint1;
|
||||
} else if (type == 1) {
|
||||
if (!pressed) {
|
||||
thumb = thumbDrawable2;
|
||||
} else {
|
||||
thumb = thumbDrawablePressed2;
|
||||
}
|
||||
inner = innerPaint2;
|
||||
outer = outerPaint2;
|
||||
}
|
||||
int height = getMeasuredHeight();
|
||||
int width = getMeasuredWidth();
|
||||
int y = (height - thumbHeight) / 2;
|
||||
canvas.drawRect(thumbWidth / 2, height / 2 - Utilities.dp(1), width - thumbWidth / 2, height / 2 + Utilities.dp(1), inner);
|
||||
canvas.drawRect(thumbWidth / 2, height / 2 - Utilities.dp(1), thumbWidth / 2 + thumbX, height / 2 + Utilities.dp(1), outer);
|
||||
thumb.setBounds(thumbX, y, thumbX + thumbWidth, y + thumbHeight);
|
||||
thumb.draw(canvas);
|
||||
}
|
||||
}
|
|
@ -94,6 +94,12 @@ public class TightTextView extends TextView {
|
|||
}
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
try {
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
} catch (Exception e2) {
|
||||
setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.getSize(heightMeasureSpec));
|
||||
FileLog.e("tmessages", e2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Before Width: | Height: | Size: 703 B After Width: | Height: | Size: 591 B |
Before Width: | Height: | Size: 725 B After Width: | Height: | Size: 599 B |
BIN
TMessagesProj/src/main/res/drawable-hdpi/mic.png
Executable file
After Width: | Height: | Size: 602 B |
BIN
TMessagesProj/src/main/res/drawable-hdpi/mic_pressed.png
Executable file
After Width: | Height: | Size: 581 B |
BIN
TMessagesProj/src/main/res/drawable-hdpi/pause1.png
Executable file
After Width: | Height: | Size: 175 B |
BIN
TMessagesProj/src/main/res/drawable-hdpi/pause1_pressed.png
Executable file
After Width: | Height: | Size: 175 B |
BIN
TMessagesProj/src/main/res/drawable-hdpi/pause2.png
Executable file
After Width: | Height: | Size: 175 B |
BIN
TMessagesProj/src/main/res/drawable-hdpi/pause2_pressed.png
Executable file
After Width: | Height: | Size: 175 B |
BIN
TMessagesProj/src/main/res/drawable-hdpi/photocancel.png
Executable file
After Width: | Height: | Size: 1.1 KiB |
BIN
TMessagesProj/src/main/res/drawable-hdpi/photocancel_pressed.png
Executable file
After Width: | Height: | Size: 1.1 KiB |
BIN
TMessagesProj/src/main/res/drawable-hdpi/photoload.png
Executable file
After Width: | Height: | Size: 952 B |
BIN
TMessagesProj/src/main/res/drawable-hdpi/photoload_pressed.png
Executable file
After Width: | Height: | Size: 967 B |
BIN
TMessagesProj/src/main/res/drawable-hdpi/play1.png
Executable file
After Width: | Height: | Size: 441 B |
BIN
TMessagesProj/src/main/res/drawable-hdpi/play1_pressed.png
Executable file
After Width: | Height: | Size: 440 B |
BIN
TMessagesProj/src/main/res/drawable-hdpi/play2.png
Executable file
After Width: | Height: | Size: 439 B |
BIN
TMessagesProj/src/main/res/drawable-hdpi/play2_pressed.png
Executable file
After Width: | Height: | Size: 439 B |
BIN
TMessagesProj/src/main/res/drawable-hdpi/player1.png
Executable file
After Width: | Height: | Size: 687 B |
BIN
TMessagesProj/src/main/res/drawable-hdpi/player1_pressed.png
Executable file
After Width: | Height: | Size: 1.2 KiB |
BIN
TMessagesProj/src/main/res/drawable-hdpi/player2.png
Executable file
After Width: | Height: | Size: 676 B |
BIN
TMessagesProj/src/main/res/drawable-hdpi/player2_pressed.png
Executable file
After Width: | Height: | Size: 1.2 KiB |
BIN
TMessagesProj/src/main/res/drawable-hdpi/rec.png
Executable file
After Width: | Height: | Size: 331 B |
BIN
TMessagesProj/src/main/res/drawable-hdpi/slidearrow.png
Executable file
After Width: | Height: | Size: 420 B |
BIN
TMessagesProj/src/main/res/drawable-hdpi/tooltip.png
Executable file
After Width: | Height: | Size: 367 B |
Before Width: | Height: | Size: 418 B After Width: | Height: | Size: 343 B |
Before Width: | Height: | Size: 420 B After Width: | Height: | Size: 344 B |
BIN
TMessagesProj/src/main/res/drawable-ldpi/mic.png
Executable file
After Width: | Height: | Size: 359 B |
BIN
TMessagesProj/src/main/res/drawable-ldpi/mic_pressed.png
Executable file
After Width: | Height: | Size: 356 B |
BIN
TMessagesProj/src/main/res/drawable-ldpi/pause1.png
Executable file
After Width: | Height: | Size: 155 B |
BIN
TMessagesProj/src/main/res/drawable-ldpi/pause1_pressed.png
Executable file
After Width: | Height: | Size: 157 B |
BIN
TMessagesProj/src/main/res/drawable-ldpi/pause2.png
Executable file
After Width: | Height: | Size: 157 B |
BIN
TMessagesProj/src/main/res/drawable-ldpi/pause2_pressed.png
Executable file
After Width: | Height: | Size: 157 B |
BIN
TMessagesProj/src/main/res/drawable-ldpi/photocancel.png
Executable file
After Width: | Height: | Size: 709 B |
BIN
TMessagesProj/src/main/res/drawable-ldpi/photocancel_pressed.png
Executable file
After Width: | Height: | Size: 715 B |