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

import X.0AA;
import X.0CM;
import X.0HH;
import X.2FV;
import X.2He;
import X.2kf;
import X.2sF;
import X.30v;
import X.33g;
import X.3XD;
import X.7s1;
import X.878;
import X.8jA;
import X.8n2;
import X.C5303OQg;
import X.C5304OQh;
import X.C5418OUr;
import X.C5520OYp;
import X.Cmx;
import X.HeD;
import X.M12;
import X.OQL;
import X.OV8;
import X.OWT;
import X.OXG;
import X.OXI;
import X.OXN;
import X.OYB;
import X.OYE;
import X.Qz3;
import X.Qz9;
import X.Ss0;
import android.content.ClipboardManager;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import com.ss.android.ugc.aweme.arch.widgets.base.DataCenter;
import com.ss.android.ugc.aweme.base.fragment.AmeBaseFragment;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;
import kotlin.h.b.n;

public final class SecondLevelMusicFragment extends AmeBaseFragment implements 0CM<33g> {
    public static final C5520OYp LIZ = new C5520OYp((byte) 0);
    public Qz3 LIZIZ;
    public Ss0 LIZJ;
    public OQL LIZLLL;
    public C5303OQg LJ;
    public OXG LJIIIZ;
    public String LJIIJ;
    public String LJIIJJI;
    public String LJIIL;
    public boolean LJIILIIL;
    public String LJIILJJIL;
    public int LJIILL;
    public DataCenter LJIIZILJ;
    public C5418OUr LJIJ;
    public int LJIJI;
    public int LJIJJ;
    public HashMap LJIJJLI;

    static {
        Covode.recordClassIndex(89298);
    }

    public final void LIZ() {
        C5418OUr oUr = this.LJIJ;
        if (oUr != null) {
            oUr.LIZIZ(this.LJIIJ, this.LJIILL);
        }
    }

    public final /* synthetic */ void onDestroyView() {
        SecondLevelMusicFragment.super.onDestroyView();
        HashMap hashMap = this.LJIJJLI;
        if (hashMap != null) {
            hashMap.clear();
        }
    }

    public final void LIZIZ() {
        C5303OQg oQg = this.LJ;
        if (oQg == null) {
            n.LIZ("");
        }
        oQg.setVisibility(0);
        C5303OQg oQg2 = this.LJ;
        if (oQg2 == null) {
            n.LIZ("");
        }
        oQg2.LIZ();
    }

    private void LIZJ() {
        C5303OQg oQg = this.LJ;
        if (oQg == null) {
            n.LIZ("");
        }
        oQg.setVisibility(0);
        C5303OQg oQg2 = this.LJ;
        if (oQg2 == null) {
            n.LIZ("");
        }
        C5304OQh oQh = new C5304OQh();
        30v.LIZIZ(oQh, new OYE(this));
        oQg2.setStatus(oQh);
    }

    public static NetworkInfo LIZ(ConnectivityManager connectivityManager) {
        try {
            if (8n2.LJIIJJI != null && 8n2.LJIIIZ && !8n2.LIZ()) {
                return 8n2.LJIIJJI;
            }
            NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
            8n2.LJIIJJI = activeNetworkInfo;
            return activeNetworkInfo;
        } catch (Exception e) {
            2kf.LIZ(e);
            return 3XD.LIZ();
        }
    }

    public final void onCreate(Bundle bundle) {
        SecondLevelMusicFragment.super.onCreate(bundle);
        Bundle arguments = getArguments();
        if (arguments != null) {
            this.LJIIJ = arguments.getString("music_class_id");
            this.LJIIJJI = arguments.getString("music_class_name");
            this.LJIIL = arguments.getString("music_class_enter_from");
            this.LJIILIIL = arguments.getBoolean("music_class_is_hot", false);
            this.LJIILJJIL = arguments.getString("music_class_enter_method");
            this.LJIJI = arguments.getInt("com.ss.android.ugc.aweme.intent.extra.EXTRA_MUSIC_TYPE");
            this.LJIILL = arguments.getInt("music_class_level");
        }
    }

    private boolean LIZ(Context context) {
        if (context != null) {
            try {
                Object LIZ2 = LIZ(context, "connectivity");
                if (LIZ2 != null) {
                    NetworkInfo LIZ3 = LIZ((ConnectivityManager) LIZ2);
                    if (LIZ3 == null || !LIZ3.isAvailable()) {
                        return false;
                    }
                    return true;
                }
            } catch (Exception unused) {
                return false;
            }
        }
        throw new NullPointerException("null cannot be cast to non-null type android.net.ConnectivityManager");
    }

    public final /* synthetic */ void onChanged(Object obj) {
        OV8 ov8;
        List<OXN> list;
        String str;
        ArrayList<OXN> arrayList;
        OXN oxn;
        ArrayList<OXN> arrayList2;
        33g r13 = (33g) obj;
        if (r13 != null) {
            String str2 = r13.LIZ;
            int hashCode = str2.hashCode();
            if (hashCode != -314811087) {
                if (hashCode == -252789122 && str2.equals("second_level_music_list")) {
                    C5303OQg oQg = this.LJ;
                    if (oQg == null) {
                        n.LIZ("");
                    }
                    oQg.setVisibility(8);
                    DataCenter dataCenter = this.LJIIZILJ;
                    if (dataCenter != null) {
                        ov8 = (OV8) dataCenter.LIZ("second_level_music_list");
                        if (ov8 != null) {
                            list = (List) ov8.LIZ("list_collection_data");
                        }
                        list = null;
                    } else {
                        ov8 = null;
                        list = null;
                    }
                    if (878.LIZ(list)) {
                        C5303OQg oQg2 = this.LJ;
                        if (oQg2 == null) {
                            n.LIZ("");
                        }
                        oQg2.setVisibility(0);
                        C5303OQg oQg3 = this.LJ;
                        if (oQg3 == null) {
                            n.LIZ("");
                        }
                        C5304OQh oQh = new C5304OQh();
                        String string = getString(2131826216);
                        n.LIZIZ(string, "");
                        oQh.LIZ((CharSequence) string);
                        oQg3.setStatus(oQh);
                        return;
                    }
                    if (list != null) {
                        int i = 0;
                        for (OXN oxn2 : list) {
                            OXG oxg = this.LJIIIZ;
                            if (!(oxg == null || (arrayList2 = oxg.LIZIZ) == null)) {
                                arrayList2.add(oxn2);
                            }
                            if (this.LJIILL == 1) {
                                if (i == 0) {
                                    OXG oxg2 = this.LJIIIZ;
                                    if (oxg2 != null) {
                                        oxg2.LIZ(oxn2.LIZ, oxn2.LIZIZ, oxn2.LJ, ov8);
                                    }
                                } else {
                                    OXG oxg3 = this.LJIIIZ;
                                    if (oxg3 != null) {
                                        oxg3.LIZ(oxn2.LIZ, oxn2.LIZIZ, oxn2.LJ, (OV8<String, Object>) null);
                                    }
                                }
                            }
                            i++;
                        }
                    }
                    Ss0 ss0 = this.LIZJ;
                    if (ss0 == null) {
                        n.LIZ("");
                    }
                    ss0.setAdapter(this.LJIIIZ);
                    Qz3 qz3 = this.LIZIZ;
                    if (qz3 == null) {
                        n.LIZ("");
                    }
                    Ss0 ss02 = this.LIZJ;
                    if (ss02 == null) {
                        n.LIZ("");
                    }
                    qz3.setupWithViewPager(ss02);
                    Qz3 qz32 = this.LIZIZ;
                    if (qz32 == null) {
                        n.LIZ("");
                    }
                    int tabCount = qz32.getTabCount();
                    for (int i2 = 0; i2 < tabCount; i2++) {
                        2sF r2 = new 2sF(getContext());
                        OXG oxg4 = this.LJIIIZ;
                        if (oxg4 == null || (arrayList = oxg4.LIZIZ) == null || (oxn = arrayList.get(i2)) == null) {
                            str = null;
                        } else {
                            str = oxn.LIZIZ;
                        }
                        Qz3 qz33 = this.LIZIZ;
                        if (qz33 == null) {
                            n.LIZ("");
                        }
                        Qz9 LIZIZ2 = qz33.LIZIZ(i2);
                        r2.setText(str);
                        if (LIZIZ2 != null) {
                            LIZIZ2.LIZ(r2);
                            LIZIZ2.LIZ = str;
                        }
                        if (i2 == 0) {
                            r2.LIZ();
                        }
                        Qz3 qz34 = this.LIZIZ;
                        if (qz34 == null) {
                            n.LIZ("");
                        }
                        int tabCount2 = qz34.getTabCount();
                        Qz3 qz35 = this.LIZIZ;
                        if (qz35 == null) {
                            n.LIZ("");
                        }
                        View LIZLLL2 = qz35.LIZLLL(i2);
                        if (LIZLLL2 != null) {
                            if (i2 == 0) {
                                if (tabCount2 == 1) {
                                    int i3 = this.LJIJJ;
                                    LIZ(LIZLLL2, i3, i3);
                                } else {
                                    LIZ(LIZLLL2, this.LJIJJ, -1);
                                }
                            } else if (i2 == tabCount2 - 1) {
                                LIZ(LIZLLL2, -1, this.LJIJJ);
                            }
                        }
                    }
                    Qz3 qz36 = this.LIZIZ;
                    if (qz36 == null) {
                        n.LIZ("");
                    }
                    qz36.LIZ(new OXI(this));
                }
            } else if (str2.equals("status_second_level_music_list")) {
                Integer num = (Integer) r13.LIZ();
                if (num == null || num.intValue() != 0) {
                    LIZJ();
                }
            }
        }
    }

    public final void LIZ(Integer num) {
        ArrayList<MusicClassDetailFragment> arrayList;
        BaseMusicListFragment baseMusicListFragment = null;
        if (num != null) {
            int intValue = num.intValue();
            OXG oxg = this.LJIIIZ;
            if (!(oxg == null || (arrayList = oxg.LIZ) == null)) {
                baseMusicListFragment = arrayList.get(intValue);
            }
        }
        if (baseMusicListFragment instanceof MusicClassDetailFragment) {
            OWT LJIIIZ2 = baseMusicListFragment.LJIIIZ();
            if (LJIIIZ2 instanceof OWT) {
                LJIIIZ2.LIZ();
            }
        }
    }

    public static Object LIZ(Context context, String str) {
        Object obj;
        MethodCollector.i(5357);
        if (Build.VERSION.SDK_INT > 27 || !"clipboard".equals(str)) {
            if (!2FV.LIZIZ && "connectivity".equals(str)) {
                try {
                    new 7s1().LIZ();
                    2FV.LIZIZ = true;
                    obj = context.getSystemService(str);
                } catch (Throwable unused) {
                }
            }
            obj = context.getSystemService(str);
        } else if (2FV.LIZ) {
            synchronized (ClipboardManager.class) {
                try {
                    obj = context.getSystemService(str);
                    if (Thread.currentThread() != Looper.getMainLooper().getThread()) {
                        Field declaredField = ClipboardManager.class.getDeclaredField("mHandler");
                        declaredField.setAccessible(true);
                        declaredField.set(obj, new 2He((Handler) declaredField.get(obj)));
                    }
                } catch (Exception e) {
                    8jA.LIZ(e, "ClipboardManager Handler Reflect Fail");
                } catch (Throwable th) {
                    MethodCollector.o(5357);
                    throw th;
                }
                2FV.LIZ = false;
            }
        } else {
            obj = context.getSystemService(str);
        }
        MethodCollector.o(5357);
        return obj;
    }

    public final void onViewCreated(View view, Bundle bundle) {
        M12.LIZ(view);
        SecondLevelMusicFragment.super.onViewCreated(view, bundle);
        Ss0 ss0 = this.LIZJ;
        if (ss0 == null) {
            n.LIZ("");
        }
        ss0.setOffscreenPageLimit(1);
        0AA childFragmentManager = getChildFragmentManager();
        n.LIZIZ(childFragmentManager, "");
        this.LJIIIZ = new OXG(childFragmentManager, this.LJIIJ, this.LJIIJJI, this.LJIIL, this.LJIJI, this.LJIILIIL, this.LJIILJJIL, this.LJIILL);
        Qz3 qz3 = this.LIZIZ;
        if (qz3 == null) {
            n.LIZ("");
        }
        qz3.setTabMode(0);
        Qz3 qz32 = this.LIZIZ;
        if (qz32 == null) {
            n.LIZ("");
        }
        qz32.setTabMaxWidth(Integer.MAX_VALUE);
        if (!LIZ(getContext())) {
            LIZJ();
        } else {
            LIZ();
        }
    }

    private final void LIZ(View view, int i, int i2) {
        if (i != -1 || i2 != -1) {
            ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
            Objects.requireNonNull(layoutParams, "null cannot be cast to non-null type android.view.ViewGroup.MarginLayoutParams");
            ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) layoutParams;
            if (i != -1) {
                marginLayoutParams.setMarginStart(i);
            }
            if (i2 != -1) {
                marginLayoutParams.setMarginEnd(i2);
            }
            view.setLayoutParams(marginLayoutParams);
            view.invalidate();
        }
    }

    public final View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        M12.LIZ(layoutInflater);
        View LIZ2 = 0HH.LIZ(layoutInflater, 2131560278, viewGroup, false);
        Qz3 findViewById = LIZ2.findViewById(2131369982);
        n.LIZIZ(findViewById, "");
        this.LIZIZ = findViewById;
        Ss0 findViewById2 = LIZ2.findViewById(2131369985);
        n.LIZIZ(findViewById2, "");
        this.LIZJ = findViewById2;
        View findViewById3 = LIZ2.findViewById(2131367825);
        n.LIZIZ(findViewById3, "");
        this.LJ = (C5303OQg) findViewById3;
        View findViewById4 = LIZ2.findViewById(2131371262);
        n.LIZIZ(findViewById4, "");
        OQL oql = (OQL) findViewById4;
        this.LIZLLL = oql;
        if (oql == null) {
            n.LIZ("");
        }
        oql.setOnTitleBarClickListener(new OYB(this));
        OQL oql2 = this.LIZLLL;
        if (oql2 == null) {
            n.LIZ("");
        }
        oql2.setColorMode(0);
        OQL oql3 = this.LIZLLL;
        if (oql3 == null) {
            n.LIZ("");
        }
        oql3.setTitle((CharSequence) this.LJIIJJI);
        LIZIZ();
        this.LJIJJ = (int) HeD.LIZIZ(getActivity(), 16.0f);
        if (this.LJIIZILJ == null) {
            this.LJIIZILJ = DataCenter.LIZ(Cmx.LIZIZ(this), this);
        }
        DataCenter dataCenter = this.LJIIZILJ;
        if (dataCenter != null) {
            dataCenter.LIZ("status_second_level_music_list", this);
        }
        DataCenter dataCenter2 = this.LJIIZILJ;
        if (dataCenter2 != null) {
            dataCenter2.LIZ("second_level_music_list", this);
        }
        this.LJIJ = new C5418OUr(getContext(), this.LJIIZILJ);
        return LIZ2;
    }
}
