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

import X.0CB;
import X.0CH;
import X.0CN;
import X.1hK;
import X.2UX;
import X.2nK;
import X.6Is;
import X.C2359KrW;
import X.C2360KrX;
import X.C2362KrZ;
import X.C2363Kra;
import X.C2364Krb;
import X.C2377Kro;
import X.C2455Kt4;
import X.C2619Kvi;
import X.C2640Kw3;
import X.M12;
import android.widget.FrameLayout;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import com.ss.android.ugc.aweme.feed.model.Aweme;
import java.lang.ref.WeakReference;
import java.util.LinkedHashMap;
import java.util.Map;

public final class AdPopUpWebPageHelper implements 6Is {
    public static final Map<Integer, AdPopUpWebPageHelper> LJI = new LinkedHashMap();
    public static final C2360KrX LJII = new C2360KrX((byte) 0);
    public String LIZ;
    public long LIZIZ;
    public C2640Kw3 LIZJ;
    public final C2359KrW LIZLLL = new C2359KrW(this);
    public final C2363Kra LJ = new C2363Kra(this);
    public final C2362KrZ LJFF = new C2362KrZ(this);
    public WeakReference<1hK> LJIIIIZZ;

    public final void onStateChanged(0CH r2, 0CB r3) {
        if (r3 == 0CB.ON_RESUME) {
            onResume();
        } else if (r3 == 0CB.ON_PAUSE) {
            onPause();
        } else if (r3 == 0CB.ON_DESTROY) {
            onDestroy();
        }
    }

    @0CN(LIZ = 0CB.ON_RESUME)
    public final void onResume() {
        this.LIZIZ = System.currentTimeMillis();
    }

    public final Aweme LIZ() {
        C2377Kro LIZ2 = C2455Kt4.LIZIZ.LIZ();
        if (LIZ2 != null) {
            return LIZ2.LJIIL;
        }
        return null;
    }

    public final 1hK LIZIZ() {
        WeakReference<1hK> weakReference = this.LJIIIIZZ;
        if (weakReference != null) {
            return (1hK) weakReference.get();
        }
        return null;
    }

    @0CN(LIZ = 0CB.ON_DESTROY)
    public final void onDestroy() {
        1hK LIZIZ2 = LIZIZ();
        if (LIZIZ2 != null) {
            LJII.LIZ(LIZIZ2);
        }
    }

    @0CN(LIZ = 0CB.ON_PAUSE)
    public final void onPause() {
        LIZ(System.currentTimeMillis() - this.LIZIZ);
    }

    static {
        Covode.recordClassIndex(59690);
    }

    public final void LIZJ() {
        MethodCollector.i(675);
        1hK LIZIZ2 = LIZIZ();
        if (LIZIZ2 == null) {
            MethodCollector.o(675);
            return;
        }
        LIZIZ2.getLifecycle().LIZIZ(this);
        if (this.LIZJ != null) {
            C2619Kvi kvi = C2364Krb.LIZ;
            M12.LIZ((Object) LIZIZ2);
            C2640Kw3 LIZIZ3 = kvi.LIZIZ(LIZIZ2);
            if (LIZIZ3 != null) {
                LIZIZ3.LIZJ();
                FrameLayout LIZ2 = C2364Krb.LIZ.LIZ(LIZIZ2);
                if (LIZ2 != null) {
                    LIZ2.removeView(LIZIZ3);
                    MethodCollector.o(675);
                    return;
                }
                MethodCollector.o(675);
                return;
            }
        }
        MethodCollector.o(675);
    }

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

    public AdPopUpWebPageHelper(1hK r3) {
        M12.LIZ((Object) r3);
        this.LJIIIIZZ = new WeakReference<>(r3);
        r3.getLifecycle().LIZ(this);
    }
}
