Contenu connexe Similaire à An Introduction to RxJava (20) Plus de K. Matthew Dupree (8) An Introduction to RxJava7. private void searchFor(String query) {
// ANALYTICS EVENT: Start a search on the Search activity
// Contains: Nothing (Event params are constant: Search query
// not included)
AnalyticsHelper.sendEvent(SCREEN_LABEL, "Search", "");
Bundle args = new Bundle(1);
if (query == null) {
query = "";
}
args.putString(ARG_QUERY, query);
if (TextUtils.equals(query, mQuery)) {
getLoaderManager()
.initLoader(SearchTopicsSessionsQuery.TOKEN, args,
this);
} else {
getLoaderManager()
.restartLoader(SearchTopicsSessionsQuery.TOKEN, args,
this);
}
mQuery = query;
}
8. private void searchFor(String query) {
// ANALYTICS EVENT: Start a search on the Search activity
// Contains: Nothing (Event params are constant: Search query
// not included)
AnalyticsHelper.sendEvent(SCREEN_LABEL, "Search", "");
Bundle args = new Bundle(1);
if (query == null) {
query = "";
}
args.putString(ARG_QUERY, query);
if (TextUtils.equals(query, mQuery)) {
getLoaderManager()
.initLoader(SearchTopicsSessionsQuery.TOKEN, args,
this);
} else {
getLoaderManager()
.restartLoader(SearchTopicsSessionsQuery.TOKEN, args,
this);
}
mQuery = query;
}
16. I was pretty much dragged into RxJava by my coworkers...[RxJava]
was a lot like git...when I first learned git, I didn’t really learn it. I just
spent three weeks being mad at it...and then something clicked
and I was like ‘Oh! I get it! And this is amazing and I love it!' The
same thing happened with RxJava.
—Dan Lew, Google Developer Expert
34. double[] getPopulations(Country[] counties) {
double[] populations = new double[counties.length];
for (int i = 0; i < counties.length; i++) {
populations[i] = counties[i].getPopulation();
}
return populations;
}
35. double[] getPopulations(Country[] counties) {
double[] populations = new double[counties.length];
for (int i = 0; i < counties.length; i++) {
populations[i] = counties[i].getPopulation();
}
return populations;
}
36. double[] getPopulations(Country[] counties) {
double[] populations = new double[counties.length];
for (int i = 0; i < counties.length; i++) {
populations[i] = counties[i].getPopulation();
}
return populations;
}
37. double[] getPopulations(Country[] counties) {
double[] populations = new double[counties.length];
for (int i = 0; i < counties.length; i++) {
populations[i] = counties[i].getPopulation();
}
return populations;
}
40. const countries = [
{ name: "United States", population: 300e6 },
{ name: "Canada", population: 36e6 },
{ name: "Mexico", population: 107e6 }
];
42. class Array {
map(transform) {
const newList = [];
for (let i = 0; i < this.size; i++) {
newList.push(transform(this[i]));
}
return newList;
}
}
46. const northAmericanPopExcludingUs = countries
.filter(it => it.name === "United States")
.map(it => it.population)
.reduce((totalPop, countryPop) => totalPop + countryPop);
47. const northAmericanPopExcludingUs = countries
.filter(it => it.name === "United States")
.map(it => it.population)
.reduce((totalPop, countryPop) => totalPop + countryPop);
48. const northAmericanPopExcludingUs = countries
.filter(it => it.name === "United States")
.map(it => it.population)
.reduce((totalPop, countryPop) => totalPop + countryPop);
49. const northAmericanPopExcludingUs = countries
.filter(it => it.name === "United States")
.map(it => it.population)
.reduce((totalPop, countryPop) => totalPop + countryPop);
50. const northAmericanPopExcludingUs = countries
.filter(it => it.name === "United States")
.map(it => it.population)
.reduce((totalPop, countryPop) => totalPop + countryPop);
51. const northAmericanPopExcludingUs = countries
.filter(it => it.name === "United States")
.map(it => it.population)
.reduce((totalPop, countryPop) => totalPop + countryPop);
65. for (int i = 0; i < northAmericanCountries.length; i++) {
System.out.println(northAmericanCountries[i]);
}
66. for (int i = 0; i < linkedList.length; i++) {
System.out.println(linkedList[i]);
}
77. fun <T, R> Iterable<T>.map(transform: (T) -> R): List<R> {
val destination = ArrayList<R>(collectionSizeOrDefault(10))
for (item in this)
destination.add(transform(item))
return destination
}
78. fun <T, R> Iterable<T>.map(transform: (T) -> R): List<R> {
val destination = ArrayList<R>(collectionSizeOrDefault(10))
for (item in this)
destination.add(transform(item))
return destination
}
91. for (int buttonClick : buttonClicks) {
trackClick();
}
button.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
trackClick();
}
});
92. for (int buttonClick : buttonClicks) {
trackClick();
}
button.forEachClick(new View.OnClickListener() {
@Override public void onClick(View v) {
trackClick();
}
});
93. for (int buttonClick : buttonClicks) {
trackClick();
}
clickSequence.forEachClick(new View.OnClickListener() {
@Override public void onClick(View v) {
trackClick();
}
});
122. [k, ke, key, keyn, keyno, keynot, keynote]
[results for ‘k’, results for ‘ke', results for ‘key’…]
for each result, update UI
125. [k, ke, key, keyn, keyno, keynot, keynote]
makeQueryTextObservable(mSearchView)
.flatMap { s -> makeLoadObservable(s) }
.subscribe { cursor ->
mResultsAdapter.swapCursor(cursor)
}
134. [k, ke, key, keyn, keyno, keynot, keynote]
filter
[keyn, keyno, keynot, keynote]
139. makeQueryTextObservable(mSearchView!!)
.filter { s -> s.length > 3 }
.debounce(300, TimeUnit.MILLISECONDS)
.flatMap { s -> makeLoadObservable(s) }
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe { cursor ->
mResultsAdapter!!.swapCursor(cursor)
}
140. makeQueryTextObservable(mSearchView!!)
.filter { s -> s.length > 3 }
.debounce(300, TimeUnit.MILLISECONDS)
.flatMap { s -> makeLoadObservable(s) }
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe { cursor ->
mResultsAdapter!!.swapCursor(cursor)
}
141. makeQueryTextObservable(mSearchView!!)
.filter { s -> s.length > 3 }
.debounce(300, TimeUnit.MILLISECONDS)
.flatMap { s -> makeLoadObservable(s) }
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe { cursor ->
mResultsAdapter!!.swapCursor(cursor)
}