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

项目:android-permission-checker-app    文件:PermissionGroupPresenterImpl.java   
private void fetchData() {
  getView().showProgressBar();
  getView().hideListView();
  getCompositeDisposable().add(getDataProvider().getPermissionGroups(false)
      .subscribeOn(Schedulers.computation())
      .observeOn(AndroidSchedulers.mainThread())
      .subscribeWith(new DisposableSingleObserver<ArrayList<PermissionGroupDetails>>() {
        @Override
        public void onSuccess(ArrayList<PermissionGroupDetails> permissionGroupDetails) {
          getView().hideProgressBar();
          getView().showListView();
          permissionList = permissionGroupDetails;
          getView().notifyListAdapter();
        }

        @Override public void onError(Throwable e) {

        }
      }));
}
项目:android-permission-checker-app    文件:AppDetailsPresenterImpl.java   
private void extractAPK() {
  getCompositeDisposable().add(createDirectoryAndExtractApk().subscribeOn(Schedulers.io())
      .observeOn(AndroidSchedulers.mainThread())
      .subscribeWith(new DisposableSingleObserver<String>() {
        @Override public void onSuccess(String filePath) {
          getView().onExtractionComplete(filePath);
        }

        @Override public void onError(Throwable e) {
          if (e instanceof IllegalStateException) {
            getView().showFileExitsAlert();
            return;
          }
          getView().showError("APK extraction failed");
        }
      }));
}
项目:android-permission-checker-app    文件:AppListPresenterImpl.java   
private void getAppDetails() {
  if (appDetailList != null) {
    return;
  }
  getView().showProgressBar();
  getView().hideListView();

  getCompositeDisposable().add(getDataProvider().getAppDetailsList(packages, false)
      .subscribeOn(Schedulers.computation())
      .observeOn(AndroidSchedulers.mainThread())
      .subscribeWith(new DisposableSingleObserver<ArrayList<AppDetails>>() {
        @Override public void onSuccess(ArrayList<AppDetails> appDetails) {
          getView().hideProgressBar();
          getView().showListView();
          if (appDetailList != appDetails) {
            appDetailList = appDetails;
            getView().notifyListAdapter();
          }
        }

        @Override public void onError(Throwable e) {

        }
      }));
}
项目:DiscogsBrowser    文件:SingleListPresenter.java   
/**
 * Observer that subscribes to the network response.
 *
 * @param errorMessage Error message relevant to data type.
 * @return Observer.
 */
private DisposableSingleObserver<List<? extends RecyclerViewModel>> getNetworkObserver(String errorMessage)
{
    return new DisposableSingleObserver<List<? extends RecyclerViewModel>>()
    {
        @Override
        public void onSuccess(@NonNull List<? extends RecyclerViewModel> recyclerViewModels)
        {
            items = recyclerViewModels;
            displayItems();
        }

        @Override
        public void onError(Throwable e)
        {
            controller.setError(errorMessage);
        }
    };
}
项目:HelloApolloAndroid    文件:GitHuntEntryDetailActivity.java   
private void fetchRepositoryDetails() {
    ApolloCall<EntryDetailQuery.Data> entryDetailQuery = application.apolloClient()
            .query(new EntryDetailQuery(repoFullName))
            .cacheControl(CacheControl.CACHE_FIRST);

    //Example call using Rx2Support
    disposables.add(Rx2Apollo.from(entryDetailQuery)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribeWith(new DisposableSingleObserver<Response<EntryDetailQuery.Data>>() {
                @Override
                public void onSuccess(Response<EntryDetailQuery.Data> dataResponse) {
                    setEntryData(dataResponse.data());
                }

                @Override
                public void onError(Throwable e) {
                    Log.e(TAG, e.getMessage(), e);
                }
            }));
}
项目:JRAW-Android-Sample    文件:MainActivity.java   
private void loadSubmission() {
    if (AuthenticationManager.get().checkAuthState() == AuthenticationState.READY) {
        disposables.add(RedditService
                .getSubmission(AuthenticationManager.get().getRedditClient())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeWith(new DisposableSingleObserver<Submission>() {
                    @Override
                    public void onSuccess(Submission submission) {
                        Toast.makeText(MainActivity.this,
                                "Submission loaded with title: " + submission.getTitle(),
                                Toast.LENGTH_SHORT).show();
                    }

                    @Override
                    public void onError(Throwable e) {
                        Toast.makeText(MainActivity.this, "Something went wrong",
                                Toast.LENGTH_SHORT).show();
                    }
                }));
    } else if (AuthenticationManager.get().checkAuthState() == AuthenticationState.NONE) {
        Toast.makeText(this, "Not authenticated", Toast.LENGTH_SHORT).show();
    } else {
        Toast.makeText(this, "Token needs refresh", Toast.LENGTH_SHORT).show();
    }
}
项目:Quran    文件:PagerActivity.java   
private void onBookmarksChanged() {
  if (isInAyahMode) {
    compositeDisposable.add(
        bookmarkModel.getIsBookmarkedObservable(start.sura, start.ayah, start.getPage())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribeWith(new DisposableSingleObserver<Boolean>() {
              @Override
              public void onSuccess(Boolean isBookmarked) {
                updateAyahBookmark(start, isBookmarked, true);
              }

              @Override
              public void onError(Throwable e) {
              }
            }));
  }
}
项目:Quran    文件:PagerActivity.java   
private void toggleBookmark(final Integer sura, final Integer ayah, final int page) {
  compositeDisposable.add(bookmarkModel.toggleBookmarkObservable(sura, ayah, page)
      .observeOn(AndroidSchedulers.mainThread())
      .subscribeWith(new DisposableSingleObserver<Boolean>() {
        @Override
        public void onSuccess(Boolean isBookmarked) {
          if (sura == null || ayah == null) {
            // page bookmark
            bookmarksCache.put(page, isBookmarked);
            supportInvalidateOptionsMenu();
          } else {
            // ayah bookmark
            SuraAyah suraAyah = new SuraAyah(sura, ayah);
            updateAyahBookmark(suraAyah, isBookmarked, true);
          }
        }

        @Override
        public void onError(Throwable e) {
        }
      }));
}
项目:Quran    文件:PagerActivity.java   
private void updateToolbarPosition(final SuraAyah start, AyahTracker tracker) {
  compositeDisposable.add(bookmarkModel
      .getIsBookmarkedObservable(start.sura, start.ayah, start.getPage())
      .observeOn(AndroidSchedulers.mainThread())
      .subscribeWith(new DisposableSingleObserver<Boolean>() {
        @Override
        public void onSuccess(Boolean isBookmarked) {
          updateAyahBookmark(start, isBookmarked, false);
        }

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

  ayahToolBarPos = tracker.getToolBarPosition(start.sura, start.ayah,
      ayahToolBar.getToolBarWidth(), ayahToolBarTotalHeight);
  if (ayahToolBarPos != null) {
    ayahToolBar.updatePosition(ayahToolBarPos);
    if (ayahToolBar.getVisibility() != View.VISIBLE) {
      ayahToolBar.setVisibility(View.VISIBLE);
    }
  }
}
项目:Quran    文件:PagerActivity.java   
private void shareAyahLink(SuraAyah start, SuraAyah end) {
  showProgressDialog();
  compositeDisposable.add(
      QuranAppUtils.getQuranAppUrlObservable(getString(R.string.quranapp_key), start, end)
          .observeOn(AndroidSchedulers.mainThread())
          .subscribeWith(new DisposableSingleObserver<String>() {
            @Override
            public void onSuccess(String url) {
              ShareUtil.shareViaIntent(PagerActivity.this, url, R.string.share_ayah);
              dismissProgressDialog();
            }

            @Override
            public void onError(Throwable e) {
              dismissProgressDialog();
            }
          })
  );
}
项目:Quran    文件:InlineTranslationPresenter.java   
public void refresh(VerseRange verseRange) {
  if (disposable != null) {
    disposable.dispose();
  }

  disposable = getVerses(false, getTranslations(quranSettings), verseRange)
      .observeOn(AndroidSchedulers.mainThread())
      .subscribeWith(new DisposableSingleObserver<ResultHolder>() {
        @Override
        public void onSuccess(ResultHolder result) {
          if (translationScreen != null) {
            translationScreen.setVerses(result.translations, result.ayahInformation);
          }
        }

        @Override
        public void onError(Throwable e) {
        }
      });
}
项目:REDAndroid    文件:NotificationService.java   
@Override
public boolean onStartJob(final JobParameters params) {
    REDApplication.get(getApplicationContext()).getComponent().dataManager().
            loadIndex().observeOn(AndroidSchedulers.mainThread())
            .subscribeOn(Schedulers.io())
            .subscribe(new DisposableSingleObserver<Index>() {
                @Override
                public void onSuccess(Index index) {
                    if (index.response.notifications != null){
                        checkNotifications(index);
                    }
                    jobFinished(params, false);
                }

                @Override
                public void onError(Throwable error) {
                    jobFinished(params, false);
                }
            });

    return true;
}
项目:REDAndroid    文件:ReleasePresenter.java   
public void loadRelease(int id) {
    checkViewAttached();
    getMvpView().showLoadingProgress(true);

    mSubscription.add(mDataManager.getRelease(id)
            .observeOn(AndroidSchedulers.mainThread())
            .subscribeOn(Schedulers.io())
            .subscribeWith(new DisposableSingleObserver<TorrentGroup>() {
                @Override
                public void onSuccess(TorrentGroup torrentGroup) {
                    getMvpView().showRelease(torrentGroup);
                    flattenTorrents(torrentGroup.response.torrents);
                }

                @Override
                public void onError(Throwable error) {
                    getMvpView().showError(error.getMessage());
                    getMvpView().showLoadingProgress(false);
                }
            }));
}
项目:REDAndroid    文件:RequestPresenter.java   
public void loadRequest(int id) {
    checkViewAttached();
    getMvpView().showLoadingProgress(true);

    mSubscription.add(mDataManager.getRequest(id)
            .observeOn(AndroidSchedulers.mainThread())
            .subscribeOn(Schedulers.io())
            .subscribeWith(new DisposableSingleObserver<Request>() {
                @Override
                public void onSuccess(Request request) {
                    getMvpView().showRequest(request);
                    getMvpView().showLoadingProgress(false);
                }

                @Override
                public void onError(Throwable error) {
                    getMvpView().showError(error.getMessage());
                    getMvpView().showLoadingProgress(false);
                }
            }));
}
项目:REDAndroid    文件:ThreadListPresenter.java   
public void loadThreads(int id, int page) {
    checkViewAttached();
    getMvpView().showProgress(true);

    mSubscription.add(mDataManager.getThreads(id, page)
        .observeOn(AndroidSchedulers.mainThread())
        .subscribeOn(Schedulers.io())
        .subscribeWith(new DisposableSingleObserver<ForumView>() {
            @Override
            public void onSuccess(ForumView item) {
                if (item.response.threads.size() == 0){
                    getMvpView().showThreadsEmpty();
                    getMvpView().showProgress(false);
                } else {
                    getMvpView().showThreads(item);
                    getMvpView().showProgress(false);
                }
            }

            @Override
            public void onError(Throwable error) {
                getMvpView().showError();
                getMvpView().showProgress(false);
            }
        }));
}
项目:REDAndroid    文件:LoginPresenter.java   
public void login(String username, String password) {
    checkViewAttached();
    getMvpView().showLoadingProgress(true);

    mSubscription.add(mDataManager.login(username, password, 1)
            .observeOn(AndroidSchedulers.mainThread())
            .subscribeOn(Schedulers.io())
            .subscribeWith(new DisposableSingleObserver<Boolean>() {
                @Override
                public void onSuccess(Boolean success) {
                    if (success) {
                        loginWithCookie();
                    } else {
                        getMvpView().showError("Login Failed");
                    }
                }

                @Override
                public void onError(Throwable error) {
                    getMvpView().showError(error.getMessage());
                    getMvpView().showLoadingProgress(false);
                }
            }));
}
项目:REDAndroid    文件:LoginPresenter.java   
public void loginWithCookie() {
    checkViewAttached();

    getMvpView().showLoadingProgress(true);
    mSubscription.add(mDataManager.loginWithCookie()
            .observeOn(AndroidSchedulers.mainThread())
            .subscribeOn(Schedulers.io())
            .subscribeWith(new DisposableSingleObserver<Index>() {
                @Override
                public void onSuccess(Index value) {
                    getMvpView().showLoginSuccess();
                    getMvpView().showLoadingProgress(false);
                }

                @Override
                public void onError(Throwable error) {
                    getMvpView().showError(error.getMessage());
                    getMvpView().showLoadingProgress(false);
                }
            }));
}
项目:REDAndroid    文件:ArtistSearchPresenter.java   
public void loadArtists(String searchTerm) {
    checkViewAttached();
    if (searchTerm.isEmpty() || searchTerm.equals("") || searchTerm.equals(null)){
        getMvpView().showError();
    }

    mSubscription.add(mDataManager.artistsSearch(searchTerm)
        .observeOn(AndroidSchedulers.mainThread())
        .subscribeOn(Schedulers.io())
        .subscribeWith(new DisposableSingleObserver<Artist>() {
            @Override
            public void onSuccess(Artist artist) {
                if (artist.response == null){
                    getMvpView().showResultsEmpty();
                } else {
                    getMvpView().showResults(artist.response);
                }
            }

            @Override
            public void onError(Throwable error) {
                getMvpView().showResultsEmpty();
            }
        }));
}
项目:REDAndroid    文件:Top10Presenter.java   
public void loadTopTorrents(String detail) {
    checkViewAttached();
    getMvpView().showProgress(true);

    mSubscription.add(mDataManager.getTopTorrents(detail)
        .observeOn(AndroidSchedulers.mainThread())
        .subscribeOn(Schedulers.io())
        .subscribeWith(new DisposableSingleObserver<Top10>() {
            @Override public void onSuccess(Top10 items) {
                if (items.response == null || items.response.size() == 0) {
                    getMvpView().showTop10Empty();
                    getMvpView().showProgress(false);
                } else {
                    //If you use type=torrents you will always want the first one
                    getMvpView().showTop10(items.response.get(0).results);
                    getMvpView().showProgress(false);
                }
            }

            @Override public void onError(Throwable error) {
                getMvpView().showError();
                error.printStackTrace();
                getMvpView().showProgress(false);
            }
        }));
}
项目:REDAndroid    文件:SubscriptionsPresenter.java   
public void loadSubscriptions(String type) {
    checkViewAttached();
    getMvpView().showLoadingProgress(true);

    mDataManager.loadSubscriptions(type.equals("read") ? true : false)
            .observeOn(AndroidSchedulers.mainThread())
            .subscribeOn(Schedulers.io())
            .subscribe(new DisposableSingleObserver<Subscription>() {
                @Override
                public void onSuccess(Subscription subs) {
                    if (subs.response.threads == null || subs.response.threads.size() == 0){
                        getMvpView().showSubscriptionsEmpty();
                    }
                    else {
                        getMvpView().showSubscriptions(subs.response.threads);
                    }
                    getMvpView().showLoadingProgress(false);
                }

                @Override
                public void onError(Throwable e) {
                    getMvpView().showError(e.getMessage());
                    getMvpView().showLoadingProgress(false);
                }
            });
}
项目:REDAndroid    文件:BookmarkPresenter.java   
public void loadTorrentBookmarks() {
    checkViewAttached();
    getMvpView().showProgress(true);

    mSubscription.add(mDataManager.getTorrentBookmarks()
        .observeOn(AndroidSchedulers.mainThread())
        .subscribeOn(Schedulers.io())
        .subscribeWith(new DisposableSingleObserver<TorrentBookmark>() {
            @Override public void onSuccess(TorrentBookmark items) {
                if (items.response.bookmarks.size() == 0) {
                    getMvpView().showBookmarksEmpty();
                    getMvpView().showProgress(false);
                } else {
                    getMvpView().showBookmarks(items.response.bookmarks);
                    getMvpView().showProgress(false);
                }
            }

            @Override public void onError(Throwable error) {
                getMvpView().showError();
                error.printStackTrace();
                getMvpView().showProgress(false);
            }
        }));
}
项目:REDAndroid    文件:ArtistPresenter.java   
public void loadArtist(int id) {
    checkViewAttached();
    getMvpView().showLoadingProgress(true);

    mSubscription.add(mDataManager.artistsSearch(id)
            .observeOn(AndroidSchedulers.mainThread())
            .subscribeOn(Schedulers.io())
            .subscribeWith(new DisposableSingleObserver<Artist>() {
                @Override
                public void onSuccess(Artist artist) {
                    if (artist.response.body.equals("")){
                        artist.response.body = "No description";
                    }
                    getMvpView().showArtist(artist);
                    getMvpView().showLoadingProgress(false);
                }

                @Override
                public void onError(Throwable error) {
                    getMvpView().showError(error.getMessage());
                    getMvpView().showLoadingProgress(false);
                }
            }));
}
项目:REDAndroid    文件:InboxPresenter.java   
public void loadInbox(String type) {
    checkViewAttached();
    getMvpView().showLoadingProgress(true);

    mSubscription.add(mDataManager.loadInbox(type)
            .observeOn(AndroidSchedulers.mainThread())
            .subscribeOn(Schedulers.io())
            .subscribeWith(new DisposableSingleObserver<Conversations>() {
                @Override
                public void onSuccess(Conversations conversations) {
                    if (conversations.response.messages.size() == 0){
                        getMvpView().showInboxEmpty();
                        getMvpView().showLoadingProgress(false);
                    } else {
                        getMvpView().showInbox(conversations.response.messages);
                        getMvpView().showLoadingProgress(false);
                    }
                }

                @Override
                public void onError(Throwable error) {
                    getMvpView().showError(error.getMessage());
                    getMvpView().showLoadingProgress(false);
                }
            }));
}
项目:commitstrip-reader    文件:CachePresenter.java   
@Override
public void getNumberOfStrip(Date from, Date to) {
    compositeDisposable.add(
            mStripRepository.fetchNumberOfStrip(from, to)
                    .count()
                    .subscribeOn(Schedulers.newThread())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribeWith(new DisposableSingleObserver<Long>() {

                        @Override
                        public void onSuccess(Long numberOfStrip) {
                            mView.setNumberOfStrip(numberOfStrip);
                        }

                        @Override
                        public void onError(Throwable t) {
                            Log.e(TAG, "", t);
                        }

                    }));
}
项目:commitstrip-reader    文件:CachePresenter.java   
@Override
public void scheduleStripForDownload(Date from, Date to) {
    compositeDisposable.add(
        mStripRepository.fetchNumberOfStrip(from, to)
            .subscribeOn(Schedulers.newThread())
            .toList()
            .flatMap(strips -> mStripRepository.scheduleStripForDownload (strips))
            .subscribeWith(new DisposableSingleObserver<Integer>() {

                @Override
                public void onSuccess(Integer numberStrip) {
                    mNumberStrip = numberStrip;
                }

                @Override
                public void onError(Throwable e) {
                    Log.e(TAG, "", e);
                }
            }));

}
项目:commitstrip-reader    文件:DisplayFavoriteStripPresenter.java   
@Override
public void onSwipeLeft() {

    if (mCurrentStrip != null) {

        mSubscriptions.add(
                mStripRepository
                        .fetchNextFavoriteStrip(mCurrentStrip.getReleaseDate())
                        .subscribeWith(new DisposableSingleObserver<StripDto>() {
                            @Override
                            public void onSuccess(StripDto nextStrip) {
                                if (nextStrip != null) {
                                    passToStrip (nextStrip.getNext());
                                }
                            }

                            @Override
                            public void onError(Throwable e) {}
                        }));
    }
}
项目:commitstrip-reader    文件:DisplayFavoriteStripPresenter.java   
@Override
public void onSwipeRight() {
    mSubscriptions.add(
            mStripRepository
                    .fetchPreviousFavoriteStrip(mCurrentStrip.getReleaseDate())
                    .subscribeWith(new DisposableSingleObserver<StripDto>() {
                        @Override
                        public void onSuccess(StripDto previousStrip) {
                            if (previousStrip != null) {
                                passToStrip (previousStrip.getPrevious());
                            }
                        }

                        @Override
                        public void onError(Throwable e) {}
                    }));
}
项目:yarpc-java    文件:CompletionStages.java   
/** Converts a {@link Single} to a {@link CompletionStage}. */
public static <T> CompletionStage<T> fromSingle(Single<? extends T> single) {
  DisposingCompletableFuture<T> future = new DisposingCompletableFuture<>();
  DisposableSingleObserver<T> singleObserver =
      single.subscribeWith(
          new DisposableSingleObserver<T>() {
            @Override
            public void onSuccess(T obj) {
              future.complete(obj);
            }

            @Override
            public void onError(Throwable ex) {
              future.completeExceptionally(ex);
            }
          });
  future.setSingleObserver(singleObserver);
  return future;
}
项目:yarpc-java    文件:CompletionStagesTest.java   
@Test
public void testFromSingleWithCancellation() {
  Single<String> single = Single.never();
  single.subscribe(
      new DisposableSingleObserver<String>() {
        @Override
        public void onSuccess(String obj) {
          fail("onSuccess should not get called for a never-signaling Single");
        }

        @Override
        public void onError(Throwable ex) {
          fail("onError should not get called for a never-signaling Single");
        }
      });
  CompletableFuture<String> future = CompletionStages.fromSingle(single).toCompletableFuture();

  assertTrue(future.cancel(true));
  assertTrue(future.isCancelled());
}
项目:yarpc-java    文件:CompletionStagesTest.java   
@Test
public void testFromSingleWithException() throws Exception {
  Single<String> single = Single.error(new TestException());
  single.subscribe(
      new DisposableSingleObserver<String>() {
        @Override
        public void onSuccess(String obj) {
          fail("onSuccess should not get called for a Single that signals an error");
        }

        @Override
        public void onError(Throwable ex) {}
      });
  CompletableFuture<String> future = CompletionStages.fromSingle(single).toCompletableFuture();

  try {
    future.get();
    fail("An exception should have been thrown");
  } catch (ExecutionException e) {
    assertTrue(e.getCause() instanceof TestException);
  }
}
项目:MVP-RX-Android-Sample    文件:NewsUseCase.java   
@Override
public void getNews(BaseCallback callback) {
    disposableSingleObserver = new DisposableSingleObserver<NewsModel>() {
        @Override
        public void onSuccess(NewsModel newsModel) {
            callback.onSuccess(newsModel);
        }

        @Override
        public void onError(Throwable e) {
            callback.onFail();
        }
    };
    if (!compositeDisposable.isDisposed()) {
        newsModelSingle = dataRepository.requestNews();
        newsDisposable = newsModelSingle.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribeWith(disposableSingleObserver);
        compositeDisposable.add(newsDisposable);
    }
}
项目:Realtime-Bus    文件:TrackPresenterImp.java   
private DisposableSingleObserver<List<BusStation>> getStationsObserver() {
    return new DisposableSingleObserver<List<BusStation>>() {
        @Override
        public void onSuccess(List<BusStation> busStations) {
            vista.showLoading(false);
            vista.showStations(busStations);
            vista.showOffline(false);
            preferencesHelper.saveAutoCompleteItem(lineName);
            loadBusIfNetworkConnected();
            restartAutoRefreshService();
        }

        @Override
        public void onError(Throwable throwable) {
            throwable.printStackTrace();
            vista.showLoading(false);
            vista.showError(ERROR_SEARCH_LINE);
            if (throwable instanceof NetworkInteractor.NetworkUnavailableException) {
                vista.showOffline(true);
            } else {
                vista.showOffline(false);
            }
        }
    };
}
项目:Realtime-Bus    文件:TrackPresenterImp.java   
private DisposableSingleObserver<List<Bus>> getBusObserver() {
    return new DisposableSingleObserver<List<Bus>>() {
        @Override
        public void onSuccess(List<Bus> buses) {
            vista.showOffline(false);
            vista.showLoading(false);
            if (buses == null || buses.isEmpty()) {
                vista.showError(ERROR_NO_BUS);
            } else {
                vista.showBuses(buses);
            }
        }

        @Override
        public void onError(Throwable throwable) {
            Logger.e("There was a problem loading bus on line " + throwable);
            throwable.printStackTrace();
            vista.showLoading(false);
            if (throwable instanceof NetworkInteractor.NetworkUnavailableException) {
                vista.showOffline(true);
            } else {
                vista.showOffline(false);
            }
        }
    };
}
项目:codeexamples-android    文件:MainActivity.java   
private DisposableSingleObserver<List<Issue>> getIssuesObserver() {
    return new DisposableSingleObserver<List<Issue>>() {
        @Override
        public void onSuccess(List<Issue> issues) {
            IssueAdapter listAdapter = (IssueAdapter) list.getAdapter();
            MainActivity.this.issues.clear();
            MainActivity.this.issues.addAll(new ArrayList<Issue>(issues));
            list.getAdapter().notifyDataSetChanged();
        }

        @Override
        public void onError(Throwable e) {
            Toast.makeText(MainActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
        }
    };
}
项目:android-ponewheel    文件:RidesListActivity.java   
public void refreshList() {
    disposable = Single.fromCallable(() -> {
                Timber.d("fetching ride row list");
                List<Ride> rideRowList = App.INSTANCE.db.rideDao().getAll();
                Timber.d("rideRowList.size() = " + rideRowList.size());
                return rideRowList;

            })
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribeWith(new DisposableSingleObserver<List<Ride>>() {

                @Override
                public void onSuccess(List<Ride> rides) {
                    for (Ride ride : rides) {
                        Timber.d("ride = " + ride);
                    }

                    rideListAdapter.getRideList().clear();
                    rideListAdapter.getRideList().addAll(rides);
                    rideListAdapter.notifyDataSetChanged();
                }

                @Override
                public void onError(Throwable e) {
                    Log.e(TAG, "onError: ", e);
                }
            });
}
项目:Quran    文件:SuraListFragment.java   
@Override
public void onResume() {
  final Activity activity = getActivity();
  QuranSettings settings = QuranSettings.getInstance(activity);
  if (activity instanceof QuranActivity) {
    disposable = ((QuranActivity) activity).getLatestPageObservable()
        .first(Constants.NO_PAGE)
        .observeOn(AndroidSchedulers.mainThread())
        .subscribeWith(new DisposableSingleObserver<Integer>() {
          @Override
          public void onSuccess(Integer recentPage) {
            if (recentPage != Constants.NO_PAGE) {
              int sura = QuranInfo.safelyGetSuraOnPage(recentPage);
              int juz = QuranInfo.getJuzFromPage(recentPage);
              int position = sura + juz - 1;
              mRecyclerView.scrollToPosition(position);
            }
          }

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

  if (settings.isArabicNames()) {
    updateScrollBarPositionHoneycomb();
  }

  super.onResume();
}
项目:Quran    文件:JuzListFragment.java   
@Override
public void onResume() {
  final Activity activity = getActivity();

  if (activity instanceof QuranActivity) {
    disposable = ((QuranActivity) activity).getLatestPageObservable()
        .first(Constants.NO_PAGE)
        .observeOn(AndroidSchedulers.mainThread())
        .subscribeWith(new DisposableSingleObserver<Integer>() {
          @Override
          public void onSuccess(Integer recentPage) {
            if (recentPage != Constants.NO_PAGE) {
              int juz = QuranInfo.getJuzFromPage(recentPage);
              int position = (juz - 1) * 9;
              mRecyclerView.scrollToPosition(position);
            }
          }

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

  QuranSettings settings = QuranSettings.getInstance(activity);
  if (settings.isArabicNames()) {
    updateScrollBarPositionHoneycomb();
  }

  super.onResume();
}
项目:Quran    文件:PagerActivity.java   
private void requestTranslationsList() {
  compositeDisposable.add(
      Single.fromCallable(() ->
          translationsDBAdapter.getTranslations())
        .subscribeOn(Schedulers.io())
        .observeOn(AndroidSchedulers.mainThread())
        .subscribeWith(new DisposableSingleObserver<List<LocalTranslation>>() {
          @Override
          public void onSuccess(List<LocalTranslation> translationList) {
            int items = translationList.size();
            String[] titles = new String[items];
            for (int i = 0; i < items; i++) {
              LocalTranslation item = translationList.get(i);
              if (!TextUtils.isEmpty(item.translatorForeign)) {
                titles[i] = item.translatorForeign;
              } else if (!TextUtils.isEmpty(item.translator)) {
                titles[i] = item.translator;
              } else {
                titles[i] = item.name;
              }
            }
            Set<String> activeTranslations = quranSettings.getActiveTranslations();

            if (translationsSpinnerAdapter != null) {
              translationsSpinnerAdapter.updateItems(titles, translationList, activeTranslations);
            }
            translationItems = titles;
            translations = translationList;

            if (showingTranslation) {
              // Since translation items have changed, need to
              updateActionBarSpinner();
            }
          }

          @Override
          public void onError(Throwable e) {
          }
        }));
}
项目:Quran    文件:BookmarkPresenter.java   
public void deleteAfterSomeTime(List<QuranRow> remove) {
  // the fragment just called this, so fragment should be valid
  fragment.onNewData(predictQuranListAfterDeletion(remove));

  if (pendingRemoval != null) {
    // handle a new delete request when one is already happening by adding those items to delete
    // now and un-subscribing from the old request.
    if (itemsToRemove != null) {
      remove.addAll(itemsToRemove);
    }
    cancelDeletion();
  }

  itemsToRemove = remove;
  pendingRemoval = Single.timer(DELAY_DELETION_DURATION_IN_MS, TimeUnit.MILLISECONDS)
      .flatMap(ignore -> removeItemsObservable())
      .subscribeOn(Schedulers.io())
      .observeOn(AndroidSchedulers.mainThread())
      .subscribeWith(new DisposableSingleObserver<BookmarkResult>() {

        @Override
        public void onSuccess(BookmarkResult result) {
          pendingRemoval = null;
          cachedData = result;
          if (fragment != null) {
            fragment.onNewData(result);
          }
        }

        @Override
        public void onError(Throwable e) {
        }
      });
}
项目:REDAndroid    文件:CategoryPresenter.java   
public void loadCategories() {
    checkViewAttached();
    getMvpView().showProgress(true);

    mSubscription.add(mDataManager.getCategories()
        .observeOn(AndroidSchedulers.mainThread())
        .subscribeOn(Schedulers.io())
        .subscribeWith(new DisposableSingleObserver<List<Object>>() {
            @Override
            public void onSuccess(List<Object> items) {
                if (items.size() == 0){
                    getMvpView().showCategoriesEmpty();
                    getMvpView().showProgress(false);
                } else {
                    getMvpView().showCategories(items);
                    getMvpView().showProgress(false);
                }
            }

            @Override
            public void onError(Throwable error) {
                getMvpView().showError();
                error.printStackTrace();
                getMvpView().showProgress(false);
            }
        }));
}