Swiggy v4.51.1版本的 MD5 值为:5af7ec91512a0a8c1510e3f8bac20b8b
以下内容为反编译后的 ImageUrlBuilder.java 源代码,内容仅作参考
package in.swiggy.android.commons.utils.imageutil;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.util.Base64;
import android.util.DisplayMetrics;
import com.facebook.network.connectionclass.ConnectionQuality;
import com.xiaomi.mipush.sdk.Constants;
import in.swiggy.android.commons.extension.KotlinExtensionsKt;
import in.swiggy.android.commons.extension.StringExtensionsKt;
import in.swiggy.android.commons.utils.i0;
import in.swiggy.android.commons.utils.x;
import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import kotlin.NoWhenBranchMatchedException;
import kotlin.Pair;
import kotlin.collections.CollectionsKt___CollectionsKt;
import kotlin.j;
import kotlin.jvm.functions.Function0;
import kotlin.jvm.internal.o;
import kotlin.k;
import kotlin.text.StringsKt__StringsKt;
import kotlin.text.q;
public final class ImageUrlBuilder {
private static SharedPreferences g;
public static final ImageUrlBuilder a = new ImageUrlBuilder();
private static String b = "f_avif";
private static String c = "f_webm";
private static String d = "media-assets.swiggy.com";
private static String e = "res.cloudinary.com";
private static final DisplayMetrics f = Resources.getSystem().getDisplayMetrics();
private static final j h = k.b(new Function0<Boolean>() {
@Override
public final Boolean invoke() {
SharedPreferences sharedPreferences;
String str;
sharedPreferences = ImageUrlBuilder.g;
if (sharedPreferences != null) {
str = sharedPreferences.getString("key_cache_reuse_for_low_network", "true");
} else {
str = null;
}
return Boolean.valueOf(KotlinExtensionsKt.q(str, true));
}
});
private static final j i = k.b(new Function0<Boolean>() {
@Override
public final Boolean invoke() {
SharedPreferences sharedPreferences;
String str;
sharedPreferences = ImageUrlBuilder.g;
if (sharedPreferences != null) {
str = sharedPreferences.getString("use_eco_image_video_quality", "true");
if (str == null) {
str = "";
}
} else {
str = null;
}
return Boolean.valueOf(KotlinExtensionsKt.q(str, false));
}
});
private static final j j = k.b(new Function0<Boolean>() {
@Override
public final Boolean invoke() {
SharedPreferences sharedPreferences;
String str;
sharedPreferences = ImageUrlBuilder.g;
if (sharedPreferences != null) {
str = sharedPreferences.getString("enable_no_extension_video_handling", "true");
if (str == null) {
str = "";
}
} else {
str = null;
}
return Boolean.valueOf(KotlinExtensionsKt.q(str, false));
}
});
public class a {
public static final int[] a;
static {
int[] iArr = new int[ConnectionQuality.values().length];
try {
iArr[ConnectionQuality.POOR.ordinal()] = 1;
} catch (NoSuchFieldError unused) {
}
try {
iArr[ConnectionQuality.MODERATE.ordinal()] = 2;
} catch (NoSuchFieldError unused2) {
}
try {
iArr[ConnectionQuality.UNKNOWN.ordinal()] = 3;
} catch (NoSuchFieldError unused3) {
}
try {
iArr[ConnectionQuality.GOOD.ordinal()] = 4;
} catch (NoSuchFieldError unused4) {
}
try {
iArr[ConnectionQuality.EXCELLENT.ordinal()] = 5;
} catch (NoSuchFieldError unused5) {
}
a = iArr;
}
}
private ImageUrlBuilder() {
}
public static final String A(Context context, String str) {
boolean U;
o.k(context, "context");
ConnectionQuality b2 = b.d().b(context);
if (str != null) {
int i2 = 0;
U = StringsKt__StringsKt.U(str, "https://res.cloudinary.com/swiggy/image/upload/", false, 2, null);
if (U) {
int f2 = i0.f(context);
if (f2 < 1032) {
i2 = f2;
}
String substring = str.substring(47);
o.j(substring, "substring(...)");
ImageUrlBuilder imageUrlBuilder = a;
o.h(b2);
String m = imageUrlBuilder.m(b2, i2, 0, false, false, imageUrlBuilder.v(), false);
return "https://res.cloudinary.com/swiggy/image/upload/" + m + "/" + substring;
}
}
if (str == null) {
return "";
}
return str;
}
private final SharedPreferences B(Context context) {
if (g == null) {
g = androidx.preference.b.a(context.getApplicationContext());
}
SharedPreferences sharedPreferences = g;
o.h(sharedPreferences);
return sharedPreferences;
}
public static final void C(SharedPreferences sharedPreferences) {
o.k(sharedPreferences, "sharedPreferences");
String string = sharedPreferences.getString("image_base_uri_wp", "res.cloudinary.com");
if (string != null && StringExtensionsKt.e(string)) {
d = string;
e = string;
}
}
public static final void D(String mpBaseUrl, SharedPreferences mSharedPreferences) {
o.k(mpBaseUrl, "mpBaseUrl");
o.k(mSharedPreferences, "mSharedPreferences");
String string = mSharedPreferences.getString("image_base_uri_wp", "res.cloudinary.com");
if (string != null && StringExtensionsKt.e(string)) {
e = string;
}
if (StringExtensionsKt.e(mpBaseUrl)) {
d = mpBaseUrl;
}
}
private final String f(boolean z, boolean z2) {
String t0;
ArrayList arrayList = new ArrayList();
if (z2) {
arrayList.add("c_fit");
} else {
arrayList.add("c_fill");
}
if (z) {
arrayList.add("e_grayscale");
}
t0 = CollectionsKt___CollectionsKt.t0(arrayList, Constants.ACCEPT_TIME_SEPARATOR_SP, null, null, 0, null, null, 62, null);
return t0;
}
public static final String g(String str, boolean z, boolean z2) {
boolean C;
boolean U;
String str2 = d;
if (str != null) {
C = q.C(str);
if (!C) {
U = StringsKt__StringsKt.U(a.l(str), "svg", false, 2, null);
if (U) {
str2 = e;
}
}
}
String uri = new Uri.Builder().scheme("https").authority(str2).appendPath("swiggy").appendPath("image").appendPath("upload").appendEncodedPath(a.f(z, z2)).appendEncodedPath(String.valueOf(str)).appendEncodedPath("cache").build().toString();
o.j(uri, "toString(...)");
return uri;
}
private final String i(ConnectionQuality connectionQuality, int i2, int i3, boolean z) {
String t0;
ArrayList arrayList = new ArrayList();
arrayList.add("c_crop");
arrayList.add("g_face");
arrayList.add("c_thumb");
arrayList.add("fl_lossy");
arrayList.add(b);
if (i3 > 0) {
ImageUrlBuilder imageUrlBuilder = a;
int k = imageUrlBuilder.k(i3, connectionQuality);
arrayList.add("h_" + k);
int k2 = imageUrlBuilder.k(i2, connectionQuality);
arrayList.add("w_" + k2);
}
arrayList.add(a.t(connectionQuality, false, z));
t0 = CollectionsKt___CollectionsKt.t0(arrayList, Constants.ACCEPT_TIME_SEPARATOR_SP, null, null, 0, null, null, 62, null);
return t0;
}
public static final String j(Context context, String str, int i2, int i3) {
o.k(context, "context");
ConnectionQuality b2 = b.d().b(context);
ImageUrlBuilder imageUrlBuilder = a;
imageUrlBuilder.B(context);
if (imageUrlBuilder.z() && b2 != ConnectionQuality.EXCELLENT && b2 != ConnectionQuality.GOOD && str != null) {
in.swiggy.android.commons.utils.imageutil.a.a.a().put(str, new Pair<>(Integer.valueOf(i2), Integer.valueOf(i3)));
}
if (StringExtensionsKt.e(str)) {
Uri.Builder appendPath = new Uri.Builder().scheme("https").authority(e).appendPath("swiggy").appendPath("image").appendPath("upload");
o.h(b2);
String uri = appendPath.appendEncodedPath(imageUrlBuilder.i(b2, i2, i3, imageUrlBuilder.v())).appendEncodedPath(String.valueOf(str)).build().toString();
o.j(uri, "toString(...)");
return uri;
}
return "";
}
private final int k(int i2, ConnectionQuality connectionQuality) {
float f2;
float f3;
int i3 = a.a[connectionQuality.ordinal()];
if (i3 != 1) {
if (i3 == 2 || i3 == 3) {
f2 = i2;
f3 = 1.33f;
} else {
return i2;
}
} else {
f2 = i2;
f3 = 1.66f;
}
return (int) (f2 / f3);
}
private final String m(ConnectionQuality connectionQuality, int i2, int i3, boolean z, boolean z2, boolean z3, boolean z4) {
String t0;
ArrayList arrayList = new ArrayList();
if (z4) {
arrayList.add("c_fit");
} else {
arrayList.add("c_fill");
}
arrayList.add("fl_lossy");
arrayList.add(b);
ImageUrlBuilder imageUrlBuilder = a;
arrayList.add(imageUrlBuilder.t(connectionQuality, z2, z3));
if (i3 > 0) {
int k = imageUrlBuilder.k(i3, connectionQuality);
arrayList.add("h_" + k);
}
if (i2 > 0) {
int k2 = imageUrlBuilder.k(i2, connectionQuality);
arrayList.add("w_" + k2);
}
if (z) {
arrayList.add("e_grayscale");
}
t0 = CollectionsKt___CollectionsKt.t0(arrayList, Constants.ACCEPT_TIME_SEPARATOR_SP, null, null, 0, null, null, 62, null);
return t0;
}
public static final String n(Context context, String str, int i2, int i3, boolean z, boolean z2, boolean z3) {
boolean C;
boolean U;
o.k(context, "context");
ConnectionQuality b2 = b.d().b(context);
ImageUrlBuilder imageUrlBuilder = a;
imageUrlBuilder.B(context);
String str2 = d;
if (str != null) {
C = q.C(str);
if (!C) {
U = StringsKt__StringsKt.U(imageUrlBuilder.l(str), "svg", false, 2, null);
if (U) {
str2 = e;
}
}
}
if (imageUrlBuilder.z() && b2 != ConnectionQuality.EXCELLENT && b2 != ConnectionQuality.GOOD && str != null) {
in.swiggy.android.commons.utils.imageutil.a.a.a().put(str, new Pair<>(Integer.valueOf(i2), Integer.valueOf(i3)));
}
if ((z2 && b2 == ConnectionQuality.POOR) || !StringExtensionsKt.e(str)) {
return "";
}
Uri.Builder appendPath = new Uri.Builder().scheme("https").authority(str2).appendPath("swiggy").appendPath("image").appendPath("upload");
o.h(b2);
String uri = appendPath.appendEncodedPath(imageUrlBuilder.m(b2, i2, i3, z, z2, imageUrlBuilder.v(), z3)).appendEncodedPath(String.valueOf(str)).build().toString();
o.j(uri, "toString(...)");
return uri;
}
public static String o(Context context, String str, int i2, int i3, boolean z, boolean z2, boolean z3, int i4, Object obj) {
if ((i4 & 64) != 0) {
z3 = false;
}
return n(context, str, i2, i3, z, z2, z3);
}
public static final String p(String str) {
if (StringExtensionsKt.e(str)) {
String uri = new Uri.Builder().scheme("https").authority(d).appendPath("swiggy").appendPath("raw").appendPath("upload").appendPath(String.valueOf(str)).build().toString();
o.j(uri, "toString(...)");
return uri;
}
return "";
}
private final String q(int i2, int i3, boolean z, boolean z2, boolean z3, boolean z4) {
String str;
String str2;
String t0;
ArrayList arrayList = new ArrayList();
if (z3) {
str = "c_fit";
} else {
str = "c_fill";
}
arrayList.add(str);
arrayList.add("fl_lossy");
arrayList.add(b);
if (z2) {
str2 = "q_auto:eco";
} else {
str2 = "q_auto";
}
arrayList.add(str2);
if (i3 > 0) {
arrayList.add("h_" + i3);
}
if (i2 > 0) {
arrayList.add("w_" + i2);
}
if (z4) {
arrayList.add("r_max");
}
if (z) {
arrayList.add("e_grayscale");
}
t0 = CollectionsKt___CollectionsKt.t0(arrayList, Constants.ACCEPT_TIME_SEPARATOR_SP, null, null, 0, null, null, 62, null);
return t0;
}
public static final String r(String str, int i2, int i3, boolean z, boolean z2, boolean z3) {
boolean C;
boolean U;
String str2 = d;
if (str != null) {
C = q.C(str);
if (!C) {
U = StringsKt__StringsKt.U(a.l(str), "svg", false, 2, null);
if (U) {
str2 = e;
}
}
}
if (StringExtensionsKt.e(str)) {
String uri = new Uri.Builder().scheme("https").authority(str2).appendPath("swiggy").appendPath("image").appendPath("upload").appendEncodedPath(a.q(i2, i3, z, true, z2, z3)).appendEncodedPath(str).build().toString();
o.j(uri, "toString(...)");
return uri;
}
return "";
}
public static String s(String str, int i2, int i3, boolean z, boolean z2, boolean z3, int i4, Object obj) {
if ((i4 & 32) != 0) {
z3 = false;
}
return r(str, i2, i3, z, z2, z3);
}
private final String t(ConnectionQuality connectionQuality, boolean z, boolean z2) {
if (z) {
return "q_auto:low";
}
if (!z2) {
int i2 = a.a[connectionQuality.ordinal()];
if (i2 == 1) {
return "q_auto:low";
}
if (i2 != 2 && i2 != 3) {
if (i2 != 4 && i2 != 5) {
throw new NoWhenBranchMatchedException();
}
return "q_auto";
}
}
return "q_auto:eco";
}
private final boolean u() {
return ((Boolean) j.getValue()).booleanValue();
}
private final boolean v() {
return ((Boolean) i.getValue()).booleanValue();
}
private final String w(int i2, int i3, boolean z, boolean z2) {
String str;
String t0;
DisplayMetrics displayMetrics;
if (z2) {
int i4 = f.widthPixels;
float f2 = displayMetrics.heightPixels / i4;
int i5 = i4 - 360;
i3 = i5;
i2 = (int) (i5 * f2);
}
ArrayList arrayList = new ArrayList();
if (StringExtensionsKt.e(c)) {
arrayList.add(c);
}
arrayList.add("fl_lossy");
if (z) {
str = "q_auto:eco";
} else {
str = "q_auto";
}
arrayList.add(str);
if (i2 > 0) {
arrayList.add("h_" + i2);
arrayList.add("w_" + i3);
}
t0 = CollectionsKt___CollectionsKt.t0(arrayList, Constants.ACCEPT_TIME_SEPARATOR_SP, null, null, 0, null, null, 62, null);
return t0;
}
public static final String x(String videoId, Context context, int i2, int i3, boolean z) {
boolean C;
o.k(videoId, "videoId");
o.k(context, "context");
ImageUrlBuilder imageUrlBuilder = a;
imageUrlBuilder.B(context);
if (imageUrlBuilder.u() && StringExtensionsKt.e(videoId)) {
C = q.C(imageUrlBuilder.l(videoId));
if (C) {
videoId = videoId + ".mp4";
}
}
String uri = imageUrlBuilder.e().appendEncodedPath(imageUrlBuilder.w(i2, i3, imageUrlBuilder.v(), z)).appendEncodedPath(videoId).build().toString();
o.j(uri, "toString(...)");
return uri;
}
public static String y(String str, Context context, int i2, int i3, boolean z, int i4, Object obj) {
if ((i4 & 4) != 0) {
i2 = -1;
}
if ((i4 & 8) != 0) {
i3 = -1;
}
if ((i4 & 16) != 0) {
z = false;
}
return x(str, context, i2, i3, z);
}
private final boolean z() {
return ((Boolean) h.getValue()).booleanValue();
}
public final void E(String formatParam) {
o.k(formatParam, "formatParam");
if (!StringExtensionsKt.e(formatParam)) {
formatParam = "f_avif";
}
b = formatParam;
}
public final void F(String formatParam) {
o.k(formatParam, "formatParam");
c = formatParam;
}
public final String b(Bitmap bitmap) {
o.k(bitmap, "bitmap");
try {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
return Base64.encodeToString(byteArrayOutputStream.toByteArray(), 2);
} catch (Exception e2) {
x.e("ImageUrlBuilder", e2.getMessage());
return null;
}
}
public final Bitmap c(Drawable drawable) {
o.k(drawable, "drawable");
if (drawable instanceof BitmapDrawable) {
return ((BitmapDrawable) drawable).getBitmap();
}
try {
Bitmap createBitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
o.j(createBitmap, "createBitmap(...)");
Canvas canvas = new Canvas(createBitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
return createBitmap;
} catch (Exception e2) {
x.e("ImageUrlBuilder", e2.getMessage());
return null;
}
}
public final String d() {
return d;
}
public final Uri.Builder e() {
Uri.Builder appendPath = new Uri.Builder().scheme("https").authority(d).appendPath("swiggy").appendPath("video").appendPath("upload");
o.j(appendPath, "appendPath(...)");
return appendPath;
}
public final Uri.Builder h() {
Uri.Builder appendPath = new Uri.Builder().scheme("https").authority("res.cloudinary.com").appendPath("swiggy").appendPath("video").appendPath("upload");
o.j(appendPath, "appendPath(...)");
return appendPath;
}
public final String l(String str) {
int o0;
int o02;
if (str == null || str.length() <= 1) {
return "";
}
o0 = StringsKt__StringsKt.o0(str, ".", 0, false, 6, null);
if (o0 == -1) {
return "";
}
o02 = StringsKt__StringsKt.o0(str, ".", 0, false, 6, null);
String substring = str.substring(o02 + 1, str.length());
o.j(substring, "substring(...)");
return substring;
}
}