本文整理汇总了Java中io.reactivex.schedulers.Schedulers类的典型用法代码示例。如果您正苦于以下问题:Java Schedulers类的具体用法?Java Schedulers怎么用?Java Schedulers使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Schedulers类属于io.reactivex.schedulers包,在下文中一共展示了Schedulers类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: applySchedules
import io.reactivex.schedulers.Schedulers; //导入依赖的package包/类
public static <T> FlowableTransformer<T, T> applySchedules(final IView view) {
return new FlowableTransformer<T, T>() {
@Override
public Publisher<T> apply(Flowable<T> upstream) {
return upstream.subscribeOn(Schedulers.io())
.doOnSubscribe(new Consumer<Subscription>() {
@Override
public void accept(Subscription subscription) throws Exception {
view.showLoading();
}
})
.subscribeOn(AndroidSchedulers.mainThread())
.observeOn(AndroidSchedulers.mainThread())
.doOnTerminate(new Action() {
@Override
public void run() throws Exception {
view.hideLoading();
}
});
}
};
}
示例2: loadRequest
import io.reactivex.schedulers.Schedulers; //导入依赖的package包/类
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);
}
}));
}
示例3: getMoviesList
import io.reactivex.schedulers.Schedulers; //导入依赖的package包/类
@MainThread
@NonNull
LiveData<Response<List<Country>>> getMoviesList() {
if (countriesLiveData == null) {
countriesLiveData = new MutableLiveData<>();
countriesRepository.getCountries()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.doOnSubscribe(disposable -> loadingLiveData.setValue(true))
.doAfterTerminate(() -> loadingLiveData.setValue(false))
.subscribe(
countries1 -> countriesLiveData.setValue(Response.success(countries1)),
throwable -> countriesLiveData.setValue(Response.error(throwable))
);
}
return countriesLiveData;
}
示例4: restart
import io.reactivex.schedulers.Schedulers; //导入依赖的package包/类
private void restart() {
mCompositeDisposable.add(FFMService.restart()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.doFinally(new Action() {
@Override
public void run() throws Exception {
findPreference("restart_webqq").setEnabled(true);
}
})
.subscribe(new Consumer<FFMResult>() {
@Override
public void accept(FFMResult ffmResult) throws Exception {
Toast.makeText(getContext(), "Succeed.", Toast.LENGTH_SHORT).show();
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
Toast.makeText(getContext(), "Network error:\n" + throwable.getMessage(), Toast.LENGTH_SHORT).show();
}
}));
}
示例5: choose
import io.reactivex.schedulers.Schedulers; //导入依赖的package包/类
private void choose(TrackPath source, SingleTrackAlbumBuilder result) {
final Single<Boolean> dbOp = Single.fromCallable(() -> {
new TrackPathNormalizer(source).removeTags();
db.addAlbum(result.build());
updateHits(result);
return true;
}).observeOn(Schedulers.io());
Single.fromCallable(() -> {
return askForRemoval(source);
}).zipWith(dbOp, (one, another) -> one && another)
.subscribe(toDelete -> {
if(toDelete) {
Files.delete(source.getPath());
}
});
}
示例6: load
import io.reactivex.schedulers.Schedulers; //导入依赖的package包/类
public static void load() {
RxHelper.safeObservable(Observable.fromCallable(() -> {
try {
InputStream stream = App.getInstance().getAssets().open(PATH);
List<Emoji> emojis = EmojiLoader.loadEmojis(stream);
ALL_EMOJIS = emojis;
for (Emoji emoji : emojis) {
for (String tag : emoji.getTags()) {
if (EMOJIS_BY_TAG.get(tag) == null) {
EMOJIS_BY_TAG.put(tag, new HashSet<>());
}
EMOJIS_BY_TAG.get(tag).add(emoji);
}
for (String alias : emoji.getAliases()) {
EMOJIS_BY_ALIAS.put(alias, emoji);
}
}
EMOJI_TRIE = new EmojiTrie(emojis);
stream.close();
} catch (IOException e) {
e.printStackTrace();
}
return "";
})).subscribeOn(Schedulers.io()).subscribe();
}
示例7: searchData
import io.reactivex.schedulers.Schedulers; //导入依赖的package包/类
private void searchData(String tag) {
mHintText.setText("");
mTagLayout.setVisibility(View.GONE);
mProgressBar.setVisibility(View.VISIBLE);
mSearchTag = tag;
Observable<GetDataBean> observable = mSearchApi.searchTagData(mSearchTag);
observable
.filter(new Predicate<GetDataBean>() {
@Override
public boolean test(@NonNull GetDataBean getDataBean) throws Exception {
return getDataBean != null;
}
})
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(mObserver);
}
示例8: fetchData
import io.reactivex.schedulers.Schedulers; //导入依赖的package包/类
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) {
}
}));
}
示例9: getUserProfile
import io.reactivex.schedulers.Schedulers; //导入依赖的package包/类
private void getUserProfile() {
mUserService.me()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(u -> {
mUserName.setText(u.getUsername());
mAvatarView.setAvatarOfUser(u);
mReputation.setText(u.getReputation());
mPost.setText(u.getPostcount());
mFollowing.setText(String.valueOf(u.getFollowingCount()));
mFollower.setText(String.valueOf(u.getFollowerCount()));
mLoginTime.setText(DateTimeFormatter.format(Long.parseLong(u.getLastonline())));
mRegTime.setText(DateTimeFormatter.format(Long.parseLong(u.getJoindate())));
mProfileViews.setText(u.getProfileviews());
mEmail.setText(u.getEmail());
GlideApp.with(UserProfileActivity.this)
.load(NodeBBService.url(u.getCoverUrl()))
.into(new SimpleTarget<Drawable>() {
@Override
public void onResourceReady(Drawable resource, Transition<? super Drawable> transition) {
mHeaderView.setBackground(resource);
}
});
});
}
示例10: login
import io.reactivex.schedulers.Schedulers; //导入依赖的package包/类
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);
}
}));
}
示例11: login
import io.reactivex.schedulers.Schedulers; //导入依赖的package包/类
public Single<Boolean> login(String username, String password, int stayLoggedIn) {
return mApiService.login(username, password, stayLoggedIn)
.subscribeOn(Schedulers.io())
.flatMap(new Function<Response<ResponseBody>, Single<? extends Boolean>>() {
@Override public Single<? extends Boolean> apply(
Response<ResponseBody> responseBodyResponse) {
String header = responseBodyResponse.raw().header("Set-Cookie", "");
if (header.contains("session")
&& !header.contains("deleted")
&& !header.contains("redirect")) {
return Single.just(true);
} else {
getPreferencesHelper().clearCookies();
return Single.just(false);
}
}
});
}
示例12: TranscodingServiceImpl
import io.reactivex.schedulers.Schedulers; //导入依赖的package包/类
@Inject
TranscodingServiceImpl(ExternalProcessService externalProcessService,
TranscoderSettings transcoderSettings,
MediaScanSettings mediaScanSettings,
OutputParser parser) {
this.externalProcessService = externalProcessService;
this.transcoderSettings = transcoderSettings;
this.mediaScanSettings = mediaScanSettings;
this.parser = parser;
this.publisher = PublishSubject.create().toSerialized();
publisher.ofType(TranscodeTask.class)
.skipWhile(o -> isActive())
.observeOn(Schedulers.computation())
.subscribeOn(Schedulers.io())
.subscribe(this::prepareTranscode);
}
示例13: loadBookList
import io.reactivex.schedulers.Schedulers; //导入依赖的package包/类
@Override
public void loadBookList(BookListType type, String tag, int start, int limited) {
Disposable refreshDispo = getBookListSingle(type, tag, start, limited)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
(beans)-> {
mView.finishLoading(beans);
}
,
(e) ->{
mView.showLoadError();
LogUtils.e(e);
}
);
addDisposable(refreshDispo);
}
示例14: writeFile
import io.reactivex.schedulers.Schedulers; //导入依赖的package包/类
public static Single<WriteFileEvent> writeFile(final String content, final Path path, final boolean overwrite) {
Preconditions.checkNotNull(content);
Preconditions.checkNotNull(path);
return Single.fromCallable(() -> {
if (path.getParent() != null && !Files.exists(path.getParent())) {
Files.createDirectories(path.getParent());
}
if (overwrite) {
Files.deleteIfExists(path);
} else if (Files.isDirectory(path)) {
throw new IOException("There is already a directory at " + path);
} else if (Files.exists(path)) {
throw new IOException("There is already a file at " + path);
}
final ByteSink sink = MoreFiles.asByteSink(path);
sink.write(content.getBytes());
return WriteFileEvent.of(path);
}).subscribeOn(Schedulers.io());
}
示例15: fetchMoreData
import io.reactivex.schedulers.Schedulers; //导入依赖的package包/类
@Override
public void fetchMoreData() {
if (TextUtils.isEmpty(getNextPageUrl()))
return;
view.showLoadingMore(true);
repository.listShotLikesForUserOfNextPage(getNextPageUrl())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.compose(((LifecycleProvider<FragmentEvent>) view).bindUntilEvent(FragmentEvent.DESTROY_VIEW))
.subscribe(listResponse -> {
view.showLoadingMore(false);
view.showMoreData(generateEpoxyModels(listResponse.body()));
setNextPageUrl(new PageLinks(listResponse).getNext());
}, throwable -> {
view.showLoadingMore(false);
view.showSnackbar(throwable.getMessage());
throwable.printStackTrace();
});
}