Skip to content

Instantly share code, notes, and snippets.

View nwellis's full-sized avatar

nwellis nwellis

  • Minneapolis, MN
View GitHub Profile
abstract class RealmObjBundler<T extends RealmObject> implements Bundler<T> {
abstract public String[] args(T obj);
@NonNull abstract public RealmQuery<T> query(Realm realm, String... args);
@Override public void put(String s, final T obj, Bundle bundle) {
if (obj == null) return;
ArrayList<String> args = new ArrayList<>();
// We need to know whether this was managed before to determine if we need to delete it afterwards
@nwellis
nwellis / GsonBundler.java
Last active May 13, 2021 12:59
Custom bundler for Icepick which saves objects via GSON
public abstract class GsonBundler<T> implements Bundler<T> {
//Maximum bytes this fragment is allowed to save, os limit is 1 Mb
public static final int MAX_BUNDLE_BYTE_SIZE = 93750; //93750 bytes == .75 Mb
abstract Class<T> getObjClass();
@Override public void put(String s, T obj, Bundle bundle) {
putReturnSize(s, obj, bundle);
}
{"lastUpload":"2021-08-07T13:12:16.241Z","extensionVersion":"v3.4.3"}
@nwellis
nwellis / RetroCallStack.java
Created December 30, 2016 21:42
Simple helper class to monitor the Retrofit 2 calls
import android.support.annotation.Nullable;
import java.util.Stack;
import retrofit2.Call;
/**
* Simple helper class to monitor the Retrofit 2 calls. Biggest use case is to cancel all pending calls.
*/
public class RetroCallStack {
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.support.annotation.ColorRes;
import android.support.annotation.IdRes;
import android.support.v4.content.ContextCompat;
@nwellis
nwellis / ApiCallback.java
Created December 30, 2016 20:27
Helper callback class that builds on top of Retrofit 2's callback interface
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
/**
* <p>
* Builds upon the Retrofit {@link Callback} class. Useful when each HTTP code group has
* specific functionality. This lacks some of the flexibility of {@link Callback} though.
* </p>
*/