本文整理汇总了Java中io.reactivex.MaybeOnSubscribe类的典型用法代码示例。如果您正苦于以下问题:Java MaybeOnSubscribe类的具体用法?Java MaybeOnSubscribe怎么用?Java MaybeOnSubscribe使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MaybeOnSubscribe类属于io.reactivex包,在下文中一共展示了MaybeOnSubscribe类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: observeSingleValueEvent
import io.reactivex.MaybeOnSubscribe; //导入依赖的package包/类
/**
* Listener for a single change in te data at the given query location.
*
* @param query reference represents a particular location in your Database and can be used for reading or writing data to that Database location.
* @return a {@link Maybe} which emits the actual state of the database for the given query.
*/
@NonNull
public static Maybe<DataSnapshot> observeSingleValueEvent(@NonNull final Query query) {
return Maybe.create(new MaybeOnSubscribe<DataSnapshot>() {
@Override
public void subscribe(final MaybeEmitter<DataSnapshot> emitter) throws Exception {
query.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
emitter.onSuccess(dataSnapshot);
emitter.onComplete();
}
@Override
public void onCancelled(DatabaseError error) {
emitter.onError(new RxFirebaseDataException(error));
}
});
}
});
}
示例2: download
import io.reactivex.MaybeOnSubscribe; //导入依赖的package包/类
@Override
public Maybe<Response> download(final Request request) {
return Maybe.create(new MaybeOnSubscribe<CloseableHttpResponse>(){
@Override
public void subscribe(MaybeEmitter emitter) throws Exception {
emitter.onSuccess(httpManager.getResponse(request));
}
}).map(new Function<CloseableHttpResponse, Response>() {
@Override
public Response apply(CloseableHttpResponse closeableHttpResponse) throws Exception {
String html = EntityUtils.toString(closeableHttpResponse.getEntity(), "UTF-8");
Response response = new Response();
response.setContent(html);
response.setStatusCode(closeableHttpResponse.getStatusLine().getStatusCode());
return response;
}
});
}
示例3: verifyCancellation
import io.reactivex.MaybeOnSubscribe; //导入依赖的package包/类
@Test public void verifyCancellation() {
final AtomicInteger i = new AtomicInteger();
//noinspection unchecked because Java
Maybe<Integer> source = Maybe.create(new MaybeOnSubscribe<Integer>() {
@Override public void subscribe(MaybeEmitter<Integer> e) {
e.setCancellable(new Cancellable() {
@Override public void cancel() {
i.incrementAndGet();
}
});
}
});
MaybeSubject<Integer> lifecycle = MaybeSubject.create();
source.as(AutoDispose.<Integer>autoDisposable(lifecycle))
.subscribe();
assertThat(i.get()).isEqualTo(0);
assertThat(lifecycle.hasObservers()).isTrue();
lifecycle.onSuccess(0);
// Verify cancellation was called
assertThat(i.get()).isEqualTo(1);
assertThat(lifecycle.hasObservers()).isFalse();
}
示例4: observeSingleValueEvent
import io.reactivex.MaybeOnSubscribe; //导入依赖的package包/类
/**
* Listener for a single change in te data at the given query location.
*
* @param query reference represents a particular location in your Database and can be used for reading or writing data to that Database location.
* @return a {@link Maybe} which emits the actual state of the database for the given query. onSuccess will be only call when
* the given {@link DataSnapshot} exists onComplete will only called when the data doesn't exist.
*/
@NonNull
public static Maybe<DataSnapshot> observeSingleValueEvent(@NonNull final Query query) {
return Maybe.create(new MaybeOnSubscribe<DataSnapshot>() {
@Override
public void subscribe(final MaybeEmitter<DataSnapshot> emitter) throws Exception {
query.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.exists()) {
emitter.onSuccess(dataSnapshot);
}
else {
emitter.onComplete();
}
}
@Override
public void onCancelled(DatabaseError error) {
emitter.onError(new RxFirebaseDataException(error));
}
});
}
});
}
示例5: get
import io.reactivex.MaybeOnSubscribe; //导入依赖的package包/类
@Override @NonNull public Maybe<T> get() {
return Maybe.create(new MaybeOnSubscribe<T>() {
@Override public void subscribe(final MaybeEmitter<T> emitter) throws Exception {
runInReadLock(readWriteLock, new ThrowingRunnable() {
@Override public void run() throws Exception {
if (!file.exists()) {
emitter.onComplete();
return;
}
T value = converter.read(file, type);
if (value == null) emitter.onComplete();
emitter.onSuccess(value);
}
});
}
});
}
示例6: getProfile
import io.reactivex.MaybeOnSubscribe; //导入依赖的package包/类
@Override
public Maybe<Profile> getProfile(final String uid) {
return Maybe.create(
new MaybeOnSubscribe<Profile>() {
@Override
public void subscribe(final MaybeEmitter e) throws Exception {
final DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
DatabaseReference idRef = rootRef.child(USER_PROFILES).child(uid);
idRef.addListenerForSingleValueEvent(new ValueEventListener() {
//does this check node for activeUser exists?
@Override
public void onDataChange(DataSnapshot snapshot) {
if (snapshot.exists()) {
//setUpProfilePageComponent(
Profile profile = snapshot.getValue(Profile.class);
e.onSuccess(profile);
} else {
e.onComplete();
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
Log.d("FIREBASE", databaseError.toString());
}
});
}
}
);
}
示例7: getThumbnails
import io.reactivex.MaybeOnSubscribe; //导入依赖的package包/类
@Override
public Maybe<List<Photo>> getThumbnails(final ContentResolver resolver) {
return Maybe.create(
new MaybeOnSubscribe<List<Photo>>() {
@Override
public void subscribe(final MaybeEmitter<List<Photo>> e) throws Exception {
Uri uri;
List<Photo> listOfAllPhotos = new ArrayList<Photo>();
Cursor cursor;
int column_index_data;
Uri imageUri;
uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
String[] projection = {MediaStore.MediaColumns.DATA};
cursor = resolver.query(uri, projection, null,
null, null);
try {
column_index_data = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA);
while (cursor.moveToNext()) {
imageUri = Uri.parse("file://" + cursor.getString(column_index_data));
listOfAllPhotos.add(new Photo(imageUri.toString()));
}
cursor.close();
} catch (Throwable t) {
if (cursor != null) {
cursor.close();
}
e.onError(t);
}
if (listOfAllPhotos.size() == 0) {
e.onComplete();
} else {
e.onSuccess(listOfAllPhotos);
}
}
}
);
}
示例8: getUser
import io.reactivex.MaybeOnSubscribe; //导入依赖的package包/类
@Override
public Maybe<User> getUser() {
return Maybe.create(
new MaybeOnSubscribe<User>() {
@Override
public void subscribe(final MaybeEmitter<User> e) throws Exception {
if (auth == null) {
auth = FirebaseAuth.getInstance();
}
if (listener != null) {
auth.removeAuthStateListener(listener);
}
listener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
FirebaseUser firebaseUser = firebaseAuth.getCurrentUser();
auth.removeAuthStateListener(listener);
if (firebaseUser != null) {
User user = new User(
firebaseUser.getEmail(),
firebaseUser.getUid()
);
Maybe.just(user);
e.onSuccess(user);
} else {
e.onComplete();
}
}
};
auth.addAuthStateListener(listener);
}
}
);
}
示例9: getToken
import io.reactivex.MaybeOnSubscribe; //导入依赖的package包/类
/**
* Fetches a Firebase Auth ID Token for the user; useful when authenticating against your own backend.
*
* @param firebaseUser current firebaseUser instance.
* @param forceRefresh force to refresh the token ID.
* @return a {@link Maybe} which emits an {@link GetTokenResult} if success.
*/
@NonNull
public static Maybe<GetTokenResult> getToken(@NonNull final FirebaseUser firebaseUser,
final boolean forceRefresh) {
return Maybe.create(new MaybeOnSubscribe<GetTokenResult>() {
@Override
public void subscribe(MaybeEmitter<GetTokenResult> emitter) throws Exception {
RxHandler.assignOnTask(emitter, firebaseUser.getToken(forceRefresh));
}
});
}
示例10: linkWithCredential
import io.reactivex.MaybeOnSubscribe; //导入依赖的package包/类
/**
* Attaches the given {@link AuthCredential} to the user.
*
* @param firebaseUser current firebaseUser instance.
* @param credential new {@link AuthCredential} to link.
* @return a {@link Maybe} which emits an {@link AuthResult} if success.
*/
@NonNull
public static Maybe<AuthResult> linkWithCredential(@NonNull final FirebaseUser firebaseUser,
@NonNull final AuthCredential credential) {
return Maybe.create(new MaybeOnSubscribe<AuthResult>() {
@Override public void subscribe(MaybeEmitter<AuthResult> emitter) throws Exception {
RxHandler.assignOnTask(emitter, firebaseUser.linkWithCredential(credential));
}
});
}
示例11: unlink
import io.reactivex.MaybeOnSubscribe; //导入依赖的package包/类
/**
* Detaches credentials from a given provider type from this user.
*
* @param firebaseUser current firebaseUser instance.
* @param provider a unique identifier of the type of provider to be unlinked, for example, {@link com.google.firebase.auth.FacebookAuthProvider#PROVIDER_ID}.
* @return a {@link Maybe} which emits an {@link AuthResult} if success.
*/
@NonNull
public static Maybe<AuthResult> unlink(@NonNull final FirebaseUser firebaseUser,
@NonNull final String provider) {
return Maybe.create(new MaybeOnSubscribe<AuthResult>() {
@Override public void subscribe(MaybeEmitter<AuthResult> emitter) throws Exception {
RxHandler.assignOnTask(emitter, firebaseUser.unlink(provider));
}
});
}
示例12: signInAnonymously
import io.reactivex.MaybeOnSubscribe; //导入依赖的package包/类
/**
* Asynchronously signs in as an anonymous user.
* If there is already an anonymous user signed in, that user will be returned; otherwise, a new anonymous user identity will be created and returned.
*
* @param firebaseAuth firebaseAuth instance.
* @return a {@link Maybe} which emits an {@link AuthResult} if success.
* @see <a href="https://firebase.google.com/docs/reference/android/com/google/firebase/auth/FirebaseAuth">Firebase Auth API</a>
*/
@NonNull
public static Maybe<AuthResult> signInAnonymously(@NonNull final FirebaseAuth firebaseAuth) {
return Maybe.create(new MaybeOnSubscribe<AuthResult>() {
@Override
public void subscribe(MaybeEmitter<AuthResult> emitter) throws Exception {
RxHandler.assignOnTask(emitter, firebaseAuth.signInAnonymously());
}
});
}
示例13: signInWithCredential
import io.reactivex.MaybeOnSubscribe; //导入依赖的package包/类
/**
* Asynchronously signs in with the given credentials.
*
* @param firebaseAuth firebaseAuth instance.
* @param credential The auth credential. Value must not be null.
* @return a {@link Maybe} which emits an {@link AuthResult} if success.
* @see <a href="https://firebase.google.com/docs/reference/android/com/google/firebase/auth/FirebaseAuth">Firebase Auth API</a>
*/
@NonNull
public static Maybe<AuthResult> signInWithCredential(@NonNull final FirebaseAuth firebaseAuth,
@NonNull final AuthCredential credential) {
return Maybe.create(new MaybeOnSubscribe<AuthResult>() {
@Override
public void subscribe(MaybeEmitter<AuthResult> emitter) throws Exception {
RxHandler.assignOnTask(emitter, firebaseAuth.signInWithCredential(credential));
}
});
}
示例14: fetchProvidersForEmail
import io.reactivex.MaybeOnSubscribe; //导入依赖的package包/类
/**
* Gets the list of provider IDs that can be used to sign in for the given email address. Useful for an "identifier-first" sign-in flow.
*
* @param firebaseAuth firebaseAuth instance.
* @param email An email address.
* @return a {@link Maybe} which emits an {@link ProviderQueryResult} if success.
* @see <a href="https://firebase.google.com/docs/reference/android/com/google/firebase/auth/FirebaseAuth">Firebase Auth API</a>
*/
@NonNull
public static Maybe<ProviderQueryResult> fetchProvidersForEmail(@NonNull final FirebaseAuth firebaseAuth,
@NonNull final String email) {
return Maybe.create(new MaybeOnSubscribe<ProviderQueryResult>() {
@Override
public void subscribe(MaybeEmitter<ProviderQueryResult> emitter) throws Exception {
RxHandler.assignOnTask(emitter, firebaseAuth.fetchProvidersForEmail(email));
}
});
}
示例15: checkActionCode
import io.reactivex.MaybeOnSubscribe; //导入依赖的package包/类
/**
* Checks that the code given is valid. This code will have been generated
* by {@link FirebaseAuth#sendPasswordResetEmail(String)} or {@link com.google.firebase.auth.FirebaseUser#sendEmailVerification()} valid for a single use.
*
* @param firebaseAuth firebaseAuth instance.
* @param code generated code by firebase.
* @return a {@link Maybe} which emits when the action is completed.
*/
@NonNull
public static Maybe<ActionCodeResult> checkActionCode(@NonNull final FirebaseAuth firebaseAuth,
@NonNull final String code) {
return Maybe.create(new MaybeOnSubscribe<ActionCodeResult>() {
@Override
public void subscribe(MaybeEmitter<ActionCodeResult> emitter) throws Exception {
RxHandler.assignOnTask(emitter, firebaseAuth.checkActionCode(code));
}
});
}