Skip to content

Commit

Permalink
更新第三方库
Browse files Browse the repository at this point in the history
  • Loading branch information
br3ant committed Jun 9, 2021
1 parent 3b19186 commit ddf7990
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 16 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.4.31"
ext.kotlin_version = "1.5.10"
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.1"
classpath "com.android.tools.build:gradle:4.2.1"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong
Expand Down
6 changes: 3 additions & 3 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue Oct 13 16:43:45 CST 2020
#Wed Jun 09 17:42:16 CST 2021
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
22 changes: 11 additions & 11 deletions utils/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,31 +49,31 @@ android {
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])

api 'androidx.appcompat:appcompat:1.2.0'
api 'androidx.appcompat:appcompat:1.3.0'
api 'androidx.constraintlayout:constraintlayout:2.0.4'

//fragmentation
api 'com.github.br3ant:SFragmentation:1.7.7'
api 'com.github.weikaiyun.SFragmentation:fragmentation:1.8.2'

//kotlin
api "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
api "androidx.core:core-ktx:1.3.2"
api "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
api "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0"
api "androidx.lifecycle:lifecycle-livedata-ktx:2.2.0"
api "androidx.lifecycle:lifecycle-reactivestreams-ktx:2.2.0"
api 'androidx.fragment:fragment-ktx:1.2.5'
api "androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1"
api "androidx.lifecycle:lifecycle-livedata-ktx:2.3.1"
api "androidx.lifecycle:lifecycle-reactivestreams-ktx:2.3.1"
api 'androidx.fragment:fragment-ktx:1.3.3'

//room
def room_version = '2.2.6'
def room_version = '2.3.0'
api "androidx.room:room-runtime:$room_version"
api "androidx.room:room-rxjava2:$room_version"
api "androidx.room:room-ktx:$room_version"
kapt "androidx.room:room-compiler:$room_version"

//rxhttp
api 'com.ljx.rxhttp:rxhttp:2.5.6'
kapt 'com.ljx.rxhttp:rxhttp-compiler:2.5.6' //生成RxHttp类,非kotlin项目,请使用annotationProcessor代替kapt
api 'com.ljx.rxhttp:rxhttp:2.5.7'
kapt 'com.ljx.rxhttp:rxhttp-compiler:2.5.7' //生成RxHttp类,非kotlin项目,请使用annotationProcessor代替kapt
api 'com.ljx.rxlife:rxlife-coroutine:2.0.1' //管理协程生命周期,页面销毁,关闭请求
api 'com.ljx.rxlife2:rxlife-rxjava:2.0.0'

Expand All @@ -84,7 +84,7 @@ dependencies {
//okhttp
api 'com.squareup.okhttp3:okhttp:4.9.1'

api 'com.github.liangjingkanji:BRV:1.3.13'
api 'com.github.liangjingkanji:BRV:1.3.22'

//gson
api 'com.google.code.gson:gson:2.8.6'
Expand All @@ -98,7 +98,7 @@ dependencies {
api 'com.github.lihangleo2:ShadowLayout:3.1.3'

//binding
api 'com.hi-dhl:binding:1.0.9'
api 'com.hi-dhl:binding:1.1.3'

//util
api 'com.blankj:utilcodex:1.29.0'
Expand Down
2 changes: 2 additions & 0 deletions utils/src/main/java/com/br3ant/utils/rxhttp/RxHttpUtils.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.br3ant.utils.rxhttp;

import com.br3ant.utils.GsonUtil;
import com.br3ant.utils.rxhttp.interceptor.LogInterceptor;

import java.util.concurrent.TimeUnit;

Expand All @@ -22,6 +23,7 @@ public class RxHttpUtils {
public static void init() {

RxHttp.init(new OkHttpClient.Builder()
.addInterceptor(new LogInterceptor())
.readTimeout(20000, TimeUnit.MILLISECONDS)
.writeTimeout(20000, TimeUnit.MILLISECONDS)
.connectTimeout(20000, TimeUnit.MILLISECONDS).build());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package com.br3ant.utils.rxhttp.interceptor

import com.blankj.utilcode.util.LogUtils
import okhttp3.Interceptor
import okhttp3.Request
import okhttp3.Response
import okio.Buffer
import java.io.EOFException
import java.io.IOException
import java.nio.charset.StandardCharsets


class LogInterceptor : Interceptor {

@Throws(IOException::class)
override fun intercept(chain: Interceptor.Chain): Response {
val request: Request = chain.request()
logForRequest(request)
val response: Response = chain.proceed(request)
logForResponse(response)
return response
}


private fun logForRequest(request: Request) {
try {
val requestBody = request.body
if (requestBody != null) {
val buffer = Buffer()
requestBody.writeTo(buffer)
val charset = requestBody.contentType()?.charset(UTF8)
val body = buffer.readString(charset ?: UTF8)
LogUtils.iTag(TAG, "method = ${request.method} -- url = ${request.url}?${body}")
} else {
LogUtils.iTag(TAG, "method = ${request.method} -- url = ${request.url}")
}
} catch (e: Exception) {
e.printStackTrace()
}
}

private fun logForResponse(response: Response?) {
val body = response?.body ?: return
try {
val source = body.source()
source.request(Long.MAX_VALUE)
val buffer = source.buffer
if (!isPlaintext(buffer)) {
return
}
if (body.contentLength() != 0L) {
val string = buffer.clone().readString(body.contentType()?.charset(UTF8) ?: UTF8)
LogUtils.iTag(TAG, "response = $string")
}
} catch (e: Exception) {
e.printStackTrace()
}
}

private fun isPlaintext(buffer: Buffer): Boolean {
return try {
val prefix = Buffer()
val byteCount = if (buffer.size < 64) buffer.size else 64
buffer.copyTo(prefix, 0, byteCount)
for (i in 0..15) {
if (prefix.exhausted()) {
break
}
val codePoint = prefix.readUtf8CodePoint()
if (Character.isISOControl(codePoint) && !Character.isWhitespace(codePoint)) {
return false
}
}
true
} catch (e: EOFException) {
false
}
}


companion object {
private val UTF8 = StandardCharsets.UTF_8
private const val TAG = "OkHttp"
}
}

0 comments on commit ddf7990

Please sign in to comment.