Skip to content

Commit 30de6ed

Browse files
committed
1、新增coil拓展函数
2、升级版本
1 parent 0b81fa4 commit 30de6ed

File tree

4 files changed

+71
-25
lines changed

4 files changed

+71
-25
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
@file:JvmName("-SingletonGraphicsExtensions")
2+
@file:Suppress("NOTHING_TO_INLINE")
3+
package com.flyjingfish.graphicsdrawablecoillib
4+
5+
6+
import coil.request.ImageRequest
7+
import com.flyjingfish.graphicsdrawablelib.GraphicsDrawable
8+
9+
inline fun ImageRequest.Builder.setGraphicsImageViewDrawable(
10+
graphicsDrawable: GraphicsDrawable
11+
): ImageRequest.Builder {
12+
return this.target(CoilGraphicsImageViewTarget(graphicsDrawable))
13+
}
14+
15+
inline fun ImageRequest.Builder.setGraphicsViewBackground(
16+
graphicsDrawable: GraphicsDrawable
17+
): ImageRequest.Builder {
18+
return this.target(CoilGraphicsViewBackgroundTarget(graphicsDrawable))
19+
}

README.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@
3535
```gradle
3636
dependencies {
3737
//必选项
38-
implementation 'io.github.FlyJingFish:GraphicsDrawable:1.0.2'
38+
implementation 'io.github.FlyJingFish:GraphicsDrawable:1.0.3'
3939
//可选项,如果您使用 Glide 则使用这个
40-
implementation 'io.github.FlyJingFish:GraphicsDrawableGlideLib:1.0.2'
40+
implementation 'io.github.FlyJingFish:GraphicsDrawableGlideLib:1.0.3'
4141
//可选项,如果您使用 Coil 则使用这个
42-
implementation 'io.github.FlyJingFish:GraphicsDrawableCoilLib:1.0.2'
42+
implementation 'io.github.FlyJingFish:GraphicsDrawableCoilLib:1.0.3'
4343
}
4444
```
4545
## 第二步、使用说明
@@ -144,6 +144,14 @@ val request = ImageRequest.Builder(context)
144144

145145
imageLoader.enqueue(request)
146146

147+
// 或者
148+
149+
imageView.load(url){
150+
placeholder(R.drawable.placeholder)
151+
error(R.drawable.error)
152+
setGraphicsImageViewDrawable(pic1Drawable)
153+
}
154+
147155
```
148156

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

173+
174+
// 或者
175+
176+
imageView.load(url){
177+
placeholder(R.drawable.placeholder)
178+
error(R.drawable.error)
179+
setGraphicsViewBackground(pic1Drawable)
180+
}
181+
165182
```
166183

167184
### 四、番外:使用 svg 资源图作为自定义图形

app/src/main/java/com/flyjingfish/graphicsdrawable/MyImageLoader.kt

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
package com.flyjingfish.graphicsdrawable
22

33
import android.graphics.drawable.Drawable
4-
import android.util.TypedValue
54
import android.widget.ImageView
65
import androidx.annotation.DrawableRes
7-
import coil.Coil
8-
import coil.request.ImageRequest
6+
import coil.load
97
import com.bumptech.glide.Glide
108
import com.bumptech.glide.RequestBuilder
119
import com.bumptech.glide.request.RequestOptions
12-
import com.flyjingfish.graphicsdrawablecoillib.CoilGraphicsImageViewTarget
13-
import com.flyjingfish.graphicsdrawablecoillib.CoilGraphicsViewBackgroundTarget
10+
import com.flyjingfish.graphicsdrawablecoillib.setGraphicsImageViewDrawable
11+
import com.flyjingfish.graphicsdrawablecoillib.setGraphicsViewBackground
1412
import com.flyjingfish.graphicsdrawableglidelib.GlideGraphicsImageViewTarget
1513
import com.flyjingfish.graphicsdrawableglidelib.GlideGraphicsViewBackgroundTarget
1614
import com.flyjingfish.graphicsdrawablelib.GraphicsDrawable
@@ -45,24 +43,36 @@ object MyImageLoader {
4543
@DrawableRes err: Int,
4644
graphicsDrawable: GraphicsDrawable
4745
) {
48-
val imageLoader = Coil.imageLoader(iv.context)
49-
val requestBuilder = ImageRequest.Builder(iv.context)
50-
.data(url)
46+
// val imageLoader = Coil.imageLoader(iv.context)
47+
// val requestBuilder = ImageRequest.Builder(iv.context)
48+
// .data(url)
49+
//
50+
// if (p != -1) requestBuilder.placeholder(p)
51+
// if (err != -1) requestBuilder.error(err)
52+
//
53+
// if (useDrawable) {
54+
// if (backgroundMode){
55+
// requestBuilder.target(CoilGraphicsViewBackgroundTarget(graphicsDrawable))
56+
// }else{
57+
// requestBuilder.target(CoilGraphicsImageViewTarget(graphicsDrawable))
58+
// }
59+
// } else {
60+
// requestBuilder.target(iv)
61+
// }
62+
// val request = requestBuilder.build()
63+
// imageLoader.enqueue(request)
5164

52-
if (p != -1) requestBuilder.placeholder(p)
53-
if (err != -1) requestBuilder.error(err)
54-
55-
if (useDrawable) {
56-
if (backgroundMode){
57-
requestBuilder.target(CoilGraphicsViewBackgroundTarget(graphicsDrawable))
58-
}else{
59-
requestBuilder.target(CoilGraphicsImageViewTarget(graphicsDrawable))
65+
iv.load(url){
66+
if (p != -1) placeholder(p)
67+
if (err != -1) error(err)
68+
if (useDrawable) {
69+
if (backgroundMode){
70+
setGraphicsViewBackground(graphicsDrawable)
71+
}else{
72+
setGraphicsImageViewDrawable(graphicsDrawable)
73+
}
6074
}
61-
} else {
62-
requestBuilder.target(iv)
6375
}
64-
val request = requestBuilder.build()
65-
imageLoader.enqueue(request)
6676
}
6777

6878
private fun intoGlide(

version.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
#Sat Mar 16 00:32:34 CST 2024
2-
PROJ_VERSION=1.0.2
1+
#Mon Mar 18 15:37:04 CST 2024
2+
PROJ_VERSION=1.0.3

0 commit comments

Comments
 (0)