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

회원가입쪽 Refactoring #71

Merged
merged 1 commit into from
Jul 5, 2023
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 @@ -14,8 +14,6 @@ import com.teampophory.pophory.feature.signup.adapter.SignUpViewPagerAdapter
class SignUpActivity : AppCompatActivity(), SignUpButtonInterface {

private val binding by viewBinding(ActivitySignUpBinding::inflate)
private lateinit var viewPager: ViewPager2
private lateinit var viewPagerAdapter: SignUpViewPagerAdapter

private val viewModel by viewModels<SignUpViewModel>()
private var currentPosition = 0
Expand All @@ -29,11 +27,11 @@ class SignUpActivity : AppCompatActivity(), SignUpButtonInterface {
toast(it)
}

//다음 버튼
// 다음 버튼
clickNextButton()
//뷰페이저
// 뷰페이저
setViewPager()
//백버튼 클릭
// 백버튼 클릭
clickToolbarBackButton()
}

Expand Down Expand Up @@ -63,15 +61,14 @@ class SignUpActivity : AppCompatActivity(), SignUpButtonInterface {
binding.btnNext.setOnClickListener {
when (currentPosition) {
0 -> {
val nextPosition = currentPosition + 1
binding.viewpager.currentItem = nextPosition
binding.viewpager.currentItem = currentPosition + 1
}

1 -> {
//todo 중복된 아이디가 존재하는 경우
// TODO 중복된 아이디가 존재하는 경우
val dialog = SignUpDialogFragment()
dialog.show(supportFragmentManager, "")
//중복된 아이디가 존재하지 않을 경우
// 중복된 아이디가 존재하지 않을 경우
// val nextPosition = currentPosition + 1
// binding.viewpager.currentItem = nextPosition
}
Expand All @@ -86,17 +83,13 @@ class SignUpActivity : AppCompatActivity(), SignUpButtonInterface {


private val pageChangeCallback = object : ViewPager2.OnPageChangeCallback() {
override fun onPageScrollStateChanged(state: Int) {
super.onPageScrollStateChanged(state)
}

override fun onPageScrolled(
position: Int,
positionOffset: Float,
positionOffsetPixels: Int
) {
super.onPageScrolled(position, positionOffset, positionOffsetPixels)
//tablayout 변경
// tablayout 변경
with(binding) {
tabFirst.isSelected = position == 0
tabSecond.isSelected = position == 1
Expand All @@ -118,22 +111,19 @@ class SignUpActivity : AppCompatActivity(), SignUpButtonInterface {
}

private fun setViewPager() {
viewPagerAdapter = SignUpViewPagerAdapter(this, this)
viewPager = binding.viewpager

viewPager.apply {
adapter = viewPagerAdapter
binding.viewpager.apply {
adapter = SignUpViewPagerAdapter(this@SignUpActivity, this@SignUpActivity)
isUserInputEnabled = false
}
viewPager.registerOnPageChangeCallback(pageChangeCallback)
binding.viewpager.registerOnPageChangeCallback(pageChangeCallback)
}

private fun setButton(buttonText: String, isEnabled: Boolean) {
binding.btnNext.text = buttonText
binding.btnNext.isEnabled = isEnabled
}

override fun setButtonState(state: Boolean) {
override fun onChangeState(state: Boolean) {
binding.btnNext.isEnabled = state
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.teampophory.pophory.feature.signup

interface SignUpButtonInterface {
fun setButtonState(state : Boolean)
}
fun interface SignUpButtonInterface {
fun onChangeState(state: Boolean)
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,26 @@ import android.graphics.Point
import android.graphics.drawable.ColorDrawable
import android.os.Build
import android.os.Bundle
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.WindowInsets
import android.view.WindowManager
import androidx.fragment.app.DialogFragment
import com.teampophory.pophory.R
import com.teampophory.pophory.common.view.dp
import com.teampophory.pophory.common.view.viewBinding
import com.teampophory.pophory.databinding.FragmentSignUpDialogBinding

class SignUpDialogFragment : DialogFragment() {
private val binding by viewBinding(FragmentSignUpDialogBinding::bind)

private var _binding: FragmentSignUpDialogBinding? = null
private val binding get() = _binding!!

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
_binding = FragmentSignUpDialogBinding.inflate(inflater, container, false)
val view = binding.root
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
// 레이아웃 배경을 투명하게 해줌
dialog?.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
return view
return FragmentSignUpDialogBinding.inflate(inflater, container, false).root
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
Expand All @@ -45,6 +43,7 @@ class SignUpDialogFragment : DialogFragment() {
dialogWidthPercent(it, dialog)
}
}

private fun dialogWidthPercent(context: Context, dialog: Dialog?, percent: Double = 0.8) {
val deviceSize = getDeviceSize(context)
dialog?.window?.run {
Expand Down Expand Up @@ -79,9 +78,4 @@ class SignUpDialogFragment : DialogFragment() {
return intArrayOf(size.x, size.y)
}
}

override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
}
}
Original file line number Diff line number Diff line change
@@ -1,49 +1,40 @@
package com.teampophory.pophory.feature.signup

import android.os.Bundle
import android.text.Editable
import android.text.TextWatcher
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.view.isGone
import androidx.core.view.isVisible
import androidx.core.widget.doAfterTextChanged
import androidx.fragment.app.Fragment
import com.teampophory.pophory.R
import com.teampophory.pophory.common.view.viewBinding
import com.teampophory.pophory.databinding.FragmentSignUpFirstBinding
import java.util.regex.Pattern

class SignUpFirstFragment : Fragment() {

private var _binding: FragmentSignUpFirstBinding? = null
private var buttonState:SignUpButtonInterface? = null
private val binding: FragmentSignUpFirstBinding
get() = requireNotNull(_binding) { "앗 ! _binding이 null이다 !" }
private val binding by viewBinding(FragmentSignUpFirstBinding::bind)
private var buttonState: SignUpButtonInterface? = null

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
_binding = FragmentSignUpFirstBinding.inflate(inflater, container, false)
return binding.root
): View {
return FragmentSignUpFirstBinding.inflate(inflater, container, false).root
Copy link
Contributor

Choose a reason for hiding this comment

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

binding.inflate(inflater, container, false).root 로 작성하는 것과 무슨 차이가 있는 건가요??!

Copy link
Member Author

Choose a reason for hiding this comment

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

@jihyeonAnAn 이거 알려줄게

}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.tvErrorMessage.isVisible = false
binding.btnDeleteEditText.isGone = true
//edittext 상태
// edittext 상태
setEditText()
//edittext 삭제 버튼
// edittext 삭제 버튼
deleteAllEditText()
}

override fun onDestroyView() {
super.onDestroyView()
_binding = null
}

private fun deleteAllEditText() {
binding.btnDeleteEditText.setOnClickListener {
binding.editTvName.text.clear()
Expand All @@ -53,65 +44,47 @@ class SignUpFirstFragment : Fragment() {
private fun setEditText() {
//텍스트창 활성화
binding.editTvName.apply {
setOnFocusChangeListener { view, hasFocus ->
//포커스가 주어졌을 때
setOnFocusChangeListener { _, hasFocus ->
// 포커스가 주어졌을 때
if (hasFocus) {
setBackgroundResource(R.drawable.bg_sign_up_edit_text_selected)
} else {
setBackgroundResource(R.drawable.bg_sign_up_edit_text_default)
}
}

//edittext text 변화 감지
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) {
//X버튼 생성 여부
binding.btnDeleteEditText.isGone = count < 1
//글자 수 계산
binding.tvTextCount.text = "(${s.toString().length}/6)"

//에러 메시지 : 현재 한국어만 지원함!
val pattern = Pattern.compile(HANGUL_PATTERN)
val matcher = pattern.matcher(binding.editTvName.text)
if (!matcher.find()) {
binding.tvErrorMessage.text = "현재 한국어만 지원하고 있어요."
binding.editTvName.setBackgroundResource(R.drawable.bg_sign_up_edit_text_error)
binding.tvErrorMessage.isVisible = true
buttonState?.setButtonState(false)
} else if (s.toString().length < 2) {
binding.tvErrorMessage.text = "2-6글자 이내로 작성해주세요."
binding.editTvName.setBackgroundResource(R.drawable.bg_sign_up_edit_text_error)
binding.tvErrorMessage.isVisible = true
buttonState?.setButtonState(false)
} else {
binding.editTvName.setBackgroundResource(R.drawable.bg_sign_up_edit_text_selected)
binding.tvErrorMessage.isVisible = false
buttonState?.setButtonState(true)
}

}

override fun afterTextChanged(s: Editable?) {

doAfterTextChanged {
binding.btnDeleteEditText.isGone = it?.isEmpty() == true
// 글자 수 계산
binding.tvTextCount.text = "(${it.toString().length}/6)"

// 에러 메시지 : 현재 한국어만 지원함!
val matcher = HANGUL_REGEX.matcher(binding.editTvName.text)
if (!matcher.find()) {
binding.tvErrorMessage.text = "현재 한국어만 지원하고 있어요."
binding.editTvName.setBackgroundResource(R.drawable.bg_sign_up_edit_text_error)
binding.tvErrorMessage.isVisible = true
buttonState?.onChangeState(false)
} else if (it.toString().length < 2) {
binding.tvErrorMessage.text = "2-6글자 이내로 작성해주세요."
binding.editTvName.setBackgroundResource(R.drawable.bg_sign_up_edit_text_error)
binding.tvErrorMessage.isVisible = true
buttonState?.onChangeState(false)
} else {
binding.editTvName.setBackgroundResource(R.drawable.bg_sign_up_edit_text_selected)
binding.tvErrorMessage.isVisible = false
buttonState?.onChangeState(true)
}

})
}
}
}

fun setSignUpButtonInterface(buttonState: SignUpButtonInterface){
fun setSignUpButtonInterface(buttonState: SignUpButtonInterface) {
this.buttonState = buttonState
}

companion object {
const val HANGUL_PATTERN = "^[ㄱ-ㅎㅏ-ㅣ가-힣]*\$"
private const val HANGUL_PATTERN = "^[ㄱ-ㅎㅏ-ㅣ가-힣]*\$"
val HANGUL_REGEX: Pattern = Pattern.compile(HANGUL_PATTERN)
}
}
Loading