-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: develop
Are you sure you want to change the base?
The head ref may contain hidden characters: "feat/#16-\uC0DD\uB144\uC6D4\uC77C-\uC785\uB825-\uD654\uBA74"
Changes from 6 commits
ac5dbc6
329337a
8de06d5
92616d4
87787b5
7c59dcd
8962048
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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() { | ||
_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() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
이렇게 사용하면 코드 줄 수도 줄어들고 불필요한 괄호도 사라집니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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('-') && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ! 보단 뒤에 .not()을 사용하면 가독이 오르고 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?) { | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 비어있는 함수들은 |
||
|
||
}) | ||
} | ||
|
||
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() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() | ||
} | ||
} |
There was a problem hiding this comment.
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 도 없네요~!