Search in sources :

Example 6 with Subscription

use of rx.Subscription in project GeekNews by codeestX.

the class MainPresenter method registerEvent.

void registerEvent() {
    Subscription rxSubscription = RxBus.getDefault().toObservable(NightModeEvent.class).compose(RxUtil.<NightModeEvent>rxSchedulerHelper()).map(new Func1<NightModeEvent, Boolean>() {

        @Override
        public Boolean call(NightModeEvent nightModeEvent) {
            return nightModeEvent.getNightMode();
        }
    }).subscribe(new CommonSubscriber<Boolean>(mView, "切换模式失败ヽ(≧Д≦)ノ") {

        @Override
        public void onNext(Boolean aBoolean) {
            mView.useNightMode(aBoolean);
        }
    });
    addSubscrebe(rxSubscription);
}
Also used : NightModeEvent(com.codeest.geeknews.model.event.NightModeEvent) Subscription(rx.Subscription) Func1(rx.functions.Func1)

Example 7 with Subscription

use of rx.Subscription in project GeekNews by codeestX.

the class MainPresenter method checkVersion.

@Override
public void checkVersion(final String currentVersion) {
    Subscription rxSubscription = mRetrofitHelper.fetchVersionInfo().compose(RxUtil.<MyHttpResponse<VersionBean>>rxSchedulerHelper()).compose(RxUtil.<VersionBean>handleMyResult()).filter(new Func1<VersionBean, Boolean>() {

        @Override
        public Boolean call(VersionBean versionBean) {
            return Integer.valueOf(currentVersion.replace(".", "")) < Integer.valueOf(versionBean.getCode().replace(".", ""));
        }
    }).map(new Func1<VersionBean, String>() {

        @Override
        public String call(VersionBean bean) {
            StringBuilder content = new StringBuilder("版本号: v");
            content.append(bean.getCode());
            content.append("\r\n");
            content.append("版本大小: ");
            content.append(bean.getSize());
            content.append("\r\n");
            content.append("更新内容:\r\n");
            content.append(bean.getDes().replace("\\r\\n", "\r\n"));
            return content.toString();
        }
    }).subscribe(new CommonSubscriber<String>(mView) {

        @Override
        public void onNext(String s) {
            mView.showUpdateDialog(s);
        }
    });
    addSubscrebe(rxSubscription);
}
Also used : Subscription(rx.Subscription) VersionBean(com.codeest.geeknews.model.bean.VersionBean) Func1(rx.functions.Func1)

Example 8 with Subscription

use of rx.Subscription in project GeekNews by codeestX.

the class MainPresenter method checkPermissions.

@Override
public void checkPermissions(RxPermissions rxPermissions) {
    Subscription rxSubscription = rxPermissions.request(Manifest.permission.WRITE_EXTERNAL_STORAGE).subscribe(new Action1<Boolean>() {

        @Override
        public void call(Boolean granted) {
            if (granted) {
                mView.startDownloadService();
            } else {
                mView.showError("下载应用需要文件写入权限哦~");
            }
        }
    });
    addSubscrebe(rxSubscription);
}
Also used : Subscription(rx.Subscription)

Example 9 with Subscription

use of rx.Subscription in project GeekNews by codeestX.

the class NodePresenter method getTopInfo.

@Override
public void getTopInfo(String node_name) {
    Subscription rxSubscription = mRetrofitHelper.fetchNodeInfo(node_name).compose(RxUtil.<NodeBean>rxSchedulerHelper()).subscribe(new CommonSubscriber<NodeBean>(mView) {

        @Override
        public void onNext(NodeBean nodeBean) {
            mView.showTopInfo(nodeBean);
        }
    });
    addSubscrebe(rxSubscription);
}
Also used : NodeBean(com.codeest.geeknews.model.bean.NodeBean) Subscription(rx.Subscription)

Example 10 with Subscription

use of rx.Subscription in project GeekNews by codeestX.

the class NodePresenter method getContent.

@Override
public void getContent(String node_name) {
    Subscription rxSubscription = mRetrofitHelper.fetchTopicList(node_name).compose(RxUtil.<List<NodeListBean>>rxSchedulerHelper()).subscribe(new CommonSubscriber<List<NodeListBean>>(mView) {

        @Override
        public void onNext(List<NodeListBean> nodeListBeen) {
            mView.showContent(nodeListBeen);
        }
    });
    addSubscrebe(rxSubscription);
}
Also used : NodeListBean(com.codeest.geeknews.model.bean.NodeListBean) List(java.util.List) Subscription(rx.Subscription)

Aggregations

Subscription (rx.Subscription)275 Test (org.junit.Test)82 List (java.util.List)66 Action0 (rx.functions.Action0)45 ArrayList (java.util.ArrayList)40 CompositeSubscription (rx.subscriptions.CompositeSubscription)40 CountDownLatch (java.util.concurrent.CountDownLatch)38 Func1 (rx.functions.Func1)24 AtomicReference (java.util.concurrent.atomic.AtomicReference)20 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)19 Observable (rx.Observable)18 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)17 LinkedList (java.util.LinkedList)13 CommandStreamTest (com.netflix.hystrix.metric.CommandStreamTest)11 PlayList (io.github.ryanhoo.music.data.model.PlayList)11 View (android.view.View)10 MetaChangedEvent (io.hefuyi.listener.event.MetaChangedEvent)10 Bundle (android.os.Bundle)9 IOException (java.io.IOException)9 AndroidSchedulers (rx.android.schedulers.AndroidSchedulers)9