Search in sources :

Example 1 with RepositoryViewModel

use of uk.ivanc.archimvvm.viewmodel.RepositoryViewModel 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 2 with RepositoryViewModel

use of uk.ivanc.archimvvm.viewmodel.RepositoryViewModel 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);
}
Also used : GithubService(uk.ivanc.archimvvm.model.GithubService) RepositoryViewModel(uk.ivanc.archimvvm.viewmodel.RepositoryViewModel) Before(org.junit.Before)

Aggregations

RepositoryViewModel (uk.ivanc.archimvvm.viewmodel.RepositoryViewModel)2 ActionBar (android.support.v7.app.ActionBar)1 Before (org.junit.Before)1 GithubService (uk.ivanc.archimvvm.model.GithubService)1 Repository (uk.ivanc.archimvvm.model.Repository)1