package com.bytedance.ies.sdk.widgets;

import X.0CB;
import X.0CH;
import X.6Is;
import X.C2381GbG;
import X.C2888GjR;
import X.GSF;
import X.Mjy;
import X.Pj3;
import android.content.Context;
import android.view.View;
import com.bytedance.android.widget.Widget;
import com.bytedance.covode.number.Covode;
import com.bytedance.ies.sdk.datachannel.DataChannel;
import com.bytedance.ies.sdk.datachannel.DataChannelGlobal;

public abstract class LiveWidget extends Widget implements ILayeredWidget, 6Is {
    public Mjy compositeDisposable;
    public DataChannel dataChannel;
    public LayeredElementContext layeredElementContext;
    public Pj3 lifecycleTransformer;
    public RecyclableWidgetManager subWidgetManager;

    static {
        Covode.recordClassIndex(30525);
    }

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

    public final <T> Pj3<T> getAutoUnbindTransformer() {
        return this.lifecycleTransformer;
    }

    public Context getContext() {
        return this.context;
    }

    public LayeredElementContext getLayeredElementContext() {
        return this.layeredElementContext;
    }

    public DataChannel provideDataChannel() {
        return this.dataChannel;
    }

    public void enableSubWidgetManager() {
        enableSubWidgetManager((C2888GjR) null, (FluencyOpt) null);
    }

    public void onDetachWidget() {
        if (!(this instanceof IUnLoadWidget)) {
            if (this.widgetCallback != null) {
                this.widgetCallback.unloadWidget(this);
            }
            RecyclableWidgetManager recyclableWidgetManager = this.subWidgetManager;
            if (recyclableWidgetManager != null && recyclableWidgetManager.isSubWidgetManager) {
                this.subWidgetManager.detachWidget();
            }
        }
    }

    public void hide() {
        LayeredElementContext layeredElementContext2 = this.layeredElementContext;
        if (layeredElementContext2 == null || layeredElementContext2.getConstraintPropertyById(getId()) == null) {
            super.hide();
            return;
        }
        ConstraintProperty constraintPropertyById = this.layeredElementContext.getConstraintPropertyById(getId());
        if (constraintPropertyById != null && constraintPropertyById.visibility() == 0) {
            constraintPropertyById.visibility(8);
            if (this.widgetCallback != null) {
                this.widgetCallback.onHide(this);
            }
        }
    }

    public void onCreate() {
        Mjy mjy = this.compositeDisposable;
        if (mjy != null) {
            mjy.dispose();
        }
        this.compositeDisposable = new Mjy();
        this.lifecycleTransformer = new Pj3(this.compositeDisposable);
        super.onCreate();
        this.dataChannel = GSF.LIZ(this.widgetCallback.getFragment());
    }

    public void onDestroy() {
        super.onDestroy();
        if (this.widgetCallback != null) {
            this.widgetCallback.removeAllMessages(this);
        }
        onDetachWidget();
        DataChannel dataChannel2 = this.dataChannel;
        if (dataChannel2 != null) {
            dataChannel2.LIZIZ((Object) this);
        }
        DataChannelGlobal.LIZLLL.LIZIZ((Object) this);
        this.compositeDisposable.dispose();
        RecyclableWidgetManager recyclableWidgetManager = this.subWidgetManager;
        if (!(recyclableWidgetManager == null || recyclableWidgetManager.parentFragment == null)) {
            this.subWidgetManager.parentFragment.getLifecycle().LIZIZ(this.subWidgetManager);
        }
        this.subWidgetManager = null;
    }

    public void show() {
        LayeredElementContext layeredElementContext2 = this.layeredElementContext;
        if (layeredElementContext2 == null || layeredElementContext2.getConstraintPropertyById(getId()) == null) {
            super.show();
            return;
        }
        ConstraintProperty constraintPropertyById = this.layeredElementContext.getConstraintPropertyById(getId());
        if (constraintPropertyById != null && constraintPropertyById.visibility() == 8) {
            constraintPropertyById.visibility(0);
            if (this.widgetCallback != null) {
                this.widgetCallback.onShow(this);
            }
        }
    }

    public void setLayeredElementContext(LayeredElementContext layeredElementContext2) {
        this.layeredElementContext = layeredElementContext2;
    }

    public final <T extends View> T findViewById(int i) {
        return getView().findViewById(i);
    }

    public void onVisibilityToUser(boolean z) {
        RecyclableWidgetManager recyclableWidgetManager = this.subWidgetManager;
        if (recyclableWidgetManager != null && recyclableWidgetManager.isSubWidgetManager) {
            this.subWidgetManager.onVisibility(z);
        }
    }

    public void setWidgetCallback(C2381GbG gbG) {
        super.setWidgetCallback(gbG);
        if (gbG != null) {
            this.dataChannel = GSF.LIZ(gbG.getFragment());
        }
    }

    public <T> void onCustomInfoCallBack(T t) {
        RecyclableWidgetManager recyclableWidgetManager = this.subWidgetManager;
        if (recyclableWidgetManager != null && recyclableWidgetManager.isSubWidgetManager) {
            this.subWidgetManager.onCustomInfoCallBack(t.getClass(), t);
        }
    }

    public void enableSubWidgetManager(C2888GjR gjR, FluencyOpt fluencyOpt) {
        if (this.subWidgetManager == null) {
            RecyclableWidgetManager of = RecyclableWidgetManager.of(this.widgetCallback.getFragment(), getView(), false, (IWidgetProvider) LiveWidgetProvider.getInstance(), fluencyOpt);
            this.subWidgetManager = of;
            of.mWidgetCreateTimeListener = gjR;
            this.subWidgetManager.isSubWidgetManager = true;
        }
    }
}
