package com.ss.android.ugc.aweme.contentlanguage.view;

import X.070;
import X.0Bs;
import X.0Bv;
import X.0Bx;
import X.0By;
import X.0CM;
import X.0HH;
import X.1Bn;
import X.1hK;
import X.878;
import X.AnonymousClass2GD;
import X.BSq;
import X.C15292rx;
import X.C15322s0;
import X.C15852sr;
import X.C216735j;
import X.JT0;
import X.M12;
import X.OQL;
import X.OQO;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.recyclerview.widget.RecyclerView;
import com.bytedance.covode.number.Covode;
import com.ss.android.ugc.aweme.base.fragment.AmeBaseFragment;
import com.ss.android.ugc.aweme.contentlanguage.viewmodel.ContentPreferenceViewModel;
import com.ss.android.ugc.aweme.views.WrapLinearLayoutManager;
import java.util.ArrayList;
import java.util.Collection;
import kotlin.h.b.n;

public class LanguageListFragment extends AmeBaseFragment implements 0CM<ArrayList<C15852sr>>, C15322s0 {
    public ContentPreferenceViewModel LIZ;
    public OQL LIZIZ;
    public RecyclerView LIZJ;
    public int LIZLLL;
    public C15292rx LJ;
    public int LJIIIZ;

    static {
        Covode.recordClassIndex(62275);
    }

    public final void LIZ() {
        if (getActivity() != null) {
            getActivity().getSupportFragmentManager().LIZJ();
        }
    }

    public void onResume() {
        LanguageListFragment.super.onResume();
        ContentPreferenceViewModel contentPreferenceViewModel = this.LIZ;
        if (contentPreferenceViewModel != null && contentPreferenceViewModel.LIZIZ) {
            contentPreferenceViewModel.LJ();
            contentPreferenceViewModel.LIZIZ = false;
        }
    }

    public /* synthetic */ void onChanged(Object obj) {
        ArrayList<C15852sr> arrayList = (ArrayList) obj;
        if (!878.LIZ(arrayList)) {
            C15292rx r0 = this.LJ;
            if (r0 == null) {
                C15292rx r1 = new C15292rx(getContext(), this);
                this.LJ = r1;
                r1.LIZ = arrayList;
                this.LIZJ.setAdapter(this.LJ);
                return;
            }
            r0.LIZ = arrayList;
            this.LJ.notifyDataSetChanged();
        }
    }

    public final void LIZ(int i) {
        C15852sr r0;
        ArrayList arrayList;
        C15852sr r02;
        if (i != this.LIZLLL) {
            if (i == this.LJIIIZ) {
                this.LIZIZ.getEndText().setTextColor(070.LIZJ(getContext(), 2131099673));
                this.LIZIZ.getEndText().setEnabled(false);
            } else {
                this.LIZIZ.getEndText().setTextColor(070.LIZJ(getContext(), 2131099731));
                this.LIZIZ.getEndText().setEnabled(true);
            }
            ContentPreferenceViewModel contentPreferenceViewModel = this.LIZ;
            int i2 = this.LIZLLL;
            1Bn<ArrayList<C15852sr>> LIZLLL2 = contentPreferenceViewModel.LIZLLL();
            if (!878.LIZ((Collection) LIZLLL2.getValue())) {
                if (!(i2 < 0 || (arrayList = (ArrayList) LIZLLL2.getValue()) == null || (r02 = (C15852sr) arrayList.get(i2)) == null)) {
                    r02.LIZ = false;
                }
                ArrayList arrayList2 = (ArrayList) LIZLLL2.getValue();
                if (!(arrayList2 == null || (r0 = (C15852sr) arrayList2.get(i)) == null)) {
                    r0.LIZ = true;
                }
                contentPreferenceViewModel.LIZ = i;
            }
            this.LIZLLL = i;
            this.LJ.notifyDataSetChanged();
        }
    }

    public void onCreate(Bundle bundle) {
        ArrayList arrayList;
        C15852sr r1;
        LanguageListFragment.super.onCreate(bundle);
        if (getActivity() != null) {
            1hK activity = getActivity();
            Integer num = null;
            0Bx LIZ2 = 0By.LIZ(activity, (0Bv) null);
            if (AnonymousClass2GD.LIZ) {
                0Bs.LIZ(LIZ2, activity);
            }
            ContentPreferenceViewModel LIZ3 = LIZ2.LIZ(ContentPreferenceViewModel.class);
            this.LIZ = LIZ3;
            LIZ3.LIZLLL().observe(this, this);
            ContentPreferenceViewModel contentPreferenceViewModel = this.LIZ;
            M12.LIZ(getContext());
            if (!878.LIZ((Collection) contentPreferenceViewModel.LIZLLL().getValue()) && contentPreferenceViewModel.LIZ >= 0) {
                int i = contentPreferenceViewModel.LIZ;
                ArrayList arrayList2 = (ArrayList) contentPreferenceViewModel.LIZLLL().getValue();
                if (arrayList2 == null || (num = Integer.valueOf(arrayList2.size())) == null) {
                    n.LIZIZ();
                }
                if (!(i > num.intValue() - 1 || (arrayList = (ArrayList) contentPreferenceViewModel.LIZLLL().getValue()) == null || (r1 = (C15852sr) arrayList.get(contentPreferenceViewModel.LIZ)) == null)) {
                    r1.LIZ = false;
                }
            }
            this.LJIIIZ = -1;
            this.LIZLLL = -1;
        }
    }

    public void onViewCreated(View view, Bundle bundle) {
        this.LIZIZ = view.findViewById(2131371262);
        this.LIZJ = view.findViewById(2131367134);
        LanguageListFragment.super.onViewCreated(view, bundle);
        RecyclerView recyclerView = this.LIZJ;
        getContext();
        recyclerView.setLayoutManager(new WrapLinearLayoutManager());
        this.LIZJ.LIZ(BSq.LIZ(getContext()));
        this.LIZIZ.getTitleView().setTextColor(070.LIZJ(getContext(), 2131100294));
        this.LIZIZ.setTitle(getText(2131823227));
        this.LIZIZ.getEndText().setEnabled(false);
        this.LIZIZ.getEndText().setTextColor(070.LIZJ(getContext(), 2131099673));
        this.LIZIZ.setOnTitleBarClickListener(new OQO() {
            static {
                Covode.recordClassIndex(62276);
            }

            public final void LIZ(View view) {
                if (LanguageListFragment.this.getActivity() != null) {
                    LanguageListFragment.this.getActivity().getSupportFragmentManager().LIZJ();
                }
            }

            public final void LIZIZ(View view) {
                C216735j r2;
                if (LanguageListFragment.this.LIZIZ == null || LanguageListFragment.this.LIZIZ.getEndText() == null || LanguageListFragment.this.LIZIZ.getEndText().getCurrentTextColor() == 070.LIZJ(view.getContext(), 2131099673)) {
                    LanguageListFragment.this.LIZ();
                } else if (LanguageListFragment.this.LIZLLL != -1) {
                    ContentPreferenceViewModel contentPreferenceViewModel = LanguageListFragment.this.LIZ;
                    C15852sr r3 = (C15852sr) ((ArrayList) LanguageListFragment.this.LIZ.LIZLLL().getValue()).get(LanguageListFragment.this.LIZLLL);
                    if (r3 == null) {
                        r2 = null;
                    } else {
                        r2 = new C216735j();
                        if (r3.LIZIZ instanceof JT0) {
                            JT0 jt0 = r3.LIZIZ;
                            r2.setEnglishName(jt0.LIZ);
                            r2.setLanguageCode(jt0.LIZIZ);
                            r2.setLocalName(r3.LIZ());
                        } else {
                            throw new IllegalStateException("please send I18nLanguageItem");
                        }
                    }
                    contentPreferenceViewModel.LIZ(r2);
                    LanguageListFragment.this.LIZ();
                }
            }
        });
    }

    public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        return 0HH.LIZ(layoutInflater, 2131558474, viewGroup, false);
    }
}
