package com.bytedance.tiktok.homepage.services;

import X.0CD;
import X.0CG;
import X.0CH;
import X.1hK;
import X.2KS;
import X.7ZL;
import X.7df;
import X.7xA;
import X.C4602Eje;
import X.C5011EqF;
import X.C5012EqG;
import X.C5015EqJ;
import X.C5018EqM;
import X.C5020EqO;
import X.C5057Eqz;
import X.C5169Esn;
import X.CqG;
import X.Lnj;
import X.M12;
import X.MHK;
import X.Otb;
import android.content.Context;
import android.content.res.Resources;
import android.os.Handler;
import android.view.View;
import androidx.fragment.app.Fragment;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import com.bytedance.tiktok.homepage.mainpagefragment.dialog.FissionPopupWindowHelp;
import com.ss.android.ugc.aweme.homepage.api.data.MainPageDataViewModel;
import com.ss.android.ugc.aweme.homepage.api.interaction.ScrollSwitchStateManager;
import com.ss.android.ugc.aweme.main.IMainPageFragment;
import com.ss.android.ugc.aweme.main.MainActivity;
import com.ss.android.ugc.aweme.main.MainPageFragment;
import com.ss.android.ugc.aweme.main.TabChangeManager;
import java.lang.ref.WeakReference;
import java.util.Objects;
import kotlin.h.b.n;

public final class MainPageFragmentImpl implements IMainPageFragment {
    public WeakReference<MainPageFragment> LIZ;

    static {
        Covode.recordClassIndex(38634);
    }

    public final boolean LIZIZ() {
        MainPageFragment mainPageFragment;
        Otb otb;
        WeakReference<MainPageFragment> weakReference = this.LIZ;
        if (weakReference == null || (mainPageFragment = (MainPageFragment) weakReference.get()) == null || (otb = mainPageFragment.LJJIIJZLJL) == null || !otb.isShowing()) {
            return false;
        }
        return true;
    }

    public final void LIZJ() {
        MainPageFragment mainPageFragment;
        CqG cqG;
        WeakReference<MainPageFragment> weakReference = this.LIZ;
        if (weakReference != null && (mainPageFragment = (MainPageFragment) weakReference.get()) != null && (cqG = mainPageFragment.LJIJJLI) != null) {
            cqG.LIZIZ();
        }
    }

    public final String LIZLLL() {
        MainPageFragment mainPageFragment;
        MainPageDataViewModel mainPageDataViewModel;
        String str;
        WeakReference<MainPageFragment> weakReference = this.LIZ;
        if (weakReference == null || (mainPageFragment = (MainPageFragment) weakReference.get()) == null || (mainPageDataViewModel = mainPageFragment.LJIILIIL) == null || (str = mainPageDataViewModel.LIZIZ) == null) {
            return "";
        }
        return str;
    }

    public final String LJ() {
        MainPageFragment mainPageFragment;
        String LJI;
        WeakReference<MainPageFragment> weakReference = this.LIZ;
        if (weakReference == null || (mainPageFragment = (MainPageFragment) weakReference.get()) == null || (LJI = mainPageFragment.LJI()) == null) {
            return "";
        }
        return LJI;
    }

    public final void LIZ() {
        MainPageFragment mainPageFragment;
        WeakReference<MainPageFragment> weakReference = this.LIZ;
        if (weakReference != null && (mainPageFragment = (MainPageFragment) weakReference.get()) != null) {
            if (MHK.LIZ.LIZIZ()) {
                mainPageFragment.LJIIL().LIZLLL();
                return;
            }
            C5018EqM eqM = mainPageFragment.LJIL;
            if (eqM == null) {
                n.LIZIZ();
            }
            if (eqM.LJIIIIZZ) {
                C5018EqM eqM2 = mainPageFragment.LJIL;
                if (eqM2 == null) {
                    n.LIZIZ();
                }
                eqM2.LIZ();
            }
        }
    }

    public final void LJFF() {
        MainPageFragment mainPageFragment;
        C5011EqF eqF;
        Handler LIZ2;
        WeakReference<MainPageFragment> weakReference = this.LIZ;
        if (weakReference != null && (mainPageFragment = (MainPageFragment) weakReference.get()) != null && (eqF = mainPageFragment.LJJIIJ) != null && eqF.LIZ() != null) {
            C5011EqF eqF2 = mainPageFragment.LJJIIJ;
            if (!(eqF2 == null || (LIZ2 = eqF2.LIZ()) == null)) {
                LIZ2.removeCallbacks(new C5057Eqz(mainPageFragment));
            }
            FissionPopupWindowHelp fissionPopupWindowHelp = mainPageFragment.LJJ;
            if (fissionPopupWindowHelp != null) {
                fissionPopupWindowHelp.LIZIZ();
            }
        }
    }

    public final void LJI() {
        MainPageFragment mainPageFragment;
        C5011EqF eqF;
        C5012EqG LJIILIIL;
        WeakReference<MainPageFragment> weakReference = this.LIZ;
        if (weakReference != null) {
            mainPageFragment = (MainPageFragment) weakReference.get();
        } else {
            mainPageFragment = null;
        }
        if (MHK.LIZ.LIZIZ()) {
            if (mainPageFragment != null && (LJIILIIL = mainPageFragment.LJIILIIL()) != null) {
                LJIILIIL.LIZ(false);
            }
        } else if (mainPageFragment != null && (eqF = mainPageFragment.LJJIIJ) != null) {
            eqF.LIZ(false);
        }
    }

    public static IMainPageFragment LJII() {
        MethodCollector.i(26);
        IMainPageFragment iMainPageFragment = (IMainPageFragment) Lnj.LIZ(IMainPageFragment.class, false);
        if (iMainPageFragment != null) {
            MethodCollector.o(26);
            return iMainPageFragment;
        }
        Object LIZIZ = Lnj.LIZIZ(IMainPageFragment.class, false);
        if (LIZIZ != null) {
            IMainPageFragment iMainPageFragment2 = (IMainPageFragment) LIZIZ;
            MethodCollector.o(26);
            return iMainPageFragment2;
        }
        if (Lnj.LJIIIIZZ == null) {
            synchronized (IMainPageFragment.class) {
                try {
                    if (Lnj.LJIIIIZZ == null) {
                        Lnj.LJIIIIZZ = new MainPageFragmentImpl();
                    }
                } catch (Throwable th) {
                    MethodCollector.o(26);
                    throw th;
                }
            }
        }
        MainPageFragmentImpl mainPageFragmentImpl = (MainPageFragmentImpl) Lnj.LJIIIIZZ;
        MethodCollector.o(26);
        return mainPageFragmentImpl;
    }

    public final void LIZ(1hK r1) {
        M12.LIZ(r1);
        C5169Esn.LIZIZ(r1);
    }

    public final void LIZIZ(1hK r1) {
        M12.LIZ(r1);
        C5169Esn.LIZ(r1);
    }

    public final void LIZ(Context context) {
        M12.LIZ(context);
        if (!(context instanceof MainActivity)) {
            context = null;
        }
        MainActivity mainActivity = (MainActivity) context;
        if (mainActivity != null) {
            mainActivity.refreshSlideSwitchCanScrollRight();
        }
    }

    public final void LIZ(0CG r3) {
        0CD lifecycle;
        M12.LIZ(r3);
        WeakReference<MainPageFragment> weakReference = this.LIZ;
        MainPageFragment mainPageFragment = null;
        if (weakReference != null) {
            mainPageFragment = (MainPageFragment) weakReference.get();
        }
        if ((mainPageFragment instanceof 0CH) && mainPageFragment != null && (lifecycle = mainPageFragment.getLifecycle()) != null) {
            lifecycle.LIZ(r3);
        }
    }

    public final void LIZ(Fragment fragment) {
        this.LIZ = new WeakReference<>(fragment);
    }

    public final void LIZ(ScrollSwitchStateManager scrollSwitchStateManager) {
        MainPageFragment mainPageFragment;
        C5011EqF eqF;
        C5012EqG LJIILIIL;
        M12.LIZ(scrollSwitchStateManager);
        WeakReference<MainPageFragment> weakReference = this.LIZ;
        if (weakReference != null) {
            mainPageFragment = (MainPageFragment) weakReference.get();
        } else {
            mainPageFragment = null;
        }
        if (MHK.LIZ.LIZIZ()) {
            if (mainPageFragment != null && (LJIILIIL = mainPageFragment.LJIILIIL()) != null) {
                LJIILIIL.LIZ(scrollSwitchStateManager);
            }
        } else if (mainPageFragment != null && (eqF = mainPageFragment.LJJIIJ) != null) {
            M12.LIZ(scrollSwitchStateManager);
            if (!n.LIZ("NOTIFICATION", eqF.LIZJ.LIZLLL)) {
                TabChangeManager.LIZ(eqF.LIZJ, "NOTIFICATION", true, 26);
                7df.LJJJI().LJJIII();
                2KS.LIZ().LIZIZ();
                eqF.LJI();
                scrollSwitchStateManager.LIZ(false);
                MainPageFragment mainPageFragment2 = eqF.LIZ;
                Objects.requireNonNull(mainPageFragment2, "null cannot be cast to non-null type com.ss.android.ugc.aweme.main.MainPageFragment");
                mainPageFragment2.LIZIZ(true);
                7xA.LIZ(C4602Eje.NOTICE);
            }
            eqF.LIZIZ.LIZ();
        }
    }

    public final void LIZ(boolean z) {
        MainPageFragment mainPageFragment;
        Context context;
        Resources resources;
        View view;
        int i;
        WeakReference<MainPageFragment> weakReference = this.LIZ;
        if (weakReference != null && (mainPageFragment = (MainPageFragment) weakReference.get()) != null && (context = mainPageFragment.getContext()) != null && (resources = context.getResources()) != null && mainPageFragment != null && (view = mainPageFragment.LIZIZ) != null) {
            if (!z) {
                i = 2131100203;
            } else {
                i = 2131099715;
            }
            view.setBackgroundColor(resources.getColor(i));
        }
    }

    public final void LIZ(String str, String str2) {
        MainPageFragment mainPageFragment;
        C5015EqJ eqJ;
        M12.LIZ(str, str2);
        WeakReference<MainPageFragment> weakReference = this.LIZ;
        if (weakReference != null && (mainPageFragment = (MainPageFragment) weakReference.get()) != null && (eqJ = mainPageFragment.LJJIFFI) != null) {
            M12.LIZ(str, str2);
            if (C5020EqO.LIZ.LIZIZ(str, str2) && C5020EqO.LIZ.LIZ(str2)) {
                C5020EqO.LIZ.LIZ(new 7ZL(new WeakReference(eqJ.LIZ.getActivity()), eqJ.LIZ(str2), eqJ.LIZ(str), (byte) 0));
            }
        }
    }
}
