Skip to content

Instantly share code, notes, and snippets.


Christophe Beyls cbeyls

View GitHub Profile
cbeyls / StickyHeaderLinearLayoutManager.kt
Created Sep 27, 2021
Sticky headers LinearLayoutManager, adapted from Epoxy
View StickyHeaderLinearLayoutManager.kt
package be.digitalia.util.stickyheader
import android.content.Context
import android.os.Parcel
import android.os.Parcelable
import android.view.View
import android.view.ViewGroup
import android.view.ViewTreeObserver
import androidx.recyclerview.widget.LinearLayoutManager
cbeyls / FlowLayout.kt
Created Sep 17, 2020
FlowLayout implementation for Jetpack Compose
View FlowLayout.kt
package be.digitalia.compose.layout
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Layout
import androidx.compose.ui.Modifier
fun FlowLayout(
modifier: Modifier = Modifier,
cbeyls / LayerCrossfadeTransition.kt
Last active Aug 1, 2020
A Transition for the Coil image loader that crossfades from the current drawable to a new one, and enables a hardware layer for the duration of the animation if the view is not opaque.
View LayerCrossfadeTransition.kt
package be.digitalia.bifff.coil
import android.view.View
import androidx.core.view.ViewCompat
import androidx.core.view.isVisible
import coil.annotation.ExperimentalCoilApi
import coil.decode.DataSource
import coil.drawable.CrossfadeDrawable
import coil.request.ErrorResult
import coil.request.RequestResult
cbeyls / TypedFragmentResults.kt
Created May 19, 2020
Example of type-safe Fragment result contract extensions
View TypedFragmentResults.kt
import android.os.Bundle
import androidx.core.os.bundleOf
import androidx.lifecycle.LifecycleOwner
interface FragmentResultContract<T> {
fun toBundle(result: T): Bundle
cbeyls / RecyclerViewExt.kt
Last active Dec 30, 2020
Extension function to enforce a single scroll direction for a RecyclerView
View RecyclerViewExt.kt
package be.digitalia.samples.utils
import android.view.MotionEvent
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.OnItemTouchListener
import kotlin.math.abs
fun RecyclerView.enforceSingleScrollDirection() {
val enforcer = SingleScrollDirectionEnforcer()
cbeyls /
Last active Jan 3, 2020
Utility class to enforce a single scroll direction for a RecyclerView or a ViewPager2
package be.digitalia.samples.utils;
import android.view.MotionEvent;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager2.widget.ViewPager2;
public class RecyclerViewUtils {
cbeyls / BinaryTrees.kt
Created Aug 18, 2019
Kotlin implementation of the binary-trees benchmark from The Computer Language Benchmarks Game
View BinaryTrees.kt
* The Computer Language Benchmarks Game
* based on Jarkko Miettinen's Java program
* contributed by Christophe Beyls
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.runBlocking
cbeyls / Parcelers.kt
Last active Oct 8, 2021
Kotlin Parcelize extensions
View Parcelers.kt
package be.digitalia.sample
import android.os.Parcel
import kotlinx.parcelize.Parceler
import java.math.BigDecimal
import java.math.BigInteger
import java.util.Date
inline fun <T> Parcel.readNullable(reader: () -> T) =
if (readInt() != 0) reader() else null
View DogRiddle.kt
sealed class Animal {
// Cats are simple. A cat is a cat.
object Cat : Animal()
sealed class Dog : Animal() {
abstract val breed: String?
class DogWithBreed(override val breed: String) : Dog()
cbeyls /
Created Apr 27, 2019
A Factory providing utility LiveData instances
package be.digitalia.common.livedata;
import android.os.Handler;
import android.os.Looper;
import android.os.SystemClock;
import androidx.annotation.NonNull;
import androidx.lifecycle.LiveData;
import java.util.concurrent.TimeUnit;