Skip to content

Instantly share code, notes, and snippets.

@digitalbuddha
digitalbuddha / RxIdlingResource.java
Created November 17, 2016 20:05 — forked from aahlenst/RxIdlingResource.java
IdlingResource that makes Espresso 2 wait until all RxJava 2 tasks have finished
/*
* The MIT License
*
* Copyright (c) 2016 Andreas Ahlenstorf
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
@digitalbuddha
digitalbuddha / RxIdlingResource.java
Created November 17, 2016 20:05 — forked from aahlenst/RxIdlingResource.java
IdlingResource that makes Espresso 2 wait until all RxJava 2 tasks have finished
/*
* The MIT License
*
* Copyright (c) 2016 Andreas Ahlenstorf
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
@digitalbuddha
digitalbuddha / Store1.java
Last active January 13, 2017 14:47
Store1
Store<Article> Store = ParsingStoreBuilder.<BufferedSource, String>builder()
.fetcher(this::ResponseAsSource) //responseBody.source()
.persister(SourcePersisterFactory.create(context.getFilesDir())
.parser(GsonParserFactory.createSourceParser(gson, Article.class))
.open();
Store<Article> ArticleStore = StoreBuilder.<Article>builder()
.fetcher(barCode -> retrofitApi.getArticleObservable(barcode.getValue()))
.open();
@digitalbuddha
digitalbuddha / Store3.java
Last active January 12, 2017 20:59
Store3.java
Store<Article> articleStore = ParsingStoreBuilder.<BufferedSource, Article>builder()
.fetcher(barCode -> api.getSource(barCode.getKey()))
.parser(source -> {
try (InputStreamReader reader = new InputStreamReader(source.inputStream())) {
return gson.fromJson(reader, Article.class);
} catch (IOException e) {
throw new RuntimeException(e);} })
.open();
Store<Article> Store = ParsingStoreBuilder.<BufferedSource, Article>builder()
.fetcher(this::getResponseAsBufferedSource)
.parser(GsonParserFactory.createSourceParser(gson, Article.class))
.open();
Store<Books> bookStore = ParsingStoreBuilder.<BufferedSource, Books>builder()
.fetcher(barCode -> api.getSource(barCode.getKey()))
.persister(SourcePersisterFactory.create(context.getFilesDir())
.parser(GsonParserFactory.createSourceParser(gson, Books.class))
.open();
void getAllCountries(@NonNull final SelectCountryCallback callback, String username){
// Attempt to get countries from local cache, if present
if(dbData(callback)) return;
// Call API to get updated list of countries
callToApi(callback,username);
}
void callToApi(callback,username);
{
@digitalbuddha
digitalbuddha / RxApolloClient.java
Last active March 22, 2017 15:04
RxApolloClient
ApolloWatcher<EpisodeHeroName.Data> watcher = apolloClient.newCall(query).watcher();
RxApollo
.toObservable(watcher)
.subscribe(new Observer<EpisodeHeroName.Data>() {
@Override public void onCompleted() {
}
@Override public void onError(Throwable e) {