package com.ss.android.ugc.aweme.tools.draft.ftc.pages;

import X.0CH;
import X.0HH;
import X.1hK;
import X.2GO;
import X.2HZ;
import X.2nK;
import X.3BB;
import X.3SC;
import X.3af;
import X.3br;
import X.4Tk;
import X.4r1;
import X.7he;
import X.AnonymousClass5CV;
import X.AnonymousClass6J4;
import X.AnonymousClass74H;
import X.AnonymousClass7AN;
import X.AnonymousClass7AS;
import X.AnonymousClass7B0;
import X.AnonymousClass7B3;
import X.AnonymousClass7B5;
import X.AnonymousClass7BH;
import X.AnonymousClass7BI;
import X.AnonymousClass7BJ;
import X.C37926di;
import X.C42006kI;
import X.C42016kJ;
import X.C54357Ab;
import X.C54367Ac;
import X.C54427Ai;
import X.C54467Am;
import X.C54477An;
import X.C54487Ao;
import X.C54497Ap;
import X.C54507Aq;
import X.C54537At;
import X.C54577Ax;
import X.C54587Ay;
import X.CqM;
import X.Crj;
import X.D8s;
import X.DAe;
import X.FWb;
import X.ISm;
import X.LeS;
import X.M12;
import X.NO8;
import X.OQh;
import X.Rc9;
import X.Szo;
import X.T3t;
import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import androidx.fragment.app.Fragment;
import com.bytedance.covode.number.Covode;
import com.ss.android.ugc.aweme.shortvideo.edit.VideoPublishEditModel;
import com.ss.android.ugc.aweme.tools.draft.ftc.viewmodel.KidsDraftFeedViewModel;
import com.ss.android.ugc.aweme.tools.draft.ftc.viewmodel.KidsDraftOptionViewModel;
import java.util.HashMap;
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 KidsDraftVideoFeedFragment extends Fragment implements AnonymousClass7BJ, 2HZ, 2GO {
    public static C42016kJ LJII;
    public static final AnonymousClass7BI LJIIIIZZ = new AnonymousClass7BI((byte) 0);
    public VideoPublishEditModel LIZ;
    public C42016kJ LIZIZ;
    public int LIZJ = 1;
    public boolean LIZLLL = true;
    public AnonymousClass7AN LJ;
    public final Crj LJFF = 7he.LIZ(AnonymousClass74H.LIZ);
    public final Crj LJI = 7he.LIZ(new AnonymousClass7B0(this));
    public final Crj LJIIIZ = 7he.LIZ(new C54427Ai(this));
    public final Crj LJIIJ = 7he.LIZ(new C54577Ax(this));
    public final Crj LJIIJJI = 7he.LIZ(new C54537At(this));
    public HashMap LJIIL;

    static {
        Covode.recordClassIndex(119551);
    }

    public final C54367Ac LIZ() {
        return (C54367Ac) this.LJIIIZ.getValue();
    }

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

    public final KidsDraftFeedViewModel LIZIZ() {
        return (KidsDraftFeedViewModel) this.LJIIJ.getValue();
    }

    public final Map<Integer, Object> getSubscriberEventTypes() {
        HashMap hashMap = new HashMap();
        hashMap.put(379, new Rc9(KidsDraftVideoFeedFragment.class, "handleDownloadVideoStatus", AnonymousClass7AS.class, ThreadMode.MAIN, 0, false));
        return hashMap;
    }

    public final void LJ() {
        LIZ(false);
    }

    public final void onPause() {
        KidsDraftVideoFeedFragment.super.onPause();
        C54357Ab LIZIZ2 = LIZ().LIZIZ(this.LIZJ - 1);
        if (LIZIZ2 != null) {
            LIZIZ2.LIZ(false);
        }
    }

    public final void onResume() {
        KidsDraftVideoFeedFragment.super.onResume();
        C54357Ab LIZIZ2 = LIZ().LIZIZ(this.LIZJ - 1);
        if (LIZIZ2 != null) {
            LIZIZ2.LIZ(true);
        }
    }

    public final void onDestroyView() {
        KidsDraftVideoFeedFragment.super.onDestroyView();
        C54507Aq.LJIIJJI.LIZ();
        CqM.LIZ(new 4Tk());
        if (EventBus.LIZ().LIZ(this)) {
            EventBus.LIZ().LIZIZ(this);
        }
        C54507Aq.LJIIIIZZ.remove(this);
        AnonymousClass7AN.LIZLLL = true;
        HashMap hashMap = this.LJIIL;
        if (hashMap != null) {
            hashMap.clear();
        }
    }

    public final void LIZJ() {
        if (AnonymousClass7AN.LIZJ) {
            LIZ(true);
            if (LIZ(2131364225) != null) {
                ((C54507Aq) LIZ(2131364225)).LIZ(C54507Aq.LJIIJ);
                return;
            }
            return;
        }
        if (LIZ(2131364225) != null) {
            LIZ(2131364225);
            if (C54507Aq.LJIIIZ.hasMessages(1)) {
                LIZ(true);
                ((C54507Aq) LIZ(2131364225)).LIZIZ();
                return;
            }
        }
        if (LIZ(2131364225) != null) {
            LIZ(2131364225);
            if (C54507Aq.LJIIIZ.hasMessages(2)) {
                LIZ(true);
                ((C54507Aq) LIZ(2131364225)).LIZJ();
                return;
            }
        }
        LIZ(false);
    }

    public final void LIZLLL() {
        String str;
        AnonymousClass7AN r5 = this.LJ;
        if (r5 == null) {
            n.LIZ("");
        }
        1hK activity = getActivity();
        if (activity == null) {
            n.LIZIZ();
        }
        VideoPublishEditModel videoPublishEditModel = this.LIZ;
        0CH viewLifecycleOwner = getViewLifecycleOwner();
        n.LIZIZ(viewLifecycleOwner, "");
        AnonymousClass7B5 r0 = (AnonymousClass7B5) LIZ(2131368784);
        n.LIZIZ(r0, "");
        r5.LIZ(activity, videoPublishEditModel, viewLifecycleOwner, r0);
        AnonymousClass6J4 r3 = new AnonymousClass6J4();
        NO8 LJ2 = FWb.LIZIZ.LIZ().LJJIIJ().LJ();
        String str2 = null;
        if (LJ2 != null) {
            str = LJ2.LIZJ();
        } else {
            str = null;
        }
        r3.LIZ("author_id", str);
        C42016kJ r02 = this.LIZIZ;
        if (r02 != null) {
            str2 = r02.LJFF().getCreationId();
        }
        r3.LIZ("group_id", str2);
        2nK.LIZ("download_retry", r3.LIZ);
    }

    public final void onDestroy() {
        AnonymousClass5CV LIZ2;
        KidsDraftVideoFeedFragment.super.onDestroy();
        C54367Ac LIZ3 = LIZ();
        for (Map.Entry next : LIZ3.LIZJ.entrySet()) {
            int intValue = ((Number) next.getKey()).intValue();
            next.getValue();
            C54357Ab r0 = LIZ3.LIZJ.get(Integer.valueOf(intValue));
            if (!(r0 == null || (LIZ2 = r0.LIZ()) == null)) {
                LIZ2.LIZIZ();
            }
        }
    }

    public final C42016kJ LIZ(VideoPublishEditModel videoPublishEditModel) {
        return new C42006kI("VideoPublishFragment").LIZ(videoPublishEditModel, "KidsEdit");
    }

    private final void LIZ(boolean z) {
        FrameLayout frameLayout;
        FrameLayout frameLayout2;
        if (LIZ(2131364225) == null) {
            return;
        }
        if (z) {
            C54507Aq r0 = (C54507Aq) LIZ(2131364225);
            n.LIZIZ(r0, "");
            r0.setVisibility(0);
            if (LIZ(2131364791) != null) {
                FrameLayout frameLayout3 = (FrameLayout) LIZ(2131364791);
                n.LIZIZ(frameLayout3, "");
                frameLayout3.setVisibility(0);
                C54357Ab LIZIZ2 = LIZ().LIZIZ(this.LIZJ - 1);
                if (LIZIZ2 != null && (frameLayout2 = LIZIZ2.LJIIJ) != null) {
                    ViewGroup.LayoutParams layoutParams = frameLayout2.getLayoutParams();
                    if (layoutParams != null) {
                        layoutParams.height = (int) C37926di.LIZIZ(getContext(), 37.0f);
                    }
                    if (frameLayout2 != null) {
                        frameLayout2.setLayoutParams(layoutParams);
                        frameLayout2.requestLayout();
                        return;
                    }
                    return;
                }
                return;
            }
            return;
        }
        C54507Aq r02 = (C54507Aq) LIZ(2131364225);
        n.LIZIZ(r02, "");
        r02.setVisibility(8);
        if (LIZ(2131364791) != null) {
            FrameLayout frameLayout4 = (FrameLayout) LIZ(2131364791);
            n.LIZIZ(frameLayout4, "");
            frameLayout4.setVisibility(8);
            C54357Ab LIZIZ3 = LIZ().LIZIZ(this.LIZJ - 1);
            if (LIZIZ3 != null && (frameLayout = LIZIZ3.LJIIJ) != null) {
                ViewGroup.LayoutParams layoutParams2 = frameLayout.getLayoutParams();
                if (layoutParams2 != null) {
                    layoutParams2.height = 0;
                }
                if (frameLayout != null) {
                    frameLayout.setLayoutParams(layoutParams2);
                    frameLayout.requestLayout();
                }
            }
        }
    }

    @ISm(LIZ = ThreadMode.MAIN)
    public final void handleDownloadVideoStatus(AnonymousClass7AS r10) {
        boolean z;
        Integer num;
        String str;
        String str2;
        String str3;
        String str4;
        String str5;
        String str6;
        M12.LIZ(r10);
        AnonymousClass7BH r1 = r10.LIZ;
        if (r1 == null || AnonymousClass7BH.LIZ != 3) {
            z = true;
        } else {
            z = false;
        }
        LIZ(z);
        String str7 = null;
        if (r1 != null) {
            num = Integer.valueOf(AnonymousClass7BH.LIZ);
        } else {
            num = null;
        }
        if (num != null) {
            if (num.intValue() == 1) {
                C54507Aq r2 = (C54507Aq) LIZ(2131364225);
                r2.LIZLLL();
                r2.LIZ();
                C54507Aq.LJIIJ = 0;
                ImageView imageView = r2.LIZIZ;
                if (imageView == null) {
                    n.LIZ("");
                }
                imageView.setVisibility(8);
                TextView textView = r2.LIZJ;
                if (textView == null) {
                    n.LIZ("");
                }
                textView.setVisibility(8);
                TextView textView2 = r2.LJFF;
                if (textView2 == null) {
                    n.LIZ("");
                }
                textView2.setVisibility(8);
                RelativeLayout relativeLayout = r2.LIZ;
                if (relativeLayout == null) {
                    n.LIZ("");
                }
                relativeLayout.setBackgroundColor(Color.parseColor("#383838"));
                RelativeLayout relativeLayout2 = r2.LIZ;
                if (relativeLayout2 == null) {
                    n.LIZ("");
                }
                relativeLayout2.setVisibility(0);
                TextView textView3 = r2.LIZLLL;
                if (textView3 == null) {
                    n.LIZ("");
                }
                textView3.setVisibility(0);
                TextView textView4 = r2.LJ;
                if (textView4 == null) {
                    n.LIZ("");
                }
                textView4.setVisibility(0);
                TextView textView5 = r2.LJI;
                if (textView5 == null) {
                    n.LIZ("");
                }
                textView5.setVisibility(0);
                RelativeLayout relativeLayout3 = r2.LIZ;
                if (relativeLayout3 == null) {
                    n.LIZ("");
                }
                relativeLayout3.requestLayout();
                VideoPublishEditModel videoPublishEditModel = AnonymousClass7BH.LIZJ;
                if (videoPublishEditModel != null) {
                    str2 = videoPublishEditModel.getCreationId();
                } else {
                    str2 = null;
                }
                VideoPublishEditModel videoPublishEditModel2 = this.LIZ;
                if (videoPublishEditModel2 != null) {
                    str7 = videoPublishEditModel2.getCreationId();
                }
                LIZ(n.LIZ(str2, str7));
                AnonymousClass6J4 r3 = new AnonymousClass6J4();
                r3.LIZ("start_download", System.currentTimeMillis());
                2nK.LIZ("download_start", r3.LIZ);
                return;
            } else if (num.intValue() == 2) {
                VideoPublishEditModel videoPublishEditModel3 = AnonymousClass7BH.LIZJ;
                if (videoPublishEditModel3 != null) {
                    str = videoPublishEditModel3.getCreationId();
                } else {
                    str = null;
                }
                VideoPublishEditModel videoPublishEditModel4 = this.LIZ;
                if (videoPublishEditModel4 != null) {
                    str7 = videoPublishEditModel4.getCreationId();
                }
                if (n.LIZ(str, str7)) {
                    ((C54507Aq) LIZ(2131364225)).LIZ(AnonymousClass7BH.LIZIZ);
                    return;
                } else {
                    LIZ(false);
                    return;
                }
            } else if (num.intValue() == 3) {
                AnonymousClass7AN r0 = this.LJ;
                if (r0 == null) {
                    n.LIZ("");
                }
                r0.LIZ = true;
                return;
            }
        }
        if (num != null) {
            if (num.intValue() == 4) {
                VideoPublishEditModel videoPublishEditModel5 = AnonymousClass7BH.LIZJ;
                if (videoPublishEditModel5 != null) {
                    str4 = videoPublishEditModel5.getCreationId();
                } else {
                    str4 = null;
                }
                VideoPublishEditModel videoPublishEditModel6 = this.LIZ;
                if (videoPublishEditModel6 != null) {
                    str5 = videoPublishEditModel6.getCreationId();
                } else {
                    str5 = null;
                }
                if (n.LIZ(str4, str5)) {
                    ((C54507Aq) LIZ(2131364225)).LIZIZ();
                    LIZ(true);
                } else {
                    LIZ(false);
                    3BB r5 = new 3BB(getContext());
                    r5.LIZIZ(2131826485);
                    r5.LIZ();
                    3af r12 = r5.LIZ;
                    if (r12 != null) {
                        r12.LIZLLL(2130968646);
                    }
                    r5.LIZIZ();
                }
                AnonymousClass6J4 r7 = new AnonymousClass6J4();
                r7.LIZ("end_download", System.currentTimeMillis());
                NO8 LJ2 = FWb.LIZIZ.LIZ().LJJIIJ().LJ();
                if (LJ2 != null) {
                    str6 = LJ2.LIZJ();
                } else {
                    str6 = null;
                }
                r7.LIZ("author_id", str6);
                if (videoPublishEditModel5 != null) {
                    str7 = videoPublishEditModel5.getCreationId();
                }
                r7.LIZ("group_id", str7);
                r7.LIZ("is_self_video", 1);
                2nK.LIZ("download_end", r7.LIZ);
            } else if (num.intValue() == 5) {
                ((C54507Aq) LIZ(2131364225)).LIZJ();
                LIZ(true);
                AnonymousClass6J4 r13 = new AnonymousClass6J4();
                NO8 LJ3 = FWb.LIZIZ.LIZ().LJJIIJ().LJ();
                if (LJ3 != null) {
                    str3 = LJ3.LIZJ();
                } else {
                    str3 = null;
                }
                r13.LIZ("author_id", str3);
                C42016kJ r02 = this.LIZIZ;
                if (r02 != null) {
                    str7 = r02.LJFF().getCreationId();
                }
                r13.LIZ("group_id", str7);
                2nK.LIZ("download_fail", r13.LIZ);
            }
        }
    }

    public final int LIZ(List<? extends VideoPublishEditModel> list, VideoPublishEditModel videoPublishEditModel) {
        if (videoPublishEditModel == null) {
            return 0;
        }
        int i = 0;
        for (T next : list) {
            int i2 = i + 1;
            if (i < 0) {
                LeS.LIZIZ();
            }
            if (n.LIZ(videoPublishEditModel.getCreationId(), ((VideoPublishEditModel) next).getCreationId())) {
                return i;
            }
            i = i2;
        }
        return 0;
    }

    public final void onViewCreated(View view, Bundle bundle) {
        M12.LIZ(view);
        KidsDraftVideoFeedFragment.super.onViewCreated(view, bundle);
        LIZ(2131367406).setStatus(new OQh());
        LIZ(2131367406).LIZ();
        LIZ(2131362572).setOnClickListener(new AnonymousClass7B3(this));
        C54507Aq.LJIIIIZZ.add(this);
        ((C54507Aq) LIZ(2131364225)).setVideoDownloadClickListener(this);
        T3t LIZ2 = LIZ(2131364787);
        n.LIZIZ(LIZ2, "");
        LIZ2.setAdapter(LIZ());
        T3t LIZ3 = LIZ(2131364787);
        n.LIZIZ(LIZ3, "");
        LIZ3.setVisibility(8);
        LIZ(2131364787).LIZ(new C54487Ao(this));
        3br LIZ4 = LIZ(2131367439);
        LIZ4.LIZ = LIZ(2131364787);
        LIZ4.LIZIZ = null;
        KidsDraftFeedViewModel LIZIZ2 = LIZIZ();
        LIZIZ2.LIZ = DAe.LIZ(3SC.LIZ, (D8s) null, new C54587Ay(LIZIZ2, (4r1) null), 3);
        ((KidsDraftOptionViewModel) this.LJIIJJI.getValue()).LIZ.observe(getViewLifecycleOwner(), new C54467Am(this));
        LIZIZ().LIZIZ.observe(getViewLifecycleOwner(), new C54497Ap(this));
        LIZIZ().LIZJ.observe(getViewLifecycleOwner(), new C54477An(this));
    }

    public final View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        M12.LIZ(layoutInflater);
        Szo LIZ2 = Szo.LIZIZ.LIZ(this);
        LIZ2.LIZ(2131099677);
        LIZ2.LIZIZ(false);
        LIZ2.LIZ.LIZJ();
        if (!EventBus.LIZ().LIZ(this)) {
            EventBus.LIZ(EventBus.LIZ(), this);
        }
        AnonymousClass7AN.LIZLLL = false;
        return 0HH.LIZ(layoutInflater, 2131560293, viewGroup, false);
    }
}
