use of com.lzy.demo.model.ServerModel in project okhttp-OkGo by jeasonlzy.
the class FormUploadActivity method formUpload.
@OnClick(R.id.formUpload)
public void formUpload(View view) {
ArrayList<File> files = new ArrayList<>();
if (imageItems != null && imageItems.size() > 0) {
for (int i = 0; i < imageItems.size(); i++) {
files.add(new File(imageItems.get(i).path));
}
}
//拼接参数
//
OkGo.post(Urls.URL_FORM_UPLOAD).tag(//
this).headers("header1", //
"headerValue1").headers("header2", //
"headerValue2").params("param1", //
"paramValue1").params("param2", //
"paramValue2").addFileParams("file", // 这种方式为同一个key,上传多个文件
files).execute(new JsonCallback<LzyResponse<ServerModel>>() {
@Override
public void onBefore(BaseRequest request) {
super.onBefore(request);
btnFormUpload.setText("正在上传中...");
}
@Override
public void onSuccess(LzyResponse<ServerModel> responseData, Call call, Response response) {
handleResponse(responseData.data, call, response);
btnFormUpload.setText("上传完成");
}
@Override
public void onError(Call call, Response response, Exception e) {
super.onError(call, response, e);
handleError(call, response);
btnFormUpload.setText("上传出错");
}
@Override
public void upProgress(long currentSize, long totalSize, float progress, long networkSpeed) {
System.out.println("upProgress -- " + totalSize + " " + currentSize + " " + progress + " " + networkSpeed);
String downloadLength = Formatter.formatFileSize(getApplicationContext(), currentSize);
String totalLength = Formatter.formatFileSize(getApplicationContext(), totalSize);
tvDownloadSize.setText(downloadLength + "/" + totalLength);
String netSpeed = Formatter.formatFileSize(getApplicationContext(), networkSpeed);
tvNetSpeed.setText(netSpeed + "/S");
tvProgress.setText((Math.round(progress * 10000) * 1.0f / 100) + "%");
pbProgress.setMax(100);
pbProgress.setProgress((int) (progress * 100));
}
});
}
use of com.lzy.demo.model.ServerModel in project okhttp-OkGo by jeasonlzy.
the class TestActivity method btn1.
@OnClick(R.id.btn1)
public void btn1(View view) {
Call<String> stringCall = OkGo.get("").getCall(StringConvert.create());
Call<Bitmap> bitmapCall = OkGo.get("").getCall(BitmapConvert.create());
Call<File> fileCall = OkGo.get("").getCall(new FileConvert());
Call<LzyResponse<ServerModel>> call = OkGo.get("").getCall(new JsonConvert<LzyResponse<ServerModel>>() {
});
Call<LzyResponse<ServerModel>> listCall = OkGo.get("").getCall(new JsonConvert<LzyResponse<ServerModel>>() {
});
Observable<String> stringObservable = OkGo.get("").getCall(StringConvert.create(), RxAdapter.<String>create());
Observable<LzyResponse<ServerModel>> observable = OkGo.get("").getCall(new JsonConvert<LzyResponse<ServerModel>>() {
}, RxAdapter.<LzyResponse<ServerModel>>create());
}
use of com.lzy.demo.model.ServerModel in project okhttp-OkGo by jeasonlzy.
the class RxCommonActivity method jsonArrayRequest.
@OnClick(R.id.jsonArrayRequest)
public void jsonArrayRequest(View view) {
Subscription subscription = //
ServerApi.getServerListModel("aaa", "bbb").doOnSubscribe(new Action0() {
@Override
public void call() {
showLoading();
}
}).map(new Func1<LzyResponse<List<ServerModel>>, List<ServerModel>>() {
@Override
public List<ServerModel> call(LzyResponse<List<ServerModel>> response) {
return response.data;
}
}).observeOn(//
AndroidSchedulers.mainThread()).subscribe(new Action1<List<ServerModel>>() {
@Override
public void call(List<ServerModel> serverModels) {
//请求成功
dismissLoading();
handleResponse(serverModels, null, null);
}
}, new Action1<Throwable>() {
@Override
public void call(Throwable throwable) {
//请求失败
throwable.printStackTrace();
showToast("请求失败");
dismissLoading();
handleError(null, null);
}
});
addSubscribe(subscription);
}
use of com.lzy.demo.model.ServerModel in project okhttp-OkGo by jeasonlzy.
the class RxCommonActivity method retrofitRequest.
@OnClick(R.id.retrofitRequest)
public void retrofitRequest(View view) {
Subscription subscription = //
ServerApi.getServerModel("aaa", "bbb").doOnSubscribe(new Action0() {
@Override
public void call() {
//开始请求前显示对话框
showLoading();
}
}).map(new Func1<LzyResponse<ServerModel>, ServerModel>() {
@Override
public ServerModel call(LzyResponse<ServerModel> response) {
return response.data;
}
}).observeOn(//切换到主线程
AndroidSchedulers.mainThread()).subscribe(new Action1<ServerModel>() {
@Override
public void call(ServerModel serverModel) {
//请求成功
dismissLoading();
handleResponse(serverModel, null, null);
}
}, new Action1<Throwable>() {
@Override
public void call(Throwable throwable) {
//请求失败
throwable.printStackTrace();
showToast("请求失败");
dismissLoading();
handleError(null, null);
}
});
addSubscribe(subscription);
}
use of com.lzy.demo.model.ServerModel in project okhttp-OkGo by jeasonlzy.
the class PostTextActivity method postJson.
@OnClick(R.id.postJson)
public void postJson(View view) {
HashMap<String, String> params = new HashMap<>();
params.put("key1", "value1");
params.put("key2", "这里是需要提交的json格式数据");
params.put("key3", "也可以使用三方工具将对象转成json字符串");
params.put("key4", "其实你怎么高兴怎么写都行");
JSONObject jsonObject = new JSONObject(params);
//
OkGo.post(Urls.URL_TEXT_UPLOAD).tag(//
this).headers("header1", //
"headerValue1").upJson(//
jsonObject).execute(new DialogCallback<LzyResponse<ServerModel>>(this) {
@Override
public void onSuccess(LzyResponse<ServerModel> responseData, Call call, Response response) {
handleResponse(responseData.data, call, response);
}
@Override
public void onError(Call call, Response response, Exception e) {
super.onError(call, response, e);
handleError(call, response);
}
});
}
Aggregations