Skip to content

Commit

Permalink
更新Coil版本
Browse files Browse the repository at this point in the history
  • Loading branch information
zhujiang2 committed May 22, 2021
1 parent 005e357 commit e23d6d4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
4 changes: 2 additions & 2 deletions banner/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ android {

dependencies {
implementation "androidx.compose.material:material:$compose_version"
api "dev.chrisbanes.accompanist:accompanist-coil:0.10.0"
api "dev.chrisbanes.accompanist:accompanist-insets:0.10.0"
api "com.google.accompanist:accompanist-coil:0.10.0"
api "com.google.accompanist:accompanist-insets:0.10.0"
}
23 changes: 10 additions & 13 deletions banner/src/main/java/com/zj/banner/ui/BannerCard.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import androidx.compose.ui.graphics.painter.BitmapPainter
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import com.google.accompanist.coil.rememberCoilPainter
import com.zj.banner.model.BaseBannerBean
import dev.chrisbanes.accompanist.coil.CoilImage

private const val TAG = "BannerCard"

Expand Down Expand Up @@ -46,23 +46,20 @@ fun <T : BaseBannerBean> BannerCard(
when (bean.data) {
is String -> {
val img = bean.data as String
if (img.contains("https://") || img.contains("http://")) {
val painter = if (img.contains("https://") || img.contains("http://")) {
Log.d(TAG, "PostCardPopular: 加载网络图片")
CoilImage(
data = img,
contentDescription = null,
modifier = imgModifier
)
rememberCoilPainter(img)
} else {
Log.d(TAG, "PostCardPopular: 加载本地图片")
val bitmap = BitmapFactory.decodeFile(img)
Image(
modifier = imgModifier,
painter = BitmapPainter(bitmap.asImageBitmap()),
contentDescription = "",
contentScale = ContentScale.Crop
)
BitmapPainter(bitmap.asImageBitmap())
}
Image(
modifier = imgModifier,
painter = painter,
contentDescription = "",
contentScale = ContentScale.Crop
)
}
is Int -> {
Log.d(TAG, "PostCardPopular: 加载本地资源图片")
Expand Down

0 comments on commit e23d6d4

Please sign in to comment.