Search in sources :

Example 1 with UserSettings

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);
    }));
}
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)

Example 2 with UserSettings

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));
}
Also used : UserSettings(io.reark.rxgithubapp.shared.pojo.UserSettings)

Example 3 with UserSettings

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));
}
Also used : UserSettings(io.reark.rxgithubapp.shared.pojo.UserSettings) GitHubOwner(io.reark.rxgithubapp.shared.pojo.GitHubOwner) TestSubscriber(rx.observers.TestSubscriber) GitHubRepository(io.reark.rxgithubapp.shared.pojo.GitHubRepository) Test(org.junit.Test)

Example 4 with UserSettings

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));
}
Also used : UserSettings(io.reark.rxgithubapp.shared.pojo.UserSettings)

Aggregations

UserSettings (io.reark.rxgithubapp.shared.pojo.UserSettings)4 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 GitHubOwner (io.reark.rxgithubapp.shared.pojo.GitHubOwner)1 GitHubRepository (io.reark.rxgithubapp.shared.pojo.GitHubRepository)1 Inject (javax.inject.Inject)1 Test (org.junit.Test)1