use of uk.ivanc.archimvp.model.Repository in project archi by ivacf.
the class MainActivity method setupRecyclerView.
private void setupRecyclerView(RecyclerView recyclerView) {
RepositoryAdapter adapter = new RepositoryAdapter();
adapter.setCallback(new RepositoryAdapter.Callback() {
@Override
public void onItemClick(Repository repository) {
startActivity(RepositoryActivity.newIntent(MainActivity.this, repository));
}
});
recyclerView.setAdapter(adapter);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
}
use of uk.ivanc.archimvp.model.Repository in project archi by ivacf.
the class RepositoryActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
presenter = new RepositoryPresenter();
presenter.attachView(this);
setContentView(R.layout.activity_repository);
toolbar = (Toolbar) findViewById(R.id.toolbar);
descriptionText = (TextView) findViewById(R.id.text_repo_description);
homepageText = (TextView) findViewById(R.id.text_homepage);
languageText = (TextView) findViewById(R.id.text_language);
forkText = (TextView) findViewById(R.id.text_fork);
ownerNameText = (TextView) findViewById(R.id.text_owner_name);
ownerEmailText = (TextView) findViewById(R.id.text_owner_email);
ownerLocationText = (TextView) findViewById(R.id.text_owner_location);
ownerImage = (ImageView) findViewById(R.id.image_owner);
ownerLayout = findViewById(R.id.layout_owner);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
}
Repository repository = getIntent().getParcelableExtra(EXTRA_REPOSITORY);
bindRepositoryData(repository);
presenter.loadOwner(repository.owner.url);
}
use of uk.ivanc.archimvp.model.Repository in project archi by ivacf.
the class RepositoryAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(RepositoryViewHolder holder, int position) {
Repository repository = repositories.get(position);
Context context = holder.titleTextView.getContext();
holder.repository = repository;
holder.titleTextView.setText(repository.name);
holder.descriptionTextView.setText(repository.description);
holder.watchersTextView.setText(context.getResources().getString(R.string.text_watchers, repository.watchers));
holder.starsTextView.setText(context.getResources().getString(R.string.text_stars, repository.stars));
holder.forksTextView.setText(context.getResources().getString(R.string.text_forks, repository.forks));
}
use of uk.ivanc.archimvp.model.Repository in project archi by ivacf.
the class MainPresenter method loadRepositories.
public void loadRepositories(String usernameEntered) {
String username = usernameEntered.trim();
if (username.isEmpty())
return;
mainMvpView.showProgressIndicator();
if (subscription != null)
subscription.unsubscribe();
ArchiApplication application = ArchiApplication.get(mainMvpView.getContext());
GithubService githubService = application.getGithubService();
subscription = githubService.publicRepositories(username).observeOn(AndroidSchedulers.mainThread()).subscribeOn(application.defaultSubscribeScheduler()).subscribe(new Subscriber<List<Repository>>() {
@Override
public void onCompleted() {
Log.i(TAG, "Repos loaded " + repositories);
if (!repositories.isEmpty()) {
mainMvpView.showRepositories(repositories);
} else {
mainMvpView.showMessage(R.string.text_empty_repos);
}
}
@Override
public void onError(Throwable error) {
Log.e(TAG, "Error loading GitHub repos ", error);
if (isHttp404(error)) {
mainMvpView.showMessage(R.string.error_username_not_found);
} else {
mainMvpView.showMessage(R.string.error_loading_repos);
}
}
@Override
public void onNext(List<Repository> repositories) {
MainPresenter.this.repositories = repositories;
}
});
}
use of uk.ivanc.archimvp.model.Repository in project archi by ivacf.
the class MainPresenterTest method loadRepositoriesCallsShowMessage_withUsernameNotFoundString.
@Test
public void loadRepositoriesCallsShowMessage_withUsernameNotFoundString() {
String username = "ivacf";
HttpException mockHttpException = new HttpException(Response.error(404, mock(ResponseBody.class)));
when(githubService.publicRepositories(username)).thenReturn(Observable.<List<Repository>>error(mockHttpException));
mainPresenter.loadRepositories(username);
verify(mainMvpView).showProgressIndicator();
verify(mainMvpView).showMessage(R.string.error_username_not_found);
}
Aggregations