jimu-decompiled/sources/com/ubt/jimu/utils/GlideCacheUtils.java
2025-05-13 19:24:51 +02:00

117 lines
3.2 KiB
Java

package com.ubt.jimu.utils;
import android.content.Context;
import android.os.Looper;
import com.bumptech.glide.Glide;
import java.io.File;
import java.math.BigDecimal;
/* loaded from: classes2.dex */
public class GlideCacheUtils {
private static GlideCacheUtils a;
public static GlideCacheUtils a() {
if (a == null) {
a = new GlideCacheUtils();
}
return a;
}
public void b(Context context) {
try {
if (Looper.myLooper() == Looper.getMainLooper()) {
Glide.b(context).b();
}
} catch (Exception e) {
e.printStackTrace();
}
}
public String c(Context context) {
try {
return a(a(new File(context.getCacheDir() + "/image_manager_disk_cache")));
} catch (Exception e) {
e.printStackTrace();
return "";
}
}
public void a(final Context context) {
try {
if (Looper.myLooper() == Looper.getMainLooper()) {
new Thread(new Runnable(this) { // from class: com.ubt.jimu.utils.GlideCacheUtils.1
@Override // java.lang.Runnable
public void run() {
Glide.b(context).a();
}
}).start();
} else {
Glide.b(context).a();
}
} catch (Exception e) {
e.printStackTrace();
}
}
private long a(File file) throws Exception {
long length;
long j = 0;
try {
for (File file2 : file.listFiles()) {
if (file2.isDirectory()) {
length = a(file2);
} else {
length = file2.length();
}
j += length;
}
} catch (Exception e) {
e.printStackTrace();
}
return j;
}
public void a(String str, boolean z) {
if (android.text.TextUtils.isEmpty(str)) {
return;
}
try {
File file = new File(str);
if (file.isDirectory()) {
for (File file2 : file.listFiles()) {
a(file2.getAbsolutePath(), true);
}
}
if (z) {
if (!file.isDirectory()) {
file.delete();
} else if (file.listFiles().length == 0) {
file.delete();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
private static String a(double d) {
double d2 = d / 1024.0d;
if (d2 < 1.0d) {
return "0.0KB";
}
double d3 = d2 / 1024.0d;
if (d3 < 1.0d) {
return new BigDecimal(Double.toString(d2)).setScale(2, 4).toPlainString() + "KB";
}
double d4 = d3 / 1024.0d;
if (d4 < 1.0d) {
return new BigDecimal(Double.toString(d3)).setScale(2, 4).toPlainString() + "MB";
}
double d5 = d4 / 1024.0d;
if (d5 < 1.0d) {
return new BigDecimal(Double.toString(d4)).setScale(2, 4).toPlainString() + "GB";
}
return BigDecimal.valueOf(d5).setScale(2, 4).toPlainString() + "TB";
}
}