Skip to content

Commit

Permalink
feat: 优化代码
Browse files Browse the repository at this point in the history
  • Loading branch information
BzCoder committed Jan 18, 2022
1 parent feb36a5 commit 1adbb42
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
19 changes: 16 additions & 3 deletions LibEasyGlide/src/main/java/me/bzcoder/easyglide/EasyGlide.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ object EasyGlide {
*
* @param context
* @param drawableId
* @param imageView
*/

@JvmStatic
fun ImageView.loadImage(context: Context, @RawRes @DrawableRes drawableId: Int) {
loadImage(context, GlideConfigImpl
.builder()
Expand All @@ -59,6 +60,7 @@ object EasyGlide {
.build())
}

@JvmStatic
@JvmOverloads
fun ImageView.loadImage(context: Context, url: String?, @DrawableRes placeHolder: Int = placeHolderImageView, onProgressListener: OnProgressListener? = null, requestListener: RequestListener<Drawable?>? = null) {
loadImage(context,
Expand All @@ -78,11 +80,10 @@ object EasyGlide {
/**
* 加载本地图片
* @param context
* @param drawableId
* @param resizeX
* @param resizeY
* @param imageView
*/
@JvmStatic
@JvmOverloads
fun ImageView.loadResizeXYImage(context: Context, url: String?, resizeX: Int, resizeY: Int, @DrawableRes placeHolder: Int = placeHolderImageView) {
loadImage(context,
Expand All @@ -98,6 +99,7 @@ object EasyGlide {
.build())
}

@JvmStatic
@JvmOverloads
fun ImageView.loadCircleImage(context: Context, url: String?, @DrawableRes placeHolder: Int = circlePlaceholderImageView) {
loadImage(context,
Expand All @@ -112,6 +114,7 @@ object EasyGlide {
.build())
}

@JvmStatic
@JvmOverloads
fun ImageView.loadGrayImage(context: Context, url: String?, @DrawableRes placeHolder: Int = placeHolderImageView) {
loadImage(context,
Expand All @@ -126,6 +129,7 @@ object EasyGlide {
.build())
}

@JvmStatic
@JvmOverloads
fun ImageView.loadBlurImage(context: Context, url: String?, radius: Int = 10, @DrawableRes placeHolder: Int = placeHolderImageView) {
loadImage(context,
Expand All @@ -140,6 +144,7 @@ object EasyGlide {
.build())
}

@JvmStatic
@JvmOverloads
fun ImageView.loadRoundCornerImage(context: Context, url: String?, radius: Int = 40, margin: Int = 0, @DrawableRes placeHolder: Int = placeHolderImageView) {
loadImage(context,
Expand All @@ -154,6 +159,7 @@ object EasyGlide {
.build())
}

@JvmStatic
@JvmOverloads
fun ImageView.loadCircleWithBorderImage(context: Context, url: String?, borderWidth: Int = 2, @ColorInt borderColor: Int = 0xACACAC, @DrawableRes placeHolder: Int = placeHolderImageView) {
loadImage(context,
Expand All @@ -168,6 +174,7 @@ object EasyGlide {
.build())
}

@JvmStatic
@JvmOverloads
fun ImageView.loadBorderImage(context: Context, url: String?, borderWidth: Int = 2, @ColorInt borderColor: Int = 0xACACAC, @DrawableRes placeHolder: Int = placeHolderImageView) {
loadImage(context,
Expand All @@ -190,6 +197,7 @@ object EasyGlide {
* CircleCrop
* CenterCrop
*/
@JvmStatic
fun ImageView.loadImageWithTransformation(context: Context, url: String?, vararg bitmapTransformations: BitmapTransformation, @DrawableRes placeHolder: Int = placeHolderImageView) {
loadImage(context,
GlideConfigImpl
Expand All @@ -210,10 +218,12 @@ object EasyGlide {
* @param context
* @param url
*/
@JvmStatic
fun preloadImage(context: Context, url: String?) {
Glide.with(context).load(url).preload()
}

@SuppressLint("CheckResult")
fun loadImage(context: Context, config: GlideConfigImpl) {
Preconditions.checkNotNull(context, "Context is required")
Preconditions.checkNotNull(config, "ImageConfigImpl is required")
Expand Down Expand Up @@ -307,6 +317,7 @@ object EasyGlide {
* 清除内存缓存
*/
@SuppressLint("CheckResult")
@JvmStatic
fun clearMemory(context: Context) {
Observable.just(0)
.observeOn(Schedulers.io())
Expand All @@ -316,6 +327,7 @@ object EasyGlide {
/**
* 取消图片加载
*/
@JvmStatic
fun clearImage(context: Context, imageView: ImageView?) {
EasyGlideApp.get(context).requestManagerRetriever[context].clear(imageView!!)
}
Expand All @@ -326,6 +338,7 @@ object EasyGlide {
* @param imgUrl
*/
@SuppressLint("CheckResult")
@JvmStatic
fun downloadImageToGallery(context: Context, imgUrl: String?) {
val extension = MimeTypeMap.getFileExtensionFromUrl(imgUrl)
Observable.create(ObservableOnSubscribe { emitter: ObservableEmitter<File?> ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class GlideConfigImpl private constructor(builder: Builder) : ImageConfig() {
return this
}

fun setDecodeFormate(decodeFormat: DecodeFormat?): Builder {
fun setDecodeFormat(decodeFormat: DecodeFormat?): Builder {
formatType = decodeFormat
return this
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ object ProgressManager {
}

fun addListener(url: String, listener: OnProgressListener?) {
if (!TextUtils.isEmpty(url) && listener != null) {
if (url.isNotBlank() && listener != null) {
listenersMap[url] = listener
listener.onProgress(false, 1, 0, 0)
}
Expand Down

0 comments on commit 1adbb42

Please sign in to comment.