package com.ss.android.ugc.aweme.inbox;

import X.0CC;
import X.0CD;
import X.0GK;
import X.0Gp;
import X.0Q2;
import X.0Q9;
import X.1Bn;
import X.1Cx;
import X.1DM;
import X.1I0;
import X.1hK;
import X.2GO;
import X.2HZ;
import X.2Pr;
import X.3PM;
import X.3he;
import X.3oA;
import X.7he;
import X.C0295Crj;
import X.C1885Dgv;
import X.C2645DtB;
import X.C2657DtN;
import X.C2658DtO;
import X.C2662DtS;
import X.C2663DtT;
import X.C2664DtU;
import X.C2665DtV;
import X.C2667DtX;
import X.C2676Dtg;
import X.C2680Dtk;
import X.C2683Dtn;
import X.C2690Dtu;
import X.C2691Dtv;
import X.C2693Dtx;
import X.C2695Dtz;
import X.C2696Du0;
import X.C2701Du5;
import X.C2704Du8;
import X.C2708DuC;
import X.C2709DuD;
import X.C2711DuF;
import X.C2712DuG;
import X.C2713DuH;
import X.C2715DuJ;
import X.C2716DuK;
import X.C2717DuL;
import X.C2719DuN;
import X.C2720DuO;
import X.C2722DuQ;
import X.C2725DuT;
import X.C2726DuU;
import X.C2728DuW;
import X.C2729DuX;
import X.C2730DuY;
import X.C2732Dua;
import X.C2733Dub;
import X.C2734Duc;
import X.C2740Dui;
import X.C2753Duv;
import X.C2756Duy;
import X.C2844DwO;
import X.C3040DzY;
import X.C3041DzZ;
import X.C3106E1m;
import X.C3136E2q;
import X.C4820EnA;
import X.C4829EnJ;
import X.C4941Ep7;
import X.C5380EwC;
import X.E2H;
import X.Gfd;
import X.ISm;
import X.Ikf;
import X.Lea;
import X.Ls2;
import X.M12;
import X.MHG;
import X.OQg;
import X.P8Q;
import X.P8R;
import X.Qw9;
import X.Rc9;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.SystemClock;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.LiveData;
import androidx.recyclerview.widget.RecyclerView;
import com.bytedance.covode.number.Covode;
import com.bytedance.hox.Hox;
import com.ss.android.ugc.aweme.benchmark.BenchmarkServiceImpl;
import com.ss.android.ugc.aweme.im.sdk.common.controller.providedservices.IMService;
import com.ss.android.ugc.aweme.inbox.vm.InboxActivityNoticeVM;
import com.ss.android.ugc.aweme.inbox.widget.InboxAdapterWidget;
import com.ss.android.ugc.aweme.inbox.widget.multi.MultiAdapterWidget;
import com.ss.android.ugc.aweme.inbox.widget.multi.NoticeAndDMCombineWidget;
import com.ss.android.ugc.aweme.inbox.widget.multi.vm.InboxTopHorizontalListVM;
import com.ss.android.ugc.aweme.main.TabChangeManager;
import com.ss.android.ugc.aweme.notification.view.FixedLinearlayoutManager;
import com.ss.android.ugc.aweme.services.story.event.StoryPublishEvent;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import kotlin.h.b.n;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.ThreadMode;

public final class InboxFragment extends BaseInboxFragment implements 0GK, 1I0, C4829EnJ, C5380EwC, C2734Duc, 2HZ, 2GO {
    public 1Cx LIZIZ;
    public FixedLinearlayoutManager LIZJ;
    public boolean LIZLLL;
    public boolean LJ = true;
    public final C0295Crj LJIIIZ = 7he.LIZ(C2726DuU.LIZ);
    public final C0295Crj LJIIJ = 7he.LIZ(new C2657DtN(this));
    public final C0295Crj LJIIJJI = 7he.LIZ(C2667DtX.LIZ);
    public final C0295Crj LJIIL = 7he.LIZ(new C2665DtV(this));
    public final C0295Crj LJIILIIL = 7he.LIZ(new C2662DtS(this));
    public final C0295Crj LJIILJJIL = 7he.LIZ(new C2663DtT(this));
    public final C0295Crj LJIILL = 7he.LIZ(new C2664DtU(this));
    public final C0295Crj LJIIZILJ = 7he.LIZ(new C2676Dtg(this));
    public final C0295Crj LJIJ = 7he.LIZ(new C2680Dtk(this));
    public final C0295Crj LJIJI = 7he.LIZ(new C2704Du8(this));
    public final C0295Crj LJIJJ = 7he.LIZ(new C2658DtO(this));
    public boolean LJIJJLI = true;
    public boolean LJIL;
    public boolean LJJ;
    public boolean LJJI;
    public Ls2<2Pr> LJJIFFI = new C2716DuK(this);
    public int LJJII;
    public SparseArray LJJIII;

    static {
        Covode.recordClassIndex(87774);
    }

    public final View LIZ(int i) {
        if (this.LJJIII == null) {
            this.LJJIII = new SparseArray();
        }
        View view = (View) this.LJJIII.get(i);
        if (view != null) {
            return view;
        }
        View view2 = getView();
        if (view2 == null) {
            return null;
        }
        View findViewById = view2.findViewById(i);
        this.LJJIII.put(i, findViewById);
        return findViewById;
    }

    public final void LJ() {
        SparseArray sparseArray = this.LJJIII;
        if (sparseArray != null) {
            sparseArray.clear();
        }
    }

    public final boolean LJI() {
        return ((Boolean) this.LJIIIZ.getValue()).booleanValue();
    }

    public final InboxFragmentVM LJII() {
        return (InboxFragmentVM) this.LJIIJ.getValue();
    }

    public final boolean LJIIIIZZ() {
        return ((Boolean) this.LJIIJJI.getValue()).booleanValue();
    }

    public final MultiAdapterWidget LJIIIZ() {
        return (MultiAdapterWidget) this.LJIIL.getValue();
    }

    public final NoticeAndDMCombineWidget LJIIJ() {
        return (NoticeAndDMCombineWidget) this.LJIILIIL.getValue();
    }

    public final InboxAdapterWidget LJIIJJI() {
        return (InboxAdapterWidget) this.LJIILJJIL.getValue();
    }

    public final InboxAdapterWidget LJIIL() {
        return (InboxAdapterWidget) this.LJIILL.getValue();
    }

    public final InboxAdapterWidget LJIILIIL() {
        return (InboxAdapterWidget) this.LJIIZILJ.getValue();
    }

    public final List<InboxAdapterWidget> LJIILJJIL() {
        return (List) this.LJIJ.getValue();
    }

    public final C2701Du5 LJIILL() {
        return (C2701Du5) this.LJIJI.getValue();
    }

    public final String az_() {
        return "MainTabPage";
    }

    public final String getBtmPageCode() {
        return "b9081";
    }

    public final Map<Integer, Object> getSubscriberEventTypes() {
        HashMap hashMap = new HashMap();
        hashMap.put(191, new Rc9(InboxFragment.class, "onSwitchInbox", C1885Dgv.class, ThreadMode.MAIN, 0, true));
        hashMap.put(265, new Rc9(InboxFragment.class, "onPrivacyUserSettingsChange", 3oA.class, ThreadMode.MAIN, 0, false));
        hashMap.put(356, new Rc9(InboxFragment.class, "onStoryPublishEventPost", StoryPublishEvent.class, ThreadMode.MAIN, 0, false));
        hashMap.put(447, new Rc9(InboxFragment.class, "onDoubleClickTab", C4941Ep7.class, ThreadMode.MAIN, 0, false));
        hashMap.put(348, new Rc9(InboxFragment.class, "onNewIntent", C2732Dua.class, ThreadMode.POSTING, 0, false));
        return hashMap;
    }

    public final /* synthetic */ void onDestroyView() {
        super.onDestroyView();
        LJ();
    }

    public final String LIZJ() {
        return Qw9.LIZ(this);
    }

    public final String aB_() {
        return 0Q9.LIZ(this);
    }

    public final boolean aD_() {
        M12.LIZ(this);
        return true;
    }

    public final Map<String, String> aE_() {
        return 0Q9.LIZIZ(this);
    }

    public final void onPause() {
        InboxFragment.super.onPause();
        C2733Dub.LIZ = null;
    }

    public final void onStart() {
        InboxFragment.super.onStart();
        LJIL();
    }

    public final void onStop() {
        InboxFragment.super.onStop();
        LJJ();
    }

    public final void LJIJI() {
        IMService.createIIMServicebyMonsterPlugin(false).processMessagingDeepLink(this);
    }

    private final void LJIL() {
        if (this.LJIJJLI && !this.LJIL) {
            BenchmarkServiceImpl.createIBenchmarkServicebyMonsterPlugin(false).startBenchmark(3);
            this.LJIL = true;
        }
    }

    private final void LJJ() {
        if (this.LJIJJLI && this.LJIL) {
            BenchmarkServiceImpl.createIBenchmarkServicebyMonsterPlugin(false).stopBenchmark();
            this.LJIL = false;
        }
    }

    public final P8R LIZIZ() {
        P8Q p8q = P8R.LIZ;
        Context requireContext = requireContext();
        n.LIZIZ(requireContext, "");
        return p8q.LIZ(requireContext, this);
    }

    public final void LJIILLIIL() {
        for (InboxAdapterWidget LIZ : LJIILJJIL()) {
            LIZ(LIZ);
        }
    }

    public final void LJIJJLI() {
        LIZ(2131370607).LIZ();
        OQg LIZ = LIZ(2131370607);
        n.LIZIZ(LIZ, "");
        LIZ.setVisibility(0);
        1DM LIZ2 = LIZ(2131365949);
        n.LIZIZ(LIZ2, "");
        LIZ2.setRefreshing(false);
    }

    public final boolean aC_() {
        0CD lifecycle = getLifecycle();
        n.LIZIZ(lifecycle, "");
        if (!lifecycle.LIZ().isAtLeast(0CC.CREATED)) {
            return false;
        }
        3he r1 = Hox.LJ;
        1hK requireActivity = requireActivity();
        n.LIZIZ(requireActivity, "");
        if (r1.LIZ(requireActivity).LIZLLL("NOTIFICATION")) {
            return true;
        }
        return false;
    }

    public final void LIZ() {
        1Bn<Boolean> LJ2;
        for (InboxAdapterWidget LIZLLL2 : LJIILJJIL()) {
            LIZLLL2.LIZLLL();
        }
        InboxAdapterWidget LJIIL2 = LJIIL();
        if (LJIIL2 != null && (LJ2 = LJIIL2.LJ()) != null) {
            LJ2.postValue(Boolean.valueOf(LJI()));
        }
    }

    public final void LJIJ() {
        LJII().LIZJ.observe(this, new C2696Du0(this));
        LJII().LIZLLL.observe(this, new C2711DuF(this));
        List<InboxAdapterWidget> LJIILJJIL2 = LJIILJJIL();
        if (!(LJIILJJIL2 instanceof Collection) || !LJIILJJIL2.isEmpty()) {
            Iterator<T> it = LJIILJJIL2.iterator();
            while (it.hasNext()) {
                if (n.LIZ(it.next(), LJIILIIL())) {
                    return;
                }
            }
        }
        LJII().LIZIZ.observe(this, new C2695Dtz(this));
    }

    public final void onDestroy() {
        InboxFragment.super.onDestroy();
        for (InboxAdapterWidget LIZIZ2 : LJIILJJIL()) {
            getLifecycle().LIZIZ(LIZIZ2);
        }
        EventBus.LIZ().LIZIZ(this);
        if (LIZ(2131365948) != null && MHG.LIZIZ.LIZIZ()) {
            Gfd LIZ = LIZ(2131365948);
            Ls2<2Pr> ls2 = this.LJJIFFI;
            if (ls2 != null) {
                ls2 = new C2730DuY(ls2);
            }
            LIZ.removeCallbacks((Runnable) ls2);
            3PM.LIZIZ("InboxFragment", "remove add item animator runnable");
        }
    }

    public InboxFragment() {
        C2708DuC.LIZJ.LIZ(C2722DuQ.LIZ);
        C3041DzZ.LIZ.LIZ();
        this.LJJII = -1;
    }

    public final void LJIIZILJ() {
        List<InboxAdapterWidget> LJIILJJIL2 = LJIILJJIL();
        if (!(LJIILJJIL2 instanceof Collection) || !LJIILJJIL2.isEmpty()) {
            for (InboxAdapterWidget LJFF : LJIILJJIL2) {
                if (!Lea.LIZ(InboxAdapterWidget.LJIIJJI, LJFF.LJFF().getValue())) {
                    return;
                }
            }
        }
        3PM.LIZIZ("InboxFragment", "all widget load end!");
        C2712DuG duG = C2708DuC.LIZ;
        if (duG != null) {
            Long.valueOf(duG.LIZ);
        }
        C2712DuG duG2 = C2708DuC.LIZ;
        if (duG2 != null) {
            duG2.LJIIJJI = SystemClock.uptimeMillis();
            long j = duG2.LIZ;
            long j2 = duG2.LIZIZ;
            C2753Duv duv = duG2.LIZJ;
            long j3 = duG2.LIZLLL;
            long j4 = duG2.LJ;
            long j5 = duG2.LJFF;
            long j6 = duG2.LJI;
            long j7 = duG2.LJII;
            long j8 = duG2.LJIIIIZZ;
            long j9 = duG2.LJIIIZ;
            long j10 = duG2.LJIIJ;
            long j11 = duG2.LJIIJJI;
            M12.LIZ(duv);
            0Gp.LIZ(new C2713DuH(new C2712DuG(j, j2, duv, j3, j4, j5, j6, j7, j8, j9, j10, j11)));
        }
        C2708DuC.LIZ = null;
        if (this.LJ) {
            C3040DzY.LIZ(new C2683Dtn(this));
            this.LJ = false;
            LJII().LIZ(C2693Dtx.ALL_ENDED);
        }
        if (!this.LJJI) {
            RecyclerView LIZ = LIZ(2131365948);
            n.LIZIZ(LIZ, "");
            if (LIZ.getItemAnimator() == null && MHG.LIZIZ.LIZIZ()) {
                3PM.LIZIZ("InboxFragment", "start add item animator");
                this.LJJI = true;
                Gfd LIZ2 = LIZ(2131365948);
                Ls2<2Pr> ls2 = this.LJJIFFI;
                if (ls2 != null) {
                    ls2 = new C2730DuY(ls2);
                }
                LIZ2.postDelayed((Runnable) ls2, 1500);
            }
        }
    }

    public final void onResume() {
        InboxFragment.super.onResume();
        C2733Dub.LIZ = "inbox_first_page";
        1hK activity = getActivity();
        if (activity != null && n.LIZ(TabChangeManager.LJII.LIZ(activity).LIZ(), this)) {
            0Q2.LIZ(this);
        }
        Ikf activityStatusViewModel = IMService.createIIMServicebyMonsterPlugin(false).getActivityStatusViewModel();
        if (activityStatusViewModel.LIZ().LJ()) {
            C2715DuJ duJ = new C2715DuJ(this);
            C2720DuO LIZ = activityStatusViewModel.LIZ();
            if (!LIZ.LIZIZ() || C2728DuW.LIZ.LIZ() == 3 || C2728DuW.LIZ.LIZ() == 4) {
                1hK requireActivity = requireActivity();
                n.LIZIZ(requireActivity, "");
                LIZ.LIZ(requireActivity, this, duJ);
            }
            if (!((LinearLayout) LIZ(2131365950)).hasOnClickListeners()) {
                ((LinearLayout) LIZ(2131365950)).setOnClickListener(new C2725DuT(this, LIZ, duJ));
            }
            LIZ(2131371254).setActive(IMService.createIIMServicebyMonsterPlugin(false).getActivityStatusViewModel().LIZ().LIZ());
        }
    }

    @ISm(LIZ = ThreadMode.MAIN)
    public final void onPrivacyUserSettingsChange(3oA r2) {
        M12.LIZ(r2);
        this.LIZLLL = true;
    }

    public final void LIZIZ(Bundle bundle) {
        M12.LIZ(bundle);
        LJJ();
        this.LJIJJLI = false;
    }

    public final void onCreate(Bundle bundle) {
        C2708DuC.LIZJ.LIZ(C2756Duy.ON_CREATE, new C2709DuD(this, bundle));
    }

    @ISm
    public final void onNewIntent(C2732Dua dua) {
        Intent intent;
        LIZ(false);
        C3106E1m e1m = C3106E1m.LIZ;
        if (dua != null) {
            intent = dua.LIZ;
        } else {
            intent = null;
        }
        e1m.LIZ((Fragment) this, intent);
        LJIJI();
    }

    @ISm(LIZ = ThreadMode.MAIN, LIZIZ = true)
    public final void onSwitchInbox(C1885Dgv dgv) {
        M12.LIZ(dgv);
        E2H.CONTACTS.markEnterInbox();
        this.LJ = true;
        C3136E2q.LIZJ.LIZ();
    }

    @ISm(LIZ = ThreadMode.MAIN)
    public final void onDoubleClickTab(C4941Ep7 ep7) {
        M12.LIZ(ep7);
        InboxFragmentVM LJII = LJII();
        List<InboxAdapterWidget> LJIILJJIL2 = LJIILJJIL();
        FixedLinearlayoutManager fixedLinearlayoutManager = this.LIZJ;
        if (fixedLinearlayoutManager == null) {
            n.LIZ("");
        }
        int LJIIJ2 = fixedLinearlayoutManager.LJIIJ();
        M12.LIZ(LJIILJJIL2);
        if (!LJII.LIZ(LJIILJJIL2, LJIIJ2, false) && !LJII.LIZ(LJIILJJIL2, 0, true)) {
            LJII.LIZ.postValue(0);
        }
    }

    @ISm(LIZ = ThreadMode.MAIN)
    public final void onStoryPublishEventPost(StoryPublishEvent storyPublishEvent) {
        M12.LIZ(storyPublishEvent);
        if (C2844DwO.LIZ.LJIILL().canShowStoryCell()) {
            LIZ(2131365948).LIZIZ(0);
            ((InboxTopHorizontalListVM) this.LJIJJ.getValue()).LIZJ();
            LIZ(2131365948).post(new C2729DuX(this));
        }
    }

    public final void LIZ(Bundle bundle) {
        M12.LIZ(bundle);
        0Q2.LIZ(this);
        String string = bundle.getString(C4820EnA.LIZIZ, "");
        3he r1 = Hox.LJ;
        1hK activity = getActivity();
        if (activity == null) {
            n.LIZIZ();
        }
        n.LIZIZ(activity, "");
        String LJFF = r1.LIZ(activity).LJFF("HOME");
        if (this.LJJ && aq_() && (n.LIZ(string, C4820EnA.LIZLLL) || bundle.getBoolean(LJFF))) {
            if (C2740Dui.LIZIZ.LIZ()) {
                LJIIJ().LIZLLL.LIZ = true;
            } else {
                LJIIIZ().LIZ = true;
            }
            3PM.LIZIZ("InboxFragment", "onNodeShow");
            LIZ();
            C3136E2q.LIZJ.LIZ();
            LJII().LIZ();
            InboxActivityNoticeVM.LIZ.LIZ(this).LJIIIZ().clear();
        }
        this.LJIJJLI = true;
        this.LJJ = true;
        LJIL();
    }

    public final void LIZ(InboxAdapterWidget inboxAdapterWidget) {
        try {
            inboxAdapterWidget.LJFF().observe(this, new C2690Dtu(this, inboxAdapterWidget));
            LiveData<Boolean> cO_ = inboxAdapterWidget.cO_();
            if (cO_ != null) {
                cO_.observe(this, new C2691Dtv(this));
            }
        } catch (Exception e) {
            3PM.LIZIZ("InboxFragment", "repeat add : " + e.getMessage());
        }
    }

    public final void LIZ(boolean z) {
        String str;
        String str2;
        String str3;
        Intent intent;
        Intent intent2;
        Intent intent3;
        Intent intent4;
        1hK activity = getActivity();
        int i = -1;
        if (!(activity == null || (intent4 = activity.getIntent()) == null)) {
            i = intent4.getIntExtra("intent_story_widget_action", -1);
        }
        this.LJJII = i;
        if (i == 1) {
            1hK activity2 = getActivity();
            if (activity2 == null || (intent3 = activity2.getIntent()) == null || (str = LIZ(intent3, "uid")) == null) {
                str = "";
            }
            n.LIZIZ(str, "");
            1hK activity3 = getActivity();
            if (activity3 == null || (intent2 = activity3.getIntent()) == null || (str2 = LIZ(intent2, "id")) == null) {
                str2 = "";
            }
            n.LIZIZ(str2, "");
            1hK activity4 = getActivity();
            if (activity4 == null || (intent = activity4.getIntent()) == null || (str3 = LIZ(intent, "enter_from")) == null) {
                str3 = "";
            }
            n.LIZIZ(str3, "");
            C2645DtB dtB = new C2645DtB(Long.parseLong(str), Long.parseLong(str2));
            if (C2740Dui.LIZIZ.LIZ()) {
                LJIIJ().LIZLLL.LIZ(dtB);
                LJIIJ().LIZLLL.LIZJ = str3;
                if (!z) {
                    LJIIJ().LIZLLL.LIZLLL();
                    return;
                }
                return;
            }
            LJIIIZ().LIZ(dtB);
            LJIIIZ().LIZJ = str3;
            if (!z) {
                LJIIIZ().LIZLLL();
            }
        }
    }

    public static String LIZ(Intent intent, String str) {
        try {
            return intent.getStringExtra(str);
        } catch (Exception unused) {
            return null;
        }
    }

    public final void onViewCreated(View view, Bundle bundle) {
        M12.LIZ(view);
        LIZ((Ls2<2Pr>) new C2717DuL(this, view, bundle));
    }

    public final void onActivityResult(int i, int i2, Intent intent) {
        InboxFragment.super.onActivityResult(i, i2, intent);
        InboxAdapterWidget LJIIL2 = LJIIL();
        if (LJIIL2 != null) {
            LJIIL2.LIZ(i, i2, intent);
        }
    }

    public final View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        M12.LIZ(layoutInflater);
        return (View) C2708DuC.LIZJ.LIZ(C2756Duy.ON_CREATE_VIEW, new C2719DuN(this, layoutInflater, viewGroup));
    }
}
