package defpackage;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.media3.container.NalUnitUtil;
import androidx.media3.exoplayer.upstream.CmcdData;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.af;
import androidx.recyclerview.widget.t;
import com.strmr.ps.R;
import com.strmr.ps.data.model.SourceType;
import com.strmr.ps.data.model.StreamInfo;
import defpackage.yx8;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import kotlin.Metadata;

/* JADX INFO: loaded from: classes3.dex */
@Metadata(d1 = {"\u0000\u0014\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0005\u0018\u00002\u000e\u0012\u0004\u0012\u00020\u0002\u0012\u0004\u0012\u00020\u00030\u0001:\u0004\u0004\u0005\u0006\u0007¨\u0006\b"}, d2 = {"Ljy8;", "Landroidx/recyclerview/widget/af;", "Lyx8;", "Landroidx/recyclerview/widget/RecyclerView$ag;", CmcdData.OBJECT_TYPE_AUDIO_ONLY, "d", "b", "c", "app_sideloadRelease"}, k = 1, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
public final class jy8 extends af<yx8, RecyclerView.ag> {
    public final cy8 c;
    public final cy8 d;

    @Metadata(d1 = {"\u0000\u0010\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\u0010\b\n\u0002\b\u0004\b\u0086\u0003\u0018\u00002\u00020\u0001R\u0014\u0010\u0003\u001a\u00020\u00028\u0006X\u0086T¢\u0006\u0006\n\u0004\b\u0003\u0010\u0004R\u0014\u0010\u0005\u001a\u00020\u00028\u0006X\u0086T¢\u0006\u0006\n\u0004\b\u0005\u0010\u0004¨\u0006\u0006"}, d2 = {"Ljy8$a;", "", "", "VIEW_TYPE_STREAM", "I", "VIEW_TYPE_SEPARATOR", "app_sideloadRelease"}, k = 1, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
    public static final class a {
    }

    @Metadata(d1 = {"\u0000\n\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\u0018\u00002\u00020\u0001¨\u0006\u0002"}, d2 = {"Ljy8$b;", "Landroidx/recyclerview/widget/RecyclerView$ag;", "app_sideloadRelease"}, k = 1, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
    public static final class b extends RecyclerView.ag {
        public final TextView a;

        public b(View view) {
            super(view);
            View viewFindViewById = view.findViewById(R.id.separator_text);
            cr4.f(viewFindViewById, "findViewById(...)");
            this.a = (TextView) viewFindViewById;
        }
    }

    @Metadata(d1 = {"\u0000\u000e\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\u0018\u00002\b\u0012\u0004\u0012\u00020\u00020\u0001¨\u0006\u0003"}, d2 = {"Ljy8$c;", "Landroidx/recyclerview/widget/t$f;", "Lyx8;", "app_sideloadRelease"}, k = 1, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
    public static final class c extends t.f<yx8> {
        @Override // androidx.recyclerview.widget.t.f
        public final boolean a(Object obj, Object obj2) {
            return ((yx8) obj).equals((yx8) obj2);
        }

        @Override // androidx.recyclerview.widget.t.f
        public final boolean b(Object obj, Object obj2) {
            yx8 yx8Var = (yx8) obj;
            yx8 yx8Var2 = (yx8) obj2;
            if ((yx8Var instanceof yx8.c) && (yx8Var2 instanceof yx8.c)) {
                StreamInfo streamInfo = ((yx8.c) yx8Var).a;
                String infoHash = streamInfo.getInfoHash();
                StreamInfo streamInfo2 = ((yx8.c) yx8Var2).a;
                return cr4.b(infoHash, streamInfo2.getInfoHash()) && cr4.b(streamInfo.getDirectUrl(), streamInfo2.getDirectUrl());
            }
            if ((yx8Var instanceof yx8.a) && (yx8Var2 instanceof yx8.a)) {
                return cr4.b(((yx8.a) yx8Var).b.getId(), ((yx8.a) yx8Var2).b.getId());
            }
            if ((yx8Var instanceof yx8.b) && (yx8Var2 instanceof yx8.b)) {
                return cr4.b(((yx8.b) yx8Var).a, ((yx8.b) yx8Var2).a);
            }
            return false;
        }
    }

    @Metadata(d1 = {"\u0000\n\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\u0018\u00002\u00020\u0001¨\u0006\u0002"}, d2 = {"Ljy8$d;", "Landroidx/recyclerview/widget/RecyclerView$ag;", "app_sideloadRelease"}, k = 1, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
    @vx8
    public static final class d extends RecyclerView.ag {
        public final sq3 a;
        public final sq3 b;
        public final LinearLayout c;
        public final TextView d;
        public final TextView e;
        public final TextView f;
        public final TextView g;
        public final TextView h;
        public final TextView i;
        public final TextView j;
        public final TextView k;
        public final TextView l;
        public final TextView m;
        public final LinearLayout n;
        public final TextView o;
        public final TextView p;
        public final TextView q;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public d(View view, cy8 cy8Var, cy8 cy8Var2) {
            super(view);
            cr4.g(cy8Var, "onSourceClick");
            cr4.g(cy8Var2, "onSourceLongClick");
            this.a = cy8Var;
            this.b = cy8Var2;
            View viewFindViewById = view.findViewById(R.id.source_item_container);
            cr4.f(viewFindViewById, "findViewById(...)");
            this.c = (LinearLayout) viewFindViewById;
            View viewFindViewById2 = view.findViewById(R.id.quality_badge);
            cr4.f(viewFindViewById2, "findViewById(...)");
            this.d = (TextView) viewFindViewById2;
            View viewFindViewById3 = view.findViewById(R.id.filename_text);
            cr4.f(viewFindViewById3, "findViewById(...)");
            this.e = (TextView) viewFindViewById3;
            View viewFindViewById4 = view.findViewById(R.id.library_badge);
            cr4.f(viewFindViewById4, "findViewById(...)");
            this.f = (TextView) viewFindViewById4;
            View viewFindViewById5 = view.findViewById(R.id.source_type_badge);
            cr4.f(viewFindViewById5, "findViewById(...)");
            this.g = (TextView) viewFindViewById5;
            View viewFindViewById6 = view.findViewById(R.id.season_pack_badge);
            cr4.f(viewFindViewById6, "findViewById(...)");
            this.h = (TextView) viewFindViewById6;
            View viewFindViewById7 = view.findViewById(R.id.scraper_text);
            cr4.f(viewFindViewById7, "findViewById(...)");
            this.i = (TextView) viewFindViewById7;
            View viewFindViewById8 = view.findViewById(R.id.codec_badge);
            cr4.f(viewFindViewById8, "findViewById(...)");
            this.j = (TextView) viewFindViewById8;
            View viewFindViewById9 = view.findViewById(R.id.hdr_badge);
            cr4.f(viewFindViewById9, "findViewById(...)");
            this.k = (TextView) viewFindViewById9;
            View viewFindViewById10 = view.findViewById(R.id.audio_badge);
            cr4.f(viewFindViewById10, "findViewById(...)");
            this.l = (TextView) viewFindViewById10;
            View viewFindViewById11 = view.findViewById(R.id.edition_badge);
            cr4.f(viewFindViewById11, "findViewById(...)");
            this.m = (TextView) viewFindViewById11;
            View viewFindViewById12 = view.findViewById(R.id.debrid_badges_container);
            cr4.f(viewFindViewById12, "findViewById(...)");
            this.n = (LinearLayout) viewFindViewById12;
            View viewFindViewById13 = view.findViewById(R.id.size_text);
            cr4.f(viewFindViewById13, "findViewById(...)");
            this.o = (TextView) viewFindViewById13;
            View viewFindViewById14 = view.findViewById(R.id.bitrate_text);
            cr4.f(viewFindViewById14, "findViewById(...)");
            this.p = (TextView) viewFindViewById14;
            View viewFindViewById15 = view.findViewById(R.id.seeds_text);
            cr4.f(viewFindViewById15, "findViewById(...)");
            this.q = (TextView) viewFindViewById15;
        }

        public static void b(TextView textView, int i, int i2) {
            Drawable background = textView.getBackground();
            Drawable drawableMutate = background != null ? background.mutate() : null;
            GradientDrawable gradientDrawable = drawableMutate instanceof GradientDrawable ? (GradientDrawable) drawableMutate : null;
            if (gradientDrawable != null) {
                gradientDrawable.setColor(i);
            }
            textView.setTextColor(i2);
        }

        public static int d(Context context, int i) {
            return (int) TypedValue.applyDimension(1, i, context.getResources().getDisplayMetrics());
        }

        public final void c(yx8 yx8Var) {
            StreamInfo streamInfo;
            boolean z = yx8Var instanceof yx8.c;
            if (z) {
                streamInfo = ((yx8.c) yx8Var).a;
            } else if (!(yx8Var instanceof yx8.a)) {
                return;
            } else {
                streamInfo = ((yx8.a) yx8Var).a;
            }
            yx8.c cVar = z ? (yx8.c) yx8Var : null;
            boolean zIsFilteredOut = cVar != null ? cVar.a.isFilteredOut() : false;
            this.itemView.setOnClickListener(new bn8(this, yx8Var, 9));
            this.itemView.setOnLongClickListener(new dv1(this, yx8Var, 7));
            this.itemView.setOnFocusChangeListener(new fb(this, 16));
            String qualityBadge = streamInfo.getQualityBadge();
            TextView textView = this.d;
            textView.setText(qualityBadge);
            int iA = i60.a(streamInfo.getQuality());
            cr4.g(streamInfo.getQuality(), "quality");
            b(textView, iA, -1);
            boolean z2 = yx8Var instanceof yx8.a;
            TextView textView2 = this.f;
            if (z2) {
                textView2.setVisibility(0);
                b(textView2, 1711327315, -1);
            } else {
                textView2.setVisibility(8);
            }
            SourceType sourceType = streamInfo.getSourceType();
            SourceType sourceType2 = SourceType.UNKNOWN;
            TextView textView3 = this.g;
            if (sourceType != sourceType2) {
                textView3.setText(sourceType.getLabel());
                textView3.setVisibility(0);
                b(textView3, i60.b(sourceType), -1);
            } else {
                textView3.setVisibility(8);
            }
            boolean zIsSeasonPack = streamInfo.isSeasonPack();
            TextView textView4 = this.h;
            if (zIsSeasonPack) {
                textView4.setVisibility(0);
                b(textView4, 2013236224, -1);
            } else {
                textView4.setVisibility(8);
            }
            this.o.setText(z ? ((yx8.c) yx8Var).a() : z2 ? ((yx8.a) yx8Var).a.getSizeFormatted() : "");
            Double estimatedBitrateMbps = streamInfo.getEstimatedBitrateMbps();
            TextView textView5 = this.p;
            if (estimatedBitrateMbps == null || estimatedBitrateMbps.doubleValue() <= 0.0d) {
                textView5.setVisibility(8);
            } else {
                textView5.setText(String.format(Locale.US, "%.1f Mbps", Arrays.copyOf(new Object[]{estimatedBitrateMbps}, 1)));
                textView5.setVisibility(0);
            }
            String codec = streamInfo.getCodec();
            TextView textView6 = this.j;
            if (codec != null) {
                textView6.setText(codec);
                textView6.setVisibility(0);
                b(textView6, 1434484864, -1);
            } else {
                textView6.setVisibility(8);
            }
            List<String> hdrBadges = streamInfo.getHdrBadges();
            boolean zIsEmpty = hdrBadges.isEmpty();
            TextView textView7 = this.k;
            if (zIsEmpty) {
                textView7.setVisibility(8);
            } else {
                textView7.setText(y41.ai(hdrBadges, " | ", null, null, null, 62));
                textView7.setVisibility(0);
                String str = hdrBadges.contains("DV") ? "DV" : (String) y41.z(hdrBadges);
                if (!cr4.b(str, "DV")) {
                    cr4.b(str, "HDR10+");
                }
                b(textView7, 2004910208, cr4.b(str, "DV") ? -10496 : -1);
            }
            String audio = streamInfo.getAudio();
            TextView textView8 = this.l;
            if (audio != null) {
                textView8.setText(audio);
                textView8.setVisibility(0);
                b(textView8, 2004910208, -1);
            } else {
                textView8.setVisibility(8);
            }
            String edition = streamInfo.getEdition();
            TextView textView9 = this.m;
            if (edition != null) {
                textView9.setText(edition);
                textView9.setVisibility(0);
                b(textView9, 2008254719, -1);
            } else {
                textView9.setVisibility(8);
            }
            Integer seeds = streamInfo.getSeeds();
            TextView textView10 = this.q;
            if (seeds == null || seeds.intValue() <= 0) {
                textView10.setVisibility(8);
            } else {
                textView10.setText("👤 " + seeds);
                textView10.setVisibility(0);
            }
            String scraperName = streamInfo.getScraperName();
            String releaseGroup = streamInfo.getReleaseGroup();
            TextView textView11 = this.i;
            if (releaseGroup != null) {
                textView11.setText(releaseGroup);
                textView11.setVisibility(0);
                textView11.setTextColor(-5592406);
            } else if (n89.ab(scraperName) || scraperName.equals("Debrid Library")) {
                textView11.setVisibility(8);
            } else {
                textView11.setText(scraperName);
                textView11.setVisibility(0);
                textView11.setTextColor(-5592406);
            }
            List<String> debridBadges = streamInfo.getDebridBadges();
            LinearLayout linearLayout = this.n;
            linearLayout.removeAllViews();
            if (!debridBadges.isEmpty()) {
                Context context = this.itemView.getContext();
                for (String str2 : debridBadges) {
                    cr4.d(context);
                    TextView textView12 = new TextView(context);
                    textView12.setText(str2);
                    textView12.setTextSize(10.0f);
                    textView12.setTextColor(-1);
                    textView12.setGravity(17);
                    textView12.setPadding(d(context, 8), d(context, 2), d(context, 8), d(context, 2));
                    textView12.setTypeface(textView12.getTypeface(), 1);
                    Drawable drawable = context.getDrawable(R.drawable.bg_badge_capsule);
                    textView12.setBackground(drawable != null ? drawable.mutate() : null);
                    Drawable background = textView12.getBackground();
                    GradientDrawable gradientDrawable = background instanceof GradientDrawable ? (GradientDrawable) background : null;
                    if (gradientDrawable != null) {
                        gradientDrawable.setColor(1721585919);
                    }
                    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(-2, -2);
                    layoutParams.setMarginEnd(d(context, 5));
                    textView12.setLayoutParams(layoutParams);
                    linearLayout.addView(textView12);
                }
            }
            String fileName = streamInfo.getFileName();
            TextView textView13 = this.e;
            textView13.setText(fileName);
            LinearLayout linearLayout2 = this.c;
            if (zIsFilteredOut) {
                linearLayout2.setBackgroundResource(R.drawable.selector_source_glass_filtered);
                linearLayout2.setAlpha(0.6f);
                textView13.setAlpha(0.5f);
            } else {
                linearLayout2.setBackgroundResource(R.drawable.selector_source_glass);
                linearLayout2.setAlpha(1.0f);
                textView13.setAlpha(0.7f);
            }
        }
    }

    public jy8(cy8 cy8Var, cy8 cy8Var2) {
        super(new c());
        this.c = cy8Var;
        this.d = cy8Var2;
    }

    @Override // androidx.recyclerview.widget.RecyclerView.g
    public final int getItemViewType(int i) {
        yx8 yx8Var = (yx8) d(i);
        if ((yx8Var instanceof yx8.c) || (yx8Var instanceof yx8.a)) {
            return 0;
        }
        if (yx8Var instanceof yx8.b) {
            return 1;
        }
        throw new io6();
    }

    @Override // androidx.recyclerview.widget.RecyclerView.g
    public final void onBindViewHolder(RecyclerView.ag agVar, int i) {
        cr4.g(agVar, "holder");
        yx8 yx8Var = (yx8) d(i);
        if (yx8Var instanceof yx8.c) {
            ((d) agVar).c(yx8Var);
        } else if (yx8Var instanceof yx8.a) {
            ((d) agVar).c(yx8Var);
        } else {
            if (!(yx8Var instanceof yx8.b)) {
                throw new io6();
            }
            ((b) agVar).a.setText(((yx8.b) yx8Var).a);
        }
    }

    @Override // androidx.recyclerview.widget.RecyclerView.g
    public final RecyclerView.ag onCreateViewHolder(ViewGroup viewGroup, int i) {
        cr4.g(viewGroup, "parent");
        LayoutInflater layoutInflaterFrom = LayoutInflater.from(viewGroup.getContext());
        if (i == 0) {
            View viewInflate = layoutInflaterFrom.inflate(R.layout.item_source, viewGroup, false);
            cr4.d(viewInflate);
            return new d(viewInflate, this.c, this.d);
        }
        if (i != 1) {
            throw new IllegalArgumentException(n41.k("Unknown view type: ", i));
        }
        View viewInflate2 = layoutInflaterFrom.inflate(R.layout.item_source_separator, viewGroup, false);
        cr4.d(viewInflate2);
        return new b(viewInflate2);
    }
}
