Skip to content

Commit

Permalink
feat: 공통 이미지 로딩 BindingAdapter 설정 #33 (#41)
Browse files Browse the repository at this point in the history
* build: dataBinding 사용 설정

* feat: 이미지 로딩 바인딩 어댑터 설정

- Glide, Coil 바인딩 어댑터를 각각 작성
- placeholder 설정

* style: ktlint check

- import 순서 조정

* fix: attribute 개수에 맞추어 BindingAdapter의 value 재설정

* style: 마지막 줄 개행 추가

* feat: placeHolder를 필수 속성으로 변경 및 coil 이미지 로딩 코드 수정

- placeHolder를 ImageView의 필수 속성으로 지정
- Coil BindingAdapter에서 url이 null인 경우에도 이미지를 로드하는 동작이 수행되도록 수정

* ui: 상단바 색상 변경
  • Loading branch information
Junyoung-WON authored Jul 23, 2024
1 parent c98784e commit 5428d76
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 4 deletions.
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"],
)
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>

0 comments on commit 5428d76

Please sign in to comment.