Java Code Examples for io.reactivex.SingleEmitter#onSuccess()

The following examples show how to use io.reactivex.SingleEmitter#onSuccess() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SettingsCheckHandleSingleOnSubscribe.java    From RxGps with Apache License 2.0 6 votes vote down vote up
static void onResolutionResult(String observableId, int resultCode) {
    if (observableMap.containsKey(observableId)) {
        SettingsCheckHandleSingleOnSubscribe observable = observableMap.get(observableId).get();

        if (observable != null && observable.emitterWeakRef != null) {
            SingleEmitter<Boolean> observer = observable.emitterWeakRef.get();

            if (observer != null) {
                observer.onSuccess(resultCode == Activity.RESULT_OK);
            }
        }

        observableMap.remove(observableId);
    }

    observableMapCleanup();
}
 
Example 2
Source File: RxValue.java    From rxfirebase with Apache License 2.0 6 votes vote down vote up
/**
 * @param emit
 * @return
 */
@NonNull
@CheckReturnValue
public static ValueEventListener listener(@NonNull final SingleEmitter<DataSnapshot> emit) {
    return new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            if (!emit.isDisposed()) {
                emit.onSuccess(dataSnapshot);
            }
        }

        @Override
        public void onCancelled(DatabaseError e) {
            if (!emit.isDisposed()) {
                emit.onError(e.toException());
            }
        }
    };
}
 
Example 3
Source File: RxDatabaseReference.java    From rxfirebase with Apache License 2.0 6 votes vote down vote up
/**
 * @param emit
 * @return
 */
@NonNull
@CheckReturnValue
public static ValueEventListener listener(@NonNull final SingleEmitter<DataSnapshot> emit) {
    return new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            if (!emit.isDisposed()) {
                emit.onSuccess(dataSnapshot);
            }
        }

        @Override
        public void onCancelled(DatabaseError e) {
            if (!emit.isDisposed()) {
                emit.onError(e.toException());
            }
        }
    };
}
 
Example 4
Source File: RxTask.java    From ground-android with Apache License 2.0 5 votes vote down vote up
private static <T> void onNullableSuccess(@Nullable T v, SingleEmitter<T> emitter) {
  if (v == null) {
    emitter.onError(new NullPointerException());
  } else {
    emitter.onSuccess(v);
  }
}
 
Example 5
Source File: GoogleSignInResultSingle.java    From eternity with Apache License 2.0 5 votes vote down vote up
@Override
public void subscribe(SingleEmitter<GoogleSignInAccount> emitter) throws Exception {
  if (!result.isSuccess()) {
    emitter.onError(new GoogleSignInException(result));
    return;
  }

  emitter.onSuccess(result.getSignInAccount());
}
 
Example 6
Source File: LocationAvailabilitySingleOnSubscribe.java    From RxGps with Apache License 2.0 5 votes vote down vote up
@Override
protected void onGoogleApiClientReady(GoogleApiClient apiClient, SingleEmitter<Boolean> emitter) {
    //noinspection MissingPermission
    LocationAvailability locationAvailability = LocationServices.FusedLocationApi.getLocationAvailability(apiClient);

    if (locationAvailability != null) {
        emitter.onSuccess(locationAvailability.isLocationAvailable());
    } else {
        emitter.onSuccess(false);
    }
}
 
Example 7
Source File: DisposableUtil.java    From RxAndroidBle with Apache License 2.0 5 votes vote down vote up
public static <T> DisposableSingleObserver<T> disposableSingleObserverFromEmitter(final SingleEmitter<T> emitter) {
    return new DisposableSingleObserver<T>() {

        @Override
        public void onSuccess(T t) {
            emitter.onSuccess(t);
        }

        @Override
        public void onError(Throwable e) {
            emitter.tryOnError(e);
        }
    };
}
 
Example 8
Source File: RxValue.java    From rxfirebase with Apache License 2.0 5 votes vote down vote up
/**
 * @param emitter
 * @param function
 * @return
 */
@NonNull
@CheckReturnValue
public static Transaction.Handler transaction(
        @NonNull final SingleEmitter<DataSnapshot> emitter,
        @NonNull final Function<MutableData, Transaction.Result> function) {
    return new Transaction.Handler() {
        @Override
        public Transaction.Result doTransaction(MutableData mutableData) {
            try {
                return function.apply(mutableData);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }

        @Override
        public void onComplete(@Nullable DatabaseError databaseError,
                               boolean committed,
                               @NonNull DataSnapshot dataSnapshot) {
            if (!emitter.isDisposed()) {
                if (null == databaseError) {
                    emitter.onSuccess(dataSnapshot);
                } else {
                    emitter.onError(databaseError.toException());
                }
            }
        }
    };
}
 
Example 9
Source File: RxDatabaseReference.java    From rxfirebase with Apache License 2.0 5 votes vote down vote up
/**
 * @param emitter
 * @param function
 * @return
 */
@NonNull
@CheckReturnValue
public static Transaction.Handler transaction(
        @NonNull final SingleEmitter<DataSnapshot> emitter,
        @NonNull final Function<MutableData, Transaction.Result> function) {
    return new Transaction.Handler() {
        @Override
        public Transaction.Result doTransaction(MutableData mutableData) {
            try {
                return function.apply(mutableData);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }

        @Override
        public void onComplete(@Nullable DatabaseError databaseError,
                               boolean committed,
                               @NonNull DataSnapshot dataSnapshot) {
            if (!emitter.isDisposed()) {
                if (null == databaseError) {
                    emitter.onSuccess(dataSnapshot);
                } else {
                    emitter.onError(databaseError.toException());
                }
            }
        }
    };
}
 
Example 10
Source File: SingleOnSubscribeExecuteAsBlocking.java    From storio with Apache License 2.0 5 votes vote down vote up
@Override
public void subscribe(@NonNull SingleEmitter<Result> emitter) throws Exception {
    try {
        final Result value = preparedOperation.executeAsBlocking();
        emitter.onSuccess(value);
    } catch (Exception e) {
        emitter.onError(e);
    }
}
 
Example 11
Source File: SingleOnSubscribeExecuteAsBlockingOptional.java    From storio with Apache License 2.0 5 votes vote down vote up
@Override
public void subscribe(@NonNull SingleEmitter<Optional<Result>> emitter) throws Exception {
    try {
        final Result value = preparedOperation.executeAsBlocking();
        emitter.onSuccess(Optional.of(value));
    } catch (Exception e) {
        emitter.onError(e);
    }
}
 
Example 12
Source File: RxDateDialog.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void notifyClick(SingleEmitter<Pair<Period, List<Date>>> callback, Pair<Period, List<Date>> button) {
    callback.onSuccess(button);
}
 
Example 13
Source File: RxDateDialog.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void notifyClickDataSet(SingleEmitter<List<String>> callback, List<String> button) {
    callback.onSuccess(button);
}