package com.ss.android.ugc.aweme.compliance.privacy.settings.account.pages.comment;

import X.0Bx;
import X.6iy;
import X.9HM;
import X.AnonymousClass2aZ;
import X.AnonymousClass3CL;
import X.AnonymousClass3CM;
import X.AnonymousClass3CN;
import X.C15012rV;
import X.C15052rZ;
import X.C35493jR;
import X.C35623je;
import X.C35663ji;
import X.C35673jj;
import X.C35683jk;
import X.C35713jn;
import X.C35743jq;
import X.C35803jw;
import X.C36003kG;
import X.C36383ks;
import X.C37093m1;
import X.C38943p0;
import X.C38953p1;
import X.CZv;
import X.LeS;
import X.Lea;
import X.LsC;
import X.M12;
import X.Mk2;
import X.Mk3;
import X.PhE;
import X.PlI;
import android.os.Bundle;
import android.util.SparseArray;
import android.view.View;
import com.bytedance.covode.number.Covode;
import com.google.gson.Gson;
import com.ss.android.ugc.aweme.compliance.api.services.privacy.CommentFilterDislikeControl;
import com.ss.android.ugc.aweme.compliance.privacy.settings.account.base.BasePrivacySettingFragment;
import com.ss.android.ugc.aweme.compliance.privacy.settings.account.pages.commentfilter.CommentFilterModel;
import com.ss.android.ugc.aweme.compliance.privacy.settings.account.pages.commentfilter.api.CommentFilterApi;
import com.ss.android.ugc.aweme.compliance.privacy.settings.account.pages.commentfilter.subadapters.keywords.KeyWordsViewModel;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import kotlin.h.b.n;
import kotlin.o.z;

@CZv
public final class CommentPrivacySettingFragment extends BasePrivacySettingFragment {
    public CommentViewModel LIZ;
    public C35713jn LIZIZ;
    public CommentFilterModel LIZJ;
    public List<? extends C15012rV> LIZLLL;
    public SparseArray LJ;

    static {
        Covode.recordClassIndex(61618);
    }

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

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

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

    public final List<C15012rV> LIZJ() {
        C35713jn r0 = this.LIZIZ;
        if (r0 == null) {
            n.LIZ("");
        }
        List LIZ2 = 6iy.LIZ(r0);
        List<? extends C15012rV> list = this.LIZLLL;
        if (list == null) {
            n.LIZ("");
        }
        return Lea.LJIIJJI(Lea.LIZLLL(LIZ2, list));
    }

    public final void onDetach() {
        CommentFilterModel commentFilterModel = this.LIZJ;
        if (commentFilterModel == null) {
            n.LIZ("");
        }
        KeyWordsViewModel keyWordsViewModel = commentFilterModel.LIZ;
        if (keyWordsViewModel.LJI && keyWordsViewModel.LJFF) {
            List<String> list = keyWordsViewModel.LIZLLL;
            ArrayList arrayList = new ArrayList();
            for (T next : list) {
                String str = (String) next;
                Objects.requireNonNull(str, "null cannot be cast to non-null type kotlin.CharSequence");
                if (!n.LIZ(z.LIZJ(str).toString(), "")) {
                    arrayList.add(next);
                }
            }
            List<String> list2 = arrayList;
            ArrayList arrayList2 = new ArrayList(9HM.LIZ(list2, 10));
            for (String str2 : list2) {
                Objects.requireNonNull(str2, "null cannot be cast to non-null type kotlin.CharSequence");
                arrayList2.add(z.LIZIZ(str2).toString());
            }
            List list3 = arrayList2;
            AnonymousClass3CL r3 = new AnonymousClass3CL(keyWordsViewModel);
            CommentFilterApi.LIZ.setCommentFilterKeywords(new Gson().LIZIZ(list3)).LIZIZ(PhE.LIZIZ(PlI.LIZJ)).LIZ(Mk2.LIZ(Mk3.LIZ)).LIZ(new AnonymousClass3CN(keyWordsViewModel, r3, list3), new AnonymousClass3CM(r3));
            if (list3.isEmpty()) {
                keyWordsViewModel.LIZIZ.setValue(2);
                C36003kG.LIZIZ.LIZIZ(2);
            }
            C36383ks r2 = C36383ks.LIZ;
            Integer num = (Integer) keyWordsViewModel.LIZIZ.getValue();
            if (num == null) {
                num = 2;
            }
            n.LIZIZ(num, "");
            r2.LIZ(num.intValue(), keyWordsViewModel.LIZJ);
        }
        CommentPrivacySettingFragment.super.onDetach();
    }

    public final void onCreate(Bundle bundle) {
        C15012rV r1;
        super.onCreate(bundle);
        CommentViewModel LIZ2 = new 0Bx(this).LIZ(CommentViewModel.class);
        n.LIZIZ(LIZ2, "");
        this.LIZ = LIZ2;
        CommentViewModel commentViewModel = this.LIZ;
        if (commentViewModel == null) {
            n.LIZ("");
        }
        this.LIZIZ = new C35713jn(commentViewModel, this);
        CommentFilterModel LIZ3 = new 0Bx(this).LIZ(CommentFilterModel.class);
        n.LIZIZ(LIZ3, "");
        CommentFilterModel commentFilterModel = LIZ3;
        this.LIZJ = commentFilterModel;
        if (commentFilterModel == null) {
            n.LIZ("");
        }
        C38953p1.LIZ.LIZ().LIZIZ(PhE.LIZIZ(PlI.LIZJ)).LIZ(Mk2.LIZ(Mk3.LIZ)).LIZ(new C35673jj(commentFilterModel), C35683jk.LIZ);
        C15012rV[] r3 = new C15012rV[5];
        r3[0] = new C35663ji(this);
        CommentFilterModel commentFilterModel2 = this.LIZJ;
        if (commentFilterModel2 == null) {
            n.LIZ("");
        }
        r3[1] = new C35743jq(commentFilterModel2, this);
        if (CommentFilterDislikeControl.isNewVersion()) {
            r1 = new C35493jR(this);
        } else {
            CommentFilterModel commentFilterModel3 = this.LIZJ;
            if (commentFilterModel3 == null) {
                n.LIZ("");
            }
            r1 = new C35803jw(commentFilterModel3, this);
        }
        r3[2] = r1;
        CommentFilterModel commentFilterModel4 = this.LIZJ;
        if (commentFilterModel4 == null) {
            n.LIZ("");
        }
        r3[3] = new C15052rZ(commentFilterModel4, this);
        CommentFilterModel commentFilterModel5 = this.LIZJ;
        if (commentFilterModel5 == null) {
            n.LIZ("");
        }
        r3[4] = new C35623je(commentFilterModel5, this);
        this.LIZLLL = LeS.LIZIZ(r3);
    }

    public final void onViewCreated(View view, Bundle bundle) {
        M12.LIZ(view);
        super.onViewCreated(view, bundle);
        LIZIZ(2131821253);
        C35713jn r1 = this.LIZIZ;
        if (r1 == null) {
            n.LIZ("");
        }
        LIZ((CharSequence) r1.LIZJ());
        C38943p0.LIZ("PRIVACY_SETTING_ALOG", (LsC<? super AnonymousClass2aZ, ? extends AnonymousClass2aZ>) C37093m1.LIZ);
    }
}
