私はGoogleの意識のAPIをいくつか取り乱しています。今ではRxJavaの理解が私を制限しています。Returnコールバックで観測可能rxjava
最後に達成したいこと: 私は天気と場所をApiから取得し、それらを1つのオブジェクトに結合して更新のために渡すことができます。
しかし、戻り値の型がvoidであることからapiコールバックからObservableをどのように返すか、api.getWeatherとapi.getLocationからweatherオブジェクトとlocationオブジェクトをマージする方法はわかりません私のプロジェクトで私の他のもののため
public void requestUserCurrentInfo() {
Subscription userInfo = getWeatherLocation().subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()).subscribe(userinfo ->
Log.d(TAG,userinfo.something()));
}
public Observable<UserInfo> getWeatherLocation() {
try {
Awareness.SnapshotApi.getWeather(client)
.setResultCallback(weather -> {
if (!weather.getStatus().isSuccess()) {
Log.d(TAG, "Could not get weather");
return;
}
//How do I do here?
return weather.getWeather();
});
Awareness.SnapshotApi.getLocation(mGoogleApiClient)
.setResultCallback(retrievedLocation -> {
if(!retrievedLocation.getStatus().isSuccess()) return;
Log.d("FRAG", retrievedLocation.getLocation().getLatitude() + "");
});
} catch (SecurityException exception) {
throw new SecurityException("No permission " + exception);
}
}
、私はすべてのステップが観察< SmhiResponseを返すため、私はこのようにそれを得ることができ、リポジトリパターン以下のREST APIを介していくつかのものを得る>
getWeatherSubscription = getWeatherUsecase.execute().subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()).subscribe(
smhiResponseModel -> {Log.d(TAG,"Retrieved weather"); locationView.hideLoading();},
err -> {Log.d(TAG,"Error fetching weather"); locationView.hideLoading();}
);
ありがとう魅力があり、このように書くと非常に意味をなさない – buddhabath
Zこの場合、どのようにして購読解除を管理するのですか? – buddhabath
終了すると、購読者に対してonErrorまたはonCompletedが実行されます。あなたはすでにすべての要素(実際にはただ一つ)を受け取っているか、エラーがスローされたため、とにかく何かをしてください。 –