Skip to content

Commit

Permalink
Merge pull request #104 from FakeDevelopers/feature/BDBD-533
Browse files Browse the repository at this point in the history
Feature/bdbd 533
  • Loading branch information
minseonglove authored Mar 8, 2023
2 parents 3baf50e + 23f1bad commit 0688acc
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 99 deletions.
3 changes: 3 additions & 0 deletions presentation/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,8 @@
<activity
android:name="com.fakedevelopers.presentation.ui.MainActivity"
android:windowSoftInputMode="adjustResize" />
<activity
android:name="com.fakedevelopers.presentation.ui.register.UserRegistrationActivity"
android:windowSoftInputMode="adjustResize" />
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package com.fakedevelopers.presentation.ui.base

import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import androidx.annotation.IntRange
import androidx.appcompat.app.AppCompatActivity
import androidx.viewbinding.ViewBinding
import com.google.android.material.snackbar.Snackbar

abstract class BaseActivity<VB : ViewBinding>(
private val bindingFactory: (LayoutInflater) -> VB
Expand All @@ -16,4 +20,25 @@ abstract class BaseActivity<VB : ViewBinding>(
binding = bindingFactory(layoutInflater)
setContentView(binding.root)
}

protected fun sendSnackBar(
message: String,
@IntRange(from = -2) length: Int = Snackbar.LENGTH_SHORT,
anchorView: View? = null
) {
Snackbar.make(
binding.root,
message,
length
).apply {
if (anchorView != null) {
this.anchorView = anchorView
}
}.show()
}

protected fun navigateActivity(activity: Class<*>) {
startActivity(Intent(this, activity))
finish()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package com.fakedevelopers.presentation.ui.login
import android.os.Bundle
import android.view.View
import androidx.fragment.app.viewModels
import androidx.navigation.fragment.findNavController
import com.fakedevelopers.domain.secret.Constants.Companion.LOGIN_SUCCESS
import com.fakedevelopers.presentation.R
import com.fakedevelopers.presentation.databinding.FragmentLoginBinding
import com.fakedevelopers.presentation.ui.MainActivity
import com.fakedevelopers.presentation.ui.base.BaseFragment
import com.fakedevelopers.presentation.ui.register.UserRegistrationActivity
import com.fakedevelopers.presentation.ui.util.repeatOnStarted
import dagger.hilt.android.AndroidEntryPoint
import io.getstream.logging.helper.stringify
Expand All @@ -28,7 +28,7 @@ class LoginFragment : BaseFragment<FragmentLoginBinding>(

override fun initListener() {
binding.textviewLoginRegistration.setOnClickListener {
findNavController().navigate(R.id.action_loginFragment_to_userRegistrationFragment)
navigateActivity(UserRegistrationActivity::class.java)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.fakedevelopers.presentation.R
import com.fakedevelopers.presentation.databinding.FragmentLoginTypeBinding
import com.fakedevelopers.presentation.ui.MainActivity
import com.fakedevelopers.presentation.ui.base.BaseFragment
import com.fakedevelopers.presentation.ui.register.UserRegistrationActivity
import com.fakedevelopers.presentation.ui.util.ApiErrorHandler
import com.fakedevelopers.presentation.ui.util.repeatOnStarted
import com.google.android.gms.auth.api.Auth
Expand Down Expand Up @@ -71,7 +72,7 @@ class LoginTypeFragment : BaseFragment<FragmentLoginTypeBinding>(
findNavController().navigate(R.id.action_loginTypeFragment_to_loginFragment)
}
binding.textViewLogintypeRegistration.setOnClickListener {
findNavController().navigate(R.id.action_loginTypeFragment_to_userRegistrationFragment)
navigateActivity(UserRegistrationActivity::class.java)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,27 @@
package com.fakedevelopers.presentation.ui.register

import android.content.Intent
import android.os.Bundle
import android.view.View
import androidx.activity.OnBackPressedCallback
import androidx.core.content.ContextCompat
import androidx.lifecycle.ViewModelProvider
import androidx.activity.viewModels
import androidx.core.view.isVisible
import androidx.navigation.NavController
import androidx.navigation.NavOptions
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.fragment.findNavController
import androidx.navigation.navOptions
import com.fakedevelopers.presentation.R
import com.fakedevelopers.presentation.databinding.FragmentUserRegistrationBinding
import com.fakedevelopers.presentation.databinding.ActivityUserRegistrationBinding
import com.fakedevelopers.presentation.ui.MainActivity
import com.fakedevelopers.presentation.ui.base.BaseFragment
import com.fakedevelopers.presentation.ui.base.BaseActivity
import com.fakedevelopers.presentation.ui.util.repeatOnStarted
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.collectLatest

class UserRegistrationFragment : BaseFragment<FragmentUserRegistrationBinding>(
R.layout.fragment_user_registration
@AndroidEntryPoint
class UserRegistrationActivity : BaseActivity<ActivityUserRegistrationBinding>(
ActivityUserRegistrationBinding::inflate
) {
private val viewModel: UserRegistrationViewModel by lazy {
ViewModelProvider(requireActivity())[UserRegistrationViewModel::class.java]
}

private val navController by lazy {
(childFragmentManager.findFragmentById(R.id.navigation_user_registration) as NavHostFragment).navController
}

private val viewModel: UserRegistrationViewModel by viewModels()
private lateinit var navController: NavController
private val singleTopOptions = navOptions {
launchSingleTop = true
}
Expand All @@ -40,53 +34,50 @@ class UserRegistrationFragment : BaseFragment<FragmentUserRegistrationBinding>(
}
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding.vm = viewModel
navController =
(supportFragmentManager.findFragmentById(R.id.navigation_user_registration) as NavHostFragment).navController
setProgressBar(viewModel.currentStep)
viewModel.setInitialStep()
initListener()
initCollector()
}

override fun onStart() {
super.onStart()
requireActivity().onBackPressedDispatcher.addCallback(backPressedCallback)
onBackPressedDispatcher.addCallback(backPressedCallback)
}

override fun initListener() {
fun initListener() {
navController.addOnDestinationChangedListener { _, destination, _ ->
setToolbarTitleByDestination(destination.id)
setNextByDestination(destination.id)
binding.buttonUserRegistrationNext.isVisible =
destination.id != R.id.acceptTermsFragmentContents
}
// 뒤로버튼
binding.includeUserRegistrationToolbar.buttonBack.setOnClickListener {
viewModel.toPreviousStep()
}
}

private fun setRegistrationNextButton(state: Boolean) {
binding.buttonUserRegistrationNext.let {
val color = if (state) R.color.bidderbidder_primary else R.color.bidderbidder_gray
it.isEnabled = state
it.setBackgroundColor(ContextCompat.getColor(requireActivity(), color))
}
}

override fun initCollector() {
fun initCollector() {
// 회원가입 단계 관리
repeatOnStarted(viewLifecycleOwner) {
repeatOnStarted(this) {
viewModel.changeRegistrationStep.collectLatest {
toNextStep(it)
}
}
// 실패 토스트 메세지
repeatOnStarted(viewLifecycleOwner) {
repeatOnStarted(this) {
viewModel.failureMessage.collectLatest {
sendSnackBar(it)
}
}
repeatOnStarted(viewLifecycleOwner) {
repeatOnStarted(this) {
viewModel.nextStepEnabled.collect {
setRegistrationNextButton(it)
binding.buttonUserRegistrationNext.isEnabled = it
}
}
}
Expand All @@ -101,13 +92,6 @@ class UserRegistrationFragment : BaseFragment<FragmentUserRegistrationBinding>(
}
}

private fun setNextByDestination(destinationId: Int) {
binding.buttonUserRegistrationNext.visibility = when (destinationId) {
R.id.acceptTermsFragmentContents -> View.INVISIBLE
else -> View.VISIBLE
}
}

private fun setProgressBar(state: RegistrationProgressState) {
binding.includeUserRegistrationNavigation.run {
root.visibility = state.getVisibleState()
Expand All @@ -122,12 +106,11 @@ class UserRegistrationFragment : BaseFragment<FragmentUserRegistrationBinding>(
setProgressBar(state)

if (state.checkCancelStep()) {
findNavController().popBackStack()
navController.popBackStack()
}

if (state.checkLastStep()) {
startActivity(Intent(requireContext(), MainActivity::class.java))
requireActivity().finish()
navigateActivity(MainActivity::class.java)
}

state.navigationId?.let { navId ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class UserRegistrationViewModel : ViewModel() {

/* AcceptTermsFragment */
private val _acceptAllState = MutableEventFlow<Boolean>()
private var essentialTerms = mutableListOf<Boolean>()
private var optionalTerms = mutableListOf<Boolean>()
private var essentialTerms = arrayOf<Boolean>()
private var optionalTerms = arrayOf<Boolean>()
val acceptAllState = _acceptAllState.asEventFlow()
var acceptTermDetail: String = ""

Expand Down Expand Up @@ -81,8 +81,8 @@ class UserRegistrationViewModel : ViewModel() {
}

fun setTermSize(essentialSize: Int, optionalSize: Int) {
essentialTerms = MutableList(essentialSize) { false }
optionalTerms = MutableList(optionalSize) { false }
essentialTerms = Array(essentialSize) { false }
optionalTerms = Array(optionalSize) { false }
}

// 약관 선택 상태 변경
Expand All @@ -91,26 +91,20 @@ class UserRegistrationViewModel : ViewModel() {
TYPE_ESSENTIAL -> essentialTerms[idx] = isChecked
TYPE_OPTIONAL -> optionalTerms[idx] = isChecked
}
if (essentialTerms.all { !it } && optionalTerms.all { !it }) {
if (essentialTerms.none { it } && optionalTerms.none { it }) {
setAcceptAllState(false)
}
setNextStepEnabled(checkAcceptTerms())
setNextStepEnabled(essentialTerms.all { it })
}

// 필수 약관에 모두 동의 했다면 폰 인증 화면으로 넘어갑니다.
private fun checkAcceptTerms(): Boolean {
return essentialTerms.all { it }
}

// 필수 약관에 모두 동의 했다면 폰 인증 화면으로 넘어갑니다.
private fun getNextStepOfAccetTerms(): RegistrationProgressState {
private fun getNextStepOfAcceptTerms(): RegistrationProgressState =
if (essentialTerms.all { it }) {
return INPUT_ID
INPUT_ID
} else {
sendFailureMessage(NOT_AGREE_TO_ESSENTIAL_TERMS)
return EMPTY_STATE
EMPTY_STATE
}
}

// 코드 조건 확인
private fun checkNextAuthCode(): Boolean {
Expand Down Expand Up @@ -163,14 +157,13 @@ class UserRegistrationViewModel : ViewModel() {
private fun checkUserId() = !lastDuplicationState && userId == inputUserId.value

// 이미 중복 체크된 아이디거나 중복 체크를 통과한 아이디면 다음 단계 반환
private fun getNextStepOfInputId(): RegistrationProgressState {
private fun getNextStepOfInputId(): RegistrationProgressState =
if (checkUserId()) {
return INPUT_PASSWORD
INPUT_PASSWORD
} else {
sendFailureMessage(NOT_ID_DUPLICATION_CHECK)
return EMPTY_STATE
EMPTY_STATE
}
}

// 유효한 아이디 여부 표시
private fun setUserIdValidationState(state: Boolean) {
Expand Down Expand Up @@ -227,14 +220,13 @@ class UserRegistrationViewModel : ViewModel() {
}

// 비밀번호 조건 확인 후 다음 단계 반환
private fun getNextStepOfInputPassword(): RegistrationProgressState {
private fun getNextStepOfInputPassword(): RegistrationProgressState =
if (checkUserPassword()) {
return PHONE_AUTH_BEFORE_SENDING
PHONE_AUTH_BEFORE_SENDING
} else {
sendFailureMessage(INVALID_REGEX)
return EMPTY_STATE
EMPTY_STATE
}
}

// 다음 단계 버튼 활성화
fun setNextStepEnabled(state: Boolean) {
Expand All @@ -246,18 +238,15 @@ class UserRegistrationViewModel : ViewModel() {
// 현재 단계 조건 충족시 다음 단계로 이동
fun moveNextStep() {
when (currentStep) {
ACCEPT_TERMS -> getNextStepOfAccetTerms()
ACCEPT_TERMS -> getNextStepOfAcceptTerms()
INPUT_ID -> getNextStepOfInputId()
INPUT_PASSWORD -> getNextStepOfInputPassword()
PHONE_AUTH_BEFORE_SENDING -> {
sendFailureMessage(NOT_RECEIVED_AUTH_CODE)
EMPTY_STATE
}
PHONE_AUTH_CHECK_AUTH_CODE -> getNextStepOfAuthCheck()
else -> {
// 여긴 갈 일 없어!
EMPTY_STATE
}
else -> EMPTY_STATE
}.let {
setCurrentStep(it)
}
Expand Down
9 changes: 9 additions & 0 deletions presentation/src/main/res/drawable/selector_long_button.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="true">
<color android:color="@color/bidderbidder_primary" />
</item>
<item android:state_enabled="false">
<color android:color="@color/gray_30" />
</item>
</selector>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
xmlns:tools="http://schemas.android.com/tools">

<data>

<variable
name="vm"
type="com.fakedevelopers.presentation.ui.register.UserRegistrationViewModel" />
Expand Down Expand Up @@ -49,23 +48,16 @@

<androidx.appcompat.widget.AppCompatButton
android:id="@+id/button_user_registration_next"
android:layout_width="match_parent"
style="@style/ButtonUserRegistration"
android:layout_width="0dp"
android:layout_height="@dimen/registration_button_next_step_height"
android:background="#D6D6D6"
android:enabled="@{vm.nextStepEnabled}"
android:onClick="@{() -> vm.moveNextStep()}"
android:shadowColor="#111111"
android:text="@string/registration_button_to_next"
android:textColor="@color/white"
android:textSize="@dimen/registration_button_next_step_text_size"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0"
tools:ignore="SpUsage" />
app:layout_constraintVertical_bias="1.0" />

</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
Loading

0 comments on commit 0688acc

Please sign in to comment.