package com.strmr.ps.ui.mobile.settings;

import android.annotation.SuppressLint;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.media3.container.NalUnitUtil;
import androidx.media3.exoplayer.upstream.CmcdData;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.materialswitch.MaterialSwitch;
import com.strmr.ps.R;
import com.strmr.ps.data.local.entity.InstalledAddonEntity;
import com.strmr.ps.ui.mobile.settings.g;
import defpackage.co;
import defpackage.cr4;
import defpackage.gr3;
import defpackage.gy5;
import defpackage.n41;
import defpackage.n89;
import defpackage.sq3;
import defpackage.td;
import defpackage.vx8;
import defpackage.y41;
import java.util.ArrayList;
import java.util.Iterator;
import kotlin.Metadata;

/* JADX INFO: loaded from: classes3.dex */
@Metadata(d1 = {"\u0000\u0010\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\u0018\u00002\f\u0012\b\u0012\u00060\u0002R\u00020\u00000\u0001:\u0001\u0003¨\u0006\u0004"}, d2 = {"Lcom/strmr/ps/ui/mobile/settings/g;", "Landroidx/recyclerview/widget/RecyclerView$g;", "Lcom/strmr/ps/ui/mobile/settings/g$a;", CmcdData.OBJECT_TYPE_AUDIO_ONLY, "app_sideloadRelease"}, k = 1, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
public final class g extends RecyclerView.g<a> {
    public final sq3 a;
    public final gr3 b;
    public final sq3 c;
    public final sq3 d;
    public final sq3 e;
    public final co f;
    public ArrayList g = new ArrayList();
    public boolean h;

    @Metadata(d1 = {"\u0000\n\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\b\u0087\u0004\u0018\u00002\u00020\u0001¨\u0006\u0002"}, d2 = {"Lcom/strmr/ps/ui/mobile/settings/g$a;", "Landroidx/recyclerview/widget/RecyclerView$ag;", "app_sideloadRelease"}, k = 1, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
    @SuppressLint({"ClickableViewAccessibility"})
    @vx8
    public final class a extends RecyclerView.ag {
        public static final /* synthetic */ int j = 0;
        public final TextView a;
        public final TextView b;
        public final TextView c;
        public final TextView d;
        public final MaterialSwitch e;
        public final ImageButton f;
        public final ImageButton g;
        public final ImageButton h;

        public a(View view) {
            super(view);
            View viewFindViewById = view.findViewById(R.id.drag_handle);
            cr4.f(viewFindViewById, "findViewById(...)");
            View viewFindViewById2 = view.findViewById(R.id.addon_icon);
            cr4.f(viewFindViewById2, "findViewById(...)");
            this.a = (TextView) viewFindViewById2;
            View viewFindViewById3 = view.findViewById(R.id.addon_name);
            cr4.f(viewFindViewById3, "findViewById(...)");
            this.b = (TextView) viewFindViewById3;
            View viewFindViewById4 = view.findViewById(R.id.addon_description);
            cr4.f(viewFindViewById4, "findViewById(...)");
            this.c = (TextView) viewFindViewById4;
            View viewFindViewById5 = view.findViewById(R.id.addon_version);
            cr4.f(viewFindViewById5, "findViewById(...)");
            this.d = (TextView) viewFindViewById5;
            View viewFindViewById6 = view.findViewById(R.id.addon_switch);
            cr4.f(viewFindViewById6, "findViewById(...)");
            this.e = (MaterialSwitch) viewFindViewById6;
            View viewFindViewById7 = view.findViewById(R.id.btn_refresh);
            cr4.f(viewFindViewById7, "findViewById(...)");
            this.f = (ImageButton) viewFindViewById7;
            View viewFindViewById8 = view.findViewById(R.id.btn_configure);
            cr4.f(viewFindViewById8, "findViewById(...)");
            this.g = (ImageButton) viewFindViewById8;
            View viewFindViewById9 = view.findViewById(R.id.btn_delete);
            cr4.f(viewFindViewById9, "findViewById(...)");
            this.h = (ImageButton) viewFindViewById9;
            ((ImageView) viewFindViewById).setOnTouchListener(new gy5(g.this, this, 1));
        }
    }

    public g(sq3 sq3Var, gr3 gr3Var, sq3 sq3Var2, sq3 sq3Var3, sq3 sq3Var4, co coVar) {
        this.a = sq3Var;
        this.b = gr3Var;
        this.c = sq3Var2;
        this.d = sq3Var3;
        this.e = sq3Var4;
        this.f = coVar;
    }

    @Override // androidx.recyclerview.widget.RecyclerView.g
    public final int getItemCount() {
        return this.g.size();
    }

    @Override // androidx.recyclerview.widget.RecyclerView.g
    public final void onBindViewHolder(RecyclerView.ag agVar, int i) {
        int i2;
        String strConcat;
        a aVar = (a) agVar;
        cr4.g(aVar, "holder");
        final InstalledAddonEntity installedAddonEntity = (InstalledAddonEntity) this.g.get(i);
        ImageButton imageButton = aVar.g;
        MaterialSwitch materialSwitch = aVar.e;
        cr4.g(installedAddonEntity, "addon");
        TextView textView = aVar.a;
        textView.setText(String.valueOf(Character.toUpperCase(n89.v(installedAddonEntity.getName()))));
        final g gVar = g.this;
        int iIntValue = ((Number) ((y) gVar.a).invoke(installedAddonEntity.getName())).intValue();
        Drawable background = textView.getBackground();
        GradientDrawable gradientDrawable = background instanceof GradientDrawable ? (GradientDrawable) background : null;
        if (gradientDrawable != null) {
            gradientDrawable.setColor(iIntValue);
        } else {
            GradientDrawable gradientDrawable2 = new GradientDrawable();
            gradientDrawable2.setShape(1);
            gradientDrawable2.setColor(iIntValue);
            textView.setBackground(gradientDrawable2);
        }
        ArrayList arrayList = gVar.g;
        if (arrayList == null || !arrayList.isEmpty()) {
            Iterator it = arrayList.iterator();
            i2 = 0;
            while (it.hasNext()) {
                if (cr4.b(((InstalledAddonEntity) it.next()).getAddonId(), installedAddonEntity.getAddonId()) && (i2 = i2 + 1) < 0) {
                    y41.bl();
                    throw null;
                }
            }
        } else {
            i2 = 0;
        }
        boolean z = i2 > 1;
        TextView textView2 = aVar.b;
        String name = installedAddonEntity.getName();
        if (z) {
            name = name + " #" + installedAddonEntity.getInstanceNumber();
        }
        textView2.setText(name);
        TextView textView3 = aVar.c;
        String description = installedAddonEntity.getDescription();
        if (description == null) {
            description = "Stream addon";
        }
        textView3.setText(description);
        TextView textView4 = aVar.d;
        String version = installedAddonEntity.getVersion();
        if (version == null || (strConcat = "v".concat(version)) == null) {
            strConcat = "";
        }
        textView4.setText(strConcat);
        materialSwitch.setOnCheckedChangeListener(null);
        materialSwitch.setChecked(installedAddonEntity.getEnabled());
        materialSwitch.setOnCheckedChangeListener(new td(gVar, installedAddonEntity, 1));
        final int i3 = 0;
        aVar.f.setOnClickListener(new View.OnClickListener(gVar) { // from class: w06
            public final /* synthetic */ g b;

            {
                this.b = gVar;
            }

            @Override // android.view.View.OnClickListener
            public final void onClick(View view) {
                int i4 = i3;
                InstalledAddonEntity installedAddonEntity2 = installedAddonEntity;
                g gVar2 = this.b;
                switch (i4) {
                    case 0:
                        int i5 = g.a.j;
                        gVar2.d.invoke(installedAddonEntity2);
                        break;
                    case 1:
                        int i6 = g.a.j;
                        gVar2.e.invoke(installedAddonEntity2);
                        break;
                    default:
                        int i7 = g.a.j;
                        gVar2.c.invoke(installedAddonEntity2);
                        break;
                }
            }
        });
        imageButton.setVisibility(installedAddonEntity.isCustom() ? 0 : 8);
        final int i4 = 1;
        imageButton.setOnClickListener(new View.OnClickListener(gVar) { // from class: w06
            public final /* synthetic */ g b;

            {
                this.b = gVar;
            }

            @Override // android.view.View.OnClickListener
            public final void onClick(View view) {
                int i42 = i4;
                InstalledAddonEntity installedAddonEntity2 = installedAddonEntity;
                g gVar2 = this.b;
                switch (i42) {
                    case 0:
                        int i5 = g.a.j;
                        gVar2.d.invoke(installedAddonEntity2);
                        break;
                    case 1:
                        int i6 = g.a.j;
                        gVar2.e.invoke(installedAddonEntity2);
                        break;
                    default:
                        int i7 = g.a.j;
                        gVar2.c.invoke(installedAddonEntity2);
                        break;
                }
            }
        });
        final int i5 = 2;
        aVar.h.setOnClickListener(new View.OnClickListener(gVar) { // from class: w06
            public final /* synthetic */ g b;

            {
                this.b = gVar;
            }

            @Override // android.view.View.OnClickListener
            public final void onClick(View view) {
                int i42 = i5;
                InstalledAddonEntity installedAddonEntity2 = installedAddonEntity;
                g gVar2 = this.b;
                switch (i42) {
                    case 0:
                        int i52 = g.a.j;
                        gVar2.d.invoke(installedAddonEntity2);
                        break;
                    case 1:
                        int i6 = g.a.j;
                        gVar2.e.invoke(installedAddonEntity2);
                        break;
                    default:
                        int i7 = g.a.j;
                        gVar2.c.invoke(installedAddonEntity2);
                        break;
                }
            }
        });
    }

    @Override // androidx.recyclerview.widget.RecyclerView.g
    public final RecyclerView.ag onCreateViewHolder(ViewGroup viewGroup, int i) {
        View viewD = n41.d(viewGroup, "parent", R.layout.item_mobile_addon_card, viewGroup, false);
        cr4.d(viewD);
        return new a(viewD);
    }
}
