package com.vinfast.companion.core.base.ui.widget;

/* JADX INFO: compiled from: r8-map-id-ae6aab8d9a1033945587ffdd1bc6222159522c1d66e66a2c4cecb065134dd0a6 */
/* JADX INFO: loaded from: E:\ios\vf_dex\classes15.dex */
@kotlin.Metadata(d1 = {"\u0000>\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0010\b\n\u0002\b\u0002\n\u0002\u0010\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0004\n\u0002\u0018\u0002\n\u0002\b\u0006\n\u0002\u0018\u0002\n\u0002\b\u001d\u0018\u00002\u00020\u0001:\u00016B\u001b\b\u0016\u0012\u0006\u0010\u0003\u001a\u00020\u0002\u0012\b\u0010\u0005\u001a\u0004\u0018\u00010\u0004¢\u0006\u0004\b\u0006\u0010\u0007B#\b\u0016\u0012\u0006\u0010\u0003\u001a\u00020\u0002\u0012\b\u0010\u0005\u001a\u0004\u0018\u00010\u0004\u0012\u0006\u0010\t\u001a\u00020\b¢\u0006\u0004\b\u0006\u0010\nJ\u0017\u0010\f\u001a\u00020\u000b2\u0006\u0010\u0003\u001a\u00020\u0002H\u0002¢\u0006\u0004\b\f\u0010\rJ\u0011\u0010\u000f\u001a\u0004\u0018\u00010\u000eH\u0002¢\u0006\u0004\b\u000f\u0010\u0010J\u000f\u0010\u0011\u001a\u00020\u000bH\u0002¢\u0006\u0004\b\u0011\u0010\u0012J\u0017\u0010\u0015\u001a\u00020\u000b2\b\u0010\u0014\u001a\u0004\u0018\u00010\u0013¢\u0006\u0004\b\u0015\u0010\u0016J\u0015\u0010\u0018\u001a\u00020\u000b2\u0006\u0010\u0017\u001a\u00020\b¢\u0006\u0004\b\u0018\u0010\u0019J\u0017\u0010\u001c\u001a\u00020\u000b2\b\u0010\u001b\u001a\u0004\u0018\u00010\u001a¢\u0006\u0004\b\u001c\u0010\u001dR\u0018\u0010 \u001a\u0004\u0018\u00010\u00028\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\b\u001e\u0010\u001fR\u0016\u0010#\u001a\u00020\b8\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\b!\u0010\"R\u0016\u0010%\u001a\u00020\b8\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\b$\u0010\"R\u0016\u0010'\u001a\u00020\b8\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\b&\u0010\"R\u0016\u0010)\u001a\u00020\b8\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\b(\u0010\"R\u0016\u0010+\u001a\u00020\b8\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\b*\u0010\"R\u0018\u0010.\u001a\u0004\u0018\u00010\u00138\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\b,\u0010-R\u0016\u00100\u001a\u00020\b8\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\b/\u0010\"R\u0018\u00103\u001a\u0004\u0018\u00010\u001a8\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\b1\u00102R\u0018\u00105\u001a\u0004\u0018\u00010\u00138\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\b4\u0010-¨\u00067"}, d2 = {"Lcom/vinfast/companion/core/base/ui/widget/AboveOnKeyboardLayout;", "Landroid/widget/RelativeLayout;", "Landroid/content/Context;", "context", "Landroid/util/AttributeSet;", "attrs", "<init>", "(Landroid/content/Context;Landroid/util/AttributeSet;)V", "", "defStyleAttr", "(Landroid/content/Context;Landroid/util/AttributeSet;I)V", "", "q", "(Landroid/content/Context;)V", "Landroid/app/Activity;", "getActivity", "()Landroid/app/Activity;", "s", "()V", "Landroid/view/View;", "anchorView", "setAnchor", "(Landroid/view/View;)V", "margin", "setMarginKeyboard", "(I)V", "Lcom/vinfast/companion/core/base/ui/widget/AboveOnKeyboardLayout$KeyboardShowHideListener;", "listener", "setKeyboardShowHideListener", "(Lcom/vinfast/companion/core/base/ui/widget/AboveOnKeyboardLayout$KeyboardShowHideListener;)V", "a", "Landroid/content/Context;", "mContext", "b", "I", "mOldKeyboardHeight", "c", "mNowKeyboardHeight", "d", "mScreenHeight", "e", "viewParamHeight", "f", "viewAnchorMarginBottom", "g", "Landroid/view/View;", "mAnchor", "h", "mMarginKeyboard", "i", "Lcom/vinfast/companion/core/base/ui/widget/AboveOnKeyboardLayout$KeyboardShowHideListener;", "mListener", "j", "viewBottom", "KeyboardShowHideListener", "core_release"}, k = 1, mv = {2, 2, 0}, xi = 48)
public final class AboveOnKeyboardLayout extends android.widget.RelativeLayout {

    /* JADX INFO: renamed from: a, reason: from kotlin metadata */
    private android.content.Context mContext;

    /* JADX INFO: renamed from: b, reason: from kotlin metadata */
    private int mOldKeyboardHeight;

    /* JADX INFO: renamed from: c, reason: from kotlin metadata */
    private int mNowKeyboardHeight;

    /* JADX INFO: renamed from: d, reason: from kotlin metadata */
    private int mScreenHeight;

    /* JADX INFO: renamed from: e, reason: from kotlin metadata */
    private int viewParamHeight;

    /* JADX INFO: renamed from: f, reason: from kotlin metadata */
    private int viewAnchorMarginBottom;

    /* JADX INFO: renamed from: g, reason: from kotlin metadata */
    private android.view.View mAnchor;

    /* JADX INFO: renamed from: h, reason: from kotlin metadata */
    private int mMarginKeyboard;

    /* JADX INFO: renamed from: i, reason: from kotlin metadata */
    private com.vinfast.companion.core.base.ui.widget.AboveOnKeyboardLayout.KeyboardShowHideListener mListener;

    /* JADX INFO: renamed from: j, reason: from kotlin metadata */
    private android.view.View viewBottom;

    /* JADX INFO: compiled from: r8-map-id-ae6aab8d9a1033945587ffdd1bc6222159522c1d66e66a2c4cecb065134dd0a6 */
    @kotlin.Metadata(d1 = {"\u0000\u0016\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\u0010\u000b\n\u0000\n\u0002\u0010\u0002\n\u0002\b\u0003\bf\u0018\u00002\u00020\u0001J\u0017\u0010\u0005\u001a\u00020\u00042\u0006\u0010\u0003\u001a\u00020\u0002H&¢\u0006\u0004\b\u0005\u0010\u0006¨\u0006\u0007À\u0006\u0003"}, d2 = {"Lcom/vinfast/companion/core/base/ui/widget/AboveOnKeyboardLayout$KeyboardShowHideListener;", "", "", "isShow", "", "a", "(Z)V", "core_release"}, k = 1, mv = {2, 2, 0}, xi = 48)
    public interface KeyboardShowHideListener {
        void a(boolean isShow);
    }

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public AboveOnKeyboardLayout(@org.jetbrains.annotations.NotNull android.content.Context context, @org.jetbrains.annotations.Nullable android.util.AttributeSet attributeSet) {
        super(context, attributeSet);
        kotlin.jvm.internal.Intrinsics.l(context, "context");
        this.mOldKeyboardHeight = -1;
        this.mNowKeyboardHeight = -1;
        q(context);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final android.app.Activity getActivity() {
        for (android.content.Context baseContext = this.mContext; baseContext instanceof android.content.ContextWrapper; baseContext = ((android.content.ContextWrapper) baseContext).getBaseContext()) {
            if (baseContext instanceof android.app.Activity) {
                return (android.app.Activity) baseContext;
            }
        }
        return null;
    }

    private final void q(android.content.Context context) {
        setFitsSystemWindows(false);
        this.mContext = context;
        this.mMarginKeyboard = context.getResources().getDimensionPixelSize(com.vinfast.companion.core.R.dimen.dimen8dp);
        android.widget.RelativeLayout.LayoutParams layoutParams = new android.widget.RelativeLayout.LayoutParams(-1, -2);
        layoutParams.addRule(12, 1);
        android.view.View view = new android.view.View(context);
        this.viewBottom = view;
        addView(view, layoutParams);
        s();
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final kotlin.Unit r(com.vinfast.companion.core.base.ui.widget.AboveOnKeyboardLayout aboveOnKeyboardLayout, android.view.View view) {
        kotlin.jvm.internal.Intrinsics.l(view, "it");
        android.view.ViewGroup.LayoutParams layoutParams = aboveOnKeyboardLayout.getLayoutParams();
        layoutParams.height = aboveOnKeyboardLayout.viewParamHeight - aboveOnKeyboardLayout.viewAnchorMarginBottom;
        aboveOnKeyboardLayout.setLayoutParams(layoutParams);
        return kotlin.Unit.a;
    }

    private final void s() {
        getViewTreeObserver().addOnGlobalLayoutListener(new android.view.ViewTreeObserver.OnGlobalLayoutListener() { // from class: com.vinfast.companion.core.base.ui.widget.AboveOnKeyboardLayout$setSoftKeyboardListener$1
            private final void a() {
                if (this.a.mNowKeyboardHeight <= 0) {
                    if (this.a.viewParamHeight != 0) {
                        android.view.ViewGroup.LayoutParams layoutParams = this.a.getLayoutParams();
                        timber.log.Timber.a.a("Height of param: OldHeight: " + layoutParams.height + " --- NewHeight: " + this.a.viewParamHeight, new java.lang.Object[0]);
                        layoutParams.height = this.a.viewParamHeight;
                        this.a.setLayoutParams(layoutParams);
                    }
                    if (this.a.mListener != null) {
                        com.vinfast.companion.core.base.ui.widget.AboveOnKeyboardLayout.KeyboardShowHideListener keyboardShowHideListener = this.a.mListener;
                        kotlin.jvm.internal.Intrinsics.i(keyboardShowHideListener);
                        keyboardShowHideListener.a(false);
                        return;
                    }
                    return;
                }
                android.view.ViewGroup.LayoutParams layoutParams2 = this.a.getLayoutParams();
                if (this.a.viewParamHeight == 0) {
                    com.vinfast.companion.core.base.ui.widget.AboveOnKeyboardLayout aboveOnKeyboardLayout = this.a;
                    aboveOnKeyboardLayout.viewParamHeight = aboveOnKeyboardLayout.getHeight();
                }
                int i = ((this.a.viewParamHeight - this.a.mNowKeyboardHeight) + this.a.viewAnchorMarginBottom) - this.a.mMarginKeyboard;
                timber.log.Timber.a.a("Height of param: OldHeight: " + layoutParams2.height + " --- NewHeight: " + i, new java.lang.Object[0]);
                layoutParams2.height = i;
                this.a.setLayoutParams(layoutParams2);
                if (this.a.mListener != null) {
                    com.vinfast.companion.core.base.ui.widget.AboveOnKeyboardLayout.KeyboardShowHideListener keyboardShowHideListener2 = this.a.mListener;
                    kotlin.jvm.internal.Intrinsics.i(keyboardShowHideListener2);
                    keyboardShowHideListener2.a(true);
                }
            }

            private final void b() {
                if (this.a.mOldKeyboardHeight != -1 || this.a.mAnchor == null) {
                    return;
                }
                int[] iArr = new int[2];
                android.view.View view = this.a.mAnchor;
                kotlin.jvm.internal.Intrinsics.i(view);
                view.getLocationInWindow(iArr);
                int i = iArr[1];
                android.view.View view2 = this.a.mAnchor;
                kotlin.jvm.internal.Intrinsics.i(view2);
                int height = i + view2.getHeight();
                android.view.View view3 = this.a.viewBottom;
                if (view3 != null) {
                    view3.getLocationInWindow(iArr);
                }
                int i2 = iArr[1];
                android.view.View view4 = this.a.viewBottom;
                kotlin.jvm.internal.Intrinsics.i(view4);
                int height2 = i2 + view4.getHeight();
                com.vinfast.companion.core.base.ui.widget.AboveOnKeyboardLayout aboveOnKeyboardLayout = this.a;
                aboveOnKeyboardLayout.viewAnchorMarginBottom = (height2 - height) + aboveOnKeyboardLayout.getPaddingBottom();
            }

            @Override // android.view.ViewTreeObserver.OnGlobalLayoutListener
            public void onGlobalLayout() {
                android.view.Window window;
                android.view.View decorView;
                if (this.a.viewParamHeight == 0) {
                    com.vinfast.companion.core.base.ui.widget.AboveOnKeyboardLayout aboveOnKeyboardLayout = this.a;
                    aboveOnKeyboardLayout.viewParamHeight = aboveOnKeyboardLayout.getHeight();
                }
                b();
                android.graphics.Rect rect = new android.graphics.Rect();
                android.app.Activity activity = this.a.getActivity();
                if (activity != null && (window = activity.getWindow()) != null && (decorView = window.getDecorView()) != null) {
                    decorView.getWindowVisibleDisplayFrame(rect);
                }
                if (this.a.mScreenHeight == 0) {
                    this.a.mScreenHeight = rect.bottom;
                }
                com.vinfast.companion.core.base.ui.widget.AboveOnKeyboardLayout aboveOnKeyboardLayout2 = this.a;
                aboveOnKeyboardLayout2.mNowKeyboardHeight = aboveOnKeyboardLayout2.mScreenHeight - rect.bottom;
                if (this.a.mOldKeyboardHeight != -1 && this.a.mNowKeyboardHeight != this.a.mOldKeyboardHeight) {
                    a();
                }
                com.vinfast.companion.core.base.ui.widget.AboveOnKeyboardLayout aboveOnKeyboardLayout3 = this.a;
                aboveOnKeyboardLayout3.mOldKeyboardHeight = aboveOnKeyboardLayout3.mNowKeyboardHeight;
            }
        });
    }

    public final void setAnchor(@org.jetbrains.annotations.Nullable android.view.View anchorView) {
        this.mAnchor = anchorView;
        if (anchorView != null) {
            com.vinfast.companion.core.extensions.ViewExtensionKt.G(anchorView, new kotlin.jvm.functions.Function1() { // from class: com.vinfast.companion.core.base.ui.widget.a
                public final java.lang.Object invoke(java.lang.Object obj) {
                    return com.vinfast.companion.core.base.ui.widget.AboveOnKeyboardLayout.r(this.a, (android.view.View) obj);
                }
            });
        }
    }

    public final void setKeyboardShowHideListener(@org.jetbrains.annotations.Nullable com.vinfast.companion.core.base.ui.widget.AboveOnKeyboardLayout.KeyboardShowHideListener listener) {
        this.mListener = listener;
    }

    public final void setMarginKeyboard(int margin) {
        this.mMarginKeyboard = margin;
    }

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public AboveOnKeyboardLayout(@org.jetbrains.annotations.NotNull android.content.Context context, @org.jetbrains.annotations.Nullable android.util.AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        kotlin.jvm.internal.Intrinsics.l(context, "context");
        this.mOldKeyboardHeight = -1;
        this.mNowKeyboardHeight = -1;
        q(context);
    }
}
