package com.ss.android.ugc.aweme.commercialize.preview.service;

import X.2Pr;
import X.2nK;
import X.3QV;
import X.4EV;
import X.4EW;
import X.4FQ;
import X.C4103LeY;
import X.C4174Lfh;
import X.C4176Lfj;
import X.C4177Lfk;
import X.C4178Lfl;
import X.C4672Lnj;
import X.C4939Ls2;
import X.K0V;
import X.M12;
import X.MMD;
import android.content.Context;
import android.view.ViewGroup;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import com.bytedance.keva.Keva;
import com.ss.android.ugc.aweme.commercialize.preview.manager.AdsPreviewStateManager;
import java.util.List;
import java.util.concurrent.TimeUnit;
import kotlin.h.b.n;

public final class AdsPreviewServiceImpl implements IAdsPreviewService {
    static {
        Covode.recordClassIndex(59369);
    }

    public static IAdsPreviewService LIZ() {
        MethodCollector.i(18569);
        IAdsPreviewService iAdsPreviewService = (IAdsPreviewService) C4672Lnj.LIZ(IAdsPreviewService.class, false);
        if (iAdsPreviewService != null) {
            MethodCollector.o(18569);
            return iAdsPreviewService;
        }
        Object LIZIZ = C4672Lnj.LIZIZ(IAdsPreviewService.class, false);
        if (LIZIZ != null) {
            IAdsPreviewService iAdsPreviewService2 = (IAdsPreviewService) LIZIZ;
            MethodCollector.o(18569);
            return iAdsPreviewService2;
        }
        if (C4672Lnj.LJLLLL == null) {
            synchronized (IAdsPreviewService.class) {
                try {
                    if (C4672Lnj.LJLLLL == null) {
                        C4672Lnj.LJLLLL = new AdsPreviewServiceImpl();
                    }
                } catch (Throwable th) {
                    MethodCollector.o(18569);
                    throw th;
                }
            }
        }
        AdsPreviewServiceImpl adsPreviewServiceImpl = (AdsPreviewServiceImpl) C4672Lnj.LJLLLL;
        MethodCollector.o(18569);
        return adsPreviewServiceImpl;
    }

    public final void LIZIZ(ViewGroup viewGroup) {
        M12.LIZ((Object) viewGroup);
        C4177Lfk.LIZIZ.LIZ(viewGroup);
    }

    public final void LIZ(ViewGroup viewGroup) {
        M12.LIZ((Object) viewGroup);
        M12.LIZ((Object) viewGroup);
        4EV r0 = C4178Lfl.LIZ;
        if (r0 != null) {
            r0.dismiss();
        }
        C4178Lfl.LIZ = null;
        C4177Lfk.LIZIZ.LIZ(viewGroup);
    }

    private final boolean LIZIZ(String str, String str2) {
        Keva repo = Keva.getRepo("ads_preview_keva");
        long j = repo.getLong("preview_timestamp", 0);
        if (j != 0 && TimeUnit.MILLISECONDS.toMinutes(System.currentTimeMillis() - j) <= ((long) K0V.LIZIZ.LIZ().getValidationDurationInMinute())) {
            int hashCode = str.hashCode();
            if (hashCode != 98494) {
                if (hashCode == 2989182 && str.equals("adid")) {
                    String[] stringArray = repo.getStringArray("preview_adids", new String[0]);
                    n.LIZIZ(stringArray, "");
                    if (C4103LeY.LIZIZ((T[]) stringArray, str2)) {
                        return true;
                    }
                }
            } else if (str.equals("cid")) {
                String[] stringArray2 = repo.getStringArray("preview_cids", new String[0]);
                n.LIZIZ(stringArray2, "");
                if (C4103LeY.LIZIZ((T[]) stringArray2, str2)) {
                    return true;
                }
            }
        }
        return false;
    }

    public final boolean LIZ(String str, String str2) {
        List<String> list;
        List<String> list2;
        if (str != null && (list2 = AdsPreviewStateManager.LJFF) != null && list2.contains(str)) {
            return true;
        }
        if (str != null && (((list = AdsPreviewStateManager.LJFF) == null || list.isEmpty()) && LIZIZ("adid", str))) {
            return true;
        }
        if (str2 != null) {
            List<String> list3 = AdsPreviewStateManager.LJI;
            if (list3 != null && list3.contains(str2)) {
                return true;
            }
            List<String> list4 = AdsPreviewStateManager.LJI;
            if ((list4 == null || list4.isEmpty()) && LIZIZ("cid", str2)) {
                return true;
            }
        }
        return false;
    }

    public final void LIZ(Context context, ViewGroup viewGroup, MMD mmd) {
        M12.LIZ((Object) context, (Object) viewGroup);
        C4177Lfk.LIZIZ.LIZ(context, viewGroup, mmd);
    }

    public final void LIZ(Context context, ViewGroup viewGroup, C4939Ls2<2Pr> ls2, C4939Ls2<2Pr> ls22) {
        M12.LIZ((Object) context, (Object) viewGroup);
        M12.LIZ((Object) context, (Object) viewGroup);
        C4177Lfk.LIZIZ.LIZ(context, viewGroup, (MMD) null);
        4EW r1 = new 4EW(context);
        r1.LIZJ(2131821420);
        r1.LIZLLL(2131821419);
        3QV.LIZ(r1, new C4174Lfh(ls22));
        r1.LIZ(false);
        r1.LIZIZ(new C4176Lfj(ls2));
        4EV LIZ = r1.LIZ();
        C4178Lfl.LIZ = LIZ;
        4FQ.LIZ(LIZ.LIZJ());
        2nK.onEventV3("ads_interface_preview_ad_successfully");
    }
}
