Skip to content

Commit

Permalink
feat: 优化代码,升级OKHttp至4.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
BzCoder committed Jan 29, 2022
1 parent 1adbb42 commit 340af2d
Show file tree
Hide file tree
Showing 15 changed files with 29 additions and 53 deletions.
12 changes: 0 additions & 12 deletions .idea/runConfigurations.xml

This file was deleted.

6 changes: 3 additions & 3 deletions LibEasyGlide/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ plugins {
id 'kotlin-kapt'
}
android {
compileSdkVersion 30
compileSdkVersion 31


defaultConfig {
minSdkVersion 18
targetSdkVersion 30
targetSdkVersion 31

testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'

Expand Down Expand Up @@ -56,6 +56,6 @@ dependencies {

implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
implementation 'io.reactivex.rxjava2:rxjava:2.2.6'
implementation 'com.squareup.okhttp3:okhttp:3.11.0'
implementation 'com.squareup.okhttp3:okhttp:4.7.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.5.31"
}
4 changes: 2 additions & 2 deletions LibEasyGlide/src/main/java/me/bzcoder/easyglide/EasyGlide.kt
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,8 @@ object EasyGlide {
* 取消图片加载
*/
@JvmStatic
fun clearImage(context: Context, imageView: ImageView?) {
EasyGlideApp.get(context).requestManagerRetriever[context].clear(imageView!!)
fun clearImage(context: Context, imageView: ImageView) {
EasyGlideApp.get(context).requestManagerRetriever[context].clear(imageView)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ class GlideConfigImpl private constructor(builder: Builder) : ImageConfig() {
return this
}

fun placeholderDrawble(placeholderDrawble: Drawable?): Builder {
placeholderDrawable = placeholderDrawble
fun placeholderDrawable(placeholderDrawable: Drawable?): Builder {
this.placeholderDrawable = placeholderDrawable
return this
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ class OkHttpStreamFetcher // Public API.
}

override fun onResponse(call: Call, response: Response) {
responseBody = response.body()
responseBody = response.body
if (response.isSuccessful) {
val contentLength = Preconditions.checkNotNull(responseBody).contentLength()
stream = ContentLengthInputStream.obtain(responseBody!!.byteStream(), contentLength)
callback?.onDataReady(stream)
} else {
callback?.onLoadFailed(HttpException(response.message(), response.code()))
callback?.onLoadFailed(HttpException(response.message, response.code))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ class OkHttpUrlLoader // Public API.
return true
}

override fun buildLoadData(model: GlideUrl, width: Int, height: Int,
options: Options): LoadData<InputStream>? {
override fun buildLoadData(model: GlideUrl, width: Int, height: Int, options: Options): LoadData<InputStream> {
return LoadData(model, OkHttpStreamFetcher(client, model))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import android.widget.ProgressBar
import me.bzcoder.easyglide.R
import me.bzcoder.easyglide.util.Utils.dp2px
import me.bzcoder.easyglide.util.Utils.sp2px
import kotlin.math.acos

class CircleProgressView @JvmOverloads constructor(
context: Context?,
Expand Down Expand Up @@ -251,8 +252,7 @@ class CircleProgressView @JvmOverloads constructor(
canvas.save()
canvas.translate(mRealWidth / 2.toFloat(), mRealHeight / 2.toFloat())
val progressY = progress * 1.0f / max * (mRadius * 2)
val angle =
(Math.acos((mRadius - progressY) / mRadius.toDouble()) * 180 / Math.PI).toFloat()
val angle = (acos((mRadius - progressY) / mRadius.toDouble()) * 180 / Math.PI).toFloat()
val startAngle = 90 + angle
val sweepAngle = 360 - angle * 2
// 绘制未到达区域
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ object ProgressManager {
val request = chain.request()
val response = chain.proceed(request)
response.newBuilder().run {
val body = response.body()
val body = response.body
if (body != null) {
this.body(ProgressResponseBody(request.url().toString(), LISTENER, body))
this.body(ProgressResponseBody(request.url.toString(), LISTENER, body))
}
this.build()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ProgressResponseBody internal constructor(private val url: String, private

override fun source(): BufferedSource {
if (bufferedSource == null) {
bufferedSource = Okio.buffer(source(responseBody.source()))
bufferedSource = source(responseBody.source()).buffer()
}
return bufferedSource!!
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import java.security.MessageDigest
class BlurTransformation @JvmOverloads constructor(private val context: Context, radius: Int = MAX_RADIUS, sampling: Int = DEFAULT_SAMPLING) : BitmapTransformation() {
private val ID = javaClass.name
private val radius //模糊半径0~25
: Int
: Int = if (radius > MAX_RADIUS) MAX_RADIUS else radius
private val sampling //取样0~25
: Int
: Int = if (sampling > MAX_RADIUS) MAX_RADIUS else sampling

@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
override fun transform(pool: BitmapPool, toTransform: Bitmap, outWidth: Int, outHeight: Int): Bitmap {
Expand All @@ -35,18 +35,13 @@ class BlurTransformation @JvmOverloads constructor(private val context: Context,
val paint = Paint()
paint.flags = Paint.FILTER_BITMAP_FLAG
canvas.drawBitmap(toTransform, 0f, 0f, paint)
bitmap = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
BlurUtils.rsBlur(context, bitmap, radius)
} else {
BlurUtils.blur(bitmap, radius)!!
}
bitmap = BlurUtils.rsBlur(context, bitmap, radius)
return bitmap
}

override fun equals(obj: Any?): Boolean {
if (obj is BlurTransformation) {
val other = obj
return radius == other.radius && sampling == other.sampling
return radius == obj.radius && sampling == obj.sampling
}
return false
}
Expand All @@ -64,8 +59,4 @@ class BlurTransformation @JvmOverloads constructor(private val context: Context,
private const val DEFAULT_SAMPLING = 1
}

init {
this.radius = if (radius > MAX_RADIUS) MAX_RADIUS else radius
this.sampling = if (sampling > MAX_RADIUS) MAX_RADIUS else sampling
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ class BorderTransformation(borderWidth: Int, @ColorInt borderColor: Int) : Bitma

//描绘边框
paint.isAntiAlias = true
if (mBorderPaint != null) {
canvas.drawRect(0 + mBorderWidth / 2, 0 + mBorderWidth / 2, width - mBorderWidth / 2, height - mBorderWidth / 2, mBorderPaint)
}
canvas.drawRect(0 + mBorderWidth / 2, 0 + mBorderWidth / 2, width - mBorderWidth / 2, height - mBorderWidth / 2, mBorderPaint)
return bitmap
}

Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ EasyGlide是一款基于Glide4.12.0的工具封装类,功能不复杂,主要
- 加载完毕后PlaceHolder不会自动隐藏 [Glide #3195](https://github.com/bumptech/glide/issues/3195)

## 改动
- Not Publish
- 2.0.1
- 升级至Androidx
- 升级Gradle至7.0
- 升级Gradle至7.0+
- 升级Glide至4.12.0
- 优化代码逻辑
- 升级OKHttp至4.7.0
- 优化代码风格&逻辑
- 2.0.0
- 改为Kotlin扩展函数
- 1.0.8
Expand Down
7 changes: 3 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@ android {
}


lintOptions {
abortOnError false
}

viewBinding {
enabled = true
}
lint {
abortOnError false
}

}

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.4'
classpath 'com.android.tools.build:gradle:7.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip

0 comments on commit 340af2d

Please sign in to comment.