当前位置: 首页>>代码示例>>Java>>正文


Java MaybeOnSubscribe类代码示例

本文整理汇总了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));
            }
         });
      }
   });
}
 
开发者ID:DVT,项目名称:showcase-android,代码行数:27,代码来源:RxFirebaseDatabase.java

示例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;
        }
    });
}
 
开发者ID:fengzhizi715,项目名称:NetDiscovery,代码行数:24,代码来源:HttpClientDownloader.java

示例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();
}
 
开发者ID:uber,项目名称:AutoDispose,代码行数:26,代码来源:AutoDisposeMaybeObserverTest.java

示例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));
            }
         });
      }
   });
}
 
开发者ID:FrangSierra,项目名称:Rx2Firebase,代码行数:32,代码来源:RxFirebaseDatabase.java

示例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);
        }
      });
    }
  });
}
 
开发者ID:Gridstone,项目名称:RxStore,代码行数:19,代码来源:RealValueStore.java

示例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());
                        }
                    });
                }
            }
    );
}
 
开发者ID:BracketCove,项目名称:Profiler,代码行数:31,代码来源:FirebaseDatabaseService.java

示例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);
                    }
                }
            }
    );
}
 
开发者ID:BracketCove,项目名称:Profiler,代码行数:41,代码来源:PhotoService.java

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

}
 
开发者ID:BracketCove,项目名称:Profiler,代码行数:39,代码来源:FirebaseAuthService.java

示例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));
      }
   });
}
 
开发者ID:DVT,项目名称:showcase-android,代码行数:18,代码来源:RxFirebaseUser.java

示例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));
      }
   });
}
 
开发者ID:DVT,项目名称:showcase-android,代码行数:17,代码来源:RxFirebaseUser.java

示例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));
      }
   });
}
 
开发者ID:DVT,项目名称:showcase-android,代码行数:17,代码来源:RxFirebaseUser.java

示例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());
      }
   });
}
 
开发者ID:DVT,项目名称:showcase-android,代码行数:18,代码来源:RxFirebaseAuth.java

示例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));
      }
   });
}
 
开发者ID:DVT,项目名称:showcase-android,代码行数:19,代码来源:RxFirebaseAuth.java

示例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));
      }
   });
}
 
开发者ID:DVT,项目名称:showcase-android,代码行数:19,代码来源:RxFirebaseAuth.java

示例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));
      }
   });
}
 
开发者ID:DVT,项目名称:showcase-android,代码行数:19,代码来源:RxFirebaseAuth.java


注:本文中的io.reactivex.MaybeOnSubscribe类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。