如何在另一个中使用一个可观察值?

时间:2017-03-25 20:56:24

标签: android rx-java rx-android

我有一个Android应用程序,从网络中获取2种数据类型,一种用于频道列表,另一种用于epg&#39>

关键是,我的epg网址必须包含频道列表中的频道ID。这就是我想要做的事情

Observable<ChannelList> channelList =
        NetworkService.getChannels();

List<String> channelIds = new ArrayList<>();

channelList.subscribe(chList -> {
            for (ChannelInfo chInfo : chList.getChannelInfoList()) {
                channelIds.add(chInfo.getId());
            }
        });

Observable<EpgList> epgList =
        NetworkService.getEpgList(channelIds);

但是在方法完成之前它不会获取id,所以我如何阻止该点的执行并需要id?

1 个答案:

答案 0 :(得分:1)

试试这个:

    final TwitterAuthConfig authConfig = new TwitterAuthConfig(BuildConfig.CONSUMER_KEY,
            BuildConfig.CONSUMER_SECRET);

    final Fabric fabric = new Fabric.Builder(this)
            .kits(new Twitter(authConfig))
            .logger(new DefaultLogger(Log.DEBUG))
            .debuggable(true)
            .build();

    Fabric.with(fabric);

    final HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
    loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BASIC);
    final OkHttpClient customClient = new OkHttpClient.Builder()
            .addInterceptor(loggingInterceptor).build();

    final TwitterSession activeSession = TwitterCore.getInstance()
            .getSessionManager().getActiveSession();

    final TwitterApiClient customApiClient;
    if (activeSession != null) {
        customApiClient = new TwitterApiClient(activeSession, customClient);
        TwitterCore.getInstance().addApiClient(activeSession, customApiClient);
    } else {
        customApiClient = new TwitterApiClient(customClient);
        TwitterCore.getInstance().addGuestApiClient(customApiClient);
    }