Search in sources :

Example 1 with DataStreamNotification

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);
    }));
}
Also used : RemoteViews(android.widget.RemoteViews) R(io.reark.rxgithubapp.R) UserSettings(io.reark.rxgithubapp.shared.pojo.UserSettings) Log(io.reark.reark.utils.Log) Service(android.app.Service) Intent(android.content.Intent) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) IBinder(android.os.IBinder) AppWidgetManager(android.appwidget.AppWidgetManager) Inject(javax.inject.Inject) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Glide(com.bumptech.glide.Glide) AppWidgetTarget(com.bumptech.glide.request.target.AppWidgetTarget) RxGitHubApp(io.reark.rxgithubapp.advanced.RxGitHubApp) Schedulers(io.reactivex.schedulers.Schedulers) DataStreamNotification(io.reark.reark.data.DataStreamNotification) DataFunctions(io.reark.rxgithubapp.shared.data.DataFunctions) RemoteViews(android.widget.RemoteViews) AppWidgetTarget(com.bumptech.glide.request.target.AppWidgetTarget) UserSettings(io.reark.rxgithubapp.shared.pojo.UserSettings) DataStreamNotification(io.reark.reark.data.DataStreamNotification) AppWidgetManager(android.appwidget.AppWidgetManager)

Aggregations

Service (android.app.Service)1 AppWidgetManager (android.appwidget.AppWidgetManager)1 Intent (android.content.Intent)1 IBinder (android.os.IBinder)1 RemoteViews (android.widget.RemoteViews)1 Glide (com.bumptech.glide.Glide)1 AppWidgetTarget (com.bumptech.glide.request.target.AppWidgetTarget)1 AndroidSchedulers (io.reactivex.android.schedulers.AndroidSchedulers)1 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)1 Schedulers (io.reactivex.schedulers.Schedulers)1 DataStreamNotification (io.reark.reark.data.DataStreamNotification)1 Log (io.reark.reark.utils.Log)1 R (io.reark.rxgithubapp.R)1 RxGitHubApp (io.reark.rxgithubapp.advanced.RxGitHubApp)1 DataFunctions (io.reark.rxgithubapp.shared.data.DataFunctions)1 UserSettings (io.reark.rxgithubapp.shared.pojo.UserSettings)1 Inject (javax.inject.Inject)1