package com.bytedance.android.livesdk.toolbar;

import X.04n;
import X.0S6;
import X.0aN;
import X.155;
import X.15B;
import X.8eL;
import X.C1083FvQ;
import X.H1C;
import X.H1F;
import X.H1H;
import X.H1J;
import X.H1L;
import X.HFR;
import X.M12;
import android.content.Context;
import android.content.MutableContextWrapper;
import android.view.LayoutInflater;
import android.view.View;
import com.bytedance.android.live.toolbar.IToolbarService;
import com.bytedance.android.livesdk.livesetting.performance.LiveLayoutPreloadSetting;
import com.bytedance.android.livesdk.livesetting.performance.degrade.LiveToolBarOptSetting;
import com.bytedance.android.livesdk.livesetting.performance.degrade.LiveToolBarPreloadOptSetting;
import com.bytedance.covode.number.Covode;
import com.bytedance.ies.sdk.datachannel.DataChannel;
import java.util.Stack;
import kotlin.h.b.n;

public class ToolbarService implements IToolbarService {
    static {
        Covode.recordClassIndex(20949);
    }

    public void onInit() {
    }

    public Class<LiveAudienceToolbarWidget> audienceToolbarWidget() {
        return LiveAudienceToolbarWidget.class;
    }

    public Class<LiveBroadcastToolbarWidget> broadcastToolbarWidget() {
        return LiveBroadcastToolbarWidget.class;
    }

    public Class<LiveToolbarWidget> toolbarWidget() {
        return LiveToolbarWidget.class;
    }

    public void preloadBroadcastToolbarWidget() {
        0S6.LJFF.LIZ(2131562107);
    }

    public void releaseToolbarView() {
        H1C.LIZ.clear();
        H1C.LIZIZ = null;
        H1C.LIZJ = null;
    }

    public void preloadAudienceToolbarWidget() {
        if (!LiveToolBarOptSetting.INSTANCE.enable()) {
            0S6.LJFF.LIZ(2131562108);
        }
    }

    public void preloadToolbarButton(Context context) {
        if (LiveToolBarPreloadOptSetting.INSTANCE.enable()) {
            String LIZ = 0aN.LIZ();
            n.LIZIZ(LIZ, "");
            H1F.LIZIZ = LIZ;
            if (context != null) {
                8eL.LIZJ().submit(new H1J(context));
            }
        }
    }

    public 155 toolbarManager(DataChannel dataChannel) {
        Object obj;
        if (LiveToolBarOptSetting.INSTANCE.enable()) {
            Object obj2 = null;
            if (dataChannel != null) {
                obj = dataChannel.LIZIZ(C1083FvQ.class);
            } else {
                obj = null;
            }
            if (n.LIZ(obj, true)) {
                if (dataChannel != null) {
                    obj2 = dataChannel.LIZIZ(HFR.class);
                }
                if (n.LIZ(obj2, false)) {
                    return H1L.LIZ;
                }
            }
        }
        return H1H.LIZ;
    }

    public void preloadToolbarView(Context context, int i, 15B r6) {
        int i2;
        M12.LIZ(r6);
        M12.LIZ(r6);
        if (LiveLayoutPreloadSetting.INSTANCE.enable() && context != null) {
            H1C.LIZIZ = new 04n(new MutableContextWrapper(context));
            H1C.LIZJ = LayoutInflater.from(new MutableContextWrapper(context));
            Stack<View> stack = H1C.LIZ.get(r6);
            if (stack != null) {
                for (View view : stack) {
                    n.LIZIZ(view, "");
                    Context context2 = view.getContext();
                    if (!(context2 instanceof MutableContextWrapper)) {
                        context2 = null;
                    }
                    MutableContextWrapper mutableContextWrapper = (MutableContextWrapper) context2;
                    if (mutableContextWrapper != null) {
                        mutableContextWrapper.setBaseContext(context);
                    }
                }
            }
            Stack stack2 = H1C.LIZ.get(r6);
            if (stack2 != null) {
                i2 = stack2.size();
            } else {
                H1C.LIZ.put(r6, new Stack());
                i2 = 0;
            }
            int i3 = i - i2;
            for (int i4 = 0; i4 < i3; i4++) {
                H1C.LIZLLL.LIZ(r6);
            }
        }
    }
}
