use of uk.ivanc.archimvvm.ArchiApplication in project archi by ivacf.
the class RepositoryViewModel method loadFullUser.
private void loadFullUser(String url) {
ArchiApplication application = ArchiApplication.get(context);
GithubService githubService = application.getGithubService();
subscription = githubService.userFromUrl(url).observeOn(AndroidSchedulers.mainThread()).subscribeOn(application.defaultSubscribeScheduler()).subscribe(new Action1<User>() {
@Override
public void call(User user) {
Log.i(TAG, "Full user data loaded " + user);
ownerName.set(user.name);
ownerEmail.set(user.email);
ownerLocation.set(user.location);
ownerEmailVisibility.set(user.hasEmail() ? View.VISIBLE : View.GONE);
ownerLocationVisibility.set(user.hasLocation() ? View.VISIBLE : View.GONE);
ownerLayoutVisibility.set(View.VISIBLE);
}
});
}
use of uk.ivanc.archimvvm.ArchiApplication in project archi by ivacf.
the class MainViewModel method loadGithubRepos.
private void loadGithubRepos(String username) {
progressVisibility.set(View.VISIBLE);
recyclerViewVisibility.set(View.INVISIBLE);
infoMessageVisibility.set(View.INVISIBLE);
if (subscription != null && !subscription.isUnsubscribed())
subscription.unsubscribe();
ArchiApplication application = ArchiApplication.get(context);
GithubService githubService = application.getGithubService();
subscription = githubService.publicRepositories(username).observeOn(AndroidSchedulers.mainThread()).subscribeOn(application.defaultSubscribeScheduler()).subscribe(new Subscriber<List<Repository>>() {
@Override
public void onCompleted() {
if (dataListener != null)
dataListener.onRepositoriesChanged(repositories);
progressVisibility.set(View.INVISIBLE);
if (!repositories.isEmpty()) {
recyclerViewVisibility.set(View.VISIBLE);
} else {
infoMessage.set(context.getString(R.string.text_empty_repos));
infoMessageVisibility.set(View.VISIBLE);
}
}
@Override
public void onError(Throwable error) {
Log.e(TAG, "Error loading GitHub repos ", error);
progressVisibility.set(View.INVISIBLE);
if (isHttp404(error)) {
infoMessage.set(context.getString(R.string.error_username_not_found));
} else {
infoMessage.set(context.getString(R.string.error_loading_repos));
}
infoMessageVisibility.set(View.VISIBLE);
}
@Override
public void onNext(List<Repository> repositories) {
Log.i(TAG, "Repos loaded " + repositories);
MainViewModel.this.repositories = repositories;
}
});
}
Aggregations