package com.ss.android.ugc.aweme.im.sdk.notification;

import X.0AA;
import X.1hK;
import X.3p3;
import X.49h;
import X.4r1;
import X.C0746D8s;
import X.C0782DAc;
import X.C0789DAj;
import X.C0849DCr;
import X.DAU;
import X.DBT;
import X.DEU;
import X.EQA;
import X.Lnj;
import X.M12;
import android.app.Activity;
import android.app.Dialog;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.Fragment;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import com.ss.android.ugc.aweme.im.INotificationManagerService;
import com.ss.android.ugc.aweme.im.sdk.common.controller.providedservices.IMService;
import com.ss.android.ugc.aweme.out.AVExternalServiceImpl;
import com.ss.android.ugc.aweme.services.IExternalService;
import java.lang.ref.WeakReference;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import kotlin.h.b.n;

public final class NotificationManagerServiceImpl implements INotificationManagerService {
    static {
        Covode.recordClassIndex(86562);
    }

    public final boolean LIZ() {
        return EQA.LJIIL.LIZ().LJIIJ;
    }

    public final boolean LIZIZ() {
        return EQA.LJIIL.LIZ().LJFF;
    }

    public static INotificationManagerService LIZJ() {
        MethodCollector.i(2036);
        INotificationManagerService iNotificationManagerService = (INotificationManagerService) Lnj.LIZ(INotificationManagerService.class, false);
        if (iNotificationManagerService != null) {
            MethodCollector.o(2036);
            return iNotificationManagerService;
        }
        Object LIZIZ = Lnj.LIZIZ(INotificationManagerService.class, false);
        if (LIZIZ != null) {
            INotificationManagerService iNotificationManagerService2 = (INotificationManagerService) LIZIZ;
            MethodCollector.o(2036);
            return iNotificationManagerService2;
        }
        if (Lnj.LLLIZZ == null) {
            synchronized (INotificationManagerService.class) {
                try {
                    if (Lnj.LLLIZZ == null) {
                        Lnj.LLLIZZ = new NotificationManagerServiceImpl();
                    }
                } catch (Throwable th) {
                    MethodCollector.o(2036);
                    throw th;
                }
            }
        }
        NotificationManagerServiceImpl notificationManagerServiceImpl = (NotificationManagerServiceImpl) Lnj.LLLIZZ;
        MethodCollector.o(2036);
        return notificationManagerServiceImpl;
    }

    public final void LIZ(Integer num) {
        EQA LIZ = EQA.LJIIL.LIZ();
        boolean z = true;
        if (num == null || num.intValue() != 1) {
            z = false;
        }
        LIZ.LIZLLL = z;
    }

    public final void LIZIZ(Integer num) {
        EQA LIZ = EQA.LJIIL.LIZ();
        boolean z = true;
        if (num == null || num.intValue() != 1) {
            z = false;
        }
        LIZ.LIZIZ = z;
    }

    public final void LIZJ(Integer num) {
        EQA LIZ = EQA.LJIIL.LIZ();
        boolean z = true;
        if (num == null || num.intValue() != 1) {
            z = false;
        }
        LIZ.LJFF = z;
    }

    public final void LIZLLL(Integer num) {
        EQA LIZ = EQA.LJIIL.LIZ();
        boolean z = true;
        if (num == null || num.intValue() != 1) {
            z = false;
        }
        LIZ.LJI = z;
    }

    public final void LJ(Integer num) {
        EQA LIZ = EQA.LJIIL.LIZ();
        boolean z = true;
        if (num == null || num.intValue() != 1) {
            z = false;
        }
        LIZ.LJ = z;
    }

    public final void LJFF(Integer num) {
        EQA LIZ = EQA.LJIIL.LIZ();
        boolean z = true;
        if (num == null || num.intValue() != 1) {
            z = false;
        }
        LIZ.LIZJ = z;
    }

    public final void LIZ(3p3 r5) {
        boolean z;
        boolean z2;
        boolean z3;
        boolean z4;
        M12.LIZ(r5);
        EQA LIZ = EQA.LJIIL.LIZ();
        M12.LIZ(r5);
        boolean z5 = false;
        if (r5.LJIILJJIL == 1) {
            z = true;
        } else {
            z = false;
        }
        LIZ.LIZLLL = z;
        if (r5.LJIJJLI == 1) {
            z2 = true;
        } else {
            z2 = false;
        }
        LIZ.LIZIZ = z2;
        if (r5.LJIIL == 1) {
            z3 = true;
        } else {
            z3 = false;
        }
        LIZ.LJFF = z3;
        if (r5.LJ == 1) {
            z4 = true;
        } else {
            z4 = false;
        }
        LIZ.LJI = z4;
        if (r5.LJIILIIL == 1) {
            z5 = true;
        }
        LIZ.LJ = z5;
    }

    public final ViewGroup LIZ(Activity activity) {
        Object obj;
        Window window;
        EQA.LJIIL.LIZ();
        View view = null;
        if (activity == null) {
            return null;
        }
        if (activity instanceof 1hK) {
            1hK r8 = (1hK) activity;
            0AA supportFragmentManager = r8.getSupportFragmentManager();
            n.LIZIZ(supportFragmentManager, "");
            List LJFF = supportFragmentManager.LJFF();
            n.LIZIZ(LJFF, "");
            Iterator it = LJFF.iterator();
            while (true) {
                if (!it.hasNext()) {
                    obj = null;
                    break;
                }
                obj = it.next();
                Fragment fragment = (Fragment) obj;
                if ((fragment instanceof DialogFragment) && fragment.isVisible()) {
                    break;
                }
            }
            DialogFragment dialogFragment = (Fragment) obj;
            if (dialogFragment != null) {
                Objects.requireNonNull(dialogFragment, "null cannot be cast to non-null type androidx.fragment.app.DialogFragment");
                Dialog dialog = dialogFragment.getDialog();
                if (!(dialog == null || (window = dialog.getWindow()) == null)) {
                    view = window.getDecorView();
                }
                ViewGroup viewGroup = (ViewGroup) view;
                if (viewGroup != null) {
                    return viewGroup;
                }
            }
            Window window2 = r8.getWindow();
            n.LIZIZ(window2, "");
            View decorView = window2.getDecorView();
            Objects.requireNonNull(decorView, "null cannot be cast to non-null type android.view.ViewGroup");
            return (ViewGroup) decorView;
        }
        Window window3 = activity.getWindow();
        n.LIZIZ(window3, "");
        View decorView2 = window3.getDecorView();
        Objects.requireNonNull(decorView2, "null cannot be cast to non-null type android.view.ViewGroup");
        return (ViewGroup) decorView2;
    }

    public final void LIZ(boolean z) {
        EQA LIZ = EQA.LJIIL.LIZ();
        if (!z) {
            DBT unused = C0782DAc.LIZ(C0789DAj.LIZ((C0746D8s) C0849DCr.LIZIZ), (C0746D8s) null, (DAU) null, new DEU(LIZ, z, (4r1) null), 3);
        } else {
            LIZ.LJIIIIZZ = z;
        }
    }

    public final void LIZIZ(Activity activity) {
        String str;
        String str2;
        String str3;
        EQA LIZ = EQA.LJIIL.LIZ();
        LIZ.LIZ = new WeakReference<>(activity);
        StringBuilder sb = new StringBuilder(" mIsColdStart: ");
        sb.append(LIZ.LJIIIZ);
        sb.append(" activity: ");
        String str4 = null;
        if (activity != null) {
            str = activity.getLocalClassName();
        } else {
            str = null;
        }
        sb.append(str);
        M12.LIZ("NotificationManager", sb.toString());
        if ((activity instanceof 49h) && LIZ.LJIIIZ) {
            LIZ.LJIIIZ = false;
        } else if (IMService.createIIMServicebyMonsterPlugin(false).isNotificationMessageQueueEmpty()) {
            M12.LIZ("NotificationManager", " MessageQueue is empty");
        } else {
            if (activity != null) {
                str2 = activity.getLocalClassName();
            } else {
                str2 = null;
            }
            if (!TextUtils.equals(str2, "miniapp.views.MiniAppListH5Activity")) {
                if (activity != null) {
                    str3 = activity.getLocalClassName();
                } else {
                    str3 = null;
                }
                if (!TextUtils.equals(str3, "miniapp.RecentlyUsedMicroAppActivity") && !LIZ.LIZ(activity)) {
                    if (activity != null) {
                        str4 = activity.getLocalClassName();
                    }
                    if (!TextUtils.equals(str4, "shortvideo.ui.VideoRecordNewActivity")) {
                        IExternalService LIZ2 = AVExternalServiceImpl.LIZ();
                        if (LIZ2.configService().shortVideoConfig().isRecording()) {
                            return;
                        }
                        if ((activity == null || !LIZ2.publishService().inPublishPage(activity)) && !LIZ.LJIIIIZZ) {
                            IMService.createIIMServicebyMonsterPlugin(false).showIMNotification(LIZ.LJII);
                            LIZ.LJII = false;
                            return;
                        }
                        return;
                    }
                    return;
                }
            }
            IMService.createIIMServicebyMonsterPlugin(false).clearIMNotification();
            LIZ.LJII = false;
        }
    }
}
