Instantly share code, notes, and snippets.

Christophe Beyls cbeyls

View GitHub Profile
@cbeyls
cbeyls / ComputableLiveData.java
Created Mar 11, 2018
A LiveData class that can be invalidated & computed on demand (based on an internal architecture components class)
View ComputableLiveData.java
package be.digitalia.arch.lifecycle;
import android.arch.lifecycle.LiveData;
import android.arch.lifecycle.MutableLiveData;
import android.os.AsyncTask;
import android.support.annotation.MainThread;
import android.support.annotation.NonNull;
import android.support.annotation.VisibleForTesting;
import android.support.annotation.WorkerThread;
@cbeyls
cbeyls / ViewLifecycleFragment.java
Last active Jul 11, 2018
Fragment providing separate lifecycle owners for each created view hierarchy.
View ViewLifecycleFragment.java
package be.digitalia.archcomponentsfix.fragment;
import android.arch.lifecycle.Lifecycle.Event;
import android.arch.lifecycle.LifecycleOwner;
import android.arch.lifecycle.LifecycleRegistry;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.View;
@cbeyls
cbeyls / SuspendIntentService.kt
Created Aug 6, 2017
An Intent Service processing work in order from a Kotlin coroutine running on the main thread.
View SuspendIntentService.kt
package be.digitalia.common.services
import android.app.Service
import android.content.Intent
import android.os.Message
import kotlinx.coroutines.experimental.android.UI
import kotlinx.coroutines.experimental.channels.Channel
import kotlinx.coroutines.experimental.channels.LinkedListChannel
import kotlinx.coroutines.experimental.launch
@cbeyls
cbeyls / KotlinFunctions.md
Last active Feb 17, 2019
Comparison of Kotlin functions: also, apply, let, run, with
View KotlinFunctions.md
Function Function type Target passed as Returns
also Extension it Target
apply Extension this Target
let Extension it Block return value
run Extension this Block return value
with Regular this Block return value
@cbeyls
cbeyls / ParcelableUtils.kt
Last active Aug 10, 2018
Kotlin Parcelable utilities
View ParcelableUtils.kt
package be.digitalia.sample
import android.os.Parcel
import android.os.Parcelable
import java.math.BigDecimal
import java.math.BigInteger
import java.util.*
interface KParcelable : Parcelable {
@cbeyls
cbeyls / FragmentArgumentDelegate.kt
Last active Oct 16, 2018 — forked from yanngx/FragmentArgumentDelegate.kt
Fragment arguments without hassle !
View FragmentArgumentDelegate.kt
package be.brol
import android.os.Binder
import android.os.Bundle
import android.os.Parcelable
import android.support.v4.app.BundleCompat
import android.support.v4.app.Fragment
import kotlin.reflect.KProperty
/**
@cbeyls
cbeyls / SafeLoadersFragmentActivity.java
Last active Sep 15, 2018
Activity to restore the safe Loaders behavior of support libraries < 24.0.0 in recent versions
View SafeLoadersFragmentActivity.java
package android.support.v4.app;
/**
* Inherit from this class to prevent Loaders from being forcefully retained during a configuration change.
* Forceful retain currently causes all stopped Loaders to briefly start, causing unexpected issues for detached fragments.
* This restores the Loaders behavior of support libraries < 24.0.0
*
* @author Christophe Beyls
* @see <a href="https://issuetracker.google.com/issues/37916599">Bug report</a>
*/
@cbeyls
cbeyls / LifecycleLoader.java
Last active May 19, 2017
Lifecycle-aware Loader delivering results from a LiveData source
View LifecycleLoader.java
package be.digitalia.common.loaders;
import android.arch.lifecycle.Lifecycle;
import android.arch.lifecycle.LifecycleOwner;
import android.arch.lifecycle.LifecycleRegistry;
import android.arch.lifecycle.LiveData;
import android.arch.lifecycle.Observer;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
@cbeyls
cbeyls / SafeCoordinatorLayout.java
Last active Feb 22, 2017
CoordinatorLayout properly restoring the Behavior states on API < 13 by avoiding null ClassLoaders
View SafeCoordinatorLayout.java
package be.digitalia.common.widgets;
import android.content.Context;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.design.widget.CoordinatorLayout;
import android.support.v4.os.ParcelableCompat;
import android.support.v4.os.ParcelableCompatCreatorCallbacks;
import android.util.AttributeSet;
@cbeyls
cbeyls / MultiChoiceHelper.java
Last active Oct 10, 2018
Helper class to reproduce ListView's modal MultiChoice mode with a RecyclerView. Compatible with API 7+.
View MultiChoiceHelper.java
package be.digitalia.common.widgets;
import android.content.Context;
import android.os.Build;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.NonNull;
import android.support.v4.util.LongSparseArray;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.view.ActionMode;