diff --git a/feature/feature-common/src/main/java/com/ggne/feature_common/custom/RoyalFlushVerificationEditText.kt b/feature/feature-common/src/main/java/com/ggne/feature_common/custom/RoyalFlushVerificationEditText.kt new file mode 100644 index 0000000..f9b8ea0 --- /dev/null +++ b/feature/feature-common/src/main/java/com/ggne/feature_common/custom/RoyalFlushVerificationEditText.kt @@ -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_royalFlushVerificationEditTextHint, 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 + } + } + + +} \ No newline at end of file diff --git a/feature/feature-common/src/main/res/layout/royal_flush_verification_edit_text.xml b/feature/feature-common/src/main/res/layout/royal_flush_verification_edit_text.xml new file mode 100644 index 0000000..636ad81 --- /dev/null +++ b/feature/feature-common/src/main/res/layout/royal_flush_verification_edit_text.xml @@ -0,0 +1,54 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/feature/feature-common/src/main/res/values/attrs.xml b/feature/feature-common/src/main/res/values/attrs.xml index adfb641..c1490e2 100644 --- a/feature/feature-common/src/main/res/values/attrs.xml +++ b/feature/feature-common/src/main/res/values/attrs.xml @@ -5,4 +5,12 @@ + + + + + + + + \ No newline at end of file diff --git a/feature/feature-common/src/main/res/values/strings.xml b/feature/feature-common/src/main/res/values/strings.xml index f66188e..7429d64 100644 --- a/feature/feature-common/src/main/res/values/strings.xml +++ b/feature/feature-common/src/main/res/values/strings.xml @@ -2,4 +2,6 @@ 시작 아이콘 끝 아이콘 + %d/%d + 사용 가능한 닉네임입니다. \ No newline at end of file