mirror of
https://github.com/accelforce/Yuito
synced 2024-12-22 05:19:05 +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) {
|
||||
override fun handleOnBackPressed() {
|
||||
if (!viewModel.hasUnsavedChanges(profileData)) finish()
|
||||
|
||||
lifecycleScope.launch {
|
||||
when (showConfirmationDialog()) {
|
||||
AlertDialog.BUTTON_POSITIVE -> save()
|
||||
else -> finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
override fun handleOnBackPressed() = checkForPotentialUnsavedChanges()
|
||||
}
|
||||
|
||||
onBackPressedDispatcher.addCallback(this, onBackCallback)
|
||||
}
|
||||
|
||||
fun checkForPotentialUnsavedChanges() {
|
||||
if (hasUnsavedChanges()) {
|
||||
showUnsavedChangesDialog()
|
||||
} else {
|
||||
finish()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
super.onStop()
|
||||
if (!isFinishing) {
|
||||
@ -228,7 +227,7 @@ class EditProfileActivity : BaseActivity(), Injectable {
|
||||
}
|
||||
}
|
||||
|
||||
internal val profileData
|
||||
private val profileData
|
||||
get() = ProfileData(
|
||||
displayName = binding.displayNameEditText.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()
|
||||
}
|
||||
|
||||
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))
|
||||
.setMessage(getString(R.string.message_edit_profile_save_changes_prompt))
|
||||
.create()
|
||||
|
Loading…
Reference in New Issue
Block a user