package com.adealink.weparty.commonui.widget.slide.touch

import android.animation.ValueAnimator
import android.view.MotionEvent
import android.view.View
import com.adealink.weparty.commonui.widget.slide.AnimationProcessor
import com.adealink.weparty.commonui.widget.slide.Slide
import com.adealink.weparty.commonui.widget.slide.SlideBuilder
import com.adealink.weparty.commonui.widget.slide.SlideListener

abstract class AbsTouchConsumer(
    var mBuilder: SlideBuilder,
    var mNotifier: SlideListener
) {

    val mAnimationProcessor = AnimationProcessor(
        mBuilder,
        onAnimationUpdate = {
            onAnimationUpdate(it)
        },
        onAnimationEnd = {
            mNotifier.notifySlideFinish(it)
        }
    )


    var mStartPositionY: Float = 0f
    var mStartPositionX: Float = 0f

    @Volatile
    var mPrevPositionY: Float = 0f

    @Volatile
    var mPrevPositionX: Float = 0f

    var mViewStartPositionY: Float = 0f
    var mViewStartPositionX: Float = 0f

    val top: Int
        get() = mBuilder.mSliderView.top

    val bottom: Int
        get() = mBuilder.mSliderView.bottom

    abstract val dir: Slide.SlideDirection

    abstract fun onSlide(touchedView: View?, event: MotionEvent): Boolean

    abstract fun onAnimationUpdate(animation: ValueAnimator)

}
