package com.bytedance.android.livesdk.broadcast.preview.widget;

import X.0CB;
import X.0CH;
import X.1MZ;
import X.2K7;
import X.6Is;
import X.7vl;
import X.C1377G0k;
import X.C1408G1p;
import X.C1409G1q;
import X.C1410G1r;
import X.C1411G1s;
import X.C2438GcB;
import X.Crj;
import X.G9S;
import android.text.SpannableString;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.text.style.ImageSpan;
import android.view.View;
import com.bytedance.android.livesdk.livesetting.broadcast.LiveBroadcastPreviewSetting;
import com.bytedance.covode.number.Covode;
import com.bytedance.ies.sdk.datachannel.DataChannel;
import com.bytedance.ies.sdk.widgets.LiveWidget;
import kotlin.h.b.n;

public final class PreviewTitleWidget extends LiveWidget implements 6Is {
    public static final C1411G1s LIZLLL = new C1411G1s((byte) 0);
    public 1MZ LIZ;
    public final TextWatcher LIZIZ = new C1410G1r(this);
    public final Long LIZJ;
    public final Crj LJ = 7vl.LIZ(new G9S(this));

    static {
        Covode.recordClassIndex(12329);
    }

    public final ImageSpan LIZ() {
        return (ImageSpan) this.LJ.getValue();
    }

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

    public static boolean LIZIZ() {
        try {
            return 2K7.LIZ.LIZJ();
        } catch (Exception unused) {
            return false;
        }
    }

    public final int getLayoutId() {
        if (LiveBroadcastPreviewSetting.INSTANCE.enableV1Style() || LiveBroadcastPreviewSetting.INSTANCE.enableV2Style()) {
            return 2131562226;
        }
        return 2131562225;
    }

    public final void onCreate() {
        super.onCreate();
        View view = getView();
        if (!(view instanceof 1MZ)) {
            view = null;
        }
        1MZ r1 = (1MZ) view;
        if (r1 != null) {
            this.LIZ = r1;
            DataChannel dataChannel = this.dataChannel;
            if (dataChannel != null) {
                dataChannel.LIZ((0CH) this, C2438GcB.class, new C1408G1p(this));
            }
            DataChannel dataChannel2 = this.dataChannel;
            if (dataChannel2 != null) {
                dataChannel2.LIZIZ((0CH) this, C1377G0k.class, new C1409G1q(this));
            }
        }
    }

    public static final /* synthetic */ 1MZ LIZ(PreviewTitleWidget previewTitleWidget) {
        1MZ r1 = previewTitleWidget.LIZ;
        if (r1 == null) {
            n.LIZ("");
        }
        return r1;
    }

    public PreviewTitleWidget(Long l) {
        this.LIZJ = l;
    }

    public final void LIZ(String str) {
        if (str != null && str.length() != 0) {
            1MZ r0 = this.LIZ;
            if (r0 == null) {
                n.LIZ("");
            }
            if (r0.isFocused()) {
                1MZ r02 = this.LIZ;
                if (r02 == null) {
                    n.LIZ("");
                }
                if (!TextUtils.isEmpty(String.valueOf(r02.getText()))) {
                    1MZ r03 = this.LIZ;
                    if (r03 == null) {
                        n.LIZ("");
                    }
                    r03.setText(str);
                    return;
                }
            }
            SpannableString spannableString = new SpannableString(str + ' ');
            spannableString.setSpan(LIZ(), str.length(), str.length() + 1, 17);
            1MZ r04 = this.LIZ;
            if (r04 == null) {
                n.LIZ("");
            }
            r04.setText(spannableString);
        }
    }
}
