Skip to content

Commit

Permalink
[feature/common/royal_flush_edit_text]: #9 feat: Royal Flush Edit Tex…
Browse files Browse the repository at this point in the history
…t Hint 속성 구현
  • Loading branch information
soopeach committed May 10, 2023
1 parent 8a11ff6 commit f085da7
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,47 @@ import androidx.constraintlayout.widget.ConstraintLayout
import com.ggne.feature_common.R
import com.ggne.feature_common.databinding.RoyalFlushEditTextBinding

class RoyalFlushEditText(context: Context, attrs: AttributeSet): ConstraintLayout(context, attrs) {
class RoyalFlushEditText(context: Context, attrs: AttributeSet) : ConstraintLayout(context, attrs) {

private val binding = RoyalFlushEditTextBinding.inflate(LayoutInflater.from(context), this, true)
private val binding =
RoyalFlushEditTextBinding.inflate(LayoutInflater.from(context), this, true)

init {

context.theme.obtainStyledAttributes(
attrs,
R.styleable.RoyalFlushEditText,
0, 0
0,
0,
).apply {
try {
getResourceId(R.styleable.RoyalFlushEditText_startIcon, EMPTY_RESOURCE).let { resource ->

getResourceId(
R.styleable.RoyalFlushEditText_startIcon,
EMPTY_RESOURCE,
).let { resource ->
if (resource == EMPTY_RESOURCE) {
binding.startIc.visibility = GONE
} else {
binding.startIc.setImageResource(resource)
}
}

getResourceId(R.styleable.RoyalFlushEditText_endIcon, EMPTY_RESOURCE).let { resource ->
getResourceId(
R.styleable.RoyalFlushEditText_endIcon,
EMPTY_RESOURCE,
).let { resource ->
if (resource == EMPTY_RESOURCE) {
binding.endIc.visibility = GONE
} else {
binding.endIc.setImageResource(resource)
}
}

getString(R.styleable.RoyalFlushEditText_royalFlushEditTextHint).let { hint ->
binding.et.hint = hint
}

} finally {
recycle()
}
Expand All @@ -47,4 +60,4 @@ class RoyalFlushEditText(context: Context, attrs: AttributeSet): ConstraintLayou
companion object {
private const val EMPTY_RESOURCE = -1
}
}
}
Original file line number Diff line number Diff line change
@@ -1,48 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="60dp"
android:paddingHorizontal="18dp"
android:paddingVertical="14dp"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:background="@drawable/royal_flush_edit_text_background">

<ImageView
android:id="@+id/start_ic"
android:layout_width="0dp"
android:layout_height="0dp"
android:paddingEnd="4dp"
app:layout_constraintBottom_toBottomOf="@id/et"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@id/et"
app:layout_constraintBottom_toBottomOf="@id/et"
android:contentDescription="@string/start_ic" />
android:contentDescription="@string/start_ic"/>

<EditText
android:id="@+id/et"
android:layout_width="0dp"
android:layout_height="0dp"
android:autofillHints="yes"
android:background="@null"
android:textSize="14sp"
android:maxLines="1"
android:gravity="center_vertical"
android:inputType="text"
app:layout_constraintStart_toEndOf="@id/start_ic"
android:maxLines="1"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/end_ic"
app:layout_constraintStart_toEndOf="@id/start_ic"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:autofillHints="yes"
tools:ignore="LabelFor" />

<ImageView
android:id="@+id/end_ic"
android:layout_width="0dp"
android:layout_height="0dp"
android:paddingStart="4dp"
app:layout_constraintBottom_toBottomOf="@id/et"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@id/et"
app:layout_constraintBottom_toBottomOf="@id/et"
android:contentDescription="@string/start_ic" />
android:contentDescription="@string/end_ic"/>

</androidx.constraintlayout.widget.ConstraintLayout>
5 changes: 3 additions & 2 deletions feature/feature-common/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="RoyalFlushEditText">
<attr name="startIcon" format="reference"/>
<attr name="endIcon" format="reference"/>
<attr name="startIcon" format="reference" />
<attr name="endIcon" format="reference" />
<attr name="royalFlushEditTextHint" format="string" />
</declare-styleable>
</resources>

0 comments on commit f085da7

Please sign in to comment.