-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of https://github.com/Team-Going/Going-Android …
…into fix/#263-qa-issue
- Loading branch information
Showing
20 changed files
with
283 additions
and
84 deletions.
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
152 changes: 152 additions & 0 deletions
152
...c/main/java/com/going/presentation/designsystem/edittext/EmojiCounterEditTextMultiLine.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,152 @@ | ||
package com.going.presentation.designsystem.edittext | ||
|
||
import android.content.Context | ||
import android.content.res.TypedArray | ||
import android.text.method.ScrollingMovementMethod | ||
import android.util.AttributeSet | ||
import android.view.LayoutInflater | ||
import android.view.View.OnFocusChangeListener | ||
import androidx.constraintlayout.widget.ConstraintLayout | ||
import androidx.core.content.res.ResourcesCompat | ||
import androidx.core.view.isVisible | ||
import androidx.core.widget.doAfterTextChanged | ||
import com.going.presentation.R | ||
import com.going.presentation.databinding.ViewEmojiCounterEdittextMultilineBinding | ||
import com.going.ui.extension.colorOf | ||
import com.going.ui.extension.getGraphemeLength | ||
import com.going.ui.extension.setOnSingleClickListener | ||
|
||
class EmojiCounterEditTextMultiLine(context: Context, attrs: AttributeSet) : | ||
ConstraintLayout(context, attrs) { | ||
|
||
private val binding: ViewEmojiCounterEdittextMultilineBinding | ||
|
||
private var maxLen: Int = 0 | ||
private var canBlankError: Boolean = false | ||
lateinit var overWarning: String | ||
var blankWarning: String = "" | ||
|
||
private val editTextStateMap by lazy { | ||
mapOf( | ||
EditTextState.SUCCESS to Triple( | ||
R.color.gray_700, | ||
R.drawable.shape_rect_4_gray700_line, | ||
"" | ||
), | ||
EditTextState.EMPTY to Triple( | ||
R.color.gray_200, | ||
R.drawable.shape_rect_4_gray200_line, | ||
"" | ||
), | ||
EditTextState.BLANK to Triple( | ||
R.color.red_500, | ||
R.drawable.shape_rect_4_red500_line, | ||
blankWarning | ||
), | ||
EditTextState.OVER to Triple( | ||
R.color.red_500, | ||
R.drawable.shape_rect_4_red500_line, | ||
overWarning | ||
), | ||
) | ||
} | ||
|
||
val editText | ||
get() = binding.etEmojiCounterEtContent | ||
|
||
var state: EditTextState = EditTextState.EMPTY | ||
set(value) { | ||
field = value | ||
|
||
binding.run { | ||
btnDeleteText.isVisible = | ||
(value != EditTextState.EMPTY) && etEmojiCounterEtContent.hasFocus() | ||
} | ||
|
||
editTextStateMap[field]?.let { setEditTextState(it) } | ||
} | ||
|
||
init { | ||
val typedArray = context.obtainStyledAttributes(attrs, R.styleable.EmojiCounterEditText) | ||
binding = ViewEmojiCounterEdittextMultilineBinding.inflate( | ||
LayoutInflater.from(context), | ||
this, | ||
true, | ||
) | ||
|
||
initDeleteBtnClickListener() | ||
setBindingContent(typedArray) | ||
initEtFocusChangeListener() | ||
|
||
typedArray.recycle() | ||
|
||
checkTextAvailable() | ||
} | ||
|
||
private fun initDeleteBtnClickListener() = with(binding) { | ||
btnDeleteText.setOnSingleClickListener { | ||
etEmojiCounterEtContent.text = null | ||
} | ||
} | ||
|
||
private fun setBindingContent(typedArray: TypedArray) { | ||
with(binding) { | ||
tvEmojiCounterEtTitle.text = | ||
typedArray.getString(R.styleable.EmojiCounterEditText_title) | ||
etEmojiCounterEtContent.hint = | ||
typedArray.getString(R.styleable.EmojiCounterEditText_hint) | ||
etEmojiCounterEtContent.minLines = | ||
typedArray.getInt(R.styleable.EmojiCounterEditText_minLines, 1) | ||
etEmojiCounterEtContent.maxLines = | ||
typedArray.getInt(R.styleable.EmojiCounterEditText_minLines, 2) | ||
etEmojiCounterEtContent.movementMethod = ScrollingMovementMethod() | ||
tvEmojiCounterEtNameCounter.text = context.getString(R.string.counter, 0, maxLen) | ||
} | ||
canBlankError = typedArray.getBoolean(R.styleable.EmojiCounterEditText_canBlankError, false) | ||
} | ||
|
||
private fun initEtFocusChangeListener() { | ||
binding.etEmojiCounterEtContent.onFocusChangeListener = | ||
OnFocusChangeListener { _, hasFocus -> | ||
binding.btnDeleteText.isVisible = hasFocus && (state != EditTextState.EMPTY) | ||
} | ||
} | ||
|
||
private fun checkTextAvailable() { | ||
binding.etEmojiCounterEtContent.doAfterTextChanged { text -> | ||
val len = text.toString().getGraphemeLength() | ||
|
||
state = when { | ||
text.toString().isBlank() && len != 0 && canBlankError -> EditTextState.BLANK | ||
len > maxLen -> EditTextState.OVER | ||
len > 0 -> EditTextState.SUCCESS | ||
else -> EditTextState.EMPTY | ||
} | ||
|
||
binding.tvEmojiCounterEtNameCounter.text = | ||
context.getString(R.string.counter, len, maxLen) | ||
} | ||
} | ||
|
||
fun setMaxLen(len: Int) { | ||
maxLen = len | ||
binding.tvEmojiCounterEtNameCounter.text = context.getString(R.string.counter, 0, maxLen) | ||
} | ||
|
||
private fun setEditTextState(info: Triple<Int, Int, String>) { | ||
val color = info.first | ||
val background = info.second | ||
val text = info.third | ||
|
||
with(binding) { | ||
tvEmojiCounterEtWarningMessage.isVisible = color == R.color.red_500 | ||
tvEmojiCounterEtNameCounter.setTextColor(context.colorOf(color)) | ||
etEmojiCounterEtContent.background = ResourcesCompat.getDrawable( | ||
this@EmojiCounterEditTextMultiLine.resources, | ||
background, | ||
context.theme, | ||
) | ||
tvEmojiCounterEtWarningMessage.text = text | ||
} | ||
} | ||
} |
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
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
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
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
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
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
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
14 changes: 10 additions & 4 deletions
14
presentation/src/main/res/drawable/shape_line_gray100_fill_dash_5_vertical.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 |
---|---|---|
@@ -1,5 +1,11 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<rotate xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:fromDegrees="90" | ||
android:toDegrees="90" | ||
android:drawable="@drawable/shape_line_gray100_fill_dash_5"/> | ||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<item | ||
android:left="-600dp" | ||
android:right="-600dp"> | ||
<rotate | ||
android:drawable="@drawable/shape_line_gray100_fill_dash_5" | ||
android:fromDegrees="90" | ||
android:visible="true" /> | ||
</item> | ||
</layer-list> |
Oops, something went wrong.