use of uk.ivanc.archimvvm.model.Repository in project archi by ivacf.
the class MockModelFabric method newRepository.
public static Repository newRepository(String name) {
Random random = new Random();
Repository repository = new Repository();
repository.name = name;
repository.id = random.nextInt(10000);
repository.description = "Description for " + name;
repository.watchers = random.nextInt(100);
repository.forks = random.nextInt(100);
repository.stars = random.nextInt(100);
repository.owner = newUser("User-" + name);
return repository;
}
use of uk.ivanc.archimvvm.model.Repository in project archi by ivacf.
the class RepositoryActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = DataBindingUtil.setContentView(this, R.layout.repository_activity);
setSupportActionBar(binding.toolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
}
Repository repository = getIntent().getParcelableExtra(EXTRA_REPOSITORY);
repositoryViewModel = new RepositoryViewModel(this, repository);
binding.setViewModel(repositoryViewModel);
//Currently there is no way of setting an activity title using data binding
setTitle(repository.name);
}
use of uk.ivanc.archimvvm.model.Repository 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.Repository in project archi by ivacf.
the class ItemRepoViewModelTest method shouldStartActivityOnItemClick.
@Test
public void shouldStartActivityOnItemClick() {
Repository repository = new Repository();
Context mockContext = mock(Context.class);
ItemRepoViewModel itemRepoViewModel = new ItemRepoViewModel(mockContext, repository);
itemRepoViewModel.onItemClick(new View(application));
verify(mockContext).startActivity(any(Intent.class));
}
use of uk.ivanc.archimvvm.model.Repository in project archi by ivacf.
the class ItemRepoViewModelTest method shouldGetName.
@Test
public void shouldGetName() {
Repository repository = new Repository();
repository.name = "ivan";
ItemRepoViewModel itemRepoViewModel = new ItemRepoViewModel(application, repository);
assertEquals(repository.name, itemRepoViewModel.getName());
}
Aggregations