# CommonFramework **Repository Path**: jerry_ee/commonFramework ## Basic Information - **Project Name**: CommonFramework - **Description**: mvvm、Rxjava、okhttp、retrofit为一起网络框架 - **Primary Language**: Android - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2022-08-10 - **Last Updated**: 2023-07-25 ## Categories & Tags **Categories**: Uncategorized **Tags**: Android ## README # CommonFramework #### 介绍 mvvm、Rxjava、okhttp、retrofit为一起网络框架 #### 软件架构 软件架构说明 #### 接入引导 ##### 最新版本:[![](https://jitpack.io/v/com.gitee.jerry_ee/commonFramework.svg)](https://jitpack.io/#com.gitee.jerry_ee/commonFramework) ### 依赖配置 #### 在项目根目录下的`build.gradle`中 ```groovy allprojects { repositories { maven { url 'https://www.jitpack.io' } } } ``` #### 在`build.gradle`文件中声明dataBinding、viewBinding ##### 3.6之前的版本如下定义 ```groovy android { /*支持dataBinding*/ dateBinding { enabled = true } /*支持viewBinding*/ viewBinding { enabled = true } } ``` ##### 4.0以上的版本如下定义 ```groovy android { buildFeatures { /*支持dataBinding*/ dataBinding = true /*支持viewBinding*/ viewBinding = true } } ``` #### 在项目模块下的`build.gradle`中(以下依赖项不必全部引入,请按需来) ##### 基础View库(mvvm 框架 支持dataBinding和viewBinding) ```groovy dependencies { implementation 'com.gitee.jerry_ee.commonFramework:common-baseview:1.1.18' } ``` ##### 网络框架(Okhttp+Retrofit2+RxJava3组成) ```groovy dependencies { implementation 'com.gitee.jerry_ee.commonFramework:opensource-retrofit:1.1.18' } ``` #### 使用说明 ##### 公共基础Activity、Fragment、Dialog等类 ![公共基础类](img/%E5%9F%BA%E7%A1%80%E7%B1%BB.png) ##### 使用dataBinding基础Activity、Fragment、Dialog等类 ![使用dataBinding基础](img/%E4%BD%BF%E7%94%A8dataBinding%E5%9F%BA%E7%A1%80%E7%B1%BB.png) ##### 使用viewBinding基础Activity、Fragment、Dialog等类 ![使用viewBinding基础](img/viewBinding%E5%9F%BA%E7%A1%80%E7%B1%BB.png) ##### 使用viewModel基础Activity、Fragment、Dialog等类 ![使用viewModel基础](img/viewModel%E5%9F%BA%E7%A1%80%E7%B1%BB.png) ##### 初始化信息 ```groovy public class MyApplication extends BaseApplication { @Override public void onCreate() { super.onCreate(); /*初始化请求配置*/ GlobalRetrofitInitialization.getInstance(this) .create("基础Url", "接口类(枚举)", BuildConfig.DEBUG, R.string.app_name) /*配置更换基础URl*/ .configureReplaceBaseUrl(() -> "新Url") /*配置加载框*/ .configureLoadingBox(new ILoadingBoxListener() { @Override public void onShowLoading(String message) { if (!RecyclerUtils.isNotEmptyRefreshLayout()) { UiLoadingChange.showLoad().postValue((TextUtils.isEmpty(message) ? "" : message)); } } @Override public void onDismissLoad() { if (RecyclerUtils.isNotEmptyRefreshLayout()) { RecyclerUtils.finishRefresh(); } else { UiLoadingChange.dismissLoad().postValue(false); } } }) /*配置超时时间*/ .configureTimeout(60) /*配置公共参数*/ .configurePublicParam(() -> { Map map = new HashMap<>(); return map; }) /*配置加密方式*/ .configureParamEncryption(new IParamEncryption() { @Override public String onEncryptionKey() { return "加密串key值(例如:data)"; } @Override public String onEncryptionParam(String param) { return AESUtil.encryptByNoPadding(param); } }) /*解密响应数据*/ .configureParamDecrypt(encryptionParam -> { return 解密方法(encryptionParam); }); /*初始化土司*/ ToastExt.getInstance().init(this, Gravity.CENTER, null); } } ``` ##### 请求接口定义(支持DOGET、DOPPOAST、DODELETE、DOPUT等请求) ###### 接口使用方式 ```groovy public enum HttpConstant { /** * 测试 */ @DOPOST(urlName = "接口名称", urlAddress = "接口路径", requestDataFormat = 请求方式) test(), } ``` ###### 接口为.do使用方式 ```groovy public enum HttpConstant { /** * 测试 */ @DOPOST(urlName = "接口名称", urlAddress = "接口路径.do", requestDataFormat = 请求方式) test("接口名"), /** * 接口名 */ private String testName; HttpConstant(String flag) { this.flag = flag; } public String getTestName() { return testName; } } ``` ##### ViewModel使用方式 ```groovy public class TestViewModel extends BaseViewModelProxy { public void test() { Map map = new HashMap<>(); viewModel.executeResponse(executor.executor(HttpConstant.LOGIN, map, new TypeToken>() { }.getType()), (Consumer>) it -> { ToastExt.getInstance().showToast(it.getResponseMessage()); }, throwable -> ToastExt.getInstance().showToast(Objects.requireNonNull(throwable.getMessage()))); } /** * 文件上传 * * @param file 文件信息 */ public void fileUpload(Map file) { Map map = new HashMap<>(); viewModel.executeResponse(executor.executor(HttpConstant.FILE_UPLOAD, map, file, new TypeToken>() { }.getType()), (Consumer>) it -> { ToastExt.getInstance().showToast(it.getResponseMessage()); }, throwable -> ToastExt.getInstance().showToast(Objects.requireNonNull(throwable.getMessage()))); } /** * 文件上传 * * @param files 文件信息 */ public void fileUploads(Map> files) { Map map = new HashMap<>(); viewModel.executeResponse(executor.executors(HttpConstant.FILE_UPLOAD, map, files, new TypeToken>() { }.getType()), (Consumer>) it -> { ToastExt.getInstance().showToast(it.getResponseMessage()); }, throwable -> ToastExt.getInstance().showToast(Objects.requireNonNull(throwable.getMessage()))); } /** * 文件上传 * * @param file 文件信息 */ public void fileUpload(File file) { viewModel.executeResponse(executor.executor(HttpConstant.UPLOAD_IMAGE, file, new TypeToken>() { }.getType()), (Consumer>) it -> { ToastExt.getInstance().showToast(it.getResponseMessage()); }, throwable -> ToastExt.getInstance().showToast(Objects.requireNonNull(throwable.getMessage()))); } } ``` #### 参与贡献 1. Fork 本仓库 2. 新建 Feat_xxx 分支 3. 提交代码 4. 新建 Pull Request #### 特技 1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md 2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com) 3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目 4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目 5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) 6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)