package com.bytedance.sdk.component.adexpress.dynamic.dynamicview;

import android.content.Context;
import android.text.TextUtils;
import android.view.ViewGroup;
import android.widget.TextView;
import java.text.DecimalFormat;
import java.util.ArrayList;
import org.json.JSONArray;
import org.json.JSONException;
import tv.danmaku.ijk.media.player.IjkMediaMeta;

/* JADX INFO: loaded from: classes.dex */
public class hi extends ajl {
    public hi(Context context, DynamicRootView dynamicRootView, com.bytedance.sdk.component.adexpress.dynamic.yz.wu wuVar) {
        super(context, dynamicRootView, wuVar);
        this.wu += 6;
        if (this.duv.mon()) {
            com.bytedance.sdk.component.adexpress.ajl.fm fmVar = new com.bytedance.sdk.component.adexpress.ajl.fm(context, this.duv.wsy(), this.duv.jnr(), 1, this.duv.wu());
            this.fhx = fmVar;
            fmVar.setMaxLines(1);
        } else {
            TextView textView = new TextView(context);
            this.fhx = textView;
            textView.setIncludeFontPadding(false);
        }
        this.fhx.setTag(Integer.valueOf(getClickArea()));
        addView(this.fhx, getWidgetLayoutParams());
    }

    private boolean fm() {
        DynamicRootView dynamicRootView = this.onz;
        return (dynamicRootView == null || dynamicRootView.getRenderRequest() == null || this.onz.getRenderRequest().vt() == 4) ? false : true;
    }

    private void ku() {
        if (this.fhx instanceof com.bytedance.sdk.component.adexpress.ajl.fm) {
            String text = getText();
            ArrayList arrayList = new ArrayList();
            try {
                JSONArray jSONArray = new JSONArray(text);
                for (int i10 = 0; i10 < jSONArray.length(); i10++) {
                    arrayList.add(jSONArray.optString(i10));
                }
            } catch (JSONException unused) {
                arrayList.add(text);
            }
            ((com.bytedance.sdk.component.adexpress.ajl.fm) this.fhx).setMaxLines(1);
            ((com.bytedance.sdk.component.adexpress.ajl.fm) this.fhx).setTextColor(this.duv.wsy());
            ((com.bytedance.sdk.component.adexpress.ajl.fm) this.fhx).setTextSize(this.duv.jnr());
            ((com.bytedance.sdk.component.adexpress.ajl.fm) this.fhx).setAnimationText(arrayList);
            ((com.bytedance.sdk.component.adexpress.ajl.fm) this.fhx).setAnimationType(this.duv.zan());
            ((com.bytedance.sdk.component.adexpress.ajl.fm) this.fhx).setAnimationDuration(this.duv.bx() * 1000);
            ((com.bytedance.sdk.component.adexpress.ajl.fm) this.fhx).fm();
        }
    }

    private void vt() {
        int iFm;
        if (b.r(this.dsz, "source") || b.r(this.dsz, IjkMediaMeta.IJKM_KEY_TITLE) || b.r(this.dsz, "text_star")) {
            int[] iArrRo = com.bytedance.sdk.component.adexpress.dynamic.jnr.ku.ro(this.duv.ajl(), this.duv.jnr(), true);
            int iFm2 = (int) com.bytedance.sdk.component.adexpress.yz.wsy.fm(getContext(), this.duv.ro());
            int iFm3 = (int) com.bytedance.sdk.component.adexpress.yz.wsy.fm(getContext(), this.duv.lb());
            int iFm4 = (int) com.bytedance.sdk.component.adexpress.yz.wsy.fm(getContext(), this.duv.yz());
            int iFm5 = (int) com.bytedance.sdk.component.adexpress.yz.wsy.fm(getContext(), this.duv.fm());
            int iMin = Math.min(iFm2, iFm5);
            if (b.r(this.dsz, "source") && (iFm = ((this.wu - ((int) com.bytedance.sdk.component.adexpress.yz.wsy.fm(getContext(), this.duv.jnr()))) - iFm2) - iFm5) > 1 && iFm <= iMin * 2) {
                int i10 = iFm / 2;
                this.fhx.setPadding(iFm3, iFm2 - i10, iFm4, iFm5 - (iFm - i10));
                return;
            }
            int i11 = (((iArrRo[1] + iFm2) + iFm5) - this.wu) - 2;
            if (i11 <= 1) {
                return;
            }
            if (i11 <= iMin * 2) {
                int i12 = i11 / 2;
                this.fhx.setPadding(iFm3, iFm2 - i12, iFm4, iFm5 - (i11 - i12));
            } else if (i11 > iFm2 + iFm5) {
                final int i13 = (i11 - iFm2) - iFm5;
                this.fhx.setPadding(iFm3, 0, iFm4, 0);
                if (i13 <= ((int) com.bytedance.sdk.component.adexpress.yz.wsy.fm(getContext(), 1.0f)) + 1) {
                    ((TextView) this.fhx).setTextSize(this.duv.jnr() - 1.0f);
                } else if (i13 <= (((int) com.bytedance.sdk.component.adexpress.yz.wsy.fm(getContext(), 1.0f)) + 1) * 2) {
                    ((TextView) this.fhx).setTextSize(this.duv.jnr() - 2.0f);
                } else {
                    post(new Runnable() { // from class: com.bytedance.sdk.component.adexpress.dynamic.dynamicview.hi.1
                        @Override // java.lang.Runnable
                        public void run() {
                            try {
                                ViewGroup.LayoutParams layoutParams = hi.this.fhx.getLayoutParams();
                                hi hiVar = hi.this;
                                layoutParams.height = hiVar.wu + i13;
                                hiVar.fhx.setLayoutParams(layoutParams);
                                hi.this.fhx.setTranslationY(-i13);
                                ((ViewGroup) hi.this.fhx.getParent()).setClipChildren(false);
                                ((ViewGroup) hi.this.fhx.getParent().getParent()).setClipChildren(false);
                            } catch (Throwable unused) {
                            }
                        }
                    });
                }
            } else if (iFm2 > iFm5) {
                this.fhx.setPadding(iFm3, iFm2 - (i11 - iMin), iFm4, iFm5 - iMin);
            } else {
                this.fhx.setPadding(iFm3, iFm2 - iMin, iFm4, iFm5 - (i11 - iMin));
            }
        }
        if (b.r(this.dsz, "fillButton")) {
            this.fhx.setTextAlignment(2);
            ((TextView) this.fhx).setGravity(17);
        }
    }

    @Override // com.bytedance.sdk.component.adexpress.dynamic.dynamicview.ajl, com.bytedance.sdk.component.adexpress.dynamic.dynamicview.pkk
    public boolean ef() {
        int i10;
        double d10;
        super.ef();
        if (TextUtils.isEmpty(getText())) {
            this.fhx.setVisibility(4);
            return true;
        }
        if (this.duv.mon()) {
            ku();
            return true;
        }
        ((TextView) this.fhx).setText(this.duv.ajl());
        ((TextView) this.fhx).setTextDirection(5);
        this.fhx.setTextAlignment(this.duv.wu());
        ((TextView) this.fhx).setTextColor(this.duv.wsy());
        ((TextView) this.fhx).setTextSize(this.duv.jnr());
        if (this.duv.maa()) {
            int iLse = this.duv.lse();
            if (iLse > 0) {
                ((TextView) this.fhx).setLines(iLse);
                ((TextView) this.fhx).setEllipsize(TextUtils.TruncateAt.END);
            }
        } else {
            ((TextView) this.fhx).setMaxLines(1);
            ((TextView) this.fhx).setGravity(17);
            ((TextView) this.fhx).setEllipsize(TextUtils.TruncateAt.END);
        }
        com.bytedance.sdk.component.adexpress.dynamic.yz.wu wuVar = this.dsz;
        if (wuVar != null && wuVar.vt() != null) {
            if (com.bytedance.sdk.component.adexpress.yz.ro() && fm() && (b.r(this.dsz, "text_star") || b.r(this.dsz, "score-count") || b.r(this.dsz, "score-count-type-1") || b.r(this.dsz, "score-count-type-2"))) {
                setVisibility(8);
                return true;
            }
            if (b.r(this.dsz, "score-count") || b.r(this.dsz, "score-count-type-2")) {
                try {
                    try {
                        i10 = Integer.parseInt(getText());
                    } catch (NumberFormatException unused) {
                        i10 = -1;
                    }
                    if (i10 < 0) {
                        if (com.bytedance.sdk.component.adexpress.yz.ro()) {
                            setVisibility(8);
                            return true;
                        }
                        this.fhx.setVisibility(0);
                    }
                    if (TextUtils.equals(this.dsz.vt().ro(), "score-count-type-2")) {
                        ((TextView) this.fhx).setText(String.format(new DecimalFormat("(###,###,###)").format(i10), Integer.valueOf(i10)));
                        ((TextView) this.fhx).setGravity(17);
                        return true;
                    }
                    fm((TextView) this.fhx, i10, getContext(), "tt_comment_num");
                } catch (Exception unused2) {
                }
            } else if (b.r(this.dsz, "text_star")) {
                try {
                    d10 = Double.parseDouble(getText());
                } catch (Exception unused3) {
                    d10 = -1.0d;
                }
                if (d10 < 0.0d || d10 > 5.0d) {
                    if (com.bytedance.sdk.component.adexpress.yz.ro()) {
                        setVisibility(8);
                        return true;
                    }
                    this.fhx.setVisibility(0);
                }
                ((TextView) this.fhx).setIncludeFontPadding(false);
                ((TextView) this.fhx).setText(String.format("%.1f", Double.valueOf(d10)));
            } else if (TextUtils.equals("privacy-detail", this.dsz.vt().ro())) {
                ((TextView) this.fhx).setText("Permission list | Privacy policy");
            } else if (b.r(this.dsz, "development-name")) {
                ((TextView) this.fhx).setText(com.bytedance.sdk.component.utils.maa.fm(com.bytedance.sdk.component.adexpress.yz.fm(), "tt_text_privacy_development") + getText());
            } else if (b.r(this.dsz, "app-version")) {
                ((TextView) this.fhx).setText(com.bytedance.sdk.component.utils.maa.fm(com.bytedance.sdk.component.adexpress.yz.fm(), "tt_text_privacy_app_version") + getText());
            } else {
                ((TextView) this.fhx).setText(getText());
            }
            this.fhx.setTextAlignment(this.duv.wu());
            ((TextView) this.fhx).setGravity(this.duv.ef());
            if (com.bytedance.sdk.component.adexpress.yz.ro()) {
                vt();
            }
        }
        return true;
    }

    public String getText() {
        String strAjl = this.duv.ajl();
        if (TextUtils.isEmpty(strAjl)) {
            if (!com.bytedance.sdk.component.adexpress.yz.ro() && b.r(this.dsz, "text_star")) {
                strAjl = "5";
            }
            if (!com.bytedance.sdk.component.adexpress.yz.ro() && b.r(this.dsz, "score-count")) {
                strAjl = "6870";
            }
        }
        return (b.r(this.dsz, IjkMediaMeta.IJKM_KEY_TITLE) || b.r(this.dsz, "subtitle")) ? strAjl.replace("\n", "") : strAjl;
    }

    public void fm(TextView textView, int i10, Context context, String str) {
        textView.setText("(" + String.format(com.bytedance.sdk.component.utils.maa.fm(context, str), Integer.valueOf(i10)) + ")");
        if (i10 == -1) {
            textView.setVisibility(8);
        }
    }
}
