package com.ss.android.ugc.aweme.spark;

import X.C1326Kar;
import X.C1582Kez;
import X.C1649Kg4;
import X.C1651Kg6;
import X.C1653Kg8;
import X.C1654Kg9;
import X.C1655KgA;
import X.C1656KgB;
import X.C1692Kgl;
import X.C1715Kh8;
import X.C1999Kli;
import X.C2125Knk;
import X.C2127Knm;
import X.C4672Lnj;
import X.KLX;
import X.M12;
import android.content.Context;
import android.os.Bundle;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import com.bytedance.hybrid.spark.SparkContext;
import com.bytedance.hybrid.spark.page.SparkFragment;
import java.util.Map;
import kotlin.h.b.n;

public final class AdSparkUtils implements IAdSparkUtils {
    static {
        Covode.recordClassIndex(114927);
    }

    public final SparkFragment LIZ() {
        return new AdSparkFragment();
    }

    public static IAdSparkUtils LIZIZ() {
        MethodCollector.i(16144);
        IAdSparkUtils iAdSparkUtils = (IAdSparkUtils) C4672Lnj.LIZ(IAdSparkUtils.class, false);
        if (iAdSparkUtils != null) {
            MethodCollector.o(16144);
            return iAdSparkUtils;
        }
        Object LIZIZ = C4672Lnj.LIZIZ(IAdSparkUtils.class, false);
        if (LIZIZ != null) {
            IAdSparkUtils iAdSparkUtils2 = (IAdSparkUtils) LIZIZ;
            MethodCollector.o(16144);
            return iAdSparkUtils2;
        }
        if (C4672Lnj.bz == null) {
            synchronized (IAdSparkUtils.class) {
                try {
                    if (C4672Lnj.bz == null) {
                        C4672Lnj.bz = new AdSparkUtils();
                    }
                } catch (Throwable th) {
                    MethodCollector.o(16144);
                    throw th;
                }
            }
        }
        AdSparkUtils adSparkUtils = (AdSparkUtils) C4672Lnj.bz;
        MethodCollector.o(16144);
        return adSparkUtils;
    }

    public static Object LIZ(Bundle bundle, String str) {
        try {
            return bundle.get(str);
        } catch (Exception | OutOfMemoryError unused) {
            return null;
        }
    }

    public final void LIZ(SparkContext sparkContext, String str) {
        M12.LIZ((Object) sparkContext);
        if (str != null && str.length() != 0) {
            sparkContext.LIZ(C1654Kg9.class, new C1653Kg8(str));
        }
    }

    public final void LIZ(SparkContext sparkContext, Bundle bundle) {
        M12.LIZ((Object) sparkContext);
        if (bundle != null) {
            for (String str : bundle.keySet()) {
                if (!n.LIZ("url", str)) {
                    Object LIZ = LIZ(bundle, str);
                    if (LIZ instanceof Boolean) {
                        n.LIZIZ(str, "");
                        sparkContext.LIZ(str, ((Boolean) LIZ).booleanValue());
                    } else if (LIZ instanceof Double) {
                        n.LIZIZ(str, "");
                        sparkContext.LIZ(str, ((Number) LIZ).doubleValue());
                    } else if (LIZ instanceof Integer) {
                        n.LIZIZ(str, "");
                        sparkContext.LIZ(str, ((Number) LIZ).intValue());
                    } else if (LIZ instanceof String) {
                        n.LIZIZ(str, "");
                        sparkContext.LIZ(str, (String) LIZ);
                    }
                }
            }
        }
    }

    public final void LIZ(Context context, String str, Bundle bundle, String str2) {
        M12.LIZ((Object) context, (Object) str);
        AdSparkContext LIZ = C1999Kli.LIZ(this, context, str, bundle, 8);
        LIZ((SparkContext) LIZ, bundle);
        LIZ((SparkContext) LIZ, str2);
        C1715Kh8.LJIIJJI.LIZ(context, (SparkContext) LIZ).LIZ();
    }

    public final AdSparkContext LIZ(Context context, String str, Bundle bundle, Map<String, String> map) {
        Context context2 = context;
        M12.LIZ((Object) context2);
        C2127Knm knm = new C2127Knm();
        AdSparkContext adSparkContext = new AdSparkContext();
        String str2 = str;
        if (str2 != null) {
            adSparkContext.LIZ(str2);
        }
        Map<String, String> map2 = map;
        Bundle bundle2 = bundle;
        adSparkContext.LIZIZ(new KLX(this, str2, context2, bundle2, knm, map2));
        adSparkContext.LIZIZ(knm);
        adSparkContext.LIZ((C1692Kgl) new C2125Knk(knm));
        C1651Kg6 kg6 = new C1651Kg6();
        M12.LIZ((Object) kg6);
        adSparkContext.LIZ(C1655KgA.class, kg6);
        adSparkContext.LIZ(C1656KgB.class, knm);
        adSparkContext.LIZ(Bundle.class, bundle2);
        adSparkContext.LIZ((C1582Kez) new C1326Kar(adSparkContext, this, str2, context2, bundle2, knm, map2));
        M12.LIZ((Object) knm);
        adSparkContext.LIZ(C1649Kg4.class, knm);
        return adSparkContext;
    }
}
