use of home.smart.fly.httpurlconnectiondemo.retrofit2.bean.GithubUserBean in project My-MVP by REBOOTERS.
the class Retrofit2DemoActivity method SimpleRetrofit.
private void SimpleRetrofit() {
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
Retrofit.Builder builder = new Retrofit.Builder().baseUrl(BASE_URL);
Retrofit retrofit = builder.client(httpClient.build()).build();
ApiService simpleService = retrofit.create(ApiService.class);
Call<ResponseBody> call = simpleService.getUserString(name);
call.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
loading.dismiss();
try {
String result = response.body().string();
Gson gson = new Gson();
GithubUserBean bean = gson.fromJson(result, GithubUserBean.class);
setUserView(bean);
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
loading.dismiss();
}
});
}
use of home.smart.fly.httpurlconnectiondemo.retrofit2.bean.GithubUserBean in project My-MVP by REBOOTERS.
the class Retrofit2DemoActivity method LazyRetrofit.
private void LazyRetrofit() {
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
Retrofit.Builder builder = new Retrofit.Builder().baseUrl(BASE_URL).addConverterFactory(GsonConverterFactory.create());
Retrofit retrofit = builder.client(httpClient.build()).build();
ApiService service = retrofit.create(ApiService.class);
Call<GithubUserBean> call = service.getUser(name);
call.enqueue(new Callback<GithubUserBean>() {
@Override
public void onResponse(Call<GithubUserBean> call, Response<GithubUserBean> response) {
GithubUserBean bean = response.body();
setUserView(bean);
loading.dismiss();
}
@Override
public void onFailure(Call<GithubUserBean> call, Throwable t) {
loading.dismiss();
}
});
}
use of home.smart.fly.httpurlconnectiondemo.retrofit2.bean.GithubUserBean in project My-MVP by REBOOTERS.
the class Retrofit2DemoActivity method RxRetrofit.
private void RxRetrofit() {
ApiService service = GenServiceUtil.createService(ApiService.class);
final Call<GithubUserBean> call = service.getUser(name);
final Observable myObserable = Observable.create(new Observable.OnSubscribe<GithubUserBean>() {
@Override
public void call(Subscriber<? super GithubUserBean> subscriber) {
Response<GithubUserBean> bean = null;
try {
bean = call.execute();
subscriber.onNext(bean.body());
} catch (IOException e) {
e.printStackTrace();
subscriber.onError(e);
}
subscriber.onCompleted();
}
});
myObserable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).map(new Func1<GithubUserBean, GithubUserBean>() {
@Override
public GithubUserBean call(GithubUserBean o) {
if (TextUtils.isEmpty(o.getBio())) {
o.setBio("nothing !");
}
return o;
}
}).subscribe(new Subscriber<GithubUserBean>() {
@Override
public void onCompleted() {
loading.dismiss();
}
@Override
public void onError(Throwable e) {
loading.dismiss();
}
@Override
public void onNext(GithubUserBean o) {
setUserView(o);
}
});
}
Aggregations