From df877a45b95c0aa41c9cd139b09d225ef5751979 Mon Sep 17 00:00:00 2001 From: hodu <92203597+Junyoung-WON@users.noreply.github.com> Date: Thu, 25 Jul 2024 13:06:51 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EB=91=A5=EA=B7=BC=20=EB=AA=A8=EC=84=9C?= =?UTF-8?q?=EB=A6=AC=EC=9D=98=20=EC=9D=B4=EB=AF=B8=EC=A7=80=EB=A5=BC=20?= =?UTF-8?q?=EB=A1=9C=EB=93=9C=ED=95=98=EB=8A=94=20BindingAdapters=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20#58=20(#59)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 둥근 모서리로 이미지를 로딩하는 Glide 바인딩 어댑터 작성 - 세 속성이 모두 필요하다. - glideRoundedCornerImageUrl: 출력하고자 하는 이미지 url - glidePlaceHolder: placeHolder의 url - glideRoundingRadius: 모서리의 둥근 정도를 Int로 설정 * feat: 둥근 모서리로 이미지를 로딩하는 Coil 바인딩 어댑터 작성 - 세 속성이 모두 필요하다. - coilRoundedCornerImageUrl: 출력하고자 하는 이미지 url - coilPlaceHolder: placeHolder의 url - coilRoundingRadius: 모서리의 둥근 정도를 Float으로 설정 * fix: centerCrop 설정을 BindingAdapter 에 위임 - xml 속성으로 centerCrop을 주게 되면 Round Corner가 제대로 적용되지 않는 현상 발생 - Glide의 api로 제공되는 centerCrop() 메서드를 활용 --- .../staccato/presentation/BindingAdapters.kt | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/android/Staccato_AN/app/src/main/java/com/woowacourse/staccato/presentation/BindingAdapters.kt b/android/Staccato_AN/app/src/main/java/com/woowacourse/staccato/presentation/BindingAdapters.kt index b745373df..a295c42cd 100644 --- a/android/Staccato_AN/app/src/main/java/com/woowacourse/staccato/presentation/BindingAdapters.kt +++ b/android/Staccato_AN/app/src/main/java/com/woowacourse/staccato/presentation/BindingAdapters.kt @@ -6,6 +6,8 @@ import androidx.databinding.BindingAdapter import coil.load import coil.transform.RoundedCornersTransformation import com.bumptech.glide.Glide +import com.bumptech.glide.load.resource.bitmap.RoundedCorners +import com.bumptech.glide.request.RequestOptions @BindingAdapter( value = ["coilImageUrl", "coilPlaceHolder"], @@ -34,6 +36,21 @@ fun ImageView.setCircleImageWithCoil( } } +@BindingAdapter( + value = ["coilRoundedCornerImageUrl", "coilPlaceHolder", "coilRoundingRadius"], +) +fun ImageView.setRoundedCornerImageWithCoil( + url: String?, + placeHolder: Drawable? = null, + roundingRadius: Float, +) { + load(url) { + placeholder(placeHolder) + transformations(RoundedCornersTransformation(roundingRadius)) + error(placeHolder) + } +} + @BindingAdapter( value = ["glideImageUrl", "glidePlaceHolder"], ) @@ -44,6 +61,7 @@ fun ImageView.loadImageWithGlide( Glide.with(context) .load(url) .placeholder(placeHolder) + .centerCrop() .error(placeHolder) .into(this) } @@ -62,3 +80,20 @@ fun ImageView.setCircleImageWithGlide( .error(placeHolder) .into(this) } + +@BindingAdapter( + value = ["glideRoundedCornerImageUrl", "glidePlaceHolder", "glideRoundingRadius"], +) +fun ImageView.setRoundedCornerImageWithGlide( + url: String?, + placeHolder: Drawable? = null, + roundingRadius: Int, +) { + Glide.with(context) + .load(url) + .placeholder(placeHolder) + .centerCrop() + .apply(RequestOptions.bitmapTransform(RoundedCorners(roundingRadius))) + .error(placeHolder) + .into(this) +}