mirror of https://github.com/NekoX-Dev/NekoX.git
Merge branch 'dev'
This commit is contained in:
commit
9d113ccb7a
|
@ -3,7 +3,7 @@ buildscript {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:1.0.0'
|
classpath 'com.android.tools.build:gradle:1.1.3'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
apply plugin: 'com.android.application'
|
apply plugin: 'com.android.application'
|
||||||
|
@ -13,7 +13,7 @@ repositories {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile 'com.android.support:support-v4:21.0.+'
|
compile 'com.android.support:support-v4:22.0.+'
|
||||||
compile 'com.google.android.gms:play-services:3.2.+'
|
compile 'com.google.android.gms:play-services:3.2.+'
|
||||||
compile 'net.hockeyapp.android:HockeySDK:3.5.+'
|
compile 'net.hockeyapp.android:HockeySDK:3.5.+'
|
||||||
compile 'com.googlecode.mp4parser:isoparser:1.0.+'
|
compile 'com.googlecode.mp4parser:isoparser:1.0.+'
|
||||||
|
@ -21,8 +21,8 @@ dependencies {
|
||||||
}
|
}
|
||||||
|
|
||||||
android {
|
android {
|
||||||
compileSdkVersion 21
|
compileSdkVersion 22
|
||||||
buildToolsVersion '21.1.2'
|
buildToolsVersion '22.0.1'
|
||||||
|
|
||||||
compileOptions {
|
compileOptions {
|
||||||
sourceCompatibility JavaVersion.VERSION_1_7
|
sourceCompatibility JavaVersion.VERSION_1_7
|
||||||
|
@ -81,8 +81,8 @@ android {
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
minSdkVersion 8
|
minSdkVersion 8
|
||||||
targetSdkVersion 21
|
targetSdkVersion 22
|
||||||
versionCode 423
|
versionCode 492
|
||||||
versionName "2.4.0"
|
versionName "2.7.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
android:label="@string/AppName"
|
android:label="@string/AppName"
|
||||||
android:theme="@style/Theme.TMessages.Start"
|
android:theme="@style/Theme.TMessages.Start"
|
||||||
android:name=".ApplicationLoader"
|
android:name=".ApplicationLoader"
|
||||||
android:hardwareAccelerated="true"
|
android:hardwareAccelerated="@bool/useHardwareAcceleration"
|
||||||
android:largeHeap="true">
|
android:largeHeap="true">
|
||||||
|
|
||||||
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="AIzaSyCTNmNqbWovP9ETcAob98YlrfOQEAC0CJ4" />
|
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="AIzaSyCTNmNqbWovP9ETcAob98YlrfOQEAC0CJ4" />
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
android:label="@string/AppName"
|
android:label="@string/AppName"
|
||||||
android:theme="@style/Theme.TMessages.Start"
|
android:theme="@style/Theme.TMessages.Start"
|
||||||
android:name=".ApplicationLoader"
|
android:name=".ApplicationLoader"
|
||||||
android:hardwareAccelerated="true"
|
android:hardwareAccelerated="@bool/useHardwareAcceleration"
|
||||||
android:largeHeap="true">
|
android:largeHeap="true">
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
android:label="@string/AppName"
|
android:label="@string/AppName"
|
||||||
android:theme="@style/Theme.TMessages.Start"
|
android:theme="@style/Theme.TMessages.Start"
|
||||||
android:name=".ApplicationLoader"
|
android:name=".ApplicationLoader"
|
||||||
android:hardwareAccelerated="true"
|
android:hardwareAccelerated="@bool/useHardwareAcceleration"
|
||||||
android:largeHeap="true">
|
android:largeHeap="true">
|
||||||
|
|
||||||
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="AIzaSyA-t0jLPjUt2FxrA8VPK2EiYHcYcboIR6k" />
|
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="AIzaSyA-t0jLPjUt2FxrA8VPK2EiYHcYcboIR6k" />
|
||||||
|
|
|
@ -104,7 +104,7 @@ include $(BUILD_STATIC_LIBRARY)
|
||||||
include $(CLEAR_VARS)
|
include $(CLEAR_VARS)
|
||||||
LOCAL_PRELINK_MODULE := false
|
LOCAL_PRELINK_MODULE := false
|
||||||
LOCAL_STATIC_LIBRARIES := webp sqlite
|
LOCAL_STATIC_LIBRARIES := webp sqlite
|
||||||
LOCAL_MODULE := tmessages.5
|
LOCAL_MODULE := tmessages.7
|
||||||
LOCAL_CFLAGS := -w -std=gnu99 -O2 -DNULL=0 -DSOCKLEN_T=socklen_t -DLOCALE_NOT_USED -D_LARGEFILE_SOURCE=1 -D_FILE_OFFSET_BITS=64
|
LOCAL_CFLAGS := -w -std=gnu99 -O2 -DNULL=0 -DSOCKLEN_T=socklen_t -DLOCALE_NOT_USED -D_LARGEFILE_SOURCE=1 -D_FILE_OFFSET_BITS=64
|
||||||
LOCAL_CFLAGS += -Drestrict='' -D__EMX__ -DOPUS_BUILD -DFIXED_POINT -DUSE_ALLOCA -DHAVE_LRINT -DHAVE_LRINTF -fno-math-errno
|
LOCAL_CFLAGS += -Drestrict='' -D__EMX__ -DOPUS_BUILD -DFIXED_POINT -DUSE_ALLOCA -DHAVE_LRINT -DHAVE_LRINTF -fno-math-errno
|
||||||
LOCAL_CFLAGS += -DANDROID_NDK -DDISABLE_IMPORTGL -fno-strict-aliasing -fprefetch-loop-arrays -DAVOID_TABLES -DANDROID_TILE_BASED_DECODE -DANDROID_ARMV6_IDCT -ffast-math
|
LOCAL_CFLAGS += -DANDROID_NDK -DDISABLE_IMPORTGL -fno-strict-aliasing -fprefetch-loop-arrays -DAVOID_TABLES -DANDROID_TILE_BASED_DECODE -DANDROID_ARMV6_IDCT -ffast-math
|
||||||
|
|
|
@ -21,6 +21,9 @@ jmethodID jclass_Bitmap_createBitmap;
|
||||||
jclass jclass_Config;
|
jclass jclass_Config;
|
||||||
jfieldID jclass_Config_ARGB_8888;
|
jfieldID jclass_Config_ARGB_8888;
|
||||||
|
|
||||||
|
const uint32_t PGPhotoEnhanceHistogramBins = 256;
|
||||||
|
const uint32_t PGPhotoEnhanceSegments = 4;
|
||||||
|
|
||||||
jclass createGlobarRef(JNIEnv *env, jclass class) {
|
jclass createGlobarRef(JNIEnv *env, jclass class) {
|
||||||
if (class) {
|
if (class) {
|
||||||
return (*env)->NewGlobalRef(env, class);
|
return (*env)->NewGlobalRef(env, class);
|
||||||
|
@ -312,6 +315,115 @@ JNIEXPORT void Java_org_telegram_messenger_Utilities_blurBitmap(JNIEnv *env, jcl
|
||||||
AndroidBitmap_unlockPixels(env, bitmap);
|
AndroidBitmap_unlockPixels(env, bitmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JNIEXPORT void Java_org_telegram_messenger_Utilities_calcCDT(JNIEnv *env, jclass class, jobject hsvBuffer, int width, int height, jobject buffer) {
|
||||||
|
float imageWidth = width;
|
||||||
|
float imageHeight = height;
|
||||||
|
float _clipLimit = 1.25f;
|
||||||
|
|
||||||
|
uint32_t totalSegments = PGPhotoEnhanceSegments * PGPhotoEnhanceSegments;
|
||||||
|
uint32_t tileArea = (uint32_t)(floorf(imageWidth / PGPhotoEnhanceSegments) * floorf(imageHeight / PGPhotoEnhanceSegments));
|
||||||
|
uint32_t clipLimit = (uint32_t)max(1, _clipLimit * tileArea / (float) PGPhotoEnhanceHistogramBins);
|
||||||
|
float scale = 255.0f / (float) tileArea;
|
||||||
|
|
||||||
|
|
||||||
|
unsigned char *bytes = (*env)->GetDirectBufferAddress(env, hsvBuffer);
|
||||||
|
|
||||||
|
uint32_t **hist = calloc(totalSegments, sizeof(uint32_t *));
|
||||||
|
uint32_t **cdfs = calloc(totalSegments, sizeof(uint32_t *));
|
||||||
|
uint32_t *cdfsMin = calloc(totalSegments, sizeof(uint32_t));
|
||||||
|
uint32_t *cdfsMax = calloc(totalSegments, sizeof(uint32_t));
|
||||||
|
|
||||||
|
for (uint32_t a = 0; a < totalSegments; a++) {
|
||||||
|
hist[a] = calloc(PGPhotoEnhanceHistogramBins, sizeof(uint32_t));
|
||||||
|
cdfs[a] = calloc(PGPhotoEnhanceHistogramBins, sizeof(uint32_t));
|
||||||
|
}
|
||||||
|
|
||||||
|
float xMul = PGPhotoEnhanceSegments / imageWidth;
|
||||||
|
float yMul = PGPhotoEnhanceSegments / imageHeight;
|
||||||
|
|
||||||
|
for (uint32_t y = 0; y < imageHeight; y++) {
|
||||||
|
uint32_t yOffset = y * width * 4;
|
||||||
|
for (uint32_t x = 0; x < imageWidth; x++) {
|
||||||
|
uint32_t index = x * 4 + yOffset;
|
||||||
|
|
||||||
|
uint32_t tx = (uint32_t)(x * xMul);
|
||||||
|
uint32_t ty = (uint32_t)(y * yMul);
|
||||||
|
uint32_t t = ty * PGPhotoEnhanceSegments + tx;
|
||||||
|
|
||||||
|
hist[t][bytes[index + 2]]++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (uint32_t i = 0; i < totalSegments; i++) {
|
||||||
|
if (clipLimit > 0) {
|
||||||
|
uint32_t clipped = 0;
|
||||||
|
for (uint32_t j = 0; j < PGPhotoEnhanceHistogramBins; ++j) {
|
||||||
|
if (hist[i][j] > clipLimit) {
|
||||||
|
clipped += hist[i][j] - clipLimit;
|
||||||
|
hist[i][j] = clipLimit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t redistBatch = clipped / PGPhotoEnhanceHistogramBins;
|
||||||
|
uint32_t residual = clipped - redistBatch * PGPhotoEnhanceHistogramBins;
|
||||||
|
|
||||||
|
for (uint32_t j = 0; j < PGPhotoEnhanceHistogramBins; ++j) {
|
||||||
|
hist[i][j] += redistBatch;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (uint32_t j = 0; j < residual; ++j) {
|
||||||
|
hist[i][j]++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
memcpy(cdfs[i], hist[i], PGPhotoEnhanceHistogramBins * sizeof(uint32_t));
|
||||||
|
|
||||||
|
uint32_t hMin = PGPhotoEnhanceHistogramBins - 1;
|
||||||
|
for (uint32_t j = 0; j < hMin; ++j) {
|
||||||
|
if (cdfs[j] != 0) {
|
||||||
|
hMin = j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t cdf = 0;
|
||||||
|
for (uint32_t j = hMin; j < PGPhotoEnhanceHistogramBins; ++j) {
|
||||||
|
cdf += cdfs[i][j];
|
||||||
|
cdfs[i][j] = (uint8_t) min(255, cdf * scale);
|
||||||
|
}
|
||||||
|
|
||||||
|
cdfsMin[i] = cdfs[i][hMin];
|
||||||
|
cdfsMax[i] = cdfs[i][PGPhotoEnhanceHistogramBins - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t resultSize = 4 * PGPhotoEnhanceHistogramBins * totalSegments;
|
||||||
|
uint32_t resultBytesPerRow = 4 * PGPhotoEnhanceHistogramBins;
|
||||||
|
|
||||||
|
unsigned char *result = (*env)->GetDirectBufferAddress(env, buffer);
|
||||||
|
for (uint32_t tile = 0; tile < totalSegments; tile++) {
|
||||||
|
uint32_t yOffset = tile * resultBytesPerRow;
|
||||||
|
for (uint32_t i = 0; i < PGPhotoEnhanceHistogramBins; i++) {
|
||||||
|
uint32_t index = i * 4 + yOffset;
|
||||||
|
result[index] = (uint8_t)cdfs[tile][i];
|
||||||
|
result[index + 1] = (uint8_t)cdfsMin[tile];
|
||||||
|
result[index + 2] = (uint8_t)cdfsMax[tile];
|
||||||
|
result[index + 3] = 255;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (uint32_t a = 0; a < totalSegments; a++) {
|
||||||
|
free(hist[a]);
|
||||||
|
free(cdfs[a]);
|
||||||
|
}
|
||||||
|
free(hist);
|
||||||
|
free(cdfs);
|
||||||
|
free(cdfsMax);
|
||||||
|
free(cdfsMin);
|
||||||
|
}
|
||||||
|
|
||||||
|
JNIEXPORT int Java_org_telegram_messenger_Utilities_pinBitmap(JNIEnv *env, jclass class, jobject bitmap) {
|
||||||
|
unsigned char *pixels;
|
||||||
|
return AndroidBitmap_lockPixels(env, bitmap, &pixels) >= 0 ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
JNIEXPORT void Java_org_telegram_messenger_Utilities_loadBitmap(JNIEnv *env, jclass class, jstring path, jobject bitmap, int scale, int width, int height, int stride) {
|
JNIEXPORT void Java_org_telegram_messenger_Utilities_loadBitmap(JNIEnv *env, jclass class, jstring path, jobject bitmap, int scale, int width, int height, int stride) {
|
||||||
|
|
||||||
AndroidBitmapInfo info;
|
AndroidBitmapInfo info;
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -43,7 +43,7 @@
|
||||||
<application
|
<application
|
||||||
android:name=".ApplicationLoader"
|
android:name=".ApplicationLoader"
|
||||||
android:allowBackup="false"
|
android:allowBackup="false"
|
||||||
android:hardwareAccelerated="true"
|
android:hardwareAccelerated="@bool/useHardwareAcceleration"
|
||||||
android:icon="@drawable/ic_launcher"
|
android:icon="@drawable/ic_launcher"
|
||||||
android:label="@string/AppName"
|
android:label="@string/AppName"
|
||||||
android:largeHeap="true"
|
android:largeHeap="true"
|
||||||
|
@ -52,7 +52,7 @@
|
||||||
<activity
|
<activity
|
||||||
android:name="org.telegram.ui.LaunchActivity"
|
android:name="org.telegram.ui.LaunchActivity"
|
||||||
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
|
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
|
||||||
android:hardwareAccelerated="true"
|
android:hardwareAccelerated="@bool/useHardwareAcceleration"
|
||||||
android:launchMode="singleTask"
|
android:launchMode="singleTask"
|
||||||
android:windowSoftInputMode="adjustPan">
|
android:windowSoftInputMode="adjustPan">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
|
|
|
@ -28,7 +28,7 @@ public class ByteStream {
|
||||||
private final ArrayList<ByteBufferDesc> queue;
|
private final ArrayList<ByteBufferDesc> queue;
|
||||||
|
|
||||||
public ByteStream() {
|
public ByteStream() {
|
||||||
this.queue = new ArrayList<ByteBufferDesc>();
|
this.queue = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void append(ByteBufferDesc buf) {
|
public void append(ByteBufferDesc buf) {
|
||||||
|
|
|
@ -22,17 +22,17 @@ import java.io.IOException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
public interface PyroClientListener {
|
public interface PyroClientListener {
|
||||||
public void connectedClient(PyroClient client);
|
void connectedClient(PyroClient client);
|
||||||
|
|
||||||
public void unconnectableClient(PyroClient client, Exception cause);
|
void unconnectableClient(PyroClient client, Exception cause);
|
||||||
|
|
||||||
public void droppedClient(PyroClient client, IOException cause);
|
void droppedClient(PyroClient client, IOException cause);
|
||||||
|
|
||||||
public void disconnectedClient(PyroClient client);
|
void disconnectedClient(PyroClient client);
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
public void receivedData(PyroClient client, ByteBuffer data);
|
void receivedData(PyroClient client, ByteBuffer data);
|
||||||
|
|
||||||
public void sentData(PyroClient client, int bytes);
|
void sentData(PyroClient client, int bytes);
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
package org.telegram.PhoneFormat;
|
package org.telegram.PhoneFormat;
|
||||||
|
|
||||||
import org.telegram.messenger.ApplicationLoader;
|
import org.telegram.messenger.ApplicationLoader;
|
||||||
|
import org.telegram.messenger.FileLog;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
@ -97,9 +98,11 @@ public class PhoneFormat {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init(String countryCode) {
|
public void init(String countryCode) {
|
||||||
|
InputStream stream = null;
|
||||||
|
ByteArrayOutputStream bos = null;
|
||||||
try {
|
try {
|
||||||
InputStream stream = ApplicationLoader.applicationContext.getAssets().open("PhoneFormats.dat");
|
stream = ApplicationLoader.applicationContext.getAssets().open("PhoneFormats.dat");
|
||||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
bos = new ByteArrayOutputStream();
|
||||||
byte[] buf = new byte[1024];
|
byte[] buf = new byte[1024];
|
||||||
int len;
|
int len;
|
||||||
while ((len = stream.read(buf, 0, 1024)) != -1) {
|
while ((len = stream.read(buf, 0, 1024)) != -1) {
|
||||||
|
@ -111,6 +114,21 @@ public class PhoneFormat {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return;
|
return;
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (bos != null) {
|
||||||
|
bos.close();
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
FileLog.e("tmessages", e);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
if (stream != null) {
|
||||||
|
stream.close();
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
FileLog.e("tmessages", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (countryCode != null && countryCode.length() != 0) {
|
if (countryCode != null && countryCode.length() != 0) {
|
||||||
|
@ -119,10 +137,10 @@ public class PhoneFormat {
|
||||||
Locale loc = Locale.getDefault();
|
Locale loc = Locale.getDefault();
|
||||||
defaultCountry = loc.getCountry().toLowerCase();
|
defaultCountry = loc.getCountry().toLowerCase();
|
||||||
}
|
}
|
||||||
callingCodeOffsets = new HashMap<String, Integer>(255);
|
callingCodeOffsets = new HashMap<>(255);
|
||||||
callingCodeCountries = new HashMap<String, ArrayList<String>>(255);
|
callingCodeCountries = new HashMap<>(255);
|
||||||
callingCodeData = new HashMap<String, CallingCodeInfo>(10);
|
callingCodeData = new HashMap<>(10);
|
||||||
countryCallingCode = new HashMap<String, String>(255);
|
countryCallingCode = new HashMap<>(255);
|
||||||
|
|
||||||
parseDataHeader();
|
parseDataHeader();
|
||||||
initialzed = true;
|
initialzed = true;
|
||||||
|
@ -293,7 +311,7 @@ public class PhoneFormat {
|
||||||
|
|
||||||
offset += 2;
|
offset += 2;
|
||||||
|
|
||||||
ArrayList<String> strs = new ArrayList<String>(5);
|
ArrayList<String> strs = new ArrayList<>(5);
|
||||||
String str;
|
String str;
|
||||||
while ((str = valueString(offset)).length() != 0) {
|
while ((str = valueString(offset)).length() != 0) {
|
||||||
strs.add(str);
|
strs.add(str);
|
||||||
|
@ -302,14 +320,14 @@ public class PhoneFormat {
|
||||||
res.trunkPrefixes = strs;
|
res.trunkPrefixes = strs;
|
||||||
offset++;
|
offset++;
|
||||||
|
|
||||||
strs = new ArrayList<String>(5);
|
strs = new ArrayList<>(5);
|
||||||
while ((str = valueString(offset)).length() != 0) {
|
while ((str = valueString(offset)).length() != 0) {
|
||||||
strs.add(str);
|
strs.add(str);
|
||||||
offset += str.length() + 1;
|
offset += str.length() + 1;
|
||||||
}
|
}
|
||||||
res.intlPrefixes = strs;
|
res.intlPrefixes = strs;
|
||||||
|
|
||||||
ArrayList<RuleSet> ruleSets = new ArrayList<RuleSet>(setCnt);
|
ArrayList<RuleSet> ruleSets = new ArrayList<>(setCnt);
|
||||||
offset = start + block1Len;
|
offset = start + block1Len;
|
||||||
for (int s = 0; s < setCnt; s++) {
|
for (int s = 0; s < setCnt; s++) {
|
||||||
RuleSet ruleSet = new RuleSet();
|
RuleSet ruleSet = new RuleSet();
|
||||||
|
@ -317,7 +335,7 @@ public class PhoneFormat {
|
||||||
offset += 2;
|
offset += 2;
|
||||||
int ruleCnt = value16(offset);
|
int ruleCnt = value16(offset);
|
||||||
offset += 2;
|
offset += 2;
|
||||||
ArrayList<PhoneRule> rules = new ArrayList<PhoneRule>(ruleCnt);
|
ArrayList<PhoneRule> rules = new ArrayList<>(ruleCnt);
|
||||||
for (int r = 0; r < ruleCnt; r++) {
|
for (int r = 0; r < ruleCnt; r++) {
|
||||||
PhoneRule rule = new PhoneRule();
|
PhoneRule rule = new PhoneRule();
|
||||||
rule.minVal = value32(offset);
|
rule.minVal = value32(offset);
|
||||||
|
@ -380,7 +398,7 @@ public class PhoneFormat {
|
||||||
callingCodeOffsets.put(callingCode, offset);
|
callingCodeOffsets.put(callingCode, offset);
|
||||||
ArrayList<String> countries = callingCodeCountries.get(callingCode);
|
ArrayList<String> countries = callingCodeCountries.get(callingCode);
|
||||||
if (countries == null) {
|
if (countries == null) {
|
||||||
countries = new ArrayList<String>();
|
countries = new ArrayList<>();
|
||||||
callingCodeCountries.put(callingCode, countries);
|
callingCodeCountries.put(callingCode, countries);
|
||||||
}
|
}
|
||||||
countries.add(country);
|
countries.add(country);
|
||||||
|
|
|
@ -14,6 +14,7 @@ import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.pm.ActivityInfo;
|
import android.content.pm.ActivityInfo;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
|
import android.graphics.Color;
|
||||||
import android.graphics.Point;
|
import android.graphics.Point;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.graphics.Typeface;
|
import android.graphics.Typeface;
|
||||||
|
@ -23,6 +24,8 @@ import android.os.Environment;
|
||||||
import android.text.Spannable;
|
import android.text.Spannable;
|
||||||
import android.text.SpannableStringBuilder;
|
import android.text.SpannableStringBuilder;
|
||||||
import android.text.Spanned;
|
import android.text.Spanned;
|
||||||
|
import android.text.style.ForegroundColorSpan;
|
||||||
|
import android.util.DisplayMetrics;
|
||||||
import android.util.StateSet;
|
import android.util.StateSet;
|
||||||
import android.view.Display;
|
import android.view.Display;
|
||||||
import android.view.Surface;
|
import android.view.Surface;
|
||||||
|
@ -33,12 +36,20 @@ import android.widget.AbsListView;
|
||||||
import android.widget.EdgeEffect;
|
import android.widget.EdgeEffect;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
|
import android.widget.ProgressBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import org.telegram.messenger.ConnectionsManager;
|
||||||
import org.telegram.messenger.FileLog;
|
import org.telegram.messenger.FileLog;
|
||||||
import org.telegram.messenger.R;
|
import org.telegram.messenger.R;
|
||||||
import org.telegram.messenger.TLRPC;
|
import org.telegram.messenger.TLRPC;
|
||||||
import org.telegram.messenger.ApplicationLoader;
|
import org.telegram.messenger.ApplicationLoader;
|
||||||
|
import org.telegram.messenger.UserConfig;
|
||||||
|
import org.telegram.ui.AnimationCompat.AnimatorListenerAdapterProxy;
|
||||||
|
import org.telegram.ui.AnimationCompat.AnimatorSetProxy;
|
||||||
|
import org.telegram.ui.AnimationCompat.ObjectAnimatorProxy;
|
||||||
|
import org.telegram.ui.AnimationCompat.ViewProxy;
|
||||||
|
import org.telegram.ui.Components.ForegroundDetector;
|
||||||
import org.telegram.ui.Components.NumberPicker;
|
import org.telegram.ui.Components.NumberPicker;
|
||||||
import org.telegram.ui.Components.TypefaceSpan;
|
import org.telegram.ui.Components.TypefaceSpan;
|
||||||
|
|
||||||
|
@ -59,15 +70,18 @@ public class AndroidUtilities {
|
||||||
public static float density = 1;
|
public static float density = 1;
|
||||||
public static Point displaySize = new Point();
|
public static Point displaySize = new Point();
|
||||||
public static Integer photoSize = null;
|
public static Integer photoSize = null;
|
||||||
|
public static DisplayMetrics displayMetrics = new DisplayMetrics();
|
||||||
|
public static int leftBaseline;
|
||||||
private static Boolean isTablet = null;
|
private static Boolean isTablet = null;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
density = ApplicationLoader.applicationContext.getResources().getDisplayMetrics().density;
|
density = ApplicationLoader.applicationContext.getResources().getDisplayMetrics().density;
|
||||||
|
leftBaseline = isTablet() ? 80 : 72;
|
||||||
checkDisplaySize();
|
checkDisplaySize();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void lockOrientation(Activity activity) {
|
public static void lockOrientation(Activity activity) {
|
||||||
if (activity == null || prevOrientation != -10) {
|
if (activity == null || prevOrientation != -10 || Build.VERSION.SDK_INT < 9) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
@ -115,7 +129,7 @@ public class AndroidUtilities {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void unlockOrientation(Activity activity) {
|
public static void unlockOrientation(Activity activity) {
|
||||||
if (activity == null) {
|
if (activity == null || Build.VERSION.SDK_INT < 9) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
@ -163,8 +177,6 @@ public class AndroidUtilities {
|
||||||
}
|
}
|
||||||
InputMethodManager inputManager = (InputMethodManager)view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
|
InputMethodManager inputManager = (InputMethodManager)view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
inputManager.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
|
inputManager.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
|
||||||
|
|
||||||
((InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(view, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isKeyboardShowed(View view) {
|
public static boolean isKeyboardShowed(View view) {
|
||||||
|
@ -228,12 +240,13 @@ public class AndroidUtilities {
|
||||||
if (manager != null) {
|
if (manager != null) {
|
||||||
Display display = manager.getDefaultDisplay();
|
Display display = manager.getDefaultDisplay();
|
||||||
if (display != null) {
|
if (display != null) {
|
||||||
|
display.getMetrics(displayMetrics);
|
||||||
if(android.os.Build.VERSION.SDK_INT < 13) {
|
if(android.os.Build.VERSION.SDK_INT < 13) {
|
||||||
displaySize.set(display.getWidth(), display.getHeight());
|
displaySize.set(display.getWidth(), display.getHeight());
|
||||||
} else {
|
} else {
|
||||||
display.getSize(displaySize);
|
display.getSize(displaySize);
|
||||||
}
|
}
|
||||||
FileLog.e("tmessages", "display size = " + displaySize.x + " " + displaySize.y);
|
FileLog.e("tmessages", "display size = " + displaySize.x + " " + displaySize.y + " " + displayMetrics.xdpi + "x" + displayMetrics.ydpi);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -241,6 +254,10 @@ public class AndroidUtilities {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static float getPixelsInCM(float cm, boolean isX) {
|
||||||
|
return (cm / 2.54f) * (isX ? displayMetrics.xdpi : displayMetrics.ydpi);
|
||||||
|
}
|
||||||
|
|
||||||
public static long makeBroadcastId(int id) {
|
public static long makeBroadcastId(int id) {
|
||||||
return 0x0000000100000000L | ((long)id & 0x00000000FFFFFFFFL);
|
return 0x0000000100000000L | ((long)id & 0x00000000FFFFFFFFL);
|
||||||
}
|
}
|
||||||
|
@ -421,6 +438,19 @@ public class AndroidUtilities {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setProgressBarAnimationDuration(ProgressBar progressBar, int duration) {
|
||||||
|
if (progressBar == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Field mCursorDrawableRes = ProgressBar.class.getDeclaredField("mDuration");
|
||||||
|
mCursorDrawableRes.setAccessible(true);
|
||||||
|
mCursorDrawableRes.setInt(progressBar, duration);
|
||||||
|
} catch (Exception e) {
|
||||||
|
FileLog.e("tmessages", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static int getViewInset(View view) {
|
public static int getViewInset(View view) {
|
||||||
if (view == null || Build.VERSION.SDK_INT < 21) {
|
if (view == null || Build.VERSION.SDK_INT < 21) {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -514,20 +544,133 @@ public class AndroidUtilities {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Spannable replaceBold(String str) {
|
public static Spannable replaceTags(String str) {
|
||||||
int start;
|
try {
|
||||||
ArrayList<Integer> bolds = new ArrayList<>();
|
int start = -1;
|
||||||
while ((start = str.indexOf("<b>")) != -1) {
|
int startColor = -1;
|
||||||
int end = str.indexOf("</b>") - 3;
|
int end = -1;
|
||||||
str = str.replaceFirst("<b>", "").replaceFirst("</b>", "");
|
StringBuilder stringBuilder = new StringBuilder(str);
|
||||||
bolds.add(start);
|
while ((start = stringBuilder.indexOf("<br>")) != -1) {
|
||||||
bolds.add(end);
|
stringBuilder.replace(start, start + 4, "\n");
|
||||||
|
}
|
||||||
|
while ((start = stringBuilder.indexOf("<br/>")) != -1) {
|
||||||
|
stringBuilder.replace(start, start + 5, "\n");
|
||||||
|
}
|
||||||
|
ArrayList<Integer> bolds = new ArrayList<>();
|
||||||
|
ArrayList<Integer> colors = new ArrayList<>();
|
||||||
|
while ((start = stringBuilder.indexOf("<b>")) != -1 || (startColor = stringBuilder.indexOf("<c")) != -1) {
|
||||||
|
if (start != -1) {
|
||||||
|
stringBuilder.replace(start, start + 3, "");
|
||||||
|
end = stringBuilder.indexOf("</b>");
|
||||||
|
stringBuilder.replace(end, end + 4, "");
|
||||||
|
bolds.add(start);
|
||||||
|
bolds.add(end);
|
||||||
|
} else if (startColor != -1) {
|
||||||
|
stringBuilder.replace(startColor, startColor + 2, "");
|
||||||
|
end = stringBuilder.indexOf(">", startColor);
|
||||||
|
int color = Color.parseColor(stringBuilder.substring(startColor, end));
|
||||||
|
stringBuilder.replace(startColor, end + 1, "");
|
||||||
|
end = stringBuilder.indexOf("</c>");
|
||||||
|
stringBuilder.replace(end, end + 4, "");
|
||||||
|
colors.add(startColor);
|
||||||
|
colors.add(end);
|
||||||
|
colors.add(color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(stringBuilder);
|
||||||
|
for (int a = 0; a < bolds.size() / 2; a++) {
|
||||||
|
spannableStringBuilder.setSpan(new TypefaceSpan(AndroidUtilities.getTypeface("fonts/rmedium.ttf")), bolds.get(a * 2), bolds.get(a * 2 + 1), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
|
}
|
||||||
|
for (int a = 0; a < colors.size() / 3; a++) {
|
||||||
|
spannableStringBuilder.setSpan(new ForegroundColorSpan(colors.get(a * 3 + 2)), colors.get(a * 3), colors.get(a * 3 + 1), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
|
}
|
||||||
|
return spannableStringBuilder;
|
||||||
|
} catch (Exception e) {
|
||||||
|
FileLog.e("tmessages", e);
|
||||||
}
|
}
|
||||||
SpannableStringBuilder stringBuilder = new SpannableStringBuilder(str);
|
return new SpannableStringBuilder(str);
|
||||||
for (int a = 0; a < bolds.size() / 2; a++) {
|
|
||||||
TypefaceSpan span = new TypefaceSpan(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
|
|
||||||
stringBuilder.setSpan(span, bolds.get(a * 2), bolds.get(a * 2 + 1), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
|
|
||||||
}
|
|
||||||
return stringBuilder;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean needShowPasscode(boolean reset) {
|
||||||
|
boolean wasInBackground;
|
||||||
|
if (Build.VERSION.SDK_INT >= 14) {
|
||||||
|
wasInBackground = ForegroundDetector.getInstance().isWasInBackground(reset);
|
||||||
|
if (reset) {
|
||||||
|
ForegroundDetector.getInstance().resetBackgroundVar();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
wasInBackground = UserConfig.lastPauseTime != 0;
|
||||||
|
}
|
||||||
|
return UserConfig.passcodeHash.length() > 0 && wasInBackground &&
|
||||||
|
(UserConfig.appLocked || UserConfig.autoLockIn != 0 && UserConfig.lastPauseTime != 0 && !UserConfig.appLocked && (UserConfig.lastPauseTime + UserConfig.autoLockIn) <= ConnectionsManager.getInstance().getCurrentTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void shakeTextView(final TextView textView, final float x, final int num) {
|
||||||
|
if (num == 6) {
|
||||||
|
ViewProxy.setTranslationX(textView, 0);
|
||||||
|
textView.clearAnimation();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
AnimatorSetProxy animatorSetProxy = new AnimatorSetProxy();
|
||||||
|
animatorSetProxy.playTogether(ObjectAnimatorProxy.ofFloat(textView, "translationX", AndroidUtilities.dp(x)));
|
||||||
|
animatorSetProxy.setDuration(50);
|
||||||
|
animatorSetProxy.addListener(new AnimatorListenerAdapterProxy() {
|
||||||
|
@Override
|
||||||
|
public void onAnimationEnd(Object animation) {
|
||||||
|
shakeTextView(textView, num == 5 ? 0 : -x, num + 1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
animatorSetProxy.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*public static String ellipsize(String text, int maxLines, int maxWidth, TextPaint paint) {
|
||||||
|
if (text == null || paint == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
int count;
|
||||||
|
int offset = 0;
|
||||||
|
StringBuilder result = null;
|
||||||
|
TextView
|
||||||
|
for (int a = 0; a < maxLines; a++) {
|
||||||
|
count = paint.breakText(text, true, maxWidth, null);
|
||||||
|
if (a != maxLines - 1) {
|
||||||
|
if (result == null) {
|
||||||
|
result = new StringBuilder(count * maxLines + 1);
|
||||||
|
}
|
||||||
|
boolean foundSpace = false;
|
||||||
|
for (int c = count - 1; c >= offset; c--) {
|
||||||
|
if (text.charAt(c) == ' ') {
|
||||||
|
foundSpace = true;
|
||||||
|
result.append(text.substring(offset, c - 1));
|
||||||
|
offset = c - 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!foundSpace) {
|
||||||
|
offset = count;
|
||||||
|
}
|
||||||
|
text = text.substring(0, offset);
|
||||||
|
} else if (maxLines == 1) {
|
||||||
|
return text.substring(0, count);
|
||||||
|
} else {
|
||||||
|
result.append(text.substring(0, count));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result.toString();
|
||||||
|
}*/
|
||||||
|
|
||||||
|
/*public static void turnOffHardwareAcceleration(Window window) {
|
||||||
|
if (window == null || Build.MODEL == null || Build.VERSION.SDK_INT < 11) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (Build.MODEL.contains("GT-S5301") ||
|
||||||
|
Build.MODEL.contains("GT-S5303") ||
|
||||||
|
Build.MODEL.contains("GT-B5330") ||
|
||||||
|
Build.MODEL.contains("GT-S5302") ||
|
||||||
|
Build.MODEL.contains("GT-S6012B") ||
|
||||||
|
Build.MODEL.contains("MegaFon_SP-AI")) {
|
||||||
|
window.clearFlags(WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
|
||||||
|
}
|
||||||
|
}*/
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,6 +54,7 @@ public class ContactsController {
|
||||||
private ArrayList<Integer> delayedContactsUpdate = new ArrayList<>();
|
private ArrayList<Integer> delayedContactsUpdate = new ArrayList<>();
|
||||||
private String inviteText;
|
private String inviteText;
|
||||||
private boolean updatingInviteText = false;
|
private boolean updatingInviteText = false;
|
||||||
|
private HashMap<String, String> sectionsToReplace = new HashMap<>();
|
||||||
|
|
||||||
private int loadingDeleteInfo = 0;
|
private int loadingDeleteInfo = 0;
|
||||||
private int deleteAccountTTL;
|
private int deleteAccountTTL;
|
||||||
|
@ -114,6 +115,28 @@ public class ContactsController {
|
||||||
if (preferences.getBoolean("needGetStatuses", false)) {
|
if (preferences.getBoolean("needGetStatuses", false)) {
|
||||||
reloadContactsStatuses();
|
reloadContactsStatuses();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sectionsToReplace.put("À", "A");
|
||||||
|
sectionsToReplace.put("Á", "A");
|
||||||
|
sectionsToReplace.put("Ä", "A");
|
||||||
|
sectionsToReplace.put("Ù", "U");
|
||||||
|
sectionsToReplace.put("Ú", "U");
|
||||||
|
sectionsToReplace.put("Ü", "U");
|
||||||
|
sectionsToReplace.put("Ì", "I");
|
||||||
|
sectionsToReplace.put("Í", "I");
|
||||||
|
sectionsToReplace.put("Ï", "I");
|
||||||
|
sectionsToReplace.put("È", "E");
|
||||||
|
sectionsToReplace.put("É", "E");
|
||||||
|
sectionsToReplace.put("Ê", "E");
|
||||||
|
sectionsToReplace.put("Ë", "E");
|
||||||
|
sectionsToReplace.put("Ò", "O");
|
||||||
|
sectionsToReplace.put("Ó", "O");
|
||||||
|
sectionsToReplace.put("Ö", "O");
|
||||||
|
sectionsToReplace.put("Ç", "C");
|
||||||
|
sectionsToReplace.put("Ñ", "N");
|
||||||
|
sectionsToReplace.put("Ÿ", "Y");
|
||||||
|
sectionsToReplace.put("Ý", "Y");
|
||||||
|
sectionsToReplace.put("Ţ", "Y");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cleanup() {
|
public void cleanup() {
|
||||||
|
@ -514,10 +537,10 @@ public class ContactsController {
|
||||||
checkContactsInternal();
|
checkContactsInternal();
|
||||||
}
|
}
|
||||||
final HashMap<Integer, Contact> contactsMap = readContactsFromPhoneBook();
|
final HashMap<Integer, Contact> contactsMap = readContactsFromPhoneBook();
|
||||||
final HashMap<String, Contact> contactsBookShort = new HashMap<String, Contact>();
|
final HashMap<String, Contact> contactsBookShort = new HashMap<>();
|
||||||
int oldCount = contactHashMap.size();
|
int oldCount = contactHashMap.size();
|
||||||
|
|
||||||
ArrayList<TLRPC.TL_inputPhoneContact> toImport = new ArrayList<TLRPC.TL_inputPhoneContact>();
|
ArrayList<TLRPC.TL_inputPhoneContact> toImport = new ArrayList<>();
|
||||||
if (!contactHashMap.isEmpty()) {
|
if (!contactHashMap.isEmpty()) {
|
||||||
for (HashMap.Entry<Integer, Contact> pair : contactsMap.entrySet()) {
|
for (HashMap.Entry<Integer, Contact> pair : contactsMap.entrySet()) {
|
||||||
Integer id = pair.getKey();
|
Integer id = pair.getKey();
|
||||||
|
@ -619,10 +642,10 @@ public class ContactsController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final ArrayList<TLRPC.User> toDelete = new ArrayList<TLRPC.User>();
|
final ArrayList<TLRPC.User> toDelete = new ArrayList<>();
|
||||||
if (contactHashMap != null && !contactHashMap.isEmpty()) {
|
if (contactHashMap != null && !contactHashMap.isEmpty()) {
|
||||||
try {
|
try {
|
||||||
final HashMap<String, TLRPC.User> contactsPhonesShort = new HashMap<String, TLRPC.User>();
|
final HashMap<String, TLRPC.User> contactsPhonesShort = new HashMap<>();
|
||||||
|
|
||||||
for (TLRPC.TL_contact value : contacts) {
|
for (TLRPC.TL_contact value : contacts) {
|
||||||
TLRPC.User user = MessagesController.getInstance().getUser(value.user_id);
|
TLRPC.User user = MessagesController.getInstance().getUser(value.user_id);
|
||||||
|
@ -692,7 +715,7 @@ public class ContactsController {
|
||||||
}
|
}
|
||||||
final int count = (int)Math.ceil(toImport.size() / 500.0f);
|
final int count = (int)Math.ceil(toImport.size() / 500.0f);
|
||||||
for (int a = 0; a < count; a++) {
|
for (int a = 0; a < count; a++) {
|
||||||
ArrayList<TLRPC.TL_inputPhoneContact> finalToImport = new ArrayList<TLRPC.TL_inputPhoneContact>();
|
ArrayList<TLRPC.TL_inputPhoneContact> finalToImport = new ArrayList<>();
|
||||||
finalToImport.addAll(toImport.subList(a * 500, Math.min((a + 1) * 500, toImport.size())));
|
finalToImport.addAll(toImport.subList(a * 500, Math.min((a + 1) * 500, toImport.size())));
|
||||||
TLRPC.TL_contacts_importContacts req = new TLRPC.TL_contacts_importContacts();
|
TLRPC.TL_contacts_importContacts req = new TLRPC.TL_contacts_importContacts();
|
||||||
req.contacts = finalToImport;
|
req.contacts = finalToImport;
|
||||||
|
@ -713,7 +736,7 @@ public class ContactsController {
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
MessagesStorage.getInstance().putUsersAndChats(res.users, null, true, true);
|
MessagesStorage.getInstance().putUsersAndChats(res.users, null, true, true);
|
||||||
ArrayList<TLRPC.TL_contact> cArr = new ArrayList<TLRPC.TL_contact>();
|
ArrayList<TLRPC.TL_contact> cArr = new ArrayList<>();
|
||||||
for (TLRPC.TL_importedContact c : res.imported) {
|
for (TLRPC.TL_importedContact c : res.imported) {
|
||||||
TLRPC.TL_contact contact = new TLRPC.TL_contact();
|
TLRPC.TL_contact contact = new TLRPC.TL_contact();
|
||||||
contact.user_id = c.user_id;
|
contact.user_id = c.user_id;
|
||||||
|
@ -848,7 +871,7 @@ public class ContactsController {
|
||||||
public void run() {
|
public void run() {
|
||||||
MessagesController.getInstance().putUsers(usersArr, from == 1);
|
MessagesController.getInstance().putUsers(usersArr, from == 1);
|
||||||
|
|
||||||
final HashMap<Integer, TLRPC.User> usersDict = new HashMap<Integer, TLRPC.User>();
|
final HashMap<Integer, TLRPC.User> usersDict = new HashMap<>();
|
||||||
|
|
||||||
final boolean isEmpty = contactsArr.isEmpty();
|
final boolean isEmpty = contactsArr.isEmpty();
|
||||||
|
|
||||||
|
@ -933,9 +956,9 @@ public class ContactsController {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
final SparseArray<TLRPC.TL_contact> contactsDictionary = new SparseArray<TLRPC.TL_contact>();
|
final SparseArray<TLRPC.TL_contact> contactsDictionary = new SparseArray<>();
|
||||||
final HashMap<String, ArrayList<TLRPC.TL_contact>> sectionsDict = new HashMap<String, ArrayList<TLRPC.TL_contact>>();
|
final HashMap<String, ArrayList<TLRPC.TL_contact>> sectionsDict = new HashMap<>();
|
||||||
final ArrayList<String> sortedSectionsArray = new ArrayList<String>();
|
final ArrayList<String> sortedSectionsArray = new ArrayList<>();
|
||||||
HashMap<String, TLRPC.TL_contact> contactsByPhonesDict = null;
|
HashMap<String, TLRPC.TL_contact> contactsByPhonesDict = null;
|
||||||
|
|
||||||
if (!contactsBookLoaded) {
|
if (!contactsBookLoaded) {
|
||||||
|
@ -958,13 +981,17 @@ public class ContactsController {
|
||||||
if (key == null || key.length() == 0) {
|
if (key == null || key.length() == 0) {
|
||||||
key = user.last_name;
|
key = user.last_name;
|
||||||
}
|
}
|
||||||
|
if (key.length() > 1) {
|
||||||
|
key = key.substring(0, 1);
|
||||||
|
}
|
||||||
if (key.length() == 0) {
|
if (key.length() == 0) {
|
||||||
key = "#";
|
key = "#";
|
||||||
} else {
|
} else {
|
||||||
key = key.toUpperCase();
|
key = key.toUpperCase();
|
||||||
}
|
}
|
||||||
if (key.length() > 1) {
|
String replace = sectionsToReplace.get(key);
|
||||||
key = key.substring(0, 1);
|
if (replace != null) {
|
||||||
|
key = replace;
|
||||||
}
|
}
|
||||||
ArrayList<TLRPC.TL_contact> arr = sectionsDict.get(key);
|
ArrayList<TLRPC.TL_contact> arr = sectionsDict.get(key);
|
||||||
if (arr == null) {
|
if (arr == null) {
|
||||||
|
@ -1067,7 +1094,7 @@ public class ContactsController {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateUnregisteredContacts(final ArrayList<TLRPC.TL_contact> contactsArr) {
|
private void updateUnregisteredContacts(final ArrayList<TLRPC.TL_contact> contactsArr) {
|
||||||
final HashMap<String, TLRPC.TL_contact> contactsPhonesShort = new HashMap<String, TLRPC.TL_contact>();
|
final HashMap<String, TLRPC.TL_contact> contactsPhonesShort = new HashMap<>();
|
||||||
|
|
||||||
for (TLRPC.TL_contact value : contactsArr) {
|
for (TLRPC.TL_contact value : contactsArr) {
|
||||||
TLRPC.User user = MessagesController.getInstance().getUser(value.user_id);
|
TLRPC.User user = MessagesController.getInstance().getUser(value.user_id);
|
||||||
|
@ -1077,7 +1104,7 @@ public class ContactsController {
|
||||||
contactsPhonesShort.put(user.phone, value);
|
contactsPhonesShort.put(user.phone, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
final ArrayList<Contact> sortedPhoneBookContacts = new ArrayList<Contact>();
|
final ArrayList<Contact> sortedPhoneBookContacts = new ArrayList<>();
|
||||||
for (HashMap.Entry<Integer, Contact> pair : contactsBook.entrySet()) {
|
for (HashMap.Entry<Integer, Contact> pair : contactsBook.entrySet()) {
|
||||||
Contact value = pair.getValue();
|
Contact value = pair.getValue();
|
||||||
int id = pair.getKey();
|
int id = pair.getKey();
|
||||||
|
@ -1135,8 +1162,8 @@ public class ContactsController {
|
||||||
}
|
}
|
||||||
|
|
||||||
StringBuilder ids = new StringBuilder();
|
StringBuilder ids = new StringBuilder();
|
||||||
final HashMap<String, ArrayList<TLRPC.TL_contact>> sectionsDict = new HashMap<String, ArrayList<TLRPC.TL_contact>>();
|
final HashMap<String, ArrayList<TLRPC.TL_contact>> sectionsDict = new HashMap<>();
|
||||||
final ArrayList<String> sortedSectionsArray = new ArrayList<String>();
|
final ArrayList<String> sortedSectionsArray = new ArrayList<>();
|
||||||
|
|
||||||
for (TLRPC.TL_contact value : contacts) {
|
for (TLRPC.TL_contact value : contacts) {
|
||||||
TLRPC.User user = MessagesController.getInstance().getUser(value.user_id);
|
TLRPC.User user = MessagesController.getInstance().getUser(value.user_id);
|
||||||
|
@ -1148,17 +1175,21 @@ public class ContactsController {
|
||||||
if (key == null || key.length() == 0) {
|
if (key == null || key.length() == 0) {
|
||||||
key = user.last_name;
|
key = user.last_name;
|
||||||
}
|
}
|
||||||
|
if (key.length() > 1) {
|
||||||
|
key = key.substring(0, 1);
|
||||||
|
}
|
||||||
if (key.length() == 0) {
|
if (key.length() == 0) {
|
||||||
key = "#";
|
key = "#";
|
||||||
} else {
|
} else {
|
||||||
key = key.toUpperCase();
|
key = key.toUpperCase();
|
||||||
}
|
}
|
||||||
if (key.length() > 1) {
|
String replace = sectionsToReplace.get(key);
|
||||||
key = key.substring(0, 1);
|
if (replace != null) {
|
||||||
|
key = replace;
|
||||||
}
|
}
|
||||||
ArrayList<TLRPC.TL_contact> arr = sectionsDict.get(key);
|
ArrayList<TLRPC.TL_contact> arr = sectionsDict.get(key);
|
||||||
if (arr == null) {
|
if (arr == null) {
|
||||||
arr = new ArrayList<TLRPC.TL_contact>();
|
arr = new ArrayList<>();
|
||||||
sectionsDict.put(key, arr);
|
sectionsDict.put(key, arr);
|
||||||
sortedSectionsArray.add(key);
|
sortedSectionsArray.add(key);
|
||||||
}
|
}
|
||||||
|
@ -1193,7 +1224,7 @@ public class ContactsController {
|
||||||
try {
|
try {
|
||||||
Uri rawContactUri = ContactsContract.RawContacts.CONTENT_URI.buildUpon().appendQueryParameter(ContactsContract.RawContacts.ACCOUNT_NAME, currentAccount.name).appendQueryParameter(ContactsContract.RawContacts.ACCOUNT_TYPE, currentAccount.type).build();
|
Uri rawContactUri = ContactsContract.RawContacts.CONTENT_URI.buildUpon().appendQueryParameter(ContactsContract.RawContacts.ACCOUNT_NAME, currentAccount.name).appendQueryParameter(ContactsContract.RawContacts.ACCOUNT_TYPE, currentAccount.type).build();
|
||||||
Cursor c1 = ApplicationLoader.applicationContext.getContentResolver().query(rawContactUri, new String[]{BaseColumns._ID, ContactsContract.RawContacts.SYNC2}, null, null, null);
|
Cursor c1 = ApplicationLoader.applicationContext.getContentResolver().query(rawContactUri, new String[]{BaseColumns._ID, ContactsContract.RawContacts.SYNC2}, null, null, null);
|
||||||
HashMap<Integer, Long> bookContacts = new HashMap<Integer, Long>();
|
HashMap<Integer, Long> bookContacts = new HashMap<>();
|
||||||
if (c1 != null) {
|
if (c1 != null) {
|
||||||
while (c1.moveToNext()) {
|
while (c1.moveToNext()) {
|
||||||
bookContacts.put(c1.getInt(1), c1.getLong(0));
|
bookContacts.put(c1.getInt(1), c1.getLong(0));
|
||||||
|
@ -1213,7 +1244,7 @@ public class ContactsController {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void performWriteContactsToPhoneBook() {
|
private void performWriteContactsToPhoneBook() {
|
||||||
final ArrayList<TLRPC.TL_contact> contactsArray = new ArrayList<TLRPC.TL_contact>();
|
final ArrayList<TLRPC.TL_contact> contactsArray = new ArrayList<>();
|
||||||
contactsArray.addAll(contacts);
|
contactsArray.addAll(contacts);
|
||||||
Utilities.photoBookQueue.postRunnable(new Runnable() {
|
Utilities.photoBookQueue.postRunnable(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -1225,8 +1256,8 @@ public class ContactsController {
|
||||||
|
|
||||||
private void applyContactsUpdates(ArrayList<Integer> ids, ConcurrentHashMap<Integer, TLRPC.User> userDict, ArrayList<TLRPC.TL_contact> newC, ArrayList<Integer> contactsTD) {
|
private void applyContactsUpdates(ArrayList<Integer> ids, ConcurrentHashMap<Integer, TLRPC.User> userDict, ArrayList<TLRPC.TL_contact> newC, ArrayList<Integer> contactsTD) {
|
||||||
if (newC == null || contactsTD == null) {
|
if (newC == null || contactsTD == null) {
|
||||||
newC = new ArrayList<TLRPC.TL_contact>();
|
newC = new ArrayList<>();
|
||||||
contactsTD = new ArrayList<Integer>();
|
contactsTD = new ArrayList<>();
|
||||||
for (Integer uid : ids) {
|
for (Integer uid : ids) {
|
||||||
if (uid > 0) {
|
if (uid > 0) {
|
||||||
TLRPC.TL_contact contact = new TLRPC.TL_contact();
|
TLRPC.TL_contact contact = new TLRPC.TL_contact();
|
||||||
|
@ -1351,8 +1382,8 @@ public class ContactsController {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void processContactsUpdates(ArrayList<Integer> ids, ConcurrentHashMap<Integer, TLRPC.User> userDict) {
|
public void processContactsUpdates(ArrayList<Integer> ids, ConcurrentHashMap<Integer, TLRPC.User> userDict) {
|
||||||
final ArrayList<TLRPC.TL_contact> newContacts = new ArrayList<TLRPC.TL_contact>();
|
final ArrayList<TLRPC.TL_contact> newContacts = new ArrayList<>();
|
||||||
final ArrayList<Integer> contactsToDelete = new ArrayList<Integer>();
|
final ArrayList<Integer> contactsToDelete = new ArrayList<>();
|
||||||
for (Integer uid : ids) {
|
for (Integer uid : ids) {
|
||||||
if (uid > 0) {
|
if (uid > 0) {
|
||||||
TLRPC.TL_contact contact = new TLRPC.TL_contact();
|
TLRPC.TL_contact contact = new TLRPC.TL_contact();
|
||||||
|
@ -1406,7 +1437,7 @@ public class ContactsController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayList<ContentProviderOperation> query = new ArrayList<ContentProviderOperation>();
|
ArrayList<ContentProviderOperation> query = new ArrayList<>();
|
||||||
|
|
||||||
ContentProviderOperation.Builder builder = ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI);
|
ContentProviderOperation.Builder builder = ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI);
|
||||||
builder.withValue(ContactsContract.RawContacts.ACCOUNT_NAME, currentAccount.name);
|
builder.withValue(ContactsContract.RawContacts.ACCOUNT_NAME, currentAccount.name);
|
||||||
|
@ -1471,7 +1502,7 @@ public class ContactsController {
|
||||||
}
|
}
|
||||||
|
|
||||||
TLRPC.TL_contacts_importContacts req = new TLRPC.TL_contacts_importContacts();
|
TLRPC.TL_contacts_importContacts req = new TLRPC.TL_contacts_importContacts();
|
||||||
ArrayList<TLRPC.TL_inputPhoneContact> contactsParams = new ArrayList<TLRPC.TL_inputPhoneContact>();
|
ArrayList<TLRPC.TL_inputPhoneContact> contactsParams = new ArrayList<>();
|
||||||
TLRPC.TL_inputPhoneContact c = new TLRPC.TL_inputPhoneContact();
|
TLRPC.TL_inputPhoneContact c = new TLRPC.TL_inputPhoneContact();
|
||||||
c.phone = user.phone;
|
c.phone = user.phone;
|
||||||
if (!c.phone.startsWith("+")) {
|
if (!c.phone.startsWith("+")) {
|
||||||
|
@ -1510,7 +1541,7 @@ public class ContactsController {
|
||||||
});
|
});
|
||||||
TLRPC.TL_contact newContact = new TLRPC.TL_contact();
|
TLRPC.TL_contact newContact = new TLRPC.TL_contact();
|
||||||
newContact.user_id = u.id;
|
newContact.user_id = u.id;
|
||||||
ArrayList<TLRPC.TL_contact> arrayList = new ArrayList<TLRPC.TL_contact>();
|
ArrayList<TLRPC.TL_contact> arrayList = new ArrayList<>();
|
||||||
arrayList.add(newContact);
|
arrayList.add(newContact);
|
||||||
MessagesStorage.getInstance().putContacts(arrayList, false);
|
MessagesStorage.getInstance().putContacts(arrayList, false);
|
||||||
|
|
||||||
|
@ -1552,7 +1583,7 @@ public class ContactsController {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
TLRPC.TL_contacts_deleteContacts req = new TLRPC.TL_contacts_deleteContacts();
|
TLRPC.TL_contacts_deleteContacts req = new TLRPC.TL_contacts_deleteContacts();
|
||||||
final ArrayList<Integer> uids = new ArrayList<Integer>();
|
final ArrayList<Integer> uids = new ArrayList<>();
|
||||||
for (TLRPC.User user : users) {
|
for (TLRPC.User user : users) {
|
||||||
TLRPC.InputUser inputUser = MessagesController.getInputUser(user);
|
TLRPC.InputUser inputUser = MessagesController.getInputUser(user);
|
||||||
if (inputUser == null) {
|
if (inputUser == null) {
|
||||||
|
@ -1631,7 +1662,7 @@ public class ContactsController {
|
||||||
editor.remove("needGetStatuses").commit();
|
editor.remove("needGetStatuses").commit();
|
||||||
TLRPC.Vector vector = (TLRPC.Vector) response;
|
TLRPC.Vector vector = (TLRPC.Vector) response;
|
||||||
if (!vector.objects.isEmpty()) {
|
if (!vector.objects.isEmpty()) {
|
||||||
ArrayList<TLRPC.User> dbUsersStatus = new ArrayList<TLRPC.User>();
|
ArrayList<TLRPC.User> dbUsersStatus = new ArrayList<>();
|
||||||
for (Object object : vector.objects) {
|
for (Object object : vector.objects) {
|
||||||
TLRPC.User toDbUser = new TLRPC.User();
|
TLRPC.User toDbUser = new TLRPC.User();
|
||||||
TLRPC.TL_contactStatus status = (TLRPC.TL_contactStatus) object;
|
TLRPC.TL_contactStatus status = (TLRPC.TL_contactStatus) object;
|
||||||
|
@ -1741,7 +1772,7 @@ public class ContactsController {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String formatName(String firstName, String lastName) {
|
public static String formatName(String firstName, String lastName) {
|
||||||
String result = null;
|
String result = "";
|
||||||
if (LocaleController.nameDisplayOrder == 1) {
|
if (LocaleController.nameDisplayOrder == 1) {
|
||||||
result = firstName;
|
result = firstName;
|
||||||
if (result == null || result.length() == 0) {
|
if (result == null || result.length() == 0) {
|
||||||
|
|
|
@ -344,7 +344,7 @@ public class ImageLoader {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
AndroidUtilities.runOnUIThread(new Runnable() {
|
imageLoadQueue.postRunnable(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
runHttpTasks(true);
|
runHttpTasks(true);
|
||||||
|
@ -354,7 +354,7 @@ public class ImageLoader {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCancelled() {
|
protected void onCancelled() {
|
||||||
AndroidUtilities.runOnUIThread(new Runnable() {
|
imageLoadQueue.postRunnable(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
runHttpTasks(true);
|
runHttpTasks(true);
|
||||||
|
@ -449,6 +449,11 @@ public class ImageLoader {
|
||||||
originalBitmap = scaledBitmap;
|
originalBitmap = scaledBitmap;
|
||||||
FileOutputStream stream = new FileOutputStream(thumbFile);
|
FileOutputStream stream = new FileOutputStream(thumbFile);
|
||||||
originalBitmap.compress(Bitmap.CompressFormat.JPEG, 60, stream);
|
originalBitmap.compress(Bitmap.CompressFormat.JPEG, 60, stream);
|
||||||
|
try {
|
||||||
|
stream.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
FileLog.e("tmessages", e);
|
||||||
|
}
|
||||||
final BitmapDrawable bitmapDrawable = new BitmapDrawable(originalBitmap);
|
final BitmapDrawable bitmapDrawable = new BitmapDrawable(originalBitmap);
|
||||||
AndroidUtilities.runOnUIThread(new Runnable() {
|
AndroidUtilities.runOnUIThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -615,7 +620,9 @@ public class ImageLoader {
|
||||||
if (mediaId != null) {
|
if (mediaId != null) {
|
||||||
MediaStore.Images.Thumbnails.getThumbnail(ApplicationLoader.applicationContext.getContentResolver(), mediaId, MediaStore.Images.Thumbnails.MINI_KIND, opts);
|
MediaStore.Images.Thumbnails.getThumbnail(ApplicationLoader.applicationContext.getContentResolver(), mediaId, MediaStore.Images.Thumbnails.MINI_KIND, opts);
|
||||||
} else {
|
} else {
|
||||||
BitmapFactory.decodeFile(cacheImage.finalFilePath.getAbsolutePath(), opts);
|
FileInputStream is = new FileInputStream(cacheFileFinal);
|
||||||
|
image = BitmapFactory.decodeStream(is, null, opts);
|
||||||
|
is.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
float photoW = opts.outWidth;
|
float photoW = opts.outWidth;
|
||||||
|
@ -633,14 +640,18 @@ public class ImageLoader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cacheImage.filter == null || blur) {
|
if (cacheImage.filter == null || blur || cacheImage.httpUrl != null) {
|
||||||
opts.inPreferredConfig = Bitmap.Config.ARGB_8888;
|
opts.inPreferredConfig = Bitmap.Config.ARGB_8888;
|
||||||
} else {
|
} else {
|
||||||
opts.inPreferredConfig = Bitmap.Config.RGB_565;
|
opts.inPreferredConfig = Bitmap.Config.RGB_565;
|
||||||
}
|
}
|
||||||
|
//if (Build.VERSION.SDK_INT < 21) {
|
||||||
|
// opts.inPurgeable = true;
|
||||||
|
//}
|
||||||
|
|
||||||
opts.inDither = false;
|
opts.inDither = false;
|
||||||
if (mediaId != null) {
|
if (mediaId != null) {
|
||||||
image = MediaStore.Images.Thumbnails.getThumbnail(ApplicationLoader.applicationContext.getContentResolver(), mediaId, MediaStore.Images.Thumbnails.MINI_KIND, null);
|
image = MediaStore.Images.Thumbnails.getThumbnail(ApplicationLoader.applicationContext.getContentResolver(), mediaId, MediaStore.Images.Thumbnails.MINI_KIND, opts);
|
||||||
}
|
}
|
||||||
if (image == null) {
|
if (image == null) {
|
||||||
if (isWebp) {
|
if (isWebp) {
|
||||||
|
@ -1057,6 +1068,12 @@ public class ImageLoader {
|
||||||
FileLog.e("tmessages", e);
|
FileLog.e("tmessages", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
new File(cachePath, ".nomedia").createNewFile();
|
||||||
|
} catch (Exception e) {
|
||||||
|
FileLog.e("tmessages", e);
|
||||||
|
}
|
||||||
|
|
||||||
mediaDirs.put(FileLoader.MEDIA_DIR_CACHE, cachePath);
|
mediaDirs.put(FileLoader.MEDIA_DIR_CACHE, cachePath);
|
||||||
FileLog.e("tmessages", "cache path = " + cachePath);
|
FileLog.e("tmessages", "cache path = " + cachePath);
|
||||||
|
|
||||||
|
@ -1678,42 +1695,47 @@ public class ImageLoader {
|
||||||
runHttpFileLoadTasks(null, 0);
|
runHttpFileLoadTasks(null, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void runHttpFileLoadTasks(HttpFileTask oldTask, int reason) {
|
private void runHttpFileLoadTasks(final HttpFileTask oldTask, final int reason) {
|
||||||
if (oldTask != null) {
|
AndroidUtilities.runOnUIThread(new Runnable() {
|
||||||
currentHttpFileLoadTasksCount--;
|
@Override
|
||||||
}
|
public void run() {
|
||||||
if (oldTask != null) {
|
if (oldTask != null) {
|
||||||
if (reason == 1) {
|
currentHttpFileLoadTasksCount--;
|
||||||
if (oldTask.canRetry) {
|
}
|
||||||
final HttpFileTask newTask = new HttpFileTask(oldTask.url, oldTask.tempFile, oldTask.ext);
|
if (oldTask != null) {
|
||||||
Runnable runnable = new Runnable() {
|
if (reason == 1) {
|
||||||
@Override
|
if (oldTask.canRetry) {
|
||||||
public void run() {
|
final HttpFileTask newTask = new HttpFileTask(oldTask.url, oldTask.tempFile, oldTask.ext);
|
||||||
httpFileLoadTasks.add(newTask);
|
Runnable runnable = new Runnable() {
|
||||||
runHttpFileLoadTasks(null, 0);
|
@Override
|
||||||
}
|
public void run() {
|
||||||
};
|
httpFileLoadTasks.add(newTask);
|
||||||
retryHttpsTasks.put(oldTask.url, runnable);
|
runHttpFileLoadTasks(null, 0);
|
||||||
AndroidUtilities.runOnUIThread(runnable, 1000);
|
}
|
||||||
} else {
|
};
|
||||||
NotificationCenter.getInstance().postNotificationName(NotificationCenter.httpFileDidFailedLoad, oldTask.url);
|
retryHttpsTasks.put(oldTask.url, runnable);
|
||||||
|
AndroidUtilities.runOnUIThread(runnable, 1000);
|
||||||
|
} else {
|
||||||
|
NotificationCenter.getInstance().postNotificationName(NotificationCenter.httpFileDidFailedLoad, oldTask.url);
|
||||||
|
}
|
||||||
|
} else if (reason == 2) {
|
||||||
|
httpFileLoadTasksByKeys.remove(oldTask.url);
|
||||||
|
File file = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), Utilities.MD5(oldTask.url) + "." + oldTask.ext);
|
||||||
|
String result = oldTask.tempFile.renameTo(file) ? file.toString() : oldTask.tempFile.toString();
|
||||||
|
NotificationCenter.getInstance().postNotificationName(NotificationCenter.httpFileDidLoaded, oldTask.url, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (currentHttpFileLoadTasksCount < 2 && !httpFileLoadTasks.isEmpty()) {
|
||||||
|
HttpFileTask task = httpFileLoadTasks.poll();
|
||||||
|
if (android.os.Build.VERSION.SDK_INT >= 11) {
|
||||||
|
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, null, null, null);
|
||||||
|
} else {
|
||||||
|
task.execute(null, null, null);
|
||||||
|
}
|
||||||
|
currentHttpFileLoadTasksCount++;
|
||||||
}
|
}
|
||||||
} else if (reason == 2) {
|
|
||||||
httpFileLoadTasksByKeys.remove(oldTask.url);
|
|
||||||
File file = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), Utilities.MD5(oldTask.url) + "." + oldTask.ext);
|
|
||||||
String result = oldTask.tempFile.renameTo(file) ? file.toString() : oldTask.tempFile.toString();
|
|
||||||
NotificationCenter.getInstance().postNotificationName(NotificationCenter.httpFileDidLoaded, oldTask.url, result);
|
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
while (currentHttpFileLoadTasksCount < 2 && !httpFileLoadTasks.isEmpty()) {
|
|
||||||
HttpFileTask task = httpFileLoadTasks.poll();
|
|
||||||
if (android.os.Build.VERSION.SDK_INT >= 11) {
|
|
||||||
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, null, null, null);
|
|
||||||
} else {
|
|
||||||
task.execute(null, null, null);
|
|
||||||
}
|
|
||||||
currentHttpFileLoadTasksCount++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Bitmap loadBitmap(String path, Uri uri, float maxWidth, float maxHeight, boolean useMaxScale) {
|
public static Bitmap loadBitmap(String path, Uri uri, float maxWidth, float maxHeight, boolean useMaxScale) {
|
||||||
|
@ -1963,6 +1985,15 @@ public class ImageLoader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (message.media instanceof TLRPC.TL_messageMediaWebPage) {
|
||||||
|
if (message.media.webpage.photo != null) {
|
||||||
|
for (TLRPC.PhotoSize size : message.media.webpage.photo.sizes) {
|
||||||
|
if (size instanceof TLRPC.TL_photoCachedSize) {
|
||||||
|
photoSize = size;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (photoSize != null && photoSize.bytes != null && photoSize.bytes.length != 0) {
|
if (photoSize != null && photoSize.bytes != null && photoSize.bytes.length != 0) {
|
||||||
if (photoSize.location instanceof TLRPC.TL_fileLocationUnavailable) {
|
if (photoSize.location instanceof TLRPC.TL_fileLocationUnavailable) {
|
||||||
|
@ -2000,6 +2031,13 @@ public class ImageLoader {
|
||||||
message.media.video.thumb = newPhotoSize;
|
message.media.video.thumb = newPhotoSize;
|
||||||
} else if (message.media instanceof TLRPC.TL_messageMediaDocument) {
|
} else if (message.media instanceof TLRPC.TL_messageMediaDocument) {
|
||||||
message.media.document.thumb = newPhotoSize;
|
message.media.document.thumb = newPhotoSize;
|
||||||
|
} else if (message.media instanceof TLRPC.TL_messageMediaWebPage) {
|
||||||
|
for (int a = 0; a < message.media.webpage.photo.sizes.size(); a++) {
|
||||||
|
if (message.media.webpage.photo.sizes.get(a) instanceof TLRPC.TL_photoCachedSize) {
|
||||||
|
message.media.webpage.photo.sizes.set(a, newPhotoSize);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,8 +29,8 @@ import org.telegram.messenger.Utilities;
|
||||||
|
|
||||||
public class ImageReceiver implements NotificationCenter.NotificationCenterDelegate {
|
public class ImageReceiver implements NotificationCenter.NotificationCenterDelegate {
|
||||||
|
|
||||||
public static interface ImageReceiverDelegate {
|
public interface ImageReceiverDelegate {
|
||||||
public void didSetImage(ImageReceiver imageReceiver, boolean set, boolean thumb);
|
void didSetImage(ImageReceiver imageReceiver, boolean set, boolean thumb);
|
||||||
}
|
}
|
||||||
|
|
||||||
private View parentView;
|
private View parentView;
|
||||||
|
@ -68,7 +68,8 @@ public class ImageReceiver implements NotificationCenter.NotificationCenterDeleg
|
||||||
private Matrix shaderMatrix;
|
private Matrix shaderMatrix;
|
||||||
private int alpha = 255;
|
private int alpha = 255;
|
||||||
private boolean isPressed;
|
private boolean isPressed;
|
||||||
private boolean disableRecycle;
|
private int orientation;
|
||||||
|
private boolean centerRotation;
|
||||||
private ImageReceiverDelegate delegate;
|
private ImageReceiverDelegate delegate;
|
||||||
|
|
||||||
public ImageReceiver() {
|
public ImageReceiver() {
|
||||||
|
@ -209,12 +210,17 @@ public class ImageReceiver implements NotificationCenter.NotificationCenterDeleg
|
||||||
return isPressed;
|
return isPressed;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setImageBitmap(Bitmap bitmap) {
|
public void setOrientation(int angle, boolean center) {
|
||||||
setImageBitmap(bitmap != null ? new BitmapDrawable(null, bitmap) : null);
|
orientation = angle;
|
||||||
|
centerRotation = center;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDisableRecycle(boolean value) {
|
public int getOrientation() {
|
||||||
disableRecycle = value;
|
return orientation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setImageBitmap(Bitmap bitmap) {
|
||||||
|
setImageBitmap(bitmap != null ? new BitmapDrawable(null, bitmap) : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setImageBitmap(Drawable bitmap) {
|
public void setImageBitmap(Drawable bitmap) {
|
||||||
|
@ -280,8 +286,17 @@ public class ImageReceiver implements NotificationCenter.NotificationCenterDeleg
|
||||||
canvas.drawRoundRect(roundRect, roundRadius, roundRadius, roundPaint);
|
canvas.drawRoundRect(roundRect, roundRadius, roundRadius, roundPaint);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
int bitmapW = bitmapDrawable.getIntrinsicWidth();
|
int bitmapW;
|
||||||
int bitmapH = bitmapDrawable.getIntrinsicHeight();
|
int bitmapH;
|
||||||
|
int originalW = bitmapDrawable.getIntrinsicWidth();
|
||||||
|
int originalH = bitmapDrawable.getIntrinsicHeight();
|
||||||
|
if (orientation == 90 || orientation == 270) {
|
||||||
|
bitmapW = bitmapDrawable.getIntrinsicHeight();
|
||||||
|
bitmapH = bitmapDrawable.getIntrinsicWidth();
|
||||||
|
} else {
|
||||||
|
bitmapW = bitmapDrawable.getIntrinsicWidth();
|
||||||
|
bitmapH = bitmapDrawable.getIntrinsicHeight();
|
||||||
|
}
|
||||||
float scaleW = bitmapW / (float) imageW;
|
float scaleW = bitmapW / (float) imageW;
|
||||||
float scaleH = bitmapH / (float) imageH;
|
float scaleH = bitmapH / (float) imageH;
|
||||||
|
|
||||||
|
@ -312,14 +327,32 @@ public class ImageReceiver implements NotificationCenter.NotificationCenterDeleg
|
||||||
canvas.save();
|
canvas.save();
|
||||||
canvas.clipRect(imageX, imageY, imageX + imageW, imageY + imageH);
|
canvas.clipRect(imageX, imageY, imageX + imageW, imageY + imageH);
|
||||||
|
|
||||||
|
if (orientation != 0) {
|
||||||
|
if (centerRotation) {
|
||||||
|
canvas.rotate(orientation, imageW / 2, imageH / 2);
|
||||||
|
} else {
|
||||||
|
canvas.rotate(orientation, 0, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (bitmapW / scaleH > imageW) {
|
if (bitmapW / scaleH > imageW) {
|
||||||
bitmapW /= scaleH;
|
bitmapW /= scaleH;
|
||||||
|
originalW /= scaleH;
|
||||||
drawRegion.set(imageX - (bitmapW - imageW) / 2, imageY, imageX + (bitmapW + imageW) / 2, imageY + imageH);
|
drawRegion.set(imageX - (bitmapW - imageW) / 2, imageY, imageX + (bitmapW + imageW) / 2, imageY + imageH);
|
||||||
} else {
|
} else {
|
||||||
bitmapH /= scaleW;
|
bitmapH /= scaleW;
|
||||||
|
originalH /= scaleW;
|
||||||
drawRegion.set(imageX, imageY - (bitmapH - imageH) / 2, imageX + imageW, imageY + (bitmapH + imageH) / 2);
|
drawRegion.set(imageX, imageY - (bitmapH - imageH) / 2, imageX + imageW, imageY + (bitmapH + imageH) / 2);
|
||||||
}
|
}
|
||||||
bitmapDrawable.setBounds(drawRegion);
|
if (orientation == 90 || orientation == 270) {
|
||||||
|
int width = (drawRegion.right - drawRegion.left) / 2;
|
||||||
|
int height = (drawRegion.bottom - drawRegion.top) / 2;
|
||||||
|
int centerX = (drawRegion.right + drawRegion.left) / 2;
|
||||||
|
int centerY = (drawRegion.top + drawRegion.bottom) / 2;
|
||||||
|
bitmapDrawable.setBounds(centerX - height, centerY - width, centerX + height, centerY + width);
|
||||||
|
} else {
|
||||||
|
bitmapDrawable.setBounds(drawRegion);
|
||||||
|
}
|
||||||
if (isVisible) {
|
if (isVisible) {
|
||||||
try {
|
try {
|
||||||
bitmapDrawable.setAlpha(alpha);
|
bitmapDrawable.setAlpha(alpha);
|
||||||
|
@ -339,8 +372,24 @@ public class ImageReceiver implements NotificationCenter.NotificationCenterDeleg
|
||||||
|
|
||||||
canvas.restore();
|
canvas.restore();
|
||||||
} else {
|
} else {
|
||||||
|
canvas.save();
|
||||||
|
if (orientation != 0) {
|
||||||
|
if (centerRotation) {
|
||||||
|
canvas.rotate(orientation, imageW / 2, imageH / 2);
|
||||||
|
} else {
|
||||||
|
canvas.rotate(orientation, 0, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
drawRegion.set(imageX, imageY, imageX + imageW, imageY + imageH);
|
drawRegion.set(imageX, imageY, imageX + imageW, imageY + imageH);
|
||||||
bitmapDrawable.setBounds(drawRegion);
|
if (orientation == 90 || orientation == 270) {
|
||||||
|
int width = (drawRegion.right - drawRegion.left) / 2;
|
||||||
|
int height = (drawRegion.bottom - drawRegion.top) / 2;
|
||||||
|
int centerX = (drawRegion.right + drawRegion.left) / 2;
|
||||||
|
int centerY = (drawRegion.top + drawRegion.bottom) / 2;
|
||||||
|
bitmapDrawable.setBounds(centerX - height, centerY - width, centerX + height, centerY + width);
|
||||||
|
} else {
|
||||||
|
bitmapDrawable.setBounds(drawRegion);
|
||||||
|
}
|
||||||
if (isVisible) {
|
if (isVisible) {
|
||||||
try {
|
try {
|
||||||
bitmapDrawable.setAlpha(alpha);
|
bitmapDrawable.setAlpha(alpha);
|
||||||
|
@ -357,6 +406,7 @@ public class ImageReceiver implements NotificationCenter.NotificationCenterDeleg
|
||||||
FileLog.e("tmessages", e);
|
FileLog.e("tmessages", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
canvas.restore();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -391,6 +441,16 @@ public class ImageReceiver implements NotificationCenter.NotificationCenterDeleg
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getBitmapWidth() {
|
||||||
|
Bitmap bitmap = getBitmap();
|
||||||
|
return orientation == 0 || orientation == 180 ? bitmap.getWidth() : bitmap.getHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getBitmapHeight() {
|
||||||
|
Bitmap bitmap = getBitmap();
|
||||||
|
return orientation == 0 || orientation == 180 ? bitmap.getHeight() : bitmap.getWidth();
|
||||||
|
}
|
||||||
|
|
||||||
public void setVisible(boolean value, boolean invalidate) {
|
public void setVisible(boolean value, boolean invalidate) {
|
||||||
if (isVisible == value) {
|
if (isVisible == value) {
|
||||||
return;
|
return;
|
||||||
|
@ -432,10 +492,18 @@ public class ImageReceiver implements NotificationCenter.NotificationCenterDeleg
|
||||||
return imageX;
|
return imageX;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getImageX2() {
|
||||||
|
return imageX + imageW;
|
||||||
|
}
|
||||||
|
|
||||||
public int getImageY() {
|
public int getImageY() {
|
||||||
return imageY;
|
return imageY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getImageY2() {
|
||||||
|
return imageY + imageH;
|
||||||
|
}
|
||||||
|
|
||||||
public int getImageWidth() {
|
public int getImageWidth() {
|
||||||
return imageW;
|
return imageW;
|
||||||
}
|
}
|
||||||
|
@ -617,7 +685,7 @@ public class ImageReceiver implements NotificationCenter.NotificationCenterDeleg
|
||||||
if (newKey != null) {
|
if (newKey != null) {
|
||||||
newBitmap = ImageLoader.getInstance().getImageFromMemory(newKey);
|
newBitmap = ImageLoader.getInstance().getImageFromMemory(newKey);
|
||||||
}
|
}
|
||||||
if (key == null || image == null || image == newBitmap || disableRecycle) {
|
if (key == null || image == null || image == newBitmap) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Bitmap bitmap = image.getBitmap();
|
Bitmap bitmap = image.getBitmap();
|
||||||
|
|
|
@ -54,6 +54,7 @@ public class LocaleController {
|
||||||
public static FastDateFormat formatterWeek;
|
public static FastDateFormat formatterWeek;
|
||||||
public static FastDateFormat formatterMonth;
|
public static FastDateFormat formatterMonth;
|
||||||
public static FastDateFormat formatterYear;
|
public static FastDateFormat formatterYear;
|
||||||
|
public static FastDateFormat formatterMonthYear;
|
||||||
public static FastDateFormat formatterYearMax;
|
public static FastDateFormat formatterYearMax;
|
||||||
public static FastDateFormat chatDate;
|
public static FastDateFormat chatDate;
|
||||||
public static FastDateFormat chatFullDate;
|
public static FastDateFormat chatFullDate;
|
||||||
|
@ -135,7 +136,7 @@ public class LocaleController {
|
||||||
addRules(new String[]{"bem", "brx", "da", "de", "el", "en", "eo", "es", "et", "fi", "fo", "gl", "he", "iw", "it", "nb",
|
addRules(new String[]{"bem", "brx", "da", "de", "el", "en", "eo", "es", "et", "fi", "fo", "gl", "he", "iw", "it", "nb",
|
||||||
"nl", "nn", "no", "sv", "af", "bg", "bn", "ca", "eu", "fur", "fy", "gu", "ha", "is", "ku",
|
"nl", "nn", "no", "sv", "af", "bg", "bn", "ca", "eu", "fur", "fy", "gu", "ha", "is", "ku",
|
||||||
"lb", "ml", "mr", "nah", "ne", "om", "or", "pa", "pap", "ps", "so", "sq", "sw", "ta", "te",
|
"lb", "ml", "mr", "nah", "ne", "om", "or", "pa", "pap", "ps", "so", "sq", "sw", "ta", "te",
|
||||||
"tk", "ur", "zu", "mn", "gsw", "chr", "rm", "pt"}, new PluralRules_One());
|
"tk", "ur", "zu", "mn", "gsw", "chr", "rm", "pt", "an", "ast"}, new PluralRules_One());
|
||||||
addRules(new String[]{"cs", "sk"}, new PluralRules_Czech());
|
addRules(new String[]{"cs", "sk"}, new PluralRules_Czech());
|
||||||
addRules(new String[]{"ff", "fr", "kab"}, new PluralRules_French());
|
addRules(new String[]{"ff", "fr", "kab"}, new PluralRules_French());
|
||||||
addRules(new String[]{"hr", "ru", "sr", "uk", "be", "bs", "sh"}, new PluralRules_Balkan());
|
addRules(new String[]{"hr", "ru", "sr", "uk", "be", "bs", "sh"}, new PluralRules_Balkan());
|
||||||
|
@ -443,10 +444,12 @@ public class LocaleController {
|
||||||
}
|
}
|
||||||
|
|
||||||
private HashMap<String, String> getLocaleFileStrings(File file) {
|
private HashMap<String, String> getLocaleFileStrings(File file) {
|
||||||
|
FileInputStream stream = null;
|
||||||
try {
|
try {
|
||||||
HashMap<String, String> stringMap = new HashMap<>();
|
HashMap<String, String> stringMap = new HashMap<>();
|
||||||
XmlPullParser parser = Xml.newPullParser();
|
XmlPullParser parser = Xml.newPullParser();
|
||||||
parser.setInput(new FileInputStream(file), "UTF-8");
|
stream = new FileInputStream(file);
|
||||||
|
parser.setInput(stream, "UTF-8");
|
||||||
int eventType = parser.getEventType();
|
int eventType = parser.getEventType();
|
||||||
String name = null;
|
String name = null;
|
||||||
String value = null;
|
String value = null;
|
||||||
|
@ -483,6 +486,15 @@ public class LocaleController {
|
||||||
return stringMap;
|
return stringMap;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
FileLog.e("tmessages", e);
|
FileLog.e("tmessages", e);
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (stream != null) {
|
||||||
|
stream.close();
|
||||||
|
stream = null;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
FileLog.e("tmessages", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -544,6 +556,9 @@ public class LocaleController {
|
||||||
currentLocale = newLocale;
|
currentLocale = newLocale;
|
||||||
currentLocaleInfo = localeInfo;
|
currentLocaleInfo = localeInfo;
|
||||||
currentPluralRules = allRules.get(currentLocale.getLanguage());
|
currentPluralRules = allRules.get(currentLocale.getLanguage());
|
||||||
|
if (currentPluralRules == null) {
|
||||||
|
currentPluralRules = allRules.get("en");
|
||||||
|
}
|
||||||
changingConfiguration = true;
|
changingConfiguration = true;
|
||||||
Locale.setDefault(currentLocale);
|
Locale.setDefault(currentLocale);
|
||||||
android.content.res.Configuration config = new android.content.res.Configuration();
|
android.content.res.Configuration config = new android.content.res.Configuration();
|
||||||
|
@ -571,6 +586,9 @@ public class LocaleController {
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
value = ApplicationLoader.applicationContext.getString(res);
|
value = ApplicationLoader.applicationContext.getString(res);
|
||||||
}
|
}
|
||||||
|
if (value == null) {
|
||||||
|
value = "LOC_ERR:" + key;
|
||||||
|
}
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -638,6 +656,9 @@ public class LocaleController {
|
||||||
}
|
}
|
||||||
currentLocale = newLocale;
|
currentLocale = newLocale;
|
||||||
currentPluralRules = allRules.get(currentLocale.getLanguage());
|
currentPluralRules = allRules.get(currentLocale.getLanguage());
|
||||||
|
if (currentPluralRules == null) {
|
||||||
|
currentPluralRules = allRules.get("en");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -695,6 +716,20 @@ public class LocaleController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private FastDateFormat createFormatter(Locale locale, String format, String defaultFormat) {
|
||||||
|
if (format == null || format.length() == 0) {
|
||||||
|
format = defaultFormat;
|
||||||
|
}
|
||||||
|
FastDateFormat formatter = null;
|
||||||
|
try {
|
||||||
|
formatter = FastDateFormat.getInstance(format, locale);
|
||||||
|
} catch (Exception e) {
|
||||||
|
format = defaultFormat;
|
||||||
|
formatter = FastDateFormat.getInstance(format, locale);
|
||||||
|
}
|
||||||
|
return formatter;
|
||||||
|
}
|
||||||
|
|
||||||
public void recreateFormatters() {
|
public void recreateFormatters() {
|
||||||
Locale locale = currentLocale;
|
Locale locale = currentLocale;
|
||||||
if (locale == null) {
|
if (locale == null) {
|
||||||
|
@ -706,59 +741,15 @@ public class LocaleController {
|
||||||
}
|
}
|
||||||
isRTL = lang.toLowerCase().equals("ar");
|
isRTL = lang.toLowerCase().equals("ar");
|
||||||
nameDisplayOrder = lang.toLowerCase().equals("ko") ? 2 : 1;
|
nameDisplayOrder = lang.toLowerCase().equals("ko") ? 2 : 1;
|
||||||
String formatString = getStringInternal("formatterMonth", R.string.formatterMonth);
|
|
||||||
if (formatString == null || formatString.length() == 0) {
|
|
||||||
formatString = "dd MMM";
|
|
||||||
}
|
|
||||||
formatterMonth = FastDateFormat.getInstance(formatString, locale);
|
|
||||||
|
|
||||||
formatString = getStringInternal("formatterYear", R.string.formatterYear);
|
formatterMonth = createFormatter(locale, getStringInternal("formatterMonth", R.string.formatterMonth), "dd MMM");
|
||||||
if (formatString == null || formatString.length() == 0) {
|
formatterYear = createFormatter(locale, getStringInternal("formatterYear", R.string.formatterYear), "dd.MM.yy");
|
||||||
formatString = "dd.MM.yy";
|
formatterYearMax = createFormatter(locale, getStringInternal("formatterYearMax", R.string.formatterYearMax), "dd.MM.yyyy");
|
||||||
}
|
chatDate = createFormatter(locale, getStringInternal("chatDate", R.string.chatDate), "d MMMM");
|
||||||
formatterYear = FastDateFormat.getInstance(formatString, locale);
|
chatFullDate = createFormatter(locale, getStringInternal("chatFullDate", R.string.chatFullDate), "d MMMM yyyy");
|
||||||
|
formatterWeek = createFormatter(locale, getStringInternal("formatterWeek", R.string.formatterWeek), "EEE");
|
||||||
formatString = getStringInternal("formatterYearMax", R.string.formatterYearMax);
|
formatterMonthYear = createFormatter(locale, getStringInternal("formatterMonthYear", R.string.formatterMonthYear), "MMMM yyyy");
|
||||||
if (formatString == null || formatString.length() == 0) {
|
formatterDay = createFormatter(lang.toLowerCase().equals("ar") || lang.toLowerCase().equals("ko") ? locale : Locale.US, is24HourFormat ? getStringInternal("formatterDay24H", R.string.formatterDay24H) : getStringInternal("formatterDay12H", R.string.formatterDay12H), is24HourFormat ? "HH:mm" : "h:mm a");
|
||||||
formatString = "dd.MM.yyyy";
|
|
||||||
}
|
|
||||||
formatterYearMax = FastDateFormat.getInstance(formatString, locale);
|
|
||||||
|
|
||||||
formatString = getStringInternal("chatDate", R.string.chatDate);
|
|
||||||
if (formatString == null || formatString.length() == 0) {
|
|
||||||
formatString = "d MMMM";
|
|
||||||
}
|
|
||||||
chatDate = FastDateFormat.getInstance(formatString, locale);
|
|
||||||
|
|
||||||
formatString = getStringInternal("chatFullDate", R.string.chatFullDate);
|
|
||||||
if (formatString == null || formatString.length() == 0) {
|
|
||||||
formatString = "d MMMM yyyy";
|
|
||||||
}
|
|
||||||
chatFullDate = FastDateFormat.getInstance(formatString, locale);
|
|
||||||
|
|
||||||
formatString = getStringInternal("formatterWeek", R.string.formatterWeek);
|
|
||||||
if (formatString == null || formatString.length() == 0) {
|
|
||||||
formatString = "EEE";
|
|
||||||
}
|
|
||||||
formatterWeek = FastDateFormat.getInstance(formatString, locale);
|
|
||||||
|
|
||||||
if (is24HourFormat) {
|
|
||||||
formatString = getStringInternal("formatterDay24H", R.string.formatterDay24H);
|
|
||||||
} else {
|
|
||||||
formatString = getStringInternal("formatterDay12H", R.string.formatterDay12H);
|
|
||||||
}
|
|
||||||
if (formatString == null || formatString.length() == 0) {
|
|
||||||
if (is24HourFormat) {
|
|
||||||
formatString = "HH:mm";
|
|
||||||
} else {
|
|
||||||
formatString = "h:mm a";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (lang.toLowerCase().equals("ar") || lang.toLowerCase().equals("ko")) {
|
|
||||||
formatterDay = FastDateFormat.getInstance(formatString, locale);
|
|
||||||
} else {
|
|
||||||
formatterDay = FastDateFormat.getInstance(formatString, Locale.US);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String stringForMessageListDate(long date) {
|
public static String stringForMessageListDate(long date) {
|
||||||
|
|
|
@ -87,12 +87,12 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
|
||||||
|
|
||||||
public static int[] readArgs = new int[3];
|
public static int[] readArgs = new int[3];
|
||||||
|
|
||||||
public static interface FileDownloadProgressListener {
|
public interface FileDownloadProgressListener {
|
||||||
public void onFailedDownload(String fileName);
|
void onFailedDownload(String fileName);
|
||||||
public void onSuccessDownload(String fileName);
|
void onSuccessDownload(String fileName);
|
||||||
public void onProgressDownload(String fileName, float progress);
|
void onProgressDownload(String fileName, float progress);
|
||||||
public void onProgressUpload(String fileName, float progress, boolean isEncrypted);
|
void onProgressUpload(String fileName, float progress, boolean isEncrypted);
|
||||||
public int getObserverTag();
|
int getObserverTag();
|
||||||
}
|
}
|
||||||
|
|
||||||
private class AudioBuffer {
|
private class AudioBuffer {
|
||||||
|
@ -165,6 +165,8 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
|
||||||
public int size;
|
public int size;
|
||||||
public int type;
|
public int type;
|
||||||
public int date;
|
public int date;
|
||||||
|
public String thumbPath;
|
||||||
|
public String imagePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final static String MIME_TYPE = "video/avc";
|
public final static String MIME_TYPE = "video/avc";
|
||||||
|
@ -232,6 +234,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
|
||||||
private long recordStartTime;
|
private long recordStartTime;
|
||||||
private long recordTimeCount;
|
private long recordTimeCount;
|
||||||
private long recordDialogId;
|
private long recordDialogId;
|
||||||
|
private MessageObject recordReplyingMessageObject;
|
||||||
private DispatchQueue fileDecodingQueue;
|
private DispatchQueue fileDecodingQueue;
|
||||||
private DispatchQueue playerQueue;
|
private DispatchQueue playerQueue;
|
||||||
private ArrayList<AudioBuffer> usedPlayerBuffers = new ArrayList<>();
|
private ArrayList<AudioBuffer> usedPlayerBuffers = new ArrayList<>();
|
||||||
|
@ -507,7 +510,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
|
||||||
lastProgress = progress;
|
lastProgress = progress;
|
||||||
playingMessageObject.audioProgress = value;
|
playingMessageObject.audioProgress = value;
|
||||||
playingMessageObject.audioProgressSec = lastProgress / 1000;
|
playingMessageObject.audioProgressSec = lastProgress / 1000;
|
||||||
NotificationCenter.getInstance().postNotificationName(NotificationCenter.audioProgressDidChanged, playingMessageObject.messageOwner.id, value);
|
NotificationCenter.getInstance().postNotificationName(NotificationCenter.audioProgressDidChanged, playingMessageObject.getId(), value);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
FileLog.e("tmessages", e);
|
FileLog.e("tmessages", e);
|
||||||
}
|
}
|
||||||
|
@ -975,7 +978,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
|
||||||
} else if (id == NotificationCenter.messagesDeleted) {
|
} else if (id == NotificationCenter.messagesDeleted) {
|
||||||
if (playingMessageObject != null) {
|
if (playingMessageObject != null) {
|
||||||
ArrayList<Integer> markAsDeletedMessages = (ArrayList<Integer>)args[0];
|
ArrayList<Integer> markAsDeletedMessages = (ArrayList<Integer>)args[0];
|
||||||
if (markAsDeletedMessages.contains(playingMessageObject.messageOwner.id)) {
|
if (markAsDeletedMessages.contains(playingMessageObject.getId())) {
|
||||||
clenupPlayer(false);
|
clenupPlayer(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1102,8 +1105,16 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
|
||||||
if (proximitySensor != null && audioTrackPlayer == null && audioPlayer == null || isPaused || (useFrontSpeaker == (event.values[0] < proximitySensor.getMaximumRange() / 10))) {
|
if (proximitySensor != null && audioTrackPlayer == null && audioPlayer == null || isPaused || (useFrontSpeaker == (event.values[0] < proximitySensor.getMaximumRange() / 10))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
boolean newValue = event.values[0] < proximitySensor.getMaximumRange() / 10;
|
||||||
|
try {
|
||||||
|
if (newValue && NotificationsController.getInstance().audioManager.isWiredHeadsetOn()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
FileLog.e("tmessages", e);
|
||||||
|
}
|
||||||
ignoreProximity = true;
|
ignoreProximity = true;
|
||||||
useFrontSpeaker = event.values[0] < proximitySensor.getMaximumRange() / 10;
|
useFrontSpeaker = newValue;
|
||||||
NotificationCenter.getInstance().postNotificationName(NotificationCenter.audioRouteChanged, useFrontSpeaker);
|
NotificationCenter.getInstance().postNotificationName(NotificationCenter.audioRouteChanged, useFrontSpeaker);
|
||||||
MessageObject currentMessageObject = playingMessageObject;
|
MessageObject currentMessageObject = playingMessageObject;
|
||||||
float progress = playingMessageObject.audioProgress;
|
float progress = playingMessageObject.audioProgress;
|
||||||
|
@ -1185,7 +1196,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
|
||||||
playingMessageObject.audioProgressSec = 0;
|
playingMessageObject.audioProgressSec = 0;
|
||||||
playingMessageObject = null;
|
playingMessageObject = null;
|
||||||
if (notify) {
|
if (notify) {
|
||||||
NotificationCenter.getInstance().postNotificationName(NotificationCenter.audioDidReset, lastFile.messageOwner.id);
|
NotificationCenter.getInstance().postNotificationName(NotificationCenter.audioDidReset, lastFile.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1225,7 +1236,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean seekToProgress(MessageObject messageObject, float progress) {
|
public boolean seekToProgress(MessageObject messageObject, float progress) {
|
||||||
if (audioTrackPlayer == null && audioPlayer == null || messageObject == null || playingMessageObject == null || playingMessageObject != null && playingMessageObject.messageOwner.id != messageObject.messageOwner.id) {
|
if (audioTrackPlayer == null && audioPlayer == null || messageObject == null || playingMessageObject == null || playingMessageObject != null && playingMessageObject.getId() != messageObject.getId()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
@ -1247,7 +1258,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
|
||||||
if (messageObject == null) {
|
if (messageObject == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ((audioTrackPlayer != null || audioPlayer != null) && playingMessageObject != null && messageObject.messageOwner.id == playingMessageObject.messageOwner.id) {
|
if ((audioTrackPlayer != null || audioPlayer != null) && playingMessageObject != null && messageObject.getId() == playingMessageObject.getId()) {
|
||||||
if (isPaused) {
|
if (isPaused) {
|
||||||
resumeAudio(messageObject);
|
resumeAudio(messageObject);
|
||||||
}
|
}
|
||||||
|
@ -1410,7 +1421,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
|
||||||
|
|
||||||
public boolean pauseAudio(MessageObject messageObject) {
|
public boolean pauseAudio(MessageObject messageObject) {
|
||||||
stopProximitySensor();
|
stopProximitySensor();
|
||||||
if (audioTrackPlayer == null && audioPlayer == null || messageObject == null || playingMessageObject == null || playingMessageObject != null && playingMessageObject.messageOwner.id != messageObject.messageOwner.id) {
|
if (audioTrackPlayer == null && audioPlayer == null || messageObject == null || playingMessageObject == null || playingMessageObject != null && playingMessageObject.getId() != messageObject.getId()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
@ -1430,7 +1441,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
|
||||||
|
|
||||||
public boolean resumeAudio(MessageObject messageObject) {
|
public boolean resumeAudio(MessageObject messageObject) {
|
||||||
startProximitySensor();
|
startProximitySensor();
|
||||||
if (audioTrackPlayer == null && audioPlayer == null || messageObject == null || playingMessageObject == null || playingMessageObject != null && playingMessageObject.messageOwner.id != messageObject.messageOwner.id) {
|
if (audioTrackPlayer == null && audioPlayer == null || messageObject == null || playingMessageObject == null || playingMessageObject != null && playingMessageObject.getId() != messageObject.getId()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
@ -1449,14 +1460,14 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPlayingAudio(MessageObject messageObject) {
|
public boolean isPlayingAudio(MessageObject messageObject) {
|
||||||
return !(audioTrackPlayer == null && audioPlayer == null || messageObject == null || playingMessageObject == null || playingMessageObject != null && playingMessageObject.messageOwner.id != messageObject.messageOwner.id);
|
return !(audioTrackPlayer == null && audioPlayer == null || messageObject == null || playingMessageObject == null || playingMessageObject != null && playingMessageObject.getId() != messageObject.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAudioPaused() {
|
public boolean isAudioPaused() {
|
||||||
return isPaused;
|
return isPaused;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startRecording(final long dialog_id) {
|
public void startRecording(final long dialog_id, final MessageObject reply_to_msg) {
|
||||||
clenupPlayer(true);
|
clenupPlayer(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -1503,6 +1514,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
|
||||||
recordStartTime = System.currentTimeMillis();
|
recordStartTime = System.currentTimeMillis();
|
||||||
recordTimeCount = 0;
|
recordTimeCount = 0;
|
||||||
recordDialogId = dialog_id;
|
recordDialogId = dialog_id;
|
||||||
|
recordReplyingMessageObject = reply_to_msg;
|
||||||
fileBuffer.rewind();
|
fileBuffer.rewind();
|
||||||
|
|
||||||
audioRecorder.startRecording();
|
audioRecorder.startRecording();
|
||||||
|
@ -1555,11 +1567,11 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
|
||||||
long duration = recordTimeCount;
|
long duration = recordTimeCount;
|
||||||
audioToSend.duration = (int) (duration / 1000);
|
audioToSend.duration = (int) (duration / 1000);
|
||||||
if (duration > 700) {
|
if (duration > 700) {
|
||||||
SendMessagesHelper.getInstance().sendMessage(audioToSend, recordingAudioFileToSend.getAbsolutePath(), recordDialogId);
|
SendMessagesHelper.getInstance().sendMessage(audioToSend, recordingAudioFileToSend.getAbsolutePath(), recordDialogId, recordReplyingMessageObject);
|
||||||
|
NotificationCenter.getInstance().postNotificationName(NotificationCenter.audioDidSent);
|
||||||
} else {
|
} else {
|
||||||
recordingAudioFileToSend.delete();
|
recordingAudioFileToSend.delete();
|
||||||
}
|
}
|
||||||
NotificationCenter.getInstance().postNotificationName(NotificationCenter.audioDidSent);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1696,10 +1708,10 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
|
||||||
FileLog.e("tmessages", e);
|
FileLog.e("tmessages", e);
|
||||||
result = false;
|
result = false;
|
||||||
} finally {
|
} finally {
|
||||||
if(source != null) {
|
if (source != null) {
|
||||||
source.close();
|
source.close();
|
||||||
}
|
}
|
||||||
if(destination != null) {
|
if (destination != null) {
|
||||||
destination.close();
|
destination.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1737,7 +1749,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentGifDrawable != null && currentGifMessageObject != null && messageObject.messageOwner.id == currentGifMessageObject.messageOwner.id) {
|
if (currentGifDrawable != null && currentGifMessageObject != null && messageObject.getId() == currentGifMessageObject.getId()) {
|
||||||
currentMediaCell = cell;
|
currentMediaCell = cell;
|
||||||
currentGifDrawable.parentView = new WeakReference<View>(cell);
|
currentGifDrawable.parentView = new WeakReference<View>(cell);
|
||||||
return currentGifDrawable;
|
return currentGifDrawable;
|
||||||
|
@ -1786,7 +1798,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentGifMessageObject != null && messageObject.messageOwner.id == currentGifMessageObject.messageOwner.id) {
|
if (currentGifMessageObject != null && messageObject.getId() == currentGifMessageObject.getId()) {
|
||||||
if (currentGifDrawable != null) {
|
if (currentGifDrawable != null) {
|
||||||
currentGifDrawable.stop();
|
currentGifDrawable.stop();
|
||||||
currentGifDrawable.recycle();
|
currentGifDrawable.recycle();
|
||||||
|
|
|
@ -30,6 +30,8 @@ import java.util.AbstractMap;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class MessageObject {
|
public class MessageObject {
|
||||||
|
|
||||||
|
@ -39,9 +41,12 @@ public class MessageObject {
|
||||||
|
|
||||||
public TLRPC.Message messageOwner;
|
public TLRPC.Message messageOwner;
|
||||||
public CharSequence messageText;
|
public CharSequence messageText;
|
||||||
|
public CharSequence linkDescription;
|
||||||
|
public MessageObject replyMessageObject;
|
||||||
public int type;
|
public int type;
|
||||||
public int contentType;
|
public int contentType;
|
||||||
public String dateKey;
|
public String dateKey;
|
||||||
|
public String monthKey;
|
||||||
public boolean deleted = false;
|
public boolean deleted = false;
|
||||||
public float audioProgress;
|
public float audioProgress;
|
||||||
public int audioProgressSec;
|
public int audioProgressSec;
|
||||||
|
@ -75,6 +80,10 @@ public class MessageObject {
|
||||||
|
|
||||||
messageOwner = message;
|
messageOwner = message;
|
||||||
|
|
||||||
|
if (message.replyMessage != null) {
|
||||||
|
replyMessageObject = new MessageObject(message.replyMessage, users, false);
|
||||||
|
}
|
||||||
|
|
||||||
if (message instanceof TLRPC.TL_messageService) {
|
if (message instanceof TLRPC.TL_messageService) {
|
||||||
if (message.action != null) {
|
if (message.action != null) {
|
||||||
TLRPC.User fromUser = null;
|
TLRPC.User fromUser = null;
|
||||||
|
@ -85,7 +94,7 @@ public class MessageObject {
|
||||||
fromUser = MessagesController.getInstance().getUser(message.from_id);
|
fromUser = MessagesController.getInstance().getUser(message.from_id);
|
||||||
}
|
}
|
||||||
if (message.action instanceof TLRPC.TL_messageActionChatCreate) {
|
if (message.action instanceof TLRPC.TL_messageActionChatCreate) {
|
||||||
if (isFromMe()) {
|
if (isOut()) {
|
||||||
messageText = LocaleController.getString("ActionYouCreateGroup", R.string.ActionYouCreateGroup);
|
messageText = LocaleController.getString("ActionYouCreateGroup", R.string.ActionYouCreateGroup);
|
||||||
} else {
|
} else {
|
||||||
if (fromUser != null) {
|
if (fromUser != null) {
|
||||||
|
@ -96,7 +105,7 @@ public class MessageObject {
|
||||||
}
|
}
|
||||||
} else if (message.action instanceof TLRPC.TL_messageActionChatDeleteUser) {
|
} else if (message.action instanceof TLRPC.TL_messageActionChatDeleteUser) {
|
||||||
if (message.action.user_id == message.from_id) {
|
if (message.action.user_id == message.from_id) {
|
||||||
if (isFromMe()) {
|
if (isOut()) {
|
||||||
messageText = LocaleController.getString("ActionYouLeftUser", R.string.ActionYouLeftUser);
|
messageText = LocaleController.getString("ActionYouLeftUser", R.string.ActionYouLeftUser);
|
||||||
} else {
|
} else {
|
||||||
if (fromUser != null) {
|
if (fromUser != null) {
|
||||||
|
@ -114,7 +123,7 @@ public class MessageObject {
|
||||||
whoUser = MessagesController.getInstance().getUser(message.action.user_id);
|
whoUser = MessagesController.getInstance().getUser(message.action.user_id);
|
||||||
}
|
}
|
||||||
if (whoUser != null && fromUser != null) {
|
if (whoUser != null && fromUser != null) {
|
||||||
if (isFromMe()) {
|
if (isOut()) {
|
||||||
messageText = replaceWithLink(LocaleController.getString("ActionYouKickUser", R.string.ActionYouKickUser), "un2", whoUser);
|
messageText = replaceWithLink(LocaleController.getString("ActionYouKickUser", R.string.ActionYouKickUser), "un2", whoUser);
|
||||||
} else if (message.action.user_id == UserConfig.getClientUserId()) {
|
} else if (message.action.user_id == UserConfig.getClientUserId()) {
|
||||||
messageText = replaceWithLink(LocaleController.getString("ActionKickUserYou", R.string.ActionKickUserYou), "un1", fromUser);
|
messageText = replaceWithLink(LocaleController.getString("ActionKickUserYou", R.string.ActionKickUserYou), "un1", fromUser);
|
||||||
|
@ -135,7 +144,7 @@ public class MessageObject {
|
||||||
whoUser = MessagesController.getInstance().getUser(message.action.user_id);
|
whoUser = MessagesController.getInstance().getUser(message.action.user_id);
|
||||||
}
|
}
|
||||||
if (whoUser != null && fromUser != null) {
|
if (whoUser != null && fromUser != null) {
|
||||||
if (isFromMe()) {
|
if (isOut()) {
|
||||||
messageText = replaceWithLink(LocaleController.getString("ActionYouAddUser", R.string.ActionYouAddUser), "un2", whoUser);
|
messageText = replaceWithLink(LocaleController.getString("ActionYouAddUser", R.string.ActionYouAddUser), "un2", whoUser);
|
||||||
} else if (message.action.user_id == UserConfig.getClientUserId()) {
|
} else if (message.action.user_id == UserConfig.getClientUserId()) {
|
||||||
messageText = replaceWithLink(LocaleController.getString("ActionAddUserYou", R.string.ActionAddUserYou), "un1", fromUser);
|
messageText = replaceWithLink(LocaleController.getString("ActionAddUserYou", R.string.ActionAddUserYou), "un1", fromUser);
|
||||||
|
@ -147,7 +156,7 @@ public class MessageObject {
|
||||||
messageText = LocaleController.getString("ActionAddUser", R.string.ActionAddUser).replace("un2", "").replace("un1", "");
|
messageText = LocaleController.getString("ActionAddUser", R.string.ActionAddUser).replace("un2", "").replace("un1", "");
|
||||||
}
|
}
|
||||||
} else if (message.action instanceof TLRPC.TL_messageActionChatEditPhoto) {
|
} else if (message.action instanceof TLRPC.TL_messageActionChatEditPhoto) {
|
||||||
if (isFromMe()) {
|
if (isOut()) {
|
||||||
messageText = LocaleController.getString("ActionYouChangedPhoto", R.string.ActionYouChangedPhoto);
|
messageText = LocaleController.getString("ActionYouChangedPhoto", R.string.ActionYouChangedPhoto);
|
||||||
} else {
|
} else {
|
||||||
if (fromUser != null) {
|
if (fromUser != null) {
|
||||||
|
@ -157,7 +166,7 @@ public class MessageObject {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (message.action instanceof TLRPC.TL_messageActionChatEditTitle) {
|
} else if (message.action instanceof TLRPC.TL_messageActionChatEditTitle) {
|
||||||
if (isFromMe()) {
|
if (isOut()) {
|
||||||
messageText = LocaleController.getString("ActionYouChangedTitle", R.string.ActionYouChangedTitle).replace("un2", message.action.title);
|
messageText = LocaleController.getString("ActionYouChangedTitle", R.string.ActionYouChangedTitle).replace("un2", message.action.title);
|
||||||
} else {
|
} else {
|
||||||
if (fromUser != null) {
|
if (fromUser != null) {
|
||||||
|
@ -167,7 +176,7 @@ public class MessageObject {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (message.action instanceof TLRPC.TL_messageActionChatDeletePhoto) {
|
} else if (message.action instanceof TLRPC.TL_messageActionChatDeletePhoto) {
|
||||||
if (isFromMe()) {
|
if (isOut()) {
|
||||||
messageText = LocaleController.getString("ActionYouRemovedPhoto", R.string.ActionYouRemovedPhoto);
|
messageText = LocaleController.getString("ActionYouRemovedPhoto", R.string.ActionYouRemovedPhoto);
|
||||||
} else {
|
} else {
|
||||||
if (fromUser != null) {
|
if (fromUser != null) {
|
||||||
|
@ -178,7 +187,7 @@ public class MessageObject {
|
||||||
}
|
}
|
||||||
} else if (message.action instanceof TLRPC.TL_messageActionTTLChange) {
|
} else if (message.action instanceof TLRPC.TL_messageActionTTLChange) {
|
||||||
if (message.action.ttl != 0) {
|
if (message.action.ttl != 0) {
|
||||||
if (isFromMe()) {
|
if (isOut()) {
|
||||||
messageText = LocaleController.formatString("MessageLifetimeChangedOutgoing", R.string.MessageLifetimeChangedOutgoing, AndroidUtilities.formatTTLString(message.action.ttl));
|
messageText = LocaleController.formatString("MessageLifetimeChangedOutgoing", R.string.MessageLifetimeChangedOutgoing, AndroidUtilities.formatTTLString(message.action.ttl));
|
||||||
} else {
|
} else {
|
||||||
if (fromUser != null) {
|
if (fromUser != null) {
|
||||||
|
@ -188,7 +197,7 @@ public class MessageObject {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (isFromMe()) {
|
if (isOut()) {
|
||||||
messageText = LocaleController.getString("MessageLifetimeYouRemoved", R.string.MessageLifetimeYouRemoved);
|
messageText = LocaleController.getString("MessageLifetimeYouRemoved", R.string.MessageLifetimeYouRemoved);
|
||||||
} else {
|
} else {
|
||||||
if (fromUser != null) {
|
if (fromUser != null) {
|
||||||
|
@ -199,7 +208,7 @@ public class MessageObject {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (message.action instanceof TLRPC.TL_messageActionLoginUnknownLocation) {
|
} else if (message.action instanceof TLRPC.TL_messageActionLoginUnknownLocation) {
|
||||||
String date = LocaleController.formatString("formatDateAtTime", R.string.formatDateAtTime, LocaleController.formatterYear.format(((long)message.date) * 1000), LocaleController.formatterDay.format(((long)message.date) * 1000));
|
String date = LocaleController.formatString("formatDateAtTime", R.string.formatDateAtTime, LocaleController.formatterYear.format(((long) message.date) * 1000), LocaleController.formatterDay.format(((long) message.date) * 1000));
|
||||||
TLRPC.User to_user = UserConfig.getCurrentUser();
|
TLRPC.User to_user = UserConfig.getCurrentUser();
|
||||||
if (to_user == null) {
|
if (to_user == null) {
|
||||||
if (users != null) {
|
if (users != null) {
|
||||||
|
@ -228,7 +237,7 @@ public class MessageObject {
|
||||||
}
|
}
|
||||||
} else if (message.action instanceof TLRPC.TL_messageEncryptedAction) {
|
} else if (message.action instanceof TLRPC.TL_messageEncryptedAction) {
|
||||||
if (message.action.encryptedAction instanceof TLRPC.TL_decryptedMessageActionScreenshotMessages) {
|
if (message.action.encryptedAction instanceof TLRPC.TL_decryptedMessageActionScreenshotMessages) {
|
||||||
if (isFromMe()) {
|
if (isOut()) {
|
||||||
messageText = LocaleController.formatString("ActionTakeScreenshootYou", R.string.ActionTakeScreenshootYou);
|
messageText = LocaleController.formatString("ActionTakeScreenshootYou", R.string.ActionTakeScreenshootYou);
|
||||||
} else {
|
} else {
|
||||||
if (fromUser != null) {
|
if (fromUser != null) {
|
||||||
|
@ -240,7 +249,7 @@ public class MessageObject {
|
||||||
} else if (message.action.encryptedAction instanceof TLRPC.TL_decryptedMessageActionSetMessageTTL) {
|
} else if (message.action.encryptedAction instanceof TLRPC.TL_decryptedMessageActionSetMessageTTL) {
|
||||||
TLRPC.TL_decryptedMessageActionSetMessageTTL action = (TLRPC.TL_decryptedMessageActionSetMessageTTL) message.action.encryptedAction;
|
TLRPC.TL_decryptedMessageActionSetMessageTTL action = (TLRPC.TL_decryptedMessageActionSetMessageTTL) message.action.encryptedAction;
|
||||||
if (action.ttl_seconds != 0) {
|
if (action.ttl_seconds != 0) {
|
||||||
if (isFromMe()) {
|
if (isOut()) {
|
||||||
messageText = LocaleController.formatString("MessageLifetimeChangedOutgoing", R.string.MessageLifetimeChangedOutgoing, AndroidUtilities.formatTTLString(action.ttl_seconds));
|
messageText = LocaleController.formatString("MessageLifetimeChangedOutgoing", R.string.MessageLifetimeChangedOutgoing, AndroidUtilities.formatTTLString(action.ttl_seconds));
|
||||||
} else {
|
} else {
|
||||||
if (fromUser != null) {
|
if (fromUser != null) {
|
||||||
|
@ -250,7 +259,7 @@ public class MessageObject {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (isFromMe()) {
|
if (isOut()) {
|
||||||
messageText = LocaleController.getString("MessageLifetimeYouRemoved", R.string.MessageLifetimeYouRemoved);
|
messageText = LocaleController.getString("MessageLifetimeYouRemoved", R.string.MessageLifetimeYouRemoved);
|
||||||
} else {
|
} else {
|
||||||
if (fromUser != null) {
|
if (fromUser != null) {
|
||||||
|
@ -265,7 +274,7 @@ public class MessageObject {
|
||||||
messageText = LocaleController.formatString("YouCreatedBroadcastList", R.string.YouCreatedBroadcastList);
|
messageText = LocaleController.formatString("YouCreatedBroadcastList", R.string.YouCreatedBroadcastList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (message.media != null && !(message.media instanceof TLRPC.TL_messageMediaEmpty)) {
|
} else if (!isMediaEmpty()) {
|
||||||
if (message.media instanceof TLRPC.TL_messageMediaPhoto) {
|
if (message.media instanceof TLRPC.TL_messageMediaPhoto) {
|
||||||
messageText = LocaleController.getString("AttachPhoto", R.string.AttachPhoto);
|
messageText = LocaleController.getString("AttachPhoto", R.string.AttachPhoto);
|
||||||
} else if (message.media instanceof TLRPC.TL_messageMediaVideo) {
|
} else if (message.media instanceof TLRPC.TL_messageMediaVideo) {
|
||||||
|
@ -278,9 +287,19 @@ public class MessageObject {
|
||||||
messageText = LocaleController.getString("UnsuppotedMedia", R.string.UnsuppotedMedia);
|
messageText = LocaleController.getString("UnsuppotedMedia", R.string.UnsuppotedMedia);
|
||||||
} else if (message.media instanceof TLRPC.TL_messageMediaDocument) {
|
} else if (message.media instanceof TLRPC.TL_messageMediaDocument) {
|
||||||
if (isSticker()) {
|
if (isSticker()) {
|
||||||
messageText = LocaleController.getString("AttachSticker", R.string.AttachSticker);
|
String sch = getStrickerChar();
|
||||||
|
if (sch != null && sch.length() > 0) {
|
||||||
|
messageText = String.format("%s %s", sch, LocaleController.getString("AttachSticker", R.string.AttachSticker));
|
||||||
|
} else {
|
||||||
|
messageText = LocaleController.getString("AttachSticker", R.string.AttachSticker);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
messageText = LocaleController.getString("AttachDocument", R.string.AttachDocument);
|
String name = FileLoader.getDocumentFileName(message.media.document);
|
||||||
|
if (name != null && name.length() > 0) {
|
||||||
|
messageText = name;
|
||||||
|
} else {
|
||||||
|
messageText = LocaleController.getString("AttachDocument", R.string.AttachDocument);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (message.media instanceof TLRPC.TL_messageMediaAudio) {
|
} else if (message.media instanceof TLRPC.TL_messageMediaAudio) {
|
||||||
messageText = LocaleController.getString("AttachAudio", R.string.AttachAudio);
|
messageText = LocaleController.getString("AttachAudio", R.string.AttachAudio);
|
||||||
|
@ -290,23 +309,23 @@ public class MessageObject {
|
||||||
}
|
}
|
||||||
messageText = Emoji.replaceEmoji(messageText, textPaint.getFontMetricsInt(), AndroidUtilities.dp(20));
|
messageText = Emoji.replaceEmoji(messageText, textPaint.getFontMetricsInt(), AndroidUtilities.dp(20));
|
||||||
|
|
||||||
if (message instanceof TLRPC.TL_message || message instanceof TLRPC.TL_messageForwarded) {
|
if (message instanceof TLRPC.TL_message || message instanceof TLRPC.TL_messageForwarded_old2) {
|
||||||
if (message.media == null || message.media instanceof TLRPC.TL_messageMediaEmpty) {
|
if (isMediaEmpty()) {
|
||||||
contentType = type = 0;
|
contentType = type = 0;
|
||||||
} else if (message.media != null && message.media instanceof TLRPC.TL_messageMediaPhoto) {
|
} else if (message.media instanceof TLRPC.TL_messageMediaPhoto) {
|
||||||
contentType = type = 1;
|
contentType = type = 1;
|
||||||
} else if (message.media != null && message.media instanceof TLRPC.TL_messageMediaGeo) {
|
} else if (message.media instanceof TLRPC.TL_messageMediaGeo) {
|
||||||
contentType = 1;
|
contentType = 1;
|
||||||
type = 4;
|
type = 4;
|
||||||
} else if (message.media != null && message.media instanceof TLRPC.TL_messageMediaVideo) {
|
} else if (message.media instanceof TLRPC.TL_messageMediaVideo) {
|
||||||
contentType = 1;
|
contentType = 1;
|
||||||
type = 3;
|
type = 3;
|
||||||
} else if (message.media != null && message.media instanceof TLRPC.TL_messageMediaContact) {
|
} else if (message.media instanceof TLRPC.TL_messageMediaContact) {
|
||||||
contentType = 3;
|
contentType = 3;
|
||||||
type = 12;
|
type = 12;
|
||||||
} else if (message.media != null && message.media instanceof TLRPC.TL_messageMediaUnsupported) {
|
} else if (message.media instanceof TLRPC.TL_messageMediaUnsupported) {
|
||||||
contentType = type = 0;
|
contentType = type = 0;
|
||||||
} else if (message.media != null && message.media instanceof TLRPC.TL_messageMediaDocument) {
|
} else if (message.media instanceof TLRPC.TL_messageMediaDocument) {
|
||||||
contentType = 1;
|
contentType = 1;
|
||||||
if (message.media.document.mime_type != null) {
|
if (message.media.document.mime_type != null) {
|
||||||
if (message.media.document.mime_type.equals("image/gif") && message.media.document.thumb != null && !(message.media.document.thumb instanceof TLRPC.TL_photoSizeEmpty)) {
|
if (message.media.document.mime_type.equals("image/gif") && message.media.document.thumb != null && !(message.media.document.thumb instanceof TLRPC.TL_photoSizeEmpty)) {
|
||||||
|
@ -322,7 +341,7 @@ public class MessageObject {
|
||||||
} else {
|
} else {
|
||||||
type = 9;
|
type = 9;
|
||||||
}
|
}
|
||||||
} else if (message.media != null && message.media instanceof TLRPC.TL_messageMediaAudio) {
|
} else if (message.media instanceof TLRPC.TL_messageMediaAudio) {
|
||||||
contentType = type = 2;
|
contentType = type = 2;
|
||||||
}
|
}
|
||||||
} else if (message instanceof TLRPC.TL_messageService) {
|
} else if (message instanceof TLRPC.TL_messageService) {
|
||||||
|
@ -346,11 +365,14 @@ public class MessageObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
Calendar rightNow = new GregorianCalendar();
|
Calendar rightNow = new GregorianCalendar();
|
||||||
rightNow.setTimeInMillis((long)(messageOwner.date) * 1000);
|
rightNow.setTimeInMillis((long) (messageOwner.date) * 1000);
|
||||||
int dateDay = rightNow.get(Calendar.DAY_OF_YEAR);
|
int dateDay = rightNow.get(Calendar.DAY_OF_YEAR);
|
||||||
int dateYear = rightNow.get(Calendar.YEAR);
|
int dateYear = rightNow.get(Calendar.YEAR);
|
||||||
int dateMonth = rightNow.get(Calendar.MONTH);
|
int dateMonth = rightNow.get(Calendar.MONTH);
|
||||||
dateKey = String.format("%d_%02d_%02d", dateYear, dateMonth, dateDay);
|
dateKey = String.format("%d_%02d_%02d", dateYear, dateMonth, dateDay);
|
||||||
|
if (contentType == 1 || contentType == 2) {
|
||||||
|
monthKey = String.format("%d_%02d", dateYear, dateMonth);
|
||||||
|
}
|
||||||
|
|
||||||
if (generateLayout) {
|
if (generateLayout) {
|
||||||
generateLayout();
|
generateLayout();
|
||||||
|
@ -412,6 +434,24 @@ public class MessageObject {
|
||||||
photoObject.location = messageOwner.media.document.thumb.location;
|
photoObject.location = messageOwner.media.document.thumb.location;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (messageOwner.media instanceof TLRPC.TL_messageMediaWebPage) {
|
||||||
|
if (messageOwner.media.webpage.photo != null) {
|
||||||
|
if (!update || photoThumbs == null) {
|
||||||
|
photoThumbs = new ArrayList<>(messageOwner.media.webpage.photo.sizes);
|
||||||
|
} else if (photoThumbs != null && !photoThumbs.isEmpty()) {
|
||||||
|
for (TLRPC.PhotoSize photoObject : photoThumbs) {
|
||||||
|
for (TLRPC.PhotoSize size : messageOwner.media.webpage.photo.sizes) {
|
||||||
|
if (size instanceof TLRPC.TL_photoSizeEmpty) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (size.type.equals(photoObject.type)) {
|
||||||
|
photoObject.location = size.location;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -483,6 +523,9 @@ public class MessageObject {
|
||||||
} else if (!(c != ' ' && digitsInRow > 0)) {
|
} else if (!(c != ' ' && digitsInRow > 0)) {
|
||||||
digitsInRow = 0;
|
digitsInRow = 0;
|
||||||
}
|
}
|
||||||
|
if ((c == '@' || c == '#') && i == 0 || i != 0 && (message.charAt(i - 1) == ' ' || message.charAt(i - 1) == '\n')) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (c == ':') {
|
if (c == ':') {
|
||||||
if (schemeSequence == 0) {
|
if (schemeSequence == 0) {
|
||||||
schemeSequence = 1;
|
schemeSequence = 1;
|
||||||
|
@ -514,11 +557,24 @@ public class MessageObject {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void generateLinkDescription() {
|
||||||
|
if (linkDescription != null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (messageOwner.media instanceof TLRPC.TL_messageMediaWebPage && messageOwner.media.webpage instanceof TLRPC.TL_webPage && messageOwner.media.webpage.description != null) {
|
||||||
|
linkDescription = Spannable.Factory.getInstance().newSpannable(messageOwner.media.webpage.description);
|
||||||
|
if (containsUrls(linkDescription)) {
|
||||||
|
Linkify.addLinks((Spannable) linkDescription, Linkify.WEB_URLS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void generateLayout() {
|
private void generateLayout() {
|
||||||
if (type != 0 || messageOwner.to_id == null || messageText == null || messageText.length() == 0) {
|
if (type != 0 || messageOwner.to_id == null || messageText == null || messageText.length() == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
generateLinkDescription();
|
||||||
textLayoutBlocks = new ArrayList<>();
|
textLayoutBlocks = new ArrayList<>();
|
||||||
|
|
||||||
if (messageText instanceof Spannable && containsUrls(messageText)) {
|
if (messageText instanceof Spannable && containsUrls(messageText)) {
|
||||||
|
@ -527,17 +583,33 @@ public class MessageObject {
|
||||||
} else {
|
} else {
|
||||||
Linkify.addLinks((Spannable) messageText, Linkify.WEB_URLS);
|
Linkify.addLinks((Spannable) messageText, Linkify.WEB_URLS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Pattern pattern = Pattern.compile("(^|\\s)@[a-zA-Z\\d_]{5,32}|(^|\\s)#[\\w\\.]+");
|
||||||
|
Matcher matcher = pattern.matcher(messageText);
|
||||||
|
while (matcher.find()) {
|
||||||
|
int start = matcher.start();
|
||||||
|
int end = matcher.end();
|
||||||
|
if (messageText.charAt(start) != '@' && messageText.charAt(start) != '#') {
|
||||||
|
start++;
|
||||||
|
}
|
||||||
|
URLSpanNoUnderline url = new URLSpanNoUnderline(messageText.subSequence(start, end).toString());
|
||||||
|
((Spannable) messageText).setSpan(url, start, end, 0);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
FileLog.e("tmessages", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int maxWidth;
|
int maxWidth;
|
||||||
if (AndroidUtilities.isTablet()) {
|
if (AndroidUtilities.isTablet()) {
|
||||||
if (messageOwner.to_id.chat_id != 0) {
|
if (messageOwner.to_id.chat_id != 0 && !isOut()) {
|
||||||
maxWidth = AndroidUtilities.getMinTabletSide() - AndroidUtilities.dp(122);
|
maxWidth = AndroidUtilities.getMinTabletSide() - AndroidUtilities.dp(122);
|
||||||
} else {
|
} else {
|
||||||
maxWidth = AndroidUtilities.getMinTabletSide() - AndroidUtilities.dp(80);
|
maxWidth = AndroidUtilities.getMinTabletSide() - AndroidUtilities.dp(80);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (messageOwner.to_id.chat_id != 0) {
|
if (messageOwner.to_id.chat_id != 0 && !isOut()) {
|
||||||
maxWidth = Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) - AndroidUtilities.dp(122);
|
maxWidth = Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) - AndroidUtilities.dp(122);
|
||||||
} else {
|
} else {
|
||||||
maxWidth = Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) - AndroidUtilities.dp(80);
|
maxWidth = Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) - AndroidUtilities.dp(80);
|
||||||
|
@ -556,7 +628,7 @@ public class MessageObject {
|
||||||
textHeight = textLayout.getHeight();
|
textHeight = textLayout.getHeight();
|
||||||
int linesCount = textLayout.getLineCount();
|
int linesCount = textLayout.getLineCount();
|
||||||
|
|
||||||
int blocksCount = (int)Math.ceil((float)linesCount / LINES_PER_BLOCK);
|
int blocksCount = (int) Math.ceil((float) linesCount / LINES_PER_BLOCK);
|
||||||
int linesOffset = 0;
|
int linesOffset = 0;
|
||||||
float prevOffset = 0;
|
float prevOffset = 0;
|
||||||
|
|
||||||
|
@ -581,7 +653,7 @@ public class MessageObject {
|
||||||
block.textLayout = new StaticLayout(str, textPaint, maxWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
|
block.textLayout = new StaticLayout(str, textPaint, maxWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
|
||||||
block.textYOffset = textLayout.getLineTop(linesOffset);
|
block.textYOffset = textLayout.getLineTop(linesOffset);
|
||||||
if (a != 0) {
|
if (a != 0) {
|
||||||
blockHeight = Math.min(blockHeight, (int)(block.textYOffset - prevOffset));
|
blockHeight = Math.min(blockHeight, (int) (block.textYOffset - prevOffset));
|
||||||
}
|
}
|
||||||
prevOffset = block.textYOffset;
|
prevOffset = block.textYOffset;
|
||||||
/*if (a != blocksCount - 1) {
|
/*if (a != blocksCount - 1) {
|
||||||
|
@ -613,7 +685,7 @@ public class MessageObject {
|
||||||
FileLog.e("tmessages", e);
|
FileLog.e("tmessages", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
int linesMaxWidth = (int)Math.ceil(lastLine);
|
int linesMaxWidth = (int) Math.ceil(lastLine);
|
||||||
int lastLineWidthWithLeft;
|
int lastLineWidthWithLeft;
|
||||||
int linesMaxWidthWithLeft;
|
int linesMaxWidthWithLeft;
|
||||||
boolean hasNonRTL = false;
|
boolean hasNonRTL = false;
|
||||||
|
@ -622,7 +694,7 @@ public class MessageObject {
|
||||||
lastLineWidth = linesMaxWidth;
|
lastLineWidth = linesMaxWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
linesMaxWidthWithLeft = lastLineWidthWithLeft = (int)Math.ceil(lastLine + lastLeft);
|
linesMaxWidthWithLeft = lastLineWidthWithLeft = (int) Math.ceil(lastLine + lastLeft);
|
||||||
if (lastLeft == 0) {
|
if (lastLeft == 0) {
|
||||||
hasNonRTL = true;
|
hasNonRTL = true;
|
||||||
}
|
}
|
||||||
|
@ -655,8 +727,8 @@ public class MessageObject {
|
||||||
}
|
}
|
||||||
textRealMaxWidth = Math.max(textRealMaxWidth, lineWidth);
|
textRealMaxWidth = Math.max(textRealMaxWidth, lineWidth);
|
||||||
textRealMaxWidthWithLeft = Math.max(textRealMaxWidthWithLeft, lineWidth + lineLeft);
|
textRealMaxWidthWithLeft = Math.max(textRealMaxWidthWithLeft, lineWidth + lineLeft);
|
||||||
linesMaxWidth = Math.max(linesMaxWidth, (int)Math.ceil(lineWidth));
|
linesMaxWidth = Math.max(linesMaxWidth, (int) Math.ceil(lineWidth));
|
||||||
linesMaxWidthWithLeft = Math.max(linesMaxWidthWithLeft, (int)Math.ceil(lineWidth + lineLeft));
|
linesMaxWidthWithLeft = Math.max(linesMaxWidthWithLeft, (int) Math.ceil(lineWidth + lineLeft));
|
||||||
}
|
}
|
||||||
if (hasNonRTL) {
|
if (hasNonRTL) {
|
||||||
textRealMaxWidth = textRealMaxWidthWithLeft;
|
textRealMaxWidth = textRealMaxWidthWithLeft;
|
||||||
|
@ -667,7 +739,7 @@ public class MessageObject {
|
||||||
} else if (a == blocksCount - 1) {
|
} else if (a == blocksCount - 1) {
|
||||||
lastLineWidth = linesMaxWidth;
|
lastLineWidth = linesMaxWidth;
|
||||||
}
|
}
|
||||||
textWidth = Math.max(textWidth, (int)Math.ceil(textRealMaxWidth));
|
textWidth = Math.max(textWidth, (int) Math.ceil(textRealMaxWidth));
|
||||||
} else {
|
} else {
|
||||||
textWidth = Math.max(textWidth, Math.min(maxWidth, linesMaxWidth));
|
textWidth = Math.max(textWidth, Math.min(maxWidth, linesMaxWidth));
|
||||||
}
|
}
|
||||||
|
@ -687,16 +759,16 @@ public class MessageObject {
|
||||||
return (messageOwner.flags & TLRPC.MESSAGE_FLAG_OUT) != 0;
|
return (messageOwner.flags & TLRPC.MESSAGE_FLAG_OUT) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isFromMe() {
|
|
||||||
return messageOwner.from_id == UserConfig.getClientUserId();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isUnread() {
|
public boolean isUnread() {
|
||||||
return (messageOwner.flags & TLRPC.MESSAGE_FLAG_UNREAD) != 0;
|
return (messageOwner.flags & TLRPC.MESSAGE_FLAG_UNREAD) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIsRead() {
|
public void setIsRead() {
|
||||||
messageOwner.flags &=~ TLRPC.MESSAGE_FLAG_UNREAD;
|
messageOwner.flags &= ~TLRPC.MESSAGE_FLAG_UNREAD;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return messageOwner.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSecretPhoto() {
|
public boolean isSecretPhoto() {
|
||||||
|
@ -706,15 +778,15 @@ public class MessageObject {
|
||||||
public boolean isSecretMedia() {
|
public boolean isSecretMedia() {
|
||||||
return messageOwner instanceof TLRPC.TL_message_secret &&
|
return messageOwner instanceof TLRPC.TL_message_secret &&
|
||||||
(messageOwner.media instanceof TLRPC.TL_messageMediaPhoto && messageOwner.ttl != 0 && messageOwner.ttl <= 60 ||
|
(messageOwner.media instanceof TLRPC.TL_messageMediaPhoto && messageOwner.ttl != 0 && messageOwner.ttl <= 60 ||
|
||||||
messageOwner.media instanceof TLRPC.TL_messageMediaAudio ||
|
messageOwner.media instanceof TLRPC.TL_messageMediaAudio ||
|
||||||
messageOwner.media instanceof TLRPC.TL_messageMediaVideo);
|
messageOwner.media instanceof TLRPC.TL_messageMediaVideo);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setIsUnread(TLRPC.Message message, boolean unread) {
|
public static void setIsUnread(TLRPC.Message message, boolean unread) {
|
||||||
if (unread) {
|
if (unread) {
|
||||||
message.flags |= TLRPC.MESSAGE_FLAG_UNREAD;
|
message.flags |= TLRPC.MESSAGE_FLAG_UNREAD;
|
||||||
} else {
|
} else {
|
||||||
message.flags &=~ TLRPC.MESSAGE_FLAG_UNREAD;
|
message.flags &= ~TLRPC.MESSAGE_FLAG_UNREAD;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -732,7 +804,7 @@ public class MessageObject {
|
||||||
} else {
|
} else {
|
||||||
if (messageOwner.to_id.chat_id != 0) {
|
if (messageOwner.to_id.chat_id != 0) {
|
||||||
return -messageOwner.to_id.chat_id;
|
return -messageOwner.to_id.chat_id;
|
||||||
} else if (isFromMe()) {
|
} else if (isOut()) {
|
||||||
return messageOwner.to_id.user_id;
|
return messageOwner.to_id.user_id;
|
||||||
} else {
|
} else {
|
||||||
return messageOwner.from_id;
|
return messageOwner.from_id;
|
||||||
|
@ -741,7 +813,7 @@ public class MessageObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSending() {
|
public boolean isSending() {
|
||||||
return messageOwner.send_state == MESSAGE_SEND_STATE_SENDING;
|
return messageOwner.send_state == MESSAGE_SEND_STATE_SENDING && messageOwner.id < 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSendError() {
|
public boolean isSendError() {
|
||||||
|
@ -749,7 +821,7 @@ public class MessageObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSent() {
|
public boolean isSent() {
|
||||||
return messageOwner.send_state == MESSAGE_SEND_STATE_SENT;
|
return messageOwner.send_state == MESSAGE_SEND_STATE_SENT || messageOwner.id > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSecretTimeString() {
|
public String getSecretTimeString() {
|
||||||
|
@ -787,7 +859,129 @@ public class MessageObject {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getStrickerChar() {
|
||||||
|
if (messageOwner.media != null && messageOwner.media.document != null) {
|
||||||
|
for (TLRPC.DocumentAttribute attribute : messageOwner.media.document.attributes) {
|
||||||
|
if (attribute instanceof TLRPC.TL_documentAttributeSticker) {
|
||||||
|
return attribute.alt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getApproximateHeight() {
|
||||||
|
if (type == 0) {
|
||||||
|
return textHeight;
|
||||||
|
} else if (contentType == 2) {
|
||||||
|
return AndroidUtilities.dp(68);
|
||||||
|
} else if (contentType == 3) {
|
||||||
|
return AndroidUtilities.dp(71);
|
||||||
|
} else if (type == 9) {
|
||||||
|
return AndroidUtilities.dp(100);
|
||||||
|
} else if (type == 4) {
|
||||||
|
return AndroidUtilities.dp(114);
|
||||||
|
} else if (type == 13) {
|
||||||
|
float maxHeight = AndroidUtilities.displaySize.y * 0.4f;
|
||||||
|
float maxWidth;
|
||||||
|
if (AndroidUtilities.isTablet()) {
|
||||||
|
maxWidth = AndroidUtilities.getMinTabletSide() * 0.5f;
|
||||||
|
} else {
|
||||||
|
maxWidth = AndroidUtilities.displaySize.x * 0.5f;
|
||||||
|
}
|
||||||
|
int photoHeight = 0;
|
||||||
|
int photoWidth = 0;
|
||||||
|
for (TLRPC.DocumentAttribute attribute : messageOwner.media.document.attributes) {
|
||||||
|
if (attribute instanceof TLRPC.TL_documentAttributeImageSize) {
|
||||||
|
photoWidth = attribute.w;
|
||||||
|
photoHeight = attribute.h;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (photoWidth == 0) {
|
||||||
|
photoHeight = (int) maxHeight;
|
||||||
|
photoWidth = photoHeight + AndroidUtilities.dp(100);
|
||||||
|
}
|
||||||
|
if (photoHeight > maxHeight) {
|
||||||
|
photoWidth *= maxHeight / photoHeight;
|
||||||
|
photoHeight = (int)maxHeight;
|
||||||
|
}
|
||||||
|
if (photoWidth > maxWidth) {
|
||||||
|
photoHeight *= maxWidth / photoWidth;
|
||||||
|
}
|
||||||
|
return photoHeight + AndroidUtilities.dp(14);
|
||||||
|
} else {
|
||||||
|
int photoHeight = 0;
|
||||||
|
int photoWidth = 0;
|
||||||
|
|
||||||
|
if (AndroidUtilities.isTablet()) {
|
||||||
|
photoWidth = (int) (AndroidUtilities.getMinTabletSide() * 0.7f);
|
||||||
|
} else {
|
||||||
|
photoWidth = (int) (Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) * 0.7f);
|
||||||
|
}
|
||||||
|
photoHeight = photoWidth + AndroidUtilities.dp(100);
|
||||||
|
if (photoWidth > AndroidUtilities.getPhotoSize()) {
|
||||||
|
photoWidth = AndroidUtilities.getPhotoSize();
|
||||||
|
}
|
||||||
|
if (photoHeight > AndroidUtilities.getPhotoSize()) {
|
||||||
|
photoHeight = AndroidUtilities.getPhotoSize();
|
||||||
|
}
|
||||||
|
TLRPC.PhotoSize currentPhotoObject = FileLoader.getClosestPhotoSizeWithSize(photoThumbs, AndroidUtilities.getPhotoSize());
|
||||||
|
|
||||||
|
if (currentPhotoObject != null) {
|
||||||
|
float scale = (float) currentPhotoObject.w / (float) photoWidth;
|
||||||
|
int w = (int) (currentPhotoObject.w / scale);
|
||||||
|
int h = (int) (currentPhotoObject.h / scale);
|
||||||
|
if (w == 0) {
|
||||||
|
w = AndroidUtilities.dp(100);
|
||||||
|
}
|
||||||
|
if (h == 0) {
|
||||||
|
h = AndroidUtilities.dp(100);
|
||||||
|
}
|
||||||
|
if (h > photoHeight) {
|
||||||
|
float scale2 = h;
|
||||||
|
h = photoHeight;
|
||||||
|
scale2 /= h;
|
||||||
|
w = (int) (w / scale2);
|
||||||
|
} else if (h < AndroidUtilities.dp(120)) {
|
||||||
|
h = AndroidUtilities.dp(120);
|
||||||
|
float hScale = (float) currentPhotoObject.h / h;
|
||||||
|
if (currentPhotoObject.w / hScale < photoWidth) {
|
||||||
|
w = (int) (currentPhotoObject.w / hScale);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isSecretPhoto()) {
|
||||||
|
if (AndroidUtilities.isTablet()) {
|
||||||
|
w = h = (int) (AndroidUtilities.getMinTabletSide() * 0.5f);
|
||||||
|
} else {
|
||||||
|
w = h = (int) (Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) * 0.5f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
photoWidth = w;
|
||||||
|
photoHeight = h;
|
||||||
|
}
|
||||||
|
return photoHeight + AndroidUtilities.dp(14);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isSticker() {
|
public boolean isSticker() {
|
||||||
return isStickerMessage(messageOwner);
|
return isStickerMessage(messageOwner);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isForwarded() {
|
||||||
|
return (messageOwner.flags & TLRPC.MESSAGE_FLAG_FWD) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isReply() {
|
||||||
|
return !(replyMessageObject != null && replyMessageObject.messageOwner instanceof TLRPC.TL_messageEmpty) && messageOwner.reply_to_msg_id != 0 && (messageOwner.flags & TLRPC.MESSAGE_FLAG_REPLY) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isMediaEmpty() {
|
||||||
|
return isMediaEmpty(messageOwner);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isMediaEmpty(TLRPC.Message message) {
|
||||||
|
return message == null || message.media == null || message.media instanceof TLRPC.TL_messageMediaEmpty || message.media instanceof TLRPC.TL_messageMediaWebPage;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -103,7 +103,7 @@ public class MessagesStorage {
|
||||||
database.executeFast("PRAGMA temp_store = 1").stepThis().dispose();
|
database.executeFast("PRAGMA temp_store = 1").stepThis().dispose();
|
||||||
if (createTable) {
|
if (createTable) {
|
||||||
database.executeFast("CREATE TABLE users(uid INTEGER PRIMARY KEY, name TEXT, status INTEGER, data BLOB)").stepThis().dispose();
|
database.executeFast("CREATE TABLE users(uid INTEGER PRIMARY KEY, name TEXT, status INTEGER, data BLOB)").stepThis().dispose();
|
||||||
database.executeFast("CREATE TABLE messages(mid INTEGER PRIMARY KEY, uid INTEGER, read_state INTEGER, send_state INTEGER, date INTEGER, data BLOB, out INTEGER, ttl INTEGER, media INTEGER)").stepThis().dispose();
|
database.executeFast("CREATE TABLE messages(mid INTEGER PRIMARY KEY, uid INTEGER, read_state INTEGER, send_state INTEGER, date INTEGER, data BLOB, out INTEGER, ttl INTEGER, media INTEGER, replydata BLOB)").stepThis().dispose();
|
||||||
database.executeFast("CREATE TABLE chats(uid INTEGER PRIMARY KEY, name TEXT, data BLOB)").stepThis().dispose();
|
database.executeFast("CREATE TABLE chats(uid INTEGER PRIMARY KEY, name TEXT, data BLOB)").stepThis().dispose();
|
||||||
database.executeFast("CREATE TABLE enc_chats(uid INTEGER PRIMARY KEY, user INTEGER, name TEXT, data BLOB, g BLOB, authkey BLOB, ttl INTEGER, layer INTEGER, seq_in INTEGER, seq_out INTEGER, use_count INTEGER, exchange_id INTEGER, key_date INTEGER, fprint INTEGER, fauthkey BLOB, khash BLOB)").stepThis().dispose();
|
database.executeFast("CREATE TABLE enc_chats(uid INTEGER PRIMARY KEY, user INTEGER, name TEXT, data BLOB, g BLOB, authkey BLOB, ttl INTEGER, layer INTEGER, seq_in INTEGER, seq_out INTEGER, use_count INTEGER, exchange_id INTEGER, key_date INTEGER, fprint INTEGER, fauthkey BLOB, khash BLOB)").stepThis().dispose();
|
||||||
database.executeFast("CREATE TABLE dialogs(did INTEGER PRIMARY KEY, date INTEGER, unread_count INTEGER, last_mid INTEGER)").stepThis().dispose();
|
database.executeFast("CREATE TABLE dialogs(did INTEGER PRIMARY KEY, date INTEGER, unread_count INTEGER, last_mid INTEGER)").stepThis().dispose();
|
||||||
|
@ -122,6 +122,8 @@ public class MessagesStorage {
|
||||||
database.executeFast("CREATE TABLE messages_seq(mid INTEGER PRIMARY KEY, seq_in INTEGER, seq_out INTEGER);").stepThis().dispose();
|
database.executeFast("CREATE TABLE messages_seq(mid INTEGER PRIMARY KEY, seq_in INTEGER, seq_out INTEGER);").stepThis().dispose();
|
||||||
database.executeFast("CREATE TABLE web_recent_v3(id TEXT, type INTEGER, image_url TEXT, thumb_url TEXT, local_url TEXT, width INTEGER, height INTEGER, size INTEGER, date INTEGER, PRIMARY KEY (id, type));").stepThis().dispose();
|
database.executeFast("CREATE TABLE web_recent_v3(id TEXT, type INTEGER, image_url TEXT, thumb_url TEXT, local_url TEXT, width INTEGER, height INTEGER, size INTEGER, date INTEGER, PRIMARY KEY (id, type));").stepThis().dispose();
|
||||||
database.executeFast("CREATE TABLE stickers(id INTEGER PRIMARY KEY, data BLOB, date INTEGER);").stepThis().dispose();
|
database.executeFast("CREATE TABLE stickers(id INTEGER PRIMARY KEY, data BLOB, date INTEGER);").stepThis().dispose();
|
||||||
|
database.executeFast("CREATE TABLE hashtag_recent_v2(id TEXT PRIMARY KEY, date INTEGER);").stepThis().dispose();
|
||||||
|
database.executeFast("CREATE TABLE webpage_pending(id INTEGER, mid INTEGER, PRIMARY KEY (id, mid));").stepThis().dispose();
|
||||||
|
|
||||||
database.executeFast("CREATE TABLE user_contacts_v6(uid INTEGER PRIMARY KEY, fname TEXT, sname TEXT)").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 TABLE user_phones_v6(uid INTEGER, phone TEXT, sphone TEXT, deleted INTEGER, PRIMARY KEY (uid, phone))").stepThis().dispose();
|
||||||
|
@ -162,7 +164,7 @@ public class MessagesStorage {
|
||||||
database.executeFast("CREATE TABLE keyvalue(id TEXT PRIMARY KEY, value TEXT)").stepThis().dispose();
|
database.executeFast("CREATE TABLE keyvalue(id TEXT PRIMARY KEY, value TEXT)").stepThis().dispose();
|
||||||
|
|
||||||
//version
|
//version
|
||||||
database.executeFast("PRAGMA user_version = 13").stepThis().dispose();
|
database.executeFast("PRAGMA user_version = 16").stepThis().dispose();
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
SQLiteCursor cursor = database.queryFinalized("SELECT seq, pts, date, qts, lsv, sg, pbytes FROM params WHERE id = 1");
|
SQLiteCursor cursor = database.queryFinalized("SELECT seq, pts, date, qts, lsv, sg, pbytes FROM params WHERE id = 1");
|
||||||
|
@ -193,7 +195,7 @@ public class MessagesStorage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int version = database.executeInt("PRAGMA user_version");
|
int version = database.executeInt("PRAGMA user_version");
|
||||||
if (version < 13) {
|
if (version < 16) {
|
||||||
updateDbToLastVersion(version);
|
updateDbToLastVersion(version);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -368,6 +370,21 @@ public class MessagesStorage {
|
||||||
database.executeFast("PRAGMA user_version = 13").stepThis().dispose();
|
database.executeFast("PRAGMA user_version = 13").stepThis().dispose();
|
||||||
version = 13;
|
version = 13;
|
||||||
}
|
}
|
||||||
|
if (version == 13 && version < 14) {
|
||||||
|
database.executeFast("ALTER TABLE messages ADD COLUMN replydata BLOB default NULL").stepThis().dispose();
|
||||||
|
database.executeFast("PRAGMA user_version = 14").stepThis().dispose();
|
||||||
|
version = 14;
|
||||||
|
}
|
||||||
|
if (version == 14 && version < 15) {
|
||||||
|
database.executeFast("CREATE TABLE IF NOT EXISTS hashtag_recent_v2(id TEXT PRIMARY KEY, date INTEGER);").stepThis().dispose();
|
||||||
|
database.executeFast("PRAGMA user_version = 15").stepThis().dispose();
|
||||||
|
version = 15;
|
||||||
|
}
|
||||||
|
if (version == 15 && version < 16) {
|
||||||
|
database.executeFast("CREATE TABLE IF NOT EXISTS webpage_pending(id INTEGER, mid INTEGER, PRIMARY KEY (id, mid));").stepThis().dispose();
|
||||||
|
database.executeFast("PRAGMA user_version = 16").stepThis().dispose();
|
||||||
|
version = 16;
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
FileLog.e("tmessages", e);
|
FileLog.e("tmessages", e);
|
||||||
}
|
}
|
||||||
|
@ -622,7 +639,7 @@ public class MessagesStorage {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
SQLiteCursor cursor = database.queryFinalized("SELECT id, image_url, thumb_url, local_url, width, height, size, date FROM web_recent_v3 wallpapers WHERE type = " + type);
|
SQLiteCursor cursor = database.queryFinalized("SELECT id, image_url, thumb_url, local_url, width, height, size, date FROM web_recent_v3 WHERE type = " + type);
|
||||||
final ArrayList<MediaController.SearchImage> arrayList = new ArrayList<>();
|
final ArrayList<MediaController.SearchImage> arrayList = new ArrayList<>();
|
||||||
while (cursor.next()) {
|
while (cursor.next()) {
|
||||||
MediaController.SearchImage searchImage = new MediaController.SearchImage();
|
MediaController.SearchImage searchImage = new MediaController.SearchImage();
|
||||||
|
@ -679,6 +696,19 @@ public class MessagesStorage {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void clearWebRecent(final int type) {
|
||||||
|
storageQueue.postRunnable(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
database.executeFast("DELETE FROM web_recent_v3 WHERE type = " + type).stepThis().dispose();
|
||||||
|
} catch (Exception e) {
|
||||||
|
FileLog.e("tmessages", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public void putWebRecent(final ArrayList<MediaController.SearchImage> arrayList) {
|
public void putWebRecent(final ArrayList<MediaController.SearchImage> arrayList) {
|
||||||
storageQueue.postRunnable(new Runnable() {
|
storageQueue.postRunnable(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -753,7 +783,7 @@ public class MessagesStorage {
|
||||||
try {
|
try {
|
||||||
ArrayList<Integer> ids = new ArrayList<>();
|
ArrayList<Integer> ids = new ArrayList<>();
|
||||||
ArrayList<TLRPC.User> users = new ArrayList<>();
|
ArrayList<TLRPC.User> users = new ArrayList<>();
|
||||||
SQLiteCursor cursor = database.queryFinalized(String.format(Locale.US, "SELECT * FROM blocked_users WHERE 1"));
|
SQLiteCursor cursor = database.queryFinalized("SELECT * FROM blocked_users WHERE 1");
|
||||||
StringBuilder usersToLoad = new StringBuilder();
|
StringBuilder usersToLoad = new StringBuilder();
|
||||||
while (cursor.next()) {
|
while (cursor.next()) {
|
||||||
int user_id = cursor.intValue(0);
|
int user_id = cursor.intValue(0);
|
||||||
|
@ -838,6 +868,59 @@ public class MessagesStorage {
|
||||||
//database.executeFast("DELETE FROM secret_holes WHERE uid = " + high_id).stepThis().dispose();
|
//database.executeFast("DELETE FROM secret_holes WHERE uid = " + high_id).stepThis().dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((int) did == 0) {
|
||||||
|
SQLiteCursor cursor = database.queryFinalized("SELECT data FROM messages WHERE uid = " + did);
|
||||||
|
ArrayList<File> filesToDelete = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
while (cursor.next()) {
|
||||||
|
ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
|
||||||
|
if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
|
||||||
|
TLRPC.Message message = (TLRPC.Message) TLClassStore.Instance().TLdeserialize(data, data.readInt32());
|
||||||
|
if (message == null || message.media == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (message.media instanceof TLRPC.TL_messageMediaAudio) {
|
||||||
|
File file = FileLoader.getPathToAttach(message.media.audio);
|
||||||
|
if (file != null && file.toString().length() > 0) {
|
||||||
|
filesToDelete.add(file);
|
||||||
|
}
|
||||||
|
} else if (message.media instanceof TLRPC.TL_messageMediaPhoto) {
|
||||||
|
for (TLRPC.PhotoSize photoSize : message.media.photo.sizes) {
|
||||||
|
File file = FileLoader.getPathToAttach(photoSize);
|
||||||
|
if (file != null && file.toString().length() > 0) {
|
||||||
|
filesToDelete.add(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (message.media instanceof TLRPC.TL_messageMediaVideo) {
|
||||||
|
File file = FileLoader.getPathToAttach(message.media.video);
|
||||||
|
if (file != null && file.toString().length() > 0) {
|
||||||
|
filesToDelete.add(file);
|
||||||
|
}
|
||||||
|
file = FileLoader.getPathToAttach(message.media.video.thumb);
|
||||||
|
if (file != null && file.toString().length() > 0) {
|
||||||
|
filesToDelete.add(file);
|
||||||
|
}
|
||||||
|
} else if (message.media instanceof TLRPC.TL_messageMediaDocument) {
|
||||||
|
File file = FileLoader.getPathToAttach(message.media.document);
|
||||||
|
if (file != null && file.toString().length() > 0) {
|
||||||
|
filesToDelete.add(file);
|
||||||
|
}
|
||||||
|
file = FileLoader.getPathToAttach(message.media.document.thumb);
|
||||||
|
if (file != null && file.toString().length() > 0) {
|
||||||
|
filesToDelete.add(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
buffersStorage.reuseFreeBuffer(data);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
FileLog.e("tmessages", e);
|
||||||
|
}
|
||||||
|
cursor.dispose();
|
||||||
|
FileLoader.getInstance().deleteFiles(filesToDelete);
|
||||||
|
}
|
||||||
|
|
||||||
database.executeFast("UPDATE dialogs SET unread_count = 0 WHERE did = " + did).stepThis().dispose();
|
database.executeFast("UPDATE dialogs SET unread_count = 0 WHERE did = " + did).stepThis().dispose();
|
||||||
database.executeFast("DELETE FROM messages WHERE uid = " + did).stepThis().dispose();
|
database.executeFast("DELETE FROM messages WHERE uid = " + did).stepThis().dispose();
|
||||||
database.executeFast("DELETE FROM media_counts_v2 WHERE uid = " + did).stepThis().dispose();
|
database.executeFast("DELETE FROM media_counts_v2 WHERE uid = " + did).stepThis().dispose();
|
||||||
|
@ -1032,20 +1115,16 @@ public class MessagesStorage {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateDialogsWithReadedMessagesInternal(final ArrayList<Integer> messages) {
|
private void updateDialogsWithReadedMessagesInternal(final ArrayList<Integer> messages, final HashMap<Integer, Integer> inbox) {
|
||||||
if (Thread.currentThread().getId() != storageQueue.getId()) {
|
|
||||||
throw new RuntimeException("wrong db thread");
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
HashMap<Long, Integer> dialogsToUpdate = new HashMap<>();
|
HashMap<Long, Integer> dialogsToUpdate = new HashMap<>();
|
||||||
|
StringBuilder dialogsToReload = new StringBuilder();
|
||||||
|
|
||||||
if (messages != null && !messages.isEmpty()) {
|
if (messages != null && !messages.isEmpty()) {
|
||||||
StringBuilder dialogsToReload = new StringBuilder();
|
|
||||||
String ids = TextUtils.join(",", messages);
|
String ids = TextUtils.join(",", messages);
|
||||||
int totalCount = 0;
|
|
||||||
SQLiteCursor cursor = database.queryFinalized(String.format(Locale.US, "SELECT uid, read_state, out FROM messages WHERE mid IN(%s)", ids));
|
SQLiteCursor cursor = database.queryFinalized(String.format(Locale.US, "SELECT uid, read_state, out FROM messages WHERE mid IN(%s)", ids));
|
||||||
while (cursor.next()) {
|
while (cursor.next()) {
|
||||||
int out = cursor.intValue(2);
|
int out = cursor.intValue(2);
|
||||||
totalCount++;
|
|
||||||
if (out != 0) {
|
if (out != 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -1066,8 +1145,26 @@ public class MessagesStorage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cursor.dispose();
|
cursor.dispose();
|
||||||
|
} else if (inbox != null && !inbox.isEmpty()) {
|
||||||
|
for (HashMap.Entry<Integer, Integer> entry : inbox.entrySet()) {
|
||||||
|
SQLiteCursor cursor = database.queryFinalized(String.format(Locale.US, "SELECT COUNT(mid) FROM messages WHERE uid = %d AND mid <= %d AND read_state = 0 AND out = 0", entry.getKey(), entry.getValue()));
|
||||||
|
if (cursor.next()) {
|
||||||
|
int count = cursor.intValue(0);
|
||||||
|
if (count == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
dialogsToUpdate.put((long) entry.getKey(), count);
|
||||||
|
if (dialogsToReload.length() != 0) {
|
||||||
|
dialogsToReload.append(",");
|
||||||
|
}
|
||||||
|
dialogsToReload.append(entry.getKey());
|
||||||
|
}
|
||||||
|
cursor.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
cursor = database.queryFinalized(String.format(Locale.US, "SELECT did, unread_count FROM dialogs WHERE did IN(%s)", dialogsToReload.toString()));
|
if (dialogsToReload.length() > 0) {
|
||||||
|
SQLiteCursor cursor = database.queryFinalized(String.format(Locale.US, "SELECT did, unread_count FROM dialogs WHERE did IN(%s)", dialogsToReload.toString()));
|
||||||
while (cursor.next()) {
|
while (cursor.next()) {
|
||||||
long did = cursor.longValue(0);
|
long did = cursor.longValue(0);
|
||||||
int count = cursor.intValue(1);
|
int count = cursor.intValue(1);
|
||||||
|
@ -1100,19 +1197,19 @@ public class MessagesStorage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateDialogsWithReadedMessages(final ArrayList<Integer> messages, boolean useQueue) {
|
public void updateDialogsWithReadedMessages(final HashMap<Integer, Integer> inbox, boolean useQueue) {
|
||||||
if (messages.isEmpty()) {
|
if (inbox.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (useQueue) {
|
if (useQueue) {
|
||||||
storageQueue.postRunnable(new Runnable() {
|
storageQueue.postRunnable(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
updateDialogsWithReadedMessagesInternal(messages);
|
updateDialogsWithReadedMessagesInternal(null, inbox);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
updateDialogsWithReadedMessagesInternal(messages);
|
updateDialogsWithReadedMessagesInternal(null, inbox);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1657,6 +1754,8 @@ public class MessagesStorage {
|
||||||
try {
|
try {
|
||||||
ArrayList<Integer> loadedUsers = new ArrayList<>();
|
ArrayList<Integer> loadedUsers = new ArrayList<>();
|
||||||
ArrayList<Integer> fromUser = new ArrayList<>();
|
ArrayList<Integer> fromUser = new ArrayList<>();
|
||||||
|
ArrayList<Integer> replyMessages = new ArrayList<>();
|
||||||
|
HashMap<Integer, ArrayList<TLRPC.Message>> replyMessageOwners = new HashMap<>();
|
||||||
|
|
||||||
SQLiteCursor cursor = null;
|
SQLiteCursor cursor = null;
|
||||||
int lower_id = (int)dialog_id;
|
int lower_id = (int)dialog_id;
|
||||||
|
@ -1678,18 +1777,18 @@ public class MessagesStorage {
|
||||||
cursor.dispose();
|
cursor.dispose();
|
||||||
|
|
||||||
if (containMessage) {
|
if (containMessage) {
|
||||||
cursor = database.queryFinalized(String.format(Locale.US, "SELECT * FROM (SELECT m.read_state, m.data, m.send_state, m.mid, m.date, r.random_id FROM messages as m LEFT JOIN randoms as r ON r.mid = m.mid WHERE m.uid = %d AND m.mid <= %d ORDER BY m.date DESC, m.mid DESC LIMIT %d) UNION " +
|
cursor = database.queryFinalized(String.format(Locale.US, "SELECT * FROM (SELECT m.read_state, m.data, m.send_state, m.mid, m.date, r.random_id, m.replydata FROM messages as m LEFT JOIN randoms as r ON r.mid = m.mid WHERE m.uid = %d AND m.mid <= %d ORDER BY m.date DESC, m.mid DESC LIMIT %d) UNION " +
|
||||||
"SELECT * FROM (SELECT m.read_state, m.data, m.send_state, m.mid, m.date, r.random_id FROM messages as m LEFT JOIN randoms as r ON r.mid = m.mid WHERE m.uid = %d AND m.mid > %d ORDER BY m.date ASC, m.mid ASC LIMIT %d)", dialog_id, max_id, count_query / 2, dialog_id, max_id, count_query / 2 - 1));
|
"SELECT * FROM (SELECT m.read_state, m.data, m.send_state, m.mid, m.date, r.random_id, m.replydata FROM messages as m LEFT JOIN randoms as r ON r.mid = m.mid WHERE m.uid = %d AND m.mid > %d ORDER BY m.date ASC, m.mid ASC LIMIT %d)", dialog_id, max_id, count_query / 2, dialog_id, max_id, count_query / 2 - 1));
|
||||||
} else {
|
} else {
|
||||||
cursor = null;
|
cursor = null;
|
||||||
}
|
}
|
||||||
} else if (load_type == 1) {
|
} else if (load_type == 1) {
|
||||||
cursor = database.queryFinalized(String.format(Locale.US, "SELECT m.read_state, m.data, m.send_state, m.mid, m.date, r.random_id FROM messages as m LEFT JOIN randoms as r ON r.mid = m.mid WHERE m.uid = %d AND m.date >= %d AND m.mid > %d ORDER BY m.date ASC, m.mid ASC LIMIT %d", dialog_id, minDate, max_id, count_query));
|
cursor = database.queryFinalized(String.format(Locale.US, "SELECT m.read_state, m.data, m.send_state, m.mid, m.date, r.random_id, m.replydata FROM messages as m LEFT JOIN randoms as r ON r.mid = m.mid WHERE m.uid = %d AND m.date >= %d AND m.mid > %d ORDER BY m.date ASC, m.mid ASC LIMIT %d", dialog_id, minDate, max_id, count_query));
|
||||||
} else if (minDate != 0) {
|
} else if (minDate != 0) {
|
||||||
if (max_id != 0) {
|
if (max_id != 0) {
|
||||||
cursor = database.queryFinalized(String.format(Locale.US, "SELECT m.read_state, m.data, m.send_state, m.mid, m.date, r.random_id FROM messages as m LEFT JOIN randoms as r ON r.mid = m.mid WHERE m.uid = %d AND m.date <= %d AND m.mid < %d ORDER BY m.date DESC, m.mid DESC LIMIT %d", dialog_id, minDate, max_id, count_query));
|
cursor = database.queryFinalized(String.format(Locale.US, "SELECT m.read_state, m.data, m.send_state, m.mid, m.date, r.random_id, m.replydata FROM messages as m LEFT JOIN randoms as r ON r.mid = m.mid WHERE m.uid = %d AND m.date <= %d AND m.mid < %d ORDER BY m.date DESC, m.mid DESC LIMIT %d", dialog_id, minDate, max_id, count_query));
|
||||||
} else {
|
} else {
|
||||||
cursor = database.queryFinalized(String.format(Locale.US, "SELECT m.read_state, m.data, m.send_state, m.mid, m.date, r.random_id FROM messages as m LEFT JOIN randoms as r ON r.mid = m.mid WHERE m.uid = %d AND m.date <= %d ORDER BY m.date DESC, m.mid DESC LIMIT %d,%d", dialog_id, minDate, offset_query, count_query));
|
cursor = database.queryFinalized(String.format(Locale.US, "SELECT m.read_state, m.data, m.send_state, m.mid, m.date, r.random_id, m.replydata FROM messages as m LEFT JOIN randoms as r ON r.mid = m.mid WHERE m.uid = %d AND m.date <= %d ORDER BY m.date DESC, m.mid DESC LIMIT %d,%d", dialog_id, minDate, offset_query, count_query));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (load_type == 2) {
|
if (load_type == 2) {
|
||||||
|
@ -1725,16 +1824,16 @@ public class MessagesStorage {
|
||||||
offset_query = count_unread - count_query;
|
offset_query = count_unread - count_query;
|
||||||
count_query += 10;
|
count_query += 10;
|
||||||
}
|
}
|
||||||
cursor = database.queryFinalized(String.format(Locale.US, "SELECT m.read_state, m.data, m.send_state, m.mid, m.date, r.random_id FROM messages as m LEFT JOIN randoms as r ON r.mid = m.mid WHERE m.uid = %d ORDER BY m.date DESC, m.mid DESC LIMIT %d,%d", dialog_id, offset_query, count_query));
|
cursor = database.queryFinalized(String.format(Locale.US, "SELECT m.read_state, m.data, m.send_state, m.mid, m.date, r.random_id, m.replydata FROM messages as m LEFT JOIN randoms as r ON r.mid = m.mid WHERE m.uid = %d ORDER BY m.date DESC, m.mid DESC LIMIT %d,%d", dialog_id, offset_query, count_query));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (load_type == 1) {
|
if (load_type == 1) {
|
||||||
cursor = database.queryFinalized(String.format(Locale.US, "SELECT m.read_state, m.data, m.send_state, m.mid, m.date, r.random_id FROM messages as m LEFT JOIN randoms as r ON r.mid = m.mid WHERE m.uid = %d AND m.mid < %d ORDER BY m.mid DESC LIMIT %d", dialog_id, max_id, count_query));
|
cursor = database.queryFinalized(String.format(Locale.US, "SELECT m.read_state, m.data, m.send_state, m.mid, m.date, r.random_id, m.replydata FROM messages as m LEFT JOIN randoms as r ON r.mid = m.mid WHERE m.uid = %d AND m.mid < %d ORDER BY m.mid DESC LIMIT %d", dialog_id, max_id, count_query));
|
||||||
} else if (minDate != 0) {
|
} else if (minDate != 0) {
|
||||||
if (max_id != 0) {
|
if (max_id != 0) {
|
||||||
cursor = database.queryFinalized(String.format(Locale.US, "SELECT m.read_state, m.data, m.send_state, m.mid, m.date, r.random_id FROM messages as m LEFT JOIN randoms as r ON r.mid = m.mid WHERE m.uid = %d AND m.mid > %d ORDER BY m.mid ASC LIMIT %d", dialog_id, max_id, count_query));
|
cursor = database.queryFinalized(String.format(Locale.US, "SELECT m.read_state, m.data, m.send_state, m.mid, m.date, r.random_id, m.replydata FROM messages as m LEFT JOIN randoms as r ON r.mid = m.mid WHERE m.uid = %d AND m.mid > %d ORDER BY m.mid ASC LIMIT %d", dialog_id, max_id, count_query));
|
||||||
} else {
|
} else {
|
||||||
cursor = database.queryFinalized(String.format(Locale.US, "SELECT m.read_state, m.data, m.send_state, m.mid, m.date, r.random_id FROM messages as m LEFT JOIN randoms as r ON r.mid = m.mid WHERE m.uid = %d AND m.date <= %d ORDER BY m.mid ASC LIMIT %d,%d", dialog_id, minDate, offset_query, count_query));
|
cursor = database.queryFinalized(String.format(Locale.US, "SELECT m.read_state, m.data, m.send_state, m.mid, m.date, r.random_id, m.replydata FROM messages as m LEFT JOIN randoms as r ON r.mid = m.mid WHERE m.uid = %d AND m.date <= %d ORDER BY m.mid ASC LIMIT %d,%d", dialog_id, minDate, offset_query, count_query));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (load_type == 2) {
|
if (load_type == 2) {
|
||||||
|
@ -1770,7 +1869,7 @@ public class MessagesStorage {
|
||||||
offset_query = count_unread - count_query;
|
offset_query = count_unread - count_query;
|
||||||
count_query += 10;
|
count_query += 10;
|
||||||
}
|
}
|
||||||
cursor = database.queryFinalized(String.format(Locale.US, "SELECT m.read_state, m.data, m.send_state, m.mid, m.date, r.random_id FROM messages as m LEFT JOIN randoms as r ON r.mid = m.mid WHERE m.uid = %d ORDER BY m.mid ASC LIMIT %d,%d", dialog_id, offset_query, count_query));
|
cursor = database.queryFinalized(String.format(Locale.US, "SELECT m.read_state, m.data, m.send_state, m.mid, m.date, r.random_id, m.replydata FROM messages as m LEFT JOIN randoms as r ON r.mid = m.mid WHERE m.uid = %d ORDER BY m.mid ASC LIMIT %d,%d", dialog_id, offset_query, count_query));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (cursor != null) {
|
if (cursor != null) {
|
||||||
|
@ -1796,6 +1895,43 @@ public class MessagesStorage {
|
||||||
if (message.fwd_from_id != 0) {
|
if (message.fwd_from_id != 0) {
|
||||||
fromUser.add(message.fwd_from_id);
|
fromUser.add(message.fwd_from_id);
|
||||||
}
|
}
|
||||||
|
if (message.reply_to_msg_id != 0) {
|
||||||
|
boolean ok = false;
|
||||||
|
if (!cursor.isNull(6)) {
|
||||||
|
ByteBufferDesc data2 = buffersStorage.getFreeBuffer(cursor.byteArrayLength(6));
|
||||||
|
if (data2 != null && cursor.byteBufferValue(6, data2.buffer) != 0) {
|
||||||
|
message.replyMessage = (TLRPC.Message) TLClassStore.Instance().TLdeserialize(data2, data2.readInt32());
|
||||||
|
if (message.replyMessage != null) {
|
||||||
|
fromUser.add(message.replyMessage.from_id);
|
||||||
|
if (message.replyMessage.action != null && message.replyMessage.action.user_id != 0) {
|
||||||
|
fromUser.add(message.replyMessage.action.user_id);
|
||||||
|
}
|
||||||
|
if (message.replyMessage.media != null && message.replyMessage.media.user_id != 0) {
|
||||||
|
fromUser.add(message.replyMessage.media.user_id);
|
||||||
|
}
|
||||||
|
if (message.replyMessage.media != null && message.replyMessage.media.audio != null && message.replyMessage.media.audio.user_id != 0) {
|
||||||
|
fromUser.add(message.replyMessage.media.audio.user_id);
|
||||||
|
}
|
||||||
|
if (message.replyMessage.fwd_from_id != 0) {
|
||||||
|
fromUser.add(message.replyMessage.fwd_from_id);
|
||||||
|
}
|
||||||
|
ok = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
buffersStorage.reuseFreeBuffer(data2);
|
||||||
|
}
|
||||||
|
if (!ok) {
|
||||||
|
if (!replyMessages.contains(message.reply_to_msg_id)) {
|
||||||
|
replyMessages.add(message.reply_to_msg_id);
|
||||||
|
}
|
||||||
|
ArrayList<TLRPC.Message> messages = replyMessageOwners.get(message.reply_to_msg_id);
|
||||||
|
if (messages == null) {
|
||||||
|
messages = new ArrayList<>();
|
||||||
|
replyMessageOwners.put(message.reply_to_msg_id, messages);
|
||||||
|
}
|
||||||
|
messages.add(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
message.send_state = cursor.intValue(2);
|
message.send_state = cursor.intValue(2);
|
||||||
if (!MessageObject.isUnread(message) && lower_id != 0 || message.id > 0) {
|
if (!MessageObject.isUnread(message) && lower_id != 0 || message.id > 0) {
|
||||||
message.send_state = 0;
|
message.send_state = 0;
|
||||||
|
@ -1846,33 +1982,39 @@ public class MessagesStorage {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
/*ArrayList<Range<Integer>> holes = getHoles(dialog_id);
|
if (!replyMessages.isEmpty()) {
|
||||||
if (holes != null && !res.messages.isEmpty()) {
|
cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, mid, date FROM messages WHERE mid IN(%s)", TextUtils.join(",", replyMessages)));
|
||||||
int start = res.messages.get(res.messages.size() - 1).id;
|
while (cursor.next()) {
|
||||||
int end = res.messages.get(0).id;
|
ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
|
||||||
for (Range<Integer> range : holes) {
|
if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
|
||||||
if (range.contains(start) && range.contains(end)) {
|
TLRPC.Message message = (TLRPC.Message) TLClassStore.Instance().TLdeserialize(data, data.readInt32());
|
||||||
res.messages.clear();
|
message.id = cursor.intValue(1);
|
||||||
} else if (range.contains(start)) {
|
message.date = cursor.intValue(2);
|
||||||
while (!res.messages.isEmpty() && range.contains(res.messages.get(res.messages.size() - 1).id)) {
|
message.dialog_id = dialog_id;
|
||||||
res.messages.remove(res.messages.size() - 1);
|
fromUser.add(message.from_id);
|
||||||
|
if (message.action != null && message.action.user_id != 0) {
|
||||||
|
fromUser.add(message.action.user_id);
|
||||||
}
|
}
|
||||||
if (!res.messages.isEmpty()) {
|
if (message.media != null && message.media.user_id != 0) {
|
||||||
start = res.messages.get(res.messages.size() - 1).id;
|
fromUser.add(message.media.user_id);
|
||||||
}
|
}
|
||||||
} else if (range.contains(end)) {
|
if (message.media != null && message.media.audio != null && message.media.audio.user_id != 0) {
|
||||||
while (!res.messages.isEmpty() && range.contains(res.messages.get(0).id)) {
|
fromUser.add(message.media.audio.user_id);
|
||||||
res.messages.remove(0);
|
|
||||||
}
|
}
|
||||||
if (!res.messages.isEmpty()) {
|
if (message.fwd_from_id != 0) {
|
||||||
end = res.messages.get(0).id;
|
fromUser.add(message.fwd_from_id);
|
||||||
|
}
|
||||||
|
ArrayList<TLRPC.Message> arrayList = replyMessageOwners.get(message.id);
|
||||||
|
if (arrayList != null) {
|
||||||
|
for (TLRPC.Message m : arrayList) {
|
||||||
|
m.replyMessage = message;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (start >= )
|
|
||||||
if (res.messages.isEmpty()) {
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
buffersStorage.reuseFreeBuffer(data);
|
||||||
}
|
}
|
||||||
}*/
|
cursor.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
StringBuilder usersToLoad = new StringBuilder();
|
StringBuilder usersToLoad = new StringBuilder();
|
||||||
for (int uid : fromUser) {
|
for (int uid : fromUser) {
|
||||||
|
@ -2524,6 +2666,79 @@ public class MessagesStorage {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void putWebPages(final HashMap<Long, TLRPC.WebPage> webPages) {
|
||||||
|
if (webPages == null || webPages.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
storageQueue.postRunnable(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
String ids = TextUtils.join(",", webPages.keySet());
|
||||||
|
SQLiteCursor cursor = database.queryFinalized(String.format(Locale.US, "SELECT mid FROM webpage_pending WHERE id IN (%s)", ids));
|
||||||
|
ArrayList<Integer> mids = new ArrayList<>();
|
||||||
|
while (cursor.next()) {
|
||||||
|
mids.add(cursor.intValue(0));
|
||||||
|
}
|
||||||
|
cursor.dispose();
|
||||||
|
|
||||||
|
if (mids.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final ArrayList<TLRPC.Message> messages = new ArrayList<>();
|
||||||
|
cursor = database.queryFinalized(String.format(Locale.US, "SELECT mid, data FROM messages WHERE mid IN (%s)", TextUtils.join(",", mids)));
|
||||||
|
while (cursor.next()) {
|
||||||
|
int mid = cursor.intValue(0);
|
||||||
|
ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(1));
|
||||||
|
if (data != null && cursor.byteBufferValue(1, data.buffer) != 0) {
|
||||||
|
TLRPC.Message message = (TLRPC.Message)TLClassStore.Instance().TLdeserialize(data, data.readInt32());
|
||||||
|
if (message.media instanceof TLRPC.TL_messageMediaWebPage) {
|
||||||
|
message.id = mid;
|
||||||
|
message.media.webpage = webPages.get(message.media.webpage.id);
|
||||||
|
messages.add(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
buffersStorage.reuseFreeBuffer(data);
|
||||||
|
}
|
||||||
|
cursor.dispose();
|
||||||
|
|
||||||
|
database.executeFast(String.format(Locale.US, "DELETE FROM webpage_pending WHERE id IN (%s)", ids)).stepThis().dispose();
|
||||||
|
|
||||||
|
if (messages.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
database.beginTransaction();
|
||||||
|
|
||||||
|
SQLitePreparedStatement state = database.executeFast("UPDATE messages SET data = ? WHERE mid = ?");
|
||||||
|
for (TLRPC.Message message : messages) {
|
||||||
|
ByteBufferDesc data = buffersStorage.getFreeBuffer(message.getObjectSize());
|
||||||
|
message.serializeToStream(data);
|
||||||
|
|
||||||
|
state.requery();
|
||||||
|
state.bindByteBuffer(1, data.buffer);
|
||||||
|
state.bindInteger(2, message.id);
|
||||||
|
state.step();
|
||||||
|
|
||||||
|
buffersStorage.reuseFreeBuffer(data);
|
||||||
|
}
|
||||||
|
state.dispose();
|
||||||
|
|
||||||
|
database.commitTransaction();
|
||||||
|
|
||||||
|
AndroidUtilities.runOnUIThread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
NotificationCenter.getInstance().postNotificationName(NotificationCenter.didReceivedWebpages, messages);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (Exception e) {
|
||||||
|
FileLog.e("tmessages", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private void putMessagesInternal(final ArrayList<TLRPC.Message> messages, final boolean withTransaction, final boolean isBroadcast, final int downloadMask) {
|
private void putMessagesInternal(final ArrayList<TLRPC.Message> messages, final boolean withTransaction, final boolean isBroadcast, final int downloadMask) {
|
||||||
try {
|
try {
|
||||||
if (withTransaction) {
|
if (withTransaction) {
|
||||||
|
@ -2537,10 +2752,11 @@ public class MessagesStorage {
|
||||||
HashMap<Integer, Long> messagesMediaIdsMap = new HashMap<>();
|
HashMap<Integer, Long> messagesMediaIdsMap = new HashMap<>();
|
||||||
StringBuilder messageIds = new StringBuilder();
|
StringBuilder messageIds = new StringBuilder();
|
||||||
StringBuilder messageMediaIds = new StringBuilder();
|
StringBuilder messageMediaIds = new StringBuilder();
|
||||||
SQLitePreparedStatement state = database.executeFast("REPLACE INTO messages VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)");
|
SQLitePreparedStatement state = database.executeFast("REPLACE INTO messages VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, NULL)");
|
||||||
SQLitePreparedStatement state2 = database.executeFast("REPLACE INTO media_v2 VALUES(?, ?, ?, ?, ?)");
|
SQLitePreparedStatement state2 = database.executeFast("REPLACE INTO media_v2 VALUES(?, ?, ?, ?, ?)");
|
||||||
SQLitePreparedStatement state3 = database.executeFast("REPLACE INTO randoms VALUES(?, ?)");
|
SQLitePreparedStatement state3 = database.executeFast("REPLACE INTO randoms VALUES(?, ?)");
|
||||||
SQLitePreparedStatement state4 = database.executeFast("REPLACE INTO download_queue VALUES(?, ?, ?, ?)");
|
SQLitePreparedStatement state4 = database.executeFast("REPLACE INTO download_queue VALUES(?, ?, ?, ?)");
|
||||||
|
SQLitePreparedStatement state5 = database.executeFast("REPLACE INTO webpage_pending VALUES(?, ?)");
|
||||||
|
|
||||||
for (TLRPC.Message message : messages) {
|
for (TLRPC.Message message : messages) {
|
||||||
long dialog_id = message.dialog_id;
|
long dialog_id = message.dialog_id;
|
||||||
|
@ -2674,15 +2890,23 @@ public class MessagesStorage {
|
||||||
state2.bindByteBuffer(5, data.buffer);
|
state2.bindByteBuffer(5, data.buffer);
|
||||||
state2.step();
|
state2.step();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (message.media instanceof TLRPC.TL_messageMediaWebPage && message.media.webpage instanceof TLRPC.TL_webPagePending) {
|
||||||
|
state5.requery();
|
||||||
|
state5.bindLong(1, message.media.webpage.id);
|
||||||
|
state5.bindInteger(2, message.id);
|
||||||
|
state5.step();
|
||||||
|
}
|
||||||
|
|
||||||
buffersStorage.reuseFreeBuffer(data);
|
buffersStorage.reuseFreeBuffer(data);
|
||||||
|
|
||||||
if (downloadMask != 0) {
|
if (message.date >= ConnectionsManager.getInstance().getCurrentTime() - 60 * 60 * 24 && downloadMask != 0) {
|
||||||
if (message.media instanceof TLRPC.TL_messageMediaAudio || message.media instanceof TLRPC.TL_messageMediaPhoto || message.media instanceof TLRPC.TL_messageMediaVideo || message.media instanceof TLRPC.TL_messageMediaDocument) {
|
if (message.media instanceof TLRPC.TL_messageMediaAudio || message.media instanceof TLRPC.TL_messageMediaPhoto || message.media instanceof TLRPC.TL_messageMediaVideo || message.media instanceof TLRPC.TL_messageMediaDocument) {
|
||||||
int type = 0;
|
int type = 0;
|
||||||
long id = 0;
|
long id = 0;
|
||||||
TLObject object = null;
|
TLObject object = null;
|
||||||
if (message.media instanceof TLRPC.TL_messageMediaAudio) {
|
if (message.media instanceof TLRPC.TL_messageMediaAudio) {
|
||||||
if ((downloadMask & MediaController.AUTODOWNLOAD_MASK_AUDIO) != 0) {
|
if ((downloadMask & MediaController.AUTODOWNLOAD_MASK_AUDIO) != 0 && message.media.audio.size < 1024 * 1024 * 5) {
|
||||||
id = message.media.audio.id;
|
id = message.media.audio.id;
|
||||||
type = MediaController.AUTODOWNLOAD_MASK_AUDIO;
|
type = MediaController.AUTODOWNLOAD_MASK_AUDIO;
|
||||||
object = message.media.audio;
|
object = message.media.audio;
|
||||||
|
@ -2728,6 +2952,7 @@ public class MessagesStorage {
|
||||||
state2.dispose();
|
state2.dispose();
|
||||||
state3.dispose();
|
state3.dispose();
|
||||||
state4.dispose();
|
state4.dispose();
|
||||||
|
state5.dispose();
|
||||||
|
|
||||||
state = database.executeFast("REPLACE INTO dialogs(did, date, unread_count, last_mid) VALUES(?, ?, ?, ?)");
|
state = database.executeFast("REPLACE INTO dialogs(did, date, unread_count, last_mid) VALUES(?, ?, ?, ?)");
|
||||||
for (HashMap.Entry<Long, TLRPC.Message> pair : messagesMap.entrySet()) {
|
for (HashMap.Entry<Long, TLRPC.Message> pair : messagesMap.entrySet()) {
|
||||||
|
@ -3111,14 +3336,20 @@ public class MessagesStorage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void markMessagesAsReadInternal(final ArrayList<Integer> messages, HashMap<Integer, Integer> encryptedMessages) {
|
private void markMessagesAsReadInternal(HashMap<Integer, Integer> inbox, HashMap<Integer, Integer> outbox, HashMap<Integer, Integer> encryptedMessages) {
|
||||||
if (Thread.currentThread().getId() != storageQueue.getId()) {
|
if (Thread.currentThread().getId() != storageQueue.getId()) {
|
||||||
throw new RuntimeException("wrong db thread");
|
throw new RuntimeException("wrong db thread");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (messages != null && !messages.isEmpty()) {
|
if (inbox != null) {
|
||||||
String ids = TextUtils.join(",", messages);
|
for (HashMap.Entry<Integer, Integer> entry : inbox.entrySet()) {
|
||||||
database.executeFast(String.format(Locale.US, "UPDATE messages SET read_state = 1 WHERE mid IN(%s)", ids)).stepThis().dispose();
|
database.executeFast(String.format(Locale.US, "UPDATE messages SET read_state = 1 WHERE uid = %d AND mid <= %d AND read_state = 0 AND out = 0", entry.getKey(), entry.getValue())).stepThis().dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (outbox != null) {
|
||||||
|
for (HashMap.Entry<Integer, Integer> entry : outbox.entrySet()) {
|
||||||
|
database.executeFast(String.format(Locale.US, "UPDATE messages SET read_state = 1 WHERE uid = %d AND mid <= %d AND read_state = 0 AND out = 1", entry.getKey(), entry.getValue())).stepThis().dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (encryptedMessages != null && !encryptedMessages.isEmpty()) {
|
if (encryptedMessages != null && !encryptedMessages.isEmpty()) {
|
||||||
for (HashMap.Entry<Integer, Integer> entry : encryptedMessages.entrySet()) {
|
for (HashMap.Entry<Integer, Integer> entry : encryptedMessages.entrySet()) {
|
||||||
|
@ -3137,16 +3368,16 @@ public class MessagesStorage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void markMessagesAsRead(final ArrayList<Integer> messages, final HashMap<Integer, Integer> encryptedMessages, boolean useQueue) {
|
public void markMessagesAsRead(final HashMap<Integer, Integer> inbox, final HashMap<Integer, Integer> outbox, final HashMap<Integer, Integer> encryptedMessages, boolean useQueue) {
|
||||||
if (useQueue) {
|
if (useQueue) {
|
||||||
storageQueue.postRunnable(new Runnable() {
|
storageQueue.postRunnable(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
markMessagesAsReadInternal(messages, encryptedMessages);
|
markMessagesAsReadInternal(inbox, outbox, encryptedMessages);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
markMessagesAsReadInternal(messages, encryptedMessages);
|
markMessagesAsReadInternal(inbox, outbox, encryptedMessages);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3178,6 +3409,7 @@ public class MessagesStorage {
|
||||||
NotificationCenter.getInstance().postNotificationName(NotificationCenter.messagesDeleted, mids);
|
NotificationCenter.getInstance().postNotificationName(NotificationCenter.messagesDeleted, mids);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
MessagesStorage.getInstance().updateDialogsWithReadedMessagesInternal(mids, null);
|
||||||
MessagesStorage.getInstance().markMessagesAsDeletedInternal(mids);
|
MessagesStorage.getInstance().markMessagesAsDeletedInternal(mids);
|
||||||
MessagesStorage.getInstance().updateDialogsWithDeletedMessagesInternal(mids);
|
MessagesStorage.getInstance().updateDialogsWithDeletedMessagesInternal(mids);
|
||||||
}
|
}
|
||||||
|
@ -3189,9 +3421,6 @@ public class MessagesStorage {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void markMessagesAsDeletedInternal(final ArrayList<Integer> messages) {
|
private void markMessagesAsDeletedInternal(final ArrayList<Integer> messages) {
|
||||||
if (Thread.currentThread().getId() != storageQueue.getId()) {
|
|
||||||
throw new RuntimeException("wrong db thread");
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
String ids = TextUtils.join(",", messages);
|
String ids = TextUtils.join(",", messages);
|
||||||
SQLiteCursor cursor = database.queryFinalized(String.format(Locale.US, "SELECT uid, data FROM messages WHERE mid IN(%s)", ids));
|
SQLiteCursor cursor = database.queryFinalized(String.format(Locale.US, "SELECT uid, data FROM messages WHERE mid IN(%s)", ids));
|
||||||
|
@ -3287,7 +3516,7 @@ public class MessagesStorage {
|
||||||
ArrayList<Integer> usersToLoad = new ArrayList<>();
|
ArrayList<Integer> usersToLoad = new ArrayList<>();
|
||||||
ArrayList<Integer> chatsToLoad = new ArrayList<>();
|
ArrayList<Integer> chatsToLoad = new ArrayList<>();
|
||||||
ArrayList<Integer> encryptedToLoad = new ArrayList<>();
|
ArrayList<Integer> encryptedToLoad = new ArrayList<>();
|
||||||
cursor = database.queryFinalized(String.format(Locale.US, "SELECT d.did, d.last_mid, d.unread_count, d.date, m.data, m.read_state, m.mid, m.send_state FROM dialogs as d LEFT JOIN messages as m ON d.last_mid = m.mid WHERE d.did IN(%s)", ids));
|
cursor = database.queryFinalized(String.format(Locale.US, "SELECT d.did, d.last_mid, d.unread_count, d.date, m.data, m.read_state, m.mid, m.send_state, m.date FROM dialogs as d LEFT JOIN messages as m ON d.last_mid = m.mid WHERE d.did IN(%s)", ids));
|
||||||
while (cursor.next()) {
|
while (cursor.next()) {
|
||||||
TLRPC.TL_dialog dialog = new TLRPC.TL_dialog();
|
TLRPC.TL_dialog dialog = new TLRPC.TL_dialog();
|
||||||
dialog.id = cursor.longValue(0);
|
dialog.id = cursor.longValue(0);
|
||||||
|
@ -3302,6 +3531,10 @@ public class MessagesStorage {
|
||||||
MessageObject.setIsUnread(message, cursor.intValue(5) != 1);
|
MessageObject.setIsUnread(message, cursor.intValue(5) != 1);
|
||||||
message.id = cursor.intValue(6);
|
message.id = cursor.intValue(6);
|
||||||
message.send_state = cursor.intValue(7);
|
message.send_state = cursor.intValue(7);
|
||||||
|
int date = cursor.intValue(8);
|
||||||
|
if (date != 0) {
|
||||||
|
dialog.last_message_date = date;
|
||||||
|
}
|
||||||
dialogs.messages.add(message);
|
dialogs.messages.add(message);
|
||||||
|
|
||||||
if (!usersToLoad.contains(message.from_id)) {
|
if (!usersToLoad.contains(message.from_id)) {
|
||||||
|
@ -3399,11 +3632,19 @@ public class MessagesStorage {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fixUnsupportedMedia(TLRPC.Message message) {
|
private void fixUnsupportedMedia(TLRPC.Message message) {
|
||||||
if (message != null && message.media instanceof TLRPC.TL_messageMediaUnsupported && message.media.bytes != null) {
|
if (message == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
boolean ok = false;
|
||||||
|
if (message.media instanceof TLRPC.TL_messageMediaUnsupported_old) {
|
||||||
if (message.media.bytes.length == 0) {
|
if (message.media.bytes.length == 0) {
|
||||||
message.media.bytes = new byte[1];
|
message.media.bytes = new byte[1];
|
||||||
message.media.bytes[0] = TLRPC.LAYER;
|
message.media.bytes[0] = TLRPC.LAYER;
|
||||||
}
|
}
|
||||||
|
} else if (message.media instanceof TLRPC.TL_messageMediaUnsupported) {
|
||||||
|
message.media = new TLRPC.TL_messageMediaUnsupported_old();
|
||||||
|
message.media.bytes = new byte[1];
|
||||||
|
message.media.bytes[0] = TLRPC.LAYER;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3417,7 +3658,7 @@ public class MessagesStorage {
|
||||||
try {
|
try {
|
||||||
database.beginTransaction();
|
database.beginTransaction();
|
||||||
if (!messages.messages.isEmpty()) {
|
if (!messages.messages.isEmpty()) {
|
||||||
SQLitePreparedStatement state = database.executeFast("REPLACE INTO messages VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)");
|
SQLitePreparedStatement state = database.executeFast("REPLACE INTO messages VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, NULL)");
|
||||||
SQLitePreparedStatement state2 = database.executeFast("REPLACE INTO media_v2 VALUES(?, ?, ?, ?, ?)");
|
SQLitePreparedStatement state2 = database.executeFast("REPLACE INTO media_v2 VALUES(?, ?, ?, ?, ?)");
|
||||||
for (TLRPC.Message message : messages.messages) {
|
for (TLRPC.Message message : messages.messages) {
|
||||||
fixUnsupportedMedia(message);
|
fixUnsupportedMedia(message);
|
||||||
|
@ -3471,7 +3712,7 @@ public class MessagesStorage {
|
||||||
usersToLoad.add(UserConfig.getClientUserId());
|
usersToLoad.add(UserConfig.getClientUserId());
|
||||||
ArrayList<Integer> chatsToLoad = new ArrayList<>();
|
ArrayList<Integer> chatsToLoad = new ArrayList<>();
|
||||||
ArrayList<Integer> encryptedToLoad = new ArrayList<>();
|
ArrayList<Integer> encryptedToLoad = new ArrayList<>();
|
||||||
SQLiteCursor cursor = database.queryFinalized(String.format(Locale.US, "SELECT d.did, d.last_mid, d.unread_count, d.date, m.data, m.read_state, m.mid, m.send_state, s.flags FROM dialogs as d LEFT JOIN messages as m ON d.last_mid = m.mid LEFT JOIN dialog_settings as s ON d.did = s.did ORDER BY d.date DESC LIMIT %d,%d", offset, count));
|
SQLiteCursor cursor = database.queryFinalized(String.format(Locale.US, "SELECT d.did, d.last_mid, d.unread_count, d.date, m.data, m.read_state, m.mid, m.send_state, s.flags, m.date FROM dialogs as d LEFT JOIN messages as m ON d.last_mid = m.mid LEFT JOIN dialog_settings as s ON d.did = s.did ORDER BY d.date DESC LIMIT %d,%d", offset, count));
|
||||||
while (cursor.next()) {
|
while (cursor.next()) {
|
||||||
TLRPC.TL_dialog dialog = new TLRPC.TL_dialog();
|
TLRPC.TL_dialog dialog = new TLRPC.TL_dialog();
|
||||||
dialog.id = cursor.longValue(0);
|
dialog.id = cursor.longValue(0);
|
||||||
|
@ -3495,6 +3736,10 @@ public class MessagesStorage {
|
||||||
if (message != null) {
|
if (message != null) {
|
||||||
MessageObject.setIsUnread(message, cursor.intValue(5) != 1);
|
MessageObject.setIsUnread(message, cursor.intValue(5) != 1);
|
||||||
message.id = cursor.intValue(6);
|
message.id = cursor.intValue(6);
|
||||||
|
int date = cursor.intValue(9);
|
||||||
|
if (date != 0) {
|
||||||
|
dialog.last_message_date = date;
|
||||||
|
}
|
||||||
message.send_state = cursor.intValue(7);
|
message.send_state = cursor.intValue(7);
|
||||||
dialogs.messages.add(message);
|
dialogs.messages.add(message);
|
||||||
|
|
||||||
|
@ -3585,7 +3830,7 @@ public class MessagesStorage {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!dialogs.dialogs.isEmpty()) {
|
if (!dialogs.dialogs.isEmpty()) {
|
||||||
SQLitePreparedStatement state = database.executeFast("REPLACE INTO messages VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)");
|
SQLitePreparedStatement state = database.executeFast("REPLACE INTO messages VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, NULL)");
|
||||||
SQLitePreparedStatement state2 = database.executeFast("REPLACE INTO dialogs(did, date, unread_count, last_mid) VALUES(?, ?, ?, ?)");
|
SQLitePreparedStatement state2 = database.executeFast("REPLACE INTO dialogs(did, date, unread_count, last_mid) VALUES(?, ?, ?, ?)");
|
||||||
SQLitePreparedStatement state3 = database.executeFast("REPLACE INTO media_v2 VALUES(?, ?, ?, ?, ?)");
|
SQLitePreparedStatement state3 = database.executeFast("REPLACE INTO media_v2 VALUES(?, ?, ?, ?, ?)");
|
||||||
SQLitePreparedStatement state4 = database.executeFast("REPLACE INTO dialog_settings VALUES(?, ?)");
|
SQLitePreparedStatement state4 = database.executeFast("REPLACE INTO dialog_settings VALUES(?, ?)");
|
||||||
|
@ -3654,6 +3899,42 @@ public class MessagesStorage {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TLRPC.User getUserSync(final int user_id) {
|
||||||
|
final Semaphore semaphore = new Semaphore(0);
|
||||||
|
final TLRPC.User[] user = new TLRPC.User[1];
|
||||||
|
MessagesStorage.getInstance().getStorageQueue().postRunnable(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
user[0] = getUser(user_id);
|
||||||
|
semaphore.release();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
semaphore.acquire();
|
||||||
|
} catch (Exception e) {
|
||||||
|
FileLog.e("tmessages", e);
|
||||||
|
}
|
||||||
|
return user[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
public TLRPC.Chat getChatSync(final int user_id) {
|
||||||
|
final Semaphore semaphore = new Semaphore(0);
|
||||||
|
final TLRPC.Chat[] chat = new TLRPC.Chat[1];
|
||||||
|
MessagesStorage.getInstance().getStorageQueue().postRunnable(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
chat[0] = getChat(user_id);
|
||||||
|
semaphore.release();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
semaphore.acquire();
|
||||||
|
} catch (Exception e) {
|
||||||
|
FileLog.e("tmessages", e);
|
||||||
|
}
|
||||||
|
return chat[0];
|
||||||
|
}
|
||||||
|
|
||||||
public TLRPC.User getUser(final int user_id) {
|
public TLRPC.User getUser(final int user_id) {
|
||||||
TLRPC.User user = null;
|
TLRPC.User user = null;
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -23,7 +23,7 @@ import java.util.zip.ZipFile;
|
||||||
|
|
||||||
public class NativeLoader {
|
public class NativeLoader {
|
||||||
|
|
||||||
private final static int LIB_VERSION = 5;
|
private final static int LIB_VERSION = 7;
|
||||||
private final static String LIB_NAME = "tmessages." + LIB_VERSION;
|
private final static String LIB_NAME = "tmessages." + LIB_VERSION;
|
||||||
private final static String LIB_SO_NAME = "lib" + LIB_NAME + ".so";
|
private final static String LIB_SO_NAME = "lib" + LIB_NAME + ".so";
|
||||||
private final static String LOCALE_LIB_SO_NAME = "lib" + LIB_NAME + "loc.so";
|
private final static String LOCALE_LIB_SO_NAME = "lib" + LIB_NAME + "loc.so";
|
||||||
|
|
|
@ -48,6 +48,14 @@ public class NotificationCenter {
|
||||||
public static final int updateMessageMedia = totalEvents++;
|
public static final int updateMessageMedia = totalEvents++;
|
||||||
public static final int recentImagesDidLoaded = totalEvents++;
|
public static final int recentImagesDidLoaded = totalEvents++;
|
||||||
public static final int replaceMessagesObjects = totalEvents++;
|
public static final int replaceMessagesObjects = totalEvents++;
|
||||||
|
public static final int didSetPasscode = totalEvents++;
|
||||||
|
public static final int didSetTwoStepPassword = totalEvents++;
|
||||||
|
public static final int screenStateChanged = totalEvents++;
|
||||||
|
public static final int appSwitchedToForeground = totalEvents++;
|
||||||
|
public static final int didLoadedReplyMessages = totalEvents++;
|
||||||
|
public static final int newSessionReceived = totalEvents++;
|
||||||
|
public static final int didReceivedWebpages = totalEvents++;
|
||||||
|
public static final int didReceivedWebpagesInUpdates = totalEvents++;
|
||||||
|
|
||||||
public static final int httpFileDidLoaded = totalEvents++;
|
public static final int httpFileDidLoaded = totalEvents++;
|
||||||
public static final int httpFileDidFailedLoad = totalEvents++;
|
public static final int httpFileDidFailedLoad = totalEvents++;
|
||||||
|
@ -60,7 +68,6 @@ public class NotificationCenter {
|
||||||
public static final int didReceiveSmsCode = totalEvents++;
|
public static final int didReceiveSmsCode = totalEvents++;
|
||||||
public static final int emojiDidLoaded = totalEvents++;
|
public static final int emojiDidLoaded = totalEvents++;
|
||||||
public static final int appDidLogout = totalEvents++;
|
public static final int appDidLogout = totalEvents++;
|
||||||
public static final int needPasswordEnter = totalEvents++;
|
|
||||||
|
|
||||||
public static final int FileDidUpload = totalEvents++;
|
public static final int FileDidUpload = totalEvents++;
|
||||||
public static final int FileDidFailUpload = totalEvents++;
|
public static final int FileDidFailUpload = totalEvents++;
|
||||||
|
@ -106,7 +113,7 @@ public class NotificationCenter {
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface NotificationCenterDelegate {
|
public interface NotificationCenterDelegate {
|
||||||
public abstract void didReceivedNotification(int id, Object... args);
|
void didReceivedNotification(int id, Object... args);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void postNotificationName(int id, Object... args) {
|
public void postNotificationName(int id, Object... args) {
|
||||||
|
|
|
@ -11,13 +11,16 @@ package org.telegram.android;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlarmManager;
|
import android.app.AlarmManager;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
|
import android.content.ContentValues;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.ResolveInfo;
|
import android.content.pm.ResolveInfo;
|
||||||
|
import android.content.res.AssetFileDescriptor;
|
||||||
import android.graphics.drawable.BitmapDrawable;
|
import android.graphics.drawable.BitmapDrawable;
|
||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
|
import android.media.MediaPlayer;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
|
@ -29,6 +32,7 @@ import android.support.v4.app.RemoteInput;
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.telegram.messenger.ConnectionsManager;
|
import org.telegram.messenger.ConnectionsManager;
|
||||||
|
import org.telegram.messenger.DispatchQueue;
|
||||||
import org.telegram.messenger.FileLog;
|
import org.telegram.messenger.FileLog;
|
||||||
import org.telegram.messenger.R;
|
import org.telegram.messenger.R;
|
||||||
import org.telegram.messenger.RPCRequest;
|
import org.telegram.messenger.RPCRequest;
|
||||||
|
@ -48,11 +52,13 @@ public class NotificationsController {
|
||||||
|
|
||||||
public static final String EXTRA_VOICE_REPLY = "extra_voice_reply";
|
public static final String EXTRA_VOICE_REPLY = "extra_voice_reply";
|
||||||
|
|
||||||
|
private DispatchQueue notificationsQueue = new DispatchQueue("notificationsQueue");
|
||||||
private ArrayList<MessageObject> pushMessages = new ArrayList<>();
|
private ArrayList<MessageObject> pushMessages = new ArrayList<>();
|
||||||
private HashMap<Integer, MessageObject> pushMessagesDict = new HashMap<>();
|
private HashMap<Integer, MessageObject> pushMessagesDict = new HashMap<>();
|
||||||
private NotificationManagerCompat notificationManager = null;
|
private NotificationManagerCompat notificationManager = null;
|
||||||
private HashMap<Long, Integer> pushDialogs = new HashMap<>();
|
private HashMap<Long, Integer> pushDialogs = new HashMap<>();
|
||||||
private HashMap<Long, Integer> wearNoticationsIds = new HashMap<>();
|
private HashMap<Long, Integer> wearNoticationsIds = new HashMap<>();
|
||||||
|
private HashMap<Long, Integer> pushDialogsOverrideMention = new HashMap<>();
|
||||||
private int wearNotificationId = 10000;
|
private int wearNotificationId = 10000;
|
||||||
public ArrayList<MessageObject> popupMessages = new ArrayList<>();
|
public ArrayList<MessageObject> popupMessages = new ArrayList<>();
|
||||||
private long openned_dialog_id = 0;
|
private long openned_dialog_id = 0;
|
||||||
|
@ -60,6 +66,12 @@ public class NotificationsController {
|
||||||
private int personal_count = 0;
|
private int personal_count = 0;
|
||||||
private boolean notifyCheck = false;
|
private boolean notifyCheck = false;
|
||||||
private int lastOnlineFromOtherDevice = 0;
|
private int lastOnlineFromOtherDevice = 0;
|
||||||
|
private boolean inChatSoundEnabled = true;
|
||||||
|
|
||||||
|
private long lastSoundPlay;
|
||||||
|
private MediaPlayer mediaPlayerIn;
|
||||||
|
private MediaPlayer mediaPlayerOut;
|
||||||
|
protected AudioManager audioManager;
|
||||||
|
|
||||||
private static volatile NotificationsController Instance = null;
|
private static volatile NotificationsController Instance = null;
|
||||||
public static NotificationsController getInstance() {
|
public static NotificationsController getInstance() {
|
||||||
|
@ -77,6 +89,15 @@ public class NotificationsController {
|
||||||
|
|
||||||
public NotificationsController() {
|
public NotificationsController() {
|
||||||
notificationManager = NotificationManagerCompat.from(ApplicationLoader.applicationContext);
|
notificationManager = NotificationManagerCompat.from(ApplicationLoader.applicationContext);
|
||||||
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Context.MODE_PRIVATE);
|
||||||
|
inChatSoundEnabled = preferences.getBoolean("EnableInChatSound", true);
|
||||||
|
|
||||||
|
try {
|
||||||
|
audioManager = (AudioManager) ApplicationLoader.applicationContext.getSystemService(Context.AUDIO_SERVICE);
|
||||||
|
//mediaPlayer = new MediaPlayer();
|
||||||
|
} catch (Exception e) {
|
||||||
|
FileLog.e("tmessages", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cleanup() {
|
public void cleanup() {
|
||||||
|
@ -95,6 +116,10 @@ public class NotificationsController {
|
||||||
editor.commit();
|
editor.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setInChatSoundEnabled(boolean value) {
|
||||||
|
inChatSoundEnabled = value;
|
||||||
|
}
|
||||||
|
|
||||||
public void setOpennedDialogId(long dialog_id) {
|
public void setOpennedDialogId(long dialog_id) {
|
||||||
openned_dialog_id = dialog_id;
|
openned_dialog_id = dialog_id;
|
||||||
}
|
}
|
||||||
|
@ -130,7 +155,9 @@ public class NotificationsController {
|
||||||
}
|
}
|
||||||
|
|
||||||
String msg = null;
|
String msg = null;
|
||||||
if ((int)dialog_id != 0) {
|
if ((int)dialog_id == 0 || AndroidUtilities.needShowPasscode(false) || UserConfig.isWaitingForPasscodeEnter) {
|
||||||
|
msg = LocaleController.getString("YouHaveNewMessage", R.string.YouHaveNewMessage);
|
||||||
|
} else {
|
||||||
if (chat_id == 0 && user_id != 0) {
|
if (chat_id == 0 && user_id != 0) {
|
||||||
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Context.MODE_PRIVATE);
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Context.MODE_PRIVATE);
|
||||||
if (preferences.getBoolean("EnablePreviewAll", true)) {
|
if (preferences.getBoolean("EnablePreviewAll", true)) {
|
||||||
|
@ -144,7 +171,7 @@ public class NotificationsController {
|
||||||
msg = LocaleController.formatString("NotificationUnrecognizedDevice", R.string.NotificationUnrecognizedDevice, UserConfig.getCurrentUser().first_name, date, messageObject.messageOwner.action.title, messageObject.messageOwner.action.address);
|
msg = LocaleController.formatString("NotificationUnrecognizedDevice", R.string.NotificationUnrecognizedDevice, UserConfig.getCurrentUser().first_name, date, messageObject.messageOwner.action.title, messageObject.messageOwner.action.address);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaEmpty) {
|
if (messageObject.isMediaEmpty()) {
|
||||||
if (!shortMessage) {
|
if (!shortMessage) {
|
||||||
if (messageObject.messageOwner.message != null && messageObject.messageOwner.message.length() != 0) {
|
if (messageObject.messageOwner.message != null && messageObject.messageOwner.message.length() != 0) {
|
||||||
msg = LocaleController.formatString("NotificationMessageText", R.string.NotificationMessageText, ContactsController.formatName(user.first_name, user.last_name), messageObject.messageOwner.message);
|
msg = LocaleController.formatString("NotificationMessageText", R.string.NotificationMessageText, ContactsController.formatName(user.first_name, user.last_name), messageObject.messageOwner.message);
|
||||||
|
@ -209,7 +236,7 @@ public class NotificationsController {
|
||||||
msg = messageObject.messageText.toString();
|
msg = messageObject.messageText.toString();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaEmpty) {
|
if (messageObject.isMediaEmpty()) {
|
||||||
if (!shortMessage && messageObject.messageOwner.message != null && messageObject.messageOwner.message.length() != 0) {
|
if (!shortMessage && messageObject.messageOwner.message != null && messageObject.messageOwner.message.length() != 0) {
|
||||||
msg = LocaleController.formatString("NotificationMessageGroupText", R.string.NotificationMessageGroupText, ContactsController.formatName(user.first_name, user.last_name), chat.title, messageObject.messageOwner.message);
|
msg = LocaleController.formatString("NotificationMessageGroupText", R.string.NotificationMessageGroupText, ContactsController.formatName(user.first_name, user.last_name), chat.title, messageObject.messageOwner.message);
|
||||||
} else {
|
} else {
|
||||||
|
@ -237,8 +264,6 @@ public class NotificationsController {
|
||||||
msg = LocaleController.formatString("NotificationMessageGroupNoText", R.string.NotificationMessageGroupNoText, ContactsController.formatName(user.first_name, user.last_name), chat.title);
|
msg = LocaleController.formatString("NotificationMessageGroupNoText", R.string.NotificationMessageGroupNoText, ContactsController.formatName(user.first_name, user.last_name), chat.title);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
msg = LocaleController.getString("YouHaveNewMessage", R.string.YouHaveNewMessage);
|
|
||||||
}
|
}
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
@ -250,7 +275,7 @@ public class NotificationsController {
|
||||||
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
|
||||||
int minutes = preferences.getInt("repeat_messages", 60);
|
int minutes = preferences.getInt("repeat_messages", 60);
|
||||||
if (minutes > 0 && personal_count > 0) {
|
if (minutes > 0 && personal_count > 0) {
|
||||||
alarm.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + minutes * 60 * 1000, pintent);
|
alarm.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + minutes * 60 * 1000, pintent);
|
||||||
} else {
|
} else {
|
||||||
alarm.cancel(pintent);
|
alarm.cancel(pintent);
|
||||||
}
|
}
|
||||||
|
@ -266,9 +291,9 @@ public class NotificationsController {
|
||||||
PendingIntent pintent = PendingIntent.getService(ApplicationLoader.applicationContext, 0, new Intent(ApplicationLoader.applicationContext, NotificationDelay.class), 0);
|
PendingIntent pintent = PendingIntent.getService(ApplicationLoader.applicationContext, 0, new Intent(ApplicationLoader.applicationContext, NotificationDelay.class), 0);
|
||||||
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
|
||||||
if (onlineReason) {
|
if (onlineReason) {
|
||||||
alarm.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 3 * 1000, pintent);
|
alarm.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 3 * 1000, pintent);
|
||||||
} else {
|
} else {
|
||||||
alarm.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 500, pintent);
|
alarm.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 500, pintent);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
FileLog.e("tmessages", e);
|
FileLog.e("tmessages", e);
|
||||||
|
@ -310,7 +335,11 @@ public class NotificationsController {
|
||||||
MessageObject lastMessageObject = pushMessages.get(0);
|
MessageObject lastMessageObject = pushMessages.get(0);
|
||||||
|
|
||||||
long dialog_id = lastMessageObject.getDialogId();
|
long dialog_id = lastMessageObject.getDialogId();
|
||||||
int mid = lastMessageObject.messageOwner.id;
|
long override_dialog_id = dialog_id;
|
||||||
|
if ((lastMessageObject.messageOwner.flags & TLRPC.MESSAGE_FLAG_MENTION) != 0) {
|
||||||
|
override_dialog_id = lastMessageObject.messageOwner.from_id;
|
||||||
|
}
|
||||||
|
int mid = lastMessageObject.getId();
|
||||||
int chat_id = lastMessageObject.messageOwner.to_id.chat_id;
|
int chat_id = lastMessageObject.messageOwner.to_id.chat_id;
|
||||||
int user_id = lastMessageObject.messageOwner.to_id.user_id;
|
int user_id = lastMessageObject.messageOwner.to_id.user_id;
|
||||||
if (user_id == 0) {
|
if (user_id == 0) {
|
||||||
|
@ -339,9 +368,9 @@ public class NotificationsController {
|
||||||
int vibrate_override = 0;
|
int vibrate_override = 0;
|
||||||
|
|
||||||
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Context.MODE_PRIVATE);
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Context.MODE_PRIVATE);
|
||||||
int notify_override = preferences.getInt("notify2_" + dialog_id, 0);
|
int notify_override = preferences.getInt("notify2_" + override_dialog_id, 0);
|
||||||
if (notify_override == 3) {
|
if (notify_override == 3) {
|
||||||
int mute_until = preferences.getInt("notifyuntil_" + dialog_id, 0);
|
int mute_until = preferences.getInt("notifyuntil_" + override_dialog_id, 0);
|
||||||
if (mute_until >= ConnectionsManager.getInstance().getCurrentTime()) {
|
if (mute_until >= ConnectionsManager.getInstance().getCurrentTime()) {
|
||||||
notify_override = 2;
|
notify_override = 2;
|
||||||
}
|
}
|
||||||
|
@ -358,6 +387,7 @@ public class NotificationsController {
|
||||||
inAppPriority = preferences.getBoolean("EnableInAppPriority", false);
|
inAppPriority = preferences.getBoolean("EnableInAppPriority", false);
|
||||||
vibrate_override = preferences.getInt("vibrate_" + dialog_id, 0);
|
vibrate_override = preferences.getInt("vibrate_" + dialog_id, 0);
|
||||||
priority_override = preferences.getInt("priority_" + dialog_id, 3);
|
priority_override = preferences.getInt("priority_" + dialog_id, 3);
|
||||||
|
boolean vibrateOnlyIfSilent = false;
|
||||||
|
|
||||||
choosenSoundPath = preferences.getString("sound_path_" + dialog_id, null);
|
choosenSoundPath = preferences.getString("sound_path_" + dialog_id, null);
|
||||||
if (chat_id != 0) {
|
if (chat_id != 0) {
|
||||||
|
@ -387,6 +417,10 @@ public class NotificationsController {
|
||||||
priority = priority_override;
|
priority = priority_override;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (needVibrate == 4) {
|
||||||
|
vibrateOnlyIfSilent = true;
|
||||||
|
needVibrate = 0;
|
||||||
|
}
|
||||||
if (needVibrate == 2 && (vibrate_override == 1 || vibrate_override == 3 || vibrate_override == 5) || needVibrate != 2 && vibrate_override == 2 || vibrate_override != 0) {
|
if (needVibrate == 2 && (vibrate_override == 1 || vibrate_override == 3 || vibrate_override == 5) || needVibrate != 2 && vibrate_override == 2 || vibrate_override != 0) {
|
||||||
needVibrate = vibrate_override;
|
needVibrate = vibrate_override;
|
||||||
}
|
}
|
||||||
|
@ -403,6 +437,16 @@ public class NotificationsController {
|
||||||
priority = 1;
|
priority = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (vibrateOnlyIfSilent && needVibrate != 2) {
|
||||||
|
try {
|
||||||
|
int mode = audioManager.getRingerMode();
|
||||||
|
if (mode != AudioManager.RINGER_MODE_SILENT && mode != AudioManager.RINGER_MODE_VIBRATE) {
|
||||||
|
needVibrate = 2;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
FileLog.e("tmessages", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Intent intent = new Intent(ApplicationLoader.applicationContext, LaunchActivity.class);
|
Intent intent = new Intent(ApplicationLoader.applicationContext, LaunchActivity.class);
|
||||||
|
@ -416,14 +460,18 @@ public class NotificationsController {
|
||||||
intent.putExtra("userId", user_id);
|
intent.putExtra("userId", user_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (pushDialogs.size() == 1) {
|
if (AndroidUtilities.needShowPasscode(false) || UserConfig.isWaitingForPasscodeEnter) {
|
||||||
if (chat != null) {
|
photoPath = null;
|
||||||
if (chat.photo != null && chat.photo.photo_small != null && chat.photo.photo_small.volume_id != 0 && chat.photo.photo_small.local_id != 0) {
|
} else {
|
||||||
photoPath = chat.photo.photo_small;
|
if (pushDialogs.size() == 1) {
|
||||||
}
|
if (chat != null) {
|
||||||
} else {
|
if (chat.photo != null && chat.photo.photo_small != null && chat.photo.photo_small.volume_id != 0 && chat.photo.photo_small.local_id != 0) {
|
||||||
if (user.photo != null && user.photo.photo_small != null && user.photo.photo_small.volume_id != 0 && user.photo.photo_small.local_id != 0) {
|
photoPath = chat.photo.photo_small;
|
||||||
photoPath = user.photo.photo_small;
|
}
|
||||||
|
} else {
|
||||||
|
if (user.photo != null && user.photo.photo_small != null && user.photo.photo_small.volume_id != 0 && user.photo.photo_small.local_id != 0) {
|
||||||
|
photoPath = user.photo.photo_small;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -436,7 +484,7 @@ public class NotificationsController {
|
||||||
|
|
||||||
String name = null;
|
String name = null;
|
||||||
boolean replace = true;
|
boolean replace = true;
|
||||||
if ((int)dialog_id == 0 || pushDialogs.size() > 1) {
|
if ((int)dialog_id == 0 || pushDialogs.size() > 1 || AndroidUtilities.needShowPasscode(false) || UserConfig.isWaitingForPasscodeEnter) {
|
||||||
name = LocaleController.getString("AppName", R.string.AppName);
|
name = LocaleController.getString("AppName", R.string.AppName);
|
||||||
replace = false;
|
replace = false;
|
||||||
} else {
|
} else {
|
||||||
|
@ -451,7 +499,7 @@ public class NotificationsController {
|
||||||
if (pushDialogs.size() == 1) {
|
if (pushDialogs.size() == 1) {
|
||||||
detailText = LocaleController.formatPluralString("NewMessages", total_unread_count);
|
detailText = LocaleController.formatPluralString("NewMessages", total_unread_count);
|
||||||
} else {
|
} else {
|
||||||
detailText = LocaleController.formatString("NotificationMessagesPeopleDisplayOrder", R.string.NotificationMessagesPeopleDisplayOrder, LocaleController.formatPluralString("NewMessages", total_unread_count), LocaleController.formatPluralString("FromContacts", pushDialogs.size()));
|
detailText = LocaleController.formatString("NotificationMessagesPeopleDisplayOrder", R.string.NotificationMessagesPeopleDisplayOrder, LocaleController.formatPluralString("NewMessages", total_unread_count), LocaleController.formatPluralString("FromChats", pushDialogs.size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(ApplicationLoader.applicationContext)
|
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(ApplicationLoader.applicationContext)
|
||||||
|
@ -608,7 +656,7 @@ public class NotificationsController {
|
||||||
|
|
||||||
for (long dialog_id : sortedDialogs) {
|
for (long dialog_id : sortedDialogs) {
|
||||||
ArrayList<MessageObject> messageObjects = messagesByDialogs.get(dialog_id);
|
ArrayList<MessageObject> messageObjects = messagesByDialogs.get(dialog_id);
|
||||||
int max_id = messageObjects.get(0).messageOwner.id;
|
int max_id = messageObjects.get(0).getId();
|
||||||
TLRPC.Chat chat = null;
|
TLRPC.Chat chat = null;
|
||||||
TLRPC.User user = null;
|
TLRPC.User user = null;
|
||||||
String name = null;
|
String name = null;
|
||||||
|
@ -730,19 +778,21 @@ public class NotificationsController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void processReadMessages(ArrayList<Integer> readMessages, long dialog_id, int max_date, int max_id, boolean isPopup) {
|
public void processReadMessages(HashMap<Integer, Integer> inbox, long dialog_id, int max_date, int max_id, boolean isPopup) {
|
||||||
int oldCount = popupMessages.size();
|
int oldCount = popupMessages.size();
|
||||||
int oldCount2 = pushMessages.size();
|
if (inbox != null) {
|
||||||
if (readMessages != null) {
|
for (HashMap.Entry<Integer, Integer> entry : inbox.entrySet()) {
|
||||||
for (Integer id : readMessages) {
|
for (int a = 0; a < pushMessages.size(); a++) {
|
||||||
MessageObject messageObject = pushMessagesDict.get(id);
|
MessageObject messageObject = pushMessages.get(a);
|
||||||
if (messageObject != null) {
|
if (messageObject.getDialogId() == entry.getKey() && messageObject.getId() <= entry.getValue()) {
|
||||||
if (isPersonalMessage(messageObject)) {
|
if (isPersonalMessage(messageObject)) {
|
||||||
personal_count--;
|
personal_count--;
|
||||||
|
}
|
||||||
|
popupMessages.remove(messageObject);
|
||||||
|
pushMessagesDict.remove(messageObject.getId());
|
||||||
|
pushMessages.remove(a);
|
||||||
|
a--;
|
||||||
}
|
}
|
||||||
pushMessages.remove(messageObject);
|
|
||||||
popupMessages.remove(messageObject);
|
|
||||||
pushMessagesDict.remove(id);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -757,11 +807,11 @@ public class NotificationsController {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!isPopup) {
|
if (!isPopup) {
|
||||||
if (messageObject.messageOwner.id <= max_id || max_id < 0) {
|
if (messageObject.getId() <= max_id || max_id < 0) {
|
||||||
remove = true;
|
remove = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (messageObject.messageOwner.id == max_id || max_id < 0) {
|
if (messageObject.getId() == max_id || max_id < 0) {
|
||||||
remove = true;
|
remove = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -772,7 +822,7 @@ public class NotificationsController {
|
||||||
}
|
}
|
||||||
pushMessages.remove(a);
|
pushMessages.remove(a);
|
||||||
popupMessages.remove(messageObject);
|
popupMessages.remove(messageObject);
|
||||||
pushMessagesDict.remove(messageObject.messageOwner.id);
|
pushMessagesDict.remove(messageObject.getId());
|
||||||
a--;
|
a--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -783,6 +833,126 @@ public class NotificationsController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void playInChatSound() {
|
||||||
|
if (!inChatSoundEnabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
if (audioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
FileLog.e("tmessages", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Context.MODE_PRIVATE);
|
||||||
|
int notify_override = preferences.getInt("notify2_" + openned_dialog_id, 0);
|
||||||
|
if (notify_override == 3) {
|
||||||
|
int mute_until = preferences.getInt("notifyuntil_" + openned_dialog_id, 0);
|
||||||
|
if (mute_until >= ConnectionsManager.getInstance().getCurrentTime()) {
|
||||||
|
notify_override = 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (notify_override == 2) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
notificationsQueue.postRunnable(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (lastSoundPlay > System.currentTimeMillis() - 500) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
if (mediaPlayerIn == null) {
|
||||||
|
AssetFileDescriptor assetFileDescriptor = ApplicationLoader.applicationContext.getResources().openRawResourceFd(R.raw.sound_in);
|
||||||
|
if (assetFileDescriptor != null) {
|
||||||
|
mediaPlayerIn = new MediaPlayer();
|
||||||
|
mediaPlayerIn.setAudioStreamType(AudioManager.STREAM_SYSTEM);
|
||||||
|
mediaPlayerIn.setDataSource(assetFileDescriptor.getFileDescriptor(), assetFileDescriptor.getStartOffset(), assetFileDescriptor.getLength());
|
||||||
|
mediaPlayerIn.setLooping(false);
|
||||||
|
assetFileDescriptor.close();
|
||||||
|
mediaPlayerIn.prepare();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mediaPlayerIn.start();
|
||||||
|
} catch (Exception e) {
|
||||||
|
FileLog.e("tmessages", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
/*String choosenSoundPath = null;
|
||||||
|
String defaultPath = Settings.System.DEFAULT_NOTIFICATION_URI.getPath();
|
||||||
|
|
||||||
|
choosenSoundPath = preferences.getString("sound_path_" + openned_dialog_id, null);
|
||||||
|
boolean isChat = (int)(openned_dialog_id) < 0;
|
||||||
|
if (isChat) {
|
||||||
|
if (choosenSoundPath != null && choosenSoundPath.equals(defaultPath)) {
|
||||||
|
choosenSoundPath = null;
|
||||||
|
} else if (choosenSoundPath == null) {
|
||||||
|
choosenSoundPath = preferences.getString("GroupSoundPath", defaultPath);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (choosenSoundPath != null && choosenSoundPath.equals(defaultPath)) {
|
||||||
|
choosenSoundPath = null;
|
||||||
|
} else if (choosenSoundPath == null) {
|
||||||
|
choosenSoundPath = preferences.getString("GlobalSoundPath", defaultPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (choosenSoundPath != null && !choosenSoundPath.equals("NoSound")) {
|
||||||
|
if (lastMediaPlayerUri == null || !choosenSoundPath.equals(lastMediaPlayerUri)) {
|
||||||
|
lastMediaPlayerUri = choosenSoundPath;
|
||||||
|
mediaPlayer.reset();
|
||||||
|
mediaPlayer.setAudioStreamType(AudioManager.STREAM_NOTIFICATION);
|
||||||
|
if (choosenSoundPath.equals(defaultPath)) {
|
||||||
|
mediaPlayer.setDataSource(ApplicationLoader.applicationContext, Settings.System.DEFAULT_NOTIFICATION_URI);
|
||||||
|
} else {
|
||||||
|
mediaPlayer.setDataSource(ApplicationLoader.applicationContext, Uri.parse(choosenSoundPath));
|
||||||
|
}
|
||||||
|
mediaPlayer.prepare();
|
||||||
|
}
|
||||||
|
mediaPlayer.start();
|
||||||
|
}*/
|
||||||
|
} catch (Exception e) {
|
||||||
|
FileLog.e("tmessages", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void playOutChatSound() {
|
||||||
|
if (!inChatSoundEnabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
if (audioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
FileLog.e("tmessages", e);
|
||||||
|
}
|
||||||
|
notificationsQueue.postRunnable(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
if (mediaPlayerOut == null) {
|
||||||
|
AssetFileDescriptor assetFileDescriptor = ApplicationLoader.applicationContext.getResources().openRawResourceFd(R.raw.sound_out);
|
||||||
|
if (assetFileDescriptor != null) {
|
||||||
|
mediaPlayerOut = new MediaPlayer();
|
||||||
|
mediaPlayerOut.setAudioStreamType(AudioManager.STREAM_SYSTEM);
|
||||||
|
mediaPlayerOut.setDataSource(assetFileDescriptor.getFileDescriptor(), assetFileDescriptor.getStartOffset(), assetFileDescriptor.getLength());
|
||||||
|
mediaPlayerOut.setLooping(false);
|
||||||
|
assetFileDescriptor.close();
|
||||||
|
mediaPlayerOut.prepare();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mediaPlayerOut.start();
|
||||||
|
} catch (Exception e) {
|
||||||
|
FileLog.e("tmessages", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public void processNewMessages(ArrayList<MessageObject> messageObjects, boolean isLast) {
|
public void processNewMessages(ArrayList<MessageObject> messageObjects, boolean isLast) {
|
||||||
if (messageObjects.isEmpty()) {
|
if (messageObjects.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
|
@ -795,13 +965,18 @@ public class NotificationsController {
|
||||||
int popup = 0;
|
int popup = 0;
|
||||||
|
|
||||||
for (MessageObject messageObject : messageObjects) {
|
for (MessageObject messageObject : messageObjects) {
|
||||||
if (pushMessagesDict.containsKey(messageObject.messageOwner.id)) {
|
if (pushMessagesDict.containsKey(messageObject.getId())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
long dialog_id = messageObject.getDialogId();
|
long dialog_id = messageObject.getDialogId();
|
||||||
|
long original_dialog_id = dialog_id;
|
||||||
if (dialog_id == openned_dialog_id && ApplicationLoader.isScreenOn) {
|
if (dialog_id == openned_dialog_id && ApplicationLoader.isScreenOn) {
|
||||||
|
playInChatSound();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if ((messageObject.messageOwner.flags & TLRPC.MESSAGE_FLAG_MENTION) != 0) {
|
||||||
|
dialog_id = messageObject.messageOwner.from_id;
|
||||||
|
}
|
||||||
if (isPersonalMessage(messageObject)) {
|
if (isPersonalMessage(messageObject)) {
|
||||||
personal_count++;
|
personal_count++;
|
||||||
}
|
}
|
||||||
|
@ -826,7 +1001,10 @@ public class NotificationsController {
|
||||||
popupMessages.add(0, messageObject);
|
popupMessages.add(0, messageObject);
|
||||||
}
|
}
|
||||||
pushMessages.add(0, messageObject);
|
pushMessages.add(0, messageObject);
|
||||||
pushMessagesDict.put(messageObject.messageOwner.id, messageObject);
|
pushMessagesDict.put(messageObject.getId(), messageObject);
|
||||||
|
if (original_dialog_id != dialog_id) {
|
||||||
|
pushDialogsOverrideMention.put(original_dialog_id, 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -834,7 +1012,7 @@ public class NotificationsController {
|
||||||
notifyCheck = isLast;
|
notifyCheck = isLast;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!popupMessages.isEmpty() && oldCount != popupMessages.size()) {
|
if (!popupMessages.isEmpty() && oldCount != popupMessages.size() && !AndroidUtilities.needShowPasscode(false) && !UserConfig.isWaitingForPasscodeEnter) {
|
||||||
if (ApplicationLoader.mainInterfacePaused || !ApplicationLoader.isScreenOn) {
|
if (ApplicationLoader.mainInterfacePaused || !ApplicationLoader.isScreenOn) {
|
||||||
MessageObject messageObject = messageObjects.get(0);
|
MessageObject messageObject = messageObjects.get(0);
|
||||||
if (popup == 3 || popup == 1 && ApplicationLoader.isScreenOn || popup == 2 && !ApplicationLoader.isScreenOn) {
|
if (popup == 3 || popup == 1 && ApplicationLoader.isScreenOn || popup == 2 && !ApplicationLoader.isScreenOn) {
|
||||||
|
@ -859,6 +1037,13 @@ public class NotificationsController {
|
||||||
notify_override = 2;
|
notify_override = 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (notifyCheck) {
|
||||||
|
Integer override = pushDialogsOverrideMention.get(dialog_id);
|
||||||
|
if (override != null && override == 1) {
|
||||||
|
pushDialogsOverrideMention.put(dialog_id, 0);
|
||||||
|
notify_override = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
boolean canAddValue = !(notify_override == 2 || (!preferences.getBoolean("EnableAll", true) || ((int)dialog_id < 0) && !preferences.getBoolean("EnableGroup", true)) && notify_override == 0);
|
boolean canAddValue = !(notify_override == 2 || (!preferences.getBoolean("EnableAll", true) || ((int)dialog_id < 0) && !preferences.getBoolean("EnableGroup", true)) && notify_override == 0);
|
||||||
|
|
||||||
Integer currentCount = pushDialogs.get(dialog_id);
|
Integer currentCount = pushDialogs.get(dialog_id);
|
||||||
|
@ -876,6 +1061,7 @@ public class NotificationsController {
|
||||||
}
|
}
|
||||||
if (newCount == 0) {
|
if (newCount == 0) {
|
||||||
pushDialogs.remove(dialog_id);
|
pushDialogs.remove(dialog_id);
|
||||||
|
pushDialogsOverrideMention.remove(dialog_id);
|
||||||
for (int a = 0; a < pushMessages.size(); a++) {
|
for (int a = 0; a < pushMessages.size(); a++) {
|
||||||
MessageObject messageObject = pushMessages.get(a);
|
MessageObject messageObject = pushMessages.get(a);
|
||||||
if (messageObject.getDialogId() == dialog_id) {
|
if (messageObject.getDialogId() == dialog_id) {
|
||||||
|
@ -884,7 +1070,7 @@ public class NotificationsController {
|
||||||
}
|
}
|
||||||
pushMessages.remove(a);
|
pushMessages.remove(a);
|
||||||
a--;
|
a--;
|
||||||
pushMessagesDict.remove(messageObject.messageOwner.id);
|
pushMessagesDict.remove(messageObject.getId());
|
||||||
popupMessages.remove(messageObject);
|
popupMessages.remove(messageObject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -923,27 +1109,6 @@ public class NotificationsController {
|
||||||
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Context.MODE_PRIVATE);
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Context.MODE_PRIVATE);
|
||||||
HashMap<Long, Boolean> settingsCache = new HashMap<>();
|
HashMap<Long, Boolean> settingsCache = new HashMap<>();
|
||||||
|
|
||||||
for (HashMap.Entry<Long, Integer> entry : dialogs.entrySet()) {
|
|
||||||
long dialog_id = entry.getKey();
|
|
||||||
Boolean value = settingsCache.get(dialog_id);
|
|
||||||
if (value == null) {
|
|
||||||
int notify_override = preferences.getInt("notify2_" + dialog_id, 0);
|
|
||||||
if (notify_override == 3) {
|
|
||||||
int mute_until = preferences.getInt("notifyuntil_" + dialog_id, 0);
|
|
||||||
if (mute_until >= ConnectionsManager.getInstance().getCurrentTime()) {
|
|
||||||
notify_override = 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
value = !(notify_override == 2 || (!preferences.getBoolean("EnableAll", true) || ((int) dialog_id < 0) && !preferences.getBoolean("EnableGroup", true)) && notify_override == 0);
|
|
||||||
settingsCache.put(dialog_id, value);
|
|
||||||
}
|
|
||||||
if (!value) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
int count = entry.getValue();
|
|
||||||
pushDialogs.put(dialog_id, count);
|
|
||||||
total_unread_count += count;
|
|
||||||
}
|
|
||||||
if (messages != null) {
|
if (messages != null) {
|
||||||
for (TLRPC.Message message : messages) {
|
for (TLRPC.Message message : messages) {
|
||||||
if (pushMessagesDict.containsKey(message.id)) {
|
if (pushMessagesDict.containsKey(message.id)) {
|
||||||
|
@ -954,6 +1119,10 @@ public class NotificationsController {
|
||||||
personal_count++;
|
personal_count++;
|
||||||
}
|
}
|
||||||
long dialog_id = messageObject.getDialogId();
|
long dialog_id = messageObject.getDialogId();
|
||||||
|
long original_dialog_id = dialog_id;
|
||||||
|
if ((messageObject.messageOwner.flags & TLRPC.MESSAGE_FLAG_MENTION) != 0) {
|
||||||
|
dialog_id = messageObject.messageOwner.from_id;
|
||||||
|
}
|
||||||
Boolean value = settingsCache.get(dialog_id);
|
Boolean value = settingsCache.get(dialog_id);
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
int notify_override = preferences.getInt("notify2_" + dialog_id, 0);
|
int notify_override = preferences.getInt("notify2_" + dialog_id, 0);
|
||||||
|
@ -969,10 +1138,39 @@ public class NotificationsController {
|
||||||
if (!value || dialog_id == openned_dialog_id && ApplicationLoader.isScreenOn) {
|
if (!value || dialog_id == openned_dialog_id && ApplicationLoader.isScreenOn) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
pushMessagesDict.put(messageObject.messageOwner.id, messageObject);
|
pushMessagesDict.put(messageObject.getId(), messageObject);
|
||||||
pushMessages.add(0, messageObject);
|
pushMessages.add(0, messageObject);
|
||||||
|
if (original_dialog_id != dialog_id) {
|
||||||
|
pushDialogsOverrideMention.put(original_dialog_id, 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for (HashMap.Entry<Long, Integer> entry : dialogs.entrySet()) {
|
||||||
|
long dialog_id = entry.getKey();
|
||||||
|
Boolean value = settingsCache.get(dialog_id);
|
||||||
|
if (value == null) {
|
||||||
|
int notify_override = preferences.getInt("notify2_" + dialog_id, 0);
|
||||||
|
if (notify_override == 3) {
|
||||||
|
int mute_until = preferences.getInt("notifyuntil_" + dialog_id, 0);
|
||||||
|
if (mute_until >= ConnectionsManager.getInstance().getCurrentTime()) {
|
||||||
|
notify_override = 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Integer override = pushDialogsOverrideMention.get(dialog_id);
|
||||||
|
if (override != null && override == 1) {
|
||||||
|
pushDialogsOverrideMention.put(dialog_id, 0);
|
||||||
|
notify_override = 1;
|
||||||
|
}
|
||||||
|
value = !(notify_override == 2 || (!preferences.getBoolean("EnableAll", true) || ((int) dialog_id < 0) && !preferences.getBoolean("EnableGroup", true)) && notify_override == 0);
|
||||||
|
settingsCache.put(dialog_id, value);
|
||||||
|
}
|
||||||
|
if (!value) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
int count = entry.getValue();
|
||||||
|
pushDialogs.put(dialog_id, count);
|
||||||
|
total_unread_count += count;
|
||||||
|
}
|
||||||
if (total_unread_count == 0) {
|
if (total_unread_count == 0) {
|
||||||
popupMessages.clear();
|
popupMessages.clear();
|
||||||
NotificationCenter.getInstance().postNotificationName(NotificationCenter.pushMessagesUpdated);
|
NotificationCenter.getInstance().postNotificationName(NotificationCenter.pushMessagesUpdated);
|
||||||
|
@ -988,20 +1186,33 @@ public class NotificationsController {
|
||||||
setBadge(ApplicationLoader.applicationContext, enabled ? total_unread_count : 0);
|
setBadge(ApplicationLoader.applicationContext, enabled ? total_unread_count : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setBadge(Context context, int count) {
|
private void setBadge(final Context context, final int count) {
|
||||||
try {
|
notificationsQueue.postRunnable(new Runnable() {
|
||||||
String launcherClassName = getLauncherClassName(context);
|
@Override
|
||||||
if (launcherClassName == null) {
|
public void run() {
|
||||||
return;
|
try {
|
||||||
|
ContentValues cv = new ContentValues();
|
||||||
|
cv.put("tag", "org.telegram.messenger/org.telegram.ui.LaunchActivity");
|
||||||
|
cv.put("count", count);
|
||||||
|
context.getContentResolver().insert(Uri.parse("content://com.teslacoilsw.notifier/unread_count"), cv);
|
||||||
|
} catch (Throwable e) {
|
||||||
|
//ignore
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
String launcherClassName = getLauncherClassName(context);
|
||||||
|
if (launcherClassName == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Intent intent = new Intent("android.intent.action.BADGE_COUNT_UPDATE");
|
||||||
|
intent.putExtra("badge_count", count);
|
||||||
|
intent.putExtra("badge_count_package_name", context.getPackageName());
|
||||||
|
intent.putExtra("badge_count_class_name", launcherClassName);
|
||||||
|
context.sendBroadcast(intent);
|
||||||
|
} catch (Throwable e) {
|
||||||
|
FileLog.e("tmessages", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Intent intent = new Intent("android.intent.action.BADGE_COUNT_UPDATE");
|
});
|
||||||
intent.putExtra("badge_count", count);
|
|
||||||
intent.putExtra("badge_count_package_name", context.getPackageName());
|
|
||||||
intent.putExtra("badge_count_class_name", launcherClassName);
|
|
||||||
context.sendBroadcast(intent);
|
|
||||||
} catch (Throwable e) {
|
|
||||||
FileLog.e("tmessages", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getLauncherClassName(Context context) {
|
public static String getLauncherClassName(Context context) {
|
||||||
|
|
|
@ -28,5 +28,6 @@ public class ScreenReceiver extends BroadcastReceiver {
|
||||||
ConnectionsManager.getInstance().setAppPaused(false, true);
|
ConnectionsManager.getInstance().setAppPaused(false, true);
|
||||||
ApplicationLoader.isScreenOn = true;
|
ApplicationLoader.isScreenOn = true;
|
||||||
}
|
}
|
||||||
|
NotificationCenter.getInstance().postNotificationName(NotificationCenter.screenStateChanged);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,7 +119,7 @@ public class SecretChatHelper {
|
||||||
reqSend = new TLRPC.TL_decryptedMessageService();
|
reqSend = new TLRPC.TL_decryptedMessageService();
|
||||||
} else {
|
} else {
|
||||||
reqSend = new TLRPC.TL_decryptedMessageService_old();
|
reqSend = new TLRPC.TL_decryptedMessageService_old();
|
||||||
reqSend.random_bytes = new byte[Math.max(1, (int) Math.ceil(Utilities.random.nextDouble() * 16))];
|
reqSend.random_bytes = new byte[15];
|
||||||
Utilities.random.nextBytes(reqSend.random_bytes);
|
Utilities.random.nextBytes(reqSend.random_bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -224,7 +224,7 @@ public class SecretChatHelper {
|
||||||
reqSend = new TLRPC.TL_decryptedMessageService();
|
reqSend = new TLRPC.TL_decryptedMessageService();
|
||||||
} else {
|
} else {
|
||||||
reqSend = new TLRPC.TL_decryptedMessageService_old();
|
reqSend = new TLRPC.TL_decryptedMessageService_old();
|
||||||
reqSend.random_bytes = new byte[Math.max(1, (int) Math.ceil(Utilities.random.nextDouble() * 16))];
|
reqSend.random_bytes = new byte[15];
|
||||||
Utilities.random.nextBytes(reqSend.random_bytes);
|
Utilities.random.nextBytes(reqSend.random_bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -252,7 +252,7 @@ public class SecretChatHelper {
|
||||||
reqSend = new TLRPC.TL_decryptedMessageService();
|
reqSend = new TLRPC.TL_decryptedMessageService();
|
||||||
} else {
|
} else {
|
||||||
reqSend = new TLRPC.TL_decryptedMessageService_old();
|
reqSend = new TLRPC.TL_decryptedMessageService_old();
|
||||||
reqSend.random_bytes = new byte[Math.max(1, (int) Math.ceil(Utilities.random.nextDouble() * 16))];
|
reqSend.random_bytes = new byte[15];
|
||||||
Utilities.random.nextBytes(reqSend.random_bytes);
|
Utilities.random.nextBytes(reqSend.random_bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -283,7 +283,7 @@ public class SecretChatHelper {
|
||||||
reqSend = new TLRPC.TL_decryptedMessageService();
|
reqSend = new TLRPC.TL_decryptedMessageService();
|
||||||
} else {
|
} else {
|
||||||
reqSend = new TLRPC.TL_decryptedMessageService_old();
|
reqSend = new TLRPC.TL_decryptedMessageService_old();
|
||||||
reqSend.random_bytes = new byte[Math.max(1, (int) Math.ceil(Utilities.random.nextDouble() * 16))];
|
reqSend.random_bytes = new byte[15];
|
||||||
Utilities.random.nextBytes(reqSend.random_bytes);
|
Utilities.random.nextBytes(reqSend.random_bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -312,7 +312,7 @@ public class SecretChatHelper {
|
||||||
reqSend = new TLRPC.TL_decryptedMessageService();
|
reqSend = new TLRPC.TL_decryptedMessageService();
|
||||||
} else {
|
} else {
|
||||||
reqSend = new TLRPC.TL_decryptedMessageService_old();
|
reqSend = new TLRPC.TL_decryptedMessageService_old();
|
||||||
reqSend.random_bytes = new byte[Math.max(1, (int) Math.ceil(Utilities.random.nextDouble() * 16))];
|
reqSend.random_bytes = new byte[15];
|
||||||
Utilities.random.nextBytes(reqSend.random_bytes);
|
Utilities.random.nextBytes(reqSend.random_bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -343,7 +343,7 @@ public class SecretChatHelper {
|
||||||
reqSend = new TLRPC.TL_decryptedMessageService();
|
reqSend = new TLRPC.TL_decryptedMessageService();
|
||||||
} else {
|
} else {
|
||||||
reqSend = new TLRPC.TL_decryptedMessageService_old();
|
reqSend = new TLRPC.TL_decryptedMessageService_old();
|
||||||
reqSend.random_bytes = new byte[Math.max(1, (int) Math.ceil(Utilities.random.nextDouble() * 16))];
|
reqSend.random_bytes = new byte[15];
|
||||||
Utilities.random.nextBytes(reqSend.random_bytes);
|
Utilities.random.nextBytes(reqSend.random_bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -375,7 +375,7 @@ public class SecretChatHelper {
|
||||||
reqSend = new TLRPC.TL_decryptedMessageService();
|
reqSend = new TLRPC.TL_decryptedMessageService();
|
||||||
} else {
|
} else {
|
||||||
reqSend = new TLRPC.TL_decryptedMessageService_old();
|
reqSend = new TLRPC.TL_decryptedMessageService_old();
|
||||||
reqSend.random_bytes = new byte[Math.max(1, (int) Math.ceil(Utilities.random.nextDouble() * 16))];
|
reqSend.random_bytes = new byte[15];
|
||||||
Utilities.random.nextBytes(reqSend.random_bytes);
|
Utilities.random.nextBytes(reqSend.random_bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -406,7 +406,7 @@ public class SecretChatHelper {
|
||||||
reqSend = new TLRPC.TL_decryptedMessageService();
|
reqSend = new TLRPC.TL_decryptedMessageService();
|
||||||
} else {
|
} else {
|
||||||
reqSend = new TLRPC.TL_decryptedMessageService_old();
|
reqSend = new TLRPC.TL_decryptedMessageService_old();
|
||||||
reqSend.random_bytes = new byte[Math.max(1, (int) Math.ceil(Utilities.random.nextDouble() * 16))];
|
reqSend.random_bytes = new byte[15];
|
||||||
Utilities.random.nextBytes(reqSend.random_bytes);
|
Utilities.random.nextBytes(reqSend.random_bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -436,7 +436,7 @@ public class SecretChatHelper {
|
||||||
reqSend = new TLRPC.TL_decryptedMessageService();
|
reqSend = new TLRPC.TL_decryptedMessageService();
|
||||||
} else {
|
} else {
|
||||||
reqSend = new TLRPC.TL_decryptedMessageService_old();
|
reqSend = new TLRPC.TL_decryptedMessageService_old();
|
||||||
reqSend.random_bytes = new byte[Math.max(1, (int) Math.ceil(Utilities.random.nextDouble() * 16))];
|
reqSend.random_bytes = new byte[15];
|
||||||
Utilities.random.nextBytes(reqSend.random_bytes);
|
Utilities.random.nextBytes(reqSend.random_bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -464,7 +464,7 @@ public class SecretChatHelper {
|
||||||
reqSend = new TLRPC.TL_decryptedMessageService();
|
reqSend = new TLRPC.TL_decryptedMessageService();
|
||||||
} else {
|
} else {
|
||||||
reqSend = new TLRPC.TL_decryptedMessageService_old();
|
reqSend = new TLRPC.TL_decryptedMessageService_old();
|
||||||
reqSend.random_bytes = new byte[Math.max(1, (int) Math.ceil(Utilities.random.nextDouble() * 16))];
|
reqSend.random_bytes = new byte[15];
|
||||||
Utilities.random.nextBytes(reqSend.random_bytes);
|
Utilities.random.nextBytes(reqSend.random_bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -500,7 +500,7 @@ public class SecretChatHelper {
|
||||||
reqSend = new TLRPC.TL_decryptedMessageService();
|
reqSend = new TLRPC.TL_decryptedMessageService();
|
||||||
} else {
|
} else {
|
||||||
reqSend = new TLRPC.TL_decryptedMessageService_old();
|
reqSend = new TLRPC.TL_decryptedMessageService_old();
|
||||||
reqSend.random_bytes = new byte[Math.max(1, (int) Math.ceil(Utilities.random.nextDouble() * 16))];
|
reqSend.random_bytes = new byte[15];
|
||||||
Utilities.random.nextBytes(reqSend.random_bytes);
|
Utilities.random.nextBytes(reqSend.random_bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -659,7 +659,7 @@ public class SecretChatHelper {
|
||||||
int myLayer = Math.max(17, AndroidUtilities.getMyLayerVersion(chat.layer));
|
int myLayer = Math.max(17, AndroidUtilities.getMyLayerVersion(chat.layer));
|
||||||
layer.layer = Math.min(myLayer, AndroidUtilities.getPeerLayerVersion(chat.layer));
|
layer.layer = Math.min(myLayer, AndroidUtilities.getPeerLayerVersion(chat.layer));
|
||||||
layer.message = req;
|
layer.message = req;
|
||||||
layer.random_bytes = new byte[Math.max(1, (int) Math.ceil(Utilities.random.nextDouble() * 16))];
|
layer.random_bytes = new byte[15];
|
||||||
Utilities.random.nextBytes(layer.random_bytes);
|
Utilities.random.nextBytes(layer.random_bytes);
|
||||||
toEncryptObject = layer;
|
toEncryptObject = layer;
|
||||||
|
|
||||||
|
@ -795,7 +795,7 @@ public class SecretChatHelper {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
newMsgObj.send_state = MessageObject.MESSAGE_SEND_STATE_SENT;
|
newMsgObj.send_state = MessageObject.MESSAGE_SEND_STATE_SENT;
|
||||||
NotificationCenter.getInstance().postNotificationName(NotificationCenter.messageReceivedByServer, newMsgObj.id, newMsgObj.id, newMsgObj);
|
NotificationCenter.getInstance().postNotificationName(NotificationCenter.messageReceivedByServer, newMsgObj.id, newMsgObj.id, newMsgObj, false);
|
||||||
SendMessagesHelper.getInstance().processSentMessage(newMsgObj.id);
|
SendMessagesHelper.getInstance().processSentMessage(newMsgObj.id);
|
||||||
if (newMsgObj.media instanceof TLRPC.TL_messageMediaVideo) {
|
if (newMsgObj.media instanceof TLRPC.TL_messageMediaVideo) {
|
||||||
SendMessagesHelper.getInstance().stopVideoService(attachPath);
|
SendMessagesHelper.getInstance().stopVideoService(attachPath);
|
||||||
|
@ -1072,8 +1072,8 @@ public class SecretChatHelper {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
MessagesStorage.getInstance().deleteDialog(did, true);
|
MessagesStorage.getInstance().deleteDialog(did, true);
|
||||||
NotificationCenter.getInstance().postNotificationName(NotificationCenter.removeAllMessagesFromDialog, did);
|
|
||||||
NotificationCenter.getInstance().postNotificationName(NotificationCenter.dialogsNeedReload);
|
NotificationCenter.getInstance().postNotificationName(NotificationCenter.dialogsNeedReload);
|
||||||
|
NotificationCenter.getInstance().postNotificationName(NotificationCenter.removeAllMessagesFromDialog, did);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return null;
|
return null;
|
||||||
|
@ -1104,10 +1104,7 @@ public class SecretChatHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] salt = new byte[256];
|
byte[] salt = new byte[256];
|
||||||
for (int a = 0; a < 256; a++) {
|
Utilities.random.nextBytes(salt);
|
||||||
salt[a] = (byte) (Utilities.random.nextDouble() * 256);
|
|
||||||
}
|
|
||||||
|
|
||||||
BigInteger p = new BigInteger(1, MessagesStorage.secretPBytes);
|
BigInteger p = new BigInteger(1, MessagesStorage.secretPBytes);
|
||||||
BigInteger g_b = BigInteger.valueOf(MessagesStorage.secretG);
|
BigInteger g_b = BigInteger.valueOf(MessagesStorage.secretG);
|
||||||
g_b = g_b.modPow(new BigInteger(1, salt), p);
|
g_b = g_b.modPow(new BigInteger(1, salt), p);
|
||||||
|
@ -1409,9 +1406,7 @@ public class SecretChatHelper {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final byte[] salt = new byte[256];
|
final byte[] salt = new byte[256];
|
||||||
for (int a = 0; a < 256; a++) {
|
Utilities.random.nextBytes(salt);
|
||||||
salt[a] = (byte) (Utilities.random.nextDouble() * 256);
|
|
||||||
}
|
|
||||||
|
|
||||||
BigInteger i_g_a = BigInteger.valueOf(MessagesStorage.secretG);
|
BigInteger i_g_a = BigInteger.valueOf(MessagesStorage.secretG);
|
||||||
i_g_a = i_g_a.modPow(new BigInteger(1, salt), new BigInteger(1, MessagesStorage.secretPBytes));
|
i_g_a = i_g_a.modPow(new BigInteger(1, salt), new BigInteger(1, MessagesStorage.secretPBytes));
|
||||||
|
@ -1616,7 +1611,7 @@ public class SecretChatHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startSecretChat(final Context context, final TLRPC.User user) {
|
public void startSecretChat(final Context context, final TLRPC.User user) {
|
||||||
if (user == null) {
|
if (user == null || context == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
startingSecretChat = true;
|
startingSecretChat = true;
|
||||||
|
@ -1777,6 +1772,10 @@ public class SecretChatHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
progressDialog.show();
|
try {
|
||||||
|
progressDialog.show();
|
||||||
|
} catch (Exception e) {
|
||||||
|
//don't promt
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -51,11 +51,11 @@ public class SmsListener extends BroadcastReceiver {
|
||||||
NotificationCenter.getInstance().postNotificationName(NotificationCenter.didReceiveSmsCode, matcher.group(0));
|
NotificationCenter.getInstance().postNotificationName(NotificationCenter.didReceiveSmsCode, matcher.group(0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Throwable e) {
|
||||||
FileLog.e("tmessages", e);
|
FileLog.e("tmessages", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch(Exception e) {
|
} catch(Throwable e) {
|
||||||
FileLog.e("tmessages", e);
|
FileLog.e("tmessages", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ public class WearReplyReceiver extends BroadcastReceiver {
|
||||||
if (dialog_id == 0 || max_id == 0) {
|
if (dialog_id == 0 || max_id == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SendMessagesHelper.getInstance().sendMessage(text.toString(), dialog_id);
|
SendMessagesHelper.getInstance().sendMessage(text.toString(), dialog_id, null, null, true);
|
||||||
MessagesController.getInstance().markDialogAsRead(dialog_id, max_id, max_id, 0, 0, true, false);
|
MessagesController.getInstance().markDialogAsRead(dialog_id, max_id, max_id, 0, 0, true, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,185 @@
|
||||||
|
/*
|
||||||
|
* This is the source code of Telegram for Android v. 2.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-2015.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.telegram.android.query;
|
||||||
|
|
||||||
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
import org.telegram.SQLite.SQLiteCursor;
|
||||||
|
import org.telegram.SQLite.SQLitePreparedStatement;
|
||||||
|
import org.telegram.android.AndroidUtilities;
|
||||||
|
import org.telegram.android.ImageLoader;
|
||||||
|
import org.telegram.android.MessageObject;
|
||||||
|
import org.telegram.android.MessagesStorage;
|
||||||
|
import org.telegram.android.NotificationCenter;
|
||||||
|
import org.telegram.messenger.ByteBufferDesc;
|
||||||
|
import org.telegram.messenger.ConnectionsManager;
|
||||||
|
import org.telegram.messenger.FileLog;
|
||||||
|
import org.telegram.messenger.RPCRequest;
|
||||||
|
import org.telegram.messenger.TLClassStore;
|
||||||
|
import org.telegram.messenger.TLObject;
|
||||||
|
import org.telegram.messenger.TLRPC;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
public class ReplyMessageQuery {
|
||||||
|
|
||||||
|
public static void loadReplyMessagesForMessages(final ArrayList<MessageObject> messages, final long dialog_id) {
|
||||||
|
final ArrayList<Integer> replyMessages = new ArrayList<>();
|
||||||
|
final HashMap<Integer, ArrayList<MessageObject>> replyMessageOwners = new HashMap<>();
|
||||||
|
for (MessageObject messageObject : messages) {
|
||||||
|
if (messageObject.getId() > 0 && messageObject.isReply() && messageObject.replyMessageObject == null) {
|
||||||
|
Integer id = messageObject.messageOwner.reply_to_msg_id;
|
||||||
|
ArrayList<MessageObject> messageObjects = replyMessageOwners.get(id);
|
||||||
|
if (messageObjects == null) {
|
||||||
|
messageObjects = new ArrayList<>();
|
||||||
|
replyMessageOwners.put(id, messageObjects);
|
||||||
|
}
|
||||||
|
messageObjects.add(messageObject);
|
||||||
|
if (!replyMessages.contains(id)) {
|
||||||
|
replyMessages.add(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (replyMessages.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
MessagesStorage.getInstance().getStorageQueue().postRunnable(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
final ArrayList<TLRPC.Message> result = new ArrayList<>();
|
||||||
|
final ArrayList<TLRPC.User> users = new ArrayList<>();
|
||||||
|
ArrayList<Integer> loadedUsers = new ArrayList<>();
|
||||||
|
ArrayList<Integer> fromUser = new ArrayList<>();
|
||||||
|
|
||||||
|
SQLiteCursor cursor = MessagesStorage.getInstance().getDatabase().queryFinalized(String.format(Locale.US, "SELECT data, mid, date FROM messages WHERE mid IN(%s)", TextUtils.join(",", replyMessages)));
|
||||||
|
while (cursor.next()) {
|
||||||
|
ByteBufferDesc data = MessagesStorage.getInstance().getBuffersStorage().getFreeBuffer(cursor.byteArrayLength(0));
|
||||||
|
if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
|
||||||
|
TLRPC.Message message = (TLRPC.Message) TLClassStore.Instance().TLdeserialize(data, data.readInt32());
|
||||||
|
message.id = cursor.intValue(1);
|
||||||
|
message.date = cursor.intValue(2);
|
||||||
|
message.dialog_id = dialog_id;
|
||||||
|
fromUser.add(message.from_id);
|
||||||
|
if (message.action != null && message.action.user_id != 0) {
|
||||||
|
fromUser.add(message.action.user_id);
|
||||||
|
}
|
||||||
|
if (message.media != null && message.media.user_id != 0) {
|
||||||
|
fromUser.add(message.media.user_id);
|
||||||
|
}
|
||||||
|
if (message.media != null && message.media.audio != null && message.media.audio.user_id != 0) {
|
||||||
|
fromUser.add(message.media.audio.user_id);
|
||||||
|
}
|
||||||
|
if (message.fwd_from_id != 0) {
|
||||||
|
fromUser.add(message.fwd_from_id);
|
||||||
|
}
|
||||||
|
result.add(message);
|
||||||
|
replyMessages.remove((Integer) message.id);
|
||||||
|
}
|
||||||
|
MessagesStorage.getInstance().getBuffersStorage().reuseFreeBuffer(data);
|
||||||
|
}
|
||||||
|
cursor.dispose();
|
||||||
|
|
||||||
|
StringBuilder usersToLoad = new StringBuilder();
|
||||||
|
for (int uid : fromUser) {
|
||||||
|
if (!loadedUsers.contains(uid)) {
|
||||||
|
if (usersToLoad.length() != 0) {
|
||||||
|
usersToLoad.append(",");
|
||||||
|
}
|
||||||
|
usersToLoad.append(uid);
|
||||||
|
loadedUsers.add(uid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (usersToLoad.length() != 0) {
|
||||||
|
MessagesStorage.getInstance().getUsersInternal(usersToLoad.toString(), users);
|
||||||
|
}
|
||||||
|
broadcastReplyMessages(result, replyMessageOwners, users, dialog_id);
|
||||||
|
|
||||||
|
if (!replyMessages.isEmpty()) {
|
||||||
|
TLRPC.TL_messages_getMessages req = new TLRPC.TL_messages_getMessages();
|
||||||
|
req.id = replyMessages;
|
||||||
|
ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() {
|
||||||
|
@Override
|
||||||
|
public void run(TLObject response, TLRPC.TL_error error) {
|
||||||
|
if (error == null) {
|
||||||
|
TLRPC.messages_Messages messagesRes = (TLRPC.messages_Messages) response;
|
||||||
|
ImageLoader.saveMessagesThumbs(messagesRes.messages);
|
||||||
|
broadcastReplyMessages(messagesRes.messages, replyMessageOwners, messagesRes.users, dialog_id);
|
||||||
|
MessagesStorage.getInstance().putUsersAndChats(messagesRes.users, null, true, true);
|
||||||
|
saveReplyMessages(replyMessageOwners, messagesRes.messages);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
FileLog.e("tmessages", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void saveReplyMessages(final HashMap<Integer, ArrayList<MessageObject>> replyMessageOwners, final ArrayList<TLRPC.Message> result) {
|
||||||
|
MessagesStorage.getInstance().getStorageQueue().postRunnable(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
MessagesStorage.getInstance().getDatabase().beginTransaction();
|
||||||
|
SQLitePreparedStatement state = MessagesStorage.getInstance().getDatabase().executeFast("UPDATE messages SET replydata = ? WHERE mid = ?");
|
||||||
|
for (TLRPC.Message message : result) {
|
||||||
|
ArrayList<MessageObject> messageObjects = replyMessageOwners.get(message.id);
|
||||||
|
if (messageObjects != null) {
|
||||||
|
ByteBufferDesc data = MessagesStorage.getInstance().getBuffersStorage().getFreeBuffer(message.getObjectSize());
|
||||||
|
message.serializeToStream(data);
|
||||||
|
for (MessageObject messageObject : messageObjects) {
|
||||||
|
state.requery();
|
||||||
|
state.bindByteBuffer(1, data.buffer);
|
||||||
|
state.bindInteger(2, messageObject.getId());
|
||||||
|
state.step();
|
||||||
|
}
|
||||||
|
MessagesStorage.getInstance().getBuffersStorage().reuseFreeBuffer(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
state.dispose();
|
||||||
|
MessagesStorage.getInstance().getDatabase().commitTransaction();
|
||||||
|
} catch (Exception e) {
|
||||||
|
FileLog.e("tmessages", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void broadcastReplyMessages(final ArrayList<TLRPC.Message> result, final HashMap<Integer, ArrayList<MessageObject>> replyMessageOwners, ArrayList<TLRPC.User> users, final long dialog_id) {
|
||||||
|
final HashMap<Integer, TLRPC.User> usersHashMap = new HashMap<>();
|
||||||
|
for (TLRPC.User user : users) {
|
||||||
|
usersHashMap.put(user.id, user);
|
||||||
|
}
|
||||||
|
AndroidUtilities.runOnUIThread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
boolean changed = false;
|
||||||
|
for (TLRPC.Message message : result) {
|
||||||
|
ArrayList<MessageObject> arrayList = replyMessageOwners.get(message.id);
|
||||||
|
if (arrayList != null) {
|
||||||
|
MessageObject messageObject = new MessageObject(message, usersHashMap, false);
|
||||||
|
for (MessageObject m : arrayList) {
|
||||||
|
m.replyMessageObject = messageObject;
|
||||||
|
}
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (changed) {
|
||||||
|
NotificationCenter.getInstance().postNotificationName(NotificationCenter.didLoadedReplyMessages, dialog_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -59,7 +59,7 @@ public class MP4Builder {
|
||||||
private long dataOffset = 0;
|
private long dataOffset = 0;
|
||||||
private long writedSinceLastMdat = 0;
|
private long writedSinceLastMdat = 0;
|
||||||
private boolean writeNewMdat = true;
|
private boolean writeNewMdat = true;
|
||||||
private HashMap<Track, long[]> track2SampleSizes = new HashMap<Track, long[]>();
|
private HashMap<Track, long[]> track2SampleSizes = new HashMap<>();
|
||||||
private ByteBuffer sizeBuffer = null;
|
private ByteBuffer sizeBuffer = null;
|
||||||
|
|
||||||
public MP4Builder createMovie(Mp4Movie mp4Movie) throws Exception {
|
public MP4Builder createMovie(Mp4Movie mp4Movie) throws Exception {
|
||||||
|
@ -158,7 +158,7 @@ public class MP4Builder {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected FileTypeBox createFileTypeBox() {
|
protected FileTypeBox createFileTypeBox() {
|
||||||
LinkedList<String> minorBrands = new LinkedList<String>();
|
LinkedList<String> minorBrands = new LinkedList<>();
|
||||||
minorBrands.add("isom");
|
minorBrands.add("isom");
|
||||||
minorBrands.add("3gp4");
|
minorBrands.add("3gp4");
|
||||||
return new FileTypeBox("isom", 0, minorBrands);
|
return new FileTypeBox("isom", 0, minorBrands);
|
||||||
|
@ -237,7 +237,10 @@ public class MP4Builder {
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getTimescale(Mp4Movie mp4Movie) {
|
public long getTimescale(Mp4Movie mp4Movie) {
|
||||||
long timescale = mp4Movie.getTracks().iterator().next().getTimeScale();
|
long timescale = 0;
|
||||||
|
if (!mp4Movie.getTracks().isEmpty()) {
|
||||||
|
timescale = mp4Movie.getTracks().iterator().next().getTimeScale();
|
||||||
|
}
|
||||||
for (Track track : mp4Movie.getTracks()) {
|
for (Track track : mp4Movie.getTracks()) {
|
||||||
timescale = gcd(track.getTimeScale(), timescale);
|
timescale = gcd(track.getTimeScale(), timescale);
|
||||||
}
|
}
|
||||||
|
@ -347,7 +350,7 @@ public class MP4Builder {
|
||||||
|
|
||||||
protected void createStts(Track track, SampleTableBox stbl) {
|
protected void createStts(Track track, SampleTableBox stbl) {
|
||||||
TimeToSampleBox.Entry lastEntry = null;
|
TimeToSampleBox.Entry lastEntry = null;
|
||||||
List<TimeToSampleBox.Entry> entries = new ArrayList<TimeToSampleBox.Entry>();
|
List<TimeToSampleBox.Entry> entries = new ArrayList<>();
|
||||||
|
|
||||||
for (long delta : track.getSampleDurations()) {
|
for (long delta : track.getSampleDurations()) {
|
||||||
if (lastEntry != null && lastEntry.getDelta() == delta) {
|
if (lastEntry != null && lastEntry.getDelta() == delta) {
|
||||||
|
@ -418,7 +421,7 @@ public class MP4Builder {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void createStco(Track track, SampleTableBox stbl) {
|
protected void createStco(Track track, SampleTableBox stbl) {
|
||||||
ArrayList<Long> chunksOffsets = new ArrayList<Long>();
|
ArrayList<Long> chunksOffsets = new ArrayList<>();
|
||||||
long lastOffset = -1;
|
long lastOffset = -1;
|
||||||
for (Sample sample : track.getSamples()) {
|
for (Sample sample : track.getSamples()) {
|
||||||
long offset = sample.getOffset();
|
long offset = sample.getOffset();
|
||||||
|
|
|
@ -28,43 +28,43 @@ public interface Cache {
|
||||||
* @param key Cache key
|
* @param key Cache key
|
||||||
* @return An {@link Entry} or null in the event of a cache miss
|
* @return An {@link Entry} or null in the event of a cache miss
|
||||||
*/
|
*/
|
||||||
public Entry get(String key);
|
Entry get(String key);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds or replaces an entry to the cache.
|
* Adds or replaces an entry to the cache.
|
||||||
* @param key Cache key
|
* @param key Cache key
|
||||||
* @param entry Data to store and metadata for cache coherency, TTL, etc.
|
* @param entry Data to store and metadata for cache coherency, TTL, etc.
|
||||||
*/
|
*/
|
||||||
public void put(String key, Entry entry);
|
void put(String key, Entry entry);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs any potentially long-running actions needed to initialize the cache;
|
* Performs any potentially long-running actions needed to initialize the cache;
|
||||||
* will be called from a worker thread.
|
* will be called from a worker thread.
|
||||||
*/
|
*/
|
||||||
public void initialize();
|
void initialize();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invalidates an entry in the cache.
|
* Invalidates an entry in the cache.
|
||||||
* @param key Cache key
|
* @param key Cache key
|
||||||
* @param fullExpire True to fully expire the entry, false to soft expire
|
* @param fullExpire True to fully expire the entry, false to soft expire
|
||||||
*/
|
*/
|
||||||
public void invalidate(String key, boolean fullExpire);
|
void invalidate(String key, boolean fullExpire);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes an entry from the cache.
|
* Removes an entry from the cache.
|
||||||
* @param key Cache key
|
* @param key Cache key
|
||||||
*/
|
*/
|
||||||
public void remove(String key);
|
void remove(String key);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Empties the cache.
|
* Empties the cache.
|
||||||
*/
|
*/
|
||||||
public void clear();
|
void clear();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Data and metadata for an entry returned by the cache.
|
* Data and metadata for an entry returned by the cache.
|
||||||
*/
|
*/
|
||||||
public static class Entry {
|
class Entry {
|
||||||
/** The data returned from cache. */
|
/** The data returned from cache. */
|
||||||
public byte[] data;
|
public byte[] data;
|
||||||
|
|
||||||
|
|
|
@ -26,5 +26,5 @@ public interface Network {
|
||||||
* @return A {@link NetworkResponse} with data and caching metadata; will never be null
|
* @return A {@link NetworkResponse} with data and caching metadata; will never be null
|
||||||
* @throws VolleyError on errors
|
* @throws VolleyError on errors
|
||||||
*/
|
*/
|
||||||
public NetworkResponse performRequest(Request<?> request) throws VolleyError;
|
NetworkResponse performRequest(Request<?> request) throws VolleyError;
|
||||||
}
|
}
|
||||||
|
|
|
@ -175,7 +175,7 @@ public class RequestQueue {
|
||||||
* {@link RequestQueue#cancelAll(RequestFilter)}.
|
* {@link RequestQueue#cancelAll(RequestFilter)}.
|
||||||
*/
|
*/
|
||||||
public interface RequestFilter {
|
public interface RequestFilter {
|
||||||
public boolean apply(Request<?> request);
|
boolean apply(Request<?> request);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -26,7 +26,7 @@ public class Response<T> {
|
||||||
/** Callback interface for delivering parsed responses. */
|
/** Callback interface for delivering parsed responses. */
|
||||||
public interface Listener<T> {
|
public interface Listener<T> {
|
||||||
/** Called when a response is received. */
|
/** Called when a response is received. */
|
||||||
public void onResponse(T response);
|
void onResponse(T response);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Callback interface for delivering error responses. */
|
/** Callback interface for delivering error responses. */
|
||||||
|
@ -35,7 +35,7 @@ public class Response<T> {
|
||||||
* Callback method that an error has been occurred with the
|
* Callback method that an error has been occurred with the
|
||||||
* provided error code and optional user-readable message.
|
* provided error code and optional user-readable message.
|
||||||
*/
|
*/
|
||||||
public void onErrorResponse(VolleyError error);
|
void onErrorResponse(VolleyError error);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns a successful response containing the parsed result. */
|
/** Returns a successful response containing the parsed result. */
|
||||||
|
|
|
@ -20,16 +20,16 @@ public interface ResponseDelivery {
|
||||||
/**
|
/**
|
||||||
* Parses a response from the network or cache and delivers it.
|
* Parses a response from the network or cache and delivers it.
|
||||||
*/
|
*/
|
||||||
public void postResponse(Request<?> request, Response<?> response);
|
void postResponse(Request<?> request, Response<?> response);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses a response from the network or cache and delivers it. The provided
|
* Parses a response from the network or cache and delivers it. The provided
|
||||||
* Runnable will be executed after delivery.
|
* Runnable will be executed after delivery.
|
||||||
*/
|
*/
|
||||||
public void postResponse(Request<?> request, Response<?> response, Runnable runnable);
|
void postResponse(Request<?> request, Response<?> response, Runnable runnable);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Posts an error for the given request.
|
* Posts an error for the given request.
|
||||||
*/
|
*/
|
||||||
public void postError(Request<?> request, VolleyError error);
|
void postError(Request<?> request, VolleyError error);
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,12 +24,12 @@ public interface RetryPolicy {
|
||||||
/**
|
/**
|
||||||
* Returns the current timeout (used for logging).
|
* Returns the current timeout (used for logging).
|
||||||
*/
|
*/
|
||||||
public int getCurrentTimeout();
|
int getCurrentTimeout();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the current retry count (used for logging).
|
* Returns the current retry count (used for logging).
|
||||||
*/
|
*/
|
||||||
public int getCurrentRetryCount();
|
int getCurrentRetryCount();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepares for the next retry by applying a backoff to the timeout.
|
* Prepares for the next retry by applying a backoff to the timeout.
|
||||||
|
@ -37,5 +37,5 @@ public interface RetryPolicy {
|
||||||
* @throws VolleyError In the event that the retry could not be performed (for example if we
|
* @throws VolleyError In the event that the retry could not be performed (for example if we
|
||||||
* ran out of attempts), the passed in error is thrown.
|
* ran out of attempts), the passed in error is thrown.
|
||||||
*/
|
*/
|
||||||
public void retry(VolleyError error) throws VolleyError;
|
void retry(VolleyError error) throws VolleyError;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,10 +27,10 @@ public interface Authenticator {
|
||||||
*
|
*
|
||||||
* @throws AuthFailureError If authentication did not succeed
|
* @throws AuthFailureError If authentication did not succeed
|
||||||
*/
|
*/
|
||||||
public String getAuthToken() throws AuthFailureError;
|
String getAuthToken() throws AuthFailureError;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invalidates the provided auth token.
|
* Invalidates the provided auth token.
|
||||||
*/
|
*/
|
||||||
public void invalidateAuthToken(String authToken);
|
void invalidateAuthToken(String authToken);
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ public interface HttpStack {
|
||||||
* {@link Request#getHeaders()}
|
* {@link Request#getHeaders()}
|
||||||
* @return the HTTP response
|
* @return the HTTP response
|
||||||
*/
|
*/
|
||||||
public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders)
|
HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders)
|
||||||
throws IOException, AuthFailureError;
|
throws IOException, AuthFailureError;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,7 @@ public class HurlStack implements HttpStack {
|
||||||
* Returns a URL to use instead of the provided one, or null to indicate
|
* Returns a URL to use instead of the provided one, or null to indicate
|
||||||
* this URL should not be used at all.
|
* this URL should not be used at all.
|
||||||
*/
|
*/
|
||||||
public String rewriteUrl(String originalUrl);
|
String rewriteUrl(String originalUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final UrlRewriter mUrlRewriter;
|
private final UrlRewriter mUrlRewriter;
|
||||||
|
|
|
@ -71,8 +71,8 @@ public class ImageLoader {
|
||||||
* must not block. Implementation with an LruCache is recommended.
|
* must not block. Implementation with an LruCache is recommended.
|
||||||
*/
|
*/
|
||||||
public interface ImageCache {
|
public interface ImageCache {
|
||||||
public Bitmap getBitmap(String url);
|
Bitmap getBitmap(String url);
|
||||||
public void putBitmap(String url, Bitmap bitmap);
|
void putBitmap(String url, Bitmap bitmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -138,7 +138,7 @@ public class ImageLoader {
|
||||||
* image loading in order to, for example, run an animation to fade in network loaded
|
* image loading in order to, for example, run an animation to fade in network loaded
|
||||||
* images.
|
* images.
|
||||||
*/
|
*/
|
||||||
public void onResponse(ImageContainer response, boolean isImmediate);
|
void onResponse(ImageContainer response, boolean isImmediate);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
package org.telegram.messenger;
|
package org.telegram.messenger;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
import android.app.AlarmManager;
|
import android.app.AlarmManager;
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
|
@ -19,6 +20,7 @@ import android.content.SharedPreferences;
|
||||||
import android.content.pm.PackageInfo;
|
import android.content.pm.PackageInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
|
import android.graphics.drawable.ColorDrawable;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
@ -38,10 +40,13 @@ import org.telegram.android.LocaleController;
|
||||||
import org.telegram.android.MessagesController;
|
import org.telegram.android.MessagesController;
|
||||||
import org.telegram.android.NativeLoader;
|
import org.telegram.android.NativeLoader;
|
||||||
import org.telegram.android.ScreenReceiver;
|
import org.telegram.android.ScreenReceiver;
|
||||||
|
import org.telegram.ui.Components.ForegroundDetector;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
public class ApplicationLoader extends Application {
|
public class ApplicationLoader extends Application {
|
||||||
|
|
||||||
private GoogleCloudMessaging gcm;
|
private GoogleCloudMessaging gcm;
|
||||||
private AtomicInteger msgId = new AtomicInteger();
|
private AtomicInteger msgId = new AtomicInteger();
|
||||||
private String regid;
|
private String regid;
|
||||||
|
@ -49,15 +54,80 @@ public class ApplicationLoader extends Application {
|
||||||
public static final String PROPERTY_REG_ID = "registration_id";
|
public static final String PROPERTY_REG_ID = "registration_id";
|
||||||
private static final String PROPERTY_APP_VERSION = "appVersion";
|
private static final String PROPERTY_APP_VERSION = "appVersion";
|
||||||
private static final int PLAY_SERVICES_RESOLUTION_REQUEST = 9000;
|
private static final int PLAY_SERVICES_RESOLUTION_REQUEST = 9000;
|
||||||
public static Drawable cachedWallpaper = null;
|
private static Drawable cachedWallpaper;
|
||||||
|
private static int selectedColor;
|
||||||
|
private static boolean isCustomTheme;
|
||||||
|
private static final Object sync = new Object();
|
||||||
|
|
||||||
public static volatile Context applicationContext = null;
|
public static volatile Context applicationContext;
|
||||||
public static volatile Handler applicationHandler = null;
|
public static volatile Handler applicationHandler;
|
||||||
private static volatile boolean applicationInited = false;
|
private static volatile boolean applicationInited = false;
|
||||||
|
|
||||||
public static volatile boolean isScreenOn = false;
|
public static volatile boolean isScreenOn = false;
|
||||||
public static volatile boolean mainInterfacePaused = true;
|
public static volatile boolean mainInterfacePaused = true;
|
||||||
|
|
||||||
|
public static boolean isCustomTheme() {
|
||||||
|
return isCustomTheme;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getSelectedColor() {
|
||||||
|
return selectedColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void reloadWallpaper() {
|
||||||
|
cachedWallpaper = null;
|
||||||
|
loadWallpaper();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void loadWallpaper() {
|
||||||
|
if (cachedWallpaper != null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Utilities.searchQueue.postRunnable(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
synchronized (sync) {
|
||||||
|
int selectedColor = 0;
|
||||||
|
try {
|
||||||
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
||||||
|
int selectedBackground = preferences.getInt("selectedBackground", 1000001);
|
||||||
|
selectedColor = preferences.getInt("selectedColor", 0);
|
||||||
|
int cacheColorHint = 0;
|
||||||
|
if (selectedColor == 0) {
|
||||||
|
if (selectedBackground == 1000001) {
|
||||||
|
cachedWallpaper = applicationContext.getResources().getDrawable(R.drawable.background_hd);
|
||||||
|
isCustomTheme = false;
|
||||||
|
} else {
|
||||||
|
File toFile = new File(ApplicationLoader.applicationContext.getFilesDir(), "wallpaper.jpg");
|
||||||
|
if (toFile.exists()) {
|
||||||
|
cachedWallpaper = Drawable.createFromPath(toFile.getAbsolutePath());
|
||||||
|
isCustomTheme = true;
|
||||||
|
} else {
|
||||||
|
cachedWallpaper = applicationContext.getResources().getDrawable(R.drawable.background_hd);
|
||||||
|
isCustomTheme = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Throwable throwable) {
|
||||||
|
//ignore
|
||||||
|
}
|
||||||
|
if (cachedWallpaper == null) {
|
||||||
|
if (selectedColor == 0) {
|
||||||
|
selectedColor = -2693905;
|
||||||
|
}
|
||||||
|
cachedWallpaper = new ColorDrawable(selectedColor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Drawable getCachedWallpaper() {
|
||||||
|
synchronized (sync) {
|
||||||
|
return cachedWallpaper;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void postInitApplication() {
|
public static void postInitApplication() {
|
||||||
if (applicationInited) {
|
if (applicationInited) {
|
||||||
return;
|
return;
|
||||||
|
@ -117,6 +187,10 @@ public class ApplicationLoader extends Application {
|
||||||
applicationContext = getApplicationContext();
|
applicationContext = getApplicationContext();
|
||||||
NativeLoader.initNativeLibs(ApplicationLoader.applicationContext);
|
NativeLoader.initNativeLibs(ApplicationLoader.applicationContext);
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT >= 14) {
|
||||||
|
new ForegroundDetector(this);
|
||||||
|
}
|
||||||
|
|
||||||
applicationHandler = new Handler(applicationContext.getMainLooper());
|
applicationHandler = new Handler(applicationContext.getMainLooper());
|
||||||
|
|
||||||
startPushService();
|
startPushService();
|
||||||
|
|
|
@ -366,6 +366,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
||||||
datacenters.put(datacenter.datacenterId, datacenter);
|
datacenters.put(datacenter.datacenterId, datacenter);
|
||||||
}
|
}
|
||||||
currentDatacenterId = data.readInt32();
|
currentDatacenterId = data.readInt32();
|
||||||
|
data.cleanup();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
UserConfig.clearConfig();
|
UserConfig.clearConfig();
|
||||||
}
|
}
|
||||||
|
@ -388,6 +389,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
||||||
for (int a = 0; a < count; a++) {
|
for (int a = 0; a < count; a++) {
|
||||||
sessionsToDestroy.add(data.readInt64());
|
sessionsToDestroy.add(data.readInt64());
|
||||||
}
|
}
|
||||||
|
data.cleanup();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -405,6 +407,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
||||||
Datacenter datacenter = new Datacenter(data, 1);
|
Datacenter datacenter = new Datacenter(data, 1);
|
||||||
datacenters.put(datacenter.datacenterId, datacenter);
|
datacenters.put(datacenter.datacenterId, datacenter);
|
||||||
}
|
}
|
||||||
|
data.cleanup();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -452,7 +455,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
||||||
|
|
||||||
datacenter = new Datacenter();
|
datacenter = new Datacenter();
|
||||||
datacenter.datacenterId = 3;
|
datacenter.datacenterId = 3;
|
||||||
datacenter.addAddressAndPort("174.140.142.6", 443);
|
datacenter.addAddressAndPort("149.154.175.100", 443);
|
||||||
datacenters.put(datacenter.datacenterId, datacenter);
|
datacenters.put(datacenter.datacenterId, datacenter);
|
||||||
|
|
||||||
datacenter = new Datacenter();
|
datacenter = new Datacenter();
|
||||||
|
@ -477,7 +480,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
||||||
|
|
||||||
datacenter = new Datacenter();
|
datacenter = new Datacenter();
|
||||||
datacenter.datacenterId = 3;
|
datacenter.datacenterId = 3;
|
||||||
datacenter.addAddressAndPort("174.140.142.5", 443);
|
datacenter.addAddressAndPort("149.154.175.117", 443);
|
||||||
datacenters.put(datacenter.datacenterId, datacenter);
|
datacenters.put(datacenter.datacenterId, datacenter);
|
||||||
}
|
}
|
||||||
} else if (datacenters.size() == 1) {
|
} else if (datacenters.size() == 1) {
|
||||||
|
@ -488,7 +491,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
||||||
|
|
||||||
datacenter = new Datacenter();
|
datacenter = new Datacenter();
|
||||||
datacenter.datacenterId = 3;
|
datacenter.datacenterId = 3;
|
||||||
datacenter.addAddressAndPort("174.140.142.6", 443);
|
datacenter.addAddressAndPort("149.154.175.100", 443);
|
||||||
datacenters.put(datacenter.datacenterId, datacenter);
|
datacenters.put(datacenter.datacenterId, datacenter);
|
||||||
|
|
||||||
datacenter = new Datacenter();
|
datacenter = new Datacenter();
|
||||||
|
@ -528,6 +531,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
||||||
data.writeInt64(session);
|
data.writeInt64(session);
|
||||||
}
|
}
|
||||||
editor.putString("sessionsToDestroy", Base64.encodeToString(data.toByteArray(), Base64.DEFAULT));
|
editor.putString("sessionsToDestroy", Base64.encodeToString(data.toByteArray(), Base64.DEFAULT));
|
||||||
|
data.cleanup();
|
||||||
} else {
|
} else {
|
||||||
editor.remove("sessionsToDestroy");
|
editor.remove("sessionsToDestroy");
|
||||||
}
|
}
|
||||||
|
@ -539,6 +543,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
||||||
datacenter.SerializeToStream(data);
|
datacenter.SerializeToStream(data);
|
||||||
}
|
}
|
||||||
editor.putString("datacenters", Base64.encodeToString(data.toByteArray(), Base64.DEFAULT));
|
editor.putString("datacenters", Base64.encodeToString(data.toByteArray(), Base64.DEFAULT));
|
||||||
|
data.cleanup();
|
||||||
} else {
|
} else {
|
||||||
editor.remove("datacenters");
|
editor.remove("datacenters");
|
||||||
}
|
}
|
||||||
|
@ -641,8 +646,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
||||||
int lastClassGuid = 1;
|
int lastClassGuid = 1;
|
||||||
public int generateClassGuid() {
|
public int generateClassGuid() {
|
||||||
int guid = lastClassGuid++;
|
int guid = lastClassGuid++;
|
||||||
ArrayList<Long> requests = new ArrayList<>();
|
requestsByGuids.put(guid, new ArrayList<Long>());
|
||||||
requestsByGuids.put(guid, requests);
|
|
||||||
return guid;
|
return guid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -763,8 +767,12 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (error == null) {
|
if (error == null) {
|
||||||
lastDcUpdateTime = (int)(System.currentTimeMillis() / 1000);
|
|
||||||
TLRPC.TL_config config = (TLRPC.TL_config)response;
|
TLRPC.TL_config config = (TLRPC.TL_config)response;
|
||||||
|
int updateIn = config.expires - getCurrentTime();
|
||||||
|
if (updateIn <= 0) {
|
||||||
|
updateIn = 120;
|
||||||
|
}
|
||||||
|
lastDcUpdateTime = (int)(System.currentTimeMillis() / 1000) - DC_UPDATE_TIME + updateIn;
|
||||||
ArrayList<Datacenter> datacentersArr = new ArrayList<>();
|
ArrayList<Datacenter> datacentersArr = new ArrayList<>();
|
||||||
HashMap<Integer, Datacenter> datacenterMap = new HashMap<>();
|
HashMap<Integer, Datacenter> datacenterMap = new HashMap<>();
|
||||||
for (TLRPC.TL_dcOption datacenterDesc : config.dc_options) {
|
for (TLRPC.TL_dcOption datacenterDesc : config.dc_options) {
|
||||||
|
@ -1029,11 +1037,6 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
||||||
for (int i = 0; i < runningRequests.size(); i++) {
|
for (int i = 0; i < runningRequests.size(); i++) {
|
||||||
RPCRequest request = runningRequests.get(i);
|
RPCRequest request = runningRequests.get(i);
|
||||||
|
|
||||||
if (UserConfig.waitingForPasswordEnter && (request.flags & RPCRequest.RPCRequestClassWithoutLogin) == 0) {
|
|
||||||
FileLog.e("tmessages", "skip request " + request.rawRequest + ", need password enter");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
int datacenterId = request.runningDatacenterId;
|
int datacenterId = request.runningDatacenterId;
|
||||||
if (datacenterId == DEFAULT_DATACENTER_ID) {
|
if (datacenterId == DEFAULT_DATACENTER_ID) {
|
||||||
if (movingToDatacenterId != DEFAULT_DATACENTER_ID) {
|
if (movingToDatacenterId != DEFAULT_DATACENTER_ID) {
|
||||||
|
@ -1236,11 +1239,6 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (UserConfig.waitingForPasswordEnter && (request.flags & RPCRequest.RPCRequestClassWithoutLogin) == 0) {
|
|
||||||
FileLog.e("tmessages", "skip request " + request.rawRequest + ", need password enter");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
int datacenterId = request.runningDatacenterId;
|
int datacenterId = request.runningDatacenterId;
|
||||||
if (datacenterId == DEFAULT_DATACENTER_ID) {
|
if (datacenterId == DEFAULT_DATACENTER_ID) {
|
||||||
if (movingToDatacenterId != DEFAULT_DATACENTER_ID && (request.flags & RPCRequest.RPCRequestClassEnableUnauthorized) == 0) {
|
if (movingToDatacenterId != DEFAULT_DATACENTER_ID && (request.flags & RPCRequest.RPCRequestClassEnableUnauthorized) == 0) {
|
||||||
|
@ -1338,6 +1336,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
||||||
if (canCompress) {
|
if (canCompress) {
|
||||||
try {
|
try {
|
||||||
byte[] data = Utilities.compress(os.toByteArray());
|
byte[] data = Utilities.compress(os.toByteArray());
|
||||||
|
os.cleanup();
|
||||||
if (data.length < requestLength) {
|
if (data.length < requestLength) {
|
||||||
TLRPC.TL_gzip_packed packed = new TLRPC.TL_gzip_packed();
|
TLRPC.TL_gzip_packed packed = new TLRPC.TL_gzip_packed();
|
||||||
packed.packed_data = data;
|
packed.packed_data = data;
|
||||||
|
@ -1345,6 +1344,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
||||||
os = new SerializedData(true);
|
os = new SerializedData(true);
|
||||||
packed.serializeToStream(os);
|
packed.serializeToStream(os);
|
||||||
requestLength = os.length();
|
requestLength = os.length();
|
||||||
|
os.cleanup();
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
FileLog.e("tmessages", e);
|
FileLog.e("tmessages", e);
|
||||||
|
@ -1406,6 +1406,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
||||||
if (rawRequest != null && (rawRequest instanceof TLRPC.TL_messages_sendMessage ||
|
if (rawRequest != null && (rawRequest instanceof TLRPC.TL_messages_sendMessage ||
|
||||||
rawRequest instanceof TLRPC.TL_messages_sendMedia ||
|
rawRequest instanceof TLRPC.TL_messages_sendMedia ||
|
||||||
rawRequest instanceof TLRPC.TL_messages_forwardMessages ||
|
rawRequest instanceof TLRPC.TL_messages_forwardMessages ||
|
||||||
|
rawRequest instanceof TLRPC.TL_messages_forwardMessage ||
|
||||||
rawRequest instanceof TLRPC.TL_messages_sendEncrypted ||
|
rawRequest instanceof TLRPC.TL_messages_sendEncrypted ||
|
||||||
rawRequest instanceof TLRPC.TL_messages_sendEncryptedFile ||
|
rawRequest instanceof TLRPC.TL_messages_sendEncryptedFile ||
|
||||||
rawRequest instanceof TLRPC.TL_messages_sendEncryptedService)) {
|
rawRequest instanceof TLRPC.TL_messages_sendEncryptedService)) {
|
||||||
|
@ -1426,6 +1427,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
||||||
if (currentRawRequest instanceof TLRPC.TL_messages_sendMessage ||
|
if (currentRawRequest instanceof TLRPC.TL_messages_sendMessage ||
|
||||||
currentRawRequest instanceof TLRPC.TL_messages_sendMedia ||
|
currentRawRequest instanceof TLRPC.TL_messages_sendMedia ||
|
||||||
currentRawRequest instanceof TLRPC.TL_messages_forwardMessages ||
|
currentRawRequest instanceof TLRPC.TL_messages_forwardMessages ||
|
||||||
|
currentRawRequest instanceof TLRPC.TL_messages_forwardMessage ||
|
||||||
currentRawRequest instanceof TLRPC.TL_messages_sendEncrypted ||
|
currentRawRequest instanceof TLRPC.TL_messages_sendEncrypted ||
|
||||||
currentRawRequest instanceof TLRPC.TL_messages_sendEncryptedFile ||
|
currentRawRequest instanceof TLRPC.TL_messages_sendEncryptedFile ||
|
||||||
currentRawRequest instanceof TLRPC.TL_messages_sendEncryptedService) {
|
currentRawRequest instanceof TLRPC.TL_messages_sendEncryptedService) {
|
||||||
|
@ -1438,6 +1440,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
||||||
if (request.rawRequest instanceof TLRPC.TL_messages_sendMessage ||
|
if (request.rawRequest instanceof TLRPC.TL_messages_sendMessage ||
|
||||||
request.rawRequest instanceof TLRPC.TL_messages_sendMedia ||
|
request.rawRequest instanceof TLRPC.TL_messages_sendMedia ||
|
||||||
request.rawRequest instanceof TLRPC.TL_messages_forwardMessages ||
|
request.rawRequest instanceof TLRPC.TL_messages_forwardMessages ||
|
||||||
|
request.rawRequest instanceof TLRPC.TL_messages_forwardMessage ||
|
||||||
request.rawRequest instanceof TLRPC.TL_messages_sendEncrypted ||
|
request.rawRequest instanceof TLRPC.TL_messages_sendEncrypted ||
|
||||||
request.rawRequest instanceof TLRPC.TL_messages_sendEncryptedFile ||
|
request.rawRequest instanceof TLRPC.TL_messages_sendEncryptedFile ||
|
||||||
request.rawRequest instanceof TLRPC.TL_messages_sendEncryptedService) {
|
request.rawRequest instanceof TLRPC.TL_messages_sendEncryptedService) {
|
||||||
|
@ -1720,6 +1723,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
||||||
if (quickAckId != null) {
|
if (quickAckId != null) {
|
||||||
SerializedData data = new SerializedData(messageKeyFull);
|
SerializedData data = new SerializedData(messageKeyFull);
|
||||||
quickAckId.add(data.readInt32() & 0x7fffffff);
|
quickAckId.add(data.readInt32() & 0x7fffffff);
|
||||||
|
data.cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
MessageKeyData keyData = Utilities.generateMessageKeyData(datacenter.authKey, messageKey, false);
|
MessageKeyData keyData = Utilities.generateMessageKeyData(datacenter.authKey, messageKey, false);
|
||||||
|
@ -2140,7 +2144,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
||||||
implicitError.code = ((TLRPC.RpcError)resultContainer.result).error_code;
|
implicitError.code = ((TLRPC.RpcError)resultContainer.result).error_code;
|
||||||
implicitError.text = ((TLRPC.RpcError)resultContainer.result).error_message;
|
implicitError.text = ((TLRPC.RpcError)resultContainer.result).error_message;
|
||||||
} else if (!(resultContainer.result instanceof TLRPC.TL_error)) {
|
} else if (!(resultContainer.result instanceof TLRPC.TL_error)) {
|
||||||
if (request.rawRequest == null || !request.rawRequest.responseClass().isAssignableFrom(resultContainer.result.getClass())) {
|
if (request.rawRequest == null || resultContainer.result == null || !request.rawRequest.responseClass().isAssignableFrom(resultContainer.result.getClass())) {
|
||||||
if (request.rawRequest == null) {
|
if (request.rawRequest == null) {
|
||||||
FileLog.e("tmessages", "rawRequest is null");
|
FileLog.e("tmessages", "rawRequest is null");
|
||||||
} else {
|
} else {
|
||||||
|
@ -2169,10 +2173,6 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (request.rawRequest instanceof TLRPC.TL_auth_checkPassword) {
|
|
||||||
UserConfig.setWaitingForPasswordEnter(false);
|
|
||||||
UserConfig.saveConfig(false);
|
|
||||||
}
|
|
||||||
request.completionBlock.run(resultContainer.result, null);
|
request.completionBlock.run(resultContainer.result, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2180,7 +2180,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
||||||
if (implicitError != null && implicitError.code == 401) {
|
if (implicitError != null && implicitError.code == 401) {
|
||||||
isError = true;
|
isError = true;
|
||||||
if (implicitError.text != null && implicitError.text.contains("SESSION_PASSWORD_NEEDED")) {
|
if (implicitError.text != null && implicitError.text.contains("SESSION_PASSWORD_NEEDED")) {
|
||||||
UserConfig.setWaitingForPasswordEnter(true);
|
/*UserConfig.setWaitingForPasswordEnter(true); TODO
|
||||||
UserConfig.saveConfig(false);
|
UserConfig.saveConfig(false);
|
||||||
if (UserConfig.isClientActivated()) {
|
if (UserConfig.isClientActivated()) {
|
||||||
discardResponse = true;
|
discardResponse = true;
|
||||||
|
@ -2190,7 +2190,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
||||||
NotificationCenter.getInstance().postNotificationName(NotificationCenter.needPasswordEnter);
|
NotificationCenter.getInstance().postNotificationName(NotificationCenter.needPasswordEnter);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}*/
|
||||||
} else if (datacenter.datacenterId == currentDatacenterId || datacenter.datacenterId == movingToDatacenterId) {
|
} else if (datacenter.datacenterId == currentDatacenterId || datacenter.datacenterId == movingToDatacenterId) {
|
||||||
if ((request.flags & RPCRequest.RPCRequestClassGeneric) != 0 && UserConfig.isClientActivated()) {
|
if ((request.flags & RPCRequest.RPCRequestClassGeneric) != 0 && UserConfig.isClientActivated()) {
|
||||||
UserConfig.clearConfig();
|
UserConfig.clearConfig();
|
||||||
|
|
|
@ -54,10 +54,10 @@ public class FileLoadOperation {
|
||||||
private File tempPath = null;
|
private File tempPath = null;
|
||||||
private boolean isForceRequest = false;
|
private boolean isForceRequest = false;
|
||||||
|
|
||||||
public static interface FileLoadOperationDelegate {
|
public interface FileLoadOperationDelegate {
|
||||||
public abstract void didFinishLoadingFile(FileLoadOperation operation, File finalFile);
|
void didFinishLoadingFile(FileLoadOperation operation, File finalFile);
|
||||||
public abstract void didFailedLoadingFile(FileLoadOperation operation, int state);
|
void didFailedLoadingFile(FileLoadOperation operation, int state);
|
||||||
public abstract void didChangedLoadProgress(FileLoadOperation operation, float progress);
|
void didChangedLoadProgress(FileLoadOperation operation, float progress);
|
||||||
}
|
}
|
||||||
|
|
||||||
public FileLoadOperation(TLRPC.FileLocation photoLocation, int size) {
|
public FileLoadOperation(TLRPC.FileLocation photoLocation, int size) {
|
||||||
|
|
|
@ -19,13 +19,13 @@ import java.util.concurrent.Semaphore;
|
||||||
|
|
||||||
public class FileLoader {
|
public class FileLoader {
|
||||||
|
|
||||||
public static interface FileLoaderDelegate {
|
public interface FileLoaderDelegate {
|
||||||
public abstract void fileUploadProgressChanged(String location, float progress, boolean isEncrypted);
|
void fileUploadProgressChanged(String location, float progress, boolean isEncrypted);
|
||||||
public abstract void fileDidUploaded(String location, TLRPC.InputFile inputFile, TLRPC.InputEncryptedFile inputEncryptedFile);
|
void fileDidUploaded(String location, TLRPC.InputFile inputFile, TLRPC.InputEncryptedFile inputEncryptedFile);
|
||||||
public abstract void fileDidFailedUpload(String location, boolean isEncrypted);
|
void fileDidFailedUpload(String location, boolean isEncrypted);
|
||||||
public abstract void fileDidLoaded(String location, File finalFile, int type);
|
void fileDidLoaded(String location, File finalFile, int type);
|
||||||
public abstract void fileDidFailedLoad(String location, int state);
|
void fileDidFailedLoad(String location, int state);
|
||||||
public abstract void fileLoadProgressChanged(String location, float progress);
|
void fileLoadProgressChanged(String location, float progress);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final int MEDIA_DIR_IMAGE = 0;
|
public static final int MEDIA_DIR_IMAGE = 0;
|
||||||
|
@ -132,6 +132,9 @@ public class FileLoader {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void uploadFile(final String location, final boolean encrypted, final boolean small, final int estimatedSize) {
|
public void uploadFile(final String location, final boolean encrypted, final boolean small, final int estimatedSize) {
|
||||||
|
if (location == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
fileLoaderQueue.postRunnable(new Runnable() {
|
fileLoaderQueue.postRunnable(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -628,7 +631,7 @@ public class FileLoader {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TLRPC.PhotoSize getClosestPhotoSizeWithSize(ArrayList<TLRPC.PhotoSize> sizes, int side) {
|
public static TLRPC.PhotoSize getClosestPhotoSizeWithSize(ArrayList<TLRPC.PhotoSize> sizes, int side) {
|
||||||
if (sizes == null) {
|
if (sizes == null || sizes.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
int lastSide = 0;
|
int lastSide = 0;
|
||||||
|
@ -638,7 +641,7 @@ public class FileLoader {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
int currentSide = obj.w >= obj.h ? obj.w : obj.h;
|
int currentSide = obj.w >= obj.h ? obj.w : obj.h;
|
||||||
if (closestObject == null || obj instanceof TLRPC.TL_photoCachedSize || currentSide <= side && lastSide < currentSide) {
|
if (closestObject == null || side > 100 && closestObject.location != null && closestObject.location.dc_id == Integer.MIN_VALUE || obj instanceof TLRPC.TL_photoCachedSize || currentSide <= side && lastSide < currentSide) {
|
||||||
closestObject = obj;
|
closestObject = obj;
|
||||||
lastSide = currentSide;
|
lastSide = currentSide;
|
||||||
}
|
}
|
||||||
|
|
|
@ -181,7 +181,7 @@ public class FileLog {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void cleanupLogs() {
|
public static void cleanupLogs() {
|
||||||
ArrayList<Uri> uris = new ArrayList<Uri>();
|
ArrayList<Uri> uris = new ArrayList<>();
|
||||||
File sdCard = ApplicationLoader.applicationContext.getExternalFilesDir(null);
|
File sdCard = ApplicationLoader.applicationContext.getExternalFilesDir(null);
|
||||||
File dir = new File (sdCard.getAbsolutePath() + "/logs");
|
File dir = new File (sdCard.getAbsolutePath() + "/logs");
|
||||||
File[] files = dir.listFiles();
|
File[] files = dir.listFiles();
|
||||||
|
|
|
@ -45,10 +45,10 @@ public class FileUploadOperation {
|
||||||
private MessageDigest mdEnc = null;
|
private MessageDigest mdEnc = null;
|
||||||
private boolean started = false;
|
private boolean started = false;
|
||||||
|
|
||||||
public static interface FileUploadOperationDelegate {
|
public interface FileUploadOperationDelegate {
|
||||||
public abstract void didFinishUploadingFile(FileUploadOperation operation, TLRPC.InputFile inputFile, TLRPC.InputEncryptedFile inputEncryptedFile);
|
void didFinishUploadingFile(FileUploadOperation operation, TLRPC.InputFile inputFile, TLRPC.InputEncryptedFile inputEncryptedFile);
|
||||||
public abstract void didFailedUploadingFile(FileUploadOperation operation);
|
void didFailedUploadingFile(FileUploadOperation operation);
|
||||||
public abstract void didChangedUploadProgress(FileUploadOperation operation, float progress);
|
void didChangedUploadProgress(FileUploadOperation operation, float progress);
|
||||||
}
|
}
|
||||||
|
|
||||||
public FileUploadOperation(String location, boolean encrypted, int estimated) {
|
public FileUploadOperation(String location, boolean encrypted, int estimated) {
|
||||||
|
@ -91,6 +91,14 @@ public class FileUploadOperation {
|
||||||
remove(fileKey + "_iv").
|
remove(fileKey + "_iv").
|
||||||
remove(fileKey + "_key").
|
remove(fileKey + "_key").
|
||||||
remove(fileKey + "_ivc").commit();
|
remove(fileKey + "_ivc").commit();
|
||||||
|
try {
|
||||||
|
if (stream != null) {
|
||||||
|
stream.close();
|
||||||
|
stream = null;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
FileLog.e("tmessages", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void checkNewDataAvailable(final long finalSize) {
|
protected void checkNewDataAvailable(final long finalSize) {
|
||||||
|
@ -100,7 +108,7 @@ public class FileUploadOperation {
|
||||||
if (estimatedSize != 0 && finalSize != 0) {
|
if (estimatedSize != 0 && finalSize != 0) {
|
||||||
estimatedSize = 0;
|
estimatedSize = 0;
|
||||||
totalFileSize = finalSize;
|
totalFileSize = finalSize;
|
||||||
totalPartsCount = (int) Math.ceil((float) totalFileSize / (float) uploadChunkSize);
|
totalPartsCount = (int) (totalFileSize + uploadChunkSize - 1) / uploadChunkSize;
|
||||||
if (started) {
|
if (started) {
|
||||||
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("uploadinfo", Activity.MODE_PRIVATE);
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("uploadinfo", Activity.MODE_PRIVATE);
|
||||||
storeFileUploadInfo(preferences);
|
storeFileUploadInfo(preferences);
|
||||||
|
@ -154,7 +162,7 @@ public class FileUploadOperation {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uploadChunkSize = (int) Math.max(32, Math.ceil(totalFileSize / (1024.0f * 3000)));
|
uploadChunkSize = (int) Math.max(32, (totalFileSize + 1024 * 3000 - 1) / (1024 * 3000));
|
||||||
if (1024 % uploadChunkSize != 0) {
|
if (1024 % uploadChunkSize != 0) {
|
||||||
int chunkSize = 64;
|
int chunkSize = 64;
|
||||||
while (uploadChunkSize > chunkSize) {
|
while (uploadChunkSize > chunkSize) {
|
||||||
|
@ -164,7 +172,7 @@ public class FileUploadOperation {
|
||||||
}
|
}
|
||||||
|
|
||||||
uploadChunkSize *= 1024;
|
uploadChunkSize *= 1024;
|
||||||
totalPartsCount = (int) Math.ceil((float) totalFileSize / (float) uploadChunkSize);
|
totalPartsCount = (int) (totalFileSize + uploadChunkSize - 1) / uploadChunkSize;
|
||||||
readBuffer = new byte[uploadChunkSize];
|
readBuffer = new byte[uploadChunkSize];
|
||||||
|
|
||||||
fileKey = Utilities.MD5(uploadingFilePath + (isEncrypted ? "enc" : ""));
|
fileKey = Utilities.MD5(uploadingFilePath + (isEncrypted ? "enc" : ""));
|
||||||
|
@ -347,7 +355,7 @@ public class FileUploadOperation {
|
||||||
if (error == null) {
|
if (error == null) {
|
||||||
if (response instanceof TLRPC.TL_boolTrue) {
|
if (response instanceof TLRPC.TL_boolTrue) {
|
||||||
currentPartNum++;
|
currentPartNum++;
|
||||||
delegate.didChangedUploadProgress(FileUploadOperation.this, (float) currentUploaded / (float) totalFileSize);
|
delegate.didChangedUploadProgress(FileUploadOperation.this, currentUploaded / (float) totalFileSize);
|
||||||
if (isLastPart) {
|
if (isLastPart) {
|
||||||
state = 3;
|
state = 3;
|
||||||
if (key == null) {
|
if (key == null) {
|
||||||
|
|
|
@ -55,7 +55,7 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
|
||||||
}
|
}
|
||||||
datacenter.connection.delegate = this;
|
datacenter.connection.delegate = this;
|
||||||
|
|
||||||
processedMessageIds = new ArrayList<Long>();
|
processedMessageIds = new ArrayList<>();
|
||||||
authNonce = null;
|
authNonce = null;
|
||||||
authServerNonce = null;
|
authServerNonce = null;
|
||||||
authNewNonce = null;
|
authNewNonce = null;
|
||||||
|
@ -92,10 +92,10 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
|
||||||
HashMap<String, Object> selectPublicKey(ArrayList<Long> fingerprints) {
|
HashMap<String, Object> selectPublicKey(ArrayList<Long> fingerprints) {
|
||||||
synchronized (lock) {
|
synchronized (lock) {
|
||||||
if (serverPublicKeys == null) {
|
if (serverPublicKeys == null) {
|
||||||
serverPublicKeys = new ArrayList<HashMap<String, Object>>();
|
serverPublicKeys = new ArrayList<>();
|
||||||
HashMap<String, Object> map;
|
HashMap<String, Object> map;
|
||||||
|
|
||||||
map = new HashMap<String, Object>();
|
map = new HashMap<>();
|
||||||
map.put("key", new BigInteger[]{
|
map.put("key", new BigInteger[]{
|
||||||
new BigInteger("c150023e2f70db7985ded064759cfecf0af328e69a41daf4d6f01b538135" +
|
new BigInteger("c150023e2f70db7985ded064759cfecf0af328e69a41daf4d6f01b538135" +
|
||||||
"a6f91f8f8b2a0ec9ba9720ce352efcf6c5680ffc424bd634864902de0b4bd6d49f4e580230e" +
|
"a6f91f8f8b2a0ec9ba9720ce352efcf6c5680ffc424bd634864902de0b4bd6d49f4e580230e" +
|
||||||
|
@ -108,7 +108,7 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
|
||||||
map.put("fingerprint", 0xc3b42b026ce86b21L);
|
map.put("fingerprint", 0xc3b42b026ce86b21L);
|
||||||
serverPublicKeys.add(map);
|
serverPublicKeys.add(map);
|
||||||
|
|
||||||
map = new HashMap<String, Object>();
|
map = new HashMap<>();
|
||||||
map.put("key", new BigInteger[]{
|
map.put("key", new BigInteger[]{
|
||||||
new BigInteger("c6aeda78b02a251db4b6441031f467fa871faed32526c436524b1fb3b5dc" +
|
new BigInteger("c6aeda78b02a251db4b6441031f467fa871faed32526c436524b1fb3b5dc" +
|
||||||
"a28efb8c089dd1b46d92c895993d87108254951c5f001a0f055f3063dcd14d431a300eb9e29" +
|
"a28efb8c089dd1b46d92c895993d87108254951c5f001a0f055f3063dcd14d431a300eb9e29" +
|
||||||
|
@ -121,7 +121,7 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
|
||||||
map.put("fingerprint", 0x9a996a1db11c729bL);
|
map.put("fingerprint", 0x9a996a1db11c729bL);
|
||||||
serverPublicKeys.add(map);
|
serverPublicKeys.add(map);
|
||||||
|
|
||||||
map = new HashMap<String, Object>();
|
map = new HashMap<>();
|
||||||
map.put("key", new BigInteger[]{
|
map.put("key", new BigInteger[]{
|
||||||
new BigInteger("b1066749655935f0a5936f517034c943bea7f3365a8931ae52c8bcb14856" +
|
new BigInteger("b1066749655935f0a5936f517034c943bea7f3365a8931ae52c8bcb14856" +
|
||||||
"f004b83d26cf2839be0f22607470d67481771c1ce5ec31de16b20bbaa4ecd2f7d2ecf6b6356" +
|
"f004b83d26cf2839be0f22607470d67481771c1ce5ec31de16b20bbaa4ecd2f7d2ecf6b6356" +
|
||||||
|
@ -134,7 +134,7 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
|
||||||
map.put("fingerprint", 0xb05b2a6f70cdea78L);
|
map.put("fingerprint", 0xb05b2a6f70cdea78L);
|
||||||
serverPublicKeys.add(map);
|
serverPublicKeys.add(map);
|
||||||
|
|
||||||
map = new HashMap<String, Object>();
|
map = new HashMap<>();
|
||||||
map.put("key", new BigInteger[]{
|
map.put("key", new BigInteger[]{
|
||||||
new BigInteger("c2a8c55b4a62e2b78a19b91cf692bcdc4ba7c23fe4d06f194e2a0c30f6d9" +
|
new BigInteger("c2a8c55b4a62e2b78a19b91cf692bcdc4ba7c23fe4d06f194e2a0c30f6d9" +
|
||||||
"996f7d1a2bcc89bc1ac4333d44359a6c433252d1a8402d9970378b5912b75bc8cc3fa76710a" +
|
"996f7d1a2bcc89bc1ac4333d44359a6c433252d1a8402d9970378b5912b75bc8cc3fa76710a" +
|
||||||
|
@ -190,7 +190,7 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
|
||||||
if (message instanceof TLRPC.TL_resPQ) {
|
if (message instanceof TLRPC.TL_resPQ) {
|
||||||
if (processedPQRes) {
|
if (processedPQRes) {
|
||||||
TLRPC.TL_msgs_ack msgsAck = new TLRPC.TL_msgs_ack();
|
TLRPC.TL_msgs_ack msgsAck = new TLRPC.TL_msgs_ack();
|
||||||
msgsAck.msg_ids = new ArrayList<Long>();
|
msgsAck.msg_ids = new ArrayList<>();
|
||||||
msgsAck.msg_ids.add(messageId);
|
msgsAck.msg_ids.add(messageId);
|
||||||
sendMessageData(msgsAck, generateMessageId());
|
sendMessageData(msgsAck, generateMessageId());
|
||||||
return;
|
return;
|
||||||
|
@ -250,6 +250,7 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
|
||||||
innerData.serializeToStream(os);
|
innerData.serializeToStream(os);
|
||||||
|
|
||||||
byte[] innerDataBytes = os.toByteArray();
|
byte[] innerDataBytes = os.toByteArray();
|
||||||
|
os.cleanup();
|
||||||
|
|
||||||
SerializedData dataWithHash = new SerializedData();
|
SerializedData dataWithHash = new SerializedData();
|
||||||
dataWithHash.writeRaw(Utilities.computeSHA1(innerDataBytes));
|
dataWithHash.writeRaw(Utilities.computeSHA1(innerDataBytes));
|
||||||
|
@ -261,6 +262,7 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] encryptedBytes = Utilities.encryptWithRSA((BigInteger[])publicKey.get("key"), dataWithHash.toByteArray());
|
byte[] encryptedBytes = Utilities.encryptWithRSA((BigInteger[])publicKey.get("key"), dataWithHash.toByteArray());
|
||||||
|
dataWithHash.cleanup();
|
||||||
SerializedData encryptedData = new SerializedData();
|
SerializedData encryptedData = new SerializedData();
|
||||||
encryptedData.writeRaw(encryptedBytes);
|
encryptedData.writeRaw(encryptedBytes);
|
||||||
if (encryptedData.length() < 256) {
|
if (encryptedData.length() < 256) {
|
||||||
|
@ -269,12 +271,14 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
|
||||||
newEncryptedData.writeByte(0);
|
newEncryptedData.writeByte(0);
|
||||||
}
|
}
|
||||||
newEncryptedData.writeRaw(encryptedData.toByteArray());
|
newEncryptedData.writeRaw(encryptedData.toByteArray());
|
||||||
|
encryptedData.cleanup();
|
||||||
encryptedData = newEncryptedData;
|
encryptedData = newEncryptedData;
|
||||||
}
|
}
|
||||||
reqDH.encrypted_data = encryptedData.toByteArray();
|
reqDH.encrypted_data = encryptedData.toByteArray();
|
||||||
|
encryptedData.cleanup();
|
||||||
|
|
||||||
TLRPC.TL_msgs_ack msgsAck = new TLRPC.TL_msgs_ack();
|
TLRPC.TL_msgs_ack msgsAck = new TLRPC.TL_msgs_ack();
|
||||||
msgsAck.msg_ids = new ArrayList<Long>();
|
msgsAck.msg_ids = new ArrayList<>();
|
||||||
msgsAck.msg_ids.add(messageIdf);
|
msgsAck.msg_ids.add(messageIdf);
|
||||||
sendMessageData(msgsAck, generateMessageId());
|
sendMessageData(msgsAck, generateMessageId());
|
||||||
|
|
||||||
|
@ -305,8 +309,10 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
|
||||||
serverNonceAndNewNonce.writeRaw(authServerNonce);
|
serverNonceAndNewNonce.writeRaw(authServerNonce);
|
||||||
serverNonceAndNewNonce.writeRaw(authNewNonce);
|
serverNonceAndNewNonce.writeRaw(authNewNonce);
|
||||||
tmpAesKey.writeRaw(Utilities.computeSHA1(newNonceAndServerNonce.toByteArray()));
|
tmpAesKey.writeRaw(Utilities.computeSHA1(newNonceAndServerNonce.toByteArray()));
|
||||||
|
newNonceAndServerNonce.cleanup();
|
||||||
|
|
||||||
byte[] serverNonceAndNewNonceHash = Utilities.computeSHA1(serverNonceAndNewNonce.toByteArray());
|
byte[] serverNonceAndNewNonceHash = Utilities.computeSHA1(serverNonceAndNewNonce.toByteArray());
|
||||||
|
serverNonceAndNewNonce.cleanup();
|
||||||
byte[] serverNonceAndNewNonceHash0_12 = new byte[12];
|
byte[] serverNonceAndNewNonceHash0_12 = new byte[12];
|
||||||
System.arraycopy(serverNonceAndNewNonceHash, 0, serverNonceAndNewNonceHash0_12, 0, 12);
|
System.arraycopy(serverNonceAndNewNonceHash, 0, serverNonceAndNewNonceHash0_12, 0, 12);
|
||||||
|
|
||||||
|
@ -322,6 +328,7 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
|
||||||
newNonceAndNewNonce.writeRaw(authNewNonce);
|
newNonceAndNewNonce.writeRaw(authNewNonce);
|
||||||
newNonceAndNewNonce.writeRaw(authNewNonce);
|
newNonceAndNewNonce.writeRaw(authNewNonce);
|
||||||
tmpAesIv.writeRaw(Utilities.computeSHA1(newNonceAndNewNonce.toByteArray()));
|
tmpAesIv.writeRaw(Utilities.computeSHA1(newNonceAndNewNonce.toByteArray()));
|
||||||
|
newNonceAndNewNonce.cleanup();
|
||||||
|
|
||||||
byte[] newNonce0_4 = new byte[4];
|
byte[] newNonce0_4 = new byte[4];
|
||||||
System.arraycopy(authNewNonce, 0, newNonce0_4, 0, 4);
|
System.arraycopy(authNewNonce, 0, newNonce0_4, 0, 4);
|
||||||
|
@ -417,6 +424,7 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
|
||||||
serverSaltData.writeByte(x);
|
serverSaltData.writeByte(x);
|
||||||
}
|
}
|
||||||
ByteBuffer saltBuffer = ByteBuffer.wrap(serverSaltData.toByteArray());
|
ByteBuffer saltBuffer = ByteBuffer.wrap(serverSaltData.toByteArray());
|
||||||
|
serverSaltData.cleanup();
|
||||||
|
|
||||||
timeDifference = dhInnerData.server_time - (int)(System.currentTimeMillis() / 1000);
|
timeDifference = dhInnerData.server_time - (int)(System.currentTimeMillis() / 1000);
|
||||||
|
|
||||||
|
@ -455,8 +463,11 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
|
||||||
Utilities.aesIgeEncryption(clientDataWithHash.buffer, tmpAesKey.toByteArray(), tmpAesIv.toByteArray(), true, false, 0, clientDataWithHash.length());
|
Utilities.aesIgeEncryption(clientDataWithHash.buffer, tmpAesKey.toByteArray(), tmpAesIv.toByteArray(), true, false, 0, clientDataWithHash.length());
|
||||||
setClientDhParams.encrypted_data = clientDataWithHash;
|
setClientDhParams.encrypted_data = clientDataWithHash;
|
||||||
|
|
||||||
|
tmpAesKey.cleanup();
|
||||||
|
tmpAesIv.cleanup();
|
||||||
|
|
||||||
TLRPC.TL_msgs_ack msgsAck = new TLRPC.TL_msgs_ack();
|
TLRPC.TL_msgs_ack msgsAck = new TLRPC.TL_msgs_ack();
|
||||||
msgsAck.msg_ids = new ArrayList<Long>();
|
msgsAck.msg_ids = new ArrayList<>();
|
||||||
msgsAck.msg_ids.add(messageId);
|
msgsAck.msg_ids.add(messageId);
|
||||||
sendMessageData(msgsAck, generateMessageId());
|
sendMessageData(msgsAck, generateMessageId());
|
||||||
|
|
||||||
|
@ -494,7 +505,7 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
|
||||||
}
|
}
|
||||||
|
|
||||||
TLRPC.TL_msgs_ack msgsAck = new TLRPC.TL_msgs_ack();
|
TLRPC.TL_msgs_ack msgsAck = new TLRPC.TL_msgs_ack();
|
||||||
msgsAck.msg_ids = new ArrayList<Long>();
|
msgsAck.msg_ids = new ArrayList<>();
|
||||||
msgsAck.msg_ids.add(messageId);
|
msgsAck.msg_ids.add(messageId);
|
||||||
sendMessageData(msgsAck, generateMessageId());
|
sendMessageData(msgsAck, generateMessageId());
|
||||||
|
|
||||||
|
@ -507,6 +518,7 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
|
||||||
newNonce1.writeByte(1);
|
newNonce1.writeByte(1);
|
||||||
newNonce1.writeRaw(authKeyAuxHash);
|
newNonce1.writeRaw(authKeyAuxHash);
|
||||||
byte[] newNonceHash1Full = Utilities.computeSHA1(newNonce1.toByteArray());
|
byte[] newNonceHash1Full = Utilities.computeSHA1(newNonce1.toByteArray());
|
||||||
|
newNonce1.cleanup();
|
||||||
byte[] newNonceHash1 = new byte[16];
|
byte[] newNonceHash1 = new byte[16];
|
||||||
System.arraycopy(newNonceHash1Full, newNonceHash1Full.length - 16, newNonceHash1, 0, 16);
|
System.arraycopy(newNonceHash1Full, newNonceHash1Full.length - 16, newNonceHash1, 0, 16);
|
||||||
|
|
||||||
|
@ -515,6 +527,7 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
|
||||||
newNonce2.writeByte(2);
|
newNonce2.writeByte(2);
|
||||||
newNonce2.writeRaw(authKeyAuxHash);
|
newNonce2.writeRaw(authKeyAuxHash);
|
||||||
byte[] newNonceHash2Full = Utilities.computeSHA1(newNonce2.toByteArray());
|
byte[] newNonceHash2Full = Utilities.computeSHA1(newNonce2.toByteArray());
|
||||||
|
newNonce2.cleanup();
|
||||||
byte[] newNonceHash2 = new byte[16];
|
byte[] newNonceHash2 = new byte[16];
|
||||||
System.arraycopy(newNonceHash2Full, newNonceHash2Full.length - 16, newNonceHash2, 0, 16);
|
System.arraycopy(newNonceHash2Full, newNonceHash2Full.length - 16, newNonceHash2, 0, 16);
|
||||||
|
|
||||||
|
@ -523,6 +536,7 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
|
||||||
newNonce3.writeByte(3);
|
newNonce3.writeByte(3);
|
||||||
newNonce3.writeRaw(authKeyAuxHash);
|
newNonce3.writeRaw(authKeyAuxHash);
|
||||||
byte[] newNonceHash3Full = Utilities.computeSHA1(newNonce3.toByteArray());
|
byte[] newNonceHash3Full = Utilities.computeSHA1(newNonce3.toByteArray());
|
||||||
|
newNonce3.cleanup();
|
||||||
byte[] newNonceHash3 = new byte[16];
|
byte[] newNonceHash3 = new byte[16];
|
||||||
System.arraycopy(newNonceHash3Full, newNonceHash3Full.length - 16, newNonceHash3, 0, 16);
|
System.arraycopy(newNonceHash3Full, newNonceHash3Full.length - 16, newNonceHash3, 0, 16);
|
||||||
|
|
||||||
|
@ -544,7 +558,7 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
|
||||||
datacenter.authKey = authKey;
|
datacenter.authKey = authKey;
|
||||||
datacenter.authKeyId = authKeyId;
|
datacenter.authKeyId = authKeyId;
|
||||||
datacenter.addServerSalt(serverSalt);
|
datacenter.addServerSalt(serverSalt);
|
||||||
HashMap<String, Object> resultDict = new HashMap<String, Object>();
|
HashMap<String, Object> resultDict = new HashMap<>();
|
||||||
resultDict.put("timeDifference", timeDifference);
|
resultDict.put("timeDifference", timeDifference);
|
||||||
if (delegate != null) {
|
if (delegate != null) {
|
||||||
delegate.ActionDidFinishExecution(parent, resultDict);
|
delegate.ActionDidFinishExecution(parent, resultDict);
|
||||||
|
@ -575,7 +589,7 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
TLRPC.TL_msgs_ack msgsAck = new TLRPC.TL_msgs_ack();
|
TLRPC.TL_msgs_ack msgsAck = new TLRPC.TL_msgs_ack();
|
||||||
msgsAck.msg_ids = new ArrayList<Long>();
|
msgsAck.msg_ids = new ArrayList<>();
|
||||||
msgsAck.msg_ids.add(messageId);
|
msgsAck.msg_ids.add(messageId);
|
||||||
sendMessageData(msgsAck, generateMessageId());
|
sendMessageData(msgsAck, generateMessageId());
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,7 +63,7 @@ public class RPCRequest {
|
||||||
|
|
||||||
boolean initRequest = false;
|
boolean initRequest = false;
|
||||||
|
|
||||||
ArrayList<Long> respondsToMessageIds = new ArrayList<Long>();
|
ArrayList<Long> respondsToMessageIds = new ArrayList<>();
|
||||||
|
|
||||||
public void addRespondMessageId(long messageId) {
|
public void addRespondMessageId(long messageId) {
|
||||||
respondsToMessageIds.add(messageId);
|
respondsToMessageIds.add(messageId);
|
||||||
|
|
|
@ -49,6 +49,41 @@ public class SerializedData extends AbsSerializedData {
|
||||||
in = new DataInputStream(inbuf);
|
in = new DataInputStream(inbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void cleanup() {
|
||||||
|
try {
|
||||||
|
if (inbuf != null) {
|
||||||
|
inbuf.close();
|
||||||
|
inbuf = null;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
FileLog.e("tmessages", e);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
if (in != null) {
|
||||||
|
in.close();
|
||||||
|
in = null;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
FileLog.e("tmessages", e);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
if (outbuf != null) {
|
||||||
|
outbuf.close();
|
||||||
|
outbuf = null;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
FileLog.e("tmessages", e);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
if (out != null) {
|
||||||
|
out.close();
|
||||||
|
out = null;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
FileLog.e("tmessages", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public SerializedData(File file) throws Exception {
|
public SerializedData(File file) throws Exception {
|
||||||
FileInputStream is = new FileInputStream(file);
|
FileInputStream is = new FileInputStream(file);
|
||||||
byte[] data = new byte[(int)file.length()];
|
byte[] data = new byte[(int)file.length()];
|
||||||
|
|
|
@ -61,7 +61,6 @@ public class TLClassStore {
|
||||||
classStore.put(TLRPC.TL_account_privacyRules.constructor, TLRPC.TL_account_privacyRules.class);
|
classStore.put(TLRPC.TL_account_privacyRules.constructor, TLRPC.TL_account_privacyRules.class);
|
||||||
classStore.put(TLRPC.TL_help_appUpdate.constructor, TLRPC.TL_help_appUpdate.class);
|
classStore.put(TLRPC.TL_help_appUpdate.constructor, TLRPC.TL_help_appUpdate.class);
|
||||||
classStore.put(TLRPC.TL_help_noAppUpdate.constructor, TLRPC.TL_help_noAppUpdate.class);
|
classStore.put(TLRPC.TL_help_noAppUpdate.constructor, TLRPC.TL_help_noAppUpdate.class);
|
||||||
classStore.put(TLRPC.TL_messageForwarded.constructor, TLRPC.TL_messageForwarded.class);
|
|
||||||
classStore.put(TLRPC.TL_messageEmpty.constructor, TLRPC.TL_messageEmpty.class);
|
classStore.put(TLRPC.TL_messageEmpty.constructor, TLRPC.TL_messageEmpty.class);
|
||||||
classStore.put(TLRPC.TL_message.constructor, TLRPC.TL_message.class);
|
classStore.put(TLRPC.TL_message.constructor, TLRPC.TL_message.class);
|
||||||
classStore.put(TLRPC.TL_messageService.constructor, TLRPC.TL_messageService.class);
|
classStore.put(TLRPC.TL_messageService.constructor, TLRPC.TL_messageService.class);
|
||||||
|
@ -125,8 +124,6 @@ public class TLClassStore {
|
||||||
classStore.put(TLRPC.TL_boolTrue.constructor, TLRPC.TL_boolTrue.class);
|
classStore.put(TLRPC.TL_boolTrue.constructor, TLRPC.TL_boolTrue.class);
|
||||||
classStore.put(TLRPC.TL_boolFalse.constructor, TLRPC.TL_boolFalse.class);
|
classStore.put(TLRPC.TL_boolFalse.constructor, TLRPC.TL_boolFalse.class);
|
||||||
classStore.put(TLRPC.TL_auth_exportedAuthorization.constructor, TLRPC.TL_auth_exportedAuthorization.class);
|
classStore.put(TLRPC.TL_auth_exportedAuthorization.constructor, TLRPC.TL_auth_exportedAuthorization.class);
|
||||||
classStore.put(TLRPC.TL_messages_statedMessagesLinks.constructor, TLRPC.TL_messages_statedMessagesLinks.class);
|
|
||||||
classStore.put(TLRPC.TL_messages_statedMessages.constructor, TLRPC.TL_messages_statedMessages.class);
|
|
||||||
classStore.put(TLRPC.TL_inputNotifyChats.constructor, TLRPC.TL_inputNotifyChats.class);
|
classStore.put(TLRPC.TL_inputNotifyChats.constructor, TLRPC.TL_inputNotifyChats.class);
|
||||||
classStore.put(TLRPC.TL_inputNotifyPeer.constructor, TLRPC.TL_inputNotifyPeer.class);
|
classStore.put(TLRPC.TL_inputNotifyPeer.constructor, TLRPC.TL_inputNotifyPeer.class);
|
||||||
classStore.put(TLRPC.TL_inputNotifyUsers.constructor, TLRPC.TL_inputNotifyUsers.class);
|
classStore.put(TLRPC.TL_inputNotifyUsers.constructor, TLRPC.TL_inputNotifyUsers.class);
|
||||||
|
@ -157,9 +154,6 @@ public class TLClassStore {
|
||||||
classStore.put(TLRPC.TL_messageActionChatEditTitle.constructor, TLRPC.TL_messageActionChatEditTitle.class);
|
classStore.put(TLRPC.TL_messageActionChatEditTitle.constructor, TLRPC.TL_messageActionChatEditTitle.class);
|
||||||
classStore.put(TLRPC.TL_messageActionGeoChatCreate.constructor, TLRPC.TL_messageActionGeoChatCreate.class);
|
classStore.put(TLRPC.TL_messageActionGeoChatCreate.constructor, TLRPC.TL_messageActionGeoChatCreate.class);
|
||||||
classStore.put(TLRPC.TL_messageActionGeoChatCheckin.constructor, TLRPC.TL_messageActionGeoChatCheckin.class);
|
classStore.put(TLRPC.TL_messageActionGeoChatCheckin.constructor, TLRPC.TL_messageActionGeoChatCheckin.class);
|
||||||
classStore.put(TLRPC.TL_contacts_foreignLinkMutual.constructor, TLRPC.TL_contacts_foreignLinkMutual.class);
|
|
||||||
classStore.put(TLRPC.TL_contacts_foreignLinkUnknown.constructor, TLRPC.TL_contacts_foreignLinkUnknown.class);
|
|
||||||
classStore.put(TLRPC.TL_contacts_foreignLinkRequested.constructor, TLRPC.TL_contacts_foreignLinkRequested.class);
|
|
||||||
classStore.put(TLRPC.TL_dh_gen_retry.constructor, TLRPC.TL_dh_gen_retry.class);
|
classStore.put(TLRPC.TL_dh_gen_retry.constructor, TLRPC.TL_dh_gen_retry.class);
|
||||||
classStore.put(TLRPC.TL_dh_gen_fail.constructor, TLRPC.TL_dh_gen_fail.class);
|
classStore.put(TLRPC.TL_dh_gen_fail.constructor, TLRPC.TL_dh_gen_fail.class);
|
||||||
classStore.put(TLRPC.TL_dh_gen_ok.constructor, TLRPC.TL_dh_gen_ok.class);
|
classStore.put(TLRPC.TL_dh_gen_ok.constructor, TLRPC.TL_dh_gen_ok.class);
|
||||||
|
@ -216,12 +210,12 @@ public class TLClassStore {
|
||||||
classStore.put(TLRPC.TL_userStatusRecently.constructor, TLRPC.TL_userStatusRecently.class);
|
classStore.put(TLRPC.TL_userStatusRecently.constructor, TLRPC.TL_userStatusRecently.class);
|
||||||
classStore.put(TLRPC.TL_msg_copy.constructor, TLRPC.TL_msg_copy.class);
|
classStore.put(TLRPC.TL_msg_copy.constructor, TLRPC.TL_msg_copy.class);
|
||||||
classStore.put(TLRPC.TL_contacts_importedContacts.constructor, TLRPC.TL_contacts_importedContacts.class);
|
classStore.put(TLRPC.TL_contacts_importedContacts.constructor, TLRPC.TL_contacts_importedContacts.class);
|
||||||
|
classStore.put(TLRPC.TL_disabledFeature.constructor, TLRPC.TL_disabledFeature.class);
|
||||||
classStore.put(TLRPC.TL_futureSalt.constructor, TLRPC.TL_futureSalt.class);
|
classStore.put(TLRPC.TL_futureSalt.constructor, TLRPC.TL_futureSalt.class);
|
||||||
classStore.put(TLRPC.TL_updateEncryptedMessagesRead.constructor, TLRPC.TL_updateEncryptedMessagesRead.class);
|
classStore.put(TLRPC.TL_updateEncryptedMessagesRead.constructor, TLRPC.TL_updateEncryptedMessagesRead.class);
|
||||||
classStore.put(TLRPC.TL_updateContactLink.constructor, TLRPC.TL_updateContactLink.class);
|
classStore.put(TLRPC.TL_updateContactLink.constructor, TLRPC.TL_updateContactLink.class);
|
||||||
classStore.put(TLRPC.TL_updateReadMessages.constructor, TLRPC.TL_updateReadMessages.class);
|
classStore.put(TLRPC.TL_updateReadMessages.constructor, TLRPC.TL_updateReadMessages.class);
|
||||||
classStore.put(TLRPC.TL_updateChatParticipantDelete.constructor, TLRPC.TL_updateChatParticipantDelete.class);
|
classStore.put(TLRPC.TL_updateChatParticipantDelete.constructor, TLRPC.TL_updateChatParticipantDelete.class);
|
||||||
classStore.put(TLRPC.TL_updateRestoreMessages.constructor, TLRPC.TL_updateRestoreMessages.class);
|
|
||||||
classStore.put(TLRPC.TL_updateServiceNotification.constructor, TLRPC.TL_updateServiceNotification.class);
|
classStore.put(TLRPC.TL_updateServiceNotification.constructor, TLRPC.TL_updateServiceNotification.class);
|
||||||
classStore.put(TLRPC.TL_updateNotifySettings.constructor, TLRPC.TL_updateNotifySettings.class);
|
classStore.put(TLRPC.TL_updateNotifySettings.constructor, TLRPC.TL_updateNotifySettings.class);
|
||||||
classStore.put(TLRPC.TL_updateUserTyping.constructor, TLRPC.TL_updateUserTyping.class);
|
classStore.put(TLRPC.TL_updateUserTyping.constructor, TLRPC.TL_updateUserTyping.class);
|
||||||
|
@ -259,9 +253,6 @@ public class TLClassStore {
|
||||||
classStore.put(TLRPC.TL_decryptedMessageActionTyping.constructor, TLRPC.TL_decryptedMessageActionTyping.class);
|
classStore.put(TLRPC.TL_decryptedMessageActionTyping.constructor, TLRPC.TL_decryptedMessageActionTyping.class);
|
||||||
classStore.put(TLRPC.TL_decryptedMessageActionReadMessages.constructor, TLRPC.TL_decryptedMessageActionReadMessages.class);
|
classStore.put(TLRPC.TL_decryptedMessageActionReadMessages.constructor, TLRPC.TL_decryptedMessageActionReadMessages.class);
|
||||||
classStore.put(TLRPC.TL_decryptedMessageActionScreenshotMessages.constructor, TLRPC.TL_decryptedMessageActionScreenshotMessages.class);
|
classStore.put(TLRPC.TL_decryptedMessageActionScreenshotMessages.constructor, TLRPC.TL_decryptedMessageActionScreenshotMessages.class);
|
||||||
classStore.put(TLRPC.TL_contacts_myLinkRequested.constructor, TLRPC.TL_contacts_myLinkRequested.class);
|
|
||||||
classStore.put(TLRPC.TL_contacts_myLinkContact.constructor, TLRPC.TL_contacts_myLinkContact.class);
|
|
||||||
classStore.put(TLRPC.TL_contacts_myLinkEmpty.constructor, TLRPC.TL_contacts_myLinkEmpty.class);
|
|
||||||
classStore.put(TLRPC.TL_server_DH_inner_data.constructor, TLRPC.TL_server_DH_inner_data.class);
|
classStore.put(TLRPC.TL_server_DH_inner_data.constructor, TLRPC.TL_server_DH_inner_data.class);
|
||||||
classStore.put(TLRPC.TL_new_session_created.constructor, TLRPC.TL_new_session_created.class);
|
classStore.put(TLRPC.TL_new_session_created.constructor, TLRPC.TL_new_session_created.class);
|
||||||
classStore.put(TLRPC.TL_account_password.constructor, TLRPC.TL_account_password.class);
|
classStore.put(TLRPC.TL_account_password.constructor, TLRPC.TL_account_password.class);
|
||||||
|
@ -329,8 +320,6 @@ public class TLClassStore {
|
||||||
classStore.put(TLRPC.TL_contactFound.constructor, TLRPC.TL_contactFound.class);
|
classStore.put(TLRPC.TL_contactFound.constructor, TLRPC.TL_contactFound.class);
|
||||||
classStore.put(TLRPC.TL_inputFileBig.constructor, TLRPC.TL_inputFileBig.class);
|
classStore.put(TLRPC.TL_inputFileBig.constructor, TLRPC.TL_inputFileBig.class);
|
||||||
classStore.put(TLRPC.TL_inputFile.constructor, TLRPC.TL_inputFile.class);
|
classStore.put(TLRPC.TL_inputFile.constructor, TLRPC.TL_inputFile.class);
|
||||||
classStore.put(TLRPC.TL_messages_statedMessageLink.constructor, TLRPC.TL_messages_statedMessageLink.class);
|
|
||||||
classStore.put(TLRPC.TL_messages_statedMessage.constructor, TLRPC.TL_messages_statedMessage.class);
|
|
||||||
classStore.put(TLRPC.TL_userFull.constructor, TLRPC.TL_userFull.class);
|
classStore.put(TLRPC.TL_userFull.constructor, TLRPC.TL_userFull.class);
|
||||||
classStore.put(TLRPC.TL_updates_state.constructor, TLRPC.TL_updates_state.class);
|
classStore.put(TLRPC.TL_updates_state.constructor, TLRPC.TL_updates_state.class);
|
||||||
classStore.put(TLRPC.TL_resPQ.constructor, TLRPC.TL_resPQ.class);
|
classStore.put(TLRPC.TL_resPQ.constructor, TLRPC.TL_resPQ.class);
|
||||||
|
@ -340,7 +329,6 @@ public class TLClassStore {
|
||||||
classStore.put(TLRPC.TL_updateShort.constructor, TLRPC.TL_updateShort.class);
|
classStore.put(TLRPC.TL_updateShort.constructor, TLRPC.TL_updateShort.class);
|
||||||
classStore.put(TLRPC.TL_updatesCombined.constructor, TLRPC.TL_updatesCombined.class);
|
classStore.put(TLRPC.TL_updatesCombined.constructor, TLRPC.TL_updatesCombined.class);
|
||||||
classStore.put(TLRPC.TL_updatesTooLong.constructor, TLRPC.TL_updatesTooLong.class);
|
classStore.put(TLRPC.TL_updatesTooLong.constructor, TLRPC.TL_updatesTooLong.class);
|
||||||
classStore.put(TLRPC.TL_messages_chat.constructor, TLRPC.TL_messages_chat.class);
|
|
||||||
classStore.put(TLRPC.TL_wallPaper.constructor, TLRPC.TL_wallPaper.class);
|
classStore.put(TLRPC.TL_wallPaper.constructor, TLRPC.TL_wallPaper.class);
|
||||||
classStore.put(TLRPC.TL_wallPaperSolid.constructor, TLRPC.TL_wallPaperSolid.class);
|
classStore.put(TLRPC.TL_wallPaperSolid.constructor, TLRPC.TL_wallPaperSolid.class);
|
||||||
classStore.put(TLRPC.TL_msg_new_detailed_info.constructor, TLRPC.TL_msg_new_detailed_info.class);
|
classStore.put(TLRPC.TL_msg_new_detailed_info.constructor, TLRPC.TL_msg_new_detailed_info.class);
|
||||||
|
@ -378,7 +366,27 @@ public class TLClassStore {
|
||||||
classStore.put(TLRPC.TL_decryptedMessageActionAbortKey.constructor, TLRPC.TL_decryptedMessageActionAbortKey.class);
|
classStore.put(TLRPC.TL_decryptedMessageActionAbortKey.constructor, TLRPC.TL_decryptedMessageActionAbortKey.class);
|
||||||
classStore.put(TLRPC.TL_decryptedMessageActionNoop.constructor, TLRPC.TL_decryptedMessageActionNoop.class);
|
classStore.put(TLRPC.TL_decryptedMessageActionNoop.constructor, TLRPC.TL_decryptedMessageActionNoop.class);
|
||||||
classStore.put(TLRPC.TL_decryptedMessageMediaExternalDocument.constructor, TLRPC.TL_decryptedMessageMediaExternalDocument.class);
|
classStore.put(TLRPC.TL_decryptedMessageMediaExternalDocument.constructor, TLRPC.TL_decryptedMessageMediaExternalDocument.class);
|
||||||
|
classStore.put(TLRPC.TL_updateReadHistoryInbox.constructor, TLRPC.TL_updateReadHistoryInbox.class);
|
||||||
|
classStore.put(TLRPC.TL_updateReadHistoryOutbox.constructor, TLRPC.TL_updateReadHistoryOutbox.class);
|
||||||
|
classStore.put(TLRPC.TL_contactLinkUnknown.constructor, TLRPC.TL_contactLinkUnknown.class);
|
||||||
|
classStore.put(TLRPC.TL_contactLinkNone.constructor, TLRPC.TL_contactLinkNone.class);
|
||||||
|
classStore.put(TLRPC.TL_contactLinkHasPhone.constructor, TLRPC.TL_contactLinkHasPhone.class);
|
||||||
|
classStore.put(TLRPC.TL_contactLinkContact.constructor, TLRPC.TL_contactLinkContact.class);
|
||||||
|
classStore.put(TLRPC.TL_messages_affectedMessages.constructor, TLRPC.TL_messages_affectedMessages.class);
|
||||||
|
classStore.put(TLRPC.TL_updateWebPage.constructor, TLRPC.TL_updateWebPage.class);
|
||||||
|
classStore.put(TLRPC.TL_webPagePending.constructor, TLRPC.TL_webPagePending.class);
|
||||||
|
classStore.put(TLRPC.TL_webPageEmpty.constructor, TLRPC.TL_webPageEmpty.class);
|
||||||
|
classStore.put(TLRPC.TL_webPage.constructor, TLRPC.TL_webPage.class);
|
||||||
|
classStore.put(TLRPC.TL_messageMediaWebPage.constructor, TLRPC.TL_messageMediaWebPage.class);
|
||||||
|
classStore.put(TLRPC.TL_authorization.constructor, TLRPC.TL_authorization.class);
|
||||||
|
classStore.put(TLRPC.TL_account_authorizations.constructor, TLRPC.TL_account_authorizations.class);
|
||||||
|
classStore.put(TLRPC.TL_account_passwordSettings.constructor, TLRPC.TL_account_passwordSettings.class);
|
||||||
|
classStore.put(TLRPC.TL_account_passwordInputSettings.constructor, TLRPC.TL_account_passwordInputSettings.class);
|
||||||
|
classStore.put(TLRPC.TL_auth_passwordRecovery.constructor, TLRPC.TL_auth_passwordRecovery.class);
|
||||||
|
classStore.put(TLRPC.TL_messages_getWebPagePreview.constructor, TLRPC.TL_messages_getWebPagePreview.class);
|
||||||
|
|
||||||
|
classStore.put(TLRPC.TL_messageMediaUnsupported_old.constructor, TLRPC.TL_messageMediaUnsupported_old.class);
|
||||||
|
classStore.put(TLRPC.TL_userSelf_old2.constructor, TLRPC.TL_userSelf_old2.class);
|
||||||
classStore.put(TLRPC.TL_msg_container.constructor, TLRPC.TL_msg_container.class);
|
classStore.put(TLRPC.TL_msg_container.constructor, TLRPC.TL_msg_container.class);
|
||||||
classStore.put(TLRPC.TL_fileEncryptedLocation.constructor, TLRPC.TL_fileEncryptedLocation.class);
|
classStore.put(TLRPC.TL_fileEncryptedLocation.constructor, TLRPC.TL_fileEncryptedLocation.class);
|
||||||
classStore.put(TLRPC.TL_messageActionTTLChange.constructor, TLRPC.TL_messageActionTTLChange.class);
|
classStore.put(TLRPC.TL_messageActionTTLChange.constructor, TLRPC.TL_messageActionTTLChange.class);
|
||||||
|
@ -413,6 +421,10 @@ public class TLClassStore {
|
||||||
classStore.put(TLRPC.TL_decryptedMessageHolder.constructor, TLRPC.TL_decryptedMessageHolder.class);
|
classStore.put(TLRPC.TL_decryptedMessageHolder.constructor, TLRPC.TL_decryptedMessageHolder.class);
|
||||||
classStore.put(TLRPC.TL_documentEncrypted_old.constructor, TLRPC.TL_documentEncrypted_old.class);
|
classStore.put(TLRPC.TL_documentEncrypted_old.constructor, TLRPC.TL_documentEncrypted_old.class);
|
||||||
classStore.put(TLRPC.TL_document_old.constructor, TLRPC.TL_document_old.class);
|
classStore.put(TLRPC.TL_document_old.constructor, TLRPC.TL_document_old.class);
|
||||||
|
classStore.put(TLRPC.TL_config_old.constructor, TLRPC.TL_config_old.class);
|
||||||
|
classStore.put(TLRPC.TL_messageForwarded_old2.constructor, TLRPC.TL_messageForwarded_old2.class);
|
||||||
|
classStore.put(TLRPC.TL_message_old2.constructor, TLRPC.TL_message_old2.class);
|
||||||
|
classStore.put(TLRPC.TL_documentAttributeSticker_old.constructor, TLRPC.TL_documentAttributeSticker_old.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
static TLClassStore store = null;
|
static TLClassStore store = null;
|
||||||
|
@ -459,8 +471,11 @@ public class TLClassStore {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
FileLog.e("tmessages", String.format("unknown class %x", constructor));
|
FileLog.e("tmessages", String.format("unknown class %x", constructor));
|
||||||
return null;
|
if (BuildVars.DEBUG_VERSION) {
|
||||||
//throw new RuntimeException(String.format("unknown class %x", constructor));
|
throw new RuntimeException(String.format("unknown class %x", constructor));
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -28,11 +28,11 @@ public class TcpConnection extends ConnectionContext {
|
||||||
TcpConnectionStageSuspended
|
TcpConnectionStageSuspended
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract static interface TcpConnectionDelegate {
|
public interface TcpConnectionDelegate {
|
||||||
public abstract void tcpConnectionClosed(TcpConnection connection);
|
void tcpConnectionClosed(TcpConnection connection);
|
||||||
public abstract void tcpConnectionConnected(TcpConnection connection);
|
void tcpConnectionConnected(TcpConnection connection);
|
||||||
public abstract void tcpConnectionQuiackAckReceived(TcpConnection connection, int ack);
|
void tcpConnectionQuiackAckReceived(TcpConnection connection, int ack);
|
||||||
public abstract void tcpConnectionReceivedData(TcpConnection connection, ByteBufferDesc data, int length);
|
void tcpConnectionReceivedData(TcpConnection connection, ByteBufferDesc data, int length);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static PyroSelector selector;
|
private static PyroSelector selector;
|
||||||
|
|
|
@ -30,7 +30,12 @@ public class UserConfig {
|
||||||
private final static Object sync = new Object();
|
private final static Object sync = new Object();
|
||||||
public static boolean saveIncomingPhotos = false;
|
public static boolean saveIncomingPhotos = false;
|
||||||
public static int contactsVersion = 1;
|
public static int contactsVersion = 1;
|
||||||
public static boolean waitingForPasswordEnter = false;
|
public static String passcodeHash = "";
|
||||||
|
public static boolean appLocked = false;
|
||||||
|
public static int passcodeType = 0;
|
||||||
|
public static int autoLockIn = 60 * 60;
|
||||||
|
public static int lastPauseTime = 0;
|
||||||
|
public static boolean isWaitingForPasscodeEnter = false;
|
||||||
|
|
||||||
public static int getNewMessageId() {
|
public static int getNewMessageId() {
|
||||||
int id;
|
int id;
|
||||||
|
@ -61,13 +66,19 @@ public class UserConfig {
|
||||||
editor.putInt("lastBroadcastId", lastBroadcastId);
|
editor.putInt("lastBroadcastId", lastBroadcastId);
|
||||||
editor.putBoolean("registeredForInternalPush", registeredForInternalPush);
|
editor.putBoolean("registeredForInternalPush", registeredForInternalPush);
|
||||||
editor.putBoolean("blockedUsersLoaded", blockedUsersLoaded);
|
editor.putBoolean("blockedUsersLoaded", blockedUsersLoaded);
|
||||||
editor.putBoolean("waitingForPasswordEnter", waitingForPasswordEnter);
|
editor.putString("passcodeHash1", passcodeHash);
|
||||||
|
editor.putBoolean("appLocked", appLocked);
|
||||||
|
editor.putInt("passcodeType", passcodeType);
|
||||||
|
editor.putInt("autoLockIn", autoLockIn);
|
||||||
|
editor.putInt("lastPauseTime", lastPauseTime);
|
||||||
|
|
||||||
if (currentUser != null) {
|
if (currentUser != null) {
|
||||||
if (withFile) {
|
if (withFile) {
|
||||||
SerializedData data = new SerializedData();
|
SerializedData data = new SerializedData();
|
||||||
currentUser.serializeToStream(data);
|
currentUser.serializeToStream(data);
|
||||||
String userString = Base64.encodeToString(data.toByteArray(), Base64.DEFAULT);
|
String userString = Base64.encodeToString(data.toByteArray(), Base64.DEFAULT);
|
||||||
editor.putString("user", userString);
|
editor.putString("user", userString);
|
||||||
|
data.cleanup();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
editor.remove("user");
|
editor.remove("user");
|
||||||
|
@ -88,18 +99,6 @@ public class UserConfig {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isWaitingForPasswordEnter() {
|
|
||||||
synchronized (sync) {
|
|
||||||
return waitingForPasswordEnter;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setWaitingForPasswordEnter(boolean value) {
|
|
||||||
synchronized (sync) {
|
|
||||||
waitingForPasswordEnter = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getClientUserId() {
|
public static int getClientUserId() {
|
||||||
synchronized (sync) {
|
synchronized (sync) {
|
||||||
return currentUser != null ? currentUser.id : 0;
|
return currentUser != null ? currentUser.id : 0;
|
||||||
|
@ -172,6 +171,7 @@ public class UserConfig {
|
||||||
if (lastSendMessageId > -210000) {
|
if (lastSendMessageId > -210000) {
|
||||||
lastSendMessageId = -210000;
|
lastSendMessageId = -210000;
|
||||||
}
|
}
|
||||||
|
data.cleanup();
|
||||||
Utilities.stageQueue.postRunnable(new Runnable() {
|
Utilities.stageQueue.postRunnable(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -194,13 +194,18 @@ public class UserConfig {
|
||||||
lastBroadcastId = preferences.getInt("lastBroadcastId", -1);
|
lastBroadcastId = preferences.getInt("lastBroadcastId", -1);
|
||||||
registeredForInternalPush = preferences.getBoolean("registeredForInternalPush", false);
|
registeredForInternalPush = preferences.getBoolean("registeredForInternalPush", false);
|
||||||
blockedUsersLoaded = preferences.getBoolean("blockedUsersLoaded", false);
|
blockedUsersLoaded = preferences.getBoolean("blockedUsersLoaded", false);
|
||||||
waitingForPasswordEnter = preferences.getBoolean("waitingForPasswordEnter", false);
|
passcodeHash = preferences.getString("passcodeHash1", "");
|
||||||
|
appLocked = preferences.getBoolean("appLocked", false);
|
||||||
|
passcodeType = preferences.getInt("passcodeType", 0);
|
||||||
|
autoLockIn = preferences.getInt("autoLockIn", 60 * 60);
|
||||||
|
lastPauseTime = preferences.getInt("lastPauseTime", 0);
|
||||||
String user = preferences.getString("user", null);
|
String user = preferences.getString("user", null);
|
||||||
if (user != null) {
|
if (user != null) {
|
||||||
byte[] userBytes = Base64.decode(user, Base64.DEFAULT);
|
byte[] userBytes = Base64.decode(user, Base64.DEFAULT);
|
||||||
if (userBytes != null) {
|
if (userBytes != null) {
|
||||||
SerializedData data = new SerializedData(userBytes);
|
SerializedData data = new SerializedData(userBytes);
|
||||||
currentUser = (TLRPC.TL_userSelf)TLClassStore.Instance().TLdeserialize(data, data.readInt32());
|
currentUser = (TLRPC.TL_userSelf)TLClassStore.Instance().TLdeserialize(data, data.readInt32());
|
||||||
|
data.cleanup();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -211,15 +216,19 @@ public class UserConfig {
|
||||||
currentUser = null;
|
currentUser = null;
|
||||||
registeredForInternalPush = false;
|
registeredForInternalPush = false;
|
||||||
registeredForPush = false;
|
registeredForPush = false;
|
||||||
waitingForPasswordEnter = false;
|
|
||||||
contactsHash = "";
|
contactsHash = "";
|
||||||
importHash = "";
|
importHash = "";
|
||||||
lastLocalId = -210000;
|
|
||||||
lastSendMessageId = -210000;
|
lastSendMessageId = -210000;
|
||||||
contactsVersion = 1;
|
contactsVersion = 1;
|
||||||
lastBroadcastId = -1;
|
lastBroadcastId = -1;
|
||||||
saveIncomingPhotos = false;
|
saveIncomingPhotos = false;
|
||||||
blockedUsersLoaded = false;
|
blockedUsersLoaded = false;
|
||||||
|
appLocked = false;
|
||||||
|
passcodeType = 0;
|
||||||
|
passcodeHash = "";
|
||||||
|
autoLockIn = 60 * 60;
|
||||||
|
lastPauseTime = 0;
|
||||||
|
isWaitingForPasscodeEnter = false;
|
||||||
saveConfig(true);
|
saveConfig(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,6 @@ import android.os.Build;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.provider.DocumentsContract;
|
import android.provider.DocumentsContract;
|
||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
import android.text.Html;
|
|
||||||
import android.text.SpannableStringBuilder;
|
import android.text.SpannableStringBuilder;
|
||||||
import android.util.Base64;
|
import android.util.Base64;
|
||||||
|
|
||||||
|
@ -29,6 +28,8 @@ import net.hockeyapp.android.CrashManager;
|
||||||
import net.hockeyapp.android.CrashManagerListener;
|
import net.hockeyapp.android.CrashManagerListener;
|
||||||
import net.hockeyapp.android.UpdateManager;
|
import net.hockeyapp.android.UpdateManager;
|
||||||
|
|
||||||
|
import org.telegram.android.AndroidUtilities;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -39,7 +40,6 @@ import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.channels.FileChannel;
|
|
||||||
import java.security.KeyFactory;
|
import java.security.KeyFactory;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.PublicKey;
|
import java.security.PublicKey;
|
||||||
|
@ -97,6 +97,7 @@ public class Utilities {
|
||||||
for (int a = 0; a < count; a++) {
|
for (int a = 0; a < count; a++) {
|
||||||
goodPrimes.add(data.readString());
|
goodPrimes.add(data.readString());
|
||||||
}
|
}
|
||||||
|
data.cleanup();
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
FileLog.e("tmessages", e);
|
FileLog.e("tmessages", e);
|
||||||
|
@ -108,7 +109,9 @@ public class Utilities {
|
||||||
|
|
||||||
public native static long doPQNative(long _what);
|
public native static long doPQNative(long _what);
|
||||||
public native static void loadBitmap(String path, Bitmap bitmap, int scale, int width, int height, int stride);
|
public native static void loadBitmap(String path, Bitmap bitmap, int scale, int width, int height, int stride);
|
||||||
|
public native static int pinBitmap(Bitmap bitmap);
|
||||||
public native static void blurBitmap(Object bitmap, int radius);
|
public native static void blurBitmap(Object bitmap, int radius);
|
||||||
|
public native static void calcCDT(ByteBuffer hsvBuffer, int width, int height, ByteBuffer buffer);
|
||||||
public native static Bitmap loadWebpImage(ByteBuffer buffer, int len, BitmapFactory.Options options);
|
public native static Bitmap loadWebpImage(ByteBuffer buffer, int len, BitmapFactory.Options options);
|
||||||
public native static Bitmap loadBpgImage(ByteBuffer buffer, int len, BitmapFactory.Options options);
|
public native static Bitmap loadBpgImage(ByteBuffer buffer, int len, BitmapFactory.Options options);
|
||||||
public native static int convertVideoFrame(ByteBuffer src, ByteBuffer dest, int destFormat, int width, int height, int padding, int swap);
|
public native static int convertVideoFrame(ByteBuffer src, ByteBuffer dest, int destFormat, int width, int height, int padding, int swap);
|
||||||
|
@ -144,6 +147,9 @@ public class Utilities {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String bytesToHex(byte[] bytes) {
|
public static String bytesToHex(byte[] bytes) {
|
||||||
|
if (bytes == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
char[] hexChars = new char[bytes.length * 2];
|
char[] hexChars = new char[bytes.length * 2];
|
||||||
int v;
|
int v;
|
||||||
for (int j = 0; j < bytes.length; j++) {
|
for (int j = 0; j < bytes.length; j++) {
|
||||||
|
@ -155,6 +161,9 @@ public class Utilities {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] hexToBytes(String hex) {
|
public static byte[] hexToBytes(String hex) {
|
||||||
|
if (hex == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
int len = hex.length();
|
int len = hex.length();
|
||||||
byte[] data = new byte[len / 2];
|
byte[] data = new byte[len / 2];
|
||||||
for (int i = 0; i < len; i += 2) {
|
for (int i = 0; i < len; i += 2) {
|
||||||
|
@ -228,6 +237,7 @@ public class Utilities {
|
||||||
data.writeString(pr);
|
data.writeString(pr);
|
||||||
}
|
}
|
||||||
byte[] bytes = data.toByteArray();
|
byte[] bytes = data.toByteArray();
|
||||||
|
data.cleanup();
|
||||||
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("primes", Context.MODE_PRIVATE);
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("primes", Context.MODE_PRIVATE);
|
||||||
SharedPreferences.Editor editor = preferences.edit();
|
SharedPreferences.Editor editor = preferences.edit();
|
||||||
editor.putString("primes", Base64.encodeToString(bytes, Base64.DEFAULT));
|
editor.putString("primes", Base64.encodeToString(bytes, Base64.DEFAULT));
|
||||||
|
@ -363,35 +373,41 @@ public class Utilities {
|
||||||
data.writeRaw(messageKey);
|
data.writeRaw(messageKey);
|
||||||
data.writeRaw(authKey, x, 32);
|
data.writeRaw(authKey, x, 32);
|
||||||
byte[] sha1_a = Utilities.computeSHA1(data.toByteArray());
|
byte[] sha1_a = Utilities.computeSHA1(data.toByteArray());
|
||||||
|
data.cleanup();
|
||||||
|
|
||||||
data = new SerializedData();
|
data = new SerializedData();
|
||||||
data.writeRaw(authKey, 32 + x, 16);
|
data.writeRaw(authKey, 32 + x, 16);
|
||||||
data.writeRaw(messageKey);
|
data.writeRaw(messageKey);
|
||||||
data.writeRaw(authKey, 48 + x, 16);
|
data.writeRaw(authKey, 48 + x, 16);
|
||||||
byte[] sha1_b = Utilities.computeSHA1(data.toByteArray());
|
byte[] sha1_b = Utilities.computeSHA1(data.toByteArray());
|
||||||
|
data.cleanup();
|
||||||
|
|
||||||
data = new SerializedData();
|
data = new SerializedData();
|
||||||
data.writeRaw(authKey, 64 + x, 32);
|
data.writeRaw(authKey, 64 + x, 32);
|
||||||
data.writeRaw(messageKey);
|
data.writeRaw(messageKey);
|
||||||
byte[] sha1_c = Utilities.computeSHA1(data.toByteArray());
|
byte[] sha1_c = Utilities.computeSHA1(data.toByteArray());
|
||||||
|
data.cleanup();
|
||||||
|
|
||||||
data = new SerializedData();
|
data = new SerializedData();
|
||||||
data.writeRaw(messageKey);
|
data.writeRaw(messageKey);
|
||||||
data.writeRaw(authKey, 96 + x, 32);
|
data.writeRaw(authKey, 96 + x, 32);
|
||||||
byte[] sha1_d = Utilities.computeSHA1(data.toByteArray());
|
byte[] sha1_d = Utilities.computeSHA1(data.toByteArray());
|
||||||
|
data.cleanup();
|
||||||
|
|
||||||
SerializedData aesKey = new SerializedData();
|
data = new SerializedData();
|
||||||
aesKey.writeRaw(sha1_a, 0, 8);
|
data.writeRaw(sha1_a, 0, 8);
|
||||||
aesKey.writeRaw(sha1_b, 8, 12);
|
data.writeRaw(sha1_b, 8, 12);
|
||||||
aesKey.writeRaw(sha1_c, 4, 12);
|
data.writeRaw(sha1_c, 4, 12);
|
||||||
keyData.aesKey = aesKey.toByteArray();
|
keyData.aesKey = data.toByteArray();
|
||||||
|
data.cleanup();
|
||||||
|
|
||||||
SerializedData aesIv = new SerializedData();
|
data = new SerializedData();
|
||||||
aesIv.writeRaw(sha1_a, 8, 12);
|
data.writeRaw(sha1_a, 8, 12);
|
||||||
aesIv.writeRaw(sha1_b, 0, 8);
|
data.writeRaw(sha1_b, 0, 8);
|
||||||
aesIv.writeRaw(sha1_c, 16, 4);
|
data.writeRaw(sha1_c, 16, 4);
|
||||||
aesIv.writeRaw(sha1_d, 0, 8);
|
data.writeRaw(sha1_d, 0, 8);
|
||||||
keyData.aesIv = aesIv.toByteArray();
|
keyData.aesIv = data.toByteArray();
|
||||||
|
data.cleanup();
|
||||||
|
|
||||||
return keyData;
|
return keyData;
|
||||||
}
|
}
|
||||||
|
@ -408,10 +424,25 @@ public class Utilities {
|
||||||
while ((bytesRead = gis.read(data)) != -1) {
|
while ((bytesRead = gis.read(data)) != -1) {
|
||||||
bytesOutput.write(data, 0, bytesRead);
|
bytesOutput.write(data, 0, bytesRead);
|
||||||
}
|
}
|
||||||
gis.close();
|
try {
|
||||||
is.close();
|
gis.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
FileLog.e("tmessages", e);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
is.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
FileLog.e("tmessages", e);
|
||||||
|
}
|
||||||
SerializedData stream = new SerializedData(bytesOutput.toByteArray());
|
SerializedData stream = new SerializedData(bytesOutput.toByteArray());
|
||||||
return TLClassStore.Instance().TLdeserialize(stream, stream.readInt32(), parentObject);
|
try {
|
||||||
|
bytesOutput.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
FileLog.e("tmessages", e);
|
||||||
|
}
|
||||||
|
TLObject object = TLClassStore.Instance().TLdeserialize(stream, stream.readInt32(), parentObject);
|
||||||
|
stream.cleanup();
|
||||||
|
return object;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
FileLog.e("tmessages", e);
|
FileLog.e("tmessages", e);
|
||||||
}
|
}
|
||||||
|
@ -432,6 +463,12 @@ public class Utilities {
|
||||||
packedData = bytesStream.toByteArray();
|
packedData = bytesStream.toByteArray();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
FileLog.e("tmessages", e);
|
FileLog.e("tmessages", e);
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
bytesStream.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
FileLog.e("tmessages", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return packedData;
|
return packedData;
|
||||||
}
|
}
|
||||||
|
@ -449,23 +486,23 @@ public class Utilities {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean copyFile(File sourceFile, File destFile) throws IOException {
|
public static boolean copyFile(File sourceFile, File destFile) throws IOException {
|
||||||
if(!destFile.exists()) {
|
if (!destFile.exists()) {
|
||||||
destFile.createNewFile();
|
destFile.createNewFile();
|
||||||
}
|
}
|
||||||
FileChannel source = null;
|
FileInputStream source = null;
|
||||||
FileChannel destination = null;
|
FileOutputStream destination = null;
|
||||||
try {
|
try {
|
||||||
source = new FileInputStream(sourceFile).getChannel();
|
source = new FileInputStream(sourceFile);
|
||||||
destination = new FileOutputStream(destFile).getChannel();
|
destination = new FileOutputStream(destFile);
|
||||||
destination.transferFrom(source, 0, source.size());
|
destination.getChannel().transferFrom(source.getChannel(), 0, source.getChannel().size());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
FileLog.e("tmessages", e);
|
FileLog.e("tmessages", e);
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
if(source != null) {
|
if (source != null) {
|
||||||
source.close();
|
source.close();
|
||||||
}
|
}
|
||||||
if(destination != null) {
|
if (destination != null) {
|
||||||
destination.close();
|
destination.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -656,7 +693,7 @@ public class Utilities {
|
||||||
builder.append(" ");
|
builder.append(" ");
|
||||||
}
|
}
|
||||||
query.trim();
|
query.trim();
|
||||||
builder.append(Html.fromHtml("<font color=\"#4d83b3\">" + query + "</font>"));
|
builder.append(AndroidUtilities.replaceTags("<c#ff4d83b3>" + query + "</c>"));
|
||||||
|
|
||||||
lastIndex = end;
|
lastIndex = end;
|
||||||
}
|
}
|
||||||
|
@ -711,7 +748,13 @@ public class Utilities {
|
||||||
buffer.write(b);
|
buffer.write(b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return buffer.toByteArray();
|
byte[] array = buffer.toByteArray();
|
||||||
|
try {
|
||||||
|
buffer.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
FileLog.e("tmessages", e);
|
||||||
|
}
|
||||||
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void checkForCrashes(Activity context) {
|
public static void checkForCrashes(Activity context) {
|
||||||
|
|
|
@ -1,629 +0,0 @@
|
||||||
/*
|
|
||||||
* This is the source code of Telegram for Android v. 2.0.x.
|
|
||||||
* It is licensed under GNU GPL v. 2 or later.
|
|
||||||
* You should have received a copy of the license in this archive (see LICENSE).
|
|
||||||
*
|
|
||||||
* Copyright Nikolai Kudashov, 2013-2014.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.telegram.ui;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.app.AlertDialog;
|
|
||||||
import android.app.ProgressDialog;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.view.Gravity;
|
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.widget.AdapterView;
|
|
||||||
import android.widget.FrameLayout;
|
|
||||||
import android.widget.ListView;
|
|
||||||
import android.widget.ProgressBar;
|
|
||||||
|
|
||||||
import org.telegram.android.AndroidUtilities;
|
|
||||||
import org.telegram.android.ContactsController;
|
|
||||||
import org.telegram.android.LocaleController;
|
|
||||||
import org.telegram.android.MessagesController;
|
|
||||||
import org.telegram.android.MessagesStorage;
|
|
||||||
import org.telegram.android.NotificationCenter;
|
|
||||||
import org.telegram.messenger.ApplicationLoader;
|
|
||||||
import org.telegram.messenger.ConnectionsManager;
|
|
||||||
import org.telegram.messenger.FileLog;
|
|
||||||
import org.telegram.messenger.R;
|
|
||||||
import org.telegram.messenger.RPCRequest;
|
|
||||||
import org.telegram.messenger.TLObject;
|
|
||||||
import org.telegram.messenger.TLRPC;
|
|
||||||
import org.telegram.messenger.UserConfig;
|
|
||||||
import org.telegram.messenger.Utilities;
|
|
||||||
import org.telegram.ui.ActionBar.ActionBar;
|
|
||||||
import org.telegram.ui.ActionBar.ActionBarMenu;
|
|
||||||
import org.telegram.ui.ActionBar.BaseFragment;
|
|
||||||
import org.telegram.ui.Adapters.BaseFragmentAdapter;
|
|
||||||
import org.telegram.ui.Cells.HeaderCell;
|
|
||||||
import org.telegram.ui.Cells.TextFieldCell;
|
|
||||||
import org.telegram.ui.Cells.TextInfoPrivacyCell;
|
|
||||||
import org.telegram.ui.Cells.TextSettingsCell;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
public class AccountPasswordActivity extends BaseFragment {
|
|
||||||
|
|
||||||
private ListAdapter listAdapter;
|
|
||||||
private TextFieldCell oldPasswordCell;
|
|
||||||
private TextFieldCell newPasswordCell;
|
|
||||||
private TextFieldCell verifyPasswordCell;
|
|
||||||
private TextFieldCell hintPasswordCell;
|
|
||||||
private View doneButton;
|
|
||||||
private ProgressDialog progressDialog;
|
|
||||||
|
|
||||||
private int type;
|
|
||||||
private boolean hasPassword;
|
|
||||||
private boolean loading;
|
|
||||||
private byte[] new_salt;
|
|
||||||
private String hint;
|
|
||||||
private byte[] current_salt;
|
|
||||||
|
|
||||||
private int changePasswordSectionRow;
|
|
||||||
private int oldPasswordRow;
|
|
||||||
private int newPasswordRow;
|
|
||||||
private int verifyPasswordRow;
|
|
||||||
private int hintRow;
|
|
||||||
private int passwordDetailRow;
|
|
||||||
private int deleteAccountSection;
|
|
||||||
private int deleteAccountRow;
|
|
||||||
private int deleteAccountDetailRow;
|
|
||||||
private int rowCount;
|
|
||||||
|
|
||||||
private final static int done_button = 1;
|
|
||||||
|
|
||||||
public AccountPasswordActivity(int type) {
|
|
||||||
super();
|
|
||||||
this.type = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onFragmentCreate() {
|
|
||||||
super.onFragmentCreate();
|
|
||||||
|
|
||||||
getCurrentPassword();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public View createView(LayoutInflater inflater, ViewGroup container) {
|
|
||||||
if (fragmentView == null) {
|
|
||||||
if (type == 0) {
|
|
||||||
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
|
|
||||||
}
|
|
||||||
actionBar.setAllowOverlayTitle(true);
|
|
||||||
actionBar.setTitle(LocaleController.getString("Password", R.string.Password));
|
|
||||||
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
|
|
||||||
@Override
|
|
||||||
public void onItemClick(int id) {
|
|
||||||
if (id == -1) {
|
|
||||||
finishFragment();
|
|
||||||
} else if (id == done_button) {
|
|
||||||
doneWithPassword();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
ActionBarMenu menu = actionBar.createMenu();
|
|
||||||
doneButton = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));
|
|
||||||
doneButton.setVisibility(loading ? View.GONE : View.VISIBLE);
|
|
||||||
|
|
||||||
if (type == 0) {
|
|
||||||
oldPasswordCell = new TextFieldCell(getParentActivity());
|
|
||||||
oldPasswordCell.setFieldTitleAndHint(LocaleController.getString("OldPassword", R.string.OldPassword), LocaleController.getString("EnterOldPassword", R.string.EnterOldPassword), AndroidUtilities.dp(10), true);
|
|
||||||
oldPasswordCell.setBackgroundColor(0xffffffff);
|
|
||||||
newPasswordCell = new TextFieldCell(getParentActivity());
|
|
||||||
newPasswordCell.setFieldTitleAndHint(LocaleController.getString("NewPassword", R.string.NewPassword), LocaleController.getString("EnterNewPassword", R.string.EnterNewPassword), 0, true);
|
|
||||||
newPasswordCell.setBackgroundColor(0xffffffff);
|
|
||||||
verifyPasswordCell = new TextFieldCell(getParentActivity());
|
|
||||||
verifyPasswordCell.setFieldTitleAndHint(null, LocaleController.getString("VerifyNewPassword", R.string.VerifyNewPassword), AndroidUtilities.dp(10), true);
|
|
||||||
verifyPasswordCell.setBackgroundColor(0xffffffff);
|
|
||||||
hintPasswordCell = new TextFieldCell(getParentActivity());
|
|
||||||
hintPasswordCell.setFieldTitleAndHint(LocaleController.getString("PasswordHint", R.string.PasswordHint), LocaleController.getString("EnterHint", R.string.EnterHint), AndroidUtilities.dp(22), false);
|
|
||||||
hintPasswordCell.setBackgroundColor(0xffffffff);
|
|
||||||
if (hint != null) {
|
|
||||||
hintPasswordCell.setFieldText(hint);
|
|
||||||
}
|
|
||||||
} else if (type == 1) {
|
|
||||||
oldPasswordCell = new TextFieldCell(getParentActivity());
|
|
||||||
oldPasswordCell.setFieldTitleAndHint(null, LocaleController.getString("EnterYourPassword", R.string.EnterYourPassword), AndroidUtilities.dp(22), true);
|
|
||||||
oldPasswordCell.setBackgroundColor(0xffffffff);
|
|
||||||
}
|
|
||||||
|
|
||||||
listAdapter = new ListAdapter(getParentActivity());
|
|
||||||
|
|
||||||
fragmentView = new FrameLayout(getParentActivity());
|
|
||||||
FrameLayout frameLayout = (FrameLayout) fragmentView;
|
|
||||||
frameLayout.setBackgroundColor(0xfff0f0f0);
|
|
||||||
|
|
||||||
FrameLayout progressView = new FrameLayout(getParentActivity());
|
|
||||||
frameLayout.addView(progressView);
|
|
||||||
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) progressView.getLayoutParams();
|
|
||||||
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
|
|
||||||
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
|
|
||||||
progressView.setLayoutParams(layoutParams);
|
|
||||||
|
|
||||||
ProgressBar progressBar = new ProgressBar(getParentActivity());
|
|
||||||
progressView.addView(progressBar);
|
|
||||||
layoutParams = (FrameLayout.LayoutParams) progressView.getLayoutParams();
|
|
||||||
layoutParams.width = FrameLayout.LayoutParams.WRAP_CONTENT;
|
|
||||||
layoutParams.height = FrameLayout.LayoutParams.WRAP_CONTENT;
|
|
||||||
layoutParams.gravity = Gravity.CENTER;
|
|
||||||
progressView.setLayoutParams(layoutParams);
|
|
||||||
|
|
||||||
ListView listView = new ListView(getParentActivity());
|
|
||||||
listView.setDivider(null);
|
|
||||||
listView.setDividerHeight(0);
|
|
||||||
listView.setVerticalScrollBarEnabled(false);
|
|
||||||
listView.setDrawSelectorOnTop(true);
|
|
||||||
listView.setEmptyView(progressView);
|
|
||||||
frameLayout.addView(listView);
|
|
||||||
layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
|
|
||||||
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
|
|
||||||
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
|
|
||||||
layoutParams.gravity = Gravity.TOP;
|
|
||||||
listView.setLayoutParams(layoutParams);
|
|
||||||
listView.setAdapter(listAdapter);
|
|
||||||
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) {
|
|
||||||
if (i == deleteAccountRow) {
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
|
||||||
builder.setMessage(LocaleController.getString("AreYouSureDeleteAccount", R.string.AreYouSureDeleteAccount));
|
|
||||||
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
|
|
||||||
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialogInterface, int i) {
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
|
||||||
builder.setMessage(LocaleController.getString("AreYouSureDeleteAccount2", R.string.AreYouSureDeleteAccount2));
|
|
||||||
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
|
|
||||||
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialogInterface, int i) {
|
|
||||||
TLRPC.TL_account_deleteAccount req = new TLRPC.TL_account_deleteAccount();
|
|
||||||
req.reason = "Forgot password";
|
|
||||||
ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() {
|
|
||||||
@Override
|
|
||||||
public void run(TLObject response, TLRPC.TL_error error) {
|
|
||||||
if (error == null) {
|
|
||||||
AndroidUtilities.runOnUIThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
|
|
||||||
SharedPreferences.Editor editor = preferences.edit();
|
|
||||||
editor.clear().commit();
|
|
||||||
MessagesController.getInstance().unregistedPush();
|
|
||||||
MessagesController.getInstance().logOut();
|
|
||||||
UserConfig.clearConfig();
|
|
||||||
NotificationCenter.getInstance().postNotificationName(NotificationCenter.appDidLogout);
|
|
||||||
MessagesStorage.getInstance().cleanUp(false);
|
|
||||||
MessagesController.getInstance().cleanUp();
|
|
||||||
ContactsController.getInstance().deleteAllAppAccounts();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassWithoutLogin);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
|
||||||
showAlertDialog(builder);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
|
||||||
showAlertDialog(builder);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
updateRows();
|
|
||||||
} else {
|
|
||||||
ViewGroup parent = (ViewGroup)fragmentView.getParent();
|
|
||||||
if (parent != null) {
|
|
||||||
parent.removeView(fragmentView);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return fragmentView;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onResume() {
|
|
||||||
super.onResume();
|
|
||||||
if (listAdapter != null) {
|
|
||||||
listAdapter.notifyDataSetChanged();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateRows() {
|
|
||||||
rowCount = 0;
|
|
||||||
if (!loading) {
|
|
||||||
if (type == 0) {
|
|
||||||
changePasswordSectionRow = rowCount++;
|
|
||||||
oldPasswordRow = hasPassword ? rowCount++ : -1;
|
|
||||||
newPasswordRow = rowCount++;
|
|
||||||
verifyPasswordRow = rowCount++;
|
|
||||||
hintRow = rowCount++;
|
|
||||||
passwordDetailRow = rowCount++;
|
|
||||||
deleteAccountSection = -1;
|
|
||||||
deleteAccountRow = -1;
|
|
||||||
deleteAccountDetailRow = -1;
|
|
||||||
} else if (type == 1) {
|
|
||||||
changePasswordSectionRow = rowCount++;
|
|
||||||
oldPasswordRow = rowCount++;
|
|
||||||
passwordDetailRow = rowCount++;
|
|
||||||
deleteAccountSection = rowCount++;
|
|
||||||
deleteAccountDetailRow = rowCount++;
|
|
||||||
verifyPasswordRow = -1;
|
|
||||||
newPasswordRow = -1;
|
|
||||||
hintRow = -1;
|
|
||||||
deleteAccountRow = -1;
|
|
||||||
}
|
|
||||||
doneButton.setVisibility(View.VISIBLE);
|
|
||||||
}
|
|
||||||
listAdapter.notifyDataSetChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void needShowAlert(final String text) {
|
|
||||||
if (text == null || getParentActivity() == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
|
||||||
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
|
|
||||||
builder.setMessage(text);
|
|
||||||
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
|
|
||||||
showAlertDialog(builder);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void needShowProgress() {
|
|
||||||
if (getParentActivity() == null || getParentActivity().isFinishing() || progressDialog != null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
progressDialog = new ProgressDialog(getParentActivity());
|
|
||||||
progressDialog.setMessage(LocaleController.getString("Loading", R.string.Loading));
|
|
||||||
progressDialog.setCanceledOnTouchOutside(false);
|
|
||||||
progressDialog.setCancelable(false);
|
|
||||||
progressDialog.show();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void needHideProgress() {
|
|
||||||
if (progressDialog == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
progressDialog.dismiss();
|
|
||||||
} catch (Exception e) {
|
|
||||||
FileLog.e("tmessages", e);
|
|
||||||
}
|
|
||||||
progressDialog = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void getCurrentPassword() {
|
|
||||||
loading = true;
|
|
||||||
TLRPC.TL_account_getPassword req = new TLRPC.TL_account_getPassword();
|
|
||||||
ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() {
|
|
||||||
@Override
|
|
||||||
public void run(final TLObject response, final TLRPC.TL_error error) {
|
|
||||||
AndroidUtilities.runOnUIThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
loading = false;
|
|
||||||
TLRPC.account_Password res = (TLRPC.account_Password) response;
|
|
||||||
if (res instanceof TLRPC.TL_account_noPassword) {
|
|
||||||
hasPassword = false;
|
|
||||||
new_salt = res.new_salt;
|
|
||||||
hint = null;
|
|
||||||
current_salt = null;
|
|
||||||
} else if (res instanceof TLRPC.TL_account_password) {
|
|
||||||
hasPassword = true;
|
|
||||||
new_salt = res.new_salt;
|
|
||||||
hint = res.hint;
|
|
||||||
current_salt = res.current_salt;
|
|
||||||
} else {
|
|
||||||
new_salt = null;
|
|
||||||
hint = null;
|
|
||||||
current_salt = null;
|
|
||||||
}
|
|
||||||
if (new_salt != null) {
|
|
||||||
byte[] salt = new byte[new_salt.length + 16];
|
|
||||||
Utilities.random.nextBytes(salt);
|
|
||||||
System.arraycopy(new_salt, 0, salt, 0, new_salt.length);
|
|
||||||
new_salt = salt;
|
|
||||||
}
|
|
||||||
if (type == 0 && hintPasswordCell != null && hint != null) {
|
|
||||||
hintPasswordCell.setFieldText(hint);
|
|
||||||
}
|
|
||||||
updateRows();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}, true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassFailOnServerErrors | RPCRequest.RPCRequestClassWithoutLogin);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void doneWithPassword() {
|
|
||||||
if (type == 0) {
|
|
||||||
String oldPassword = oldPasswordCell.getFieldText();
|
|
||||||
String newPassword = newPasswordCell.getFieldText();
|
|
||||||
String verifyPasswrod = verifyPasswordCell.getFieldText();
|
|
||||||
String hint = hintPasswordCell.getFieldText();
|
|
||||||
if (hasPassword) {
|
|
||||||
if (oldPassword.length() == 0) {
|
|
||||||
needShowAlert(LocaleController.getString("PasswordOldIncorrect", R.string.PasswordOldIncorrect));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (newPassword.length() == 0) {
|
|
||||||
needShowAlert(LocaleController.getString("PasswordNewIncorrect", R.string.PasswordNewIncorrect));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!newPassword.equals(verifyPasswrod)) {
|
|
||||||
needShowAlert(LocaleController.getString("PasswordDoNotMatch", R.string.PasswordDoNotMatch));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (hint.toLowerCase().contains(newPassword.toLowerCase())) {
|
|
||||||
needShowAlert(LocaleController.getString("HintIncorrect", R.string.HintIncorrect));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
byte[] oldPasswordBytes = null;
|
|
||||||
byte[] newPasswordBytes = null;
|
|
||||||
try {
|
|
||||||
oldPasswordBytes = oldPassword.getBytes("UTF-8");
|
|
||||||
newPasswordBytes = newPassword.getBytes("UTF-8");
|
|
||||||
} catch (Exception e) {
|
|
||||||
FileLog.e("tmessages", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
TLRPC.TL_account_setPassword req = new TLRPC.TL_account_setPassword();
|
|
||||||
req.hint = hintPasswordCell.getFieldText();
|
|
||||||
if (req.hint == null) {
|
|
||||||
req.hint = "";
|
|
||||||
}
|
|
||||||
if (hasPassword) {
|
|
||||||
byte[] hash = new byte[current_salt.length * 2 + oldPasswordBytes.length];
|
|
||||||
System.arraycopy(current_salt, 0, hash, 0, current_salt.length);
|
|
||||||
System.arraycopy(oldPasswordBytes, 0, hash, oldPasswordBytes.length, oldPasswordBytes.length);
|
|
||||||
System.arraycopy(current_salt, 0, hash, hash.length - current_salt.length, current_salt.length);
|
|
||||||
req.current_password_hash = Utilities.computeSHA256(hash, 0, hash.length);
|
|
||||||
} else {
|
|
||||||
req.current_password_hash = new byte[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
needShowProgress();
|
|
||||||
byte[] hash = new byte[new_salt.length * 2 + newPasswordBytes.length];
|
|
||||||
System.arraycopy(new_salt, 0, hash, 0, new_salt.length);
|
|
||||||
System.arraycopy(newPasswordBytes, 0, hash, newPasswordBytes.length, newPasswordBytes.length);
|
|
||||||
System.arraycopy(new_salt, 0, hash, hash.length - new_salt.length, new_salt.length);
|
|
||||||
req.new_password_hash = Utilities.computeSHA256(hash, 0, hash.length);
|
|
||||||
req.new_salt = new_salt;
|
|
||||||
ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() {
|
|
||||||
@Override
|
|
||||||
public void run(final TLObject response, final TLRPC.TL_error error) {
|
|
||||||
AndroidUtilities.runOnUIThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
needHideProgress();
|
|
||||||
if (error == null) {
|
|
||||||
UserConfig.registeredForPush = false;
|
|
||||||
UserConfig.registeredForInternalPush = false;
|
|
||||||
UserConfig.saveConfig(false);
|
|
||||||
MessagesController.getInstance().registerForPush(UserConfig.pushString);
|
|
||||||
ConnectionsManager.getInstance().initPushConnection();
|
|
||||||
finishFragment();
|
|
||||||
} else {
|
|
||||||
if (error.text.contains("PASSWORD_HASH_INVALID")) {
|
|
||||||
needShowAlert(LocaleController.getString("PasswordOldIncorrect", R.string.PasswordOldIncorrect));
|
|
||||||
} else if (error.text.contains("NEW_PASSWORD_BAD")) {
|
|
||||||
needShowAlert(LocaleController.getString("PasswordNewIncorrect", R.string.PasswordNewIncorrect));
|
|
||||||
} else if (error.text.startsWith("FLOOD_WAIT")) {
|
|
||||||
needShowAlert(LocaleController.getString("FloodWait", R.string.FloodWait));
|
|
||||||
} else {
|
|
||||||
needShowAlert(error.text);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}, true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassFailOnServerErrors);
|
|
||||||
} else if (type == 1) {
|
|
||||||
String oldPassword = oldPasswordCell.getFieldText();
|
|
||||||
if (oldPassword.length() == 0) {
|
|
||||||
needShowAlert(LocaleController.getString("PasswordIncorrect", R.string.PasswordIncorrect));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
byte[] oldPasswordBytes = null;
|
|
||||||
try {
|
|
||||||
oldPasswordBytes = oldPassword.getBytes("UTF-8");
|
|
||||||
} catch (Exception e) {
|
|
||||||
FileLog.e("tmessages", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
needShowProgress();
|
|
||||||
byte[] hash = new byte[current_salt.length * 2 + oldPasswordBytes.length];
|
|
||||||
System.arraycopy(current_salt, 0, hash, 0, current_salt.length);
|
|
||||||
System.arraycopy(oldPasswordBytes, 0, hash, oldPasswordBytes.length, oldPasswordBytes.length);
|
|
||||||
System.arraycopy(current_salt, 0, hash, hash.length - current_salt.length, current_salt.length);
|
|
||||||
|
|
||||||
TLRPC.TL_auth_checkPassword req = new TLRPC.TL_auth_checkPassword();
|
|
||||||
req.password_hash = Utilities.computeSHA256(hash, 0, hash.length);
|
|
||||||
ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() {
|
|
||||||
@Override
|
|
||||||
public void run(final TLObject response, final TLRPC.TL_error error) {
|
|
||||||
AndroidUtilities.runOnUIThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
needHideProgress();
|
|
||||||
if (error == null) {
|
|
||||||
if (UserConfig.isClientActivated()) {
|
|
||||||
presentFragment(new MessagesActivity(null), true);
|
|
||||||
UserConfig.registeredForPush = false;
|
|
||||||
UserConfig.registeredForInternalPush = false;
|
|
||||||
UserConfig.saveConfig(false);
|
|
||||||
MessagesController.getInstance().registerForPush(UserConfig.pushString);
|
|
||||||
ConnectionsManager.getInstance().initPushConnection();
|
|
||||||
} else {
|
|
||||||
TLRPC.TL_auth_authorization res = (TLRPC.TL_auth_authorization)response;
|
|
||||||
UserConfig.clearConfig();
|
|
||||||
MessagesController.getInstance().cleanUp();
|
|
||||||
UserConfig.setCurrentUser(res.user);
|
|
||||||
UserConfig.saveConfig(true);
|
|
||||||
MessagesStorage.getInstance().cleanUp(true);
|
|
||||||
ArrayList<TLRPC.User> users = new ArrayList<>();
|
|
||||||
users.add(res.user);
|
|
||||||
MessagesStorage.getInstance().putUsersAndChats(users, null, true, true);
|
|
||||||
MessagesController.getInstance().putUser(res.user, false);
|
|
||||||
ContactsController.getInstance().checkAppAccount();
|
|
||||||
MessagesController.getInstance().getBlockedUsers(true);
|
|
||||||
presentFragment(new MessagesActivity(null), true);
|
|
||||||
NotificationCenter.getInstance().postNotificationName(NotificationCenter.mainUserInfoChanged);
|
|
||||||
ConnectionsManager.getInstance().initPushConnection();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (error.text.contains("PASSWORD_HASH_INVALID")) {
|
|
||||||
needShowAlert(LocaleController.getString("PasswordOldIncorrect", R.string.PasswordOldIncorrect));
|
|
||||||
} else if (error.text.startsWith("FLOOD_WAIT")) {
|
|
||||||
needShowAlert(LocaleController.getString("FloodWait", R.string.FloodWait));
|
|
||||||
} else {
|
|
||||||
needShowAlert(error.text);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}, true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassFailOnServerErrors | RPCRequest.RPCRequestClassWithoutLogin);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class ListAdapter extends BaseFragmentAdapter {
|
|
||||||
private Context mContext;
|
|
||||||
|
|
||||||
public ListAdapter(Context context) {
|
|
||||||
mContext = context;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean areAllItemsEnabled() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isEnabled(int i) {
|
|
||||||
return i == deleteAccountRow;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getCount() {
|
|
||||||
return rowCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getItem(int i) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getItemId(int i) {
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasStableIds() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public View getView(int i, View view, ViewGroup viewGroup) {
|
|
||||||
int viewType = getItemViewType(i);
|
|
||||||
if (viewType == 0) {
|
|
||||||
if (view == null) {
|
|
||||||
view = new TextInfoPrivacyCell(mContext);
|
|
||||||
}
|
|
||||||
if (i == passwordDetailRow) {
|
|
||||||
if (type == 0) {
|
|
||||||
((TextInfoPrivacyCell) view).setText(LocaleController.getString("PasswordImportant", R.string.PasswordImportant));
|
|
||||||
} else if (type == 1) {
|
|
||||||
((TextInfoPrivacyCell) view).setText(hint == null || hint.length() == 0 ? "" : LocaleController.formatString("PasswordHintDetail", R.string.PasswordHintDetail, hint));
|
|
||||||
}
|
|
||||||
((TextInfoPrivacyCell) view).setTextColor(0xffcf3030);
|
|
||||||
if (deleteAccountDetailRow != -1) {
|
|
||||||
view.setBackgroundResource(R.drawable.greydivider);
|
|
||||||
} else {
|
|
||||||
view.setBackgroundResource(R.drawable.greydivider_bottom);
|
|
||||||
}
|
|
||||||
} else if (i == deleteAccountDetailRow) {
|
|
||||||
((TextInfoPrivacyCell) view).setText(LocaleController.getString("DeleteAccountImportant", R.string.DeleteAccountImportant));
|
|
||||||
((TextInfoPrivacyCell) view).setTextColor(0xffcf3030);
|
|
||||||
view.setBackgroundResource(R.drawable.greydivider_bottom);
|
|
||||||
}
|
|
||||||
} else if (viewType == 1) {
|
|
||||||
if (view == null) {
|
|
||||||
view = new HeaderCell(mContext);
|
|
||||||
view.setBackgroundColor(0xffffffff);
|
|
||||||
}
|
|
||||||
if (i == changePasswordSectionRow) {
|
|
||||||
if (type == 0) {
|
|
||||||
((HeaderCell) view).setText(LocaleController.getString("ChangePassword", R.string.ChangePassword));
|
|
||||||
} else if (type == 1) {
|
|
||||||
((HeaderCell) view).setText(LocaleController.getString("EnterPassword", R.string.EnterPassword));
|
|
||||||
}
|
|
||||||
} else if (i == deleteAccountSection) {
|
|
||||||
((HeaderCell) view).setText(LocaleController.getString("PasswordDeleteAccountTitle", R.string.PasswordDeleteAccountTitle));
|
|
||||||
}
|
|
||||||
} else if (viewType == 2) {
|
|
||||||
return newPasswordCell;
|
|
||||||
} else if (viewType == 3) {
|
|
||||||
return oldPasswordCell;
|
|
||||||
} else if (viewType == 4) {
|
|
||||||
return verifyPasswordCell;
|
|
||||||
} else if (viewType == 5) {
|
|
||||||
return hintPasswordCell;
|
|
||||||
} else if (viewType == 6) {
|
|
||||||
if (view == null) {
|
|
||||||
view = new TextSettingsCell(mContext);
|
|
||||||
view.setBackgroundColor(0xffffffff);
|
|
||||||
}
|
|
||||||
TextSettingsCell textCell = (TextSettingsCell) view;
|
|
||||||
if (i == deleteAccountRow) {
|
|
||||||
textCell.setText(LocaleController.getString("PasswordDeleteAccount", R.string.PasswordDeleteAccount), false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return view;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getItemViewType(int i) {
|
|
||||||
if (i == passwordDetailRow || i == deleteAccountDetailRow) {
|
|
||||||
return 0;
|
|
||||||
} else if (i == changePasswordSectionRow || i == deleteAccountSection) {
|
|
||||||
return 1;
|
|
||||||
} else if (i == newPasswordRow) {
|
|
||||||
return 2;
|
|
||||||
} else if (i == oldPasswordRow) {
|
|
||||||
return 3;
|
|
||||||
} else if (i == verifyPasswordRow) {
|
|
||||||
return 4;
|
|
||||||
} else if (i == hintRow) {
|
|
||||||
return 5;
|
|
||||||
} else if (i == deleteAccountRow) {
|
|
||||||
return 6;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getViewTypeCount() {
|
|
||||||
return 7;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isEmpty() {
|
|
||||||
return rowCount == 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -13,6 +13,7 @@ import android.content.res.Configuration;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
import android.util.TypedValue;
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
|
@ -47,7 +48,6 @@ public class ActionBar extends FrameLayout {
|
||||||
|
|
||||||
private boolean allowOverlayTitle;
|
private boolean allowOverlayTitle;
|
||||||
private CharSequence lastTitle;
|
private CharSequence lastTitle;
|
||||||
private boolean showingOverlayTitle;
|
|
||||||
private boolean castShadows = true;
|
private boolean castShadows = true;
|
||||||
|
|
||||||
protected boolean isSearchFieldVisible;
|
protected boolean isSearchFieldVisible;
|
||||||
|
@ -91,9 +91,9 @@ public class ActionBar extends FrameLayout {
|
||||||
|
|
||||||
if (titleTextView != null && titleTextView.getVisibility() == VISIBLE) {
|
if (titleTextView != null && titleTextView.getVisibility() == VISIBLE) {
|
||||||
if (!AndroidUtilities.isTablet() && getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
if (!AndroidUtilities.isTablet() && getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
||||||
titleTextView.setTextSize(18);
|
titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
|
||||||
} else {
|
} else {
|
||||||
titleTextView.setTextSize(20);
|
titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
layoutParams = (LayoutParams) titleTextView.getLayoutParams();
|
layoutParams = (LayoutParams) titleTextView.getLayoutParams();
|
||||||
|
@ -106,9 +106,9 @@ public class ActionBar extends FrameLayout {
|
||||||
}
|
}
|
||||||
if (subTitleTextView != null && subTitleTextView.getVisibility() == VISIBLE) {
|
if (subTitleTextView != null && subTitleTextView.getVisibility() == VISIBLE) {
|
||||||
if (!AndroidUtilities.isTablet() && getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
if (!AndroidUtilities.isTablet() && getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
||||||
subTitleTextView.setTextSize(14);
|
subTitleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
|
||||||
} else {
|
} else {
|
||||||
subTitleTextView.setTextSize(16);
|
subTitleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
layoutParams = (LayoutParams) subTitleTextView.getLayoutParams();
|
layoutParams = (LayoutParams) subTitleTextView.getLayoutParams();
|
||||||
|
@ -121,22 +121,14 @@ public class ActionBar extends FrameLayout {
|
||||||
}
|
}
|
||||||
|
|
||||||
int x = 0;
|
int x = 0;
|
||||||
if (backButtonImageView != null) {
|
if (backButtonImageView != null && backButtonImageView.getVisibility() == VISIBLE) {
|
||||||
if (AndroidUtilities.isTablet()) {
|
x = AndroidUtilities.dp(AndroidUtilities.isTablet() ? 80 : 72);
|
||||||
x = AndroidUtilities.dp(80);
|
|
||||||
} else {
|
|
||||||
x = AndroidUtilities.dp(72);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (AndroidUtilities.isTablet()) {
|
x = AndroidUtilities.dp(AndroidUtilities.isTablet() ? 26 : 18);
|
||||||
x = AndroidUtilities.dp(26);
|
|
||||||
} else {
|
|
||||||
x = AndroidUtilities.dp(18);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (menu != null) {
|
if (menu != null) {
|
||||||
maxTextWidth = Math.min(maxTextWidth, width - menu.getMeasuredWidth() - AndroidUtilities.dp(16));
|
maxTextWidth = Math.min(maxTextWidth, width - menu.getMeasuredWidth() - AndroidUtilities.dp(16) - x);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (titleTextView != null && titleTextView.getVisibility() == VISIBLE) {
|
if (titleTextView != null && titleTextView.getVisibility() == VISIBLE) {
|
||||||
|
@ -173,7 +165,7 @@ public class ActionBar extends FrameLayout {
|
||||||
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams)menu.getLayoutParams();
|
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams)menu.getLayoutParams();
|
||||||
layoutParams.width = isSearchFieldVisible ? LayoutParams.MATCH_PARENT : LayoutParams.WRAP_CONTENT;
|
layoutParams.width = isSearchFieldVisible ? LayoutParams.MATCH_PARENT : LayoutParams.WRAP_CONTENT;
|
||||||
layoutParams.height = height;
|
layoutParams.height = height;
|
||||||
layoutParams.leftMargin = isSearchFieldVisible ? AndroidUtilities.dp(54) : 0;
|
layoutParams.leftMargin = isSearchFieldVisible ? AndroidUtilities.dp(AndroidUtilities.isTablet() ? 74 : 66) : 0;
|
||||||
layoutParams.topMargin = occupyStatusBar ? AndroidUtilities.statusBarHeight : 0;
|
layoutParams.topMargin = occupyStatusBar ? AndroidUtilities.statusBarHeight : 0;
|
||||||
menu.setLayoutParams(layoutParams);
|
menu.setLayoutParams(layoutParams);
|
||||||
menu.measure(width, height);
|
menu.measure(width, height);
|
||||||
|
@ -202,17 +194,31 @@ public class ActionBar extends FrameLayout {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBackButtonDrawable(Drawable drawable) {
|
public void setBackButtonDrawable(Drawable drawable) {
|
||||||
|
boolean reposition = false;
|
||||||
if (backButtonImageView == null) {
|
if (backButtonImageView == null) {
|
||||||
createBackButtonImage();
|
createBackButtonImage();
|
||||||
|
} else {
|
||||||
|
reposition = true;
|
||||||
}
|
}
|
||||||
|
backButtonImageView.setVisibility(drawable == null ? GONE : VISIBLE);
|
||||||
backButtonImageView.setImageDrawable(drawable);
|
backButtonImageView.setImageDrawable(drawable);
|
||||||
|
if (reposition) {
|
||||||
|
positionTitle(getMeasuredWidth(), getMeasuredHeight());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBackButtonImage(int resource) {
|
public void setBackButtonImage(int resource) {
|
||||||
|
boolean reposition = false;
|
||||||
if (backButtonImageView == null) {
|
if (backButtonImageView == null) {
|
||||||
createBackButtonImage();
|
createBackButtonImage();
|
||||||
|
} else {
|
||||||
|
reposition = true;
|
||||||
}
|
}
|
||||||
|
backButtonImageView.setVisibility(resource == 0 ? GONE : VISIBLE);
|
||||||
backButtonImageView.setImageResource(resource);
|
backButtonImageView.setImageResource(resource);
|
||||||
|
if (reposition) {
|
||||||
|
positionTitle(getMeasuredWidth(), getMeasuredHeight());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createSubtitleTextView() {
|
private void createSubtitleTextView() {
|
||||||
|
@ -234,7 +240,7 @@ public class ActionBar extends FrameLayout {
|
||||||
createSubtitleTextView();
|
createSubtitleTextView();
|
||||||
}
|
}
|
||||||
if (subTitleTextView != null) {
|
if (subTitleTextView != null) {
|
||||||
subTitleTextView.setVisibility(value != null && !isSearchFieldVisible ? VISIBLE : GONE);
|
subTitleTextView.setVisibility(value != null && !isSearchFieldVisible ? VISIBLE : INVISIBLE);
|
||||||
subTitleTextView.setText(value);
|
subTitleTextView.setText(value);
|
||||||
positionTitle(getMeasuredWidth(), getMeasuredHeight());
|
positionTitle(getMeasuredWidth(), getMeasuredHeight());
|
||||||
}
|
}
|
||||||
|
@ -276,7 +282,7 @@ public class ActionBar extends FrameLayout {
|
||||||
}
|
}
|
||||||
if (titleTextView != null) {
|
if (titleTextView != null) {
|
||||||
lastTitle = value;
|
lastTitle = value;
|
||||||
titleTextView.setVisibility(value != null && !isSearchFieldVisible ? VISIBLE : GONE);
|
titleTextView.setVisibility(value != null && !isSearchFieldVisible ? VISIBLE : INVISIBLE);
|
||||||
titleTextView.setText(value);
|
titleTextView.setText(value);
|
||||||
positionTitle(getMeasuredWidth(), getMeasuredHeight());
|
positionTitle(getMeasuredWidth(), getMeasuredHeight());
|
||||||
}
|
}
|
||||||
|
@ -344,7 +350,7 @@ public class ActionBar extends FrameLayout {
|
||||||
layoutParams.width = LayoutParams.FILL_PARENT;
|
layoutParams.width = LayoutParams.FILL_PARENT;
|
||||||
layoutParams.gravity = Gravity.RIGHT;
|
layoutParams.gravity = Gravity.RIGHT;
|
||||||
actionMode.setLayoutParams(layoutParams);
|
actionMode.setLayoutParams(layoutParams);
|
||||||
actionMode.setVisibility(GONE);
|
actionMode.setVisibility(INVISIBLE);
|
||||||
|
|
||||||
if (occupyStatusBar) {
|
if (occupyStatusBar) {
|
||||||
actionModeTop = new View(getContext());
|
actionModeTop = new View(getContext());
|
||||||
|
@ -355,7 +361,7 @@ public class ActionBar extends FrameLayout {
|
||||||
layoutParams.width = LayoutParams.FILL_PARENT;
|
layoutParams.width = LayoutParams.FILL_PARENT;
|
||||||
layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
|
layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
|
||||||
actionModeTop.setLayoutParams(layoutParams);
|
actionModeTop.setLayoutParams(layoutParams);
|
||||||
actionModeTop.setVisibility(GONE);
|
actionModeTop.setVisibility(INVISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
return actionMode;
|
return actionMode;
|
||||||
|
@ -366,7 +372,7 @@ public class ActionBar extends FrameLayout {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
actionMode.setVisibility(VISIBLE);
|
actionMode.setVisibility(VISIBLE);
|
||||||
if (actionModeTop != null) {
|
if (occupyStatusBar && actionModeTop != null) {
|
||||||
actionModeTop.setVisibility(VISIBLE);
|
actionModeTop.setVisibility(VISIBLE);
|
||||||
}
|
}
|
||||||
if (titleFrameLayout != null) {
|
if (titleFrameLayout != null) {
|
||||||
|
@ -381,9 +387,9 @@ public class ActionBar extends FrameLayout {
|
||||||
if (actionMode == null) {
|
if (actionMode == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
actionMode.setVisibility(GONE);
|
actionMode.setVisibility(INVISIBLE);
|
||||||
if (actionModeTop != null) {
|
if (occupyStatusBar && actionModeTop != null) {
|
||||||
actionModeTop.setVisibility(GONE);
|
actionModeTop.setVisibility(INVISIBLE);
|
||||||
}
|
}
|
||||||
if (titleFrameLayout != null) {
|
if (titleFrameLayout != null) {
|
||||||
titleFrameLayout.setVisibility(VISIBLE);
|
titleFrameLayout.setVisibility(VISIBLE);
|
||||||
|
@ -400,10 +406,10 @@ public class ActionBar extends FrameLayout {
|
||||||
protected void onSearchFieldVisibilityChanged(boolean visible) {
|
protected void onSearchFieldVisibilityChanged(boolean visible) {
|
||||||
isSearchFieldVisible = visible;
|
isSearchFieldVisible = visible;
|
||||||
if (titleTextView != null) {
|
if (titleTextView != null) {
|
||||||
titleTextView.setVisibility(visible ? GONE : VISIBLE);
|
titleTextView.setVisibility(visible ? INVISIBLE : VISIBLE);
|
||||||
}
|
}
|
||||||
if (subTitleTextView != null) {
|
if (subTitleTextView != null) {
|
||||||
subTitleTextView.setVisibility(visible ? GONE : VISIBLE);
|
subTitleTextView.setVisibility(visible ? INVISIBLE : VISIBLE);
|
||||||
}
|
}
|
||||||
Drawable drawable = backButtonImageView.getDrawable();
|
Drawable drawable = backButtonImageView.getDrawable();
|
||||||
if (drawable != null && drawable instanceof MenuDrawable) {
|
if (drawable != null && drawable instanceof MenuDrawable) {
|
||||||
|
@ -418,6 +424,13 @@ public class ActionBar extends FrameLayout {
|
||||||
menu.closeSearchField();
|
menu.closeSearchField();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void openSearchField(String text) {
|
||||||
|
if (menu == null || text == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
menu.openSearchField(!isSearchFieldVisible, text);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||||
int actionBarHeight = AndroidUtilities.getCurrentActionBarHeight();
|
int actionBarHeight = AndroidUtilities.getCurrentActionBarHeight();
|
||||||
|
@ -445,16 +458,15 @@ public class ActionBar extends FrameLayout {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTitleOverlayText(String text) {
|
public void setTitleOverlayText(String text) {
|
||||||
if (showingOverlayTitle == (text != null) || !allowOverlayTitle || parentFragment.parentLayout == null) {
|
if (!allowOverlayTitle || parentFragment.parentLayout == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
showingOverlayTitle = text != null;
|
|
||||||
CharSequence textToSet = text != null ? text : lastTitle;
|
CharSequence textToSet = text != null ? text : lastTitle;
|
||||||
if (textToSet != null && titleTextView == null) {
|
if (textToSet != null && titleTextView == null) {
|
||||||
createTitleTextView();
|
createTitleTextView();
|
||||||
}
|
}
|
||||||
if (titleTextView != null) {
|
if (titleTextView != null) {
|
||||||
titleTextView.setVisibility(textToSet != null && !isSearchFieldVisible ? VISIBLE : GONE);
|
titleTextView.setVisibility(textToSet != null && !isSearchFieldVisible ? VISIBLE : INVISIBLE);
|
||||||
titleTextView.setText(textToSet);
|
titleTextView.setText(textToSet);
|
||||||
positionTitle(getMeasuredWidth(), getMeasuredHeight());
|
positionTitle(getMeasuredWidth(), getMeasuredHeight());
|
||||||
}
|
}
|
||||||
|
@ -473,6 +485,9 @@ public class ActionBar extends FrameLayout {
|
||||||
|
|
||||||
public void setOccupyStatusBar(boolean value) {
|
public void setOccupyStatusBar(boolean value) {
|
||||||
occupyStatusBar = value;
|
occupyStatusBar = value;
|
||||||
|
if (actionMode != null) {
|
||||||
|
actionMode.setPadding(0, occupyStatusBar ? AndroidUtilities.statusBarHeight : 0, 0, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getOccupyStatusBar() {
|
public boolean getOccupyStatusBar() {
|
||||||
|
|
|
@ -39,12 +39,12 @@ import java.util.ArrayList;
|
||||||
|
|
||||||
public class ActionBarLayout extends FrameLayout {
|
public class ActionBarLayout extends FrameLayout {
|
||||||
|
|
||||||
public static interface ActionBarLayoutDelegate {
|
public interface ActionBarLayoutDelegate {
|
||||||
public abstract boolean onPreIme();
|
boolean onPreIme();
|
||||||
public abstract boolean needPresentFragment(BaseFragment fragment, boolean removeLast, boolean forceWithoutAnimation, ActionBarLayout layout);
|
boolean needPresentFragment(BaseFragment fragment, boolean removeLast, boolean forceWithoutAnimation, ActionBarLayout layout);
|
||||||
public abstract boolean needAddFragmentToStack(BaseFragment fragment, ActionBarLayout layout);
|
boolean needAddFragmentToStack(BaseFragment fragment, ActionBarLayout layout);
|
||||||
public abstract boolean needCloseLastFragment(ActionBarLayout layout);
|
boolean needCloseLastFragment(ActionBarLayout layout);
|
||||||
public abstract void onRebuildAllFragments(ActionBarLayout layout);
|
void onRebuildAllFragments(ActionBarLayout layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class LinearLayoutContainer extends LinearLayout {
|
public class LinearLayoutContainer extends LinearLayout {
|
||||||
|
@ -225,7 +225,7 @@ public class ActionBarLayout extends FrameLayout {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean dispatchKeyEventPreIme(KeyEvent event) {
|
public boolean dispatchKeyEventPreIme(KeyEvent event) {
|
||||||
if (event != null && event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
|
if (event != null && event.getKeyCode() == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP) {
|
||||||
return delegate != null && delegate.onPreIme() || super.dispatchKeyEventPreIme(event);
|
return delegate != null && delegate.onPreIme() || super.dispatchKeyEventPreIme(event);
|
||||||
}
|
}
|
||||||
return super.dispatchKeyEventPreIme(event);
|
return super.dispatchKeyEventPreIme(event);
|
||||||
|
@ -303,7 +303,7 @@ public class ActionBarLayout extends FrameLayout {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
containerViewBack.setVisibility(View.GONE);
|
containerViewBack.setVisibility(View.INVISIBLE);
|
||||||
//AndroidUtilities.unlockOrientation(parentActivity);
|
//AndroidUtilities.unlockOrientation(parentActivity);
|
||||||
startedTracking = false;
|
startedTracking = false;
|
||||||
animationInProgress = false;
|
animationInProgress = false;
|
||||||
|
@ -321,7 +321,15 @@ public class ActionBarLayout extends FrameLayout {
|
||||||
beginTrackingSent = false;
|
beginTrackingSent = false;
|
||||||
|
|
||||||
BaseFragment lastFragment = fragmentsStack.get(fragmentsStack.size() - 2);
|
BaseFragment lastFragment = fragmentsStack.get(fragmentsStack.size() - 2);
|
||||||
View fragmentView = lastFragment.createView(parentActivity.getLayoutInflater(), null);
|
View fragmentView = lastFragment.fragmentView;
|
||||||
|
if (fragmentView == null) {
|
||||||
|
fragmentView = lastFragment.createView(parentActivity, parentActivity.getLayoutInflater());
|
||||||
|
} else {
|
||||||
|
ViewGroup parent = (ViewGroup) fragmentView.getParent();
|
||||||
|
if (parent != null) {
|
||||||
|
parent.removeView(fragmentView);
|
||||||
|
}
|
||||||
|
}
|
||||||
ViewGroup parent = (ViewGroup) fragmentView.getParent();
|
ViewGroup parent = (ViewGroup) fragmentView.getParent();
|
||||||
if (parent != null) {
|
if (parent != null) {
|
||||||
parent.removeView(fragmentView);
|
parent.removeView(fragmentView);
|
||||||
|
@ -342,7 +350,7 @@ public class ActionBarLayout extends FrameLayout {
|
||||||
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
|
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
|
||||||
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
|
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
|
||||||
fragmentView.setLayoutParams(layoutParams);
|
fragmentView.setLayoutParams(layoutParams);
|
||||||
if (fragmentView.getBackground() == null) {
|
if (!lastFragment.hasOwnBackground && fragmentView.getBackground() == null) {
|
||||||
fragmentView.setBackgroundColor(0xffffffff);
|
fragmentView.setBackgroundColor(0xffffffff);
|
||||||
}
|
}
|
||||||
lastFragment.onResume();
|
lastFragment.onResume();
|
||||||
|
@ -372,7 +380,7 @@ public class ActionBarLayout extends FrameLayout {
|
||||||
int dx = Math.max(0, (int) (ev.getX() - startedTrackingX));
|
int dx = Math.max(0, (int) (ev.getX() - startedTrackingX));
|
||||||
int dy = Math.abs((int) ev.getY() - startedTrackingY);
|
int dy = Math.abs((int) ev.getY() - startedTrackingY);
|
||||||
velocityTracker.addMovement(ev);
|
velocityTracker.addMovement(ev);
|
||||||
if (maybeStartTracking && !startedTracking && dx >= AndroidUtilities.dp(10) && Math.abs(dx) / 3 > dy) {
|
if (maybeStartTracking && !startedTracking && dx >= AndroidUtilities.getPixelsInCM(0.3f, true) && Math.abs(dx) / 3 > dy) {
|
||||||
prepareForMoving(ev);
|
prepareForMoving(ev);
|
||||||
} else if (startedTracking) {
|
} else if (startedTracking) {
|
||||||
if (!beginTrackingSent) {
|
if (!beginTrackingSent) {
|
||||||
|
@ -502,8 +510,7 @@ public class ActionBarLayout extends FrameLayout {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean checkTransitionAnimation() {
|
public boolean checkTransitionAnimation() {
|
||||||
if (transitionAnimationInProgress && transitionAnimationStartTime < System.currentTimeMillis() - 400) {
|
if (transitionAnimationInProgress && transitionAnimationStartTime < System.currentTimeMillis() - 1000) {
|
||||||
transitionAnimationInProgress = false;
|
|
||||||
onAnimationEndCheck(true);
|
onAnimationEndCheck(true);
|
||||||
}
|
}
|
||||||
return transitionAnimationInProgress;
|
return transitionAnimationInProgress;
|
||||||
|
@ -532,7 +539,7 @@ public class ActionBarLayout extends FrameLayout {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
containerViewBack.setVisibility(View.GONE);
|
containerViewBack.setVisibility(View.INVISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean presentFragment(BaseFragment fragment) {
|
public boolean presentFragment(BaseFragment fragment) {
|
||||||
|
@ -556,7 +563,15 @@ public class ActionBarLayout extends FrameLayout {
|
||||||
final BaseFragment currentFragment = !fragmentsStack.isEmpty() ? fragmentsStack.get(fragmentsStack.size() - 1) : null;
|
final BaseFragment currentFragment = !fragmentsStack.isEmpty() ? fragmentsStack.get(fragmentsStack.size() - 1) : null;
|
||||||
|
|
||||||
fragment.setParentLayout(this);
|
fragment.setParentLayout(this);
|
||||||
View fragmentView = fragment.createView(parentActivity.getLayoutInflater(), null);
|
View fragmentView = fragment.fragmentView;
|
||||||
|
if (fragmentView == null) {
|
||||||
|
fragmentView = fragment.createView(parentActivity, parentActivity.getLayoutInflater());
|
||||||
|
} else {
|
||||||
|
ViewGroup parent = (ViewGroup) fragmentView.getParent();
|
||||||
|
if (parent != null) {
|
||||||
|
parent.removeView(fragmentView);
|
||||||
|
}
|
||||||
|
}
|
||||||
if (fragment.needAddActionBar() && fragment.actionBar != null) {
|
if (fragment.needAddActionBar() && fragment.actionBar != null) {
|
||||||
if (removeActionBarExtraHeight) {
|
if (removeActionBarExtraHeight) {
|
||||||
fragment.actionBar.setOccupyStatusBar(false);
|
fragment.actionBar.setOccupyStatusBar(false);
|
||||||
|
@ -577,7 +592,7 @@ public class ActionBarLayout extends FrameLayout {
|
||||||
fragmentsStack.add(fragment);
|
fragmentsStack.add(fragment);
|
||||||
fragment.onResume();
|
fragment.onResume();
|
||||||
currentActionBar = fragment.actionBar;
|
currentActionBar = fragment.actionBar;
|
||||||
if (fragmentView.getBackground() == null) {
|
if (!fragment.hasOwnBackground && fragmentView.getBackground() == null) {
|
||||||
fragmentView.setBackgroundColor(0xffffffff);
|
fragmentView.setBackgroundColor(0xffffffff);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -585,6 +600,7 @@ public class ActionBarLayout extends FrameLayout {
|
||||||
containerView = containerViewBack;
|
containerView = containerViewBack;
|
||||||
containerViewBack = temp;
|
containerViewBack = temp;
|
||||||
containerView.setVisibility(View.VISIBLE);
|
containerView.setVisibility(View.VISIBLE);
|
||||||
|
setInnerTranslationX(0);
|
||||||
|
|
||||||
bringChildToFront(containerView);
|
bringChildToFront(containerView);
|
||||||
|
|
||||||
|
@ -633,6 +649,8 @@ public class ActionBarLayout extends FrameLayout {
|
||||||
ViewProxy.setTranslationX(containerView, 0);
|
ViewProxy.setTranslationX(containerView, 0);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
ViewProxy.setAlpha(containerView, 0.0f);
|
||||||
|
ViewProxy.setTranslationX(containerView, 48.0f);
|
||||||
currentAnimation = new AnimatorSetProxy();
|
currentAnimation = new AnimatorSetProxy();
|
||||||
currentAnimation.playTogether(
|
currentAnimation.playTogether(
|
||||||
ObjectAnimatorProxy.ofFloat(containerView, "alpha", 0.0f, 1.0f),
|
ObjectAnimatorProxy.ofFloat(containerView, "alpha", 0.0f, 1.0f),
|
||||||
|
@ -640,6 +658,11 @@ public class ActionBarLayout extends FrameLayout {
|
||||||
currentAnimation.setInterpolator(new DecelerateInterpolator(1.5f));
|
currentAnimation.setInterpolator(new DecelerateInterpolator(1.5f));
|
||||||
currentAnimation.setDuration(200);
|
currentAnimation.setDuration(200);
|
||||||
currentAnimation.addListener(new AnimatorListenerAdapterProxy() {
|
currentAnimation.addListener(new AnimatorListenerAdapterProxy() {
|
||||||
|
@Override
|
||||||
|
public void onAnimationStart(Object animation) {
|
||||||
|
transitionAnimationStartTime = System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAnimationEnd(Object animation) {
|
public void onAnimationEnd(Object animation) {
|
||||||
onAnimationEndCheck(false);
|
onAnimationEndCheck(false);
|
||||||
|
@ -672,6 +695,22 @@ public class ActionBarLayout extends FrameLayout {
|
||||||
}
|
}
|
||||||
fragment.setParentLayout(this);
|
fragment.setParentLayout(this);
|
||||||
if (position == -1) {
|
if (position == -1) {
|
||||||
|
if (!fragmentsStack.isEmpty()) {
|
||||||
|
BaseFragment previousFragment = fragmentsStack.get(fragmentsStack.size() - 1);
|
||||||
|
previousFragment.onPause();
|
||||||
|
if (previousFragment.actionBar != null) {
|
||||||
|
ViewGroup parent = (ViewGroup) previousFragment.actionBar.getParent();
|
||||||
|
if (parent != null) {
|
||||||
|
parent.removeView(previousFragment.actionBar);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (previousFragment.fragmentView != null) {
|
||||||
|
ViewGroup parent = (ViewGroup) previousFragment.fragmentView.getParent();
|
||||||
|
if (parent != null) {
|
||||||
|
parent.removeView(previousFragment.fragmentView);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
fragmentsStack.add(fragment);
|
fragmentsStack.add(fragment);
|
||||||
} else {
|
} else {
|
||||||
fragmentsStack.add(position, fragment);
|
fragmentsStack.add(position, fragment);
|
||||||
|
@ -684,17 +723,18 @@ public class ActionBarLayout extends FrameLayout {
|
||||||
fragment.onFragmentDestroy();
|
fragment.onFragmentDestroy();
|
||||||
fragment.setParentLayout(null);
|
fragment.setParentLayout(null);
|
||||||
fragmentsStack.remove(fragment);
|
fragmentsStack.remove(fragment);
|
||||||
containerViewBack.setVisibility(View.GONE);
|
containerViewBack.setVisibility(View.INVISIBLE);
|
||||||
bringChildToFront(containerView);
|
bringChildToFront(containerView);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void closeLastFragment(boolean animated) {
|
public void closeLastFragment(boolean animated) {
|
||||||
if (delegate != null && !delegate.needCloseLastFragment(this) || checkTransitionAnimation()) {
|
if (delegate != null && !delegate.needCloseLastFragment(this) || checkTransitionAnimation() || fragmentsStack.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (parentActivity.getCurrentFocus() != null) {
|
if (parentActivity.getCurrentFocus() != null) {
|
||||||
AndroidUtilities.hideKeyboard(parentActivity.getCurrentFocus());
|
AndroidUtilities.hideKeyboard(parentActivity.getCurrentFocus());
|
||||||
}
|
}
|
||||||
|
setInnerTranslationX(0);
|
||||||
boolean needAnimation = Build.VERSION.SDK_INT > 10 && animated && parentActivity.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE).getBoolean("view_animations", true);
|
boolean needAnimation = Build.VERSION.SDK_INT > 10 && animated && parentActivity.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE).getBoolean("view_animations", true);
|
||||||
final BaseFragment currentFragment = fragmentsStack.get(fragmentsStack.size() - 1);
|
final BaseFragment currentFragment = fragmentsStack.get(fragmentsStack.size() - 1);
|
||||||
BaseFragment previousFragment = null;
|
BaseFragment previousFragment = null;
|
||||||
|
@ -709,7 +749,15 @@ public class ActionBarLayout extends FrameLayout {
|
||||||
containerView.setVisibility(View.VISIBLE);
|
containerView.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
previousFragment.setParentLayout(this);
|
previousFragment.setParentLayout(this);
|
||||||
View fragmentView = previousFragment.createView(parentActivity.getLayoutInflater(), null);
|
View fragmentView = previousFragment.fragmentView;
|
||||||
|
if (fragmentView == null) {
|
||||||
|
fragmentView = previousFragment.createView(parentActivity, parentActivity.getLayoutInflater());
|
||||||
|
} else {
|
||||||
|
ViewGroup parent = (ViewGroup) fragmentView.getParent();
|
||||||
|
if (parent != null) {
|
||||||
|
parent.removeView(fragmentView);
|
||||||
|
}
|
||||||
|
}
|
||||||
if (previousFragment.needAddActionBar() && previousFragment.actionBar != null) {
|
if (previousFragment.needAddActionBar() && previousFragment.actionBar != null) {
|
||||||
if (removeActionBarExtraHeight) {
|
if (removeActionBarExtraHeight) {
|
||||||
previousFragment.actionBar.setOccupyStatusBar(false);
|
previousFragment.actionBar.setOccupyStatusBar(false);
|
||||||
|
@ -728,7 +776,7 @@ public class ActionBarLayout extends FrameLayout {
|
||||||
fragmentView.setLayoutParams(layoutParams);
|
fragmentView.setLayoutParams(layoutParams);
|
||||||
previousFragment.onResume();
|
previousFragment.onResume();
|
||||||
currentActionBar = previousFragment.actionBar;
|
currentActionBar = previousFragment.actionBar;
|
||||||
if (fragmentView.getBackground() == null) {
|
if (!previousFragment.hasOwnBackground && fragmentView.getBackground() == null) {
|
||||||
fragmentView.setBackgroundColor(0xffffffff);
|
fragmentView.setBackgroundColor(0xffffffff);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -754,6 +802,11 @@ public class ActionBarLayout extends FrameLayout {
|
||||||
currentAnimation.setInterpolator(new DecelerateInterpolator(1.5f));
|
currentAnimation.setInterpolator(new DecelerateInterpolator(1.5f));
|
||||||
currentAnimation.setDuration(200);
|
currentAnimation.setDuration(200);
|
||||||
currentAnimation.addListener(new AnimatorListenerAdapterProxy() {
|
currentAnimation.addListener(new AnimatorListenerAdapterProxy() {
|
||||||
|
@Override
|
||||||
|
public void onAnimationStart(Object animation) {
|
||||||
|
transitionAnimationStartTime = System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAnimationEnd(Object animation) {
|
public void onAnimationEnd(Object animation) {
|
||||||
onAnimationEndCheck(false);
|
onAnimationEndCheck(false);
|
||||||
|
@ -775,12 +828,12 @@ public class ActionBarLayout extends FrameLayout {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
removeFragmentFromStack(currentFragment);
|
removeFragmentFromStack(currentFragment);
|
||||||
setVisibility(GONE);
|
setVisibility(INVISIBLE);
|
||||||
if (backgroundView != null) {
|
if (backgroundView != null) {
|
||||||
backgroundView.setVisibility(GONE);
|
backgroundView.setVisibility(INVISIBLE);
|
||||||
}
|
}
|
||||||
if (drawerLayoutContainer != null) {
|
if (drawerLayoutContainer != null) {
|
||||||
drawerLayoutContainer.setAllowOpenDrawer(true);
|
drawerLayoutContainer.setAllowOpenDrawer(true, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -796,6 +849,11 @@ public class ActionBarLayout extends FrameLayout {
|
||||||
currentAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
|
currentAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
|
||||||
currentAnimation.setDuration(200);
|
currentAnimation.setDuration(200);
|
||||||
currentAnimation.addListener(new AnimatorListenerAdapterProxy() {
|
currentAnimation.addListener(new AnimatorListenerAdapterProxy() {
|
||||||
|
@Override
|
||||||
|
public void onAnimationStart(Object animation) {
|
||||||
|
transitionAnimationStartTime = System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAnimationEnd(Object animation) {
|
public void onAnimationEnd(Object animation) {
|
||||||
onAnimationEndCheck(false);
|
onAnimationEndCheck(false);
|
||||||
|
@ -809,9 +867,9 @@ public class ActionBarLayout extends FrameLayout {
|
||||||
currentAnimation.start();
|
currentAnimation.start();
|
||||||
} else {
|
} else {
|
||||||
removeFragmentFromStack(currentFragment);
|
removeFragmentFromStack(currentFragment);
|
||||||
setVisibility(GONE);
|
setVisibility(INVISIBLE);
|
||||||
if (backgroundView != null) {
|
if (backgroundView != null) {
|
||||||
backgroundView.setVisibility(GONE);
|
backgroundView.setVisibility(INVISIBLE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -823,7 +881,15 @@ public class ActionBarLayout extends FrameLayout {
|
||||||
}
|
}
|
||||||
BaseFragment previousFragment = fragmentsStack.get(fragmentsStack.size() - 1);
|
BaseFragment previousFragment = fragmentsStack.get(fragmentsStack.size() - 1);
|
||||||
previousFragment.setParentLayout(this);
|
previousFragment.setParentLayout(this);
|
||||||
View fragmentView = previousFragment.createView(parentActivity.getLayoutInflater(), null);
|
View fragmentView = previousFragment.fragmentView;
|
||||||
|
if (fragmentView == null) {
|
||||||
|
fragmentView = previousFragment.createView(parentActivity, parentActivity.getLayoutInflater());
|
||||||
|
} else {
|
||||||
|
ViewGroup parent = (ViewGroup) fragmentView.getParent();
|
||||||
|
if (parent != null) {
|
||||||
|
parent.removeView(fragmentView);
|
||||||
|
}
|
||||||
|
}
|
||||||
if (previousFragment.needAddActionBar() && previousFragment.actionBar != null) {
|
if (previousFragment.needAddActionBar() && previousFragment.actionBar != null) {
|
||||||
if (removeActionBarExtraHeight) {
|
if (removeActionBarExtraHeight) {
|
||||||
previousFragment.actionBar.setOccupyStatusBar(false);
|
previousFragment.actionBar.setOccupyStatusBar(false);
|
||||||
|
@ -842,7 +908,7 @@ public class ActionBarLayout extends FrameLayout {
|
||||||
fragmentView.setLayoutParams(layoutParams);
|
fragmentView.setLayoutParams(layoutParams);
|
||||||
previousFragment.onResume();
|
previousFragment.onResume();
|
||||||
currentActionBar = previousFragment.actionBar;
|
currentActionBar = previousFragment.actionBar;
|
||||||
if (fragmentView.getBackground() == null) {
|
if (!previousFragment.hasOwnBackground && fragmentView.getBackground() == null) {
|
||||||
fragmentView.setBackgroundColor(0xffffffff);
|
fragmentView.setBackgroundColor(0xffffffff);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,7 @@ public class ActionBarMenu extends LinearLayout {
|
||||||
view.setOnClickListener(new OnClickListener() {
|
view.setOnClickListener(new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
onItemClick((Integer)view.getTag());
|
onItemClick((Integer) view.getTag());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return view;
|
return view;
|
||||||
|
@ -147,6 +147,24 @@ public class ActionBarMenu extends LinearLayout {
|
||||||
ActionBarMenuItem item = (ActionBarMenuItem)view;
|
ActionBarMenuItem item = (ActionBarMenuItem)view;
|
||||||
if (item.isSearchField()) {
|
if (item.isSearchField()) {
|
||||||
parentActionBar.onSearchFieldVisibilityChanged(item.toggleSearch());
|
parentActionBar.onSearchFieldVisibilityChanged(item.toggleSearch());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void openSearchField(boolean toggle, String text) {
|
||||||
|
for (int a = 0; a < getChildCount(); a++) {
|
||||||
|
View view = getChildAt(a);
|
||||||
|
if (view instanceof ActionBarMenuItem) {
|
||||||
|
ActionBarMenuItem item = (ActionBarMenuItem)view;
|
||||||
|
if (item.isSearchField()) {
|
||||||
|
if (toggle) {
|
||||||
|
parentActionBar.onSearchFieldVisibilityChanged(item.toggleSearch());
|
||||||
|
}
|
||||||
|
item.getSearchField().setText(text);
|
||||||
|
item.getSearchField().setSelection(text.length());
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ public class ActionBarMenuItem extends FrameLayoutFixed {
|
||||||
|
|
||||||
public static class ActionBarMenuItemSearchListener {
|
public static class ActionBarMenuItemSearchListener {
|
||||||
public void onSearchExpand() { }
|
public void onSearchExpand() { }
|
||||||
public void onSearchCollapse() { }
|
public boolean onSearchCollapse() { return true; }
|
||||||
public void onTextChanged(EditText editText) { }
|
public void onTextChanged(EditText editText) { }
|
||||||
public void onSearchPressed(EditText editText) { }
|
public void onSearchPressed(EditText editText) { }
|
||||||
}
|
}
|
||||||
|
@ -322,11 +322,10 @@ public class ActionBarMenuItem extends FrameLayoutFixed {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (searchContainer.getVisibility() == VISIBLE) {
|
if (searchContainer.getVisibility() == VISIBLE) {
|
||||||
searchContainer.setVisibility(GONE);
|
if (listener == null || listener != null && listener.onSearchCollapse()) {
|
||||||
setVisibility(VISIBLE);
|
searchContainer.setVisibility(GONE);
|
||||||
AndroidUtilities.hideKeyboard(searchField);
|
setVisibility(VISIBLE);
|
||||||
if (listener != null) {
|
AndroidUtilities.hideKeyboard(searchField);
|
||||||
listener.onSearchCollapse();
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
|
@ -348,6 +347,10 @@ public class ActionBarMenuItem extends FrameLayoutFixed {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setIcon(int resId) {
|
||||||
|
iconView.setImageResource(resId);
|
||||||
|
}
|
||||||
|
|
||||||
public EditText getSearchField() {
|
public EditText getSearchField() {
|
||||||
return searchField;
|
return searchField;
|
||||||
}
|
}
|
||||||
|
@ -399,7 +402,7 @@ public class ActionBarMenuItem extends FrameLayoutFixed {
|
||||||
searchField.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
searchField.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
||||||
if (actionId == EditorInfo.IME_ACTION_SEARCH || event != null && event.getAction() == KeyEvent.ACTION_UP && event.getKeyCode() == KeyEvent.KEYCODE_SEARCH) {
|
if (actionId == EditorInfo.IME_ACTION_SEARCH || event != null && (event.getAction() == KeyEvent.ACTION_UP && event.getKeyCode() == KeyEvent.KEYCODE_SEARCH || event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
|
||||||
AndroidUtilities.hideKeyboard(searchField);
|
AndroidUtilities.hideKeyboard(searchField);
|
||||||
if (listener != null) {
|
if (listener != null) {
|
||||||
listener.onSearchPressed(searchField);
|
listener.onSearchPressed(searchField);
|
||||||
|
|
|
@ -48,8 +48,8 @@ public class ActionBarPopupWindow extends PopupWindow {
|
||||||
private ViewTreeObserver.OnScrollChangedListener mSuperScrollListener;
|
private ViewTreeObserver.OnScrollChangedListener mSuperScrollListener;
|
||||||
private ViewTreeObserver mViewTreeObserver;
|
private ViewTreeObserver mViewTreeObserver;
|
||||||
|
|
||||||
public static interface OnDispatchKeyEventListener {
|
public interface OnDispatchKeyEventListener {
|
||||||
public void onDispatchKeyEvent(KeyEvent keyEvent);
|
void onDispatchKeyEvent(KeyEvent keyEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class ActionBarPopupWindowLayout extends LinearLayout {
|
public static class ActionBarPopupWindowLayout extends LinearLayout {
|
||||||
|
@ -200,7 +200,11 @@ public class ActionBarPopupWindow extends PopupWindow {
|
||||||
@Override
|
@Override
|
||||||
public void dismiss() {
|
public void dismiss() {
|
||||||
setFocusable(false);
|
setFocusable(false);
|
||||||
super.dismiss();
|
try {
|
||||||
|
super.dismiss();
|
||||||
|
} catch (Exception e) {
|
||||||
|
//don't promt
|
||||||
|
}
|
||||||
unregisterListener();
|
unregisterListener();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ package org.telegram.ui.ActionBar;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
@ -23,7 +24,7 @@ import org.telegram.messenger.R;
|
||||||
|
|
||||||
public class BaseFragment {
|
public class BaseFragment {
|
||||||
private boolean isFinished = false;
|
private boolean isFinished = false;
|
||||||
private AlertDialog visibleDialog = null;
|
protected AlertDialog visibleDialog = null;
|
||||||
|
|
||||||
protected View fragmentView;
|
protected View fragmentView;
|
||||||
protected ActionBarLayout parentLayout;
|
protected ActionBarLayout parentLayout;
|
||||||
|
@ -31,6 +32,7 @@ public class BaseFragment {
|
||||||
protected int classGuid = 0;
|
protected int classGuid = 0;
|
||||||
protected Bundle arguments;
|
protected Bundle arguments;
|
||||||
protected boolean swipeBackEnabled = true;
|
protected boolean swipeBackEnabled = true;
|
||||||
|
protected boolean hasOwnBackground = false;
|
||||||
|
|
||||||
public BaseFragment() {
|
public BaseFragment() {
|
||||||
classGuid = ConnectionsManager.getInstance().generateClassGuid();
|
classGuid = ConnectionsManager.getInstance().generateClassGuid();
|
||||||
|
@ -41,7 +43,7 @@ public class BaseFragment {
|
||||||
classGuid = ConnectionsManager.getInstance().generateClassGuid();
|
classGuid = ConnectionsManager.getInstance().generateClassGuid();
|
||||||
}
|
}
|
||||||
|
|
||||||
public View createView(LayoutInflater inflater, ViewGroup container) {
|
public View createView(Context context, LayoutInflater inflater) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,7 +78,7 @@ public class BaseFragment {
|
||||||
if (parentLayout != null) {
|
if (parentLayout != null) {
|
||||||
actionBar = new ActionBar(parentLayout.getContext());
|
actionBar = new ActionBar(parentLayout.getContext());
|
||||||
actionBar.parentFragment = this;
|
actionBar.parentFragment = this;
|
||||||
actionBar.setBackgroundResource(R.color.header);
|
actionBar.setBackgroundColor(0xff54759e);
|
||||||
actionBar.setItemsBackground(R.drawable.bar_selector);
|
actionBar.setItemsBackground(R.drawable.bar_selector);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -201,9 +203,9 @@ public class BaseFragment {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void showAlertDialog(AlertDialog.Builder builder) {
|
public AlertDialog showAlertDialog(AlertDialog.Builder builder) {
|
||||||
if (parentLayout == null || parentLayout.checkTransitionAnimation() || parentLayout.animationInProgress || parentLayout.startedTracking) {
|
if (parentLayout == null || parentLayout.checkTransitionAnimation() || parentLayout.animationInProgress || parentLayout.startedTracking) {
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (visibleDialog != null) {
|
if (visibleDialog != null) {
|
||||||
|
@ -223,9 +225,11 @@ public class BaseFragment {
|
||||||
onDialogDismiss();
|
onDialogDismiss();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
return visibleDialog;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
FileLog.e("tmessages", e);
|
FileLog.e("tmessages", e);
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onDialogDismiss() {
|
protected void onDialogDismiss() {
|
||||||
|
|
|
@ -165,6 +165,9 @@ public class DrawerLayoutContainer extends FrameLayout {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void openDrawer(boolean fast) {
|
public void openDrawer(boolean fast) {
|
||||||
|
if (!allowOpenDrawer) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (AndroidUtilities.isTablet() && parentActionBarLayout != null && parentActionBarLayout.parentActivity != null) {
|
if (AndroidUtilities.isTablet() && parentActionBarLayout != null && parentActionBarLayout.parentActivity != null) {
|
||||||
AndroidUtilities.hideKeyboard(parentActionBarLayout.parentActivity.getCurrentFocus());
|
AndroidUtilities.hideKeyboard(parentActionBarLayout.parentActivity.getCurrentFocus());
|
||||||
}
|
}
|
||||||
|
@ -248,11 +251,15 @@ public class DrawerLayoutContainer extends FrameLayout {
|
||||||
parentActionBarLayout = layout;
|
parentActionBarLayout = layout;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAllowOpenDrawer(boolean value) {
|
public void setAllowOpenDrawer(boolean value, boolean animated) {
|
||||||
allowOpenDrawer = value;
|
allowOpenDrawer = value;
|
||||||
if (!allowOpenDrawer && drawerPosition != 0) {
|
if (!allowOpenDrawer && drawerPosition != 0) {
|
||||||
setDrawerPosition(0);
|
if (!animated) {
|
||||||
onDrawerAnimationEnd(false);
|
setDrawerPosition(0);
|
||||||
|
onDrawerAnimationEnd(false);
|
||||||
|
} else {
|
||||||
|
closeDrawer(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -294,7 +301,7 @@ public class DrawerLayoutContainer extends FrameLayout {
|
||||||
float dx = (int) (ev.getX() - startedTrackingX);
|
float dx = (int) (ev.getX() - startedTrackingX);
|
||||||
float dy = Math.abs((int) ev.getY() - startedTrackingY);
|
float dy = Math.abs((int) ev.getY() - startedTrackingY);
|
||||||
velocityTracker.addMovement(ev);
|
velocityTracker.addMovement(ev);
|
||||||
if (maybeStartTracking && !startedTracking && (dx > 0 && dx / 3.0f > Math.abs(dy) || dx < 0 && Math.abs(dx) >= Math.abs(dy) && Math.abs(dx) >= AndroidUtilities.dp(10))) {
|
if (maybeStartTracking && !startedTracking && (dx > 0 && dx / 3.0f > Math.abs(dy) && Math.abs(dx) >= AndroidUtilities.getPixelsInCM(0.2f, true) || dx < 0 && Math.abs(dx) >= Math.abs(dy) && Math.abs(dx) >= AndroidUtilities.getPixelsInCM(0.3f, true))) {
|
||||||
prepareForDrawerOpen(ev);
|
prepareForDrawerOpen(ev);
|
||||||
startedTrackingX = (int) ev.getX();
|
startedTrackingX = (int) ev.getX();
|
||||||
requestDisallowInterceptTouchEvent(true);
|
requestDisallowInterceptTouchEvent(true);
|
||||||
|
|
|
@ -1,61 +0,0 @@
|
||||||
/*
|
|
||||||
* This is the source code of Telegram for Android v. 1.7.x.
|
|
||||||
* It is licensed under GNU GPL v. 2 or later.
|
|
||||||
* You should have received a copy of the license in this archive (see LICENSE).
|
|
||||||
*
|
|
||||||
* Copyright Nikolai Kudashov, 2013-2014.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.telegram.ui.Adapters;
|
|
||||||
|
|
||||||
import org.telegram.android.AndroidUtilities;
|
|
||||||
import org.telegram.messenger.ConnectionsManager;
|
|
||||||
import org.telegram.messenger.RPCRequest;
|
|
||||||
import org.telegram.messenger.TLObject;
|
|
||||||
import org.telegram.messenger.TLRPC;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
public class BaseContactsSearchAdapter extends BaseFragmentAdapter {
|
|
||||||
|
|
||||||
protected ArrayList<TLRPC.User> globalSearch = new ArrayList<>();
|
|
||||||
private long reqId = 0;
|
|
||||||
private int lastReqId;
|
|
||||||
protected String lastFoundUsername = null;
|
|
||||||
|
|
||||||
public void queryServerSearch(final String query) {
|
|
||||||
if (reqId != 0) {
|
|
||||||
ConnectionsManager.getInstance().cancelRpc(reqId, true);
|
|
||||||
reqId = 0;
|
|
||||||
}
|
|
||||||
if (query == null || query.length() < 5) {
|
|
||||||
globalSearch.clear();
|
|
||||||
lastReqId = 0;
|
|
||||||
notifyDataSetChanged();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
TLRPC.TL_contacts_search req = new TLRPC.TL_contacts_search();
|
|
||||||
req.q = query;
|
|
||||||
req.limit = 50;
|
|
||||||
final int currentReqId = ++lastReqId;
|
|
||||||
reqId = ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() {
|
|
||||||
@Override
|
|
||||||
public void run(final TLObject response, final TLRPC.TL_error error) {
|
|
||||||
AndroidUtilities.runOnUIThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (currentReqId == lastReqId) {
|
|
||||||
if (error == null) {
|
|
||||||
TLRPC.TL_contacts_found res = (TLRPC.TL_contacts_found) response;
|
|
||||||
globalSearch = res.users;
|
|
||||||
lastFoundUsername = query;
|
|
||||||
notifyDataSetChanged();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
reqId = 0;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}, true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassFailOnServerErrors);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,209 @@
|
||||||
|
/*
|
||||||
|
* This is the source code of Telegram for Android v. 1.7.x.
|
||||||
|
* It is licensed under GNU GPL v. 2 or later.
|
||||||
|
* You should have received a copy of the license in this archive (see LICENSE).
|
||||||
|
*
|
||||||
|
* Copyright Nikolai Kudashov, 2013-2014.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.telegram.ui.Adapters;
|
||||||
|
|
||||||
|
import org.telegram.SQLite.SQLiteCursor;
|
||||||
|
import org.telegram.SQLite.SQLitePreparedStatement;
|
||||||
|
import org.telegram.android.AndroidUtilities;
|
||||||
|
import org.telegram.android.MessagesStorage;
|
||||||
|
import org.telegram.messenger.ConnectionsManager;
|
||||||
|
import org.telegram.messenger.FileLog;
|
||||||
|
import org.telegram.messenger.RPCRequest;
|
||||||
|
import org.telegram.messenger.TLObject;
|
||||||
|
import org.telegram.messenger.TLRPC;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
public class BaseSearchAdapter extends BaseFragmentAdapter {
|
||||||
|
|
||||||
|
protected static class HashtagObject {
|
||||||
|
String hashtag;
|
||||||
|
int date;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ArrayList<TLRPC.User> globalSearch = new ArrayList<>();
|
||||||
|
private long reqId = 0;
|
||||||
|
private int lastReqId;
|
||||||
|
protected String lastFoundUsername = null;
|
||||||
|
|
||||||
|
protected ArrayList<HashtagObject> hashtags;
|
||||||
|
protected HashMap<String, HashtagObject> hashtagsByText;
|
||||||
|
protected boolean hashtagsLoadedFromDb = false;
|
||||||
|
|
||||||
|
public void queryServerSearch(final String query) {
|
||||||
|
if (reqId != 0) {
|
||||||
|
ConnectionsManager.getInstance().cancelRpc(reqId, true);
|
||||||
|
reqId = 0;
|
||||||
|
}
|
||||||
|
if (query == null || query.length() < 5) {
|
||||||
|
globalSearch.clear();
|
||||||
|
lastReqId = 0;
|
||||||
|
notifyDataSetChanged();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
TLRPC.TL_contacts_search req = new TLRPC.TL_contacts_search();
|
||||||
|
req.q = query;
|
||||||
|
req.limit = 50;
|
||||||
|
final int currentReqId = ++lastReqId;
|
||||||
|
reqId = ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() {
|
||||||
|
@Override
|
||||||
|
public void run(final TLObject response, final TLRPC.TL_error error) {
|
||||||
|
AndroidUtilities.runOnUIThread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (currentReqId == lastReqId) {
|
||||||
|
if (error == null) {
|
||||||
|
TLRPC.TL_contacts_found res = (TLRPC.TL_contacts_found) response;
|
||||||
|
globalSearch = res.users;
|
||||||
|
lastFoundUsername = query;
|
||||||
|
notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
reqId = 0;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassFailOnServerErrors);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadRecentHashtags() {
|
||||||
|
MessagesStorage.getInstance().getStorageQueue().postRunnable(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
SQLiteCursor cursor = MessagesStorage.getInstance().getDatabase().queryFinalized("SELECT id, date FROM hashtag_recent_v2 WHERE 1");
|
||||||
|
final ArrayList<HashtagObject> arrayList = new ArrayList<>();
|
||||||
|
final HashMap<String, HashtagObject> hashMap = new HashMap<>();
|
||||||
|
while (cursor.next()) {
|
||||||
|
HashtagObject hashtagObject = new HashtagObject();
|
||||||
|
hashtagObject.hashtag = cursor.stringValue(0);
|
||||||
|
hashtagObject.date = cursor.intValue(1);
|
||||||
|
arrayList.add(hashtagObject);
|
||||||
|
hashMap.put(hashtagObject.hashtag, hashtagObject);
|
||||||
|
}
|
||||||
|
cursor.dispose();
|
||||||
|
Collections.sort(arrayList, new Comparator<HashtagObject>() {
|
||||||
|
@Override
|
||||||
|
public int compare(HashtagObject lhs, HashtagObject rhs) {
|
||||||
|
if (lhs.date < rhs.date) {
|
||||||
|
return 1;
|
||||||
|
} else if (lhs.date > rhs.date) {
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
AndroidUtilities.runOnUIThread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
setHashtags(arrayList, hashMap);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (Exception e) {
|
||||||
|
FileLog.e("tmessages", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addHashtagsFromMessage(String message) {
|
||||||
|
if (message == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
boolean changed = false;
|
||||||
|
Pattern pattern = Pattern.compile("(^|\\s)#[\\w@\\.]+");
|
||||||
|
Matcher matcher = pattern.matcher(message);
|
||||||
|
while (matcher.find()) {
|
||||||
|
int start = matcher.start();
|
||||||
|
int end = matcher.end();
|
||||||
|
if (message.charAt(start) != '@' && message.charAt(start) != '#') {
|
||||||
|
start++;
|
||||||
|
}
|
||||||
|
String hashtag = message.substring(start, end);
|
||||||
|
if (hashtagsByText == null) {
|
||||||
|
hashtagsByText = new HashMap<>();
|
||||||
|
hashtags = new ArrayList<>();
|
||||||
|
}
|
||||||
|
HashtagObject hashtagObject = hashtagsByText.get(hashtag);
|
||||||
|
if (hashtagObject == null) {
|
||||||
|
hashtagObject = new HashtagObject();
|
||||||
|
hashtagObject.hashtag = hashtag;
|
||||||
|
hashtagsByText.put(hashtagObject.hashtag, hashtagObject);
|
||||||
|
} else {
|
||||||
|
hashtags.remove(hashtagObject);
|
||||||
|
}
|
||||||
|
hashtagObject.date = (int) (System.currentTimeMillis() / 1000);
|
||||||
|
hashtags.add(0, hashtagObject);
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
if (changed) {
|
||||||
|
putRecentHashtags(hashtags);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void putRecentHashtags(final ArrayList<HashtagObject> arrayList) {
|
||||||
|
MessagesStorage.getInstance().getStorageQueue().postRunnable(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
MessagesStorage.getInstance().getDatabase().beginTransaction();
|
||||||
|
SQLitePreparedStatement state = MessagesStorage.getInstance().getDatabase().executeFast("REPLACE INTO hashtag_recent_v2 VALUES(?, ?)");
|
||||||
|
for (int a = 0; a < arrayList.size(); a++) {
|
||||||
|
if (a == 100) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
HashtagObject hashtagObject = arrayList.get(a);
|
||||||
|
state.requery();
|
||||||
|
state.bindString(1, hashtagObject.hashtag);
|
||||||
|
state.bindInteger(2, hashtagObject.date);
|
||||||
|
state.step();
|
||||||
|
}
|
||||||
|
state.dispose();
|
||||||
|
MessagesStorage.getInstance().getDatabase().commitTransaction();
|
||||||
|
if (arrayList.size() >= 100) {
|
||||||
|
MessagesStorage.getInstance().getDatabase().beginTransaction();
|
||||||
|
for (int a = 100; a < arrayList.size(); a++) {
|
||||||
|
MessagesStorage.getInstance().getDatabase().executeFast("DELETE FROM hashtag_recent_v2 WHERE id = '" + arrayList.get(a).hashtag + "'").stepThis().dispose();
|
||||||
|
}
|
||||||
|
MessagesStorage.getInstance().getDatabase().commitTransaction();
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
FileLog.e("tmessages", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearRecentHashtags() {
|
||||||
|
hashtags = new ArrayList<>();
|
||||||
|
hashtagsByText = new HashMap<>();
|
||||||
|
MessagesStorage.getInstance().getStorageQueue().postRunnable(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
MessagesStorage.getInstance().getDatabase().executeFast("DELETE FROM hashtag_recent_v2 WHERE 1").stepThis().dispose();
|
||||||
|
} catch (Exception e) {
|
||||||
|
FileLog.e("tmessages", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setHashtags(ArrayList<HashtagObject> arrayList, HashMap<String, HashtagObject> hashMap) {
|
||||||
|
hashtags = arrayList;
|
||||||
|
hashtagsByText = hashMap;
|
||||||
|
hashtagsLoadedFromDb = true;
|
||||||
|
}
|
||||||
|
}
|
|
@ -73,7 +73,7 @@ public class CountrySearchAdapter extends BaseFragmentAdapter {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
long time = System.currentTimeMillis();
|
long time = System.currentTimeMillis();
|
||||||
ArrayList<Country> resultArray = new ArrayList<Country>();
|
ArrayList<Country> resultArray = new ArrayList<>();
|
||||||
|
|
||||||
String n = query.substring(0, 1);
|
String n = query.substring(0, 1);
|
||||||
ArrayList<Country> arr = countries.get(n.toUpperCase());
|
ArrayList<Country> arr = countries.get(n.toUpperCase());
|
||||||
|
|
|
@ -13,7 +13,6 @@ import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
import org.telegram.android.AndroidUtilities;
|
import org.telegram.android.AndroidUtilities;
|
||||||
import org.telegram.android.MessageObject;
|
|
||||||
import org.telegram.android.MessagesController;
|
import org.telegram.android.MessagesController;
|
||||||
import org.telegram.messenger.TLRPC;
|
import org.telegram.messenger.TLRPC;
|
||||||
import org.telegram.ui.Cells.DialogCell;
|
import org.telegram.ui.Cells.DialogCell;
|
||||||
|
@ -24,6 +23,7 @@ public class DialogsAdapter extends BaseFragmentAdapter {
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private boolean serverOnly;
|
private boolean serverOnly;
|
||||||
private long openedDialogId;
|
private long openedDialogId;
|
||||||
|
private int currentCount;
|
||||||
|
|
||||||
public DialogsAdapter(Context context, boolean onlyFromServer) {
|
public DialogsAdapter(Context context, boolean onlyFromServer) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
|
@ -34,6 +34,11 @@ public class DialogsAdapter extends BaseFragmentAdapter {
|
||||||
openedDialogId = id;
|
openedDialogId = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isDataSetChanged() {
|
||||||
|
int current = currentCount;
|
||||||
|
return current != getCount();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean areAllItemsEnabled() {
|
public boolean areAllItemsEnabled() {
|
||||||
return true;
|
return true;
|
||||||
|
@ -58,6 +63,7 @@ public class DialogsAdapter extends BaseFragmentAdapter {
|
||||||
if (!MessagesController.getInstance().dialogsEndReached) {
|
if (!MessagesController.getInstance().dialogsEndReached) {
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
currentCount = count;
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,22 +103,23 @@ public class DialogsAdapter extends BaseFragmentAdapter {
|
||||||
if (view == null) {
|
if (view == null) {
|
||||||
view = new DialogCell(mContext);
|
view = new DialogCell(mContext);
|
||||||
}
|
}
|
||||||
((DialogCell) view).useSeparator = (i != getCount() - 1);
|
if (view instanceof DialogCell) { //TODO finally i need to find this crash
|
||||||
TLRPC.TL_dialog dialog = null;
|
((DialogCell) view).useSeparator = (i != getCount() - 1);
|
||||||
if (serverOnly) {
|
TLRPC.TL_dialog dialog = null;
|
||||||
dialog = MessagesController.getInstance().dialogsServerOnly.get(i);
|
if (serverOnly) {
|
||||||
} else {
|
dialog = MessagesController.getInstance().dialogsServerOnly.get(i);
|
||||||
dialog = MessagesController.getInstance().dialogs.get(i);
|
} else {
|
||||||
if (AndroidUtilities.isTablet()) {
|
dialog = MessagesController.getInstance().dialogs.get(i);
|
||||||
if (dialog.id == openedDialogId) {
|
if (AndroidUtilities.isTablet()) {
|
||||||
view.setBackgroundColor(0x0f000000);
|
if (dialog.id == openedDialogId) {
|
||||||
} else {
|
view.setBackgroundColor(0x0f000000);
|
||||||
view.setBackgroundColor(0);
|
} else {
|
||||||
|
view.setBackgroundColor(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
((DialogCell) view).setDialog(dialog, i, serverOnly);
|
||||||
}
|
}
|
||||||
MessageObject message = MessagesController.getInstance().dialogMessage.get(dialog.top_message);
|
|
||||||
((DialogCell) view).setDialog(dialog.id, message, true, dialog.last_message_date, dialog.unread_count, MessagesController.getInstance().isDialogMuted(dialog.id));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
|
@ -133,9 +140,6 @@ public class DialogsAdapter extends BaseFragmentAdapter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEmpty() {
|
public boolean isEmpty() {
|
||||||
if (MessagesController.getInstance().loadingDialogs && MessagesController.getInstance().dialogs.isEmpty()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
int count;
|
int count;
|
||||||
if (serverOnly) {
|
if (serverOnly) {
|
||||||
count = MessagesController.getInstance().dialogsServerOnly.size();
|
count = MessagesController.getInstance().dialogsServerOnly.size();
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
package org.telegram.ui.Adapters;
|
package org.telegram.ui.Adapters;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.text.Html;
|
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
@ -33,6 +32,7 @@ import org.telegram.messenger.UserConfig;
|
||||||
import org.telegram.messenger.Utilities;
|
import org.telegram.messenger.Utilities;
|
||||||
import org.telegram.ui.Cells.DialogCell;
|
import org.telegram.ui.Cells.DialogCell;
|
||||||
import org.telegram.ui.Cells.GreySectionCell;
|
import org.telegram.ui.Cells.GreySectionCell;
|
||||||
|
import org.telegram.ui.Cells.HashtagSearchCell;
|
||||||
import org.telegram.ui.Cells.LoadingCell;
|
import org.telegram.ui.Cells.LoadingCell;
|
||||||
import org.telegram.ui.Cells.ProfileSearchCell;
|
import org.telegram.ui.Cells.ProfileSearchCell;
|
||||||
|
|
||||||
|
@ -44,18 +44,19 @@ import java.util.Locale;
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
|
|
||||||
public class DialogsSearchAdapter extends BaseContactsSearchAdapter {
|
public class DialogsSearchAdapter extends BaseSearchAdapter {
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private Timer searchTimer;
|
private Timer searchTimer;
|
||||||
private ArrayList<TLObject> searchResult = new ArrayList<>();
|
private ArrayList<TLObject> searchResult = new ArrayList<>();
|
||||||
private ArrayList<CharSequence> searchResultNames = new ArrayList<>();
|
private ArrayList<CharSequence> searchResultNames = new ArrayList<>();
|
||||||
private ArrayList<MessageObject> searchResultMessages = new ArrayList<>();
|
private ArrayList<MessageObject> searchResultMessages = new ArrayList<>();
|
||||||
|
private ArrayList<String> searchResultHashtags = new ArrayList<>();
|
||||||
private String lastSearchText;
|
private String lastSearchText;
|
||||||
private long reqId = 0;
|
private long reqId = 0;
|
||||||
private int lastReqId;
|
private int lastReqId;
|
||||||
private MessagesActivitySearchAdapterDelegate delegate;
|
private MessagesActivitySearchAdapterDelegate delegate;
|
||||||
private boolean needMessagesSearch;
|
private int needMessagesSearch;
|
||||||
private boolean messagesSearchEndReached;
|
private boolean messagesSearchEndReached;
|
||||||
private String lastMessagesSearchString;
|
private String lastMessagesSearchString;
|
||||||
private int lastSearchId = 0;
|
private int lastSearchId = 0;
|
||||||
|
@ -66,11 +67,11 @@ public class DialogsSearchAdapter extends BaseContactsSearchAdapter {
|
||||||
public CharSequence name;
|
public CharSequence name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static interface MessagesActivitySearchAdapterDelegate {
|
public interface MessagesActivitySearchAdapterDelegate {
|
||||||
public abstract void searchStateChanged(boolean searching);
|
void searchStateChanged(boolean searching);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DialogsSearchAdapter(Context context, boolean messagesSearch) {
|
public DialogsSearchAdapter(Context context, int messagesSearch) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
needMessagesSearch = messagesSearch;
|
needMessagesSearch = messagesSearch;
|
||||||
}
|
}
|
||||||
|
@ -87,8 +88,12 @@ public class DialogsSearchAdapter extends BaseContactsSearchAdapter {
|
||||||
searchMessagesInternal(lastMessagesSearchString);
|
searchMessagesInternal(lastMessagesSearchString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getLastSearchString() {
|
||||||
|
return lastMessagesSearchString;
|
||||||
|
}
|
||||||
|
|
||||||
private void searchMessagesInternal(final String query) {
|
private void searchMessagesInternal(final String query) {
|
||||||
if (!needMessagesSearch) {
|
if (needMessagesSearch == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (reqId != 0) {
|
if (reqId != 0) {
|
||||||
|
@ -110,7 +115,7 @@ public class DialogsSearchAdapter extends BaseContactsSearchAdapter {
|
||||||
req.peer = new TLRPC.TL_inputPeerEmpty();
|
req.peer = new TLRPC.TL_inputPeerEmpty();
|
||||||
req.q = query;
|
req.q = query;
|
||||||
if (lastMessagesSearchString != null && query.equals(lastMessagesSearchString) && !searchResultMessages.isEmpty()) {
|
if (lastMessagesSearchString != null && query.equals(lastMessagesSearchString) && !searchResultMessages.isEmpty()) {
|
||||||
req.max_id = searchResultMessages.get(searchResultMessages.size() - 1).messageOwner.id;
|
req.max_id = searchResultMessages.get(searchResultMessages.size() - 1).getId();
|
||||||
}
|
}
|
||||||
lastMessagesSearchString = query;
|
lastMessagesSearchString = query;
|
||||||
req.filter = new TLRPC.TL_inputMessagesFilterEmpty();
|
req.filter = new TLRPC.TL_inputMessagesFilterEmpty();
|
||||||
|
@ -151,6 +156,9 @@ public class DialogsSearchAdapter extends BaseContactsSearchAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void searchDialogsInternal(final String query, final boolean serverOnly, final int searchId) {
|
private void searchDialogsInternal(final String query, final boolean serverOnly, final int searchId) {
|
||||||
|
if (needMessagesSearch == 2) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
MessagesStorage.getInstance().getStorageQueue().postRunnable(new Runnable() {
|
MessagesStorage.getInstance().getStorageQueue().postRunnable(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -178,15 +186,15 @@ public class DialogsSearchAdapter extends BaseContactsSearchAdapter {
|
||||||
int resultCount = 0;
|
int resultCount = 0;
|
||||||
|
|
||||||
HashMap<Long, DialogSearchResult> dialogsResult = new HashMap<>();
|
HashMap<Long, DialogSearchResult> dialogsResult = new HashMap<>();
|
||||||
SQLiteCursor cursor = MessagesStorage.getInstance().getDatabase().queryFinalized(String.format(Locale.US, "SELECT did, date FROM dialogs ORDER BY date DESC LIMIT 200"));
|
SQLiteCursor cursor = MessagesStorage.getInstance().getDatabase().queryFinalized("SELECT did, date FROM dialogs ORDER BY date DESC LIMIT 200");
|
||||||
while (cursor.next()) {
|
while (cursor.next()) {
|
||||||
long id = cursor.longValue(0);
|
long id = cursor.longValue(0);
|
||||||
DialogSearchResult dialogSearchResult = new DialogSearchResult();
|
DialogSearchResult dialogSearchResult = new DialogSearchResult();
|
||||||
dialogSearchResult.date = cursor.intValue(1);
|
dialogSearchResult.date = cursor.intValue(1);
|
||||||
dialogsResult.put(id, dialogSearchResult);
|
dialogsResult.put(id, dialogSearchResult);
|
||||||
|
|
||||||
int lower_id = (int)id;
|
int lower_id = (int) id;
|
||||||
int high_id = (int)(id >> 32);
|
int high_id = (int) (id >> 32);
|
||||||
if (lower_id != 0) {
|
if (lower_id != 0) {
|
||||||
if (high_id == 1) {
|
if (high_id == 1) {
|
||||||
if (!serverOnly && !chatsToLoad.contains(lower_id)) {
|
if (!serverOnly && !chatsToLoad.contains(lower_id)) {
|
||||||
|
@ -215,6 +223,10 @@ public class DialogsSearchAdapter extends BaseContactsSearchAdapter {
|
||||||
cursor = MessagesStorage.getInstance().getDatabase().queryFinalized(String.format(Locale.US, "SELECT data, status, name FROM users WHERE uid IN(%s)", TextUtils.join(",", usersToLoad)));
|
cursor = MessagesStorage.getInstance().getDatabase().queryFinalized(String.format(Locale.US, "SELECT data, status, name FROM users WHERE uid IN(%s)", TextUtils.join(",", usersToLoad)));
|
||||||
while (cursor.next()) {
|
while (cursor.next()) {
|
||||||
String name = cursor.stringValue(2);
|
String name = cursor.stringValue(2);
|
||||||
|
String tName = LocaleController.getInstance().getTranslitString(name);
|
||||||
|
if (name.equals(tName)) {
|
||||||
|
tName = null;
|
||||||
|
}
|
||||||
String username = null;
|
String username = null;
|
||||||
int usernamePos = name.lastIndexOf(";;;");
|
int usernamePos = name.lastIndexOf(";;;");
|
||||||
if (usernamePos != -1) {
|
if (usernamePos != -1) {
|
||||||
|
@ -222,7 +234,7 @@ public class DialogsSearchAdapter extends BaseContactsSearchAdapter {
|
||||||
}
|
}
|
||||||
int found = 0;
|
int found = 0;
|
||||||
for (String q : search) {
|
for (String q : search) {
|
||||||
if (name.startsWith(q) || name.contains(" " + q)) {
|
if (name.startsWith(q) || name.contains(" " + q) || tName != null && (tName.startsWith(q) || tName.contains(" " + q))) {
|
||||||
found = 1;
|
found = 1;
|
||||||
} else if (username != null && username.startsWith(q)) {
|
} else if (username != null && username.startsWith(q)) {
|
||||||
found = 2;
|
found = 2;
|
||||||
|
@ -257,8 +269,12 @@ public class DialogsSearchAdapter extends BaseContactsSearchAdapter {
|
||||||
cursor = MessagesStorage.getInstance().getDatabase().queryFinalized(String.format(Locale.US, "SELECT data, name FROM chats WHERE uid IN(%s)", TextUtils.join(",", chatsToLoad)));
|
cursor = MessagesStorage.getInstance().getDatabase().queryFinalized(String.format(Locale.US, "SELECT data, name FROM chats WHERE uid IN(%s)", TextUtils.join(",", chatsToLoad)));
|
||||||
while (cursor.next()) {
|
while (cursor.next()) {
|
||||||
String name = cursor.stringValue(1);
|
String name = cursor.stringValue(1);
|
||||||
|
String tName = LocaleController.getInstance().getTranslitString(name);
|
||||||
|
if (name.equals(tName)) {
|
||||||
|
tName = null;
|
||||||
|
}
|
||||||
for (String q : search) {
|
for (String q : search) {
|
||||||
if (name.startsWith(q) || name.contains(" " + q)) {
|
if (name.startsWith(q) || name.contains(" " + q) || tName != null && (tName.startsWith(q) || tName.contains(" " + q))) {
|
||||||
ByteBufferDesc data = MessagesStorage.getInstance().getBuffersStorage().getFreeBuffer(cursor.byteArrayLength(0));
|
ByteBufferDesc data = MessagesStorage.getInstance().getBuffersStorage().getFreeBuffer(cursor.byteArrayLength(0));
|
||||||
if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
|
if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
|
||||||
TLRPC.Chat chat = (TLRPC.Chat) TLClassStore.Instance().TLdeserialize(data, data.readInt32());
|
TLRPC.Chat chat = (TLRPC.Chat) TLClassStore.Instance().TLdeserialize(data, data.readInt32());
|
||||||
|
@ -285,6 +301,10 @@ public class DialogsSearchAdapter extends BaseContactsSearchAdapter {
|
||||||
cursor = MessagesStorage.getInstance().getDatabase().queryFinalized(String.format(Locale.US, "SELECT q.data, u.name, q.user, q.g, q.authkey, q.ttl, u.data, u.status, q.layer, q.seq_in, q.seq_out, q.use_count, q.exchange_id, q.key_date, q.fprint, q.fauthkey, q.khash FROM enc_chats as q INNER JOIN users as u ON q.user = u.uid WHERE q.uid IN(%s)", TextUtils.join(",", encryptedToLoad)));
|
cursor = MessagesStorage.getInstance().getDatabase().queryFinalized(String.format(Locale.US, "SELECT q.data, u.name, q.user, q.g, q.authkey, q.ttl, u.data, u.status, q.layer, q.seq_in, q.seq_out, q.use_count, q.exchange_id, q.key_date, q.fprint, q.fauthkey, q.khash FROM enc_chats as q INNER JOIN users as u ON q.user = u.uid WHERE q.uid IN(%s)", TextUtils.join(",", encryptedToLoad)));
|
||||||
while (cursor.next()) {
|
while (cursor.next()) {
|
||||||
String name = cursor.stringValue(1);
|
String name = cursor.stringValue(1);
|
||||||
|
String tName = LocaleController.getInstance().getTranslitString(name);
|
||||||
|
if (name.equals(tName)) {
|
||||||
|
tName = null;
|
||||||
|
}
|
||||||
|
|
||||||
String username = null;
|
String username = null;
|
||||||
int usernamePos = name.lastIndexOf(";;;");
|
int usernamePos = name.lastIndexOf(";;;");
|
||||||
|
@ -293,7 +313,7 @@ public class DialogsSearchAdapter extends BaseContactsSearchAdapter {
|
||||||
}
|
}
|
||||||
int found = 0;
|
int found = 0;
|
||||||
for (String q : search) {
|
for (String q : search) {
|
||||||
if (name.startsWith(q) || name.contains(" " + q)) {
|
if (name.startsWith(q) || name.contains(" " + q) || tName != null && (tName.startsWith(q) || tName.contains(" " + q))) {
|
||||||
found = 1;
|
found = 1;
|
||||||
} else if (username != null && username.startsWith(q)) {
|
} else if (username != null && username.startsWith(q)) {
|
||||||
found = 2;
|
found = 2;
|
||||||
|
@ -327,7 +347,7 @@ public class DialogsSearchAdapter extends BaseContactsSearchAdapter {
|
||||||
user.status.expires = cursor.intValue(7);
|
user.status.expires = cursor.intValue(7);
|
||||||
}
|
}
|
||||||
if (found == 1) {
|
if (found == 1) {
|
||||||
dialogSearchResult.name = Html.fromHtml("<font color=\"#00a60e\">" + ContactsController.formatName(user.first_name, user.last_name) + "</font>");
|
dialogSearchResult.name = AndroidUtilities.replaceTags("<c#ff00a60e>" + ContactsController.formatName(user.first_name, user.last_name) + "</c>");
|
||||||
} else {
|
} else {
|
||||||
dialogSearchResult.name = Utilities.generateSearchName("@" + user.username, null, "@" + q);
|
dialogSearchResult.name = Utilities.generateSearchName("@" + user.username, null, "@" + q);
|
||||||
}
|
}
|
||||||
|
@ -374,10 +394,14 @@ public class DialogsSearchAdapter extends BaseContactsSearchAdapter {
|
||||||
cursor = MessagesStorage.getInstance().getDatabase().queryFinalized("SELECT u.data, u.status, u.name, u.uid FROM users as u INNER JOIN contacts as c ON u.uid = c.uid");
|
cursor = MessagesStorage.getInstance().getDatabase().queryFinalized("SELECT u.data, u.status, u.name, u.uid FROM users as u INNER JOIN contacts as c ON u.uid = c.uid");
|
||||||
while (cursor.next()) {
|
while (cursor.next()) {
|
||||||
int uid = cursor.intValue(3);
|
int uid = cursor.intValue(3);
|
||||||
if (dialogsResult.containsKey((long)uid)) {
|
if (dialogsResult.containsKey((long) uid)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
String name = cursor.stringValue(2);
|
String name = cursor.stringValue(2);
|
||||||
|
String tName = LocaleController.getInstance().getTranslitString(name);
|
||||||
|
if (name.equals(tName)) {
|
||||||
|
tName = null;
|
||||||
|
}
|
||||||
String username = null;
|
String username = null;
|
||||||
int usernamePos = name.lastIndexOf(";;;");
|
int usernamePos = name.lastIndexOf(";;;");
|
||||||
if (usernamePos != -1) {
|
if (usernamePos != -1) {
|
||||||
|
@ -385,7 +409,7 @@ public class DialogsSearchAdapter extends BaseContactsSearchAdapter {
|
||||||
}
|
}
|
||||||
int found = 0;
|
int found = 0;
|
||||||
for (String q : search) {
|
for (String q : search) {
|
||||||
if (name.startsWith(q) || name.contains(" " + q)) {
|
if (name.startsWith(q) || name.contains(" " + q) || tName != null && (tName.startsWith(q) || tName.contains(" " + q))) {
|
||||||
found = 1;
|
found = 1;
|
||||||
} else if (username != null && username.startsWith(q)) {
|
} else if (username != null && username.startsWith(q)) {
|
||||||
found = 2;
|
found = 2;
|
||||||
|
@ -458,6 +482,25 @@ public class DialogsSearchAdapter extends BaseContactsSearchAdapter {
|
||||||
return i > searchResult.size() && i <= globalSearch.size() + searchResult.size();
|
return i > searchResult.size() && i <= globalSearch.size() + searchResult.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clearRecentHashtags() {
|
||||||
|
super.clearRecentHashtags();
|
||||||
|
searchResultHashtags.clear();
|
||||||
|
notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setHashtags(ArrayList<HashtagObject> arrayList, HashMap<String, HashtagObject> hashMap) {
|
||||||
|
super.setHashtags(arrayList, hashMap);
|
||||||
|
for (HashtagObject hashtagObject : arrayList) {
|
||||||
|
searchResultHashtags.add(hashtagObject.hashtag);
|
||||||
|
}
|
||||||
|
if (delegate != null) {
|
||||||
|
delegate.searchStateChanged(false);
|
||||||
|
}
|
||||||
|
notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
|
||||||
public void searchDialogs(final String query, final boolean serverOnly) {
|
public void searchDialogs(final String query, final boolean serverOnly) {
|
||||||
if (query != null && lastSearchText != null && query.equals(lastSearchText)) {
|
if (query != null && lastSearchText != null && query.equals(lastSearchText)) {
|
||||||
return;
|
return;
|
||||||
|
@ -470,12 +513,39 @@ public class DialogsSearchAdapter extends BaseContactsSearchAdapter {
|
||||||
FileLog.e("tmessages", e);
|
FileLog.e("tmessages", e);
|
||||||
}
|
}
|
||||||
if (query == null || query.length() == 0) {
|
if (query == null || query.length() == 0) {
|
||||||
|
hashtagsLoadedFromDb = false;
|
||||||
searchResult.clear();
|
searchResult.clear();
|
||||||
searchResultNames.clear();
|
searchResultNames.clear();
|
||||||
|
searchResultHashtags.clear();
|
||||||
|
if (needMessagesSearch != 2) {
|
||||||
|
queryServerSearch(null);
|
||||||
|
}
|
||||||
searchMessagesInternal(null);
|
searchMessagesInternal(null);
|
||||||
queryServerSearch(null);
|
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
} else {
|
} else {
|
||||||
|
if (query.startsWith("#") && query.length() == 1) {
|
||||||
|
messagesSearchEndReached = true;
|
||||||
|
if (!hashtagsLoadedFromDb) {
|
||||||
|
loadRecentHashtags();
|
||||||
|
if (delegate != null) {
|
||||||
|
delegate.searchStateChanged(true);
|
||||||
|
}
|
||||||
|
notifyDataSetChanged();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
searchResultMessages.clear();
|
||||||
|
searchResultHashtags.clear();
|
||||||
|
for (HashtagObject hashtagObject : hashtags) {
|
||||||
|
searchResultHashtags.add(hashtagObject.hashtag);
|
||||||
|
}
|
||||||
|
if (delegate != null) {
|
||||||
|
delegate.searchStateChanged(false);
|
||||||
|
}
|
||||||
|
notifyDataSetChanged();
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
searchResultHashtags.clear();
|
||||||
|
}
|
||||||
final int searchId = ++lastSearchId;
|
final int searchId = ++lastSearchId;
|
||||||
searchTimer = new Timer();
|
searchTimer = new Timer();
|
||||||
searchTimer.schedule(new TimerTask() {
|
searchTimer.schedule(new TimerTask() {
|
||||||
|
@ -491,7 +561,9 @@ public class DialogsSearchAdapter extends BaseContactsSearchAdapter {
|
||||||
AndroidUtilities.runOnUIThread(new Runnable() {
|
AndroidUtilities.runOnUIThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
queryServerSearch(query);
|
if (needMessagesSearch != 2) {
|
||||||
|
queryServerSearch(query);
|
||||||
|
}
|
||||||
searchMessagesInternal(query);
|
searchMessagesInternal(query);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -507,11 +579,27 @@ public class DialogsSearchAdapter extends BaseContactsSearchAdapter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEnabled(int i) {
|
public boolean isEnabled(int i) {
|
||||||
return i != searchResult.size() && i != searchResult.size() + (globalSearch.isEmpty() ? 0 : globalSearch.size() + 1);
|
if (!searchResultHashtags.isEmpty()) {
|
||||||
|
return i != 0;
|
||||||
|
}
|
||||||
|
int localCount = searchResult.size();
|
||||||
|
int globalCount = globalSearch.isEmpty() ? 0 : globalSearch.size() + 1;
|
||||||
|
int messagesCount = searchResultMessages.isEmpty() ? 0 : searchResultMessages.size() + 1;
|
||||||
|
if (i >= 0 && i < localCount || i > localCount && i < globalCount + localCount) {
|
||||||
|
return true;
|
||||||
|
} else if (i > globalCount + localCount && i < globalCount + localCount + messagesCount) {
|
||||||
|
return true;
|
||||||
|
} else if (messagesCount != 0 && i == globalCount + localCount + messagesCount) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getCount() {
|
public int getCount() {
|
||||||
|
if (!searchResultHashtags.isEmpty()) {
|
||||||
|
return searchResultHashtags.size() + 1;
|
||||||
|
}
|
||||||
int count = searchResult.size();
|
int count = searchResult.size();
|
||||||
int globalCount = globalSearch.size();
|
int globalCount = globalSearch.size();
|
||||||
int messagesCount = searchResultMessages.size();
|
int messagesCount = searchResultMessages.size();
|
||||||
|
@ -526,6 +614,9 @@ public class DialogsSearchAdapter extends BaseContactsSearchAdapter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getItem(int i) {
|
public Object getItem(int i) {
|
||||||
|
if (!searchResultHashtags.isEmpty()) {
|
||||||
|
return searchResultHashtags.get(i - 1);
|
||||||
|
}
|
||||||
int localCount = searchResult.size();
|
int localCount = searchResult.size();
|
||||||
int globalCount = globalSearch.isEmpty() ? 0 : globalSearch.size() + 1;
|
int globalCount = globalSearch.isEmpty() ? 0 : globalSearch.size() + 1;
|
||||||
int messagesCount = searchResultMessages.isEmpty() ? 0 : searchResultMessages.size() + 1;
|
int messagesCount = searchResultMessages.isEmpty() ? 0 : searchResultMessages.size() + 1;
|
||||||
|
@ -557,7 +648,9 @@ public class DialogsSearchAdapter extends BaseContactsSearchAdapter {
|
||||||
if (view == null) {
|
if (view == null) {
|
||||||
view = new GreySectionCell(mContext);
|
view = new GreySectionCell(mContext);
|
||||||
}
|
}
|
||||||
if (!globalSearch.isEmpty() && i == searchResult.size()) {
|
if (!searchResultHashtags.isEmpty()) {
|
||||||
|
((GreySectionCell) view).setText(LocaleController.getString("Hashtags", R.string.Hashtags).toUpperCase());
|
||||||
|
} else if (!globalSearch.isEmpty() && i == searchResult.size()) {
|
||||||
((GreySectionCell) view).setText(LocaleController.getString("GlobalSearch", R.string.GlobalSearch));
|
((GreySectionCell) view).setText(LocaleController.getString("GlobalSearch", R.string.GlobalSearch));
|
||||||
} else {
|
} else {
|
||||||
((GreySectionCell) view).setText(LocaleController.getString("SearchMessages", R.string.SearchMessages));
|
((GreySectionCell) view).setText(LocaleController.getString("SearchMessages", R.string.SearchMessages));
|
||||||
|
@ -577,10 +670,11 @@ public class DialogsSearchAdapter extends BaseContactsSearchAdapter {
|
||||||
((ProfileSearchCell) view).useSeparator = (i != getCount() - 1 && i != localCount - 1 && i != localCount + globalCount - 1);
|
((ProfileSearchCell) view).useSeparator = (i != getCount() - 1 && i != localCount - 1 && i != localCount + globalCount - 1);
|
||||||
Object obj = getItem(i);
|
Object obj = getItem(i);
|
||||||
if (obj instanceof TLRPC.User) {
|
if (obj instanceof TLRPC.User) {
|
||||||
user = MessagesController.getInstance().getUser(((TLRPC.User) obj).id);
|
/*user = MessagesController.getInstance().getUser(((TLRPC.User) obj).id);
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
user = (TLRPC.User) obj;
|
user = (TLRPC.User) obj;
|
||||||
}
|
}*/
|
||||||
|
user = (TLRPC.User) obj;
|
||||||
} else if (obj instanceof TLRPC.Chat) {
|
} else if (obj instanceof TLRPC.Chat) {
|
||||||
chat = MessagesController.getInstance().getChat(((TLRPC.Chat) obj).id);
|
chat = MessagesController.getInstance().getChat(((TLRPC.Chat) obj).id);
|
||||||
} else if (obj instanceof TLRPC.EncryptedChat) {
|
} else if (obj instanceof TLRPC.EncryptedChat) {
|
||||||
|
@ -604,7 +698,7 @@ public class DialogsSearchAdapter extends BaseContactsSearchAdapter {
|
||||||
foundUserName = foundUserName.substring(1);
|
foundUserName = foundUserName.substring(1);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
username = Html.fromHtml(String.format("<font color=\"#4d83b3\">@%s</font>%s", user.username.substring(0, foundUserName.length()), user.username.substring(foundUserName.length())));
|
username = AndroidUtilities.replaceTags(String.format("<c#ff4d83b3>@%s</c>%s", user.username.substring(0, foundUserName.length()), user.username.substring(foundUserName.length())));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
username = user.username;
|
username = user.username;
|
||||||
FileLog.e("tmessages", e);
|
FileLog.e("tmessages", e);
|
||||||
|
@ -618,11 +712,17 @@ public class DialogsSearchAdapter extends BaseContactsSearchAdapter {
|
||||||
}
|
}
|
||||||
((DialogCell) view).useSeparator = (i != getCount() - 1);
|
((DialogCell) view).useSeparator = (i != getCount() - 1);
|
||||||
MessageObject messageObject = (MessageObject)getItem(i);
|
MessageObject messageObject = (MessageObject)getItem(i);
|
||||||
((DialogCell) view).setDialog(messageObject.getDialogId(), messageObject, false, messageObject.messageOwner.date, 0, false);
|
((DialogCell) view).setDialog(messageObject.getDialogId(), messageObject, messageObject.messageOwner.date);
|
||||||
} else if (type == 3) {
|
} else if (type == 3) {
|
||||||
if (view == null) {
|
if (view == null) {
|
||||||
view = new LoadingCell(mContext);
|
view = new LoadingCell(mContext);
|
||||||
}
|
}
|
||||||
|
} else if (type == 4) {
|
||||||
|
if (view == null) {
|
||||||
|
view = new HashtagSearchCell(mContext);
|
||||||
|
}
|
||||||
|
((HashtagSearchCell) view).setText(searchResultHashtags.get(i - 1));
|
||||||
|
((HashtagSearchCell) view).setNeedDivider(i != searchResultHashtags.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
|
@ -630,6 +730,9 @@ public class DialogsSearchAdapter extends BaseContactsSearchAdapter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemViewType(int i) {
|
public int getItemViewType(int i) {
|
||||||
|
if (!searchResultHashtags.isEmpty()) {
|
||||||
|
return i == 0 ? 1 : 4;
|
||||||
|
}
|
||||||
int localCount = searchResult.size();
|
int localCount = searchResult.size();
|
||||||
int globalCount = globalSearch.isEmpty() ? 0 : globalSearch.size() + 1;
|
int globalCount = globalSearch.isEmpty() ? 0 : globalSearch.size() + 1;
|
||||||
int messagesCount = searchResultMessages.isEmpty() ? 0 : searchResultMessages.size() + 1;
|
int messagesCount = searchResultMessages.isEmpty() ? 0 : searchResultMessages.size() + 1;
|
||||||
|
@ -645,11 +748,11 @@ public class DialogsSearchAdapter extends BaseContactsSearchAdapter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getViewTypeCount() {
|
public int getViewTypeCount() {
|
||||||
return 4;
|
return 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEmpty() {
|
public boolean isEmpty() {
|
||||||
return searchResult.isEmpty() && globalSearch.isEmpty() && searchResultMessages.isEmpty();
|
return searchResult.isEmpty() && globalSearch.isEmpty() && searchResultMessages.isEmpty() && searchResultHashtags.isEmpty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,272 @@
|
||||||
|
/*
|
||||||
|
* This is the source code of Telegram for Android v. 2.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-2015.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.telegram.ui.Adapters;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
import org.telegram.android.MessageObject;
|
||||||
|
import org.telegram.android.MessagesController;
|
||||||
|
import org.telegram.messenger.TLRPC;
|
||||||
|
import org.telegram.ui.Cells.MentionCell;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
public class MentionsAdapter extends BaseSearchAdapter {
|
||||||
|
|
||||||
|
public interface MentionsAdapterDelegate {
|
||||||
|
void needChangePanelVisibility(boolean show);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
|
private TLRPC.ChatParticipants info;
|
||||||
|
private ArrayList<TLRPC.User> searchResultUsernames;
|
||||||
|
private ArrayList<String> searchResultHashtags;
|
||||||
|
private MentionsAdapterDelegate delegate;
|
||||||
|
private int resultStartPosition;
|
||||||
|
private int resultLength;
|
||||||
|
private String lastText;
|
||||||
|
private int lastPosition;
|
||||||
|
private ArrayList<MessageObject> messages;
|
||||||
|
private boolean needUsernames = true;
|
||||||
|
|
||||||
|
public MentionsAdapter(Context context, MentionsAdapterDelegate delegate) {
|
||||||
|
mContext = context;
|
||||||
|
this.delegate = delegate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setChatInfo(TLRPC.ChatParticipants chatParticipants) {
|
||||||
|
info = chatParticipants;
|
||||||
|
if (lastText != null) {
|
||||||
|
searchUsernameOrHashtag(lastText, lastPosition, messages);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNeedUsernames(boolean value) {
|
||||||
|
needUsernames = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clearRecentHashtags() {
|
||||||
|
super.clearRecentHashtags();
|
||||||
|
searchResultHashtags.clear();
|
||||||
|
notifyDataSetChanged();
|
||||||
|
if (delegate != null) {
|
||||||
|
delegate.needChangePanelVisibility(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setHashtags(ArrayList<HashtagObject> arrayList, HashMap<String, HashtagObject> hashMap) {
|
||||||
|
super.setHashtags(arrayList, hashMap);
|
||||||
|
if (lastText != null) {
|
||||||
|
searchUsernameOrHashtag(lastText, lastPosition, messages);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void searchUsernameOrHashtag(String text, int position, ArrayList<MessageObject> messageObjects) {
|
||||||
|
if (text == null || text.length() == 0) {
|
||||||
|
delegate.needChangePanelVisibility(false);
|
||||||
|
lastText = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int searchPostion = position;
|
||||||
|
if (text.length() > 0) {
|
||||||
|
searchPostion--;
|
||||||
|
}
|
||||||
|
lastText = null;
|
||||||
|
StringBuilder result = new StringBuilder();
|
||||||
|
int foundType = -1;
|
||||||
|
boolean hasIllegalUsernameCharacters = false;
|
||||||
|
for (int a = searchPostion; a >= 0; a--) {
|
||||||
|
if (a >= text.length()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
char ch = text.charAt(a);
|
||||||
|
if (a == 0 || text.charAt(a - 1) == ' ' || text.charAt(a - 1) == '\n') {
|
||||||
|
if (needUsernames && ch == '@') {
|
||||||
|
if (hasIllegalUsernameCharacters) {
|
||||||
|
delegate.needChangePanelVisibility(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (info == null) {
|
||||||
|
lastText = text;
|
||||||
|
lastPosition = position;
|
||||||
|
messages = messageObjects;
|
||||||
|
delegate.needChangePanelVisibility(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
foundType = 0;
|
||||||
|
resultStartPosition = a;
|
||||||
|
resultLength = result.length() + 1;
|
||||||
|
break;
|
||||||
|
} else if (ch == '#') {
|
||||||
|
if (!hashtagsLoadedFromDb) {
|
||||||
|
loadRecentHashtags();
|
||||||
|
lastText = text;
|
||||||
|
lastPosition = position;
|
||||||
|
messages = messageObjects;
|
||||||
|
delegate.needChangePanelVisibility(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
foundType = 1;
|
||||||
|
resultStartPosition = a;
|
||||||
|
resultLength = result.length() + 1;
|
||||||
|
result.insert(0, ch);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!(ch >= '0' && ch <= '9' || ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z' || ch == '_')) {
|
||||||
|
hasIllegalUsernameCharacters = true;
|
||||||
|
}
|
||||||
|
result.insert(0, ch);
|
||||||
|
}
|
||||||
|
if (foundType == -1) {
|
||||||
|
delegate.needChangePanelVisibility(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (foundType == 0) {
|
||||||
|
final ArrayList<Integer> users = new ArrayList<>();
|
||||||
|
for (int a = 0; a < Math.min(100, messageObjects.size()); a++) {
|
||||||
|
int from_id = messageObjects.get(a).messageOwner.from_id;
|
||||||
|
if (!users.contains(from_id)) {
|
||||||
|
users.add(from_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String usernameString = result.toString().toLowerCase();
|
||||||
|
ArrayList<TLRPC.User> newResult = new ArrayList<>();
|
||||||
|
for (TLRPC.TL_chatParticipant chatParticipant : info.participants) {
|
||||||
|
TLRPC.User user = MessagesController.getInstance().getUser(chatParticipant.user_id);
|
||||||
|
if (user == null || user instanceof TLRPC.TL_userSelf) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (user.username != null && user.username.length() > 0 && (usernameString.length() > 0 && user.username.toLowerCase().startsWith(usernameString) || usernameString.length() == 0)) {
|
||||||
|
newResult.add(user);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
searchResultHashtags = null;
|
||||||
|
searchResultUsernames = newResult;
|
||||||
|
Collections.sort(searchResultUsernames, new Comparator<TLRPC.User>() {
|
||||||
|
@Override
|
||||||
|
public int compare(TLRPC.User lhs, TLRPC.User rhs) {
|
||||||
|
int lhsNum = users.indexOf(lhs.id);
|
||||||
|
int rhsNum = users.indexOf(rhs.id);
|
||||||
|
if (lhsNum != -1 && rhsNum != -1) {
|
||||||
|
return lhsNum < rhsNum ? -1 : (lhsNum == rhsNum ? 0 : 1);
|
||||||
|
} else if (lhsNum != -1 && rhsNum == -1) {
|
||||||
|
return -1;
|
||||||
|
} else if (lhsNum == -1 && rhsNum != -1) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
notifyDataSetChanged();
|
||||||
|
delegate.needChangePanelVisibility(!newResult.isEmpty());
|
||||||
|
} else {
|
||||||
|
ArrayList<String> newResult = new ArrayList<>();
|
||||||
|
String hashtagString = result.toString().toLowerCase();
|
||||||
|
for (HashtagObject hashtagObject : hashtags) {
|
||||||
|
if (hashtagString != null && hashtagObject.hashtag != null && hashtagObject.hashtag.startsWith(hashtagString)) {
|
||||||
|
newResult.add(hashtagObject.hashtag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
searchResultHashtags = newResult;
|
||||||
|
searchResultUsernames = null;
|
||||||
|
notifyDataSetChanged();
|
||||||
|
delegate.needChangePanelVisibility(!newResult.isEmpty());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getResultStartPosition() {
|
||||||
|
return resultStartPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getResultLength() {
|
||||||
|
return resultLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getViewTypeCount() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getCount() {
|
||||||
|
if (searchResultUsernames != null) {
|
||||||
|
return searchResultUsernames.size();
|
||||||
|
} else if (searchResultHashtags != null) {
|
||||||
|
return searchResultHashtags.size();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEmpty() {
|
||||||
|
if (searchResultUsernames != null) {
|
||||||
|
return searchResultUsernames.isEmpty();
|
||||||
|
} else if (searchResultHashtags != null) {
|
||||||
|
return searchResultHashtags.isEmpty();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemViewType(int position) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasStableIds() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean areAllItemsEnabled() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEnabled(int position) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getItem(int i) {
|
||||||
|
if (searchResultUsernames != null) {
|
||||||
|
if (i < 0 || i >= searchResultUsernames.size()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return searchResultUsernames.get(i);
|
||||||
|
} else if (searchResultHashtags != null) {
|
||||||
|
if (i < 0 || i >= searchResultHashtags.size()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return searchResultHashtags.get(i);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View getView(int i, View view, ViewGroup viewGroup) {
|
||||||
|
if (view == null) {
|
||||||
|
view = new MentionCell(mContext);
|
||||||
|
}
|
||||||
|
if (searchResultUsernames != null) {
|
||||||
|
((MentionCell) view).setUser(searchResultUsernames.get(i));
|
||||||
|
} else if (searchResultHashtags != null) {
|
||||||
|
((MentionCell) view).setText(searchResultHashtags.get(i));
|
||||||
|
}
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
}
|
|
@ -9,7 +9,6 @@
|
||||||
package org.telegram.ui.Adapters;
|
package org.telegram.ui.Adapters;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.text.Html;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
@ -31,7 +30,7 @@ import java.util.HashMap;
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
|
|
||||||
public class ContactsSearchAdapter extends BaseContactsSearchAdapter {
|
public class SearchAdapter extends BaseSearchAdapter {
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private HashMap<Integer, TLRPC.User> ignoreUsers;
|
private HashMap<Integer, TLRPC.User> ignoreUsers;
|
||||||
private ArrayList<TLRPC.User> searchResult = new ArrayList<>();
|
private ArrayList<TLRPC.User> searchResult = new ArrayList<>();
|
||||||
|
@ -41,7 +40,7 @@ public class ContactsSearchAdapter extends BaseContactsSearchAdapter {
|
||||||
private boolean allowUsernameSearch;
|
private boolean allowUsernameSearch;
|
||||||
private boolean useUserCell;
|
private boolean useUserCell;
|
||||||
|
|
||||||
public ContactsSearchAdapter(Context context, HashMap<Integer, TLRPC.User> arg1, boolean usernameSearch) {
|
public SearchAdapter(Context context, HashMap<Integer, TLRPC.User> arg1, boolean usernameSearch) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
ignoreUsers = arg1;
|
ignoreUsers = arg1;
|
||||||
allowUsernameSearch = usernameSearch;
|
allowUsernameSearch = usernameSearch;
|
||||||
|
@ -124,10 +123,14 @@ public class ContactsSearchAdapter extends BaseContactsSearchAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
String name = ContactsController.formatName(user.first_name, user.last_name).toLowerCase();
|
String name = ContactsController.formatName(user.first_name, user.last_name).toLowerCase();
|
||||||
|
String tName = LocaleController.getInstance().getTranslitString(name);
|
||||||
|
if (name.equals(tName)) {
|
||||||
|
tName = null;
|
||||||
|
}
|
||||||
|
|
||||||
int found = 0;
|
int found = 0;
|
||||||
for (String q : search) {
|
for (String q : search) {
|
||||||
if (name.startsWith(q) || name.contains(" " + q)) {
|
if (name.startsWith(q) || name.contains(" " + q) || tName != null && (tName.startsWith(q) || tName.contains(" " + q))) {
|
||||||
found = 1;
|
found = 1;
|
||||||
} else if (user.username != null && user.username.startsWith(q)) {
|
} else if (user.username != null && user.username.startsWith(q)) {
|
||||||
found = 2;
|
found = 2;
|
||||||
|
@ -253,7 +256,7 @@ public class ContactsSearchAdapter extends BaseContactsSearchAdapter {
|
||||||
foundUserName = foundUserName.substring(1);
|
foundUserName = foundUserName.substring(1);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
username = Html.fromHtml(String.format("<font color=\"#4d83b3\">@%s</font>%s", user.username.substring(0, foundUserName.length()), user.username.substring(foundUserName.length())));
|
username = AndroidUtilities.replaceTags(String.format("<c#ff4d83b3>@%s</c>%s", user.username.substring(0, foundUserName.length()), user.username.substring(foundUserName.length())));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
username = user.username;
|
username = user.username;
|
||||||
FileLog.e("tmessages", e);
|
FileLog.e("tmessages", e);
|
|
@ -47,8 +47,8 @@ public class StickersAdapter extends RecyclerView.Adapter implements Notificatio
|
||||||
private String lastSticker;
|
private String lastSticker;
|
||||||
private boolean visible;
|
private boolean visible;
|
||||||
|
|
||||||
public static interface StickersAdapterDelegate {
|
public interface StickersAdapterDelegate {
|
||||||
public abstract void needChangePanelVisibility(boolean show);
|
void needChangePanelVisibility(boolean show);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class Holder extends RecyclerView.ViewHolder {
|
private class Holder extends RecyclerView.ViewHolder {
|
||||||
|
@ -80,7 +80,7 @@ public class StickersAdapter extends RecyclerView.Adapter implements Notificatio
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (stickers != null && !stickers.isEmpty() && !stickersToLoad.isEmpty() && visible) {
|
if (stickers != null && !stickers.isEmpty() && !stickersToLoad.isEmpty() && visible) {
|
||||||
String fileName = (String)args[0];
|
String fileName = (String) args[0];
|
||||||
stickersToLoad.remove(fileName);
|
stickersToLoad.remove(fileName);
|
||||||
if (stickersToLoad.isEmpty()) {
|
if (stickersToLoad.isEmpty()) {
|
||||||
delegate.needChangePanelVisibility(stickers != null && !stickers.isEmpty() && stickersToLoad.isEmpty());
|
delegate.needChangePanelVisibility(stickers != null && !stickers.isEmpty() && stickersToLoad.isEmpty());
|
||||||
|
@ -203,6 +203,9 @@ public class StickersAdapter extends RecyclerView.Adapter implements Notificatio
|
||||||
}
|
}
|
||||||
HashMap<Long, TLRPC.Document> documents = new HashMap<>();
|
HashMap<Long, TLRPC.Document> documents = new HashMap<>();
|
||||||
for (TLRPC.Document document : res.documents) {
|
for (TLRPC.Document document : res.documents) {
|
||||||
|
if (document == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
documents.put(document.id, document);
|
documents.put(document.id, document);
|
||||||
if (document.thumb != null && document.thumb.location != null) {
|
if (document.thumb != null && document.thumb.location != null) {
|
||||||
document.thumb.location.ext = "webp";
|
document.thumb.location.ext = "webp";
|
||||||
|
@ -211,6 +214,7 @@ public class StickersAdapter extends RecyclerView.Adapter implements Notificatio
|
||||||
final HashMap<String, ArrayList<TLRPC.Document>> result = new HashMap<>();
|
final HashMap<String, ArrayList<TLRPC.Document>> result = new HashMap<>();
|
||||||
for (TLRPC.TL_stickerPack stickerPack : res.packs) {
|
for (TLRPC.TL_stickerPack stickerPack : res.packs) {
|
||||||
if (stickerPack != null && stickerPack.emoticon != null) {
|
if (stickerPack != null && stickerPack.emoticon != null) {
|
||||||
|
stickerPack.emoticon = stickerPack.emoticon.replace("\uFE0F", "");
|
||||||
ArrayList<TLRPC.Document> arrayList = result.get(stickerPack.emoticon);
|
ArrayList<TLRPC.Document> arrayList = result.get(stickerPack.emoticon);
|
||||||
for (Long id : stickerPack.documents) {
|
for (Long id : stickerPack.documents) {
|
||||||
TLRPC.Document document = documents.get(id);
|
TLRPC.Document document = documents.get(id);
|
||||||
|
|
|
@ -177,14 +177,14 @@ public abstract class Animator10 implements Cloneable {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static interface AnimatorListener {
|
public interface AnimatorListener {
|
||||||
void onAnimationStart(Animator10 animation);
|
void onAnimationStart(Animator10 animation);
|
||||||
void onAnimationEnd(Animator10 animation);
|
void onAnimationEnd(Animator10 animation);
|
||||||
void onAnimationCancel(Animator10 animation);
|
void onAnimationCancel(Animator10 animation);
|
||||||
void onAnimationRepeat(Animator10 animation);
|
void onAnimationRepeat(Animator10 animation);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static interface AnimatorPauseListener {
|
public interface AnimatorPauseListener {
|
||||||
void onAnimationPause(Animator10 animation);
|
void onAnimationPause(Animator10 animation);
|
||||||
void onAnimationResume(Animator10 animation);
|
void onAnimationResume(Animator10 animation);
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,10 +25,10 @@ import java.util.List;
|
||||||
|
|
||||||
public final class AnimatorSet10 extends Animator10 {
|
public final class AnimatorSet10 extends Animator10 {
|
||||||
|
|
||||||
private ArrayList<Animator10> mPlayingSet = new ArrayList<Animator10>();
|
private ArrayList<Animator10> mPlayingSet = new ArrayList<>();
|
||||||
private HashMap<Animator10, Node> mNodeMap = new HashMap<Animator10, Node>();
|
private HashMap<Animator10, Node> mNodeMap = new HashMap<>();
|
||||||
private ArrayList<Node> mNodes = new ArrayList<Node>();
|
private ArrayList<Node> mNodes = new ArrayList<>();
|
||||||
private ArrayList<Node> mSortedNodes = new ArrayList<Node>();
|
private ArrayList<Node> mSortedNodes = new ArrayList<>();
|
||||||
private boolean mNeedsSort = true;
|
private boolean mNeedsSort = true;
|
||||||
private AnimatorSetListener mSetListener = null;
|
private AnimatorSetListener mSetListener = null;
|
||||||
boolean mTerminated = false;
|
boolean mTerminated = false;
|
||||||
|
@ -89,7 +89,7 @@ public final class AnimatorSet10 extends Animator10 {
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<Animator10> getChildAnimations() {
|
public ArrayList<Animator10> getChildAnimations() {
|
||||||
ArrayList<Animator10> childList = new ArrayList<Animator10>();
|
ArrayList<Animator10> childList = new ArrayList<>();
|
||||||
for (Node node : mNodes) {
|
for (Node node : mNodes) {
|
||||||
childList.add(node.animation);
|
childList.add(node.animation);
|
||||||
}
|
}
|
||||||
|
@ -295,7 +295,7 @@ public final class AnimatorSet10 extends Animator10 {
|
||||||
ArrayList<AnimatorListener> oldListeners = node.animation.getListeners();
|
ArrayList<AnimatorListener> oldListeners = node.animation.getListeners();
|
||||||
if (oldListeners != null && oldListeners.size() > 0) {
|
if (oldListeners != null && oldListeners.size() > 0) {
|
||||||
final ArrayList<AnimatorListener> clonedListeners = new
|
final ArrayList<AnimatorListener> clonedListeners = new
|
||||||
ArrayList<AnimatorListener>(oldListeners);
|
ArrayList<>(oldListeners);
|
||||||
|
|
||||||
for (AnimatorListener listener : clonedListeners) {
|
for (AnimatorListener listener : clonedListeners) {
|
||||||
if (listener instanceof DependencyListener ||
|
if (listener instanceof DependencyListener ||
|
||||||
|
@ -306,7 +306,7 @@ public final class AnimatorSet10 extends Animator10 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final ArrayList<Node> nodesToStart = new ArrayList<Node>();
|
final ArrayList<Node> nodesToStart = new ArrayList<>();
|
||||||
for (Node node : mSortedNodes) {
|
for (Node node : mSortedNodes) {
|
||||||
if (mSetListener == null) {
|
if (mSetListener == null) {
|
||||||
mSetListener = new AnimatorSetListener(this);
|
mSetListener = new AnimatorSetListener(this);
|
||||||
|
@ -379,12 +379,12 @@ public final class AnimatorSet10 extends Animator10 {
|
||||||
anim.mNeedsSort = true;
|
anim.mNeedsSort = true;
|
||||||
anim.mTerminated = false;
|
anim.mTerminated = false;
|
||||||
anim.mStarted = false;
|
anim.mStarted = false;
|
||||||
anim.mPlayingSet = new ArrayList<Animator10>();
|
anim.mPlayingSet = new ArrayList<>();
|
||||||
anim.mNodeMap = new HashMap<Animator10, Node>();
|
anim.mNodeMap = new HashMap<>();
|
||||||
anim.mNodes = new ArrayList<Node>();
|
anim.mNodes = new ArrayList<>();
|
||||||
anim.mSortedNodes = new ArrayList<Node>();
|
anim.mSortedNodes = new ArrayList<>();
|
||||||
|
|
||||||
HashMap<Node, Node> nodeCloneMap = new HashMap<Node, Node>();
|
HashMap<Node, Node> nodeCloneMap = new HashMap<>();
|
||||||
for (Node node : mNodes) {
|
for (Node node : mNodes) {
|
||||||
Node nodeClone = node.clone();
|
Node nodeClone = node.clone();
|
||||||
nodeCloneMap.put(node, nodeClone);
|
nodeCloneMap.put(node, nodeClone);
|
||||||
|
@ -400,7 +400,7 @@ public final class AnimatorSet10 extends Animator10 {
|
||||||
for (AnimatorListener listener : cloneListeners) {
|
for (AnimatorListener listener : cloneListeners) {
|
||||||
if (listener instanceof AnimatorSetListener) {
|
if (listener instanceof AnimatorSetListener) {
|
||||||
if (listenersToRemove == null) {
|
if (listenersToRemove == null) {
|
||||||
listenersToRemove = new ArrayList<AnimatorListener>();
|
listenersToRemove = new ArrayList<>();
|
||||||
}
|
}
|
||||||
listenersToRemove.add(listener);
|
listenersToRemove.add(listener);
|
||||||
}
|
}
|
||||||
|
@ -543,14 +543,14 @@ public final class AnimatorSet10 extends Animator10 {
|
||||||
private void sortNodes() {
|
private void sortNodes() {
|
||||||
if (mNeedsSort) {
|
if (mNeedsSort) {
|
||||||
mSortedNodes.clear();
|
mSortedNodes.clear();
|
||||||
ArrayList<Node> roots = new ArrayList<Node>();
|
ArrayList<Node> roots = new ArrayList<>();
|
||||||
int numNodes = mNodes.size();
|
int numNodes = mNodes.size();
|
||||||
for (Node node : mNodes) {
|
for (Node node : mNodes) {
|
||||||
if (node.dependencies == null || node.dependencies.size() == 0) {
|
if (node.dependencies == null || node.dependencies.size() == 0) {
|
||||||
roots.add(node);
|
roots.add(node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ArrayList<Node> tmpRoots = new ArrayList<Node>();
|
ArrayList<Node> tmpRoots = new ArrayList<>();
|
||||||
while (roots.size() > 0) {
|
while (roots.size() > 0) {
|
||||||
int numRoots = roots.size();
|
int numRoots = roots.size();
|
||||||
for (Node root : roots) {
|
for (Node root : roots) {
|
||||||
|
@ -582,7 +582,7 @@ public final class AnimatorSet10 extends Animator10 {
|
||||||
for (int j = 0; j < numDependencies; ++j) {
|
for (int j = 0; j < numDependencies; ++j) {
|
||||||
Dependency dependency = node.dependencies.get(j);
|
Dependency dependency = node.dependencies.get(j);
|
||||||
if (node.nodeDependencies == null) {
|
if (node.nodeDependencies == null) {
|
||||||
node.nodeDependencies = new ArrayList<Node>();
|
node.nodeDependencies = new ArrayList<>();
|
||||||
}
|
}
|
||||||
if (!node.nodeDependencies.contains(dependency.node)) {
|
if (!node.nodeDependencies.contains(dependency.node)) {
|
||||||
node.nodeDependencies.add(dependency.node);
|
node.nodeDependencies.add(dependency.node);
|
||||||
|
@ -620,8 +620,8 @@ public final class AnimatorSet10 extends Animator10 {
|
||||||
|
|
||||||
public void addDependency(Dependency dependency) {
|
public void addDependency(Dependency dependency) {
|
||||||
if (dependencies == null) {
|
if (dependencies == null) {
|
||||||
dependencies = new ArrayList<Dependency>();
|
dependencies = new ArrayList<>();
|
||||||
nodeDependencies = new ArrayList<Node>();
|
nodeDependencies = new ArrayList<>();
|
||||||
}
|
}
|
||||||
dependencies.add(dependency);
|
dependencies.add(dependency);
|
||||||
if (!nodeDependencies.contains(dependency.node)) {
|
if (!nodeDependencies.contains(dependency.node)) {
|
||||||
|
@ -629,7 +629,7 @@ public final class AnimatorSet10 extends Animator10 {
|
||||||
}
|
}
|
||||||
Node dependencyNode = dependency.node;
|
Node dependencyNode = dependency.node;
|
||||||
if (dependencyNode.nodeDependents == null) {
|
if (dependencyNode.nodeDependents == null) {
|
||||||
dependencyNode.nodeDependents = new ArrayList<Node>();
|
dependencyNode.nodeDependents = new ArrayList<>();
|
||||||
}
|
}
|
||||||
dependencyNode.nodeDependents.add(this);
|
dependencyNode.nodeDependents.add(this);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,5 +17,5 @@
|
||||||
package org.telegram.ui.Animation;
|
package org.telegram.ui.Animation;
|
||||||
|
|
||||||
public interface TypeEvaluator<T> {
|
public interface TypeEvaluator<T> {
|
||||||
public T evaluate(float fraction, T startValue, T endValue);
|
T evaluate(float fraction, T startValue, T endValue);
|
||||||
}
|
}
|
||||||
|
|
|
@ -646,7 +646,7 @@ public class ValueAnimator extends Animator10 {
|
||||||
return anim;
|
return anim;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static interface AnimatorUpdateListener {
|
public interface AnimatorUpdateListener {
|
||||||
void onAnimationUpdate(ValueAnimator animation);
|
void onAnimationUpdate(ValueAnimator animation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ public class View10 extends Animation {
|
||||||
|
|
||||||
public static boolean NEED_PROXY = Build.VERSION.SDK_INT < 11;
|
public static boolean NEED_PROXY = Build.VERSION.SDK_INT < 11;
|
||||||
|
|
||||||
private static final WeakHashMap<View, View10> PROXIES = new WeakHashMap<View, View10>();
|
private static final WeakHashMap<View, View10> PROXIES = new WeakHashMap<>();
|
||||||
|
|
||||||
public static View10 wrap(View view) {
|
public static View10 wrap(View view) {
|
||||||
View10 proxy = PROXIES.get(view);
|
View10 proxy = PROXIES.get(view);
|
||||||
|
@ -68,7 +68,7 @@ public class View10 extends Animation {
|
||||||
setDuration(0);
|
setDuration(0);
|
||||||
setFillAfter(true);
|
setFillAfter(true);
|
||||||
view.setAnimation(this);
|
view.setAnimation(this);
|
||||||
mView = new WeakReference<View>(view);
|
mView = new WeakReference<>(view);
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getAlpha() {
|
public float getAlpha() {
|
||||||
|
|
|
@ -64,131 +64,124 @@ public class BlockedUsersActivity extends BaseFragment implements NotificationCe
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View createView(LayoutInflater inflater, ViewGroup container) {
|
public View createView(Context context, LayoutInflater inflater) {
|
||||||
if (fragmentView == null) {
|
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
|
||||||
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
|
actionBar.setAllowOverlayTitle(true);
|
||||||
actionBar.setAllowOverlayTitle(true);
|
actionBar.setTitle(LocaleController.getString("BlockedUsers", R.string.BlockedUsers));
|
||||||
actionBar.setTitle(LocaleController.getString("BlockedUsers", R.string.BlockedUsers));
|
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
|
||||||
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
|
@Override
|
||||||
@Override
|
public void onItemClick(int id) {
|
||||||
public void onItemClick(int id) {
|
if (id == -1) {
|
||||||
if (id == -1) {
|
finishFragment();
|
||||||
finishFragment();
|
} else if (id == block_user) {
|
||||||
} else if (id == block_user) {
|
Bundle args = new Bundle();
|
||||||
Bundle args = new Bundle();
|
args.putBoolean("onlyUsers", true);
|
||||||
args.putBoolean("onlyUsers", true);
|
args.putBoolean("destroyAfterSelect", true);
|
||||||
args.putBoolean("destroyAfterSelect", true);
|
args.putBoolean("returnAsResult", true);
|
||||||
args.putBoolean("returnAsResult", true);
|
ContactsActivity fragment = new ContactsActivity(args);
|
||||||
ContactsActivity fragment = new ContactsActivity(args);
|
fragment.setDelegate(BlockedUsersActivity.this);
|
||||||
fragment.setDelegate(BlockedUsersActivity.this);
|
presentFragment(fragment);
|
||||||
presentFragment(fragment);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
|
||||||
ActionBarMenu menu = actionBar.createMenu();
|
ActionBarMenu menu = actionBar.createMenu();
|
||||||
menu.addItem(block_user, R.drawable.plus);
|
menu.addItem(block_user, R.drawable.plus);
|
||||||
|
|
||||||
fragmentView = new FrameLayout(getParentActivity());
|
fragmentView = new FrameLayout(context);
|
||||||
FrameLayout frameLayout = (FrameLayout) fragmentView;
|
FrameLayout frameLayout = (FrameLayout) fragmentView;
|
||||||
|
|
||||||
emptyTextView = new TextView(getParentActivity());
|
emptyTextView = new TextView(context);
|
||||||
emptyTextView.setTextColor(0xff808080);
|
emptyTextView.setTextColor(0xff808080);
|
||||||
emptyTextView.setTextSize(20);
|
emptyTextView.setTextSize(20);
|
||||||
emptyTextView.setGravity(Gravity.CENTER);
|
emptyTextView.setGravity(Gravity.CENTER);
|
||||||
emptyTextView.setVisibility(View.INVISIBLE);
|
emptyTextView.setVisibility(View.INVISIBLE);
|
||||||
emptyTextView.setText(LocaleController.getString("NoBlocked", R.string.NoBlocked));
|
emptyTextView.setText(LocaleController.getString("NoBlocked", R.string.NoBlocked));
|
||||||
frameLayout.addView(emptyTextView);
|
frameLayout.addView(emptyTextView);
|
||||||
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) emptyTextView.getLayoutParams();
|
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) emptyTextView.getLayoutParams();
|
||||||
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
|
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
|
||||||
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
|
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
|
||||||
layoutParams.gravity = Gravity.TOP;
|
layoutParams.gravity = Gravity.TOP;
|
||||||
emptyTextView.setLayoutParams(layoutParams);
|
emptyTextView.setLayoutParams(layoutParams);
|
||||||
emptyTextView.setOnTouchListener(new View.OnTouchListener() {
|
emptyTextView.setOnTouchListener(new View.OnTouchListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onTouch(View v, MotionEvent event) {
|
public boolean onTouch(View v, MotionEvent event) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
progressView = new FrameLayout(context);
|
||||||
|
frameLayout.addView(progressView);
|
||||||
|
layoutParams = (FrameLayout.LayoutParams) progressView.getLayoutParams();
|
||||||
|
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
|
||||||
|
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
|
||||||
|
progressView.setLayoutParams(layoutParams);
|
||||||
|
|
||||||
|
ProgressBar progressBar = new ProgressBar(context);
|
||||||
|
progressView.addView(progressBar);
|
||||||
|
layoutParams = (FrameLayout.LayoutParams) progressView.getLayoutParams();
|
||||||
|
layoutParams.width = FrameLayout.LayoutParams.WRAP_CONTENT;
|
||||||
|
layoutParams.height = FrameLayout.LayoutParams.WRAP_CONTENT;
|
||||||
|
layoutParams.gravity = Gravity.CENTER;
|
||||||
|
progressView.setLayoutParams(layoutParams);
|
||||||
|
|
||||||
|
listView = new ListView(context);
|
||||||
|
listView.setEmptyView(emptyTextView);
|
||||||
|
listView.setVerticalScrollBarEnabled(false);
|
||||||
|
listView.setDivider(null);
|
||||||
|
listView.setDividerHeight(0);
|
||||||
|
listView.setAdapter(listViewAdapter = new ListAdapter(context));
|
||||||
|
if (Build.VERSION.SDK_INT >= 11) {
|
||||||
|
listView.setVerticalScrollbarPosition(LocaleController.isRTL ? ListView.SCROLLBAR_POSITION_LEFT : ListView.SCROLLBAR_POSITION_RIGHT);
|
||||||
|
}
|
||||||
|
frameLayout.addView(listView);
|
||||||
|
layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
|
||||||
|
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
|
||||||
|
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
|
||||||
|
listView.setLayoutParams(layoutParams);
|
||||||
|
|
||||||
|
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
|
||||||
|
if (i < MessagesController.getInstance().blockedUsers.size()) {
|
||||||
|
Bundle args = new Bundle();
|
||||||
|
args.putInt("user_id", MessagesController.getInstance().blockedUsers.get(i));
|
||||||
|
presentFragment(new ProfileActivity(args));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
|
||||||
|
if (i < 0 || i >= MessagesController.getInstance().blockedUsers.size() || getParentActivity() == null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
selectedUserId = MessagesController.getInstance().blockedUsers.get(i);
|
||||||
|
|
||||||
progressView = new FrameLayout(getParentActivity());
|
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
||||||
frameLayout.addView(progressView);
|
CharSequence[] items = new CharSequence[]{LocaleController.getString("Unblock", R.string.Unblock)};
|
||||||
layoutParams = (FrameLayout.LayoutParams) progressView.getLayoutParams();
|
builder.setItems(items, new DialogInterface.OnClickListener() {
|
||||||
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
|
@Override
|
||||||
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
|
public void onClick(DialogInterface dialogInterface, int i) {
|
||||||
progressView.setLayoutParams(layoutParams);
|
if (i == 0) {
|
||||||
|
MessagesController.getInstance().unblockUser(selectedUserId);
|
||||||
ProgressBar progressBar = new ProgressBar(getParentActivity());
|
|
||||||
progressView.addView(progressBar);
|
|
||||||
layoutParams = (FrameLayout.LayoutParams) progressView.getLayoutParams();
|
|
||||||
layoutParams.width = FrameLayout.LayoutParams.WRAP_CONTENT;
|
|
||||||
layoutParams.height = FrameLayout.LayoutParams.WRAP_CONTENT;
|
|
||||||
layoutParams.gravity = Gravity.CENTER;
|
|
||||||
progressView.setLayoutParams(layoutParams);
|
|
||||||
|
|
||||||
listView = new ListView(getParentActivity());
|
|
||||||
listView.setEmptyView(emptyTextView);
|
|
||||||
listView.setVerticalScrollBarEnabled(false);
|
|
||||||
listView.setDivider(null);
|
|
||||||
listView.setDividerHeight(0);
|
|
||||||
listView.setAdapter(listViewAdapter = new ListAdapter(getParentActivity()));
|
|
||||||
if (Build.VERSION.SDK_INT >= 11) {
|
|
||||||
listView.setVerticalScrollbarPosition(LocaleController.isRTL ? ListView.SCROLLBAR_POSITION_LEFT : ListView.SCROLLBAR_POSITION_RIGHT);
|
|
||||||
}
|
|
||||||
frameLayout.addView(listView);
|
|
||||||
layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
|
|
||||||
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
|
|
||||||
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
|
|
||||||
listView.setLayoutParams(layoutParams);
|
|
||||||
|
|
||||||
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
|
|
||||||
if (i < MessagesController.getInstance().blockedUsers.size()) {
|
|
||||||
Bundle args = new Bundle();
|
|
||||||
args.putInt("user_id", MessagesController.getInstance().blockedUsers.get(i));
|
|
||||||
presentFragment(new ProfileActivity(args));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
|
|
||||||
@Override
|
|
||||||
public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
|
|
||||||
if (i < 0 || i >= MessagesController.getInstance().blockedUsers.size() || getParentActivity() == null) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
selectedUserId = MessagesController.getInstance().blockedUsers.get(i);
|
|
||||||
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
|
||||||
CharSequence[] items = new CharSequence[] {LocaleController.getString("Unblock", R.string.Unblock)};
|
|
||||||
builder.setItems(items, new DialogInterface.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialogInterface, int i) {
|
|
||||||
if (i == 0) {
|
|
||||||
MessagesController.getInstance().unblockUser(selectedUserId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
showAlertDialog(builder);
|
});
|
||||||
|
showAlertDialog(builder);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (MessagesController.getInstance().loadingBlockedUsers) {
|
|
||||||
progressView.setVisibility(View.VISIBLE);
|
|
||||||
emptyTextView.setVisibility(View.GONE);
|
|
||||||
listView.setEmptyView(null);
|
|
||||||
} else {
|
|
||||||
progressView.setVisibility(View.GONE);
|
|
||||||
listView.setEmptyView(emptyTextView);
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (MessagesController.getInstance().loadingBlockedUsers) {
|
||||||
|
progressView.setVisibility(View.VISIBLE);
|
||||||
|
emptyTextView.setVisibility(View.GONE);
|
||||||
|
listView.setEmptyView(null);
|
||||||
} else {
|
} else {
|
||||||
ViewGroup parent = (ViewGroup)fragmentView.getParent();
|
progressView.setVisibility(View.GONE);
|
||||||
if (parent != null) {
|
listView.setEmptyView(emptyTextView);
|
||||||
parent.removeView(fragmentView);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return fragmentView;
|
return fragmentView;
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@ import org.telegram.android.AndroidUtilities;
|
||||||
import org.telegram.android.ImageReceiver;
|
import org.telegram.android.ImageReceiver;
|
||||||
import org.telegram.android.MessageObject;
|
import org.telegram.android.MessageObject;
|
||||||
import org.telegram.android.MessagesController;
|
import org.telegram.android.MessagesController;
|
||||||
|
import org.telegram.messenger.ApplicationLoader;
|
||||||
import org.telegram.messenger.FileLoader;
|
import org.telegram.messenger.FileLoader;
|
||||||
import org.telegram.messenger.FileLog;
|
import org.telegram.messenger.FileLog;
|
||||||
import org.telegram.messenger.R;
|
import org.telegram.messenger.R;
|
||||||
|
@ -35,10 +36,10 @@ import org.telegram.ui.Components.AvatarDrawable;
|
||||||
|
|
||||||
public class ChatActionCell extends BaseCell {
|
public class ChatActionCell extends BaseCell {
|
||||||
|
|
||||||
public static interface ChatActionCellDelegate {
|
public interface ChatActionCellDelegate {
|
||||||
public abstract void didClickedImage(ChatActionCell cell);
|
void didClickedImage(ChatActionCell cell);
|
||||||
public abstract void didLongPressed(ChatActionCell cell);
|
void didLongPressed(ChatActionCell cell);
|
||||||
public abstract void needOpenUserProfile(int uid);
|
void needOpenUserProfile(int uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Drawable backgroundBlack;
|
private static Drawable backgroundBlack;
|
||||||
|
@ -55,7 +56,6 @@ public class ChatActionCell extends BaseCell {
|
||||||
private int textX = 0;
|
private int textX = 0;
|
||||||
private int textY = 0;
|
private int textY = 0;
|
||||||
private int textXLeft = 0;
|
private int textXLeft = 0;
|
||||||
private boolean useBlackBackground = false;
|
|
||||||
private int previousWidth = 0;
|
private int previousWidth = 0;
|
||||||
private boolean imagePressed = false;
|
private boolean imagePressed = false;
|
||||||
|
|
||||||
|
@ -119,10 +119,6 @@ public class ChatActionCell extends BaseCell {
|
||||||
requestLayout();
|
requestLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUseBlackBackground(boolean value) {
|
|
||||||
useBlackBackground = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MessageObject getMessageObject() {
|
public MessageObject getMessageObject() {
|
||||||
return currentMessageObject;
|
return currentMessageObject;
|
||||||
}
|
}
|
||||||
|
@ -267,7 +263,7 @@ public class ChatActionCell extends BaseCell {
|
||||||
}
|
}
|
||||||
|
|
||||||
Drawable backgroundDrawable = null;
|
Drawable backgroundDrawable = null;
|
||||||
if (useBlackBackground) {
|
if (ApplicationLoader.isCustomTheme()) {
|
||||||
backgroundDrawable = backgroundBlack;
|
backgroundDrawable = backgroundBlack;
|
||||||
} else {
|
} else {
|
||||||
backgroundDrawable = backgroundBlue;
|
backgroundDrawable = backgroundBlue;
|
||||||
|
|
|
@ -183,9 +183,15 @@ public class ChatAudioCell extends ChatBaseCell implements SeekBar.SeekBarDelega
|
||||||
buttonState = 3;
|
buttonState = 3;
|
||||||
invalidate();
|
invalidate();
|
||||||
} else if (buttonState == 3) {
|
} else if (buttonState == 3) {
|
||||||
FileLoader.getInstance().cancelLoadFile(currentMessageObject.messageOwner.media.audio);
|
if (currentMessageObject.isOut() && currentMessageObject.isSending()) {
|
||||||
buttonState = 2;
|
if (delegate != null) {
|
||||||
invalidate();
|
delegate.didPressedCancelSendButton(this);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
FileLoader.getInstance().cancelLoadFile(currentMessageObject.messageOwner.media.audio);
|
||||||
|
buttonState = 2;
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -291,12 +297,7 @@ public class ChatAudioCell extends ChatBaseCell implements SeekBar.SeekBarDelega
|
||||||
@Override
|
@Override
|
||||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||||
int width = MeasureSpec.getSize(widthMeasureSpec);
|
int width = MeasureSpec.getSize(widthMeasureSpec);
|
||||||
setMeasuredDimension(width, AndroidUtilities.dp(68));
|
setMeasuredDimension(width, AndroidUtilities.dp(68) + namesOffset);
|
||||||
if (isChat) {
|
|
||||||
backgroundWidth = Math.min(width - AndroidUtilities.dp(102), AndroidUtilities.dp(300));
|
|
||||||
} else {
|
|
||||||
backgroundWidth = Math.min(width - AndroidUtilities.dp(50), AndroidUtilities.dp(300));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -325,7 +326,7 @@ public class ChatAudioCell extends ChatBaseCell implements SeekBar.SeekBarDelega
|
||||||
}
|
}
|
||||||
int diff = 0;
|
int diff = 0;
|
||||||
if (needAvatarImage) {
|
if (needAvatarImage) {
|
||||||
avatarImage.setImageCoords(x, AndroidUtilities.dp(9), AndroidUtilities.dp(50), AndroidUtilities.dp(50));
|
avatarImage.setImageCoords(x, AndroidUtilities.dp(9) + namesOffset, AndroidUtilities.dp(50), AndroidUtilities.dp(50));
|
||||||
} else {
|
} else {
|
||||||
diff = AndroidUtilities.dp(56);
|
diff = AndroidUtilities.dp(56);
|
||||||
seekBarX -= diff;
|
seekBarX -= diff;
|
||||||
|
@ -337,8 +338,8 @@ public class ChatAudioCell extends ChatBaseCell implements SeekBar.SeekBarDelega
|
||||||
seekBar.height = AndroidUtilities.dp(30);
|
seekBar.height = AndroidUtilities.dp(30);
|
||||||
progressView.width = backgroundWidth - AndroidUtilities.dp(136) + diff;
|
progressView.width = backgroundWidth - AndroidUtilities.dp(136) + diff;
|
||||||
progressView.height = AndroidUtilities.dp(30);
|
progressView.height = AndroidUtilities.dp(30);
|
||||||
seekBarY = AndroidUtilities.dp(13);
|
seekBarY = AndroidUtilities.dp(13) + namesOffset;
|
||||||
buttonY = AndroidUtilities.dp(10);
|
buttonY = AndroidUtilities.dp(10) + namesOffset;
|
||||||
|
|
||||||
updateProgress();
|
updateProgress();
|
||||||
}
|
}
|
||||||
|
@ -358,6 +359,12 @@ public class ChatAudioCell extends ChatBaseCell implements SeekBar.SeekBarDelega
|
||||||
@Override
|
@Override
|
||||||
public void setMessageObject(MessageObject messageObject) {
|
public void setMessageObject(MessageObject messageObject) {
|
||||||
if (currentMessageObject != messageObject || isUserDataChanged()) {
|
if (currentMessageObject != messageObject || isUserDataChanged()) {
|
||||||
|
if (AndroidUtilities.isTablet()) {
|
||||||
|
backgroundWidth = Math.min(AndroidUtilities.getMinTabletSide() - AndroidUtilities.dp(isChat ? 102 : 50), AndroidUtilities.dp(300));
|
||||||
|
} else {
|
||||||
|
backgroundWidth = Math.min(AndroidUtilities.displaySize.x - AndroidUtilities.dp(isChat ? 102 : 50), AndroidUtilities.dp(300));
|
||||||
|
}
|
||||||
|
|
||||||
int uid = messageObject.messageOwner.media.audio.user_id;
|
int uid = messageObject.messageOwner.media.audio.user_id;
|
||||||
if (uid == 0) {
|
if (uid == 0) {
|
||||||
uid = messageObject.messageOwner.from_id;
|
uid = messageObject.messageOwner.from_id;
|
||||||
|
@ -430,7 +437,7 @@ public class ChatAudioCell extends ChatBaseCell implements SeekBar.SeekBarDelega
|
||||||
buttonDrawable.draw(canvas);
|
buttonDrawable.draw(canvas);
|
||||||
|
|
||||||
canvas.save();
|
canvas.save();
|
||||||
canvas.translate(timeX, AndroidUtilities.dp(45));
|
canvas.translate(timeX, AndroidUtilities.dp(45) + namesOffset);
|
||||||
timeLayout.draw(canvas);
|
timeLayout.draw(canvas);
|
||||||
canvas.restore();
|
canvas.restore();
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,9 +10,10 @@ package org.telegram.ui.Cells;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.res.Configuration;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
|
import android.graphics.Paint;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.text.Html;
|
|
||||||
import android.text.Layout;
|
import android.text.Layout;
|
||||||
import android.text.StaticLayout;
|
import android.text.StaticLayout;
|
||||||
import android.text.TextPaint;
|
import android.text.TextPaint;
|
||||||
|
@ -22,7 +23,11 @@ import android.view.SoundEffectConstants;
|
||||||
|
|
||||||
import org.telegram.android.AndroidUtilities;
|
import org.telegram.android.AndroidUtilities;
|
||||||
import org.telegram.android.ContactsController;
|
import org.telegram.android.ContactsController;
|
||||||
|
import org.telegram.android.Emoji;
|
||||||
import org.telegram.android.LocaleController;
|
import org.telegram.android.LocaleController;
|
||||||
|
import org.telegram.messenger.ApplicationLoader;
|
||||||
|
import org.telegram.messenger.FileLoader;
|
||||||
|
import org.telegram.messenger.FileLog;
|
||||||
import org.telegram.messenger.TLRPC;
|
import org.telegram.messenger.TLRPC;
|
||||||
import org.telegram.android.MessagesController;
|
import org.telegram.android.MessagesController;
|
||||||
import org.telegram.messenger.R;
|
import org.telegram.messenger.R;
|
||||||
|
@ -32,16 +37,19 @@ import org.telegram.ui.Components.AvatarDrawable;
|
||||||
|
|
||||||
public class ChatBaseCell extends BaseCell {
|
public class ChatBaseCell extends BaseCell {
|
||||||
|
|
||||||
public static interface ChatBaseCellDelegate {
|
public interface ChatBaseCellDelegate {
|
||||||
public abstract void didPressedUserAvatar(ChatBaseCell cell, TLRPC.User user);
|
void didPressedUserAvatar(ChatBaseCell cell, TLRPC.User user);
|
||||||
public abstract void didPressedCancelSendButton(ChatBaseCell cell);
|
void didPressedCancelSendButton(ChatBaseCell cell);
|
||||||
public abstract void didLongPressed(ChatBaseCell cell);
|
void didLongPressed(ChatBaseCell cell);
|
||||||
public abstract boolean canPerformActions();
|
void didPressReplyMessage(ChatBaseCell cell, int id);
|
||||||
|
void didPressUrl(String url);
|
||||||
|
boolean canPerformActions();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isChat = false;
|
public boolean isChat = false;
|
||||||
protected boolean isPressed = false;
|
protected boolean isPressed = false;
|
||||||
protected boolean forwardName = false;
|
protected boolean forwardName = false;
|
||||||
|
protected boolean isHighlighted = false;
|
||||||
protected boolean media = false;
|
protected boolean media = false;
|
||||||
protected boolean isCheckPressed = true;
|
protected boolean isCheckPressed = true;
|
||||||
private boolean wasLayout = false;
|
private boolean wasLayout = false;
|
||||||
|
@ -66,12 +74,17 @@ public class ChatBaseCell extends BaseCell {
|
||||||
private static Drawable clockMediaDrawable;
|
private static Drawable clockMediaDrawable;
|
||||||
private static Drawable broadcastMediaDrawable;
|
private static Drawable broadcastMediaDrawable;
|
||||||
private static Drawable errorDrawable;
|
private static Drawable errorDrawable;
|
||||||
|
private static Drawable backgroundBlack;
|
||||||
|
private static Drawable backgroundBlue;
|
||||||
protected static Drawable mediaBackgroundDrawable;
|
protected static Drawable mediaBackgroundDrawable;
|
||||||
private static TextPaint timePaintIn;
|
private static TextPaint timePaintIn;
|
||||||
private static TextPaint timePaintOut;
|
private static TextPaint timePaintOut;
|
||||||
private static TextPaint timeMediaPaint;
|
private static TextPaint timeMediaPaint;
|
||||||
private static TextPaint namePaint;
|
private static TextPaint namePaint;
|
||||||
private static TextPaint forwardNamePaint;
|
private static TextPaint forwardNamePaint;
|
||||||
|
protected static TextPaint replyNamePaint;
|
||||||
|
protected static TextPaint replyTextPaint;
|
||||||
|
protected static Paint replyLinePaint;
|
||||||
|
|
||||||
protected int backgroundWidth = 100;
|
protected int backgroundWidth = 100;
|
||||||
|
|
||||||
|
@ -83,6 +96,19 @@ public class ChatBaseCell extends BaseCell {
|
||||||
private boolean avatarPressed = false;
|
private boolean avatarPressed = false;
|
||||||
private boolean forwardNamePressed = false;
|
private boolean forwardNamePressed = false;
|
||||||
|
|
||||||
|
private StaticLayout replyNameLayout;
|
||||||
|
private StaticLayout replyTextLayout;
|
||||||
|
private ImageReceiver replyImageReceiver;
|
||||||
|
private int replyStartX;
|
||||||
|
private int replyStartY;
|
||||||
|
protected int replyNameWidth;
|
||||||
|
private float replyNameOffset;
|
||||||
|
protected int replyTextWidth;
|
||||||
|
private float replyTextOffset;
|
||||||
|
private boolean needReplyImage = false;
|
||||||
|
private boolean replyPressed = false;
|
||||||
|
private TLRPC.FileLocation currentReplyPhoto;
|
||||||
|
|
||||||
private StaticLayout nameLayout;
|
private StaticLayout nameLayout;
|
||||||
protected int nameWidth;
|
protected int nameWidth;
|
||||||
private float nameOffsetX = 0;
|
private float nameOffsetX = 0;
|
||||||
|
@ -137,6 +163,8 @@ public class ChatBaseCell extends BaseCell {
|
||||||
mediaBackgroundDrawable = getResources().getDrawable(R.drawable.phototime);
|
mediaBackgroundDrawable = getResources().getDrawable(R.drawable.phototime);
|
||||||
broadcastDrawable = getResources().getDrawable(R.drawable.broadcast3);
|
broadcastDrawable = getResources().getDrawable(R.drawable.broadcast3);
|
||||||
broadcastMediaDrawable = getResources().getDrawable(R.drawable.broadcast4);
|
broadcastMediaDrawable = getResources().getDrawable(R.drawable.broadcast4);
|
||||||
|
backgroundBlack = getResources().getDrawable(R.drawable.system_black);
|
||||||
|
backgroundBlue = getResources().getDrawable(R.drawable.system_blue);
|
||||||
|
|
||||||
timePaintIn = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
|
timePaintIn = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
|
||||||
timePaintIn.setTextSize(AndroidUtilities.dp(12));
|
timePaintIn.setTextSize(AndroidUtilities.dp(12));
|
||||||
|
@ -155,17 +183,30 @@ public class ChatBaseCell extends BaseCell {
|
||||||
|
|
||||||
forwardNamePaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
|
forwardNamePaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
|
||||||
forwardNamePaint.setTextSize(AndroidUtilities.dp(14));
|
forwardNamePaint.setTextSize(AndroidUtilities.dp(14));
|
||||||
|
|
||||||
|
replyNamePaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
|
||||||
|
replyNamePaint.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
|
||||||
|
replyNamePaint.setTextSize(AndroidUtilities.dp(14));
|
||||||
|
|
||||||
|
replyTextPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
|
||||||
|
replyTextPaint.setTextSize(AndroidUtilities.dp(14));
|
||||||
|
replyTextPaint.linkColor = 0xff316f9f;
|
||||||
|
|
||||||
|
replyLinePaint = new Paint();
|
||||||
}
|
}
|
||||||
avatarImage = new ImageReceiver(this);
|
avatarImage = new ImageReceiver(this);
|
||||||
avatarImage.setRoundRadius(AndroidUtilities.dp(21));
|
avatarImage.setRoundRadius(AndroidUtilities.dp(21));
|
||||||
avatarDrawable = new AvatarDrawable();
|
avatarDrawable = new AvatarDrawable();
|
||||||
|
replyImageReceiver = new ImageReceiver(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDetachedFromWindow() {
|
protected void onDetachedFromWindow() {
|
||||||
super.onDetachedFromWindow();
|
super.onDetachedFromWindow();
|
||||||
avatarImage.clearImage();
|
avatarImage.clearImage();
|
||||||
|
replyImageReceiver.clearImage();
|
||||||
currentPhoto = null;
|
currentPhoto = null;
|
||||||
|
currentReplyPhoto = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -178,6 +219,14 @@ public class ChatBaseCell extends BaseCell {
|
||||||
this.delegate = delegate;
|
this.delegate = delegate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setHighlighted(boolean value) {
|
||||||
|
if (isHighlighted == value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
isHighlighted = value;
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
public void setCheckPressed(boolean value, boolean pressed) {
|
public void setCheckPressed(boolean value, boolean pressed) {
|
||||||
isCheckPressed = value;
|
isCheckPressed = value;
|
||||||
isPressed = pressed;
|
isPressed = pressed;
|
||||||
|
@ -202,10 +251,27 @@ public class ChatBaseCell extends BaseCell {
|
||||||
newPhoto = newUser.photo.photo_small;
|
newPhoto = newUser.photo.photo_small;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (replyTextLayout == null && currentMessageObject.replyMessageObject != null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (currentPhoto == null && newPhoto != null || currentPhoto != null && newPhoto == null || currentPhoto != null && newPhoto != null && (currentPhoto.local_id != newPhoto.local_id || currentPhoto.volume_id != newPhoto.volume_id)) {
|
if (currentPhoto == null && newPhoto != null || currentPhoto != null && newPhoto == null || currentPhoto != null && newPhoto != null && (currentPhoto.local_id != newPhoto.local_id || currentPhoto.volume_id != newPhoto.volume_id)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TLRPC.FileLocation newReplyPhoto = null;
|
||||||
|
|
||||||
|
if (currentMessageObject.replyMessageObject != null) {
|
||||||
|
TLRPC.PhotoSize photoSize = FileLoader.getClosestPhotoSizeWithSize(currentMessageObject.replyMessageObject.photoThumbs, 80);
|
||||||
|
if (photoSize != null && currentMessageObject.replyMessageObject.type != 13) {
|
||||||
|
newReplyPhoto = photoSize.location;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentReplyPhoto == null && newReplyPhoto != null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
String newNameString = null;
|
String newNameString = null;
|
||||||
if (drawName && isChat && newUser != null && !currentMessageObject.isOut()) {
|
if (drawName && isChat && newUser != null && !currentMessageObject.isOut()) {
|
||||||
newNameString = ContactsController.formatName(newUser.first_name, newUser.last_name);
|
newNameString = ContactsController.formatName(newUser.first_name, newUser.last_name);
|
||||||
|
@ -217,7 +283,7 @@ public class ChatBaseCell extends BaseCell {
|
||||||
|
|
||||||
newUser = MessagesController.getInstance().getUser(currentMessageObject.messageOwner.fwd_from_id);
|
newUser = MessagesController.getInstance().getUser(currentMessageObject.messageOwner.fwd_from_id);
|
||||||
newNameString = null;
|
newNameString = null;
|
||||||
if (newUser != null && drawForwardedName && currentMessageObject.messageOwner instanceof TLRPC.TL_messageForwarded) {
|
if (newUser != null && drawForwardedName && currentMessageObject.messageOwner.fwd_from_id != 0) {
|
||||||
newNameString = ContactsController.formatName(newUser.first_name, newUser.last_name);
|
newNameString = ContactsController.formatName(newUser.first_name, newUser.last_name);
|
||||||
}
|
}
|
||||||
return currentForwardNameString == null && newNameString != null || currentForwardNameString != null && newNameString == null || currentForwardNameString != null && newNameString != null && !currentForwardNameString.equals(newNameString);
|
return currentForwardNameString == null && newNameString != null || currentForwardNameString != null && newNameString == null || currentForwardNameString != null && newNameString != null && !currentForwardNameString.equals(newNameString);
|
||||||
|
@ -231,6 +297,11 @@ public class ChatBaseCell extends BaseCell {
|
||||||
isCheckPressed = true;
|
isCheckPressed = true;
|
||||||
isAvatarVisible = false;
|
isAvatarVisible = false;
|
||||||
wasLayout = false;
|
wasLayout = false;
|
||||||
|
replyNameLayout = null;
|
||||||
|
replyTextLayout = null;
|
||||||
|
replyNameWidth = 0;
|
||||||
|
replyTextWidth = 0;
|
||||||
|
currentReplyPhoto = null;
|
||||||
|
|
||||||
currentUser = MessagesController.getInstance().getUser(messageObject.messageOwner.from_id);
|
currentUser = MessagesController.getInstance().getUser(messageObject.messageOwner.from_id);
|
||||||
if (isChat && !messageObject.isOut()) {
|
if (isChat && !messageObject.isOut()) {
|
||||||
|
@ -272,7 +343,7 @@ public class ChatBaseCell extends BaseCell {
|
||||||
nameLayout = new StaticLayout(nameStringFinal, namePaint, nameWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
|
nameLayout = new StaticLayout(nameStringFinal, namePaint, nameWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
|
||||||
if (nameLayout.getLineCount() > 0) {
|
if (nameLayout.getLineCount() > 0) {
|
||||||
nameWidth = (int)Math.ceil(nameLayout.getLineWidth(0));
|
nameWidth = (int)Math.ceil(nameLayout.getLineWidth(0));
|
||||||
namesOffset += AndroidUtilities.dp(18);
|
namesOffset += AndroidUtilities.dp(19);
|
||||||
nameOffsetX = nameLayout.getLineLeft(0);
|
nameOffsetX = nameLayout.getLineLeft(0);
|
||||||
} else {
|
} else {
|
||||||
nameWidth = 0;
|
nameWidth = 0;
|
||||||
|
@ -283,7 +354,7 @@ public class ChatBaseCell extends BaseCell {
|
||||||
nameWidth = 0;
|
nameWidth = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (drawForwardedName && messageObject.messageOwner instanceof TLRPC.TL_messageForwarded) {
|
if (drawForwardedName && messageObject.isForwarded()) {
|
||||||
currentForwardUser = MessagesController.getInstance().getUser(messageObject.messageOwner.fwd_from_id);
|
currentForwardUser = MessagesController.getInstance().getUser(messageObject.messageOwner.fwd_from_id);
|
||||||
if (currentForwardUser != null) {
|
if (currentForwardUser != null) {
|
||||||
currentForwardNameString = ContactsController.formatName(currentForwardUser.first_name, currentForwardUser.last_name);
|
currentForwardNameString = ContactsController.formatName(currentForwardUser.first_name, currentForwardUser.last_name);
|
||||||
|
@ -291,7 +362,7 @@ public class ChatBaseCell extends BaseCell {
|
||||||
forwardedNameWidth = getMaxNameWidth();
|
forwardedNameWidth = getMaxNameWidth();
|
||||||
|
|
||||||
CharSequence str = TextUtils.ellipsize(currentForwardNameString.replace("\n", " "), forwardNamePaint, forwardedNameWidth - AndroidUtilities.dp(40), TextUtils.TruncateAt.END);
|
CharSequence str = TextUtils.ellipsize(currentForwardNameString.replace("\n", " "), forwardNamePaint, forwardedNameWidth - AndroidUtilities.dp(40), TextUtils.TruncateAt.END);
|
||||||
str = Html.fromHtml(String.format("%s<br>%s <b>%s</b>", LocaleController.getString("ForwardedMessage", R.string.ForwardedMessage), LocaleController.getString("From", R.string.From), str));
|
str = AndroidUtilities.replaceTags(String.format("%s\n%s <b>%s</b>", LocaleController.getString("ForwardedMessage", R.string.ForwardedMessage), LocaleController.getString("From", R.string.From), str));
|
||||||
forwardedNameLayout = new StaticLayout(str, forwardNamePaint, forwardedNameWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
|
forwardedNameLayout = new StaticLayout(str, forwardNamePaint, forwardedNameWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
|
||||||
if (forwardedNameLayout.getLineCount() > 1) {
|
if (forwardedNameLayout.getLineCount() > 1) {
|
||||||
forwardedNameWidth = Math.max((int) Math.ceil(forwardedNameLayout.getLineWidth(0)), (int) Math.ceil(forwardedNameLayout.getLineWidth(1)));
|
forwardedNameWidth = Math.max((int) Math.ceil(forwardedNameLayout.getLineWidth(0)), (int) Math.ceil(forwardedNameLayout.getLineWidth(1)));
|
||||||
|
@ -311,6 +382,99 @@ public class ChatBaseCell extends BaseCell {
|
||||||
forwardedNameWidth = 0;
|
forwardedNameWidth = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (messageObject.isReply()) {
|
||||||
|
namesOffset += AndroidUtilities.dp(42);
|
||||||
|
if (messageObject.contentType == 2 || messageObject.contentType == 3) {
|
||||||
|
namesOffset += AndroidUtilities.dp(4);
|
||||||
|
} else if (messageObject.contentType == 1) {
|
||||||
|
if (messageObject.type == 13) {
|
||||||
|
namesOffset -= AndroidUtilities.dp(42);
|
||||||
|
} else {
|
||||||
|
namesOffset += AndroidUtilities.dp(5);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int maxWidth;
|
||||||
|
if (messageObject.type == 13) {
|
||||||
|
int width;
|
||||||
|
if (AndroidUtilities.isTablet()) {
|
||||||
|
if (AndroidUtilities.isSmallTablet() && getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
|
||||||
|
width = AndroidUtilities.displaySize.x;
|
||||||
|
} else {
|
||||||
|
int leftWidth = AndroidUtilities.displaySize.x / 100 * 35;
|
||||||
|
if (leftWidth < AndroidUtilities.dp(320)) {
|
||||||
|
leftWidth = AndroidUtilities.dp(320);
|
||||||
|
}
|
||||||
|
width = AndroidUtilities.displaySize.x - leftWidth;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
width = AndroidUtilities.displaySize.x;
|
||||||
|
}
|
||||||
|
if (messageObject.isOut()) {
|
||||||
|
maxWidth = width - backgroundWidth - AndroidUtilities.dp(60);
|
||||||
|
} else {
|
||||||
|
maxWidth = width - backgroundWidth - AndroidUtilities.dp(56 + (isChat ? 61 : 0));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
maxWidth = getMaxNameWidth() - AndroidUtilities.dp(22);
|
||||||
|
}
|
||||||
|
if (!media && messageObject.contentType != 0) {
|
||||||
|
maxWidth -= AndroidUtilities.dp(8);
|
||||||
|
}
|
||||||
|
|
||||||
|
CharSequence stringFinalName = null;
|
||||||
|
CharSequence stringFinalText = null;
|
||||||
|
if (messageObject.replyMessageObject != null) {
|
||||||
|
TLRPC.PhotoSize photoSize = FileLoader.getClosestPhotoSizeWithSize(messageObject.replyMessageObject.photoThumbs, 80);
|
||||||
|
if (photoSize == null || messageObject.replyMessageObject.type == 13 || messageObject.type == 13 && !AndroidUtilities.isTablet()) {
|
||||||
|
replyImageReceiver.setImageBitmap((Drawable) null);
|
||||||
|
needReplyImage = false;
|
||||||
|
} else {
|
||||||
|
currentReplyPhoto = photoSize.location;
|
||||||
|
replyImageReceiver.setImage(photoSize.location, "50_50", null, true);
|
||||||
|
needReplyImage = true;
|
||||||
|
maxWidth -= AndroidUtilities.dp(44);
|
||||||
|
}
|
||||||
|
|
||||||
|
TLRPC.User user = MessagesController.getInstance().getUser(messageObject.replyMessageObject.messageOwner.from_id);
|
||||||
|
if (user != null) {
|
||||||
|
stringFinalName = TextUtils.ellipsize(ContactsController.formatName(user.first_name, user.last_name).replace("\n", " "), replyNamePaint, maxWidth - AndroidUtilities.dp(8), TextUtils.TruncateAt.END);
|
||||||
|
}
|
||||||
|
if (messageObject.replyMessageObject.messageText != null && messageObject.replyMessageObject.messageText.length() > 0) {
|
||||||
|
String mess = messageObject.replyMessageObject.messageText.toString();
|
||||||
|
if (mess.length() > 150) {
|
||||||
|
mess = mess.substring(0, 150);
|
||||||
|
}
|
||||||
|
mess = mess.replace("\n", " ");
|
||||||
|
stringFinalText = Emoji.replaceEmoji(mess, replyTextPaint.getFontMetricsInt(), AndroidUtilities.dp(14));
|
||||||
|
stringFinalText = TextUtils.ellipsize(stringFinalText, replyTextPaint, maxWidth - AndroidUtilities.dp(8), TextUtils.TruncateAt.END);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (stringFinalName == null) {
|
||||||
|
stringFinalName = LocaleController.getString("Loading", R.string.Loading);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
replyNameLayout = new StaticLayout(stringFinalName, replyNamePaint, maxWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
|
||||||
|
if (replyNameLayout.getLineCount() > 0) {
|
||||||
|
replyNameWidth = (int)Math.ceil(replyNameLayout.getLineWidth(0)) + AndroidUtilities.dp(12 + (needReplyImage ? 44 : 0));
|
||||||
|
replyNameOffset = replyNameLayout.getLineLeft(0);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
FileLog.e("tmessages", e);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
if (stringFinalText != null) {
|
||||||
|
replyTextLayout = new StaticLayout(stringFinalText, replyTextPaint, maxWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
|
||||||
|
if (replyTextLayout.getLineCount() > 0) {
|
||||||
|
replyTextWidth = (int) Math.ceil(replyTextLayout.getLineWidth(0)) + AndroidUtilities.dp(12 + (needReplyImage ? 44 : 0));
|
||||||
|
replyTextOffset = replyTextLayout.getLineLeft(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
FileLog.e("tmessages", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
requestLayout();
|
requestLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -337,6 +501,11 @@ public class ChatBaseCell extends BaseCell {
|
||||||
forwardNamePressed = true;
|
forwardNamePressed = true;
|
||||||
result = true;
|
result = true;
|
||||||
}
|
}
|
||||||
|
} else if (currentMessageObject.isReply()) {
|
||||||
|
if (x >= replyStartX && x <= replyStartX + Math.max(replyNameWidth, replyTextWidth) && y >= replyStartY && y <= replyStartY + AndroidUtilities.dp(35)) {
|
||||||
|
replyPressed = true;
|
||||||
|
result = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (result) {
|
if (result) {
|
||||||
startCheckLongPress();
|
startCheckLongPress();
|
||||||
|
@ -374,6 +543,20 @@ public class ChatBaseCell extends BaseCell {
|
||||||
forwardNamePressed = false;
|
forwardNamePressed = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (replyPressed) {
|
||||||
|
if (event.getAction() == MotionEvent.ACTION_UP) {
|
||||||
|
replyPressed = false;
|
||||||
|
playSoundEffect(SoundEffectConstants.CLICK);
|
||||||
|
if (delegate != null) {
|
||||||
|
delegate.didPressReplyMessage(this, currentMessageObject.messageOwner.reply_to_msg_id);
|
||||||
|
}
|
||||||
|
} else if (event.getAction() == MotionEvent.ACTION_CANCEL) {
|
||||||
|
replyPressed = false;
|
||||||
|
} else if (event.getAction() == MotionEvent.ACTION_MOVE) {
|
||||||
|
if (!(x >= replyStartX && x <= replyStartX + Math.max(replyNameWidth, replyTextWidth) && y >= replyStartY && y <= replyStartY + AndroidUtilities.dp(35))) {
|
||||||
|
replyPressed = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -442,7 +625,7 @@ public class ChatBaseCell extends BaseCell {
|
||||||
|
|
||||||
Drawable currentBackgroundDrawable = null;
|
Drawable currentBackgroundDrawable = null;
|
||||||
if (currentMessageObject.isOut()) {
|
if (currentMessageObject.isOut()) {
|
||||||
if (isPressed() && isCheckPressed || !isCheckPressed && isPressed) {
|
if (isPressed() && isCheckPressed || !isCheckPressed && isPressed || isHighlighted) {
|
||||||
if (!media) {
|
if (!media) {
|
||||||
currentBackgroundDrawable = backgroundDrawableOutSelected;
|
currentBackgroundDrawable = backgroundDrawableOutSelected;
|
||||||
} else {
|
} else {
|
||||||
|
@ -457,7 +640,7 @@ public class ChatBaseCell extends BaseCell {
|
||||||
}
|
}
|
||||||
setDrawableBounds(currentBackgroundDrawable, layoutWidth - backgroundWidth - (!media ? 0 : AndroidUtilities.dp(9)), AndroidUtilities.dp(1), backgroundWidth, layoutHeight - AndroidUtilities.dp(2));
|
setDrawableBounds(currentBackgroundDrawable, layoutWidth - backgroundWidth - (!media ? 0 : AndroidUtilities.dp(9)), AndroidUtilities.dp(1), backgroundWidth, layoutHeight - AndroidUtilities.dp(2));
|
||||||
} else {
|
} else {
|
||||||
if (isPressed() && isCheckPressed || !isCheckPressed && isPressed) {
|
if (isPressed() && isCheckPressed || !isCheckPressed && isPressed || isHighlighted) {
|
||||||
if (!media) {
|
if (!media) {
|
||||||
currentBackgroundDrawable = backgroundDrawableInSelected;
|
currentBackgroundDrawable = backgroundDrawableInSelected;
|
||||||
} else {
|
} else {
|
||||||
|
@ -491,21 +674,87 @@ public class ChatBaseCell extends BaseCell {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (drawForwardedName && forwardedNameLayout != null) {
|
if (drawForwardedName && forwardedNameLayout != null) {
|
||||||
canvas.save();
|
forwardNameY = AndroidUtilities.dp(10 + (drawName ? 19 : 0));
|
||||||
if (currentMessageObject.isOut()) {
|
if (currentMessageObject.isOut()) {
|
||||||
forwardNamePaint.setColor(0xff4a923c);
|
forwardNamePaint.setColor(0xff4a923c);
|
||||||
forwardNameX = currentBackgroundDrawable.getBounds().left + AndroidUtilities.dp(10);
|
forwardNameX = currentBackgroundDrawable.getBounds().left + AndroidUtilities.dp(10);
|
||||||
forwardNameY = AndroidUtilities.dp(10 + (drawName ? 18 : 0));
|
|
||||||
} else {
|
} else {
|
||||||
forwardNamePaint.setColor(0xff006fc8);
|
forwardNamePaint.setColor(0xff006fc8);
|
||||||
forwardNameX = currentBackgroundDrawable.getBounds().left + AndroidUtilities.dp(19);
|
forwardNameX = currentBackgroundDrawable.getBounds().left + AndroidUtilities.dp(19);
|
||||||
forwardNameY = AndroidUtilities.dp(10 + (drawName ? 18 : 0));
|
|
||||||
}
|
}
|
||||||
|
canvas.save();
|
||||||
canvas.translate(forwardNameX - forwardNameOffsetX, forwardNameY);
|
canvas.translate(forwardNameX - forwardNameOffsetX, forwardNameY);
|
||||||
forwardedNameLayout.draw(canvas);
|
forwardedNameLayout.draw(canvas);
|
||||||
canvas.restore();
|
canvas.restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (currentMessageObject.isReply()) {
|
||||||
|
if (currentMessageObject.type == 13) {
|
||||||
|
replyLinePaint.setColor(0xffffffff);
|
||||||
|
replyNamePaint.setColor(0xffffffff);
|
||||||
|
replyTextPaint.setColor(0xffffffff);
|
||||||
|
int backWidth;
|
||||||
|
if (currentMessageObject.isOut()) {
|
||||||
|
backWidth = currentBackgroundDrawable.getBounds().left - AndroidUtilities.dp(32);
|
||||||
|
replyStartX = currentBackgroundDrawable.getBounds().left - AndroidUtilities.dp(9) - backWidth;
|
||||||
|
} else {
|
||||||
|
backWidth = getWidth() - currentBackgroundDrawable.getBounds().right - AndroidUtilities.dp(32);
|
||||||
|
replyStartX = currentBackgroundDrawable.getBounds().right + AndroidUtilities.dp(23);
|
||||||
|
}
|
||||||
|
Drawable back;
|
||||||
|
if (ApplicationLoader.isCustomTheme()) {
|
||||||
|
back = backgroundBlack;
|
||||||
|
} else {
|
||||||
|
back = backgroundBlue;
|
||||||
|
}
|
||||||
|
replyStartY = layoutHeight - AndroidUtilities.dp(58);
|
||||||
|
back.setBounds(replyStartX - AndroidUtilities.dp(7), replyStartY - AndroidUtilities.dp(6), replyStartX - AndroidUtilities.dp(7) + backWidth, replyStartY + AndroidUtilities.dp(41));
|
||||||
|
back.draw(canvas);
|
||||||
|
} else {
|
||||||
|
if (currentMessageObject.isOut()) {
|
||||||
|
replyLinePaint.setColor(0xff8dc97a);
|
||||||
|
replyNamePaint.setColor(0xff61a349);
|
||||||
|
if (currentMessageObject.replyMessageObject != null && currentMessageObject.replyMessageObject.type == 0) {
|
||||||
|
replyTextPaint.setColor(0xff000000);
|
||||||
|
} else {
|
||||||
|
replyTextPaint.setColor(0xff70b15c);
|
||||||
|
}
|
||||||
|
replyStartX = currentBackgroundDrawable.getBounds().left + AndroidUtilities.dp(11);
|
||||||
|
} else {
|
||||||
|
replyLinePaint.setColor(0xff6c9fd2);
|
||||||
|
replyNamePaint.setColor(0xff377aae);
|
||||||
|
if (currentMessageObject.replyMessageObject != null && currentMessageObject.replyMessageObject.type == 0) {
|
||||||
|
replyTextPaint.setColor(0xff000000);
|
||||||
|
} else {
|
||||||
|
replyTextPaint.setColor(0xff999999);
|
||||||
|
}
|
||||||
|
if (currentMessageObject.contentType == 1 && media) {
|
||||||
|
replyStartX = currentBackgroundDrawable.getBounds().left + AndroidUtilities.dp(11);
|
||||||
|
} else {
|
||||||
|
replyStartX = currentBackgroundDrawable.getBounds().left + AndroidUtilities.dp(20);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
replyStartY = AndroidUtilities.dp(12 + (drawForwardedName && forwardedNameLayout != null ? 36 : 0) + (drawName && nameLayout != null ? 20 : 0));
|
||||||
|
}
|
||||||
|
canvas.drawRect(replyStartX, replyStartY, replyStartX + AndroidUtilities.dp(2), replyStartY + AndroidUtilities.dp(35), replyLinePaint);
|
||||||
|
if (needReplyImage) {
|
||||||
|
replyImageReceiver.setImageCoords(replyStartX + AndroidUtilities.dp(10), replyStartY, AndroidUtilities.dp(35), AndroidUtilities.dp(35));
|
||||||
|
replyImageReceiver.draw(canvas);
|
||||||
|
}
|
||||||
|
if (replyNameLayout != null) {
|
||||||
|
canvas.save();
|
||||||
|
canvas.translate(replyStartX - replyNameOffset + AndroidUtilities.dp(10 + (needReplyImage ? 44 : 0)), replyStartY);
|
||||||
|
replyNameLayout.draw(canvas);
|
||||||
|
canvas.restore();
|
||||||
|
}
|
||||||
|
if (replyTextLayout != null) {
|
||||||
|
canvas.save();
|
||||||
|
canvas.translate(replyStartX - replyTextOffset + AndroidUtilities.dp(10 + (needReplyImage ? 44 : 0)), replyStartY + AndroidUtilities.dp(19));
|
||||||
|
replyTextLayout.draw(canvas);
|
||||||
|
canvas.restore();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (drawTime) {
|
if (drawTime) {
|
||||||
if (media) {
|
if (media) {
|
||||||
setDrawableBounds(mediaBackgroundDrawable, timeX - AndroidUtilities.dp(3), layoutHeight - AndroidUtilities.dp(27.5f), timeWidth + AndroidUtilities.dp(6 + (currentMessageObject.isOut() ? 20 : 0)), AndroidUtilities.dp(16.5f));
|
setDrawableBounds(mediaBackgroundDrawable, timeX - AndroidUtilities.dp(3), layoutHeight - AndroidUtilities.dp(27.5f), timeWidth + AndroidUtilities.dp(6 + (currentMessageObject.isOut() ? 20 : 0)), AndroidUtilities.dp(16.5f));
|
||||||
|
@ -574,9 +823,9 @@ public class ChatBaseCell extends BaseCell {
|
||||||
if (drawCheck2) {
|
if (drawCheck2) {
|
||||||
if (!media) {
|
if (!media) {
|
||||||
if (drawCheck1) {
|
if (drawCheck1) {
|
||||||
setDrawableBounds(checkDrawable, layoutWidth - AndroidUtilities.dp(22.5f) - checkDrawable.getIntrinsicWidth(), layoutHeight - AndroidUtilities.dp(8.5f) - checkDrawable.getIntrinsicHeight());
|
setDrawableBounds(checkDrawable, layoutWidth - AndroidUtilities.dp(22.5f) - checkDrawable.getIntrinsicWidth(), layoutHeight - AndroidUtilities.dp(8.0f) - checkDrawable.getIntrinsicHeight());
|
||||||
} else {
|
} else {
|
||||||
setDrawableBounds(checkDrawable, layoutWidth - AndroidUtilities.dp(18.5f) - checkDrawable.getIntrinsicWidth(), layoutHeight - AndroidUtilities.dp(8.5f) - checkDrawable.getIntrinsicHeight());
|
setDrawableBounds(checkDrawable, layoutWidth - AndroidUtilities.dp(18.5f) - checkDrawable.getIntrinsicWidth(), layoutHeight - AndroidUtilities.dp(8.0f) - checkDrawable.getIntrinsicHeight());
|
||||||
}
|
}
|
||||||
checkDrawable.draw(canvas);
|
checkDrawable.draw(canvas);
|
||||||
} else {
|
} else {
|
||||||
|
@ -590,7 +839,7 @@ public class ChatBaseCell extends BaseCell {
|
||||||
}
|
}
|
||||||
if (drawCheck1) {
|
if (drawCheck1) {
|
||||||
if (!media) {
|
if (!media) {
|
||||||
setDrawableBounds(halfCheckDrawable, layoutWidth - AndroidUtilities.dp(18) - halfCheckDrawable.getIntrinsicWidth(), layoutHeight - AndroidUtilities.dp(8.5f) - halfCheckDrawable.getIntrinsicHeight());
|
setDrawableBounds(halfCheckDrawable, layoutWidth - AndroidUtilities.dp(18) - halfCheckDrawable.getIntrinsicWidth(), layoutHeight - AndroidUtilities.dp(8.0f) - halfCheckDrawable.getIntrinsicHeight());
|
||||||
halfCheckDrawable.draw(canvas);
|
halfCheckDrawable.draw(canvas);
|
||||||
} else {
|
} else {
|
||||||
setDrawableBounds(halfCheckMediaDrawable, layoutWidth - AndroidUtilities.dp(20.5f) - halfCheckMediaDrawable.getIntrinsicWidth(), layoutHeight - AndroidUtilities.dp(13.0f) - halfCheckMediaDrawable.getIntrinsicHeight());
|
setDrawableBounds(halfCheckMediaDrawable, layoutWidth - AndroidUtilities.dp(20.5f) - halfCheckMediaDrawable.getIntrinsicWidth(), layoutHeight - AndroidUtilities.dp(13.0f) - halfCheckMediaDrawable.getIntrinsicHeight());
|
||||||
|
|
|
@ -32,9 +32,9 @@ import org.telegram.ui.Components.AvatarDrawable;
|
||||||
|
|
||||||
public class ChatContactCell extends ChatBaseCell {
|
public class ChatContactCell extends ChatBaseCell {
|
||||||
|
|
||||||
public static interface ChatContactCellDelegate {
|
public interface ChatContactCellDelegate {
|
||||||
public abstract void didClickAddButton(ChatContactCell cell, TLRPC.User user);
|
void didClickAddButton(ChatContactCell cell, TLRPC.User user);
|
||||||
public abstract void didClickPhone(ChatContactCell cell);
|
void didClickPhone(ChatContactCell cell);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static TextPaint namePaint;
|
private static TextPaint namePaint;
|
||||||
|
@ -113,7 +113,7 @@ public class ChatContactCell extends ChatBaseCell {
|
||||||
if (x >= avatarImage.getImageX() && x <= avatarImage.getImageX() + namesWidth + AndroidUtilities.dp(42) && y >= avatarImage.getImageY() && y <= avatarImage.getImageY() + avatarImage.getImageHeight()) {
|
if (x >= avatarImage.getImageX() && x <= avatarImage.getImageX() + namesWidth + AndroidUtilities.dp(42) && y >= avatarImage.getImageY() && y <= avatarImage.getImageY() + avatarImage.getImageHeight()) {
|
||||||
avatarPressed = true;
|
avatarPressed = true;
|
||||||
result = true;
|
result = true;
|
||||||
} else if (x >= avatarImage.getImageX() + namesWidth + AndroidUtilities.dp(52) && y >= AndroidUtilities.dp(13) && x <= avatarImage.getImageX() + namesWidth + AndroidUtilities.dp(92) && y <= AndroidUtilities.dp(52)) {
|
} else if (x >= avatarImage.getImageX() + namesWidth + AndroidUtilities.dp(52) && y >= AndroidUtilities.dp(13) + namesOffset && x <= avatarImage.getImageX() + namesWidth + AndroidUtilities.dp(92) && y <= AndroidUtilities.dp(52) + namesOffset) {
|
||||||
buttonPressed = true;
|
buttonPressed = true;
|
||||||
result = true;
|
result = true;
|
||||||
}
|
}
|
||||||
|
@ -154,7 +154,7 @@ public class ChatContactCell extends ChatBaseCell {
|
||||||
} else if (event.getAction() == MotionEvent.ACTION_CANCEL) {
|
} else if (event.getAction() == MotionEvent.ACTION_CANCEL) {
|
||||||
buttonPressed = false;
|
buttonPressed = false;
|
||||||
} else if (event.getAction() == MotionEvent.ACTION_MOVE) {
|
} else if (event.getAction() == MotionEvent.ACTION_MOVE) {
|
||||||
if (!(x >= avatarImage.getImageX() + namesWidth + AndroidUtilities.dp(52) && y >= AndroidUtilities.dp(13) && x <= avatarImage.getImageX() + namesWidth + AndroidUtilities.dp(92) && y <= AndroidUtilities.dp(52))) {
|
if (!(x >= avatarImage.getImageX() + namesWidth + AndroidUtilities.dp(52) && y >= AndroidUtilities.dp(13) + namesOffset && x <= avatarImage.getImageX() + namesWidth + AndroidUtilities.dp(92) && y <= AndroidUtilities.dp(52) + namesOffset)) {
|
||||||
buttonPressed = false;
|
buttonPressed = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -235,7 +235,7 @@ public class ChatContactCell extends ChatBaseCell {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||||
setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), AndroidUtilities.dp(71));
|
setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), AndroidUtilities.dp(71) + namesOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -257,7 +257,7 @@ public class ChatContactCell extends ChatBaseCell {
|
||||||
x = AndroidUtilities.dp(16);
|
x = AndroidUtilities.dp(16);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
avatarImage.setImageCoords(x, AndroidUtilities.dp(9), AndroidUtilities.dp(42), AndroidUtilities.dp(42));
|
avatarImage.setImageCoords(x, AndroidUtilities.dp(9) + namesOffset, AndroidUtilities.dp(42), AndroidUtilities.dp(42));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -272,14 +272,14 @@ public class ChatContactCell extends ChatBaseCell {
|
||||||
|
|
||||||
if (nameLayout != null) {
|
if (nameLayout != null) {
|
||||||
canvas.save();
|
canvas.save();
|
||||||
canvas.translate(avatarImage.getImageX() + avatarImage.getImageWidth() + AndroidUtilities.dp(9), AndroidUtilities.dp(10));
|
canvas.translate(avatarImage.getImageX() + avatarImage.getImageWidth() + AndroidUtilities.dp(9), AndroidUtilities.dp(10) + namesOffset);
|
||||||
namePaint.setColor(AvatarDrawable.getColorForId(currentMessageObject.messageOwner.media.user_id));
|
namePaint.setColor(AvatarDrawable.getColorForId(currentMessageObject.messageOwner.media.user_id));
|
||||||
nameLayout.draw(canvas);
|
nameLayout.draw(canvas);
|
||||||
canvas.restore();
|
canvas.restore();
|
||||||
}
|
}
|
||||||
if (phoneLayout != null) {
|
if (phoneLayout != null) {
|
||||||
canvas.save();
|
canvas.save();
|
||||||
canvas.translate(avatarImage.getImageX() + avatarImage.getImageWidth() + AndroidUtilities.dp(9), AndroidUtilities.dp(31));
|
canvas.translate(avatarImage.getImageX() + avatarImage.getImageWidth() + AndroidUtilities.dp(9), AndroidUtilities.dp(31) + namesOffset);
|
||||||
phoneLayout.draw(canvas);
|
phoneLayout.draw(canvas);
|
||||||
canvas.restore();
|
canvas.restore();
|
||||||
}
|
}
|
||||||
|
@ -291,7 +291,7 @@ public class ChatContactCell extends ChatBaseCell {
|
||||||
} else {
|
} else {
|
||||||
addContactDrawable = addContactDrawableIn;
|
addContactDrawable = addContactDrawableIn;
|
||||||
}
|
}
|
||||||
setDrawableBounds(addContactDrawable, avatarImage.getImageX() + namesWidth + AndroidUtilities.dp(78), AndroidUtilities.dp(13));
|
setDrawableBounds(addContactDrawable, avatarImage.getImageX() + namesWidth + AndroidUtilities.dp(78), AndroidUtilities.dp(13) + namesOffset);
|
||||||
addContactDrawable.draw(canvas);
|
addContactDrawable.draw(canvas);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,9 +43,9 @@ import java.util.Locale;
|
||||||
|
|
||||||
public class ChatMediaCell extends ChatBaseCell implements MediaController.FileDownloadProgressListener {
|
public class ChatMediaCell extends ChatBaseCell implements MediaController.FileDownloadProgressListener {
|
||||||
|
|
||||||
public static interface ChatMediaCellDelegate {
|
public interface ChatMediaCellDelegate {
|
||||||
public abstract void didClickedImage(ChatMediaCell cell);
|
void didClickedImage(ChatMediaCell cell);
|
||||||
public abstract void didPressedOther(ChatMediaCell cell);
|
void didPressedOther(ChatMediaCell cell);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Drawable placeholderDocInDrawable;
|
private static Drawable placeholderDocInDrawable;
|
||||||
|
@ -191,7 +191,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
|
||||||
otherPressed = true;
|
otherPressed = true;
|
||||||
result = true;
|
result = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else if (currentMessageObject.type != 13) {
|
||||||
if (x >= photoImage.getImageX() && x <= photoImage.getImageX() + backgroundWidth && y >= photoImage.getImageY() && y <= photoImage.getImageY() + photoImage.getImageHeight()) {
|
if (x >= photoImage.getImageX() && x <= photoImage.getImageX() + backgroundWidth && y >= photoImage.getImageY() && y <= photoImage.getImageY() + photoImage.getImageHeight()) {
|
||||||
imagePressed = true;
|
imagePressed = true;
|
||||||
result = true;
|
result = true;
|
||||||
|
@ -359,7 +359,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
|
||||||
photoImage.cancelLoadImage();
|
photoImage.cancelLoadImage();
|
||||||
} else if (currentMessageObject.type == 8 || currentMessageObject.type == 9) {
|
} else if (currentMessageObject.type == 8 || currentMessageObject.type == 9) {
|
||||||
FileLoader.getInstance().cancelLoadFile(currentMessageObject.messageOwner.media.document);
|
FileLoader.getInstance().cancelLoadFile(currentMessageObject.messageOwner.media.document);
|
||||||
if (lastDownloadedGifMessage != null && lastDownloadedGifMessage.messageOwner.id == currentMessageObject.messageOwner.id) {
|
if (lastDownloadedGifMessage != null && lastDownloadedGifMessage.getId() == currentMessageObject.getId()) {
|
||||||
lastDownloadedGifMessage = null;
|
lastDownloadedGifMessage = null;
|
||||||
}
|
}
|
||||||
} else if (currentMessageObject.type == 3) {
|
} else if (currentMessageObject.type == 3) {
|
||||||
|
@ -413,7 +413,6 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
|
||||||
media = messageObject.type != 9;
|
media = messageObject.type != 9;
|
||||||
boolean dataChanged = currentMessageObject == messageObject && (isUserDataChanged() || photoNotSet);
|
boolean dataChanged = currentMessageObject == messageObject && (isUserDataChanged() || photoNotSet);
|
||||||
if (currentMessageObject != messageObject || isPhotoDataChanged(messageObject) || dataChanged) {
|
if (currentMessageObject != messageObject || isPhotoDataChanged(messageObject) || dataChanged) {
|
||||||
super.setMessageObject(messageObject);
|
|
||||||
cancelLoading = false;
|
cancelLoading = false;
|
||||||
|
|
||||||
buttonState = -1;
|
buttonState = -1;
|
||||||
|
@ -510,13 +509,13 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
|
||||||
photoImage.setImageBitmap((BitmapDrawable) null);
|
photoImage.setImageBitmap((BitmapDrawable) null);
|
||||||
}
|
}
|
||||||
} else if (messageObject.type == 4) { //geo
|
} else if (messageObject.type == 4) { //geo
|
||||||
photoWidth = AndroidUtilities.dp(100);
|
photoWidth = AndroidUtilities.dp(200);
|
||||||
photoHeight = AndroidUtilities.dp(100);
|
photoHeight = AndroidUtilities.dp(100);
|
||||||
backgroundWidth = photoWidth + AndroidUtilities.dp(12);
|
backgroundWidth = photoWidth + AndroidUtilities.dp(12);
|
||||||
|
|
||||||
double lat = messageObject.messageOwner.media.geo.lat;
|
double lat = messageObject.messageOwner.media.geo.lat;
|
||||||
double lon = messageObject.messageOwner.media.geo._long;
|
double lon = messageObject.messageOwner.media.geo._long;
|
||||||
currentUrl = String.format(Locale.US, "https://maps.googleapis.com/maps/api/staticmap?center=%f,%f&zoom=13&size=100x100&maptype=roadmap&scale=%d&markers=color:red|size:big|%f,%f&sensor=false", lat, lon, Math.min(2, (int)Math.ceil(AndroidUtilities.density)), lat, lon);
|
currentUrl = String.format(Locale.US, "https://maps.googleapis.com/maps/api/staticmap?center=%f,%f&zoom=13&size=200x100&maptype=roadmap&scale=%d&markers=color:red|size:big|%f,%f&sensor=false", lat, lon, Math.min(2, (int)Math.ceil(AndroidUtilities.density)), lat, lon);
|
||||||
photoImage.setNeedsQualityThumb(false);
|
photoImage.setNeedsQualityThumb(false);
|
||||||
photoImage.setShouldGenerateQualityThumb(false);
|
photoImage.setShouldGenerateQualityThumb(false);
|
||||||
photoImage.setParentMessageObject(null);
|
photoImage.setParentMessageObject(null);
|
||||||
|
@ -530,15 +529,20 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
float maxHeight = AndroidUtilities.displaySize.y * 0.4f;
|
||||||
float maxWidth;
|
float maxWidth;
|
||||||
if (AndroidUtilities.isTablet()) {
|
if (AndroidUtilities.isTablet()) {
|
||||||
maxWidth = (int) (AndroidUtilities.getMinTabletSide() * 0.5f);
|
maxWidth = AndroidUtilities.getMinTabletSide() * 0.5f;
|
||||||
} else {
|
} else {
|
||||||
maxWidth = (int) (Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) * 0.5f);
|
maxWidth = AndroidUtilities.displaySize.x * 0.5f;
|
||||||
}
|
}
|
||||||
if (photoWidth == 0) {
|
if (photoWidth == 0) {
|
||||||
photoWidth = (int)maxWidth;
|
photoHeight = (int) maxHeight;
|
||||||
photoHeight = photoWidth + AndroidUtilities.dp(100);
|
photoWidth = photoHeight + AndroidUtilities.dp(100);
|
||||||
|
}
|
||||||
|
if (photoHeight > maxHeight) {
|
||||||
|
photoWidth *= maxHeight / photoHeight;
|
||||||
|
photoHeight = (int)maxHeight;
|
||||||
}
|
}
|
||||||
if (photoWidth > maxWidth) {
|
if (photoWidth > maxWidth) {
|
||||||
photoHeight *= maxWidth / photoWidth;
|
photoHeight *= maxWidth / photoWidth;
|
||||||
|
@ -549,23 +553,23 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
|
||||||
photoImage.setNeedsQualityThumb(false);
|
photoImage.setNeedsQualityThumb(false);
|
||||||
photoImage.setShouldGenerateQualityThumb(false);
|
photoImage.setShouldGenerateQualityThumb(false);
|
||||||
photoImage.setParentMessageObject(null);
|
photoImage.setParentMessageObject(null);
|
||||||
if (currentMessageObject.messageOwner.attachPath != null && currentMessageObject.messageOwner.attachPath.length() > 0) {
|
if (messageObject.messageOwner.attachPath != null && messageObject.messageOwner.attachPath.length() > 0) {
|
||||||
File f = new File(currentMessageObject.messageOwner.attachPath);
|
File f = new File(messageObject.messageOwner.attachPath);
|
||||||
if (f.exists()) {
|
if (f.exists()) {
|
||||||
photoImage.setImage(null, currentMessageObject.messageOwner.attachPath,
|
photoImage.setImage(null, messageObject.messageOwner.attachPath,
|
||||||
String.format(Locale.US, "%d_%d", photoWidth, photoHeight),
|
String.format(Locale.US, "%d_%d", photoWidth, photoHeight),
|
||||||
null,
|
null,
|
||||||
currentPhotoObjectThumb != null ? currentPhotoObjectThumb.location : null,
|
currentPhotoObjectThumb != null ? currentPhotoObjectThumb.location : null,
|
||||||
"b1",
|
"b1",
|
||||||
currentMessageObject.messageOwner.media.document.size, true);
|
messageObject.messageOwner.media.document.size, true);
|
||||||
}
|
}
|
||||||
} else if (currentMessageObject.messageOwner.media.document.id != 0) {
|
} else if (messageObject.messageOwner.media.document.id != 0) {
|
||||||
photoImage.setImage(currentMessageObject.messageOwner.media.document, null,
|
photoImage.setImage(messageObject.messageOwner.media.document, null,
|
||||||
String.format(Locale.US, "%d_%d", photoWidth, photoHeight),
|
String.format(Locale.US, "%d_%d", photoWidth, photoHeight),
|
||||||
null,
|
null,
|
||||||
currentPhotoObjectThumb != null ? currentPhotoObjectThumb.location : null,
|
currentPhotoObjectThumb != null ? currentPhotoObjectThumb.location : null,
|
||||||
"b1",
|
"b1",
|
||||||
currentMessageObject.messageOwner.media.document.size, true);
|
messageObject.messageOwner.media.document.size, true);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (AndroidUtilities.isTablet()) {
|
if (AndroidUtilities.isTablet()) {
|
||||||
|
@ -603,7 +607,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
|
||||||
|
|
||||||
if (currentPhotoObject != null) {
|
if (currentPhotoObject != null) {
|
||||||
boolean noSize = false;
|
boolean noSize = false;
|
||||||
if (currentMessageObject.type == 3 || currentMessageObject.type == 8) {
|
if (messageObject.type == 3 || messageObject.type == 8) {
|
||||||
noSize = true;
|
noSize = true;
|
||||||
}
|
}
|
||||||
float scale = (float) currentPhotoObject.w / (float) photoWidth;
|
float scale = (float) currentPhotoObject.w / (float) photoWidth;
|
||||||
|
@ -636,12 +640,12 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
|
||||||
w = (int) (currentPhotoObject.w / hScale);
|
w = (int) (currentPhotoObject.w / hScale);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int timeWidthTotal = timeWidth + AndroidUtilities.dp(14 + (currentMessageObject.isOut() ? 20 : 0));
|
int timeWidthTotal = timeWidth + AndroidUtilities.dp(14 + (messageObject.isOut() ? 20 : 0));
|
||||||
if (w < timeWidthTotal) {
|
if (w < timeWidthTotal) {
|
||||||
w = timeWidthTotal;
|
w = timeWidthTotal;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentMessageObject.isSecretPhoto()) {
|
if (messageObject.isSecretPhoto()) {
|
||||||
if (AndroidUtilities.isTablet()) {
|
if (AndroidUtilities.isTablet()) {
|
||||||
w = h = (int) (AndroidUtilities.getMinTabletSide() * 0.5f);
|
w = h = (int) (AndroidUtilities.getMinTabletSide() * 0.5f);
|
||||||
} else {
|
} else {
|
||||||
|
@ -665,7 +669,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
|
||||||
String fileName = FileLoader.getAttachFileName(currentPhotoObject);
|
String fileName = FileLoader.getAttachFileName(currentPhotoObject);
|
||||||
if (messageObject.type == 1) {
|
if (messageObject.type == 1) {
|
||||||
boolean photoExist = true;
|
boolean photoExist = true;
|
||||||
File cacheFile = FileLoader.getPathToMessage(currentMessageObject.messageOwner);
|
File cacheFile = FileLoader.getPathToMessage(messageObject.messageOwner);
|
||||||
if (!cacheFile.exists()) {
|
if (!cacheFile.exists()) {
|
||||||
photoExist = false;
|
photoExist = false;
|
||||||
} else {
|
} else {
|
||||||
|
@ -696,6 +700,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
|
||||||
photoImage.setImageBitmap((Bitmap)null);
|
photoImage.setImageBitmap((Bitmap)null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
super.setMessageObject(messageObject);
|
||||||
|
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
|
@ -738,7 +743,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
|
||||||
buttonState = 1;
|
buttonState = 1;
|
||||||
radialProgress.setBackground(getDrawableForCurrentState(), true, animated);
|
radialProgress.setBackground(getDrawableForCurrentState(), true, animated);
|
||||||
Float progress = ImageLoader.getInstance().getFileProgress(currentMessageObject.messageOwner.attachPath);
|
Float progress = ImageLoader.getInstance().getFileProgress(currentMessageObject.messageOwner.attachPath);
|
||||||
if (progress == null && SendMessagesHelper.getInstance().isSendingMessage(currentMessageObject.messageOwner.id)) {
|
if (progress == null && SendMessagesHelper.getInstance().isSendingMessage(currentMessageObject.getId())) {
|
||||||
progress = 1.0f;
|
progress = 1.0f;
|
||||||
}
|
}
|
||||||
radialProgress.setProgress(progress != null ? progress : 0, false);
|
radialProgress.setProgress(progress != null ? progress : 0, false);
|
||||||
|
@ -788,7 +793,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||||
setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), photoHeight + AndroidUtilities.dp(14));
|
setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), photoHeight + AndroidUtilities.dp(14) + namesOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -809,10 +814,10 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
|
||||||
x = AndroidUtilities.dp(15);
|
x = AndroidUtilities.dp(15);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
photoImage.setImageCoords(x, AndroidUtilities.dp(7), photoWidth, photoHeight);
|
photoImage.setImageCoords(x, AndroidUtilities.dp(7) + namesOffset, photoWidth, photoHeight);
|
||||||
int size = AndroidUtilities.dp(48);
|
int size = AndroidUtilities.dp(48);
|
||||||
buttonX = (int)(x + (photoWidth - size) / 2.0f);
|
buttonX = (int)(x + (photoWidth - size) / 2.0f);
|
||||||
buttonY = (int)(AndroidUtilities.dp(7) + (photoHeight - size) / 2.0f);
|
buttonY = (int)(AndroidUtilities.dp(7) + (photoHeight - size) / 2.0f) + namesOffset;
|
||||||
|
|
||||||
radialProgress.setProgressRect(buttonX, buttonY, buttonX + AndroidUtilities.dp(48), buttonY + AndroidUtilities.dp(48));
|
radialProgress.setProgressRect(buttonX, buttonY, buttonX + AndroidUtilities.dp(48), buttonY + AndroidUtilities.dp(48));
|
||||||
deleteProgressRect.set(buttonX + AndroidUtilities.dp(3), buttonY + AndroidUtilities.dp(3), buttonX + AndroidUtilities.dp(45), buttonY + AndroidUtilities.dp(45));
|
deleteProgressRect.set(buttonX + AndroidUtilities.dp(3), buttonY + AndroidUtilities.dp(3), buttonX + AndroidUtilities.dp(45), buttonY + AndroidUtilities.dp(45));
|
||||||
|
@ -854,12 +859,13 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
|
||||||
protected void onAfterBackgroundDraw(Canvas canvas) {
|
protected void onAfterBackgroundDraw(Canvas canvas) {
|
||||||
boolean imageDrawn = false;
|
boolean imageDrawn = false;
|
||||||
if (gifDrawable != null) {
|
if (gifDrawable != null) {
|
||||||
|
drawTime = !gifDrawable.isPlaying();
|
||||||
canvas.save();
|
canvas.save();
|
||||||
gifDrawable.setBounds(photoImage.getImageX(), photoImage.getImageY(), photoImage.getImageX() + photoWidth, photoImage.getImageY() + photoHeight);
|
gifDrawable.setBounds(photoImage.getImageX(), photoImage.getImageY(), photoImage.getImageX() + photoWidth, photoImage.getImageY() + photoHeight);
|
||||||
gifDrawable.draw(canvas);
|
gifDrawable.draw(canvas);
|
||||||
canvas.restore();
|
canvas.restore();
|
||||||
} else {
|
} else {
|
||||||
photoImage.setPressed(isPressed() && isCheckPressed || !isCheckPressed && isPressed);
|
photoImage.setPressed(isPressed() && isCheckPressed || !isCheckPressed && isPressed || isHighlighted);
|
||||||
photoImage.setVisible(!PhotoViewer.getInstance().isShowingImage(currentMessageObject), false);
|
photoImage.setVisible(!PhotoViewer.getInstance().isShowingImage(currentMessageObject), false);
|
||||||
imageDrawn = photoImage.draw(canvas);
|
imageDrawn = photoImage.draw(canvas);
|
||||||
drawTime = photoImage.getVisible();
|
drawTime = photoImage.getVisible();
|
||||||
|
@ -870,8 +876,8 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
|
||||||
if (currentMessageObject.type == 9) {
|
if (currentMessageObject.type == 9) {
|
||||||
Drawable menuDrawable = null;
|
Drawable menuDrawable = null;
|
||||||
if (currentMessageObject.isOut()) {
|
if (currentMessageObject.isOut()) {
|
||||||
infoPaint.setColor(0xff75b166);
|
infoPaint.setColor(0xff70b15c);
|
||||||
docBackPaint.setColor(0xffd0f3b3);
|
docBackPaint.setColor(0xffdaf5c3);
|
||||||
menuDrawable = docMenuOutDrawable;
|
menuDrawable = docMenuOutDrawable;
|
||||||
} else {
|
} else {
|
||||||
infoPaint.setColor(0xffa1adbb);
|
infoPaint.setColor(0xffa1adbb);
|
||||||
|
@ -879,7 +885,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
|
||||||
menuDrawable = docMenuInDrawable;
|
menuDrawable = docMenuInDrawable;
|
||||||
}
|
}
|
||||||
|
|
||||||
setDrawableBounds(menuDrawable, photoImage.getImageX() + backgroundWidth - AndroidUtilities.dp(44), AndroidUtilities.dp(10));
|
setDrawableBounds(menuDrawable, photoImage.getImageX() + backgroundWidth - AndroidUtilities.dp(44), AndroidUtilities.dp(10) + namesOffset);
|
||||||
menuDrawable.draw(canvas);
|
menuDrawable.draw(canvas);
|
||||||
|
|
||||||
if (buttonState >= 0 && buttonState < 4) {
|
if (buttonState >= 0 && buttonState < 4) {
|
||||||
|
@ -978,7 +984,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
|
||||||
@Override
|
@Override
|
||||||
public void onSuccessDownload(String fileName) {
|
public void onSuccessDownload(String fileName) {
|
||||||
radialProgress.setProgress(1, true);
|
radialProgress.setProgress(1, true);
|
||||||
if (currentMessageObject.type == 8 && lastDownloadedGifMessage != null && lastDownloadedGifMessage.messageOwner.id == currentMessageObject.messageOwner.id) {
|
if (currentMessageObject.type == 8 && lastDownloadedGifMessage != null && lastDownloadedGifMessage.getId() == currentMessageObject.getId()) {
|
||||||
buttonState = 2;
|
buttonState = 2;
|
||||||
didPressedButton(true);
|
didPressedButton(true);
|
||||||
} else if (!photoNotSet) {
|
} else if (!photoNotSet) {
|
||||||
|
|
|
@ -9,34 +9,128 @@
|
||||||
package org.telegram.ui.Cells;
|
package org.telegram.ui.Cells;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
|
import android.graphics.Paint;
|
||||||
|
import android.graphics.Path;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.provider.Browser;
|
||||||
|
import android.text.Layout;
|
||||||
import android.text.Spannable;
|
import android.text.Spannable;
|
||||||
|
import android.text.SpannableStringBuilder;
|
||||||
|
import android.text.StaticLayout;
|
||||||
|
import android.text.TextPaint;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.text.style.ClickableSpan;
|
import android.text.style.ClickableSpan;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
|
|
||||||
import org.telegram.android.AndroidUtilities;
|
import org.telegram.android.AndroidUtilities;
|
||||||
|
import org.telegram.android.ImageReceiver;
|
||||||
|
import org.telegram.android.MediaController;
|
||||||
|
import org.telegram.messenger.FileLoader;
|
||||||
import org.telegram.messenger.FileLog;
|
import org.telegram.messenger.FileLog;
|
||||||
import org.telegram.android.MessageObject;
|
import org.telegram.android.MessageObject;
|
||||||
|
import org.telegram.messenger.R;
|
||||||
|
import org.telegram.messenger.TLRPC;
|
||||||
|
import org.telegram.ui.Components.StaticLayoutEx;
|
||||||
|
import org.telegram.ui.Components.URLSpanNoUnderline;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
public class ChatMessageCell extends ChatBaseCell {
|
public class ChatMessageCell extends ChatBaseCell {
|
||||||
|
|
||||||
private int textX, textY;
|
private int textX, textY;
|
||||||
private int totalHeight = 0;
|
private int totalHeight = 0;
|
||||||
private ClickableSpan pressedLink;
|
private ClickableSpan pressedLink;
|
||||||
|
private int linkBlockNum;
|
||||||
|
private MyPath urlPath = new MyPath();
|
||||||
|
private boolean linkPreviewPressed;
|
||||||
|
private static Paint urlPaint;
|
||||||
|
|
||||||
private int lastVisibleBlockNum = 0;
|
private int lastVisibleBlockNum = 0;
|
||||||
private int firstVisibleBlockNum = 0;
|
private int firstVisibleBlockNum = 0;
|
||||||
private int totalVisibleBlocksCount = 0;
|
private int totalVisibleBlocksCount = 0;
|
||||||
|
|
||||||
|
private ImageReceiver linkImageView;
|
||||||
|
private boolean isSmallImage;
|
||||||
|
private boolean drawLinkImageView;
|
||||||
|
private boolean hasLinkPreview;
|
||||||
|
private int linkPreviewHeight;
|
||||||
|
private boolean isInstagram;
|
||||||
|
private int smallImageX;
|
||||||
|
private int descriptionY;
|
||||||
|
private int durationWidth;
|
||||||
|
private StaticLayout siteNameLayout;
|
||||||
|
private StaticLayout titleLayout;
|
||||||
|
private StaticLayout descriptionLayout;
|
||||||
|
private StaticLayout durationLayout;
|
||||||
|
private StaticLayout authorLayout;
|
||||||
|
private static TextPaint durationPaint;
|
||||||
|
private TLRPC.PhotoSize currentPhotoObject;
|
||||||
|
private TLRPC.PhotoSize currentPhotoObjectThumb;
|
||||||
|
private boolean imageCleared;
|
||||||
|
|
||||||
|
private static Drawable igvideoDrawable;
|
||||||
|
|
||||||
|
private class MyPath extends Path {
|
||||||
|
|
||||||
|
private StaticLayout currentLayout;
|
||||||
|
private int currentLine;
|
||||||
|
private float lastTop = -1;
|
||||||
|
|
||||||
|
public void setCurrentLayout(StaticLayout layout, int start) {
|
||||||
|
currentLayout = layout;
|
||||||
|
currentLine = layout.getLineForOffset(start);
|
||||||
|
lastTop = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addRect(float left, float top, float right, float bottom, Direction dir) {
|
||||||
|
if (lastTop == -1) {
|
||||||
|
lastTop = top;
|
||||||
|
} else if (lastTop != top) {
|
||||||
|
lastTop = top;
|
||||||
|
currentLine++;
|
||||||
|
}
|
||||||
|
float lineRight = currentLayout.getLineRight(currentLine);
|
||||||
|
float lineLeft = currentLayout.getLineLeft(currentLine);
|
||||||
|
if (left >= lineRight) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (right > lineRight) {
|
||||||
|
right = lineRight;
|
||||||
|
}
|
||||||
|
if (left < lineLeft) {
|
||||||
|
left = lineLeft;
|
||||||
|
}
|
||||||
|
super.addRect(left, top, right, bottom, dir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public ChatMessageCell(Context context) {
|
public ChatMessageCell(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
drawForwardedName = true;
|
drawForwardedName = true;
|
||||||
|
linkImageView = new ImageReceiver(this);
|
||||||
|
if (urlPaint == null) {
|
||||||
|
urlPaint = new Paint();
|
||||||
|
urlPaint.setColor(0x33316f9f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void resetPressedLink() {
|
||||||
|
if (pressedLink != null) {
|
||||||
|
pressedLink = null;
|
||||||
|
}
|
||||||
|
linkPreviewPressed = false;
|
||||||
|
invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onTouchEvent(MotionEvent event) {
|
public boolean onTouchEvent(MotionEvent event) {
|
||||||
|
boolean result = false;
|
||||||
if (currentMessageObject != null && currentMessageObject.textLayoutBlocks != null && !currentMessageObject.textLayoutBlocks.isEmpty() && currentMessageObject.messageText instanceof Spannable && !isPressed) {
|
if (currentMessageObject != null && currentMessageObject.textLayoutBlocks != null && !currentMessageObject.textLayoutBlocks.isEmpty() && currentMessageObject.messageText instanceof Spannable && !isPressed) {
|
||||||
if (event.getAction() == MotionEvent.ACTION_DOWN || pressedLink != null && event.getAction() == MotionEvent.ACTION_UP) {
|
if (event.getAction() == MotionEvent.ACTION_DOWN || (linkPreviewPressed || pressedLink != null) && event.getAction() == MotionEvent.ACTION_UP) {
|
||||||
int x = (int)event.getX();
|
int x = (int)event.getX();
|
||||||
int y = (int)event.getY();
|
int y = (int)event.getY();
|
||||||
if (x >= textX && y >= textY && x <= textX + currentMessageObject.textWidth && y <= textY + currentMessageObject.textHeight) {
|
if (x >= textX && y >= textY && x <= textX + currentMessageObject.textWidth && y <= textY + currentMessageObject.textHeight) {
|
||||||
|
@ -54,42 +148,127 @@ public class ChatMessageCell extends ChatBaseCell {
|
||||||
if (left <= x && left + block.textLayout.getLineWidth(line) >= x) {
|
if (left <= x && left + block.textLayout.getLineWidth(line) >= x) {
|
||||||
Spannable buffer = (Spannable)currentMessageObject.messageText;
|
Spannable buffer = (Spannable)currentMessageObject.messageText;
|
||||||
ClickableSpan[] link = buffer.getSpans(off, off, ClickableSpan.class);
|
ClickableSpan[] link = buffer.getSpans(off, off, ClickableSpan.class);
|
||||||
|
|
||||||
if (link.length != 0) {
|
if (link.length != 0) {
|
||||||
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
||||||
|
resetPressedLink();
|
||||||
pressedLink = link[0];
|
pressedLink = link[0];
|
||||||
return true;
|
linkBlockNum = blockNum;
|
||||||
|
try {
|
||||||
|
int start = buffer.getSpanStart(pressedLink) - block.charactersOffset;
|
||||||
|
urlPath.setCurrentLayout(block.textLayout, start);
|
||||||
|
block.textLayout.getSelectionPath(start, buffer.getSpanEnd(pressedLink) - block.charactersOffset, urlPath);
|
||||||
|
} catch (Exception e) {
|
||||||
|
FileLog.e("tmessages", e);
|
||||||
|
}
|
||||||
|
result = true;
|
||||||
} else {
|
} else {
|
||||||
if (link[0] == pressedLink) {
|
if (link[0] == pressedLink) {
|
||||||
try {
|
try {
|
||||||
pressedLink.onClick(this);
|
if (pressedLink instanceof URLSpanNoUnderline) {
|
||||||
|
String url = ((URLSpanNoUnderline) pressedLink).getURL();
|
||||||
|
if (url.startsWith("@") || url.startsWith("#")) {
|
||||||
|
if (delegate != null) {
|
||||||
|
delegate.didPressUrl(url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
pressedLink.onClick(this);
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
FileLog.e("tmessages", e);
|
FileLog.e("tmessages", e);
|
||||||
}
|
}
|
||||||
return true;
|
resetPressedLink();
|
||||||
|
result = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
pressedLink = null;
|
resetPressedLink();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
pressedLink = null;
|
resetPressedLink();
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
pressedLink = null;
|
resetPressedLink();
|
||||||
FileLog.e("tmessages", e);
|
FileLog.e("tmessages", e);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
pressedLink = null;
|
resetPressedLink();
|
||||||
|
}
|
||||||
|
} else if (hasLinkPreview && x >= textX && x <= textX + backgroundWidth && y >= textY + currentMessageObject.textHeight && y <= textY + currentMessageObject.textHeight + linkPreviewHeight + AndroidUtilities.dp(8)) {
|
||||||
|
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
||||||
|
resetPressedLink();
|
||||||
|
if (drawLinkImageView && linkImageView.isInsideImage(x, y)) {
|
||||||
|
linkPreviewPressed = true;
|
||||||
|
result = true;
|
||||||
|
} else {
|
||||||
|
if (descriptionLayout != null && y >= descriptionY) {
|
||||||
|
try {
|
||||||
|
x -= textX + AndroidUtilities.dp(10);
|
||||||
|
y -= descriptionY;
|
||||||
|
final int line = descriptionLayout.getLineForVertical(y);
|
||||||
|
final int off = descriptionLayout.getOffsetForHorizontal(line, x);
|
||||||
|
|
||||||
|
final float left = descriptionLayout.getLineLeft(line);
|
||||||
|
if (left <= x && left + descriptionLayout.getLineWidth(line) >= x) {
|
||||||
|
Spannable buffer = (Spannable) currentMessageObject.linkDescription;
|
||||||
|
ClickableSpan[] link = buffer.getSpans(off, off, ClickableSpan.class);
|
||||||
|
if (link.length != 0) {
|
||||||
|
resetPressedLink();
|
||||||
|
pressedLink = link[0];
|
||||||
|
linkPreviewPressed = true;
|
||||||
|
linkBlockNum = -10;
|
||||||
|
result = true;
|
||||||
|
try {
|
||||||
|
int start = buffer.getSpanStart(pressedLink);
|
||||||
|
urlPath.setCurrentLayout(descriptionLayout, start);
|
||||||
|
descriptionLayout.getSelectionPath(start, buffer.getSpanEnd(pressedLink), urlPath);
|
||||||
|
} catch (Exception e) {
|
||||||
|
FileLog.e("tmessages", e);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
resetPressedLink();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
resetPressedLink();
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
resetPressedLink();
|
||||||
|
FileLog.e("tmessages", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (linkPreviewPressed) {
|
||||||
|
try {
|
||||||
|
if (pressedLink != null) {
|
||||||
|
pressedLink.onClick(this);
|
||||||
|
} else {
|
||||||
|
Uri uri = Uri.parse(currentMessageObject.messageOwner.media.webpage.url);
|
||||||
|
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
|
||||||
|
intent.putExtra(Browser.EXTRA_APPLICATION_ID, getContext().getPackageName());
|
||||||
|
getContext().startActivity(intent);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
FileLog.e("tmessages", e);
|
||||||
|
}
|
||||||
|
resetPressedLink();
|
||||||
|
result = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
pressedLink = null;
|
resetPressedLink();
|
||||||
}
|
}
|
||||||
|
} else if (event.getAction() == MotionEvent.ACTION_CANCEL) {
|
||||||
|
resetPressedLink();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
pressedLink = null;
|
resetPressedLink();
|
||||||
}
|
}
|
||||||
return super.onTouchEvent(event);
|
if (result && event.getAction() == MotionEvent.ACTION_DOWN) {
|
||||||
|
startCheckLongPress();
|
||||||
|
}
|
||||||
|
if (event.getAction() != MotionEvent.ACTION_DOWN && event.getAction() != MotionEvent.ACTION_MOVE) {
|
||||||
|
cancelCheckLongPress();
|
||||||
|
}
|
||||||
|
return result || super.onTouchEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setVisiblePart(int position, int height) {
|
public void setVisiblePart(int position, int height) {
|
||||||
|
@ -127,6 +306,51 @@ public class ChatMessageCell extends ChatBaseCell {
|
||||||
return left1 <= right2;
|
return left1 <= right2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private StaticLayout generateStaticLayout(CharSequence text, TextPaint paint, int maxWidth, int smallWidth, int linesCount, int maxLines) {
|
||||||
|
SpannableStringBuilder stringBuilder = new SpannableStringBuilder(text);
|
||||||
|
int addedChars = 0;
|
||||||
|
StaticLayout layout = new StaticLayout(text, paint, smallWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
|
||||||
|
for (int a = 0; a < linesCount; a++) {
|
||||||
|
int pos = layout.getLineEnd(a);
|
||||||
|
if (pos == text.length()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
pos--;
|
||||||
|
if (stringBuilder.charAt(pos + addedChars) == ' ') {
|
||||||
|
stringBuilder.replace(pos + addedChars, pos + addedChars + 1, "\n");
|
||||||
|
} else {
|
||||||
|
stringBuilder.insert(pos + addedChars, "\n");
|
||||||
|
addedChars++;
|
||||||
|
}
|
||||||
|
if (a == layout.getLineCount() - 1 || a == maxLines - 1) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return StaticLayoutEx.createStaticLayout(stringBuilder, paint, maxWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, AndroidUtilities.dp(1), false, TextUtils.TruncateAt.END, maxWidth, maxLines);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean isUserDataChanged() {
|
||||||
|
if (imageCleared || !hasLinkPreview && currentMessageObject.messageOwner.media != null && currentMessageObject.messageOwner.media.webpage instanceof TLRPC.TL_webPage) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//suppress warning
|
||||||
|
return super.isUserDataChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDetachedFromWindow() {
|
||||||
|
super.onDetachedFromWindow();
|
||||||
|
if (linkImageView != null) {
|
||||||
|
linkImageView.clearImage();
|
||||||
|
if (currentPhotoObject != null) {
|
||||||
|
imageCleared = true;
|
||||||
|
currentPhotoObject = null;
|
||||||
|
currentPhotoObjectThumb = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setMessageObject(MessageObject messageObject) {
|
public void setMessageObject(MessageObject messageObject) {
|
||||||
if (currentMessageObject != messageObject || isUserDataChanged()) {
|
if (currentMessageObject != messageObject || isUserDataChanged()) {
|
||||||
|
@ -134,7 +358,21 @@ public class ChatMessageCell extends ChatBaseCell {
|
||||||
firstVisibleBlockNum = 0;
|
firstVisibleBlockNum = 0;
|
||||||
lastVisibleBlockNum = 0;
|
lastVisibleBlockNum = 0;
|
||||||
}
|
}
|
||||||
pressedLink = null;
|
drawLinkImageView = false;
|
||||||
|
hasLinkPreview = false;
|
||||||
|
resetPressedLink();
|
||||||
|
linkPreviewPressed = false;
|
||||||
|
linkPreviewHeight = 0;
|
||||||
|
smallImageX = 0;
|
||||||
|
isInstagram = false;
|
||||||
|
durationLayout = null;
|
||||||
|
descriptionLayout = null;
|
||||||
|
titleLayout = null;
|
||||||
|
siteNameLayout = null;
|
||||||
|
authorLayout = null;
|
||||||
|
currentPhotoObject = null;
|
||||||
|
imageCleared = false;
|
||||||
|
currentPhotoObjectThumb = null;
|
||||||
int maxWidth;
|
int maxWidth;
|
||||||
|
|
||||||
if (AndroidUtilities.isTablet()) {
|
if (AndroidUtilities.isTablet()) {
|
||||||
|
@ -164,13 +402,223 @@ public class ChatMessageCell extends ChatBaseCell {
|
||||||
|
|
||||||
int maxChildWidth = Math.max(backgroundWidth, nameWidth);
|
int maxChildWidth = Math.max(backgroundWidth, nameWidth);
|
||||||
maxChildWidth = Math.max(maxChildWidth, forwardedNameWidth);
|
maxChildWidth = Math.max(maxChildWidth, forwardedNameWidth);
|
||||||
|
maxChildWidth = Math.max(maxChildWidth, replyNameWidth);
|
||||||
|
maxChildWidth = Math.max(maxChildWidth, replyTextWidth);
|
||||||
|
|
||||||
int timeMore = timeWidth + AndroidUtilities.dp(6);
|
int timeMore = timeWidth + AndroidUtilities.dp(6);
|
||||||
if (messageObject.isOut()) {
|
if (messageObject.isOut()) {
|
||||||
timeMore += AndroidUtilities.dp(20.5f);
|
timeMore += AndroidUtilities.dp(20.5f);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (maxWidth - messageObject.lastLineWidth < timeMore) {
|
if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaWebPage && messageObject.messageOwner.media.webpage instanceof TLRPC.TL_webPage) {
|
||||||
|
int linkPreviewMaxWidth;
|
||||||
|
if (AndroidUtilities.isTablet()) {
|
||||||
|
if (currentMessageObject.messageOwner.to_id.chat_id != 0 && !currentMessageObject.isOut()) {
|
||||||
|
linkPreviewMaxWidth = AndroidUtilities.getMinTabletSide() - AndroidUtilities.dp(122);
|
||||||
|
} else {
|
||||||
|
linkPreviewMaxWidth = AndroidUtilities.getMinTabletSide() - AndroidUtilities.dp(80);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (currentMessageObject.messageOwner.to_id.chat_id != 0 && !currentMessageObject.isOut()) {
|
||||||
|
linkPreviewMaxWidth = Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) - AndroidUtilities.dp(122);
|
||||||
|
} else {
|
||||||
|
linkPreviewMaxWidth = Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) - AndroidUtilities.dp(80);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int additinalWidth = AndroidUtilities.dp(10);
|
||||||
|
int restLinesCount = 3;
|
||||||
|
int additionalHeight = 0;
|
||||||
|
linkPreviewMaxWidth -= additinalWidth;
|
||||||
|
|
||||||
|
hasLinkPreview = true;
|
||||||
|
TLRPC.TL_webPage webPage = (TLRPC.TL_webPage) messageObject.messageOwner.media.webpage;
|
||||||
|
|
||||||
|
if (currentMessageObject.photoThumbs == null && webPage.photo != null) {
|
||||||
|
currentMessageObject.generateThumbs(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (MediaController.getInstance().canDownloadMedia(MediaController.AUTODOWNLOAD_MASK_PHOTO)) {
|
||||||
|
isSmallImage = webPage.description != null && webPage.type != null && (webPage.type.equals("app") || webPage.type.equals("profile") || webPage.type.equals("article")) && currentMessageObject.photoThumbs != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (webPage.site_name != null) {
|
||||||
|
try {
|
||||||
|
int width = (int) Math.ceil(replyNamePaint.measureText(webPage.site_name));
|
||||||
|
siteNameLayout = new StaticLayout(webPage.site_name, replyNamePaint, Math.min(width, linkPreviewMaxWidth), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
|
||||||
|
int height = siteNameLayout.getLineBottom(siteNameLayout.getLineCount() - 1);
|
||||||
|
linkPreviewHeight += height;
|
||||||
|
totalHeight += height;
|
||||||
|
additionalHeight += height;
|
||||||
|
maxChildWidth = Math.max(maxChildWidth, width + additinalWidth);
|
||||||
|
} catch (Exception e) {
|
||||||
|
FileLog.e("tmessages", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (webPage.title != null) {
|
||||||
|
try {
|
||||||
|
if (linkPreviewHeight != 0) {
|
||||||
|
linkPreviewHeight += AndroidUtilities.dp(2);
|
||||||
|
totalHeight += AndroidUtilities.dp(2);
|
||||||
|
}
|
||||||
|
int restLines = 0;
|
||||||
|
if (!isSmallImage || webPage.description == null) {
|
||||||
|
titleLayout = StaticLayoutEx.createStaticLayout(webPage.title, replyNamePaint, linkPreviewMaxWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, AndroidUtilities.dp(1), false, TextUtils.TruncateAt.END, linkPreviewMaxWidth, 2);
|
||||||
|
} else {
|
||||||
|
restLines = restLinesCount;
|
||||||
|
titleLayout = generateStaticLayout(webPage.title, replyNamePaint, linkPreviewMaxWidth, linkPreviewMaxWidth - AndroidUtilities.dp(48 + 2), restLinesCount, 2);
|
||||||
|
restLinesCount -= titleLayout.getLineCount();
|
||||||
|
}
|
||||||
|
int height = titleLayout.getLineBottom(titleLayout.getLineCount() - 1);
|
||||||
|
linkPreviewHeight += height;
|
||||||
|
totalHeight += height;
|
||||||
|
for (int a = 0; a < titleLayout.getLineCount(); a++) {
|
||||||
|
int width = (int) Math.ceil(titleLayout.getLineWidth(a));
|
||||||
|
if (a < restLines) {
|
||||||
|
smallImageX = Math.max(smallImageX, width);
|
||||||
|
width += AndroidUtilities.dp(48 + 2);
|
||||||
|
}
|
||||||
|
maxChildWidth = Math.max(maxChildWidth, width + additinalWidth);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
FileLog.e("tmessages", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (webPage.author != null) {
|
||||||
|
try {
|
||||||
|
if (linkPreviewHeight != 0) {
|
||||||
|
linkPreviewHeight += AndroidUtilities.dp(2);
|
||||||
|
totalHeight += AndroidUtilities.dp(2);
|
||||||
|
}
|
||||||
|
int width = Math.min((int) Math.ceil(replyNamePaint.measureText(webPage.author)), linkPreviewMaxWidth);
|
||||||
|
if (restLinesCount == 3 && (!isSmallImage || webPage.description == null)) {
|
||||||
|
authorLayout = new StaticLayout(webPage.author, replyNamePaint, width, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
|
||||||
|
} else {
|
||||||
|
authorLayout = generateStaticLayout(webPage.author, replyNamePaint, width, linkPreviewMaxWidth - AndroidUtilities.dp(48 + 2), restLinesCount, 1);
|
||||||
|
restLinesCount -= authorLayout.getLineCount();
|
||||||
|
}
|
||||||
|
int height = authorLayout.getLineBottom(authorLayout.getLineCount() - 1);
|
||||||
|
linkPreviewHeight += height;
|
||||||
|
totalHeight += height;
|
||||||
|
maxChildWidth = Math.max(maxChildWidth, width + additinalWidth);
|
||||||
|
} catch (Exception e) {
|
||||||
|
FileLog.e("tmessages", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (webPage.description != null) {
|
||||||
|
try {
|
||||||
|
currentMessageObject.generateLinkDescription();
|
||||||
|
if (linkPreviewHeight != 0) {
|
||||||
|
linkPreviewHeight += AndroidUtilities.dp(2);
|
||||||
|
totalHeight += AndroidUtilities.dp(2);
|
||||||
|
}
|
||||||
|
int restLines = 0;
|
||||||
|
if (restLinesCount == 3 && !isSmallImage) {
|
||||||
|
descriptionLayout = StaticLayoutEx.createStaticLayout(messageObject.linkDescription, replyTextPaint, linkPreviewMaxWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, AndroidUtilities.dp(1), false, TextUtils.TruncateAt.END, linkPreviewMaxWidth, 6);
|
||||||
|
} else {
|
||||||
|
restLines = restLinesCount;
|
||||||
|
descriptionLayout = generateStaticLayout(messageObject.linkDescription, replyTextPaint, linkPreviewMaxWidth, linkPreviewMaxWidth - AndroidUtilities.dp(48 + 2), restLinesCount, 6);
|
||||||
|
}
|
||||||
|
int height = descriptionLayout.getLineBottom(descriptionLayout.getLineCount() - 1);
|
||||||
|
linkPreviewHeight += height;
|
||||||
|
totalHeight += height;
|
||||||
|
for (int a = 0; a < descriptionLayout.getLineCount(); a++) {
|
||||||
|
int width = (int) Math.ceil(descriptionLayout.getLineWidth(a));
|
||||||
|
if (a < restLines) {
|
||||||
|
smallImageX = Math.max(smallImageX, width);
|
||||||
|
width += AndroidUtilities.dp(48 + 2);
|
||||||
|
}
|
||||||
|
maxChildWidth = Math.max(maxChildWidth, width + additinalWidth);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
FileLog.e("tmessages", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (webPage.photo != null && MediaController.getInstance().canDownloadMedia(MediaController.AUTODOWNLOAD_MASK_PHOTO)) {
|
||||||
|
boolean smallImage = webPage.type != null && (webPage.type.equals("app") || webPage.type.equals("profile") || webPage.type.equals("article"));
|
||||||
|
if (smallImage && descriptionLayout != null && descriptionLayout.getLineCount() == 1) {
|
||||||
|
smallImage = false;
|
||||||
|
isSmallImage = false;
|
||||||
|
}
|
||||||
|
int maxPhotoWidth = smallImage ? AndroidUtilities.dp(48) : linkPreviewMaxWidth;
|
||||||
|
currentPhotoObject = FileLoader.getClosestPhotoSizeWithSize(messageObject.photoThumbs, maxPhotoWidth);
|
||||||
|
currentPhotoObjectThumb = FileLoader.getClosestPhotoSizeWithSize(messageObject.photoThumbs, 80);
|
||||||
|
if (currentPhotoObjectThumb == currentPhotoObject) {
|
||||||
|
currentPhotoObjectThumb = null;
|
||||||
|
}
|
||||||
|
if (currentPhotoObject != null) {
|
||||||
|
if (linkPreviewHeight != 0) {
|
||||||
|
linkPreviewHeight += AndroidUtilities.dp(2);
|
||||||
|
totalHeight += AndroidUtilities.dp(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
maxChildWidth = Math.max(maxChildWidth, maxPhotoWidth + additinalWidth);
|
||||||
|
currentPhotoObject.size = -1;
|
||||||
|
if (currentPhotoObjectThumb != null) {
|
||||||
|
currentPhotoObjectThumb.size = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int width;
|
||||||
|
int height;
|
||||||
|
if (smallImage) {
|
||||||
|
width = height = maxPhotoWidth;
|
||||||
|
} else {
|
||||||
|
width = currentPhotoObject.w;
|
||||||
|
height = currentPhotoObject.h;
|
||||||
|
float scale = width / (float) maxPhotoWidth;
|
||||||
|
width /= scale;
|
||||||
|
height /= scale;
|
||||||
|
if (height > AndroidUtilities.displaySize.y / 3) {
|
||||||
|
height = AndroidUtilities.displaySize.y / 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isSmallImage) {
|
||||||
|
if (AndroidUtilities.dp(50) + additionalHeight > linkPreviewHeight) {
|
||||||
|
totalHeight += AndroidUtilities.dp(50) + additionalHeight - linkPreviewHeight + AndroidUtilities.dp(8);
|
||||||
|
linkPreviewHeight = AndroidUtilities.dp(50) + additionalHeight;
|
||||||
|
}
|
||||||
|
linkPreviewHeight -= AndroidUtilities.dp(8);
|
||||||
|
} else {
|
||||||
|
totalHeight += height + AndroidUtilities.dp(12);
|
||||||
|
linkPreviewHeight += height;
|
||||||
|
}
|
||||||
|
|
||||||
|
linkImageView.setImageCoords(0, 0, width, height);
|
||||||
|
linkImageView.setImage(currentPhotoObject.location, String.format(Locale.US, "%d_%d", width, height), currentPhotoObjectThumb != null ? currentPhotoObjectThumb.location : null, String.format(Locale.US, "%d_%d_b", width, height), 0, false);
|
||||||
|
drawLinkImageView = true;
|
||||||
|
|
||||||
|
if (webPage.site_name != null) {
|
||||||
|
if (webPage.site_name.toLowerCase().equals("instagram") && webPage.type != null && webPage.type.equals("video")) {
|
||||||
|
isInstagram = true;
|
||||||
|
if (igvideoDrawable == null) {
|
||||||
|
igvideoDrawable = getResources().getDrawable(R.drawable.igvideo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (webPage.duration != 0) {
|
||||||
|
if (durationPaint == null) {
|
||||||
|
durationPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
|
||||||
|
durationPaint.setTextSize(AndroidUtilities.dp(12));
|
||||||
|
durationPaint.setColor(0xffffffff);
|
||||||
|
}
|
||||||
|
int minutes = webPage.duration / 60;
|
||||||
|
int seconds = webPage.duration - minutes * 60;
|
||||||
|
String str = String.format("%d:%02d", minutes, seconds);
|
||||||
|
durationWidth = (int) Math.ceil(durationPaint.measureText(str));
|
||||||
|
durationLayout = new StaticLayout(str, durationPaint, durationWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
linkPreviewHeight -= AndroidUtilities.dp(6);
|
||||||
|
totalHeight += AndroidUtilities.dp(4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasLinkPreview || maxWidth - messageObject.lastLineWidth < timeMore) {
|
||||||
totalHeight += AndroidUtilities.dp(14);
|
totalHeight += AndroidUtilities.dp(14);
|
||||||
backgroundWidth = Math.max(maxChildWidth, messageObject.lastLineWidth) + AndroidUtilities.dp(29);
|
backgroundWidth = Math.max(maxChildWidth, messageObject.lastLineWidth) + AndroidUtilities.dp(29);
|
||||||
} else {
|
} else {
|
||||||
|
@ -205,7 +653,7 @@ public class ChatMessageCell extends ChatBaseCell {
|
||||||
@Override
|
@Override
|
||||||
protected void onDraw(Canvas canvas) {
|
protected void onDraw(Canvas canvas) {
|
||||||
super.onDraw(canvas);
|
super.onDraw(canvas);
|
||||||
if (currentMessageObject == null || currentMessageObject.textLayoutBlocks == null || currentMessageObject.textLayoutBlocks.isEmpty() || firstVisibleBlockNum < 0) {
|
if (currentMessageObject == null || currentMessageObject.textLayoutBlocks == null || currentMessageObject.textLayoutBlocks.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,19 +665,121 @@ public class ChatMessageCell extends ChatBaseCell {
|
||||||
textY = AndroidUtilities.dp(10) + namesOffset;
|
textY = AndroidUtilities.dp(10) + namesOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int a = firstVisibleBlockNum; a <= lastVisibleBlockNum; a++) {
|
if (firstVisibleBlockNum >= 0) {
|
||||||
if (a >= currentMessageObject.textLayoutBlocks.size()) {
|
for (int a = firstVisibleBlockNum; a <= lastVisibleBlockNum; a++) {
|
||||||
break;
|
if (a >= currentMessageObject.textLayoutBlocks.size()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
MessageObject.TextLayoutBlock block = currentMessageObject.textLayoutBlocks.get(a);
|
||||||
|
canvas.save();
|
||||||
|
canvas.translate(textX - (int) Math.ceil(block.textXOffset), textY + block.textYOffset);
|
||||||
|
if (pressedLink != null && a == linkBlockNum) {
|
||||||
|
canvas.drawPath(urlPath, urlPaint);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
block.textLayout.draw(canvas);
|
||||||
|
} catch (Exception e) {
|
||||||
|
FileLog.e("tmessages", e);
|
||||||
|
}
|
||||||
|
canvas.restore();
|
||||||
}
|
}
|
||||||
MessageObject.TextLayoutBlock block = currentMessageObject.textLayoutBlocks.get(a);
|
}
|
||||||
canvas.save();
|
|
||||||
canvas.translate(textX - (int)Math.ceil(block.textXOffset), textY + block.textYOffset);
|
if (hasLinkPreview) {
|
||||||
try {
|
int startY = textY + currentMessageObject.textHeight + AndroidUtilities.dp(8);
|
||||||
block.textLayout.draw(canvas);
|
int linkPreviewY = startY;
|
||||||
} catch (Exception e) {
|
int smallImageStartY = 0;
|
||||||
FileLog.e("tmessages", e);
|
replyLinePaint.setColor(currentMessageObject.isOut() ? 0xff8dc97a : 0xff6c9fd2);
|
||||||
|
|
||||||
|
canvas.drawRect(textX, linkPreviewY - AndroidUtilities.dp(3), textX + AndroidUtilities.dp(2), linkPreviewY + linkPreviewHeight + AndroidUtilities.dp(3), replyLinePaint);
|
||||||
|
|
||||||
|
if (siteNameLayout != null) {
|
||||||
|
replyNamePaint.setColor(currentMessageObject.isOut() ? 0xff70b15c : 0xff4b91cf);
|
||||||
|
canvas.save();
|
||||||
|
canvas.translate(textX + AndroidUtilities.dp(10), linkPreviewY - AndroidUtilities.dp(3));
|
||||||
|
siteNameLayout.draw(canvas);
|
||||||
|
canvas.restore();
|
||||||
|
linkPreviewY += siteNameLayout.getLineBottom(siteNameLayout.getLineCount() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (titleLayout != null) {
|
||||||
|
if (linkPreviewY != startY) {
|
||||||
|
linkPreviewY += AndroidUtilities.dp(2);
|
||||||
|
}
|
||||||
|
replyNamePaint.setColor(0xff000000);
|
||||||
|
smallImageStartY = linkPreviewY - AndroidUtilities.dp(1);
|
||||||
|
canvas.save();
|
||||||
|
canvas.translate(textX + AndroidUtilities.dp(10), linkPreviewY - AndroidUtilities.dp(3));
|
||||||
|
titleLayout.draw(canvas);
|
||||||
|
canvas.restore();
|
||||||
|
linkPreviewY += titleLayout.getLineBottom(titleLayout.getLineCount() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (authorLayout != null) {
|
||||||
|
if (linkPreviewY != startY) {
|
||||||
|
linkPreviewY += AndroidUtilities.dp(2);
|
||||||
|
}
|
||||||
|
if (smallImageStartY == 0) {
|
||||||
|
smallImageStartY = linkPreviewY - AndroidUtilities.dp(1);
|
||||||
|
}
|
||||||
|
replyNamePaint.setColor(0xff000000);
|
||||||
|
canvas.save();
|
||||||
|
canvas.translate(textX + AndroidUtilities.dp(10), linkPreviewY - AndroidUtilities.dp(3));
|
||||||
|
authorLayout.draw(canvas);
|
||||||
|
canvas.restore();
|
||||||
|
linkPreviewY += authorLayout.getLineBottom(authorLayout.getLineCount() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (descriptionLayout != null) {
|
||||||
|
if (linkPreviewY != startY) {
|
||||||
|
linkPreviewY += AndroidUtilities.dp(2);
|
||||||
|
}
|
||||||
|
if (smallImageStartY == 0) {
|
||||||
|
smallImageStartY = linkPreviewY - AndroidUtilities.dp(1);
|
||||||
|
}
|
||||||
|
replyTextPaint.setColor(0xff000000);
|
||||||
|
descriptionY = linkPreviewY - AndroidUtilities.dp(3);
|
||||||
|
canvas.save();
|
||||||
|
canvas.translate(textX + AndroidUtilities.dp(10), descriptionY);
|
||||||
|
if (pressedLink != null && linkBlockNum == -10) {
|
||||||
|
canvas.drawPath(urlPath, urlPaint);
|
||||||
|
}
|
||||||
|
descriptionLayout.draw(canvas);
|
||||||
|
canvas.restore();
|
||||||
|
linkPreviewY += descriptionLayout.getLineBottom(descriptionLayout.getLineCount() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (drawLinkImageView) {
|
||||||
|
if (linkPreviewY != startY) {
|
||||||
|
linkPreviewY += AndroidUtilities.dp(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isSmallImage) {
|
||||||
|
linkImageView.setImageCoords(textX + smallImageX + AndroidUtilities.dp(12), smallImageStartY, linkImageView.getImageWidth(), linkImageView.getImageHeight());
|
||||||
|
} else {
|
||||||
|
linkImageView.setImageCoords(textX + AndroidUtilities.dp(10), linkPreviewY, linkImageView.getImageWidth(), linkImageView.getImageHeight());
|
||||||
|
}
|
||||||
|
linkImageView.draw(canvas);
|
||||||
|
|
||||||
|
if (isInstagram && igvideoDrawable != null) {
|
||||||
|
int x = linkImageView.getImageX() + linkImageView.getImageWidth() - igvideoDrawable.getIntrinsicWidth() - AndroidUtilities.dp(4);
|
||||||
|
int y = linkImageView.getImageY() + AndroidUtilities.dp(4);
|
||||||
|
igvideoDrawable.setBounds(x, y, x + igvideoDrawable.getIntrinsicWidth(), y + igvideoDrawable.getIntrinsicHeight());
|
||||||
|
igvideoDrawable.draw(canvas);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (durationLayout != null) {
|
||||||
|
int x = linkImageView.getImageX() + linkImageView.getImageWidth() - AndroidUtilities.dp(8) - durationWidth;
|
||||||
|
int y = linkImageView.getImageY() + linkImageView.getImageHeight() - AndroidUtilities.dp(19);
|
||||||
|
mediaBackgroundDrawable.setBounds(x - AndroidUtilities.dp(4), y - AndroidUtilities.dp(1.5f), x + durationWidth + AndroidUtilities.dp(4), y + AndroidUtilities.dp(14.5f));
|
||||||
|
mediaBackgroundDrawable.draw(canvas);
|
||||||
|
|
||||||
|
canvas.save();
|
||||||
|
canvas.translate(x, y);
|
||||||
|
durationLayout.draw(canvas);
|
||||||
|
canvas.restore();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
canvas.restore();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,6 @@ import android.content.Context;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.text.Html;
|
|
||||||
import android.text.Layout;
|
import android.text.Layout;
|
||||||
import android.text.StaticLayout;
|
import android.text.StaticLayout;
|
||||||
import android.text.TextPaint;
|
import android.text.TextPaint;
|
||||||
|
@ -55,12 +54,15 @@ public class DialogCell extends BaseCell {
|
||||||
private static Paint linePaint;
|
private static Paint linePaint;
|
||||||
|
|
||||||
private long currentDialogId;
|
private long currentDialogId;
|
||||||
private boolean allowPrintStrings;
|
private boolean isDialogCell;
|
||||||
private int lastMessageDate;
|
private int lastMessageDate;
|
||||||
private int unreadCount;
|
private int unreadCount;
|
||||||
private boolean lastUnreadState;
|
private boolean lastUnreadState;
|
||||||
|
private int lastSendState;
|
||||||
private boolean dialogMuted;
|
private boolean dialogMuted;
|
||||||
private MessageObject message;
|
private MessageObject message;
|
||||||
|
private int index;
|
||||||
|
private boolean isServerOnly;
|
||||||
|
|
||||||
private ImageReceiver avatarImage;
|
private ImageReceiver avatarImage;
|
||||||
private AvatarDrawable avatarDrawable;
|
private AvatarDrawable avatarDrawable;
|
||||||
|
@ -129,6 +131,7 @@ public class DialogCell extends BaseCell {
|
||||||
messagePaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
|
messagePaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
|
||||||
messagePaint.setTextSize(AndroidUtilities.dp(16));
|
messagePaint.setTextSize(AndroidUtilities.dp(16));
|
||||||
messagePaint.setColor(0xff8f8f8f);
|
messagePaint.setColor(0xff8f8f8f);
|
||||||
|
messagePaint.linkColor = 0xff8f8f8f;
|
||||||
|
|
||||||
linePaint = new Paint();
|
linePaint = new Paint();
|
||||||
linePaint.setColor(0xffdcdcdc);
|
linePaint.setColor(0xffdcdcdc);
|
||||||
|
@ -166,14 +169,24 @@ public class DialogCell extends BaseCell {
|
||||||
avatarDrawable = new AvatarDrawable();
|
avatarDrawable = new AvatarDrawable();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDialog(long dialog_id, MessageObject messageObject, boolean usePrintStrings, int date, int unread, boolean muted) {
|
public void setDialog(TLRPC.TL_dialog dialog, int i, boolean server) {
|
||||||
|
currentDialogId = dialog.id;
|
||||||
|
isDialogCell = true;
|
||||||
|
index = i;
|
||||||
|
isServerOnly = server;
|
||||||
|
update(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDialog(long dialog_id, MessageObject messageObject, int date) {
|
||||||
currentDialogId = dialog_id;
|
currentDialogId = dialog_id;
|
||||||
message = messageObject;
|
message = messageObject;
|
||||||
allowPrintStrings = usePrintStrings;
|
isDialogCell = false;
|
||||||
lastMessageDate = date;
|
lastMessageDate = date;
|
||||||
unreadCount = unread;
|
unreadCount = 0;
|
||||||
dialogMuted = muted;
|
|
||||||
lastUnreadState = messageObject != null && messageObject.isUnread();
|
lastUnreadState = messageObject != null && messageObject.isUnread();
|
||||||
|
if (message != null) {
|
||||||
|
lastSendState = message.messageOwner.send_state;
|
||||||
|
}
|
||||||
update(0);
|
update(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -211,7 +224,7 @@ public class DialogCell extends BaseCell {
|
||||||
String countString = null;
|
String countString = null;
|
||||||
CharSequence messageString = "";
|
CharSequence messageString = "";
|
||||||
CharSequence printingString = null;
|
CharSequence printingString = null;
|
||||||
if (allowPrintStrings) {
|
if (isDialogCell) {
|
||||||
printingString = MessagesController.getInstance().printingStrings.get(currentDialogId);
|
printingString = MessagesController.getInstance().printingStrings.get(currentDialogId);
|
||||||
}
|
}
|
||||||
TextPaint currentNamePaint = namePaint;
|
TextPaint currentNamePaint = namePaint;
|
||||||
|
@ -226,10 +239,10 @@ public class DialogCell extends BaseCell {
|
||||||
drawNameLock = true;
|
drawNameLock = true;
|
||||||
nameLockTop = AndroidUtilities.dp(16.5f);
|
nameLockTop = AndroidUtilities.dp(16.5f);
|
||||||
if (!LocaleController.isRTL) {
|
if (!LocaleController.isRTL) {
|
||||||
nameLockLeft = AndroidUtilities.dp(72);
|
nameLockLeft = AndroidUtilities.dp(AndroidUtilities.leftBaseline);
|
||||||
nameLeft = AndroidUtilities.dp(76) + lockDrawable.getIntrinsicWidth();
|
nameLeft = AndroidUtilities.dp(AndroidUtilities.leftBaseline + 4) + lockDrawable.getIntrinsicWidth();
|
||||||
} else {
|
} else {
|
||||||
nameLockLeft = getMeasuredWidth() - AndroidUtilities.dp(72) - lockDrawable.getIntrinsicWidth();
|
nameLockLeft = getMeasuredWidth() - AndroidUtilities.dp(AndroidUtilities.leftBaseline) - lockDrawable.getIntrinsicWidth();
|
||||||
nameLeft = AndroidUtilities.dp(14);
|
nameLeft = AndroidUtilities.dp(14);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -243,15 +256,15 @@ public class DialogCell extends BaseCell {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!LocaleController.isRTL) {
|
if (!LocaleController.isRTL) {
|
||||||
nameLockLeft = AndroidUtilities.dp(72);
|
nameLockLeft = AndroidUtilities.dp(AndroidUtilities.leftBaseline);
|
||||||
nameLeft = AndroidUtilities.dp(76) + (drawNameGroup ? groupDrawable.getIntrinsicWidth() : broadcastDrawable.getIntrinsicWidth());
|
nameLeft = AndroidUtilities.dp(AndroidUtilities.leftBaseline + 4) + (drawNameGroup ? groupDrawable.getIntrinsicWidth() : broadcastDrawable.getIntrinsicWidth());
|
||||||
} else {
|
} else {
|
||||||
nameLockLeft = getMeasuredWidth() - AndroidUtilities.dp(72) - (drawNameGroup ? groupDrawable.getIntrinsicWidth() : broadcastDrawable.getIntrinsicWidth());
|
nameLockLeft = getMeasuredWidth() - AndroidUtilities.dp(AndroidUtilities.leftBaseline) - (drawNameGroup ? groupDrawable.getIntrinsicWidth() : broadcastDrawable.getIntrinsicWidth());
|
||||||
nameLeft = AndroidUtilities.dp(14);
|
nameLeft = AndroidUtilities.dp(14);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!LocaleController.isRTL) {
|
if (!LocaleController.isRTL) {
|
||||||
nameLeft = AndroidUtilities.dp(72);
|
nameLeft = AndroidUtilities.dp(AndroidUtilities.leftBaseline);
|
||||||
} else {
|
} else {
|
||||||
nameLeft = AndroidUtilities.dp(14);
|
nameLeft = AndroidUtilities.dp(14);
|
||||||
}
|
}
|
||||||
|
@ -316,7 +329,7 @@ public class DialogCell extends BaseCell {
|
||||||
} else {
|
} else {
|
||||||
if (chat != null && chat.id > 0) {
|
if (chat != null && chat.id > 0) {
|
||||||
String name = "";
|
String name = "";
|
||||||
if (message.isFromMe()) {
|
if (message.isOut()) {
|
||||||
name = LocaleController.getString("FromYou", R.string.FromYou);
|
name = LocaleController.getString("FromYou", R.string.FromYou);
|
||||||
} else {
|
} else {
|
||||||
if (fromUser != null) {
|
if (fromUser != null) {
|
||||||
|
@ -328,9 +341,9 @@ public class DialogCell extends BaseCell {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
checkMessage = false;
|
checkMessage = false;
|
||||||
if (message.messageOwner.media != null && !(message.messageOwner.media instanceof TLRPC.TL_messageMediaEmpty)) {
|
if (message.messageOwner.media != null && !message.isMediaEmpty()) {
|
||||||
currentMessagePaint = messagePrintingPaint;
|
currentMessagePaint = messagePrintingPaint;
|
||||||
messageString = Emoji.replaceEmoji(Html.fromHtml(String.format("<font color=#4d83b3>%s:</font> <font color=#4d83b3>%s</font>", name, message.messageText)), messagePaint.getFontMetricsInt(), AndroidUtilities.dp(20));
|
messageString = Emoji.replaceEmoji(AndroidUtilities.replaceTags(String.format("<c#ff4d83b3>%s:</c> <c#ff4d83b3>%s</c>", name, message.messageText)), messagePaint.getFontMetricsInt(), AndroidUtilities.dp(20));
|
||||||
} else {
|
} else {
|
||||||
if (message.messageOwner.message != null) {
|
if (message.messageOwner.message != null) {
|
||||||
String mess = message.messageOwner.message;
|
String mess = message.messageOwner.message;
|
||||||
|
@ -338,12 +351,12 @@ public class DialogCell extends BaseCell {
|
||||||
mess = mess.substring(0, 150);
|
mess = mess.substring(0, 150);
|
||||||
}
|
}
|
||||||
mess = mess.replace("\n", " ");
|
mess = mess.replace("\n", " ");
|
||||||
messageString = Emoji.replaceEmoji(Html.fromHtml(String.format("<font color=#4d83b3>%s:</font> <font color=#808080>%s</font>", name, mess.replace("<", "<").replace(">", ">"))), messagePaint.getFontMetricsInt(), AndroidUtilities.dp(20));
|
messageString = Emoji.replaceEmoji(AndroidUtilities.replaceTags(String.format("<c#ff4d83b3>%s:</c> <c#ff808080>%s</c>", name, mess.replace("<", "<").replace(">", ">"))), messagePaint.getFontMetricsInt(), AndroidUtilities.dp(20));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
messageString = message.messageText;
|
messageString = message.messageText;
|
||||||
if (message.messageOwner.media != null && !(message.messageOwner.media instanceof TLRPC.TL_messageMediaEmpty)) {
|
if (message.messageOwner.media != null && !message.isMediaEmpty()) {
|
||||||
currentMessagePaint = messagePrintingPaint;
|
currentMessagePaint = messagePrintingPaint;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -357,7 +370,7 @@ public class DialogCell extends BaseCell {
|
||||||
drawCount = false;
|
drawCount = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message.isFromMe() && message.isOut()) {
|
if (message.isOut()) {
|
||||||
if (message.isSending()) {
|
if (message.isSending()) {
|
||||||
drawCheck1 = false;
|
drawCheck1 = false;
|
||||||
drawCheck2 = false;
|
drawCheck2 = false;
|
||||||
|
@ -426,7 +439,7 @@ public class DialogCell extends BaseCell {
|
||||||
if (!LocaleController.isRTL) {
|
if (!LocaleController.isRTL) {
|
||||||
nameWidth = getMeasuredWidth() - nameLeft - AndroidUtilities.dp(14) - timeWidth;
|
nameWidth = getMeasuredWidth() - nameLeft - AndroidUtilities.dp(14) - timeWidth;
|
||||||
} else {
|
} else {
|
||||||
nameWidth = getMeasuredWidth() - nameLeft - AndroidUtilities.dp(72) - timeWidth;
|
nameWidth = getMeasuredWidth() - nameLeft - AndroidUtilities.dp(AndroidUtilities.leftBaseline) - timeWidth;
|
||||||
nameLeft += timeWidth;
|
nameLeft += timeWidth;
|
||||||
}
|
}
|
||||||
if (drawNameLock) {
|
if (drawNameLock) {
|
||||||
|
@ -484,14 +497,14 @@ public class DialogCell extends BaseCell {
|
||||||
FileLog.e("tmessages", e);
|
FileLog.e("tmessages", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
int messageWidth = getMeasuredWidth() - AndroidUtilities.dp(88);
|
int messageWidth = getMeasuredWidth() - AndroidUtilities.dp(AndroidUtilities.leftBaseline + 16);
|
||||||
int avatarLeft;
|
int avatarLeft;
|
||||||
if (!LocaleController.isRTL) {
|
if (!LocaleController.isRTL) {
|
||||||
messageLeft = AndroidUtilities.dp(72);
|
messageLeft = AndroidUtilities.dp(AndroidUtilities.leftBaseline);
|
||||||
avatarLeft = AndroidUtilities.dp(9);
|
avatarLeft = AndroidUtilities.dp(AndroidUtilities.isTablet() ? 13 : 9);
|
||||||
} else {
|
} else {
|
||||||
messageLeft = AndroidUtilities.dp(16);
|
messageLeft = AndroidUtilities.dp(16);
|
||||||
avatarLeft = getMeasuredWidth() - AndroidUtilities.dp(61);
|
avatarLeft = getMeasuredWidth() - AndroidUtilities.dp(AndroidUtilities.isTablet() ? 65 : 61);
|
||||||
}
|
}
|
||||||
avatarImage.setImageCoords(avatarLeft, avatarTop, AndroidUtilities.dp(52), AndroidUtilities.dp(52));
|
avatarImage.setImageCoords(avatarLeft, avatarTop, AndroidUtilities.dp(52), AndroidUtilities.dp(52));
|
||||||
if (drawError) {
|
if (drawError) {
|
||||||
|
@ -543,15 +556,15 @@ public class DialogCell extends BaseCell {
|
||||||
if (LocaleController.isRTL) {
|
if (LocaleController.isRTL) {
|
||||||
if (nameLayout != null && nameLayout.getLineCount() > 0) {
|
if (nameLayout != null && nameLayout.getLineCount() > 0) {
|
||||||
left = nameLayout.getLineLeft(0);
|
left = nameLayout.getLineLeft(0);
|
||||||
|
widthpx = Math.ceil(nameLayout.getLineWidth(0));
|
||||||
|
if (dialogMuted) {
|
||||||
|
nameMuteLeft = (int) (nameLeft + (nameWidth - widthpx) - AndroidUtilities.dp(6) - muteDrawable.getIntrinsicWidth());
|
||||||
|
}
|
||||||
if (left == 0) {
|
if (left == 0) {
|
||||||
widthpx = Math.ceil(nameLayout.getLineWidth(0));
|
|
||||||
if (widthpx < nameWidth) {
|
if (widthpx < nameWidth) {
|
||||||
nameLeft += (nameWidth - widthpx);
|
nameLeft += (nameWidth - widthpx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (dialogMuted) {
|
|
||||||
nameMuteLeft = (nameLeft - AndroidUtilities.dp(6) - muteDrawable.getIntrinsicWidth());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (messageLayout != null && messageLayout.getLineCount() > 0) {
|
if (messageLayout != null && messageLayout.getLineCount() > 0) {
|
||||||
left = messageLayout.getLineLeft(0);
|
left = messageLayout.getLineLeft(0);
|
||||||
|
@ -587,10 +600,42 @@ public class DialogCell extends BaseCell {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void checkCurrentDialogIndex() {
|
||||||
|
TLRPC.TL_dialog dialog = null;
|
||||||
|
if (isServerOnly) {
|
||||||
|
if (index < MessagesController.getInstance().dialogsServerOnly.size()) {
|
||||||
|
dialog = MessagesController.getInstance().dialogsServerOnly.get(index);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (index < MessagesController.getInstance().dialogs.size()) {
|
||||||
|
dialog = MessagesController.getInstance().dialogs.get(index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (dialog != null) {
|
||||||
|
if (currentDialogId != dialog.id || message != null && message.getId() != dialog.top_message || unreadCount != dialog.unread_count) {
|
||||||
|
currentDialogId = dialog.id;
|
||||||
|
update(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void update(int mask) {
|
public void update(int mask) {
|
||||||
|
if (isDialogCell) {
|
||||||
|
TLRPC.TL_dialog dialog = MessagesController.getInstance().dialogs_dict.get(currentDialogId);
|
||||||
|
if (dialog != null && mask == 0) {
|
||||||
|
message = MessagesController.getInstance().dialogMessage.get(dialog.top_message);
|
||||||
|
lastUnreadState = message != null && message.isUnread();
|
||||||
|
unreadCount = dialog.unread_count;
|
||||||
|
lastMessageDate = dialog.last_message_date;
|
||||||
|
if (message != null) {
|
||||||
|
lastSendState = message.messageOwner.send_state;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (mask != 0) {
|
if (mask != 0) {
|
||||||
boolean continueUpdate = false;
|
boolean continueUpdate = false;
|
||||||
if (allowPrintStrings && (mask & MessagesController.UPDATE_MASK_USER_PRINT) != 0) {
|
if (isDialogCell && (mask & MessagesController.UPDATE_MASK_USER_PRINT) != 0) {
|
||||||
CharSequence printString = MessagesController.getInstance().printingStrings.get(currentDialogId);
|
CharSequence printString = MessagesController.getInstance().printingStrings.get(currentDialogId);
|
||||||
if (lastPrintString != null && printString == null || lastPrintString == null && printString != null || lastPrintString != null && printString != null && !lastPrintString.equals(printString)) {
|
if (lastPrintString != null && printString == null || lastPrintString == null && printString != null || lastPrintString != null && printString != null && !lastPrintString.equals(printString)) {
|
||||||
continueUpdate = true;
|
continueUpdate = true;
|
||||||
|
@ -618,8 +663,9 @@ public class DialogCell extends BaseCell {
|
||||||
}
|
}
|
||||||
if (!continueUpdate && (mask & MessagesController.UPDATE_MASK_READ_DIALOG_MESSAGE) != 0) {
|
if (!continueUpdate && (mask & MessagesController.UPDATE_MASK_READ_DIALOG_MESSAGE) != 0) {
|
||||||
if (message != null && lastUnreadState != message.isUnread()) {
|
if (message != null && lastUnreadState != message.isUnread()) {
|
||||||
|
lastUnreadState = message.isUnread();
|
||||||
continueUpdate = true;
|
continueUpdate = true;
|
||||||
} else if (allowPrintStrings) {
|
} else if (isDialogCell) {
|
||||||
TLRPC.TL_dialog dialog = MessagesController.getInstance().dialogs_dict.get(currentDialogId);
|
TLRPC.TL_dialog dialog = MessagesController.getInstance().dialogs_dict.get(currentDialogId);
|
||||||
if (dialog != null && unreadCount != dialog.unread_count) {
|
if (dialog != null && unreadCount != dialog.unread_count) {
|
||||||
unreadCount = dialog.unread_count;
|
unreadCount = dialog.unread_count;
|
||||||
|
@ -627,11 +673,19 @@ public class DialogCell extends BaseCell {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!continueUpdate && (mask & MessagesController.UPDATE_MASK_SEND_STATE) != 0) {
|
||||||
|
if (message != null && lastSendState != message.messageOwner.send_state) {
|
||||||
|
lastSendState = message.messageOwner.send_state;
|
||||||
|
continueUpdate = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!continueUpdate) {
|
if (!continueUpdate) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dialogMuted = isDialogCell && MessagesController.getInstance().isDialogMuted(currentDialogId);
|
||||||
user = null;
|
user = null;
|
||||||
chat = null;
|
chat = null;
|
||||||
encryptedChat = null;
|
encryptedChat = null;
|
||||||
|
@ -748,9 +802,9 @@ public class DialogCell extends BaseCell {
|
||||||
|
|
||||||
if (useSeparator) {
|
if (useSeparator) {
|
||||||
if (LocaleController.isRTL) {
|
if (LocaleController.isRTL) {
|
||||||
canvas.drawLine(0, getMeasuredHeight() - 1, getMeasuredWidth() - AndroidUtilities.dp(72), getMeasuredHeight() - 1, linePaint);
|
canvas.drawLine(0, getMeasuredHeight() - 1, getMeasuredWidth() - AndroidUtilities.dp(AndroidUtilities.leftBaseline), getMeasuredHeight() - 1, linePaint);
|
||||||
} else {
|
} else {
|
||||||
canvas.drawLine(AndroidUtilities.dp(72), getMeasuredHeight() - 1, getMeasuredWidth(), getMeasuredHeight() - 1, linePaint);
|
canvas.drawLine(AndroidUtilities.dp(AndroidUtilities.leftBaseline), getMeasuredHeight() - 1, getMeasuredWidth(), getMeasuredHeight() - 1, linePaint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,15 +9,25 @@
|
||||||
package org.telegram.ui.Cells;
|
package org.telegram.ui.Cells;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.Canvas;
|
||||||
|
import android.graphics.Paint;
|
||||||
|
import android.graphics.Rect;
|
||||||
|
import android.graphics.drawable.BitmapDrawable;
|
||||||
|
import android.graphics.drawable.ColorDrawable;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import org.telegram.PhoneFormat.PhoneFormat;
|
import org.telegram.PhoneFormat.PhoneFormat;
|
||||||
import org.telegram.android.AndroidUtilities;
|
import org.telegram.android.AndroidUtilities;
|
||||||
import org.telegram.android.ContactsController;
|
import org.telegram.android.ContactsController;
|
||||||
|
import org.telegram.messenger.ApplicationLoader;
|
||||||
|
import org.telegram.messenger.R;
|
||||||
import org.telegram.messenger.TLRPC;
|
import org.telegram.messenger.TLRPC;
|
||||||
import org.telegram.ui.Components.AvatarDrawable;
|
import org.telegram.ui.Components.AvatarDrawable;
|
||||||
import org.telegram.ui.Components.BackupImageView;
|
import org.telegram.ui.Components.BackupImageView;
|
||||||
|
@ -27,15 +37,30 @@ public class DrawerProfileCell extends FrameLayout {
|
||||||
private BackupImageView avatarImageView;
|
private BackupImageView avatarImageView;
|
||||||
private TextView nameTextView;
|
private TextView nameTextView;
|
||||||
private TextView phoneTextView;
|
private TextView phoneTextView;
|
||||||
|
private ImageView shadowView;
|
||||||
|
private Rect srcRect = new Rect();
|
||||||
|
private Rect destRect = new Rect();
|
||||||
|
private Paint paint = new Paint();
|
||||||
|
|
||||||
public DrawerProfileCell(Context context) {
|
public DrawerProfileCell(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
setBackgroundColor(0xff4c84b5);
|
setBackgroundColor(0xff4c84b5);
|
||||||
|
|
||||||
|
shadowView = new ImageView(context);
|
||||||
|
shadowView.setVisibility(INVISIBLE);
|
||||||
|
shadowView.setScaleType(ImageView.ScaleType.FIT_XY);
|
||||||
|
shadowView.setImageResource(R.drawable.bottom_shadow);
|
||||||
|
addView(shadowView);
|
||||||
|
LayoutParams layoutParams = (FrameLayout.LayoutParams) shadowView.getLayoutParams();
|
||||||
|
layoutParams.width = LayoutParams.MATCH_PARENT;
|
||||||
|
layoutParams.height = AndroidUtilities.dp(70);
|
||||||
|
layoutParams.gravity = Gravity.LEFT | Gravity.BOTTOM;
|
||||||
|
shadowView.setLayoutParams(layoutParams);
|
||||||
|
|
||||||
avatarImageView = new BackupImageView(context);
|
avatarImageView = new BackupImageView(context);
|
||||||
avatarImageView.imageReceiver.setRoundRadius(AndroidUtilities.dp(32));
|
avatarImageView.getImageReceiver().setRoundRadius(AndroidUtilities.dp(32));
|
||||||
addView(avatarImageView);
|
addView(avatarImageView);
|
||||||
LayoutParams layoutParams = (LayoutParams) avatarImageView.getLayoutParams();
|
layoutParams = (LayoutParams) avatarImageView.getLayoutParams();
|
||||||
layoutParams.width = AndroidUtilities.dp(64);
|
layoutParams.width = AndroidUtilities.dp(64);
|
||||||
layoutParams.height = AndroidUtilities.dp(64);
|
layoutParams.height = AndroidUtilities.dp(64);
|
||||||
layoutParams.gravity = Gravity.LEFT | Gravity.BOTTOM;
|
layoutParams.gravity = Gravity.LEFT | Gravity.BOTTOM;
|
||||||
|
@ -88,6 +113,35 @@ public class DrawerProfileCell extends FrameLayout {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDraw(Canvas canvas) {
|
||||||
|
Drawable backgroundDrawable = ApplicationLoader.getCachedWallpaper();
|
||||||
|
if (ApplicationLoader.isCustomTheme() && backgroundDrawable != null) {
|
||||||
|
phoneTextView.setTextColor(0xffffffff);
|
||||||
|
shadowView.setVisibility(VISIBLE);
|
||||||
|
if (backgroundDrawable instanceof ColorDrawable) {
|
||||||
|
backgroundDrawable.setBounds(0, 0, getMeasuredWidth(), getMeasuredHeight());
|
||||||
|
backgroundDrawable.draw(canvas);
|
||||||
|
} else if (backgroundDrawable instanceof BitmapDrawable) {
|
||||||
|
Bitmap bitmap = ((BitmapDrawable) backgroundDrawable).getBitmap();
|
||||||
|
float scaleX = (float) getMeasuredWidth() / (float) bitmap.getWidth();
|
||||||
|
float scaleY = (float) getMeasuredHeight() / (float) bitmap.getHeight();
|
||||||
|
float scale = scaleX < scaleY ? scaleY : scaleX;
|
||||||
|
int width = (int) (getMeasuredWidth() / scale);
|
||||||
|
int height = (int) (getMeasuredHeight() / scale);
|
||||||
|
int x = (bitmap.getWidth() - width) / 2;
|
||||||
|
int y = (bitmap.getHeight() - height) / 2;
|
||||||
|
srcRect.set(x, y, x + width, y + height);
|
||||||
|
destRect.set(0, 0, getMeasuredWidth(), getMeasuredHeight());
|
||||||
|
canvas.drawBitmap(bitmap, srcRect, destRect, paint);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
shadowView.setVisibility(INVISIBLE);
|
||||||
|
phoneTextView.setTextColor(0xffc2e5ff);
|
||||||
|
super.onDraw(canvas);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void setUser(TLRPC.User user) {
|
public void setUser(TLRPC.User user) {
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
package org.telegram.ui.Cells;
|
package org.telegram.ui.Cells;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.util.AttributeSet;
|
|
||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
|
@ -21,7 +20,9 @@ import org.telegram.android.LocaleController;
|
||||||
public class GreySectionCell extends FrameLayout {
|
public class GreySectionCell extends FrameLayout {
|
||||||
private TextView textView;
|
private TextView textView;
|
||||||
|
|
||||||
private void init() {
|
public GreySectionCell(Context context) {
|
||||||
|
super(context);
|
||||||
|
|
||||||
setBackgroundColor(0xfff2f2f2);
|
setBackgroundColor(0xfff2f2f2);
|
||||||
|
|
||||||
textView = new TextView(getContext());
|
textView = new TextView(getContext());
|
||||||
|
@ -39,26 +40,6 @@ public class GreySectionCell extends FrameLayout {
|
||||||
textView.setLayoutParams(layoutParams);
|
textView.setLayoutParams(layoutParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GreySectionCell(Context context) {
|
|
||||||
super(context);
|
|
||||||
init();
|
|
||||||
}
|
|
||||||
|
|
||||||
public GreySectionCell(Context context, AttributeSet attrs) {
|
|
||||||
super(context, attrs);
|
|
||||||
init();
|
|
||||||
}
|
|
||||||
|
|
||||||
public GreySectionCell(Context context, AttributeSet attrs, int defStyleAttr) {
|
|
||||||
super(context, attrs, defStyleAttr);
|
|
||||||
init();
|
|
||||||
}
|
|
||||||
|
|
||||||
public GreySectionCell(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
|
||||||
super(context, attrs, defStyleAttr, defStyleRes);
|
|
||||||
init();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||||
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(36), MeasureSpec.EXACTLY));
|
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(36), MeasureSpec.EXACTLY));
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
/*
|
||||||
|
* This is the source code of Telegram for Android v. 2.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-2015.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.telegram.ui.Cells;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.graphics.Canvas;
|
||||||
|
import android.graphics.Paint;
|
||||||
|
import android.util.TypedValue;
|
||||||
|
import android.view.Gravity;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import org.telegram.android.AndroidUtilities;
|
||||||
|
|
||||||
|
public class HashtagSearchCell extends TextView {
|
||||||
|
|
||||||
|
private boolean needDivider;
|
||||||
|
private static Paint paint;
|
||||||
|
|
||||||
|
public HashtagSearchCell(Context context) {
|
||||||
|
super(context);
|
||||||
|
setGravity(Gravity.CENTER_VERTICAL);
|
||||||
|
setPadding(AndroidUtilities.dp(16), 0, AndroidUtilities.dp(16), 0);
|
||||||
|
setTextSize(TypedValue.COMPLEX_UNIT_DIP, 17);
|
||||||
|
setTextColor(0xff000000);
|
||||||
|
if (paint == null) {
|
||||||
|
paint = new Paint();
|
||||||
|
paint.setColor(0xffdcdcdc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNeedDivider(boolean value) {
|
||||||
|
needDivider = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||||
|
setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), AndroidUtilities.dp(48) + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDraw(Canvas canvas) {
|
||||||
|
super.onDraw(canvas);
|
||||||
|
if (needDivider) {
|
||||||
|
canvas.drawLine(0, getHeight() - 1, getWidth(), getHeight() - 1, paint);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,107 @@
|
||||||
|
/*
|
||||||
|
* This is the source code of Telegram for Android v. 2.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-2015.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.telegram.ui.Cells;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
import android.util.TypedValue;
|
||||||
|
import android.view.Gravity;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import org.telegram.android.AndroidUtilities;
|
||||||
|
import org.telegram.android.ContactsController;
|
||||||
|
import org.telegram.messenger.TLRPC;
|
||||||
|
import org.telegram.ui.Components.AvatarDrawable;
|
||||||
|
import org.telegram.ui.Components.BackupImageView;
|
||||||
|
|
||||||
|
public class MentionCell extends LinearLayout {
|
||||||
|
|
||||||
|
private BackupImageView imageView;
|
||||||
|
private TextView nameTextView;
|
||||||
|
private TextView usernameTextView;
|
||||||
|
private AvatarDrawable avatarDrawable;
|
||||||
|
|
||||||
|
public MentionCell(Context context) {
|
||||||
|
super(context);
|
||||||
|
|
||||||
|
setOrientation(HORIZONTAL);
|
||||||
|
|
||||||
|
avatarDrawable = new AvatarDrawable();
|
||||||
|
avatarDrawable.setSmallStyle(true);
|
||||||
|
|
||||||
|
imageView = new BackupImageView(context);
|
||||||
|
imageView.setRoundRadius(AndroidUtilities.dp(14));
|
||||||
|
addView(imageView);
|
||||||
|
LayoutParams layoutParams = (LayoutParams) imageView.getLayoutParams();
|
||||||
|
layoutParams.leftMargin = AndroidUtilities.dp(12);
|
||||||
|
layoutParams.topMargin = AndroidUtilities.dp(4);
|
||||||
|
layoutParams.width = AndroidUtilities.dp(28);
|
||||||
|
layoutParams.height = AndroidUtilities.dp(28);
|
||||||
|
imageView.setLayoutParams(layoutParams);
|
||||||
|
|
||||||
|
nameTextView = new TextView(context);
|
||||||
|
nameTextView.setTextColor(0xff000000);
|
||||||
|
nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
|
||||||
|
nameTextView.setSingleLine(true);
|
||||||
|
nameTextView.setGravity(Gravity.LEFT);
|
||||||
|
nameTextView.setEllipsize(TextUtils.TruncateAt.END);
|
||||||
|
addView(nameTextView);
|
||||||
|
layoutParams = (LayoutParams) nameTextView.getLayoutParams();
|
||||||
|
layoutParams.leftMargin = AndroidUtilities.dp(12);
|
||||||
|
layoutParams.width = LayoutParams.WRAP_CONTENT;
|
||||||
|
layoutParams.height = LayoutParams.WRAP_CONTENT;
|
||||||
|
layoutParams.gravity = Gravity.CENTER_VERTICAL;
|
||||||
|
nameTextView.setLayoutParams(layoutParams);
|
||||||
|
|
||||||
|
usernameTextView = new TextView(context);
|
||||||
|
usernameTextView.setTextColor(0xff999999);
|
||||||
|
usernameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
|
||||||
|
usernameTextView.setSingleLine(true);
|
||||||
|
usernameTextView.setGravity(Gravity.LEFT);
|
||||||
|
usernameTextView.setEllipsize(TextUtils.TruncateAt.END);
|
||||||
|
addView(usernameTextView);
|
||||||
|
layoutParams = (LayoutParams) usernameTextView.getLayoutParams();
|
||||||
|
layoutParams.leftMargin = AndroidUtilities.dp(12);
|
||||||
|
layoutParams.width = LayoutParams.WRAP_CONTENT;
|
||||||
|
layoutParams.height = LayoutParams.WRAP_CONTENT;
|
||||||
|
layoutParams.gravity = Gravity.CENTER_VERTICAL;
|
||||||
|
usernameTextView.setLayoutParams(layoutParams);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||||
|
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(36), MeasureSpec.EXACTLY));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUser(TLRPC.User user) {
|
||||||
|
if (user == null) {
|
||||||
|
nameTextView.setText("");
|
||||||
|
usernameTextView.setText("");
|
||||||
|
imageView.setImageDrawable(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
avatarDrawable.setInfo(user);
|
||||||
|
if (user.photo != null && user.photo.photo_small != null) {
|
||||||
|
imageView.setImage(user.photo.photo_small, "50_50", avatarDrawable);
|
||||||
|
} else {
|
||||||
|
imageView.setImageDrawable(avatarDrawable);
|
||||||
|
}
|
||||||
|
nameTextView.setText(ContactsController.formatName(user.first_name, user.last_name));
|
||||||
|
usernameTextView.setText("@" + user.username);
|
||||||
|
imageView.setVisibility(VISIBLE);
|
||||||
|
usernameTextView.setVisibility(VISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setText(String text) {
|
||||||
|
imageView.setVisibility(INVISIBLE);
|
||||||
|
usernameTextView.setVisibility(INVISIBLE);
|
||||||
|
nameTextView.setText(text);
|
||||||
|
}
|
||||||
|
}
|
|
@ -9,6 +9,7 @@
|
||||||
package org.telegram.ui.Cells;
|
package org.telegram.ui.Cells;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
@ -32,28 +33,60 @@ public class PhotoEditToolCell extends FrameLayoutFixed {
|
||||||
LayoutParams layoutParams = (LayoutParams) iconImage.getLayoutParams();
|
LayoutParams layoutParams = (LayoutParams) iconImage.getLayoutParams();
|
||||||
layoutParams.width = LayoutParams.MATCH_PARENT;
|
layoutParams.width = LayoutParams.MATCH_PARENT;
|
||||||
layoutParams.height = LayoutParams.MATCH_PARENT;
|
layoutParams.height = LayoutParams.MATCH_PARENT;
|
||||||
layoutParams.bottomMargin = AndroidUtilities.dp(20);
|
layoutParams.bottomMargin = AndroidUtilities.dp(12);
|
||||||
iconImage.setLayoutParams(layoutParams);
|
iconImage.setLayoutParams(layoutParams);
|
||||||
|
|
||||||
nameTextView = new TextView(context);
|
nameTextView = new TextView(context);
|
||||||
nameTextView.setGravity(Gravity.CENTER);
|
nameTextView.setGravity(Gravity.CENTER);
|
||||||
nameTextView.setTextColor(0xffffffff);
|
nameTextView.setTextColor(0xffffffff);
|
||||||
nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);
|
nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
|
||||||
|
nameTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
|
||||||
|
nameTextView.setMaxLines(1);
|
||||||
|
nameTextView.setSingleLine(true);
|
||||||
|
nameTextView.setEllipsize(TextUtils.TruncateAt.END);
|
||||||
addView(nameTextView);
|
addView(nameTextView);
|
||||||
layoutParams = (LayoutParams) nameTextView.getLayoutParams();
|
layoutParams = (LayoutParams) nameTextView.getLayoutParams();
|
||||||
layoutParams.width = LayoutParams.MATCH_PARENT;
|
layoutParams.width = LayoutParams.MATCH_PARENT;
|
||||||
layoutParams.height = AndroidUtilities.dp(20);
|
layoutParams.height = LayoutParams.WRAP_CONTENT;
|
||||||
layoutParams.gravity = Gravity.LEFT | Gravity.BOTTOM;
|
layoutParams.gravity = Gravity.LEFT | Gravity.BOTTOM;
|
||||||
|
layoutParams.leftMargin = AndroidUtilities.dp(4);
|
||||||
|
layoutParams.rightMargin = AndroidUtilities.dp(4);
|
||||||
nameTextView.setLayoutParams(layoutParams);
|
nameTextView.setLayoutParams(layoutParams);
|
||||||
|
|
||||||
|
valueTextView = new TextView(context);
|
||||||
|
valueTextView.setTextColor(0xff6cc3ff);
|
||||||
|
valueTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 11);
|
||||||
|
valueTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
|
||||||
|
addView(valueTextView);
|
||||||
|
layoutParams = (LayoutParams) valueTextView.getLayoutParams();
|
||||||
|
layoutParams.width = LayoutParams.WRAP_CONTENT;
|
||||||
|
layoutParams.height = LayoutParams.WRAP_CONTENT;
|
||||||
|
layoutParams.gravity = Gravity.LEFT | Gravity.TOP;
|
||||||
|
layoutParams.leftMargin = AndroidUtilities.dp(57);
|
||||||
|
layoutParams.topMargin = AndroidUtilities.dp(3);
|
||||||
|
valueTextView.setLayoutParams(layoutParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||||
super.onMeasure(MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(80), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(60), MeasureSpec.EXACTLY));
|
super.onMeasure(MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(86), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(60), MeasureSpec.EXACTLY));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIconAndText(int resId, String text) {
|
public void setIconAndTextAndValue(int resId, String text, float value) {
|
||||||
iconImage.setImageResource(resId);
|
iconImage.setImageResource(resId);
|
||||||
nameTextView.setText(text);
|
nameTextView.setText(text.toUpperCase());
|
||||||
|
if (value == 0) {
|
||||||
|
valueTextView.setText("");
|
||||||
|
} else if (value > 0) {
|
||||||
|
valueTextView.setText("+" + (int) value);
|
||||||
|
} else {
|
||||||
|
valueTextView.setText("" + (int) value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIconAndTextAndValue(int resId, String text, String value) {
|
||||||
|
iconImage.setImageResource(resId);
|
||||||
|
nameTextView.setText(text.toUpperCase());
|
||||||
|
valueTextView.setText(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,6 @@ import android.util.TypedValue;
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.FrameLayout;
|
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
@ -23,11 +22,12 @@ import org.telegram.android.AndroidUtilities;
|
||||||
import org.telegram.android.MediaController;
|
import org.telegram.android.MediaController;
|
||||||
import org.telegram.messenger.R;
|
import org.telegram.messenger.R;
|
||||||
import org.telegram.ui.Components.BackupImageView;
|
import org.telegram.ui.Components.BackupImageView;
|
||||||
|
import org.telegram.ui.Components.FrameLayoutFixed;
|
||||||
|
|
||||||
public class PhotoPickerAlbumsCell extends FrameLayout {
|
public class PhotoPickerAlbumsCell extends FrameLayoutFixed {
|
||||||
|
|
||||||
public static interface PhotoPickerAlbumsCellDelegate {
|
public interface PhotoPickerAlbumsCellDelegate {
|
||||||
public abstract void didSelectAlbum(MediaController.AlbumEntry albumEntry);
|
void didSelectAlbum(MediaController.AlbumEntry albumEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
private AlbumView[] albumViews;
|
private AlbumView[] albumViews;
|
||||||
|
@ -35,7 +35,7 @@ public class PhotoPickerAlbumsCell extends FrameLayout {
|
||||||
private int albumsCount;
|
private int albumsCount;
|
||||||
private PhotoPickerAlbumsCellDelegate delegate;
|
private PhotoPickerAlbumsCellDelegate delegate;
|
||||||
|
|
||||||
private class AlbumView extends FrameLayout {
|
private class AlbumView extends FrameLayoutFixed {
|
||||||
|
|
||||||
private BackupImageView imageView;
|
private BackupImageView imageView;
|
||||||
private TextView nameTextView;
|
private TextView nameTextView;
|
||||||
|
@ -117,7 +117,7 @@ public class PhotoPickerAlbumsCell extends FrameLayout {
|
||||||
for (int a = 0; a < 4; a++) {
|
for (int a = 0; a < 4; a++) {
|
||||||
albumViews[a] = new AlbumView(context);
|
albumViews[a] = new AlbumView(context);
|
||||||
addView(albumViews[a]);
|
addView(albumViews[a]);
|
||||||
albumViews[a].setVisibility(GONE);
|
albumViews[a].setVisibility(INVISIBLE);
|
||||||
albumViews[a].setTag(a);
|
albumViews[a].setTag(a);
|
||||||
albumViews[a].setOnClickListener(new OnClickListener() {
|
albumViews[a].setOnClickListener(new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -132,7 +132,7 @@ public class PhotoPickerAlbumsCell extends FrameLayout {
|
||||||
|
|
||||||
public void setAlbumsCount(int count) {
|
public void setAlbumsCount(int count) {
|
||||||
for (int a = 0; a < albumViews.length; a++) {
|
for (int a = 0; a < albumViews.length; a++) {
|
||||||
albumViews[a].setVisibility(a < count ? VISIBLE : GONE);
|
albumViews[a].setVisibility(a < count ? VISIBLE : INVISIBLE);
|
||||||
}
|
}
|
||||||
albumsCount = count;
|
albumsCount = count;
|
||||||
}
|
}
|
||||||
|
@ -146,7 +146,9 @@ public class PhotoPickerAlbumsCell extends FrameLayout {
|
||||||
|
|
||||||
if (albumEntry != null) {
|
if (albumEntry != null) {
|
||||||
AlbumView albumView = albumViews[a];
|
AlbumView albumView = albumViews[a];
|
||||||
|
albumView.imageView.setOrientation(0, true);
|
||||||
if (albumEntry.coverPhoto != null && albumEntry.coverPhoto.path != null) {
|
if (albumEntry.coverPhoto != null && albumEntry.coverPhoto.path != null) {
|
||||||
|
albumView.imageView.setOrientation(albumEntry.coverPhoto.orientation, true);
|
||||||
albumView.imageView.setImage("thumb://" + albumEntry.coverPhoto.imageId + ":" + albumEntry.coverPhoto.path, null, getContext().getResources().getDrawable(R.drawable.nophotos));
|
albumView.imageView.setImage("thumb://" + albumEntry.coverPhoto.imageId + ":" + albumEntry.coverPhoto.path, null, getContext().getResources().getDrawable(R.drawable.nophotos));
|
||||||
} else {
|
} else {
|
||||||
albumView.imageView.setImageResource(R.drawable.nophotos);
|
albumView.imageView.setImageResource(R.drawable.nophotos);
|
||||||
|
@ -154,7 +156,7 @@ public class PhotoPickerAlbumsCell extends FrameLayout {
|
||||||
albumView.nameTextView.setText(albumEntry.bucketName);
|
albumView.nameTextView.setText(albumEntry.bucketName);
|
||||||
albumView.countTextView.setText(String.format("%d", albumEntry.photos.size()));
|
albumView.countTextView.setText(String.format("%d", albumEntry.photos.size()));
|
||||||
} else {
|
} else {
|
||||||
albumViews[a].setVisibility(GONE);
|
albumViews[a].setVisibility(INVISIBLE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,16 +169,16 @@ public class PhotoPickerAlbumsCell extends FrameLayout {
|
||||||
itemWidth = (AndroidUtilities.displaySize.x - ((albumsCount + 1) * AndroidUtilities.dp(4))) / albumsCount;
|
itemWidth = (AndroidUtilities.displaySize.x - ((albumsCount + 1) * AndroidUtilities.dp(4))) / albumsCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(4) + itemWidth, MeasureSpec.EXACTLY));
|
|
||||||
|
|
||||||
for (int a = 0; a < albumsCount; a++) {
|
for (int a = 0; a < albumsCount; a++) {
|
||||||
LayoutParams layoutParams = (LayoutParams) albumViews[a].getLayoutParams();
|
LayoutParams layoutParams = (LayoutParams) albumViews[a].getLayoutParams();
|
||||||
layoutParams.topMargin = AndroidUtilities.dp(4);
|
layoutParams.topMargin = AndroidUtilities.dp(4);
|
||||||
layoutParams.leftMargin = (itemWidth + AndroidUtilities.dp(4)) * a;
|
layoutParams.leftMargin = (itemWidth + AndroidUtilities.dp(4)) * a;
|
||||||
layoutParams.width = itemWidth;
|
layoutParams.width = itemWidth;
|
||||||
layoutParams.height = itemWidth;
|
layoutParams.height = itemWidth;
|
||||||
|
layoutParams.gravity = Gravity.LEFT | Gravity.TOP;
|
||||||
albumViews[a].setLayoutParams(layoutParams);
|
albumViews[a].setLayoutParams(layoutParams);
|
||||||
albumViews[a].measure(MeasureSpec.makeMeasureSpec(itemWidth, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(itemWidth, MeasureSpec.EXACTLY));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(4) + itemWidth, MeasureSpec.EXACTLY));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,6 @@ package org.telegram.ui.Cells;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
import android.widget.ImageView;
|
|
||||||
|
|
||||||
import org.telegram.android.AndroidUtilities;
|
import org.telegram.android.AndroidUtilities;
|
||||||
import org.telegram.messenger.R;
|
import org.telegram.messenger.R;
|
||||||
|
@ -23,7 +22,6 @@ public class PhotoPickerPhotoCell extends FrameLayout {
|
||||||
public BackupImageView photoImage;
|
public BackupImageView photoImage;
|
||||||
public FrameLayout checkFrame;
|
public FrameLayout checkFrame;
|
||||||
public CheckBox checkBox;
|
public CheckBox checkBox;
|
||||||
public ImageView editedImage;
|
|
||||||
public int itemWidth;
|
public int itemWidth;
|
||||||
|
|
||||||
public PhotoPickerPhotoCell(Context context) {
|
public PhotoPickerPhotoCell(Context context) {
|
||||||
|
@ -57,16 +55,6 @@ public class PhotoPickerPhotoCell extends FrameLayout {
|
||||||
layoutParams.topMargin = AndroidUtilities.dp(6);
|
layoutParams.topMargin = AndroidUtilities.dp(6);
|
||||||
layoutParams.rightMargin = AndroidUtilities.dp(6);
|
layoutParams.rightMargin = AndroidUtilities.dp(6);
|
||||||
checkBox.setLayoutParams(layoutParams);
|
checkBox.setLayoutParams(layoutParams);
|
||||||
|
|
||||||
editedImage = new ImageView(context);
|
|
||||||
editedImage.setImageResource(R.drawable.photo_edit);
|
|
||||||
editedImage.setScaleType(ImageView.ScaleType.CENTER);
|
|
||||||
addView(editedImage);
|
|
||||||
layoutParams = (LayoutParams) editedImage.getLayoutParams();
|
|
||||||
layoutParams.width = AndroidUtilities.dp(42);
|
|
||||||
layoutParams.height = AndroidUtilities.dp(42);
|
|
||||||
layoutParams.gravity = Gravity.LEFT | Gravity.TOP;
|
|
||||||
editedImage.setLayoutParams(layoutParams);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -10,6 +10,7 @@ package org.telegram.ui.Cells;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
|
@ -25,8 +26,8 @@ import org.telegram.messenger.R;
|
||||||
|
|
||||||
public class PhotoPickerSearchCell extends LinearLayout {
|
public class PhotoPickerSearchCell extends LinearLayout {
|
||||||
|
|
||||||
public static interface PhotoPickerSearchCellDelegate {
|
public interface PhotoPickerSearchCellDelegate {
|
||||||
public abstract void didPressedSearchButton(int index);
|
void didPressedSearchButton(int index);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class SearchButton extends FrameLayout {
|
private class SearchButton extends FrameLayout {
|
||||||
|
@ -39,62 +40,57 @@ public class PhotoPickerSearchCell extends LinearLayout {
|
||||||
public SearchButton(Context context) {
|
public SearchButton(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
|
|
||||||
setBackgroundColor(0xff292929);
|
setBackgroundColor(0xff1a1a1a);
|
||||||
|
|
||||||
selector = new View(context);
|
selector = new View(context);
|
||||||
selector.setBackgroundResource(R.drawable.list_selector);
|
selector.setBackgroundResource(R.drawable.list_selector);
|
||||||
addView(selector);
|
addView(selector);
|
||||||
FrameLayout.LayoutParams layoutParams1 = (FrameLayout.LayoutParams) selector.getLayoutParams();
|
FrameLayout.LayoutParams layoutParams1 = (FrameLayout.LayoutParams) selector.getLayoutParams();
|
||||||
layoutParams1.width = FrameLayout.LayoutParams.MATCH_PARENT;
|
layoutParams1.width = LayoutParams.MATCH_PARENT;
|
||||||
layoutParams1.height = FrameLayout.LayoutParams.MATCH_PARENT;
|
layoutParams1.height = LayoutParams.MATCH_PARENT;
|
||||||
selector.setLayoutParams(layoutParams1);
|
selector.setLayoutParams(layoutParams1);
|
||||||
|
|
||||||
LinearLayout linearLayout = new LinearLayout(context);
|
|
||||||
linearLayout.setOrientation(HORIZONTAL);
|
|
||||||
addView(linearLayout);
|
|
||||||
layoutParams1 = (FrameLayout.LayoutParams) linearLayout.getLayoutParams();
|
|
||||||
layoutParams1.width = FrameLayout.LayoutParams.WRAP_CONTENT;
|
|
||||||
layoutParams1.height = FrameLayout.LayoutParams.MATCH_PARENT;
|
|
||||||
layoutParams1.gravity = Gravity.CENTER;
|
|
||||||
linearLayout.setLayoutParams(layoutParams1);
|
|
||||||
|
|
||||||
imageView = new ImageView(context);
|
imageView = new ImageView(context);
|
||||||
linearLayout.addView(imageView);
|
imageView.setScaleType(ImageView.ScaleType.CENTER);
|
||||||
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) imageView.getLayoutParams();
|
addView(imageView);
|
||||||
layoutParams.height = LinearLayout.LayoutParams.WRAP_CONTENT;
|
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) imageView.getLayoutParams();
|
||||||
layoutParams.width = LinearLayout.LayoutParams.WRAP_CONTENT;
|
layoutParams.height = AndroidUtilities.dp(48);
|
||||||
|
layoutParams.width = AndroidUtilities.dp(48);
|
||||||
|
layoutParams1.gravity = Gravity.LEFT | Gravity.TOP;
|
||||||
imageView.setLayoutParams(layoutParams);
|
imageView.setLayoutParams(layoutParams);
|
||||||
|
|
||||||
FrameLayout frameLayout = new FrameLayout(context);
|
|
||||||
frameLayout.setPadding(AndroidUtilities.dp(4), 0, 0, 0);
|
|
||||||
linearLayout.addView(frameLayout);
|
|
||||||
layoutParams = (LinearLayout.LayoutParams) frameLayout.getLayoutParams();
|
|
||||||
layoutParams.height = LinearLayout.LayoutParams.MATCH_PARENT;
|
|
||||||
layoutParams.width = LinearLayout.LayoutParams.WRAP_CONTENT;
|
|
||||||
frameLayout.setLayoutParams(layoutParams);
|
|
||||||
|
|
||||||
textView1 = new TextView(context);
|
textView1 = new TextView(context);
|
||||||
textView1.setGravity(Gravity.CENTER_VERTICAL);
|
textView1.setGravity(Gravity.CENTER_VERTICAL);
|
||||||
textView1.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13);
|
textView1.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
|
||||||
textView1.setPadding(0, 0, AndroidUtilities.dp(8), 0);
|
|
||||||
textView1.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
|
textView1.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
|
||||||
textView1.setTextColor(0xffffffff);
|
textView1.setTextColor(0xffffffff);
|
||||||
frameLayout.addView(textView1);
|
textView1.setSingleLine(true);
|
||||||
|
textView1.setEllipsize(TextUtils.TruncateAt.END);
|
||||||
|
addView(textView1);
|
||||||
layoutParams1 = (FrameLayout.LayoutParams) textView1.getLayoutParams();
|
layoutParams1 = (FrameLayout.LayoutParams) textView1.getLayoutParams();
|
||||||
layoutParams1.width = FrameLayout.LayoutParams.WRAP_CONTENT;
|
layoutParams1.width = LayoutParams.MATCH_PARENT;
|
||||||
layoutParams1.height = FrameLayout.LayoutParams.MATCH_PARENT;
|
layoutParams1.height = LayoutParams.WRAP_CONTENT;
|
||||||
|
layoutParams1.gravity = Gravity.TOP | Gravity.LEFT;
|
||||||
|
layoutParams1.rightMargin = AndroidUtilities.dp(4);
|
||||||
|
layoutParams1.leftMargin = AndroidUtilities.dp(51);
|
||||||
|
layoutParams1.topMargin = AndroidUtilities.dp(8);
|
||||||
textView1.setLayoutParams(layoutParams1);
|
textView1.setLayoutParams(layoutParams1);
|
||||||
|
|
||||||
textView2 = new TextView(context);
|
textView2 = new TextView(context);
|
||||||
textView2.setGravity(Gravity.CENTER_VERTICAL);
|
textView2.setGravity(Gravity.CENTER_VERTICAL);
|
||||||
textView2.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 9);
|
textView2.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
|
||||||
textView2.setPadding(0, AndroidUtilities.dp(24), AndroidUtilities.dp(8), 0);
|
|
||||||
textView2.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
|
textView2.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
|
||||||
textView2.setTextColor(0xff464646);
|
textView2.setTextColor(0xff666666);
|
||||||
frameLayout.addView(textView2);
|
textView2.setSingleLine(true);
|
||||||
|
textView2.setEllipsize(TextUtils.TruncateAt.END);
|
||||||
|
addView(textView2);
|
||||||
layoutParams1 = (FrameLayout.LayoutParams) textView2.getLayoutParams();
|
layoutParams1 = (FrameLayout.LayoutParams) textView2.getLayoutParams();
|
||||||
layoutParams1.width = FrameLayout.LayoutParams.WRAP_CONTENT;
|
layoutParams1.width = LayoutParams.MATCH_PARENT;
|
||||||
layoutParams1.height = FrameLayout.LayoutParams.MATCH_PARENT;
|
layoutParams1.height = LayoutParams.WRAP_CONTENT;
|
||||||
|
layoutParams1.gravity = Gravity.TOP | Gravity.LEFT;
|
||||||
|
layoutParams1.leftMargin = AndroidUtilities.dp(51);
|
||||||
|
layoutParams1.rightMargin = AndroidUtilities.dp(4);
|
||||||
|
layoutParams1.topMargin = AndroidUtilities.dp(26);
|
||||||
textView2.setLayoutParams(layoutParams1);
|
textView2.setLayoutParams(layoutParams1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,7 +111,8 @@ public class PhotoPickerSearchCell extends LinearLayout {
|
||||||
|
|
||||||
SearchButton searchButton = new SearchButton(context);
|
SearchButton searchButton = new SearchButton(context);
|
||||||
searchButton.textView1.setText(LocaleController.getString("SearchImages", R.string.SearchImages));
|
searchButton.textView1.setText(LocaleController.getString("SearchImages", R.string.SearchImages));
|
||||||
searchButton.imageView.setImageResource(R.drawable.web_search);
|
searchButton.textView2.setText(LocaleController.getString("SearchImagesInfo", R.string.SearchImagesInfo));
|
||||||
|
searchButton.imageView.setImageResource(R.drawable.search_web);
|
||||||
addView(searchButton);
|
addView(searchButton);
|
||||||
LayoutParams layoutParams = (LayoutParams) searchButton.getLayoutParams();
|
LayoutParams layoutParams = (LayoutParams) searchButton.getLayoutParams();
|
||||||
layoutParams.weight = 0.5f;
|
layoutParams.weight = 0.5f;
|
||||||
|
@ -144,7 +141,7 @@ public class PhotoPickerSearchCell extends LinearLayout {
|
||||||
searchButton = new SearchButton(context);
|
searchButton = new SearchButton(context);
|
||||||
searchButton.textView1.setText(LocaleController.getString("SearchGifs", R.string.SearchGifs));
|
searchButton.textView1.setText(LocaleController.getString("SearchGifs", R.string.SearchGifs));
|
||||||
searchButton.textView2.setText("GIPHY");
|
searchButton.textView2.setText("GIPHY");
|
||||||
searchButton.imageView.setImageResource(R.drawable.gif_search);
|
searchButton.imageView.setImageResource(R.drawable.search_gif);
|
||||||
addView(searchButton);
|
addView(searchButton);
|
||||||
layoutParams = (LayoutParams) searchButton.getLayoutParams();
|
layoutParams = (LayoutParams) searchButton.getLayoutParams();
|
||||||
layoutParams.weight = 0.5f;
|
layoutParams.weight = 0.5f;
|
||||||
|
|
|
@ -30,6 +30,7 @@ import org.telegram.messenger.UserConfig;
|
||||||
import org.telegram.ui.Components.AvatarDrawable;
|
import org.telegram.ui.Components.AvatarDrawable;
|
||||||
|
|
||||||
public class ProfileSearchCell extends BaseCell {
|
public class ProfileSearchCell extends BaseCell {
|
||||||
|
|
||||||
private static TextPaint namePaint;
|
private static TextPaint namePaint;
|
||||||
private static TextPaint nameEncryptedPaint;
|
private static TextPaint nameEncryptedPaint;
|
||||||
private static TextPaint onlinePaint;
|
private static TextPaint onlinePaint;
|
||||||
|
@ -149,10 +150,10 @@ public class ProfileSearchCell extends BaseCell {
|
||||||
if (encryptedChat != null) {
|
if (encryptedChat != null) {
|
||||||
drawNameLock = true;
|
drawNameLock = true;
|
||||||
if (!LocaleController.isRTL) {
|
if (!LocaleController.isRTL) {
|
||||||
nameLockLeft = AndroidUtilities.dp(72);
|
nameLockLeft = AndroidUtilities.dp(AndroidUtilities.leftBaseline);
|
||||||
nameLeft = AndroidUtilities.dp(76) + lockDrawable.getIntrinsicWidth();
|
nameLeft = AndroidUtilities.dp(AndroidUtilities.leftBaseline + 4) + lockDrawable.getIntrinsicWidth();
|
||||||
} else {
|
} else {
|
||||||
nameLockLeft = getMeasuredWidth() - AndroidUtilities.dp(74) - lockDrawable.getIntrinsicWidth();
|
nameLockLeft = getMeasuredWidth() - AndroidUtilities.dp(AndroidUtilities.leftBaseline + 2) - lockDrawable.getIntrinsicWidth();
|
||||||
nameLeft = AndroidUtilities.dp(11);
|
nameLeft = AndroidUtilities.dp(11);
|
||||||
}
|
}
|
||||||
nameLockTop = AndroidUtilities.dp(16.5f);
|
nameLockTop = AndroidUtilities.dp(16.5f);
|
||||||
|
@ -167,15 +168,15 @@ public class ProfileSearchCell extends BaseCell {
|
||||||
nameLockTop = AndroidUtilities.dp(30);
|
nameLockTop = AndroidUtilities.dp(30);
|
||||||
}
|
}
|
||||||
if (!LocaleController.isRTL) {
|
if (!LocaleController.isRTL) {
|
||||||
nameLockLeft = AndroidUtilities.dp(72);
|
nameLockLeft = AndroidUtilities.dp(AndroidUtilities.leftBaseline);
|
||||||
nameLeft = AndroidUtilities.dp(76) + (drawNameGroup ? groupDrawable.getIntrinsicWidth() : broadcastDrawable.getIntrinsicWidth());
|
nameLeft = AndroidUtilities.dp(AndroidUtilities.leftBaseline + 4) + (drawNameGroup ? groupDrawable.getIntrinsicWidth() : broadcastDrawable.getIntrinsicWidth());
|
||||||
} else {
|
} else {
|
||||||
nameLockLeft = getMeasuredWidth() - AndroidUtilities.dp(74) - (drawNameGroup ? groupDrawable.getIntrinsicWidth() : broadcastDrawable.getIntrinsicWidth());
|
nameLockLeft = getMeasuredWidth() - AndroidUtilities.dp(AndroidUtilities.leftBaseline + 2) - (drawNameGroup ? groupDrawable.getIntrinsicWidth() : broadcastDrawable.getIntrinsicWidth());
|
||||||
nameLeft = AndroidUtilities.dp(11);
|
nameLeft = AndroidUtilities.dp(11);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!LocaleController.isRTL) {
|
if (!LocaleController.isRTL) {
|
||||||
nameLeft = AndroidUtilities.dp(72);
|
nameLeft = AndroidUtilities.dp(AndroidUtilities.leftBaseline);
|
||||||
} else {
|
} else {
|
||||||
nameLeft = AndroidUtilities.dp(11);
|
nameLeft = AndroidUtilities.dp(11);
|
||||||
}
|
}
|
||||||
|
@ -211,7 +212,7 @@ public class ProfileSearchCell extends BaseCell {
|
||||||
if (!LocaleController.isRTL) {
|
if (!LocaleController.isRTL) {
|
||||||
onlineWidth = nameWidth = getMeasuredWidth() - nameLeft - AndroidUtilities.dp(14);
|
onlineWidth = nameWidth = getMeasuredWidth() - nameLeft - AndroidUtilities.dp(14);
|
||||||
} else {
|
} else {
|
||||||
onlineWidth = nameWidth = getMeasuredWidth() - nameLeft - AndroidUtilities.dp(72);
|
onlineWidth = nameWidth = getMeasuredWidth() - nameLeft - AndroidUtilities.dp(AndroidUtilities.leftBaseline);
|
||||||
}
|
}
|
||||||
if (drawNameLock) {
|
if (drawNameLock) {
|
||||||
nameWidth -= AndroidUtilities.dp(6) + lockDrawable.getIntrinsicWidth();
|
nameWidth -= AndroidUtilities.dp(6) + lockDrawable.getIntrinsicWidth();
|
||||||
|
@ -226,7 +227,7 @@ public class ProfileSearchCell extends BaseCell {
|
||||||
|
|
||||||
if (chat == null) {
|
if (chat == null) {
|
||||||
if (!LocaleController.isRTL) {
|
if (!LocaleController.isRTL) {
|
||||||
onlineLeft = AndroidUtilities.dp(72);
|
onlineLeft = AndroidUtilities.dp(AndroidUtilities.leftBaseline);
|
||||||
} else {
|
} else {
|
||||||
onlineLeft = AndroidUtilities.dp(11);
|
onlineLeft = AndroidUtilities.dp(11);
|
||||||
}
|
}
|
||||||
|
@ -254,9 +255,9 @@ public class ProfileSearchCell extends BaseCell {
|
||||||
|
|
||||||
int avatarLeft;
|
int avatarLeft;
|
||||||
if (!LocaleController.isRTL) {
|
if (!LocaleController.isRTL) {
|
||||||
avatarLeft = AndroidUtilities.dp(9);
|
avatarLeft = AndroidUtilities.dp(AndroidUtilities.isTablet() ? 13 : 9);
|
||||||
} else {
|
} else {
|
||||||
avatarLeft = getMeasuredWidth() - AndroidUtilities.dp(61);
|
avatarLeft = getMeasuredWidth() - AndroidUtilities.dp(AndroidUtilities.isTablet() ? 65 : 61);
|
||||||
}
|
}
|
||||||
|
|
||||||
avatarImage.setImageCoords(avatarLeft, AndroidUtilities.dp(10), AndroidUtilities.dp(52), AndroidUtilities.dp(52));
|
avatarImage.setImageCoords(avatarLeft, AndroidUtilities.dp(10), AndroidUtilities.dp(52), AndroidUtilities.dp(52));
|
||||||
|
@ -384,9 +385,9 @@ public class ProfileSearchCell extends BaseCell {
|
||||||
|
|
||||||
if (useSeparator) {
|
if (useSeparator) {
|
||||||
if (LocaleController.isRTL) {
|
if (LocaleController.isRTL) {
|
||||||
canvas.drawLine(0, getMeasuredHeight() - 1, getMeasuredWidth() - AndroidUtilities.dp(72), getMeasuredHeight() - 1, linePaint);
|
canvas.drawLine(0, getMeasuredHeight() - 1, getMeasuredWidth() - AndroidUtilities.dp(AndroidUtilities.leftBaseline), getMeasuredHeight() - 1, linePaint);
|
||||||
} else {
|
} else {
|
||||||
canvas.drawLine(AndroidUtilities.dp(72), getMeasuredHeight() - 1, getMeasuredWidth(), getMeasuredHeight() - 1, linePaint);
|
canvas.drawLine(AndroidUtilities.dp(AndroidUtilities.leftBaseline), getMeasuredHeight() - 1, getMeasuredWidth(), getMeasuredHeight() - 1, linePaint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,205 @@
|
||||||
|
/*
|
||||||
|
* This is the source code of Telegram for Android v. 2.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-2015.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.telegram.ui.Cells;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.graphics.Canvas;
|
||||||
|
import android.graphics.Paint;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
import android.util.TypedValue;
|
||||||
|
import android.view.Gravity;
|
||||||
|
import android.widget.FrameLayout;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import org.telegram.android.AndroidUtilities;
|
||||||
|
import org.telegram.android.LocaleController;
|
||||||
|
import org.telegram.messenger.R;
|
||||||
|
import org.telegram.messenger.TLRPC;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
public class SessionCell extends FrameLayout {
|
||||||
|
|
||||||
|
private TextView nameTextView;
|
||||||
|
private TextView onlineTextView;
|
||||||
|
private TextView detailTextView;
|
||||||
|
private TextView detailExTextView;
|
||||||
|
boolean needDivider;
|
||||||
|
private static Paint paint;
|
||||||
|
|
||||||
|
public SessionCell(Context context) {
|
||||||
|
super(context);
|
||||||
|
|
||||||
|
if (paint == null) {
|
||||||
|
paint = new Paint();
|
||||||
|
paint.setColor(0xffd9d9d9);
|
||||||
|
paint.setStrokeWidth(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
LinearLayout linearLayout = new LinearLayout(context);
|
||||||
|
linearLayout.setOrientation(LinearLayout.HORIZONTAL);
|
||||||
|
linearLayout.setWeightSum(1);
|
||||||
|
addView(linearLayout);
|
||||||
|
LayoutParams layoutParams = (LayoutParams) linearLayout.getLayoutParams();
|
||||||
|
layoutParams.width = LayoutParams.MATCH_PARENT;
|
||||||
|
layoutParams.height = AndroidUtilities.dp(30);
|
||||||
|
layoutParams.leftMargin = AndroidUtilities.dp(17);
|
||||||
|
layoutParams.rightMargin = AndroidUtilities.dp(17);
|
||||||
|
layoutParams.topMargin = AndroidUtilities.dp(11);
|
||||||
|
layoutParams.gravity = LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT;
|
||||||
|
linearLayout.setLayoutParams(layoutParams);
|
||||||
|
|
||||||
|
nameTextView = new TextView(context);
|
||||||
|
nameTextView.setTextColor(0xff212121);
|
||||||
|
nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
|
||||||
|
nameTextView.setLines(1);
|
||||||
|
nameTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
|
||||||
|
nameTextView.setMaxLines(1);
|
||||||
|
nameTextView.setSingleLine(true);
|
||||||
|
nameTextView.setEllipsize(TextUtils.TruncateAt.END);
|
||||||
|
nameTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
|
||||||
|
|
||||||
|
onlineTextView = new TextView(context);
|
||||||
|
onlineTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
|
||||||
|
onlineTextView.setGravity((LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.TOP);
|
||||||
|
|
||||||
|
if (LocaleController.isRTL) {
|
||||||
|
linearLayout.addView(onlineTextView);
|
||||||
|
linearLayout.addView(nameTextView);
|
||||||
|
} else {
|
||||||
|
linearLayout.addView(nameTextView);
|
||||||
|
linearLayout.addView(onlineTextView);
|
||||||
|
}
|
||||||
|
|
||||||
|
LinearLayout.LayoutParams layoutParams2 = (LinearLayout.LayoutParams) nameTextView.getLayoutParams();
|
||||||
|
layoutParams2.width = 0;
|
||||||
|
layoutParams2.height = LayoutParams.MATCH_PARENT;
|
||||||
|
layoutParams2.weight = 1;
|
||||||
|
if (LocaleController.isRTL) {
|
||||||
|
layoutParams2.leftMargin = AndroidUtilities.dp(10);
|
||||||
|
} else {
|
||||||
|
layoutParams2.rightMargin = AndroidUtilities.dp(10);
|
||||||
|
}
|
||||||
|
layoutParams2.gravity = LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT;
|
||||||
|
nameTextView.setLayoutParams(layoutParams2);
|
||||||
|
|
||||||
|
layoutParams2 = (LinearLayout.LayoutParams) onlineTextView.getLayoutParams();
|
||||||
|
layoutParams2.width = LayoutParams.WRAP_CONTENT;
|
||||||
|
layoutParams2.height = LayoutParams.MATCH_PARENT;
|
||||||
|
layoutParams2.topMargin = AndroidUtilities.dp(2);
|
||||||
|
layoutParams2.gravity = (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.TOP;
|
||||||
|
onlineTextView.setLayoutParams(layoutParams2);
|
||||||
|
|
||||||
|
detailTextView = new TextView(context);
|
||||||
|
detailTextView.setTextColor(0xff212121);
|
||||||
|
detailTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
|
||||||
|
detailTextView.setLines(1);
|
||||||
|
detailTextView.setMaxLines(1);
|
||||||
|
detailTextView.setSingleLine(true);
|
||||||
|
detailTextView.setEllipsize(TextUtils.TruncateAt.END);
|
||||||
|
detailTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
|
||||||
|
addView(detailTextView);
|
||||||
|
layoutParams = (LayoutParams) detailTextView.getLayoutParams();
|
||||||
|
layoutParams.width = LayoutParams.MATCH_PARENT;
|
||||||
|
layoutParams.height = LayoutParams.WRAP_CONTENT;
|
||||||
|
layoutParams.leftMargin = AndroidUtilities.dp(17);
|
||||||
|
layoutParams.rightMargin = AndroidUtilities.dp(17);
|
||||||
|
layoutParams.topMargin = AndroidUtilities.dp(36);
|
||||||
|
layoutParams.gravity = (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP;
|
||||||
|
detailTextView.setLayoutParams(layoutParams);
|
||||||
|
|
||||||
|
detailExTextView = new TextView(context);
|
||||||
|
detailExTextView.setTextColor(0xff999999);
|
||||||
|
detailExTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
|
||||||
|
detailExTextView.setLines(1);
|
||||||
|
detailExTextView.setMaxLines(1);
|
||||||
|
detailExTextView.setSingleLine(true);
|
||||||
|
detailExTextView.setEllipsize(TextUtils.TruncateAt.END);
|
||||||
|
detailExTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
|
||||||
|
addView(detailExTextView);
|
||||||
|
layoutParams = (LayoutParams) detailExTextView.getLayoutParams();
|
||||||
|
layoutParams.width = LayoutParams.MATCH_PARENT;
|
||||||
|
layoutParams.height = LayoutParams.WRAP_CONTENT;
|
||||||
|
layoutParams.leftMargin = AndroidUtilities.dp(17);
|
||||||
|
layoutParams.rightMargin = AndroidUtilities.dp(17);
|
||||||
|
layoutParams.topMargin = AndroidUtilities.dp(59);
|
||||||
|
layoutParams.gravity = (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP;
|
||||||
|
detailExTextView.setLayoutParams(layoutParams);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||||
|
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(90) + (needDivider ? 1 : 0), MeasureSpec.EXACTLY));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSession(TLRPC.TL_authorization session, boolean divider) {
|
||||||
|
needDivider = divider;
|
||||||
|
|
||||||
|
nameTextView.setText(String.format(Locale.US, "%s %s", session.app_name, session.app_version));
|
||||||
|
if ((session.flags & 1) != 0) {
|
||||||
|
onlineTextView.setText(LocaleController.getString("Online", R.string.Online));
|
||||||
|
onlineTextView.setTextColor(0xff2f8cc9);
|
||||||
|
} else {
|
||||||
|
onlineTextView.setText(LocaleController.stringForMessageListDate(session.date_active));
|
||||||
|
onlineTextView.setTextColor(0xff999999);
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
if (session.ip.length() != 0) {
|
||||||
|
stringBuilder.append(session.ip);
|
||||||
|
}
|
||||||
|
if (session.country.length() != 0) {
|
||||||
|
if (stringBuilder.length() != 0) {
|
||||||
|
stringBuilder.append(" ");
|
||||||
|
}
|
||||||
|
stringBuilder.append("— ");
|
||||||
|
stringBuilder.append(session.country);
|
||||||
|
}
|
||||||
|
detailExTextView.setText(stringBuilder);
|
||||||
|
|
||||||
|
stringBuilder = new StringBuilder();
|
||||||
|
if (session.device_model.length() != 0) {
|
||||||
|
stringBuilder.append(session.device_model);
|
||||||
|
}
|
||||||
|
if (session.system_version.length() != 0 || session.platform.length() != 0) {
|
||||||
|
if (stringBuilder.length() != 0) {
|
||||||
|
stringBuilder.append(", ");
|
||||||
|
}
|
||||||
|
if (session.platform.length() != 0) {
|
||||||
|
stringBuilder.append(session.platform);
|
||||||
|
}
|
||||||
|
if (session.system_version.length() != 0) {
|
||||||
|
if (session.platform.length() != 0) {
|
||||||
|
stringBuilder.append(" ");
|
||||||
|
}
|
||||||
|
stringBuilder.append(session.system_version);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((session.flags & 2) == 0) {
|
||||||
|
if (stringBuilder.length() != 0) {
|
||||||
|
stringBuilder.append(", ");
|
||||||
|
}
|
||||||
|
stringBuilder.append(LocaleController.getString("UnofficialApp", R.string.UnofficialApp));
|
||||||
|
stringBuilder.append(" (ID: ");
|
||||||
|
stringBuilder.append(session.api_id);
|
||||||
|
stringBuilder.append(")");
|
||||||
|
}
|
||||||
|
|
||||||
|
detailTextView.setText(stringBuilder);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDraw(Canvas canvas) {
|
||||||
|
if (needDivider) {
|
||||||
|
canvas.drawLine(getPaddingLeft(), getHeight() - 1, getWidth() - getPaddingRight(), getHeight() - 1, paint);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -36,7 +36,7 @@ import org.telegram.ui.Components.LineProgressView;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
public class SharedDocumentCell extends FrameLayout implements MediaController.FileDownloadProgressListener {
|
public class SharedDocumentCell extends FrameLayout implements MediaController.FileDownloadProgressListener {
|
||||||
|
|
||||||
private ImageView placeholderImabeView;
|
private ImageView placeholderImabeView;
|
||||||
private BackupImageView thumbImageView;
|
private BackupImageView thumbImageView;
|
||||||
|
@ -106,11 +106,11 @@ public class SharedDocumentCell extends FrameLayout implements MediaController.
|
||||||
extTextView.setLayoutParams(layoutParams);
|
extTextView.setLayoutParams(layoutParams);
|
||||||
|
|
||||||
thumbImageView = new BackupImageView(context);
|
thumbImageView = new BackupImageView(context);
|
||||||
thumbImageView.imageReceiver.setDelegate(new ImageReceiver.ImageReceiverDelegate() {
|
thumbImageView.getImageReceiver().setDelegate(new ImageReceiver.ImageReceiverDelegate() {
|
||||||
@Override
|
@Override
|
||||||
public void didSetImage(ImageReceiver imageReceiver, boolean set, boolean thumb) {
|
public void didSetImage(ImageReceiver imageReceiver, boolean set, boolean thumb) {
|
||||||
extTextView.setVisibility(set ? GONE : VISIBLE);
|
extTextView.setVisibility(set ? INVISIBLE : VISIBLE);
|
||||||
placeholderImabeView.setVisibility(set ? GONE : VISIBLE);
|
placeholderImabeView.setVisibility(set ? INVISIBLE : VISIBLE);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
addView(thumbImageView);
|
addView(thumbImageView);
|
||||||
|
@ -143,7 +143,7 @@ public class SharedDocumentCell extends FrameLayout implements MediaController.
|
||||||
nameTextView.setLayoutParams(layoutParams);
|
nameTextView.setLayoutParams(layoutParams);
|
||||||
|
|
||||||
statusImageView = new ImageView(context);
|
statusImageView = new ImageView(context);
|
||||||
statusImageView.setVisibility(GONE);
|
statusImageView.setVisibility(INVISIBLE);
|
||||||
addView(statusImageView);
|
addView(statusImageView);
|
||||||
layoutParams = (LayoutParams) statusImageView.getLayoutParams();
|
layoutParams = (LayoutParams) statusImageView.getLayoutParams();
|
||||||
layoutParams.width = LayoutParams.WRAP_CONTENT;
|
layoutParams.width = LayoutParams.WRAP_CONTENT;
|
||||||
|
@ -184,7 +184,7 @@ public class SharedDocumentCell extends FrameLayout implements MediaController.
|
||||||
progressView.setLayoutParams(layoutParams);
|
progressView.setLayoutParams(layoutParams);
|
||||||
|
|
||||||
checkBox = new CheckBox(context, R.drawable.round_check2);
|
checkBox = new CheckBox(context, R.drawable.round_check2);
|
||||||
checkBox.setVisibility(GONE);
|
checkBox.setVisibility(INVISIBLE);
|
||||||
addView(checkBox);
|
addView(checkBox);
|
||||||
layoutParams = (LayoutParams) checkBox.getLayoutParams();
|
layoutParams = (LayoutParams) checkBox.getLayoutParams();
|
||||||
layoutParams.width = AndroidUtilities.dp(22);
|
layoutParams.width = AndroidUtilities.dp(22);
|
||||||
|
@ -229,13 +229,13 @@ public class SharedDocumentCell extends FrameLayout implements MediaController.
|
||||||
extTextView.setVisibility(VISIBLE);
|
extTextView.setVisibility(VISIBLE);
|
||||||
extTextView.setText(type);
|
extTextView.setText(type);
|
||||||
} else {
|
} else {
|
||||||
extTextView.setVisibility(GONE);
|
extTextView.setVisibility(INVISIBLE);
|
||||||
}
|
}
|
||||||
if (resId == 0) {
|
if (resId == 0) {
|
||||||
placeholderImabeView.setImageResource(getThumbForNameOrMime(text, type));
|
placeholderImabeView.setImageResource(getThumbForNameOrMime(text, type));
|
||||||
placeholderImabeView.setVisibility(VISIBLE);
|
placeholderImabeView.setVisibility(VISIBLE);
|
||||||
} else {
|
} else {
|
||||||
placeholderImabeView.setVisibility(GONE);
|
placeholderImabeView.setVisibility(INVISIBLE);
|
||||||
}
|
}
|
||||||
if (thumb != null || resId != 0) {
|
if (thumb != null || resId != 0) {
|
||||||
if (thumb != null) {
|
if (thumb != null) {
|
||||||
|
@ -245,10 +245,16 @@ public class SharedDocumentCell extends FrameLayout implements MediaController.
|
||||||
}
|
}
|
||||||
thumbImageView.setVisibility(VISIBLE);
|
thumbImageView.setVisibility(VISIBLE);
|
||||||
} else {
|
} else {
|
||||||
thumbImageView.setVisibility(GONE);
|
thumbImageView.setVisibility(INVISIBLE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDetachedFromWindow() {
|
||||||
|
super.onDetachedFromWindow();
|
||||||
|
MediaController.getInstance().removeLoadingFileObserver(this);
|
||||||
|
}
|
||||||
|
|
||||||
public void setChecked(boolean checked, boolean animated) {
|
public void setChecked(boolean checked, boolean animated) {
|
||||||
if (checkBox.getVisibility() != VISIBLE) {
|
if (checkBox.getVisibility() != VISIBLE) {
|
||||||
checkBox.setVisibility(VISIBLE);
|
checkBox.setVisibility(VISIBLE);
|
||||||
|
@ -262,30 +268,40 @@ public class SharedDocumentCell extends FrameLayout implements MediaController.
|
||||||
loaded = false;
|
loaded = false;
|
||||||
loading = false;
|
loading = false;
|
||||||
|
|
||||||
int idx = -1;
|
if (document != null && document.messageOwner.media != null) {
|
||||||
String name = FileLoader.getDocumentFileName(document.messageOwner.media.document);
|
int idx = -1;
|
||||||
placeholderImabeView.setVisibility(VISIBLE);
|
String name = FileLoader.getDocumentFileName(document.messageOwner.media.document);
|
||||||
extTextView.setVisibility(VISIBLE);
|
placeholderImabeView.setVisibility(VISIBLE);
|
||||||
placeholderImabeView.setImageResource(getThumbForNameOrMime(name, document.messageOwner.media.document.mime_type));
|
extTextView.setVisibility(VISIBLE);
|
||||||
nameTextView.setText(name);
|
placeholderImabeView.setImageResource(getThumbForNameOrMime(name, document.messageOwner.media.document.mime_type));
|
||||||
extTextView.setText((idx = name.lastIndexOf(".")) == -1 ? "" : name.substring(idx + 1).toLowerCase());
|
nameTextView.setText(name);
|
||||||
if (document.messageOwner.media.document.thumb instanceof TLRPC.TL_photoSizeEmpty) {
|
extTextView.setText((idx = name.lastIndexOf(".")) == -1 ? "" : name.substring(idx + 1).toLowerCase());
|
||||||
thumbImageView.setVisibility(GONE);
|
if (document.messageOwner.media.document.thumb instanceof TLRPC.TL_photoSizeEmpty) {
|
||||||
thumbImageView.setImageBitmap(null);
|
thumbImageView.setVisibility(INVISIBLE);
|
||||||
|
thumbImageView.setImageBitmap(null);
|
||||||
|
} else {
|
||||||
|
thumbImageView.setVisibility(VISIBLE);
|
||||||
|
thumbImageView.setImage(document.messageOwner.media.document.thumb.location, "40_40", (Drawable) null);
|
||||||
|
}
|
||||||
|
long date = (long) document.messageOwner.date * 1000;
|
||||||
|
dateTextView.setText(String.format("%s, %s", Utilities.formatFileSize(document.messageOwner.media.document.size), LocaleController.formatString("formatDateAtTime", R.string.formatDateAtTime, LocaleController.formatterYear.format(new Date(date)), LocaleController.formatterDay.format(new Date(date)))));
|
||||||
} else {
|
} else {
|
||||||
thumbImageView.setVisibility(VISIBLE);
|
nameTextView.setText("");
|
||||||
thumbImageView.setImage(document.messageOwner.media.document.thumb.location, "40_40", (Drawable) null);
|
extTextView.setText("");
|
||||||
|
dateTextView.setText("");
|
||||||
|
placeholderImabeView.setVisibility(VISIBLE);
|
||||||
|
extTextView.setVisibility(VISIBLE);
|
||||||
|
thumbImageView.setVisibility(INVISIBLE);
|
||||||
|
thumbImageView.setImageBitmap(null);
|
||||||
}
|
}
|
||||||
long date = (long) document.messageOwner.date * 1000;
|
|
||||||
dateTextView.setText(String.format("%s, %s", Utilities.formatFileSize(document.messageOwner.media.document.size), LocaleController.formatString("formatDateAtTime", R.string.formatDateAtTime, LocaleController.formatterYear.format(new Date(date)), LocaleController.formatterDay.format(new Date(date)))));
|
|
||||||
setWillNotDraw(!needDivider);
|
setWillNotDraw(!needDivider);
|
||||||
progressView.setProgress(0, false);
|
progressView.setProgress(0, false);
|
||||||
|
|
||||||
updateFileExistIcon();
|
updateFileExistIcon();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateFileExistIcon() {
|
public void updateFileExistIcon() {
|
||||||
if (message != null) {
|
if (message != null && message.messageOwner.media != null) {
|
||||||
String fileName = null;
|
String fileName = null;
|
||||||
File cacheFile = null;
|
File cacheFile = null;
|
||||||
if (message.messageOwner.attachPath == null || message.messageOwner.attachPath.length() == 0 || !(new File(message.messageOwner.attachPath).exists())) {
|
if (message.messageOwner.attachPath == null || message.messageOwner.attachPath.length() == 0 || !(new File(message.messageOwner.attachPath).exists())) {
|
||||||
|
@ -296,7 +312,7 @@ public class SharedDocumentCell extends FrameLayout implements MediaController.
|
||||||
}
|
}
|
||||||
loaded = false;
|
loaded = false;
|
||||||
if (fileName == null) {
|
if (fileName == null) {
|
||||||
statusImageView.setVisibility(GONE);
|
statusImageView.setVisibility(INVISIBLE);
|
||||||
dateTextView.setPadding(0, 0, 0, 0);
|
dateTextView.setPadding(0, 0, 0, 0);
|
||||||
loading = false;
|
loading = false;
|
||||||
loaded = true;
|
loaded = true;
|
||||||
|
@ -315,15 +331,15 @@ public class SharedDocumentCell extends FrameLayout implements MediaController.
|
||||||
}
|
}
|
||||||
progressView.setProgress(progress, false);
|
progressView.setProgress(progress, false);
|
||||||
} else {
|
} else {
|
||||||
progressView.setVisibility(GONE);
|
progressView.setVisibility(INVISIBLE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
loading = false;
|
loading = false;
|
||||||
loaded = true;
|
loaded = true;
|
||||||
progressView.setVisibility(GONE);
|
progressView.setVisibility(INVISIBLE);
|
||||||
progressView.setProgress(0, false);
|
progressView.setProgress(0, false);
|
||||||
statusImageView.setVisibility(GONE);
|
statusImageView.setVisibility(INVISIBLE);
|
||||||
dateTextView.setPadding(0, 0, 0, 0);
|
dateTextView.setPadding(0, 0, 0, 0);
|
||||||
MediaController.getInstance().removeLoadingFileObserver(this);
|
MediaController.getInstance().removeLoadingFileObserver(this);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
/*
|
||||||
|
* This is the source code of Telegram for Android v. 2.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-2015.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.telegram.ui.Cells;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.util.TypedValue;
|
||||||
|
import android.view.Gravity;
|
||||||
|
import android.widget.FrameLayout;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import org.telegram.android.AndroidUtilities;
|
||||||
|
import org.telegram.android.LocaleController;
|
||||||
|
|
||||||
|
public class SharedMediaSectionCell extends FrameLayout {
|
||||||
|
|
||||||
|
private TextView textView;
|
||||||
|
|
||||||
|
public SharedMediaSectionCell(Context context) {
|
||||||
|
super(context);
|
||||||
|
|
||||||
|
textView = new TextView(getContext());
|
||||||
|
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
|
||||||
|
textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
|
||||||
|
textView.setTextColor(0xff222222);
|
||||||
|
textView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL);
|
||||||
|
addView(textView);
|
||||||
|
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams)textView.getLayoutParams();
|
||||||
|
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
|
||||||
|
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
|
||||||
|
layoutParams.leftMargin = AndroidUtilities.dp(13);
|
||||||
|
layoutParams.rightMargin = AndroidUtilities.dp(13);
|
||||||
|
layoutParams.gravity = LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT;
|
||||||
|
textView.setLayoutParams(layoutParams);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||||
|
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(40), MeasureSpec.EXACTLY));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setText(String text) {
|
||||||
|
textView.setText(text);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,254 @@
|
||||||
|
/*
|
||||||
|
* This is the source code of Telegram for Android v. 2.0.x.
|
||||||
|
* It is licensed under GNU GPL v. 2 or later.
|
||||||
|
* You should have received a copy of the license in this archive (see LICENSE).
|
||||||
|
*
|
||||||
|
* Copyright Nikolai Kudashov, 2013-2014.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.telegram.ui.Cells;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.Build;
|
||||||
|
import android.util.TypedValue;
|
||||||
|
import android.view.Gravity;
|
||||||
|
import android.view.MotionEvent;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import org.telegram.android.AndroidUtilities;
|
||||||
|
import org.telegram.android.MessageObject;
|
||||||
|
import org.telegram.messenger.ApplicationLoader;
|
||||||
|
import org.telegram.messenger.FileLoader;
|
||||||
|
import org.telegram.messenger.R;
|
||||||
|
import org.telegram.messenger.TLRPC;
|
||||||
|
import org.telegram.ui.Components.BackupImageView;
|
||||||
|
import org.telegram.ui.Components.CheckBox;
|
||||||
|
import org.telegram.ui.Components.FrameLayoutFixed;
|
||||||
|
import org.telegram.ui.PhotoViewer;
|
||||||
|
|
||||||
|
public class SharedPhotoVideoCell extends FrameLayoutFixed {
|
||||||
|
|
||||||
|
private PhotoVideoView[] photoVideoViews;
|
||||||
|
private MessageObject[] messageObjects;
|
||||||
|
private int[] indeces;
|
||||||
|
private SharedPhotoVideoCellDelegate delegate;
|
||||||
|
private int itemsCount;
|
||||||
|
private boolean isFirst;
|
||||||
|
|
||||||
|
public interface SharedPhotoVideoCellDelegate {
|
||||||
|
void didClickItem(SharedPhotoVideoCell cell, int index, MessageObject messageObject, int a);
|
||||||
|
boolean didLongClickItem(SharedPhotoVideoCell cell, int index, MessageObject messageObject, int a);
|
||||||
|
}
|
||||||
|
|
||||||
|
private class PhotoVideoView extends FrameLayoutFixed {
|
||||||
|
|
||||||
|
private BackupImageView imageView;
|
||||||
|
private TextView videoTextView;
|
||||||
|
private LinearLayout videoInfoContainer;
|
||||||
|
private View selector;
|
||||||
|
private CheckBox checkBox;
|
||||||
|
|
||||||
|
public PhotoVideoView(Context context) {
|
||||||
|
super(context);
|
||||||
|
|
||||||
|
imageView = new BackupImageView(context);
|
||||||
|
imageView.getImageReceiver().setNeedsQualityThumb(true);
|
||||||
|
imageView.getImageReceiver().setShouldGenerateQualityThumb(true);
|
||||||
|
addView(imageView);
|
||||||
|
LayoutParams layoutParams = (LayoutParams) imageView.getLayoutParams();
|
||||||
|
layoutParams.width = LayoutParams.MATCH_PARENT;
|
||||||
|
layoutParams.height = LayoutParams.MATCH_PARENT;
|
||||||
|
imageView.setLayoutParams(layoutParams);
|
||||||
|
|
||||||
|
videoInfoContainer = new LinearLayout(context);
|
||||||
|
videoInfoContainer.setOrientation(LinearLayout.HORIZONTAL);
|
||||||
|
videoInfoContainer.setBackgroundResource(R.drawable.phototime);
|
||||||
|
videoInfoContainer.setPadding(AndroidUtilities.dp(3), 0, AndroidUtilities.dp(3), 0);
|
||||||
|
videoInfoContainer.setGravity(Gravity.CENTER_VERTICAL);
|
||||||
|
addView(videoInfoContainer);
|
||||||
|
layoutParams = (LayoutParams) videoInfoContainer.getLayoutParams();
|
||||||
|
layoutParams.width = LayoutParams.MATCH_PARENT;
|
||||||
|
layoutParams.height = AndroidUtilities.dp(16);
|
||||||
|
layoutParams.gravity = Gravity.BOTTOM | Gravity.LEFT;
|
||||||
|
videoInfoContainer.setLayoutParams(layoutParams);
|
||||||
|
|
||||||
|
ImageView imageView1 = new ImageView(context);
|
||||||
|
imageView1.setImageResource(R.drawable.ic_video);
|
||||||
|
videoInfoContainer.addView(imageView1);
|
||||||
|
LinearLayout.LayoutParams layoutParams1 = (LinearLayout.LayoutParams) imageView1.getLayoutParams();
|
||||||
|
layoutParams1.width = LinearLayout.LayoutParams.WRAP_CONTENT;
|
||||||
|
layoutParams1.height = LinearLayout.LayoutParams.WRAP_CONTENT;
|
||||||
|
imageView1.setLayoutParams(layoutParams1);
|
||||||
|
|
||||||
|
videoTextView = new TextView(context);
|
||||||
|
videoTextView.setTextColor(0xffffffff);
|
||||||
|
videoTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);
|
||||||
|
videoTextView.setGravity(Gravity.CENTER_VERTICAL);
|
||||||
|
videoInfoContainer.addView(videoTextView);
|
||||||
|
layoutParams1 = (LinearLayout.LayoutParams) videoTextView.getLayoutParams();
|
||||||
|
layoutParams1.width = LinearLayout.LayoutParams.WRAP_CONTENT;
|
||||||
|
layoutParams1.height = LinearLayout.LayoutParams.WRAP_CONTENT;
|
||||||
|
layoutParams1.leftMargin = AndroidUtilities.dp(4);
|
||||||
|
layoutParams1.gravity = Gravity.CENTER_VERTICAL;
|
||||||
|
layoutParams1.bottomMargin = AndroidUtilities.dp(1);
|
||||||
|
videoTextView.setLayoutParams(layoutParams1);
|
||||||
|
|
||||||
|
selector = new View(context);
|
||||||
|
selector.setBackgroundResource(R.drawable.list_selector);
|
||||||
|
addView(selector);
|
||||||
|
layoutParams = (LayoutParams) selector.getLayoutParams();
|
||||||
|
layoutParams.width = LayoutParams.MATCH_PARENT;
|
||||||
|
layoutParams.height = LayoutParams.MATCH_PARENT;
|
||||||
|
selector.setLayoutParams(layoutParams);
|
||||||
|
|
||||||
|
checkBox = new CheckBox(context, R.drawable.round_check2);
|
||||||
|
checkBox.setVisibility(INVISIBLE);
|
||||||
|
addView(checkBox);
|
||||||
|
layoutParams = (LayoutParams) checkBox.getLayoutParams();
|
||||||
|
layoutParams.width = AndroidUtilities.dp(22);
|
||||||
|
layoutParams.height = AndroidUtilities.dp(22);
|
||||||
|
layoutParams.gravity = Gravity.RIGHT | Gravity.TOP;
|
||||||
|
layoutParams.topMargin = AndroidUtilities.dp(6);
|
||||||
|
layoutParams.rightMargin = AndroidUtilities.dp(6);
|
||||||
|
checkBox.setLayoutParams(layoutParams);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onTouchEvent(MotionEvent event) {
|
||||||
|
if (Build.VERSION.SDK_INT >= 21) {
|
||||||
|
selector.drawableHotspotChanged(event.getX(), event.getY());
|
||||||
|
}
|
||||||
|
return super.onTouchEvent(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public SharedPhotoVideoCell(Context context) {
|
||||||
|
super(context);
|
||||||
|
|
||||||
|
messageObjects = new MessageObject[6];
|
||||||
|
photoVideoViews = new PhotoVideoView[6];
|
||||||
|
indeces = new int[6];
|
||||||
|
for (int a = 0; a < 6; a++) {
|
||||||
|
photoVideoViews[a] = new PhotoVideoView(context);
|
||||||
|
addView(photoVideoViews[a]);
|
||||||
|
photoVideoViews[a].setVisibility(INVISIBLE);
|
||||||
|
photoVideoViews[a].setTag(a);
|
||||||
|
photoVideoViews[a].setOnClickListener(new OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
if (delegate != null) {
|
||||||
|
int a = (Integer) v.getTag();
|
||||||
|
delegate.didClickItem(SharedPhotoVideoCell.this, indeces[a], messageObjects[a], a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
photoVideoViews[a].setOnLongClickListener(new OnLongClickListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onLongClick(View v) {
|
||||||
|
if (delegate != null) {
|
||||||
|
int a = (Integer) v.getTag();
|
||||||
|
return delegate.didLongClickItem(SharedPhotoVideoCell.this, indeces[a], messageObjects[a], a);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDelegate(SharedPhotoVideoCellDelegate delegate) {
|
||||||
|
this.delegate = delegate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setItemsCount(int count) {
|
||||||
|
for (int a = 0; a < photoVideoViews.length; a++) {
|
||||||
|
photoVideoViews[a].setVisibility(a < count ? VISIBLE : INVISIBLE);
|
||||||
|
}
|
||||||
|
itemsCount = count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BackupImageView getImageView(int a) {
|
||||||
|
if (a >= itemsCount) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return photoVideoViews[a].imageView;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MessageObject getMessageObject(int a) {
|
||||||
|
if (a >= itemsCount) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return messageObjects[a];
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsFirst(boolean first) {
|
||||||
|
isFirst = first;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setChecked(int a, boolean checked, boolean animated) {
|
||||||
|
if (photoVideoViews[a].checkBox.getVisibility() != VISIBLE) {
|
||||||
|
photoVideoViews[a].checkBox.setVisibility(VISIBLE);
|
||||||
|
}
|
||||||
|
photoVideoViews[a].checkBox.setChecked(checked, animated);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setItem(int a, int index, MessageObject messageObject) {
|
||||||
|
messageObjects[a] = messageObject;
|
||||||
|
indeces[a] = index;
|
||||||
|
|
||||||
|
if (messageObject != null) {
|
||||||
|
photoVideoViews[a].setVisibility(VISIBLE);
|
||||||
|
|
||||||
|
PhotoVideoView photoVideoView = photoVideoViews[a];
|
||||||
|
photoVideoView.imageView.getImageReceiver().setParentMessageObject(messageObject);
|
||||||
|
photoVideoView.imageView.getImageReceiver().setVisible(!PhotoViewer.getInstance().isShowingImage(messageObject), false);
|
||||||
|
if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaVideo && messageObject.messageOwner.media.video != null) {
|
||||||
|
photoVideoView.videoInfoContainer.setVisibility(VISIBLE);
|
||||||
|
int duration = messageObject.messageOwner.media.video.duration;
|
||||||
|
int minutes = duration / 60;
|
||||||
|
int seconds = duration - minutes * 60;
|
||||||
|
photoVideoView.videoTextView.setText(String.format("%d:%02d", minutes, seconds));
|
||||||
|
if (messageObject.messageOwner.media.video.thumb != null) {
|
||||||
|
TLRPC.FileLocation location = messageObject.messageOwner.media.video.thumb.location;
|
||||||
|
photoVideoView.imageView.setImage(null, null, null, ApplicationLoader.applicationContext.getResources().getDrawable(R.drawable.photo_placeholder_in), null, location, "b", 0);
|
||||||
|
} else {
|
||||||
|
photoVideoView.imageView.setImageResource(R.drawable.photo_placeholder_in);
|
||||||
|
}
|
||||||
|
} else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto && messageObject.messageOwner.media.photo != null && !messageObject.photoThumbs.isEmpty()) {
|
||||||
|
photoVideoView.videoInfoContainer.setVisibility(INVISIBLE);
|
||||||
|
TLRPC.PhotoSize photoSize = FileLoader.getClosestPhotoSizeWithSize(messageObject.photoThumbs, 80);
|
||||||
|
photoVideoView.imageView.setImage(null, null, null, ApplicationLoader.applicationContext.getResources().getDrawable(R.drawable.photo_placeholder_in), null, photoSize.location, "b", 0);
|
||||||
|
} else {
|
||||||
|
photoVideoView.videoInfoContainer.setVisibility(INVISIBLE);
|
||||||
|
photoVideoView.imageView.setImageResource(R.drawable.photo_placeholder_in);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
photoVideoViews[a].setVisibility(INVISIBLE);
|
||||||
|
messageObjects[a] = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||||
|
int itemWidth;
|
||||||
|
if (AndroidUtilities.isTablet()) {
|
||||||
|
itemWidth = (AndroidUtilities.dp(490) - ((itemsCount + 1) * AndroidUtilities.dp(4))) / itemsCount;
|
||||||
|
} else {
|
||||||
|
itemWidth = (AndroidUtilities.displaySize.x - ((itemsCount + 1) * AndroidUtilities.dp(4))) / itemsCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int a = 0; a < itemsCount; a++) {
|
||||||
|
LayoutParams layoutParams = (LayoutParams) photoVideoViews[a].getLayoutParams();
|
||||||
|
layoutParams.topMargin = isFirst ? 0 : AndroidUtilities.dp(4);
|
||||||
|
layoutParams.leftMargin = (itemWidth + AndroidUtilities.dp(4)) * a + AndroidUtilities.dp(4);
|
||||||
|
layoutParams.width = itemWidth;
|
||||||
|
layoutParams.height = itemWidth;
|
||||||
|
layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
|
||||||
|
photoVideoViews[a].setLayoutParams(layoutParams);
|
||||||
|
}
|
||||||
|
|
||||||
|
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec((isFirst ? 0 : AndroidUtilities.dp(4)) + itemWidth, MeasureSpec.EXACTLY));
|
||||||
|
}
|
||||||
|
}
|
|
@ -26,9 +26,7 @@ public class StickerCell extends FrameLayoutFixed {
|
||||||
super(context);
|
super(context);
|
||||||
|
|
||||||
imageView = new BackupImageView(context);
|
imageView = new BackupImageView(context);
|
||||||
imageView.imageReceiver.setAspectFit(true);
|
imageView.setAspectFit(true);
|
||||||
imageView.imageReceiver.setDisableRecycle(true);
|
|
||||||
imageView.processDetach = false;
|
|
||||||
addView(imageView);
|
addView(imageView);
|
||||||
LayoutParams layoutParams = (LayoutParams) imageView.getLayoutParams();
|
LayoutParams layoutParams = (LayoutParams) imageView.getLayoutParams();
|
||||||
layoutParams.width = AndroidUtilities.dp(66);
|
layoutParams.width = AndroidUtilities.dp(66);
|
||||||
|
@ -45,8 +43,8 @@ public class StickerCell extends FrameLayoutFixed {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setPressed(boolean pressed) {
|
public void setPressed(boolean pressed) {
|
||||||
if (imageView.imageReceiver.getPressed() != pressed) {
|
if (imageView.getImageReceiver().getPressed() != pressed) {
|
||||||
imageView.imageReceiver.setPressed(pressed);
|
imageView.getImageReceiver().setPressed(pressed);
|
||||||
imageView.invalidate();
|
imageView.invalidate();
|
||||||
}
|
}
|
||||||
super.setPressed(pressed);
|
super.setPressed(pressed);
|
||||||
|
|
|
@ -97,32 +97,32 @@ public class TextCell extends FrameLayout {
|
||||||
|
|
||||||
public void setText(String text) {
|
public void setText(String text) {
|
||||||
textView.setText(text);
|
textView.setText(text);
|
||||||
imageView.setVisibility(GONE);
|
imageView.setVisibility(INVISIBLE);
|
||||||
valueTextView.setVisibility(GONE);
|
valueTextView.setVisibility(INVISIBLE);
|
||||||
valueImageView.setVisibility(GONE);
|
valueImageView.setVisibility(INVISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTextAndIcon(String text, int resId) {
|
public void setTextAndIcon(String text, int resId) {
|
||||||
textView.setText(text);
|
textView.setText(text);
|
||||||
imageView.setImageResource(resId);
|
imageView.setImageResource(resId);
|
||||||
imageView.setVisibility(VISIBLE);
|
imageView.setVisibility(VISIBLE);
|
||||||
valueTextView.setVisibility(GONE);
|
valueTextView.setVisibility(INVISIBLE);
|
||||||
valueImageView.setVisibility(GONE);
|
valueImageView.setVisibility(INVISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTextAndValue(String text, String value) {
|
public void setTextAndValue(String text, String value) {
|
||||||
textView.setText(text);
|
textView.setText(text);
|
||||||
valueTextView.setText(value);
|
valueTextView.setText(value);
|
||||||
valueTextView.setVisibility(VISIBLE);
|
valueTextView.setVisibility(VISIBLE);
|
||||||
imageView.setVisibility(GONE);
|
imageView.setVisibility(INVISIBLE);
|
||||||
valueImageView.setVisibility(GONE);
|
valueImageView.setVisibility(INVISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTextAndValueDrawable(String text, Drawable drawable) {
|
public void setTextAndValueDrawable(String text, Drawable drawable) {
|
||||||
textView.setText(text);
|
textView.setText(text);
|
||||||
valueImageView.setVisibility(VISIBLE);
|
valueImageView.setVisibility(VISIBLE);
|
||||||
valueImageView.setImageDrawable(drawable);
|
valueImageView.setImageDrawable(drawable);
|
||||||
valueTextView.setVisibility(GONE);
|
valueTextView.setVisibility(INVISIBLE);
|
||||||
imageView.setVisibility(GONE);
|
imageView.setVisibility(INVISIBLE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue