GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Merge pull request #36 from marukami/retrofit-frag · fmlking/RxJava-Android-Samples@3f41658

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • app/src/main/java/com/morihacky/android/rxjava/fragments
    • RetrofitFragment.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎app/src/main/java/com/morihacky/android/rxjava/fragments/RetrofitFragment.java‎

Copy file name to clipboardExpand all lines: app/src/main/java/com/morihacky/android/rxjava/fragments/RetrofitFragment.java
+96-95Lines changed: 96 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@
3737
public class RetrofitFragment
3838
extends Fragment {
3939

40-
@Bind(R.id.demo_retrofit_contributors_username) EditText _username;
41-
@Bind(R.id.demo_retrofit_contributors_repository) EditText _repo;
40+
@Bind(R.id.demo_retrofit_contributors_username) EditText _contributorsUsername;
41+
@Bind(R.id.demo_retrofit_contributors_repository) EditText _contributorsRepo;
42+
@Bind(R.id.demo_retrofit_contributors_with_user_info_username) EditText _userInfoUsername;
43+
@Bind(R.id.demo_retrofit_contributors_with_user_info_repository) EditText _userInfoRepo;
4244
@Bind(R.id.log_list) ListView _resultList;
4345

4446
private GithubApi _api;
@@ -87,106 +89,105 @@ public void onListContributorsClicked() {
8789
_adapter.clear();
8890

8991
_subscriptions.add(//
90-
_api.contributors(_username.getText().toString(), _repo.getText().toString())
91-
.subscribeOn(Schedulers.io())
92-
.observeOn(AndroidSchedulers.mainThread())
93-
.subscribe(new Observer<List<Contributor>>() {
94-
@Override
95-
public void onCompleted() {
96-
Timber.d("Retrofit call 1 completed");
97-
}
98-
99-
@Override
100-
public void onError(Throwable e) {
101-
Timber.e(e,
102-
"woops we got an error while getting the list of contributors");
103-
}
104-
105-
@Override
106-
public void onNext(List<Contributor> contributors) {
107-
for (Contributor c : contributors) {
108-
_adapter.add(format("%s has made %d contributions to %s",
109-
c.login,
110-
c.contributions,
111-
_repo.getText().toString()));
112-
113-
Timber.d("%s has made %d contributions to %s",
114-
c.login,
115-
c.contributions,
116-
_repo.getText().toString());
92+
_api.contributors(_contributorsUsername.getText().toString(), _contributorsRepo.getText().toString())
93+
.subscribeOn(Schedulers.io())
94+
.observeOn(AndroidSchedulers.mainThread())
95+
.subscribe(new Observer<List<Contributor>>() {
96+
@Override
97+
public void onCompleted() {
98+
Timber.d("Retrofit call 1 completed");
11799
}
118-
}
119-
}));
100+
101+
@Override
102+
public void onError(Throwable e) {
103+
Timber.e(e,
104+
"woops we got an error while getting the list of contributors");
105+
}
106+
107+
@Override
108+
public void onNext(List<Contributor> contributors) {
109+
for (Contributor c : contributors) {
110+
_adapter.add(format("%s has made %d contributions to %s",
111+
c.login,
112+
c.contributions,
113+
_contributorsRepo.getText().toString()));
114+
115+
Timber.d("%s has made %d contributions to %s",
116+
c.login,
117+
c.contributions,
118+
_contributorsRepo.getText().toString());
119+
}
120+
}
121+
}));
120122
}
121123

122124
@OnClick(R.id.btn_demo_retrofit_contributors_with_user_info)
123125
public void onListContributorsWithFullUserInfoClicked() {
124126
_adapter.clear();
125127

126-
_subscriptions.add(_api.contributors(_username.getText().toString(),
127-
_repo.getText().toString())
128-
.flatMap(new Func1<List<Contributor>, Observable<Contributor>>() {
129-
@Override
130-
public Observable<Contributor> call(List<Contributor> contributors) {
131-
return Observable.from(contributors);
132-
}
133-
})
134-
.flatMap(new Func1<Contributor, Observable<Pair<User, Contributor>>>() {
135-
@Override
136-
public Observable<Pair<User, Contributor>> call(Contributor contributor) {
137-
Observable<User> _userObservable = _api.user(contributor.login)
138-
.filter(new Func1<User, Boolean>() {
139-
@Override
140-
public Boolean call(User user) {
141-
return !isEmpty(user.name) && !isEmpty(user.email);
142-
}
143-
});
144-
145-
return Observable.zip(_userObservable,
146-
Observable.just(contributor),
147-
new Func2<User, Contributor, Pair<User, Contributor>>() {
148-
@Override
149-
public Pair<User, Contributor> call(User user,
150-
Contributor contributor) {
151-
return new Pair<>(user, contributor);
152-
}
153-
});
154-
}
155-
})
156-
.subscribeOn(Schedulers.newThread())
157-
.observeOn(AndroidSchedulers.mainThread())
158-
.subscribe(new Observer<Pair<User, Contributor>>() {
159-
@Override
160-
public void onCompleted() {
161-
Timber.d("Retrofit call 2 completed ");
162-
}
163-
164-
@Override
165-
public void onError(Throwable e) {
166-
Timber.e(e,
167-
"error while getting the list of contributors along with full names");
168-
}
169-
170-
@Override
171-
public void onNext(Pair<User, Contributor> pair) {
172-
User user = pair.first;
173-
Contributor contributor = pair.second;
174-
175-
_adapter.add(format("%s(%s) has made %d contributions to %s",
176-
user.name,
177-
user.email,
178-
contributor.contributions,
179-
_repo.getText().toString()));
180-
181-
_adapter.notifyDataSetChanged();
182-
183-
Timber.d("%s(%s) has made %d contributions to %s",
184-
user.name,
185-
user.email,
186-
contributor.contributions,
187-
_repo.getText().toString());
188-
}
189-
}));
128+
_subscriptions.add(_api.contributors(_userInfoUsername.getText().toString(), _userInfoRepo.getText().toString())
129+
.flatMap(new Func1<List<Contributor>, Observable<Contributor>>() {
130+
@Override
131+
public Observable<Contributor> call(List<Contributor> contributors) {
132+
return Observable.from(contributors);
133+
}
134+
})
135+
.flatMap(new Func1<Contributor, Observable<Pair<User, Contributor>>>() {
136+
@Override
137+
public Observable<Pair<User, Contributor>> call(Contributor contributor) {
138+
Observable<User> _userObservable = _api.user(contributor.login)
139+
.filter(new Func1<User, Boolean>() {
140+
@Override
141+
public Boolean call(User user) {
142+
return !isEmpty(user.name) && !isEmpty(user.email);
143+
}
144+
});
145+
146+
return Observable.zip(_userObservable,
147+
Observable.just(contributor),
148+
new Func2<User, Contributor, Pair<User, Contributor>>() {
149+
@Override
150+
public Pair<User, Contributor> call(User user,
151+
Contributor contributor) {
152+
return new Pair<>(user, contributor);
153+
}
154+
});
155+
}
156+
})
157+
.subscribeOn(Schedulers.newThread())
158+
.observeOn(AndroidSchedulers.mainThread())
159+
.subscribe(new Observer<Pair<User, Contributor>>() {
160+
@Override
161+
public void onCompleted() {
162+
Timber.d("Retrofit call 2 completed ");
163+
}
164+
165+
@Override
166+
public void onError(Throwable e) {
167+
Timber.e(e,
168+
"error while getting the list of contributors along with full names");
169+
}
170+
171+
@Override
172+
public void onNext(Pair<User, Contributor> pair) {
173+
User user = pair.first;
174+
Contributor contributor = pair.second;
175+
176+
_adapter.add(format("%s(%s) has made %d contributions to %s",
177+
user.name,
178+
user.email,
179+
contributor.contributions,
180+
_contributorsRepo.getText().toString()));
181+
182+
_adapter.notifyDataSetChanged();
183+
184+
Timber.d("%s(%s) has made %d contributions to %s",
185+
user.name,
186+
user.email,
187+
contributor.contributions,
188+
_contributorsRepo.getText().toString());
189+
}
190+
}));
190191
}
191192

192193
// -----------------------------------------------------------------------------------

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.