use of io.reark.reark.data.DataStreamNotification 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);
}));
}
Aggregations