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,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 AgreeServiceConditionViewModel @Inject constructor(): BaseViewModel() {
private val _btnNext: SingleLiveEvent<Unit> = SingleLiveEvent()
val btnNext: LiveData<Unit> = _btnNext

fun onClickCheckButton() {
Copy link
Member

Choose a reason for hiding this comment

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

단순 button click 이벤트들은 databinding 을 지양하고
fragment에서 활용해주면 됩니다.
또한 observer 도 없네요~!

_btnNext.call()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
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()
}

override fun initObserver() {
Copy link
Member

Choose a reason for hiding this comment

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

with()을 사용할 땐

override fun initObserver) = with(viewModel){
.......
}

이렇게 사용하면 코드 줄 수도 줄어들고 불필요한 괄호도 사라집니다.

Copy link
Member Author

Choose a reason for hiding this comment

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

넵! 바로 반영하겠습니다!

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('-') &&
Copy link
Member

Choose a reason for hiding this comment

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

! 보단 뒤에 .not()을 사용하면 가독이 오르고
또한 각 숫자들이 의미하는 바가 뭔지 알기 어렵습니다.
매직넘버들은 상수화 해줘요~!

Copy link
Member Author

Choose a reason for hiding this comment

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

오옹! 그렇군요! 바로 수정하겠습니다!

!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?) {
}
Copy link
Member

Choose a reason for hiding this comment

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

비어있는 함수들은 = Unit 처리해주면 좋습니다.


})
}

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
@@ -0,0 +1,27 @@
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() {
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() {
Copy link
Member

Choose a reason for hiding this comment

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

여기도 이벤트 그냥 activity, fragment 에서 하도록 해줘요~!

_btnNext.call()
}

fun onClickBackButton() {
_btnBack.call()
}
}
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