package xyz.stream.utils;

import android.app.Application;
import android.content.Context;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.SurfaceTexture;
import android.net.ConnectivityManager;
import android.net.LinkAddress;
import android.net.LinkProperties;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.CountDownTimer;
import android.os.RemoteException;
import android.text.TextUtils;
import android.util.SparseIntArray;
import android.view.SurfaceHolder;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.media3.common.ParserException;
import androidx.media3.common.util.Consumer;
import androidx.media3.common.util.ParsableByteArray;
import androidx.room.RoomDatabase;
import androidx.room.s0;
import com.bumptech.glide.load.ImageHeaderParser$ImageType;
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton;
import java.io.FileInputStream;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.InterfaceAddress;
import java.net.NetworkInterface;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.IdentityHashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import n7.x1;
import ra.y0;
import tv.danmaku.ijk.media.player.ui.IjkVideoView;
import xyz.netfly.ui.iptv.IptvLiveActivity;
import xyz.netfly.ui.vod_player.PlayerActivity;
import xyz.stream.api.entity.BaseEntity;
import xyz.stream.utils.entity.CheckResultEntity;
import xyz.stream.utils.event.RemainingDayEvent;
import xyz.stream.view.TriangleView;
import xyz.stream.view.listener.OnDialogSelectListener;

/* JADX INFO: loaded from: classes3.dex */
public class e0 implements o.a, n2.p, n4.b, a5.f, j5.m, com.google.android.gms.ads.mediation.customevent.d, com.google.android.material.floatingactionbutton.i, OnDialogSelectListener, y {

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public static volatile e0 f36126d;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final /* synthetic */ int f36127a;

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

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public Object f36129c;

    public /* synthetic */ e0(Object obj, Object obj2, int i10) {
        this.f36127a = i10;
        this.f36129c = obj;
        this.f36128b = obj2;
    }

    public static String i(int i10) {
        String str = String.format("%d.%d.%d.%d", Arrays.copyOf(new Object[]{Integer.valueOf(i10 & 255), Integer.valueOf((i10 >> 8) & 255), Integer.valueOf((i10 >> 16) & 255), Integer.valueOf((i10 >> 24) & 255)}, 4));
        nb.g.h(str, "format(format, *args)");
        return str;
    }

    public static String l(InetAddress inetAddress) {
        InetAddress byName;
        try {
            for (InterfaceAddress interfaceAddress : NetworkInterface.getByInetAddress(inetAddress).getInterfaceAddresses()) {
                if (!interfaceAddress.getAddress().isLoopbackAddress() && (interfaceAddress.getAddress() instanceof Inet4Address)) {
                    int i10 = Integer.MIN_VALUE;
                    for (int networkPrefixLength = interfaceAddress.getNetworkPrefixLength() - 1; networkPrefixLength > 0; networkPrefixLength--) {
                        i10 >>= 1;
                    }
                    try {
                        byName = InetAddress.getByName(((i10 >> 24) & 255) + "." + ((i10 >> 16) & 255) + "." + ((i10 >> 8) & 255) + "." + (i10 & 255));
                    } catch (Exception unused) {
                        byName = null;
                    }
                    if (byName != null) {
                        String hostAddress = byName.getHostAddress();
                        nb.g.f(hostAddress);
                        return hostAddress;
                    }
                }
            }
            return "";
        } catch (Exception unused2) {
            return "";
        }
    }

    public static e0 m() {
        if (f36126d == null) {
            synchronized (e0.class) {
                try {
                    if (f36126d == null) {
                        f36126d = new e0(0);
                    }
                } finally {
                }
            }
        }
        return f36126d;
    }

    public static void t(ConstraintLayout constraintLayout, TextView textView, TriangleView triangleView, String str) {
        if (str == null || str.isEmpty()) {
            triangleView.setVisibility(8);
            constraintLayout.setVisibility(8);
            return;
        }
        e.d().getClass();
        if (e.e().equals("ar")) {
            triangleView.setScaleX(-1.0f);
        }
        constraintLayout.setVisibility(0);
        triangleView.setVisibility(0);
        textView.setText(str);
    }

    @Override // o.a
    public final Object apply(Object obj) {
        return (androidx.activity.result.i) this.f36128b;
    }

    @Override // n2.p
    public final void b(byte[] bArr, int i10, int i11, n2.o oVar, Consumer consumer) {
        w2.d cue;
        ((ParsableByteArray) this.f36128b).reset(bArr, i11 + i10);
        ((ParsableByteArray) this.f36128b).setPosition(i10);
        ArrayList arrayList = new ArrayList();
        try {
            w2.j.d((ParsableByteArray) this.f36128b);
            while (!TextUtils.isEmpty(((ParsableByteArray) this.f36128b).readLine())) {
            }
            ArrayList arrayList2 = new ArrayList();
            while (true) {
                ParsableByteArray parsableByteArray = (ParsableByteArray) this.f36128b;
                byte b10 = -1;
                int position = 0;
                while (b10 == -1) {
                    position = parsableByteArray.getPosition();
                    String line = parsableByteArray.readLine();
                    b10 = line == null ? (byte) 0 : "STYLE".equals(line) ? (byte) 2 : line.startsWith("NOTE") ? (byte) 1 : (byte) 3;
                }
                parsableByteArray.setPosition(position);
                if (b10 == 0) {
                    ua.b.K(new w2.k(arrayList2), oVar, consumer);
                    return;
                }
                if (b10 == 1) {
                    while (!TextUtils.isEmpty(((ParsableByteArray) this.f36128b).readLine())) {
                    }
                } else if (b10 == 2) {
                    if (!arrayList2.isEmpty()) {
                        throw new IllegalArgumentException("A style block was found after the first cue.");
                    }
                    ((ParsableByteArray) this.f36128b).readLine();
                    arrayList.addAll(((w2.b) this.f36129c).a((ParsableByteArray) this.f36128b));
                } else if (b10 == 3 && (cue = w2.i.parseCue((ParsableByteArray) this.f36128b, arrayList)) != null) {
                    arrayList2.add(cue);
                }
            }
        } catch (ParserException e10) {
            throw new IllegalArgumentException(e10);
        }
    }

    @Override // j5.m
    public final void c(Bitmap bitmap, c5.e eVar) throws IOException {
        IOException exception = ((t5.f) this.f36129c).getException();
        if (exception != null) {
            if (bitmap == null) {
                throw exception;
            }
            eVar.a(bitmap);
            throw exception;
        }
    }

    @Override // n2.p
    public final int d() {
        return 1;
    }

    @Override // j5.m
    public final void e() {
        com.bumptech.glide.load.resource.bitmap.a aVar = (com.bumptech.glide.load.resource.bitmap.a) this.f36128b;
        synchronized (aVar) {
            aVar.f5816c = aVar.f5814a.length;
        }
    }

    public final void f(Enum r22, Object obj) {
        ((Map) this.f36128b).put(r22, obj);
        ((Map) this.f36129c).put(obj, r22);
    }

    @Override // com.google.android.material.floatingactionbutton.i
    public final int getHeight() {
        ViewGroup.MarginLayoutParams marginLayoutParams;
        Object obj = this.f36129c;
        if (((ExtendedFloatingActionButton) obj).f22544x0 != -1) {
            return (((ExtendedFloatingActionButton) obj).f22544x0 == 0 || ((ExtendedFloatingActionButton) obj).f22544x0 == -2) ? ((com.google.android.material.floatingactionbutton.i) this.f36128b).getHeight() : ((ExtendedFloatingActionButton) obj).f22544x0;
        }
        if (!(((ExtendedFloatingActionButton) obj).getParent() instanceof View)) {
            return ((com.google.android.material.floatingactionbutton.i) this.f36128b).getHeight();
        }
        View view = (View) ((ExtendedFloatingActionButton) this.f36129c).getParent();
        ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
        if (layoutParams == null || layoutParams.height != -2) {
            return (view.getHeight() - ((!(((ExtendedFloatingActionButton) this.f36129c).getLayoutParams() instanceof ViewGroup.MarginLayoutParams) || (marginLayoutParams = (ViewGroup.MarginLayoutParams) ((ExtendedFloatingActionButton) this.f36129c).getLayoutParams()) == null) ? 0 : marginLayoutParams.topMargin + marginLayoutParams.bottomMargin)) - (view.getPaddingBottom() + view.getPaddingTop());
        }
        return ((com.google.android.material.floatingactionbutton.i) this.f36128b).getHeight();
    }

    @Override // com.google.android.material.floatingactionbutton.i
    public final ViewGroup.LayoutParams getLayoutParams() {
        Object obj = this.f36129c;
        return new ViewGroup.LayoutParams(-1, ((ExtendedFloatingActionButton) obj).f22544x0 == 0 ? -2 : ((ExtendedFloatingActionButton) obj).f22544x0);
    }

    @Override // com.google.android.material.floatingactionbutton.i
    public final int getPaddingEnd() {
        return ((ExtendedFloatingActionButton) this.f36129c).f22537q0;
    }

    @Override // com.google.android.material.floatingactionbutton.i
    public final int getPaddingStart() {
        return ((ExtendedFloatingActionButton) this.f36129c).f22536p0;
    }

    @Override // com.google.android.material.floatingactionbutton.i
    public final int getWidth() {
        ViewGroup.MarginLayoutParams marginLayoutParams;
        if (!(((ExtendedFloatingActionButton) this.f36129c).getParent() instanceof View)) {
            return ((com.google.android.material.floatingactionbutton.i) this.f36128b).getWidth();
        }
        View view = (View) ((ExtendedFloatingActionButton) this.f36129c).getParent();
        ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
        if (layoutParams == null || layoutParams.width != -2) {
            return (view.getWidth() - ((!(((ExtendedFloatingActionButton) this.f36129c).getLayoutParams() instanceof ViewGroup.MarginLayoutParams) || (marginLayoutParams = (ViewGroup.MarginLayoutParams) ((ExtendedFloatingActionButton) this.f36129c).getLayoutParams()) == null) ? 0 : marginLayoutParams.leftMargin + marginLayoutParams.rightMargin)) - (view.getPaddingRight() + view.getPaddingLeft());
        }
        return ((com.google.android.material.floatingactionbutton.i) this.f36128b).getWidth();
    }

    public final ab.b h() {
        return new ab.b((String) this.f36128b, ((Map) this.f36129c) == null ? Collections.emptyMap() : Collections.unmodifiableMap(new HashMap((Map) this.f36129c)));
    }

    public final ArrayList j(String str) {
        s0 s0VarK = s0.k(1, "SELECT work_spec_id FROM dependency WHERE prerequisite_id=?");
        if (str == null) {
            s0VarK.d(1);
        } else {
            s0VarK.l(1, str);
        }
        ((RoomDatabase) this.f36128b).assertNotSuspendingTransaction();
        Cursor cursorC = androidx.room.util.b.c((RoomDatabase) this.f36128b, s0VarK);
        try {
            ArrayList arrayList = new ArrayList(cursorC.getCount());
            while (cursorC.moveToNext()) {
                arrayList.add(cursorC.getString(0));
            }
            return arrayList;
        } finally {
            cursorC.close();
            s0VarK.m();
        }
    }

    @Override // a5.f
    public final ImageHeaderParser$ImageType k(a5.c cVar) throws Throwable {
        com.bumptech.glide.load.resource.bitmap.a aVar = null;
        try {
            com.bumptech.glide.load.resource.bitmap.a aVar2 = new com.bumptech.glide.load.resource.bitmap.a(new FileInputStream(((com.bumptech.glide.load.data.n) this.f36128b).a().getFileDescriptor()), (c5.b) this.f36129c);
            try {
                ImageHeaderParser$ImageType imageHeaderParser$ImageTypeB = cVar.b(aVar2);
                try {
                    aVar2.close();
                } catch (IOException unused) {
                }
                ((com.bumptech.glide.load.data.n) this.f36128b).a();
                return imageHeaderParser$ImageTypeB;
            } catch (Throwable th) {
                th = th;
                aVar = aVar2;
                if (aVar != null) {
                    try {
                        aVar.close();
                    } catch (IOException unused2) {
                    }
                }
                ((com.bumptech.glide.load.data.n) this.f36128b).a();
                throw th;
            }
        } catch (Throwable th2) {
            th = th2;
        }
    }

    @Override // xyz.stream.utils.y
    public final void n(String str) {
        try {
            if (((BaseEntity) m.f36162a.fromJson(str, BaseEntity.class)).getCode() != 200) {
                ((xyz.stream.api.e) this.f36128b).onSuccess(Boolean.FALSE);
            } else {
                ((xyz.stream.api.e) this.f36128b).onSuccess(Boolean.TRUE);
            }
        } catch (Exception unused) {
            ((xyz.stream.api.e) this.f36128b).onSuccess(Boolean.FALSE);
        }
    }

    public final y0 o() {
        y0 y0Var = (y0) this.f36128b;
        if (y0Var != null) {
            return y0Var;
        }
        da.l lVar = (da.l) this.f36129c;
        return lVar instanceof ma.k ? ((ma.k) lVar).f30532a.f30529b : ((ma.i0) ma.t.f30555b.h(lVar)).f30529b;
    }

    @Override // xyz.stream.view.listener.OnDialogSelectListener
    public final void onCancelClick() {
        switch (this.f36127a) {
            case 22:
                IptvLiveActivity iptvLiveActivity = (IptvLiveActivity) this.f36129c;
                int i10 = IptvLiveActivity.R;
                iptvLiveActivity.S();
                break;
            default:
                super.onCancelClick();
                rf.w wVar = ((PlayerActivity) this.f36129c).f35718k;
                if (wVar != null) {
                    wVar.x();
                }
                break;
        }
    }

    @Override // xyz.stream.view.listener.OnDialogSelectListener
    public final void onItemSelected(int i10) {
        switch (this.f36127a) {
            case 22:
                Integer num = ((Integer[]) ((Map) this.f36128b).keySet().toArray(new Integer[0]))[i10];
                f0.o().v(num.intValue(), "sp_live_video_ratio");
                IjkVideoView ijkVideoView = ((IptvLiveActivity) this.f36129c).f35294d;
                if (ijkVideoView != null) {
                    ijkVideoView.setResizeMode(num.intValue());
                }
                ((ie.k) ((IptvLiveActivity) this.f36129c).binding).f27104j.getRatioText().setText((CharSequence) ((Map) this.f36128b).get(num));
                ((IptvLiveActivity) this.f36129c).S();
                break;
            default:
                ((OnDialogSelectListener) this.f36128b).onItemSelected(i10);
                rf.w wVar = ((PlayerActivity) this.f36129c).f35718k;
                if (wVar != null) {
                    wVar.x();
                }
                break;
        }
    }

    public final void p(Context context) {
        CheckResultEntity checkResultEntityC;
        if (f0.o().j("sp_is_login_new", Boolean.FALSE)) {
            CheckResultEntity checkResultEntityC2 = e.d().c();
            double dIntValue = checkResultEntityC2 == null ? 0.0d : ((double) (checkResultEntityC2.getExpiredAt().intValue() - checkResultEntityC2.getNowTs().intValue())) / 86400.0d;
            if (dIntValue <= 0.0d) {
                fe.d.b().e(new RemainingDayEvent(" 0 " + context.getString(c0.day)));
                return;
            }
            if (dIntValue > 10.0d) {
                this.f36128b = "";
                fe.d.b().e(new RemainingDayEvent((String) this.f36128b));
                return;
            }
            if (dIntValue > 1.0d) {
                this.f36128b = " " + ((int) dIntValue) + " " + context.getString(c0.days);
                fe.d.b().e(new RemainingDayEvent((String) this.f36128b));
                return;
            }
            if (((CountDownTimer) this.f36129c) == null && (checkResultEntityC = e.d().c()) != null) {
                d0 d0Var = new d0(this, ((long) (checkResultEntityC.getExpiredAt().intValue() - checkResultEntityC.getNowTs().intValue())) * 1000, context);
                this.f36129c = d0Var;
                d0Var.start();
            }
        }
    }

    public final String q() {
        Object next;
        InetAddress address;
        LinkProperties linkProperties;
        if (Build.VERSION.SDK_INT < 31) {
            WifiInfo connectionInfo = ((WifiManager) this.f36128b).getConnectionInfo();
            nb.g.h(connectionInfo, "getConnectionInfo(...)");
            int ipAddress = connectionInfo.getIpAddress();
            if (ipAddress != 0) {
                return i(ipAddress);
            }
            return null;
        }
        ConnectivityManager connectivityManager = (ConnectivityManager) this.f36129c;
        List<LinkAddress> linkAddresses = (connectivityManager == null || (linkProperties = connectivityManager.getLinkProperties(connectivityManager.getActiveNetwork())) == null) ? null : linkProperties.getLinkAddresses();
        if (linkAddresses == null) {
            return null;
        }
        Iterator<T> it = linkAddresses.iterator();
        while (true) {
            if (!it.hasNext()) {
                next = null;
                break;
            }
            next = it.next();
            String hostAddress = ((LinkAddress) next).getAddress().getHostAddress();
            if (hostAddress != null && kotlin.text.i.k0(hostAddress, '.')) {
                break;
            }
        }
        LinkAddress linkAddress = (LinkAddress) next;
        if (linkAddress == null || (address = linkAddress.getAddress()) == null) {
            return null;
        }
        return address.getHostAddress();
    }

    @Override // xyz.stream.utils.y
    public final void r(Exception exc) {
        ((xyz.stream.api.e) this.f36128b).onSuccess(Boolean.FALSE);
    }

    public final boolean s(String str) {
        s0 s0VarK = s0.k(1, "SELECT COUNT(*)=0 FROM dependency WHERE work_spec_id=? AND prerequisite_id IN (SELECT id FROM workspec WHERE state!=2)");
        if (str == null) {
            s0VarK.d(1);
        } else {
            s0VarK.l(1, str);
        }
        ((RoomDatabase) this.f36128b).assertNotSuspendingTransaction();
        Cursor cursorC = androidx.room.util.b.c((RoomDatabase) this.f36128b, s0VarK);
        try {
            boolean z10 = false;
            if (cursorC.moveToFirst()) {
                z10 = cursorC.getInt(0) != 0;
            }
            return z10;
        } finally {
            cursorC.close();
            s0VarK.m();
        }
    }

    public final String toString() {
        switch (this.f36127a) {
            case 10:
                return (String) this.f36128b;
            default:
                return super.toString();
        }
    }

    public final void u(Annotation annotation) {
        if (((Map) this.f36129c) == null) {
            this.f36129c = new HashMap();
        }
        ((Map) this.f36129c).put(annotation.annotationType(), annotation);
    }

    public final int v(Context context, com.google.android.gms.common.api.e eVar) {
        com.google.android.gms.common.internal.w.checkNotNull(context);
        com.google.android.gms.common.internal.w.checkNotNull(eVar);
        int i10 = 0;
        if (!eVar.requiresGooglePlayServices()) {
            return 0;
        }
        int minApkVersion = eVar.getMinApkVersion();
        int iB = ((SparseIntArray) this.f36128b).get(minApkVersion, -1);
        if (iB == -1) {
            int i11 = 0;
            while (true) {
                if (i11 >= ((SparseIntArray) this.f36128b).size()) {
                    i10 = -1;
                    break;
                }
                int iKeyAt = ((SparseIntArray) this.f36128b).keyAt(i11);
                if (iKeyAt > minApkVersion && ((SparseIntArray) this.f36128b).get(iKeyAt) == 0) {
                    break;
                }
                i11++;
            }
            iB = i10 == -1 ? ((e8.e) this.f36129c).b(context, minApkVersion) : i10;
            ((SparseIntArray) this.f36128b).put(minApkVersion, iB);
        }
        return iB;
    }

    public final void w() {
        ((SparseIntArray) this.f36128b).clear();
    }

    public /* synthetic */ e0(Object obj, Object obj2, int i10, int i11) {
        this.f36127a = i10;
        this.f36128b = obj;
        this.f36129c = obj2;
    }

    public e0(x1 x1Var) {
        String strZze;
        this.f36127a = 10;
        this.f36129c = x1Var;
        try {
            strZze = x1Var.zze();
        } catch (RemoteException unused) {
            strZze = null;
        }
        this.f36128b = strZze;
    }

    public e0() {
        e8.d dVar = e8.d.f25520d;
        this.f36127a = 12;
        this.f36128b = new SparseIntArray();
        com.google.android.gms.common.internal.w.checkNotNull(dVar);
        this.f36129c = dVar;
    }

    public e0(Application application, ce.e eVar) {
        this.f36127a = 21;
        this.f36128b = application;
        this.f36129c = eVar;
    }

    public e0(WifiManager wifiManager, ConnectivityManager connectivityManager) {
        this.f36127a = 20;
        this.f36128b = wifiManager;
        this.f36129c = connectivityManager;
    }

    public e0(SurfaceHolder surfaceHolder) {
        this.f36127a = 19;
        if (surfaceHolder == null) {
            throw new IllegalArgumentException("surfaceHolder may not be null");
        }
        this.f36128b = surfaceHolder;
    }

    public e0(int i10) {
        this.f36127a = i10;
        if (i10 == 2) {
            this.f36128b = new ParsableByteArray();
            this.f36129c = new w2.b();
        } else if (i10 == 15) {
            this.f36128b = new HashMap();
            this.f36129c = new HashMap();
        } else {
            if (i10 != 18) {
                return;
            }
            this.f36128b = new int[4];
            this.f36129c = new StringBuilder();
        }
    }

    public e0(SurfaceTexture surfaceTexture) {
        this.f36127a = 19;
        if (surfaceTexture == null) {
            throw new IllegalArgumentException("surfaceTexture may not be null");
        }
        this.f36129c = surfaceTexture;
    }

    public e0(RoomDatabase roomDatabase, int i10) {
        this.f36127a = i10;
        if (i10 != 4) {
            nb.g.i(roomDatabase, "database");
            this.f36128b = roomDatabase;
            Set setNewSetFromMap = Collections.newSetFromMap(new IdentityHashMap());
            nb.g.h(setNewSetFromMap, "newSetFromMap(...)");
            this.f36129c = setNewSetFromMap;
            return;
        }
        this.f36128b = roomDatabase;
        this.f36129c = new n4.c(this, roomDatabase, 0);
    }

    /* JADX WARN: 'this' call moved to the top of the method (can break code semantics) */
    public /* synthetic */ e0(Object obj) {
        this(15);
        this.f36127a = 15;
    }

    public e0(da.l lVar) {
        this.f36127a = 14;
        this.f36128b = null;
        this.f36129c = lVar;
    }

    public e0(String str) {
        this.f36127a = 16;
        this.f36129c = null;
        this.f36128b = str;
    }
}
