package com.ss.android.ugc.aweme.ad.feed.shakeEgg;

import X.1hK;
import X.3G1;
import X.83A;
import X.A3f;
import X.C3011L4w;
import X.C3419LKo;
import X.C3422LKr;
import X.C4672Lnj;
import X.D4J;
import X.FMA;
import X.L58;
import X.M12;
import android.content.Context;
import android.content.res.Resources;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import com.ss.android.ugc.aweme.ad.preload.AdLandPagePreloadServiceImpl;
import com.ss.android.ugc.aweme.ad.preload.IAdLandPagePreloadService;
import com.ss.android.ugc.aweme.feed.model.Aweme;
import com.ss.android.ugc.aweme.feed.model.AwemeRawAd;
import java.util.List;
import kotlin.h.b.n;
import org.json.JSONObject;

public final class ShakeEggService implements IShakeEggService {
    static {
        Covode.recordClassIndex(52744);
    }

    public static IShakeEggService LIZ() {
        MethodCollector.i(17619);
        IShakeEggService iShakeEggService = (IShakeEggService) C4672Lnj.LIZ(IShakeEggService.class, false);
        if (iShakeEggService != null) {
            MethodCollector.o(17619);
            return iShakeEggService;
        }
        Object LIZIZ = C4672Lnj.LIZIZ(IShakeEggService.class, false);
        if (LIZIZ != null) {
            IShakeEggService iShakeEggService2 = (IShakeEggService) LIZIZ;
            MethodCollector.o(17619);
            return iShakeEggService2;
        }
        if (C4672Lnj.LJJIJLIJ == null) {
            synchronized (IShakeEggService.class) {
                try {
                    if (C4672Lnj.LJJIJLIJ == null) {
                        C4672Lnj.LJJIJLIJ = new ShakeEggService();
                    }
                } catch (Throwable th) {
                    MethodCollector.o(17619);
                    throw th;
                }
            }
        }
        ShakeEggService shakeEggService = (ShakeEggService) C4672Lnj.LJJIJLIJ;
        MethodCollector.o(17619);
        return shakeEggService;
    }

    public final FMA LIZ(1hK r2) {
        M12.LIZ((Object) r2);
        return new ShakeEgg(r2);
    }

    public final boolean LIZIZ(Aweme aweme) {
        C3419LKo LIZ = LIZ(aweme);
        if (LIZ == null || LIZ.getShaken()) {
            return false;
        }
        return true;
    }

    public final C3419LKo LIZ(Aweme aweme) {
        AwemeRawAd awemeRawAd;
        C3419LKo shakeModel;
        if (aweme == null || (awemeRawAd = aweme.getAwemeRawAd()) == null || (shakeModel = awemeRawAd.getShakeModel()) == null) {
            return null;
        }
        return shakeModel;
    }

    public final void LIZ(AwemeRawAd awemeRawAd, List<String> list) {
        String str;
        M12.LIZ((Object) awemeRawAd);
        L58 l58 = D4J.LIZ;
        n.LIZIZ(l58, "");
        C3011L4w LIZJ = l58.LIZJ();
        if (LIZJ != null) {
            IAdLandPagePreloadService LJFF = AdLandPagePreloadServiceImpl.LJFF();
            if (LJFF != null) {
                str = LJFF.LJI("lynx_feed");
            } else {
                str = null;
            }
            LIZJ.LIZ(list, str, "lynx_feed", (83A) new C3422LKr(awemeRawAd));
        }
    }

    public final String LIZ(C3419LKo lKo, Context context) {
        M12.LIZ((Object) context);
        JSONObject jSONObject = new JSONObject();
        Resources resources = context.getResources();
        n.LIZIZ(resources, "");
        jSONObject.putOpt("width", Integer.valueOf(resources.getDisplayMetrics().widthPixels));
        jSONObject.putOpt("height", Integer.valueOf(3G1.LJ(context) - 3G1.LJ()));
        Resources resources2 = context.getResources();
        n.LIZIZ(resources2, "");
        jSONObject.putOpt("scale", Float.valueOf(resources2.getDisplayMetrics().density));
        if (lKo != null) {
            List<String> geckoChannel = lKo.getGeckoChannel();
            if (geckoChannel != null) {
                jSONObject.putOpt("gecko_channel", A3f.LIZ().LIZIZ(geckoChannel));
            }
            Object frontendData = lKo.getFrontendData();
            if (frontendData != null) {
                jSONObject.putOpt("data", A3f.LIZ().LIZIZ(frontendData));
            }
        }
        String jSONObject2 = jSONObject.toString();
        n.LIZIZ(jSONObject2, "");
        return jSONObject2;
    }
}
