Skip to content

Instantly share code, notes, and snippets.

Avatar

Antonio Gutierrez Martinez czyrux

  • Facebook
  • London
View GitHub Profile
@czyrux
czyrux / RxBus.java
Created Nov 2, 2016
Event bus using RxJava
View RxBus.java
import com.jakewharton.rxrelay.PublishRelay;
import com.jakewharton.rxrelay.Relay;
import rx.Observable;
public class RxBus {
private static final RxBus INSTANCE = new RxBus();
private final Relay<Object, Object> busSubject = PublishRelay.create().toSerialized();
@czyrux
czyrux / Store.java
Last active Oct 30, 2016
Store concept using RxJava subject
View Store.java
import com.jakewharton.rxrelay.BehaviorRelay;
import com.jakewharton.rxrelay.Relay;
import rx.Observable;
public class Store<T> {
private final Relay<T, T> storeSubject;
public Store() {
@czyrux
czyrux / UncheckedPool.java
Created Jul 23, 2016
Leaner version of a Simple (non-synchronized) pool of objects. This Pool does not do any check whether an object to be released is already or not in the pool, unlike android.support.v4.util.Pools.SimplePool
View UncheckedPool.java
import android.support.v4.util.Pools;
/**
* Simple (non-synchronized) pool of objects. This Pool does not do any check whether an object to be released is
* already in the pool, unlike {@link android.support.v4.util.Pools.SimplePool}
*
* @param <T> The pooled type.
*/
public class UncheckedPool<T> implements Pools.Pool<T> {
View PresenterLoader.java
import android.content.Context;
import android.support.v4.content.Loader;
public final class PresenterLoader<T extends Presenter> extends Loader<T>{
private final PresenterFactory<T> factory;
private T presenter;
public PresenterLoader(Context context, PresenterFactory<T> factory) {
super(context);
@czyrux
czyrux / ShareHelper.java
Last active Aug 29, 2015
Example on how to share content with specific requirements in Android
View ShareHelper.java
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import android.annotation.TargetApi;
import android.app.Activity;
@czyrux
czyrux / AsyncLoader.java
Last active Aug 29, 2015
Utility Loader class implementation which extends AsyncTaskLoader and handles caveats regarding loader lifecycle. It also provides error handling and a helper class to decouple the loader job task.
View AsyncLoader.java
import android.content.Context;
import android.support.v4.content.AsyncTaskLoader;
/**
* Loader which extends AsyncTaskLoader and handles caveats as pointed out in
* http://code.google.com/p/android/issues/detail?id=14944.
* <p/>
*
* @param <T> data type
* @author Antonio Gutierrez <agutierrez88s@gmail.com>
@czyrux
czyrux / ParcelUtils.java
Created Feb 15, 2015
Utility class for parceling objects in Android
View ParcelUtils.java
import android.os.Parcel;
import android.os.Parcelable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* Utility class for parceling objects
*/
@czyrux
czyrux / LocaleUtils.java
Created Feb 15, 2015
Utility class to change update locale settings within an Android Application. Changes will be reflected only within the app
View LocaleUtils.java
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Build;
import java.util.Locale;
/**
* Utility class to change app locale settings.
@czyrux
czyrux / Pools.java
Last active Aug 29, 2015
Tiny helper class for creating pools of objects in Java. Specially suitable for Android Projects
View Pools.java
/**
* Helper class for creating pools of objects.
*
* An example use looks like this:
*
* <pre>
* public class MyPooledClass implements {@link PoolObject}{
*
* private static final SynchronizedPool<MyPooledClass> sPool = new SynchronizedPool<MyPooledClass>(new MyPooledFactoryClass(), 10);
*