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 9a9b223 commit f1b3adc
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.android.mediproject.core.common.bindingadapter

import android.graphics.Bitmap
import android.text.Editable
import android.text.Spanned
import android.view.View
import android.widget.EditText
Expand Down Expand Up @@ -66,11 +67,19 @@ object BindingAdapter {
@JvmStatic
fun setOnClick(view: View, iSendText: ISendText, editText: EditText) {
view.setOnClickListener {
iSendText.onClickedSendButton(editText.text)
iSendText.onClickWithText(editText.text.toString())
editText.text.clear()
}
}

@BindingAdapter("onClickWithText", "otherEditText", requireAll = true)
@JvmStatic
fun setOnClickWithText(view: TextView, onClickWithText: ISendText, otherEditText: Editable) {
view.setOnClickListener {
onClickWithText.onClickWithText(otherEditText.toString())
}
}

/**
* ImageView에 이미지를 설정합니다.
* 이미지가 없을 경우 TextView에 메시지를 표시합니다.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.android.mediproject.core.common.bindingadapter

interface ISendText {
fun onClickedSendButton(text: CharSequence)
}
fun onClickWithText(text: String)
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class Subtitle @JvmOverloads constructor(
const val PASSWORD = 1
}

lateinit var title: TextView
lateinit var redPoint: TextView
lateinit var inputData: EditText
var title: TextView
var redPoint: TextView
var inputData: EditText

init {
val infService = Context.LAYOUT_INFLATER_SERVICE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class MedicineCommentsViewModel @Inject constructor(
}
}

override fun onClickedSendButton(text: CharSequence) {/* viewModelScope.launch {
override fun onClickWithText(text: String) {/* viewModelScope.launch {
if (text.isEmpty()) {
_action.emit(OnCompleteApplyCommentOrReply(false))
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.viewModels
import com.android.mediproject.core.common.viewmodel.repeatOnStarted
import com.android.mediproject.feature.intro.R
import com.android.mediproject.feature.intro.databinding.DialogEmailVerificationBinding
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.filterNotNull

@AndroidEntryPoint
class EmailVerficationDialogFragment : DialogFragment() {
Expand All @@ -35,11 +39,38 @@ class EmailVerficationDialogFragment : DialogFragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.viewModel = viewModel
setDialog()
binding.lifecycleOwner = viewLifecycleOwner

init()
viewLifecycleOwner.repeatOnStarted {
viewModel.verificationState.filterNotNull().collect {
when (it) {
is VerificationState.Verified -> {
Toast.makeText(requireContext(), getString(R.string.confirmedVerificationCode), Toast.LENGTH_SHORT).show()
dismiss()
}

is VerificationState.VerifyFailed -> {
Toast.makeText(requireContext(), getString(R.string.verificationCodeError), Toast.LENGTH_SHORT).show()
}
}
}
}
}

private fun setDialog() {
binding.run {}
private fun init() {
binding.run {
positiveButton.setOnClickListener {
if (dialogSubtitle1.inputData.text.toString().isEmpty()) {
Toast.makeText(requireContext(), getString(R.string.verificationCodeHint), Toast.LENGTH_SHORT).show()
return@setOnClickListener
}
viewModel.onClickWithText(dialogSubtitle1.inputData.text.toString())
}
negativeButton.setOnClickListener {
dismiss()
}
}
}

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

import androidx.lifecycle.viewModelScope
import com.android.mediproject.core.common.bindingadapter.ISendText
import com.android.mediproject.core.common.network.Dispatcher
import com.android.mediproject.core.common.network.MediDispatchers
import com.android.mediproject.core.data.session.AccountSessionRepository
Expand All @@ -19,16 +20,16 @@ class VerificationViewModel @Inject constructor(
private val signRepository: SignRepository,
private val accountSessionRepository: AccountSessionRepository,
@Dispatcher(MediDispatchers.Default) private val defaultDispatcher: kotlinx.coroutines.CoroutineDispatcher,
) : BaseViewModel() {
) : BaseViewModel(), ISendText {

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) {
override fun onClickWithText(text: String) {
viewModelScope.launch {
withContext(defaultDispatcher) { signRepository.verifyEmail(email, code) }.onSuccess {
withContext(defaultDispatcher) { signRepository.verifyEmail(email.value, text) }.onSuccess {
_verificationState.value = VerificationState.Verified
}.onFailure {
_verificationState.value = VerificationState.VerifyFailed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<variable
name="viewModel"
type="com.android.mediproject.feature.intro.verification.VerificationViewModel" />

</data>

<LinearLayout
Expand Down Expand Up @@ -44,7 +43,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/sendedVerificationCode"
android:textSize="16sp" />
android:textSize="14sp" />

<TextView
android:layout_width="wrap_content"
Expand Down Expand Up @@ -80,8 +79,6 @@
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
2 changes: 2 additions & 0 deletions feature/intro/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@
<string name="complete">완료</string>
<string name="verificationCodeDescription">로그인 하려면 이메일 인증이 필요합니다</string>
<string name="sendedVerificationCode">다음 이메일로 인증 코드가 전송되었습니다</string>
<string name="verificationCodeError">인증 코드가 틀렸습니다</string>
<string name="confirmedVerificationCode">인증 완료</string>
</resources>

0 comments on commit f1b3adc

Please sign in to comment.