Telegram5 v10.6.2版本的 MD5 值为:423cae39e902ed9dd2cc7f4b4547b276

以下内容为反编译后的 ImageLoader.java 源代码,内容仅作参考


package org.telegram.messenger;

import android.annotation.TargetApi;
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.Matrix;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Point;
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.media.MediaMetadataRetriever;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Environment;
import android.os.Environmenu;
import android.os.SystemClock;
import android.provider.MediaStore;
import android.text.TextUtils;
import android.util.Pair;
import android.util.SparseArray;
import androidx.core.graphics.ColorUtils;
import j$.util.concurrent.ConcurrentHashMap;
import j$.util.function.Consumer;
import j$.util.stream.Stream;
import j$.wrappers.C$r8$wrapper$java$util$stream$Stream$VWRP;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.InterruptedIOException;
import java.io.RandomAccessFile;
import java.net.HttpURLConnection;
import java.net.SocketException;
import java.net.SocketTimeoutException;
import java.net.URL;
import java.net.URLConnection;
import java.net.UnknownHostException;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.file.CopyOption;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.zip.GZIPInputStream;
import org.json.JSONArray;
import org.json.JSONObject;
import org.telegram.DispatchQueuePriority;
import org.telegram.messenger.DocumentObject;
import org.telegram.messenger.FileLoader;
import org.telegram.messenger.FilePathDatabase;
import org.telegram.messenger.ImageLoader;
import org.telegram.messenger.ImageReceiver;
import org.telegram.messenger.secretmedia.EncryptedFileInputStream;
import org.telegram.messenger.utils.BitmapsCache;
import org.telegram.tgnet.ConnectionsManager;
import org.telegram.tgnet.RequestDelegate;
import org.telegram.tgnet.TLObject;
import org.telegram.tgnet.TLRPC$Document;
import org.telegram.tgnet.TLRPC$FileLocation;
import org.telegram.tgnet.TLRPC$InputEncryptedFile;
import org.telegram.tgnet.TLRPC$InputFile;
import org.telegram.tgnet.TLRPC$Message;
import org.telegram.tgnet.TLRPC$MessageExtendedMedia;
import org.telegram.tgnet.TLRPC$MessageMedia;
import org.telegram.tgnet.TLRPC$Photo;
import org.telegram.tgnet.TLRPC$PhotoSize;
import org.telegram.tgnet.TLRPC$TL_document;
import org.telegram.tgnet.TLRPC$TL_documentAttributeVideo;
import org.telegram.tgnet.TLRPC$TL_documentEncrypted;
import org.telegram.tgnet.TLRPC$TL_error;
import org.telegram.tgnet.TLRPC$TL_fileLocationToBeDeprecated;
import org.telegram.tgnet.TLRPC$TL_fileLocationUnavailable;
import org.telegram.tgnet.TLRPC$TL_messageExtendedMediaPreview;
import org.telegram.tgnet.TLRPC$TL_messageMediaDocument;
import org.telegram.tgnet.TLRPC$TL_messageMediaInvoice;
import org.telegram.tgnet.TLRPC$TL_messageMediaPhoto;
import org.telegram.tgnet.TLRPC$TL_messageMediaWebPage;
import org.telegram.tgnet.TLRPC$TL_photoCachedSize;
import org.telegram.tgnet.TLRPC$TL_photoPathSize;
import org.telegram.tgnet.TLRPC$TL_photoSize_layer127;
import org.telegram.tgnet.TLRPC$TL_photoStrippedSize;
import org.telegram.tgnet.TLRPC$TL_secureFile;
import org.telegram.tgnet.TLRPC$TL_upload_getWebFile;
import org.telegram.tgnet.TLRPC$WallPaper;
import org.telegram.tgnet.TLRPC$WallPaperSettings;
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.RLottieDrawable;
import org.telegram.ui.Components.SlotsDrawable;
import org.telegram.ui.Components.ThemePreviewDrawable;

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<>();
    private HashMap<String, CacheImage> imageLoadingByKeys = new HashMap<>();
    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;

    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 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 boolean isSdCardPath(File file) {
        return !TextUtils.isEmpty(SharedConfig.storageCacheDir) && file.getAbsolutePath().startsWith(SharedConfig.storageCacheDir);
    }

    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 putThumbsToCache(ArrayList<MessageThumb> arrayList) {
        for (int i = 0; i < arrayList.size(); i++) {
            putImageToCache(arrayList.get(i).drawable, arrayList.get(i).key, true);
        }
    }

    public LruCache<BitmapDrawable> getLottieMemCahce() {
        return this.lottieMemCache;
    }

    public 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<>();
        }
    }

    public 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;
        }

        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);
                }
            });
        }

        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);
                }
            });
        }

        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));
        }

        @Override
        public Boolean doInBackground(Void... voidArr) {
            InputStream inputStream;
            URLConnection uRLConnection;
            InputStream inputStream2;
            List<String> list;
            String str;
            int responseCode;
            boolean z = true;
            boolean z2 = false;
            try {
                uRLConnection = new URL(this.url).openConnection();
                try {
                    uRLConnection.addRequestProperty("User-Agent", "Mozilla/5.0 (iPhone; CPU iPhone OS 10_0 like Mac OS X) AppleWebKit/602.1.38 (KHTML, like Gecko) Version/10.0 Mobile/14A5297c Safari/602.1");
                    uRLConnection.setConnectTimeout(5000);
                    uRLConnection.setReadTimeout(5000);
                    if (uRLConnection instanceof HttpURLConnection) {
                        HttpURLConnection httpURLConnection = (HttpURLConnection) uRLConnection;
                        httpURLConnection.setInstanceFollowRedirects(true);
                        int responseCode2 = httpURLConnection.getResponseCode();
                        if (responseCode2 == 302 || responseCode2 == 301 || responseCode2 == 303) {
                            String headerField = httpURLConnection.getHeaderField("Location");
                            String headerField2 = httpURLConnection.getHeaderField("Set-Cookie");
                            uRLConnection = new URL(headerField).openConnection();
                            uRLConnection.setRequestProperty("Cookie", headerField2);
                            uRLConnection.addRequestProperty("User-Agent", "Mozilla/5.0 (iPhone; CPU iPhone OS 10_0 like Mac OS X) AppleWebKit/602.1.38 (KHTML, like Gecko) Version/10.0 Mobile/14A5297c Safari/602.1");
                        }
                    }
                    uRLConnection.connect();
                    inputStream2 = uRLConnection.getInputStream();
                    try {
                        this.fileOutputStream = new RandomAccessFile(this.tempFile, "rws");
                    } catch (Throwable th) {
                        inputStream = inputStream2;
                        th = th;
                        if (th instanceof SocketTimeoutException) {
                            if (ApplicationLoader.isNetworkOnline()) {
                                this.canRetry = false;
                            }
                        } else if (th instanceof UnknownHostException) {
                            this.canRetry = false;
                        } else if (th instanceof SocketException) {
                            if (th.getMessage() != null && th.getMessage().contains("ECONNRESET")) {
                                this.canRetry = false;
                            }
                        } else if (th instanceof FileNotFoundException) {
                            this.canRetry = false;
                        }
                        FileLog.e(th);
                        inputStream2 = inputStream;
                        if (this.canRetry) {
                        }
                        return Boolean.valueOf(z2);
                    }
                } catch (Throwable th2) {
                    th = th2;
                    inputStream = null;
                }
            } catch (Throwable th3) {
                th = th3;
                inputStream = null;
                uRLConnection = null;
            }
            if (this.canRetry) {
                try {
                    if ((uRLConnection instanceof HttpURLConnection) && (responseCode = ((HttpURLConnection) uRLConnection).getResponseCode()) != 200 && responseCode != 202 && responseCode != 304) {
                        this.canRetry = false;
                    }
                } catch (Exception e) {
                    FileLog.e(e);
                }
                if (uRLConnection != null) {
                    try {
                        Map<String, List<String>> headerFields = uRLConnection.getHeaderFields();
                        if (headerFields != null && (list = headerFields.get("content-Length")) != null && !list.isEmpty() && (str = list.get(0)) != null) {
                            this.fileSize = Utilities.parseInt((CharSequence) str).intValue();
                        }
                    } catch (Exception e2) {
                        FileLog.e(e2);
                    }
                }
                if (inputStream2 != null) {
                    try {
                        byte[] bArr = new byte[LiteMode.FLAG_CHAT_SCALE];
                        int i = 0;
                        while (true) {
                            if (isCancelled()) {
                                break;
                            }
                            try {
                                int read = inputStream2.read(bArr);
                                if (read <= 0) {
                                    break;
                                }
                                this.fileOutputStream.write(bArr, 0, read);
                                i += read;
                                int i2 = this.fileSize;
                                if (i2 > 0) {
                                    reportProgress(i, i2);
                                }
                            } catch (Exception e3) {
                                e = e3;
                                z = false;
                            }
                        }
                    } catch (Throwable th4) {
                        th = th4;
                        z = false;
                    }
                    z2 = z;
                }
                try {
                    RandomAccessFile randomAccessFile = this.fileOutputStream;
                    if (randomAccessFile != null) {
                        randomAccessFile.close();
                        this.fileOutputStream = null;
                    }
                } catch (Throwable th5) {
                    FileLog.e(th5);
                }
                if (inputStream2 != null) {
                    try {
                        inputStream2.close();
                    } catch (Throwable th6) {
                        FileLog.e(th6);
                    }
                }
            }
            return Boolean.valueOf(z2);
        }

        @Override
        public void onPostExecute(Boolean bool) {
            ImageLoader.this.runHttpFileLoadTasks(this, bool.booleanValue() ? 2 : 1);
        }

        @Override
        protected void onCancelled() {
            ImageLoader.this.runHttpFileLoadTasks(this, 2);
        }
    }

    public 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;
        }

        @Override
        public String doInBackground(Void... voidArr) {
            InputStream inputStream;
            ByteArrayOutputStream byteArrayOutputStream;
            InputStream inputStream2;
            ByteArrayOutputStream byteArrayOutputStream2;
            int read;
            int responseCode;
            try {
                try {
                    HttpURLConnection httpURLConnection = (HttpURLConnection) new URL(this.cacheImage.imageLocation.path.replace("athumb://", "https://")).openConnection();
                    this.httpConnection = httpURLConnection;
                    httpURLConnection.setConnectTimeout(5000);
                    this.httpConnection.setReadTimeout(5000);
                    this.httpConnection.connect();
                    try {
                        HttpURLConnection httpURLConnection2 = this.httpConnection;
                        if (httpURLConnection2 != null && (responseCode = httpURLConnection2.getResponseCode()) != 200 && responseCode != 202 && responseCode != 304) {
                            this.canRetry = false;
                        }
                    } catch (Exception e) {
                        FileLog.e((Throwable) e, false);
                    }
                    inputStream2 = this.httpConnection.getInputStream();
                    try {
                        byteArrayOutputStream2 = new ByteArrayOutputStream();
                    } catch (Throwable th) {
                        byteArrayOutputStream = null;
                        inputStream = inputStream2;
                        th = th;
                    }
                } catch (Throwable th2) {
                    th = th2;
                    inputStream = null;
                    byteArrayOutputStream = null;
                }
            } catch (Exception unused) {
            }
            try {
                byte[] bArr = new byte[LiteMode.FLAG_CHAT_SCALE];
                while (!isCancelled() && (read = inputStream2.read(bArr)) > 0) {
                    byteArrayOutputStream2.write(bArr, 0, read);
                }
                this.canRetry = false;
                JSONArray jSONArray = new JSONObject(new String(byteArrayOutputStream2.toByteArray())).getJSONArray("results");
                if (jSONArray.length() <= 0) {
                    try {
                        HttpURLConnection httpURLConnection3 = this.httpConnection;
                        if (httpURLConnection3 != null) {
                            httpURLConnection3.disconnect();
                        }
                    } catch (Throwable unused2) {
                    }
                    if (inputStream2 != null) {
                        try {
                            inputStream2.close();
                        } catch (Throwable th3) {
                            FileLog.e(th3);
                        }
                    }
                    byteArrayOutputStream2.close();
                }
                String string = jSONArray.getJSONObject(0).getString("artworkUrl100");
                if (this.small) {
                    try {
                        HttpURLConnection httpURLConnection4 = this.httpConnection;
                        if (httpURLConnection4 != null) {
                            httpURLConnection4.disconnect();
                        }
                    } catch (Throwable unused3) {
                    }
                    if (inputStream2 != null) {
                        try {
                            inputStream2.close();
                        } catch (Throwable th4) {
                            FileLog.e(th4);
                        }
                    }
                    try {
                        byteArrayOutputStream2.close();
                    } catch (Exception unused4) {
                    }
                    return string;
                }
                String replace = string.replace("100x100", "600x600");
                try {
                    HttpURLConnection httpURLConnection5 = this.httpConnection;
                    if (httpURLConnection5 != null) {
                        httpURLConnection5.disconnect();
                    }
                } catch (Throwable unused5) {
                }
                if (inputStream2 != null) {
                    try {
                        inputStream2.close();
                    } catch (Throwable th5) {
                        FileLog.e(th5);
                    }
                }
                try {
                    byteArrayOutputStream2.close();
                } catch (Exception unused6) {
                }
                return replace;
            } catch (Throwable th6) {
                inputStream = inputStream2;
                th = th6;
                byteArrayOutputStream = byteArrayOutputStream2;
                try {
                    if (th instanceof SocketTimeoutException) {
                        if (ApplicationLoader.isNetworkOnline()) {
                            this.canRetry = false;
                        }
                    } else if (th instanceof UnknownHostException) {
                        this.canRetry = false;
                    } else if (th instanceof SocketException) {
                        if (th.getMessage() != null && th.getMessage().contains("ECONNRESET")) {
                            this.canRetry = false;
                        }
                    } else if (th instanceof FileNotFoundException) {
                        this.canRetry = false;
                    }
                    FileLog.e(th, false);
                    try {
                        HttpURLConnection httpURLConnection6 = this.httpConnection;
                        if (httpURLConnection6 != null) {
                            httpURLConnection6.disconnect();
                        }
                    } catch (Throwable unused7) {
                    }
                    if (inputStream != null) {
                        try {
                            inputStream.close();
                        } catch (Throwable th7) {
                            FileLog.e(th7);
                        }
                    }
                    if (byteArrayOutputStream != null) {
                        byteArrayOutputStream.close();
                    }
                    return null;
                } catch (Throwable th8) {
                    try {
                        HttpURLConnection httpURLConnection7 = this.httpConnection;
                        if (httpURLConnection7 != null) {
                            httpURLConnection7.disconnect();
                        }
                    } catch (Throwable unused8) {
                    }
                    if (inputStream != null) {
                        try {
                            inputStream.close();
                        } catch (Throwable th9) {
                            FileLog.e(th9);
                        }
                    }
                    if (byteArrayOutputStream == null) {
                        throw th8;
                    }
                    try {
                        byteArrayOutputStream.close();
                        throw th8;
                    } catch (Exception unused9) {
                        throw th8;
                    }
                }
            }
        }

        @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();
                }
            });
        }

        public void lambda$onPostExecute$0(String str) {
            CacheImage cacheImage = this.cacheImage;
            cacheImage.httpTask = 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);
        }

        public void lambda$onCancelled$2() {
            ImageLoader.this.runArtworkTasks(true);
        }

        @Override
        protected void onCancelled() {
            ImageLoader.this.imageLoadQueue.postRunnable(new Runnable() {
                @Override
                public final void run() {
                    ImageLoader.ArtworkLoadTask.this.lambda$onCancelled$2();
                }
            });
        }
    }

    public 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 static void lambda$doInBackground$2(TLObject tLObject, TLRPC$TL_error tLRPC$TL_error) {
        }

        public HttpImageTask(CacheImage cacheImage, long j) {
            this.cacheImage = cacheImage;
            this.imageSize = j;
        }

        public HttpImageTask(CacheImage cacheImage, int i, String str) {
            this.cacheImage = cacheImage;
            this.imageSize = i;
            this.overrideUrl = str;
        }

        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);
                }
            });
        }

        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);
                }
            });
        }

        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));
        }

        @Override
        public Boolean doInBackground(Void... voidArr) {
            InputStream inputStream;
            boolean z;
            InputStream inputStream2;
            int i;
            WebFile webFile;
            HttpURLConnection httpURLConnection;
            List<String> list;
            String str;
            int responseCode;
            CacheImage cacheImage;
            File file;
            HttpURLConnection httpURLConnection2;
            RandomAccessFile randomAccessFile;
            boolean z2 = true;
            boolean z3 = false;
            if (!isCancelled()) {
                try {
                    String str2 = this.cacheImage.imageLocation.path;
                    if ((str2.startsWith("https://static-maps") || str2.startsWith("https://maps.googleapis")) && (((i = MessagesController.getInstance(this.cacheImage.currentAccount).mapProvider) == 3 || i == 4) && (webFile = (WebFile) ImageLoader.this.testWebFile.get(str2)) != null)) {
                        TLRPC$TL_upload_getWebFile tLRPC$TL_upload_getWebFile = new TLRPC$TL_upload_getWebFile();
                        tLRPC$TL_upload_getWebFile.location = webFile.location;
                        tLRPC$TL_upload_getWebFile.offset = 0;
                        tLRPC$TL_upload_getWebFile.limit = 0;
                        ConnectionsManager.getInstance(this.cacheImage.currentAccount).sendRequest(tLRPC$TL_upload_getWebFile, new RequestDelegate() {
                            @Override
                            public final void run(TLObject tLObject, TLRPC$TL_error tLRPC$TL_error) {
                                ImageLoader.HttpImageTask.lambda$doInBackground$2(tLObject, tLRPC$TL_error);
                            }
                        });
                    }
                    String str3 = this.overrideUrl;
                    if (str3 != null) {
                        str2 = str3;
                    }
                    HttpURLConnection httpURLConnection3 = (HttpURLConnection) new URL(str2).openConnection();
                    this.httpConnection = httpURLConnection3;
                    httpURLConnection3.addRequestProperty("User-Agent", "Mozilla/5.0 (iPhone; CPU iPhone OS 10_0 like Mac OS X) AppleWebKit/602.1.38 (KHTML, like Gecko) Version/10.0 Mobile/14A5297c Safari/602.1");
                    this.httpConnection.setConnectTimeout(5000);
                    this.httpConnection.setReadTimeout(5000);
                    this.httpConnection.setInstanceFollowRedirects(true);
                } catch (Throwable th) {
                    th = th;
                    inputStream = null;
                }
                if (!isCancelled()) {
                    this.httpConnection.connect();
                    inputStream2 = this.httpConnection.getInputStream();
                    try {
                        this.fileOutputStream = new RandomAccessFile(this.cacheImage.tempFilePath, "rws");
                    } catch (Throwable th2) {
                        inputStream = inputStream2;
                        th = th2;
                        if (th instanceof SocketTimeoutException) {
                            if (ApplicationLoader.isNetworkOnline()) {
                                this.canRetry = false;
                            }
                        } else if (th instanceof UnknownHostException) {
                            this.canRetry = false;
                        } else if (th instanceof SocketException) {
                            if (th.getMessage() != null && th.getMessage().contains("ECONNRESET")) {
                                this.canRetry = false;
                            }
                        } else if (th instanceof FileNotFoundException) {
                            this.canRetry = false;
                        } else if (!(th instanceof InterruptedIOException)) {
                            z = true;
                            FileLog.e(th, z);
                            inputStream2 = inputStream;
                            if (!isCancelled()) {
                            }
                            randomAccessFile = this.fileOutputStream;
                            if (randomAccessFile != null) {
                            }
                            httpURLConnection2 = this.httpConnection;
                            if (httpURLConnection2 != null) {
                            }
                            if (inputStream2 != null) {
                            }
                            if (z3) {
                            }
                            return Boolean.valueOf(z3);
                        }
                        z = false;
                        FileLog.e(th, z);
                        inputStream2 = inputStream;
                        if (!isCancelled()) {
                        }
                        randomAccessFile = this.fileOutputStream;
                        if (randomAccessFile != null) {
                        }
                        httpURLConnection2 = this.httpConnection;
                        if (httpURLConnection2 != null) {
                        }
                        if (inputStream2 != null) {
                        }
                        if (z3) {
                        }
                        return Boolean.valueOf(z3);
                    }
                    if (!isCancelled()) {
                        try {
                            HttpURLConnection httpURLConnection4 = this.httpConnection;
                            if (httpURLConnection4 != null && (responseCode = httpURLConnection4.getResponseCode()) != 200 && responseCode != 202 && responseCode != 304) {
                                this.canRetry = false;
                            }
                        } catch (Exception e) {
                            FileLog.e((Throwable) e, false);
                        }
                        if (this.imageSize == 0 && (httpURLConnection = this.httpConnection) != null) {
                            try {
                                Map<String, List<String>> headerFields = httpURLConnection.getHeaderFields();
                                if (headerFields != null && (list = headerFields.get("content-Length")) != null && !list.isEmpty() && (str = list.get(0)) != null) {
                                    this.imageSize = Utilities.parseInt((CharSequence) str).intValue();
                                }
                            } catch (Exception e2) {
                                FileLog.e(e2);
                            }
                        }
                        if (inputStream2 != null) {
                            try {
                                byte[] bArr = new byte[LiteMode.FLAG_ANIMATED_EMOJI_REACTIONS_NOT_PREMIUM];
                                int i2 = 0;
                                while (true) {
                                    if (isCancelled()) {
                                        break;
                                    }
                                    try {
                                        int read = inputStream2.read(bArr);
                                        if (read <= 0) {
                                            break;
                                        }
                                        i2 += read;
                                        this.fileOutputStream.write(bArr, 0, read);
                                        long j = this.imageSize;
                                        if (j != 0) {
                                            reportProgress(i2, j);
                                        }
                                    } catch (Exception e3) {
                                        e = e3;
                                    }
                                }
                                z2 = z3;
                                z3 = z2;
                            } catch (Throwable th3) {
                                th = th3;
                            }
                        }
                    }
                    randomAccessFile = this.fileOutputStream;
                    if (randomAccessFile != null) {
                        randomAccessFile.close();
                        this.fileOutputStream = null;
                    }
                    httpURLConnection2 = this.httpConnection;
                    if (httpURLConnection2 != null) {
                        httpURLConnection2.disconnect();
                    }
                    if (inputStream2 != null) {
                        try {
                            inputStream2.close();
                        } catch (Throwable th4) {
                            FileLog.e(th4);
                        }
                    }
                    if (z3 && (file = (cacheImage = this.cacheImage).tempFilePath) != null && !file.renameTo(cacheImage.finalFilePath)) {
                        CacheImage cacheImage2 = this.cacheImage;
                        cacheImage2.finalFilePath = cacheImage2.tempFilePath;
                    }
                    return Boolean.valueOf(z3);
                }
            }
            inputStream2 = null;
            if (!isCancelled()) {
            }
            randomAccessFile = this.fileOutputStream;
            if (randomAccessFile != null) {
            }
            httpURLConnection2 = this.httpConnection;
            if (httpURLConnection2 != null) {
            }
            if (inputStream2 != null) {
            }
            if (z3) {
                CacheImage cacheImage22 = this.cacheImage;
                cacheImage22.finalFilePath = cacheImage22.tempFilePath;
            }
            return Boolean.valueOf(z3);
        }

        @Override
        public void onPostExecute(final Boolean bool) {
            if (!bool.booleanValue() && this.canRetry) {
                ImageLoader.this.httpFileLoadError(this.cacheImage.url);
            } else {
                ImageLoader imageLoader = ImageLoader.this;
                CacheImage cacheImage = this.cacheImage;
                imageLoader.fileDidLoaded(cacheImage.url, cacheImage.finalFilePath, 0);
            }
            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 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$3(Boolean bool) {
            if (bool.booleanValue()) {
                NotificationCenter notificationCenter = NotificationCenter.getInstance(this.cacheImage.currentAccount);
                int i = NotificationCenter.fileLoaded;
                CacheImage cacheImage = this.cacheImage;
                notificationCenter.lambda$postNotificationNameOnUIThread$1(i, cacheImage.url, cacheImage.finalFilePath);
                return;
            }
            NotificationCenter.getInstance(this.cacheImage.currentAccount).lambda$postNotificationNameOnUIThread$1(NotificationCenter.fileLoadFailed, this.cacheImage.url, 2);
        }

        public void lambda$onPostExecute$5() {
            ImageLoader.this.runHttpTasks(true);
        }

        public void lambda$onCancelled$6() {
            ImageLoader.this.runHttpTasks(true);
        }

        @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();
                }
            });
        }

        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$onCancelled$7() {
            NotificationCenter.getInstance(this.cacheImage.currentAccount).lambda$postNotificationNameOnUIThread$1(NotificationCenter.fileLoadFailed, this.cacheImage.url, 1);
        }
    }

    public 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;
        }

        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);
                }
            });
        }

        public void lambda$removeTask$0(String str) {
            ImageLoader.this.thumbGenerateTasks.remove(str);
        }

        @Override
        public void run() {
            int min;
            Bitmap createScaledBitmap;
            try {
                if (this.info == null) {
                    removeTask();
                    return;
                }
                final String str = "q_" + this.info.parentDocument.dc_id + "_" + this.info.parentDocument.id;
                File file = new File(FileLoader.getDirectory(4), str + ".jpg");
                if (!file.exists() && this.originalPath.exists()) {
                    if (this.info.big) {
                        Point point = AndroidUtilities.displaySize;
                        min = Math.max(point.x, point.y);
                    } else {
                        Point point2 = AndroidUtilities.displaySize;
                        min = Math.min(180, Math.min(point2.x, point2.y) / 4);
                    }
                    int i = this.mediaType;
                    Bitmap bitmap = null;
                    if (i == 0) {
                        float f = min;
                        bitmap = ImageLoader.loadBitmap(this.originalPath.toString(), null, f, f, false);
                    } else {
                        int i2 = 2;
                        if (i == 2) {
                            String file2 = this.originalPath.toString();
                            if (!this.info.big) {
                                i2 = 1;
                            }
                            bitmap = SendMessagesHelper.createVideoThumbnail(file2, i2);
                        } else if (i == 3) {
                            String lowerCase = this.originalPath.toString().toLowerCase();
                            if (lowerCase.endsWith("mp4")) {
                                String file3 = this.originalPath.toString();
                                if (!this.info.big) {
                                    i2 = 1;
                                }
                                bitmap = SendMessagesHelper.createVideoThumbnail(file3, i2);
                            } else if (lowerCase.endsWith(".jpg") || lowerCase.endsWith(".jpeg") || lowerCase.endsWith(".png") || lowerCase.endsWith(".gif")) {
                                float f2 = min;
                                bitmap = ImageLoader.loadBitmap(lowerCase, null, f2, f2, false);
                            }
                        }
                    }
                    if (bitmap == null) {
                        removeTask();
                        return;
                    }
                    int width = bitmap.getWidth();
                    int height = bitmap.getHeight();
                    if (width != 0 && height != 0) {
                        float f3 = width;
                        float f4 = min;
                        float f5 = height;
                        float min2 = Math.min(f3 / f4, f5 / f4);
                        if (min2 > 1.0f && (createScaledBitmap = Bitmaps.createScaledBitmap(bitmap, (int) (f3 / min2), (int) (f5 / min2), true)) != bitmap) {
                            bitmap.recycle();
                            bitmap = createScaledBitmap;
                        }
                        FileOutputStream fileOutputStream = new FileOutputStream(file);
                        bitmap.compress(Bitmap.CompressFormat.JPEG, this.info.big ? 83 : 60, fileOutputStream);
                        try {
                            fileOutputStream.close();
                        } catch (Exception e) {
                            FileLog.e(e);
                        }
                        final BitmapDrawable bitmapDrawable = new BitmapDrawable(bitmap);
                        final ArrayList arrayList = new ArrayList(this.info.imageReceiverArray);
                        final ArrayList arrayList2 = new ArrayList(this.info.imageReceiverGuidsArray);
                        AndroidUtilities.runOnUIThread(new Runnable() {
                            @Override
                            public final void run() {
                                ImageLoader.ThumbGenerateTask.this.lambda$run$1(str, arrayList, bitmapDrawable, arrayList2);
                            }
                        });
                        return;
                    }
                    removeTask();
                    return;
                }
                removeTask();
            } catch (Throwable th) {
                FileLog.e(th);
                removeTask();
            }
        }

        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);
        }
    }

    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) {
                            sb.append(readLine);
                        } else {
                            String sb2 = sb.toString();
                            bufferedReader.close();
                            gZIPInputStream.close();
                            return sb2;
                        }
                    } finally {
                    }
                }
            } finally {
            }
        } catch (Exception unused) {
            return "";
        }
    }

    public 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;
        }

        @Override
        public void run() {
            ThemePreviewDrawable themePreviewDrawable;
            boolean z;
            boolean z2;
            Bitmap bitmap;
            Object obj;
            CacheImage cacheImage;
            SecureDocumentKey secureDocumentKey;
            byte[] bArr;
            Throwable th;
            RandomAccessFile randomAccessFile;
            RandomAccessFile randomAccessFile2;
            String lowerCase;
            boolean z3;
            String str;
            boolean z4;
            String str2;
            Long l;
            boolean z5;
            boolean z6;
            boolean z7;
            float f;
            Bitmap bitmap2;
            float f2;
            boolean z8;
            boolean z9;
            int i;
            float f3;
            ?? r15;
            boolean z10;
            boolean z11;
            int i2;
            int i3;
            byte[] bArr2;
            boolean z12;
            int i4;
            FileInputStream fileInputStream;
            Bitmap createScaledBitmap;
            CacheImage cacheImage2;
            String str3;
            Object obj2;
            Bitmap bitmap3;
            float f4;
            float f5;
            boolean z13;
            int i5;
            int i6;
            boolean z14;
            int i7;
            FileInputStream fileInputStream2;
            String str4;
            boolean z15;
            Bitmap createScaledBitmap2;
            Bitmap thumbnail;
            String str5;
            ?? r8;
            boolean z16;
            boolean z17;
            FileInputStream fileInputStream3;
            boolean z18;
            float min;
            Long l2;
            boolean z19;
            String str6;
            boolean z20;
            boolean z21;
            boolean z22;
            boolean z23;
            boolean z24;
            Bitmap bitmap4;
            MediaMetadataRetriever mediaMetadataRetriever;
            BitmapsCache.CacheOptions cacheOptions;
            AnimatedFileDrawable animatedFileDrawable;
            int i8;
            int i9;
            String str7;
            int i10;
            int i11;
            int i12;
            int i13;
            int i14;
            boolean z25;
            boolean z26;
            boolean z27;
            String str8;
            boolean z28;
            boolean z29;
            Throwable th2;
            ?? r4;
            boolean z30;
            RandomAccessFile randomAccessFile3;
            boolean z31;
            BitmapsCache.CacheOptions cacheOptions2;
            RLottieDrawable rLottieDrawable;
            RLottieDrawable rLottieDrawable2;
            byte[] bArr3;
            RLottieDrawable rLottieDrawable3;
            boolean z32;
            boolean z33;
            int i15;
            synchronized (this.sync) {
                this.runningThread = Thread.currentThread();
                Thread.interrupted();
                if (this.isCancelled) {
                    return;
                }
                CacheImage cacheImage3 = this.cacheImage;
                ImageLocation imageLocation = cacheImage3.imageLocation;
                TLRPC$PhotoSize tLRPC$PhotoSize = imageLocation.photoSize;
                if (tLRPC$PhotoSize instanceof TLRPC$TL_photoStrippedSize) {
                    Bitmap strippedPhotoBitmap = ImageLoader.getStrippedPhotoBitmap(((TLRPC$TL_photoStrippedSize) tLRPC$PhotoSize).bytes, "b");
                    onPostExecute(strippedPhotoBitmap != null ? new BitmapDrawable(strippedPhotoBitmap) : null);
                    return;
                }
                int i16 = cacheImage3.imageType;
                if (i16 == 5) {
                    try {
                        CacheImage cacheImage4 = this.cacheImage;
                        themePreviewDrawable = new ThemePreviewDrawable(cacheImage4.finalFilePath, (DocumentObject.ThemeDocument) cacheImage4.imageLocation.document);
                    } catch (Throwable th3) {
                        FileLog.e(th3);
                        themePreviewDrawable = null;
                    }
                    onPostExecute(themePreviewDrawable);
                    return;
                }
                boolean z34 = true;
                if (i16 == 3 || i16 == 4) {
                    Point point = AndroidUtilities.displaySize;
                    int i17 = point.x;
                    int i18 = point.y;
                    String str9 = cacheImage3.filter;
                    if (str9 != null) {
                        String[] split = str9.split("_");
                        if (split.length >= 2) {
                            z = false;
                            float parseFloat = Float.parseFloat(split[0]);
                            z2 = true;
                            float parseFloat2 = Float.parseFloat(split[1]);
                            float f6 = AndroidUtilities.density;
                            int i19 = (int) (parseFloat2 * f6);
                            i17 = (int) (parseFloat * f6);
                            i18 = i19;
                            cacheImage = this.cacheImage;
                            File file = cacheImage.finalFilePath;
                            if (cacheImage.imageType == 4) {
                                z = z2;
                            }
                            bitmap = SvgHelper.getBitmap(file, i17, i18, z);
                            if (bitmap != null && !TextUtils.isEmpty(this.cacheImage.filter) && this.cacheImage.filter.contains("wallpaper")) {
                                obj = this.cacheImage.parentObject;
                                if (obj instanceof TLRPC$WallPaper) {
                                    bitmap = applyWallpaperSetting(bitmap, (TLRPC$WallPaper) obj);
                                }
                            }
                            onPostExecute(bitmap == null ? new BitmapDrawable(bitmap) : null);
                            return;
                        }
                    }
                    z = false;
                    z2 = true;
                    cacheImage = this.cacheImage;
                    File file2 = cacheImage.finalFilePath;
                    if (cacheImage.imageType == 4) {
                    }
                    bitmap = SvgHelper.getBitmap(file2, i17, i18, z);
                    if (bitmap != null) {
                        obj = this.cacheImage.parentObject;
                        if (obj instanceof TLRPC$WallPaper) {
                        }
                    }
                    onPostExecute(bitmap == null ? new BitmapDrawable(bitmap) : null);
                    return;
                }
                if (i16 == 1) {
                    int min2 = Math.min(512, AndroidUtilities.dp(170.6f));
                    int min3 = Math.min(512, AndroidUtilities.dp(170.6f));
                    String str10 = this.cacheImage.filter;
                    if (str10 != null) {
                        String[] split2 = str10.split("_");
                        if (split2.length >= 2) {
                            float parseFloat3 = Float.parseFloat(split2[0]);
                            float parseFloat4 = Float.parseFloat(split2[1]);
                            int min4 = Math.min(512, (int) (AndroidUtilities.density * parseFloat3));
                            int min5 = Math.min(512, (int) (AndroidUtilities.density * parseFloat4));
                            if (parseFloat3 > 90.0f || parseFloat4 > 90.0f || this.cacheImage.filter.contains("nolimit")) {
                                min3 = min5;
                                z25 = false;
                                min2 = min4;
                            } else {
                                min2 = Math.min(min4, 160);
                                min3 = Math.min(min5, 160);
                                z25 = true;
                            }
                            z29 = (split2.length >= 3 && "pcache".equals(split2[2])) || this.cacheImage.filter.contains("pcache") || !(this.cacheImage.filter.contains("nolimit") || SharedConfig.getDevicePerformanceClass() == 2);
                            z33 = this.cacheImage.filter.contains("lastframe");
                            z32 = this.cacheImage.filter.contains("lastreactframe");
                            if (z32) {
                                z33 = true;
                            }
                            z28 = this.cacheImage.filter.contains("firstframe");
                        } else {
                            z25 = false;
                            z32 = false;
                            z28 = false;
                            z29 = false;
                            z33 = false;
                        }
                        if (split2.length >= 3) {
                            if ("nr".equals(split2[2])) {
                                i13 = 2;
                            } else if ("nrs".equals(split2[2])) {
                                i13 = 3;
                            } else if ("dice".equals(split2[2])) {
                                str8 = split2[3];
                                i13 = 2;
                                if (split2.length >= 5) {
                                    if (!"c1".equals(split2[4])) {
                                        if ("c2".equals(split2[4])) {
                                            i11 = min3;
                                            z27 = z32;
                                            z26 = z33;
                                            i12 = min2;
                                            i14 = 3;
                                        } else if ("c3".equals(split2[4])) {
                                            i11 = min3;
                                            z26 = z33;
                                            boolean z35 = z32;
                                            i12 = min2;
                                            i14 = 4;
                                            z27 = z35;
                                        } else if ("c4".equals(split2[4])) {
                                            i11 = min3;
                                            z27 = z32;
                                            z26 = z33;
                                            i12 = min2;
                                            i14 = 5;
                                        } else {
                                            i15 = "c5".equals(split2[4]) ? 6 : 12;
                                        }
                                    }
                                    z27 = z32;
                                    z26 = z33;
                                    i12 = min2;
                                    i14 = i15;
                                    i11 = min3;
                                }
                                i11 = min3;
                                z27 = z32;
                                z26 = z33;
                                i12 = min2;
                                i14 = 0;
                            }
                            str8 = null;
                            if (split2.length >= 5) {
                            }
                            i11 = min3;
                            z27 = z32;
                            z26 = z33;
                            i12 = min2;
                            i14 = 0;
                        }
                        i13 = 1;
                        str8 = null;
                        if (split2.length >= 5) {
                        }
                        i11 = min3;
                        z27 = z32;
                        z26 = z33;
                        i12 = min2;
                        i14 = 0;
                    } else {
                        i11 = min3;
                        i12 = min2;
                        i13 = 1;
                        i14 = 0;
                        z25 = false;
                        z26 = false;
                        z27 = false;
                        str8 = null;
                        z28 = false;
                        z29 = false;
                    }
                    if (str8 != null) {
                        if ("🎰".equals(str8)) {
                            rLottieDrawable3 = new SlotsDrawable(str8, i12, i11);
                        } else {
                            rLottieDrawable3 = new RLottieDrawable(str8, i12, i11);
                        }
                        rLottieDrawable2 = rLottieDrawable3;
                    } else {
                        File file3 = this.cacheImage.finalFilePath;
                        try {
                            try {
                                randomAccessFile3 = new RandomAccessFile(this.cacheImage.finalFilePath, "r");
                                try {
                                    bArr3 = this.cacheImage.type == 1 ? ImageLoader.headerThumb : ImageLoader.header;
                                    try {
                                        randomAccessFile3.readFully(bArr3, 0, 2);
                                    } catch (Exception e) {
                                        e = e;
                                        z30 = false;
                                        FileLog.e(e, z30);
                                        if (randomAccessFile3 != null) {
                                            try {
                                                randomAccessFile3.close();
                                            } catch (Exception e2) {
                                                FileLog.e(e2);
                                            }
                                        }
                                        z31 = false;
                                        if ((!z26 || z28) ? false : z29) {
                                        }
                                        cacheOptions2 = new BitmapsCache.CacheOptions();
                                        if (z26) {
                                        }
                                        cacheOptions2.firstFrame = true;
                                        if (z31) {
                                        }
                                        rLottieDrawable2 = rLottieDrawable;
                                        if (!z26) {
                                        }
                                        loadLastFrame(rLottieDrawable2, i11, i12, z26, z27);
                                        return;
                                    }
                                } catch (Exception e3) {
                                    e = e3;
                                    z30 = false;
                                }
                            } catch (Throwable th4) {
                                th2 = th4;
                                r4 = str8;
                                if (r4 == 0) {
                                    try {
                                        r4.close();
                                        throw th2;
                                    } catch (Exception e4) {
                                        FileLog.e(e4);
                                        throw th2;
                                    }
                                }
                                throw th2;
                            }
                        } catch (Exception e5) {
                            e = e5;
                            z30 = false;
                            randomAccessFile3 = null;
                        } catch (Throwable th5) {
                            th2 = th5;
                            r4 = 0;
                            if (r4 == 0) {
                            }
                        }
                        if (bArr3[0] == 31) {
                            if (bArr3[1] == -117) {
                                z31 = true;
                                randomAccessFile3.close();
                                if (!((!z26 || z28) ? false : z29) || z26 || z28) {
                                    cacheOptions2 = new BitmapsCache.CacheOptions();
                                    if (z26 && !z28) {
                                        String str11 = this.cacheImage.filter;
                                        if (str11 != null && str11.contains("compress")) {
                                            cacheOptions2.compressQuality = 60;
                                        }
                                        String str12 = this.cacheImage.filter;
                                        if (str12 != null && str12.contains("flbk")) {
                                            cacheOptions2.fallback = true;
                                        }
                                    } else {
                                        cacheOptions2.firstFrame = true;
                                    }
                                } else {
                                    cacheOptions2 = null;
                                }
                                if (z31) {
                                    File file4 = this.cacheImage.finalFilePath;
                                    rLottieDrawable = new RLottieDrawable(file4, ImageLoader.decompressGzip(file4), i12, i11, cacheOptions2, z25, null, i14);
                                } else {
                                    rLottieDrawable = new RLottieDrawable(this.cacheImage.finalFilePath, i12, i11, cacheOptions2, z25, null, i14);
                                }
                                rLottieDrawable2 = rLottieDrawable;
                            }
                        }
                        z31 = false;
                        randomAccessFile3.close();
                        if ((!z26 || z28) ? false : z29) {
                        }
                        cacheOptions2 = new BitmapsCache.CacheOptions();
                        if (z26) {
                        }
                        cacheOptions2.firstFrame = true;
                        if (z31) {
                        }
                        rLottieDrawable2 = rLottieDrawable;
                    }
                    if (!z26 || z28) {
                        loadLastFrame(rLottieDrawable2, i11, i12, z26, z27);
                        return;
                    } else {
                        rLottieDrawable2.setAutoRepeat(i13);
                        onPostExecute(rLottieDrawable2);
                        return;
                    }
                }
                if (i16 == 2) {
                    long j = imageLocation != null ? imageLocation.videoSeekTo : 0L;
                    String str13 = cacheImage3.filter;
                    if (str13 != null) {
                        String[] split3 = str13.split("_");
                        if (split3.length >= 2) {
                            float parseFloat5 = Float.parseFloat(split3[0]);
                            float parseFloat6 = Float.parseFloat(split3[1]);
                            if (parseFloat5 <= 90.0f && parseFloat6 <= 90.0f && !this.cacheImage.filter.contains("nolimit")) {
                                z20 = true;
                                z21 = false;
                                z22 = false;
                                z23 = false;
                                z24 = false;
                                for (i10 = 0; i10 < split3.length; i10++) {
                                    if ("pcache".equals(split3[i10])) {
                                        z22 = true;
                                    }
                                    if ("firstframe".equals(split3[i10])) {
                                        z21 = true;
                                    }
                                    if ("nostream".equals(split3[i10])) {
                                        z24 = true;
                                    }
                                    if ("pframe".equals(split3[i10])) {
                                        z23 = true;
                                    }
                                }
                                if (z21) {
                                    z24 = true;
                                }
                            }
                        }
                        z20 = false;
                        z21 = false;
                        z22 = false;
                        z23 = false;
                        z24 = false;
                        while (i10 < split3.length) {
                        }
                        if (z21) {
                        }
                    } else {
                        z20 = false;
                        z21 = false;
                        z22 = false;
                        z23 = false;
                        z24 = false;
                    }
                    if (!z23) {
                        if (!z22 || z21) {
                            cacheOptions = null;
                        } else {
                            BitmapsCache.CacheOptions cacheOptions3 = new BitmapsCache.CacheOptions();
                            String str14 = this.cacheImage.filter;
                            if (str14 != null && str14.contains("compress")) {
                                cacheOptions3.compressQuality = 60;
                            }
                            cacheOptions = cacheOptions3;
                        }
                        if (ImageLoader.this.isAnimatedAvatar(this.cacheImage.filter) || ImageLoader.AUTOPLAY_FILTER.equals(this.cacheImage.filter)) {
                            CacheImage cacheImage5 = this.cacheImage;
                            ImageLocation imageLocation2 = cacheImage5.imageLocation;
                            TLRPC$Document tLRPC$Document = imageLocation2.document;
                            if (!(tLRPC$Document instanceof TLRPC$TL_documentEncrypted) && !z22) {
                                if (!(tLRPC$Document instanceof TLRPC$Document)) {
                                    tLRPC$Document = null;
                                }
                                long j2 = tLRPC$Document != null ? cacheImage5.size : imageLocation2.currentSize;
                                CacheImage cacheImage6 = this.cacheImage;
                                animatedFileDrawable = new AnimatedFileDrawable(cacheImage6.finalFilePath, z21, z24 ? 0L : j2, cacheImage6.priority, z24 ? null : tLRPC$Document, (tLRPC$Document != null || z24) ? null : cacheImage6.imageLocation, cacheImage6.parentObject, j, cacheImage6.currentAccount, false, cacheOptions);
                                if (!MessageObject.isWebM(tLRPC$Document) && !MessageObject.isVideoSticker(tLRPC$Document) && !ImageLoader.this.isAnimatedAvatar(this.cacheImage.filter)) {
                                    z34 = false;
                                }
                                animatedFileDrawable.setIsWebmSticker(z34);
                                if (z21) {
                                    Bitmap frameAtTime = animatedFileDrawable.getFrameAtTime(0L, false);
                                    animatedFileDrawable.recycle();
                                    Thread.interrupted();
                                    if (frameAtTime == null) {
                                        onPostExecute(null);
                                        return;
                                    } else {
                                        onPostExecute(new BitmapDrawable(frameAtTime));
                                        return;
                                    }
                                }
                                animatedFileDrawable.setLimitFps(z20);
                                Thread.interrupted();
                                onPostExecute(animatedFileDrawable);
                                return;
                            }
                        }
                        String str15 = this.cacheImage.filter;
                        if (str15 != null) {
                            String[] split4 = str15.split("_");
                            if (split4.length >= 2) {
                                float parseFloat7 = Float.parseFloat(split4[0]);
                                float parseFloat8 = Float.parseFloat(split4[1]);
                                float f7 = AndroidUtilities.density;
                                i9 = (int) (parseFloat8 * f7);
                                i8 = (int) (parseFloat7 * f7);
                                boolean z36 = !z21 || ((str7 = this.cacheImage.filter) != null && ("d".equals(str7) || this.cacheImage.filter.contains("_d")));
                                int i20 = (!z24 ? null : this.cacheImage.imageLocation.document) == null ? 1 : 0;
                                int i21 = this.cacheImage.cacheType;
                                int i22 = i21 <= 1 ? i21 : i20;
                                CacheImage cacheImage7 = this.cacheImage;
                                animatedFileDrawable = new AnimatedFileDrawable(cacheImage7.finalFilePath, z36, 0L, cacheImage7.priority, !z24 ? null : cacheImage7.imageLocation.document, null, null, j, cacheImage7.currentAccount, false, i8, i9, cacheOptions, i22);
                                if (!MessageObject.isWebM(this.cacheImage.imageLocation.document) && !MessageObject.isVideoSticker(this.cacheImage.imageLocation.document) && !ImageLoader.this.isAnimatedAvatar(this.cacheImage.filter)) {
                                    z34 = false;
                                }
                                animatedFileDrawable.setIsWebmSticker(z34);
                                if (z21) {
                                }
                            }
                        }
                        i8 = 0;
                        i9 = 0;
                        if (z21) {
                        }
                        if ((!z24 ? null : this.cacheImage.imageLocation.document) == null) {
                        }
                        int i212 = this.cacheImage.cacheType;
                        if (i212 <= 1) {
                        }
                        CacheImage cacheImage72 = this.cacheImage;
                        animatedFileDrawable = new AnimatedFileDrawable(cacheImage72.finalFilePath, z36, 0L, cacheImage72.priority, !z24 ? null : cacheImage72.imageLocation.document, null, null, j, cacheImage72.currentAccount, false, i8, i9, cacheOptions, i22);
                        if (!MessageObject.isWebM(this.cacheImage.imageLocation.document)) {
                            z34 = false;
                        }
                        animatedFileDrawable.setIsWebmSticker(z34);
                        if (z21) {
                        }
                    } else {
                        try {
                            mediaMetadataRetriever = new MediaMetadataRetriever();
                            mediaMetadataRetriever.setDataSource(this.cacheImage.finalFilePath.getAbsolutePath());
                            bitmap4 = mediaMetadataRetriever.getFrameAtTime(2L);
                        } catch (Exception e6) {
                            e = e6;
                            bitmap4 = null;
                        }
                        try {
                            mediaMetadataRetriever.release();
                        } catch (Exception e7) {
                            e = e7;
                            e.printStackTrace();
                            Thread.interrupted();
                            if (bitmap4 != null) {
                            }
                        }
                        Thread.interrupted();
                        if (bitmap4 != null) {
                            onPostExecute(null);
                        } else {
                            onPostExecute(new BitmapDrawable(bitmap4));
                        }
                    }
                } else {
                    File file5 = cacheImage3.finalFilePath;
                    boolean z37 = (cacheImage3.secureDocument == null && (cacheImage3.encryptionKeyPath == null || file5 == null || !file5.getAbsolutePath().endsWith(".enc"))) ? false : true;
                    SecureDocument secureDocument = this.cacheImage.secureDocument;
                    if (secureDocument != null) {
                        secureDocumentKey = secureDocument.secureDocumentKey;
                        TLRPC$TL_secureFile tLRPC$TL_secureFile = secureDocument.secureFile;
                        if (tLRPC$TL_secureFile == null || (bArr = tLRPC$TL_secureFile.file_hash) == null) {
                            bArr = secureDocument.fileHash;
                        }
                    } else {
                        secureDocumentKey = null;
                        bArr = null;
                    }
                    try {
                        if (Build.VERSION.SDK_INT < 19) {
                            try {
                                randomAccessFile2 = new RandomAccessFile(file5, "r");
                                try {
                                    byte[] bArr4 = this.cacheImage.type == 1 ? ImageLoader.headerThumb : ImageLoader.header;
                                    randomAccessFile2.readFully(bArr4, 0, bArr4.length);
                                    lowerCase = new String(bArr4).toLowerCase().toLowerCase();
                                } catch (Exception e8) {
                                    e = e8;
                                    FileLog.e(e);
                                    if (randomAccessFile2 != null) {
                                        try {
                                            randomAccessFile2.close();
                                        } catch (Exception e9) {
                                            FileLog.e(e9);
                                        }
                                    }
                                    z3 = false;
                                    str = this.cacheImage.imageLocation.path;
                                    if (str != null) {
                                    }
                                    z4 = true;
                                    str2 = null;
                                    l = null;
                                    z5 = false;
                                    BitmapFactory.Options options = new BitmapFactory.Options();
                                    options.inSampleSize = 1;
                                    if (Build.VERSION.SDK_INT < 21) {
                                    }
                                    boolean z38 = ImageLoader.this.canForce8888;
                                    str5 = this.cacheImage.filter;
                                    if (str5 == null) {
                                    }
                                    f3 = f2;
                                    r15 = z8;
                                    z10 = z9;
                                    i = 1;
                                    if (this.cacheImage.type == i) {
                                    }
                                    Thread.interrupted();
                                    if (BuildVars.LOGS_ENABLED) {
                                    }
                                    if (bitmap2 != null) {
                                    }
                                    cacheImage2 = this.cacheImage;
                                    if (cacheImage2 != null) {
                                    }
                                    onPostExecute(bitmap2 == null ? new ExtendedBitmapDrawable(bitmap2, i3, i2) : bArr2);
                                }
                            } catch (Exception e10) {
                                e = e10;
                                randomAccessFile2 = null;
                            } catch (Throwable th6) {
                                th = th6;
                                randomAccessFile = null;
                                if (randomAccessFile != null) {
                                    try {
                                        randomAccessFile.close();
                                        throw th;
                                    } catch (Exception e11) {
                                        FileLog.e(e11);
                                        throw th;
                                    }
                                }
                                throw th;
                            }
                            if (lowerCase.startsWith("riff")) {
                                if (lowerCase.endsWith("webp")) {
                                    z3 = true;
                                    randomAccessFile2.close();
                                    str = this.cacheImage.imageLocation.path;
                                    if (str != null) {
                                        if (str.startsWith("thumb://")) {
                                            int indexOf = str.indexOf(":", 8);
                                            if (indexOf >= 0) {
                                                l = Long.valueOf(Long.parseLong(str.substring(8, indexOf)));
                                                str6 = str.substring(indexOf + 1);
                                            } else {
                                                str6 = null;
                                                l = null;
                                            }
                                            str2 = str6;
                                        } else {
                                            if (str.startsWith("vthumb://")) {
                                                int indexOf2 = str.indexOf(":", 9);
                                                if (indexOf2 >= 0) {
                                                    l2 = Long.valueOf(Long.parseLong(str.substring(9, indexOf2)));
                                                    z19 = true;
                                                } else {
                                                    l2 = null;
                                                    z19 = false;
                                                }
                                                l = l2;
                                                z5 = z19;
                                                str2 = null;
                                                z4 = false;
                                                BitmapFactory.Options options2 = new BitmapFactory.Options();
                                                options2.inSampleSize = 1;
                                                if (Build.VERSION.SDK_INT < 21) {
                                                    options2.inPurgeable = true;
                                                }
                                                boolean z382 = ImageLoader.this.canForce8888;
                                                str5 = this.cacheImage.filter;
                                                if (str5 == null) {
                                                    String[] split5 = str5.split("_");
                                                    if (split5.length >= 2) {
                                                        float parseFloat9 = Float.parseFloat(split5[0]) * AndroidUtilities.density;
                                                        try {
                                                            f2 = parseFloat9;
                                                            f = Float.parseFloat(split5[1]) * AndroidUtilities.density;
                                                        } catch (Throwable th7) {
                                                            th = th7;
                                                            f2 = parseFloat9;
                                                            z6 = z5;
                                                            z7 = z4;
                                                            f = 0.0f;
                                                            bitmap2 = null;
                                                            z8 = false;
                                                            z9 = false;
                                                            i = 1;
                                                            FileLog.e(th, !(th instanceof FileNotFoundException));
                                                            f3 = f2;
                                                            r15 = z8;
                                                            z10 = z9;
                                                            if (this.cacheImage.type == i) {
                                                            }
                                                            Thread.interrupted();
                                                            if (BuildVars.LOGS_ENABLED) {
                                                            }
                                                            if (bitmap2 != null) {
                                                            }
                                                            cacheImage2 = this.cacheImage;
                                                            if (cacheImage2 != null) {
                                                            }
                                                            onPostExecute(bitmap2 == null ? new ExtendedBitmapDrawable(bitmap2, i3, i2) : bArr2);
                                                        }
                                                    } else {
                                                        f = 0.0f;
                                                        f2 = 0.0f;
                                                    }
                                                    try {
                                                        if (this.cacheImage.filter.contains("b2r")) {
                                                            r8 = 4;
                                                        } else if (this.cacheImage.filter.contains("b2")) {
                                                            r8 = 3;
                                                        } else if (this.cacheImage.filter.contains("b1")) {
                                                            r8 = 2;
                                                        } else {
                                                            r8 = this.cacheImage.filter.contains("b") ? 1 : 0;
                                                        }
                                                        try {
                                                            boolean contains = this.cacheImage.filter.contains("i");
                                                            try {
                                                                z8 = r8;
                                                                try {
                                                                    if (this.cacheImage.filter.contains("f")) {
                                                                        z382 = true;
                                                                    } else if (this.cacheImage.filter.contains("F")) {
                                                                        z382 = false;
                                                                    }
                                                                    if (z3 || f2 == 0.0f || f == 0.0f) {
                                                                        z16 = z382;
                                                                        z9 = contains;
                                                                        z6 = z5;
                                                                        z7 = z4;
                                                                    } else {
                                                                        try {
                                                                            options2.inJustDecodeBounds = true;
                                                                        } catch (Throwable th8) {
                                                                            th = th8;
                                                                            z9 = contains;
                                                                            z6 = z5;
                                                                            z7 = z4;
                                                                            bitmap2 = null;
                                                                            i = 1;
                                                                            FileLog.e(th, !(th instanceof FileNotFoundException));
                                                                            f3 = f2;
                                                                            r15 = z8;
                                                                            z10 = z9;
                                                                            if (this.cacheImage.type == i) {
                                                                            }
                                                                            Thread.interrupted();
                                                                            if (BuildVars.LOGS_ENABLED) {
                                                                            }
                                                                            if (bitmap2 != null) {
                                                                            }
                                                                            cacheImage2 = this.cacheImage;
                                                                            if (cacheImage2 != null) {
                                                                            }
                                                                            onPostExecute(bitmap2 == null ? new ExtendedBitmapDrawable(bitmap2, i3, i2) : bArr2);
                                                                        }
                                                                        try {
                                                                            try {
                                                                                if (l == null || str2 != null) {
                                                                                    z16 = z382;
                                                                                    z9 = contains;
                                                                                    if (secureDocumentKey != null) {
                                                                                        RandomAccessFile randomAccessFile4 = new RandomAccessFile(file5, "r");
                                                                                        int length = (int) randomAccessFile4.length();
                                                                                        byte[] bArr5 = (byte[]) ImageLoader.bytesLocal.get();
                                                                                        if (bArr5 == null || bArr5.length < length) {
                                                                                            bArr5 = null;
                                                                                        }
                                                                                        if (bArr5 == null) {
                                                                                            bArr5 = new byte[length];
                                                                                            ImageLoader.bytesLocal.set(bArr5);
                                                                                        }
                                                                                        randomAccessFile4.readFully(bArr5, 0, length);
                                                                                        randomAccessFile4.close();
                                                                                        EncryptedFileInputStream.decryptBytesWithKeyFile(bArr5, 0, length, secureDocumentKey);
                                                                                        z6 = z5;
                                                                                        z7 = z4;
                                                                                        byte[] computeSHA256 = Utilities.computeSHA256(bArr5, 0, length);
                                                                                        if (bArr != null && Arrays.equals(computeSHA256, bArr)) {
                                                                                            z18 = false;
                                                                                            int i23 = bArr5[0] & 255;
                                                                                            int i24 = length - i23;
                                                                                            if (!z18) {
                                                                                                BitmapFactory.decodeByteArray(bArr5, i23, i24, options2);
                                                                                            }
                                                                                        }
                                                                                        z18 = true;
                                                                                        int i232 = bArr5[0] & 255;
                                                                                        int i242 = length - i232;
                                                                                        if (!z18) {
                                                                                        }
                                                                                    } else {
                                                                                        z6 = z5;
                                                                                        z7 = z4;
                                                                                        if (z37) {
                                                                                            fileInputStream3 = new EncryptedFileInputStream(file5, this.cacheImage.encryptionKeyPath);
                                                                                        } else {
                                                                                            fileInputStream3 = new FileInputStream(file5);
                                                                                        }
                                                                                        BitmapFactory.decodeStream(fileInputStream3, null, options2);
                                                                                        fileInputStream3.close();
                                                                                    }
                                                                                } else {
                                                                                    if (z5) {
                                                                                        z9 = contains;
                                                                                        try {
                                                                                            z16 = z382;
                                                                                            MediaStore.Video.Thumbnails.getThumbnail(ApplicationLoader.applicationContext.getContentResolver(), l.longValue(), 1, options2);
                                                                                        } catch (Throwable th9) {
                                                                                            th = th9;
                                                                                            z6 = z5;
                                                                                            z7 = z4;
                                                                                            bitmap2 = null;
                                                                                            i = 1;
                                                                                            FileLog.e(th, !(th instanceof FileNotFoundException));
                                                                                            f3 = f2;
                                                                                            r15 = z8;
                                                                                            z10 = z9;
                                                                                            if (this.cacheImage.type == i) {
                                                                                            }
                                                                                            Thread.interrupted();
                                                                                            if (BuildVars.LOGS_ENABLED) {
                                                                                            }
                                                                                            if (bitmap2 != null) {
                                                                                            }
                                                                                            cacheImage2 = this.cacheImage;
                                                                                            if (cacheImage2 != null) {
                                                                                            }
                                                                                            onPostExecute(bitmap2 == null ? new ExtendedBitmapDrawable(bitmap2, i3, i2) : bArr2);
                                                                                        }
                                                                                    } else {
                                                                                        z16 = z382;
                                                                                        z9 = contains;
                                                                                        MediaStore.Images.Thumbnails.getThumbnail(ApplicationLoader.applicationContext.getContentResolver(), l.longValue(), 1, options2);
                                                                                    }
                                                                                    z6 = z5;
                                                                                    z7 = z4;
                                                                                }
                                                                                float f8 = options2.outWidth;
                                                                                float f9 = options2.outHeight;
                                                                                if (f2 >= f && f8 > f9) {
                                                                                    min = Math.max(f8 / f2, f9 / f);
                                                                                } else {
                                                                                    min = Math.min(f8 / f2, f9 / f);
                                                                                }
                                                                                if (min < 1.2f) {
                                                                                    min = 1.0f;
                                                                                }
                                                                                options2.inJustDecodeBounds = false;
                                                                                if (min > 1.0f && (f8 > f2 || f9 > f)) {
                                                                                    int i25 = 1;
                                                                                    do {
                                                                                        i25 *= 2;
                                                                                    } while (i25 * 2 < min);
                                                                                    options2.inSampleSize = i25;
                                                                                } else {
                                                                                    options2.inSampleSize = (int) min;
                                                                                }
                                                                            } catch (Throwable th10) {
                                                                                th = th10;
                                                                                z382 = z17;
                                                                                bitmap2 = null;
                                                                                i = 1;
                                                                                FileLog.e(th, !(th instanceof FileNotFoundException));
                                                                                f3 = f2;
                                                                                r15 = z8;
                                                                                z10 = z9;
                                                                                if (this.cacheImage.type == i) {
                                                                                }
                                                                                Thread.interrupted();
                                                                                if (BuildVars.LOGS_ENABLED) {
                                                                                }
                                                                                if (bitmap2 != null) {
                                                                                }
                                                                                cacheImage2 = this.cacheImage;
                                                                                if (cacheImage2 != null) {
                                                                                }
                                                                                onPostExecute(bitmap2 == null ? new ExtendedBitmapDrawable(bitmap2, i3, i2) : bArr2);
                                                                            }
                                                                        } catch (Throwable th11) {
                                                                            th = th11;
                                                                            z6 = z5;
                                                                            z7 = z4;
                                                                            z382 = z17;
                                                                            bitmap2 = null;
                                                                            i = 1;
                                                                            FileLog.e(th, !(th instanceof FileNotFoundException));
                                                                            f3 = f2;
                                                                            r15 = z8;
                                                                            z10 = z9;
                                                                            if (this.cacheImage.type == i) {
                                                                            }
                                                                            Thread.interrupted();
                                                                            if (BuildVars.LOGS_ENABLED) {
                                                                            }
                                                                            if (bitmap2 != null) {
                                                                            }
                                                                            cacheImage2 = this.cacheImage;
                                                                            if (cacheImage2 != null) {
                                                                            }
                                                                            onPostExecute(bitmap2 == null ? new ExtendedBitmapDrawable(bitmap2, i3, i2) : bArr2);
                                                                        }
                                                                    }
                                                                    z382 = z16;
                                                                    bitmap2 = null;
                                                                } catch (Throwable th12) {
                                                                    th = th12;
                                                                }
                                                            } catch (Throwable th13) {
                                                                th = th13;
                                                                z8 = r8;
                                                            }
                                                        } catch (Throwable th14) {
                                                            th = th14;
                                                            z8 = r8;
                                                            z6 = z5;
                                                            z7 = z4;
                                                            bitmap2 = null;
                                                            z9 = false;
                                                            i = 1;
                                                            FileLog.e(th, !(th instanceof FileNotFoundException));
                                                            f3 = f2;
                                                            r15 = z8;
                                                            z10 = z9;
                                                            if (this.cacheImage.type == i) {
                                                            }
                                                            Thread.interrupted();
                                                            if (BuildVars.LOGS_ENABLED) {
                                                            }
                                                            if (bitmap2 != null) {
                                                            }
                                                            cacheImage2 = this.cacheImage;
                                                            if (cacheImage2 != null) {
                                                            }
                                                            onPostExecute(bitmap2 == null ? new ExtendedBitmapDrawable(bitmap2, i3, i2) : bArr2);
                                                        }
                                                    } catch (Throwable th15) {
                                                        th = th15;
                                                        z6 = z5;
                                                        z7 = z4;
                                                        bitmap2 = null;
                                                        z8 = false;
                                                        z9 = false;
                                                        i = 1;
                                                        FileLog.e(th, !(th instanceof FileNotFoundException));
                                                        f3 = f2;
                                                        r15 = z8;
                                                        z10 = z9;
                                                        if (this.cacheImage.type == i) {
                                                        }
                                                        Thread.interrupted();
                                                        if (BuildVars.LOGS_ENABLED) {
                                                        }
                                                        if (bitmap2 != null) {
                                                        }
                                                        cacheImage2 = this.cacheImage;
                                                        if (cacheImage2 != null) {
                                                        }
                                                        onPostExecute(bitmap2 == null ? new ExtendedBitmapDrawable(bitmap2, i3, i2) : bArr2);
                                                    }
                                                } else {
                                                    z6 = z5;
                                                    z7 = z4;
                                                    if (str2 != null) {
                                                        try {
                                                            options2.inJustDecodeBounds = true;
                                                            options2.inPreferredConfig = z382 ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565;
                                                            FileInputStream fileInputStream4 = new FileInputStream(file5);
                                                            bitmap2 = BitmapFactory.decodeStream(fileInputStream4, null, options2);
                                                            try {
                                                                fileInputStream4.close();
                                                                int i26 = options2.outWidth;
                                                                int i27 = options2.outHeight;
                                                                options2.inJustDecodeBounds = false;
                                                                float min6 = (Math.min(i27, i26) / Math.max(66, Math.min(AndroidUtilities.getRealScreenSize().x, AndroidUtilities.getRealScreenSize().y))) * 6.0f;
                                                                if (min6 < 1.0f) {
                                                                    min6 = 1.0f;
                                                                }
                                                                if (min6 > 1.0f) {
                                                                    int i28 = 1;
                                                                    do {
                                                                        i28 *= 2;
                                                                    } while (i28 * 2 <= min6);
                                                                    options2.inSampleSize = i28;
                                                                } else {
                                                                    options2.inSampleSize = (int) min6;
                                                                }
                                                                f = 0.0f;
                                                            } catch (Throwable th16) {
                                                                th = th16;
                                                                f = 0.0f;
                                                                f2 = 0.0f;
                                                                z8 = false;
                                                                z9 = false;
                                                                i = 1;
                                                                FileLog.e(th, !(th instanceof FileNotFoundException));
                                                                f3 = f2;
                                                                r15 = z8;
                                                                z10 = z9;
                                                                if (this.cacheImage.type == i) {
                                                                }
                                                                Thread.interrupted();
                                                                if (BuildVars.LOGS_ENABLED) {
                                                                }
                                                                if (bitmap2 != null) {
                                                                }
                                                                cacheImage2 = this.cacheImage;
                                                                if (cacheImage2 != null) {
                                                                }
                                                                onPostExecute(bitmap2 == null ? new ExtendedBitmapDrawable(bitmap2, i3, i2) : bArr2);
                                                            }
                                                        } catch (Throwable th17) {
                                                            th = th17;
                                                            f = 0.0f;
                                                            bitmap2 = null;
                                                            f2 = 0.0f;
                                                            z8 = false;
                                                            z9 = false;
                                                            i = 1;
                                                            FileLog.e(th, !(th instanceof FileNotFoundException));
                                                            f3 = f2;
                                                            r15 = z8;
                                                            z10 = z9;
                                                            if (this.cacheImage.type == i) {
                                                            }
                                                            Thread.interrupted();
                                                            if (BuildVars.LOGS_ENABLED) {
                                                            }
                                                            if (bitmap2 != null) {
                                                            }
                                                            cacheImage2 = this.cacheImage;
                                                            if (cacheImage2 != null) {
                                                            }
                                                            onPostExecute(bitmap2 == null ? new ExtendedBitmapDrawable(bitmap2, i3, i2) : bArr2);
                                                        }
                                                    } else {
                                                        f = 0.0f;
                                                        bitmap2 = null;
                                                    }
                                                    f2 = 0.0f;
                                                    z8 = false;
                                                    z9 = false;
                                                }
                                                f3 = f2;
                                                r15 = z8;
                                                z10 = z9;
                                                i = 1;
                                                if (this.cacheImage.type == i) {
                                                    try {
                                                        ImageLoader.this.lastCacheOutTime = SystemClock.elapsedRealtime();
                                                    } catch (Throwable th18) {
                                                        th = th18;
                                                        z11 = false;
                                                    }
                                                    synchronized (this.sync) {
                                                        if (this.isCancelled) {
                                                            return;
                                                        }
                                                        if (z3) {
                                                            RandomAccessFile randomAccessFile5 = new RandomAccessFile(file5, "r");
                                                            MappedByteBuffer map = randomAccessFile5.getChannel().map(FileChannel.MapMode.READ_ONLY, 0L, file5.length());
                                                            BitmapFactory.Options options3 = new BitmapFactory.Options();
                                                            options3.inJustDecodeBounds = true;
                                                            Utilities.loadWebpImage(null, map, map.limit(), options3, true);
                                                            bitmap2 = Bitmaps.createBitmap(options3.outWidth, options3.outHeight, Bitmap.Config.ARGB_8888);
                                                            Utilities.loadWebpImage(bitmap2, map, map.limit(), null, !options2.inPurgeable);
                                                            randomAccessFile5.close();
                                                        } else {
                                                            if (!options2.inPurgeable && secureDocumentKey == null) {
                                                                if (z37) {
                                                                    fileInputStream = new EncryptedFileInputStream(file5, this.cacheImage.encryptionKeyPath);
                                                                } else {
                                                                    fileInputStream = new FileInputStream(file5);
                                                                }
                                                                bitmap2 = BitmapFactory.decodeStream(fileInputStream, null, options2);
                                                                fileInputStream.close();
                                                            }
                                                            RandomAccessFile randomAccessFile6 = new RandomAccessFile(file5, "r");
                                                            int length2 = (int) randomAccessFile6.length();
                                                            byte[] bArr6 = (byte[]) ImageLoader.bytesThumbLocal.get();
                                                            if (bArr6 == null || bArr6.length < length2) {
                                                                bArr6 = null;
                                                            }
                                                            if (bArr6 == null) {
                                                                bArr6 = new byte[length2];
                                                                ImageLoader.bytesThumbLocal.set(bArr6);
                                                            }
                                                            randomAccessFile6.readFully(bArr6, 0, length2);
                                                            randomAccessFile6.close();
                                                            if (secureDocumentKey != null) {
                                                                EncryptedFileInputStream.decryptBytesWithKeyFile(bArr6, 0, length2, secureDocumentKey);
                                                                byte[] computeSHA2562 = Utilities.computeSHA256(bArr6, 0, length2);
                                                                if (bArr != null && Arrays.equals(computeSHA2562, bArr)) {
                                                                    z12 = false;
                                                                    i4 = bArr6[0] & 255;
                                                                    length2 -= i4;
                                                                }
                                                                z12 = true;
                                                                i4 = bArr6[0] & 255;
                                                                length2 -= i4;
                                                            } else {
                                                                if (z37) {
                                                                    EncryptedFileInputStream.decryptBytesWithKeyFile(bArr6, 0, length2, this.cacheImage.encryptionKeyPath);
                                                                }
                                                                z12 = false;
                                                                i4 = 0;
                                                            }
                                                            if (!z12) {
                                                                bitmap2 = BitmapFactory.decodeByteArray(bArr6, i4, length2, options2);
                                                            }
                                                        }
                                                        if (bitmap2 == null) {
                                                            if (file5.length() == 0 || this.cacheImage.filter == null) {
                                                                file5.delete();
                                                            }
                                                            z11 = false;
                                                        } else {
                                                            if (this.cacheImage.filter != null) {
                                                                float width = bitmap2.getWidth();
                                                                float height = bitmap2.getHeight();
                                                                if (!options2.inPurgeable && f3 != 0.0f && width != f3 && width > 20.0f + f3 && bitmap2 != (createScaledBitmap = Bitmaps.createScaledBitmap(bitmap2, (int) f3, (int) (height / (width / f3)), true))) {
                                                                    bitmap2.recycle();
                                                                    bitmap2 = createScaledBitmap;
                                                                }
                                                            }
                                                            z11 = z10 ? Utilities.needInvert(bitmap2, options2.inPurgeable ? 0 : 1, bitmap2.getWidth(), bitmap2.getHeight(), bitmap2.getRowBytes()) != 0 : false;
                                                            try {
                                                                if (r15 == 1) {
                                                                    if (bitmap2.getConfig() == Bitmap.Config.ARGB_8888) {
                                                                        Utilities.blurBitmap(bitmap2, 3, options2.inPurgeable ? 0 : 1, bitmap2.getWidth(), bitmap2.getHeight(), bitmap2.getRowBytes());
                                                                    }
                                                                } else if (r15 == 2) {
                                                                    if (bitmap2.getConfig() == Bitmap.Config.ARGB_8888) {
                                                                        Utilities.blurBitmap(bitmap2, 1, options2.inPurgeable ? 0 : 1, bitmap2.getWidth(), bitmap2.getHeight(), bitmap2.getRowBytes());
                                                                    }
                                                                } else {
                                                                    if (r15 != 3 && r15 != 4) {
                                                                        if (r15 == 0 && options2.inPurgeable) {
                                                                            Utilities.pinBitmap(bitmap2);
                                                                        }
                                                                    }
                                                                    if (bitmap2.getConfig() == Bitmap.Config.ARGB_8888) {
                                                                        if (r15 == 4) {
                                                                            Bitmap createBitmap = Bitmap.createBitmap(bitmap2.getWidth(), bitmap2.getHeight(), bitmap2.getConfig());
                                                                            Canvas canvas = new Canvas(createBitmap);
                                                                            canvas.save();
                                                                            canvas.scale(1.2f, 1.2f, bitmap2.getWidth() / 2.0f, bitmap2.getHeight() / 2.0f);
                                                                            canvas.drawBitmap(bitmap2, 0.0f, 0.0f, (Paint) null);
                                                                            canvas.restore();
                                                                            Path path = new Path();
                                                                            path.addCircle(bitmap2.getWidth() / 2.0f, bitmap2.getHeight() / 2.0f, Math.min(bitmap2.getWidth(), bitmap2.getHeight()) / 2.0f, Path.Direction.CW);
                                                                            canvas.clipPath(path);
                                                                            canvas.drawBitmap(bitmap2, 0.0f, 0.0f, (Paint) null);
                                                                            bitmap2.recycle();
                                                                            bitmap2 = createBitmap;
                                                                        }
                                                                        Utilities.blurBitmap(bitmap2, 7, options2.inPurgeable ? 0 : 1, bitmap2.getWidth(), bitmap2.getHeight(), bitmap2.getRowBytes());
                                                                        Utilities.blurBitmap(bitmap2, 7, options2.inPurgeable ? 0 : 1, bitmap2.getWidth(), bitmap2.getHeight(), bitmap2.getRowBytes());
                                                                        Utilities.blurBitmap(bitmap2, 7, options2.inPurgeable ? 0 : 1, bitmap2.getWidth(), bitmap2.getHeight(), bitmap2.getRowBytes());
                                                                    }
                                                                }
                                                            } catch (Throwable th19) {
                                                                th = th19;
                                                                FileLog.e(th, !(th instanceof FileNotFoundException));
                                                                i2 = 0;
                                                                i3 = 0;
                                                                bArr2 = null;
                                                                Thread.interrupted();
                                                                if (BuildVars.LOGS_ENABLED) {
                                                                }
                                                                if (bitmap2 != null) {
                                                                }
                                                                cacheImage2 = this.cacheImage;
                                                                if (cacheImage2 != null) {
                                                                }
                                                                onPostExecute(bitmap2 == null ? new ExtendedBitmapDrawable(bitmap2, i3, i2) : bArr2);
                                                            }
                                                        }
                                                        i2 = 0;
                                                        i3 = 0;
                                                        bArr2 = null;
                                                    }
                                                } else {
                                                    int i29 = l != null ? 0 : 20;
                                                    if (i29 != 0) {
                                                        try {
                                                        } catch (Throwable th20) {
                                                            th = th20;
                                                        }
                                                        if (ImageLoader.this.lastCacheOutTime != 0) {
                                                            bitmap3 = bitmap2;
                                                            f4 = f3;
                                                            long j3 = i29;
                                                            if (ImageLoader.this.lastCacheOutTime > SystemClock.elapsedRealtime() - j3) {
                                                                try {
                                                                    f5 = f;
                                                                    if (Build.VERSION.SDK_INT < 21) {
                                                                        Thread.sleep(j3);
                                                                    }
                                                                } catch (Throwable th21) {
                                                                    th = th21;
                                                                    bitmap2 = bitmap3;
                                                                    i3 = 0;
                                                                    z13 = false;
                                                                    bArr2 = null;
                                                                    i5 = 0;
                                                                    FileLog.e(th, !(th instanceof FileNotFoundException));
                                                                    z11 = z13;
                                                                    i2 = i5;
                                                                    Thread.interrupted();
                                                                    if (BuildVars.LOGS_ENABLED) {
                                                                    }
                                                                    if (bitmap2 != null) {
                                                                    }
                                                                    cacheImage2 = this.cacheImage;
                                                                    if (cacheImage2 != null) {
                                                                    }
                                                                    onPostExecute(bitmap2 == null ? new ExtendedBitmapDrawable(bitmap2, i3, i2) : bArr2);
                                                                }
                                                            } else {
                                                                f5 = f;
                                                            }
                                                            ImageLoader.this.lastCacheOutTime = SystemClock.elapsedRealtime();
                                                            synchronized (this.sync) {
                                                                try {
                                                                    if (this.isCancelled) {
                                                                        return;
                                                                    }
                                                                    if (!z382) {
                                                                        CacheImage cacheImage8 = this.cacheImage;
                                                                        if (cacheImage8.filter != null && r15 == 0 && cacheImage8.imageLocation.path == null) {
                                                                            options2.inPreferredConfig = Bitmap.Config.RGB_565;
                                                                            options2.inDither = false;
                                                                            if (l == null && str2 == null) {
                                                                                if (!z6) {
                                                                                    thumbnail = MediaStore.Images.Thumbnails.getThumbnail(ApplicationLoader.applicationContext.getContentResolver(), l.longValue(), 1, options2);
                                                                                } else if (l.longValue() == 0) {
                                                                                    AnimatedFileDrawable animatedFileDrawable2 = new AnimatedFileDrawable(file5, true, 0L, 0, null, null, null, 0L, 0, true, null);
                                                                                    Bitmap frameAtTime2 = animatedFileDrawable2.getFrameAtTime(0L, true);
                                                                                    try {
                                                                                        animatedFileDrawable2.recycle();
                                                                                        bitmap2 = frameAtTime2;
                                                                                    } catch (Throwable th22) {
                                                                                        th = th22;
                                                                                        bitmap2 = frameAtTime2;
                                                                                        i3 = 0;
                                                                                        z13 = false;
                                                                                        bArr2 = null;
                                                                                        i5 = 0;
                                                                                        FileLog.e(th, !(th instanceof FileNotFoundException));
                                                                                        z11 = z13;
                                                                                        i2 = i5;
                                                                                        Thread.interrupted();
                                                                                        if (BuildVars.LOGS_ENABLED) {
                                                                                        }
                                                                                        if (bitmap2 != null) {
                                                                                        }
                                                                                        cacheImage2 = this.cacheImage;
                                                                                        if (cacheImage2 != null) {
                                                                                        }
                                                                                        onPostExecute(bitmap2 == null ? new ExtendedBitmapDrawable(bitmap2, i3, i2) : bArr2);
                                                                                    }
                                                                                } else {
                                                                                    thumbnail = MediaStore.Video.Thumbnails.getThumbnail(ApplicationLoader.applicationContext.getContentResolver(), l.longValue(), 1, options2);
                                                                                }
                                                                                bitmap2 = thumbnail;
                                                                            } else {
                                                                                bitmap2 = bitmap3;
                                                                            }
                                                                            if (bitmap2 != null) {
                                                                                try {
                                                                                } catch (Throwable th23) {
                                                                                    th = th23;
                                                                                    i3 = 0;
                                                                                    z13 = false;
                                                                                    bArr2 = null;
                                                                                    i5 = 0;
                                                                                    FileLog.e(th, !(th instanceof FileNotFoundException));
                                                                                    z11 = z13;
                                                                                    i2 = i5;
                                                                                    Thread.interrupted();
                                                                                    if (BuildVars.LOGS_ENABLED) {
                                                                                    }
                                                                                    if (bitmap2 != null) {
                                                                                    }
                                                                                    cacheImage2 = this.cacheImage;
                                                                                    if (cacheImage2 != null) {
                                                                                    }
                                                                                    onPostExecute(bitmap2 == null ? new ExtendedBitmapDrawable(bitmap2, i3, i2) : bArr2);
                                                                                }
                                                                                if (z3 && secureDocumentKey == null) {
                                                                                    RandomAccessFile randomAccessFile7 = new RandomAccessFile(file5, "r");
                                                                                    MappedByteBuffer map2 = randomAccessFile7.getChannel().map(FileChannel.MapMode.READ_ONLY, 0L, file5.length());
                                                                                    BitmapFactory.Options options4 = new BitmapFactory.Options();
                                                                                    options4.inJustDecodeBounds = true;
                                                                                    bArr2 = null;
                                                                                    try {
                                                                                        Utilities.loadWebpImage(null, map2, map2.limit(), options4, true);
                                                                                        bitmap2 = Bitmaps.createBitmap(options4.outWidth, options4.outHeight, Bitmap.Config.ARGB_8888);
                                                                                        try {
                                                                                            Utilities.loadWebpImage(bitmap2, map2, map2.limit(), null, !options2.inPurgeable);
                                                                                            randomAccessFile7.close();
                                                                                            i3 = 0;
                                                                                            bArr2 = null;
                                                                                        } catch (Throwable th24) {
                                                                                            th = th24;
                                                                                            bArr2 = null;
                                                                                        }
                                                                                    } catch (Throwable th25) {
                                                                                        th = th25;
                                                                                    }
                                                                                } else {
                                                                                    if (bitmap2 == null) {
                                                                                        if (secureDocumentKey != null) {
                                                                                            fileInputStream2 = new EncryptedFileInputStream(file5, secureDocumentKey);
                                                                                        } else if (z37) {
                                                                                            fileInputStream2 = new EncryptedFileInputStream(file5, this.cacheImage.encryptionKeyPath);
                                                                                        } else {
                                                                                            try {
                                                                                                fileInputStream2 = new FileInputStream(file5);
                                                                                            } catch (Throwable th26) {
                                                                                                th = th26;
                                                                                                bArr2 = null;
                                                                                            }
                                                                                        }
                                                                                        CacheImage cacheImage9 = this.cacheImage;
                                                                                        if ((cacheImage9.imageLocation.document instanceof TLRPC$TL_document) || ((str4 = cacheImage9.filter) != null && str4.contains("exif"))) {
                                                                                            Pair<Integer, Integer> imageOrientation = AndroidUtilities.getImageOrientation(fileInputStream2);
                                                                                            i3 = ((Integer) imageOrientation.first).intValue();
                                                                                            try {
                                                                                                i6 = ((Integer) imageOrientation.second).intValue();
                                                                                                try {
                                                                                                    if (secureDocumentKey == null) {
                                                                                                        try {
                                                                                                            if (this.cacheImage.encryptionKeyPath == null) {
                                                                                                                fileInputStream2.getChannel().position(0L);
                                                                                                            }
                                                                                                        } catch (Throwable th27) {
                                                                                                            th = th27;
                                                                                                            i5 = i6;
                                                                                                            z13 = false;
                                                                                                            bArr2 = null;
                                                                                                        }
                                                                                                    }
                                                                                                    fileInputStream2.close();
                                                                                                    if (secureDocumentKey != null) {
                                                                                                        fileInputStream2 = new EncryptedFileInputStream(file5, secureDocumentKey);
                                                                                                    } else if (z37) {
                                                                                                        fileInputStream2 = new EncryptedFileInputStream(file5, this.cacheImage.encryptionKeyPath);
                                                                                                    }
                                                                                                } catch (Throwable th28) {
                                                                                                    th = th28;
                                                                                                    bArr2 = null;
                                                                                                    i5 = i6;
                                                                                                    z13 = false;
                                                                                                    FileLog.e(th, !(th instanceof FileNotFoundException));
                                                                                                    z11 = z13;
                                                                                                    i2 = i5;
                                                                                                    Thread.interrupted();
                                                                                                    if (BuildVars.LOGS_ENABLED) {
                                                                                                    }
                                                                                                    if (bitmap2 != null) {
                                                                                                    }
                                                                                                    cacheImage2 = this.cacheImage;
                                                                                                    if (cacheImage2 != null) {
                                                                                                    }
                                                                                                    onPostExecute(bitmap2 == null ? new ExtendedBitmapDrawable(bitmap2, i3, i2) : bArr2);
                                                                                                }
                                                                                            } catch (Throwable th29) {
                                                                                                th = th29;
                                                                                                bArr2 = null;
                                                                                            }
                                                                                        } else {
                                                                                            i6 = 0;
                                                                                            i3 = 0;
                                                                                        }
                                                                                        bArr2 = null;
                                                                                        try {
                                                                                            bitmap2 = BitmapFactory.decodeStream(fileInputStream2, null, options2);
                                                                                            fileInputStream2.close();
                                                                                        } catch (Throwable th30) {
                                                                                            th = th30;
                                                                                            i5 = i6;
                                                                                            z13 = false;
                                                                                            FileLog.e(th, !(th instanceof FileNotFoundException));
                                                                                            z11 = z13;
                                                                                            i2 = i5;
                                                                                            Thread.interrupted();
                                                                                            if (BuildVars.LOGS_ENABLED) {
                                                                                            }
                                                                                            if (bitmap2 != null) {
                                                                                            }
                                                                                            cacheImage2 = this.cacheImage;
                                                                                            if (cacheImage2 != null) {
                                                                                            }
                                                                                            onPostExecute(bitmap2 == null ? new ExtendedBitmapDrawable(bitmap2, i3, i2) : bArr2);
                                                                                        }
                                                                                    } else {
                                                                                        bArr2 = null;
                                                                                        i6 = 0;
                                                                                        i3 = 0;
                                                                                    }
                                                                                    if (bitmap2 == null) {
                                                                                        try {
                                                                                            RandomAccessFile randomAccessFile8 = new RandomAccessFile(file5, "r");
                                                                                            int length3 = (int) randomAccessFile8.length();
                                                                                            byte[] bArr7 = (byte[]) ImageLoader.bytesLocal.get();
                                                                                            if (bArr7 == null || bArr7.length < length3) {
                                                                                                bArr7 = bArr2;
                                                                                            }
                                                                                            if (bArr7 == null) {
                                                                                                bArr7 = new byte[length3];
                                                                                                ImageLoader.bytesLocal.set(bArr7);
                                                                                            }
                                                                                            randomAccessFile8.readFully(bArr7, 0, length3);
                                                                                            randomAccessFile8.close();
                                                                                            try {
                                                                                                if (secureDocumentKey != null) {
                                                                                                    EncryptedFileInputStream.decryptBytesWithKeyFile(bArr7, 0, length3, secureDocumentKey);
                                                                                                    i5 = i6;
                                                                                                    byte[] computeSHA2563 = Utilities.computeSHA256(bArr7, 0, length3);
                                                                                                    if (bArr != null && Arrays.equals(computeSHA2563, bArr)) {
                                                                                                        z14 = false;
                                                                                                        i7 = bArr7[0] & 255;
                                                                                                        length3 -= i7;
                                                                                                    }
                                                                                                    z14 = true;
                                                                                                    i7 = bArr7[0] & 255;
                                                                                                    length3 -= i7;
                                                                                                } else {
                                                                                                    i5 = i6;
                                                                                                    if (z37) {
                                                                                                        EncryptedFileInputStream.decryptBytesWithKeyFile(bArr7, 0, length3, this.cacheImage.encryptionKeyPath);
                                                                                                    }
                                                                                                    z14 = false;
                                                                                                    i7 = 0;
                                                                                                }
                                                                                                if (!z14) {
                                                                                                    bitmap2 = BitmapFactory.decodeByteArray(bArr7, i7, length3, options2);
                                                                                                }
                                                                                            } catch (Throwable th31) {
                                                                                                th = th31;
                                                                                                try {
                                                                                                    FileLog.e(th);
                                                                                                    if (bitmap2 != null) {
                                                                                                    }
                                                                                                } catch (Throwable th32) {
                                                                                                    th = th32;
                                                                                                    z13 = false;
                                                                                                    FileLog.e(th, !(th instanceof FileNotFoundException));
                                                                                                    z11 = z13;
                                                                                                    i2 = i5;
                                                                                                    Thread.interrupted();
                                                                                                    if (BuildVars.LOGS_ENABLED) {
                                                                                                    }
                                                                                                    if (bitmap2 != null) {
                                                                                                    }
                                                                                                    cacheImage2 = this.cacheImage;
                                                                                                    if (cacheImage2 != null) {
                                                                                                    }
                                                                                                    onPostExecute(bitmap2 == null ? new ExtendedBitmapDrawable(bitmap2, i3, i2) : bArr2);
                                                                                                }
                                                                                                z11 = z13;
                                                                                                i2 = i5;
                                                                                                Thread.interrupted();
                                                                                                if (BuildVars.LOGS_ENABLED) {
                                                                                                }
                                                                                                if (bitmap2 != null) {
                                                                                                }
                                                                                                cacheImage2 = this.cacheImage;
                                                                                                if (cacheImage2 != null) {
                                                                                                }
                                                                                                onPostExecute(bitmap2 == null ? new ExtendedBitmapDrawable(bitmap2, i3, i2) : bArr2);
                                                                                            }
                                                                                        } catch (Throwable th33) {
                                                                                            th = th33;
                                                                                            i5 = i6;
                                                                                        }
                                                                                    } else {
                                                                                        i5 = i6;
                                                                                    }
                                                                                    if (bitmap2 != null) {
                                                                                        if (z7 && (file5.length() == 0 || this.cacheImage.filter == null)) {
                                                                                            file5.delete();
                                                                                        }
                                                                                        z13 = false;
                                                                                    } else {
                                                                                        if (this.cacheImage.filter != null) {
                                                                                            float width2 = bitmap2.getWidth();
                                                                                            float height2 = bitmap2.getHeight();
                                                                                            if (!options2.inPurgeable && f4 != 0.0f && width2 != f4 && width2 > 20.0f + f4) {
                                                                                                if (width2 <= height2 || f4 <= f5) {
                                                                                                    float f10 = height2 / f5;
                                                                                                    if (f10 > 1.0f) {
                                                                                                        createScaledBitmap2 = Bitmaps.createScaledBitmap(bitmap2, (int) (width2 / f10), (int) f5, true);
                                                                                                        if (bitmap2 != createScaledBitmap2) {
                                                                                                            bitmap2.recycle();
                                                                                                            bitmap2 = createScaledBitmap2;
                                                                                                        }
                                                                                                    }
                                                                                                    createScaledBitmap2 = bitmap2;
                                                                                                    if (bitmap2 != createScaledBitmap2) {
                                                                                                    }
                                                                                                } else {
                                                                                                    float f11 = width2 / f4;
                                                                                                    if (f11 > 1.0f) {
                                                                                                        createScaledBitmap2 = Bitmaps.createScaledBitmap(bitmap2, (int) f4, (int) (height2 / f11), true);
                                                                                                        if (bitmap2 != createScaledBitmap2) {
                                                                                                        }
                                                                                                    }
                                                                                                    createScaledBitmap2 = bitmap2;
                                                                                                    if (bitmap2 != createScaledBitmap2) {
                                                                                                    }
                                                                                                }
                                                                                            }
                                                                                            if (bitmap2 != null) {
                                                                                                if (z10) {
                                                                                                    Bitmap createScaledBitmap3 = bitmap2.getWidth() * bitmap2.getHeight() > 22500 ? Bitmaps.createScaledBitmap(bitmap2, 100, 100, false) : bitmap2;
                                                                                                    z13 = Utilities.needInvert(createScaledBitmap3, options2.inPurgeable ? 0 : 1, createScaledBitmap3.getWidth(), createScaledBitmap3.getHeight(), createScaledBitmap3.getRowBytes()) != 0;
                                                                                                    if (createScaledBitmap3 != bitmap2) {
                                                                                                        try {
                                                                                                            createScaledBitmap3.recycle();
                                                                                                        } catch (Throwable th34) {
                                                                                                            th = th34;
                                                                                                        }
                                                                                                    }
                                                                                                } else {
                                                                                                    z13 = false;
                                                                                                }
                                                                                                if (r15 != 0 && (height2 > 100.0f || width2 > 100.0f)) {
                                                                                                    height2 = 80.0f;
                                                                                                    bitmap2 = Bitmaps.createScaledBitmap(bitmap2, 80, 80, false);
                                                                                                    width2 = 80.0f;
                                                                                                }
                                                                                                if (r15 == 0 || height2 >= 100.0f || width2 >= 100.0f) {
                                                                                                    z15 = false;
                                                                                                } else {
                                                                                                    if (bitmap2.getConfig() == Bitmap.Config.ARGB_8888) {
                                                                                                        Utilities.blurBitmap(bitmap2, 3, options2.inPurgeable ? 0 : 1, bitmap2.getWidth(), bitmap2.getHeight(), bitmap2.getRowBytes());
                                                                                                    }
                                                                                                    z15 = true;
                                                                                                }
                                                                                                if (!z15 && options2.inPurgeable) {
                                                                                                    Utilities.pinBitmap(bitmap2);
                                                                                                }
                                                                                            }
                                                                                        }
                                                                                        z15 = false;
                                                                                        z13 = false;
                                                                                        if (!z15) {
                                                                                            Utilities.pinBitmap(bitmap2);
                                                                                        }
                                                                                    }
                                                                                    z11 = z13;
                                                                                    i2 = i5;
                                                                                }
                                                                                i3 = 0;
                                                                                z13 = false;
                                                                                i5 = 0;
                                                                                FileLog.e(th, !(th instanceof FileNotFoundException));
                                                                                z11 = z13;
                                                                                i2 = i5;
                                                                            } else {
                                                                                bArr2 = null;
                                                                                i3 = 0;
                                                                            }
                                                                            i5 = 0;
                                                                            if (bitmap2 != null) {
                                                                            }
                                                                            z11 = z13;
                                                                            i2 = i5;
                                                                        }
                                                                    }
                                                                    options2.inPreferredConfig = Bitmap.Config.ARGB_8888;
                                                                    options2.inDither = false;
                                                                    if (l == null) {
                                                                    }
                                                                    bitmap2 = bitmap3;
                                                                    if (bitmap2 != null) {
                                                                    }
                                                                    i5 = 0;
                                                                    if (bitmap2 != null) {
                                                                    }
                                                                    z11 = z13;
                                                                    i2 = i5;
                                                                } finally {
                                                                    th = th;
                                                                    bArr2 = null;
                                                                    while (true) {
                                                                        try {
                                                                            try {
                                                                                break;
                                                                            } catch (Throwable th35) {
                                                                                th = th35;
                                                                                bitmap2 = bitmap3;
                                                                                i3 = 0;
                                                                                z13 = false;
                                                                                i5 = 0;
                                                                                FileLog.e(th, !(th instanceof FileNotFoundException));
                                                                                z11 = z13;
                                                                                i2 = i5;
                                                                                Thread.interrupted();
                                                                                if (BuildVars.LOGS_ENABLED) {
                                                                                }
                                                                                if (bitmap2 != null) {
                                                                                }
                                                                                cacheImage2 = this.cacheImage;
                                                                                if (cacheImage2 != null) {
                                                                                }
                                                                                onPostExecute(bitmap2 == null ? new ExtendedBitmapDrawable(bitmap2, i3, i2) : bArr2);
                                                                            }
                                                                        } catch (Throwable th36) {
                                                                            th = th36;
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                    f5 = f;
                                                    bitmap3 = bitmap2;
                                                    f4 = f3;
                                                    ImageLoader.this.lastCacheOutTime = SystemClock.elapsedRealtime();
                                                    synchronized (this.sync) {
                                                    }
                                                }
                                                Thread.interrupted();
                                                if (BuildVars.LOGS_ENABLED && z37) {
                                                    StringBuilder sb = new StringBuilder();
                                                    sb.append("Image Loader image is empty = ");
                                                    sb.append(bitmap2 != null);
                                                    sb.append(" ");
                                                    sb.append(file5);
                                                    FileLog.e(sb.toString());
                                                }
                                                if (bitmap2 != null && !TextUtils.isEmpty(this.cacheImage.filter) && this.cacheImage.filter.contains("wallpaper")) {
                                                    obj2 = this.cacheImage.parentObject;
                                                    if (obj2 instanceof TLRPC$WallPaper) {
                                                        bitmap2 = applyWallpaperSetting(bitmap2, (TLRPC$WallPaper) obj2);
                                                    }
                                                }
                                                cacheImage2 = this.cacheImage;
                                                if ((cacheImage2 != null || (str3 = cacheImage2.filter) == null || !str3.contains("ignoreOrientation")) && (z11 || i3 != 0 || i2 != 0)) {
                                                    onPostExecute(bitmap2 == null ? new ExtendedBitmapDrawable(bitmap2, i3, i2) : bArr2);
                                                } else {
                                                    onPostExecute(bitmap2 != null ? new BitmapDrawable(bitmap2) : bArr2);
                                                    return;
                                                }
                                            }
                                            if (!str.startsWith("http")) {
                                                str2 = null;
                                                l = null;
                                            }
                                        }
                                        z5 = false;
                                        z4 = false;
                                        BitmapFactory.Options options22 = new BitmapFactory.Options();
                                        options22.inSampleSize = 1;
                                        if (Build.VERSION.SDK_INT < 21) {
                                        }
                                        boolean z3822 = ImageLoader.this.canForce8888;
                                        str5 = this.cacheImage.filter;
                                        if (str5 == null) {
                                        }
                                        f3 = f2;
                                        r15 = z8;
                                        z10 = z9;
                                        i = 1;
                                        if (this.cacheImage.type == i) {
                                        }
                                        Thread.interrupted();
                                        if (BuildVars.LOGS_ENABLED) {
                                            StringBuilder sb2 = new StringBuilder();
                                            sb2.append("Image Loader image is empty = ");
                                            sb2.append(bitmap2 != null);
                                            sb2.append(" ");
                                            sb2.append(file5);
                                            FileLog.e(sb2.toString());
                                        }
                                        if (bitmap2 != null) {
                                            obj2 = this.cacheImage.parentObject;
                                            if (obj2 instanceof TLRPC$WallPaper) {
                                            }
                                        }
                                        cacheImage2 = this.cacheImage;
                                        if (cacheImage2 != null) {
                                        }
                                        onPostExecute(bitmap2 == null ? new ExtendedBitmapDrawable(bitmap2, i3, i2) : bArr2);
                                    }
                                    z4 = true;
                                    str2 = null;
                                    l = null;
                                    z5 = false;
                                    BitmapFactory.Options options222 = new BitmapFactory.Options();
                                    options222.inSampleSize = 1;
                                    if (Build.VERSION.SDK_INT < 21) {
                                    }
                                    boolean z38222 = ImageLoader.this.canForce8888;
                                    str5 = this.cacheImage.filter;
                                    if (str5 == null) {
                                    }
                                    f3 = f2;
                                    r15 = z8;
                                    z10 = z9;
                                    i = 1;
                                    if (this.cacheImage.type == i) {
                                    }
                                    Thread.interrupted();
                                    if (BuildVars.LOGS_ENABLED) {
                                    }
                                    if (bitmap2 != null) {
                                    }
                                    cacheImage2 = this.cacheImage;
                                    if (cacheImage2 != null) {
                                    }
                                    onPostExecute(bitmap2 == null ? new ExtendedBitmapDrawable(bitmap2, i3, i2) : bArr2);
                                }
                            }
                            z3 = false;
                            randomAccessFile2.close();
                            str = this.cacheImage.imageLocation.path;
                            if (str != null) {
                            }
                            z4 = true;
                            str2 = null;
                            l = null;
                            z5 = false;
                            BitmapFactory.Options options2222 = new BitmapFactory.Options();
                            options2222.inSampleSize = 1;
                            if (Build.VERSION.SDK_INT < 21) {
                            }
                            boolean z382222 = ImageLoader.this.canForce8888;
                            str5 = this.cacheImage.filter;
                            if (str5 == null) {
                            }
                            f3 = f2;
                            r15 = z8;
                            z10 = z9;
                            i = 1;
                            if (this.cacheImage.type == i) {
                            }
                            Thread.interrupted();
                            if (BuildVars.LOGS_ENABLED) {
                            }
                            if (bitmap2 != null) {
                            }
                            cacheImage2 = this.cacheImage;
                            if (cacheImage2 != null) {
                            }
                            onPostExecute(bitmap2 == null ? new ExtendedBitmapDrawable(bitmap2, i3, i2) : bArr2);
                        }
                        z3 = false;
                        str = this.cacheImage.imageLocation.path;
                        if (str != null) {
                        }
                        z4 = true;
                        str2 = null;
                        l = null;
                        z5 = false;
                        BitmapFactory.Options options22222 = new BitmapFactory.Options();
                        options22222.inSampleSize = 1;
                        if (Build.VERSION.SDK_INT < 21) {
                        }
                        boolean z3822222 = ImageLoader.this.canForce8888;
                        str5 = this.cacheImage.filter;
                        if (str5 == null) {
                        }
                        f3 = f2;
                        r15 = z8;
                        z10 = z9;
                        i = 1;
                        if (this.cacheImage.type == i) {
                        }
                        Thread.interrupted();
                        if (BuildVars.LOGS_ENABLED) {
                        }
                        if (bitmap2 != null) {
                        }
                        cacheImage2 = this.cacheImage;
                        if (cacheImage2 != null) {
                        }
                        onPostExecute(bitmap2 == null ? new ExtendedBitmapDrawable(bitmap2, i3, i2) : bArr2);
                    } catch (Throwable th37) {
                        th = th37;
                        randomAccessFile = 19;
                    }
                }
            }
        }

        private Bitmap applyWallpaperSetting(Bitmap bitmap, TLRPC$WallPaper tLRPC$WallPaper) {
            int i;
            if (!tLRPC$WallPaper.pattern || tLRPC$WallPaper.settings == null) {
                TLRPC$WallPaperSettings tLRPC$WallPaperSettings = tLRPC$WallPaper.settings;
                return (tLRPC$WallPaperSettings == null || !tLRPC$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 tLRPC$WallPaperSettings2 = tLRPC$WallPaper.settings;
            boolean z = true;
            if (tLRPC$WallPaperSettings2.second_background_color == 0) {
                i = AndroidUtilities.getPatternColor(tLRPC$WallPaperSettings2.background_color);
                canvas.drawColor(ColorUtils.setAlphaComponent(tLRPC$WallPaper.settings.background_color, 255));
            } else if (tLRPC$WallPaperSettings2.third_background_color == 0) {
                int alphaComponent = ColorUtils.setAlphaComponent(tLRPC$WallPaperSettings2.background_color, 255);
                int alphaComponent2 = ColorUtils.setAlphaComponent(tLRPC$WallPaper.settings.second_background_color, 255);
                int averageColor = AndroidUtilities.getAverageColor(alphaComponent, alphaComponent2);
                GradientDrawable gradientDrawable = new GradientDrawable(BackgroundGradientDrawable.getGradientOrientation(tLRPC$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(tLRPC$WallPaperSettings2.background_color, 255);
                int alphaComponent4 = ColorUtils.setAlphaComponent(tLRPC$WallPaper.settings.second_background_color, 255);
                int alphaComponent5 = ColorUtils.setAlphaComponent(tLRPC$WallPaper.settings.third_background_color, 255);
                int i2 = tLRPC$WallPaper.settings.fourth_background_color;
                int alphaComponent6 = i2 == 0 ? 0 : ColorUtils.setAlphaComponent(i2, 255);
                int patternColor = MotionBackgroundDrawable.getPatternColor(alphaComponent3, alphaComponent4, alphaComponent5, alphaComponent6);
                MotionBackgroundDrawable motionBackgroundDrawable = new MotionBackgroundDrawable();
                motionBackgroundDrawable.setColors(alphaComponent3, alphaComponent4, alphaComponent5, alphaComponent6);
                motionBackgroundDrawable.setBounds(0, 0, createBitmap.getWidth(), createBitmap.getHeight());
                motionBackgroundDrawable.setPatternBitmap(tLRPC$WallPaper.settings.intensity, bitmap);
                motionBackgroundDrawable.draw(canvas);
                z = false;
                i = patternColor;
            }
            if (z) {
                Paint paint = new Paint(2);
                paint.setColorFilter(new PorterDuffColorFilter(i, PorterDuff.Mode.SRC_IN));
                paint.setAlpha((int) ((tLRPC$WallPaper.settings.intensity / 100.0f) * 255.0f));
                canvas.drawBitmap(bitmap, 0.0f, 0.0f, paint);
            }
            return createBitmap;
        }

        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 lambda$onPostExecute$1(Drawable drawable) {
            final String str;
            boolean z = false;
            final Drawable drawable2 = null;
            r2 = null;
            r2 = null;
            r2 = null;
            String str2 = null;
            if (drawable instanceof RLottieDrawable) {
                RLottieDrawable rLottieDrawable = (RLottieDrawable) drawable;
                Drawable drawable3 = (Drawable) ImageLoader.this.lottieMemCache.get(this.cacheImage.key);
                if (drawable3 == null) {
                    ImageLoader.this.lottieMemCache.put(this.cacheImage.key, rLottieDrawable);
                    drawable = rLottieDrawable;
                } else {
                    rLottieDrawable.recycle(false);
                    drawable = drawable3;
                }
                if (drawable != null) {
                    ImageLoader.this.incrementUseCount(this.cacheImage.key);
                    str2 = this.cacheImage.key;
                }
            } else if (drawable instanceof AnimatedFileDrawable) {
                AnimatedFileDrawable animatedFileDrawable = (AnimatedFileDrawable) drawable;
                if (animatedFileDrawable.isWebmSticker) {
                    BitmapDrawable fromLottieCache = ImageLoader.this.getFromLottieCache(this.cacheImage.key);
                    if (fromLottieCache == null) {
                        ImageLoader.this.lottieMemCache.put(this.cacheImage.key, animatedFileDrawable);
                        drawable = animatedFileDrawable;
                    } else {
                        animatedFileDrawable.recycle();
                        drawable = fromLottieCache;
                    }
                    ImageLoader.this.incrementUseCount(this.cacheImage.key);
                    str2 = this.cacheImage.key;
                }
            } else {
                if (!(drawable instanceof BitmapDrawable)) {
                    str = null;
                    ImageLoader.this.imageLoadQueue.postRunnable(new Runnable() {
                        @Override
                        public final void run() {
                            ImageLoader.CacheOutTask.this.lambda$onPostExecute$0(drawable2, str);
                        }
                    }, this.cacheImage.priority);
                }
                BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
                BitmapDrawable fromMemCache = ImageLoader.this.getFromMemCache(this.cacheImage.key);
                boolean z2 = true;
                if (fromMemCache == null) {
                    if (this.cacheImage.key.endsWith("_f")) {
                        ImageLoader.this.wallpaperMemCache.put(this.cacheImage.key, bitmapDrawable);
                    } else {
                        if (this.cacheImage.key.endsWith("_isc") || bitmapDrawable.getBitmap().getWidth() > AndroidUtilities.density * 80.0f || bitmapDrawable.getBitmap().getHeight() > AndroidUtilities.density * 80.0f) {
                            ImageLoader.this.memCache.put(this.cacheImage.key, bitmapDrawable);
                        } else {
                            ImageLoader.this.smallImagesMemCache.put(this.cacheImage.key, bitmapDrawable);
                        }
                        z = true;
                    }
                    z2 = z;
                    drawable = bitmapDrawable;
                } else {
                    AndroidUtilities.recycleBitmap(bitmapDrawable.getBitmap());
                    drawable = fromMemCache;
                }
                if (drawable != null && z2) {
                    ImageLoader.this.incrementUseCount(this.cacheImage.key);
                    str2 = this.cacheImage.key;
                }
            }
            String str3 = str2;
            drawable2 = drawable;
            str = str3;
            ImageLoader.this.imageLoadQueue.postRunnable(new Runnable() {
                @Override
                public final void run() {
                    ImageLoader.CacheOutTask.this.lambda$onPostExecute$0(drawable2, str);
                }
            }, this.cacheImage.priority);
        }

        public void lambda$onPostExecute$0(Drawable drawable, String str) {
            this.cacheImage.setImageAndClear(drawable, str);
        }

        public void cancel() {
            synchronized (this.sync) {
                try {
                    this.isCancelled = true;
                    Thread thread = this.runningThread;
                    if (thread != null) {
                        thread.interrupt();
                    }
                } catch (Exception unused) {
                }
            }
        }
    }

    public boolean isAnimatedAvatar(String str) {
        return str != null && str.endsWith("avatar");
    }

    private boolean isPFrame(String str) {
        return str != null && str.endsWith("pframe");
    }

    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 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 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 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);
        }

        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 setImageReceiverGuid(ImageReceiver imageReceiver, int i) {
            int indexOf = this.imageReceiverArray.indexOf(imageReceiver);
            if (indexOf == -1) {
                return;
            }
            this.imageReceiverGuidsArray.set(indexOf, Integer.valueOf(i));
        }

        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) {
                    if (i == 1) {
                        ImageLoader.this.cacheThumbOutQueue.cancelRunnable(this.cacheTask);
                    } else {
                        ImageLoader.this.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);
                }
                if (this.key != null) {
                    ImageLoader.this.imageLoadingByKeys.remove(this.key);
                }
            }
        }

        void changePriority(int i) {
            TLRPC$Document tLRPC$Document;
            ?? r6;
            TLObject tLObject;
            TLRPC$TL_fileLocationToBeDeprecated tLRPC$TL_fileLocationToBeDeprecated;
            TLRPC$TL_fileLocationToBeDeprecated tLRPC$TL_fileLocationToBeDeprecated2;
            ?? r9;
            ?? r7;
            ImageLocation imageLocation = this.imageLocation;
            if (imageLocation != null) {
                TLRPC$TL_fileLocationToBeDeprecated tLRPC$TL_fileLocationToBeDeprecated3 = imageLocation.location;
                if (tLRPC$TL_fileLocationToBeDeprecated3 != null) {
                    r9 = this.ext;
                    tLRPC$TL_fileLocationToBeDeprecated = tLRPC$TL_fileLocationToBeDeprecated3;
                    tLRPC$Document = null;
                    r6 = null;
                    r7 = 0;
                } else {
                    TLRPC$Document tLRPC$Document2 = imageLocation.document;
                    if (tLRPC$Document2 != null) {
                        tLRPC$Document = tLRPC$Document2;
                        r6 = null;
                    } else {
                        SecureDocument secureDocument = imageLocation.secureDocument;
                        if (secureDocument != null) {
                            r6 = secureDocument;
                            tLRPC$Document = null;
                            tLRPC$TL_fileLocationToBeDeprecated2 = null;
                            tLRPC$TL_fileLocationToBeDeprecated = tLRPC$TL_fileLocationToBeDeprecated2;
                            tLObject = tLRPC$TL_fileLocationToBeDeprecated2;
                            r9 = tLRPC$TL_fileLocationToBeDeprecated;
                            r7 = tLObject;
                        } else {
                            TLObject tLObject2 = imageLocation.webFile;
                            if (tLObject2 != null) {
                                tLObject = tLObject2;
                                tLRPC$Document = null;
                                r6 = null;
                                tLRPC$TL_fileLocationToBeDeprecated = null;
                                r9 = tLRPC$TL_fileLocationToBeDeprecated;
                                r7 = tLObject;
                            } else {
                                tLRPC$Document = null;
                                r6 = null;
                            }
                        }
                    }
                    tLRPC$TL_fileLocationToBeDeprecated2 = r6;
                    tLRPC$TL_fileLocationToBeDeprecated = tLRPC$TL_fileLocationToBeDeprecated2;
                    tLObject = tLRPC$TL_fileLocationToBeDeprecated2;
                    r9 = tLRPC$TL_fileLocationToBeDeprecated;
                    r7 = tLObject;
                }
                FileLoader.getInstance(this.currentAccount).changePriority(i, tLRPC$Document, r6, r7, tLRPC$TL_fileLocationToBeDeprecated, r9, null);
            }
        }

        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);
            }
            if (this.key != null) {
                ImageLoader.this.imageLoadingByKeys.remove(this.key);
            }
        }

        public void lambda$setImageAndClear$0(Drawable drawable, ArrayList arrayList, ArrayList arrayList2, String str) {
            int i = 0;
            if (drawable instanceof AnimatedFileDrawable) {
                AnimatedFileDrawable animatedFileDrawable = (AnimatedFileDrawable) drawable;
                if (!animatedFileDrawable.isWebmSticker) {
                    boolean z = false;
                    while (i < arrayList.size()) {
                        ImageReceiver imageReceiver = (ImageReceiver) arrayList.get(i);
                        AnimatedFileDrawable makeCopy = i == 0 ? animatedFileDrawable : animatedFileDrawable.makeCopy();
                        if (imageReceiver.setImageBitmapByKey(makeCopy, this.key, this.type, false, ((Integer) arrayList2.get(i)).intValue())) {
                            if (makeCopy == animatedFileDrawable) {
                                z = true;
                            }
                        } else if (makeCopy != animatedFileDrawable) {
                            makeCopy.recycle();
                        }
                        i++;
                    }
                    if (!z) {
                        animatedFileDrawable.recycle();
                    }
                    if (str == null) {
                        ImageLoader.this.decrementUseCount(str);
                        return;
                    }
                    return;
                }
            }
            while (i < arrayList.size()) {
                ((ImageReceiver) arrayList.get(i)).setImageBitmapByKey(drawable, this.key, this.types.get(i).intValue(), false, ((Integer) arrayList2.get(i)).intValue());
                i++;
            }
            if (str == null) {
            }
        }
    }

    public static ImageLoader getInstance() {
        ImageLoader imageLoader = Instance;
        if (imageLoader == null) {
            synchronized (ImageLoader.class) {
                imageLoader = Instance;
                if (imageLoader == null) {
                    imageLoader = new ImageLoader();
                    Instance = imageLoader;
                }
            }
        }
        return imageLoader;
    }

    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) * 1024 * 1024;
        float f = min;
        this.memCache = new LruCache<BitmapDrawable>((int) (0.8f * f)) {
            @Override
            public int sizeOf(String str, BitmapDrawable bitmapDrawable) {
                return ImageLoader.this.sizeOfBitmapDrawable(bitmapDrawable);
            }

            @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);
                    }
                }
            }
        };
        this.smallImagesMemCache = new LruCache<BitmapDrawable>((int) (f * 0.2f)) {
            @Override
            public int sizeOf(String str, BitmapDrawable bitmapDrawable) {
                return ImageLoader.this.sizeOfBitmapDrawable(bitmapDrawable);
            }

            @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);
                    }
                }
            }
        };
        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 int sizeOf(String str, BitmapDrawable bitmapDrawable) {
                return ImageLoader.this.sizeOfBitmapDrawable(bitmapDrawable);
            }

            @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 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);
                    }
                }
            }
        };
        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 {
            ApplicationLoader.applicationContext.registerReceiver(anonymousClass6, intentFilter);
        } catch (Throwable unused) {
        }
        checkMediaPaths();
    }

    public class AnonymousClass5 implements FileLoader.FileLoaderDelegate {
        final int val$currentAccount;

        AnonymousClass5(int i) {
            this.val$currentAccount = i;
        }

        @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);
                    }
                });
            }
        }

        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 fileDidUploaded(final String str, final TLRPC$InputFile tLRPC$InputFile, final TLRPC$InputEncryptedFile tLRPC$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, tLRPC$InputFile, tLRPC$InputEncryptedFile, bArr, bArr2, j);
                }
            });
        }

        public static void lambda$fileDidUploaded$1(int i, String str, TLRPC$InputFile tLRPC$InputFile, TLRPC$InputEncryptedFile tLRPC$InputEncryptedFile, byte[] bArr, byte[] bArr2, long j) {
            NotificationCenter.getInstance(i).lambda$postNotificationNameOnUIThread$1(NotificationCenter.fileUploaded, str, tLRPC$InputFile, tLRPC$InputEncryptedFile, bArr, bArr2, Long.valueOf(j));
        }

        public void lambda$fileDidUploaded$2(final int i, final String str, final TLRPC$InputFile tLRPC$InputFile, final TLRPC$InputEncryptedFile tLRPC$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, tLRPC$InputFile, tLRPC$InputEncryptedFile, bArr, bArr2, j);
                }
            });
            ImageLoader.this.fileProgresses.remove(str);
        }

        @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);
                }
            });
        }

        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);
        }

        @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);
                }
            });
        }

        public void lambda$fileDidLoaded$5(File file, String str, int i, Object obj, int i2) {
            FilePathDatabase.FileMeta fileMetadataFromParent;
            int i3;
            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 (j >= 0) {
                    i3 = 1;
                } else {
                    i3 = ChatObject.isChannelAndNotMegaGroup(MessagesController.getInstance(i).getChat(Long.valueOf(-j))) ? 4 : 2;
                }
                if (SaveToGallerySettingsHelper.needSave(i3, fileMetadataFromParent, messageObject, i)) {
                    AndroidUtilities.addMediaToGallery(file.toString());
                }
            }
            NotificationCenter.getInstance(i).lambda$postNotificationNameOnUIThread$1(NotificationCenter.fileLoaded, str, file);
            ImageLoader.this.fileDidLoaded(str, file, i2);
        }

        @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);
                }
            });
        }

        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));
        }

        @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);
                    }
                });
            }
        }

        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 = new CacheOutTask(cacheImage2);
                    cacheImage2.filter = str3;
                    cacheImage2.imageType = cacheImage.imageType;
                    cacheImage2.cacheType = cacheImage.cacheType;
                    ImageLoader.this.imageLoadingByKeys.put(str2, cacheImage2);
                    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 class AnonymousClass6 extends BroadcastReceiver {
        AnonymousClass6() {
        }

        @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();
            }
        }

        public void lambda$onReceive$0() {
            ImageLoader.this.checkMediaPaths();
        }
    }

    public int sizeOfBitmapDrawable(BitmapDrawable bitmapDrawable) {
        if (bitmapDrawable instanceof AnimatedFileDrawable) {
            AnimatedFileDrawable animatedFileDrawable = (AnimatedFileDrawable) bitmapDrawable;
            return Math.max(animatedFileDrawable.getIntrinsicHeight() * bitmapDrawable.getIntrinsicWidth() * 4 * 3, animatedFileDrawable.getRenderingHeight() * animatedFileDrawable.getRenderingWidth() * 4 * 3);
        }
        if (bitmapDrawable instanceof RLottieDrawable) {
            return bitmapDrawable.getIntrinsicWidth() * bitmapDrawable.getIntrinsicHeight() * 4 * 2;
        }
        return bitmapDrawable.getBitmap().getByteCount();
    }

    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 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 static void lambda$checkMediaPaths$0(SparseArray sparseArray, Runnable runnable) {
        FileLoader.setMediaDirs(sparseArray);
        if (runnable != null) {
            runnable.run();
        }
    }

    public void addTestWebFile(String str, WebFile webFile) {
        if (str == null || webFile == null) {
            return;
        }
        this.testWebFile.put(str, webFile);
    }

    public void removeTestWebFile(String str) {
        if (str == null) {
            return;
        }
        this.testWebFile.remove(str);
    }

    @TargetApi(26)
    private static void moveDirectory(File file, final File file2) {
        if (file.exists()) {
            if (file2.exists() || file2.mkdir()) {
                try {
                    Stream convert = C$r8$wrapper$java$util$stream$Stream$VWRP.convert(Files.list(file.toPath()));
                    try {
                        convert.forEach(new Consumer() {
                            @Override
                            public final void accept(Object obj) {
                                ImageLoader.lambda$moveDirectory$2(file2, (java.nio.file.Path) obj);
                            }

                            @Override
                            public Consumer andThen(Consumer consumer) {
                                return Consumer.CC.$default$andThen(this, consumer);
                            }
                        });
                        convert.close();
                    } finally {
                    }
                } catch (Exception e) {
                    FileLog.e(e);
                }
            }
        }
    }

    public static void lambda$moveDirectory$2(File file, java.nio.file.Path path) {
        File file2 = new File(file, path.getFileName().toString());
        if (Files.isDirectory(path, new LinkOption[0])) {
            moveDirectory(path.toFile(), file2);
            return;
        }
        try {
            Files.move(path, file2.toPath(), new CopyOption[0]);
        } catch (Exception e) {
            FileLog.e(e);
        }
    }

    public SparseArray<File> createMediaPaths() {
        File file;
        File file2;
        File file3;
        int size;
        int i;
        File[] externalFilesDirs;
        SparseArray<File> 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);
        if (BuildVars.LOGS_ENABLED) {
            FileLog.d("cache path = " + cacheDir);
        }
        FileLog.d("selected SD card = " + SharedConfig.storageCacheDir);
        try {
            if (Environmenu.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
                File externalStorageDirectory = Environment.getExternalStorageDirectory();
                File file4 = null;
                if (!TextUtils.isEmpty(SharedConfig.storageCacheDir)) {
                    ArrayList<File> rootDirs = AndroidUtilities.getRootDirs();
                    if (rootDirs != null) {
                        int size2 = rootDirs.size();
                        int i2 = 0;
                        while (true) {
                            if (i2 >= size2) {
                                break;
                            }
                            File file5 = rootDirs.get(i2);
                            FileLog.d("root dir " + i2 + " " + file5);
                            if (file5.getAbsolutePath().startsWith(SharedConfig.storageCacheDir)) {
                                externalStorageDirectory = file5;
                                break;
                            }
                            i2++;
                        }
                    }
                    if (!externalStorageDirectory.getAbsolutePath().startsWith(SharedConfig.storageCacheDir) && (externalFilesDirs = ApplicationLoader.applicationContext.getExternalFilesDirs(null)) != null) {
                        for (int i3 = 0; i3 < externalFilesDirs.length; i3++) {
                            if (externalFilesDirs[i3] != null) {
                                FileLog.d("dirsDebug " + i3 + " " + externalFilesDirs[i3]);
                            }
                        }
                    }
                }
                FileLog.d("external storage = " + externalStorageDirectory);
                if (Build.VERSION.SDK_INT >= 30) {
                    try {
                        if (ApplicationLoader.applicationContext.getExternalMediaDirs().length > 0) {
                            File publicStorageDir = getPublicStorageDir();
                            try {
                                file = new File(publicStorageDir, "Telegram");
                                try {
                                    file.mkdirs();
                                } catch (Exception e2) {
                                    e = e2;
                                    FileLog.e(e);
                                    this.telegramPath = new File(ApplicationLoader.applicationContext.getExternalFilesDir(null), "Telegram");
                                    file4 = file;
                                    this.telegramPath.mkdirs();
                                    if (Build.VERSION.SDK_INT >= 19) {
                                        ArrayList<File> dataDirs = AndroidUtilities.getDataDirs();
                                        size = dataDirs.size();
                                        i = 0;
                                        while (true) {
                                            if (i >= size) {
                                            }
                                            i++;
                                        }
                                    }
                                    if (this.telegramPath.isDirectory()) {
                                    }
                                    if (file4 != null) {
                                        try {
                                            file3 = new File(file4, "Telegram Images");
                                            file3.mkdir();
                                            if (file3.isDirectory()) {
                                                sparseArray.put(100, file3);
                                                if (BuildVars.LOGS_ENABLED) {
                                                }
                                            }
                                        } catch (Exception e3) {
                                            FileLog.e(e3);
                                        }
                                        try {
                                            file2 = new File(file4, "Telegram Video");
                                            file2.mkdir();
                                            if (file2.isDirectory()) {
                                                sparseArray.put(101, file2);
                                                if (BuildVars.LOGS_ENABLED) {
                                                }
                                            }
                                        } catch (Exception e4) {
                                            FileLog.e(e4);
                                        }
                                    }
                                    SharedConfig.checkSaveToGalleryFiles();
                                    return sparseArray;
                                }
                            } catch (Exception e5) {
                                file = publicStorageDir;
                                e = e5;
                            }
                        } else {
                            file = null;
                        }
                    } catch (Exception e6) {
                        e = e6;
                        file = null;
                    }
                    this.telegramPath = new File(ApplicationLoader.applicationContext.getExternalFilesDir(null), "Telegram");
                    file4 = file;
                } else {
                    if (!(!TextUtils.isEmpty(SharedConfig.storageCacheDir) && externalStorageDirectory.getAbsolutePath().startsWith(SharedConfig.storageCacheDir))) {
                        if (externalStorageDirectory.exists()) {
                            if (externalStorageDirectory.isDirectory()) {
                            }
                            FileLog.d("can't write to this directory = " + externalStorageDirectory + " use files dir");
                            externalStorageDirectory = ApplicationLoader.applicationContext.getExternalFilesDir(null);
                        }
                    }
                    this.telegramPath = new File(externalStorageDirectory, "Telegram");
                }
                this.telegramPath.mkdirs();
                if (Build.VERSION.SDK_INT >= 19 && !this.telegramPath.isDirectory()) {
                    ArrayList<File> dataDirs2 = AndroidUtilities.getDataDirs();
                    size = dataDirs2.size();
                    i = 0;
                    while (true) {
                        if (i >= size) {
                            break;
                        }
                        File file6 = dataDirs2.get(i);
                        if (file6 != null && !TextUtils.isEmpty(SharedConfig.storageCacheDir) && file6.getAbsolutePath().startsWith(SharedConfig.storageCacheDir)) {
                            File file7 = new File(file6, "Telegram");
                            this.telegramPath = file7;
                            file7.mkdirs();
                            break;
                        }
                        i++;
                    }
                }
                if (this.telegramPath.isDirectory()) {
                    try {
                        File file8 = new File(this.telegramPath, "Telegram Images");
                        file8.mkdir();
                        if (file8.isDirectory() && canMoveFiles(cacheDir, file8, 0)) {
                            sparseArray.put(0, file8);
                            if (BuildVars.LOGS_ENABLED) {
                                FileLog.d("image path = " + file8);
                            }
                        }
                    } catch (Exception e7) {
                        FileLog.e(e7);
                    }
                    try {
                        File file9 = new File(this.telegramPath, "Telegram Video");
                        file9.mkdir();
                        if (file9.isDirectory() && canMoveFiles(cacheDir, file9, 2)) {
                            sparseArray.put(2, file9);
                            if (BuildVars.LOGS_ENABLED) {
                                FileLog.d("video path = " + file9);
                            }
                        }
                    } catch (Exception e8) {
                        FileLog.e(e8);
                    }
                    try {
                        File file10 = new File(this.telegramPath, "Telegram Audio");
                        file10.mkdir();
                        if (file10.isDirectory() && canMoveFiles(cacheDir, file10, 1)) {
                            AndroidUtilities.createEmptyFile(new File(file10, ".nomedia"));
                            sparseArray.put(1, file10);
                            if (BuildVars.LOGS_ENABLED) {
                                FileLog.d("audio path = " + file10);
                            }
                        }
                    } catch (Exception e9) {
                        FileLog.e(e9);
                    }
                    try {
                        File file11 = new File(this.telegramPath, "Telegram Documents");
                        file11.mkdir();
                        if (file11.isDirectory() && canMoveFiles(cacheDir, file11, 3)) {
                            AndroidUtilities.createEmptyFile(new File(file11, ".nomedia"));
                            sparseArray.put(3, file11);
                            if (BuildVars.LOGS_ENABLED) {
                                FileLog.d("documents path = " + file11);
                            }
                        }
                    } catch (Exception e10) {
                        FileLog.e(e10);
                    }
                    try {
                        File file12 = new File(this.telegramPath, "Telegram Files");
                        file12.mkdir();
                        if (file12.isDirectory() && canMoveFiles(cacheDir, file12, 5)) {
                            AndroidUtilities.createEmptyFile(new File(file12, ".nomedia"));
                            sparseArray.put(5, file12);
                            if (BuildVars.LOGS_ENABLED) {
                                FileLog.d("files path = " + file12);
                            }
                        }
                    } catch (Exception e11) {
                        FileLog.e(e11);
                    }
                    try {
                        File file13 = new File(this.telegramPath, "Telegram Stories");
                        file13.mkdir();
                        if (file13.isDirectory() && canMoveFiles(cacheDir, file13, 6)) {
                            AndroidUtilities.createEmptyFile(new File(file13, ".nomedia"));
                            sparseArray.put(6, file13);
                            if (BuildVars.LOGS_ENABLED) {
                                FileLog.d("stories path = " + file13);
                            }
                        }
                    } catch (Exception e12) {
                        FileLog.e(e12);
                    }
                }
                if (file4 != null && file4.isDirectory()) {
                    file3 = new File(file4, "Telegram Images");
                    file3.mkdir();
                    if (file3.isDirectory() && canMoveFiles(cacheDir, file3, 0)) {
                        sparseArray.put(100, file3);
                        if (BuildVars.LOGS_ENABLED) {
                            FileLog.d("image path = " + file3);
                        }
                    }
                    file2 = new File(file4, "Telegram Video");
                    file2.mkdir();
                    if (file2.isDirectory() && canMoveFiles(cacheDir, file2, 2)) {
                        sparseArray.put(101, file2);
                        if (BuildVars.LOGS_ENABLED) {
                            FileLog.d("video path = " + file2);
                        }
                    }
                }
            } else if (BuildVars.LOGS_ENABLED) {
                FileLog.d("this Android can't rename files");
            }
            SharedConfig.checkSaveToGalleryFiles();
        } catch (Exception e13) {
            FileLog.e(e13);
        }
        return sparseArray;
    }

    private File getPublicStorageDir() {
        File file = ApplicationLoader.applicationContext.getExternalMediaDirs()[0];
        if (!TextUtils.isEmpty(SharedConfig.storageCacheDir)) {
            for (int i = 0; i < ApplicationLoader.applicationContext.getExternalMediaDirs().length; i++) {
                File file2 = ApplicationLoader.applicationContext.getExternalMediaDirs()[i];
                if (file2 != null && file2.getPath().startsWith(SharedConfig.storageCacheDir)) {
                    file = ApplicationLoader.applicationContext.getExternalMediaDirs()[i];
                }
            }
        }
        return file;
    }

    private boolean canMoveFiles(File file, File file2, int i) {
        File file3;
        File file4;
        byte[] bArr;
        RandomAccessFile randomAccessFile;
        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[1024];
                file3.createNewFile();
                randomAccessFile = new RandomAccessFile(file3, "rws");
            } catch (Throwable th) {
                th = th;
            }
        } 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;
            randomAccessFile2 = randomAccessFile;
            if (randomAccessFile2 != null) {
                try {
                    randomAccessFile2.close();
                } catch (Exception e4) {
                    FileLog.e(e4);
                }
            }
            throw th;
        }
    }

    public Float getFileProgress(String str) {
        long[] jArr;
        if (str == null || (jArr = this.fileProgresses.get(str)) == null) {
            return null;
        }
        if (jArr[1] == 0) {
            return Float.valueOf(0.0f);
        }
        return Float.valueOf(Math.min(1.0f, ((float) jArr[0]) / ((float) jArr[1])));
    }

    public long[] getFileProgressSizes(String str) {
        if (str == null) {
            return null;
        }
        return this.fileProgresses.get(str);
    }

    public String getReplacedKey(String str) {
        if (str == null) {
            return null;
        }
        return this.replacedBitmaps.get(str);
    }

    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);
            boolean z = false;
            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()) {
                    z = true;
                }
            }
            if (!z) {
                this.ignoreRemoval = str;
                lruCache.remove(str);
                lruCache.put(str2, bitmapDrawable);
                this.ignoreRemoval = null;
            } else {
                lruCache.remove(str);
            }
        }
        Integer num = this.bitmapUseCounts.get(str);
        if (num != null) {
            this.bitmapUseCounts.put(str2, num);
            this.bitmapUseCounts.remove(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 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 void removeImage(String str) {
        this.bitmapUseCounts.remove(str);
        this.memCache.remove(str);
        this.smallImagesMemCache.remove(str);
    }

    public boolean isInMemCache(String str, boolean z) {
        return z ? getFromLottieCache(str) != null : getFromMemCache(str) != null;
    }

    public void clearMemory() {
        this.smallImagesMemCache.evictAll();
        this.memCache.evictAll();
        this.lottieMemCache.evictAll();
    }

    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 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 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 void cancelLoadingForImageReceiver(final ImageReceiver imageReceiver, final boolean z) {
        if (imageReceiver == null) {
            return;
        }
        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 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 BitmapDrawable getImageFromMemory(TLObject tLObject, String str, String str2) {
        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 tLRPC$FileLocation = (TLRPC$FileLocation) tLObject;
            str3 = tLRPC$FileLocation.volume_id + "_" + tLRPC$FileLocation.local_id;
        } else if (tLObject instanceof TLRPC$Document) {
            TLRPC$Document tLRPC$Document = (TLRPC$Document) tLObject;
            str3 = tLRPC$Document.dc_id + "_" + tLRPC$Document.id;
        } else if (tLObject instanceof SecureDocument) {
            SecureDocument secureDocument = (SecureDocument) tLObject;
            str3 = secureDocument.secureFile.dc_id + "_" + secureDocument.secureFile.id;
        } else if (tLObject instanceof WebFile) {
            str3 = Utilities.MD5(((WebFile) tLObject).url);
        }
        if (str2 != null) {
            str3 = str3 + "@" + str2;
        }
        return getFromMemCache(str3);
    }

    public void lambda$replaceImageInCache$5(String str, String str2, ImageLocation imageLocation) {
        ArrayList<String> filterKeys;
        for (int i = 0; i < 2; i++) {
            if (i == 0) {
                filterKeys = this.memCache.getFilterKeys(str);
            } else {
                filterKeys = 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);
            }
        }
    }

    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);
        }
    }

    public void putImageToCache(BitmapDrawable bitmapDrawable, String str, boolean z) {
        if (z) {
            this.smallImagesMemCache.put(str, bitmapDrawable);
        } else {
            this.memCache.put(str, bitmapDrawable);
        }
    }

    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 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 lambda$cancelForceLoadingForImageReceiver$6(String str) {
        this.forceLoadingImages.remove(str);
    }

    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 void lambda$createLoadOperationForImageReceiver$7(int i, String str, String str2, int i2, ImageReceiver imageReceiver, int i3, String str3, int i4, ImageLocation imageLocation, boolean z, Object obj, int i5, TLRPC$Document tLRPC$Document, boolean z2, boolean z3, String str4, int i6, long j) {
        int i7;
        String str5;
        boolean z4;
        boolean z5;
        String str6;
        int i8;
        String str7;
        int i9;
        int i10;
        int i11;
        File file;
        int i12;
        boolean z6;
        int i13;
        String str8;
        File file2;
        File file3;
        File file4;
        File file5;
        int i14;
        String str9;
        int i15;
        int i16;
        int i17;
        String str10;
        String str11;
        long j2;
        String str12;
        String str13;
        File file6;
        File file7;
        String str14;
        int i18;
        int i19;
        int i20;
        CacheImage cacheImage;
        CacheImage cacheImage2;
        int i21;
        boolean z7;
        int i22;
        boolean z8;
        TLRPC$Document tLRPC$Document2 = tLRPC$Document;
        if (i != 2) {
            CacheImage cacheImage3 = this.imageLoadingByUrl.get(str);
            CacheImage cacheImage4 = this.imageLoadingByKeys.get(str2);
            CacheImage cacheImage5 = this.imageLoadingByTag.get(i2);
            if (cacheImage5 != null) {
                if (cacheImage5 == cacheImage4) {
                    cacheImage5.setImageReceiverGuid(imageReceiver, i3);
                    cacheImage = cacheImage3;
                    cacheImage2 = cacheImage4;
                    str5 = str4;
                    z5 = true;
                    i21 = 2;
                    z4 = 0;
                } else if (cacheImage5 == cacheImage3) {
                    cacheImage = cacheImage3;
                    if (cacheImage4 == null) {
                        z8 = false;
                        cacheImage2 = cacheImage4;
                        i22 = 2;
                        str5 = str4;
                        cacheImage5.replaceImageReceiver(imageReceiver, str2, str3, i4, i3);
                    } else {
                        cacheImage2 = cacheImage4;
                        str5 = str4;
                        i22 = 2;
                        z8 = false;
                    }
                    i21 = i22;
                    z5 = true;
                    z4 = z8;
                } else {
                    cacheImage = cacheImage3;
                    cacheImage2 = cacheImage4;
                    str5 = str4;
                    i21 = 2;
                    z7 = false;
                    cacheImage5.removeImageReceiver(imageReceiver);
                }
                if (!z5 || cacheImage2 == null) {
                    i7 = i21;
                } else {
                    i7 = i21;
                    cacheImage2.addImageReceiver(imageReceiver, str2, str3, i4, i3);
                    z5 = true;
                }
                if (!z5 && cacheImage != null) {
                    cacheImage.addImageReceiver(imageReceiver, str2, str3, i4, i3);
                    z5 = true;
                }
            } else {
                cacheImage = cacheImage3;
                cacheImage2 = cacheImage4;
                str5 = str4;
                i21 = 2;
                z7 = false;
            }
            z5 = z7 ? 1 : 0;
            z4 = z7;
            if (z5) {
            }
            i7 = i21;
            if (!z5) {
                cacheImage.addImageReceiver(imageReceiver, str2, str3, i4, i3);
                z5 = true;
            }
        } else {
            i7 = 2;
            str5 = str4;
            z4 = 0;
            z5 = false;
        }
        if (z5) {
            return;
        }
        String str15 = imageLocation.path;
        if (str15 != null) {
            if (str15.startsWith("http") || str15.startsWith("athumb")) {
                i9 = z4;
                file = null;
            } else if (str15.startsWith("thumb://")) {
                int indexOf = str15.indexOf(":", 8);
                if (indexOf >= 0) {
                    file = new File(str15.substring(indexOf + 1));
                    i9 = 1;
                }
                file = null;
                i9 = 1;
            } else {
                if (str15.startsWith("vthumb://")) {
                    int indexOf2 = str15.indexOf(":", 9);
                    if (indexOf2 >= 0) {
                        file = new File(str15.substring(indexOf2 + 1));
                    }
                    file = null;
                } else {
                    file = new File(str15);
                }
                i9 = 1;
            }
            str6 = "athumb";
            i11 = i7;
            i10 = z4;
            i8 = 1;
            str7 = str3;
        } else {
            if (i == 0 && z) {
                if (obj instanceof MessageObject) {
                    MessageObject messageObject = (MessageObject) obj;
                    TLRPC$Document document = messageObject.getDocument();
                    String str16 = messageObject.messageOwner.attachPath;
                    file2 = FileLoader.getInstance(i5).getPathToMessage(messageObject.messageOwner);
                    str8 = str16;
                    i13 = messageObject.getMediaType();
                    tLRPC$Document2 = document;
                    z6 = z4;
                    i12 = 1;
                } else if (tLRPC$Document2 != null) {
                    i12 = 1;
                    File pathToAttach = FileLoader.getInstance(i5).getPathToAttach(tLRPC$Document2, true);
                    int i23 = MessageObject.isVideoDocument(tLRPC$Document) ? 2 : 3;
                    file2 = pathToAttach;
                    str8 = null;
                    i13 = i23;
                    z6 = true;
                } else {
                    i12 = 1;
                    z6 = z4;
                    i13 = z6 ? 1 : 0;
                    str8 = null;
                    file2 = null;
                    tLRPC$Document2 = null;
                }
                if (tLRPC$Document2 != null) {
                    if (z2) {
                        File directory = FileLoader.getDirectory(4);
                        str6 = "athumb";
                        StringBuilder sb = new StringBuilder();
                        file3 = file2;
                        sb.append("q_");
                        sb.append(tLRPC$Document2.dc_id);
                        sb.append("_");
                        sb.append(tLRPC$Document2.id);
                        sb.append(".jpg");
                        file4 = new File(directory, sb.toString());
                        if (file4.exists()) {
                            i10 = 1;
                            if (!TextUtils.isEmpty(str8)) {
                                file5 = new File(str8);
                            }
                            file5 = null;
                            File file8 = file5 != null ? file3 : file5;
                            if (file4 != null) {
                                String attachFileName = FileLoader.getAttachFileName(tLRPC$Document2);
                                ThumbGenerateInfo thumbGenerateInfo = this.waitingForQualityThumb.get(attachFileName);
                                if (thumbGenerateInfo == null) {
                                    thumbGenerateInfo = new ThumbGenerateInfo();
                                    thumbGenerateInfo.parentDocument = tLRPC$Document2;
                                    thumbGenerateInfo.filter = str3;
                                    thumbGenerateInfo.big = z6;
                                    this.waitingForQualityThumb.put(attachFileName, thumbGenerateInfo);
                                }
                                if (!thumbGenerateInfo.imageReceiverArray.contains(imageReceiver)) {
                                    thumbGenerateInfo.imageReceiverArray.add(imageReceiver);
                                    thumbGenerateInfo.imageReceiverGuidsArray.add(Integer.valueOf(i3));
                                }
                                this.waitingForQualityThumbByTag.put(i2, attachFileName);
                                if (file8.exists() && z3) {
                                    generateThumb(i13, file8, thumbGenerateInfo);
                                    return;
                                }
                                return;
                            }
                            str7 = str3;
                            i8 = 1;
                            file = file4;
                            i9 = 1;
                            i11 = 2;
                        }
                    } else {
                        str6 = "athumb";
                        file3 = file2;
                    }
                    i10 = z4;
                    file4 = null;
                    if (!TextUtils.isEmpty(str8)) {
                    }
                    file5 = null;
                    if (file5 != null) {
                    }
                    if (file4 != null) {
                    }
                } else {
                    i8 = i12;
                    str6 = "athumb";
                    str7 = str3;
                    i9 = i8;
                    i10 = z4;
                }
            } else {
                str6 = "athumb";
                i8 = 1;
                str7 = str3;
                i9 = z4;
                i10 = i9;
            }
            i11 = 2;
            file = null;
        }
        if (i != i11) {
            boolean isEncrypted = imageLocation.isEncrypted();
            CacheImage cacheImage6 = new CacheImage();
            cacheImage6.priority = imageReceiver.getFileLoadingPriority() == 0 ? z4 : i8;
            if (!z) {
                if (imageLocation.imageType != i11) {
                    if (MessageObject.isGifDocument(imageLocation.webFile) || MessageObject.isGifDocument(imageLocation.document) || MessageObject.isRoundVideoDocument(imageLocation.document) || MessageObject.isVideoSticker(imageLocation.document)) {
                        i11 = 2;
                    } else {
                        String str17 = imageLocation.path;
                        if (str17 != null && !str17.startsWith("vthumb") && !str17.startsWith("thumb")) {
                            String httpUrlExtension = getHttpUrlExtension(str17, "jpg");
                            if (httpUrlExtension.equals("webm") || httpUrlExtension.equals("mp4") || httpUrlExtension.equals("gif")) {
                                cacheImage6.imageType = 2;
                            } else if ("tgs".equals(str5)) {
                                cacheImage6.imageType = 1;
                            }
                        }
                    }
                }
                cacheImage6.imageType = i11;
            }
            if (file == null) {
                TLRPC$PhotoSize tLRPC$PhotoSize = imageLocation.photoSize;
                int i24 = i9;
                if ((tLRPC$PhotoSize instanceof TLRPC$TL_photoStrippedSize) || (tLRPC$PhotoSize instanceof TLRPC$TL_photoPathSize)) {
                    i14 = i6;
                    str11 = AUTOPLAY_FILTER;
                    str9 = str7;
                    i10 = i10;
                    j2 = 0;
                    i15 = 1;
                } else {
                    SecureDocument secureDocument = imageLocation.secureDocument;
                    if (secureDocument != null) {
                        cacheImage6.secureDocument = secureDocument;
                        int i25 = secureDocument.secureFile.dc_id == Integer.MIN_VALUE ? 1 : z4;
                        file = new File(FileLoader.getDirectory(4), str);
                        i14 = i6;
                        i15 = i25;
                        str9 = str7;
                        j2 = 0;
                        str11 = AUTOPLAY_FILTER;
                    } else {
                        int i26 = i10;
                        if (AUTOPLAY_FILTER.equals(str7) || isAnimatedAvatar(str7)) {
                            i14 = i6;
                            str12 = AUTOPLAY_FILTER;
                            str13 = "_";
                        } else {
                            i14 = i6;
                            str12 = AUTOPLAY_FILTER;
                            if (i14 == 0) {
                                str13 = "_";
                                if (j > 0) {
                                    if (imageLocation.path == null) {
                                    }
                                }
                            }
                            File file9 = new File(FileLoader.getDirectory(4), str);
                            if (file9.exists()) {
                                i19 = 1;
                            } else {
                                if (i14 == 2) {
                                    file9 = new File(FileLoader.getDirectory(4), str + ".enc");
                                }
                                i19 = i26;
                            }
                            TLRPC$Document tLRPC$Document3 = imageLocation.document;
                            if (tLRPC$Document3 != null) {
                                if (tLRPC$Document3 instanceof DocumentObject.ThemeDocument) {
                                    if (((DocumentObject.ThemeDocument) tLRPC$Document3).wallpaper == null) {
                                        i20 = 5;
                                        i15 = 1;
                                    } else {
                                        i15 = i24;
                                        i20 = 5;
                                    }
                                    cacheImage6.imageType = i20;
                                    str11 = str12;
                                    i10 = i19;
                                    file = file9;
                                    str9 = str7;
                                    j2 = 0;
                                } else if ("application/x-tgsdice".equals(tLRPC$Document3.mime_type)) {
                                    cacheImage6.imageType = 1;
                                    i10 = i19;
                                    file = file9;
                                    i15 = 1;
                                    str9 = str7;
                                    j2 = 0;
                                    str11 = str12;
                                } else if ("application/x-tgsticker".equals(imageLocation.document.mime_type)) {
                                    cacheImage6.imageType = 1;
                                } else if ("application/x-tgwallpattern".equals(imageLocation.document.mime_type)) {
                                    cacheImage6.imageType = 3;
                                } else if (FileLoader.getDocumentFileName(imageLocation.document).endsWith(".svg")) {
                                    cacheImage6.imageType = 3;
                                }
                            }
                            i15 = i24;
                            str11 = str12;
                            i10 = i19;
                            file = file9;
                            str9 = str7;
                            j2 = 0;
                        }
                        TLRPC$Document tLRPC$Document4 = imageLocation.document;
                        if (tLRPC$Document4 != null) {
                            if (tLRPC$Document4 instanceof TLRPC$TL_documentEncrypted) {
                                file7 = new File(FileLoader.getDirectory(4), str);
                            } else if (MessageObject.isVideoDocument(tLRPC$Document4)) {
                                file7 = new File(FileLoader.getDirectory(2), str);
                            } else {
                                file7 = new File(FileLoader.getDirectory(3), str);
                            }
                            if (isAnimatedAvatar(str7)) {
                                str14 = str12;
                            } else {
                                str14 = str12;
                            }
                            if (!file7.exists()) {
                                File directory2 = FileLoader.getDirectory(4);
                                StringBuilder sb2 = new StringBuilder();
                                str12 = str14;
                                sb2.append(tLRPC$Document4.dc_id);
                                sb2.append(str13);
                                sb2.append(tLRPC$Document4.id);
                                sb2.append(".temp");
                                file7 = new File(directory2, sb2.toString());
                                if (!(tLRPC$Document4 instanceof DocumentObject.ThemeDocument)) {
                                    if (((DocumentObject.ThemeDocument) tLRPC$Document4).wallpaper == null) {
                                        i18 = 5;
                                        i15 = 1;
                                    } else {
                                        i15 = i24;
                                        i18 = 5;
                                    }
                                    cacheImage6.imageType = i18;
                                } else if ("application/x-tgsdice".equals(imageLocation.document.mime_type)) {
                                    cacheImage6.imageType = 1;
                                    i15 = 1;
                                } else {
                                    if ("application/x-tgsticker".equals(tLRPC$Document4.mime_type)) {
                                        cacheImage6.imageType = 1;
                                    } else if ("application/x-tgwallpattern".equals(tLRPC$Document4.mime_type)) {
                                        cacheImage6.imageType = 3;
                                    } else if (FileLoader.getDocumentFileName(imageLocation.document).endsWith(".svg")) {
                                        cacheImage6.imageType = 3;
                                    }
                                    i15 = i24;
                                    file = file7;
                                    j2 = tLRPC$Document4.size;
                                    str9 = str3;
                                    i10 = i26;
                                    str11 = str12;
                                }
                                file = file7;
                                j2 = tLRPC$Document4.size;
                                str9 = str3;
                                i10 = i26;
                                str11 = str12;
                            }
                            str12 = str14;
                            if (!(tLRPC$Document4 instanceof DocumentObject.ThemeDocument)) {
                            }
                            file = file7;
                            j2 = tLRPC$Document4.size;
                            str9 = str3;
                            i10 = i26;
                            str11 = str12;
                        } else {
                            String str18 = str13;
                            if (imageLocation.webFile != null) {
                                file = new File(FileLoader.getDirectory(3), str);
                                i15 = i24;
                                str9 = str3;
                                i10 = i26;
                                str11 = str12;
                            } else {
                                if (i14 == 1) {
                                    file6 = new File(FileLoader.getDirectory(4), str);
                                } else {
                                    file6 = new File(FileLoader.getDirectory(z4), str);
                                }
                                str9 = str3;
                                file = file6;
                                if (isAnimatedAvatar(str9)) {
                                    str11 = str12;
                                } else {
                                    str11 = str12;
                                    if (str11.equals(str9)) {
                                        if (imageLocation.location != null) {
                                        }
                                    }
                                    i15 = i24;
                                    i10 = i26;
                                }
                                file = new File(FileLoader.getDirectory(4), imageLocation.location.volume_id + str18 + imageLocation.location.local_id + ".temp");
                                i15 = i24;
                                i10 = i26;
                            }
                            j2 = 0;
                        }
                    }
                }
                if (hasAutoplayFilter(str3) || isAnimatedAvatar(str9)) {
                    cacheImage6.imageType = 2;
                    cacheImage6.size = j2;
                    cacheImage6.isPFrame = isPFrame(str9);
                    if (str11.equals(str9) || isAnimatedAvatar(str9)) {
                        i16 = i4;
                        i17 = i10;
                        i15 = 1;
                    }
                }
                i16 = i4;
                i17 = i10;
            } else {
                i14 = i6;
                str9 = str7;
                i15 = i9;
                i16 = i4;
                i17 = i10;
            }
            cacheImage6.type = i16;
            cacheImage6.key = str2;
            cacheImage6.cacheType = i14;
            cacheImage6.filter = str9;
            cacheImage6.imageLocation = imageLocation;
            cacheImage6.ext = str4;
            cacheImage6.currentAccount = i5;
            cacheImage6.parentObject = obj;
            int i27 = imageLocation.imageType;
            if (i27 != 0) {
                cacheImage6.imageType = i27;
            }
            if (i14 == 2) {
                File internalCacheDir = FileLoader.getInternalCacheDir();
                StringBuilder sb3 = new StringBuilder();
                str10 = str;
                sb3.append(str10);
                sb3.append(".enc.key");
                cacheImage6.encryptionKeyPath = new File(internalCacheDir, sb3.toString());
            } else {
                str10 = str;
            }
            String str19 = str6;
            cacheImage6.addImageReceiver(imageReceiver, str2, str3, i4, i3);
            if (i15 != 0 || i17 != 0 || file.exists()) {
                cacheImage6.finalFilePath = file;
                cacheImage6.imageLocation = imageLocation;
                cacheImage6.cacheTask = new CacheOutTask(cacheImage6);
                this.imageLoadingByKeys.put(str2, cacheImage6);
                if (i != 0) {
                    this.cacheThumbOutQueue.postRunnable(cacheImage6.cacheTask);
                    return;
                } else {
                    cacheImage6.runningTask = this.cacheOutQueue.postRunnable(cacheImage6.cacheTask, cacheImage6.priority);
                    return;
                }
            }
            cacheImage6.url = str10;
            this.imageLoadingByUrl.put(str10, cacheImage6);
            if (cacheImage6.isPFrame) {
                this.imageLoadingByUrlPframe.put(str10, cacheImage6);
            }
            String str20 = imageLocation.path;
            if (str20 != null) {
                String MD5 = Utilities.MD5(str20);
                cacheImage6.tempFilePath = new File(FileLoader.getDirectory(4), MD5 + "_temp.jpg");
                cacheImage6.finalFilePath = file;
                if (imageLocation.path.startsWith(str19)) {
                    ArtworkLoadTask artworkLoadTask = new ArtworkLoadTask(cacheImage6);
                    cacheImage6.artworkTask = artworkLoadTask;
                    this.artworkTasks.add(artworkLoadTask);
                    runArtworkTasks(z4);
                    return;
                }
                HttpImageTask httpImageTask = new HttpImageTask(cacheImage6, j);
                cacheImage6.httpTask = httpImageTask;
                this.httpTasks.add(httpImageTask);
                runHttpTasks(z4);
                return;
            }
            int i28 = z4;
            int fileLoadingPriority = i != 0 ? 3 : imageReceiver.getFileLoadingPriority();
            if (imageLocation.location != null) {
                FileLoader.getInstance(i5).loadFile(imageLocation, obj, str4, fileLoadingPriority, (i14 != 0 || (j > 0 && imageLocation.key == null)) ? i14 : 1);
            } else if (imageLocation.document != null) {
                FileLoader.getInstance(i5).loadFile(imageLocation.document, obj, fileLoadingPriority, i14);
            } else if (imageLocation.secureDocument != null) {
                FileLoader.getInstance(i5).loadFile(imageLocation.secureDocument, fileLoadingPriority);
            } else if (imageLocation.webFile != null) {
                FileLoader.getInstance(i5).loadFile(imageLocation.webFile, fileLoadingPriority, i14);
            }
            if (imageReceiver.isForceLoding()) {
                this.forceLoadingImages.put(cacheImage6.key, Integer.valueOf(i28));
            }
        }
    }

    public void preloadArtwork(final String str) {
        this.imageLoadQueue.postRunnable(new Runnable() {
            @Override
            public final void run() {
                ImageLoader.this.lambda$preloadArtwork$8(str);
            }
        });
    }

    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 loadImageForImageReceiver(ImageReceiver imageReceiver) {
        loadImageForImageReceiver(imageReceiver, null);
    }

    public void loadImageForImageReceiver(ImageReceiver imageReceiver, List<ImageReceiver> list) {
        boolean z;
        boolean z2;
        String imageKey;
        boolean z3;
        String thumbKey;
        boolean z4;
        Object parentObject;
        ImageLocation thumbLocation;
        ImageLocation mediaLocation;
        ImageLocation imageLocation;
        ImageLocation imageLocation2;
        boolean z5;
        String ext;
        ImageLocation imageLocation3;
        String str;
        String str2;
        int i;
        String str3;
        ImageLocation imageLocation4;
        String str4;
        int i2;
        String str5;
        String str6;
        String str7;
        String str8;
        String str9;
        String str10;
        String str11;
        ImageLocation imageLocation5;
        String str12;
        int i3;
        String str13;
        ImageLocation imageLocation6;
        boolean z6;
        ImageLocation imageLocation7;
        ImageLocation imageLocation8;
        String str14;
        String str15;
        String str16;
        BitmapDrawable bitmapDrawable;
        Drawable findInPreloadImageReceivers;
        BitmapDrawable bitmapDrawable2;
        boolean hasBitmap;
        BitmapDrawable bitmapDrawable3;
        if (imageReceiver == null) {
            return;
        }
        String mediaKey = imageReceiver.getMediaKey();
        int newGuid = imageReceiver.getNewGuid();
        if (mediaKey != null) {
            ImageLocation mediaLocation2 = imageReceiver.getMediaLocation();
            Drawable findInPreloadImageReceivers2 = findInPreloadImageReceivers(mediaKey, list);
            if (findInPreloadImageReceivers2 == null) {
                if (useLottieMemCache(mediaLocation2, mediaKey)) {
                    bitmapDrawable3 = getFromLottieCache(mediaKey);
                } else {
                    bitmapDrawable3 = this.memCache.get(mediaKey);
                    if (bitmapDrawable3 != null) {
                        this.memCache.moveToFront(mediaKey);
                    }
                    if (bitmapDrawable3 == null && (bitmapDrawable3 = this.smallImagesMemCache.get(mediaKey)) != null) {
                        this.smallImagesMemCache.moveToFront(mediaKey);
                    }
                    if (bitmapDrawable3 == null && (bitmapDrawable3 = this.wallpaperMemCache.get(mediaKey)) != null) {
                        this.wallpaperMemCache.moveToFront(mediaKey);
                    }
                }
                findInPreloadImageReceivers2 = bitmapDrawable3;
            }
            if (findInPreloadImageReceivers2 instanceof RLottieDrawable) {
                hasBitmap = ((RLottieDrawable) findInPreloadImageReceivers2).hasBitmap();
            } else {
                hasBitmap = findInPreloadImageReceivers2 instanceof AnimatedFileDrawable ? ((AnimatedFileDrawable) findInPreloadImageReceivers2).hasBitmap() : true;
            }
            if (hasBitmap && findInPreloadImageReceivers2 != null) {
                cancelLoadingForImageReceiver(imageReceiver, true);
                imageReceiver.setImageBitmapByKey(findInPreloadImageReceivers2, mediaKey, 3, true, newGuid);
                if (!imageReceiver.isForcePreview()) {
                    return;
                }
                z2 = false;
                z = true;
            } else if (findInPreloadImageReceivers2 != null) {
                imageReceiver.setImageBitmapByKey(findInPreloadImageReceivers2, mediaKey, 3, true, newGuid);
                z = false;
                z2 = true;
            }
            imageKey = imageReceiver.getImageKey();
            if (!z && imageKey != null) {
                ImageLocation imageLocation9 = imageReceiver.getImageLocation();
                findInPreloadImageReceivers = findInPreloadImageReceivers(imageKey, list);
                if (findInPreloadImageReceivers == null && useLottieMemCache(imageLocation9, imageKey)) {
                    findInPreloadImageReceivers = getFromLottieCache(imageKey);
                }
                if (findInPreloadImageReceivers != null) {
                    bitmapDrawable2 = this.memCache.get(imageKey);
                    if (bitmapDrawable2 != null) {
                        this.memCache.moveToFront(imageKey);
                    }
                    if (bitmapDrawable2 == null && (bitmapDrawable2 = this.smallImagesMemCache.get(imageKey)) != null) {
                        this.smallImagesMemCache.moveToFront(imageKey);
                    }
                    if (bitmapDrawable2 == null && (bitmapDrawable2 = this.wallpaperMemCache.get(imageKey)) != null) {
                        this.wallpaperMemCache.moveToFront(imageKey);
                    }
                } else {
                    bitmapDrawable2 = findInPreloadImageReceivers;
                }
                if (bitmapDrawable2 != null) {
                    cancelLoadingForImageReceiver(imageReceiver, true);
                    imageReceiver.setImageBitmapByKey(bitmapDrawable2, imageKey, 0, true, newGuid);
                    if (!imageReceiver.isForcePreview() && (mediaKey == null || z2)) {
                        return;
                    }
                    z3 = true;
                    thumbKey = imageReceiver.getThumbKey();
                    if (thumbKey != null) {
                        if (useLottieMemCache(imageReceiver.getThumbLocation(), thumbKey)) {
                            bitmapDrawable = getFromLottieCache(thumbKey);
                        } else {
                            bitmapDrawable = this.memCache.get(thumbKey);
                            if (bitmapDrawable != null) {
                                this.memCache.moveToFront(thumbKey);
                            }
                            if (bitmapDrawable == null && (bitmapDrawable = this.smallImagesMemCache.get(thumbKey)) != null) {
                                this.smallImagesMemCache.moveToFront(thumbKey);
                            }
                            if (bitmapDrawable == null && (bitmapDrawable = this.wallpaperMemCache.get(thumbKey)) != null) {
                                this.wallpaperMemCache.moveToFront(thumbKey);
                            }
                        }
                        BitmapDrawable bitmapDrawable4 = bitmapDrawable;
                        if (bitmapDrawable4 != null) {
                            imageReceiver.setImageBitmapByKey(bitmapDrawable4, thumbKey, 1, true, newGuid);
                            cancelLoadingForImageReceiver(imageReceiver, false);
                            if (z3 && imageReceiver.isForcePreview()) {
                                return;
                            }
                            z4 = true;
                            parentObject = imageReceiver.getParentObject();
                            TLRPC$Document qualityThumbDocument = imageReceiver.getQualityThumbDocument();
                            thumbLocation = imageReceiver.getThumbLocation();
                            String thumbFilter = imageReceiver.getThumbFilter();
                            mediaLocation = imageReceiver.getMediaLocation();
                            String mediaFilter = imageReceiver.getMediaFilter();
                            imageLocation = imageReceiver.getImageLocation();
                            String imageFilter = imageReceiver.getImageFilter();
                            if (imageLocation == null && imageReceiver.isNeedsQualityThumb() && imageReceiver.isCurrentKeyQuality()) {
                                if (!(parentObject instanceof MessageObject)) {
                                    imageLocation2 = ImageLocation.getForDocument(((MessageObject) parentObject).getDocument());
                                } else if (qualityThumbDocument != null) {
                                    imageLocation2 = ImageLocation.getForDocument(qualityThumbDocument);
                                }
                                z5 = true;
                                String str17 = null;
                                String str18 = (imageLocation2 == null && imageLocation2.imageType == 2) ? "mp4" : null;
                                ImageLocation imageLocation10 = imageLocation2;
                                String str19 = (mediaLocation == null && mediaLocation.imageType == 2) ? "mp4" : null;
                                ext = imageReceiver.getExt();
                                if (ext == null) {
                                    ext = "jpg";
                                }
                                String str20 = str18 != null ? ext : str18;
                                String str21 = str19 != null ? ext : str19;
                                ImageLocation imageLocation11 = imageLocation10;
                                imageLocation3 = mediaLocation;
                                str = null;
                                str2 = null;
                                String str22 = null;
                                String str23 = null;
                                i = 0;
                                boolean z7 = false;
                                while (i < 2) {
                                    if (i == 0) {
                                        imageLocation6 = imageLocation11;
                                        i3 = newGuid;
                                        str13 = str20;
                                    } else {
                                        i3 = newGuid;
                                        str13 = str21;
                                        imageLocation6 = imageLocation3;
                                    }
                                    if (imageLocation6 == null) {
                                        z6 = z4;
                                        imageLocation8 = imageLocation11;
                                    } else {
                                        z6 = z4;
                                        if (imageLocation3 != null) {
                                            imageLocation8 = imageLocation11;
                                            imageLocation7 = imageLocation3;
                                        } else {
                                            imageLocation7 = imageLocation11;
                                            imageLocation8 = imageLocation7;
                                        }
                                        String key = imageLocation6.getKey(parentObject, imageLocation7, false);
                                        if (key != null) {
                                            str14 = thumbFilter;
                                            String key2 = imageLocation6.getKey(parentObject, imageLocation3 != null ? imageLocation3 : imageLocation8, true);
                                            if (imageLocation6.path != null) {
                                                key2 = key2 + "." + getHttpUrlExtension(imageLocation6.path, "jpg");
                                                str15 = imageFilter;
                                            } else {
                                                TLRPC$PhotoSize tLRPC$PhotoSize = imageLocation6.photoSize;
                                                str15 = imageFilter;
                                                if ((tLRPC$PhotoSize instanceof TLRPC$TL_photoStrippedSize) || (tLRPC$PhotoSize instanceof TLRPC$TL_photoPathSize)) {
                                                    key2 = key2 + "." + str13;
                                                } else if (imageLocation6.location != null) {
                                                    String str24 = key2 + "." + str13;
                                                    if (imageReceiver.getExt() == null) {
                                                        TLRPC$TL_fileLocationToBeDeprecated tLRPC$TL_fileLocationToBeDeprecated = imageLocation6.location;
                                                        if (tLRPC$TL_fileLocationToBeDeprecated.key == null) {
                                                            str16 = str24;
                                                            if (tLRPC$TL_fileLocationToBeDeprecated.volume_id != -2147483648L || tLRPC$TL_fileLocationToBeDeprecated.local_id >= 0) {
                                                                key2 = str16;
                                                            }
                                                            key2 = str16;
                                                            z7 = true;
                                                        }
                                                    }
                                                    str16 = str24;
                                                    key2 = str16;
                                                    z7 = true;
                                                } else {
                                                    WebFile webFile = imageLocation6.webFile;
                                                    if (webFile != null) {
                                                        key2 = key2 + "." + getHttpUrlExtension(imageLocation6.webFile.url, FileLoader.getMimeTypePart(webFile.mime_type));
                                                    } else if (imageLocation6.secureDocument != null) {
                                                        key2 = key2 + "." + str13;
                                                    } else if (imageLocation6.document != null) {
                                                        if (i == 0 && z5) {
                                                            key = "q_" + key;
                                                        }
                                                        String documentFileName = FileLoader.getDocumentFileName(imageLocation6.document);
                                                        int lastIndexOf = documentFileName.lastIndexOf(46);
                                                        String str25 = "";
                                                        String substring = lastIndexOf == -1 ? "" : documentFileName.substring(lastIndexOf);
                                                        if (substring.length() > 1) {
                                                            str25 = substring;
                                                        } else if ("video/mp4".equals(imageLocation6.document.mime_type)) {
                                                            str25 = ".mp4";
                                                        } else if ("video/x-matroska".equals(imageLocation6.document.mime_type)) {
                                                            str25 = ".mkv";
                                                        }
                                                        key2 = key2 + str25;
                                                        z7 = (MessageObject.isVideoDocument(imageLocation6.document) || MessageObject.isGifDocument(imageLocation6.document) || MessageObject.isRoundVideoDocument(imageLocation6.document) || MessageObject.canPreviewDocument(imageLocation6.document)) ? false : true;
                                                    }
                                                }
                                            }
                                            if (i == 0) {
                                                str = key;
                                                str22 = key2;
                                            } else {
                                                str2 = key;
                                                str23 = key2;
                                            }
                                            if (imageLocation6 == thumbLocation) {
                                                if (i == 0) {
                                                    str = null;
                                                    imageLocation11 = null;
                                                    str22 = null;
                                                    i++;
                                                    newGuid = i3;
                                                    z4 = z6;
                                                    thumbFilter = str14;
                                                    imageFilter = str15;
                                                } else {
                                                    str2 = null;
                                                    str23 = null;
                                                    imageLocation3 = null;
                                                }
                                            }
                                            imageLocation11 = imageLocation8;
                                            i++;
                                            newGuid = i3;
                                            z4 = z6;
                                            thumbFilter = str14;
                                            imageFilter = str15;
                                        }
                                    }
                                    str14 = thumbFilter;
                                    str15 = imageFilter;
                                    imageLocation11 = imageLocation8;
                                    i++;
                                    newGuid = i3;
                                    z4 = z6;
                                    thumbFilter = str14;
                                    imageFilter = str15;
                                }
                                boolean z8 = z4;
                                str3 = thumbFilter;
                                imageLocation4 = imageLocation11;
                                str4 = imageFilter;
                                int i4 = newGuid;
                                if (thumbLocation == null) {
                                    ImageLocation strippedLocation = imageReceiver.getStrippedLocation();
                                    if (strippedLocation == null) {
                                        strippedLocation = imageLocation3 != null ? imageLocation3 : imageLocation;
                                    }
                                    String key3 = thumbLocation.getKey(parentObject, strippedLocation, false);
                                    i2 = 1;
                                    String key4 = thumbLocation.getKey(parentObject, strippedLocation, true);
                                    if (thumbLocation.path != null) {
                                        key4 = key4 + "." + getHttpUrlExtension(thumbLocation.path, "jpg");
                                    } else {
                                        TLRPC$PhotoSize tLRPC$PhotoSize2 = thumbLocation.photoSize;
                                        if ((tLRPC$PhotoSize2 instanceof TLRPC$TL_photoStrippedSize) || (tLRPC$PhotoSize2 instanceof TLRPC$TL_photoPathSize)) {
                                            key4 = key4 + "." + ext;
                                        } else if (thumbLocation.location != null) {
                                            key4 = key4 + "." + ext;
                                        }
                                    }
                                    str17 = key4;
                                    str5 = key3;
                                } else {
                                    i2 = 1;
                                    str5 = null;
                                }
                                if (str2 != null && mediaFilter != null) {
                                    str2 = str2 + "@" + mediaFilter;
                                }
                                if (str != null || str4 == null) {
                                    str6 = str4;
                                } else {
                                    StringBuilder sb = new StringBuilder();
                                    sb.append(str);
                                    sb.append("@");
                                    str6 = str4;
                                    sb.append(str6);
                                    str = sb.toString();
                                }
                                if (str5 != null || str3 == null) {
                                    str7 = str3;
                                } else {
                                    StringBuilder sb2 = new StringBuilder();
                                    sb2.append(str5);
                                    sb2.append("@");
                                    str7 = str3;
                                    sb2.append(str7);
                                    str5 = sb2.toString();
                                }
                                String str26 = str5;
                                if (imageReceiver.getUniqKeyPrefix() != null || str == null) {
                                    str8 = str;
                                } else {
                                    str8 = imageReceiver.getUniqKeyPrefix() + str;
                                }
                                if (imageReceiver.getUniqKeyPrefix() != null || str2 == null) {
                                    str9 = str2;
                                } else {
                                    str9 = imageReceiver.getUniqKeyPrefix() + str2;
                                }
                                if (imageLocation4 != null) {
                                    str10 = ext;
                                    str11 = str6;
                                    imageLocation5 = imageLocation4;
                                } else if (imageLocation4.path != null) {
                                    createLoadOperationForImageReceiver(imageReceiver, str26, str17, ext, thumbLocation, str7, 0L, 1, 1, z8 ? 2 : i2, i4);
                                    createLoadOperationForImageReceiver(imageReceiver, str8, str22, str20, imageLocation4, str6, imageReceiver.getSize(), 1, 0, 0, i4);
                                    return;
                                } else {
                                    str10 = ext;
                                    imageLocation5 = imageLocation4;
                                    str11 = str6;
                                }
                                if (imageLocation3 == null) {
                                    int cacheType = imageReceiver.getCacheType();
                                    int i5 = (cacheType == 0 && z7) ? i2 : cacheType;
                                    int i6 = i5 == 0 ? i2 : i5;
                                    if (z8) {
                                        str12 = mediaFilter;
                                    } else {
                                        str12 = mediaFilter;
                                        createLoadOperationForImageReceiver(imageReceiver, str26, str17, str10, thumbLocation, str7, 0L, i6, 1, 1, i4);
                                    }
                                    if (!z3) {
                                        createLoadOperationForImageReceiver(imageReceiver, str8, str22, str20, imageLocation5, str11, 0L, 1, 0, 0, i4);
                                    }
                                    if (z2) {
                                        return;
                                    }
                                    createLoadOperationForImageReceiver(imageReceiver, str9, str23, str21, imageLocation3, str12, imageReceiver.getSize(), i5, 3, 0, i4);
                                    return;
                                }
                                int cacheType2 = imageReceiver.getCacheType();
                                int i7 = (cacheType2 == 0 && z7) ? i2 : cacheType2;
                                createLoadOperationForImageReceiver(imageReceiver, str26, str17, str10, thumbLocation, str7, 0L, i7 == 0 ? i2 : i7, 1, z8 ? 2 : i2, i4);
                                createLoadOperationForImageReceiver(imageReceiver, str8, str22, str20, imageLocation5, str11, imageReceiver.getSize(), i7, 0, 0, i4);
                                return;
                            }
                            imageLocation2 = imageLocation;
                            z5 = false;
                            String str172 = null;
                            if (imageLocation2 == null) {
                            }
                            ImageLocation imageLocation102 = imageLocation2;
                            if (mediaLocation == null) {
                            }
                            ext = imageReceiver.getExt();
                            if (ext == null) {
                            }
                            if (str18 != null) {
                            }
                            if (str19 != null) {
                            }
                            ImageLocation imageLocation112 = imageLocation102;
                            imageLocation3 = mediaLocation;
                            str = null;
                            str2 = null;
                            String str222 = null;
                            String str232 = null;
                            i = 0;
                            boolean z72 = false;
                            while (i < 2) {
                            }
                            boolean z82 = z4;
                            str3 = thumbFilter;
                            imageLocation4 = imageLocation112;
                            str4 = imageFilter;
                            int i42 = newGuid;
                            if (thumbLocation == null) {
                            }
                            if (str2 != null) {
                                str2 = str2 + "@" + mediaFilter;
                            }
                            if (str != null) {
                            }
                            str6 = str4;
                            if (str5 != null) {
                            }
                            str7 = str3;
                            String str262 = str5;
                            if (imageReceiver.getUniqKeyPrefix() != null) {
                            }
                            str8 = str;
                            if (imageReceiver.getUniqKeyPrefix() != null) {
                            }
                            str9 = str2;
                            if (imageLocation4 != null) {
                            }
                            if (imageLocation3 == null) {
                            }
                        }
                    }
                    z4 = false;
                    parentObject = imageReceiver.getParentObject();
                    TLRPC$Document qualityThumbDocument2 = imageReceiver.getQualityThumbDocument();
                    thumbLocation = imageReceiver.getThumbLocation();
                    String thumbFilter2 = imageReceiver.getThumbFilter();
                    mediaLocation = imageReceiver.getMediaLocation();
                    String mediaFilter2 = imageReceiver.getMediaFilter();
                    imageLocation = imageReceiver.getImageLocation();
                    String imageFilter2 = imageReceiver.getImageFilter();
                    if (imageLocation == null) {
                        if (!(parentObject instanceof MessageObject)) {
                        }
                        z5 = true;
                        String str1722 = null;
                        if (imageLocation2 == null) {
                        }
                        ImageLocation imageLocation1022 = imageLocation2;
                        if (mediaLocation == null) {
                        }
                        ext = imageReceiver.getExt();
                        if (ext == null) {
                        }
                        if (str18 != null) {
                        }
                        if (str19 != null) {
                        }
                        ImageLocation imageLocation1122 = imageLocation1022;
                        imageLocation3 = mediaLocation;
                        str = null;
                        str2 = null;
                        String str2222 = null;
                        String str2322 = null;
                        i = 0;
                        boolean z722 = false;
                        while (i < 2) {
                        }
                        boolean z822 = z4;
                        str3 = thumbFilter2;
                        imageLocation4 = imageLocation1122;
                        str4 = imageFilter2;
                        int i422 = newGuid;
                        if (thumbLocation == null) {
                        }
                        if (str2 != null) {
                        }
                        if (str != null) {
                        }
                        str6 = str4;
                        if (str5 != null) {
                        }
                        str7 = str3;
                        String str2622 = str5;
                        if (imageReceiver.getUniqKeyPrefix() != null) {
                        }
                        str8 = str;
                        if (imageReceiver.getUniqKeyPrefix() != null) {
                        }
                        str9 = str2;
                        if (imageLocation4 != null) {
                        }
                        if (imageLocation3 == null) {
                        }
                    }
                    imageLocation2 = imageLocation;
                    z5 = false;
                    String str17222 = null;
                    if (imageLocation2 == null) {
                    }
                    ImageLocation imageLocation10222 = imageLocation2;
                    if (mediaLocation == null) {
                    }
                    ext = imageReceiver.getExt();
                    if (ext == null) {
                    }
                    if (str18 != null) {
                    }
                    if (str19 != null) {
                    }
                    ImageLocation imageLocation11222 = imageLocation10222;
                    imageLocation3 = mediaLocation;
                    str = null;
                    str2 = null;
                    String str22222 = null;
                    String str23222 = null;
                    i = 0;
                    boolean z7222 = false;
                    while (i < 2) {
                    }
                    boolean z8222 = z4;
                    str3 = thumbFilter2;
                    imageLocation4 = imageLocation11222;
                    str4 = imageFilter2;
                    int i4222 = newGuid;
                    if (thumbLocation == null) {
                    }
                    if (str2 != null) {
                    }
                    if (str != null) {
                    }
                    str6 = str4;
                    if (str5 != null) {
                    }
                    str7 = str3;
                    String str26222 = str5;
                    if (imageReceiver.getUniqKeyPrefix() != null) {
                    }
                    str8 = str;
                    if (imageReceiver.getUniqKeyPrefix() != null) {
                    }
                    str9 = str2;
                    if (imageLocation4 != null) {
                    }
                    if (imageLocation3 == null) {
                    }
                }
            }
            z3 = z;
            thumbKey = imageReceiver.getThumbKey();
            if (thumbKey != null) {
            }
            z4 = false;
            parentObject = imageReceiver.getParentObject();
            TLRPC$Document qualityThumbDocument22 = imageReceiver.getQualityThumbDocument();
            thumbLocation = imageReceiver.getThumbLocation();
            String thumbFilter22 = imageReceiver.getThumbFilter();
            mediaLocation = imageReceiver.getMediaLocation();
            String mediaFilter22 = imageReceiver.getMediaFilter();
            imageLocation = imageReceiver.getImageLocation();
            String imageFilter22 = imageReceiver.getImageFilter();
            if (imageLocation == null) {
            }
            imageLocation2 = imageLocation;
            z5 = false;
            String str172222 = null;
            if (imageLocation2 == null) {
            }
            ImageLocation imageLocation102222 = imageLocation2;
            if (mediaLocation == null) {
            }
            ext = imageReceiver.getExt();
            if (ext == null) {
            }
            if (str18 != null) {
            }
            if (str19 != null) {
            }
            ImageLocation imageLocation112222 = imageLocation102222;
            imageLocation3 = mediaLocation;
            str = null;
            str2 = null;
            String str222222 = null;
            String str232222 = null;
            i = 0;
            boolean z72222 = false;
            while (i < 2) {
            }
            boolean z82222 = z4;
            str3 = thumbFilter22;
            imageLocation4 = imageLocation112222;
            str4 = imageFilter22;
            int i42222 = newGuid;
            if (thumbLocation == null) {
            }
            if (str2 != null) {
            }
            if (str != null) {
            }
            str6 = str4;
            if (str5 != null) {
            }
            str7 = str3;
            String str262222 = str5;
            if (imageReceiver.getUniqKeyPrefix() != null) {
            }
            str8 = str;
            if (imageReceiver.getUniqKeyPrefix() != null) {
            }
            str9 = str2;
            if (imageLocation4 != null) {
            }
            if (imageLocation3 == null) {
            }
        }
        z = false;
        z2 = false;
        imageKey = imageReceiver.getImageKey();
        if (!z) {
            ImageLocation imageLocation92 = imageReceiver.getImageLocation();
            findInPreloadImageReceivers = findInPreloadImageReceivers(imageKey, list);
            if (findInPreloadImageReceivers == null) {
                findInPreloadImageReceivers = getFromLottieCache(imageKey);
            }
            if (findInPreloadImageReceivers != null) {
            }
            if (bitmapDrawable2 != null) {
            }
        }
        z3 = z;
        thumbKey = imageReceiver.getThumbKey();
        if (thumbKey != null) {
        }
        z4 = false;
        parentObject = imageReceiver.getParentObject();
        TLRPC$Document qualityThumbDocument222 = imageReceiver.getQualityThumbDocument();
        thumbLocation = imageReceiver.getThumbLocation();
        String thumbFilter222 = imageReceiver.getThumbFilter();
        mediaLocation = imageReceiver.getMediaLocation();
        String mediaFilter222 = imageReceiver.getMediaFilter();
        imageLocation = imageReceiver.getImageLocation();
        String imageFilter222 = imageReceiver.getImageFilter();
        if (imageLocation == null) {
        }
        imageLocation2 = imageLocation;
        z5 = false;
        String str1722222 = null;
        if (imageLocation2 == null) {
        }
        ImageLocation imageLocation1022222 = imageLocation2;
        if (mediaLocation == null) {
        }
        ext = imageReceiver.getExt();
        if (ext == null) {
        }
        if (str18 != null) {
        }
        if (str19 != null) {
        }
        ImageLocation imageLocation1122222 = imageLocation1022222;
        imageLocation3 = mediaLocation;
        str = null;
        str2 = null;
        String str2222222 = null;
        String str2322222 = null;
        i = 0;
        boolean z722222 = false;
        while (i < 2) {
        }
        boolean z822222 = z4;
        str3 = thumbFilter222;
        imageLocation4 = imageLocation1122222;
        str4 = imageFilter222;
        int i422222 = newGuid;
        if (thumbLocation == null) {
        }
        if (str2 != null) {
        }
        if (str != null) {
        }
        str6 = str4;
        if (str5 != null) {
        }
        str7 = str3;
        String str2622222 = str5;
        if (imageReceiver.getUniqKeyPrefix() != null) {
        }
        str8 = str;
        if (imageReceiver.getUniqKeyPrefix() != null) {
        }
        str9 = str2;
        if (imageLocation4 != null) {
        }
        if (imageLocation3 == null) {
        }
    }

    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;
    }

    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;
    }

    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 boolean hasLottieMemCache(String str) {
        LruCache<BitmapDrawable> lruCache = this.lottieMemCache;
        return lruCache != null && lruCache.contains(str);
    }

    public void httpFileLoadError(final String str) {
        this.imageLoadQueue.postRunnable(new Runnable() {
            @Override
            public final void run() {
                ImageLoader.this.lambda$httpFileLoadError$9(str);
            }
        });
    }

    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 void artworkLoadError(final String str) {
        this.imageLoadQueue.postRunnable(new Runnable() {
            @Override
            public final void run() {
                ImageLoader.this.lambda$artworkLoadError$10(str);
            }
        });
    }

    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 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 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 = 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);
                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.cacheOutQueue.postRunnable(cacheOutTask, cacheOutTask.cacheImage.priority);
            } else {
                this.cacheThumbOutQueue.postRunnable(cacheOutTask);
            }
        }
    }

    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 lambda$fileDidFailedLoad$12(String str) {
        CacheImage cacheImage = this.imageLoadingByUrl.get(str);
        if (cacheImage != null) {
            cacheImage.setImageAndClear(null, null);
        }
    }

    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 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 boolean isLoadingHttpFile(String str) {
        return this.httpFileLoadTasksByKeys.containsKey(str);
    }

    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 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 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 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 lambda$runHttpFileLoadTasks$14(HttpFileTask httpFileTask, int i) {
        if (httpFileTask != null) {
            this.currentHttpFileLoadTasksCount--;
        }
        if (httpFileTask != null) {
            if (i == 1) {
                if (!httpFileTask.canRetry) {
                    this.httpFileLoadTasksByKeys.remove(httpFileTask.url);
                    NotificationCenter.getInstance(httpFileTask.currentAccount).lambda$postNotificationNameOnUIThread$1(NotificationCenter.httpFileDidFailedLoad, httpFileTask.url, 0);
                } else {
                    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 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 void lambda$runHttpFileLoadTasks$13(HttpFileTask httpFileTask) {
        this.httpFileLoadTasks.add(httpFileTask);
        runHttpFileLoadTasks(null, 0);
    }

    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 static Bitmap loadBitmap(String str, Uri uri, float f, float f2, boolean z) {
        String str2;
        InputStream openInputStream;
        float max;
        int i;
        Matrix matrix;
        float f3;
        Bitmap decodeStream;
        Bitmap createBitmap;
        Bitmap createBitmap2;
        Pair<Integer, Integer> imageOrientation;
        InputStream inputStream;
        String path;
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        if (str == null && uri != null && uri.getScheme() != null) {
            if (uri.getScheme().contains("file")) {
                path = uri.getPath();
            } else if (Build.VERSION.SDK_INT < 30 || !"content".equals(uri.getScheme())) {
                try {
                    path = AndroidUtilities.getPath(uri);
                } catch (Throwable th) {
                    FileLog.e(th);
                }
            }
            str2 = path;
            Bitmap bitmap = null;
            if (str2 == null) {
                BitmapFactory.decodeFile(str2, options);
            } else if (uri != null) {
                try {
                    InputStream openInputStream2 = ApplicationLoader.applicationContext.getContentResolver().openInputStream(uri);
                    BitmapFactory.decodeStream(openInputStream2, null, options);
                    openInputStream2.close();
                    openInputStream = ApplicationLoader.applicationContext.getContentResolver().openInputStream(uri);
                    float f4 = options.outWidth / f;
                    float f5 = options.outHeight / f2;
                    max = z ? Math.max(f4, f5) : Math.min(f4, f5);
                    if (max < 1.0f) {
                        max = 1.0f;
                    }
                    options.inJustDecodeBounds = false;
                    i = (int) max;
                    options.inSampleSize = i;
                    if (i % 2 != 0) {
                        int i2 = 1;
                        while (true) {
                            int i3 = i2 * 2;
                            if (i3 >= options.inSampleSize) {
                                break;
                            }
                            i2 = i3;
                        }
                        options.inSampleSize = i2;
                    }
                    options.inPurgeable = Build.VERSION.SDK_INT < 21;
                    imageOrientation = AndroidUtilities.getImageOrientation(str2);
                    if (((Integer) imageOrientation.first).intValue() == 0 && ((Integer) imageOrientation.second).intValue() == 0) {
                        try {
                            inputStream = ApplicationLoader.applicationContext.getContentResolver().openInputStream(uri);
                        } catch (Throwable unused) {
                            inputStream = null;
                        }
                        try {
                            imageOrientation = AndroidUtilities.getImageOrientation(inputStream);
                        } catch (Throwable unused2) {
                            if (inputStream != null) {
                                inputStream.close();
                            }
                            if (((Integer) imageOrientation.first).intValue() == 0) {
                            }
                            matrix = new Matrix();
                            if (((Integer) imageOrientation.second).intValue() != 0) {
                            }
                            if (((Integer) imageOrientation.first).intValue() != 0) {
                            }
                            f3 = max / options.inSampleSize;
                            if (f3 > 1.0f) {
                            }
                            if (str2 != null) {
                            }
                        }
                    }
                    if (((Integer) imageOrientation.first).intValue() == 0) {
                        if (((Integer) imageOrientation.second).intValue() == 0) {
                        }
                        matrix = null;
                        f3 = max / options.inSampleSize;
                        if (f3 > 1.0f) {
                            if (matrix == null) {
                                matrix = new Matrix();
                            }
                            float f6 = 1.0f / f3;
                            matrix.postScale(f6, f6);
                        }
                        if (str2 != null) {
                            try {
                                bitmap = BitmapFactory.decodeFile(str2, options);
                            } catch (Throwable th2) {
                                FileLog.e(th2);
                                getInstance().clearMemory();
                                if (bitmap == null) {
                                    try {
                                        bitmap = BitmapFactory.decodeFile(str2, options);
                                        if (bitmap != null && options.inPurgeable) {
                                            Utilities.pinBitmap(bitmap);
                                        }
                                    } catch (Throwable th3) {
                                        FileLog.e(th3);
                                        return bitmap;
                                    }
                                }
                                if (bitmap == null) {
                                    return bitmap;
                                }
                                createBitmap2 = Bitmaps.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
                                if (createBitmap2 == bitmap) {
                                    return bitmap;
                                }
                                bitmap.recycle();
                            }
                            if (bitmap == null) {
                                return bitmap;
                            }
                            if (options.inPurgeable) {
                                Utilities.pinBitmap(bitmap);
                            }
                            createBitmap2 = Bitmaps.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
                            if (createBitmap2 == bitmap) {
                                return bitmap;
                            }
                            bitmap.recycle();
                            return createBitmap2;
                        }
                        try {
                        } catch (Throwable th4) {
                            FileLog.e(th4);
                        }
                        if (uri == null) {
                            return null;
                        }
                        try {
                            decodeStream = BitmapFactory.decodeStream(openInputStream, null, options);
                        } catch (Throwable th5) {
                            th = th5;
                        }
                        if (decodeStream != null) {
                            try {
                                if (options.inPurgeable) {
                                    Utilities.pinBitmap(decodeStream);
                                }
                                createBitmap = Bitmaps.createBitmap(decodeStream, 0, 0, decodeStream.getWidth(), decodeStream.getHeight(), matrix, true);
                            } catch (Throwable th6) {
                                th = th6;
                                bitmap = decodeStream;
                                try {
                                    FileLog.e(th);
                                    openInputStream.close();
                                    return bitmap;
                                } finally {
                                }
                            }
                            if (createBitmap != decodeStream) {
                                decodeStream.recycle();
                                bitmap = createBitmap;
                                openInputStream.close();
                                return bitmap;
                            }
                        }
                        bitmap = decodeStream;
                        openInputStream.close();
                        return bitmap;
                    }
                    matrix = new Matrix();
                    if (((Integer) imageOrientation.second).intValue() != 0) {
                        float f7 = -1.0f;
                        float f8 = ((Integer) imageOrientation.second).intValue() == 1 ? -1.0f : 1.0f;
                        if (((Integer) imageOrientation.second).intValue() != 2) {
                            f7 = 1.0f;
                        }
                        matrix.postScale(f8, f7);
                    }
                    if (((Integer) imageOrientation.first).intValue() != 0) {
                        matrix.postRotate(((Integer) imageOrientation.first).intValue());
                    }
                    f3 = max / options.inSampleSize;
                    if (f3 > 1.0f) {
                    }
                    if (str2 != null) {
                    }
                } catch (Throwable th7) {
                    FileLog.e(th7);
                    return null;
                }
            }
            openInputStream = null;
            float f42 = options.outWidth / f;
            float f52 = options.outHeight / f2;
            if (z) {
            }
            if (max < 1.0f) {
            }
            options.inJustDecodeBounds = false;
            i = (int) max;
            options.inSampleSize = i;
            if (i % 2 != 0) {
            }
            options.inPurgeable = Build.VERSION.SDK_INT < 21;
            imageOrientation = AndroidUtilities.getImageOrientation(str2);
            if (((Integer) imageOrientation.first).intValue() == 0) {
                inputStream = ApplicationLoader.applicationContext.getContentResolver().openInputStream(uri);
                imageOrientation = AndroidUtilities.getImageOrientation(inputStream);
            }
            if (((Integer) imageOrientation.first).intValue() == 0) {
            }
            matrix = new Matrix();
            if (((Integer) imageOrientation.second).intValue() != 0) {
            }
            if (((Integer) imageOrientation.first).intValue() != 0) {
            }
            f3 = max / options.inSampleSize;
            if (f3 > 1.0f) {
            }
            if (str2 != null) {
            }
        }
        str2 = str;
        Bitmap bitmap2 = null;
        if (str2 == null) {
        }
        openInputStream = null;
        float f422 = options.outWidth / f;
        float f522 = options.outHeight / f2;
        if (z) {
        }
        if (max < 1.0f) {
        }
        options.inJustDecodeBounds = false;
        i = (int) max;
        options.inSampleSize = i;
        if (i % 2 != 0) {
        }
        options.inPurgeable = Build.VERSION.SDK_INT < 21;
        imageOrientation = AndroidUtilities.getImageOrientation(str2);
        if (((Integer) imageOrientation.first).intValue() == 0) {
        }
        if (((Integer) imageOrientation.first).intValue() == 0) {
        }
        matrix = new Matrix();
        if (((Integer) imageOrientation.second).intValue() != 0) {
        }
        if (((Integer) imageOrientation.first).intValue() != 0) {
        }
        f3 = max / options.inSampleSize;
        if (f3 > 1.0f) {
        }
        if (str2 != null) {
        }
    }

    public static void fillPhotoSizeWithBytes(TLRPC$PhotoSize tLRPC$PhotoSize) {
        if (tLRPC$PhotoSize != null) {
            byte[] bArr = tLRPC$PhotoSize.bytes;
            if (bArr == null || bArr.length == 0) {
                try {
                    RandomAccessFile randomAccessFile = new RandomAccessFile(FileLoader.getInstance(UserConfig.selectedAccount).getPathToAttach(tLRPC$PhotoSize, true), "r");
                    if (((int) randomAccessFile.length()) < 20000) {
                        byte[] bArr2 = new byte[(int) randomAccessFile.length()];
                        tLRPC$PhotoSize.bytes = bArr2;
                        randomAccessFile.readFully(bArr2, 0, bArr2.length);
                    }
                } catch (Throwable th) {
                    FileLog.e(th);
                }
            }
        }
    }

    private static TLRPC$PhotoSize scaleAndSaveImageInternal(TLRPC$PhotoSize tLRPC$PhotoSize, Bitmap bitmap, Bitmap.CompressFormat compressFormat, boolean z, int i, int i2, float f, float f2, float f3, int i3, boolean z2, boolean z3, boolean z4) throws Exception {
        TLRPC$TL_fileLocationToBeDeprecated tLRPC$TL_fileLocationToBeDeprecated;
        File directory;
        Bitmap createScaledBitmap = (f3 > 1.0f || z3) ? Bitmaps.createScaledBitmap(bitmap, i, i2, true) : bitmap;
        if (tLRPC$PhotoSize != null) {
            TLRPC$FileLocation tLRPC$FileLocation = tLRPC$PhotoSize.location;
            if (tLRPC$FileLocation instanceof TLRPC$TL_fileLocationToBeDeprecated) {
                tLRPC$TL_fileLocationToBeDeprecated = (TLRPC$TL_fileLocationToBeDeprecated) tLRPC$FileLocation;
                String str = tLRPC$TL_fileLocationToBeDeprecated.volume_id + "_" + tLRPC$TL_fileLocationToBeDeprecated.local_id + ".jpg";
                if (z4) {
                    directory = tLRPC$TL_fileLocationToBeDeprecated.volume_id != -2147483648L ? FileLoader.getDirectory(0) : FileLoader.getDirectory(4);
                } else {
                    directory = FileLoader.getDirectory(4);
                }
                FileOutputStream fileOutputStream = new FileOutputStream(new File(directory, str));
                createScaledBitmap.compress(compressFormat, i3, fileOutputStream);
                if (!z2) {
                    tLRPC$PhotoSize.size = (int) fileOutputStream.getChannel().size();
                }
                fileOutputStream.close();
                if (z2) {
                    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
                    createScaledBitmap.compress(compressFormat, i3, byteArrayOutputStream);
                    byte[] byteArray = byteArrayOutputStream.toByteArray();
                    tLRPC$PhotoSize.bytes = byteArray;
                    tLRPC$PhotoSize.size = byteArray.length;
                    byteArrayOutputStream.close();
                }
                if (createScaledBitmap != bitmap) {
                    createScaledBitmap.recycle();
                }
                return tLRPC$PhotoSize;
            }
        }
        tLRPC$TL_fileLocationToBeDeprecated = new TLRPC$TL_fileLocationToBeDeprecated();
        tLRPC$TL_fileLocationToBeDeprecated.volume_id = -2147483648L;
        tLRPC$TL_fileLocationToBeDeprecated.dc_id = Integer.MIN_VALUE;
        tLRPC$TL_fileLocationToBeDeprecated.local_id = SharedConfig.getLastLocalId();
        tLRPC$TL_fileLocationToBeDeprecated.file_reference = new byte[0];
        tLRPC$PhotoSize = new TLRPC$TL_photoSize_layer127();
        tLRPC$PhotoSize.location = tLRPC$TL_fileLocationToBeDeprecated;
        tLRPC$PhotoSize.w = createScaledBitmap.getWidth();
        int height = createScaledBitmap.getHeight();
        tLRPC$PhotoSize.h = height;
        int i4 = tLRPC$PhotoSize.w;
        if (i4 <= 100 && height <= 100) {
            tLRPC$PhotoSize.type = "s";
        } else if (i4 <= 320 && height <= 320) {
            tLRPC$PhotoSize.type = "m";
        } else if (i4 <= 800 && height <= 800) {
            tLRPC$PhotoSize.type = "x";
        } else if (i4 <= 1280 && height <= 1280) {
            tLRPC$PhotoSize.type = "y";
        } else {
            tLRPC$PhotoSize.type = "w";
        }
        String str2 = tLRPC$TL_fileLocationToBeDeprecated.volume_id + "_" + tLRPC$TL_fileLocationToBeDeprecated.local_id + ".jpg";
        if (z4) {
        }
        FileOutputStream fileOutputStream2 = new FileOutputStream(new File(directory, str2));
        createScaledBitmap.compress(compressFormat, i3, fileOutputStream2);
        if (!z2) {
        }
        fileOutputStream2.close();
        if (z2) {
        }
        if (createScaledBitmap != bitmap) {
        }
        return tLRPC$PhotoSize;
    }

    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(TLRPC$PhotoSize tLRPC$PhotoSize, Bitmap bitmap, float f, float f2, int i, boolean z, boolean z2) {
        return scaleAndSaveImage(tLRPC$PhotoSize, bitmap, Bitmap.CompressFormat.JPEG, false, f, f2, i, z, 0, 0, z2);
    }

    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 tLRPC$PhotoSize, Bitmap bitmap, Bitmap.CompressFormat compressFormat, boolean z, float f, float f2, int i, boolean z2, int i2, int i3, boolean z3) {
        boolean z4;
        float f3;
        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;
                    }
                    z4 = true;
                    f3 = max;
                    i4 = (int) (width / f3);
                    i5 = (int) (height / f3);
                    if (i5 != 0 && i4 != 0) {
                        try {
                            return scaleAndSaveImageInternal(tLRPC$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(tLRPC$PhotoSize, bitmap, compressFormat, z, i4, i5, width, height, f3, i, z2, z4, z3);
                            } catch (Throwable th2) {
                                FileLog.e(th2);
                            }
                        }
                    }
                }
            }
            z4 = false;
            f3 = max2;
            i4 = (int) (width / f3);
            i5 = (int) (height / f3);
            if (i5 != 0) {
                return scaleAndSaveImageInternal(tLRPC$PhotoSize, bitmap, compressFormat, z, i4, i5, width, height, f3, i, z2, z4, z3);
            }
        }
        return null;
    }

    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 void saveMessageThumbs(TLRPC$Message tLRPC$Message) {
        TLRPC$PhotoSize findPhotoCachedSize;
        byte[] bArr;
        TLRPC$PhotoSize tLRPC$TL_photoSize_layer127;
        if (tLRPC$Message.media == null || (findPhotoCachedSize = findPhotoCachedSize(tLRPC$Message)) == null || (bArr = findPhotoCachedSize.bytes) == null || bArr.length == 0) {
            return;
        }
        TLRPC$FileLocation tLRPC$FileLocation = findPhotoCachedSize.location;
        if (tLRPC$FileLocation == null || (tLRPC$FileLocation instanceof TLRPC$TL_fileLocationUnavailable)) {
            TLRPC$TL_fileLocationToBeDeprecated tLRPC$TL_fileLocationToBeDeprecated = new TLRPC$TL_fileLocationToBeDeprecated();
            findPhotoCachedSize.location = tLRPC$TL_fileLocationToBeDeprecated;
            tLRPC$TL_fileLocationToBeDeprecated.volume_id = -2147483648L;
            tLRPC$TL_fileLocationToBeDeprecated.local_id = SharedConfig.getLastLocalId();
        }
        int i = 0;
        if (findPhotoCachedSize.h <= 50 && findPhotoCachedSize.w <= 50) {
            tLRPC$TL_photoSize_layer127 = new TLRPC$TL_photoStrippedSize();
            tLRPC$TL_photoSize_layer127.location = findPhotoCachedSize.location;
            tLRPC$TL_photoSize_layer127.bytes = findPhotoCachedSize.bytes;
            tLRPC$TL_photoSize_layer127.h = findPhotoCachedSize.h;
            tLRPC$TL_photoSize_layer127.w = findPhotoCachedSize.w;
        } else {
            boolean z = true;
            File pathToAttach = FileLoader.getInstance(UserConfig.selectedAccount).getPathToAttach(findPhotoCachedSize, true);
            if (MessageObject.shouldEncryptPhotoOrVideo(UserConfig.selectedAccount, tLRPC$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) {
                            randomAccessFile.read(bArr2, 0, 32);
                            randomAccessFile.read(bArr3, 0, 16);
                        } else {
                            Utilities.random.nextBytes(bArr2);
                            Utilities.random.nextBytes(bArr3);
                            randomAccessFile.write(bArr2);
                            randomAccessFile.write(bArr3);
                        }
                        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();
            }
            tLRPC$TL_photoSize_layer127 = new TLRPC$TL_photoSize_layer127();
            tLRPC$TL_photoSize_layer127.w = findPhotoCachedSize.w;
            tLRPC$TL_photoSize_layer127.h = findPhotoCachedSize.h;
            tLRPC$TL_photoSize_layer127.location = findPhotoCachedSize.location;
            tLRPC$TL_photoSize_layer127.size = findPhotoCachedSize.size;
            tLRPC$TL_photoSize_layer127.type = findPhotoCachedSize.type;
        }
        TLRPC$MessageMedia tLRPC$MessageMedia = tLRPC$Message.media;
        if (tLRPC$MessageMedia instanceof TLRPC$TL_messageMediaPhoto) {
            int size = tLRPC$MessageMedia.photo.sizes.size();
            while (i < size) {
                if (tLRPC$Message.media.photo.sizes.get(i) instanceof TLRPC$TL_photoCachedSize) {
                    tLRPC$Message.media.photo.sizes.set(i, tLRPC$TL_photoSize_layer127);
                    return;
                }
                i++;
            }
            return;
        }
        if (tLRPC$MessageMedia instanceof TLRPC$TL_messageMediaDocument) {
            int size2 = tLRPC$MessageMedia.document.thumbs.size();
            while (i < size2) {
                if (tLRPC$Message.media.document.thumbs.get(i) instanceof TLRPC$TL_photoCachedSize) {
                    tLRPC$Message.media.document.thumbs.set(i, tLRPC$TL_photoSize_layer127);
                    return;
                }
                i++;
            }
            return;
        }
        if (tLRPC$MessageMedia instanceof TLRPC$TL_messageMediaWebPage) {
            int size3 = tLRPC$MessageMedia.webpage.photo.sizes.size();
            while (i < size3) {
                if (tLRPC$Message.media.webpage.photo.sizes.get(i) instanceof TLRPC$TL_photoCachedSize) {
                    tLRPC$Message.media.webpage.photo.sizes.set(i, tLRPC$TL_photoSize_layer127);
                    return;
                }
                i++;
            }
        }
    }

    private static TLRPC$PhotoSize findPhotoCachedSize(TLRPC$Message tLRPC$Message) {
        TLRPC$PhotoSize tLRPC$PhotoSize;
        TLRPC$MessageMedia tLRPC$MessageMedia = tLRPC$Message.media;
        int i = 0;
        if (tLRPC$MessageMedia instanceof TLRPC$TL_messageMediaPhoto) {
            int size = tLRPC$MessageMedia.photo.sizes.size();
            while (i < size) {
                tLRPC$PhotoSize = tLRPC$Message.media.photo.sizes.get(i);
                if (!(tLRPC$PhotoSize instanceof TLRPC$TL_photoCachedSize)) {
                    i++;
                }
            }
            return null;
        }
        if (tLRPC$MessageMedia instanceof TLRPC$TL_messageMediaDocument) {
            TLRPC$Document tLRPC$Document = tLRPC$MessageMedia.document;
            if (tLRPC$Document == null) {
                return null;
            }
            int size2 = tLRPC$Document.thumbs.size();
            while (i < size2) {
                tLRPC$PhotoSize = tLRPC$Message.media.document.thumbs.get(i);
                if (!(tLRPC$PhotoSize instanceof TLRPC$TL_photoCachedSize)) {
                    i++;
                }
            }
            return null;
        }
        if (tLRPC$MessageMedia instanceof TLRPC$TL_messageMediaWebPage) {
            TLRPC$Photo tLRPC$Photo = tLRPC$MessageMedia.webpage.photo;
            if (tLRPC$Photo == null) {
                return null;
            }
            int size3 = tLRPC$Photo.sizes.size();
            while (i < size3) {
                tLRPC$PhotoSize = tLRPC$Message.media.webpage.photo.sizes.get(i);
                if (!(tLRPC$PhotoSize instanceof TLRPC$TL_photoCachedSize)) {
                    i++;
                }
            }
            return null;
        }
        if (!(tLRPC$MessageMedia instanceof TLRPC$TL_messageMediaInvoice)) {
            return null;
        }
        TLRPC$MessageExtendedMedia tLRPC$MessageExtendedMedia = tLRPC$MessageMedia.extended_media;
        if (tLRPC$MessageExtendedMedia instanceof TLRPC$TL_messageExtendedMediaPreview) {
            return ((TLRPC$TL_messageExtendedMediaPreview) tLRPC$MessageExtendedMedia).thumb;
        }
        return null;
        return tLRPC$PhotoSize;
    }

    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 MessageThumb generateMessageThumb(TLRPC$Message tLRPC$Message) {
        int i;
        int i2;
        Bitmap strippedPhotoBitmap;
        byte[] bArr;
        TLRPC$PhotoSize findPhotoCachedSize = findPhotoCachedSize(tLRPC$Message);
        if (findPhotoCachedSize != null && (bArr = findPhotoCachedSize.bytes) != null && bArr.length != 0) {
            File pathToAttach = FileLoader.getInstance(UserConfig.selectedAccount).getPathToAttach(findPhotoCachedSize, true);
            TLRPC$TL_photoSize_layer127 tLRPC$TL_photoSize_layer127 = new TLRPC$TL_photoSize_layer127();
            tLRPC$TL_photoSize_layer127.w = findPhotoCachedSize.w;
            tLRPC$TL_photoSize_layer127.h = findPhotoCachedSize.h;
            tLRPC$TL_photoSize_layer127.location = findPhotoCachedSize.location;
            tLRPC$TL_photoSize_layer127.size = findPhotoCachedSize.size;
            tLRPC$TL_photoSize_layer127.type = findPhotoCachedSize.type;
            if (pathToAttach.exists() && tLRPC$Message.grouped_id == 0) {
                org.telegram.ui.Components.Point messageSize = ChatMessageCell.getMessageSize(findPhotoCachedSize.w, findPhotoCachedSize.h);
                String format = String.format(Locale.US, "%d_%d@%d_%d_b", Long.valueOf(findPhotoCachedSize.location.volume_id), Integer.valueOf(findPhotoCachedSize.location.local_id), Integer.valueOf((int) (messageSize.x / AndroidUtilities.density)), Integer.valueOf((int) (messageSize.y / AndroidUtilities.density)));
                if (!getInstance().isInMemCache(format, false)) {
                    String path = pathToAttach.getPath();
                    float f = messageSize.x;
                    float f2 = AndroidUtilities.density;
                    Bitmap loadBitmap = loadBitmap(path, null, (int) (f / f2), (int) (messageSize.y / f2), false);
                    if (loadBitmap != null) {
                        Utilities.blurBitmap(loadBitmap, 3, 1, loadBitmap.getWidth(), loadBitmap.getHeight(), loadBitmap.getRowBytes());
                        float f3 = messageSize.x;
                        float f4 = AndroidUtilities.density;
                        Bitmap createScaledBitmap = Bitmaps.createScaledBitmap(loadBitmap, (int) (f3 / f4), (int) (messageSize.y / f4), true);
                        if (createScaledBitmap != loadBitmap) {
                            loadBitmap.recycle();
                            loadBitmap = createScaledBitmap;
                        }
                        return new MessageThumb(format, new BitmapDrawable(loadBitmap));
                    }
                }
            }
        } else {
            TLRPC$MessageMedia tLRPC$MessageMedia = tLRPC$Message.media;
            if (tLRPC$MessageMedia instanceof TLRPC$TL_messageMediaDocument) {
                int size = tLRPC$MessageMedia.document.thumbs.size();
                for (int i3 = 0; i3 < size; i3++) {
                    TLRPC$PhotoSize tLRPC$PhotoSize = tLRPC$Message.media.document.thumbs.get(i3);
                    if (tLRPC$PhotoSize instanceof TLRPC$TL_photoStrippedSize) {
                        TLRPC$PhotoSize closestPhotoSizeWithSize = FileLoader.getClosestPhotoSizeWithSize(tLRPC$Message.media.document.thumbs, 320);
                        if (closestPhotoSizeWithSize == null) {
                            int i4 = 0;
                            while (true) {
                                if (i4 >= tLRPC$Message.media.document.attributes.size()) {
                                    i = 0;
                                    i2 = 0;
                                    break;
                                }
                                if (tLRPC$Message.media.document.attributes.get(i4) instanceof TLRPC$TL_documentAttributeVideo) {
                                    TLRPC$TL_documentAttributeVideo tLRPC$TL_documentAttributeVideo = (TLRPC$TL_documentAttributeVideo) tLRPC$Message.media.document.attributes.get(i4);
                                    i2 = tLRPC$TL_documentAttributeVideo.h;
                                    i = tLRPC$TL_documentAttributeVideo.w;
                                    break;
                                }
                                i4++;
                            }
                        } else {
                            i2 = closestPhotoSizeWithSize.h;
                            i = closestPhotoSizeWithSize.w;
                        }
                        org.telegram.ui.Components.Point messageSize2 = ChatMessageCell.getMessageSize(i, i2);
                        String format2 = String.format(Locale.US, "%s_false@%d_%d_b", ImageLocation.getStrippedKey(tLRPC$Message, tLRPC$Message, tLRPC$PhotoSize), Integer.valueOf((int) (messageSize2.x / AndroidUtilities.density)), Integer.valueOf((int) (messageSize2.y / AndroidUtilities.density)));
                        if (!getInstance().isInMemCache(format2, false) && (strippedPhotoBitmap = getStrippedPhotoBitmap(tLRPC$PhotoSize.bytes, null)) != null) {
                            Utilities.blurBitmap(strippedPhotoBitmap, 3, 1, strippedPhotoBitmap.getWidth(), strippedPhotoBitmap.getHeight(), strippedPhotoBitmap.getRowBytes());
                            float f5 = messageSize2.x;
                            float f6 = AndroidUtilities.density;
                            Bitmap createScaledBitmap2 = Bitmaps.createScaledBitmap(strippedPhotoBitmap, (int) (f5 / f6), (int) (messageSize2.y / f6), true);
                            if (createScaledBitmap2 != strippedPhotoBitmap) {
                                strippedPhotoBitmap.recycle();
                                strippedPhotoBitmap = createScaledBitmap2;
                            }
                            return new MessageThumb(format2, new BitmapDrawable(strippedPhotoBitmap));
                        }
                    }
                }
            }
        }
        return null;
    }

    public void onFragmentStackChanged() {
        for (int i = 0; i < this.cachedAnimatedFileDrawables.size(); i++) {
            this.cachedAnimatedFileDrawables.get(i).repeatCount = 0;
        }
    }

    public DispatchQueuePriority getCacheOutQueue() {
        return this.cacheOutQueue;
    }

    public static class MessageThumb {
        BitmapDrawable drawable;
        String key;

        public MessageThumb(String str, BitmapDrawable bitmapDrawable) {
            this.key = str;
            this.drawable = bitmapDrawable;
        }
    }
}