package com.fuyoul.sanwenseller.listener

import android.support.design.widget.AppBarLayout

/**
 *  @author: chen
 *  @CreatDate: 2017\11\13 0013
 *  @Desc:
 */
abstract class AppBarStateChangeListener : AppBarLayout.OnOffsetChangedListener {
    private var mCurrentState = State.IDLE

    enum class State {
        EXPANDED,
        COLLAPSED,
        IDLE;
    }

    abstract fun onStateChanged(appBarLayout: AppBarLayout?, state: State)

    override fun onOffsetChanged(appBarLayout: AppBarLayout?, i: Int) {

        if (i == 0) {
            if (mCurrentState != State.EXPANDED) {
                onStateChanged(appBarLayout, State.EXPANDED)
            }
            mCurrentState = State.EXPANDED
        } else if (Math.abs(i) >= appBarLayout!!.getTotalScrollRange()) {
            if (mCurrentState != State.COLLAPSED) {
                onStateChanged(appBarLayout, State.COLLAPSED)
            }
            mCurrentState = State.COLLAPSED
        } else {
            if (mCurrentState != State.IDLE) {
                onStateChanged(appBarLayout, State.IDLE)
            }
            mCurrentState = State.IDLE
        }

    }
}