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


package com.iBookStar.a;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import com.bytedance.sdk.openadsdk.api.plugin.PluginConstants;
import com.iBookStar.R;
import com.iBookStar.a.j;
import com.iBookStar.utils.e;
import com.iBookStar.utils.p;
import com.iBookStar.utils.s;
import com.iBookStar.utils.w;
import com.iBookStar.views.CommonWebView;
import com.iBookStar.views.NativeAdUtil;
import com.mbridge.msdk.playercommon.exoplayer2.text.ttml.TtmlNode;
import java.util.HashMap;
import java.util.Map;
import org.json.JSONArray;
import org.json.JSONObject;

public class k implements j.i {
    private static final int e = com.iBookStar.utils.k.a(50.0f);
    private static final int f = com.iBookStar.utils.k.a(90.0f);
    private CommonWebView a;
    private Map<String, c> b = new HashMap();
    private float c;
    private float d;

    /* access modifiers changed from: package-private */
    public class a implements View.OnClickListener {
        final /* synthetic */ c a;
        final /* synthetic */ View b;

        a(k kVar, c cVar, View view) {
            this.a = cVar;
            this.b = view;
        }

        public void onClick(View view) {
            this.a.i().a(this.b);
        }
    }

    /* access modifiers changed from: package-private */
    public class b implements View.OnClickListener {
        b() {
        }

        public void onClick(View view) {
            p.a("SdkAdsMgr", "vvvvvvvvvvvvvvvvvvv, continue read click");
            if (k.this.a != null && !k.this.a.isFinished()) {
                try {
                    k.this.a.loadUrl("javascript:if(window.onContinueBtnClick){window.onContinueBtnClick()}");
                } catch (Throwable th) {
                    th.printStackTrace();
                }
            }
        }
    }

    public static class c {
        private RelativeLayout a;
        private f b;
        private String c;
        private int d;
        private boolean e;
        private float f = -100.0f;
        private float g = 5000.0f;
        private boolean h;
        private j i;
        private String j;
        private boolean k;

        public c a(float f2) {
            this.f = f2;
            return this;
        }

        public c a(int i2) {
            this.d = i2;
            return this;
        }

        public c a(RelativeLayout relativeLayout) {
            this.a = relativeLayout;
            return this;
        }

        public c a(f fVar) {
            this.b = fVar;
            return this;
        }

        public c a(j jVar) {
            this.i = jVar;
            return this;
        }

        public c a(String str) {
            this.j = str;
            return this;
        }

        public c a(boolean z) {
            this.k = z;
            return this;
        }

        public void a() {
            RelativeLayout relativeLayout = this.a;
            if (!(relativeLayout == null || relativeLayout.getParent() == null)) {
                ((ViewGroup) this.a.getParent()).removeView(this.a);
            }
            this.a = null;
            j jVar = this.i;
            if (jVar != null) {
                jVar.a();
                this.i = null;
            }
        }

        public float b() {
            return this.f;
        }

        public c b(float f2) {
            this.g = f2;
            return this;
        }

        public c b(String str) {
            this.c = str;
            return this;
        }

        public c b(boolean z) {
            this.h = z;
            return this;
        }

        public float c() {
            return this.g;
        }

        public c c(boolean z) {
            this.e = z;
            return this;
        }

        public RelativeLayout d() {
            return this.a;
        }

        public f e() {
            return this.b;
        }

        public String f() {
            return this.j;
        }

        public String g() {
            return this.c;
        }

        public int h() {
            return this.d;
        }

        public j i() {
            return this.i;
        }

        public boolean j() {
            return this.k;
        }

        public boolean k() {
            return this.h;
        }

        public boolean l() {
            return this.e;
        }
    }

    public k(CommonWebView commonWebView) {
        this.a = commonWebView;
        this.c = 0.0f;
        this.d = ((float) commonWebView.getWidth()) / commonWebView.getScale();
    }

    private void a(c cVar) {
        if (cVar != null && cVar.d() != null && cVar.d().getParent() != null) {
            a(cVar.g(), 0.0f);
            cVar.a();
        }
    }

    private void a(c cVar, View view, int i, boolean z) {
        if (view != null && cVar != null && cVar.d() == null) {
            RelativeLayout relativeLayout = (RelativeLayout) ((LayoutInflater) com.iBookStar.b.a.k().getSystemService("layout_inflater")).inflate(com.iBookStar.utils.k.a(R.layout.ym_sdk_container, "ym_sdk_container", TtmlNode.TAG_LAYOUT), (ViewGroup) null);
            if (z) {
                view.setOnClickListener(new a(this, cVar, view));
            }
            relativeLayout.findViewById(com.iBookStar.utils.k.a(R.id.ym_sdk_ad_read_tv, "ym_sdk_ad_read_tv", "id")).setOnClickListener(new b());
            ((ViewGroup) relativeLayout.findViewById(com.iBookStar.utils.k.a(R.id.ym_sdk_ad_rl, "ym_sdk_ad_rl", "id"))).addView(view, new RelativeLayout.LayoutParams(-1, i));
            cVar.a(relativeLayout);
            relativeLayout.setTranslationY(cVar.c() * this.a.getScale());
            this.a.addAdView(relativeLayout);
        }
    }

    private void a(String str, float f2) {
        CommonWebView commonWebView = this.a;
        if (commonWebView != null && !commonWebView.isFinished()) {
            try {
                JSONObject jSONObject = new JSONObject();
                jSONObject.put("containerId", str);
                jSONObject.put("height", (double) (f2 / this.a.getScale()));
                this.a.loadUrl(String.format("javascript:if(window.onHeightChange){window.onHeightChange(%s)}", jSONObject.toString()));
            } catch (Throwable th) {
                th.printStackTrace();
            }
        }
    }

    private c b(f fVar) {
        for (c cVar : this.b.values()) {
            if (cVar.e().y().equalsIgnoreCase(fVar.y())) {
                return cVar;
            }
        }
        return null;
    }

    private void b(c cVar) {
        CommonWebView commonWebView = this.a;
        if (commonWebView != null && !commonWebView.isFinished() && cVar != null) {
            a(cVar);
            if (!cVar.j()) {
                NativeAdUtil.getInstance().loadReport(cVar.e().y(), 1);
                cVar.a(true);
                try {
                    JSONObject jSONObject = new JSONObject();
                    jSONObject.put("resultCode", "997");
                    JSONArray jSONArray = new JSONArray();
                    jSONArray.put(cVar.e().J());
                    jSONObject.put("fas", jSONArray);
                    this.a.loadUrl(String.format("javascript:if(%s){%s(%s)}", cVar.f(), cVar.f(), jSONObject.toString()));
                } catch (Throwable th) {
                    th.printStackTrace();
                }
            }
        }
    }

    private c c(f fVar) {
        for (String str : this.b.keySet()) {
            c cVar = this.b.get(str);
            if (cVar.e().y().equalsIgnoreCase(fVar.y())) {
                this.b.remove(str);
                return cVar;
            }
        }
        return null;
    }

    private void c(c cVar) {
        CommonWebView commonWebView = this.a;
        if (commonWebView != null && !commonWebView.isFinished() && cVar != null && !cVar.j()) {
            NativeAdUtil.getInstance().loadReport(cVar.e().y(), 0);
            cVar.d().getChildAt(0).setBackgroundResource(com.iBookStar.utils.k.a(R.drawable.ym_sdk_container_bg, "ym_sdk_container_bg", "drawable"));
            if (cVar.l()) {
                cVar.d().getChildAt(1).setVisibility(0);
            }
            try {
                JSONObject jSONObject = new JSONObject();
                jSONObject.put("resultCode", "998");
                JSONArray jSONArray = new JSONArray();
                JSONObject B = cVar.e().B();
                if (B != null) {
                    jSONArray.put(B);
                }
                jSONObject.put("ads", jSONArray);
                this.a.loadUrl(String.format("javascript:if(%s){%s(%s)}", cVar.f(), cVar.f(), jSONObject.toString()));
            } catch (Throwable th) {
                th.printStackTrace();
            }
        }
    }

    private void c(String str) {
        CommonWebView commonWebView = this.a;
        if (commonWebView != null && !commonWebView.isFinished()) {
            try {
                this.a.loadUrl(String.format("javascript:if(window.getAdPosition){window.getAdPosition('%s')}", str));
            } catch (Throwable th) {
                th.printStackTrace();
            }
        }
    }

    public void a() {
        for (c cVar : this.b.values()) {
            if (cVar.d() != null && cVar.k()) {
                cVar.d().setTranslationY(this.a.getScale() * 5000.0f);
                cVar.b(false);
            }
        }
    }

    public void a(f fVar, String str, String str2, boolean z) {
        c remove = this.b.remove(str2);
        if (remove != null) {
            try {
                remove.a();
            } catch (Throwable th) {
                th.printStackTrace();
            }
            a(remove.g(), 0.0f);
        }
        j jVar = new j(this);
        this.b.put(str2, new c().a(jVar).a(fVar).b(str2).c(z).a(str));
        jVar.a(this.a.getContext(), fVar, (((float) com.iBookStar.utils.k.d(this.a.getContext())) - (com.iBookStar.b.a.k().getResources().getDimension(com.iBookStar.utils.k.a(R.dimen.ym_sdk_ad_margin_horizontal, "ym_sdk_ad_margin_horizontal", "dimen")) * 2.0f)) - (com.iBookStar.b.a.k().getResources().getDimension(com.iBookStar.utils.k.a(R.dimen.ym_sdk_ad_bg_padding, "ym_sdk_ad_bg_padding", "dimen")) * 2.0f));
    }

    public void a(String str) {
        float f2;
        RelativeLayout relativeLayout;
        String str2 = "absoluteTop";
        if (!s.a(str)) {
            try {
                JSONObject jSONObject = new JSONObject(str);
                if (jSONObject.optInt(PluginConstants.KEY_ERROR_CODE) >= 0) {
                    String optString = jSONObject.optString("containerId");
                    float optDouble = (float) jSONObject.optDouble("absoluteLeft");
                    if (!jSONObject.has(str2)) {
                        str2 = "y";
                    }
                    float optDouble2 = (float) jSONObject.optDouble(str2);
                    c cVar = this.b.get(optString);
                    if (cVar != null && cVar.d() != null && Math.round(optDouble2) != Math.round(cVar.c())) {
                        cVar.a(optDouble).b(optDouble2);
                        float f3 = this.c;
                        if (optDouble >= f3 && optDouble < f3 + this.d) {
                            relativeLayout = cVar.d();
                            cVar.b(true);
                            f2 = this.a.getScale();
                        } else if (cVar.k()) {
                            cVar.b(false);
                            relativeLayout = cVar.d();
                            f2 = 5000.0f;
                            optDouble2 = this.a.getScale();
                        } else {
                            return;
                        }
                        relativeLayout.setTranslationY(optDouble2 * f2);
                    }
                }
            } catch (Throwable th) {
                th.printStackTrace();
            }
        }
    }

    public void a(boolean z) {
        for (c cVar : this.b.values()) {
            try {
                cVar.a();
            } catch (Throwable th) {
                th.printStackTrace();
            }
        }
        this.b.clear();
        if (z) {
            this.a = null;
        }
    }

    public void a(boolean z, String str) {
        try {
            JSONArray jSONArray = new JSONArray(str);
            if (jSONArray.length() > 0) {
                for (int i = 0; i < jSONArray.length(); i++) {
                    c cVar = this.b.get(jSONArray.getString(i));
                    if (cVar.d() != null) {
                        cVar.d().findViewById(com.iBookStar.utils.k.a(R.id.ym_sdk_mask, "ym_sdk_mask", "id")).setVisibility(z ? 4 : 0);
                    }
                }
                return;
            }
        } catch (Throwable th) {
            th.printStackTrace();
        }
        for (c cVar2 : this.b.values()) {
            if (cVar2.d() != null) {
                cVar2.d().findViewById(com.iBookStar.utils.k.a(R.id.ym_sdk_mask, "ym_sdk_mask", "id")).setVisibility(z ? 4 : 0);
            }
        }
    }

    public boolean a(f fVar) {
        if (fVar == null) {
            return false;
        }
        for (c cVar : this.b.values()) {
            if (cVar.e().y().equalsIgnoreCase(fVar.y())) {
                this.a.loadUrl(String.format("javascript:if(window.reloadAd){window.reloadAd('%s')}", fVar.y()));
                return true;
            }
        }
        return false;
    }

    public void b() {
        try {
            p.a("SdkAdsMgr", "vvvvvvvvvvvvvvvvvvv, onGlobalLayout begin");
            for (c cVar : this.b.values()) {
                if (cVar.d() != null) {
                    int height = cVar.d().getHeight();
                    if (height > 0) {
                        if (height > (cVar.l() ? f : e) && height != cVar.h()) {
                            cVar.a(height);
                            p.a("SdkAdsMgr", String.format("vvvvvvvvvvvvvvvvvvv, onGlobalLayout containerId=%s, height=%d", cVar.g(), Integer.valueOf(height)));
                            a(cVar.g(), (float) height);
                        }
                    }
                }
            }
            p.a("SdkAdsMgr", "vvvvvvvvvvvvvvvvvvv, onGlobalLayout end");
        } catch (Throwable th) {
            th.printStackTrace();
        }
    }

    public void b(String str) {
        try {
            JSONObject jSONObject = new JSONObject(str);
            this.c = (float) jSONObject.optDouble("x");
            this.d = (float) jSONObject.optDouble("width");
            for (c cVar : this.b.values()) {
                if (cVar.d() != null) {
                    if (cVar.b() >= this.c && cVar.b() < this.c + this.d) {
                        cVar.d().setTranslationY(cVar.c() * this.a.getScale());
                        cVar.b(true);
                    }
                }
            }
        } catch (Throwable th) {
            th.printStackTrace();
        }
    }

    public void c() {
        for (c cVar : this.b.values()) {
            c(cVar.g());
        }
    }

    @Override // com.iBookStar.a.j.i
    public void onAdClick(f fVar, View view) {
        d.a().b(fVar);
        this.a.setAdItem(fVar);
        w.a().a(new e(true));
    }

    @Override // com.iBookStar.a.j.i
    public void onAdClose(f fVar, View view) {
        CommonWebView commonWebView = this.a;
        if (commonWebView != null && !commonWebView.isFinished()) {
            a(b(fVar));
        }
    }

    @Override // com.iBookStar.a.j.i
    public void onAdLoadFail(f fVar) {
        CommonWebView commonWebView = this.a;
        if (commonWebView != null && !commonWebView.isFinished()) {
            b(c(fVar));
        }
    }

    @Override // com.iBookStar.a.j.i
    public void onAdLoadSuccess(f fVar, View view, int i, boolean z) {
        CommonWebView commonWebView;
        if (view != null && (commonWebView = this.a) != null && !commonWebView.isFinished()) {
            c b2 = b(fVar);
            a(b2, view, i, z);
            c(b2);
        }
    }

    @Override // com.iBookStar.a.j.i
    public void onAdPreLoad(f fVar, View view, int i, boolean z) {
        CommonWebView commonWebView;
        if (view != null && (commonWebView = this.a) != null && !commonWebView.isFinished()) {
            a(b(fVar), view, i, z);
        }
    }

    @Override // com.iBookStar.a.j.i
    public void onAdRenderFail(f fVar) {
        CommonWebView commonWebView = this.a;
        if (commonWebView != null && !commonWebView.isFinished()) {
            b(c(fVar));
        }
    }

    @Override // com.iBookStar.a.j.i
    public void onAdRenderSuccess(f fVar, View view, int i, boolean z) {
        CommonWebView commonWebView;
        if (view != null && (commonWebView = this.a) != null && !commonWebView.isFinished()) {
            c b2 = b(fVar);
            a(b2, view, i, z);
            c(b2);
        }
    }

    @Override // com.iBookStar.a.j.i
    public void onAdShow(f fVar, View view) {
        d.a().d(fVar);
    }
}