kotlin useful extensions

Retrofit in Kotlin

request.enqueue(callback(
   { resp -> hendle response here }, 
   { err -> hendle error here }
))

Picasso in Kotlin

Picasso.with(context).load(imageUrl).into(imageView) {
    onSuccess {
        //we are happier here
    }
}

// OR more concise

imageView.load(imageUrl) {
    onSuccess {
        //we are happier here
    }
}

Example of painfull function in Java, add listener to get view's height and width

ViewTreeObserver vto = mView.getViewTreeObserver(); 
vto.addOnGlobalLayoutListener (new OnGlobalLayoutListener() { 
    @Override 
    public void onGlobalLayout() {
        layout.getViewTreeObserver().removeOnGlobalLayoutListener(this); 
        int width  = layout.getMeasuredWidth();
        int height = layout.getMeasuredHeight(); 

    } 
});

Let's do the same in Kotlin

mView.afterMeasured {
  // inside this block the view is completely drawn
}

Animation listner (all callbacks are optional ;) )

animation.setAnimationListener {
    onAnimationRepeat {
        // do something
    }

    onAnimationEnd {
        // do something
    }
    
    onAnimationStart {
        // do something
    }
}