Google 인식 API를 사용하는 중 일부가 엉망이되어 RxJava에 대한 이해가 제한됩니다.Return 콜백에서 관찰 할 수 있습니다. rxjava
최종 목표 : Api에서 Weather와 Location을 가져 와서이를 업데이트 할 수있는 하나의 객체로 병합하고 싶습니다.
그러나 반환 유형이 void이고 api.getWeather 및 api.getLocation에서 날씨 및 위치 개체를 병합하는 방법을 알기 때문에 API 콜백에서 Observable을 반환하는 방법을 잘 모르겠습니다. 내 프로젝트에서 내 다른 것들에 대한
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가 구독자에서 실행 됨) unsubscribe wouldnt 어쨌든 모든 요소 (실제로는 그 중 하나)를 받았거나 오류가 발생했기 때문에 아무 것도하지 마십시오. –