package com.ss.android.ugc.aweme.commercialize.profile;

import X.0CB;
import X.0CH;
import X.1hK;
import X.2UX;
import X.2nK;
import X.33g;
import X.6Is;
import X.C2640Kw3;
import X.C2642Kw5;
import X.C2644Kw7;
import X.C2652KwF;
import X.C2653KwG;
import X.C2655KwI;
import X.C2668KwV;
import X.C2683Kwk;
import X.C3290LFp;
import X.C4939Ls2;
import X.M12;
import android.app.Activity;
import android.content.Context;
import android.content.ContextWrapper;
import android.widget.FrameLayout;
import androidx.fragment.app.Fragment;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import com.ss.android.ugc.aweme.arch.widgets.base.DataCenter;
import com.ss.android.ugc.aweme.commercialize.widget.AbsAdFeedWidget;
import com.ss.android.ugc.aweme.feed.model.Aweme;
import com.ss.android.ugc.aweme.feed.model.AwemeRawAd;
import java.lang.ref.WeakReference;
import java.util.HashMap;
import java.util.Map;

public final class AdProfilePopUpWebPageWidget extends AbsAdFeedWidget implements 6Is {
    public static final Map<String, WeakReference<Runnable>> LJIIL = new HashMap();
    public static final C2652KwF LJIILIIL = new C2652KwF((byte) 0);
    public C2640Kw3 LIZ;
    public long LJII;
    public String LJIIIIZZ;
    public final C2644Kw7 LJIIIZ = new C2644Kw7(this);
    public final C2653KwG LJIIJ = new C2653KwG(this);
    public final C2683Kwk LJIIJJI = new C2683Kwk(this);
    public final Runnable LJIJ = new C2642Kw5(this);

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

    public final void onPause() {
        LIZ(System.currentTimeMillis() - this.LJII);
        super.onPause();
    }

    public final void onResume() {
        this.LJII = System.currentTimeMillis();
        super.onResume();
    }

    static {
        Covode.recordClassIndex(59458);
    }

    public final void LJ() {
        super.LJ();
        DataCenter dataCenter = this.LJ;
        if (dataCenter != null) {
            dataCenter.LIZ("ad_feed_on_page_selected", this);
            dataCenter.LIZ("ad_feed_on_page_unselected", this);
        }
    }

    public final /* synthetic */ void onChanged(Object obj) {
        onChanged((33g) obj);
    }

    public final void LIZ(long j) {
        if (this.LIZ != null) {
            2UX r1 = new 2UX();
            r1.LIZ("duration", j);
            2nK.LIZ("h5_stay_time", r1.LIZ);
        }
    }

    public static final boolean LIZ(C2655KwI kwI) {
        Context context;
        WeakReference weakReference;
        Runnable runnable;
        C2652KwF kwF = LJIILIIL;
        if (kwI != null && (context = kwI.LIZ) != null) {
            while (true) {
                if (context != null) {
                    if (!(context instanceof Activity)) {
                        if (!(context instanceof ContextWrapper)) {
                            break;
                        }
                        context = ((ContextWrapper) context).getBaseContext();
                    } else {
                        Activity activity = (Activity) context;
                        if (activity != null) {
                            String str = kwI.LJII;
                            if (!(str == null || (weakReference = LJIIL.get(str)) == null || (runnable = (Runnable) weakReference.get()) == null)) {
                                runnable.run();
                            }
                            C2640Kw3 LIZIZ = kwF.LIZIZ(activity);
                            if (LIZIZ != null && !LIZIZ.LJII()) {
                                FrameLayout LIZ2 = kwF.LIZ(activity);
                                if (LIZ2 != null) {
                                    LIZ2.setVisibility(0);
                                }
                                LIZIZ.setShouldStartAnimation(kwI.LJIIJ);
                                LIZIZ.getActionMode().LJFF = kwI.LIZLLL;
                                LIZIZ.LIZ((C4939Ls2<? extends Object>) new C2668KwV(LIZIZ, kwI));
                                return true;
                            }
                        }
                    }
                } else {
                    break;
                }
            }
        }
        return false;
    }

    public final void LIZ(33g r6) {
        String str;
        1hK activity;
        String aid;
        String aid2;
        AwemeRawAd awemeRawAd;
        MethodCollector.i(1272);
        super.onChanged(r6);
        if (r6 == null || (str = r6.LIZ) == null) {
            MethodCollector.o(1272);
            return;
        }
        int hashCode = str.hashCode();
        if (hashCode != -1540531799) {
            if (hashCode == -1132409520 && str.equals("ad_feed_on_page_selected")) {
                Aweme aweme = this.LJIILJJIL;
                if (C3290LFp.LJLIIIL(aweme) || C3290LFp.LJJZZIII(aweme) || !(aweme == null || (awemeRawAd = aweme.getAwemeRawAd()) == null || awemeRawAd.getWebviewType() != 1)) {
                    Aweme aweme2 = this.LJIILJJIL;
                    if (aweme2 == null || (aid2 = aweme2.getAid()) == null) {
                        MethodCollector.o(1272);
                        return;
                    }
                    LJIIL.put(aid2, new WeakReference(this.LJIJ));
                    MethodCollector.o(1272);
                    return;
                }
                MethodCollector.o(1272);
                return;
            }
        } else if (str.equals("ad_feed_on_page_unselected")) {
            Aweme aweme3 = this.LJIILJJIL;
            if (!(aweme3 == null || (aid = aweme3.getAid()) == null)) {
                LJIIL.remove(aid);
            }
            if (this.LIZ == null) {
                MethodCollector.o(1272);
                return;
            }
            Fragment fragment = this.LJIILL;
            if (fragment == null || (activity = fragment.getActivity()) == null) {
                MethodCollector.o(1272);
                return;
            }
            C2652KwF kwF = LJIILIIL;
            M12.LIZ((Object) activity);
            C2640Kw3 LIZIZ = kwF.LIZIZ(activity);
            if (LIZIZ != null) {
                LIZIZ.LIZJ();
                FrameLayout LIZ2 = kwF.LIZ(activity);
                if (LIZ2 != null) {
                    LIZ2.removeView(LIZIZ);
                }
            }
            this.LIZ = null;
        }
        MethodCollector.o(1272);
    }
}
