package com.ss.android.ugc.aweme.shortvideo.edit.infosticker.interact.duet;

import X.0Bs;
import X.0Bv;
import X.0Bx;
import X.0By;
import X.0Gh;
import X.0Gp;
import X.0HH;
import X.1Bn;
import X.2GD;
import X.2Pr;
import X.2uR;
import X.2vu;
import X.3YD;
import X.3c9;
import X.3cC;
import X.3cI;
import X.7he;
import X.9rx;
import X.BRI;
import X.C0263FZd;
import X.C0280FZu;
import X.CDg;
import X.CDh;
import X.CDs;
import X.Crj;
import X.FZ9;
import X.FZB;
import X.FZC;
import X.FZF;
import X.FZH;
import X.FZL;
import X.FZT;
import X.FZU;
import X.FZV;
import X.FZW;
import X.FZX;
import X.FZY;
import X.FZZ;
import X.Lea;
import X.LsD;
import X.M12;
import X.O6j;
import X.Qeg;
import android.content.Context;
import android.content.res.Resources;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageButton;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.bytedance.covode.number.Covode;
import com.ss.android.ugc.aweme.profile.model.User;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import kotlin.h.b.n;

public final class DuetStickerSearchUserFragment extends Fragment implements 3YD, FZZ {
    public static final FZY LJIIJJI = new FZY((byte) 0);
    public RecyclerView LIZ;
    public C0263FZd LIZIZ;
    public EditText LIZJ;
    public ImageButton LIZLLL;
    public Qeg LJ;
    public View LJFF;
    public 0Gh LJI;
    public List<? extends User> LJII;
    public FZC LJIIIIZZ;
    public final LinkedHashSet<User> LJIIIZ;
    public final LsD<User, Boolean, 2Pr> LJIIJ;
    public boolean LJIIL;
    public DuetStickerSearchViewModel LJIILIIL;
    public final Crj LJIILJJIL;
    public final Crj LJIILL;
    public final FZ9 LJIILLIIL;
    public HashMap LJIIZILJ;

    static {
        Covode.recordClassIndex(109898);
    }

    private HashSet<String> LJII() {
        return (HashSet) this.LJIILJJIL.getValue();
    }

    public final C0280FZu LJFF() {
        return (C0280FZu) this.LJIILL.getValue();
    }

    public DuetStickerSearchUserFragment() {
        this(new LinkedHashSet(0), (LsD<? super User, ? super Boolean, 2Pr>) null);
    }

    public final RecyclerView LIZ() {
        RecyclerView recyclerView = this.LIZ;
        if (recyclerView == null) {
            n.LIZ("");
        }
        return recyclerView;
    }

    public final ImageButton LIZJ() {
        ImageButton imageButton = this.LIZLLL;
        if (imageButton == null) {
            n.LIZ("");
        }
        return imageButton;
    }

    public final Qeg LIZLLL() {
        Qeg qeg = this.LJ;
        if (qeg == null) {
            n.LIZ("");
        }
        return qeg;
    }

    public final View LJ() {
        View view = this.LJFF;
        if (view == null) {
            n.LIZ("");
        }
        return view;
    }

    public final void onDestroy() {
        DuetStickerSearchUserFragment.super.onDestroy();
        this.LJI.LIZJ();
    }

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

    public final CDs LJI() {
        return new CDs(6, (Long) null, this.LIZIZ.LJII, "at_user", 20, Lea.LJIIJJI(LJII()));
    }

    private void LJIIIIZZ() {
        if (!LJFF().LIZIZ()) {
            LJFF().LIZJ = this;
        }
        this.LJIILLIIL.LIZ().LIZ(new FZF(this), 0Gp.LIZIZ, this.LJI.LIZIZ());
    }

    public final 2uR ch_() {
        String str;
        String str2;
        String str3;
        Resources resources;
        Resources resources2;
        Resources resources3;
        2uR r5 = new 2uR();
        3cI[] r7 = new 3cI[1];
        3c9 r2 = new 3c9();
        Context context = getContext();
        if (context == null || (resources3 = context.getResources()) == null || (str = resources3.getString(2131824119)) == null) {
            str = "";
        }
        n.LIZIZ(str, "");
        r2.LIZ(str);
        r2.LIZ(2vu.SECONDARY);
        r2.LIZ(new FZH(this));
        r7[0] = r2;
        r5.LIZ(r7);
        3cC r22 = new 3cC();
        Context context2 = getContext();
        if (context2 == null || (resources2 = context2.getResources()) == null || (str2 = resources2.getString(2131822251)) == null) {
            str2 = "";
        }
        n.LIZIZ(str2, "");
        r22.LIZ(str2);
        r5.LIZ(r22);
        3cI[] r3 = new 3cI[1];
        3c9 r23 = new 3c9();
        Context context3 = getContext();
        if (context3 == null || (resources = context3.getResources()) == null || (str3 = resources.getString(2131824001)) == null) {
            str3 = "";
        }
        n.LIZIZ(str3, "");
        r23.LIZ(str3);
        r23.LIZ(new FZL(this));
        r3[0] = r23;
        r5.LIZIZ(r3);
        return r5;
    }

    public final void LIZ(CDh cDh) {
        String userId;
        M12.LIZ(cDh);
        this.LIZIZ.LIZLLL();
        this.LJIIL = false;
        if (this.LIZIZ.LJII.length() == 0) {
            C0263FZd fZd = this.LIZIZ;
            if (fZd.LJIILIIL != null) {
                fZd.LJIILIIL.itemView.LIZJ();
            }
            fZd.LJIIIZ = 1;
            return;
        }
        ArrayList<CDg> arrayList = this.LIZIZ.LIZLLL;
        arrayList.clear();
        List list = cDh.LIZ;
        if (list != null) {
            ArrayList arrayList2 = new ArrayList();
            for (Object next : list) {
                FZ9 fz9 = this.LJIILLIIL;
                String userId2 = ((CDg) next).LJI.getUserId();
                if (userId2 == null) {
                    userId2 = "";
                }
                if (!fz9.LIZ(userId2)) {
                    arrayList2.add(next);
                }
            }
            List list2 = arrayList2;
            if (list2 != null && !list2.isEmpty()) {
                arrayList.addAll(list2);
            }
        }
        List<String> list3 = this.LIZIZ.LIZIZ;
        list3.clear();
        List<CDg> list4 = cDh.LIZ;
        if (list4 != null) {
            for (CDg cDg : list4) {
                if (cDg.LJI.getMentionBlockType() == 1 && (userId = cDg.LJI.getUserId()) != null) {
                    list3.add(userId);
                }
            }
        }
        this.LIZIZ.notifyDataSetChanged();
        LJII().addAll(this.LIZIZ.LIZIZ());
    }

    public final void LIZ(String str) {
        M12.LIZ(str);
        LJII().clear();
        this.LIZIZ.LIZ(str);
        if (!TextUtils.isEmpty(str)) {
            if (!LJFF().LIZIZ()) {
                LJFF().LIZJ = this;
            }
            ArrayList arrayList = new ArrayList();
            FZC fzc = this.LJIIIIZZ;
            if (fzc != null) {
                arrayList.addAll(fzc.LIZ);
                arrayList.addAll(fzc.LIZIZ);
                arrayList.addAll(fzc.LIZ);
            }
            ArrayList arrayList2 = new ArrayList();
            for (Object next : arrayList) {
                User user = (User) next;
                if (user.getFollowStatus() == 1 || user.getFollowStatus() == 2) {
                    arrayList2.add(next);
                }
            }
            List list = arrayList2;
            FZ9 fz9 = this.LJIILLIIL;
            M12.LIZ(str, list);
            fz9.LIZLLL = str;
            0Gp LIZIZ2 = 0Gp.LIZ(new FZB(fz9, list, str)).LIZIZ(new 9rx(fz9), 0Gp.LIZIZ);
            n.LIZIZ(LIZIZ2, "");
            LIZIZ2.LIZ(new FZT(this), 0Gp.LIZIZ, this.LJI.LIZIZ());
            return;
        }
        List<? extends User> list2 = this.LJII;
        if (list2 == null || list2.isEmpty()) {
            LJIIIIZZ();
            return;
        }
        this.LIZIZ.LIZJ.clear();
        this.LIZIZ.LIZLLL.clear();
        LinkedHashSet linkedHashSet = new LinkedHashSet();
        linkedHashSet.addAll(this.LIZIZ.LIZ);
        Collection collection = this.LJII;
        if (collection == null) {
            collection = new ArrayList();
        }
        linkedHashSet.addAll(collection);
        this.LIZIZ.LIZJ.addAll(linkedHashSet);
        this.LIZIZ.notifyDataSetChanged();
        RecyclerView recyclerView = this.LIZ;
        if (recyclerView == null) {
            n.LIZ("");
        }
        recyclerView.LIZIZ(0);
    }

    public DuetStickerSearchUserFragment(LinkedHashSet<User> linkedHashSet, LsD<? super User, ? super Boolean, 2Pr> lsD) {
        M12.LIZ(linkedHashSet);
        this.LJIIIZ = linkedHashSet;
        this.LJIIJ = lsD;
        this.LIZIZ = new C0263FZd();
        this.LJI = new 0Gh();
        this.LJIILJJIL = 7he.LIZ(FZV.LIZ);
        this.LJIILL = 7he.LIZ(FZX.LIZ);
        FZ9 fz9 = new FZ9();
        boolean z = true;
        fz9.LIZ = true;
        this.LJIILLIIL = fz9;
        this.LIZIZ.LJI = lsD;
        this.LIZIZ.LIZ.addAll(linkedHashSet);
        C0263FZd fZd = this.LIZIZ;
        fZd.LJ = fZd.LIZ.size() < 30 ? false : z;
        this.LIZIZ.LJIILJJIL = new O6j(this) {
            public final /* synthetic */ DuetStickerSearchUserFragment LIZ;

            static {
                Covode.recordClassIndex(109899);
            }

            {
                this.LIZ = r1;
            }

            public final void LIZ() {
                this.LIZ.LIZIZ.LIZJ();
                this.LIZ.LJFF().LIZ(false, this.LIZ.LJI());
            }
        };
    }

    public final void onViewCreated(View view, Bundle bundle) {
        1Bn r2;
        M12.LIZ(view);
        DuetStickerSearchUserFragment.super.onViewCreated(view, bundle);
        RecyclerView findViewById = view.findViewById(2131364296);
        n.LIZIZ(findViewById, "");
        this.LIZ = findViewById;
        View findViewById2 = view.findViewById(2131364292);
        n.LIZIZ(findViewById2, "");
        this.LIZJ = (EditText) findViewById2;
        View findViewById3 = view.findViewById(2131364278);
        n.LIZIZ(findViewById3, "");
        this.LIZLLL = (ImageButton) findViewById3;
        Qeg findViewById4 = view.findViewById(2131364294);
        n.LIZIZ(findViewById4, "");
        this.LJ = findViewById4;
        View findViewById5 = view.findViewById(2131364293);
        n.LIZIZ(findViewById5, "");
        this.LJFF = findViewById5;
        RecyclerView recyclerView = this.LIZ;
        if (recyclerView == null) {
            n.LIZ("");
        }
        recyclerView.setAdapter(this.LIZIZ);
        getContext();
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager();
        linearLayoutManager.LIZIZ(1);
        RecyclerView recyclerView2 = this.LIZ;
        if (recyclerView2 == null) {
            n.LIZ("");
        }
        recyclerView2.setLayoutManager(linearLayoutManager);
        0Bx LIZ2 = 0By.LIZ(this, (0Bv) null);
        if (2GD.LIZ) {
            0Bs.LIZ(LIZ2, this);
        }
        DuetStickerSearchViewModel LIZ3 = LIZ2.LIZ(DuetStickerSearchViewModel.class);
        this.LJIILIIL = LIZ3;
        if (!(LIZ3 == null || (r2 = LIZ3.LIZ) == null)) {
            r2.observe(this, new BRI(this));
        }
        DuetStickerSearchViewModel duetStickerSearchViewModel = this.LJIILIIL;
        if (duetStickerSearchViewModel != null) {
            duetStickerSearchViewModel.LIZ(this.LIZIZ.LIZ);
        }
        this.LIZIZ.LJFF = this.LJIILIIL;
        ImageButton imageButton = this.LIZLLL;
        if (imageButton == null) {
            n.LIZ("");
        }
        imageButton.setOnClickListener(new FZW(this));
        EditText editText = this.LIZJ;
        if (editText == null) {
            n.LIZ("");
        }
        editText.addTextChangedListener(new FZU(this));
        LJIIIIZZ();
    }

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