package com.google.android.material.appbar;

import X.06Z;
import X.1gt;
import X.C4785Qso;
import X.C4786Qsp;
import android.content.Context;
import android.util.AttributeSet;
import android.view.VelocityTracker;
import android.view.View;
import android.widget.OverScroller;
import com.bytedance.covode.number.Covode;

public abstract class HeaderBehavior<V extends View> extends C4785Qso<V> {
    public int activePointerId = -1;
    public Runnable flingRunnable;
    public boolean isBeingDragged;
    public int lastMotionY;
    public OverScroller scroller;
    public int touchSlop = -1;
    public VelocityTracker velocityTracker;

    static {
        Covode.recordClassIndex(43878);
    }

    public boolean canDragView(V v) {
        return false;
    }

    public void onFlingFinished(1gt r1, V v) {
    }

    public int getTopBottomOffsetForScrollingSibling() {
        return getTopAndBottomOffset();
    }

    public HeaderBehavior() {
    }

    private void ensureVelocityTracker() {
        if (this.velocityTracker == null) {
            this.velocityTracker = VelocityTracker.obtain();
        }
    }

    public int getMaxDragOffset(V v) {
        return -v.getHeight();
    }

    public int getScrollRangeForDragFling(V v) {
        return v.getHeight();
    }

    public HeaderBehavior(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
    }

    public int setHeaderTopBottomOffset(1gt r7, V v, int i) {
        return setHeaderTopBottomOffset(r7, v, i, Integer.MIN_VALUE, Integer.MAX_VALUE);
    }

    /* JADX WARNING: Code restructure failed: missing block: B:14:0x002c, code lost:
        if (r2 != 3) goto L_0x002e;
     */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public boolean onInterceptTouchEvent(X.1gt r7, V r8, android.view.MotionEvent r9) {
        /*
            r6 = this;
            int r0 = r6.touchSlop
            if (r0 >= 0) goto L_0x0012
            android.content.Context r0 = r7.getContext()
            android.view.ViewConfiguration r0 = android.view.ViewConfiguration.get(r0)
            int r0 = r0.getScaledTouchSlop()
            r6.touchSlop = r0
        L_0x0012:
            int r0 = r9.getAction()
            r5 = 2
            r4 = 1
            if (r0 != r5) goto L_0x001f
            boolean r0 = r6.isBeingDragged
            if (r0 == 0) goto L_0x001f
            return r4
        L_0x001f:
            int r2 = r9.getActionMasked()
            r3 = 0
            if (r2 == 0) goto L_0x0067
            r1 = -1
            if (r2 == r4) goto L_0x0058
            if (r2 == r5) goto L_0x0038
            r0 = 3
            if (r2 == r0) goto L_0x0058
        L_0x002e:
            android.view.VelocityTracker r0 = r6.velocityTracker
            if (r0 == 0) goto L_0x0035
            r0.addMovement(r9)
        L_0x0035:
            boolean r0 = r6.isBeingDragged
            return r0
        L_0x0038:
            int r0 = r6.activePointerId
            if (r0 == r1) goto L_0x002e
            int r0 = r9.findPointerIndex(r0)
            if (r0 == r1) goto L_0x002e
            float r0 = r9.getY(r0)
            int r2 = (int) r0
            int r0 = r6.lastMotionY
            int r0 = r2 - r0
            int r1 = java.lang.Math.abs(r0)
            int r0 = r6.touchSlop
            if (r1 <= r0) goto L_0x002e
            r6.isBeingDragged = r4
            r6.lastMotionY = r2
            goto L_0x002e
        L_0x0058:
            r6.isBeingDragged = r3
            r6.activePointerId = r1
            android.view.VelocityTracker r0 = r6.velocityTracker
            if (r0 == 0) goto L_0x002e
            r0.recycle()
            r0 = 0
            r6.velocityTracker = r0
            goto L_0x002e
        L_0x0067:
            r6.isBeingDragged = r3
            float r0 = r9.getX()
            int r2 = (int) r0
            float r0 = r9.getY()
            int r1 = (int) r0
            boolean r0 = r6.canDragView(r8)
            if (r0 == 0) goto L_0x002e
            boolean r0 = r7.LIZ(r8, r2, r1)
            if (r0 == 0) goto L_0x002e
            r6.lastMotionY = r1
            int r0 = r9.getPointerId(r3)
            r6.activePointerId = r0
            r6.ensureVelocityTracker()
            goto L_0x002e
        */
        throw new UnsupportedOperationException("Method not decompiled: com.google.android.material.appbar.HeaderBehavior.onInterceptTouchEvent(X.1gt, android.view.View, android.view.MotionEvent):boolean");
    }

    /* JADX WARNING: Code restructure failed: missing block: B:10:0x0026, code lost:
        if (r1 != 3) goto L_0x0028;
     */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public boolean onTouchEvent(X.1gt r15, V r16, android.view.MotionEvent r17) {
        /*
            r14 = this;
            int r0 = r14.touchSlop
            r6 = r15
            if (r0 >= 0) goto L_0x0013
            android.content.Context r0 = r6.getContext()
            android.view.ViewConfiguration r0 = android.view.ViewConfiguration.get(r0)
            int r0 = r0.getScaledTouchSlop()
            r14.touchSlop = r0
        L_0x0013:
            r3 = r17
            int r1 = r3.getActionMasked()
            r2 = 1
            r5 = 0
            r7 = r16
            if (r1 == 0) goto L_0x0095
            r4 = -1
            if (r1 == r2) goto L_0x0064
            r0 = 2
            if (r1 == r0) goto L_0x0030
            r0 = 3
            if (r1 == r0) goto L_0x0086
        L_0x0028:
            android.view.VelocityTracker r0 = r14.velocityTracker
            if (r0 == 0) goto L_0x002f
            r0.addMovement(r3)
        L_0x002f:
            return r2
        L_0x0030:
            int r0 = r14.activePointerId
            int r0 = r3.findPointerIndex(r0)
            if (r0 != r4) goto L_0x0039
            return r5
        L_0x0039:
            float r0 = r3.getY(r0)
            int r4 = (int) r0
            int r8 = r14.lastMotionY
            int r8 = r8 - r4
            boolean r0 = r14.isBeingDragged
            if (r0 != 0) goto L_0x0052
            int r1 = java.lang.Math.abs(r8)
            int r0 = r14.touchSlop
            if (r1 <= r0) goto L_0x0052
            r14.isBeingDragged = r2
            if (r8 <= 0) goto L_0x0062
            int r8 = r8 - r0
        L_0x0052:
            boolean r0 = r14.isBeingDragged
            if (r0 == 0) goto L_0x0028
            r14.lastMotionY = r4
            int r9 = r14.getMaxDragOffset(r7)
            r10 = 0
            r5 = r14
            r5.scroll(r6, r7, r8, r9, r10)
            goto L_0x0028
        L_0x0062:
            int r8 = r8 + r0
            goto L_0x0052
        L_0x0064:
            android.view.VelocityTracker r0 = r14.velocityTracker
            if (r0 == 0) goto L_0x0086
            r0.addMovement(r3)
            android.view.VelocityTracker r1 = r14.velocityTracker
            r0 = 1000(0x3e8, float:1.401E-42)
            r1.computeCurrentVelocity(r0)
            android.view.VelocityTracker r1 = r14.velocityTracker
            int r0 = r14.activePointerId
            float r13 = r1.getYVelocity(r0)
            int r0 = r14.getScrollRangeForDragFling(r7)
            int r11 = -r0
            r12 = 0
            r8 = r14
            r9 = r6
            r10 = r7
            r8.fling(r9, r10, r11, r12, r13)
        L_0x0086:
            r14.isBeingDragged = r5
            r14.activePointerId = r4
            android.view.VelocityTracker r0 = r14.velocityTracker
            if (r0 == 0) goto L_0x0028
            r0.recycle()
            r0 = 0
            r14.velocityTracker = r0
            goto L_0x0028
        L_0x0095:
            float r0 = r3.getX()
            int r4 = (int) r0
            float r0 = r3.getY()
            int r1 = (int) r0
            boolean r0 = r6.LIZ(r7, r4, r1)
            if (r0 == 0) goto L_0x00b8
            boolean r0 = r14.canDragView(r7)
            if (r0 == 0) goto L_0x00b8
            r14.lastMotionY = r1
            int r0 = r3.getPointerId(r5)
            r14.activePointerId = r0
            r14.ensureVelocityTracker()
            goto L_0x0028
        L_0x00b8:
            return r5
        */
        throw new UnsupportedOperationException("Method not decompiled: com.google.android.material.appbar.HeaderBehavior.onTouchEvent(X.1gt, android.view.View, android.view.MotionEvent):boolean");
    }

    public final int scroll(1gt r7, V v, int i, int i2, int i3) {
        return setHeaderTopBottomOffset(r7, v, getTopBottomOffsetForScrollingSibling() - i, i2, i3);
    }

    public int setHeaderTopBottomOffset(1gt r3, V v, int i, int i2, int i3) {
        int LIZ;
        int topAndBottomOffset = getTopAndBottomOffset();
        if (i2 == 0 || topAndBottomOffset < i2 || topAndBottomOffset > i3 || topAndBottomOffset == (LIZ = 06Z.LIZ(i, i2, i3))) {
            return 0;
        }
        setTopAndBottomOffset(LIZ);
        return topAndBottomOffset - LIZ;
    }

    public final boolean fling(1gt r13, V v, int i, int i2, float f) {
        Runnable runnable = this.flingRunnable;
        if (runnable != null) {
            v.removeCallbacks(runnable);
            this.flingRunnable = null;
        }
        if (this.scroller == null) {
            this.scroller = new OverScroller(v.getContext());
        }
        this.scroller.fling(0, getTopAndBottomOffset(), 0, Math.round(f), 0, 0, i, i2);
        if (this.scroller.computeScrollOffset()) {
            C4786Qsp qsp = new C4786Qsp(this, r13, v);
            this.flingRunnable = qsp;
            v.postOnAnimation(qsp);
            return true;
        }
        onFlingFinished(r13, v);
        return false;
    }
}
