標籤:parse int art pil fileutil 多檔案 請求 key值 UI
功能
最佳化設計:加入基礎API,減少Api冗餘
強大的緩衝模式: 支援離線緩衝, 無網路智能載入緩衝,可配置是否需要緩衝
cookie管理:內建cookie管理機制
全方位請求模式:支援多種方式訪問網路(get,put, post ,delete)
輕送調用:支援表單,圖文一起,json上傳。
檔案傳輸:支援檔案下載和上傳,支援進度
動態添加:支援要求頭和參數統一添加,分別添加。
結果處理:支援對返回結果的統一處理,自動幫你序列化複雜的資料。
擴充性強:支援自訂的Retrofit的API,預設Api無法滿足時可自訂自己的Service
悠雅方便:支援統一請求訪問網路的流程式控制制,以方便幫你完美加入Processbar進度。
RxJava結合: 結合RxJava,線程智能控制
整合
Gradle:
RxAPi
主要處理請求的API,包含RxGet, RxPost, RxDelete,RxPut, RxBody,RxFrom, RxUpLoad,RxDownLoad.使用基本APi之前 請閱讀對RxCallBack的介紹。
RxGet
進行get方式的請求調用,多種返回結果的方式供你選擇,返回不同的資料類型參考請看原文連結RxCallBack的介紹。
基礎使用:
返回String
new Novate.Builder(this) .baseUrl(“www.xxx.com/”) .build() .rxGet("service/path", parameters, new RxStringCallback() { });
返回Bean
novate.rxGet("path or url", parameters, new RxResultCallback<JavaBean>() { });
返回List
new Novate.Builder(this) .baseUrl("http://xxx.com/") .build() .rxGet("service/getList", parameters, new RxListCallback<List<JavaBean>>() { ... });
返回File
novate.rxGet("path or url", null, new RxFileCallBack(filePath, "name.jpg") {
..... });
RxPost:
進行Post方式的請求調用
返回String
novate.rxPost("path or url", parameters, new RxStringCallback() { ..... });
返回Bean
novate.rxPost("path or url", parameters, new RxResultCallback<ResultModel>() {
});
返回List
novate.rxPost("path or url", parameters, new RxListCallback<List<ResultModel>>() { .... });
返回File
novate.rxPost("path or url", null, new RxFileCallBack(filePath, "name.jpg") { .... });
上傳檔案
這裡主要介紹怎麼使用Novate上傳檔案:
Novate提供了2種方式上傳檔案。body和part模式,Body不包含key值,part包含key值。
RxUploadWithBody
以Body方式post資料,可以上報檔案,圖片等。
String mPath = uploadPath; //"you File path "; String url = "http:/xxx.com"; novate.rxUploadWithBody(url, new File(mPath), new RxStringCallback() { .... });}
RxUploadWithPart
上傳檔案,預設的key是 image
String mPath = uploadPath; //"you File path "; String url = "http:/xxx.com"; File file = new File(mPath); novate.rxUploadWithPart(url, file, new RxStringCallback() { .... });
上傳多檔案:
RxUploadWithPartListByFile:
List<File> fileList = new ArrayList<>(); fileList.add(file); fileList.add(file); fileList.add(file); novate.rxUploadWithPartListByFile(url, fileList, new RxStringCallback() { });
圖文一起
RequestBody requestBody = new MultipartBody.Builder().setType(MultipartBody.FORM) .addFormDataPart("key1", V1) .addFormDataPart("key2", v2) .addFormDataPart("file", file.getName(), RequestBody.create(MediaType.parse("image/*"), file)) .build(); novate.rxBody(url , requestBody, callback);
RxBody
RequestBody requestBody = new MultipartBody.Builder().setType(MultipartBody.FORM) .addFormDataPart("key1", V1) .addFormDataPart("key2", v2) .addFormDataPart("file", file.getName(), RequestBody.create(MediaType.parse("image/*"), file)) .build(); novate.rxBody(url , requestBody, callback);
下載檔案
使用rxGet()實現下載:
String downUrl = "http://wap.dl.pinyin.sogou.com/wapdl/hole/201512/03/SogouInput_android_v7.11_sweb.apk"; novate.rxGet(downUrl, parameters, new RxFileCallBack(FileUtil.getBasePath(this), "test.apk") { });
RxDown()下載
String downUrl = "http://wap.dl.pinyin.sogou.com/wapdl/hole/201512/03/SogouInput_android_v7.11_sweb.apk"; new Novate.Builder(this) .rxDownload(downUrl, new RxFileCallBack(FileUtil.getBasePath(this), "test.apk") { });
OkHTTP 姿勢
喜歡okhtp姿勢的朋友可以繼續使用姿勢:
Request request = new Request.Builder() .get() .url("you url") .build(); novate.execute(request, new RxStringCallback() { });
Retrofit Api 姿勢
Novate預設的API
讓你不爽時,Novate同樣支援你自己Retrofit的ApiService
。
定義APi 同Retrofit的Api
建立MyApi
public interface MyApi { @GET("url") Observable<MyBean> getdata(@QueryMap Map<String, String> maps); }
Execute
調用Call()
MyApi myApi = novate.create(MyApi.class); novate.call(myApi.getdata(parameters), new BaseSubscriber<MyBean>{ ‘‘‘‘‘‘‘ });}
Novate 一款Android RxStyle的網路架構