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 생년월일 입력 화면 #39

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
android:exported="true"
android:screenOrientation="portrait"
android:label="@string/app_name"
android:theme="@style/Theme.Owori">
android:theme="@style/Theme.Owori"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ class LoginFragment : BaseFragment<FragmentLoginBinding, LoginViewModel>(R.layou
with(viewModel) {
// TODO : PolicyFragment를 위해 작성한 부분이라 수정 필요.
callKakaoLogin.observe(viewLifecycleOwner) {
navigateTo(R.id.action_loginFragment_to_PolicyFragment)
navigateTo(R.id.action_LoginFragment_to_nickNameFragment)
}

callGoogleLogin.observe(viewLifecycleOwner) {
navigateTo(R.id.action_loginFragment_to_PolicyFragment)
navigateTo(R.id.action_LoginFragment_to_nickNameFragment)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.owori.android.presenter.policy

import androidx.fragment.app.viewModels
import com.owori.android.R
import com.owori.android.core.BaseFragment
import com.owori.android.databinding.FragmentAgreeServiceConditionBinding

class AgreeServiceConditionFragment : BaseFragment<FragmentAgreeServiceConditionBinding, AgreeServiceConditionViewModel>(R.layout.fragment_agree_service_condition) {
override val viewModel: AgreeServiceConditionViewModel by viewModels()
override fun setBindingVariables() {
with(binding) {
vm = viewModel
}
}

override fun initView() {

}

override fun initObserver() {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.owori.android.presenter.policy

import androidx.lifecycle.LiveData
import com.owori.android.core.BaseViewModel
import com.owori.android.presenter.util.SingleLiveEvent
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class AgreeServiceConditionViewModel @Inject constructor(): BaseViewModel() {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
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
import com.owori.android.core.navigateTo
import com.owori.android.databinding.FragmentBirthDateBinding


class BirthDateFragment : BaseFragment<FragmentBirthDateBinding, BirthDateViewModel>(R.layout.fragment_birth_date) {
override val viewModel: BirthDateViewModel by viewModels()
override fun setBindingVariables() {
with(binding) {
vm = viewModel
}
}

override fun initView() {
initTextWatcher()
initClickListener()
}

override fun initObserver() = with(viewModel) {
birthDate.observe(viewLifecycleOwner) {
val verify = it.split(HYPHEN)
if(verify.size == VERIFY_BIRTHDATE_PARTITION) {
if(verify[BIRTHDATE_YEAR_PART].length == YEAR_LENGTH && verify[BIRTHDATE_MONTH_PART].length == MONTH_LENGTH &&
verify[BIRTHDATE_DAY_PART].length == DAY_LENGTH) {
setButtonEnableTrue()
} else {
setButtonEnableFalse()
}
} else {
setButtonEnableFalse()
}
}
}
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().isNotBlank()) {
try{
textlength = binding.birthdateEt.text.toString().length
}catch (e: NumberFormatException){
e.printStackTrace()
return
}
if (textlength == YEAR_LENGTH && before != TEXT_BEFORE) {
val date = binding.birthdateEt.text.toString()+HYPHEN
binding.birthdateEt.setText(date)
binding.birthdateEt.setSelection(binding.birthdateEt.text.length)

}else if (textlength == BIRTH_DATE_CONTAIN_MONTH_LENGTH && before != TEXT_BEFORE){
val date = binding.birthdateEt.text.toString()+HYPHEN
binding.birthdateEt.setText(date)
binding.birthdateEt.setSelection(binding.birthdateEt.text.length)

}else if(textlength == YEAR_CONTAIN_HYPHEN_LENGTH && !binding.birthdateEt.text.toString().contains(HYPHEN) &&
binding.birthdateEt.text.toString().substring(BIRTHDATE_START, YEAR_LENGTH).contains(HYPHEN).not()){
val date = binding.birthdateEt.text.toString().substring(BIRTHDATE_START, YEAR_LENGTH) +
HYPHEN + binding.birthdateEt.text.toString().substring(YEAR_LENGTH)
binding.birthdateEt.setText(date)
binding.birthdateEt.setSelection(binding.birthdateEt.text.length)

}else if(textlength == MONTH_CONTAIN_HYPHEN_LENGTH &&
binding.birthdateEt.text.toString().substring(BIRTH_DATE_CONTAIN_MONTH_LENGTH, MONTH_CONTAIN_HYPHEN_LENGTH) != HYPHEN &&
binding.birthdateEt.text.toString().substring(BIRTHDATE_START,YEAR_LENGTH).contains(HYPHEN).not() &&
binding.birthdateEt.text.toString().substring(YEAR_CONTAIN_HYPHEN_LENGTH,MONTH_CONTAIN_HYPHEN_LENGTH).contains(HYPHEN).not() &&
binding.birthdateEt.text.toString().substring(YEAR_CONTAIN_HYPHEN_LENGTH).contains(HYPHEN).not()){
val date = binding.birthdateEt.text.toString().substring(BIRTHDATE_START,BIRTH_DATE_CONTAIN_MONTH_LENGTH) +
HYPHEN+binding.birthdateEt.text.toString().substring(BIRTH_DATE_CONTAIN_MONTH_LENGTH)
binding.birthdateEt.setText(date)
binding.birthdateEt.setSelection(binding.birthdateEt.text.length)
}
}
}

override fun afterTextChanged(s: Editable?) = Unit
})
}

private fun initClickListener() {
binding.viewpagerButton.setOnClickListener {
navigateTo(R.id.action_birthDateFragment_to_familyConnectFragment)
}
binding.backButton.setOnClickListener {
requireActivity().onBackPressedDispatcher.onBackPressed()
}
}
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))
}
}

companion object {
private const val TEXT_BEFORE = 1
private const val BIRTHDATE_START = 0
private const val YEAR_LENGTH = 4
private const val BIRTH_DATE_CONTAIN_MONTH_LENGTH = 7
private const val MONTH_CONTAIN_HYPHEN_LENGTH = 8
private const val YEAR_CONTAIN_HYPHEN_LENGTH = 5
private const val VERIFY_BIRTHDATE_PARTITION = 3
private const val BIRTHDATE_YEAR_PART = 0
private const val BIRTHDATE_MONTH_PART = 1
private const val BIRTHDATE_DAY_PART = 2
private const val MONTH_LENGTH = 2
private const val DAY_LENGTH = 2
private const val HYPHEN = "-"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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
import javax.inject.Inject

@HiltViewModel
class BirthDateViewModel @Inject constructor(): BaseViewModel() {
val _birthDate: MutableLiveData<String> = MutableLiveData("")
val birthDate: LiveData<String> = _birthDate
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.owori.android.presenter.policy


import androidx.fragment.app.viewModels
import com.owori.android.R
import com.owori.android.core.BaseFragment
import com.owori.android.core.navigateTo
import com.owori.android.databinding.FragmentFamilyConnectBinding


class FamilyConnectFragment : BaseFragment<FragmentFamilyConnectBinding, FamilyConnectViewModel>(R.layout.fragment_family_connect) {
override val viewModel: FamilyConnectViewModel by viewModels()
override fun setBindingVariables() {
with(binding) {
vm = viewModel
}
}

override fun initView() {

}

override fun initObserver() {
with(viewModel) {
returnLogin.observe(viewLifecycleOwner) {
navigateTo(R.id.action_familyConnectFragment_to_inputFamilyCodeFragment)
}
btnNext.observe(viewLifecycleOwner) {
navigateTo(R.id.action_familyConnectFragment_to_groupFragment)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.owori.android.presenter.policy

import androidx.lifecycle.LiveData
import com.owori.android.core.BaseViewModel
import com.owori.android.presenter.util.SingleLiveEvent
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class FamilyConnectViewModel @Inject constructor(): BaseViewModel() {

private val _btnNext: SingleLiveEvent<Unit> = SingleLiveEvent()
val btnNext: LiveData<Unit> = _btnNext
private val _returnLogin: SingleLiveEvent<Unit> = SingleLiveEvent()
val returnLogin: LiveData<Unit> = _returnLogin

fun onClickCheckButton() {
_btnNext.call()
}

fun onClickBackButton() {
_returnLogin.call()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.owori.android.presenter.policy


import androidx.fragment.app.viewModels
import com.owori.android.R
import com.owori.android.core.BaseFragment
import com.owori.android.core.navigateTo
import com.owori.android.databinding.FragmentGroupBinding


class GroupFragment : BaseFragment<FragmentGroupBinding, GroupViewModel>(R.layout.fragment_group) {
override val viewModel: GroupViewModel by viewModels()
override fun setBindingVariables() {
with(binding) {
vm = viewModel
}
}

override fun initView() {

}

override fun initObserver() {
with(viewModel) {
btnNext.observe(viewLifecycleOwner) {
navigateTo(R.id.action_groupFragment_to_shareCodeFragment)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.owori.android.presenter.policy

import androidx.lifecycle.LiveData
import com.owori.android.core.BaseViewModel
import com.owori.android.presenter.util.SingleLiveEvent
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class GroupViewModel @Inject constructor(): BaseViewModel() {
private val _btnNext: SingleLiveEvent<Unit> = SingleLiveEvent()
val btnNext: LiveData<Unit> = _btnNext

fun onClickCheckButton() {
_btnNext.call()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.owori.android.presenter.policy


import androidx.fragment.app.viewModels
import com.owori.android.R
import com.owori.android.core.BaseFragment
import com.owori.android.core.navigateTo
import com.owori.android.databinding.FragmentInputFamilyCodeBinding


class InputFamilyCodeFragment : BaseFragment<FragmentInputFamilyCodeBinding, InputFamilyCodeViewModel>(R.layout.fragment_input_family_code) {
override val viewModel: InputFamilyCodeViewModel by viewModels()
override fun setBindingVariables() {
with(binding) {
vm = viewModel
}
}

override fun initView() {

}

override fun initObserver() {
with(viewModel) {
btnNext.observe(viewLifecycleOwner) {
navigateTo(R.id.action_inputFamilyCodeFragment_to_agreeServiceConditionFragment)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.owori.android.presenter.policy

import androidx.lifecycle.LiveData
import com.owori.android.core.BaseViewModel
import com.owori.android.presenter.util.SingleLiveEvent
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class InputFamilyCodeViewModel @Inject constructor(): BaseViewModel() {
private val _btnNext: SingleLiveEvent<Unit> = SingleLiveEvent()
val btnNext: LiveData<Unit> = _btnNext

fun onClickCheckButton() {
_btnNext.call()
}
}
Loading