Java Code Examples for io.reactivex.Observable.just()

The following are Jave code examples for showing how to use just() of the io.reactivex.Observable class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: GitHub   File: SearchInteractor.java   View Source Code Vote up 6 votes
/**
 * Search for items
 */
public Observable<SearchViewState> search(String searchString) {
  // Empty String, so no search
  if (searchString.isEmpty()) {
    return Observable.just(new SearchViewState.SearchNotStartedYet());
  }

  // search for product
  return searchEngine.searchFor(searchString)
      .map(products -> {
        if (products.isEmpty()) {
          return new SearchViewState.EmptyResult(searchString);
        } else {
          return new SearchViewState.SearchResult(searchString, products);
        }
      })
      .startWith(new SearchViewState.Loading())
      .onErrorReturn(error -> new SearchViewState.Error(searchString, error));
}
 
Example 2
Project: Learning-RxJava   File: Ch4_9.java   View Source Code Vote up 6 votes
public static void main(String[] args) {
    Observable<String> source1 =
            Observable.just("Alpha", "Beta", "Gamma", "Delta",
                    "Epsilon");
    Observable<String> source2 =
            Observable.just("Zeta", "Eta", "Theta");
    Observable.concat(source1, source2)
            .subscribe(i -> System.out.println("RECEIVED: " + i));
}
 
Example 3
Project: Ghost-Android   File: PostEditFragment.java   View Source Code Vote up 6 votes
public Observable<Boolean> onSaveClicked() {
    // can't use cleverness like !PostUtils.isDirty(mLastSavedPost, mPost) here
    // consider: edit published post => hit back to auto-save => open again and hit "Save"
    // in this case we will end up not asking for confirmation! here again, we're conflating 2
    // kinds of "dirtiness": (1) dirty relative to auto-saved post, and, (2) dirty relative to
    // post on server TODO fix this behaviour!
    if (mPost.isDraft()) {
        return Observable.just(saveToServerExplicitly());
    }
    return Observables.getDialog(emitter -> {
        // confirm save for scheduled and published posts
        return new AlertDialog.Builder(mActivity)
                .setMessage(getString(R.string.alert_save_msg))
                .setPositiveButton(R.string.alert_save_yes, (dialog, which) -> {
                    emitter.onNext(saveToServerExplicitly());
                    emitter.onComplete();
                })
                .setNegativeButton(R.string.alert_save_no, (dialog, which) -> {
                    dialog.dismiss();
                    emitter.onNext(false);
                    emitter.onComplete();
                })
                .create();
    });
}
 
Example 4
Project: RxNetWork   File: ApplyImpl.java   View Source Code Vote up 5 votes
@Override
public <T> Observable<CacheResult<T>> applyCacheNetWork(@NonNull final Object key, Observable<T> observable, final LruDisk lruDisk, TypeToken<T> typeToken, boolean network) {
    final T query = lruDisk.query(key, typeToken);
    return (query == null || network) ?
            apply(key, observable, lruDisk, true)
            :
            Observable.just(new CacheResult<>(query, key, CacheResult.CacheType.CACHE));
}
 
Example 5
Project: code-examples-android-expert   File: RxJavaUnitTest.java   View Source Code Vote up 5 votes
@Test
public void returnAValue(){
    result = "";
    Observable<String> observer = Observable.just("Hello"); // provides datea
    observer.subscribe(s -> result=s); // Callable as subscriber
    assertTrue(result.equals("Hello"));
}
 
Example 6
Project: RxAndroid-Examples   File: DataSource.java   View Source Code Vote up 5 votes
public static Observable<ArrayList<String>> getSearchData(String key) {
    ArrayList<String> data = getStudentList();
    ArrayList<String> result = new ArrayList<String>();
    for (int i = 0; i < data.size(); i++) {
        if (data.get(i).toUpperCase().contains(key.toUpperCase())) {
            result.add(data.get(i));
        }
    }
    Observable<ArrayList<String>> observable = Observable.just(result);
    return observable;
}
 
Example 7
Project: Learning-RxJava   File: Ch4_5.java   View Source Code Vote up 5 votes
public static void main(String[] args) {
    Observable<String> source =
            Observable.just("Alpha", "Beta", "Gamma", "Delta",
                    "Epsilon");
    source.flatMap(s -> Observable.fromArray(s.split("")))
            .subscribe(System.out::println);
}
 
Example 8
Project: Auto.js   File: Modules.java   View Source Code Vote up 5 votes
public Observable<List<Module>> getModules(Context context) {
    if (mModules != null)
        return Observable.just(mModules);
    return Observable.fromCallable(() -> loadModulesFrom(context.getAssets().open(MODULES_JSON_PATH)))
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .doOnNext(modules -> mModules = modules);
}
 
Example 9
Project: Learning-RxJava   File: Ch10_5.java   View Source Code Vote up 5 votes
@Test
public void testSingle() {
    Observable<String> source =
            Observable.just("Alpha", "Beta", "Gamma", "Delta",
                    "Zeta");
    List<String> allWithLengthFour = source.filter(s ->
            s.length() == 4)
            .toList()
            .blockingGet();
    assertTrue(allWithLengthFour.equals(Arrays.asList("Beta","Zeta")));
}
 
Example 10
Project: Reactive-Programming-With-Java-9   File: Demo_concat.java   View Source Code Vote up 5 votes
public static void main(String[] args) {
	// TODO Auto-generated method stub
	Observable source1=	Observable.range(1,5);
	Observable source2=Observable.just(10,20,30);
	Observable.concat(source1,source2).subscribe(new Consumer<Integer>() {

		@Override
		public void accept(Integer value) throws Exception {
			// TODO Auto-generated method stub
			System.out.println(value);
			
		}
	});

}
 
Example 11
Project: SyncMarket   File: SyncMarket.java   View Source Code Vote up 5 votes
private static Observable<String> getCallableObservable(final String selects) {
    if(isNetworkAvailable()) {
        Observable<String> observable = Observable.fromCallable(new Callable<String>() {
            @Override
            public String call() throws Exception {
                return getAttrFromNetwork(selects);
            }
        })
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread());
        return observable;
    } else
        Log.e(TAG, "check your network connection");
    return Observable.just("");
}
 
Example 12
Project: AesExoPlayer   File: RxPermissions.java   View Source Code Vote up 4 votes
private Observable<?> oneOf(Observable<?> trigger, Observable<?> pending) {
    if (trigger == null) {
        return Observable.just(new Object());
    }
    return Observable.merge(trigger, pending);
}
 
Example 13
Project: Flax   File: FlaxActionObservableBuilder.java   View Source Code Vote up 4 votes
public FlaxActionObservableBuilder() {
    actionObservable = Observable.just(new FlaxAction(FlaxAction.NONE));
}
 
Example 14
Project: EditPhoto   File: ContrastView.java   View Source Code Vote up 4 votes
private Observable<ColorMatrixColorFilter> postContrast(float value) {
    return Observable.just(contrast(value));
}
 
Example 15
Project: RxJava2-Android-Sample   File: BufferExampleActivity.java   View Source Code Vote up 4 votes
private Observable<String> getObservable() {
    return Observable.just("one", "two", "three", "four", "five");
}
 
Example 16
Project: jobson   File: TestHelpers.java   View Source Code Vote up 4 votes
public static Observable<byte[]> generateRandomByteObservable() {
    return Observable.just(generateRandomBytes());
}
 
Example 17
Project: buckaroo   File: HelpCommand.java   View Source Code Vote up 4 votes
@Override
public Function<FileSystem, Observable<Event>> routine() {
    return fs -> Observable.just(Notification.of("Read the docs at: \n" +
        "https://buckaroo.readthedocs.io/en/latest/cli.html"));
}
 
Example 18
Project: simple-stack   File: Chat.java   View Source Code Vote up 4 votes
public Observable<Message> getMessage(int index) {
    return Observable.just(messages.get(index));
}
 
Example 19
Project: Reactive-Programming-With-Java-9   File: Demo_Create_Observable.java   View Source Code Vote up 4 votes
public static void main(String[] args) {
	// TODO Auto-generated method stub
	Observable observable=Observable.just("Welcome to RxJava");
	observable.subscribe(s->System.out.println(s));
}
 
Example 20
Project: AesExoPlayer   File: RxPermissions.java   View Source Code Vote up 3 votes
/**
 * Invokes Activity.shouldShowRequestPermissionRationale and wraps
 * the returned value in an observable.
 * <p>
 * In case of multiple permissions, only emits true if
 * Activity.shouldShowRequestPermissionRationale returned true for
 * all revoked permissions.
 * <p>
 * You shouldn't call this method if all permissions have been granted.
 * <p>
 * For SDK &lt; 23, the observable will always emit false.
 */
@SuppressWarnings("WeakerAccess")
public Observable<Boolean> shouldShowRequestPermissionRationale(final Activity activity, final String... permissions) {
    if (!isMarshmallow()) {
        return Observable.just(false);
    }
    return Observable.just(shouldShowRequestPermissionRationaleImplementation(activity, permissions));
}