use of home.smart.fly.http.model.GankAndroid in project My-MVP by REBOOTERS.
the class RxJavaBaseActivity method withRetrofit2AndGson.
private void withRetrofit2AndGson() {
final OkHttpClient mClient = new OkHttpClient.Builder().readTimeout(10, TimeUnit.SECONDS).connectTimeout(30, TimeUnit.SECONDS).addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY)).build();
final Retrofit mRetrofit = new Retrofit.Builder().client(mClient).baseUrl(BASE_URL).addConverterFactory(GsonConverterFactory.create()).addCallAdapterFactory(RxJava2CallAdapterFactory.create()).build();
GankApi mGankApi = mRetrofit.create(GankApi.class);
Observable<GankAndroid> mAndroidObservable = mGankApi.getData("10/1");
mAndroidObservable.subscribeOn(Schedulers.io()).map(new Function<GankAndroid, GankAndroid.ResultsEntity>() {
@Override
public GankAndroid.ResultsEntity apply(GankAndroid gankAndroid) throws Exception {
return gankAndroid.getResults().get(0);
}
}).observeOn(AndroidSchedulers.mainThread()).subscribe(new Consumer<GankAndroid.ResultsEntity>() {
@Override
public void accept(GankAndroid.ResultsEntity resultsEntity) throws Exception {
sb.append(resultsEntity.getCreatedAt()).append("\n").append(resultsEntity.getType()).append("\n").append(resultsEntity.getDesc()).append("\n").append(resultsEntity.getUrl()).append("\n").append(resultsEntity.getWho());
logContent.setText(sb.toString());
}
});
}
Aggregations