package defpackage;

import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.cardview.widget.CardView;
import androidx.media3.container.NalUnitUtil;
import androidx.media3.exoplayer.upstream.CmcdData;
import androidx.recyclerview.widget.RecyclerView;
import com.strmr.ps.R;
import com.strmr.ps.data.local.entity.PlaybackProgress;
import com.strmr.ps.data.model.tmdb.TMDBEpisode;
import defpackage.co2;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
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 = {"Lco2;", "Landroidx/recyclerview/widget/RecyclerView$g;", "Lco2$a;", CmcdData.OBJECT_TYPE_AUDIO_ONLY, "app_sideloadRelease"}, k = 1, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
@vx8
public final class co2 extends RecyclerView.g<a> {
    public final List a;
    public final Map b;
    public final boolean c;
    public final sq3 d;
    public final sq3 e;
    public final gr3 f;
    public final LinkedHashSet g;
    public final LinkedHashMap h;
    public final j65 i;

    @Metadata(d1 = {"\u0000\n\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\b\u0086\u0004\u0018\u00002\u00020\u0001¨\u0006\u0002"}, d2 = {"Lco2$a;", "Landroidx/recyclerview/widget/RecyclerView$ag;", "app_sideloadRelease"}, k = 1, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
    @vx8
    public final class a extends RecyclerView.ag {
        public static final /* synthetic */ int h = 0;
        public final CardView a;
        public final ImageView b;
        public final TextView c;
        public final ImageView d;
        public final View e;
        public final TextView f;

        public a(View view) {
            super(view);
            View viewFindViewById = view.findViewById(R.id.episode_card);
            cr4.f(viewFindViewById, "findViewById(...)");
            this.a = (CardView) viewFindViewById;
            View viewFindViewById2 = view.findViewById(R.id.episode_image);
            cr4.f(viewFindViewById2, "findViewById(...)");
            this.b = (ImageView) viewFindViewById2;
            View viewFindViewById3 = view.findViewById(R.id.episode_title);
            cr4.f(viewFindViewById3, "findViewById(...)");
            this.c = (TextView) viewFindViewById3;
            View viewFindViewById4 = view.findViewById(R.id.episode_watched_badge);
            cr4.f(viewFindViewById4, "findViewById(...)");
            this.d = (ImageView) viewFindViewById4;
            View viewFindViewById5 = view.findViewById(R.id.episode_progress_bar);
            cr4.f(viewFindViewById5, "findViewById(...)");
            this.e = viewFindViewById5;
            this.f = (TextView) view.findViewById(R.id.episode_indicator_badge);
        }
    }

    public co2(List list, Set set, Map map, boolean z, sq3 sq3Var, sq3 sq3Var2, q62 q62Var) {
        cr4.g(set, "watchedEpisodes");
        cr4.g(map, "episodeProgress");
        this.a = list;
        this.b = map;
        this.c = z;
        this.d = sq3Var;
        this.e = sq3Var2;
        this.f = q62Var;
        this.g = y41.bq(set);
        this.h = wo5.o(map);
        this.i = v65.a(new ah(this, 12));
    }

    public final int d(int i) {
        Iterator it = this.a.iterator();
        int i2 = 0;
        while (it.hasNext()) {
            Integer episodeNumber = ((TMDBEpisode) it.next()).getEpisodeNumber();
            if (episodeNumber != null && episodeNumber.intValue() == i) {
                return i2;
            }
            i2++;
        }
        return -1;
    }

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

    @Override // androidx.recyclerview.widget.RecyclerView.g
    public final void onBindViewHolder(RecyclerView.ag agVar, int i) {
        String string;
        a aVar = (a) agVar;
        cr4.g(aVar, "holder");
        final TMDBEpisode tMDBEpisode = (TMDBEpisode) this.a.get(i);
        ImageView imageView = aVar.b;
        CardView cardView = aVar.a;
        ImageView imageView2 = aVar.d;
        View view = aVar.e;
        final co2 co2Var = co2.this;
        cr4.g(tMDBEpisode, PlaybackProgress.TYPE_EPISODE);
        Integer seasonNumber = tMDBEpisode.getSeasonNumber();
        Integer episodeNumber = tMDBEpisode.getEpisodeNumber();
        if (seasonNumber == null && episodeNumber == null) {
            string = "";
        } else {
            StringBuilder sb = new StringBuilder();
            if (seasonNumber != null) {
                sb.append("S" + seasonNumber.intValue());
            }
            if (episodeNumber != null) {
                if (sb.length() > 0) {
                    sb.append(" ");
                }
                sb.append("E" + episodeNumber);
            }
            string = sb.toString();
        }
        aVar.c.setText(n89.ab(string) ? "" : string);
        String str = "S" + tMDBEpisode.getSeasonNumber() + "E" + tMDBEpisode.getEpisodeNumber();
        final boolean zContains = co2Var.g.contains(str);
        Float f = (Float) co2Var.h.get(str);
        boolean z = co2Var.c && (!zContains && (f == null || (f.floatValue() > 0.05f ? 1 : (f.floatValue() == 0.05f ? 0 : -1)) < 0));
        f80 f80VarF = ((l08) com.bumptech.glide.a.f(aVar.itemView.getContext()).n(tMDBEpisode.getStillUrl()).an(tf2.b()).l(R.drawable.default_background)).f(R.drawable.default_background);
        cr4.f(f80VarF, "error(...)");
        l08 l08Var = (l08) f80VarF;
        if (z) {
            ((l08) l08Var.x(new nd0(2), true)).ah(imageView);
        } else {
            l08Var.ah(imageView);
        }
        view.setVisibility(8);
        if (f != null && f.floatValue() >= 0.05f && f.floatValue() < 0.9f) {
            view.setVisibility(0);
            view.post(new yg(aVar, f, 22));
            imageView2.setVisibility(8);
            cardView.setAlpha(1.0f);
        } else if (zContains || (f != null && f.floatValue() >= 0.9f)) {
            imageView2.setVisibility(0);
            cardView.setAlpha(0.85f);
        } else {
            imageView2.setVisibility(8);
            cardView.setAlpha(1.0f);
        }
        TextView textView = aVar.f;
        if (textView != null) {
            Integer episodeNumber2 = tMDBEpisode.getEpisodeNumber();
            q07 q07Var = (q07) co2Var.i.getValue();
            String str2 = (episodeNumber2 != null && episodeNumber2.intValue() == 1) ? "PREMIERE" : cr4.b(tMDBEpisode.getEpisodeType(), "finale") ? "FINALE" : (episodeNumber2 == null || !((Set) q07Var.a).contains(episodeNumber2)) ? (episodeNumber2 == null || !((Set) q07Var.b).contains(episodeNumber2)) ? null : "MID-SEASON FINALE" : "MID-SEASON PREMIERE";
            if (str2 != null) {
                textView.setText(str2);
                int i2 = (str2.equals("MID-SEASON PREMIERE") || str2.equals("MID-SEASON FINALE")) ? -680437 : -8635667;
                Drawable background = textView.getBackground();
                if (background != null) {
                    background.setTint(i2);
                }
                textView.setVisibility(0);
            } else {
                textView.setVisibility(8);
            }
        }
        aVar.itemView.setOnFocusChangeListener(new ao2(aVar, co2Var, tMDBEpisode, 0));
        aVar.itemView.setOnClickListener(new rb5(co2Var, tMDBEpisode, 8));
        aVar.itemView.setOnLongClickListener(new View.OnLongClickListener() { // from class: bo2
            @Override // android.view.View.OnLongClickListener
            public final boolean onLongClick(View view2) {
                int i3 = co2.a.h;
                gr3 gr3Var = this.a.f;
                if (gr3Var == null) {
                    return true;
                }
                gr3Var.invoke(tMDBEpisode, Boolean.valueOf(zContains));
                return true;
            }
        });
    }

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