package xyz.netfly.mobile.player;

import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.net.ConnectivityManager;
import android.net.NetworkCapabilities;
import android.os.Build;
import android.os.Environment;
import android.os.Handler;
import android.os.StatFs;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowInsets;
import android.view.WindowInsetsController;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.TranslateAnimation;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.SeekBar;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.gms.measurement.internal.u1;
import ie.a5;
import ie.c5;
import ie.e5;
import ie.f5;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicReference;
import org.drive_hunter.R;
import tv.danmaku.ijk.media.player.ui.IjkVideoView;
import xyz.netfly.mobile.view.VideoDetailControl;
import xyz.netfly.mobile.view.VideoDetailFullControl;
import xyz.stream.api.entity.SeriesEntity;
import xyz.stream.api.entity.TagsEntity;
import xyz.stream.api.entity.VideoInfoEntity;
import xyz.stream.download.DownloadFile;
import xyz.stream.download.DownloadManager;
import xyz.stream.download.DownloadProgressListener;
import xyz.stream.utils.entity.AppInfoEntity;
import xyz.stream.utils.f0;
import xyz.stream.view.DividerItemDecoration;
import xyz.stream.view.GridSpacingItemDecoration;
import xyz.stream.view.MaskOverLay;
import xyz.stream.view.SpacesItemHorDecoration;
import xyz.stream.view.UiUtils;
import xyz.stream.view.VideoGestureFrameLayout;

/* JADX INFO: loaded from: classes3.dex */
public final class t implements DownloadProgressListener {
    public int A;
    public String B;
    public String D;
    public Double F;
    public String G;
    public int H;
    public int I;
    public String J;
    public String K;
    public boolean L;
    public boolean M;
    public ArrayList Q;
    public ke.g S;
    public ke.c U;
    public y V;
    public w W;
    public androidx.activity.result.d X;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public AppCompatActivity f35007a;

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

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public ie.y f35009c;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public VideoDetailControl f35011e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public VideoDetailFullControl f35012f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public xyz.netfly.player.n f35013g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public x1.a f35014h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public xyz.netfly.player.r f35015i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public DownloadManager f35016j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public xyz.stream.api.q f35017k;

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public PopupWindow f35023q;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public PopupWindow f35024r;

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public PopupWindow f35025s;

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    public q f35026t;

    /* JADX INFO: renamed from: u, reason: collision with root package name */
    public String f35027u;

    /* JADX INFO: renamed from: x, reason: collision with root package name */
    public VideoInfoEntity f35030x;

    /* JADX INFO: renamed from: y, reason: collision with root package name */
    public SeriesEntity f35031y;

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

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final Handler f35010d = new Handler();

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public boolean f35018l = false;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public boolean f35019m = false;

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    public boolean f35020n = false;

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public boolean f35021o = false;

    /* JADX INFO: renamed from: p, reason: collision with root package name */
    public int f35022p = 2;

    /* JADX INFO: renamed from: v, reason: collision with root package name */
    public int f35028v = 0;

    /* JADX INFO: renamed from: w, reason: collision with root package name */
    public int f35029w = 0;
    public int C = -1;
    public int E = 0;
    public final ArrayList N = new ArrayList();
    public final ArrayList O = new ArrayList();
    public final ArrayList P = new ArrayList();
    public int R = 0;
    public int T = 1;
    public final List Y = Arrays.asList("0.5x", "0.75x", "1.0x\nNormal", "1.25x", "1.5x", "2.0x");
    public final e Z = new e(this, 2);

    public static /* synthetic */ void a(t tVar) {
        int currentPosition = tVar.f35008b.getCurrentPosition();
        xyz.netfly.api.c.b().o();
        IjkVideoView ijkVideoView = tVar.f35008b;
        ijkVideoView.seekTo(Math.min(currentPosition + 15000, ijkVideoView.getDuration()));
    }

    public static /* synthetic */ void b(t tVar) {
        int currentPosition = tVar.f35008b.getCurrentPosition();
        xyz.netfly.api.c.b().o();
        tVar.f35008b.seekTo(Math.max(currentPosition - 15000, 0));
    }

    public static void c(t tVar, String str, ke.n nVar, String str2) {
        if (str != null) {
            tVar.getClass();
            xyz.stream.api.o.f().C(str, new m(tVar, nVar, 1));
            return;
        }
        List<TagsEntity> tags = tVar.f35030x.getTags();
        ArrayList arrayListE = tags != null ? t4.f.x(tags).m(new fa.h(18)).E() : new ArrayList();
        List list = (List) xyz.stream.utils.m.f36162a.fromJson(str2, new VideoController$9().getType());
        xyz.stream.api.o oVarF = xyz.stream.api.o.f();
        if (list != null && !list.isEmpty()) {
            arrayListE = null;
        }
        int i10 = tVar.A;
        if (list == null || list.isEmpty()) {
            list = null;
        }
        oVarF.q(arrayListE, i10, list, new m(tVar, nVar, 0));
    }

    public static /* synthetic */ void d(t tVar) {
        int currentPosition = tVar.f35008b.getCurrentPosition();
        xyz.netfly.api.c.b().o();
        IjkVideoView ijkVideoView = tVar.f35008b;
        ijkVideoView.seekTo(Math.min(currentPosition + 15000, ijkVideoView.getDuration()));
    }

    public static /* synthetic */ void e(t tVar) {
        int currentPosition = tVar.f35008b.getCurrentPosition();
        xyz.netfly.api.c.b().o();
        tVar.f35008b.seekTo(Math.max(currentPosition - 15000, 0));
    }

    public static boolean g(AppCompatActivity appCompatActivity) {
        boolean zJ = f0.o().j("flutter.downloadOnlyWifi", Boolean.TRUE);
        ConnectivityManager connectivityManager = (ConnectivityManager) appCompatActivity.getSystemService("connectivity");
        NetworkCapabilities networkCapabilities = connectivityManager.getNetworkCapabilities(connectivityManager.getActiveNetwork());
        return (networkCapabilities != null && networkCapabilities.hasTransport(1)) || !zJ;
    }

    public static PopupWindow m(AppCompatActivity appCompatActivity, ViewGroup viewGroup, VideoGestureFrameLayout videoGestureFrameLayout, int i10) {
        PopupWindow popupWindow = new PopupWindow(viewGroup, -1, i10);
        popupWindow.getContentView().setSystemUiVisibility(4870);
        popupWindow.setBackgroundDrawable(new ColorDrawable(-16777216));
        popupWindow.setInputMethodMode(1);
        popupWindow.setSoftInputMode(16);
        MaskOverLay.getInstance().backgroundAlpha(appCompatActivity, 0.5f);
        popupWindow.setOnDismissListener(new j(appCompatActivity, 0));
        popupWindow.setBackgroundDrawable(new BitmapDrawable());
        popupWindow.setFocusable(true);
        popupWindow.setOutsideTouchable(true);
        TranslateAnimation translateAnimation = new TranslateAnimation(2, 0.0f, 2, 0.0f, 2, 1.0f, 2, 0.0f);
        translateAnimation.setInterpolator(new AccelerateInterpolator());
        translateAnimation.setDuration(200L);
        popupWindow.showAtLocation(videoGestureFrameLayout, 81, 0, 0);
        viewGroup.startAnimation(translateAnimation);
        return popupWindow;
    }

    public static float n() {
        try {
            return Float.parseFloat(f0.o().q("flutter.subtitleSize2", String.valueOf(0.054f)));
        } catch (Exception unused) {
            return 0.054f;
        }
    }

    public final void A(TextView textView) {
        Double d10 = this.F;
        double dDoubleValue = d10 == null ? 0.0d : d10.doubleValue();
        textView.setText(String.format(Locale.US, "%s %s s", dDoubleValue > 0.0d ? "+" : dDoubleValue == 0.0d ? "" : "-", Double.valueOf(Math.abs(dDoubleValue))));
    }

    public final void B() {
        u();
        if (this.f35019m) {
            this.f35009c.f27708i.setVisibility(0);
        } else if (this.f35018l) {
            this.f35012f.setVisibility(0);
            this.f35012f.f35138a.f26964a.setVisibility(0);
        } else {
            this.f35011e.setVisibility(0);
            this.f35011e.f35131a.f26901a.setVisibility(0);
        }
    }

    public final void C() {
        if (this.f35018l) {
            this.f35012f.setVisibility(0);
            this.f35012f.f35138a.f26964a.setVisibility(0);
        } else {
            this.f35011e.setVisibility(0);
            this.f35011e.f35131a.f26901a.setVisibility(0);
        }
    }

    public final void D(final boolean z10) {
        final int episodeNumber = this.f35031y.getEpisodeNumber();
        UiUtils.adaptActivityDensity(this.f35007a);
        int i10 = 0;
        final a5 a5VarInflate = a5.inflate(this.f35007a.getLayoutInflater(), null, false);
        LinearLayout linearLayout = a5VarInflate.f26644a;
        AppCompatActivity appCompatActivity = this.f35007a;
        VideoGestureFrameLayout videoGestureFrameLayout = this.f35009c.Z;
        ArrayList arrayList = this.P;
        this.f35025s = m(appCompatActivity, linearLayout, videoGestureFrameLayout, arrayList.size() > 24 ? z10 ? UiUtils.dp2px(1215.0f) : UiUtils.dp2px(1020.0f) : z10 ? UiUtils.dp2px(1100.0f) : UiUtils.dp2px(900.0f));
        a5VarInflate.f26651h.setText(this.f35007a.getString(z10 ? R.string.download : R.string.episodes));
        LinearLayout linearLayout2 = a5VarInflate.f26648e;
        TextView textView = a5VarInflate.f26652i;
        if (z10) {
            linearLayout2.setVisibility(0);
            textView.setVisibility(0);
            String string = this.f35007a.getString(R.string.download_all);
            TextView textView2 = a5VarInflate.f26645b;
            textView2.setText(string);
            a5VarInflate.f26646c.setText(this.f35007a.getString(R.string.download_selected));
            String string2 = this.f35007a.getString(R.string.used);
            StatFs statFs = new StatFs(Environment.getDataDirectory().getPath());
            long blockSizeLong = statFs.getBlockSizeLong();
            long availableBlocksLong = statFs.getAvailableBlocksLong();
            long blockCountLong = statFs.getBlockCountLong();
            Locale locale = Locale.US;
            String strReplace = string2.replace("{1}", String.format(locale, "%.2f", Double.valueOf(((((blockCountLong - availableBlocksLong) * blockSizeLong) / 1024.0d) / 1024.0d) / 1024.0d)));
            StatFs statFs2 = new StatFs(Environment.getDataDirectory().getPath());
            textView.setText(strReplace.replace("{2}", String.format(locale, "%.2f", Double.valueOf((((statFs2.getBlockCountLong() * statFs2.getBlockSizeLong()) / 1024.0d) / 1024.0d) / 1024.0d))));
            textView2.setOnClickListener(new g(this, 20));
        } else {
            linearLayout2.setVisibility(8);
            textView.setVisibility(8);
        }
        o oVar = new o(this, 6, 0);
        GridSpacingItemDecoration gridSpacingItemDecoration = new GridSpacingItemDecoration(6, 30, false);
        RecyclerView recyclerView = a5VarInflate.f26649f;
        recyclerView.addItemDecoration(gridSpacingItemDecoration);
        recyclerView.setLayoutManager(oVar);
        int size = arrayList.size();
        RecyclerView recyclerView2 = a5VarInflate.f26650g;
        if (size > 24) {
            recyclerView2.setVisibility(0);
            LinearLayoutManager linearLayoutManager = new LinearLayoutManager();
            linearLayoutManager.setOrientation(0);
            recyclerView2.setLayoutManager(linearLayoutManager);
            xyz.stream.utils.e.d().getClass();
            int i11 = xyz.stream.utils.e.e().contains("ar") ? 30 : 0;
            xyz.stream.utils.e.d().getClass();
            recyclerView2.addItemDecoration(new DividerItemDecoration(0, 0, i11, xyz.stream.utils.e.e().contains("ar") ? 0 : 30));
            ArrayList arrayList2 = new ArrayList();
            int size2 = arrayList.size();
            if (size2 != 0) {
                int i12 = (size2 + 19) / 20;
                while (i10 < i12) {
                    int i13 = i10 * 20;
                    i10++;
                    int iMin = Math.min((i10 * 20) - 1, size2 - 1);
                    int episodeNumber2 = ((SeriesEntity) arrayList.get(i13)).getEpisodeNumber();
                    int episodeNumber3 = ((SeriesEntity) arrayList.get(iMin)).getEpisodeNumber();
                    if (i13 == iMin) {
                        arrayList2.add(String.valueOf(episodeNumber2));
                    } else {
                        arrayList2.add(episodeNumber2 + "-" + episodeNumber3);
                    }
                }
            }
            int iIndexOf = t4.f.x(arrayList).m(new fa.h(12)).E().indexOf(Integer.valueOf(this.f35031y.getVideoId()));
            int i14 = iIndexOf / 20;
            final ke.e eVar = new ke.e(i14, this.f35007a, arrayList2);
            recyclerView2.setAdapter(eVar);
            eVar.f29121d = new le.b() { // from class: xyz.netfly.mobile.player.k
                @Override // le.b
                public final void onItemClick(View view, int i15) {
                    int i16 = episodeNumber;
                    boolean z11 = z10;
                    t tVar = this.f34983a;
                    tVar.getClass();
                    ke.e eVar2 = eVar;
                    int i17 = eVar2.f29120c;
                    eVar2.f29120c = i15;
                    if (i17 != i15) {
                        eVar2.notifyItemChanged(i17);
                        eVar2.notifyItemChanged(eVar2.f29120c);
                    }
                    a5 a5Var = a5VarInflate;
                    RecyclerView recyclerView3 = a5Var.f26649f;
                    TextView textView3 = a5Var.f26646c;
                    ArrayList arrayList3 = tVar.P;
                    tVar.w(recyclerView3, textView3, arrayList3.subList(i15 * 20, Math.min(arrayList3.size(), (i15 + 1) * 20)), i16, i15, z11);
                }
            };
            recyclerView2.post(new i0.o(iIndexOf, 4, a5VarInflate));
            w(a5VarInflate.f26649f, a5VarInflate.f26646c, arrayList.subList(i14 * 20, Math.min(arrayList.size(), (i14 + 1) * 20)), episodeNumber, i14, z10);
        } else {
            recyclerView2.setVisibility(8);
            w(a5VarInflate.f26649f, a5VarInflate.f26646c, arrayList, episodeNumber, 0, z10);
        }
        a5VarInflate.f26647d.setOnClickListener(new g(this, 21));
    }

    public final void E() {
        VideoDetailControl videoDetailControl = this.f35011e;
        videoDetailControl.removeCallbacks(videoDetailControl.f35132b);
        videoDetailControl.post(videoDetailControl.f35132b);
        VideoDetailFullControl videoDetailFullControl = this.f35012f;
        videoDetailFullControl.removeCallbacks(videoDetailFullControl.f35139b);
        videoDetailFullControl.post(videoDetailFullControl.f35139b);
    }

    public final void F() {
        List<DownloadFile> listQueryDownloadTask = this.f35016j.queryDownloadTask(false);
        if (listQueryDownloadTask == null || listQueryDownloadTask.isEmpty()) {
            AppCompatActivity appCompatActivity = this.f35007a;
            uf.r.c(appCompatActivity, appCompatActivity.getString(R.string.add_download_list));
        } else {
            Iterator<DownloadFile> it = listQueryDownloadTask.iterator();
            while (it.hasNext()) {
                if (Objects.equals(it.next().getVideoId(), this.f35030x.getId())) {
                    break;
                }
            }
            AppCompatActivity appCompatActivity2 = this.f35007a;
            uf.r.c(appCompatActivity2, appCompatActivity2.getString(R.string.add_download_list));
        }
        this.f35009c.f27711l.setVisibility(8);
        this.f35009c.L.setText(this.f35007a.getString(R.string.preparing));
        this.f35009c.f27718s.setVisibility(8);
        new Thread(new e(this, 5)).start();
    }

    public final void G() {
        if (this.f35019m) {
            if (this.f35009c.f27708i.getVisibility() == 0) {
                this.f35009c.f27708i.setVisibility(8);
                return;
            } else {
                this.f35009c.f27708i.setVisibility(0);
                u();
                return;
            }
        }
        if ((this.f35011e.getVisibility() == 0 && !this.f35018l) || (this.f35012f.getVisibility() == 0 && this.f35018l)) {
            p();
        } else if (this.f35008b.getPlaybackState() >= 3) {
            B();
        }
    }

    public final void H() {
        if (this.f35018l) {
            l();
        } else {
            k();
        }
    }

    public final void I() {
        if (this.f35021o) {
            p();
            PopupWindow popupWindow = this.f35024r;
            if (popupWindow != null && popupWindow.isShowing()) {
                this.f35024r.dismiss();
            }
        } else {
            p();
            UiUtils.adaptActivityDensity(this.f35007a);
            c5 c5VarInflate = c5.inflate(this.f35007a.getLayoutInflater(), null, false);
            this.f35024r = m(this.f35007a, c5VarInflate.f26739a, this.f35009c.Z, UiUtils.dp2px(220.0f));
            LinearLayoutManager linearLayoutManager = new LinearLayoutManager();
            linearLayoutManager.setOrientation(0);
            RecyclerView recyclerView = c5VarInflate.f26741c;
            recyclerView.setLayoutManager(linearLayoutManager);
            xyz.netfly.player.r rVar = this.f35015i;
            ke.k kVar = new ke.k(this.f35015i.f35276c, this.f35007a, t4.f.x(rVar.f35275b).m(new com.google.gson.internal.a(rVar, 12)).E());
            recyclerView.setAdapter(kVar);
            recyclerView.setHasFixedSize(false);
            recyclerView.setAnimation(null);
            kVar.f29140e = new i(this, 3);
            c5VarInflate.f26740b.setOnClickListener(new g(this, 0));
        }
        this.f35021o = !this.f35021o;
    }

    public final void J() {
        int i10 = 1;
        if (this.f35020n) {
            p();
            PopupWindow popupWindow = this.f35023q;
            if (popupWindow != null && popupWindow.isShowing()) {
                this.f35023q.dismiss();
            }
        } else {
            p();
            UiUtils.adaptActivityDensity(this.f35007a);
            e5 e5VarInflate = e5.inflate(this.f35007a.getLayoutInflater(), null, false);
            this.f35023q = m(this.f35007a, e5VarInflate.f26817a, this.f35009c.Z, UiUtils.dp2px(220.0f));
            LinearLayoutManager linearLayoutManager = new LinearLayoutManager();
            linearLayoutManager.setOrientation(0);
            RecyclerView recyclerView = e5VarInflate.f26819c;
            recyclerView.setLayoutManager(linearLayoutManager);
            ke.p pVar = new ke.p(this.f35022p, this.f35007a, this.Y);
            recyclerView.setAdapter(pVar);
            recyclerView.setHasFixedSize(false);
            recyclerView.setAnimation(null);
            SeekBar seekBar = e5VarInflate.f26820d;
            pVar.f29150e = new androidx.media3.exoplayer.analytics.g(this, seekBar, 19);
            seekBar.setOnSeekBarChangeListener(new r(this, pVar));
            e5VarInflate.f26818b.setOnClickListener(new g(this, i10));
        }
        this.f35020n = !this.f35020n;
    }

    public final void K() {
        ie.y yVar = this.f35009c;
        if (yVar == null || this.f35015i == null) {
            return;
        }
        yVar.f27706g.getBtnQuality().setVisibility(this.f35015i.f35275b.size() > 1 ? 0 : 8);
        String strC = this.f35015i.c();
        if (strC != null) {
            this.f35009c.f27706g.getQualityText().setText(strC);
        }
    }

    public final void f(float f10) {
        int iMin = (int) ((Math.min(this.f35008b.getHeight(), this.f35008b.getWidth()) * f10) + 0.5f);
        this.f35009c.I.setTextSizePx(iMin);
        this.f35008b.setSubtitleSizePx(iMin);
    }

    public final void h() {
        IjkVideoView ijkVideoView = this.f35008b;
        if (ijkVideoView != null && ijkVideoView.getPlaybackState() <= 1) {
            this.f35008b.setDrawableArtwork(null);
        }
        if (this.f35026t == null) {
            return;
        }
        AppCompatActivity appCompatActivity = this.f35007a;
        if (appCompatActivity != null) {
            try {
                com.bumptech.glide.c.f(appCompatActivity).clear(this.f35026t);
            } catch (Exception unused) {
            }
        }
        this.f35026t = null;
        this.f35027u = null;
    }

    public final void i(List list) {
        if (list == null || list.isEmpty()) {
            return;
        }
        if (!g(this.f35007a)) {
            kotlinx.coroutines.flow.h.M(this.f35007a, new androidx.media3.exoplayer.analytics.g(this, list, 20));
            return;
        }
        new Thread(new com.tekartik.sqflite.g(this, list, 4)).start();
        this.f35025s.dismiss();
        AppCompatActivity appCompatActivity = this.f35007a;
        uf.r.c(appCompatActivity, appCompatActivity.getString(R.string.add_download_list));
    }

    public final void j() {
        int i10 = this.H;
        if (i10 == 46) {
            return;
        }
        if (i10 == 44) {
            this.f35016j.pauseDownloadTask(Integer.valueOf(this.f35032z));
        } else if (g(this.f35007a)) {
            F();
        } else {
            kotlinx.coroutines.flow.h.M(this.f35007a, new i(this, 0));
        }
    }

    public final void k() {
        UiUtils.adaptActivityDensity(this.f35007a);
        this.f35007a.setRequestedOrientation(0);
        this.f35007a.getWindow().setFlags(1024, 1024);
        View decorView = this.f35007a.getWindow().getDecorView();
        if (Build.VERSION.SDK_INT >= 30) {
            WindowInsetsController insetsController = this.f35007a.getWindow().getInsetsController();
            if (insetsController != null) {
                insetsController.setSystemBarsBehavior(2);
                insetsController.hide(WindowInsets.Type.systemBars());
            }
            this.f35007a.getWindow().setDecorFitsSystemWindows(false);
        } else {
            decorView.setSystemUiVisibility(5894);
        }
        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(-1, -1);
        layoutParams.gravity = 17;
        this.f35008b.setLayoutParams(layoutParams);
        this.f35009c.f27699c.setLayoutParams(layoutParams);
        this.f35009c.f27698b0.setLayoutParams(layoutParams);
        this.f35011e.setVisibility(8);
        this.f35009c.B.setVisibility(8);
        this.f35009c.f27721v.setVisibility(8);
        this.f35009c.Z.setLayoutParams(new LinearLayout.LayoutParams(-1, -1));
        this.f35008b.postDelayed(new e(this, 4), 150L);
        this.f35018l = true;
    }

    public final void l() {
        UiUtils.adaptActivityDensity(this.f35007a);
        this.f35007a.setRequestedOrientation(1);
        this.f35007a.getWindow().clearFlags(1024);
        this.f35007a.getWindow().getDecorView().setSystemUiVisibility(0);
        Window window = this.f35007a.getWindow();
        AppCompatActivity appCompatActivity = this.f35007a;
        Object obj = g0.d.f26125a;
        window.setStatusBarColor(appCompatActivity.getColor(R.color.black_1));
        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(-1, (Math.min(this.f35029w, this.f35028v) * 9) / 16);
        this.f35008b.setLayoutParams(layoutParams);
        this.f35009c.f27699c.setLayoutParams(layoutParams);
        layoutParams.gravity = 17;
        if (Build.VERSION.SDK_INT >= 30) {
            WindowInsetsController insetsController = this.f35007a.getWindow().getInsetsController();
            if (insetsController != null) {
                insetsController.show(WindowInsets.Type.systemBars());
            }
            this.f35007a.getWindow().setDecorFitsSystemWindows(true);
        }
        this.f35009c.f27698b0.setLayoutParams(layoutParams);
        this.f35012f.setVisibility(8);
        this.f35009c.f27721v.setVisibility(0);
        this.f35009c.B.setVisibility(0);
        this.f35009c.Z.setLayoutParams(new LinearLayout.LayoutParams(-1, (Math.min(this.f35029w, this.f35028v) * 9) / 16));
        this.f35008b.postDelayed(new e(this, 3), 150L);
        this.f35018l = false;
    }

    public final VideoInfoEntity o(int i10, int i11) {
        CountDownLatch countDownLatch = new CountDownLatch(1);
        AtomicReference atomicReference = new AtomicReference();
        xyz.stream.api.o.f().s(i10, i11, new p(this, atomicReference, countDownLatch, 0));
        try {
            countDownLatch.await();
            return (VideoInfoEntity) atomicReference.get();
        } catch (Exception e10) {
            xyz.stream.utils.h.c(e10.getMessage());
            return null;
        }
    }

    public final void p() {
        if (this.f35019m) {
            this.f35009c.f27708i.setVisibility(8);
            return;
        }
        this.f35010d.removeCallbacks(this.Z);
        if (this.f35018l) {
            this.f35012f.setVisibility(8);
            this.f35012f.f35138a.f26964a.setVisibility(8);
        } else {
            this.f35011e.setVisibility(8);
            this.f35011e.f35131a.f26901a.setVisibility(8);
        }
    }

    @Override // xyz.stream.download.DownloadProgressListener
    public final void postDownloadData(int i10, int i11, int i12) {
        if (this.f35007a.isFinishing() || this.f35007a.isDestroyed()) {
            return;
        }
        this.f35007a.runOnUiThread(new f(this, i10, i11, i12, 0));
    }

    public final void q(AppCompatActivity appCompatActivity, ie.y yVar, int i10, int i11, int i12, String str, String str2, boolean z10, boolean z11, androidx.activity.result.d dVar, y yVar2) {
        if (appCompatActivity == null || yVar == null) {
            return;
        }
        this.V = yVar2;
        this.f35028v = (int) UiUtils.getScreenWidth(appCompatActivity);
        this.f35029w = (int) UiUtils.getScreenHeight(appCompatActivity);
        this.f35009c = yVar;
        this.f35007a = appCompatActivity;
        VideoDetailControl videoDetailControl = yVar.f27705f;
        this.f35011e = videoDetailControl;
        VideoDetailFullControl videoDetailFullControl = yVar.f27706g;
        this.f35012f = videoDetailFullControl;
        IjkVideoView ijkVideoView = yVar.f27704e0;
        this.f35008b = ijkVideoView;
        this.f35032z = i10;
        this.I = i11;
        this.A = i12;
        this.J = str;
        this.K = str2;
        this.X = dVar;
        this.L = z10;
        this.M = z11;
        videoDetailControl.setVideoView(ijkVideoView);
        this.f35012f.setVideoView(this.f35008b);
        this.f35016j = DownloadManager.getInstance();
        this.f35017k = xyz.stream.api.q.g();
        this.f35014h = new x1.a(this.f35008b);
        this.f35015i = new xyz.netfly.player.r(false);
        K();
        videoDetailFullControl.setSpeedText(appCompatActivity.getString(R.string.speed) + "(" + ((String) this.Y.get(this.f35022p)).split("\n")[0] + ")");
        videoDetailFullControl.setEpisodeText(appCompatActivity.getString(R.string.episodes));
        videoDetailFullControl.setSubtitleText(appCompatActivity.getString(R.string.audio) + " & " + appCompatActivity.getString(R.string.subtitle));
        yVar.L.setText(appCompatActivity.getString(R.string.download));
        videoDetailFullControl.setNextText(appCompatActivity.getString(R.string.next) + " " + appCompatActivity.getString(R.string.episode));
        yVar.P.setText(appCompatActivity.getString(R.string.lock_content_top));
        yVar.O.setText(appCompatActivity.getString(R.string.lock_content_bottom));
        yVar.Q.setText(appCompatActivity.getString(R.string.my_list));
        yVar.U.setText(appCompatActivity.getString(R.string.share));
        yVar.N.setText(appCompatActivity.getString(R.string.feedback));
        yVar.V.setText(appCompatActivity.getString(R.string.similar));
        yVar.J.setText(appCompatActivity.getString(R.string.cast_crew));
        int i13 = 14;
        int i14 = 8;
        int i15 = 2;
        int i16 = 6;
        if (this.M) {
            List<DownloadFile> listQueryDownloadTask = this.f35016j.queryDownloadTask(false);
            String filePath = null;
            if (listQueryDownloadTask != null && !listQueryDownloadTask.isEmpty()) {
                Object obj = t4.f.x(listQueryDownloadTask).e(new i(this, 2)).g().f32947a;
                if (obj == null) {
                    obj = null;
                }
                DownloadFile downloadFile = (DownloadFile) obj;
                if (downloadFile != null && downloadFile.getStatus().intValue() == 46) {
                    y yVar3 = this.V;
                    if (yVar3 != null) {
                        String filePath2 = downloadFile.getFilePath();
                        VideoDetailActivity videoDetailActivity = yVar3.f35043a;
                        xyz.netfly.player.q qVar = videoDetailActivity.f34920d;
                        if (qVar != null) {
                            qVar.c();
                            videoDetailActivity.f34920d.f35272f = filePath2;
                        }
                    }
                    filePath = downloadFile.getFilePath();
                }
            }
            this.D = filePath;
            if (filePath == null || filePath.isEmpty()) {
                appCompatActivity.finish();
                return;
            } else {
                videoDetailFullControl.getBtnQuality().setVisibility(8);
                if (yVar2 != null) {
                    new Thread(new androidx.emoji2.text.v(this, appCompatActivity, yVar2, i13)).start();
                }
            }
        } else {
            ArrayList arrayList = this.P;
            if (arrayList.isEmpty()) {
                LinearLayoutManager linearLayoutManager = new LinearLayoutManager();
                linearLayoutManager.setOrientation(0);
                this.f35009c.F.setLayoutManager(linearLayoutManager);
                xyz.stream.utils.e.d().getClass();
                int i17 = xyz.stream.utils.e.e().contains("ar") ? 30 : 0;
                xyz.stream.utils.e.d().getClass();
                this.f35009c.F.addItemDecoration(new DividerItemDecoration(0, 0, i17, xyz.stream.utils.e.e().contains("ar") ? 0 : 30));
            } else {
                arrayList.clear();
            }
            ke.c cVar = this.U;
            ArrayList arrayList2 = this.N;
            if (cVar == null) {
                LinearLayoutManager linearLayoutManager2 = new LinearLayoutManager();
                linearLayoutManager2.setOrientation(0);
                this.f35009c.E.addItemDecoration(new SpacesItemHorDecoration(UiUtils.dp2px(15.0f), 0, 0));
                this.f35009c.E.setLayoutManager(linearLayoutManager2);
                ke.c cVar2 = new ke.c(arrayList2, this.f35007a);
                this.U = cVar2;
                this.f35009c.E.setAdapter(cVar2);
                this.U.f29116c = new i(this, 1);
            } else {
                arrayList2.clear();
                this.U.notifyDataSetChanged();
            }
            UiUtils.showProgressDialog(this.f35007a);
            new Thread(new e(this, i16)).start();
        }
        this.f35009c.K.setOnClickListener(new g(this, i15));
        this.f35009c.f27723x.setOnClickListener(new g(this, 11));
        this.f35009c.f27720u.setOnClickListener(new g(this, 12));
        this.f35009c.f27719t.setOnClickListener(new g(this, 13));
        this.f35009c.f27706g.getSetting().setOnClickListener(new g(this, i13));
        this.f35009c.f27706g.getNext().setOnClickListener(new g(this, 15));
        this.f35009c.f27706g.getVideoRatio().setOnClickListener(new g(this, 16));
        this.f35009c.f27706g.getSubtitle().setOnClickListener(new g(this, 17));
        this.f35009c.f27706g.getEpisode().setOnClickListener(new g(this, 18));
        this.f35009c.f27706g.getBtnQuality().setOnClickListener(new g(this, 19));
        this.f35011e.getBtnFullScreen().setOnClickListener(new g(this, 3));
        this.f35012f.getBtnBack().setOnClickListener(new g(this, 4));
        this.f35011e.getBtnPre().setOnClickListener(new g(this, 5));
        this.f35011e.getBtnNext().setOnClickListener(new g(this, i16));
        this.f35012f.getBtnPre().setOnClickListener(new g(this, 7));
        this.f35012f.getBtnNext().setOnClickListener(new g(this, i14));
        this.f35012f.getLock().setOnClickListener(new g(this, 9));
        this.f35012f.getSpeed().setOnClickListener(new g(this, 10));
    }

    public final void r() {
        ArrayList arrayList = this.P;
        int i10 = 0;
        if (arrayList.isEmpty()) {
            x(false);
            C();
            return;
        }
        int i11 = this.C;
        int i12 = i11 + 1;
        if (i11 != arrayList.size() - 1) {
            i10 = i12;
        } else {
            if (this.R == ((Integer) u1.e(this.Q, 1)).intValue()) {
                x(false);
                C();
                return;
            }
            int iIndexOf = this.Q.indexOf(Integer.valueOf(this.R));
            this.f35009c.C.setVisibility(0);
            int i13 = iIndexOf + 1;
            List listM = xyz.stream.api.o.f().m(this.f35030x.getId().intValue(), null, (Integer) this.Q.get(i13));
            this.f35009c.C.setVisibility(0);
            if (listM == null || listM.isEmpty()) {
                x(false);
                C();
                return;
            } else {
                this.R = ((Integer) this.Q.get(i13)).intValue();
                arrayList.clear();
                arrayList.addAll(listM);
            }
        }
        int videoId = ((SeriesEntity) arrayList.get(i10)).getVideoId();
        y yVar = this.V;
        if (yVar != null) {
            yVar.a(videoId);
        }
    }

    public final void s() {
        ArrayList arrayList = this.P;
        if (arrayList.isEmpty()) {
            x(false);
            C();
            return;
        }
        int i10 = this.C;
        int size = i10 - 1;
        if (i10 == 0) {
            if (this.R == ((Integer) this.Q.get(0)).intValue()) {
                x(false);
                C();
                return;
            }
            int iIndexOf = this.Q.indexOf(Integer.valueOf(this.R));
            this.f35009c.C.setVisibility(0);
            int i11 = iIndexOf - 1;
            List listM = xyz.stream.api.o.f().m(this.f35030x.getId().intValue(), null, (Integer) this.Q.get(i11));
            this.f35009c.C.setVisibility(8);
            if (listM == null || listM.isEmpty()) {
                x(false);
                C();
                return;
            } else {
                this.R = ((Integer) this.Q.get(i11)).intValue();
                arrayList.clear();
                arrayList.addAll(listM);
                size = arrayList.size() - 1;
            }
        }
        int videoId = ((SeriesEntity) arrayList.get(size)).getVideoId();
        y yVar = this.V;
        if (yVar != null) {
            yVar.a(videoId);
        }
    }

    public final void t() {
        this.f35010d.removeCallbacks(this.Z);
    }

    public final void u() {
        Handler handler = this.f35010d;
        e eVar = this.Z;
        handler.removeCallbacks(eVar);
        handler.postDelayed(eVar, 5000L);
    }

    public final void v(int i10) {
        this.R = i10;
        ArrayList arrayList = this.P;
        int iIndexOf = t4.f.x(arrayList).m(new fa.h(17)).E().indexOf(Integer.valueOf(this.f35031y.getVideoId()));
        ke.g gVar = this.S;
        if (gVar == null) {
            ke.g gVar2 = new ke.g(arrayList, iIndexOf, i10, null, this.f35007a);
            this.S = gVar2;
            this.f35009c.F.setAdapter(gVar2);
        } else {
            gVar.f29123a = arrayList;
            gVar.f29127e = i10;
            gVar.a(iIndexOf);
            ke.g gVar3 = this.S;
            gVar3.f29124b = null;
            gVar3.notifyDataSetChanged();
            this.S.notifyItemRangeChanged(0, arrayList.size());
        }
        this.f35009c.F.post(new a(this, iIndexOf, 1));
        this.S.f29128f = new i(this, 8);
        this.f35009c.R.setText(this.f35007a.getString(R.string.season) + " " + i10);
        this.f35009c.M.setText(this.f35007a.getString(R.string.episodes) + " " + arrayList.size());
    }

    public final void w(RecyclerView recyclerView, final TextView textView, final List list, int i10, final int i11, final boolean z10) {
        List<DownloadFile> listQueryDownloadTask;
        final ArrayList arrayList = new ArrayList();
        if (z10 && (listQueryDownloadTask = this.f35016j.queryDownloadTask(false)) != null && !listQueryDownloadTask.isEmpty()) {
            for (DownloadFile downloadFile : listQueryDownloadTask) {
                if (Objects.equals(downloadFile.getVideoId(), this.f35030x.getId())) {
                    arrayList.add(downloadFile.getEpisodeId());
                }
            }
        }
        final ke.g gVar = new ke.g(list, t4.f.x(list).m(new fa.h(15)).E().indexOf(Integer.valueOf(i10)), this.R, arrayList, this.f35007a);
        recyclerView.setAdapter(gVar);
        final ArrayList arrayList2 = new ArrayList();
        textView.setOnClickListener(new xyz.netfly.ads.i(this, arrayList2, 1));
        gVar.f29128f = new le.b() { // from class: xyz.netfly.mobile.player.b
            @Override // le.b
            public final void onItemClick(View view, int i12) {
                t tVar = this.f34946a;
                boolean z11 = z10;
                List list2 = list;
                ke.g gVar2 = gVar;
                if (!z11) {
                    if (tVar.V != null) {
                        gVar2.a(i12);
                        RecyclerView recyclerView2 = tVar.f35009c.F;
                        int i13 = (i11 * 20) + i12;
                        recyclerView2.scrollToPosition(i13);
                        tVar.S.a(i13);
                        tVar.V.a(((SeriesEntity) list2.get(i12)).getVideoId());
                    }
                    tVar.f35025s.dismiss();
                    return;
                }
                tVar.getClass();
                Integer numValueOf = Integer.valueOf(((SeriesEntity) list2.get(i12)).getVideoId());
                List list3 = arrayList;
                if (list3.contains(numValueOf)) {
                    return;
                }
                list3.add(Integer.valueOf(((SeriesEntity) list2.get(i12)).getVideoId()));
                Integer numValueOf2 = Integer.valueOf(((SeriesEntity) list2.get(i12)).getVideoId());
                List list4 = arrayList2;
                list4.add(numValueOf2);
                gVar2.f29124b = list3;
                gVar2.notifyDataSetChanged();
                String str = tVar.f35007a.getString(R.string.download_selected) + "(" + list4.size() + ")";
                TextView textView2 = textView;
                textView2.setText(str);
                textView2.setBackgroundResource(R.drawable.shape_radius_red_select_12);
                textView2.setTextColor(tVar.f35007a.getResources().getColor(R.color.main_text));
            }
        };
    }

    public final void x(boolean z10) {
        if (z10) {
            this.f35011e.getBtnPlay().setImageDrawable(f.a.getDrawable(this.f35007a, R.mipmap.pause_circle));
            this.f35012f.getBtnPlay().setImageDrawable(f.a.getDrawable(this.f35007a, R.mipmap.pause_circle));
        } else {
            this.f35011e.getBtnPlay().setImageDrawable(f.a.getDrawable(this.f35007a, R.mipmap.play_circle));
            this.f35012f.getBtnPlay().setImageDrawable(f.a.getDrawable(this.f35007a, R.mipmap.play_circle));
        }
    }

    public final void y() {
        String str;
        AppInfoEntity appInfoEntity = xyz.stream.utils.e.d().f36115d;
        String dbVersion = appInfoEntity != null ? appInfoEntity.getDbVersion() : "1.0";
        String strH = kotlinx.coroutines.flow.h.h("yyyyMMdd", new Date(((long) this.f35030x.getUpdatedAt().intValue()) * 1000));
        if (this.A == 3) {
            str = this.f35030x.getTitle() + "_S" + this.f35031y.getSeasonNumber() + ".E" + this.f35031y.getEpisodeNumber() + ".mp4";
        } else {
            str = this.f35030x.getTitle() + ".mp4";
        }
        TextView textView = this.f35009c.T;
        StringBuilder sbT = defpackage.e.t("spiderman_", dbVersion, "/", strH, "/");
        sbT.append(str);
        textView.setText(sbT.toString());
        this.f35009c.S.setText(kotlinx.coroutines.flow.h.m(this.f35030x.getRuntime()));
    }

    public final void z(f5 f5Var) {
        float f10;
        try {
            f10 = Float.parseFloat(f0.o().q("flutter.subtitleSize2", String.valueOf(0.054f)));
        } catch (Exception e10) {
            u.a.g(e10, new StringBuilder("setSubtitleSizeMode: "));
            f10 = 0.054f;
        }
        if (f10 == 0.041f) {
            f5Var.f26870n.setBackgroundResource(R.drawable.shape_circle_subtitle_select);
            f5Var.f26869m.setBackgroundResource(R.drawable.shape_circle_subtitle_unselect);
            f5Var.f26868l.setBackgroundResource(R.drawable.shape_circle_subtitle_unselect);
            AppCompatActivity appCompatActivity = this.f35007a;
            Object obj = g0.d.f26125a;
            f5Var.f26866j.setTextColor(appCompatActivity.getColor(R.color.white));
            f5Var.f26865i.setTextColor(this.f35007a.getColor(R.color.black_9));
            f5Var.f26864h.setTextColor(this.f35007a.getColor(R.color.black_9));
            return;
        }
        if (f10 == 0.054f) {
            f5Var.f26870n.setBackgroundResource(R.drawable.shape_circle_subtitle_unselect);
            f5Var.f26869m.setBackgroundResource(R.drawable.shape_circle_subtitle_select);
            f5Var.f26868l.setBackgroundResource(R.drawable.shape_circle_subtitle_unselect);
            AppCompatActivity appCompatActivity2 = this.f35007a;
            Object obj2 = g0.d.f26125a;
            f5Var.f26866j.setTextColor(appCompatActivity2.getColor(R.color.black_9));
            f5Var.f26865i.setTextColor(this.f35007a.getColor(R.color.white));
            f5Var.f26864h.setTextColor(this.f35007a.getColor(R.color.black_9));
            return;
        }
        f5Var.f26870n.setBackgroundResource(R.drawable.shape_circle_subtitle_unselect);
        f5Var.f26869m.setBackgroundResource(R.drawable.shape_circle_subtitle_unselect);
        f5Var.f26868l.setBackgroundResource(R.drawable.shape_circle_subtitle_select);
        AppCompatActivity appCompatActivity3 = this.f35007a;
        Object obj3 = g0.d.f26125a;
        f5Var.f26866j.setTextColor(appCompatActivity3.getColor(R.color.black_9));
        f5Var.f26865i.setTextColor(this.f35007a.getColor(R.color.black_9));
        f5Var.f26864h.setTextColor(this.f35007a.getColor(R.color.white));
    }
}
