Created
January 30, 2015 03:29
-
-
Save SeongUgJung/5dcdcdb22174a5af50e2 to your computer and use it in GitHub Desktop.
like fork & join as RxJava-Android
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void refreshTokenAndGoNextActivity(long initTime) { | |
// like fork & join...but need to refactor | |
Observable.combineLatest(Observable.create(new Observable.OnSubscribe<Integer>() { | |
@Override | |
public void call(Subscriber<? super Integer> subscriber) { | |
new Thread(new Runnable() { | |
@Override | |
public void run() { | |
try { | |
introModel.refreshAccountInfo(); | |
subscriber.onNext(200); | |
} catch (JandiNetworkException e) { | |
subscriber.onNext(e.httpStatusCode); | |
} | |
subscriber.onCompleted(); | |
} | |
}).start(); | |
} | |
}), Observable.create(new Observable.OnSubscribe<Integer>() { | |
@Override | |
public void call(Subscriber<? super Integer> subscriber) { | |
new Thread(new Runnable() { | |
@Override | |
public void run() { | |
subscriber.onNext(introModel.refreshEntityInfo() ? 1 : -1); | |
subscriber.onCompleted(); | |
} | |
}).start(); | |
} | |
}), new Func2<Integer, Integer, Integer>() { | |
@Override | |
public Integer call(Integer o, Integer o2) { | |
return o; | |
} | |
}).subscribe(new Action1<Integer>() { | |
@Override | |
public void call(Integer o) { | |
if (o == 200) { | |
introModel.sleep(initTime, MAX_DELAY_MS); | |
introViewModel.moveMainOrTeamSelectActivity(); | |
} else if (o == 401) { | |
introModel.clearTokenInfo(); | |
introModel.clearAccountInfo(); | |
introModel.sleep(initTime, MAX_DELAY_MS); | |
introViewModel.moveToIntroTutorialActivity(); | |
} else { | |
introViewModel.showWarningToast(getString(R.string.err_network)); | |
finishOnUiThread(); | |
} | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment