正在查看: КЛ£ v1.0.0 应用的 ImageLoader.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: КЛ£ v1.0.0 应用的 ImageLoader.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package im.pggrnmxjgs.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.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.media.ThumbnailUtils;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Environment;
import android.text.TextUtils;
import android.util.SparseArray;
import im.pggrnmxjgs.messenger.FileLoader;
import im.pggrnmxjgs.messenger.ImageLoader;
import im.pggrnmxjgs.tgnet.ConnectionsManager;
import im.pggrnmxjgs.tgnet.RequestDelegate;
import im.pggrnmxjgs.tgnet.TLObject;
import im.pggrnmxjgs.tgnet.TLRPC;
import im.pggrnmxjgs.ui.components.AnimatedFileDrawable;
import im.pggrnmxjgs.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 boolean canForce8888;
private LruCache<RLottieDrawable> lottieMemCache;
private LruCache<BitmapDrawable> memCache;
private static ThreadLocal<byte[]> bytesLocal = new ThreadLocal<>();
private static ThreadLocal<byte[]> bytesThumbLocal = new ThreadLocal<>();
private static byte[] header = new byte[12];
private static byte[] headerThumb = new byte[12];
private static volatile ImageLoader Instance = null;
private HashMap<String, Integer> bitmapUseCounts = new HashMap<>();
private HashMap<String, CacheImage> imageLoadingByUrl = new HashMap<>();
private HashMap<String, CacheImage> imageLoadingByKeys = new HashMap<>();
private SparseArray<CacheImage> imageLoadingByTag = new SparseArray<>();
private HashMap<String, ThumbGenerateInfo> waitingForQualityThumb = new HashMap<>();
private SparseArray<String> waitingForQualityThumbByTag = new SparseArray<>();
private LinkedList<HttpImageTask> httpTasks = new LinkedList<>();
private LinkedList<ArtworkLoadTask> artworkTasks = new LinkedList<>();
private DispatchQueue cacheOutQueue = new DispatchQueue("cacheOutQueue");
private DispatchQueue cacheThumbOutQueue = new DispatchQueue("cacheThumbOutQueue");
private DispatchQueue thumbGeneratingQueue = new DispatchQueue("thumbGeneratingQueue");
private DispatchQueue imageLoadQueue = new DispatchQueue("imageLoadQueue");
private HashMap<String, String> replacedBitmaps = new HashMap<>();
private ConcurrentHashMap<String, Float> fileProgresses = new ConcurrentHashMap<>();
private HashMap<String, ThumbGenerateTask> thumbGenerateTasks = new HashMap<>();
private HashMap<String, Integer> forceLoadingImages = new HashMap<>();
private int currentHttpTasksCount = 0;
private int currentArtworkTasksCount = 0;
private ConcurrentHashMap<String, WebFile> testWebFile = new ConcurrentHashMap<>();
private LinkedList<HttpFileTask> httpFileLoadTasks = new LinkedList<>();
private HashMap<String, HttpFileTask> httpFileLoadTasksByKeys = new HashMap<>();
private HashMap<String, Runnable> retryHttpsTasks = new HashMap<>();
private int currentHttpFileLoadTasksCount = 0;
private String ignoreRemoval = null;
private volatile long lastCacheOutTime = 0;
private int lastImageNum = 0;
private long lastProgressUpdateTime = 0;
private File appPath = null;
private class ThumbGenerateInfo {
private boolean big;
private String filter;
private ArrayList<ImageReceiver> imageReceiverArray;
private ArrayList<Integer> imageReceiverGuidsArray;
private TLRPC.Document parentDocument;
private ThumbGenerateInfo() {
this.imageReceiverArray = new ArrayList<>();
this.imageReceiverGuidsArray = new ArrayList<>();
}
}
class HttpFileTask extends AsyncTask<Void, Void, Boolean> {
private int currentAccount;
private String ext;
private int fileSize;
private long lastProgressTime;
private File tempFile;
private String url;
private RandomAccessFile fileOutputStream = null;
private boolean canRetry = true;
public HttpFileTask(String url, File tempFile, String ext, int currentAccount) {
this.url = url;
this.tempFile = tempFile;
this.ext = ext;
this.currentAccount = currentAccount;
}
private void reportProgress(final float progress) {
long currentTime = System.currentTimeMillis();
if (progress != 1.0f) {
long j = this.lastProgressTime;
if (j != 0 && j >= currentTime - 500) {
return;
}
}
this.lastProgressTime = currentTime;
Utilities.stageQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ImageLoader.HttpFileTask.this.lambda$reportProgress$1$ImageLoader$HttpFileTask(progress);
}
});
}
public void lambda$reportProgress$1$ImageLoader$HttpFileTask(final float progress) {
ImageLoader.this.fileProgresses.put(this.url, Float.valueOf(progress));
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
ImageLoader.HttpFileTask.this.lambda$null$0$ImageLoader$HttpFileTask(progress);
}
});
}
public void lambda$null$0$ImageLoader$HttpFileTask(float progress) {
NotificationCenter.getInstance(this.currentAccount).postNotificationName(NotificationCenter.FileLoadProgressChanged, this.url, Float.valueOf(progress));
}
@Override
public Boolean doInBackground(Void... voids) {
List values;
String length;
int code;
InputStream httpConnectionStream = null;
boolean done = false;
URLConnection httpConnection = null;
try {
URL downloadUrl = new URL(this.url);
httpConnection = downloadUrl.openConnection();
httpConnection.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");
httpConnection.setConnectTimeout(5000);
httpConnection.setReadTimeout(5000);
if (httpConnection instanceof HttpURLConnection) {
HttpURLConnection httpURLConnection = (HttpURLConnection) httpConnection;
httpURLConnection.setInstanceFollowRedirects(true);
int status = httpURLConnection.getResponseCode();
if (status == 302 || status == 301 || status == 303) {
String newUrl = httpURLConnection.getHeaderField("Location");
String cookies = httpURLConnection.getHeaderField("Set-Cookie");
URL downloadUrl2 = new URL(newUrl);
httpConnection = downloadUrl2.openConnection();
httpConnection.setRequestProperty("Cookie", cookies);
httpConnection.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");
}
}
httpConnection.connect();
httpConnectionStream = httpConnection.getInputStream();
this.fileOutputStream = new RandomAccessFile(this.tempFile, "rws");
} catch (Throwable e) {
if (e instanceof SocketTimeoutException) {
if (ApplicationLoader.isNetworkOnline()) {
this.canRetry = false;
}
} else if (e instanceof UnknownHostException) {
this.canRetry = false;
} else if (e instanceof SocketException) {
if (e.getMessage() != null && e.getMessage().contains("ECONNRESET")) {
this.canRetry = false;
}
} else if (e instanceof FileNotFoundException) {
this.canRetry = false;
}
FileLog.e(e);
}
if (this.canRetry) {
try {
if ((httpConnection instanceof HttpURLConnection) && (code = ((HttpURLConnection) httpConnection).getResponseCode()) != 200 && code != 202 && code != 304) {
this.canRetry = false;
}
} catch (Exception e2) {
FileLog.e(e2);
}
if (httpConnection != null) {
try {
Map<String, List<String>> headerFields = httpConnection.getHeaderFields();
if (headerFields != null && (values = headerFields.get("content-Length")) != null && !values.isEmpty() && (length = values.get(0)) != null) {
this.fileSize = Utilities.parseInt(length).intValue();
}
} catch (Exception e3) {
FileLog.e(e3);
}
}
if (httpConnectionStream != null) {
try {
byte[] data = new byte[32768];
int totalLoaded = 0;
while (!isCancelled()) {
try {
int read = httpConnectionStream.read(data);
if (read > 0) {
this.fileOutputStream.write(data, 0, read);
totalLoaded += read;
if (this.fileSize > 0) {
reportProgress(totalLoaded / this.fileSize);
}
} else if (read == -1) {
done = true;
if (this.fileSize != 0) {
reportProgress(1.0f);
}
}
} catch (Exception e4) {
FileLog.e(e4);
}
}
} catch (Throwable e5) {
FileLog.e(e5);
}
}
try {
if (this.fileOutputStream != null) {
this.fileOutputStream.close();
this.fileOutputStream = null;
}
} catch (Throwable e6) {
FileLog.e(e6);
}
if (httpConnectionStream != null) {
try {
httpConnectionStream.close();
} catch (Throwable e7) {
FileLog.e(e7);
}
}
}
return Boolean.valueOf(done);
}
@Override
public void onPostExecute(Boolean result) {
ImageLoader.this.runHttpFileLoadTasks(this, result.booleanValue() ? 2 : 1);
}
@Override
protected void onCancelled() {
ImageLoader.this.runHttpFileLoadTasks(this, 2);
}
}
class ArtworkLoadTask extends AsyncTask<Void, Void, String> {
private CacheImage cacheImage;
private boolean canRetry = true;
private HttpURLConnection httpConnection;
private boolean small;
public ArtworkLoadTask(CacheImage cacheImage) {
this.cacheImage = cacheImage;
Uri uri = Uri.parse(cacheImage.imageLocation.path);
this.small = uri.getQueryParameter("s") != null;
}
@Override
public String doInBackground(Void... voids) {
int code;
ByteArrayOutputStream outbuf = null;
InputStream httpConnectionStream = null;
try {
try {
String location = this.cacheImage.imageLocation.path;
URL downloadUrl = new URL(location.replace("athumb://", "https://"));
HttpURLConnection httpURLConnection = (HttpURLConnection) downloadUrl.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 && (code = this.httpConnection.getResponseCode()) != 200 && code != 202 && code != 304) {
this.canRetry = false;
}
} catch (Exception e) {
FileLog.e(e);
}
httpConnectionStream = this.httpConnection.getInputStream();
outbuf = new ByteArrayOutputStream();
byte[] data = new byte[32768];
while (true) {
if (isCancelled()) {
break;
}
int read = httpConnectionStream.read(data);
if (read > 0) {
outbuf.write(data, 0, read);
} else if (read == -1) {
}
}
this.canRetry = false;
JSONObject object = new JSONObject(new String(outbuf.toByteArray()));
JSONArray array = object.getJSONArray("results");
if (array.length() <= 0) {
try {
if (this.httpConnection != null) {
this.httpConnection.disconnect();
}
} catch (Throwable th) {
}
if (httpConnectionStream != null) {
try {
httpConnectionStream.close();
} catch (Throwable e2) {
FileLog.e(e2);
}
}
outbuf.close();
return null;
}
JSONObject media = array.getJSONObject(0);
String artworkUrl100 = media.getString("artworkUrl100");
if (this.small) {
try {
if (this.httpConnection != null) {
this.httpConnection.disconnect();
}
} catch (Throwable th2) {
}
if (httpConnectionStream != null) {
try {
httpConnectionStream.close();
} catch (Throwable e3) {
FileLog.e(e3);
}
}
try {
outbuf.close();
} catch (Exception e4) {
}
return artworkUrl100;
}
String replace = artworkUrl100.replace("100x100", "600x600");
try {
if (this.httpConnection != null) {
this.httpConnection.disconnect();
}
} catch (Throwable th3) {
}
if (httpConnectionStream != null) {
try {
httpConnectionStream.close();
} catch (Throwable e5) {
FileLog.e(e5);
}
}
try {
outbuf.close();
} catch (Exception e6) {
}
return replace;
} catch (Throwable e7) {
try {
if (e7 instanceof SocketTimeoutException) {
if (ApplicationLoader.isNetworkOnline()) {
this.canRetry = false;
}
} else if (e7 instanceof UnknownHostException) {
this.canRetry = false;
} else if (e7 instanceof SocketException) {
if (e7.getMessage() != null && e7.getMessage().contains("ECONNRESET")) {
this.canRetry = false;
}
} else if (e7 instanceof FileNotFoundException) {
this.canRetry = false;
}
FileLog.e(e7);
try {
if (this.httpConnection != null) {
this.httpConnection.disconnect();
}
} catch (Throwable th4) {
}
if (httpConnectionStream != null) {
try {
httpConnectionStream.close();
} catch (Throwable e8) {
FileLog.e(e8);
}
}
if (outbuf == null) {
return null;
}
outbuf.close();
return null;
} catch (Throwable th5) {
try {
if (this.httpConnection != null) {
this.httpConnection.disconnect();
}
} catch (Throwable th6) {
}
if (httpConnectionStream != null) {
try {
httpConnectionStream.close();
} catch (Throwable e9) {
FileLog.e(e9);
}
}
if (outbuf == null) {
throw th5;
}
try {
outbuf.close();
throw th5;
} catch (Exception e10) {
throw th5;
}
}
}
} catch (Exception e11) {
return null;
}
}
@Override
public void onPostExecute(String result) {
if (result != null) {
this.cacheImage.httpTask = ImageLoader.this.new HttpImageTask(this.cacheImage, 0, result);
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() {
@Override
public final void run() {
ImageLoader.ArtworkLoadTask.this.lambda$onPostExecute$0$ImageLoader$ArtworkLoadTask();
}
});
}
public void lambda$onPostExecute$0$ImageLoader$ArtworkLoadTask() {
ImageLoader.this.runArtworkTasks(true);
}
public void lambda$onCancelled$1$ImageLoader$ArtworkLoadTask() {
ImageLoader.this.runArtworkTasks(true);
}
@Override
protected void onCancelled() {
ImageLoader.this.imageLoadQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ImageLoader.ArtworkLoadTask.this.lambda$onCancelled$1$ImageLoader$ArtworkLoadTask();
}
});
}
}
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;
public HttpImageTask(CacheImage cacheImage, int size) {
this.cacheImage = cacheImage;
this.imageSize = size;
}
public HttpImageTask(CacheImage cacheImage, int size, String url) {
this.cacheImage = cacheImage;
this.imageSize = size;
this.overrideUrl = url;
}
private void reportProgress(final float progress) {
long currentTime = System.currentTimeMillis();
if (progress != 1.0f) {
long j = this.lastProgressTime;
if (j != 0 && j >= currentTime - 500) {
return;
}
}
this.lastProgressTime = currentTime;
Utilities.stageQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ImageLoader.HttpImageTask.this.lambda$reportProgress$1$ImageLoader$HttpImageTask(progress);
}
});
}
public void lambda$reportProgress$1$ImageLoader$HttpImageTask(final float progress) {
ImageLoader.this.fileProgresses.put(this.cacheImage.url, Float.valueOf(progress));
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
ImageLoader.HttpImageTask.this.lambda$null$0$ImageLoader$HttpImageTask(progress);
}
});
}
public void lambda$null$0$ImageLoader$HttpImageTask(float progress) {
NotificationCenter.getInstance(this.cacheImage.currentAccount).postNotificationName(NotificationCenter.FileLoadProgressChanged, this.cacheImage.url, Float.valueOf(progress));
}
@Override
public Boolean doInBackground(Void... voids) {
int provider;
WebFile webFile;
HttpURLConnection httpURLConnection;
List values;
String length;
int code;
InputStream httpConnectionStream = null;
boolean done = false;
if (!isCancelled()) {
try {
String location = this.cacheImage.imageLocation.path;
if ((location.startsWith("https://static-maps") || location.startsWith("https://maps.googleapis")) && (((provider = MessagesController.getInstance(this.cacheImage.currentAccount).mapProvider) == 3 || provider == 4) && (webFile = (WebFile) ImageLoader.this.testWebFile.get(location)) != null)) {
TLRPC.TL_upload_getWebFile req = new TLRPC.TL_upload_getWebFile();
req.location = webFile.location;
req.offset = 0;
req.limit = 0;
ConnectionsManager.getInstance(this.cacheImage.currentAccount).sendRequest(req, new RequestDelegate() {
@Override
public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
ImageLoader.HttpImageTask.lambda$doInBackground$2(tLObject, tL_error);
}
});
}
URL downloadUrl = new URL(this.overrideUrl != null ? this.overrideUrl : location);
HttpURLConnection httpURLConnection2 = (HttpURLConnection) downloadUrl.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();
httpConnectionStream = this.httpConnection.getInputStream();
this.fileOutputStream = new RandomAccessFile(this.cacheImage.tempFilePath, "rws");
}
} catch (Throwable e) {
if (e instanceof SocketTimeoutException) {
if (ApplicationLoader.isNetworkOnline()) {
this.canRetry = false;
}
} else if (e instanceof UnknownHostException) {
this.canRetry = false;
} else if (e instanceof SocketException) {
if (e.getMessage() != null && e.getMessage().contains("ECONNRESET")) {
this.canRetry = false;
}
} else if (e instanceof FileNotFoundException) {
this.canRetry = false;
}
FileLog.e(e);
}
}
if (!isCancelled()) {
try {
if (this.httpConnection != null && (code = this.httpConnection.getResponseCode()) != 200 && code != 202 && code != 304) {
this.canRetry = false;
}
} catch (Exception e2) {
FileLog.e(e2);
}
if (this.imageSize == 0 && (httpURLConnection = this.httpConnection) != null) {
try {
Map<String, List<String>> headerFields = httpURLConnection.getHeaderFields();
if (headerFields != null && (values = headerFields.get("content-Length")) != null && !values.isEmpty() && (length = values.get(0)) != null) {
this.imageSize = Utilities.parseInt(length).intValue();
}
} catch (Exception e3) {
FileLog.e(e3);
}
}
if (httpConnectionStream != null) {
try {
byte[] data = new byte[MessagesController.UPDATE_MASK_CHAT];
int totalLoaded = 0;
while (!isCancelled()) {
try {
int read = httpConnectionStream.read(data);
if (read > 0) {
totalLoaded += read;
this.fileOutputStream.write(data, 0, read);
if (this.imageSize != 0) {
reportProgress(totalLoaded / this.imageSize);
}
} else if (read == -1) {
done = true;
if (this.imageSize != 0) {
reportProgress(1.0f);
}
}
} catch (Exception e4) {
FileLog.e(e4);
}
}
} catch (Throwable e5) {
FileLog.e(e5);
}
}
}
try {
if (this.fileOutputStream != null) {
this.fileOutputStream.close();
this.fileOutputStream = null;
}
} catch (Throwable e6) {
FileLog.e(e6);
}
try {
if (this.httpConnection != null) {
this.httpConnection.disconnect();
}
} catch (Throwable th) {
}
if (httpConnectionStream != null) {
try {
httpConnectionStream.close();
} catch (Throwable e7) {
FileLog.e(e7);
}
}
if (done && this.cacheImage.tempFilePath != null && !this.cacheImage.tempFilePath.renameTo(this.cacheImage.finalFilePath)) {
CacheImage cacheImage = this.cacheImage;
cacheImage.finalFilePath = cacheImage.tempFilePath;
}
return Boolean.valueOf(done);
}
static void lambda$doInBackground$2(TLObject response, TLRPC.TL_error error) {
}
@Override
public void onPostExecute(final Boolean result) {
if (result.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() {
@Override
public final void run() {
ImageLoader.HttpImageTask.this.lambda$onPostExecute$4$ImageLoader$HttpImageTask(result);
}
});
ImageLoader.this.imageLoadQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ImageLoader.HttpImageTask.this.lambda$onPostExecute$5$ImageLoader$HttpImageTask();
}
});
}
public void lambda$onPostExecute$4$ImageLoader$HttpImageTask(final Boolean result) {
ImageLoader.this.fileProgresses.remove(this.cacheImage.url);
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
ImageLoader.HttpImageTask.this.lambda$null$3$ImageLoader$HttpImageTask(result);
}
});
}
public void lambda$null$3$ImageLoader$HttpImageTask(Boolean result) {
if (result.booleanValue()) {
NotificationCenter.getInstance(this.cacheImage.currentAccount).postNotificationName(NotificationCenter.fileDidLoad, this.cacheImage.url, this.cacheImage.finalFilePath);
} else {
NotificationCenter.getInstance(this.cacheImage.currentAccount).postNotificationName(NotificationCenter.fileDidFailToLoad, this.cacheImage.url, 2);
}
}
public void lambda$onPostExecute$5$ImageLoader$HttpImageTask() {
ImageLoader.this.runHttpTasks(true);
}
public void lambda$onCancelled$6$ImageLoader$HttpImageTask() {
ImageLoader.this.runHttpTasks(true);
}
@Override
protected void onCancelled() {
ImageLoader.this.imageLoadQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ImageLoader.HttpImageTask.this.lambda$onCancelled$6$ImageLoader$HttpImageTask();
}
});
Utilities.stageQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ImageLoader.HttpImageTask.this.lambda$onCancelled$8$ImageLoader$HttpImageTask();
}
});
}
public void lambda$onCancelled$8$ImageLoader$HttpImageTask() {
ImageLoader.this.fileProgresses.remove(this.cacheImage.url);
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
ImageLoader.HttpImageTask.this.lambda$null$7$ImageLoader$HttpImageTask();
}
});
}
public void lambda$null$7$ImageLoader$HttpImageTask() {
NotificationCenter.getInstance(this.cacheImage.currentAccount).postNotificationName(NotificationCenter.fileDidFailToLoad, this.cacheImage.url, 1);
}
}
class ThumbGenerateTask implements Runnable {
private ThumbGenerateInfo info;
private int mediaType;
private File originalPath;
public ThumbGenerateTask(int type, File path, ThumbGenerateInfo i) {
this.mediaType = type;
this.originalPath = path;
this.info = i;
}
private void removeTask() {
ThumbGenerateInfo thumbGenerateInfo = this.info;
if (thumbGenerateInfo != null) {
final String name = FileLoader.getAttachFileName(thumbGenerateInfo.parentDocument);
ImageLoader.this.imageLoadQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ImageLoader.ThumbGenerateTask.this.lambda$removeTask$0$ImageLoader$ThumbGenerateTask(name);
}
});
}
}
public void lambda$removeTask$0$ImageLoader$ThumbGenerateTask(String name) {
}
@Override
public void run() {
Bitmap originalBitmap;
Bitmap scaledBitmap;
try {
if (this.info == null) {
removeTask();
return;
}
final String key = "q_" + this.info.parentDocument.dc_id + "_" + this.info.parentDocument.id;
File thumbFile = new File(FileLoader.getDirectory(4), key + ".jpg");
if (!thumbFile.exists() && this.originalPath.exists()) {
int size = this.info.big ? Math.max(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) : Math.min(180, Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) / 4);
Bitmap originalBitmap2 = null;
if (this.mediaType == 0) {
originalBitmap2 = ImageLoader.loadBitmap(this.originalPath.toString(), null, size, size, false);
} else {
int i = 2;
if (this.mediaType == 2) {
String file = this.originalPath.toString();
if (!this.info.big) {
i = 1;
}
originalBitmap2 = ThumbnailUtils.createVideoThumbnail(file, i);
} else if (this.mediaType == 3) {
String path = this.originalPath.toString().toLowerCase();
if (path.endsWith("mp4")) {
String file2 = this.originalPath.toString();
if (!this.info.big) {
i = 1;
}
originalBitmap2 = ThumbnailUtils.createVideoThumbnail(file2, i);
} else if (path.endsWith(".jpg") || path.endsWith(".jpeg") || path.endsWith(".png") || path.endsWith(".gif")) {
originalBitmap2 = ImageLoader.loadBitmap(path, null, size, size, false);
}
}
}
if (originalBitmap2 == null) {
removeTask();
return;
}
int w = originalBitmap2.getWidth();
int h = originalBitmap2.getHeight();
if (w != 0 && h != 0) {
float scaleFactor = Math.min(w / size, h / size);
if (scaleFactor > 1.0f && (scaledBitmap = Bitmaps.createScaledBitmap(originalBitmap2, (int) (w / scaleFactor), (int) (h / scaleFactor), true)) != originalBitmap2) {
originalBitmap2.recycle();
originalBitmap = scaledBitmap;
} else {
originalBitmap = originalBitmap2;
}
FileOutputStream stream = new FileOutputStream(thumbFile);
originalBitmap.compress(Bitmap.CompressFormat.JPEG, this.info.big ? 83 : 60, stream);
try {
stream.close();
} catch (Exception e) {
FileLog.e(e);
}
final BitmapDrawable bitmapDrawable = new BitmapDrawable(originalBitmap);
final ArrayList<ImageReceiver> finalImageReceiverArray = new ArrayList<>(this.info.imageReceiverArray);
final ArrayList<Integer> finalImageReceiverGuidsArray = new ArrayList<>(this.info.imageReceiverGuidsArray);
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
ImageLoader.ThumbGenerateTask.this.lambda$run$1$ImageLoader$ThumbGenerateTask(key, finalImageReceiverArray, bitmapDrawable, finalImageReceiverGuidsArray);
}
});
return;
}
removeTask();
return;
}
removeTask();
} catch (Throwable e2) {
FileLog.e(e2);
removeTask();
}
}
public void lambda$run$1$ImageLoader$ThumbGenerateTask(String key, ArrayList finalImageReceiverArray, BitmapDrawable bitmapDrawable, ArrayList finalImageReceiverGuidsArray) {
removeTask();
String kf = key;
if (this.info.filter != null) {
kf = kf + "@" + this.info.filter;
}
for (int a = 0; a < finalImageReceiverArray.size(); a++) {
ImageReceiver imgView = (ImageReceiver) finalImageReceiverArray.get(a);
imgView.setImageBitmapByKey(bitmapDrawable, kf, 0, false, ((Integer) finalImageReceiverGuidsArray.get(a)).intValue());
}
ImageLoader.this.memCache.put(kf, bitmapDrawable);
}
}
class CacheOutTask implements Runnable {
private CacheImage cacheImage;
private boolean isCancelled;
private Thread runningThread;
private final Object sync = new Object();
public CacheOutTask(CacheImage image) {
this.cacheImage = image;
}
@Override
public void run() {
throw new UnsupportedOperationException("Method not decompiled: im.pggrnmxjgs.messenger.ImageLoader.CacheOutTask.run():void");
}
private void onPostExecute(final Drawable drawable) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
ImageLoader.CacheOutTask.this.lambda$onPostExecute$1$ImageLoader$CacheOutTask(drawable);
}
});
}
public void lambda$onPostExecute$1$ImageLoader$CacheOutTask(Drawable drawable) {
Drawable toSet = null;
String decrementKey = null;
if (drawable instanceof RLottieDrawable) {
Drawable drawable2 = (RLottieDrawable) drawable;
toSet = (Drawable) ImageLoader.this.lottieMemCache.get(this.cacheImage.key);
if (toSet == null) {
ImageLoader.this.lottieMemCache.put(this.cacheImage.key, drawable2);
toSet = drawable2;
} else {
drawable2.recycle();
}
if (toSet != null) {
ImageLoader.this.incrementUseCount(this.cacheImage.key);
decrementKey = this.cacheImage.key;
}
} else if (drawable instanceof AnimatedFileDrawable) {
toSet = drawable;
} else if (drawable instanceof BitmapDrawable) {
BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
toSet = (Drawable) ImageLoader.this.memCache.get(this.cacheImage.key);
if (toSet == null) {
ImageLoader.this.memCache.put(this.cacheImage.key, bitmapDrawable);
toSet = bitmapDrawable;
} else {
Bitmap image = bitmapDrawable.getBitmap();
image.recycle();
}
if (toSet != null) {
ImageLoader.this.incrementUseCount(this.cacheImage.key);
decrementKey = this.cacheImage.key;
}
}
final Drawable toSetFinal = toSet;
final String decrementKetFinal = decrementKey;
ImageLoader.this.imageLoadQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ImageLoader.CacheOutTask.this.lambda$null$0$ImageLoader$CacheOutTask(toSetFinal, decrementKetFinal);
}
});
}
public void lambda$null$0$ImageLoader$CacheOutTask(Drawable toSetFinal, String decrementKetFinal) {
this.cacheImage.setImageAndClear(toSetFinal, decrementKetFinal);
}
public void cancel() {
synchronized (this.sync) {
try {
this.isCancelled = true;
if (this.runningThread != null) {
this.runningThread.interrupt();
}
} catch (Exception e) {
}
}
}
}
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 key, String filter, int type, int guid) {
int index = this.imageReceiverArray.indexOf(imageReceiver);
if (index >= 0) {
this.imageReceiverGuidsArray.set(index, Integer.valueOf(guid));
return;
}
this.imageReceiverArray.add(imageReceiver);
this.imageReceiverGuidsArray.add(Integer.valueOf(guid));
this.keys.add(key);
this.filters.add(filter);
this.imageTypes.add(Integer.valueOf(type));
ImageLoader.this.imageLoadingByTag.put(imageReceiver.getTag(type), this);
}
public void replaceImageReceiver(ImageReceiver imageReceiver, String key, String filter, int type, int guid) {
int index = this.imageReceiverArray.indexOf(imageReceiver);
if (index == -1) {
return;
}
if (this.imageTypes.get(index).intValue() != type) {
ArrayList<ImageReceiver> arrayList = this.imageReceiverArray;
index = arrayList.subList(index + 1, arrayList.size()).indexOf(imageReceiver);
if (index == -1) {
return;
}
}
this.imageReceiverGuidsArray.set(index, Integer.valueOf(guid));
this.keys.set(index, key);
this.filters.set(index, filter);
}
public void removeImageReceiver(ImageReceiver imageReceiver) {
int currentImageType = this.imageType;
int a = 0;
while (a < this.imageReceiverArray.size()) {
ImageReceiver obj = this.imageReceiverArray.get(a);
if (obj == null || obj == imageReceiver) {
this.imageReceiverArray.remove(a);
this.imageReceiverGuidsArray.remove(a);
this.keys.remove(a);
this.filters.remove(a);
currentImageType = this.imageTypes.remove(a).intValue();
if (obj != null) {
ImageLoader.this.imageLoadingByTag.remove(obj.getTag(currentImageType));
}
a--;
}
a++;
}
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 (currentImageType == 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(final Drawable image, final String decrementKey) {
if (image != null) {
final ArrayList<ImageReceiver> finalImageReceiverArray = new ArrayList<>(this.imageReceiverArray);
final ArrayList<Integer> finalImageReceiverGuidsArray = new ArrayList<>(this.imageReceiverGuidsArray);
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
ImageLoader.CacheImage.this.lambda$setImageAndClear$0$ImageLoader$CacheImage(image, finalImageReceiverArray, finalImageReceiverGuidsArray, decrementKey);
}
});
}
for (int a = 0; a < this.imageReceiverArray.size(); a++) {
ImageReceiver imageReceiver = this.imageReceiverArray.get(a);
ImageLoader.this.imageLoadingByTag.remove(imageReceiver.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 void lambda$setImageAndClear$0$ImageLoader$CacheImage(Drawable image, ArrayList finalImageReceiverArray, ArrayList finalImageReceiverGuidsArray, String decrementKey) {
if (image instanceof AnimatedFileDrawable) {
boolean imageSet = false;
AnimatedFileDrawable fileDrawable = (AnimatedFileDrawable) image;
int a = 0;
while (a < finalImageReceiverArray.size()) {
ImageReceiver imgView = (ImageReceiver) finalImageReceiverArray.get(a);
AnimatedFileDrawable toSet = a == 0 ? fileDrawable : fileDrawable.makeCopy();
if (imgView.setImageBitmapByKey(toSet, this.key, this.imageType, false, ((Integer) finalImageReceiverGuidsArray.get(a)).intValue())) {
if (toSet == fileDrawable) {
imageSet = true;
}
} else if (toSet != fileDrawable) {
toSet.recycle();
}
a++;
}
if (!imageSet) {
fileDrawable.recycle();
}
} else {
for (int a2 = 0; a2 < finalImageReceiverArray.size(); a2++) {
ImageReceiver imgView2 = (ImageReceiver) finalImageReceiverArray.get(a2);
imgView2.setImageBitmapByKey(image, this.key, this.imageTypes.get(a2).intValue(), false, ((Integer) finalImageReceiverGuidsArray.get(a2)).intValue());
}
}
if (decrementKey != null) {
ImageLoader.this.decrementUseCount(decrementKey);
}
}
}
public static ImageLoader getInstance() {
ImageLoader localInstance = Instance;
if (localInstance == null) {
synchronized (ImageLoader.class) {
localInstance = Instance;
if (localInstance == null) {
ImageLoader imageLoader = new ImageLoader();
localInstance = imageLoader;
Instance = imageLoader;
}
}
}
return localInstance;
}
public ImageLoader() {
int maxSize;
this.thumbGeneratingQueue.setPriority(1);
int memoryClass = ((ActivityManager) ApplicationLoader.applicationContext.getSystemService("activity")).getMemoryClass();
boolean z = memoryClass >= 192;
this.canForce8888 = z;
if (z) {
maxSize = 30;
} else {
maxSize = 15;
}
int cacheSize = Math.min(maxSize, memoryClass / 7) * 1024 * 1024;
this.memCache = new LruCache<BitmapDrawable>(cacheSize) {
@Override
public int sizeOf(String key, BitmapDrawable value) {
return value.getBitmap().getByteCount();
}
@Override
public void entryRemoved(boolean evicted, String key, BitmapDrawable oldValue, BitmapDrawable newValue) {
if (ImageLoader.this.ignoreRemoval == null || !ImageLoader.this.ignoreRemoval.equals(key)) {
Integer count = (Integer) ImageLoader.this.bitmapUseCounts.get(key);
if (count == null || count.intValue() == 0) {
Bitmap b = oldValue.getBitmap();
if (!b.isRecycled()) {
b.recycle();
}
}
}
}
};
this.lottieMemCache = new LruCache<RLottieDrawable>(10485760) {
@Override
public int sizeOf(String key, RLottieDrawable value) {
return value.getIntrinsicWidth() * value.getIntrinsicHeight() * 4 * 2;
}
@Override
public void entryRemoved(boolean evicted, String key, RLottieDrawable oldValue, RLottieDrawable newValue) {
Integer count = (Integer) ImageLoader.this.bitmapUseCounts.get(key);
if (count == null || count.intValue() == 0) {
oldValue.recycle();
}
}
};
SparseArray<File> mediaDirs = new SparseArray<>();
File cachePath = AndroidUtilities.getCacheDir();
if (!cachePath.isDirectory()) {
try {
cachePath.mkdirs();
} catch (Exception e) {
FileLog.e(e);
}
}
try {
new File(cachePath, ".nomedia").createNewFile();
} catch (Exception e2) {
FileLog.e(e2);
}
mediaDirs.put(4, cachePath);
for (int a = 0; a < 3; a++) {
int currentAccount = a;
FileLoader.getInstance(a).setDelegate(new AnonymousClass3(currentAccount));
}
FileLoader.setMediaDirs(mediaDirs);
BroadcastReceiver receiver = new AnonymousClass4();
IntentFilter filter = new IntentFilter();
filter.addAction("android.intent.action.MEDIA_BAD_REMOVAL");
filter.addAction("android.intent.action.MEDIA_CHECKING");
filter.addAction("android.intent.action.MEDIA_EJECT");
filter.addAction("android.intent.action.MEDIA_MOUNTED");
filter.addAction("android.intent.action.MEDIA_NOFS");
filter.addAction("android.intent.action.MEDIA_REMOVED");
filter.addAction("android.intent.action.MEDIA_SHARED");
filter.addAction("android.intent.action.MEDIA_UNMOUNTABLE");
filter.addAction("android.intent.action.MEDIA_UNMOUNTED");
filter.addDataScheme("file");
try {
ApplicationLoader.applicationContext.registerReceiver(receiver, filter);
} catch (Throwable th) {
}
checkMediaPaths();
}
class AnonymousClass3 implements FileLoader.FileLoaderDelegate {
final int val$currentAccount;
AnonymousClass3(int i) {
this.val$currentAccount = i;
}
@Override
public void fileUploadProgressChanged(final String location, final float progress, final boolean isEncrypted) {
ImageLoader.this.fileProgresses.put(location, Float.valueOf(progress));
long currentTime = System.currentTimeMillis();
if (ImageLoader.this.lastProgressUpdateTime == 0 || ImageLoader.this.lastProgressUpdateTime < currentTime - 500) {
ImageLoader.this.lastProgressUpdateTime = currentTime;
final int i = this.val$currentAccount;
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
NotificationCenter.getInstance(i).postNotificationName(NotificationCenter.FileUploadProgressChanged, location, Float.valueOf(progress), Boolean.valueOf(isEncrypted));
}
});
}
}
@Override
public void fileDidUploaded(final String location, final TLRPC.InputFile inputFile, final TLRPC.InputEncryptedFile inputEncryptedFile, final byte[] key, final byte[] iv, final long totalFileSize, final boolean apply) {
DispatchQueue dispatchQueue = Utilities.stageQueue;
final int i = this.val$currentAccount;
dispatchQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ImageLoader.AnonymousClass3.this.lambda$fileDidUploaded$2$ImageLoader$3(i, location, inputFile, inputEncryptedFile, key, iv, totalFileSize, apply);
}
});
}
public void lambda$fileDidUploaded$2$ImageLoader$3(final int currentAccount, final String location, final TLRPC.InputFile inputFile, final TLRPC.InputEncryptedFile inputEncryptedFile, final byte[] key, final byte[] iv, final long totalFileSize, final boolean apply) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.FileDidUpload, location, inputFile, inputEncryptedFile, key, iv, Long.valueOf(totalFileSize), Boolean.valueOf(apply));
}
});
ImageLoader.this.fileProgresses.remove(location);
}
@Override
public void fileDidFailedUpload(final String location, final boolean isEncrypted) {
DispatchQueue dispatchQueue = Utilities.stageQueue;
final int i = this.val$currentAccount;
dispatchQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ImageLoader.AnonymousClass3.this.lambda$fileDidFailedUpload$4$ImageLoader$3(i, location, isEncrypted);
}
});
}
public void lambda$fileDidFailedUpload$4$ImageLoader$3(final int currentAccount, final String location, final boolean isEncrypted) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.FileDidFailUpload, location, Boolean.valueOf(isEncrypted));
}
});
ImageLoader.this.fileProgresses.remove(location);
}
@Override
public void fileDidLoaded(final String location, final File finalFile, final int type) {
ImageLoader.this.fileProgresses.remove(location);
final int i = this.val$currentAccount;
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
ImageLoader.AnonymousClass3.this.lambda$fileDidLoaded$5$ImageLoader$3(finalFile, location, i, type);
}
});
}
public void lambda$fileDidLoaded$5$ImageLoader$3(File finalFile, String location, int currentAccount, int type) {
if (SharedConfig.saveToGallery && ImageLoader.this.appPath != null && finalFile != null && ((location.endsWith(".mp4") || location.endsWith(".jpg")) && finalFile.toString().startsWith(ImageLoader.this.appPath.toString()))) {
AndroidUtilities.addMediaToGallery(finalFile.toString());
}
NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.fileDidLoad, location, finalFile);
ImageLoader.this.fileDidLoaded(location, finalFile, type);
}
@Override
public void fileDidFailedLoad(final String location, final int canceled) {
ImageLoader.this.fileProgresses.remove(location);
final int i = this.val$currentAccount;
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
ImageLoader.AnonymousClass3.this.lambda$fileDidFailedLoad$6$ImageLoader$3(location, canceled, i);
}
});
}
public void lambda$fileDidFailedLoad$6$ImageLoader$3(String location, int canceled, int currentAccount) {
ImageLoader.this.fileDidFailedLoad(location, canceled);
NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.fileDidFailToLoad, location, Integer.valueOf(canceled));
}
@Override
public void fileLoadProgressChanged(final String location, final float progress) {
ImageLoader.this.fileProgresses.put(location, Float.valueOf(progress));
long currentTime = System.currentTimeMillis();
if (ImageLoader.this.lastProgressUpdateTime == 0 || ImageLoader.this.lastProgressUpdateTime < currentTime - 500) {
ImageLoader.this.lastProgressUpdateTime = currentTime;
final int i = this.val$currentAccount;
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
NotificationCenter.getInstance(i).postNotificationName(NotificationCenter.FileLoadProgressChanged, location, Float.valueOf(progress));
}
});
}
}
}
class AnonymousClass4 extends BroadcastReceiver {
AnonymousClass4() {
}
@Override
public void onReceive(Context arg0, Intent intent) {
if (BuildVars.LOGS_ENABLED) {
FileLog.d("file system changed");
}
Runnable r = new Runnable() {
@Override
public final void run() {
ImageLoader.AnonymousClass4.this.lambda$onReceive$0$ImageLoader$4();
}
};
if ("android.intent.action.MEDIA_UNMOUNTED".equals(intent.getAction())) {
AndroidUtilities.runOnUIThread(r, 1000L);
} else {
r.run();
}
}
public void lambda$onReceive$0$ImageLoader$4() {
ImageLoader.this.checkMediaPaths();
}
}
public void checkMediaPaths() {
this.cacheOutQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ImageLoader.this.lambda$checkMediaPaths$1$ImageLoader();
}
});
}
public void lambda$checkMediaPaths$1$ImageLoader() {
final SparseArray<File> paths = createMediaPaths();
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
FileLoader.setMediaDirs(paths);
}
});
}
public void addTestWebFile(String url, WebFile webFile) {
if (url == null || webFile == null) {
return;
}
this.testWebFile.put(url, webFile);
}
public void removeTestWebFile(String url) {
if (url == null) {
return;
}
this.testWebFile.remove(url);
}
public SparseArray<File> createMediaPaths() {
SparseArray<File> mediaDirs = new SparseArray<>();
File cachePath = AndroidUtilities.getCacheDir();
if (!cachePath.isDirectory()) {
try {
cachePath.mkdirs();
} catch (Exception e) {
FileLog.e(e);
}
}
try {
new File(cachePath, ".nomedia").createNewFile();
} catch (Exception e2) {
FileLog.e(e2);
}
mediaDirs.put(4, cachePath);
if (BuildVars.LOGS_ENABLED) {
FileLog.d("cache path = " + cachePath);
}
try {
if ("mounted".equals(Environment.getExternalStorageState())) {
File file = new File(Environment.getExternalStorageDirectory(), "Tsss");
this.appPath = file;
file.mkdirs();
if (this.appPath.isDirectory()) {
try {
File imagePath = new File(this.appPath, "Tsss Images");
imagePath.mkdir();
if (imagePath.isDirectory() && canMoveFiles(cachePath, imagePath, 0)) {
mediaDirs.put(0, imagePath);
if (BuildVars.LOGS_ENABLED) {
FileLog.d("image path = " + imagePath);
}
}
} catch (Exception e3) {
FileLog.e(e3);
}
try {
File videoPath = new File(this.appPath, "Tsss Video");
videoPath.mkdir();
if (videoPath.isDirectory() && canMoveFiles(cachePath, videoPath, 2)) {
mediaDirs.put(2, videoPath);
if (BuildVars.LOGS_ENABLED) {
FileLog.d("video path = " + videoPath);
}
}
} catch (Exception e4) {
FileLog.e(e4);
}
try {
File audioPath = new File(this.appPath, "Tsss Audio");
audioPath.mkdir();
if (audioPath.isDirectory() && canMoveFiles(cachePath, audioPath, 1)) {
new File(audioPath, ".nomedia").createNewFile();
mediaDirs.put(1, audioPath);
if (BuildVars.LOGS_ENABLED) {
FileLog.d("audio path = " + audioPath);
}
}
} catch (Exception e5) {
FileLog.e(e5);
}
try {
File documentPath = new File(this.appPath, "Tsss Documents");
documentPath.mkdir();
if (documentPath.isDirectory() && canMoveFiles(cachePath, documentPath, 3)) {
new File(documentPath, ".nomedia").createNewFile();
mediaDirs.put(3, documentPath);
if (BuildVars.LOGS_ENABLED) {
FileLog.d("documents path = " + documentPath);
}
}
} 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 mediaDirs;
}
private boolean canMoveFiles(File from, File to, int type) {
RandomAccessFile file = null;
File srcFile = null;
File dstFile = null;
try {
try {
try {
if (type == 0) {
srcFile = new File(from, "000000000_999999_temp.jpg");
dstFile = new File(to, "000000000_999999.jpg");
} else if (type == 3) {
srcFile = new File(from, "000000000_999999_temp.doc");
dstFile = new File(to, "000000000_999999.doc");
} else if (type == 1) {
srcFile = new File(from, "000000000_999999_temp.ogg");
dstFile = new File(to, "000000000_999999.ogg");
} else if (type == 2) {
srcFile = new File(from, "000000000_999999_temp.mp4");
dstFile = new File(to, "000000000_999999.mp4");
}
byte[] buffer = new byte[1024];
srcFile.createNewFile();
RandomAccessFile file2 = new RandomAccessFile(srcFile, "rws");
file2.write(buffer);
file2.close();
file = null;
boolean canRename = srcFile.renameTo(dstFile);
srcFile.delete();
dstFile.delete();
if (!canRename) {
if (0 == 0) {
return false;
}
file.close();
return false;
}
if (0 != 0) {
try {
file.close();
} catch (Exception e) {
FileLog.e(e);
}
}
return true;
} catch (Exception e2) {
FileLog.e(e2);
if (file == null) {
return false;
}
file.close();
return false;
}
} catch (Exception e3) {
FileLog.e(e3);
return false;
}
} catch (Throwable th) {
if (file != null) {
try {
file.close();
} catch (Exception e4) {
FileLog.e(e4);
}
}
throw th;
}
}
public Float getFileProgress(String location) {
if (location == null) {
return null;
}
return this.fileProgresses.get(location);
}
public String getReplacedKey(String oldKey) {
if (oldKey == null) {
return null;
}
return this.replacedBitmaps.get(oldKey);
}
private void performReplace(String oldKey, String newKey) {
BitmapDrawable b = this.memCache.get(oldKey);
this.replacedBitmaps.put(oldKey, newKey);
if (b != null) {
BitmapDrawable oldBitmap = this.memCache.get(newKey);
boolean dontChange = false;
if (oldBitmap != null && oldBitmap.getBitmap() != null && b.getBitmap() != null) {
Bitmap oldBitmapObject = oldBitmap.getBitmap();
Bitmap newBitmapObject = b.getBitmap();
if (oldBitmapObject.getWidth() > newBitmapObject.getWidth() || oldBitmapObject.getHeight() > newBitmapObject.getHeight()) {
dontChange = true;
}
}
if (!dontChange) {
this.ignoreRemoval = oldKey;
this.memCache.remove(oldKey);
this.memCache.put(newKey, b);
this.ignoreRemoval = null;
} else {
this.memCache.remove(oldKey);
}
}
Integer val = this.bitmapUseCounts.get(oldKey);
if (val != null) {
this.bitmapUseCounts.put(newKey, val);
this.bitmapUseCounts.remove(oldKey);
}
}
public void incrementUseCount(String key) {
Integer count = this.bitmapUseCounts.get(key);
if (count == null) {
this.bitmapUseCounts.put(key, 1);
} else {
this.bitmapUseCounts.put(key, Integer.valueOf(count.intValue() + 1));
}
}
public boolean decrementUseCount(String key) {
Integer count = this.bitmapUseCounts.get(key);
if (count == null) {
return true;
}
if (count.intValue() != 1) {
this.bitmapUseCounts.put(key, Integer.valueOf(count.intValue() - 1));
return false;
}
this.bitmapUseCounts.remove(key);
return true;
}
public void removeImage(String key) {
this.bitmapUseCounts.remove(key);
this.memCache.remove(key);
}
public boolean isInMemCache(String key, boolean animated) {
return animated ? this.lottieMemCache.get(key) != null : this.memCache.get(key) != null;
}
public void clearMemory() {
this.memCache.evictAll();
this.lottieMemCache.evictAll();
}
private void removeFromWaitingForThumb(int TAG, ImageReceiver imageReceiver) {
String location = this.waitingForQualityThumbByTag.get(TAG);
if (location != null) {
ThumbGenerateInfo info = this.waitingForQualityThumb.get(location);
if (info != null) {
int index = info.imageReceiverArray.indexOf(imageReceiver);
if (index >= 0) {
info.imageReceiverArray.remove(index);
info.imageReceiverGuidsArray.remove(index);
}
if (info.imageReceiverArray.isEmpty()) {
this.waitingForQualityThumb.remove(location);
}
}
this.waitingForQualityThumbByTag.remove(TAG);
}
}
public void cancelLoadingForImageReceiver(final ImageReceiver imageReceiver, final boolean cancelAll) {
if (imageReceiver == null) {
return;
}
this.imageLoadQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ImageLoader.this.lambda$cancelLoadingForImageReceiver$2$ImageLoader(cancelAll, imageReceiver);
}
});
}
public void lambda$cancelLoadingForImageReceiver$2$ImageLoader(boolean cancelAll, ImageReceiver imageReceiver) {
int imageType;
for (int a = 0; a < 3; a++) {
if (a > 0 && !cancelAll) {
return;
}
if (a == 0) {
imageType = 1;
} else if (a == 1) {
imageType = 0;
} else {
imageType = 3;
}
int TAG = imageReceiver.getTag(imageType);
if (TAG != 0) {
if (a == 0) {
removeFromWaitingForThumb(TAG, imageReceiver);
}
CacheImage ei = this.imageLoadingByTag.get(TAG);
if (ei != null) {
ei.removeImageReceiver(imageReceiver);
}
}
}
}
public BitmapDrawable getAnyImageFromMemory(String key) {
ArrayList<String> filters;
BitmapDrawable drawable = this.memCache.get(key);
if (drawable == null && (filters = this.memCache.getFilterKeys(key)) != null && !filters.isEmpty()) {
return this.memCache.get(key + "@" + filters.get(0));
}
return drawable;
}
public BitmapDrawable getImageFromMemory(TLObject fileLocation, String httpUrl, String filter) {
if (fileLocation == null && httpUrl == null) {
return null;
}
String key = null;
if (httpUrl != null) {
key = Utilities.MD5(httpUrl);
} else if (fileLocation instanceof TLRPC.FileLocation) {
TLRPC.FileLocation location = (TLRPC.FileLocation) fileLocation;
key = location.volume_id + "_" + location.local_id;
} else if (fileLocation instanceof TLRPC.Document) {
TLRPC.Document location2 = (TLRPC.Document) fileLocation;
key = location2.dc_id + "_" + location2.id;
} else if (fileLocation instanceof SecureDocument) {
SecureDocument location3 = (SecureDocument) fileLocation;
key = location3.secureFile.dc_id + "_" + location3.secureFile.id;
} else if (fileLocation instanceof WebFile) {
key = Utilities.MD5(((WebFile) fileLocation).url);
}
if (filter != null) {
key = key + "@" + filter;
}
return this.memCache.get(key);
}
public void lambda$replaceImageInCache$3$ImageLoader(String oldKey, String newKey, ImageLocation newLocation) {
ArrayList<String> arr = this.memCache.getFilterKeys(oldKey);
if (arr != null) {
for (int a = 0; a < arr.size(); a++) {
String filter = arr.get(a);
String oldK = oldKey + "@" + filter;
String newK = newKey + "@" + filter;
performReplace(oldK, newK);
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.didReplacedPhotoInMemCache, oldK, newK, newLocation);
}
return;
}
performReplace(oldKey, newKey);
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.didReplacedPhotoInMemCache, oldKey, newKey, newLocation);
}
public void replaceImageInCache(final String oldKey, final String newKey, final ImageLocation newLocation, boolean post) {
if (post) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
ImageLoader.this.lambda$replaceImageInCache$3$ImageLoader(oldKey, newKey, newLocation);
}
});
} else {
lambda$replaceImageInCache$3$ImageLoader(oldKey, newKey, newLocation);
}
}
public void putImageToCache(BitmapDrawable bitmap, String key) {
this.memCache.put(key, bitmap);
}
private void generateThumb(int mediaType, File originalPath, ThumbGenerateInfo info) {
if ((mediaType == 0 || mediaType == 2 || mediaType == 3) && originalPath != null && info != null) {
String name = FileLoader.getAttachFileName(info.parentDocument);
ThumbGenerateTask task = this.thumbGenerateTasks.get(name);
if (task == null) {
ThumbGenerateTask task2 = new ThumbGenerateTask(mediaType, originalPath, info);
this.thumbGeneratingQueue.postRunnable(task2);
}
}
}
public void cancelForceLoadingForImageReceiver(ImageReceiver imageReceiver) {
final String key;
if (imageReceiver == null || (key = imageReceiver.getImageKey()) == null) {
return;
}
this.imageLoadQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ImageLoader.this.lambda$cancelForceLoadingForImageReceiver$4$ImageLoader(key);
}
});
}
public void lambda$cancelForceLoadingForImageReceiver$4$ImageLoader(String key) {
this.forceLoadingImages.remove(key);
}
private void createLoadOperationForImageReceiver(final ImageReceiver imageReceiver, final String key, final String url, final String ext, final ImageLocation imageLocation, final String filter, final int size, final int cacheType, final int imageType, final int thumb, final int guid) {
int TAG;
if (imageReceiver == null || url == null || key == null || imageLocation == null) {
return;
}
int TAG2 = imageReceiver.getTag(imageType);
if (TAG2 != 0) {
TAG = TAG2;
} else {
int TAG3 = this.lastImageNum;
imageReceiver.setTag(TAG3, imageType);
int i = this.lastImageNum + 1;
this.lastImageNum = i;
if (i == Integer.MAX_VALUE) {
this.lastImageNum = 0;
}
TAG = TAG3;
}
final int finalTag = TAG;
final boolean finalIsNeedsQualityThumb = imageReceiver.isNeedsQualityThumb();
final Object parentObject = imageReceiver.getParentObject();
final TLRPC.Document qualityDocument = imageReceiver.getQulityThumbDocument();
final boolean shouldGenerateQualityThumb = imageReceiver.isShouldGenerateQualityThumb();
final int currentAccount = imageReceiver.getCurrentAccount();
final boolean currentKeyQuality = imageType == 0 && imageReceiver.isCurrentKeyQuality();
this.imageLoadQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ImageLoader.this.lambda$createLoadOperationForImageReceiver$5$ImageLoader(thumb, url, key, finalTag, imageReceiver, filter, imageType, guid, imageLocation, currentKeyQuality, parentObject, qualityDocument, finalIsNeedsQualityThumb, shouldGenerateQualityThumb, cacheType, size, ext, currentAccount);
}
});
}
public void lambda$createLoadOperationForImageReceiver$5$ImageLoader(int r30, java.lang.String r31, java.lang.String r32, int r33, im.pggrnmxjgs.messenger.ImageReceiver r34, java.lang.String r35, int r36, int r37, im.pggrnmxjgs.messenger.ImageLocation r38, boolean r39, java.lang.Object r40, im.pggrnmxjgs.tgnet.TLRPC.Document r41, boolean r42, boolean r43, int r44, int r45, java.lang.String r46, int r47) {
throw new UnsupportedOperationException("Method not decompiled: im.pggrnmxjgs.messenger.ImageLoader.lambda$createLoadOperationForImageReceiver$5$ImageLoader(int, java.lang.String, java.lang.String, int, im.pggrnmxjgs.messenger.ImageReceiver, java.lang.String, int, int, im.pggrnmxjgs.messenger.ImageLocation, boolean, java.lang.Object, im.pggrnmxjgs.tgnet.TLRPC$Document, boolean, boolean, int, int, java.lang.String, int):void");
}
public void loadImageForImageReceiver(im.pggrnmxjgs.messenger.ImageReceiver r44) {
throw new UnsupportedOperationException("Method not decompiled: im.pggrnmxjgs.messenger.ImageLoader.loadImageForImageReceiver(im.pggrnmxjgs.messenger.ImageReceiver):void");
}
public void httpFileLoadError(final String location) {
this.imageLoadQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ImageLoader.this.lambda$httpFileLoadError$6$ImageLoader(location);
}
});
}
public void lambda$httpFileLoadError$6$ImageLoader(String location) {
CacheImage img = this.imageLoadingByUrl.get(location);
if (img == null) {
return;
}
HttpImageTask oldTask = img.httpTask;
img.httpTask = new HttpImageTask(oldTask.cacheImage, oldTask.imageSize);
this.httpTasks.add(img.httpTask);
runHttpTasks(false);
}
public void artworkLoadError(final String location) {
this.imageLoadQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ImageLoader.this.lambda$artworkLoadError$7$ImageLoader(location);
}
});
}
public void lambda$artworkLoadError$7$ImageLoader(String location) {
CacheImage img = this.imageLoadingByUrl.get(location);
if (img == null) {
return;
}
ArtworkLoadTask oldTask = img.artworkTask;
img.artworkTask = new ArtworkLoadTask(oldTask.cacheImage);
this.artworkTasks.add(img.artworkTask);
runArtworkTasks(false);
}
public void fileDidLoaded(final String location, final File finalFile, final int type) {
this.imageLoadQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ImageLoader.this.lambda$fileDidLoaded$8$ImageLoader(location, type, finalFile);
}
});
}
public void lambda$fileDidLoaded$8$ImageLoader(String location, int type, File finalFile) {
ThumbGenerateInfo info = this.waitingForQualityThumb.get(location);
if (info != null && info.parentDocument != null) {
generateThumb(type, finalFile, info);
this.waitingForQualityThumb.remove(location);
}
CacheImage img = this.imageLoadingByUrl.get(location);
if (img == null) {
return;
}
this.imageLoadingByUrl.remove(location);
ArrayList<CacheOutTask> tasks = new ArrayList<>();
for (int a = 0; a < img.imageReceiverArray.size(); a++) {
String key = img.keys.get(a);
String filter = img.filters.get(a);
int imageType = img.imageTypes.get(a).intValue();
ImageReceiver imageReceiver = img.imageReceiverArray.get(a);
int guid = img.imageReceiverGuidsArray.get(a).intValue();
CacheImage cacheImage = this.imageLoadingByKeys.get(key);
if (cacheImage == null) {
cacheImage = new CacheImage();
cacheImage.secureDocument = img.secureDocument;
cacheImage.currentAccount = img.currentAccount;
cacheImage.finalFilePath = finalFile;
cacheImage.key = key;
cacheImage.imageLocation = img.imageLocation;
cacheImage.imageType = imageType;
cacheImage.ext = img.ext;
cacheImage.encryptionKeyPath = img.encryptionKeyPath;
cacheImage.cacheTask = new CacheOutTask(cacheImage);
cacheImage.filter = filter;
cacheImage.animatedFile = img.animatedFile;
cacheImage.lottieFile = img.lottieFile;
this.imageLoadingByKeys.put(key, cacheImage);
tasks.add(cacheImage.cacheTask);
}
cacheImage.addImageReceiver(imageReceiver, key, filter, imageType, guid);
}
for (int a2 = 0; a2 < tasks.size(); a2++) {
CacheOutTask task = tasks.get(a2);
if (task.cacheImage.imageType == 1) {
this.cacheThumbOutQueue.postRunnable(task);
} else {
this.cacheOutQueue.postRunnable(task);
}
}
}
public void fileDidFailedLoad(final String location, int canceled) {
if (canceled == 1) {
return;
}
this.imageLoadQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ImageLoader.this.lambda$fileDidFailedLoad$9$ImageLoader(location);
}
});
}
public void lambda$fileDidFailedLoad$9$ImageLoader(String location) {
CacheImage img = this.imageLoadingByUrl.get(location);
if (img != null) {
img.setImageAndClear(null, null);
}
}
public void runHttpTasks(boolean complete) {
if (complete) {
this.currentHttpTasksCount--;
}
while (this.currentHttpTasksCount < 4 && !this.httpTasks.isEmpty()) {
HttpImageTask task = this.httpTasks.poll();
if (task != null) {
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, null, null, null);
this.currentHttpTasksCount++;
}
}
}
public void runArtworkTasks(boolean complete) {
if (complete) {
this.currentArtworkTasksCount--;
}
while (this.currentArtworkTasksCount < 4 && !this.artworkTasks.isEmpty()) {
try {
ArtworkLoadTask task = this.artworkTasks.poll();
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, null, null, null);
this.currentArtworkTasksCount++;
} catch (Throwable th) {
runArtworkTasks(false);
}
}
}
public boolean isLoadingHttpFile(String url) {
return this.httpFileLoadTasksByKeys.containsKey(url);
}
public static String getHttpFileName(String url) {
return Utilities.MD5(url);
}
public static File getHttpFilePath(String url, String defaultExt) {
String ext = getHttpUrlExtension(url, defaultExt);
return new File(FileLoader.getDirectory(4), Utilities.MD5(url) + "." + ext);
}
public void loadHttpFile(String url, String defaultExt, int currentAccount) {
if (url == null || url.length() == 0 || this.httpFileLoadTasksByKeys.containsKey(url)) {
return;
}
String ext = getHttpUrlExtension(url, defaultExt);
File file = new File(FileLoader.getDirectory(4), Utilities.MD5(url) + "_temp." + ext);
file.delete();
HttpFileTask task = new HttpFileTask(url, file, ext, currentAccount);
this.httpFileLoadTasks.add(task);
this.httpFileLoadTasksByKeys.put(url, task);
runHttpFileLoadTasks(null, 0);
}
public void cancelLoadHttpFile(String url) {
HttpFileTask task = this.httpFileLoadTasksByKeys.get(url);
if (task != null) {
task.cancel(true);
this.httpFileLoadTasksByKeys.remove(url);
this.httpFileLoadTasks.remove(task);
}
Runnable runnable = this.retryHttpsTasks.get(url);
if (runnable != null) {
AndroidUtilities.cancelRunOnUIThread(runnable);
}
runHttpFileLoadTasks(null, 0);
}
public void runHttpFileLoadTasks(final HttpFileTask oldTask, final int reason) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
ImageLoader.this.lambda$runHttpFileLoadTasks$11$ImageLoader(oldTask, reason);
}
});
}
public void lambda$runHttpFileLoadTasks$11$ImageLoader(HttpFileTask oldTask, int reason) {
if (oldTask != null) {
this.currentHttpFileLoadTasksCount--;
}
if (oldTask != null) {
if (reason == 1) {
if (!oldTask.canRetry) {
this.httpFileLoadTasksByKeys.remove(oldTask.url);
NotificationCenter.getInstance(oldTask.currentAccount).postNotificationName(NotificationCenter.httpFileDidFailedLoad, oldTask.url, 0);
} else {
final HttpFileTask newTask = new HttpFileTask(oldTask.url, oldTask.tempFile, oldTask.ext, oldTask.currentAccount);
Runnable runnable = new Runnable() {
@Override
public final void run() {
ImageLoader.this.lambda$null$10$ImageLoader(newTask);
}
};
this.retryHttpsTasks.put(oldTask.url, runnable);
AndroidUtilities.runOnUIThread(runnable, 1000L);
}
} else if (reason == 2) {
this.httpFileLoadTasksByKeys.remove(oldTask.url);
File file = new File(FileLoader.getDirectory(4), Utilities.MD5(oldTask.url) + "." + oldTask.ext);
String result = oldTask.tempFile.renameTo(file) ? file.toString() : oldTask.tempFile.toString();
NotificationCenter.getInstance(oldTask.currentAccount).postNotificationName(NotificationCenter.httpFileDidLoad, oldTask.url, result);
}
}
while (this.currentHttpFileLoadTasksCount < 2 && !this.httpFileLoadTasks.isEmpty()) {
HttpFileTask task = this.httpFileLoadTasks.poll();
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, null, null, null);
this.currentHttpFileLoadTasksCount++;
}
}
public void lambda$null$10$ImageLoader(HttpFileTask newTask) {
this.httpFileLoadTasks.add(newTask);
runHttpFileLoadTasks(null, 0);
}
public static boolean shouldSendImageAsDocument(String path, Uri uri) {
BitmapFactory.Options bmOptions = new BitmapFactory.Options();
bmOptions.inJustDecodeBounds = true;
if (path == null && uri != null && uri.getScheme() != null) {
if (uri.getScheme().contains("file")) {
path = uri.getPath();
} else {
try {
path = AndroidUtilities.getPath(uri);
} catch (Throwable e) {
FileLog.e(e);
}
}
}
if (path != null) {
BitmapFactory.decodeFile(path, bmOptions);
} else if (uri != null) {
try {
InputStream inputStream = ApplicationLoader.applicationContext.getContentResolver().openInputStream(uri);
BitmapFactory.decodeStream(inputStream, null, bmOptions);
inputStream.close();
} catch (Throwable e2) {
FileLog.e(e2);
return false;
}
}
float photoW = bmOptions.outWidth;
float photoH = bmOptions.outHeight;
return photoW / photoH > 10.0f || photoH / photoW > 10.0f;
}
public static android.graphics.Bitmap loadBitmap(java.lang.String r19, android.net.Uri r20, float r21, float r22, boolean r23) {
throw new UnsupportedOperationException("Method not decompiled: im.pggrnmxjgs.messenger.ImageLoader.loadBitmap(java.lang.String, android.net.Uri, float, float, boolean):android.graphics.Bitmap");
}
public static void fillPhotoSizeWithBytes(TLRPC.PhotoSize photoSize) {
if (photoSize != null) {
if (photoSize.bytes != null && photoSize.bytes.length != 0) {
return;
}
File file = FileLoader.getPathToAttach(photoSize, true);
try {
RandomAccessFile f = new RandomAccessFile(file, "r");
int len = (int) f.length();
if (len < 20000) {
photoSize.bytes = new byte[(int) f.length()];
f.readFully(photoSize.bytes, 0, photoSize.bytes.length);
}
} catch (Throwable e) {
FileLog.e(e);
}
}
}
private static TLRPC.PhotoSize scaleAndSaveImageInternal(TLRPC.PhotoSize photoSize, Bitmap bitmap, int w, int h, float photoW, float photoH, float scaleFactor, int quality, boolean cache, boolean scaleAnyway, boolean isPng) throws Exception {
Bitmap scaledBitmap;
TLRPC.TL_fileLocationToBeDeprecated location;
TLRPC.PhotoSize photoSize2 = photoSize;
if (scaleFactor > 1.0f || scaleAnyway) {
scaledBitmap = Bitmaps.createScaledBitmap(bitmap, w, h, true);
} else {
scaledBitmap = bitmap;
}
if (photoSize2 == null) {
}
if (photoSize2 == null || !(photoSize2.location instanceof TLRPC.TL_fileLocationToBeDeprecated)) {
location = new TLRPC.TL_fileLocationToBeDeprecated();
location.volume_id = -2147483648L;
location.dc_id = Integer.MIN_VALUE;
location.local_id = SharedConfig.getLastLocalId();
location.file_reference = new byte[0];
photoSize2 = new TLRPC.TL_photoSize();
photoSize2.location = location;
photoSize2.w = scaledBitmap.getWidth();
photoSize2.h = scaledBitmap.getHeight();
if (photoSize2.w <= 100 && photoSize2.h <= 100) {
photoSize2.type = "s";
} else if (photoSize2.w <= 320 && photoSize2.h <= 320) {
photoSize2.type = "m";
} else if (photoSize2.w <= 800 && photoSize2.h <= 800) {
photoSize2.type = "x";
} else if (photoSize2.w <= 1280 && photoSize2.h <= 1280) {
photoSize2.type = "y";
} else {
photoSize2.type = "w";
}
} else {
location = (TLRPC.TL_fileLocationToBeDeprecated) photoSize2.location;
}
String fileName = location.volume_id + "_" + location.local_id + ".jpg";
File cacheFile = new File(FileLoader.getDirectory(location.volume_id == -2147483648L ? 4 : 0), fileName);
FileOutputStream stream = new FileOutputStream(cacheFile);
if (isPng) {
scaledBitmap.compress(Bitmap.CompressFormat.PNG, quality, stream);
} else {
scaledBitmap.compress(Bitmap.CompressFormat.JPEG, quality, stream);
}
if (cache) {
ByteArrayOutputStream stream2 = new ByteArrayOutputStream();
if (isPng) {
scaledBitmap.compress(Bitmap.CompressFormat.PNG, quality, stream2);
} else {
scaledBitmap.compress(Bitmap.CompressFormat.JPEG, quality, stream2);
}
photoSize2.bytes = stream2.toByteArray();
photoSize2.size = photoSize2.bytes.length;
stream2.close();
} else {
photoSize2.size = (int) stream.getChannel().size();
}
stream.close();
if (scaledBitmap != bitmap) {
scaledBitmap.recycle();
}
return photoSize2;
}
public static TLRPC.PhotoSize SaveImageWithOriginalInternal(TLRPC.PhotoSize photoSize, String strPath, boolean cache) throws Exception {
TLRPC.TL_fileLocationToBeDeprecated location;
if (photoSize != null) {
}
if (photoSize == null || !(photoSize.location instanceof TLRPC.TL_fileLocationToBeDeprecated)) {
location = new TLRPC.TL_fileLocationToBeDeprecated();
location.volume_id = -2147483648L;
location.dc_id = Integer.MIN_VALUE;
location.local_id = SharedConfig.getLastLocalId();
location.file_reference = new byte[0];
photoSize = new TLRPC.TL_photoSize();
photoSize.location = location;
BitmapFactory.Options options = new BitmapFactory.Options();
BitmapFactory.decodeFile(strPath, 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 = "y";
} else {
photoSize.type = "w";
}
} else {
location = (TLRPC.TL_fileLocationToBeDeprecated) photoSize.location;
}
String fileName = location.volume_id + "_" + location.local_id + ".jpg";
File cacheFile = new File(FileLoader.getDirectory(location.volume_id == -2147483648L ? 4 : 0), fileName);
FileInputStream fileInputStream = new FileInputStream(strPath);
AndroidUtilities.copyFile(fileInputStream, cacheFile);
if (cache) {
ByteArrayOutputStream stream2 = new ByteArrayOutputStream();
photoSize.bytes = stream2.toByteArray();
photoSize.size = photoSize.bytes.length;
stream2.close();
} else {
photoSize.size = (int) fileInputStream.getChannel().size();
}
fileInputStream.close();
return photoSize;
}
public static TLRPC.PhotoSize scaleAndSaveImage(Bitmap bitmap, float maxWidth, float maxHeight, int quality, boolean cache) {
return scaleAndSaveImage(null, bitmap, maxWidth, maxHeight, quality, cache, 0, 0, false);
}
public static TLRPC.PhotoSize scaleAndSaveImage(TLRPC.PhotoSize photoSize, Bitmap bitmap, float maxWidth, float maxHeight, int quality, boolean cache) {
return scaleAndSaveImage(photoSize, bitmap, maxWidth, maxHeight, quality, cache, 0, 0, false);
}
public static TLRPC.PhotoSize scaleAndSaveImage(Bitmap bitmap, float maxWidth, float maxHeight, int quality, boolean cache, int minWidth, int minHeight) {
return scaleAndSaveImage(null, bitmap, maxWidth, maxHeight, quality, cache, minWidth, minHeight, false);
}
public static TLRPC.PhotoSize scaleAndSaveImage(Bitmap bitmap, float maxWidth, float maxHeight, int quality, boolean cache, boolean isPng) {
return scaleAndSaveImage(null, bitmap, maxWidth, maxHeight, quality, cache, 0, 0, isPng);
}
public static TLRPC.PhotoSize scaleAndSaveImage(Bitmap bitmap, float maxWidth, float maxHeight, int quality, boolean cache, int minWidth, int minHeight, boolean isPng) {
return scaleAndSaveImage(null, bitmap, maxWidth, maxHeight, quality, cache, minWidth, minHeight, isPng);
}
public static TLRPC.PhotoSize scaleAndSaveImage(TLRPC.PhotoSize photoSize, Bitmap bitmap, float maxWidth, float maxHeight, int quality, boolean cache, int minWidth, int minHeight, boolean isPng) {
boolean scaleAnyway;
float scaleFactor;
float scaleFactor2;
if (bitmap == null) {
return null;
}
float photoW = bitmap.getWidth();
float photoH = bitmap.getHeight();
if (photoW != 0.0f && photoH != 0.0f) {
float scaleFactor3 = Math.max(photoW / maxWidth, photoH / maxHeight);
if (minWidth != 0 && minHeight != 0 && (photoW < minWidth || photoH < minHeight)) {
if (photoW < minWidth && photoH > minHeight) {
scaleFactor2 = photoW / minWidth;
} else if (photoW > minWidth && photoH < minHeight) {
scaleFactor2 = photoH / minHeight;
} else {
scaleFactor2 = Math.max(photoW / minWidth, photoH / minHeight);
}
scaleAnyway = true;
scaleFactor = scaleFactor2;
} else {
scaleAnyway = false;
scaleFactor = scaleFactor3;
}
int w = (int) (photoW / scaleFactor);
int h = (int) (photoH / scaleFactor);
if (h != 0 && w != 0) {
try {
return scaleAndSaveImageInternal(photoSize, bitmap, w, h, photoW, photoH, scaleFactor, quality, cache, scaleAnyway, isPng);
} catch (Throwable e) {
FileLog.e(e);
getInstance().clearMemory();
System.gc();
try {
return scaleAndSaveImageInternal(photoSize, bitmap, w, h, photoW, photoH, scaleFactor, quality, cache, scaleAnyway, isPng);
} catch (Throwable e2) {
FileLog.e(e2);
return null;
}
}
}
return null;
}
return null;
}
public static String getHttpUrlExtension(String url, String defaultExt) {
String ext = null;
String last = Uri.parse(url).getLastPathSegment();
if (!TextUtils.isEmpty(last) && last.length() > 1) {
url = last;
}
int idx = url.lastIndexOf(46);
if (idx != -1) {
ext = url.substring(idx + 1);
}
if (ext == null || ext.length() == 0 || ext.length() > 4) {
return defaultExt;
}
return ext;
}
public static void saveMessageThumbs(TLRPC.Message message) {
TLRPC.PhotoSize photoSize;
boolean isEncrypted;
File file;
TLRPC.PhotoSize photoSize2 = null;
if (message.media instanceof TLRPC.TL_messageMediaPhoto) {
int a = 0;
int count = message.media.photo.sizes.size();
while (true) {
if (a >= count) {
break;
}
TLRPC.PhotoSize size = message.media.photo.sizes.get(a);
if (!(size instanceof TLRPC.TL_photoCachedSize)) {
a++;
} else {
photoSize2 = size;
break;
}
}
photoSize = photoSize2;
} else if (message.media instanceof TLRPC.TL_messageMediaDocument) {
int a2 = 0;
int count2 = message.media.document.thumbs.size();
while (true) {
if (a2 >= count2) {
break;
}
TLRPC.PhotoSize size2 = message.media.document.thumbs.get(a2);
if (!(size2 instanceof TLRPC.TL_photoCachedSize)) {
a2++;
} else {
photoSize2 = size2;
break;
}
}
photoSize = photoSize2;
} else {
if ((message.media instanceof TLRPC.TL_messageMediaWebPage) && message.media.webpage.photo != null) {
int count3 = message.media.webpage.photo.sizes.size();
for (int a3 = 0; a3 < count3; a3++) {
TLRPC.PhotoSize size3 = message.media.webpage.photo.sizes.get(a3);
if (size3 instanceof TLRPC.TL_photoCachedSize) {
photoSize = size3;
break;
}
}
}
photoSize = null;
}
if (photoSize != null && photoSize.bytes != null && photoSize.bytes.length != 0) {
if (photoSize.location == null || (photoSize.location instanceof TLRPC.TL_fileLocationUnavailable)) {
photoSize.location = new TLRPC.TL_fileLocationToBeDeprecated();
photoSize.location.volume_id = -2147483648L;
photoSize.location.local_id = SharedConfig.getLastLocalId();
}
File file2 = FileLoader.getPathToAttach(photoSize, true);
if (!MessageObject.shouldEncryptPhotoOrVideo(message)) {
isEncrypted = false;
file = file2;
} else {
isEncrypted = true;
file = new File(file2.getAbsolutePath() + ".enc");
}
if (!file.exists()) {
if (isEncrypted) {
try {
File keyPath = new File(FileLoader.getInternalCacheDir(), file.getName() + ".key");
RandomAccessFile keyFile = new RandomAccessFile(keyPath, "rws");
long len = keyFile.length();
byte[] encryptKey = new byte[32];
byte[] encryptIv = new byte[16];
if (len > 0 && len % 48 == 0) {
keyFile.read(encryptKey, 0, 32);
keyFile.read(encryptIv, 0, 16);
} else {
Utilities.random.nextBytes(encryptKey);
Utilities.random.nextBytes(encryptIv);
keyFile.write(encryptKey);
keyFile.write(encryptIv);
}
keyFile.close();
Utilities.aesCtrDecryptionByteArray(photoSize.bytes, encryptKey, encryptIv, 0, photoSize.bytes.length, 0);
} catch (Exception e) {
FileLog.e(e);
}
}
RandomAccessFile writeFile = new RandomAccessFile(file, "rws");
writeFile.write(photoSize.bytes);
writeFile.close();
}
TLRPC.TL_photoSize newPhotoSize = new TLRPC.TL_photoSize();
newPhotoSize.w = photoSize.w;
newPhotoSize.h = photoSize.h;
newPhotoSize.location = photoSize.location;
newPhotoSize.size = photoSize.size;
newPhotoSize.type = photoSize.type;
if (message.media instanceof TLRPC.TL_messageMediaPhoto) {
int count4 = message.media.photo.sizes.size();
for (int a4 = 0; a4 < count4; a4++) {
if (message.media.photo.sizes.get(a4) instanceof TLRPC.TL_photoCachedSize) {
message.media.photo.sizes.set(a4, newPhotoSize);
return;
}
}
return;
}
if (message.media instanceof TLRPC.TL_messageMediaDocument) {
int count5 = message.media.document.thumbs.size();
for (int a5 = 0; a5 < count5; a5++) {
if (message.media.document.thumbs.get(a5) instanceof TLRPC.TL_photoCachedSize) {
message.media.document.thumbs.set(a5, newPhotoSize);
return;
}
}
return;
}
if (message.media instanceof TLRPC.TL_messageMediaWebPage) {
int count6 = message.media.webpage.photo.sizes.size();
for (int a6 = 0; a6 < count6; a6++) {
if (message.media.webpage.photo.sizes.get(a6) instanceof TLRPC.TL_photoCachedSize) {
message.media.webpage.photo.sizes.set(a6, newPhotoSize);
return;
}
}
}
}
}
public static void saveMessagesThumbs(ArrayList<TLRPC.Message> messages) {
if (messages == null || messages.isEmpty()) {
return;
}
for (int a = 0; a < messages.size(); a++) {
TLRPC.Message message = messages.get(a);
saveMessageThumbs(message);
}
}
}