package X; import android.app.Activity; import android.content.Context; import android.net.Uri; import com.bytedance.covode.number.Covode; import com.ss.android.ugc.aweme.download.component_api.DownloadServiceManager; import com.ss.android.ugc.aweme.fe.method.DownloadFileMethod; import com.zhiliaoapp.musically.R; import java.io.File; import java.util.List; import java.util.concurrent.Callable; import kotlin.g.b.m; import org.json.JSONObject; /* renamed from: X.3LH reason: invalid class name */ public final class AnonymousClass3LH implements AbstractC37614Epv { public final /* synthetic */ DownloadFileMethod LIZ; public final /* synthetic */ JSONObject LIZIZ; public final /* synthetic */ AnonymousClass3J0 LIZJ; public final /* synthetic */ Activity LIZLLL; static { Covode.recordClassIndex(66788); } public AnonymousClass3LH(DownloadFileMethod downloadFileMethod, JSONObject jSONObject, AnonymousClass3J0 r3, Activity activity) { this.LIZ = downloadFileMethod; this.LIZIZ = jSONObject; this.LIZJ = r3; this.LIZLLL = activity; } /* JADX WARNING: Removed duplicated region for block: B:50:0x00f6 */ @Override // X.AbstractC37614Epv public final void LIZ(String[] strArr, int[] iArr) { String optString; String sb; Uri uri; String str; List LIZ2; List LIZ3; File parentFile; T t; if (iArr == null || iArr.length == 0 || iArr[0] != 0) { C10140ax.LIZ(new C10140ax(this.LIZLLL).LIZ(this.LIZLLL.getString(R.string.a2s))); return; } DownloadFileMethod downloadFileMethod = this.LIZ; JSONObject jSONObject = this.LIZIZ; AnonymousClass3J0 r6 = this.LIZJ; JSONObject jSONObject2 = new JSONObject(); jSONObject2.put("code", -1); Context context = (Context) downloadFileMethod.mContextRef.get(); if (context != null) { jSONObject2.put("reason", "params insufficient"); String str2 = null; if (C61952cK.LIZ(jSONObject != null ? jSONObject.optString("url") : null)) { if (!(!C61952cK.LIZ(jSONObject != null ? jSONObject.optString("suffix") : null) || jSONObject == null || (optString = jSONObject.optString("suffix")) == null || (AnonymousClass1ZS.LIZ((CharSequence) optString, (CharSequence) "../", false)) || context == null)) { downloadFileMethod.LIZ = jSONObject != null ? jSONObject.optString("url") : null; downloadFileMethod.LIZIZ = jSONObject != null ? jSONObject.optString("type") : null; downloadFileMethod.LJ = jSONObject != null ? jSONObject.optString("id") : null; Boolean valueOf = jSONObject != null ? Boolean.valueOf(jSONObject.optBoolean("externalStorage")) : null; String str3 = (m.LIZ(downloadFileMethod.LIZIZ, "image") ? AnonymousClass26J.LIZ(downloadFileMethod.LIZ) + System.currentTimeMillis() : AnonymousClass26J.LIZ(downloadFileMethod.LIZ)) + (jSONObject != null ? jSONObject.optString("suffix") : null); String str4 = downloadFileMethod.LIZIZ; if (str4 == null || str4.hashCode() != 100313435 || !str4.equals("image")) { uri = AnonymousClass0EI.LIZ(context, str3); if (uri == null) { uri = AnonymousClass0EI.LIZIZ(context, str3, "video/mp4"); } } else if (valueOf == null || !m.LIZ((Object) valueOf, (Object) true)) { StringBuilder sb2 = new StringBuilder(); File LIZIZ2 = C55182Fn.LIZIZ(); m.LIZIZ(LIZIZ2, ""); sb = sb2.append(LIZIZ2.getPath()).append("/downloadMedia/").toString(); uri = null; if (sb != null) { str = sb + str3; if (!C10170b0.LJ.LJ(str) || AnonymousClass0EI.LIZJ(context, uri)) { jSONObject2.put("reason", "file already exists"); jSONObject2.put("path", str); } else { String str5 = downloadFileMethod.LIZ; if (!(!m.LIZ((Object) downloadFileMethod.LIZIZ, (Object) "image")) && str5 != null && (LIZ2 = AnonymousClass1ZS.LIZ(str5, new String[]{","}, 0, 6)) != null && LIZ2.size() == 2) { String str6 = (String) LIZ2.get(0); if (AnonymousClass1ZS.LIZIZ(str6, "data:image", false) && AnonymousClass1ZS.LIZJ(str6, ";base64", false)) { String str7 = downloadFileMethod.LIZ; if (!(str7 == null || (LIZ3 = AnonymousClass1ZS.LIZ(str7, new String[]{","}, 0, 6)) == null || LIZ3.size() != 2)) { C23360wH r8 = new C23360wH(); r8.element = null; if (str != null) { r8.element = (T) new File(str); T t2 = r8.element; if (!(t2 == null || (parentFile = t2.getParentFile()) == null || parentFile.exists() || (t = r8.element) == null)) { t.mkdirs(); } } AnonymousClass0ED.LIZ((Callable) new AnonymousClass3LI(downloadFileMethod, r8, uri, LIZ3, str)); } jSONObject2.remove("reason"); jSONObject2.put("code", 1); } } if (sb != null) { str2 = sb; } else if (uri != null) { str2 = uri.toString(); } AbstractC46330IHf with = DownloadServiceManager.INSTANCE.getDownloadService().with(downloadFileMethod.LIZ); with.LIZJ = str3; with.LJFF = str2; AbstractC46330IHf LIZ4 = with.LIZ("js_file_download_method"); LIZ4.LJJIIJZLJL = downloadFileMethod; downloadFileMethod.LIZLLL = Integer.valueOf(LIZ4.LJFF()); jSONObject2.remove("reason"); jSONObject2.put("code", 1); } } str = null; if (!C10170b0.LJ.LJ(str)) { } jSONObject2.put("reason", "file already exists"); jSONObject2.put("path", str); } else { uri = AnonymousClass0EI.LIZJ(context, str3, null); if (uri == null) { uri = AnonymousClass0EI.LIZ(context, str3, "image/jpeg"); } } sb = null; str = null; if (!C10170b0.LJ.LJ(str)) { } jSONObject2.put("reason", "file already exists"); jSONObject2.put("path", str); } } } if (r6 != null) { r6.LIZ(jSONObject2); } } }