package defpackage;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.media3.container.NalUnitUtil;
import androidx.media3.exoplayer.upstream.CmcdData;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.strmr.ps.R;
import com.strmr.ps.data.model.StreamInfo;
import java.util.List;
import kotlin.Metadata;

/* JADX INFO: loaded from: classes3.dex */
@Metadata(d1 = {"\u0000\f\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\u0018\u00002\u00020\u0001:\u0001\u0002¨\u0006\u0003"}, d2 = {"Lay8;", "Landroid/app/Dialog;", CmcdData.OBJECT_TYPE_AUDIO_ONLY, "app_sideloadRelease"}, k = 1, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
public final class ay8 extends Dialog {
    public static final /* synthetic */ int i = 0;
    public final List a;
    public final int b;
    public final zd c;
    public RecyclerView d;
    public TextView e;
    public boolean f;

    @Metadata(d1 = {"\u0000\u0010\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\b\u0002\u0018\u00002\f\u0012\b\u0012\u00060\u0002R\u00020\u00000\u0001:\u0001\u0003¨\u0006\u0004"}, d2 = {"Lay8$a;", "Landroidx/recyclerview/widget/RecyclerView$g;", "Lay8$a$a;", CmcdData.OBJECT_TYPE_AUDIO_ONLY, "app_sideloadRelease"}, k = 1, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
    public static final class a extends RecyclerView.g<C0069a> {
        public final List a;
        public final int b;
        public final zd c;

        /* JADX INFO: renamed from: ay8$a$a, reason: collision with other inner class name */
        @Metadata(d1 = {"\u0000\n\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\b\u0086\u0004\u0018\u00002\u00020\u0001¨\u0006\u0002"}, d2 = {"Lay8$a$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 C0069a extends RecyclerView.ag {
            public static final /* synthetic */ int h = 0;
            public final TextView a;
            public final TextView b;
            public final TextView c;
            public final TextView d;
            public final TextView e;
            public final ImageView f;

            public C0069a(View view) {
                super(view);
                View viewFindViewById = view.findViewById(R.id.source_badge);
                cr4.f(viewFindViewById, "findViewById(...)");
                this.a = (TextView) viewFindViewById;
                View viewFindViewById2 = view.findViewById(R.id.quality_badge);
                cr4.f(viewFindViewById2, "findViewById(...)");
                this.b = (TextView) viewFindViewById2;
                View viewFindViewById3 = view.findViewById(R.id.source_name);
                cr4.f(viewFindViewById3, "findViewById(...)");
                this.c = (TextView) viewFindViewById3;
                View viewFindViewById4 = view.findViewById(R.id.source_size);
                cr4.f(viewFindViewById4, "findViewById(...)");
                this.d = (TextView) viewFindViewById4;
                View viewFindViewById5 = view.findViewById(R.id.source_codec);
                cr4.f(viewFindViewById5, "findViewById(...)");
                this.e = (TextView) viewFindViewById5;
                View viewFindViewById6 = view.findViewById(R.id.current_indicator);
                cr4.f(viewFindViewById6, "findViewById(...)");
                this.f = (ImageView) viewFindViewById6;
                boolean zHasSystemFeature = view.getContext().getPackageManager().hasSystemFeature("android.software.leanback");
                view.setFocusable(true);
                view.setFocusableInTouchMode(zHasSystemFeature);
            }
        }

        public a(List list, int i, zd zdVar) {
            cr4.g(list, "sources");
            this.a = list;
            this.b = i;
            this.c = zdVar;
        }

        @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) {
            C0069a c0069a = (C0069a) agVar;
            cr4.g(c0069a, "holder");
            StreamInfo streamInfo = (StreamInfo) this.a.get(i);
            a aVar = a.this;
            TextView textView = c0069a.e;
            TextView textView2 = c0069a.a;
            cr4.g(streamInfo, "source");
            String debridBadge = streamInfo.getDebridBadge();
            if (debridBadge != null) {
                textView2.setText(debridBadge);
                textView2.setVisibility(0);
            } else {
                textView2.setVisibility(8);
            }
            c0069a.b.setText(streamInfo.getQuality().getLabel());
            c0069a.c.setText(streamInfo.getFileName());
            c0069a.d.setText(streamInfo.getSizeFormatted());
            StringBuilder sb = new StringBuilder();
            String codec = streamInfo.getCodec();
            if (codec != null) {
                sb.append(codec);
            }
            String audio = streamInfo.getAudio();
            if (audio != null) {
                if (sb.length() > 0) {
                    sb.append(" / ");
                }
                sb.append(audio);
            }
            String string = sb.toString();
            if (n89.ab(string)) {
                textView.setVisibility(8);
            } else {
                textView.setText(string);
                textView.setVisibility(0);
            }
            boolean z = i == aVar.b;
            c0069a.itemView.setActivated(z);
            c0069a.f.setVisibility(z ? 0 : 8);
            c0069a.itemView.setOnClickListener(new d50(i, aVar, streamInfo, 1));
            c0069a.itemView.setOnFocusChangeListener(new fb(c0069a, 15));
        }

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

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public ay8(Context context, List list, int i2, zd zdVar) {
        super(context, R.style.PlayerPanelDialogTheme);
        cr4.g(list, "sources");
        this.a = list;
        this.b = i2;
        this.c = zdVar;
    }

    @Override // android.app.Dialog, android.view.Window.Callback
    public final boolean dispatchKeyEvent(KeyEvent keyEvent) {
        cr4.g(keyEvent, "event");
        int keyCode = keyEvent.getKeyCode();
        if (keyCode == 23 || keyCode == 66) {
            if (keyEvent.getAction() == 1 && !this.f) {
                this.f = true;
                return true;
            }
            if (keyEvent.getAction() == 0 && !this.f) {
                return true;
            }
        }
        return super.dispatchKeyEvent(keyEvent);
    }

    @Override // android.app.Dialog
    public final void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        requestWindowFeature(1);
        setContentView(R.layout.dialog_source_selection);
        Window window = getWindow();
        if (window != null) {
            window.setLayout(-1, -1);
            window.setGravity(8388613);
        }
        this.d = (RecyclerView) findViewById(R.id.source_list);
        this.e = (TextView) findViewById(R.id.empty_text);
        List list = this.a;
        if (list.size() <= 1) {
            TextView textView = this.e;
            if (textView == null) {
                cr4.n("emptyText");
                throw null;
            }
            textView.setVisibility(0);
            RecyclerView recyclerView = this.d;
            if (recyclerView == null) {
                cr4.n("recyclerView");
                throw null;
            }
            recyclerView.setVisibility(8);
        } else {
            TextView textView2 = this.e;
            if (textView2 == null) {
                cr4.n("emptyText");
                throw null;
            }
            textView2.setVisibility(8);
            RecyclerView recyclerView2 = this.d;
            if (recyclerView2 == null) {
                cr4.n("recyclerView");
                throw null;
            }
            recyclerView2.setVisibility(0);
        }
        zd zdVar = new zd(this, 15);
        int i2 = this.b;
        a aVar = new a(list, i2, zdVar);
        RecyclerView recyclerView3 = this.d;
        if (recyclerView3 == null) {
            cr4.n("recyclerView");
            throw null;
        }
        getContext();
        recyclerView3.setLayoutManager(new LinearLayoutManager());
        RecyclerView recyclerView4 = this.d;
        if (recyclerView4 == null) {
            cr4.n("recyclerView");
            throw null;
        }
        recyclerView4.addItemDecoration(new by8());
        RecyclerView recyclerView5 = this.d;
        if (recyclerView5 == null) {
            cr4.n("recyclerView");
            throw null;
        }
        recyclerView5.setAdapter(aVar);
        if (i2 >= 0 && i2 < list.size()) {
            RecyclerView recyclerView6 = this.d;
            if (recyclerView6 == null) {
                cr4.n("recyclerView");
                throw null;
            }
            final int i3 = 0;
            recyclerView6.post(new Runnable(this) { // from class: zx8
                public final /* synthetic */ ay8 b;

                {
                    this.b = this;
                }

                @Override // java.lang.Runnable
                public final void run() {
                    View view;
                    View view2;
                    switch (i3) {
                        case 0:
                            ay8 ay8Var = this.b;
                            RecyclerView recyclerView7 = ay8Var.d;
                            int i4 = ay8Var.b;
                            if (recyclerView7 == null) {
                                cr4.n("recyclerView");
                                throw null;
                            }
                            recyclerView7.scrollToPosition(i4);
                            RecyclerView recyclerView8 = ay8Var.d;
                            if (recyclerView8 == null) {
                                cr4.n("recyclerView");
                                throw null;
                            }
                            RecyclerView.ag agVarFindViewHolderForAdapterPosition = recyclerView8.findViewHolderForAdapterPosition(i4);
                            if (agVarFindViewHolderForAdapterPosition == null || (view = agVarFindViewHolderForAdapterPosition.itemView) == null) {
                                return;
                            }
                            view.requestFocus();
                            return;
                        default:
                            RecyclerView recyclerView9 = this.b.d;
                            if (recyclerView9 == null) {
                                cr4.n("recyclerView");
                                throw null;
                            }
                            RecyclerView.ag agVarFindViewHolderForAdapterPosition2 = recyclerView9.findViewHolderForAdapterPosition(0);
                            if (agVarFindViewHolderForAdapterPosition2 == null || (view2 = agVarFindViewHolderForAdapterPosition2.itemView) == null) {
                                return;
                            }
                            view2.requestFocus();
                            return;
                    }
                }
            });
            return;
        }
        if (list.isEmpty()) {
            return;
        }
        RecyclerView recyclerView7 = this.d;
        if (recyclerView7 == null) {
            cr4.n("recyclerView");
            throw null;
        }
        final int i4 = 1;
        recyclerView7.post(new Runnable(this) { // from class: zx8
            public final /* synthetic */ ay8 b;

            {
                this.b = this;
            }

            @Override // java.lang.Runnable
            public final void run() {
                View view;
                View view2;
                switch (i4) {
                    case 0:
                        ay8 ay8Var = this.b;
                        RecyclerView recyclerView72 = ay8Var.d;
                        int i42 = ay8Var.b;
                        if (recyclerView72 == null) {
                            cr4.n("recyclerView");
                            throw null;
                        }
                        recyclerView72.scrollToPosition(i42);
                        RecyclerView recyclerView8 = ay8Var.d;
                        if (recyclerView8 == null) {
                            cr4.n("recyclerView");
                            throw null;
                        }
                        RecyclerView.ag agVarFindViewHolderForAdapterPosition = recyclerView8.findViewHolderForAdapterPosition(i42);
                        if (agVarFindViewHolderForAdapterPosition == null || (view = agVarFindViewHolderForAdapterPosition.itemView) == null) {
                            return;
                        }
                        view.requestFocus();
                        return;
                    default:
                        RecyclerView recyclerView9 = this.b.d;
                        if (recyclerView9 == null) {
                            cr4.n("recyclerView");
                            throw null;
                        }
                        RecyclerView.ag agVarFindViewHolderForAdapterPosition2 = recyclerView9.findViewHolderForAdapterPosition(0);
                        if (agVarFindViewHolderForAdapterPosition2 == null || (view2 = agVarFindViewHolderForAdapterPosition2.itemView) == null) {
                            return;
                        }
                        view2.requestFocus();
                        return;
                }
            }
        });
    }

    @Override // android.app.Dialog
    public final void show() {
        super.show();
        this.f = false;
    }
}
