Permalink
Browse files

callback hell suedo code

  • Loading branch information...
Noh.Jaechun Noh.Jaechun
Noh.Jaechun authored and Noh.Jaechun committed Oct 12, 2017
1 parent d2a9486 commit bba6a30ed3d5efca5707ab3edf89fbae16f92fe3
@@ -0,0 +1,9 @@
package com.suribada.rxjavabook.weather;
/**
* Created by Naver on 2017. 10. 12..
*/
public class Area {
public String code;
}
@@ -0,0 +1,59 @@
package com.suribada.rxjavabook.weather;
import android.location.Location;
/**
* 콜백 Hell 표현
*
* Created by Naver on 2017. 10. 12..
*/
public class LegacyWeatherRepository {
public interface AreaResultListener {
void onResult(int code, Area area);
void onFailure(Throwable e);
}
public interface WeatherResultListener {
void onResult(int code, Weather weather);
void onFail(Throwable e);
}
public void requestWeather(Location location) {
requestLocationCode(location, new AreaResultListener() {
@Override
public void onResult(int code, Area area) {
String areaCode = "1111"; // 디폴트 위치
if (code == 200) {
areaCode = area.code;
}
requestWeather(areaCode, new WeatherResultListener() {
@Override
public void onResult(int code, Weather weather) {
// 화면에 보여주기
}
@Override
public void onFail(Throwable e) {
// 로그나 Toast
}
});
}
@Override
public void onFailure(Throwable e) {
// 로그나 Toast
}
});
}
public void requestLocationCode(Location location, AreaResultListener listener) {
}
public void requestWeather(String areaCode, WeatherResultListener listener) {
}
}
@@ -0,0 +1,8 @@
package com.suribada.rxjavabook.weather;
/**
* Created by Naver on 2017. 10. 12..
*/
public class Weather {
}
@@ -7,6 +7,7 @@
import java.util.List;
import io.reactivex.Observable;
import io.reactivex.observers.DisposableObserver;
/**
* Created by lia on 2017-10-12.
@@ -39,4 +40,26 @@ public void testObservable() {
private void showText(String input) {
System.out.println("input=" + input);
}
public void testDisposableObserver() {
Observable.fromIterable(list)
.filter(value -> value.length() > 3)
.map(os -> "OS:" + os)
.subscribe(new DisposableObserver<String>() {
@Override
public void onNext(String s) {
}
@Override
public void onError(Throwable e) {
}
@Override
public void onComplete() {
}
}
}
}
View
@@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-beta5'
classpath 'com.android.tools.build:gradle:3.0.0-beta6'
}
}

0 comments on commit bba6a30

Please sign in to comment.