Skip to content

Commit

Permalink
1、新增coil拓展函数
Browse files Browse the repository at this point in the history
2、升级版本
  • Loading branch information
FlyJingFish committed Mar 18, 2024
1 parent 0b81fa4 commit 30de6ed
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@file:JvmName("-SingletonGraphicsExtensions")
@file:Suppress("NOTHING_TO_INLINE")
package com.flyjingfish.graphicsdrawablecoillib


import coil.request.ImageRequest
import com.flyjingfish.graphicsdrawablelib.GraphicsDrawable

inline fun ImageRequest.Builder.setGraphicsImageViewDrawable(
graphicsDrawable: GraphicsDrawable
): ImageRequest.Builder {
return this.target(CoilGraphicsImageViewTarget(graphicsDrawable))
}

inline fun ImageRequest.Builder.setGraphicsViewBackground(
graphicsDrawable: GraphicsDrawable
): ImageRequest.Builder {
return this.target(CoilGraphicsViewBackgroundTarget(graphicsDrawable))
}
23 changes: 20 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@
```gradle
dependencies {
//必选项
implementation 'io.github.FlyJingFish:GraphicsDrawable:1.0.2'
implementation 'io.github.FlyJingFish:GraphicsDrawable:1.0.3'
//可选项,如果您使用 Glide 则使用这个
implementation 'io.github.FlyJingFish:GraphicsDrawableGlideLib:1.0.2'
implementation 'io.github.FlyJingFish:GraphicsDrawableGlideLib:1.0.3'
//可选项,如果您使用 Coil 则使用这个
implementation 'io.github.FlyJingFish:GraphicsDrawableCoilLib:1.0.2'
implementation 'io.github.FlyJingFish:GraphicsDrawableCoilLib:1.0.3'
}
```
## 第二步、使用说明
Expand Down Expand Up @@ -144,6 +144,14 @@ val request = ImageRequest.Builder(context)

imageLoader.enqueue(request)

// 或者

imageView.load(url){
placeholder(R.drawable.placeholder)
error(R.drawable.error)
setGraphicsImageViewDrawable(pic1Drawable)
}

```

- View 设置 背景
Expand All @@ -162,6 +170,15 @@ val request = ImageRequest.Builder(context)
.build()
imageLoader.enqueue(request)


// 或者

imageView.load(url){
placeholder(R.drawable.placeholder)
error(R.drawable.error)
setGraphicsViewBackground(pic1Drawable)
}

```

### 四、番外:使用 svg 资源图作为自定义图形
Expand Down
50 changes: 30 additions & 20 deletions app/src/main/java/com/flyjingfish/graphicsdrawable/MyImageLoader.kt
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package com.flyjingfish.graphicsdrawable

import android.graphics.drawable.Drawable
import android.util.TypedValue
import android.widget.ImageView
import androidx.annotation.DrawableRes
import coil.Coil
import coil.request.ImageRequest
import coil.load
import com.bumptech.glide.Glide
import com.bumptech.glide.RequestBuilder
import com.bumptech.glide.request.RequestOptions
import com.flyjingfish.graphicsdrawablecoillib.CoilGraphicsImageViewTarget
import com.flyjingfish.graphicsdrawablecoillib.CoilGraphicsViewBackgroundTarget
import com.flyjingfish.graphicsdrawablecoillib.setGraphicsImageViewDrawable
import com.flyjingfish.graphicsdrawablecoillib.setGraphicsViewBackground
import com.flyjingfish.graphicsdrawableglidelib.GlideGraphicsImageViewTarget
import com.flyjingfish.graphicsdrawableglidelib.GlideGraphicsViewBackgroundTarget
import com.flyjingfish.graphicsdrawablelib.GraphicsDrawable
Expand Down Expand Up @@ -45,24 +43,36 @@ object MyImageLoader {
@DrawableRes err: Int,
graphicsDrawable: GraphicsDrawable
) {
val imageLoader = Coil.imageLoader(iv.context)
val requestBuilder = ImageRequest.Builder(iv.context)
.data(url)
// val imageLoader = Coil.imageLoader(iv.context)
// val requestBuilder = ImageRequest.Builder(iv.context)
// .data(url)
//
// if (p != -1) requestBuilder.placeholder(p)
// if (err != -1) requestBuilder.error(err)
//
// if (useDrawable) {
// if (backgroundMode){
// requestBuilder.target(CoilGraphicsViewBackgroundTarget(graphicsDrawable))
// }else{
// requestBuilder.target(CoilGraphicsImageViewTarget(graphicsDrawable))
// }
// } else {
// requestBuilder.target(iv)
// }
// val request = requestBuilder.build()
// imageLoader.enqueue(request)

if (p != -1) requestBuilder.placeholder(p)
if (err != -1) requestBuilder.error(err)

if (useDrawable) {
if (backgroundMode){
requestBuilder.target(CoilGraphicsViewBackgroundTarget(graphicsDrawable))
}else{
requestBuilder.target(CoilGraphicsImageViewTarget(graphicsDrawable))
iv.load(url){
if (p != -1) placeholder(p)
if (err != -1) error(err)
if (useDrawable) {
if (backgroundMode){
setGraphicsViewBackground(graphicsDrawable)
}else{
setGraphicsImageViewDrawable(graphicsDrawable)
}
}
} else {
requestBuilder.target(iv)
}
val request = requestBuilder.build()
imageLoader.enqueue(request)
}

private fun intoGlide(
Expand Down
4 changes: 2 additions & 2 deletions version.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#Sat Mar 16 00:32:34 CST 2024
PROJ_VERSION=1.0.2
#Mon Mar 18 15:37:04 CST 2024
PROJ_VERSION=1.0.3

0 comments on commit 30de6ed

Please sign in to comment.