package androidx.leanback.widget;

import android.content.Context;
import android.util.SparseArray;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.leanback.widget.bt;
import androidx.leanback.widget.bw;
import androidx.leanback.widget.ca;
import androidx.leanback.widget.cb;
import androidx.leanback.widget.cc;
import androidx.leanback.widget.ci;
import androidx.leanback.widget.cp;
import androidx.leanback.widget.p;
import com.strmr.ps.R;
import defpackage.ca7;
import defpackage.ch7;
import defpackage.vw2;

/* JADX INFO: loaded from: classes.dex */
public class cd extends ca {
    public final float e = 0.01f;
    public ci f;
    public final p g;
    public final p h;

    public class a implements p.c {
        @Override // androidx.leanback.widget.p.c
        public final void a(ci.a aVar, Object obj, p.a aVar2) {
            d dVar = ((c) aVar2).d;
            if (dVar.ae == aVar && dVar.af == obj) {
                return;
            }
            dVar.ae = aVar;
            dVar.af = obj;
            dVar.c();
        }
    }

    public class b implements p.b {
        @Override // androidx.leanback.widget.p.b
        public final void a(ci.a aVar, Object obj, p.a aVar2) {
            d dVar = ((c) aVar2).d;
            n nVar = dVar.n;
            if (nVar != null) {
                nVar.a(aVar, obj, dVar, dVar.d);
            }
        }
    }

    public static class c extends bt.a {
        public d d;
    }

    public class d extends ca.a implements cc {
        public p.d aa;
        public p.d ab;
        public final c ac;
        public final c ad;
        public ci.a ae;
        public Object af;
        public bw.h ag;
        public cc.a ah;
        public boolean ai;
        public final bw.f aj;
        public final ci.a o;
        public final ImageView p;
        public final ViewGroup q;
        public final ViewGroup r;
        public final ViewGroup s;
        public final TextView t;
        public final TextView u;
        public final SeekBar v;
        public final ThumbsBar w;
        public long x;
        public long y;
        public final StringBuilder z;

        public class a extends bw.f {
            public a() {
            }

            @Override // androidx.leanback.widget.bw.f
            public final void a(long j) {
                d.this.v.setSecondaryProgress((int) ((j / r0.x) * 2.147483647E9d));
            }

            @Override // androidx.leanback.widget.bw.f
            public final void b(long j) {
                d.this.e(j);
            }

            @Override // androidx.leanback.widget.bw.f
            public final void c(long j) {
                d dVar = d.this;
                if (dVar.x != j) {
                    dVar.x = j;
                    StringBuilder sb = dVar.z;
                    TextView textView = dVar.t;
                    if (textView != null) {
                        cd.ab(j, sb);
                        textView.setText(sb.toString());
                    }
                }
            }
        }

        public class b extends cb.a {
        }

        public d(View view, ci ciVar) {
            super(view);
            this.x = Long.MIN_VALUE;
            this.y = Long.MIN_VALUE;
            this.z = new StringBuilder();
            this.ac = new c();
            this.ad = new c();
            this.aj = new a();
            this.p = (ImageView) view.findViewById(R.id.image);
            ViewGroup viewGroup = (ViewGroup) view.findViewById(R.id.description_dock);
            this.q = viewGroup;
            this.u = (TextView) view.findViewById(R.id.current_time);
            this.t = (TextView) view.findViewById(R.id.total_time);
            SeekBar seekBar = (SeekBar) view.findViewById(R.id.playback_progress);
            this.v = seekBar;
            seekBar.setOnClickListener(new cf(this));
            seekBar.setOnKeyListener(new cg(this));
            seekBar.setAccessibilitySeekListener(new ch(this));
            seekBar.setMax(Integer.MAX_VALUE);
            this.r = (ViewGroup) view.findViewById(R.id.controls_dock);
            this.s = (ViewGroup) view.findViewById(R.id.secondary_controls_dock);
            ci.a aVarD = ciVar == null ? null : ciVar.d(viewGroup);
            this.o = aVarD;
            if (aVarD != null) {
                viewGroup.addView(aVarD.a);
            }
            this.w = (ThumbsBar) view.findViewById(R.id.thumbs_row);
        }

        @Override // androidx.leanback.widget.cc
        public final void b(cc.a aVar) {
            this.ah = aVar;
        }

        public final void c() {
            if (this.g) {
                ci.a aVar = this.ae;
                if (aVar == null) {
                    o oVar = this.m;
                    if (oVar != null) {
                        oVar.b(null, null, this, this.d);
                        return;
                    }
                    return;
                }
                o oVar2 = this.m;
                if (oVar2 != null) {
                    oVar2.b(aVar, this.af, this, this.d);
                }
            }
        }

        public final ci d(boolean z) {
            bs bsVar = z ? ((bw) this.d).d : ((bw) this.d).e;
            if (bsVar == null) {
                return null;
            }
            ch7 ch7Var = bsVar.b;
            if (ch7Var instanceof t) {
                return ((t) ch7Var).b;
            }
            Object objA = bsVar.g() > 0 ? bsVar.a(0) : null;
            ch7 ch7Var2 = bsVar.b;
            if (ch7Var2 != null) {
                return ch7Var2.a(objA);
            }
            throw new IllegalStateException("Presenter selector must not be null");
        }

        public final void e(long j) {
            if (j != this.y) {
                this.y = j;
                TextView textView = this.u;
                if (textView != null) {
                    StringBuilder sb = this.z;
                    cd.ab(j, sb);
                    textView.setText(sb.toString());
                }
            }
            if (this.ai) {
                return;
            }
            long j2 = this.x;
            this.v.setProgress(j2 > 0 ? (int) ((this.y / j2) * 2.147483647E9d) : 0);
        }

        public final boolean f() {
            if (this.ai) {
                return true;
            }
            cc.a aVar = this.ah;
            if (aVar == null || !aVar.b() || this.x <= 0) {
                return false;
            }
            this.ai = true;
            this.ah.e();
            this.ah.a();
            this.aa.a.setVisibility(8);
            this.ab.a.setVisibility(4);
            this.o.a.setVisibility(4);
            this.w.setVisibility(0);
            return true;
        }

        public final void g(boolean z) {
            if (!this.ai) {
                return;
            }
            this.ai = false;
            this.ah.c(z);
            int i = 0;
            while (true) {
                ThumbsBar thumbsBar = this.w;
                int childCount = thumbsBar.getChildCount();
                SparseArray sparseArray = thumbsBar.i;
                if (i >= childCount) {
                    sparseArray.clear();
                    this.aa.a.setVisibility(0);
                    this.ab.a.setVisibility(0);
                    this.o.a.setVisibility(0);
                    thumbsBar.setVisibility(4);
                    return;
                }
                sparseArray.put(i, null);
                ((ImageView) thumbsBar.getChildAt(i)).setImageBitmap(null);
                i++;
            }
        }

        public final void h(boolean z) {
            long j = this.y;
            long j2 = this.x;
            long j3 = (long) (j2 * cd.this.e);
            if (!z) {
                j3 = -j3;
            }
            long j4 = j + j3;
            if (j4 > j2) {
                j4 = j2;
            } else if (j4 < 0) {
                j4 = 0;
            }
            this.v.setProgress((int) ((j4 / j2) * 2.147483647E9d));
            this.ah.d(j4);
        }
    }

    public cd() {
        a aVar = new a();
        b bVar = new b();
        this.b = null;
        this.c = false;
        p pVar = new p(R.layout.lb_control_bar);
        this.g = pVar;
        pVar.e = false;
        p pVar2 = new p(R.layout.lb_control_bar);
        this.h = pVar2;
        pVar2.e = false;
        pVar.c = aVar;
        pVar2.c = aVar;
        pVar.b = bVar;
        pVar2.b = bVar;
    }

    public static void ab(long j, StringBuilder sb) {
        sb.setLength(0);
        if (j < 0) {
            sb.append("--");
            return;
        }
        long j2 = j / 1000;
        long j3 = j2 / 60;
        long j4 = j3 / 60;
        long j5 = j2 - (j3 * 60);
        long j6 = j3 - (60 * j4);
        if (j4 > 0) {
            sb.append(j4);
            sb.append(':');
            if (j6 < 10) {
                sb.append('0');
            }
        }
        sb.append(j6);
        sb.append(':');
        if (j5 < 10) {
            sb.append('0');
        }
        sb.append(j5);
    }

    @Override // androidx.leanback.widget.ca
    public final void aa(cp.b bVar) {
        d dVar = (d) bVar;
        if (dVar.a.hasFocus()) {
            dVar.v.requestFocus();
        }
    }

    @Override // androidx.leanback.widget.cp
    public final cp.b j(ViewGroup viewGroup) {
        View viewG = vw2.g(viewGroup, R.layout.lb_playback_transport_controls_row, viewGroup, false);
        d dVar = new d(viewG, this.f);
        p pVar = this.g;
        ViewGroup viewGroup2 = dVar.r;
        dVar.aa = (p.d) pVar.d(viewGroup2);
        Context context = viewGroup2.getContext();
        TypedValue typedValue = new TypedValue();
        int color = context.getTheme().resolveAttribute(R.attr.playbackProgressPrimaryColor, typedValue, true) ? context.getResources().getColor(typedValue.resourceId) : context.getResources().getColor(R.color.lb_playback_progress_color_no_theme);
        SeekBar seekBar = dVar.v;
        seekBar.setProgressColor(color);
        Context context2 = viewGroup2.getContext();
        TypedValue typedValue2 = new TypedValue();
        seekBar.setSecondaryProgressColor(context2.getTheme().resolveAttribute(R.attr.playbackProgressSecondaryColor, typedValue2, true) ? context2.getResources().getColor(typedValue2.resourceId) : context2.getResources().getColor(R.color.lb_playback_progress_secondary_color_no_theme));
        viewGroup2.addView(dVar.aa.a);
        p pVar2 = this.h;
        ViewGroup viewGroup3 = dVar.s;
        p.d dVar2 = (p.d) pVar2.d(viewGroup3);
        dVar.ab = dVar2;
        viewGroup3.addView(dVar2.a);
        ((PlaybackTransportRowView) viewG.findViewById(R.id.transport_row)).setOnUnhandledKeyListener(new ce(dVar));
        return dVar;
    }

    @Override // androidx.leanback.widget.cp
    public void q(cp.b bVar, Object obj) {
        super.q(bVar, obj);
        d dVar = (d) bVar;
        c cVar = dVar.ad;
        c cVar2 = dVar.ac;
        ViewGroup viewGroup = dVar.q;
        ImageView imageView = dVar.p;
        bw bwVar = (bw) dVar.d;
        ca7 ca7Var = bwVar.b;
        viewGroup.setVisibility(0);
        ci.a aVar = dVar.o;
        if (aVar != null) {
            this.f.c(aVar, bwVar.b);
        }
        if (bwVar.c == null) {
            imageView.setVisibility(8);
        } else {
            imageView.setVisibility(0);
        }
        imageView.setImageDrawable(bwVar.c);
        cVar2.a = bwVar.d;
        cVar2.b = dVar.d(true);
        cVar2.d = dVar;
        this.g.c(dVar.aa, cVar2);
        cVar.a = bwVar.e;
        cVar.b = dVar.d(false);
        cVar.d = dVar;
        this.h.c(dVar.ab, cVar);
        long j = bwVar.f;
        if (dVar.x != j) {
            dVar.x = j;
            StringBuilder sb = dVar.z;
            TextView textView = dVar.t;
            if (textView != null) {
                ab(j, sb);
                textView.setText(sb.toString());
            }
        }
        dVar.e(bwVar.g);
        dVar.v.setSecondaryProgress((int) ((bwVar.h / dVar.x) * 2.147483647E9d));
        bwVar.i = dVar.aj;
    }

    @Override // androidx.leanback.widget.cp
    public final void r(cp.b bVar) {
        super.r(bVar);
        ci ciVar = this.f;
        if (ciVar != null) {
            ciVar.f(((d) bVar).o);
        }
    }

    @Override // androidx.leanback.widget.cp
    public final void s(cp.b bVar) {
        super.s(bVar);
        ci ciVar = this.f;
        if (ciVar != null) {
            ciVar.g(((d) bVar).o);
        }
    }

    @Override // androidx.leanback.widget.cp
    public final void u(cp.b bVar, boolean z) {
        super.u(bVar, z);
        if (z) {
            ((d) bVar).c();
        }
    }

    @Override // androidx.leanback.widget.cp
    public void w(cp.b bVar) {
        d dVar = (d) bVar;
        bw bwVar = (bw) dVar.d;
        if (dVar.o != null) {
            this.f.getClass();
        }
        this.g.e(dVar.aa);
        this.h.e(dVar.ab);
        bwVar.i = null;
        super.w(bVar);
    }
}
