Skip to content

Instantly share code, notes, and snippets.

View dadouf's full-sized avatar

David Ferrand dadouf

View GitHub Profile
private var hasInitParentDimensions = false
private var maxImageWidth: Int = 0
private var maxImageHeight: Int = 0
private var maxImageAspectRatio: Float = 1f
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VH {
if (!hasInitParentDimensions) {
maxImageWidth = parent.width
maxImageHeight = parent.height
maxImageAspectRatio = maxImageWidth.toFloat() / maxImageHeight.toFloat()
@dadouf
dadouf / HeightWrappingViewPager.kt
Created June 2, 2020 08:45
ViewPager that wraps its content's height
import android.content.Context
import android.support.v4.view.ViewPager
import android.util.AttributeSet
internal class HeightWrappingViewPager @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null)
: ViewPager(context, attrs) {
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
var heightMeasureSpecModif = heightMeasureSpec
@dadouf
dadouf / MockitoKotlinHelpers.kt
Last active February 25, 2020 10:36
Mockito+Kotlin: set mocks to throw unchecked exceptions
import org.mockito.BDDMockito
// Use just like a normal .willThrow:
// ```
// given(api.fetch()).willThrowUnchecked(Exception("First error"), Exception("Second error"))
// ```
fun <T> BDDMockito.BDDMyOngoingStubbing<T>.willThrowUnchecked(vararg throwables: Throwable) {
var invocationNumber = 0
this.willAnswer {