-
Notifications
You must be signed in to change notification settings - Fork 0
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
양 끝에 아이콘을 추가할 수 있는 Edit Text & 검증 텍스트와 텍스트 제한 기능이 있는 Edit Text 구현 #12
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
c36922b
[feature/common/royal_flush_edit_text]: #9 chore: feautre-common 모듈에 …
soopeach 00f40ba
[feature/common/royal_flush_edit_text]: #9 feat: 기본 Royal Flush Edit …
soopeach 84c314b
[feature/common/royal_flush_edit_text]: #9 feat: Royal Flush Edit Tex…
soopeach 8a11ff6
[feature/common/royal_flush_edit_text]: #9 feat: Royal Flush Edit Tex…
soopeach f085da7
[feature/common/royal_flush_edit_text]: #9 feat: Royal Flush Edit Tex…
soopeach be6c697
[feature/common/royal_flush_edit_text]: #9 style: Royal Flush Edit Te…
soopeach 40c1717
[feature/common/royal_flush_edit_text]: #9 rename: Royal Flush Edit T…
soopeach 9b85710
[feature/common/royal_flush_edit_text]: #9 feat: Edit Text에 텍스트 입력 후 …
soopeach 6d9b401
[feature/common/royal_flush_edit_text]: #9 feat: 빈 문자열을 반환하는 확장 프로퍼티 추가
soopeach 43ad8d1
[feature/common/royal_flush_edit_text]: #9 feat: RoyalFlushVerificati…
soopeach cd5b180
[feature/common/royal_flush_edit_text]: #9 rename: 컨벤션에 맞게 리소스 아이디 수정
soopeach File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...ure/feature-common/src/main/java/com/ggne/feature_common/custom/RoyalFlushIconEditText.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.ggne.feature_common.custom | ||
|
||
import android.content.Context | ||
import android.util.AttributeSet | ||
import android.view.LayoutInflater | ||
import androidx.constraintlayout.widget.ConstraintLayout | ||
import com.ggne.feature_common.R | ||
import com.ggne.feature_common.databinding.RoyalFlushIconEditTextBinding | ||
|
||
class RoyalFlushIconEditText(context: Context, attrs: AttributeSet) : | ||
ConstraintLayout(context, attrs) { | ||
|
||
private val binding = | ||
RoyalFlushIconEditTextBinding.inflate(LayoutInflater.from(context), this, true) | ||
|
||
init { | ||
|
||
context.theme.obtainStyledAttributes( | ||
attrs, | ||
R.styleable.RoyalFlushIconEditText, | ||
0, | ||
0, | ||
).apply { | ||
try { | ||
|
||
getResourceId( | ||
R.styleable.RoyalFlushIconEditText_startIcon, | ||
EMPTY_RESOURCE, | ||
).let { resource -> | ||
if (resource == EMPTY_RESOURCE) { | ||
binding.ivStartIcon.visibility = GONE | ||
} else { | ||
binding.ivStartIcon.setImageResource(resource) | ||
} | ||
} | ||
|
||
getResourceId( | ||
R.styleable.RoyalFlushIconEditText_endIcon, | ||
EMPTY_RESOURCE, | ||
).let { resource -> | ||
if (resource == EMPTY_RESOURCE) { | ||
binding.ivEndIcon.visibility = GONE | ||
} else { | ||
binding.ivEndIcon.setImageResource(resource) | ||
} | ||
} | ||
|
||
getString(R.styleable.RoyalFlushIconEditText_royalFlushIconEditTextHint).let { hint -> | ||
binding.et.hint = hint | ||
} | ||
} finally { | ||
recycle() | ||
} | ||
} | ||
|
||
removeAllViews() | ||
addView(binding.root) | ||
} | ||
|
||
companion object { | ||
private const val EMPTY_RESOURCE = -1 | ||
} | ||
} |
107 changes: 107 additions & 0 deletions
107
...ure-common/src/main/java/com/ggne/feature_common/custom/RoyalFlushVerificationEditText.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package com.ggne.feature_common.custom | ||
|
||
import android.content.Context | ||
import android.util.AttributeSet | ||
import android.view.LayoutInflater | ||
import androidx.constraintlayout.widget.ConstraintLayout | ||
import com.ggne.feature_common.extensions.EMPTY | ||
import com.ggne.feature_common.R | ||
import com.ggne.feature_common.extensions.addAfterTextChangedListener | ||
import com.ggne.feature_common.databinding.RoyalFlushVerificationEditTextBinding | ||
|
||
class RoyalFlushVerificationEditText(context: Context, attrs: AttributeSet) : | ||
ConstraintLayout(context, attrs) { | ||
|
||
private var maxLength: Int | ||
private var verificationText: String = String.EMPTY | ||
|
||
val text | ||
get() = binding.et.text.toString() | ||
|
||
val editText | ||
get() = binding.et | ||
|
||
private val binding = | ||
RoyalFlushVerificationEditTextBinding.inflate(LayoutInflater.from(context), this, true) | ||
|
||
init { | ||
|
||
context.theme.obtainStyledAttributes( | ||
attrs, | ||
R.styleable.RoyalFlushVerificationEditText, | ||
0, | ||
0, | ||
).apply { | ||
try { | ||
|
||
getString(R.styleable.RoyalFlushVerificationEditText_royalFlushVerificationEditTextHint).let { hint -> | ||
binding.et.hint = hint | ||
} | ||
|
||
getInt(R.styleable.RoyalFlushVerificationEditText_maxLength, Int.MAX_VALUE).let { inputtedMaxLength -> | ||
maxLength = inputtedMaxLength | ||
} | ||
|
||
getBoolean(R.styleable.RoyalFlushVerificationEditText_isCounterVisible, true).let { isVisible -> | ||
if (isVisible) { | ||
|
||
with(binding.counterTv) { | ||
visibility = VISIBLE | ||
text = context.getString(R.string.text_counter_format, 0, maxLength) | ||
} | ||
|
||
binding.et.addAfterTextChangedListener { text -> | ||
if (text.length <= maxLength) { | ||
binding.counterTv.text = context.getString(R.string.text_counter_format, text.length, maxLength) | ||
} else { | ||
with(binding.et) { | ||
setText(text.substring(0, maxLength)) | ||
setSelection(maxLength) | ||
} | ||
} | ||
} | ||
|
||
} else { | ||
binding.counterTv.visibility = GONE | ||
maxLength = Int.MAX_VALUE | ||
} | ||
|
||
} | ||
|
||
getBoolean(R.styleable.RoyalFlushVerificationEditText_isVerificationVisible, false).let { isVisible -> | ||
if (isVisible) { | ||
getString(R.styleable.RoyalFlushVerificationEditText_verificationText).let { inputtedVerificationText -> | ||
verificationText = inputtedVerificationText ?: String.EMPTY | ||
} | ||
setVerification(true) | ||
} else { | ||
setVerification(false) | ||
} | ||
} | ||
|
||
|
||
} finally { | ||
recycle() | ||
} | ||
} | ||
|
||
removeAllViews() | ||
addView(binding.root) | ||
|
||
} | ||
|
||
fun setVerificationText(text: String) { | ||
verificationText = text | ||
} | ||
|
||
fun setVerification(isVerified: Boolean) { | ||
if (isVerified) { | ||
binding.verificationTv.visibility = VISIBLE | ||
binding.verificationTv.text = verificationText | ||
} else { | ||
binding.verificationTv.visibility = GONE | ||
} | ||
} | ||
|
||
|
||
} |
4 changes: 4 additions & 0 deletions
4
feature/feature-common/src/main/java/com/ggne/feature_common/extensions/utils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.ggne.feature_common.extensions | ||
|
||
val String.Companion.EMPTY: String | ||
get() = "" |
19 changes: 19 additions & 0 deletions
19
feature/feature-common/src/main/java/com/ggne/feature_common/extensions/viewExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.ggne.feature_common.extensions | ||
|
||
import android.text.Editable | ||
import android.text.TextWatcher | ||
import android.widget.EditText | ||
|
||
fun EditText.addAfterTextChangedListener(block: (String) -> Unit) { | ||
this.addTextChangedListener(object : TextWatcher { | ||
override fun afterTextChanged(s: Editable?) { | ||
block(s.toString()) | ||
} | ||
|
||
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) { | ||
} | ||
|
||
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) { | ||
} | ||
}) | ||
} |
9 changes: 9 additions & 0 deletions
9
feature/feature-common/src/main/res/drawable/royal_flush_edit_text_background.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<selector > | ||
<item xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<shape android:shape="rectangle"> | ||
<solid android:color="#DFDBCC" /> | ||
<corners android:radius="8dp" /> | ||
</shape> | ||
</item> | ||
</selector> |
49 changes: 49 additions & 0 deletions
49
feature/feature-common/src/main/res/layout/royal_flush_icon_edit_text.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +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:background="@drawable/royal_flush_edit_text_background" | ||
android:paddingHorizontal="18dp" | ||
android:paddingVertical="14dp"> | ||
|
||
<ImageView | ||
android:id="@+id/iv_start_icon" | ||
android:layout_width="0dp" | ||
android:layout_height="0dp" | ||
android:contentDescription="@string/start_ic" | ||
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" /> | ||
|
||
<EditText | ||
android:id="@+id/et" | ||
android:layout_width="0dp" | ||
android:layout_height="0dp" | ||
android:autofillHints="yes" | ||
android:background="@null" | ||
android:gravity="center_vertical" | ||
android:inputType="text" | ||
android:maxLines="1" | ||
android:textSize="18sp" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toStartOf="@id/iv_end_icon" | ||
app:layout_constraintStart_toEndOf="@id/iv_start_icon" | ||
app:layout_constraintTop_toTopOf="parent" | ||
tools:ignore="LabelFor" /> | ||
|
||
<ImageView | ||
android:id="@+id/iv_end_icon" | ||
android:layout_width="0dp" | ||
android:layout_height="0dp" | ||
android:contentDescription="@string/end_ic" | ||
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" /> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> |
54 changes: 54 additions & 0 deletions
54
feature/feature-common/src/main/res/layout/royal_flush_verification_edit_text.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ConstraintLayout이 중첩으로 쓰인 이유가 있을까요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Linear로 개선이 가능해보이네요 감사합니다! |
||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content"> | ||
|
||
<androidx.constraintlayout.widget.ConstraintLayout | ||
android:id="@+id/et_container" | ||
android:layout_width="match_parent" | ||
android:layout_height="60dp" | ||
android:background="@drawable/royal_flush_edit_text_background" | ||
android:paddingHorizontal="18dp" | ||
android:paddingVertical="14dp" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent"> | ||
|
||
<EditText | ||
android:id="@+id/et" | ||
android:layout_width="0dp" | ||
android:layout_height="0dp" | ||
android:autofillHints="yes" | ||
android:background="@null" | ||
android:gravity="center_vertical" | ||
android:inputType="text" | ||
android:maxLines="1" | ||
android:textSize="18sp" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toStartOf="@id/tv_counter" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" | ||
tools:ignore="LabelFor" /> | ||
|
||
<TextView | ||
android:id="@+id/tv_counter" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:paddingStart="4dp" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" /> | ||
</androidx.constraintlayout.widget.ConstraintLayout> | ||
|
||
<TextView | ||
android:id="@+id/tv_verification" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginStart="3dp" | ||
android:layout_marginTop="6dp" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toBottomOf="@id/et_container" /> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<declare-styleable name="RoyalFlushIconEditText"> | ||
<attr name="startIcon" format="reference" /> | ||
<attr name="endIcon" format="reference" /> | ||
<attr name="royalFlushIconEditTextHint" format="string" /> | ||
</declare-styleable> | ||
|
||
<declare-styleable name="RoyalFlushVerificationEditText"> | ||
<attr name="isCounterVisible" format="boolean" /> | ||
<attr name="isVerificationVisible" format="boolean" /> | ||
<attr name="verificationText" format="string" /> | ||
<attr name="maxLength" format="integer" /> | ||
<attr name="royalFlushVerificationEditTextHint" format="string" /> | ||
</declare-styleable> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<string name="start_ic">시작 아이콘</string> | ||
<string name="end_ic">끝 아이콘</string> | ||
<string name="text_counter_format">%d/%d</string> | ||
<string name="can_use_nickname">사용 가능한 닉네임입니다.</string> | ||
</resources> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이런 리소스에 있는 hex color도 테마에 미리 정해놓은걸로 쓸수있나요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
그럼요