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/#15] tendency test splash 구현 #20

Merged
merged 6 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package com.going.presentation.onboarding

import android.os.Bundle
import android.view.inputmethod.EditorInfo
import android.widget.TextView
import androidx.activity.viewModels
import androidx.core.content.res.ResourcesCompat
import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
import com.going.domain.entity.NameState
Expand All @@ -21,10 +23,10 @@ class OnboardingProfileSettingActivity :

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

private fun initBindingViewModel() {
Expand All @@ -38,29 +40,71 @@ class OnboardingProfileSettingActivity :
}
}

private fun initSetOnFucusChangeListener() {
private fun initSetOnFocusChangeListener() {
binding.etOnboardingProfileSettingName.setOnFocusChangeListener { _, hasFocus ->
Comment on lines +43 to 44
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setOnFocusChangeListener 리스너도 있군요,,!

judgeCounterColorWithFocus(hasFocus)
setColors(
hasFocus,
viewModel.nowNameLength.value ?: 0,
binding.tvNameCounter,
) { background ->
binding.etOnboardingProfileSettingName.background = ResourcesCompat.getDrawable(
this.resources,
background,
theme,
)
}
}

binding.etOnboardingProfileSettingInfo.setOnFocusChangeListener { _, hasFocus ->
judgeCounterColorWithFocus(hasFocus)
setColors(
hasFocus,
viewModel.nowInfoLength.value ?: 0,
binding.tvInfoCounter,
) { background ->
binding.etOnboardingProfileSettingInfo.background = ResourcesCompat.getDrawable(
this.resources,
background,
theme,
)
}
}
}

private fun judgeCounterColorWithFocus(hasFocus: Boolean) {
if (hasFocus) {
setNameCounterColor(R.color.gray_700)
} else {
setNameCounterColor(R.color.gray_200)
private fun observeIsNameAvailable() {
viewModel.isNameAvailable.observe(this) { state ->
setColors(
false,
viewModel.nowNameLength.value ?: 0,
binding.tvNameCounter,
) { background ->
binding.etOnboardingProfileSettingName.background = ResourcesCompat.getDrawable(
this.resources,
background,
theme,
)
}
}
if (viewModel.isNameAvailable.value == NameState.Blank) {
setNameCounterColor(R.color.red_500)
}

private fun setColors(
hasFocus: Boolean,
length: Int,
counter: TextView,
setBackground: (Int) -> Unit,
) {
val (color, background) = when {
viewModel.isNameAvailable.value != NameState.Blank && hasFocus -> R.color.gray_700 to R.drawable.sel_rounded_corner_edit_text
length == 0 -> R.color.gray_200 to R.drawable.sel_rounded_corner_edit_text_empty
viewModel.isNameAvailable.value == NameState.Blank && counter == binding.tvNameCounter -> R.color.red_500 to R.drawable.sel_rounded_corner_edit_text_error
else -> R.color.gray_700 to R.drawable.sel_rounded_corner_edit_text
}

setCounterColor(counter, color)
setBackground(background)
}

private fun setNameCounterColor(color: Int) {
binding.tvNameCounter.setTextColor(getColor(color))
private fun setCounterColor(counter: TextView, color: Int) {
counter.setTextColor(getColor(color))
}

private fun observeIsProfileAvailable() {
Expand Down Expand Up @@ -94,15 +138,6 @@ class OnboardingProfileSettingActivity :
}
}

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

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

import android.os.Bundle
import com.going.presentation.R
import com.going.presentation.databinding.ActivityTendencyTestSplashBinding
import com.going.ui.base.BaseActivity
import com.going.ui.extension.setOnSingleClickListener

class TendencyTestActivity :
BaseActivity<ActivityTendencyTestSplashBinding>(R.layout.activity_tendency_test_splash) {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

initStartBtnSingleClickListener()
}

private fun initStartBtnSingleClickListener() {
binding.btnTendencySplashStart.setOnSingleClickListener {
// 페이지 이동~
}
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="false">
<item>
<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:width="1dp"/>
<stroke android:color="@color/gray_700"/>
<corners android:radius="4dp" />
</shape>
Expand Down
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>
<shape>
<stroke android:width="1dp"/>
<stroke android:color="@color/gray_200"/>
<corners android:radius="4dp" />
</shape>
</item>
</selector>
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="false">
<item>
<shape>
<stroke android:width="2dp"/>
<stroke android:width="1dp"/>
<stroke android:color="@color/red_500"/>
<corners android:radius="4dp" />
</shape>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
android:layout_marginHorizontal="24dp"
android:layout_marginTop="6dp"
android:afterTextChanged="@{(text) -> viewModel.checkProfileAvailable()}"
android:background="@{viewModel.isNameAvailable() == NameState.Blank ? @drawable/sel_rounded_corner_edit_text_error : @drawable/sel_rounded_corner_edit_text}"
android:background="@drawable/sel_rounded_corner_edit_text_empty"
android:hint="@string/onboarding_et_name_hint"
android:imeOptions="actionNext"
android:inputType="text"
Expand Down Expand Up @@ -95,7 +95,7 @@
android:layout_marginHorizontal="24dp"
android:layout_marginTop="6dp"
android:afterTextChanged="@{(text) -> viewModel.checkProfileAvailable()}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저도 데바 사용할 때 이렇게 함수 이용해서 해봐야겠어요

android:background="@drawable/sel_rounded_corner_edit_text"
android:background="@drawable/sel_rounded_corner_edit_text_empty"
android:hint="@string/onboarding_one_line_et_info"
android:imeOptions="actionDone"
android:inputType="text"
Expand All @@ -106,9 +106,11 @@
app:layout_constraintTop_toBottomOf="@id/tv_onboarding_profile_setting_on_line_info_title" />

<TextView
android:id="@+id/tv_info_counter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{@string/text_count(viewModel.nowInfoLength, viewModel.MAX_INFO_LEN)}"
android:textColor="@color/gray_200"
app:layout_constraintEnd_toEndOf="@id/et_onboarding_profile_setting_info"
app:layout_constraintTop_toBottomOf="@id/et_onboarding_profile_setting_info" />

Expand Down
54 changes: 54 additions & 0 deletions presentation/src/main/res/layout/activity_tendency_test_splash.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<data>

</data>

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white_000">

<TextView
android:id="@+id/tv_tendency_splash_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/tendency_splash_title"
android:gravity="center"
android:textColor="@color/gray_700"
android:layout_marginTop="236dp"
style="@style/TextAppearance.Doorip.Head3"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<!--더미 이미지의 크기가 너무 커서 임시로 크기를 지정했습니다. 추후 이미자가 나온다면 wrap_content 사용 예정-->
<ImageView
android:layout_width="200dp"
android:layout_height="126dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_tendency_splash_title"
android:layout_marginTop="10dp"
android:src="@drawable/img_sign_in_main" />

<androidx.appcompat.widget.AppCompatButton
android:id="@+id/btn_tendency_splash_start"
style="@style/button_style"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginHorizontal="24dp"
android:layout_marginBottom="22dp"
android:background="@drawable/sel_rounded_corner_button"
android:paddingVertical="10dp"
android:text="@string/tendency_splash_start_btn"
android:textColor="@color/white_000"
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
4 changes: 4 additions & 0 deletions presentation/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@
<string name="onboarding_one_line_et_info">당신을 한줄로 표현해보세요</string>
<string name="onboarding_finish_btn">유형 검사하러 가기</string>

<!--tendency_test_splash-->
<string name="tendency_splash_title">9개의 질문으로\n여행 성향을 분석해보세요</string>
<string name="tendency_splash_start_btn">시작하기</string>

</resources>
2 changes: 1 addition & 1 deletion presentation/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

<!-- Button Style -->
<style name="button_style" parent="Widget.AppCompat.Button">

<item name="android:textAppearance">@style/TextAppearance.Doorip.Body2.Bold</item>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오호 버튼 사용할 때 여기서 유용하게 쓰겠습니다!

<item name="android:buttonCornerRadius">46dp</item>
<item name="cornerRadius">40dp</item>
<item name="android:radius">40dp</item>
Expand Down