Skip to content

Commit

Permalink
리뷰 반영
Browse files Browse the repository at this point in the history
  • Loading branch information
DongJun-H committed Mar 23, 2022
1 parent e7f92d1 commit 93aaf58
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.moyerun.moyeorun_android.common
package com.moyerun.moyeorun_android.views
import android.content.Context
import android.content.res.TypedArray
import android.util.AttributeSet
Expand All @@ -11,46 +11,46 @@ class BadgeRoundImageView : ConstraintLayout {
constructor(context: Context): super(context) { initView() }
constructor(context: Context, attrs: AttributeSet): super(context, attrs) {
initView()
getAttrs(attrs)
setAttrs(attrs)
}
constructor(context: Context, attrs: AttributeSet, defStyle: Int): super(context, attrs) {
initView()
getAttrs(attrs, defStyle)
setAttrs(attrs, defStyle)
}

// 뷰 참조할 때 사용
private lateinit var binding: ViewBadgeRoundImageBinding

// View Binding으로 레이아웃 파일 연결
private fun initView() { binding = ViewBadgeRoundImageBinding.inflate(LayoutInflater.from(context), this, true) }

// attrs.xml에 선언해둔 attribute를 이용하여 이를 각각의 View에 설정해준다.
private fun getAttrs(attrs: AttributeSet) {
val typedArray = context.obtainStyledAttributes(attrs, R.styleable.BadgeRoundImageView)
setTypedArray(typedArray)
private fun getAttrs(attributeSet: AttributeSet, customViewAttrs: IntArray, defStyle: Int=0, defStyleRes: Int=0)
= context.obtainStyledAttributes(attributeSet, customViewAttrs, defStyle, defStyleRes)

private fun setAttrs(attrs: AttributeSet) {
val attributesTypedArray = getAttrs(attrs, R.styleable.BadgeRoundImageView)
setTypedArray(attributesTypedArray)
}
private fun getAttrs(attrs: AttributeSet, defStyle: Int) {
val typedArray = context.obtainStyledAttributes(attrs, R.styleable.BadgeRoundImageView, defStyle, 0)
setTypedArray(typedArray)
private fun setAttrs(attrs: AttributeSet, defStyle: Int) {
val attributesTypedArray = getAttrs(attrs, R.styleable.BadgeRoundImageView, defStyle, 0)
setTypedArray(attributesTypedArray)
}
private fun setTypedArray(typedArray: TypedArray) {
binding.imgBigCircle.apply {
val bigCircleImgResId = typedArray.getResourceId(R.styleable.BadgeRoundImageView_bigCircleImgSrc, R.drawable.ic_launcher_foreground)
val bigCircleImgBgResId = typedArray.getResourceId(R.styleable.BadgeRoundImageView_bigCircleImgBackground, R.drawable.ic_launcher_foreground)
val bigCircleImgSize = typedArray.getDimensionPixelSize(R.styleable.BadgeRoundImageView_bigCircleImgSize, 0)
val bigCircleImgBgResId = typedArray.getResourceId(R.styleable.BadgeRoundImageView_bigCircleBackgroundColor, R.drawable.ic_launcher_foreground)
val bigCircleSize = typedArray.getDimensionPixelSize(R.styleable.BadgeRoundImageView_bigCircleSize, 0)

this.setImageResource(bigCircleImgResId)
this.setBackgroundResource(bigCircleImgBgResId)
this.layoutParams.apply {
this.height = bigCircleImgSize
this.width = bigCircleImgSize
this.height = bigCircleSize
this.width = bigCircleSize
}
binding.viewBigCircle.radius = bigCircleImgSize.toFloat()
binding.viewBigCircle.radius = bigCircleSize.toFloat()
}

binding.imgBadgeSymbol.apply {
val badgeResId = typedArray.getResourceId(R.styleable.BadgeRoundImageView_badgeSrc, R.drawable.ic_launcher_foreground)
val badgeBgResId = typedArray.getResourceId(R.styleable.BadgeRoundImageView_badgeBackground, R.drawable.ic_launcher_foreground)
val badgeResId = typedArray.getResourceId(R.styleable.BadgeRoundImageView_badgeImgSrc, R.drawable.ic_launcher_foreground)
val badgeBgResId = typedArray.getResourceId(R.styleable.BadgeRoundImageView_badgeBackgroundColor, R.drawable.ic_launcher_foreground)
val badgeSize = typedArray.getDimensionPixelSize(R.styleable.BadgeRoundImageView_badgeSize, 0)

this.setImageResource(badgeResId)
Expand All @@ -64,7 +64,6 @@ class BadgeRoundImageView : ConstraintLayout {
typedArray.recycle()
}

// Set Programmatically
fun setBigCircleImgSrc(imgResId: Int) {
binding.imgBigCircle.setImageResource(imgResId)
}
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<resources>
<declare-styleable name="BadgeRoundImageView">
<attr name="bigCircleImgSrc" format="reference|integer"/>
<attr name="bigCircleImgBackground" format="reference|integer|color"/>
<attr name="bigCircleImgSize" format="reference|integer|dimension"/>
<attr name="badgeSrc" format="reference|integer"/>
<attr name="badgeBackground" format="reference|integer|color"/>
<attr name="bigCircleBackgroundColor" format="reference|integer|color"/>
<attr name="bigCircleSize" format="reference|integer|dimension"/>
<attr name="badgeImgSrc" format="reference|integer"/>
<attr name="badgeBackgroundColor" format="reference|integer|color"/>
<attr name="badgeSize" format="reference|integer|dimension"/>
</declare-styleable>
</resources>

0 comments on commit 93aaf58

Please sign in to comment.