package vn.vinfast.charginguikit.ui.views.battery;

/* JADX INFO: compiled from: r8-map-id-ae6aab8d9a1033945587ffdd1bc6222159522c1d66e66a2c4cecb065134dd0a6 */
/* JADX INFO: loaded from: E:\ios\vf_dex\classes6.dex */
@kotlin.Metadata(d1 = {"\u0000<\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\b\n\u0002\b\u0004\n\u0002\u0010\u0002\n\u0002\b\u0010\n\u0002\u0010\u000b\n\u0002\b\u0007\n\u0002\u0018\u0002\n\u0002\b\n\n\u0002\u0018\u0002\n\u0002\b\u000b\u0018\u0000 \u00162\u00020\u0001:\u00019B'\b\u0007\u0012\u0006\u0010\u0003\u001a\u00020\u0002\u0012\n\b\u0002\u0010\u0005\u001a\u0004\u0018\u00010\u0004\u0012\b\b\u0002\u0010\u0007\u001a\u00020\u0006¢\u0006\u0004\b\b\u0010\tJ\u0017\u0010\f\u001a\u00020\u000b2\u0006\u0010\n\u001a\u00020\u0006H\u0002¢\u0006\u0004\b\f\u0010\rJ\u000f\u0010\u000e\u001a\u00020\u000bH\u0002¢\u0006\u0004\b\u000e\u0010\u000fJ\u000f\u0010\u0010\u001a\u00020\u000bH\u0002¢\u0006\u0004\b\u0010\u0010\u000fJ\u000f\u0010\u0011\u001a\u00020\u0006H\u0002¢\u0006\u0004\b\u0011\u0010\u0012J\u000f\u0010\u0013\u001a\u00020\u000bH\u0002¢\u0006\u0004\b\u0013\u0010\u000fJ\u000f\u0010\u0014\u001a\u00020\u000bH\u0003¢\u0006\u0004\b\u0014\u0010\u000fJ\u0017\u0010\u0016\u001a\u00020\u000b2\u0006\u0010\u0015\u001a\u00020\u0006H\u0002¢\u0006\u0004\b\u0016\u0010\rJ\u0017\u0010\u0018\u001a\u00020\u000b2\u0006\u0010\u0017\u001a\u00020\u0006H\u0002¢\u0006\u0004\b\u0018\u0010\rJ\r\u0010\u0019\u001a\u00020\u0006¢\u0006\u0004\b\u0019\u0010\u0012J\u0017\u0010\u001b\u001a\u00020\u000b2\u0006\u0010\u001a\u001a\u00020\u0006H\u0007¢\u0006\u0004\b\u001b\u0010\rJ7\u0010\"\u001a\u00020\u000b2\u0006\u0010\u001d\u001a\u00020\u001c2\u0006\u0010\u001e\u001a\u00020\u00062\u0006\u0010\u001f\u001a\u00020\u00062\u0006\u0010 \u001a\u00020\u00062\u0006\u0010!\u001a\u00020\u0006H\u0014¢\u0006\u0004\b\"\u0010#R\u0018\u0010'\u001a\u0004\u0018\u00010$8\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\b%\u0010&R\u0016\u0010)\u001a\u00020\u001c8\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\b\u0018\u0010(R\u0016\u0010\u001a\u001a\u00020\u00068\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\b\u0014\u0010*R\u0016\u0010,\u001a\u00020\u00068\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\b+\u0010*R\u0016\u0010-\u001a\u00020\u001c8\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\b\u0013\u0010(R\u0016\u0010.\u001a\u00020\u00068\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\b\u0010\u0010*R*\u00105\u001a\n\u0012\u0004\u0012\u00020\u000b\u0018\u00010/8\u0006@\u0006X\u0086\u000e¢\u0006\u0012\n\u0004\b\u000e\u00100\u001a\u0004\b1\u00102\"\u0004\b3\u00104R\u0014\u00108\u001a\u00020$8BX\u0082\u0004¢\u0006\u0006\u001a\u0004\b6\u00107¨\u0006:"}, d2 = {"Lvn/vinfast/charginguikit/ui/views/battery/BatteryReminderView;", "Landroid/widget/FrameLayout;", "Landroid/content/Context;", "context", "Landroid/util/AttributeSet;", "attrs", "", "defStyleAttr", "<init>", "(Landroid/content/Context;Landroid/util/AttributeSet;I)V", "percent", "", "setTextForShowPercent", "(I)V", "g", "()V", "f", "getBatteryWidth", "()I", "e", "c", "perPercentSize", "h", "marginX", "b", "getValueReminder", "batteryPercent", "setBatteryPercent", "", "changed", "left", "top", "right", "bottom", "onLayout", "(ZIIII)V", "Lvn/vinfast/charginguikit/databinding/ViewBatteryReminderBinding;", "a", "Lvn/vinfast/charginguikit/databinding/ViewBatteryReminderBinding;", "_binding", "Z", "isLayout", "I", "d", "percentReminder", "shouldShowWarning", "_xDelta", "Lkotlin/Function0;", "Lkotlin/jvm/functions/Function0;", "getHandleShowWarning", "()Lkotlin/jvm/functions/Function0;", "setHandleShowWarning", "(Lkotlin/jvm/functions/Function0;)V", "handleShowWarning", "getViewBinding", "()Lvn/vinfast/charginguikit/databinding/ViewBatteryReminderBinding;", "viewBinding", "Companion", "chargingkitui_release"}, k = 1, mv = {2, 2, 0}, xi = 48)
public final class BatteryReminderView extends android.widget.FrameLayout {
    private static float i = com.vinfast.companion.core.utils.DimensionUtils.a.a(303.0f);

    /* JADX INFO: renamed from: a, reason: from kotlin metadata */
    private vn.vinfast.charginguikit.databinding.ViewBatteryReminderBinding _binding;

    /* JADX INFO: renamed from: b, reason: from kotlin metadata */
    private boolean isLayout;

    /* JADX INFO: renamed from: c, reason: from kotlin metadata */
    private int batteryPercent;

    /* JADX INFO: renamed from: d, reason: from kotlin metadata */
    private int percentReminder;

    /* JADX INFO: renamed from: e, reason: from kotlin metadata */
    private boolean shouldShowWarning;

    /* JADX INFO: renamed from: f, reason: from kotlin metadata */
    private int _xDelta;

    /* JADX INFO: renamed from: g, reason: from kotlin metadata */
    private kotlin.jvm.functions.Function0 handleShowWarning;

    /* JADX WARN: 'this' call moved to the top of the method (can break code semantics) */
    @kotlin.jvm.JvmOverloads
    public BatteryReminderView(@org.jetbrains.annotations.NotNull android.content.Context context) {
        this(context, null, 0, 6, null);
        kotlin.jvm.internal.Intrinsics.l(context, "context");
    }

    private final void b(int marginX) {
        int i2 = (int) (i / 20);
        this.percentReminder = (marginX / i2) * 5;
        h(i2);
    }

    private final void c() {
        getViewBinding().d.setOnTouchListener(new android.view.View.OnTouchListener() { // from class: vn.vinfast.charginguikit.ui.views.battery.d
            @Override // android.view.View.OnTouchListener
            public final boolean onTouch(android.view.View view, android.view.MotionEvent motionEvent) {
                return vn.vinfast.charginguikit.ui.views.battery.BatteryReminderView.d(this.a, view, motionEvent);
            }
        });
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final boolean d(vn.vinfast.charginguikit.ui.views.battery.BatteryReminderView batteryReminderView, android.view.View view, android.view.MotionEvent motionEvent) {
        int batteryWidth;
        int rawX = (int) motionEvent.getRawX();
        int action = motionEvent.getAction();
        if (action == 0) {
            androidx.appcompat.widget.LinearLayoutCompat.LayoutParams layoutParams = view.getLayoutParams();
            kotlin.jvm.internal.Intrinsics.j(layoutParams, "null cannot be cast to non-null type androidx.appcompat.widget.LinearLayoutCompat.LayoutParams");
            batteryReminderView._xDelta = rawX - ((android.widget.LinearLayout.LayoutParams) layoutParams).leftMargin;
            timber.log.Timber.Forest forest = timber.log.Timber.a;
            forest.j("ACTION_DOWN X " + rawX, new java.lang.Object[0]);
            forest.j("ACTION_DOWN _xDelta " + batteryReminderView._xDelta, new java.lang.Object[0]);
        } else if (action != 1) {
            if (action == 2) {
                if (rawX - batteryReminderView._xDelta < batteryReminderView.getBatteryWidth()) {
                    batteryReminderView.shouldShowWarning = true;
                    batteryWidth = batteryReminderView.getBatteryWidth();
                } else {
                    int i2 = batteryReminderView._xDelta;
                    float f = rawX - i2;
                    float f2 = i;
                    if (f > f2) {
                        batteryReminderView.shouldShowWarning = false;
                        batteryWidth = (int) f2;
                    } else {
                        batteryReminderView.shouldShowWarning = false;
                        batteryWidth = rawX - i2;
                    }
                }
                timber.log.Timber.a.j("ACTION_MOVE _xDelta " + (rawX - batteryReminderView._xDelta), new java.lang.Object[0]);
                batteryReminderView.b(batteryWidth);
            }
        } else if (batteryReminderView.shouldShowWarning) {
            kotlin.jvm.functions.Function0 function0 = batteryReminderView.handleShowWarning;
            if (function0 != null) {
                function0.invoke();
            }
            batteryReminderView.shouldShowWarning = false;
        }
        return true;
    }

    private final void e() {
        androidx.appcompat.widget.LinearLayoutCompat.LayoutParams layoutParams = new androidx.appcompat.widget.LinearLayoutCompat.LayoutParams(-2, -2);
        layoutParams.setMarginStart(getBatteryWidth());
        getViewBinding().d.setLayoutParams(layoutParams);
        androidx.appcompat.widget.LinearLayoutCompat.LayoutParams layoutParams2 = new androidx.appcompat.widget.LinearLayoutCompat.LayoutParams(-2, -2);
        layoutParams2.setMarginStart(getBatteryWidth());
        ((android.widget.LinearLayout.LayoutParams) layoutParams2).bottomMargin = (int) com.vinfast.companion.core.utils.DimensionUtils.a.a(4.0f);
        getViewBinding().e.setLayoutParams(layoutParams2);
    }

    private final void f() {
        int height = getViewBinding().f.getHeight();
        int batteryWidth = getBatteryWidth();
        if (this.batteryPercent > 95) {
            getViewBinding().g.setBackgroundResource(vn.vinfast.charginguikit.R.drawable.bg_gradient_reminder_full);
        } else {
            getViewBinding().g.setBackgroundResource(vn.vinfast.charginguikit.R.drawable.bg_gradient_reminder);
        }
        getViewBinding().g.setLayoutParams(new android.widget.FrameLayout.LayoutParams(batteryWidth, height));
        e();
    }

    private final void g() {
        androidx.appcompat.widget.LinearLayoutCompat.LayoutParams layoutParams = new androidx.appcompat.widget.LinearLayoutCompat.LayoutParams(-2, -2);
        layoutParams.setMarginStart(getViewBinding().d.getWidth() / 2);
        layoutParams.setMarginEnd(getViewBinding().d.getWidth() / 2);
        getViewBinding().b.setLayoutParams(layoutParams);
    }

    private final int getBatteryWidth() {
        int i2 = this.batteryPercent;
        return i2 > 95 ? getViewBinding().c.getWidth() : (int) ((i * i2) / 100);
    }

    private final vn.vinfast.charginguikit.databinding.ViewBatteryReminderBinding getViewBinding() {
        vn.vinfast.charginguikit.databinding.ViewBatteryReminderBinding viewBatteryReminderBinding = this._binding;
        kotlin.jvm.internal.Intrinsics.i(viewBatteryReminderBinding);
        return viewBatteryReminderBinding;
    }

    private final void h(int perPercentSize) {
        setTextForShowPercent(this.percentReminder);
        int i2 = (this.percentReminder / 5) * perPercentSize;
        androidx.appcompat.widget.LinearLayoutCompat.LayoutParams layoutParams = getViewBinding().d.getLayoutParams();
        kotlin.jvm.internal.Intrinsics.j(layoutParams, "null cannot be cast to non-null type androidx.appcompat.widget.LinearLayoutCompat.LayoutParams");
        androidx.appcompat.widget.LinearLayoutCompat.LayoutParams layoutParams2 = layoutParams;
        ((android.widget.LinearLayout.LayoutParams) layoutParams2).leftMargin = i2;
        getViewBinding().d.setLayoutParams(layoutParams2);
        androidx.appcompat.widget.LinearLayoutCompat.LayoutParams layoutParams3 = getViewBinding().e.getLayoutParams();
        kotlin.jvm.internal.Intrinsics.j(layoutParams3, "null cannot be cast to non-null type androidx.appcompat.widget.LinearLayoutCompat.LayoutParams");
        androidx.appcompat.widget.LinearLayoutCompat.LayoutParams layoutParams4 = layoutParams3;
        ((android.widget.LinearLayout.LayoutParams) layoutParams4).leftMargin = i2;
        getViewBinding().e.setLayoutParams(layoutParams4);
        getViewBinding().f.setProgress(this.percentReminder);
    }

    private final void setTextForShowPercent(int percent) {
        getViewBinding().e.setText(percent + "%");
    }

    @org.jetbrains.annotations.Nullable
    public final kotlin.jvm.functions.Function0<kotlin.Unit> getHandleShowWarning() {
        return this.handleShowWarning;
    }

    public final int getValueReminder() {
        int i2 = this.percentReminder;
        return (i2 <= 0 || i2 < this.batteryPercent) ? this.batteryPercent : i2;
    }

    @Override // android.widget.FrameLayout, android.view.ViewGroup, android.view.View
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        super.onLayout(changed, left, top, right, bottom);
        if (this.isLayout) {
            return;
        }
        g();
        f();
        this.isLayout = true;
    }

    @android.annotation.SuppressLint({"SetTextI18n"})
    public final void setBatteryPercent(int batteryPercent) {
        this.batteryPercent = batteryPercent;
        setTextForShowPercent(batteryPercent);
        getViewBinding().f.setPercentBattery(batteryPercent);
        this.isLayout = false;
        requestLayout();
    }

    public final void setHandleShowWarning(@org.jetbrains.annotations.Nullable kotlin.jvm.functions.Function0<kotlin.Unit> function0) {
        this.handleShowWarning = function0;
    }

    /* JADX WARN: 'this' call moved to the top of the method (can break code semantics) */
    @kotlin.jvm.JvmOverloads
    public BatteryReminderView(@org.jetbrains.annotations.NotNull android.content.Context context, @org.jetbrains.annotations.Nullable android.util.AttributeSet attributeSet) {
        this(context, attributeSet, 0, 4, null);
        kotlin.jvm.internal.Intrinsics.l(context, "context");
    }

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    @kotlin.jvm.JvmOverloads
    public BatteryReminderView(@org.jetbrains.annotations.NotNull android.content.Context context, @org.jetbrains.annotations.Nullable android.util.AttributeSet attributeSet, int i2) {
        super(context, attributeSet, i2);
        kotlin.jvm.internal.Intrinsics.l(context, "context");
        vn.vinfast.charginguikit.databinding.ViewBatteryReminderBinding viewBatteryReminderBindingC = vn.vinfast.charginguikit.databinding.ViewBatteryReminderBinding.c(android.view.LayoutInflater.from(context), this, false);
        this._binding = viewBatteryReminderBindingC;
        kotlin.jvm.internal.Intrinsics.i(viewBatteryReminderBindingC);
        addView(viewBatteryReminderBindingC.b());
        getViewBinding().f.setEnabled(false);
        c();
    }

    public /* synthetic */ BatteryReminderView(android.content.Context context, android.util.AttributeSet attributeSet, int i2, int i3, kotlin.jvm.internal.DefaultConstructorMarker defaultConstructorMarker) {
        this(context, (i3 & 2) != 0 ? null : attributeSet, (i3 & 4) != 0 ? 0 : i2);
    }
}
