Skip to content
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

[UI/#13] onboarding profile setting #14

Merged
merged 26 commits into from
Jan 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
89fb554
[ADD/#7] TextInputLayout custom style 추가
chattymin Dec 30, 2023
c78c6a3
[ADD/#7] Onboarding Profile 페이지 string 리소스 추가
chattymin Dec 30, 2023
eabbdf9
[UI/#7] Onboarding Profile 페이지 UI 와이어프레임 구현
chattymin Dec 30, 2023
076a94e
[FEAT/#7] 글자 수 검증 with 이모지, 공백
chattymin Dec 31, 2023
6a8b598
[FIX/#7] 버튼 검증과 입력값 유효성 검증이 다르던 코드 수정
chattymin Dec 31, 2023
6e4cccc
[ADD/#7] 텍스트박스 커서 색 변경
chattymin Dec 31, 2023
86bf4d9
[ADD/#13] hideKeyboard에 focus Clear 기능 추가
chattymin Dec 31, 2023
7c87fc7
[FEAT/#13] 버튼 연동 및 페이지 이동 함수 구현
chattymin Dec 31, 2023
0544c36
[FEAT/#13] 글자수 세기 커스텀 함수 구현
chattymin Dec 31, 2023
aad46aa
[UI/#13] 글자수 세기 string 리소스 생성 및 ui 구현
chattymin Dec 31, 2023
97de0bb
[MOD/#13] 글자수 검사 함수 리펙토링 및 변수명 수정
chattymin Dec 31, 2023
4f0844d
[CHORE/#13] xml 배경색 제거
chattymin Dec 31, 2023
774af30
Merge branch 'develop' into ui/#13-onboarding-profile-setting
chattymin Dec 31, 2023
8d82e62
[CHORE/#13] 정책 변경으로 인한 이름 최대 길이 수 변경
chattymin Jan 1, 2024
b6a6603
[UI/#13] Button radius 처리 및 색상 처리
chattymin Jan 1, 2024
7679e1f
[REFACTOR/#13] 입력창 UI 및 로직 전체 리펙토링 및 커스텀
chattymin Jan 1, 2024
03fe1eb
[UI/#13] 에러 외곽 테두리 색 변경
chattymin Jan 1, 2024
93f0536
[CHORE/#13] enum class 분리
chattymin Jan 1, 2024
a35d5fa
[CHORE/#13] 함수 로직 간략화
chattymin Jan 1, 2024
2e99854
[CHORE/#13] 변수명 변경
chattymin Jan 1, 2024
4f30c20
[CHORE/#13] 변수명 변경 및 불필요 내용 삭제
chattymin Jan 1, 2024
fd8150a
Merge remote-tracking branch 'origin/ui/#13-onboarding-profile-settin…
chattymin Jan 1, 2024
3297edb
[CHORE/#13] 실수로 삭제한 내용 복구
chattymin Jan 1, 2024
afcb5af
[CHORE/#13] 색상코드 변경 반영
chattymin Jan 1, 2024
f6d6187
[CHORE/#13] 변수명 변경
chattymin Jan 1, 2024
32fc59f
[CHORE/#13] 중복 내용 함수화 진행
chattymin Jan 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
</intent-filter>
</activity>

<activity
android:name="com.going.presentation.onboarding.OnboardingProfileSettingActivity"
android:exported="true" />

</application>

</manifest>
3 changes: 2 additions & 1 deletion core-ui/src/main/java/com/going/ui/extension/ContextExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ fun Context.drawableOf(@DrawableRes resId: Int) = ContextCompat.getDrawable(this
fun Context.hideKeyboard(view: View) {
val inputMethodManager = getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager
inputMethodManager.hideSoftInputFromWindow(view.windowToken, 0)
}
view.clearFocus()
}
5 changes: 5 additions & 0 deletions domain/src/main/kotlin/com/going/domain/entity/NameState.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.going.domain.entity

enum class NameState {
Empty, Success, Blank
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package com.going.presentation.onboarding

import android.os.Bundle
import android.view.inputmethod.EditorInfo
import androidx.activity.viewModels
import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
import com.going.domain.entity.NameState
import com.going.presentation.R
import com.going.presentation.databinding.ActivityOnboardingProfileSettingBinding
import com.going.ui.base.BaseActivity
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach

class OnboardingProfileSettingActivity :
BaseActivity<ActivityOnboardingProfileSettingBinding>(R.layout.activity_onboarding_profile_setting) {
private val viewModel by viewModels<OnboardingProfileSettingViewModel>()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

initBindingViewModel()
initOnLineInfoEditorActionListener()
initSetOnFucusChangeListener()
observeIsProfileAvailable()
observeTextLength()
observeIsNameAvailable()
}

private fun initBindingViewModel() {
binding.viewModel = viewModel
}

private fun initOnLineInfoEditorActionListener() {
binding.etOnboardingProfileSettingInfo.setOnEditorActionListener { view, actionId, _ ->
if (actionId == EditorInfo.IME_ACTION_DONE) view.clearFocus()
false
}
}

private fun initSetOnFucusChangeListener() {
binding.etOnboardingProfileSettingName.setOnFocusChangeListener { _, hasFocus ->
judgeCounterColorWithFocus(hasFocus)
}

binding.etOnboardingProfileSettingInfo.setOnFocusChangeListener { _, hasFocus ->
judgeCounterColorWithFocus(hasFocus)
}
}

private fun judgeCounterColorWithFocus(hasFocus: Boolean) {
if (hasFocus) {
setNameCounterColor(R.color.gray_700)
} else {
setNameCounterColor(R.color.gray_200)
}
if (viewModel.isNameAvailable.value == NameState.Blank) {
setNameCounterColor(R.color.red_400)
}
}

private fun setNameCounterColor(color: Int) {
binding.tvNameCounter.setTextColor(getColor(color))
}

private fun observeIsProfileAvailable() {
viewModel.isMoveScreenAvailable.flowWithLifecycle(lifecycle).onEach { isEnd ->
if (isEnd) moveSplash()
}.launchIn(lifecycleScope)
}

// 커스텀 글자수 제한 함수
private fun observeTextLength() {
viewModel.nowNameLength.observe(this) { length ->
val maxNameLength = viewModel.getMaxNameLen()

if (length > maxNameLength) {
binding.etOnboardingProfileSettingName.apply {
setText(text?.subSequence(0, maxNameLength))
setSelection(maxNameLength)
}
}
}

viewModel.nowInfoLength.observe(this) { length ->
val maxInfoLength = viewModel.getMaxInfoLen()

if (length > maxInfoLength) {
binding.etOnboardingProfileSettingInfo.apply {
setText(text?.subSequence(0, maxInfoLength))
setSelection(maxInfoLength)
}
}
}
}

private fun observeIsNameAvailable() {
viewModel.isNameAvailable.observe(this) { state ->
when (state) {
NameState.Blank -> binding.tvNameCounter.setTextColor(getColor(R.color.red_400))
else -> binding.tvNameCounter.setTextColor(getColor(R.color.gray_700))
}
}
}

private fun moveSplash() {
// 스플래시로 이동
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.going.presentation.onboarding

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.going.domain.entity.NameState
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import java.text.BreakIterator

class OnboardingProfileSettingViewModel : ViewModel() {
val name = MutableLiveData(String())
val nowNameLength = MutableLiveData(0)
val info = MutableLiveData(String())
val nowInfoLength = MutableLiveData(0)

val isNameAvailable = MutableLiveData(NameState.Empty)
val isProfileAvailable = MutableLiveData(false)

private val _isMoveScreenAvailable = MutableStateFlow(false)
val isMoveScreenAvailable: StateFlow<Boolean> = _isMoveScreenAvailable

fun getMaxNameLen() = MAX_NAME_LEN
fun getMaxInfoLen() = MAX_INFO_LEN

fun checkProfileAvailable() {
nowNameLength.value = getGraphemeLength(name.value)
nowInfoLength.value = getGraphemeLength(info.value)

isNameAvailable.value = when {
nowNameLength.value == 0 -> NameState.Empty
name.value.isNullOrBlank() -> NameState.Blank
else -> NameState.Success
}

val isInfoAvailable = getGraphemeLength(info.value) in 1..MAX_INFO_LEN

isProfileAvailable.value =
(isNameAvailable.value == NameState.Success) && isInfoAvailable
}

// 이모지 포함 글자 수 세는 함수
private fun getGraphemeLength(value: String?): Int {
BREAK_ITERATOR.setText(value)

var count = 0
while (BREAK_ITERATOR.next() != BreakIterator.DONE) {
count++
}

return count
}

fun setIsMoveScreenAvailable() {
_isMoveScreenAvailable.value = true
}

companion object {
val BREAK_ITERATOR: BreakIterator = BreakIterator.getCharacterInstance()

const val MAX_NAME_LEN = 3
const val MAX_INFO_LEN = 20
}
}
19 changes: 19 additions & 0 deletions presentation/src/main/res/drawable/sel_rounded_corner_button.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false">
<shape>
<corners android:radius="4dp" />
<solid android:color="@color/gray_200" />
</shape>
</item>

<!-- State Enabled -->
<item android:state_enabled="true">
<shape>
<corners android:radius="4dp" />
<solid android:color="@color/gray_500" />
</shape>
</item>

</selector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="false">
<shape>
<stroke android:width="2dp"/>
<stroke android:color="@color/gray_200"/>
<corners android:radius="4dp" />
</shape>
</item>
<item android:state_focused="true">
<shape>
<stroke android:width="2dp"/>
<stroke android:color="@color/gray_700"/>
<corners android:radius="4dp" />
</shape>
</item>
</selector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="false">
<shape>
<stroke android:width="2dp"/>
<stroke android:color="@color/red_400"/>
<corners android:radius="4dp" />
</shape>
</item>
</selector>
4 changes: 2 additions & 2 deletions presentation/src/main/res/layout/activity_login.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
android:gravity="center"
android:lineHeight="42dp"
android:text="@string/sign_in_tv_title"
android:textColor="@color/white"
android:textColor="@color/white_000"
app:layout_constraintBottom_toTopOf="@id/iv_sign_in"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
Expand Down Expand Up @@ -58,7 +58,7 @@
android:gravity="center"
android:lineHeight="42dp"
android:text="@string/sign_in_tv_terms"
android:textColor="@color/white"
android:textColor="@color/white_000"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/btn_sign_in" />
Expand Down
Loading