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

import X.0AA;
import X.0Bs;
import X.0Bv;
import X.0Bx;
import X.0By;
import X.0Gh;
import X.0Gp;
import X.0HH;
import X.1hK;
import X.2GD;
import X.2Pr;
import X.2nK;
import X.2uR;
import X.2wD;
import X.3D4;
import X.3Dx;
import X.3G4;
import X.3YB;
import X.3YD;
import X.3Yi;
import X.3Ym;
import X.3Yu;
import X.3Yw;
import X.3ZQ;
import X.3cA;
import X.3cC;
import X.3cI;
import X.6J4;
import X.BRG;
import X.BRH;
import X.C0183FWb;
import X.C0261FZb;
import X.C0268FZi;
import X.FZ9;
import X.FZE;
import X.FZG;
import X.FZM;
import X.FZR;
import X.Ls2;
import X.LsD;
import X.M12;
import X.NO8;
import X.Qeg;
import android.app.Activity;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.bytedance.covode.number.Covode;
import com.bytedance.tux.sheet.sheet.TuxSheet;
import com.ss.android.ugc.aweme.profile.model.User;
import com.ss.android.ugc.aweme.shortvideo.edit.VideoPublishEditModel;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Objects;
import kotlin.h.b.n;

public final class DuetStickerRecommendFragment extends Fragment implements 3YD {
    public static final BRG LJIIL = new BRG((byte) 0);
    public RecyclerView LIZ;
    public C0268FZi LIZIZ;
    public TuxSheet LIZJ;
    public 3Yi LIZLLL;
    public Qeg LJ;
    public 3Yu LJFF;
    public DuetStickerRecommendViewModel LJI;
    public 0Gh LJII;
    public DuetStickerSearchUserFragment LJIIIIZZ;
    public final LinkedHashSet<User> LJIIIZ;
    public final boolean LJIIJ;
    public final VideoPublishEditModel LJIIJJI;
    public View LJIILIIL;
    public final FZ9 LJIILJJIL;
    public HashMap LJIILL;

    static {
        Covode.recordClassIndex(109885);
    }

    public DuetStickerRecommendFragment() {
        this(new LinkedHashSet(0), false, (VideoPublishEditModel) null);
    }

    public final void onDestroy() {
        DuetStickerRecommendFragment.super.onDestroy();
        this.LJII.LIZJ();
    }

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

    public final 2uR ch_() {
        String str;
        Resources resources;
        2uR r5 = new 2uR();
        3cC r3 = new 3cC();
        Context context = getContext();
        if (context == null || (resources = context.getResources()) == null || (str = resources.getString(2131824133)) == null) {
            str = "";
        }
        n.LIZIZ(str, "");
        r3.LIZ(str);
        r5.LIZ(r3);
        3cA r1 = new 3cA();
        r1.LIZ(2131755740);
        r1.LIZ(new FZM(this));
        r5.LIZIZ(new 3cI[]{r1});
        r5.LIZLLL = true;
        return r5;
    }

    /* JADX WARNING: Code restructure failed: missing block: B:25:0x00cd, code lost:
        r9.add(r7);
     */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public final void LIZ(java.util.LinkedHashSet<com.ss.android.ugc.aweme.profile.model.User> r11) {
        /*
            r10 = this;
            java.util.LinkedHashSet<com.ss.android.ugc.aweme.profile.model.User> r0 = r10.LJIIIZ
            r0.clear()
            java.util.LinkedHashSet<com.ss.android.ugc.aweme.profile.model.User> r0 = r10.LJIIIZ
            r0.addAll(r11)
            X.FZi r0 = r10.LIZIZ
            java.util.LinkedHashSet<com.ss.android.ugc.aweme.profile.model.User> r0 = r0.LIZ
            r0.clear()
            X.FZi r0 = r10.LIZIZ
            java.util.LinkedHashSet<com.ss.android.ugc.aweme.profile.model.User> r0 = r0.LIZ
            r0.addAll(r11)
            X.FZi r0 = r10.LIZIZ
            java.util.ArrayList<com.ss.android.ugc.aweme.profile.model.User> r0 = r0.LJI
            java.util.ArrayList r3 = new java.util.ArrayList
            r3.<init>()
            java.util.Iterator r2 = r0.iterator()
        L_0x0025:
            boolean r1 = r2.hasNext()
            r0 = 1
            r4 = 0
            if (r1 == 0) goto L_0x0045
            java.lang.Object r1 = r2.next()
            r0 = r1
            com.ss.android.ugc.aweme.profile.model.User r0 = (com.ss.android.ugc.aweme.profile.model.User) r0
            java.lang.String r0 = r0.getUid()
            if (r0 == 0) goto L_0x0025
            int r0 = r0.length()
            if (r0 != 0) goto L_0x0041
            goto L_0x0025
        L_0x0041:
            r3.add(r1)
            goto L_0x0025
        L_0x0045:
            java.util.List r3 = (java.util.List) r3
            X.FZi r0 = r10.LIZIZ
            java.util.ArrayList<com.ss.android.ugc.aweme.profile.model.User> r0 = r0.LJI
            r0.clear()
            X.FZi r0 = r10.LIZIZ
            java.util.ArrayList<com.ss.android.ugc.aweme.profile.model.User> r0 = r0.LJI
            r0.addAll(r3)
            int r0 = r11.size()
            r3 = 15
            if (r0 < r3) goto L_0x0091
            X.FZi r0 = r10.LIZIZ
            java.util.ArrayList<com.ss.android.ugc.aweme.profile.model.User> r0 = r0.LJI
            r0.clear()
            X.FZi r0 = r10.LIZIZ
            java.util.ArrayList<com.ss.android.ugc.aweme.profile.model.User> r1 = r0.LJI
            java.util.List r0 = X.Lea.LJIIJJI(r11)
            java.util.List r0 = r0.subList(r4, r3)
            r1.addAll(r0)
        L_0x0073:
            X.FZi r0 = r10.LIZIZ
            java.util.ArrayList<com.ss.android.ugc.aweme.profile.model.User> r1 = r0.LJI
            com.ss.android.ugc.aweme.profile.model.User r0 = new com.ss.android.ugc.aweme.profile.model.User
            r0.<init>()
            r1.add(r0)
            X.FZi r0 = r10.LIZIZ
            r0.notifyDataSetChanged()
            com.ss.android.ugc.aweme.shortvideo.edit.infosticker.interact.duet.DuetStickerRecommendViewModel r1 = r10.LJI
            if (r1 != 0) goto L_0x008d
            java.lang.String r0 = ""
            kotlin.h.b.n.LIZ(r0)
        L_0x008d:
            r1.LIZ(r11)
            return
        L_0x0091:
            X.FZi r0 = r10.LIZIZ
            java.util.ArrayList<com.ss.android.ugc.aweme.profile.model.User> r0 = r0.LJI
            java.util.ArrayList r9 = new java.util.ArrayList
            r9.<init>()
            java.util.Iterator r8 = r0.iterator()
        L_0x009e:
            boolean r0 = r8.hasNext()
            if (r0 == 0) goto L_0x00d1
            java.lang.Object r7 = r8.next()
            r6 = r7
            com.ss.android.ugc.aweme.profile.model.User r6 = (com.ss.android.ugc.aweme.profile.model.User) r6
            r0 = r11
            java.util.Iterator r5 = r0.iterator()
        L_0x00b0:
            boolean r0 = r5.hasNext()
            if (r0 == 0) goto L_0x00cd
            java.lang.Object r2 = r5.next()
            r0 = r2
            com.ss.android.ugc.aweme.profile.model.User r0 = (com.ss.android.ugc.aweme.profile.model.User) r0
            java.lang.String r1 = r0.getUid()
            java.lang.String r0 = r6.getUid()
            boolean r0 = android.text.TextUtils.equals(r1, r0)
            if (r0 == 0) goto L_0x00b0
            if (r2 != 0) goto L_0x009e
        L_0x00cd:
            r9.add(r7)
            goto L_0x009e
        L_0x00d1:
            java.util.List r9 = (java.util.List) r9
            java.util.List r2 = X.Lea.LJII(r9)
            r2.addAll(r4, r11)
            X.FZi r0 = r10.LIZIZ
            java.util.ArrayList<com.ss.android.ugc.aweme.profile.model.User> r0 = r0.LJI
            r0.clear()
            int r0 = r2.size()
            if (r0 <= r3) goto L_0x00f3
            X.FZi r0 = r10.LIZIZ
            java.util.ArrayList<com.ss.android.ugc.aweme.profile.model.User> r1 = r0.LJI
            java.util.List r0 = r2.subList(r4, r3)
            r1.addAll(r0)
            goto L_0x0073
        L_0x00f3:
            X.FZi r0 = r10.LIZIZ
            java.util.ArrayList<com.ss.android.ugc.aweme.profile.model.User> r0 = r0.LJI
            r0.addAll(r2)
            goto L_0x0073
        */
        throw new UnsupportedOperationException("Method not decompiled: com.ss.android.ugc.aweme.shortvideo.edit.infosticker.interact.duet.DuetStickerRecommendFragment.LIZ(java.util.LinkedHashSet):void");
    }

    public final void LIZ(User user, boolean z) {
        String str;
        String str2;
        if (user != null) {
            6J4 r3 = new 6J4();
            n.LIZIZ(r3, "");
            VideoPublishEditModel videoPublishEditModel = this.LJIIJJI;
            String str3 = null;
            if (videoPublishEditModel != null) {
                str = videoPublishEditModel.getCreationId();
            } else {
                str = null;
            }
            r3.LIZ("creation_id", str);
            NO8 LJ2 = C0183FWb.LIZIZ.LIZ().LJJIIJ().LJ();
            if (LJ2 != null) {
                str3 = LJ2.LIZJ();
            }
            r3.LIZ("user_id", str3);
            r3.LIZ("invite_user_id", user.getUid());
            6J4 r2 = r3;
            if (z) {
                str2 = "click head";
            } else {
                str2 = "search";
            }
            r2.LIZ("click_method", str2);
            2nK.LIZ("invite_people_to_duet", r3.LIZ);
        }
    }

    public final void onViewCreated(View view, Bundle bundle) {
        String str;
        Resources resources;
        M12.LIZ(view);
        DuetStickerRecommendFragment.super.onViewCreated(view, bundle);
        if (getView() != null) {
            View view2 = getView();
            Objects.requireNonNull(view2, "null cannot be cast to non-null type android.view.View");
            this.LJIILIIL = view2;
            if (view2 == null) {
                n.LIZ("");
            }
            RecyclerView findViewById = view2.findViewById(2131364295);
            n.LIZIZ(findViewById, "");
            RecyclerView recyclerView = findViewById;
            this.LIZ = recyclerView;
            if (recyclerView == null) {
                n.LIZ("");
            }
            recyclerView.LIZIZ(new FZR(this));
            View view3 = this.LJIILIIL;
            if (view3 == null) {
                n.LIZ("");
            }
            3Yu findViewById2 = view3.findViewById(2131366142);
            n.LIZIZ(findViewById2, "");
            3Yu r2 = findViewById2;
            this.LJFF = r2;
            if (r2 == null) {
                n.LIZ("");
            }
            Context context = getContext();
            if (context == null || (resources = context.getResources()) == null || (str = resources.getString(2131824128)) == null) {
                str = "Invite people to Duet";
            }
            r2.setTitle(str);
            3Yu r1 = this.LJFF;
            if (r1 == null) {
                n.LIZ("");
            }
            r1.setHeaderSize(3Yw.SMALL);
            3Yu r12 = this.LJFF;
            if (r12 == null) {
                n.LIZ("");
            }
            r12.setShowSeparator(true);
            RecyclerView recyclerView2 = this.LIZ;
            if (recyclerView2 == null) {
                n.LIZ("");
            }
            recyclerView2.setAdapter(this.LIZIZ);
            View view4 = this.LJIILIIL;
            if (view4 == null) {
                n.LIZ("");
            }
            3Yi findViewById3 = view4.findViewById(2131364276);
            n.LIZIZ(findViewById3, "");
            3Yi r0 = findViewById3;
            this.LIZLLL = r0;
            if (r0 == null) {
                n.LIZ("");
            }
            r0.setWithSeparator(false);
            3Yi r13 = this.LIZLLL;
            if (r13 == null) {
                n.LIZ("");
            }
            r13.setInset(2wD.PADDING_16);
            3Yi r02 = this.LIZLLL;
            if (r02 == null) {
                n.LIZ("");
            }
            r02.setIcon((3ZQ) null);
            3Yi r03 = this.LIZLLL;
            if (r03 == null) {
                n.LIZ("");
            }
            3Ym accessory = r03.getAccessory();
            if (!(accessory instanceof 3D4)) {
                accessory = null;
            }
            3Dx r14 = (3Dx) accessory;
            if (r14 != null) {
                r14.LIZJ(this.LJIIJ);
            }
            View view5 = this.LJIILIIL;
            if (view5 == null) {
                n.LIZ("");
            }
            Qeg findViewById4 = view5.findViewById(2131364297);
            n.LIZIZ(findViewById4, "");
            Qeg qeg = findViewById4;
            this.LJ = qeg;
            if (qeg == null) {
                n.LIZ("");
            }
            BRG brg = LJIIL;
            qeg.setText(brg.LIZ(brg.LIZ(getContext(), this.LJIIIZ)));
            getContext();
            LinearLayoutManager linearLayoutManager = new LinearLayoutManager();
            linearLayoutManager.LIZIZ(0);
            RecyclerView recyclerView3 = this.LIZ;
            if (recyclerView3 == null) {
                n.LIZ("");
            }
            recyclerView3.setLayoutManager(linearLayoutManager);
            this.LJIILJJIL.LIZ().LIZ(new FZE(this), 0Gp.LIZIZ, this.LJII.LIZIZ());
        }
        0Bx LIZ2 = 0By.LIZ(this, (0Bv) null);
        if (2GD.LIZ) {
            0Bs.LIZ(LIZ2, this);
        }
        DuetStickerRecommendViewModel LIZ3 = LIZ2.LIZ(DuetStickerRecommendViewModel.class);
        n.LIZIZ(LIZ3, "");
        DuetStickerRecommendViewModel duetStickerRecommendViewModel = LIZ3;
        this.LJI = duetStickerRecommendViewModel;
        C0268FZi fZi = this.LIZIZ;
        if (duetStickerRecommendViewModel == null) {
            n.LIZ("");
        }
        fZi.LIZLLL = duetStickerRecommendViewModel;
        DuetStickerRecommendViewModel duetStickerRecommendViewModel2 = this.LJI;
        if (duetStickerRecommendViewModel2 == null) {
            n.LIZ("");
        }
        duetStickerRecommendViewModel2.LIZ.observe(this, new BRH(this));
    }

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

    public DuetStickerRecommendFragment(LinkedHashSet<User> linkedHashSet, boolean z, VideoPublishEditModel videoPublishEditModel) {
        M12.LIZ(linkedHashSet);
        this.LJIIIZ = linkedHashSet;
        this.LJIIJ = z;
        this.LJIIJJI = videoPublishEditModel;
        this.LIZIZ = new C0268FZi();
        this.LJII = new 0Gh();
        FZ9 fz9 = new FZ9();
        boolean z2 = true;
        fz9.LIZ = true;
        this.LJIILJJIL = fz9;
        this.LIZIZ.LJ = new LsD<User, Boolean, 2Pr>(this) {
            static {
                Covode.recordClassIndex(109886);
            }

            public final /* synthetic */ Object invoke(Object obj, Object obj2) {
                boolean booleanValue = ((Boolean) obj2).booleanValue();
                ((DuetStickerRecommendFragment) this.receiver).LIZ((User) obj, booleanValue);
                return 2Pr.LIZ;
            }
        };
        this.LIZIZ.LIZ.addAll(linkedHashSet);
        C0268FZi fZi = this.LIZIZ;
        fZi.LIZJ = fZi.LIZ.size() < 30 ? false : z2;
        this.LIZIZ.LIZIZ = new Ls2<2Pr>(this) {
            static {
                Covode.recordClassIndex(109887);
            }

            public final /* synthetic */ Object invoke() {
                1hK r2;
                DuetStickerRecommendFragment duetStickerRecommendFragment = (DuetStickerRecommendFragment) this.receiver;
                DuetStickerSearchUserFragment duetStickerSearchUserFragment = new DuetStickerSearchUserFragment(duetStickerRecommendFragment.LIZIZ.LIZ, new C0261FZb(duetStickerRecommendFragment));
                duetStickerRecommendFragment.LJIIIIZZ = duetStickerSearchUserFragment;
                3YB r22 = new 3YB();
                r22.LIZ(1);
                r22.LIZIZ(3G4.LJ(duetStickerRecommendFragment.getContext()) - 3G4.LIZJ(duetStickerRecommendFragment.getContext()));
                r22.LIZIZ();
                r22.LIZ(new FZG(duetStickerRecommendFragment));
                r22.LIZIZ(false);
                r22.LIZ(duetStickerSearchUserFragment);
                duetStickerRecommendFragment.LIZJ = r22.LIZ;
                TuxSheet tuxSheet = duetStickerRecommendFragment.LIZJ;
                if (tuxSheet != null) {
                    Context context = duetStickerRecommendFragment.getContext();
                    0AA r1 = null;
                    if (context != null) {
                        while (true) {
                            if (!(context instanceof Activity)) {
                                if (context instanceof ContextWrapper) {
                                    context = ((ContextWrapper) context).getBaseContext();
                                    if (context == null) {
                                        break;
                                    }
                                } else {
                                    break;
                                }
                            } else {
                                r2 = (Activity) context;
                                break;
                            }
                        }
                    }
                    r2 = null;
                    if (!(r2 instanceof 1hK)) {
                        r2 = null;
                    }
                    1hK r23 = r2;
                    if (r23 != null) {
                        r1 = r23.getSupportFragmentManager();
                    }
                    tuxSheet.show(r1, "DuetSearchUserDialog");
                }
                return 2Pr.LIZ;
            }
        };
    }
}
