Skip to content

Commit

Permalink
#219 이메일 인증 다이얼로그 함수에서 프래그먼트로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
pknujsp committed Mar 11, 2024
1 parent 4229089 commit 9a9b223
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 19 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.android.mediproject.feature.intro.verification

import android.app.Dialog
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.viewModels
import com.android.mediproject.feature.intro.databinding.DialogEmailVerificationBinding
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class EmailVerficationDialogFragment : DialogFragment() {

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

private val viewModel by viewModels<VerificationViewModel>()

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
_binding = DialogEmailVerificationBinding.inflate(layoutInflater, null, false)
return MaterialAlertDialogBuilder(requireActivity()).apply {
setView(binding.root)
}.create()
}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return binding.root
}

override fun getView(): View = binding.root

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.viewModel = viewModel
setDialog()
}

private fun setDialog() {
binding.run {}
}

}
Original file line number Diff line number Diff line change
@@ -1,13 +1,43 @@
package com.android.mediproject.feature.intro.verification

import androidx.lifecycle.viewModelScope
import com.android.mediproject.core.common.network.Dispatcher
import com.android.mediproject.core.common.network.MediDispatchers
import com.android.mediproject.core.data.session.AccountSessionRepository
import com.android.mediproject.core.data.sign.SignRepository
import com.android.mediproject.core.ui.base.BaseViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import javax.inject.Inject

@HiltViewModel
class VerificationViewModel @Inject constructor(
private val signRepository: SignRepository,
private val accountSessionRepository: AccountSessionRepository,
@Dispatcher(MediDispatchers.Default) private val defaultDispatcher: kotlinx.coroutines.CoroutineDispatcher,
) : BaseViewModel() {


val email = accountSessionRepository.lastSavedEmail.stateIn(viewModelScope, kotlinx.coroutines.flow.SharingStarted.Eagerly, "")

private val _verificationState = MutableStateFlow<VerificationState?>(null)
val verificationState = _verificationState.asStateFlow()

fun verifyEmail(code: String) {
viewModelScope.launch {
withContext(defaultDispatcher) { signRepository.verifyEmail(email, code) }.onSuccess {
_verificationState.value = VerificationState.Verified
}.onFailure {
_verificationState.value = VerificationState.VerifyFailed
}
}
}
}

sealed interface VerificationState {
data object Verified : VerificationState
data object VerifyFailed : VerificationState
}
17 changes: 16 additions & 1 deletion feature/intro/src/main/res/layout/dialog_email_verification.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<variable
name="viewModel"
type="com.android.mediproject.feature.intro.IntroViewModel" />
type="com.android.mediproject.feature.intro.verification.VerificationViewModel" />

</data>

Expand Down Expand Up @@ -40,6 +40,19 @@
android:text="@string/verificationCodeDescription"
android:textSize="16sp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/sendedVerificationCode"
android:textSize="16sp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="@{viewModel.email}"
android:textSize="14sp" />

<com.android.mediproject.core.ui.base.view.Subtitle
android:id="@+id/dialogSubtitle1"
android:layout_width="match_parent"
Expand Down Expand Up @@ -67,6 +80,8 @@
android:text="@string/complete"
android:textColor="@color/white"
android:textSize="18sp"
android:onClick="@{()->viewModel.verifyEmail()}"
app:onClickSend="@{()->viewModel.verifyEmail()}"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@id/guideline"
app:layout_constraintStart_toStartOf="parent"
Expand Down
1 change: 1 addition & 0 deletions feature/intro/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@
<string name="verificationCodeHint">코드를 입력하세요</string>
<string name="complete">완료</string>
<string name="verificationCodeDescription">로그인 하려면 이메일 인증이 필요합니다</string>
<string name="sendedVerificationCode">다음 이메일로 인증 코드가 전송되었습니다</string>
</resources>

0 comments on commit 9a9b223

Please sign in to comment.