Java Code Examples for rx.subscriptions.CompositeSubscription#add()

The following examples show how to use rx.subscriptions.CompositeSubscription#add() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BannerView.java    From HeroVideo-master with Apache License 2.0 6 votes vote down vote up
/**
 * 图片开始轮播
 */
private void startScroll()
{

    compositeSubscription = new CompositeSubscription();
    isStopScroll = false;
    Subscription subscription = Observable.timer(delayTime, TimeUnit.SECONDS)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(aLong -> {

                if (isStopScroll)
                    return;

                isStopScroll = true;
                viewPager.setCurrentItem(viewPager.getCurrentItem() + 1);
            });
    compositeSubscription.add(subscription);
}
 
Example 2
Source File: MusicPresenter.java    From FileManager with Apache License 2.0 6 votes vote down vote up
public MusicPresenter(Context context){
    this.mContext = context;
    mCompositeSubscription = new CompositeSubscription();
    mCategoryManager = CategoryManager.getInstance();

    mCompositeSubscription.add(RxBus.getDefault()
            .IoToUiObservable(TypeEvent.class)
            .map(TypeEvent::getType)
            .subscribe(type -> {
                if (type == AppConstant.SELECT_ALL){
                    mView.selectAll();
                }else if (type == AppConstant.REFRESH){
                    mView.setDataByObservable(mCategoryManager.getMusicList());
                }else if (type == AppConstant.CLEAN_CHOICE){
                    mView.clearSelect();
                }
            }, Throwable::printStackTrace));

}
 
Example 3
Source File: BannerView.java    From HeroVideo-master with Apache License 2.0 6 votes vote down vote up
/**
 * 图片开始轮播
 */
private void startScroll()
{

    compositeSubscription = new CompositeSubscription();
    isStopScroll = false;
    Subscription subscription = Observable.timer(delayTime, TimeUnit.SECONDS)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(aLong -> {

                if (isStopScroll)
                    return;

                isStopScroll = true;
                viewPager.setCurrentItem(viewPager.getCurrentItem() + 1);
            });
    compositeSubscription.add(subscription);
}
 
Example 4
Source File: CommonPresenter.java    From FileManager with Apache License 2.0 5 votes vote down vote up
public CommonPresenter(Context context, String path) {
    this.mContext = context;
    this.mPath = path;
    mCompositeSubscription = new CompositeSubscription();

    mCompositeSubscription.add(RxBus.getDefault()
            .IoToUiObservable(CleanChoiceEvent.class)
            .subscribe(event -> {
                mView.setLongClick(false);
                mView.clearSelect();
            }, Throwable::printStackTrace));

    mCompositeSubscription.add(RxBus.getDefault()
            .IoToUiObservable(RefreshEvent.class)
            .subscribe(event -> {
                mView.refreshAdapter();
            }, Throwable::printStackTrace));

    mCompositeSubscription.add(RxBus.getDefault()
            .IoToUiObservable(AllChoiceEvent.class)
            .map(event -> "/" + event.getPath())
            .subscribe(dirPath -> {
                //如果全选了,就取消。否则全选
                if (dirPath.equals(this.mPath)) {
                    mView.allChoiceClick();
                }
            }, Throwable::printStackTrace));

    mCompositeSubscription.add(RxBus.getDefault()
            .IoToUiObservable(SnackBarEvent.class)
            .subscribe(snackBarEvent -> {
                mView.showSnackBar(snackBarEvent.getContent());
            }));
}
 
Example 5
Source File: DebugViewContainer.java    From u2020-mvp with Apache License 2.0 5 votes vote down vote up
private void setupMadge(final ViewHolder viewHolder, CompositeSubscription subscriptions) {
    subscriptions.add(pixelGridEnabled.asObservable().subscribe(enabled -> {
        viewHolder.madgeFrameLayout.setOverlayEnabled(enabled);
    }));
    subscriptions.add(pixelRatioEnabled.asObservable().subscribe(enabled -> {
        viewHolder.madgeFrameLayout.setOverlayRatioEnabled(enabled);
    }));
}
 
Example 6
Source File: MainActivity.java    From JianDanRxJava with Apache License 2.0 5 votes vote down vote up
@Override
protected void onStart() {
    super.onStart();
    mRxBusComposite = new CompositeSubscription();
    Subscription sub = RxNetWorkEvent.toObserverable()
            .observeOn(AndroidSchedulers.mainThread())
            .subscribeOn(AndroidSchedulers.mainThread())
            .subscribe(netWorkEvent -> {
                if (netWorkEvent.getType() == NetWorkEvent.UNAVAILABLE) {
                    if (noNetWorkDialog == null) {
                        noNetWorkDialog = new MaterialDialog.Builder(MainActivity.this)
                                .title(R.string.no_network)
                                .content(R.string.open_network)
                                .backgroundColor(getResources().getColor(JDApplication.COLOR_OF_DIALOG))
                                .contentColor(JDApplication.COLOR_OF_DIALOG_CONTENT)
                                .positiveColor(JDApplication.COLOR_OF_DIALOG_CONTENT)
                                .negativeColor(JDApplication.COLOR_OF_DIALOG_CONTENT)
                                .titleColor(JDApplication.COLOR_OF_DIALOG_CONTENT)
                                .negativeText(R.string.no).positiveText(R.string.yes)
                                .onPositive((dialog, which) -> IntentHelper.toSettingActivity(mContext))
                                .cancelable(false)
                                .build();
                    }
                    if (!noNetWorkDialog.isShowing()) {
                        noNetWorkDialog.show();
                    }
                }
            });
    mRxBusComposite.add(sub);
}
 
Example 7
Source File: AutoRemoveSubscription.java    From akarnokd-misc with Apache License 2.0 5 votes vote down vote up
public static <T> void subscribeAutoRelease(
        Observable<T> source, 
        final Action1<T> onNext, 
        CompositeSubscription composite) {
    Subscriber<T> subscriber = new Subscriber<T>() {
        @Override
        public void onCompleted() {
            composite.remove(this);
        }
        @Override
        public void onError(Throwable e) {
            composite.remove(this);
            RxJavaHooks.onError(e);
        }
        @Override
        public void onNext(T t) {
            try {
                onNext.call(t);
            } catch (Throwable ex) {
                unsubscribe();
                onError(ex);
            }
        }
    };
    composite.add(subscriber);
    source.subscribe(subscriber);
}
 
Example 8
Source File: DebugViewContainer.java    From u2020 with Apache License 2.0 5 votes vote down vote up
private void setupMadge(final ViewHolder viewHolder, CompositeSubscription subscriptions) {
  subscriptions.add(pixelGridEnabled.asObservable().subscribe(enabled -> {
    viewHolder.madgeFrameLayout.setOverlayEnabled(enabled);
  }));
  subscriptions.add(pixelRatioEnabled.asObservable().subscribe(enabled -> {
    viewHolder.madgeFrameLayout.setOverlayRatioEnabled(enabled);
  }));
}
 
Example 9
Source File: RxBus.java    From CleanArch with MIT License 5 votes vote down vote up
/**
 * 订阅
 * @param subscription  new CompositeSubscription()
 * @param eventLisener
 */
public void subscribe(@NonNull CompositeSubscription subscription,@NonNull final EventLisener eventLisener){
    subscription.add(_bus.subscribe(new Action1<Object>() {
        @Override
        public void call(Object event) {
            eventLisener.dealRxEvent(event);
        }
    }));
}
 
Example 10
Source File: CategoryBottomPresenter.java    From FileManager with Apache License 2.0 5 votes vote down vote up
public CategoryBottomPresenter(Context context) {
    this.mContext = context;
    mCompositeSubscription = new CompositeSubscription();
    mCategoryManager = CategoryManager.getInstance();

    mCompositeSubscription.add(RxBus.getDefault()
            .IoToUiObservable(TypeEvent.class)
            .map(TypeEvent::getType)
            .subscribe(type -> {
                if (type == AppConstant.SELECT_ALL) {
                    mView.selectAll();
                } else if (type == AppConstant.REFRESH) {
                    switch (mIndex) {
                        case AppConstant.VIDEO_INDEX:
                            mView.setDataByObservable(mCategoryManager.getVideoList());
                            break;
                        case AppConstant.DOC_INDEX:
                            mView.setDataByObservable(mCategoryManager.getDocList());
                            break;
                        case AppConstant.ZIP_INDEX:
                            mView.setDataByObservable(mCategoryManager.getZipList());
                            break;
                        case AppConstant.APK_INDEX:
                            mView.setDataByObservable(mCategoryManager.getApkList());
                            break;
                    }
                } else if (type == AppConstant.CLEAN_CHOICE) {
                    mView.clearSelect();
                }
            }, Throwable::printStackTrace));


}
 
Example 11
Source File: DebugViewContainer.java    From u2020-mvp with Apache License 2.0 5 votes vote down vote up
private void setupScalpel(final ViewHolder viewHolder, CompositeSubscription subscriptions) {
    subscriptions.add(scalpelEnabled.asObservable().subscribe(enabled -> {
        viewHolder.content.setLayerInteractionEnabled(enabled);
    }));
    subscriptions.add(scalpelWireframeEnabled.asObservable().subscribe(enabled -> {
        viewHolder.content.setDrawViews(!enabled);
    }));
}
 
Example 12
Source File: AppManagerPresenter.java    From FileManager with Apache License 2.0 5 votes vote down vote up
public AppManagerPresenter(Context context) {
    this.mContext = context;
    mCompositeSubscription = new CompositeSubscription();
    mCompositeSubscription.add(RxBus.getDefault()
            .IoToUiObservable(PackageEvent.class)
            .subscribe(packageEvent -> {
                if (packageEvent.getState().equals(PackageEvent.REMOVE)) {
                    mView.removeItem(packageEvent.getPackageName());
                }
            }, Throwable::printStackTrace));
}
 
Example 13
Source File: OrderedMerge.java    From usergrid with Apache License 2.0 5 votes vote down vote up
@Override
public void call( final Subscriber<? super T> outerOperation ) {


    CompositeSubscription csub = new CompositeSubscription();


    //when a subscription is received, we need to subscribe on each observable
    SubscriberCoordinator coordinator = new SubscriberCoordinator( comparator, outerOperation, observables.length );

    InnerObserver<T>[] innerObservers = new InnerObserver[observables.length];


    //we have to do this in 2 steps to get the synchronization correct.  We must set up our total inner observers
    //before starting subscriptions otherwise our assertions for completion or starting won't work properly
    for ( int i = 0; i < observables.length; i++ ) {
        //subscribe to each one and add it to the composite
        //create a new inner and subscribe
        final InnerObserver<T> inner = new InnerObserver<T>( coordinator, maxBufferSize, i );

        coordinator.add( inner );

        innerObservers[i] = inner;
    }
    /**
     * Once we're set up, begin the subscription to sub observables
     */
    for ( int i = 0; i < observables.length; i++ ) {
        //subscribe after setting them up
        //add our subscription to the composite for future cancellation
        Subscription subscription = observables[i].subscribe( innerObservers[i] );

        csub.add( subscription );

        //add the internal composite subscription
        outerOperation.add( csub );
    }
}
 
Example 14
Source File: DebugViewContainer.java    From u2020 with Apache License 2.0 5 votes vote down vote up
private void setupScalpel(final ViewHolder viewHolder, CompositeSubscription subscriptions) {
  subscriptions.add(scalpelEnabled.asObservable().subscribe(enabled -> {
    viewHolder.content.setLayerInteractionEnabled(enabled);
  }));
  subscriptions.add(scalpelWireframeEnabled.asObservable().subscribe(enabled -> {
    viewHolder.content.setDrawViews(!enabled);
  }));
}
 
Example 15
Source File: PostPresenter.java    From android-rxmvp with Apache License 2.0 5 votes vote down vote up
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;
    }
 
Example 16
Source File: RxFingerPrinter.java    From LLApp with Apache License 2.0 5 votes vote down vote up
/**
 * 保存订阅后的subscription
 * @param o
 * @param subscription
 */
public void addSubscription(Object o, Subscription subscription) {
    if (mSubscriptionMap == null) {
        mSubscriptionMap = new HashMap<>();
    }
    String key = o.getClass().getName();
    if (mSubscriptionMap.get(key) != null) {
        mSubscriptionMap.get(key).add(subscription);
    } else {
        CompositeSubscription compositeSubscription = new CompositeSubscription();
        compositeSubscription.add(subscription);
        mSubscriptionMap.put(key, compositeSubscription);
    }
}
 
Example 17
Source File: RxBus.java    From TestChat with Apache License 2.0 5 votes vote down vote up
public void addSubscription(Object object, Subscription subscription) {
        String name = object.getClass().getName();
        if (mSubscriptionMap.get(name) == null) {
                CompositeSubscription compositeSubscription = new CompositeSubscription();
                compositeSubscription.add(subscription);
                mSubscriptionMap.put(name, compositeSubscription);
        } else {
                mSubscriptionMap.get(name).add(subscription);
        }
}
 
Example 18
Source File: RxBusManager.java    From TestChat with Apache License 2.0 5 votes vote down vote up
public void addSubscription(Object object, Subscription subscription) {
        String name = object.getClass().getName();
        if (mSubscriptionMap.get(name) == null) {
                CompositeSubscription compositeSubscription = new CompositeSubscription();
                compositeSubscription.add(subscription);
                mSubscriptionMap.put(name, compositeSubscription);
        } else {
                mSubscriptionMap.get(name).add(subscription);
        }
}
 
Example 19
Source File: ActionModePresenter.java    From FileManager with Apache License 2.0 4 votes vote down vote up
public ActionModePresenter(Context context) {

        mCompositeSubscription = new CompositeSubscription();

        mCompositeSubscription.add(RxBus.getDefault()
                .IoToUiObservable(ActionMutipeChoiceEvent.class)
                .subscribe(event -> {

                    mList = event.getList();
                    mFiles = new String[mList.size()];
                    for (int i = 0; i < mFiles.length; i++) {
                        mFiles[i] = mList.get(i);
                    }

                    mView.cretaeActionMode();

                    final String mSelected = context.getString(R.string._selected);
                    mView.setActionModeTitle(mList.size() + mSelected);

                    if (mList.size() == 0) {
                        mView.finishActionMode();
                    }
                }, Throwable::printStackTrace));

        mCompositeSubscription.add(RxBus.getDefault()
                .IoToUiObservable(TypeEvent.class)
                .subscribe(event -> {
                    if (event.getType() == AppConstant.CLEAN_ACTIONMODE) {
                        mView.finishActionMode();
                    } else if (event.getType() == AppConstant.CLEAN_CHOICE) {
                        mView.finishActionMode();
                    }
                }, Throwable::printStackTrace));

        mCompositeSubscription.add(RxBus.getDefault()
                .IoToUiObservable(ActionChoiceFolderEvent.class)
                .subscribe(event -> {
                    unZipPath = event.getFilePath();
                    mView.showFolderDialog(AppConstant.UNZIP);
                }, Throwable::printStackTrace));

    }
 
Example 20
Source File: StoragePresenter.java    From FileManager with Apache License 2.0 4 votes vote down vote up
public StoragePresenter(Context context) {
    this.mContext = context.getApplicationContext();
    mCompositeSubscription = new CompositeSubscription();
    mScanManger = ScanManager.getInstance();
    mCleanManager = CleanManager.getInstance();
    mProcessManager = ProcessManager.getInstance();

    //生产者速度太快,加上sample对事件进行过滤。否则会出现rx.exceptions.MissingBackpressureException
    //60帧
    mCompositeSubscription.add(RxBus.getDefault()
            .toObservable(TotalJunkSizeEvent.class)
            .sample(16, TimeUnit.MILLISECONDS)
            .subscribeOn(Schedulers.computation())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(totalJunkSizeEvent -> {
                mView.setTotalJunk(totalJunkSizeEvent.getTotalSize());
            }, Throwable::printStackTrace));

    //当前扫描类名
    mCompositeSubscription.add(RxBus.getDefault()
            .toObservable(CurrenScanJunkEvent.class)
            .sample(16, TimeUnit.MILLISECONDS)
            .subscribeOn(Schedulers.computation())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(event -> {
                if (event.getType() == CurrenScanJunkEvent.OVER_CACHE) {
                    mView.setCurrenOverScanJunk(event.getJunkInfo());
                } else if (event.getType() == CurrenScanJunkEvent.SYS_CAHCE) {
                    mView.setCurrenSysCacheScanJunk(event.getJunkInfo());
                }
            }, Throwable::printStackTrace));

    mCompositeSubscription.add(RxBus.getDefault()
            .IoToUiObservable(CurrentJunSizeEvent.class)
            .subscribe(event -> {
                mTotalJunkSize = event.getTotalSize();
                mView.setTotalJunk(FormatUtil.formatFileSize(mTotalJunkSize).toString());
            }, Throwable::printStackTrace));

    mCompositeSubscription.add(RxBus.getDefault()
            .IoToUiObservable(ItemTotalJunkSizeEvent.class)
            .subscribe(event -> {
                mView.setItemTotalJunk(event.getIndex(), event.getTotalSize());
            }, Throwable::printStackTrace));

    mCompositeSubscription.add(RxBus.getDefault()
            .IoToUiObservable(JunkDataEvent.class)
            .subscribe(junkDataEvent -> {
                mView.setData(junkDataEvent.getJunkGroup());
            }, Throwable::printStackTrace));

    mCompositeSubscription.add(RxBus.getDefault()
            .IoToUiObservable(JunkShowDialogEvent.class)
            .subscribe(event -> {
                mView.showDialog();
            }, Throwable::printStackTrace));

    mCompositeSubscription.add(RxBus.getDefault()
            .IoToUiObservable(JunkDismissDialogEvent.class)
            .subscribe(event -> {
                mView.dimissDialog(event.getIndex());
            }, Throwable::printStackTrace));


    mCompositeSubscription.add(RxBus.getDefault()
            .IoToUiObservable(JunkTypeClickEvent.class)
            .subscribe(event -> {
                mView.groupClick(event.isExpand(), event.getPosition());
            }, Throwable::printStackTrace));

}