diff --git a/feature/feature-common/build.gradle.kts b/feature/feature-common/build.gradle.kts index c74772a..0fbf81f 100644 --- a/feature/feature-common/build.gradle.kts +++ b/feature/feature-common/build.gradle.kts @@ -1,3 +1,5 @@ +@file:Suppress("UnstableApiUsage") + @Suppress("DSL_SCOPE_VIOLATION") plugins { @@ -6,6 +8,9 @@ plugins { android { namespace = "com.ggne.feature_common" + buildFeatures { + viewBinding = true + } } dependencies { diff --git a/feature/feature-common/src/main/java/com/ggne/feature_common/custom/RoyalFlushIconEditText.kt b/feature/feature-common/src/main/java/com/ggne/feature_common/custom/RoyalFlushIconEditText.kt new file mode 100644 index 0000000..36ad3f6 --- /dev/null +++ b/feature/feature-common/src/main/java/com/ggne/feature_common/custom/RoyalFlushIconEditText.kt @@ -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 + } +} 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..576d595 --- /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_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 + } + } + + +} \ No newline at end of file diff --git a/feature/feature-common/src/main/java/com/ggne/feature_common/extensions/utils.kt b/feature/feature-common/src/main/java/com/ggne/feature_common/extensions/utils.kt new file mode 100644 index 0000000..cf6d88b --- /dev/null +++ b/feature/feature-common/src/main/java/com/ggne/feature_common/extensions/utils.kt @@ -0,0 +1,4 @@ +package com.ggne.feature_common.extensions + +val String.Companion.EMPTY: String + get() = "" \ No newline at end of file diff --git a/feature/feature-common/src/main/java/com/ggne/feature_common/extensions/viewExtensions.kt b/feature/feature-common/src/main/java/com/ggne/feature_common/extensions/viewExtensions.kt new file mode 100644 index 0000000..0fd30ce --- /dev/null +++ b/feature/feature-common/src/main/java/com/ggne/feature_common/extensions/viewExtensions.kt @@ -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) { + } + }) +} \ No newline at end of file diff --git a/feature/feature-common/src/main/res/drawable/royal_flush_edit_text_background.xml b/feature/feature-common/src/main/res/drawable/royal_flush_edit_text_background.xml new file mode 100644 index 0000000..bdb680f --- /dev/null +++ b/feature/feature-common/src/main/res/drawable/royal_flush_edit_text_background.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/feature/feature-common/src/main/res/layout/royal_flush_icon_edit_text.xml b/feature/feature-common/src/main/res/layout/royal_flush_icon_edit_text.xml new file mode 100644 index 0000000..81e50d3 --- /dev/null +++ b/feature/feature-common/src/main/res/layout/royal_flush_icon_edit_text.xml @@ -0,0 +1,49 @@ + + + + + + + + + + \ 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..f7c5249 --- /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 new file mode 100644 index 0000000..c1490e2 --- /dev/null +++ b/feature/feature-common/src/main/res/values/attrs.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ 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 new file mode 100644 index 0000000..7429d64 --- /dev/null +++ b/feature/feature-common/src/main/res/values/strings.xml @@ -0,0 +1,7 @@ + + + 시작 아이콘 + 끝 아이콘 + %d/%d + 사용 가능한 닉네임입니다. + \ No newline at end of file