package com.adealink.weparty.commonui.drag

import android.util.SparseArray
import com.adealink.frame.log.Log

class DragViewMaker {

    /**
     * 用于保存 Float 与 TouchDelegate 的映射
     */
    private val mFloatView2Delegate = SparseArray<DragTouchEventDelegate>()

    fun makeViewFloat(v: IDragView) {
        val view = v.getView()
        val delegate = DragTouchEventDelegate(v)
        view.touchDelegate = delegate
        Log.d(TAG_DRAG_VIEW_MAKER, "(makeViewFloat): " + view.hashCode())
        mFloatView2Delegate.put(view.hashCode(), delegate)

    }

    fun updateViewStatus(viewHashCode: Int, @DragViewStatus viewStatus: Int) {
        mFloatView2Delegate.get(viewHashCode)?.updateViewStatus(viewStatus)
    }

    fun isDragging(v: IDragView): Boolean {
        return mFloatView2Delegate.get(v.getView().hashCode())?.isDragging()?:false
    }

    fun isMinimized(v: IDragView): Boolean {
        return mFloatView2Delegate.get(v.getView().hashCode())?.isMinimized()?:false
    }

    /**
     * 清除View缓存
     */
    fun remove(v: IDragView) {
        mFloatView2Delegate.remove(v.getView().hashCode())
    }

    /**
     * 清除View缓存
     */
    fun clear() {
        mFloatView2Delegate.clear()
    }
}
