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

Feat/#16 생년월일 입력 화면 #42

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
@@ -1,6 +1,9 @@
package com.owori.android.presenter.policy


import android.text.Editable
import android.text.TextWatcher
import androidx.core.content.ContextCompat
import androidx.fragment.app.viewModels
import com.owori.android.R
import com.owori.android.core.BaseFragment
Expand All @@ -17,14 +20,91 @@ class BirthDateFragment : BaseFragment<FragmentBirthDateBinding, BirthDateViewMo
}

override fun initView() {

initTextWatcher()
}

override fun initObserver() {
with(viewModel) {
btnNext.observe(viewLifecycleOwner) {
navigateTo(R.id.action_birthDateFragment_to_familyConnectFragment)
}

birthDate.observe(viewLifecycleOwner) {
val verify = it.split("-")
if(verify.size == 3) {
if(verify[0].length == 4 && verify[1].length == 2 && verify[2].length == 2) {
setButtonEnableTrue()
} else {
setButtonEnableFalse()
}
} else {
setButtonEnableFalse()
}
}

btnBack.observe(viewLifecycleOwner) {
requireActivity().onBackPressedDispatcher.onBackPressed()
}
}
}

private fun initTextWatcher() {
binding.birthdateEt.addTextChangedListener(object : TextWatcher {
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
}
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
var textlength = 0
if(binding.birthdateEt.isFocusable && s.toString() != "") {
try{
textlength = binding.birthdateEt.text.toString().length
}catch (e: NumberFormatException){
e.printStackTrace()
return
}
if (textlength == 4 && before != 1) {
val date = binding.birthdateEt.text.toString()+"-"
binding.birthdateEt.setText(date)
binding.birthdateEt.setSelection(binding.birthdateEt.text.length)

}else if (textlength == 7&& before != 1){
val date = binding.birthdateEt.text.toString()+"-"
binding.birthdateEt.setText(date)
binding.birthdateEt.setSelection(binding.birthdateEt.text.length)

}else if(textlength == 5 && !binding.birthdateEt.text.toString().contains("-") &&
!binding.birthdateEt.text.toString().substring(0,4).contains('-')){
val date = binding.birthdateEt.text.toString().substring(0,4)+"-"+binding.birthdateEt.text.toString().substring(4)
binding.birthdateEt.setText(date)
binding.birthdateEt.setSelection(binding.birthdateEt.text.length)

}else if(textlength == 8 && binding.birthdateEt.text.toString().substring(7,8) != "-" &&
!binding.birthdateEt.text.toString().substring(0,4).contains('-') &&
!binding.birthdateEt.text.toString().substring(5,8).contains('-') &&
!binding.birthdateEt.text.toString().substring(5).contains('-')){
val date = binding.birthdateEt.text.toString().substring(0,7)+"-"+binding.birthdateEt.text.toString().substring(7)
binding.birthdateEt.setText(date)
binding.birthdateEt.setSelection(binding.birthdateEt.text.length)
}
}
}

override fun afterTextChanged(s: Editable?) {
}

})
}

private fun setButtonEnableTrue() {
with(binding.viewpagerButton) {
isEnabled = true
setTextColor(ContextCompat.getColor(requireContext(), R.color.white))
}
}

private fun setButtonEnableFalse() {
with(binding.viewpagerButton) {
isEnabled = false
setTextColor(ContextCompat.getColor(requireContext(), R.color.grey_909090))
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.owori.android.presenter.policy

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.owori.android.core.BaseViewModel
import com.owori.android.presenter.util.SingleLiveEvent
import dagger.hilt.android.lifecycle.HiltViewModel
Expand All @@ -10,8 +11,17 @@ import javax.inject.Inject
class BirthDateViewModel @Inject constructor(): BaseViewModel() {
private val _btnNext: SingleLiveEvent<Unit> = SingleLiveEvent()
val btnNext: LiveData<Unit> = _btnNext
private val _btnBack: SingleLiveEvent<Unit> = SingleLiveEvent()
val btnBack: LiveData<Unit> = _btnBack

val _birthDate: MutableLiveData<String> = MutableLiveData("")
val birthDate: LiveData<String> = _birthDate

fun onClickCheckButton() {
_btnNext.call()
}

fun onClickBackButton() {
_btnBack.call()
}
}
216 changes: 209 additions & 7 deletions app/src/main/res/layout/fragment_birth_date.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">

<data>

Expand All @@ -14,24 +14,226 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".presenter.policy.BirthDateFragment">

<ImageButton
android:id="@+id/back_button"
android:layout_width="wrap_content"
android:layout_height="?attr/actionBarSize"
android:layout_marginStart="5dp"
android:adjustViewBounds="true"
android:background="@android:color/transparent"
android:onClick="@{()->vm.onClickBackButton()}"
android:src="@drawable/arrow_back"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/indicator_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="70dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<ImageView
android:id="@+id/first_indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/unfocused_nickname"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<View
android:id="@+id/first_nav_line"
android:layout_width="6dp"
android:layout_height="5dp"
android:layout_marginHorizontal="1.5dp"
android:background="@drawable/navigation_line"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/first_indicator"
app:layout_constraintTop_toTopOf="parent" />

<View
android:id="@+id/second_nav_line"
android:layout_width="10dp"
android:layout_height="4dp"
android:layout_marginHorizontal="1.5dp"
android:background="@drawable/navigation_line"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/first_nav_line"
app:layout_constraintTop_toTopOf="parent" />


<ImageView
android:id="@+id/second_indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="1.5dp"
android:src="@drawable/focused_birthdate"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@id/second_nav_line"
app:layout_constraintTop_toTopOf="parent" />

<View
android:id="@+id/third_nav_line"
android:layout_width="10dp"
android:layout_height="4dp"
android:layout_marginHorizontal="1.5dp"
android:background="@drawable/navigation_line"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/second_indicator"
app:layout_constraintTop_toTopOf="parent" />

<View
android:id="@+id/fourth_nav_line"
android:layout_width="10dp"
android:layout_height="4dp"
android:layout_marginHorizontal="1.5dp"
android:background="@drawable/navigation_line"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/third_nav_line"
app:layout_constraintTop_toTopOf="parent" />

<ImageView
android:id="@+id/third_indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="1.5dp"
android:src="@drawable/unfocused_connect"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/fourth_nav_line"
app:layout_constraintTop_toTopOf="parent" />

<View
android:id="@+id/fifth_nav_line"
android:layout_width="10dp"
android:layout_height="4dp"
android:layout_marginHorizontal="1.5dp"
android:background="@drawable/navigation_line"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/third_indicator"
app:layout_constraintTop_toTopOf="parent" />

<View
android:id="@+id/sixth_nav_line"
android:layout_width="10dp"
android:layout_height="4dp"
android:layout_marginHorizontal="1.5dp"
android:background="@drawable/navigation_line"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/fifth_nav_line"
app:layout_constraintTop_toTopOf="parent" />

<ImageView
android:id="@+id/fourth_indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="1.5dp"
android:src="@drawable/unfocused_group"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/fifth_nav_line"
app:layout_constraintTop_toTopOf="parent" />

<View
android:id="@+id/seventh_nav_line"
android:layout_width="10dp"
android:layout_height="4dp"
android:layout_marginHorizontal="1.5dp"
android:background="@drawable/navigation_line"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/fourth_indicator"
app:layout_constraintTop_toTopOf="parent" />

<View
android:id="@+id/eighth_nav_line"
android:layout_width="10dp"
android:layout_height="4dp"
android:layout_marginHorizontal="1.5dp"
android:background="@drawable/navigation_line"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/seventh_nav_line"
app:layout_constraintTop_toTopOf="parent" />


<ImageView
android:id="@+id/fifth_indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="1.5dp"
android:src="@drawable/unfocused_agree"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/eighth_nav_line"
app:layout_constraintTop_toTopOf="parent" />


</androidx.constraintlayout.widget.ConstraintLayout>

<TextView
android:id="@+id/birthdate_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginVertical="18dp"
android:layout_marginStart="20dp"
android:includeFontPadding="false"
android:textAppearance="@style/TextTitle.00"
android:text="@string/birthdate_title"
android:textColor="@color/black"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:text="생일 입력 화면"/>
app:layout_constraintTop_toBottomOf="@id/indicator_layout" />

<TextView
android:id="@+id/birthdate_subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:textAppearance="@style/TextBodyMedium.01"
android:includeFontPadding="false"
android:text="@string/birthdate_subtitle"
android:textColor="@color/grey_909090"
app:layout_constraintStart_toStartOf="@id/birthdate_title"
app:layout_constraintTop_toBottomOf="@id/birthdate_title" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:textAppearance="@style/TextBodyRegular.01"
android:textColor="@color/grey_787878"
android:includeFontPadding="false"
android:text="@string/birthdate_edittext_title"
app:layout_constraintBottom_toBottomOf="@id/birthdate_et"
app:layout_constraintStart_toStartOf="@id/birthdate_et"
app:layout_constraintTop_toTopOf="@id/birthdate_et" />

<EditText
android:id="@+id/birthdate_et"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="20dp"
android:layout_marginTop="48dp"
android:textAppearance="@style/TextBodyMedium.01"
android:includeFontPadding="false"
android:inputType="number"
android:lines="1"
android:maxLength="10"
android:maxLines="1"
android:paddingHorizontal="70dp"
android:text="@={vm._birthDate}"
app:layout_constraintTop_toBottomOf="@+id/birthdate_subtitle"
tools:layout_editor_absoluteX="20dp" />

<Button
android:id="@+id/viewpager_button"
android:layout_width="match_parent"
android:layout_height="64dp"
android:background="@drawable/check_btn_ripple"
android:enabled="false"
android:onClick="@{()-> vm.onClickCheckButton()}"
android:paddingVertical="3dp"
android:text="@string/policy_check"
android:textAppearance="@style/TextSubTitle.01"
android:textColor="@color/white"
android:textColor="@color/grey_909090"
app:layout_constraintBottom_toBottomOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<string name="nickname_edittext_title">닉네임</string>
<string name="nickname_edittext_hint"><font size="16">숫자, 특수문자, 이모티콘 모두 사용 가능</font></string>
<string name="nickname_length_limit">/7</string>
<string name="birthdate_title">생년월일 8자리를 입력해주세요</string>
<string name="birthdate_title">생년월일 8자리를\n입력해주세요</string>
<string name="birthdate_subtitle">원활한 서비스를 위해 생년월일이 필요해요\n매년 오월이가 생일을 챙겨줄게요!</string>
<string name="birthdate_edittext_title">생년월일</string>
<string name="family_group_title">우리 가족\n그룹명을 정해주세요</string>
Expand Down