Skip to content

Instantly share code, notes, and snippets.

public class BaseActivity
{
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
bundleService = new BundleService(savedInstanceState, getIntent().getExtras());
}
....
protected void onSaveInstanceState(Bundle outState) {
outState.putAll(bundleService.getAll());
super.onSaveInstanceState(outState);
Observable.fromCallable(() -> {
RedditData result = null;
Response response = makeRequest();
String diskStorage = null;
try {
ResponseBody body = response.body();
BufferedSource sourceForDisk = body.source();
MediaType contentType = body.contentType();
Charset charset = contentType != null ? contentType.charset(UTF_8) : UTF_8;
public void readTwice()
{
Observable.fromCallable(() -> {
RedditData inflatedModel = null;
Response response = makeRequest();
String diskValue = null;
try {
File file = new File(getContext().getCacheDir(), "file");
BufferedSink cacheBody = Okio.buffer(Okio.sink(file));
@Singleton
public class Store {
@NonNull
public static final String SCANNED = "ScannedItemIDs";
@NonNull
public static final String SYNCED = "ScannedAndSyncedItemIDs";
@NonNull
private final RxStore store;
@NonNull
private final Api api;
@digitalbuddha
digitalbuddha / Dagger 2.md
Created February 29, 2016 20:02 — forked from lenguyenthanh/ Dagger 2.md
Dagger 2 configuration

Small gist show how to config Dagger 2 to an Android project

protected void clickButton(int id) {
onView(withId(id)).perform(click());
}
protected void clickOKButton() {
onView(withId(R.id.yes)).perform(click());
}
protected void clickYesButton() {
onView(withText("Yes")).perform(click());
package com.fresconews.fresco.framework.databinding.bindingAdapters;
import android.content.SharedPreferences;
import android.databinding.BindingAdapter;
import android.graphics.SurfaceTexture;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.preference.PreferenceManager;
import android.view.Surface;
import android.view.TextureView;
@Value.Immutable
@Value.Style(allParameters = true)
public abstract class Foo implements FooModel{
public static final FooModel.Mapper<Foo> MAPPER = new FooModel.Mapper<>((Mapper.Creator<Foo>) ImmutableFoo::of);
public static final class Marshal extends FooModel.FooMarshal {}
}
@digitalbuddha
digitalbuddha / MirroredSource.java
Last active August 29, 2016 14:22 — forked from RoryKelly/MirroredSource.java
Mirrored Source for OKIO.
import java.io.IOException;
import java.util.concurrent.atomic.AtomicBoolean;
import okio.Buffer;
import okio.Source;
import okio.Timeout;
import timber.log.Timber;
public class MirroredSource {
private final Buffer buffer = new Buffer();
@digitalbuddha
digitalbuddha / StoreReadme.md
Last active October 3, 2016 15:30
In Progress readme for new store Lib

Store

A Store is responsible for managing a particular data request in your application. When you create a Store, you provide it with an implementation of a Fetcher class which defines how it will fetch new data. You can also define how your Store will save data in-memory and on-disk as well as how to parse it. Once you’ve defined how your Store will handles these actions, Store handles the logic around data flow, allowing your views to show the best data source and ensuring that the newest data is always available for later offline use. Stores can both be used with logical defaults or are fully customizable to work with SqlLite, and your favorite networking libraries

Store’s leverage RxJava and intelligent in-flight logic to prevent excessive calls to the network and disk cache. By wrapping your data calls in Store’s, you eliminate the possibility of flooding your network with the same request while adding 2 layers of caching (memory + disk)

Creating a Store

The simplest way to make a Store is wi