Search in sources :

Example 6 with Repository

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;
}
Also used : Repository(uk.ivanc.archimvvm.model.Repository) Random(java.util.Random)

Example 7 with 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);
}
Also used : Repository(uk.ivanc.archimvvm.model.Repository) RepositoryViewModel(uk.ivanc.archimvvm.viewmodel.RepositoryViewModel) ActionBar(android.support.v7.app.ActionBar)

Example 8 with Repository

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;
        }
    });
}
Also used : GithubService(uk.ivanc.archimvvm.model.GithubService) Repository(uk.ivanc.archimvvm.model.Repository) ArchiApplication(uk.ivanc.archimvvm.ArchiApplication) Subscriber(rx.Subscriber) List(java.util.List)

Example 9 with Repository

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));
}
Also used : Context(android.content.Context) Repository(uk.ivanc.archimvvm.model.Repository) ItemRepoViewModel(uk.ivanc.archimvvm.viewmodel.ItemRepoViewModel) Intent(android.content.Intent) View(android.view.View) Test(org.junit.Test)

Example 10 with Repository

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());
}
Also used : Repository(uk.ivanc.archimvvm.model.Repository) ItemRepoViewModel(uk.ivanc.archimvvm.viewmodel.ItemRepoViewModel) Test(org.junit.Test)

Aggregations

Repository (uk.ivanc.archimvvm.model.Repository)13 Test (org.junit.Test)10 ItemRepoViewModel (uk.ivanc.archimvvm.viewmodel.ItemRepoViewModel)7 TextView (android.widget.TextView)3 Context (android.content.Context)1 Intent (android.content.Intent)1 Observable (android.databinding.Observable)1 ActionBar (android.support.v7.app.ActionBar)1 View (android.view.View)1 List (java.util.List)1 Random (java.util.Random)1 HttpException (retrofit2.adapter.rxjava.HttpException)1 Subscriber (rx.Subscriber)1 ArchiApplication (uk.ivanc.archimvvm.ArchiApplication)1 GithubService (uk.ivanc.archimvvm.model.GithubService)1 RepositoryViewModel (uk.ivanc.archimvvm.viewmodel.RepositoryViewModel)1