package com.bytedance.android.livesdk.chatroom.viewmodule;

import X.0CB;
import X.0CH;
import X.0UO;
import X.0ZZ;
import X.0b0;
import X.0cm;
import X.4kw;
import X.4kx;
import X.6Is;
import X.C1059Fv2;
import X.C1064Fv7;
import X.C2108GSn;
import X.C2109GSo;
import X.C2111GSq;
import X.C2115GSu;
import X.C2675Gg0;
import X.Kek;
import X.Mjy;
import android.content.Context;
import android.content.res.Resources;
import android.net.Uri;
import android.view.ViewGroup;
import com.bytedance.android.live.browser.IHybridContainerService;
import com.bytedance.android.livesdk.livesetting.gift.LiveGoalAnchorAccessControlSetting;
import com.bytedance.android.livesdk.livesetting.gift.LiveStreamGoalIndicatorWebLinkSetting;
import com.bytedance.android.livesdkapi.depend.model.live.Room;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import com.bytedance.ies.sdk.datachannel.DataChannel;
import com.bytedance.ies.sdk.widgets.LayeredLiveWidget;
import com.google.gson.Gson;
import kotlin.h.b.n;
import org.json.JSONObject;

public final class LiveGoalsWidget extends LayeredLiveWidget implements 6Is {
    public ViewGroup LIZ;
    public Kek LIZIZ;
    public final Mjy LIZJ = new Mjy();

    static {
        Covode.recordClassIndex(14550);
    }

    public final int getLayoutId() {
        return 2131562200;
    }

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

    public final void onDestroy() {
        super.onDestroy();
        Kek kek = this.LIZIZ;
        if (kek != null) {
            kek.LIZJ();
        }
        this.LIZJ.LIZ();
    }

    public final void onPause() {
        super.onPause();
        Kek kek = this.LIZIZ;
        if (kek != null) {
            C2115GSu.LIZ(kek, "container_disappear", new JSONObject());
        }
        Kek kek2 = this.LIZIZ;
        if (kek2 != null) {
            JSONObject jSONObject = new JSONObject();
            jSONObject.put("type", "app");
            jSONObject.put("args", new JSONObject().put("foreground", false));
            C2115GSu.LIZ(kek2, "H5_appStateChange", jSONObject);
        }
    }

    public final void onResume() {
        super.onResume();
        Kek kek = this.LIZIZ;
        if (kek != null) {
            C2115GSu.LIZ(kek, "container_appear", new JSONObject());
        }
        Kek kek2 = this.LIZIZ;
        if (kek2 != null) {
            JSONObject jSONObject = new JSONObject();
            jSONObject.put("type", "app");
            jSONObject.put("args", new JSONObject().put("foreground", true));
            C2115GSu.LIZ(kek2, "H5_appStateChange", jSONObject);
        }
    }

    public final void onCreate() {
        Object obj;
        Resources resources;
        MethodCollector.i(3267);
        super.onCreate();
        this.LIZ = (ViewGroup) findViewById(2131370506);
        String value = LiveStreamGoalIndicatorWebLinkSetting.INSTANCE.getValue();
        Context context = this.context;
        n.LIZIZ(context, "");
        this.LIZIZ = 0ZZ.LIZ(0cm.LIZ(IHybridContainerService.class), context, LIZ(value), (String) null, false, false, new C2109GSo(this, value), 28);
        Context context2 = this.context;
        if (!(context2 == null || (resources = context2.getResources()) == null)) {
            int color = resources.getColor(2131100577);
            Kek kek = this.LIZIZ;
            if (kek != null) {
                kek.setBackgroundColor(color);
            }
        }
        ViewGroup viewGroup = this.LIZ;
        if (viewGroup != null) {
            viewGroup.addView(this.LIZIZ, -1, -1);
        }
        this.LIZJ.LIZ(C2675Gg0.LIZ().LIZ(C2111GSq.class).LIZLLL(new C2108GSn(this)));
        DataChannel dataChannel = this.dataChannel;
        ViewGroup.LayoutParams layoutParams = null;
        if (dataChannel != null) {
            obj = dataChannel.LIZIZ(C1059Fv2.class);
        } else {
            obj = null;
        }
        if (n.LIZ(obj, false)) {
            ViewGroup viewGroup2 = this.LIZ;
            if (!(viewGroup2 == null || (layoutParams = viewGroup2.getLayoutParams()) == null)) {
                layoutParams.width = 0b0.LIZ(82.0f);
            }
            ViewGroup viewGroup3 = this.LIZ;
            if (viewGroup3 != null) {
                viewGroup3.setLayoutParams(layoutParams);
            }
        }
        this.LIZJ.LIZ(C2675Gg0.LIZ().LIZ(4kx.class).LIZLLL(new 4kw(this)));
        MethodCollector.o(3267);
    }

    private final String LIZ(String str) {
        Boolean bool;
        Gson gson;
        Room room;
        try {
            Uri.Builder buildUpon = Uri.parse(str).buildUpon();
            DataChannel dataChannel = this.dataChannel;
            Object obj = null;
            if (dataChannel != null) {
                bool = (Boolean) dataChannel.LIZIZ(C1059Fv2.class);
            } else {
                bool = null;
            }
            if (n.LIZ(bool, true)) {
                gson = 0UO.LIZIZ;
                obj = LiveGoalAnchorAccessControlSetting.INSTANCE.getValue();
            } else {
                gson = 0UO.LIZIZ;
                DataChannel dataChannel2 = this.dataChannel;
                if (!(dataChannel2 == null || (room = (Room) dataChannel2.LIZIZ(C1064Fv7.class)) == null)) {
                    obj = room.mIndicators;
                }
            }
            buildUpon.appendQueryParameter("indicator_business_keys", gson.LIZIZ(obj));
            buildUpon.appendQueryParameter("entrance", "live_entrance");
            String uri = buildUpon.build().toString();
            n.LIZIZ(uri, "");
            return uri;
        } catch (Exception unused) {
            return str;
        }
    }
}
