package pe;

import android.content.Intent;
import android.os.Handler;
import android.os.Looper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.google.android.gms.common.api.internal.i0;
import ie.c0;
import ie.g3;
import ie.j0;
import ie.k4;
import ie.l4;
import ie.m4;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.concurrent.ExecutorService;
import kotlinx.coroutines.y;
import org.drive_hunter.R;
import xyz.stream.api.database.entity.ServerEntity;
import xyz.stream.api.p;
import xyz.stream.api.viewmodel.IptvViewModel;
import xyz.stream.utils.entity.CheckResultEntity;
import xyz.stream.view.BaseFragment;
import xyz.stream.view.SpacesItemHorDecoration;
import xyz.stream.view.UiUtils;

/* JADX INFO: loaded from: classes3.dex */
public class g extends BaseFragment<IptvViewModel, j0> implements xyz.stream.api.database.e {
    public static final /* synthetic */ int S0 = 0;
    public g3 E0;
    public l4 F0;
    public m4 G0;
    public k4 H0;
    public qe.g J0;
    public androidx.activity.result.d K0;
    public c0 L0;
    public View M0;
    public View N0;
    public final ArrayList I0 = new ArrayList();
    public final Handler O0 = new Handler(Looper.getMainLooper());
    public int P0 = 0;
    public Integer Q0 = null;
    public final i0 R0 = new i0(this, 10);

    public final void J() {
        if (this.F0 == null || this.J0 == null) {
            return;
        }
        int i10 = 0;
        int itemCount = this.I0.isEmpty() ? this.J0.getItemCount() - 1 : 0;
        if (itemCount < 0) {
            return;
        }
        this.F0.f27181b.clearFocus();
        this.F0.f27181b.requestFocus();
        this.F0.f27181b.setSelection(itemCount);
        this.F0.f27181b.postDelayed(new b(this, itemCount, i10), 80L);
    }

    public final void K(boolean z10) {
        this.F0.f27180a.setVisibility(0);
        if (!this.I0.isEmpty()) {
            this.J0.notifyDataSetChanged();
        }
        if (z10) {
            J();
        }
    }

    @Override // xyz.stream.view.BaseFragment
    public final void focus() {
        super.focus();
        J();
    }

    @Override // xyz.stream.view.BaseFragment
    public final v3.a getViewBinding(LayoutInflater layoutInflater, ViewGroup viewGroup) {
        return j0.inflate(layoutInflater, viewGroup, false);
    }

    @Override // xyz.stream.api.database.e
    public final void h(String str) {
        UiUtils.dismissProgressDialog();
        Handler handler = this.O0;
        handler.removeCallbacksAndMessages(null);
        handler.post(new d(this, str, 1));
    }

    @Override // xyz.stream.view.BaseFragment
    public final boolean handleBackPressed() {
        g3 g3Var = this.E0;
        if (g3Var == null || this.G0 == null || this.H0 == null || this.F0 == null) {
            return false;
        }
        if (g3Var.f26889a.getVisibility() != 0 && this.G0.f27210a.getVisibility() != 0 && this.H0.f27140a.getVisibility() != 0) {
            return false;
        }
        if (this.E0.f26889a.getVisibility() == 0) {
            y.W(this.E0.f26889a);
        } else if (this.G0.f27210a.getVisibility() == 0) {
            y.W(this.G0.f27210a);
        } else if (this.H0.f27140a.getVisibility() == 0) {
            y.W(this.H0.f27140a);
        }
        y.M(this.F0.f27180a, new a(this, 0));
        return true;
    }

    @Override // xyz.stream.api.database.e
    public final void i(int i10, String str) {
        Handler handler = this.O0;
        if (i10 == 0) {
            handler.post(this.R0);
        }
        handler.post(new androidx.activity.n(this, str, i10, 12));
    }

    @Override // xyz.stream.view.BaseFragment
    public final void initData() {
        super.initData();
        y.M(this.F0.f27180a, null);
        this.E0.f26889a.setVisibility(8);
        this.G0.f27210a.setVisibility(8);
        this.H0.f27140a.setVisibility(8);
        UiUtils.showProgressDialog(requireActivity());
        ((IptvViewModel) this.viewModel).getIptvList(requireActivity());
        ((IptvViewModel) this.viewModel).liveIptvList.c(getViewLifecycleOwner(), new oe.e(this, 1));
    }

    @Override // xyz.stream.view.BaseFragment
    public final void initListener() {
        super.initListener();
        final int i10 = 0;
        this.L0.f26726a.setOnClickListener(new View.OnClickListener(this) { // from class: pe.c

            /* JADX INFO: renamed from: b, reason: collision with root package name */
            public final /* synthetic */ g f31938b;

            {
                this.f31938b = this;
            }

            @Override // android.view.View.OnClickListener
            public final void onClick(View view) {
                int i11 = i10;
                g gVar = this.f31938b;
                switch (i11) {
                    case 0:
                        int i12 = g.S0;
                        gVar.getClass();
                        CheckResultEntity checkResultEntityC = xyz.stream.utils.e.d().c();
                        if (checkResultEntityC == null || checkResultEntityC.getIsPremium() == null || checkResultEntityC.getIsPremium().intValue() != 0) {
                            gVar.Q0 = null;
                            gVar.E0.f26890b.setText("");
                            gVar.E0.f26891c.setText("");
                            gVar.E0.f26890b.setBackgroundResource(R.drawable.shape_radius_white_12);
                            gVar.E0.f26890b.setEnabled(true);
                            y.N(gVar.F0.f27180a);
                            y.V(gVar.E0.f26889a, new a(gVar, 2));
                        } else {
                            y.a0(gVar.requireActivity());
                        }
                        break;
                    case 1:
                        int i13 = g.S0;
                        gVar.getClass();
                        Intent intent = new Intent("android.intent.action.OPEN_DOCUMENT");
                        intent.addCategory("android.intent.category.OPENABLE");
                        intent.setType("*/*");
                        intent.putExtra("android.intent.extra.MIME_TYPES", new String[]{"application/vnd.apple.mpegurl", "application/x-mpegurl", "audio/mpegurl", "audio/x-mpegurl", "text/plain"});
                        intent.addFlags(195);
                        gVar.K0.launch(intent, null);
                        break;
                    case 2:
                        if (gVar.E0.f26890b.getText().toString().isEmpty()) {
                            UiUtils.showTip(gVar.context, gVar.getString(R.string.name_hint));
                            gVar.E0.f26890b.requestFocus();
                        } else if (!gVar.E0.f26891c.getText().toString().isEmpty()) {
                            gVar.M0 = gVar.E0.f26889a;
                            xyz.stream.api.database.f fVarD = xyz.stream.api.database.f.d();
                            Integer num = gVar.Q0;
                            String string = gVar.E0.f26890b.getText().toString();
                            String string2 = gVar.E0.f26891c.getText().toString();
                            fVarD.getClass();
                            String strI = xyz.stream.api.database.f.i(string2);
                            if (strI != null) {
                                HashMap map = new HashMap();
                                boolean zH = xyz.stream.api.database.f.h(strI);
                                ExecutorService executorService = fVarD.f35809b;
                                if (!zH) {
                                    executorService.execute(new p(fVarD, gVar, string, strI, num, new HashMap(map)));
                                } else {
                                    executorService.execute(new xyz.netfly.ads.p(fVarD, strI, gVar, num, string, 5));
                                }
                            } else {
                                gVar.h("Invalid IPTV URL.");
                            }
                        } else {
                            UiUtils.showTip(gVar.context, gVar.getString(R.string.url_hint));
                            gVar.E0.f26891c.requestFocus();
                        }
                        break;
                    default:
                        y.W(gVar.H0.f27140a);
                        y.M(gVar.F0.f27180a, new a(gVar, 1));
                        break;
                }
            }
        });
        final int i11 = 1;
        this.L0.f26726a.setOnKeyListener(new oe.d(this, i11));
        this.J0.f32299c = new oe.g(this, i11);
        this.E0.f26892d.setOnClickListener(new View.OnClickListener(this) { // from class: pe.c

            /* JADX INFO: renamed from: b, reason: collision with root package name */
            public final /* synthetic */ g f31938b;

            {
                this.f31938b = this;
            }

            @Override // android.view.View.OnClickListener
            public final void onClick(View view) {
                int i112 = i11;
                g gVar = this.f31938b;
                switch (i112) {
                    case 0:
                        int i12 = g.S0;
                        gVar.getClass();
                        CheckResultEntity checkResultEntityC = xyz.stream.utils.e.d().c();
                        if (checkResultEntityC == null || checkResultEntityC.getIsPremium() == null || checkResultEntityC.getIsPremium().intValue() != 0) {
                            gVar.Q0 = null;
                            gVar.E0.f26890b.setText("");
                            gVar.E0.f26891c.setText("");
                            gVar.E0.f26890b.setBackgroundResource(R.drawable.shape_radius_white_12);
                            gVar.E0.f26890b.setEnabled(true);
                            y.N(gVar.F0.f27180a);
                            y.V(gVar.E0.f26889a, new a(gVar, 2));
                        } else {
                            y.a0(gVar.requireActivity());
                        }
                        break;
                    case 1:
                        int i13 = g.S0;
                        gVar.getClass();
                        Intent intent = new Intent("android.intent.action.OPEN_DOCUMENT");
                        intent.addCategory("android.intent.category.OPENABLE");
                        intent.setType("*/*");
                        intent.putExtra("android.intent.extra.MIME_TYPES", new String[]{"application/vnd.apple.mpegurl", "application/x-mpegurl", "audio/mpegurl", "audio/x-mpegurl", "text/plain"});
                        intent.addFlags(195);
                        gVar.K0.launch(intent, null);
                        break;
                    case 2:
                        if (gVar.E0.f26890b.getText().toString().isEmpty()) {
                            UiUtils.showTip(gVar.context, gVar.getString(R.string.name_hint));
                            gVar.E0.f26890b.requestFocus();
                        } else if (!gVar.E0.f26891c.getText().toString().isEmpty()) {
                            gVar.M0 = gVar.E0.f26889a;
                            xyz.stream.api.database.f fVarD = xyz.stream.api.database.f.d();
                            Integer num = gVar.Q0;
                            String string = gVar.E0.f26890b.getText().toString();
                            String string2 = gVar.E0.f26891c.getText().toString();
                            fVarD.getClass();
                            String strI = xyz.stream.api.database.f.i(string2);
                            if (strI != null) {
                                HashMap map = new HashMap();
                                boolean zH = xyz.stream.api.database.f.h(strI);
                                ExecutorService executorService = fVarD.f35809b;
                                if (!zH) {
                                    executorService.execute(new p(fVarD, gVar, string, strI, num, new HashMap(map)));
                                } else {
                                    executorService.execute(new xyz.netfly.ads.p(fVarD, strI, gVar, num, string, 5));
                                }
                            } else {
                                gVar.h("Invalid IPTV URL.");
                            }
                        } else {
                            UiUtils.showTip(gVar.context, gVar.getString(R.string.url_hint));
                            gVar.E0.f26891c.requestFocus();
                        }
                        break;
                    default:
                        y.W(gVar.H0.f27140a);
                        y.M(gVar.F0.f27180a, new a(gVar, 1));
                        break;
                }
            }
        });
        final int i12 = 2;
        this.E0.f26893e.setOnClickListener(new View.OnClickListener(this) { // from class: pe.c

            /* JADX INFO: renamed from: b, reason: collision with root package name */
            public final /* synthetic */ g f31938b;

            {
                this.f31938b = this;
            }

            @Override // android.view.View.OnClickListener
            public final void onClick(View view) {
                int i112 = i12;
                g gVar = this.f31938b;
                switch (i112) {
                    case 0:
                        int i122 = g.S0;
                        gVar.getClass();
                        CheckResultEntity checkResultEntityC = xyz.stream.utils.e.d().c();
                        if (checkResultEntityC == null || checkResultEntityC.getIsPremium() == null || checkResultEntityC.getIsPremium().intValue() != 0) {
                            gVar.Q0 = null;
                            gVar.E0.f26890b.setText("");
                            gVar.E0.f26891c.setText("");
                            gVar.E0.f26890b.setBackgroundResource(R.drawable.shape_radius_white_12);
                            gVar.E0.f26890b.setEnabled(true);
                            y.N(gVar.F0.f27180a);
                            y.V(gVar.E0.f26889a, new a(gVar, 2));
                        } else {
                            y.a0(gVar.requireActivity());
                        }
                        break;
                    case 1:
                        int i13 = g.S0;
                        gVar.getClass();
                        Intent intent = new Intent("android.intent.action.OPEN_DOCUMENT");
                        intent.addCategory("android.intent.category.OPENABLE");
                        intent.setType("*/*");
                        intent.putExtra("android.intent.extra.MIME_TYPES", new String[]{"application/vnd.apple.mpegurl", "application/x-mpegurl", "audio/mpegurl", "audio/x-mpegurl", "text/plain"});
                        intent.addFlags(195);
                        gVar.K0.launch(intent, null);
                        break;
                    case 2:
                        if (gVar.E0.f26890b.getText().toString().isEmpty()) {
                            UiUtils.showTip(gVar.context, gVar.getString(R.string.name_hint));
                            gVar.E0.f26890b.requestFocus();
                        } else if (!gVar.E0.f26891c.getText().toString().isEmpty()) {
                            gVar.M0 = gVar.E0.f26889a;
                            xyz.stream.api.database.f fVarD = xyz.stream.api.database.f.d();
                            Integer num = gVar.Q0;
                            String string = gVar.E0.f26890b.getText().toString();
                            String string2 = gVar.E0.f26891c.getText().toString();
                            fVarD.getClass();
                            String strI = xyz.stream.api.database.f.i(string2);
                            if (strI != null) {
                                HashMap map = new HashMap();
                                boolean zH = xyz.stream.api.database.f.h(strI);
                                ExecutorService executorService = fVarD.f35809b;
                                if (!zH) {
                                    executorService.execute(new p(fVarD, gVar, string, strI, num, new HashMap(map)));
                                } else {
                                    executorService.execute(new xyz.netfly.ads.p(fVarD, strI, gVar, num, string, 5));
                                }
                            } else {
                                gVar.h("Invalid IPTV URL.");
                            }
                        } else {
                            UiUtils.showTip(gVar.context, gVar.getString(R.string.url_hint));
                            gVar.E0.f26891c.requestFocus();
                        }
                        break;
                    default:
                        y.W(gVar.H0.f27140a);
                        y.M(gVar.F0.f27180a, new a(gVar, 1));
                        break;
                }
            }
        });
        final int i13 = 3;
        this.H0.f27143d.setOnClickListener(new View.OnClickListener(this) { // from class: pe.c

            /* JADX INFO: renamed from: b, reason: collision with root package name */
            public final /* synthetic */ g f31938b;

            {
                this.f31938b = this;
            }

            @Override // android.view.View.OnClickListener
            public final void onClick(View view) {
                int i112 = i13;
                g gVar = this.f31938b;
                switch (i112) {
                    case 0:
                        int i122 = g.S0;
                        gVar.getClass();
                        CheckResultEntity checkResultEntityC = xyz.stream.utils.e.d().c();
                        if (checkResultEntityC == null || checkResultEntityC.getIsPremium() == null || checkResultEntityC.getIsPremium().intValue() != 0) {
                            gVar.Q0 = null;
                            gVar.E0.f26890b.setText("");
                            gVar.E0.f26891c.setText("");
                            gVar.E0.f26890b.setBackgroundResource(R.drawable.shape_radius_white_12);
                            gVar.E0.f26890b.setEnabled(true);
                            y.N(gVar.F0.f27180a);
                            y.V(gVar.E0.f26889a, new a(gVar, 2));
                        } else {
                            y.a0(gVar.requireActivity());
                        }
                        break;
                    case 1:
                        int i132 = g.S0;
                        gVar.getClass();
                        Intent intent = new Intent("android.intent.action.OPEN_DOCUMENT");
                        intent.addCategory("android.intent.category.OPENABLE");
                        intent.setType("*/*");
                        intent.putExtra("android.intent.extra.MIME_TYPES", new String[]{"application/vnd.apple.mpegurl", "application/x-mpegurl", "audio/mpegurl", "audio/x-mpegurl", "text/plain"});
                        intent.addFlags(195);
                        gVar.K0.launch(intent, null);
                        break;
                    case 2:
                        if (gVar.E0.f26890b.getText().toString().isEmpty()) {
                            UiUtils.showTip(gVar.context, gVar.getString(R.string.name_hint));
                            gVar.E0.f26890b.requestFocus();
                        } else if (!gVar.E0.f26891c.getText().toString().isEmpty()) {
                            gVar.M0 = gVar.E0.f26889a;
                            xyz.stream.api.database.f fVarD = xyz.stream.api.database.f.d();
                            Integer num = gVar.Q0;
                            String string = gVar.E0.f26890b.getText().toString();
                            String string2 = gVar.E0.f26891c.getText().toString();
                            fVarD.getClass();
                            String strI = xyz.stream.api.database.f.i(string2);
                            if (strI != null) {
                                HashMap map = new HashMap();
                                boolean zH = xyz.stream.api.database.f.h(strI);
                                ExecutorService executorService = fVarD.f35809b;
                                if (!zH) {
                                    executorService.execute(new p(fVarD, gVar, string, strI, num, new HashMap(map)));
                                } else {
                                    executorService.execute(new xyz.netfly.ads.p(fVarD, strI, gVar, num, string, 5));
                                }
                            } else {
                                gVar.h("Invalid IPTV URL.");
                            }
                        } else {
                            UiUtils.showTip(gVar.context, gVar.getString(R.string.url_hint));
                            gVar.E0.f26891c.requestFocus();
                        }
                        break;
                    default:
                        y.W(gVar.H0.f27140a);
                        y.M(gVar.F0.f27180a, new a(gVar, 1));
                        break;
                }
            }
        });
    }

    @Override // xyz.stream.view.BaseFragment
    public final void initView() {
        this.L0 = c0.inflate(getLayoutInflater(), null, false);
        j0 j0Var = (j0) this.binding;
        this.E0 = j0Var.f27059b;
        l4 l4Var = j0Var.f27061d;
        this.F0 = l4Var;
        this.G0 = j0Var.f27062e;
        this.H0 = j0Var.f27060c;
        this.M0 = l4Var.f27180a;
        if (xyz.stream.utils.e.d().f36119h) {
            this.E0.f26892d.setVisibility(0);
            UiUtils.setUnFocusable(this.L0.f26726a);
            UiUtils.setUnFocusable(this.E0.f26892d);
            UiUtils.setUnFocusable(this.H0.f27143d);
            UiUtils.setUnFocusable(this.E0.f26893e);
            this.E0.f26893e.setBackgroundResource(R.drawable.shape_login_select);
            this.H0.f27143d.setBackgroundResource(R.drawable.shape_login_select);
        }
        this.F0.f27181b.addItemDecoration(new SpacesItemHorDecoration(25, 0, 0));
        this.F0.f27181b.setSelectedItemAtCentered(true);
        qe.g gVar = new qe.g(this.I0, requireActivity(), this.L0.f26726a);
        this.J0 = gVar;
        this.F0.f27181b.setAdapter(gVar);
    }

    @Override // xyz.stream.api.database.e
    public final void n(ServerEntity serverEntity, int i10) {
        UiUtils.dismissProgressDialog();
        Handler handler = this.O0;
        handler.removeCallbacksAndMessages(null);
        handler.post(new b(this, i10, 1));
        if (serverEntity != null) {
            ((IptvViewModel) this.viewModel).optionIptv(requireActivity(), serverEntity.getServerName(), serverEntity.getRootPath(), false);
        }
    }

    @Override // androidx.fragment.app.e0
    public final void onDestroy() {
        super.onDestroy();
    }

    @Override // xyz.stream.view.BaseFragment
    public final void onInit() {
        super.onInit();
        this.K0 = registerForActivityResult(new b.c(), new com.google.gson.internal.a(this, 16));
    }

    @Override // xyz.stream.api.database.e
    public final void q(String str, String str2, Integer num) {
        UiUtils.dismissProgressDialog();
        Handler handler = this.O0;
        handler.removeCallbacksAndMessages(null);
        handler.post(new androidx.media3.exoplayer.audio.j(this, str2, num, str, 6));
    }
}
