Search in sources :

Example 1 with Repository

use of uk.ivanc.archi.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));
}
Also used : Context(android.content.Context) Repository(uk.ivanc.archi.model.Repository)

Example 2 with Repository

use of uk.ivanc.archi.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));
}
Also used : Repository(uk.ivanc.archi.model.Repository) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager)

Example 3 with Repository

use of uk.ivanc.archi.model.Repository in project archi by ivacf.

the class MainActivity method loadGithubRepos.

public void loadGithubRepos(String username) {
    progressBar.setVisibility(View.VISIBLE);
    reposRecycleView.setVisibility(View.GONE);
    infoTextView.setVisibility(View.GONE);
    ArchiApplication application = ArchiApplication.get(this);
    GithubService githubService = application.getGithubService();
    subscription = githubService.publicRepositories(username).observeOn(AndroidSchedulers.mainThread()).subscribeOn(application.defaultSubscribeScheduler()).subscribe(new Subscriber<List<Repository>>() {

        @Override
        public void onCompleted() {
            progressBar.setVisibility(View.GONE);
            if (reposRecycleView.getAdapter().getItemCount() > 0) {
                reposRecycleView.requestFocus();
                hideSoftKeyboard();
                reposRecycleView.setVisibility(View.VISIBLE);
            } else {
                infoTextView.setText(R.string.text_empty_repos);
                infoTextView.setVisibility(View.VISIBLE);
            }
        }

        @Override
        public void onError(Throwable error) {
            Log.e(TAG, "Error loading GitHub repos ", error);
            progressBar.setVisibility(View.GONE);
            if (error instanceof HttpException && ((HttpException) error).code() == 404) {
                infoTextView.setText(R.string.error_username_not_found);
            } else {
                infoTextView.setText(R.string.error_loading_repos);
            }
            infoTextView.setVisibility(View.VISIBLE);
        }

        @Override
        public void onNext(List<Repository> repositories) {
            Log.i(TAG, "Repos loaded " + repositories);
            RepositoryAdapter adapter = (RepositoryAdapter) reposRecycleView.getAdapter();
            adapter.setRepositories(repositories);
            adapter.notifyDataSetChanged();
        }
    });
}
Also used : GithubService(uk.ivanc.archi.model.GithubService) Repository(uk.ivanc.archi.model.Repository) Subscriber(rx.Subscriber) HttpException(retrofit2.adapter.rxjava.HttpException) List(java.util.List)

Example 4 with Repository

use of uk.ivanc.archi.model.Repository in project archi by ivacf.

the class RepositoryActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_repository);
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
    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);
    Repository repository = getIntent().getParcelableExtra(EXTRA_REPOSITORY);
    bindRepositoryData(repository);
    loadFullUser(repository.owner.url);
}
Also used : Repository(uk.ivanc.archi.model.Repository) ActionBar(android.support.v7.app.ActionBar)

Aggregations

Repository (uk.ivanc.archi.model.Repository)4 Context (android.content.Context)1 ActionBar (android.support.v7.app.ActionBar)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 List (java.util.List)1 HttpException (retrofit2.adapter.rxjava.HttpException)1 Subscriber (rx.Subscriber)1 GithubService (uk.ivanc.archi.model.GithubService)1