1

这是一个用 RxJava 编写的方法

    public Observable<String> method() {
    return model.getOffers()
            .filter(new Func1<Offers, Boolean>() {
                @Override
                public Boolean call(Offers offers) {
                    if (offers == null)
                        return false;
                    return offers.hasSuperOffer();
                }
            })
            .flatMap(new Func1<Offers, Observable<Long>>() {
                @Override
                public Observable<Long> call(Offers offers) {
                    Long offerEndTime = offers.getRemainingTime();
                    if (offerEndTime == null) {
                        return Observable.empty();
                    }
                    AtomicLong remainingTimeSec;
                    Long currentTimeSec = System.currentTimeMillis() / 1000;
                    if (remainingTimeSec.get() == -1 && (offerEndTime > currentTimeSec)) {
                        remainingTimeSec.set(offerEndTime - currentTimeSec);
                    } else {
                        return Observable.empty();
                    }
                    return Observable.interval(1, TimeUnit.SECONDS)
                            .onBackpressureDrop()
                            .subscribeOn(Schedulers.io())
                            .observeOn(Schedulers.io())
                            .take(remainingTimeSec.intValue())
                            .doOnUnsubscribe(new Action0() {
                                @Override
                                public void call() {
                                }
                            })
                            .doOnCompleted(new Action0() {
                                @Override
                                public void call() {
                                }
                            })
                            .map(new Func1<Long, Long>() {
                                @Override
                                public Long call(Long elapsedTimeSec) {
                                    return remainingTimeSec.getAndDecrement();
                                }
                            });
                }
            })
            .map(new Func1<Long, String>() {
                @Override
                public String call(Long remainingTime) {
                    return DateUtils.getRemainingTimeStr(remainingTime);
                }
            });
}

我正在尝试将其转换为 RxJava3,但某些参数已更改: Func1 已更改为 Function Action0 已更改为 Action

在我进行更改后,过滤器中出现以下错误:

filter (io.reactivex.rxjava3.functions@io.reactivex.rxjava3.annotations.NonNull Predicate <? MyClass> in Observable cannot be applied to (anonymous.io.reactivex.rxjava3.functions.Function <MyClass.model.Offers.java.lang.Boolean>)

谁能帮我?谢谢!

4

0 回答 0