Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 공통 이미지 로딩 BindingAdapter 설정 #33 #41

Merged
4 changes: 4 additions & 0 deletions android/Staccato_AN/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ android {
kotlinOptions {
jvmTarget = "1.8"
}

buildFeatures {
dataBinding = true
}
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package com.woowacourse.staccato.presentation

import android.graphics.drawable.Drawable
import android.widget.ImageView
import androidx.databinding.BindingAdapter
import coil.load
import coil.transform.RoundedCornersTransformation
import com.bumptech.glide.Glide

@BindingAdapter(
value = ["coilImageUrl", "coilPlaceHolder"],
requireAll = false,
Copy link
Member

@s6m1n s6m1n Jul 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

coilImageUrlcoilPlaceHolder 값이 모두 필요하니 requireAll = false 옵션을 없애는 게 더 안전할 것 같다는 생각이 듭니다! (밑에 메서드들도 마찬가지..!)

)
fun ImageView.loadImageWithCoil(
url: String?,
placeHolder: Drawable? = null,
) {
url?.let {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

url이 null일 때도 placeholder가 적용되도록 수정이 필요해보입니당!!

this.load(it) {
placeholder(placeHolder)
error(placeHolder)
}
}
}

@BindingAdapter(
value = ["coilCircleImageUrl", "coilPlaceHolder"],
requireAll = false,
)
fun ImageView.setCircleImageWithCoil(
url: String?,
placeHolder: Drawable? = null,
) {
url?.let {
this.load(it) {
placeholder(placeHolder)
transformations(RoundedCornersTransformation(1000f))
error(placeHolder)
}
}
}

@BindingAdapter(
value = ["glideImageUrl", "glidePlaceHolder"],
requireAll = false,
)
fun ImageView.loadImageWithGlide(
url: String?,
placeHolder: Drawable? = null,
) {
Glide.with(context)
.load(url)
.placeholder(placeHolder)
.error(placeHolder)
.into(this)
}

@BindingAdapter(
value = ["glideCircleImageUrl", "glidePlaceHolder"],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

value들의 이름을 명확하게 작성해주셔서 나중에 사용하기 편할 것 같습니다!👍

requireAll = false,
)
fun ImageView.setCircleImageWithGlide(
url: String?,
placeHolder: Drawable? = null,
) {
Glide.with(context)
.load(url)
.placeholder(placeHolder)
.circleCrop()
.error(placeHolder)
.into(this)
}
Loading