盛康基办.apk(点击下载) / ImageLoader.java


package im.guobwnxjuc.messenger;

import android.app.ActivityManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.media.ThumbnailUtils;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Environment;
import android.text.TextUtils;
import android.util.SparseArray;
import androidx.exifinterface.media.ExifInterface;
import com.google.android.exoplayer2.util.MimeTypes;
import com.king.zxing.util.LogUtils;
import im.guobwnxjuc.messenger.FileLoader;
import im.guobwnxjuc.messenger.ImageLoader;
import im.guobwnxjuc.tgnet.ConnectionsManager;
import im.guobwnxjuc.tgnet.TLObject;
import im.guobwnxjuc.tgnet.TLRPC;
import im.guobwnxjuc.ui.components.AnimatedFileDrawable;
import im.guobwnxjuc.ui.components.RLottieDrawable;
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.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.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.json.JSONArray;
import org.json.JSONObject;

public class ImageLoader {
    public static final String AUTOPLAY_FILTER = "g";
    private static volatile ImageLoader Instance = null;
    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 File appPath;
    private LinkedList<ArtworkLoadTask> artworkTasks = new LinkedList<>();
    private HashMap<String, Integer> bitmapUseCounts = new HashMap<>();
    private DispatchQueue cacheOutQueue = new DispatchQueue("cacheOutQueue");
    private DispatchQueue cacheThumbOutQueue = new DispatchQueue("cacheThumbOutQueue");
    private boolean canForce8888;
    private int currentArtworkTasksCount;
    private int currentHttpFileLoadTasksCount;
    private int currentHttpTasksCount;
    private ConcurrentHashMap<String, Float> fileProgresses = new ConcurrentHashMap<>();
    private HashMap<String, Integer> forceLoadingImages = new HashMap<>();
    private LinkedList<HttpFileTask> httpFileLoadTasks;
    private HashMap<String, HttpFileTask> httpFileLoadTasksByKeys;
    private LinkedList<HttpImageTask> httpTasks = new LinkedList<>();
    private String ignoreRemoval;
    private DispatchQueue imageLoadQueue = new DispatchQueue("imageLoadQueue");
    private HashMap<String, CacheImage> imageLoadingByKeys = new HashMap<>();
    private SparseArray<CacheImage> imageLoadingByTag = new SparseArray<>();
    private HashMap<String, CacheImage> imageLoadingByUrl = new HashMap<>();
    private volatile long lastCacheOutTime;
    private int lastImageNum;
    private long lastProgressUpdateTime;
    private LruCache<RLottieDrawable> lottieMemCache;
    private LruCache<BitmapDrawable> memCache;
    private HashMap<String, String> replacedBitmaps = new HashMap<>();
    private HashMap<String, Runnable> retryHttpsTasks;
    private ConcurrentHashMap<String, WebFile> testWebFile;
    private HashMap<String, ThumbGenerateTask> thumbGenerateTasks = new HashMap<>();
    private DispatchQueue thumbGeneratingQueue = new DispatchQueue("thumbGeneratingQueue");
    private HashMap<String, ThumbGenerateInfo> waitingForQualityThumb = new HashMap<>();
    private SparseArray<String> waitingForQualityThumbByTag = new SparseArray<>();

    /* access modifiers changed from: private */
    public 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<>();
        }
    }

    /* access modifiers changed from: private */
    public class HttpFileTask extends AsyncTask<Void, Void, Boolean> {
        private boolean canRetry = true;
        private int currentAccount;
        private String ext;
        private RandomAccessFile fileOutputStream = null;
        private int fileSize;
        private long lastProgressTime;
        private File tempFile;
        private String url;

        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(float f) {
            long currentTimeMillis = System.currentTimeMillis();
            if (f != 1.0f) {
                long j = this.lastProgressTime;
                if (j != 0 && j >= currentTimeMillis - 500) {
                    return;
                }
            }
            this.lastProgressTime = currentTimeMillis;
            Utilities.stageQueue.postRunnable(new Runnable(f) {
                /* class im.guobwnxjuc.messenger.$$Lambda$ImageLoader$HttpFileTask$H7NPyt6HL76xOpp4z96kE2cwg */
                private final /* synthetic */ float f$1;

                {
                    this.f$1 = r2;
                }

                public final void run() {
                    ImageLoader.HttpFileTask.this.lambda$reportProgress$1$ImageLoader$HttpFileTask(this.f$1);
                }
            });
        }

        public /* synthetic */ void lambda$reportProgress$1$ImageLoader$HttpFileTask(float f) {
            ImageLoader.this.fileProgresses.put(this.url, Float.valueOf(f));
            AndroidUtilities.runOnUIThread(new Runnable(f) {
                /* class im.guobwnxjuc.messenger.$$Lambda$ImageLoader$HttpFileTask$QVgQSAzWL6ZCrGAhJ42MmsbawO0 */
                private final /* synthetic */ float f$1;

                {
                    this.f$1 = r2;
                }

                public final void run() {
                    ImageLoader.HttpFileTask.this.lambda$null$0$ImageLoader$HttpFileTask(this.f$1);
                }
            });
        }

        public /* synthetic */ void lambda$null$0$ImageLoader$HttpFileTask(float f) {
            NotificationCenter.getInstance(this.currentAccount).postNotificationName(NotificationCenter.FileLoadProgressChanged, this.url, Float.valueOf(f));
        }

        /* access modifiers changed from: protected */
        /* JADX WARNING: Code restructure failed: missing block: B:81:0x0123, code lost:
            if (r5 != -1) goto L_0x0131;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:84:0x0127, code lost:
            if (r9.fileSize == 0) goto L_0x0140;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:85:0x0129, code lost:
            reportProgress(1.0f);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:86:0x012f, code lost:
            r0 = e;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:87:0x0131, code lost:
            r1 = false;
         */
        /* JADX WARNING: Removed duplicated region for block: B:100:0x0145 A[Catch:{ all -> 0x014d }] */
        /* JADX WARNING: Removed duplicated region for block: B:104:0x0153 A[SYNTHETIC, Splitter:B:104:0x0153] */
        /* JADX WARNING: Removed duplicated region for block: B:24:0x0076  */
        /* JADX WARNING: Removed duplicated region for block: B:27:0x007f  */
        /* JADX WARNING: Removed duplicated region for block: B:43:0x00ad A[SYNTHETIC, Splitter:B:43:0x00ad] */
        public Boolean doInBackground(Void... voidArr) {
            InputStream inputStream;
            URLConnection uRLConnection;
            Throwable th;
            List<String> list;
            String str;
            int responseCode;
            Throwable th2;
            InputStream inputStream2;
            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();
                    inputStream = uRLConnection.getInputStream();
                    try {
                        this.fileOutputStream = new RandomAccessFile(this.tempFile, "rws");
                    } catch (Throwable th3) {
                        inputStream2 = inputStream;
                        th2 = th3;
                    }
                } catch (Throwable th4) {
                    th2 = th4;
                    inputStream2 = null;
                    if (!(th2 instanceof SocketTimeoutException)) {
                        if (ApplicationLoader.isNetworkOnline()) {
                            this.canRetry = false;
                        }
                    } else if (th2 instanceof UnknownHostException) {
                        this.canRetry = false;
                    } else if (th2 instanceof SocketException) {
                        if (th2.getMessage() != null && th2.getMessage().contains("ECONNRESET")) {
                            this.canRetry = false;
                        }
                    } else if (th2 instanceof FileNotFoundException) {
                        this.canRetry = false;
                    }
                    FileLog.e(th2);
                    inputStream = inputStream2;
                    if (this.canRetry) {
                    }
                    return Boolean.valueOf(z2);
                }
            } catch (Throwable th5) {
                th2 = th5;
                inputStream2 = null;
                uRLConnection = null;
                if (!(th2 instanceof SocketTimeoutException)) {
                }
                FileLog.e(th2);
                inputStream = inputStream2;
                if (this.canRetry) {
                }
                return Boolean.valueOf(z2);
            }
            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(str).intValue();
                        }
                    } catch (Exception e2) {
                        FileLog.e(e2);
                    }
                }
                if (inputStream != null) {
                    try {
                        byte[] bArr = new byte[32768];
                        int i = 0;
                        while (true) {
                            if (isCancelled()) {
                                break;
                            }
                            try {
                                int read = inputStream.read(bArr);
                                if (read <= 0) {
                                    break;
                                }
                                this.fileOutputStream.write(bArr, 0, read);
                                i += read;
                                if (this.fileSize > 0) {
                                    reportProgress(((float) i) / ((float) this.fileSize));
                                }
                            } catch (Exception e3) {
                                Exception e4 = e3;
                                z = false;
                                try {
                                    FileLog.e(e4);
                                } catch (Throwable th6) {
                                    th = th6;
                                }
                                z2 = z;
                                if (this.fileOutputStream != null) {
                                }
                                if (inputStream != null) {
                                }
                                return Boolean.valueOf(z2);
                            }
                        }
                    } catch (Throwable th7) {
                        th = th7;
                        z = false;
                        FileLog.e(th);
                        z2 = z;
                        if (this.fileOutputStream != null) {
                        }
                        if (inputStream != null) {
                        }
                        return Boolean.valueOf(z2);
                    }
                    z2 = z;
                }
                try {
                    if (this.fileOutputStream != null) {
                        this.fileOutputStream.close();
                        this.fileOutputStream = null;
                    }
                } catch (Throwable th8) {
                    FileLog.e(th8);
                }
                if (inputStream != null) {
                    try {
                        inputStream.close();
                    } catch (Throwable th9) {
                        FileLog.e(th9);
                    }
                }
            }
            return Boolean.valueOf(z2);
        }

        /* access modifiers changed from: protected */
        public void onPostExecute(Boolean bool) {
            ImageLoader.this.runHttpFileLoadTasks(this, bool.booleanValue() ? 2 : 1);
        }

        /* access modifiers changed from: protected */
        public void onCancelled() {
            ImageLoader.this.runHttpFileLoadTasks(this, 2);
        }
    }

    /* access modifiers changed from: private */
    public class ArtworkLoadTask extends AsyncTask<Void, Void, String> {
        private CacheImage cacheImage;
        private boolean canRetry = true;
        private HttpURLConnection httpConnection;
        private boolean small;

        public ArtworkLoadTask(CacheImage cacheImage2) {
            boolean z = true;
            this.cacheImage = cacheImage2;
            this.small = Uri.parse(cacheImage2.imageLocation.path).getQueryParameter("s") == null ? false : z;
        }

        /* access modifiers changed from: protected */
        /* JADX WARNING: Removed duplicated region for block: B:102:0x013b A[Catch:{ all -> 0x0141 }] */
        /* JADX WARNING: Removed duplicated region for block: B:105:0x0144 A[SYNTHETIC, Splitter:B:105:0x0144] */
        /* JADX WARNING: Removed duplicated region for block: B:110:0x014e  */
        /* JADX WARNING: Removed duplicated region for block: B:125:0x016a A[SYNTHETIC, Splitter:B:125:0x016a] */
        /* JADX WARNING: Removed duplicated region for block: B:82:0x0105 A[Catch:{ all -> 0x0152, all -> 0x015d, all -> 0x0164 }] */
        /* JADX WARNING: Removed duplicated region for block: B:85:0x010e A[Catch:{ all -> 0x0152, all -> 0x015d, all -> 0x0164 }] */
        public String doInBackground(Void... voidArr) {
            ByteArrayOutputStream byteArrayOutputStream;
            InputStream inputStream;
            Throwable th;
            ByteArrayOutputStream byteArrayOutputStream2;
            int responseCode;
            try {
                HttpURLConnection httpURLConnection = (HttpURLConnection) new URL(this.cacheImage.imageLocation.path.replace("athumb://", "https://")).openConnection();
                this.httpConnection = httpURLConnection;
                httpURLConnection.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.connect();
                try {
                    if (!(this.httpConnection == null || (responseCode = this.httpConnection.getResponseCode()) == 200 || responseCode == 202 || responseCode == 304)) {
                        this.canRetry = false;
                    }
                } catch (Exception e) {
                    FileLog.e(e);
                }
                InputStream inputStream2 = this.httpConnection.getInputStream();
                try {
                    byteArrayOutputStream2 = new ByteArrayOutputStream();
                } catch (Throwable th2) {
                    byteArrayOutputStream = null;
                    inputStream = inputStream2;
                    th = th2;
                    try {
                        if (th instanceof SocketTimeoutException) {
                        }
                        FileLog.e(th);
                        try {
                            if (this.httpConnection != null) {
                            }
                        } catch (Throwable unused) {
                        }
                        if (inputStream != null) {
                        }
                        if (byteArrayOutputStream != null) {
                        }
                        return null;
                    } catch (Throwable th3) {
                        FileLog.e(th3);
                    }
                }
                try {
                    byte[] bArr = new byte[32768];
                    while (true) {
                        if (!isCancelled()) {
                            int read = inputStream2.read(bArr);
                            if (read <= 0) {
                                break;
                            }
                            byteArrayOutputStream2.write(bArr, 0, read);
                        } else {
                            break;
                        }
                    }
                    this.canRetry = false;
                    JSONArray jSONArray = new JSONObject(new String(byteArrayOutputStream2.toByteArray())).getJSONArray("results");
                    if (jSONArray.length() > 0) {
                        String string = jSONArray.getJSONObject(0).getString("artworkUrl100");
                        if (this.small) {
                            try {
                                if (this.httpConnection != null) {
                                    this.httpConnection.disconnect();
                                }
                            } catch (Throwable unused2) {
                            }
                            if (inputStream2 != null) {
                                try {
                                    inputStream2.close();
                                } catch (Throwable th4) {
                                    FileLog.e(th4);
                                }
                            }
                            try {
                                byteArrayOutputStream2.close();
                            } catch (Exception unused3) {
                            }
                            return string;
                        }
                        String replace = string.replace("100x100", "600x600");
                        try {
                            if (this.httpConnection != null) {
                                this.httpConnection.disconnect();
                            }
                        } catch (Throwable unused4) {
                        }
                        if (inputStream2 != null) {
                            try {
                                inputStream2.close();
                            } catch (Throwable th5) {
                                FileLog.e(th5);
                            }
                        }
                        try {
                            byteArrayOutputStream2.close();
                        } catch (Exception unused5) {
                        }
                        return replace;
                    }
                    try {
                        if (this.httpConnection != null) {
                            this.httpConnection.disconnect();
                        }
                    } catch (Throwable unused6) {
                    }
                    if (inputStream2 != null) {
                        try {
                            inputStream2.close();
                        } catch (Throwable th6) {
                            FileLog.e(th6);
                        }
                    }
                    try {
                        byteArrayOutputStream2.close();
                    } catch (Exception unused7) {
                    }
                    return null;
                } catch (Throwable th7) {
                    inputStream = inputStream2;
                    th = th7;
                    byteArrayOutputStream = byteArrayOutputStream2;
                    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);
                    if (this.httpConnection != null) {
                        this.httpConnection.disconnect();
                    }
                    if (inputStream != null) {
                        try {
                            inputStream.close();
                        } catch (Throwable th8) {
                            FileLog.e(th8);
                        }
                    }
                    if (byteArrayOutputStream != null) {
                        byteArrayOutputStream.close();
                    }
                    return null;
                }
            } catch (Throwable th9) {
                th = th9;
                inputStream = null;
                byteArrayOutputStream = null;
                if (th instanceof SocketTimeoutException) {
                }
                FileLog.e(th);
                if (this.httpConnection != null) {
                }
                if (inputStream != null) {
                }
                if (byteArrayOutputStream != null) {
                }
                return null;
            }
            if (byteArrayOutputStream != null) {
                try {
                    byteArrayOutputStream.close();
                } catch (Exception unused8) {
                }
            }
            throw th;
            throw th;
            if (inputStream != null) {
                inputStream.close();
            }
            if (byteArrayOutputStream != null) {
            }
            throw th;
        }

        /* access modifiers changed from: protected */
        public void onPostExecute(String str) {
            if (str != null) {
                this.cacheImage.httpTask = new HttpImageTask(this.cacheImage, 0, str);
                ImageLoader.this.httpTasks.add(this.cacheImage.httpTask);
                ImageLoader.this.runHttpTasks(false);
            } else if (this.canRetry) {
                ImageLoader.this.artworkLoadError(this.cacheImage.url);
            }
            ImageLoader.this.imageLoadQueue.postRunnable(new Runnable() {
                /* class im.guobwnxjuc.messenger.$$Lambda$ImageLoader$ArtworkLoadTask$Nhp9XfZaVKgl7PQ92dAzsMpxNPw */

                public final void run() {
                    ImageLoader.ArtworkLoadTask.this.lambda$onPostExecute$0$ImageLoader$ArtworkLoadTask();
                }
            });
        }

        public /* synthetic */ void lambda$onPostExecute$0$ImageLoader$ArtworkLoadTask() {
            ImageLoader.this.runArtworkTasks(true);
        }

        public /* synthetic */ void lambda$onCancelled$1$ImageLoader$ArtworkLoadTask() {
            ImageLoader.this.runArtworkTasks(true);
        }

        /* access modifiers changed from: protected */
        public void onCancelled() {
            ImageLoader.this.imageLoadQueue.postRunnable(new Runnable() {
                /* class im.guobwnxjuc.messenger.$$Lambda$ImageLoader$ArtworkLoadTask$DTTSVAsfbdAJdbf5N9ENizuqCM */

                public final void run() {
                    ImageLoader.ArtworkLoadTask.this.lambda$onCancelled$1$ImageLoader$ArtworkLoadTask();
                }
            });
        }
    }

    /* access modifiers changed from: private */
    public class HttpImageTask extends AsyncTask<Void, Void, Boolean> {
        private CacheImage cacheImage;
        private boolean canRetry = true;
        private RandomAccessFile fileOutputStream;
        private HttpURLConnection httpConnection;
        private int imageSize;
        private long lastProgressTime;
        private String overrideUrl;

        static /* synthetic */ void lambda$doInBackground$2(TLObject tLObject, TLRPC.TL_error tL_error) {
        }

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

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

        private void reportProgress(float f) {
            long currentTimeMillis = System.currentTimeMillis();
            if (f != 1.0f) {
                long j = this.lastProgressTime;
                if (j != 0 && j >= currentTimeMillis - 500) {
                    return;
                }
            }
            this.lastProgressTime = currentTimeMillis;
            Utilities.stageQueue.postRunnable(new Runnable(f) {
                /* class im.guobwnxjuc.messenger.$$Lambda$ImageLoader$HttpImageTask$WABU3oZDDcbUbI9bYiQ58IhCA8 */
                private final /* synthetic */ float f$1;

                {
                    this.f$1 = r2;
                }

                public final void run() {
                    ImageLoader.HttpImageTask.this.lambda$reportProgress$1$ImageLoader$HttpImageTask(this.f$1);
                }
            });
        }

        public /* synthetic */ void lambda$reportProgress$1$ImageLoader$HttpImageTask(float f) {
            ImageLoader.this.fileProgresses.put(this.cacheImage.url, Float.valueOf(f));
            AndroidUtilities.runOnUIThread(new Runnable(f) {
                /* class im.guobwnxjuc.messenger.$$Lambda$ImageLoader$HttpImageTask$5VeuaCkgkT_5gexJFDXVhhlk8Ss */
                private final /* synthetic */ float f$1;

                {
                    this.f$1 = r2;
                }

                public final void run() {
                    ImageLoader.HttpImageTask.this.lambda$null$0$ImageLoader$HttpImageTask(this.f$1);
                }
            });
        }

        public /* synthetic */ void lambda$null$0$ImageLoader$HttpImageTask(float f) {
            NotificationCenter.getInstance(this.cacheImage.currentAccount).postNotificationName(NotificationCenter.FileLoadProgressChanged, this.cacheImage.url, Float.valueOf(f));
        }

        /* access modifiers changed from: protected */
        /* JADX WARNING: Code restructure failed: missing block: B:89:0x0161, code lost:
            if (r5 != -1) goto L_0x0175;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:92:0x0165, code lost:
            if (r8.imageSize == 0) goto L_0x017c;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:93:0x0167, code lost:
            reportProgress(1.0f);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:94:0x016d, code lost:
            r2 = move-exception;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:95:0x016e, code lost:
            r0 = r2;
            r2 = true;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:96:0x0171, code lost:
            r2 = move-exception;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:97:0x0172, code lost:
            r0 = r2;
            r2 = true;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:98:0x0175, code lost:
            r0 = false;
         */
        /* JADX WARNING: Removed duplicated region for block: B:107:0x0186 A[Catch:{ all -> 0x018e }] */
        /* JADX WARNING: Removed duplicated region for block: B:113:0x0196 A[Catch:{ all -> 0x019c }] */
        /* JADX WARNING: Removed duplicated region for block: B:116:0x019f A[SYNTHETIC, Splitter:B:116:0x019f] */
        /* JADX WARNING: Removed duplicated region for block: B:48:0x00e7 A[SYNTHETIC, Splitter:B:48:0x00e7] */
        public Boolean doInBackground(Void... voidArr) {
            InputStream inputStream;
            HttpURLConnection httpURLConnection;
            List<String> list;
            String str;
            int responseCode;
            Throwable th;
            InputStream inputStream2;
            int i;
            WebFile webFile;
            boolean z = true;
            boolean z2 = 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 tL_upload_getWebFile = new TLRPC.TL_upload_getWebFile();
                        tL_upload_getWebFile.location = webFile.location;
                        tL_upload_getWebFile.offset = 0;
                        tL_upload_getWebFile.limit = 0;
                        ConnectionsManager.getInstance(this.cacheImage.currentAccount).sendRequest(tL_upload_getWebFile, $$Lambda$ImageLoader$HttpImageTask$XhQbUSv8Y5IRS03JQLHcbqtSKlg.INSTANCE);
                    }
                    if (this.overrideUrl != null) {
                        str2 = this.overrideUrl;
                    }
                    HttpURLConnection httpURLConnection2 = (HttpURLConnection) new URL(str2).openConnection();
                    this.httpConnection = httpURLConnection2;
                    httpURLConnection2.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);
                    if (!isCancelled()) {
                        this.httpConnection.connect();
                        inputStream = this.httpConnection.getInputStream();
                        try {
                            this.fileOutputStream = new RandomAccessFile(this.cacheImage.tempFilePath, "rws");
                        } catch (Throwable th2) {
                            inputStream2 = inputStream;
                            th = th2;
                        }
                        if (!isCancelled()) {
                            try {
                                if (!(this.httpConnection == null || (responseCode = this.httpConnection.getResponseCode()) == 200 || responseCode == 202 || responseCode == 304)) {
                                    this.canRetry = false;
                                }
                            } catch (Exception e) {
                                FileLog.e(e);
                            }
                            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(str).intValue();
                                    }
                                } catch (Exception e2) {
                                    FileLog.e(e2);
                                }
                            }
                            if (inputStream != null) {
                                try {
                                    byte[] bArr = new byte[8192];
                                    int i2 = 0;
                                    while (true) {
                                        if (isCancelled()) {
                                            break;
                                        }
                                        try {
                                            int read = inputStream.read(bArr);
                                            if (read <= 0) {
                                                break;
                                            }
                                            i2 += read;
                                            this.fileOutputStream.write(bArr, 0, read);
                                            if (this.imageSize != 0) {
                                                reportProgress(((float) i2) / ((float) this.imageSize));
                                            }
                                        } catch (Exception e3) {
                                            Exception e4 = e3;
                                            FileLog.e(e4);
                                            z = z2;
                                            z2 = z;
                                            if (this.fileOutputStream != null) {
                                            }
                                            if (this.httpConnection != null) {
                                            }
                                            if (inputStream != null) {
                                            }
                                            CacheImage cacheImage2 = this.cacheImage;
                                            cacheImage2.finalFilePath = cacheImage2.tempFilePath;
                                            return Boolean.valueOf(z2);
                                        }
                                    }
                                    z2 = z;
                                } catch (Throwable th3) {
                                    Throwable th4 = th3;
                                    FileLog.e(th4);
                                    if (this.fileOutputStream != null) {
                                    }
                                    if (this.httpConnection != null) {
                                    }
                                    if (inputStream != null) {
                                    }
                                    CacheImage cacheImage22 = this.cacheImage;
                                    cacheImage22.finalFilePath = cacheImage22.tempFilePath;
                                    return Boolean.valueOf(z2);
                                }
                            }
                        }
                        if (this.fileOutputStream != null) {
                            this.fileOutputStream.close();
                            this.fileOutputStream = null;
                        }
                        if (this.httpConnection != null) {
                            this.httpConnection.disconnect();
                        }
                        if (inputStream != null) {
                            try {
                                inputStream.close();
                            } catch (Throwable th5) {
                                FileLog.e(th5);
                            }
                        }
                        if (z2 && this.cacheImage.tempFilePath != null && !this.cacheImage.tempFilePath.renameTo(this.cacheImage.finalFilePath)) {
                            CacheImage cacheImage222 = this.cacheImage;
                            cacheImage222.finalFilePath = cacheImage222.tempFilePath;
                        }
                        return Boolean.valueOf(z2);
                    }
                } catch (Throwable th6) {
                    th = th6;
                    inputStream2 = null;
                    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);
                    inputStream = inputStream2;
                    if (!isCancelled()) {
                    }
                    if (this.fileOutputStream != null) {
                    }
                    if (this.httpConnection != null) {
                    }
                    if (inputStream != null) {
                    }
                    CacheImage cacheImage2222 = this.cacheImage;
                    cacheImage2222.finalFilePath = cacheImage2222.tempFilePath;
                    return Boolean.valueOf(z2);
                }
            }
            inputStream = null;
            if (!isCancelled()) {
            }
            try {
                if (this.fileOutputStream != null) {
                }
            } catch (Throwable th7) {
                FileLog.e(th7);
            }
            try {
                if (this.httpConnection != null) {
                }
            } catch (Throwable unused) {
            }
            if (inputStream != null) {
            }
            CacheImage cacheImage22222 = this.cacheImage;
            cacheImage22222.finalFilePath = cacheImage22222.tempFilePath;
            return Boolean.valueOf(z2);
        }

        /* access modifiers changed from: protected */
        public void onPostExecute(Boolean bool) {
            if (bool.booleanValue() || !this.canRetry) {
                ImageLoader.this.fileDidLoaded(this.cacheImage.url, this.cacheImage.finalFilePath, 0);
            } else {
                ImageLoader.this.httpFileLoadError(this.cacheImage.url);
            }
            Utilities.stageQueue.postRunnable(new Runnable(bool) {
                /* class im.guobwnxjuc.messenger.$$Lambda$ImageLoader$HttpImageTask$1AozDHJZ1FDK_aQiSb1U91HG8Eg */
                private final /* synthetic */ Boolean f$1;

                {
                    this.f$1 = r2;
                }

                public final void run() {
                    ImageLoader.HttpImageTask.this.lambda$onPostExecute$4$ImageLoader$HttpImageTask(this.f$1);
                }
            });
            ImageLoader.this.imageLoadQueue.postRunnable(new Runnable() {
                /* class im.guobwnxjuc.messenger.$$Lambda$ImageLoader$HttpImageTask$akxnCQZjMgoFc6WnMs7z0Dqrk8 */

                public final void run() {
                    ImageLoader.HttpImageTask.this.lambda$onPostExecute$5$ImageLoader$HttpImageTask();
                }
            });
        }

        public /* synthetic */ void lambda$onPostExecute$4$ImageLoader$HttpImageTask(Boolean bool) {
            ImageLoader.this.fileProgresses.remove(this.cacheImage.url);
            AndroidUtilities.runOnUIThread(new Runnable(bool) {
                /* class im.guobwnxjuc.messenger.$$Lambda$ImageLoader$HttpImageTask$bmT3AIoI03OC_RpVLfzQhZ8V8s */
                private final /* synthetic */ Boolean f$1;

                {
                    this.f$1 = r2;
                }

                public final void run() {
                    ImageLoader.HttpImageTask.this.lambda$null$3$ImageLoader$HttpImageTask(this.f$1);
                }
            });
        }

        public /* synthetic */ void lambda$null$3$ImageLoader$HttpImageTask(Boolean bool) {
            if (bool.booleanValue()) {
                NotificationCenter.getInstance(this.cacheImage.currentAccount).postNotificationName(NotificationCenter.fileDidLoad, this.cacheImage.url, this.cacheImage.finalFilePath);
                return;
            }
            NotificationCenter.getInstance(this.cacheImage.currentAccount).postNotificationName(NotificationCenter.fileDidFailToLoad, this.cacheImage.url, 2);
        }

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

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

        /* access modifiers changed from: protected */
        public void onCancelled() {
            ImageLoader.this.imageLoadQueue.postRunnable(new Runnable() {
                /* class im.guobwnxjuc.messenger.$$Lambda$ImageLoader$HttpImageTask$L0FWWhgU0dDMHHEC2XSksmxswtQ */

                public final void run() {
                    ImageLoader.HttpImageTask.this.lambda$onCancelled$6$ImageLoader$HttpImageTask();
                }
            });
            Utilities.stageQueue.postRunnable(new Runnable() {
                /* class im.guobwnxjuc.messenger.$$Lambda$ImageLoader$HttpImageTask$DULT8Tr2SIkk8fdoIPwo9QZxa4o */

                public final void run() {
                    ImageLoader.HttpImageTask.this.lambda$onCancelled$8$ImageLoader$HttpImageTask();
                }
            });
        }

        public /* synthetic */ void lambda$onCancelled$8$ImageLoader$HttpImageTask() {
            ImageLoader.this.fileProgresses.remove(this.cacheImage.url);
            AndroidUtilities.runOnUIThread(new Runnable() {
                /* class im.guobwnxjuc.messenger.$$Lambda$ImageLoader$HttpImageTask$BIwEHOC6AMcpeFV_7V7Gk262dHM */

                public final void run() {
                    ImageLoader.HttpImageTask.this.lambda$null$7$ImageLoader$HttpImageTask();
                }
            });
        }

        public /* synthetic */ void lambda$null$7$ImageLoader$HttpImageTask() {
            NotificationCenter.getInstance(this.cacheImage.currentAccount).postNotificationName(NotificationCenter.fileDidFailToLoad, this.cacheImage.url, 1);
        }
    }

    /* access modifiers changed from: private */
    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) {
                ImageLoader.this.imageLoadQueue.postRunnable(new Runnable(FileLoader.getAttachFileName(thumbGenerateInfo.parentDocument)) {
                    /* class im.guobwnxjuc.messenger.$$Lambda$ImageLoader$ThumbGenerateTask$bxDrBa3kuG5Zt4Wn1w4xRvJYYzI */
                    private final /* synthetic */ String f$1;

                    {
                        this.f$1 = r2;
                    }

                    public final void run() {
                        ImageLoader.ThumbGenerateTask.this.lambda$removeTask$0$ImageLoader$ThumbGenerateTask(this.f$1);
                    }
                });
            }
        }

        public /* synthetic */ void lambda$removeTask$0$ImageLoader$ThumbGenerateTask(String str) {
            ThumbGenerateTask thumbGenerateTask = (ThumbGenerateTask) ImageLoader.this.thumbGenerateTasks.remove(str);
        }

        public void run() {
            Bitmap createScaledBitmap;
            try {
                if (this.info == null) {
                    removeTask();
                    return;
                }
                String str = "q_" + this.info.parentDocument.dc_id + "_" + this.info.parentDocument.id;
                File file = new File(FileLoader.getDirectory(4), str + ".jpg");
                if (!file.exists()) {
                    if (this.originalPath.exists()) {
                        int max = this.info.big ? Math.max(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) : Math.min(180, Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) / 4);
                        Bitmap bitmap = null;
                        if (this.mediaType == 0) {
                            float f = (float) max;
                            bitmap = ImageLoader.loadBitmap(this.originalPath.toString(), null, f, f, false);
                        } else {
                            int i = 2;
                            if (this.mediaType == 2) {
                                String file2 = this.originalPath.toString();
                                if (!this.info.big) {
                                    i = 1;
                                }
                                bitmap = ThumbnailUtils.createVideoThumbnail(file2, i);
                            } else if (this.mediaType == 3) {
                                String lowerCase = this.originalPath.toString().toLowerCase();
                                if (lowerCase.endsWith("mp4")) {
                                    String file3 = this.originalPath.toString();
                                    if (!this.info.big) {
                                        i = 1;
                                    }
                                    bitmap = ThumbnailUtils.createVideoThumbnail(file3, i);
                                } else if (lowerCase.endsWith(".jpg") || lowerCase.endsWith(".jpeg") || lowerCase.endsWith(".png") || lowerCase.endsWith(".gif")) {
                                    float f2 = (float) max;
                                    bitmap = ImageLoader.loadBitmap(lowerCase, null, f2, f2, false);
                                }
                            }
                        }
                        if (bitmap == null) {
                            removeTask();
                            return;
                        }
                        int width = bitmap.getWidth();
                        int height = bitmap.getHeight();
                        if (width != 0) {
                            if (height != 0) {
                                float f3 = (float) width;
                                float f4 = (float) max;
                                float f5 = (float) height;
                                float min = Math.min(f3 / f4, f5 / f4);
                                if (min > 1.0f && (createScaledBitmap = Bitmaps.createScaledBitmap(bitmap, (int) (f3 / min), (int) (f5 / min), 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);
                                }
                                AndroidUtilities.runOnUIThread(new Runnable(str, new ArrayList(this.info.imageReceiverArray), new BitmapDrawable(bitmap), new ArrayList(this.info.imageReceiverGuidsArray)) {
                                    /* class im.guobwnxjuc.messenger.$$Lambda$ImageLoader$ThumbGenerateTask$oSUczgXh1gghkILOFYv2ENHEtcU */
                                    private final /* synthetic */ String f$1;
                                    private final /* synthetic */ ArrayList f$2;
                                    private final /* synthetic */ BitmapDrawable f$3;
                                    private final /* synthetic */ ArrayList f$4;

                                    {
                                        this.f$1 = r2;
                                        this.f$2 = r3;
                                        this.f$3 = r4;
                                        this.f$4 = r5;
                                    }

                                    public final void run() {
                                        ImageLoader.ThumbGenerateTask.this.lambda$run$1$ImageLoader$ThumbGenerateTask(this.f$1, this.f$2, this.f$3, this.f$4);
                                    }
                                });
                                return;
                            }
                        }
                        removeTask();
                        return;
                    }
                }
                removeTask();
            } catch (Throwable th) {
                FileLog.e(th);
                removeTask();
            }
        }

        public /* synthetic */ void lambda$run$1$ImageLoader$ThumbGenerateTask(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);
        }
    }

    /* access modifiers changed from: private */
    public class CacheOutTask implements Runnable {
        private CacheImage cacheImage;
        private boolean isCancelled;
        private Thread runningThread;
        private final Object sync = new Object();

        public CacheOutTask(CacheImage cacheImage2) {
            this.cacheImage = cacheImage2;
        }

        /* JADX WARN: Multi-variable type inference failed */
        /* JADX WARN: Type inference failed for: r33v0, types: [im.guobwnxjuc.messenger.ImageLoader$CacheOutTask] */
        /* JADX WARN: Type inference failed for: r3v16 */
        /* JADX WARN: Type inference failed for: r3v43 */
        /* JADX WARN: Type inference failed for: r3v44 */
        /* JADX WARN: Type inference failed for: r3v45 */
        /* JADX WARN: Type inference failed for: r3v46 */
        /* JADX WARNING: Code restructure failed: missing block: B:100:0x01f0, code lost:
            monitor-enter(r8);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:103:0x01f3, code lost:
            if (r33.isCancelled == false) goto L_0x01f7;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:104:0x01f5, code lost:
            monitor-exit(r8);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:105:0x01f6, code lost:
            return;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:106:0x01f7, code lost:
            monitor-exit(r8);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:108:0x0202, code lost:
            if (im.guobwnxjuc.messenger.ImageLoader.AUTOPLAY_FILTER.equals(r33.cacheImage.filter) == false) goto L_0x023b;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:10:0x0023, code lost:
            r7 = r33.sync;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:110:0x020c, code lost:
            if ((r33.cacheImage.imageLocation.document instanceof im.guobwnxjuc.tgnet.TLRPC.TL_documentEncrypted) != false) goto L_0x023b;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:111:0x020e, code lost:
            r6 = r33.cacheImage.finalFilePath;
            r8 = (long) r33.cacheImage.size;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:112:0x0222, code lost:
            if ((r33.cacheImage.imageLocation.document instanceof im.guobwnxjuc.tgnet.TLRPC.Document) == false) goto L_0x022c;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:113:0x0224, code lost:
            r10 = r33.cacheImage.imageLocation.document;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:114:0x022c, code lost:
            r10 = null;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:115:0x022d, code lost:
            r0 = new im.guobwnxjuc.ui.components.AnimatedFileDrawable(r6, false, r8, r10, r33.cacheImage.parentObject, r33.cacheImage.currentAccount, false);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:116:0x023b, code lost:
            r0 = new im.guobwnxjuc.ui.components.AnimatedFileDrawable(r33.cacheImage.finalFilePath, "d".equals(r33.cacheImage.filter), 0, null, null, r33.cacheImage.currentAccount, false);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:117:0x025d, code lost:
            java.lang.Thread.interrupted();
            onPostExecute(r0);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:11:0x0025, code lost:
            monitor-enter(r7);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:121:0x0268, code lost:
            r8 = r33.cacheImage.finalFilePath;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:122:0x0270, code lost:
            if (r33.cacheImage.secureDocument != null) goto L_0x0289;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:124:0x0276, code lost:
            if (r33.cacheImage.encryptionKeyPath == null) goto L_0x0287;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:125:0x0278, code lost:
            if (r8 == null) goto L_0x0287;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:127:0x0284, code lost:
            if (r8.getAbsolutePath().endsWith(".enc") == false) goto L_0x0287;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:128:0x0287, code lost:
            r9 = false;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:129:0x0289, code lost:
            r9 = true;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:131:0x028e, code lost:
            if (r33.cacheImage.secureDocument == null) goto L_0x02ba;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:132:0x0290, code lost:
            r0 = r33.cacheImage.secureDocument.secureDocumentKey;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:133:0x029c, code lost:
            if (r33.cacheImage.secureDocument.secureFile == null) goto L_0x02b1;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:135:0x02a6, code lost:
            if (r33.cacheImage.secureDocument.secureFile.file_hash == null) goto L_0x02b1;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:136:0x02a8, code lost:
            r10 = r33.cacheImage.secureDocument.secureFile.file_hash;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:137:0x02b1, code lost:
            r10 = r33.cacheImage.secureDocument.fileHash;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:138:0x02b7, code lost:
            r11 = r10;
            r10 = r0;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:139:0x02ba, code lost:
            r10 = null;
            r11 = null;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:141:0x02c0, code lost:
            if (android.os.Build.VERSION.SDK_INT >= 19) goto L_0x032c;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:143:?, code lost:
            r12 = new java.io.RandomAccessFile(r8, "r");
         */
        /* JADX WARNING: Code restructure failed: missing block: B:146:0x02cd, code lost:
            if (r33.cacheImage.imageType != 1) goto L_0x02d4;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:147:0x02cf, code lost:
            r0 = im.guobwnxjuc.messenger.ImageLoader.headerThumb;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:148:0x02d4, code lost:
            r0 = im.guobwnxjuc.messenger.ImageLoader.header;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:149:0x02d8, code lost:
            r12.readFully(r0, 0, r0.length);
            r0 = new java.lang.String(r0).toLowerCase().toLowerCase();
         */
        /* JADX WARNING: Code restructure failed: missing block: B:14:0x0028, code lost:
            if (r33.isCancelled == false) goto L_0x002c;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:150:0x02ef, code lost:
            if (r0.startsWith("riff") == false) goto L_0x02fb;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:152:0x02f7, code lost:
            if (r0.endsWith("webp") == false) goto L_0x02fb;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:153:0x02f9, code lost:
            r13 = true;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:154:0x02fb, code lost:
            r13 = false;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:156:?, code lost:
            r12.close();
         */
        /* JADX WARNING: Code restructure failed: missing block: B:158:?, code lost:
            r12.close();
         */
        /* JADX WARNING: Code restructure failed: missing block: B:159:0x0303, code lost:
            r0 = move-exception;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:15:0x002a, code lost:
            monitor-exit(r7);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:160:0x0304, code lost:
            im.guobwnxjuc.messenger.FileLog.e(r0);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:161:0x0309, code lost:
            r0 = e;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:162:0x030b, code lost:
            r0 = e;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:163:0x030d, code lost:
            r0 = move-exception;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:164:0x030e, code lost:
            r2 = r0;
            r4 = null;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:165:0x0311, code lost:
            r0 = e;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:166:0x0312, code lost:
            r12 = null;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:167:0x0313, code lost:
            r13 = false;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:169:?, code lost:
            im.guobwnxjuc.messenger.FileLog.e(r0);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:16:0x002b, code lost:
            return;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:170:0x0317, code lost:
            if (r12 != null) goto L_0x0319;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:171:0x0319, code lost:
            r12.close();
         */
        /* JADX WARNING: Code restructure failed: missing block: B:172:0x031d, code lost:
            r0 = move-exception;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:173:0x031e, code lost:
            r2 = r0;
            r4 = r12;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:174:0x0320, code lost:
            if (r4 != null) goto L_0x0322;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:176:?, code lost:
            r4.close();
         */
        /* JADX WARNING: Code restructure failed: missing block: B:177:0x0326, code lost:
            r0 = move-exception;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:178:0x0327, code lost:
            im.guobwnxjuc.messenger.FileLog.e(r0);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:179:0x032b, code lost:
            throw r2;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:17:0x002c, code lost:
            monitor-exit(r7);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:180:0x032c, code lost:
            r13 = false;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:182:0x0333, code lost:
            if (r33.cacheImage.imageLocation.path != null) goto L_0x0335;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:183:0x0335, code lost:
            r0 = r33.cacheImage.imageLocation.path;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:184:0x0341, code lost:
            if (r0.startsWith("thumb://") != false) goto L_0x0343;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:185:0x0343, code lost:
            r12 = r0.indexOf(com.king.zxing.util.LogUtils.COLON, 8);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:186:0x0349, code lost:
            if (r12 >= 0) goto L_0x034b;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:187:0x034b, code lost:
            r14 = java.lang.Long.valueOf(java.lang.Long.parseLong(r0.substring(8, r12)));
            r0 = r0.substring(r12 + 1);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:188:0x035d, code lost:
            r0 = null;
            r14 = null;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:189:0x035f, code lost:
            r12 = r0;
            r15 = r14;
            r14 = false;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:18:0x002d, code lost:
            r0 = (im.guobwnxjuc.tgnet.TLRPC.TL_photoStrippedSize) r33.cacheImage.imageLocation.photoSize;
            r7 = ((r0.bytes.length - 3) + im.guobwnxjuc.messenger.Bitmaps.header.length) + im.guobwnxjuc.messenger.Bitmaps.footer.length;
            r8 = (byte[]) im.guobwnxjuc.messenger.ImageLoader.bytesLocal.get();
         */
        /* JADX WARNING: Code restructure failed: missing block: B:190:0x0362, code lost:
            r16 = false;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:192:0x036b, code lost:
            if (r0.startsWith("vthumb://") != false) goto L_0x036d;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:193:0x036d, code lost:
            r14 = r0.indexOf(com.king.zxing.util.LogUtils.COLON, 9);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:194:0x0375, code lost:
            if (r14 >= 0) goto L_0x0377;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:195:0x0377, code lost:
            r14 = java.lang.Long.valueOf(java.lang.Long.parseLong(r0.substring(9, r14)));
            r0 = true;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:196:0x0386, code lost:
            r0 = false;
            r14 = null;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:197:0x0388, code lost:
            r15 = r14;
            r12 = null;
            r16 = false;
            r14 = r0;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:199:0x0394, code lost:
            if (r0.startsWith("http") == false) goto L_0x0396;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:19:0x004b, code lost:
            if (r8 == null) goto L_0x0051;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:200:0x0396, code lost:
            r12 = null;
            r14 = false;
            r15 = null;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:201:0x039a, code lost:
            r12 = null;
            r14 = false;
            r15 = null;
            r16 = true;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:202:0x039f, code lost:
            r7 = new android.graphics.BitmapFactory.Options();
            r7.inSampleSize = 1;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:203:0x03aa, code lost:
            if (android.os.Build.VERSION.SDK_INT < 21) goto L_0x03ac;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:204:0x03ac, code lost:
            r7.inPurgeable = true;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:205:0x03ae, code lost:
            r19 = r33.this$0.canForce8888;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:208:0x03bc, code lost:
            if (r33.cacheImage.filter != null) goto L_0x03be;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:209:0x03be, code lost:
            r0 = r33.cacheImage.filter.split("_");
         */
        /* JADX WARNING: Code restructure failed: missing block: B:210:0x03c9, code lost:
            if (r0.length >= 2) goto L_0x03cb;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:212:0x03d3, code lost:
            r2 = java.lang.Float.parseFloat(r0[0]) * im.guobwnxjuc.messenger.AndroidUtilities.density;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:215:0x03dd, code lost:
            r23 = r2;
            r2 = java.lang.Float.parseFloat(r0[1]) * im.guobwnxjuc.messenger.AndroidUtilities.density;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:216:0x03e3, code lost:
            r0 = move-exception;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:217:0x03e4, code lost:
            r6 = r0;
            r0 = 0.0f;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:218:0x03e8, code lost:
            r2 = 0.0f;
            r23 = 0.0f;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:21:0x004e, code lost:
            if (r8.length < r7) goto L_0x0051;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:221:0x03f5, code lost:
            if (r33.cacheImage.filter.contains("b2") != false) goto L_0x03f7;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:222:0x03f7, code lost:
            r3 = 3;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:224:0x0403, code lost:
            if (r33.cacheImage.filter.contains("b1") != false) goto L_0x0405;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:225:0x0405, code lost:
            r3 = 2;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:227:0x0411, code lost:
            if (r33.cacheImage.filter.contains("b") != false) goto L_0x0413;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:228:0x0413, code lost:
            r3 = 1;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:229:0x0415, code lost:
            r3 = 0;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:22:0x0051, code lost:
            r8 = null;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:231:?, code lost:
            r4 = r33.cacheImage.filter.contains("i");
         */
        /* JADX WARNING: Code restructure failed: missing block: B:233:?, code lost:
            r6 = "f";
         */
        /* JADX WARNING: Code restructure failed: missing block: B:234:0x042a, code lost:
            if (r33.cacheImage.filter.contains(r6) != false) goto L_0x042c;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:235:0x042c, code lost:
            r19 = true;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:236:0x042e, code lost:
            if (r13 != false) goto L_0x053e;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:23:0x0052, code lost:
            if (r8 != null) goto L_0x005d;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:241:0x0438, code lost:
            r7.inJustDecodeBounds = true;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:242:0x043a, code lost:
            if (r15 == null) goto L_0x0475;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:244:0x043e, code lost:
            if (r14 != false) goto L_0x0440;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:247:0x0446, code lost:
            r6 = r3;
            r26 = r4;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:249:?, code lost:
            android.provider.MediaStore.Video.Thumbnails.getThumbnail(im.guobwnxjuc.messenger.ApplicationLoader.applicationContext.getContentResolver(), r15.longValue(), 1, r7);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:24:0x0054, code lost:
            r8 = new byte[r7];
            im.guobwnxjuc.messenger.ImageLoader.bytesLocal.set(r8);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:250:0x0451, code lost:
            r0 = th;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:251:0x0452, code lost:
            r3 = r3;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:252:0x0456, code lost:
            r6 = r3;
            r26 = r4;
            android.provider.MediaStore.Images.Thumbnails.getThumbnail(im.guobwnxjuc.messenger.ApplicationLoader.applicationContext.getContentResolver(), r15.longValue(), 1, r7);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:253:0x0466, code lost:
            r27 = r6;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:254:0x046a, code lost:
            r0 = th;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:255:0x046b, code lost:
            r3 = r6;
            r4 = r26;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:256:0x046e, code lost:
            r5 = null;
            r6 = r0;
            r0 = r2;
            r2 = r23;
            r3 = r3;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:257:0x0475, code lost:
            r26 = r4;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:258:0x0478, code lost:
            if (r10 != null) goto L_0x047a;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:25:0x005d, code lost:
            java.lang.System.arraycopy(im.guobwnxjuc.messenger.Bitmaps.header, 0, r8, 0, im.guobwnxjuc.messenger.Bitmaps.header.length);
            java.lang.System.arraycopy(r0.bytes, 3, r8, im.guobwnxjuc.messenger.Bitmaps.header.length, r0.bytes.length - 3);
            java.lang.System.arraycopy(im.guobwnxjuc.messenger.Bitmaps.footer, 0, r8, (im.guobwnxjuc.messenger.Bitmaps.header.length + r0.bytes.length) - 3, im.guobwnxjuc.messenger.Bitmaps.footer.length);
            r8[164(0xa4, float:2.3E-43)] = r0.bytes[1];
            r8[166(0xa6, float:2.33E-43)] = r0.bytes[2];
            r0 = android.graphics.BitmapFactory.decodeByteArray(r8, 0, r7);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:260:?, code lost:
            r0 = new java.io.RandomAccessFile(r8, "r");
            r4 = (int) r0.length();
            r3 = (byte[]) im.guobwnxjuc.messenger.ImageLoader.bytesLocal.get();
         */
        /* JADX WARNING: Code restructure failed: missing block: B:264:0x0496, code lost:
            r3 = null;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:265:0x0497, code lost:
            if (r3 == null) goto L_0x0499;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:266:0x0499, code lost:
            r3 = new byte[r4];
            im.guobwnxjuc.messenger.ImageLoader.bytesLocal.set(r3);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:267:0x04a2, code lost:
            r0.readFully(r3, 0, r4);
            r0.close();
            im.guobwnxjuc.messenger.secretmedia.EncryptedFileInputStream.decryptBytesWithKeyFile(r3, 0, r4, r10);
            r0 = im.guobwnxjuc.messenger.Utilities.computeSHA256(r3, 0, r4);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:268:0x04b0, code lost:
            if (r11 == null) goto L_0x04bd;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:26:0x0095, code lost:
            if (r0 == null) goto L_0x00bf;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:271:0x04b9, code lost:
            r27 = r3;
            r0 = false;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:272:0x04bd, code lost:
            r27 = r3;
            r0 = true;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:275:?, code lost:
            r5 = r3[0] & kotlin.UByte.MAX_VALUE;
            r4 = r4 - r5;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:276:0x04c6, code lost:
            if (r0 == false) goto L_0x04c8;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:277:0x04c8, code lost:
            android.graphics.BitmapFactory.decodeByteArray(r3, r5, r4, r7);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:278:0x04cc, code lost:
            r0 = th;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:279:0x04cd, code lost:
            r27 = r3;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:280:0x04cf, code lost:
            r6 = r0;
            r0 = r2;
            r2 = r23;
            r4 = r26;
            r3 = r27;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:281:0x04d9, code lost:
            r27 = r3;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:282:0x04db, code lost:
            if (r9 != false) goto L_0x04dd;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:283:0x04dd, code lost:
            r0 = new im.guobwnxjuc.messenger.secretmedia.EncryptedFileInputStream(r8, r33.cacheImage.encryptionKeyPath);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:284:0x04e7, code lost:
            r0 = new java.io.FileInputStream(r8);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:285:0x04ec, code lost:
            android.graphics.BitmapFactory.decodeStream(r0, null, r7);
            r0.close();
         */
        /* JADX WARNING: Code restructure failed: missing block: B:286:0x04f3, code lost:
            r0 = (float) r7.outWidth;
            r3 = (float) r7.outHeight;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:287:0x04fb, code lost:
            if (r23 < r2) goto L_0x050a;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:28:0x009f, code lost:
            if (android.text.TextUtils.isEmpty(r33.cacheImage.filter) != false) goto L_0x00bf;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:290:0x0501, code lost:
            r4 = java.lang.Math.max(r0 / r23, r3 / r2);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:291:0x050a, code lost:
            r4 = java.lang.Math.min(r0 / r23, r3 / r2);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:293:0x0517, code lost:
            if (r4 < 1.2f) goto L_0x0519;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:294:0x0519, code lost:
            r4 = 1.0f;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:295:0x051b, code lost:
            r7.inJustDecodeBounds = false;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:296:0x0520, code lost:
            if (r4 <= 1.0f) goto L_0x0538;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:301:0x052a, code lost:
            r0 = 1;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:302:0x052b, code lost:
            r0 = r0 * 2;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:303:0x0533, code lost:
            if (((float) (r0 * 2)) < r4) goto L_0x052b;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:304:0x0535, code lost:
            r7.inSampleSize = r0;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:305:0x0538, code lost:
            r7.inSampleSize = (int) r4;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:306:0x053c, code lost:
            r0 = th;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:307:0x053e, code lost:
            r27 = r3 == true ? 1 : 0;
            r26 = r4;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:308:0x0542, code lost:
            r4 = r26;
            r3 = r27;
            r0 = null;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:309:0x0549, code lost:
            r0 = move-exception;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:30:0x00ab, code lost:
            if (r33.cacheImage.filter.contains("b") == false) goto L_0x00bf;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:310:0x054a, code lost:
            r6 = r0;
            r0 = r2;
            r2 = r23;
            r3 = r3;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:311:0x0554, code lost:
            r0 = move-exception;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:312:0x0555, code lost:
            r6 = r0;
            r0 = r2;
            r2 = r23;
            r3 = r3;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:313:0x055d, code lost:
            r0 = move-exception;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:314:0x055e, code lost:
            r6 = r0;
            r0 = r2;
            r2 = r23;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:315:0x0563, code lost:
            if (r12 != null) goto L_0x0565;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:316:0x0565, code lost:
            r7.inJustDecodeBounds = true;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:317:0x0568, code lost:
            if (r19 != false) goto L_0x056a;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:318:0x056a, code lost:
            r0 = android.graphics.Bitmap.Config.ARGB_8888;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:319:0x056d, code lost:
            r0 = android.graphics.Bitmap.Config.RGB_565;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:31:0x00ad, code lost:
            im.guobwnxjuc.messenger.Utilities.blurBitmap(r0, 3, 1, r0.getWidth(), r0.getHeight(), r0.getRowBytes());
         */
        /* JADX WARNING: Code restructure failed: missing block: B:320:0x056f, code lost:
            r7.inPreferredConfig = r0;
            r0 = new java.io.FileInputStream(r8);
            r3 = android.graphics.BitmapFactory.decodeStream(r0, null, r7);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:322:?, code lost:
            r0.close();
            r0 = r7.outWidth;
            r2 = r7.outHeight;
            r7.inJustDecodeBounds = false;
            r0 = (float) java.lang.Math.max(r0 / androidx.recyclerview.widget.ItemTouchHelper.Callback.DEFAULT_DRAG_ANIMATION_DURATION, r2 / androidx.recyclerview.widget.ItemTouchHelper.Callback.DEFAULT_DRAG_ANIMATION_DURATION);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:323:0x0590, code lost:
            if (r0 < 1.0f) goto L_0x0592;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:324:0x0592, code lost:
            r0 = 1.0f;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:326:0x0596, code lost:
            if (r0 > 1.0f) goto L_0x0598;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:327:0x0598, code lost:
            r2 = 1;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:328:0x0599, code lost:
            r2 = r2 * 2;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:329:0x05a1, code lost:
            if (((float) (r2 * 2)) < r0) goto L_0x0599;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:32:0x00bf, code lost:
            if (r0 == null) goto L_0x00c7;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:330:0x05a3, code lost:
            r7.inSampleSize = r2;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:331:0x05a6, code lost:
            r7.inSampleSize = (int) r0;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:332:0x05a9, code lost:
            r0 = r3;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:333:0x05ab, code lost:
            r0 = move-exception;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:334:0x05ac, code lost:
            r6 = r0;
            r5 = r3;
            r0 = 0.0f;
            r2 = 0.0f;
            r3 = null;
            r4 = false;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:335:0x05b3, code lost:
            r0 = null;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:336:0x05b4, code lost:
            r2 = 0.0f;
            r3 = null;
            r4 = false;
            r23 = 0.0f;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:337:0x05b9, code lost:
            r5 = r0;
            r0 = r23;
            r3 = r3;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:338:0x05bd, code lost:
            r0 = move-exception;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:339:0x05be, code lost:
            r6 = r0;
            r0 = 0.0f;
            r2 = 0.0f;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:33:0x00c1, code lost:
            r4 = new android.graphics.drawable.BitmapDrawable(r0);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:340:0x05c1, code lost:
            r3 = null;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:341:0x05c2, code lost:
            r4 = false;
            r3 = r3;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:342:0x05c3, code lost:
            r5 = null;
            r3 = r3;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:343:0x05c4, code lost:
            im.guobwnxjuc.messenger.FileLog.e(r6);
            r2 = r0;
            r0 = r2;
            r3 = r3;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:345:0x05d7, code lost:
            if (r33.cacheImage.imageType == 1) goto L_0x05d9;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:347:?, code lost:
            r33.this$0.lastCacheOutTime = java.lang.System.currentTimeMillis();
         */
        /* JADX WARNING: Code restructure failed: missing block: B:348:0x05e4, code lost:
            monitor-enter(r33.sync);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:34:0x00c7, code lost:
            r4 = null;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:351:0x05e7, code lost:
            if (r33.isCancelled != false) goto L_0x05e9;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:353:0x05ea, code lost:
            return;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:355:0x05ec, code lost:
            if (r13 == false) goto L_0x0633;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:356:0x05ee, code lost:
            r2 = new java.io.RandomAccessFile(r8, "r");
            r6 = r2.getChannel().map(java.nio.channels.FileChannel.MapMode.READ_ONLY, 0, r8.length());
            r9 = new android.graphics.BitmapFactory.Options();
            r9.inJustDecodeBounds = true;
            im.guobwnxjuc.messenger.Utilities.loadWebpImage(null, r6, r6.limit(), r9, true);
            r5 = im.guobwnxjuc.messenger.Bitmaps.createBitmap(r9.outWidth, r9.outHeight, android.graphics.Bitmap.Config.ARGB_8888);
            r9 = r6.limit();
         */
        /* JADX WARNING: Code restructure failed: missing block: B:357:0x0625, code lost:
            if (r7.inPurgeable != false) goto L_0x0629;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:358:0x0627, code lost:
            r10 = true;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:359:0x0629, code lost:
            r10 = false;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:35:0x00c8, code lost:
            onPostExecute(r4);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:360:0x062a, code lost:
            im.guobwnxjuc.messenger.Utilities.loadWebpImage(r5, r6, r9, null, r10);
            r2.close();
         */
        /* JADX WARNING: Code restructure failed: missing block: B:362:0x0635, code lost:
            if (r7.inPurgeable != false) goto L_0x0654;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:363:0x0637, code lost:
            if (r10 == null) goto L_0x063a;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:364:0x063a, code lost:
            if (r9 == false) goto L_0x0646;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:365:0x063c, code lost:
            r2 = new im.guobwnxjuc.messenger.secretmedia.EncryptedFileInputStream(r8, r33.cacheImage.encryptionKeyPath);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:366:0x0646, code lost:
            r2 = new java.io.FileInputStream(r8);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:367:0x064b, code lost:
            r5 = android.graphics.BitmapFactory.decodeStream(r2, null, r7);
            r2.close();
         */
        /* JADX WARNING: Code restructure failed: missing block: B:368:0x0654, code lost:
            r2 = new java.io.RandomAccessFile(r8, "r");
            r6 = (int) r2.length();
            r12 = (byte[]) im.guobwnxjuc.messenger.ImageLoader.bytesThumbLocal.get();
         */
        /* JADX WARNING: Code restructure failed: missing block: B:369:0x066a, code lost:
            if (r12 == null) goto L_0x0670;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:371:0x066d, code lost:
            if (r12.length < r6) goto L_0x0670;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:372:0x0670, code lost:
            r12 = null;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:373:0x0671, code lost:
            if (r12 != null) goto L_0x067c;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:374:0x0673, code lost:
            r12 = new byte[r6];
            im.guobwnxjuc.messenger.ImageLoader.bytesThumbLocal.set(r12);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:375:0x067c, code lost:
            r2.readFully(r12, 0, r6);
            r2.close();
         */
        /* JADX WARNING: Code restructure failed: missing block: B:376:0x0683, code lost:
            if (r10 == null) goto L_0x069f;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:377:0x0685, code lost:
            im.guobwnxjuc.messenger.secretmedia.EncryptedFileInputStream.decryptBytesWithKeyFile(r12, 0, r6, r10);
            r2 = im.guobwnxjuc.messenger.Utilities.computeSHA256(r12, 0, r6);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:378:0x068c, code lost:
            if (r11 == null) goto L_0x0697;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:380:0x0692, code lost:
            if (java.util.Arrays.equals(r2, r11) != false) goto L_0x0695;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:381:0x0695, code lost:
            r2 = false;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:382:0x0697, code lost:
            r2 = true;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:383:0x0698, code lost:
            r9 = r12[0] & kotlin.UByte.MAX_VALUE;
            r6 = r6 - r9;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:384:0x069f, code lost:
            if (r9 == false) goto L_0x06a9;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:385:0x06a1, code lost:
            im.guobwnxjuc.messenger.secretmedia.EncryptedFileInputStream.decryptBytesWithKeyFile(r12, 0, r6, r33.cacheImage.encryptionKeyPath);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:386:0x06a9, code lost:
            r2 = false;
            r9 = 0;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:387:0x06ab, code lost:
            if (r2 != false) goto L_0x06b1;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:388:0x06ad, code lost:
            r5 = android.graphics.BitmapFactory.decodeByteArray(r12, r9, r6, r7);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:389:0x06b1, code lost:
            if (r5 != null) goto L_0x06c9;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:391:0x06bb, code lost:
            if (r8.length() == 0) goto L_0x06c3;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:393:0x06c1, code lost:
            if (r33.cacheImage.filter != null) goto L_0x06c6;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:394:0x06c3, code lost:
            r8.delete();
         */
        /* JADX WARNING: Code restructure failed: missing block: B:395:0x06c6, code lost:
            r2 = false;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:397:0x06cd, code lost:
            if (r33.cacheImage.filter == null) goto L_0x06fa;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:398:0x06cf, code lost:
            r2 = (float) r5.getWidth();
            r6 = (float) r5.getHeight();
         */
        /* JADX WARNING: Code restructure failed: missing block: B:399:0x06db, code lost:
            if (r7.inPurgeable != false) goto L_0x06fa;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:401:0x06df, code lost:
            if (r0 == 0.0f) goto L_0x06fa;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:403:0x06e3, code lost:
            if (r2 == r0) goto L_0x06fa;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:405:0x06e9, code lost:
            if (r2 <= (r0 + 20.0f)) goto L_0x06fa;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:406:0x06eb, code lost:
            r0 = im.guobwnxjuc.messenger.Bitmaps.createScaledBitmap(r5, (int) r0, (int) (r6 / (r2 / r0)), true);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:407:0x06f4, code lost:
            if (r5 == r0) goto L_0x06fa;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:408:0x06f6, code lost:
            r5.recycle();
            r5 = r0;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:409:0x06fa, code lost:
            if (r4 == false) goto L_0x071a;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:40:0x00d6, code lost:
            if (r33.cacheImage.lottieFile == false) goto L_0x01e8;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:411:0x06fe, code lost:
            if (r7.inPurgeable == false) goto L_0x0702;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:412:0x0700, code lost:
            r0 = 0;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:413:0x0702, code lost:
            r0 = 1;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:415:0x0713, code lost:
            if (im.guobwnxjuc.messenger.Utilities.needInvert(r5, r0, r5.getWidth(), r5.getHeight(), r5.getRowBytes()) == 0) goto L_0x0717;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:416:0x0715, code lost:
            r0 = true;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:417:0x0717, code lost:
            r0 = false;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:418:0x0718, code lost:
            r2 = r0;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:419:0x071a, code lost:
            r2 = false;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:41:0x00d8, code lost:
            r8 = r33.sync;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:421:0x071c, code lost:
            if (r3 != 1) goto L_0x0743;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:424:0x0724, code lost:
            if (r5.getConfig() != android.graphics.Bitmap.Config.ARGB_8888) goto L_0x07ce;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:426:0x0729, code lost:
            if (r7.inPurgeable == false) goto L_0x072d;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:427:0x072b, code lost:
            r10 = 0;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:428:0x072d, code lost:
            r10 = 1;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:429:0x072e, code lost:
            im.guobwnxjuc.messenger.Utilities.blurBitmap(r5, 3, r10, r5.getWidth(), r5.getHeight(), r5.getRowBytes());
         */
        /* JADX WARNING: Code restructure failed: missing block: B:42:0x00da, code lost:
            monitor-enter(r8);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:430:0x0740, code lost:
            r0 = th;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:433:0x0744, code lost:
            if (r3 != 2) goto L_0x0768;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:435:0x074c, code lost:
            if (r5.getConfig() != android.graphics.Bitmap.Config.ARGB_8888) goto L_0x07ce;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:437:0x0751, code lost:
            if (r7.inPurgeable == false) goto L_0x0755;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:438:0x0753, code lost:
            r10 = 0;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:439:0x0755, code lost:
            r10 = 1;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:440:0x0756, code lost:
            im.guobwnxjuc.messenger.Utilities.blurBitmap(r5, 1, r10, r5.getWidth(), r5.getHeight(), r5.getRowBytes());
         */
        /* JADX WARNING: Code restructure failed: missing block: B:442:0x0769, code lost:
            if (r3 != 3) goto L_0x07bc;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:444:0x0771, code lost:
            if (r5.getConfig() != android.graphics.Bitmap.Config.ARGB_8888) goto L_0x07ce;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:446:0x0776, code lost:
            if (r7.inPurgeable == false) goto L_0x077a;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:447:0x0778, code lost:
            r10 = 0;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:448:0x077a, code lost:
            r10 = 1;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:449:0x077b, code lost:
            im.guobwnxjuc.messenger.Utilities.blurBitmap(r5, 7, r10, r5.getWidth(), r5.getHeight(), r5.getRowBytes());
         */
        /* JADX WARNING: Code restructure failed: missing block: B:450:0x078e, code lost:
            if (r7.inPurgeable == false) goto L_0x0792;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:451:0x0790, code lost:
            r10 = 0;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:452:0x0792, code lost:
            r10 = 1;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:453:0x0793, code lost:
            im.guobwnxjuc.messenger.Utilities.blurBitmap(r5, 7, r10, r5.getWidth(), r5.getHeight(), r5.getRowBytes());
         */
        /* JADX WARNING: Code restructure failed: missing block: B:454:0x07a6, code lost:
            if (r7.inPurgeable == false) goto L_0x07aa;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:455:0x07a8, code lost:
            r10 = 0;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:456:0x07aa, code lost:
            r10 = 1;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:457:0x07ab, code lost:
            im.guobwnxjuc.messenger.Utilities.blurBitmap(r5, 7, r10, r5.getWidth(), r5.getHeight(), r5.getRowBytes());
         */
        /* JADX WARNING: Code restructure failed: missing block: B:458:0x07bc, code lost:
            if (r3 != null) goto L_0x07ce;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:45:0x00dd, code lost:
            if (r33.isCancelled == false) goto L_0x00e1;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:460:0x07c0, code lost:
            if (r7.inPurgeable == false) goto L_0x07ce;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:461:0x07c2, code lost:
            im.guobwnxjuc.messenger.Utilities.pinBitmap(r5);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:465:0x07c9, code lost:
            r0 = th;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:466:0x07ca, code lost:
            r2 = false;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:467:0x07cb, code lost:
            im.guobwnxjuc.messenger.FileLog.e(r0);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:468:0x07ce, code lost:
            r6 = 0;
            r12 = null;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:469:0x07d2, code lost:
            r6 = 20;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:46:0x00df, code lost:
            monitor-exit(r8);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:470:0x07d4, code lost:
            if (r15 != null) goto L_0x07d6;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:471:0x07d6, code lost:
            r6 = 0;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:472:0x07d7, code lost:
            if (r6 != 0) goto L_0x07d9;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:475:0x07e3, code lost:
            if (r33.this$0.lastCacheOutTime != 0) goto L_0x07e5;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:477:0x07ef, code lost:
            r24 = r5;
            r5 = (long) r6;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:478:0x07f6, code lost:
            if (r33.this$0.lastCacheOutTime > (java.lang.System.currentTimeMillis() - r5)) goto L_0x07f8;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:47:0x00e0, code lost:
            return;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:481:0x07fc, code lost:
            if (android.os.Build.VERSION.SDK_INT < 21) goto L_0x07fe;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:482:0x07fe, code lost:
            java.lang.Thread.sleep(r5);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:483:0x0802, code lost:
            r5 = r24;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:487:0x0807, code lost:
            r6 = false;
            r12 = null;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:489:0x080b, code lost:
            r24 = r5;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:48:0x00e1, code lost:
            monitor-exit(r8);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:491:?, code lost:
            r33.this$0.lastCacheOutTime = java.lang.System.currentTimeMillis();
         */
        /* JADX WARNING: Code restructure failed: missing block: B:492:0x0818, code lost:
            monitor-enter(r33.sync);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:495:0x081b, code lost:
            if (r33.isCancelled != false) goto L_0x081d;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:497:0x081e, code lost:
            return;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:499:0x0820, code lost:
            if (r19 != false) goto L_0x0838;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:49:0x00e2, code lost:
            r8 = java.lang.Math.min(512, im.guobwnxjuc.messenger.AndroidUtilities.dp(170.6f));
            r0 = java.lang.Math.min(512, im.guobwnxjuc.messenger.AndroidUtilities.dp(170.6f));
         */
        /* JADX WARNING: Code restructure failed: missing block: B:501:0x0826, code lost:
            if (r33.cacheImage.filter == null) goto L_0x0838;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:502:0x0828, code lost:
            if (r3 != null) goto L_0x0838;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:504:0x0830, code lost:
            if (r33.cacheImage.imageLocation.path == null) goto L_0x0833;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:505:0x0833, code lost:
            r7.inPreferredConfig = android.graphics.Bitmap.Config.RGB_565;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:506:0x0838, code lost:
            r7.inPreferredConfig = android.graphics.Bitmap.Config.ARGB_8888;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:507:0x083c, code lost:
            r7.inDither = false;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:508:0x083f, code lost:
            if (r15 == null) goto L_0x0865;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:509:0x0841, code lost:
            if (r12 != null) goto L_0x0865;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:50:0x00fb, code lost:
            if (r33.cacheImage.filter == null) goto L_0x01cb;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:510:0x0843, code lost:
            if (r14 == false) goto L_0x0855;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:511:0x0845, code lost:
            r5 = android.provider.MediaStore.Video.Thumbnails.getThumbnail(im.guobwnxjuc.messenger.ApplicationLoader.applicationContext.getContentResolver(), r15.longValue(), 1, r7);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:512:0x0855, code lost:
            r5 = android.provider.MediaStore.Images.Thumbnails.getThumbnail(im.guobwnxjuc.messenger.ApplicationLoader.applicationContext.getContentResolver(), r15.longValue(), 1, r7);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:513:0x0865, code lost:
            r5 = r24;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:514:0x0867, code lost:
            if (r5 != null) goto L_0x0974;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:515:0x0869, code lost:
            if (r13 == false) goto L_0x08b5;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:517:?, code lost:
            r6 = new java.io.RandomAccessFile(r8, "r");
            r9 = r6.getChannel().map(java.nio.channels.FileChannel.MapMode.READ_ONLY, 0, r8.length());
            r10 = new android.graphics.BitmapFactory.Options();
            r10.inJustDecodeBounds = true;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:51:0x00fd, code lost:
            r10 = r33.cacheImage.filter.split("_");
         */
        /* JADX WARNING: Code restructure failed: missing block: B:520:?, code lost:
            im.guobwnxjuc.messenger.Utilities.loadWebpImage(null, r9, r9.limit(), r10, true);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:521:0x0892, code lost:
            r5 = im.guobwnxjuc.messenger.Bitmaps.createBitmap(r10.outWidth, r10.outHeight, android.graphics.Bitmap.Config.ARGB_8888);
            r10 = r9.limit();
         */
        /* JADX WARNING: Code restructure failed: missing block: B:522:0x08a2, code lost:
            if (r7.inPurgeable != false) goto L_0x08a6;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:523:0x08a4, code lost:
            r11 = true;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:524:0x08a6, code lost:
            r11 = false;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:525:0x08a7, code lost:
            r12 = null;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:527:?, code lost:
            im.guobwnxjuc.messenger.Utilities.loadWebpImage(r5, r9, r10, null, r11);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:528:0x08ab, code lost:
            r6.close();
            r9 = 0;
            r12 = null;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:529:0x08b2, code lost:
            r12 = null;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:52:0x0108, code lost:
            if (r10.length < 2) goto L_0x0148;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:533:0x08b7, code lost:
            if (r7.inPurgeable != false) goto L_0x0912;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:534:0x08b9, code lost:
            if (r10 == null) goto L_0x08bc;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:535:0x08bc, code lost:
            if (r9 == false) goto L_0x08c8;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:536:0x08be, code lost:
            r6 = new im.guobwnxjuc.messenger.secretmedia.EncryptedFileInputStream(r8, r33.cacheImage.encryptionKeyPath);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:537:0x08c8, code lost:
            r6 = new java.io.FileInputStream(r8);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:539:0x08d5, code lost:
            if ((r33.cacheImage.imageLocation.document instanceof im.guobwnxjuc.tgnet.TLRPC.TL_document) == false) goto L_0x0908;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:53:0x010a, code lost:
            r0 = java.lang.Float.parseFloat(r10[0]);
            r8 = java.lang.Float.parseFloat(r10[1]);
            r11 = java.lang.Math.min(512, (int) (im.guobwnxjuc.messenger.AndroidUtilities.density * r0));
            r9 = java.lang.Math.min(512, (int) (im.guobwnxjuc.messenger.AndroidUtilities.density * r8));
         */
        /* JADX WARNING: Code restructure failed: missing block: B:541:?, code lost:
            r9 = new androidx.exifinterface.media.ExifInterface(r6).getAttributeInt(androidx.exifinterface.media.ExifInterface.TAG_ORIENTATION, 1);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:543:0x08e4, code lost:
            if (r9 == 3) goto L_0x08f4;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:545:0x08e7, code lost:
            if (r9 == 6) goto L_0x08f1;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:547:0x08eb, code lost:
            if (r9 == 8) goto L_0x08ee;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:548:0x08ee, code lost:
            r9 = 270;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:549:0x08f1, code lost:
            r9 = 90;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:54:0x012c, code lost:
            if (r0 > 90.0f) goto L_0x0146;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:550:0x08f4, code lost:
            r9 = 180;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:557:0x0908, code lost:
            r9 = 0;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:561:0x0912, code lost:
            r12 = null;
            r6 = new java.io.RandomAccessFile(r8, "r");
            r14 = (int) r6.length();
            r13 = (byte[]) im.guobwnxjuc.messenger.ImageLoader.bytesLocal.get();
         */
        /* JADX WARNING: Code restructure failed: missing block: B:562:0x0929, code lost:
            if (r13 == null) goto L_0x092f;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:564:0x092c, code lost:
            if (r13.length < r14) goto L_0x092f;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:565:0x092f, code lost:
            r13 = null;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:566:0x0930, code lost:
            if (r13 != null) goto L_0x093b;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:567:0x0932, code lost:
            r13 = new byte[r14];
            im.guobwnxjuc.messenger.ImageLoader.bytesLocal.set(r13);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:568:0x093b, code lost:
            r6.readFully(r13, 0, r14);
            r6.close();
         */
        /* JADX WARNING: Code restructure failed: missing block: B:569:0x0942, code lost:
            if (r10 == null) goto L_0x095e;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:56:0x0130, code lost:
            if (r8 > 90.0f) goto L_0x0146;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:570:0x0944, code lost:
            im.guobwnxjuc.messenger.secretmedia.EncryptedFileInputStream.decryptBytesWithKeyFile(r13, 0, r14, r10);
            r6 = im.guobwnxjuc.messenger.Utilities.computeSHA256(r13, 0, r14);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:571:0x094b, code lost:
            if (r11 == null) goto L_0x0956;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:573:0x0951, code lost:
            if (java.util.Arrays.equals(r6, r11) != false) goto L_0x0954;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:574:0x0954, code lost:
            r6 = false;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:575:0x0956, code lost:
            r6 = true;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:576:0x0957, code lost:
            r9 = r13[0] & kotlin.UByte.MAX_VALUE;
            r14 = r14 - r9;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:577:0x095e, code lost:
            if (r9 == false) goto L_0x0968;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:578:0x0960, code lost:
            im.guobwnxjuc.messenger.secretmedia.EncryptedFileInputStream.decryptBytesWithKeyFile(r13, 0, r14, r33.cacheImage.encryptionKeyPath);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:579:0x0968, code lost:
            r6 = false;
            r9 = 0;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:57:0x0132, code lost:
            r8 = java.lang.Math.min(r11, 160);
            r0 = java.lang.Math.min(r9, 160);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:580:0x096a, code lost:
            if (r6 != false) goto L_0x0975;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:581:0x096c, code lost:
            r5 = android.graphics.BitmapFactory.decodeByteArray(r13, r9, r14, r7);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:582:0x0971, code lost:
            r12 = null;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:584:0x0974, code lost:
            r12 = null;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:585:0x0975, code lost:
            r9 = 0;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:58:0x0140, code lost:
            if (im.guobwnxjuc.messenger.SharedConfig.getDevicePerfomanceClass() == 2) goto L_0x0143;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:59:0x0142, code lost:
            r6 = true;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:60:0x0143, code lost:
            r11 = r8;
            r8 = true;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:61:0x0146, code lost:
            r0 = r9;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:62:0x0148, code lost:
            r11 = r8;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:63:0x0149, code lost:
            r8 = false;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:65:0x014b, code lost:
            if (r10.length < 3) goto L_0x0164;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:663:0x0a6a, code lost:
            r0 = th;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:664:0x0a6b, code lost:
            r12 = null;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:668:?, code lost:
            throw r0;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:669:0x0a6f, code lost:
            r0 = th;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:670:0x0a71, code lost:
            r12 = null;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:672:0x0a73, code lost:
            r5 = r24;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:674:0x0a75, code lost:
            r6 = false;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:676:0x0a76, code lost:
            r25 = 0;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:67:0x0155, code lost:
            if ("nr".equals(r10[2]) == false) goto L_0x0159;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:681:0x0a83, code lost:
            if (r5 != null) goto L_0x0a85;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:682:0x0a85, code lost:
            r4 = new android.graphics.drawable.BitmapDrawable(r5);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:683:0x0a8b, code lost:
            r4 = r12;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:684:0x0a8c, code lost:
            onPostExecute(r4);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:686:0x0a92, code lost:
            r4 = new im.guobwnxjuc.messenger.ExtendedBitmapDrawable(r5, r2, r6);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:687:0x0a98, code lost:
            r4 = r12;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:68:0x0157, code lost:
            r2 = 2;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:696:?, code lost:
            return;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:697:?, code lost:
            return;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:698:?, code lost:
            return;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:699:?, code lost:
            return;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:70:0x0161, code lost:
            if ("nrs".equals(r10[2]) == false) goto L_0x0164;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:71:0x0164, code lost:
            r2 = 1;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:73:0x0167, code lost:
            if (r10.length < 5) goto L_0x01c3;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:75:0x0172, code lost:
            if ("c1".equals(r10[4]) == false) goto L_0x0183;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:76:0x0174, code lost:
            r4 = new int[]{16219713, 13275258, 16757049, 15582629, 16765248, 16245699, 16768889, 16510934};
         */
        /* JADX WARNING: Code restructure failed: missing block: B:77:0x0179, code lost:
            r15 = r0;
            r5 = r2;
            r18 = r4;
            r16 = r6;
            r17 = r8;
            r14 = r11;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:79:0x018b, code lost:
            if ("c2".equals(r10[4]) == false) goto L_0x0193;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:80:0x018d, code lost:
            r4 = new int[]{16219713, 11172960, 16757049, 13150599, 16765248, 14534815, 16768889, 15128242};
         */
        /* JADX WARNING: Code restructure failed: missing block: B:82:0x019b, code lost:
            if ("c3".equals(r10[4]) == false) goto L_0x01a3;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:83:0x019d, code lost:
            r4 = new int[]{16219713, 9199944, 16757049, 11371874, 16765248, 12885622, 16768889, 13939080};
         */
        /* JADX WARNING: Code restructure failed: missing block: B:85:0x01ab, code lost:
            if ("c4".equals(r10[4]) == false) goto L_0x01b3;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:86:0x01ad, code lost:
            r4 = new int[]{16219713, 7224364, 16757049, 9591348, 16765248, 10579526, 16768889, 11303506};
         */
        /* JADX WARNING: Code restructure failed: missing block: B:88:0x01bb, code lost:
            if ("c5".equals(r10[4]) == false) goto L_0x01c3;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:89:0x01bd, code lost:
            r4 = new int[]{16219713, 2694162, 16757049, 4663842, 16765248, 5716784, 16768889, 6834492};
         */
        /* JADX WARNING: Code restructure failed: missing block: B:8:0x0015, code lost:
            r2 = 3;
            r5 = 1;
            r6 = false;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:90:0x01c3, code lost:
            r15 = r0;
            r5 = r2;
            r16 = r6;
            r17 = r8;
            r14 = r11;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:91:0x01cb, code lost:
            r15 = r0;
            r14 = r8;
            r16 = false;
            r17 = false;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:92:0x01d1, code lost:
            r18 = null;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:93:0x01d3, code lost:
            r0 = new im.guobwnxjuc.ui.components.RLottieDrawable(r33.cacheImage.finalFilePath, r14, r15, r16, r17, r18);
            r0.setAutoRepeat(r5);
            onPostExecute(r0);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:98:0x01ec, code lost:
            if (r33.cacheImage.animatedFile == false) goto L_0x0268;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:99:0x01ee, code lost:
            r8 = r33.sync;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:9:0x0021, code lost:
            if ((r33.cacheImage.imageLocation.photoSize instanceof im.guobwnxjuc.tgnet.TLRPC.TL_photoStrippedSize) == false) goto L_0x00d0;
         */
        /* JADX WARNING: Removed duplicated region for block: B:171:0x0319  */
        /* JADX WARNING: Removed duplicated region for block: B:175:0x0322 A[SYNTHETIC, Splitter:B:175:0x0322] */
        /* JADX WARNING: Removed duplicated region for block: B:183:0x0335  */
        /* JADX WARNING: Removed duplicated region for block: B:204:0x03ac  */
        /* JADX WARNING: Removed duplicated region for block: B:209:0x03be A[Catch:{ all -> 0x05bd }] */
        /* JADX WARNING: Removed duplicated region for block: B:315:0x0563  */
        /* JADX WARNING: Removed duplicated region for block: B:346:0x05d9 A[SYNTHETIC, Splitter:B:346:0x05d9] */
        /* JADX WARNING: Removed duplicated region for block: B:469:0x07d2  */
        /* JADX WARNING: Removed duplicated region for block: B:493:0x0819 A[SYNTHETIC, Splitter:B:493:0x0819] */
        /* JADX WARNING: Removed duplicated region for block: B:650:0x0a55 A[SYNTHETIC, Splitter:B:650:0x0a55] */
        /* JADX WARNING: Removed duplicated region for block: B:680:0x0a80 A[ADDED_TO_REGION] */
        /* JADX WARNING: Removed duplicated region for block: B:686:0x0a92  */
        /* JADX WARNING: Removed duplicated region for block: B:687:0x0a98  */
        /* JADX WARNING: Unknown variable types count: 1 */
        public void run() {
            File file;
            boolean z;
            BitmapFactory.Options options;
            Bitmap bitmap;
            boolean z2;
            String str;
            float f;
            float f2;
            ExtendedBitmapDrawable extendedBitmapDrawable;
            int i;
            boolean z3;
            ExtendedBitmapDrawable extendedBitmapDrawable2;
            int i2;
            boolean z4;
            boolean z5;
            Bitmap bitmap2;
            boolean z6;
            Bitmap bitmap3;
            FileInputStream fileInputStream;
            synchronized (this.sync) {
                this.runningThread = Thread.currentThread();
                Thread.interrupted();
                if (this.isCancelled) {
                    return;
                }
            }
            int i3 = 0;
            try {
                fileInputStream.getChannel().position(0L);
                extendedBitmapDrawable = null;
                try {
                    bitmap = BitmapFactory.decodeStream(fileInputStream, null, options);
                    fileInputStream.close();
                    if (bitmap == null) {
                        if (z && (file.length() == 0 || this.cacheImage.filter == null)) {
                            file.delete();
                        }
                        z4 = false;
                    } else {
                        try {
                            if (this.cacheImage.filter != null) {
                                float width = (float) bitmap.getWidth();
                                float height = (float) bitmap.getHeight();
                                if (!options.inPurgeable && f2 != 0.0f && width != f2 && width > f2 + 20.0f) {
                                    if (width <= height || f2 <= f) {
                                        bitmap3 = Bitmaps.createScaledBitmap(bitmap, (int) (width / (height / f)), (int) f, true);
                                    } else {
                                        bitmap3 = Bitmaps.createScaledBitmap(bitmap, (int) f2, (int) (height / (width / f2)), true);
                                    }
                                    if (bitmap != bitmap3) {
                                        bitmap.recycle();
                                        bitmap = bitmap3;
                                    }
                                }
                                if (bitmap != null) {
                                    if (z2) {
                                        Bitmap createScaledBitmap = bitmap.getWidth() * bitmap.getHeight() > 22500 ? Bitmaps.createScaledBitmap(bitmap, 100, 100, false) : bitmap;
                                        z6 = Utilities.needInvert(createScaledBitmap, options.inPurgeable ? 0 : 1, createScaledBitmap.getWidth(), createScaledBitmap.getHeight(), createScaledBitmap.getRowBytes()) != 0;
                                        if (createScaledBitmap != bitmap) {
                                            try {
                                                createScaledBitmap.recycle();
                                            } catch (Throwable unused) {
                                                z4 = z6;
                                                i2 = i3;
                                                z3 = z4;
                                                i = i2;
                                                Thread.interrupted();
                                                if (!z3) {
                                                }
                                                if (bitmap == null) {
                                                }
                                                onPostExecute(extendedBitmapDrawable2);
                                            }
                                        }
                                    } else {
                                        z6 = false;
                                    }
                                    if (str == null || height >= 100.0f || width >= 100.0f) {
                                        z4 = z6;
                                        bitmap2 = bitmap;
                                        z5 = false;
                                        if (!z5) {
                                            try {
                                                if (options.inPurgeable) {
                                                    Utilities.pinBitmap(bitmap2);
                                                }
                                            } catch (Throwable unused2) {
                                                bitmap = bitmap2;
                                                i2 = i3;
                                                z3 = z4;
                                                i = i2;
                                                Thread.interrupted();
                                                if (!z3) {
                                                }
                                                if (bitmap == null) {
                                                }
                                                onPostExecute(extendedBitmapDrawable2);
                                            }
                                        }
                                        bitmap = bitmap2;
                                    } else {
                                        if (bitmap.getConfig() == Bitmap.Config.ARGB_8888) {
                                            Utilities.blurBitmap(bitmap, 3, options.inPurgeable ? 0 : 1, bitmap.getWidth(), bitmap.getHeight(), bitmap.getRowBytes());
                                        }
                                        z4 = z6;
                                        bitmap2 = bitmap;
                                        z5 = true;
                                        if (!z5) {
                                        }
                                        bitmap = bitmap2;
                                    }
                                }
                            }
                            bitmap2 = bitmap;
                            z5 = false;
                            z4 = false;
                            if (!z5) {
                            }
                            bitmap = bitmap2;
                        } catch (Throwable unused3) {
                            i2 = i3;
                            z4 = false;
                            z3 = z4;
                            i = i2;
                            Thread.interrupted();
                            if (!z3) {
                            }
                            if (bitmap == null) {
                            }
                            onPostExecute(extendedBitmapDrawable2);
                        }
                    }
                    z3 = z4;
                    i = i3;
                } catch (Throwable unused4) {
                }
            } catch (Throwable unused5) {
                i2 = i3;
                z4 = false;
                extendedBitmapDrawable = null;
            }
            Thread.interrupted();
            if (!z3) {
            }
            if (bitmap == null) {
            }
            onPostExecute(extendedBitmapDrawable2);
        }

        private void onPostExecute(Drawable drawable) {
            AndroidUtilities.runOnUIThread(new Runnable(drawable) {
                /* class im.guobwnxjuc.messenger.$$Lambda$ImageLoader$CacheOutTask$1sjefDy6Pci05b8Vf0RqC8rZyMo */
                private final /* synthetic */ Drawable f$1;

                {
                    this.f$1 = r2;
                }

                public final void run() {
                    ImageLoader.CacheOutTask.this.lambda$onPostExecute$1$ImageLoader$CacheOutTask(this.f$1);
                }
            });
        }

        /* JADX DEBUG: Failed to insert an additional move for type inference into block B:16:0x006e */
        public /* synthetic */ void lambda$onPostExecute$1$ImageLoader$CacheOutTask(Drawable drawable) {
            String str = null;
            if (drawable instanceof RLottieDrawable) {
                RLottieDrawable rLottieDrawable = (RLottieDrawable) drawable;
                Drawable drawable2 = (Drawable) ImageLoader.this.lottieMemCache.get(this.cacheImage.key);
                if (drawable2 == null) {
                    ImageLoader.this.lottieMemCache.put(this.cacheImage.key, rLottieDrawable);
                    drawable = rLottieDrawable;
                } else {
                    rLottieDrawable.recycle();
                    drawable = drawable2;
                }
                if (drawable != null) {
                    ImageLoader.this.incrementUseCount(this.cacheImage.key);
                    str = this.cacheImage.key;
                }
            } else if (!(drawable instanceof AnimatedFileDrawable)) {
                if (drawable instanceof BitmapDrawable) {
                    BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
                    Drawable drawable3 = (Drawable) ImageLoader.this.memCache.get(this.cacheImage.key);
                    if (drawable3 == null) {
                        ImageLoader.this.memCache.put(this.cacheImage.key, bitmapDrawable);
                        drawable = bitmapDrawable;
                    } else {
                        bitmapDrawable.getBitmap().recycle();
                        drawable = drawable3;
                    }
                    if (drawable != null) {
                        ImageLoader.this.incrementUseCount(this.cacheImage.key);
                        str = this.cacheImage.key;
                    }
                } else {
                    drawable = null;
                }
            }
            ImageLoader.this.imageLoadQueue.postRunnable(new Runnable(drawable, str) {
                /* class im.guobwnxjuc.messenger.$$Lambda$ImageLoader$CacheOutTask$X8k5c1rQpEVrGHikWea8b0nxe3A */
                private final /* synthetic */ Drawable f$1;
                private final /* synthetic */ String f$2;

                {
                    this.f$1 = r2;
                    this.f$2 = r3;
                }

                public final void run() {
                    ImageLoader.CacheOutTask.this.lambda$null$0$ImageLoader$CacheOutTask(this.f$1, this.f$2);
                }
            });
        }

        public /* synthetic */ void lambda$null$0$ImageLoader$CacheOutTask(Drawable drawable, String str) {
            this.cacheImage.setImageAndClear(drawable, str);
        }

        /* JADX WARNING: Exception block dominator not found, dom blocks: [] */
        /* JADX WARNING: Missing exception handler attribute for start block: B:8:0x0012 */
        public void cancel() {
            synchronized (this.sync) {
                this.isCancelled = true;
                if (this.runningThread != null) {
                    this.runningThread.interrupt();
                }
            }
        }
    }

    /* access modifiers changed from: private */
    public class CacheImage {
        protected boolean animatedFile;
        protected ArtworkLoadTask artworkTask;
        protected CacheOutTask cacheTask;
        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;
        protected ArrayList<Integer> imageTypes;
        protected String key;
        protected ArrayList<String> keys;
        protected boolean lottieFile;
        protected Object parentObject;
        protected SecureDocument secureDocument;
        protected int size;
        protected File tempFilePath;
        protected String url;

        private CacheImage() {
            this.imageReceiverArray = new ArrayList<>();
            this.imageReceiverGuidsArray = new ArrayList<>();
            this.keys = new ArrayList<>();
            this.filters = new ArrayList<>();
            this.imageTypes = new ArrayList<>();
        }

        public void addImageReceiver(ImageReceiver imageReceiver, String str, String str2, int i, int i2) {
            int indexOf = this.imageReceiverArray.indexOf(imageReceiver);
            if (indexOf >= 0) {
                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.imageTypes.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) {
                if (this.imageTypes.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 removeImageReceiver(ImageReceiver imageReceiver) {
            int i = this.imageType;
            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.imageTypes.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)) {
                    if (this.imageLocation.location != null) {
                        FileLoader.getInstance(this.currentAccount).cancelLoadFile(this.imageLocation.location, this.ext);
                    } else if (this.imageLocation.document != null) {
                        FileLoader.getInstance(this.currentAccount).cancelLoadFile(this.imageLocation.document);
                    } else if (this.imageLocation.secureDocument != null) {
                        FileLoader.getInstance(this.currentAccount).cancelLoadFile(this.imageLocation.secureDocument);
                    } else if (this.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);
                    }
                    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.key != null) {
                    ImageLoader.this.imageLoadingByKeys.remove(this.key);
                }
            }
        }

        public void setImageAndClear(Drawable drawable, String str) {
            if (drawable != null) {
                AndroidUtilities.runOnUIThread(new Runnable(drawable, new ArrayList(this.imageReceiverArray), new ArrayList(this.imageReceiverGuidsArray), str) {
                    /* class im.guobwnxjuc.messenger.$$Lambda$ImageLoader$CacheImage$JV8mL0_gygdbOmHdxS4SAbSD5H8 */
                    private final /* synthetic */ Drawable f$1;
                    private final /* synthetic */ ArrayList f$2;
                    private final /* synthetic */ ArrayList f$3;
                    private final /* synthetic */ String f$4;

                    {
                        this.f$1 = r2;
                        this.f$2 = r3;
                        this.f$3 = r4;
                        this.f$4 = r5;
                    }

                    public final void run() {
                        ImageLoader.CacheImage.this.lambda$setImageAndClear$0$ImageLoader$CacheImage(this.f$1, this.f$2, this.f$3, this.f$4);
                    }
                });
            }
            for (int i = 0; i < this.imageReceiverArray.size(); i++) {
                ImageLoader.this.imageLoadingByTag.remove(this.imageReceiverArray.get(i).getTag(this.imageType));
            }
            this.imageReceiverArray.clear();
            this.imageReceiverGuidsArray.clear();
            if (this.url != null) {
                ImageLoader.this.imageLoadingByUrl.remove(this.url);
            }
            if (this.key != null) {
                ImageLoader.this.imageLoadingByKeys.remove(this.key);
            }
        }

        public /* synthetic */ void lambda$setImageAndClear$0$ImageLoader$CacheImage(Drawable drawable, ArrayList arrayList, ArrayList arrayList2, String str) {
            AnimatedFileDrawable animatedFileDrawable;
            int i = 0;
            if (drawable instanceof AnimatedFileDrawable) {
                AnimatedFileDrawable animatedFileDrawable2 = (AnimatedFileDrawable) drawable;
                boolean z = false;
                while (i < arrayList.size()) {
                    ImageReceiver imageReceiver = (ImageReceiver) arrayList.get(i);
                    if (i == 0) {
                        animatedFileDrawable = animatedFileDrawable2;
                    } else {
                        animatedFileDrawable = animatedFileDrawable2.makeCopy();
                    }
                    if (imageReceiver.setImageBitmapByKey(animatedFileDrawable, this.key, this.imageType, false, ((Integer) arrayList2.get(i)).intValue())) {
                        if (animatedFileDrawable == animatedFileDrawable2) {
                            z = true;
                        }
                    } else if (animatedFileDrawable != animatedFileDrawable2) {
                        animatedFileDrawable.recycle();
                    }
                    i++;
                }
                if (!z) {
                    animatedFileDrawable2.recycle();
                }
            } else {
                while (i < arrayList.size()) {
                    ((ImageReceiver) arrayList.get(i)).setImageBitmapByKey(drawable, this.key, this.imageTypes.get(i).intValue(), false, ((Integer) arrayList2.get(i)).intValue());
                    i++;
                }
            }
            if (str != null) {
                ImageLoader.this.decrementUseCount(str);
            }
        }
    }

    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.currentHttpTasksCount = 0;
        this.currentArtworkTasksCount = 0;
        this.testWebFile = new ConcurrentHashMap<>();
        this.httpFileLoadTasks = new LinkedList<>();
        this.httpFileLoadTasksByKeys = new HashMap<>();
        this.retryHttpsTasks = new HashMap<>();
        this.currentHttpFileLoadTasksCount = 0;
        this.ignoreRemoval = null;
        this.lastCacheOutTime = 0;
        this.lastImageNum = 0;
        this.lastProgressUpdateTime = 0;
        this.appPath = null;
        boolean z = true;
        this.thumbGeneratingQueue.setPriority(1);
        int memoryClass = ((ActivityManager) ApplicationLoader.applicationContext.getSystemService("activity")).getMemoryClass();
        z = memoryClass < 192 ? false : z;
        this.canForce8888 = z;
        this.memCache = new LruCache<BitmapDrawable>(Math.min(z ? 30 : 15, memoryClass / 7) * 1024 * 1024) {
            /* class im.guobwnxjuc.messenger.ImageLoader.AnonymousClass1 */

            /* access modifiers changed from: protected */
            public int sizeOf(String str, BitmapDrawable bitmapDrawable) {
                return bitmapDrawable.getBitmap().getByteCount();
            }

            /* access modifiers changed from: protected */
            public void entryRemoved(boolean z, 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()) {
                            bitmap.recycle();
                        }
                    }
                }
            }
        };
        this.lottieMemCache = new LruCache<RLottieDrawable>(10485760) {
            /* class im.guobwnxjuc.messenger.ImageLoader.AnonymousClass2 */

            /* access modifiers changed from: protected */
            public int sizeOf(String str, RLottieDrawable rLottieDrawable) {
                return rLottieDrawable.getIntrinsicWidth() * rLottieDrawable.getIntrinsicHeight() * 4 * 2;
            }

            /* access modifiers changed from: protected */
            public void entryRemoved(boolean z, String str, RLottieDrawable rLottieDrawable, RLottieDrawable rLottieDrawable2) {
                Integer num = (Integer) ImageLoader.this.bitmapUseCounts.get(str);
                if (num == null || num.intValue() == 0) {
                    rLottieDrawable.recycle();
                }
            }
        };
        SparseArray sparseArray = new SparseArray();
        File cacheDir = AndroidUtilities.getCacheDir();
        if (!cacheDir.isDirectory()) {
            try {
                cacheDir.mkdirs();
            } catch (Exception e) {
                FileLog.e(e);
            }
        }
        try {
            new File(cacheDir, ".nomedia").createNewFile();
        } catch (Exception e2) {
            FileLog.e(e2);
        }
        sparseArray.put(4, cacheDir);
        for (final int i = 0; i < 3; i++) {
            FileLoader.getInstance(i).setDelegate(new FileLoader.FileLoaderDelegate() {
                /* class im.guobwnxjuc.messenger.ImageLoader.AnonymousClass3 */

                @Override // im.guobwnxjuc.messenger.FileLoader.FileLoaderDelegate
                public void fileUploadProgressChanged(String str, float f, boolean z) {
                    ImageLoader.this.fileProgresses.put(str, Float.valueOf(f));
                    long currentTimeMillis = System.currentTimeMillis();
                    if (ImageLoader.this.lastProgressUpdateTime == 0 || ImageLoader.this.lastProgressUpdateTime < currentTimeMillis - 500) {
                        ImageLoader.this.lastProgressUpdateTime = currentTimeMillis;
                        AndroidUtilities.runOnUIThread(new Runnable(i, str, f, z) {
                            /* class im.guobwnxjuc.messenger.$$Lambda$ImageLoader$3$eCR8zml5eBZMIWnOLPmHNTQOzCk */
                            private final /* synthetic */ int f$0;
                            private final /* synthetic */ String f$1;
                            private final /* synthetic */ float f$2;
                            private final /* synthetic */ boolean f$3;

                            {
                                this.f$0 = r1;
                                this.f$1 = r2;
                                this.f$2 = r3;
                                this.f$3 = r4;
                            }

                            public final void run() {
                                NotificationCenter.getInstance(this.f$0).postNotificationName(NotificationCenter.FileUploadProgressChanged, this.f$1, Float.valueOf(this.f$2), Boolean.valueOf(this.f$3));
                            }
                        });
                    }
                }

                @Override // im.guobwnxjuc.messenger.FileLoader.FileLoaderDelegate
                public void fileDidUploaded(String str, TLRPC.InputFile inputFile, TLRPC.InputEncryptedFile inputEncryptedFile, byte[] bArr, byte[] bArr2, long j, boolean z) {
                    Utilities.stageQueue.postRunnable(new Runnable(i, str, inputFile, inputEncryptedFile, bArr, bArr2, j, z) {
                        /* class im.guobwnxjuc.messenger.$$Lambda$ImageLoader$3$i4gTfEXGgbsmkuG5uJ0tkf21vts */
                        private final /* synthetic */ int f$1;
                        private final /* synthetic */ String f$2;
                        private final /* synthetic */ TLRPC.InputFile f$3;
                        private final /* synthetic */ TLRPC.InputEncryptedFile f$4;
                        private final /* synthetic */ byte[] f$5;
                        private final /* synthetic */ byte[] f$6;
                        private final /* synthetic */ long f$7;
                        private final /* synthetic */ boolean f$8;

                        {
                            this.f$1 = r2;
                            this.f$2 = r3;
                            this.f$3 = r4;
                            this.f$4 = r5;
                            this.f$5 = r6;
                            this.f$6 = r7;
                            this.f$7 = r8;
                            this.f$8 = r10;
                        }

                        public final void run() {
                            ImageLoader.AnonymousClass3.this.lambda$fileDidUploaded$2$ImageLoader$3(this.f$1, this.f$2, this.f$3, this.f$4, this.f$5, this.f$6, this.f$7, this.f$8);
                        }
                    });
                }

                public /* synthetic */ void lambda$fileDidUploaded$2$ImageLoader$3(int i, String str, TLRPC.InputFile inputFile, TLRPC.InputEncryptedFile inputEncryptedFile, byte[] bArr, byte[] bArr2, long j, boolean z) {
                    AndroidUtilities.runOnUIThread(new Runnable(i, str, inputFile, inputEncryptedFile, bArr, bArr2, j, z) {
                        /* class im.guobwnxjuc.messenger.$$Lambda$ImageLoader$3$1F7sxwHhHZmwUWmXc6xbFHL5ZMg */
                        private final /* synthetic */ int f$0;
                        private final /* synthetic */ String f$1;
                        private final /* synthetic */ TLRPC.InputFile f$2;
                        private final /* synthetic */ TLRPC.InputEncryptedFile f$3;
                        private final /* synthetic */ byte[] f$4;
                        private final /* synthetic */ byte[] f$5;
                        private final /* synthetic */ long f$6;
                        private final /* synthetic */ boolean f$7;

                        {
                            this.f$0 = r1;
                            this.f$1 = r2;
                            this.f$2 = r3;
                            this.f$3 = r4;
                            this.f$4 = r5;
                            this.f$5 = r6;
                            this.f$6 = r7;
                            this.f$7 = r9;
                        }

                        public final void run() {
                            NotificationCenter.getInstance(this.f$0).postNotificationName(NotificationCenter.FileDidUpload, this.f$1, this.f$2, this.f$3, this.f$4, this.f$5, Long.valueOf(this.f$6), Boolean.valueOf(this.f$7));
                        }
                    });
                    ImageLoader.this.fileProgresses.remove(str);
                }

                @Override // im.guobwnxjuc.messenger.FileLoader.FileLoaderDelegate
                public void fileDidFailedUpload(String str, boolean z) {
                    Utilities.stageQueue.postRunnable(new Runnable(i, str, z) {
                        /* class im.guobwnxjuc.messenger.$$Lambda$ImageLoader$3$xbU66vuLKGCEWxuC7WoyYehOZZo */
                        private final /* synthetic */ int f$1;
                        private final /* synthetic */ String f$2;
                        private final /* synthetic */ boolean f$3;

                        {
                            this.f$1 = r2;
                            this.f$2 = r3;
                            this.f$3 = r4;
                        }

                        public final void run() {
                            ImageLoader.AnonymousClass3.this.lambda$fileDidFailedUpload$4$ImageLoader$3(this.f$1, this.f$2, this.f$3);
                        }
                    });
                }

                public /* synthetic */ void lambda$fileDidFailedUpload$4$ImageLoader$3(int i, String str, boolean z) {
                    AndroidUtilities.runOnUIThread(new Runnable(i, str, z) {
                        /* class im.guobwnxjuc.messenger.$$Lambda$ImageLoader$3$fAfzndYUXvSNwOT1gpncsB7LmE */
                        private final /* synthetic */ int f$0;
                        private final /* synthetic */ String f$1;
                        private final /* synthetic */ boolean f$2;

                        {
                            this.f$0 = r1;
                            this.f$1 = r2;
                            this.f$2 = r3;
                        }

                        public final void run() {
                            NotificationCenter.getInstance(this.f$0).postNotificationName(NotificationCenter.FileDidFailUpload, this.f$1, Boolean.valueOf(this.f$2));
                        }
                    });
                    ImageLoader.this.fileProgresses.remove(str);
                }

                @Override // im.guobwnxjuc.messenger.FileLoader.FileLoaderDelegate
                public void fileDidLoaded(String str, File file, int i) {
                    ImageLoader.this.fileProgresses.remove(str);
                    AndroidUtilities.runOnUIThread(new Runnable(file, str, i, i) {
                        /* class im.guobwnxjuc.messenger.$$Lambda$ImageLoader$3$6SDraKKzX2Y6SE_Hwzy72uxk */
                        private final /* synthetic */ File f$1;
                        private final /* synthetic */ String f$2;
                        private final /* synthetic */ int f$3;
                        private final /* synthetic */ int f$4;

                        {
                            this.f$1 = r2;
                            this.f$2 = r3;
                            this.f$3 = r4;
                            this.f$4 = r5;
                        }

                        public final void run() {
                            ImageLoader.AnonymousClass3.this.lambda$fileDidLoaded$5$ImageLoader$3(this.f$1, this.f$2, this.f$3, this.f$4);
                        }
                    });
                }

                public /* synthetic */ void lambda$fileDidLoaded$5$ImageLoader$3(File file, String str, int i, int i2) {
                    if (SharedConfig.saveToGallery && ImageLoader.this.appPath != null && file != null && ((str.endsWith(".mp4") || str.endsWith(".jpg")) && file.toString().startsWith(ImageLoader.this.appPath.toString()))) {
                        AndroidUtilities.addMediaToGallery(file.toString());
                    }
                    NotificationCenter.getInstance(i).postNotificationName(NotificationCenter.fileDidLoad, str, file);
                    ImageLoader.this.fileDidLoaded(str, file, i2);
                }

                @Override // im.guobwnxjuc.messenger.FileLoader.FileLoaderDelegate
                public void fileDidFailedLoad(String str, int i) {
                    ImageLoader.this.fileProgresses.remove(str);
                    AndroidUtilities.runOnUIThread(new Runnable(str, i, i) {
                        /* class im.guobwnxjuc.messenger.$$Lambda$ImageLoader$3$pDsuG3OF_jRK7qx0I3f4zEvbxg */
                        private final /* synthetic */ String f$1;
                        private final /* synthetic */ int f$2;
                        private final /* synthetic */ int f$3;

                        {
                            this.f$1 = r2;
                            this.f$2 = r3;
                            this.f$3 = r4;
                        }

                        public final void run() {
                            ImageLoader.AnonymousClass3.this.lambda$fileDidFailedLoad$6$ImageLoader$3(this.f$1, this.f$2, this.f$3);
                        }
                    });
                }

                public /* synthetic */ void lambda$fileDidFailedLoad$6$ImageLoader$3(String str, int i, int i2) {
                    ImageLoader.this.fileDidFailedLoad(str, i);
                    NotificationCenter.getInstance(i2).postNotificationName(NotificationCenter.fileDidFailToLoad, str, Integer.valueOf(i));
                }

                @Override // im.guobwnxjuc.messenger.FileLoader.FileLoaderDelegate
                public void fileLoadProgressChanged(String str, float f) {
                    ImageLoader.this.fileProgresses.put(str, Float.valueOf(f));
                    long currentTimeMillis = System.currentTimeMillis();
                    if (ImageLoader.this.lastProgressUpdateTime == 0 || ImageLoader.this.lastProgressUpdateTime < currentTimeMillis - 500) {
                        ImageLoader.this.lastProgressUpdateTime = currentTimeMillis;
                        AndroidUtilities.runOnUIThread(new Runnable(i, str, f) {
                            /* class im.guobwnxjuc.messenger.$$Lambda$ImageLoader$3$OyU2T1XIaI8GZ6qGVDV8u79rbw */
                            private final /* synthetic */ int f$0;
                            private final /* synthetic */ String f$1;
                            private final /* synthetic */ float f$2;

                            {
                                this.f$0 = r1;
                                this.f$1 = r2;
                                this.f$2 = r3;
                            }

                            public final void run() {
                                NotificationCenter.getInstance(this.f$0).postNotificationName(NotificationCenter.FileLoadProgressChanged, this.f$1, Float.valueOf(this.f$2));
                            }
                        });
                    }
                }
            });
        }
        FileLoader.setMediaDirs(sparseArray);
        AnonymousClass4 r0 = new BroadcastReceiver() {
            /* class im.guobwnxjuc.messenger.ImageLoader.AnonymousClass4 */

            public void onReceive(Context context, Intent intent) {
                if (BuildVars.LOGS_ENABLED) {
                    FileLog.d("file system changed");
                }
                $$Lambda$ImageLoader$4$frgORrwnGkawgfaSpWfs88AdLwo r3 = new Runnable() {
                    /* class im.guobwnxjuc.messenger.$$Lambda$ImageLoader$4$frgORrwnGkawgfaSpWfs88AdLwo */

                    public final void run() {
                        ImageLoader.AnonymousClass4.this.lambda$onReceive$0$ImageLoader$4();
                    }
                };
                if ("android.intent.action.MEDIA_UNMOUNTED".equals(intent.getAction())) {
                    AndroidUtilities.runOnUIThread(r3, 1000);
                } else {
                    r3.run();
                }
            }

            public /* synthetic */ void lambda$onReceive$0$ImageLoader$4() {
                ImageLoader.this.checkMediaPaths();
            }
        };
        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(r0, intentFilter);
        } catch (Throwable unused) {
        }
        checkMediaPaths();
    }

    public void checkMediaPaths() {
        this.cacheOutQueue.postRunnable(new Runnable() {
            /* class im.guobwnxjuc.messenger.$$Lambda$ImageLoader$tSe6zbzzq1ZWIdg2WRA1z_vW9o */

            public final void run() {
                ImageLoader.this.lambda$checkMediaPaths$1$ImageLoader();
            }
        });
    }

    public /* synthetic */ void lambda$checkMediaPaths$1$ImageLoader() {
        AndroidUtilities.runOnUIThread(new Runnable(createMediaPaths()) {
            /* class im.guobwnxjuc.messenger.$$Lambda$ImageLoader$zJVWiNYz3fbq1FfAx3Ab4IpHU */
            private final /* synthetic */ SparseArray f$0;

            {
                this.f$0 = r1;
            }

            public final void run() {
                FileLoader.setMediaDirs(this.f$0);
            }
        });
    }

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

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

    public SparseArray<File> createMediaPaths() {
        SparseArray<File> sparseArray = new SparseArray<>();
        File cacheDir = AndroidUtilities.getCacheDir();
        if (!cacheDir.isDirectory()) {
            try {
                cacheDir.mkdirs();
            } catch (Exception e) {
                FileLog.e(e);
            }
        }
        try {
            new File(cacheDir, ".nomedia").createNewFile();
        } catch (Exception e2) {
            FileLog.e(e2);
        }
        sparseArray.put(4, cacheDir);
        if (BuildVars.LOGS_ENABLED) {
            FileLog.d("cache path = " + cacheDir);
        }
        try {
            if ("mounted".equals(Environment.getExternalStorageState())) {
                File file = new File(Environment.getExternalStorageDirectory(), "Hong");
                this.appPath = file;
                file.mkdirs();
                if (this.appPath.isDirectory()) {
                    try {
                        File file2 = new File(this.appPath, "Hong Images");
                        file2.mkdir();
                        if (file2.isDirectory() && canMoveFiles(cacheDir, file2, 0)) {
                            sparseArray.put(0, file2);
                            if (BuildVars.LOGS_ENABLED) {
                                FileLog.d("image path = " + file2);
                            }
                        }
                    } catch (Exception e3) {
                        FileLog.e(e3);
                    }
                    try {
                        File file3 = new File(this.appPath, "Hong Video");
                        file3.mkdir();
                        if (file3.isDirectory() && canMoveFiles(cacheDir, file3, 2)) {
                            sparseArray.put(2, file3);
                            if (BuildVars.LOGS_ENABLED) {
                                FileLog.d("video path = " + file3);
                            }
                        }
                    } catch (Exception e4) {
                        FileLog.e(e4);
                    }
                    try {
                        File file4 = new File(this.appPath, "Hong Audio");
                        file4.mkdir();
                        if (file4.isDirectory() && canMoveFiles(cacheDir, file4, 1)) {
                            new File(file4, ".nomedia").createNewFile();
                            sparseArray.put(1, file4);
                            if (BuildVars.LOGS_ENABLED) {
                                FileLog.d("audio path = " + file4);
                            }
                        }
                    } catch (Exception e5) {
                        FileLog.e(e5);
                    }
                    try {
                        File file5 = new File(this.appPath, "Hong Documents");
                        file5.mkdir();
                        if (file5.isDirectory() && canMoveFiles(cacheDir, file5, 3)) {
                            new File(file5, ".nomedia").createNewFile();
                            sparseArray.put(3, file5);
                            if (BuildVars.LOGS_ENABLED) {
                                FileLog.d("documents path = " + file5);
                            }
                        }
                    } catch (Exception e6) {
                        FileLog.e(e6);
                    }
                }
            } else if (BuildVars.LOGS_ENABLED) {
                FileLog.d("this Android can't rename files");
            }
            SharedConfig.checkSaveToGalleryFiles();
        } catch (Exception e7) {
            FileLog.e(e7);
        }
        return sparseArray;
    }

    /* JADX WARNING: Removed duplicated region for block: B:30:0x007a A[SYNTHETIC, Splitter:B:30:0x007a] */
    /* JADX WARNING: Removed duplicated region for block: B:35:0x0086 A[SYNTHETIC, Splitter:B:35:0x0086] */
    /* JADX WARNING: Removed duplicated region for block: B:42:? A[RETURN, SYNTHETIC] */
    private boolean canMoveFiles(File file, File file2, int i) {
        Throwable th;
        Exception e;
        File file3;
        File file4;
        RandomAccessFile randomAccessFile = null;
        if (i == 0) {
            try {
                file3 = new File(file, "000000000_999999_temp.jpg");
                file4 = new File(file2, "000000000_999999.jpg");
            } catch (Exception e2) {
                e = e2;
                try {
                    FileLog.e(e);
                    if (randomAccessFile != null) {
                    }
                } catch (Throwable th2) {
                    th = th2;
                    if (randomAccessFile != null) {
                        try {
                            randomAccessFile.close();
                        } catch (Exception e3) {
                            FileLog.e(e3);
                        }
                    }
                    throw th;
                }
            }
        } else if (i == 3) {
            file3 = new File(file, "000000000_999999_temp.doc");
            file4 = new File(file2, "000000000_999999.doc");
        } else if (i == 1) {
            file3 = new File(file, "000000000_999999_temp.ogg");
            file4 = new File(file2, "000000000_999999.ogg");
        } else if (i == 2) {
            file3 = new File(file, "000000000_999999_temp.mp4");
            file4 = new File(file2, "000000000_999999.mp4");
        } else {
            file4 = null;
            file3 = null;
        }
        byte[] bArr = new byte[1024];
        file3.createNewFile();
        RandomAccessFile randomAccessFile2 = new RandomAccessFile(file3, "rws");
        try {
            randomAccessFile2.write(bArr);
            randomAccessFile2.close();
            boolean renameTo = file3.renameTo(file4);
            file3.delete();
            file4.delete();
            if (renameTo) {
                return true;
            }
            return false;
        } catch (Exception e4) {
            e = e4;
            randomAccessFile = randomAccessFile2;
            FileLog.e(e);
            if (randomAccessFile != null) {
                return false;
            }
            try {
                randomAccessFile.close();
                return false;
            } catch (Exception e5) {
                FileLog.e(e5);
                return false;
            }
        } catch (Throwable th3) {
            th = th3;
            randomAccessFile = randomAccessFile2;
            if (randomAccessFile != null) {
            }
            throw th;
        }
    }

    public Float getFileProgress(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) {
        BitmapDrawable bitmapDrawable = this.memCache.get(str);
        this.replacedBitmaps.put(str, str2);
        if (bitmapDrawable != null) {
            BitmapDrawable bitmapDrawable2 = this.memCache.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;
                this.memCache.remove(str);
                this.memCache.put(str2, bitmapDrawable);
                this.ignoreRemoval = null;
            } else {
                this.memCache.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);
    }

    public boolean isInMemCache(String str, boolean z) {
        if (z) {
            return this.lottieMemCache.get(str) != null;
        }
        if (this.memCache.get(str) != null) {
            return true;
        }
        return false;
    }

    public void clearMemory() {
        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 cancelLoadingForImageReceiver(ImageReceiver imageReceiver, boolean z) {
        if (imageReceiver != null) {
            this.imageLoadQueue.postRunnable(new Runnable(z, imageReceiver) {
                /* class im.guobwnxjuc.messenger.$$Lambda$ImageLoader$PEvfrsVtr8i6atmSqcQ3US2riws */
                private final /* synthetic */ boolean f$1;
                private final /* synthetic */ ImageReceiver f$2;

                {
                    this.f$1 = r2;
                    this.f$2 = r3;
                }

                public final void run() {
                    ImageLoader.this.lambda$cancelLoadingForImageReceiver$2$ImageLoader(this.f$1, this.f$2);
                }
            });
        }
    }

    public /* synthetic */ void lambda$cancelLoadingForImageReceiver$2$ImageLoader(boolean z, ImageReceiver imageReceiver) {
        int i = 0;
        while (true) {
            int i2 = 3;
            if (i >= 3) {
                return;
            }
            if (i <= 0 || z) {
                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++;
            } else {
                return;
            }
        }
    }

    public BitmapDrawable getAnyImageFromMemory(String str) {
        ArrayList<String> filterKeys;
        BitmapDrawable bitmapDrawable = this.memCache.get(str);
        if (bitmapDrawable != null || (filterKeys = this.memCache.getFilterKeys(str)) == null || filterKeys.isEmpty()) {
            return bitmapDrawable;
        }
        LruCache<BitmapDrawable> lruCache = this.memCache;
        return lruCache.get(str + "@" + filterKeys.get(0));
    }

    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 fileLocation = (TLRPC.FileLocation) tLObject;
            str3 = fileLocation.volume_id + "_" + fileLocation.local_id;
        } else if (tLObject instanceof TLRPC.Document) {
            TLRPC.Document document = (TLRPC.Document) tLObject;
            str3 = document.dc_id + "_" + 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 this.memCache.get(str3);
    }

    /* access modifiers changed from: private */
    /* renamed from: replaceImageInCacheInternal */
    public void lambda$replaceImageInCache$3$ImageLoader(String str, String str2, ImageLocation imageLocation) {
        ArrayList<String> filterKeys = this.memCache.getFilterKeys(str);
        if (filterKeys != null) {
            for (int i = 0; i < filterKeys.size(); i++) {
                String str3 = filterKeys.get(i);
                String str4 = str + "@" + str3;
                String str5 = str2 + "@" + str3;
                performReplace(str4, str5);
                NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.didReplacedPhotoInMemCache, str4, str5, imageLocation);
            }
            return;
        }
        performReplace(str, str2);
        NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.didReplacedPhotoInMemCache, str, str2, imageLocation);
    }

    public void replaceImageInCache(String str, String str2, ImageLocation imageLocation, boolean z) {
        if (z) {
            AndroidUtilities.runOnUIThread(new Runnable(str, str2, imageLocation) {
                /* class im.guobwnxjuc.messenger.$$Lambda$ImageLoader$y9JbSIlyY3gRZWz1IS751t9XA2Y */
                private final /* synthetic */ String f$1;
                private final /* synthetic */ String f$2;
                private final /* synthetic */ ImageLocation f$3;

                {
                    this.f$1 = r2;
                    this.f$2 = r3;
                    this.f$3 = r4;
                }

                public final void run() {
                    ImageLoader.this.lambda$replaceImageInCache$3$ImageLoader(this.f$1, this.f$2, this.f$3);
                }
            });
        } else {
            lambda$replaceImageInCache$3$ImageLoader(str, str2, imageLocation);
        }
    }

    public void putImageToCache(BitmapDrawable bitmapDrawable, String str) {
        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) {
            if (this.thumbGenerateTasks.get(FileLoader.getAttachFileName(thumbGenerateInfo.parentDocument)) == null) {
                this.thumbGeneratingQueue.postRunnable(new ThumbGenerateTask(i, file, thumbGenerateInfo));
            }
        }
    }

    public void cancelForceLoadingForImageReceiver(ImageReceiver imageReceiver) {
        String imageKey;
        if (imageReceiver != null && (imageKey = imageReceiver.getImageKey()) != null) {
            this.imageLoadQueue.postRunnable(new Runnable(imageKey) {
                /* class im.guobwnxjuc.messenger.$$Lambda$ImageLoader$C50FnGZV3qe_4wXn2tcTywvPVE */
                private final /* synthetic */ String f$1;

                {
                    this.f$1 = r2;
                }

                public final void run() {
                    ImageLoader.this.lambda$cancelForceLoadingForImageReceiver$4$ImageLoader(this.f$1);
                }
            });
        }
    }

    public /* synthetic */ void lambda$cancelForceLoadingForImageReceiver$4$ImageLoader(String str) {
        this.forceLoadingImages.remove(str);
    }

    private void createLoadOperationForImageReceiver(ImageReceiver imageReceiver, String str, String str2, String str3, ImageLocation imageLocation, String str4, int i, int i2, int i3, int i4, int i5) {
        if (imageReceiver != null && str2 != null && str != null && imageLocation != null) {
            int tag = imageReceiver.getTag(i3);
            if (tag == 0) {
                tag = this.lastImageNum;
                imageReceiver.setTag(tag, i3);
                int i6 = this.lastImageNum + 1;
                this.lastImageNum = i6;
                if (i6 == Integer.MAX_VALUE) {
                    this.lastImageNum = 0;
                }
            }
            boolean isNeedsQualityThumb = imageReceiver.isNeedsQualityThumb();
            this.imageLoadQueue.postRunnable(new Runnable(i4, str2, str, tag, imageReceiver, str4, i3, i5, imageLocation, i3 == 0 && imageReceiver.isCurrentKeyQuality(), imageReceiver.getParentObject(), imageReceiver.getQulityThumbDocument(), isNeedsQualityThumb, imageReceiver.isShouldGenerateQualityThumb(), i2, i, str3, imageReceiver.getCurrentAccount()) {
                /* class im.guobwnxjuc.messenger.$$Lambda$ImageLoader$MABa6xONzvXWPUEC2VD0wDr8rls */
                private final /* synthetic */ int f$1;
                private final /* synthetic */ boolean f$10;
                private final /* synthetic */ Object f$11;
                private final /* synthetic */ TLRPC.Document f$12;
                private final /* synthetic */ boolean f$13;
                private final /* synthetic */ boolean f$14;
                private final /* synthetic */ int f$15;
                private final /* synthetic */ int f$16;
                private final /* synthetic */ String f$17;
                private final /* synthetic */ int f$18;
                private final /* synthetic */ String f$2;
                private final /* synthetic */ String f$3;
                private final /* synthetic */ int f$4;
                private final /* synthetic */ ImageReceiver f$5;
                private final /* synthetic */ String f$6;
                private final /* synthetic */ int f$7;
                private final /* synthetic */ int f$8;
                private final /* synthetic */ ImageLocation f$9;

                {
                    this.f$1 = r4;
                    this.f$2 = r5;
                    this.f$3 = r6;
                    this.f$4 = r7;
                    this.f$5 = r8;
                    this.f$6 = r9;
                    this.f$7 = r10;
                    this.f$8 = r11;
                    this.f$9 = r12;
                    this.f$10 = r13;
                    this.f$11 = r14;
                    this.f$12 = r15;
                    this.f$13 = r16;
                    this.f$14 = r17;
                    this.f$15 = r18;
                    this.f$16 = r19;
                    this.f$17 = r20;
                    this.f$18 = r21;
                }

                public final void run() {
                    ImageLoader.this.lambda$createLoadOperationForImageReceiver$5$ImageLoader(this.f$1, this.f$2, this.f$3, this.f$4, this.f$5, this.f$6, this.f$7, this.f$8, this.f$9, this.f$10, this.f$11, this.f$12, this.f$13, this.f$14, this.f$15, this.f$16, this.f$17, this.f$18);
                }
            });
        }
    }

    /* JADX DEBUG: Failed to insert an additional move for type inference into block B:18:0x0089 */
    /* JADX WARN: Type inference failed for: r9v1, types: [boolean, int] */
    /* JADX WARN: Type inference failed for: r9v17 */
    /* JADX WARN: Type inference failed for: r9v18 */
    /* JADX WARN: Type inference failed for: r9v25 */
    /* JADX WARN: Type inference failed for: r9v36 */
    /* JADX WARN: Type inference failed for: r9v37 */
    /* JADX WARNING: Code restructure failed: missing block: B:67:0x0198, code lost:
        if (r7.exists() == false) goto L_0x019a;
     */
    /* JADX WARNING: Removed duplicated region for block: B:161:0x0389  */
    /* JADX WARNING: Removed duplicated region for block: B:162:0x0393  */
    /* JADX WARNING: Removed duplicated region for block: B:66:0x018d  */
    /* JADX WARNING: Removed duplicated region for block: B:70:0x019d  */
    /* JADX WARNING: Removed duplicated region for block: B:72:0x01a1  */
    /* JADX WARNING: Removed duplicated region for block: B:82:0x01f0  */
    /* JADX WARNING: Removed duplicated region for block: B:87:0x0202  */
    /* JADX WARNING: Unknown variable types count: 1 */
    public /* synthetic */ void lambda$createLoadOperationForImageReceiver$5$ImageLoader(int i, String str, String str2, int i2, ImageReceiver imageReceiver, String str3, int i3, int i4, ImageLocation imageLocation, boolean z, Object obj, TLRPC.Document document, boolean z2, boolean z3, int i5, int i6, String str4, int i7) {
        int i8;
        ?? r9;
        boolean z4;
        String str5;
        File file;
        int i9;
        boolean z5;
        boolean z6;
        int i10;
        boolean z7;
        int i11;
        boolean z8;
        int i12;
        boolean z9;
        File file2;
        boolean z10;
        File file3;
        File file4;
        String str6;
        File file5;
        int i13;
        boolean z11;
        File file6;
        File file7;
        boolean z12;
        File file8;
        boolean z13;
        CacheImage cacheImage;
        CacheImage cacheImage2;
        boolean z14;
        boolean z15;
        TLRPC.Document document2 = 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) {
                    cacheImage = cacheImage3;
                    cacheImage2 = cacheImage4;
                    z4 = true;
                    r9 = 1;
                    i8 = 0;
                } else if (cacheImage5 == cacheImage3) {
                    cacheImage = cacheImage3;
                    if (cacheImage4 == null) {
                        cacheImage2 = cacheImage4;
                        z15 = true;
                        i8 = 0;
                        cacheImage5.replaceImageReceiver(imageReceiver, str2, str3, i3, i4);
                    } else {
                        cacheImage2 = cacheImage4;
                        z15 = true;
                        i8 = 0;
                    }
                    z4 = true;
                    r9 = z15;
                } else {
                    cacheImage = cacheImage3;
                    cacheImage2 = cacheImage4;
                    z14 = true;
                    i8 = 0;
                    cacheImage5.removeImageReceiver(imageReceiver);
                }
                if (!z4 && cacheImage2 != null) {
                    cacheImage2.addImageReceiver(imageReceiver, str2, str3, i3, i4);
                    z4 = true;
                }
                if (!z4 && cacheImage != null) {
                    cacheImage.addImageReceiver(imageReceiver, str2, str3, i3, i4);
                    z4 = true;
                }
            } else {
                cacheImage = cacheImage3;
                cacheImage2 = cacheImage4;
                z14 = true;
                i8 = 0;
            }
            z4 = false;
            r9 = z14;
            cacheImage2.addImageReceiver(imageReceiver, str2, str3, i3, i4);
            z4 = true;
            cacheImage.addImageReceiver(imageReceiver, str2, str3, i3, i4);
            z4 = true;
        } else {
            r9 = 1;
            i8 = 0;
            z4 = false;
        }
        if (!z4) {
            if (imageLocation.path != null) {
                String str7 = imageLocation.path;
                if (str7.startsWith("http") || str7.startsWith("athumb")) {
                    z13 = false;
                    file = null;
                } else {
                    if (str7.startsWith("thumb://")) {
                        int indexOf = str7.indexOf(LogUtils.COLON, 8);
                        if (indexOf >= 0) {
                            file = new File(str7.substring(indexOf + r9));
                            z13 = true;
                        }
                    } else {
                        if (str7.startsWith("vthumb://")) {
                            int indexOf2 = str7.indexOf(LogUtils.COLON, 9);
                            if (indexOf2 >= 0) {
                                int i14 = r9 == true ? 1 : 0;
                                int i15 = r9 == true ? 1 : 0;
                                int i16 = r9 == true ? 1 : 0;
                                int i17 = r9 == true ? 1 : 0;
                                int i18 = r9 == true ? 1 : 0;
                                int i19 = r9 == true ? 1 : 0;
                                int i20 = r9 == true ? 1 : 0;
                                int i21 = r9 == true ? 1 : 0;
                                int i22 = r9 == true ? 1 : 0;
                                int i23 = r9 == true ? 1 : 0;
                                file = new File(str7.substring(indexOf2 + i14));
                            }
                        } else {
                            file = new File(str7);
                        }
                        z13 = true;
                    }
                    file = null;
                    z13 = true;
                }
                z5 = z13;
                str5 = "athumb";
                z6 = false;
            } else {
                if (i != 0 || !z) {
                    str5 = "athumb";
                    z6 = false;
                    z5 = false;
                } else {
                    if (obj instanceof MessageObject) {
                        MessageObject messageObject = (MessageObject) obj;
                        TLRPC.Document document3 = messageObject.getDocument();
                        str6 = messageObject.messageOwner.attachPath;
                        document2 = document3;
                        file5 = FileLoader.getPathToMessage(messageObject.messageOwner);
                        i13 = messageObject.getFileType();
                        z11 = false;
                    } else if (document2 != null) {
                        File pathToAttach = FileLoader.getPathToAttach(document2, r9);
                        int i24 = MessageObject.isVideoDocument(document) ? 2 : 3;
                        file5 = pathToAttach;
                        str6 = null;
                        i13 = i24;
                        z11 = true;
                    } else {
                        str6 = null;
                        z11 = false;
                        i13 = 0;
                        file5 = null;
                        document2 = null;
                    }
                    if (document2 != null) {
                        if (z2) {
                            File directory = FileLoader.getDirectory(4);
                            file6 = file5;
                            StringBuilder sb = new StringBuilder();
                            str5 = "athumb";
                            sb.append("q_");
                            sb.append(document2.dc_id);
                            sb.append("_");
                            sb.append(document2.id);
                            sb.append(".jpg");
                            file7 = new File(directory, sb.toString());
                            if (file7.exists()) {
                                z12 = true;
                                if (!TextUtils.isEmpty(str6)) {
                                    file8 = new File(str6);
                                }
                                file8 = null;
                                if (file8 == null) {
                                    file8 = file6;
                                }
                                if (file7 != null) {
                                    String attachFileName = FileLoader.getAttachFileName(document2);
                                    ThumbGenerateInfo thumbGenerateInfo = this.waitingForQualityThumb.get(attachFileName);
                                    if (thumbGenerateInfo == null) {
                                        thumbGenerateInfo = new ThumbGenerateInfo();
                                        thumbGenerateInfo.parentDocument = document2;
                                        thumbGenerateInfo.filter = str3;
                                        thumbGenerateInfo.big = z11;
                                        this.waitingForQualityThumb.put(attachFileName, thumbGenerateInfo);
                                    }
                                    if (!thumbGenerateInfo.imageReceiverArray.contains(imageReceiver)) {
                                        thumbGenerateInfo.imageReceiverArray.add(imageReceiver);
                                        thumbGenerateInfo.imageReceiverGuidsArray.add(Integer.valueOf(i4));
                                    }
                                    this.waitingForQualityThumbByTag.put(i2, attachFileName);
                                    if (file8.exists() && z3) {
                                        generateThumb(i13, file8, thumbGenerateInfo);
                                        return;
                                    }
                                    return;
                                }
                                z6 = z12;
                                file = file7;
                                z5 = true;
                            }
                        } else {
                            file6 = file5;
                            str5 = "athumb";
                        }
                        z12 = false;
                        file7 = null;
                        if (!TextUtils.isEmpty(str6)) {
                        }
                        file8 = null;
                        if (file8 == null) {
                        }
                        if (file7 != null) {
                        }
                    } else {
                        str5 = "athumb";
                        z6 = false;
                        z5 = true;
                    }
                }
                i9 = 2;
                file = null;
                if (i != i9) {
                    boolean isEncrypted = imageLocation.isEncrypted();
                    CacheImage cacheImage6 = new CacheImage();
                    if (!z) {
                        if (MessageObject.isGifDocument(imageLocation.webFile) || MessageObject.isGifDocument(imageLocation.document) || MessageObject.isRoundVideoDocument(imageLocation.document)) {
                            cacheImage6.animatedFile = true;
                        } else if (imageLocation.path != null) {
                            String str8 = imageLocation.path;
                            if (!str8.startsWith("vthumb") && !str8.startsWith("thumb")) {
                                String httpUrlExtension = getHttpUrlExtension(str8, "jpg");
                                if (httpUrlExtension.equals("mp4") || httpUrlExtension.equals("gif")) {
                                    cacheImage6.animatedFile = true;
                                }
                            }
                        }
                    }
                    if (file == null) {
                        if (imageLocation.photoSize instanceof TLRPC.TL_photoStrippedSize) {
                            i10 = i5;
                            z9 = true;
                        } else {
                            if (imageLocation.secureDocument != null) {
                                cacheImage6.secureDocument = imageLocation.secureDocument;
                                z5 = cacheImage6.secureDocument.secureFile.dc_id == Integer.MIN_VALUE;
                                file4 = new File(FileLoader.getDirectory(4), str);
                                i10 = i5;
                            } else {
                                i10 = i5;
                                if (!AUTOPLAY_FILTER.equals(str3)) {
                                    if (i10 != 0 || i6 <= 0 || imageLocation.path != null || isEncrypted) {
                                        file4 = new File(FileLoader.getDirectory(4), str);
                                        if (file4.exists()) {
                                            z6 = true;
                                        } else if (i10 == 2) {
                                            File directory2 = FileLoader.getDirectory(4);
                                            file4 = new File(directory2, str + ".enc");
                                            z6 = z6;
                                        }
                                        if (imageLocation.document != null) {
                                            cacheImage6.lottieFile = "application/x-tgsticker".equals(imageLocation.document.mime_type);
                                        }
                                    }
                                }
                                if (imageLocation.document != null) {
                                    TLRPC.Document document4 = imageLocation.document;
                                    if (document4 instanceof TLRPC.TL_documentEncrypted) {
                                        file3 = new File(FileLoader.getDirectory(4), str);
                                        z10 = z5;
                                    } else if (MessageObject.isVideoDocument(document4)) {
                                        z10 = z5;
                                        file3 = new File(FileLoader.getDirectory(2), str);
                                    } else {
                                        z10 = z5;
                                        file3 = new File(FileLoader.getDirectory(3), str);
                                    }
                                    if (AUTOPLAY_FILTER.equals(str3) && !file3.exists()) {
                                        File directory3 = FileLoader.getDirectory(4);
                                        file3 = new File(directory3, document4.dc_id + "_" + document4.id + ".temp");
                                    }
                                    cacheImage6.lottieFile = "application/x-tgsticker".equals(document4.mime_type);
                                    i12 = document4.size;
                                    z6 = z6;
                                    z9 = z10;
                                    file = file3;
                                    if (!AUTOPLAY_FILTER.equals(str3)) {
                                        cacheImage6.animatedFile = true;
                                        cacheImage6.size = i12;
                                        i11 = i3;
                                        z8 = z6;
                                        z7 = true;
                                    } else {
                                        i11 = i3;
                                        z8 = z6;
                                        z7 = z9;
                                    }
                                } else {
                                    if (imageLocation.webFile != null) {
                                        file2 = new File(FileLoader.getDirectory(3), str);
                                    } else {
                                        file2 = new File(FileLoader.getDirectory(i8), str);
                                    }
                                    z6 = z6;
                                    z9 = z5;
                                    file = file2;
                                }
                            }
                            file = file4;
                            z9 = z5;
                        }
                        i12 = 0;
                        if (!AUTOPLAY_FILTER.equals(str3)) {
                        }
                    } else {
                        i10 = i5;
                        z8 = z6;
                        i11 = i3;
                        z7 = z5;
                    }
                    cacheImage6.imageType = i11;
                    cacheImage6.key = str2;
                    cacheImage6.filter = str3;
                    cacheImage6.imageLocation = imageLocation;
                    cacheImage6.ext = str4;
                    cacheImage6.currentAccount = i7;
                    cacheImage6.parentObject = obj;
                    if (imageLocation.lottieAnimation) {
                        cacheImage6.lottieFile = true;
                    }
                    if (i10 == 2) {
                        File internalCacheDir = FileLoader.getInternalCacheDir();
                        cacheImage6.encryptionKeyPath = new File(internalCacheDir, str + ".enc.key");
                    }
                    cacheImage6.addImageReceiver(imageReceiver, str2, str3, i3, i4);
                    if (z7 || z8 || 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 {
                            this.cacheOutQueue.postRunnable(cacheImage6.cacheTask);
                            return;
                        }
                    } else {
                        cacheImage6.url = str;
                        this.imageLoadingByUrl.put(str, cacheImage6);
                        if (imageLocation.path != null) {
                            String MD5 = Utilities.MD5(imageLocation.path);
                            File directory4 = FileLoader.getDirectory(4);
                            cacheImage6.tempFilePath = new File(directory4, MD5 + "_temp.jpg");
                            cacheImage6.finalFilePath = file;
                            if (imageLocation.path.startsWith(str5)) {
                                cacheImage6.artworkTask = new ArtworkLoadTask(cacheImage6);
                                this.artworkTasks.add(cacheImage6.artworkTask);
                                runArtworkTasks(false);
                                return;
                            }
                            cacheImage6.httpTask = new HttpImageTask(cacheImage6, i6);
                            this.httpTasks.add(cacheImage6.httpTask);
                            runHttpTasks(false);
                            return;
                        }
                        if (imageLocation.location != null) {
                            FileLoader.getInstance(i7).loadFile(imageLocation, obj, str4, i != 0 ? 2 : 1, (i10 != 0 || (i6 > 0 && imageLocation.key == null)) ? i10 : 1);
                        } else if (imageLocation.document != null) {
                            FileLoader.getInstance(i7).loadFile(imageLocation.document, obj, i != 0 ? 2 : 1, i10);
                        } else if (imageLocation.secureDocument != null) {
                            FileLoader.getInstance(i7).loadFile(imageLocation.secureDocument, i != 0 ? 2 : 1);
                        } else if (imageLocation.webFile != null) {
                            FileLoader.getInstance(i7).loadFile(imageLocation.webFile, i != 0 ? 2 : 1, i10);
                        }
                        if (imageReceiver.isForceLoding()) {
                            this.forceLoadingImages.put(cacheImage6.key, 0);
                            return;
                        }
                        return;
                    }
                }
            }
            i9 = 2;
            if (i != i9) {
            }
        }
    }

    /* JADX WARNING: Code restructure failed: missing block: B:109:0x01df, code lost:
        if (r8.location.local_id < 0) goto L_0x01e4;
     */
    /* JADX WARNING: Removed duplicated region for block: B:133:0x026d  */
    /* JADX WARNING: Removed duplicated region for block: B:139:0x028b  */
    /* JADX WARNING: Removed duplicated region for block: B:153:0x02c8  */
    /* JADX WARNING: Removed duplicated region for block: B:154:0x02cd  */
    /* JADX WARNING: Removed duplicated region for block: B:156:0x02d3  */
    /* JADX WARNING: Removed duplicated region for block: B:162:0x02f7  */
    /* JADX WARNING: Removed duplicated region for block: B:178:0x0358  */
    /* JADX WARNING: Removed duplicated region for block: B:193:0x03a8  */
    /* JADX WARNING: Removed duplicated region for block: B:201:0x03df  */
    /* JADX WARNING: Removed duplicated region for block: B:218:0x043e  */
    /* JADX WARNING: Removed duplicated region for block: B:233:0x02e2 A[SYNTHETIC] */
    /* JADX WARNING: Removed duplicated region for block: B:34:0x0083  */
    /* JADX WARNING: Removed duplicated region for block: B:36:0x008a  */
    /* JADX WARNING: Removed duplicated region for block: B:44:0x00a8  */
    /* JADX WARNING: Removed duplicated region for block: B:71:0x011e  */
    /* JADX WARNING: Removed duplicated region for block: B:73:0x012b  */
    /* JADX WARNING: Removed duplicated region for block: B:78:0x013b  */
    /* JADX WARNING: Removed duplicated region for block: B:82:0x0150  */
    public void loadImageForImageReceiver(ImageReceiver imageReceiver) {
        boolean z;
        String imageKey;
        boolean z2;
        String thumbKey;
        boolean z3;
        Object parentObject;
        ImageLocation thumbLocation;
        ImageLocation imageLocation;
        boolean z4;
        String ext;
        ImageLocation imageLocation2;
        int i;
        String str;
        String str2;
        String str3;
        String str4;
        String str5;
        String str6;
        boolean z5;
        int i2;
        boolean z6;
        String str7;
        String str8;
        BitmapDrawable bitmapDrawable;
        ImageLocation imageLocation3;
        BitmapDrawable bitmapDrawable2;
        BitmapDrawable bitmapDrawable3;
        if (imageReceiver != null) {
            String mediaKey = imageReceiver.getMediaKey();
            int newGuid = imageReceiver.getNewGuid();
            if (mediaKey != null) {
                ImageLocation mediaLocation = imageReceiver.getMediaLocation();
                if (mediaLocation == null || (!MessageObject.isAnimatedStickerDocument(mediaLocation.document) && !mediaLocation.lottieAnimation)) {
                    bitmapDrawable3 = this.memCache.get(mediaKey);
                    if (bitmapDrawable3 != null) {
                        this.memCache.moveToFront(mediaKey);
                    }
                } else {
                    bitmapDrawable3 = this.lottieMemCache.get(mediaKey);
                }
                if (bitmapDrawable3 != null) {
                    cancelLoadingForImageReceiver(imageReceiver, true);
                    imageReceiver.setImageBitmapByKey(bitmapDrawable3, mediaKey, 3, true, newGuid);
                    if (imageReceiver.isForcePreview()) {
                        z = true;
                        imageKey = imageReceiver.getImageKey();
                        if (!z && imageKey != null) {
                            imageLocation3 = imageReceiver.getImageLocation();
                            if (imageLocation3 != null || (!MessageObject.isAnimatedStickerDocument(imageLocation3.document) && !imageLocation3.lottieAnimation)) {
                                bitmapDrawable2 = this.memCache.get(imageKey);
                                if (bitmapDrawable2 != null) {
                                    this.memCache.moveToFront(imageKey);
                                }
                            } else {
                                bitmapDrawable2 = this.lottieMemCache.get(imageKey);
                            }
                            if (bitmapDrawable2 != null) {
                                cancelLoadingForImageReceiver(imageReceiver, true);
                                imageReceiver.setImageBitmapByKey(bitmapDrawable2, imageKey, 0, true, newGuid);
                                if (imageReceiver.isForcePreview() || mediaKey != null) {
                                    z2 = true;
                                    thumbKey = imageReceiver.getThumbKey();
                                    if (thumbKey != null) {
                                        ImageLocation thumbLocation2 = imageReceiver.getThumbLocation();
                                        if (thumbLocation2 == null || (!MessageObject.isAnimatedStickerDocument(thumbLocation2.document) && !thumbLocation2.lottieAnimation)) {
                                            bitmapDrawable = this.memCache.get(thumbKey);
                                            if (bitmapDrawable != null) {
                                                this.memCache.moveToFront(thumbKey);
                                            }
                                        } else {
                                            bitmapDrawable = this.lottieMemCache.get(imageKey);
                                        }
                                        if (bitmapDrawable != null) {
                                            imageReceiver.setImageBitmapByKey(bitmapDrawable, thumbKey, 1, true, newGuid);
                                            cancelLoadingForImageReceiver(imageReceiver, false);
                                            if (!z2 || !imageReceiver.isForcePreview()) {
                                                z3 = true;
                                                parentObject = imageReceiver.getParentObject();
                                                TLRPC.Document qulityThumbDocument = imageReceiver.getQulityThumbDocument();
                                                thumbLocation = imageReceiver.getThumbLocation();
                                                String thumbFilter = imageReceiver.getThumbFilter();
                                                ImageLocation mediaLocation2 = imageReceiver.getMediaLocation();
                                                String mediaFilter = imageReceiver.getMediaFilter();
                                                imageLocation = imageReceiver.getImageLocation();
                                                String imageFilter = imageReceiver.getImageFilter();
                                                if (imageLocation == null && imageReceiver.isNeedsQualityThumb() && imageReceiver.isCurrentKeyQuality()) {
                                                    if (!(parentObject instanceof MessageObject)) {
                                                        imageLocation = ImageLocation.getForDocument(((MessageObject) parentObject).getDocument());
                                                    } else if (qulityThumbDocument != null) {
                                                        imageLocation = ImageLocation.getForDocument(qulityThumbDocument);
                                                    }
                                                    z4 = true;
                                                    ext = imageReceiver.getExt();
                                                    if (ext == null) {
                                                        ext = "jpg";
                                                    }
                                                    imageLocation2 = mediaLocation2;
                                                    String str9 = null;
                                                    String str10 = null;
                                                    String str11 = null;
                                                    String str12 = null;
                                                    i = 0;
                                                    boolean z7 = false;
                                                    while (i < 2) {
                                                        ImageLocation imageLocation4 = i == 0 ? imageLocation : imageLocation2;
                                                        if (imageLocation4 != null) {
                                                            String key = imageLocation4.getKey(parentObject, imageLocation2 != null ? imageLocation2 : imageLocation);
                                                            if (key != null) {
                                                                z6 = z2;
                                                                if (imageLocation4.path != null) {
                                                                    str7 = key + "." + getHttpUrlExtension(imageLocation4.path, "jpg");
                                                                } else if (imageLocation4.photoSize instanceof TLRPC.TL_photoStrippedSize) {
                                                                    str7 = key + "." + ext;
                                                                } else {
                                                                    if (imageLocation4.location != null) {
                                                                        str7 = key + "." + ext;
                                                                        if (imageReceiver.getExt() == null && imageLocation4.location.key == null) {
                                                                            i2 = newGuid;
                                                                            if (imageLocation4.location.volume_id == -2147483648L) {
                                                                            }
                                                                        } else {
                                                                            i2 = newGuid;
                                                                        }
                                                                        z5 = z4;
                                                                        z7 = true;
                                                                        if (i != 0) {
                                                                            str9 = str7;
                                                                            str12 = key;
                                                                        } else {
                                                                            str10 = str7;
                                                                            str11 = key;
                                                                        }
                                                                        if (imageLocation4 == thumbLocation) {
                                                                            if (i == 0) {
                                                                                imageLocation = null;
                                                                                str9 = null;
                                                                                str12 = null;
                                                                            } else {
                                                                                str10 = null;
                                                                                imageLocation2 = null;
                                                                                str11 = null;
                                                                            }
                                                                        }
                                                                        i++;
                                                                        z2 = z6;
                                                                        newGuid = i2;
                                                                        z4 = z5;
                                                                    } else {
                                                                        i2 = newGuid;
                                                                        if (imageLocation4.webFile != null) {
                                                                            String mimeTypePart = FileLoader.getMimeTypePart(imageLocation4.webFile.mime_type);
                                                                            str7 = key + "." + getHttpUrlExtension(imageLocation4.webFile.url, mimeTypePart);
                                                                        } else if (imageLocation4.secureDocument != null) {
                                                                            str7 = key + "." + ext;
                                                                        } else {
                                                                            if (imageLocation4.document != null) {
                                                                                if (i == 0 && z4) {
                                                                                    key = "q_" + key;
                                                                                }
                                                                                String documentFileName = FileLoader.getDocumentFileName(imageLocation4.document);
                                                                                String str13 = "";
                                                                                if (documentFileName != null) {
                                                                                    int lastIndexOf = documentFileName.lastIndexOf(46);
                                                                                    z5 = z4;
                                                                                    if (lastIndexOf != -1) {
                                                                                        str8 = documentFileName.substring(lastIndexOf);
                                                                                        if (str8.length() <= 1) {
                                                                                            str13 = str8;
                                                                                        } else if (MimeTypes.VIDEO_MP4.equals(imageLocation4.document.mime_type)) {
                                                                                            str13 = ".mp4";
                                                                                        } else if ("video/x-matroska".equals(imageLocation4.document.mime_type)) {
                                                                                            str13 = ".mkv";
                                                                                        }
                                                                                        str7 = key + str13;
                                                                                        z7 = MessageObject.isVideoDocument(imageLocation4.document) && !MessageObject.isGifDocument(imageLocation4.document) && !MessageObject.isRoundVideoDocument(imageLocation4.document) && !MessageObject.canPreviewDocument(imageLocation4.document);
                                                                                    }
                                                                                } else {
                                                                                    z5 = z4;
                                                                                }
                                                                                str8 = str13;
                                                                                if (str8.length() <= 1) {
                                                                                }
                                                                                str7 = key + str13;
                                                                                z7 = MessageObject.isVideoDocument(imageLocation4.document) && !MessageObject.isGifDocument(imageLocation4.document) && !MessageObject.isRoundVideoDocument(imageLocation4.document) && !MessageObject.canPreviewDocument(imageLocation4.document);
                                                                            } else {
                                                                                z5 = z4;
                                                                                str7 = null;
                                                                            }
                                                                            if (i != 0) {
                                                                            }
                                                                            if (imageLocation4 == thumbLocation) {
                                                                            }
                                                                            i++;
                                                                            z2 = z6;
                                                                            newGuid = i2;
                                                                            z4 = z5;
                                                                        }
                                                                    }
                                                                    z5 = z4;
                                                                    if (i != 0) {
                                                                    }
                                                                    if (imageLocation4 == thumbLocation) {
                                                                    }
                                                                    i++;
                                                                    z2 = z6;
                                                                    newGuid = i2;
                                                                    z4 = z5;
                                                                }
                                                                z5 = z4;
                                                                i2 = newGuid;
                                                                if (i != 0) {
                                                                }
                                                                if (imageLocation4 == thumbLocation) {
                                                                }
                                                                i++;
                                                                z2 = z6;
                                                                newGuid = i2;
                                                                z4 = z5;
                                                            }
                                                        }
                                                        z5 = z4;
                                                        i2 = newGuid;
                                                        z6 = z2;
                                                        i++;
                                                        z2 = z6;
                                                        newGuid = i2;
                                                        z4 = z5;
                                                    }
                                                    int i3 = 1;
                                                    if (thumbLocation != null) {
                                                        ImageLocation strippedLocation = imageReceiver.getStrippedLocation();
                                                        if (strippedLocation == null) {
                                                            strippedLocation = imageLocation2 != null ? imageLocation2 : imageLocation;
                                                        }
                                                        str2 = thumbLocation.getKey(parentObject, strippedLocation);
                                                        if (thumbLocation.path != null) {
                                                            str6 = str2 + "." + getHttpUrlExtension(thumbLocation.path, "jpg");
                                                        } else if (thumbLocation.photoSize instanceof TLRPC.TL_photoStrippedSize) {
                                                            str6 = str2 + "." + ext;
                                                        } else if (thumbLocation.location != null) {
                                                            str6 = str2 + "." + ext;
                                                        } else {
                                                            str = null;
                                                        }
                                                        str = str6;
                                                    } else {
                                                        str2 = null;
                                                        str = null;
                                                    }
                                                    str3 = str11;
                                                    if (!(str3 == null || mediaFilter == null)) {
                                                        str3 = str3 + "@" + mediaFilter;
                                                    }
                                                    str4 = str12;
                                                    if (!(str4 == null || imageFilter == null)) {
                                                        str4 = str4 + "@" + imageFilter;
                                                    }
                                                    if (!(str2 == null || thumbFilter == null)) {
                                                        str2 = str2 + "@" + thumbFilter;
                                                    }
                                                    if (imageLocation == null && imageLocation.path != null) {
                                                        if (z3) {
                                                            i3 = 2;
                                                        }
                                                        createLoadOperationForImageReceiver(imageReceiver, str2, str, ext, thumbLocation, thumbFilter, 0, 1, 1, i3, newGuid);
                                                        createLoadOperationForImageReceiver(imageReceiver, str4, str9, ext, imageLocation, imageFilter, imageReceiver.getSize(), 1, 0, 0, newGuid);
                                                        return;
                                                    } else if (imageLocation2 != null) {
                                                        int cacheType = imageReceiver.getCacheType();
                                                        int i4 = (cacheType != 0 || !z7) ? cacheType : 1;
                                                        int i5 = i4 == 0 ? 1 : i4;
                                                        if (!z3) {
                                                            if (z3) {
                                                                i3 = 2;
                                                            }
                                                            str5 = mediaFilter;
                                                            createLoadOperationForImageReceiver(imageReceiver, str2, str, ext, thumbLocation, thumbFilter, 0, i5, 1, i3, newGuid);
                                                        } else {
                                                            str5 = mediaFilter;
                                                        }
                                                        if (!z2) {
                                                            createLoadOperationForImageReceiver(imageReceiver, str4, str9, ext, imageLocation, imageFilter, 0, 1, 0, 0, newGuid);
                                                        }
                                                        createLoadOperationForImageReceiver(imageReceiver, str3, str10, ext, imageLocation2, str5, imageReceiver.getSize(), i4, 3, 0, newGuid);
                                                        return;
                                                    } else {
                                                        int cacheType2 = imageReceiver.getCacheType();
                                                        int i6 = (cacheType2 != 0 || !z7) ? cacheType2 : 1;
                                                        int i7 = i6 == 0 ? 1 : i6;
                                                        if (z3) {
                                                            i3 = 2;
                                                        }
                                                        createLoadOperationForImageReceiver(imageReceiver, str2, str, ext, thumbLocation, thumbFilter, 0, i7, 1, i3, newGuid);
                                                        createLoadOperationForImageReceiver(imageReceiver, str4, str9, ext, imageLocation, imageFilter, imageReceiver.getSize(), i6, 0, 0, newGuid);
                                                        return;
                                                    }
                                                }
                                                z4 = false;
                                                ext = imageReceiver.getExt();
                                                if (ext == null) {
                                                }
                                                imageLocation2 = mediaLocation2;
                                                String str92 = null;
                                                String str102 = null;
                                                String str112 = null;
                                                String str122 = null;
                                                i = 0;
                                                boolean z72 = false;
                                                while (i < 2) {
                                                }
                                                int i32 = 1;
                                                if (thumbLocation != null) {
                                                }
                                                str3 = str112;
                                                str3 = str3 + "@" + mediaFilter;
                                                str4 = str122;
                                                str4 = str4 + "@" + imageFilter;
                                                str2 = str2 + "@" + thumbFilter;
                                                if (imageLocation == null) {
                                                }
                                                if (imageLocation2 != null) {
                                                }
                                            } else {
                                                return;
                                            }
                                        }
                                    }
                                    z3 = false;
                                    parentObject = imageReceiver.getParentObject();
                                    TLRPC.Document qulityThumbDocument2 = imageReceiver.getQulityThumbDocument();
                                    thumbLocation = imageReceiver.getThumbLocation();
                                    String thumbFilter2 = imageReceiver.getThumbFilter();
                                    ImageLocation mediaLocation22 = imageReceiver.getMediaLocation();
                                    String mediaFilter2 = imageReceiver.getMediaFilter();
                                    imageLocation = imageReceiver.getImageLocation();
                                    String imageFilter2 = imageReceiver.getImageFilter();
                                    if (!(parentObject instanceof MessageObject)) {
                                    }
                                    z4 = true;
                                    ext = imageReceiver.getExt();
                                    if (ext == null) {
                                    }
                                    imageLocation2 = mediaLocation22;
                                    String str922 = null;
                                    String str1022 = null;
                                    String str1122 = null;
                                    String str1222 = null;
                                    i = 0;
                                    boolean z722 = false;
                                    while (i < 2) {
                                    }
                                    int i322 = 1;
                                    if (thumbLocation != null) {
                                    }
                                    str3 = str1122;
                                    str3 = str3 + "@" + mediaFilter2;
                                    str4 = str1222;
                                    str4 = str4 + "@" + imageFilter2;
                                    str2 = str2 + "@" + thumbFilter2;
                                    if (imageLocation == null) {
                                    }
                                    if (imageLocation2 != null) {
                                    }
                                } else {
                                    return;
                                }
                            }
                        }
                        z2 = z;
                        thumbKey = imageReceiver.getThumbKey();
                        if (thumbKey != null) {
                        }
                        z3 = false;
                        parentObject = imageReceiver.getParentObject();
                        TLRPC.Document qulityThumbDocument22 = imageReceiver.getQulityThumbDocument();
                        thumbLocation = imageReceiver.getThumbLocation();
                        String thumbFilter22 = imageReceiver.getThumbFilter();
                        ImageLocation mediaLocation222 = imageReceiver.getMediaLocation();
                        String mediaFilter22 = imageReceiver.getMediaFilter();
                        imageLocation = imageReceiver.getImageLocation();
                        String imageFilter22 = imageReceiver.getImageFilter();
                        if (!(parentObject instanceof MessageObject)) {
                        }
                        z4 = true;
                        ext = imageReceiver.getExt();
                        if (ext == null) {
                        }
                        imageLocation2 = mediaLocation222;
                        String str9222 = null;
                        String str10222 = null;
                        String str11222 = null;
                        String str12222 = null;
                        i = 0;
                        boolean z7222 = false;
                        while (i < 2) {
                        }
                        int i3222 = 1;
                        if (thumbLocation != null) {
                        }
                        str3 = str11222;
                        str3 = str3 + "@" + mediaFilter22;
                        str4 = str12222;
                        str4 = str4 + "@" + imageFilter22;
                        str2 = str2 + "@" + thumbFilter22;
                        if (imageLocation == null) {
                        }
                        if (imageLocation2 != null) {
                        }
                    } else {
                        return;
                    }
                }
            }
            z = false;
            imageKey = imageReceiver.getImageKey();
            imageLocation3 = imageReceiver.getImageLocation();
            if (imageLocation3 != null) {
            }
            bitmapDrawable2 = this.memCache.get(imageKey);
            if (bitmapDrawable2 != null) {
            }
            if (bitmapDrawable2 != null) {
            }
            z2 = z;
            thumbKey = imageReceiver.getThumbKey();
            if (thumbKey != null) {
            }
            z3 = false;
            parentObject = imageReceiver.getParentObject();
            TLRPC.Document qulityThumbDocument222 = imageReceiver.getQulityThumbDocument();
            thumbLocation = imageReceiver.getThumbLocation();
            String thumbFilter222 = imageReceiver.getThumbFilter();
            ImageLocation mediaLocation2222 = imageReceiver.getMediaLocation();
            String mediaFilter222 = imageReceiver.getMediaFilter();
            imageLocation = imageReceiver.getImageLocation();
            String imageFilter222 = imageReceiver.getImageFilter();
            if (!(parentObject instanceof MessageObject)) {
            }
            z4 = true;
            ext = imageReceiver.getExt();
            if (ext == null) {
            }
            imageLocation2 = mediaLocation2222;
            String str92222 = null;
            String str102222 = null;
            String str112222 = null;
            String str122222 = null;
            i = 0;
            boolean z72222 = false;
            while (i < 2) {
            }
            int i32222 = 1;
            if (thumbLocation != null) {
            }
            str3 = str112222;
            str3 = str3 + "@" + mediaFilter222;
            str4 = str122222;
            str4 = str4 + "@" + imageFilter222;
            str2 = str2 + "@" + thumbFilter222;
            if (imageLocation == null) {
            }
            if (imageLocation2 != null) {
            }
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void httpFileLoadError(String str) {
        this.imageLoadQueue.postRunnable(new Runnable(str) {
            /* class im.guobwnxjuc.messenger.$$Lambda$ImageLoader$SkagYLCniDTKxdnmEUpOIm_oJmY */
            private final /* synthetic */ String f$1;

            {
                this.f$1 = r2;
            }

            public final void run() {
                ImageLoader.this.lambda$httpFileLoadError$6$ImageLoader(this.f$1);
            }
        });
    }

    public /* synthetic */ void lambda$httpFileLoadError$6$ImageLoader(String str) {
        CacheImage cacheImage = this.imageLoadingByUrl.get(str);
        if (cacheImage != null) {
            HttpImageTask httpImageTask = cacheImage.httpTask;
            cacheImage.httpTask = new HttpImageTask(httpImageTask.cacheImage, httpImageTask.imageSize);
            this.httpTasks.add(cacheImage.httpTask);
            runHttpTasks(false);
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void artworkLoadError(String str) {
        this.imageLoadQueue.postRunnable(new Runnable(str) {
            /* class im.guobwnxjuc.messenger.$$Lambda$ImageLoader$z4CyW1opv3w6xbqLPjW9F6ATOBM */
            private final /* synthetic */ String f$1;

            {
                this.f$1 = r2;
            }

            public final void run() {
                ImageLoader.this.lambda$artworkLoadError$7$ImageLoader(this.f$1);
            }
        });
    }

    public /* synthetic */ void lambda$artworkLoadError$7$ImageLoader(String str) {
        CacheImage cacheImage = this.imageLoadingByUrl.get(str);
        if (cacheImage != null) {
            cacheImage.artworkTask = new ArtworkLoadTask(cacheImage.artworkTask.cacheImage);
            this.artworkTasks.add(cacheImage.artworkTask);
            runArtworkTasks(false);
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void fileDidLoaded(String str, File file, int i) {
        this.imageLoadQueue.postRunnable(new Runnable(str, i, file) {
            /* class im.guobwnxjuc.messenger.$$Lambda$ImageLoader$gh2YDNF18bQ7ZCyvGWQexPJXwI0 */
            private final /* synthetic */ String f$1;
            private final /* synthetic */ int f$2;
            private final /* synthetic */ File f$3;

            {
                this.f$1 = r2;
                this.f$2 = r3;
                this.f$3 = r4;
            }

            public final void run() {
                ImageLoader.this.lambda$fileDidLoaded$8$ImageLoader(this.f$1, this.f$2, this.f$3);
            }
        });
    }

    public /* synthetic */ void lambda$fileDidLoaded$8$ImageLoader(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) {
            this.imageLoadingByUrl.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.imageTypes.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.secureDocument = cacheImage.secureDocument;
                    cacheImage2.currentAccount = cacheImage.currentAccount;
                    cacheImage2.finalFilePath = file;
                    cacheImage2.key = str2;
                    cacheImage2.imageLocation = cacheImage.imageLocation;
                    cacheImage2.imageType = intValue;
                    cacheImage2.ext = cacheImage.ext;
                    cacheImage2.encryptionKeyPath = cacheImage.encryptionKeyPath;
                    cacheImage2.cacheTask = new CacheOutTask(cacheImage2);
                    cacheImage2.filter = str3;
                    cacheImage2.animatedFile = cacheImage.animatedFile;
                    cacheImage2.lottieFile = cacheImage.lottieFile;
                    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.imageType == 1) {
                    this.cacheThumbOutQueue.postRunnable(cacheOutTask);
                } else {
                    this.cacheOutQueue.postRunnable(cacheOutTask);
                }
            }
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void fileDidFailedLoad(String str, int i) {
        if (i != 1) {
            this.imageLoadQueue.postRunnable(new Runnable(str) {
                /* class im.guobwnxjuc.messenger.$$Lambda$ImageLoader$Ac9VKluEf_XR7NumqPqWmNgyllg */
                private final /* synthetic */ String f$1;

                {
                    this.f$1 = r2;
                }

                public final void run() {
                    ImageLoader.this.lambda$fileDidFailedLoad$9$ImageLoader(this.f$1);
                }
            });
        }
    }

    public /* synthetic */ void lambda$fileDidFailedLoad$9$ImageLoader(String str) {
        CacheImage cacheImage = this.imageLoadingByUrl.get(str);
        if (cacheImage != null) {
            cacheImage.setImageAndClear(null, null);
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private 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++;
            }
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private 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);
        File directory = FileLoader.getDirectory(4);
        return new File(directory, Utilities.MD5(str) + "." + httpUrlExtension);
    }

    public void loadHttpFile(String str, String str2, int i) {
        if (str != null && str.length() != 0 && !this.httpFileLoadTasksByKeys.containsKey(str)) {
            String httpUrlExtension = getHttpUrlExtension(str, str2);
            File directory = FileLoader.getDirectory(4);
            File file = new File(directory, 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);
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void runHttpFileLoadTasks(HttpFileTask httpFileTask, int i) {
        AndroidUtilities.runOnUIThread(new Runnable(httpFileTask, i) {
            /* class im.guobwnxjuc.messenger.$$Lambda$ImageLoader$yKuBFd9pDaK3qX8X2A1gXutblM */
            private final /* synthetic */ ImageLoader.HttpFileTask f$1;
            private final /* synthetic */ int f$2;

            {
                this.f$1 = r2;
                this.f$2 = r3;
            }

            public final void run() {
                ImageLoader.this.lambda$runHttpFileLoadTasks$11$ImageLoader(this.f$1, this.f$2);
            }
        });
    }

    public /* synthetic */ void lambda$runHttpFileLoadTasks$11$ImageLoader(HttpFileTask httpFileTask, int i) {
        if (httpFileTask != null) {
            this.currentHttpFileLoadTasksCount--;
        }
        if (httpFileTask != null) {
            if (i == 1) {
                if (httpFileTask.canRetry) {
                    $$Lambda$ImageLoader$U6AllnGOXGwqJ82Eta92UX6uRaI r3 = new Runnable(new HttpFileTask(httpFileTask.url, httpFileTask.tempFile, httpFileTask.ext, httpFileTask.currentAccount)) {
                        /* class im.guobwnxjuc.messenger.$$Lambda$ImageLoader$U6AllnGOXGwqJ82Eta92UX6uRaI */
                        private final /* synthetic */ ImageLoader.HttpFileTask f$1;

                        {
                            this.f$1 = r2;
                        }

                        public final void run() {
                            ImageLoader.this.lambda$null$10$ImageLoader(this.f$1);
                        }
                    };
                    this.retryHttpsTasks.put(httpFileTask.url, r3);
                    AndroidUtilities.runOnUIThread(r3, 1000);
                } else {
                    this.httpFileLoadTasksByKeys.remove(httpFileTask.url);
                    NotificationCenter.getInstance(httpFileTask.currentAccount).postNotificationName(NotificationCenter.httpFileDidFailedLoad, httpFileTask.url, 0);
                }
            } else if (i == 2) {
                this.httpFileLoadTasksByKeys.remove(httpFileTask.url);
                File file = new File(FileLoader.getDirectory(4), Utilities.MD5(httpFileTask.url) + "." + httpFileTask.ext);
                if (!httpFileTask.tempFile.renameTo(file)) {
                    file = httpFileTask.tempFile;
                }
                NotificationCenter.getInstance(httpFileTask.currentAccount).postNotificationName(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 /* synthetic */ void lambda$null$10$ImageLoader(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 = (float) options.outWidth;
        float f2 = (float) options.outHeight;
        if (f / f2 > 10.0f || f2 / f > 10.0f) {
            return true;
        }
        return false;
    }

    /* JADX WARNING: Removed duplicated region for block: B:24:0x0060  */
    /* JADX WARNING: Removed duplicated region for block: B:25:0x0065  */
    /* JADX WARNING: Removed duplicated region for block: B:28:0x006f  */
    /* JADX WARNING: Removed duplicated region for block: B:31:0x007d  */
    /* JADX WARNING: Removed duplicated region for block: B:38:0x008e  */
    /* JADX WARNING: Removed duplicated region for block: B:41:0x0093  */
    /* JADX WARNING: Removed duplicated region for block: B:42:0x0095  */
    /* JADX WARNING: Removed duplicated region for block: B:46:0x009f A[SYNTHETIC, Splitter:B:46:0x009f] */
    /* JADX WARNING: Removed duplicated region for block: B:63:0x00d1 A[SYNTHETIC, Splitter:B:63:0x00d1] */
    /* JADX WARNING: Removed duplicated region for block: B:90:0x0132  */
    public static Bitmap loadBitmap(String str, Uri uri, float f, float f2, boolean z) {
        InputStream inputStream;
        float max;
        String str2;
        Matrix matrix;
        Throwable th;
        Bitmap bitmap;
        Bitmap createBitmap;
        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 th2) {
                    FileLog.e(th2);
                }
            }
        }
        Bitmap bitmap2 = null;
        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();
                inputStream = ApplicationLoader.applicationContext.getContentResolver().openInputStream(uri);
                float f3 = ((float) options.outWidth) / f;
                float f4 = ((float) options.outHeight) / f2;
                max = !z ? Math.max(f3, f4) : Math.min(f3, f4);
                if (max < 1.0f) {
                    max = 1.0f;
                }
                boolean z2 = false;
                options.inJustDecodeBounds = false;
                options.inSampleSize = (int) max;
                if (options.inSampleSize % 2 != 0) {
                    int i = 1;
                    while (true) {
                        int i2 = i * 2;
                        if (i2 >= options.inSampleSize) {
                            break;
                        }
                        i = i2;
                    }
                    options.inSampleSize = i;
                }
                if (Build.VERSION.SDK_INT < 21) {
                    z2 = true;
                }
                options.inPurgeable = z2;
                if (str == null) {
                    str2 = str;
                } else {
                    str2 = uri != null ? AndroidUtilities.getPath(uri) : null;
                }
                if (str2 != null) {
                    try {
                        int attributeInt = new ExifInterface(str2).getAttributeInt(ExifInterface.TAG_ORIENTATION, 1);
                        matrix = new Matrix();
                        if (attributeInt == 3) {
                            matrix.postRotate(180.0f);
                        } else if (attributeInt == 6) {
                            matrix.postRotate(90.0f);
                        } else if (attributeInt == 8) {
                            try {
                                matrix.postRotate(270.0f);
                            } catch (Throwable unused) {
                            }
                        }
                    } catch (Throwable unused2) {
                    }
                    if (str != null) {
                        try {
                            Bitmap decodeFile = BitmapFactory.decodeFile(str, options);
                            if (decodeFile == null) {
                                return decodeFile;
                            }
                            if (options.inPurgeable) {
                                Utilities.pinBitmap(decodeFile);
                            }
                            Bitmap createBitmap2 = Bitmaps.createBitmap(decodeFile, 0, 0, decodeFile.getWidth(), decodeFile.getHeight(), matrix, true);
                            if (createBitmap2 == decodeFile) {
                                return decodeFile;
                            }
                            decodeFile.recycle();
                            return createBitmap2;
                        } catch (Throwable th3) {
                            FileLog.e(th3);
                            return null;
                        }
                    } else if (uri == null) {
                        return null;
                    } else {
                        try {
                            Bitmap decodeStream = BitmapFactory.decodeStream(inputStream, null, options);
                            if (decodeStream != null) {
                                try {
                                    if (options.inPurgeable) {
                                        Utilities.pinBitmap(decodeStream);
                                    }
                                    Bitmap createBitmap3 = Bitmaps.createBitmap(decodeStream, 0, 0, decodeStream.getWidth(), decodeStream.getHeight(), matrix, true);
                                    if (createBitmap3 != decodeStream) {
                                        decodeStream.recycle();
                                        bitmap = createBitmap3;
                                        inputStream.close();
                                        return bitmap;
                                    }
                                } catch (Throwable th4) {
                                    th = th4;
                                    bitmap2 = decodeStream;
                                    try {
                                        FileLog.e(th);
                                        inputStream.close();
                                        return bitmap2;
                                    } catch (Throwable th5) {
                                        FileLog.e(th5);
                                    }
                                }
                            }
                            bitmap = decodeStream;
                            try {
                                inputStream.close();
                                return bitmap;
                            } catch (Throwable th6) {
                                FileLog.e(th6);
                                return bitmap;
                            }
                        } catch (Throwable th7) {
                            th = th7;
                            FileLog.e(th);
                            inputStream.close();
                            return bitmap2;
                        }
                    }
                }
                matrix = null;
                if (str != null) {
                }
            } catch (Throwable th8) {
                FileLog.e(th8);
                return null;
            }
        }
        inputStream = null;
        float f32 = ((float) options.outWidth) / f;
        float f42 = ((float) options.outHeight) / f2;
        if (!z) {
        }
        if (max < 1.0f) {
        }
        boolean z22 = false;
        options.inJustDecodeBounds = false;
        options.inSampleSize = (int) max;
        if (options.inSampleSize % 2 != 0) {
        }
        if (Build.VERSION.SDK_INT < 21) {
        }
        options.inPurgeable = z22;
        if (str == null) {
        }
        if (str2 != null) {
        }
        matrix = null;
        if (str != null) {
        }
        throw th;
    }

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

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

    public static TLRPC.PhotoSize SaveImageWithOriginalInternal(TLRPC.PhotoSize photoSize, String str, boolean z) throws Exception {
        TLRPC.TL_fileLocationToBeDeprecated tL_fileLocationToBeDeprecated;
        int i = 0;
        if (photoSize == null || !(photoSize.location instanceof TLRPC.TL_fileLocationToBeDeprecated)) {
            tL_fileLocationToBeDeprecated = new TLRPC.TL_fileLocationToBeDeprecated();
            tL_fileLocationToBeDeprecated.volume_id = -2147483648L;
            tL_fileLocationToBeDeprecated.dc_id = Integer.MIN_VALUE;
            tL_fileLocationToBeDeprecated.local_id = SharedConfig.getLastLocalId();
            tL_fileLocationToBeDeprecated.file_reference = new byte[0];
            photoSize = new TLRPC.TL_photoSize();
            photoSize.location = tL_fileLocationToBeDeprecated;
            BitmapFactory.Options options = new BitmapFactory.Options();
            BitmapFactory.decodeFile(str, options);
            photoSize.w = options.outWidth;
            photoSize.h = options.outHeight;
            if (photoSize.w <= 100 && photoSize.h <= 100) {
                photoSize.type = "s";
            } else if (photoSize.w <= 320 && photoSize.h <= 320) {
                photoSize.type = "m";
            } else if (photoSize.w <= 800 && photoSize.h <= 800) {
                photoSize.type = "x";
            } else if (photoSize.w > 1280 || photoSize.h > 1280) {
                photoSize.type = "w";
            } else {
                photoSize.type = "y";
            }
        } else {
            tL_fileLocationToBeDeprecated = (TLRPC.TL_fileLocationToBeDeprecated) photoSize.location;
        }
        String str2 = tL_fileLocationToBeDeprecated.volume_id + "_" + tL_fileLocationToBeDeprecated.local_id + ".jpg";
        if (tL_fileLocationToBeDeprecated.volume_id == -2147483648L) {
            i = 4;
        }
        File file = new File(FileLoader.getDirectory(i), str2);
        FileInputStream fileInputStream = new FileInputStream(str);
        AndroidUtilities.copyFile(fileInputStream, file);
        if (z) {
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            photoSize.bytes = byteArrayOutputStream.toByteArray();
            photoSize.size = photoSize.bytes.length;
            byteArrayOutputStream.close();
        } else {
            photoSize.size = (int) fileInputStream.getChannel().size();
        }
        fileInputStream.close();
        return photoSize;
    }

    public static TLRPC.PhotoSize scaleAndSaveImage(Bitmap bitmap, float f, float f2, int i, boolean z) {
        return scaleAndSaveImage(null, bitmap, f, f2, i, z, 0, 0, false);
    }

    public static TLRPC.PhotoSize scaleAndSaveImage(TLRPC.PhotoSize photoSize, Bitmap bitmap, float f, float f2, int i, boolean z) {
        return scaleAndSaveImage(photoSize, bitmap, f, f2, i, z, 0, 0, false);
    }

    public static TLRPC.PhotoSize scaleAndSaveImage(Bitmap bitmap, float f, float f2, int i, boolean z, int i2, int i3) {
        return scaleAndSaveImage(null, bitmap, f, f2, i, z, i2, i3, false);
    }

    public static TLRPC.PhotoSize scaleAndSaveImage(Bitmap bitmap, float f, float f2, int i, boolean z, boolean z2) {
        return scaleAndSaveImage(null, bitmap, 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, boolean z2) {
        return scaleAndSaveImage(null, bitmap, f, f2, i, z, i2, i3, z2);
    }

    public static TLRPC.PhotoSize scaleAndSaveImage(TLRPC.PhotoSize photoSize, Bitmap bitmap, float f, float f2, int i, boolean z, int i2, int i3, boolean z2) {
        boolean z3;
        float f3;
        int i4;
        int i5;
        float f4;
        if (bitmap == null) {
            return null;
        }
        float width = (float) bitmap.getWidth();
        float height = (float) bitmap.getHeight();
        if (!(width == 0.0f || height == 0.0f)) {
            float max = Math.max(width / f, height / f2);
            if (!(i2 == 0 || i3 == 0)) {
                float f5 = (float) i2;
                if (width < f5 || height < ((float) i3)) {
                    if (width >= f5 || height <= ((float) i3)) {
                        if (width > f5) {
                            float f6 = (float) i3;
                            if (height < f6) {
                                f4 = height / f6;
                            }
                        }
                        f4 = Math.max(width / f5, height / ((float) i3));
                    } else {
                        f4 = width / f5;
                    }
                    f3 = f4;
                    z3 = true;
                    i4 = (int) (width / f3);
                    i5 = (int) (height / f3);
                    if (!(i5 == 0 || i4 == 0)) {
                        return scaleAndSaveImageInternal(photoSize, bitmap, i4, i5, width, height, f3, i, z, z3, z2);
                    }
                }
            }
            f3 = max;
            z3 = false;
            i4 = (int) (width / f3);
            i5 = (int) (height / f3);
            try {
                return scaleAndSaveImageInternal(photoSize, bitmap, i4, i5, width, height, f3, i, z, z3, z2);
            } catch (Throwable th) {
                FileLog.e(th);
            }
        }
        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 message) {
        TLRPC.PhotoSize photoSize;
        int i = 0;
        TLRPC.PhotoSize photoSize2 = null;
        if (message.media instanceof TLRPC.TL_messageMediaPhoto) {
            int size = message.media.photo.sizes.size();
            int i2 = 0;
            while (true) {
                if (i2 >= size) {
                    break;
                }
                photoSize = message.media.photo.sizes.get(i2);
                if (photoSize instanceof TLRPC.TL_photoCachedSize) {
                    break;
                }
                i2++;
            }
        } else if (message.media instanceof TLRPC.TL_messageMediaDocument) {
            int size2 = message.media.document.thumbs.size();
            int i3 = 0;
            while (true) {
                if (i3 >= size2) {
                    break;
                }
                photoSize = message.media.document.thumbs.get(i3);
                if (photoSize instanceof TLRPC.TL_photoCachedSize) {
                    break;
                }
                i3++;
            }
        } else {
            if ((message.media instanceof TLRPC.TL_messageMediaWebPage) && message.media.webpage.photo != null) {
                int size3 = message.media.webpage.photo.sizes.size();
                int i4 = 0;
                while (true) {
                    if (i4 >= size3) {
                        break;
                    }
                    photoSize = message.media.webpage.photo.sizes.get(i4);
                    if (photoSize instanceof TLRPC.TL_photoCachedSize) {
                        break;
                    }
                    i4++;
                }
            }
            if (photoSize2 != null && photoSize2.bytes != null && photoSize2.bytes.length != 0) {
                if (photoSize2.location == null || (photoSize2.location instanceof TLRPC.TL_fileLocationUnavailable)) {
                    photoSize2.location = new TLRPC.TL_fileLocationToBeDeprecated();
                    photoSize2.location.volume_id = -2147483648L;
                    photoSize2.location.local_id = SharedConfig.getLastLocalId();
                }
                boolean z = true;
                File pathToAttach = FileLoader.getPathToAttach(photoSize2, true);
                if (MessageObject.shouldEncryptPhotoOrVideo(message)) {
                    pathToAttach = new File(pathToAttach.getAbsolutePath() + ".enc");
                } else {
                    z = false;
                }
                if (!pathToAttach.exists()) {
                    if (z) {
                        try {
                            File internalCacheDir = FileLoader.getInternalCacheDir();
                            RandomAccessFile randomAccessFile = new RandomAccessFile(new File(internalCacheDir, pathToAttach.getName() + ".key"), "rws");
                            long length = randomAccessFile.length();
                            byte[] bArr = new byte[32];
                            byte[] bArr2 = new byte[16];
                            if (length <= 0 || length % 48 != 0) {
                                Utilities.random.nextBytes(bArr);
                                Utilities.random.nextBytes(bArr2);
                                randomAccessFile.write(bArr);
                                randomAccessFile.write(bArr2);
                            } else {
                                randomAccessFile.read(bArr, 0, 32);
                                randomAccessFile.read(bArr2, 0, 16);
                            }
                            randomAccessFile.close();
                            Utilities.aesCtrDecryptionByteArray(photoSize2.bytes, bArr, bArr2, 0, photoSize2.bytes.length, 0);
                        } catch (Exception e) {
                            FileLog.e(e);
                        }
                    }
                    RandomAccessFile randomAccessFile2 = new RandomAccessFile(pathToAttach, "rws");
                    randomAccessFile2.write(photoSize2.bytes);
                    randomAccessFile2.close();
                }
                TLRPC.TL_photoSize tL_photoSize = new TLRPC.TL_photoSize();
                tL_photoSize.w = photoSize2.w;
                tL_photoSize.h = photoSize2.h;
                tL_photoSize.location = photoSize2.location;
                tL_photoSize.size = photoSize2.size;
                tL_photoSize.type = photoSize2.type;
                if (message.media instanceof TLRPC.TL_messageMediaPhoto) {
                    int size4 = message.media.photo.sizes.size();
                    while (i < size4) {
                        if (message.media.photo.sizes.get(i) instanceof TLRPC.TL_photoCachedSize) {
                            message.media.photo.sizes.set(i, tL_photoSize);
                            return;
                        }
                        i++;
                    }
                    return;
                } else if (message.media instanceof TLRPC.TL_messageMediaDocument) {
                    int size5 = message.media.document.thumbs.size();
                    while (i < size5) {
                        if (message.media.document.thumbs.get(i) instanceof TLRPC.TL_photoCachedSize) {
                            message.media.document.thumbs.set(i, tL_photoSize);
                            return;
                        }
                        i++;
                    }
                    return;
                } else if (message.media instanceof TLRPC.TL_messageMediaWebPage) {
                    int size6 = message.media.webpage.photo.sizes.size();
                    while (i < size6) {
                        if (message.media.webpage.photo.sizes.get(i) instanceof TLRPC.TL_photoCachedSize) {
                            message.media.webpage.photo.sizes.set(i, tL_photoSize);
                            return;
                        }
                        i++;
                    }
                    return;
                } else {
                    return;
                }
            } else {
                return;
            }
        }
        photoSize2 = photoSize;
        if (photoSize2 != null) {
        }
    }

    public static void saveMessagesThumbs(ArrayList<TLRPC.Message> arrayList) {
        if (!(arrayList == null || arrayList.isEmpty())) {
            for (int i = 0; i < arrayList.size(); i++) {
                saveMessageThumbs(arrayList.get(i));
            }
        }
    }
}