diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 60508a114b63a18cb50332b0bb217c419db263ef..0000000000000000000000000000000000000000 --- a/LICENSE +++ /dev/null @@ -1,11 +0,0 @@ -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. \ No newline at end of file diff --git a/README.md b/README.md index ccb511c6d3273ebaaef6966bc44250b48230d6ca..703adf691072398f8728490eb05bdb33838eeb83 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,13 @@ # BaseOkHttp V3 -**本项目是基于开源项目BaseOkHttp V3进行鸿蒙化的移植和开发的,可以通过项目标签()以及github地址()追踪到原安卓项目版本** +**本项目是基于开源项目BaseOkHttp V3进行OpenHarmony的移植和开发的,可以通过项目标签以及github地址()追踪到原安卓项目版本** ## 项目介绍 - 项目名称:BaseOkHttp V3 -- 所属系列:鸿蒙的第三方组件适配移植 +- 所属系列:OpenHarmony的第三方组件适配移植 - 功能:OkHttp的二次封装库,提供各种快速使用方法以及更为方便的扩展功能。提供更高效的Json请求和解析工具以及文件上传下载封装,HTTPS和Cookie操作也更得心应手 -- 基线版本:Release版本号 3.2.1 +- 基线版本:BaseOkHttpV3组件 Release 3.2.1 - 项目移植状态:完成 - 调用差异:无 - 开发版本:sdk5,DevEco Studio2.1 beta3 @@ -21,19 +21,23 @@ ## 安装教程 -1. 下载baseokhttp_v3的har包baseokhttp_v3_ohos.har(位于:)。 -2. 启动 DevEco Studio,将下载的har包,导入工程目录“entry->libs”下。 -3. 在moudle级别下的build.gradle文件中添加依赖,在dependences标签中增加对libs目录下har包的引用。 -``` -dependencies { - implementation fileTree(dir: 'libs', include: ['*.jar', '*.har']) - compile(name:'baseokhttp_v3_ohos', ext:'har') - compile files('libs\\okhttp-4.9.0.jar') - compile files('libs\\okio-2.10.0.jar') - compile files('libs\\kotlin-stdlib-1.3.50.jar') - compile files('libs\\json.jar') +1.在项目根目录下的build.gradle文件中, + ```gradle +allprojects { + repositories { + maven { + url 'https://s01.oss.sonatype.org/content/repositories/snapshots/' + } + } } -``` + ``` +2.在entry模块的build.gradle文件中, + ```gradle + dependencies { + implementation('com.gitee.chinasoft_ohos:BaseOkHttpV3:0.0.1-SNAPSHOT') + ...... + } + ``` 如无法运行,删除项目.gradle,.idea,build,gradle,build.gradle文件, @@ -781,8 +785,20 @@ BaseOkHttpV3 的底层是 OkHttp,我们提供了自动化的默认 OkHttpClien 要全局拦截 OkHttpClient 或 OkHttpClient.Builder,您可以设置`BaseOkHttp.globalCustomOkHttpClient`和`BaseOkHttp.globalCustomOkHttpClientBuilder`进行拦截修改,需要将修改后的组件 return 到接口返回参数中才可生效。 +## 测试信息 + +CodeCheck代码测试无异常 + +CloudTest代码测试无异常 + +火绒安全病毒安全检测通过 + +当前版本demo功能与安卓原组件基本无差异 + +测试员:何刚 + ## 版本迭代 -- v0.0.1_alpha +- 0.0.1-SNAPSHOT ## 版权和许可信息 Copyright Kongzue BaseOkHttp diff --git a/baseokhttp_v3/build.gradle b/baseokhttp_v3/build.gradle index dae037a4dce14fe80a738a2f8af05394c01ffece..3793cc0dd530abe7c7a5a52e72be290d73dc7024 100644 --- a/baseokhttp_v3/build.gradle +++ b/baseokhttp_v3/build.gradle @@ -5,13 +5,11 @@ ohos { defaultConfig { compatibleSdkVersion 5 } - } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation 'org.conscrypt:conscrypt-openjdk:1.1.3' - api files('libs\\okhttp-4.9.0.jar') - api files('libs\\okio-2.10.0.jar') - api files('libs\\kotlin-stdlib-1.3.50.jar') + api 'org.conscrypt:conscrypt-openjdk:1.1.3:' + api 'com.squareup.okhttp3:okhttp:3.14.9' + api 'org.json:json:20210307' } diff --git a/baseokhttp_v3/libs/json.jar b/baseokhttp_v3/libs/json.jar deleted file mode 100644 index 2c0bf8330b7f8b33670e04687565791d27f5339a..0000000000000000000000000000000000000000 Binary files a/baseokhttp_v3/libs/json.jar and /dev/null differ diff --git a/baseokhttp_v3/libs/kotlin-stdlib-1.3.50.jar b/baseokhttp_v3/libs/kotlin-stdlib-1.3.50.jar deleted file mode 100644 index 445c65502250a3010d1e538e30a0cf7aa3a07903..0000000000000000000000000000000000000000 Binary files a/baseokhttp_v3/libs/kotlin-stdlib-1.3.50.jar and /dev/null differ diff --git a/baseokhttp_v3/libs/okhttp-4.9.0.jar b/baseokhttp_v3/libs/okhttp-4.9.0.jar deleted file mode 100644 index 9f4bb287a7e3e77b777a5473595ef2eac27f947a..0000000000000000000000000000000000000000 Binary files a/baseokhttp_v3/libs/okhttp-4.9.0.jar and /dev/null differ diff --git a/baseokhttp_v3/libs/okio-2.10.0.jar b/baseokhttp_v3/libs/okio-2.10.0.jar deleted file mode 100644 index eef1956134653506129a81c95d0450221fda33f5..0000000000000000000000000000000000000000 Binary files a/baseokhttp_v3/libs/okio-2.10.0.jar and /dev/null differ diff --git a/baseokhttp_v3/src/main/java/com/kongzue/baseokhttp/listener/BeanResponseInterceptListener.java b/baseokhttp_v3/src/main/java/com/kongzue/baseokhttp/listener/BeanResponseInterceptListener.java index 3270704c8789ad7acdf6dd42085019b1e49e6d4d..4134b55620fdf7411d15039e29de6704ed9aee93 100644 --- a/baseokhttp_v3/src/main/java/com/kongzue/baseokhttp/listener/BeanResponseInterceptListener.java +++ b/baseokhttp_v3/src/main/java/com/kongzue/baseokhttp/listener/BeanResponseInterceptListener.java @@ -34,12 +34,12 @@ public abstract class BeanResponseInterceptListener implements BaseResponseIn return onResponse(context, url, tInstance, new DecodeJsonException(response.toString())); } tInstance = JsonBean.getBean(data, tClass); - + return onResponse(context, url, tInstance, null); } else { return onResponse(context, url, tInstance, error); } } - + public abstract boolean onResponse(Context context, String url, T response, Exception error); } diff --git a/baseokhttp_v3/src/main/java/com/kongzue/baseokhttp/listener/OnDownloadListener.java b/baseokhttp_v3/src/main/java/com/kongzue/baseokhttp/listener/OnDownloadListener.java index 4b6ccf13cf7a636d9d65b1897bf80e78e3c5038c..675527604bf23b76185f759e69f216a023278845 100644 --- a/baseokhttp_v3/src/main/java/com/kongzue/baseokhttp/listener/OnDownloadListener.java +++ b/baseokhttp_v3/src/main/java/com/kongzue/baseokhttp/listener/OnDownloadListener.java @@ -10,10 +10,25 @@ import java.io.File; * CreateTime: 2019/5/19 15:33 */ public interface OnDownloadListener { - + + /** + * 下载成功 + * + * @param file + */ void onDownloadSuccess(File file); - + + /** + * 下载中 + * + * @param progress + */ void onDownloading(int progress); - + + /** + * 下载失败 + * + * @param e + */ void onDownloadFailed(Exception e); } diff --git a/baseokhttp_v3/src/main/java/com/kongzue/baseokhttp/listener/WebSocketStatusListener.java b/baseokhttp_v3/src/main/java/com/kongzue/baseokhttp/listener/WebSocketStatusListener.java index c58373d16440412e273af2205c0c0d74239f694a..0ac0e7e48facb708419cefab5d665b9fd6951b5a 100644 --- a/baseokhttp_v3/src/main/java/com/kongzue/baseokhttp/listener/WebSocketStatusListener.java +++ b/baseokhttp_v3/src/main/java/com/kongzue/baseokhttp/listener/WebSocketStatusListener.java @@ -11,17 +11,45 @@ import okio.ByteString; * CreateTime: 2018/12/31 17:10 */ public interface WebSocketStatusListener { - + + /** + * 已连接 + * + * @param response + */ void connected(Response response); - + + /** + * 收到消息 + * + * @param message + */ void onMessage(String message); - + + /** + * 收到消息 + * + * @param message + */ void onMessage(ByteString message); - + + /** + * 重新连接 + */ void onReconnect(); - + + /** + * 断开 + * + * @param breakStatus 状态 + */ void onDisconnected(int breakStatus); - + + /** + * 连接失败 + * + * @param t + */ void onConnectionFailed(Throwable t); - + } diff --git a/build.gradle b/build.gradle index 9b1ac2b57371bb74de78dfe634da0f744a240082..a1d5543eec73e49357b8fede1c60a6608255461c 100644 --- a/build.gradle +++ b/build.gradle @@ -33,6 +33,9 @@ allprojects { maven { url 'https://developer.huawei.com/repo/' } + maven { + url 'https://s01.oss.sonatype.org/content/repositories/snapshots/' + } google() jcenter() } diff --git a/entry/build.gradle b/entry/build.gradle index 1e361d4a2fc3cddab70332e054f4932cf7ecdd31..b4b20d29a4f32198de1552f10f7e3b06aeef2cc7 100644 --- a/entry/build.gradle +++ b/entry/build.gradle @@ -1,4 +1,5 @@ apply plugin: 'com.huawei.ohos.hap' + ohos { compileSdkVersion 5 defaultConfig { @@ -14,9 +15,5 @@ ohos { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar', '*.har']) testCompile 'junit:junit:4.12' - compile(name:'baseokhttp_v3_ohos', ext:'har') - compile files('libs\\okhttp-4.9.0.jar') - compile files('libs\\okio-2.10.0.jar') - compile files('libs\\kotlin-stdlib-1.3.50.jar') - compile files('libs\\json.jar') + implementation project(':baseokhttp_v3') } diff --git a/entry/libs/baseokhttp_v3_ohos.har b/entry/libs/baseokhttp_v3_ohos.har deleted file mode 100644 index c98c6f4bd67675b52000cf9bffbced3b9a21fc9f..0000000000000000000000000000000000000000 Binary files a/entry/libs/baseokhttp_v3_ohos.har and /dev/null differ diff --git a/entry/libs/json.jar b/entry/libs/json.jar deleted file mode 100644 index 2c0bf8330b7f8b33670e04687565791d27f5339a..0000000000000000000000000000000000000000 Binary files a/entry/libs/json.jar and /dev/null differ diff --git a/entry/libs/kotlin-stdlib-1.3.50.jar b/entry/libs/kotlin-stdlib-1.3.50.jar deleted file mode 100644 index 445c65502250a3010d1e538e30a0cf7aa3a07903..0000000000000000000000000000000000000000 Binary files a/entry/libs/kotlin-stdlib-1.3.50.jar and /dev/null differ diff --git a/entry/libs/okhttp-4.9.0.jar b/entry/libs/okhttp-4.9.0.jar deleted file mode 100644 index 9f4bb287a7e3e77b777a5473595ef2eac27f947a..0000000000000000000000000000000000000000 Binary files a/entry/libs/okhttp-4.9.0.jar and /dev/null differ diff --git a/entry/libs/okio-2.10.0.jar b/entry/libs/okio-2.10.0.jar deleted file mode 100644 index eef1956134653506129a81c95d0450221fda33f5..0000000000000000000000000000000000000000 Binary files a/entry/libs/okio-2.10.0.jar and /dev/null differ diff --git a/entry/src/main/java/com/kongzue/baseokhttpv3/slice/MainAbilitySlice.java b/entry/src/main/java/com/kongzue/baseokhttpv3/slice/MainAbilitySlice.java index 64872c74d73a005dbec4f4955d7300e258270727..f75218e50399ad4eaa4682a0eee3c49949db3977 100644 --- a/entry/src/main/java/com/kongzue/baseokhttpv3/slice/MainAbilitySlice.java +++ b/entry/src/main/java/com/kongzue/baseokhttpv3/slice/MainAbilitySlice.java @@ -15,7 +15,6 @@ import com.kongzue.baseokhttpv3.ResourceTable; import ohos.aafwk.ability.AbilitySlice; import ohos.aafwk.content.Intent; import ohos.agp.components.*; -import ohos.agp.render.Paint; import ohos.agp.utils.Point; import ohos.agp.window.service.Display; import ohos.agp.window.service.DisplayManager; @@ -31,7 +30,6 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import java.util.ArrayList; -import java.util.Base64; import java.util.List; import java.util.Optional; @@ -270,7 +268,6 @@ public class MainAbilitySlice extends AbilitySlice @Override public void onDownloadSuccess(File file) { - HiLog.info(Logger.LABEL, "下载成功" + file.getAbsolutePath()); MyToast.show(context, "文件已下载完成", MyToast.ToastLayout.BOTTOM); } @@ -495,24 +492,6 @@ public class MainAbilitySlice extends AbilitySlice (int)(current / (total * 1.0f) * 100)); } }).doPost(); - - // HttpRequest.POST(context, "https://api.yesapi.cn/?s=App.CDN.UploadImg", new - // Parameter() - // .add("return_data", "0") - // .add("app_key", "DC43EBA4682FE70A316898472E5A0D2F") - // .add("sign", "7BDB268AEED6EF49B0B027B8CCDE5EC8").add("file", - // fileList) - // , new ResponseListener() { - // @Override - // public void onResponse(String response, Exception error) { - // - // if (error == null) { - // HiLog.info(Logger.LABEL, "成功"); - // } else { - // HiLog.info(Logger.LABEL, "失败"+error.getMessage()); - // } - // } - // }); } catch (IOException e) {