This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyBroadcastReceiver(val listener : MyBroadcastListener) extends BroadcastReceiver() { | |
override fun onReceive(p0: Context?, p1: Intent?) { | |
listener.onSomeEventHappened() | |
} | |
interface MyBroadcastListener { | |
fun onSomeEventHappened() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun <T> any(): T { | |
Mockito.any<T>() | |
return uninitialized() | |
} | |
private fun <T> uninitialized(): T = null as T |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
content: mock-maker-inline |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class JokesPresenter extends BasePresenter<JokesView> { | |
private JokesStore store; | |
private Subscription subscription; | |
@Inject | |
public JokesPresenter(JokesStore jokesStore) { this.store = jokesStore; } | |
@Override | |
public void onCreate() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class JokesStore extends RxStore<JokeRequest, JokeResponse> { | |
private JokesEndpoint endpoints; | |
@Inject | |
public JokesStore(JokesEndpoint endpoints) { | |
this.endpoints = endpoints; | |
} | |
@Override |