AlertDialog при выходе
This commit is contained in:
parent
9ea2a7720f
commit
835ddd1afb
@ -1,8 +1,15 @@
|
||||
package ru.myitschool.work.ui.profile
|
||||
|
||||
import android.content.DialogInterface
|
||||
import android.graphics.Color
|
||||
import android.graphics.Typeface
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.content.res.ResourcesCompat
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.viewModels
|
||||
import androidx.navigation.fragment.findNavController
|
||||
@ -78,11 +85,59 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) {
|
||||
|
||||
viewModel.action.collectWhenStarted(this) { action ->
|
||||
when(action) {
|
||||
is ProfileViewModel.Action.OpenLogin -> {
|
||||
is ProfileViewModel.Action.Logout -> {
|
||||
findNavController().navigate(LoginDestination) {
|
||||
popUpTo<ProfileDestination> { inclusive = true }
|
||||
}
|
||||
}
|
||||
is ProfileViewModel.Action.OpenLogin -> {
|
||||
|
||||
val builder = AlertDialog.Builder(requireContext())
|
||||
|
||||
builder.setTitle(ContextCompat.getContextForLanguage(requireContext()).getString(R.string.profile_logout_dialog));
|
||||
builder.setMessage(ContextCompat.getContextForLanguage(requireContext()).getString(R.string.profile_logout_text_dialog))
|
||||
builder.setPositiveButton(
|
||||
ContextCompat.getContextForLanguage(requireContext()).getString(R.string.logout),
|
||||
DialogInterface.OnClickListener { dialogInterface, i ->
|
||||
viewModel.logout()
|
||||
dialogInterface.dismiss()
|
||||
})
|
||||
builder.setNegativeButton(
|
||||
ContextCompat.getContextForLanguage(requireContext()).getString(R.string.cancel),
|
||||
DialogInterface.OnClickListener { dialogInterface, i ->
|
||||
dialogInterface.dismiss()
|
||||
|
||||
})
|
||||
|
||||
val dialog = builder.create()
|
||||
|
||||
|
||||
|
||||
dialog.setOnShowListener {
|
||||
val titleView = dialog.findViewById<TextView>(android.R.id.title)
|
||||
val messageView = dialog.findViewById<TextView>(android.R.id.message)
|
||||
|
||||
|
||||
|
||||
titleView?.setTextAppearance(R.style.Theme_UiTemplate_TextH2)
|
||||
messageView?.setTextAppearance(R.style.Theme_UiTemplate_TextH4)
|
||||
|
||||
|
||||
|
||||
val positiveButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE)
|
||||
val negativeButton = dialog.getButton(AlertDialog.BUTTON_NEGATIVE)
|
||||
|
||||
|
||||
positiveButton.setTextColor(ContextCompat.getColor(requireContext(), R.color.ErrorRed) )
|
||||
negativeButton.setTextColor(ContextCompat.getColor(requireContext(), R.color.AccentBlue) )
|
||||
}
|
||||
|
||||
// Установка кнопок
|
||||
|
||||
|
||||
// Показать диалог
|
||||
dialog.show()
|
||||
}
|
||||
|
||||
is ProfileViewModel.Action.OpenLog -> {
|
||||
findNavController().navigate(EntryListDestination) {
|
||||
|
@ -37,11 +37,17 @@ class ProfileViewModel @Inject constructor(
|
||||
updateUserInfo()
|
||||
}
|
||||
|
||||
fun logout(){
|
||||
viewModelScope.launch {
|
||||
logoutUseCase.get().invoke()
|
||||
_action.emit(Action.Logout)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun clickLogout() {
|
||||
viewModelScope.launch {
|
||||
logoutUseCase.get().invoke()
|
||||
_action.emit(Action.OpenLogin)
|
||||
}
|
||||
}
|
||||
@ -108,6 +114,7 @@ class ProfileViewModel @Inject constructor(
|
||||
data object OpenScan : Action
|
||||
data object OpenLog : Action
|
||||
data object OpenSearch : Action
|
||||
data object Logout : Action
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
@ -23,4 +23,8 @@
|
||||
<string name="qr_result_status_success">Успешно</string>
|
||||
<string name="qr_result_status_cancel">Операция отменена</string>
|
||||
<string name="qr_result_status_error">Что-то пошло не так</string>
|
||||
</resources>
|
||||
<string name="profile_logout_dialog">Выход</string>
|
||||
<string name="profile_logout_text_dialog">Вы уверенны что хотите выйти из системы?</string>
|
||||
<string name="logout">Выход</string>
|
||||
<string name="cancel">Отмена</string>
|
||||
</resources>
|
||||
|
@ -1,4 +1,6 @@
|
||||
<resources>
|
||||
<string name="app_name">NTO Pass</string>
|
||||
<string name="entry_history">Entry History</string>
|
||||
<string name="logout">Logout</string>
|
||||
<string name="cancel">Cancel</string>
|
||||
</resources>
|
@ -5,4 +5,6 @@
|
||||
<string name="profile_main_textview">Home</string>
|
||||
<string name="profile_admin_button">Admin panel</string>
|
||||
<string name="profile_list_button">Entry History</string>
|
||||
<string name="profile_logout_dialog">Logout</string>
|
||||
<string name="profile_logout_text_dialog">Are you sure you want to log out?</string>
|
||||
</resources>
|
Loading…
x
Reference in New Issue
Block a user