liyiheng/EasyVolley


对Volley的二次封装

Download


Step 1. Add the JitPack repository to your build file

Add it in your root settings.gradle at the end of repositories:

	dependencyResolutionManagement {
		repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
		repositories {
			mavenCentral()
			maven { url 'https://jitpack.io' }
		}
	}

Add it in your settings.gradle.kts at the end of repositories:

	dependencyResolutionManagement {
		repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
		repositories {
			mavenCentral()
			maven { url = uri("https://jitpack.io") }
		}
	}

Add to pom.xml

	<repositories>
		<repository>
		    <id>jitpack.io</id>
		    <url>https://jitpack.io</url>
		</repository>
	</repositories>

Add it in your build.sbt at the end of resolvers:

 
    resolvers += "jitpack" at "https://jitpack.io"
        
    

Add it in your project.clj at the end of repositories:

 
    :repositories [["jitpack" "https://jitpack.io"]]
        
    

Step 2. Add the dependency

	dependencies {
		implementation 'com.github.XanthusL:EasyVolley:-SNAPSHOT'
	}
	dependencies {
		implementation("com.github.XanthusL:EasyVolley:-SNAPSHOT")
	}
	<dependency>
	    <groupId>com.github.XanthusL</groupId>
	    <artifactId>EasyVolley</artifactId>
	    <version>-SNAPSHOT</version>
	</dependency>

                            
    libraryDependencies += "com.github.XanthusL" % "EasyVolley" % "-SNAPSHOT"
        
        

                            
    :dependencies [[com.github.XanthusL/EasyVolley "-SNAPSHOT"]]
        
        

Readme


EasyVolley

对Volley进行简单的封装,方便使用

retrofit + RxJava 的封装见ApkBus

usage

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

  dependencies {
      ...
      compile 'com.github.XanthusL:EasyVolley:0.1'
  }

1.初始化,建议在Application中进行初始化操作

  EasyVolley.init(this);

2.简单使用

        // GET请求-----------------------------------------------------
        EasyVolley.stringGet("this param is URL", new EasyCallBack() {
            //请求成功的回调(http状态码200)
            @Override
            protected void onResponse(String response) {

            }

            //错误回调
            @Override
            protected void onErrorResponse(VolleyError error) {
                  // 由于异常导致此错误回调时,error.networkResponse为null
                  // 因此使用error.networkResponse时建议对其进行非空判断,避免NP
                  
                  //error.networkResponse.statCode为http状态码
                  //error.networkResponse.data为数据内容
            }
        });
        
        // POST请求-----------------------------------------------------
        EasyVolley.stringPost("url", new HashMap<String, String>(), new EasyCallBack() {
            @Override
            protected void onResponse(String response) {

            }

            @Override
            protected void onErrorResponse(VolleyError error) {

            }
        });
        
        // POST请求,有同名参数时-----------------------------------------
        EasyVolley.stringPost("url", new EasyCallBack() {
            @Override
            protected void onResponse(String response) {

            }

            @Override
            protected void onErrorResponse(VolleyError error) {

            }
        }, "?param=abc&param=456");

3.对请求错误的情况进行统一判断和处理

  可在EasyCallBack.java中对错误情况进行判断和处理,就不必使用时在各个逻辑的错误回调中单独判断;
  EasyCallBack的onErrorResponse()方法也可以改为非抽象方法,这样就可以仅在需要的时候重写该方法.
  详见EasyCallBack.java中的注释

4.设置请求头.如添加授权信息等

      HashMap<String,String> map = new HashMap();
      map.put("test1","hahahaha");
      EasyVolley.setHeaders(map);

###just notes

https://www.codingame.com/home

https://coderbyte.com/challenges

http://gocode.io/

https://leetcode.com/