package xyz.stream.view;

import android.app.Activity;
import android.graphics.drawable.ColorDrawable;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;
import androidx.annotation.ColorInt;
import androidx.core.view.m3;
import java.util.ArrayList;
import java.util.Iterator;
import rf.r;
import v3.a;
import xyz.stream.view.BindingDialogBuilder;

/* JADX INFO: loaded from: classes3.dex */
public class BindingDialogBuilder<T extends v3.a> {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final Activity f36204a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final BindingInflater f36205b;

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

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

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

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public Float f36211h;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final ArrayList f36206c = new ArrayList();

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

    public interface BindingInflater<T extends v3.a> {
        T inflate(LayoutInflater layoutInflater);
    }

    public interface DialogClick<T extends v3.a> {
        void onClick(T t10, e.m mVar, View view);
    }

    public static class DialogHandle<T extends v3.a> {
        public final T binding;
        public final e.m dialog;

        /* JADX WARN: Multi-variable type inference failed */
        public DialogHandle(v3.a aVar, e.m mVar) {
            this.binding = aVar;
            this.dialog = mVar;
        }
    }

    public interface DialogSetup<T extends v3.a> {
        void setup(T t10, e.m mVar);
    }

    public interface ViewProvider<T extends v3.a, V extends View> {
        V get(T t10);
    }

    public BindingDialogBuilder(Activity activity, BindingInflater bindingInflater) {
        this.f36204a = activity;
        this.f36205b = bindingInflater;
    }

    public static <T extends v3.a> BindingDialogBuilder<T> with(Activity activity, BindingInflater<T> bindingInflater) {
        return new BindingDialogBuilder<>(activity, bindingInflater);
    }

    public BindingDialogBuilder<T> background(ViewProvider<T, ? extends View> viewProvider, int i10) {
        return setup(new c(viewProvider, i10, 2));
    }

    public BindingDialogBuilder<T> cancelable(boolean z10) {
        this.f36208e = z10;
        return this;
    }

    public BindingDialogBuilder<T> click(ViewProvider<T, ? extends View> viewProvider, DialogClick<T> dialogClick) {
        return setup(new uf.j(viewProvider, dialogClick, 3));
    }

    public BindingDialogBuilder<T> dimAmount(float f10) {
        this.f36211h = Float.valueOf(f10);
        return this;
    }

    public BindingDialogBuilder<T> focus(ViewProvider<T, ? extends View> viewProvider) {
        return setup(new r(viewProvider, 2));
    }

    public BindingDialogBuilder<T> hide(ViewProvider<T, ? extends View> viewProvider) {
        return visibility(viewProvider, 8);
    }

    public BindingDialogBuilder<T> maskOwner(Object obj) {
        this.f36210g = obj;
        return this;
    }

    public BindingDialogBuilder<T> setup(DialogSetup<T> dialogSetup) {
        this.f36206c.add(dialogSetup);
        return this;
    }

    public DialogHandle<T> show() {
        Activity activity = this.f36204a;
        v3.a aVarInflate = this.f36205b.inflate(LayoutInflater.from(activity));
        e.l lVar = new e.l(activity, this.f36207d);
        lVar.setView(aVarInflate.getRoot());
        lVar.f25255a.f25211k = this.f36208e;
        e.m mVarCreate = lVar.create();
        mVarCreate.show();
        DialogHandle<T> dialogHandle = new DialogHandle<>(aVarInflate, mVarCreate);
        Iterator it = this.f36206c.iterator();
        while (it.hasNext()) {
            ((DialogSetup) it.next()).setup(dialogHandle.binding, dialogHandle.dialog);
        }
        if (this.f36209f > 0) {
            e.m mVar = dialogHandle.dialog;
            View root = dialogHandle.binding.getRoot();
            int i10 = this.f36209f;
            Object obj = this.f36210g;
            Float f10 = this.f36211h;
            if (mVar != null && root != null && mVar.getWindow() != null) {
                Window window = mVar.getWindow();
                window.getDecorView().setPadding(0, 0, 0, 0);
                if (obj != null) {
                    MaskOverLay.getInstance().backgroundAlpha(obj, 0.4f);
                    mVar.setOnDismissListener(new xyz.netfly.mobile.view.j(obj, 2));
                }
                if (f10 != null) {
                    window.setDimAmount(f10.floatValue());
                }
                int iApplyDimension = (int) TypedValue.applyDimension(1, i10, root.getResources().getDisplayMetrics());
                WindowManager.LayoutParams attributes = window.getAttributes();
                attributes.width = iApplyDimension;
                attributes.height = -2;
                window.setAttributes(attributes);
                m3 m3Var = new m3(window, window.getDecorView());
                m3Var.a(7);
                m3Var.b();
                window.setBackgroundDrawable(new ColorDrawable(0));
                root.post(new androidx.activity.n(mVar, root, iApplyDimension, 23));
            }
        }
        return dialogHandle;
    }

    public BindingDialogBuilder<T> tablet(boolean z10, DialogSetup<T> dialogSetup) {
        return setup(new uf.i(z10, dialogSetup));
    }

    public BindingDialogBuilder<T> tabletConfirmStyle(boolean z10, final ViewProvider<T, ? extends TextView> viewProvider, final ViewProvider<T, ? extends View> viewProvider2, @ColorInt final int i10, final int i11) {
        return tablet(z10, new DialogSetup() { // from class: xyz.stream.view.a
            @Override // xyz.stream.view.BindingDialogBuilder.DialogSetup
            public final void setup(v3.a aVar, e.m mVar) {
                TextView textView = (TextView) viewProvider.get(aVar);
                UiUtils.setUnFocusable(textView);
                BindingDialogBuilder.ViewProvider viewProvider3 = viewProvider2;
                if (viewProvider3 != null) {
                    UiUtils.setUnFocusable(viewProvider3.get(aVar));
                }
                textView.setTextColor(i10);
                textView.setBackgroundResource(i11);
            }
        });
    }

    public BindingDialogBuilder<T> text(ViewProvider<T, ? extends TextView> viewProvider, CharSequence charSequence) {
        return setup(new uf.j(viewProvider, charSequence, 2));
    }

    public BindingDialogBuilder<T> textColor(ViewProvider<T, ? extends TextView> viewProvider, @ColorInt int i10) {
        return setup(new c(viewProvider, i10, 0));
    }

    public BindingDialogBuilder<T> textColorRes(final ViewProvider<T, ? extends TextView> viewProvider, final int i10) {
        return setup(new DialogSetup() { // from class: xyz.stream.view.b
            @Override // xyz.stream.view.BindingDialogBuilder.DialogSetup
            public final void setup(v3.a aVar, e.m mVar) {
                BindingDialogBuilder bindingDialogBuilder = this.f36469a;
                bindingDialogBuilder.getClass();
                TextView textView = (TextView) viewProvider.get(aVar);
                Object obj = g0.d.f26125a;
                textView.setTextColor(bindingDialogBuilder.f36204a.getColor(i10));
            }
        });
    }

    public BindingDialogBuilder<T> theme(int i10) {
        this.f36207d = i10;
        return this;
    }

    public BindingDialogBuilder<T> visibility(ViewProvider<T, ? extends View> viewProvider, int i10) {
        return setup(new c(viewProvider, i10, 1));
    }

    public BindingDialogBuilder<T> width(int i10) {
        this.f36209f = i10;
        return this;
    }
}
