mirror of
https://github.com/accelforce/Yuito
synced 2025-01-03 11:30:29 +01:00
Avoid synthetic accessors.
This commit is contained in:
parent
8edc8d6422
commit
e56c0cb5a3
@ -206,21 +206,20 @@ class EditProfileActivity : BaseActivity(), Injectable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val onBackCallback = object : OnBackPressedCallback(enabled = true) {
|
val onBackCallback = object : OnBackPressedCallback(enabled = true) {
|
||||||
override fun handleOnBackPressed() {
|
override fun handleOnBackPressed() = checkForPotentialUnsavedChanges()
|
||||||
if (!viewModel.hasUnsavedChanges(profileData)) finish()
|
|
||||||
|
|
||||||
lifecycleScope.launch {
|
|
||||||
when (showConfirmationDialog()) {
|
|
||||||
AlertDialog.BUTTON_POSITIVE -> save()
|
|
||||||
else -> finish()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onBackPressedDispatcher.addCallback(this, onBackCallback)
|
onBackPressedDispatcher.addCallback(this, onBackCallback)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun checkForPotentialUnsavedChanges() {
|
||||||
|
if (hasUnsavedChanges()) {
|
||||||
|
showUnsavedChangesDialog()
|
||||||
|
} else {
|
||||||
|
finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onStop() {
|
override fun onStop() {
|
||||||
super.onStop()
|
super.onStop()
|
||||||
if (!isFinishing) {
|
if (!isFinishing) {
|
||||||
@ -228,7 +227,7 @@ class EditProfileActivity : BaseActivity(), Injectable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal val profileData
|
private val profileData
|
||||||
get() = ProfileData(
|
get() = ProfileData(
|
||||||
displayName = binding.displayNameEditText.text.toString(),
|
displayName = binding.displayNameEditText.text.toString(),
|
||||||
note = binding.noteEditText.text.toString(),
|
note = binding.noteEditText.text.toString(),
|
||||||
@ -322,7 +321,16 @@ class EditProfileActivity : BaseActivity(), Injectable {
|
|||||||
Snackbar.make(binding.avatarButton, R.string.error_media_upload_sending, Snackbar.LENGTH_LONG).show()
|
Snackbar.make(binding.avatarButton, R.string.error_media_upload_sending, Snackbar.LENGTH_LONG).show()
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun showConfirmationDialog() = AlertDialog.Builder(this)
|
private fun showUnsavedChangesDialog() = lifecycleScope.launch {
|
||||||
|
when (launchAlertDialog()) {
|
||||||
|
AlertDialog.BUTTON_POSITIVE -> save()
|
||||||
|
else -> finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun hasUnsavedChanges() = viewModel.hasUnsavedChanges(profileData)
|
||||||
|
|
||||||
|
private suspend fun launchAlertDialog() = AlertDialog.Builder(this)
|
||||||
.setTitle(getString(R.string.title_edit_profile_save_changes_prompt))
|
.setTitle(getString(R.string.title_edit_profile_save_changes_prompt))
|
||||||
.setMessage(getString(R.string.message_edit_profile_save_changes_prompt))
|
.setMessage(getString(R.string.message_edit_profile_save_changes_prompt))
|
||||||
.create()
|
.create()
|
||||||
|
Loading…
Reference in New Issue
Block a user