package com.ss.android.ugc.aweme.comment.widgets;

import X.0CB;
import X.0CH;
import X.0CM;
import X.2Pr;
import X.2ha;
import X.33g;
import X.4RU;
import X.6Is;
import X.7hc;
import X.7he;
import X.9xA;
import X.C0339K0c;
import X.C0762KGj;
import X.C2555Kug;
import X.C2624Kvn;
import X.C3236LDn;
import X.C3290LFp;
import X.C4939Ls2;
import X.C4950LsD;
import X.Crj;
import X.Cwu;
import X.HeD;
import X.LFK;
import X.LFW;
import X.LG9;
import X.LGD;
import X.LGE;
import X.LRV;
import X.M12;
import X.OCa;
import X.PMk;
import X.PMp;
import X.TSt;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.bytedance.covode.number.Covode;
import com.ss.android.ugc.aweme.arch.widgets.base.DataCenter;
import com.ss.android.ugc.aweme.feed.model.Aweme;
import com.ss.android.ugc.aweme.feed.model.AwemeRawAd;
import java.util.Map;
import kotlin.h.b.n;
import org.json.JSONException;
import org.json.JSONObject;

public final class NewCommentAdWidget extends BaseCommentWidget implements View.OnClickListener, 0CM<33g>, 6Is {
    public static final /* synthetic */ PMp[] LJIIIIZZ;
    public static final LGD LJIIIZ = new LGD((byte) 0);
    public final LG9 LJIIJ = LIZ(2131363479);
    public final LG9 LJIIJJI = LIZ(2131363478);
    public final LG9 LJIIL = LIZ(2131363476);
    public final LG9 LJIILIIL = LIZ(2131363480);
    public final LG9 LJIILJJIL = LIZ(2131363475);
    public final Crj LJIILL = 7he.LIZ(7hc.NONE, LGE.LIZ);
    public boolean LJIILLIIL = true;
    public boolean LJIIZILJ;
    public int LJIJ;
    public boolean LJIJI;
    public int LJIJJ;
    public final C4939Ls2<2Pr> LJIJJLI;

    private final LinearLayout LJIIJJI() {
        return (LinearLayout) this.LJIIJ.LIZ(this, LJIIIIZZ[0]);
    }

    private final View LJIIL() {
        return this.LJIILJJIL.LIZ(this, LJIIIIZZ[4]);
    }

    public final int LIZJ() {
        return 2131562351;
    }

    public final void onStateChanged(0CH r1, 0CB r2) {
        super.onStateChanged(r1, r2);
    }

    public final void onDestroy() {
        super.onDestroy();
    }

    public final void onPause() {
        NewCommentAdWidget.super.onPause();
        LJIILJJIL();
    }

    public final void onResume() {
        NewCommentAdWidget.super.onResume();
        LJIILIIL();
    }

    private final void LJIILL() {
        LinearLayout LJIIJJI2 = LJIIJJI();
        Context context = this.LIZIZ;
        n.LIZIZ(context, "");
        LIZ(LJIIJJI2, context.getResources().getDimensionPixelOffset(2131165266), 0, false);
    }

    private final void LJIILLIIL() {
        LinearLayout LJIIJJI2 = LJIIJJI();
        Context context = this.LIZIZ;
        n.LIZIZ(context, "");
        LIZ(LJIIJJI2, context.getResources().getDimensionPixelOffset(2131165266), 300, false);
    }

    public final void LJIIJ() {
        LJIIJJI().setOnClickListener(this);
        LJIIL().setOnClickListener(this);
        LJIIL().setAlpha(0.5f);
    }

    public final void onCreate() {
        super.onCreate();
        DataCenter dataCenter = this.LJ;
        dataCenter.LIZ("comment_ad_struct", this, true);
        dataCenter.LIZ("comment_ad_view_state", this, true);
    }

    private final void LJIILIIL() {
        if (LJFF() && LJ().isAppAd() && !C3290LFp.LJJLL(LJ()) && !this.LJIIZILJ) {
            this.LJIIZILJ = true;
        }
    }

    private final void LJIILJJIL() {
        if (LJFF() && LJ().isAppAd() && LJ().getAwemeRawAd() != null && this.LJIIZILJ) {
            this.LJIIZILJ = false;
        }
    }

    static {
        Class<NewCommentAdWidget> cls = NewCommentAdWidget.class;
        Covode.recordClassIndex(57755);
        LJIIIIZZ = new PMp[]{new PMk(cls, "mCommentAdLayout", "getMCommentAdLayout()Landroid/widget/LinearLayout;", 0), new PMk(cls, "mCommentAdSourceTv", "getMCommentAdSourceTv()Landroid/widget/TextView;", 0), new PMk(cls, "mCommentAdDesTv", "getMCommentAdDesTv()Landroid/widget/TextView;", 0), new PMk(cls, "mCommentAdUserIv", "getMCommentAdUserIv()Lcom/ss/android/ugc/aweme/base/ui/RemoteImageView;", 0), new PMk(cls, "mCommentAdCloseBtn", "getMCommentAdCloseBtn()Landroid/view/View;", 0)};
    }

    public final /* synthetic */ void onChanged(Object obj) {
        onChanged((33g) obj);
    }

    private final void LIZIZ(int i) {
        if (i == 0) {
            if (this.LJIJ != 0) {
                this.LJ.LIZIZ("comment_shown", this);
            }
        } else if (i > 0) {
            this.LJ.LIZ("comment_shown", this, true);
        }
        this.LJIJ = i;
    }

    public NewCommentAdWidget(C4939Ls2<2Pr> ls2) {
        M12.LIZ((Object) ls2);
        this.LJIJJLI = ls2;
    }

    public final void onClick(View view) {
        ViewGroup.LayoutParams layoutParams;
        AwemeRawAd awemeRawAd;
        if (view != null) {
            layoutParams = view.getLayoutParams();
        } else {
            layoutParams = null;
        }
        if (!(layoutParams instanceof ViewGroup.MarginLayoutParams)) {
            layoutParams = null;
        }
        ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) layoutParams;
        if (marginLayoutParams != null && marginLayoutParams.bottomMargin >= 0 && LJFF() && (awemeRawAd = LJ().getAwemeRawAd()) != null) {
            n.LIZIZ(awemeRawAd, "");
            int id = view.getId();
            if (id == 2131363479) {
                String type = awemeRawAd.getType();
                if (type != null && type.length() != 0) {
                    Aweme LJ = LJ();
                    if (LJ.isAd()) {
                        C0762KGj LIZ = C0339K0c.LIZ("comment_end_ad", "click", LJ.getAwemeRawAd());
                        LIZ.LIZIZ("refer", "button");
                        LIZ.LIZ("anchor_id", C3236LDn.LIZIZ(LJ));
                        LIZ.LIZ("room_id", C3236LDn.LIZ(LJ));
                        LIZ.LIZIZ();
                        AwemeRawAd awemeRawAd2 = LJ.getAwemeRawAd();
                        if (awemeRawAd2 != null) {
                            LFW.LIZ.LIZ("click", awemeRawAd2.getClickTrackUrlList(), awemeRawAd2.getCreativeId(), awemeRawAd2.getLogExtra(), (C4950LsD<? super C2624Kvn, ? super Boolean, ? extends C2624Kvn>) new LFK(awemeRawAd2));
                        }
                    }
                    if (C2555Kug.LIZ(this.LIZIZ, LJ(), 6, (4RU) this.LJIILL.getValue())) {
                        this.LJIJJLI.invoke();
                    }
                }
            } else if (id == 2131363475) {
                this.LJIILLIIL = false;
                Context context = this.LIZIZ;
                JSONObject LIZ2 = C3236LDn.LIZ(context, awemeRawAd, true, (Map<String, String>) null);
                if (!TextUtils.isEmpty("button")) {
                    try {
                        LIZ2.put("refer", "button");
                    } catch (JSONException e) {
                        TSt.LIZ(e);
                    }
                }
                C3236LDn.LIZIZ(context, "close", awemeRawAd, LIZ2);
                C0762KGj LIZ3 = C0339K0c.LIZ("comment_end_ad", "close", awemeRawAd);
                LIZ3.LIZIZ("refer", "button");
                LIZ3.LIZJ();
                LJIILLIIL();
            }
        }
    }

    public final void LIZ(33g r7) {
        int i;
        int i2;
        9xA r4;
        Aweme aweme;
        super.onChanged(r7);
        if (r7 != null) {
            String str = r7.LIZ;
            boolean z = false;
            switch (str.hashCode()) {
                case -1106422991:
                    if (str.equals("comment_shown")) {
                        boolean LIZ = r7.LIZ();
                        if (LIZ == null) {
                            LIZ = false;
                        }
                        if (n.LIZ(LIZ, 0) && (i = this.LJIJ) > 0 && this.LJIJI && (i2 = this.LJIJJ) < i) {
                            int i3 = i2 + 1;
                            this.LJIJJ = i3;
                            if (i3 == i && this.LJIILLIIL) {
                                LIZ(LJIIJJI(), 2ha.LIZ(16.0d), 300, true);
                                return;
                            }
                            return;
                        }
                        return;
                    }
                    return;
                case 566175283:
                    if (str.equals("comment_ad_view_state")) {
                        boolean LIZ2 = r7.LIZ();
                        if (LIZ2 == null) {
                            LIZ2 = false;
                        }
                        if (n.LIZ(LIZ2, 0)) {
                            LJIILL();
                            return;
                        } else if (n.LIZ(LIZ2, 1)) {
                            LJIILLIIL();
                            return;
                        } else {
                            return;
                        }
                    } else {
                        return;
                    }
                case 584899985:
                    if (str.equals("comment_ad_struct") && (r4 = (9xA) r7.LIZ()) != null) {
                        LIZIZ(r4.getShowButtonNumber());
                        LG9 lg9 = this.LJIIJJI;
                        PMp[] pMpArr = LJIIIIZZ;
                        ((TextView) lg9.LIZ(this, pMpArr[1])).setText(r4.getSource());
                        ((TextView) this.LJIIL.LIZ(this, pMpArr[2])).setText(r4.getTitle());
                        OCa.LIZ(this.LJIILIIL.LIZ(this, pMpArr[3]), r4.getAvatarIcon());
                        GradientDrawable gradientDrawable = new GradientDrawable();
                        gradientDrawable.setCornerRadius(HeD.LIZIZ(this.LIZIZ, 4.0f));
                        gradientDrawable.setColor(Color.parseColor(C3290LFp.LJJLIIIJILLIZJL(LJ())));
                        LJIIJJI().setBackground(gradientDrawable);
                        return;
                    }
                    return;
                case 2016314694:
                    if (str.equals("comment_aweme_and_params")) {
                        this.LJIILLIIL = true;
                        this.LJIJJ = 0;
                        LIZIZ(0);
                        LJIILL();
                        Cwu cwu = (Cwu) r7.LIZ();
                        if (cwu != null && (aweme = (Aweme) cwu.getFirst()) != null) {
                            AwemeRawAd awemeRawAd = aweme.getAwemeRawAd();
                            if (awemeRawAd != null) {
                                z = awemeRawAd.isCommentAreaSwitch();
                            }
                            this.LJIJI = z;
                            LJIILJJIL();
                            LJIILIIL();
                            return;
                        }
                        return;
                    }
                    return;
                default:
                    return;
            }
        }
    }

    private final void LIZ(View view, int i, int i2, boolean z) {
        ViewGroup.LayoutParams layoutParams;
        boolean z2;
        ViewGroup.MarginLayoutParams marginLayoutParams = null;
        if (view != null) {
            layoutParams = view.getLayoutParams();
        } else {
            layoutParams = null;
        }
        if (layoutParams instanceof ViewGroup.MarginLayoutParams) {
            marginLayoutParams = layoutParams;
        }
        ViewGroup.MarginLayoutParams marginLayoutParams2 = marginLayoutParams;
        if (marginLayoutParams2 != null) {
            int i3 = marginLayoutParams2.bottomMargin;
            if (i3 >= 0) {
                z2 = true;
            } else {
                z2 = false;
            }
            if (z) {
                if (!z2) {
                    C3236LDn.LIZ(this.LIZIZ, LJ().getAwemeRawAd());
                    C0339K0c.LIZ("comment_end_ad", "othershow", LJ().getAwemeRawAd()).LIZJ();
                    LRV.LIZ(view, i3, i, i2).start();
                }
            } else if (z2) {
                LRV.LIZ(view, i3, i, i2).start();
            }
        }
    }
}
