本文整理汇总了Java中rx.subjects.PublishSubject.create方法的典型用法代码示例。如果您正苦于以下问题:Java PublishSubject.create方法的具体用法?Java PublishSubject.create怎么用?Java PublishSubject.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rx.subjects.PublishSubject
的用法示例。
在下文中一共展示了PublishSubject.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testPagingCapabilities
import rx.subjects.PublishSubject; //导入方法依赖的package包/类
@Test
public void testPagingCapabilities() {
PublishSubject<Object> view = PublishSubject.create();
BehaviorSubject<Integer> nextPageRequests = BehaviorSubject.create();
final TestObserver<Delivery<Object, String>> testObserver = new TestObserver<>();
nextPageRequests
.concatMap(new Func1<Integer, Observable<Integer>>() {
@Override
public Observable<Integer> call(Integer targetPage) {
return targetPage <= requestedPageCount ?
Observable.<Integer>never() :
Observable.range(requestedPageCount, targetPage - requestedPageCount);
}
})
.doOnNext(new Action1<Integer>() {
@Override
public void call(Integer it) {
requestedPageCount = it + 1;
}
})
.startWith(Observable.range(0, requestedPageCount))
.concatMap(new Func1<Integer, Observable<String>>() {
@Override
public Observable<String> call(final Integer page) {
return requestPage(page, PAGE_SIZE);
}
})
.compose(new DeliverReplay<Object, String>(view))
.subscribe(testObserver);
ArrayList<Delivery<Object, String>> onNext = new ArrayList<>();
testObserver.assertReceivedOnNext(onNext);
view.onNext(999);
addOnNext(onNext, 999, 0, 1, 2);
testObserver.assertReceivedOnNext(onNext);
nextPageRequests.onNext(2);
addOnNext(onNext, 999, 3, 4, 5);
testObserver.assertReceivedOnNext(onNext);
view.onNext(null);
assertEquals(0, testObserver.getOnCompletedEvents().size());
testObserver.assertReceivedOnNext(onNext);
nextPageRequests.onNext(3);
assertEquals(0, testObserver.getOnCompletedEvents().size());
testObserver.assertReceivedOnNext(onNext);
view.onNext(9999);
addOnNext(onNext, 9999, 0, 1, 2, 3, 4, 5, 6, 7, 8);
assertEquals(0, testObserver.getOnCompletedEvents().size());
testObserver.assertReceivedOnNext(onNext);
}
示例2: begin
import rx.subjects.PublishSubject; //导入方法依赖的package包/类
public PublishSubject<Boolean> begin() {
if(publishSubject == null){
publishSubject = PublishSubject.create();
}
if (Build.VERSION.SDK_INT < 23){
publishSubject.onError(new FPerException(SYSTEM_API_ERROR));
}else {
initManager();
confirmFinger();
startListening(null);
}
return publishSubject;
}
示例3: MockWalker
import rx.subjects.PublishSubject; //导入方法依赖的package包/类
private MockWalker(Context context) {
mContext = context.getApplicationContext();
mChanges = PublishSubject.create();
mClient = new GoogleApiClient.Builder(mContext)
.addApi(LocationServices.API)
.addConnectionCallbacks(this)
.build();
mClient.connect();
}
示例4: RxBus
import rx.subjects.PublishSubject; //导入方法依赖的package包/类
/**
* 用SerializedSubject包装PublishSubject,序列化
*/
private RxBus() {
//private final PublishSubject<Object> _bus = PublishSubject.create();
// If multiple threads are going to emit events to this
// then it must be made thread-safe like this instead
_bus = new SerializedSubject<>(PublishSubject.create());
}
示例5: onNext
import rx.subjects.PublishSubject; //导入方法依赖的package包/类
public void onNext(T1 args) {
try {
int id;
Subject<T2, T2> subj = PublishSubject.create();
Observer<T2> subjSerial = new SerializedObserver(subj);
synchronized (ResultManager.this.guard) {
ResultManager resultManager = ResultManager.this;
id = resultManager.leftIds;
resultManager.leftIds = id + 1;
ResultManager.this.leftMap.put(Integer.valueOf(id), subjSerial);
}
Observable<T2> window = Observable.create(new WindowObservableFunc(subj, ResultManager.this.cancel));
Observable<D1> duration = (Observable) OnSubscribeGroupJoin.this.leftDuration.call(args);
Subscriber<D1> d1 = new LeftDurationObserver(id);
ResultManager.this.group.add(d1);
duration.unsafeSubscribe(d1);
R result = OnSubscribeGroupJoin.this.resultSelector.call(args, window);
synchronized (ResultManager.this.guard) {
List<T2> rightMapValues = new ArrayList(ResultManager.this.rightMap.values());
}
ResultManager.this.subscriber.onNext(result);
for (T2 t2 : rightMapValues) {
subjSerial.onNext(t2);
}
} catch (Throwable t) {
Exceptions.throwOrReport(t, this);
}
}
示例6: schedulePermissionsRequest
import rx.subjects.PublishSubject; //导入方法依赖的package包/类
@NonNull
private static Observable<Boolean> schedulePermissionsRequest(final Activity activity, final PermissionGroup permissions) {
final int requestCode = getRequestCode();
final PublishSubject<Boolean> subj = PublishSubject.create();
requestMap.put(requestCode, subj);
return subj.doOnSubscribe(new Action0() {
@Override
public void call() {
ActivityCompat.requestPermissions(activity, new String[] {permissions.getValue()}, requestCode);
}
});
}
示例7: manage
import rx.subjects.PublishSubject; //导入方法依赖的package包/类
@Override
public Observable<PartialResult<JsonList<ControlMessage.Status>>> manage(ControlMessage message) {
final ManageOperation manageOp = new ManageOperation(message);
final byte[] serializedOp = SerializationUtils.serialize(manageOp);
final UUID operationId = UUID.randomUUID();
final Command command = Command.newBuilder()
.setIdsIndex(this.remoteHandle)
.setSerializedOp(ByteString.copyFrom(serializedOp))
.setHighId(operationId.getMostSignificantBits())
.setLowId(operationId.getLeastSignificantBits())
.build();
final PublishSubject<PartialResult<JsonList<ControlMessage.Status>>> subj = PublishSubject.create();
final StreamObserver<PartialResponse> responseObserver =
new ManageObserver(subj, message, this);
return subj.doOnSubscribe(() -> this.stub.withDeadlineAfter(TIMEOUT, TimeUnit.MILLISECONDS)
.manage(command, responseObserver))
.doOnUnsubscribe(() -> this.unsubscribe(operationId));
}
示例8: onActivityCreated
import rx.subjects.PublishSubject; //导入方法依赖的package包/类
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
PublishSubject<String> publishSubject = PublishSubject.create();
PublishSubjectTopFragment topFragment = new PublishSubjectTopFragment(publishSubject);
PublishSubjectBottomFragment bottom_Fragment = new PublishSubjectBottomFragment(publishSubject);
getActivity().getSupportFragmentManager()
.beginTransaction()
.replace(R.id.fl_top,topFragment, "top")
.replace(R.id.fl_bottom, bottom_Fragment, "bottom")
.commit();
}
示例9: setupSubscriptions
import rx.subjects.PublishSubject; //导入方法依赖的package包/类
private void setupSubscriptions() {
subject = PublishSubject.create();
subscription = subject.observeOn(Schedulers.io())
.flatMap(new Func1<String, Observable<List<DownloadableItem>>>() {
@Override public Observable<List<DownloadableItem>> call(String s) {
Timber.d("Constructing downloadables....");
List<DownloadableItem> list = new ArrayList<>();
for (int i = 0; i < URLS.length; i++) {
DownloadStatus status = downlink.downloadStatus(URLS[i]);
list.add(DownloadableItem.builder()
.name("Item " + (i + 1))
.url(URLS[i])
.status(status)
.build());
}
return Observable.just(list);
}
})
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Subscriber<List<DownloadableItem>>() {
@Override public void onCompleted() {
}
@Override public void onError(Throwable e) {
Timber.d(e, "Error occurred");
}
@Override public void onNext(List<DownloadableItem> downloadableItems) {
Timber.d("Setting data in adapter...");
downloadsAdapter.setData(downloadableItems);
}
});
}
示例10: requestKeyboardUpdates
import rx.subjects.PublishSubject; //导入方法依赖的package包/类
public Observable<KeyboardState> requestKeyboardUpdates(Activity activity) {
publishSubject = PublishSubject.create();
activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
viewTreeObserverListener = new GlobalLayoutListener();
rootView = new WeakReference<>(activity.findViewById(Window.ID_ANDROID_CONTENT));
rootView.get().getViewTreeObserver().addOnGlobalLayoutListener(viewTreeObserverListener);
publishSubject.doOnUnsubscribe(new Action0() {
@Override
public void call() {
destroy();
}
});
return publishSubject;
}
示例11: should_allow_a_subscription_after_an_unsubscription
import rx.subjects.PublishSubject; //导入方法依赖的package包/类
@Test
public void should_allow_a_subscription_after_an_unsubscription() {
// given
PublishSubject<Integer> subject = PublishSubject.create();
Observable<Integer> limitedObservable = SubscriptionLimiter.limitSubscriptions(1, subject);
TestSubscriber<Integer> subscriber = new TestSubscriber<>();
TestSubscriber<Integer> subscriber2 = new TestSubscriber<>();
Subscription subscription = limitedObservable.subscribe(subscriber);
// when
subscription.unsubscribe();
limitedObservable.subscribe(subscriber2);
subject.onNext(123);
// then
assertThat(subscriber2.getOnNextEvents()).hasSize(1).contains(123);
}
示例12: loadCommentsSubscriptions
import rx.subjects.PublishSubject; //导入方法依赖的package包/类
private Subscription loadCommentsSubscriptions() {
final CompositeSubscription compositeSubscription = new CompositeSubscription();
final PublishSubject<List<RedditListing>> listPublishSubject = PublishSubject.create();
//get the posts from the network request
final Subscription postSub = listPublishSubject.map(redditListings -> redditListings.get(0))
.map(redditListing -> redditListing.data.children.get(0).data)
.onErrorResumeNext(throwable -> Observable.empty())
.observeOn(androidSchedulers.mainThread())
.subscribe(defaultPostView::setRedditItem);
//get the commentns from the network request
final Observable<List<RedditItem>> networkItems = listPublishSubject.map(redditListings -> redditListings.get(1))
.map(redditListing -> redditListing.data.children)
.onErrorResumeNext(throwable -> Observable.just(Collections.emptyList()))
.flatMap(children -> Observable.from(children)
.map(child -> child.data)
.toList());
//get the comments from the saved state
final Subscription commentSub = Observable.concat(postModel.getCommentsFromState(), networkItems)
.observeOn(androidSchedulers.mainThread())
.doOnNext(postModel::saveComentsState)
.subscribe(defaultPostView::setCommentList);
final Subscription subscription = Observable.just(postModel.getIntentRedditItem())
.flatMap(redditItem -> postModel.getCommentsForPost(redditItem.subreddit, redditItem.id))
.subscribeOn(androidSchedulers.network())
.subscribe(listPublishSubject);
compositeSubscription.add(subscription);
compositeSubscription.add(postSub);
compositeSubscription.add(commentSub);
return compositeSubscription;
}
示例13: RxBindingExampleViewModel
import rx.subjects.PublishSubject; //导入方法依赖的package包/类
@Inject
public RxBindingExampleViewModel() {
final long intervalMs = 10;
final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("mm:ss:SS");
timeStream = Observable
.interval(intervalMs, TimeUnit.MILLISECONDS)
.onBackpressureDrop()
.map(beats -> Duration.ofMillis(intervalMs * beats))
.map(duration -> formatter.format(LocalTime.MIDNIGHT.plus(duration)));
calculateSubject = PublishSubject.create();
highLoadStream = calculateSubject
.observeOn(Schedulers.computation())
.scan((sum, value) -> ++sum)
.map(iteration -> {
// Simulate high processing load
try {
Thread.sleep(1000);
}
catch (InterruptedException e) {}
return iteration;
});
}
示例14: ObjectRequest
import rx.subjects.PublishSubject; //导入方法依赖的package包/类
/**
* Creates a new request with the given method.
*
* @param method the request {@link Method} to use
* @param url URL to fetch the Object
* @param clazz the Object class to return
*/
private ObjectRequest(int method, String url, Class clazz) {
super(method, url, null);
mClazz = clazz;
mHasCache = BaseApplication.getVolleyCache().get(getCacheKey()) != null;
setShouldCache(false);
addEntryListener();
setRetryPolicy(new DefaultRetryPolicy(DEFAULT_TIMEOUT_MS, DEFAULT_MAX_RETRIES, DEFAULT_BACKOFF_MULT));
mSubject = new SerializedSubject<>(PublishSubject.create());
}
示例15: onCreate
import rx.subjects.PublishSubject; //导入方法依赖的package包/类
@Override public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mRepositories = new ArrayList<>();
timespanSubject = PublishSubject.create();
Injector.obtain(getContext()).inject(this);
timespanAdapter = new TrendingTimespanAdapter(
new ContextThemeWrapper(getContext(), R.style.Theme_U2020_TrendingTimespan));
repositoryAdapter = new RepositoryAdapter(mRepositories);
repositoryAdapter.setRepositoryClickListener(repository -> {
startActivity(mIntentFactory.createUrlIntent(repository.html_url));
});
Observable<Result<RepositoriesResponse>> result = timespanSubject //
.debounce(300, TimeUnit.MILLISECONDS) //
.flatMap(trendingSearch) //
.observeOn(mainThread()) //
.share();
subscriptions.add(result //
.filter(Results.isSuccess()) //
.map(SearchResultToRepositoryList.instance()) //
.subscribe(repositories -> {
if (page == FRIST_PAGE) mRepositories.clear();
mRepositories.addAll(repositories);
if (binding.trendingListView.getAdapter() == null) {
binding.trendingListView.setAdapter(repositoryAdapter);
}
repositoryAdapter.notifyDataSetChanged();
}));
subscriptions.add(result //
.filter(Funcs.not(Results.isSuccess())) //
.subscribe(trendingError));
}