package com.ss.android.ugc.aweme.choosemusic.fragment;

import X.0A9;
import X.0AA;
import X.0AP;
import X.0Bs;
import X.0Bv;
import X.0Bx;
import X.0By;
import X.0HH;
import X.1hK;
import X.2GD;
import X.2GO;
import X.2HZ;
import X.2UX;
import X.2ha;
import X.2nK;
import X.BJk;
import X.BcV;
import X.C0131MIu;
import X.C5238ONt;
import X.C5379OTe;
import X.C5397OTw;
import X.Cbz;
import X.CjP;
import X.CjQ;
import X.ISm;
import X.OSU;
import X.OSX;
import X.OT0;
import X.OTJ;
import X.OTK;
import X.OTM;
import X.OTV;
import X.OVT;
import X.Rc9;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewStub;
import android.view.Window;
import android.widget.TextView;
import androidx.fragment.app.Fragment;
import com.bytedance.covode.number.Covode;
import com.ss.android.ugc.aweme.base.fragment.AmeBaseFragment;
import com.ss.android.ugc.aweme.base.model.UrlModel;
import com.ss.android.ugc.aweme.choosemusic.activity.ChooseMusicActivity;
import com.ss.android.ugc.aweme.choosemusic.activity.MusicBottomSheetBehavior;
import com.ss.android.ugc.aweme.choosemusic.cutmusic.ChooseMusicCutViewModel;
import com.ss.android.ugc.aweme.choosemusic.model.ChooseMusicWithSceneViewModel;
import com.ss.android.ugc.aweme.choosemusic.view.ChooseMusicSelectView;
import com.ss.android.ugc.aweme.choosemusic.viewmodel.SelectedMusicViewModel;
import com.ss.android.ugc.aweme.commercialize.media.impl.service.CommerceMediaServiceImpl;
import com.ss.android.ugc.aweme.music.model.Music;
import com.ss.android.ugc.aweme.search.SearchServiceImpl;
import com.ss.android.ugc.aweme.shortvideo.model.MusicModel;
import java.util.HashMap;
import java.util.Map;
import org.greenrobot.eventbus.ThreadMode;

public abstract class BaseChooseMusicFragment extends AmeBaseFragment implements View.OnClickListener, 0A9, 2HZ, 2GO {
    public int LIZ;
    public NewMusicTabFragment LIZIZ;
    public boolean LIZJ;
    public OTV LIZLLL;
    public 1hK LJ;
    public OT0 LJIIIZ;
    public View LJIIJ;
    public TextView LJIIJJI;
    public View LJIIL;
    public boolean LJIILIIL;
    public boolean LJIILJJIL;
    public boolean LJIILL;
    public UrlModel LJIIZILJ;
    public int LJIJ;
    public String LJIJI;
    public ChooseMusicCutViewModel LJIJJ;
    public SelectedMusicViewModel LJIJJLI;
    public int LJIL;
    public ChooseMusicSelectView LJJ;
    public TextWatcher LJJI = new TextWatcher() {
        static {
            Covode.recordClassIndex(56112);
        }

        public final void afterTextChanged(Editable editable) {
        }

        public final void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
        }

        public final void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
        }
    };
    public BcV LJJIFFI;
    public String LJJII;
    public BJk LJJIII;
    public Music LJJIIJ;
    public String LJJIIJZLJL;
    public String LJJIIZ;
    public boolean LJJIIZI;
    public MusicModel LJJIJ;
    public String LJJIJIIJI;
    public String LJJIJIIJIL;
    public boolean LJJIJIL;
    public long LJJIJL;
    public long LJJIJLIJ;
    public boolean LJJIL;
    public View LJJIZ;
    public View LJJJ;
    public View LJJJI;
    public View LJJJIL;
    public View LJJJJ;
    public View LJJJJI;
    public ViewStub LJJJJIZL;
    public ViewStub LJJJJJ;

    static {
        Covode.recordClassIndex(56106);
    }

    public final void LIZ() {
    }

    public final boolean LJJIJIIJI() {
        return true;
    }

    public Map<Integer, Object> getSubscriberEventTypes() {
        HashMap hashMap = new HashMap();
        hashMap.put(94, new Rc9(BaseChooseMusicFragment.class, "onSearchMusicPageStateEvent", OTJ.class, ThreadMode.POSTING, 0, false));
        hashMap.put(304, new Rc9(BaseChooseMusicFragment.class, "onMusicBottomToastEvent", OTK.class, ThreadMode.MAIN, 0, false));
        return hashMap;
    }

    public void onDestroy() {
        BaseChooseMusicFragment.super.onDestroy();
    }

    public void onDestroyView() {
        getChildFragmentManager().LIZIZ(this);
        OT0 ot0 = this.LJIIIZ;
        if (ot0 != null) {
            ot0.LIZIZ();
        }
        ChooseMusicSelectView chooseMusicSelectView = this.LJJ;
        if (chooseMusicSelectView != null) {
            chooseMusicSelectView.LIZ();
        }
        BaseChooseMusicFragment.super.onDestroyView();
    }

    public final void LIZJ() {
        SearchServiceImpl.LJJIIZ().LJI().LIZ(getFragmentManager());
        0AA childFragmentManager = getChildFragmentManager();
        Fragment LIZ2 = childFragmentManager.LIZ(2131365160);
        if (LIZ2 != null && LIZ2.isAdded()) {
            0AP LIZ3 = childFragmentManager.LIZ();
            LIZ3.LIZ(LIZ2);
            LIZ3.LIZJ();
        }
        Cbz.LIZ(this.LJJJI, 8);
        Cbz.LIZ(this.LJJJIL, 0);
        this.LIZJ = false;
    }

    public final MusicBottomSheetBehavior LIZLLL() {
        ChooseMusicActivity activity = getActivity();
        if (activity instanceof ChooseMusicActivity) {
            MusicBottomSheetBehavior musicBottomSheetBehavior = activity.LIZIZ;
            if (musicBottomSheetBehavior == null || !(musicBottomSheetBehavior instanceof MusicBottomSheetBehavior)) {
                return null;
            }
            return musicBottomSheetBehavior;
        } else if (activity == null) {
            return null;
        } else {
            MusicBottomSheetBehavior musicBottomSheetBehavior2 = LIZ((1hK) activity).LIZ(ChooseMusicWithSceneViewModel.class).LIZJ;
            if (musicBottomSheetBehavior2 instanceof MusicBottomSheetBehavior) {
                return musicBottomSheetBehavior2;
            }
            return null;
        }
    }

    public final void LIZIZ() {
        if (this.LJJJJI == null || getActivity() == null || !C5238ONt.LIZ.LIZJ()) {
            if (this.LJJJJIZL.getParent() != null) {
                View inflate = this.LJJJJIZL.inflate();
                this.LJIIJ = inflate.findViewById(2131363127);
                this.LJIIJJI = (TextView) inflate.findViewById(2131363858);
                this.LJIIL = inflate.findViewById(2131363128);
            }
        } else if (this.LJJJJJ.getParent() != null) {
            ChooseMusicSelectView chooseMusicSelectView = new ChooseMusicSelectView(this.LJJJJJ.inflate(), getActivity(), this);
            this.LJJ = chooseMusicSelectView;
            chooseMusicSelectView.LIZ(new OSX(OSU.LIZ, (String) null, (String) null, OSU.LIZ));
            this.LJJ.LIZ((int) this.LJJIJLIJ, (int) this.LJJIJL);
            this.LJJ.LIZ((C5397OTw<OVT>) this.LIZIZ);
            this.LJJ.LJIIIZ = new C5379OTe() {
                static {
                    Covode.recordClassIndex(56107);
                }

                public final void LIZ() {
                    BaseChooseMusicFragment.this.LIZIZ.LJ();
                    BaseChooseMusicFragment.this.LIZIZ.LJFF();
                }

                public final void LIZIZ() {
                    BaseChooseMusicFragment.this.LIZIZ.LJ();
                    BaseChooseMusicFragment.this.LIZIZ.LJFF();
                }

                public final void LIZ(MusicModel musicModel) {
                    1hK activity = BaseChooseMusicFragment.this.getActivity();
                    0Bx LIZ2 = 0By.LIZ(activity, (0Bv) null);
                    if (2GD.LIZ) {
                        0Bs.LIZ(LIZ2, activity);
                    }
                    LIZ2.LIZ(ChooseMusicWithSceneViewModel.class).LIZIZ = true;
                    BaseChooseMusicFragment.this.LIZ(musicModel);
                }

                public final void LIZ(MusicModel musicModel, boolean z) {
                    String str;
                    NewMusicTabFragment newMusicTabFragment = BaseChooseMusicFragment.this.LIZIZ;
                    if (z) {
                        str = "follow_type";
                    } else {
                        str = "unfollow_type";
                    }
                    newMusicTabFragment.LIZ(new OVT(musicModel, str, -1, -1));
                }
            };
        }
    }

    public static 0Bx LIZ(1hK r2) {
        0Bx LIZ2 = 0By.LIZ(r2, (0Bv) null);
        if (2GD.LIZ) {
            0Bs.LIZ(LIZ2, r2);
        }
        return LIZ2;
    }

    @ISm(LIZ = ThreadMode.MAIN)
    public void onMusicBottomToastEvent(OTK otk) {
        CjP.LIZ.LIZ(this.LJJJJ, 2ha.LIZ(40.0d), 300, true);
    }

    @ISm
    public void onSearchMusicPageStateEvent(OTJ otj) {
        if (otj != null) {
            if (otj.LIZ != 0) {
                Cbz.LIZ(this.LJJJ, 8);
                Cbz.LIZ(this.LJJIZ, 0);
            } else {
                Cbz.LIZ(this.LJJJ, 0);
                Cbz.LIZ(this.LJJIZ, 8);
            }
            if (otj.LIZ == -1) {
                Cbz.LIZ(this.LJJJIL, 0);
                Cbz.LIZ(this.LJJJI, 8);
            }
        }
    }

    public final void LIZ(MusicModel musicModel) {
        2UX r2 = new 2UX();
        r2.LIZ("creation_id", this.LJJIJIIJI);
        r2.LIZ("enter_from", "change_music_page" + "_" + OSU.LIZ.split("_")[1]);
        r2.LIZ("shoot_way", this.LJJIJIIJIL);
        r2.LIZ("music_id", musicModel.getMusicId());
        if (OSU.LIZ().booleanValue()) {
            r2.LIZ("from_location", OSU.LJI);
            r2.LIZ("type", OSU.LJII);
            r2.LIZ("is_editor_pro", 1);
        }
        2nK.LIZ("unselect_music", r2.LIZ);
    }

    /* JADX WARNING: Code restructure failed: missing block: B:11:0x0060, code lost:
        if (r2 != null) goto L_0x0062;
     */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public void onClick(android.view.View r6) {
        /*
            r5 = this;
            int r1 = r6.getId()
            r0 = 2131369674(0x7f0a1eca, float:1.8359333E38)
            if (r1 != r0) goto L_0x00aa
            com.ss.android.ugc.aweme.IAccountService r0 = com.ss.android.ugc.aweme.AccountService.LIZ()
            com.ss.android.ugc.aweme.IAccountUserService r0 = r0.LJFF()
            boolean r0 = r0.isChildrenMode()
            if (r0 == 0) goto L_0x002a
            X.3BB r1 = new X.3BB
            android.content.Context r0 = r5.getContext()
            r1.<init>(r0)
            r0 = 2131822537(0x7f1107c9, float:1.9277848E38)
            r1.LIZIZ(r0)
            r1.LIZIZ()
            return
        L_0x002a:
            r0 = 1
            r5.LIZJ = r0
            android.view.View r1 = r5.LJJJI
            r0 = 0
            X.Cbz.LIZ(r1, r0)
            android.view.View r1 = r5.LJJJIL
            r0 = 4
            X.Cbz.LIZ(r1, r0)
            X.0AA r4 = r5.getChildFragmentManager()
            r3 = 2131365160(0x7f0a0d28, float:1.8350177E38)
            androidx.fragment.app.Fragment r2 = r4.LIZ(r3)
            if (r2 != 0) goto L_0x0062
            com.ss.android.ugc.aweme.search.ISearchService r1 = com.ss.android.ugc.aweme.search.SearchServiceImpl.LJJIIZ()
            android.os.Bundle r0 = r5.getArguments()
            X.OTI r2 = r1.LIZ(r0)
            com.ss.android.ugc.aweme.choosemusic.fragment.BaseChooseMusicFragment$3 r0 = new com.ss.android.ugc.aweme.choosemusic.fragment.BaseChooseMusicFragment$3
            r0.<init>()
            r2.LIZ(r0)
            boolean r0 = r2 instanceof androidx.fragment.app.Fragment
            if (r0 == 0) goto L_0x0074
            androidx.fragment.app.Fragment r2 = (androidx.fragment.app.Fragment) r2
            if (r2 == 0) goto L_0x0074
        L_0x0062:
            boolean r0 = r2.isAdded()
            if (r0 != 0) goto L_0x0074
            X.0AP r1 = r4.LIZ()
            java.lang.String r0 = "ChooseSearchMusicFragment"
            r1.LIZ(r3, r2, r0)
            r1.LIZJ()
        L_0x0074:
            com.ss.android.ugc.aweme.choosemusic.fragment.NewMusicTabFragment r0 = r5.LIZIZ
            r0.LJ()
            com.ss.android.ugc.aweme.choosemusic.fragment.NewMusicTabFragment r0 = r5.LIZIZ
            r0.LJFF()
            X.2UX r2 = new X.2UX
            r2.<init>()
            java.lang.String r1 = "enter_from"
            java.lang.String r0 = "change_music_page"
            r2.LIZ(r1, r0)
            java.lang.String r1 = X.OSU.LIZLLL
            java.lang.String r0 = "creation_id"
            r2.LIZ(r0, r1)
            com.ss.android.ugc.aweme.services.external.ICommerceToolsService r1 = com.ss.android.ugc.aweme.commerce.tools.common.CommerceToolsService.LIZ()
            java.lang.String r0 = "is_commercial"
            java.lang.String[] r0 = new java.lang.String[]{r0}
            java.util.Map r0 = r1.getPageContextMobValues(r0)
            r2.LIZ(r0)
            java.util.Map r1 = r2.LIZ
            java.lang.String r0 = "enter_search"
            X.2nK.LIZ(r0, r1)
            return
        L_0x00aa:
            int r1 = r6.getId()
            r0 = 2131369890(0x7f0a1fa2, float:1.8359771E38)
            if (r1 != r0) goto L_0x00b7
            r5.LIZJ()
            return
        L_0x00b7:
            int r1 = r6.getId()
            r0 = 2131362572(0x7f0a030c, float:1.8344928E38)
            if (r1 != r0) goto L_0x00c9
            X.1hK r0 = r5.getActivity()
            if (r0 == 0) goto L_0x00c9
            r0.onBackPressed()
        L_0x00c9:
            return
        */
        throw new UnsupportedOperationException("Method not decompiled: com.ss.android.ugc.aweme.choosemusic.fragment.BaseChooseMusicFragment.onClick(android.view.View):void");
    }

    public void onCreate(Bundle bundle) {
        BaseChooseMusicFragment.super.onCreate(bundle);
        if (getArguments() != null) {
            this.LIZ = getArguments().getInt("com.ss.android.ugc.aweme.intent.extra.EXTRA_MUSIC_TYPE", 1);
            this.LJIL = getArguments().getInt("sound_page_scene", 0);
            this.LJJII = getArguments().getString("challenge");
            this.LJJIJIIJI = getArguments().getString("creation_id");
            this.LJJIJIIJIL = getArguments().getString("shoot_way");
            this.LJJIII = getArguments().getSerializable("music_style");
            this.LJJIIJ = (Music) getArguments().getSerializable("sticker_music");
            this.LJJIIJZLJL = getArguments().getString("first_sticker_music_ids", (String) null);
            this.LJJIIZI = getArguments().getBoolean("is_busi_sticker", false);
            this.LJJIIZ = getArguments().getString("first_sticker_id", (String) null);
            this.LJJIJ = (MusicModel) getArguments().getSerializable("music_model");
            this.LJIILIIL = getArguments().getBoolean("music_allow_clear", false);
            this.LJIILJJIL = getArguments().getBoolean("music_allow_cut", false);
            this.LJIILL = getArguments().getBoolean("music_is_photomv", false);
            this.LJJIJIL = getArguments().getBoolean("extra_beat_music_sticker", false);
            this.LJJIL = getArguments().getBoolean("hide_cancel_music_ui", false);
            this.LJIJI = getArguments().getString("reuse_original_sound_id");
            this.LJIIZILJ = getArguments().getSerializable("reuse_original_sound_url");
            this.LJIJ = getArguments().getInt("reuse_original_sound_length");
            if (this.LJIILJJIL) {
                this.LJJIJL = getArguments().getLong("max_video_duration", 0);
                this.LJJIJLIJ = getArguments().getLong("shoot_video_length", 0);
            } else {
                this.LJJIJL = 0;
                this.LJJIJLIJ = 0;
            }
            long j = this.LJJIJLIJ;
            if (j == 0) {
                j = this.LJJIJL;
            }
            OSU.LJFF = (int) j;
        }
        this.LJIJJ = LIZ(getActivity()).LIZ(ChooseMusicCutViewModel.class);
        this.LJIJJLI = LIZ(getActivity()).LIZ(SelectedMusicViewModel.class);
        this.LJJIFFI = SearchServiceImpl.LJJIIZ().LJI();
        CommerceMediaServiceImpl.LJI().LIZIZ(this).LIZ();
    }

    public void onViewCreated(View view, Bundle bundle) {
        BaseChooseMusicFragment baseChooseMusicFragment = this;
        BaseChooseMusicFragment.super.onViewCreated(view, bundle);
        0AA childFragmentManager = getChildFragmentManager();
        NewMusicTabFragment LIZ2 = childFragmentManager.LIZ(2131363713);
        if (LIZ2 != null) {
            baseChooseMusicFragment.LIZIZ = LIZ2;
        } else {
            int i = baseChooseMusicFragment.LIZ;
            String str = baseChooseMusicFragment.LJJII;
            Music music = baseChooseMusicFragment.LJJIIJ;
            String str2 = baseChooseMusicFragment.LJJIIJZLJL;
            String str3 = baseChooseMusicFragment.LJJIIZ;
            boolean z = baseChooseMusicFragment.LJJIIZI;
            String str4 = baseChooseMusicFragment.LJJIJIIJIL;
            int i2 = baseChooseMusicFragment.LJIL;
            boolean z2 = baseChooseMusicFragment.LJJIL;
            long j = baseChooseMusicFragment.LJJIJL;
            long j2 = baseChooseMusicFragment.LJJIJLIJ;
            UrlModel urlModel = baseChooseMusicFragment.LJIIZILJ;
            int i3 = baseChooseMusicFragment.LJIJ;
            String str5 = baseChooseMusicFragment.LJIJI;
            Bundle bundle2 = new Bundle();
            bundle2.putInt("com.ss.android.ugc.aweme.intent.extra.EXTRA_MUSIC_TYPE", i);
            if (!TextUtils.isEmpty(str)) {
                String str6 = str;
                bundle2.putString("challenge", str6);
            }
            if (music != null) {
                bundle2.putSerializable("sticker_music", music);
            }
            if (str2 != null) {
                bundle2.putString("first_sticker_music_ids", str2);
            }
            if (str3 != null) {
                bundle2.putString("first_sticker_id", str3);
            }
            bundle2.putBoolean("is_busi_sticker", z);
            NewMusicTabFragment newMusicTabFragment = new NewMusicTabFragment();
            if (!TextUtils.isEmpty(str4)) {
                bundle2.putString("shoot_way", str4);
            }
            bundle2.putInt("sound_page_scene", i2);
            bundle2.putBoolean("hide_cancel_music_ui", z2);
            bundle2.putLong("max_video_duration", j);
            bundle2.putLong("shoot_video_length", j2);
            bundle2.putSerializable("reuse_original_sound_url", urlModel);
            bundle2.putInt("reuse_original_sound_length", i3);
            bundle2.putString("reuse_original_sound_id", str5);
            newMusicTabFragment.setArguments(bundle2);
            baseChooseMusicFragment = this;
            baseChooseMusicFragment.LIZIZ = newMusicTabFragment;
            newMusicTabFragment.LJIILIIL = 0;
            MusicModel musicModel = baseChooseMusicFragment.LJJIJ;
            if (musicModel != null && musicModel.isMvThemeMusic()) {
                baseChooseMusicFragment.LIZIZ.LJIJJ = true;
            }
            baseChooseMusicFragment.LIZIZ.LJIJJLI = baseChooseMusicFragment.LJIILL;
            0AP LIZ3 = childFragmentManager.LIZ();
            LIZ3.LIZ(2131363713, baseChooseMusicFragment.LIZIZ);
            LIZ3.LIZJ();
        }
        OT0 ot0 = baseChooseMusicFragment.LJIIIZ;
        if (ot0 != null) {
            ot0.LIZ(baseChooseMusicFragment.LIZIZ);
        }
        if (baseChooseMusicFragment.LJIILIIL && !C0131MIu.LIZ()) {
            LIZIZ();
        }
        getChildFragmentManager().LIZ(baseChooseMusicFragment);
        baseChooseMusicFragment.LIZLLL.LIZ();
        if (SearchServiceImpl.LJJIIZ().LJJIIJZLJL().LJIIJ) {
            baseChooseMusicFragment.LIZLLL.LIZ(false);
        }
        OTM.LJIILL.LIZ(getActivity(), baseChooseMusicFragment.LJJIJLIJ, baseChooseMusicFragment.LJJIJL);
    }

    public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        View decorView;
        this.LJJJJI = 0HH.LIZ(layoutInflater, 2131559748, viewGroup, false);
        OSU.LJ = this.LJJIJIIJIL;
        OSU.LIZLLL = this.LJJIJIIJI;
        this.LIZLLL = new OTV(this.LJJJJI, this, this.LJJI);
        this.LJJJJIZL = (ViewStub) this.LJJJJI.findViewById(2131372960);
        this.LJJJJJ = (ViewStub) this.LJJJJI.findViewById(2131363305);
        Window window = getActivity().getWindow();
        if (!(window == null || (decorView = window.getDecorView()) == null)) {
            this.LJJIZ = decorView.findViewById(2131362572);
            View findViewById = decorView.findViewById(2131369890);
            this.LJJJ = findViewById;
            findViewById.setOnClickListener(this);
            Cbz.LIZ(this.LJJJ, 8);
            Cbz.LIZ(this.LJJIZ, 0);
        }
        this.LJJJI = this.LJJJJI.findViewById(2131365160);
        this.LJJJIL = this.LJJJJI.findViewById(2131367309);
        this.LJ = getActivity();
        OT0 ot0 = new OT0(this.LJ, layoutInflater, viewGroup);
        this.LJIIIZ = ot0;
        ot0.LIZ((int) this.LJJIJLIJ, (int) this.LJJIJL);
        this.LJIIIZ.LIZ();
        View LIZ2 = 0HH.LIZ(layoutInflater, 2131560423, (ViewGroup) this.LJJJJI.findViewById(2131367784), true);
        LIZ2.findViewById(2131362848).setText(2131827044);
        CjP.LIZ.LIZ(LIZ2, 2ha.LIZ(-100.0d), 0, false);
        LIZ2.findViewById(2131362846).setOnClickListener(new CjQ(LIZ2));
        this.LJJJJ = LIZ2;
        return this.LJJJJI;
    }
}
