正在查看: Telegram v11.13.0 应用的 ImageLoader.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: Telegram v11.13.0 应用的 ImageLoader.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package org.telegram.messenger;
import android.app.ActivityManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.SystemClock;
import android.text.TextUtils;
import android.util.SparseArray;
import androidx.core.graphics.ColorUtils;
import com.android.billingclient.api.zzg$;
import j$.util.concurrent.ConcurrentHashMap;
import j$.util.function.Consumer;
import j$.util.stream.Stream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.RandomAccessFile;
import java.net.HttpURLConnection;
import java.nio.file.CopyOption;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.zip.GZIPInputStream;
import org.telegram.DispatchQueuePriority;
import org.telegram.messenger.FileLoader;
import org.telegram.messenger.FilePathDatabase;
import org.telegram.messenger.ImageLoader;
import org.telegram.messenger.ImageReceiver;
import org.telegram.tgnet.TLObject;
import org.telegram.tgnet.TLRPC;
import org.telegram.ui.Cells.ChatMessageCell;
import org.telegram.ui.Components.AnimatedFileDrawable;
import org.telegram.ui.Components.BackgroundGradientDrawable;
import org.telegram.ui.Components.MotionBackgroundDrawable;
import org.telegram.ui.Components.Point;
import org.telegram.ui.Components.RLottieDrawable;
import org.telegram.ui.web.WebInstantView;
public class ImageLoader {
public static final String AUTOPLAY_FILTER = "g";
public static final int CACHE_TYPE_CACHE = 1;
public static final int CACHE_TYPE_ENCRYPTED = 2;
public static final int CACHE_TYPE_NONE = 0;
private static final boolean DEBUG_MODE = false;
private boolean canForce8888;
private LruCache<BitmapDrawable> lottieMemCache;
private LruCache<BitmapDrawable> memCache;
private LruCache<BitmapDrawable> smallImagesMemCache;
private LruCache<BitmapDrawable> wallpaperMemCache;
private static ThreadLocal<byte[]> bytesLocal = new ThreadLocal<>();
private static ThreadLocal<byte[]> bytesThumbLocal = new ThreadLocal<>();
private static byte[] header = new byte[12];
private static byte[] headerThumb = new byte[12];
private static volatile ImageLoader Instance = null;
private HashMap<String, Integer> bitmapUseCounts = new HashMap<>();
ArrayList<AnimatedFileDrawable> cachedAnimatedFileDrawables = new ArrayList<>();
private HashMap<String, CacheImage> imageLoadingByUrl = new HashMap<>();
private HashMap<String, CacheImage> imageLoadingByUrlPframe = new HashMap<>();
public ConcurrentHashMap<String, CacheImage> imageLoadingByKeys = new ConcurrentHashMap<>();
public HashSet<String> imageLoadingKeys = new HashSet<>();
private SparseArray<CacheImage> imageLoadingByTag = new SparseArray<>();
private HashMap<String, ThumbGenerateInfo> waitingForQualityThumb = new HashMap<>();
private SparseArray<String> waitingForQualityThumbByTag = new SparseArray<>();
private LinkedList<HttpImageTask> httpTasks = new LinkedList<>();
private LinkedList<ArtworkLoadTask> artworkTasks = new LinkedList<>();
private DispatchQueuePriority cacheOutQueue = new DispatchQueuePriority("cacheOutQueue");
private DispatchQueue cacheThumbOutQueue = new DispatchQueue("cacheThumbOutQueue");
private DispatchQueue thumbGeneratingQueue = new DispatchQueue("thumbGeneratingQueue");
private DispatchQueue imageLoadQueue = new DispatchQueue("imageLoadQueue");
private HashMap<String, String> replacedBitmaps = new HashMap<>();
private ConcurrentHashMap<String, long[]> fileProgresses = new ConcurrentHashMap<>();
private HashMap<String, ThumbGenerateTask> thumbGenerateTasks = new HashMap<>();
private HashMap<String, Integer> forceLoadingImages = new HashMap<>();
private int currentHttpTasksCount = 0;
private int currentArtworkTasksCount = 0;
private ConcurrentHashMap<String, WebFile> testWebFile = new ConcurrentHashMap<>();
private LinkedList<HttpFileTask> httpFileLoadTasks = new LinkedList<>();
private HashMap<String, HttpFileTask> httpFileLoadTasksByKeys = new HashMap<>();
private HashMap<String, Runnable> retryHttpsTasks = new HashMap<>();
private int currentHttpFileLoadTasksCount = 0;
private String ignoreRemoval = null;
private volatile long lastCacheOutTime = 0;
private int lastImageNum = 0;
private File telegramPath = null;
class AnonymousClass5 implements FileLoader.FileLoaderDelegate {
final int val$currentAccount;
AnonymousClass5(int i) {
this.val$currentAccount = i;
}
public void lambda$fileDidFailedLoad$6(String str, int i, int i2) {
ImageLoader.this.fileDidFailedLoad(str, i);
NotificationCenter.getInstance(i2).lambda$postNotificationNameOnUIThread$1(NotificationCenter.fileLoadFailed, str, Integer.valueOf(i));
}
public static void lambda$fileDidFailedUpload$3(int i, String str, boolean z) {
NotificationCenter.getInstance(i).lambda$postNotificationNameOnUIThread$1(NotificationCenter.fileUploadFailed, str, Boolean.valueOf(z));
}
public void lambda$fileDidFailedUpload$4(final int i, final String str, final boolean z) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
ImageLoader.AnonymousClass5.lambda$fileDidFailedUpload$3(i, str, z);
}
});
ImageLoader.this.fileProgresses.remove(str);
}
public void lambda$fileDidLoaded$5(File file, String str, int i, Object obj, int i2) {
FilePathDatabase.FileMeta fileMetadataFromParent;
if (file != null && ((str.endsWith(".mp4") || str.endsWith(".jpg")) && (fileMetadataFromParent = FileLoader.getFileMetadataFromParent(i, obj)) != null)) {
MessageObject messageObject = obj instanceof MessageObject ? (MessageObject) obj : null;
long j = fileMetadataFromParent.dialogId;
if (SaveToGallerySettingsHelper.needSave(j >= 0 ? 1 : ChatObject.isChannelAndNotMegaGroup(MessagesController.getInstance(i).getChat(Long.valueOf(-j))) ? 4 : 2, fileMetadataFromParent, messageObject, i)) {
AndroidUtilities.addMediaToGallery(file.toString());
}
}
NotificationCenter.getInstance(i).lambda$postNotificationNameOnUIThread$1(NotificationCenter.fileLoaded, str, file);
ImageLoader.this.fileDidLoaded(str, file, i2);
}
public static void lambda$fileDidUploaded$1(int i, String str, TLRPC.InputFile inputFile, TLRPC.InputEncryptedFile inputEncryptedFile, byte[] bArr, byte[] bArr2, long j) {
NotificationCenter.getInstance(i).lambda$postNotificationNameOnUIThread$1(NotificationCenter.fileUploaded, str, inputFile, inputEncryptedFile, bArr, bArr2, Long.valueOf(j));
}
public void lambda$fileDidUploaded$2(final int i, final String str, final TLRPC.InputFile inputFile, final TLRPC.InputEncryptedFile inputEncryptedFile, final byte[] bArr, final byte[] bArr2, final long j) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
ImageLoader.AnonymousClass5.lambda$fileDidUploaded$1(i, str, inputFile, inputEncryptedFile, bArr, bArr2, j);
}
});
ImageLoader.this.fileProgresses.remove(str);
}
public void lambda$fileLoadProgressChanged$7(String str, FileLoadOperation fileLoadOperation) {
CacheImage cacheImage = (CacheImage) ImageLoader.this.imageLoadingByUrlPframe.remove(str);
if (cacheImage == null) {
return;
}
ImageLoader.this.imageLoadingByUrl.remove(str);
ArrayList arrayList = new ArrayList();
for (int i = 0; i < cacheImage.imageReceiverArray.size(); i++) {
String str2 = cacheImage.keys.get(i);
String str3 = cacheImage.filters.get(i);
int intValue = cacheImage.types.get(i).intValue();
ImageReceiver imageReceiver = cacheImage.imageReceiverArray.get(i);
int intValue2 = cacheImage.imageReceiverGuidsArray.get(i).intValue();
CacheImage cacheImage2 = (CacheImage) ImageLoader.this.imageLoadingByKeys.get(str2);
if (cacheImage2 == null) {
cacheImage2 = new CacheImage();
cacheImage2.priority = cacheImage.priority;
cacheImage2.secureDocument = cacheImage.secureDocument;
cacheImage2.currentAccount = cacheImage.currentAccount;
cacheImage2.finalFilePath = fileLoadOperation.getCurrentFile();
cacheImage2.parentObject = cacheImage.parentObject;
cacheImage2.isPFrame = cacheImage.isPFrame;
cacheImage2.key = str2;
cacheImage2.imageLocation = cacheImage.imageLocation;
cacheImage2.type = intValue;
cacheImage2.ext = cacheImage.ext;
cacheImage2.encryptionKeyPath = cacheImage.encryptionKeyPath;
cacheImage2.cacheTask = ImageLoader.this.new CacheOutTask(cacheImage2);
cacheImage2.filter = str3;
cacheImage2.imageType = cacheImage.imageType;
cacheImage2.cacheType = cacheImage.cacheType;
ImageLoader.this.imageLoadingByKeys.put(str2, cacheImage2);
ImageLoader.this.imageLoadingKeys.add(ImageLoader.cutFilter(str2));
arrayList.add(cacheImage2.cacheTask);
}
cacheImage2.addImageReceiver(imageReceiver, str2, str3, intValue, intValue2);
}
for (int i2 = 0; i2 < arrayList.size(); i2++) {
CacheOutTask cacheOutTask = (CacheOutTask) arrayList.get(i2);
if (cacheOutTask.cacheImage.type == 1) {
ImageLoader.this.cacheThumbOutQueue.postRunnable(cacheOutTask);
} else {
ImageLoader.this.cacheOutQueue.postRunnable(cacheOutTask, cacheOutTask.cacheImage.priority);
}
}
}
public static void lambda$fileLoadProgressChanged$8(int i, String str, long j, long j2) {
NotificationCenter.getInstance(i).lambda$postNotificationNameOnUIThread$1(NotificationCenter.fileLoadProgressChanged, str, Long.valueOf(j), Long.valueOf(j2));
}
public static void lambda$fileUploadProgressChanged$0(int i, String str, long j, long j2, boolean z) {
NotificationCenter.getInstance(i).lambda$postNotificationNameOnUIThread$1(NotificationCenter.fileUploadProgressChanged, str, Long.valueOf(j), Long.valueOf(j2), Boolean.valueOf(z));
}
@Override
public void fileDidFailedLoad(final String str, final int i) {
ImageLoader.this.fileProgresses.remove(str);
final int i2 = this.val$currentAccount;
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
ImageLoader.AnonymousClass5.this.lambda$fileDidFailedLoad$6(str, i, i2);
}
});
}
@Override
public void fileDidFailedUpload(final String str, final boolean z) {
DispatchQueue dispatchQueue = Utilities.stageQueue;
final int i = this.val$currentAccount;
dispatchQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ImageLoader.AnonymousClass5.this.lambda$fileDidFailedUpload$4(i, str, z);
}
});
}
@Override
public void fileDidLoaded(final String str, final File file, final Object obj, final int i) {
ImageLoader.this.fileProgresses.remove(str);
final int i2 = this.val$currentAccount;
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
ImageLoader.AnonymousClass5.this.lambda$fileDidLoaded$5(file, str, i2, obj, i);
}
});
}
@Override
public void fileDidUploaded(final String str, final TLRPC.InputFile inputFile, final TLRPC.InputEncryptedFile inputEncryptedFile, final byte[] bArr, final byte[] bArr2, final long j) {
DispatchQueue dispatchQueue = Utilities.stageQueue;
final int i = this.val$currentAccount;
dispatchQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ImageLoader.AnonymousClass5.this.lambda$fileDidUploaded$2(i, str, inputFile, inputEncryptedFile, bArr, bArr2, j);
}
});
}
@Override
public void fileLoadProgressChanged(final FileLoadOperation fileLoadOperation, final String str, final long j, final long j2) {
ImageLoader.this.fileProgresses.put(str, new long[]{j, j2});
if (!ImageLoader.this.imageLoadingByUrlPframe.isEmpty() && fileLoadOperation.checkPrefixPreloadFinished()) {
ImageLoader.this.imageLoadQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ImageLoader.AnonymousClass5.this.lambda$fileLoadProgressChanged$7(str, fileLoadOperation);
}
});
}
long elapsedRealtime = SystemClock.elapsedRealtime();
long j3 = fileLoadOperation.lastProgressUpdateTime;
if (j3 == 0 || j3 < elapsedRealtime - 500 || j == 0) {
fileLoadOperation.lastProgressUpdateTime = elapsedRealtime;
final int i = this.val$currentAccount;
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
ImageLoader.AnonymousClass5.lambda$fileLoadProgressChanged$8(i, str, j, j2);
}
});
}
}
@Override
public void fileUploadProgressChanged(FileUploadOperation fileUploadOperation, final String str, final long j, final long j2, final boolean z) {
ImageLoader.this.fileProgresses.put(str, new long[]{j, j2});
long elapsedRealtime = SystemClock.elapsedRealtime();
long j3 = fileUploadOperation.lastProgressUpdateTime;
if (j3 == 0 || j3 < elapsedRealtime - 100 || j == j2) {
fileUploadOperation.lastProgressUpdateTime = elapsedRealtime;
final int i = this.val$currentAccount;
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
ImageLoader.AnonymousClass5.lambda$fileUploadProgressChanged$0(i, str, j, j2, z);
}
});
}
}
}
class AnonymousClass6 extends BroadcastReceiver {
AnonymousClass6() {
}
public void lambda$onReceive$0() {
ImageLoader.this.checkMediaPaths();
}
@Override
public void onReceive(Context context, Intent intent) {
if (BuildVars.LOGS_ENABLED) {
FileLog.d("file system changed");
}
Runnable runnable = new Runnable() {
@Override
public final void run() {
ImageLoader.AnonymousClass6.this.lambda$onReceive$0();
}
};
if ("android.intent.action.MEDIA_UNMOUNTED".equals(intent.getAction())) {
AndroidUtilities.runOnUIThread(runnable, 1000L);
} else {
runnable.run();
}
}
}
static class AnonymousClass7 {
static final int[] $SwitchMap$android$graphics$Bitmap$CompressFormat;
static {
Bitmap.CompressFormat compressFormat;
Bitmap.CompressFormat compressFormat2;
int[] iArr = new int[Bitmap.CompressFormat.values().length];
$SwitchMap$android$graphics$Bitmap$CompressFormat = iArr;
try {
iArr[Bitmap.CompressFormat.WEBP.ordinal()] = 1;
} catch (NoSuchFieldError unused) {
}
try {
int[] iArr2 = $SwitchMap$android$graphics$Bitmap$CompressFormat;
compressFormat2 = Bitmap.CompressFormat.WEBP_LOSSY;
iArr2[compressFormat2.ordinal()] = 2;
} catch (NoSuchFieldError unused2) {
}
try {
int[] iArr3 = $SwitchMap$android$graphics$Bitmap$CompressFormat;
compressFormat = Bitmap.CompressFormat.WEBP_LOSSLESS;
iArr3[compressFormat.ordinal()] = 3;
} catch (NoSuchFieldError unused3) {
}
}
}
class ArtworkLoadTask extends AsyncTask<Void, Void, String> {
private CacheImage cacheImage;
private boolean canRetry = true;
private HttpURLConnection httpConnection;
private boolean small;
public ArtworkLoadTask(CacheImage cacheImage) {
this.cacheImage = cacheImage;
this.small = Uri.parse(cacheImage.imageLocation.path).getQueryParameter("s") != null;
}
public void lambda$onCancelled$2() {
ImageLoader.this.runArtworkTasks(true);
}
public void lambda$onPostExecute$0(String str) {
CacheImage cacheImage = this.cacheImage;
cacheImage.httpTask = ImageLoader.this.new HttpImageTask(cacheImage, 0, str);
ImageLoader.this.httpTasks.add(this.cacheImage.httpTask);
ImageLoader.this.runHttpTasks(false);
}
public void lambda$onPostExecute$1() {
ImageLoader.this.runArtworkTasks(true);
}
@Override
public java.lang.String doInBackground(java.lang.Void... r8) {
throw new UnsupportedOperationException("Method not decompiled: org.telegram.messenger.ImageLoader.ArtworkLoadTask.doInBackground(java.lang.Void[]):java.lang.String");
}
@Override
protected void onCancelled() {
ImageLoader.this.imageLoadQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ImageLoader.ArtworkLoadTask.this.lambda$onCancelled$2();
}
});
}
@Override
public void onPostExecute(final String str) {
if (str != null) {
ImageLoader.this.imageLoadQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ImageLoader.ArtworkLoadTask.this.lambda$onPostExecute$0(str);
}
});
} else if (this.canRetry) {
ImageLoader.this.artworkLoadError(this.cacheImage.url);
}
ImageLoader.this.imageLoadQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ImageLoader.ArtworkLoadTask.this.lambda$onPostExecute$1();
}
});
}
}
class CacheImage {
protected ArtworkLoadTask artworkTask;
protected CacheOutTask cacheTask;
protected int cacheType;
protected int currentAccount;
protected File encryptionKeyPath;
protected String ext;
protected String filter;
protected ArrayList<String> filters;
protected File finalFilePath;
protected HttpImageTask httpTask;
protected ImageLocation imageLocation;
protected ArrayList<ImageReceiver> imageReceiverArray;
protected ArrayList<Integer> imageReceiverGuidsArray;
protected int imageType;
public boolean isPFrame;
protected String key;
protected ArrayList<String> keys;
protected Object parentObject;
public int priority;
public Runnable runningTask;
protected SecureDocument secureDocument;
protected long size;
protected File tempFilePath;
protected int type;
protected ArrayList<Integer> types;
protected String url;
private CacheImage() {
this.priority = 1;
this.imageReceiverArray = new ArrayList<>();
this.imageReceiverGuidsArray = new ArrayList<>();
this.keys = new ArrayList<>();
this.filters = new ArrayList<>();
this.types = new ArrayList<>();
}
public void lambda$setImageAndClear$0(android.graphics.drawable.Drawable r10, java.util.ArrayList r11, java.util.ArrayList r12, java.lang.String r13) {
throw new UnsupportedOperationException("Method not decompiled: org.telegram.messenger.ImageLoader.CacheImage.lambda$setImageAndClear$0(android.graphics.drawable.Drawable, java.util.ArrayList, java.util.ArrayList, java.lang.String):void");
}
public void addImageReceiver(ImageReceiver imageReceiver, String str, String str2, int i, int i2) {
int indexOf = this.imageReceiverArray.indexOf(imageReceiver);
if (indexOf >= 0 && Objects.equals(this.imageReceiverArray.get(indexOf).getImageKey(), str)) {
this.imageReceiverGuidsArray.set(indexOf, Integer.valueOf(i2));
return;
}
this.imageReceiverArray.add(imageReceiver);
this.imageReceiverGuidsArray.add(Integer.valueOf(i2));
this.keys.add(str);
this.filters.add(str2);
this.types.add(Integer.valueOf(i));
ImageLoader.this.imageLoadingByTag.put(imageReceiver.getTag(i), this);
}
void changePriority(int i) {
TLRPC.Document document;
?? r6;
TLObject tLObject;
TLRPC.TL_fileLocationToBeDeprecated tL_fileLocationToBeDeprecated;
TLRPC.TL_fileLocationToBeDeprecated tL_fileLocationToBeDeprecated2;
?? r9;
?? r7;
ImageLocation imageLocation = this.imageLocation;
if (imageLocation != null) {
TLRPC.TL_fileLocationToBeDeprecated tL_fileLocationToBeDeprecated3 = imageLocation.location;
if (tL_fileLocationToBeDeprecated3 != null) {
r9 = this.ext;
tL_fileLocationToBeDeprecated = tL_fileLocationToBeDeprecated3;
document = null;
r6 = null;
r7 = 0;
} else {
TLRPC.Document document2 = imageLocation.document;
if (document2 != null) {
document = document2;
r6 = null;
} else {
SecureDocument secureDocument = imageLocation.secureDocument;
if (secureDocument != null) {
r6 = secureDocument;
document = null;
tL_fileLocationToBeDeprecated2 = null;
tL_fileLocationToBeDeprecated = tL_fileLocationToBeDeprecated2;
tLObject = tL_fileLocationToBeDeprecated2;
r9 = tL_fileLocationToBeDeprecated;
r7 = tLObject;
} else {
TLObject tLObject2 = imageLocation.webFile;
if (tLObject2 != null) {
tLObject = tLObject2;
document = null;
r6 = null;
tL_fileLocationToBeDeprecated = null;
r9 = tL_fileLocationToBeDeprecated;
r7 = tLObject;
} else {
document = null;
r6 = null;
}
}
}
tL_fileLocationToBeDeprecated2 = r6;
tL_fileLocationToBeDeprecated = tL_fileLocationToBeDeprecated2;
tLObject = tL_fileLocationToBeDeprecated2;
r9 = tL_fileLocationToBeDeprecated;
r7 = tLObject;
}
FileLoader.getInstance(this.currentAccount).changePriority(i, document, r6, r7, tL_fileLocationToBeDeprecated, r9, null);
}
}
public void removeImageReceiver(ImageReceiver imageReceiver) {
int i = this.type;
int i2 = 0;
while (i2 < this.imageReceiverArray.size()) {
ImageReceiver imageReceiver2 = this.imageReceiverArray.get(i2);
if (imageReceiver2 == null || imageReceiver2 == imageReceiver) {
this.imageReceiverArray.remove(i2);
this.imageReceiverGuidsArray.remove(i2);
this.keys.remove(i2);
this.filters.remove(i2);
i = this.types.remove(i2).intValue();
if (imageReceiver2 != null) {
ImageLoader.this.imageLoadingByTag.remove(imageReceiver2.getTag(i));
}
i2--;
}
i2++;
}
if (this.imageReceiverArray.isEmpty()) {
if (this.imageLocation != null && !ImageLoader.this.forceLoadingImages.containsKey(this.key)) {
ImageLocation imageLocation = this.imageLocation;
if (imageLocation.location != null) {
FileLoader.getInstance(this.currentAccount).cancelLoadFile(this.imageLocation.location, this.ext);
} else if (imageLocation.document != null) {
FileLoader.getInstance(this.currentAccount).cancelLoadFile(this.imageLocation.document);
} else if (imageLocation.secureDocument != null) {
FileLoader.getInstance(this.currentAccount).cancelLoadFile(this.imageLocation.secureDocument);
} else if (imageLocation.webFile != null) {
FileLoader.getInstance(this.currentAccount).cancelLoadFile(this.imageLocation.webFile);
}
}
if (this.cacheTask != null) {
ImageLoader imageLoader = ImageLoader.this;
if (i == 1) {
imageLoader.cacheThumbOutQueue.cancelRunnable(this.cacheTask);
} else {
imageLoader.cacheOutQueue.cancelRunnable(this.cacheTask);
ImageLoader.this.cacheOutQueue.cancelRunnable(this.runningTask);
}
this.cacheTask.cancel();
this.cacheTask = null;
}
if (this.httpTask != null) {
ImageLoader.this.httpTasks.remove(this.httpTask);
this.httpTask.cancel(true);
this.httpTask = null;
}
if (this.artworkTask != null) {
ImageLoader.this.artworkTasks.remove(this.artworkTask);
this.artworkTask.cancel(true);
this.artworkTask = null;
}
if (this.url != null) {
ImageLoader.this.imageLoadingByUrl.remove(this.url);
}
if (this.url != null) {
ImageLoader.this.imageLoadingByUrlPframe.remove(this.url);
}
String str = this.key;
if (str != null) {
ImageLoader.this.imageLoadingByKeys.remove(str);
ImageLoader.this.imageLoadingKeys.remove(ImageLoader.cutFilter(this.key));
}
}
}
public void replaceImageReceiver(ImageReceiver imageReceiver, String str, String str2, int i, int i2) {
int indexOf = this.imageReceiverArray.indexOf(imageReceiver);
if (indexOf == -1) {
return;
}
if (this.types.get(indexOf).intValue() != i) {
ArrayList<ImageReceiver> arrayList = this.imageReceiverArray;
indexOf = arrayList.subList(indexOf + 1, arrayList.size()).indexOf(imageReceiver);
if (indexOf == -1) {
return;
}
}
this.imageReceiverGuidsArray.set(indexOf, Integer.valueOf(i2));
this.keys.set(indexOf, str);
this.filters.set(indexOf, str2);
}
public void setImageAndClear(final Drawable drawable, final String str) {
if (drawable != null) {
final ArrayList arrayList = new ArrayList(this.imageReceiverArray);
final ArrayList arrayList2 = new ArrayList(this.imageReceiverGuidsArray);
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
ImageLoader.CacheImage.this.lambda$setImageAndClear$0(drawable, arrayList, arrayList2, str);
}
});
}
for (int i = 0; i < this.imageReceiverArray.size(); i++) {
ImageLoader.this.imageLoadingByTag.remove(this.imageReceiverArray.get(i).getTag(this.type));
}
this.imageReceiverArray.clear();
this.imageReceiverGuidsArray.clear();
if (this.url != null) {
ImageLoader.this.imageLoadingByUrl.remove(this.url);
}
if (this.url != null) {
ImageLoader.this.imageLoadingByUrlPframe.remove(this.url);
}
String str2 = this.key;
if (str2 != null) {
ImageLoader.this.imageLoadingByKeys.remove(str2);
ImageLoader.this.imageLoadingKeys.remove(ImageLoader.cutFilter(this.key));
}
}
public void setImageReceiverGuid(ImageReceiver imageReceiver, int i) {
int indexOf = this.imageReceiverArray.indexOf(imageReceiver);
if (indexOf == -1) {
return;
}
this.imageReceiverGuidsArray.set(indexOf, Integer.valueOf(i));
}
}
class CacheOutTask implements Runnable {
private CacheImage cacheImage;
private boolean isCancelled;
private Thread runningThread;
private final Object sync = new Object();
public CacheOutTask(CacheImage cacheImage) {
this.cacheImage = cacheImage;
}
private Bitmap applyWallpaperSetting(Bitmap bitmap, TLRPC.WallPaper wallPaper) {
int i;
if (!wallPaper.pattern || wallPaper.settings == null) {
TLRPC.WallPaperSettings wallPaperSettings = wallPaper.settings;
return (wallPaperSettings == null || !wallPaperSettings.blur) ? bitmap : Utilities.blurWallpaper(bitmap);
}
Bitmap createBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(createBitmap);
TLRPC.WallPaperSettings wallPaperSettings2 = wallPaper.settings;
boolean z = true;
if (wallPaperSettings2.second_background_color == 0) {
i = AndroidUtilities.getPatternColor(wallPaperSettings2.background_color);
canvas.drawColor(ColorUtils.setAlphaComponent(wallPaper.settings.background_color, NotificationCenter.reloadInterface));
} else {
int i2 = wallPaperSettings2.third_background_color;
int alphaComponent = ColorUtils.setAlphaComponent(wallPaperSettings2.background_color, NotificationCenter.reloadInterface);
if (i2 == 0) {
int alphaComponent2 = ColorUtils.setAlphaComponent(wallPaper.settings.second_background_color, NotificationCenter.reloadInterface);
int averageColor = AndroidUtilities.getAverageColor(alphaComponent, alphaComponent2);
GradientDrawable gradientDrawable = new GradientDrawable(BackgroundGradientDrawable.getGradientOrientation(wallPaper.settings.rotation), new int[]{alphaComponent, alphaComponent2});
gradientDrawable.setBounds(0, 0, createBitmap.getWidth(), createBitmap.getHeight());
gradientDrawable.draw(canvas);
i = averageColor;
} else {
int alphaComponent3 = ColorUtils.setAlphaComponent(wallPaper.settings.second_background_color, NotificationCenter.reloadInterface);
int alphaComponent4 = ColorUtils.setAlphaComponent(wallPaper.settings.third_background_color, NotificationCenter.reloadInterface);
int i3 = wallPaper.settings.fourth_background_color;
int alphaComponent5 = i3 == 0 ? 0 : ColorUtils.setAlphaComponent(i3, NotificationCenter.reloadInterface);
int patternColor = MotionBackgroundDrawable.getPatternColor(alphaComponent, alphaComponent3, alphaComponent4, alphaComponent5);
MotionBackgroundDrawable motionBackgroundDrawable = new MotionBackgroundDrawable();
motionBackgroundDrawable.setColors(alphaComponent, alphaComponent3, alphaComponent4, alphaComponent5);
motionBackgroundDrawable.setBounds(0, 0, createBitmap.getWidth(), createBitmap.getHeight());
motionBackgroundDrawable.setPatternBitmap(wallPaper.settings.intensity, bitmap);
motionBackgroundDrawable.draw(canvas);
i = patternColor;
z = false;
}
}
if (z) {
Paint paint = new Paint(2);
paint.setColorFilter(new PorterDuffColorFilter(i, PorterDuff.Mode.SRC_IN));
paint.setAlpha((int) ((wallPaper.settings.intensity / 100.0f) * 255.0f));
canvas.drawBitmap(bitmap, 0.0f, 0.0f, paint);
}
return createBitmap;
}
public void lambda$onPostExecute$0(Drawable drawable, String str) {
this.cacheImage.setImageAndClear(drawable, str);
}
public void lambda$onPostExecute$1(final android.graphics.drawable.Drawable r6) {
throw new UnsupportedOperationException("Method not decompiled: org.telegram.messenger.ImageLoader.CacheOutTask.lambda$onPostExecute$1(android.graphics.drawable.Drawable):void");
}
private void loadLastFrame(RLottieDrawable rLottieDrawable, int i, int i2, boolean z, boolean z2) {
Bitmap createBitmap;
Canvas canvas;
Drawable bitmapDrawable;
if (z && z2) {
float f = i * 1.2f;
float f2 = i2 * 1.2f;
createBitmap = Bitmap.createBitmap((int) f, (int) f2, Bitmap.Config.ARGB_8888);
canvas = new Canvas(createBitmap);
canvas.scale(2.0f, 2.0f, f / 2.0f, f2 / 2.0f);
} else {
createBitmap = Bitmap.createBitmap(i, i2, Bitmap.Config.ARGB_8888);
canvas = new Canvas(createBitmap);
}
rLottieDrawable.prepareForGenerateCache();
Bitmap createBitmap2 = Bitmap.createBitmap(rLottieDrawable.getIntrinsicWidth(), rLottieDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
rLottieDrawable.setGeneratingFrame(z ? rLottieDrawable.getFramesCount() - 1 : 0);
rLottieDrawable.getNextFrame(createBitmap2);
rLottieDrawable.releaseForGenerateCache();
canvas.save();
if (!z || !z2) {
canvas.scale(createBitmap2.getWidth() / i, createBitmap2.getHeight() / i2, i / 2.0f, i2 / 2.0f);
}
Paint paint = new Paint(1);
paint.setFilterBitmap(true);
if (z && z2) {
canvas.drawBitmap(createBitmap2, (createBitmap.getWidth() - createBitmap2.getWidth()) / 2.0f, (createBitmap.getHeight() - createBitmap2.getHeight()) / 2.0f, paint);
bitmapDrawable = new ImageReceiver.ReactionLastFrame(createBitmap);
} else {
canvas.drawBitmap(createBitmap2, 0.0f, 0.0f, paint);
bitmapDrawable = new BitmapDrawable(createBitmap);
}
rLottieDrawable.recycle(false);
createBitmap2.recycle();
onPostExecute(bitmapDrawable);
}
private void onPostExecute(final Drawable drawable) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
ImageLoader.CacheOutTask.this.lambda$onPostExecute$1(drawable);
}
});
}
public void cancel() {
synchronized (this.sync) {
try {
this.isCancelled = true;
Thread thread = this.runningThread;
if (thread != null) {
thread.interrupt();
}
} catch (Exception unused) {
}
}
}
@Override
public void run() {
throw new UnsupportedOperationException("Method not decompiled: org.telegram.messenger.ImageLoader.CacheOutTask.run():void");
}
}
class HttpFileTask extends AsyncTask<Void, Void, Boolean> {
private int currentAccount;
private String ext;
private int fileSize;
private long lastProgressTime;
private File tempFile;
private String url;
private RandomAccessFile fileOutputStream = null;
private boolean canRetry = true;
public HttpFileTask(String str, File file, String str2, int i) {
this.url = str;
this.tempFile = file;
this.ext = str2;
this.currentAccount = i;
}
public void lambda$reportProgress$0(long j, long j2) {
NotificationCenter.getInstance(this.currentAccount).lambda$postNotificationNameOnUIThread$1(NotificationCenter.fileLoadProgressChanged, this.url, Long.valueOf(j), Long.valueOf(j2));
}
public void lambda$reportProgress$1(final long j, final long j2) {
ImageLoader.this.fileProgresses.put(this.url, new long[]{j, j2});
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
ImageLoader.HttpFileTask.this.lambda$reportProgress$0(j, j2);
}
});
}
private void reportProgress(final long j, final long j2) {
long elapsedRealtime = SystemClock.elapsedRealtime();
if (j != j2) {
long j3 = this.lastProgressTime;
if (j3 != 0 && j3 >= elapsedRealtime - 100) {
return;
}
}
this.lastProgressTime = elapsedRealtime;
Utilities.stageQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ImageLoader.HttpFileTask.this.lambda$reportProgress$1(j, j2);
}
});
}
@Override
public java.lang.Boolean doInBackground(java.lang.Void... r12) {
throw new UnsupportedOperationException("Method not decompiled: org.telegram.messenger.ImageLoader.HttpFileTask.doInBackground(java.lang.Void[]):java.lang.Boolean");
}
@Override
protected void onCancelled() {
ImageLoader.this.runHttpFileLoadTasks(this, 2);
}
@Override
public void onPostExecute(Boolean bool) {
ImageLoader.this.runHttpFileLoadTasks(this, bool.booleanValue() ? 2 : 1);
}
}
class HttpImageTask extends AsyncTask<Void, Void, Boolean> {
private CacheImage cacheImage;
private boolean canRetry = true;
private RandomAccessFile fileOutputStream;
private HttpURLConnection httpConnection;
private long imageSize;
private long lastProgressTime;
private String overrideUrl;
public HttpImageTask(CacheImage cacheImage, int i, String str) {
this.cacheImage = cacheImage;
this.imageSize = i;
this.overrideUrl = str;
}
public HttpImageTask(CacheImage cacheImage, long j) {
this.cacheImage = cacheImage;
this.imageSize = j;
}
public static void lambda$doInBackground$2(TLObject tLObject, TLRPC.TL_error tL_error) {
}
public void lambda$onCancelled$6() {
ImageLoader.this.runHttpTasks(true);
}
public void lambda$onCancelled$7() {
NotificationCenter.getInstance(this.cacheImage.currentAccount).lambda$postNotificationNameOnUIThread$1(NotificationCenter.fileLoadFailed, this.cacheImage.url, 1);
}
public void lambda$onCancelled$8() {
ImageLoader.this.fileProgresses.remove(this.cacheImage.url);
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
ImageLoader.HttpImageTask.this.lambda$onCancelled$7();
}
});
}
public void lambda$onPostExecute$3(Boolean bool) {
if (!bool.booleanValue()) {
NotificationCenter.getInstance(this.cacheImage.currentAccount).lambda$postNotificationNameOnUIThread$1(NotificationCenter.fileLoadFailed, this.cacheImage.url, 2);
return;
}
NotificationCenter notificationCenter = NotificationCenter.getInstance(this.cacheImage.currentAccount);
int i = NotificationCenter.fileLoaded;
CacheImage cacheImage = this.cacheImage;
notificationCenter.lambda$postNotificationNameOnUIThread$1(i, cacheImage.url, cacheImage.finalFilePath);
}
public void lambda$onPostExecute$4(final Boolean bool) {
ImageLoader.this.fileProgresses.remove(this.cacheImage.url);
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
ImageLoader.HttpImageTask.this.lambda$onPostExecute$3(bool);
}
});
}
public void lambda$onPostExecute$5() {
ImageLoader.this.runHttpTasks(true);
}
public void lambda$reportProgress$0(long j, long j2) {
NotificationCenter.getInstance(this.cacheImage.currentAccount).lambda$postNotificationNameOnUIThread$1(NotificationCenter.fileLoadProgressChanged, this.cacheImage.url, Long.valueOf(j), Long.valueOf(j2));
}
public void lambda$reportProgress$1(final long j, final long j2) {
ImageLoader.this.fileProgresses.put(this.cacheImage.url, new long[]{j, j2});
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
ImageLoader.HttpImageTask.this.lambda$reportProgress$0(j, j2);
}
});
}
private void reportProgress(final long j, final long j2) {
long elapsedRealtime = SystemClock.elapsedRealtime();
if (j != j2) {
long j3 = this.lastProgressTime;
if (j3 != 0 && j3 >= elapsedRealtime - 100) {
return;
}
}
this.lastProgressTime = elapsedRealtime;
Utilities.stageQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ImageLoader.HttpImageTask.this.lambda$reportProgress$1(j, j2);
}
});
}
@Override
public java.lang.Boolean doInBackground(java.lang.Void... r13) {
throw new UnsupportedOperationException("Method not decompiled: org.telegram.messenger.ImageLoader.HttpImageTask.doInBackground(java.lang.Void[]):java.lang.Boolean");
}
@Override
protected void onCancelled() {
ImageLoader.this.imageLoadQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ImageLoader.HttpImageTask.this.lambda$onCancelled$6();
}
}, this.cacheImage.priority);
Utilities.stageQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ImageLoader.HttpImageTask.this.lambda$onCancelled$8();
}
});
}
@Override
public void onPostExecute(final Boolean bool) {
if (bool.booleanValue() || !this.canRetry) {
ImageLoader imageLoader = ImageLoader.this;
CacheImage cacheImage = this.cacheImage;
imageLoader.fileDidLoaded(cacheImage.url, cacheImage.finalFilePath, 0);
} else {
ImageLoader.this.httpFileLoadError(this.cacheImage.url);
}
Utilities.stageQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ImageLoader.HttpImageTask.this.lambda$onPostExecute$4(bool);
}
});
ImageLoader.this.imageLoadQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ImageLoader.HttpImageTask.this.lambda$onPostExecute$5();
}
}, this.cacheImage.priority);
}
}
public static class MessageThumb {
BitmapDrawable drawable;
String key;
public MessageThumb(String str, BitmapDrawable bitmapDrawable) {
this.key = str;
this.drawable = bitmapDrawable;
}
}
public static class PhotoSizeFromPhoto extends TLRPC.PhotoSize {
public final TLRPC.InputPhoto inputPhoto;
public final TLRPC.Photo photo;
public PhotoSizeFromPhoto(TLRPC.Photo photo) {
this.photo = photo;
TLRPC.TL_inputPhoto tL_inputPhoto = new TLRPC.TL_inputPhoto();
tL_inputPhoto.id = photo.id;
tL_inputPhoto.file_reference = photo.file_reference;
tL_inputPhoto.access_hash = photo.access_hash;
this.inputPhoto = tL_inputPhoto;
}
}
private static class ThumbGenerateInfo {
private boolean big;
private String filter;
private ArrayList<ImageReceiver> imageReceiverArray;
private ArrayList<Integer> imageReceiverGuidsArray;
private TLRPC.Document parentDocument;
private ThumbGenerateInfo() {
this.imageReceiverArray = new ArrayList<>();
this.imageReceiverGuidsArray = new ArrayList<>();
}
}
class ThumbGenerateTask implements Runnable {
private ThumbGenerateInfo info;
private int mediaType;
private File originalPath;
public ThumbGenerateTask(int i, File file, ThumbGenerateInfo thumbGenerateInfo) {
this.mediaType = i;
this.originalPath = file;
this.info = thumbGenerateInfo;
}
public void lambda$removeTask$0(String str) {
ImageLoader.this.thumbGenerateTasks.remove(str);
}
public void lambda$run$1(String str, ArrayList arrayList, BitmapDrawable bitmapDrawable, ArrayList arrayList2) {
removeTask();
if (this.info.filter != null) {
str = str + "@" + this.info.filter;
}
for (int i = 0; i < arrayList.size(); i++) {
((ImageReceiver) arrayList.get(i)).setImageBitmapByKey(bitmapDrawable, str, 0, false, ((Integer) arrayList2.get(i)).intValue());
}
ImageLoader.this.memCache.put(str, bitmapDrawable);
}
private void removeTask() {
ThumbGenerateInfo thumbGenerateInfo = this.info;
if (thumbGenerateInfo == null) {
return;
}
final String attachFileName = FileLoader.getAttachFileName(thumbGenerateInfo.parentDocument);
ImageLoader.this.imageLoadQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ImageLoader.ThumbGenerateTask.this.lambda$removeTask$0(attachFileName);
}
});
}
@Override
public void run() {
throw new UnsupportedOperationException("Method not decompiled: org.telegram.messenger.ImageLoader.ThumbGenerateTask.run():void");
}
}
public ImageLoader() {
this.thumbGeneratingQueue.setPriority(1);
int memoryClass = ((ActivityManager) ApplicationLoader.applicationContext.getSystemService("activity")).getMemoryClass();
boolean z = memoryClass >= 192;
this.canForce8888 = z;
int min = Math.min(z ? 30 : 15, memoryClass / 7) * FileLoaderPriorityQueue.PRIORITY_VALUE_MAX;
float f = min;
this.memCache = new LruCache<BitmapDrawable>((int) (0.8f * f)) {
@Override
public void entryRemoved(boolean z2, String str, BitmapDrawable bitmapDrawable, BitmapDrawable bitmapDrawable2) {
if (ImageLoader.this.ignoreRemoval == null || !ImageLoader.this.ignoreRemoval.equals(str)) {
Integer num = (Integer) ImageLoader.this.bitmapUseCounts.get(str);
if (num == null || num.intValue() == 0) {
Bitmap bitmap = bitmapDrawable.getBitmap();
if (bitmap.isRecycled()) {
return;
}
ArrayList arrayList = new ArrayList();
arrayList.add(bitmap);
AndroidUtilities.recycleBitmaps(arrayList);
}
}
}
@Override
public int sizeOf(String str, BitmapDrawable bitmapDrawable) {
return ImageLoader.this.sizeOfBitmapDrawable(bitmapDrawable);
}
};
this.smallImagesMemCache = new LruCache<BitmapDrawable>((int) (f * 0.2f)) {
@Override
public void entryRemoved(boolean z2, String str, BitmapDrawable bitmapDrawable, BitmapDrawable bitmapDrawable2) {
if (ImageLoader.this.ignoreRemoval == null || !ImageLoader.this.ignoreRemoval.equals(str)) {
Integer num = (Integer) ImageLoader.this.bitmapUseCounts.get(str);
if (num == null || num.intValue() == 0) {
Bitmap bitmap = bitmapDrawable.getBitmap();
if (bitmap.isRecycled()) {
return;
}
ArrayList arrayList = new ArrayList();
arrayList.add(bitmap);
AndroidUtilities.recycleBitmaps(arrayList);
}
}
}
@Override
public int sizeOf(String str, BitmapDrawable bitmapDrawable) {
return ImageLoader.this.sizeOfBitmapDrawable(bitmapDrawable);
}
};
this.wallpaperMemCache = new LruCache<BitmapDrawable>(min / 4) {
@Override
public int sizeOf(String str, BitmapDrawable bitmapDrawable) {
return ImageLoader.this.sizeOfBitmapDrawable(bitmapDrawable);
}
};
this.lottieMemCache = new LruCache<BitmapDrawable>(10485760) {
@Override
public void entryRemoved(boolean z2, String str, BitmapDrawable bitmapDrawable, BitmapDrawable bitmapDrawable2) {
Integer num = (Integer) ImageLoader.this.bitmapUseCounts.get(str);
boolean z3 = bitmapDrawable instanceof AnimatedFileDrawable;
if (z3) {
ImageLoader.this.cachedAnimatedFileDrawables.remove((AnimatedFileDrawable) bitmapDrawable);
}
if (num == null || num.intValue() == 0) {
if (z3) {
((AnimatedFileDrawable) bitmapDrawable).recycle();
}
if (bitmapDrawable instanceof RLottieDrawable) {
((RLottieDrawable) bitmapDrawable).recycle(false);
}
}
}
@Override
public BitmapDrawable put(String str, BitmapDrawable bitmapDrawable) {
if (bitmapDrawable instanceof AnimatedFileDrawable) {
ImageLoader.this.cachedAnimatedFileDrawables.add((AnimatedFileDrawable) bitmapDrawable);
}
return (BitmapDrawable) super.put(str, (String) bitmapDrawable);
}
@Override
public int sizeOf(String str, BitmapDrawable bitmapDrawable) {
return ImageLoader.this.sizeOfBitmapDrawable(bitmapDrawable);
}
};
SparseArray sparseArray = new SparseArray();
File cacheDir = AndroidUtilities.getCacheDir();
if (!cacheDir.isDirectory()) {
try {
cacheDir.mkdirs();
} catch (Exception e) {
FileLog.e(e);
}
}
AndroidUtilities.createEmptyFile(new File(cacheDir, ".nomedia"));
sparseArray.put(4, cacheDir);
for (int i = 0; i < 4; i++) {
FileLoader.getInstance(i).setDelegate(new AnonymousClass5(i));
}
FileLoader.setMediaDirs(sparseArray);
AnonymousClass6 anonymousClass6 = new AnonymousClass6();
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction("android.intent.action.MEDIA_BAD_REMOVAL");
intentFilter.addAction("android.intent.action.MEDIA_CHECKING");
intentFilter.addAction("android.intent.action.MEDIA_EJECT");
intentFilter.addAction("android.intent.action.MEDIA_MOUNTED");
intentFilter.addAction("android.intent.action.MEDIA_NOFS");
intentFilter.addAction("android.intent.action.MEDIA_REMOVED");
intentFilter.addAction("android.intent.action.MEDIA_SHARED");
intentFilter.addAction("android.intent.action.MEDIA_UNMOUNTABLE");
intentFilter.addAction("android.intent.action.MEDIA_UNMOUNTED");
intentFilter.addDataScheme("file");
try {
if (Build.VERSION.SDK_INT >= 33) {
zzg$.ExternalSyntheticApiModelOutline0.m(ApplicationLoader.applicationContext, anonymousClass6, intentFilter, 4);
} else {
ApplicationLoader.applicationContext.registerReceiver(anonymousClass6, intentFilter);
}
} catch (Throwable unused) {
}
checkMediaPaths();
}
public void artworkLoadError(final String str) {
this.imageLoadQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ImageLoader.this.lambda$artworkLoadError$10(str);
}
});
}
private boolean canMoveFiles(File file, File file2, int i) {
RandomAccessFile randomAccessFile;
File file3;
File file4;
byte[] bArr;
RandomAccessFile randomAccessFile2 = null;
try {
try {
if (i == 0) {
file3 = new File(file, "000000000_999999_temp.f");
file4 = new File(file2, "000000000_999999.f");
} else {
if (i != 3 && i != 5 && i != 6) {
if (i == 1) {
file3 = new File(file, "000000000_999999_temp.f");
file4 = new File(file2, "000000000_999999.f");
} else if (i == 2) {
file3 = new File(file, "000000000_999999_temp.f");
file4 = new File(file2, "000000000_999999.f");
} else {
file4 = null;
file3 = null;
}
}
file3 = new File(file, "000000000_999999_temp.f");
file4 = new File(file2, "000000000_999999.f");
}
bArr = new byte[LiteMode.FLAG_AUTOPLAY_VIDEOS];
file3.createNewFile();
randomAccessFile = new RandomAccessFile(file3, "rws");
} catch (Throwable th) {
th = th;
randomAccessFile = null;
}
} catch (Exception e) {
e = e;
}
try {
randomAccessFile.write(bArr);
randomAccessFile.close();
boolean renameTo = file3.renameTo(file4);
file3.delete();
file4.delete();
return renameTo;
} catch (Exception e2) {
e = e2;
randomAccessFile2 = randomAccessFile;
FileLog.e(e);
if (randomAccessFile2 == null) {
return false;
}
try {
randomAccessFile2.close();
return false;
} catch (Exception e3) {
FileLog.e(e3);
return false;
}
} catch (Throwable th2) {
th = th2;
if (randomAccessFile != null) {
try {
randomAccessFile.close();
} catch (Exception e4) {
FileLog.e(e4);
}
}
throw th;
}
}
private void createLoadOperationForImageReceiver(final ImageReceiver imageReceiver, final String str, final String str2, final String str3, final ImageLocation imageLocation, final String str4, final long j, final int i, final int i2, final int i3, final int i4) {
if (imageReceiver == null || str2 == null || str == null || imageLocation == null) {
return;
}
int tag = imageReceiver.getTag(i2);
if (tag == 0) {
tag = this.lastImageNum;
imageReceiver.setTag(tag, i2);
int i5 = this.lastImageNum + 1;
this.lastImageNum = i5;
if (i5 == Integer.MAX_VALUE) {
this.lastImageNum = 0;
}
}
final int i6 = tag;
final boolean isNeedsQualityThumb = imageReceiver.isNeedsQualityThumb();
final Object parentObject = imageReceiver.getParentObject();
final TLRPC.Document qualityThumbDocument = imageReceiver.getQualityThumbDocument();
final boolean isShouldGenerateQualityThumb = imageReceiver.isShouldGenerateQualityThumb();
final int currentAccount = imageReceiver.getCurrentAccount();
final boolean z = i2 == 0 && imageReceiver.isCurrentKeyQuality();
Runnable runnable = new Runnable() {
@Override
public final void run() {
ImageLoader.this.lambda$createLoadOperationForImageReceiver$7(i3, str2, str, i6, imageReceiver, i4, str4, i2, imageLocation, z, parentObject, currentAccount, qualityThumbDocument, isNeedsQualityThumb, isShouldGenerateQualityThumb, str3, i, j);
}
};
this.imageLoadQueue.postRunnable(runnable, imageReceiver.getFileLoadingPriority() == 0 ? 0L : 1L);
imageReceiver.addLoadingImageRunnable(runnable);
}
public static Drawable createStripedBitmap(ArrayList<TLRPC.PhotoSize> arrayList) {
for (int i = 0; i < arrayList.size(); i++) {
if (arrayList.get(i) instanceof TLRPC.TL_photoStrippedSize) {
return new BitmapDrawable(ApplicationLoader.applicationContext.getResources(), getStrippedPhotoBitmap(((TLRPC.TL_photoStrippedSize) arrayList.get(i)).bytes, "b"));
}
}
return null;
}
public static String cutFilter(String str) {
if (str == null) {
return null;
}
int indexOf = str.indexOf(64);
return indexOf >= 0 ? str.substring(0, indexOf) : str;
}
public static String decompressGzip(File file) {
StringBuilder sb = new StringBuilder();
if (file == null) {
return "";
}
try {
GZIPInputStream gZIPInputStream = new GZIPInputStream(new FileInputStream(file));
try {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(gZIPInputStream, "UTF-8"));
while (true) {
try {
String readLine = bufferedReader.readLine();
if (readLine == null) {
String sb2 = sb.toString();
bufferedReader.close();
gZIPInputStream.close();
return sb2;
}
sb.append(readLine);
} finally {
}
}
} finally {
}
} catch (Exception unused) {
return "";
}
}
public void fileDidFailedLoad(final String str, int i) {
if (i == 1) {
return;
}
this.imageLoadQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ImageLoader.this.lambda$fileDidFailedLoad$12(str);
}
});
}
public void fileDidLoaded(final String str, final File file, final int i) {
this.imageLoadQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ImageLoader.this.lambda$fileDidLoaded$11(str, i, file);
}
});
}
public static TLRPC.PhotoSize fileToSize(String str, boolean z) {
if (str == null) {
return null;
}
try {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(str, options);
int i = options.outWidth;
int i2 = options.outHeight;
TLRPC.TL_fileLocationToBeDeprecated tL_fileLocationToBeDeprecated = new TLRPC.TL_fileLocationToBeDeprecated();
tL_fileLocationToBeDeprecated.volume_id = -2147483648L;
tL_fileLocationToBeDeprecated.dc_id = Integer.MIN_VALUE;
tL_fileLocationToBeDeprecated.local_id = SharedConfig.getLastLocalId();
tL_fileLocationToBeDeprecated.file_reference = new byte[0];
TLRPC.TL_photoSize_layer127 tL_photoSize_layer127 = new TLRPC.TL_photoSize_layer127();
tL_photoSize_layer127.location = tL_fileLocationToBeDeprecated;
tL_photoSize_layer127.w = i;
tL_photoSize_layer127.h = i2;
tL_photoSize_layer127.type = (i > 100 || i2 > 100) ? (i > 320 || i2 > 320) ? (i > 800 || i2 > 800) ? (i > 1280 || i2 > 1280) ? "w" : "y" : "x" : "m" : "s";
File file = new File((z || tL_fileLocationToBeDeprecated.volume_id == -2147483648L) ? FileLoader.getDirectory(4) : FileLoader.getDirectory(0), tL_fileLocationToBeDeprecated.volume_id + "_" + tL_fileLocationToBeDeprecated.local_id + ".jpg");
new File(str).renameTo(file);
tL_photoSize_layer127.size = (int) file.length();
return tL_photoSize_layer127;
} catch (Exception e) {
FileLog.e(e);
return null;
}
}
public static void fillPhotoSizeWithBytes(TLRPC.PhotoSize photoSize) {
if (photoSize != null) {
byte[] bArr = photoSize.bytes;
if (bArr == null || bArr.length == 0) {
try {
RandomAccessFile randomAccessFile = new RandomAccessFile(FileLoader.getInstance(UserConfig.selectedAccount).getPathToAttach(photoSize, true), "r");
if (((int) randomAccessFile.length()) < 20000) {
int length = (int) randomAccessFile.length();
byte[] bArr2 = new byte[length];
photoSize.bytes = bArr2;
randomAccessFile.readFully(bArr2, 0, length);
}
} catch (Throwable th) {
FileLog.e(th);
}
}
}
}
private Drawable findInPreloadImageReceivers(String str, List<ImageReceiver> list) {
if (list == null) {
return null;
}
for (int i = 0; i < list.size(); i++) {
ImageReceiver imageReceiver = list.get(i);
if (str.equals(imageReceiver.getImageKey())) {
return imageReceiver.getImageDrawable();
}
if (str.equals(imageReceiver.getMediaKey())) {
return imageReceiver.getMediaDrawable();
}
}
return null;
}
private static TLRPC.PhotoSize findPhotoCachedSize(TLRPC.Message message) {
TLRPC.MessageMedia messageMedia = message.media;
int i = 0;
if (messageMedia instanceof TLRPC.TL_messageMediaPhoto) {
int size = messageMedia.photo.sizes.size();
while (i < size) {
TLRPC.PhotoSize photoSize = (TLRPC.PhotoSize) message.media.photo.sizes.get(i);
if (photoSize instanceof TLRPC.TL_photoCachedSize) {
return photoSize;
}
i++;
}
} else if (messageMedia instanceof TLRPC.TL_messageMediaDocument) {
TLRPC.Document document = messageMedia.document;
if (document != null) {
int size2 = document.thumbs.size();
while (i < size2) {
TLRPC.PhotoSize photoSize2 = (TLRPC.PhotoSize) message.media.document.thumbs.get(i);
if (photoSize2 instanceof TLRPC.TL_photoCachedSize) {
return photoSize2;
}
i++;
}
}
} else if (messageMedia instanceof TLRPC.TL_messageMediaWebPage) {
TLRPC.Photo photo = messageMedia.webpage.photo;
if (photo != null) {
int size3 = photo.sizes.size();
while (i < size3) {
TLRPC.PhotoSize photoSize3 = (TLRPC.PhotoSize) message.media.webpage.photo.sizes.get(i);
if (photoSize3 instanceof TLRPC.TL_photoCachedSize) {
return photoSize3;
}
i++;
}
}
} else if ((messageMedia instanceof TLRPC.TL_messageMediaInvoice) && !messageMedia.extended_media.isEmpty() && (message.media.extended_media.get(0) instanceof TLRPC.TL_messageExtendedMediaPreview)) {
return ((TLRPC.TL_messageExtendedMediaPreview) message.media.extended_media.get(0)).thumb;
}
return null;
}
private static TLRPC.PhotoSize findPhotoCachedSize(TLRPC.MessageMedia messageMedia) {
int i = 0;
if (messageMedia instanceof TLRPC.TL_messageMediaPhoto) {
int size = messageMedia.photo.sizes.size();
while (i < size) {
TLRPC.PhotoSize photoSize = (TLRPC.PhotoSize) messageMedia.photo.sizes.get(i);
if (photoSize instanceof TLRPC.TL_photoCachedSize) {
return photoSize;
}
i++;
}
} else if (messageMedia instanceof TLRPC.TL_messageMediaDocument) {
TLRPC.Document document = messageMedia.document;
if (document != null) {
int size2 = document.thumbs.size();
while (i < size2) {
TLRPC.PhotoSize photoSize2 = (TLRPC.PhotoSize) messageMedia.document.thumbs.get(i);
if (photoSize2 instanceof TLRPC.TL_photoCachedSize) {
return photoSize2;
}
i++;
}
}
} else if (messageMedia instanceof TLRPC.TL_messageMediaWebPage) {
TLRPC.Photo photo = messageMedia.webpage.photo;
if (photo != null) {
int size3 = photo.sizes.size();
while (i < size3) {
TLRPC.PhotoSize photoSize3 = (TLRPC.PhotoSize) messageMedia.webpage.photo.sizes.get(i);
if (photoSize3 instanceof TLRPC.TL_photoCachedSize) {
return photoSize3;
}
i++;
}
}
} else if ((messageMedia instanceof TLRPC.TL_messageMediaInvoice) && !messageMedia.extended_media.isEmpty() && (messageMedia.extended_media.get(0) instanceof TLRPC.TL_messageExtendedMediaPreview)) {
return ((TLRPC.TL_messageExtendedMediaPreview) messageMedia.extended_media.get(0)).thumb;
}
return null;
}
public static MessageThumb generateMessageThumb(TLRPC.Message message) {
int i;
int i2;
Bitmap strippedPhotoBitmap;
byte[] bArr;
TLRPC.PhotoSize findPhotoCachedSize = findPhotoCachedSize(message);
if (findPhotoCachedSize == null || (bArr = findPhotoCachedSize.bytes) == null || bArr.length == 0) {
TLRPC.MessageMedia messageMedia = message.media;
if (messageMedia instanceof TLRPC.TL_messageMediaDocument) {
int size = messageMedia.document.thumbs.size();
for (int i3 = 0; i3 < size; i3++) {
TLRPC.PhotoSize photoSize = (TLRPC.PhotoSize) message.media.document.thumbs.get(i3);
if (photoSize instanceof TLRPC.TL_photoStrippedSize) {
TLRPC.PhotoSize closestPhotoSizeWithSize = FileLoader.getClosestPhotoSizeWithSize(message.media.document.thumbs, 320);
if (closestPhotoSizeWithSize == null) {
int i4 = 0;
while (true) {
if (i4 >= message.media.document.attributes.size()) {
i = 0;
i2 = 0;
break;
}
if (message.media.document.attributes.get(i4) instanceof TLRPC.TL_documentAttributeVideo) {
TLRPC.TL_documentAttributeVideo tL_documentAttributeVideo = (TLRPC.TL_documentAttributeVideo) message.media.document.attributes.get(i4);
i2 = tL_documentAttributeVideo.h;
i = tL_documentAttributeVideo.w;
break;
}
i4++;
}
} else {
i2 = closestPhotoSizeWithSize.h;
i = closestPhotoSizeWithSize.w;
}
Point messageSize = ChatMessageCell.getMessageSize(i, i2);
String format = String.format(Locale.US, "%s_false@%d_%d_b", ImageLocation.getStrippedKey(message, message, photoSize), Integer.valueOf((int) (messageSize.x / AndroidUtilities.density)), Integer.valueOf((int) (messageSize.y / AndroidUtilities.density)));
if (!getInstance().isInMemCache(format, false) && (strippedPhotoBitmap = getStrippedPhotoBitmap(photoSize.bytes, null)) != null) {
Utilities.blurBitmap(strippedPhotoBitmap, 3, 1, strippedPhotoBitmap.getWidth(), strippedPhotoBitmap.getHeight(), strippedPhotoBitmap.getRowBytes());
float f = messageSize.x;
float f2 = AndroidUtilities.density;
Bitmap createScaledBitmap = Bitmaps.createScaledBitmap(strippedPhotoBitmap, (int) (f / f2), (int) (messageSize.y / f2), true);
if (createScaledBitmap != strippedPhotoBitmap) {
strippedPhotoBitmap.recycle();
strippedPhotoBitmap = createScaledBitmap;
}
return new MessageThumb(format, new BitmapDrawable(strippedPhotoBitmap));
}
}
}
}
} else {
File pathToAttach = FileLoader.getInstance(UserConfig.selectedAccount).getPathToAttach(findPhotoCachedSize, true);
TLRPC.TL_photoSize_layer127 tL_photoSize_layer127 = new TLRPC.TL_photoSize_layer127();
tL_photoSize_layer127.w = findPhotoCachedSize.w;
tL_photoSize_layer127.h = findPhotoCachedSize.h;
tL_photoSize_layer127.location = findPhotoCachedSize.location;
tL_photoSize_layer127.size = findPhotoCachedSize.size;
tL_photoSize_layer127.type = findPhotoCachedSize.type;
if (pathToAttach.exists() && message.grouped_id == 0) {
Point messageSize2 = ChatMessageCell.getMessageSize(findPhotoCachedSize.w, findPhotoCachedSize.h);
String format2 = String.format(Locale.US, "%d_%d@%d_%d_b", Long.valueOf(findPhotoCachedSize.location.volume_id), Integer.valueOf(findPhotoCachedSize.location.local_id), Integer.valueOf((int) (messageSize2.x / AndroidUtilities.density)), Integer.valueOf((int) (messageSize2.y / AndroidUtilities.density)));
if (!getInstance().isInMemCache(format2, false)) {
String path = pathToAttach.getPath();
float f3 = messageSize2.x;
float f4 = AndroidUtilities.density;
Bitmap loadBitmap = loadBitmap(path, null, (int) (f3 / f4), (int) (messageSize2.y / f4), false);
if (loadBitmap != null) {
Utilities.blurBitmap(loadBitmap, 3, 1, loadBitmap.getWidth(), loadBitmap.getHeight(), loadBitmap.getRowBytes());
float f5 = messageSize2.x;
float f6 = AndroidUtilities.density;
Bitmap createScaledBitmap2 = Bitmaps.createScaledBitmap(loadBitmap, (int) (f5 / f6), (int) (messageSize2.y / f6), true);
if (createScaledBitmap2 != loadBitmap) {
loadBitmap.recycle();
loadBitmap = createScaledBitmap2;
}
return new MessageThumb(format2, new BitmapDrawable(loadBitmap));
}
}
}
}
return null;
}
private void generateThumb(int i, File file, ThumbGenerateInfo thumbGenerateInfo) {
if ((i != 0 && i != 2 && i != 3) || file == null || thumbGenerateInfo == null) {
return;
}
if (this.thumbGenerateTasks.get(FileLoader.getAttachFileName(thumbGenerateInfo.parentDocument)) == null) {
this.thumbGeneratingQueue.postRunnable(new ThumbGenerateTask(i, file, thumbGenerateInfo));
}
}
public BitmapDrawable getFromLottieCache(String str) {
BitmapDrawable bitmapDrawable = this.lottieMemCache.get(str);
if (!(bitmapDrawable instanceof AnimatedFileDrawable) || !((AnimatedFileDrawable) bitmapDrawable).isRecycled()) {
return bitmapDrawable;
}
this.lottieMemCache.remove(str);
return null;
}
public static String getHttpFileName(String str) {
return Utilities.MD5(str);
}
public static File getHttpFilePath(String str, String str2) {
String httpUrlExtension = getHttpUrlExtension(str, str2);
return new File(FileLoader.getDirectory(4), Utilities.MD5(str) + "." + httpUrlExtension);
}
public static String getHttpUrlExtension(String str, String str2) {
String lastPathSegment = Uri.parse(str).getLastPathSegment();
if (!TextUtils.isEmpty(lastPathSegment) && lastPathSegment.length() > 1) {
str = lastPathSegment;
}
int lastIndexOf = str.lastIndexOf(46);
String substring = lastIndexOf != -1 ? str.substring(lastIndexOf + 1) : null;
return (substring == null || substring.length() == 0 || substring.length() > 4) ? str2 : substring;
}
public static ImageLoader getInstance() {
ImageLoader imageLoader = Instance;
if (imageLoader == null) {
synchronized (ImageLoader.class) {
try {
imageLoader = Instance;
if (imageLoader == null) {
imageLoader = new ImageLoader();
Instance = imageLoader;
}
} finally {
}
}
}
return imageLoader;
}
private java.io.File getPublicStorageDir() {
throw new UnsupportedOperationException("Method not decompiled: org.telegram.messenger.ImageLoader.getPublicStorageDir():java.io.File");
}
public static Bitmap getStrippedPhotoBitmap(byte[] bArr, String str) {
int length = (bArr.length - 3) + Bitmaps.header.length + Bitmaps.footer.length;
byte[] bArr2 = bytesLocal.get();
if (bArr2 == null || bArr2.length < length) {
bArr2 = null;
}
if (bArr2 == null) {
bArr2 = new byte[length];
bytesLocal.set(bArr2);
}
byte[] bArr3 = Bitmaps.header;
System.arraycopy(bArr3, 0, bArr2, 0, bArr3.length);
System.arraycopy(bArr, 3, bArr2, Bitmaps.header.length, bArr.length - 3);
System.arraycopy(Bitmaps.footer, 0, bArr2, (Bitmaps.header.length + bArr.length) - 3, Bitmaps.footer.length);
bArr2[164] = bArr[1];
bArr2[166] = bArr[2];
BitmapFactory.Options options = new BitmapFactory.Options();
boolean z = !TextUtils.isEmpty(str) && str.contains("r");
options.inPreferredConfig = (SharedConfig.deviceIsHigh() || z) ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565;
Bitmap decodeByteArray = BitmapFactory.decodeByteArray(bArr2, 0, length, options);
if (z) {
Bitmap createBitmap = Bitmap.createBitmap(decodeByteArray.getWidth(), decodeByteArray.getHeight(), decodeByteArray.getConfig());
Canvas canvas = new Canvas(createBitmap);
canvas.save();
canvas.scale(1.2f, 1.2f, decodeByteArray.getWidth() / 2.0f, decodeByteArray.getHeight() / 2.0f);
canvas.drawBitmap(decodeByteArray, 0.0f, 0.0f, (Paint) null);
canvas.restore();
Path path = new Path();
path.addCircle(decodeByteArray.getWidth() / 2.0f, decodeByteArray.getHeight() / 2.0f, Math.min(decodeByteArray.getWidth(), decodeByteArray.getHeight()) / 2.0f, Path.Direction.CW);
canvas.clipPath(path);
canvas.drawBitmap(decodeByteArray, 0.0f, 0.0f, (Paint) null);
decodeByteArray.recycle();
decodeByteArray = createBitmap;
}
if (decodeByteArray != null && !TextUtils.isEmpty(str) && str.contains("b")) {
Utilities.blurBitmap(decodeByteArray, 3, 1, decodeByteArray.getWidth(), decodeByteArray.getHeight(), decodeByteArray.getRowBytes());
}
return decodeByteArray;
}
public static boolean hasAutoplayFilter(String str) {
if (str == null) {
return false;
}
String[] split = str.split("_");
for (int i = 0; i < split.length; i++) {
if (AUTOPLAY_FILTER.equals(split[i]) || "pframe".equals(split[i])) {
return true;
}
}
return false;
}
public void httpFileLoadError(final String str) {
this.imageLoadQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ImageLoader.this.lambda$httpFileLoadError$9(str);
}
});
}
public boolean isAnimatedAvatar(String str) {
return str != null && str.endsWith("avatar");
}
private boolean isPFrame(String str) {
return str != null && str.endsWith("pframe");
}
public static boolean isSdCardPath(File file) {
return !TextUtils.isEmpty(SharedConfig.storageCacheDir) && file.getAbsolutePath().startsWith(SharedConfig.storageCacheDir);
}
public void lambda$artworkLoadError$10(String str) {
CacheImage cacheImage = this.imageLoadingByUrl.get(str);
if (cacheImage == null) {
return;
}
ArtworkLoadTask artworkLoadTask = cacheImage.artworkTask;
if (artworkLoadTask != null) {
ArtworkLoadTask artworkLoadTask2 = new ArtworkLoadTask(artworkLoadTask.cacheImage);
cacheImage.artworkTask = artworkLoadTask2;
this.artworkTasks.add(artworkLoadTask2);
}
runArtworkTasks(false);
}
public void lambda$cancelForceLoadingForImageReceiver$6(String str) {
this.forceLoadingImages.remove(str);
}
public void lambda$cancelLoadingForImageReceiver$4(boolean z, ImageReceiver imageReceiver) {
int i = 0;
while (true) {
int i2 = 3;
if (i >= 3) {
return;
}
if (i > 0 && !z) {
return;
}
if (i == 0) {
i2 = 1;
} else if (i == 1) {
i2 = 0;
}
int tag = imageReceiver.getTag(i2);
if (tag != 0) {
if (i == 0) {
removeFromWaitingForThumb(tag, imageReceiver);
}
CacheImage cacheImage = this.imageLoadingByTag.get(tag);
if (cacheImage != null) {
cacheImage.removeImageReceiver(imageReceiver);
}
}
i++;
}
}
public void lambda$changeFileLoadingPriorityForImageReceiver$3(ImageReceiver imageReceiver, int i) {
CacheImage cacheImage;
int i2 = 0;
while (true) {
int i3 = 3;
if (i2 >= 3) {
return;
}
if (i2 == 0) {
i3 = 1;
} else if (i2 == 1) {
i3 = 0;
}
int tag = imageReceiver.getTag(i3);
if (tag != 0 && (cacheImage = this.imageLoadingByTag.get(tag)) != null) {
cacheImage.changePriority(i);
}
i2++;
}
}
public static void lambda$checkMediaPaths$0(SparseArray sparseArray, Runnable runnable) {
FileLoader.setMediaDirs(sparseArray);
if (runnable != null) {
runnable.run();
}
}
public void lambda$checkMediaPaths$1(final Runnable runnable) {
final SparseArray<File> createMediaPaths = createMediaPaths();
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
ImageLoader.lambda$checkMediaPaths$0(createMediaPaths, runnable);
}
});
}
public void lambda$createLoadOperationForImageReceiver$7(int r27, java.lang.String r28, java.lang.String r29, int r30, org.telegram.messenger.ImageReceiver r31, int r32, java.lang.String r33, int r34, org.telegram.messenger.ImageLocation r35, boolean r36, java.lang.Object r37, int r38, org.telegram.tgnet.TLRPC.Document r39, boolean r40, boolean r41, java.lang.String r42, int r43, long r44) {
throw new UnsupportedOperationException("Method not decompiled: org.telegram.messenger.ImageLoader.lambda$createLoadOperationForImageReceiver$7(int, java.lang.String, java.lang.String, int, org.telegram.messenger.ImageReceiver, int, java.lang.String, int, org.telegram.messenger.ImageLocation, boolean, java.lang.Object, int, org.telegram.tgnet.TLRPC$Document, boolean, boolean, java.lang.String, int, long):void");
}
public void lambda$fileDidFailedLoad$12(String str) {
CacheImage cacheImage = this.imageLoadingByUrl.get(str);
if (cacheImage != null) {
cacheImage.setImageAndClear(null, null);
}
}
public void lambda$fileDidLoaded$11(String str, int i, File file) {
ThumbGenerateInfo thumbGenerateInfo = this.waitingForQualityThumb.get(str);
if (thumbGenerateInfo != null && thumbGenerateInfo.parentDocument != null) {
generateThumb(i, file, thumbGenerateInfo);
this.waitingForQualityThumb.remove(str);
}
CacheImage cacheImage = this.imageLoadingByUrl.get(str);
if (cacheImage == null) {
return;
}
this.imageLoadingByUrl.remove(str);
this.imageLoadingByUrlPframe.remove(str);
ArrayList arrayList = new ArrayList();
for (int i2 = 0; i2 < cacheImage.imageReceiverArray.size(); i2++) {
String str2 = cacheImage.keys.get(i2);
String str3 = cacheImage.filters.get(i2);
int intValue = cacheImage.types.get(i2).intValue();
ImageReceiver imageReceiver = cacheImage.imageReceiverArray.get(i2);
int intValue2 = cacheImage.imageReceiverGuidsArray.get(i2).intValue();
CacheImage cacheImage2 = (CacheImage) this.imageLoadingByKeys.get(str2);
if (cacheImage2 == null) {
cacheImage2 = new CacheImage();
cacheImage2.priority = cacheImage.priority;
cacheImage2.secureDocument = cacheImage.secureDocument;
cacheImage2.currentAccount = cacheImage.currentAccount;
cacheImage2.finalFilePath = file;
cacheImage2.parentObject = cacheImage.parentObject;
cacheImage2.isPFrame = cacheImage.isPFrame;
cacheImage2.key = str2;
cacheImage2.cacheType = cacheImage.cacheType;
cacheImage2.imageLocation = cacheImage.imageLocation;
cacheImage2.type = intValue;
cacheImage2.ext = cacheImage.ext;
cacheImage2.encryptionKeyPath = cacheImage.encryptionKeyPath;
cacheImage2.cacheTask = new CacheOutTask(cacheImage2);
cacheImage2.filter = str3;
cacheImage2.imageType = cacheImage.imageType;
this.imageLoadingByKeys.put(str2, cacheImage2);
this.imageLoadingKeys.add(cutFilter(str2));
arrayList.add(cacheImage2.cacheTask);
}
cacheImage2.addImageReceiver(imageReceiver, str2, str3, intValue, intValue2);
}
for (int i3 = 0; i3 < arrayList.size(); i3++) {
CacheOutTask cacheOutTask = (CacheOutTask) arrayList.get(i3);
if (cacheOutTask.cacheImage.type == 1) {
this.cacheThumbOutQueue.postRunnable(cacheOutTask);
} else {
this.cacheOutQueue.postRunnable(cacheOutTask, cacheOutTask.cacheImage.priority);
}
}
}
public void lambda$httpFileLoadError$9(String str) {
CacheImage cacheImage = this.imageLoadingByUrl.get(str);
if (cacheImage == null) {
return;
}
HttpImageTask httpImageTask = cacheImage.httpTask;
if (httpImageTask != null) {
HttpImageTask httpImageTask2 = new HttpImageTask(httpImageTask.cacheImage, httpImageTask.imageSize);
cacheImage.httpTask = httpImageTask2;
this.httpTasks.add(httpImageTask2);
}
runHttpTasks(false);
}
public static void lambda$moveDirectory$2(File file, java.nio.file.Path path) {
java.nio.file.Path fileName;
String path2;
boolean isDirectory;
java.nio.file.Path path3;
File file2;
fileName = path.getFileName();
path2 = fileName.toString();
File file3 = new File(file, path2);
isDirectory = Files.isDirectory(path, new LinkOption[0]);
if (isDirectory) {
file2 = path.toFile();
moveDirectory(file2, file3);
return;
}
try {
path3 = file3.toPath();
Files.move(path, path3, new CopyOption[0]);
} catch (Exception e) {
FileLog.e(e);
}
}
public void lambda$preloadArtwork$8(String str) {
String httpUrlExtension = getHttpUrlExtension(str, "jpg");
String str2 = Utilities.MD5(str) + "." + httpUrlExtension;
File file = new File(FileLoader.getDirectory(4), str2);
if (file.exists()) {
return;
}
ImageLocation forPath = ImageLocation.getForPath(str);
CacheImage cacheImage = new CacheImage();
cacheImage.type = 1;
cacheImage.key = Utilities.MD5(str);
cacheImage.filter = null;
cacheImage.imageLocation = forPath;
cacheImage.ext = httpUrlExtension;
cacheImage.parentObject = null;
int i = forPath.imageType;
if (i != 0) {
cacheImage.imageType = i;
}
cacheImage.url = str2;
this.imageLoadingByUrl.put(str2, cacheImage);
String MD5 = Utilities.MD5(forPath.path);
cacheImage.tempFilePath = new File(FileLoader.getDirectory(4), MD5 + "_temp.jpg");
cacheImage.finalFilePath = file;
ArtworkLoadTask artworkLoadTask = new ArtworkLoadTask(cacheImage);
cacheImage.artworkTask = artworkLoadTask;
this.artworkTasks.add(artworkLoadTask);
runArtworkTasks(false);
}
public void lambda$runHttpFileLoadTasks$13(HttpFileTask httpFileTask) {
this.httpFileLoadTasks.add(httpFileTask);
runHttpFileLoadTasks(null, 0);
}
public void lambda$runHttpFileLoadTasks$14(HttpFileTask httpFileTask, int i) {
if (httpFileTask != null) {
this.currentHttpFileLoadTasksCount--;
}
if (httpFileTask != null) {
if (i == 1) {
if (httpFileTask.canRetry) {
final HttpFileTask httpFileTask2 = new HttpFileTask(httpFileTask.url, httpFileTask.tempFile, httpFileTask.ext, httpFileTask.currentAccount);
Runnable runnable = new Runnable() {
@Override
public final void run() {
ImageLoader.this.lambda$runHttpFileLoadTasks$13(httpFileTask2);
}
};
this.retryHttpsTasks.put(httpFileTask.url, runnable);
AndroidUtilities.runOnUIThread(runnable, 1000L);
} else {
this.httpFileLoadTasksByKeys.remove(httpFileTask.url);
NotificationCenter.getInstance(httpFileTask.currentAccount).lambda$postNotificationNameOnUIThread$1(NotificationCenter.httpFileDidFailedLoad, httpFileTask.url, 0);
}
} else if (i == 2) {
this.httpFileLoadTasksByKeys.remove(httpFileTask.url);
File file = new File(FileLoader.getDirectory(4), Utilities.MD5(httpFileTask.url) + "." + httpFileTask.ext);
if (!httpFileTask.tempFile.renameTo(file)) {
file = httpFileTask.tempFile;
}
NotificationCenter.getInstance(httpFileTask.currentAccount).lambda$postNotificationNameOnUIThread$1(NotificationCenter.httpFileDidLoad, httpFileTask.url, file.toString());
}
}
while (this.currentHttpFileLoadTasksCount < 2 && !this.httpFileLoadTasks.isEmpty()) {
this.httpFileLoadTasks.poll().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, null, null, null);
this.currentHttpFileLoadTasksCount++;
}
}
public static android.graphics.Bitmap loadBitmap(java.lang.String r17, android.net.Uri r18, float r19, float r20, boolean r21) {
throw new UnsupportedOperationException("Method not decompiled: org.telegram.messenger.ImageLoader.loadBitmap(java.lang.String, android.net.Uri, float, float, boolean):android.graphics.Bitmap");
}
private static void moveDirectory(File file, final File file2) {
java.nio.file.Path path;
Stream convert;
if (file.exists()) {
if (file2.exists() || file2.mkdir()) {
try {
path = file.toPath();
convert = Stream.VivifiedWrapper.convert(Files.list(path));
try {
convert.forEach(new Consumer() {
public final void accept(Object obj) {
ImageLoader.lambda$moveDirectory$2(file2, (java.nio.file.Path) obj);
}
public Consumer andThen(Consumer consumer) {
return Consumer.-CC.$default$andThen(this, consumer);
}
});
convert.close();
} finally {
}
} catch (Exception e) {
FileLog.e(e);
}
}
}
}
private void performReplace(String str, String str2) {
LruCache<BitmapDrawable> lruCache = this.memCache;
BitmapDrawable bitmapDrawable = lruCache.get(str);
if (bitmapDrawable == null) {
lruCache = this.smallImagesMemCache;
bitmapDrawable = lruCache.get(str);
}
this.replacedBitmaps.put(str, str2);
if (bitmapDrawable != null) {
BitmapDrawable bitmapDrawable2 = lruCache.get(str2);
if (bitmapDrawable2 != null && bitmapDrawable2.getBitmap() != null && bitmapDrawable.getBitmap() != null) {
Bitmap bitmap = bitmapDrawable2.getBitmap();
Bitmap bitmap2 = bitmapDrawable.getBitmap();
if (bitmap.getWidth() > bitmap2.getWidth() || bitmap.getHeight() > bitmap2.getHeight()) {
lruCache.remove(str);
}
}
this.ignoreRemoval = str;
lruCache.remove(str);
lruCache.put(str2, bitmapDrawable);
this.ignoreRemoval = null;
}
Integer num = this.bitmapUseCounts.get(str);
if (num != null) {
this.bitmapUseCounts.put(str2, num);
this.bitmapUseCounts.remove(str);
}
}
private void removeFromWaitingForThumb(int i, ImageReceiver imageReceiver) {
String str = this.waitingForQualityThumbByTag.get(i);
if (str != null) {
ThumbGenerateInfo thumbGenerateInfo = this.waitingForQualityThumb.get(str);
if (thumbGenerateInfo != null) {
int indexOf = thumbGenerateInfo.imageReceiverArray.indexOf(imageReceiver);
if (indexOf >= 0) {
thumbGenerateInfo.imageReceiverArray.remove(indexOf);
thumbGenerateInfo.imageReceiverGuidsArray.remove(indexOf);
}
if (thumbGenerateInfo.imageReceiverArray.isEmpty()) {
this.waitingForQualityThumb.remove(str);
}
}
this.waitingForQualityThumbByTag.remove(i);
}
}
public void lambda$replaceImageInCache$5(String str, String str2, ImageLocation imageLocation) {
int i = 0;
while (i < 2) {
ArrayList<String> filterKeys = (i == 0 ? this.memCache : this.smallImagesMemCache).getFilterKeys(str);
if (filterKeys != null) {
for (int i2 = 0; i2 < filterKeys.size(); i2++) {
String str3 = filterKeys.get(i2);
String str4 = str + "@" + str3;
String str5 = str2 + "@" + str3;
performReplace(str4, str5);
NotificationCenter.getGlobalInstance().lambda$postNotificationNameOnUIThread$1(NotificationCenter.didReplacedPhotoInMemCache, str4, str5, imageLocation);
}
} else {
performReplace(str, str2);
NotificationCenter.getGlobalInstance().lambda$postNotificationNameOnUIThread$1(NotificationCenter.didReplacedPhotoInMemCache, str, str2, imageLocation);
}
i++;
}
}
public void runArtworkTasks(boolean z) {
if (z) {
this.currentArtworkTasksCount--;
}
while (this.currentArtworkTasksCount < 4 && !this.artworkTasks.isEmpty()) {
try {
this.artworkTasks.poll().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, null, null, null);
this.currentArtworkTasksCount++;
} catch (Throwable unused) {
runArtworkTasks(false);
}
}
}
public void runHttpFileLoadTasks(final HttpFileTask httpFileTask, final int i) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
ImageLoader.this.lambda$runHttpFileLoadTasks$14(httpFileTask, i);
}
});
}
public void runHttpTasks(boolean z) {
if (z) {
this.currentHttpTasksCount--;
}
while (this.currentHttpTasksCount < 4 && !this.httpTasks.isEmpty()) {
HttpImageTask poll = this.httpTasks.poll();
if (poll != null) {
poll.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, null, null, null);
this.currentHttpTasksCount++;
}
}
}
public static void saveMessageThumbs(TLRPC.Message message) {
byte[] bArr;
TLRPC.PhotoSize tL_photoSize_layer127;
TLRPC.Photo photo;
ArrayList arrayList;
TLRPC.MessageMedia messageMedia = message.media;
if (messageMedia == null) {
return;
}
int i = 0;
if (messageMedia instanceof TLRPC.TL_messageMediaPaidMedia) {
TLRPC.TL_messageMediaPaidMedia tL_messageMediaPaidMedia = (TLRPC.TL_messageMediaPaidMedia) messageMedia;
while (i < tL_messageMediaPaidMedia.extended_media.size()) {
TLRPC.MessageExtendedMedia messageExtendedMedia = tL_messageMediaPaidMedia.extended_media.get(i);
if (messageExtendedMedia instanceof TLRPC.TL_messageExtendedMedia) {
saveMessageThumbs(message, ((TLRPC.TL_messageExtendedMedia) messageExtendedMedia).media);
}
i++;
}
return;
}
TLRPC.PhotoSize findPhotoCachedSize = findPhotoCachedSize(message);
if (findPhotoCachedSize == null || (bArr = findPhotoCachedSize.bytes) == null || bArr.length == 0) {
return;
}
TLRPC.FileLocation fileLocation = findPhotoCachedSize.location;
if (fileLocation == null || (fileLocation instanceof TLRPC.TL_fileLocationUnavailable)) {
TLRPC.TL_fileLocationToBeDeprecated tL_fileLocationToBeDeprecated = new TLRPC.TL_fileLocationToBeDeprecated();
findPhotoCachedSize.location = tL_fileLocationToBeDeprecated;
tL_fileLocationToBeDeprecated.volume_id = -2147483648L;
tL_fileLocationToBeDeprecated.local_id = SharedConfig.getLastLocalId();
}
if (findPhotoCachedSize.h > 50 || findPhotoCachedSize.w > 50) {
boolean z = true;
File pathToAttach = FileLoader.getInstance(UserConfig.selectedAccount).getPathToAttach(findPhotoCachedSize, true);
if (MessageObject.shouldEncryptPhotoOrVideo(UserConfig.selectedAccount, message)) {
pathToAttach = new File(pathToAttach.getAbsolutePath() + ".enc");
} else {
z = false;
}
if (!pathToAttach.exists()) {
if (z) {
try {
RandomAccessFile randomAccessFile = new RandomAccessFile(new File(FileLoader.getInternalCacheDir(), pathToAttach.getName() + ".key"), "rws");
long length = randomAccessFile.length();
byte[] bArr2 = new byte[32];
byte[] bArr3 = new byte[16];
if (length <= 0 || length % 48 != 0) {
Utilities.random.nextBytes(bArr2);
Utilities.random.nextBytes(bArr3);
randomAccessFile.write(bArr2);
randomAccessFile.write(bArr3);
} else {
randomAccessFile.read(bArr2, 0, 32);
randomAccessFile.read(bArr3, 0, 16);
}
randomAccessFile.close();
Utilities.aesCtrDecryptionByteArray(findPhotoCachedSize.bytes, bArr2, bArr3, 0, r8.length, 0);
} catch (Exception e) {
FileLog.e(e);
}
}
RandomAccessFile randomAccessFile2 = new RandomAccessFile(pathToAttach, "rws");
randomAccessFile2.write(findPhotoCachedSize.bytes);
randomAccessFile2.close();
}
tL_photoSize_layer127 = new TLRPC.TL_photoSize_layer127();
tL_photoSize_layer127.w = findPhotoCachedSize.w;
tL_photoSize_layer127.h = findPhotoCachedSize.h;
tL_photoSize_layer127.location = findPhotoCachedSize.location;
tL_photoSize_layer127.size = findPhotoCachedSize.size;
tL_photoSize_layer127.type = findPhotoCachedSize.type;
} else {
tL_photoSize_layer127 = new TLRPC.TL_photoStrippedSize();
tL_photoSize_layer127.location = findPhotoCachedSize.location;
tL_photoSize_layer127.bytes = findPhotoCachedSize.bytes;
tL_photoSize_layer127.h = findPhotoCachedSize.h;
tL_photoSize_layer127.w = findPhotoCachedSize.w;
}
TLRPC.MessageMedia messageMedia2 = message.media;
if (messageMedia2 instanceof TLRPC.TL_messageMediaPhoto) {
int size = messageMedia2.photo.sizes.size();
while (i < size) {
if (((TLRPC.PhotoSize) message.media.photo.sizes.get(i)) instanceof TLRPC.TL_photoCachedSize) {
photo = message.media.photo;
} else {
i++;
}
}
return;
}
if (messageMedia2 instanceof TLRPC.TL_messageMediaDocument) {
int size2 = messageMedia2.document.thumbs.size();
while (i < size2) {
if (((TLRPC.PhotoSize) message.media.document.thumbs.get(i)) instanceof TLRPC.TL_photoCachedSize) {
arrayList = message.media.document.thumbs;
arrayList.set(i, tL_photoSize_layer127);
}
i++;
}
return;
}
if (messageMedia2 instanceof TLRPC.TL_messageMediaWebPage) {
int size3 = messageMedia2.webpage.photo.sizes.size();
while (i < size3) {
if (((TLRPC.PhotoSize) message.media.webpage.photo.sizes.get(i)) instanceof TLRPC.TL_photoCachedSize) {
photo = message.media.webpage.photo;
} else {
i++;
}
}
return;
}
return;
arrayList = photo.sizes;
arrayList.set(i, tL_photoSize_layer127);
}
public static void saveMessageThumbs(TLRPC.Message message, TLRPC.MessageMedia messageMedia) {
TLRPC.PhotoSize findPhotoCachedSize;
byte[] bArr;
TLRPC.PhotoSize tL_photoSize_layer127;
TLRPC.Photo photo;
ArrayList arrayList;
if (message == null || messageMedia == null || (findPhotoCachedSize = findPhotoCachedSize(messageMedia)) == null || (bArr = findPhotoCachedSize.bytes) == null || bArr.length == 0) {
return;
}
TLRPC.FileLocation fileLocation = findPhotoCachedSize.location;
if (fileLocation == null || (fileLocation instanceof TLRPC.TL_fileLocationUnavailable)) {
TLRPC.TL_fileLocationToBeDeprecated tL_fileLocationToBeDeprecated = new TLRPC.TL_fileLocationToBeDeprecated();
findPhotoCachedSize.location = tL_fileLocationToBeDeprecated;
tL_fileLocationToBeDeprecated.volume_id = -2147483648L;
tL_fileLocationToBeDeprecated.local_id = SharedConfig.getLastLocalId();
}
int i = 0;
if (findPhotoCachedSize.h > 50 || findPhotoCachedSize.w > 50) {
boolean z = true;
File pathToAttach = FileLoader.getInstance(UserConfig.selectedAccount).getPathToAttach(findPhotoCachedSize, true);
if (MessageObject.shouldEncryptPhotoOrVideo(UserConfig.selectedAccount, message)) {
pathToAttach = new File(pathToAttach.getAbsolutePath() + ".enc");
} else {
z = false;
}
if (!pathToAttach.exists()) {
if (z) {
try {
RandomAccessFile randomAccessFile = new RandomAccessFile(new File(FileLoader.getInternalCacheDir(), pathToAttach.getName() + ".key"), "rws");
long length = randomAccessFile.length();
byte[] bArr2 = new byte[32];
byte[] bArr3 = new byte[16];
if (length <= 0 || length % 48 != 0) {
Utilities.random.nextBytes(bArr2);
Utilities.random.nextBytes(bArr3);
randomAccessFile.write(bArr2);
randomAccessFile.write(bArr3);
} else {
randomAccessFile.read(bArr2, 0, 32);
randomAccessFile.read(bArr3, 0, 16);
}
randomAccessFile.close();
Utilities.aesCtrDecryptionByteArray(findPhotoCachedSize.bytes, bArr2, bArr3, 0, r7.length, 0);
} catch (Exception e) {
FileLog.e(e);
}
}
RandomAccessFile randomAccessFile2 = new RandomAccessFile(pathToAttach, "rws");
randomAccessFile2.write(findPhotoCachedSize.bytes);
randomAccessFile2.close();
}
tL_photoSize_layer127 = new TLRPC.TL_photoSize_layer127();
tL_photoSize_layer127.w = findPhotoCachedSize.w;
tL_photoSize_layer127.h = findPhotoCachedSize.h;
tL_photoSize_layer127.location = findPhotoCachedSize.location;
tL_photoSize_layer127.size = findPhotoCachedSize.size;
tL_photoSize_layer127.type = findPhotoCachedSize.type;
} else {
tL_photoSize_layer127 = new TLRPC.TL_photoStrippedSize();
tL_photoSize_layer127.location = findPhotoCachedSize.location;
tL_photoSize_layer127.bytes = findPhotoCachedSize.bytes;
tL_photoSize_layer127.h = findPhotoCachedSize.h;
tL_photoSize_layer127.w = findPhotoCachedSize.w;
}
if (messageMedia instanceof TLRPC.TL_messageMediaPhoto) {
int size = messageMedia.photo.sizes.size();
while (i < size) {
if (((TLRPC.PhotoSize) messageMedia.photo.sizes.get(i)) instanceof TLRPC.TL_photoCachedSize) {
photo = messageMedia.photo;
} else {
i++;
}
}
return;
}
if (messageMedia instanceof TLRPC.TL_messageMediaDocument) {
int size2 = messageMedia.document.thumbs.size();
while (i < size2) {
if (((TLRPC.PhotoSize) messageMedia.document.thumbs.get(i)) instanceof TLRPC.TL_photoCachedSize) {
arrayList = messageMedia.document.thumbs;
arrayList.set(i, tL_photoSize_layer127);
}
i++;
}
return;
}
if (messageMedia instanceof TLRPC.TL_messageMediaWebPage) {
int size3 = messageMedia.webpage.photo.sizes.size();
while (i < size3) {
if (((TLRPC.PhotoSize) messageMedia.webpage.photo.sizes.get(i)) instanceof TLRPC.TL_photoCachedSize) {
photo = messageMedia.webpage.photo;
} else {
i++;
}
}
return;
}
return;
arrayList = photo.sizes;
arrayList.set(i, tL_photoSize_layer127);
}
public static void saveMessagesThumbs(ArrayList<TLRPC.Message> arrayList) {
if (arrayList == null || arrayList.isEmpty()) {
return;
}
for (int i = 0; i < arrayList.size(); i++) {
saveMessageThumbs(arrayList.get(i));
}
}
public static TLRPC.PhotoSize scaleAndSaveImage(Bitmap bitmap, float f, float f2, int i, boolean z) {
return scaleAndSaveImage(null, bitmap, Bitmap.CompressFormat.JPEG, false, f, f2, i, z, 0, 0, false);
}
public static TLRPC.PhotoSize scaleAndSaveImage(Bitmap bitmap, float f, float f2, int i, boolean z, int i2, int i3) {
return scaleAndSaveImage(null, bitmap, Bitmap.CompressFormat.JPEG, false, f, f2, i, z, i2, i3, false);
}
public static TLRPC.PhotoSize scaleAndSaveImage(Bitmap bitmap, float f, float f2, boolean z, int i, boolean z2, int i2, int i3) {
return scaleAndSaveImage(null, bitmap, Bitmap.CompressFormat.JPEG, z, f, f2, i, z2, i2, i3, false);
}
public static TLRPC.PhotoSize scaleAndSaveImage(Bitmap bitmap, Bitmap.CompressFormat compressFormat, float f, float f2, int i, boolean z, int i2, int i3) {
return scaleAndSaveImage(null, bitmap, compressFormat, false, f, f2, i, z, i2, i3, false);
}
public static TLRPC.PhotoSize scaleAndSaveImage(TLRPC.PhotoSize photoSize, Bitmap bitmap, float f, float f2, int i, boolean z, boolean z2) {
return scaleAndSaveImage(photoSize, bitmap, Bitmap.CompressFormat.JPEG, false, f, f2, i, z, 0, 0, z2);
}
public static TLRPC.PhotoSize scaleAndSaveImage(TLRPC.PhotoSize photoSize, Bitmap bitmap, Bitmap.CompressFormat compressFormat, boolean z, float f, float f2, int i, boolean z2, int i2, int i3, boolean z3) {
float f3;
boolean z4;
int i4;
int i5;
float max;
if (bitmap == null) {
return null;
}
float width = bitmap.getWidth();
float height = bitmap.getHeight();
if (width != 0.0f && height != 0.0f) {
float max2 = Math.max(width / f, height / f2);
if (i2 != 0 && i3 != 0) {
float f4 = i2;
if (width < f4 || height < i3) {
if (width >= f4 || height <= i3) {
if (width > f4) {
float f5 = i3;
if (height < f5) {
max = height / f5;
}
}
max = Math.max(width / f4, height / i3);
} else {
max = width / f4;
}
f3 = max;
z4 = true;
i4 = (int) (width / f3);
i5 = (int) (height / f3);
if (i5 != 0 && i4 != 0) {
try {
return scaleAndSaveImageInternal(photoSize, bitmap, compressFormat, z, i4, i5, width, height, f3, i, z2, z4, z3);
} catch (Throwable th) {
FileLog.e(th);
getInstance().clearMemory();
System.gc();
try {
return scaleAndSaveImageInternal(photoSize, bitmap, compressFormat, z, i4, i5, width, height, f3, i, z2, z4, z3);
} catch (Throwable th2) {
FileLog.e(th2);
}
}
}
}
}
f3 = max2;
z4 = false;
i4 = (int) (width / f3);
i5 = (int) (height / f3);
if (i5 != 0) {
return scaleAndSaveImageInternal(photoSize, bitmap, compressFormat, z, i4, i5, width, height, f3, i, z2, z4, z3);
}
}
return null;
}
private static org.telegram.tgnet.TLRPC.PhotoSize scaleAndSaveImageInternal(org.telegram.tgnet.TLRPC.PhotoSize r2, android.graphics.Bitmap r3, android.graphics.Bitmap.CompressFormat r4, boolean r5, int r6, int r7, float r8, float r9, float r10, int r11, boolean r12, boolean r13, boolean r14) {
throw new UnsupportedOperationException("Method not decompiled: org.telegram.messenger.ImageLoader.scaleAndSaveImageInternal(org.telegram.tgnet.TLRPC$PhotoSize, android.graphics.Bitmap, android.graphics.Bitmap$CompressFormat, boolean, int, int, float, float, float, int, boolean, boolean, boolean):org.telegram.tgnet.TLRPC$PhotoSize");
}
public static boolean shouldSendImageAsDocument(String str, Uri uri) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
if (str == null && uri != null && uri.getScheme() != null) {
if (uri.getScheme().contains("file")) {
str = uri.getPath();
} else {
try {
str = AndroidUtilities.getPath(uri);
} catch (Throwable th) {
FileLog.e(th);
}
}
}
if (str != null) {
BitmapFactory.decodeFile(str, options);
} else if (uri != null) {
try {
InputStream openInputStream = ApplicationLoader.applicationContext.getContentResolver().openInputStream(uri);
BitmapFactory.decodeStream(openInputStream, null, options);
openInputStream.close();
} catch (Throwable th2) {
FileLog.e(th2);
return false;
}
}
float f = options.outWidth;
float f2 = options.outHeight;
return f / f2 > 10.0f || f2 / f > 10.0f;
}
public int sizeOfBitmapDrawable(BitmapDrawable bitmapDrawable) {
if (!(bitmapDrawable instanceof AnimatedFileDrawable)) {
return bitmapDrawable instanceof RLottieDrawable ? bitmapDrawable.getIntrinsicWidth() * bitmapDrawable.getIntrinsicHeight() * 8 : bitmapDrawable.getBitmap().getByteCount();
}
AnimatedFileDrawable animatedFileDrawable = (AnimatedFileDrawable) bitmapDrawable;
return Math.max(animatedFileDrawable.getIntrinsicHeight() * bitmapDrawable.getIntrinsicWidth() * 12, animatedFileDrawable.getRenderingHeight() * animatedFileDrawable.getRenderingWidth() * 12);
}
private boolean useLottieMemCache(ImageLocation imageLocation, String str) {
if (str.endsWith("_firstframe") || str.endsWith("_lastframe")) {
return false;
}
return (imageLocation != null && (MessageObject.isAnimatedStickerDocument(imageLocation.document, true) || imageLocation.imageType == 1 || MessageObject.isVideoSticker(imageLocation.document))) || isAnimatedAvatar(str);
}
public void addTestWebFile(String str, WebFile webFile) {
if (str == null || webFile == null) {
return;
}
this.testWebFile.put(str, webFile);
}
public void cancelForceLoadingForImageReceiver(ImageReceiver imageReceiver) {
final String imageKey;
if (imageReceiver == null || (imageKey = imageReceiver.getImageKey()) == null) {
return;
}
this.imageLoadQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ImageLoader.this.lambda$cancelForceLoadingForImageReceiver$6(imageKey);
}
});
}
public void cancelLoadHttpFile(String str) {
HttpFileTask httpFileTask = this.httpFileLoadTasksByKeys.get(str);
if (httpFileTask != null) {
httpFileTask.cancel(true);
this.httpFileLoadTasksByKeys.remove(str);
this.httpFileLoadTasks.remove(httpFileTask);
}
Runnable runnable = this.retryHttpsTasks.get(str);
if (runnable != null) {
AndroidUtilities.cancelRunOnUIThread(runnable);
}
runHttpFileLoadTasks(null, 0);
}
public void cancelLoadingForImageReceiver(final ImageReceiver imageReceiver, final boolean z) {
if (imageReceiver == null) {
return;
}
WebInstantView.cancelLoadPhoto(imageReceiver);
ArrayList<Runnable> loadingOperations = imageReceiver.getLoadingOperations();
if (!loadingOperations.isEmpty()) {
for (int i = 0; i < loadingOperations.size(); i++) {
this.imageLoadQueue.cancelRunnable(loadingOperations.get(i));
}
loadingOperations.clear();
}
imageReceiver.addLoadingImageRunnable(null);
this.imageLoadQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ImageLoader.this.lambda$cancelLoadingForImageReceiver$4(z, imageReceiver);
}
});
}
public void changeFileLoadingPriorityForImageReceiver(final ImageReceiver imageReceiver) {
if (imageReceiver == null) {
return;
}
final int fileLoadingPriority = imageReceiver.getFileLoadingPriority();
this.imageLoadQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ImageLoader.this.lambda$changeFileLoadingPriorityForImageReceiver$3(imageReceiver, fileLoadingPriority);
}
});
}
public void checkMediaPaths() {
checkMediaPaths(null);
}
public void checkMediaPaths(final Runnable runnable) {
this.cacheOutQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ImageLoader.this.lambda$checkMediaPaths$1(runnable);
}
});
}
public void clearMemory() {
this.smallImagesMemCache.evictAll();
this.memCache.evictAll();
this.lottieMemCache.evictAll();
}
public android.util.SparseArray<java.io.File> createMediaPaths() {
throw new UnsupportedOperationException("Method not decompiled: org.telegram.messenger.ImageLoader.createMediaPaths():android.util.SparseArray");
}
public boolean decrementUseCount(String str) {
Integer num = this.bitmapUseCounts.get(str);
if (num == null) {
return true;
}
if (num.intValue() == 1) {
this.bitmapUseCounts.remove(str);
return true;
}
this.bitmapUseCounts.put(str, Integer.valueOf(num.intValue() - 1));
return false;
}
public DispatchQueuePriority getCacheOutQueue() {
return this.cacheOutQueue;
}
public Float getFileProgress(String str) {
long[] jArr;
if (str == null || (jArr = (long[]) this.fileProgresses.get(str)) == null) {
return null;
}
long j = jArr[1];
return Float.valueOf(j == 0 ? 0.0f : Math.min(1.0f, jArr[0] / j));
}
public long[] getFileProgressSizes(String str) {
if (str == null) {
return null;
}
return (long[]) this.fileProgresses.get(str);
}
public BitmapDrawable getFromMemCache(String str) {
BitmapDrawable bitmapDrawable = this.memCache.get(str);
if (bitmapDrawable == null) {
bitmapDrawable = this.smallImagesMemCache.get(str);
}
if (bitmapDrawable == null) {
bitmapDrawable = this.wallpaperMemCache.get(str);
}
return bitmapDrawable == null ? getFromLottieCache(str) : bitmapDrawable;
}
public BitmapDrawable getImageFromMemory(TLObject tLObject, String str, String str2) {
StringBuilder sb;
long j;
String str3 = null;
if (tLObject == null && str == null) {
return null;
}
if (str != null) {
str3 = Utilities.MD5(str);
} else {
if (tLObject instanceof TLRPC.FileLocation) {
TLRPC.FileLocation fileLocation = (TLRPC.FileLocation) tLObject;
sb = new StringBuilder();
sb.append(fileLocation.volume_id);
sb.append("_");
sb.append(fileLocation.local_id);
} else {
if (tLObject instanceof TLRPC.Document) {
TLRPC.Document document = (TLRPC.Document) tLObject;
sb = new StringBuilder();
sb.append(document.dc_id);
sb.append("_");
j = document.id;
} else if (tLObject instanceof SecureDocument) {
SecureDocument secureDocument = (SecureDocument) tLObject;
sb = new StringBuilder();
sb.append(secureDocument.secureFile.dc_id);
sb.append("_");
j = secureDocument.secureFile.id;
} else if (tLObject instanceof WebFile) {
str3 = Utilities.MD5(((WebFile) tLObject).url);
}
sb.append(j);
}
str3 = sb.toString();
}
if (str2 != null) {
str3 = str3 + "@" + str2;
}
return getFromMemCache(str3);
}
public LruCache<BitmapDrawable> getLottieMemCahce() {
return this.lottieMemCache;
}
public String getReplacedKey(String str) {
if (str == null) {
return null;
}
return this.replacedBitmaps.get(str);
}
public boolean hasLottieMemCache(String str) {
LruCache<BitmapDrawable> lruCache = this.lottieMemCache;
return lruCache != null && lruCache.contains(str);
}
public void incrementUseCount(String str) {
Integer num = this.bitmapUseCounts.get(str);
if (num == null) {
this.bitmapUseCounts.put(str, 1);
} else {
this.bitmapUseCounts.put(str, Integer.valueOf(num.intValue() + 1));
}
}
public boolean isInMemCache(String str, boolean z) {
return z ? getFromLottieCache(str) != null : getFromMemCache(str) != null;
}
public boolean isLoadingHttpFile(String str) {
return this.httpFileLoadTasksByKeys.containsKey(str);
}
public void loadHttpFile(String str, String str2, int i) {
if (str == null || str.length() == 0 || this.httpFileLoadTasksByKeys.containsKey(str)) {
return;
}
String httpUrlExtension = getHttpUrlExtension(str, str2);
File file = new File(FileLoader.getDirectory(4), Utilities.MD5(str) + "_temp." + httpUrlExtension);
file.delete();
HttpFileTask httpFileTask = new HttpFileTask(str, file, httpUrlExtension, i);
this.httpFileLoadTasks.add(httpFileTask);
this.httpFileLoadTasksByKeys.put(str, httpFileTask);
runHttpFileLoadTasks(null, 0);
}
public void loadImageForImageReceiver(ImageReceiver imageReceiver) {
loadImageForImageReceiver(imageReceiver, null);
}
public void loadImageForImageReceiver(org.telegram.messenger.ImageReceiver r38, java.util.List<org.telegram.messenger.ImageReceiver> r39) {
throw new UnsupportedOperationException("Method not decompiled: org.telegram.messenger.ImageLoader.loadImageForImageReceiver(org.telegram.messenger.ImageReceiver, java.util.List):void");
}
public void moveToFront(String str) {
if (str == null) {
return;
}
if (this.lottieMemCache.get(str) != null) {
this.lottieMemCache.moveToFront(str);
}
if (this.memCache.get(str) != null) {
this.memCache.moveToFront(str);
}
if (this.smallImagesMemCache.get(str) != null) {
this.smallImagesMemCache.moveToFront(str);
}
}
public void onFragmentStackChanged() {
for (int i = 0; i < this.cachedAnimatedFileDrawables.size(); i++) {
this.cachedAnimatedFileDrawables.get(i).repeatCount = 0;
}
}
public void preloadArtwork(final String str) {
this.imageLoadQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ImageLoader.this.lambda$preloadArtwork$8(str);
}
});
}
public void putImageToCache(BitmapDrawable bitmapDrawable, String str, boolean z) {
(z ? this.smallImagesMemCache : this.memCache).put(str, bitmapDrawable);
}
public void putThumbsToCache(ArrayList<MessageThumb> arrayList) {
for (int i = 0; i < arrayList.size(); i++) {
putImageToCache(arrayList.get(i).drawable, arrayList.get(i).key, true);
}
}
public void removeImage(String str) {
this.bitmapUseCounts.remove(str);
this.memCache.remove(str);
this.smallImagesMemCache.remove(str);
}
public void removeTestWebFile(String str) {
if (str == null) {
return;
}
this.testWebFile.remove(str);
}
public void replaceImageInCache(final String str, final String str2, final ImageLocation imageLocation, boolean z) {
if (z) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
ImageLoader.this.lambda$replaceImageInCache$5(str, str2, imageLocation);
}
});
} else {
lambda$replaceImageInCache$5(str, str2, imageLocation);
}
}
}