Git Product home page Git Product logo

retrohttp's Introduction

RetroHttp简介

概述

RetroHttp 是一个基于 RetrofitHttp 进行封装使用的http库,目的是使通讯变得更加简洁。

依赖

在你 project 对应的 build.gradle 中添加以下代码:

	allprojects {
		repositories {
			...
			maven { url 'https://jitpack.io' }
		}
	}

在你需要引用的 module对应的build.gradle中(此处以app_module的build.gradle中引用 0.0.1版本为例)添加版本依赖:

	dependencies {
	        implementation 'com.github.ShaoqiangPei:RetroHttp:0.0.1'
	}

使用说明

一. RetroHttp架构

RetroHttp架构说明请参考 RetroHttp架构说明

二. RetroHttp使用

2.1 依赖

如上,在你的项目中添加 RetroHttp 库依赖

2.2 RetroHttp 库初始化

你需要在你项目的自定义的Application中对RetroHttp 库做初始化操作,类似下面这样:

/**
 * Description:自定义Application
 * 
 * Author:pei
 * Date: 2019/8/28
 */
public class AppContext extends Application {

    @Override
    public void onCreate() {
        super.onCreate();

        //初始化 RetroHttp
        RetroConfig.getInstance().init(this)
                                 //是否开启网络log打印
                                 .setHttpLog(AppConfig.getInstance().isHttpLog());

    }
}

:AppConfig为整个项目设置的一个配置类,具体介绍可参考BaseRetrofitor使用说明中的第七项:整个app的配置类 —— AppConfig

2.3 拷贝 httpApp 包到自己的项目中

将 RetroHttp库 中的 httpApp包 整个拷贝到自己的项目中(httpApp包下为模板类),然后按需修改每个类,以符合实际开发通讯需求。具体处理,请参考 RetroHttp架构说明 中的 “httpApp包” 讲解部分。
这里需要注意的是:将httpApp拷贝到你项目之后,你需要将AppConfig移到你项目结构的最外层作为整个app的配置管理类。

三. 通讯接入流程

具体参考通讯接入流程说明

四. Apk下载与安装(更新应用)

apk的下载与更新,主要涉及到 download文件夹,外部调用的话,只涉及到其中的 DownLoadHelper 类。
下载更新apk的方法,可参考Apk文件下载与安装

五. Http/Https 通讯的兼容

Android9.0以后通讯不支持 http 方式,建议使用 https 方式通讯。RetroHttp支持 http通讯兼容,如果你项目中要使用http通讯的话, 你可以在你项目的清单文件 manifast.xml中添加 retrohttp_config.xml文件的声明(注:retrohttp_config.xml文件包含在retrohttp库中)
在你 manifast.xml 的 application 标签下,添加如下声明:

<application
        //其他代码省略
	//......
        android:networkSecurityConfig="@xml/retrohttp_config"
        
	>
	
	//其他代码省略
	//......

</application>
	

六. 查看通讯log

在RetroHttp初始化时通过配置类 AppConfig 中的变量:

        //是否打印httpLog
         RetroConfig.getInstance().setHttpLog(AppConfig.getInstance().isHttpLog());

来控制是否显示通讯log,过滤 log 的 tag=http,log等级为 w
具体可参考BaseRetrofitor使用说明中关于Log打印的介绍。

七. 其他问题

  1. Url不规范
  2. 通讯返回结果为非json格式的解析
  3. Kotlin版网络通讯如何写?
  4. 如何发起串联请求?
  5. 如何实现并发请求

retrohttp's People

Contributors

shaoqiangpei avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.