package se;

import android.app.Activity;
import android.content.res.Resources;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.constraintlayout.widget.ConstraintLayout;
import ie.f1;
import java.util.ArrayList;
import oe.h;
import org.drive_hunter.R;
import xyz.stream.api.entity.LiveChannelEntity;
import xyz.stream.view.CustomImageView;
import xyz.stream.view.OnItemListener;
import xyz.stream.view.PlayingView;
import xyz.stream.view.SingleTypeAdapter;
import xyz.stream.view.UiUtils;

/* JADX INFO: loaded from: classes3.dex */
public final class b extends SingleTypeAdapter {

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public int f32750b;

    public b(ArrayList arrayList, Activity activity) {
        super(arrayList, activity);
        this.f32750b = -1;
    }

    public static void e(b bVar, int i10, f1 f1Var, View view, boolean z10) {
        if (!z10) {
            bVar.getClass();
            f1Var.f26831c.setSelected(false);
            f1Var.f26829a.setBackgroundResource(R.drawable.shape_radius_black3_12);
            f1Var.f26831c.setTextColor(bVar.context.getResources().getColor(R.color.white));
            f1Var.f26832d.setBarColorRes(R.color.main_color);
            return;
        }
        OnItemListener onItemListener = bVar.onItemListener;
        if (onItemListener != null) {
            onItemListener.onItemFocus(view, i10);
        }
        f1Var.f26831c.setSelected(true);
        f1Var.f26829a.setBackgroundResource(R.drawable.shape_radius_red_select_12);
        f1Var.f26831c.setTextColor(bVar.context.getResources().getColor(R.color.main_text));
        f1Var.f26832d.setBarColorRes(R.color.main_text);
    }

    @Override // xyz.stream.view.SingleTypeAdapter
    public final v3.a createBinding(ViewGroup viewGroup) {
        return f1.inflate(LayoutInflater.from(this.context), viewGroup, false);
    }

    public final void f(int i10, int i11) {
        int iIndexOf;
        int iIndexOf2;
        int i12 = this.f32750b;
        this.f32750b = i10;
        if (i12 > -1) {
            Object obj = t4.f.x(this.dataList).e(new xyz.netfly.mobile.player.c(i12, 1)).g().f32947a;
            if (obj == null) {
                obj = null;
            }
            LiveChannelEntity liveChannelEntity = (LiveChannelEntity) obj;
            if (liveChannelEntity != null && (iIndexOf2 = this.dataList.indexOf(liveChannelEntity)) >= 0) {
                notifyItemChanged(iIndexOf2);
            }
        }
        if (i11 >= 0 && i11 < this.dataList.size()) {
            notifyItemChanged(i11);
            return;
        }
        Object obj2 = t4.f.x(this.dataList).e(new xyz.netfly.mobile.player.c(i10, 2)).g().f32947a;
        LiveChannelEntity liveChannelEntity2 = (LiveChannelEntity) (obj2 != null ? obj2 : null);
        if (liveChannelEntity2 == null || (iIndexOf = this.dataList.indexOf(liveChannelEntity2)) < 0) {
            return;
        }
        notifyItemChanged(iIndexOf);
    }

    @Override // xyz.stream.view.SingleTypeAdapter
    public final void onBindData(v3.a aVar, Object obj, int i10) {
        Resources resources;
        f1 f1Var = (f1) aVar;
        LiveChannelEntity liveChannelEntity = (LiveChannelEntity) obj;
        ConstraintLayout constraintLayout = f1Var.f26829a;
        constraintLayout.setBackgroundResource(constraintLayout.isFocused() ? R.drawable.shape_radius_red_select_12 : R.drawable.shape_radius_black3_12);
        int iIntValue = liveChannelEntity.getId().intValue();
        int i11 = this.f32750b;
        ConstraintLayout constraintLayout2 = f1Var.f26829a;
        PlayingView playingView = f1Var.f26832d;
        TextView textView = f1Var.f26831c;
        if (iIntValue == i11) {
            playingView.setVisibility(0);
            boolean zIsFocused = constraintLayout2.isFocused();
            int i12 = R.color.main_text;
            playingView.setBarColorRes(zIsFocused ? R.color.main_text : R.color.main_color);
            if (constraintLayout2.isFocused()) {
                resources = this.context.getResources();
            } else {
                resources = this.context.getResources();
                i12 = R.color.white;
            }
            textView.setTextColor(resources.getColor(i12));
        } else {
            playingView.setVisibility(8);
            textView.setTextColor(this.context.getResources().getColor(R.color.black_9));
        }
        constraintLayout2.setOnFocusChangeListener(new h(this, i10, f1Var, 3));
        textView.setText(liveChannelEntity.getName());
        String logo = liveChannelEntity.getLogo();
        CustomImageView customImageView = f1Var.f26830b;
        if (logo == null || liveChannelEntity.getLogo().isEmpty()) {
            customImageView.clearImage();
            textView.setVisibility(0);
        } else {
            textView.setVisibility(8);
            customImageView.load(CustomImageView.Request.raw(liveChannelEntity.getLogo()).radius(UiUtils.dp2px(12.0f)).size(UiUtils.dp2px(100.0f), UiUtils.dp2px(100.0f)).scaleType(ImageView.ScaleType.FIT_CENTER).listener(new a(f1Var)));
        }
    }
}
