翰林优商.apk(点击下载) / h.java


package com.iBookStar.a;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Rect;
import android.os.AsyncTask;
import android.text.TextPaint;
import android.text.TextUtils;
import android.view.View;
import androidx.collection.LruCache;
import androidx.constraintlayout.core.motion.utils.TypedValues;
import com.iBookStar.a.i;
import com.iBookStar.activityComm.RewardAdProxyActivity;
import com.iBookStar.d.a;
import com.iBookStar.d.d;
import com.iBookStar.utils.e;
import com.iBookStar.utils.k;
import com.iBookStar.utils.s;
import com.iBookStar.utils.w;
import com.iBookStar.views.CommonWebView;
import com.iBookStar.views.GameWebView;
import com.iBookStar.views.NativeAdUtil;
import com.mbridge.msdk.foundation.entity.CampaignEx;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONObject;

public class h extends NativeAdUtil implements com.iBookStar.d.b {
    private LruCache<String, f> a = new LruCache<>(100);
    private LruCache<String, f> b = new LruCache<>(100);

    class a implements GameWebView.i {
        final /* synthetic */ NativeAdUtil.MNativeAdClickListener a;
        final /* synthetic */ String b;

        a(h hVar, NativeAdUtil.MNativeAdClickListener mNativeAdClickListener, String str) {
            this.a = mNativeAdClickListener;
            this.b = str;
        }

        @Override // com.iBookStar.views.GameWebView.i
        public void onAdClicked() {
            NativeAdUtil.MNativeAdClickListener mNativeAdClickListener = this.a;
            if (mNativeAdClickListener != null) {
                mNativeAdClickListener.onAdClicked(this.b, false);
            }
        }

        @Override // com.iBookStar.views.GameWebView.i
        public void onApkDown() {
            NativeAdUtil.MNativeAdClickListener mNativeAdClickListener = this.a;
            if (mNativeAdClickListener != null) {
                mNativeAdClickListener.onApkDown(this.b);
            }
        }

        @Override // com.iBookStar.views.GameWebView.i
        public void onPreApkDown() {
            NativeAdUtil.MNativeAdClickListener mNativeAdClickListener = this.a;
            if (mNativeAdClickListener != null) {
                mNativeAdClickListener.onAdClicked(this.b, true);
            }
        }
    }

    /* access modifiers changed from: package-private */
    public class b extends i.l {
        final /* synthetic */ List a;
        final /* synthetic */ f b;
        final /* synthetic */ int c;
        final /* synthetic */ JSONArray d;
        final /* synthetic */ JSONObject e;
        final /* synthetic */ JSONObject f;
        final /* synthetic */ CommonWebView g;
        final /* synthetic */ String h;
        final /* synthetic */ JSONArray i;

        b(List list, f fVar, int i2, JSONArray jSONArray, JSONObject jSONObject, JSONObject jSONObject2, CommonWebView commonWebView, String str, JSONArray jSONArray2) {
            this.a = list;
            this.b = fVar;
            this.c = i2;
            this.d = jSONArray;
            this.e = jSONObject;
            this.f = jSONObject2;
            this.g = commonWebView;
            this.h = str;
            this.i = jSONArray2;
        }

        @Override // com.iBookStar.a.i.j
        public void a() {
            try {
                this.a.remove(this.b);
                h.this.a(this.b, this.c);
                this.d.put(this.e);
                if (this.a.isEmpty()) {
                    this.f.put("ads", this.d);
                    h.this.a(this.g, this.h, this.f.toString());
                }
            } catch (Throwable unused) {
            }
        }

        @Override // com.iBookStar.a.i.j
        public void b() {
            String str;
            JSONArray jSONArray;
            JSONObject jSONObject;
            try {
                this.i.put(this.b.J());
                this.a.remove(this.b);
                if (this.a.isEmpty()) {
                    if (this.d.length() > 0) {
                        jSONObject = this.f;
                        jSONArray = this.d;
                        str = "ads";
                    } else {
                        if (this.i.length() > 0) {
                            this.f.put("resultCode", "999");
                            jSONObject = this.f;
                            jSONArray = this.i;
                            str = "fas";
                        }
                        h.this.a(this.g, this.h, this.f.toString());
                    }
                    jSONObject.put(str, jSONArray);
                    h.this.a(this.g, this.h, this.f.toString());
                }
            } catch (Throwable unused) {
            }
        }
    }

    private static class c extends AsyncTask<Object, Integer, Object> {
        private c() {
        }

        /* synthetic */ c(a aVar) {
            this();
        }

        /* access modifiers changed from: protected */
        @Override // android.os.AsyncTask
        public Object doInBackground(Object... objArr) {
            Bitmap bitmap;
            NativeAdUtil.MNativeAdItem mNativeAdItem = (NativeAdUtil.MNativeAdItem) objArr[0];
            int intValue = ((Integer) objArr[1]).intValue();
            int intValue2 = ((Integer) objArr[2]).intValue();
            NativeAdUtil.MNativeAdListener mNativeAdListener = (NativeAdUtil.MNativeAdListener) objArr[3];
            String a = com.iBookStar.b.a.a(mNativeAdItem.getAdPic());
            Bitmap a2 = k.a(a, -1, -1);
            if (a2 == null) {
                com.iBookStar.d.a aVar = new com.iBookStar.d.a(mNativeAdItem.getAdPic(), null);
                aVar.b(a);
                if (a.equalsIgnoreCase(d.a().b(aVar))) {
                    a2 = k.a(a, -1, -1);
                }
            }
            if (s.c(mNativeAdItem.getAdBg())) {
                String a3 = com.iBookStar.b.a.a(mNativeAdItem.getAdBg());
                bitmap = k.a(a3, -1, -1);
                if (bitmap == null) {
                    com.iBookStar.d.a aVar2 = new com.iBookStar.d.a(mNativeAdItem.getAdBg(), null);
                    aVar2.b(a3);
                    if (a3.equalsIgnoreCase(d.a().b(aVar2))) {
                        bitmap = k.a(a3, -1, -1);
                    }
                }
            } else {
                bitmap = null;
            }
            if (!(bitmap == null || a2 == null)) {
                if (intValue <= 0) {
                    try {
                        intValue = k.d(com.iBookStar.b.a.k());
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                if (intValue2 <= 0) {
                    intValue2 = k.c(com.iBookStar.b.a.k());
                }
                Bitmap createBitmap = Bitmap.createBitmap(intValue, intValue2, Bitmap.Config.RGB_565);
                Canvas canvas = new Canvas(createBitmap);
                canvas.drawBitmap(bitmap, new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()), new Rect(0, 0, intValue, intValue2), (Paint) null);
                int i = (intValue2 * 580) / 1920;
                int i2 = (intValue * 70) / 1080;
                if (s.c(mNativeAdItem.getAdTitle())) {
                    TextPaint textPaint = new TextPaint();
                    textPaint.setTextSize((float) k.a(16.0f));
                    textPaint.setTextAlign(Paint.Align.CENTER);
                    canvas.drawText((String) TextUtils.ellipsize(mNativeAdItem.getAdTitle(), textPaint, (float) (intValue - (i2 * 2)), TextUtils.TruncateAt.END), (float) (intValue / 2), (float) i, textPaint);
                    i += k.a(24.0f);
                }
                float width = ((float) (intValue - (i2 * 2))) / ((float) a2.getWidth());
                Matrix matrix = new Matrix();
                matrix.postScale(width, width);
                matrix.postTranslate((float) i2, (float) i);
                canvas.drawBitmap(a2, matrix, null);
                mNativeAdItem.setAdBmp(createBitmap);
                mNativeAdItem.setAdBg(null);
                return new Object[]{mNativeAdItem, mNativeAdListener};
            }
            mNativeAdItem.setAdBg(null);
            return new Object[]{mNativeAdItem, mNativeAdListener};
        }

        /* access modifiers changed from: protected */
        @Override // android.os.AsyncTask
        public void onPostExecute(Object obj) {
            Object[] objArr = (Object[]) obj;
            NativeAdUtil.MNativeAdItem mNativeAdItem = (NativeAdUtil.MNativeAdItem) objArr[0];
            NativeAdUtil.MNativeAdListener mNativeAdListener = (NativeAdUtil.MNativeAdListener) objArr[1];
            if (mNativeAdListener != null) {
                mNativeAdListener.onComplete(mNativeAdItem);
            }
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void a(CommonWebView commonWebView, String str, String str2) {
        if (commonWebView != null && !commonWebView.isFinished() && s.c(str) && s.c(str2)) {
            try {
                commonWebView.loadUrl(String.format("javascript:if(%s){%s(%s)}", str, str, str2));
            } catch (Throwable th) {
                th.printStackTrace();
            }
        }
    }

    private void a(String str, CommonWebView commonWebView, String str2, int i, String str3, boolean z, String str4) {
        Throwable th;
        String str5;
        String str6;
        String str7;
        String str8;
        JSONObject jSONObject;
        JSONArray optJSONArray;
        h hVar;
        CommonWebView commonWebView2;
        String str9;
        JSONObject jSONObject2;
        int i2;
        String str10;
        String str11;
        String str12;
        String str13;
        String str14;
        JSONObject jSONObject3;
        String str15;
        String str16;
        String str17;
        ArrayList arrayList;
        String str18;
        String str19;
        int i3;
        JSONArray jSONArray;
        String str20;
        String str21;
        String str22;
        String str23;
        String str24;
        String str25;
        String str26;
        int i4;
        h hVar2;
        String str27;
        String str28;
        CommonWebView commonWebView3;
        JSONObject jSONObject4;
        f fVar;
        int i5;
        h hVar3;
        String str29;
        String str30;
        String str31;
        String str32 = "sclickurl";
        String str33 = "ads";
        try {
            if (!s.a(str)) {
                JSONObject jSONObject5 = new JSONObject(str);
                if ("0".equalsIgnoreCase(jSONObject5.optString("resultCode"))) {
                    JSONArray optJSONArray2 = jSONObject5.optJSONArray(com.sigmob.sdk.base.h.l);
                    jSONObject5.remove(com.sigmob.sdk.base.h.l);
                    String str34 = "ad_pic";
                    String str35 = "id";
                    String str36 = "isMacro";
                    String str37 = "c_interval";
                    String str38 = "ad_rate";
                    String str39 = "clickurl";
                    String str40 = "showurl";
                    String str41 = "ad-hot-action-type";
                    String str42 = "ad-hot-action-param";
                    String str43 = "extraParam";
                    if (optJSONArray2 != null) {
                        try {
                            if (optJSONArray2.length() > 0) {
                                str8 = "loadurl";
                                int i6 = 0;
                                while (i6 < optJSONArray2.length()) {
                                    f fVar2 = new f();
                                    JSONObject jSONObject6 = optJSONArray2.getJSONObject(i6);
                                    fVar2.n(jSONObject6.optString(str35));
                                    fVar2.a(jSONObject6.optString(str42));
                                    fVar2.b(jSONObject6.optString(str41));
                                    fVar2.g(jSONObject6.optString(str34));
                                    JSONArray optJSONArray3 = jSONObject6.optJSONArray(str40);
                                    if (optJSONArray3 == null || optJSONArray3.length() <= 0) {
                                        str31 = str40;
                                        str30 = str34;
                                        str29 = str41;
                                    } else {
                                        str31 = str40;
                                        String[] strArr = new String[optJSONArray3.length()];
                                        str30 = str34;
                                        str29 = str41;
                                        for (int i7 = 0; i7 < optJSONArray3.length(); i7++) {
                                            strArr[i7] = optJSONArray3.getString(i7);
                                        }
                                        fVar2.f(strArr);
                                    }
                                    JSONArray optJSONArray4 = jSONObject6.optJSONArray(str39);
                                    if (optJSONArray4 != null && optJSONArray4.length() > 0) {
                                        String[] strArr2 = new String[optJSONArray4.length()];
                                        for (int i8 = 0; i8 < optJSONArray4.length(); i8++) {
                                            strArr2[i8] = optJSONArray4.getString(i8);
                                        }
                                        fVar2.b(strArr2);
                                    }
                                    fVar2.a(jSONObject6.optDouble(str38, 0.0d));
                                    fVar2.a(jSONObject6.optLong(str37, (long) (((Math.random() * 5.0d) + 3.0d) * 1000.0d)));
                                    fVar2.a(jSONObject6.optInt(str36) == 1);
                                    d.a().a(fVar2);
                                    i6++;
                                    str39 = str39;
                                    str35 = str35;
                                    str32 = str32;
                                    optJSONArray2 = optJSONArray2;
                                    str40 = str31;
                                    str34 = str30;
                                    str41 = str29;
                                }
                                str6 = str40;
                                str5 = str34;
                                str7 = str32;
                                String str44 = str39;
                                String str45 = str41;
                                String str46 = str35;
                                jSONObject = new JSONObject();
                                jSONObject.put("resultCode", jSONObject5.optString("resultCode"));
                                jSONObject.put(str33, new JSONArray());
                                JSONArray jSONArray2 = new JSONArray();
                                ArrayList arrayList2 = new ArrayList();
                                JSONArray jSONArray3 = new JSONArray();
                                optJSONArray = jSONObject5.optJSONArray(str33);
                                if (optJSONArray != null || optJSONArray.length() <= 0) {
                                    hVar = this;
                                    commonWebView2 = commonWebView;
                                    str9 = str2;
                                    jSONObject2 = jSONObject;
                                } else {
                                    boolean z2 = false;
                                    int i9 = 0;
                                    while (i9 < optJSONArray.length()) {
                                        f fVar3 = new f();
                                        JSONObject jSONObject7 = optJSONArray.getJSONObject(i9);
                                        fVar3.n(jSONObject7.optString(str46));
                                        fVar3.a(jSONObject7.optString(str42));
                                        jSONObject7.remove(str42);
                                        fVar3.b(jSONObject7.optString(str45));
                                        jSONObject7.remove(str45);
                                        fVar3.g(jSONObject7.optString(str5));
                                        JSONArray optJSONArray5 = jSONObject7.optJSONArray("ad_pics");
                                        if (optJSONArray5 == null || optJSONArray5.length() <= 0) {
                                            str11 = str5;
                                            str10 = str33;
                                            i2 = i9;
                                        } else {
                                            str11 = str5;
                                            String[] strArr3 = new String[optJSONArray5.length()];
                                            str10 = str33;
                                            i2 = i9;
                                            for (int i10 = 0; i10 < optJSONArray5.length(); i10++) {
                                                strArr3[i10] = optJSONArray5.getString(i10);
                                            }
                                            fVar3.a(strArr3);
                                        }
                                        fVar3.a(jSONObject7.optInt(str36) == 1);
                                        jSONObject7.remove(str36);
                                        JSONArray optJSONArray6 = jSONObject7.optJSONArray(str6);
                                        jSONObject7.remove(str6);
                                        if (optJSONArray6 == null || optJSONArray6.length() <= 0) {
                                            str12 = str36;
                                        } else {
                                            String[] strArr4 = new String[optJSONArray6.length()];
                                            str12 = str36;
                                            for (int i11 = 0; i11 < optJSONArray6.length(); i11++) {
                                                strArr4[i11] = optJSONArray6.getString(i11);
                                            }
                                            fVar3.f(strArr4);
                                        }
                                        JSONArray optJSONArray7 = jSONObject7.optJSONArray(str44);
                                        jSONObject7.remove(str44);
                                        if (optJSONArray7 != null && optJSONArray7.length() > 0) {
                                            String[] strArr5 = new String[optJSONArray7.length()];
                                            for (int i12 = 0; i12 < optJSONArray7.length(); i12++) {
                                                strArr5[i12] = optJSONArray7.getString(i12);
                                            }
                                            fVar3.b(strArr5);
                                        }
                                        JSONArray optJSONArray8 = jSONObject7.optJSONArray(str7);
                                        jSONObject7.remove(str7);
                                        if (optJSONArray8 == null || optJSONArray8.length() <= 0) {
                                            str13 = str44;
                                        } else {
                                            String[] strArr6 = new String[optJSONArray8.length()];
                                            str13 = str44;
                                            for (int i13 = 0; i13 < optJSONArray8.length(); i13++) {
                                                strArr6[i13] = optJSONArray8.getString(i13);
                                            }
                                            fVar3.e(strArr6);
                                        }
                                        JSONArray optJSONArray9 = jSONObject7.optJSONArray(str8);
                                        jSONObject7.remove(str8);
                                        if (optJSONArray9 == null || optJSONArray9.length() <= 0) {
                                            str14 = str8;
                                        } else {
                                            String[] strArr7 = new String[optJSONArray9.length()];
                                            str14 = str8;
                                            for (int i14 = 0; i14 < optJSONArray9.length(); i14++) {
                                                strArr7[i14] = optJSONArray9.getString(i14);
                                            }
                                            fVar3.d(strArr7);
                                        }
                                        fVar3.a(jSONObject7.optDouble(str38, 0.0d));
                                        jSONObject7.remove(str38);
                                        fVar3.a(jSONObject7.optLong(str37, (long) (((Math.random() * 5.0d) + 3.0d) * 1000.0d)));
                                        jSONObject7.remove(str37);
                                        fVar3.b(jSONObject7.optLong("mTime", 0));
                                        fVar3.c(jSONObject7.optDouble("sRatio", 0.0d));
                                        fVar3.q(jSONObject7.optString(com.sigmob.sdk.base.h.k));
                                        fVar3.l(jSONObject7.optString("dspChannalCode"));
                                        fVar3.h(jSONObject7.optString("appid"));
                                        fVar3.i(jSONObject7.optString("appkey"));
                                        fVar3.m(jSONObject7.optString(str43));
                                        jSONObject7.remove(str43);
                                        fVar3.f(jSONObject7.optString("adType"));
                                        fVar3.a(jSONObject7.optInt("bannerType", 0));
                                        fVar3.p(jSONObject7.optString("sdkCode"));
                                        fVar3.e(jSONObject7.optInt("isJs", 0));
                                        fVar3.b(jSONObject7.optInt("backDelay", 0));
                                        if (!s.c(fVar3.J())) {
                                            str16 = str43;
                                            jSONObject4 = jSONObject7;
                                            fVar = fVar3;
                                            arrayList = arrayList2;
                                            str15 = str42;
                                            str20 = str37;
                                            str22 = str38;
                                            jSONObject3 = jSONObject;
                                            str21 = str12;
                                            str24 = str45;
                                            str23 = str11;
                                            str17 = str10;
                                            i3 = i2;
                                            hVar2 = this;
                                            commonWebView3 = commonWebView;
                                            str28 = str2;
                                            i4 = i;
                                            str26 = str4;
                                            str19 = str7;
                                            str27 = str3;
                                        } else if (fVar3.J().endsWith("sdk")) {
                                            if ("motivated".equalsIgnoreCase(fVar3.h())) {
                                                arrayList2.add(fVar3);
                                                str21 = str12;
                                                str23 = str11;
                                                str22 = str38;
                                                str17 = str10;
                                                i3 = i2;
                                                str19 = str7;
                                                str18 = str14;
                                                jSONArray = optJSONArray;
                                                str16 = str43;
                                                arrayList = arrayList2;
                                                str15 = str42;
                                                jSONObject3 = jSONObject;
                                                i.e().a(fVar3, new b(arrayList2, fVar3, i, jSONArray2, jSONObject7, jSONObject, commonWebView, str2, jSONArray3));
                                                str24 = str45;
                                                str25 = str6;
                                                str20 = str37;
                                            } else {
                                                str16 = str43;
                                                arrayList = arrayList2;
                                                str15 = str42;
                                                str22 = str38;
                                                jSONObject3 = jSONObject;
                                                str21 = str12;
                                                str23 = str11;
                                                str17 = str10;
                                                i3 = i2;
                                                str19 = str7;
                                                str18 = str14;
                                                jSONArray = optJSONArray;
                                                fVar3.a(jSONObject7);
                                                if (TypedValues.Custom.S_FLOAT.equalsIgnoreCase(str4)) {
                                                    str24 = str45;
                                                    str25 = str6;
                                                    commonWebView.loadFloatNativeAd(fVar3, str2, str3);
                                                    hVar3 = this;
                                                    i5 = i;
                                                } else {
                                                    str24 = str45;
                                                    str25 = str6;
                                                    commonWebView.loadNativeAd(fVar3, str2, str3, z);
                                                    hVar3 = this;
                                                    i5 = i;
                                                }
                                                str20 = str37;
                                                hVar3.a(fVar3, i5);
                                            }
                                            z2 = true;
                                            jSONObject = jSONObject3;
                                            i9 = i3 + 1;
                                            str6 = str25;
                                            str5 = str23;
                                            str38 = str22;
                                            str36 = str21;
                                            str37 = str20;
                                            optJSONArray = jSONArray;
                                            str44 = str13;
                                            str46 = str46;
                                            str7 = str19;
                                            str8 = str18;
                                            str33 = str17;
                                            str43 = str16;
                                            str42 = str15;
                                            str45 = str24;
                                            arrayList2 = arrayList;
                                        } else {
                                            str27 = str3;
                                            str16 = str43;
                                            jSONObject4 = jSONObject7;
                                            fVar = fVar3;
                                            arrayList = arrayList2;
                                            str15 = str42;
                                            str20 = str37;
                                            str22 = str38;
                                            jSONObject3 = jSONObject;
                                            str21 = str12;
                                            str24 = str45;
                                            str23 = str11;
                                            str17 = str10;
                                            i3 = i2;
                                            hVar2 = this;
                                            commonWebView3 = commonWebView;
                                            str28 = str2;
                                            i4 = i;
                                            str26 = str4;
                                            str19 = str7;
                                        }
                                        jSONArray = optJSONArray;
                                        str25 = str6;
                                        str18 = str14;
                                        if (TypedValues.Custom.S_FLOAT.equalsIgnoreCase(str26)) {
                                            commonWebView3.loadFloatNativeAd(fVar, str28, str27);
                                        } else {
                                            jSONArray2.put(jSONObject4);
                                            hVar2.a(fVar, i4);
                                        }
                                        jSONObject = jSONObject3;
                                        i9 = i3 + 1;
                                        str6 = str25;
                                        str5 = str23;
                                        str38 = str22;
                                        str36 = str21;
                                        str37 = str20;
                                        optJSONArray = jSONArray;
                                        str44 = str13;
                                        str46 = str46;
                                        str7 = str19;
                                        str8 = str18;
                                        str33 = str17;
                                        str43 = str16;
                                        str42 = str15;
                                        str45 = str24;
                                        arrayList2 = arrayList;
                                    }
                                    hVar = this;
                                    commonWebView2 = commonWebView;
                                    str9 = str2;
                                    if (!z2) {
                                        try {
                                            if (jSONArray2.length() > 0) {
                                                jSONObject2 = jSONObject;
                                                jSONObject2.put(str33, jSONArray2);
                                            } else {
                                                jSONObject2 = jSONObject;
                                            }
                                        } catch (Throwable unused) {
                                            return;
                                        }
                                    } else {
                                        return;
                                    }
                                }
                                hVar.a(commonWebView2, str9, jSONObject2.toString());
                            }
                        } catch (Throwable th2) {
                            th = th2;
                            th.printStackTrace();
                        }
                    }
                    str6 = str40;
                    str5 = str34;
                    str7 = str32;
                    str8 = "loadurl";
                    String str442 = str39;
                    String str452 = str41;
                    String str462 = str35;
                    jSONObject = new JSONObject();
                    jSONObject.put("resultCode", jSONObject5.optString("resultCode"));
                    jSONObject.put(str33, new JSONArray());
                    JSONArray jSONArray22 = new JSONArray();
                    ArrayList arrayList22 = new ArrayList();
                    JSONArray jSONArray32 = new JSONArray();
                    optJSONArray = jSONObject5.optJSONArray(str33);
                    if (optJSONArray != null) {
                    }
                    hVar = this;
                    commonWebView2 = commonWebView;
                    str9 = str2;
                    jSONObject2 = jSONObject;
                    hVar.a(commonWebView2, str9, jSONObject2.toString());
                }
            }
        } catch (Throwable th3) {
            th = th3;
            th.printStackTrace();
        }
    }

    private f c(String str) {
        f fVar = this.a.get(str);
        return fVar == null ? this.b.get(str) : fVar;
    }

    private NativeAdUtil.MNativeAdItem d(String str) {
        NativeAdUtil.MNativeAdItem mNativeAdItem;
        Exception e;
        NativeAdUtil.MNativeAdItem mNativeAdItem2;
        String str2;
        String str3;
        String str4;
        NativeAdUtil.MNativeAdItem mNativeAdItem3;
        String str5;
        int i;
        String str6;
        JSONArray jSONArray;
        String str7;
        String str8;
        JSONArray jSONArray2;
        String str9;
        try {
            JSONObject jSONObject = new JSONObject(str);
            if (!"0".equalsIgnoreCase(jSONObject.optString("resultCode"))) {
                return null;
            }
            JSONArray optJSONArray = jSONObject.optJSONArray("ads");
            String str10 = "clickurl";
            String str11 = "showurl";
            String str12 = "isMacro";
            String str13 = "ad_pic";
            String str14 = "ad-hot-action-type";
            String str15 = "ad-hot-action-param";
            if (optJSONArray == null || optJSONArray.length() <= 0) {
                str4 = str13;
                str3 = str14;
                str6 = str10;
                str5 = str11;
                str2 = str12;
                i = 0;
                mNativeAdItem3 = null;
            } else {
                int i2 = 0;
                mNativeAdItem3 = null;
                while (i2 < optJSONArray.length()) {
                    try {
                        f fVar = new f();
                        JSONObject jSONObject2 = optJSONArray.getJSONObject(i2);
                        fVar.n(jSONObject2.optString("id"));
                        fVar.a(jSONObject2.optString(str15));
                        fVar.b(jSONObject2.optString(str14));
                        fVar.g(jSONObject2.optString(str13));
                        JSONArray optJSONArray2 = jSONObject2.optJSONArray("ad_pics");
                        if (optJSONArray2 == null || optJSONArray2.length() <= 0) {
                            str8 = str13;
                            jSONArray2 = optJSONArray;
                            str7 = str14;
                        } else {
                            jSONArray2 = optJSONArray;
                            String[] strArr = new String[optJSONArray2.length()];
                            str8 = str13;
                            str7 = str14;
                            for (int i3 = 0; i3 < optJSONArray2.length(); i3++) {
                                strArr[i3] = optJSONArray2.getString(i3);
                            }
                            fVar.a(strArr);
                        }
                        fVar.a(jSONObject2.optInt(str12) == 1);
                        JSONArray optJSONArray3 = jSONObject2.optJSONArray(str11);
                        if (optJSONArray3 != null && optJSONArray3.length() > 0) {
                            String[] strArr2 = new String[optJSONArray3.length()];
                            for (int i4 = 0; i4 < optJSONArray3.length(); i4++) {
                                strArr2[i4] = optJSONArray3.getString(i4);
                            }
                            fVar.f(strArr2);
                        }
                        JSONArray optJSONArray4 = jSONObject2.optJSONArray(str10);
                        if (optJSONArray4 != null && optJSONArray4.length() > 0) {
                            String[] strArr3 = new String[optJSONArray4.length()];
                            for (int i5 = 0; i5 < optJSONArray4.length(); i5++) {
                                strArr3[i5] = optJSONArray4.getString(i5);
                            }
                            fVar.b(strArr3);
                        }
                        JSONArray optJSONArray5 = jSONObject2.optJSONArray("loadurl");
                        if (optJSONArray5 != null && optJSONArray5.length() > 0) {
                            String[] strArr4 = new String[optJSONArray5.length()];
                            for (int i6 = 0; i6 < optJSONArray5.length(); i6++) {
                                strArr4[i6] = optJSONArray5.getString(i6);
                            }
                            fVar.d(strArr4);
                        }
                        fVar.a(jSONObject2.optDouble("ad_rate", 0.0d));
                        fVar.a(jSONObject2.optLong("c_interval", (long) (((Math.random() * 5.0d) + 3.0d) * 1000.0d)));
                        fVar.q(jSONObject2.optString(com.sigmob.sdk.base.h.k));
                        fVar.l(jSONObject2.optString("dspChannalCode"));
                        fVar.h(jSONObject2.optString("appid"));
                        fVar.i(jSONObject2.optString("appkey"));
                        fVar.m(jSONObject2.optString("extraParam"));
                        fVar.f(jSONObject2.optString("adType"));
                        fVar.a(jSONObject2.optInt("bannerType", 0));
                        fVar.p(jSONObject2.optString("sdkCode"));
                        fVar.e(jSONObject2.optInt("isJs", 0));
                        fVar.b(jSONObject2.optInt("backDelay", 0));
                        fVar.b(jSONObject2.optLong("mTime", 0));
                        fVar.c(jSONObject2.optDouble("sRatio", 0.0d));
                        if (i2 == 0) {
                            mNativeAdItem2 = new NativeAdUtil.MNativeAdItem();
                            try {
                                mNativeAdItem2.setAdId(fVar.y());
                                mNativeAdItem2.setAdPic(fVar.i());
                                if (fVar.j() != null) {
                                    ArrayList arrayList = new ArrayList(fVar.j().length);
                                    String[] j = fVar.j();
                                    str9 = str12;
                                    int i7 = 0;
                                    for (int length = j.length; i7 < length; length = length) {
                                        arrayList.add(j[i7]);
                                        i7++;
                                    }
                                    mNativeAdItem2.setAdPics(arrayList);
                                } else {
                                    str9 = str12;
                                }
                                mNativeAdItem2.setAsId(jSONObject2.optString("ad_id"));
                                mNativeAdItem2.setAdBg(jSONObject2.optString("ad_bg"));
                                mNativeAdItem2.setAdTitle(jSONObject2.optString("text_title"));
                                mNativeAdItem2.setAdContent(jSONObject2.optString("content"));
                                mNativeAdItem2.setAdDesc(jSONObject2.optString(CampaignEx.JSON_KEY_DESC));
                                mNativeAdItem2.setAdIcon(jSONObject2.optString("ad_icon"));
                                try {
                                    mNativeAdItem2.setBannerType(Integer.parseInt(jSONObject2.optString("bannerType")));
                                } catch (Exception e2) {
                                    e2.printStackTrace();
                                }
                                mNativeAdItem2.setSource(fVar.J());
                                mNativeAdItem2.setDspChannelCode(fVar.s());
                                mNativeAdItem2.setAppId(fVar.l());
                                mNativeAdItem2.setAppKey(fVar.m());
                            } catch (Exception e3) {
                                e = e3;
                                mNativeAdItem = mNativeAdItem2;
                                e.printStackTrace();
                                return mNativeAdItem;
                            }
                            try {
                                a(fVar, 0);
                                mNativeAdItem3 = mNativeAdItem2;
                            } catch (Exception e4) {
                                e = e4;
                                mNativeAdItem = mNativeAdItem2;
                                e.printStackTrace();
                                return mNativeAdItem;
                            }
                        } else {
                            str9 = str12;
                            try {
                                d.a().a(fVar);
                            } catch (Exception e5) {
                                e = e5;
                            }
                        }
                        i2++;
                        str10 = str10;
                        str11 = str11;
                        optJSONArray = jSONArray2;
                        str13 = str8;
                        str14 = str7;
                        str12 = str9;
                    } catch (Exception e6) {
                        e = e6;
                        mNativeAdItem = mNativeAdItem3;
                        e.printStackTrace();
                        return mNativeAdItem;
                    }
                }
                str4 = str13;
                str3 = str14;
                str6 = str10;
                str5 = str11;
                str2 = str12;
                i = 0;
            }
            try {
                JSONArray optJSONArray6 = jSONObject.optJSONArray(com.sigmob.sdk.base.h.l);
                if (optJSONArray6 != null && optJSONArray6.length() > 0) {
                    int i8 = 0;
                    while (i8 < optJSONArray6.length()) {
                        f fVar2 = new f();
                        JSONObject jSONObject3 = optJSONArray6.getJSONObject(i8);
                        fVar2.n(jSONObject3.optString("id"));
                        fVar2.a(jSONObject3.optString(str15));
                        fVar2.b(jSONObject3.optString(str3));
                        fVar2.g(jSONObject3.optString(str4));
                        JSONArray optJSONArray7 = jSONObject3.optJSONArray(str5);
                        if (optJSONArray7 == null || optJSONArray7.length() <= 0) {
                            jSONArray = optJSONArray6;
                        } else {
                            String[] strArr5 = new String[optJSONArray7.length()];
                            jSONArray = optJSONArray6;
                            while (i < optJSONArray7.length()) {
                                strArr5[i] = optJSONArray7.getString(i);
                                i++;
                            }
                            fVar2.f(strArr5);
                        }
                        JSONArray optJSONArray8 = jSONObject3.optJSONArray(str6);
                        if (optJSONArray8 != null && optJSONArray8.length() > 0) {
                            String[] strArr6 = new String[optJSONArray8.length()];
                            for (int i9 = 0; i9 < optJSONArray8.length(); i9++) {
                                strArr6[i9] = optJSONArray8.getString(i9);
                            }
                            fVar2.b(strArr6);
                        }
                        fVar2.a(jSONObject3.optDouble("ad_rate", 0.0d));
                        fVar2.a(jSONObject3.optLong("c_interval", (long) (((Math.random() * 5.0d) + 3.0d) * 1000.0d)));
                        fVar2.a(jSONObject3.optInt(str2) == 1);
                        d.a().a(fVar2);
                        i8++;
                        str2 = str2;
                        str3 = str3;
                        str4 = str4;
                        str15 = str15;
                        optJSONArray6 = jSONArray;
                        i = 0;
                    }
                }
                return mNativeAdItem3;
            } catch (Exception e7) {
                e = e7;
                mNativeAdItem2 = mNativeAdItem3;
                mNativeAdItem = mNativeAdItem2;
                e.printStackTrace();
                return mNativeAdItem;
            }
        } catch (Exception e8) {
            e = e8;
            mNativeAdItem = null;
            e.printStackTrace();
            return mNativeAdItem;
        }
    }

    public void a(f fVar, int i) {
        (i > 0 ? this.b : this.a).put(fVar.y(), fVar);
    }

    public void a(String str) {
        f c2 = c(str);
        if (c2 != null && c2.q() != null) {
            d.a().b(c2);
        }
    }

    public void b(String str) {
        f c2 = c(str);
        if (c2 != null && c2.I() != null) {
            d.a().d(c2);
        }
    }

    @Override // com.iBookStar.views.NativeAdUtil
    public void click(Activity activity, String str, int i, int i2, int i3, int i4, NativeAdUtil.MNativeAdClickListener mNativeAdClickListener) {
        f c2 = c(str);
        if (c2 == null) {
            return;
        }
        if (!s.c(c2.J()) || !c2.J().endsWith("sdk")) {
            c2.j(i).k(i2).i(i3).d(i4);
            d.a().b(c2);
            GameWebView.HandleAdClick(activity, c2.b(), c2.a(), i, i2, i3, i4, false, new a(this, mNativeAdClickListener, str));
            return;
        }
        RewardAdProxyActivity.a(activity, c2, 0, null);
    }

    @Override // com.iBookStar.views.NativeAdUtil
    public void click(CommonWebView commonWebView, String str, int i, int i2, int i3, int i4, boolean z, boolean z2) {
        f c2 = c(str);
        if (c2 != null) {
            commonWebView.setAdItem(c2);
            if (!s.c(c2.J()) || !c2.J().endsWith("sdk")) {
                float f = (float) i;
                float f2 = (float) i2;
                float f3 = (float) i3;
                float f4 = (float) i4;
                c2.j((int) (commonWebView.getScale() * f)).k((int) (commonWebView.getScale() * f2)).i((int) (commonWebView.getScale() * f3)).d((int) (commonWebView.getScale() * f4));
                d.a().b(c2);
                GameWebView.HandleAdClick(commonWebView, c2, (int) (f * commonWebView.getScale()), (int) (f2 * commonWebView.getScale()), (int) (f3 * commonWebView.getScale()), (int) (f4 * commonWebView.getScale()), z, z2);
            } else {
                RewardAdProxyActivity.a(((View) commonWebView.getParent()).getContext(), c2, commonWebView.getCurrentTaskId(), null);
            }
            w.a().a(new e(false));
        }
    }

    @Override // com.iBookStar.views.NativeAdUtil
    public void loadReport(String str, int i) {
        f c2 = c(str);
        if (c2 != null && c2.A() != null) {
            d.a().a(c2, i);
        }
    }

    @Override // com.iBookStar.d.b
    public void onComplete(int i, int i2, Object obj, Object obj2) {
        if (i == 0) {
            Object[] objArr = (Object[]) obj2;
            int intValue = ((Integer) objArr[1]).intValue();
            int intValue2 = ((Integer) objArr[2]).intValue();
            if (!"h5".equalsIgnoreCase((String) objArr[0])) {
                NativeAdUtil.MNativeAdListener mNativeAdListener = (NativeAdUtil.MNativeAdListener) objArr[3];
                NativeAdUtil.MNativeAdItem d = i2 == 200 ? d((String) obj) : null;
                if (mNativeAdListener == null) {
                    return;
                }
                if (d == null || !s.c(d.getAdBg())) {
                    mNativeAdListener.onComplete(d);
                } else {
                    new c(null).execute(d, Integer.valueOf(intValue), Integer.valueOf(intValue2), mNativeAdListener);
                }
            } else if (i2 == 200) {
                a((String) obj, (CommonWebView) objArr[3], (String) objArr[4], ((Integer) objArr[5]).intValue(), (String) objArr[6], ((Boolean) objArr[7]).booleanValue(), (String) objArr[8]);
            }
        }
    }

    @Override // com.iBookStar.d.b
    public void onUpdate(int i, int i2, int i3, Object obj) {
    }

    @Override // com.iBookStar.views.NativeAdUtil
    public void play(Activity activity, String str, NativeAdUtil.MVideoAdListener mVideoAdListener) {
        f c2 = c(str);
        if (c2 != null && s.c(c2.J()) && c2.J().endsWith("sdk")) {
            RewardAdProxyActivity.a(activity, c2, 0, mVideoAdListener);
        }
    }

    @Override // com.iBookStar.views.NativeAdUtil
    public void release(String str) {
        this.a.remove(str);
        this.b.remove(str);
    }

    /* JADX WARNING: Removed duplicated region for block: B:36:0x00d7  */
    /* JADX WARNING: Removed duplicated region for block: B:39:0x00e5  */
    /* JADX WARNING: Removed duplicated region for block: B:42:0x00f4  */
    @Override // com.iBookStar.views.NativeAdUtil
    public void requestAd(CommonWebView commonWebView, String str, String str2) {
        boolean z;
        int i;
        Exception e;
        StringBuilder sb = new StringBuilder(com.iBookStar.c.c.c());
        sb.append("/dspapi/ad/getH5Ad?");
        sb.append("inClient=1");
        String str3 = "webview";
        boolean z2 = false;
        String str4 = null;
        try {
            JSONObject jSONObject = new JSONObject(str);
            Iterator<String> keys = jSONObject.keys();
            i = 0;
            z = false;
            while (keys.hasNext()) {
                try {
                    String next = keys.next();
                    String optString = jSONObject.optString(next);
                    if ("containerId".equalsIgnoreCase(next)) {
                        str4 = optString;
                    } else if ("showContinueBtn".equalsIgnoreCase(next)) {
                        try {
                            z = Boolean.parseBoolean(optString);
                        } catch (Throwable th) {
                            th.printStackTrace();
                        }
                    } else {
                        if ("refer".equalsIgnoreCase(next) && s.a(optString)) {
                            optString = "SDK_NO_REFER";
                        } else if ("at".equalsIgnoreCase(next)) {
                            try {
                                i = Integer.parseInt(optString);
                            } catch (Exception unused) {
                            }
                        } else if ("renderTo".equalsIgnoreCase(next)) {
                            str3 = optString;
                        }
                        String encode = URLEncoder.encode(optString);
                        sb.append("&");
                        sb.append(next);
                        sb.append("=");
                        sb.append(encode);
                    }
                } catch (Exception e2) {
                    e = e2;
                    e.printStackTrace();
                    com.iBookStar.d.a aVar = new com.iBookStar.d.a(0, sb.toString(), a.EnumC0067a.METHOD_GET, this, new Object[]{"h5", -1, -1, commonWebView, str2, Integer.valueOf(i), str4, Boolean.valueOf(z), str3});
                    if (i == 0) {
                    }
                    aVar.a(z2);
                    if (s.c(commonWebView.getUA())) {
                    }
                    if (commonWebView.isX5CoreLoaded()) {
                    }
                    d.a().a(aVar);
                }
            }
        } catch (Exception e3) {
            e = e3;
            i = 0;
            z = false;
            e.printStackTrace();
            com.iBookStar.d.a aVar2 = new com.iBookStar.d.a(0, sb.toString(), a.EnumC0067a.METHOD_GET, this, new Object[]{"h5", -1, -1, commonWebView, str2, Integer.valueOf(i), str4, Boolean.valueOf(z), str3});
            if (i == 0) {
            }
            aVar2.a(z2);
            if (s.c(commonWebView.getUA())) {
            }
            if (commonWebView.isX5CoreLoaded()) {
            }
            d.a().a(aVar2);
        }
        com.iBookStar.d.a aVar22 = new com.iBookStar.d.a(0, sb.toString(), a.EnumC0067a.METHOD_GET, this, new Object[]{"h5", -1, -1, commonWebView, str2, Integer.valueOf(i), str4, Boolean.valueOf(z), str3});
        if (i == 0) {
            z2 = true;
        }
        aVar22.a(z2);
        if (s.c(commonWebView.getUA())) {
            aVar22.a("User-Agent", commonWebView.getUA());
        }
        if (commonWebView.isX5CoreLoaded()) {
            aVar22.a("info-x5", "1");
        }
        d.a().a(aVar22);
    }

    @Override // com.iBookStar.views.NativeAdUtil
    public void requestAd(String str, int i, int i2, NativeAdUtil.MNativeAdListener mNativeAdListener) {
        com.iBookStar.d.a aVar = new com.iBookStar.d.a(0, com.iBookStar.c.c.c() + "/api/ad/ad/getNativeAd?ad_channal_code=" + str, a.EnumC0067a.METHOD_GET, this, new Object[]{"native", Integer.valueOf(i), Integer.valueOf(i2), mNativeAdListener, 0});
        aVar.a(true);
        d.a().a(aVar);
    }

    @Override // com.iBookStar.views.NativeAdUtil
    public void show(String str) {
        f c2 = c(str);
        if (c2 != null && c2.I() != null) {
            if (s.a(c2.J()) || !c2.J().endsWith("sdk")) {
                d.a().d(c2);
            }
        }
    }
}