-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[QA] 온보딩 qa 수정
- Loading branch information
Showing
30 changed files
with
282 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
app/src/main/java/sopt/motivoo/presentation/onboarding/NickNameFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package sopt.motivoo.presentation.onboarding | ||
|
||
import android.os.Bundle | ||
import android.view.View | ||
import android.view.animation.AnimationUtils | ||
import androidx.activity.OnBackPressedCallback | ||
import androidx.fragment.app.activityViewModels | ||
import androidx.lifecycle.Lifecycle | ||
import androidx.lifecycle.flowWithLifecycle | ||
import androidx.lifecycle.lifecycleScope | ||
import androidx.navigation.fragment.findNavController | ||
import kotlinx.coroutines.delay | ||
import kotlinx.coroutines.flow.distinctUntilChanged | ||
import kotlinx.coroutines.flow.launchIn | ||
import kotlinx.coroutines.flow.onEach | ||
import kotlinx.coroutines.launch | ||
import sopt.motivoo.R | ||
import sopt.motivoo.databinding.FragmentNicknameBinding | ||
import sopt.motivoo.util.binding.BindingFragment | ||
import sopt.motivoo.util.extension.drawableOf | ||
import sopt.motivoo.util.extension.setOnSingleClickListener | ||
|
||
class NickNameFragment : BindingFragment<FragmentNicknameBinding>(R.layout.fragment_nickname) { | ||
|
||
private val onboardingViewModel by activityViewModels<OnboardingViewModel>() | ||
private var lastNickNameLength = 0 | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
binding.onboardingViewModel = onboardingViewModel | ||
collectData() | ||
clickNextButton() | ||
overrideOnBackPressed() | ||
} | ||
|
||
private fun clickNextButton() { | ||
binding.btnNicknameDone.setOnSingleClickListener { | ||
findNavController().navigate(R.id.action_nickNameFragment_to_ageQuestionFragment) | ||
} | ||
} | ||
|
||
private fun collectData() { | ||
onboardingViewModel.nickName.flowWithLifecycle( | ||
viewLifecycleOwner.lifecycle, | ||
Lifecycle.State.STARTED | ||
) | ||
.distinctUntilChanged() | ||
.onEach { it?.let { it1 -> handleNickNameChange(it1) } } | ||
.launchIn(viewLifecycleOwner.lifecycleScope) | ||
} | ||
|
||
private fun handleNickNameChange(nickName: String) { | ||
val currentLength = nickName.length | ||
binding.btnNicknameDone.isEnabled = nickName.isNotEmpty() | ||
|
||
if (currentLength >= 8 && lastNickNameLength != currentLength) { | ||
setErrorAnimation() | ||
} else if (currentLength < 8) { | ||
resetErrorState() | ||
} | ||
|
||
lastNickNameLength = currentLength | ||
} | ||
|
||
private fun setErrorAnimation() { | ||
val fadeIn = AnimationUtils.loadAnimation(context, R.anim.fade_in) | ||
with(binding) { | ||
tvNicknameErrorMessage.startAnimation(fadeIn) | ||
etNickname.background = | ||
requireContext().drawableOf(R.drawable.shape_edittext_error_radius8) | ||
tvNicknameErrorMessage.visibility = View.VISIBLE | ||
|
||
lifecycleScope.launch { | ||
delay(FOUR_SECONDS) | ||
val fadeOut = AnimationUtils.loadAnimation(context, R.anim.fade_out) | ||
binding.tvNicknameErrorMessage.startAnimation(fadeOut) | ||
binding.tvNicknameErrorMessage.visibility = View.INVISIBLE | ||
binding.etNickname.background = | ||
requireContext().drawableOf(R.drawable.selector_edittext_input) | ||
} | ||
} | ||
} | ||
|
||
private fun resetErrorState() { | ||
binding.tvNicknameErrorMessage.visibility = View.INVISIBLE | ||
binding.etNickname.background = | ||
requireContext().drawableOf(R.drawable.selector_edittext_input) | ||
} | ||
|
||
private fun overrideOnBackPressed() { | ||
requireActivity().onBackPressedDispatcher.addCallback( | ||
viewLifecycleOwner, | ||
object : OnBackPressedCallback(true) { | ||
override fun handleOnBackPressed() { | ||
requireActivity().finishAffinity() | ||
} | ||
} | ||
) | ||
} | ||
|
||
companion object { | ||
const val FOUR_SECONDS = 4000L | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.