use of uk.ivanc.archimvvm.model.GithubService in project archi by ivacf.
the class MainViewModelTest method setUp.
@Before
public void setUp() {
githubService = mock(GithubService.class);
dataListener = mock(MainViewModel.DataListener.class);
application = (ArchiApplication) RuntimeEnvironment.application;
// Mock the retrofit service so we don't call the API directly
application.setGithubService(githubService);
// Change the default subscribe schedulers so all observables
// will now run on the same thread
application.setDefaultSubscribeScheduler(Schedulers.immediate());
mainViewModel = new MainViewModel(application, dataListener);
}
use of uk.ivanc.archimvvm.model.GithubService 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.model.GithubService 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;
}
});
}
use of uk.ivanc.archimvvm.model.GithubService in project archi by ivacf.
the class RepositoryViewModelTest method setUp.
@Before
public void setUp() {
githubService = mock(GithubService.class);
application = (ArchiApplication) RuntimeEnvironment.application;
// Mock the retrofit service so we don't call the API directly
application.setGithubService(githubService);
// Change the default subscribe schedulers so all observables
// will now run on the same thread
application.setDefaultSubscribeScheduler(Schedulers.immediate());
// Default behaviour is to load a mock owner when the view model is instantiated
repository = MockModelFabric.newRepository("Repository");
owner = MockModelFabric.newUser("owner");
when(githubService.userFromUrl(repository.owner.url)).thenReturn(Observable.just(owner));
viewModel = new RepositoryViewModel(application, repository);
}
Aggregations