Skip to content

Commit

Permalink
callback hell suedo code
Browse files Browse the repository at this point in the history
  • Loading branch information
Noh.Jaechun authored and Noh.Jaechun committed Oct 12, 2017
1 parent d2a9486 commit bba6a30
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 1 deletion.
9 changes: 9 additions & 0 deletions app/src/main/java/com/suribada/rxjavabook/weather/Area.java
@@ -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 {
}
23 changes: 23 additions & 0 deletions app/src/test/java/com/suribada/rxjavabook/RxJava1Test.java
Expand Up @@ -7,6 +7,7 @@
import java.util.List;

import io.reactivex.Observable;
import io.reactivex.observers.DisposableObserver;

/**
* Created by lia on 2017-10-12.
Expand Down Expand Up @@ -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() {

}
}
}
}
2 changes: 1 addition & 1 deletion build.gradle
Expand Up @@ -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'
}
}

Expand Down

0 comments on commit bba6a30

Please sign in to comment.