use of io.reark.rxgithubapp.shared.pojo.UserSettings in project reark by reark.
the class WidgetService method updateWidget.
private void updateWidget(final int widgetId) {
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(getApplicationContext());
RemoteViews remoteViews = new RemoteViews(getApplication().getPackageName(), R.layout.widget_layout);
remoteViews.setTextViewText(R.id.widget_layout_title, "Loading repository..");
appWidgetManager.updateAppWidget(widgetId, remoteViews);
clearDisposable();
compositeDisposable.add(getUserSettings.call().map(UserSettings::getSelectedRepositoryId).doOnNext(repositoryId -> Log.d(TAG, "Changed repository to " + repositoryId)).switchMap(fetchAndGetGitHubRepository::call).filter(DataStreamNotification::isOnNext).map(DataStreamNotification::getValue).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(repository -> {
remoteViews.setTextViewText(R.id.widget_layout_title, repository.getName());
remoteViews.setTextViewText(R.id.widget_layout_stargazers, "stars: " + repository.getStargazersCount());
remoteViews.setTextViewText(R.id.widget_layout_forks, "forks: " + repository.getForksCount());
AppWidgetTarget widgetTarget = new AppWidgetTarget(WidgetService.this, remoteViews, R.id.widget_avatar_image_view, widgetId);
Glide.with(WidgetService.this).load(repository.getOwner().getAvatarUrl()).asBitmap().fitCenter().into(widgetTarget);
appWidgetManager.updateAppWidget(widgetId, remoteViews);
}));
}
use of io.reark.rxgithubapp.shared.pojo.UserSettings in project reark by reark.
the class MainActivity method onActivityResult.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.d(TAG, "onActivityResult");
if (data == null) {
Log.d(TAG, "No data from onActivityResult");
return;
}
final int repositoryId = data.getIntExtra("repositoryId", 0);
if (repositoryId == 0) {
Log.e(TAG, "Invalid repositoryId from onActivityResult");
return;
}
Log.d(TAG, "New repositoryId: " + repositoryId);
// We should probably send an intent to update the widget
// in case its service is not alive anymore. This works as
// long as it is alive, though.
setUserSettings.call(new UserSettings(repositoryId));
}
use of io.reark.rxgithubapp.shared.pojo.UserSettings in project reark by reark.
the class RepositoryViewModelTest method testRepositoryViewModelFetchesValidGitHubRepository.
@Test(timeout = 1000)
public void testRepositoryViewModelFetchesValidGitHubRepository() throws Exception {
GitHubRepository gitHubRepository = new GitHubRepository(2, "repo", 3, 4, mock(GitHubOwner.class));
RepositoryViewModel repositoryViewModel = new RepositoryViewModel(() -> Observable.just(new UserSettings(1)), repositoryId -> Observable.just(gitHubRepository));
TestSubscriber<GitHubRepository> observer = new TestSubscriber<>();
repositoryViewModel.getRepository().subscribe(observer);
repositoryViewModel.subscribeToDataStore();
observer.awaitTerminalEvent();
assertEquals("Invalid number of repositories", 1, observer.getOnNextEvents().size());
assertEquals("Provided GitHubRepository does not match", gitHubRepository, observer.getOnNextEvents().get(0));
}
use of io.reark.rxgithubapp.shared.pojo.UserSettings in project reark by reark.
the class MainActivity method onActivityResult.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.d(TAG, "onActivityResult");
if (data == null) {
Log.d(TAG, "No data from onActivityResult");
return;
}
final int repositoryId = data.getIntExtra("repositoryId", 0);
if (repositoryId == 0) {
Log.e(TAG, "Invalid repositoryId from onActivityResult");
return;
}
Log.d(TAG, "New repositoryId: " + repositoryId);
// We should probably send an intent to update the widget
// in case its service is not alive anymore. This works as
// long as it is alive, though.
setUserSettings.call(new UserSettings(repositoryId));
}
Aggregations