Java 类io.reactivex.observers.DisposableMaybeObserver 实例源码

项目:Profiler    文件:CreateAccountPresenter.java   
public void getUser() {
    disposableSubscriptions.add(auth.getUser()
            .subscribeOn(schedulerProvider.io())
            .observeOn(schedulerProvider.ui())
            .subscribeWith(new DisposableMaybeObserver<User>() {
                @Override
                public void onComplete() {
                    //TODO handle this as an issue
                    view.showProgressIndicator(false);
                }

                @Override
                public void onSuccess(User user) {
                    addUserProfileToDatabase(user.getEmail(), user.getUserId());
                }

                @Override
                public void onError(Throwable e) {
                    view.showProgressIndicator(false);
                    view.makeToast(e.getMessage());
                }
            })

    );
}
项目:Profiler    文件:ProfileDetailPresenter.java   
private void getActiveUser(){
    subscriptions.add(auth.getUser()
            .subscribeOn(schedulerProvider.io())
            .observeOn(schedulerProvider.ui())
            .subscribeWith(new DisposableMaybeObserver<User>() {
                @Override
                public void onSuccess(User user) {
                    getUserProfile(user.getUserId());
                }

                @Override
                public void onError(Throwable e) {
                    view.makeToast(R.string.error_no_data_found);
                }

                @Override
                public void onComplete() {
                    view.startProfilePageActivity();
                }
            })

    );
}
项目:Profiler    文件:ProfileDetailPresenter.java   
private void getUserProfile(String uid) {
    subscriptions.add(database.getProfile(uid)
            .subscribeOn(schedulerProvider.io())
            .observeOn(schedulerProvider.ui())
            .subscribeWith(new DisposableMaybeObserver<Profile>() {
                @Override
                public void onSuccess(Profile profile) {
                    ProfileDetailPresenter.this.currentProfile = profile;
                    view.setBioText(profile.getBio());
                    view.setInterestsText(profile.getInterests());
                }

                @Override
                public void onError(Throwable e) {
                    view.makeToast(R.string.error_no_data_found);
                }

                @Override
                public void onComplete() {
                    view.startProfilePageActivity();
                }
            })

    );
}
项目:Profiler    文件:PhotoGalleryPresenter.java   
private void loadImageURLsIfAvailable(){
    view.showProgressIndicator(true);
    subscriptions.add(photoSource.getThumbnails(resolver)
            .subscribeOn(schedulerProvider.io())
            .observeOn(schedulerProvider.ui())
            .subscribeWith(new DisposableMaybeObserver<List<Photo>>() {
                @Override
                public void onSuccess(List<Photo> photos) {
                    view.showProgressIndicator(false);
                    PhotoGalleryPresenter.this.photos = photos;
                    view.setAdapterData(photos);
                }

                @Override
                public void onError(Throwable e) {
                    view.makeToast(e.getMessage());
                }

                @Override
                public void onComplete() {
                    view.setNoListDataFound();
                }

            })
    );
}
项目:Profiler    文件:PhotoDetailPresenter.java   
private void getCurrentUser() {
    view.showProgressIndicator(true);
    subscriptions.add(auth.getUser()
            .subscribeOn(schedulerProvider.io())
            .observeOn(schedulerProvider.ui())
            .subscribeWith(new DisposableMaybeObserver<User>() {
                @Override
                public void onComplete() {
                    view.startPhotoGalleryActivity();
                }

                @Override
                public void onSuccess(User user) {
                    getCurrentProfile(user.getUserId());
                }

                @Override
                public void onError(Throwable e) {
                    view.startPhotoGalleryActivity();
                    view.makeToast(e.getMessage());
                }
            })

    );
}
项目:Quran    文件:QuranImportPresenter.java   
private void parseIntentUri(final Uri uri) {
  getBookmarkDataObservable(parseUri(uri))
      .observeOn(AndroidSchedulers.mainThread())
      .subscribe(new DisposableMaybeObserver<BookmarkData>() {
        @Override
        public void onSuccess(BookmarkData bookmarkData) {
          if (mCurrentActivity != null) {
            mCurrentActivity.showImportConfirmationDialog(bookmarkData);
          }
        }

        @Override
        public void onError(Throwable e) {
          if (mCurrentActivity != null) {
            handleExternalStorageFile(uri);
          }
        }

        @Override
        public void onComplete() {
          if (mCurrentActivity != null) {
            handleExternalStorageFile(uri);
          }
        }
      });
}
项目:Quran    文件:QuranImportPresenter.java   
private void handleExternalStorageFileInternal(Uri uri) {
  getBookmarkDataObservable(parseExternalFile(uri))
      .observeOn(AndroidSchedulers.mainThread())
      .subscribe(new DisposableMaybeObserver<BookmarkData>() {
        @Override
        public void onSuccess(BookmarkData bookmarkData) {
          if (mCurrentActivity != null) {
            mCurrentActivity.showImportConfirmationDialog(bookmarkData);
          }
        }

        @Override
        public void onError(Throwable e) {
          if (mCurrentActivity != null) {
            mCurrentActivity.showError();
          }
        }

        @Override
        public void onComplete() {
          if (mCurrentActivity != null) {
            mCurrentActivity.showError();
          }
        }
      });
}
项目:rxlint    文件:SubscriberTest.java   
public void rx2MaybeWithSubscriber() {
    io.reactivex.Maybe.just("test").subscribeWith(new DisposableMaybeObserver<String>() {
        @Override
        public void onSuccess(String s) {

        }

        @Override
        public void onError(Throwable e) {

        }

        @Override
        public void onComplete() {

        }
    });
}
项目:commitstrip-reader    文件:ListStripAbstractPresenter.java   
@Override
public void deleteFavorite(Long id) {

    mSubscriptions.add(mStripRepository.deleteFavorite(id).subscribeWith(
            new DisposableMaybeObserver<Integer>() {

                @Override
                public void onSuccess(Integer numberRow) {}

                @Override
                public void onError(Throwable e) {
                    Log.e(TAG, "Could not delete in favorite", e);

                    mListStripView.displayErrorAddFavorite();
                }

                @Override
                public void onComplete() {}
            }));
}
项目:Profiler    文件:ProfilePagePresenter.java   
private void getUserData() {
    view.setThumbnailLoadingIndicator(true);
    view.setDetailLoadingIndicators(true);
    disposableSubscriptions.add(
            auth.getUser().subscribeOn(schedulerProvider.io())
                    .observeOn(schedulerProvider.ui())
                    .subscribeWith(
                            new DisposableMaybeObserver<User>() {

                                @Override
                                public void onError(Throwable e) {
                                    view.makeToast(R.string.error_retrieving_data);
                                    view.startLoginActivity();
                                }

                                @Override
                                public void onComplete() {
                                    view.makeToast(R.string.error_retrieving_data);
                                    view.startLoginActivity();
                                }

                                @Override
                                public void onSuccess(User user) {
                                    ProfilePagePresenter.this.currentUser = user;
                                    getUserProfileFromDatabase();
                                }
                            }
                    )
    );
}
项目:Profiler    文件:ProfilePagePresenter.java   
private void getUserProfileFromDatabase() {
    disposableSubscriptions.add(database.getProfile(currentUser.getUserId())
            .subscribeOn(schedulerProvider.io())
            .observeOn(schedulerProvider.ui())
            .subscribeWith(new DisposableMaybeObserver<Profile>() {
                @Override
                public void onSuccess(Profile profile) {
                    view.setBio(profile.getBio());
                    view.setInterests(profile.getInterests());
                    view.setName(profile.getName());
                    view.setEmail(profile.getEmail());

                    view.setDetailLoadingIndicators(false);
                    String photoURL = profile.getPhotoURL();
                    if (photoURL.equals("")){
                        view.setDefaultProfilePhoto();
                    } else {
                        view.setProfilePhotoURL(profile.getPhotoURL());
                    }

                }

                @Override
                public void onError(Throwable e) {
                    view.makeToast(e.getMessage());
                    view.startLoginActivity();
                }

                @Override
                public void onComplete() {
                    view.startLoginActivity();
                }
            })
    );

}
项目:Profiler    文件:LoginPresenter.java   
/**
 * When this Activity first starts, check and see if there is a currently logged in user.
 * If so, send the user to their Profile Page.
 */
public void getUser() {
    view.showProgressIndicator(true);
    compositeDisposable.add(
            authSource.getUser()
                    .subscribeOn(schedulerProvider.io())
                    .observeOn(schedulerProvider.ui())
                    .subscribeWith(new DisposableMaybeObserver<User>() {
                        /**
                         * If a uses is found, send them straight to their profile
                         * @param user
                         */
                        @Override
                        public void onSuccess(User user) {
                            view.startProfileActivity();
                        }

                        @Override
                        public void onError(Throwable e) {
                            view.showProgressIndicator(false);
                            view.makeToast(e.getMessage());
                        }

                        /**
                         * This method fires, when we don't find a user in the Auth Database.
                         * This is not considered an error!!!
                         */
                        @Override
                        public void onComplete() {
                            view.showProgressIndicator(false);
                        }
                    })
    );
}
项目:Profiler    文件:ProfileSettingsPresenter.java   
private void getCurrentUser() {
    view.showProgressIndicator(true);
    disposableSubscriptions.add(
            auth.getUser()
                    .subscribeOn(schedulerProvider.io())
                    .observeOn(schedulerProvider.ui())
                    .subscribeWith(
                            new DisposableMaybeObserver<User>() {

                                @Override
                                public void onError(Throwable e) {
                                    view.makeToast(R.string.error_retrieving_data);
                                    view.startLogInActivity();
                                }

                                @Override
                                public void onComplete() {
                                    view.showProgressIndicator(false);
                                }

                                @Override
                                public void onSuccess(User user) {
                                    view.showProgressIndicator(false);
                                    ProfileSettingsPresenter.this.uid = user.getUserId();
                                }
                            }
                    )
    );
}
项目:Profiler    文件:PhotoDetailPresenter.java   
private void getCurrentProfile(String uid) {
    subscriptions.add(database.getProfile(uid)
            .subscribeOn(schedulerProvider.io())
            .observeOn(schedulerProvider.ui())
            .subscribeWith(new DisposableMaybeObserver<Profile>() {
                @Override
                public void onComplete() {
                    view.startProfilePageActivity();
                }

                @Override
                public void onSuccess(Profile profile) {
                    PhotoDetailPresenter.this.currentProfile = profile;
                    view.setBitmap();
                    view.showProgressIndicator(true);
                }

                @Override
                public void onError(Throwable e) {
                    view.showProgressIndicator(false);
                    view.makeToast(e.getMessage());
                }

            })

    );
}
项目:LifecycleAwareRx    文件:LifecycleTest.java   
@Test
public void viewsAreNotCalledWhenLifecycleDestroyedWithMaybe() throws Exception {
    Maybe.just("test")
        .compose(LifecycleBinder.bind(lifecycleOwner, new DisposableMaybeObserver<String>() {
            @Override
            public void onSuccess(final String value) {
                LifecycleTest.this.methodOnViewCalled = true;
            }

            @Override
            public void onError(final Throwable e) {
                LifecycleTest.this.onErrorCalled = true;
            }

            @Override
            public void onComplete() {
                LifecycleTest.this.onCompleteCalled = true;
            }
        }));

    lifecycleOwner.handleLifecycleEvent(Lifecycle.Event.ON_START);
    TimeUnit.MILLISECONDS.sleep(100);
    assertEquals(true, methodOnViewCalled);

    lifecycleOwner.handleLifecycleEvent(Lifecycle.Event.ON_DESTROY);
    methodOnViewCalled = false; // Make sure there's a fresh state just as LifecycleOwner hits destroy
    onCompleteCalled = false;
    onErrorCalled = false;

    // Need to wait to give it time to potentially fail
    TimeUnit.MILLISECONDS.sleep(100);
    assertEquals(false, methodOnViewCalled);
    assertEquals(false, onCompleteCalled);
    assertEquals(false, onErrorCalled);
}
项目:LifecycleAwareRx    文件:LifecycleTest.java   
@Test
public void viewsAreOnlyCalledWhenLifecycleActiveWithMaybe() throws Exception {
    Maybe.just("test")
        .compose(LifecycleBinder.bind(lifecycleOwner, new DisposableMaybeObserver<String>() {
            @Override
            public void onSuccess(final String value) {
                LifecycleTest.this.methodOnViewCalled = true;
            }

            @Override
            public void onError(final Throwable e) {
            }

            @Override
            public void onComplete() {
            }
        }));

    // Need to wait to give it time to potentially fail
    TimeUnit.MILLISECONDS.sleep(100);
    assertEquals(false, methodOnViewCalled);

    lifecycleOwner.handleLifecycleEvent(Lifecycle.Event.ON_CREATE);
    TimeUnit.MILLISECONDS.sleep(100);
    assertEquals(false, methodOnViewCalled);

    lifecycleOwner.handleLifecycleEvent(Lifecycle.Event.ON_START);
    TimeUnit.MILLISECONDS.sleep(100);
    // At this point the views should now be called since the lifecycle is active
    assertEquals(true, methodOnViewCalled);
}
项目:WeatherWeight    文件:ForecastPresenter.java   
/**
 * Loads the last forecast ({@link Channel}) that was retrieved when the activity first starts.
 */
public void loadLastForecast() {
    lastForecastStore.get()
            .subscribeOn(schedulerProvider.io())
            .observeOn(schedulerProvider.ui())
            .subscribe(new DisposableMaybeObserver<Channel>() {
                           @Override
                           public void onSuccess(Channel channel) {
                               setChannel(channel);
                               if (isViewAttached()) {
                                   String location = channel.getLocation().toString();
                                   getView().setLocationInputText(location);
                               }
                           }

                           @Override
                           public void onError(Throwable e) {
                               if (isViewAttached()) {
                                   getView().showError(e, false);
                               }
                           }

                           @Override
                           public void onComplete() {
                               if (isViewAttached()) {
                                   getView().showContent();
                               }
                           }
                       });
}
项目:commitstrip-reader    文件:DisplayStripAbstractPresenter.java   
@Override
public void deleteFavorite() {

    if (mCurrentStrip != null && mCurrentStrip.getId() != null) {

        mSubscriptions.add(
                mStripRepository
                        .deleteFavorite(mCurrentStrip.getId())
                        .subscribeOn(Schedulers.newThread())
                        .observeOn(AndroidSchedulers.mainThread())
                        .subscribeWith(new DisposableMaybeObserver<Integer>() {

                            @Override
                            public void onSuccess(Integer numberRowAffected) {
                                if (numberRowAffected > 0) {
                                    mStripView.displayIconIsFavorite(false);
                                }
                            }

                            @Override
                            public void onError(Throwable e) {
                                mStripView.displayErrorAddFavorite();

                                Log.e(TAG, "Could not delete favorite: ", e);
                            }

                            @Override
                            public void onComplete() {}
                        }));

    } else {
        mStripView.displayErrorAddFavorite();
    }
}
项目:Quran    文件:TranslationManagerPresenter.java   
public void getTranslationsList(boolean forceDownload) {
  Observable.concat(
      getCachedTranslationListObservable(forceDownload), getRemoteTranslationListObservable())
      .filter(translationList -> translationList.translations != null)
      .firstElement()
      .filter(translationList -> !translationList.translations.isEmpty())
      .map(translationList -> mergeWithServerTranslations(translationList.translations))
      .subscribeOn(Schedulers.io())
      .observeOn(AndroidSchedulers.mainThread())
      .subscribe(new DisposableMaybeObserver<List<TranslationItem>>() {
        @Override
        public void onSuccess(List<TranslationItem> translationItems) {
          if (currentActivity != null) {
            currentActivity.onTranslationsUpdated(translationItems);
          }

          // used for marking upgrades, irrespective of whether or not there is a bound activity
          boolean updatedTranslations = false;
          for (TranslationItem item : translationItems) {
            if (item.needsUpgrade()) {
              updatedTranslations = true;
              break;
            }
          }
          quranSettings.setHaveUpdatedTranslations(updatedTranslations);
        }

        @Override
        public void onError(Throwable e) {
          if (currentActivity != null) {
            currentActivity.onErrorDownloadTranslations();
          }
        }

        @Override
        public void onComplete() {
          if (currentActivity != null) {
            currentActivity.onErrorDownloadTranslations();
          }
        }
      });
}
项目:commitstrip-reader    文件:FullScreenStripPresenter.java   
@Override
public void fetchStrip(Long id) {

    if (Configuration.isIdCorrect(id)) {

        mSubscriptions.add (
            mStripRepository.fetchStrip(id, false)
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeWith(new DisposableMaybeObserver<StripDto>() {
                    @Override
                    public void onSuccess(StripDto strip) {

                        // Display image
                        mFullScreenStripView.askForDisplayImage(strip);

                        // Update current strip
                        mCurrentStrip = strip;

                        // If we were reading strip in from 0 mode,update last read id and date.
                        long lastReadDate
                                = mStripRepository.fetchLastReadDateFromTheBeginningMode();

                        if (mReadFrom0Mode && strip.getReleaseDate().getTime() > lastReadDate) {
                            mStripRepository.saveLastReadIdFromTheBeginningMode(strip.getId());

                            Long date = strip.getReleaseDate().getTime();
                            mStripRepository.saveLastReadDateFromTheBeginningMode(date);
                        }
                    }

                    @Override
                    public void onError(Throwable e) {
                        Log.e(TAG, "Could not fetch strip: ", e);
                    }

                    @Override
                    public void onComplete() {}
                }));
    }
}