package n4;

import Z6.AbstractC0385z;
import android.app.Dialog;
import android.content.Context;
import android.os.Build;
import android.os.SystemClock;
import android.text.TextUtils;
import android.util.SparseArray;
import android.util.TypedValue;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import androidx.navigation.fragment.NavHostFragment;
import c1.C0576a;
import com.google.android.gms.internal.measurement.C1;
import com.martsnew.tv.R;
import d5.AbstractC0844a;
import h0.ComponentCallbacksC1023x;
import h0.DialogInterfaceOnCancelListenerC1017q;
import java.io.Serializable;
import java.lang.ref.WeakReference;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import n.R0;
import n.T0;
import x0.AbstractC1709a;

/* JADX INFO: loaded from: classes.dex */
public abstract class u0 implements E0.h {

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public static final /* synthetic */ int f15495q = 0;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public static boolean f15496r = false;

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public static Method f15497s;

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    public static final /* synthetic */ int f15498t = 0;

    /* JADX INFO: renamed from: u, reason: collision with root package name */
    public static final /* synthetic */ int f15499u = 0;

    public static B1.f A(int i, T0.j jVar, x0.o oVar) throws u0.F {
        B1.f fVarA = B1.f.a(jVar, oVar);
        while (true) {
            int i5 = fVarA.f961a;
            if (i5 == i) {
                return fVarA;
            }
            AbstractC0844a.s(i5, "Ignoring unknown WAV chunk: ", "WavHeaderReader");
            long j8 = fVarA.f962b;
            long j9 = 8 + j8;
            if (j8 % 2 != 0) {
                j9 = 9 + j8;
            }
            if (j9 > 2147483647L) {
                throw u0.F.c("Chunk is too large (~2GB+) to skip; id: " + i5);
            }
            jVar.b((int) j9);
            fVarA = B1.f.a(jVar, oVar);
        }
    }

    public static void b(StringBuilder sb, Object obj, O6.l lVar) {
        if (lVar != null) {
            sb.append((CharSequence) lVar.b(obj));
            return;
        }
        if (obj == null ? true : obj instanceof CharSequence) {
            sb.append((CharSequence) obj);
        } else if (obj instanceof Character) {
            sb.append(((Character) obj).charValue());
        } else {
            sb.append((CharSequence) obj.toString());
        }
    }

    public static C6.j c(C6.j jVar) {
        C6.g gVar = jVar.f1411q;
        gVar.b();
        return gVar.f1405y > 0 ? jVar : C6.j.f1410r;
    }

    public static boolean f(T0.j jVar) {
        x0.o oVar = new x0.o(8);
        int i = B1.f.a(jVar, oVar).f961a;
        if (i != 1380533830 && i != 1380333108) {
            return false;
        }
        jVar.f(oVar.f18539a, 0, 4, false);
        oVar.F(0);
        int iG = oVar.g();
        if (iG == 1463899717) {
            return true;
        }
        AbstractC1709a.o("WavHeaderReader", "Unsupported form type: " + iG);
        return false;
    }

    public static void g(boolean z8, String str, Object... objArr) {
        if (!z8) {
            throw new IllegalStateException(String.format(str, objArr));
        }
    }

    /* JADX WARN: Multi-variable type inference failed */
    public static long[] h(Serializable serializable) {
        if (!(serializable instanceof int[])) {
            if (serializable instanceof long[]) {
                return (long[]) serializable;
            }
            return null;
        }
        int[] iArr = (int[]) serializable;
        long[] jArr = new long[iArr.length];
        for (int i = 0; i < iArr.length; i++) {
            jArr[i] = iArr[i];
        }
        return jArr;
    }

    public static A7.a i(O0.s sVar) {
        long jElapsedRealtime = SystemClock.elapsedRealtime();
        int length = sVar.length();
        int i = 0;
        for (int i5 = 0; i5 < length; i5++) {
            if (sVar.o(jElapsedRealtime, i5)) {
                i++;
            }
        }
        return new A7.a(length, i, false);
    }

    public static androidx.lifecycle.W j(Class cls) throws InvocationTargetException {
        try {
            Object objNewInstance = cls.getDeclaredConstructor(null).newInstance(null);
            P6.g.b(objNewInstance);
            return (androidx.lifecycle.W) objNewInstance;
        } catch (IllegalAccessException e8) {
            throw new RuntimeException("Cannot create an instance of " + cls, e8);
        } catch (InstantiationException e9) {
            throw new RuntimeException("Cannot create an instance of " + cls, e9);
        } catch (NoSuchMethodException e10) {
            throw new RuntimeException("Cannot create an instance of " + cls, e10);
        }
    }

    public static byte[] l(byte[] bArr) {
        if (bArr.length != 16) {
            throw new IllegalArgumentException("value must be a block.");
        }
        byte[] bArr2 = new byte[16];
        for (int i = 0; i < 16; i++) {
            byte b8 = (byte) ((bArr[i] << 1) & 254);
            bArr2[i] = b8;
            if (i < 15) {
                bArr2[i] = (byte) (((byte) ((bArr[i + 1] >> 7) & 1)) | b8);
            }
        }
        bArr2[15] = (byte) (((byte) ((bArr[0] >> 7) & 135)) ^ bArr2[15]);
        return bArr2;
    }

    public static boolean r(View view, KeyEvent keyEvent) {
        ArrayList arrayList;
        int size;
        int iIndexOfKey;
        Field field = M.J.f4065a;
        if (Build.VERSION.SDK_INT >= 28) {
            return false;
        }
        ArrayList arrayList2 = M.I.f4061d;
        M.I i = (M.I) view.getTag(R.id.tag_unhandled_key_event_manager);
        WeakReference weakReference = null;
        if (i == null) {
            i = new M.I();
            i.f4062a = null;
            i.f4063b = null;
            i.f4064c = null;
            view.setTag(R.id.tag_unhandled_key_event_manager, i);
        }
        WeakReference weakReference2 = i.f4064c;
        if (weakReference2 != null && weakReference2.get() == keyEvent) {
            return false;
        }
        i.f4064c = new WeakReference(keyEvent);
        if (i.f4063b == null) {
            i.f4063b = new SparseArray();
        }
        SparseArray sparseArray = i.f4063b;
        if (keyEvent.getAction() == 1 && (iIndexOfKey = sparseArray.indexOfKey(keyEvent.getKeyCode())) >= 0) {
            weakReference = (WeakReference) sparseArray.valueAt(iIndexOfKey);
            sparseArray.removeAt(iIndexOfKey);
        }
        if (weakReference == null) {
            weakReference = (WeakReference) sparseArray.get(keyEvent.getKeyCode());
        }
        if (weakReference == null) {
            return false;
        }
        View view2 = (View) weakReference.get();
        if (view2 == null || !view2.isAttachedToWindow() || (arrayList = (ArrayList) view2.getTag(R.id.tag_unhandled_key_listeners)) == null || (size = arrayList.size() - 1) < 0) {
            return true;
        }
        arrayList.get(size).getClass();
        throw new ClassCastException();
    }

    public static final E1.F s(ComponentCallbacksC1023x componentCallbacksC1023x) {
        Dialog dialog;
        Window window;
        P6.g.e(componentCallbacksC1023x, "<this>");
        for (ComponentCallbacksC1023x componentCallbacksC1023x2 = componentCallbacksC1023x; componentCallbacksC1023x2 != null; componentCallbacksC1023x2 = componentCallbacksC1023x2.f13268N) {
            if (componentCallbacksC1023x2 instanceof NavHostFragment) {
                E1.F f3 = ((NavHostFragment) componentCallbacksC1023x2).f8979o0;
                if (f3 != null) {
                    return f3;
                }
                throw new NullPointerException("null cannot be cast to non-null type androidx.navigation.NavController");
            }
            ComponentCallbacksC1023x componentCallbacksC1023x3 = componentCallbacksC1023x2.q().f13091z;
            if (componentCallbacksC1023x3 instanceof NavHostFragment) {
                E1.F f7 = ((NavHostFragment) componentCallbacksC1023x3).f8979o0;
                if (f7 != null) {
                    return f7;
                }
                throw new NullPointerException("null cannot be cast to non-null type androidx.navigation.NavController");
            }
        }
        View view = componentCallbacksC1023x.X;
        if (view != null) {
            return W3.b.m(view);
        }
        View decorView = null;
        DialogInterfaceOnCancelListenerC1017q dialogInterfaceOnCancelListenerC1017q = componentCallbacksC1023x instanceof DialogInterfaceOnCancelListenerC1017q ? (DialogInterfaceOnCancelListenerC1017q) componentCallbacksC1023x : null;
        if (dialogInterfaceOnCancelListenerC1017q != null && (dialog = dialogInterfaceOnCancelListenerC1017q.f13237z0) != null && (window = dialog.getWindow()) != null) {
            decorView = window.getDecorView();
        }
        if (decorView != null) {
            return W3.b.m(decorView);
        }
        throw new IllegalStateException(AbstractC0844a.k("Fragment ", componentCallbacksC1023x, " does not have a NavController set"));
    }

    public static final int t(int i, int i5, int i8) {
        if (i8 > 0) {
            if (i < i5) {
                int i9 = i5 % i8;
                if (i9 < 0) {
                    i9 += i8;
                }
                int i10 = i % i8;
                if (i10 < 0) {
                    i10 += i8;
                }
                int i11 = (i9 - i10) % i8;
                if (i11 < 0) {
                    i11 += i8;
                }
                return i5 - i11;
            }
        } else {
            if (i8 >= 0) {
                throw new IllegalArgumentException("Step is zero.");
            }
            if (i > i5) {
                int i12 = -i8;
                int i13 = i % i12;
                if (i13 < 0) {
                    i13 += i12;
                }
                int i14 = i5 % i12;
                if (i14 < 0) {
                    i14 += i12;
                }
                int i15 = (i13 - i14) % i12;
                if (i15 < 0) {
                    i15 += i12;
                }
                return i15 + i5;
            }
        }
        return i5;
    }

    public static List u(j5.p pVar, List list) {
        ArrayList arrayList;
        if (list != null) {
            arrayList = new ArrayList(B6.m.a0(list));
            Iterator it = list.iterator();
            while (it.hasNext()) {
                arrayList.add(pVar.a(it.next()));
            }
        } else {
            arrayList = null;
        }
        return arrayList == null ? B6.t.f1032q : arrayList;
    }

    /* JADX WARN: Removed duplicated region for block: B:41:0x009c  */
    /* JADX WARN: Removed duplicated region for block: B:52:0x00d4  */
    /* JADX WARN: Removed duplicated region for block: B:68:0x00f4  */
    /* JADX WARN: Removed duplicated region for block: B:8:0x0014  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static final Object v(E6.d dVar, O1.A a3, O6.l lVar, boolean z8, boolean z9) throws Throwable {
        T1.h hVar;
        e7.c cVar;
        E6.i iVarA;
        O1.A a8;
        O6.l lVar2;
        boolean z10;
        boolean z11;
        if (dVar instanceof T1.h) {
            hVar = (T1.h) dVar;
            int i = hVar.f6517y;
            if ((i & Integer.MIN_VALUE) != 0) {
                hVar.f6517y = i - Integer.MIN_VALUE;
            } else {
                hVar = new T1.h(dVar);
            }
        }
        T1.h hVar2 = hVar;
        Object obj = hVar2.f6516x;
        F6.a aVar = F6.a.f2580q;
        int i5 = hVar2.f6517y;
        if (i5 == 0) {
            C1.N(obj);
            if (a3.g() && a3.h() && a3.h()) {
                O1.w wVar = a3.f4918e;
                if (wVar == null) {
                    P6.g.h("connectionManager");
                    throw null;
                }
                Y1.b bVarC = wVar.c();
                if (bVarC == null) {
                    throw new IllegalStateException("Cannot return a SupportSQLiteOpenHelper since no SupportSQLiteOpenHelper.Factory was configured with Room.");
                }
                if (bVarC.c0().g0()) {
                    T1.j jVar = new T1.j(null, a3, lVar, z9, z8);
                    hVar2.f6517y = 1;
                    Object objI = a3.i(z8, jVar, hVar2);
                    if (objI != aVar) {
                        return objI;
                    }
                }
            } else {
                hVar2.f6512t = a3;
                hVar2.f6513u = lVar;
                hVar2.f6514v = z8;
                hVar2.f6515w = z9;
                hVar2.f6517y = 2;
                if (a3.g()) {
                    E6.i iVar = hVar2.f3016r;
                    P6.g.b(iVar);
                    O1.E e8 = (O1.E) iVar.K(O1.E.f4936s);
                    if (e8 != null) {
                        E6.f fVar = e8.f4937q;
                        e7.c cVar2 = a3.f4914a;
                        if (cVar2 == null) {
                            P6.g.h("coroutineScope");
                            throw null;
                        }
                        iVarA = cVar2.f12542q.A(fVar);
                        if (iVarA == null) {
                            if (z9) {
                                iVarA = a3.f4915b;
                                if (iVarA == null) {
                                    P6.g.h("transactionContext");
                                    throw null;
                                }
                            } else {
                                cVar = a3.f4914a;
                                if (cVar == null) {
                                    P6.g.h("coroutineScope");
                                    throw null;
                                }
                            }
                        }
                        if (iVarA != aVar) {
                            a8 = a3;
                            lVar2 = lVar;
                            z10 = z9;
                            obj = iVarA;
                            z11 = z8;
                        }
                    }
                } else {
                    cVar = a3.f4914a;
                    if (cVar == null) {
                        P6.g.h("coroutineScope");
                        throw null;
                    }
                }
                iVarA = cVar.f12542q;
                if (iVarA != aVar) {
                }
            }
        }
        if (i5 == 1) {
            C1.N(obj);
            return obj;
        }
        if (i5 != 2) {
            if (i5 != 3) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            C1.N(obj);
            return obj;
        }
        boolean z12 = hVar2.f6515w;
        boolean z13 = hVar2.f6514v;
        O6.l lVar3 = hVar2.f6513u;
        O1.A a9 = hVar2.f6512t;
        C1.N(obj);
        z10 = z12;
        z11 = z13;
        lVar2 = lVar3;
        a8 = a9;
        T1.g gVar = new T1.g(null, a8, lVar2, z11, z10);
        hVar2.f6512t = null;
        hVar2.f6513u = null;
        hVar2.f6517y = 3;
        Object objC = AbstractC0385z.C((E6.i) obj, gVar, hVar2);
        return objC == aVar ? aVar : objC;
    }

    public static TypedValue w(Context context, int i) {
        TypedValue typedValue = new TypedValue();
        if (context.getTheme().resolveAttribute(i, typedValue, true)) {
            return typedValue;
        }
        return null;
    }

    public static int x(int i, Context context, String str) {
        TypedValue typedValueW = w(context, i);
        if (typedValueW != null) {
            return typedValueW.data;
        }
        throw new IllegalArgumentException(String.format("%1$s requires a value for the %2$s attribute to be set in your app theme. You can either set the attribute in your theme or update your theme to inherit from Theme.MaterialComponents (or a descendant).", str, context.getResources().getResourceName(i)));
    }

    public static Set y(Object... objArr) {
        P6.g.e(objArr, "elements");
        int length = objArr.length;
        if (length == 0) {
            return B6.v.f1034q;
        }
        if (length == 1) {
            Set setSingleton = Collections.singleton(objArr[0]);
            P6.g.d(setSingleton, "singleton(...)");
            return setSingleton;
        }
        LinkedHashSet linkedHashSet = new LinkedHashSet(B6.w.l0(objArr.length));
        for (Object obj : objArr) {
            linkedHashSet.add(obj);
        }
        return linkedHashSet;
    }

    public static void z(View view, CharSequence charSequence) {
        if (Build.VERSION.SDK_INT >= 26) {
            R0.a(view, charSequence);
            return;
        }
        T0 t02 = T0.f14777A;
        if (t02 != null && t02.f14779q == view) {
            T0.b(null);
        }
        if (!TextUtils.isEmpty(charSequence)) {
            new T0(view, charSequence);
            return;
        }
        T0 t03 = T0.f14778B;
        if (t03 != null && t03.f14779q == view) {
            t03.a();
        }
        view.setOnLongClickListener(null);
        view.setLongClickable(false);
        view.setOnHoverListener(null);
    }

    public abstract void B(View view, View view2);

    public abstract View k(ViewGroup viewGroup);

    public u0.D p(C0576a c0576a) {
        ByteBuffer byteBuffer = c0576a.f18u;
        byteBuffer.getClass();
        AbstractC1709a.d(byteBuffer.position() == 0 && byteBuffer.hasArray() && byteBuffer.arrayOffset() == 0);
        return q(c0576a, byteBuffer);
    }

    public abstract u0.D q(C0576a c0576a, ByteBuffer byteBuffer);
}
