package defpackage;

import android.content.Context;
import android.view.View;
import android.widget.HorizontalScrollView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import androidx.recyclerview.widget.RecyclerView;
import com.strmr.ps.data.model.debrid.DebridFileItem;
import com.strmr.ps.data.model.debrid.DebridServiceSection;
import com.strmr.ps.ui.library.DebridLibraryFragment;
import com.strmr.ps.ui.library.DebridLibraryFragment$createLibraryLayoutManager$1;
import com.strmr.ps.ui.player.VideoPlayerActivity;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/* JADX INFO: loaded from: classes3.dex */
public final /* synthetic */ class hv1 implements sq3 {
    public final /* synthetic */ int a;
    public final /* synthetic */ DebridLibraryFragment b;

    public /* synthetic */ hv1(DebridLibraryFragment debridLibraryFragment, int i) {
        this.a = i;
        this.b = debridLibraryFragment;
    }

    /* JADX WARN: Type inference fix 'apply assigned field type' failed
    java.lang.UnsupportedOperationException: ArgType.getObject(), call class: class jadx.core.dex.instructions.args.ArgType$UnknownArg
    	at jadx.core.dex.instructions.args.ArgType.getObject(ArgType.java:593)
    	at jadx.core.dex.attributes.nodes.ClassTypeVarsAttr.getTypeVarsMapFor(ClassTypeVarsAttr.java:35)
    	at jadx.core.dex.nodes.utils.TypeUtils.replaceClassGenerics(TypeUtils.java:177)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.insertExplicitUseCast(FixTypesVisitor.java:397)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.tryFieldTypeWithNewCasts(FixTypesVisitor.java:359)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.applyFieldType(FixTypesVisitor.java:309)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.visit(FixTypesVisitor.java:94)
     */
    @Override // defpackage.sq3
    public final Object invoke(Object obj) {
        String name;
        int i = this.a;
        e6a e6aVar = e6a.a;
        DebridLibraryFragment debridLibraryFragment = this.b;
        switch (i) {
            case 0:
                DebridFileItem.File file = (DebridFileItem.File) obj;
                cr4.g(file, "file");
                debridLibraryFragment.q().f(file);
                return e6aVar;
            case 1:
                Boolean bool = (Boolean) obj;
                View view = debridLibraryFragment.j;
                if (view != null) {
                    view.setVisibility(bool.booleanValue() ? 0 : 8);
                    return e6aVar;
                }
                cr4.n("loadingIndicator");
                throw null;
            case 2:
                List list = (List) obj;
                if (debridLibraryFragment.q().p.isEmpty()) {
                    if (debridLibraryFragment.q) {
                        debridLibraryFragment.q = false;
                        debridLibraryFragment.r();
                    }
                    cr4.d(list);
                    ArrayList arrayList = new ArrayList();
                    for (Object obj2 : list) {
                        DebridServiceSection debridServiceSection = (DebridServiceSection) obj2;
                        if (!debridServiceSection.getItems().isEmpty() || debridServiceSection.isLoading()) {
                            arrayList.add(obj2);
                        }
                    }
                    debridLibraryFragment.t = arrayList;
                    ArrayList<DebridServiceSection> arrayList2 = new ArrayList();
                    for (Object obj3 : arrayList) {
                        if (!((DebridServiceSection) obj3).getItems().isEmpty()) {
                            arrayList2.add(obj3);
                        }
                    }
                    if (arrayList2.size() < 2) {
                        HorizontalScrollView horizontalScrollView = debridLibraryFragment.m;
                        if (horizontalScrollView == null) {
                            cr4.n("serviceTabsContainer");
                            throw null;
                        }
                        horizontalScrollView.setVisibility(8);
                    } else {
                        HorizontalScrollView horizontalScrollView2 = debridLibraryFragment.m;
                        if (horizontalScrollView2 == null) {
                            cr4.n("serviceTabsContainer");
                            throw null;
                        }
                        horizontalScrollView2.setVisibility(0);
                        LinearLayout linearLayout = debridLibraryFragment.n;
                        if (linearLayout == null) {
                            cr4.n("serviceTabs");
                            throw null;
                        }
                        dp4 dp4VarG = zr7.g(0, linearLayout.getChildCount());
                        ArrayList arrayList3 = new ArrayList(y41.p(dp4VarG, 10));
                        Iterator<Integer> it = dp4VarG.iterator();
                        while (((cp4) it).c) {
                            int iNextInt = ((to4) it).nextInt();
                            LinearLayout linearLayout2 = debridLibraryFragment.n;
                            if (linearLayout2 == null) {
                                cr4.n("serviceTabs");
                                throw null;
                            }
                            Object tag = linearLayout2.getChildAt(iNextInt).getTag();
                            arrayList3.add(tag instanceof String ? (String) tag : null);
                        }
                        List listAm = y41.am(null);
                        ArrayList arrayList4 = new ArrayList(y41.p(arrayList2, 10));
                        Iterator it2 = arrayList2.iterator();
                        while (it2.hasNext()) {
                            arrayList4.add(((DebridServiceSection) it2.next()).getServiceName());
                        }
                        if (arrayList3.equals(y41.au(arrayList4, listAm))) {
                            debridLibraryFragment.u();
                        } else {
                            LinearLayout linearLayout3 = debridLibraryFragment.n;
                            if (linearLayout3 == null) {
                                cr4.n("serviceTabs");
                                throw null;
                            }
                            linearLayout3.removeAllViews();
                            debridLibraryFragment.l("All", null, debridLibraryFragment.s == null);
                            for (DebridServiceSection debridServiceSection2 : arrayList2) {
                                debridLibraryFragment.l(debridServiceSection2.getServiceDisplayName() + " (" + debridServiceSection2.getItems().size() + ")", debridServiceSection2.getServiceName(), cr4.b(debridLibraryFragment.s, debridServiceSection2.getServiceName()));
                            }
                        }
                    }
                    debridLibraryFragment.o();
                }
                return e6aVar;
            case 3:
                if (((DebridFileItem.Folder) obj) != null && !debridLibraryFragment.q) {
                    debridLibraryFragment.q = true;
                    HorizontalScrollView horizontalScrollView3 = debridLibraryFragment.m;
                    if (horizontalScrollView3 == null) {
                        cr4.n("serviceTabsContainer");
                        throw null;
                    }
                    horizontalScrollView3.setVisibility(8);
                    debridLibraryFragment.requireContext();
                    DebridLibraryFragment$createLibraryLayoutManager$1 debridLibraryFragment$createLibraryLayoutManager$1 = new DebridLibraryFragment$createLibraryLayoutManager$1(debridLibraryFragment);
                    RecyclerView recyclerView = debridLibraryFragment.i;
                    if (recyclerView == null) {
                        cr4.n("libraryContent");
                        throw null;
                    }
                    recyclerView.setLayoutManager(debridLibraryFragment$createLibraryLayoutManager$1);
                    RecyclerView recyclerView2 = debridLibraryFragment.i;
                    if (recyclerView2 == null) {
                        cr4.n("libraryContent");
                        throw null;
                    }
                    bv1 bv1Var = debridLibraryFragment.p;
                    if (bv1Var == null) {
                        cr4.n("folderAdapter");
                        throw null;
                    }
                    recyclerView2.setAdapter(bv1Var);
                    debridLibraryFragment.m();
                }
                return e6aVar;
            case 4:
                List list2 = (List) obj;
                if (!debridLibraryFragment.q().p.isEmpty()) {
                    bv1 bv1Var2 = debridLibraryFragment.p;
                    if (bv1Var2 == null) {
                        cr4.n("folderAdapter");
                        throw null;
                    }
                    bv1Var2.e(list2);
                }
                return e6aVar;
            case 5:
                List list3 = (List) obj;
                cr4.d(list3);
                if (list3.size() <= 1) {
                    TextView textView = debridLibraryFragment.l;
                    if (textView == null) {
                        cr4.n("breadcrumbTrail");
                        throw null;
                    }
                    textView.setVisibility(8);
                } else {
                    String strAi = y41.ai(list3, " > ", null, null, new me1(15), 30);
                    TextView textView2 = debridLibraryFragment.l;
                    if (textView2 == null) {
                        cr4.n("breadcrumbTrail");
                        throw null;
                    }
                    textView2.setText(strAi);
                    TextView textView3 = debridLibraryFragment.l;
                    if (textView3 == null) {
                        cr4.n("breadcrumbTrail");
                        throw null;
                    }
                    textView3.setVisibility(0);
                }
                return e6aVar;
            case 6:
                DebridFileItem.Folder folder = (DebridFileItem.Folder) obj;
                cr4.g(folder, "folder");
                debridLibraryFragment.q().e(folder);
                return e6aVar;
            case 7:
                String str = (String) obj;
                if (str != null) {
                    DebridFileItem.Folder folder2 = (DebridFileItem.Folder) debridLibraryFragment.q().g.e();
                    if (folder2 == null || (name = folder2.getName()) == null) {
                        name = "Debrid File";
                    }
                    long[] jArr = VideoPlayerActivity.R0;
                    Context contextRequireContext = debridLibraryFragment.requireContext();
                    cr4.f(contextRequireContext, "requireContext(...)");
                    VideoPlayerActivity.b.a(contextRequireContext, str, name, null, null, -1, -1, 0L, null);
                    debridLibraryFragment.q().l.l(null);
                }
                return e6aVar;
            case 8:
                String str2 = (String) obj;
                if (str2 != null) {
                    Toast.makeText(debridLibraryFragment.requireContext(), str2, 1).show();
                    debridLibraryFragment.q().n.l(null);
                }
                return e6aVar;
            case 9:
                DebridFileItem debridFileItem = (DebridFileItem) obj;
                cr4.g(debridFileItem, "item");
                debridLibraryFragment.s(debridFileItem);
                return e6aVar;
            case 10:
                DebridFileItem.File file2 = (DebridFileItem.File) obj;
                cr4.g(file2, "file");
                debridLibraryFragment.q().f(file2);
                return e6aVar;
            case 11:
                DebridFileItem.Folder folder3 = (DebridFileItem.Folder) obj;
                cr4.g(folder3, "folder");
                debridLibraryFragment.q().e(folder3);
                return e6aVar;
            default:
                DebridFileItem debridFileItem2 = (DebridFileItem) obj;
                cr4.g(debridFileItem2, "item");
                debridLibraryFragment.s(debridFileItem2);
                return e6aVar;
        }
    }
}
