mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-19 09:25:34 +00:00
[fenix] For https://github.com/mozilla-mobile/fenix/issues/15675: Disable Save button when editing saved login until something has been changed
set save button state by calling invalidateOptionsMenu, causing onPrepareOptionsMenu to be called which will enable/disable the save button depending on if changes have been made or not
This commit is contained in:
parent
1d8006f733
commit
efc846d57a
@ -13,7 +13,6 @@ import android.view.Menu
|
||||
import android.view.MenuInflater
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import androidx.appcompat.view.menu.ActionMenuItemView
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.fragment.app.Fragment
|
||||
@ -57,7 +56,6 @@ class EditLoginFragment : Fragment(R.layout.fragment_edit_login) {
|
||||
|
||||
private var usernameChanged = false
|
||||
private var passwordChanged = false
|
||||
private var saveEnabled = false
|
||||
|
||||
private var validPassword = true
|
||||
private var validUsername = true
|
||||
@ -90,8 +88,9 @@ class EditLoginFragment : Fragment(R.layout.fragment_edit_login) {
|
||||
usernameText.text = args.savedLoginItem.username.toEditable()
|
||||
passwordText.text = args.savedLoginItem.password.toEditable()
|
||||
|
||||
clearUsernameTextButton.isEnabled = oldLogin.username.isNotEmpty()
|
||||
|
||||
formatEditableValues()
|
||||
initSaveState()
|
||||
setUpClickListeners()
|
||||
setUpTextListeners()
|
||||
togglePasswordReveal(passwordText, revealPasswordButton)
|
||||
@ -101,18 +100,6 @@ class EditLoginFragment : Fragment(R.layout.fragment_edit_login) {
|
||||
}
|
||||
}
|
||||
|
||||
private fun initSaveState() {
|
||||
saveEnabled = false // don't enable saving until something has been changed
|
||||
val saveButton =
|
||||
activity?.findViewById<ActionMenuItemView>(R.id.save_login_button)
|
||||
saveButton?.isEnabled = saveEnabled
|
||||
|
||||
usernameChanged = false
|
||||
passwordChanged = false
|
||||
|
||||
clearUsernameTextButton.isEnabled = oldLogin.username.isNotEmpty()
|
||||
}
|
||||
|
||||
private fun formatEditableValues() {
|
||||
hostnameText.isClickable = false
|
||||
hostnameText.isFocusable = false
|
||||
@ -263,20 +250,20 @@ class EditLoginFragment : Fragment(R.layout.fragment_edit_login) {
|
||||
}
|
||||
|
||||
private fun setSaveButtonState() {
|
||||
val saveButton = activity?.findViewById<ActionMenuItemView>(R.id.save_login_button)
|
||||
val changesMadeWithNoErrors =
|
||||
validUsername && validPassword && (usernameChanged || passwordChanged)
|
||||
|
||||
changesMadeWithNoErrors.let {
|
||||
saveButton?.isEnabled = it
|
||||
saveEnabled = it
|
||||
}
|
||||
activity?.invalidateOptionsMenu()
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||
inflater.inflate(R.menu.login_save, menu)
|
||||
}
|
||||
|
||||
override fun onPrepareOptionsMenu(menu: Menu) {
|
||||
val saveButton = menu.findItem(R.id.save_login_button)
|
||||
val changesMadeWithNoErrors =
|
||||
validUsername && validPassword && (usernameChanged || passwordChanged)
|
||||
saveButton.isEnabled = changesMadeWithNoErrors // don't enable saving until something has been changed
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
redirectToReAuth(
|
||||
listOf(R.id.loginDetailFragment),
|
||||
@ -288,14 +275,12 @@ class EditLoginFragment : Fragment(R.layout.fragment_edit_login) {
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean = when (item.itemId) {
|
||||
R.id.save_login_button -> {
|
||||
view?.hideKeyboard()
|
||||
if (saveEnabled) {
|
||||
interactor.onSaveLogin(
|
||||
args.savedLoginItem.guid,
|
||||
usernameText.text.toString(),
|
||||
passwordText.text.toString()
|
||||
)
|
||||
requireComponents.analytics.metrics.track(Event.EditLoginSave)
|
||||
}
|
||||
true
|
||||
}
|
||||
else -> false
|
||||
|
Loading…
Reference in New Issue
Block a user