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
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
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"],
)
fun ImageView.loadImageWithCoil(
url: String?,
placeHolder: Drawable? = null,
) {
load(url) {
placeholder(placeHolder)
error(placeHolder)
}
}

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

@BindingAdapter(
value = ["glideImageUrl", "glidePlaceHolder"],
)
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들의 이름을 명확하게 작성해주셔서 나중에 사용하기 편할 것 같습니다!👍

)
fun ImageView.setCircleImageWithGlide(
url: String?,
placeHolder: Drawable? = null,
) {
Glide.with(context)
.load(url)
.placeholder(placeHolder)
.circleCrop()
.error(placeHolder)
.into(this)
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,4 @@

</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</layout>
</layout>
8 changes: 5 additions & 3 deletions android/Staccato_AN/app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Base.Theme.Staccato_AN" parent="Theme.Material3.DayNight.NoActionBar">
<!-- Customize your light theme here. -->
<!-- <item name="colorPrimary">@color/my_light_primary</item> -->
<!-- Status bar color. -->
<item name="android:statusBarColor">@android:color/white</item>
<!-- Customize your theme here. -->
<item name="android:windowLightStatusBar">true</item>
</style>

<style name="Theme.Staccato_AN" parent="Base.Theme.Staccato_AN" />
</resources>
</resources>
Loading