diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml deleted file mode 100644 index 7f68460..0000000 --- a/.idea/runConfigurations.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/LibEasyGlide/build.gradle b/LibEasyGlide/build.gradle index c29040b..13976a8 100644 --- a/LibEasyGlide/build.gradle +++ b/LibEasyGlide/build.gradle @@ -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' @@ -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" } diff --git a/LibEasyGlide/src/main/java/me/bzcoder/easyglide/EasyGlide.kt b/LibEasyGlide/src/main/java/me/bzcoder/easyglide/EasyGlide.kt index 6e20c5e..fc91566 100644 --- a/LibEasyGlide/src/main/java/me/bzcoder/easyglide/EasyGlide.kt +++ b/LibEasyGlide/src/main/java/me/bzcoder/easyglide/EasyGlide.kt @@ -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) } /** diff --git a/LibEasyGlide/src/main/java/me/bzcoder/easyglide/config/GlideConfigImpl.kt b/LibEasyGlide/src/main/java/me/bzcoder/easyglide/config/GlideConfigImpl.kt index 04baf54..bfd3aab 100644 --- a/LibEasyGlide/src/main/java/me/bzcoder/easyglide/config/GlideConfigImpl.kt +++ b/LibEasyGlide/src/main/java/me/bzcoder/easyglide/config/GlideConfigImpl.kt @@ -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 } diff --git a/LibEasyGlide/src/main/java/me/bzcoder/easyglide/http/OkHttpStreamFetcher.kt b/LibEasyGlide/src/main/java/me/bzcoder/easyglide/http/OkHttpStreamFetcher.kt index 7ef9dc8..b91f004 100644 --- a/LibEasyGlide/src/main/java/me/bzcoder/easyglide/http/OkHttpStreamFetcher.kt +++ b/LibEasyGlide/src/main/java/me/bzcoder/easyglide/http/OkHttpStreamFetcher.kt @@ -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)) } } diff --git a/LibEasyGlide/src/main/java/me/bzcoder/easyglide/http/OkHttpUrlLoader.kt b/LibEasyGlide/src/main/java/me/bzcoder/easyglide/http/OkHttpUrlLoader.kt index cda2c43..1e27a47 100644 --- a/LibEasyGlide/src/main/java/me/bzcoder/easyglide/http/OkHttpUrlLoader.kt +++ b/LibEasyGlide/src/main/java/me/bzcoder/easyglide/http/OkHttpUrlLoader.kt @@ -19,8 +19,7 @@ class OkHttpUrlLoader // Public API. return true } - override fun buildLoadData(model: GlideUrl, width: Int, height: Int, - options: Options): LoadData? { + override fun buildLoadData(model: GlideUrl, width: Int, height: Int, options: Options): LoadData { return LoadData(model, OkHttpStreamFetcher(client, model)) } diff --git a/LibEasyGlide/src/main/java/me/bzcoder/easyglide/progress/CircleProgressView.kt b/LibEasyGlide/src/main/java/me/bzcoder/easyglide/progress/CircleProgressView.kt index e150693..754e824 100644 --- a/LibEasyGlide/src/main/java/me/bzcoder/easyglide/progress/CircleProgressView.kt +++ b/LibEasyGlide/src/main/java/me/bzcoder/easyglide/progress/CircleProgressView.kt @@ -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?, @@ -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 // 绘制未到达区域 diff --git a/LibEasyGlide/src/main/java/me/bzcoder/easyglide/progress/ProgressManager.kt b/LibEasyGlide/src/main/java/me/bzcoder/easyglide/progress/ProgressManager.kt index af7d744..49f976d 100644 --- a/LibEasyGlide/src/main/java/me/bzcoder/easyglide/progress/ProgressManager.kt +++ b/LibEasyGlide/src/main/java/me/bzcoder/easyglide/progress/ProgressManager.kt @@ -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() } diff --git a/LibEasyGlide/src/main/java/me/bzcoder/easyglide/progress/ProgressResponseBody.kt b/LibEasyGlide/src/main/java/me/bzcoder/easyglide/progress/ProgressResponseBody.kt index be75eaf..23eca26 100644 --- a/LibEasyGlide/src/main/java/me/bzcoder/easyglide/progress/ProgressResponseBody.kt +++ b/LibEasyGlide/src/main/java/me/bzcoder/easyglide/progress/ProgressResponseBody.kt @@ -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!! } diff --git a/LibEasyGlide/src/main/java/me/bzcoder/easyglide/transformation/BlurTransformation.kt b/LibEasyGlide/src/main/java/me/bzcoder/easyglide/transformation/BlurTransformation.kt index e0492f5..dd91988 100644 --- a/LibEasyGlide/src/main/java/me/bzcoder/easyglide/transformation/BlurTransformation.kt +++ b/LibEasyGlide/src/main/java/me/bzcoder/easyglide/transformation/BlurTransformation.kt @@ -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 { @@ -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 } @@ -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 - } } \ No newline at end of file diff --git a/LibEasyGlide/src/main/java/me/bzcoder/easyglide/transformation/BorderTransformation.kt b/LibEasyGlide/src/main/java/me/bzcoder/easyglide/transformation/BorderTransformation.kt index c5b8095..7d072a3 100644 --- a/LibEasyGlide/src/main/java/me/bzcoder/easyglide/transformation/BorderTransformation.kt +++ b/LibEasyGlide/src/main/java/me/bzcoder/easyglide/transformation/BorderTransformation.kt @@ -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 } diff --git a/README.md b/README.md index eda21f1..83136bb 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/app/build.gradle b/app/build.gradle index a754dd0..fbb07c0 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -22,13 +22,12 @@ android { } - lintOptions { - abortOnError false - } - viewBinding { enabled = true } + lint { + abortOnError false + } } diff --git a/build.gradle b/build.gradle index 3bfe831..1d2af3f 100644 --- a/build.gradle +++ b/build.gradle @@ -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 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 65e5abd..0544d55 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -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