package com.ss.android.ugc.aweme.watch.history;

import X.1hK;
import X.8Ze;
import X.AnonymousClass2UX;
import X.AnonymousClass348;
import X.AnonymousClass4HZ;
import X.AnonymousClass4JE;
import X.AnonymousClass4JF;
import X.AnonymousClass4JG;
import X.AnonymousClass4JH;
import X.AnonymousClass4JI;
import X.AnonymousClass4JJ;
import X.C12422nK;
import X.C30053af;
import X.C474046i;
import X.C50084Gq;
import X.Lnj;
import X.RjB;
import android.app.Activity;
import android.os.Handler;
import android.os.Looper;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import com.ss.android.ugc.aweme.IAccountUserService;
import com.ss.android.ugc.aweme.IWatchHistoryApi;

public final class WatchHistoryService implements IWatchHistoryApi {
    public final C50084Gq LIZ = RjB.LIZIZ;
    public final Handler LIZIZ = new Handler(Looper.getMainLooper());

    static {
        Covode.recordClassIndex(123889);
    }

    public final 8Ze LIZJ() {
        if (!AnonymousClass4JG.LIZ.LIZ() || AnonymousClass4JI.LIZ.LIZ()) {
            return null;
        }
        return new WatchHistoryInitTask();
    }

    public final int LIZLLL() {
        if (!AnonymousClass4JG.LIZ.LIZ()) {
            return 2;
        }
        if (AnonymousClass4HZ.LIZ.LIZIZ()) {
            return 1;
        }
        return 0;
    }

    public final void LIZ() {
        if (AnonymousClass4JG.LIZ.LIZ() && AnonymousClass4JH.LIZ.LIZ()) {
            IAccountUserService LJFF = C474046i.LJFF();
            if (LJFF == null || LJFF.isLogin()) {
                AnonymousClass348.LIZ().submit(new AnonymousClass4JE(this));
            }
        }
    }

    public final void LIZIZ() {
        IAccountUserService LJFF = C474046i.LJFF();
        if ((LJFF == null || LJFF.isLogin()) && AnonymousClass4JG.LIZ.LIZ() && AnonymousClass4JI.LIZ.LIZ()) {
            AnonymousClass348.LIZ().submit(AnonymousClass4JJ.LIZ);
        }
    }

    public static IWatchHistoryApi LJ() {
        MethodCollector.i(1140);
        IWatchHistoryApi iWatchHistoryApi = (IWatchHistoryApi) Lnj.LIZ(IWatchHistoryApi.class, false);
        if (iWatchHistoryApi != null) {
            MethodCollector.o(1140);
            return iWatchHistoryApi;
        }
        Object LIZIZ2 = Lnj.LIZIZ(IWatchHistoryApi.class, false);
        if (LIZIZ2 != null) {
            IWatchHistoryApi iWatchHistoryApi2 = (IWatchHistoryApi) LIZIZ2;
            MethodCollector.o(1140);
            return iWatchHistoryApi2;
        }
        if (Lnj.bW == null) {
            synchronized (IWatchHistoryApi.class) {
                try {
                    if (Lnj.bW == null) {
                        Lnj.bW = new WatchHistoryService();
                    }
                } catch (Throwable th) {
                    MethodCollector.o(1140);
                    throw th;
                }
            }
        }
        WatchHistoryService watchHistoryService = (WatchHistoryService) Lnj.bW;
        MethodCollector.o(1140);
        return watchHistoryService;
    }

    public final void LIZ(String str) {
        if (str != null && str.length() != 0) {
            IAccountUserService LJFF = C474046i.LJFF();
            if ((LJFF == null || LJFF.isLogin()) && AnonymousClass4JG.LIZ.LIZ() && AnonymousClass4HZ.LIZ.LIZIZ()) {
                this.LIZIZ.postDelayed(new AnonymousClass4JF(this, str), 2000);
            }
        }
    }

    public final void LIZ(1hK r13, String str) {
        if (r13 != null && AnonymousClass4JG.LIZ.LIZ()) {
            AnonymousClass4HZ r11 = AnonymousClass4HZ.LIZ;
            int i = r11.LIZ().getInt("key_watch_history_guide", 0);
            long j = r11.LIZ().getLong("key_watch_history_guide_time", -1);
            if (i >= 3) {
                return;
            }
            if (j <= 0 || System.currentTimeMillis() - j >= 86400000) {
                r11.LIZ().storeLong("key_watch_history_guide_time", System.currentTimeMillis());
                r11.LIZ().storeInt("key_watch_history_guide", i + 1);
                C30053af r2 = new C30053af((Activity) r13);
                r2.LIZ((CharSequence) r13.getString(2131834974));
                r2.LIZ(5000);
                C30053af.LIZ(r2);
                AnonymousClass2UX r1 = new AnonymousClass2UX();
                r1.LIZ("enter_from", str);
                C12422nK.LIZ("show_history_access_popup", r1.LIZ);
            }
        }
    }
}
