package h0;

import a.AbstractC0386a;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import androidx.lifecycle.C0520z;
import com.martsnew.tv.R;
import d3.V0;
import d5.AbstractC0844a;
import p.C1406c;
import p.C1409f;

/* JADX INFO: renamed from: h0.q, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public class DialogInterfaceOnCancelListenerC1017q extends ComponentCallbacksC1023x implements DialogInterface.OnCancelListener, DialogInterface.OnDismissListener {

    /* JADX INFO: renamed from: A0, reason: collision with root package name */
    public boolean f13223A0;

    /* JADX INFO: renamed from: B0, reason: collision with root package name */
    public boolean f13224B0;

    /* JADX INFO: renamed from: C0, reason: collision with root package name */
    public boolean f13225C0;

    /* JADX INFO: renamed from: o0, reason: collision with root package name */
    public Handler f13227o0;

    /* JADX INFO: renamed from: x0, reason: collision with root package name */
    public boolean f13235x0;

    /* JADX INFO: renamed from: z0, reason: collision with root package name */
    public Dialog f13237z0;

    /* JADX INFO: renamed from: p0, reason: collision with root package name */
    public final M4.k f13228p0 = new M4.k(22, this);
    public final DialogInterfaceOnCancelListenerC1014n q0 = new DialogInterfaceOnCancelListenerC1014n(this);

    /* JADX INFO: renamed from: r0, reason: collision with root package name */
    public final DialogInterfaceOnDismissListenerC1015o f13229r0 = new DialogInterfaceOnDismissListenerC1015o(this);

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

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

    /* JADX INFO: renamed from: u0, reason: collision with root package name */
    public boolean f13232u0 = true;

    /* JADX INFO: renamed from: v0, reason: collision with root package name */
    public boolean f13233v0 = true;

    /* JADX INFO: renamed from: w0, reason: collision with root package name */
    public int f13234w0 = -1;

    /* JADX INFO: renamed from: y0, reason: collision with root package name */
    public final V0 f13236y0 = new V0(15, this);

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

    @Override // h0.ComponentCallbacksC1023x
    public final void A() {
        this.f13276V = true;
    }

    @Override // h0.ComponentCallbacksC1023x
    public void E(Context context) {
        Object obj;
        super.E(context);
        androidx.lifecycle.A a3 = this.f13287h0;
        a3.getClass();
        androidx.lifecycle.A.a("observeForever");
        V0 v02 = this.f13236y0;
        C0520z c0520z = new C0520z(a3, v02);
        C1409f c1409f = a3.f8748b;
        C1406c c1406cA = c1409f.a(v02);
        if (c1406cA != null) {
            obj = c1406cA.f16012r;
        } else {
            C1406c c1406c = new C1406c(v02, c0520z);
            c1409f.f16021t++;
            C1406c c1406c2 = c1409f.f16019r;
            if (c1406c2 == null) {
                c1409f.f16018q = c1406c;
                c1409f.f16019r = c1406c;
            } else {
                c1406c2.f16013s = c1406c;
                c1406c.f16014t = c1406c2;
                c1409f.f16019r = c1406c;
            }
            obj = null;
        }
        if (((C0520z) obj) == null) {
            c0520z.a(true);
        }
        if (this.f13225C0) {
            return;
        }
        this.f13224B0 = false;
    }

    @Override // h0.ComponentCallbacksC1023x
    public void F(Bundle bundle) {
        super.F(bundle);
        this.f13227o0 = new Handler();
        this.f13233v0 = this.f13270P == 0;
        if (bundle != null) {
            this.f13230s0 = bundle.getInt("android:style", 0);
            this.f13231t0 = bundle.getInt("android:theme", 0);
            this.f13232u0 = bundle.getBoolean("android:cancelable", true);
            this.f13233v0 = bundle.getBoolean("android:showsDialog", this.f13233v0);
            this.f13234w0 = bundle.getInt("android:backStackId", -1);
        }
    }

    @Override // h0.ComponentCallbacksC1023x
    public final void J() {
        this.f13276V = true;
        Dialog dialog = this.f13237z0;
        if (dialog != null) {
            this.f13223A0 = true;
            dialog.setOnDismissListener(null);
            this.f13237z0.dismiss();
            if (!this.f13224B0) {
                onDismiss(this.f13237z0);
            }
            this.f13237z0 = null;
            this.f13226D0 = false;
        }
    }

    @Override // h0.ComponentCallbacksC1023x
    public final void K() {
        this.f13276V = true;
        if (!this.f13225C0 && !this.f13224B0) {
            this.f13224B0 = true;
        }
        androidx.lifecycle.A a3 = this.f13287h0;
        a3.getClass();
        androidx.lifecycle.A.a("removeObserver");
        C0520z c0520z = (C0520z) a3.f8748b.b(this.f13236y0);
        if (c0520z == null) {
            return;
        }
        c0520z.a(false);
    }

    /* JADX WARN: Removed duplicated region for block: B:26:0x0046 A[Catch: all -> 0x004e, TryCatch #0 {all -> 0x004e, blocks: (B:12:0x001a, B:14:0x0026, B:24:0x003e, B:26:0x0046, B:29:0x0050, B:20:0x0030, B:22:0x0036, B:23:0x003b, B:30:0x0068), top: B:49:0x001a }] */
    @Override // h0.ComponentCallbacksC1023x
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public LayoutInflater L(Bundle bundle) {
        Context contextO;
        LayoutInflater layoutInflaterL = super.L(bundle);
        boolean z8 = this.f13233v0;
        if (z8 && !this.f13235x0) {
            if (z8 && !this.f13226D0) {
                try {
                    this.f13235x0 = true;
                    Dialog dialogG0 = g0(bundle);
                    this.f13237z0 = dialogG0;
                    if (this.f13233v0) {
                        int i = this.f13230s0;
                        if (i == 1 || i == 2) {
                            dialogG0.requestWindowFeature(1);
                            contextO = o();
                            if (contextO instanceof Activity) {
                                this.f13237z0.setOwnerActivity((Activity) contextO);
                            }
                            this.f13237z0.setCancelable(this.f13232u0);
                            this.f13237z0.setOnCancelListener(this.q0);
                            this.f13237z0.setOnDismissListener(this.f13229r0);
                            this.f13226D0 = true;
                        } else if (i == 3) {
                            Window window = dialogG0.getWindow();
                            if (window != null) {
                                window.addFlags(24);
                            }
                            dialogG0.requestWindowFeature(1);
                            contextO = o();
                            if (contextO instanceof Activity) {
                            }
                            this.f13237z0.setCancelable(this.f13232u0);
                            this.f13237z0.setOnCancelListener(this.q0);
                            this.f13237z0.setOnDismissListener(this.f13229r0);
                            this.f13226D0 = true;
                        } else {
                            contextO = o();
                            if (contextO instanceof Activity) {
                            }
                            this.f13237z0.setCancelable(this.f13232u0);
                            this.f13237z0.setOnCancelListener(this.q0);
                            this.f13237z0.setOnDismissListener(this.f13229r0);
                            this.f13226D0 = true;
                        }
                    } else {
                        this.f13237z0 = null;
                    }
                    this.f13235x0 = false;
                } catch (Throwable th) {
                    this.f13235x0 = false;
                    throw th;
                }
            }
            if (P.L(2)) {
                Log.d("FragmentManager", "get layout inflater for DialogFragment " + this + " from dialog context");
            }
            Dialog dialog = this.f13237z0;
            if (dialog != null) {
                return layoutInflaterL.cloneInContext(dialog.getContext());
            }
        } else if (P.L(2)) {
            String str = "getting layout inflater for DialogFragment " + this;
            if (!this.f13233v0) {
                Log.d("FragmentManager", "mShowsDialog = false: " + str);
                return layoutInflaterL;
            }
            Log.d("FragmentManager", "mCreatingDialog = true: " + str);
        }
        return layoutInflaterL;
    }

    @Override // h0.ComponentCallbacksC1023x
    public void R(Bundle bundle) {
        Dialog dialog = this.f13237z0;
        if (dialog != null) {
            Bundle bundleOnSaveInstanceState = dialog.onSaveInstanceState();
            bundleOnSaveInstanceState.putBoolean("android:dialogShowing", false);
            bundle.putBundle("android:savedDialogState", bundleOnSaveInstanceState);
        }
        int i = this.f13230s0;
        if (i != 0) {
            bundle.putInt("android:style", i);
        }
        int i5 = this.f13231t0;
        if (i5 != 0) {
            bundle.putInt("android:theme", i5);
        }
        boolean z8 = this.f13232u0;
        if (!z8) {
            bundle.putBoolean("android:cancelable", z8);
        }
        boolean z9 = this.f13233v0;
        if (!z9) {
            bundle.putBoolean("android:showsDialog", z9);
        }
        int i8 = this.f13234w0;
        if (i8 != -1) {
            bundle.putInt("android:backStackId", i8);
        }
    }

    @Override // h0.ComponentCallbacksC1023x
    public void S() {
        this.f13276V = true;
        Dialog dialog = this.f13237z0;
        if (dialog != null) {
            this.f13223A0 = false;
            dialog.show();
            View decorView = this.f13237z0.getWindow().getDecorView();
            P6.g.e(decorView, "<this>");
            decorView.setTag(R.id.view_tree_lifecycle_owner, this);
            decorView.setTag(R.id.view_tree_view_model_store_owner, this);
            decorView.setTag(R.id.view_tree_saved_state_registry_owner, this);
        }
    }

    @Override // h0.ComponentCallbacksC1023x
    public void T() {
        this.f13276V = true;
        Dialog dialog = this.f13237z0;
        if (dialog != null) {
            dialog.hide();
        }
    }

    @Override // h0.ComponentCallbacksC1023x
    public final void V(Bundle bundle) {
        Bundle bundle2;
        this.f13276V = true;
        if (this.f13237z0 == null || bundle == null || (bundle2 = bundle.getBundle("android:savedDialogState")) == null) {
            return;
        }
        this.f13237z0.onRestoreInstanceState(bundle2);
    }

    @Override // h0.ComponentCallbacksC1023x
    public final void W(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        Bundle bundle2;
        super.W(layoutInflater, viewGroup, bundle);
        if (this.X != null || this.f13237z0 == null || bundle == null || (bundle2 = bundle.getBundle("android:savedDialogState")) == null) {
            return;
        }
        this.f13237z0.onRestoreInstanceState(bundle2);
    }

    public final void f0(boolean z8, boolean z9) {
        if (this.f13224B0) {
            return;
        }
        this.f13224B0 = true;
        this.f13225C0 = false;
        Dialog dialog = this.f13237z0;
        if (dialog != null) {
            dialog.setOnDismissListener(null);
            this.f13237z0.dismiss();
            if (!z9) {
                if (Looper.myLooper() == this.f13227o0.getLooper()) {
                    onDismiss(this.f13237z0);
                } else {
                    this.f13227o0.post(this.f13228p0);
                }
            }
        }
        this.f13223A0 = true;
        if (this.f13234w0 >= 0) {
            P pQ = q();
            int i = this.f13234w0;
            if (i < 0) {
                throw new IllegalArgumentException(AbstractC0844a.j("Bad id: ", i));
            }
            pQ.x(new M(pQ, null, i), z8);
            this.f13234w0 = -1;
            return;
        }
        C1001a c1001a = new C1001a(q());
        c1001a.f13158p = true;
        P p3 = this.f13265K;
        if (p3 != null && p3 != c1001a.f13160r) {
            throw new IllegalStateException("Cannot remove Fragment attached to a different FragmentManager. Fragment " + toString() + " is already attached to a FragmentManager.");
        }
        c1001a.b(new X(3, this));
        if (z8) {
            c1001a.g(true, true);
        } else {
            c1001a.f();
        }
    }

    public Dialog g0(Bundle bundle) {
        if (P.L(3)) {
            Log.d("FragmentManager", "onCreateDialog called for DialogFragment " + this);
        }
        return new d.n(Z(), this.f13231t0);
    }

    public final Dialog h0() {
        Dialog dialog = this.f13237z0;
        if (dialog != null) {
            return dialog;
        }
        throw new IllegalStateException("DialogFragment " + this + " does not have a Dialog.");
    }

    public void i0(P p3, String str) {
        this.f13224B0 = false;
        this.f13225C0 = true;
        p3.getClass();
        C1001a c1001a = new C1001a(p3);
        c1001a.f13158p = true;
        c1001a.h(0, this, str, 1);
        c1001a.f();
    }

    @Override // h0.ComponentCallbacksC1023x
    public final AbstractC0386a j() {
        return new C1016p(this, new C1019t(this));
    }

    public void onDismiss(DialogInterface dialogInterface) {
        if (this.f13223A0) {
            return;
        }
        if (P.L(3)) {
            Log.d("FragmentManager", "onDismiss called for DialogFragment " + this);
        }
        f0(true, true);
    }

    public void onCancel(DialogInterface dialogInterface) {
    }
}
