Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/Team-Going/Going-Android
Browse files Browse the repository at this point in the history
…into fix/#265-2nd-2nd-todo-qa
  • Loading branch information
Marchbreeze committed Mar 21, 2024
2 parents 0153773 + 35a0a02 commit a1798de
Show file tree
Hide file tree
Showing 12 changed files with 261 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.going.presentation.designsystem.edittext

import android.content.Context
import android.content.res.TypedArray
import android.text.InputType
import android.text.method.ScrollingMovementMethod
import android.util.AttributeSet
import android.view.LayoutInflater
Expand Down
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
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ class ProfileEditActivity :

private fun observeNameTextChanged() {
binding.etProfileEditNickname.editText.doAfterTextChanged { name ->
viewModel.checkIsNameChanged(name.toString())
viewModel.checkIsNameChanged(name.toString(), binding.etProfileEditNickname.state, binding.etProfileEditInfo.state)
}
}

private fun observeInfoTextChanged() {
binding.etProfileEditInfo.editText.doAfterTextChanged { info ->
viewModel.checkIsInfoChanged(info.toString())
viewModel.checkIsInfoChanged(info.toString(), binding.etProfileEditNickname.state, binding.etProfileEditInfo.state)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.going.domain.entity.request.UserProfileRequestModel
import com.going.domain.repository.ProfileRepository
import com.going.presentation.designsystem.edittext.EditTextState
import com.going.presentation.onboarding.signup.SignUpViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableSharedFlow
Expand Down Expand Up @@ -40,23 +41,23 @@ class ProfileEditViewModel @Inject constructor(
defaultInfo = info
}

fun checkIsNameChanged(name: String) {
fun checkIsNameChanged(name: String, nameState: EditTextState, infoState: EditTextState) {
nowName = name
isNameChanged = name != defaultName

checkIsValueChanged()
checkIsValueChanged(nameState, infoState)
}

fun checkIsInfoChanged(info: String) {
fun checkIsInfoChanged(info: String, nameState: EditTextState, infoState: EditTextState) {
nowInfo = info
isInfoChanged = info != defaultInfo

checkIsValueChanged()
checkIsValueChanged(nameState, infoState)
}

private fun checkIsValueChanged() {
private fun checkIsValueChanged(nameState: EditTextState, infoState: EditTextState) {
_isValueChanged.value =
nowName.isNotBlank() && nowName.length <= getMaxNameLen() && nowInfo.isNotBlank() && nowInfo.length <= getMaxInfoLen() && (isInfoChanged || isNameChanged)
nowName.isNotBlank() && nameState == EditTextState.SUCCESS && nowInfo.isNotBlank() && infoState == EditTextState.SUCCESS && (isInfoChanged || isNameChanged)
}

fun patchUserInfo() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ class ParticipantProfileActivity :
}
}

setFragmentHeight(profile.result == -1)

tvProfileName.text = profile.name
tvProfileOneLine.text = profile.intro

Expand Down Expand Up @@ -149,15 +151,15 @@ class ParticipantProfileActivity :
setFragmentHeight()
}

private fun setFragmentHeight(temp: Boolean = true) {
private fun setFragmentHeight(isEmpty: Boolean = true) {
val displayHeight = getWindowHeight()
val toolbarHeight = binding.tbTripProfile.height
val appBarHeight = binding.appbarTripProfile.totalScrollRange
val tabHeight = binding.tabTripProfile.height

binding.vpTripProfile.layoutParams = binding.vpTripProfile.layoutParams.also {
it.height =
if (temp) displayHeight - toolbarHeight - appBarHeight - tabHeight else displayHeight - toolbarHeight - tabHeight
if (isEmpty) displayHeight - toolbarHeight - appBarHeight - tabHeight else displayHeight - toolbarHeight - tabHeight
}
}

Expand Down
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>
5 changes: 3 additions & 2 deletions presentation/src/main/res/layout/activity_profile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,12 @@
<TextView
android:id="@+id/tv_profile_one_line"
style="@style/TextAppearance.Doorip.Detail1.Regular"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="start"
android:layout_marginTop="3dp"
android:gravity="start"
android:textColor="@color/gray_500"
app:layout_constraintEnd_toStartOf="@+id/btn_profile_edit"
app:layout_constraintStart_toStartOf="@id/tv_profile_name"
app:layout_constraintTop_toBottomOf="@id/tv_profile_name"
tools:text="@string/profile_tv_one_line" />
Expand Down
2 changes: 1 addition & 1 deletion presentation/src/main/res/layout/activity_todo_change.xml
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@

</LinearLayout>

<com.going.presentation.designsystem.edittext.EmojiCounterEditText
<com.going.presentation.designsystem.edittext.EmojiCounterEditTextMultiLine
android:id="@+id/et_todo_create_memo"
android:layout_width="0dp"
android:layout_height="wrap_content"
Expand Down
2 changes: 1 addition & 1 deletion presentation/src/main/res/layout/activity_todo_create.xml
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@

</LinearLayout>

<com.going.presentation.designsystem.edittext.EmojiCounterEditText
<com.going.presentation.designsystem.edittext.EmojiCounterEditTextMultiLine
android:id="@+id/et_todo_create_memo"
android:layout_width="0dp"
android:layout_height="wrap_content"
Expand Down
16 changes: 8 additions & 8 deletions presentation/src/main/res/layout/view_chart_textview.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,33 @@
android:layout_height="wrap_content"
android:gravity="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/linear_layout_chart_description"
app:layout_constraintHorizontal_weight="2"
app:layout_constraintEnd_toStartOf="@id/img_chart_dash_vertical"
app:layout_constraintHorizontal_weight="2.6"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<ImageView
android:id="@+id/img_chart_dash_vertical"
android:layout_width="100dp"
android:layout_width="1dp"
android:layout_height="0dp"
android:background="@drawable/shape_line_gray100_fill_dash_4_vertical"
android:background="@drawable/shape_line_gray100_fill_dash_5_vertical"
android:layerType="software"
android:layout_marginHorizontal="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/linear_layout_chart_description"
app:layout_constraintHorizontal_weight="1"
app:layout_constraintHorizontal_weight="0.6"
app:layout_constraintStart_toEndOf="@id/tv_chart_title"
app:layout_constraintTop_toTopOf="parent" />

<LinearLayout
android:id="@+id/linear_layout_chart_description"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginStart="26dp"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_weight="7"
app:layout_constraintStart_toEndOf="@id/tv_chart_title"
app:layout_constraintHorizontal_weight="6.8"
app:layout_constraintStart_toEndOf="@id/img_chart_dash_vertical"
app:layout_constraintTop_toTopOf="parent">

<TextView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
android:background="@drawable/shape_rect_4_gray200_line"
android:gravity="top"
android:includeFontPadding="false"
android:inputType="textMultiLine"
android:inputType="text"
android:lineSpacingMultiplier="1.2"
android:overScrollMode="always"
android:paddingVertical="20dp"
Expand Down
Loading

0 comments on commit a1798de

Please sign in to comment.