package com.dreamteam.timelapse

import android.animation.ValueAnimator
import android.content.Context
import android.util.AttributeSet
import android.util.Log
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout

class CustomSwipeRefreshLayout(context: Context, attrs: AttributeSet) : SwipeRefreshLayout(context, attrs) {
    init {
        this.setEnabled(true)
        this.setRefreshing(true)
        Log.d("CustomSwipeRefreshLayout", "CustomSwipeRefreshLayout instancié")
    }
    override fun canChildScrollUp(): Boolean {
        // Vérifie si l'enfant direct (RecyclerView par exemple) peut encore scroller vers le haut
        val view = getChildAt(0)
        //Log.i("CustomSwipeRefreshLayout", "canChildScrollUp: ${view?.canScrollVertically(-1)}")
        return view != null && view.canScrollVertically(-1)
    }
    private var mMeasured = false
    private var mPreMeasureRefreshing = false


//    fun dragDown(){
//        this.post {
//            Log.i("SwipeRefreshLayout", "Je suis delanché par le code")
//            val distanceToMove = 200 // La distance que l'on veut faire descendre l'élément, ajustable
//            val valueAnimator = ValueAnimator.ofInt(0, distanceToMove)
//            valueAnimator.addUpdateListener { animation ->
//                val value = animation.animatedValue as Int
//                // Manipule le mouvement de l'animation du rafraîchissement
//                this.setProgressViewOffset(false, 0, value)
//            }
//            valueAnimator.duration = 500 // Durée de l'animation
//            valueAnimator.start()
//        }
//    }
}