-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
93 additions
and
19 deletions.
There are no files selected for viewing
17 changes: 0 additions & 17 deletions
17
feature/intro/src/main/java/com/android/mediproject/feature/intro/EmailVerificationDialog.kt
This file was deleted.
Oops, something went wrong.
45 changes: 45 additions & 0 deletions
45
...c/main/java/com/android/mediproject/feature/intro/verification/EmailVerificationDialog.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,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 {} | ||
} | ||
|
||
} |
32 changes: 31 additions & 1 deletion
32
...src/main/java/com/android/mediproject/feature/intro/verification/VerificationViewModel.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 |
---|---|---|
@@ -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 | ||
} |
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