This file contains hidden or 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
override fun login(auth: Authorization): Single<GithubUser> = Single.fromCallable { | |
val response = get("https://api.github.com/user", auth = auth) | |
if (response.statusCode != 200) { | |
throw RuntimeException("Incorrect login or password") | |
} | |
val jsonObject = response.jsonObject | |
with(jsonObject) { | |
return@with GithubUser(getString("login"), getInt("id"), | |
getString("repos_url"), getString("name")) |
This file contains hidden or 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
@SchedulerSupport(SchedulerSupport.NONE) | |
@Override | |
public final void subscribe(SingleObserver<? super T> subscriber) { | |
ObjectHelper.requireNonNull(subscriber, "subscriber is null"); | |
subscriber = RxJavaPlugins.onSubscribe(this, subscriber); | |
ObjectHelper.requireNonNull(subscriber, "subscriber returned by the RxJavaPlugins hook is null"); | |
try { |
This file contains hidden or 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
apiClient.login(auth) | |
// some code ommitted | |
.subscribeOn(Schedulers.io()) | |
.observeOn(AndroidSchedulers.mainThread()) |
This file contains hidden or 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
// new SingleFlatMap() | |
val flatMap = apiClient.login(auth) | |
.flatMap { apiClient.getRepositories(it.repos_url, auth) } | |
// new SingleMap | |
val map = flatMap | |
.map { list -> list.map { it.full_name } } | |
// new SingleSubscribeOn | |
val subscribeOn = map | |
.subscribeOn(Schedulers.io()) | |
// new SingleObserveOn |
This file contains hidden or 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 attemptLoginRx() { | |
showProgress(true) | |
apiClient.login(auth) | |
.flatMap { | |
user -> apiClient.getRepositories(user.repos_url, auth) | |
} | |
.map { | |
list -> list.map { it.full_name } | |
} |
This file contains hidden or 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 Scheduler { | |
@NonNull | |
public Disposable scheduleDirect(@NonNull Runnable run) { ... } | |
@NonNull | |
public Disposable scheduleDirect(@NonNull Runnable run, long delay, @NonNull TimeUnit unit) { ... } | |
@NonNull | |
public Disposable schedulePeriodicallyDirect(@NonNull Runnable run, long initialDelay, long period, @NonNull TimeUnit unit) { ... } { |
This file contains hidden or 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 SplashActivity extends Activity { | |
@Subscribe | |
public void on(DatabaseLoadedEvent event) { | |
runOnUiThread(new Runnable() { | |
@Override | |
public void run() { | |
progressBar.setVisibility(View.GONE); | |
showMainActivity(); | |
} |
This file contains hidden or 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 postEventOnUiThread(final Object event) { | |
mUiHandler.post(new Runnable() { | |
@Override | |
public void run() { | |
mEventBus.post(event); | |
} | |
}); | |
} |
This file contains hidden or 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 SplashActivity extends Activity { | |
@Override | |
protected void onStart() { | |
super.onStart(); | |
eventBus.register(this); | |
} | |
@Override | |
protected void onStop() { |
This file contains hidden or 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
mBackground.execute(new Runnable() { | |
@Override | |
public void run() { | |
try { | |
initDatabaseInternal(); | |
mBackground.post(new DatabaseLoadedEvent()); | |
} catch (Exception e) { | |
Log.e("Failed to init db", e); |