Skip to content

Instantly share code, notes, and snippets.

Avatar
🇦🇷
https://feresr.github.io/

Fernando Raviola feresr

🇦🇷
https://feresr.github.io/
View GitHub Profile
View errorHandling.java
observableThatShouldNotCompleteOnError
.flatMap(e -> obsrevableThatMayThrow(e)
.onErrorResumeNext(Observable.empty())
).subscribe()
View RxStore.java
public abstract class RxStore<Input, Output> {
private BehaviorSubject<Input> subject = BehaviorSubject.create();
private Observable<Output> observable;
public final Subscription register(Subscriber<Output> subscriber) {
if (observable == null) {
observable = subject.compose(getTransformer());
}
return observable.subscribe(subscriber);
@feresr
feresr / JokesStore.java
Last active Feb 1, 2017
RxDataStore implementation
View JokesStore.java
public class JokesStore extends RxStore<JokeRequest, JokeResponse> {
private JokesEndpoint endpoints;
@Inject
public JokesStore(JokesEndpoint endpoints) {
this.endpoints = endpoints;
}
@Override
@feresr
feresr / UsingRxStorage.java
Last active Feb 1, 2017
using rx storage
View UsingRxStorage.java
public class JokesPresenter extends BasePresenter<JokesView> {
private JokesStore store;
private Subscription subscription;
@Inject
public JokesPresenter(JokesStore jokesStore) { this.store = jokesStore; }
@Override
public void onCreate() {
@feresr
feresr / rxRelayAwesome1.java
Last active Feb 3, 2017
RxRelays are awesome 1
View rxRelayAwesome1.java
public abstract class RxStore<Input, Output> {
private BehaviorRelay<Output> relay = BehaviorRelay.create(defaultValue());
public final Subscription register(Subscriber<Output> subscriber) {
return relay.subscribe(subscriber);
}
public final void execute(Input event) {
buildObservable(event).subscribe(relay);
}
View rxRelayAwesome0.java
public void execute() {
//doesn't actually execute anything just yet... just creates the observable
observable = endpoints.getJoke().doOnNext(joke -> storage.save(joke));
}
public Subscription subscribe(Subscriber<Joke> subscriber) {
return observable.subscribe(subscriber);
}
public final void unsubscribe(Subscription subscription) { } //unsubscribe
View rxRelayAwesome2.java
public Constructor() {
observable = endpoints.getJoke().doOnNext(joke -> storage.save(joke)).publish();
}
public void execute() {
observable.connect();
}
public Subscription subscribe(Subscriber<Joke> subscriber) { } //subscribe
public final void unsubscribe(Subscription) { } //unsubscribe
View rxRelayAwesome3.java
public class JokesStore extends RxStore<JokeRequest, JokeResponse> {
private Observable<JokeResponse> buildObservable(JokeRequest event) {
return endpoints.getJoke(event.jokeNumber)
.subscribeOn().onBackPressureDrop()
.doOnNext(joke -> storage.save(joke))
.onErrorReturn() //create a joke response, set isSuccessful to false)
.observeOn();
}
View MainActivity.java
package com.example.gonzalo_mov.congreso;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
@feresr
feresr / org.mockito.plugins.MockMaker
Created Aug 13, 2017
Mockito enable mock final classes
View org.mockito.plugins.MockMaker
content: mock-maker-inline